Back to home page

sPhenix code displayed by LXR

 
 

    


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

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