CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
FastSimProducer Class Reference

The core class of the new SimplifiedGeometryPropagator. More...

Inheritance diagram for FastSimProducer:
edm::stream::EDProducer<>

Public Member Functions

 FastSimProducer (const edm::ParameterSet &)
 
 ~FastSimProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Private Member Functions

void beginStream (edm::StreamID id) override
 
virtual FSimTrack createFSimTrack (fastsim::Particle *particle, fastsim::ParticleManager *particleManager, HepPDT::ParticleDataTable const &particleTable)
 
void endStream () override
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

std::unique_ptr
< RandomEngineAndDistribution
_randomEngine
 The random engine. More...
 
double beamPipeRadius_
 The radius of the beampipe. More...
 
fastsim::Geometry caloGeometry_
 Hack to interface "old" calo to "new" tracking. More...
 
edm::ESGetToken< CaloGeometry,
CaloGeometryRecord
caloGeometryESToken_
 
edm::ESGetToken< CaloTopology,
CaloTopologyRecord
caloTopologyESToken_
 
fastsim::Decayer decayer_
 Handles decays of non-stable particles using pythia. More...
 
double deltaRchargedMother_
 Cut on deltaR for ClosestChargedDaughter algorithm (FastSim tracking) More...
 
edm::EDGetTokenT
< edm::HepMCProduct
genParticlesToken_
 Token to get the genParticles. More...
 
fastsim::Geometry geometry_
 The definition of the tracker according to python config. More...
 
std::map< std::string,
fastsim::InteractionModel * > 
interactionModelMap_
 Each interaction model has a unique name. More...
 
std::vector< std::unique_ptr
< fastsim::InteractionModel > > 
interactionModels_
 All defined interaction models. More...
 
std::unique_ptr
< CalorimetryManager
myCalorimetry
 
const edm::ESGetToken
< HepPDT::ParticleDataTable,
edm::DefaultRecord
particleDataTableESToken_
 
fastsim::ParticleFilter particleFilter_
 Decides which particles have to be propagated. More...
 
bool simulateCalorimetry
 
bool simulateMuons
 
edm::ESWatcher
< CaloGeometryRecord
watchCaloGeometry_
 
edm::ESWatcher
< CaloTopologyRecord
watchCaloTopology_
 

Static Private Attributes

static const std::string MESSAGECATEGORY = "FastSimulation"
 Category of debugging messages ("FastSimulation") More...
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T...>
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T...>
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

The core class of the new SimplifiedGeometryPropagator.

Coordinates the propagation of all particles, this means it does the following loop: 1) Get particle from ParticleManager 2) Call LayerNavigator to move particle to next intersection with layer 3) Loop over all the interactions and add secondaries to the event 4) Repeat steps 2), 3) until particle left the tracker, lost all its energy or is about to decay 5) If particle is about to decay: do decay and add secondaries to the event 6) Restart from 1) with the next particle 7) If last particle was propagated add SimTracks, SimVertices, SimHits,... to the event

Definition at line 64 of file FastSimProducer.cc.

Constructor & Destructor Documentation

FastSimProducer::FastSimProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 102 of file FastSimProducer.cc.

References caloGeometryESToken_, caloTopologyESToken_, beamerCreator::create(), DeDxTools::esConsumes(), Exception, get, edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNames(), interactionModelMap_, interactionModels_, eostools::move(), myCalorimetry, simulateCalorimetry, and AlCaHLTBitMon_QueryRunRegistry::string.

103  : genParticlesToken_(consumes<edm::HepMCProduct>(iConfig.getParameter<edm::InputTag>("src"))),
104  geometry_(iConfig.getParameter<edm::ParameterSet>("trackerDefinition"), consumesCollector()),
105  caloGeometry_(iConfig.getParameter<edm::ParameterSet>("caloDefinition"), consumesCollector()),
106  beamPipeRadius_(iConfig.getParameter<double>("beamPipeRadius")),
107  deltaRchargedMother_(iConfig.getParameter<double>("deltaRchargedMother")),
108  particleFilter_(iConfig.getParameter<edm::ParameterSet>("particleFilter")),
109  _randomEngine(nullptr),
110  simulateCalorimetry(iConfig.getParameter<bool>("simulateCalorimetry")),
111  simulateMuons(iConfig.getParameter<bool>("simulateMuons")),
113  if (simulateCalorimetry) {
116  }
117 
118  //----------------
119  // define interaction models
120  //---------------
121 
122  const edm::ParameterSet& modelCfgs = iConfig.getParameter<edm::ParameterSet>("interactionModels");
123  for (const std::string& modelName : modelCfgs.getParameterNames()) {
124  const edm::ParameterSet& modelCfg = modelCfgs.getParameter<edm::ParameterSet>(modelName);
125  std::string modelClassName(modelCfg.getParameter<std::string>("className"));
126  // Use plugin-factory to create model
127  std::unique_ptr<fastsim::InteractionModel> interactionModel(
128  fastsim::InteractionModelFactory::get()->create(modelClassName, modelName, modelCfg));
129  if (!interactionModel.get()) {
130  throw cms::Exception("FastSimProducer") << "InteractionModel " << modelName << " could not be created";
131  }
132  // Add model to list
133  interactionModels_.push_back(std::move(interactionModel));
134  // and create the map
135  interactionModelMap_[modelName] = interactionModels_.back().get();
136  }
137 
138  //----------------
139  // calorimetry
140  //---------------
141 
142  if (simulateCalorimetry) {
143  myCalorimetry =
144  std::make_unique<CalorimetryManager>(nullptr,
145  iConfig.getParameter<edm::ParameterSet>("Calorimetry"),
146  iConfig.getParameter<edm::ParameterSet>("MaterialEffectsForMuonsInECAL"),
147  iConfig.getParameter<edm::ParameterSet>("MaterialEffectsForMuonsInHCAL"),
148  iConfig.getParameter<edm::ParameterSet>("GFlash"),
149  consumesCollector());
150  }
151 
152  //----------------
153  // register products
154  //----------------
155 
156  // SimTracks and SimVertices
157  produces<edm::SimTrackContainer>();
158  produces<edm::SimVertexContainer>();
159  // products of interaction models, i.e. simHits
160  for (auto& interactionModel : interactionModels_) {
161  interactionModel->registerProducts(producesCollector());
162  }
163  produces<edm::PCaloHitContainer>("EcalHitsEB");
164  produces<edm::PCaloHitContainer>("EcalHitsEE");
165  produces<edm::PCaloHitContainer>("EcalHitsES");
166  produces<edm::PCaloHitContainer>("HcalHits");
167  produces<edm::SimTrackContainer>("MuonSimTracks");
168 }
std::vector< std::unique_ptr< fastsim::InteractionModel > > interactionModels_
All defined interaction models.
fastsim::Geometry caloGeometry_
Hack to interface &quot;old&quot; calo to &quot;new&quot; tracking.
std::unique_ptr< RandomEngineAndDistribution > _randomEngine
The random engine.
double deltaRchargedMother_
Cut on deltaR for ClosestChargedDaughter algorithm (FastSim tracking)
fastsim::Geometry geometry_
The definition of the tracker according to python config.
edm::EDGetTokenT< edm::HepMCProduct > genParticlesToken_
Token to get the genParticles.
const edm::ESGetToken< HepPDT::ParticleDataTable, edm::DefaultRecord > particleDataTableESToken_
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryESToken_
def move
Definition: eostools.py:511
double beamPipeRadius_
The radius of the beampipe.
std::vector< std::string > getParameterNames() const
edm::ESGetToken< CaloTopology, CaloTopologyRecord > caloTopologyESToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::map< std::string, fastsim::InteractionModel * > interactionModelMap_
Each interaction model has a unique name.
std::unique_ptr< CalorimetryManager > myCalorimetry
#define get
fastsim::ParticleFilter particleFilter_
Decides which particles have to be propagated.
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
FastSimProducer::~FastSimProducer ( )
inlineoverride

Definition at line 67 of file FastSimProducer.cc.

67 { ; }

Member Function Documentation

void FastSimProducer::beginStream ( edm::StreamID  id)
overrideprivate

Definition at line 170 of file FastSimProducer.cc.

References _randomEngine, and gpuClustering::id.

170  {
171  _randomEngine = std::make_unique<RandomEngineAndDistribution>(id);
172 }
std::unique_ptr< RandomEngineAndDistribution > _randomEngine
The random engine.
uint16_t *__restrict__ id
FSimTrack FastSimProducer::createFSimTrack ( fastsim::Particle particle,
fastsim::ParticleManager particleManager,
HepPDT::ParticleDataTable const &  particleTable 
)
privatevirtual

Definition at line 379 of file FastSimProducer.cc.

References _randomEngine, fastsim::ParticleManager::addSecondaries(), caloGeometry_, fastsim::Particle::charge(), fastsim::Decayer::decay(), decayer_, fastsim::SimplifiedGeometry::ECAL, fastsim::Particle::genParticleIndex(), fastsim::SimplifiedGeometry::getCaloType(), fastsim::ParticleManager::getSimTrack(), fastsim::ParticleManager::getSimVertex(), fastsim::SimplifiedGeometry::getThickness(), fastsim::SimplifiedGeometry::HCAL, fastsim::SimplifiedGeometry::isForward(), fastsim::Particle::isStable(), LogDebug, makeParticle(), MESSAGECATEGORY, fastsim::Particle::momentum(), fastsim::LayerNavigator::moveParticleToNextLayer(), FSimTrack::onEcal(), FSimTrack::onHcal(), FSimTrack::onLayer1(), FSimTrack::onLayer2(), FSimTrack::onVFcal(), fastsim::Particle::pdgId(), fastsim::Particle::position(), fastsim::SimplifiedGeometry::PRESHOWER1, fastsim::SimplifiedGeometry::PRESHOWER2, fastsim::Particle::remainingProperLifeTimeC(), FSimTrack::setEcal(), FSimTrack::setGlobal(), FSimTrack::setHcal(), FSimTrack::setLayer1(), FSimTrack::setLayer2(), FSimTrack::setVFcal(), fastsim::Particle::simTrackIndex(), fastsim::Particle::simVertexIndex(), summarizeEdmComparisonLogfiles::success, and fastsim::SimplifiedGeometry::VFCAL.

Referenced by produce().

381  {
382  FSimTrack myFSimTrack(particle->pdgId(),
383  particleManager->getSimTrack(particle->simTrackIndex()).momentum(),
384  particle->simVertexIndex(),
385  particle->genParticleIndex(),
386  particle->simTrackIndex(),
387  particle->charge(),
388  particle->position(),
389  particle->momentum(),
390  particleManager->getSimVertex(particle->simVertexIndex()));
391 
392  // move the particle through the caloLayers
393  fastsim::LayerNavigator caloLayerNavigator(caloGeometry_);
394  const fastsim::SimplifiedGeometry* caloLayer = nullptr;
395 
396  // moveParticleToNextLayer(..) returns 0 in case that particle decays
397  // in this case particle is propagated up to its decay vertex
398  while (caloLayerNavigator.moveParticleToNextLayer(*particle, caloLayer)) {
399  LogDebug(MESSAGECATEGORY) << " moved to next caloLayer: " << *caloLayer;
400  LogDebug(MESSAGECATEGORY) << " new state: " << *particle;
401 
402  // break after 25 ns: only happens for particles stuck in loops
403  if (particle->position().T() > 50) {
404  caloLayer = nullptr;
405  break;
406  }
407 
409  // Define ParticlePropagators (RawParticle) needed for CalorimetryManager and save them
411 
412  RawParticle PP = makeParticle(&particleTable, particle->pdgId(), particle->momentum(), particle->position());
413 
414  // no material
415  if (caloLayer->getThickness(particle->position(), particle->momentum()) < 1E-10) {
416  // unfortunately needed for CalorimetryManager
417  if (caloLayer->getCaloType() == fastsim::SimplifiedGeometry::ECAL) {
418  if (!myFSimTrack.onEcal()) {
419  myFSimTrack.setEcal(PP, 0);
420  }
421  } else if (caloLayer->getCaloType() == fastsim::SimplifiedGeometry::HCAL) {
422  if (!myFSimTrack.onHcal()) {
423  myFSimTrack.setHcal(PP, 0);
424  }
425  } else if (caloLayer->getCaloType() == fastsim::SimplifiedGeometry::VFCAL) {
426  if (!myFSimTrack.onVFcal()) {
427  myFSimTrack.setVFcal(PP, 0);
428  }
429  }
430 
431  // not necessary to continue propagation
432  if (caloLayer->getCaloType() == fastsim::SimplifiedGeometry::VFCAL) {
433  myFSimTrack.setGlobal();
434  caloLayer = nullptr;
435  break;
436  }
437 
438  continue;
439  }
440 
441  // Stupid variable used by the old propagator
442  // For details check BaseParticlePropagator.h
443  int success = 0;
444  if (caloLayer->isForward()) {
445  success = 2;
446  // particle moves inwards
447  if (particle->position().Z() * particle->momentum().Z() < 0) {
448  success *= -1;
449  }
450  } else {
451  success = 1;
452  // particle moves inwards
453  if (particle->momentum().X() * particle->position().X() + particle->momentum().Y() * particle->position().Y() <
454  0) {
455  success *= -1;
456  }
457  }
458 
459  // Save the hit
461  if (!myFSimTrack.onLayer1()) {
462  myFSimTrack.setLayer1(PP, success);
463  }
464  }
465 
467  if (!myFSimTrack.onLayer2()) {
468  myFSimTrack.setLayer2(PP, success);
469  }
470  }
471 
472  if (caloLayer->getCaloType() == fastsim::SimplifiedGeometry::ECAL) {
473  if (!myFSimTrack.onEcal()) {
474  myFSimTrack.setEcal(PP, success);
475  }
476  }
477 
478  if (caloLayer->getCaloType() == fastsim::SimplifiedGeometry::HCAL) {
479  if (!myFSimTrack.onHcal()) {
480  myFSimTrack.setHcal(PP, success);
481  }
482  }
483 
484  if (caloLayer->getCaloType() == fastsim::SimplifiedGeometry::VFCAL) {
485  if (!myFSimTrack.onVFcal()) {
486  myFSimTrack.setVFcal(PP, success);
487  }
488  }
489 
490  // Particle reached end of detector
491  if (caloLayer->getCaloType() == fastsim::SimplifiedGeometry::VFCAL) {
492  myFSimTrack.setGlobal();
493  caloLayer = nullptr;
494  break;
495  }
496 
497  LogDebug(MESSAGECATEGORY) << "--------------------------------"
498  << "\n-------------------------------";
499  }
500 
501  // do decays
502  // don't have to worry about daughters if particle already within the calorimetry
503  // since they will be rejected by the vertex cut of the ParticleFilter
504  if (!particle->isStable() && particle->remainingProperLifeTimeC() < 1E-10) {
505  LogDebug(MESSAGECATEGORY) << "Decaying particle...";
506  std::vector<std::unique_ptr<fastsim::Particle> > secondaries;
507  decayer_.decay(*particle, secondaries, _randomEngine->theEngine());
508  LogDebug(MESSAGECATEGORY) << " decay has " << secondaries.size() << " products";
509  particleManager->addSecondaries(particle->position(), particle->simTrackIndex(), secondaries);
510  }
511 
512  return myFSimTrack;
513 }
fastsim::Geometry caloGeometry_
Hack to interface &quot;old&quot; calo to &quot;new&quot; tracking.
std::unique_ptr< RandomEngineAndDistribution > _randomEngine
The random engine.
Implementation of a generic detector layer (base class for forward/barrel layers).
const math::XYZTLorentzVector & position() const
Return position of the particle.
Definition: Particle.h:140
virtual const double getThickness(const math::XYZTLorentzVector &position) const =0
Return thickness of the layer at a given position.
Handles/tracks (possible) intersections of particle&#39;s trajectory and tracker layers.
double remainingProperLifeTimeC() const
Return the particle&#39;s remaining proper lifetime[in ct].
Definition: Particle.h:150
int genParticleIndex() const
Return index of the particle in the genParticle vector.
Definition: Particle.h:165
fastsim::Decayer decayer_
Handles decays of non-stable particles using pythia.
int pdgId() const
Return pdgId of the particle.
Definition: Particle.h:134
const SimVertex getSimVertex(unsigned i)
Returns the position of a given SimVertex. Needed for interfacing the code with the old calorimetry...
const SimTrack getSimTrack(unsigned i)
Returns a given SimTrack. Needed for interfacing the code with the old calorimetry.
RawParticle makeParticle(HepPDT::ParticleDataTable const *, int id, const math::XYZTLorentzVector &p)
Definition: makeParticle.cc:28
int simVertexIndex() const
Return index of the origin vertex.
Definition: Particle.h:159
CaloType getCaloType() const
Hack to interface &quot;old&quot; Calorimetry with &quot;new&quot; Tracker.
void addSecondaries(const math::XYZTLorentzVector &vertexPosition, int motherSimTrackId, std::vector< std::unique_ptr< Particle > > &secondaries, const SimplifiedGeometry *layer=nullptr)
Adds secondaries that are produced by any of the interactions (or particle decay) to the buffer...
void decay(const Particle &particle, std::vector< std::unique_ptr< Particle > > &secondaries, CLHEP::HepRandomEngine &engine) const
Decay particle using pythia.
Definition: Decayer.cc:29
int simTrackIndex() const
Return index of the SimTrack.
Definition: Particle.h:153
virtual bool isForward() const =0
Returns false/true depending if the object is a (non-abstract) barrel/forward layer.
double charge() const
Return charge of the particle.
Definition: Particle.h:137
static const std::string MESSAGECATEGORY
Category of debugging messages (&quot;FastSimulation&quot;)
bool isStable() const
Returns true if particle is considered stable.
Definition: Particle.h:171
const math::XYZTLorentzVector & momentum() const
Return momentum of the particle.
Definition: Particle.h:143
#define LogDebug(id)
void FastSimProducer::endStream ( )
overrideprivate

Definition at line 377 of file FastSimProducer.cc.

References _randomEngine.

377 { _randomEngine.reset(); }
std::unique_ptr< RandomEngineAndDistribution > _randomEngine
The random engine.
void FastSimProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 174 of file FastSimProducer.cc.

References _randomEngine, funct::abs(), beamPipeRadius_, caloGeometry_, caloGeometryESToken_, caloTopologyESToken_, edm::ESWatcher< T >::check(), createFSimTrack(), fastsim::Decayer::decay(), decayer_, deltaRchargedMother_, genParticleCandidates2GenParticles_cfi::genParticles, genParticlesToken_, geometry_, edm::Event::getByToken(), fastsim::SimplifiedGeometry::getCaloType(), edm::EventSetup::getData(), fastsim::SimplifiedGeometry::getInteractionModels(), fastsim::Geometry::getMagneticFieldZ(), fastsim::SimplifiedGeometry::getThickness(), interactionModelMap_, interactionModels_, phase1PixelTopology::layer, LogDebug, MESSAGECATEGORY, eostools::move(), fastsim::LayerNavigator::moveParticleToNextLayer(), myCalorimetry, particleDataTableESToken_, particleFilter_, edm::Event::put(), simulateCalorimetry, simulateMuons, fastsim::SimplifiedGeometry::TRACKERBOUNDARY, fastsim::Geometry::update(), watchCaloGeometry_, and watchCaloTopology_.

174  {
175  LogDebug(MESSAGECATEGORY) << " produce";
176 
179 
180  // Define containers for SimTracks, SimVertices
181  std::unique_ptr<edm::SimTrackContainer> simTracks_(new edm::SimTrackContainer);
182  std::unique_ptr<edm::SimVertexContainer> simVertices_(new edm::SimVertexContainer);
183 
184  // Get the particle data table (in case lifetime or charge of GenParticles not set)
185  auto const& pdt = iSetup.getData(particleDataTableESToken_);
186 
187  // Get the GenParticle collection
189  iEvent.getByToken(genParticlesToken_, genParticles);
190 
191  // Load the ParticleManager which returns the particles that have to be propagated
192  // Creates a fastsim::Particle out of a GenParticle/secondary
193  fastsim::ParticleManager particleManager(*genParticles->GetEvent(),
194  pdt,
198  *simTracks_,
199  *simVertices_);
200 
201  // Initialize the calorimeter geometry
202  if (simulateCalorimetry) {
203  if (watchCaloGeometry_.check(iSetup) || watchCaloTopology_.check(iSetup)) {
204  auto const& pG = iSetup.getData(caloGeometryESToken_);
205  myCalorimetry->getCalorimeter()->setupGeometry(pG);
206 
207  auto const& theCaloTopology = iSetup.getData(caloTopologyESToken_);
208  myCalorimetry->getCalorimeter()->setupTopology(theCaloTopology);
209  myCalorimetry->getCalorimeter()->initialize(geometry_.getMagneticFieldZ(math::XYZTLorentzVector(0., 0., 0., 0.)));
210 
211  myCalorimetry->getHFShowerLibrary()->initHFShowerLibrary(iSetup);
212  }
213 
214  // Important: this also cleans the calorimetry information from the last event
215  myCalorimetry->initialize(_randomEngine.get());
216  }
217 
218  // The vector of SimTracks needed for the CalorimetryManager
219  std::vector<FSimTrack> myFSimTracks;
220 
221  LogDebug(MESSAGECATEGORY) << "################################"
222  << "\n###############################";
223 
224  // loop over particles
225  for (std::unique_ptr<fastsim::Particle> particle = particleManager.nextParticle(*_randomEngine); particle != nullptr;
226  particle = particleManager.nextParticle(*_randomEngine)) {
227  LogDebug(MESSAGECATEGORY) << "\n moving NEXT particle: " << *particle;
228 
229  // -----------------------------
230  // This condition is necessary because of hack for calorimetry
231  // -> The CalorimetryManager should also be implemented based on this new FastSim classes (Particle.h) in a future project.
232  // A second loop (below) loops over all parts of the calorimetry in order to create a track of the old FastSim class FSimTrack.
233  // The condition below (R<128, z<302) makes sure that the particle geometrically is outside the tracker boundaries
234  // -----------------------------
235 
236  if (particle->position().Perp2() < 128. * 128. && std::abs(particle->position().Z()) < 302.) {
237  // move the particle through the layers
238  fastsim::LayerNavigator layerNavigator(geometry_);
239  const fastsim::SimplifiedGeometry* layer = nullptr;
240 
241  // moveParticleToNextLayer(..) returns 0 in case that particle decays
242  // in this case particle is propagated up to its decay vertex
243  while (layerNavigator.moveParticleToNextLayer(*particle, layer)) {
244  LogDebug(MESSAGECATEGORY) << " moved to next layer: " << *layer;
245  LogDebug(MESSAGECATEGORY) << " new state: " << *particle;
246 
247  // Hack to interface "old" calo to "new" tracking
248  // Particle reached calorimetry so stop further propagation
250  layer = nullptr;
251  // particle no longer is on a layer
252  particle->resetOnLayer();
253  break;
254  }
255 
256  // break after 25 ns: only happens for particles stuck in loops
257  if (particle->position().T() > 25) {
258  layer = nullptr;
259  // particle no longer is on a layer
260  particle->resetOnLayer();
261  break;
262  }
263 
264  // perform interaction between layer and particle
265  // do only if there is actual material
266  if (layer->getThickness(particle->position(), particle->momentum()) > 1E-10) {
267  int nSecondaries = 0;
268  // loop on interaction models
269  for (fastsim::InteractionModel* interactionModel : layer->getInteractionModels()) {
270  LogDebug(MESSAGECATEGORY) << " interact with " << *interactionModel;
271  std::vector<std::unique_ptr<fastsim::Particle> > secondaries;
272  interactionModel->interact(*particle, *layer, secondaries, *_randomEngine);
273  nSecondaries += secondaries.size();
274  particleManager.addSecondaries(particle->position(), particle->simTrackIndex(), secondaries, layer);
275  }
276 
277  // kinematic cuts: particle might e.g. lost all its energy
278  if (!particleFilter_.acceptsEn(*particle)) {
279  // Add endvertex if particle did not create any secondaries
280  if (nSecondaries == 0)
281  particleManager.addEndVertex(particle.get());
282  layer = nullptr;
283  break;
284  }
285  }
286 
287  LogDebug(MESSAGECATEGORY) << "--------------------------------"
288  << "\n-------------------------------";
289  }
290 
291  // do decays
292  if (!particle->isStable() && particle->remainingProperLifeTimeC() < 1E-10) {
293  LogDebug(MESSAGECATEGORY) << "Decaying particle...";
294  std::vector<std::unique_ptr<fastsim::Particle> > secondaries;
295  decayer_.decay(*particle, secondaries, _randomEngine->theEngine());
296  LogDebug(MESSAGECATEGORY) << " decay has " << secondaries.size() << " products";
297  particleManager.addSecondaries(particle->position(), particle->simTrackIndex(), secondaries);
298  continue;
299  }
300 
301  LogDebug(MESSAGECATEGORY) << "################################"
302  << "\n###############################";
303  }
304 
305  // -----------------------------
306  // Hack to interface "old" calorimetry with "new" propagation in tracker
307  // The CalorimetryManager has to know which particle could in principle hit which parts of the calorimeter
308  // I think it's a bit strange to propagate the particle even further (and even decay it) if it already hits
309  // some part of the calorimetry but this is how the code works...
310  // -----------------------------
311 
312  if (particle->position().Perp2() >= 128. * 128. || std::abs(particle->position().Z()) >= 302.) {
313  LogDebug(MESSAGECATEGORY) << "\n moving particle to calorimetry: " << *particle;
314 
315  // create FSimTrack (this is the object the old propagation uses)
316  myFSimTracks.push_back(createFSimTrack(particle.get(), &particleManager, pdt));
317  // particle was decayed
318  if (!particle->isStable() && particle->remainingProperLifeTimeC() < 1E-10) {
319  continue;
320  }
321 
322  LogDebug(MESSAGECATEGORY) << "################################"
323  << "\n###############################";
324  }
325 
326  // -----------------------------
327  // End Hack
328  // -----------------------------
329 
330  LogDebug(MESSAGECATEGORY) << "################################"
331  << "\n###############################";
332  }
333 
334  // store simTracks and simVertices
335  iEvent.put(std::move(simTracks_));
336  iEvent.put(std::move(simVertices_));
337  // store products of interaction models, i.e. simHits
338  for (auto& interactionModel : interactionModels_) {
339  interactionModel->storeProducts(iEvent);
340  }
341 
342  // -----------------------------
343  // Calorimetry Manager
344  // -----------------------------
345  if (simulateCalorimetry) {
346  for (auto myFSimTrack : myFSimTracks) {
347  myCalorimetry->reconstructTrack(myFSimTrack, _randomEngine.get());
348  }
349  }
350 
351  // -----------------------------
352  // Store Hits
353  // -----------------------------
354  std::unique_ptr<edm::PCaloHitContainer> p4(new edm::PCaloHitContainer);
355  std::unique_ptr<edm::PCaloHitContainer> p5(new edm::PCaloHitContainer);
356  std::unique_ptr<edm::PCaloHitContainer> p6(new edm::PCaloHitContainer);
357  std::unique_ptr<edm::PCaloHitContainer> p7(new edm::PCaloHitContainer);
358 
359  std::unique_ptr<edm::SimTrackContainer> m1(new edm::SimTrackContainer);
360 
361  if (simulateCalorimetry) {
362  myCalorimetry->loadFromEcalBarrel(*p4);
363  myCalorimetry->loadFromEcalEndcap(*p5);
364  myCalorimetry->loadFromPreshower(*p6);
365  myCalorimetry->loadFromHcal(*p7);
366  if (simulateMuons) {
367  myCalorimetry->harvestMuonSimTracks(*m1);
368  }
369  }
370  iEvent.put(std::move(p4), "EcalHitsEB");
371  iEvent.put(std::move(p5), "EcalHitsEE");
372  iEvent.put(std::move(p6), "EcalHitsES");
373  iEvent.put(std::move(p7), "HcalHits");
374  iEvent.put(std::move(m1), "MuonSimTracks");
375 }
std::vector< std::unique_ptr< fastsim::InteractionModel > > interactionModels_
All defined interaction models.
edm::ESWatcher< CaloGeometryRecord > watchCaloGeometry_
void update(const edm::EventSetup &iSetup, const std::map< std::string, InteractionModel * > &interactionModelMap)
Initializes the tracker geometry.
Definition: Geometry.cc:55
std::vector< PCaloHit > PCaloHitContainer
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
fastsim::Geometry caloGeometry_
Hack to interface &quot;old&quot; calo to &quot;new&quot; tracking.
std::unique_ptr< RandomEngineAndDistribution > _randomEngine
The random engine.
Implementation of a generic detector layer (base class for forward/barrel layers).
virtual const double getThickness(const math::XYZTLorentzVector &position) const =0
Return thickness of the layer at a given position.
Handles/tracks (possible) intersections of particle&#39;s trajectory and tracker layers.
Manages GenParticles and Secondaries from interactions.
double deltaRchargedMother_
Cut on deltaR for ClosestChargedDaughter algorithm (FastSim tracking)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
fastsim::Geometry geometry_
The definition of the tracker according to python config.
edm::EDGetTokenT< edm::HepMCProduct > genParticlesToken_
Token to get the genParticles.
fastsim::Decayer decayer_
Handles decays of non-stable particles using pythia.
virtual FSimTrack createFSimTrack(fastsim::Particle *particle, fastsim::ParticleManager *particleManager, HepPDT::ParticleDataTable const &particleTable)
constexpr std::array< uint8_t, layerIndexSize > layer
bool getData(T &iHolder) const
Definition: EventSetup.h:128
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
Base class for any interaction model between a particle and a tracker layer.
const edm::ESGetToken< HepPDT::ParticleDataTable, edm::DefaultRecord > particleDataTableESToken_
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryESToken_
CaloType getCaloType() const
Hack to interface &quot;old&quot; Calorimetry with &quot;new&quot; Tracker.
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double beamPipeRadius_
The radius of the beampipe.
void decay(const Particle &particle, std::vector< std::unique_ptr< Particle > > &secondaries, CLHEP::HepRandomEngine &engine) const
Decay particle using pythia.
Definition: Decayer.cc:29
edm::ESWatcher< CaloTopologyRecord > watchCaloTopology_
const std::vector< InteractionModel * > & getInteractionModels() const
Return the vector of all interaction models that are assigned with a layer.
edm::ESGetToken< CaloTopology, CaloTopologyRecord > caloTopologyESToken_
std::vector< SimVertex > SimVertexContainer
std::map< std::string, fastsim::InteractionModel * > interactionModelMap_
Each interaction model has a unique name.
static const std::string MESSAGECATEGORY
Category of debugging messages (&quot;FastSimulation&quot;)
std::unique_ptr< CalorimetryManager > myCalorimetry
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
std::vector< SimTrack > SimTrackContainer
double getMagneticFieldZ(const math::XYZTLorentzVector &position) const
Initializes the tracker geometry.
Definition: Geometry.cc:156
fastsim::ParticleFilter particleFilter_
Decides which particles have to be propagated.
#define LogDebug(id)

Member Data Documentation

std::unique_ptr<RandomEngineAndDistribution> FastSimProducer::_randomEngine
private

The random engine.

Definition at line 83 of file FastSimProducer.cc.

Referenced by beginStream(), createFSimTrack(), endStream(), and produce().

double FastSimProducer::beamPipeRadius_
private

The radius of the beampipe.

Definition at line 80 of file FastSimProducer.cc.

Referenced by produce().

fastsim::Geometry FastSimProducer::caloGeometry_
private

Hack to interface "old" calo to "new" tracking.

Definition at line 79 of file FastSimProducer.cc.

Referenced by createFSimTrack(), and produce().

edm::ESGetToken<CaloGeometry, CaloGeometryRecord> FastSimProducer::caloGeometryESToken_
private

Definition at line 96 of file FastSimProducer.cc.

Referenced by FastSimProducer(), and produce().

edm::ESGetToken<CaloTopology, CaloTopologyRecord> FastSimProducer::caloTopologyESToken_
private

Definition at line 97 of file FastSimProducer.cc.

Referenced by FastSimProducer(), and produce().

fastsim::Decayer FastSimProducer::decayer_
private

Handles decays of non-stable particles using pythia.

Definition at line 91 of file FastSimProducer.cc.

Referenced by createFSimTrack(), and produce().

double FastSimProducer::deltaRchargedMother_
private

Cut on deltaR for ClosestChargedDaughter algorithm (FastSim tracking)

Definition at line 81 of file FastSimProducer.cc.

Referenced by produce().

edm::EDGetTokenT<edm::HepMCProduct> FastSimProducer::genParticlesToken_
private

Token to get the genParticles.

Definition at line 77 of file FastSimProducer.cc.

Referenced by produce().

fastsim::Geometry FastSimProducer::geometry_
private

The definition of the tracker according to python config.

Definition at line 78 of file FastSimProducer.cc.

Referenced by produce().

std::map<std::string, fastsim::InteractionModel*> FastSimProducer::interactionModelMap_
private

Each interaction model has a unique name.

Definition at line 93 of file FastSimProducer.cc.

Referenced by FastSimProducer(), and produce().

std::vector<std::unique_ptr<fastsim::InteractionModel> > FastSimProducer::interactionModels_
private

All defined interaction models.

Definition at line 92 of file FastSimProducer.cc.

Referenced by FastSimProducer(), and produce().

const std::string FastSimProducer::MESSAGECATEGORY = "FastSimulation"
staticprivate

Category of debugging messages ("FastSimulation")

Definition at line 94 of file FastSimProducer.cc.

Referenced by createFSimTrack(), and produce().

std::unique_ptr<CalorimetryManager> FastSimProducer::myCalorimetry
private

Definition at line 88 of file FastSimProducer.cc.

Referenced by FastSimProducer(), and produce().

const edm::ESGetToken<HepPDT::ParticleDataTable, edm::DefaultRecord> FastSimProducer::particleDataTableESToken_
private

Definition at line 95 of file FastSimProducer.cc.

Referenced by produce().

fastsim::ParticleFilter FastSimProducer::particleFilter_
private

Decides which particles have to be propagated.

Definition at line 82 of file FastSimProducer.cc.

Referenced by produce().

bool FastSimProducer::simulateCalorimetry
private

Definition at line 85 of file FastSimProducer.cc.

Referenced by FastSimProducer(), and produce().

bool FastSimProducer::simulateMuons
private

Definition at line 89 of file FastSimProducer.cc.

Referenced by produce().

edm::ESWatcher<CaloGeometryRecord> FastSimProducer::watchCaloGeometry_
private

Definition at line 86 of file FastSimProducer.cc.

Referenced by produce().

edm::ESWatcher<CaloTopologyRecord> FastSimProducer::watchCaloTopology_
private

Definition at line 87 of file FastSimProducer.cc.

Referenced by produce().