DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4InteractionVertexSmear.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DD4hep/Printout.h>
16 #include <DD4hep/InstanceCount.h>
17 #include <DDG4/Geant4Random.h>
18 #include <DDG4/Geant4Context.h>
21 
22 // C/C++ include files
23 #include <cmath>
24 
25 using namespace dd4hep::sim;
26 
29  : Geant4GeneratorAction(ctxt, nam)
30 {
32  declareProperty("Offset", m_offset);
33  declareProperty("Sigma", m_sigma);
34  declareProperty("Mask", m_mask = 1);
35  m_needsControl = true;
36 }
37 
41 }
42 
43 
45 void Geant4InteractionVertexSmear::smear(Interaction* inter) const {
46  Geant4Random& rndm = context()->event().random();
47  if ( inter ) {
48  double dx = rndm.gauss(m_offset.x(),m_sigma.x());
49  double dy = rndm.gauss(m_offset.y(),m_sigma.y());
50  double dz = rndm.gauss(m_offset.z(),m_sigma.z());
51  double dt = rndm.gauss(m_offset.t(),m_sigma.t());
52  print("+++ Smearing primary vertex for interaction type %d (%d Vertices, %d particles) "
53  "by (%+.2e mm, %+.2e mm, %+.2e mm, %+.2e ns)",
54  m_mask,int(inter->vertices.size()),int(inter->particles.size()),dx,dy,dz,dt);
55  smearInteraction(this,inter,dx,dy,dz,dt);
56  return;
57  }
58  print("+++ No interaction of type %d present.",m_mask);
59 }
60 
63  typedef std::vector<Geant4PrimaryInteraction*> _I;
65 
66  if ( m_mask >= 0 ) {
67  Interaction* inter = evt->get(m_mask);
68  smear(inter);
69  return;
70  }
71  _I interactions = evt->interactions();
72  for(_I::iterator i=interactions.begin(); i != interactions.end(); ++i)
73  smear(*i);
74 }
dd4hep::sim::Geant4InteractionVertexSmear::m_sigma
ROOT::Math::PxPyPzEVector m_sigma
Property: The gaussian sigmas to the offset.
Definition: Geant4InteractionVertexSmear.h:61
dd4hep::sim::Geant4PrimaryEvent
Class modelling a complete primary event with multiple interactions.
Definition: Geant4Primary.h:143
dd4hep::sim::Geant4InteractionVertexSmear::smear
void smear(Interaction *interaction) const
Action routine to smear one single interaction according to the properties.
dd4hep::sim::Geant4PrimaryEvent::interactions
std::vector< Geant4PrimaryInteraction * > interactions() const
Retrieve all interactions.
Definition: Geant4Primary.cpp:113
dd4hep::sim::Geant4InteractionVertexSmear::~Geant4InteractionVertexSmear
virtual ~Geant4InteractionVertexSmear()
Default destructor.
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::Geant4Context::event
Geant4Event & event() const
Access the geant4 event – valid only between BeginEvent() and EndEvent()!
Definition: Geant4Context.cpp:84
dd4hep::sim::Geant4Event::random
Geant4Random & random() const
Access the random number generator.
Definition: Geant4Context.h:137
Geant4InputHandling.h
Geant4InteractionVertexSmear.h
dd4hep::sim::Geant4Event::extension
T * extension(bool alert=true)
Access to type safe extension object. Exception is thrown if the object is invalid.
Definition: Geant4Context.h:151
Geant4Random.h
dd4hep::sim::Geant4InteractionVertexSmear::Geant4InteractionVertexSmear
Geant4InteractionVertexSmear()=delete
Inhibit default constructor.
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::Geant4GeneratorAction
Concrete implementation of the Geant4 generator action base class.
Definition: Geant4GeneratorAction.h:47
dd4hep::sim::Geant4InteractionVertexSmear::m_mask
int m_mask
Property: Unique identifier of the interaction created.
Definition: Geant4InteractionVertexSmear.h:63
dd4hep::sim::Geant4Random
Mini interface to THE random generator of the application.
Definition: Geant4Random.h:59
dd4hep::sim::Geant4InteractionVertexSmear::m_offset
ROOT::Math::PxPyPzEVector m_offset
Property: The constant smearing offset.
Definition: Geant4InteractionVertexSmear.h:59
dd4hep::sim::Geant4Action::print
void print(const char *fmt,...) const
Support for messages with variable output level using output level.
Definition: Geant4Action.cpp:144
dd4hep::sim::Geant4Random::gauss
double gauss(double mean=0, double sigma=1)
Create gaussian distributed random numbers.
Definition: Geant4Random.cpp:304
dd4hep::sim::smearInteraction
int smearInteraction(const Geant4Action *caller, Geant4PrimaryEvent::Interaction *inter, double dx, double dy, double dz, double dt)
Smear the primary vertex of an interaction.
Definition: Geant4InputHandling.cpp:313
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::Geant4InteractionVertexSmear::operator()
virtual void operator()(G4Event *event)
Callback to generate primary particles.
InstanceCount.h
Printout.h
Geant4Context.h
dd4hep::sim::Geant4InteractionVertexSmear::Interaction
Geant4PrimaryInteraction Interaction
Interaction definition.
Definition: Geant4InteractionVertexSmear.h:55
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4Action::context
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:270
dd4hep::sim::Geant4PrimaryEvent::get
Geant4PrimaryInteraction * get(int id) const
Retrieve an interaction by its ID.
Definition: Geant4Primary.cpp:107