Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:13:24

0001 #pragma once
0002 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,00,0)
0003 #include <string>
0004 #include <sstream>
0005 #include <vector>
0006 #include <utility>
0007 #include <map>
0008 #include <algorithm>
0009 #include <fun4all/Fun4AllBase.h>
0010 #include <fun4all/Fun4AllUtils.h>
0011 #include <fun4all/Fun4AllServer.h>
0012 #include <fun4all/Fun4AllInputManager.h>
0013 #include <fun4all/Fun4AllDstInputManager.h>
0014 #include <fun4all/SubsysReco.h>
0015 #include <ffamodules/CDBInterface.h>
0016 #include <Calo_Calib.C>
0017 #include <dummy/dummy.h>
0018 #include <largerlenc/LargeRLENC.h>
0019 #include <jetbase/FastJetAlgo.h>
0020 #include <jetbase/JetReco.h>
0021 #include <jetbase/TowerJetInput.h>
0022 #include <jetbackground/RetowerCEMC.h>
0023 #include <largerlenc/LargeRLENC_LEDPedestalScan.h>
0024 #include <phool/recoConsts.h>
0025 #include <TFile.h>
0026 #include <TTree.h>
0027 #include <fstream>
0028 
0029 R__LOAD_LIBRARY(libfun4all.so)
0030 R__LOAD_LIBRARY(libcalo_io.so)
0031 R__LOAD_LIBRARY(libffamodules.so)
0032 R__LOAD_LIBRARY(libLargeRLENC.so)
0033 R__LOAD_LIBRARY(libdummy.so)
0034 R__LOAD_LIBRARY(libjetbase.so)
0035 R__LOAD_LIBRARY(libjetbackground.so)
0036 std::pair<std::string, std::string> fix_calo_fitting_dst_names(int dst_numb, std::string data_fitting_dst_name){
0037     int first_file_num=dst_numb*2;
0038     int snd_file_num = first_file_num+1;
0039     std::string file_name_stem=data_fitting_dst_name.substr(0, data_fitting_dst_name.find(".root")-5);
0040     std::stringstream file1 (file_name_stem), file2(file_name_stem);
0041     std::stringstream file11, file22;
0042     file11 <<std::setw(5) <<std::setfill('0') <<first_file_num <<".root";
0043     file22 <<std::setw(5) <<std::setfill('0') <<snd_file_num <<".root";
0044     std::string s (file1.str());
0045     std::string s2 (file2.str());
0046     s+=file11.str();
0047     s2+=file22.str();
0048     return std::make_pair(s, s2);
0049 
0050 }
0051 int RunLargeRLENC(std::string data_dst="none", std::string data_fitting_dst="none", std::string data_trigger="none", std::string data_jet="none", std::string truthfile="none", std::string truthjetfile="none", std::string calotowersfile="none", std::string truthrecofile="none", std::string globalrecofile="none", std::string n_evt="0", std::string minpt="1.0", const std::string& dbtag="ProdA_2024")
0052 {
0053     std::cout<<"actually processing this thing" <<std::endl;
0054     std::map<std::string, std::string> input_files {{data_dst, "data_calo_dst"}, {data_fitting_dst, "data_fitting"}, {data_trigger,/* "none",*/"data_trigger"}, {data_jet, "data_jet"}, {truthjetfile, "truthjet"}, {calotowersfile, "calotowers"}, {truthrecofile, "truthreco"}, {globalrecofile, "globalreco"}, {truthfile, "truth"}};
0055 
0056     Fun4AllServer* se=Fun4AllServer::instance();
0057     std::cout<<"Initiated the fun for all server" <<std::endl;
0058     int run_number=0, segment=0, n_evts=std::stoi(n_evt);
0059 //  std::string run_str="", segn_str="", substr="";
0060     bool data=true;
0061 
0062     se->Verbosity(0);
0063     if(data_dst.find("none") != std::string::npos) data=false;
0064     if(data){
0065         segment=Fun4AllUtils::GetRunSegment(data_dst).second;
0066     }
0067 
0068     for(auto f:input_files)
0069     {
0070         std::cout<<"working on the file for: " <<f.second <<std::endl;
0071         if(f.first.find("none") != std::string::npos) continue;
0072 
0073         /*if(f.second.find("data_trigger") != std::string::npos  || f.second.find("data_jet")!=std::string::npos){
0074             std::pair<std::string, std::string> calo_fitting_files=fix_calo_fitting_dst_names(segment, f.first); //issue with the most recent pass needs fixing, probably should pick up ana number but meh
0075             input_files[calo_fitting_files.first]="data_1_fitting";
0076             input_files[calo_fitting_files.second]="data_2_fitting";
0077             Fun4AllInputManager* inputfile1=new Fun4AllDstInputManager(Form("%s_1", f.second.c_str()));
0078             Fun4AllInputManager* inputfile2=new Fun4AllDstInputManager(Form("%s_2", f.second.c_str()));
0079             inputfile1->AddFile(calo_fitting_files.first    );
0080             inputfile2->AddFile(calo_fitting_files.second   );
0081             se->registerInputManager(inputfile1);
0082             se->registerInputManager(inputfile2);
0083             std::cout<<"Calo Fitting file 1: " <<calo_fitting_files.first   <<std::endl;
0084             std::cout<<"Calo Fitting file 2: " <<calo_fitting_files.second  <<std::endl;
0085             input_files.erase(f.first); 
0086             continue;
0087         }*/
0088         std::cout<<f.first<<std::endl;
0089         std::stringstream filename(f.first);
0090         if(run_number == 0){
0091             std::cout<<"trying to get the run number" <<f.first <<std::endl;
0092 
0093             std::pair<int, int> runseg=Fun4AllUtils::GetRunSegment(f.first);
0094             run_number=runseg.first;
0095             segment=runseg.second;
0096             std::cout<<"run " <<run_number <<" segement " <<segment <<std::endl;
0097         }
0098 /*          while(std::getline(filename, substr, '-')){
0099                 if(run_number==0){
0100                     run_str=substr;
0101                     try{ run_number=std::stoi(run_str);}
0102                     catch(std::exception& e){ run_number=-1;}
0103                 }
0104                 if(run_number > 0){
0105                     segn_str=substr;
0106                     try{ segment=std::stoi(segn_str);}
0107                     catch(std::exception& e){segment=-1;}
0108                 }
0109             }
0110             if( run_number <=0 || segment <= 0 ) 
0111             {
0112                 run_number = 0;
0113                 segment = 0;
0114             }
0115         }*/ //turns out there was a one line for this apparently
0116         try{
0117             Fun4AllInputManager* input_file = new Fun4AllDstInputManager(f.second);
0118             input_file->AddFile(f.first);
0119             se->registerInputManager(input_file); 
0120         }
0121         catch(std::exception& e){std::cout<<"Unable to load file " <<f.first <<std::endl;}
0122     }
0123 
0124     if(data){
0125         recoConsts *rc = recoConsts::instance();
0126         rc->set_StringFlag("CDB_GLOBALTAG", dbtag);
0127         rc->set_uint64Flag("TIMESTAMP", run_number);
0128         CDBInterface::instance() -> Verbosity(0);
0129         Process_Calo_Calib();
0130     }
0131     else{
0132         recoConsts *rc = recoConsts::instance();
0133         rc->set_StringFlag("CDB_GLOBALTAG", "MDC2");
0134         rc->set_uint64Flag("TIMESTAMP", run_number);
0135         CDBInterface::instance() -> Verbosity(0);
0136         Process_Calo_Calib();
0137     }
0138         
0139     bool nojets=true, retower_needed=true;
0140 /*  if(data){ //check if the jet objects have already been constructed and retowering needed
0141 
0142         TFile* f1=new TFile(data_dst.c_str(), "READ");
0143         if(f1->IsOpen())
0144         {
0145             TTree* T=(TTree*) f1->Get("T");
0146             auto brlist=T->GetListOfBranches();
0147 
0148             for(int b=0; b<(int) brlist->GetEntries(); b++)
0149             {
0150                 std::string branch_name (brlist[b].GetName());
0151                 std::transform(branch_name.begin(), branch_name.end(), branch_name.begin(), ::tolower);
0152                 if(branch_name.find("retower")!= std::string::npos) retower_needed=false;
0153                 if(branch_name.find("antikt")!= std::string::npos) nojets=false;
0154             }
0155         }   
0156     }
0157     if(data && retower_needed){
0158         RetowerCEMC* rtcemc=new RetowerCEMC("RetowerCEMC");
0159         rtcemc->Verbosity(0);
0160         rtcemc->set_towerinfo(true);
0161         rtcemc->set_frac_cut(0.5);
0162         se->registerSubsystem(rtcemc);
0163     }*/
0164 /*  if(data && nojets){ //if no jet objects, run fastjet
0165         JetReco* data_jets=new JetReco("TowerJetReco");
0166         data_jets->add_input(new TowerJetInput(Jet::CEMC_TOWERINFO_RETOWER));
0167         data_jets->add_input(new TowerJetInput(Jet::HCALIN_TOWERINFO));
0168         data_jets->add_input(new TowerJetInput(Jet::HCALOUT_TOWERINFO));
0169         data_jets->add_algo(new FastJetAlgo(Jet::ANTIKT, 0.4), "AntiKt_TowerInfo_r04");
0170 
0171         data_jets->set_algo_node("ANTIKT");
0172         data_jets->set_input_node("TOWER");
0173         data_jets->Verbosity(0);
0174         se->registerSubsystem(data_jets);
0175 
0176         }*/
0177 
0178     std::cout<<"Loaded all subparts in, now loading in the analysis code" <<std::endl;
0179 //  std::string text_out_filename="/gpfs/mnt/gpfs02/sphenix/user/sgross/sphenix_analysis/EnergyCorrelatorsJets/LargeRLCaloENC/Missing_pT_for_felix_run-"+std::to_string(run_number)+"-"+std::to_string(segment)+".csv";
0180     //std::fstream* ofs=new std::fstream(text_out_filename);
0181     LargeRLENC* rlenc=new LargeRLENC(run_number, segment, std::stof(minpt), data);
0182 
0183 //  LEDPedestalScan* sc=new LEDPedestalScan(run_number, segment, false, false);
0184     se->registerSubsystem(rlenc);
0185 //  se->registerSubsystem(sc);
0186 //  dummy* d=new dummy();
0187 //  se->registerSubsystem(d);
0188     std::cout<<"Runing for " <<n_evt <<" events" <<std::endl;
0189     se->run(n_evts);
0190 //  sc->Print();
0191 
0192     rlenc->Print();
0193     return 0;
0194 }
0195 #endif