00001
00002
00003
00004
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "FWCore/ServiceRegistry/interface/Service.h"
00025 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00026 #include "FWCore/Framework/interface/MakerMacros.h"
00027
00028
00029 #include "FastSimulation/Utilities/interface/RandomEngine.h"
00030 #include "FastSimulation/MuonSimHitProducer/interface/MuonSimHitProducer.h"
00031 #include "FastSimulation/MaterialEffects/interface/MaterialEffects.h"
00032 #include "FastSimulation/MaterialEffects/interface/MultipleScatteringSimulator.h"
00033 #include "FastSimulation/MaterialEffects/interface/EnergyLossSimulator.h"
00034 #include "FastSimulation/ParticlePropagator/interface/ParticlePropagator.h"
00035 #include "FastSimulation/MaterialEffects/interface/MuonBremsstrahlungSimulator.h"
00036
00037
00038 #include "SimDataFormats/Track/interface/SimTrack.h"
00039 #include "SimDataFormats/Vertex/interface/SimVertex.h"
00040 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00041
00042
00043 #include <vector>
00044 #include <iostream>
00045
00046
00047 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
00048 #include "RecoMuon/Navigation/interface/DirectMuonNavigation.h"
00049 #include "RecoMuon/MeasurementDet/interface/MuonDetLayerMeasurements.h"
00050 #include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h"
00051
00052
00053 #include "TrackingTools/GeomPropagators/interface/HelixArbitraryPlaneCrossing.h"
00054 #include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h"
00055
00056
00057 #include "DataFormats/MuonDetId/interface/DTWireId.h"
00058 #include "DataFormats/GeometrySurface/interface/PlaneBuilder.h"
00059 #include "DataFormats/GeometrySurface/interface/TangentPlane.h"
00060
00061
00063
00064 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00065 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
00066 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
00067 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00068 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00069
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 MuonSimHitProducer::MuonSimHitProducer(const edm::ParameterSet& iConfig):
00081 theEstimator(iConfig.getParameter<double>("Chi2EstimatorCut")),
00082 propagatorWithoutMaterial(0)
00083 {
00084
00085
00086
00087
00088 edm::Service<edm::RandomNumberGenerator> rng;
00089 if ( ! rng.isAvailable() ) {
00090 throw cms::Exception("Configuration") <<
00091 "MuonSimHitProducer requires the RandomGeneratorService \n"
00092 "which is not present in the configuration file. \n"
00093 "You must add the service in the configuration file\n"
00094 "or remove the module that requires it.";
00095 }
00096
00097 random = new RandomEngine(&(*rng));
00098
00099
00100 readParameters(iConfig.getParameter<edm::ParameterSet>("MUONS"),
00101 iConfig.getParameter<edm::ParameterSet>("TRACKS"),
00102 iConfig.getParameter<edm::ParameterSet>("MaterialEffectsForMuons"));
00103
00104
00105
00106
00107 produces<edm::PSimHitContainer>("MuonCSCHits");
00108 produces<edm::PSimHitContainer>("MuonDTHits");
00109 produces<edm::PSimHitContainer>("MuonRPCHits");
00110
00111 edm::ParameterSet serviceParameters =
00112 iConfig.getParameter<edm::ParameterSet>("ServiceParameters");
00113 theService = new MuonServiceProxy(serviceParameters);
00114 }
00115
00116
00117 void
00118 MuonSimHitProducer::beginRun(edm::Run const& run, const edm::EventSetup & es) {
00119
00120
00121 edm::ESHandle<MagneticField> magField;
00122 edm::ESHandle<DTGeometry> dtGeometry;
00123 edm::ESHandle<CSCGeometry> cscGeometry;
00124 edm::ESHandle<RPCGeometry> rpcGeometry;
00125 edm::ESHandle<Propagator> propagator;
00126
00127 es.get<IdealMagneticFieldRecord>().get(magField);
00128 es.get<MuonGeometryRecord>().get("MisAligned",dtGeometry);
00129 es.get<MuonGeometryRecord>().get("MisAligned",cscGeometry);
00130 es.get<MuonGeometryRecord>().get(rpcGeometry);
00131
00132 magfield = &(*magField);
00133 dtGeom = &(*dtGeometry);
00134 cscGeom = &(*cscGeometry);
00135 rpcGeom = &(*rpcGeometry);
00136
00137 theService->update(es);
00138
00139
00140 propagatorWithMaterial = &(*(theService->propagator("SteppingHelixPropagatorAny")));
00141 propagatorWithoutMaterial = propagatorWithMaterial->clone();
00142 SteppingHelixPropagator* SHpropagator = dynamic_cast<SteppingHelixPropagator*> (propagatorWithoutMaterial);
00143 SHpropagator->setMaterialMode(true);
00144
00145 }
00146
00147 MuonSimHitProducer::~MuonSimHitProducer()
00148 {
00149
00150
00151
00152 if ( random ) {
00153 delete random;
00154 }
00155
00156 if ( theMaterialEffects ) delete theMaterialEffects;
00157 if ( propagatorWithoutMaterial) delete propagatorWithoutMaterial;
00158 }
00159
00160
00161
00162
00163
00164
00165
00166
00167 void
00168 MuonSimHitProducer::produce(edm::Event& iEvent,const edm::EventSetup& iSetup) {
00169
00170
00171
00172 MuonPatternRecoDumper dumper;
00173
00174 edm::Handle<std::vector<SimTrack> > simMuons;
00175 edm::Handle<std::vector<SimVertex> > simVertices;
00176 std::vector<PSimHit> theCSCHits;
00177 std::vector<PSimHit> theDTHits;
00178 std::vector<PSimHit> theRPCHits;
00179
00180 DirectMuonNavigation navigation(theService->detLayerGeometry());
00181 iEvent.getByLabel(theSimModuleLabel_,theSimModuleProcess_,simMuons);
00182 iEvent.getByLabel(theSimModuleLabel_,simVertices);
00183
00184 for ( unsigned int itrk=0; itrk<simMuons->size(); itrk++ ) {
00185 const SimTrack &mySimTrack = (*simMuons)[itrk];
00186 math::XYZTLorentzVector mySimP4(mySimTrack.momentum().x(),
00187 mySimTrack.momentum().y(),
00188 mySimTrack.momentum().z(),
00189 mySimTrack.momentum().t());
00190
00191
00192
00193 int pid = mySimTrack.type();
00194 if ( abs(pid) != 13 ) continue;
00195
00196 double t0 = 0;
00197 GlobalPoint initialPosition;
00198 int ivert = mySimTrack.vertIndex();
00199 if ( ivert >= 0 ) {
00200 t0 = (*simVertices)[ivert].position().t();
00201 GlobalPoint xyzzy((*simVertices)[ivert].position().x(),
00202 (*simVertices)[ivert].position().y(),
00203 (*simVertices)[ivert].position().z());
00204 initialPosition = xyzzy;
00205 }
00206
00207
00208
00209
00210
00211 double tof = t0/29.98;
00212
00213 #ifdef FAMOS_DEBUG
00214 std::cout << " ===> MuonSimHitProducer::reconstruct() found SIMTRACK - pid = "
00215 << pid ;
00216 std::cout << " : pT = " << mySimP4.Pt()
00217 << ", eta = " << mySimP4.Eta()
00218 << ", phi = " << mySimP4.Phi() << std::endl;
00219 #endif
00220
00221
00222
00223
00224
00225 GlobalPoint startingPosition(mySimTrack.trackerSurfacePosition().x(),
00226 mySimTrack.trackerSurfacePosition().y(),
00227 mySimTrack.trackerSurfacePosition().z());
00228 GlobalVector startingMomentum(mySimTrack.trackerSurfaceMomentum().x(),
00229 mySimTrack.trackerSurfaceMomentum().y(),
00230 mySimTrack.trackerSurfaceMomentum().z());
00231
00232
00233
00234
00235
00236 GlobalVector dtracker = startingPosition-initialPosition;
00237 tof += dtracker.mag()/29.98;
00238
00239 #ifdef FAMOS_DEBUG
00240 std::cout << " the Muon START position " << startingPosition << std::endl;
00241 std::cout << " the Muon START momentum " << startingMomentum << std::endl;
00242 #endif
00243
00244
00245
00246
00247 PlaneBuilder pb;
00248 GlobalVector zAxis = startingMomentum.unit();
00249 GlobalVector yAxis(zAxis.y(),-zAxis.x(),0);
00250 GlobalVector xAxis = yAxis.cross(zAxis);
00251 Surface::RotationType rot = Surface::RotationType(xAxis,yAxis,zAxis);
00252 PlaneBuilder::ReturnType startingPlane = pb.plane(startingPosition,rot);
00253 GlobalTrajectoryParameters gtp(startingPosition,
00254 startingMomentum,
00255 (int)mySimTrack.charge(),
00256 magfield);
00257 TrajectoryStateOnSurface startingState(gtp,*startingPlane);
00258
00259 std::vector<const DetLayer *> navLayers;
00260 if ( fabs(startingState.globalMomentum().eta()) > 4.5 ) {
00261 navLayers = navigation.compatibleEndcapLayers(*(startingState.freeState()),
00262 alongMomentum);
00263 }
00264 else {
00265 navLayers = navigation.compatibleLayers(*(startingState.freeState()),
00266 alongMomentum);
00267 }
00268
00269
00270
00271
00272
00273 if ( navLayers.empty() ) continue;
00274
00275 #ifdef FAMOS_DEBUG
00276 std::cout << "Found " << navLayers.size()
00277 << " compatible DetLayers..." << std::endl;
00278 #endif
00279
00280 TrajectoryStateOnSurface propagatedState = startingState;
00281 for ( unsigned int ilayer=0; ilayer<navLayers.size(); ilayer++ ) {
00282
00283 #ifdef FAMOS_DEBUG
00284 std::cout << "Propagating to layer " << ilayer << " "
00285 << dumper.dumpLayer(navLayers[ilayer])
00286 << std::endl;
00287 #endif
00288
00289 std::vector<DetWithState> comps =
00290 navLayers[ilayer]->compatibleDets(propagatedState,*propagatorWithMaterial,theEstimator);
00291 if ( comps.empty() ) continue;
00292
00293 #ifdef FAMOS_DEBUG
00294 std::cout << "Propagating " << propagatedState << std::endl;
00295 #endif
00296
00297
00298 double pi = propagatedState.globalMomentum().mag();
00299
00300
00301 SteppingHelixStateInfo shsStart(*(propagatedState.freeTrajectoryState()));
00302 const SteppingHelixStateInfo& shsDest =
00303 ((const SteppingHelixPropagator*)propagatorWithMaterial)->propagate(shsStart,navLayers[ilayer]->surface());
00304 std::pair<TrajectoryStateOnSurface,double> next(shsDest.getStateOnSurface(navLayers[ilayer]->surface()),
00305 shsDest.path());
00306
00307
00308 if ( !next.first.isValid() ) continue;
00309
00310
00311 double radPath = shsDest.radPath();
00312 double pathLength = next.second;
00313
00314
00315
00316 std::pair<TrajectoryStateOnSurface,double> nextNoMaterial =
00317 propagatorWithoutMaterial->propagateWithPath(propagatedState,navLayers[ilayer]->surface());
00318
00319
00320 propagatedState = next.first;
00321 double pf = propagatedState.globalMomentum().mag();
00322
00323
00324
00325
00326 if ( theMaterialEffects && nextNoMaterial.first.isValid() ) applyMaterialEffects(propagatedState,nextNoMaterial.first,radPath);
00327
00328 if ( !propagatedState.isValid() ) continue;
00329
00330
00331
00332
00333
00334
00335 double pavg = 0.5*(pi+pf);
00336 double m = mySimP4.M();
00337 double rbeta = sqrt(1+m*m/(pavg*pavg))/29.98;
00338 double dtof = pathLength*rbeta;
00339
00340 #ifdef FAMOS_DEBUG
00341 std::cout << "Propagated to next surface... path length = " << pathLength
00342 << " cm, dTOF = " << dtof << " ns" << std::endl;
00343 #endif
00344
00345 tof += dtof;
00346
00347 for ( unsigned int icomp=0; icomp<comps.size(); icomp++ )
00348 {
00349 const GeomDet *gd = comps[icomp].first;
00350 if ( gd->subDetector() == GeomDetEnumerators::DT ) {
00351 DTChamberId id(gd->geographicalId());
00352 const DTChamber *chamber = dtGeom->chamber(id);
00353 std::vector<const DTSuperLayer *> superlayer = chamber->superLayers();
00354 for ( unsigned int isl=0; isl<superlayer.size(); isl++ ) {
00355 std::vector<const DTLayer *> layer = superlayer[isl]->layers();
00356 for ( unsigned int ilayer=0; ilayer<layer.size(); ilayer++ ) {
00357 DTLayerId lid = layer[ilayer]->id();
00358 #ifdef FAMOS_DEBUG
00359 std::cout << " Extrapolated to DT ("
00360 << lid.wheel() << ","
00361 << lid.station() << ","
00362 << lid.sector() << ","
00363 << lid.superlayer() << ","
00364 << lid.layer() << ")" << std::endl;
00365 #endif
00366
00367 const GeomDetUnit *det = dtGeom->idToDetUnit(lid);
00368
00369 HelixArbitraryPlaneCrossing crossing(propagatedState.globalPosition().basicVector(),
00370 propagatedState.globalMomentum().basicVector(),
00371 propagatedState.transverseCurvature(),
00372 anyDirection);
00373 std::pair<bool,double> path = crossing.pathLength(det->surface());
00374 if ( ! path.first ) continue;
00375 LocalPoint lpos = det->toLocal(GlobalPoint(crossing.position(path.second)));
00376 if ( ! det->surface().bounds().inside(lpos) ) continue;
00377 const DTTopology& dtTopo = layer[ilayer]->specificTopology();
00378 int wire = dtTopo.channel(lpos);
00379 if (wire - dtTopo.firstChannel() < 0 || wire - dtTopo.lastChannel() > 0 ) continue;
00380
00381
00382
00383 DTWireId wid(lid,wire);
00384 double thickness = det->surface().bounds().thickness();
00385 LocalVector lmom = det->toLocal(GlobalVector(crossing.direction(path.second)));
00386 lmom = lmom.unit()*propagatedState.localMomentum().mag();
00387
00388
00389
00390 double pmu = lmom.mag();
00391 double theDTHitIneff = pmu>0? exp(kDT*log(pmu)+fDT):0.;
00392 if (random->flatShoot()<theDTHitIneff) continue;
00393
00394 double eloss = 0;
00395 double pz = fabs(lmom.z());
00396 LocalPoint entry = lpos - 0.5*thickness*lmom/pz;
00397 LocalPoint exit = lpos + 0.5*thickness*lmom/pz;
00398 double dtof = path.second*rbeta;
00399 int trkid = mySimTrack.trackId();
00400 unsigned int id = wid.rawId();
00401 short unsigned int processType = 2;
00402 PSimHit hit(entry,exit,lmom.mag(),
00403 tof+dtof,eloss,pid,id,trkid,lmom.theta(),lmom.phi(),processType);
00404 theDTHits.push_back(hit);
00405
00406 }
00407 }
00408 }
00409 else if ( gd->subDetector() == GeomDetEnumerators::CSC ) {
00410 CSCDetId id(gd->geographicalId());
00411 const CSCChamber *chamber = cscGeom->chamber(id);
00412 std::vector<const CSCLayer *> layers = chamber->layers();
00413 for ( unsigned int ilayer=0; ilayer<layers.size(); ilayer++ ) {
00414 CSCDetId lid = layers[ilayer]->id();
00415
00416 #ifdef FAMOS_DEBUG
00417 std::cout << " Extrapolated to CSC ("
00418 << lid.endcap() << ","
00419 << lid.ring() << ","
00420 << lid.station() << ","
00421 << lid.layer() << ")" << std::endl;
00422 #endif
00423
00424 const GeomDetUnit *det = cscGeom->idToDetUnit(lid);
00425 HelixArbitraryPlaneCrossing crossing(propagatedState.globalPosition().basicVector(),
00426 propagatedState.globalMomentum().basicVector(),
00427 propagatedState.transverseCurvature(),
00428 anyDirection);
00429 std::pair<bool,double> path = crossing.pathLength(det->surface());
00430 if ( ! path.first ) continue;
00431 LocalPoint lpos = det->toLocal(GlobalPoint(crossing.position(path.second)));
00432
00433
00434
00435 const CSCLayerGeometry* laygeom = layers[ilayer]->geometry();
00436 if ( ! laygeom->inside( lpos ) ) continue;
00437
00438 double thickness = det->surface().bounds().thickness();
00439 LocalVector lmom = det->toLocal(GlobalVector(crossing.direction(path.second)));
00440 lmom = lmom.unit()*propagatedState.localMomentum().mag();
00441
00442
00443
00444 double pmu = lmom.mag();
00445 double theCSCHitIneff = pmu>0? exp(kCSC*log(pmu)+fCSC):0.;
00446
00447 if (id.station()==1 && id.ring()==1) theCSCHitIneff = theCSCHitIneff*0.442;
00448 if (random->flatShoot()<theCSCHitIneff) continue;
00449
00450 double eloss = 0;
00451 double pz = fabs(lmom.z());
00452 LocalPoint entry = lpos - 0.5*thickness*lmom/pz;
00453 LocalPoint exit = lpos + 0.5*thickness*lmom/pz;
00454 double dtof = path.second*rbeta;
00455 int trkid = mySimTrack.trackId();
00456 unsigned int id = lid.rawId();
00457 short unsigned int processType = 2;
00458 PSimHit hit(entry,exit,lmom.mag(),
00459 tof+dtof,eloss,pid,id,trkid,lmom.theta(),lmom.phi(),processType);
00460 theCSCHits.push_back(hit);
00461 }
00462 }
00463 else if ( gd->subDetector() == GeomDetEnumerators::RPCBarrel ||
00464 gd->subDetector() == GeomDetEnumerators::RPCEndcap ) {
00465 RPCDetId id(gd->geographicalId());
00466 const RPCChamber *chamber = rpcGeom->chamber(id);
00467 std::vector<const RPCRoll *> roll = chamber->rolls();
00468 for ( unsigned int iroll=0; iroll<roll.size(); iroll++ ) {
00469 RPCDetId rid = roll[iroll]->id();
00470
00471 #ifdef FAMOS_DEBUG
00472 std::cout << " Extrapolated to RPC ("
00473 << rid.ring() << ","
00474 << rid.station() << ","
00475 << rid.sector() << ","
00476 << rid.subsector() << ","
00477 << rid.layer() << ","
00478 << rid.roll() << ")" << std::endl;
00479 #endif
00480
00481 const GeomDetUnit *det = rpcGeom->idToDetUnit(rid);
00482 HelixArbitraryPlaneCrossing crossing(propagatedState.globalPosition().basicVector(),
00483 propagatedState.globalMomentum().basicVector(),
00484 propagatedState.transverseCurvature(),
00485 anyDirection);
00486 std::pair<bool,double> path = crossing.pathLength(det->surface());
00487 if ( ! path.first ) continue;
00488 LocalPoint lpos = det->toLocal(GlobalPoint(crossing.position(path.second)));
00489 if ( ! det->surface().bounds().inside(lpos) ) continue;
00490 double thickness = det->surface().bounds().thickness();
00491 LocalVector lmom = det->toLocal(GlobalVector(crossing.direction(path.second)));
00492 lmom = lmom.unit()*propagatedState.localMomentum().mag();
00493 double eloss = 0;
00494 double pz = fabs(lmom.z());
00495 LocalPoint entry = lpos - 0.5*thickness*lmom/pz;
00496 LocalPoint exit = lpos + 0.5*thickness*lmom/pz;
00497 double dtof = path.second*rbeta;
00498 int trkid = mySimTrack.trackId();
00499 unsigned int id = rid.rawId();
00500 short unsigned int processType = 2;
00501 PSimHit hit(entry,exit,lmom.mag(),
00502 tof+dtof,eloss,pid,id,trkid,lmom.theta(),lmom.phi(),processType);
00503 theRPCHits.push_back(hit);
00504 }
00505 }
00506 else {
00507 std::cout << "Extrapolated to unknown subdetector '" << gd->subDetector() << "'..." << std::endl;
00508 }
00509 }
00510 }
00511 }
00512
00513 std::auto_ptr<edm::PSimHitContainer> pcsc(new edm::PSimHitContainer);
00514 int n = 0;
00515 for ( std::vector<PSimHit>::const_iterator i = theCSCHits.begin();
00516 i != theCSCHits.end(); i++ ) {
00517 pcsc->push_back(*i);
00518 n += 1;
00519 }
00520 iEvent.put(pcsc,"MuonCSCHits");
00521
00522 std::auto_ptr<edm::PSimHitContainer> pdt(new edm::PSimHitContainer);
00523 n = 0;
00524 for ( std::vector<PSimHit>::const_iterator i = theDTHits.begin();
00525 i != theDTHits.end(); i++ ) {
00526 pdt->push_back(*i);
00527 n += 1;
00528 }
00529 iEvent.put(pdt,"MuonDTHits");
00530
00531 std::auto_ptr<edm::PSimHitContainer> prpc(new edm::PSimHitContainer);
00532 n = 0;
00533 for ( std::vector<PSimHit>::const_iterator i = theRPCHits.begin();
00534 i != theRPCHits.end(); i++ ) {
00535 prpc->push_back(*i);
00536 n += 1;
00537 }
00538 iEvent.put(prpc,"MuonRPCHits");
00539
00540 }
00541
00542 void
00543 MuonSimHitProducer::readParameters(const edm::ParameterSet& fastMuons,
00544 const edm::ParameterSet& fastTracks,
00545 const edm::ParameterSet& matEff) {
00546
00547 theSimModuleLabel_ = fastMuons.getParameter<std::string>("simModuleLabel");
00548 theSimModuleProcess_ = fastMuons.getParameter<std::string>("simModuleProcess");
00549 theTrkModuleLabel_ = fastMuons.getParameter<std::string>("trackModuleLabel");
00550 std::vector<double> simHitIneffDT = fastMuons.getParameter<std::vector<double> >("simHitDTIneffParameters");
00551 std::vector<double> simHitIneffCSC = fastMuons.getParameter<std::vector<double> >("simHitCSCIneffParameters");
00552 kDT = simHitIneffDT[0];
00553 fDT = simHitIneffDT[1];
00554 kCSC = simHitIneffCSC[0];
00555 fCSC = simHitIneffCSC[1];
00556
00557
00558 fullPattern_ = fastTracks.getUntrackedParameter<bool>("FullPatternRecognition");
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569 theMaterialEffects = 0;
00570 if ( matEff.getParameter<bool>("PairProduction") ||
00571 matEff.getParameter<bool>("Bremsstrahlung") ||
00572 matEff.getParameter<bool>("MuonBremsstrahlung") ||
00573 matEff.getParameter<bool>("EnergyLoss") ||
00574 matEff.getParameter<bool>("MultipleScattering") )
00575 theMaterialEffects = new MaterialEffects(matEff,random);
00576
00577 }
00578
00579 void
00580 MuonSimHitProducer::applyMaterialEffects(TrajectoryStateOnSurface& tsosWithdEdx,
00581 TrajectoryStateOnSurface& tsos,
00582 double radPath) {
00583
00584
00585 EnergyLossSimulator* energyLoss = theMaterialEffects->energyLossSimulator();
00586
00587
00588 MultipleScatteringSimulator* multipleScattering = theMaterialEffects->multipleScatteringSimulator();
00589
00590
00591 MuonBremsstrahlungSimulator* bremsstrahlung = theMaterialEffects->muonBremsstrahlungSimulator();
00592
00593
00594
00595 const Surface& nextSurface = tsos.surface();
00596 GlobalPoint gPos = energyLoss ? tsos.globalPosition() : tsosWithdEdx.globalPosition();
00597 GlobalVector gMom = energyLoss ? tsos.globalMomentum() : tsosWithdEdx.globalMomentum();
00598 double mu = 0.1056583692;
00599 double en = std::sqrt(gMom.mag2()+mu*mu);
00600
00601
00602 XYZTLorentzVector position(gPos.x(),gPos.y(),gPos.z(),0.);
00603 XYZTLorentzVector momentum(gMom.x(),gMom.y(),gMom.z(),en);
00604 float charge = (float)(tsos.charge());
00605 ParticlePropagator theMuon(momentum,position,charge,0);
00606 theMuon.setID(-(int)charge*13);
00607
00608
00609 if ( energyLoss ) {
00610
00611
00612 GlobalPoint gPosWithdEdx = tsosWithdEdx.globalPosition();
00613 GlobalVector gMomWithdEdx = tsosWithdEdx.globalMomentum();
00614 double enWithdEdx = std::sqrt(gMomWithdEdx.mag2()+mu*mu);
00615 XYZTLorentzVector
00616 deltaPos(gPosWithdEdx.x()-gPos.x(),gPosWithdEdx.y()-gPos.y(),
00617 gPosWithdEdx.z()-gPos.z(),0.);
00618 XYZTLorentzVector
00619 deltaMom(gMomWithdEdx.x()-gMom.x(),gMomWithdEdx.y()-gMom.y(),
00620 gMomWithdEdx.z()-gMom.z(), enWithdEdx -en);
00621
00622
00623 energyLoss->updateState(theMuon,radPath);
00624
00625
00626
00627 radPath *= -deltaMom.E()/energyLoss->mostLikelyLoss();
00628 double fac = energyLoss->deltaMom().E()/energyLoss->mostLikelyLoss();
00629
00630
00631 XYZTLorentzVector theNewMomentum = theMuon.momentum() + energyLoss->deltaMom() + fac * deltaMom;
00632 XYZTLorentzVector theNewPosition = theMuon.vertex() + fac * deltaPos;
00633 fac = (theNewMomentum.E()*theNewMomentum.E()-mu*mu)/theNewMomentum.Vect().Mag2();
00634 fac = fac>0.? std::sqrt(fac) : 1E-9;
00635 theMuon.SetXYZT(theNewMomentum.Px()*fac,theNewMomentum.Py()*fac,
00636 theNewMomentum.Pz()*fac,theNewMomentum.E());
00637 theMuon.setVertex(theNewPosition);
00638
00639 }
00640
00641
00642 if ( multipleScattering ) {
00643
00644 GlobalVector normal = nextSurface.tangentPlane(tsos.globalPosition())->normalVector();
00645 multipleScattering->setNormalVector(normal);
00646
00647 multipleScattering->updateState(theMuon,radPath);
00648 }
00649
00650
00651 if ( bremsstrahlung ) {
00652
00653 bremsstrahlung->updateState(theMuon,radPath);
00654 }
00655
00656
00657
00658 GlobalPoint propagatedPosition(theMuon.X(),theMuon.Y(),theMuon.Z());
00659 GlobalVector propagatedMomentum(theMuon.Px(),theMuon.Py(),theMuon.Pz());
00660 GlobalTrajectoryParameters propagatedGtp(propagatedPosition,propagatedMomentum,(int)charge,magfield);
00661 tsosWithdEdx = TrajectoryStateOnSurface(propagatedGtp,nextSurface);
00662
00663 }
00664
00665
00666
00667
00668 DEFINE_FWK_MODULE(MuonSimHitProducer);