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_FUN4ALLSINGLEDSTPILEUPINPUTMANAGER_H
0004 #define G4MAIN_FUN4ALLSINGLEDSTPILEUPINPUTMANAGER_H
0005 
0006 /*!
0007  * \file Fun4AllSingleDstPileupInputManager.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>
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 
0024 /*!
0025  * dedicated input manager that merges single events into "merged" events, containing a trigger event
0026  * and a number of time-shifted pile-up events corresponding to a given pile-up rate
0027  */
0028 class Fun4AllSingleDstPileupInputManager : public Fun4AllInputManager
0029 {
0030  public:
0031   Fun4AllSingleDstPileupInputManager(const std::string &name = "DUMMY", const std::string &nodename = "DST", const std::string &topnodename = "TOP");
0032   int fileopen(const std::string &filenam) override;
0033   int fileclose() override;
0034   int run(const int nevents = 0) override;
0035   int BranchSelect(const std::string &branch, const int iflag) override;
0036   int setBranches() override;
0037   void Print(const std::string &what = "ALL") const override;
0038   int PushBackEvents(const int i) override;
0039 
0040   // Effectivly turn off the synchronization checking (copy from Fun4AllNoSyncDstInputManager)
0041   int SyncIt(const SyncObject * /*mastersync*/) override { return Fun4AllReturnCodes::SYNC_OK; }
0042   int GetSyncObject(SyncObject ** /*mastersync*/) override { return Fun4AllReturnCodes::SYNC_NOOBJECT; }
0043   int NoSyncPushBackEvents(const int nevt) override { return PushBackEvents(nevt); }
0044 
0045   /// collision rate in Hz
0046   void setCollisionRate(double Hz)
0047   {
0048     m_collision_rate = Hz;
0049   }
0050 
0051   /// time between bunch crossing in ns
0052   void setTimeBetweenCrossings(double nsec)
0053   {
0054     m_time_between_crossings = nsec;
0055   }
0056 
0057   //! set time window for pileup events (ns)
0058   void setPileupTimeWindow(double tmin, double tmax)
0059   {
0060     m_tmin = tmin;
0061     m_tmax = tmax;
0062   }
0063 
0064  private:
0065   //!@name event counters
0066   //@{
0067   bool m_ReadRunTTree{true};
0068   int m_ievent_total{0};
0069   int m_ievent_thisfile{0};
0070   //@}
0071 
0072   std::string m_fullfilename;
0073   std::string m_RunNode{"RUN"};
0074   std::map<const std::string, int> m_branchread;
0075 
0076   //! dst node from TopNode
0077   PHCompositeNode *m_dstNode{nullptr};
0078 
0079   //! run node from TopNode
0080   PHCompositeNode *m_runNode{nullptr};
0081 
0082   //! internal dst node to copy background events
0083   std::unique_ptr<PHCompositeNode> m_dstNodeInternal;
0084 
0085   //!@name internal runnodes to perform the summation over multiple runs
0086   //@{
0087   std::unique_ptr<PHCompositeNode> m_runNodeCopy;
0088   std::unique_ptr<PHCompositeNode> m_runNodeSum;
0089   //@}
0090 
0091   //! input manager for active (trigger) events
0092   /*! corresponding nodes are copied directly to the topNode */
0093   std::unique_ptr<PHNodeIOManager> m_IManager;
0094 
0095   //! input manager for background (pileup) events
0096   /*! corresponding nodes are copied to the internal dst node, then merged to the top node */
0097   std::unique_ptr<PHNodeIOManager> m_IManager_background;
0098 
0099   //! time between crossings. This is a RHIC constant (ns)
0100   double m_time_between_crossings = sphenix_constants::time_between_crossings;
0101 
0102   //! collision rate (Hz)
0103   double m_collision_rate{5e4};
0104 
0105   //! min integration time for pileup in the TPC (ns)
0106   double m_tmin{-13500};
0107 
0108   //! max integration time for pileup in the TPC (ns)
0109   double m_tmax{13500};
0110 
0111   //! random generator
0112   class Deleter
0113   {
0114    public:
0115     void operator()(gsl_rng *rng) const { gsl_rng_free(rng); }
0116   };
0117 
0118   std::unique_ptr<gsl_rng, Deleter> m_rng;
0119 };
0120 
0121 #endif /* G4MAIN_FUN4ALLSINGLEDSTPILEUPINPUTMANAGER_H */