CMS 3D CMS Logo

TrackCandidateProducer.cc

Go to the documentation of this file.
00001 #include <memory>
00002 
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/EventSetup.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 #include "FWCore/Framework/interface/ESHandle.h"
00007 
00008 #include "DataFormats/Common/interface/Handle.h"
00009 #include "DataFormats/Common/interface/OwnVector.h"
00010 #include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
00011 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
00012 #include "DataFormats/TrackerRecHit2D/interface/SiTrackerGSRecHit2DCollection.h" 
00013 #include "DataFormats/TrackerRecHit2D/interface/SiTrackerGSMatchedRecHit2DCollection.h" 
00014 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00015 #include "DataFormats/TrackReco/interface/Track.h"
00016 #include "DataFormats/TrackReco/interface/TrackExtraFwd.h"
00017 
00018 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00019 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00020 
00021 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00022 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00023 
00024 #include "FastSimulation/Tracking/interface/TrackerRecHit.h"
00025 //#include "FastSimulation/Tracking/interface/TrackerRecHitSplit.h"
00026 
00027 #include "FastSimulation/Tracking/plugins/TrackCandidateProducer.h"
00028 
00029 #include <vector>
00030 #include <map>
00031 //
00032 
00033 //for debug only 
00034 //#define FAMOS_DEBUG
00035 
00036 TrackCandidateProducer::TrackCandidateProducer(const edm::ParameterSet& conf) 
00037 {  
00038 #ifdef FAMOS_DEBUG
00039   std::cout << "TrackCandidateProducer created" << std::endl;
00040 #endif
00041 
00042   // The main product is a track candidate collection.
00043   produces<TrackCandidateCollection>();
00044 
00045   // These products contain tracks already reconstructed at this level
00046   // (No need to reconstruct them twice!)
00047   produces<reco::TrackCollection>();
00048   produces<TrackingRecHitCollection>();
00049   produces<reco::TrackExtraCollection>();
00050   produces<std::vector<Trajectory> >();
00051   produces<TrajTrackAssociationCollection>();
00052   
00053   // The name of the seed producer
00054   seedProducer = conf.getParameter<edm::InputTag>("SeedProducer");
00055 
00056   // The name of the recHit producer
00057   hitProducer = conf.getParameter<edm::InputTag>("HitProducer");
00058 
00059   // The name of the track producer (tracks already produced need not be produced again!)
00060   // trackProducer = conf.getParameter<edm::InputTag>("TrackProducer");
00061   trackProducers = conf.getParameter<std::vector<edm::InputTag> >("TrackProducers");
00062 
00063   // Copy (or not) the tracks already produced in a new collection
00064   keepFittedTracks = conf.getParameter<bool>("KeepFittedTracks");
00065 
00066   // The minimum number of crossed layers
00067   minNumberOfCrossedLayers = conf.getParameter<unsigned int>("MinNumberOfCrossedLayers");
00068 
00069   // The maximum number of crossed layers
00070   maxNumberOfCrossedLayers = conf.getParameter<unsigned int>("MaxNumberOfCrossedLayers");
00071 
00072   // Reject overlapping hits?
00073   rejectOverlaps = conf.getParameter<bool>("OverlapCleaning");
00074 
00075   // Split hits ?
00076   splitHits = conf.getParameter<bool>("SplitHits");
00077 
00078   // Reject tracks with several seeds ?
00079   // Typically don't do that at HLT for electrons, but do it otherwise
00080   seedCleaning = conf.getParameter<bool>("SeedCleaning");
00081 
00082 }
00083 
00084   
00085 // Virtual destructor needed.
00086 TrackCandidateProducer::~TrackCandidateProducer() {
00087 
00088   // do nothing
00089 #ifdef FAMOS_DEBUG
00090   std::cout << "TrackCandidateProducer destructed" << std::endl;
00091 #endif
00092 
00093 } 
00094  
00095 void 
00096 TrackCandidateProducer::beginRun(edm::Run & run, const edm::EventSetup & es) {
00097 
00098   //services
00099   //  es.get<TrackerRecoGeometryRecord>().get(theGeomSearchTracker);
00100 
00101   edm::ESHandle<TrackerGeometry>        geometry;
00102 
00103 
00104   es.get<TrackerDigiGeometryRecord>().get(geometry);
00105 
00106   theGeometry = &(*geometry);
00107 
00108 }
00109   
00110   // Functions that gets called by framework every event
00111 void 
00112 TrackCandidateProducer::produce(edm::Event& e, const edm::EventSetup& es) {        
00113 
00114 #ifdef FAMOS_DEBUG
00115   std::cout << "################################################################" << std::endl;
00116   std::cout << " TrackCandidateProducer produce init " << std::endl;
00117 #endif
00118 
00119   // Useful typedef's to avoid retyping
00120   typedef std::pair<reco::TrackRef,edm::Ref<std::vector<Trajectory> > > TrackPair;
00121   typedef std::map<unsigned,TrackPair> TrackMap;
00122 
00123   // The produced objects
00124   std::auto_ptr<TrackCandidateCollection> output(new TrackCandidateCollection);    
00125   std::auto_ptr<reco::TrackCollection> recoTracks(new reco::TrackCollection);    
00126   std::auto_ptr<TrackingRecHitCollection> recoHits(new TrackingRecHitCollection);
00127   std::auto_ptr<reco::TrackExtraCollection> recoTrackExtras(new reco::TrackExtraCollection);
00128   std::auto_ptr<std::vector<Trajectory> > recoTrajectories(new std::vector<Trajectory> );
00129   std::auto_ptr<TrajTrackAssociationCollection> recoTrajTrackMap( new TrajTrackAssociationCollection() );
00130   
00131   // Get the seeds
00132   // edm::Handle<TrajectorySeedCollection> theSeeds;
00133   edm::Handle<edm::View<TrajectorySeed> > theSeeds;
00134   e.getByLabel(seedProducer,theSeeds);
00135 
00136   // No seed -> output an empty track collection
00137   if(theSeeds->size() == 0) {
00138     e.put(output);
00139     e.put(recoTracks);
00140     e.put(recoHits);
00141     e.put(recoTrackExtras);
00142     e.put(recoTrajectories);
00143     e.put(recoTrajTrackMap);
00144     return;
00145   }
00146 
00147   // Get the GS RecHits
00148   //  edm::Handle<SiTrackerGSRecHit2DCollection> theGSRecHits;
00149   edm::Handle<SiTrackerGSMatchedRecHit2DCollection> theGSRecHits;
00150   e.getByLabel(hitProducer, theGSRecHits);
00151 
00152   // The input track collection + extra's
00153   /*
00154   edm::Handle<reco::TrackCollection> theTrackCollection;
00155   edm:: Handle<std::vector<Trajectory> > theTrajectoryCollection;
00156   edm::Handle<TrajTrackAssociationCollection> theAssoMap;  
00157   bool isTrackCollection = e.getByLabel(trackProducer,theTrackCollection);
00158   */
00159   std::vector<edm::Handle<reco::TrackCollection> > theTrackCollections;
00160   std::vector<edm:: Handle<std::vector<Trajectory> > > theTrajectoryCollections;
00161   std::vector<edm::Handle<TrajTrackAssociationCollection> > theAssoMaps;
00162   std::vector<bool> isTrackCollections;
00163   TrajTrackAssociationCollection::const_iterator anAssociation;  
00164   TrajTrackAssociationCollection::const_iterator lastAssociation;
00165   TrackMap theTrackMap;
00166   unsigned nCollections = trackProducers.size();
00167   unsigned nRecoHits = 0;
00168 
00169   if ( nCollections ) { 
00170     theTrackCollections.resize(nCollections);
00171     theTrajectoryCollections.resize(nCollections);
00172     theAssoMaps.resize(nCollections);
00173     isTrackCollections.resize(nCollections);
00174     for ( unsigned tprod=0; tprod < nCollections; ++tprod ) { 
00175       isTrackCollections[tprod] = e.getByLabel(trackProducers[tprod],theTrackCollections[tprod]); 
00176 
00177       if ( isTrackCollections[tprod] ) { 
00178         // The track collection
00179         reco::TrackCollection::const_iterator aTrack = theTrackCollections[tprod]->begin();
00180         reco::TrackCollection::const_iterator lastTrack = theTrackCollections[tprod]->end();
00181         // The numbers of hits
00182         for ( ; aTrack!=lastTrack; ++aTrack ) nRecoHits+= aTrack->recHitsSize();
00183         e.getByLabel(trackProducers[tprod],theTrajectoryCollections[tprod]);
00184         e.getByLabel(trackProducers[tprod],theAssoMaps[tprod]);
00185         // The association between trajectories and tracks
00186         anAssociation = theAssoMaps[tprod]->begin();
00187         lastAssociation = theAssoMaps[tprod]->end(); 
00188 #ifdef FAMOS_DEBUG
00189         std::cout << "Input Track Producer " << tprod << " : " << trackProducers[tprod] << std::endl;
00190         std::cout << "List of tracks already reconstructed " << std::endl;
00191 #endif
00192         // Build the map of correspondance between reco tracks and sim tracks
00193         for ( ; anAssociation != lastAssociation; ++anAssociation ) { 
00194           edm::Ref<std::vector<Trajectory> > aTrajectoryRef = anAssociation->key;
00195           reco::TrackRef aTrackRef = anAssociation->val;
00196           // Find the simtrack id of the reconstructed track
00197           int recoTrackId = findId(*aTrackRef);
00198           if ( recoTrackId < 0 ) continue;
00199 #ifdef FAMOS_DEBUG
00200           std::cout << recoTrackId << " ";
00201 #endif
00202           // And store it.
00203           theTrackMap[recoTrackId] = TrackPair(aTrackRef,aTrajectoryRef);
00204         }
00205 #ifdef FAMOS_DEBUG
00206         std::cout << std::endl;
00207 #endif
00208       }
00209     }
00210     // This is to save some time at push_back.
00211     recoHits->reserve(nRecoHits); 
00212   }
00213 
00214   // Loop over the seeds
00215   int currentTrackId = -1;
00216   /*
00217   TrajectorySeedCollection::const_iterator aSeed = theSeeds->begin();
00218   TrajectorySeedCollection::const_iterator lastSeed = theSeeds->end();
00219   for ( ; aSeed!=lastSeed; ++aSeed ) { 
00220     // The first hit of the seed  and its simtrack id
00221   */
00222   /* */
00223 #ifdef FAMOS_DEBUG
00224   std::cout << "Input seed Producer : " << seedProducer << std::endl;
00225   std::cout << "Number of seeds : " << theSeeds->size() << std::endl;
00226 #endif
00227   unsigned seed_size = theSeeds->size(); 
00228   for (unsigned seednr = 0; seednr < seed_size; ++seednr){
00229 
00230     // The seed
00231     const BasicTrajectorySeed* aSeed = &((*theSeeds)[seednr]);
00232   /* */
00233     // Find the first hit of the Seed
00234     TrajectorySeed::range theSeedingRecHitRange = aSeed->recHits();
00235     //    const SiTrackerGSRecHit2D * theFirstSeedingRecHit = 
00236     //      (const SiTrackerGSRecHit2D*) (&(*(theSeedingRecHitRange.first)));
00237     const SiTrackerGSMatchedRecHit2D * theFirstSeedingRecHit = 
00238       (const SiTrackerGSMatchedRecHit2D*) (&(*(theSeedingRecHitRange.first)));
00239 
00240     TrackerRecHit theFirstSeedingTrackerRecHit(theFirstSeedingRecHit,theGeometry);
00241     // SiTrackerGSRecHit2DCollection::const_iterator theSeedingRecHitEnd = theSeedingRecHitRange.second;
00242 
00243     // The SimTrack id associated to that recHit
00244     int simTrackId = theFirstSeedingRecHit->simtrackId();
00245     // std::cout << "The Sim Track Id : " << simTrackId << std::endl;
00246     // std::cout << "The Current Track Id : " << currentTrackId << std::endl;
00247     // const SimTrack& theSimTrack = (*theSimTracks)[simTrackId]; 
00248 
00249     // Don't consider seeds belonging to a track already considered 
00250     // (Equivalent to seed cleaning)
00251     if ( seedCleaning && currentTrackId == simTrackId ) continue;
00252     currentTrackId = simTrackId;
00253     
00254     // A vector of TrackerRecHits belonging to the track and the number of crossed layers
00255     std::vector<TrackerRecHit> theTrackerRecHits;
00256     // std::vector<TrackerRecHit> theTrackerRecHitsSplit;
00257     unsigned theNumberOfCrossedLayers = 0;
00258  
00259     // The track has indeed been reconstructed already -> Save the pertaining info
00260     TrackMap::const_iterator theTrackIt = theTrackMap.find(simTrackId);
00261     //    if ( isTrackCollection && theTrackIt != theTrackMap.end() ) { 
00262     if ( nCollections && theTrackIt != theTrackMap.end() ) { 
00263 
00264       if ( keepFittedTracks ) { 
00265 
00266 #ifdef FAMOS_DEBUG
00267         std::cout << "Track " << simTrackId << " already reconstructed -> copy it" << std::endl;
00268 #endif      
00269         // The track and trajectroy references
00270         reco::TrackRef aTrackRef = theTrackIt->second.first;
00271         edm::Ref<std::vector<Trajectory> > aTrajectoryRef = theTrackIt->second.second;
00272         
00273         // A copy of the track
00274         reco::Track aRecoTrack(*aTrackRef);
00275         recoTracks->push_back(aRecoTrack);      
00276         
00277         // A copy of the hits
00278         unsigned nh = aRecoTrack.recHitsSize();
00279         for ( unsigned ih=0; ih<nh; ++ih ) {
00280           TrackingRecHit *hit = aRecoTrack.recHit(ih)->clone();
00281           recoHits->push_back(hit);
00282         }
00283         
00284         // A copy of the trajectories
00285         recoTrajectories->push_back(*aTrajectoryRef);
00286         
00287       } else { 
00288 
00289 #ifdef FAMOS_DEBUG
00290         std::cout << "Track " << simTrackId << " already reconstructed -> ignore it" << std::endl;
00291 #endif      
00292 
00293       }
00294 
00295       // The track was not saved -> create a track candidate.
00296 
00297     } else { 
00298       
00299 #ifdef FAMOS_DEBUG
00300       std::cout << "Track " << simTrackId << " will return a track candidate" << std::endl;
00301 #endif
00302       // Get all the rechits associated to this track
00303       SiTrackerGSMatchedRecHit2DCollection::range theRecHitRange = theGSRecHits->get(simTrackId);
00304       SiTrackerGSMatchedRecHit2DCollection::const_iterator theRecHitRangeIteratorBegin = theRecHitRange.first;
00305       SiTrackerGSMatchedRecHit2DCollection::const_iterator theRecHitRangeIteratorEnd   = theRecHitRange.second;
00306       SiTrackerGSMatchedRecHit2DCollection::const_iterator iterRecHit;
00307       
00308       bool firstRecHit = true;
00309       // 
00310       TrackerRecHit theCurrentRecHit, thePreviousRecHit;
00311 
00312       TrackerRecHit theFirstHitComp, theSecondHitComp;
00313 
00314       for ( iterRecHit = theRecHitRangeIteratorBegin; 
00315             iterRecHit != theRecHitRangeIteratorEnd; 
00316             ++iterRecHit) {
00317         
00318         // Check the number of crossed layers
00319         if ( theNumberOfCrossedLayers >= maxNumberOfCrossedLayers ) continue;
00320         
00321         // Get current and previous rechits
00322         thePreviousRecHit = theCurrentRecHit;
00323         theCurrentRecHit = TrackerRecHit(&(*iterRecHit),theGeometry);
00324         
00325         // Check that the first rechit is indeed the first seeding hit
00326         if ( firstRecHit && theCurrentRecHit != theFirstSeedingTrackerRecHit ) continue;
00327         
00328         // Count the number of crossed layers
00329         if ( !theCurrentRecHit.isOnTheSameLayer(thePreviousRecHit) ) 
00330           ++theNumberOfCrossedLayers;
00331         
00332         // Add all rechits (Grouped Trajectory Builder) from this hit onwards
00333         // Always add the first seeding rechit anyway
00334         if ( !rejectOverlaps || firstRecHit ) {  
00335           
00336           // Split matched hits (if requested / possible )
00337           if ( splitHits && theCurrentRecHit.matchedHit()->isMatched() ) {
00338             
00339             addSplitHits(theCurrentRecHit,theTrackerRecHits);
00340             
00341           // No splitting   
00342           } else {
00343             
00344             theTrackerRecHits.push_back(theCurrentRecHit);
00345 
00346           }
00347 
00348           firstRecHit = false;
00349           
00350         // And now treat the following RecHits if hits in the same layer 
00351         // have to be rejected - The split option is not 
00352         } else { 
00353           
00354           // Not the same layer : Add the current hit
00355           if ( theCurrentRecHit.subDetId()    != thePreviousRecHit.subDetId() || 
00356                theCurrentRecHit.layerNumber() != thePreviousRecHit.layerNumber() ) {
00357             
00358             // Split matched hits (if requested / possible )
00359             if ( splitHits && theCurrentRecHit.matchedHit()->isMatched() ) {
00360               
00361               addSplitHits(theCurrentRecHit,theTrackerRecHits);
00362 
00363             // No splitting           
00364             } else {
00365 
00366               theTrackerRecHits.push_back(theCurrentRecHit);
00367             
00368             }
00369             
00370             // Same layer : keep the current hit if better, and drop the other - otherwise do nothing  
00371           } else if ( theCurrentRecHit.localError() < thePreviousRecHit.localError() ) { 
00372             
00373             // Split matched hits (if requested / possible )
00374             if( splitHits && theCurrentRecHit.matchedHit()->isMatched() ){
00375 
00376               // Remove the previous hit(s)
00377               theTrackerRecHits.pop_back();
00378               if ( thePreviousRecHit.matchedHit()->isMatched() ) theTrackerRecHits.pop_back();
00379 
00380               // Replace by the new hits
00381               addSplitHits(theCurrentRecHit,theTrackerRecHits);
00382 
00383             // No splitting   
00384             } else {
00385 
00386               // Replace the previous hit by the current hit
00387               theTrackerRecHits.back() = theCurrentRecHit;
00388 
00389             }
00390 
00391           } else { 
00392             
00393           }
00394 
00395         }
00396         
00397       }
00398       // End of loop over the track rechits
00399     }
00400     
00401 #ifdef FAMOS_DEBUG
00402      std::cout << "Hit number " << theTrackerRecHits.size() << std::endl;
00403 #endif
00404 
00405     //replace TrackerRecHit con TrackerRecHitsSplit
00406     // 1) Create the OwnWector of TrackingRecHits
00407     edm::OwnVector<TrackingRecHit> recHits;
00408     unsigned nTrackerHits = theTrackerRecHits.size();
00409     recHits.reserve(nTrackerHits); // To save some time at push_back
00410 
00411     for ( unsigned ih=0; ih<nTrackerHits; ++ih ) {
00412       TrackingRecHit* aTrackingRecHit = theTrackerRecHits[ih].hit()->clone();
00413       recHits.push_back(aTrackingRecHit);
00414 
00415 #ifdef FAMOS_DEBUG
00416       const DetId& detId = theTrackerRecHits[ih].hit()->geographicalId();      
00417       std::cout << "Added RecHit from detid " << detId.rawId() 
00418                 << " subdet = " << theTrackerRecHits[ih].subDetId() 
00419                 << " layer = " << theTrackerRecHits[ih].layerNumber()
00420                 << " ring = " << theTrackerRecHits[ih].ringNumber()
00421                 << " error = " << theTrackerRecHits[ih].localError()
00422                 << std::endl;
00423       
00424       std::cout << "Track/z/r : "
00425                 << simTrackId << " " 
00426                 << theTrackerRecHits[ih].globalPosition().z() << " " 
00427                 << theTrackerRecHits[ih].globalPosition().perp() << std::endl;
00428       if ( theTrackerRecHits[ih].matchedHit() && theTrackerRecHits[ih].matchedHit()->isMatched() ) 
00429         std::cout << "Matched : " << theTrackerRecHits[ih].matchedHit()->isMatched() 
00430                   << "Rphi Hit = " <<  theTrackerRecHits[ih].matchedHit()->monoHit()->simhitId()                 
00431                   << "Stereo Hit = " <<  theTrackerRecHits[ih].matchedHit()->stereoHit()->simhitId()
00432                   <<std::endl;
00433 
00434 #endif
00435     }
00436 
00437     // Check the number of crossed layers
00438     if ( theNumberOfCrossedLayers < minNumberOfCrossedLayers ) continue;
00439 
00440 
00441     // Create a track Candidate (now with the reference to the seed!) .
00442     TrackCandidate  
00443       newTrackCandidate(recHits, 
00444                         *aSeed, 
00445                         aSeed->startingState(), 
00446                         edm::RefToBase<TrajectorySeed>(theSeeds,seednr));
00447 
00448     //std::cout << "Track kept for later fit!" << std::endl;
00449     
00450 #ifdef FAMOS_DEBUG
00451     // Log
00452     std::cout << "\tSeed Information " << std::endl;
00453     std::cout << "\tSeed Direction = " << aSeed->direction() << std::endl;
00454     std::cout << "\tSeed StartingDet = " << aSeed->startingState().detId() << std::endl;
00455     
00456     std::cout << "\tTrajectory Parameters " 
00457               << std::endl;
00458     std::cout << "\t\t detId  = " 
00459               << newTrackCandidate.trajectoryStateOnDet().detId() 
00460               << std::endl;
00461     std::cout << "\t\t loc.px = " 
00462               << newTrackCandidate.trajectoryStateOnDet().parameters().momentum().x()    
00463               << std::endl;
00464     std::cout << "\t\t loc.py = " 
00465               << newTrackCandidate.trajectoryStateOnDet().parameters().momentum().y()    
00466               << std::endl;
00467     std::cout << "\t\t loc.pz = " 
00468               << newTrackCandidate.trajectoryStateOnDet().parameters().momentum().z()    
00469               << std::endl;
00470     std::cout << "\t\t error  = ";
00471     for(std::vector< float >::const_iterator iElement = newTrackCandidate.trajectoryStateOnDet().errorMatrix().begin();
00472         iElement < newTrackCandidate.trajectoryStateOnDet().errorMatrix().end();
00473         ++iElement) {
00474       std::cout << "\t" << *iElement;
00475     }
00476     std::cout << std::endl;
00477 #endif
00478 
00479     output->push_back(newTrackCandidate);
00480 
00481   }
00482   
00483   // Save the track candidates in the event
00484 #ifdef FAMOS_DEBUG
00485   std::cout << "Saving " 
00486             << output->size() << " track candidates and " 
00487             << recoTracks->size() << " reco::Tracks " << std::endl;
00488 #endif
00489   // Save the track candidates
00490   e.put(output);
00491 
00492 
00493 
00494   // Save the tracking recHits
00495 
00496   edm::OrphanHandle <TrackingRecHitCollection> theRecoHits = e.put(recoHits );
00497 
00498   // Create the track extras and add the references to the rechits
00499   unsigned hits=0;
00500   unsigned nTracks = recoTracks->size();
00501   recoTrackExtras->reserve(nTracks); // To save some time at push_back
00502   for ( unsigned index = 0; index < nTracks; ++index ) { 
00503     //reco::TrackExtra aTrackExtra;
00504     reco::Track& aTrack = recoTracks->at(index);
00505     reco::TrackExtra aTrackExtra(aTrack.outerPosition(),
00506                                  aTrack.outerMomentum(),
00507                                  aTrack.outerOk(),
00508                                  aTrack.innerPosition(),
00509                                  aTrack.innerMomentum(),
00510                                  aTrack.innerOk(),
00511                                  aTrack.outerStateCovariance(),
00512                                  aTrack.outerDetId(),
00513                                  aTrack.innerStateCovariance(),
00514                                  aTrack.innerDetId(),
00515                                  aTrack.seedDirection(),
00516                                  aTrack.seedRef());
00517 
00518     unsigned nHits = aTrack.recHitsSize();
00519     for ( unsigned int ih=0; ih<nHits; ++ih) {
00520       aTrackExtra.add(TrackingRecHitRef(theRecoHits,hits++));
00521     }
00522     recoTrackExtras->push_back(aTrackExtra);
00523   }
00524   
00525 
00526   // Save the track extras
00527   edm::OrphanHandle<reco::TrackExtraCollection> theRecoTrackExtras = e.put(recoTrackExtras);
00528 
00529   // Add the reference to the track extra in the tracks
00530   for ( unsigned index = 0; index<nTracks; ++index ) { 
00531     const reco::TrackExtraRef theTrackExtraRef(theRecoTrackExtras,index);
00532     (recoTracks->at(index)).setExtra(theTrackExtraRef);
00533   }
00534 
00535   // Save the tracks
00536   edm::OrphanHandle<reco::TrackCollection> theRecoTracks = e.put(recoTracks);
00537 
00538   // Save the trajectories
00539   edm::OrphanHandle<std::vector<Trajectory> > theRecoTrajectories = e.put(recoTrajectories);
00540   
00541   // Create and set the trajectory/track association map 
00542   for ( unsigned index = 0; index<nTracks; ++index ) { 
00543     edm::Ref<std::vector<Trajectory> > trajRef( theRecoTrajectories, index );
00544     edm::Ref<reco::TrackCollection>    tkRef( theRecoTracks, index );
00545     recoTrajTrackMap->insert(trajRef,tkRef);
00546   }
00547 
00548   // Save the association map.
00549   e.put(recoTrajTrackMap);
00550 
00551 }
00552 
00553 int 
00554 TrackCandidateProducer::findId(const reco::Track& aTrack) const {
00555   int trackId = -1;
00556   trackingRecHit_iterator aHit = aTrack.recHitsBegin();
00557   trackingRecHit_iterator lastHit = aTrack.recHitsEnd();
00558   for ( ; aHit!=lastHit; ++aHit ) {
00559     if ( !aHit->get()->isValid() ) continue;
00560     //    const SiTrackerGSRecHit2D * rechit = (const SiTrackerGSRecHit2D*) (aHit->get());
00561     const SiTrackerGSMatchedRecHit2D * rechit = (const SiTrackerGSMatchedRecHit2D*) (aHit->get());
00562     trackId = rechit->simtrackId();
00563     break;
00564   }
00565   return trackId;
00566 }
00567 
00568 void 
00569 TrackCandidateProducer::addSplitHits(const TrackerRecHit& theCurrentRecHit,
00570                                      std::vector<TrackerRecHit>& theTrackerRecHits) { 
00571   
00572   const SiTrackerGSRecHit2D* mHit = theCurrentRecHit.matchedHit()->monoHit();
00573   const SiTrackerGSRecHit2D* sHit = theCurrentRecHit.matchedHit()->stereoHit();
00574   
00575   // Add the new hits
00576   if( mHit->simhitId() < sHit->simhitId() ) {
00577     
00578     theTrackerRecHits.push_back(TrackerRecHit(mHit,theCurrentRecHit));
00579     theTrackerRecHits.push_back(TrackerRecHit(sHit,theCurrentRecHit));
00580     
00581   } else {
00582     
00583     theTrackerRecHits.push_back(TrackerRecHit(sHit,theCurrentRecHit));
00584     theTrackerRecHits.push_back(TrackerRecHit(mHit,theCurrentRecHit));
00585     
00586   }
00587 
00588 }

Generated on Tue Jun 9 17:35:15 2009 for CMSSW by  doxygen 1.5.4