Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:21:57

0001 // Tell emacs that this is a C++ source
0002 //  -*- C++ -*-.
0003 #ifndef G4MAIN_FUN4ALLDSTPILEUPINPUTMANAGER_H
0004 #define G4MAIN_FUN4ALLDSTPILEUPINPUTMANAGER_H
0005 
0006 /*!
0007  * \file Fun4AllDstPileupInputManager.h
0008  * \author Hugo Pereira Da Costa <hugo.pereira-da-costa@cea.fr>
0009  */
0010 
0011 #include <fun4all/Fun4AllInputManager.h>
0012 #include <fun4all/Fun4AllReturnCodes.h>  // for SYNC_NOOBJECT, SYNC_OK
0013 
0014 #include <phool/PHCompositeNode.h>  // for PHCompositeNode
0015 #include <phool/PHNodeIOManager.h>  // for PHNodeIOManager
0016 #include <phool/sphenix_constants.h>
0017 
0018 #include <gsl/gsl_rng.h>
0019 
0020 #include <map>
0021 #include <memory>
0022 #include <string>
0023 #include <utility>  // for pair
0024 
0025 /*!
0026  * dedicated input manager that merges single events into "merged" events, containing a trigger event
0027  * and a number of time-shifted pile-up events corresponding to a given pile-up rate
0028  */
0029 class Fun4AllDstPileupInputManager : public Fun4AllInputManager
0030 {
0031  public:
0032   Fun4AllDstPileupInputManager(const std::string &name = "DUMMY", const std::string &nodename = "DST", const std::string &topnodename = "TOP");
0033   int fileopen(const std::string &filenam) override;
0034   int fileclose() override;
0035   int run(const int nevents = 0) override;
0036   int BranchSelect(const std::string &branch, const int iflag) override;
0037   int setBranches() override;
0038   void Print(const std::string &what = "ALL") const override;
0039   int PushBackEvents(const int i) override;
0040 
0041   // Effectivly turn off the synchronization checking (copy from Fun4AllNoSyncDstInputManager)
0042   int SyncIt(const SyncObject * /*mastersync*/) override { return Fun4AllReturnCodes::SYNC_OK; }
0043   int GetSyncObject(SyncObject ** /*mastersync*/) override { return Fun4AllReturnCodes::SYNC_NOOBJECT; }
0044   int NoSyncPushBackEvents(const int nevt) override { return PushBackEvents(nevt); }
0045 
0046   /// collision rate in Hz
0047   void setCollisionRate(double Hz)
0048   {
0049     m_collision_rate = Hz;
0050   }
0051 
0052   /// time between bunch crossing in ns
0053   void setTimeBetweenCrossings(double nsec)
0054   {
0055     m_time_between_crossings = nsec;
0056   }
0057 
0058   //! set time window for pileup events (ns)
0059   void setPileupTimeWindow(double tmin, double tmax)
0060   {
0061     m_tmin = tmin;
0062     m_tmax = tmax;
0063   }
0064   //! for symmetric windows
0065   void setDetectorActiveCrossings(const std::string &name, const int nbcross);
0066 
0067   void setDetectorActiveCrossings(const std::string &name, const int min, const int max);
0068 
0069  private:
0070   //! loads one event on internal DST node
0071   int runOne(const int nevents = 0);
0072 
0073   //!@name event counters
0074   //@{
0075   bool m_ReadRunTTree = true;
0076   int m_ievent_total = 0;
0077   int m_ievent_thisfile = 0;
0078   //@}
0079 
0080   std::string m_fullfilename;
0081   std::string m_RunNode = "RUN";
0082   std::map<const std::string, int> m_branchread;
0083 
0084   //! dst node from TopNode
0085   PHCompositeNode *m_dstNode{nullptr};
0086 
0087   //! run node from TopNode
0088   PHCompositeNode *m_runNode{nullptr};
0089 
0090   //! internal dst node to copy background events
0091   std::unique_ptr<PHCompositeNode> m_dstNodeInternal;
0092 
0093   //!@name internal runnodes to perform the summation over multiple runs
0094   //@{
0095   std::unique_ptr<PHCompositeNode> m_runNodeCopy;
0096   std::unique_ptr<PHCompositeNode> m_runNodeSum;
0097   //@}
0098 
0099   //! input manager for active (trigger) events
0100   /*! corresponding nodes are copied directly to the topNode */
0101   std::unique_ptr<PHNodeIOManager> m_IManager;
0102 
0103   //! time between crossings. This is a RHIC constant (ns)
0104   double m_time_between_crossings = sphenix_constants::time_between_crossings;
0105 
0106   //! collision rate (Hz)
0107   double m_collision_rate{5e4};
0108 
0109   //! min integration time for pileup in the TPC (ns)
0110   double m_tmin{-13500};
0111 
0112   //! max integration time for pileup in the TPC (ns)
0113   double m_tmax{13500};
0114 
0115   //! random generator
0116   class Deleter
0117   {
0118    public:
0119     void operator()(gsl_rng *rng) const { gsl_rng_free(rng); }
0120   };
0121 
0122   std::unique_ptr<gsl_rng, Deleter> m_rng;
0123 
0124   std::map<std::string, std::pair<double, double>> m_DetectorTiming;
0125 };
0126 
0127 #endif /* G4MAIN_FUN4ALLDSTPILEUPINPUTMANAGER_H_ */