CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/RecoTracker/SingleTrackPattern/src/CosmicTrackFinder.cc

Go to the documentation of this file.
00001 // Package:    RecoTracker/SingleTrackPattern
00002 // Class:      CosmicTrackFinder
00003 // Original Author:  Michele Pioppi-INFN perugia
00004 #include <memory>
00005 #include <string>
00006 
00007 #include "RecoTracker/SingleTrackPattern/interface/CosmicTrackFinder.h"
00008 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
00009 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
00010 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2DCollection.h"
00011 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2DCollection.h"
00012 #include "DataFormats/Common/interface/Handle.h"
00013 #include "FWCore/Framework/interface/ESHandle.h"
00014 #include "FWCore/Framework/interface/EventSetup.h"
00015 #include "DataFormats/TrackReco/interface/Track.h"
00016 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00017 #include "DataFormats/TrackReco/interface/TrackExtra.h"
00018 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00020 #include "TrackingTools/PatternTools/interface/TSCPBuilderNoMaterial.h"
00021 #include "FWCore/Utilities/interface/InputTag.h"
00022 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00023 
00024 
00025 namespace cms
00026 {
00027 
00028   CosmicTrackFinder::CosmicTrackFinder(edm::ParameterSet const& conf) : 
00029     cosmicTrajectoryBuilder_(conf) ,
00030     crackTrajectoryBuilder_(conf) ,
00031     conf_(conf)
00032   {
00033     geometry=conf_.getUntrackedParameter<std::string>("GeometricStructure","STANDARD");
00034     produces<TrackCandidateCollection>();
00035   }
00036 
00037 
00038   // Virtual destructor needed.
00039   CosmicTrackFinder::~CosmicTrackFinder() { }  
00040 
00041   // Functions that gets called by framework every event
00042   void CosmicTrackFinder::produce(edm::Event& e, const edm::EventSetup& es)
00043   {
00044     using namespace std  ;
00045     edm::InputTag matchedrecHitsTag = conf_.getParameter<edm::InputTag>("matchedRecHits");
00046     edm::InputTag rphirecHitsTag = conf_.getParameter<edm::InputTag>("rphirecHits");
00047     edm::InputTag stereorecHitsTag = conf_.getParameter<edm::InputTag>("stereorecHits");
00048     edm::InputTag pixelRecHitsTag = conf_.getParameter<edm::InputTag>("pixelRecHits");  
00049 
00050 
00051     edm::InputTag seedTag = conf_.getParameter<edm::InputTag>("cosmicSeeds");
00052     // retrieve seeds
00053     edm::Handle<TrajectorySeedCollection> seed;
00054     e.getByLabel(seedTag,seed);  
00055 
00056   //retrieve PixelRecHits
00057     static const SiPixelRecHitCollection s_empty;
00058     const SiPixelRecHitCollection *pixelHitCollection = &s_empty;
00059     edm::Handle<SiPixelRecHitCollection> pixelHits;
00060     if (geometry!="MTCC" && (geometry!="CRACK" )) {
00061       if( e.getByLabel(pixelRecHitsTag, pixelHits)) {
00062         pixelHitCollection = pixelHits.product();
00063       } else {
00064         edm::LogWarning("CosmicTrackFinder") << "Collection SiPixelRecHitCollection with InputTag " << pixelRecHitsTag << " cannot be found, using empty collection of same type.";
00065       }
00066     }
00067     
00068    
00069 
00070 
00071  //retrieve StripRecHits
00072     edm::Handle<SiStripMatchedRecHit2DCollection> matchedrecHits;
00073     e.getByLabel( matchedrecHitsTag ,matchedrecHits);
00074     edm::Handle<SiStripRecHit2DCollection> rphirecHits;
00075     e.getByLabel( rphirecHitsTag ,rphirecHits);
00076     edm::Handle<SiStripRecHit2DCollection> stereorecHits;
00077     e.getByLabel( stereorecHitsTag, stereorecHits);
00078 
00079     // Step B: create empty output collection
00080     std::auto_ptr<TrackCandidateCollection> output(new TrackCandidateCollection);
00081 
00082     edm::ESHandle<TrackerGeometry> tracker;
00083     es.get<TrackerDigiGeometryRecord>().get(tracker);
00084     edm::LogVerbatim("CosmicTrackFinder") << "========== Cosmic Track Finder Info ==========";
00085     edm::LogVerbatim("CosmicTrackFinder") << " Numbers of Seeds " << (*seed).size();
00086     if((*seed).size()>0){
00087 
00088       std::vector<Trajectory> trajoutput;
00089       
00090       if(geometry!="CRACK" ) {
00091         cosmicTrajectoryBuilder_.run(*seed,
00092                                    *stereorecHits,
00093                                    *rphirecHits,
00094                                    *matchedrecHits,
00095                                    *pixelHitCollection,
00096                                    es,
00097                                    e,
00098                                    trajoutput);
00099       } else {
00100         crackTrajectoryBuilder_.run(*seed,
00101                                    *stereorecHits,
00102                                    *rphirecHits,
00103                                    *matchedrecHits,
00104                                    *pixelHitCollection,
00105                                    es,
00106                                    e,
00107                                    trajoutput);
00108       }
00109 
00110       edm::LogVerbatim("CosmicTrackFinder") << " Numbers of Temp Trajectories " << trajoutput.size();
00111       edm::LogVerbatim("CosmicTrackFinder") << "========== END Info ==========";
00112       if(trajoutput.size()>0){
00113         std::vector<Trajectory*> tmpTraj;
00114         std::vector<Trajectory>::iterator itr;
00115         for (itr=trajoutput.begin();itr!=trajoutput.end();itr++)tmpTraj.push_back(&(*itr));
00116 
00117         //The best track is selected
00118         //FOR MTCC the criteria are:
00119         //1)# of layers,2) # of Hits,3)Chi2
00120         if (geometry=="MTCC")  stable_sort(tmpTraj.begin(),tmpTraj.end(),CompareTrajLay());
00121         else  stable_sort(tmpTraj.begin(),tmpTraj.end(),CompareTrajChi());
00122 
00123 
00124 
00125         const Trajectory  theTraj = *(*tmpTraj.begin());
00126         bool seedplus=(theTraj.seed().direction()==alongMomentum);
00127         //PropagationDirection seedDir =theTraj.seed().direction();
00128 
00129         if (seedplus)
00130           LogDebug("CosmicTrackFinder")<<"Reconstruction along momentum ";
00131         else
00132           LogDebug("CosmicTrackFinder")<<"Reconstruction opposite to momentum";
00133 
00134         /*
00135         // === the convention is to save always final tracks with hits sorted *along* momentum  
00136         */
00137 
00138         Trajectory::RecHitContainer thits;
00139         //it->recHitsV(thits);
00140         theTraj.recHitsV(thits,true);
00141         edm::OwnVector<TrackingRecHit> recHits;
00142         recHits.reserve(thits.size());
00143 
00144         // reverse hit order
00145         for (Trajectory::RecHitContainer::const_iterator hitIt = thits.end()-1;
00146              hitIt >= thits.begin(); hitIt--) {
00147           recHits.push_back( (**hitIt).hit()->clone());
00148         }
00149 
00150         TSOS firstState;
00151         unsigned int firstId;
00152 
00153         firstState=theTraj.lastMeasurement().updatedState();
00154         firstId = theTraj.lastMeasurement().recHit()->geographicalId().rawId();
00155 
00156         /*
00157         cout << "firstState y, z: " << firstState.globalPosition().y() 
00158              << " , " << firstState.globalPosition().z() <<  endl;
00159 
00160         */
00161 
00162         AlgebraicSymMatrix55 C = AlgebraicMatrixID();
00163         TSOS startingState( firstState.localParameters(), LocalTrajectoryError(C),
00164                             firstState.surface(),
00165                             firstState.magneticField() );
00166 
00167         // protection againt invalid initial states
00168         if (! firstState.isValid()) {
00169           edm::LogWarning("CosmicTrackFinder") << "invalid innerState, will not make TrackCandidate";
00170           edm::OrphanHandle<TrackCandidateCollection> rTrackCand = e.put(output);  
00171           return;
00172         }
00173 
00174         if(firstId != recHits.front().geographicalId().rawId()){
00175           edm::LogWarning("CosmicTrackFinder") <<"Mismatch in DetID of first hit: firstID= " <<firstId
00176                                                << "   DetId= " << recHits.front().geographicalId().rawId();
00177           edm::OrphanHandle<TrackCandidateCollection> rTrackCand = e.put(output);  
00178           return;
00179         }
00180 
00181         PTrajectoryStateOnDet* state = TrajectoryStateTransform().persistentState( startingState, firstId);
00182         
00183         
00184         output->push_back(TrackCandidate(recHits,theTraj.seed(),*state,theTraj.seedRef() ) );
00185         
00186         delete state;
00187       }
00188 
00189     }
00190     edm::OrphanHandle<TrackCandidateCollection> rTrackCand = e.put(output);  
00191   }
00192 }