CMS 3D CMS Logo

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