CMS 3D CMS Logo

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, CaloGeometryRecordcaloGeometryESToken_
 
edm::ESGetToken< CaloTopology, CaloTopologyRecordcaloTopologyESToken_
 
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::HepMCProductgenParticlesToken_
 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< CalorimetryManagermyCalorimetry
 
const edm::ESGetToken< HepPDT::ParticleDataTable, edm::DefaultRecordparticleDataTableESToken_
 
fastsim::ParticleFilter particleFilter_
 Decides which particles have to be propagated. More...
 
bool simulateCalorimetry
 
bool simulateMuons
 
bool useFastSimsDecayer
 
edm::ESWatcher< CaloGeometryRecordwatchCaloGeometry_
 
edm::ESWatcher< CaloTopologyRecordwatchCaloTopology_
 

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::FastSimProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 103 of file FastSimProducer.cc.

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

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

◆ ~FastSimProducer()

FastSimProducer::~FastSimProducer ( )
inlineoverride

Definition at line 67 of file FastSimProducer.cc.

67 { ; }

Member Function Documentation

◆ beginStream()

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

Definition at line 172 of file FastSimProducer.cc.

References _randomEngine, and l1ctLayer2EG_cff::id.

172  {
173  _randomEngine = std::make_unique<RandomEngineAndDistribution>(id);
174 }
std::unique_ptr< RandomEngineAndDistribution > _randomEngine
The random engine.

◆ createFSimTrack()

FSimTrack FastSimProducer::createFSimTrack ( fastsim::Particle particle,
fastsim::ParticleManager particleManager,
HepPDT::ParticleDataTable const &  particleTable 
)
privatevirtual

Definition at line 386 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, useFastSimsDecayer, and fastsim::SimplifiedGeometry::VFCAL.

Referenced by produce().

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

◆ endStream()

void FastSimProducer::endStream ( )
overrideprivate

Definition at line 384 of file FastSimProducer.cc.

References _randomEngine.

384 { _randomEngine.reset(); }
std::unique_ptr< RandomEngineAndDistribution > _randomEngine
The random engine.

◆ produce()

void FastSimProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 176 of file FastSimProducer.cc.

References _randomEngine, funct::abs(), fastsim::ParticleFilter::acceptsEn(), beamPipeRadius_, caloGeometry_, caloGeometryESToken_, caloTopologyESToken_, edm::ESWatcher< T >::check(), createFSimTrack(), fastsim::Decayer::decay(), decayer_, deltaRchargedMother_, AJJGenJetFilter_cfi::genParticles, genParticlesToken_, geometry_, edm::EventSetup::getData(), fastsim::Geometry::getMagneticFieldZ(), iEvent, interactionModelMap_, interactionModels_, nano_mu_digi_cff::layer, LogDebug, MESSAGECATEGORY, eostools::move(), fastsim::LayerNavigator::moveParticleToNextLayer(), myCalorimetry, particleDataTableESToken_, particleFilter_, simulateCalorimetry, simulateMuons, fastsim::SimplifiedGeometry::TRACKERBOUNDARY, fastsim::Geometry::update(), useFastSimsDecayer, watchCaloGeometry_, and watchCaloTopology_.

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

Member Data Documentation

◆ _randomEngine

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().

◆ beamPipeRadius_

double FastSimProducer::beamPipeRadius_
private

The radius of the beampipe.

Definition at line 80 of file FastSimProducer.cc.

Referenced by produce().

◆ caloGeometry_

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().

◆ caloGeometryESToken_

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

Definition at line 97 of file FastSimProducer.cc.

Referenced by FastSimProducer(), and produce().

◆ caloTopologyESToken_

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

Definition at line 98 of file FastSimProducer.cc.

Referenced by FastSimProducer(), and produce().

◆ decayer_

fastsim::Decayer FastSimProducer::decayer_
private

Handles decays of non-stable particles using pythia.

Definition at line 92 of file FastSimProducer.cc.

Referenced by createFSimTrack(), and produce().

◆ deltaRchargedMother_

double FastSimProducer::deltaRchargedMother_
private

Cut on deltaR for ClosestChargedDaughter algorithm (FastSim tracking)

Definition at line 81 of file FastSimProducer.cc.

Referenced by produce().

◆ genParticlesToken_

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

Token to get the genParticles.

Definition at line 77 of file FastSimProducer.cc.

Referenced by produce().

◆ geometry_

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().

◆ interactionModelMap_

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

Each interaction model has a unique name.

Definition at line 94 of file FastSimProducer.cc.

Referenced by FastSimProducer(), and produce().

◆ interactionModels_

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

All defined interaction models.

Definition at line 93 of file FastSimProducer.cc.

Referenced by FastSimProducer(), and produce().

◆ MESSAGECATEGORY

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

Category of debugging messages ("FastSimulation")

Definition at line 95 of file FastSimProducer.cc.

Referenced by createFSimTrack(), and produce().

◆ myCalorimetry

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

Definition at line 88 of file FastSimProducer.cc.

Referenced by FastSimProducer(), and produce().

◆ particleDataTableESToken_

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

Definition at line 96 of file FastSimProducer.cc.

Referenced by produce().

◆ particleFilter_

fastsim::ParticleFilter FastSimProducer::particleFilter_
private

Decides which particles have to be propagated.

Definition at line 82 of file FastSimProducer.cc.

Referenced by produce().

◆ simulateCalorimetry

bool FastSimProducer::simulateCalorimetry
private

Definition at line 85 of file FastSimProducer.cc.

Referenced by FastSimProducer(), and produce().

◆ simulateMuons

bool FastSimProducer::simulateMuons
private

Definition at line 89 of file FastSimProducer.cc.

Referenced by produce().

◆ useFastSimsDecayer

bool FastSimProducer::useFastSimsDecayer
private

Definition at line 90 of file FastSimProducer.cc.

Referenced by createFSimTrack(), and produce().

◆ watchCaloGeometry_

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

Definition at line 86 of file FastSimProducer.cc.

Referenced by produce().

◆ watchCaloTopology_

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

Definition at line 87 of file FastSimProducer.cc.

Referenced by produce().