CMS 3D CMS Logo

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