Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:22

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