File indexing completed on 2025-12-16 09:28:17
0001 #include <vector>
0002 #include "TROOT.h"
0003 #ifdef __APPLE__
0004 #include <unistd.h>
0005 #endif
0006 #include "TF1.h"
0007 #include "TFitResult.h"
0008 #include "TFitResultPtr.h"
0009 #include "TH1D.h"
0010 #include "TH2D.h"
0011 #include "TProfile.h"
0012 #include "TChain.h"
0013 #include "TileSpectra.h"
0014 #include "TileTrend.h"
0015 #include "AnaSummary.h"
0016 #include "CalibSummary.h"
0017 #include "CommonHelperFunctions.h"
0018 #include "PlotHelper.h"
0019 #include "ComparisonAna.h"
0020
0021
0022
0023
0024 bool ComparisonAna::CheckAndOpenIO(void){
0025
0026 int matchingbranch;
0027
0028
0029
0030
0031 if(!InputListName.IsNull()){
0032
0033
0034
0035 if (expandedList == 0){
0036 std::cout << "*********************************************************" << std::endl;
0037 std::cout << "Simple reading from file list" << std::endl;
0038 std::cout << "*********************************************************" << std::endl;
0039
0040 std::cout << "reading from file list: " << InputListName.Data() << std::endl;
0041 std::fstream dummyTxt;
0042 dummyTxt.open(InputListName.Data(),std::ios::in);
0043 if(!dummyTxt.is_open()){
0044 std::cout<<"Error opening "<<InputListName.Data()<<", does the file exist?"<<std::endl;
0045 }
0046
0047
0048 std::string dummyRootName;
0049
0050 dummyTxt>>dummyRootName;
0051
0052 int goodsetup;
0053 int goodcalib;
0054 while(dummyTxt.good()){
0055 std::cout << dummyRootName.data() << std::endl;
0056
0057 TFile dummyRoot=TFile(dummyRootName.c_str(),"READ");
0058 if(dummyRoot.IsZombie()){
0059 std::cout<<"Error opening '"<<dummyRootName<<", does the file exist?"<<std::endl;
0060 return false;
0061 }
0062 dummyRoot.Close();
0063
0064 goodsetup=TsetupIn->AddFile(dummyRootName.c_str());
0065 goodcalib=TcalibIn->AddFile(dummyRootName.c_str());
0066 if(goodcalib==0){
0067 std::cout<<"Issues retrieving Calib tree from "<<dummyRootName<<", file is ignored"<<std::endl;
0068 }
0069 if(goodsetup==0){
0070 std::cout<<"Issues retrieving Setup tree from "<<dummyRootName<<", file is ignored"<<std::endl;
0071 }
0072
0073 dummyTxt>>dummyRootName;
0074 }
0075
0076
0077
0078 } else {
0079 std::cout << "You need to provide a calib file and an output of the improved muon calib in the textfile in each line" << std::endl;
0080 std::fstream dummyTxt;
0081 dummyTxt.open(InputListName.Data(),std::ios::in);
0082 if(!dummyTxt.is_open()){
0083 std::cout<<"Error opening "<<InputListName.Data()<<", does the file exist?"<<std::endl;
0084 }
0085 std::string dummyRootCalibName;
0086 std::string dummyRootHistName;
0087
0088 dummyTxt>>dummyRootCalibName >> dummyRootHistName;
0089
0090 int goodsetup;
0091 int goodcalib;
0092 while(dummyTxt.good()){
0093 std::cout << dummyRootCalibName.data() << "\t" << dummyRootHistName.data() << std::endl;
0094
0095
0096 TFile dummyRootCalib=TFile(dummyRootCalibName.c_str(),"READ");
0097 if(dummyRootCalib.IsZombie()){
0098 std::cout<<"Error opening '"<<dummyRootCalibName<<", does the file exist?"<<std::endl;
0099 return false;
0100 }
0101 dummyRootCalib.Close();
0102 TFile dummyRootHist=TFile(dummyRootHistName.c_str(),"READ");
0103 if(dummyRootHist.IsZombie()){
0104 std::cout<<"Error opening '"<<dummyRootHistName<<", does the file exist?"<<std::endl;
0105 return false;
0106 }
0107 dummyRootHist.Close();
0108
0109
0110 AddInputFile(dummyRootHistName);
0111 goodsetup=TsetupIn->AddFile(dummyRootCalibName.c_str());
0112 goodcalib=TcalibIn->AddFile(dummyRootCalibName.c_str());
0113 if(goodcalib==0){
0114 std::cout<<"Issues retrieving Calib tree from "<<dummyRootCalibName<<", file is ignored"<<std::endl;
0115 }
0116 if(goodsetup==0){
0117 std::cout<<"Issues retrieving Setup tree from "<<dummyRootCalibName<<", file is ignored"<<std::endl;
0118 }
0119
0120 dummyTxt>>dummyRootCalibName >> dummyRootHistName;
0121 }
0122 }
0123 }
0124
0125
0126
0127
0128
0129 else {
0130 std::cout << "*********************************************************" << std::endl;
0131 std::cout << "Simple reading from vector" << std::endl;
0132 std::cout << "*********************************************************" << std::endl;
0133
0134
0135 if(RootInputNames.empty()){
0136 std::cout<<"No root files, neither text list file provided"<<std::endl;
0137 return false;
0138 }
0139
0140
0141 std::vector<TString>::iterator it;
0142 int goodsetup;
0143 int goodcalib;
0144 for(it=RootInputNames.begin(); it!=RootInputNames.end(); ++it){
0145
0146 TFile dummy=TFile(it->Data(),"READ");
0147 if(dummy.IsZombie()){
0148 std::cout<<"Error opening '"<<it->Data()<<", does the file exist?"<<std::endl;
0149 return false;
0150 }
0151 dummy.Close();
0152
0153 goodsetup=TsetupIn->AddFile(it->Data());
0154 goodcalib=TcalibIn->AddFile(it->Data());
0155 if(goodcalib==0){
0156 std::cout<<"Issues retrieving Calib tree from "<<it->Data()<<", file is ignored"<<std::endl;
0157 }
0158 if(goodsetup==0){
0159 std::cout<<"Issues retrieving Setup tree from "<<it->Data()<<", file is ignored"<<std::endl;
0160 }
0161 }
0162 }
0163
0164
0165
0166 if(RootOutputName.IsNull()){
0167 return false;
0168 } else {
0169 if(!CreateOutputRootFile()){
0170 return false;
0171 }
0172 }
0173
0174
0175
0176
0177
0178 setup=Setup::GetInstance();
0179 std::cout<<"Setup add "<<setup<<std::endl;
0180 matchingbranch=TsetupIn->SetBranchAddress("setup",&rswptr);
0181 if(matchingbranch<0){
0182 std::cout<<"Error retrieving Setup info from the tree"<<std::endl;
0183 return false;
0184 }
0185 std::cout<<"Entries "<<TsetupIn->GetEntries()<<std::endl;
0186 TsetupIn->GetEntry(0);
0187 setup->Initialize(*rswptr);
0188
0189 matchingbranch=TcalibIn->SetBranchAddress("calib",&calibptr);
0190 if(matchingbranch<0){
0191 std::cout<<"Error retrieving calibration info from the tree"<<std::endl;
0192 return false;
0193 }
0194
0195 return true;
0196 }
0197
0198
0199
0200
0201
0202 bool ComparisonAna::ProcessAna(void){
0203 if(expandedList==4){
0204 std::cout<<"in process"<<std::endl;
0205
0206
0207
0208 gSystem->Exec("mkdir -p "+OutputNameDirPlots);
0209 if (ExtPlot > 0) gSystem->Exec("mkdir -p "+OutputNameDirPlots+"/SingleLayer");
0210 StyleSettingsBasics("pdf");
0211 SetPlotStyle();
0212
0213
0214
0215
0216 bool status=true;
0217
0218 ROOT::EnableImplicitMT();
0219
0220 int entries=TcalibIn->GetEntries();
0221
0222
0223
0224
0225
0226 std::map<int, AnaSummary> sumCalibs;
0227 std::map<int, AnaSummary>::iterator isumCalibs;
0228
0229 double Xvalue;
0230 double Xmin= 9999.;
0231 double Xmax=-9999.;
0232 int nRun = 0;
0233
0234
0235
0236
0237 std::map<int,RunInfo> ri=readRunInfosFromFile(RunListInputName.Data(),debug,0);
0238 std::map<int,RunInfo>::iterator it;
0239
0240
0241
0242
0243 for(int ientry=0; ientry<entries;ientry++){
0244 TcalibIn->GetEntry(ientry);
0245 TsetupIn->GetEntry(ientry);
0246
0247
0248
0249
0250 if (ientry==0) it = ri.find(calib.GetRunNumber());
0251 Xvalue=calib.GetRunNumber();
0252
0253 AnaSummary aSum = AnaSummary(nRun, calib.GetRunNumber(),calib.GetVop());
0254
0255 TH1D* hTimeDiff = nullptr;
0256 TFile* tempFile = nullptr;
0257 if (nRun < (int)RootInputNames.size()){
0258
0259 tempFile = new TFile(RootInputNames[nRun].Data(),"READ");
0260 TH1D* hTimeDiff = (TH1D*)tempFile->Get("hDeltaTime");
0261 aSum.SetDeltaTimeHist(hTimeDiff);
0262 std::cout<<"Run "<<Xvalue<<" mean: "<< hTimeDiff->GetMean()<<std::endl;
0263 }
0264
0265 std::cout<<"filling for " << nRun <<std::endl;
0266 sumCalibs[nRun]=aSum;
0267 nRun++;
0268 }
0269 Int_t textSizePixel = 30;
0270 Float_t textSizeRel = 0.04;
0271 TCanvas* canvasDeltaTime = new TCanvas("canvasDeltaTime","",0,0,1450,1300);
0272 DefaultCancasSettings( canvasDeltaTime, 0.08, 0.062, 0.025, 0.09);
0273 canvasDeltaTime->SetLogy(1);
0274 PlotAnalysisComparison( canvasDeltaTime, 0, sumCalibs, textSizeRel,
0275 Form("%s/TimeDiff_RunOverlay.%s",OutputNameDirPlots.Data(),plotSuffix.Data()), it->second,"", debug);
0276 return true;
0277 }
0278 else{
0279 return false;
0280 }
0281 }
0282
0283
0284
0285 bool ComparisonAna::CreateOutputRootFile(void){
0286 if(Overwrite){
0287 RootOutput=new TFile(RootOutputName.Data(),"RECREATE");
0288 } else{
0289 RootOutput = new TFile(RootOutputName.Data(),"CREATE");
0290 }
0291 if(RootOutput->IsZombie()){
0292 std::cout<<"Error opening '"<<RootOutput<<"'no reachable path? Exist without force mode to overwrite?..."<<std::endl;
0293 return false;
0294 }
0295 return true;
0296 }