CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/RecoTracker/SpecialSeedGenerators/src/CosmicSeedCreator.cc

Go to the documentation of this file.
00001 #include "RecoTracker/SpecialSeedGenerators/interface/CosmicSeedCreator.h"
00002 #include "RecoTracker/TkTrackingRegions/interface/TrackingRegion.h"
00003 #include "RecoTracker/TkSeedingLayers/interface/SeedingHitSet.h"
00004 #include "TrackingTools/KalmanUpdators/interface/KFUpdator.h"
00005 #include "RecoTracker/TkSeedGenerator/interface/FastHelix.h"
00006 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00007 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include "MagneticField/Engine/interface/MagneticField.h"
00010 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00011 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h" 
00012 #include "TrackingTools/Records/interface/TransientRecHitRecord.h" 
00013 #include "TrackingTools/MaterialEffects/interface/PropagatorWithMaterial.h"
00014 #include "FWCore/Framework/interface/ESHandle.h"
00015 #include "TrackingTools/GeomPropagators/interface/PropagationExceptions.h"
00016 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00017 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00018 #include "TrackingTools/MaterialEffects/interface/PropagatorWithMaterial.h"
00019 #include "TrackingTools/TrackAssociator/interface/DetIdInfo.h"
00020 
00021 template <class T> T sqr( T t) {return t*t;}
00022 
00023 const TrajectorySeed * CosmicSeedCreator::trajectorySeed(TrajectorySeedCollection & seedCollection,
00024                                                          const SeedingHitSet & ordered,
00025                                                          const TrackingRegion & region,
00026                                                          const edm::EventSetup& es)
00027 {
00028 
00029   //_________________________
00030   //
00031   //Get Parameters
00032   //________________________
00033 
00034 
00035   //hit package
00036   //+++++++++++
00037   const SeedingHitSet & hits = ordered; 
00038   if ( hits.size() < 2) return 0;
00039 
00040 
00041   //hits
00042   //++++
00043   TransientTrackingRecHit::ConstRecHitPointer tth1 = hits[0];
00044   TransientTrackingRecHit::ConstRecHitPointer tth2 = hits[1];
00045 
00046   TransientTrackingRecHit::ConstRecHitPointer usedHit;
00047 
00048   //definition of position & momentum
00049   //++++++++++++++++++++++++++++++++++
00050   GlobalVector initialMomentum(region.direction());//direction of the trajectory seed given by the direction of the region
00051   //fix the momentum scale
00052   //initialMomentum = initialMomentum.basicVector.unitVector() * region.origin().direction().mag();
00053   //initialMomentum = region.origin().direction(); //alternative.
00054   LogDebug("CosmicSeedCreator") << "initial momentum = " << initialMomentum;
00055 
00056 
00057   //magnetic field
00058   //++++++++++++++
00059   edm::ESHandle<MagneticField> bfield;
00060   es.get<IdealMagneticFieldRecord>().get(bfield);
00061 
00062   
00063   //___________________________________________
00064   //
00065   //Direction of the trajectory seed
00066   //___________________________________________
00067 
00068 
00069   //radius
00070   //++++++
00071   bool reverseAll = false;
00072   if ( fabs(tth1->globalPosition().perp()) < fabs(tth2->globalPosition().perp()) )  
00073     //comparison of the position of the 2 hits by checking/comparing their radius
00074     {
00075       usedHit=tth1;
00076       reverseAll = true;
00077     }
00078 
00079   else usedHit=tth2;
00080 
00081 
00082   //location in the barrel (up or bottom)
00083   //+++++++++++++++++++++++++++++++++++++
00084   //simple check, probably nees to be more precise FIXME
00085   bool bottomSeed = (usedHit->globalPosition().y()<0);
00086           
00087 
00088   //apply corrections
00089   //+++++++++++++++++
00090   edm::OwnVector<TrackingRecHit> seedHits;
00091 
00092   if (reverseAll){
00093     LogDebug("CosmicSeedCreator") <<"Reverse all applied";
00094 
00095     seedHits.push_back(tth2->hit()->clone());
00096     seedHits.push_back(tth1->hit()->clone());
00097   }
00098 
00099   else {
00100     seedHits.push_back(tth1->hit()->clone());
00101     seedHits.push_back(tth2->hit()->clone());
00102   }
00103 
00104   
00105   //propagation
00106   //+++++++++++
00107 
00108   PropagationDirection seedDirection = alongMomentum; //by default
00109 
00110   
00111   if (reverseAll) initialMomentum *=-1; 
00112 
00113   if (bottomSeed){
00114     //means that the seed parameters are inverse of what we want.
00115     //reverse the momentum again
00116     initialMomentum *=-1;
00117     //and change the direction of the seed
00118     seedDirection = oppositeToMomentum;
00119   }
00120   
00121 
00122   for (int charge=-1;charge<=1;charge+=2){
00123     //fixme, what hit do you want to use ?
00124     
00125     FreeTrajectoryState freeState(GlobalTrajectoryParameters(usedHit->globalPosition(),
00126                                                              initialMomentum, charge, &*bfield),
00127                                   CurvilinearTrajectoryError(AlgebraicSymMatrix(5,1))
00128                                   );
00129 
00130     LogDebug("CosmicSeedCreator")<<"Position freeState: " << usedHit->globalPosition()
00131                                  <<"\nCharge: "<< charge
00132                                  <<"\nInitial momentum :" << initialMomentum ;
00133 
00134     TrajectoryStateOnSurface tsos(freeState, *usedHit->surface());
00135     
00136     TrajectoryStateTransform transformer;
00137     boost::shared_ptr<PTrajectoryStateOnDet> PTraj(transformer.persistentState(tsos, usedHit->hit()->geographicalId().rawId()));
00138     seedCollection.push_back( TrajectorySeed(*PTraj,seedHits,seedDirection));
00139     
00140   }//end charge loop
00141   
00142   
00143   //________________
00144   //
00145   //Return seed
00146   //________________
00147 
00148     
00149   LogDebug("CosmicSeedCreator") 
00150     << "Using SeedCreator---------->\n"
00151     << "seedCollections size = " << seedCollection.size();
00152   
00153   if ( seedCollection.size() > maxseeds_ ) {
00154     edm::LogError("TooManySeeds") << "Found too many seeds (" << seedCollection.size() << " > " << maxseeds_ << "), bailing out.\n";
00155     seedCollection.clear();
00156     return &seedCollection.back();
00157   }
00158   else {
00159     return &seedCollection.back();
00160   }
00161   
00162 }