paraToTRes[sfe][0] = parP0; paraToTRes[sfe][1] = parP1; paraToTRes[sfe][2] = parP2;
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 TString 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 TString Outdir =
"./";
161 #if defined(DEMOXCHECK)
162 spec +=
"DEMOXCHECK_";
166 TString rootFileName = Outdir +
"/TotChargeCalib_" + StrFileName +
".root";
167 TString logFileName = Outdir +
"/ChargeCalib_" + StrFileName +
".log";
168 TString 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 TString inThrFile =
"";
181 TString inTotFile =
"";
182 TString rodPath =
"";
183 TString inTotFileAux =
"";
184 TString 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,
"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, TString, std::greater<float>> badThr_Order;
274 for (
int sfe = 0; sfe < npsFEs; sfe++)
279 string knowModule =
"LI_S06_C_M1_C1";
280 string idx =
"I" +
ss.str();
282 pcdMap[knowModule][
idx][
"ThrNorm"] = -42.;
283 pcdMap[knowModule][
idx][
"ThrRmsNorm"] = -42.;
284 pcdMap[knowModule][
idx][
"ThrSigNorm"] = -42.;
285 pcdMap[knowModule][
idx][
"ThrLong"] = -42.;
286 pcdMap[knowModule][
idx][
"ThrRmsLong"] = -42.;
287 pcdMap[knowModule][
idx][
"ThrSigLong"] = -42.;
289 for (
int nl = 0; nl < 2; nl++)
290 THR_avg[nl][sfe] = ThrSig_avg[nl][sfe] = -99.;
292 idx =
"Threshold" +
ss.str();
293 h2_Thr[sfe] = std::make_unique<TH2D>(
idx.c_str(),
" ", 2, 0, 2, 200, 0, 5000);
294 idx =
"ThresholdSig" +
ss.str();
295 h2_ThrSig[sfe] = std::make_unique<TH2D>(
idx.c_str(),
" ", 2, 0, 2, 200, 0, 500);
298 if (inThrFile.Length() > 0)
301 <<
"INFO =>> [IBL] threshold scan analysis..." << endl;
303 TFile riThrFile(inThrFile,
"READ");
304 TString chi2HistName =
"SCURVE_CHI2";
305 TString thrHistName =
"SCURVE_MEAN";
306 TString sigHistName =
"SCURVE_SIGMA";
308 std::unique_ptr<TH1F> h1dChi2 = std::make_unique<TH1F>(
"h1dChi2",
"", 200, 0, 1);
309 std::unique_ptr<TH1F> h1dThr = std::make_unique<TH1F>(
"h1dThr" ,
"", 200, 0, 5000);
310 std::unique_ptr<TH1F> h1dSig = std::make_unique<TH1F>(
"h1dSig" ,
"", 200, 0, 500);
312 TDirectoryFile *
scanDir = (TDirectoryFile *)((TKey *)riThrFile.GetListOfKeys()->First())->ReadObj();
313 TList *rodKeyList = (TList *)
scanDir->GetListOfKeys();
314 TIter rodItr(rodKeyList);
317 while ((rodKey = (TKey *)rodItr()))
319 TString rodName(rodKey->GetName());
320 TDirectoryFile *rodDir = (TDirectoryFile *)rodKey->ReadObj();
321 TList *modKeyList = (TList *)rodDir->GetListOfKeys();
322 TIter modItr(modKeyList);
325 TDirectory *dirRod = roThrDir->mkdir(rodName);
327 while ((modKey = (TKey *)modItr()))
329 TString
modName(modKey->GetName());
330 string modStr(modKey->GetName());
331 TDirectory *dirMod = dirRod->mkdir(
modName);
333 TString chi2HistDirPath =
modName +
"/" + chi2HistName +
"/A0/B0";
335 TDirectory *chi2HistDir = (TDirectory *)rodDir->Get(chi2HistDirPath);
336 if (chi2HistDir == NULL)
338 cout <<
" Warning : NULL dir " << endl;
342 std::unique_ptr<TH2D> h2dChi2 (
static_cast<TH2D*
>(
static_cast<TKey*
>(chi2HistDir->GetListOfKeys()->First())->ReadObj()));
345 cout <<
" Warning : NULL dir " << endl;
348 TString thrHistDirPath =
modName +
"/" + thrHistName +
"/A0/B0";
349 TDirectoryFile *thrHistDir = (TDirectoryFile *)rodDir->Get(thrHistDirPath);
350 std::unique_ptr<TH2D> h2dThr(
static_cast<TH2D*
>(
static_cast<TKey*
>(thrHistDir->GetListOfKeys()->First())->ReadObj()));
351 TString sigHistDirPath =
modName +
"/" + sigHistName +
"/A0/B0";
353 TDirectoryFile *sigHistDir = (TDirectoryFile *)rodDir->Get(sigHistDirPath);
354 std::unique_ptr<TH2D> h2dSig (
static_cast<TH2D*
>(
static_cast<TKey*
>(sigHistDir->GetListOfKeys()->First())->ReadObj()));
356 array<std::unique_ptr<TH1F>, npsFEs> h1_ThrNorm{};
357 array<std::unique_ptr<TH1F>, npsFEs> h1_ThrSigNorm{};
358 array<std::unique_ptr<TH1F>, npsFEs> h1_ThrLong{};
359 array<std::unique_ptr<TH1F>, npsFEs> h1_ThrSigLong{};
360 array<float, npsFEs> IlledThr{};
362 for (
int sfe = 0; sfe < npsFEs; sfe++)
367 string hname = modStr +
"ThrNorm" +
ss.str();
368 h1_ThrNorm[sfe] = std::make_unique<TH1F>(
hname.c_str(),
"", 200, 0, 5000);
369 hname = modStr +
"ThrSigNorm" +
ss.str();
370 h1_ThrSigNorm[sfe] = std::make_unique<TH1F>(
hname.c_str(),
"", 200, 0, 500);
371 hname = modStr +
"ThrLong" +
ss.str();
372 h1_ThrLong[sfe] = std::make_unique<TH1F>(
hname.c_str(),
"", 200, 0, 5000);
373 hname = modStr +
"ThrSigLong" +
ss.str();
374 h1_ThrSigLong[sfe] = std::make_unique<TH1F>(
hname.c_str(),
"", 200, 0, 500);
377 for (
int col = 1; col <= ncol; col++)
381 float chi2 = h2dChi2->GetBinContent(col,
row);
382 float thr = h2dThr->GetBinContent(col,
row);
383 float sig = h2dSig->GetBinContent(col,
row);
397 if (col == 1 || col == ncol / 2 || col == ncol / 2 + 1 || col == ncol)
415 h1_ThrLong[circ]->Fill(
thr);
416 h1_ThrSigLong[circ]->Fill(
sig);
436 h1_ThrNorm[circ]->Fill(
thr);
437 h1_ThrSigNorm[circ]->Fill(
sig);
451 for (
int sfe = 0; sfe < npsFEs; sfe++)
455 string feName =
"I" +
ss.str();
457 float THRnorm = h1_ThrNorm[sfe]->GetMean();
458 bool valid = THRnorm > 100.;
459 pcdMap[modStr][feName][
"ThrNorm"] = THRnorm;
460 pcdMap[modStr][feName][
"ThrRmsNorm"] = h1_ThrNorm[sfe]->GetRMS();
461 float THRnormSig = h1_ThrSigNorm[sfe]->GetMean();
462 pcdMap[modStr][feName][
"ThrSigNorm"] = THRnormSig;
463 float THRlong = h1_ThrLong[sfe]->GetMean();
464 pcdMap[modStr][feName][
"ThrLong"] = THRlong;
465 pcdMap[modStr][feName][
"ThrRmsLong"] = h1_ThrLong[sfe]->GetRMS();
466 float THRlongSig = h1_ThrSigLong[sfe]->GetMean();
467 pcdMap[modStr][feName][
"ThrSigLong"] = THRlongSig;
469 float blank = 100. * IlledThr[sfe] * npsFEs / (1. * ncol * nrow);
472 badThr_Order.insert(std::pair<float, TString>(blank, (TString)(
modName +
" : " + blank)));
476 h2_Thr[sfe]->Fill(0.5, THRnorm, 1);
477 h2_Thr[sfe]->Fill(1.5, THRlong, 1);
478 h2_ThrSig[sfe]->Fill(0.5, THRnormSig, 1);
479 h2_ThrSig[sfe]->Fill(1.5, THRlongSig, 1);
481 dirMod->WriteTObject(h1_ThrNorm[sfe].
get());
482 dirMod->WriteTObject(h1_ThrLong[sfe].
get());
484 h1_ThrNorm[sfe].reset();
485 h1_ThrSigNorm[sfe].reset();
486 h1_ThrLong[sfe].reset();
487 h1_ThrSigLong[sfe].reset();
491 roThrDir->WriteTObject(h1dChi2.get());
493 roThrDir->WriteTObject(h1dThr.get());
495 roThrDir->WriteTObject(h1dSig.get());
499 for (
int sfe = 0; sfe < npsFEs; sfe++)
503 string hName =
"thrNorm" +
ss.str();
504 THR_avg[0][sfe] = h2_Thr[sfe]->ProjectionY(hName.c_str(), 1, 1)->
GetMean();
505 hName =
"thrLong" +
ss.str();
506 THR_avg[1][sfe] = h2_Thr[sfe]->ProjectionY(hName.c_str(), 2, 2)->
GetMean();
507 hName =
"thrSigNorm" +
ss.str();
508 ThrSig_avg[0][sfe] = h2_ThrSig[sfe]->ProjectionY(hName.c_str(), 1, 1)->
GetMean();
509 hName =
"thrSigLong" +
ss.str();
510 ThrSig_avg[1][sfe] = h2_ThrSig[sfe]->ProjectionY(hName.c_str(), 2, 2)->
GetMean();
512 h2_ThrSig[sfe].reset();
520 if (inTotFile.Length() == 0 || inTotFileAux.Length() == 0)
522 logout <<
" Missing ToT file from calib scan as input " << endl;
527 <<
"INFO =>> [IBL] tot calib analysis..." << endl;
529 TFile riTotFile(inTotFile,
"READ");
530 TFile riTotFileAux(inTotFileAux,
"READ");
532 TString totHistName =
"TOT_MEAN";
533 TString totSigHistName =
"TOT_SIGMA";
535 TDirectoryFile *
scanDir = (TDirectoryFile *)((TKey *)riTotFile.GetListOfKeys()->First())->ReadObj();
536 TList *rodKeyList = (TList *)
scanDir->GetListOfKeys();
537 TIter rodItr(rodKeyList);
540 std::map<float, std::pair<vector<TString>, vector<Double_t>>> ModuDataToPrint;
542 #if defined(DEMOXCHECK)
543 vector<TH1F *> h1_ChrgEntry(nToTibl,
nullptr);
545 vector<TH1F *> h1d_totSprdAll(nToTibl-1,
nullptr);
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 constexpr Int_t totFE = 14 * 16 * npsFEs;
562 using Row = Double_t[nchargeIBL];
563 using Row2 = Double_t[nToTibl];
565 std::unique_ptr<Row[]> TotArray{
new Row[totFE]{} };
566 std::unique_ptr<Row[]> TotErrArray{
new Row[totFE]{} };
567 std::unique_ptr<Row[]> TotSigArray {
new Row[totFE]{} };
568 std::unique_ptr<Row[]> TotSigErrArray{
new Row[totFE]{} };
569 std::unique_ptr<Row2[]> ChrgArray{
new Row2[totFE]{} };
570 std::unique_ptr<Row[]> ChrgErrArray{
new Row[totFE]{} };
572 gRandom =
new TRandom3(2203);
573 using Column = Double_t[totFE];
574 std::unique_ptr<Column[]> occuPhiEta{
new Column[nchargeIBL]{}};
577 std::map<float, TString> devChrg_Order;
578 std::map<float, TString> devToT_Order;
580 std::multimap<float, TString, std::greater<float>> badModules_Order;
581 std::multimap<float, TString, std::greater<float>> badModules_Order_detailed;
583 while ((rodKey = (TKey *)rodItr()))
585 TString rodName(rodKey->GetName());
586 string rodStr(rodKey->GetName());
587 TDirectoryFile *rodDir = (TDirectoryFile *)rodKey->ReadObj();
589 TString
path = rodDir->GetPath();
590 TString pathAux =
path.ReplaceAll(rodPath, rodPathAux);
592 TDirectoryFile *rodDirAux = (TDirectoryFile *)riTotFileAux.Get(pathAux);
593 if (rodDirAux == NULL)
595 std::cout<<
" Fail to get the rodPath in Aux: "<< pathAux << endl;
596 logout <<
" Fail to get the rodPath in Aux " << endl;
600 TDirectory *dirRod = roTotDir->mkdir(rodName);
602 TList *modKeyList = (TList *)rodDir->GetListOfKeys();
603 TIter modItr(modKeyList);
608 string modNames[16 * npsFEs];
610 float occuChrgs[nToTibl][16 * npsFEs];
612 #if defined(DEMOXCHECK)
613 TString feName_maxDevChrg =
"", feName_maxDevToT =
"";
614 float maxDevChrg = -9., maxDevToT = -9., avgDevChrg = 0., avgDevToT = 0.;
616 vector<TH1F *> h1d_totSprd(nToTibl - 1,
nullptr);
618 for (
int t = 0;
t < nToTibl - 1;
t++)
623 string prfmodname =
"ToT_Sprd_" +
tt.str();
624 h1d_totSprd[
t] =
new TH1F(prfmodname.c_str(),
"ToT spread ", 28, 0.3, 1.0);
625 prfmodname = rodStr +
"ToT spread @ ToT_" +
tt.str();
626 h1d_totSprd[
t]->SetTitle(prfmodname.c_str());
630 while ((modKey = (TKey *)modItr()))
632 TString
modName(modKey->GetName());
633 string modStr(modKey->GetName());
635 TDirectory *dirMod = dirRod->mkdir(
modName);
636 bool ibl3Dfe0 =
false, ibl3Dfe1 =
false;
638 int hashID = -1, hashIDL = -1, hashIDR = -1;
643 int eta_moduleL = -1, eta_moduleR = -1;
644 pixmap.mapping(modStr, &hashID, &
bec, &
layer, &phi_module, &eta_module);
647 pixmap.mapping(modStr +
"_1", &hashID, &
bec, &
layer, &phi_module, &eta_module);
652 eta_moduleL = eta_module;
655 pixmap.mapping(modStr +
"_2", &hashID, &
bec, &
layer, &phi_module, &eta_module);
660 eta_moduleR = eta_module;
664 std::cout<<
"negative hash ID\n";
669 if (pcdMap.find(modStr) == pcdMap.end()){
670 std::cout<<
"MOD not found "<< modStr <<
"\n";
676 array<std::unique_ptr<TH2D>, npsFEs> h2d_XchrgYtot{};
677 array<std::unique_ptr<TH2D>, npsFEs> h2d_XchrgYToTSig{};
679 for (
int sfe = 0; sfe < npsFEs; sfe++)
684 modNames[cntMod * npsFEs + sfe] = modStr +
"-" +
ss.str();
686 string prfmodname = modStr +
"ToTvsChrg_FE" +
ss.str();
687 h2d_XchrgYtot[sfe] = std::make_unique<TH2D>(prfmodname.c_str(),
"ToT vs Charge", nchargeIBL, chrgsbins, nToTibl, totbins);
689 prfmodname = modStr +
"ToT_Sig_vsChrg_FE" +
ss.str();
690 h2d_XchrgYToTSig[sfe] = std::make_unique<TH2D>(prfmodname.c_str(),
"ToT Sig vs Charge", nchargeIBL, chrgsbins, 100, 0., 1.);
694 for (
int c = 0;
c < nchargeIBL;
c++)
696 TString totHistDirPath =
modName +
"/" + totHistName +
"/A0/B0/C";
699 std::unique_ptr<TH2F> h2dTot;
700 TDirectoryFile* totHistDir(
static_cast<TDirectoryFile*
> (rodDir->Get(totHistDirPath)));
702 std::cout<<
" Missing totHistDir in : " << totHistDirPath << endl;
706 h2dTot.reset(
static_cast<TH2F*
> ((
static_cast<TKey*
>(totHistDir->GetListOfKeys()->First()))->ReadObj()));
707 if (h2dTot) h2dTot->SetDirectory(0);
710 std::cout<<
" Unrecoverable error in : " <<__LINE__ <<
" of CalibrateIBL.cxx\n";
714 unique_ptr<TH2F> h2dTotAux;
715 TDirectoryFile* totHistDirAux(
static_cast<TDirectoryFile*
>(rodDirAux->Get(totHistDirPath)));
718 std::cout<<
" Missing totHistDir in : " << totHistDirPath << endl;
719 logout <<
" Missing totHistDir in : " << totHistDirPath << endl;
723 h2dTotAux.reset(
static_cast<TH2F*
> ((
static_cast<TKey*
>(totHistDirAux->GetListOfKeys()->First())->ReadObj())));
725 if(h2dTotAux) h2dTotAux->SetDirectory(0);
728 std::cout<<
" Unrecoverable error in : " <<__LINE__ <<
" of CalibrateIBL.cxx\n";
731 TString totSigHistDirPath =
modName +
"/" + totSigHistName +
"/A0/B0/C";
733 TDirectoryFile* totSigHistDir (
static_cast<TDirectoryFile*
>(rodDir->Get(totSigHistDirPath)));
734 unique_ptr<TH2F> h2dTotSig (
static_cast<TH2F*
> ((
static_cast<TKey*
>(totSigHistDir->GetListOfKeys()->First()))->ReadObj()));
735 h2dTotSig->SetDirectory(0);
738 for (
int ieta = 0; ieta < ncol; ieta++)
740 for (
int iphi = 0; iphi < nrow; iphi++)
747 circ = (
int)(iphi / 84.);
761 float tot = h2dTot->GetBinContent(ieta + 1, iphi + 1) + HDCshift;
762 float totAux = h2dTotAux->GetBinContent(ieta + 1, iphi + 1);
770 if (
tot <= 5 ||
c <= 5)
772 if ((
c == 0 &&
tot - totAux > 0.8) || (
c >= 1 &&
c <= 3 &&
tot - totAux > 0.5) || (
c > 4 &&
tot - totAux > 0.3))
775 filltot = 0.5 * (totAux +
tot);
776 if (
c == 0 && totAux > 2.)
781 filltot = 0.5 * (totAux +
tot + 2.);
784 h2d_XchrgYtot[circ]->Fill(chrgAbaciIBL[
c], filltot, 1.);
788 float err = h2dTotSig->GetBinContent(ieta + 1, iphi + 1);
789 h2d_XchrgYToTSig[circ]->Fill(chrgAbaciIBL[
c],
err, 1.);
793 #if defined(DEMOXCHECK)
794 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))
795 logout <<
" tot = " <<
tot <<
", totAux = " << totAux <<
" @injection " << chrgAbaciIBL[
c] <<
" " <<
err << endl;
806 if (!(ibl3Dfe0 || ibl3Dfe1))
811 array<TDirectory *, npsFEs> dirFE;
813 Int_t idxMod = cntRod * 16 * npsFEs + cntMod * npsFEs;
815 for (
int sfe = 0; sfe < npsFEs; sfe++)
820 if (ibl3Dfe0 && sfe < npsFEs / 2)
824 else if (ibl3Dfe1 && sfe >= npsFEs / 2)
829 modHash += (sfe < npsFEs / 2 ? 0 : 1) * 0.8;
831 string prfmodname =
"DirFE_" +
ss.str();
832 dirFE[sfe] = dirMod->mkdir(prfmodname.c_str());
835 prfmodname = modStr +
"_profile_Tot_FE" +
ss.str();
836 std::unique_ptr<TProfile> prfl_TotsFE(h2d_XchrgYtot[sfe]->ProfileX(prfmodname.c_str(), 1, -1,
"s"));
837 prfl_TotsFE->SetTitle(prfmodname.c_str());
838 prfmodname = modStr +
"_profile_Chrg_FE" +
ss.str();
840 std::unique_ptr<TProfile> prfl_ChrgsFE(h2d_XchrgYtot[sfe]->ProfileY(prfmodname.c_str(), 1, -1,
"s"));
841 prfl_ChrgsFE->SetTitle(prfmodname.c_str());
843 Double_t TotArr[nchargeIBL], TotErrArr[nchargeIBL];
844 Double_t ChrgArr[nToTibl], ChrgErrArr[nToTibl];
846 Int_t idxFE = idxMod + sfe;
849 for (
int c = 0;
c < nchargeIBL;
c++)
851 TotArr[
c] = TotArray[idxFE][
c] = prfl_TotsFE->GetBinContent(
c + 1);
852 TotErrArr[
c] = TotErrArray[idxFE][
c] = prfl_TotsFE->GetBinError(
c + 1);
854 occuPhiEta[
c][idxFE] = prfl_TotsFE->GetBinEntries(
c + 1) * npsFEs / (1. * ncol * nrow);
856 if ((1. - occuPhiEta[
c][idxFE]) > badRDfracCut)
861 prfmodname = modStr +
"_ToTsig_FE" +
ss.str() +
"Chrg" +
sc.str();
863 std::unique_ptr<TH1D> h_ToTsig(h2d_XchrgYToTSig[sfe]->ProjectionY(prfmodname.c_str(),
c + 1,
c + 1));
864 TotSigArray[idxFE][
c] = TMath::Sqrt(h_ToTsig->GetMean() * h_ToTsig->GetMean() + h_ToTsig->GetRMS() * h_ToTsig->GetRMS());
865 TotSigErrArray[idxFE][
c] = TMath::Sqrt(h_ToTsig->GetMeanError() * h_ToTsig->GetMeanError() + h_ToTsig->GetRMSError() * h_ToTsig->GetRMSError());
873 for (
int c = 0;
c < nchargeIBL;
c++)
875 TotArr[
c] = TotArray[idxFE][
c] = 0.5 * (TotArray[idxFE - 1][
c] + TotArray[idxFE - 2][
c]);
876 TotErrArr[
c] = TotErrArray[idxFE][
c] = 0.5 * (TotErrArray[idxFE - 1][
c] + TotErrArray[idxFE - 2][
c]);
878 TotSigArray[idxFE][
c] = 0.5 * (TotSigArray[idxFE - 1][
c] + TotSigArray[idxFE - 2][
c]);
879 TotSigErrArray[idxFE][
c] = 0.5 * (TotSigErrArray[idxFE - 1][
c] + TotSigErrArray[idxFE - 2][
c]);
884 Double_t errToT_overChrg[nToTibl];
885 for (
int t = 0;
t < nToTibl;
t++)
887 ChrgArr[
t] = ChrgArray[idxFE][
t] = prfl_ChrgsFE->GetBinContent(
t + 1);
888 ChrgErrArr[
t] = ChrgErrArray[idxFE][
t] = prfl_ChrgsFE->GetBinError(
t + 1);
890 occuChrgs[
t][cntMod * npsFEs + sfe] = prfl_ChrgsFE->GetBinEntries(
t + 1) / RDentries[
t];
894 prfmodname = modStr +
"_Chrg_FE" +
ss.str() +
"ToT" +
st.str();
895 std::unique_ptr<TH1D> h_chrg(h2d_XchrgYtot[sfe]->ProjectionX(prfmodname.c_str(),
t + 1,
t + 1));
898 prfmodname = modStr +
" Charge_FE" +
ss.str() +
" @ ToT : " +
st.str();
899 h_chrg->SetTitle(prfmodname.c_str());
901 Double_t scl = h_chrg->Integral();
902 errToT_overChrg[
t] = 0.;
904 for (
int b = 0;
b < nchargeIBL;
b++)
906 errToT_overChrg[
t] += TotErrArr[
b] * (h_chrg->GetBinContent(
b + 1)) / scl;
908 if (errToT_overChrg[
t] == 0.)
909 errToT_overChrg[
t] = 1.1;
913 prfl_ChrgsFE.reset();
914 #if defined(DEMOXCHECK)
915 for (
int b = 1;
b < nToTibl;
b++)
917 double err = errToT_overChrg[
b];
918 h1d_totSprd[
b - 1]->Fill(
err);
919 h1d_totSprdAll[
b - 1]->Fill(
err);
926 for (
int t = 0;
t < nToTibl;
t++)
928 ChrgArr[
t] = ChrgArray[idxFE][
t] = 0.5 * (ChrgArray[idxFE - 1][
t] + ChrgArray[idxFE - 2][
t]);
929 ChrgErrArr[
t] = ChrgErrArray[idxFE][
t] = 0.5 * (ChrgErrArray[idxFE - 1][
t] + ChrgErrArray[idxFE - 2][
t]);
932 bool xoticMod =
std::find(reversedModules.begin(), reversedModules.end(),
int(modHash)) != reversedModules.end();
935 bool reverseH =
false, reverseT =
false;
936 for (
int t = 4;
t >= 1;
t--)
937 if (ChrgArr[
t] > ChrgArr[
t + 1])
942 for (
int t = 4;
t >= 1;
t--)
944 int tl = nToTibl -
t;
945 if (ChrgArr[
tl] < ChrgArr[
tl - 1])
954 #if defined(DEMOXCHECK)
955 logout <<
" Head reversed : " <<
int(modHash) <<
" " <<
modName <<
" " << sfe <<
" " << ChrgArr[1] <<
" "
956 << ChrgArr[2] <<
" " << ChrgArr[3] <<
" " << ChrgArr[4] <<
" " << ChrgArr[5] << std::endl;
959 for (
int t = 4;
t >= 1;
t--)
960 if (ChrgArr[
t] > ChrgArr[
t + 1] && (occuChrgs[
t][cntMod * npsFEs + sfe] < 0.5 || xoticMod))
961 ChrgArr[
t] = ChrgArray[idxFE][
t] = reverseCF_H[
t - 1] * ChrgArr[
t + 1];
965 for (
int t = 4;
t >= 1;
t--)
966 if (ChrgArr[
t + 1] != 0.)
967 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]));
972 #if defined(DEMOXCHECK)
973 logout <<
" Tail reversed : " <<
int(modHash) <<
" " <<
modName <<
" " << sfe <<
" " << ChrgArr[nToTibl - 5] <<
" "
974 << ChrgArr[nToTibl - 4] <<
" " << ChrgArr[nToTibl - 3] <<
" " << ChrgArr[nToTibl - 2] <<
" " << ChrgArr[nToTibl - 1] << std::endl;
977 for (
int t = 4;
t >= 1;
t--)
979 int tl = nToTibl -
t;
980 if (ChrgArr[
tl] < ChrgArr[
tl - 1] && (occuChrgs[
tl][cntMod * npsFEs + sfe] < 0.5 || xoticMod))
981 ChrgArr[
tl] = ChrgArray[idxFE][
tl] = reverseCF_T[
t - 1] * ChrgArr[
tl - 1];
986 for (
int t = 4;
t >= 1;
t--)
988 int tl = nToTibl -
t;
989 if (ChrgArr[
tl - 1] != 0.)
990 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]));
994 string gername = modStr +
"_grToTsig_FE_" +
ss.str();
995 std::unique_ptr<TGraphErrors> grTotSig = std::make_unique<TGraphErrors>(nchargeIBL, chrgAbaciIBL, TotSigArray[sfe], chargeErrArrIBL, TotSigErrArray[sfe]);
996 grTotSig->SetTitle(gername.c_str());
997 grTotSig->SetName(gername.c_str());
999 std::unique_ptr<TGraph> grTotSprd = std::make_unique<TGraph>(nToTibl, totAbaci, errToT_overChrg);
1000 gername =
"ToTsprd";
1001 grTotSprd->SetName(gername.c_str());
1002 gername = modStr +
" ToT spread over FrontEnd @ FE " +
ss.str();
1003 grTotSprd->SetTitle(gername.c_str());
1004 grTotSprd->SetLineColor(4);
1005 grTotSprd->SetMarkerStyle(4);
1006 grTotSprd->SetMarkerSize(1.);
1009 ToTres.SetParameter(1,13.);
1010 ToTres.SetParameter(2,0.65);
1011 ToTres.SetParLimits(1, 10., 16.);
1012 ToTres.SetParLimits(2, 0.3, 1.0);
1014 grTotSprd->Fit(&ToTres,
"MRQ");
1015 Double_t parP0 = ToTres.GetParameter(0);
1016 Double_t parP1 = ToTres.GetParameter(1);
1018 dirFE[sfe]->WriteTObject(grTotSprd.get());
1043 gername = modStr +
"_grToT_FE_" +
ss.str();
1044 std::unique_ptr<TGraphErrors> grTot = std::make_unique<TGraphErrors>(nchargeIBL, chrgAbaciIBL, TotArr, chargeErrArrIBL, TotErrArr);
1045 grTot->SetTitle(gername.c_str());
1046 grTot->SetName(gername.c_str());
1047 TF1 *f1ToTfromCharge =
new TF1(
"ToTfromCharge",
funcRation5, chrgAbaciIBL[0] - 100., chrgAbaciIBL[nchargeIBL - 1] + 300., 5);
1049 grTot->Fit(f1ToTfromCharge,
"MRQ");
1051 std::unique_ptr<TGraphErrors> grChrg = std::make_unique<TGraphErrors>(nToTibl, totAbaci, ChrgArr, totErrArr, ChrgErrArr);
1053 gername = modStr +
"_grChrg_FE_" +
ss.str();
1054 grChrg->SetName(gername.c_str());
1055 grChrg->SetTitle(gername.c_str());
1056 grChrg->SetLineColor(3);
1057 grChrg->SetLineWidth(3);
1059 TF1 *f1ChargefromToTLeft =
new TF1(
"ChargefromToTL",
funcRation5, 1., 7.5, 5);
1060 f1ChargefromToTLeft->SetLineColor(2);
1061 grChrg->Fit(f1ChargefromToTLeft,
"MRQ");
1062 if (f1ChargefromToTLeft->GetChisquare() / 4. > 2.){
1063 logout <<
"bad fit Left... " << std::endl;
1066 TF1 *f1ChargefromToTRight =
new TF1(
"ChargefromToTR",
funcRation5, 5.5, 16., 5);
1067 f1ChargefromToTRight->SetLineColor(4);
1068 grChrg->Fit(f1ChargefromToTRight,
"MRQ+");
1070 dirFE[sfe]->WriteTObject(grTot.get());
1071 dirFE[sfe]->WriteTObject(grTotSig.get());
1072 dirFE[sfe]->WriteTObject(h2d_XchrgYtot[sfe].
get());
1074 h2d_XchrgYtot[sfe].reset();
1075 h2d_XchrgYToTSig[sfe].reset();
1081 string Idx =
"I" +
ss.str();
1082 vector<TString> modName2prt;
1083 modName2prt.push_back(
modName);
1084 modName2prt.push_back((TString)(Idx));
1087 std::vector<Double_t> prtAux;
1088 prtAux.reserve(5 + 4 + nToTibl - 1 + 3);
1090 prtAux.push_back(modHash);
1091 prtAux.push_back(
bec);
1092 prtAux.push_back(
layer);
1093 prtAux.push_back(phi_module);
1094 prtAux.push_back(eta_module);
1096 modName2prt[0] = (modStr +
"_" +
ss.str()).c_str();
1097 if (ibl3Dfe0 && sfe < npsFEs / 2)
1100 modName2prt[0] =
modName +
"_0";
1101 prtAux[0] = hashIDL;
1102 prtAux[4] = eta_moduleL;
1104 if (ibl3Dfe1 && sfe >= npsFEs / 2)
1107 modName2prt[0] =
modName +
"_1";
1108 prtAux[0] = hashIDR;
1109 prtAux[4] = eta_moduleR;
1113 float ThrNorm = pcdMap[modStr][Idx][
"ThrNorm"];
1114 if (ThrNorm == 0. || ThrNorm == -42.)
1117 prtAux.push_back(THR_avg[0][sfe]);
1118 prtAux.push_back(ThrSig_avg[0][sfe]);
1119 prtAux.push_back(THR_avg[1][sfe]);
1120 prtAux.push_back(ThrSig_avg[1][sfe]);
1124 prtAux.push_back(pcdMap[modStr][Idx][
"ThrNorm"]);
1125 prtAux.push_back(pcdMap[modStr][Idx][
"ThrSigNorm"]);
1126 prtAux.push_back(pcdMap[modStr][Idx][
"ThrLong"]);
1127 prtAux.push_back(pcdMap[modStr][Idx][
"ThrSigLong"]);
1131 for (
int t = 1;
t < nToTibl;
t++)
1132 prtAux.push_back(ChrgArr[
t]);
1135 prtAux.push_back(parP0);
1136 prtAux.push_back(parP1);
1138 std::pair<vector<TString>, vector<Double_t>> payloadDB = std::pair<vector<TString>, vector<Double_t>>(modName2prt, prtAux);
1139 ModuDataToPrint.insert(std::pair<
float, std::pair<vector<TString>, vector<Double_t>>>(modHash, payloadDB));
1145 #if defined(DEMOXCHECK)
1147 TDirectory *dirToTSprd = dirRod->mkdir(
"ToT_Spreads");
1148 for (
int b = 0;
b < nToTibl - 1;
b++)
1150 Int_t
upper = h1d_totSprd[
b]->FindLastBinAbove(1, 1);
1151 h1d_totSprd[
b]->SetAxisRange(h1d_totSprd[
b]->GetBinLowEdge(
1152 h1d_totSprd[
b]->FindFirstBinAbove(1, 1)),
1153 h1d_totSprd[
b]->GetBinLowEdge(
upper) + h1d_totSprd[
b]->GetBinWidth(
upper),
"X");
1155 dirToTSprd->WriteTObject(h1d_totSprd[
b]);
1156 delete h1d_totSprd[
b];
1158 h1d_totSprd.clear();
1162 TH2F *h2_badChrgs =
new TH2F(rodName +
"ChargeOccupancy",
"Occupancy ", nchargeIBL, 0, nchargeIBL, 16 * npsFEs, 0, 16 * npsFEs);
1163 hn =
"Occupancy along charges @ " + rodName;
1164 h2_badChrgs->SetTitle(hn);
1166 TH2F *h2_badToT =
new TH2F(rodName +
"ToTOccupancy",
"Occupancy ", nToTibl - 1, 0.5, nToTibl - 0.5, 16 * npsFEs, 0, 16 * npsFEs);
1167 hn =
"Occupancy along ToT @ " + rodName;
1168 h2_badToT->SetTitle(hn);
1170 bool fillChrg =
false, fillToT =
false;
1172 for (
int sfe = 0; sfe < 16 * npsFEs; sfe++)
1175 for (
int c = 0;
c < nchargeIBL;
c++)
1177 float occu = occuPhiEta[
c][cntRod * 16 * npsFEs + sfe];
1178 float nt = 10. - floor(10. * occu + 0.5);
1180 TString modchrg = (TString)(modNames[sfe] +
"_Chrg_" +
c);
1182 badModules_Order_detailed.insert(std::pair<float, TString>(1. - occu, modchrg));
1188 h2_badChrgs->SetBinContent(
c + 1, sfe + 1,
nt);
1191 PhiEta /= nchargeIBL;
1193 badModules_Order.insert(std::pair<float, TString>(PhiEta,
1194 (TString)(modNames[sfe])));
1196 for (
int t = 1;
t < nToTibl;
t++)
1198 float nt = floor(10. * occuChrgs[
t][sfe] + 0.5);
1201 h2_badToT->SetBinContent(
t + 1, sfe + 1,
nt);
1205 TString
shortName = modNames[sfe].substr(9, 13).c_str();
1206 h2_badChrgs->GetYaxis()->SetBinLabel(sfe + 1,
shortName);
1207 h2_badToT->GetYaxis()->SetBinLabel(sfe + 1,
shortName);
1208 h2_badChrgs->SetStats(kFALSE);
1209 h2_badToT->SetStats(kFALSE);
1210 h2_badChrgs->SetTickLength(0.01,
"Y");
1211 h2_badToT->SetTickLength(0.01,
"Y");
1214 h2_badChrgs->SetOption(
"TEXT");
1215 h2_badToT->SetOption(
"TEXT");
1219 dirRod->WriteTObject(h2_badChrgs,
"",
"Overwrite");
1224 dirRod->WriteTObject(h2_badToT,
"",
"WriteDelete");
1235 #if defined(DEMOXCHECK)
1237 for (
int t = 0;
t < 4;
t++)
1240 logout <<
" correction factors for reversed charges : ";
1241 logout << reverseCF_H[
t] <<
", ";
1245 for (
int t = 0;
t < 4;
t++)
1248 logout <<
" correction factors for reversed charges : ";
1249 logout << reverseCF_T[
t] <<
", ";
1254 for (
int t = 0;
t < nToTibl;
t++)
1257 logout <<
"RD Entries per ToT bin ";
1258 logout << h1_ChrgEntry[
t]->GetMean() <<
", ";
1259 if (
t == nToTibl - 1)
1260 logout << std::endl;
1261 roTotDir->WriteTObject(h1_ChrgEntry[
t]);
1262 delete h1_ChrgEntry[
t];
1264 h1_ChrgEntry.clear();
1266 for (std::map<float, TString>::const_iterator itr = devChrg_Order.begin();
1267 itr != devChrg_Order.end(); ++itr)
1268 logout <<
" Charge dev order : " << itr->second <<
" : " << itr->first << endl;
1270 for (std::map<float, TString>::const_iterator itr = devToT_Order.begin();
1271 itr != devToT_Order.end(); ++itr)
1272 logout <<
" ToT dev order : " << itr->second <<
" : " << itr->first << endl;
1274 logout <<
"ToTRes (spread) & its RMS @ ToT from 1 to 16 : " << endl;
1275 for (
int t = 0;
t < nToTibl - 1;
t++)
1279 logout <<
"[ " << h1d_totSprdAll[
t]->GetMean() <<
" , " << h1d_totSprdAll[
t]->GetStdDev() <<
" ] ";
1280 if (
t < nToTibl - 2)
1281 logout <<
" , " << endl;
1282 if (
t == nToTibl - 2)
1283 logout <<
" ] " << endl;
1284 delete h1d_totSprdAll[
t];
1286 h1d_totSprdAll.clear();
1289 logout <<
" goto print " << std::endl;
1302 for (std::map<
float, std::pair<vector<TString>, vector<Double_t>>>::const_iterator itr = ModuDataToPrint.begin();
1303 itr != ModuDataToPrint.end(); ++itr)
1305 int hash = floor(itr->first);
1306 std::pair<vector<TString>, vector<Double_t>>
payload = itr->second;
1307 vector<Double_t> fe =
payload.second;
1309 txtDB <<
hash <<
" ";
1311 for (
unsigned int t = 5;
t < fe.size();
t++)
1313 if (
t < fe.size() - 2)
1315 txtDB << (
int)(fe[
t]) <<
" ";
1316 #if defined(DEMOXCHECK)
1317 if (fe[
t] > fe[
t + 1] &&
t >= 9 &&
t <= 23)
1318 logout <<
" Reversed charge ! " <<
t - 5 <<
" " << fe[
t] <<
" " << fe[
t + 1] << std::endl;
1323 float p01 = abs(fe[
t]);
1324 if (
t < fe.size() - 1)
1325 txtDB << 0.001 * (
int)(p01 * 1000.) <<
" ";
1327 txtDB << 0.000000001 * (
int)(p01 * 1000000000.) <<
" ";
1336 std::cout <<
" Please find the file : " << dbFileName <<
" for dataBase payload " << endl;
1339 logout <<
" modules lacking in RD during Threshold scan : " << std::endl;
1340 for (std::multimap<
float, TString, std::greater<float>>::const_iterator itr = badThr_Order.begin(); itr != badThr_Order.end(); ++itr)
1341 logout <<
" " << itr->second <<
" " << (itr->first) * 100. <<
"%" << endl;
1343 logout <<
" modules lacking in RD during ToT scan : " << std::endl;
1344 for (std::multimap<
float, TString, std::greater<float>>::const_iterator itr = badModules_Order.begin(); itr != badModules_Order.end(); ++itr)
1345 logout <<
" " << itr->second <<
" " << (itr->first) * 100. <<
"%" << endl;
1347 logout <<
" modules lacking in RD at certain charges during ToT scan : " << std::endl;
1348 for (std::multimap<
float, TString, std::greater<float>>::const_iterator itr = badModules_Order_detailed.begin();
1349 itr != badModules_Order_detailed.end(); ++itr)
1350 logout <<
" " << itr->second <<
" " << (itr->first) * 100. <<
"%" << endl;