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: giordano $
11 // $Date: 2011/08/05 19:45:49 $
12 // $Revision: 1.4 $
13 //
14 
15 #include <memory>
16 #include <string>
17 #include <iostream>
18 #include <cmath>
19 #include <vector>
20 
28 
30 
32 
34 
37 
38 
40  conf_(conf),
41  trackProducer ( conf.getParameter<std::string>("TrackProducer") ),
42  useTrajectory ( conf.getParameter<bool>("useTrajectory") ),
43  setTrackerOnly ( conf.getParameter<bool>("setTrackerOnly") ),
44  setArbitratedEcalSeeded ( conf.getParameter<bool>("setArbitratedEcalSeeded") ),
45  setArbitratedMerged ( conf.getParameter<bool>("setArbitratedMerged") ),
46  setArbitratedMergedEcalGeneral ( conf.getParameter<bool>("setArbitratedMergedEcalGeneral") ),
47  beamSpotInputTag ( conf.getParameter<edm::InputTag>("beamSpotInputTag") ),
48  filterOnConvTrackHyp( conf.getParameter<bool>("filterOnConvTrackHyp") ),
49  minConvRadius( conf.getParameter<double>("minConvRadius") )
50 {
51 
52  produces<reco::ConversionTrackCollection>();
53 
54 }
55 
56 
57  // Virtual destructor needed.
59 
60  // Functions that gets called by framework every event
62  {
63  //get input collection (through edm::View)
65  e.getByLabel(trackProducer, hTrks);
66 
67  //get association maps between trajectories and tracks and build temporary maps
70  reco::GsfTrackCollection,unsigned short> > > hTTAssGsf;
71 
72  std::map<reco::TrackRef,edm::Ref<std::vector<Trajectory> > > tracktrajmap;
73  std::map<reco::GsfTrackRef,edm::Ref<std::vector<Trajectory> > > gsftracktrajmap;
74 
75  if (useTrajectory) {
76  if (hTrks->size()>0) {
77  if (dynamic_cast<const reco::GsfTrack*>(&hTrks->at(0))) {
78  //fill map for gsf tracks
79  e.getByLabel(trackProducer, hTTAssGsf);
80  for ( edm::AssociationMap<edm::OneToOne<std::vector<Trajectory>,
81  reco::GsfTrackCollection,unsigned short> >::const_iterator iPair = hTTAssGsf->begin();
82  iPair != hTTAssGsf->end(); ++iPair) {
83 
84  gsftracktrajmap[iPair->val] = iPair->key;
85 
86  }
87 
88  }
89  else {
90  //fill map for standard tracks
91  e.getByLabel(trackProducer, hTTAss);
92  for ( TrajTrackAssociationCollection::const_iterator iPair = hTTAss->begin();
93  iPair != hTTAss->end();
94  ++iPair) {
95 
96  tracktrajmap[iPair->val] = iPair->key;
97 
98  }
99  }
100  }
101  }
102 
103  // Step B: create empty output collection
104  outputTrks = std::auto_ptr<reco::ConversionTrackCollection>(new reco::ConversionTrackCollection);
105 
106  //--------------------------------------------------
107  //Added by D. Giordano
108  // 2011/08/05
109  // Reduction of the track sample based on geometric hypothesis for conversion tracks
110 
111  edm::Handle<reco::BeamSpot> beamSpotHandle;
112  e.getByLabel(beamSpotInputTag,beamSpotHandle);
113 
114  edm::ESHandle<MagneticField> magFieldHandle;
115  es.get<IdealMagneticFieldRecord>().get( magFieldHandle );
116 
117 
118  if(filterOnConvTrackHyp && !beamSpotHandle.isValid()) {
119  edm::LogError("Invalid Collection") << "invalid collection for the BeamSpot with InputTag " << beamSpotInputTag;
120  throw;
121  }
122 
123  ConvTrackPreSelector.setMagnField(magFieldHandle.product());
124 
125  //----------------------------------------------------------
126 
127 
128  // Simple conversion of tracks to conversion tracks, setting appropriate flags from configuration
129  for (edm::RefToBaseVector<reco::Track>::const_iterator it = hTrks->refVector().begin(); it != hTrks->refVector().end(); ++it) {
130 
131  //--------------------------------------------------
132  //Added by D. Giordano
133  // 2011/08/05
134  // Reduction of the track sample based on geometric hypothesis for conversion tracks
135 
136  math::XYZVector beamSpot= math::XYZVector(beamSpotHandle->position());
137 
139  continue;
140  //--------------------------------------------------
141 
142  reco::ConversionTrack convTrack(*it);
143  convTrack.setIsTrackerOnly(setTrackerOnly);
147 
148  //fill trajectory association if configured, using correct map depending on track type
149  if (useTrajectory) {
150  if (gsftracktrajmap.size()) {
151  convTrack.setTrajRef(gsftracktrajmap.find(it->castTo<reco::GsfTrackRef>())->second);
152  }
153  else {
154  convTrack.setTrajRef(tracktrajmap.find(it->castTo<reco::TrackRef>())->second);
155  }
156  }
157 
158  outputTrks->push_back(convTrack);
159  }
160 
161  e.put(outputTrks);
162  return;
163 
164  }//end produce
165 
bool isTangentPointDistanceLessThan(float rmax, const reco::Track *track, const math::XYZVector refPoint)
void setIsArbitratedMergedEcalGeneral(bool b)
void setMagnField(const MagneticField *magnField)
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:85
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:356
tuple conf
Definition: dbtoconf.py:185
IdealHelixParameters ConvTrackPreSelector
void setIsTrackerOnly(bool b)
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
void setIsArbitratedMerged(bool b)