Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:28:20

0001 #ifndef PLOTTHELPER_1MLAYER_H
0002 #define PLOTTHELPER_1MLAYER_H
0003 
0004   // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0005   // dedicated class for all 8M layer plotting functions
0006   // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0007 
0008 //   //__________________________________________________________________________________________________________
0009 //   // Plot Trigger Primitive with Fits for Full layer
0010 //   //__________________________________________________________________________________________________________
0011 //   void PlotTriggerPrimWithFits8MLayer (TCanvas* canvas2Panel, TPad* pads[8], Double_t* topRCornerX,  Double_t* topRCornerY, 
0012 //                                          Double_t* relSizeP, Int_t textSizePixel, 
0013 //                                          std::map<int,TileSpectra> spectra, Setup* setupT, 
0014 //                                          double avMip, double facLow, double facHigh,
0015 //                                          Double_t xPMin, Double_t xPMax, Double_t scaleYMax, 
0016 //                                          int layer, int mod,  TString nameOutput, RunInfo currRunInfo){
0017 //                                   
0018 //     Double_t maxY = 0;
0019 //     std::map<int, TileSpectra>::iterator ithSpectra;
0020 //     std::map<int, TileSpectra>::iterator ithSpectraTrigg;
0021 //     
0022 //     int nRow = setupT->GetNMaxRow()+1;
0023 //     int nCol = setupT->GetNMaxColumn()+1;
0024 //     int skipped = 0;
0025 //     for (int r = 0; r < nRow; r++){
0026 //       for (int c = 0; c < nCol; c++){
0027 //         int tempCellID = setupT->GetCellID(r,c, layer, mod);
0028 //         ithSpectra=spectra.find(tempCellID);
0029 //         if(ithSpectra==spectra.end()){
0030 //           std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0031 //           continue;
0032 //         } 
0033 //         TH1D* tempHist = ithSpectra->second.GetTriggPrim();
0034 //         if (maxY < FindLargestBin1DHist(tempHist, xPMin , xPMax)) maxY = FindLargestBin1DHist(tempHist, xPMin , xPMax);
0035 //       }  
0036 //     }
0037 // 
0038 //     for (int r = 0; r < nRow; r++){
0039 //       for (int c = 0; c < nCol; c++){
0040 //         canvas2Panel->cd();
0041 //         int tempCellID = setupT->GetCellID(r,c, layer, mod);
0042 //         int p = setupT->GetChannelInLayer(tempCellID);
0043 //         pads[p]->Draw();
0044 //         pads[p]->cd();
0045 //         pads[p]->SetLogy();
0046 //         ithSpectra=spectra.find(tempCellID);
0047 //         if(ithSpectra==spectra.end()){
0048 //           skipped++;
0049 //           std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0050 //           pads[p]->Clear();
0051 //           pads[p]->Draw();
0052 //           if (p ==7 ){
0053 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-2.*relSizeP[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSizeP[p], 42);
0054 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-3.*relSizeP[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSizeP[p], 42);
0055 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4.*relSizeP[p], "Trigger primitives", true, 0.85*relSizeP[p], 42);
0056 //           }
0057 //           continue;
0058 //         } 
0059 //         TH1D* tempHist = ithSpectra->second.GetTriggPrim();
0060 //         SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0061 //         SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);   
0062 //         tempHist->GetXaxis()->SetRangeUser(xPMin,xPMax);
0063 //         tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
0064 //         
0065 //         tempHist->Draw("pe");
0066 //         short bctemp = ithSpectra->second.GetCalib()->BadChannel;
0067 //         if (bctemp != -64 && bctemp < 3){
0068 //           Color_t boxCol = kGray;
0069 //           if (bctemp == 1)
0070 //             boxCol = kGray+1;
0071 //           else if (bctemp == 0)
0072 //             boxCol = kGray+2;
0073 //           TBox* badChannelArea =  CreateBox(boxCol, xPMin, 0.7, xPMax,scaleYMax*maxY, 1001 );
0074 //           badChannelArea->Draw();
0075 //           tempHist->Draw("same,axis");
0076 //           tempHist->Draw("same,pe");
0077 //         }
0078 // 
0079 //         TString label           = Form("row %d col %d", r, c);
0080 //         if (p == 7){
0081 //           label = Form("row %d col %d layer %d", r, c, layer);
0082 //         }
0083 //         TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.045,topRCornerY[p]-1.2*relSizeP[p],label);
0084 //         SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0085 //         labelChannel->Draw();  
0086 //       
0087 //         TBox* triggArea =  CreateBox(kBlue-8, avMip*facLow, 0.7, avMip*facHigh,scaleYMax*maxY, 1001 );
0088 //         triggArea->Draw();
0089 //         
0090 //         DrawLines(avMip*facLow, avMip*facLow,0.7, scaleYMax*maxY, 1, 1, 7);
0091 //         DrawLines(avMip*facHigh, avMip*facHigh,0.7, scaleYMax*maxY, 1, 1, 7);
0092 //         tempHist->Draw("same,axis");
0093 //         tempHist->Draw("same,pe");
0094 //         
0095 //         if (p ==7 ){
0096 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-2.*relSizeP[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSizeP[p], 42);
0097 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-3.*relSizeP[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSizeP[p], 42);
0098 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4.*relSizeP[p], "Trigger primitives", true, 0.85*relSizeP[p], 42);
0099 //         }
0100 //       }
0101 //     }
0102 //     if (skipped < 6)
0103 //       canvas2Panel->SaveAs(nameOutput.Data());
0104 //   }
0105 //     
0106   //__________________________________________________________________________________________________________
0107   // Plot Noise with Fits for Full layer
0108   //__________________________________________________________________________________________________________
0109   void PlotNoiseWithFits1MLayer (TCanvas* canvas2Panel, Double_t topRCornerX,  Double_t topRCornerY, Double_t relSizeP, Int_t textSizePixel, 
0110                                   std::map<int,TileSpectra> spectra, int option, 
0111                                   Double_t xPMin, Double_t xPMax, Double_t scaleYMax, int layer, int mod,  TString nameOutput, RunInfo currRunInfo){
0112                                   
0113     Double_t maxY = 0;
0114     std::map<int, TileSpectra>::iterator ithSpectra;
0115     
0116     Setup* setupT = Setup::GetInstance();
0117     
0118     int skipped = 0;
0119     int tempCellID = setupT->GetCellID(0,0, layer, mod);
0120     ithSpectra=spectra.find(tempCellID);
0121     if(ithSpectra==spectra.end()){
0122       std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t layer " << layer << "\t module " << mod << std::endl;
0123       skipped++;
0124       return;
0125     } 
0126     TH1D* tempHist = nullptr;
0127     if (option == 0){
0128         tempHist = ithSpectra->second.GetHG();
0129     } else if (option ==1){
0130         tempHist = ithSpectra->second.GetLG();
0131     } else if (option ==2){
0132         tempHist = ithSpectra->second.GetTOA();
0133     } else if (option ==3){
0134         tempHist = ithSpectra->second.GetTOT();
0135     }
0136     if (maxY < FindLargestBin1DHist(tempHist, xPMin , xPMax)) maxY = FindLargestBin1DHist(tempHist, xPMin , xPMax);
0137 
0138     canvas2Panel->cd();
0139     canvas2Panel->SetLogy();
0140     SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0141     SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);   
0142     tempHist->GetXaxis()->SetRangeUser(xPMin,xPMax);
0143     tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
0144       
0145     tempHist->Draw("pe");
0146     short bctemp = ithSpectra->second.GetCalib()->BadChannel;
0147     if (bctemp != -64 && bctemp < 3){
0148       Color_t boxCol = kGray;
0149       if (bctemp == 1)
0150         boxCol = kGray+1;
0151       else if (bctemp == 0)
0152         boxCol = kGray+2;
0153       TBox* badChannelArea =  CreateBox(boxCol, xPMin, 0.7, xPMax,scaleYMax*maxY, 1001 );
0154       badChannelArea->SetFillColorAlpha(boxCol, 0.35);
0155       badChannelArea->Draw();
0156       tempHist->Draw("same,axis");
0157       tempHist->Draw("same,pe");
0158     }
0159       
0160     TString label           = Form("layer %d", layer);
0161     TLatex *labelChannel    = new TLatex(topRCornerX-0.04,topRCornerY-1.2*relSizeP,label);
0162     SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0163 
0164       
0165     TF1* fit = nullptr;
0166     if (option == 0){
0167       fit = ithSpectra->second.GetBackModel(1);
0168     } else  if (option ==1){
0169       fit = ithSpectra->second.GetBackModel(0);  
0170     }
0171     if (fit){
0172       SetStyleFit(fit , xPMin, xPMax, 7, 7, kBlack);
0173       fit->Draw("same");
0174       TLegend* legend = GetAndSetLegend2( topRCornerX-8*relSizeP, topRCornerY-4*0.85*relSizeP-0.4*relSizeP, topRCornerX-0.04, topRCornerY-0.6*relSizeP,0.85*textSizePixel, 1, label, 43,0.2);
0175       legend->AddEntry(fit, "Gauss noise fit", "l");
0176       legend->AddEntry((TObject*)0, Form("#mu = %2.2f #pm %2.2f",fit->GetParameter(1), fit->GetParError(1) ) , " ");
0177       legend->AddEntry((TObject*)0, Form("#sigma = %2.2f #pm %2.2f",fit->GetParameter(2), fit->GetParError(2) ) , " ");
0178       legend->Draw();
0179         
0180     } else {
0181       labelChannel->Draw();  
0182     }
0183   
0184     if (xPMin < -5) DrawLines(0, 0,0.7, scaleYMax*maxY, 2, kGray+1, 10);  
0185     DrawLatex(topRCornerX-0.04, topRCornerY-4*0.85*relSizeP-1.4*relSizeP, GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSizeP, 42);
0186     DrawLatex(topRCornerX-0.04, topRCornerY-4*0.85*relSizeP-2.2*relSizeP, GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSizeP, 42);
0187     canvas2Panel->SaveAs(nameOutput.Data());
0188   }
0189 //   
0190 //   
0191 //   //__________________________________________________________________________________________________________
0192 //   // Plot Noise extracted from collision data
0193 //   //__________________________________________________________________________________________________________
0194 //   void PlotNoiseAdvWithFits8MLayer (TCanvas* canvas2Panel, TPad* pads[8], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSizeP, Int_t textSizePixel, 
0195 //                                       std::map<int,TileSpectra> spectra, std::map<int,TileSpectra> spectraTrigg, bool isHG, 
0196 //                                       Double_t xPMin, Double_t xPMax, Double_t scaleYMax, int layer, int mod,  TString nameOutput, RunInfo currRunInfo){
0197 //                                   
0198 //     Double_t maxY = 0;
0199 //     std::map<int, TileSpectra>::iterator ithSpectra;
0200 //     std::map<int, TileSpectra>::iterator ithSpectraTrigg;
0201 //     
0202 //     Setup* setupT = Setup::GetInstance();
0203 //     int nRow = setupT->GetNMaxRow()+1;
0204 //     int nCol = setupT->GetNMaxColumn()+1;
0205 //     int skipped = 0;
0206 //     for (int r = 0; r < nRow; r++){
0207 //       for (int c = 0; c < nCol; c++){
0208 //         int tempCellID = setupT->GetCellID(r,c, layer, mod);
0209 //         ithSpectra=spectra.find(tempCellID);
0210 //         if(ithSpectra==spectra.end()){
0211 //           std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0212 //           continue;
0213 //         } 
0214 //         TH1D* tempHist = nullptr;
0215 //         if (isHG){
0216 //           tempHist = ithSpectra->second.GetHG();
0217 //         } else {
0218 //           tempHist = ithSpectra->second.GetLG();
0219 //         }
0220 //         if (maxY < FindLargestBin1DHist(tempHist, xPMin , xPMax)) maxY = FindLargestBin1DHist(tempHist, xPMin , xPMax);
0221 //       }  
0222 //     }
0223 //     for (int r = 0; r < nRow; r++){
0224 //       for (int c = 0; c < nCol; c++){
0225 //         canvas2Panel->cd();
0226 //         int tempCellID = setupT->GetCellID(r,c, layer, mod);
0227 //         int p = setupT->GetChannelInLayer(tempCellID);
0228 //         pads[p]->Draw();
0229 //         pads[p]->cd();
0230 //         pads[p]->SetLogy();
0231 //         ithSpectra=spectra.find(tempCellID);
0232 //         if(ithSpectra==spectra.end()){
0233 //           skipped++;
0234 //           std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0235 //           pads[p]->Clear();
0236 //           pads[p]->Draw();
0237 //           if (p ==7 ){
0238 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSizeP[p]-1.4*relSizeP[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSizeP[p], 42);
0239 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSizeP[p]-2.2*relSizeP[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSizeP[p], 42);
0240 //           }
0241 //           continue;
0242 //         } 
0243 //         ithSpectraTrigg=spectraTrigg.find(tempCellID);
0244 //         TH1D* tempHist = nullptr;
0245 //         if (isHG){
0246 //             tempHist = ithSpectra->second.GetHG();
0247 //         } else {
0248 //             tempHist = ithSpectra->second.GetLG();
0249 //         }
0250 //         SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0251 //         SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);   
0252 //         tempHist->GetXaxis()->SetRangeUser(xPMin,xPMax);
0253 //         tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
0254 //         
0255 //         tempHist->Draw("pe");
0256 //         short bctemp = ithSpectra->second.GetCalib()->BadChannel;
0257 //         if (bctemp != -64 && bctemp < 3){
0258 //           Color_t boxCol = kGray;
0259 //           if (bctemp == 1)
0260 //             boxCol = kGray+1;
0261 //           else if (bctemp == 0)
0262 //             boxCol = kGray+2;
0263 //           TBox* badChannelArea =  CreateBox(boxCol, xPMin, 0.7, xPMax,scaleYMax*maxY, 1001 );
0264 //           badChannelArea->Draw();
0265 //           tempHist->Draw("same,axis");
0266 //           tempHist->Draw("same,pe");
0267 //         }
0268 //         
0269 //         TH1D* tempHistT = nullptr;
0270 //         if (isHG){
0271 //             tempHistT = ithSpectraTrigg->second.GetHG();
0272 //         } else {
0273 //             tempHistT = ithSpectraTrigg->second.GetLG();
0274 //         }
0275 //         SetMarkerDefaults(tempHistT, 24, 1, kRed+1, kRed+1, kFALSE);   
0276 //         tempHistT->Draw("same,pe");
0277 //         
0278 //         TString label           = Form("row %d col %d", r, c);
0279 //         if (p == 7){
0280 //           label = Form("row %d col %d layer %d", r, c, layer);
0281 //         }
0282 //         TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.045,topRCornerY[p]-1.2*relSizeP[p],label);
0283 //         SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0284 // 
0285 //         
0286 //         TF1* fit            = nullptr;
0287 //         bool isTrigFit      = false;
0288 //         if (isHG){
0289 //           fit = ithSpectraTrigg->second.GetBackModel(1);
0290 //           if (!fit){
0291 //               fit = ithSpectra->second.GetBackModel(1);
0292 //               
0293 //           } else {
0294 //               isTrigFit = true;
0295 //           }
0296 //         } else {
0297 //           fit = ithSpectraTrigg->second.GetBackModel(0);
0298 //           if (!fit){
0299 //               fit = ithSpectra->second.GetBackModel(0);
0300 //           } else {
0301 //               isTrigFit = true;
0302 //           }  
0303 //         }
0304 //         if (fit){
0305 //           if (isTrigFit)
0306 //             SetStyleFit(fit , 0, 2000, 7, 3, kRed+3);
0307 //           else 
0308 //             SetStyleFit(fit , 0, 2000, 7, 7, kBlue+3);  
0309 //           fit->Draw("same");
0310 //           TLegend* legend = GetAndSetLegend2( topRCornerX[p]-10*relSizeP[p], topRCornerY[p]-4*0.85*relSizeP[p]-0.4*relSizeP[p], topRCornerX[p]-0.04, topRCornerY[p]-0.6*relSizeP[p],0.85*textSizePixel, 1, label, 43,0.1);
0311 //           if (isTrigFit)
0312 //             legend->AddEntry(fit, "Gauss noise fit, trigg.", "l");
0313 //           else 
0314 //             legend->AddEntry(fit, "Gauss noise fit", "l");  
0315 //           legend->AddEntry((TObject*)0, Form("#mu = %2.2f #pm %2.2f",fit->GetParameter(1), fit->GetParError(1) ) , " ");
0316 //           legend->AddEntry((TObject*)0, Form("#sigma = %2.2f #pm %2.2f",fit->GetParameter(2), fit->GetParError(2) ) , " ");
0317 //           legend->Draw();
0318 //         } else {
0319 //           labelChannel->Draw();  
0320 //         }
0321 //       
0322 //         DrawLines(0, 0,0.7, scaleYMax*maxY, 2, kGray+1, 10);  
0323 //         if (p ==7 ){
0324 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSizeP[p]-1.4*relSizeP[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSizeP[p], 42);
0325 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSizeP[p]-2.2*relSizeP[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSizeP[p], 42);
0326 //         }
0327 //       
0328 //       }
0329 //     }
0330 //     if (skipped < 6)
0331 //       canvas2Panel->SaveAs(nameOutput.Data());
0332 //   }  
0333 //   
0334 //   //__________________________________________________________________________________________________________
0335 //   // Plot Mip with Fits for Full layer
0336 //   //__________________________________________________________________________________________________________
0337 //   void PlotMipWithFits8MLayer (TCanvas* canvas2Panel, TPad* pads[8], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSizeP, Int_t textSizePixel, 
0338 //                                   std::map<int,TileSpectra> spectra, std::map<int,TileSpectra> spectraTrigg, Setup* setupT, bool isHG, 
0339 //                                   Double_t xPMin, Double_t xPMax, Double_t scaleYMax, int layer, int mod,  TString nameOutput, RunInfo currRunInfo){
0340 //                                   
0341 //     Double_t maxY = 0;
0342 //     std::map<int, TileSpectra>::iterator ithSpectra;
0343 //     std::map<int, TileSpectra>::iterator ithSpectraTrigg;
0344 //     
0345 //     int nRow = setupT->GetNMaxRow()+1;
0346 //     int nCol = setupT->GetNMaxColumn()+1;
0347 //     int skipped = 0;
0348 //     for (int r = 0; r < nRow; r++){
0349 //       for (int c = 0; c < nCol; c++){
0350 //         int tempCellID = setupT->GetCellID(r,c, layer, mod);
0351 //         ithSpectra=spectra.find(tempCellID);
0352 //         if(ithSpectra==spectra.end()){
0353 //           std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0354 //           continue;
0355 //         } 
0356 //         TH1D* tempHist = nullptr;
0357 //         if (isHG){
0358 //           tempHist = ithSpectra->second.GetHG();
0359 //         } else {
0360 //           tempHist = ithSpectra->second.GetLG();
0361 //         }
0362 //         if (maxY < FindLargestBin1DHist(tempHist, xPMin , xPMax)) maxY = FindLargestBin1DHist(tempHist, xPMin , xPMax);
0363 //       }  
0364 //     }
0365 //     
0366 //     for (int r = 0; r < nRow; r++){
0367 //       for (int c = 0; c < nCol; c++){
0368 //         canvas2Panel->cd();
0369 //         int tempCellID = setupT->GetCellID(r,c, layer, mod);
0370 //         int p = setupT->GetChannelInLayer(tempCellID);
0371 //         pads[p]->Draw();
0372 //         pads[p]->cd();
0373 //         pads[p]->SetLogy();
0374 //         ithSpectra=spectra.find(tempCellID);
0375 //         if(ithSpectra==spectra.end()){
0376 //           skipped++;
0377 //           std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0378 //           pads[p]->Clear();
0379 //           pads[p]->Draw();
0380 //           if (p ==7 ){
0381 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSizeP[p]-1.4*relSizeP[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSizeP[p], 42);
0382 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSizeP[p]-2.2*relSizeP[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSizeP[p], 42);
0383 //           }          
0384 //           continue;
0385 //         } 
0386 //         ithSpectraTrigg=spectraTrigg.find(tempCellID);
0387 //         TH1D* tempHist = nullptr;
0388 //         double noiseWidth = 0;
0389 //         if (isHG){
0390 //             tempHist = ithSpectra->second.GetHG();
0391 //             noiseWidth = ithSpectra->second.GetCalib()->PedestalSigH;
0392 //         } else {
0393 //             tempHist = ithSpectra->second.GetLG();
0394 //             noiseWidth = ithSpectra->second.GetCalib()->PedestalSigL;
0395 //         }
0396 //         SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0397 //         SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);   
0398 //         tempHist->GetXaxis()->SetRangeUser(xPMin,xPMax);
0399 //         tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
0400 //         
0401 //         tempHist->Draw("pe");
0402 //         short bctemp = ithSpectra->second.GetCalib()->BadChannel;
0403 //         if (bctemp != -64 && bctemp < 3){
0404 //           Color_t boxCol = kGray;
0405 //           if (bctemp == 1)
0406 //             boxCol = kGray+1;
0407 //           else if (bctemp == 0)
0408 //             boxCol = kGray+2;
0409 //           TBox* badChannelArea =  CreateBox(boxCol, xPMin, 0.7, xPMax,scaleYMax*maxY, 1001 );
0410 //           badChannelArea->Draw();
0411 //           tempHist->Draw("same,axis");
0412 //           tempHist->Draw("same,pe");
0413 //         }
0414 //         
0415 //         TH1D* tempHistT = nullptr;
0416 //         
0417 //         if (isHG){
0418 //             tempHistT = ithSpectraTrigg->second.GetHG();
0419 //         } else {
0420 //             tempHistT = ithSpectraTrigg->second.GetLG();
0421 //         }
0422 //         SetMarkerDefaults(tempHistT, 24, 1, kRed+1, kRed+1, kFALSE);   
0423 //         tempHistT->Draw("same,pe");
0424 //         
0425 //         TString label           = Form("row %d col %d", r, c);
0426 //         if (p == 7){
0427 //           label = Form("row %d col %d layer %d", r, c, layer);
0428 //         }
0429 //         TLatex *labelChannel    = new TLatex(topRCornerX[p]-0.045,topRCornerY[p]-1.2*relSizeP[p],label);
0430 //         SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0431 // 
0432 //         
0433 //         TF1* fit            = nullptr;
0434 //         bool isTrigFit      = false;
0435 //         double maxFit       = 0;
0436 //         if (isHG){
0437 //           fit = ithSpectraTrigg->second.GetSignalModel(1);
0438 //           if (!fit){
0439 //               fit = ithSpectra->second.GetSignalModel(1);
0440 //               if (fit){
0441 //                 maxFit = ithSpectra->second.GetCalib()->ScaleH;
0442 //               }
0443 //           } else {
0444 //               isTrigFit = true;
0445 //               maxFit = ithSpectraTrigg->second.GetCalib()->ScaleH;
0446 //           }
0447 //         } else {
0448 //           fit = ithSpectraTrigg->second.GetSignalModel(0);
0449 //           if (!fit){
0450 //               fit = ithSpectra->second.GetSignalModel(0);
0451 //               if (fit){
0452 //                 maxFit = ithSpectra->second.GetCalib()->ScaleL;
0453 //               }
0454 //           } else {
0455 //               isTrigFit = true;
0456 //               maxFit = ithSpectraTrigg->second.GetCalib()->ScaleL;
0457 //           }  
0458 //         }
0459 //         if (fit){
0460 //           if (isTrigFit)
0461 //             SetStyleFit(fit , 0, 2000, 7, 3, kRed+3);
0462 //           else 
0463 //             SetStyleFit(fit , 0, 2000, 7, 7, kBlue+3);  
0464 //           fit->Draw("same");
0465 //           TLegend* legend = GetAndSetLegend2( topRCornerX[p]-10*relSizeP[p], topRCornerY[p]-4*0.85*relSizeP[p]-0.4*relSizeP[p], topRCornerX[p]-0.04, topRCornerY[p]-0.6*relSizeP[p],0.85*textSizePixel, 1, label, 43,0.1);
0466 //           if (isTrigFit)
0467 //             legend->AddEntry(fit, "Landau-Gauss fit, trigg.", "l");
0468 //           else 
0469 //             legend->AddEntry(fit, "Landau-Gauss fit", "l");  
0470 //           legend->AddEntry((TObject*)0, Form("#scale[0.8]{L MPV = %2.2f #pm %2.2f}",fit->GetParameter(1), fit->GetParError(1) ) , " ");
0471 //           legend->AddEntry((TObject*)0, Form("#scale[0.8]{Max = %2.2f}", maxFit ) , " ");
0472 //           legend->Draw();
0473 //           DrawLines(maxFit, maxFit,0.7, scaleYMax*maxY/10, 5, kRed+3, 7);  
0474 //         } else {
0475 //           labelChannel->Draw();  
0476 //         }
0477 //       
0478 //         DrawLines(noiseWidth*3, noiseWidth*3,0.7, scaleYMax*maxY, 2, kGray+1, 10);  
0479 //         DrawLines(noiseWidth*5, noiseWidth*5,0.7, scaleYMax*maxY, 2, kGray+1, 6);  
0480 //       
0481 //         if (p ==7 ){
0482 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSizeP[p]-1.4*relSizeP[p], GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSizeP[p], 42);
0483 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-4*0.85*relSizeP[p]-2.2*relSizeP[p], GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSizeP[p], 42);
0484 //         }
0485 //       }
0486 //     }
0487 //     if (skipped < 6)
0488 //       canvas2Panel->SaveAs(nameOutput.Data());
0489 //   }
0490 // 
0491   //__________________________________________________________________________________________________________
0492   // Plot Spectra with Fits for Full layer
0493   //__________________________________________________________________________________________________________
0494   void PlotSpectra1MLayer (TCanvas* canvas,
0495                            Double_t topRCornerX,  Double_t topRCornerY, Double_t relSizeP, Int_t textSizePixel, 
0496                                   std::map<int,TileSpectra> spectra, int option, 
0497                                   Double_t xPMin, Double_t xPMax, Double_t scaleYMax, int layer, int mod,  TString nameOutput, RunInfo currRunInfo){
0498                                   
0499     Double_t maxY = 0;
0500     std::map<int, TileSpectra>::iterator ithSpectra;
0501     Setup* setupT = Setup::GetInstance();
0502     
0503     int tempCellID = setupT->GetCellID(0,0, layer, mod);
0504     ithSpectra=spectra.find(tempCellID);
0505     if(ithSpectra==spectra.end()){
0506       std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t layer " << layer << "\t module " << mod << std::endl;
0507       return;
0508     } 
0509     TH1D* tempHist = nullptr;
0510     double noiseWidth = 0;
0511     if (option == 0){
0512       tempHist = ithSpectra->second.GetHG();
0513       noiseWidth = ithSpectra->second.GetCalib()->PedestalSigH;
0514     } else if (option == 1){
0515       tempHist = ithSpectra->second.GetLG();
0516       noiseWidth = ithSpectra->second.GetCalib()->PedestalSigL;
0517     } else if (option == 2){
0518       tempHist = ithSpectra->second.GetComb();
0519     } else if (option == 3){
0520       tempHist = ithSpectra->second.GetTOA();
0521     } else if (option == 4){
0522       tempHist = ithSpectra->second.GetTOT();
0523     }
0524     if (maxY < FindLargestBin1DHist(tempHist, xPMin , xPMax)) maxY = FindLargestBin1DHist(tempHist, xPMin , xPMax);
0525     
0526     canvas->cd();
0527     canvas->SetLogy();
0528     SetStyleHistoTH1ForGraphs( tempHist, tempHist->GetXaxis()->GetTitle(), tempHist->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0529     SetMarkerDefaults(tempHist, 20, 1, kBlue+1, kBlue+1, kFALSE);   
0530     tempHist->GetXaxis()->SetRangeUser(xPMin,xPMax);
0531     tempHist->GetYaxis()->SetRangeUser(0.7,scaleYMax*maxY);
0532     
0533     tempHist->Draw("pe");
0534     short bctemp = ithSpectra->second.GetCalib()->BadChannel;
0535     if (bctemp != -64 && bctemp < 3){
0536       Color_t boxCol = kGray;
0537       if (bctemp == 1)
0538         boxCol = kGray+1;
0539       else if (bctemp == 0)
0540         boxCol = kGray+2;
0541       TBox* badChannelArea =  CreateBox(boxCol, xPMin, 0.7, xPMax,scaleYMax*maxY, 1001 );
0542       badChannelArea->Draw();
0543       tempHist->Draw("same,axis");
0544       tempHist->Draw("same,pe");
0545     }
0546             
0547     TString label = Form("layer %d", layer);
0548     TLatex *labelChannel    = new TLatex(topRCornerX-0.045,topRCornerY-1.2*relSizeP,label);
0549     SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,31);
0550     labelChannel->Draw();  
0551   
0552     if (option < 2){
0553       DrawLines(noiseWidth*3, noiseWidth*3,0.7, scaleYMax*maxY, 2, kGray+1, 10);  
0554       DrawLines(noiseWidth*5, noiseWidth*5,0.7, scaleYMax*maxY, 2, kGray+1, 6);  
0555     } else if (option == 3){
0556       DrawLines(0.3, 0.3, 0.7, scaleYMax*maxY, 2, kGray+1, 10);  
0557     }
0558     DrawLatex(topRCornerX-0.045, topRCornerY-4*0.85*relSizeP-1.4*relSizeP, GetStringFromRunInfo(currRunInfo, 2), true, 0.85*relSizeP, 42);
0559     DrawLatex(topRCornerX-0.045, topRCornerY-4*0.85*relSizeP-2.2*relSizeP, GetStringFromRunInfo(currRunInfo, 3), true, 0.85*relSizeP, 42);
0560     
0561     canvas->SaveAs(nameOutput.Data());
0562   }
0563 //   
0564 //   //__________________________________________________________________________________________________________
0565 //   // Plot Corr with Fits for Full layer
0566 //   //__________________________________________________________________________________________________________
0567 //   void PlotCorrWithFits8MLayer (TCanvas* canvas2Panel, TPad* pads[8], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSizeP, Int_t textSizePixel, 
0568 //                                   std::map<int,TileSpectra> spectra, int option, 
0569 //                                   Double_t xPMin, Double_t xPMax, Double_t maxY, int layer, int mod,  TString nameOutput, RunInfo currRunInfo){
0570 //                                   
0571 //     Setup* setupT = Setup::GetInstance();
0572 //     
0573 //     std::map<int, TileSpectra>::iterator ithSpectra;    
0574 //     int nRow = setupT->GetNMaxRow()+1;
0575 //     int nCol = setupT->GetNMaxColumn()+1;
0576 //     int skipped = 0;
0577 //     
0578 //     for (int r = 0; r < nRow; r++){
0579 //       for (int c = 0; c < nCol; c++){
0580 //         canvas2Panel->cd();
0581 //         int tempCellID = setupT->GetCellID(r,c, layer, mod);
0582 //         int p = setupT->GetChannelInLayer(tempCellID);
0583 //         pads[p]->Draw();
0584 //         pads[p]->SetLogy(0);
0585 //         pads[p]->cd();
0586 //         
0587 //         ithSpectra=spectra.find(tempCellID);
0588 //         if(ithSpectra==spectra.end()){
0589 //           skipped++;
0590 //           std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0591 //           pads[p]->Clear();
0592 //           pads[p]->Draw();
0593 //           if (p ==7 ){
0594 //             DrawLatex(topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSizeP[p]-1.4*relSizeP[p], GetStringFromRunInfo(currRunInfo, 2), false, 0.85*relSizeP[p], 42);
0595 //             DrawLatex(topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSizeP[p]-2.2*relSizeP[p], GetStringFromRunInfo(currRunInfo, 3), false, 0.85*relSizeP[p], 42);
0596 //           }
0597 //         continue;
0598 //         } 
0599 //         TProfile* tempProfile = nullptr;
0600 //         if (option == 1 || option == 2){
0601 //             tempProfile = ithSpectra->second.GetHGLGcorr();
0602 //         } else {
0603 //             tempProfile = ithSpectra->second.GetLGHGcorr();
0604 //         }
0605 //         if (!tempProfile) continue;
0606 //         TH1D* dummyhist = new TH1D("dummyhist", "", tempProfile->GetNbinsX(), tempProfile->GetXaxis()->GetXmin(), tempProfile->GetXaxis()->GetXmax());
0607 //         SetStyleHistoTH1ForGraphs( dummyhist, tempProfile->GetXaxis()->GetTitle(), tempProfile->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.5, 510, 510, 43, 63);  
0608 // 
0609 // 
0610 //         // SetStyleTProfile( tempProfile, tempProfile->GetXaxis()->GetTitle(), tempProfile->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.1, 510, 510, 43, 63);  
0611 //         SetMarkerDefaultsProfile(tempProfile, 20, 1, kBlue+1, kBlue+1);   
0612 //         Int_t maxX = 3900;        
0613 //         if (option == 0 || option == 2 )
0614 //           maxX = 340;
0615 //         if (option == 2){
0616 //           dummyhist->GetYaxis()->SetRangeUser(-maxY,maxY);
0617 //           dummyhist->GetXaxis()->SetRangeUser(xPMin,maxX);
0618 //         } else {
0619 //           dummyhist->GetYaxis()->SetRangeUser(0,maxY);
0620 //           dummyhist->GetXaxis()->SetRangeUser(0,maxX);
0621 //         }
0622 //         
0623 //         
0624 //         dummyhist->Draw("axis");
0625 // 
0626 //         short bctemp = ithSpectra->second.GetCalib()->BadChannel;
0627 //         if (bctemp != -64 && bctemp < 3){
0628 //           Color_t boxCol = kGray;
0629 //           if (bctemp == 1)
0630 //             boxCol = kGray+1;
0631 //           else if (bctemp == 0)
0632 //             boxCol = kGray+2;
0633 //           TBox* badChannelArea =  CreateBox(boxCol, 0, 0, maxX,maxY, 1001 );
0634 //           badChannelArea->Draw();
0635 //           dummyhist->Draw("axis,same");
0636 //         }
0637 // 
0638 //         tempProfile->Draw("pe, same");
0639 //                 
0640 //         TString label           = Form("row %d col %d", r, c);
0641 //         if (p == 7){
0642 //           label = Form("row %d col %d layer %d", r, c, layer);
0643 //         }
0644 //         TLatex *labelChannel    = new TLatex(topRCornerX[p]+0.045,topRCornerY[p]-1.2*relSizeP[p],label);
0645 //         SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,11);
0646 // 
0647 //         
0648 //         TF1* fit            = nullptr;
0649 //         if (option == 1 ){
0650 //           fit = ithSpectra->second.GetCorrModel(1);
0651 //         } else if (option == 0 ){
0652 //           fit = ithSpectra->second.GetCorrModel(0);
0653 //         }
0654 //         if (fit){
0655 //           Double_t rangeFit[2] = {0,0};
0656 //           fit->GetRange(rangeFit[0], rangeFit[1]);
0657 //           SetStyleFit(fit , rangeFit[0], rangeFit[1], 7, 3, kRed+3);
0658 //           fit->Draw("same");
0659 //           TLegend* legend = GetAndSetLegend2( topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSizeP[p]-0.4*relSizeP[p], topRCornerX[p]+6*relSizeP[p], topRCornerY[p]-0.6*relSizeP[p],0.85*textSizePixel, 1, label, 43,0.1);
0660 //           legend->AddEntry(fit, "linear fit, trigg.", "l");
0661 //           legend->AddEntry((TObject*)0, Form("#scale[0.8]{b = %2.3f #pm %2.4f}",fit->GetParameter(0), fit->GetParError(0) ) , " ");
0662 //           legend->AddEntry((TObject*)0, Form("#scale[0.8]{a = %2.3f #pm %2.4f}",fit->GetParameter(1), fit->GetParError(1) ) , " ");
0663 //           legend->Draw();
0664 //         } else {
0665 //           labelChannel->Draw();  
0666 //         }
0667 //       
0668 //         if (option == 2){
0669 //          DrawLines(xPMin,maxX,0, 0, 2, kGray+1, 10);   
0670 //         }
0671 //         if (p ==7 ){
0672 //           DrawLatex(topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSizeP[p]-1.4*relSizeP[p], GetStringFromRunInfo(currRunInfo, 2), false, 0.85*relSizeP[p], 42);
0673 //           DrawLatex(topRCornerX[p]+0.045, topRCornerY[p]-4*0.85*relSizeP[p]-2.2*relSizeP[p], GetStringFromRunInfo(currRunInfo, 3), false, 0.85*relSizeP[p], 42);
0674 //         }
0675 //       }
0676 //     }
0677 //     if (skipped < 6)
0678 //       canvas2Panel->SaveAs(nameOutput.Data());
0679 //   }
0680 // 
0681   //__________________________________________________________________________________________________________
0682   // Plot Corr with Fits for Full layer 2D
0683   //__________________________________________________________________________________________________________
0684   void PlotCorr2D1MLayer (TCanvas* canvas2Panel, Double_t topRCornerX,  Double_t topRCornerY, Double_t relSizeP, Int_t textSizePixel, 
0685                                   std::map<int,TileSpectra> spectra, int option,
0686                                   Double_t xPMin, Double_t xPMax, Double_t maxY, int layer, int mod,  TString nameOutput, RunInfo currRunInfo){
0687                                   
0688     Setup* setupT = Setup::GetInstance();
0689     
0690     std::map<int, TileSpectra>::iterator ithSpectra;    
0691     int skipped = 0;
0692     ReadOut::Type rotype = ReadOut::Type::Undef;
0693     
0694     
0695     canvas2Panel->cd();
0696     int tempCellID = setupT->GetCellID(0,0, layer, mod);
0697     canvas2Panel->SetLogy(0);
0698     canvas2Panel->SetLogz(1);
0699       
0700     Int_t offset = 1;
0701     ithSpectra=spectra.find(tempCellID);
0702     if(ithSpectra==spectra.end()){
0703       skipped++;
0704       std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t layer " << layer << "\t module " << mod << std::endl;
0705       return;
0706     } else {
0707       rotype = ithSpectra->second.GetROType();
0708     }
0709 
0710     TProfile* tempProfile = nullptr;
0711     TH2D* temp2D          = nullptr;        
0712     // LG-HG correlation CAEN
0713     if (option == 0){
0714       tempProfile     = ithSpectra->second.GetLGHGcorr();
0715       temp2D          = ithSpectra->second.GetCorr();
0716     // HGCROC waveform
0717     } else if (option == 1){
0718       tempProfile     = ithSpectra->second.GetWave1D();
0719       temp2D          = ithSpectra->second.GetCorr();          
0720     // HGCROC TOA-ADC correlation
0721     } else if (option == 2){
0722       tempProfile     = ithSpectra->second.GetTOAADC();
0723       temp2D          = ithSpectra->second.GetCorrTOAADC();                    
0724     } else if (option == 3){
0725       temp2D          = ithSpectra->second.GetCorrTOASample();
0726     }
0727     
0728     SetStyleHistoTH2ForGraphs( temp2D, temp2D->GetXaxis()->GetTitle(), temp2D->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.5, 510, 510, 43, 63);  
0729     
0730     std::cout << "min: " << xPMin << "\t" << xPMax << std::endl; 
0731     temp2D->GetYaxis()->SetRangeUser(-10,maxY);
0732     temp2D->GetXaxis()->SetRangeUser(xPMin,xPMax);
0733     temp2D->Draw("col");
0734 
0735     DrawCorrectBadChannelBox(ithSpectra->second.GetCalib()->BadChannel,xPMin, 0, xPMax, maxY);
0736     temp2D->Draw("axis,same");
0737     
0738     if (tempProfile){
0739       SetMarkerDefaultsProfile(tempProfile, 24, 0.3, kRed+2, kRed+2);   
0740       tempProfile->Draw("pe, same");
0741     } 
0742         
0743     TString label           = Form("layer %d", layer);
0744     TLatex *labelChannel    = new TLatex(topRCornerX,topRCornerY-1.2*relSizeP,label);
0745     SetStyleTLatex( labelChannel, 0.85*textSizePixel,4,1,43,kTRUE,11);
0746 
0747     TF1* fit            = ithSpectra->second.GetCorrModel(0);
0748     if (rotype == ReadOut::Type::Hgcroc)
0749       fit            = ithSpectra->second.GetCorrModel(2);
0750     if (fit){
0751       offset=4;
0752       Double_t rangeFit[2] = {0,0};
0753       fit->GetRange(rangeFit[0], rangeFit[1]);
0754       SetStyleFit(fit , rangeFit[0], rangeFit[1], 7, 3, kRed+3);
0755       fit->Draw("same");
0756       TLegend* legend = nullptr;
0757       if (rotype == ReadOut::Type::Caen){
0758         legend = GetAndSetLegend2( topRCornerX, topRCornerY-4*0.85*relSizeP-0.4*relSizeP, topRCornerX+6*relSizeP, topRCornerY-0.6*relSizeP,0.85*textSizePixel, 1, label, 43,0.1);
0759         legend->AddEntry(fit, "linear fit, trigg.", "l");
0760         legend->AddEntry((TObject*)0, Form("#scale[0.8]{b = %2.3f #pm %2.4f}",fit->GetParameter(0), fit->GetParError(0) ) , " ");
0761         legend->AddEntry((TObject*)0, Form("#scale[0.8]{a = %2.3f #pm %2.4f}",fit->GetParameter(1), fit->GetParError(1) ) , " ");
0762       } else {
0763         legend = GetAndSetLegend2( topRCornerX, topRCornerY-3*0.85*relSizeP-0.4*relSizeP, topRCornerX+6*relSizeP, topRCornerY-0.6*relSizeP,0.85*textSizePixel, 1, label, 43,0.1);
0764         legend->AddEntry(fit, "const fit", "l");
0765         legend->AddEntry((TObject*)0, Form("#scale[0.8]{a = %2.3f #pm %2.4f}",fit->GetParameter(0), fit->GetParError(0) ) , " ");   
0766       }
0767       legend->Draw();
0768     } else {
0769       labelChannel->Draw();  
0770     }
0771   
0772     if (option == 1){
0773       for (int i = 0; i < currRunInfo.samples; i++){
0774           DrawLines(i*25e3, i*25e3, 0,maxY*0.2, 1, kGray+2, 7, 1);
0775       } 
0776     }
0777   
0778     DrawLatex(topRCornerX, topRCornerY-offset*0.85*relSizeP-1.4*relSizeP, GetStringFromRunInfo(currRunInfo, 2), false, 0.85*relSizeP, 42);
0779     DrawLatex(topRCornerX, topRCornerY-offset*0.85*relSizeP-2.2*relSizeP, GetStringFromRunInfo(currRunInfo, 3), false, 0.85*relSizeP, 42);
0780     canvas2Panel->SaveAs(nameOutput.Data());
0781   }
0782 //   
0783 //   //__________________________________________________________________________________________________________
0784 //   // Plot Corr with Fits for Full layer
0785 //   //__________________________________________________________________________________________________________
0786 //   void PlotTrending8MLayer (TCanvas* canvas2Panel, TPad* pads[8], Double_t* topRCornerX,  Double_t* topRCornerY, Double_t* relSizeP, Int_t textSizePixel, 
0787 //                               std::map<int,TileTrend> trending, int optionTrend, 
0788 //                               Double_t xPMin, Double_t xPMax, int layer, int mod,  TString nameOutput, TString nameOutputSummary, RunInfo currRunInfo, Int_t  detailedPlot = 1){
0789 //                                   
0790 //     Setup* setupT = Setup::GetInstance();
0791 //     
0792 //     std::map<int, TileTrend>::iterator ithTrend;    
0793 //     int nRow = setupT->GetNMaxRow()+1;
0794 //     int nCol = setupT->GetNMaxColumn()+1;
0795 //     int skipped = 0;
0796 //     bool isSameVoltage    = true;
0797 //     double commanVoltage  = 0;
0798 //     
0799 //     Double_t minY = 9999;
0800 //     Double_t maxY = 0.;
0801 //     
0802 //     for (int r = 0; r < nRow; r++){
0803 //       for (int c = 0; c < nCol; c++){
0804 //         int tempCellID = setupT->GetCellID(r,c, layer, mod);
0805 //         ithTrend=trending.find(tempCellID);
0806 //         if (optionTrend == 0){
0807 //           if(minY>ithTrend->second.GetMinHGped()) minY=ithTrend->second.GetMinHGped();
0808 //           if(maxY<ithTrend->second.GetMaxHGped()) maxY=ithTrend->second.GetMaxHGped();
0809 //         } else if (optionTrend == 1){
0810 //           if(minY>ithTrend->second.GetMinLGped()) minY=ithTrend->second.GetMinLGped();
0811 //           if(maxY<ithTrend->second.GetMaxLGped()) maxY=ithTrend->second.GetMaxLGped();
0812 //         } else if (optionTrend == 2){
0813 //           if(minY>ithTrend->second.GetMinHGscale()) minY=ithTrend->second.GetMinHGscale();
0814 //           if(maxY<ithTrend->second.GetMaxHGscale()) maxY=ithTrend->second.GetMaxHGscale();
0815 //         } else if (optionTrend == 3){
0816 //           if(minY>ithTrend->second.GetMinLGscale()) minY=ithTrend->second.GetMinLGscale();
0817 //           if(maxY<ithTrend->second.GetMaxLGscale()) maxY=ithTrend->second.GetMaxLGscale();
0818 //         } else if (optionTrend == 4){
0819 //           if(minY>ithTrend->second.GetMinLGHGcorr()) minY=ithTrend->second.GetMinLGHGcorr();
0820 //           if(maxY<ithTrend->second.GetMaxLGHGcorr()) maxY=ithTrend->second.GetMaxLGHGcorr();
0821 //         } else if (optionTrend == 5){
0822 //           if(minY>ithTrend->second.GetMinHGLGcorr()) minY=ithTrend->second.GetMinHGLGcorr();
0823 //           if(maxY<ithTrend->second.GetMaxHGLGcorr()) maxY=ithTrend->second.GetMaxHGLGcorr();          
0824 //         } else if (optionTrend == 6){
0825 //           if(minY>ithTrend->second.GetMinTrigg()) minY=ithTrend->second.GetMinTrigg();
0826 //           if(maxY<ithTrend->second.GetMaxTrigg()) maxY=ithTrend->second.GetMaxTrigg();          
0827 //         } else if (optionTrend == 7){
0828 //           if(minY>ithTrend->second.GetMinSBSignal()) minY=ithTrend->second.GetMinSBSignal();
0829 //           if(maxY<ithTrend->second.GetMaxSBSignal()) maxY=ithTrend->second.GetMaxSBSignal();          
0830 //         } else if (optionTrend == 8){
0831 //           if(minY>ithTrend->second.GetMinSBNoise()) minY=ithTrend->second.GetMinSBNoise();
0832 //           if(maxY<ithTrend->second.GetMaxSBNoise()) maxY=ithTrend->second.GetMaxSBNoise();          
0833 //         } else if (optionTrend == 9){
0834 //           if(minY>ithTrend->second.GetMinHGMPV()) minY=ithTrend->second.GetMinHGMPV();
0835 //           if(maxY<ithTrend->second.GetMaxHGMPV()) maxY=ithTrend->second.GetMaxHGMPV();          
0836 //         } else if (optionTrend == 10){
0837 //           if(minY>ithTrend->second.GetMinLGMPV()) minY=ithTrend->second.GetMinLGMPV();
0838 //           if(maxY<ithTrend->second.GetMaxLGMPV()) maxY=ithTrend->second.GetMaxLGMPV();          
0839 //         } else if (optionTrend == 11){
0840 //           if(minY>ithTrend->second.GetMinHGLSigma()) minY=ithTrend->second.GetMinHGLSigma();
0841 //           if(maxY<ithTrend->second.GetMaxHGLSigma()) maxY=ithTrend->second.GetMaxHGLSigma();          
0842 //         } else if (optionTrend == 12){
0843 //           if(minY>ithTrend->second.GetMinLGLSigma()) minY=ithTrend->second.GetMinLGLSigma();
0844 //           if(maxY<ithTrend->second.GetMaxLGLSigma()) maxY=ithTrend->second.GetMaxLGLSigma();          
0845 //         } else if (optionTrend == 13){
0846 //           if(minY>ithTrend->second.GetMinHGGSigma()) minY=ithTrend->second.GetMinHGGSigma();
0847 //           if(maxY<ithTrend->second.GetMaxHGGSigma()) maxY=ithTrend->second.GetMaxHGGSigma();          
0848 //         } else if (optionTrend == 14){
0849 //           if(minY>ithTrend->second.GetMinLGGSigma()) minY=ithTrend->second.GetMinLGGSigma();
0850 //           if(maxY<ithTrend->second.GetMaxLGGSigma()) maxY=ithTrend->second.GetMaxLGGSigma();          
0851 //         } else if (optionTrend == 15){
0852 //           if(minY>ithTrend->second.GetMinHGpedwidth()) minY=ithTrend->second.GetMinHGpedwidth();
0853 //           if(maxY<ithTrend->second.GetMaxHGpedwidth()) maxY=ithTrend->second.GetMaxHGpedwidth();          
0854 //         } else if (optionTrend == 16){
0855 //           if(minY>ithTrend->second.GetMinLGpedwidth()) minY=ithTrend->second.GetMinLGpedwidth();
0856 //           if(maxY<ithTrend->second.GetMaxLGpedwidth()) maxY=ithTrend->second.GetMaxLGpedwidth();          
0857 //         } else if (optionTrend == 17){
0858 //           if(minY>ithTrend->second.GetMinLGHGOffset()) minY=ithTrend->second.GetMinLGHGOffset();
0859 //           if(maxY<ithTrend->second.GetMaxLGHGOffset()) maxY=ithTrend->second.GetMaxLGHGOffset();          
0860 //         } else if (optionTrend == 18){
0861 //           if(minY>ithTrend->second.GetMinHGLGOffset()) minY=ithTrend->second.GetMinHGLGOffset();
0862 //           if(maxY<ithTrend->second.GetMaxHGLGOffset()) maxY=ithTrend->second.GetMaxHGLGOffset();          
0863 //         }
0864 //         for (int rc = 0; rc < ithTrend->second.GetNRuns() && rc < 30; rc++ ){
0865 //           if (r == 0 && c == 0){
0866 //             if (rc == 0){
0867 //               commanVoltage = ithTrend->second.GetVoltage(rc);
0868 //             } else {
0869 //               if (commanVoltage != ithTrend->second.GetVoltage(rc))  isSameVoltage = false;
0870 //             }
0871 //           }
0872 //         }
0873 //       }
0874 //     }
0875 //     if (minY == 9999 && maxY == 0.){
0876 //       std::cout <<"Something went wrong! No ranges set for layer " <<  layer << " \t trend plotting option: " << optionTrend << "\t ABORTING!" << std::endl;
0877 //       return;
0878 //     }
0879 //     // prep for log scale
0880 //     if (optionTrend == 6){ 
0881 //       if (minY ==0 ) minY = 1;
0882 //       else minY = minY/5.;
0883 //       maxY= maxY*5.;
0884 //     } else if (optionTrend == 17 || optionTrend == 18 ){ 
0885 //       minY = 1.1*minY;
0886 //       maxY = 2*maxY;      
0887 //     } else {
0888 //       minY = 0.9*minY;
0889 //       maxY = 1.1*maxY;      
0890 //     }
0891 //     for (int r = 0; r < nRow; r++){
0892 //       for (int c = 0; c < nCol; c++){
0893 //         
0894 //         canvas2Panel->cd();
0895 //         int tempCellID = setupT->GetCellID(r,c, layer, mod);
0896 //         int p = setupT->GetChannelInLayer(tempCellID);
0897 // 
0898 //         TString label           = Form("row %d col %d", r, c);
0899 //         TString label2          = Form("Common V_{op} = %2.1f V", commanVoltage);
0900 //         if (p == 7){
0901 //           label = Form("row %d col %d layer %d", r, c, layer);
0902 //         }
0903 // 
0904 //         pads[p]->Draw();
0905 //         
0906 //         if (optionTrend == 6){ 
0907 //           pads[p]->SetLogy(1);
0908 //         } else {
0909 //           pads[p]->SetLogy(0);          
0910 //         }
0911 // 
0912 //         pads[p]->cd();
0913 //         ithTrend=trending.find(tempCellID);
0914 //         if(ithTrend==trending.end()){
0915 //           skipped++;
0916 //           std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t row " << r << "\t column " << c << "\t layer " << layer << "\t module " << mod << std::endl;
0917 //           pads[p]->Clear();
0918 //           pads[p]->Draw();
0919 //           if (p ==4 ){
0920 //             TString lab1 = Form("#it{#bf{LFHCal TB:}} %s", GetStringFromRunInfo(currRunInfo, 9).Data());
0921 //             TString lab2 = GetStringFromRunInfo(currRunInfo, 8);
0922 //             TString lab3 = GetStringFromRunInfo(currRunInfo, 10);
0923 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSizeP[p]-1*0.85*relSizeP[p], lab1, true, 0.85*textSizePixel, 43);
0924 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSizeP[p]-2*0.85*relSizeP[p], lab2, true, 0.85*textSizePixel, 43);
0925 //             DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSizeP[p]-3*0.85*relSizeP[p], lab3, true, 0.85*textSizePixel, 43);
0926 //           }
0927 //           continue;
0928 //         } 
0929 //         TGraphErrors* tempGraph = nullptr;
0930 //         if (optionTrend == 0)       tempGraph = ithTrend->second.GetHGped();
0931 //         else if (optionTrend == 1)  tempGraph = ithTrend->second.GetLGped();
0932 //         else if (optionTrend == 2)  tempGraph = ithTrend->second.GetHGScale();            
0933 //         else if (optionTrend == 3)  tempGraph = ithTrend->second.GetLGScale();
0934 //         else if (optionTrend == 4)  tempGraph = ithTrend->second.GetLGHGcorr();
0935 //         else if (optionTrend == 5)  tempGraph = ithTrend->second.GetHGLGcorr();
0936 //         else if (optionTrend == 6)  tempGraph = ithTrend->second.GetTrigger();
0937 //         else if (optionTrend == 7)  tempGraph = ithTrend->second.GetSBSignal();
0938 //         else if (optionTrend == 8)  tempGraph = ithTrend->second.GetSBNoise();
0939 //         else if (optionTrend == 9)  tempGraph = ithTrend->second.GetHGLMPV();
0940 //         else if (optionTrend == 10) tempGraph = ithTrend->second.GetLGLMPV();
0941 //         else if (optionTrend == 11) tempGraph = ithTrend->second.GetHGLSigma();
0942 //         else if (optionTrend == 12) tempGraph = ithTrend->second.GetLGLSigma();
0943 //         else if (optionTrend == 13) tempGraph = ithTrend->second.GetHGGSigma();
0944 //         else if (optionTrend == 14) tempGraph = ithTrend->second.GetLGGSigma();
0945 //         else if (optionTrend == 15) tempGraph = ithTrend->second.GetHGpedwidth();
0946 //         else if (optionTrend == 16) tempGraph = ithTrend->second.GetLGpedwidth();
0947 //         else if (optionTrend == 17) tempGraph = ithTrend->second.GetLGHGOff();
0948 //         else if (optionTrend == 18) tempGraph = ithTrend->second.GetHGLGOff();
0949 //         if (!tempGraph) continue;
0950 //         TH1D* dummyhist = new TH1D("dummyhist", "", 100, xPMin, xPMax);
0951 //         SetStyleHistoTH1ForGraphs( dummyhist, tempGraph->GetXaxis()->GetTitle(), tempGraph->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.5, 510, 510, 43, 63);  
0952 //         // if (optionTrend == 6)std::cout << "\t" << tempGraph->GetXaxis()->GetTitle() << "\t" << tempGraph->GetYaxis()->GetTitle() << std::endl;
0953 //         SetMarkerDefaultsTGraphErr(tempGraph, 20, 1, kBlue+1, kBlue+1);   
0954 //         dummyhist->GetYaxis()->SetRangeUser(minY,maxY);
0955 //         dummyhist->Draw("axis");
0956 //         tempGraph->Draw("pe, same");
0957 //                 
0958 //         DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSizeP[p], label, true, 0.85*textSizePixel, 43);
0959 //         if (isSameVoltage && p == 7){
0960 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSizeP[p]-1*0.85*relSizeP[p], label2, true, 0.85*textSizePixel, 43);
0961 //         }
0962 //         if (p ==4 ){
0963 //           TString lab1 = Form("#it{#bf{LFHCal TB:}} %s", GetStringFromRunInfo(currRunInfo, 9).Data());
0964 //           TString lab2 = GetStringFromRunInfo(currRunInfo, 8);
0965 //           TString lab3 = GetStringFromRunInfo(currRunInfo, 10);
0966 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSizeP[p]-1*0.85*relSizeP[p], lab1, true, 0.85*textSizePixel, 43);
0967 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSizeP[p]-2*0.85*relSizeP[p], lab2, true, 0.85*textSizePixel, 43);
0968 //           DrawLatex(topRCornerX[p]-0.045, topRCornerY[p]-1.2*relSizeP[p]-3*0.85*relSizeP[p], lab3, true, 0.85*textSizePixel, 43);
0969 //         }
0970 //       }
0971 //     }
0972 //     if (skipped < 8){
0973 //       if(detailedPlot) canvas2Panel->SaveAs(nameOutput.Data());
0974 //       if (layer == 0) canvas2Panel->Print(Form("%s.pdf[",nameOutputSummary.Data()));
0975 //       canvas2Panel->Print(Form("%s.pdf",nameOutputSummary.Data()));
0976 //       if (layer == setupT->GetNMaxLayer()) canvas2Panel->Print(Form("%s.pdf]",nameOutputSummary.Data()));
0977 //     }
0978 //   }
0979 //   
0980 //   //__________________________________________________________________________________________________________
0981 //   // Plot Run overlay for all 8 tiles for all runs available
0982 //   //__________________________________________________________________________________________________________
0983   void PlotRunOverlay1MLayer (TCanvas* canvas2Panel, Double_t topRCornerX, Double_t topLCornerX,  Double_t topRCornerY, Double_t relSizeP, Int_t textSizePixel, 
0984                               std::map<int,TileTrend> trending, int nruns, int optionTrend, 
0985                               Double_t xPMin, Double_t xPMax, int layer, int mod,  TString nameOutput, TString nameOutputSummary, RunInfo currRunInfo, Int_t detailedPlot = 1, bool plotMean = false){
0986                                   
0987     Setup* setupT = Setup::GetInstance();
0988     
0989     std::map<int, TileTrend>::iterator ithTrend;    
0990     int nCol = setupT->GetNMaxColumn()+1;
0991     int skipped = 0;
0992     
0993     Double_t maxY         = 0.;
0994     Double_t minY         = 9999.;
0995     bool isSameVoltage    = true;
0996     double commanVoltage  = 0;
0997     int tempCellID = setupT->GetCellID(0,0, layer, mod);
0998     ithTrend=trending.find(tempCellID);
0999     if(ithTrend==trending.end()){
1000       skipped++;
1001       std::cout << "WARNING: skipping cell ID: " << tempCellID << "\t layer " << layer << "\t module " << mod << std::endl;
1002       return;
1003     } 
1004     if (optionTrend == 0){      // HG
1005       if(maxY<ithTrend->second.GetMaxHGSpec()) maxY=ithTrend->second.GetMaxHGSpec();
1006       if(minY>ithTrend->second.GetMinHGSpec()) minY=ithTrend->second.GetMinHGSpec();
1007     } else if (optionTrend == 1){   //LG
1008       if(maxY<ithTrend->second.GetMaxLGSpec()) maxY=ithTrend->second.GetMaxLGSpec();
1009       if(minY>ithTrend->second.GetMinLGSpec()) minY=ithTrend->second.GetMinLGSpec();
1010     } 
1011     
1012     for (int rc = 0; rc < ithTrend->second.GetNRuns() && rc < 30; rc++ ){
1013       if (rc == 0){
1014         commanVoltage = ithTrend->second.GetVoltage(rc);
1015       } else {
1016         if (commanVoltage != ithTrend->second.GetVoltage(rc))  isSameVoltage = false;
1017       }
1018     }
1019     
1020     if (maxY == 0 && minY == 9999.){
1021       std::cout <<"Something went wrong! No ranges set for layer " <<  layer << " \t trend plotting option: " << optionTrend << "\t ABORTING!" << std::endl;
1022       return;
1023     }
1024     maxY = 3*maxY;
1025     TH1D* histos[30];
1026 
1027     Int_t columns     = 4;
1028     double lineBottom  = (7+0.1);
1029     double scaleTextSize = 0.75;
1030     if (nruns < 5) lineBottom = (1+0.1);
1031     else if (nruns < 9) lineBottom = (2+0.1);
1032     else if (nruns < 13) lineBottom = (3+0.1);
1033     else if (nruns < 17) lineBottom = (4+0.1);
1034     else if (nruns < 21) lineBottom = (5+0.1);
1035     else if (nruns < 25) lineBottom = (6+0.1);
1036     
1037     if (plotMean) {
1038       columns     = 2;
1039       lineBottom  = (7+0.1);
1040       if (nruns < 3) lineBottom = (1+0.1);
1041       else if (nruns < 5) lineBottom = (2+0.1);
1042       else if (nruns < 7) lineBottom = (3+0.1);
1043       else if (nruns < 9) lineBottom = (4+0.1);
1044       else if (nruns < 11) lineBottom = (5+0.1);
1045       else if (nruns < 13) lineBottom = (6+0.1);
1046       scaleTextSize = 0.65; 
1047     }
1048 
1049     double startLegY  = topRCornerY-lineBottom*relSizeP;
1050     double endLegY    = topRCornerY-relSizeP;
1051     
1052     TLegend* legend = GetAndSetLegend2(  0.6, startLegY, topRCornerX, endLegY,
1053                                         scaleTextSize*textSizePixel, columns, "",43,0.25);
1054 
1055 
1056     canvas2Panel->cd();
1057     canvas2Panel->SetLogy(1);
1058     
1059     for (int rc = 0; rc < ithTrend->second.GetNRuns() && rc < 30; rc++ ){
1060       int tmpRunNr = ithTrend->second.GetRunNr(rc);
1061       histos[rc] = nullptr;
1062       if (tmpRunNr != -1) {
1063         if (optionTrend == 0){      // HG
1064           histos[rc] = ithTrend->second.GetHGTriggRun(ithTrend->second.GetRunNr(rc));
1065         } else if (optionTrend == 1){      // LG
1066           histos[rc] = ithTrend->second.GetLGTriggRun(ithTrend->second.GetRunNr(rc));
1067         }
1068       }
1069       if (histos[rc]){
1070         SetStyleHistoTH1ForGraphs( histos[rc], histos[rc]->GetXaxis()->GetTitle(), histos[rc]->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.95, 1.3,  510, 510, 43, 63);  
1071         SetLineDefaults(histos[rc], GetColorLayer(rc), 2, GetLineStyleLayer(rc));   
1072         if(rc == 0){
1073           histos[rc]->GetXaxis()->SetRangeUser(xPMin,xPMax);
1074           histos[rc]->GetYaxis()->SetRangeUser(minY,maxY);
1075           histos[rc]->Draw("hist");
1076         } else {
1077           histos[rc]->Draw("same,hist");
1078         }
1079         if (plotMean){
1080           DrawLines(histos[rc]->GetMean(), histos[rc]->GetMean(),minY, 0.2*maxY, 4,GetColorLayer(rc) ,GetLineStyleLayer(rc));
1081           std::cout << tmpRunNr << "\t" <<  histos[rc]->GetMean() << std::endl;
1082           legend->AddEntry(histos[rc],Form("%d (%.1f)",tmpRunNr,histos[rc]->GetMean() ),"l");
1083         } else {
1084           legend->AddEntry(histos[rc],Form("%d",tmpRunNr),"l");
1085         }
1086       }
1087     }
1088     if (histos[0]) histos[0]->Draw("axis,same");                
1089     
1090     legend->Draw();
1091     TString label           = Form("layer %d", layer);
1092     TString label2          = Form("Common V_{op} = %2.1f V", commanVoltage);
1093     TString beamline = GetStringFromRunInfo(currRunInfo, 9).Data();
1094     TString lab1 = Form("#it{#bf{LFHCal TB:}} %s", beamline.Data());
1095     // labeling inside the panels & legend drawing 
1096     DrawLatex(topRCornerX, topRCornerY-(lineBottom+1.3)*relSizeP, label, true, 0.75*textSizePixel, 43);
1097     if (isSameVoltage ){
1098       DrawLatex(topRCornerX, topRCornerY-(lineBottom+0.5)*relSizeP, label2, true, 0.75*textSizePixel, 43);
1099     }    
1100     if (beamline.Contains("ORNL")) lab1 = beamline;
1101     TString lab2 = GetStringFromRunInfo(currRunInfo, 8);
1102     TString lab3 = GetStringFromRunInfo(currRunInfo, 10);
1103     DrawLatex(topLCornerX, topRCornerY-relSizeP-1*0.75*relSizeP, lab1, false, 0.85*textSizePixel, 43);
1104     DrawLatex(topLCornerX, topRCornerY-relSizeP-2*0.75*relSizeP, lab2, false, 0.85*textSizePixel, 43);
1105     DrawLatex(topLCornerX, topRCornerY-relSizeP-3*0.75*relSizeP, lab3, false, 0.85*textSizePixel, 43);
1106     if(detailedPlot) canvas2Panel->SaveAs(nameOutput.Data());
1107     if (layer == 0) canvas2Panel->Print(Form("%s.pdf[",nameOutputSummary.Data()));
1108     canvas2Panel->Print(Form("%s.pdf",nameOutputSummary.Data()));
1109     if (layer == setupT->GetNMaxLayer()) canvas2Panel->Print(Form("%s.pdf]",nameOutputSummary.Data()));
1110   }
1111 
1112   //__________________________________________________________________________________________________________
1113   // Plot Run overlay for all 8 tiles for all runs available
1114   //__________________________________________________________________________________________________________
1115   void PlotRunOverlayProfile1MLayer (TCanvas* canvas2Panel, Double_t topRCornerX,  Double_t topLCornerX,  Double_t topRCornerY, Double_t relSizeP, Int_t textSizePixel, 
1116                                       std::map<int,TileTrend> trending, int nruns,
1117                                       Double_t xPMin, Double_t xPMax, Double_t yPMin, Double_t yPMax,  int layer, int mod,  TString nameOutput, TString nameOutputSummary, RunInfo currRunInfo, Int_t detailedPlot = 1, bool scaleInt = false ){
1118                                   
1119     Setup* setupT = Setup::GetInstance();
1120     
1121     std::map<int, TileTrend>::iterator ithTrend;    
1122     int nRow = setupT->GetNMaxRow()+1;
1123     int nCol = setupT->GetNMaxColumn()+1;
1124     int skipped = 0;
1125     
1126     bool isSameVoltage    = true;
1127     double commanVoltage  = 0;
1128     
1129     int tempCellID = setupT->GetCellID(0,0, layer, mod);
1130     ithTrend=trending.find(tempCellID);
1131     if(ithTrend==trending.end()){
1132       std::cout << "WARNING: skipping cell ID: " << tempCellID  << "\t layer " << layer << "\t module " << mod << std::endl;
1133       return;
1134     } 
1135 
1136     for (int rc = 0; rc < ithTrend->second.GetNRuns() && rc < 30; rc++ ){
1137       if (rc == 0){
1138         commanVoltage = ithTrend->second.GetVoltage(rc);
1139       } else {
1140         if (commanVoltage != ithTrend->second.GetVoltage(rc))  isSameVoltage = false;
1141       }
1142     }
1143     TProfile* profs[30];
1144 
1145     double lineBottom  = (7);
1146     if (nruns < 5) lineBottom = (1);
1147     else if (nruns < 9) lineBottom = (2);
1148     else if (nruns < 13) lineBottom = (3);
1149     else if (nruns < 17) lineBottom = (4);
1150     else if (nruns < 21) lineBottom = (5);
1151     else if (nruns < 25) lineBottom = (6);
1152     
1153     canvas2Panel->cd();
1154     canvas2Panel->SetLogy(0);
1155     ithTrend=trending.find(tempCellID);
1156 
1157     TString label           = Form("layer %d", layer);
1158     TString label2          = Form("Common V_{op} = %2.1f V", commanVoltage);
1159     
1160     Double_t yPosStart = topRCornerY;
1161     double startLegY  = yPosStart -lineBottom*relSizeP;
1162     double endLegY    = yPosStart;
1163     TLegend* legend = GetAndSetLegend2(  topRCornerX, startLegY, 0.55, endLegY,
1164                                 0.75*textSizePixel, 4, "",43,0.25);    
1165     TH1D* dummyhist;
1166     for (int rc = 0; rc < ithTrend->second.GetNRuns() && rc < 30; rc++ ){
1167       int tmpRunNr = ithTrend->second.GetRunNr(rc);
1168       profs[rc] = nullptr;
1169       if (tmpRunNr != -1) {
1170         profs[rc] = ithTrend->second.GetLGHGTriggRun(ithTrend->second.GetRunNr(rc));
1171         if (scaleInt) profs[rc]->Scale(1/profs[rc]->Integral());
1172         std::cout << profs[rc] << std::endl;
1173       }
1174       if (profs[rc]){
1175         if (rc == 0){
1176           TString yTitle = profs[rc]->GetYaxis()->GetTitle();
1177           if (scaleInt) yTitle = Form("%s/ integral", yTitle.Data());
1178           dummyhist = new TH1D("dummyhist", "", profs[rc]->GetNbinsX(), profs[rc]->GetXaxis()->GetXmin(), profs[rc]->GetXaxis()->GetXmax());
1179           SetStyleHistoTH1ForGraphs( dummyhist, profs[rc]->GetXaxis()->GetTitle(), yTitle, 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.5, 510, 510, 43, 63);
1180           dummyhist->GetXaxis()->SetRangeUser(xPMin,xPMax);
1181           dummyhist->GetYaxis()->SetRangeUser(yPMin,yPMax);
1182           dummyhist->Draw("axis");
1183         }
1184 
1185         SetLineDefaults(profs[rc], GetColorLayer(rc), 2, GetLineStyleLayer(rc));   
1186         profs[rc]->SetMarkerStyle(24);
1187         if (rc < 10)
1188           profs[rc]->SetMarkerStyle(24);
1189         else 
1190           profs[rc]->SetMarkerStyle(25);
1191         profs[rc]->Draw("same,pe");
1192         legend->AddEntry(profs[rc],Form("%d",tmpRunNr),"p");
1193       }
1194     }
1195     if (dummyhist) dummyhist->Draw("axis,same");                
1196     
1197     // labeling inside the panels & legend drawing 
1198     if (isSameVoltage){
1199       DrawLatex(topRCornerX, yPosStart-(lineBottom+0.5)*relSizeP, label2, false, 0.75*textSizePixel, 43);
1200     }
1201     
1202     legend->Draw();
1203     TString beamline = GetStringFromRunInfo(currRunInfo, 9).Data();
1204     TString lab1 = Form("#it{#bf{LFHCal TB:}} %s", beamline.Data());
1205     if (beamline.Contains("ORNL"))
1206       lab1 = beamline;
1207     TString lab2 = GetStringFromRunInfo(currRunInfo, 8);
1208     TString lab3 = GetStringFromRunInfo(currRunInfo, 10);
1209     DrawLatex(topLCornerX, yPosStart-1*0.75*relSizeP, lab1, true, 0.75*textSizePixel, 43);
1210     DrawLatex(topLCornerX, yPosStart-2*0.75*relSizeP, lab2, true, 0.75*textSizePixel, 43);
1211     DrawLatex(topLCornerX, yPosStart-3*0.75*relSizeP, lab3, true, 0.75*textSizePixel, 43);
1212     DrawLatex(topLCornerX, yPosStart-4*0.75*relSizeP, label, true, 0.75*textSizePixel, 43);
1213   
1214     if(detailedPlot) canvas2Panel->SaveAs(nameOutput.Data());
1215     if (layer == 0) canvas2Panel->Print(Form("%s.pdf[",nameOutputSummary.Data()));
1216     canvas2Panel->Print(Form("%s.pdf",nameOutputSummary.Data()));
1217     if (layer == setupT->GetNMaxLayer()) canvas2Panel->Print(Form("%s.pdf]",nameOutputSummary.Data()));
1218   }
1219   
1220 #endif
1221