File indexing completed on 2025-12-16 09:23:59
0001 #ifndef MACRO_FUN4ALL_MBD_CALPASS_C
0002 #define MACRO_FUN4ALL_MBD_CALPASS_C
0003
0004 #include <globalvertex/GlobalVertexReco.h>
0005
0006 #include <mbd/MbdReco.h>
0007
0008 #include <ffamodules/CDBInterface.h>
0009 #include <ffamodules/FlagHandler.h>
0010 #include <ffamodules/HeadReco.h>
0011 #include <ffamodules/SyncReco.h>
0012
0013 #include <fun4all/Fun4AllServer.h>
0014 #include <fun4all/Fun4AllUtils.h>
0015 #include <fun4all/Fun4AllInputManager.h>
0016 #include <fun4all/Fun4AllDstInputManager.h>
0017 #include <fun4all/Fun4AllOutputManager.h>
0018 #include <fun4all/Fun4AllDstOutputManager.h>
0019
0020 #include <fun4allraw/Fun4AllPrdfInputManager.h>
0021 #include <fun4allraw/Fun4AllEventOutputManager.h>
0022
0023 #include <phool/recoConsts.h>
0024
0025
0026 #include <Rtypes.h> // defines R__LOAD_LIBRARY macro for clang-tidy
0027 #include <TString.h>
0028 #include <TSystem.h>
0029
0030 #include <fstream>
0031 R__LOAD_LIBRARY(libfun4all.so)
0032 R__LOAD_LIBRARY(libfun4allraw.so)
0033 R__LOAD_LIBRARY(libffamodules.so)
0034 R__LOAD_LIBRARY(libphool.so)
0035 R__LOAD_LIBRARY(libmbd.so)
0036 R__LOAD_LIBRARY(libglobalvertex.so)
0037
0038 void Fun4All_MBD_CalPass(const char *input = "/sphenix/user/pinkenbu/testprdf/beam-00002609-0000.prdf",
0039 const int calpass = 0, int nEvents = 0, const int nskip = 0, const std::string& cdbtag = "")
0040 {
0041
0042
0043
0044
0045 std::stringstream ss(input);
0046 std::vector<std::string> all_inputfnames;
0047 while ( ss.good() )
0048 {
0049 std::string temp;
0050 getline( ss, temp, ',' );
0051 all_inputfnames.push_back( temp );
0052 }
0053
0054
0055 std::string first_line = all_inputfnames[0];
0056 if ( first_line.ends_with(".list") )
0057 {
0058 std::ifstream listfile(all_inputfnames[0]);
0059 getline(listfile, first_line);
0060 listfile.close();
0061 }
0062
0063 std::pair<int, int> runseg = Fun4AllUtils::GetRunSegment(first_line);
0064 int runnumber = runseg.first;
0065 int segment = runseg.second;
0066 std::cout << "run number = " << runnumber << std::endl;
0067
0068 recoConsts *rc = recoConsts::instance();
0069 if ( !cdbtag.empty() )
0070 {
0071 std::cout << "Using cdb " << cdbtag << std::endl;
0072 rc->set_StringFlag("CDB_GLOBALTAG",cdbtag);
0073 }
0074 else
0075 {
0076 std::cout << "RUN\t" << runnumber << std::endl;
0077 rc->set_uint64Flag("TIMESTAMP", runnumber);
0078
0079
0080 TString bdir = "./results/";
0081 bdir += runnumber;
0082 std::cout << bdir << std::endl;
0083 rc->set_StringFlag("MBD_CALDIR",bdir.Data());
0084 }
0085
0086 if ( calpass==1 && nEvents<0 )
0087 {
0088
0089 nEvents = 30000;
0090 }
0091
0092 Fun4AllServer *se = Fun4AllServer::instance();
0093
0094
0095
0096 SyncReco *sync = new SyncReco();new Fun4AllPrdfInputManager("PRDFin");
0097 se->registerSubsystem(sync);
0098
0099 HeadReco *head = new HeadReco();
0100 se->registerSubsystem(head);
0101
0102 FlagHandler *flag = new FlagHandler();
0103 se->registerSubsystem(flag);
0104
0105
0106 MbdReco *mbdreco = new MbdReco();
0107 mbdreco->SetCalPass(calpass);
0108 se->registerSubsystem(mbdreco);
0109
0110
0111
0112
0113
0114 std::vector<Fun4AllInputManager *> in;
0115
0116 if ( all_inputfnames[0].ends_with(".prdf") )
0117 {
0118 for ( const auto& inputfname : all_inputfnames )
0119 {
0120 Fun4AllPrdfInputManager *inputman = new Fun4AllPrdfInputManager("PRDFin");
0121 inputman->fileopen( inputfname );
0122 in.push_back( inputman );
0123 se->registerInputManager( inputman );
0124 }
0125 }
0126 else if ( all_inputfnames[0].ends_with(".root") )
0127 {
0128 for ( const auto& inputfname : all_inputfnames )
0129 {
0130 Fun4AllDstInputManager *inputman = new Fun4AllDstInputManager("DST");
0131 inputman->AddFile( inputfname );
0132 in.push_back( inputman );
0133 se->registerInputManager( inputman );
0134 }
0135 }
0136 else if ( all_inputfnames[0].ends_with(".list") )
0137 {
0138 for ( const auto& inputfname : all_inputfnames )
0139 {
0140 std::cout << "adding " << inputfname << std::endl;
0141 Fun4AllDstInputManager *inputman = new Fun4AllDstInputManager("DST");
0142 inputman->AddListFile( inputfname );
0143 in.push_back( inputman );
0144 se->registerInputManager( inputman );
0145 }
0146 }
0147
0148 if ( calpass == 2 )
0149 {
0150 TString outfile = "DST_UNCALMBD-";
0151 outfile += Form("%08d-%04d",runnumber,segment);
0152 outfile += ".root";
0153 std::cout << outfile << std::endl;
0154 Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", outfile.Data());
0155 out->StripNode("CEMCPackets");
0156 out->StripNode("HCALPackets");
0157 out->StripNode("ZDCPackets");
0158 out->StripNode("SEPDPackets");
0159 out->StripNode("MBDPackets");
0160 out->StripNode("TOWERS_ZDC");
0161 out->StripNode("TOWERS_SEPD");
0162 out->StripNode("TOWERS_CEMC");
0163 out->StripNode("TOWERS_HCALIN");
0164 out->StripNode("TOWERS_HCALOUT");
0165 se->registerOutputManager(out);
0166 }
0167
0168 se->skip(nskip);
0169 se->run(nEvents);
0170
0171 se->End();
0172 delete se;
0173 gSystem->Exit(0);
0174
0175 std::cout << "Finished" << std::endl;
0176 }
0177
0178 #endif
0179