BmnRoot
Loading...
Searching...
No Matches
BmnRescale.cxx
Go to the documentation of this file.
1#include "BmnRescale.h"
2
4 UInt_t periodId, UInt_t runId,
5 Double_t lowThr,
6 Double_t ClusterSizeThr,
7 Int_t nBins) {
8 fPeriodId = periodId;
9 fRunId = runId;
10 fSetup = (fRunId >= 2041 && fRunId <= 3588) ? kSRCSETUP : kBMNSETUP;
11 fLowThr = lowThr;
12 fClusterSizeThr = ClusterSizeThr;
13 fNBins = nBins;
14 CreateStripVectors();
15}
16
18 FreeVector3D<BmnSigInfo>(fStripGemInfoMC);
19 FreeVector3D<BmnSigInfo>(fStripSilInfoMC);
20 FreeVector3D<BmnSigInfo>(fStripCSCInfoMC);
21 FreeVector3D<BmnSigInfo>(fStripGemInfoEx);
22 FreeVector3D<BmnSigInfo>(fStripSilInfoEx);
23 FreeVector3D<BmnSigInfo>(fStripCSCInfoEx);
24 FreeVector3D<TF1>(fStripGemRescale);
25 FreeVector3D<TF1>(fStripSilRescale);
26 FreeVector3D<TF1>(fStripCSCRescale);
27 delete fGemStationSet;
28 delete fSilStationSet;
29 delete fCscStationSet;
30}
31
32void BmnRescale::CreateStripVectors() {
33 TString xmlConfFileNameGEM;
34 TString xmlConfFileNameSil;
35 TString xmlConfFileNameCSC;
36 // Select xml configs
37 switch (fPeriodId) {
38 case 7:
39 if (fSetup == kBMNSETUP) {
40 xmlConfFileNameGEM = "GemRunSpring2018.xml";
41 xmlConfFileNameSil = "SiliconRunSpring2018.xml";
42 xmlConfFileNameCSC = "CSCRunSpring2018.xml";
43 } else {
44 xmlConfFileNameGEM = "GemRunSRCSpring2018.xml";
45 xmlConfFileNameSil = "SiliconRunSRCSpring2018.xml";
46 xmlConfFileNameCSC = "CSCRunSRCSpring2018.xml";
47 }
48 break;
49 case 6:
50 xmlConfFileNameGEM = "GemRunSpring2017.xml";
51 xmlConfFileNameSil = "SiliconRunSpring2017.xml";
52 break;
53 default:
54 printf("Error! Unknown config!\n");
55 return;
56 break;
57
58 }
59 // create 3d vectors for functions for all stations/modules/planes
60 if (xmlConfFileNameGEM.Length() > 0) {
61 xmlConfFileNameGEM = TString(getenv("VMCWORKDIR")) + "/parameters/gem/XMLConfigs/" + xmlConfFileNameGEM;
62 printf("xmlConfFileName %s\n", xmlConfFileNameGEM.Data());
63 fGemStationSet = new BmnGemStripStationSet(xmlConfFileNameGEM);
64 FillInfoVector<BmnGemStripStationSet, BmnGemStripStation, BmnGemStripModule>(
65 fGemStationSet, fStripGemInfoMC);
66 FillInfoVector<BmnGemStripStationSet, BmnGemStripStation, BmnGemStripModule>(
67 fGemStationSet, fStripGemInfoEx);
68 }
69 if (xmlConfFileNameSil.Length() > 0) {
70 xmlConfFileNameSil = TString(getenv("VMCWORKDIR")) + "/parameters/silicon/XMLConfigs/" + xmlConfFileNameSil;
71 printf("xmlConfFileName %s\n", xmlConfFileNameSil.Data());
72 fSilStationSet = new BmnSiliconStationSet(xmlConfFileNameSil);
73 FillInfoVector<BmnSiliconStationSet, BmnSiliconStation, BmnSiliconModule>(
74 fSilStationSet, fStripSilInfoMC);
75 FillInfoVector<BmnSiliconStationSet, BmnSiliconStation, BmnSiliconModule>(
76 fSilStationSet, fStripSilInfoEx);
77
78 }
79 if (xmlConfFileNameCSC.Length() > 0) {
80 xmlConfFileNameCSC = TString(getenv("VMCWORKDIR")) + "/parameters/csc/XMLConfigs/" + xmlConfFileNameCSC;
81 printf("xmlConfFileName %s\n", xmlConfFileNameCSC.Data());
82 fCscStationSet = new BmnCSCStationSet(xmlConfFileNameCSC);
83 FillInfoVector<BmnCSCStationSet, BmnCSCStation, BmnCSCModule>(
84 fCscStationSet, fStripCSCInfoMC);
85 FillInfoVector<BmnCSCStationSet, BmnCSCStation, BmnCSCModule>(
86 fCscStationSet, fStripCSCInfoEx);
87 }
88}
89
90TF1* BmnRescale::GetRescaleFunc(TString name, TF1 *mc, TF1 *ex) {
91 if (!mc || !ex)
92 return nullptr;
93 TF1 *funcRescale = new TF1(name,
94 [mc, ex](Double_t *x, Double_t * p) {
95 Double_t r = mc->Eval(x[0]);
96 Double_t f = ex->GetX(r); //, ex->GetXmin(), ex->GetXmax(), 1.E-15, 100, kTRUE);
97 // printf("x = %f mc = %f y = %f\n", x[0], r, f);
98 return f;
99 }, mc->GetXmin(), mc->GetXmax(), 0);
100 return funcRescale;
101}
102
103BmnStatus BmnRescale::LoadDigitDistributionsFromFile(
104 TString fileName,
105 vector<TString> digiNames,
106 vector<vector<vector<vector<BmnSigInfo* > > > > digiVecs) {
107 vector<TClonesArray*> ars;
108 TChain* chain = new TChain("bmndata");
109 chain->Add(fileName.Data());
110 Long64_t NEventsMC = chain->GetEntries();
111 printf("%s recorded entries = %lld\n", fileName.Data(), NEventsMC);
112 for (TString &digiName : digiNames) {
113 TClonesArray* arDigi = nullptr;
114 chain->SetBranchAddress(digiName.Data(), &arDigi);
115 ars.push_back(arDigi);
116 }
117 for (size_t i = 0; i < digiVecs.size(); i++)
118 CreateDigitDistributions(chain, ars[i], digiVecs[i]);
119 delete chain;
120 return kBMNSUCCESS;
121}
122
123BmnStatus BmnRescale::LoadClusterDistributionsFromFile(
124 TString fileName,
125 vector<TString> hitNames,
126 vector<vector<vector<vector<BmnSigInfo* > > > > clusterVecs) {
127 vector<TClonesArray*> hitArr;
128 TChain* chain = new TChain("bmndata");
129 chain->Add(fileName.Data());
130 Long64_t NEvents = chain->GetEntries();
131 printf("%s recorded entries = %lld\n", fileName.Data(), NEvents);
132 for (TString &hitName : hitNames) {
133 TClonesArray* arDigi = nullptr;
134 chain->SetBranchAddress(hitName.Data(), &arDigi);
135 hitArr.push_back(arDigi);
136 }
137 // for (Int_t i = 0; i < fNArs; i++)
138 // CreateClusterDistributions(chain, ars[i], clusterVecs[i]);
139 CreateClusterDistributions<
144 BmnGemStripLayer>(chain, hitArr[0], fGemStationSet, clusterVecs[0]);
145 CreateClusterDistributions<
150 BmnSiliconLayer>(chain, hitArr[1], fSilStationSet, clusterVecs[1]);
151 CreateClusterDistributions<
152 BmnCSCHit,
156 BmnCSCLayer>(chain, hitArr[2], fCscStationSet, clusterVecs[2]);
157 delete chain;
158 return kBMNSUCCESS;
159}
160
161BmnStatus BmnRescale::LoadClustersOfTrackDistributionsFromFile(
162 TString fileName,
163 TString globalTrackName,
164 vector<TString> subTrackNames,
165 vector<TString> hitNames,
166 vector<vector<vector<vector<BmnSigInfo* > > > > clusterVecs) {
167 TClonesArray* globalTrackArr;
168 vector<TClonesArray*> subTrackArr;
169 vector<TClonesArray*> hitArr;
170 TChain* chain = new TChain("bmndata");
171 chain->Add(fileName.Data());
172 Long64_t NEvents = chain->GetEntries();
173 printf("%s recorded entries = %lld\n", fileName.Data(), NEvents);
174
175 chain->SetBranchAddress(globalTrackName.Data(), &globalTrackArr);
176
177 for (TString &subTrackName : subTrackNames) {
178 TClonesArray* arDigi = nullptr;
179 if (subTrackName.Length() > 0)
180 chain->SetBranchAddress(subTrackName.Data(), &arDigi);
181 subTrackArr.push_back(arDigi);
182 }
183 for (TString &hitName : hitNames) {
184 TClonesArray* arDigi = nullptr;
185 chain->SetBranchAddress(hitName.Data(), &arDigi);
186 hitArr.push_back(arDigi);
187 }
188 // for (Int_t i = 0; i < fNArs; i++)
189 // CreateClusterDistributions(chain, ars[i], clusterVecs[i]);
190 CreateClusterDistributions<
195 BmnGemStripLayer>(chain, globalTrackArr, subTrackArr[0], hitArr[0], fGemStationSet, clusterVecs[0]);
196 CreateClusterDistributions<
201 BmnSiliconLayer>(chain, globalTrackArr, subTrackArr[1], hitArr[1], fSilStationSet, clusterVecs[1]);
202 CreateClusterDistributions<
203 BmnCSCHit,
207 BmnCSCLayer>(chain, globalTrackArr, nullptr, hitArr[2], fCscStationSet, clusterVecs[2]);
208 delete chain;
209 return kBMNSUCCESS;
210}
211
212BmnStatus BmnRescale::CreateRescales(TString fileNameMC, TString fileNameEx) {
213 if (fileNameMC == "" || fileNameEx == "") {
214 cout << "Files need to be specified!" << endl;
215 return kBMNERROR;
216 }
217 TString GlobalTrackName = "BmnGlobalTrack";
218 vector<TString> mcDigiNames = {"BmnGemStripDigit", "BmnSiliconDigit", "BmnCSCDigit"};
219 auto mcVecs = {fStripGemInfoMC, fStripSilInfoMC, fStripCSCInfoMC};
220 LoadDigitDistributionsFromFile(fileNameMC, mcDigiNames, mcVecs);
221
222 vector<TString> subTrackNames = {"BmnGemTrack", "BmnSiliconTrack", ""};
223 vector<TString> hitNames = {"BmnGemStripHit", "BmnSiliconHit", "BmnCSCHit"};
224 // vector<TString> expDigiNames = {"SILICON", "GEM", "CSC"};
225 // LoadDigitDistributionsFromFile(fileNameEx, expDigiNames, expVecs);
226 auto expVecs = {fStripGemInfoEx, fStripSilInfoEx, fStripCSCInfoEx};
227 LoadClustersOfTrackDistributionsFromFile(fileNameEx, GlobalTrackName, subTrackNames, hitNames, expVecs);
228
229 FillRescaleVector<BmnGemStripStationSet, BmnGemStripStation, BmnGemStripModule>(fGemStationSet, fStripGemInfoMC, fStripGemInfoEx, fStripGemRescale);
230 FillRescaleVector<BmnSiliconStationSet, BmnSiliconStation, BmnSiliconModule>(fSilStationSet, fStripSilInfoMC, fStripSilInfoEx, fStripSilRescale);
231 FillRescaleVector<BmnCSCStationSet, BmnCSCStation, BmnCSCModule>(fCscStationSet, fStripCSCInfoMC, fStripCSCInfoEx, fStripCSCRescale);
232
233 return kBMNSUCCESS;
234}
235
236void BmnRescale::CreateDigitDistributions(
237 TTree *treeDig, TClonesArray *digits,
238 vector<vector<vector<BmnSigInfo* > > > &infoVec) {
239 printf("CreateDigitDistributions started for %s\n", digits->GetClass()->GetName());
240 // Find bounds
241 for (Long64_t i = 0; i < treeDig->GetEntries(); i++) {
242 treeDig->GetEntry(i);
243 for (Int_t iHit = 0; iHit < digits->GetEntriesFast(); iHit++) {
244 BmnStripDigit *dig = static_cast<BmnStripDigit*> (digits->UncheckedAt(iHit));
245 Int_t s = dig->GetStation();
246 Int_t m = dig->GetModule();
247 Int_t l = dig->GetStripLayer();
248 BmnSigInfo* info = infoVec[s][m][l];
249 Double_t val = dig->GetStripSignal();
250 if (val > fLowThr) {
251 if (info->maxVal < val)
252 info->maxVal = val;
253 if (info->minVal > val)
254 info->minVal = val;
255 }
256 }
257 }
258 // Create histograms
259 for (size_t iStation = 0; iStation < infoVec.size(); iStation++) {
260 printf("iStation %zu\n", iStation);
261 for (size_t iModule = 0; iModule < infoVec[iStation].size(); iModule++) {
262 printf("\tiModule %zu\n", iModule);
263 for (size_t iLayer = 0; iLayer < infoVec[iStation][iModule].size(); iLayer++) {
264 printf("\t\tiLayer %zu\n", iLayer);
265 BmnSigInfo* info = infoVec[iStation][iModule][iLayer];
266 Double_t minVal = info->minVal;
267 Double_t maxVal = info->maxVal;
268 if (minVal > maxVal)
269 continue;
270 printf("\t\t\tMin = %f max = %f\n", minVal, maxVal);
271 TString name = Form("Sig_mc_%s_%zu_%zu_%zu",
272 digits->GetName(), iStation, iModule, iLayer);
273 info->hSig = new TH1D(name, name, fNBins,
274 minVal - 0.5 * (maxVal - minVal) / (Double_t) fNBins,
275 maxVal + 0.5 * (maxVal - minVal) / (Double_t) fNBins);
276 name = Form("IntSignal_%s_%zu_%zu_%zu",
277 digits->GetName(), iStation, iModule, iLayer);
278 info->hIntSig = new TH1D(name, name, fNBins,
279 minVal - 0.5 * (maxVal - minVal) / (Double_t) fNBins,
280 maxVal + 0.5 * (maxVal - minVal) / (Double_t) fNBins);
281 }
282 }
283 }
284 // Fill signal hists
285 for (Long64_t i = 0; i < treeDig->GetEntries(); i++) {
286 treeDig->GetEntry(i);
287 for (Int_t iHit = 0; iHit < digits->GetEntriesFast(); iHit++) {
288 BmnStripDigit *dig = static_cast<BmnStripDigit*> (digits->UncheckedAt(iHit));
289 Int_t s = dig->GetStation();
290 Int_t m = dig->GetModule();
291 Int_t l = dig->GetStripLayer();
292 BmnSigInfo* info = infoVec[s][m][l];
293 if (!(info->hSig))
294 continue;
295 Double_t val = dig->GetStripSignal();
296 if (val > fLowThr) {
297 info->hSig->Fill(val);
298 }
299 }
300 }
301 // Fill integral hists
302 for (size_t iStation = 0; iStation < infoVec.size(); iStation++) {
303 for (size_t iModule = 0; iModule < infoVec[iStation].size(); iModule++) {
304 for (size_t iLayer = 0; iLayer < infoVec[iStation][iModule].size(); iLayer++) {
305 BmnSigInfo* info = infoVec[iStation][iModule][iLayer];
306 if (!(info->hSig))
307 continue;
308 Double_t bc = 0;
309 for (Int_t i = 0; i < fNBins; i++) {
310 bc += info->hSig->GetBinContent(i);
311 info->hIntSig->SetBinContent(i, bc);
312 }
313 if (bc == 0)
314 continue;
315 info->hIntSig->Scale(1 / bc);
316 info->hIntSig->SetLineColor(kRed);
317 info->func = new TF1(
318 Form("%s_%zu_%zu_%zu", digits->GetName(), iStation, iModule, iLayer),
319 [info, bc](Double_t *x, Double_t * p) {
320 // Double_t val = (bc - x[0])/bc;//log(x[0]);
321 if (x[0] >= info->maxVal) return 1.0;
322 Int_t iBin = info->hIntSig->GetXaxis()->FindBin(x[0]);
323 Int_t jBin = iBin + ((x[0] > info->hIntSig->GetBinCenter(iBin)) ? 1 : -1);
324 Double_t v = info->hIntSig->GetBinContent(iBin) +
325 (info->hIntSig->GetBinContent(jBin) - info->hIntSig->GetBinContent(iBin))*
326 2 * abs(x[0] - info->hIntSig->GetBinCenter(iBin)) /
327 (info->hIntSig->GetBinWidth(iBin) + info->hIntSig->GetBinWidth(jBin));
328 return v;
329 }, info->minVal, info->maxVal, 0);
330 info->func->SetNpx(fNBins);
331 info->func->SetLineColor(kBlue);
332 }
333 }
334 }
335}
336
338 return GetCanvas<
341 BmnGemStripModule>(fGemStationSet);
342}
343
345 return GetCanvas<
348 BmnSiliconModule>(fSilStationSet);
349}
350
352 return GetCanvas<
355 BmnCSCModule>(fCscStationSet);
356}
int i
Definition P4_F32vec4.h:22
__m128 m
Definition P4_F32vec4.h:27
float f
Definition P4_F32vec4.h:21
BmnStatus
Definition BmnEnums.h:24
@ kBMNERROR
Definition BmnEnums.h:26
@ kBMNSUCCESS
Definition BmnEnums.h:25
@ kSRCSETUP
Definition BmnEnums.h:91
@ kBMNSETUP
Definition BmnEnums.h:90
BmnStatus CreateRescales(TString fileNameMC, TString fileNameEx)
TF1 * GetRescaleFunc(TString name, TF1 *mc, TF1 *ex)
virtual ~BmnRescale()
TCanvas * GetCanvasGem()
TCanvas * GetCanvasCSC()
TCanvas * GetCanvasSil()
BmnRescale(UInt_t periodId, UInt_t runId, Double_t lowThr=0, Double_t ClusterSizeThr=0, Int_t nBins=1e6)
Definition BmnRescale.cxx:3
Double_t maxVal
Definition BmnRescale.h:74
TF1 * func
Definition BmnRescale.h:77
TH1D * hIntSig
Definition BmnRescale.h:76
Double_t minVal
Definition BmnRescale.h:73
TH1D * hSig
Definition BmnRescale.h:75
Int_t GetStripLayer()
Int_t GetStation()
Double_t GetStripSignal()
Int_t GetModule()
name
Definition setup.py:7