CMS 3D CMS Logo

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