Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #ifndef MACRO_FUN4ALLG4EMBED_C
0002 #define MACRO_FUN4ALLG4EMBED_C
0003 
0004 #include <GlobalVariables.C>
0005 
0006 #include "G4Setup_sPHENIX.C"
0007 #include <G4_Input.C>
0008 #include <G4_Production.C>
0009 #include <globalvertex/GlobalVertexReco.h>
0010 
0011 #include <phpythia8/PHPy8JetTrigger.h>
0012 #include <caloembedding/HepMCCollisionVertex.h>
0013 #include <caloembedding/caloTowerEmbed.h>
0014 #include <caloembedding/CopyIODataNodes.h>
0015 
0016 #include <jetbase/JetReco.h>
0017 #include <jetbase/TowerJetInput.h>
0018 #include <jetbase/FastJetAlgo.h>
0019 
0020 #include <jetbackground/FastJetAlgoSub.h>
0021 #include <jetbackground/RetowerCEMC.h>
0022 
0023 #include <g4jets/TruthJetInput.h>
0024 
0025 #include <centrality/CentralityInfov2.h>
0026 #include <calotrigger/MinimumBiasInfov1.h>
0027 
0028 #include <ffamodules/CDBInterface.h>
0029 #include <ffamodules/FlagHandler.h>
0030 #include <ffamodules/SyncReco.h>
0031 
0032 #include <fun4all/Fun4AllDstOutputManager.h>
0033 #include <fun4all/Fun4AllOutputManager.h>
0034 #include <fun4all/Fun4AllServer.h>
0035 #include <fun4all/Fun4AllSyncManager.h>
0036 #include <fun4all/Fun4AllRunNodeInputManager.h>
0037 #include <fun4all/Fun4AllUtils.h>
0038 
0039 #include <phool/PHRandomSeed.h>
0040 #include <phool/recoConsts.h>
0041 
0042 #include <TRandom3.h>
0043 
0044 R__LOAD_LIBRARY(libfun4all.so)
0045 R__LOAD_LIBRARY(libffamodules.so)
0046 R__LOAD_LIBRARY(libCaloEmbedding.so)
0047 R__LOAD_LIBRARY(libglobalvertex.so)
0048 R__LOAD_LIBRARY(libcentrality.so)
0049 R__LOAD_LIBRARY(libcalotrigger.so)
0050 R__LOAD_LIBRARY(libjetbase.so)
0051 R__LOAD_LIBRARY(libjetbackground.so)
0052 R__LOAD_LIBRARY(libg4jets.so)
0053 // R__LOAD_LIBRARY(libg4dst.so)
0054 //  For HepMC Hijing
0055 //  try inputFile = /sphenix/sim/sim01/sphnxpro/sHijing_HepMC/sHijing_0-12fm.dat
0056 
0057 // namespace OUTPUTMANAGER
0058 //{
0059 // set<std::string> outfiles;
0060 // }
0061 
0062 void AddCommonNodes(Fun4AllOutputManager *out);
0063 
0064 int Fun4All_G4_Embed_data(
0065     const int nEvents = 1000,
0066     const int segment = 00000,
0067     const std::string &embed_input_file0 = "/sphenix/u/bseidlitz/work/devMac/macros/CaloProduction/condor/test.root",
0068     const std::string &outdir = "./",
0069     const std::string &outnameEnd = "embed_test.root",
0070     const std::string &jettrigger = "Jet30",
0071     const std::string &cdbtag = "MDC2")
0072 {
0073 
0074   std::cout << "segment: " << segment << std::endl;
0075 
0076   gSystem->Load("libg4dst.so");
0077 
0078   Fun4AllServer *se = Fun4AllServer::instance();
0079   se->Verbosity(1);
0080 
0081   int verbosity = 0;
0082 
0083   // Opt to print all random seed used for debugging reproducibility. Comment out to reduce stdout prints.
0084   PHRandomSeed::Verbosity(1);
0085 
0086   // just if we set some flags somewhere in this macro
0087   recoConsts *rc = recoConsts::instance();
0088   // By default every random number generator uses
0089   // PHRandomSeed() which reads /dev/urandom to get its seed
0090   // if the RANDOMSEED flag is set its value is taken as seed
0091   // You can either set this to a random value using PHRandomSeed()
0092   // which will make all seeds identical (not sure what the point of
0093   // this would be:
0094   //  rc->set_IntFlag("RANDOMSEED",PHRandomSeed());
0095   // or set it to a fixed value so you can debug your code
0096   //  rc->set_IntFlag("RANDOMSEED", 12345);
0097 
0098   //===============
0099   // conditions DB flags
0100   //===============
0101   Enable::CDB = true;
0102   // tag
0103   rc->set_StringFlag("CDB_GLOBALTAG", cdbtag);
0104   // 64 bit timestamp
0105   rc->set_uint64Flag("TIMESTAMP", CDB::timestamp);
0106 
0107   //  pair<int, int> runseg = Fun4AllUtils::GetRunSegment(embed_input_file0);
0108   // int runnumber = runseg.first;
0109   // int segment = runseg.second;
0110   int runnumber = 54912;
0111   if (runnumber != 0)
0112   {
0113     rc->set_IntFlag("RUNNUMBER", runnumber);
0114     Fun4AllSyncManager *syncman = se->getSyncManager();
0115     syncman->SegmentNumber(segment);
0116   }
0117 
0118   // Sync Headers and Flags
0119   SyncReco *sync = new SyncReco();
0120   se->registerSubsystem(sync);
0121 
0122   //  G4CEMC::useTowerInfoV2 = false;
0123   //  G4HCALOUT::useTowerInfoV2 = false;
0124   //  G4HCALIN::useTowerInfoV2 = false;
0125 
0126   //  G4CEMC::useTowerInfoV4 = true;
0127   // G4HCALOUT::useTowerInfoV4 = true;
0128   // G4HCALIN::useTowerInfoV4 = true;
0129 
0130   //===============
0131   // Input options
0132   //===============
0133   // verbosity setting (applies to all input managers)
0134   Input::VERBOSITY = 0;
0135   // First enable the input generators
0136   // Either:
0137   // read previously generated g4-hits files, in this case it opens a DST and skips
0138   // the simulations step completely. The G4Setup macro is only loaded to get information
0139   // about the number of layers used for the cell reco code
0140   //  Input::READHITS = true;
0141   // INPUTREADHITS::filename[0] = inputFile;
0142   // if you use a filelist
0143   // INPUTREADHITS::listfile[0] = inputFile;
0144   // Or:
0145   // Use particle generator
0146   // And
0147   // Further choose to embed newly simulated events to a previous simulation. Not compatible with `readhits = true`
0148   // In case embedding into a production output, please double check your G4Setup_sPHENIX.C and G4_*.C consistent with those in the production macro folder
0149   // E.g. /sphenix/sim//sim01/production/2016-07-21/single_particle/spacal2d/
0150 
0151   Input::EMBED = true;
0152   INPUTEMBED::filename[0] = embed_input_file0;
0153   // no repeating of embedding background, stop processing when end of file reached
0154   INPUTEMBED::REPEAT = false;
0155 
0156   // if you use a filelist
0157   // INPUTEMBED::listfile[0] = embed_input_file;
0158 
0159   // Input::SIMPLE = true;
0160   // Input::SIMPLE_NUMBER = 2; // if you need 2 of them
0161   // Input::SIMPLE_VERBOSITY = 1;
0162 
0163   //  Input::PYTHIA6 = true;
0164   // Enable this is emulating the nominal pp/pA/AA collision vertex distribution
0165   Input::BEAM_CONFIGURATION = Input::AA_COLLISION; // for 2023 sims we want the AA geometry for no pileup sims
0166 
0167   Input::PYTHIA8 = true;
0168   if (Input::PYTHIA8)
0169   {
0170     std::string pythia8_config_file = std::string(getenv("CALIBRATIONROOT")) + "/Generators/JetStructure_TG/";
0171     std::cout << "pythia config path: " << pythia8_config_file << std::endl;
0172     if (jettrigger == "Jet10")
0173     {
0174       pythia8_config_file += "phpythia8_15GeV_JS_MDC2.cfg";
0175     }
0176     else if (jettrigger == "Jet30")
0177     {
0178       pythia8_config_file += "phpythia8_30GeV_JS_MDC2.cfg";
0179     }
0180     else if (jettrigger == "Jet40")
0181     {
0182       pythia8_config_file += "phpythia8_40GeV_JS_MDC2.cfg";
0183     }
0184     else if (jettrigger == "PhotonJet")
0185     {
0186       pythia8_config_file += "phpythia8_JS_GJ_MDC2.cfg";
0187     }
0188     else
0189     {
0190       std::cout << "invalid jettrigger: " << jettrigger << std::endl;
0191       gSystem->Exit(1);
0192     }
0193     PYTHIA8::config_file = pythia8_config_file;
0194   }
0195 
0196   //-----------------
0197   // Initialize the selected Input/Event generation
0198   //-----------------
0199   InputInit();
0200 
0201   //--------------
0202   // Set generator specific options
0203   //--------------
0204   // can only be set after InputInit() is called
0205 
0206   if (Input::PYTHIA8)
0207   {
0208     //! apply sPHENIX nominal beam parameter with 2mrad crossing as defined in sPH-TRG-2020-001
0209     PHPy8JetTrigger *p8_js_signal_trigger = new PHPy8JetTrigger();
0210     p8_js_signal_trigger->SetEtaHighLow(1.5, -1.5); // Set eta acceptance for particles into the jet between +/- 1.5
0211     p8_js_signal_trigger->SetJetR(0.4);             // Set the radius for the trigger jet
0212     if (jettrigger == "Jet10")
0213     {
0214       p8_js_signal_trigger->SetMinJetPt(10); // require a 10 GeV minimum pT jet in the event
0215     }
0216     else if (jettrigger == "Jet30")
0217     {
0218       p8_js_signal_trigger->SetMinJetPt(30); // require a 30 GeV minimum pT jet in the event
0219     }
0220     else if (jettrigger == "Jet40")
0221     {
0222       p8_js_signal_trigger->SetMinJetPt(40); // require a 40 GeV minimum pT jet in the event
0223     }
0224     else if (jettrigger == "PhotonJet")
0225     {
0226       delete p8_js_signal_trigger;
0227       p8_js_signal_trigger = nullptr;
0228       std::cout << "no cut for PhotonJet" << std::endl;
0229     }
0230     else
0231     {
0232       std::cout << "invalid jettrigger: " << jettrigger << std::endl;
0233       gSystem->Exit(1);
0234     }
0235     if (p8_js_signal_trigger)
0236     {
0237       INPUTGENERATOR::Pythia8->register_trigger(p8_js_signal_trigger);
0238       INPUTGENERATOR::Pythia8->set_trigger_AND();
0239     }
0240     Input::ApplysPHENIXBeamParameter(INPUTGENERATOR::Pythia8);
0241   }
0242 
0243   //--------------
0244   // Set Input Manager specific options
0245   //--------------
0246   // can only be set after InputInit() is called
0247 
0248   // register all input generators with Fun4All
0249 
0250   std::string DataTopNode = "TOPData";
0251   /*
0252   EventSelector *EventSelectorHandler = new EventSelector();
0253   EventSelectorHandler->Verbosity( 1 );
0254   auto mbc = new MinBiasCut( );
0255   mbc->SetNodeName("MinimumBiasInfo");
0256   EventSelectorHandler->AddCut(mbc);
0257 
0258   auto tcc = new TowerChi2Cut( );
0259   std::vector<std::string> TowerChi2Nodes = {
0260     "TOWERINFO_CALIB_CEMC",
0261     "TOWERINFO_CALIB_HCALIN",
0262     "TOWERINFO_CALIB_HCALOUT"
0263   };
0264   tcc->SetNodeNames(TowerChi2Nodes);
0265   EventSelectorHandler->AddCut( tcc );
0266 
0267   auto zvc =  new ZVertexCut( 20, -20 );
0268   zvc->SetNodeName( "GlobalVertexMap" );
0269   EventSelectorHandler->AddCut( zvc );
0270 
0271   EventSelectorHandler->PrintCuts();
0272   se->registerSubsystem( EventSelectorHandler, DataTopNode);
0273 
0274   */
0275 
0276   HepMCCollisionVertex *collvtx = new HepMCCollisionVertex();
0277   collvtx->Verbosity(0);
0278   se->registerSubsystem(collvtx);
0279 
0280   InputRegister();
0281 
0282   FlagHandler *flag = new FlagHandler();
0283   se->registerSubsystem(flag);
0284 
0285   // set up production relatedstuff
0286   Enable::PRODUCTION = true;
0287 
0288   //======================
0289   // Write the DST
0290   //======================
0291 
0292   Enable::DSTOUT = true;
0293   Enable::DSTOUT_COMPRESS = false;
0294   DstOut::OutputDir = outdir;
0295 
0296   if (Enable::PRODUCTION)
0297   {
0298     PRODUCTION::SaveOutputDir = DstOut::OutputDir;
0299     //    Production_CreateOutputDir();
0300   }
0301 
0302 
0303   //-----------------
0304   // Copy over RunHeader, EventHeader, centrality, globalvertex, and MinimumBiasInfo nodes
0305   //-----------------
0306   CopyIODataNodes *cp = new CopyIODataNodes();
0307   cp->Verbosity(0);
0308   se->registerSubsystem(cp, DataTopNode);
0309 
0310   //======================
0311   // What to run
0312   //======================
0313 
0314   // Global options (enabled for all enables subsystems - if implemented)
0315   //  Enable::ABSORBER = true;
0316   //  Enable::OVERLAPCHECK = true;
0317   //  Enable::VERBOSITY = 1;
0318 
0319   Enable::MBD = true;
0320 
0321   // Enable::PIPE = true;
0322 
0323   // central tracking
0324   // Enable::MVTX = true;
0325 
0326   // Enable::INTT = true;
0327 
0328   // Enable::TPC = true;
0329 
0330   // Enable::MICROMEGAS = true;
0331 
0332   Enable::CEMC = true;
0333   // Enable::CEMC_ABSORBER = true;
0334   // Enable::CEMC_CELL = Enable::CEMC && true;
0335   // Enable::CEMC_TOWER = Enable::CEMC_CELL && true;
0336 
0337   Enable::HCALIN = true;
0338   // Enable::HCALIN_ABSORBER = true;
0339   // Enable::HCALIN_CELL = Enable::HCALIN && true;
0340   // Enable::HCALIN_TOWER = Enable::HCALIN_CELL && true;
0341 
0342   Enable::MAGNET = true;
0343   // Enable::MAGNET_ABSORBER = true;
0344 
0345   Enable::HCALOUT = true;
0346   // Enable::HCALOUT_ABSORBER = true;
0347   // Enable::HCALOUT_CELL = Enable::HCALOUT && true;
0348   // Enable::HCALOUT_TOWER = Enable::HCALOUT_CELL && true;
0349 
0350   Enable::EPD = true;
0351 
0352   // new settings using Enable namespace in GlobalVariables.C
0353   Enable::BLACKHOLE = true;
0354   Enable::BLACKHOLE_FORWARD_SAVEHITS = false; // disable forward/backward hits
0355   // Enable::BLACKHOLE_SAVEHITS = false; // turn off saving of bh hits
0356   // BlackHoleGeometry::visible = true;
0357 
0358   G4MAGNET::magfield = "FIELDMAP_GAP";
0359   G4MAGNET::magfield_OHCAL_steel = "FIELDMAP_STEEL";
0360   G4MAGNET::magfield_tracking = "FIELDMAP_TRACKING";
0361 
0362   // G4MAGNET::magfield = "/cvmfs/sphenix.sdcc.bnl.gov/calibrations/sphnxpro/cdb/FIELDMAP_GAP/65/a9/65a930ed6de9c0e049cd0f3ef226e6b4_sphenix3dbigmapxyz_gap_rebuild_v2.root";
0363   // G4MAGNET::magfield_OHCAL_steel = "/cvmfs/sphenix.sdcc.bnl.gov/calibrations/sphnxpro/cdb/FIELDMAP_STEEL/ea/f0/eaf07c2a2def280428b9aeea99d14fd1_sphenix3dbigmapxyz_steel_rebuild_v2.root";
0364   // G4MAGNET::magfield_tracking = "/cvmfs/sphenix.sdcc.bnl.gov/calibrations/sphnxpro/cdb/FIELDMAP_TRACKING/8e/4d/8e4d6c3b1660540a658da3a275af2bde_sphenix3dtrackingmapxyz.root";
0365 
0366   // Initialize the selected subsystems
0367   G4Init();
0368 
0369   //---------------------
0370   // GEANT4 Detector description
0371   //---------------------
0372   if (!Input::READHITS)
0373   {
0374     G4Setup();
0375   }
0376 
0377   //--------------------
0378   // GEANT4 Calorimeters
0379   //--------------------
0380 
0381   if (Enable::CEMC_CELL)
0382     CEMC_Cells();
0383 
0384   if (Enable::HCALIN_CELL)
0385     HCALInner_Cells();
0386 
0387   if (Enable::HCALOUT_CELL)
0388     HCALOuter_Cells();
0389 
0390   if (Enable::CEMC_TOWER)
0391     CEMC_Towers();
0392 
0393   if (Enable::HCALIN_TOWER)
0394     HCALInner_Towers();
0395 
0396   if (Enable::HCALOUT_TOWER)
0397     HCALOuter_Towers();
0398 
0399   //truth jets
0400   JetReco *truthjets2 = new JetReco("TRUTHJETRECO2");
0401   truthjets2->add_input(new TruthJetInput(Jet::PARTICLE));
0402   truthjets2->add_algo(new FastJetAlgo(Jet::ANTIKT, 0.2), "AntiKt_Truth_r02");
0403   truthjets2->set_algo_node("ANTIKT");
0404   truthjets2->set_input_node("TRUTH");
0405   truthjets2->Verbosity(verbosity);
0406   se->registerSubsystem(truthjets2);
0407 
0408   JetReco *truthjets3 = new JetReco("TRUTHJETRECO3");
0409   truthjets3->add_input(new TruthJetInput(Jet::PARTICLE));
0410   truthjets3->add_algo(new FastJetAlgo(Jet::ANTIKT, 0.3), "AntiKt_Truth_r03");
0411   truthjets3->set_algo_node("ANTIKT");
0412   truthjets3->set_input_node("TRUTH");
0413   truthjets3->Verbosity(verbosity);
0414   se->registerSubsystem(truthjets3);
0415 
0416   JetReco *truthjets4 = new JetReco("TRUTHJETRECO4");
0417   truthjets4->add_input(new TruthJetInput(Jet::PARTICLE));
0418   truthjets4->add_algo(new FastJetAlgo(Jet::ANTIKT, 0.4), "AntiKt_Truth_r04");
0419   truthjets4->set_algo_node("ANTIKT");
0420   truthjets4->set_input_node("TRUTH");
0421   truthjets4->Verbosity(verbosity);
0422   se->registerSubsystem(truthjets4);
0423 
0424   JetReco *truthjets5 = new JetReco("TRUTHJETRECO5");
0425   truthjets5->add_input(new TruthJetInput(Jet::PARTICLE));
0426   truthjets5->add_algo(new FastJetAlgo(Jet::ANTIKT, 0.5), "AntiKt_Truth_r05");
0427   truthjets5->set_algo_node("ANTIKT");
0428   truthjets5->set_input_node("TRUTH");
0429   truthjets5->Verbosity(verbosity);
0430   se->registerSubsystem(truthjets5);
0431 
0432   JetReco *truthjets6 = new JetReco("TRUTHJETRECO6");
0433   truthjets6->add_input(new TruthJetInput(Jet::PARTICLE));
0434   truthjets6->add_algo(new FastJetAlgo(Jet::ANTIKT, 0.6), "AntiKt_Truth_r06");
0435   truthjets6->set_algo_node("ANTIKT");
0436   truthjets6->set_input_node("TRUTH");
0437   truthjets6->Verbosity(verbosity);
0438   se->registerSubsystem(truthjets6);
0439 
0440   JetReco *truthjets7 = new JetReco("TRUTHJETRECO7");
0441   truthjets7->add_input(new TruthJetInput(Jet::PARTICLE));
0442   truthjets7->add_algo(new FastJetAlgo(Jet::ANTIKT, 0.7), "AntiKt_Truth_r07");
0443   truthjets7->set_algo_node("ANTIKT");
0444   truthjets7->set_input_node("TRUTH");
0445   truthjets7->Verbosity(verbosity);
0446   se->registerSubsystem(truthjets7);
0447 
0448   JetReco *truthjets8 = new JetReco("TRUTHJETRECO8");
0449   truthjets8->add_input(new TruthJetInput(Jet::PARTICLE));
0450   truthjets8->add_algo(new FastJetAlgo(Jet::ANTIKT, 0.8), "AntiKt_Truth_r08");
0451   truthjets8->set_algo_node("ANTIKT");
0452   truthjets8->set_input_node("TRUTH");
0453   truthjets8->Verbosity(verbosity);
0454   se->registerSubsystem(truthjets8);
0455 
0456   // waveform sim
0457   CaloWaveformSim *caloWaveformSim = new CaloWaveformSim();
0458   caloWaveformSim->set_detector_type(CaloTowerDefs::CEMC);
0459   caloWaveformSim->set_detector("CEMC");
0460   caloWaveformSim->set_nsamples(12);
0461   caloWaveformSim->set_pedestalsamples(12);
0462   caloWaveformSim->set_timewidth(0.2);
0463   caloWaveformSim->set_peakpos(6);
0464   caloWaveformSim->set_noise_type(CaloWaveformSim::NOISE_NONE);
0465   se->registerSubsystem(caloWaveformSim);
0466 
0467   caloWaveformSim = new CaloWaveformSim();
0468   caloWaveformSim->set_detector_type(CaloTowerDefs::HCALIN);
0469   caloWaveformSim->set_detector("HCALIN");
0470   caloWaveformSim->set_nsamples(12);
0471   caloWaveformSim->set_pedestalsamples(12);
0472   caloWaveformSim->set_timewidth(0.2);
0473   caloWaveformSim->set_peakpos(6);
0474   caloWaveformSim->set_noise_type(CaloWaveformSim::NOISE_NONE);
0475   se->registerSubsystem(caloWaveformSim);
0476 
0477   caloWaveformSim = new CaloWaveformSim();
0478   caloWaveformSim->set_detector_type(CaloTowerDefs::HCALOUT);
0479   caloWaveformSim->set_detector("HCALOUT");
0480   caloWaveformSim->set_nsamples(12);
0481   caloWaveformSim->set_pedestalsamples(12);
0482   caloWaveformSim->set_timewidth(0.2);
0483   caloWaveformSim->set_peakpos(6);
0484   caloWaveformSim->set_noise_type(CaloWaveformSim::NOISE_NONE);
0485   se->registerSubsystem(caloWaveformSim);
0486 
0487   se->Print("NODETREE");
0488 
0489   //-----------------
0490   // Calorimeter embedding
0491   //-----------------
0492 
0493   caloTowerEmbed *embedder_CEMC = new caloTowerEmbed("embedder_CEMC");
0494   embedder_CEMC->set_detector_type(CaloTowerDefs::CEMC);
0495   embedder_CEMC->set_removeBadTowers(false);
0496   embedder_CEMC->set_embedwaveform(true);
0497   embedder_CEMC->set_inputNodePrefix("TOWERS_");
0498   embedder_CEMC->Verbosity(verbosity);
0499   se->registerSubsystem(embedder_CEMC);
0500 
0501   caloTowerEmbed *embedder_IHCAL = new caloTowerEmbed("embedder_IHCAL");
0502   embedder_IHCAL->set_detector_type(CaloTowerDefs::HCALIN);
0503   embedder_IHCAL->set_removeBadTowers(false);
0504   embedder_IHCAL->set_embedwaveform(true);
0505   embedder_IHCAL->set_inputNodePrefix("TOWERS_");
0506   embedder_IHCAL->Verbosity(verbosity);
0507   se->registerSubsystem(embedder_IHCAL);
0508 
0509   caloTowerEmbed *embedder_OHCAL = new caloTowerEmbed("embedder_OHCal");
0510   embedder_OHCAL->set_detector_type(CaloTowerDefs::HCALOUT);
0511   embedder_OHCAL->set_removeBadTowers(false);
0512   embedder_OHCAL->set_embedwaveform(true);
0513   embedder_OHCAL->set_inputNodePrefix("TOWERS_");
0514   embedder_OHCAL->Verbosity(verbosity);
0515   se->registerSubsystem(embedder_OHCAL);
0516 
0517   // waveform fitting
0518 
0519   CaloTowerBuilder *ca2 = new CaloTowerBuilder();
0520   ca2->set_detector_type(CaloTowerDefs::CEMC);
0521   ca2->set_nsamples(12);
0522   ca2->set_dataflag(false);
0523   ca2->set_processing_type(CaloWaveformProcessing::TEMPLATE);
0524   ca2->set_builder_type(CaloTowerDefs::kWaveformTowerSimv1);
0525   // match our current ZS threshold ~60ADC for emcal
0526   ca2->set_softwarezerosuppression(true, 60);
0527   se->registerSubsystem(ca2);
0528 
0529   ca2 = new CaloTowerBuilder();
0530   ca2->set_detector_type(CaloTowerDefs::HCALIN);
0531   ca2->set_nsamples(12);
0532   ca2->set_dataflag(false);
0533   ca2->set_processing_type(CaloWaveformProcessing::TEMPLATE);
0534   ca2->set_builder_type(CaloTowerDefs::kWaveformTowerSimv1);
0535   ca2->set_softwarezerosuppression(true, 30);
0536   se->registerSubsystem(ca2);
0537 
0538   ca2 = new CaloTowerBuilder();
0539   ca2->set_detector_type(CaloTowerDefs::HCALOUT);
0540   ca2->set_nsamples(12);
0541   ca2->set_dataflag(false);
0542   ca2->set_processing_type(CaloWaveformProcessing::TEMPLATE);
0543   ca2->set_builder_type(CaloTowerDefs::kWaveformTowerSimv1);
0544   ca2->set_softwarezerosuppression(true, 30);
0545   se->registerSubsystem(ca2);
0546 
0547   //--------------
0548   // Set up Input Managers
0549   //--------------
0550 
0551   for (auto & iter : INPUTEMBED::filename)
0552   {
0553     std::string mgrname = "DSTin" + std::to_string(iter.first);
0554     Fun4AllInputManager *hitsin = new Fun4AllDstInputManager(mgrname, "DST", DataTopNode);
0555     hitsin->fileopen(iter.second);
0556     hitsin->Verbosity(Input::VERBOSITY);
0557     if (INPUTEMBED::REPEAT)
0558     {
0559       hitsin->Repeat();
0560     }
0561     se->registerInputManager(hitsin);
0562   }
0563   // input for pedestals
0564   {
0565     TRandom3 randGen;
0566     // get seed
0567     unsigned int seed = PHRandomSeed();
0568     randGen.SetSeed(seed);
0569     // a int from 0 to 3259
0570     int sequence = randGen.Integer(3260);
0571     // pad the name
0572     std::ostringstream opedname;
0573     opedname << "pedestal-54256-0" << std::setw(4) << std::setfill('0') << sequence << ".root";
0574 
0575     std::string pedestalname = opedname.str();
0576 
0577     Fun4AllInputManager *hitsin = new Fun4AllNoSyncDstInputManager("DST2");
0578     hitsin->AddFile(pedestalname);
0579     hitsin->Repeat();
0580     se->registerInputManager(hitsin);
0581   }
0582   // input geom files
0583   {
0584     Fun4AllInputManager *ingeo = new Fun4AllRunNodeInputManager("DST_GEO");
0585     std::string geoLocation = CDBInterface::instance()->getUrl("calo_geo");
0586     ingeo->AddFile(geoLocation);
0587     se->registerInputManager(ingeo);
0588   }
0589 
0590   //  InputManagers();
0591 
0592   std::string FullOutFile = outdir + "DST_TRUTH_G4HIT_" + outnameEnd;
0593   Fun4AllOutputManager *out = new Fun4AllDstOutputManager("TRUTHOUT", FullOutFile);
0594   AddCommonNodes(out);
0595   out->AddNode("G4TruthInfo");
0596   out->AddNode("G4HIT_BH_1");
0597   out->AddNode("PHHepMCGenEventMap");
0598   out->Verbosity(0);
0599   se->registerOutputManager(out);
0600   // OUTPUTMANAGER::outfiles.insert(FullOutFile);
0601   se->registerOutputManager(out);
0602 
0603   FullOutFile = outdir + "DST_TRUTH_JET_" + outnameEnd;
0604   out = new Fun4AllDstOutputManager("JETOUT", FullOutFile);
0605   AddCommonNodes(out);
0606   out->AddNode("AntiKt_Truth_r02");
0607   out->AddNode("AntiKt_Truth_r03");
0608   out->AddNode("AntiKt_Truth_r04");
0609   out->AddNode("AntiKt_Truth_r05");
0610   out->AddNode("AntiKt_Truth_r06");
0611   out->AddNode("AntiKt_Truth_r07");
0612   out->AddNode("AntiKt_Truth_r08");
0613   out->AddNode("AntiKt_Sim_r02");
0614   out->AddNode("AntiKt_Sim_r03");
0615   out->AddNode("AntiKt_Sim_r04");
0616   out->AddNode("AntiKt_Sim_r05");
0617   out->AddNode("AntiKt_Sim_r06");
0618   out->AddNode("AntiKt_Sim_r07");
0619   out->AddNode("AntiKt_Sim_r08");
0620   out->AddNode("AntiKt_Sim_Retower_r02");
0621   out->AddNode("AntiKt_Sim_Retower_r03");
0622   out->AddNode("AntiKt_Sim_Retower_r04");
0623   out->AddNode("AntiKt_Sim_Retower_r05");
0624   out->AddNode("AntiKt_Sim_Retower_r06");
0625   out->AddNode("AntiKt_Sim_Retower_r07");
0626   out->AddNode("AntiKt_Sim_Retower_r08");
0627   out->Verbosity(0);
0628   se->registerOutputManager(out);
0629   // OUTPUTMANAGER::outfiles.insert(FullOutFile);
0630 
0631   FullOutFile = outdir + "DST_CALO_" + outnameEnd;
0632   out = new Fun4AllDstOutputManager("CALOPROCESSED", FullOutFile);
0633   AddCommonNodes(out);
0634   out->AddNode("TOWERS_CEMC");
0635   out->AddNode("TOWERS_HCALIN");
0636   out->AddNode("TOWERS_HCALOUT");
0637   out->Verbosity(0);
0638   se->registerOutputManager(out);
0639   // OUTPUTMANAGER::outfiles.insert(FullOutFile);
0640 
0641   FullOutFile = outdir + "DST_GLOBAL_" + outnameEnd;
0642   out = new Fun4AllDstOutputManager("GLOBALOUT", FullOutFile);
0643   AddCommonNodes(out);
0644   out->AddNode("GlobalVertexMap");
0645   out->AddNode("MinimumBiasInfo");
0646   out->AddNode("CentralityInfo");
0647   out->AddNode("MbdOut");
0648   out->Verbosity(0);
0649   se->registerOutputManager(out);
0650   // OUTPUTMANAGER::outfiles.insert(FullOutFile);
0651 
0652   //-----------------
0653   // Event processing
0654   //-----------------
0655   // if we use a negative number of events we go back to the command line here
0656   if (nEvents < 0)
0657   {
0658     return 0;
0659   }
0660   // if we run the particle generator and use 0 it'll run forever
0661   if (nEvents == 0 && !Input::HEPMC && !Input::READHITS && INPUTEMBED::REPEAT)
0662   {
0663     std::cout << "using 0 for number of events is a bad idea when using particle generators" << std::endl;
0664     std::cout << "it will run forever, so I just return without running anything" << std::endl;
0665     return 0;
0666   }
0667 
0668   se->run(nEvents);
0669 
0670   //-----
0671   // Exit
0672   //-----
0673 
0674   CDBInterface::instance()->Print(); // print used DB files
0675   se->End();
0676   std::cout << "All done" << std::endl;
0677   delete se;
0678   gSystem->Exit(0);
0679   return 0;
0680 }
0681 
0682 void AddCommonNodes(Fun4AllOutputManager *out)
0683 {
0684   out->AddNode("Sync");
0685   out->AddNode("EventHeader");
0686   return;
0687 }
0688 
0689 #endif