CMS 3D CMS Logo

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 //
11 
12 #include <memory>
13 #include <string>
14 #include <iostream>
15 #include <cmath>
16 #include <vector>
17 
19 
22 
25 
27 
29 
31 
34 
35 
37  conf_(conf),
38  trackProducer ( conf.getParameter<std::string>("TrackProducer") ),
39  useTrajectory ( conf.getParameter<bool>("useTrajectory") ),
40  setTrackerOnly ( conf.getParameter<bool>("setTrackerOnly") ),
41  setArbitratedEcalSeeded ( conf.getParameter<bool>("setArbitratedEcalSeeded") ),
42  setArbitratedMerged ( conf.getParameter<bool>("setArbitratedMerged") ),
43  setArbitratedMergedEcalGeneral ( conf.getParameter<bool>("setArbitratedMergedEcalGeneral") ),
44  beamSpotInputTag ( consumes<reco::BeamSpot>(conf.getParameter<edm::InputTag>("beamSpotInputTag")) ),
45  filterOnConvTrackHyp( conf.getParameter<bool>("filterOnConvTrackHyp") ),
46  minConvRadius( conf.getParameter<double>("minConvRadius") )
47 {
50  consumes<edm::View<reco::Track> >(thetp);
52  consumes<TrajTrackAssociationCollection>(thetp);
54  consumes<TrajGsfTrackAssociationCollection>(thetp);
55  produces<reco::ConversionTrackCollection>();
56 
57 }
58 
59 
60  // Virtual destructor needed.
62 
63  // Functions that gets called by framework every event
65  {
66  //get input collection (through edm::View)
68  e.getByToken(genericTracks, hTrks);
69 
70  //get association maps between trajectories and tracks and build temporary maps
73 
74  std::map<reco::TrackRef,edm::Ref<std::vector<Trajectory> > > tracktrajmap;
75  std::map<reco::GsfTrackRef,edm::Ref<std::vector<Trajectory> > > gsftracktrajmap;
76 
77  if (useTrajectory) {
78  if (!hTrks->empty()) {
79  if (dynamic_cast<const reco::GsfTrack*>(&hTrks->at(0))) {
80  //fill map for gsf tracks
81  e.getByToken(gsfTrajectories, hTTAssGsf);
83  hTTAssGsf->begin();
84  iPair != hTTAssGsf->end(); ++iPair) {
85 
86  gsftracktrajmap[iPair->val] = iPair->key;
87 
88  }
89 
90  }
91  else {
92  //fill map for standard tracks
93  e.getByToken(kfTrajectories, hTTAss);
95  iPair != hTTAss->end();
96  ++iPair) {
97 
98  tracktrajmap[iPair->val] = iPair->key;
99 
100  }
101  }
102  }
103  }
104 
105  // Step B: create empty output collection
106  outputTrks = std::make_unique<reco::ConversionTrackCollection>();
107 
108  //--------------------------------------------------
109  //Added by D. Giordano
110  // 2011/08/05
111  // Reduction of the track sample based on geometric hypothesis for conversion tracks
112 
113  edm::Handle<reco::BeamSpot> beamSpotHandle;
114  e.getByToken(beamSpotInputTag,beamSpotHandle);
115 
116  edm::ESHandle<MagneticField> magFieldHandle;
117  es.get<IdealMagneticFieldRecord>().get( magFieldHandle );
118 
119 
120  if(filterOnConvTrackHyp && !beamSpotHandle.isValid()) {
121  edm::LogError("Invalid Collection")
122  << "invalid collection for the BeamSpot";
123  throw;
124  }
125 
126  ConvTrackPreSelector.setMagnField(magFieldHandle.product());
127 
128  //----------------------------------------------------------
129 
130 
131  // Simple conversion of tracks to conversion tracks, setting appropriate flags from configuration
132  for (size_t i = 0; i < hTrks->size(); ++i) {
133 
134  //--------------------------------------------------
135  //Added by D. Giordano
136  // 2011/08/05
137  // Reduction of the track sample based on geometric hypothesis for conversion tracks
138 
139  math::XYZVector beamSpot= math::XYZVector(beamSpotHandle->position());
140  edm::RefToBase<reco::Track> trackBaseRef = hTrks->refAt(i);
142  continue;
143  //--------------------------------------------------
144 
145  reco::ConversionTrack convTrack(trackBaseRef);
146  convTrack.setIsTrackerOnly(setTrackerOnly);
150 
151  //fill trajectory association if configured, using correct map depending on track type
152  if (useTrajectory) {
153  if (!gsftracktrajmap.empty()) {
154  convTrack.setTrajRef(gsftracktrajmap.find(trackBaseRef.castTo<reco::GsfTrackRef>())->second);
155  }
156  else {
157  convTrack.setTrajRef(tracktrajmap.find(trackBaseRef.castTo<reco::TrackRef>())->second);
158  }
159  }
160 
161  outputTrks->push_back(convTrack);
162  }
163 
165  return;
166 
167  }//end produce
168 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
void setIsArbitratedMergedEcalGeneral(bool b)
const_iterator end() const
last iterator over the map (read only)
void setMagnField(const MagneticField *magnField)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
edm::EDGetTokenT< edm::View< reco::Track > > genericTracks
edm::EDGetTokenT< TrajTrackAssociationCollection > kfTrajectories
ConversionTrackProducer(const edm::ParameterSet &conf)
void setTrajRef(edm::Ref< std::vector< Trajectory > > tr)
void setIsArbitratedEcalSeeded(bool b)
std::unique_ptr< reco::ConversionTrackCollection > outputTrks
IdealHelixParameters ConvTrackPreSelector
void setIsTrackerOnly(bool b)
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
edm::EDGetTokenT< reco::BeamSpot > beamSpotInputTag
const T & get() const
Definition: EventSetup.h:58
fixed size matrix
HLT enums.
edm::EDGetTokenT< TrajGsfTrackAssociationCollection > gsfTrajectories
bool isTangentPointDistanceLessThan(float rmax, const reco::Track *track, const math::XYZVector &refPoint)
void produce(edm::Event &e, const edm::EventSetup &c) override
const_iterator begin() const
first iterator over the map (read only)
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:510
void setIsArbitratedMerged(bool b)