CMS 3D CMS Logo

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