BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
rescaleAmplitudeSi.C
Go to the documentation of this file.
1#include <Rtypes.h>
2#include <TCanvas.h>
3#include <TChain.h>
4#include <TClonesArray.h>
5#include <TF1.h>
6#include <TFile.h>
7#include <TH1D.h>
8#include <TH2D.h>
9#include <TLegend.h>
10#include <TMathBase.h>
11#include <TString.h>
12#include <TTimeStamp.h>
13#include <vector>
14
15// #include "../../bmndata/math/BmnMath.h"
16
17// #include "../../bmndata/BmnStripDigit.h"
18
19R__ADD_INCLUDE_PATH($VMCWORKDIR)
20#include "macro/run/bmnloadlibs.C"
21
22/**
23 * rescaleAmplitudes
24 * Example of ADC signal rescaling procedures for Si strip digits
25 * @param fileNameMC
26 * @param fileNameEx
27 * @param fileNameDST
28 * @param aClusterSizeThr cluster size lower threshold
29 * @param aLowThr strip signal lower threshold
30 */
32 TString fileNameEx,
33 TString fileNameDST,
34 Double_t aClusterSizeThr = 1.0,
35 Double_t aLowThr = 0.0)
36{
37 if (fileNameMC == "" || fileNameEx == "") {
38 cout << "Files need to be specified!" << endl;
39 return;
40 }
41 Int_t periodId = 7;
42 Int_t runId = 4649;
43 gStyle->SetOptStat(0);
44 Int_t ClusterSizeThr = aClusterSizeThr;
45 Double_t lowThr = aLowThr;
46 Int_t RescalingBins = 4e5;
47 Int_t xBins = 400;
48 Double_t xLow = 0.0;
49 Double_t xUp = 3200.0;
50 Int_t nCSize = 5;
51 const UInt_t Pad_Width = 1280;
52 const UInt_t Pad_Height = 720;
53 vector<EColor> cols = {kBlack, kBlue, kTeal, kViolet, kOrange};
54
55 bmnloadlibs(); // load libraries
56 // gSystem->Load("libBmnRecoTools");
57
58 vector<vector<vector<TH1D*>>> histSiliconStrip;
59 vector<vector<vector<TH1D*>>> histSiliconStripEx;
60 vector<PadInfo*> canStripPads;
61 UInt_t sumMods = 0;
62 UInt_t maxLayers = 0;
63 TString name;
64 TString xmlConfFileName = periodId == 7 ? "SiliconRunSpring2018.xml" : "SiliconRunSpring2017.xml";
65 xmlConfFileName = TString(getenv("VMCWORKDIR")) + "/parameters/silicon/XMLConfigs/" + xmlConfFileName;
66 printf("xmlConfFileName %s\n", xmlConfFileName.Data());
67 BmnSiliconStationSet* stationSet = new BmnSiliconStationSet(xmlConfFileName);
68 for (Int_t iStation = 0; iStation < stationSet->GetNStations(); iStation++) {
69 vector<vector<TH1D*>> rowGEM;
70 vector<vector<TH1D*>> rowGEM2;
71 BmnSiliconStation* st = stationSet->GetStation(iStation);
72 sumMods += st->GetNModules();
73 for (Int_t iModule = 0; iModule < st->GetNModules(); iModule++) {
74 vector<TH1D*> colGEM;
75 vector<TH1D*> colGEM2;
76 BmnSiliconModule* mod = st->GetModule(iModule);
77 Int_t nStripLayers = (iStation ? (mod->GetNStripLayers() / 2) : mod->GetNStripLayers());
78 if (maxLayers < nStripLayers)
79 maxLayers = nStripLayers;
80 for (Int_t iLayer = 0; iLayer < nStripLayers; iLayer++) {
81 BmnSiliconLayer lay = mod->GetStripLayer(iLayer);
82 name = Form("Silicon_Station_%d_module_%d_layer_%d", iStation, iModule, iLayer);
83 TH1D* h = new TH1D(name, name, xBins, xLow, xUp);
84 h->SetTitleSize(0.06, "XY");
85 h->SetLabelSize(0.08, "XY");
86 h->GetXaxis()->SetTitle("Signal");
87 h->GetXaxis()->SetTitleColor(kOrange + 10);
88 h->GetYaxis()->SetTitle("Activation Count");
89 h->GetYaxis()->SetTitleColor(kOrange + 10);
90 colGEM.push_back(h);
91 name = Form("Silicon_Station_%d_module_%d_layer_%d_Ex", iStation, iModule, iLayer);
92 TH1D* h2 = new TH1D(name, name, xBins, xLow, xUp);
93 h2->SetTitleSize(0.06, "XY");
94 h2->SetLabelSize(0.08, "XY");
95 h2->GetXaxis()->SetTitle("Signal");
96 h2->GetXaxis()->SetTitleOffset(0.5);
97 h2->GetXaxis()->SetTitleColor(kOrange + 10);
98 h2->GetYaxis()->SetTitle("Activation Count");
99 h2->GetYaxis()->SetTitleOffset(0.5);
100 h2->GetYaxis()->SetTitleColor(kOrange + 10);
101 colGEM2.push_back(h2);
102 }
103 rowGEM.push_back(colGEM);
104 rowGEM2.push_back(colGEM2);
105 }
106 histSiliconStrip.push_back(rowGEM);
107 histSiliconStripEx.push_back(rowGEM2);
108 }
109 // Create canvas
110 name = "Si-full";
111 TCanvas* canStrip = new TCanvas(name, name, Pad_Width * maxLayers, Pad_Height * sumMods);
112 canStrip->Divide(maxLayers, sumMods);
113
114 BmnRescale* rescale = new BmnRescale(periodId, runId, lowThr, ClusterSizeThr, RescalingBins);
115 rescale->CreateRescales(fileNameMC, fileNameDST);
116 auto infoVecExp = rescale->GetSilInfoVectorExp();
117 auto ResVec = rescale->GetSilRescaleVector();
118
119 vector<vector<vector<TH1D*>>> hMC; // MC
120 vector<vector<vector<TH1D*>>> hMCR; // MC Rescaled
121 vector<vector<vector<TH1D*>>> hEx; // Exp
122 vector<vector<vector<TH1D*>>> hExCS;
123
124 // Load MC digits
125 TChain* chainMC = new TChain("bmndata");
126 chainMC->Add(fileNameMC.Data());
127 Long64_t NEventsMC = chainMC->GetEntries();
128 printf("#recorded MC entries = %lld\n", NEventsMC);
129 TClonesArray* gemMC = nullptr;
130 chainMC->SetBranchAddress("BmnSiliconDigit", &gemMC);
131
132 // Load Exp digits
133 TChain* chainEx = new TChain("bmndata");
134 chainEx->Add(fileNameEx.Data());
135 Long64_t NEventsEx = chainEx->GetEntries();
136 printf("#recorded Exp entries = %lld\n", NEventsEx);
137 TClonesArray* gemEx = nullptr;
138 chainEx->SetBranchAddress("SILICON", &gemEx);
139
140 // Load tracks
141 TChain* chainDST = new TChain("bmndata");
142 chainDST->Add(fileNameDST.Data());
143 Long64_t NEventsDST = chainDST->GetEntries();
144 printf("#recorded Track entries = %lld\n", NEventsDST);
145 TClonesArray* tracks = nullptr;
146 TClonesArray* gemTracks = nullptr;
147 TClonesArray* gemHits = nullptr;
148 chainDST->SetBranchAddress("BmnGlobalTrack", &tracks);
149 chainDST->SetBranchAddress("BmnSiliconTrack", &gemTracks);
150 chainDST->SetBranchAddress("BmnSiliconHit", &gemHits);
151
152 printf("rescaling func created\n");
153
154 TString title = "Si MC Rescaled";
155 TH1D* hGemMC = new TH1D("mc", title, xBins, xLow, xUp);
156 title = "Si Exp ";
157 TH1D* hGemEx = new TH1D("digs", title, xBins, xLow, xUp);
158 title = "Si Exp Hits' Digits";
159 TH1D* hGemExHits = new TH1D("digs-hits", title, xBins, xLow, xUp);
160 title = "Si Exp Cluster Signal Lower";
161 TH1D* hGemExCS = new TH1D("cluster-signal-upper", title, xBins, xLow, xUp);
162 title = "Si Exp Tracks' Digits";
163 TH1D* hGemExTracks = new TH1D("digs-tracks", title, xBins, xLow, xUp);
164 vector<TH1D*> hGemCluster;
165 for (Int_t i = 0; i < nCSize; i++) {
166 title = "Si Cluster Size";
167 TH1D* h = new TH1D(Form("si csize %.d", i), title, xBins, xLow, xUp);
168 hGemCluster.push_back(h);
169 }
170
171 for (Long64_t iEv = 0; iEv < NEventsEx; ++iEv) {
172 DrawBar((UInt_t)iEv, (UInt_t)NEventsEx);
173 chainEx->GetEntry(iEv);
174 chainDST->GetEntry(iEv);
175 // /** summ strip signals */
176 //
177 // /** digs all*/
178 // for (UInt_t iDig = 0; iDig < gemEx->GetEntriesFast(); iDig++) {
179 // BmnStripDigit * dig = (BmnStripDigit*) gemEx->At(iDig);
180 // Double_t signal = dig->GetStripSignal();
181 // dig->SetName(""); // clear marks
182 // hGemEx->Fill(signal);
183 // }
184 //
185 /** digs from hits*/
186 for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++) {
187 BmnGlobalTrack* track = (BmnGlobalTrack*)tracks->UncheckedAt(iTrack);
188 BmnTrack* subTrack = nullptr;
189 if ((track->GetSilTrackIndex() != -1))
190 subTrack = static_cast<BmnTrack*>(gemTracks->UncheckedAt(track->GetSilTrackIndex()));
191 if (!subTrack)
192 continue;
193 for (Int_t iHit = 0; iHit < subTrack->GetNHits(); iHit++) {
194 // for (Int_t iHit = 0; iHit < gemHits->GetEntriesFast(); iHit++) {
195 BmnSiliconHit* hit = (BmnSiliconHit*)gemHits->UncheckedAt(subTrack->GetHitIndex(iHit));
196 if (hit->GetFlag() == kFALSE)
197 continue;
198 // fill cluster signal for different cluster sizes
199 hGemCluster[0]->Fill(hit->GetStripTotalSignalInLowerLayer());
200 Int_t s = hit->GetStation();
201 Int_t m = hit->GetModule();
202 BmnSiliconModule* mod = stationSet->GetStation(s)->GetModule(m);
203 for (Int_t l = 0; l < mod->GetStripLayers().size(); l++) {
204 BmnSiliconLayer lay = mod->GetStripLayer(l);
205 Double_t x = hit->GetX();
206 Double_t y = hit->GetY();
207 if (lay.IsPointInsideStripLayer(-x, y)) {
208 hit->SetFlag(kFALSE);
209 Int_t iLayCorr = (s > 0) ? (l / 2) : l;
214 if ((val > lowThr) && (cs > ClusterSizeThr)) {
215 if (histSiliconStripEx[s][m][iLayCorr])
216 histSiliconStripEx[s][m][iLayCorr]->Fill(val);
217 else
218 printf("WTF? histStripEx[%d][%d][%d] == NULL!\n", s, m, l);
219 hGemExCS->Fill(hit->GetStripTotalSignalInLowerLayer());
220 }
221 }
222 }
223 }
224 }
225 // clear marks
226 for (Int_t iHit = 0; iHit < gemHits->GetEntriesFast(); iHit++) {
227 BmnHit* hit = static_cast<BmnHit*>(gemHits->UncheckedAt(iHit));
228 hit->SetFlag(kTRUE);
229 }
230 for (UInt_t iDig = 0; iDig < gemEx->GetEntriesFast(); iDig++) {
231 BmnStripDigit* dig = (BmnStripDigit*)gemEx->At(iDig);
232 dig->SetName("");
233 }
234 }
235 printf("Exp histograms filled\n");
236
237 // title = "Si-rescaled";
238 // TCanvas* can = new TCanvas(title, title, 1600, 900);
239 // can->SetLogy();
240 // hGemEx->SetLineColor(kBlack);
241 // if (hGemEx->Integral() > 0)
242 // hGemEx->Scale(1 / hGemEx->Integral());
243 // hGemEx->SetMinimum(3e-4);
244 // hGemEx->SetMaximum(5e-2);
245 // hGemEx->Draw();
246 // hGemExHits->SetLineColor(kBlue);
247 // // hGemExHits->DrawNormalized("same");
248 // hGemExCS->SetLineColor(kViolet);
249 // hGemExCS->DrawNormalized("same");
250 // hGemExTracks->SetLineColor(kTeal);
251 // // hGemExTracks->DrawNormalized("same");
252
253 for (Long64_t iEv = 0; iEv < NEventsMC; ++iEv) {
254 // printf("iev %lld\n", iEv);
255 DrawBar((UInt_t)iEv, (UInt_t)NEventsMC);
256 chainMC->GetEntry(iEv);
257 /** summ strip signals */
258 for (UInt_t iDig = 0; iDig < gemMC->GetEntriesFast(); iDig++) {
259 BmnStripDigit* dig = (BmnStripDigit*)gemMC->At(iDig);
260 if (dig->GetStripSignal() <= lowThr)
261 continue;
262 Int_t s = dig->GetStation();
263 Int_t m = dig->GetModule();
264 Int_t l = dig->GetStripLayer();
265 TF1* func = ResVec[s][m][l];
266 if (!func)
267 continue;
268 Double_t val = dig->GetStripSignal();
269 histSiliconStrip[s][m][l]->Fill(func->Eval(val));
270 }
271 }
272 printf("MC histogram filled\n");
273 //// hGemMC->SetLineColor(kRed);
274 //// hGemMC->DrawNormalized("same");
275 //
276 // auto legend = new TLegend(0.6, 0.65, 0.8, 0.9);
277 // legend->SetHeader("The Legend", "C");
278 // legend->AddEntry(hGemEx, "All digits"); // lpfe
279 // // legend->AddEntry(hGemExHits, "Digits from hits");
280 // legend->AddEntry(hGemExCS, "Cluster signal lower");
281 // // legend->AddEntry(hGemExTracks, "Digits from tracks");
282 // legend->AddEntry(hGemMC, "MC rescaled by cluster exp");
283 // legend->Draw();
284 //
285 // can->Print(Form("%s-th-%.1f-cs-%d-Lower-up500-2m.pdf", can->GetName(), lowThr, ClusterSizeThr));
286 // can->Clear();
287 //
288 // can->SetLogy(kFALSE);
289 // auto legendCluster = new TLegend(0.4, 0.65, 0.6, 0.9);
290 // for (Int_t i = 0; i < nCSize; i++) {
291 // hGemCluster[i]->SetLineColor(cols[i]);
292 // hGemCluster[i]->Draw(i == 0 ? "" : "same");
293 // legendCluster->AddEntry(hGemCluster[i], hGemCluster[i]->GetName());
294 // }
295 // legendCluster->Draw();
296 // can->Print(Form("%s-cluster-Lower.pdf", can->GetName()));
297 // can->Clear();
298
299 Int_t modCtr = 0;
300 for (Int_t iStation = 0; iStation < stationSet->GetNStations(); iStation++) {
301 BmnSiliconStation* st = stationSet->GetStation(iStation);
302 for (Int_t iModule = 0; iModule < st->GetNModules(); iModule++) {
303 BmnSiliconModule* mod = st->GetModule(iModule);
304 for (Int_t iLayer = 0; iLayer < (iStation ? (mod->GetNStripLayers() / 2) : mod->GetNStripLayers());
305 iLayer++)
306 {
307 BmnSiliconLayer lay = mod->GetStripLayer(iLayer);
308 Int_t iPad = modCtr * maxLayers + iLayer;
309 TVirtualPad* pad = canStrip->cd(iPad + 1);
310 pad->Clear();
311 pad->SetLogy();
312
313 TH1D* hR = histSiliconStrip[iStation][iModule][iLayer];
314 if (!hR)
315 continue;
316 if (hR->GetIntegral() == 0)
317 continue;
318 hR->SetLineColor(kRed);
319 hR->DrawNormalized();
320
321 // TH1D *hExp = infoVecExp[iStation][iModule][iLayer]->hSig;
322 TH1D* hExp = histSiliconStripEx[iStation][iModule][iLayer];
323 if (!hExp)
324 continue;
325 if (hExp->GetIntegral() == 0)
326 continue;
327 hExp->SetLineColor(kViolet);
328 hExp->DrawNormalized("same");
329
330 auto legend = new TLegend(0.6, 0.65, 0.8, 0.9);
331 legend->SetHeader("The Legend", "C");
332 legend->AddEntry(hExp, "Cluster signal");
333 legend->AddEntry(hR, "MC rescaled by cluster exp");
334 legend->Draw();
335
336 pad->Update();
337 pad->Modified();
338 }
339 modCtr++;
340 }
341 }
342 // canStrip->SaveAs("rescale-sil-strip.png");
343 // canStrip->Print(Form("%s-th-%.1f-cs-%d-2m.pdf", canStrip->GetName(), lowThr, ClusterSizeThr));
344 canStrip->Print(Form("%s-th-%.1f-cs-%d-tracks.png", canStrip->GetName(), lowThr, ClusterSizeThr));
345
346 // delete can;
347 delete hGemEx;
348 delete hGemExHits;
349 delete hGemExTracks;
350 delete hGemMC;
351 // delete legend;
352 // delete legendCluster;
353 delete chainMC;
354 delete chainEx;
355}
void DrawBar(UInt_t iEv, UInt_t nEv)
Definition BmnMath.cxx:940
int i
Definition P4_F32vec4.h:22
__m128 m
Definition P4_F32vec4.h:27
int Int_t
unsigned int UInt_t
constexpr Bool_t kFALSE
double Double_t
long long Long64_t
constexpr Bool_t kTRUE
#define R__ADD_INCLUDE_PATH(PATH)
kTeal
kRed
kOrange
kBlack
kBlue
kViolet
char * Form(const char *fmt,...)
R__EXTERN TStyle * gStyle
@ UpperStripLayer
BmnGlobalTrack.h.
Bool_t GetFlag() const
Definition BmnHit.h:31
Int_t GetModule()
Definition BmnHit.h:36
void SetFlag(Bool_t fl)
Definition BmnHit.h:48
Short_t GetStation() const
Definition BmnHit.h:35
BmnRescale - class implementing ADC signal rescaling specific for each strip plane.
Definition BmnRescale.h:92
BmnStatus CreateRescales(TString fileNameMC, TString fileNameEx)
vector< vector< vector< TF1 * > > > GetSilRescaleVector()
Definition BmnRescale.h:110
vector< vector< vector< BmnSigInfo * > > > GetSilInfoVectorExp()
Definition BmnRescale.h:116
Double_t GetStripTotalSignalInLowerLayer()
Strip layer characteristics of the hit (total signal, cluster size, strip position as the cluster mea...
Double_t GetStripTotalSignalInUpperLayer()
Int_t GetClusterSizeInLowerLayer()
Int_t GetClusterSizeInUpperLayer()
Bool_t IsPointInsideStripLayer(Double_t x, Double_t y)
StripLayerType GetType()
vector< BmnSiliconLayer > & GetStripLayers()
BmnSiliconLayer & GetStripLayer(Int_t num)
BmnSiliconStation * GetStation(Int_t station_num)
BmnSiliconModule * GetModule(Int_t module_num)
Class BmnStripDigit Base class for strip detector digits.
Int_t GetStripLayer()
Int_t GetStation()
Double_t GetStripSignal()
Int_t GetModule()
Int_t GetNHits() const
Accessors.
Definition BmnTrack.h:49
Int_t GetHitIndex(Int_t iHit) const
Definition BmnTrack.h:51
virtual void SetTitleOffset(Float_t offset=1)
virtual void SetTitleColor(Color_t color=1)
virtual void SetLineColor(Color_t lcolor)
TVirtualPad * cd(Int_t subpadnumber=0) override
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
virtual Int_t Add(const char *name, Long64_t nentries=TTree::kMaxEntries)
Long64_t GetEntries() const override
Int_t GetEntry(Long64_t entry=0, Int_t getall=0) override
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
virtual void SetTitleSize(Float_t size=0.02, Option_t *axis="X")
virtual TH1 * DrawNormalized(Option_t *option="", Double_t norm=1) const
TAxis * GetXaxis()
TAxis * GetYaxis()
virtual Int_t Fill(const char *name, Double_t w)
virtual Double_t * GetIntegral()
virtual void SetLabelSize(Float_t size=0.02, Option_t *axis="X")
virtual void SetTitle(const char *title="")
virtual void SetName(const char *name)
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
TObject * UncheckedAt(Int_t i) const
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
void Print(const char *filename, Option_t *option) override
const char * GetName() const override
const char * Data() const
virtual void Modified(Bool_t flag=1)=0
virtual void Update()=0
virtual void SetLogy(Int_t value=1)=0
void Clear(Option_t *option="") override=0
void rescaleAmplitudeSi(TString fileNameMC, TString fileNameEx, TString fileNameDST, Double_t aClusterSizeThr=1.0, Double_t aLowThr=0.0)
rescaleAmplitudes Example of ADC signal rescaling procedures for Si strip digits