Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-28 07:48:35

0001 #include <TROOT.h>
0002 #include <TString.h>
0003 #include <TObject.h>
0004 #include <TObjString.h>
0005 #include <TSystem.h>
0006 #include <TChain.h>
0007 #include <TMath.h>
0008 #include <TVector3.h>
0009 #include <iostream>
0010 #include <fstream>
0011 #include <TParticlePDG.h>
0012 #include <TDatabasePDG.h>
0013 #include <TRandom3.h>
0014 
0015 #include <TCanvas.h>
0016 #include <TPad.h>
0017 #include <TH1.h>
0018 #include <TH1D.h>
0019 #include <TH1F.h>
0020 #include <TH2.h>
0021 #include <TH3.h>
0022 #include <TFile.h>
0023 #include <TH2D.h>
0024 #include <TH2F.h>
0025 #include <TString.h>
0026 #include <TDatime.h>
0027 #include <TF1.h>
0028 #include <TF2.h>
0029 #include <THStack.h>
0030 #include <TGraph.h>
0031 #include <TStyle.h>
0032 #include <TGraphAsymmErrors.h>
0033 #include <TLine.h>
0034 #include <TLatex.h>
0035 #include <TArrow.h>
0036 #include <TGraphErrors.h>
0037 #include <TGaxis.h>
0038 #include <TLegend.h>
0039 #include <TFrame.h>
0040 #include <TLorentzVector.h>
0041 
0042 // #include "CommonHelperFunctions.h"
0043 
0044 struct runRecData{
0045   int runNr;
0046   int pid;
0047   int nFPGA;
0048   int triggers;
0049   int recEvents;
0050   double recEffi;
0051   std::map<int,int> triggersPerFPGA;
0052   std::map<int,int> recEventsPerFPGA;
0053   std::map<int,double> effiPerFPGA;
0054   std::map<int,int> abortedEventsPerFPGA;
0055   std::map<int,int> inProgEventsPerFPGA;
0056 };
0057 
0058 TString PrintRunRecData( runRecData info, bool simple = false){
0059   TString toPrint = "";
0060   toPrint += Form("%d\t%d\t%d\t%d\t%0.3f\n", info.runNr, info.pid, info.triggers, info.recEvents, info.recEffi);
0061   if (!simple){
0062     for (int f= 0; f < info.nFPGA; f++){
0063       toPrint +=Form("\t\t%d\t%d\t%d\t%d\t%d\t\t%0.3f\n", f, info.triggersPerFPGA[f], info.recEventsPerFPGA[f], info.abortedEventsPerFPGA[f], info.inProgEventsPerFPGA[f], info.effiPerFPGA[f] );
0064     }
0065   }
0066   return toPrint;
0067 }
0068 
0069   struct RunInfo{
0070     RunInfo(): runNr(0), species(""), pdg(0), energy(0), vop(0), vbr(0), lgSet(0), hgSet(0), posX(0), posY(0), shapetime(0), assemblyNr(0), year(-1), month(-1), readout(""), facility(""), beamline(""), samples(0), trigDelay(0) {}
0071     int runNr;
0072     TString species;
0073     int pdg;
0074     float energy;
0075     float vop;
0076     float vbr;
0077     int lgSet;
0078     int hgSet;
0079     float posX;
0080     float posY;
0081     float shapetime;
0082     int assemblyNr;
0083     int year;
0084     int month;
0085     TString readout;
0086     TString facility;
0087     TString beamline;
0088     int samples;
0089     int trigDelay;
0090     int trigDead;
0091     int phase;
0092     int nFPGA;
0093     int nASIC;
0094   } ;
0095 
0096   TString GetStringFromRunInfo(RunInfo, Int_t);
0097 
0098   //__________________________________________________________________________________________________________
0099   //__________________ Read run infos from text fitriggersle _________________________________________________________
0100   //__________________________________________________________________________________________________________    
0101   // specialData: 0 - std. TB, 1 - SPE data ORNL
0102   inline std::map<int,RunInfo> readRunInfosFromFile(TString runListFileName, int debug, int specialData = 0 ){
0103     std::map<int,RunInfo> runs;
0104     //std::cout << "INFO: You have given the following run list file: " << runListFileName.Data() << std::endl;
0105     std::ifstream runListFile;
0106     runListFile.open(runListFileName,std::ios_base::in);
0107     if (!runListFile) {
0108       std::cout << "ERROR: file " << runListFileName.Data() << " not found!" << std::endl;
0109       return runs;
0110     }
0111 
0112     TString facility="";
0113     TString beamline="";
0114     TString readout="";
0115     int year = -1;
0116     int month = -1;
0117     for( TString tempLine; tempLine.ReadLine(runListFile, kTRUE); ) {
0118       // check if line should be considered
0119       if (tempLine.BeginsWith("%") || tempLine.BeginsWith("#")){
0120         continue;
0121       }
0122       if (debug > 1) std::cout << tempLine.Data() << std::endl;
0123       
0124       TObjArray *tempArr2  = tempLine.Tokenize(" ");
0125       if(tempArr2->GetEntries()>0){
0126         if (tempLine.BeginsWith("year")){
0127           year=((TString)((TObjString*)tempArr2->At(1))->GetString()).Atoi();
0128           continue;
0129         } else if (tempLine.BeginsWith("month")){
0130           month=((TString)((TObjString*)tempArr2->At(1))->GetString()).Atoi();
0131           continue;
0132         } else if (tempLine.BeginsWith("readout")){
0133           readout=((TString)((TObjString*)tempArr2->At(1))->GetString());
0134           continue;
0135         } else if (tempLine.BeginsWith("facility")){
0136           facility=((TString)((TObjString*)tempArr2->At(1))->GetString());
0137           continue;
0138         } else if (tempLine.BeginsWith("beam-line")){ 
0139           beamline=((TString)((TObjString*)tempArr2->At(1))->GetString());
0140           continue;
0141         }
0142       }
0143       // Separate the string according to tabulators
0144       TObjArray *tempArr  = tempLine.Tokenize(",");
0145       if(tempArr->GetEntries()<1){
0146         if (debug > 1) std::cout << "nothing to be done" << std::endl;
0147         delete tempArr;
0148         continue;
0149       } 
0150 
0151       // Put them to the correct variables    
0152       RunInfo tempRun;
0153       tempRun.facility= facility;
0154       tempRun.beamline= beamline;
0155       tempRun.readout = readout;
0156       tempRun.year    = year; 
0157       tempRun.month    = month; 
0158       tempRun.runNr    = ((TString)((TObjString*)tempArr->At(0))->GetString()).Atoi();
0159       tempRun.species  =  (TString)((TObjString*)tempArr->At(1))->GetString();
0160       tempRun.pdg      = ((TString)((TObjString*)tempArr->At(2))->GetString()).Atoi();
0161       tempRun.energy   = ((TString)((TObjString*)tempArr->At(3))->GetString()).Atof();
0162       tempRun.vop      = ((TString)((TObjString*)tempArr->At(4))->GetString()).Atof();
0163       tempRun.vbr      = ((TString)((TObjString*)tempArr->At(5))->GetString()).Atof();
0164       
0165       if (readout.CompareTo("CAEN") == 0){
0166         tempRun.hgSet    = ((TString)((TObjString*)tempArr->At(6))->GetString()).Atoi();
0167         tempRun.lgSet    = ((TString)((TObjString*)tempArr->At(7))->GetString()).Atoi();
0168         if (tempArr->GetEntries() > 10){
0169          tempRun.shapetime = ((TString)((TObjString*)tempArr->At(10))->GetString()).Atof();
0170         }
0171       } else {
0172         tempRun.trigDelay = ((TString)((TObjString*)tempArr->At(6))->GetString()).Atoi();
0173         tempRun.samples   = ((TString)((TObjString*)tempArr->At(7))->GetString()).Atoi();
0174         tempRun.trigDead  = ((TString)((TObjString*)tempArr->At(10))->GetString()).Atoi();
0175         tempRun.phase     = ((TString)((TObjString*)tempArr->At(11))->GetString()).Atoi();
0176         tempRun.nFPGA     = ((TString)((TObjString*)tempArr->At(12))->GetString()).Atoi();
0177         tempRun.nASIC     = ((TString)((TObjString*)tempArr->At(13))->GetString()).Atoi();
0178       }
0179       tempRun.posX    = ((TString)((TObjString*)tempArr->At(8))->GetString()).Atoi();
0180       tempRun.posY    = ((TString)((TObjString*)tempArr->At(9))->GetString()).Atoi();
0181       if (specialData == 1) tempRun.assemblyNr = ((TString)((TObjString*)tempArr->At(10))->GetString()).Atoi();
0182                   
0183       if (debug > 1) std::cout << "Run " << tempRun.runNr << "\t species: " << tempRun.species << "\t energy: "  << tempRun.energy << "\t Vop: " << tempRun.vop << "\t Vov: " << tempRun.vop-tempRun.vbr << "\t Xbeam: " << tempRun.posX<< "\t Ybeam: " << tempRun.posY << "\t shaping time: " << tempRun.shapetime << std::endl;
0184       runs[tempRun.runNr]=tempRun;
0185     }
0186     std::cout << year << "-" << month << "\t:\t" << facility.Data() << "-" << beamline.Data() << "\t Readout: " << readout.Data() << std::endl;
0187     std::cout << "registered " << runs.size() << " runs from  "<< runListFileName.Data() << std::endl;
0188     
0189     return runs;
0190   };
0191 
0192   inline int GetSpeciesIntFromRunInfo(RunInfo currRunInfo){
0193       if (currRunInfo.species.Contains("cosmics")){
0194           return  0; // cosmics
0195       } else if (currRunInfo.species.CompareTo("g") == 0){
0196           return  1; // gamma
0197       } else if (currRunInfo.species.Contains("muon") || currRunInfo.species.Contains("Muon") || currRunInfo.species.CompareTo("mu-") == 0){
0198           return  2; // muon
0199       } else if (currRunInfo.species.Contains("Electron") || currRunInfo.species.Contains("electron") || currRunInfo.species.CompareTo("e-") == 0 ){
0200           return  3; // electron
0201       } else if (currRunInfo.species.Contains("Positron") || currRunInfo.species.Contains("positron") || currRunInfo.species.CompareTo("e+") == 0 ){
0202           return  6; // positron
0203       } else if (currRunInfo.species.Contains("Pion") || currRunInfo.species.Contains("pion") || currRunInfo.species.CompareTo("pi-") == 0 || currRunInfo.species.CompareTo("pi+") == 0 ){
0204           return  4; // pion
0205       } else if (currRunInfo.species.Contains("Hadron") || currRunInfo.species.Contains("hadron") || currRunInfo.species.CompareTo("h+") == 0 || currRunInfo.species.CompareTo("h-") == 0 ){
0206           return  5; // hadron/proton
0207       }
0208       
0209       return -1;
0210   }
0211 
0212   //********************************************************************************************************************************
0213   //********************** Returns default labeling strings  ***********************************************************************
0214   //********************************************************************************************************************************    
0215   TString GetStringFromRunInfo(RunInfo currRunInfo, Int_t option = 1){
0216       if (option == 1){
0217           if (currRunInfo.species.Contains("cosmics")){
0218               return  Form("cosmics, Run %d, #it{V}_{#it{op}} = %1.1f V", currRunInfo.runNr, currRunInfo.vop  );
0219           } else if (currRunInfo.species.CompareTo("g") == 0){
0220               return  Form("LED, Run %d, #it{V}_{#it{op}} = %1.1f V", currRunInfo.runNr, currRunInfo.vop  );
0221           } else {
0222               TString beam = currRunInfo.species.Data();
0223               if (beam.CompareTo("Muon +") == 0) beam = "#mu^{+}";
0224               if (beam.CompareTo("Electron") == 0) beam = "e^{-}";              
0225               if (beam.CompareTo("Positron") == 0) beam = "e^{+}";              
0226               if (beam.CompareTo("Pion -") == 0) beam = "#pi^{-}";              
0227               if (beam.CompareTo("Hadron +") == 0) beam = "h^{+}";              
0228               return  Form("%s-beam, #it{E}_{#it{b}}= %.0f GeV, Run %d, #it{V}_{#it{op}} = %1.1f V", beam.Data(), currRunInfo.energy, currRunInfo.runNr, currRunInfo.vop  );
0229           }
0230       } else if (option == 2){
0231           if (currRunInfo.species.CompareTo("cosmics") == 0){
0232               return  "cosmics";
0233           } else if (currRunInfo.species.CompareTo("g") == 0){
0234               return  "LED";
0235           } else {
0236               TString beam = currRunInfo.species.Data();
0237               if (beam.CompareTo("Muon +") == 0) beam = "#mu^{+}";
0238               if (beam.CompareTo("Electron") == 0) beam = "e^{-}";              
0239               if (beam.CompareTo("Positron") == 0) beam = "e^{+}";              
0240               if (beam.CompareTo("Pion -") == 0) beam = "#pi^{-}";              
0241               if (beam.CompareTo("Hadron +") == 0) beam = "h^{+}";              
0242               return  Form("%s-beam, #it{E}_{#it{b}}= %.0f GeV", beam.Data(), currRunInfo.energy);
0243           }
0244       } else if (option == 3){
0245           return Form("Run %d, #it{V}_{#it{op}} = %1.1f V", currRunInfo.runNr, currRunInfo.vop  )   ;
0246       } else if (option == 4){
0247           if (currRunInfo.species.CompareTo("cosmics") == 0){
0248               return Form("cosmics, Run %d, #it{V}_{#it{op}} = %1.1f V, HG = %1d, LG = %1d", currRunInfo.runNr, currRunInfo.vop, currRunInfo.hgSet, currRunInfo.lgSet);
0249           } else if (currRunInfo.species.CompareTo("g") == 0){
0250               return Form("LED, Run %d, #it{V}_{#it{op}} = %1.1f V, HG = %1d, LG = %1d", currRunInfo.runNr, currRunInfo.vop, currRunInfo.hgSet, currRunInfo.lgSet);
0251           } else{
0252               TString beam = currRunInfo.species.Data();
0253               if (beam.CompareTo("Muon +") == 0) beam = "#mu^{+}";
0254               if (beam.CompareTo("Electron") == 0) beam = "e^{-}";              
0255               if (beam.CompareTo("Positron") == 0) beam = "e^{+}";              
0256               if (beam.CompareTo("Pion -") == 0) beam = "#pi^{-}";              
0257               if (beam.CompareTo("Hadron +") == 0) beam = "h^{+}";                            
0258               return Form("%s-beam, #it{E}_{#it{b}}= %.0f GeV, Run %d, #it{V}_{#it{op}} = %1.1f V, HG = %1d, LG = %1d", beam.Data(), currRunInfo.energy, currRunInfo.runNr, currRunInfo.vop, currRunInfo.hgSet, currRunInfo.lgSet);
0259           }
0260       } else if (option == 5){
0261           return Form("pedestal, Run %d, #it{V}_{#it{op}} = %1.1f V", currRunInfo.runNr, currRunInfo.vop  )   ;
0262       } else if (option == 6){
0263           if (currRunInfo.facility.CompareTo("")!=0 && currRunInfo.beamline.CompareTo("")!=0 && currRunInfo.year != -1 && currRunInfo.month != -1 && currRunInfo.readout.CompareTo("")!=0)
0264           return Form("%s-%s, %02d-%d, %s read-out", currRunInfo.facility.Data(), currRunInfo.beamline.Data(),   currRunInfo.month, currRunInfo.year, currRunInfo.readout.Data());
0265           else if (currRunInfo.facility.CompareTo("")!=0 && currRunInfo.beamline.CompareTo("")!=0 && currRunInfo.year != -1 && currRunInfo.month != -1 )
0266           return Form("%s-%s, %02d-%d", currRunInfo.facility.Data(), currRunInfo.beamline.Data(),   currRunInfo.month, currRunInfo.year);
0267       } else if (option == 7){
0268           if (currRunInfo.facility.CompareTo("")!=0 && currRunInfo.beamline.CompareTo("")!=0 && currRunInfo.year != -1 && currRunInfo.month != -1 )
0269           return Form("%s-%s, %02d-%d", currRunInfo.facility.Data(), currRunInfo.beamline.Data(), currRunInfo.month, currRunInfo.year);
0270       } else if (option == 8){
0271           if ( currRunInfo.readout.CompareTo("")!=0)
0272           return Form("%s read-out",  currRunInfo.readout.Data());
0273       } else if (option == 9){
0274           if (currRunInfo.facility.CompareTo("")!=0 && currRunInfo.beamline.CompareTo("")!=0 )
0275           return Form("%s-%s", currRunInfo.facility.Data(), currRunInfo.beamline.Data());
0276       } else if (option == 10){
0277           if ( currRunInfo.year != -1 && currRunInfo.month != -1 )
0278           return Form("%02d-%d", currRunInfo.month, currRunInfo.year);
0279       }
0280       
0281       return "";
0282   }
0283   
0284   // ---------------------------- Function definiton --------------------------------------------------------------------------------------------
0285   // StyleSettingsBasics will make some standard settings for gStyle
0286   
0287   void StyleSettingsBasics( TString format = ""){
0288       //gStyle->SetOptTitle(kFALSE);
0289       gStyle->SetOptDate(0);   //show day and time
0290       gStyle->SetOptStat(0);  //show statistic
0291       gStyle->SetPalette(1,0);
0292       gStyle->SetFrameBorderMode(0);
0293       gStyle->SetFrameFillColor(0);
0294       gStyle->SetTitleFillColor(0);
0295       gStyle->SetTextSize(0.5);
0296       gStyle->SetLabelSize(0.03,"xyz");
0297       gStyle->SetLabelOffset(0.006,"xyz");
0298       gStyle->SetTitleFontSize(0.04);
0299       gStyle->SetTitleOffset(1,"y");
0300       gStyle->SetTitleOffset(0.7,"x");
0301       gStyle->SetCanvasColor(0);
0302       gStyle->SetPadTickX(1);
0303       gStyle->SetPadTickY(1);
0304       // gStyle->SetPadTickZ(1);
0305       gStyle->SetLineWidth(1);
0306       gStyle->SetPaintTextFormat(".3f");
0307       
0308       gStyle->SetPadTopMargin(0.03);
0309       gStyle->SetPadBottomMargin(0.09);
0310       gStyle->SetPadRightMargin(0.03);
0311       gStyle->SetPadLeftMargin(0.13);
0312 
0313 
0314       TGaxis::SetMaxDigits(4);
0315       gErrorIgnoreLevel=kError;
0316 
0317       if (format.CompareTo("eps") == 0 ||format.CompareTo("pdf") == 0  ) gStyle->SetLineScalePS(1);
0318   }
0319 
0320   //__________________________________________________________________________________________________________
0321   void DrawCanvasSettings( TCanvas* c1,
0322                           Double_t leftMargin,
0323                           Double_t rightMargin,
0324                           Double_t topMargin,
0325                           Double_t bottomMargin){
0326 
0327       c1->SetTickx();
0328       c1->SetTicky();
0329       c1->SetGridx(0);
0330       c1->SetGridy(0);
0331       c1->SetLogy(0);
0332       c1->SetLeftMargin(leftMargin);
0333       c1->SetRightMargin(rightMargin);
0334       c1->SetTopMargin(topMargin);
0335       c1->SetBottomMargin(bottomMargin);
0336       c1->SetFillColor(0);
0337   }
0338   
0339   
0340   //__________________________________________________________________________________________________________
0341   void DrawLatex(const double  PosX = 0.5, const double  PosY = 0.5, TString text = "", const bool alignRight = false, const double TextSize = 0.044, const int font = 42, const double dDist = 0.05, const int color = 1){
0342 
0343       std::vector<TString> Latex;
0344       
0345       TObjArray *textStr = text.Tokenize(";");
0346       for(Int_t i = 0; i<textStr->GetEntries() ; i++){
0347           TObjString* tempObj     = (TObjString*) textStr->At(i);
0348           Latex.push_back( tempObj->GetString());
0349       }
0350       for(unsigned int i = 0; i < Latex.size(); ++i){
0351           TLatex l(PosX, PosY - i*dDist, Latex[i]);
0352           l.SetNDC();
0353           l.SetTextFont(font);
0354           l.SetTextColor(color);
0355           l.SetTextSize(TextSize);
0356           if(alignRight) l.SetTextAlign(31);
0357           l.DrawClone("same");
0358       }
0359   }
0360 
0361   //__________________________________________________________________________________________________________
0362   void SetMarkerDefaultsTGraphErr(   TGraphErrors* graph,
0363                                       Style_t markerStyle,
0364                                       Size_t markerSize,
0365                                       Color_t markerColor,
0366                                       Color_t lineColor,
0367                                       Width_t lineWidth       = 1,
0368                                       Bool_t boxes            = kFALSE,
0369                                       Color_t fillColor       = 0,
0370                                       Bool_t isHollow         = kFALSE) {
0371       graph->SetMarkerStyle(markerStyle);
0372       graph->SetMarkerSize(markerSize);
0373       graph->SetMarkerColor(markerColor);
0374       graph->SetLineColor(lineColor);
0375       graph->SetLineWidth(lineWidth);
0376       if (boxes){
0377           graph->SetFillColor(fillColor);
0378           if (fillColor!=0){
0379               if (!isHollow){
0380                   graph->SetFillStyle(1001);
0381               } else {
0382                   graph->SetFillStyle(0);
0383               }
0384           } else {
0385               graph->SetFillStyle(0);
0386           }
0387       }
0388   }  
0389 
0390     //__________________________________________________________________________________________________________
0391   void SetMarkerDefaultsTGraph(  TGraph* graph,
0392                                   Style_t markerStyle,
0393                                   Size_t markerSize,
0394                                   Color_t markerColor,
0395                                   Color_t lineColor,
0396                                   Width_t lineWidth       = 1,
0397                                   Style_t lineStyle       = 1,
0398                                   Bool_t boxes            = kFALSE,
0399                                   Color_t fillColor       = 0,
0400                                   Bool_t isHollow         = kFALSE
0401                                 ) {
0402       graph->SetMarkerStyle(markerStyle);
0403       graph->SetMarkerSize(markerSize);
0404       graph->SetMarkerColor(markerColor);
0405       graph->SetLineColor(lineColor);
0406       graph->SetLineWidth(lineWidth);
0407       graph->SetLineWidth(lineStyle);
0408       if (boxes){
0409           graph->SetFillColor(fillColor);
0410           if (fillColor!=0){
0411               if (!isHollow){
0412                   graph->SetFillStyle(1001);
0413               } else {
0414                   graph->SetFillStyle(0);
0415               }
0416           } else {
0417               graph->SetFillStyle(0);
0418           }
0419       }
0420   }
0421 
0422   //__________________________________________________________________________________________________________
0423   void SetStyleHistoTH1ForGraphs( TH1* histo,
0424                                   TString XTitle,
0425                                   TString YTitle,
0426                                   Size_t xLableSize,
0427                                   Size_t xTitleSize,
0428                                   Size_t yLableSize,
0429                                   Size_t yTitleSize,
0430                                   Float_t xTitleOffset    = 1,
0431                                   Float_t yTitleOffset    = 1,
0432                                   Int_t xNDivisions       = 510,
0433                                   Int_t yNDivisions       = 510,
0434                                   Font_t textFontLabel    = 42,
0435                                   Font_t textFontTitle    = 62
0436                                 ){
0437       histo->SetXTitle(XTitle);
0438       histo->SetYTitle(YTitle);
0439       histo->SetTitle("");
0440 
0441       histo->GetYaxis()->SetLabelFont(textFontLabel);
0442       histo->GetXaxis()->SetLabelFont(textFontLabel);
0443       histo->GetYaxis()->SetTitleFont(textFontTitle);
0444       histo->GetXaxis()->SetTitleFont(textFontTitle);
0445 
0446       histo->GetXaxis()->SetLabelSize(xLableSize);
0447       histo->GetXaxis()->SetTitleSize(xTitleSize);
0448       histo->GetXaxis()->SetTitleOffset(xTitleOffset);
0449       histo->GetXaxis()->SetNdivisions(xNDivisions,kTRUE);
0450 
0451       histo->GetYaxis()->SetDecimals();
0452       histo->GetYaxis()->SetLabelSize(yLableSize);
0453       histo->GetYaxis()->SetTitleSize(yTitleSize);
0454       histo->GetYaxis()->SetTitleOffset(yTitleOffset);
0455       histo->GetYaxis()->SetNdivisions(yNDivisions,kTRUE);
0456   }
0457   
0458   //__________________________________________________________________________________________________________
0459   // Plot Corr with Fits for Full layer
0460   //__________________________________________________________________________________________________________
0461   void PlotTrending (TCanvas* canvas2Panel, Double_t topRCornerX,  Double_t topRCornerY, Double_t relSizeP, Int_t textSizePixel, 
0462                               TGraph* graph, Double_t xPMin, Double_t xPMax, TString nameOutput){
0463                               //, RunInfo currRunInfo){
0464                                   
0465     Double_t minY = 0;
0466     Double_t maxY = 1.05;
0467     
0468     canvas2Panel->cd();
0469     if (!graph) return;;
0470     TH1D* dummyhist = new TH1D("dummyhist", "", 100, xPMin, xPMax);
0471     SetStyleHistoTH1ForGraphs( dummyhist, graph->GetXaxis()->GetTitle(), graph->GetYaxis()->GetTitle(), 0.85*textSizePixel, textSizePixel, 0.85*textSizePixel, textSizePixel,0.9, 1.02, 510, 510, 43, 63);  
0472     // if (optionTrend == 6)std::cout << "\t" << graph->GetXaxis()->GetTitle() << "\t" << graph->GetYaxis()->GetTitle() << std::endl;
0473     SetMarkerDefaultsTGraph(graph, 20, 1, kBlue+1, kBlue+1);   
0474     dummyhist->GetYaxis()->SetRangeUser(minY,maxY);
0475     dummyhist->Draw("axis");
0476     graph->Draw("pe, same");
0477                 
0478 //     TString lab1 = Form("#it{#bf{LFHCal TB:}} %s", GetStringFromRunInfo(currRunInfo, 9).Data());
0479 //     TString lab2 = GetStringFromRunInfo(currRunInfo, 8);
0480 //     TString lab3 = GetStringFromRunInfo(currRunInfo, 10);
0481 //     DrawLatex(topRCornerX-0.045, topRCornerY-1.2*relSizeP-1*0.85*relSizeP, lab1, true, 0.85*textSizePixel, 43);
0482 //     DrawLatex(topRCornerX-0.045, topRCornerY-1.2*relSizeP-2*0.85*relSizeP, lab2, true, 0.85*textSizePixel, 43);
0483 //     DrawLatex(topRCornerX-0.045, topRCornerY-1.2*relSizeP-3*0.85*relSizeP, lab3, true, 0.85*textSizePixel, 43);
0484 //   
0485     canvas2Panel->SaveAs(nameOutput.Data());
0486   }
0487 //   
0488 //   //  
0489   
0490   
0491 //__________________________________________________________________________________________________________
0492 //_____________________MAIN function !!! ___________________________________________________________________
0493 //__________________________________________________________________________________________________________
0494 void EvaluateRecoEffiHGCROC( TString configFileName     = "", 
0495                              TString outputDir          = "Compare/",
0496                              TString runListFileName    = "configs/SPS_RunNumbers.txt",
0497                              Int_t verbosity            = 0
0498                           ){
0499       
0500     StyleSettingsBasics();
0501     // ********************************************************************************************************
0502     // read run list and corresponding settings
0503     // ********************************************************************************************************
0504     std::map<int,RunInfo> ri=readRunInfosFromFile(runListFileName.Data(),verbosity,0);
0505     std::map<int,runRecData> rED;
0506     // ********************************************************************************************************    
0507     // read folder and name from file
0508     // ********************************************************************************************************
0509     // std::vector<Int_t> runnumbers;
0510     // std::vector<TString> fileNames;
0511     ifstream in;
0512     in.open(configFileName,ios_base::in);
0513     if (!in) {
0514         std::cout << "ERROR: file " << configFileName.Data() << " not found!" << std::endl;
0515         return;
0516     }
0517 
0518     TGraph* graphRecEffi = new TGraph();
0519     std::map<int,RunInfo>::iterator it;
0520     
0521     for( TString tempLine; tempLine.ReadLine(in, kTRUE); ) {
0522       // check if line should be considered
0523       if (tempLine.BeginsWith("%") || tempLine.BeginsWith("#")){
0524           continue;
0525       }
0526       if (verbosity > 0) std::cout << tempLine.Data() << std::endl;
0527 
0528       // Separate the string according to tabulators
0529       TObjArray *tempArr  = tempLine.Tokenize("_");
0530       if(tempArr->GetEntries()<1){
0531           if (verbosity > 1) std::cout << "nothing to be done" << std::endl;
0532           delete tempArr;
0533           continue;
0534       } else if (tempArr->GetEntries()==1){
0535           if (verbosity > 1) std::cout << "File name doesn't contain an _ :"  << tempLine.Data()<< std::endl;
0536       }
0537       TString fileEnd  = ((TString)((TObjString*)tempArr->At(tempArr->GetEntries()-1))->GetString());
0538       TObjArray *tempArr2  = fileEnd.Tokenize(".");
0539       if(tempArr2->GetEntries()<=1 ){
0540           if (verbosity > 1) std::cout << "line doesn't have a file ending" << std::endl;
0541           delete tempArr;
0542           delete tempArr2;
0543           continue;
0544       }
0545       TString ending  = ((TString)((TObjString*)tempArr2->At(1))->GetString());
0546       if (ending.CompareTo("root") != 0){
0547           if (verbosity > 1) std::cout << "This is not a root file, skipping.... : " << tempLine.Data() << std::endl;
0548           delete tempArr;
0549           delete tempArr2;
0550           continue;
0551       }  
0552       Int_t temprun     = ((TString)((TObjString*)tempArr2->At(0))->GetString()).Atoi();
0553       
0554       std::cout << temprun << "\t" << tempLine.Data() << std::endl;
0555       // clean-up
0556       delete tempArr;
0557       delete tempArr2;
0558       
0559       TFile* tempFile = new TFile(tempLine.Data(), "OPEN");
0560       if (tempFile->IsZombie()){
0561           std::cout << tempLine.Data() << " is broken, please remove from list or fix!" << std::endl;
0562           delete tempFile;
0563           continue;
0564       }
0565       it=ri.find(temprun);
0566       
0567       TH1D* histEvents = nullptr;
0568       TH1D* histEventPerFPGA[10]; // currently setting list to maximum 10 FPGAs
0569       
0570       histEvents = (TH1D*)tempFile->Get("hNEvents");
0571       if (!histEvents){
0572         std::cout << "Event histo does not exist for run " << temprun << "Aborting!"<< std::endl;
0573         delete tempFile;
0574         continue;
0575       }
0576       for (int f = 0; f < it->second.nFPGA; f++){
0577         histEventPerFPGA[f] = nullptr;
0578         histEventPerFPGA[f] = (TH1D*)tempFile->Get(Form("hNEventsKCU%i",f));
0579         if (!histEventPerFPGA[f]){
0580           std::cout << "Event histo for KCU "<<  f<<" does not exist for run " << temprun << "Aborting!"<< std::endl;
0581           delete tempFile;
0582           continue;
0583         }
0584       }
0585       
0586       runRecData tempRunRec;
0587       tempRunRec.runNr      = temprun;
0588       tempRunRec.pid        = it->second.pdg;
0589       tempRunRec.nFPGA      = it->second.nFPGA;
0590       tempRunRec.triggers     = histEvents->GetBinContent(1);
0591       tempRunRec.recEvents    = histEvents->GetBinContent(2);
0592       if (tempRunRec.triggers > 0)
0593         tempRunRec.recEffi      = (double)tempRunRec.recEvents/tempRunRec.triggers;
0594       else 
0595         tempRunRec.recEffi      = 0;
0596       for (int f= 0; f < tempRunRec.nFPGA; f++){
0597         tempRunRec.triggersPerFPGA[f]       = histEventPerFPGA[f]->GetBinContent(1);
0598         tempRunRec.recEventsPerFPGA[f]      = histEventPerFPGA[f]->GetBinContent(2);
0599         if (histEventPerFPGA[f]->GetBinContent(1)!= 0)
0600           tempRunRec.effiPerFPGA[f]         = (double)(tempRunRec.recEventsPerFPGA[f])/tempRunRec.triggersPerFPGA[f];
0601         else 
0602           tempRunRec.effiPerFPGA[f]         = 0.;
0603         tempRunRec.abortedEventsPerFPGA[f]  = histEventPerFPGA[f]->GetBinContent(3);
0604         tempRunRec.inProgEventsPerFPGA[f]   = histEventPerFPGA[f]->GetBinContent(4);
0605       }
0606       
0607       if(tempRunRec.triggers!= 0)graphRecEffi->AddPoint(temprun,tempRunRec.recEffi);
0608 
0609       
0610       std::cout << (TString)(PrintRunRecData(tempRunRec, false)).Data() << std::endl;
0611       rED[temprun] = tempRunRec;
0612     } 
0613 
0614     for (const auto& run : rED){
0615       std::cout << (TString)(PrintRunRecData(run.second, true)).Data();
0616     }
0617   
0618     graphRecEffi->Sort();
0619     graphRecEffi->GetXaxis()->SetTitle("Run Nr.");
0620     graphRecEffi->GetYaxis()->SetTitle("#varepsilon_{rec}");
0621     
0622     TCanvas* canvas = new TCanvas("canvas","",0,0,800,600);
0623     DrawCanvasSettings( canvas,0.08, 0.01, 0.01, 0.1);
0624 
0625     PlotTrending (canvas, 0.95,  0.95, 0.035, 30, 
0626                   graphRecEffi, graphRecEffi->GetX()[0]-2 , graphRecEffi->GetX()[graphRecEffi->GetN()-1]+2, Form("%s/RecEffi.pdf",outputDir.Data()) );
0627   
0628   
0629 //     std::cout<<"=============================================================="<<std::endl;
0630 //     std::vector<runInfo> compRuns;
0631 //     std::vector<TGraphErrors*>graphsMPV;
0632 //     std::vector<TGraphErrors*>graphsMax;
0633 //     
0634 //     Int_t runsToComp = (Int_t)runnumbers.size();
0635 //     
0636 //     for (Int_t r = 0; r < runsToComp; r++){
0637 //       
0638 //       Int_t indexCRun = findCurrentRun(allRuns, runnumbers.at(r));
0639 //       runInfo currentRunInfo;
0640 //       if (indexCRun < 0){
0641 //         std::cout << "run not in current list of runs, provided" << std::endl;
0642 //         return;
0643 //       } else {
0644 //         std::cout << "Run "<< runnumbers.at(r) << "\t found at index " << indexCRun << std::endl;
0645 //         currentRunInfo = GetRunInfoObject(allRuns,indexCRun);
0646 //       }
0647 //       compRuns.push_back(currentRunInfo);
0648 //       std::cout <<  runnumbers.at(r) << "\t" << fileNames.at(r).Data() << "\t" << compRuns.at(r).vop << std::endl;
0649 //       
0650 //       TFile* tempFile = new TFile(fileNames.at(r).Data(), "OPEN");
0651 //       if (tempFile->IsZombie()){
0652 //           std::cout << fileNames.at(r).Data() << " is broken, please remove from list or fix!" << std::endl;
0653 //       }
0654 //       TGraphErrors* tempGraph = (TGraphErrors*)tempFile->Get("graphMPV_HG_channels");
0655 //       graphsMPV.push_back(tempGraph);
0656 //       tempGraph = (TGraphErrors*)tempFile->Get("graphMax_HG_channels");
0657 //       graphsMax.push_back(tempGraph);
0658 //     }
0659 //     std::cout<<"=============================================================="<<std::endl;
0660 // 
0661 //     std::vector<mipDataPoint> mipPoints;
0662 //     for (Int_t r = 0; r < runsToComp; r++){
0663 //       std::cout <<  runnumbers.at(r) << "\t" << fileNames.at(r).Data() << "\t" << compRuns.at(r).species.Data() << "\t" << compRuns.at(r).vop << std::endl;
0664 //       if (graphsMPV.at(r)->GetN() !=graphsMax.at(r)->GetN() ){
0665 //         std::cout << "MPV and Max graph don't have same size ... something is wrong!" << std::endl;
0666 //         continue;
0667 //       }
0668 //       for (Int_t e = 0; e < (Int_t)graphsMPV.at(r)->GetN(); e++){
0669 //         mipDataPoint currMip;
0670 //         currMip.layer   = (int)(graphsMPV.at(r)->GetX()[e]/10);
0671 //         currMip.channel = (int)(graphsMPV.at(r)->GetX()[e]-10*currMip.layer);
0672 //         currMip.mpvL    = (float)(graphsMPV.at(r)->GetY()[e]);
0673 //         currMip.empvL   = (float)(graphsMPV.at(r)->GetEY()[e]);
0674 //         currMip.max     = (float)(graphsMax.at(r)->GetY()[e]);
0675 //         currMip.emax    = (float)(graphsMax.at(r)->GetEY()[e]);
0676 //         currMip.vop     = (float)(compRuns.at(r).vop);
0677 //         currMip.runnr   = (int)(compRuns.at(r).runNr);
0678 //         currMip.beame   = (float)(compRuns.at(r).energy);
0679 //         if (compRuns.at(r).species.CompareTo("h") == 0)
0680 //           currMip.isHad   = true;
0681 //         else 
0682 //           currMip.isHad   = false;
0683 //         currMip.lgSet   = (float)(compRuns.at(r).lgSet);
0684 //         currMip.hgSet   = (float)(compRuns.at(r).hgSet);
0685 //         
0686 // //         std::cout << graphsMPV.at(r)->GetX()[e] << "\t l: " << currMip.layer << "\t c: " << currMip.channel << "\t vop: " << currMip.vop << std::endl;
0687 //         mipPoints.push_back(currMip);
0688 //       }      
0689 //     }
0690   return;
0691 }
0692