CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
MuonSimHitProducer Class Reference

#include <FastSimulation/MuonSimHitProducer/src/MuonSimHitProducer.cc>

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

Public Member Functions

 MuonSimHitProducer (const edm::ParameterSet &)
 
 ~MuonSimHitProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

Private Member Functions

void applyMaterialEffects (TrajectoryStateOnSurface &tsosWithdEdx, TrajectoryStateOnSurface &tsos, double radPath, RandomEngineAndDistribution const *, HepPDT::ParticleDataTable const &)
 Simulate material effects in iron (dE/dx, multiple scattering) More...
 
void beginRun (edm::Run const &run, const edm::EventSetup &es) override
 
void produce (edm::Event &, const edm::EventSetup &) override
 
void readParameters (const edm::ParameterSet &, const edm::ParameterSet &, const edm::ParameterSet &)
 

Private Attributes

const CSCGeometrycscGeom
 
bool doGL_
 
bool doL1_
 
bool doL3_
 
const DTGeometrydtGeom
 
double fCSC
 
double fDT
 
bool fullPattern_
 
double kCSC
 
double kDT
 
const MagneticFieldmagfield
 
const PropagatorpropagatorWithMaterial
 
PropagatorpropagatorWithoutMaterial
 
const RPCGeometryrpcGeom
 
edm::InputTag simMuonLabel
 
edm::EDGetTokenT< std::vector< SimTrack > > simMuonToken
 
edm::InputTag simVertexLabel
 
edm::EDGetTokenT< std::vector< SimVertex > > simVertexToken
 
Chi2MeasurementEstimator theEstimator
 
MaterialEffectstheMaterialEffects
 
MuonServiceProxytheService
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Description: <one line="" class="" summary>="">

Implementation: <Notes on="" implementation>="">

Description: Fast simulation producer of Muon Sim Hits (to be used for realistic Muon reconstruction)

Implementation: <Notes on="" implementation>="">

Definition at line 59 of file MuonSimHitProducer.h.

Constructor & Destructor Documentation

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

Definition at line 77 of file MuonSimHitProducer.cc.

References edm::ParameterSet::getParameter(), MuonServiceProxy_cff::MuonServiceProxy, readParameters(), simMuonLabel, simMuonToken, simVertexLabel, simVertexToken, and theService.

77  :
78  theEstimator(iConfig.getParameter<double>("Chi2EstimatorCut")),
80  {
81 
82  // Read relevant parameters
84  iConfig.getParameter<edm::ParameterSet>("TRACKS"),
85  iConfig.getParameter<edm::ParameterSet>("MaterialEffectsForMuons"));
86 
87  //
88  // register your products ... need to declare at least one possible product...
89  //
90  produces<edm::PSimHitContainer>("MuonCSCHits");
91  produces<edm::PSimHitContainer>("MuonDTHits");
92  produces<edm::PSimHitContainer>("MuonRPCHits");
93 
94  edm::ParameterSet serviceParameters =
95  iConfig.getParameter<edm::ParameterSet>("ServiceParameters");
96  theService = new MuonServiceProxy(serviceParameters);
97 
98  // consumes
99  simMuonToken = consumes<std::vector<SimTrack> >(simMuonLabel);
100  simVertexToken = consumes<std::vector<SimVertex> >(simVertexLabel);
101 
102 }
T getParameter(std::string const &) const
edm::EDGetTokenT< std::vector< SimVertex > > simVertexToken
Propagator * propagatorWithoutMaterial
edm::EDGetTokenT< std::vector< SimTrack > > simMuonToken
MuonServiceProxy * theService
void readParameters(const edm::ParameterSet &, const edm::ParameterSet &, const edm::ParameterSet &)
edm::InputTag simMuonLabel
edm::InputTag simVertexLabel
Chi2MeasurementEstimator theEstimator
MuonSimHitProducer::~MuonSimHitProducer ( )
override

Definition at line 135 of file MuonSimHitProducer.cc.

References propagatorWithoutMaterial, and theMaterialEffects.

136 {
137  // do anything here that needs to be done at destruction time
138  // (e.g. close files, deallocate resources etc.)
139 
142 }
MaterialEffects * theMaterialEffects
Propagator * propagatorWithoutMaterial

Member Function Documentation

void MuonSimHitProducer::applyMaterialEffects ( TrajectoryStateOnSurface tsosWithdEdx,
TrajectoryStateOnSurface tsos,
double  radPath,
RandomEngineAndDistribution const *  random,
HepPDT::ParticleDataTable const &  table 
)
private

Simulate material effects in iron (dE/dx, multiple scattering)

Definition at line 569 of file MuonSimHitProducer.cc.

References ALCARECOTkAlJpsiMuMu_cff::charge, TrajectoryStateOnSurface::charge(), DEFINE_FWK_MODULE, EnergyLossSimulator::deltaMom(), MaterialEffects::energyLossSimulator(), objects.autophobj::float, TrajectoryStateOnSurface::globalMomentum(), TrajectoryStateOnSurface::globalPosition(), PV3DBase< T, PVType, FrameType >::mag2(), magfield, rawparticle::makeMuon(), RawParticle::momentum(), EnergyLossSimulator::mostLikelyLoss(), RPCpg::mu, MaterialEffects::multipleScatteringSimulator(), MaterialEffects::muonBremsstrahlungSimulator(), BaseParticlePropagator::particle(), position, RawParticle::Px(), RawParticle::Py(), RawParticle::Pz(), RawParticle::setMomentum(), MaterialEffectsSimulator::setNormalVector(), RawParticle::setVertex(), mathSSE::sqrt(), TrajectoryStateOnSurface::surface(), Surface::tangentPlane(), theMaterialEffects, MaterialEffectsSimulator::updateState(), RawParticle::vertex(), PV3DBase< T, PVType, FrameType >::x(), RawParticle::X(), PV3DBase< T, PVType, FrameType >::y(), RawParticle::Y(), PV3DBase< T, PVType, FrameType >::z(), and RawParticle::Z().

Referenced by produce().

573  {
574 
575  // The energy loss simulator
577 
578  // The multiple scattering simulator
580 
581  // The Muon Bremsstrahlung simulator
583 
584 
585  // Initialize the Particle position, momentum and energy
586  const Surface& nextSurface = tsos.surface();
587  GlobalPoint gPos = energyLoss ? tsos.globalPosition() : tsosWithdEdx.globalPosition();
588  GlobalVector gMom = energyLoss ? tsos.globalMomentum() : tsosWithdEdx.globalMomentum();
589  double mu = 0.1056583692;
590  double en = std::sqrt(gMom.mag2()+mu*mu);
591 
592  // And now create the Particle
593  XYZTLorentzVector position(gPos.x(),gPos.y(),gPos.z(),0.);
594  XYZTLorentzVector momentum(gMom.x(),gMom.y(),gMom.z(),en);
595  float charge = (float)(tsos.charge());
596  ParticlePropagator theMuon(rawparticle::makeMuon(charge<1.,momentum,position),nullptr,nullptr,&table);
597 
598  // Recompute the energy loss to get the fluctuations
599  if ( energyLoss ) {
600  // Difference between with and without dE/dx (average only)
601  // (for corrections once fluctuations are applied)
602  GlobalPoint gPosWithdEdx = tsosWithdEdx.globalPosition();
603  GlobalVector gMomWithdEdx = tsosWithdEdx.globalMomentum();
604  double enWithdEdx = std::sqrt(gMomWithdEdx.mag2()+mu*mu);
606  deltaPos(gPosWithdEdx.x()-gPos.x(),gPosWithdEdx.y()-gPos.y(),
607  gPosWithdEdx.z()-gPos.z(),0.);
609  deltaMom(gMomWithdEdx.x()-gMom.x(),gMomWithdEdx.y()-gMom.y(),
610  gMomWithdEdx.z()-gMom.z(), enWithdEdx -en);
611 
612  // Energy loss in iron (+ fluctuations)
613  energyLoss->updateState(theMuon, radPath, random);
614 
615  // Correcting factors to account for slight differences in material descriptions
616  // (Material description is more accurate in the stepping helix propagator)
617  radPath *= -deltaMom.E()/energyLoss->mostLikelyLoss();
618  double fac = energyLoss->deltaMom().E()/energyLoss->mostLikelyLoss();
619 
620  // Particle momentum & position after energy loss + fluctuation
621  XYZTLorentzVector theNewMomentum = theMuon.particle().momentum() + energyLoss->deltaMom() + fac * deltaMom;
622  XYZTLorentzVector theNewPosition = theMuon.particle().vertex() + fac * deltaPos;
623  fac = (theNewMomentum.E()*theNewMomentum.E()-mu*mu)/theNewMomentum.Vect().Mag2();
624  fac = fac>0.? std::sqrt(fac) : 1E-9;
625  theMuon.particle().setMomentum(theNewMomentum.Px()*fac,theNewMomentum.Py()*fac,
626  theNewMomentum.Pz()*fac,theNewMomentum.E());
627  theMuon.particle().setVertex(theNewPosition);
628 
629  }
630 
631  // Does the actual mutliple scattering
632  if ( multipleScattering ) {
633  // Pass the vector normal to the "next" surface
634  GlobalVector normal = nextSurface.tangentPlane(tsos.globalPosition())->normalVector();
635  multipleScattering->setNormalVector(normal);
636  // Compute the amount of multiple scattering after a given path length
637  multipleScattering->updateState(theMuon, radPath, random);
638  }
639 
640  // Muon Bremsstrahlung
641  if ( bremsstrahlung ) {
642  // Compute the amount of Muon Bremsstrahlung after given path length
643  bremsstrahlung->updateState(theMuon, radPath, random);
644  }
645 
646 
647  // Fill the propagated state
648  GlobalPoint propagatedPosition(theMuon.particle().X(),theMuon.particle().Y(),theMuon.particle().Z());
649  GlobalVector propagatedMomentum(theMuon.particle().Px(),theMuon.particle().Py(),theMuon.particle().Pz());
650  GlobalTrajectoryParameters propagatedGtp(propagatedPosition,propagatedMomentum,(int)charge,magfield);
651  tsosWithdEdx = TrajectoryStateOnSurface(propagatedGtp,nextSurface);
652 
653 }
double mostLikelyLoss() const
Return most probable energy loss.
const MagneticField * magfield
T mag2() const
Definition: PV3DBase.h:66
virtual ConstReferenceCountingPointer< TangentPlane > tangentPlane(const GlobalPoint &) const =0
void setNormalVector(const GlobalVector &normal)
Sets the vector normal to the surface traversed.
MaterialEffects * theMaterialEffects
MultipleScatteringSimulator * multipleScatteringSimulator() const
Return the Multiple Scattering engine.
T y() const
Definition: PV3DBase.h:63
GlobalPoint globalPosition() const
void updateState(ParticlePropagator &myTrack, double radlen, RandomEngineAndDistribution const *)
Compute the material effect (calls the sub class)
RawParticle makeMuon(bool isParticle, const math::XYZTLorentzVector &p, const math::XYZTLorentzVector &xStart)
Definition: makeMuon.cc:20
TRandom random
Definition: MVATrainer.cc:138
MuonBremsstrahlungSimulator * muonBremsstrahlungSimulator() const
Return the Muon Bremsstrahlung engine.
const SurfaceType & surface() const
T sqrt(T t)
Definition: SSEVec.h:18
T z() const
Definition: PV3DBase.h:64
const XYZTLorentzVector & deltaMom() const
Returns the actual energy lost.
const int mu
Definition: Constants.h:22
GlobalVector globalMomentum() const
static int position[264][3]
Definition: ReadPGInfo.cc:509
EnergyLossSimulator * energyLossSimulator() const
Return the Energy Loss engine.
T x() const
Definition: PV3DBase.h:62
math::XYZTLorentzVector XYZTLorentzVector
Definition: RawParticle.h:27
void MuonSimHitProducer::beginRun ( edm::Run const &  run,
const edm::EventSetup es 
)
overrideprivate

Definition at line 106 of file MuonSimHitProducer.cc.

References Propagator::clone(), cscGeom, dtGeom, edm::EventSetup::get(), magfield, PhotonConversionTrajectorySeedProducerFromQuadruplets_cfi::propagator, MuonServiceProxy::propagator(), propagatorWithMaterial, propagatorWithoutMaterial, rpcGeom, SteppingHelixPropagator::setMaterialMode(), theService, and MuonServiceProxy::update().

106  {
107 
108  //services
110  edm::ESHandle<DTGeometry> dtGeometry;
111  edm::ESHandle<CSCGeometry> cscGeometry;
112  edm::ESHandle<RPCGeometry> rpcGeometry;
114 
115  es.get<IdealMagneticFieldRecord>().get(magField);
116  es.get<MuonGeometryRecord>().get("MisAligned",dtGeometry);
117  es.get<MuonGeometryRecord>().get("MisAligned",cscGeometry);
118  es.get<MuonGeometryRecord>().get(rpcGeometry);
119 
120  magfield = &(*magField);
121  dtGeom = &(*dtGeometry);
122  cscGeom = &(*cscGeometry);
123  rpcGeom = &(*rpcGeometry);
124 
125  theService->update(es);
126 
127  // A few propagators
128  propagatorWithMaterial = &(*(theService->propagator("SteppingHelixPropagatorAny")));
130  SteppingHelixPropagator* SHpropagator = dynamic_cast<SteppingHelixPropagator*> (propagatorWithoutMaterial); // Beuark!
131  SHpropagator->setMaterialMode(true); // switches OFF material effects;
132 
133 }
void update(const edm::EventSetup &setup)
update the services each event
const MagneticField * magfield
virtual Propagator * clone() const =0
const DTGeometry * dtGeom
const RPCGeometry * rpcGeom
const Propagator * propagatorWithMaterial
Propagator * propagatorWithoutMaterial
const CSCGeometry * cscGeom
MuonServiceProxy * theService
T get() const
Definition: EventSetup.h:71
void setMaterialMode(bool noMaterial)
Switch for material effects mode: no material effects if true.
edm::ESHandle< Propagator > propagator(std::string propagatorName) const
get the propagator
void MuonSimHitProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 152 of file MuonSimHitProducer.cc.

References funct::abs(), alongMomentum, anyDirection, applyMaterialEffects(), PV3DBase< T, PVType, FrameType >::basicVector(), Surface::bounds(), relativeConstraints::chamber, RPCGeometry::chamber(), CSCGeometry::chamber(), DTGeometry::chamber(), DTTopology::channel(), CoreSimTrack::charge(), gather_cfg::cout, GeomDetEnumerators::CSC, cscGeom, MuonServiceProxy::detLayerGeometry(), GeomDetEnumerators::DT, dtGeom, CSCDetId::endcap(), mps_splice::entry, cmsRelvalreport::exit, JetChargeProducer_cfi::exp, fCSC, fDT, DTTopology::firstChannel(), TrajectoryStateOnSurface::freeTrajectoryState(), GeomDet::geographicalId(), edm::Event::getByToken(), edm::EventSetup::getData(), SteppingHelixStateInfo::getStateOnSurface(), TrajectoryStateOnSurface::globalMomentum(), TrajectoryStateOnSurface::globalPosition(), mps_fire::i, triggerObjects_cff::id, RPCGeometry::idToDetUnit(), DTGeometry::idToDetUnit(), CSCGeometry::idToDetUnit(), Bounds::inside(), CSCLayerGeometry::inside(), TrajectoryStateOnSurface::isValid(), kCSC, kDT, DTTopology::lastChannel(), DTLayerId::layer(), CSCDetId::layer(), RPCDetId::layer(), LayerTriplets::layers(), TrajectoryStateOnSurface::localMomentum(), cmsBatch::log, funct::m, PV3DBase< T, PVType, FrameType >::mag(), magfield, CoreSimTrack::momentum(), eostools::move(), gen::n, GetRecoTauVFromDQM_MC_cff::next, callgraph::path, SteppingHelixStateInfo::path(), packedPFCandidateRefMixer_cfi::pf, PV3DBase< T, PVType, FrameType >::phi(), pi, sysUtil::pid, PlaneBuilder::plane(), position, Propagator::propagateWithPath(), propagatorWithMaterial, propagatorWithoutMaterial, edm::Event::put(), SteppingHelixStateInfo::radPath(), random, DetId::rawId(), relativeConstraints::ring, RPCDetId::ring(), CSCDetId::ring(), RPCDetId::roll(), RPCChamber::rolls(), makeMuonMisalignmentScenario::rot, GeomDetEnumerators::RPCBarrel, GeomDetEnumerators::RPCEndcap, rpcGeom, DTChamberId::sector(), RPCDetId::sector(), simMuonToken, simVertexToken, HGCalValidator_cfi::simVertices, mathSSE::sqrt(), DTChamberId::station(), relativeConstraints::station, CSCDetId::station(), RPCDetId::station(), edm::Event::streamID(), GeomDet::subDetector(), RPCDetId::subsector(), DTSuperLayerId::superlayer(), DTChamber::superLayers(), GeomDet::surface(), genVertex_cff::t0, theEstimator, theMaterialEffects, theService, PV3DBase< T, PVType, FrameType >::theta(), Bounds::thickness(), GeomDet::toLocal(), SimTrack::trackerSurfaceMomentum(), SimTrack::trackerSurfacePosition(), CoreSimTrack::trackId(), TrajectoryStateOnSurface::transverseCurvature(), CoreSimTrack::type(), Vector3DBase< T, FrameTag >::unit(), SimTrack::vertIndex(), DTChamberId::wheel(), x, PV3DBase< T, PVType, FrameType >::x(), MuonErrorMatrixValues_cff::xAxis, y, PV3DBase< T, PVType, FrameType >::y(), MuonErrorMatrixValues_cff::yAxis, z, PV3DBase< T, PVType, FrameType >::z(), and MetAnalyzer::zAxis.

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), and HTMLExport.HTMLExportStatic::export().

152  {
153  // using namespace edm;
154  // using namespace std;
156  iSetup.getData(pdg);
157 
159 
160  MuonPatternRecoDumper dumper;
161 
164  std::vector<PSimHit> theCSCHits;
165  std::vector<PSimHit> theDTHits;
166  std::vector<PSimHit> theRPCHits;
167 
169  iEvent.getByToken(simMuonToken,simMuons);
170  iEvent.getByToken(simVertexToken,simVertices);
171 
172  for ( unsigned int itrk=0; itrk<simMuons->size(); itrk++ ) {
173  const SimTrack &mySimTrack = (*simMuons)[itrk];
174  math::XYZTLorentzVector mySimP4(mySimTrack.momentum().x(),
175  mySimTrack.momentum().y(),
176  mySimTrack.momentum().z(),
177  mySimTrack.momentum().t());
178 
179  // Decaying hadrons are now in the list, and so are their muon daughter
180  // Ignore the hadrons here.
181  int pid = mySimTrack.type();
182  if ( abs(pid) != 13 ) continue;
183 
184  double t0 = 0;
185  GlobalPoint initialPosition;
186  int ivert = mySimTrack.vertIndex();
187  if ( ivert >= 0 ) {
188  t0 = (*simVertices)[ivert].position().t();
189  GlobalPoint xyzzy((*simVertices)[ivert].position().x(),
190  (*simVertices)[ivert].position().y(),
191  (*simVertices)[ivert].position().z());
192  initialPosition = xyzzy;
193  }
194 //
195 // Presumably t0 has dimensions of cm if not mm?
196 // Convert to ns for internal calculations.
197 // I wonder where we should get c from?
198 //
199  double tof = t0/29.98;
200 
201 #ifdef FAMOS_DEBUG
202  std::cout << " ===> MuonSimHitProducer::reconstruct() found SIMTRACK - pid = "
203  << pid ;
204  std::cout << " : pT = " << mySimP4.Pt()
205  << ", eta = " << mySimP4.Eta()
206  << ", phi = " << mySimP4.Phi() << std::endl;
207 #endif
208 
209 //
210 // Produce muons sim hits starting from undecayed simulated muons
211 //
212 
213  GlobalPoint startingPosition(mySimTrack.trackerSurfacePosition().x(),
214  mySimTrack.trackerSurfacePosition().y(),
215  mySimTrack.trackerSurfacePosition().z());
216  GlobalVector startingMomentum(mySimTrack.trackerSurfaceMomentum().x(),
217  mySimTrack.trackerSurfaceMomentum().y(),
218  mySimTrack.trackerSurfaceMomentum().z());
219 //
220 // Crap... there's no time-of-flight to the trackerSurfacePosition()...
221 // So, this will be wrong when the curvature can't be neglected, but that
222 // will be rather seldom... May as well ignore the mass too.
223 //
224  GlobalVector dtracker = startingPosition-initialPosition;
225  tof += dtracker.mag()/29.98;
226 
227 #ifdef FAMOS_DEBUG
228  std::cout << " the Muon START position " << startingPosition << std::endl;
229  std::cout << " the Muon START momentum " << startingMomentum << std::endl;
230 #endif
231 
232 //
233 // Some magic to define a TrajectoryStateOnSurface
234 //
235  PlaneBuilder pb;
236  GlobalVector zAxis = startingMomentum.unit();
237  GlobalVector yAxis(zAxis.y(),-zAxis.x(),0);
238  GlobalVector xAxis = yAxis.cross(zAxis);
240  PlaneBuilder::ReturnType startingPlane = pb.plane(startingPosition,rot);
241  GlobalTrajectoryParameters gtp(startingPosition,
242  startingMomentum,
243  (int)mySimTrack.charge(),
244  magfield);
245  TrajectoryStateOnSurface startingState(gtp,*startingPlane);
246 
247  std::vector<const DetLayer *> navLayers;
248  if ( fabs(startingState.globalMomentum().eta()) > 4.5 ) {
249  navLayers = navigation.compatibleEndcapLayers(*(startingState.freeState()),
250  alongMomentum);
251  }
252  else {
253  navLayers = navigation.compatibleLayers(*(startingState.freeState()),
254  alongMomentum);
255  }
256  /*
257  edm::ESHandle<Propagator> propagator =
258  theService->propagator("SteppingHelixPropagatorAny");
259  */
260 
261  if ( navLayers.empty() ) continue;
262 
263 #ifdef FAMOS_DEBUG
264  std::cout << "Found " << navLayers.size()
265  << " compatible DetLayers..." << std::endl;
266 #endif
267 
268  TrajectoryStateOnSurface propagatedState = startingState;
269  for ( unsigned int ilayer=0; ilayer<navLayers.size(); ilayer++ ) {
270 
271 #ifdef FAMOS_DEBUG
272  std::cout << "Propagating to layer " << ilayer << " "
273  << dumper.dumpLayer(navLayers[ilayer])
274  << std::endl;
275 #endif
276 
277  std::vector<DetWithState> comps =
278  navLayers[ilayer]->compatibleDets(propagatedState,*propagatorWithMaterial,theEstimator);
279  if ( comps.empty() ) continue;
280 
281 #ifdef FAMOS_DEBUG
282  std::cout << "Propagating " << propagatedState << std::endl;
283 #endif
284 
285  // Starting momentum
286  double pi = propagatedState.globalMomentum().mag();
287 
288  // Propagate with material effects (dE/dx average only)
289  SteppingHelixStateInfo shsStart(*(propagatedState.freeTrajectoryState()));
290  SteppingHelixStateInfo shsDest;
291  ((const SteppingHelixPropagator*)propagatorWithMaterial)->propagate(shsStart,navLayers[ilayer]->surface(),shsDest);
292  std::pair<TrajectoryStateOnSurface,double> next(shsDest.getStateOnSurface(navLayers[ilayer]->surface()),
293  shsDest.path());
294  // No need to continue if there is no valid propagation available.
295  // This happens rarely (~0.1% of ttbar events)
296  if ( !next.first.isValid() ) continue;
297  // This is the estimate of the number of radiation lengths traversed,
298  // together with the total path length
299  double radPath = shsDest.radPath();
300  double pathLength = next.second;
301 
302  // Now propagate without dE/dx (average)
303  // [To add the dE/dx fluctuations to the actual dE/dx]
304  std::pair<TrajectoryStateOnSurface,double> nextNoMaterial =
305  propagatorWithoutMaterial->propagateWithPath(propagatedState,navLayers[ilayer]->surface());
306 
307  // Update the propagated state
308  propagatedState = next.first;
309  double pf = propagatedState.globalMomentum().mag();
310 
311  // Insert dE/dx fluctuations and multiple scattering
312  // Skip this step if nextNoMaterial.first is not valid
313  // This happens rarely (~0.02% of ttbar events)
314  if ( theMaterialEffects && nextNoMaterial.first.isValid() ) applyMaterialEffects(propagatedState, nextNoMaterial.first, radPath, &random, *pdg);
315  // Check that the 'shaken' propagatedState is still valid, otherwise continue
316  if ( !propagatedState.isValid() ) continue;
317  // (No evidence that this ever happens)
318 //
319 // Consider this... 1 GeV muon has a velocity that is only 0.5% slower than c...
320 // We probably can safely ignore the mass for anything that makes it out to the
321 // muon chambers.
322 //
323  double pavg = 0.5*(pi+pf);
324  double m = mySimP4.M();
325  double rbeta = sqrt(1+m*m/(pavg*pavg))/29.98;
326  double dtof = pathLength*rbeta;
327 
328 #ifdef FAMOS_DEBUG
329  std::cout << "Propagated to next surface... path length = " << pathLength
330  << " cm, dTOF = " << dtof << " ns" << std::endl;
331 #endif
332 
333  tof += dtof;
334 
335  for ( unsigned int icomp=0; icomp<comps.size(); icomp++ )
336  {
337  const GeomDet *gd = comps[icomp].first;
338  if ( gd->subDetector() == GeomDetEnumerators::DT ) {
340  const DTChamber *chamber = dtGeom->chamber(id);
341  std::vector<const DTSuperLayer *> superlayer = chamber->superLayers();
342  for ( unsigned int isl=0; isl<superlayer.size(); isl++ ) {
343  std::vector<const DTLayer *> layer = superlayer[isl]->layers();
344  for ( unsigned int ilayer=0; ilayer<layer.size(); ilayer++ ) {
345  DTLayerId lid = layer[ilayer]->id();
346 #ifdef FAMOS_DEBUG
347  std::cout << " Extrapolated to DT ("
348  << lid.wheel() << ","
349  << lid.station() << ","
350  << lid.sector() << ","
351  << lid.superlayer() << ","
352  << lid.layer() << ")" << std::endl;
353 #endif
354 
355  const GeomDetUnit *det = dtGeom->idToDetUnit(lid);
356 
357  HelixArbitraryPlaneCrossing crossing(propagatedState.globalPosition().basicVector(),
358  propagatedState.globalMomentum().basicVector(),
359  propagatedState.transverseCurvature(),
360  anyDirection);
361  std::pair<bool,double> path = crossing.pathLength(det->surface());
362  if ( ! path.first ) continue;
363  LocalPoint lpos = det->toLocal(GlobalPoint(crossing.position(path.second)));
364  if ( ! det->surface().bounds().inside(lpos) ) continue;
365  const DTTopology& dtTopo = layer[ilayer]->specificTopology();
366  int wire = dtTopo.channel(lpos);
367  if (wire - dtTopo.firstChannel() < 0 || wire - dtTopo.lastChannel() > 0 ) continue;
368  // no drift cell here (on the chamber edge or just outside)
369  // this hit would otherwise be discarded downstream in the digitizer
370 
371  DTWireId wid(lid,wire);
372  double thickness = det->surface().bounds().thickness();
373  LocalVector lmom = det->toLocal(GlobalVector(crossing.direction(path.second)));
374  lmom = lmom.unit()*propagatedState.localMomentum().mag();
375 
376  // Factor that takes into account the (rec)hits lost because of delta's, etc.:
377  // (Not fully satisfactory patch, but it seems to work...)
378  double pmu = lmom.mag();
379  double theDTHitIneff = pmu>0? exp(kDT*log(pmu)+fDT):0.;
380  if (random.flatShoot()<theDTHitIneff) continue;
381 
382  double eloss = 0;
383  double pz = fabs(lmom.z());
384  LocalPoint entry = lpos - 0.5*thickness*lmom/pz;
385  LocalPoint exit = lpos + 0.5*thickness*lmom/pz;
386  double dtof = path.second*rbeta;
387  int trkid = mySimTrack.trackId();
388  unsigned int id = wid.rawId();
389  short unsigned int processType = 2;
390  PSimHit hit(entry,exit,lmom.mag(),
391  tof+dtof,eloss,pid,id,trkid,lmom.theta(),lmom.phi(),processType);
392  theDTHits.push_back(hit);
393 
394  }
395  }
396  }
397  else if ( gd->subDetector() == GeomDetEnumerators::CSC ) {
398  CSCDetId id(gd->geographicalId());
399  const CSCChamber *chamber = cscGeom->chamber(id);
400  std::vector<const CSCLayer *> layers = chamber->layers();
401  for ( unsigned int ilayer=0; ilayer<layers.size(); ilayer++ ) {
402  CSCDetId lid = layers[ilayer]->id();
403 
404 #ifdef FAMOS_DEBUG
405  std::cout << " Extrapolated to CSC ("
406  << lid.endcap() << ","
407  << lid.ring() << ","
408  << lid.station() << ","
409  << lid.layer() << ")" << std::endl;
410 #endif
411 
412  const GeomDetUnit *det = cscGeom->idToDetUnit(lid);
413  HelixArbitraryPlaneCrossing crossing(propagatedState.globalPosition().basicVector(),
414  propagatedState.globalMomentum().basicVector(),
415  propagatedState.transverseCurvature(),
416  anyDirection);
417  std::pair<bool,double> path = crossing.pathLength(det->surface());
418  if ( ! path.first ) continue;
419  LocalPoint lpos = det->toLocal(GlobalPoint(crossing.position(path.second)));
420  // For CSCs the Bounds are for chamber frames not gas regions
421  // if ( ! det->surface().bounds().inside(lpos) ) continue;
422  // New function knows where the 'active' volume is:
423  const CSCLayerGeometry* laygeom = layers[ilayer]->geometry();
424  if ( ! laygeom->inside( lpos ) ) continue;
425  //double thickness = laygeom->thickness(); gives number which is about 20 times too big
426  double thickness = det->surface().bounds().thickness(); // this one works much better...
427  LocalVector lmom = det->toLocal(GlobalVector(crossing.direction(path.second)));
428  lmom = lmom.unit()*propagatedState.localMomentum().mag();
429 
430  // Factor that takes into account the (rec)hits lost because of delta's, etc.:
431  // (Not fully satisfactory patch, but it seems to work...)
432  double pmu = lmom.mag();
433  double theCSCHitIneff = pmu>0? exp(kCSC*log(pmu)+fCSC):0.;
434  // Take into account the different geometry in ME11:
435  if (id.station()==1 && id.ring()==1) theCSCHitIneff = theCSCHitIneff*0.442;
436  if (random.flatShoot()<theCSCHitIneff) continue;
437 
438  double eloss = 0;
439  double pz = fabs(lmom.z());
440  LocalPoint entry = lpos - 0.5*thickness*lmom/pz;
441  LocalPoint exit = lpos + 0.5*thickness*lmom/pz;
442  double dtof = path.second*rbeta;
443  int trkid = mySimTrack.trackId();
444  unsigned int id = lid.rawId();
445  short unsigned int processType = 2;
446  PSimHit hit(entry,exit,lmom.mag(),
447  tof+dtof,eloss,pid,id,trkid,lmom.theta(),lmom.phi(),processType);
448  theCSCHits.push_back(hit);
449  }
450  }
451  else if ( gd->subDetector() == GeomDetEnumerators::RPCBarrel ||
453  RPCDetId id(gd->geographicalId());
454  const RPCChamber *chamber = rpcGeom->chamber(id);
455  std::vector<const RPCRoll *> roll = chamber->rolls();
456  for ( unsigned int iroll=0; iroll<roll.size(); iroll++ ) {
457  RPCDetId rid = roll[iroll]->id();
458 
459 #ifdef FAMOS_DEBUG
460  std::cout << " Extrapolated to RPC ("
461  << rid.ring() << ","
462  << rid.station() << ","
463  << rid.sector() << ","
464  << rid.subsector() << ","
465  << rid.layer() << ","
466  << rid.roll() << ")" << std::endl;
467 #endif
468 
469  const GeomDetUnit *det = rpcGeom->idToDetUnit(rid);
470  HelixArbitraryPlaneCrossing crossing(propagatedState.globalPosition().basicVector(),
471  propagatedState.globalMomentum().basicVector(),
472  propagatedState.transverseCurvature(),
473  anyDirection);
474  std::pair<bool,double> path = crossing.pathLength(det->surface());
475  if ( ! path.first ) continue;
476  LocalPoint lpos = det->toLocal(GlobalPoint(crossing.position(path.second)));
477  if ( ! det->surface().bounds().inside(lpos) ) continue;
478  double thickness = det->surface().bounds().thickness();
479  LocalVector lmom = det->toLocal(GlobalVector(crossing.direction(path.second)));
480  lmom = lmom.unit()*propagatedState.localMomentum().mag();
481  double eloss = 0;
482  double pz = fabs(lmom.z());
483  LocalPoint entry = lpos - 0.5*thickness*lmom/pz;
484  LocalPoint exit = lpos + 0.5*thickness*lmom/pz;
485  double dtof = path.second*rbeta;
486  int trkid = mySimTrack.trackId();
487  unsigned int id = rid.rawId();
488  short unsigned int processType = 2;
489  PSimHit hit(entry,exit,lmom.mag(),
490  tof+dtof,eloss,pid,id,trkid,lmom.theta(),lmom.phi(),processType);
491  theRPCHits.push_back(hit);
492  }
493  }
494  else {
495  std::cout << "Extrapolated to unknown subdetector '" << gd->subDetector() << "'..." << std::endl;
496  }
497  }
498  }
499  }
500 
501  std::unique_ptr<edm::PSimHitContainer> pcsc(new edm::PSimHitContainer);
502  int n = 0;
503  for ( std::vector<PSimHit>::const_iterator i = theCSCHits.begin();
504  i != theCSCHits.end(); i++ ) {
505  pcsc->push_back(*i);
506  n += 1;
507  }
508  iEvent.put(std::move(pcsc),"MuonCSCHits");
509 
510  std::unique_ptr<edm::PSimHitContainer> pdt(new edm::PSimHitContainer);
511  n = 0;
512  for ( std::vector<PSimHit>::const_iterator i = theDTHits.begin();
513  i != theDTHits.end(); i++ ) {
514  pdt->push_back(*i);
515  n += 1;
516  }
517  iEvent.put(std::move(pdt),"MuonDTHits");
518 
519  std::unique_ptr<edm::PSimHitContainer> prpc(new edm::PSimHitContainer);
520  n = 0;
521  for ( std::vector<PSimHit>::const_iterator i = theRPCHits.begin();
522  i != theRPCHits.end(); i++ ) {
523  prpc->push_back(*i);
524  n += 1;
525  }
526  iEvent.put(std::move(prpc),"MuonRPCHits");
527 
528 }
edm::ESHandle< MuonDetLayerGeometry > detLayerGeometry() const
get the detLayer geometry
const math::XYZVectorD & trackerSurfacePosition() const
Definition: SimTrack.h:37
std::pair< bool, double > pathLength(const Plane &plane) override
const MagneticField * magfield
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
const GeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: RPCGeometry.cc:48
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
int channel(const LocalPoint &p) const override
Definition: DTTopology.cc:79
const DTGeometry * dtGeom
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
Definition: DTGeometry.cc:117
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
MaterialEffects * theMaterialEffects
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
ReturnType plane(const PositionType &pos, const RotationType &rot) const
Definition: PlaneBuilder.h:22
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
T y() const
Definition: PV3DBase.h:63
GlobalPoint globalPosition() const
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:69
const Bounds & bounds() const
Definition: Surface.h:120
edm::EDGetTokenT< std::vector< SimVertex > > simVertexToken
TRandom random
Definition: MVATrainer.cc:138
int layer() const
Return the layer number.
Definition: DTLayerId.h:53
float charge() const
charge
Definition: CoreSimTrack.cc:17
int layer() const
Definition: CSCDetId.h:61
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
void applyMaterialEffects(TrajectoryStateOnSurface &tsosWithdEdx, TrajectoryStateOnSurface &tsos, double radPath, RandomEngineAndDistribution const *, HepPDT::ParticleDataTable const &)
Simulate material effects in iron (dE/dx, multiple scattering)
int firstChannel() const
Returns the wire number of the first wire.
Definition: DTTopology.h:78
const Double_t pi
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
const RPCGeometry * rpcGeom
LocalVector localMomentum() const
int endcap() const
Definition: CSCDetId.h:93
bool getData(T &iHolder) const
Definition: EventSetup.h:111
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
int lastChannel() const
Returns the wire number of the last wire.
Definition: DTTopology.h:80
const RPCChamber * chamber(RPCDetId id) const
Definition: RPCGeometry.cc:71
virtual bool inside(const Local3DPoint &) const =0
Determine if the point is inside the bounds.
T mag() const
Definition: PV3DBase.h:67
int roll() const
Definition: RPCDetId.h:120
const GeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: DTGeometry.cc:88
FreeTrajectoryState const * freeTrajectoryState(bool withErrors=true) const
const std::vector< const DTSuperLayer * > & superLayers() const
Return the superlayers in the chamber.
Definition: DTChamber.cc:60
int ring() const
Definition: RPCDetId.h:72
const Propagator * propagatorWithMaterial
TrajectoryStateOnSurface getStateOnSurface(const Surface &surf, bool returnTangentPlane=false) const
T sqrt(T t)
Definition: SSEVec.h:18
Propagator * propagatorWithoutMaterial
T z() const
Definition: PV3DBase.h:64
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Surface &) const final
Definition: Propagator.cc:15
const std::vector< const RPCRoll * > & rolls() const
Return the Rolls.
Definition: RPCChamber.cc:68
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const CSCGeometry * cscGeom
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:79
bool inside(const Local3DPoint &, const LocalError &, float scale=1.f) const override
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
Definition: SimTrack.h:30
int superlayer() const
Return the superlayer number (deprecated method name)
int ring() const
Definition: CSCDetId.h:75
Vector3DBase unit() const
Definition: Vector3DBase.h:57
int layer() const
Definition: RPCDetId.h:108
unsigned int trackId() const
Definition: CoreSimTrack.h:31
virtual float thickness() const =0
const math::XYZTLorentzVectorD & trackerSurfaceMomentum() const
Definition: SimTrack.h:39
const CSCChamber * chamber(CSCDetId id) const
Return the chamber corresponding to given DetId.
Definition: CSCGeometry.cc:133
edm::EDGetTokenT< std::vector< SimTrack > > simMuonToken
int sector() const
Sector id: the group of chambers at same phi (and increasing r)
Definition: RPCDetId.h:102
MuonServiceProxy * theService
const GeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: CSCGeometry.cc:108
int subsector() const
SubSector id : some sectors are divided along the phi direction in subsectors (from 1 to 4 in Barrel...
Definition: RPCDetId.h:114
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:22
GlobalVector globalMomentum() const
int sector() const
Definition: DTChamberId.h:61
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:19
static int position[264][3]
Definition: ReadPGInfo.cc:509
TkRotation< float > RotationType
StreamID streamID() const
Definition: Event.h:95
int station() const
Definition: CSCDetId.h:86
std::vector< PSimHit > PSimHitContainer
int station() const
Return the station number.
Definition: DTChamberId.h:51
virtual SubDetector subDetector() const
Which subdetector.
Definition: GeomDet.cc:44
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
T x() const
Definition: PV3DBase.h:62
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:56
def move(src, dest)
Definition: eostools.py:511
Global3DVector GlobalVector
Definition: GlobalVector.h:10
Chi2MeasurementEstimator theEstimator
int station() const
Definition: RPCDetId.h:96
void MuonSimHitProducer::readParameters ( const edm::ParameterSet fastMuons,
const edm::ParameterSet fastTracks,
const edm::ParameterSet matEff 
)
private

Definition at line 531 of file MuonSimHitProducer.cc.

References fCSC, fDT, fullPattern_, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), kCSC, kDT, TrajectoryFactories_cff::MaterialEffects, simMuonLabel, simVertexLabel, AlCaHLTBitMon_QueryRunRegistry::string, and theMaterialEffects.

Referenced by MuonSimHitProducer().

533  {
534  // Muons
535  std::string _simModuleLabel = fastMuons.getParameter<std::string>("simModuleLabel");
536  std::string _simModuleProcess = fastMuons.getParameter<std::string>("simModuleProcess");
537  simMuonLabel = edm::InputTag(_simModuleLabel,_simModuleProcess);
538  simVertexLabel = edm::InputTag(_simModuleLabel);
539 
540  std::vector<double> simHitIneffDT = fastMuons.getParameter<std::vector<double> >("simHitDTIneffParameters");
541  std::vector<double> simHitIneffCSC = fastMuons.getParameter<std::vector<double> >("simHitCSCIneffParameters");
542  kDT = simHitIneffDT[0];
543  fDT = simHitIneffDT[1];
544  kCSC = simHitIneffCSC[0];
545  fCSC = simHitIneffCSC[1];
546 
547  // Tracks
548  fullPattern_ = fastTracks.getUntrackedParameter<bool>("FullPatternRecognition");
549 
550  // The following should be on LogInfo
551  // std::cout << " MUON SIM HITS: FastSimulation parameters " << std::endl;
552  // std::cout << " ============================================== " << std::endl;
553  // if ( fullPattern_ )
554  // std::cout << " The FULL pattern recognition option is turned ON" << std::endl;
555  // else
556  // std::cout << " The FAST tracking option is turned ON" << std::endl;
557 
558  // Material Effects
559  theMaterialEffects = nullptr;
560  if ( matEff.getParameter<bool>("PairProduction") ||
561  matEff.getParameter<bool>("Bremsstrahlung") ||
562  matEff.getParameter<bool>("MuonBremsstrahlung") ||
563  matEff.getParameter<bool>("EnergyLoss") ||
564  matEff.getParameter<bool>("MultipleScattering") )
565  theMaterialEffects = new MaterialEffects(matEff);
566 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
MaterialEffects * theMaterialEffects
edm::InputTag simMuonLabel
edm::InputTag simVertexLabel

Member Data Documentation

const CSCGeometry* MuonSimHitProducer::cscGeom
private

Definition at line 72 of file MuonSimHitProducer.h.

Referenced by beginRun(), and produce().

bool MuonSimHitProducer::doGL_
private

Definition at line 101 of file MuonSimHitProducer.h.

bool MuonSimHitProducer::doL1_
private

Definition at line 101 of file MuonSimHitProducer.h.

bool MuonSimHitProducer::doL3_
private

Definition at line 101 of file MuonSimHitProducer.h.

const DTGeometry* MuonSimHitProducer::dtGeom
private

Definition at line 71 of file MuonSimHitProducer.h.

Referenced by beginRun(), and produce().

double MuonSimHitProducer::fCSC
private

Definition at line 89 of file MuonSimHitProducer.h.

Referenced by produce(), and readParameters().

double MuonSimHitProducer::fDT
private

Definition at line 87 of file MuonSimHitProducer.h.

Referenced by produce(), and readParameters().

bool MuonSimHitProducer::fullPattern_
private

Definition at line 100 of file MuonSimHitProducer.h.

Referenced by readParameters().

double MuonSimHitProducer::kCSC
private

Definition at line 88 of file MuonSimHitProducer.h.

Referenced by produce(), and readParameters().

double MuonSimHitProducer::kDT
private

Definition at line 86 of file MuonSimHitProducer.h.

Referenced by produce(), and readParameters().

const MagneticField* MuonSimHitProducer::magfield
private

Definition at line 70 of file MuonSimHitProducer.h.

Referenced by applyMaterialEffects(), beginRun(), and produce().

const Propagator* MuonSimHitProducer::propagatorWithMaterial
private

Definition at line 74 of file MuonSimHitProducer.h.

Referenced by beginRun(), and produce().

Propagator* MuonSimHitProducer::propagatorWithoutMaterial
private

Definition at line 75 of file MuonSimHitProducer.h.

Referenced by beginRun(), produce(), and ~MuonSimHitProducer().

const RPCGeometry* MuonSimHitProducer::rpcGeom
private

Definition at line 73 of file MuonSimHitProducer.h.

Referenced by beginRun(), and produce().

edm::InputTag MuonSimHitProducer::simMuonLabel
private

Definition at line 104 of file MuonSimHitProducer.h.

Referenced by MuonSimHitProducer(), and readParameters().

edm::EDGetTokenT<std::vector<SimTrack> > MuonSimHitProducer::simMuonToken
private

Definition at line 108 of file MuonSimHitProducer.h.

Referenced by MuonSimHitProducer(), and produce().

edm::InputTag MuonSimHitProducer::simVertexLabel
private

Definition at line 105 of file MuonSimHitProducer.h.

Referenced by MuonSimHitProducer(), and readParameters().

edm::EDGetTokenT<std::vector<SimVertex> > MuonSimHitProducer::simVertexToken
private

Definition at line 109 of file MuonSimHitProducer.h.

Referenced by MuonSimHitProducer(), and produce().

Chi2MeasurementEstimator MuonSimHitProducer::theEstimator
private

Definition at line 68 of file MuonSimHitProducer.h.

Referenced by produce().

MaterialEffects* MuonSimHitProducer::theMaterialEffects
private
MuonServiceProxy* MuonSimHitProducer::theService
private

Definition at line 67 of file MuonSimHitProducer.h.

Referenced by beginRun(), MuonSimHitProducer(), and produce().