18 if (inTotFile.empty())
return false;
20 TFile totFile(inTotFile.c_str(),
"READ");
21 if (not totFile.IsOpen()) {
22 printf(
"Error - File %s could not be opened.\n",inTotFile.c_str());
26 printf(
"File %s opened.\n",inTotFile.c_str());
27 printf(
"Running TOT calibration...\n");
31 std::vector< std::vector< std::unique_ptr<TH1F> > > histogramsTOT;
32 std::vector< std::vector< std::unique_ptr<TH1F> > > histogramsTOTsig;
33 for(
unsigned int FE = 0; FE <
m_nFE; FE++){
35 histogramsTOT.push_back( std::vector< std::unique_ptr<TH1F> >() );
36 histogramsTOTsig.push_back( std::vector< std::unique_ptr<TH1F> >() );
40 std::string title =
"FE"+std::to_string(FE)+
"_pixType"+std::to_string(
pixel);
41 std::unique_ptr<TH1F> htot = std::make_unique<TH1F>((title+
"_tot").c_str(), (title+
"_tot").c_str(),
m_totnbins,
m_totLo,
m_totHi);
42 htot->SetDirectory(0);
44 htotsig->SetDirectory(0);
46 histogramsTOT.at(FE).push_back(std::move(htot));
48 histogramsTOTsig.at(FE).push_back(std::move(htotsig));
56 while ((rodKey=
static_cast<TKey*
>(rodItr()))) {
57 TDirectoryFile* rodDir =
static_cast<TDirectoryFile*
>(rodKey->ReadObj());
59 const std::string rodName(rodKey->GetName());
60 printf(
"%s\n",rodName.c_str());
62 while ((modKey=
static_cast<TKey*
>(modItr()))) {
63 const std::string modName(modKey->GetName());
66 if (not pm.
contains(modName))
continue;
72 printf(
" -> %s\n",modName.c_str());
75 std::array<std::array<float, m_ncharge>,
m_nFE> totArrI{};
76 std::array<std::array<float, m_ncharge>,
m_nFE> totErrArrI{};
77 std::array<std::array<float, m_ncharge>,
m_nFE> totSigArrI{};
78 std::array<std::array<float, m_ncharge>,
m_nFE> totSigErrArrI{};
79 std::array<std::array<float, m_ncharge>,
m_nFE> totLongArrI{};
80 std::array<std::array<float, m_ncharge>,
m_nFE> totErrLongArrI{};
83 static const std::string totMeanStr{
"TOT_MEAN"};
84 static const std::string totSigmaStr{
"TOT_SIGMA"};
90 if(!h2dTOTmean or !h2dTOTsig) {
93 h2dTOTmean->SetDirectory(0);
94 h2dTOTsig->SetDirectory(0);
96 for (
unsigned int ieta = 0; ieta <
m_etaBins; ieta++) {
97 for (
unsigned int iphi = 0; iphi <
m_phiBins; iphi++) {
98 float totmean = h2dTOTmean->GetBinContent(ieta + 1, iphi + 1);
99 float totsig = h2dTOTsig ->GetBinContent(ieta + 1, iphi + 1);
105 int FE =
chipId(iphi, ieta);
112 histogramsTOT.at(FE).at(
pixel)->Fill(totmean);
113 histogramsTOTsig.at(FE).at(
pixel)->Fill(totsig);
123 for(
unsigned int FE = 0; FE <
m_nFE; FE++){
127 totArrI.at(FE).at(c) = histogramsTOT.at(FE).at(
pixel)->GetMean();
128 totErrArrI.at(FE).at(c) = histogramsTOT.at(FE).at(
pixel)->GetMeanError();
129 totSigArrI.at(FE).at(c) = std::sqrt(std::pow(histogramsTOTsig.at(FE).at(
pixel)->GetMean() ,2)+std::pow(histogramsTOT.at(FE).at(
pixel)->GetRMS() ,2));
130 totSigErrArrI.at(FE).at(c) = std::sqrt(std::pow(histogramsTOTsig.at(FE).at(
pixel)->GetMeanError(),2)+std::pow(histogramsTOT.at(FE).at(
pixel)->GetRMSError(),2));
132 if(totSigErrArrI.at(FE).at(c) > 1.0){
133 totArrI.at(FE).at(c) = 0.0;
138 totLongArrI.at(FE).at(c) = histogramsTOT.at(FE).at(
pixel)->GetMean();
139 totErrLongArrI.at(FE).at(c) = histogramsTOT.at(FE).at(
pixel)->GetMeanError();
141 if(totErrLongArrI.at(FE).at(c) > 1.0){
142 totLongArrI.at(FE).at(c) = 0.0;
148 histogramsTOT.at(FE).at(
pixel)->Reset(
"ICESM");
149 histogramsTOTsig.at(FE).at(
pixel)->Reset(
"ICESM");
155 for(
unsigned int FE = 0; FE <
m_nFE; FE++) {
157 std::string subdir(((FE < 10) ?
"FE0" :
"FE") +std::to_string(FE));
159 std::vector<float> v_Q;
160 std::vector<float> v_Qerr;
161 std::vector<float> v_TOT;
162 std::vector<float> v_TOTerr;
163 std::vector<float> v_TOTsig;
164 std::vector<float> v_TOTsigerr;
165 std::vector<float> v_TOTlong;
166 std::vector<float> v_TOTlongerr;
170 std::copy(std::begin(totArrI[FE]) , std::end(totArrI[FE]) , std::back_inserter(v_TOT) );
171 std::copy(std::begin(totErrArrI[FE]) , std::end(totErrArrI[FE]) , std::back_inserter(v_TOTerr) );
172 std::copy(std::begin(totSigArrI[FE]) , std::end(totSigArrI[FE]) , std::back_inserter(v_TOTsig) );
173 std::copy(std::begin(totSigErrArrI[FE]) , std::end(totSigErrArrI[FE]) , std::back_inserter(v_TOTsigerr) );
174 std::copy(std::begin(totLongArrI[FE]) , std::end(totLongArrI[FE]) , std::back_inserter(v_TOTlong) );
175 std::copy(std::begin(totErrLongArrI[FE]) , std::end(totErrLongArrI[FE]) , std::back_inserter(v_TOTlongerr) );
177 std::vector<float> pixNormalParams;
178 std::vector<float> pixNormalParamsQuality;
179 std::vector<float> pixSigParams;
180 std::vector<float> pixSigParamsQuality;
181 std::vector<float> pixLongParams;
182 std::vector<float> pixLongParamsQuality;
187 int vecsize = v_Q.size();
189 std::unique_ptr<TGraphErrors> graphnormal = std::make_unique<TGraphErrors>(vecsize, &v_Q.at(0), &v_TOT.at(0) , &v_Qerr.at(0), &v_TOTerr.at(0) );
190 std::unique_ptr<TGraphErrors> graphsig = std::make_unique<TGraphErrors>(vecsize, &v_Q.at(0), &v_TOTsig.at(0) , &v_Qerr.at(0), &v_TOTsigerr.at(0) );
195 graphnormal->Fit(functnormal.get() ,
"MRQ");
196 graphsig ->Fit(functnormalsig.get(),
"MRQ");
198 pixNormalParams =
getParams(functnormal.get() ,3 );
199 pixSigParams =
getParams(functnormalsig.get(),2 );
207 if( !
m_wFile->Get((rodName+
"/"+modName+
"/TOTfits/"+subdir).c_str()) ){
208 m_wFile->mkdir((rodName+
"/"+modName+
"/TOTfits/"+subdir).c_str(),rodName.c_str());
211 m_wFile->cd((rodName+
"/"+modName+
"/TOTfits/"+subdir).c_str());
213 graphTitles(graphnormal, std::string(modName+
" - "+subdir+
" - normal pixels: Fit: "+std::to_string(n_fit)).c_str(),
"TOT");
214 graphTitles(graphsig , std::string(modName+
" - "+subdir+
" - normal pixels: Fit: "+std::to_string(n_fit)).c_str(),
"Charge smearing");
216 graphnormal->Write(std::string(
"normal_fit_"+std::to_string(n_fit)).c_str(), TObject::kWriteDelete);
217 graphsig->Write(std::string(
"smearing_fit_"+std::to_string(n_fit)).c_str(), TObject::kWriteDelete);
222 functnormalsig.reset();
227 }
while(
reFit_normalPix(pixNormalParams, v_Q, v_Qerr, v_TOT, v_TOTerr, v_TOTsig, v_TOTsigerr, FE ) );
243 int vecsize = v_Q.size();
245 std::unique_ptr<TGraphErrors> graflong = std::make_unique<TGraphErrors>(vecsize, &v_Q.at(0), &v_TOTlong.at(0), &v_Qerr.at(0), &v_TOTlongerr.at(0) );
249 graflong ->Fit(functlong.get() ,
"MRQ");
251 pixLongParams =
getParams(functlong.get() ,3 );
257 if( !
m_wFile->Get((rodName+
"/"+modName+
"/TOTfits/"+subdir).c_str()) ){
258 m_wFile->mkdir((rodName+
"/"+modName+
"/TOTfits/"+subdir).c_str(),rodName.c_str());
261 m_wFile->cd((rodName+
"/"+modName+
"/TOTfits/"+subdir).c_str());
263 graphTitles(graflong, std::string(modName+
" - "+subdir+
" - long+ganged pixels: Fit: "+std::to_string(n_fit)).c_str(),
"TOT");
265 graflong->Write(std::string(
"long_ganged_fit_"+std::to_string(n_fit)).c_str(), TObject::kWriteDelete);
280 int modID = pm.
getID(modName);
281 auto itr = map_info.find( modID );
283 if (itr != map_info.end()) {
284 (itr->second).at(FE)->set_NormalParams( pixNormalParams);
285 (itr->second).at(FE)->set_LongParams ( pixLongParams );
286 (itr->second).at(FE)->set_SigParams ( pixSigParams );
288 (itr->second).at(FE)->set_times_fitted ( n_fit );
290 (itr->second).at(FE)->set_NormalParamsQuality( pixNormalParamsQuality);
291 (itr->second).at(FE)->set_LongParamsQuality ( pixLongParamsQuality );
292 (itr->second).at(FE)->set_SigParamsQuality ( pixSigParamsQuality );
295 printf(
"Error - Module not found in fitting step... Skipping.\n");
304 for(
unsigned int FE = 0; FE <
m_nFE; FE++) {
306 histogramsTOT.at(FE).at(
pixel).reset();
307 histogramsTOTsig.at(FE).at(
pixel).reset();
373 if (inTimFile.empty())
return false;
375 TFile timFile(inTimFile.c_str(),
"READ");
376 if (not timFile.IsOpen()) {
377 printf(
"Error - File %s could not be opened.\n",inTimFile.c_str());
380 printf(
"File %s opened.\n",inTimFile.c_str());
381 printf(
"Running timming calibration...\n");
385 std::vector< std::vector< std::unique_ptr<TH1F> > > histogramsTIM;
386 for(
unsigned int FE = 0; FE <
m_nFE; FE++){
388 histogramsTIM.push_back( std::vector< std::unique_ptr<TH1F> >() );
391 std::string title =
"FE"+std::to_string(FE)+
"_pixType"+std::to_string(
pixel);
392 std::unique_ptr<TH1F>
h = std::make_unique<TH1F>((title+
"_thr").c_str(), (title+
"_thr").c_str(),
m_timnbins,
m_timLo,
m_timHi);
395 histogramsTIM.at(FE).push_back(std::move(
h));
402 while ((rodKey=
static_cast<TKey*
>(rodItr()))) {
403 const std::string rodName(rodKey->GetName());
404 TDirectoryFile* rodDir =
static_cast<TDirectoryFile*
>(rodKey->ReadObj());
409 static const std::string sCurveMeanStr{
"SCURVE_MEAN"};
410 while ((modKey=
static_cast<TKey*
>(modItr()))) {
411 std::string modName(modKey->GetName());
417 printf(
"Error - Module %s not found in the PixelMapping tool\n",modName.c_str());
426 h2dTim->SetDirectory(0);
428 for (
unsigned int ieta = 0; ieta <
m_etaBins; ieta++) {
429 for (
unsigned int iphi = 0; iphi <
m_phiBins; iphi++) {
431 float tim = h2dTim->GetBinContent(ieta + 1, iphi + 1);
437 int FE =
chipId(iphi, ieta);
444 histogramsTIM.at(FE).at(
pixel)->Fill(tim);
451 int modID = pm.
getID(modName);
452 auto itr = map_info.find( modID );
453 if (itr == map_info.end()) {
454 printf(
"Calib::fillTiming: ERROR - Mod ID= %16s not found. Creating it -----> Inform Pixel Offline Software Experts... \n",modName.c_str());
456 map_info[modID] = std::vector<std::unique_ptr<CalibFrontEndInfo>> ();
458 for(
unsigned int FE = 0; FE <
m_nFE; FE++){
460 map_info[modID].push_back( std::unique_ptr<CalibFrontEndInfo>() );
461 std::unique_ptr<CalibFrontEndInfo> p = std::make_unique<CalibFrontEndInfo>(modID,FE,modName,std::string(rodKey->GetName()));
462 map_info[modID].at(FE) = std::move(p);
467 int tim_mean = histogramsTIM.at(FE).at(
pixel)->GetMean();
470 histogramsTIM.at(FE).at(
pixel)->Reset(
"ICESM");
473 map_info[modID].at(FE)->set_NormalIntime(tim_mean);
476 map_info[modID].at(FE)->set_LongIntime(tim_mean);
479 map_info[modID].at(FE)->set_GangedIntime(tim_mean);
482 printf(
"Error - Bad pixel in Calib::fillTiming\n");
490 for(
unsigned int FE = 0; FE <
m_nFE; FE++){
491 std::string subdir(((FE < 10) ?
"FE0" :
"FE") +std::to_string(FE));
495 int tim_mean = histogramsTIM.at(FE).at(
pixel)->GetMean();
500 if( !
m_wFile->Get((rodName+
"/"+modName+
"/Thresholds/"+subdir).c_str()) ){
501 m_wFile->mkdir((rodName+
"/"+modName+
"/Thresholds/"+subdir).c_str(),rodName.c_str());
504 m_wFile->cd((rodName+
"/"+modName+
"/Thresholds/"+subdir).c_str());
506 histogramsTIM.at(FE).at(
pixel)->SetTitle(
"Intime;Pixel intime;Counts");
508 std::string
type =
"";
513 histogramsTIM.at(FE).at(
pixel)->Write(std::string(
"intime_"+
type).c_str(), TObject::kWriteDelete);
517 histogramsTIM.at(FE).at(
pixel)->Reset(
"ICESM");
520 (itr->second).at(FE)->set_NormalIntime(tim_mean);
523 (itr->second).at(FE)->set_LongIntime(tim_mean);
526 (itr->second).at(FE)->set_GangedIntime(tim_mean);
529 printf(
"Error - Bad pixel in Calib::fillTiming\n");
538 for(
unsigned int FE = 0; FE <
m_nFE; FE++) {
540 histogramsTIM.at(FE).at(
pixel).reset();
546 printf(
"DONE with threshold calibration.\n");
554 if (inThrFile.empty())
return false;
556 TFile riThrFile(inThrFile.c_str(),
"READ");
557 if (not riThrFile.IsOpen()) {
558 printf(
"Error - File %s could not be opened.\n",inThrFile.c_str());
561 printf(
"File %s opened.\n",inThrFile.c_str());
562 printf(
"Running threshold calibration...\n");
566 std::vector< std::vector< std::unique_ptr<TH1F> > > histogramsTHR;
567 std::vector< std::vector< std::unique_ptr<TH1F> > > histogramsSIG;
568 for(
unsigned int FE = 0; FE <
m_nFE; FE++){
570 histogramsTHR.push_back( std::vector< std::unique_ptr<TH1F> >() );
571 histogramsSIG.push_back( std::vector< std::unique_ptr<TH1F> >() );
574 std::string title =
"FE"+std::to_string(FE)+
"_pixType"+std::to_string(
pixel);
575 std::unique_ptr<TH1F> hthr = std::make_unique<TH1F>((title+
"_thr").c_str(), (title+
"_thr").c_str(),
m_thrnbins,
m_thrLo,
m_thrHi);
576 hthr->SetDirectory(0);
577 std::unique_ptr<TH1F> hsig = std::make_unique<TH1F>((title+
"_sig").c_str(), (title+
"_sig").c_str(),
m_thrnbins,
m_sigLo,
m_sigHi);
578 hsig->SetDirectory(0);
580 histogramsTHR.at(FE).push_back(std::move(hthr));
582 histogramsSIG.at(FE).push_back(std::move(hsig));
589 static const std::string sCurveMeanStr{
"SCURVE_MEAN"};
590 static const std::string sCurveSigmaStr{
"SCURVE_SIGMA"};
591 while ((rodKey=
static_cast<TKey*
>(rodItr()))) {
592 const std::string rodName(rodKey->GetName());
593 TDirectoryFile* rodDir = (TDirectoryFile*)rodKey->ReadObj();
598 while ((modKey=
static_cast<TKey*
>(modItr()))) {
599 std::string modName(modKey->GetName());
605 printf(
"Error - Module %s not found in the PixelMapping tool\n",modName.c_str());
615 h2dThr->SetDirectory(0);
619 h2dSig->SetDirectory(0);
621 for (
unsigned int ieta = 0; ieta <
m_etaBins; ieta++) {
622 for (
unsigned int iphi = 0; iphi <
m_phiBins; iphi++) {
624 float thr = h2dThr->GetBinContent(ieta + 1, iphi + 1);
625 float sig = h2dSig->GetBinContent(ieta + 1, iphi + 1);
627 if (thr == 0 || thr > 10000 || sig == 0 || sig > 1000) {
631 int FE =
chipId(iphi, ieta);
638 histogramsTHR.at(FE).at(
pixel)->Fill(thr);
639 histogramsSIG.at(FE).at(
pixel)->Fill(sig);
648 int modID = pm.
getID(modName);
649 auto itr = map_info.find( modID );
652 if (itr == map_info.end()) {
654 map_info[modID] = std::vector<std::unique_ptr<CalibFrontEndInfo>> ();
656 for(
unsigned int FE = 0; FE <
m_nFE; FE++){
657 std::string subdir(((FE < 10) ?
"FE0" :
"FE") +std::to_string(FE));
658 map_info[modID].push_back( std::unique_ptr<CalibFrontEndInfo>() );
659 std::unique_ptr<CalibFrontEndInfo> p = std::make_unique<CalibFrontEndInfo>(modID,FE,modName,std::string(rodKey->GetName()));
660 map_info[modID].at(FE) = std::move(p);
665 int thr_mean = histogramsTHR.at(FE).at(
pixel)->GetMean();
666 int thr_rms = histogramsTHR.at(FE).at(
pixel)->GetRMS();
667 int sig_mean = histogramsSIG.at(FE).at(
pixel)->GetMean();
672 if( !
m_wFile->Get((rodName+
"/"+modName+
"/Thresholds/"+subdir).c_str()) ){
673 m_wFile->mkdir((rodName+
"/"+modName+
"/Thresholds/"+subdir).c_str(),rodName.c_str());
676 m_wFile->cd((rodName+
"/"+modName+
"/Thresholds/"+subdir).c_str());
678 histogramsTHR.at(FE).at(
pixel)->SetTitle(
"Threshold;Pixel threshold;Counts");
679 histogramsSIG.at(FE).at(
pixel)->SetTitle(
"Sigma;Pixel sigma;Counts");
681 std::string
type =
"";
686 histogramsTHR.at(FE).at(
pixel)->Write(std::string(
"thres_"+
type).c_str(), TObject::kWriteDelete);
687 histogramsSIG.at(FE).at(
pixel)->Write(std::string(
"sigma_"+
type).c_str(), TObject::kWriteDelete);
691 histogramsTHR.at(FE).at(
pixel)->Reset(
"ICESM");
692 histogramsSIG.at(FE).at(
pixel)->Reset(
"ICESM");
695 map_info[modID].at(FE)->set_NormalThreshold(thr_mean);
696 map_info[modID].at(FE)->set_NormalRms(thr_rms);
697 map_info[modID].at(FE)->set_NormalNoise(sig_mean);
700 map_info[modID].at(FE)->set_LongThreshold(thr_mean);
701 map_info[modID].at(FE)->set_LongRms(thr_rms);
702 map_info[modID].at(FE)->set_LongNoise(sig_mean);
705 map_info[modID].at(FE)->set_GangedThreshold(thr_mean);
706 map_info[modID].at(FE)->set_GangedRms(thr_rms);
707 map_info[modID].at(FE)->set_GangedNoise(sig_mean);
710 printf(
"Calib::fillThresholds: ERROR - Bad pixel in Calib::fillThresholds\n");
718 printf(
"Calib::fillThresholds: ERROR - REPEATED MOD ID: %s! Contact Offline team\n",modName.c_str());
724 for(
unsigned int FE = 0; FE <
m_nFE; FE++) {
726 histogramsTHR.at(FE).at(
pixel).reset();
727 histogramsSIG.at(FE).at(
pixel).reset();
733 printf(
"DONE with threshold calibration.\n");