Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-18 09:22:11

0001 #include "../genFinalCalib/tsc_cos_merge.C"
0002 
0003 #include <litecaloeval/LiteCaloEval.h>
0004 
0005 #include <Rtypes.h> // for R__LOAD_LIBRARY macro
0006 #include <TSystem.h>
0007 
0008 #include <format>
0009 #include <fstream>
0010 #include <string>
0011 
0012 R__LOAD_LIBRARY(libLiteCaloEvalTowSlope.so)
0013 
0014 //make sure TS_list has relative or full paths to actual root files
0015 void run_cosmicsTS(const std::string &runs = "runList.txt", const std::string &TS_list= "lce_output_files.txt", bool run_ohcal=false, bool run_ihcal=false)
0016 {
0017 
0018   gSystem->mkdir("fitResults", true);
0019   gSystem->mkdir("cdbFiles", true); 
0020 
0021   std::ifstream runlist(runs);
0022   std::string line;
0023 
0024   std::ifstream tsList(TS_list);
0025   std::string line2;
0026 
0027   //read from run txt file and txt file w/ lce histos at the same time
0028   while(getline(runlist,line) && getline(tsList,line2))
0029   {
0030 
0031     std::cout << "=============================================" << std::endl;
0032     std::cout << "Processing run number: " << line << std::endl;
0033 
0034     if (line.empty() || line2.empty()) continue;  // Skip blank lines
0035 
0036     std::cout << "analysing file " << line2 << std::endl;
0037 
0038 
0039     if (run_ohcal){
0040 
0041     std::cout << "Running analysis for **HCALOUT**..." << std::endl;
0042 
0043     std::string oh_out = "fitResults/oh_cosmicsMerged_fitted_" + line + ".root";
0044   
0045     LiteCaloEval hout;
0046     hout.CaloType(LiteCaloEval::HCALOUT);
0047     hout.set_spectra_binWidth(0.08);
0048     hout.Get_Histos(line2,oh_out);
0049     hout.setFitMin(0.4);//GeV
0050     hout.setFitMax(2.5);
0051     hout.FitRelativeShifts(&hout,110);
0052     hout.draw_spectra(oh_out.c_str());
0053     hout.fit_info(oh_out.c_str(), stoi(line));
0054     
0055     std::string cosmic_CDB_file_oh = std::format("/sphenix/u/bseidlitz/work/macros/calibrations/calo/hcal_towerSlope_y2/cosmicCalibFiles/ohcal_cosmic_calibration_{}.root",line);
0056     
0057     //modify the cosmics calibration file based on tsc fit output
0058     tsc_cos_merge(oh_out,cosmic_CDB_file_oh,std::format("cdbFiles/ohcal_cdb_tsc_cos_calib_{}.root",line),0);
0059     
0060     }
0061 
0062     if (run_ihcal){
0063 
0064     std::cout << "Running analysis for **HCALIN**..." << std::endl;
0065 
0066     std::string ih_out = "fitResults/ih_cosmicsMerged_fitted_" + line + ".root";
0067     
0068     LiteCaloEval hin;
0069     hin.CaloType(LiteCaloEval::HCALIN);
0070     hin.set_spectra_binWidth(0.05);
0071     hin.Get_Histos(line2, ih_out);
0072     hin.setFitMin(0.20);
0073     hin.setFitMax(1.5);
0074     hin.set_doQA(true);
0075     hin.FitRelativeShifts(&hin,110);
0076     hin.draw_spectra(ih_out.c_str());
0077     //hin.fit_info(ih_out.c_str(), stoi(line));
0078     
0079 
0080     std::string cosmic_CDB_file_ih = std::format("/sphenix/u/bseidlitz/work/macros/calibrations/calo/hcal_towerSlope_y2/cosmicCalibFiles/ihcal_cosmic_calibration_{}.root",line);
0081    
0082     //modify the cosmics calibration file based on tsc fit output
0083     tsc_cos_merge(ih_out,cosmic_CDB_file_ih,std::format("cdbFiles/ihcal_cdb_tsc_cos_calib_{}.root",line),1);
0084     }
0085 
0086   }
0087 
0088   std::cout << "Macro is done executing." << std::endl;
0089   
0090 }//end macro