CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackAlgoCompareUtil.cc
Go to the documentation of this file.
3 
4 using namespace std;
5 using namespace edm;
6 
7 
8 // constructors and destructor
10 {
11  //now do what ever other initialization is needed
12  trackLabel_algoA = iConfig.getParameter<edm::InputTag>("trackLabel_algoA");
13  trackLabel_algoB = iConfig.getParameter<edm::InputTag>("trackLabel_algoB");
14  trackingParticleLabel_fakes = iConfig.getParameter<edm::InputTag>("trackingParticleLabel_fakes");
15  trackingParticleLabel_effic = iConfig.getParameter<edm::InputTag>("trackingParticleLabel_effic");
16  vertexLabel_algoA = iConfig.getParameter<edm::InputTag>("vertexLabel_algoA");
17  vertexLabel_algoB = iConfig.getParameter<edm::InputTag>("vertexLabel_algoB");
18  beamSpotLabel = iConfig.getParameter<edm::InputTag>("beamSpotLabel");
19  assocLabel_algoA = iConfig.getUntrackedParameter<std::string>("assocLabel_algoA", "trackAssociatorByHits");
20  assocLabel_algoB = iConfig.getUntrackedParameter<std::string>("assocLabel_algoB", "trackAssociatorByHits");
21  associatormap_algoA = iConfig.getParameter< edm::InputTag >("associatormap_algoA");
22  associatormap_algoB = iConfig.getParameter< edm::InputTag >("associatormap_algoB");
23  UseAssociators = iConfig.getParameter< bool >("UseAssociators");
24  UseVertex = iConfig.getParameter< bool >("UseVertex");
25 
26  produces<RecoTracktoTPCollection>("AlgoA");
27  produces<RecoTracktoTPCollection>("AlgoB");
28  produces<TPtoRecoTrackCollection>("TP");
29 }
30 
31 
33 {
34 }
35 
36 
37 // ------------ method called once each job just before starting event loop ------------
39 {
40 }
41 
42 
43 // ------------ method called to produce the data ------------
44 void
46 {
47  // create output collection instance
48  std::auto_ptr<RecoTracktoTPCollection> outputAlgoA(new RecoTracktoTPCollection());
49  std::auto_ptr<RecoTracktoTPCollection> outputAlgoB(new RecoTracktoTPCollection());
50  std::auto_ptr<TPtoRecoTrackCollection> outputTP(new TPtoRecoTrackCollection());
51 
52  // Get Inputs
53  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
54  iEvent.getByLabel(beamSpotLabel, recoBeamSpotHandle);
55  reco::BeamSpot beamSpot = *recoBeamSpotHandle;
56 
57  edm::Handle<View<reco::Track> > trackCollAlgoA;
58  iEvent.getByLabel(trackLabel_algoA, trackCollAlgoA);
59 
60  edm::Handle< View<reco::Track> > trackCollAlgoB;
61  iEvent.getByLabel(trackLabel_algoB, trackCollAlgoB);
62 
63  edm::Handle<TrackingParticleCollection> trackingParticleCollFakes;
64  iEvent.getByLabel(trackingParticleLabel_fakes, trackingParticleCollFakes);
65 
66  edm::Handle<TrackingParticleCollection> trackingParticleCollEffic;
67  iEvent.getByLabel(trackingParticleLabel_effic, trackingParticleCollEffic);
68 
71  if(UseVertex)
72  {
73  iEvent.getByLabel(vertexLabel_algoA, vertexCollAlgoA);
74  iEvent.getByLabel(vertexLabel_algoB, vertexCollAlgoB);
75  }
76 
77  // call the associator functions:
78  reco::RecoToSimCollection recSimColl_AlgoA;
79  reco::RecoToSimCollection recSimColl_AlgoB;
80 
81  reco::SimToRecoCollection simRecColl_AlgoA;
82  reco::SimToRecoCollection simRecColl_AlgoB;
83 
84  if(UseAssociators)
85  {
87  iEvent.getByLabel(assocLabel_algoA, theAssociator_algoA);
88 
90  iEvent.getByLabel(assocLabel_algoB, theAssociator_algoB);
91 
92  recSimColl_AlgoA = theAssociator_algoA->associateRecoToSim(trackCollAlgoA, trackingParticleCollFakes);
93  recSimColl_AlgoB = theAssociator_algoB->associateRecoToSim(trackCollAlgoB, trackingParticleCollFakes);
94 
95  simRecColl_AlgoA = theAssociator_algoA->associateSimToReco(trackCollAlgoA, trackingParticleCollEffic);
96  simRecColl_AlgoB = theAssociator_algoB->associateSimToReco(trackCollAlgoB, trackingParticleCollEffic);
97  }
98  else
99  {
100  Handle<reco::RecoToSimCollection > recotosimCollectionH_AlgoA;
101  iEvent.getByLabel(associatormap_algoA,recotosimCollectionH_AlgoA);
102  recSimColl_AlgoA = *(recotosimCollectionH_AlgoA.product());
103 
104  Handle<reco::RecoToSimCollection > recotosimCollectionH_AlgoB;
105  iEvent.getByLabel(associatormap_algoB,recotosimCollectionH_AlgoB);
106  recSimColl_AlgoB = *(recotosimCollectionH_AlgoB.product());
107 
108  Handle<reco::SimToRecoCollection > simtorecoCollectionH_AlgoA;
109  iEvent.getByLabel(associatormap_algoA, simtorecoCollectionH_AlgoA);
110  simRecColl_AlgoA = *(simtorecoCollectionH_AlgoA.product());
111 
112  Handle<reco::SimToRecoCollection > simtorecoCollectionH_AlgoB;
113  iEvent.getByLabel(associatormap_algoB, simtorecoCollectionH_AlgoB);
114  simRecColl_AlgoB = *(simtorecoCollectionH_AlgoB.product());
115  }
116 
117  // define the vector of references to trackingParticleColl associated with a given reco::Track
118  std::vector<std::pair<TrackingParticleRef, double> > associatedTrackingParticles;
119 
120  // define the vector of references to trackColl associated with a given TrackingParticle
121  std::vector<std::pair<reco::TrackBaseRef, double> > associatedRecoTracks;
122 
123  // Get the magnetic field data from the event (used to calculate the point of closest TrackingParticle)
124  edm::ESHandle<MagneticField> theMagneticField;
125  iSetup.get<IdealMagneticFieldRecord>().get(theMagneticField);
126  const MagneticField *magneticField = theMagneticField.product();
127 
128  // fill collection algoA
129  for(View<reco::Track>::size_type i = 0; i < trackCollAlgoA->size(); ++i)
130  {
131  // get recoTrack algo A
132  reco::TrackBaseRef recoTrack(trackCollAlgoA, i);
133  RecoTracktoTP recoTracktoTP;
134  recoTracktoTP.SetRecoTrack(recoTrack);
135  recoTracktoTP.SetBeamSpot(beamSpot.position());
136 
137  // get the associated trackingParticle
138  if(recSimColl_AlgoA.find(recoTrack) != recSimColl_AlgoA.end())
139  {
140  associatedTrackingParticles = recSimColl_AlgoA[recoTrack];
141  recoTracktoTP.SetTrackingParticle( associatedTrackingParticles.begin()->first );
142  recoTracktoTP.SetShared( associatedTrackingParticles.begin()->second );
143  SetTrackingParticleD0Dz(associatedTrackingParticles.begin()->first, beamSpot, magneticField, recoTracktoTP);
144  }
145  else
146  {
147  recoTracktoTP.SetTrackingParticle(TrackingParticleRef());
148  recoTracktoTP.SetShared(-1.0);
149  }
150 
151  // get the reco primary vertex info
152  if(UseVertex && vertexCollAlgoA->size())
153  {
154  recoTracktoTP.SetRecoVertex( reco::VertexRef(vertexCollAlgoA, 0) );
155  }
156  else
157  {
158  recoTracktoTP.SetRecoVertex( reco::VertexRef() );
159  }
160 
161  outputAlgoA->push_back(recoTracktoTP);
162  }
163 
164 
165  // fill collection algoB
166  for(reco::TrackCollection::size_type i = 0; i < trackCollAlgoB->size(); ++i)
167  {
168  // get recoTrack algo B
169  reco::TrackBaseRef recoTrack(trackCollAlgoB, i);
170  RecoTracktoTP recoTracktoTP;
171  recoTracktoTP.SetRecoTrack(recoTrack);
172  recoTracktoTP.SetBeamSpot(beamSpot.position());
173 
174  // get the associated trackingParticle
175  if(recSimColl_AlgoB.find(recoTrack) != recSimColl_AlgoB.end())
176  {
177  associatedTrackingParticles = recSimColl_AlgoB[recoTrack];
178  recoTracktoTP.SetTrackingParticle( associatedTrackingParticles.begin()->first );
179  recoTracktoTP.SetShared( associatedTrackingParticles.begin()->second );
180  SetTrackingParticleD0Dz(associatedTrackingParticles.begin()->first, beamSpot, magneticField, recoTracktoTP);
181  }
182  else
183  {
184  recoTracktoTP.SetTrackingParticle(TrackingParticleRef());
185  recoTracktoTP.SetShared(-1.0);
186  }
187 
188  // get the reco primary vertex info
189  if(UseVertex && vertexCollAlgoB->size())
190  {
191  recoTracktoTP.SetRecoVertex( reco::VertexRef(vertexCollAlgoB, 0) );
192  }
193  else
194  {
195  recoTracktoTP.SetRecoVertex( reco::VertexRef() );
196  }
197 
198  outputAlgoB->push_back(recoTracktoTP);
199  }
200 
201 
202  for(TrackingParticleCollection::size_type i = 0; i < trackingParticleCollEffic->size(); ++i)
203  {
204  // initialize the trackingParticle (sim) info
205  TrackingParticleRef tparticle(trackingParticleCollEffic, i);
206  TPtoRecoTrack tptoRecoTrack;
207  tptoRecoTrack.SetBeamSpot(beamSpot.position());
208  tptoRecoTrack.SetTrackingParticle(tparticle);
209  SetTrackingParticleD0Dz(tparticle, beamSpot, magneticField, tptoRecoTrack);
210 
211  // get the assocated recoTrack algoA
212  if(simRecColl_AlgoA.find(tparticle) != simRecColl_AlgoA.end())
213  {
214  associatedRecoTracks = simRecColl_AlgoA[tparticle];
215  tptoRecoTrack.SetRecoTrack_AlgoA(associatedRecoTracks.begin()->first );
216  tptoRecoTrack.SetShared_AlgoA(associatedRecoTracks.begin()->second );
217  }
218  else
219  {
220  tptoRecoTrack.SetRecoTrack_AlgoA(reco::TrackBaseRef());
221  tptoRecoTrack.SetShared_AlgoA(-1.0);
222  }
223 
224  // get the recoVertex algo A
225  if(UseVertex && vertexCollAlgoA->size())
226  {
227  tptoRecoTrack.SetRecoVertex_AlgoA( reco::VertexRef(vertexCollAlgoA, 0) );
228  }
229  else
230  {
231  tptoRecoTrack.SetRecoVertex_AlgoA( reco::VertexRef() );
232  }
233 
234  // get the assocated recoTrack algoB
235  if(simRecColl_AlgoB.find(tparticle) != simRecColl_AlgoB.end())
236  {
237  associatedRecoTracks = simRecColl_AlgoB[tparticle];
238  tptoRecoTrack.SetRecoTrack_AlgoB(associatedRecoTracks.begin()->first );
239  tptoRecoTrack.SetShared_AlgoB(associatedRecoTracks.begin()->second );
240  }
241  else
242  {
243  tptoRecoTrack.SetRecoTrack_AlgoB(reco::TrackBaseRef());
244  tptoRecoTrack.SetShared_AlgoB(-1.0);
245  }
246  // get the recoVertex algo B
247  if(UseVertex && vertexCollAlgoB->size())
248  {
249  tptoRecoTrack.SetRecoVertex_AlgoB( reco::VertexRef(vertexCollAlgoB, 0) );
250  }
251  else
252  {
253  tptoRecoTrack.SetRecoVertex_AlgoB( reco::VertexRef() );
254  }
255 
256  outputTP->push_back(tptoRecoTrack);
257  }
258 
259 
260  // put the collection in the event record
261  iEvent.put(outputAlgoA, "AlgoA");
262  iEvent.put(outputAlgoB, "AlgoB");
263  iEvent.put(outputTP, "TP");
264 }
265 
266 // ------------ method called once each job just after ending the event loop ------------
268 {
269 }
270 
271 
272 // ------------ Producer Specific Meber Fucntions ----------------------------------------
274 {
275  GlobalPoint trackingParticleVertex( tp->vertex().x(), tp->vertex().y(), tp->vertex().z() );
276  GlobalVector trackingParticleP3(tp->g4Track_begin()->momentum().x(),
277  tp->g4Track_begin()->momentum().y(),
278  tp->g4Track_begin()->momentum().z() );
279  TrackCharge trackingParticleCharge(tp->charge());
280 
281  FreeTrajectoryState ftsAtProduction( trackingParticleVertex, trackingParticleP3, trackingParticleCharge, bf );
282  TSCBLBuilderNoMaterial tscblBuilder;
283  TrajectoryStateClosestToBeamLine tsAtClosestApproach = tscblBuilder(ftsAtProduction, bs); //as in TrackProducerAlgorithm
284 
285  if(tsAtClosestApproach.isValid())
286  {
287  GlobalPoint v1 = tsAtClosestApproach.trackStateAtPCA().position();
288  GlobalVector p = tsAtClosestApproach.trackStateAtPCA().momentum();
289 
291  TPRT.SetTrackingParticlePCA(v1);
292  }
293  else
294  {
295  TPRT.SetTrackingParticleMomentumPCA(GlobalVector(-9999.0, -9999.0, -9999.0));
296  TPRT.SetTrackingParticlePCA(GlobalPoint(-9999.0, -9999.0, -9999.0));
297  }
298 }
299 
300 
302 {
303  GlobalPoint trackingParticleVertex( tp->vertex().x(), tp->vertex().y(), tp->vertex().z() );
304  GlobalVector trackingParticleP3(tp->g4Track_begin()->momentum().x(),
305  tp->g4Track_begin()->momentum().y(),
306  tp->g4Track_begin()->momentum().z() );
307  TrackCharge trackingParticleCharge(tp->charge());
308 
309  FreeTrajectoryState ftsAtProduction( trackingParticleVertex, trackingParticleP3, trackingParticleCharge, bf );
310  TSCBLBuilderNoMaterial tscblBuilder;
311  TrajectoryStateClosestToBeamLine tsAtClosestApproach = tscblBuilder(ftsAtProduction, bs); //as in TrackProducerAlgorithm
312 
313  if(tsAtClosestApproach.isValid())
314  {
315  GlobalPoint v1 = tsAtClosestApproach.trackStateAtPCA().position();
316  GlobalVector p = tsAtClosestApproach.trackStateAtPCA().momentum();
317 
319  RTTP.SetTrackingParticlePCA(v1);
320  }
321  else
322  {
323  RTTP.SetTrackingParticleMomentumPCA(GlobalVector(-9999.0, -9999.0, -9999.0));
324  RTTP.SetTrackingParticlePCA(GlobalPoint(-9999.0, -9999.0, -9999.0));
325  }
326 }
327 
T getParameter(std::string const &) const
unsigned int size_type
Definition: View.h:85
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
void SetTrackingParticle(TrackingParticleRef tp)
Definition: RecoTracktoTP.h:28
void SetTrackingParticleMomentumPCA(const GlobalVector &p)
Definition: RecoTracktoTP.h:56
const_iterator end() const
last iterator over the map (read only)
void SetTrackingParticle(TrackingParticleRef tp)
Definition: TPtoRecoTrack.h:28
void SetShared_AlgoA(const float &mA)
Definition: TPtoRecoTrack.h:33
void SetTrackingParticleMomentumPCA(const GlobalVector &p)
Definition: TPtoRecoTrack.h:81
const_iterator find(const key_type &k) const
find element with specified reference key
void SetShared(const float &m)
Definition: RecoTracktoTP.h:32
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
void SetTrackingParticlePCA(const GlobalPoint &v)
Definition: RecoTracktoTP.h:57
std::vector< RecoTracktoTP > RecoTracktoTPCollection
void SetRecoVertex(reco::VertexRef vertex)
Definition: RecoTracktoTP.h:30
std::vector< TPtoRecoTrack > TPtoRecoTrackCollection
void SetRecoTrack_AlgoA(reco::TrackBaseRef track)
Definition: TPtoRecoTrack.h:30
void SetTrackingParticlePCA(const GlobalPoint &v)
Definition: TPtoRecoTrack.h:82
uint16_t size_type
void SetTrackingParticleD0Dz(TrackingParticleRef tp, const reco::BeamSpot &bs, const MagneticField *bf, TPtoRecoTrack &TPRT)
int TrackCharge
Definition: TrackCharge.h:4
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
virtual void produce(edm::Event &, const edm::EventSetup &) override
void SetRecoVertex_AlgoB(reco::VertexRef vertex)
Definition: TPtoRecoTrack.h:37
void SetRecoVertex_AlgoA(reco::VertexRef vertex)
Definition: TPtoRecoTrack.h:36
TrackAlgoCompareUtil(const edm::ParameterSet &)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:405
GlobalVector momentum() const
GlobalPoint position() const
T const * product() const
Definition: Handle.h:81
void SetShared_AlgoB(const float &mB)
Definition: TPtoRecoTrack.h:34
void SetRecoTrack(reco::TrackBaseRef track)
Definition: RecoTracktoTP.h:29
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
void SetBeamSpot(const math::XYZPoint &bs)
Definition: TPtoRecoTrack.h:39
void SetBeamSpot(const math::XYZPoint &bs)
Definition: RecoTracktoTP.h:31
const Point & position() const
position
Definition: BeamSpot.h:62
void SetRecoTrack_AlgoB(reco::TrackBaseRef track)
Definition: TPtoRecoTrack.h:31
edm::Ref< TrackingParticleCollection > TrackingParticleRef
Global3DVector GlobalVector
Definition: GlobalVector.h:10