00001
00002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00003
00004
00005 #include "DataFormats/GeometrySurface/interface/BoundDisk.h"
00006 #include "DataFormats/GeometrySurface/interface/BoundCylinder.h"
00007 #include "DataFormats/GeometrySurface/interface/Surface.h"
00008 #include "DataFormats/GeometrySurface/interface/TangentPlane.h"
00009
00010
00011 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00012 #include "TrackingTools/DetLayers/interface/BarrelDetLayer.h"
00013 #include "TrackingTools/DetLayers/interface/ForwardDetLayer.h"
00014 #include "TrackingTools/GeomPropagators/interface/AnalyticalPropagator.h"
00015 #include "FastSimulation/TrajectoryManager/interface/InsideBoundsMeasurementEstimator.h"
00016 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00017 #include "TrackingTools/GeomPropagators/interface/HelixArbitraryPlaneCrossing.h"
00018 #include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
00019
00020
00021
00022 #include "FastSimulation/TrajectoryManager/interface/TrajectoryManager.h"
00023 #include "FastSimulation/TrajectoryManager/interface/LocalMagneticField.h"
00024 #include "FastSimulation/ParticlePropagator/interface/ParticlePropagator.h"
00025 #include "FastSimulation/TrackerSetup/interface/TrackerInteractionGeometry.h"
00026 #include "FastSimulation/ParticleDecay/interface/Pythia6Decays.h"
00027 #include "FastSimulation/Event/interface/FSimEvent.h"
00028 #include "FastSimulation/Event/interface/FSimVertex.h"
00029 #include "FastSimulation/Event/interface/KineParticleFilter.h"
00030
00031 #include "FastSimulation/Utilities/interface/RandomEngine.h"
00032
00033
00034
00035
00036
00037
00038 #ifdef FAMOS_DEBUG
00039 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00040 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00041 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00042 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00043 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00044 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00045 #endif
00046
00047 #include <list>
00048
00049 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00050
00051 TrajectoryManager::TrajectoryManager(FSimEvent* aSimEvent,
00052 const edm::ParameterSet& matEff,
00053 const edm::ParameterSet& simHits,
00054 const edm::ParameterSet& decays,
00055 const RandomEngine* engine) :
00056 mySimEvent(aSimEvent),
00057 _theGeometry(0),
00058 _theFieldMap(0),
00059 theMaterialEffects(0),
00060 myDecayEngine(0),
00061 theGeomTracker(0),
00062 theGeomSearchTracker(0),
00063 theLayerMap(56, static_cast<const DetLayer*>(0)),
00064 theNegLayerOffset(27),
00065
00066 random(engine)
00067
00068 {
00069
00070
00071 if ( decays.getParameter<bool>("ActivateDecays") ) {
00072
00073
00074
00075 myDecayEngine = new Pythia6Decays();
00076 distCut = decays.getParameter<double>("DistCut");
00077 }
00078
00079
00080 if ( matEff.getParameter<bool>("PairProduction") ||
00081 matEff.getParameter<bool>("Bremsstrahlung") ||
00082 matEff.getParameter<bool>("MuonBremsstrahlung") ||
00083 matEff.getParameter<bool>("EnergyLoss") ||
00084 matEff.getParameter<bool>("MultipleScattering") ||
00085 matEff.getParameter<bool>("NuclearInteraction")
00086 )
00087 theMaterialEffects = new MaterialEffects(matEff,random);
00088
00089
00090
00091 firstLoop = simHits.getUntrackedParameter<bool>("firstLoop",true);
00092
00093 pTmin = simHits.getUntrackedParameter<double>("pTmin",0.5);
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 }
00106
00107 void
00108 TrajectoryManager::initializeRecoGeometry(const GeometricSearchTracker* geomSearchTracker,
00109 const TrackerInteractionGeometry* interactionGeometry,
00110 const MagneticFieldMap* aFieldMap)
00111 {
00112
00113
00114 theGeomSearchTracker = geomSearchTracker;
00115
00116
00117 _theGeometry = interactionGeometry;
00118
00119 initializeLayerMap();
00120
00121
00122 _theFieldMap = aFieldMap;
00123
00124 }
00125
00126 void
00127 TrajectoryManager::initializeTrackerGeometry(const TrackerGeometry* geomTracker) {
00128
00129 theGeomTracker = geomTracker;
00130
00131 }
00132
00133 const TrackerInteractionGeometry*
00134 TrajectoryManager::theGeometry() {
00135 return _theGeometry;
00136 }
00137
00138 TrajectoryManager::~TrajectoryManager() {
00139
00140 if ( myDecayEngine ) delete myDecayEngine;
00141 if ( theMaterialEffects ) delete theMaterialEffects;
00142
00143
00144
00145
00146
00147 }
00148
00149 void
00150 TrajectoryManager::reconstruct()
00151 {
00152
00153
00154
00155 thePSimHits.clear();
00156
00157
00158 XYZTLorentzVector myBeamPipe = XYZTLorentzVector(0.,2.5, 9999999.,0.);
00159
00160 std::list<TrackerLayer>::const_iterator cyliter;
00161
00162
00163
00164
00165 for( int fsimi=0; fsimi < (int) mySimEvent->nTracks(); ++fsimi) {
00166
00167
00168
00169
00170
00171 if( !mySimEvent->track(fsimi).notYetToEndVertex(myBeamPipe) ) continue;
00172 mySimEvent->track(fsimi).setPropagate();
00173
00174
00175 cyliter = _theGeometry->cylinderBegin();
00176
00177 ParticlePropagator PP(mySimEvent->track(fsimi),_theFieldMap,random);
00178
00179 int success = 1;
00180 int sign = +1;
00181 int loop = 0;
00182 int cyl = 0;
00183
00184
00185 for ( ; cyliter != _theGeometry->cylinderEnd() ; ++cyliter ) {
00186
00187 PP.setPropagationConditions(*cyliter);
00188 if ( PP.inside() && !PP.onSurface() ) break;
00189 ++cyl;
00190
00191 }
00192
00193
00194
00195
00196
00197
00198
00199
00200 double ppcos2T = PP.cos2Theta();
00201 double ppcos2V = PP.cos2ThetaV();
00202 if ( ( ppcos2T > 0.99 && ppcos2T < 0.9998 ) && ( cyl == 0 || ( ppcos2V > 0.99 && ppcos2V < 0.9998 ) ) ){
00203 if ( cyliter != _theGeometry->cylinderEnd() ) {
00204 cyliter = _theGeometry->cylinderEnd();
00205 --cyliter;
00206 }
00207
00208 } else if ( ppcos2T > 0.9998 && ( cyl == 0 || ppcos2V > 0.9998 ) ) {
00209 cyliter = _theGeometry->cylinderEnd();
00210 }
00211
00212
00213 while ( cyliter != _theGeometry->cylinderEnd() &&
00214 loop<100 &&
00215 mySimEvent->track(fsimi).notYetToEndVertex(PP.vertex())) {
00216
00217
00218 if ( cyliter->surface().mediumProperties()->radLen() < 1E-10 ) {
00219 ++cyliter; ++cyl;
00220 continue;
00221 }
00222
00223
00224
00225
00226 bool escapeBarrel = PP.getSuccess() == -1;
00227 bool escapeEndcap = (PP.getSuccess() == -2 && success == 1);
00228
00229 bool fullPropagation =
00230 (PP.getSuccess() <= 0 && success==0) || escapeEndcap;
00231
00232 if ( escapeBarrel ) {
00233 ++cyliter; ++cyl;
00234 while (cyliter != _theGeometry->cylinderEnd() && cyliter->forward() ) {
00235 sign=1; ++cyliter; ++cyl;
00236 }
00237
00238 if ( cyliter == _theGeometry->cylinderEnd() ) {
00239 --cyliter; --cyl; fullPropagation=true;
00240 }
00241
00242 }
00243
00244
00245 PP.setPropagationConditions(*cyliter,!fullPropagation);
00246 if ( escapeEndcap ) PP.increaseRCyl(0.0005);
00247
00248
00249 success = PP.getSuccess();
00250
00251
00252
00253 if ( !PP.propagateToBoundSurface(*cyliter) ||
00254 PP.getSuccess()<=0) {
00255 sign = -sign;
00256 ++loop;
00257 }
00258
00259
00260
00261 if ( PP.hasDecayed() || (!mySimEvent->track(fsimi).nDaughters() && PP.PDGcTau()<1E-3 ) ) {
00262 updateWithDaughters(PP,fsimi);
00263 break;
00264 }
00265
00266
00267
00268 if ( PP.getSuccess()==2 || cyliter==_theGeometry->cylinderBegin() )
00269 sign = +1;
00270
00271
00272 if( PP.getSuccess() > 0 && PP.onFiducial() ) {
00273
00274 bool saveHit =
00275 ( (loop==0 && sign>0) || !firstLoop ) &&
00276 PP.charge()!=0. &&
00277 cyliter->sensitive() &&
00278 PP.Perp2()>pTmin*pTmin;
00279
00280
00281 if ( theMaterialEffects )
00282 theMaterialEffects->interact(*mySimEvent,*cyliter,PP,fsimi);
00283
00284
00285 saveHit &= PP.E()>1E-6;
00286
00287 if ( saveHit ) {
00288
00289
00290 if ( cyliter->sensitive() ) {
00291
00292
00293
00294
00295
00296 if ( theGeomTracker )
00297 createPSimHits(*cyliter, PP, thePSimHits[fsimi], fsimi,mySimEvent->track(fsimi).type());
00298
00299 }
00300 }
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 if ( mySimEvent->track(fsimi).notYetToEndVertex(PP.vertex()) &&
00313 !mySimEvent->filter().accept(PP) )
00314 mySimEvent->addSimVertex(PP.vertex(),fsimi, FSimVertexType::END_VERTEX);
00315
00316 }
00317
00318
00319 if ( mySimEvent->track(fsimi).notYetToEndVertex(PP.vertex()) ) {
00320
00321
00322
00323 if (sign==1) {++cyliter;++cyl;}
00324 else {--cyliter;--cyl;}
00325
00326
00327 if( cyliter==_theGeometry->cylinderEnd()) {
00328
00329
00330
00331
00332 PP.propagateToEcal();
00333
00334
00335
00336 if(PP.getSuccess()==0) {
00337 --cyliter; --cyl; sign = -sign;
00338 PP.setPropagationConditions(*cyliter);
00339 PP.propagateToBoundSurface(*cyliter);
00340
00341
00342 if(PP.getSuccess()<0) {++cyliter; ++cyl;}
00343
00344 }
00345
00346
00347 if ( PP.hasDecayed() )
00348 updateWithDaughters(PP,fsimi);
00349
00350 }
00351 }
00352
00353 }
00354
00355
00356
00357 if ( mySimEvent->track(fsimi).notYetToEndVertex(PP.vertex()) )
00358 propagateToCalorimeters(PP,fsimi);
00359
00360 }
00361
00362
00363 if ( theMaterialEffects ) theMaterialEffects->save();
00364
00365 }
00366
00367 void
00368 TrajectoryManager::propagateToCalorimeters(ParticlePropagator& PP, int fsimi) {
00369
00370 FSimTrack& myTrack = mySimEvent->track(fsimi);
00371
00372
00373 myTrack.setTkPosition(PP.vertex().Vect());
00374 myTrack.setTkMomentum(PP.momentum());
00375
00376
00377 PP.propagateToPreshowerLayer1(false);
00378 if ( PP.hasDecayed() ) {
00379 updateWithDaughters(PP,fsimi);
00380 return;
00381 }
00382 if ( myTrack.notYetToEndVertex(PP.vertex()) && PP.getSuccess() > 0 )
00383 myTrack.setLayer1(PP,PP.getSuccess());
00384
00385
00386 PP.propagateToPreshowerLayer2(false);
00387 if ( PP.hasDecayed() ) {
00388 updateWithDaughters(PP,fsimi);
00389 return;
00390 }
00391 if ( myTrack.notYetToEndVertex(PP.vertex()) && PP.getSuccess() > 0 )
00392 myTrack.setLayer2(PP,PP.getSuccess());
00393
00394
00395 PP.propagateToEcalEntrance(false);
00396 if ( PP.hasDecayed() ) {
00397 updateWithDaughters(PP,fsimi);
00398 return;
00399 }
00400 if ( myTrack.notYetToEndVertex(PP.vertex()) )
00401 myTrack.setEcal(PP,PP.getSuccess());
00402
00403
00404 PP.propagateToHcalEntrance(false);
00405 if ( PP.hasDecayed() ) {
00406 updateWithDaughters(PP,fsimi);
00407 return;
00408 }
00409 if ( myTrack.notYetToEndVertex(PP.vertex()) )
00410 myTrack.setHcal(PP,PP.getSuccess());
00411
00412
00413 PP.propagateToVFcalEntrance(false);
00414 if ( PP.hasDecayed() ) {
00415 updateWithDaughters(PP,fsimi);
00416 return;
00417 }
00418 if ( myTrack.notYetToEndVertex(PP.vertex()) )
00419 myTrack.setVFcal(PP,PP.getSuccess());
00420
00421 }
00422
00423 bool
00424 TrajectoryManager::propagateToLayer(ParticlePropagator& PP, unsigned layer) {
00425
00426 std::list<TrackerLayer>::const_iterator cyliter;
00427 bool done = false;
00428
00429
00430 cyliter = _theGeometry->cylinderBegin();
00431
00432
00433 for ( ; cyliter != _theGeometry->cylinderEnd() ; ++cyliter ) {
00434
00435 if ( layer != cyliter->layerNumber() ) continue;
00436
00437 PP.setPropagationConditions(*cyliter);
00438
00439 done =
00440 PP.propagateToBoundSurface(*cyliter) &&
00441 PP.getSuccess() > 0 &&
00442 PP.onFiducial();
00443
00444 break;
00445
00446 }
00447
00448 return done;
00449
00450 }
00451
00452 void
00453 TrajectoryManager::updateWithDaughters(ParticlePropagator& PP, int fsimi) {
00454
00455
00456
00457
00458
00459 unsigned nDaugh = mySimEvent->track(fsimi).nDaughters();
00460 if ( nDaugh ) {
00461
00462
00463 unsigned vertexId = mySimEvent->track(fsimi).endVertex().id();
00464 mySimEvent->vertex(vertexId).setPosition(PP.vertex());
00465
00466
00467 XYZTLorentzVector momentumBefore = mySimEvent->track(fsimi).momentum();
00468 XYZTLorentzVector momentumAfter = PP.momentum();
00469 double magBefore = std::sqrt(momentumBefore.Vect().mag2());
00470 double magAfter = std::sqrt(momentumAfter.Vect().mag2());
00471
00472 XYZVector axis = momentumBefore.Vect().Cross(momentumAfter.Vect());
00473 double angle = std::acos(momentumBefore.Vect().Dot(momentumAfter.Vect())/(magAfter*magBefore));
00474 Rotation r(axis,angle);
00475
00476 double rescale = magAfter/magBefore;
00477
00478
00479 moveAllDaughters(fsimi,r,rescale);
00480
00481
00482 } else {
00483
00484
00485 if ( !myDecayEngine ) return;
00486
00487
00488 const DaughterParticleList& daughters = myDecayEngine->particleDaughters(PP);
00489
00490
00491 if ( daughters.size() ) {
00492 double distMin = 1E99;
00493 int theClosestChargedDaughterId = -1;
00494 DaughterParticleIterator daughter = daughters.begin();
00495
00496 int ivertex = mySimEvent->addSimVertex(daughter->vertex(),fsimi,
00497 FSimVertexType::DECAY_VERTEX);
00498
00499 if ( ivertex != -1 ) {
00500 for ( ; daughter != daughters.end(); ++daughter) {
00501 int theDaughterId = mySimEvent->addSimTrack(&(*daughter), ivertex);
00502
00503 if ( PP.charge() * daughter->charge() > 1E-10 ) {
00504 double dist = (daughter->Vect().Unit().Cross(PP.Vect().Unit())).R();
00505 if ( dist < distCut && dist < distMin ) {
00506 distMin = dist;
00507 theClosestChargedDaughterId = theDaughterId;
00508 }
00509 }
00510 }
00511 }
00512
00513 if ( theClosestChargedDaughterId >=0 )
00514 mySimEvent->track(fsimi).setClosestDaughterId(theClosestChargedDaughterId);
00515 }
00516
00517 }
00518
00519 }
00520
00521
00522 void
00523 TrajectoryManager::moveAllDaughters(int fsimi, const Rotation& r, double rescale) {
00524
00525
00526 for ( unsigned idaugh=0; idaugh < (unsigned)(mySimEvent->track(fsimi).nDaughters()); ++idaugh) {
00527
00528 XYZTLorentzVector daughMomentum (mySimEvent->track(fsimi).daughter(idaugh).momentum());
00529
00530 XYZVector newMomentum (r * daughMomentum.Vect());
00531 newMomentum *= rescale;
00532 double newEnergy = std::sqrt(newMomentum.mag2() + daughMomentum.mag2());
00533
00534 mySimEvent->track(fsimi).setMomentum(XYZTLorentzVector(newMomentum.X(),newMomentum.Y(),newMomentum.Z(),newEnergy));
00535
00536 int fsimDaug = mySimEvent->track(fsimi).daughter(idaugh).id();
00537 moveAllDaughters(fsimDaug,r,rescale);
00538 }
00539 }
00540
00541 void
00542 TrajectoryManager::createPSimHits(const TrackerLayer& layer,
00543 const ParticlePropagator& PP,
00544 std::map<double,PSimHit>& theHitMap,
00545 int trackID, int partID) {
00546
00547
00548
00549
00550
00551
00552 LocalMagneticField mf(PP.getMagneticField());
00553 AnalyticalPropagator alongProp(&mf, anyDirection);
00554 InsideBoundsMeasurementEstimator est;
00555
00556 typedef GeometricSearchDet::DetWithState DetWithState;
00557 const DetLayer* tkLayer = detLayer(layer,PP.Z());
00558
00559 TrajectoryStateOnSurface trajState = makeTrajectoryState( tkLayer, PP, &mf);
00560 float thickness = theMaterialEffects ? theMaterialEffects->thickness() : 0.;
00561 float eloss = theMaterialEffects ? theMaterialEffects->energyLoss() : 0.;
00562
00563
00564
00565 std::vector<DetWithState> compat
00566 = tkLayer->compatibleDets( trajState, alongProp, est);
00567
00568
00569 std::map<double,PSimHit> theTrackHits;
00570 for (std::vector<DetWithState>::const_iterator i=compat.begin(); i!=compat.end(); i++) {
00571
00572
00573 makePSimHits( i->first, i->second, theHitMap, trackID, eloss, thickness, partID);
00574 }
00575 }
00576
00577 TrajectoryStateOnSurface
00578 TrajectoryManager::makeTrajectoryState( const DetLayer* layer,
00579 const ParticlePropagator& pp,
00580 const MagneticField* field) const
00581 {
00582 GlobalPoint pos( pp.X(), pp.Y(), pp.Z());
00583 GlobalVector mom( pp.Px(), pp.Py(), pp.Pz());
00584 ReferenceCountingPointer<TangentPlane> plane = layer->surface().tangentPlane(pos);
00585 return TrajectoryStateOnSurface
00586 (GlobalTrajectoryParameters( pos, mom, TrackCharge( pp.charge()), field), *plane);
00587 }
00588
00589 void
00590 TrajectoryManager::makePSimHits( const GeomDet* det,
00591 const TrajectoryStateOnSurface& ts,
00592 std::map<double,PSimHit>& theHitMap,
00593 int tkID, float el, float thick, int pID )
00594 {
00595
00596 std::vector< const GeomDet*> comp = det->components();
00597 if (!comp.empty()) {
00598 for (std::vector< const GeomDet*>::const_iterator i = comp.begin();
00599 i != comp.end(); i++) {
00600 const GeomDetUnit* du = dynamic_cast<const GeomDetUnit*>(*i);
00601 if (du != 0)
00602 theHitMap.insert(theHitMap.end(),makeSinglePSimHit( *du, ts, tkID, el, thick, pID));
00603 }
00604 }
00605 else {
00606 const GeomDetUnit* du = dynamic_cast<const GeomDetUnit*>(det);
00607 if (du != 0)
00608 theHitMap.insert(theHitMap.end(),makeSinglePSimHit( *du, ts, tkID, el, thick, pID));
00609 }
00610
00611
00612 }
00613
00614 std::pair<double,PSimHit>
00615 TrajectoryManager::makeSinglePSimHit( const GeomDetUnit& det,
00616 const TrajectoryStateOnSurface& ts,
00617 int tkID, float el, float thick, int pID) const
00618 {
00619
00620 const float onSurfaceTolarance = 0.01;
00621
00622 LocalPoint lpos;
00623 LocalVector lmom;
00624 if ( fabs( det.toLocal(ts.globalPosition()).z()) < onSurfaceTolarance) {
00625 lpos = ts.localPosition();
00626 lmom = ts.localMomentum();
00627 }
00628 else {
00629 HelixArbitraryPlaneCrossing crossing( ts.globalPosition().basicVector(),
00630 ts.globalMomentum().basicVector(),
00631 ts.transverseCurvature(),
00632 anyDirection);
00633 std::pair<bool,double> path = crossing.pathLength(det.surface());
00634 if (!path.first) {
00635
00636 return std::pair<double,PSimHit>(0.,PSimHit());
00637 }
00638 lpos = det.toLocal( GlobalPoint( crossing.position(path.second)));
00639 lmom = det.toLocal( GlobalVector( crossing.direction(path.second)));
00640 lmom = lmom.unit() * ts.localMomentum().mag();
00641 }
00642
00643
00644 const BoundPlane& theDetPlane = det.surface();
00645 float halfThick = 0.5*theDetPlane.bounds().thickness();
00646
00647 float eloss = el;
00648 if ( thick > 0. ) {
00649
00650
00651
00652 eloss *= (2.* halfThick - 0.003) / (9.36 * thick);
00653 }
00654
00655 float pZ = lmom.z();
00656 LocalPoint entry = lpos + (-halfThick/pZ) * lmom;
00657 LocalPoint exit = lpos + halfThick/pZ * lmom;
00658 float tof = ts.globalPosition().mag() / 30. ;
00659
00660
00661
00662
00663 int localTkID = tkID;
00664 if ( mySimEvent->track(tkID).mother().closestDaughterId() == tkID )
00665 localTkID = mySimEvent->track(tkID).mother().id();
00666
00667
00668 PSimHit hit( entry, exit, lmom.mag(), tof, eloss, pID,
00669 det.geographicalId().rawId(), localTkID,
00670 lmom.theta(),
00671 lmom.phi());
00672
00673
00674 unsigned subdet = DetId(hit.detUnitId()).subdetId();
00675 double boundX = theDetPlane.bounds().width()/2.;
00676 double boundY = theDetPlane.bounds().length()/2.;
00677
00678
00679 if ( subdet == 4 || subdet == 6 )
00680 boundX *= 1. - hit.localPosition().y()/theDetPlane.position().perp();
00681
00682 #ifdef FAMOS_DEBUG
00683 unsigned detid = DetId(hit.detUnitId()).rawId();
00684 unsigned stereo = 0;
00685 unsigned theLayer = 0;
00686 unsigned theRing = 0;
00687 switch (subdet) {
00688 case 1:
00689 {
00690 PXBDetId module(detid);
00691 theLayer = module.layer();
00692 std::cout << "\tPixel Barrel Layer " << theLayer << std::endl;
00693 stereo = 1;
00694 break;
00695 }
00696 case 2:
00697 {
00698 PXFDetId module(detid);
00699 theLayer = module.disk();
00700 std::cout << "\tPixel Forward Disk " << theLayer << std::endl;
00701 stereo = 1;
00702 break;
00703 }
00704 case 3:
00705 {
00706 TIBDetId module(detid);
00707 theLayer = module.layer();
00708 std::cout << "\tTIB Layer " << theLayer << std::endl;
00709 stereo = module.stereo();
00710 break;
00711 }
00712 case 4:
00713 {
00714 TIDDetId module(detid);
00715 theLayer = module.wheel();
00716 theRing = module.ring();
00717 unsigned int theSide = module.side();
00718 if ( theSide == 1 )
00719 std::cout << "\tTID Petal Back " << std::endl;
00720 else
00721 std::cout << "\tTID Petal Front" << std::endl;
00722 std::cout << "\tTID Layer " << theLayer << std::endl;
00723 std::cout << "\tTID Ring " << theRing << std::endl;
00724 stereo = module.stereo();
00725 break;
00726 }
00727 case 5:
00728 {
00729 TOBDetId module(detid);
00730 theLayer = module.layer();
00731 stereo = module.stereo();
00732 std::cout << "\tTOB Layer " << theLayer << std::endl;
00733 break;
00734 }
00735 case 6:
00736 {
00737 TECDetId module(detid);
00738 theLayer = module.wheel();
00739 theRing = module.ring();
00740 unsigned int theSide = module.petal()[0];
00741 if ( theSide == 1 )
00742 std::cout << "\tTEC Petal Back " << std::endl;
00743 else
00744 std::cout << "\tTEC Petal Front" << std::endl;
00745 std::cout << "\tTEC Layer " << theLayer << std::endl;
00746 std::cout << "\tTEC Ring " << theRing << std::endl;
00747 stereo = module.stereo();
00748 break;
00749 }
00750 default:
00751 {
00752 stereo = 0;
00753 break;
00754 }
00755 }
00756
00757 std::cout << "Thickness = " << 2.*halfThick-0.003 << "; " << thick * 9.36 << std::endl
00758 << "Length = " << det.surface().bounds().length() << std::endl
00759 << "Width = " << det.surface().bounds().width() << std::endl;
00760
00761 std::cout << "Hit position = "
00762 << hit.localPosition().x() << " "
00763 << hit.localPosition().y() << " "
00764 << hit.localPosition().z() << std::endl;
00765 #endif
00766
00767
00768
00769
00770
00771
00772 double dist = 0.;
00773 GlobalPoint IP (mySimEvent->track(localTkID).vertex().position().x(),
00774 mySimEvent->track(localTkID).vertex().position().y(),
00775 mySimEvent->track(localTkID).vertex().position().z());
00776
00777 dist = ( fabs(hit.localPosition().x()) > boundX ||
00778 fabs(hit.localPosition().y()) > boundY ) ?
00779
00780 -( det.surface().toGlobal(hit.localPosition()) - IP ).mag2()
00781 :
00782
00783 ( det.surface().toGlobal(hit.localPosition()) - IP ).mag2();
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795 return std::pair<double,PSimHit>(dist,hit);
00796
00797 }
00798
00799 void
00800 TrajectoryManager::initializeLayerMap()
00801 {
00802
00803
00804
00805
00806
00807
00808
00809
00810
00813
00814 std::vector< BarrelDetLayer*> barrelLayers =
00815 theGeomSearchTracker->barrelLayers();
00816 LogDebug("FastTracking") << "Barrel DetLayer dump: ";
00817 for (std::vector< BarrelDetLayer*>::const_iterator bl=barrelLayers.begin();
00818 bl != barrelLayers.end(); ++bl) {
00819 LogDebug("FastTracking")<< "radius " << (**bl).specificSurface().radius();
00820 }
00821
00822 std::vector< ForwardDetLayer*> posForwardLayers =
00823 theGeomSearchTracker->posForwardLayers();
00824 LogDebug("FastTracking") << "Positive Forward DetLayer dump: ";
00825 for (std::vector< ForwardDetLayer*>::const_iterator fl=posForwardLayers.begin();
00826 fl != posForwardLayers.end(); ++fl) {
00827 LogDebug("FastTracking") << "Z pos "
00828 << (**fl).surface().position().z()
00829 << " radii "
00830 << (**fl).specificSurface().innerRadius()
00831 << ", "
00832 << (**fl).specificSurface().outerRadius();
00833 }
00834
00835 const float rTolerance = 1.5;
00836 const float zTolerance = 3.;
00837
00838 LogDebug("FastTracking")<< "Dump of TrackerInteractionGeometry cylinders:";
00839 for( std::list<TrackerLayer>::const_iterator i=_theGeometry->cylinderBegin();
00840 i!=_theGeometry->cylinderEnd(); ++i) {
00841 const BoundCylinder* cyl = i->cylinder();
00842 const BoundDisk* disk = i->disk();
00843
00844 LogDebug("FastTracking") << "Famos Layer no " << i->layerNumber()
00845 << " is sensitive? " << i->sensitive()
00846 << " pos " << i->surface().position();
00847 if (!i->sensitive()) continue;
00848
00849 if (cyl != 0) {
00850 LogDebug("FastTracking") << " cylinder radius " << cyl->radius();
00851 bool found = false;
00852 for (std::vector< BarrelDetLayer*>::const_iterator
00853 bl=barrelLayers.begin(); bl != barrelLayers.end(); ++bl) {
00854 if (fabs( cyl->radius() - (**bl).specificSurface().radius()) < rTolerance) {
00855 theLayerMap[i->layerNumber()] = *bl;
00856 found = true;
00857 LogDebug("FastTracking")<< "Corresponding DetLayer found with radius "
00858 << (**bl).specificSurface().radius();
00859 break;
00860 }
00861 }
00862 if (!found) {
00863 edm::LogWarning("FastTracking") << " Trajectory manager FAILED to find a corresponding DetLayer!";
00864 }
00865 }
00866 else {
00867 LogDebug("FastTracking") << " disk radii " << disk->innerRadius()
00868 << ", " << disk->outerRadius();
00869 bool found = false;
00870 for (std::vector< ForwardDetLayer*>::const_iterator fl=posForwardLayers.begin();
00871 fl != posForwardLayers.end(); ++fl) {
00872 if (fabs( disk->position().z() - (**fl).surface().position().z()) < zTolerance) {
00873 theLayerMap[i->layerNumber()] = *fl;
00874 found = true;
00875 LogDebug("FastTracking") << "Corresponding DetLayer found with Z pos "
00876 << (**fl).surface().position().z()
00877 << " and radii "
00878 << (**fl).specificSurface().innerRadius()
00879 << ", "
00880 << (**fl).specificSurface().outerRadius();
00881 break;
00882 }
00883 }
00884 if (!found) {
00885 edm::LogWarning("FastTracking") << "FAILED to find a corresponding DetLayer!";
00886 }
00887 }
00888 }
00889
00890
00891 std::vector< ForwardDetLayer*> negForwardLayers = theGeomSearchTracker->negForwardLayers();
00892 for (std::vector< ForwardDetLayer*>::const_iterator nl=negForwardLayers.begin();
00893 nl != negForwardLayers.end(); ++nl) {
00894 for (int i=0; i<=theNegLayerOffset; i++) {
00895 if (theLayerMap[i] == 0) continue;
00896 if ( fabs( (**nl).surface().position().z() +theLayerMap[i]-> surface().position().z()) < zTolerance) {
00897 theLayerMap[i+theNegLayerOffset] = *nl;
00898 break;
00899 }
00900 }
00901 }
00902
00903 }
00904
00905 const DetLayer*
00906 TrajectoryManager::detLayer( const TrackerLayer& layer, float zpos) const
00907 {
00908 if (zpos > 0 || !layer.forward() ) return theLayerMap[layer.layerNumber()];
00909 else return theLayerMap[layer.layerNumber()+theNegLayerOffset];
00910 }
00911
00912 void
00913 TrajectoryManager::loadSimHits(edm::PSimHitContainer & c) const
00914 {
00915
00916 std::map<unsigned,std::map<double,PSimHit> >::const_iterator itrack = thePSimHits.begin();
00917 std::map<unsigned,std::map<double,PSimHit> >::const_iterator itrackEnd = thePSimHits.end();
00918 for ( ; itrack != itrackEnd; ++itrack ) {
00919 std::map<double,PSimHit>::const_iterator it = (itrack->second).begin();
00920 std::map<double,PSimHit>::const_iterator itEnd = (itrack->second).end();
00921 for( ; it!= itEnd; ++it) {
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932 if ( it->first > 0. ) c.push_back(it->second);
00933 }
00934 }
00935
00936 }