Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:24:06

0001 #ifndef FUN4ALL_PREPDATAFITTING_C
0002 #define FUN4ALL_PREPDATAFITTING_C
0003 
0004 #include <Calo_Fitting.C>
0005 #include <QA.C>
0006 
0007 #include <calotrigger/TriggerRunInfoReco.h>
0008 
0009 #include <calovalid/CaloFittingQA.h>
0010 
0011 #include <mbd/MbdReco.h>
0012 
0013 #include <globalvertex/GlobalVertexReco.h>
0014 
0015 #include <ffamodules/CDBInterface.h>
0016 #include <ffamodules/FlagHandler.h>
0017 #include <ffamodules/HeadReco.h>
0018 #include <ffamodules/SyncReco.h>
0019 
0020 #include <fun4all/Fun4AllDstInputManager.h>
0021 #include <fun4all/Fun4AllDstOutputManager.h>
0022 #include <fun4all/Fun4AllInputManager.h>
0023 #include <fun4all/Fun4AllRunNodeInputManager.h>
0024 #include <fun4all/Fun4AllServer.h>
0025 #include <fun4all/Fun4AllUtils.h>
0026 #include <fun4all/SubsysReco.h>
0027 
0028 #include <phool/recoConsts.h>
0029 
0030 #include <Rtypes.h> // for R__LOAD_LIBRARY
0031 #include <TSystem.h>
0032 
0033 #include <format>
0034 #include <fstream>
0035 
0036 R__LOAD_LIBRARY(libfun4allraw.so)
0037 R__LOAD_LIBRARY(libcalovalid.so)
0038 R__LOAD_LIBRARY(libcalotrigger.so)
0039 
0040 // this pass containis the reco process that's stable wrt time stamps(raw tower building)
0041 void Fun4All_PrepDataFitting(int nEvents = 1e4,
0042                const std::string& inlist = "test.list",
0043                            const std::string &outfile = "DST_CALOFITTING",
0044                            const std::string &outfile_hist = "HIST_CALOFITTINGQA",
0045                            const std::string &dbtag = "ProdA_2024")
0046 {
0047   gSystem->Load("libg4dst.so");
0048 
0049   Fun4AllServer *se = Fun4AllServer::instance();
0050   se->Verbosity(0);
0051   se->VerbosityDownscale(1000);
0052 
0053   recoConsts *rc = recoConsts::instance();
0054 
0055   // conditions DB global tag
0056   rc->set_StringFlag("CDB_GLOBALTAG", dbtag);
0057   CDBInterface::instance()->Verbosity(1);
0058 
0059   FlagHandler *flag = new FlagHandler();
0060   se->registerSubsystem(flag);
0061 
0062   // Get info from DB and store in DSTs
0063   TriggerRunInfoReco *triggerinfo = new TriggerRunInfoReco();
0064   se->registerSubsystem(triggerinfo);
0065 
0066   // MBD/BBC Reconstruction
0067   MbdReco *mbdreco = new MbdReco();
0068   se->registerSubsystem(mbdreco);
0069 
0070   // Official vertex storage
0071   GlobalVertexReco *gvertex = new GlobalVertexReco();
0072   se->registerSubsystem(gvertex);
0073 
0074   Process_Calo_Fitting();
0075 
0076   ///////////////////////////////////
0077   // Validation
0078   CaloFittingQA *ca = new CaloFittingQA("CaloFittingQA");
0079   se->registerSubsystem(ca);
0080 
0081 // loop over all files in file list and create an input manager for each one  
0082   Fun4AllInputManager *In = nullptr;
0083   std::ifstream infile;
0084   infile.open(inlist);
0085   int iman = 0;
0086   std::string line;
0087   bool first {true};
0088   int runnumber = 0;
0089   int segment = 99999;
0090   if (infile.is_open())
0091   {
0092     while (std::getline(infile, line))
0093     {
0094       if (line[0] == '#')
0095       {
0096     std::cout << "found commented out line " << line << std::endl;
0097     continue;
0098       }
0099       // extract run number from first not commented out file in list
0100       if (first)
0101       {
0102     std::pair<int, int> runseg = Fun4AllUtils::GetRunSegment(line);
0103     runnumber = runseg.first;
0104     segment = runseg.second;
0105     rc->set_uint64Flag("TIMESTAMP", runnumber);
0106     first = false;
0107       }
0108       std::string magname = "DSTin_" + std::to_string(iman);
0109       In = new Fun4AllDstInputManager(magname);
0110       In->Verbosity(1);
0111       In->AddFile(line);
0112       se->registerInputManager(In);
0113       iman++;
0114     }
0115     infile.close();
0116   }
0117   
0118 // this strips all nodes under the Packets PHCompositeNode
0119 // (means removes all offline packets)
0120   std::string dstoutfile = std::format("{}-{:08}-{:05}.root",outfile, runnumber,segment);
0121   Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", dstoutfile);
0122   out->StripCompositeNode("Packets");
0123   se->registerOutputManager(out);
0124   // se->Print();
0125   if (nEvents < 0)
0126   {
0127     return;
0128   }
0129   se->run(nEvents);
0130   se->End();
0131   dstoutfile = std::format("{}-{:08}-{:05}.root",outfile_hist, runnumber,segment);
0132   QAHistManagerDef::saveQARootFile(dstoutfile);
0133 
0134   CDBInterface::instance()->Print();  // print used DB files
0135   se->PrintTimer();
0136   delete se;
0137   std::cout << "All done!" << std::endl;
0138   gSystem->Exit(0);
0139 }
0140 #endif