109int iblCalib(
const std::string& InDir,
const std::string& THRscan,
const std::string&
scan,
const std::string& scanLowCharge)
114 constexpr bool run3 =
true;
115 const float badRDfracCut = 0.2;
119 constexpr int finerToT = 1;
120 constexpr bool moreFE =
false;
121 constexpr int npsFEs = moreFE ? 8 : 2;
123 gStyle->SetOptFit(1100);
125#if defined(DEMOXCHECK)
127 std::cout <<
" DEMOXCHECK will run ... " << std::endl;
130 int XcheckCharge[2] = {13, 14}, XcheckToT = 10;
131 int XcheckPhi[2] = {57, 63}, XcheckEta[2] = {23, 29};
132 std::string XcheckModule =
"LI_S11_A_M3_A6";
135 int ToTfill = 3 * finerToT, CHRGfill = 3;
140 Double_t tmpRCf_H[4] = {0.868295, 0.67523, 0.732279, 0.678458};
141 Double_t tmpRCf_T[4] = {1.02844, 1.10788, 1.07204, 1.11015};
142 Double_t reverseCF_H[4], reverseCF_T[4];
143 for (
int t = 0; t < 4; t++)
145 reverseCF_H[t] = tmpRCf_H[t];
146 reverseCF_T[t] = tmpRCf_T[t];
149 Double_t RDentries[33] = {0, 10494.8, 14605.6, 62952.6, 8663.57, 17320.2, 20417, 49508.9,
150 21646.8, 31503.9, 14955.6, 16290.7, 11617.5, 16461.2, 11980.5, 17210.5,
151 12773.7, 18574, 13930.9, 19777, 14629.4, 20619.5, 15191.6, 20883,
152 15411.1, 19198, 12097.4, 12109.7, 8881.96, 17235.1, 20802.3, 11265.8,
155 std::vector<int> reversedModules = {182, 211, 213, 229, 223, 231, 246, 280, 295, 350, 357, 360, 371, 403, 416, 423};
158 std::string Outdir =
"./";
161#if defined(DEMOXCHECK)
162 spec +=
"DEMOXCHECK_";
165 std::string StrFileName = spec +
scan;
166 std::string rootFileName = Outdir +
"/TotChargeCalib_" + StrFileName +
".root";
167 std::string logFileName = Outdir +
"/ChargeCalib_" + StrFileName +
".log";
168 std::string dbFileName = Outdir +
"/ChargeCalib_" + StrFileName +
".TXT";
171 rootFileName = Outdir +
"/TotChargeCalib_run2_" + StrFileName +
".root";
172 logFileName = Outdir +
"/ChargeCalib_run2_" + StrFileName +
".log";
173 dbFileName = Outdir +
"/ChargeCalib_run2_" + StrFileName +
".TXT";
177 ofstream logout(logFileName);
178 ofstream txtDB(dbFileName);
180 std::string inThrFile =
"";
181 std::string inTotFile =
"";
182 std::string rodPath =
"";
183 std::string inTotFileAux =
"";
184 std::string rodPathAux =
"";
186 std::cout <<
" Running IBL calibration analysis ... " << endl;
188 inThrFile = InDir + THRscan +
".root";
189 inTotFile = InDir +
scan +
".root";
190 rodPath = inTotFile +
":/" +
scan.substr(
scan.find(
"_")+1);
191 inTotFileAux = InDir + scanLowCharge +
".root";
192 rodPathAux = inTotFileAux +
":/" + scanLowCharge.substr(scanLowCharge.find(
"_")+1);
197 inThrFile =
"calib2018/IBL/THR_SCAN_S000083686.root";
198 inTotFile =
"calib2018/IBL/TOT_SCAN_S000083690.root";
199 rodPath = inTotFile +
":/S000083690";
203 int nrow = 336, ncol = 160;
205 const Int_t numChrgs = 22;
206 Double_t IBLchrgs[numChrgs] = {1400., 1500., 1750., 2000., 2500., 3000., 3500., 4000., 5000., 6000., 8000., 10000.,
207 12000., 14000., 16000., 18000., 20000., 22000., 24000., 26000., 28000., 30000.};
209 constexpr Int_t nchargeIBL = (run3 ? 22 : 19);
211 int skip = numChrgs - nchargeIBL;
212 Double_t chrgAbaciIBL[nchargeIBL], chargeErrArrIBL[nchargeIBL];
213 for (
int c = 0; c < nchargeIBL; c++)
215 chrgAbaciIBL[c] = IBLchrgs[c +
skip];
216 chargeErrArrIBL[c] = 0.;
219 Double_t chrgsbins[nchargeIBL + 1];
220 for (
int c = 1; c < nchargeIBL; c++)
221 chrgsbins[c] = 0.5 * (chrgAbaciIBL[c - 1] + chrgAbaciIBL[c]);
223 chrgsbins[0] = chrgAbaciIBL[0] - 0.5 * (chrgAbaciIBL[1] - chrgAbaciIBL[0]);
224 chrgsbins[nchargeIBL] = chrgAbaciIBL[nchargeIBL - 1] + 0.5 * (chrgAbaciIBL[nchargeIBL - 1] - chrgAbaciIBL[nchargeIBL - 2]);
227 constexpr Int_t nToTibl = 16 * finerToT + 1;
229 Double_t totAbaci[nToTibl], totbins[nToTibl + 1];
235 for (
int t = 2; t < nToTibl; t++)
237 totAbaci[t] = totAbaci[1] + (t - 1) / (1. * finerToT);
238 totbins[t] = 0.5 * (totAbaci[t] + totAbaci[t - 1]);
240 totbins[nToTibl] = totAbaci[nToTibl - 1] + 0.5 * (totbins[nToTibl - 1] - totbins[nToTibl - 2]);
242 Double_t totErrArr[nToTibl];
243 for (
int t = 0; t < nToTibl; t++)
246#if defined(DEMOXCHECK)
247 for (
int t = 0; t < nToTibl; t++)
248 logout <<
" totAbaci : " << t <<
" " << totbins[t] <<
" < " << totAbaci[t] <<
" > " << totbins[t + 1] << endl;
252 for (
int t = 1; t < nToTibl; t++)
254 RDentries[t] = RDentries[2 * t - 1] + RDentries[2 * t];
255 logout <<
" finer RDentries : " << t <<
" " << 2 * t - 1 <<
" " << 2 * t <<
" " << RDentries[t] << endl;
260 map<string, map<string, map<string, float>>> pcdMap;
262 TFile roFile(rootFileName.c_str(),
"RECREATE");
263 TDirectory *roThrDir = roFile.mkdir(
"Threshold");
264 TDirectory *roTotDir = roFile.mkdir(
"ToT");
268 Double_t THR_avg[2][npsFEs], ThrSig_avg[2][npsFEs];
269 array<std::unique_ptr<TH2D> , npsFEs> h2_Thr{};
270 array<std::unique_ptr<TH2D> , npsFEs> h2_ThrSig{};
272 std::multimap<float, std::string, std::greater<float>> badThr_Order;
273 static const std::string knowModule{
"LI_S06_C_M1_C1"};
274 for (
int sfe = 0; sfe < npsFEs; sfe++)
279 string idx =
"I" +
ss.str();
281 pcdMap[knowModule][idx][
"ThrNorm"] = -42.;
282 pcdMap[knowModule][idx][
"ThrRmsNorm"] = -42.;
283 pcdMap[knowModule][idx][
"ThrSigNorm"] = -42.;
284 pcdMap[knowModule][idx][
"ThrLong"] = -42.;
285 pcdMap[knowModule][idx][
"ThrRmsLong"] = -42.;
286 pcdMap[knowModule][idx][
"ThrSigLong"] = -42.;
288 for (
int nl = 0; nl < 2; nl++)
289 THR_avg[nl][sfe] = ThrSig_avg[nl][sfe] = -99.;
291 idx =
"Threshold" +
ss.str();
292 h2_Thr[sfe] = std::make_unique<TH2D>(idx.c_str(),
" ", 2, 0, 2, 200, 0, 5000);
293 idx =
"ThresholdSig" +
ss.str();
294 h2_ThrSig[sfe] = std::make_unique<TH2D>(idx.c_str(),
" ", 2, 0, 2, 200, 0, 500);
297 if (inThrFile.size() > 0)
300 <<
"INFO =>> [IBL] threshold scan analysis..." << endl;
302 TFile riThrFile(inThrFile.c_str(),
"READ");
303 std::string chi2HistName =
"SCURVE_CHI2";
304 std::string thrHistName =
"SCURVE_MEAN";
305 std::string sigHistName =
"SCURVE_SIGMA";
307 std::unique_ptr<TH1F> h1dChi2 = std::make_unique<TH1F>(
"h1dChi2",
"", 200, 0, 1);
308 std::unique_ptr<TH1F> h1dThr = std::make_unique<TH1F>(
"h1dThr" ,
"", 200, 0, 5000);
309 std::unique_ptr<TH1F> h1dSig = std::make_unique<TH1F>(
"h1dSig" ,
"", 200, 0, 500);
311 TDirectoryFile *scanDir = (TDirectoryFile *)((TKey *)riThrFile.GetListOfKeys()->First())->ReadObj();
312 TList *rodKeyList = (TList *)scanDir->GetListOfKeys();
313 TIter rodItr(rodKeyList);
316 while ((rodKey = (TKey *)rodItr()))
318 std::string rodName(rodKey->GetName());
319 TDirectoryFile *rodDir = (TDirectoryFile *)rodKey->ReadObj();
320 TList *modKeyList = (TList *)rodDir->GetListOfKeys();
321 TIter modItr(modKeyList);
324 TDirectory *dirRod = roThrDir->mkdir(rodName.c_str());
326 while ((modKey = (TKey *)modItr()))
328 std::string modName(modKey->GetName());
329 string modStr(modKey->GetName());
330 TDirectory *dirMod = dirRod->mkdir(modName.c_str());
332 std::string chi2HistDirPath = modName +
"/" + chi2HistName +
"/A0/B0";
334 TDirectory *chi2HistDir = (TDirectory *)rodDir->Get(chi2HistDirPath.c_str());
335 if (chi2HistDir == NULL)
337 cout <<
" Warning : NULL dir " << endl;
341 std::unique_ptr<TH2D> h2dChi2 (
static_cast<TH2D*
>(
static_cast<TKey*
>(chi2HistDir->GetListOfKeys()->First())->ReadObj()));
344 cout <<
" Warning : NULL dir " << endl;
347 std::string thrHistDirPath = modName +
"/" + thrHistName +
"/A0/B0";
348 TDirectoryFile *thrHistDir = (TDirectoryFile *)rodDir->Get(thrHistDirPath.c_str());
349 std::unique_ptr<TH2D> h2dThr(
static_cast<TH2D*
>(
static_cast<TKey*
>(thrHistDir->GetListOfKeys()->First())->ReadObj()));
350 std::string sigHistDirPath = modName +
"/" + sigHistName +
"/A0/B0";
352 TDirectoryFile *sigHistDir = (TDirectoryFile *)rodDir->Get(sigHistDirPath.c_str());
353 std::unique_ptr<TH2D> h2dSig (
static_cast<TH2D*
>(
static_cast<TKey*
>(sigHistDir->GetListOfKeys()->First())->ReadObj()));
355 array<std::unique_ptr<TH1F>, npsFEs> h1_ThrNorm{};
356 array<std::unique_ptr<TH1F>, npsFEs> h1_ThrSigNorm{};
357 array<std::unique_ptr<TH1F>, npsFEs> h1_ThrLong{};
358 array<std::unique_ptr<TH1F>, npsFEs> h1_ThrSigLong{};
359 array<float, npsFEs> IlledThr{};
361 for (
int sfe = 0; sfe < npsFEs; sfe++)
366 string hname = modStr +
"ThrNorm" +
ss.str();
367 h1_ThrNorm[sfe] = std::make_unique<TH1F>(hname.c_str(),
"", 200, 0, 5000);
368 hname = modStr +
"ThrSigNorm" +
ss.str();
369 h1_ThrSigNorm[sfe] = std::make_unique<TH1F>(hname.c_str(),
"", 200, 0, 500);
370 hname = modStr +
"ThrLong" +
ss.str();
371 h1_ThrLong[sfe] = std::make_unique<TH1F>(hname.c_str(),
"", 200, 0, 5000);
372 hname = modStr +
"ThrSigLong" +
ss.str();
373 h1_ThrSigLong[sfe] = std::make_unique<TH1F>(hname.c_str(),
"", 200, 0, 500);
376 for (
int col = 1; col <= ncol; col++)
378 for (
int row = 1; row <= nrow; row++)
380 float chi2 = h2dChi2->GetBinContent(col, row);
381 float thr = h2dThr->GetBinContent(col, row);
382 float sig = h2dSig->GetBinContent(col, row);
389 if (thr == 0 || thr > 10000 || sig == 0 || sig > 1000 ||
chi2 > 0.5 ||
chi2 <= 0)
396 if (col == 1 || col == ncol / 2 || col == ncol / 2 + 1 || col == ncol)
400 circ = (int)(row / 84.);
414 h1_ThrLong[circ]->Fill(thr);
415 h1_ThrSigLong[circ]->Fill(sig);
421 circ = (int)(row / 84.);
435 h1_ThrNorm[circ]->Fill(thr);
436 h1_ThrSigNorm[circ]->Fill(sig);
450 for (
int sfe = 0; sfe < npsFEs; sfe++)
454 string feName =
"I" +
ss.str();
456 float THRnorm = h1_ThrNorm[sfe]->GetMean();
457 bool valid = THRnorm > 100.;
458 pcdMap[modStr][feName][
"ThrNorm"] = THRnorm;
459 pcdMap[modStr][feName][
"ThrRmsNorm"] = h1_ThrNorm[sfe]->GetRMS();
460 float THRnormSig = h1_ThrSigNorm[sfe]->GetMean();
461 pcdMap[modStr][feName][
"ThrSigNorm"] = THRnormSig;
462 float THRlong = h1_ThrLong[sfe]->GetMean();
463 pcdMap[modStr][feName][
"ThrLong"] = THRlong;
464 pcdMap[modStr][feName][
"ThrRmsLong"] = h1_ThrLong[sfe]->GetRMS();
465 float THRlongSig = h1_ThrSigLong[sfe]->GetMean();
466 pcdMap[modStr][feName][
"ThrSigLong"] = THRlongSig;
468 float blank = 100. * IlledThr[sfe] * npsFEs / (1. * ncol * nrow);
471 badThr_Order.insert(std::pair<float, std::string>(blank, (std::string)(modName +
" : " + blank)));
475 h2_Thr[sfe]->Fill(0.5, THRnorm, 1);
476 h2_Thr[sfe]->Fill(1.5, THRlong, 1);
477 h2_ThrSig[sfe]->Fill(0.5, THRnormSig, 1);
478 h2_ThrSig[sfe]->Fill(1.5, THRlongSig, 1);
480 dirMod->WriteTObject(h1_ThrNorm[sfe].
get());
481 dirMod->WriteTObject(h1_ThrLong[sfe].
get());
483 h1_ThrNorm[sfe].reset();
484 h1_ThrSigNorm[sfe].reset();
485 h1_ThrLong[sfe].reset();
486 h1_ThrSigLong[sfe].reset();
490 roThrDir->WriteTObject(h1dChi2.get());
492 roThrDir->WriteTObject(h1dThr.get());
494 roThrDir->WriteTObject(h1dSig.get());
498 for (
int sfe = 0; sfe < npsFEs; sfe++)
502 string hName =
"thrNorm" +
ss.str();
503 THR_avg[0][sfe] = h2_Thr[sfe]->ProjectionY(hName.c_str(), 1, 1)->GetMean();
504 hName =
"thrLong" +
ss.str();
505 THR_avg[1][sfe] = h2_Thr[sfe]->ProjectionY(hName.c_str(), 2, 2)->GetMean();
506 hName =
"thrSigNorm" +
ss.str();
507 ThrSig_avg[0][sfe] = h2_ThrSig[sfe]->ProjectionY(hName.c_str(), 1, 1)->GetMean();
508 hName =
"thrSigLong" +
ss.str();
509 ThrSig_avg[1][sfe] = h2_ThrSig[sfe]->ProjectionY(hName.c_str(), 2, 2)->GetMean();
511 h2_ThrSig[sfe].reset();
519 if (inTotFile.size() == 0 || inTotFileAux.size() == 0)
521 logout <<
" Missing ToT file from calib scan as input " << endl;
526 <<
"INFO =>> [IBL] tot calib analysis..." << endl;
528 TFile riTotFile(inTotFile.c_str(),
"READ");
529 TFile riTotFileAux(inTotFileAux.c_str(),
"READ");
531 std::string totHistName =
"TOT_MEAN";
532 std::string totSigHistName =
"TOT_SIGMA";
534 TDirectoryFile *scanDir = (TDirectoryFile *)((TKey *)riTotFile.GetListOfKeys()->First())->ReadObj();
535 TList *rodKeyList = (TList *)scanDir->GetListOfKeys();
536 TIter rodItr(rodKeyList);
539 std::map<float, std::pair<vector<std::string>, vector<Double_t>>> ModuDataToPrint;
541#if defined(DEMOXCHECK)
542 vector<TH1F *> h1_ChrgEntry(nToTibl,
nullptr);
544 vector<TH1F *> h1d_totSprdAll(nToTibl-1,
nullptr);
546 for (
int t = 0; t < nToTibl; t++)
551 string hname =
"ChrgEntries_ToT_" + tt.str();
552 h1_ChrgEntry[t] =
new TH1F(hname.c_str(),
"RD entries ", 100, 0., 100000);
554 hname =
"totSprdsFll_ToT_" + tt.str();
556 h1d_totSprdAll[t] =
new TH1F(hname.c_str(),
"ToT spread ", 36, 0.2, 1.1);
560 constexpr Int_t totFE = 14 * 16 * npsFEs;
561 using Row = Double_t[nchargeIBL];
562 using Row2 = Double_t[nToTibl];
564 std::unique_ptr<Row[]> TotArray{
new Row[totFE]{} };
565 std::unique_ptr<Row[]> TotErrArray{
new Row[totFE]{} };
566 std::unique_ptr<Row[]> TotSigArray {
new Row[totFE]{} };
567 std::unique_ptr<Row[]> TotSigErrArray{
new Row[totFE]{} };
568 std::unique_ptr<Row2[]> ChrgArray{
new Row2[totFE]{} };
569 std::unique_ptr<Row[]> ChrgErrArray{
new Row[totFE]{} };
571 gRandom =
new TRandom3(2203);
572 using Column = Double_t[totFE];
573 std::unique_ptr<Column[]> occuPhiEta{
new Column[nchargeIBL]{}};
576 std::map<float, std::string> devChrg_Order;
577 std::map<float, std::string> devToT_Order;
579 std::multimap<float, std::string, std::greater<float>> badModules_Order;
580 std::multimap<float, std::string, std::greater<float>> badModules_Order_detailed;
582 while ((rodKey = (TKey *)rodItr()))
584 std::string rodName(rodKey->GetName());
585 string rodStr(rodKey->GetName());
586 TDirectoryFile *rodDir = (TDirectoryFile *)rodKey->ReadObj();
588 TString path = rodDir->GetPath();
589 std::string pathAux = path.ReplaceAll(rodPath, rodPathAux).Data();
591 TDirectoryFile *rodDirAux = (TDirectoryFile *)riTotFileAux.Get(pathAux.c_str());
592 if (rodDirAux == NULL)
594 std::cout<<
" Fail to get the rodPath in Aux: "<< pathAux << endl;
595 logout <<
" Fail to get the rodPath in Aux " << endl;
599 TDirectory *dirRod = roTotDir->mkdir(rodName.c_str());
601 TList *modKeyList = (TList *)rodDir->GetListOfKeys();
602 TIter modItr(modKeyList);
607 string modNames[16 * npsFEs];
609 float occuChrgs[nToTibl][16 * npsFEs];
611#if defined(DEMOXCHECK)
612 std::string feName_maxDevChrg =
"", feName_maxDevToT =
"";
613 float maxDevChrg = -9., maxDevToT = -9., avgDevChrg = 0., avgDevToT = 0.;
615 vector<TH1F *> h1d_totSprd(nToTibl - 1,
nullptr);
617 for (
int t = 0; t < nToTibl - 1; t++)
622 string prfmodname =
"ToT_Sprd_" + tt.str();
623 h1d_totSprd[t] =
new TH1F(prfmodname.c_str(),
"ToT spread ", 28, 0.3, 1.0);
624 prfmodname = rodStr +
"ToT spread @ ToT_" + tt.str();
625 h1d_totSprd[t]->SetTitle(prfmodname.c_str());
629 while ((modKey = (TKey *)modItr()))
631 std::string modName(modKey->GetName());
632 string modStr(modKey->GetName());
634 TDirectory *dirMod = dirRod->mkdir(modName.c_str());
635 bool ibl3Dfe0 =
false, ibl3Dfe1 =
false;
637 int hashID = -1, hashIDL = -1, hashIDR = -1;
642 int eta_moduleL = -1, eta_moduleR = -1;
643 pixmap.
mapping(modStr, &hashID, &bec, &layer, &phi_module, &eta_module);
646 pixmap.
mapping(modStr +
"_1", &hashID, &bec, &layer, &phi_module, &eta_module);
651 eta_moduleL = eta_module;
654 pixmap.
mapping(modStr +
"_2", &hashID, &bec, &layer, &phi_module, &eta_module);
659 eta_moduleR = eta_module;
663 std::cout<<
"negative hash ID\n";
668 if (pcdMap.find(modStr) == pcdMap.end()){
669 std::cout<<
"MOD not found "<< modStr <<
"\n";
675 array<std::unique_ptr<TH2D>, npsFEs> h2d_XchrgYtot{};
676 array<std::unique_ptr<TH2D>, npsFEs> h2d_XchrgYToTSig{};
678 for (
int sfe = 0; sfe < npsFEs; sfe++)
683 modNames[cntMod * npsFEs + sfe] = modStr +
"-" +
ss.str();
685 string prfmodname = modStr +
"ToTvsChrg_FE" +
ss.str();
686 h2d_XchrgYtot[sfe] = std::make_unique<TH2D>(prfmodname.c_str(),
"ToT vs Charge", nchargeIBL, chrgsbins, nToTibl, totbins);
688 prfmodname = modStr +
"ToT_Sig_vsChrg_FE" +
ss.str();
689 h2d_XchrgYToTSig[sfe] = std::make_unique<TH2D>(prfmodname.c_str(),
"ToT Sig vs Charge", nchargeIBL, chrgsbins, 100, 0., 1.);
693 for (
int c = 0; c < nchargeIBL; c++)
695 std::string totHistDirPath = modName +
"/" + totHistName +
"/A0/B0/C";
696 totHistDirPath += std::to_string(c);
698 std::unique_ptr<TH2F> h2dTot;
699 TDirectoryFile* totHistDir(
static_cast<TDirectoryFile*
> (rodDir->Get(totHistDirPath.c_str())));
701 std::cout<<
" Missing totHistDir in : " << totHistDirPath << endl;
705 h2dTot.reset(
static_cast<TH2F*
> ((
static_cast<TKey*
>(totHistDir->GetListOfKeys()->First()))->ReadObj()));
706 if (h2dTot) h2dTot->SetDirectory(0);
709 std::cout<<
" Unrecoverable error in : " <<__LINE__ <<
" of CalibrateIBL.cxx\n";
713 unique_ptr<TH2F> h2dTotAux;
714 TDirectoryFile* totHistDirAux(
static_cast<TDirectoryFile*
>(rodDirAux->Get(totHistDirPath.c_str())));
717 std::cout<<
" Missing totHistDir in : " << totHistDirPath << endl;
718 logout <<
" Missing totHistDir in : " << totHistDirPath << endl;
722 h2dTotAux.reset(
static_cast<TH2F*
> ((
static_cast<TKey*
>(totHistDirAux->GetListOfKeys()->First())->ReadObj())));
724 if(h2dTotAux) h2dTotAux->SetDirectory(0);
727 std::cout<<
" Unrecoverable error in : " <<__LINE__ <<
" of CalibrateIBL.cxx\n";
730 std::string totSigHistDirPath = modName +
"/" + totSigHistName +
"/A0/B0/C";
731 totSigHistDirPath += std::to_string(c);
732 TDirectoryFile* totSigHistDir (
static_cast<TDirectoryFile*
>(rodDir->Get(totSigHistDirPath.c_str())));
733 unique_ptr<TH2F> h2dTotSig (
static_cast<TH2F*
> ((
static_cast<TKey*
>(totSigHistDir->GetListOfKeys()->First()))->ReadObj()));
734 h2dTotSig->SetDirectory(0);
737 for (
int ieta = 0; ieta < ncol; ieta++)
739 for (
int iphi = 0; iphi < nrow; iphi++)
746 circ = (int)(iphi / 84.);
760 float tot = h2dTot->GetBinContent(ieta + 1, iphi + 1) + HDCshift;
761 float totAux = h2dTotAux->GetBinContent(ieta + 1, iphi + 1);
769 if (tot <= 5 || c <= 5)
771 if ((c == 0 && tot - totAux > 0.8) || (c >= 1 && c <= 3 && tot - totAux > 0.5) || (c > 4 && tot - totAux > 0.3))
774 filltot = 0.5 * (totAux + tot);
775 if (c == 0 && totAux > 2.)
780 filltot = 0.5 * (totAux + tot + 2.);
783 h2d_XchrgYtot[circ]->Fill(chrgAbaciIBL[c], filltot, 1.);
787 float err = h2dTotSig->GetBinContent(ieta + 1, iphi + 1);
788 h2d_XchrgYToTSig[circ]->Fill(chrgAbaciIBL[c], err, 1.);
792#if defined(DEMOXCHECK)
793 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))
794 logout <<
" tot = " << tot <<
", totAux = " << totAux <<
" @injection " << chrgAbaciIBL[c] <<
" " << err << endl;
805 if (!(ibl3Dfe0 || ibl3Dfe1))
810 array<TDirectory *, npsFEs> dirFE;
812 Int_t idxMod = cntRod * 16 * npsFEs + cntMod * npsFEs;
814 for (
int sfe = 0; sfe < npsFEs; sfe++)
819 if (ibl3Dfe0 && sfe < npsFEs / 2)
823 else if (ibl3Dfe1 && sfe >= npsFEs / 2)
828 modHash += (sfe < npsFEs / 2 ? 0 : 1) * 0.8;
830 string prfmodname =
"DirFE_" +
ss.str();
831 dirFE[sfe] = dirMod->mkdir(prfmodname.c_str());
834 prfmodname = modStr +
"_profile_Tot_FE" +
ss.str();
835 std::unique_ptr<TProfile> prfl_TotsFE(h2d_XchrgYtot[sfe]->ProfileX(prfmodname.c_str(), 1, -1,
"s"));
836 prfl_TotsFE->SetTitle(prfmodname.c_str());
837 prfmodname = modStr +
"_profile_Chrg_FE" +
ss.str();
839 std::unique_ptr<TProfile> prfl_ChrgsFE(h2d_XchrgYtot[sfe]->ProfileY(prfmodname.c_str(), 1, -1,
"s"));
840 prfl_ChrgsFE->SetTitle(prfmodname.c_str());
842 Double_t TotArr[nchargeIBL], TotErrArr[nchargeIBL];
843 Double_t ChrgArr[nToTibl], ChrgErrArr[nToTibl];
845 Int_t idxFE = idxMod + sfe;
848 for (
int c = 0; c < nchargeIBL; c++)
850 TotArr[c] = TotArray[idxFE][c] = prfl_TotsFE->GetBinContent(c + 1);
851 TotErrArr[c] = TotErrArray[idxFE][c] = prfl_TotsFE->GetBinError(c + 1);
853 occuPhiEta[c][idxFE] = prfl_TotsFE->GetBinEntries(c + 1) * npsFEs / (1. * ncol * nrow);
855 if ((1. - occuPhiEta[c][idxFE]) > badRDfracCut)
860 prfmodname = modStr +
"_ToTsig_FE" +
ss.str() +
"Chrg" +
sc.str();
862 std::unique_ptr<TH1D> h_ToTsig(h2d_XchrgYToTSig[sfe]->ProjectionY(prfmodname.c_str(), c + 1, c + 1));
863 TotSigArray[idxFE][c] = TMath::Sqrt(h_ToTsig->GetMean() * h_ToTsig->GetMean() + h_ToTsig->GetRMS() * h_ToTsig->GetRMS());
864 TotSigErrArray[idxFE][c] = TMath::Sqrt(h_ToTsig->GetMeanError() * h_ToTsig->GetMeanError() + h_ToTsig->GetRMSError() * h_ToTsig->GetRMSError());
872 for (
int c = 0; c < nchargeIBL; c++)
874 TotArr[c] = TotArray[idxFE][c] = 0.5 * (TotArray[idxFE - 1][c] + TotArray[idxFE - 2][c]);
875 TotErrArr[c] = TotErrArray[idxFE][c] = 0.5 * (TotErrArray[idxFE - 1][c] + TotErrArray[idxFE - 2][c]);
877 TotSigArray[idxFE][c] = 0.5 * (TotSigArray[idxFE - 1][c] + TotSigArray[idxFE - 2][c]);
878 TotSigErrArray[idxFE][c] = 0.5 * (TotSigErrArray[idxFE - 1][c] + TotSigErrArray[idxFE - 2][c]);
883 Double_t errToT_overChrg[nToTibl];
884 for (
int t = 0; t < nToTibl; t++)
886 ChrgArr[t] = ChrgArray[idxFE][t] = prfl_ChrgsFE->GetBinContent(t + 1);
887 ChrgErrArr[t] = ChrgErrArray[idxFE][t] = prfl_ChrgsFE->GetBinError(t + 1);
889 occuChrgs[t][cntMod * npsFEs + sfe] = prfl_ChrgsFE->GetBinEntries(t + 1) / RDentries[t];
893 prfmodname = modStr +
"_Chrg_FE" +
ss.str() +
"ToT" + st.str();
894 std::unique_ptr<TH1D> h_chrg(h2d_XchrgYtot[sfe]->ProjectionX(prfmodname.c_str(), t + 1, t + 1));
897 prfmodname = modStr +
" Charge_FE" +
ss.str() +
" @ ToT : " + st.str();
898 h_chrg->SetTitle(prfmodname.c_str());
900 Double_t scl = h_chrg->Integral();
901 errToT_overChrg[t] = 0.;
903 for (
int b = 0; b < nchargeIBL; b++)
905 errToT_overChrg[t] += TotErrArr[b] * (h_chrg->GetBinContent(b + 1)) / scl;
907 if (errToT_overChrg[t] == 0.)
908 errToT_overChrg[t] = 1.1;
912 prfl_ChrgsFE.reset();
913#if defined(DEMOXCHECK)
914 for (
int b = 1; b < nToTibl; b++)
916 double err = errToT_overChrg[b];
917 h1d_totSprd[b - 1]->Fill(err);
918 h1d_totSprdAll[b - 1]->Fill(err);
925 for (
int t = 0; t < nToTibl; t++)
927 ChrgArr[t] = ChrgArray[idxFE][t] = 0.5 * (ChrgArray[idxFE - 1][t] + ChrgArray[idxFE - 2][t]);
928 ChrgErrArr[t] = ChrgErrArray[idxFE][t] = 0.5 * (ChrgErrArray[idxFE - 1][t] + ChrgErrArray[idxFE - 2][t]);
931 bool xoticMod = std::find(reversedModules.begin(), reversedModules.end(),
int(modHash)) != reversedModules.end();
934 bool reverseH =
false, reverseT =
false;
935 for (
int t = 4; t >= 1; t--)
936 if (ChrgArr[t] > ChrgArr[t + 1])
941 for (
int t = 4; t >= 1; t--)
943 int tl = nToTibl - t;
944 if (ChrgArr[tl] < ChrgArr[tl - 1])
953#if defined(DEMOXCHECK)
954 logout <<
" Head reversed : " << int(modHash) <<
" " << modName <<
" " << sfe <<
" " << ChrgArr[1] <<
" "
955 << ChrgArr[2] <<
" " << ChrgArr[3] <<
" " << ChrgArr[4] <<
" " << ChrgArr[5] << std::endl;
958 for (
int t = 4; t >= 1; t--)
959 if (ChrgArr[t] > ChrgArr[t + 1] && (occuChrgs[t][cntMod * npsFEs + sfe] < 0.5 || xoticMod))
960 ChrgArr[t] = ChrgArray[idxFE][t] = reverseCF_H[t - 1] * ChrgArr[t + 1];
964 for (
int t = 4; t >= 1; t--)
965 if (ChrgArr[t + 1] != 0.)
966 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]));
971#if defined(DEMOXCHECK)
972 logout <<
" Tail reversed : " << int(modHash) <<
" " << modName <<
" " << sfe <<
" " << ChrgArr[nToTibl - 5] <<
" "
973 << ChrgArr[nToTibl - 4] <<
" " << ChrgArr[nToTibl - 3] <<
" " << ChrgArr[nToTibl - 2] <<
" " << ChrgArr[nToTibl - 1] << std::endl;
976 for (
int t = 4; t >= 1; t--)
978 int tl = nToTibl - t;
979 if (ChrgArr[tl] < ChrgArr[tl - 1] && (occuChrgs[tl][cntMod * npsFEs + sfe] < 0.5 || xoticMod))
980 ChrgArr[tl] = ChrgArray[idxFE][tl] = reverseCF_T[t - 1] * ChrgArr[tl - 1];
985 for (
int t = 4; t >= 1; t--)
987 int tl = nToTibl - t;
988 if (ChrgArr[tl - 1] != 0.)
989 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]));
993 string gername = modStr +
"_grToTsig_FE_" +
ss.str();
994 std::unique_ptr<TGraphErrors> grTotSig = std::make_unique<TGraphErrors>(nchargeIBL, chrgAbaciIBL, TotSigArray[sfe], chargeErrArrIBL, TotSigErrArray[sfe]);
995 grTotSig->SetTitle(gername.c_str());
996 grTotSig->SetName(gername.c_str());
998 std::unique_ptr<TGraph> grTotSprd = std::make_unique<TGraph>(nToTibl, totAbaci, errToT_overChrg);
1000 grTotSprd->SetName(gername.c_str());
1001 gername = modStr +
" ToT spread over FrontEnd @ FE " +
ss.str();
1002 grTotSprd->SetTitle(gername.c_str());
1003 grTotSprd->SetLineColor(4);
1004 grTotSprd->SetMarkerStyle(4);
1005 grTotSprd->SetMarkerSize(1.);
1008 ToTres.SetParameter(1,13.);
1009 ToTres.SetParameter(2,0.65);
1010 ToTres.SetParLimits(1, 10., 16.);
1011 ToTres.SetParLimits(2, 0.3, 1.0);
1013 grTotSprd->Fit(&ToTres,
"MRQ");
1014 Double_t parP0 = ToTres.GetParameter(0);
1015 Double_t parP1 = ToTres.GetParameter(1);
1017 dirFE[sfe]->WriteTObject(grTotSprd.get());
1042 gername = modStr +
"_grToT_FE_" +
ss.str();
1043 std::unique_ptr<TGraphErrors> grTot = std::make_unique<TGraphErrors>(nchargeIBL, chrgAbaciIBL, TotArr, chargeErrArrIBL, TotErrArr);
1044 grTot->SetTitle(gername.c_str());
1045 grTot->SetName(gername.c_str());
1046 TF1 *f1ToTfromCharge =
new TF1(
"ToTfromCharge",
funcRation5, chrgAbaciIBL[0] - 100., chrgAbaciIBL[nchargeIBL - 1] + 300., 5);
1048 grTot->Fit(f1ToTfromCharge,
"MRQ");
1050 std::unique_ptr<TGraphErrors> grChrg = std::make_unique<TGraphErrors>(nToTibl, totAbaci, ChrgArr, totErrArr, ChrgErrArr);
1052 gername = modStr +
"_grChrg_FE_" +
ss.str();
1053 grChrg->SetName(gername.c_str());
1054 grChrg->SetTitle(gername.c_str());
1055 grChrg->SetLineColor(3);
1056 grChrg->SetLineWidth(3);
1058 TF1 *f1ChargefromToTLeft =
new TF1(
"ChargefromToTL",
funcRation5, 1., 7.5, 5);
1059 f1ChargefromToTLeft->SetLineColor(2);
1060 grChrg->Fit(f1ChargefromToTLeft,
"MRQ");
1061 if (f1ChargefromToTLeft->GetChisquare() / 4. > 2.){
1062 logout <<
"bad fit Left... " << std::endl;
1065 TF1 *f1ChargefromToTRight =
new TF1(
"ChargefromToTR",
funcRation5, 5.5, 16., 5);
1066 f1ChargefromToTRight->SetLineColor(4);
1067 grChrg->Fit(f1ChargefromToTRight,
"MRQ+");
1069 dirFE[sfe]->WriteTObject(grTot.get());
1070 dirFE[sfe]->WriteTObject(grTotSig.get());
1071 dirFE[sfe]->WriteTObject(h2d_XchrgYtot[sfe].
get());
1073 h2d_XchrgYtot[sfe].reset();
1074 h2d_XchrgYToTSig[sfe].reset();
1080 string Idx =
"I" +
ss.str();
1081 vector<std::string> modName2prt;
1082 modName2prt.push_back(modName);
1083 modName2prt.push_back((std::string)(Idx));
1086 std::vector<Double_t> prtAux;
1087 prtAux.reserve(5 + 4 + nToTibl - 1 + 3);
1089 prtAux.push_back(modHash);
1090 prtAux.push_back(bec);
1091 prtAux.push_back(layer);
1092 prtAux.push_back(phi_module);
1093 prtAux.push_back(eta_module);
1095 modName2prt[0] = (modStr +
"_" +
ss.str()).c_str();
1096 if (ibl3Dfe0 && sfe < npsFEs / 2)
1099 modName2prt[0] = modName +
"_0";
1100 prtAux[0] = hashIDL;
1101 prtAux[4] = eta_moduleL;
1103 if (ibl3Dfe1 && sfe >= npsFEs / 2)
1106 modName2prt[0] = modName +
"_1";
1107 prtAux[0] = hashIDR;
1108 prtAux[4] = eta_moduleR;
1112 float ThrNorm = pcdMap[modStr][Idx][
"ThrNorm"];
1113 if (ThrNorm == 0. || ThrNorm == -42.)
1116 prtAux.push_back(THR_avg[0][sfe]);
1117 prtAux.push_back(ThrSig_avg[0][sfe]);
1118 prtAux.push_back(THR_avg[1][sfe]);
1119 prtAux.push_back(ThrSig_avg[1][sfe]);
1123 prtAux.push_back(pcdMap[modStr][Idx][
"ThrNorm"]);
1124 prtAux.push_back(pcdMap[modStr][Idx][
"ThrSigNorm"]);
1125 prtAux.push_back(pcdMap[modStr][Idx][
"ThrLong"]);
1126 prtAux.push_back(pcdMap[modStr][Idx][
"ThrSigLong"]);
1130 for (
int t = 1; t < nToTibl; t++)
1131 prtAux.push_back(ChrgArr[t]);
1134 prtAux.push_back(parP0);
1135 prtAux.push_back(parP1);
1137 std::pair<vector<std::string>, vector<Double_t>> payloadDB = std::pair<vector<std::string>, vector<Double_t>>(modName2prt, prtAux);
1138 ModuDataToPrint.insert(std::pair<
float, std::pair<vector<std::string>, vector<Double_t>>>(modHash, payloadDB));
1144#if defined(DEMOXCHECK)
1146 TDirectory *dirToTSprd = dirRod->mkdir(
"ToT_Spreads");
1147 for (
int b = 0; b < nToTibl - 1; b++)
1149 Int_t
upper = h1d_totSprd[b]->FindLastBinAbove(1, 1);
1150 h1d_totSprd[b]->SetAxisRange(h1d_totSprd[b]->GetBinLowEdge(
1151 h1d_totSprd[b]->FindFirstBinAbove(1, 1)),
1152 h1d_totSprd[b]->GetBinLowEdge(
upper) + h1d_totSprd[b]->GetBinWidth(
upper),
"X");
1154 dirToTSprd->WriteTObject(h1d_totSprd[b]);
1155 delete h1d_totSprd[b];
1157 h1d_totSprd.clear();
1159 std::string hn =
"";
1161 TH2F *h2_badChrgs =
new TH2F(rodName +
"ChargeOccupancy",
"Occupancy ", nchargeIBL, 0, nchargeIBL, 16 * npsFEs, 0, 16 * npsFEs);
1162 hn =
"Occupancy along charges @ " + rodName;
1163 h2_badChrgs->SetTitle(hn);
1165 TH2F *h2_badToT =
new TH2F(rodName +
"ToTOccupancy",
"Occupancy ", nToTibl - 1, 0.5, nToTibl - 0.5, 16 * npsFEs, 0, 16 * npsFEs);
1166 hn =
"Occupancy along ToT @ " + rodName;
1167 h2_badToT->SetTitle(hn);
1169 bool fillChrg =
false, fillToT =
false;
1171 for (
int sfe = 0; sfe < 16 * npsFEs; sfe++)
1174 for (
int c = 0; c < nchargeIBL; c++)
1176 float occu = occuPhiEta[c][cntRod * 16 * npsFEs + sfe];
1177 float nt = 10. - floor(10. * occu + 0.5);
1179 std::string modchrg = (std::string)(modNames[sfe] +
"_Chrg_" + c);
1181 badModules_Order_detailed.insert(std::pair<float, std::string>(1. - occu, modchrg));
1187 h2_badChrgs->SetBinContent(c + 1, sfe + 1, nt);
1190 PhiEta /= nchargeIBL;
1192 badModules_Order.insert(std::pair<float, std::string>(PhiEta,
1193 (std::string)(modNames[sfe])));
1195 for (
int t = 1; t < nToTibl; t++)
1197 float nt = floor(10. * occuChrgs[t][sfe] + 0.5);
1200 h2_badToT->SetBinContent(t + 1, sfe + 1, nt);
1204 std::string shortName = modNames[sfe].substr(9, 13).c_str();
1205 h2_badChrgs->GetYaxis()->SetBinLabel(sfe + 1, shortName);
1206 h2_badToT->GetYaxis()->SetBinLabel(sfe + 1, shortName);
1207 h2_badChrgs->SetStats(kFALSE);
1208 h2_badToT->SetStats(kFALSE);
1209 h2_badChrgs->SetTickLength(0.01,
"Y");
1210 h2_badToT->SetTickLength(0.01,
"Y");
1213 h2_badChrgs->SetOption(
"TEXT");
1214 h2_badToT->SetOption(
"TEXT");
1218 dirRod->WriteTObject(h2_badChrgs,
"",
"Overwrite");
1223 dirRod->WriteTObject(h2_badToT,
"",
"WriteDelete");
1234#if defined(DEMOXCHECK)
1236 for (
int t = 0; t < 4; t++)
1239 logout <<
" correction factors for reversed charges : ";
1240 logout << reverseCF_H[t] <<
", ";
1244 for (
int t = 0; t < 4; t++)
1247 logout <<
" correction factors for reversed charges : ";
1248 logout << reverseCF_T[t] <<
", ";
1253 for (
int t = 0; t < nToTibl; t++)
1256 logout <<
"RD Entries per ToT bin ";
1257 logout << h1_ChrgEntry[t]->GetMean() <<
", ";
1258 if (t == nToTibl - 1)
1259 logout << std::endl;
1260 roTotDir->WriteTObject(h1_ChrgEntry[t]);
1261 delete h1_ChrgEntry[t];
1263 h1_ChrgEntry.clear();
1265 for (std::map<float, std::string>::const_iterator itr = devChrg_Order.begin();
1266 itr != devChrg_Order.end(); ++itr)
1267 logout <<
" Charge dev order : " << itr->second <<
" : " << itr->first << endl;
1269 for (std::map<float, std::string>::const_iterator itr = devToT_Order.begin();
1270 itr != devToT_Order.end(); ++itr)
1271 logout <<
" ToT dev order : " << itr->second <<
" : " << itr->first << endl;
1273 logout <<
"ToTRes (spread) & its RMS @ ToT from 1 to 16 : " << endl;
1274 for (
int t = 0; t < nToTibl - 1; t++)
1278 logout <<
"[ " << h1d_totSprdAll[t]->GetMean() <<
" , " << h1d_totSprdAll[t]->GetStdDev() <<
" ] ";
1279 if (t < nToTibl - 2)
1280 logout <<
" , " << endl;
1281 if (t == nToTibl - 2)
1282 logout <<
" ] " << endl;
1283 delete h1d_totSprdAll[t];
1285 h1d_totSprdAll.clear();
1288 logout <<
" goto print " << std::endl;
1301 for (std::map<
float, std::pair<vector<std::string>, vector<Double_t>>>::const_iterator itr = ModuDataToPrint.begin();
1302 itr != ModuDataToPrint.end(); ++itr)
1304 int hash = floor(itr->first);
1305 std::pair<vector<std::string>, vector<Double_t>> payload = itr->second;
1306 vector<Double_t> fe = payload.second;
1308 txtDB << hash <<
" ";
1310 for (
unsigned int t = 5; t < fe.size(); t++)
1312 if (t < fe.size() - 2)
1314 txtDB << (int)(fe[t]) <<
" ";
1315#if defined(DEMOXCHECK)
1316 if (fe[t] > fe[t + 1] && t >= 9 && t <= 23)
1317 logout <<
" Reversed charge ! " << t - 5 <<
" " << fe[t] <<
" " << fe[t + 1] << std::endl;
1322 float p01 = abs(fe[t]);
1323 if (t < fe.size() - 1)
1324 txtDB << 0.001 * (int)(p01 * 1000.) <<
" ";
1326 txtDB << 0.000000001 * (int)(p01 * 1000000000.) <<
" ";
1335 std::cout <<
" Please find the file : " << dbFileName <<
" for dataBase payload " << endl;
1338 logout <<
" modules lacking in RD during Threshold scan : " << std::endl;
1339 for (std::multimap<
float, std::string, std::greater<float>>::const_iterator itr = badThr_Order.begin(); itr != badThr_Order.end(); ++itr)
1340 logout <<
" " << itr->second <<
" " << (itr->first) * 100. <<
"%" << endl;
1342 logout <<
" modules lacking in RD during ToT scan : " << std::endl;
1343 for (std::multimap<
float, std::string, std::greater<float>>::const_iterator itr = badModules_Order.begin(); itr != badModules_Order.end(); ++itr)
1344 logout <<
" " << itr->second <<
" " << (itr->first) * 100. <<
"%" << endl;
1346 logout <<
" modules lacking in RD at certain charges during ToT scan : " << std::endl;
1347 for (std::multimap<
float, std::string, std::greater<float>>::const_iterator itr = badModules_Order_detailed.begin();
1348 itr != badModules_Order_detailed.end(); ++itr)
1349 logout <<
" " << itr->second <<
" " << (itr->first) * 100. <<
"%" << endl;