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{};
88 if(!h2dTOTmean or !h2dTOTsig) {
91 h2dTOTmean->SetDirectory(0);
92 h2dTOTsig->SetDirectory(0);
94 for (
unsigned int ieta = 0; ieta <
m_etaBins; ieta++) {
95 for (
unsigned int iphi = 0; iphi <
m_phiBins; iphi++) {
96 float totmean = h2dTOTmean->GetBinContent(ieta + 1, iphi + 1);
97 float totsig = h2dTOTsig ->GetBinContent(ieta + 1, iphi + 1);
103 int FE =
chipId(iphi, ieta);
110 histogramsTOT.at(FE).at(
pixel)->Fill(totmean);
111 histogramsTOTsig.at(FE).at(
pixel)->Fill(totsig);
121 for(
unsigned int FE = 0; FE <
m_nFE; FE++){
125 totArrI.at(FE).at(c) = histogramsTOT.at(FE).at(
pixel)->GetMean();
126 totErrArrI.at(FE).at(c) = histogramsTOT.at(FE).at(
pixel)->GetMeanError();
127 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));
128 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));
130 if(totSigErrArrI.at(FE).at(c) > 1.0){
131 totArrI.at(FE).at(c) = 0.0;
136 totLongArrI.at(FE).at(c) = histogramsTOT.at(FE).at(
pixel)->GetMean();
137 totErrLongArrI.at(FE).at(c) = histogramsTOT.at(FE).at(
pixel)->GetMeanError();
139 if(totErrLongArrI.at(FE).at(c) > 1.0){
140 totLongArrI.at(FE).at(c) = 0.0;
146 histogramsTOT.at(FE).at(
pixel)->Reset(
"ICESM");
147 histogramsTOTsig.at(FE).at(
pixel)->Reset(
"ICESM");
153 for(
unsigned int FE = 0; FE <
m_nFE; FE++) {
155 std::string subdir(((FE < 10) ?
"FE0" :
"FE") +std::to_string(FE));
157 std::vector<float> v_Q;
158 std::vector<float> v_Qerr;
159 std::vector<float> v_TOT;
160 std::vector<float> v_TOTerr;
161 std::vector<float> v_TOTsig;
162 std::vector<float> v_TOTsigerr;
163 std::vector<float> v_TOTlong;
164 std::vector<float> v_TOTlongerr;
168 std::copy(std::begin(totArrI[FE]) , std::end(totArrI[FE]) , std::back_inserter(v_TOT) );
169 std::copy(std::begin(totErrArrI[FE]) , std::end(totErrArrI[FE]) , std::back_inserter(v_TOTerr) );
170 std::copy(std::begin(totSigArrI[FE]) , std::end(totSigArrI[FE]) , std::back_inserter(v_TOTsig) );
171 std::copy(std::begin(totSigErrArrI[FE]) , std::end(totSigErrArrI[FE]) , std::back_inserter(v_TOTsigerr) );
172 std::copy(std::begin(totLongArrI[FE]) , std::end(totLongArrI[FE]) , std::back_inserter(v_TOTlong) );
173 std::copy(std::begin(totErrLongArrI[FE]) , std::end(totErrLongArrI[FE]) , std::back_inserter(v_TOTlongerr) );
175 std::vector<float> pixNormalParams;
176 std::vector<float> pixNormalParamsQuality;
177 std::vector<float> pixSigParams;
178 std::vector<float> pixSigParamsQuality;
179 std::vector<float> pixLongParams;
180 std::vector<float> pixLongParamsQuality;
185 int vecsize = v_Q.size();
187 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) );
188 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) );
193 graphnormal->Fit(functnormal.get() ,
"MRQ");
194 graphsig ->Fit(functnormalsig.get(),
"MRQ");
196 pixNormalParams =
getParams(functnormal.get() ,3 );
197 pixSigParams =
getParams(functnormalsig.get(),2 );
205 if( !
m_wFile->Get((rodName+
"/"+modName+
"/TOTfits/"+subdir).c_str()) ){
206 m_wFile->mkdir((rodName+
"/"+modName+
"/TOTfits/"+subdir).c_str(),rodName.c_str());
209 m_wFile->cd((rodName+
"/"+modName+
"/TOTfits/"+subdir).c_str());
211 graphTitles(graphnormal, std::string(modName+
" - "+subdir+
" - normal pixels: Fit: "+std::to_string(n_fit)).c_str(),
"TOT");
212 graphTitles(graphsig , std::string(modName+
" - "+subdir+
" - normal pixels: Fit: "+std::to_string(n_fit)).c_str(),
"Charge smearing");
214 graphnormal->Write(std::string(
"normal_fit_"+std::to_string(n_fit)).c_str(), TObject::kWriteDelete);
215 graphsig->Write(std::string(
"smearing_fit_"+std::to_string(n_fit)).c_str(), TObject::kWriteDelete);
220 functnormalsig.reset();
225 }
while(
reFit_normalPix(pixNormalParams, v_Q, v_Qerr, v_TOT, v_TOTerr, v_TOTsig, v_TOTsigerr, FE ) );
241 int vecsize = v_Q.size();
243 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) );
247 graflong ->Fit(functlong.get() ,
"MRQ");
249 pixLongParams =
getParams(functlong.get() ,3 );
255 if( !
m_wFile->Get((rodName+
"/"+modName+
"/TOTfits/"+subdir).c_str()) ){
256 m_wFile->mkdir((rodName+
"/"+modName+
"/TOTfits/"+subdir).c_str(),rodName.c_str());
259 m_wFile->cd((rodName+
"/"+modName+
"/TOTfits/"+subdir).c_str());
261 graphTitles(graflong, std::string(modName+
" - "+subdir+
" - long+ganged pixels: Fit: "+std::to_string(n_fit)).c_str(),
"TOT");
263 graflong->Write(std::string(
"long_ganged_fit_"+std::to_string(n_fit)).c_str(), TObject::kWriteDelete);
278 int modID = pm.
getID(modName);
279 auto itr = map_info.find( modID );
281 if (itr != map_info.end()) {
282 (itr->second).at(FE)->set_NormalParams( pixNormalParams);
283 (itr->second).at(FE)->set_LongParams ( pixLongParams );
284 (itr->second).at(FE)->set_SigParams ( pixSigParams );
286 (itr->second).at(FE)->set_times_fitted ( n_fit );
288 (itr->second).at(FE)->set_NormalParamsQuality( pixNormalParamsQuality);
289 (itr->second).at(FE)->set_LongParamsQuality ( pixLongParamsQuality );
290 (itr->second).at(FE)->set_SigParamsQuality ( pixSigParamsQuality );
293 printf(
"Error - Module not found in fitting step... Skipping.\n");
302 for(
unsigned int FE = 0; FE <
m_nFE; FE++) {
304 histogramsTOT.at(FE).at(
pixel).reset();
305 histogramsTOTsig.at(FE).at(
pixel).reset();
371 if (inTimFile.empty())
return false;
373 TFile timFile(inTimFile.c_str(),
"READ");
374 if (not timFile.IsOpen()) {
375 printf(
"Error - File %s could not be opened.\n",inTimFile.c_str());
378 printf(
"File %s opened.\n",inTimFile.c_str());
379 printf(
"Running timming calibration...\n");
383 std::vector< std::vector< std::unique_ptr<TH1F> > > histogramsTIM;
384 for(
unsigned int FE = 0; FE <
m_nFE; FE++){
386 histogramsTIM.push_back( std::vector< std::unique_ptr<TH1F> >() );
389 std::string title =
"FE"+std::to_string(FE)+
"_pixType"+std::to_string(
pixel);
390 std::unique_ptr<TH1F>
h = std::make_unique<TH1F>((title+
"_thr").c_str(), (title+
"_thr").c_str(),
m_timnbins,
m_timLo,
m_timHi);
393 histogramsTIM.at(FE).push_back(std::move(
h));
400 while ((rodKey=
static_cast<TKey*
>(rodItr()))) {
401 const std::string rodName(rodKey->GetName());
402 TDirectoryFile* rodDir =
static_cast<TDirectoryFile*
>(rodKey->ReadObj());
407 while ((modKey=
static_cast<TKey*
>(modItr()))) {
408 std::string modName(modKey->GetName());
414 printf(
"Error - Module %s not found in the PixelMapping tool\n",modName.c_str());
423 h2dTim->SetDirectory(0);
425 for (
unsigned int ieta = 0; ieta <
m_etaBins; ieta++) {
426 for (
unsigned int iphi = 0; iphi <
m_phiBins; iphi++) {
428 float tim = h2dTim->GetBinContent(ieta + 1, iphi + 1);
434 int FE =
chipId(iphi, ieta);
441 histogramsTIM.at(FE).at(
pixel)->Fill(tim);
448 int modID = pm.
getID(modName);
449 auto itr = map_info.find( modID );
450 if (itr == map_info.end()) {
451 printf(
"Calib::fillTiming: ERROR - Mod ID= %16s not found. Creating it -----> Inform Pixel Offline Software Experts... \n",modName.c_str());
453 map_info[modID] = std::vector<std::unique_ptr<CalibFrontEndInfo>> ();
455 for(
unsigned int FE = 0; FE <
m_nFE; FE++){
457 map_info[modID].push_back( std::unique_ptr<CalibFrontEndInfo>() );
458 std::unique_ptr<CalibFrontEndInfo> p = std::make_unique<CalibFrontEndInfo>(modID,FE,modName,std::string(rodKey->GetName()));
459 map_info[modID].at(FE) = std::move(p);
464 int tim_mean = histogramsTIM.at(FE).at(
pixel)->GetMean();
467 histogramsTIM.at(FE).at(
pixel)->Reset(
"ICESM");
470 map_info[modID].at(FE)->set_NormalIntime(tim_mean);
473 map_info[modID].at(FE)->set_LongIntime(tim_mean);
476 map_info[modID].at(FE)->set_GangedIntime(tim_mean);
479 printf(
"Error - Bad pixel in Calib::fillTiming\n");
487 for(
unsigned int FE = 0; FE <
m_nFE; FE++){
488 std::string subdir(((FE < 10) ?
"FE0" :
"FE") +std::to_string(FE));
492 int tim_mean = histogramsTIM.at(FE).at(
pixel)->GetMean();
497 if( !
m_wFile->Get((rodName+
"/"+modName+
"/Thresholds/"+subdir).c_str()) ){
498 m_wFile->mkdir((rodName+
"/"+modName+
"/Thresholds/"+subdir).c_str(),rodName.c_str());
501 m_wFile->cd((rodName+
"/"+modName+
"/Thresholds/"+subdir).c_str());
503 histogramsTIM.at(FE).at(
pixel)->SetTitle(
"Intime;Pixel intime;Counts");
505 std::string
type =
"";
510 histogramsTIM.at(FE).at(
pixel)->Write(std::string(
"intime_"+
type).c_str(), TObject::kWriteDelete);
514 histogramsTIM.at(FE).at(
pixel)->Reset(
"ICESM");
517 (itr->second).at(FE)->set_NormalIntime(tim_mean);
520 (itr->second).at(FE)->set_LongIntime(tim_mean);
523 (itr->second).at(FE)->set_GangedIntime(tim_mean);
526 printf(
"Error - Bad pixel in Calib::fillTiming\n");
535 for(
unsigned int FE = 0; FE <
m_nFE; FE++) {
537 histogramsTIM.at(FE).at(
pixel).reset();
543 printf(
"DONE with threshold calibration.\n");
551 if (inThrFile.empty())
return false;
553 TFile riThrFile(inThrFile.c_str(),
"READ");
554 if (not riThrFile.IsOpen()) {
555 printf(
"Error - File %s could not be opened.\n",inThrFile.c_str());
558 printf(
"File %s opened.\n",inThrFile.c_str());
559 printf(
"Running threshold calibration...\n");
563 std::vector< std::vector< std::unique_ptr<TH1F> > > histogramsTHR;
564 std::vector< std::vector< std::unique_ptr<TH1F> > > histogramsSIG;
565 for(
unsigned int FE = 0; FE <
m_nFE; FE++){
567 histogramsTHR.push_back( std::vector< std::unique_ptr<TH1F> >() );
568 histogramsSIG.push_back( std::vector< std::unique_ptr<TH1F> >() );
571 std::string title =
"FE"+std::to_string(FE)+
"_pixType"+std::to_string(
pixel);
572 std::unique_ptr<TH1F> hthr = std::make_unique<TH1F>((title+
"_thr").c_str(), (title+
"_thr").c_str(),
m_thrnbins,
m_thrLo,
m_thrHi);
573 hthr->SetDirectory(0);
574 std::unique_ptr<TH1F> hsig = std::make_unique<TH1F>((title+
"_sig").c_str(), (title+
"_sig").c_str(),
m_thrnbins,
m_sigLo,
m_sigHi);
575 hsig->SetDirectory(0);
577 histogramsTHR.at(FE).push_back(std::move(hthr));
579 histogramsSIG.at(FE).push_back(std::move(hsig));
586 while ((rodKey=
static_cast<TKey*
>(rodItr()))) {
587 const std::string rodName(rodKey->GetName());
588 TDirectoryFile* rodDir = (TDirectoryFile*)rodKey->ReadObj();
593 while ((modKey=
static_cast<TKey*
>(modItr()))) {
594 std::string modName(modKey->GetName());
600 printf(
"Error - Module %s not found in the PixelMapping tool\n",modName.c_str());
610 h2dThr->SetDirectory(0);
614 h2dSig->SetDirectory(0);
616 for (
unsigned int ieta = 0; ieta <
m_etaBins; ieta++) {
617 for (
unsigned int iphi = 0; iphi <
m_phiBins; iphi++) {
619 float thr = h2dThr->GetBinContent(ieta + 1, iphi + 1);
620 float sig = h2dSig->GetBinContent(ieta + 1, iphi + 1);
622 if (thr == 0 || thr > 10000 || sig == 0 || sig > 1000) {
626 int FE =
chipId(iphi, ieta);
633 histogramsTHR.at(FE).at(
pixel)->Fill(thr);
634 histogramsSIG.at(FE).at(
pixel)->Fill(sig);
643 int modID = pm.
getID(modName);
644 auto itr = map_info.find( modID );
647 if (itr == map_info.end()) {
649 map_info[modID] = std::vector<std::unique_ptr<CalibFrontEndInfo>> ();
651 for(
unsigned int FE = 0; FE <
m_nFE; FE++){
652 std::string subdir(((FE < 10) ?
"FE0" :
"FE") +std::to_string(FE));
653 map_info[modID].push_back( std::unique_ptr<CalibFrontEndInfo>() );
654 std::unique_ptr<CalibFrontEndInfo> p = std::make_unique<CalibFrontEndInfo>(modID,FE,modName,std::string(rodKey->GetName()));
655 map_info[modID].at(FE) = std::move(p);
660 int thr_mean = histogramsTHR.at(FE).at(
pixel)->GetMean();
661 int thr_rms = histogramsTHR.at(FE).at(
pixel)->GetRMS();
662 int sig_mean = histogramsSIG.at(FE).at(
pixel)->GetMean();
667 if( !
m_wFile->Get((rodName+
"/"+modName+
"/Thresholds/"+subdir).c_str()) ){
668 m_wFile->mkdir((rodName+
"/"+modName+
"/Thresholds/"+subdir).c_str(),rodName.c_str());
671 m_wFile->cd((rodName+
"/"+modName+
"/Thresholds/"+subdir).c_str());
673 histogramsTHR.at(FE).at(
pixel)->SetTitle(
"Threshold;Pixel threshold;Counts");
674 histogramsSIG.at(FE).at(
pixel)->SetTitle(
"Sigma;Pixel sigma;Counts");
676 std::string
type =
"";
681 histogramsTHR.at(FE).at(
pixel)->Write(std::string(
"thres_"+
type).c_str(), TObject::kWriteDelete);
682 histogramsSIG.at(FE).at(
pixel)->Write(std::string(
"sigma_"+
type).c_str(), TObject::kWriteDelete);
686 histogramsTHR.at(FE).at(
pixel)->Reset(
"ICESM");
687 histogramsSIG.at(FE).at(
pixel)->Reset(
"ICESM");
690 map_info[modID].at(FE)->set_NormalThreshold(thr_mean);
691 map_info[modID].at(FE)->set_NormalRms(thr_rms);
692 map_info[modID].at(FE)->set_NormalNoise(sig_mean);
695 map_info[modID].at(FE)->set_LongThreshold(thr_mean);
696 map_info[modID].at(FE)->set_LongRms(thr_rms);
697 map_info[modID].at(FE)->set_LongNoise(sig_mean);
700 map_info[modID].at(FE)->set_GangedThreshold(thr_mean);
701 map_info[modID].at(FE)->set_GangedRms(thr_rms);
702 map_info[modID].at(FE)->set_GangedNoise(sig_mean);
705 printf(
"Calib::fillThresholds: ERROR - Bad pixel in Calib::fillThresholds\n");
713 printf(
"Calib::fillThresholds: ERROR - REPEATED MOD ID: %s! Contact Offline team\n",modName.c_str());
719 for(
unsigned int FE = 0; FE <
m_nFE; FE++) {
721 histogramsTHR.at(FE).at(
pixel).reset();
722 histogramsSIG.at(FE).at(
pixel).reset();
728 printf(
"DONE with threshold calibration.\n");