CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ConversionTrackProducer.cc
Go to the documentation of this file.
1 //
2 // Package: RecoTracker/FinalTrackSelectors
3 // Class: ConversionTrackProducer
4 //
5 // Description: Trivial producer of ConversionTrack collection from an edm::View of a track collection
6 // (ConversionTrack is a simple wrappper class containing a TrackBaseRef and some additional flags)
7 //
8 // Original Author: J.Bendavid
9 //
10 // $Author: bendavid $
11 // $Date: 2010/09/27 09:27:15 $
12 // $Revision: 1.2 $
13 //
14 
15 #include <memory>
16 #include <string>
17 #include <iostream>
18 #include <cmath>
19 #include <vector>
20 
28 
29 
31 
33 
34 
36  conf_(conf)
37  {
38  produces<reco::ConversionTrackCollection>();
39 
40  }
41 
42 
43  // Virtual destructor needed.
45 
46  // Functions that gets called by framework every event
48  {
49  // retrieve producer name of input TrackCollection(s)
50  std::string trackProducer = conf_.getParameter<std::string>("TrackProducer");
51  bool useTrajectory = conf_.getParameter<bool>("useTrajectory");
52  bool setTrackerOnly = conf_.getParameter<bool>("setTrackerOnly");
53  bool setArbitratedEcalSeeded = conf_.getParameter<bool>("setArbitratedEcalSeeded");
54  bool setArbitratedMerged = conf_.getParameter<bool>("setArbitratedMerged");
55  bool setArbitratedMergedEcalGeneral = conf_.getParameter<bool>("setArbitratedMergedEcalGeneral");
56 
57  //get input collection (through edm::View)
59  e.getByLabel(trackProducer, hTrks);
60 
61  //get association maps between trajectories and tracks and build temporary maps
64  reco::GsfTrackCollection,unsigned short> > > hTTAssGsf;
65 
66  std::map<reco::TrackRef,edm::Ref<std::vector<Trajectory> > > tracktrajmap;
67  std::map<reco::GsfTrackRef,edm::Ref<std::vector<Trajectory> > > gsftracktrajmap;
68 
69  if (useTrajectory) {
70  if (hTrks->size()>0) {
71  if (dynamic_cast<const reco::GsfTrack*>(&hTrks->at(0))) {
72  //fill map for gsf tracks
73  e.getByLabel(trackProducer, hTTAssGsf);
74  for ( edm::AssociationMap<edm::OneToOne<std::vector<Trajectory>,
75  reco::GsfTrackCollection,unsigned short> >::const_iterator iPair = hTTAssGsf->begin();
76  iPair != hTTAssGsf->end(); ++iPair) {
77 
78  gsftracktrajmap[iPair->val] = iPair->key;
79 
80  }
81 
82  }
83  else {
84  //fill map for standard tracks
85  e.getByLabel(trackProducer, hTTAss);
86  for ( TrajTrackAssociationCollection::const_iterator iPair = hTTAss->begin();
87  iPair != hTTAss->end();
88  ++iPair) {
89 
90  tracktrajmap[iPair->val] = iPair->key;
91 
92  }
93  }
94  }
95  }
96 
97  // Step B: create empty output collection
98  outputTrks = std::auto_ptr<reco::ConversionTrackCollection>(new reco::ConversionTrackCollection);
99 
100  // Simple conversion of tracks to conversion tracks, setting appropriate flags from configuration
101  for (edm::RefToBaseVector<reco::Track>::const_iterator it = hTrks->refVector().begin(); it != hTrks->refVector().end(); ++it) {
102  reco::ConversionTrack convTrack(*it);
103  convTrack.setIsTrackerOnly(setTrackerOnly);
104  convTrack.setIsArbitratedEcalSeeded(setArbitratedEcalSeeded);
105  convTrack.setIsArbitratedMerged(setArbitratedMerged);
106  convTrack.setIsArbitratedMergedEcalGeneral(setArbitratedMergedEcalGeneral);
107 
108  //fill trajectory association if configured, using correct map depending on track type
109  if (useTrajectory) {
110  if (gsftracktrajmap.size()) {
111  convTrack.setTrajRef(gsftracktrajmap.find(it->castTo<reco::GsfTrackRef>())->second);
112  }
113  else {
114  convTrack.setTrajRef(tracktrajmap.find(it->castTo<reco::TrackRef>())->second);
115  }
116  }
117 
118  outputTrks->push_back(convTrack);
119  }
120 
121  e.put(outputTrks);
122  return;
123 
124  }//end produce
T getParameter(std::string const &) const
void setIsArbitratedMergedEcalGeneral(bool b)
virtual void produce(edm::Event &e, const edm::EventSetup &c)
ConversionTrackProducer(const edm::ParameterSet &conf)
void setTrajRef(edm::Ref< std::vector< Trajectory > > tr)
void setIsArbitratedEcalSeeded(bool b)
std::vector< ConversionTrack > ConversionTrackCollection
collection of ConversionTracks
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
std::auto_ptr< reco::ConversionTrackCollection > outputTrks
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
tuple conf
Definition: dbtoconf.py:185
void setIsTrackerOnly(bool b)
void setIsArbitratedMerged(bool b)