Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #include <iostream>
0002 #include <fstream>
0003 #include <vector>
0004 #include <map>
0005 #include <utility>
0006 #include <string>
0007 #ifdef __APPLE__
0008 #include <unistd.h>
0009 #endif
0010 #include "TROOT.h"
0011 #include "TString.h"
0012 #include "TFile.h"
0013 #include "TTree.h"
0014 #include "TCanvas.h"
0015 #include "TF1.h"
0016 #include "TH1D.h"
0017 #include "TObjArray.h"
0018 #include "TObjString.h"
0019 
0020 #include "Setup.h"
0021 #include "Calib.h"
0022 #include "Event.h"
0023 #include "Tile.h"
0024 #include "HGCROC.h"
0025 #include "Caen.h"
0026 #include "ComparisonCalib.h"
0027 #include "ComparisonAna.h"
0028 
0029 void PrintHelp(char* exe){
0030   std::cout<<"Usage:"<<std::endl;
0031   std::cout<<exe<<" [-option (arguments)]"<<std::endl;
0032   std::cout<<"Options:"<<std::endl;
0033   std::cout<<"-d [0-3] Debugging mode"<<std::endl;
0034   std::cout<<"-e [0-1] extended plotting"<<std::endl;
0035   std::cout<<"-E [1-X] histo reading options for expanded file list"<<std::endl;
0036   std::cout<<"-f       Force to write output if already exist"<<std::endl;
0037   std::cout<<"-F fff   set explicit plot extension explicitly, default is pdf "<<std::endl;
0038   std::cout<<"-i uuu   Input file list"<<std::endl;
0039   std::cout<<"-I uuu   expanded input file list"<<std::endl;
0040   std::cout<<"-L [1-63]restrict max layer plotting"<<std::endl;
0041   std::cout<<"-o vvv   Output file name (mandatory)"<<std::endl;
0042   std::cout<<"-O kkk   Output directory name for plots (mandatory)"<<std::endl;
0043   std::cout<<"-r rrr   Name of run list file  2024 PS TB [../configs/DataTakingDB_202409_CAEN.csv] "<<std::endl;
0044   std::cout<<"-R       Trending plots versus run #"<<std::endl;
0045   std::cout<<"-V       Trending plots versus Vop"<<std::endl;
0046   //std::cout<<"-t       Trending plots versus BoR time"<<std::endl;
0047   std::cout<<"-h       this help"<<std::endl<<std::endl;
0048   std::cout<<"Examples:"<<std::endl;
0049   std::cout<<exe<<" (-f) -o TrendingOutput.root -i input_list.txt (-f to overwrite existing output)"<<std::endl;
0050   std::cout<<exe<<" (-f) -o TrendingOutput.root InputName*.root InputName2.root (-f to overwrite existing output)"<<std::endl;
0051 }
0052   
0053 
0054 int main(int argc, char* argv[]){
0055   if(argc<4) {
0056     PrintHelp(argv[0]);
0057     return 0;
0058   }
0059   std::vector<std::string> RootRegexp;
0060   std::vector<std::string>::iterator it;
0061   for(int i=1; i<argc; i++){
0062     RootRegexp.push_back(argv[i]);
0063   }
0064 /*
0065   // Find -E value to set CompAnalysis
0066 
0067   int E_value = -1;  // default if -E not found
0068   for (int i = 1; i < argc; ++i) {
0069       if (std::string(argv[i]) == "-E") {
0070           if (i + 1 < argc) {
0071               // Convert the next argument to int
0072               E_value = std::stoi(argv[i + 1]);
0073           }
0074           break;  // Found it, no need to continue
0075       }
0076   }
0077   
0078   //declare CompAnalysis 1 and 2
0079   ComparisonCalib CompAnalysis;*/
0080   ComparisonAna CompAnalysis2;
0081  
0082  
0083  //pick Ana or Calib
0084    //if(E_value == 4){
0085     int c;
0086     while((c=getopt(argc,argv,"d:e:E:fF:i:I:L:o:O:r:RVth"))!=-1){
0087       switch(c){
0088       case 'd':
0089         std::cout<<"Compare: enable debug " << optarg <<std::endl;
0090         CompAnalysis2.EnableDebug(atoi(optarg));
0091         it=std::find(RootRegexp.begin(),RootRegexp.end(),"-d");
0092         RootRegexp.erase(it);
0093         it=std::find(RootRegexp.begin(),RootRegexp.end(),Form("%s",optarg));
0094         RootRegexp.erase(it);
0095         break;
0096       case 'e':
0097         std::cout<<"Compare: enabling extended plotting"<<std::endl;
0098         CompAnalysis2.SetExtPlotting(atoi(optarg));
0099         it=std::find(RootRegexp.begin(),RootRegexp.end(),"-e");
0100         RootRegexp.erase(it);
0101         it=std::find(RootRegexp.begin(),RootRegexp.end(),Form("%s",optarg));
0102         RootRegexp.erase(it);
0103         break;
0104       case 'E':
0105         std::cout<<"Compare: set histo reading option"<<std::endl;
0106         CompAnalysis2.ExpandedList(atoi(optarg));
0107         it=std::find(RootRegexp.begin(),RootRegexp.end(),"-E");
0108         RootRegexp.erase(it);
0109         it=std::find(RootRegexp.begin(),RootRegexp.end(),Form("%s",optarg));
0110         RootRegexp.erase(it);
0111         break;
0112       case 'f':
0113         std::cout<<"Compare: If output already exists it will be overwritten"<<std::endl;
0114         CompAnalysis2.CanOverWrite(true);
0115         it=std::find(RootRegexp.begin(),RootRegexp.end(),"-f");
0116         RootRegexp.erase(it);
0117         break;
0118       case 'F':
0119         std::cout<<"Compare: Set Plot extension to: "<< optarg<<std::endl;
0120         CompAnalysis2.SetPlotExtension(optarg);
0121         it=std::find(RootRegexp.begin(),RootRegexp.end(),"-F");
0122         RootRegexp.erase(it);
0123         it=std::find(RootRegexp.begin(),RootRegexp.end(),Form("%s",optarg));
0124         RootRegexp.erase(it);
0125         break;
0126       case 'i':
0127         std::cout<<"Compare: Root input file is: "<<optarg<<std::endl;
0128         CompAnalysis2.SetInputList(Form("%s",optarg));
0129         it=std::find(RootRegexp.begin(),RootRegexp.end(),"-i");
0130         RootRegexp.erase(it);
0131         it=std::find(RootRegexp.begin(),RootRegexp.end(),Form("%s",optarg));
0132         RootRegexp.erase(it);
0133         break;
0134       case 'I':
0135         std::cout<<"Compare: Expanded Root input file is: "<<optarg<<std::endl;
0136         CompAnalysis2.SetInputList(Form("%s",optarg));
0137         if (CompAnalysis2.GetExpandedList() == 0){
0138           CompAnalysis2.ExpandedList(1);
0139         }
0140         it=std::find(RootRegexp.begin(),RootRegexp.end(),"-I");
0141         RootRegexp.erase(it);
0142         it=std::find(RootRegexp.begin(),RootRegexp.end(),Form("%s",optarg));
0143         RootRegexp.erase(it);
0144         break;
0145       case 'L':
0146         std::cout<<"Compare: restrict max layer plotting: "<<optarg<<std::endl;
0147         CompAnalysis2.SetMaxPlotLayer(atoi(optarg));
0148         it=std::find(RootRegexp.begin(),RootRegexp.end(),"-L");
0149         RootRegexp.erase(it);
0150         it=std::find(RootRegexp.begin(),RootRegexp.end(),Form("%s",optarg));
0151         RootRegexp.erase(it);
0152         break;
0153       case 'o': 
0154         std::cout<<"Compare: Output to be saved in: "<<optarg<<std::endl;
0155         CompAnalysis2.SetRootOutput(Form("%s",optarg));
0156         it=std::find(RootRegexp.begin(),RootRegexp.end(),"-o");
0157         RootRegexp.erase(it);
0158         it=std::find(RootRegexp.begin(),RootRegexp.end(),Form("%s",optarg));
0159         RootRegexp.erase(it);
0160         break;
0161       case 'O':
0162         std::cout<<"Compare: Outputdir plots to be saved in: "<<optarg<<std::endl;
0163         CompAnalysis2.SetPlotOutputDir(Form("%s",optarg));
0164         it=std::find(RootRegexp.begin(),RootRegexp.end(),"-O");
0165         RootRegexp.erase(it);
0166         it=std::find(RootRegexp.begin(),RootRegexp.end(),Form("%s",optarg));
0167         RootRegexp.erase(it);
0168         break;
0169       case 'r':
0170         std::cout<<"Compare: run list file from: "<<optarg<<std::endl;
0171         CompAnalysis2.SetRunListInput(Form("%s",optarg));
0172         it=std::find(RootRegexp.begin(),RootRegexp.end(),"-r");
0173         RootRegexp.erase(it);
0174         it=std::find(RootRegexp.begin(),RootRegexp.end(),Form("%s",optarg));
0175         RootRegexp.erase(it);
0176         break;
0177       case 'R':
0178         std::cout<<"Compare: Trending plots versus run #"<<std::endl;
0179         CompAnalysis2.SetTrendingAxis(0);
0180         it=std::find(RootRegexp.begin(),RootRegexp.end(),"-R");
0181         RootRegexp.erase(it);
0182         break;
0183       case 'V':
0184         std::cout<<"Compare: Trending plots versus Vop"<<std::endl;
0185         CompAnalysis2.SetTrendingAxis(1);
0186         it=std::find(RootRegexp.begin(),RootRegexp.end(),"-V");
0187         RootRegexp.erase(it);
0188         break;
0189       //case 't':
0190       //  std::cout<<"Trending plots versus BoR time"<<std::endl;
0191       //  CompAnalysis2.SetTrendingAxis(2);
0192       //  it=std::find(RootRegexp.begin(),RootRegexp.end(),"-t");
0193       //  RootRegexp.erase(it);
0194       //  break;
0195       case '?':
0196         std::cout<<"Option "<<optarg <<" not supported, will be ignored "<<std::endl;
0197         break;
0198       case 'h':
0199         PrintHelp(argv[0]);
0200         return 0;
0201       }
0202     }
0203     std::cout<<"begin extra list"<<std::endl;
0204     for(it=RootRegexp.begin(); it!=RootRegexp.end(); ++it){
0205       std::cout<<*it<<std::endl;
0206       CompAnalysis2.AddInputFile(*it);
0207     }
0208     std::cout<<"end extra list"<<std::endl;
0209     if(!CompAnalysis2.CheckAndOpenIO()){
0210       std::cout<<"Check input and configurations, inconsistency or error with I/O detected"<<std::endl;
0211       PrintHelp(argv[0]);
0212       return -1;
0213     }
0214     CompAnalysis2.ProcessAna();
0215     //CompAnalysis2.Close();
0216     std::cout<<"Exiting"<<std::endl;
0217     
0218     return 0;
0219 }