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 <largerlenc/LargeRLENC.h>
0018 #include <jetbase/FastJetAlgo.h>
0019 #include <jetbase/JetReco.h>
0020 #include <jetbase/TowerJetInput.h>
0021 #include <jetbackground/RetowerCEMC.h>
0022 #include <phool/recoConsts.h>
0023 #include <TFile.h>
0024 #include <TTree.h>
0025 #include <fstream>
0026 
0027 R__LOAD_LIBRARY(libfun4all.so)
0028 R__LOAD_LIBRARY(libcalo_io.so)
0029 R__LOAD_LIBRARY(libffamodules.so)
0030 R__LOAD_LIBRARY(libLargeRLENC.so)
0031 R__LOAD_LIBRARY(libjetbase.so)
0032 R__LOAD_LIBRARY(libjetbackground.so)
0033 
0034 int RunLargeRLENC_test(std::string data_dst="none", std::string data_fitting_dst="none", std::string data_trigger="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")
0035 {
0036     std::cout<<"actually processing this thing" <<std::endl;
0037     std::map<std::string, std::string> input_files {{data_dst, "data"}, {data_fitting_dst, "data_fitting"}, {data_trigger, "data_trigger"}, {truthjetfile, "truthjet"}, {calotowersfile, "calotowers"}, {truthrecofile, "truthreco"}, {globalrecofile, "globalreco"}};
0038     Fun4AllServer* se=Fun4AllServer::instance();
0039     std::cout<<"Initiated the fun for all server" <<std::endl;
0040     int run_number=0, segment=0, n_evts=std::stoi(n_evt);
0041 //  std::string run_str="", segn_str="", substr="";
0042     bool data=true;
0043     if(data_dst.find("none") != std::string::npos) data=false;
0044     for(auto f:input_files)
0045     {
0046         std::cout<<"working on the file for: " <<f.second <<std::endl;
0047         if(f.first.find("none") != std::string::npos) continue;
0048         std::cout<<f.first<<std::endl;
0049         std::stringstream filename(f.first);
0050         if(run_number == 0){
0051             std::cout<<"trying to get the run number" <<f.first <<std::endl;
0052             std::pair<int, int> runseg=Fun4AllUtils::GetRunSegment(f.first);
0053             run_number=runseg.first;
0054             segment=runseg.second;
0055             std::cout<<"run " <<run_number <<" segement " <<segment <<std::endl;
0056         }
0057 /*          while(std::getline(filename, substr, '-')){
0058                 if(run_number==0){
0059                     run_str=substr;
0060                     try{ run_number=std::stoi(run_str);}
0061                     catch(std::exception& e){ run_number=-1;}
0062                 }
0063                 if(run_number > 0){
0064                     segn_str=substr;
0065                     try{ segment=std::stoi(segn_str);}
0066                     catch(std::exception& e){segment=-1;}
0067                 }
0068             }
0069             if( run_number <=0 || segment <= 0 ) 
0070             {
0071                 run_number = 0;
0072                 segment = 0;
0073             }
0074         }*/ //turns out there was a one line for this apparently
0075         try{
0076             Fun4AllInputManager* input_file = new Fun4AllDstInputManager(f.second);
0077             input_file->AddFile(f.first);
0078             se->registerInputManager(input_file); 
0079         }
0080         catch(std::exception& e){std::cout<<"Unable to load file " <<f.first <<std::endl;}
0081     }
0082     if(data){
0083         recoConsts *rc = recoConsts::instance();
0084         rc->set_StringFlag("CDB_GLOBALTAG", dbtag);
0085         rc->set_uint64Flag("TIMESTAMP", run_number);
0086         CDBInterface::instance() -> Verbosity(0);
0087         Process_Calo_Calib();
0088     }
0089     else{
0090         recoConsts *rc = recoConsts::instance();
0091         rc->set_StringFlag("CDB_GLOBALTAG", "MDC2");
0092         rc->set_uint64Flag("TIMESTAMP", run_number);
0093         CDBInterface::instance() -> Verbosity(0);
0094         Process_Calo_Calib();
0095     }
0096         
0097     bool nojets=true, retower_needed=true;
0098 //  if(data){ //check if the jet objects have already been constructed and retowering needed
0099 //      TFile* f1=new TFile(data_dst.c_str(), "READ");
0100 //      if(f1->IsOpen())
0101 //      {
0102 //          TTree* T=(TTree*) f1->Get("T");
0103 //          auto brlist=T->GetListOfBranches();
0104 //          for(int b=0; b<(int) brlist->GetEntries(); b++)
0105 //          {
0106 //              std::string branch_name (brlist[b].GetName());
0107 //              std::transform(branch_name.begin(), branch_name.end(), branch_name.begin(), ::tolower);
0108 //              if(branch_name.find("retower")!= std::string::npos) retower_needed=false;
0109 //              if(branch_name.find("antikt")!= std::string::npos) nojets=false;
0110 //          }
0111 //      }   
0112 //  }
0113 /*  if(data && retower_needed){
0114         RetowerCEMC* rtcemc=new RetowerCEMC("RetowerCEMC");
0115         rtcemc->Verbosity(0);
0116         rtcemc->set_towerinfo(true);
0117         rtcemc->set_frac_cut(0.5);
0118         se->registerSubsystem(rtcemc);
0119     }*/
0120     if(data && nojets){ //if no jet objects, run fastjet
0121         JetReco* data_jets=new JetReco("JetReco");
0122         data_jets->add_input(new TowerJetInput(Jet::CEMC_TOWERINFO_RETOWER));
0123         data_jets->add_input(new TowerJetInput(Jet::HCALIN_TOWERINFO));
0124         data_jets->add_input(new TowerJetInput(Jet::HCALOUT_TOWERINFO));
0125         data_jets->add_algo(new FastJetAlgo(Jet::ANTIKT, 0.4), "AntiKt_TowerInfo_r04");
0126         data_jets->set_algo_node("ANTIKT");
0127         data_jets->set_input_node("TOWER");
0128         data_jets->Verbosity(0);
0129         se->registerSubsystem(data_jets);
0130         //no background subtracting as these won't be used for real analysis, just to provide rough cuts
0131         }
0132     std::cout<<"Loaded all subparts in, now loading in the analysis code" <<std::endl;
0133 //  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";
0134     //std::fstream* ofs=new std::fstream(text_out_filename);
0135     LargeRLENC* rlenc=new LargeRLENC(run_number, segment, std::stof(minpt), data);
0136     se->registerSubsystem(rlenc);
0137     std::cout<<"Runing for " <<n_evt <<" events" <<std::endl;
0138     se->run(n_evts);
0139     rlenc->Print();
0140     return 0;
0141 }
0142 #endif