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 while ((modKey = (TKey *)modItr()))
325 TString
modName(modKey->GetName());
326 string modStr(modKey->GetName());
328 TString chi2HistDirPath =
modName +
"/" + chi2HistName +
"/A0/B0";
330 TDirectory *chi2HistDir = (TDirectory *)rodDir->Get(chi2HistDirPath);
331 if (chi2HistDir == NULL)
333 cout <<
" Warning : NULL dir " << endl;
337 std::unique_ptr<TH2D> h2dChi2 (
static_cast<TH2D*
>(
static_cast<TKey*
>(chi2HistDir->GetListOfKeys()->First())->ReadObj()));
340 cout <<
" Warning : NULL dir " << endl;
343 TString thrHistDirPath =
modName +
"/" + thrHistName +
"/A0/B0";
344 TDirectoryFile *thrHistDir = (TDirectoryFile *)rodDir->Get(thrHistDirPath);
345 std::unique_ptr<TH2D> h2dThr(
static_cast<TH2D*
>(
static_cast<TKey*
>(thrHistDir->GetListOfKeys()->First())->ReadObj()));
346 TString sigHistDirPath =
modName +
"/" + sigHistName +
"/A0/B0";
348 TDirectoryFile *sigHistDir = (TDirectoryFile *)rodDir->Get(sigHistDirPath);
349 std::unique_ptr<TH2D> h2dSig (
static_cast<TH2D*
>(
static_cast<TKey*
>(sigHistDir->GetListOfKeys()->First())->ReadObj()));
351 array<std::unique_ptr<TH1F>, npsFEs> h1_ThrNorm{};
352 array<std::unique_ptr<TH1F>, npsFEs> h1_ThrSigNorm{};
353 array<std::unique_ptr<TH1F>, npsFEs> h1_ThrLong{};
354 array<std::unique_ptr<TH1F>, npsFEs> h1_ThrSigLong{};
355 array<float, npsFEs> IlledThr{};
357 for (
int sfe = 0; sfe < npsFEs; sfe++)
362 string hname = modStr +
"ThrNorm" +
ss.str();
363 h1_ThrNorm[sfe] = std::make_unique<TH1F>(
hname.c_str(),
"", 200, 0, 5000);
364 hname = modStr +
"ThrSigNorm" +
ss.str();
365 h1_ThrSigNorm[sfe] = std::make_unique<TH1F>(
hname.c_str(),
"", 200, 0, 500);
366 hname = modStr +
"ThrLong" +
ss.str();
367 h1_ThrLong[sfe] = std::make_unique<TH1F>(
hname.c_str(),
"", 200, 0, 5000);
368 hname = modStr +
"ThrSigLong" +
ss.str();
369 h1_ThrSigLong[sfe] = std::make_unique<TH1F>(
hname.c_str(),
"", 200, 0, 500);
376 float chi2 = h2dChi2->GetBinContent(
col,
row);
377 float thr = h2dThr->GetBinContent(
col,
row);
378 float sig = h2dSig->GetBinContent(
col,
row);
385 if (thr == 0 || thr > 10000 ||
sig == 0 ||
sig > 1000 ||
chi2 > 0.5 ||
chi2 <= 0)
392 if (
col == 1 ||
col == ncol / 2 ||
col == ncol / 2 + 1 ||
col == ncol)
410 h1_ThrLong[circ]->Fill(thr);
411 h1_ThrSigLong[circ]->Fill(
sig);
431 h1_ThrNorm[circ]->Fill(thr);
432 h1_ThrSigNorm[circ]->Fill(
sig);
446 for (
int sfe = 0; sfe < npsFEs; sfe++)
450 string feName =
"I" +
ss.str();
452 float THRnorm = h1_ThrNorm[sfe]->GetMean();
453 bool valid = THRnorm > 100.;
454 pcdMap[modStr][feName][
"ThrNorm"] = THRnorm;
455 pcdMap[modStr][feName][
"ThrRmsNorm"] = h1_ThrNorm[sfe]->GetRMS();
456 float THRnormSig = h1_ThrSigNorm[sfe]->GetMean();
457 pcdMap[modStr][feName][
"ThrSigNorm"] = THRnormSig;
458 float THRlong = h1_ThrLong[sfe]->GetMean();
459 pcdMap[modStr][feName][
"ThrLong"] = THRlong;
460 pcdMap[modStr][feName][
"ThrRmsLong"] = h1_ThrLong[sfe]->GetRMS();
461 float THRlongSig = h1_ThrSigLong[sfe]->GetMean();
462 pcdMap[modStr][feName][
"ThrSigLong"] = THRlongSig;
464 float blank = 100. * IlledThr[sfe] * npsFEs / (1. * ncol * nrow);
467 badThr_Order.insert(std::pair<float, TString>(blank, (TString)(
modName +
" : " + blank)));
471 h2_Thr[sfe]->Fill(0.5, THRnorm, 1);
472 h2_Thr[sfe]->Fill(1.5, THRlong, 1);
473 h2_ThrSig[sfe]->Fill(0.5, THRnormSig, 1);
474 h2_ThrSig[sfe]->Fill(1.5, THRlongSig, 1);
476 h1_ThrNorm[sfe].reset();
477 h1_ThrSigNorm[sfe].reset();
478 h1_ThrLong[sfe].reset();
479 h1_ThrSigLong[sfe].reset();
483 roThrDir->WriteTObject(h1dChi2.get());
485 roThrDir->WriteTObject(h1dThr.get());
487 roThrDir->WriteTObject(h1dSig.get());
491 for (
int sfe = 0; sfe < npsFEs; sfe++)
495 string hName =
"thrNorm" +
ss.str();
496 THR_avg[0][sfe] = h2_Thr[sfe]->ProjectionY(hName.c_str(), 1, 1)->
GetMean();
497 hName =
"thrLong" +
ss.str();
498 THR_avg[1][sfe] = h2_Thr[sfe]->ProjectionY(hName.c_str(), 2, 2)->
GetMean();
499 hName =
"thrSigNorm" +
ss.str();
500 ThrSig_avg[0][sfe] = h2_ThrSig[sfe]->ProjectionY(hName.c_str(), 1, 1)->
GetMean();
501 hName =
"thrSigLong" +
ss.str();
502 ThrSig_avg[1][sfe] = h2_ThrSig[sfe]->ProjectionY(hName.c_str(), 2, 2)->
GetMean();
504 h2_ThrSig[sfe].reset();
512 if (inTotFile.Length() == 0 || inTotFileAux.Length() == 0)
514 logout <<
" Missing ToT file from calib scan as input " << endl;
519 <<
"INFO =>> [IBL] tot calib analysis..." << endl;
521 TFile riTotFile(inTotFile,
"READ");
522 TFile riTotFileAux(inTotFileAux,
"READ");
524 TString totHistName =
"TOT_MEAN";
525 TString totSigHistName =
"TOT_SIGMA";
527 TDirectoryFile *
scanDir = (TDirectoryFile *)((TKey *)riTotFile.GetListOfKeys()->First())->ReadObj();
528 TList *rodKeyList = (TList *)
scanDir->GetListOfKeys();
529 TIter rodItr(rodKeyList);
532 std::map<float, std::pair<vector<TString>, vector<Double_t>>> ModuDataToPrint;
534 #if defined(DEMOXCHECK)
535 vector<TH1F *> h1_ChrgEntry;
536 h1_ChrgEntry.reserve(nToTibl);
538 vector<TH1F *> h1d_totSprdAll;
539 h1d_totSprdAll.reserve(nToTibl - 1);
541 for (
int t = 0;
t < nToTibl;
t++)
546 string hname =
"ChrgEntries_ToT_" +
tt.str();
547 h1_ChrgEntry[
t] =
new TH1F(
hname.c_str(),
"RD entries ", 100, 0., 100000);
549 hname =
"totSprdsFll_ToT_" +
tt.str();
551 h1d_totSprdAll[
t] =
new TH1F(
hname.c_str(),
"ToT spread ", 36, 0.2, 1.1);
555 const Int_t totFE = 14 * 16 * npsFEs;
556 Double_t TotArray[totFE][nchargeIBL], TotErrArray[totFE][nchargeIBL];
557 Double_t TotSigArray[totFE][nchargeIBL], TotSigErrArray[totFE][nchargeIBL];
558 Double_t ChrgArray[totFE][nToTibl], ChrgErrArray[totFE][nToTibl];
560 gRandom =
new TRandom3(2203);
562 float occuPhiEta[nchargeIBL][totFE];
565 std::map<float, TString> devChrg_Order;
566 std::map<float, TString> devToT_Order;
568 std::multimap<float, TString, std::greater<float>> badModules_Order;
569 std::multimap<float, TString, std::greater<float>> badModules_Order_detailed;
571 while ((rodKey = (TKey *)rodItr()))
573 TString rodName(rodKey->GetName());
574 string rodStr(rodKey->GetName());
575 TDirectoryFile *rodDir = (TDirectoryFile *)rodKey->ReadObj();
577 TString
path = rodDir->GetPath();
578 TString pathAux =
path.ReplaceAll(rodPath, rodPathAux);
580 TDirectoryFile *rodDirAux = (TDirectoryFile *)riTotFileAux.Get(pathAux);
581 if (rodDirAux == NULL)
583 std::cout<<
" Fail to get the rodPath in Aux: "<< pathAux << endl;
584 logout <<
" Fail to get the rodPath in Aux " << endl;
588 TDirectory *dirRod = roTotDir->mkdir(rodName);
590 TList *modKeyList = (TList *)rodDir->GetListOfKeys();
591 TIter modItr(modKeyList);
596 string modNames[16 * npsFEs];
598 float occuChrgs[nToTibl][16 * npsFEs];
600 #if defined(DEMOXCHECK)
601 TString feName_maxDevChrg =
"", feName_maxDevToT =
"";
602 float maxDevChrg = -9., maxDevToT = -9., avgDevChrg = 0., avgDevToT = 0.;
604 vector<TH1F *> h1d_totSprd;
605 h1d_totSprd.reserve(nToTibl - 1);
607 for (
int t = 0;
t < nToTibl - 1;
t++)
612 string prfmodname =
"ToT_Sprd_" +
tt.str();
613 h1d_totSprd[
t] =
new TH1F(prfmodname.c_str(),
"ToT spread ", 28, 0.3, 1.0);
614 prfmodname = rodStr +
"ToT spread @ ToT_" +
tt.str();
615 h1d_totSprd[
t]->SetTitle(prfmodname.c_str());
619 while ((modKey = (TKey *)modItr()))
621 TString
modName(modKey->GetName());
622 string modStr(modKey->GetName());
624 TDirectory *dirMod = dirRod->mkdir(
modName);
625 bool ibl3Dfe0 =
false, ibl3Dfe1 =
false;
627 int hashID = -1, hashIDL = -1, hashIDR = -1;
632 int eta_moduleL = -1, eta_moduleR = -1;
633 pixmap.mapping(modStr, &hashID, &
bec, &
layer, &phi_module, &eta_module);
636 pixmap.mapping(modStr +
"_1", &hashID, &
bec, &
layer, &phi_module, &eta_module);
641 eta_moduleL = eta_module;
644 pixmap.mapping(modStr +
"_2", &hashID, &
bec, &
layer, &phi_module, &eta_module);
649 eta_moduleR = eta_module;
653 std::cout<<
"negative hash ID\n";
658 if (pcdMap.find(modStr) == pcdMap.end()){
659 std::cout<<
"MOD not found "<< modStr <<
"\n";
665 array<std::unique_ptr<TH2D>, npsFEs> h2d_XchrgYtot{};
666 array<std::unique_ptr<TH2D>, npsFEs> h2d_XchrgYToTSig{};
668 for (
int sfe = 0; sfe < npsFEs; sfe++)
673 modNames[cntMod * npsFEs + sfe] = modStr +
"-" +
ss.str();
675 string prfmodname = modStr +
"ToTvsChrg_FE" +
ss.str();
676 h2d_XchrgYtot[sfe] = std::make_unique<TH2D>(prfmodname.c_str(),
"ToT vs Charge", nchargeIBL, chrgsbins, nToTibl, totbins);
678 prfmodname = modStr +
"ToT_Sig_vsChrg_FE" +
ss.str();
679 h2d_XchrgYToTSig[sfe] = std::make_unique<TH2D>(prfmodname.c_str(),
"ToT Sig vs Charge", nchargeIBL, chrgsbins, 100, 0., 1.);
683 for (
int c = 0;
c < nchargeIBL;
c++)
685 TString totHistDirPath =
modName +
"/" + totHistName +
"/A0/B0/C";
688 std::unique_ptr<TH2F> h2dTot;
689 TDirectoryFile* totHistDir(
static_cast<TDirectoryFile*
> (rodDir->Get(totHistDirPath)));
691 std::cout<<
" Missing totHistDir in : " << totHistDirPath << endl;
694 h2dTot.reset(
static_cast<TH2F*
> ((
static_cast<TKey*
>(totHistDir->GetListOfKeys()->First()))->ReadObj()));
695 h2dTot->SetDirectory(0);
698 unique_ptr<TH2F> h2dTotAux;
699 TDirectoryFile* totHistDirAux(
static_cast<TDirectoryFile*
>(rodDirAux->Get(totHistDirPath)));
702 std::cout<<
" Missing totHistDir in : " << totHistDirPath << endl;
703 logout <<
" Missing totHistDir in : " << totHistDirPath << endl;
706 h2dTotAux.reset(
static_cast<TH2F*
> ((
static_cast<TKey*
>(totHistDirAux->GetListOfKeys()->First())->ReadObj())));
707 h2dTotAux->SetDirectory(0);
710 TString totSigHistDirPath =
modName +
"/" + totSigHistName +
"/A0/B0/C";
712 TDirectoryFile* totSigHistDir (
static_cast<TDirectoryFile*
>(rodDir->Get(totSigHistDirPath)));
713 unique_ptr<TH2F> h2dTotSig (
static_cast<TH2F*
> ((
static_cast<TKey*
>(totSigHistDir->GetListOfKeys()->First()))->ReadObj()));
714 h2dTotSig->SetDirectory(0);
717 for (
int ieta = 0; ieta < ncol; ieta++)
719 for (
int iphi = 0; iphi < nrow; iphi++)
726 circ = (
int)(iphi / 84.);
740 float tot = h2dTot->GetBinContent(ieta + 1, iphi + 1) + HDCshift;
741 float totAux = h2dTotAux->GetBinContent(ieta + 1, iphi + 1);
749 if (tot <= 5 ||
c <= 5)
751 if ((
c == 0 && tot - totAux > 0.8) || (
c >= 1 &&
c <= 3 && tot - totAux > 0.5) || (
c > 4 && tot - totAux > 0.3))
754 filltot = 0.5 * (totAux + tot);
755 if (
c == 0 && totAux > 2.)
760 filltot = 0.5 * (totAux + tot + 2.);
763 h2d_XchrgYtot[circ]->Fill(chrgAbaciIBL[
c], filltot, 1.);
767 float err = h2dTotSig->GetBinContent(ieta + 1, iphi + 1);
768 h2d_XchrgYToTSig[circ]->Fill(chrgAbaciIBL[
c],
err, 1.);
772 #if defined(DEMOXCHECK)
773 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))
774 logout <<
" tot = " << tot <<
", totAux = " << totAux <<
" @injection " << chrgAbaciIBL[
c] <<
" " <<
err << endl;
785 if (!(ibl3Dfe0 || ibl3Dfe1))
790 array<TDirectory *, npsFEs> dirFE;
792 Int_t idxMod = cntRod * 16 * npsFEs + cntMod * npsFEs;
794 for (
int sfe = 0; sfe < npsFEs; sfe++)
799 if (ibl3Dfe0 && sfe < npsFEs / 2)
803 else if (ibl3Dfe1 && sfe >= npsFEs / 2)
808 modHash += (sfe < npsFEs / 2 ? 0 : 1) * 0.8;
810 string prfmodname =
"DirFE_" +
ss.str();
811 dirFE[sfe] = dirMod->mkdir(prfmodname.c_str());
814 prfmodname = modStr +
"_profile_Tot_FE" +
ss.str();
815 std::unique_ptr<TProfile> prfl_TotsFE(h2d_XchrgYtot[sfe]->ProfileX(prfmodname.c_str(), 1, -1,
"s"));
816 prfl_TotsFE->SetTitle(prfmodname.c_str());
817 prfmodname = modStr +
"_profile_Chrg_FE" +
ss.str();
819 std::unique_ptr<TProfile> prfl_ChrgsFE(h2d_XchrgYtot[sfe]->ProfileY(prfmodname.c_str(), 1, -1,
"s"));
820 prfl_ChrgsFE->SetTitle(prfmodname.c_str());
822 Double_t TotArr[nchargeIBL], TotErrArr[nchargeIBL];
823 Double_t ChrgArr[nToTibl], ChrgErrArr[nToTibl];
825 Int_t idxFE = idxMod + sfe;
828 for (
int c = 0;
c < nchargeIBL;
c++)
830 TotArr[
c] = TotArray[idxFE][
c] = prfl_TotsFE->GetBinContent(
c + 1);
831 TotErrArr[
c] = TotErrArray[idxFE][
c] = prfl_TotsFE->GetBinError(
c + 1);
833 occuPhiEta[
c][idxFE] = prfl_TotsFE->GetBinEntries(
c + 1) * npsFEs / (1. * ncol * nrow);
835 if ((1. - occuPhiEta[
c][idxFE]) > badRDfracCut)
840 prfmodname = modStr +
"_ToTsig_FE" +
ss.str() +
"Chrg" +
sc.str();
842 std::unique_ptr<TH1D> h_ToTsig(h2d_XchrgYToTSig[sfe]->ProjectionY(prfmodname.c_str(),
c + 1,
c + 1));
843 TotSigArray[idxFE][
c] = TMath::Sqrt(h_ToTsig->GetMean() * h_ToTsig->GetMean() + h_ToTsig->GetRMS() * h_ToTsig->GetRMS());
844 TotSigErrArray[idxFE][
c] = TMath::Sqrt(h_ToTsig->GetMeanError() * h_ToTsig->GetMeanError() + h_ToTsig->GetRMSError() * h_ToTsig->GetRMSError());
852 for (
int c = 0;
c < nchargeIBL;
c++)
854 TotArr[
c] = TotArray[idxFE][
c] = 0.5 * (TotArray[idxFE - 1][
c] + TotArray[idxFE - 2][
c]);
855 TotErrArr[
c] = TotErrArray[idxFE][
c] = 0.5 * (TotErrArray[idxFE - 1][
c] + TotErrArray[idxFE - 2][
c]);
857 TotSigArray[idxFE][
c] = 0.5 * (TotSigArray[idxFE - 1][
c] + TotSigArray[idxFE - 2][
c]);
858 TotSigErrArray[idxFE][
c] = 0.5 * (TotSigErrArray[idxFE - 1][
c] + TotSigErrArray[idxFE - 2][
c]);
863 Double_t errToT_overChrg[nToTibl];
864 for (
int t = 0;
t < nToTibl;
t++)
866 ChrgArr[
t] = ChrgArray[idxFE][
t] = prfl_ChrgsFE->GetBinContent(
t + 1);
867 ChrgErrArr[
t] = ChrgErrArray[idxFE][
t] = prfl_ChrgsFE->GetBinError(
t + 1);
869 occuChrgs[
t][cntMod * npsFEs + sfe] = prfl_ChrgsFE->GetBinEntries(
t + 1) / RDentries[
t];
873 prfmodname = modStr +
"_Chrg_FE" +
ss.str() +
"ToT" + st.str();
874 std::unique_ptr<TH1D> h_chrg(h2d_XchrgYtot[sfe]->ProjectionX(prfmodname.c_str(),
t + 1,
t + 1));
877 prfmodname = modStr +
" Charge_FE" +
ss.str() +
" @ ToT : " + st.str();
878 h_chrg->SetTitle(prfmodname.c_str());
880 Double_t scl = h_chrg->Integral();
881 errToT_overChrg[
t] = 0.;
883 for (
int b = 0;
b < nchargeIBL;
b++)
885 errToT_overChrg[
t] += TotErrArr[
b] * (h_chrg->GetBinContent(
b + 1)) / scl;
887 if (errToT_overChrg[
t] == 0.)
888 errToT_overChrg[
t] = 1.1;
892 prfl_ChrgsFE.reset();
893 #if defined(DEMOXCHECK)
894 for (
int b = 1;
b < nToTibl;
b++)
896 double err = errToT_overChrg[
b];
897 h1d_totSprd[
b - 1]->Fill(
err);
898 h1d_totSprdAll[
b - 1]->Fill(
err);
905 for (
int t = 0;
t < nToTibl;
t++)
907 ChrgArr[
t] = ChrgArray[idxFE][
t] = 0.5 * (ChrgArray[idxFE - 1][
t] + ChrgArray[idxFE - 2][
t]);
908 ChrgErrArr[
t] = ChrgErrArray[idxFE][
t] = 0.5 * (ChrgErrArray[idxFE - 1][
t] + ChrgErrArray[idxFE - 2][
t]);
911 bool xoticMod =
std::find(reversedModules.begin(), reversedModules.end(),
int(modHash)) != reversedModules.end();
914 bool reverseH =
false, reverseT =
false;
915 for (
int t = 4;
t >= 1;
t--)
916 if (ChrgArr[
t] > ChrgArr[
t + 1])
921 for (
int t = 4;
t >= 1;
t--)
923 int tl = nToTibl -
t;
924 if (ChrgArr[
tl] < ChrgArr[
tl - 1])
933 #if defined(DEMOXCHECK)
934 logout <<
" Head reversed : " <<
int(modHash) <<
" " <<
modName <<
" " << sfe <<
" " << ChrgArr[1] <<
" "
935 << ChrgArr[2] <<
" " << ChrgArr[3] <<
" " << ChrgArr[4] <<
" " << ChrgArr[5] << std::endl;
938 for (
int t = 4;
t >= 1;
t--)
939 if (ChrgArr[
t] > ChrgArr[
t + 1] && (occuChrgs[
t][cntMod * npsFEs + sfe] < 0.5 || xoticMod))
940 ChrgArr[
t] = ChrgArray[idxFE][
t] = reverseCF_H[
t - 1] * ChrgArr[
t + 1];
944 for (
int t = 4;
t >= 1;
t--)
945 if (ChrgArr[
t + 1] != 0.)
946 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]));
951 #if defined(DEMOXCHECK)
952 logout <<
" Tail reversed : " <<
int(modHash) <<
" " <<
modName <<
" " << sfe <<
" " << ChrgArr[nToTibl - 5] <<
" "
953 << ChrgArr[nToTibl - 4] <<
" " << ChrgArr[nToTibl - 3] <<
" " << ChrgArr[nToTibl - 2] <<
" " << ChrgArr[nToTibl - 1] << std::endl;
956 for (
int t = 4;
t >= 1;
t--)
958 int tl = nToTibl -
t;
959 if (ChrgArr[
tl] < ChrgArr[
tl - 1] && (occuChrgs[
tl][cntMod * npsFEs + sfe] < 0.5 || xoticMod))
960 ChrgArr[
tl] = ChrgArray[idxFE][
tl] = reverseCF_T[
t - 1] * ChrgArr[
tl - 1];
965 for (
int t = 4;
t >= 1;
t--)
967 int tl = nToTibl -
t;
968 if (ChrgArr[
tl - 1] != 0.)
969 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]));
973 string gername = modStr +
"_grToTsig_FE_" +
ss.str();
974 std::unique_ptr<TGraphErrors> grTotSig = std::make_unique<TGraphErrors>(nchargeIBL, chrgAbaciIBL, TotSigArray[sfe], chargeErrArrIBL, TotSigErrArray[sfe]);
975 grTotSig->SetTitle(gername.c_str());
976 grTotSig->SetName(gername.c_str());
978 std::unique_ptr<TGraph> grTotSprd = std::make_unique<TGraph>(nToTibl, totAbaci, errToT_overChrg);
980 grTotSprd->SetName(gername.c_str());
981 gername = modStr +
" ToT spread over FrontEnd @ FE " +
ss.str();
982 grTotSprd->SetTitle(gername.c_str());
983 grTotSprd->SetLineColor(4);
984 grTotSprd->SetMarkerStyle(4);
985 grTotSprd->SetMarkerSize(1.);
986 grTotSprd->SetMaximum(0.9);
989 ToTres.SetParameter(1,13.);
990 ToTres.SetParameter(2,0.65);
991 ToTres.SetParLimits(1, 10., 16.);
992 ToTres.SetParLimits(2, 0.3, 1.0);
994 grTotSprd->Fit(&ToTres,
"MRQ");
995 Double_t parP0 = ToTres.GetParameter(0);
996 Double_t parP1 = ToTres.GetParameter(1);
998 dirFE[sfe]->WriteTObject(grTotSprd.get());
1023 gername = modStr +
"_grToT_FE_" +
ss.str();
1024 std::unique_ptr<TGraphErrors> grTot = std::make_unique<TGraphErrors>(nchargeIBL, chrgAbaciIBL, TotArr, chargeErrArrIBL, TotErrArr);
1025 grTot->SetTitle(gername.c_str());
1026 grTot->SetName(gername.c_str());
1027 TF1 *f1ToTfromCharge =
new TF1(
"ToTfromCharge",
funcRation5, chrgAbaciIBL[0] - 100., chrgAbaciIBL[nchargeIBL - 1] + 300., 5);
1029 grTot->Fit(f1ToTfromCharge,
"MRQ");
1031 std::unique_ptr<TGraphErrors> grChrg = std::make_unique<TGraphErrors>(nToTibl, totAbaci, ChrgArr, totErrArr, ChrgErrArr);
1033 gername = modStr +
"_grChrg_FE_" +
ss.str();
1034 grChrg->SetName(gername.c_str());
1035 grChrg->SetTitle(gername.c_str());
1036 grChrg->SetLineColor(3);
1037 grChrg->SetLineWidth(3);
1039 TF1 *f1ChargefromToTLeft =
new TF1(
"ChargefromToTL",
funcRation5, 1., 7.5, 5);
1040 f1ChargefromToTLeft->SetLineColor(2);
1041 grChrg->Fit(f1ChargefromToTLeft,
"MRQ");
1042 if (f1ChargefromToTLeft->GetChisquare() / 4. > 2.){
1043 logout <<
"bad fit Left... " << std::endl;
1046 TF1 *f1ChargefromToTRight =
new TF1(
"ChargefromToTR",
funcRation5, 5.5, 16., 5);
1047 f1ChargefromToTRight->SetLineColor(4);
1048 grChrg->Fit(f1ChargefromToTRight,
"MRQ+");
1050 dirFE[sfe]->WriteTObject(grTot.get());
1051 dirFE[sfe]->WriteTObject(grTotSig.get());
1052 dirFE[sfe]->WriteTObject(h2d_XchrgYtot[sfe].
get());
1054 h2d_XchrgYtot[sfe].reset();
1055 h2d_XchrgYToTSig[sfe].reset();
1061 string Idx =
"I" +
ss.str();
1062 vector<TString> modName2prt;
1063 modName2prt.push_back(
modName);
1064 modName2prt.push_back((TString)(Idx));
1067 std::vector<Double_t> prtAux;
1068 prtAux.reserve(5 + 4 + nToTibl - 1 + 3);
1070 prtAux.push_back(modHash);
1071 prtAux.push_back(
bec);
1072 prtAux.push_back(
layer);
1073 prtAux.push_back(phi_module);
1074 prtAux.push_back(eta_module);
1076 modName2prt[0] = (modStr +
"_" +
ss.str()).c_str();
1077 if (ibl3Dfe0 && sfe < npsFEs / 2)
1080 modName2prt[0] =
modName +
"_0";
1081 prtAux[0] = hashIDL;
1082 prtAux[4] = eta_moduleL;
1084 if (ibl3Dfe1 && sfe >= npsFEs / 2)
1087 modName2prt[0] =
modName +
"_1";
1088 prtAux[0] = hashIDR;
1089 prtAux[4] = eta_moduleR;
1093 float ThrNorm = pcdMap[modStr][Idx][
"ThrNorm"];
1094 if (ThrNorm == 0. || ThrNorm == -42.)
1097 prtAux.push_back(THR_avg[0][sfe]);
1098 prtAux.push_back(ThrSig_avg[0][sfe]);
1099 prtAux.push_back(THR_avg[1][sfe]);
1100 prtAux.push_back(ThrSig_avg[1][sfe]);
1104 prtAux.push_back(pcdMap[modStr][Idx][
"ThrNorm"]);
1105 prtAux.push_back(pcdMap[modStr][Idx][
"ThrSigNorm"]);
1106 prtAux.push_back(pcdMap[modStr][Idx][
"ThrLong"]);
1107 prtAux.push_back(pcdMap[modStr][Idx][
"ThrSigLong"]);
1111 for (
int t = 1;
t < nToTibl;
t++)
1112 prtAux.push_back(ChrgArr[
t]);
1115 prtAux.push_back(parP0);
1116 prtAux.push_back(parP1);
1118 std::pair<vector<TString>, vector<Double_t>> payloadDB = std::pair<vector<TString>, vector<Double_t>>(modName2prt, prtAux);
1119 ModuDataToPrint.insert(std::pair<
float, std::pair<vector<TString>, vector<Double_t>>>(modHash, payloadDB));
1125 #if defined(DEMOXCHECK)
1127 TDirectory *dirToTSprd = dirRod->mkdir(
"ToT_Spreads");
1128 for (
int b = 0;
b < nToTibl - 1;
b++)
1130 Int_t
upper = h1d_totSprd[
b]->FindLastBinAbove(1, 1);
1131 h1d_totSprd[
b]->SetAxisRange(h1d_totSprd[
b]->GetBinLowEdge(
1132 h1d_totSprd[
b]->FindFirstBinAbove(1, 1)),
1133 h1d_totSprd[
b]->GetBinLowEdge(
upper) + h1d_totSprd[
b]->GetBinWidth(
upper),
"X");
1135 dirToTSprd->WriteTObject(h1d_totSprd[
b]);
1136 delete h1d_totSprd[
b];
1138 h1d_totSprd.clear();
1142 TH2F *h2_badChrgs =
new TH2F(rodName +
"ChargeOccupancy",
"Occupancy ", nchargeIBL, 0, nchargeIBL, 16 * npsFEs, 0, 16 * npsFEs);
1143 hn =
"Occupancy along charges @ " + rodName;
1144 h2_badChrgs->SetTitle(hn);
1146 TH2F *h2_badToT =
new TH2F(rodName +
"ToTOccupancy",
"Occupancy ", nToTibl - 1, 0.5, nToTibl - 0.5, 16 * npsFEs, 0, 16 * npsFEs);
1147 hn =
"Occupancy along ToT @ " + rodName;
1148 h2_badToT->SetTitle(hn);
1150 bool fillChrg =
false, fillToT =
false;
1152 for (
int sfe = 0; sfe < 16 * npsFEs; sfe++)
1155 for (
int c = 0;
c < nchargeIBL;
c++)
1157 float occu = occuPhiEta[
c][cntRod * 16 * npsFEs + sfe];
1158 float nt = 10. - floor(10. * occu + 0.5);
1160 TString modchrg = (TString)(modNames[sfe] +
"_Chrg_" +
c);
1162 badModules_Order_detailed.insert(std::pair<float, TString>(1. - occu, modchrg));
1168 h2_badChrgs->SetBinContent(
c + 1, sfe + 1,
nt);
1171 PhiEta /= nchargeIBL;
1173 badModules_Order.insert(std::pair<float, TString>(PhiEta,
1174 (TString)(modNames[sfe])));
1176 for (
int t = 1;
t < nToTibl;
t++)
1178 float nt = floor(10. * occuChrgs[
t][sfe] + 0.5);
1181 h2_badToT->SetBinContent(
t + 1, sfe + 1,
nt);
1185 TString
shortName = modNames[sfe].substr(9, 13).c_str();
1186 h2_badChrgs->GetYaxis()->SetBinLabel(sfe + 1,
shortName);
1187 h2_badToT->GetYaxis()->SetBinLabel(sfe + 1,
shortName);
1188 h2_badChrgs->SetStats(kFALSE);
1189 h2_badToT->SetStats(kFALSE);
1190 h2_badChrgs->SetTickLength(0.01,
"Y");
1191 h2_badToT->SetTickLength(0.01,
"Y");
1194 h2_badChrgs->SetOption(
"TEXT");
1195 h2_badToT->SetOption(
"TEXT");
1199 dirRod->WriteTObject(h2_badChrgs,
"",
"Overwrite");
1204 dirRod->WriteTObject(h2_badToT,
"",
"WriteDelete");
1215 #if defined(DEMOXCHECK)
1217 for (
int t = 0;
t < 4;
t++)
1220 logout <<
" correction factors for reversed charges : ";
1221 logout << reverseCF_H[
t] <<
", ";
1225 for (
int t = 0;
t < 4;
t++)
1228 logout <<
" correction factors for reversed charges : ";
1229 logout << reverseCF_T[
t] <<
", ";
1234 for (
int t = 0;
t < nToTibl;
t++)
1237 logout <<
"RD Entries per ToT bin ";
1238 logout << h1_ChrgEntry[
t]->GetMean() <<
", ";
1239 if (
t == nToTibl - 1)
1240 logout << std::endl;
1241 roTotDir->WriteTObject(h1_ChrgEntry[
t]);
1242 delete h1_ChrgEntry[
t];
1244 h1_ChrgEntry.clear();
1246 for (std::map<float, TString>::const_iterator itr = devChrg_Order.begin();
1247 itr != devChrg_Order.end(); ++itr)
1248 logout <<
" Charge dev order : " << itr->second <<
" : " << itr->first << endl;
1250 for (std::map<float, TString>::const_iterator itr = devToT_Order.begin();
1251 itr != devToT_Order.end(); ++itr)
1252 logout <<
" ToT dev order : " << itr->second <<
" : " << itr->first << endl;
1254 logout <<
"ToTRes (spread) & its RMS @ ToT from 1 to 16 : " << endl;
1255 for (
int t = 0;
t < nToTibl - 1;
t++)
1259 logout <<
"[ " << h1d_totSprdAll[
t]->GetMean() <<
" , " << h1d_totSprdAll[
t]->GetStdDev() <<
" ] ";
1260 if (
t < nToTibl - 2)
1261 logout <<
" , " << endl;
1262 if (
t == nToTibl - 2)
1263 logout <<
" ] " << endl;
1264 delete h1d_totSprdAll[
t];
1266 h1d_totSprdAll.clear();
1269 logout <<
" goto print " << std::endl;
1282 for (std::map<
float, std::pair<vector<TString>, vector<Double_t>>>::const_iterator itr = ModuDataToPrint.begin();
1283 itr != ModuDataToPrint.end(); ++itr)
1285 int hash = floor(itr->first);
1286 std::pair<vector<TString>, vector<Double_t>>
payload = itr->second;
1287 vector<Double_t> fe =
payload.second;
1289 txtDB <<
hash <<
" ";
1291 for (
unsigned int t = 5;
t < fe.size();
t++)
1293 if (
t < fe.size() - 2)
1295 txtDB << (
int)(fe[
t]) <<
" ";
1296 #if defined(DEMOXCHECK)
1297 if (fe[
t] > fe[
t + 1] &&
t >= 9 &&
t <= 23)
1298 logout <<
" Reversed charge ! " <<
t - 5 <<
" " << fe[
t] <<
" " << fe[
t + 1] << std::endl;
1303 float p01 = abs(fe[
t]);
1304 if (
t < fe.size() - 1)
1305 txtDB << 0.001 * (
int)(p01 * 1000.) <<
" ";
1307 txtDB << 0.000000001 * (
int)(p01 * 1000000000.) <<
" ";
1316 std::cout <<
" Please find the file : " << dbFileName <<
" for dataBase payload " << endl;
1319 logout <<
" modules lacking in RD during Threshold scan : " << std::endl;
1320 for (std::multimap<
float, TString, std::greater<float>>::const_iterator itr = badThr_Order.begin(); itr != badThr_Order.end(); ++itr)
1321 logout <<
" " << itr->second <<
" " << (itr->first) * 100. <<
"%" << endl;
1323 logout <<
" modules lacking in RD during ToT scan : " << std::endl;
1324 for (std::multimap<
float, TString, std::greater<float>>::const_iterator itr = badModules_Order.begin(); itr != badModules_Order.end(); ++itr)
1325 logout <<
" " << itr->second <<
" " << (itr->first) * 100. <<
"%" << endl;
1327 logout <<
" modules lacking in RD at certain charges during ToT scan : " << std::endl;
1328 for (std::multimap<
float, TString, std::greater<float>>::const_iterator itr = badModules_Order_detailed.begin();
1329 itr != badModules_Order_detailed.end(); ++itr)
1330 logout <<
" " << itr->second <<
" " << (itr->first) * 100. <<
"%" << endl;