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