Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:18:07

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