Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:26

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework include files
0015 #include <DD4hep/Printout.h>
0016 #include <DD4hep/InstanceCount.h>
0017 #include <DDG4/Geant4Random.h>
0018 #include <DDG4/Geant4Context.h>
0019 #include <DDG4/Geant4InputHandling.h>
0020 #include <DDG4/Geant4InteractionVertexSmear.h>
0021 
0022 // C/C++ include files
0023 #include <cmath>
0024 
0025 using namespace dd4hep::sim;
0026 
0027 /// Standard constructor
0028 Geant4InteractionVertexSmear::Geant4InteractionVertexSmear(Geant4Context* ctxt, const std::string& nam)
0029   : Geant4GeneratorAction(ctxt, nam)
0030 {
0031   InstanceCount::increment(this);
0032   declareProperty("Offset", m_offset);
0033   declareProperty("Sigma",  m_sigma);
0034   declareProperty("Mask",   m_mask = 1);
0035   m_needsControl = true;
0036 }
0037 
0038 /// Default destructor
0039 Geant4InteractionVertexSmear::~Geant4InteractionVertexSmear() {
0040   InstanceCount::decrement(this);
0041 }
0042 
0043 
0044 /// Action to smear one single interaction according to the properties
0045 void Geant4InteractionVertexSmear::smear(Interaction* inter)  const  {
0046   Geant4Random& rndm = context()->event().random();
0047   if ( inter )  {
0048     double dx = rndm.gauss(m_offset.x(),m_sigma.x());
0049     double dy = rndm.gauss(m_offset.y(),m_sigma.y());
0050     double dz = rndm.gauss(m_offset.z(),m_sigma.z());
0051     double dt = rndm.gauss(m_offset.t(),m_sigma.t());
0052     print("+++ Smearing primary vertex for interaction type %d (%d Vertices, %d particles) "
0053           "by (%+.2e mm, %+.2e mm, %+.2e mm, %+.2e ns)",
0054           m_mask,int(inter->vertices.size()),int(inter->particles.size()),dx,dy,dz,dt);
0055     smearInteraction(this,inter,dx,dy,dz,dt);
0056     return;
0057   }
0058   print("+++ No interaction of type %d present.",m_mask);
0059 }
0060 
0061 /// Callback to generate primary particles
0062 void Geant4InteractionVertexSmear::operator()(G4Event*) {
0063   typedef std::vector<Geant4PrimaryInteraction*> _I;
0064   Geant4PrimaryEvent* evt = context()->event().extension<Geant4PrimaryEvent>();
0065 
0066   if ( m_mask >= 0 )  {
0067     Interaction* inter = evt->get(m_mask);
0068     smear(inter);
0069     return;
0070   }
0071   _I interactions = evt->interactions();
0072   for(_I::iterator i=interactions.begin(); i != interactions.end(); ++i)
0073     smear(*i);
0074 }