Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-05-23 08:15:38

0001 #ifndef MACRO_FUN4ALL_MBDCALRECO_C
0002 #define MACRO_FUN4ALL_MBDCALRECO_C
0003 
0004 #include <globalvertex/GlobalVertexReco.h>
0005 
0006 #include <mbd/MbdReco.h>
0007 #include <mbd/MbdCalibReco.h>
0008 
0009 #include <ffamodules/CDBInterface.h>
0010 #include <ffamodules/FlagHandler.h>
0011 #include <ffamodules/HeadReco.h>
0012 #include <ffamodules/SyncReco.h>
0013 
0014 #include <fun4all/Fun4AllServer.h>
0015 #include <fun4all/Fun4AllUtils.h>
0016 #include <fun4all/Fun4AllInputManager.h>
0017 #include <fun4all/Fun4AllDstInputManager.h>
0018 #include <fun4all/Fun4AllOutputManager.h>
0019 #include <fun4all/Fun4AllDstOutputManager.h>
0020 
0021 #include <fun4allraw/Fun4AllPrdfInputManager.h>
0022 #include <fun4allraw/Fun4AllEventOutputManager.h>
0023 
0024 #include <phool/recoConsts.h>
0025 
0026 
0027 #include <Rtypes.h> // defines R__LOAD_LIBRARY macro for clang-tidy
0028 #include <TString.h>
0029 #include <TSystem.h>
0030 
0031 #include <fstream>
0032 R__LOAD_LIBRARY(libfun4all.so)
0033 R__LOAD_LIBRARY(libfun4allraw.so)
0034 R__LOAD_LIBRARY(libffamodules.so)
0035 R__LOAD_LIBRARY(libphool.so)
0036 R__LOAD_LIBRARY(libmbd.so)
0037 R__LOAD_LIBRARY(libcalotrigger_io.so)
0038 R__LOAD_LIBRARY(libglobalvertex.so)
0039 
0040 void Fun4All_MbdCalReco(const char *input = "DST_CALOFITTING_run3oo_pro001_pcdb001_v001-00082525-00000.root",
0041     const int subpass = 0, int nEvents = 0, const std::string& cdbtag = "")
0042 {
0043   // process the input
0044   // it could be a single prdf, dst, or listfile
0045   // or it could be a comma separated string of prdf, dst, or listfiles
0046 
0047   std::stringstream ss(input);
0048   std::vector<std::string> all_inputfnames;
0049   while ( ss.good() )
0050   {
0051     std::string temp;
0052     getline( ss, temp, ',' );
0053     all_inputfnames.push_back( temp );
0054   }
0055 
0056   // Get dst or prdf filename to extract runnumber
0057   std::string first_line = all_inputfnames[0];
0058   if ( first_line.ends_with(".list") )
0059   {
0060     std::ifstream listfile(all_inputfnames[0]);
0061     getline(listfile, first_line);
0062     listfile.close();
0063   }
0064 
0065   std::pair<int, int> runseg = Fun4AllUtils::GetRunSegment(first_line);
0066   int runnumber = runseg.first;
0067 //  int segment = runseg.second;
0068   std::cout << "run number = " << runnumber << std::endl;
0069 
0070   recoConsts *rc = recoConsts::instance();
0071   if ( !cdbtag.empty() )
0072   {
0073     std::cout << "Using cdb " << cdbtag << std::endl;
0074     rc->set_StringFlag("CDB_GLOBALTAG",cdbtag);
0075   }
0076   else
0077   {
0078     std::cout << "RUN\t" << runnumber << std::endl;
0079     rc->set_uint64Flag("TIMESTAMP", runnumber);
0080 
0081     // For local calibrations
0082     TString bdir = "./results/";
0083     bdir += runnumber;
0084     std::cout << bdir << std::endl;
0085     rc->set_StringFlag("MBD_CALDIR",bdir.Data()); 
0086   }
0087 
0088   if ( subpass==1 && nEvents<0 )
0089   {
0090     //nEvents = 100000; // for p+p
0091     nEvents = 30000;  // for Au+Au
0092   }
0093 
0094   Fun4AllServer *se = Fun4AllServer::instance();
0095   //se->Verbosity(1);
0096 
0097   // MBD Reco
0098   MbdReco *mbdreco = new MbdReco();
0099   mbdreco->SetCalPass(2);
0100   se->registerSubsystem(mbdreco);
0101 
0102   // MBD Calib
0103   MbdCalibReco *mbdcalreco = new MbdCalibReco();
0104   mbdcalreco->SetSubPass(subpass);
0105   se->registerSubsystem(mbdcalreco);
0106 
0107   // Official vertex storage
0108   //GlobalVertexReco *gvertex = new GlobalVertexReco();
0109   //se->registerSubsystem(gvertex);
0110 
0111   std::vector<Fun4AllInputManager *> in;
0112 
0113   if ( all_inputfnames[0].ends_with(".prdf") )
0114   {
0115     for ( const auto& inputfname : all_inputfnames )
0116     {
0117       Fun4AllPrdfInputManager *inputman = new Fun4AllPrdfInputManager("PRDFin");
0118       inputman->fileopen( inputfname );
0119       in.push_back( inputman );
0120       se->registerInputManager( inputman );
0121     }
0122   }
0123   else if ( all_inputfnames[0].ends_with(".root") )
0124   {
0125     for ( const auto& inputfname : all_inputfnames )
0126     {
0127       Fun4AllDstInputManager *inputman = new Fun4AllDstInputManager("DST");
0128       inputman->AddFile( inputfname );
0129       in.push_back( inputman );
0130       se->registerInputManager( inputman );
0131     }
0132   }
0133   else if ( all_inputfnames[0].ends_with(".list") )
0134   {
0135     for ( const auto& inputfname : all_inputfnames )
0136     {
0137       std::cout << "adding " << inputfname << std::endl;
0138       Fun4AllDstInputManager *inputman = new Fun4AllDstInputManager("DST");
0139       inputman->AddListFile( inputfname );
0140       in.push_back( inputman );
0141       se->registerInputManager( inputman );
0142     }
0143   }
0144 
0145   se->run(nEvents);
0146 
0147   se->End();
0148   delete se;
0149   gSystem->Exit(0);
0150 
0151   std::cout << "Finished" << std::endl;
0152 }
0153 
0154 #endif
0155