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 
23 // CMSSW headers
25 
26 // Fast Simulation headers
34 
35 // SimTrack
39 
40 // STL headers
41 #include <vector>
42 #include <iostream>
43 
44 // RecoMuon headers
49 
50 // Tracking Tools
53 
54 // Data Formats
58 
60 // Geometry, Magnetic Field
66 
68 
69 // #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
70 
71 //for debug only
72 //#define FAMOS_DEBUG
73 
74 //
75 // constructors and destructor
76 //
78  theEstimator(iConfig.getParameter<double>("Chi2EstimatorCut")),
79  propagatorWithoutMaterial(nullptr)
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 }
103 
104 // ---- method called once each job just before starting event loop ----
105 void
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 }
134 
136 {
137  // do anything here that needs to be done at destruction time
138  // (e.g. close files, deallocate resources etc.)
139 
142 }
143 
144 
145 //
146 // member functions
147 //
148 
149 // ------------ method called to produce the data ------------
150 
151 void
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 }
529 
530 void
532  const edm::ParameterSet& fastTracks,
533  const edm::ParameterSet& matEff) {
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 }
567 
568 void
571  double radPath,
573  HepPDT::ParticleDataTable const& table) {
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 }
654 
655 
656 
657 //define this as a plug-in
void update(const edm::EventSetup &setup)
update the services each event
MuonSimHitProducer(const edm::ParameterSet &)
double mostLikelyLoss() const
Return most probable energy loss.
edm::ESHandle< MuonDetLayerGeometry > detLayerGeometry() const
get the detLayer geometry
void setMomentum(const XYZTLorentzVector &vtx)
set the momentum
Definition: RawParticle.h:347
const math::XYZVectorD & trackerSurfacePosition() const
Definition: SimTrack.h:37
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const MagneticField * magfield
T mag2() const
Definition: PV3DBase.h:66
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
virtual Propagator * clone() const =0
virtual ConstReferenceCountingPointer< TangentPlane > tangentPlane(const GlobalPoint &) const =0
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
HepPDT::ParticleDataTable ParticleDataTable
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void setNormalVector(const GlobalVector &normal)
Sets the vector normal to the surface traversed.
MaterialEffects * theMaterialEffects
#define nullptr
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
MultipleScatteringSimulator * multipleScatteringSimulator() const
Return the Multiple Scattering engine.
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
void updateState(ParticlePropagator &myTrack, double radlen, RandomEngineAndDistribution const *)
Compute the material effect (calls the sub class)
edm::EDGetTokenT< std::vector< SimVertex > > simVertexToken
RawParticle makeMuon(bool isParticle, const math::XYZTLorentzVector &p, const math::XYZTLorentzVector &xStart)
Definition: makeMuon.cc:20
TRandom random
Definition: MVATrainer.cc:138
int layer() const
Return the layer number.
Definition: DTLayerId.h:53
RawParticle const & particle() const
The particle being propagated.
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
MuonBremsstrahlungSimulator * muonBremsstrahlungSimulator() const
Return the Muon Bremsstrahlung engine.
virtual bool inside(const Local3DPoint &) const =0
Determine if the point is inside the bounds.
int iEvent
Definition: GenABIO.cc:224
const SurfaceType & surface() const
const XYZTLorentzVector & momentum() const
the momentum fourvector
Definition: RawParticle.h:340
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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
double Y() const
y of vertex
Definition: RawParticle.h:306
const XYZTLorentzVector & deltaMom() const
Returns the actual energy lost.
double Py() const
y of the momentum
Definition: RawParticle.h:319
double Z() const
z of vertex
Definition: RawParticle.h:307
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
void beginRun(edm::Run const &run, const edm::EventSetup &es) override
void produce(edm::Event &, const edm::EventSetup &) override
const int mu
Definition: Constants.h:22
double Pz() const
z of the momentum
Definition: RawParticle.h:322
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
const XYZTLorentzVector & vertex() const
the vertex fourvector
Definition: RawParticle.h:339
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
double X() const
x of vertex
Definition: RawParticle.h:305
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
void readParameters(const edm::ParameterSet &, const edm::ParameterSet &, const edm::ParameterSet &)
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
T get() const
Definition: EventSetup.h:71
TkRotation< float > RotationType
double Px() const
x of the momentum
Definition: RawParticle.h:316
edm::InputTag simMuonLabel
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
EnergyLossSimulator * energyLossSimulator() const
Return the Energy Loss engine.
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
void setMaterialMode(bool noMaterial)
Switch for material effects mode: no material effects if true.
void setVertex(const XYZTLorentzVector &vtx)
set the vertex
Definition: RawParticle.h:344
def move(src, dest)
Definition: eostools.py:511
edm::ESHandle< Propagator > propagator(std::string propagatorName) const
get the propagator
Definition: Run.h:45
Global3DVector GlobalVector
Definition: GlobalVector.h:10
math::XYZTLorentzVector XYZTLorentzVector
Definition: RawParticle.h:27
edm::InputTag simVertexLabel
Chi2MeasurementEstimator theEstimator
int station() const
Definition: RPCDetId.h:96