CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/RecoEgamma/EgammaPhotonProducers/src/ConversionTrackProducer.cc

Go to the documentation of this file.
00001 //
00002 // Package:         RecoTracker/FinalTrackSelectors
00003 // Class:           ConversionTrackProducer
00004 // 
00005 // Description:     Trivial producer of ConversionTrack collection from an edm::View of a track collection
00006 //                  (ConversionTrack is a simple wrappper class containing a TrackBaseRef and some additional flags)
00007 //
00008 // Original Author: J.Bendavid
00009 //
00010 // $Author: giordano $
00011 // $Date: 2011/08/05 19:45:49 $
00012 // $Revision: 1.4 $
00013 //
00014 
00015 #include <memory>
00016 #include <string>
00017 #include <iostream>
00018 #include <cmath>
00019 #include <vector>
00020 
00021 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00022 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00023 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
00024 #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
00025 #include "TrackingTools/GsfTracking/interface/TrajGsfTrackAssociation.h"
00026 #include "RecoEgamma/EgammaPhotonProducers/interface/ConversionTrackProducer.h"
00027 #include "DataFormats/Common/interface/Handle.h"
00028 
00029 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00030 
00031 #include "FWCore/Framework/interface/ESHandle.h"
00032 
00033 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00034 
00035 #include "MagneticField/Engine/interface/MagneticField.h"
00036 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00037 
00038     
00039 ConversionTrackProducer::ConversionTrackProducer(edm::ParameterSet const& conf) : 
00040   conf_(conf),
00041   trackProducer ( conf.getParameter<std::string>("TrackProducer") ),
00042   useTrajectory ( conf.getParameter<bool>("useTrajectory") ),
00043   setTrackerOnly ( conf.getParameter<bool>("setTrackerOnly") ),
00044   setArbitratedEcalSeeded ( conf.getParameter<bool>("setArbitratedEcalSeeded") ),    
00045   setArbitratedMerged ( conf.getParameter<bool>("setArbitratedMerged") ),
00046   setArbitratedMergedEcalGeneral ( conf.getParameter<bool>("setArbitratedMergedEcalGeneral") ),
00047   beamSpotInputTag (  conf.getParameter<edm::InputTag>("beamSpotInputTag") ),
00048   filterOnConvTrackHyp( conf.getParameter<bool>("filterOnConvTrackHyp") ),
00049   minConvRadius( conf.getParameter<double>("minConvRadius") )
00050 {
00051 
00052   produces<reco::ConversionTrackCollection>();
00053   
00054 }
00055 
00056 
00057   // Virtual destructor needed.
00058   ConversionTrackProducer::~ConversionTrackProducer() { }  
00059 
00060   // Functions that gets called by framework every event
00061   void ConversionTrackProducer::produce(edm::Event& e, const edm::EventSetup& es)
00062   {
00063     //get input collection (through edm::View)
00064     edm::Handle<edm::View<reco::Track> > hTrks;
00065     e.getByLabel(trackProducer, hTrks);
00066 
00067     //get association maps between trajectories and tracks and build temporary maps
00068     edm::Handle< TrajTrackAssociationCollection > hTTAss;
00069     edm::Handle< edm::AssociationMap<edm::OneToOne<std::vector<Trajectory>,
00070                                           reco::GsfTrackCollection,unsigned short> > > hTTAssGsf;    
00071                                           
00072     std::map<reco::TrackRef,edm::Ref<std::vector<Trajectory> > > tracktrajmap;
00073     std::map<reco::GsfTrackRef,edm::Ref<std::vector<Trajectory> > > gsftracktrajmap;
00074                                           
00075     if (useTrajectory) {
00076       if (hTrks->size()>0) {
00077         if (dynamic_cast<const reco::GsfTrack*>(&hTrks->at(0))) {
00078           //fill map for gsf tracks
00079           e.getByLabel(trackProducer, hTTAssGsf);     
00080           for ( edm::AssociationMap<edm::OneToOne<std::vector<Trajectory>,
00081                     reco::GsfTrackCollection,unsigned short> >::const_iterator iPair = hTTAssGsf->begin();
00082             iPair != hTTAssGsf->end(); ++iPair) {
00083         
00084             gsftracktrajmap[iPair->val] = iPair->key;
00085 
00086           }
00087                 
00088         }
00089         else {
00090           //fill map for standard tracks
00091           e.getByLabel(trackProducer, hTTAss);
00092           for ( TrajTrackAssociationCollection::const_iterator iPair = hTTAss->begin();
00093             iPair != hTTAss->end();
00094             ++iPair) {
00095         
00096             tracktrajmap[iPair->val] = iPair->key;
00097 
00098           }
00099         }
00100       }
00101     }
00102 
00103     // Step B: create empty output collection
00104     outputTrks = std::auto_ptr<reco::ConversionTrackCollection>(new reco::ConversionTrackCollection);    
00105 
00106     //--------------------------------------------------
00107     //Added by D. Giordano
00108     // 2011/08/05
00109     // Reduction of the track sample based on geometric hypothesis for conversion tracks
00110  
00111     edm::Handle<reco::BeamSpot> beamSpotHandle;
00112     e.getByLabel(beamSpotInputTag,beamSpotHandle);
00113    
00114     edm::ESHandle<MagneticField> magFieldHandle;
00115     es.get<IdealMagneticFieldRecord>().get( magFieldHandle );
00116 
00117 
00118     if(filterOnConvTrackHyp && !beamSpotHandle.isValid()) {
00119       edm::LogError("Invalid Collection") << "invalid collection for the BeamSpot with InputTag " << beamSpotInputTag;
00120       throw;
00121     }
00122 
00123     ConvTrackPreSelector.setMagnField(magFieldHandle.product());
00124 
00125     //----------------------------------------------------------
00126    
00127  
00128     // Simple conversion of tracks to conversion tracks, setting appropriate flags from configuration
00129     for (edm::RefToBaseVector<reco::Track>::const_iterator it = hTrks->refVector().begin(); it != hTrks->refVector().end(); ++it) {
00130  
00131       //--------------------------------------------------
00132       //Added by D. Giordano
00133       // 2011/08/05
00134       // Reduction of the track sample based on geometric hypothesis for conversion tracks
00135       
00136       math::XYZVector beamSpot=  math::XYZVector(beamSpotHandle->position());
00137 
00138       if( filterOnConvTrackHyp && ConvTrackPreSelector.isTangentPointDistanceLessThan( minConvRadius, it->get(), beamSpot )  )
00139         continue;
00140       //--------------------------------------------------
00141 
00142       reco::ConversionTrack convTrack(*it);
00143       convTrack.setIsTrackerOnly(setTrackerOnly);
00144       convTrack.setIsArbitratedEcalSeeded(setArbitratedEcalSeeded);
00145       convTrack.setIsArbitratedMerged(setArbitratedMerged);
00146       convTrack.setIsArbitratedMergedEcalGeneral(setArbitratedMergedEcalGeneral);
00147             
00148       //fill trajectory association if configured, using correct map depending on track type
00149       if (useTrajectory) {
00150         if (gsftracktrajmap.size()) {
00151           convTrack.setTrajRef(gsftracktrajmap.find(it->castTo<reco::GsfTrackRef>())->second);
00152         }
00153         else {
00154           convTrack.setTrajRef(tracktrajmap.find(it->castTo<reco::TrackRef>())->second);
00155         }
00156       }
00157       
00158       outputTrks->push_back(convTrack);
00159     }
00160     
00161     e.put(outputTrks);
00162     return;
00163 
00164   }//end produce
00165