CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/AnalysisAlgos/TrackInfoProducer/src/TrackInfoProducer.cc

Go to the documentation of this file.
00001 #include "AnalysisAlgos/TrackInfoProducer/interface/TrackInfoProducer.h"
00002 // system include files
00003 #include <memory>
00004 // user include files
00005 #include "DataFormats/Common/interface/Handle.h"
00006 #include "FWCore/Framework/interface/ESHandle.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00009 #include "AnalysisDataFormats/TrackInfo/interface/TrackInfo.h"
00010 #include "AnalysisDataFormats/TrackInfo/interface/TrackInfoTrackAssociation.h"
00011 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00012 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00013 TrackInfoProducer::TrackInfoProducer(const edm::ParameterSet& iConfig):
00014     conf_(iConfig),
00015     theAlgo_(iConfig)
00016 {
00017   produces<reco::TrackInfoCollection>();
00018   produces<reco::TrackInfoTrackAssociationCollection>();
00019 
00020 
00021 }
00022 
00023 
00024 void TrackInfoProducer::produce(edm::Event& theEvent, const edm::EventSetup& setup)
00025 {
00026    //
00027   // create empty output collections
00028   //
00029 
00030   std::auto_ptr<reco::TrackInfoCollection>    outputColl (new reco::TrackInfoCollection);
00031   std::auto_ptr<reco::TrackInfoTrackAssociationCollection>    TIassociationColl (new reco::TrackInfoTrackAssociationCollection);
00032   
00033   edm::InputTag TkTag = conf_.getParameter<edm::InputTag>("cosmicTracks");
00034   
00035   edm::Handle<std::vector<Trajectory> > TrajectoryCollection;
00036   edm::Handle<reco::TrackCollection > trackCollection;
00037   edm::Handle<TrajTrackAssociationCollection> assoMap;
00038     
00039   edm::ESHandle<TrackerGeometry> tkgeom;
00040   setup.get<TrackerDigiGeometryRecord>().get( tkgeom );
00041   const TrackerGeometry * tracker=&(* tkgeom);
00042     
00043   theEvent.getByLabel(TkTag,TrajectoryCollection);
00044   theEvent.getByLabel(TkTag,trackCollection);
00045   theEvent.getByLabel(TkTag,assoMap);
00046  
00047   //
00048   //run the algorithm  
00049   //
00050   reco::TrackInfo output;
00051   
00052   std::vector<Trajectory>::const_iterator traj_iterator;
00053   edm::LogInfo("TrackInfoProducer") << "Loop on trajectories";
00054   std::map<reco::TrackRef,unsigned int> trackid;
00055   int i=0;
00056 
00057  for(TrajTrackAssociationCollection::const_iterator it = assoMap->begin();it != assoMap->end(); ++it){
00058    const edm::Ref<std::vector<Trajectory> > traj = it->key;
00059    const reco::TrackRef track = it->val;
00060    trackid.insert(make_pair(track,i));
00061    i++;
00062    theAlgo_.run(traj,track,output,tracker);
00063    outputColl->push_back(*(new reco::TrackInfo(output)));
00064 
00065  }
00066  
00067 
00068     //put everything in the event
00069     edm::OrphanHandle<reco::TrackInfoCollection> rTrackInfo;
00070 
00071 //     if(forwardPredictedStateTag_!="") rTrackInfof = theEvent.put(outputFwdColl,forwardPredictedStateTag_ );
00072 //     if(backwardPredictedStateTag_!="") rTrackInfob =   theEvent.put(outputBwdColl,backwardPredictedStateTag_);
00073 //     if(updatedStateTag_!="") rTrackInfou =   theEvent.put(outputUpdatedColl,updatedStateTag_ );
00074 //     if(combinedStateTag_!="") rTrackInfoc =   theEvent.put(outputCombinedColl,combinedStateTag_ );
00075     rTrackInfo=theEvent.put(outputColl);
00076 
00077     for(std::map<reco::TrackRef,unsigned int>::iterator ref_iter=trackid.begin();ref_iter!=trackid.end();ref_iter++){
00078 
00079       TIassociationColl->insert( ref_iter->first,edm::Ref<reco::TrackInfoCollection>(rTrackInfo,ref_iter->second ));
00080     }
00081 
00082     theEvent.put(TIassociationColl); 
00083 }
00084 
00085 
00086 
00087