CMS 3D CMS Logo

MuonSimHitProducer.cc
Go to the documentation of this file.
1 //
2 // Package: MuonSimHitProducer
3 // Class: MuonSimHitProducer
4 //
14 //
15 // Original Author: Martijn Mulders/Matthew Jones
16 // Created: Wed Jul 30 11:37:24 CET 2007
17 // Working: Fri Nov 9 09:39:33 CST 2007
18 //
19 // $Id: MuonSimHitProducer.cc,v 1.36 2011/10/07 08:25:42 aperrott Exp $
20 //
21 //
22 
50 
52 public:
53  explicit MuonSimHitProducer(const edm::ParameterSet&);
54 
55 private:
58 
64  std::unique_ptr<Propagator> propagatorWithoutMaterial;
65 
66  std::unique_ptr<MaterialEffects> theMaterialEffects;
67 
68  void beginRun(edm::Run const& run, const edm::EventSetup& es) override;
69  void produce(edm::Event&, const edm::EventSetup&) override;
71 
72  // Parameters to emulate the muonSimHit association inefficiency due to delta's
73  double kDT;
74  double fDT;
75  double kCSC;
76  double fCSC;
77 
81  double radPath,
84 
85  // ----------- parameters ----------------------------
87  bool doL1_, doL3_, doGL_;
88 
89  // tags
92 
93  // tokens
96 };
97 
98 //for debug only
99 //#define FAMOS_DEBUG
100 
101 //
102 // constructors and destructor
103 //
105  : theEstimator(iConfig.getParameter<double>("Chi2EstimatorCut")), propagatorWithoutMaterial(nullptr) {
106  // Read relevant parameters
108  iConfig.getParameter<edm::ParameterSet>("TRACKS"),
109  iConfig.getParameter<edm::ParameterSet>("MaterialEffectsForMuons"));
110 
111  //
112  // register your products ... need to declare at least one possible product...
113  //
114  produces<edm::PSimHitContainer>("MuonCSCHits");
115  produces<edm::PSimHitContainer>("MuonDTHits");
116  produces<edm::PSimHitContainer>("MuonRPCHits");
117 
118  edm::ParameterSet serviceParameters = iConfig.getParameter<edm::ParameterSet>("ServiceParameters");
119  theService = new MuonServiceProxy(serviceParameters, consumesCollector(), MuonServiceProxy::UseEventSetupIn::Run);
120 
121  // consumes
122  simMuonToken = consumes<std::vector<SimTrack> >(simMuonLabel);
123  simVertexToken = consumes<std::vector<SimVertex> >(simVertexLabel);
124 }
125 
126 // ---- method called once each job just before starting event loop ----
128  //services
130  edm::ESHandle<DTGeometry> dtGeometry;
131  edm::ESHandle<CSCGeometry> cscGeometry;
132  edm::ESHandle<RPCGeometry> rpcGeometry;
134 
135  es.get<IdealMagneticFieldRecord>().get(magField);
136  es.get<MuonGeometryRecord>().get("MisAligned", dtGeometry);
137  es.get<MuonGeometryRecord>().get("MisAligned", cscGeometry);
138  es.get<MuonGeometryRecord>().get(rpcGeometry);
139 
140  magfield = &(*magField);
141  dtGeom = &(*dtGeometry);
142  cscGeom = &(*cscGeometry);
143  rpcGeom = &(*rpcGeometry);
144 
145  bool duringEvent = false;
146  theService->update(es, duringEvent);
147 
148  // A few propagators
149  propagatorWithMaterial = &(*(theService->propagator("SteppingHelixPropagatorAny")));
151  SteppingHelixPropagator* SHpropagator =
152  dynamic_cast<SteppingHelixPropagator*>(propagatorWithoutMaterial.get()); // Beuark!
153  SHpropagator->setMaterialMode(true); // switches OFF material effects;
154 }
155 
156 //
157 // member functions
158 //
159 
160 // ------------ method called to produce the data ------------
161 
163  // using namespace edm;
164  // using namespace std;
166  iSetup.getData(pdg);
167 
168  RandomEngineAndDistribution random(iEvent.streamID());
169 
170  MuonPatternRecoDumper dumper;
171 
174  std::vector<PSimHit> theCSCHits;
175  std::vector<PSimHit> theDTHits;
176  std::vector<PSimHit> theRPCHits;
177 
179  iEvent.getByToken(simMuonToken, simMuons);
180  iEvent.getByToken(simVertexToken, simVertices);
181 
182  for (unsigned int itrk = 0; itrk < simMuons->size(); itrk++) {
183  const SimTrack& mySimTrack = (*simMuons)[itrk];
184  math::XYZTLorentzVector mySimP4(
185  mySimTrack.momentum().x(), mySimTrack.momentum().y(), mySimTrack.momentum().z(), mySimTrack.momentum().t());
186 
187  // Decaying hadrons are now in the list, and so are their muon daughter
188  // Ignore the hadrons here.
189  int pid = mySimTrack.type();
190  if (abs(pid) != 13 && abs(pid) != 1000024)
191  continue;
192  double t0 = 0;
193  GlobalPoint initialPosition;
194  int ivert = mySimTrack.vertIndex();
195  if (ivert >= 0) {
196  t0 = (*simVertices)[ivert].position().t();
197  GlobalPoint xyzzy((*simVertices)[ivert].position().x(),
198  (*simVertices)[ivert].position().y(),
199  (*simVertices)[ivert].position().z());
200  initialPosition = xyzzy;
201  }
202  //
203  // Presumably t0 has dimensions of cm if not mm?
204  // Convert to ns for internal calculations.
205  // I wonder where we should get c from?
206  //
207  double tof = t0 / 29.98;
208 
209 #ifdef FAMOS_DEBUG
210  std::cout << " ===> MuonSimHitProducer::reconstruct() found SIMTRACK - pid = " << pid;
211  std::cout << " : pT = " << mySimP4.Pt() << ", eta = " << mySimP4.Eta() << ", phi = " << mySimP4.Phi() << std::endl;
212 #endif
213 
214  //
215  // Produce muons sim hits starting from undecayed simulated muons
216  //
217 
218  GlobalPoint startingPosition(mySimTrack.trackerSurfacePosition().x(),
219  mySimTrack.trackerSurfacePosition().y(),
220  mySimTrack.trackerSurfacePosition().z());
221  GlobalVector startingMomentum(mySimTrack.trackerSurfaceMomentum().x(),
222  mySimTrack.trackerSurfaceMomentum().y(),
223  mySimTrack.trackerSurfaceMomentum().z());
224  //
225  // Crap... there's no time-of-flight to the trackerSurfacePosition()...
226  // So, this will be wrong when the curvature can't be neglected, but that
227  // will be rather seldom... May as well ignore the mass too.
228  //
229  GlobalVector dtracker = startingPosition - initialPosition;
230  tof += dtracker.mag() / 29.98;
231 
232 #ifdef FAMOS_DEBUG
233  std::cout << " the Muon START position " << startingPosition << std::endl;
234  std::cout << " the Muon START momentum " << startingMomentum << std::endl;
235 #endif
236 
237  //
238  // Some magic to define a TrajectoryStateOnSurface
239  //
240  PlaneBuilder pb;
241  GlobalVector zAxis = startingMomentum.unit();
242  GlobalVector yAxis(zAxis.y(), -zAxis.x(), 0);
243  GlobalVector xAxis = yAxis.cross(zAxis);
245  PlaneBuilder::ReturnType startingPlane = pb.plane(startingPosition, rot);
246  GlobalTrajectoryParameters gtp(startingPosition, startingMomentum, (int)mySimTrack.charge(), magfield);
247  TrajectoryStateOnSurface startingState(gtp, *startingPlane);
248 
249  std::vector<const DetLayer*> navLayers;
250  if (fabs(startingState.globalMomentum().eta()) > 4.5) {
251  navLayers = navigation.compatibleEndcapLayers(*(startingState.freeState()), alongMomentum);
252  } else {
253  navLayers = navigation.compatibleLayers(*(startingState.freeState()), alongMomentum);
254  }
255  /*
256  edm::ESHandle<Propagator> propagator =
257  theService->propagator("SteppingHelixPropagatorAny");
258  */
259 
260  if (navLayers.empty())
261  continue;
262 
263 #ifdef FAMOS_DEBUG
264  std::cout << "Found " << navLayers.size() << " compatible DetLayers..." << std::endl;
265 #endif
266 
267  TrajectoryStateOnSurface propagatedState = startingState;
268  for (unsigned int ilayer = 0; ilayer < navLayers.size(); ilayer++) {
269 #ifdef FAMOS_DEBUG
270  std::cout << "Propagating to layer " << ilayer << " " << dumper.dumpLayer(navLayers[ilayer]) << std::endl;
271 #endif
272 
273  std::vector<DetWithState> comps =
274  navLayers[ilayer]->compatibleDets(propagatedState, *propagatorWithMaterial, theEstimator);
275  if (comps.empty())
276  continue;
277 
278 #ifdef FAMOS_DEBUG
279  std::cout << "Propagating " << propagatedState << std::endl;
280 #endif
281 
282  // Starting momentum
283  double pi = propagatedState.globalMomentum().mag();
284 
285  // Propagate with material effects (dE/dx average only)
286  SteppingHelixStateInfo shsStart(*(propagatedState.freeTrajectoryState()));
287  SteppingHelixStateInfo shsDest;
289  ->propagate(shsStart, navLayers[ilayer]->surface(), shsDest);
290  std::pair<TrajectoryStateOnSurface, double> next(shsDest.getStateOnSurface(navLayers[ilayer]->surface()),
291  shsDest.path());
292  // No need to continue if there is no valid propagation available.
293  // This happens rarely (~0.1% of ttbar events)
294  if (!next.first.isValid())
295  continue;
296  // This is the estimate of the number of radiation lengths traversed,
297  // together with the total path length
298  double radPath = shsDest.radPath();
299  double pathLength = next.second;
300 
301  // Now propagate without dE/dx (average)
302  // [To add the dE/dx fluctuations to the actual dE/dx]
303  std::pair<TrajectoryStateOnSurface, double> nextNoMaterial =
304  propagatorWithoutMaterial->propagateWithPath(propagatedState, navLayers[ilayer]->surface());
305 
306  // Update the propagated state
307  propagatedState = next.first;
308  double pf = propagatedState.globalMomentum().mag();
309 
310  // Insert dE/dx fluctuations and multiple scattering
311  // Skip this step if nextNoMaterial.first is not valid
312  // This happens rarely (~0.02% of ttbar events)
313  if (theMaterialEffects && nextNoMaterial.first.isValid())
314  applyMaterialEffects(propagatedState, nextNoMaterial.first, radPath, &random, *pdg);
315  // Check that the 'shaken' propagatedState is still valid, otherwise continue
316  if (!propagatedState.isValid())
317  continue;
318  // (No evidence that this ever happens)
319  //
320  // Consider this... 1 GeV muon has a velocity that is only 0.5% slower than c...
321  // We probably can safely ignore the mass for anything that makes it out to the
322  // muon chambers.
323  //
324  double pavg = 0.5 * (pi + pf);
325  double m = mySimP4.M();
326  double rbeta = sqrt(1 + m * m / (pavg * pavg)) / 29.98;
327  double dtof = pathLength * rbeta;
328 
329 #ifdef FAMOS_DEBUG
330  std::cout << "Propagated to next surface... path length = " << pathLength << " cm, dTOF = " << dtof << " ns"
331  << std::endl;
332 #endif
333 
334  tof += dtof;
335 
336  for (unsigned int icomp = 0; icomp < comps.size(); icomp++) {
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 (" << lid.wheel() << "," << lid.station() << "," << lid.sector()
348  << "," << lid.superlayer() << "," << lid.layer() << ")" << std::endl;
349 #endif
350 
351  const GeomDetUnit* det = dtGeom->idToDetUnit(lid);
352 
353  HelixArbitraryPlaneCrossing crossing(propagatedState.globalPosition().basicVector(),
354  propagatedState.globalMomentum().basicVector(),
355  propagatedState.transverseCurvature(),
356  anyDirection);
357  std::pair<bool, double> path = crossing.pathLength(det->surface());
358  if (!path.first)
359  continue;
360  LocalPoint lpos = det->toLocal(GlobalPoint(crossing.position(path.second)));
361  if (!det->surface().bounds().inside(lpos))
362  continue;
363  const DTTopology& dtTopo = layer[ilayer]->specificTopology();
364  int wire = dtTopo.channel(lpos);
365  if (wire - dtTopo.firstChannel() < 0 || wire - dtTopo.lastChannel() > 0)
366  continue;
367  // no drift cell here (on the chamber edge or just outside)
368  // this hit would otherwise be discarded downstream in the digitizer
369 
370  DTWireId wid(lid, wire);
371  double thickness = det->surface().bounds().thickness();
372  LocalVector lmom = det->toLocal(GlobalVector(crossing.direction(path.second)));
373  lmom = lmom.unit() * propagatedState.localMomentum().mag();
374 
375  // Factor that takes into account the (rec)hits lost because of delta's, etc.:
376  // (Not fully satisfactory patch, but it seems to work...)
377  double pmu = lmom.mag();
378  double theDTHitIneff = pmu > 0 ? exp(kDT * log(pmu) + fDT) : 0.;
379  if (random.flatShoot() < theDTHitIneff)
380  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(
391  entry, exit, lmom.mag(), tof + dtof, eloss, pid, id, trkid, lmom.theta(), lmom.phi(), processType);
392  theDTHits.push_back(hit);
393  }
394  }
395  } else if (gd->subDetector() == GeomDetEnumerators::CSC) {
396  CSCDetId id(gd->geographicalId());
397  const CSCChamber* chamber = cscGeom->chamber(id);
398  std::vector<const CSCLayer*> layers = chamber->layers();
399  for (unsigned int ilayer = 0; ilayer < layers.size(); ilayer++) {
400  CSCDetId lid = layers[ilayer]->id();
401 
402 #ifdef FAMOS_DEBUG
403  std::cout << " Extrapolated to CSC (" << lid.endcap() << "," << lid.ring() << "," << lid.station() << ","
404  << lid.layer() << ")" << std::endl;
405 #endif
406 
407  const GeomDetUnit* det = cscGeom->idToDetUnit(lid);
408  HelixArbitraryPlaneCrossing crossing(propagatedState.globalPosition().basicVector(),
409  propagatedState.globalMomentum().basicVector(),
410  propagatedState.transverseCurvature(),
411  anyDirection);
412  std::pair<bool, double> path = crossing.pathLength(det->surface());
413  if (!path.first)
414  continue;
415  LocalPoint lpos = det->toLocal(GlobalPoint(crossing.position(path.second)));
416  // For CSCs the Bounds are for chamber frames not gas regions
417  // if ( ! det->surface().bounds().inside(lpos) ) continue;
418  // New function knows where the 'active' volume is:
419  const CSCLayerGeometry* laygeom = layers[ilayer]->geometry();
420  if (!laygeom->inside(lpos))
421  continue;
422  //double thickness = laygeom->thickness(); gives number which is about 20 times too big
423  double thickness = det->surface().bounds().thickness(); // this one works much better...
424  LocalVector lmom = det->toLocal(GlobalVector(crossing.direction(path.second)));
425  lmom = lmom.unit() * propagatedState.localMomentum().mag();
426 
427  // Factor that takes into account the (rec)hits lost because of delta's, etc.:
428  // (Not fully satisfactory patch, but it seems to work...)
429  double pmu = lmom.mag();
430  double theCSCHitIneff = pmu > 0 ? exp(kCSC * log(pmu) + fCSC) : 0.;
431  // Take into account the different geometry in ME11:
432  if (id.station() == 1 && id.ring() == 1)
433  theCSCHitIneff = theCSCHitIneff * 0.442;
434  if (random.flatShoot() < theCSCHitIneff)
435  continue;
436 
437  double eloss = 0;
438  double pz = fabs(lmom.z());
439  LocalPoint entry = lpos - 0.5 * thickness * lmom / pz;
440  LocalPoint exit = lpos + 0.5 * thickness * lmom / pz;
441  double dtof = path.second * rbeta;
442  int trkid = mySimTrack.trackId();
443  unsigned int id = lid.rawId();
444  short unsigned int processType = 2;
445  PSimHit hit(
446  entry, exit, lmom.mag(), tof + dtof, eloss, pid, id, trkid, lmom.theta(), lmom.phi(), processType);
447  theCSCHits.push_back(hit);
448  }
449  } else if (gd->subDetector() == GeomDetEnumerators::RPCBarrel ||
451  RPCDetId id(gd->geographicalId());
452  const RPCChamber* chamber = rpcGeom->chamber(id);
453  std::vector<const RPCRoll*> roll = chamber->rolls();
454  for (unsigned int iroll = 0; iroll < roll.size(); iroll++) {
455  RPCDetId rid = roll[iroll]->id();
456 
457 #ifdef FAMOS_DEBUG
458  std::cout << " Extrapolated to RPC (" << rid.ring() << "," << rid.station() << "," << rid.sector() << ","
459  << rid.subsector() << "," << rid.layer() << "," << rid.roll() << ")" << std::endl;
460 #endif
461 
462  const GeomDetUnit* det = rpcGeom->idToDetUnit(rid);
463  HelixArbitraryPlaneCrossing crossing(propagatedState.globalPosition().basicVector(),
464  propagatedState.globalMomentum().basicVector(),
465  propagatedState.transverseCurvature(),
466  anyDirection);
467  std::pair<bool, double> path = crossing.pathLength(det->surface());
468  if (!path.first)
469  continue;
470  LocalPoint lpos = det->toLocal(GlobalPoint(crossing.position(path.second)));
471  if (!det->surface().bounds().inside(lpos))
472  continue;
473  double thickness = det->surface().bounds().thickness();
474  LocalVector lmom = det->toLocal(GlobalVector(crossing.direction(path.second)));
475  lmom = lmom.unit() * propagatedState.localMomentum().mag();
476  double eloss = 0;
477  double pz = fabs(lmom.z());
478  LocalPoint entry = lpos - 0.5 * thickness * lmom / pz;
479  LocalPoint exit = lpos + 0.5 * thickness * lmom / pz;
480  double dtof = path.second * rbeta;
481  int trkid = mySimTrack.trackId();
482  unsigned int id = rid.rawId();
483  short unsigned int processType = 2;
484  PSimHit hit(
485  entry, exit, lmom.mag(), tof + dtof, eloss, pid, id, trkid, lmom.theta(), lmom.phi(), processType);
486  theRPCHits.push_back(hit);
487  }
488  } else {
489  std::cout << "Extrapolated to unknown subdetector '" << gd->subDetector() << "'..." << std::endl;
490  }
491  }
492  }
493  }
494 
495  std::unique_ptr<edm::PSimHitContainer> pcsc(new edm::PSimHitContainer);
496  int n = 0;
497  for (std::vector<PSimHit>::const_iterator i = theCSCHits.begin(); i != theCSCHits.end(); i++) {
498  pcsc->push_back(*i);
499  n += 1;
500  }
501  iEvent.put(std::move(pcsc), "MuonCSCHits");
502 
503  std::unique_ptr<edm::PSimHitContainer> pdt(new edm::PSimHitContainer);
504  n = 0;
505  for (std::vector<PSimHit>::const_iterator i = theDTHits.begin(); i != theDTHits.end(); i++) {
506  pdt->push_back(*i);
507  n += 1;
508  }
509  iEvent.put(std::move(pdt), "MuonDTHits");
510 
511  std::unique_ptr<edm::PSimHitContainer> prpc(new edm::PSimHitContainer);
512  n = 0;
513  for (std::vector<PSimHit>::const_iterator i = theRPCHits.begin(); i != theRPCHits.end(); i++) {
514  prpc->push_back(*i);
515  n += 1;
516  }
517  iEvent.put(std::move(prpc), "MuonRPCHits");
518 }
519 
521  const edm::ParameterSet& fastTracks,
522  const edm::ParameterSet& matEff) {
523  // Muons
524  std::string _simModuleLabel = fastMuons.getParameter<std::string>("simModuleLabel");
525  std::string _simModuleProcess = fastMuons.getParameter<std::string>("simModuleProcess");
526  simMuonLabel = edm::InputTag(_simModuleLabel, _simModuleProcess);
527  simVertexLabel = edm::InputTag(_simModuleLabel);
528 
529  std::vector<double> simHitIneffDT = fastMuons.getParameter<std::vector<double> >("simHitDTIneffParameters");
530  std::vector<double> simHitIneffCSC = fastMuons.getParameter<std::vector<double> >("simHitCSCIneffParameters");
531  kDT = simHitIneffDT[0];
532  fDT = simHitIneffDT[1];
533  kCSC = simHitIneffCSC[0];
534  fCSC = simHitIneffCSC[1];
535 
536  // Tracks
537  fullPattern_ = fastTracks.getUntrackedParameter<bool>("FullPatternRecognition");
538 
539  // The following should be on LogInfo
540  // std::cout << " MUON SIM HITS: FastSimulation parameters " << std::endl;
541  // std::cout << " ============================================== " << std::endl;
542  // if ( fullPattern_ )
543  // std::cout << " The FULL pattern recognition option is turned ON" << std::endl;
544  // else
545  // std::cout << " The FAST tracking option is turned ON" << std::endl;
546 
547  // Material Effects
548  theMaterialEffects = nullptr;
549  if (matEff.getParameter<bool>("PairProduction") || matEff.getParameter<bool>("Bremsstrahlung") ||
550  matEff.getParameter<bool>("MuonBremsstrahlung") || matEff.getParameter<bool>("EnergyLoss") ||
551  matEff.getParameter<bool>("MultipleScattering"))
552  theMaterialEffects = std::make_unique<MaterialEffects>(matEff);
553 }
554 
557  double radPath,
558  RandomEngineAndDistribution const* random,
560  // The energy loss simulator
561  EnergyLossSimulator* energyLoss = theMaterialEffects->energyLossSimulator();
562 
563  // The multiple scattering simulator
564  MultipleScatteringSimulator* multipleScattering = theMaterialEffects->multipleScatteringSimulator();
565 
566  // The Muon Bremsstrahlung simulator
567  MuonBremsstrahlungSimulator* bremsstrahlung = theMaterialEffects->muonBremsstrahlungSimulator();
568 
569  // Initialize the Particle position, momentum and energy
570  const Surface& nextSurface = tsos.surface();
571  GlobalPoint gPos = energyLoss ? tsos.globalPosition() : tsosWithdEdx.globalPosition();
572  GlobalVector gMom = energyLoss ? tsos.globalMomentum() : tsosWithdEdx.globalMomentum();
573  double mu = 0.1056583692;
574  double en = std::sqrt(gMom.mag2() + mu * mu);
575 
576  // And now create the Particle
577  XYZTLorentzVector position(gPos.x(), gPos.y(), gPos.z(), 0.);
578  XYZTLorentzVector momentum(gMom.x(), gMom.y(), gMom.z(), en);
579  float charge = (float)(tsos.charge());
580  ParticlePropagator theMuon(rawparticle::makeMuon(charge < 1., momentum, position), nullptr, nullptr, &table);
581 
582  // Recompute the energy loss to get the fluctuations
583  if (energyLoss) {
584  // Difference between with and without dE/dx (average only)
585  // (for corrections once fluctuations are applied)
586  GlobalPoint gPosWithdEdx = tsosWithdEdx.globalPosition();
587  GlobalVector gMomWithdEdx = tsosWithdEdx.globalMomentum();
588  double enWithdEdx = std::sqrt(gMomWithdEdx.mag2() + mu * mu);
589  XYZTLorentzVector deltaPos(
590  gPosWithdEdx.x() - gPos.x(), gPosWithdEdx.y() - gPos.y(), gPosWithdEdx.z() - gPos.z(), 0.);
591  XYZTLorentzVector deltaMom(
592  gMomWithdEdx.x() - gMom.x(), gMomWithdEdx.y() - gMom.y(), gMomWithdEdx.z() - gMom.z(), enWithdEdx - en);
593 
594  // Energy loss in iron (+ fluctuations)
595  energyLoss->updateState(theMuon, radPath, random);
596 
597  // Correcting factors to account for slight differences in material descriptions
598  // (Material description is more accurate in the stepping helix propagator)
599  radPath *= -deltaMom.E() / energyLoss->mostLikelyLoss();
600  double fac = energyLoss->deltaMom().E() / energyLoss->mostLikelyLoss();
601 
602  // Particle momentum & position after energy loss + fluctuation
603  XYZTLorentzVector theNewMomentum = theMuon.particle().momentum() + energyLoss->deltaMom() + fac * deltaMom;
604  XYZTLorentzVector theNewPosition = theMuon.particle().vertex() + fac * deltaPos;
605  fac = (theNewMomentum.E() * theNewMomentum.E() - mu * mu) / theNewMomentum.Vect().Mag2();
606  fac = fac > 0. ? std::sqrt(fac) : 1E-9;
607  theMuon.particle().setMomentum(
608  theNewMomentum.Px() * fac, theNewMomentum.Py() * fac, theNewMomentum.Pz() * fac, theNewMomentum.E());
609  theMuon.particle().setVertex(theNewPosition);
610  }
611 
612  // Does the actual mutliple scattering
613  if (multipleScattering) {
614  // Pass the vector normal to the "next" surface
615  GlobalVector normal = nextSurface.tangentPlane(tsos.globalPosition())->normalVector();
616  multipleScattering->setNormalVector(normal);
617  // Compute the amount of multiple scattering after a given path length
618  multipleScattering->updateState(theMuon, radPath, random);
619  }
620 
621  // Muon Bremsstrahlung
622  if (bremsstrahlung) {
623  // Compute the amount of Muon Bremsstrahlung after given path length
624  bremsstrahlung->updateState(theMuon, radPath, random);
625  }
626 
627  // Fill the propagated state
628  GlobalPoint propagatedPosition(theMuon.particle().X(), theMuon.particle().Y(), theMuon.particle().Z());
629  GlobalVector propagatedMomentum(theMuon.particle().Px(), theMuon.particle().Py(), theMuon.particle().Pz());
630  GlobalTrajectoryParameters propagatedGtp(propagatedPosition, propagatedMomentum, (int)charge, magfield);
631  tsosWithdEdx = TrajectoryStateOnSurface(propagatedGtp, nextSurface);
632 }
633 
634 //define this as a plug-in
Vector3DBase
Definition: Vector3DBase.h:8
DTGeometry
Definition: DTGeometry.h:28
Chi2MeasurementEstimator.h
TkRotation< float >
DDAxes::y
CoreSimTrack::momentum
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:19
rawparticle::makeMuon
RawParticle makeMuon(bool isParticle, const math::XYZTLorentzVector &p, const math::XYZTLorentzVector &xStart)
Definition: makeMuon.cc:20
TrajectoryStateOnSurface::freeTrajectoryState
FreeTrajectoryState const * freeTrajectoryState(bool withErrors=true) const
Definition: TrajectoryStateOnSurface.h:60
MuonServiceProxy::UseEventSetupIn::Run
TrajectoryStateOnSurface::localMomentum
LocalVector localMomentum() const
Definition: TrajectoryStateOnSurface.h:75
mps_fire.i
i
Definition: mps_fire.py:428
anyDirection
Definition: PropagationDirection.h:4
MuonSimHitProducer::fCSC
double fCSC
Definition: MuonSimHitProducer.cc:76
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
MuonPatternRecoDumper.h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
SteppingHelixPropagator.h
GeomDetEnumerators::RPCEndcap
Definition: GeomDetEnumerators.h:20
GeomDet
Definition: GeomDet.h:27
DTTopology::channel
int channel(const LocalPoint &p) const override
Definition: DTTopology.cc:54
EnergyLossSimulator.h
BaseParticlePropagator::particle
RawParticle const & particle() const
The particle being propagated.
Definition: BaseParticlePropagator.h:164
Chi2MeasurementEstimator
Definition: Chi2MeasurementEstimator.h:15
MuonSimHitProducer::cscGeom
const CSCGeometry * cscGeom
Definition: MuonSimHitProducer.cc:61
MuonSimHitProducer::fDT
double fDT
Definition: MuonSimHitProducer.cc:74
RawParticle::momentum
const XYZTLorentzVector & momentum() const
the momentum fourvector
Definition: RawParticle.h:321
DTGeometry::idToDetUnit
const GeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: DTGeometry.cc:75
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
edm::Run
Definition: Run.h:45
edm::EDGetTokenT
Definition: EDGetToken.h:33
relativeConstraints.station
station
Definition: relativeConstraints.py:67
RawParticle::vertex
const XYZTLorentzVector & vertex() const
the vertex fourvector
Definition: RawParticle.h:320
CSCDetId::ring
int ring() const
Definition: CSCDetId.h:68
mps_splice.entry
entry
Definition: mps_splice.py:68
PV3DBase::theta
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
RPCDetId
Definition: RPCDetId.h:16
TrajectoryStateOnSurface::globalPosition
GlobalPoint globalPosition() const
Definition: TrajectoryStateOnSurface.h:65
gather_cfg.cout
cout
Definition: gather_cfg.py:144
DTChamber
Definition: DTChamber.h:24
PSimHitContainer.h
MuonSimHitProducer::fullPattern_
bool fullPattern_
Definition: MuonSimHitProducer.cc:86
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
SimTrack::trackerSurfaceMomentum
const math::XYZTLorentzVectorD & trackerSurfaceMomentum() const
Definition: SimTrack.h:39
MuonSimHitProducer::simMuonToken
edm::EDGetTokenT< std::vector< SimTrack > > simMuonToken
Definition: MuonSimHitProducer.cc:94
TrajectoryStateOnSurface::charge
TrackCharge charge() const
Definition: TrajectoryStateOnSurface.h:68
dileptonTrigSettings_cff.pdg
pdg
Definition: dileptonTrigSettings_cff.py:6
MultipleScatteringSimulator
Definition: MultipleScatteringSimulator.h:26
EDProducer.h
MuonSimHitProducer::kDT
double kDT
Definition: MuonSimHitProducer.cc:73
Surface
Definition: Surface.h:36
MuonSimHitProducer
Definition: MuonSimHitProducer.cc:51
CoreSimTrack::charge
float charge() const
charge
Definition: CoreSimTrack.cc:17
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
TrajectoryStateOnSurface::transverseCurvature
double transverseCurvature() const
Definition: TrajectoryStateOnSurface.h:70
MuonSimHitProducer::theService
MuonServiceProxy * theService
Definition: MuonSimHitProducer.cc:56
ReferenceCountingPointer< Plane >
DTSuperLayerId::superlayer
int superlayer() const
Return the superlayer number (deprecated method name)
Definition: DTSuperLayerId.h:42
DDAxes::x
XYZTLorentzVector
math::XYZTLorentzVector XYZTLorentzVector
Definition: RawParticle.h:25
GlobalVector
Global3DVector GlobalVector
Definition: GlobalVector.h:10
PV3DBase::mag2
T mag2() const
Definition: PV3DBase.h:63
edm::Handle
Definition: AssociativeIterator.h:50
GloballyPositioned< float >::RotationType
TkRotation< float > RotationType
Definition: GloballyPositioned.h:22
RandomEngineAndDistribution.h
RPCChamber
Definition: RPCChamber.h:19
MuonServiceProxy_cff.MuonServiceProxy
MuonServiceProxy
Definition: MuonServiceProxy_cff.py:14
DTGeometry::chamber
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
Definition: DTGeometry.cc:90
RPCGeometry::idToDetUnit
const GeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: RPCGeometry.cc:30
MuonSimHitProducer::propagatorWithMaterial
const Propagator * propagatorWithMaterial
Definition: MuonSimHitProducer.cc:63
SteppingHelixStateInfo::getStateOnSurface
TrajectoryStateOnSurface getStateOnSurface(const Surface &surf, bool returnTangentPlane=false) const
Definition: SteppingHelixStateInfo.cc:60
DTTopology
Definition: DTTopology.h:28
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
RawParticle::Z
double Z() const
z of vertex
Definition: RawParticle.h:288
MuonSimHitProducer::beginRun
void beginRun(edm::Run const &run, const edm::EventSetup &es) override
Definition: MuonSimHitProducer.cc:127
CSCGeometry
Definition: CSCGeometry.h:24
DirectMuonNavigation
Definition: DirectMuonNavigation.h:20
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
Propagator
Definition: Propagator.h:44
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
MakerMacros.h
PlaneBuilder.h
SteppingHelixPropagator
Definition: SteppingHelixPropagator.h:36
Vector3DBase::unit
Vector3DBase unit() const
Definition: Vector3DBase.h:54
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TrackCandidateProducer_cfi.propagator
propagator
Definition: TrackCandidateProducer_cfi.py:17
fastSimProducer_cff.multipleScattering
multipleScattering
Definition: fastSimProducer_cff.py:64
MuonPatternRecoDumper
Definition: MuonPatternRecoDumper.h:18
DTTopology::firstChannel
int firstChannel() const
Returns the wire number of the first wire.
Definition: DTTopology.h:79
DTWireId
Definition: DTWireId.h:12
FrontierCondition_GT_autoExpress_cfi.t0
t0
Definition: FrontierCondition_GT_autoExpress_cfi.py:148
Bounds::inside
virtual bool inside(const Local3DPoint &) const =0
Determine if the point is inside the bounds.
MuonSimHitProducer::simMuonLabel
edm::InputTag simMuonLabel
Definition: MuonSimHitProducer.cc:90
Calorimetry_cff.thickness
thickness
Definition: Calorimetry_cff.py:114
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
CSCLayerGeometry
Definition: CSCLayerGeometry.h:25
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
SimVertex.h
Surface::bounds
const Bounds & bounds() const
Definition: Surface.h:87
CSCDetId::layer
int layer() const
Definition: CSCDetId.h:56
DDAxes::z
MuonSimHitProducer::kCSC
double kCSC
Definition: MuonSimHitProducer.cc:75
IdealMagneticFieldRecord.h
edm::ESHandle< MagneticField >
MuonSimHitProducer::doL3_
bool doL3_
Definition: MuonSimHitProducer.cc:87
CSCChamber
Definition: CSCChamber.h:22
HLT_FULL_cff.zAxis
zAxis
Definition: HLT_FULL_cff.py:46209
HelixArbitraryPlaneCrossing
Definition: HelixArbitraryPlaneCrossing.h:10
GlobalTrajectoryParameters
Definition: GlobalTrajectoryParameters.h:15
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
MuonSimHitProducer::simVertexToken
edm::EDGetTokenT< std::vector< SimVertex > > simVertexToken
Definition: MuonSimHitProducer.cc:95
Point3DBase< float, GlobalTag >
GeomDet::toLocal
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:58
ParticlePropagator.h
DTLayerId
Definition: DTLayerId.h:12
GeomDetEnumerators::CSC
Definition: GeomDetEnumerators.h:17
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DTGeometry.h
SteppingHelixStateInfo
Definition: SteppingHelixStateInfo.h:27
MuonServiceProxy::update
void update(const edm::EventSetup &setup, bool duringEvent=true)
update the services each event
Definition: MuonServiceProxy.cc:111
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
MuonSimHitProducer::MuonSimHitProducer
MuonSimHitProducer(const edm::ParameterSet &)
Definition: MuonSimHitProducer.cc:104
MuonBremsstrahlungSimulator.h
GeomDetEnumerators::DT
Definition: GeomDetEnumerators.h:18
GeomDet::geographicalId
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
Surface::tangentPlane
virtual ConstReferenceCountingPointer< TangentPlane > tangentPlane(const GlobalPoint &) const =0
CSCLayerGeometry::inside
bool inside(const Local3DPoint &, const LocalError &, float scale=1.f) const override
Definition: CSCLayerGeometry.cc:282
Bounds::thickness
virtual float thickness() const =0
SimTrack::trackerSurfacePosition
const math::XYZVectorD & trackerSurfacePosition() const
Definition: SimTrack.h:37
HelixArbitraryPlaneCrossing.h
MuonSimHitProducer::propagatorWithoutMaterial
std::unique_ptr< Propagator > propagatorWithoutMaterial
Definition: MuonSimHitProducer.cc:64
edm::ParameterSet
Definition: ParameterSet.h:47
MuonSimHitProducer::magfield
const MagneticField * magfield
Definition: MuonSimHitProducer.cc:59
MaterialEffects.h
SteppingHelixStateInfo::radPath
double radPath() const
Definition: SteppingHelixStateInfo.h:63
ParticleDataTable.h
MuonSimHitProducer::simVertexLabel
edm::InputTag simVertexLabel
Definition: MuonSimHitProducer.cc:91
MuonSimHitProducer::theEstimator
Chi2MeasurementEstimator theEstimator
Definition: MuonSimHitProducer.cc:57
fastSimProducer_cff.bremsstrahlung
bremsstrahlung
Definition: fastSimProducer_cff.py:38
HLT_FULL_cff.yAxis
yAxis
Definition: HLT_FULL_cff.py:46210
SteppingHelixStateInfo::path
double path() const
Definition: SteppingHelixStateInfo.h:62
CSCDetId
Definition: CSCDetId.h:26
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
ParticlePropagator
Definition: ParticlePropagator.h:28
MuonServiceProxy::propagator
edm::ESHandle< Propagator > propagator(std::string propagatorName) const
get the propagator
Definition: MuonServiceProxy.cc:177
iEvent
int iEvent
Definition: GenABIO.cc:224
RawParticle::Y
double Y() const
y of vertex
Definition: RawParticle.h:287
RawParticle::Py
double Py() const
y of the momentum
Definition: RawParticle.h:300
edm::stream::EDProducer
Definition: EDProducer.h:38
CoreSimTrack::type
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:22
edm::EventSetup
Definition: EventSetup.h:57
PlaneBuilder::plane
ReturnType plane(const PositionType &pos, const RotationType &rot) const
Definition: PlaneBuilder.h:21
get
#define get
SteppingHelixPropagator::setMaterialMode
void setMaterialMode(bool noMaterial)
Switch for material effects mode: no material effects if true.
Definition: SteppingHelixPropagator.h:124
MuonSimHitProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: MuonSimHitProducer.cc:162
PV3DBase::basicVector
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:120
CoreSimTrack::trackId
unsigned int trackId() const
Definition: CoreSimTrack.h:31
DTTopology::lastChannel
int lastChannel() const
Returns the wire number of the last wire.
Definition: DTTopology.h:81
PV3DBase::mag
T mag() const
Definition: PV3DBase.h:64
MuonSimHitProducer::theMaterialEffects
std::unique_ptr< MaterialEffects > theMaterialEffects
Definition: MuonSimHitProducer.cc:66
TangentPlane.h
RPCGeometry::chamber
const RPCChamber * chamber(RPCDetId id) const
Definition: RPCGeometry.cc:46
TrajectoryStateOnSurface::globalMomentum
GlobalVector globalMomentum() const
Definition: TrajectoryStateOnSurface.h:66
DTChamberId::sector
int sector() const
Definition: DTChamberId.h:49
MuonSimHitProducer::doL1_
bool doL1_
Definition: MuonSimHitProducer.cc:87
MuonSimHitProducer::applyMaterialEffects
void applyMaterialEffects(TrajectoryStateOnSurface &tsosWithdEdx, TrajectoryStateOnSurface &tsos, double radPath, RandomEngineAndDistribution const *, HepPDT::ParticleDataTable const &)
Simulate material effects in iron (dE/dx, multiple scattering)
Definition: MuonSimHitProducer.cc:555
eostools.move
def move(src, dest)
Definition: eostools.py:511
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
writedatasetfile.run
run
Definition: writedatasetfile.py:27
DTWireId.h
MultipleScatteringSimulator.h
Propagator::clone
virtual Propagator * clone() const =0
RawParticle::X
double X() const
x of vertex
Definition: RawParticle.h:286
SimTrack
Definition: SimTrack.h:6
MuonDetLayerMeasurements.h
packedPFCandidateRefMixer_cfi.pf
pf
Definition: packedPFCandidateRefMixer_cfi.py:4
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
CSCDetId::endcap
int endcap() const
Definition: CSCDetId.h:85
RawParticle::setVertex
void setVertex(const XYZTLorentzVector &vtx)
set the vertex
Definition: RawParticle.h:325
MuonBremsstrahlungSimulator
Definition: MuonBremsstrahlungSimulator.h:29
MuonServiceProxy.h
HLT_FULL_cff.xAxis
xAxis
Definition: HLT_FULL_cff.py:46208
relativeConstraints.ring
ring
Definition: relativeConstraints.py:68
makeMuonMisalignmentScenario.rot
rot
Definition: makeMuonMisalignmentScenario.py:322
relativeConstraints.chamber
chamber
Definition: relativeConstraints.py:53
SimTrack::vertIndex
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
Definition: SimTrack.h:30
pdg
Definition: pdg_functions.h:28
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
TrajectoryStateOnSurface::surface
const SurfaceType & surface() const
Definition: TrajectoryStateOnSurface.h:78
PlaneBuilder
Definition: PlaneBuilder.h:13
RawParticle::setMomentum
void setMomentum(const XYZTLorentzVector &vtx)
set the momentum
Definition: RawParticle.h:328
EnergyLossSimulator
Definition: EnergyLossSimulator.h:25
GeomDetEnumerators::RPCBarrel
Definition: GeomDetEnumerators.h:19
RPCGeometry
Definition: RPCGeometry.h:20
pi
const Double_t pi
Definition: trackSplitPlot.h:36
ConsumesCollector.h
MuonSimHitProducer::rpcGeom
const RPCGeometry * rpcGeom
Definition: MuonSimHitProducer.cc:62
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
DTChamberId
Definition: DTChamberId.h:14
MuonSimHitProducer::dtGeom
const DTGeometry * dtGeom
Definition: MuonSimHitProducer.cc:60
HGCalValidator_cfi.simVertices
simVertices
Definition: HGCalValidator_cfi.py:43
edm::PSimHitContainer
std::vector< PSimHit > PSimHitContainer
Definition: PSimHitContainer.h:11
SimTrack.h
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
CSCDetId::station
int station() const
Definition: CSCDetId.h:79
MuonServiceProxy
Definition: MuonServiceProxy.h:38
PSimHit
Definition: PSimHit.h:15
MuonGeometryRecord.h
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
TableParser.table
table
Definition: TableParser.py:111
edm::Event
Definition: Event.h:73
DTLayerId::layer
int layer() const
Return the layer number.
Definition: DTLayerId.h:42
MagneticField
Definition: MagneticField.h:19
RawParticle::Px
double Px() const
x of the momentum
Definition: RawParticle.h:297
CSCGeometry::idToDetUnit
const GeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: CSCGeometry.cc:89
fastSimProducer_cff.energyLoss
energyLoss
Definition: fastSimProducer_cff.py:55
RawParticle::Pz
double Pz() const
z of the momentum
Definition: RawParticle.h:303
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
MuonServiceProxy::detLayerGeometry
edm::ESHandle< MuonDetLayerGeometry > detLayerGeometry() const
get the detLayer geometry
Definition: MuonServiceProxy.h:62
DirectMuonNavigation.h
RPCGeometry.h
ParticleDataTable
HepPDT::ParticleDataTable ParticleDataTable
Definition: ParticleDataTable.h:8
DTChamberId::wheel
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
MuonSimHitProducer::doGL_
bool doGL_
Definition: MuonSimHitProducer.cc:87
edm::InputTag
Definition: InputTag.h:15
alongMomentum
Definition: PropagationDirection.h:4
hgcalTopologyTester_cfi.layers
layers
Definition: hgcalTopologyTester_cfi.py:8
PV3DBase::phi
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
CSCGeometry::chamber
const CSCChamber * chamber(CSCDetId id) const
Return the chamber corresponding to given DetId.
Definition: CSCGeometry.cc:100
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
GeomDet::subDetector
virtual SubDetector subDetector() const
Which subdetector.
Definition: GeomDet.cc:38
DTChamberId::station
int station() const
Return the station number.
Definition: DTChamberId.h:42
hit
Definition: SiStripHitEffFromCalibTree.cc:88
CSCGeometry.h
GetRecoTauVFromDQM_MC_cff.next
next
Definition: GetRecoTauVFromDQM_MC_cff.py:31
bril_dqm_clientPB-live_cfg.rid
rid
Definition: bril_dqm_clientPB-live_cfg.py:30
RandomEngineAndDistribution
Definition: RandomEngineAndDistribution.h:18
MuonSimHitProducer::readParameters
void readParameters(const edm::ParameterSet &, const edm::ParameterSet &, const edm::ParameterSet &)
Definition: MuonSimHitProducer.cc:520