Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #include "PHG4PileupGenerator.h"
0002 
0003 #include <fun4all/Fun4AllReturnCodes.h>
0004 
0005 #include <gsl/gsl_randist.h>
0006 
0007 #include <iostream>  // for operator<<, endl, basic_ostream
0008 
0009 PHG4PileupGenerator::PHG4PileupGenerator(const std::string &name)
0010   : PHG4ParticleGeneratorBase(name)
0011 {
0012   return;
0013 }
0014 
0015 PHG4PileupGenerator::~PHG4PileupGenerator()
0016 {
0017   delete _generator;
0018 }
0019 
0020 int PHG4PileupGenerator::Init(PHCompositeNode *topNode)
0021 {
0022   if (!_generator)
0023   {
0024     return Fun4AllReturnCodes::EVENT_OK;
0025   }
0026   _generator->Init(topNode);
0027   return Fun4AllReturnCodes::EVENT_OK;
0028 }
0029 
0030 int PHG4PileupGenerator::InitRun(PHCompositeNode *topNode)
0031 {
0032   // cout << "generator ptr: " << _generator << endl;
0033 
0034   if (!_generator)
0035   {
0036     return Fun4AllReturnCodes::EVENT_OK;
0037   }
0038 
0039   _generator->InitRun(topNode);
0040 
0041   _ave_coll_per_crossing = _collision_rate * _time_between_crossings * 1000.0 * 1e-9;
0042 
0043   _min_crossing = _min_integration_time / _time_between_crossings;
0044   _max_crossing = _max_integration_time / _time_between_crossings;
0045 
0046   return Fun4AllReturnCodes::EVENT_OK;
0047 }
0048 
0049 int PHG4PileupGenerator::process_event(PHCompositeNode *topNode)
0050 {
0051   if (!_generator)
0052   {
0053     return Fun4AllReturnCodes::EVENT_OK;
0054   }
0055 
0056   // toss multiple crossings all the way back
0057   for (int icrossing = _min_crossing; icrossing <= _max_crossing; ++icrossing)
0058   {
0059     double crossing_time = _time_between_crossings * icrossing;
0060 
0061     int ncollisions = gsl_ran_poisson(RandomGenerator(), _ave_coll_per_crossing);
0062     if (icrossing == 0)
0063     {
0064       --ncollisions;
0065     }
0066 
0067     for (int icollision = 0; icollision < ncollisions; ++icollision)
0068     {
0069       _generator->set_t0(crossing_time);
0070       _generator->process_event(topNode);
0071     }
0072   }
0073 
0074   return Fun4AllReturnCodes::EVENT_OK;
0075 }
0076 
0077 int PHG4PileupGenerator::Reset(PHCompositeNode *topNode)
0078 {
0079   if (!_generator)
0080   {
0081     return Fun4AllReturnCodes::EVENT_OK;
0082   }
0083   _generator->Reset(topNode);
0084   return Fun4AllReturnCodes::EVENT_OK;
0085 }
0086 
0087 int PHG4PileupGenerator::ResetEvent(PHCompositeNode *topNode)
0088 {
0089   if (!_generator)
0090   {
0091     return Fun4AllReturnCodes::EVENT_OK;
0092   }
0093   _generator->ResetEvent(topNode);
0094   return Fun4AllReturnCodes::EVENT_OK;
0095 }
0096 
0097 int PHG4PileupGenerator::EndRun(const int runnumber)
0098 {
0099   if (!_generator)
0100   {
0101     return Fun4AllReturnCodes::EVENT_OK;
0102   }
0103   _generator->EndRun(runnumber);
0104   return Fun4AllReturnCodes::EVENT_OK;
0105 }
0106 
0107 int PHG4PileupGenerator::End(PHCompositeNode *topNode)
0108 {
0109   if (!_generator)
0110   {
0111     return Fun4AllReturnCodes::EVENT_OK;
0112   }
0113   _generator->End(topNode);
0114   return Fun4AllReturnCodes::EVENT_OK;
0115 }