BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
rescaleAmplitudeCSC.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 CSC 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 = 1e5;
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 ? "CSCRunSpring2018.xml" : "CSCRunSpring2017.xml";
65 xmlConfFileName = TString(getenv("VMCWORKDIR")) + "/parameters/csc/XMLConfigs/" + xmlConfFileName;
66 printf("xmlConfFileName %s\n", xmlConfFileName.Data());
67 BmnCSCStationSet* stationSet = new BmnCSCStationSet(xmlConfFileName);
68 for (Int_t iStation = 0; iStation < stationSet->GetNStations(); iStation++) {
69 vector<vector<TH1D*>> rowGEM;
70 vector<vector<TH1D*>> rowGEM2;
71 BmnCSCStation* 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 BmnCSCModule* mod = st->GetModule(iModule);
77 Int_t nStripLayers = mod->GetNStripLayers();
78 if (maxLayers < nStripLayers)
79 maxLayers = nStripLayers;
80 for (Int_t iLayer = 0; iLayer < nStripLayers; iLayer++) {
81 BmnCSCLayer lay = mod->GetStripLayer(iLayer);
82 name = Form("CSC_Station_%d_module_%d_layer_%d", iStation, iModule, iLayer);
83 TH1D* h = new TH1D(name, name, xBins, 0, 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("CSC_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 = "CSC-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->GetCSCInfoVectorExp();
117 auto ResVec = rescale->GetCSCRescaleVector();
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("BmnCSCDigit", &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("CSC", &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* gemHits = nullptr;
147 chainDST->SetBranchAddress("BmnGlobalTrack", &tracks);
148 chainDST->SetBranchAddress("BmnCSCHit", &gemHits);
149
150 printf("rescaling func created\n");
151
152 TString title = "CSC MC Rescaled";
153 TH1D* hGemMC = new TH1D("mc", title, xBins, xLow, xUp);
154 title = "CSC Exp ";
155 TH1D* hGemEx = new TH1D("digs", title, xBins, xLow, xUp);
156 title = "CSC Exp Hits' Digits";
157 TH1D* hGemExHits = new TH1D("digs-hits", title, xBins, xLow, xUp);
158 title = "CSC Exp Cluster Signal Lower";
159 TH1D* hGemExCS = new TH1D("cluster-signal-upper", title, xBins, xLow, xUp);
160 title = "CSC Exp Tracks' Digits";
161 TH1D* hGemExTracks = new TH1D("digs-tracks", title, xBins, xLow, xUp);
162 vector<TH1D*> hGemCluster;
163 for (Int_t i = 0; i < nCSize; i++) {
164 title = "CSC Cluster Size";
165 TH1D* h = new TH1D(Form("csc csize %.d", i), title, xBins, xLow, xUp);
166 hGemCluster.push_back(h);
167 }
168
169 for (Long64_t iEv = 0; iEv < NEventsEx; ++iEv) {
170 DrawBar((UInt_t)iEv, (UInt_t)NEventsEx);
171 chainEx->GetEntry(iEv);
172 chainDST->GetEntry(iEv);
173 // /** summ strip signals */
174 //
175 // /** digs all*/
176 // for (UInt_t iDig = 0; iDig < gemEx->GetEntriesFast(); iDig++) {
177 // BmnStripDigit * dig = (BmnStripDigit*) gemEx->At(iDig);
178 // Double_t signal = dig->GetStripSignal();
179 // dig->SetName(""); // clear marks
180 // hGemEx->Fill(signal);
181 // }
182 //
183 /** digs from hits*/
184 // for (Int_t iHit = 0; iHit < gemHits->GetEntriesFast(); iHit++) {
185 // BmnCSCHit *hit = (BmnCSCHit *) gemHits->UncheckedAt(iHit);
186 /** digs from hits of tracks*/
187 for (Int_t iTrack = 0; iTrack < tracks->GetEntriesFast(); iTrack++) {
188 BmnGlobalTrack* track = (BmnGlobalTrack*)tracks->UncheckedAt(iTrack);
189 if (track->GetCscHitIndex() != -1) {
190 BmnCSCHit* hit = (BmnCSCHit*)gemHits->UncheckedAt(track->GetCscHitIndex());
191 if (hit->GetFlag() == kFALSE)
192 continue;
193 // fill cluster signal for different cluster sizes
194 hGemCluster[0]->Fill(hit->GetStripTotalSignalInLowerLayer());
195 Int_t s = hit->GetStation();
196 Int_t m = hit->GetModule();
197 BmnCSCModule* mod = stationSet->GetStation(s)->GetModule(m);
198 for (Int_t l = 0; l < mod->GetStripLayers().size(); l++) {
199 BmnCSCLayer lay = mod->GetStripLayer(l);
200 Double_t x = hit->GetX();
201 Double_t y = hit->GetY();
202 if (lay.IsPointInsideStripLayer(-x, y)) {
203 hit->SetFlag(kFALSE);
208 if ((val > lowThr) && (cs > ClusterSizeThr)) {
209 if (histSiliconStripEx[s][m][l])
210 histSiliconStripEx[s][m][l]->Fill(val);
211 else
212 printf("WTF? histStripEx[%d][%d][%d] == NULL!\n", s, m, l);
213 hGemExCS->Fill(hit->GetStripTotalSignalInLowerLayer());
214 }
215 }
216 }
217 }
218 }
219 // clear marks
220 for (Int_t iHit = 0; iHit < gemHits->GetEntriesFast(); iHit++) {
221 BmnHit* hit = static_cast<BmnHit*>(gemHits->UncheckedAt(iHit));
222 hit->SetFlag(kTRUE);
223 }
224 for (UInt_t iDig = 0; iDig < gemEx->GetEntriesFast(); iDig++) {
225 BmnStripDigit* dig = (BmnStripDigit*)gemEx->At(iDig);
226 dig->SetName("");
227 }
228 }
229 printf("Exp histograms filled\n");
230
231 // title = "Si-rescaled";
232 // TCanvas* can = new TCanvas(title, title, 1600, 900);
233 // can->SetLogy();
234 // hGemEx->SetLineColor(kBlack);
235 // if (hGemEx->Integral() > 0)
236 // hGemEx->Scale(1 / hGemEx->Integral());
237 // hGemEx->SetMinimum(3e-4);
238 // hGemEx->SetMaximum(5e-2);
239 // hGemEx->Draw();
240 // hGemExHits->SetLineColor(kBlue);
241 // // hGemExHits->DrawNormalized("same");
242 // hGemExCS->SetLineColor(kViolet);
243 // hGemExCS->DrawNormalized("same");
244 // hGemExTracks->SetLineColor(kTeal);
245 // // hGemExTracks->DrawNormalized("same");
246
247 for (Long64_t iEv = 0; iEv < NEventsMC; ++iEv) {
248 DrawBar((UInt_t)iEv, (UInt_t)NEventsMC);
249 chainMC->GetEntry(iEv);
250 /** summ strip signals */
251 for (UInt_t iDig = 0; iDig < gemMC->GetEntriesFast(); iDig++) {
252 BmnStripDigit* dig = (BmnStripDigit*)gemMC->At(iDig);
253 if (dig->GetStripSignal() <= lowThr)
254 continue;
255 Int_t s = dig->GetStation();
256 Int_t m = dig->GetModule();
257 Int_t l = dig->GetStripLayer();
258 TF1* func = ResVec[s][m][l];
259 if (!func)
260 continue;
261 Double_t val = dig->GetStripSignal();
262 histSiliconStrip[s][m][l]->Fill(func->Eval(val));
263 }
264 }
265 printf("MC histogram filled\n");
266 //// hGemMC->SetLineColor(kRed);
267 //// hGemMC->DrawNormalized("same");
268 //
269 // auto legend = new TLegend(0.6, 0.65, 0.8, 0.9);
270 // legend->SetHeader("The Legend", "C");
271 // legend->AddEntry(hGemEx, "All digits"); // lpfe
272 // // legend->AddEntry(hGemExHits, "Digits from hits");
273 // legend->AddEntry(hGemExCS, "Cluster signal lower");
274 // // legend->AddEntry(hGemExTracks, "Digits from tracks");
275 // legend->AddEntry(hGemMC, "MC rescaled by cluster exp");
276 // legend->Draw();
277 //
278 // can->Print(Form("%s-th-%.1f-cs-%d-Lower-up500-2m.pdf", can->GetName(), lowThr, ClusterSizeThr));
279 // can->Clear();
280 //
281 // can->SetLogy(kFALSE);
282 // auto legendCluster = new TLegend(0.4, 0.65, 0.6, 0.9);
283 // for (Int_t i = 0; i < nCSize; i++) {
284 // hGemCluster[i]->SetLineColor(cols[i]);
285 // hGemCluster[i]->Draw(i == 0 ? "" : "same");
286 // legendCluster->AddEntry(hGemCluster[i], hGemCluster[i]->GetName());
287 // }
288 // legendCluster->Draw();
289 // can->Print(Form("%s-cluster-Lower.pdf", can->GetName()));
290 // can->Clear();
291
292 Int_t modCtr = 0;
293 for (Int_t iStation = 0; iStation < stationSet->GetNStations(); iStation++) {
294 BmnCSCStation* st = stationSet->GetStation(iStation);
295 for (Int_t iModule = 0; iModule < st->GetNModules(); iModule++) {
296 BmnCSCModule* mod = st->GetModule(iModule);
297 for (Int_t iLayer = 0; iLayer < mod->GetNStripLayers(); iLayer++) {
298 BmnCSCLayer lay = mod->GetStripLayer(iLayer);
299 Int_t iPad = modCtr * maxLayers + iLayer;
300 TVirtualPad* pad = canStrip->cd(iPad + 1);
301 pad->Clear();
302 pad->SetLogy();
303
304 TH1D* hR = histSiliconStrip[iStation][iModule][iLayer];
305 if (!hR)
306 continue;
307 if (hR->GetIntegral() == 0)
308 continue;
309 hR->SetLineColor(kRed);
310 hR->DrawNormalized();
311
312 // TH1D *hExp = infoVecExp[iStation][iModule][iLayer]->hSig;
313 TH1D* hExp = histSiliconStripEx[iStation][iModule][iLayer];
314 if (!hExp)
315 continue;
316 if (hExp->GetIntegral() == 0)
317 continue;
318 hExp->SetLineColor(kViolet);
319 hExp->DrawNormalized("same");
320
321 auto legend = new TLegend(0.6, 0.65, 0.8, 0.9);
322 legend->SetHeader("The Legend", "C");
323 legend->AddEntry(hExp, "Cluster signal");
324 legend->AddEntry(hR, "MC rescaled by cluster exp");
325 legend->Draw();
326
327 pad->Update();
328 pad->Modified();
329 }
330 modCtr++;
331 }
332 }
333 // canStrip->SaveAs("rescale-sil-strip.png");
334 // canStrip->Print(Form("%s-th-%.1f-cs-%d-2m.pdf", canStrip->GetName(), lowThr, ClusterSizeThr));
335 canStrip->Print(Form("%s-th-%.1f-cs-%d-tracks.png", canStrip->GetName(), lowThr, ClusterSizeThr));
336
337 // delete can;
338 delete hGemEx;
339 delete hGemExHits;
340 delete hGemExTracks;
341 delete hGemMC;
342 // delete legend;
343 // delete legendCluster;
344 delete chainMC;
345 delete chainEx;
346}
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
Double_t GetStripTotalSignalInLowerLayer()
Strip layer characteristics of the hit (total signal, cluster size, strip position as the cluster mea...
Definition BmnCSCHit.cxx:20
Double_t GetStripTotalSignalInUpperLayer()
Definition BmnCSCHit.cxx:26
Int_t GetClusterSizeInLowerLayer()
Definition BmnCSCHit.cxx:32
Int_t GetClusterSizeInUpperLayer()
Definition BmnCSCHit.cxx:38
StripLayerType GetType()
Definition BmnCSCLayer.h:50
Bool_t IsPointInsideStripLayer(Double_t x, Double_t y)
vector< BmnCSCLayer > & GetStripLayers()
Int_t GetNStripLayers()
BmnCSCLayer & GetStripLayer(Int_t num)
BmnCSCStation * GetStation(Int_t station_num)
Int_t GetNModules()
BmnCSCModule * GetModule(Int_t module_num)
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< BmnSigInfo * > > > GetCSCInfoVectorExp()
Definition BmnRescale.h:118
vector< vector< vector< TF1 * > > > GetCSCRescaleVector()
Definition BmnRescale.h:112
Class BmnStripDigit Base class for strip detector digits.
Int_t GetStripLayer()
Int_t GetStation()
Double_t GetStripSignal()
Int_t GetModule()
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 rescaleAmplitudeCSC(TString fileNameMC, TString fileNameEx, TString fileNameDST, Double_t aClusterSizeThr=1.0, Double_t aLowThr=0.0)
rescaleAmplitudes Example of ADC signal rescaling procedures for CSC strip digits