paraToTRes[sfe][0] = parP0; paraToTRes[sfe][1] = parP1; paraToTRes[sfe][2] = parP2;
112 const bool run3 =
true;
113 const float badRDfracCut = 0.2;
117 const int finerToT = 1;
118 constexpr
bool moreFE =
false;
119 constexpr
int npsFEs = moreFE ? 8 : 2;
121 gStyle->SetOptFit(1100);
123 #if defined(DEMOXCHECK)
125 std::cout <<
" DEMOXCHECK will run ... " << std::endl;
128 int XcheckCharge[2] = {13, 14}, XcheckToT = 10;
129 int XcheckPhi[2] = {57, 63}, XcheckEta[2] = {23, 29};
130 TString XcheckModule =
"LI_S11_A_M3_A6";
133 int ToTfill = 3 * finerToT, CHRGfill = 3;
138 Double_t tmpRCf_H[4] = {0.868295, 0.67523, 0.732279, 0.678458};
139 Double_t tmpRCf_T[4] = {1.02844, 1.10788, 1.07204, 1.11015};
140 Double_t reverseCF_H[4], reverseCF_T[4];
141 for (
int t = 0;
t < 4;
t++)
143 reverseCF_H[
t] = tmpRCf_H[
t];
144 reverseCF_T[
t] = tmpRCf_T[
t];
147 Double_t RDentries[33] = {0, 10494.8, 14605.6, 62952.6, 8663.57, 17320.2, 20417, 49508.9,
148 21646.8, 31503.9, 14955.6, 16290.7, 11617.5, 16461.2, 11980.5, 17210.5,
149 12773.7, 18574, 13930.9, 19777, 14629.4, 20619.5, 15191.6, 20883,
150 15411.1, 19198, 12097.4, 12109.7, 8881.96, 17235.1, 20802.3, 11265.8,
153 std::vector<int> reversedModules = {182, 211, 213, 229, 223, 231, 246, 280, 295, 350, 357, 360, 371, 403, 416, 423};
156 TString Outdir =
"./";
159 #if defined(DEMOXCHECK)
160 spec +=
"DEMOXCHECK_";
164 TString rootFileName = Outdir +
"/TotChargeCalib_" + StrFileName +
".root";
165 TString logFileName = Outdir +
"/ChargeCalib_" + StrFileName +
".log";
166 TString dbFileName = Outdir +
"/ChargeCalib_" + StrFileName +
".TXT";
169 rootFileName = Outdir +
"/TotChargeCalib_run2_" + StrFileName +
".root";
170 logFileName = Outdir +
"/ChargeCalib_run2_" + StrFileName +
".log";
171 dbFileName = Outdir +
"/ChargeCalib_run2_" + StrFileName +
".TXT";
175 ofstream logout(logFileName);
176 ofstream txtDB(dbFileName);
178 TString inThrFile =
"";
179 TString inTotFile =
"";
180 TString rodPath =
"";
181 TString inTotFileAux =
"";
182 TString rodPathAux =
"";
184 std::cout <<
" Running IBL calibration analysis ... " << endl;
186 inThrFile = InDir + THRscan +
".root";
187 inTotFile = InDir +
scan +
".root";
188 rodPath = inTotFile +
":/" +
scan.substr(
scan.find(
"_")+1);
189 inTotFileAux = InDir + scanLowCharge +
".root";
190 rodPathAux = inTotFileAux +
":/" + scanLowCharge.substr(scanLowCharge.find(
"_")+1);
195 inThrFile =
"calib2018/IBL/THR_SCAN_S000083686.root";
196 inTotFile =
"calib2018/IBL/TOT_SCAN_S000083690.root";
197 rodPath = inTotFile +
":/S000083690";
201 int nrow = 336, ncol = 160;
203 const Int_t numChrgs = 22;
204 Double_t IBLchrgs[numChrgs] = {1400., 1500., 1750., 2000., 2500., 3000., 3500., 4000., 5000., 6000., 8000., 10000.,
205 12000., 14000., 16000., 18000., 20000., 22000., 24000., 26000., 28000., 30000.};
207 const Int_t nchargeIBL = (
run3 ? 22 : 19);
209 int skip = numChrgs - nchargeIBL;
210 Double_t chrgAbaciIBL[nchargeIBL], chargeErrArrIBL[nchargeIBL];
211 for (
int c = 0;
c < nchargeIBL;
c++)
213 chrgAbaciIBL[
c] = IBLchrgs[
c +
skip];
214 chargeErrArrIBL[
c] = 0.;
217 Double_t chrgsbins[nchargeIBL + 1];
218 for (
int c = 1;
c < nchargeIBL;
c++)
219 chrgsbins[
c] = 0.5 * (chrgAbaciIBL[
c - 1] + chrgAbaciIBL[
c]);
221 chrgsbins[0] = chrgAbaciIBL[0] - 0.5 * (chrgAbaciIBL[1] - chrgAbaciIBL[0]);
222 chrgsbins[nchargeIBL] = chrgAbaciIBL[nchargeIBL - 1] + 0.5 * (chrgAbaciIBL[nchargeIBL - 1] - chrgAbaciIBL[nchargeIBL - 2]);
225 const Int_t nToTibl = 16 * finerToT + 1;
227 Double_t totAbaci[nToTibl], totbins[nToTibl + 1];
233 for (
int t = 2;
t < nToTibl;
t++)
235 totAbaci[
t] = totAbaci[1] + (
t - 1) / (1. * finerToT);
236 totbins[
t] = 0.5 * (totAbaci[
t] + totAbaci[
t - 1]);
238 totbins[nToTibl] = totAbaci[nToTibl - 1] + 0.5 * (totbins[nToTibl - 1] - totbins[nToTibl - 2]);
240 Double_t totErrArr[nToTibl];
241 for (
int t = 0;
t < nToTibl;
t++)
244 #if defined(DEMOXCHECK)
245 for (
int t = 0;
t < nToTibl;
t++)
246 logout <<
" totAbaci : " <<
t <<
" " << totbins[
t] <<
" < " << totAbaci[
t] <<
" > " << totbins[
t + 1] << endl;
250 for (
int t = 1;
t < nToTibl;
t++)
252 RDentries[
t] = RDentries[2 *
t - 1] + RDentries[2 *
t];
253 logout <<
" finer RDentries : " <<
t <<
" " << 2 *
t - 1 <<
" " << 2 *
t <<
" " << RDentries[
t] << endl;
258 map<string, map<string, map<string, float>>> pcdMap;
260 TFile roFile(rootFileName,
"RECREATE");
261 TDirectory *roThrDir = roFile.mkdir(
"Threshold");
262 TDirectory *roTotDir = roFile.mkdir(
"ToT");
266 Double_t THR_avg[2][npsFEs], ThrSig_avg[2][npsFEs];
267 array<std::unique_ptr<TH2D> , npsFEs> h2_Thr{};
268 array<std::unique_ptr<TH2D> , npsFEs> h2_ThrSig{};
270 std::multimap<float, TString, std::greater<float>> badThr_Order;
272 for (
int sfe = 0; sfe < npsFEs; sfe++)
277 string knowModule =
"LI_S06_C_M1_C1";
278 string idx =
"I" +
ss.str();
280 pcdMap[knowModule][
idx][
"ThrNorm"] = -42.;
281 pcdMap[knowModule][
idx][
"ThrRmsNorm"] = -42.;
282 pcdMap[knowModule][
idx][
"ThrSigNorm"] = -42.;
283 pcdMap[knowModule][
idx][
"ThrLong"] = -42.;
284 pcdMap[knowModule][
idx][
"ThrRmsLong"] = -42.;
285 pcdMap[knowModule][
idx][
"ThrSigLong"] = -42.;
287 for (
int nl = 0; nl < 2; nl++)
288 THR_avg[nl][sfe] = ThrSig_avg[nl][sfe] = -99.;
290 idx =
"Threshold" +
ss.str();
291 h2_Thr[sfe] = std::make_unique<TH2D>(
idx.c_str(),
" ", 2, 0, 2, 200, 0, 5000);
292 idx =
"ThresholdSig" +
ss.str();
293 h2_ThrSig[sfe] = std::make_unique<TH2D>(
idx.c_str(),
" ", 2, 0, 2, 200, 0, 500);
296 if (inThrFile.Length() > 0)
299 <<
"INFO =>> [IBL] threshold scan analysis..." << endl;
301 TFile riThrFile(inThrFile,
"READ");
302 TString chi2HistName =
"SCURVE_CHI2";
303 TString thrHistName =
"SCURVE_MEAN";
304 TString sigHistName =
"SCURVE_SIGMA";
306 std::unique_ptr<TH1F> h1dChi2 = std::make_unique<TH1F>(
"h1dChi2",
"", 200, 0, 1);
307 std::unique_ptr<TH1F> h1dThr = std::make_unique<TH1F>(
"h1dThr" ,
"", 200, 0, 5000);
308 std::unique_ptr<TH1F> h1dSig = std::make_unique<TH1F>(
"h1dSig" ,
"", 200, 0, 500);
310 TDirectoryFile *
scanDir = (TDirectoryFile *)((TKey *)riThrFile.GetListOfKeys()->First())->ReadObj();
311 TList *rodKeyList = (TList *)
scanDir->GetListOfKeys();
312 TIter rodItr(rodKeyList);
315 while ((rodKey = (TKey *)rodItr()))
317 TString rodName(rodKey->GetName());
318 TDirectoryFile *rodDir = (TDirectoryFile *)rodKey->ReadObj();
319 TList *modKeyList = (TList *)rodDir->GetListOfKeys();
320 TIter modItr(modKeyList);
323 TDirectory *dirRod = roThrDir->mkdir(rodName);
325 while ((modKey = (TKey *)modItr()))
327 TString
modName(modKey->GetName());
328 string modStr(modKey->GetName());
329 TDirectory *dirMod = dirRod->mkdir(
modName);
331 TString chi2HistDirPath =
modName +
"/" + chi2HistName +
"/A0/B0";
333 TDirectory *chi2HistDir = (TDirectory *)rodDir->Get(chi2HistDirPath);
334 if (chi2HistDir == NULL)
336 cout <<
" Warning : NULL dir " << endl;
340 std::unique_ptr<TH2D> h2dChi2 (
static_cast<TH2D*
>(
static_cast<TKey*
>(chi2HistDir->GetListOfKeys()->First())->ReadObj()));
343 cout <<
" Warning : NULL dir " << endl;
346 TString thrHistDirPath =
modName +
"/" + thrHistName +
"/A0/B0";
347 TDirectoryFile *thrHistDir = (TDirectoryFile *)rodDir->Get(thrHistDirPath);
348 std::unique_ptr<TH2D> h2dThr(
static_cast<TH2D*
>(
static_cast<TKey*
>(thrHistDir->GetListOfKeys()->First())->ReadObj()));
349 TString sigHistDirPath =
modName +
"/" + sigHistName +
"/A0/B0";
351 TDirectoryFile *sigHistDir = (TDirectoryFile *)rodDir->Get(sigHistDirPath);
352 std::unique_ptr<TH2D> h2dSig (
static_cast<TH2D*
>(
static_cast<TKey*
>(sigHistDir->GetListOfKeys()->First())->ReadObj()));
354 array<std::unique_ptr<TH1F>, npsFEs> h1_ThrNorm{};
355 array<std::unique_ptr<TH1F>, npsFEs> h1_ThrSigNorm{};
356 array<std::unique_ptr<TH1F>, npsFEs> h1_ThrLong{};
357 array<std::unique_ptr<TH1F>, npsFEs> h1_ThrSigLong{};
358 array<float, npsFEs> IlledThr{};
360 for (
int sfe = 0; sfe < npsFEs; sfe++)
365 string hname = modStr +
"ThrNorm" +
ss.str();
366 h1_ThrNorm[sfe] = std::make_unique<TH1F>(
hname.c_str(),
"", 200, 0, 5000);
367 hname = modStr +
"ThrSigNorm" +
ss.str();
368 h1_ThrSigNorm[sfe] = std::make_unique<TH1F>(
hname.c_str(),
"", 200, 0, 500);
369 hname = modStr +
"ThrLong" +
ss.str();
370 h1_ThrLong[sfe] = std::make_unique<TH1F>(
hname.c_str(),
"", 200, 0, 5000);
371 hname = modStr +
"ThrSigLong" +
ss.str();
372 h1_ThrSigLong[sfe] = std::make_unique<TH1F>(
hname.c_str(),
"", 200, 0, 500);
379 float chi2 = h2dChi2->GetBinContent(
col,
row);
380 float thr = h2dThr->GetBinContent(
col,
row);
381 float sig = h2dSig->GetBinContent(
col,
row);
388 if (thr == 0 || thr > 10000 ||
sig == 0 ||
sig > 1000 ||
chi2 > 0.5 ||
chi2 <= 0)
395 if (
col == 1 ||
col == ncol / 2 ||
col == ncol / 2 + 1 ||
col == ncol)
413 h1_ThrLong[circ]->Fill(thr);
414 h1_ThrSigLong[circ]->Fill(
sig);
434 h1_ThrNorm[circ]->Fill(thr);
435 h1_ThrSigNorm[circ]->Fill(
sig);
449 for (
int sfe = 0; sfe < npsFEs; sfe++)
453 string feName =
"I" +
ss.str();
455 float THRnorm = h1_ThrNorm[sfe]->GetMean();
456 bool valid = THRnorm > 100.;
457 pcdMap[modStr][feName][
"ThrNorm"] = THRnorm;
458 pcdMap[modStr][feName][
"ThrRmsNorm"] = h1_ThrNorm[sfe]->GetRMS();
459 float THRnormSig = h1_ThrSigNorm[sfe]->GetMean();
460 pcdMap[modStr][feName][
"ThrSigNorm"] = THRnormSig;
461 float THRlong = h1_ThrLong[sfe]->GetMean();
462 pcdMap[modStr][feName][
"ThrLong"] = THRlong;
463 pcdMap[modStr][feName][
"ThrRmsLong"] = h1_ThrLong[sfe]->GetRMS();
464 float THRlongSig = h1_ThrSigLong[sfe]->GetMean();
465 pcdMap[modStr][feName][
"ThrSigLong"] = THRlongSig;
467 float blank = 100. * IlledThr[sfe] * npsFEs / (1. * ncol * nrow);
470 badThr_Order.insert(std::pair<float, TString>(blank, (TString)(
modName +
" : " + blank)));
474 h2_Thr[sfe]->Fill(0.5, THRnorm, 1);
475 h2_Thr[sfe]->Fill(1.5, THRlong, 1);
476 h2_ThrSig[sfe]->Fill(0.5, THRnormSig, 1);
477 h2_ThrSig[sfe]->Fill(1.5, THRlongSig, 1);
479 dirMod->WriteTObject(h1_ThrNorm[sfe].
get());
480 dirMod->WriteTObject(h1_ThrLong[sfe].
get());
482 h1_ThrNorm[sfe].reset();
483 h1_ThrSigNorm[sfe].reset();
484 h1_ThrLong[sfe].reset();
485 h1_ThrSigLong[sfe].reset();
489 roThrDir->WriteTObject(h1dChi2.get());
491 roThrDir->WriteTObject(h1dThr.get());
493 roThrDir->WriteTObject(h1dSig.get());
497 for (
int sfe = 0; sfe < npsFEs; sfe++)
501 string hName =
"thrNorm" +
ss.str();
502 THR_avg[0][sfe] = h2_Thr[sfe]->ProjectionY(hName.c_str(), 1, 1)->
GetMean();
503 hName =
"thrLong" +
ss.str();
504 THR_avg[1][sfe] = h2_Thr[sfe]->ProjectionY(hName.c_str(), 2, 2)->
GetMean();
505 hName =
"thrSigNorm" +
ss.str();
506 ThrSig_avg[0][sfe] = h2_ThrSig[sfe]->ProjectionY(hName.c_str(), 1, 1)->
GetMean();
507 hName =
"thrSigLong" +
ss.str();
508 ThrSig_avg[1][sfe] = h2_ThrSig[sfe]->ProjectionY(hName.c_str(), 2, 2)->
GetMean();
510 h2_ThrSig[sfe].reset();
518 if (inTotFile.Length() == 0 || inTotFileAux.Length() == 0)
520 logout <<
" Missing ToT file from calib scan as input " << endl;
525 <<
"INFO =>> [IBL] tot calib analysis..." << endl;
527 TFile riTotFile(inTotFile,
"READ");
528 TFile riTotFileAux(inTotFileAux,
"READ");
530 TString totHistName =
"TOT_MEAN";
531 TString totSigHistName =
"TOT_SIGMA";
533 TDirectoryFile *
scanDir = (TDirectoryFile *)((TKey *)riTotFile.GetListOfKeys()->First())->ReadObj();
534 TList *rodKeyList = (TList *)
scanDir->GetListOfKeys();
535 TIter rodItr(rodKeyList);
538 std::map<float, std::pair<vector<TString>, vector<Double_t>>> ModuDataToPrint;
540 #if defined(DEMOXCHECK)
541 vector<TH1F *> h1_ChrgEntry;
542 h1_ChrgEntry.reserve(nToTibl);
544 vector<TH1F *> h1d_totSprdAll;
545 h1d_totSprdAll.reserve(nToTibl - 1);
547 for (
int t = 0;
t < nToTibl;
t++)
552 string hname =
"ChrgEntries_ToT_" +
tt.str();
553 h1_ChrgEntry[
t] =
new TH1F(
hname.c_str(),
"RD entries ", 100, 0., 100000);
555 hname =
"totSprdsFll_ToT_" +
tt.str();
557 h1d_totSprdAll[
t] =
new TH1F(
hname.c_str(),
"ToT spread ", 36, 0.2, 1.1);
561 const Int_t totFE = 14 * 16 * npsFEs;
562 Double_t TotArray[totFE][nchargeIBL], TotErrArray[totFE][nchargeIBL];
563 Double_t TotSigArray[totFE][nchargeIBL], TotSigErrArray[totFE][nchargeIBL];
564 Double_t ChrgArray[totFE][nToTibl], ChrgErrArray[totFE][nToTibl];
566 gRandom =
new TRandom3(2203);
568 float occuPhiEta[nchargeIBL][totFE];
571 std::map<float, TString> devChrg_Order;
572 std::map<float, TString> devToT_Order;
574 std::multimap<float, TString, std::greater<float>> badModules_Order;
575 std::multimap<float, TString, std::greater<float>> badModules_Order_detailed;
577 while ((rodKey = (TKey *)rodItr()))
579 TString rodName(rodKey->GetName());
580 string rodStr(rodKey->GetName());
581 TDirectoryFile *rodDir = (TDirectoryFile *)rodKey->ReadObj();
583 TString
path = rodDir->GetPath();
584 TString pathAux =
path.ReplaceAll(rodPath, rodPathAux);
586 TDirectoryFile *rodDirAux = (TDirectoryFile *)riTotFileAux.Get(pathAux);
587 if (rodDirAux == NULL)
589 std::cout<<
" Fail to get the rodPath in Aux: "<< pathAux << endl;
590 logout <<
" Fail to get the rodPath in Aux " << endl;
594 TDirectory *dirRod = roTotDir->mkdir(rodName);
596 TList *modKeyList = (TList *)rodDir->GetListOfKeys();
597 TIter modItr(modKeyList);
602 string modNames[16 * npsFEs];
604 float occuChrgs[nToTibl][16 * npsFEs];
606 #if defined(DEMOXCHECK)
607 TString feName_maxDevChrg =
"", feName_maxDevToT =
"";
608 float maxDevChrg = -9., maxDevToT = -9., avgDevChrg = 0., avgDevToT = 0.;
610 vector<TH1F *> h1d_totSprd;
611 h1d_totSprd.reserve(nToTibl - 1);
613 for (
int t = 0;
t < nToTibl - 1;
t++)
618 string prfmodname =
"ToT_Sprd_" +
tt.str();
619 h1d_totSprd[
t] =
new TH1F(prfmodname.c_str(),
"ToT spread ", 28, 0.3, 1.0);
620 prfmodname = rodStr +
"ToT spread @ ToT_" +
tt.str();
621 h1d_totSprd[
t]->SetTitle(prfmodname.c_str());
625 while ((modKey = (TKey *)modItr()))
627 TString
modName(modKey->GetName());
628 string modStr(modKey->GetName());
630 TDirectory *dirMod = dirRod->mkdir(
modName);
631 bool ibl3Dfe0 =
false, ibl3Dfe1 =
false;
633 int hashID = -1, hashIDL = -1, hashIDR = -1;
638 int eta_moduleL = -1, eta_moduleR = -1;
639 pixmap.mapping(modStr, &hashID, &
bec, &
layer, &phi_module, &eta_module);
642 pixmap.mapping(modStr +
"_1", &hashID, &
bec, &
layer, &phi_module, &eta_module);
647 eta_moduleL = eta_module;
650 pixmap.mapping(modStr +
"_2", &hashID, &
bec, &
layer, &phi_module, &eta_module);
655 eta_moduleR = eta_module;
659 std::cout<<
"negative hash ID\n";
664 if (pcdMap.find(modStr) == pcdMap.end()){
665 std::cout<<
"MOD not found "<< modStr <<
"\n";
671 array<std::unique_ptr<TH2D>, npsFEs> h2d_XchrgYtot{};
672 array<std::unique_ptr<TH2D>, npsFEs> h2d_XchrgYToTSig{};
674 for (
int sfe = 0; sfe < npsFEs; sfe++)
679 modNames[cntMod * npsFEs + sfe] = modStr +
"-" +
ss.str();
681 string prfmodname = modStr +
"ToTvsChrg_FE" +
ss.str();
682 h2d_XchrgYtot[sfe] = std::make_unique<TH2D>(prfmodname.c_str(),
"ToT vs Charge", nchargeIBL, chrgsbins, nToTibl, totbins);
684 prfmodname = modStr +
"ToT_Sig_vsChrg_FE" +
ss.str();
685 h2d_XchrgYToTSig[sfe] = std::make_unique<TH2D>(prfmodname.c_str(),
"ToT Sig vs Charge", nchargeIBL, chrgsbins, 100, 0., 1.);
689 for (
int c = 0;
c < nchargeIBL;
c++)
691 TString totHistDirPath =
modName +
"/" + totHistName +
"/A0/B0/C";
694 std::unique_ptr<TH2F> h2dTot;
695 TDirectoryFile* totHistDir(
static_cast<TDirectoryFile*
> (rodDir->Get(totHistDirPath)));
697 std::cout<<
" Missing totHistDir in : " << totHistDirPath << endl;
700 h2dTot.reset(
static_cast<TH2F*
> ((
static_cast<TKey*
>(totHistDir->GetListOfKeys()->First()))->ReadObj()));
701 h2dTot->SetDirectory(0);
704 unique_ptr<TH2F> h2dTotAux;
705 TDirectoryFile* totHistDirAux(
static_cast<TDirectoryFile*
>(rodDirAux->Get(totHistDirPath)));
708 std::cout<<
" Missing totHistDir in : " << totHistDirPath << endl;
709 logout <<
" Missing totHistDir in : " << totHistDirPath << endl;
712 h2dTotAux.reset(
static_cast<TH2F*
> ((
static_cast<TKey*
>(totHistDirAux->GetListOfKeys()->First())->ReadObj())));
713 h2dTotAux->SetDirectory(0);
716 TString totSigHistDirPath =
modName +
"/" + totSigHistName +
"/A0/B0/C";
718 TDirectoryFile* totSigHistDir (
static_cast<TDirectoryFile*
>(rodDir->Get(totSigHistDirPath)));
719 unique_ptr<TH2F> h2dTotSig (
static_cast<TH2F*
> ((
static_cast<TKey*
>(totSigHistDir->GetListOfKeys()->First()))->ReadObj()));
720 h2dTotSig->SetDirectory(0);
723 for (
int ieta = 0; ieta < ncol; ieta++)
725 for (
int iphi = 0; iphi < nrow; iphi++)
732 circ = (
int)(iphi / 84.);
746 float tot = h2dTot->GetBinContent(ieta + 1, iphi + 1) + HDCshift;
747 float totAux = h2dTotAux->GetBinContent(ieta + 1, iphi + 1);
755 if (tot <= 5 ||
c <= 5)
757 if ((
c == 0 && tot - totAux > 0.8) || (
c >= 1 &&
c <= 3 && tot - totAux > 0.5) || (
c > 4 && tot - totAux > 0.3))
760 filltot = 0.5 * (totAux + tot);
761 if (
c == 0 && totAux > 2.)
766 filltot = 0.5 * (totAux + tot + 2.);
769 h2d_XchrgYtot[circ]->Fill(chrgAbaciIBL[
c], filltot, 1.);
773 float err = h2dTotSig->GetBinContent(ieta + 1, iphi + 1);
774 h2d_XchrgYToTSig[circ]->Fill(chrgAbaciIBL[
c],
err, 1.);
778 #if defined(DEMOXCHECK)
779 if (
modName == XcheckModule && (iphi >= XcheckPhi[0] && iphi <= XcheckPhi[1]) && (ieta >= XcheckEta[0] && ieta <= XcheckEta[1]) && (
c == XcheckCharge[0] ||
c == XcheckCharge[1] || (
int)(tot + 0.5) == XcheckToT || (
int)(totAux + 0.5) == XcheckToT))
780 logout <<
" tot = " << tot <<
", totAux = " << totAux <<
" @injection " << chrgAbaciIBL[
c] <<
" " <<
err << endl;
791 if (!(ibl3Dfe0 || ibl3Dfe1))
796 array<TDirectory *, npsFEs> dirFE;
798 Int_t idxMod = cntRod * 16 * npsFEs + cntMod * npsFEs;
800 for (
int sfe = 0; sfe < npsFEs; sfe++)
805 if (ibl3Dfe0 && sfe < npsFEs / 2)
809 else if (ibl3Dfe1 && sfe >= npsFEs / 2)
814 modHash += (sfe < npsFEs / 2 ? 0 : 1) * 0.8;
816 string prfmodname =
"DirFE_" +
ss.str();
817 dirFE[sfe] = dirMod->mkdir(prfmodname.c_str());
820 prfmodname = modStr +
"_profile_Tot_FE" +
ss.str();
821 std::unique_ptr<TProfile> prfl_TotsFE(h2d_XchrgYtot[sfe]->ProfileX(prfmodname.c_str(), 1, -1,
"s"));
822 prfl_TotsFE->SetTitle(prfmodname.c_str());
823 prfmodname = modStr +
"_profile_Chrg_FE" +
ss.str();
825 std::unique_ptr<TProfile> prfl_ChrgsFE(h2d_XchrgYtot[sfe]->ProfileY(prfmodname.c_str(), 1, -1,
"s"));
826 prfl_ChrgsFE->SetTitle(prfmodname.c_str());
828 Double_t TotArr[nchargeIBL], TotErrArr[nchargeIBL];
829 Double_t ChrgArr[nToTibl], ChrgErrArr[nToTibl];
831 Int_t idxFE = idxMod + sfe;
834 for (
int c = 0;
c < nchargeIBL;
c++)
836 TotArr[
c] = TotArray[idxFE][
c] = prfl_TotsFE->GetBinContent(
c + 1);
837 TotErrArr[
c] = TotErrArray[idxFE][
c] = prfl_TotsFE->GetBinError(
c + 1);
839 occuPhiEta[
c][idxFE] = prfl_TotsFE->GetBinEntries(
c + 1) * npsFEs / (1. * ncol * nrow);
841 if ((1. - occuPhiEta[
c][idxFE]) > badRDfracCut)
846 prfmodname = modStr +
"_ToTsig_FE" +
ss.str() +
"Chrg" +
sc.str();
848 std::unique_ptr<TH1D> h_ToTsig(h2d_XchrgYToTSig[sfe]->ProjectionY(prfmodname.c_str(),
c + 1,
c + 1));
849 TotSigArray[idxFE][
c] = TMath::Sqrt(h_ToTsig->GetMean() * h_ToTsig->GetMean() + h_ToTsig->GetRMS() * h_ToTsig->GetRMS());
850 TotSigErrArray[idxFE][
c] = TMath::Sqrt(h_ToTsig->GetMeanError() * h_ToTsig->GetMeanError() + h_ToTsig->GetRMSError() * h_ToTsig->GetRMSError());
858 for (
int c = 0;
c < nchargeIBL;
c++)
860 TotArr[
c] = TotArray[idxFE][
c] = 0.5 * (TotArray[idxFE - 1][
c] + TotArray[idxFE - 2][
c]);
861 TotErrArr[
c] = TotErrArray[idxFE][
c] = 0.5 * (TotErrArray[idxFE - 1][
c] + TotErrArray[idxFE - 2][
c]);
863 TotSigArray[idxFE][
c] = 0.5 * (TotSigArray[idxFE - 1][
c] + TotSigArray[idxFE - 2][
c]);
864 TotSigErrArray[idxFE][
c] = 0.5 * (TotSigErrArray[idxFE - 1][
c] + TotSigErrArray[idxFE - 2][
c]);
869 Double_t errToT_overChrg[nToTibl];
870 for (
int t = 0;
t < nToTibl;
t++)
872 ChrgArr[
t] = ChrgArray[idxFE][
t] = prfl_ChrgsFE->GetBinContent(
t + 1);
873 ChrgErrArr[
t] = ChrgErrArray[idxFE][
t] = prfl_ChrgsFE->GetBinError(
t + 1);
875 occuChrgs[
t][cntMod * npsFEs + sfe] = prfl_ChrgsFE->GetBinEntries(
t + 1) / RDentries[
t];
879 prfmodname = modStr +
"_Chrg_FE" +
ss.str() +
"ToT" + st.str();
880 std::unique_ptr<TH1D> h_chrg(h2d_XchrgYtot[sfe]->ProjectionX(prfmodname.c_str(),
t + 1,
t + 1));
883 prfmodname = modStr +
" Charge_FE" +
ss.str() +
" @ ToT : " + st.str();
884 h_chrg->SetTitle(prfmodname.c_str());
886 Double_t scl = h_chrg->Integral();
887 errToT_overChrg[
t] = 0.;
889 for (
int b = 0;
b < nchargeIBL;
b++)
891 errToT_overChrg[
t] += TotErrArr[
b] * (h_chrg->GetBinContent(
b + 1)) / scl;
893 if (errToT_overChrg[
t] == 0.)
894 errToT_overChrg[
t] = 1.1;
898 prfl_ChrgsFE.reset();
899 #if defined(DEMOXCHECK)
900 for (
int b = 1;
b < nToTibl;
b++)
902 double err = errToT_overChrg[
b];
903 h1d_totSprd[
b - 1]->Fill(
err);
904 h1d_totSprdAll[
b - 1]->Fill(
err);
911 for (
int t = 0;
t < nToTibl;
t++)
913 ChrgArr[
t] = ChrgArray[idxFE][
t] = 0.5 * (ChrgArray[idxFE - 1][
t] + ChrgArray[idxFE - 2][
t]);
914 ChrgErrArr[
t] = ChrgErrArray[idxFE][
t] = 0.5 * (ChrgErrArray[idxFE - 1][
t] + ChrgErrArray[idxFE - 2][
t]);
917 bool xoticMod =
std::find(reversedModules.begin(), reversedModules.end(),
int(modHash)) != reversedModules.end();
920 bool reverseH =
false, reverseT =
false;
921 for (
int t = 4;
t >= 1;
t--)
922 if (ChrgArr[
t] > ChrgArr[
t + 1])
927 for (
int t = 4;
t >= 1;
t--)
929 int tl = nToTibl -
t;
930 if (ChrgArr[
tl] < ChrgArr[
tl - 1])
939 #if defined(DEMOXCHECK)
940 logout <<
" Head reversed : " <<
int(modHash) <<
" " <<
modName <<
" " << sfe <<
" " << ChrgArr[1] <<
" "
941 << ChrgArr[2] <<
" " << ChrgArr[3] <<
" " << ChrgArr[4] <<
" " << ChrgArr[5] << std::endl;
944 for (
int t = 4;
t >= 1;
t--)
945 if (ChrgArr[
t] > ChrgArr[
t + 1] && (occuChrgs[
t][cntMod * npsFEs + sfe] < 0.5 || xoticMod))
946 ChrgArr[
t] = ChrgArray[idxFE][
t] = reverseCF_H[
t - 1] * ChrgArr[
t + 1];
950 for (
int t = 4;
t >= 1;
t--)
951 if (ChrgArr[
t + 1] != 0.)
952 reverseCF_H[
t - 1] = (reverseCF_H[
t - 1] == tmpRCf_H[
t - 1] ? ChrgArr[
t] / ChrgArr[
t + 1] : 0.5 * (reverseCF_H[
t - 1] + ChrgArr[
t] / ChrgArr[
t + 1]));
957 #if defined(DEMOXCHECK)
958 logout <<
" Tail reversed : " <<
int(modHash) <<
" " <<
modName <<
" " << sfe <<
" " << ChrgArr[nToTibl - 5] <<
" "
959 << ChrgArr[nToTibl - 4] <<
" " << ChrgArr[nToTibl - 3] <<
" " << ChrgArr[nToTibl - 2] <<
" " << ChrgArr[nToTibl - 1] << std::endl;
962 for (
int t = 4;
t >= 1;
t--)
964 int tl = nToTibl -
t;
965 if (ChrgArr[
tl] < ChrgArr[
tl - 1] && (occuChrgs[
tl][cntMod * npsFEs + sfe] < 0.5 || xoticMod))
966 ChrgArr[
tl] = ChrgArray[idxFE][
tl] = reverseCF_T[
t - 1] * ChrgArr[
tl - 1];
971 for (
int t = 4;
t >= 1;
t--)
973 int tl = nToTibl -
t;
974 if (ChrgArr[
tl - 1] != 0.)
975 reverseCF_T[
t - 1] = (reverseCF_T[
t - 1] == tmpRCf_T[
t - 1] ? ChrgArr[
tl] / ChrgArr[
tl - 1] : 0.5 * (reverseCF_T[
t - 1] + ChrgArr[
tl] / ChrgArr[
tl - 1]));
979 string gername = modStr +
"_grToTsig_FE_" +
ss.str();
980 std::unique_ptr<TGraphErrors> grTotSig = std::make_unique<TGraphErrors>(nchargeIBL, chrgAbaciIBL, TotSigArray[sfe], chargeErrArrIBL, TotSigErrArray[sfe]);
981 grTotSig->SetTitle(gername.c_str());
982 grTotSig->SetName(gername.c_str());
984 std::unique_ptr<TGraph> grTotSprd = std::make_unique<TGraph>(nToTibl, totAbaci, errToT_overChrg);
986 grTotSprd->SetName(gername.c_str());
987 gername = modStr +
" ToT spread over FrontEnd @ FE " +
ss.str();
988 grTotSprd->SetTitle(gername.c_str());
989 grTotSprd->SetLineColor(4);
990 grTotSprd->SetMarkerStyle(4);
991 grTotSprd->SetMarkerSize(1.);
994 ToTres.SetParameter(1,13.);
995 ToTres.SetParameter(2,0.65);
996 ToTres.SetParLimits(1, 10., 16.);
997 ToTres.SetParLimits(2, 0.3, 1.0);
999 grTotSprd->Fit(&ToTres,
"MRQ");
1000 Double_t parP0 = ToTres.GetParameter(0);
1001 Double_t parP1 = ToTres.GetParameter(1);
1003 dirFE[sfe]->WriteTObject(grTotSprd.get());
1028 gername = modStr +
"_grToT_FE_" +
ss.str();
1029 std::unique_ptr<TGraphErrors> grTot = std::make_unique<TGraphErrors>(nchargeIBL, chrgAbaciIBL, TotArr, chargeErrArrIBL, TotErrArr);
1030 grTot->SetTitle(gername.c_str());
1031 grTot->SetName(gername.c_str());
1032 TF1 *f1ToTfromCharge =
new TF1(
"ToTfromCharge",
funcRation5, chrgAbaciIBL[0] - 100., chrgAbaciIBL[nchargeIBL - 1] + 300., 5);
1034 grTot->Fit(f1ToTfromCharge,
"MRQ");
1036 std::unique_ptr<TGraphErrors> grChrg = std::make_unique<TGraphErrors>(nToTibl, totAbaci, ChrgArr, totErrArr, ChrgErrArr);
1038 gername = modStr +
"_grChrg_FE_" +
ss.str();
1039 grChrg->SetName(gername.c_str());
1040 grChrg->SetTitle(gername.c_str());
1041 grChrg->SetLineColor(3);
1042 grChrg->SetLineWidth(3);
1044 TF1 *f1ChargefromToTLeft =
new TF1(
"ChargefromToTL",
funcRation5, 1., 7.5, 5);
1045 f1ChargefromToTLeft->SetLineColor(2);
1046 grChrg->Fit(f1ChargefromToTLeft,
"MRQ");
1047 if (f1ChargefromToTLeft->GetChisquare() / 4. > 2.){
1048 logout <<
"bad fit Left... " << std::endl;
1051 TF1 *f1ChargefromToTRight =
new TF1(
"ChargefromToTR",
funcRation5, 5.5, 16., 5);
1052 f1ChargefromToTRight->SetLineColor(4);
1053 grChrg->Fit(f1ChargefromToTRight,
"MRQ+");
1055 dirFE[sfe]->WriteTObject(grTot.get());
1056 dirFE[sfe]->WriteTObject(grTotSig.get());
1057 dirFE[sfe]->WriteTObject(h2d_XchrgYtot[sfe].
get());
1059 h2d_XchrgYtot[sfe].reset();
1060 h2d_XchrgYToTSig[sfe].reset();
1066 string Idx =
"I" +
ss.str();
1067 vector<TString> modName2prt;
1068 modName2prt.push_back(
modName);
1069 modName2prt.push_back((TString)(Idx));
1072 std::vector<Double_t> prtAux;
1073 prtAux.reserve(5 + 4 + nToTibl - 1 + 3);
1075 prtAux.push_back(modHash);
1076 prtAux.push_back(
bec);
1077 prtAux.push_back(
layer);
1078 prtAux.push_back(phi_module);
1079 prtAux.push_back(eta_module);
1081 modName2prt[0] = (modStr +
"_" +
ss.str()).c_str();
1082 if (ibl3Dfe0 && sfe < npsFEs / 2)
1085 modName2prt[0] =
modName +
"_0";
1086 prtAux[0] = hashIDL;
1087 prtAux[4] = eta_moduleL;
1089 if (ibl3Dfe1 && sfe >= npsFEs / 2)
1092 modName2prt[0] =
modName +
"_1";
1093 prtAux[0] = hashIDR;
1094 prtAux[4] = eta_moduleR;
1098 float ThrNorm = pcdMap[modStr][Idx][
"ThrNorm"];
1099 if (ThrNorm == 0. || ThrNorm == -42.)
1102 prtAux.push_back(THR_avg[0][sfe]);
1103 prtAux.push_back(ThrSig_avg[0][sfe]);
1104 prtAux.push_back(THR_avg[1][sfe]);
1105 prtAux.push_back(ThrSig_avg[1][sfe]);
1109 prtAux.push_back(pcdMap[modStr][Idx][
"ThrNorm"]);
1110 prtAux.push_back(pcdMap[modStr][Idx][
"ThrSigNorm"]);
1111 prtAux.push_back(pcdMap[modStr][Idx][
"ThrLong"]);
1112 prtAux.push_back(pcdMap[modStr][Idx][
"ThrSigLong"]);
1116 for (
int t = 1;
t < nToTibl;
t++)
1117 prtAux.push_back(ChrgArr[
t]);
1120 prtAux.push_back(parP0);
1121 prtAux.push_back(parP1);
1123 std::pair<vector<TString>, vector<Double_t>> payloadDB = std::pair<vector<TString>, vector<Double_t>>(modName2prt, prtAux);
1124 ModuDataToPrint.insert(std::pair<
float, std::pair<vector<TString>, vector<Double_t>>>(modHash, payloadDB));
1130 #if defined(DEMOXCHECK)
1132 TDirectory *dirToTSprd = dirRod->mkdir(
"ToT_Spreads");
1133 for (
int b = 0;
b < nToTibl - 1;
b++)
1135 Int_t
upper = h1d_totSprd[
b]->FindLastBinAbove(1, 1);
1136 h1d_totSprd[
b]->SetAxisRange(h1d_totSprd[
b]->GetBinLowEdge(
1137 h1d_totSprd[
b]->FindFirstBinAbove(1, 1)),
1138 h1d_totSprd[
b]->GetBinLowEdge(
upper) + h1d_totSprd[
b]->GetBinWidth(
upper),
"X");
1140 dirToTSprd->WriteTObject(h1d_totSprd[
b]);
1141 delete h1d_totSprd[
b];
1143 h1d_totSprd.clear();
1147 TH2F *h2_badChrgs =
new TH2F(rodName +
"ChargeOccupancy",
"Occupancy ", nchargeIBL, 0, nchargeIBL, 16 * npsFEs, 0, 16 * npsFEs);
1148 hn =
"Occupancy along charges @ " + rodName;
1149 h2_badChrgs->SetTitle(hn);
1151 TH2F *h2_badToT =
new TH2F(rodName +
"ToTOccupancy",
"Occupancy ", nToTibl - 1, 0.5, nToTibl - 0.5, 16 * npsFEs, 0, 16 * npsFEs);
1152 hn =
"Occupancy along ToT @ " + rodName;
1153 h2_badToT->SetTitle(hn);
1155 bool fillChrg =
false, fillToT =
false;
1157 for (
int sfe = 0; sfe < 16 * npsFEs; sfe++)
1160 for (
int c = 0;
c < nchargeIBL;
c++)
1162 float occu = occuPhiEta[
c][cntRod * 16 * npsFEs + sfe];
1163 float nt = 10. - floor(10. * occu + 0.5);
1165 TString modchrg = (TString)(modNames[sfe] +
"_Chrg_" +
c);
1167 badModules_Order_detailed.insert(std::pair<float, TString>(1. - occu, modchrg));
1173 h2_badChrgs->SetBinContent(
c + 1, sfe + 1,
nt);
1176 PhiEta /= nchargeIBL;
1178 badModules_Order.insert(std::pair<float, TString>(PhiEta,
1179 (TString)(modNames[sfe])));
1181 for (
int t = 1;
t < nToTibl;
t++)
1183 float nt = floor(10. * occuChrgs[
t][sfe] + 0.5);
1186 h2_badToT->SetBinContent(
t + 1, sfe + 1,
nt);
1190 TString
shortName = modNames[sfe].substr(9, 13).c_str();
1191 h2_badChrgs->GetYaxis()->SetBinLabel(sfe + 1,
shortName);
1192 h2_badToT->GetYaxis()->SetBinLabel(sfe + 1,
shortName);
1193 h2_badChrgs->SetStats(kFALSE);
1194 h2_badToT->SetStats(kFALSE);
1195 h2_badChrgs->SetTickLength(0.01,
"Y");
1196 h2_badToT->SetTickLength(0.01,
"Y");
1199 h2_badChrgs->SetOption(
"TEXT");
1200 h2_badToT->SetOption(
"TEXT");
1204 dirRod->WriteTObject(h2_badChrgs,
"",
"Overwrite");
1209 dirRod->WriteTObject(h2_badToT,
"",
"WriteDelete");
1220 #if defined(DEMOXCHECK)
1222 for (
int t = 0;
t < 4;
t++)
1225 logout <<
" correction factors for reversed charges : ";
1226 logout << reverseCF_H[
t] <<
", ";
1230 for (
int t = 0;
t < 4;
t++)
1233 logout <<
" correction factors for reversed charges : ";
1234 logout << reverseCF_T[
t] <<
", ";
1239 for (
int t = 0;
t < nToTibl;
t++)
1242 logout <<
"RD Entries per ToT bin ";
1243 logout << h1_ChrgEntry[
t]->GetMean() <<
", ";
1244 if (
t == nToTibl - 1)
1245 logout << std::endl;
1246 roTotDir->WriteTObject(h1_ChrgEntry[
t]);
1247 delete h1_ChrgEntry[
t];
1249 h1_ChrgEntry.clear();
1251 for (std::map<float, TString>::const_iterator itr = devChrg_Order.begin();
1252 itr != devChrg_Order.end(); ++itr)
1253 logout <<
" Charge dev order : " << itr->second <<
" : " << itr->first << endl;
1255 for (std::map<float, TString>::const_iterator itr = devToT_Order.begin();
1256 itr != devToT_Order.end(); ++itr)
1257 logout <<
" ToT dev order : " << itr->second <<
" : " << itr->first << endl;
1259 logout <<
"ToTRes (spread) & its RMS @ ToT from 1 to 16 : " << endl;
1260 for (
int t = 0;
t < nToTibl - 1;
t++)
1264 logout <<
"[ " << h1d_totSprdAll[
t]->GetMean() <<
" , " << h1d_totSprdAll[
t]->GetStdDev() <<
" ] ";
1265 if (
t < nToTibl - 2)
1266 logout <<
" , " << endl;
1267 if (
t == nToTibl - 2)
1268 logout <<
" ] " << endl;
1269 delete h1d_totSprdAll[
t];
1271 h1d_totSprdAll.clear();
1274 logout <<
" goto print " << std::endl;
1287 for (std::map<
float, std::pair<vector<TString>, vector<Double_t>>>::const_iterator itr = ModuDataToPrint.begin();
1288 itr != ModuDataToPrint.end(); ++itr)
1290 int hash = floor(itr->first);
1291 std::pair<vector<TString>, vector<Double_t>>
payload = itr->second;
1292 vector<Double_t> fe =
payload.second;
1294 txtDB <<
hash <<
" ";
1296 for (
unsigned int t = 5;
t < fe.size();
t++)
1298 if (
t < fe.size() - 2)
1300 txtDB << (
int)(fe[
t]) <<
" ";
1301 #if defined(DEMOXCHECK)
1302 if (fe[
t] > fe[
t + 1] &&
t >= 9 &&
t <= 23)
1303 logout <<
" Reversed charge ! " <<
t - 5 <<
" " << fe[
t] <<
" " << fe[
t + 1] << std::endl;
1308 float p01 = abs(fe[
t]);
1309 if (
t < fe.size() - 1)
1310 txtDB << 0.001 * (
int)(p01 * 1000.) <<
" ";
1312 txtDB << 0.000000001 * (
int)(p01 * 1000000000.) <<
" ";
1321 std::cout <<
" Please find the file : " << dbFileName <<
" for dataBase payload " << endl;
1324 logout <<
" modules lacking in RD during Threshold scan : " << std::endl;
1325 for (std::multimap<
float, TString, std::greater<float>>::const_iterator itr = badThr_Order.begin(); itr != badThr_Order.end(); ++itr)
1326 logout <<
" " << itr->second <<
" " << (itr->first) * 100. <<
"%" << endl;
1328 logout <<
" modules lacking in RD during ToT scan : " << std::endl;
1329 for (std::multimap<
float, TString, std::greater<float>>::const_iterator itr = badModules_Order.begin(); itr != badModules_Order.end(); ++itr)
1330 logout <<
" " << itr->second <<
" " << (itr->first) * 100. <<
"%" << endl;
1332 logout <<
" modules lacking in RD at certain charges during ToT scan : " << std::endl;
1333 for (std::multimap<
float, TString, std::greater<float>>::const_iterator itr = badModules_Order_detailed.begin();
1334 itr != badModules_Order_detailed.end(); ++itr)
1335 logout <<
" " << itr->second <<
" " << (itr->first) * 100. <<
"%" << endl;