ATLAS Offline Software
Functions | Variables
CalibrateIBL.cxx File Reference
#include "CxxUtils/checker_macros.h"
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <sstream>
#include <utility>
#include <map>
#include <array>
#include "TFile.h"
#include "TDirectory.h"
#include "TDirectoryFile.h"
#include "TKey.h"
#include "TH2D.h"
#include "TH2F.h"
#include "TProfile.h"
#include "TGraph.h"
#include "TGraphErrors.h"
#include "TMultiGraph.h"
#include "TMath.h"
#include "TF1.h"
#include "TStyle.h"
#include "TVectorT.h"
#include "THStack.h"
#include "TRandom3.h"
#include "ChargeCalibration/common/PixelMapping.h"
#include "PathResolver/PathResolver.h"

Go to the source code of this file.

Functions

double funcDisp (double *x, double *par)
 
double ChrgfromToT (float tot, double par[10])
 
double ToTfromChrg (float chrg, double par[5])
 
double funcRation5 (double *x, double *par)
 
double funcDispConvoluted (double *x, double *par)
 
int iblCalib (const std::string &InDir, const std::string &THRscan, const std::string &scan, const std::string &scanLowCharge)
 
void printError ()
 
int main (int argc, char *argv[])
 

Variables

 ATLAS_NO_CHECK_FILE_THREAD_SAFETY
 

Function Documentation

◆ ChrgfromToT()

double ChrgfromToT ( float  tot,
double  par[10] 
)

Definition at line 67 of file CalibrateIBL.cxx.

68 {
69  int lr = (tot <= 6. ? 0 : 5);
70  double chrg = 1400.;
71 
72  double num = par[0 + lr] + tot * (par[1 + lr] + tot * (par[2 + lr] + tot * par[3 + lr]));
73  double denom = 1. + tot * par[4 + lr];
74  if (denom != 0.)
75  chrg = num / denom;
76 
77  return chrg;
78 }

◆ funcDisp()

double funcDisp ( double *  x,
double *  par 
)

Definition at line 60 of file CalibrateIBL.cxx.

61 {
62  double ret = 9.9e10;
63  ret = par[0] * 0.1 * (1. - exp(-(x[0] - 1400.) * (x[0] - 1400.) / (1000. * par[1])) + par[2] * 0.0001 * sqrt(x[0]));
64  return ret;
65 }

◆ funcDispConvoluted()

double funcDispConvoluted ( double *  x,
double *  par 
)

Definition at line 100 of file CalibrateIBL.cxx.

101 {
102  double ret = 9.9e09;
103  ret = -par[0] * (x[0] - par[1]) + par[2];
104  return ret;
105 }

◆ funcRation5()

double funcRation5 ( double *  x,
double *  par 
)

Definition at line 90 of file CalibrateIBL.cxx.

91 {
92  double ret = 9.9e10;
93  double num = par[0] + x[0] * (par[1] + x[0] * (par[2] + x[0] * par[3]));
94  double denom = 1. + x[0] * par[4];
95  if (denom != 0.0)
96  ret = num / denom;
97  return ret;
98 }

◆ iblCalib()

int iblCalib ( const std::string &  InDir,
const std::string &  THRscan,
const std::string &  scan,
const std::string &  scanLowCharge 
)
    TF1 f1Disp( "f1Disp", funcDisp_old, chrgAbaciIBL[1], chrgAbaciIBL[nchargeIBL-1], 2 );
    grTotSig->Fit( &f1Disp,"MRQ" );
    Double_t parP0 = 1.*f1Disp.GetParameter(0);
    Double_t parP1 = 1.*f1Disp.GetParameter(1);
    Double_t parP2 = 0. ;

    TF1 f1Disp( "f1Disp", funcDisp, chrgAbaciIBL[1], chrgAbaciIBL[nchargeIBL-1], 3 );
    f1Disp.SetParLimits( 0, 3, 7 ) ;
    f1Disp.SetParLimits( 1, 300., 1000. ) ;
    f1Disp.SetParLimits( 2, -5, 5 ) ;

    grTotSig->Fit( &f1Disp,"MRQ" );
    Double_t parP0 = 1.*f1Disp.GetParameter(0);
    Double_t parP1 = 1.*f1Disp.GetParameter(1);
    Double_t parP2 = 1.*f1Disp.GetParameter(2);

paraToTRes[sfe][0] = parP0; paraToTRes[sfe][1] = parP1; paraToTRes[sfe][2] = parP2;

Definition at line 107 of file CalibrateIBL.cxx.

108 {
109  // creating the object for the pixel mapping
110  PixelMapping pixmap(PathResolver::find_file("PixelCalibAlgs/mapping.csv", "DATAPATH"));
111 
112  const bool run3 = true; // new series of injection charges (22) and new format
113  const float badRDfracCut = 0.2; // Cut on the fraction of bad read out per frontend
114  float HDCshift = 2;
115 
116  // Shall we try this later ?
117  const int finerToT = 1; // smaller bin size for ToT if doing fit
118  constexpr bool moreFE = false;
119  constexpr int npsFEs = moreFE ? 8 : 2;
120 
121  gStyle->SetOptFit(1100);
122 
123 #if defined(DEMOXCHECK)
124 
125  std::cout << " DEMOXCHECK will run ... " << std::endl;
126 
127  // For debugging a small area of pixels will print their readout and injection
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";
131 
132  // fill some histograms for monitoring
133  int ToTfill = 3 * finerToT, CHRGfill = 3;
134  const int HDC = 2; // specifying output
135 
136 #endif
137 
138  Double_t tmpRCf_H[4] = {0.868295, 0.67523, 0.732279, 0.678458}; // initial values from history calibration
139  Double_t tmpRCf_T[4] = {1.02844, 1.10788, 1.07204, 1.11015}; // initial values from history calibration
140  Double_t reverseCF_H[4], reverseCF_T[4];
141  for (int t = 0; t < 4; t++)
142  {
143  reverseCF_H[t] = tmpRCf_H[t];
144  reverseCF_T[t] = tmpRCf_T[t];
145  }
146 
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,
151  0.};
152 
153  std::vector<int> reversedModules = {182, 211, 213, 229, 223, 231, 246, 280, 295, 350, 357, 360, 371, 403, 416, 423};
154 
155  // outputs : something@somewhere as one like ...
156  TString Outdir = "./";
157  string spec = "ToTbin" + to_string(finerToT) + "_FrtEnd" + to_string(npsFEs) + "_";
158 
159 #if defined(DEMOXCHECK)
160  spec += "DEMOXCHECK_";
161 #endif
162 
163  TString StrFileName = spec + scan;
164  TString rootFileName = Outdir + "/TotChargeCalib_" + StrFileName + ".root";
165  TString logFileName = Outdir + "/ChargeCalib_" + StrFileName + ".log";
166  TString dbFileName = Outdir + "/ChargeCalib_" + StrFileName + ".TXT";
167  if (!run3)
168  {
169  rootFileName = Outdir + "/TotChargeCalib_run2_" + StrFileName + ".root";
170  logFileName = Outdir + "/ChargeCalib_run2_" + StrFileName + ".log";
171  dbFileName = Outdir + "/ChargeCalib_run2_" + StrFileName + ".TXT";
172  }
173 
174  // fetch pictures from directory : ToT/ROD_L1_Sxx/LI_Sy_AC_Mz_ACk
175  ofstream logout(logFileName);
176  ofstream txtDB(dbFileName);
177 
178  TString inThrFile = "";
179  TString inTotFile = "";
180  TString rodPath = "";
181  TString inTotFileAux = "";
182  TString rodPathAux = "";
183 
184  std::cout << " Running IBL calibration analysis ... " << endl;
185 
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);
191 
192  // historical record for run2 fomat
193  if (!run3)
194  {
195  inThrFile = "calib2018/IBL/THR_SCAN_S000083686.root";
196  inTotFile = "calib2018/IBL/TOT_SCAN_S000083690.root";
197  rodPath = inTotFile + ":/S000083690";
198  }
199 
200  // selecting Q threshold
201  int nrow = 336, ncol = 160; // y-axis, x-axis respectively
202 
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.};
206 
207  const Int_t nchargeIBL = (run3 ? 22 : 19);
208 
209  int skip = numChrgs - nchargeIBL;
210  Double_t chrgAbaciIBL[nchargeIBL], chargeErrArrIBL[nchargeIBL];
211  for (int c = 0; c < nchargeIBL; c++)
212  {
213  chrgAbaciIBL[c] = IBLchrgs[c + skip];
214  chargeErrArrIBL[c] = 0.;
215  }
216 
217  Double_t chrgsbins[nchargeIBL + 1];
218  for (int c = 1; c < nchargeIBL; c++)
219  chrgsbins[c] = 0.5 * (chrgAbaciIBL[c - 1] + chrgAbaciIBL[c]);
220 
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]);
223 
224  // please note extra +1 for ending bins.
225  const Int_t nToTibl = 16 * finerToT + 1;
226 
227  Double_t totAbaci[nToTibl], totbins[nToTibl + 1];
228 
229  totbins[0] = -0.25;
230  totbins[1] = 0.5;
231  totAbaci[0] = 0.0;
232  totAbaci[1] = 1.;
233  for (int t = 2; t < nToTibl; t++)
234  {
235  totAbaci[t] = totAbaci[1] + (t - 1) / (1. * finerToT);
236  totbins[t] = 0.5 * (totAbaci[t] + totAbaci[t - 1]);
237  }
238  totbins[nToTibl] = totAbaci[nToTibl - 1] + 0.5 * (totbins[nToTibl - 1] - totbins[nToTibl - 2]);
239 
240  Double_t totErrArr[nToTibl];
241  for (int t = 0; t < nToTibl; t++)
242  totErrArr[t] = 0.;
243 
244 #if defined(DEMOXCHECK)
245  for (int t = 0; t < nToTibl; t++)
246  logout << " totAbaci : " << t << " " << totbins[t] << " < " << totAbaci[t] << " > " << totbins[t + 1] << endl;
247 
248  if (finerToT == 1)
249  {
250  for (int t = 1; t < nToTibl; t++)
251  {
252  RDentries[t] = RDentries[2 * t - 1] + RDentries[2 * t];
253  logout << " finer RDentries : " << t << " " << 2 * t - 1 << " " << 2 * t << " " << RDentries[t] << endl;
254  }
255  }
256 #endif
257 
258  map<string, map<string, map<string, float>>> pcdMap;
259 
260  TFile roFile(rootFileName, "RECREATE");
261  TDirectory *roThrDir = roFile.mkdir("Threshold");
262  TDirectory *roTotDir = roFile.mkdir("ToT");
263 
264  // ****************************** Threshold IBL ******************************
265 
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{};
269 
270  std::multimap<float, TString, std::greater<float>> badThr_Order;
271 
272  for (int sfe = 0; sfe < npsFEs; sfe++)
273  {
274  stringstream ss;
275  ss << sfe;
276 
277  string knowModule = "LI_S06_C_M1_C1";
278  string idx = "I" + ss.str();
279 
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.;
286 
287  for (int nl = 0; nl < 2; nl++)
288  THR_avg[nl][sfe] = ThrSig_avg[nl][sfe] = -99.;
289 
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);
294  }
295 
296  if (inThrFile.Length() > 0)
297  {
298  std::cout << endl
299  << "INFO =>> [IBL] threshold scan analysis..." << endl;
300 
301  TFile riThrFile(inThrFile, "READ");
302  TString chi2HistName = "SCURVE_CHI2";
303  TString thrHistName = "SCURVE_MEAN";
304  TString sigHistName = "SCURVE_SIGMA";
305 
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);
309 
310  TDirectoryFile *scanDir = (TDirectoryFile *)((TKey *)riThrFile.GetListOfKeys()->First())->ReadObj();
311  TList *rodKeyList = (TList *)scanDir->GetListOfKeys();
312  TIter rodItr(rodKeyList);
313  TKey *rodKey;
314 
315  while ((rodKey = (TKey *)rodItr()))
316  {
317  TString rodName(rodKey->GetName());
318  TDirectoryFile *rodDir = (TDirectoryFile *)rodKey->ReadObj();
319  TList *modKeyList = (TList *)rodDir->GetListOfKeys();
320  TIter modItr(modKeyList);
321  TKey *modKey;
322 
323  while ((modKey = (TKey *)modItr()))
324  {
325  TString modName(modKey->GetName());
326  string modStr(modKey->GetName());
327 
328  TString chi2HistDirPath = modName + "/" + chi2HistName + "/A0/B0";
329 
330  TDirectory *chi2HistDir = (TDirectory *)rodDir->Get(chi2HistDirPath);
331  if (chi2HistDir == NULL)
332  {
333  cout << " Warning : NULL dir " << endl;
334  continue;
335  }
336 
337  std::unique_ptr<TH2D> h2dChi2 (static_cast<TH2D*>(static_cast<TKey*>(chi2HistDir->GetListOfKeys()->First())->ReadObj()));
338  if (h2dChi2 == NULL)
339  {
340  cout << " Warning : NULL dir " << endl;
341  continue;
342  }
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";
347 
348  TDirectoryFile *sigHistDir = (TDirectoryFile *)rodDir->Get(sigHistDirPath);
349  std::unique_ptr<TH2D> h2dSig (static_cast<TH2D*>(static_cast<TKey*>(sigHistDir->GetListOfKeys()->First())->ReadObj()));
350 
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{};
356 
357  for (int sfe = 0; sfe < npsFEs; sfe++)
358  {
359  stringstream ss;
360  ss << sfe;
361 
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);
370  }
371 
372  for (int col = 1; col <= ncol; col++)
373  {
374  for (int row = 1; row <= nrow; row++)
375  {
376  float chi2 = h2dChi2->GetBinContent(col, row);
377  float thr = h2dThr->GetBinContent(col, row);
378  float sig = h2dSig->GetBinContent(col, row);
379 
380  h1dChi2->Fill(chi2);
381  h1dThr->Fill(thr);
382  h1dSig->Fill(sig);
383  // Shall we measure/count the goodness of THR scan here ?
384  bool filled = true;
385  if (thr == 0 || thr > 10000 || sig == 0 || sig > 1000 || chi2 > 0.5 || chi2 <= 0)
386  {
387  filled = false;
388  }
389  int circ = -1;
390  if (filled)
391  {
392  if (col == 1 || col == ncol / 2 || col == ncol / 2 + 1 || col == ncol)
393  {
394  if (moreFE)
395  {
396  circ = (int)(row / 84.);
397  if (col > 80)
398  {
399  circ = 7 - circ;
400  }
401  }
402  else
403  {
404  if (col <= ncol / 2)
405  circ = 0;
406  else
407  circ = 1;
408  }
409 
410  h1_ThrLong[circ]->Fill(thr);
411  h1_ThrSigLong[circ]->Fill(sig);
412  }
413  else
414  {
415  if (moreFE)
416  {
417  circ = (int)(row / 84.);
418  if (col > 80)
419  {
420  circ = 7 - circ;
421  }
422  }
423  else
424  {
425  if (col <= ncol / 2)
426  circ = 0;
427  else
428  circ = 1;
429  }
430 
431  h1_ThrNorm[circ]->Fill(thr);
432  h1_ThrSigNorm[circ]->Fill(sig);
433  }
434  }
435  else
436  {
437  // Note: what is the intention? circ is -1 here
438  continue;
439  }
440  }
441  }
442  h2dSig.reset();
443  h2dThr.reset();
444  h2dChi2.reset();
445 
446  for (int sfe = 0; sfe < npsFEs; sfe++)
447  {
448  stringstream ss;
449  ss << sfe;
450  string feName = "I" + ss.str();
451 
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;
463 
464  float blank = 100. * IlledThr[sfe] * npsFEs / (1. * ncol * nrow);
465 
466  if (blank > 0.01)
467  badThr_Order.insert(std::pair<float, TString>(blank, (TString)(modName + " : " + blank)));
468 
469  if (valid)
470  {
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);
475  }
476  h1_ThrNorm[sfe].reset();
477  h1_ThrSigNorm[sfe].reset();
478  h1_ThrLong[sfe].reset();
479  h1_ThrSigLong[sfe].reset();
480  }
481  }
482  }
483  roThrDir->WriteTObject(h1dChi2.get());
484  h1dChi2.reset();
485  roThrDir->WriteTObject(h1dThr.get());
486  h1dThr.reset();
487  roThrDir->WriteTObject(h1dSig.get());
488  h1dSig.reset();
489  }
490 
491  for (int sfe = 0; sfe < npsFEs; sfe++)
492  {
493  stringstream ss;
494  ss << 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();
503  h2_Thr[sfe].reset();
504  h2_ThrSig[sfe].reset();
505  }
506  // ****************************** End - Threshold IBL ******************************
507 
509  /************************* IBL ToT ***************************/
511 
512  if (inTotFile.Length() == 0 || inTotFileAux.Length() == 0)
513  {
514  logout << " Missing ToT file from calib scan as input " << endl;
515  return 0;
516  }
517 
518  std::cout << endl
519  << "INFO =>> [IBL] tot calib analysis..." << endl;
520 
521  TFile riTotFile(inTotFile, "READ");
522  TFile riTotFileAux(inTotFileAux, "READ");
523 
524  TString totHistName = "TOT_MEAN";
525  TString totSigHistName = "TOT_SIGMA";
526 
527  TDirectoryFile *scanDir = (TDirectoryFile *)((TKey *)riTotFile.GetListOfKeys()->First())->ReadObj();
528  TList *rodKeyList = (TList *)scanDir->GetListOfKeys();
529  TIter rodItr(rodKeyList);
530  TKey *rodKey;
531 
532  std::map<float, std::pair<vector<TString>, vector<Double_t>>> ModuDataToPrint;
533 
534 #if defined(DEMOXCHECK)
535  vector<TH1F *> h1_ChrgEntry;
536  h1_ChrgEntry.reserve(nToTibl);
537 
538  vector<TH1F *> h1d_totSprdAll;
539  h1d_totSprdAll.reserve(nToTibl - 1);
540 
541  for (int t = 0; t < nToTibl; t++)
542  {
543  stringstream tt;
544  tt << t;
545 
546  string hname = "ChrgEntries_ToT_" + tt.str();
547  h1_ChrgEntry[t] = new TH1F(hname.c_str(), "RD entries ", 100, 0., 100000);
548 
549  hname = "totSprdsFll_ToT_" + tt.str();
550  if (t < nToTibl - 1)
551  h1d_totSprdAll[t] = new TH1F(hname.c_str(), "ToT spread ", 36, 0.2, 1.1);
552  }
553 #endif
554 
555  const Int_t totFE = 14 * 16 * npsFEs; // 16 modules on each of 14 ReadOutDisk
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];
559 
560  gRandom = new TRandom3(2203);
561 
562  float occuPhiEta[nchargeIBL][totFE];
563 
564  Int_t cntRod = 0;
565  std::map<float, TString> devChrg_Order;
566  std::map<float, TString> devToT_Order;
567 
568  std::multimap<float, TString, std::greater<float>> badModules_Order;
569  std::multimap<float, TString, std::greater<float>> badModules_Order_detailed;
570 
571  while ((rodKey = (TKey *)rodItr()))
572  {
573  TString rodName(rodKey->GetName());
574  string rodStr(rodKey->GetName());
575  TDirectoryFile *rodDir = (TDirectoryFile *)rodKey->ReadObj();
576 
577  TString path = rodDir->GetPath();
578  TString pathAux = path.ReplaceAll(rodPath, rodPathAux);
579 
580  TDirectoryFile *rodDirAux = (TDirectoryFile *)riTotFileAux.Get(pathAux);
581  if (rodDirAux == NULL)
582  {
583  std::cout<< " Fail to get the rodPath in Aux: "<< pathAux << endl;
584  logout << " Fail to get the rodPath in Aux " << endl;
585  continue;
586  }
587 
588  TDirectory *dirRod = roTotDir->mkdir(rodName);
589 
590  TList *modKeyList = (TList *)rodDir->GetListOfKeys();
591  TIter modItr(modKeyList);
592 
593  TKey *modKey;
594 
595  int cntMod = 0;
596  string modNames[16 * npsFEs];
597 
598  float occuChrgs[nToTibl][16 * npsFEs];
599 
600 #if defined(DEMOXCHECK)
601  TString feName_maxDevChrg = "", feName_maxDevToT = "";
602  float maxDevChrg = -9., maxDevToT = -9., avgDevChrg = 0., avgDevToT = 0.;
603 
604  vector<TH1F *> h1d_totSprd;
605  h1d_totSprd.reserve(nToTibl - 1);
606 
607  for (int t = 0; t < nToTibl - 1; t++)
608  {
609  stringstream tt;
610  tt << t + 1;
611 
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());
616  }
617 #endif
618 
619  while ((modKey = (TKey *)modItr()))
620  {
621  TString modName(modKey->GetName());
622  string modStr(modKey->GetName());
623 
624  TDirectory *dirMod = dirRod->mkdir(modName);
625  bool ibl3Dfe0 = false, ibl3Dfe1 = false;
626 
627  int hashID = -1, hashIDL = -1, hashIDR = -1;
628  int bec = -1;
629  int layer = -1;
630  int phi_module = -1;
631  int eta_module = -1;
632  int eta_moduleL = -1, eta_moduleR = -1;
633  pixmap.mapping(modStr, &hashID, &bec, &layer, &phi_module, &eta_module);
634  if (hashID == -1)
635  {
636  pixmap.mapping(modStr + "_1", &hashID, &bec, &layer, &phi_module, &eta_module);
637  if (hashID != -1)
638  {
639  ibl3Dfe0 = true;
640  hashIDL = hashID;
641  eta_moduleL = eta_module;
642  }
643 
644  pixmap.mapping(modStr + "_2", &hashID, &bec, &layer, &phi_module, &eta_module);
645  if (hashID != -1)
646  {
647  ibl3Dfe1 = true;
648  hashIDR = hashID;
649  eta_moduleR = eta_module;
650  }
651  }
652  if (hashID == -1){
653  std::cout<< "negative hash ID\n";
654  continue;
655  }
656 
657 
658  if (pcdMap.find(modStr) == pcdMap.end()){
659  std::cout<< "MOD not found "<< modStr << "\n";
660  continue;
661  }
662 
663 
664  // a stack of Charge-ToT data for ToT-charge converting
665  array<std::unique_ptr<TH2D>, npsFEs> h2d_XchrgYtot{};
666  array<std::unique_ptr<TH2D>, npsFEs> h2d_XchrgYToTSig{};
667 
668  for (int sfe = 0; sfe < npsFEs; sfe++)
669  {
670  stringstream ss;
671  ss << sfe;
672 
673  modNames[cntMod * npsFEs + sfe] = modStr + "-" + ss.str();
674 
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);
677 
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.);
680  }
681 
682  // Fill ToT-Chrg for pixels per module
683  for (int c = 0; c < nchargeIBL; c++)
684  {
685  TString totHistDirPath = modName + "/" + totHistName + "/A0/B0/C";
686  totHistDirPath += std::to_string(c);
687 
688  std::unique_ptr<TH2F> h2dTot;
689  TDirectoryFile* totHistDir(static_cast<TDirectoryFile*> (rodDir->Get(totHistDirPath)));
690  if(!totHistDir){
691  std::cout<<" Missing totHistDir in : " << totHistDirPath << endl;
692  }
693  else {
694  h2dTot.reset(static_cast<TH2F*> ((static_cast<TKey*>(totHistDir->GetListOfKeys()->First()))->ReadObj()));
695  h2dTot->SetDirectory(0);
696  }
697 
698  unique_ptr<TH2F> h2dTotAux;
699  TDirectoryFile* totHistDirAux(static_cast<TDirectoryFile*>(rodDirAux->Get(totHistDirPath)));
700  if (!totHistDirAux)
701  {
702  std::cout<<" Missing totHistDir in : " << totHistDirPath << endl;
703  logout << " Missing totHistDir in : " << totHistDirPath << endl;
704  }
705  else {
706  h2dTotAux.reset(static_cast<TH2F*> ((static_cast<TKey*>(totHistDirAux->GetListOfKeys()->First())->ReadObj())));
707  h2dTotAux->SetDirectory(0);
708  }
709 
710  TString totSigHistDirPath = modName + "/" + totSigHistName + "/A0/B0/C";
711  totSigHistDirPath += std::to_string(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);
715 
716  // Now one fill the calib-data from all pixles as basics.
717  for (int ieta = 0; ieta < ncol; ieta++)
718  {
719  for (int iphi = 0; iphi < nrow; iphi++)
720  {
721  int circ = -1;
722  if (moreFE)
723  {
724  // virtual FE with 80*84 pixels, so that sFE0, sFE1, sFE7, sFE6 will make up the physical 1'st FE
725  // while sFE2, sFE3, sFE5, sFE4 make up the physical 2'nd.
726  circ = (int)(iphi / 84.); // sFE0, sFE1, sFE2, sFE3
727  if (ieta > 80)
728  {
729  circ = 7 - circ;
730  } // sFE7, sFE6, sFE5, sFE4
731  }
732  else
733  {
734  if (ieta < ncol / 2)
735  circ = 0;
736  else
737  circ = 1;
738  }
739 
740  float tot = h2dTot->GetBinContent(ieta + 1, iphi + 1) + HDCshift;
741  float totAux = h2dTotAux->GetBinContent(ieta + 1, iphi + 1);
742 
743  // use ToT from higher HDC as default
744  float filltot = tot;
745 
746  // use ToT from lower HDC for SMALL charges, dirty in studying
747  // May 4, 2022, please keep below strategy, it give reasonable merging till now
748 
749  if (tot <= 5 || c <= 5)
750  {
751  if ((c == 0 && tot - totAux > 0.8) || (c >= 1 && c <= 3 && tot - totAux > 0.5) || (c > 4 && tot - totAux > 0.3))
752  filltot = totAux;
753  else
754  filltot = 0.5 * (totAux + tot);
755  if (c == 0 && totAux > 2.)
756  filltot = 1.;
757  }
758 
759  if (c > 19)
760  filltot = 0.5 * (totAux + tot + 2.);
761 
762  if (filltot > 0.){
763  h2d_XchrgYtot[circ]->Fill(chrgAbaciIBL[c], filltot, 1.);
764  }
765 
766 
767  float err = h2dTotSig->GetBinContent(ieta + 1, iphi + 1);
768  h2d_XchrgYToTSig[circ]->Fill(chrgAbaciIBL[c], err, 1.);
769  if (err == 0.)
770  err = 0.05;
771 
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;
775 #endif
776  }
777  } // all pixels done over a module
778 
779  h2dTotSig.reset();
780  h2dTotAux.reset();
781  h2dTot.reset();
782 
783  } // end looping over charges
784  float modHash = -1;
785  if (!(ibl3Dfe0 || ibl3Dfe1))
786  {
787  modHash = hashID;
788  }
789 
790  array<TDirectory *, npsFEs> dirFE;
791 
792  Int_t idxMod = cntRod * 16 * npsFEs + cntMod * npsFEs;
793 
794  for (int sfe = 0; sfe < npsFEs; sfe++)
795  {
796  stringstream ss;
797  ss << sfe;
798 
799  if (ibl3Dfe0 && sfe < npsFEs / 2)
800  {
801  modHash = hashIDL;
802  }
803  else if (ibl3Dfe1 && sfe >= npsFEs / 2)
804  {
805  modHash = hashIDR;
806  }
807  else
808  modHash += (sfe < npsFEs / 2 ? 0 : 1) * 0.8;
809 
810  string prfmodname = "DirFE_" + ss.str();
811  dirFE[sfe] = dirMod->mkdir(prfmodname.c_str());
812 
813  // standard deviation will be adopted for ERROR
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();
818  // shanly : seeming free from ROOT-7770 issue. 2021 Sep 17
819  std::unique_ptr<TProfile> prfl_ChrgsFE(h2d_XchrgYtot[sfe]->ProfileY(prfmodname.c_str(), 1, -1, "s"));
820  prfl_ChrgsFE->SetTitle(prfmodname.c_str());
821 
822  Double_t TotArr[nchargeIBL], TotErrArr[nchargeIBL];
823  Double_t ChrgArr[nToTibl], ChrgErrArr[nToTibl];
824 
825  Int_t idxFE = idxMod + sfe;
826  // ToT distribution along nchargeIBL bins charges
827  int dumbFE = 0;
828  for (int c = 0; c < nchargeIBL; c++)
829  {
830  TotArr[c] = TotArray[idxFE][c] = prfl_TotsFE->GetBinContent(c + 1);
831  TotErrArr[c] = TotErrArray[idxFE][c] = prfl_TotsFE->GetBinError(c + 1);
832 
833  occuPhiEta[c][idxFE] = prfl_TotsFE->GetBinEntries(c + 1) * npsFEs / (1. * ncol * nrow);
834 
835  if ((1. - occuPhiEta[c][idxFE]) > badRDfracCut)
836  dumbFE++;
837 
838  stringstream sc;
839  sc << c;
840  prfmodname = modStr + "_ToTsig_FE" + ss.str() + "Chrg" + sc.str();
841 
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());
845 
846  h_ToTsig.reset();
847  }
848  prfl_TotsFE.reset();
849 
850  if (dumbFE > 5)
851  {
852  for (int c = 0; c < nchargeIBL; c++)
853  {
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]);
856 
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]);
859 
860  }
861  }
862  // Charges distribution along 16 bins ToT
863  Double_t errToT_overChrg[nToTibl];
864  for (int t = 0; t < nToTibl; t++)
865  {
866  ChrgArr[t] = ChrgArray[idxFE][t] = prfl_ChrgsFE->GetBinContent(t + 1);
867  ChrgErrArr[t] = ChrgErrArray[idxFE][t] = prfl_ChrgsFE->GetBinError(t + 1);
868 
869  occuChrgs[t][cntMod * npsFEs + sfe] = prfl_ChrgsFE->GetBinEntries(t + 1) / RDentries[t];
870 
871  stringstream st;
872  st << 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));
875  st.str("");
876  st << totAbaci[t];
877  prfmodname = modStr + " Charge_FE" + ss.str() + " @ ToT : " + st.str();
878  h_chrg->SetTitle(prfmodname.c_str());
879 
880  Double_t scl = h_chrg->Integral();
881  errToT_overChrg[t] = 0.;
882  if (scl > 0.)
883  for (int b = 0; b < nchargeIBL; b++)
884  {
885  errToT_overChrg[t] += TotErrArr[b] * (h_chrg->GetBinContent(b + 1)) / scl;
886  }
887  if (errToT_overChrg[t] == 0.)
888  errToT_overChrg[t] = 1.1;
889 
890  h_chrg.reset();
891  }
892  prfl_ChrgsFE.reset();
893 #if defined(DEMOXCHECK)
894  for (int b = 1; b < nToTibl; b++)
895  {
896  double err = errToT_overChrg[b];
897  h1d_totSprd[b - 1]->Fill(err);
898  h1d_totSprdAll[b - 1]->Fill(err);
899  }
900 #endif
901 
902  // try a correction upon dumb FE
903  if (dumbFE > 5)
904  {
905  for (int t = 0; t < nToTibl; t++)
906  {
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]);
909  }
910  }
911  bool xoticMod = std::find(reversedModules.begin(), reversedModules.end(), int(modHash)) != reversedModules.end();
912 
913  // when charges' order are distorted along ToTs
914  bool reverseH = false, reverseT = false;
915  for (int t = 4; t >= 1; t--)
916  if (ChrgArr[t] > ChrgArr[t + 1])
917  {
918  reverseH = true;
919  break;
920  }
921  for (int t = 4; t >= 1; t--)
922  {
923  int tl = nToTibl - t;
924  if (ChrgArr[tl] < ChrgArr[tl - 1])
925  {
926  reverseT = true;
927  break;
928  }
929  }
930 
931  if (reverseH)
932  {
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;
936 #endif
937  // try a correction with some averaged factors
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];
941  }
942  else // prepare the average factors along ToTs
943  {
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]));
947  }
948 
949  if (reverseT)
950  {
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;
954 #endif
955  // try a correction with some averaged factors
956  for (int t = 4; t >= 1; t--)
957  {
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];
961  }
962  }
963  else // prepare the average factors along ToTs
964  {
965  for (int t = 4; t >= 1; t--)
966  {
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]));
970  }
971  }
972 
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());
977 
978  std::unique_ptr<TGraph> grTotSprd = std::make_unique<TGraph>(nToTibl, totAbaci, errToT_overChrg);
979  gername = "ToTsprd";
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);
987 
988  TF1 ToTres("ToTres", funcDispConvoluted, 0.8, 16.5, 3);
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);
993 
994  grTotSprd->Fit(&ToTres, "MRQ");
995  Double_t parP0 = ToTres.GetParameter(0);
996  Double_t parP1 = ToTres.GetParameter(1);
997 
998  dirFE[sfe]->WriteTObject(grTotSprd.get());
999  grTotSprd.reset();
1000  // Lets' keep the bad 2-para fit untill the dataBase will be updated someday
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);
1028 
1029  grTot->Fit(f1ToTfromCharge, "MRQ");
1030 
1031  std::unique_ptr<TGraphErrors> grChrg = std::make_unique<TGraphErrors>(nToTibl, totAbaci, ChrgArr, totErrArr, ChrgErrArr);
1032 
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);
1038 
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;
1044  }
1045 
1046  TF1 *f1ChargefromToTRight = new TF1("ChargefromToTR", funcRation5, 5.5, 16., 5);
1047  f1ChargefromToTRight->SetLineColor(4);
1048  grChrg->Fit(f1ChargefromToTRight, "MRQ+");
1049 
1050  dirFE[sfe]->WriteTObject(grTot.get());
1051  dirFE[sfe]->WriteTObject(grTotSig.get());
1052  dirFE[sfe]->WriteTObject(h2d_XchrgYtot[sfe].get());
1053 
1054  h2d_XchrgYtot[sfe].reset();
1055  h2d_XchrgYToTSig[sfe].reset();
1056  grTot.reset();
1057  grTotSig.reset();
1058  grChrg.reset();
1059 
1060  // prepare a map sor sorting
1061  string Idx = "I" + ss.str();
1062  vector<TString> modName2prt;
1063  modName2prt.push_back(modName);
1064  modName2prt.push_back((TString)(Idx));
1065  // unfortunately some tuning is necessary to satisfy dataBase reauirements
1066  // 5 for module ID, 4 for threshold, nToTibl - 1 for charges at ToT, 3 for ResToT
1067  std::vector<Double_t> prtAux;
1068  prtAux.reserve(5 + 4 + nToTibl - 1 + 3); // skip ToT = 0
1069  // @ 0 ... 4
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);
1075 
1076  modName2prt[0] = (modStr + "_" + ss.str()).c_str();
1077  if (ibl3Dfe0 && sfe < npsFEs / 2)
1078  {
1079  if (!moreFE)
1080  modName2prt[0] = modName + "_0";
1081  prtAux[0] = hashIDL;
1082  prtAux[4] = eta_moduleL;
1083  }
1084  if (ibl3Dfe1 && sfe >= npsFEs / 2)
1085  {
1086  if (!moreFE)
1087  modName2prt[0] = modName + "_1";
1088  prtAux[0] = hashIDR;
1089  prtAux[4] = eta_moduleR;
1090  }
1091 
1092  // @ 5 ... 8
1093  float ThrNorm = pcdMap[modStr][Idx]["ThrNorm"];
1094  if (ThrNorm == 0. || ThrNorm == -42.)
1095  {
1096  // retrieve something from average when it's missing in calibration
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]);
1101  }
1102  else
1103  {
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"]);
1108  }
1109  // since this version, the goodness will be skipped
1110  // @ 10 ... nToTibl + 8, with ToT = 0 skipped
1111  for (int t = 1; t < nToTibl; t++)
1112  prtAux.push_back(ChrgArr[t]);
1113 
1114  // @ nToTibl + 9, nToTibl + 10
1115  prtAux.push_back(parP0);
1116  prtAux.push_back(parP1);
1117 
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));
1120  } // end 1'st loop over FrontEnds
1121 
1122  cntMod++;
1123  } // end of loop over Mods
1124 
1125 #if defined(DEMOXCHECK)
1126 
1127  TDirectory *dirToTSprd = dirRod->mkdir("ToT_Spreads");
1128  for (int b = 0; b < nToTibl - 1; b++)
1129  {
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");
1134 
1135  dirToTSprd->WriteTObject(h1d_totSprd[b]);
1136  delete h1d_totSprd[b];
1137  }
1138  h1d_totSprd.clear();
1139 
1140  TString hn = "";
1141 
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);
1145 
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);
1149 
1150  bool fillChrg = false, fillToT = false;
1151 
1152  for (int sfe = 0; sfe < 16 * npsFEs; sfe++)
1153  {
1154  float PhiEta = 0.;
1155  for (int c = 0; c < nchargeIBL; c++)
1156  {
1157  float occu = occuPhiEta[c][cntRod * 16 * npsFEs + sfe];
1158  float nt = 10. - floor(10. * occu + 0.5);
1159  PhiEta += 0.1 * nt;
1160  TString modchrg = (TString)(modNames[sfe] + "_Chrg_" + c);
1161  if (nt > 0.01)
1162  badModules_Order_detailed.insert(std::pair<float, TString>(1. - occu, modchrg));
1163  if (nt > 5.)
1164  continue;
1165  if (nt < 0.1)
1166  nt = 0.01;
1167 
1168  h2_badChrgs->SetBinContent(c + 1, sfe + 1, nt);
1169  fillChrg = true;
1170  }
1171  PhiEta /= nchargeIBL;
1172  if (PhiEta > 0.01)
1173  badModules_Order.insert(std::pair<float, TString>(PhiEta,
1174  (TString)(modNames[sfe])));
1175 
1176  for (int t = 1; t < nToTibl; t++)
1177  {
1178  float nt = floor(10. * occuChrgs[t][sfe] + 0.5);
1179  if (nt > 5.)
1180  continue;
1181  h2_badToT->SetBinContent(t + 1, sfe + 1, nt);
1182  fillToT = true;
1183  }
1184 
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");
1192  }
1193 
1194  h2_badChrgs->SetOption("TEXT");
1195  h2_badToT->SetOption("TEXT");
1196 
1197  if (fillChrg)
1198  {
1199  dirRod->WriteTObject(h2_badChrgs, "", "Overwrite");
1200  }
1201 
1202  if (fillToT)
1203  {
1204  dirRod->WriteTObject(h2_badToT, "", "WriteDelete");
1205  }
1206 
1207  delete h2_badChrgs;
1208  delete h2_badToT;
1209 
1210 #endif
1211 
1212  cntRod++;
1213  } // end of loop over Rods
1214 
1215 #if defined(DEMOXCHECK)
1216 
1217  for (int t = 0; t < 4; t++)
1218  {
1219  if (t == 0)
1220  logout << " correction factors for reversed charges : ";
1221  logout << reverseCF_H[t] << ", ";
1222  if (t == 3)
1223  logout << endl;
1224  }
1225  for (int t = 0; t < 4; t++)
1226  {
1227  if (t == 0)
1228  logout << " correction factors for reversed charges : ";
1229  logout << reverseCF_T[t] << ", ";
1230  if (t == 3)
1231  logout << endl;
1232  }
1233 
1234  for (int t = 0; t < nToTibl; t++)
1235  {
1236  if (t == 0)
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];
1243  }
1244  h1_ChrgEntry.clear();
1245 
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;
1249 
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;
1253 
1254  logout << "ToTRes (spread) & its RMS @ ToT from 1 to 16 : " << endl;
1255  for (int t = 0; t < nToTibl - 1; t++)
1256  {
1257  if (t == 0)
1258  logout << "[ ";
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];
1265  }
1266  h1d_totSprdAll.clear();
1267 #endif
1268 
1269  logout << " goto print " << std::endl;
1270 
1271  // Comment out for information only
1272  // txtDB << "####################################################################################################" << endl;
1273  // txtDB << "=========== physics meaning of each column ====================" << endl;
1274  // txtDB << "hashId " << "Threshold " << "ThresholdRMS " << "ThresholdLong " << "ThresholdRMSLong " << "Chrg_ToT1 "
1275  // << "Chrg_ToT2 " << "Chrg_ToT3 " << "Chrg_ToT4 " << "Chrg_ToT5 " << "Chrg_ToT6 " << "Chrg_ToT7 " << "Chrg_ToT8 " << "Chrg_ToT9 "
1276  // << "Chrg_ToT10 " << "Chrg_ToT11 " << "Chrg_ToT12 " << "Chrg_ToT13 " << "Chrg_ToT14 " << "Chrg_ToT15 " << "Chrg_ToT16 "
1277  // << "ToT_sprd " << " ToT_sprd_var" << endl;
1278 
1279  // txtDB << "######################## TXT for IBL calibration ____Start : _> ###########################" << endl;
1280 
1281  // now print the dataBase payloads in a TXT format
1282  for (std::map<float, std::pair<vector<TString>, vector<Double_t>>>::const_iterator itr = ModuDataToPrint.begin();
1283  itr != ModuDataToPrint.end(); ++itr)
1284  {
1285  int hash = floor(itr->first);
1286  std::pair<vector<TString>, vector<Double_t>> payload = itr->second;
1287  vector<Double_t> fe = payload.second;
1288 
1289  txtDB << hash << " ";
1290 
1291  for (unsigned int t = 5; t < fe.size(); t++)
1292  {
1293  if (t < fe.size() - 2)
1294  {
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;
1299 #endif
1300  }
1301  else
1302  {
1303  float p01 = abs(fe[t]);
1304  if (t < fe.size() - 1)
1305  txtDB << 0.001 * (int)(p01 * 1000.) << " ";
1306  else
1307  txtDB << 0.000000001 * (int)(p01 * 1000000000.) << " ";
1308  }
1309  }
1310  txtDB << endl;
1311  }
1312  // txtDB << "####################################################################################################" << endl;
1313  // txtDB << "######################## TXT for IBL calibration <___ : End _____ ###########################" << endl;
1314  // txtDB << "####################################################################################################" << endl;
1315 
1316  std::cout << " Please find the file : " << dbFileName << " for dataBase payload " << endl;
1317 
1318  // statistics for BAD frontends, only for ELOG reports
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;
1322 
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;
1326 
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;
1331 
1332  roFile.Close();
1333  txtDB.close();
1334  logout.close();
1335 
1336  return 0;
1337 }

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 1345 of file CalibrateIBL.cxx.

1345  {
1346 
1347  bool saveInfo = false;
1348  std::string THR = "THR";
1349  std::string TOT_HISDIS = "TOT_HISDIS";
1350  std::string TOT_LOWQ = "TOT_LOWQ";
1351  std::string dpath = "directory_path";
1352 
1353  for(int i=1; i<argc; i++){
1354  std::string aux(argv[i]);
1355  if (THR.compare(aux.substr(0,aux.find("="))) == 0) THR = aux.substr(aux.find("=")+1);
1356  else if(TOT_HISDIS.compare(aux.substr(0,aux.find("="))) == 0) TOT_HISDIS = aux.substr(aux.find("=")+1);
1357  else if(TOT_LOWQ.compare(aux.substr(0,aux.find("="))) == 0) TOT_LOWQ = aux.substr(aux.find("=")+1);
1358  else if(dpath.compare(aux.substr(0,aux.find("="))) == 0) dpath = aux.substr(aux.find("=")+1);
1359  else if(aux.compare("saveInfo") == 0) saveInfo = true;
1360  else{
1361  printError();
1362  return 1;
1363  }
1364  }
1365 
1366  printf("%-14s = %s\n","Directory path",dpath.c_str());
1367  printf("%-14s = %s.root\n","THR",THR.c_str());
1368  printf("%-14s = %s.root\n","TOT_HISDIS",TOT_HISDIS.c_str());
1369  printf("%-14s = %s.root\n","TOT_LOWQ",TOT_LOWQ.c_str());
1370  printf("%-14s = %s\n\n\n" ,"Save root file",saveInfo ? "True" : "False" );
1371 
1372  bool correctArgc = (THR.compare("THR") == 0) or (TOT_HISDIS.compare("TOT_HISDIS") == 0) or (TOT_LOWQ.compare("TOT_LOWQ") == 0) or (dpath.compare("directory_path") == 0);
1373 
1374  if(correctArgc){
1375  printf("Cannot continue, one arguments is incorrect or not filled correctly...\n");
1376  printf("Helper below:\n**********************\n\n");
1377  printError();
1378  return 1;
1379  }
1380 
1381  iblCalib(dpath, THR, TOT_HISDIS, TOT_LOWQ);
1382  return 0;
1383 
1384 }

◆ printError()

void printError ( )

Definition at line 1339 of file CalibrateIBL.cxx.

1339  {
1340  printf("ERROR - Argument not expected or wrongly set:\n\n");
1341  printf("Valid format is: ./IBLCalibration THR=SCAN_Sxxxxxxxxx TOT_HISDIS=SCAN_Sxxxxxxxxx TOT_LOWQ=SCAN_Sxxxxxxxxx directory_path=path/to/file/\n");
1342  printf("\n\t i.e: ./IBLCalibration THR=SCAN_S000087719 TOT_HISDIS=SCAN_S000087717 TOT_LOWQ=SCAN_S000087710 directory_path=/eos/user/x/xxxx/\n");
1343 }

◆ ToTfromChrg()

double ToTfromChrg ( float  chrg,
double  par[5] 
)

Definition at line 80 of file CalibrateIBL.cxx.

81 {
82  double tot = 0.;
83  double num = par[0] + chrg * (par[1] + chrg * (par[2] + chrg * par[3]));
84  double denom = 1. + chrg * par[4];
85  if (denom != 0.0)
86  tot = num / denom;
87  return tot;
88 }

Variable Documentation

◆ ATLAS_NO_CHECK_FILE_THREAD_SAFETY

ATLAS_NO_CHECK_FILE_THREAD_SAFETY

Definition at line 24 of file CalibrateIBL.cxx.

query_example.row
row
Definition: query_example.py:24
printError
void printError()
Definition: CalibrateIBL.cxx:1339
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
Merge_LAr_blobs.filled
list filled
Definition: Merge_LAr_blobs.py:43
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
dqt_zlumi_pandas.hname
string hname
Definition: dqt_zlumi_pandas.py:279
CaloCondBlobAlgs_fillNoiseFromASCII.spec
spec
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:47
SH::scanDir
void scanDir(SampleHandler &sh, DiskList &list, const std::string &pattern, const std::string &samplePattern, const std::string &samplePostfix)
effects: scan the given directory and add all subdirectories as samples that contain root files.
Definition: ToolsDiscovery.cxx:45
GetMean
TGraphErrors * GetMean(TH2F *histo)
Definition: TRTCalib_makeplots.cxx:3907
upper
int upper(int c)
Definition: LArBadChannelParser.cxx:49
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
python.TrigEgammaMonitorHelper.TH2F
def TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:45
x
#define x
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
RunTileCalibRec.run3
run3
Definition: RunTileCalibRec.py:208
calibdata.valid
list valid
Definition: calibdata.py:45
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:182
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:523
python.BuildSignatureFlags.sig
sig
Definition: BuildSignatureFlags.py:218
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
compute_lumi.denom
denom
Definition: compute_lumi.py:76
pix::PixelMapping
Definition: PixelMapping.h:18
trigbs_pickEvents.num
num
Definition: trigbs_pickEvents.py:76
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
funcRation5
double funcRation5(double *x, double *par)
Definition: CalibrateIBL.cxx:90
query_example.col
col
Definition: query_example.py:7
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
scan
void scan(TDirectory *td=0, int depth=0)
Definition: listroot.cxx:440
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
BchCleanup.modName
modName
Definition: BchCleanup.py:201
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
DiTauMassTools::MMCFitMethod::shortName
const std::string shortName[MAX]
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:48
dqt_zlumi_alleff_HIST.tl
tl
Definition: dqt_zlumi_alleff_HIST.py:73
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
beamspotnt.nt
def nt
Definition: bin/beamspotnt.py:1063
skip
bool skip
Definition: TrigGlobEffCorrValidation.cxx:190
TileDCSDataPlotter.tt
tt
Definition: TileDCSDataPlotter.py:874
python.compressB64.c
def c
Definition: compressB64.py:93
funcDispConvoluted
double funcDispConvoluted(double *x, double *par)
Definition: CalibrateIBL.cxx:100
iblCalib
int iblCalib(const std::string &InDir, const std::string &THRscan, const std::string &scan, const std::string &scanLowCharge)
Definition: CalibrateIBL.cxx:107