CMS 3D CMS Logo

CaloPropagateTrack.cc
Go to the documentation of this file.
8 
11 
14 
15 #include <iostream>
16 
17 //#define EDM_ML_DEBUG
18 
19 namespace spr{
20 
21  std::vector<spr::propagatedTrackID> propagateCosmicCALO(edm::Handle<reco::TrackCollection>& trkCollection, const CaloGeometry* geo, const MagneticField* bField, std::string & theTrackQuality, bool debug) {
22 
23  const EcalBarrelGeometry *barrelGeom = (dynamic_cast< const EcalBarrelGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalBarrel)));
24  const EcalEndcapGeometry *endcapGeom = (dynamic_cast< const EcalEndcapGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalEndcap)));
27  std::vector<spr::propagatedTrackID> vdets;
28 
29  unsigned int indx;
30  reco::TrackCollection::const_iterator trkItr;
31  for (trkItr = trkCollection->begin(),indx=0; trkItr != trkCollection->end(); ++trkItr,indx++) {
32  const reco::Track* pTrack = &(*trkItr);
34  vdet.trkItr = trkItr;
35  vdet.ok = (pTrack->quality(trackQuality_));
36  vdet.detIdECAL = DetId(0);
37  vdet.detIdHCAL = DetId(0);
38  vdet.detIdEHCAL= DetId(0);
39 #ifdef EDM_ML_DEBUG
40  if (debug) std::cout << "Propagate track " << indx << " p " << trkItr->p() << " eta " << trkItr->eta() << " phi " << trkItr->phi() << " Flag " << vdet.ok << std::endl;
41 #endif
42  GlobalPoint vertex;
43  GlobalVector momentum;
44  int charge (pTrack->charge());
45  if (((pTrack->innerPosition()).Perp2()) <
46  ((pTrack->outerPosition()).Perp2())) {
47  vertex = GlobalPoint(((pTrack->innerPosition()).X()),
48  ((pTrack->innerPosition()).Y()),
49  ((pTrack->innerPosition()).Z()));
50  momentum = GlobalVector(((pTrack->innerMomentum()).X()),
51  ((pTrack->innerMomentum()).Y()),
52  ((pTrack->innerMomentum()).Z()));
53  } else {
54  vertex = GlobalPoint(((pTrack->outerPosition()).X()),
55  ((pTrack->outerPosition()).Y()),
56  ((pTrack->outerPosition()).Z()));
57  momentum = GlobalVector(((pTrack->outerMomentum()).X()),
58  ((pTrack->outerMomentum()).Y()),
59  ((pTrack->outerMomentum()).Z()));
60  }
61 #ifdef EDM_ML_DEBUG
62  if (debug) std::cout << "Track charge " << charge << " p " << momentum << " position " << vertex << std::endl;
63 #endif
64  std::pair<math::XYZPoint,bool> info =
65  spr::propagateECAL (vertex, momentum, charge, bField, debug);
66 
67  vdet.okECAL = info.second;
68  if (vdet.okECAL) {
69  const GlobalPoint point(info.first.x(),info.first.y(),info.first.z());
70  vdet.etaECAL = point.eta();
71  vdet.phiECAL = point.phi();
72  if (std::abs(point.eta())<spr::etaBEEcal) {
73  vdet.detIdECAL = barrelGeom->getClosestCell(point);
74  } else {
75  vdet.detIdECAL = endcapGeom->getClosestCell(point);
76  }
77  vdet.detIdEHCAL = gHB->getClosestCell(point);
78  }
79  info = spr::propagateHCAL (vertex, momentum, charge, bField, debug);
80  vdet.okHCAL = info.second;
81  if (vdet.okHCAL) {
82  const GlobalPoint point(info.first.x(),info.first.y(),info.first.z());
83  vdet.etaHCAL = point.eta();
84  vdet.phiHCAL = point.phi();
85  vdet.detIdHCAL = gHB->getClosestCell(point);
86  }
87 #ifdef EDM_ML_DEBUG
88  if (debug) {
89  std::cout << "Track [" << indx << "] Flag: " << vdet.ok << " ECAL ("
90  << vdet.okECAL << ") ";
91  if (vdet.detIdECAL.subdetId() == EcalBarrel)
92  std::cout << (EBDetId)(vdet.detIdECAL);
93  else
94  std::cout << (EEDetId)(vdet.detIdECAL);
95  std::cout << " HCAL (" << vdet.okHCAL << ") " << (HcalDetId)(vdet.detIdHCAL) << " Or " << (HcalDetId)(vdet.detIdEHCAL) << std::endl;
96  }
97 #endif
98  vdets.push_back(vdet);
99  }
100 
101 #ifdef EDM_ML_DEBUG
102  if (debug) {
103  std::cout << "propagateCALO:: for " << vdets.size() << " tracks" << std::endl;
104  for (unsigned int i=0; i<vdets.size(); ++i) {
105  std::cout << "Track [" << i << "] Flag: " << vdets[i].ok << " ECAL (" << vdets[i].okECAL << ") ";
106  if (vdets[i].detIdECAL.subdetId() == EcalBarrel) {
107  std::cout << (EBDetId)(vdets[i].detIdECAL);
108  } else {
109  std::cout << (EEDetId)(vdets[i].detIdECAL);
110  }
111  std::cout << " HCAL (" << vdets[i].okHCAL << ") " << (HcalDetId)(vdets[i].detIdHCAL) << " Or " << (HcalDetId)(vdets[i].detIdEHCAL) << std::endl;
112  }
113  }
114 #endif
115  return vdets;
116  }
117 
118  std::vector<spr::propagatedTrackID> propagateCALO(edm::Handle<reco::TrackCollection>& trkCollection, const CaloGeometry* geo, const MagneticField* bField, std::string & theTrackQuality, bool debug) {
119 
120  std::vector<spr::propagatedTrackID> vdets;
121  spr::propagateCALO(trkCollection,geo,bField,theTrackQuality, vdets, debug);
122  return vdets;
123  }
124 
125  void propagateCALO(edm::Handle<reco::TrackCollection>& trkCollection, const CaloGeometry* geo, const MagneticField* bField, std::string & theTrackQuality, std::vector<spr::propagatedTrackID>& vdets, bool debug) {
126 
127  const EcalBarrelGeometry *barrelGeom = (dynamic_cast< const EcalBarrelGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalBarrel)));
128  const EcalEndcapGeometry *endcapGeom = (dynamic_cast< const EcalEndcapGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalEndcap)));
130  reco::TrackBase::TrackQuality trackQuality_=reco::TrackBase::qualityByName(theTrackQuality);
131 
132  unsigned int indx;
133  reco::TrackCollection::const_iterator trkItr;
134  for (trkItr = trkCollection->begin(),indx=0; trkItr != trkCollection->end(); ++trkItr,indx++) {
135  const reco::Track* pTrack = &(*trkItr);
137  vdet.trkItr = trkItr;
138  vdet.ok = (pTrack->quality(trackQuality_));
139  vdet.detIdECAL = DetId(0);
140  vdet.detIdHCAL = DetId(0);
141  vdet.detIdEHCAL= DetId(0);
142 #ifdef EDM_ML_DEBUG
143  if (debug) std::cout << "Propagate track " << indx << " p " << trkItr->p() << " eta " << trkItr->eta() << " phi " << trkItr->phi() << " Flag " << vdet.ok << std::endl;
144 #endif
145  std::pair<math::XYZPoint,bool> info = spr::propagateECAL (pTrack, bField, debug);
146  vdet.okECAL = info.second;
147  if (vdet.okECAL) {
148  const GlobalPoint point(info.first.x(),info.first.y(),info.first.z());
149  vdet.etaECAL = point.eta();
150  vdet.phiECAL = point.phi();
151  if (std::abs(point.eta())<spr::etaBEEcal) {
152  vdet.detIdECAL = barrelGeom->getClosestCell(point);
153  } else {
154  vdet.detIdECAL = endcapGeom->getClosestCell(point);
155  }
156  vdet.detIdEHCAL = gHB->getClosestCell(point);
157  }
158  info = spr::propagateHCAL (pTrack, bField, debug);
159  vdet.okHCAL = info.second;
160  if (vdet.okHCAL) {
161  const GlobalPoint point(info.first.x(),info.first.y(),info.first.z());
162  vdet.etaHCAL = point.eta();
163  vdet.phiHCAL = point.phi();
164  vdet.detIdHCAL = gHB->getClosestCell(point);
165  }
166 #ifdef EDM_ML_DEBUG
167  if (debug) {
168  std::cout << "Track [" << indx << "] Flag: " << vdet.ok << " ECAL ("
169  << vdet.okECAL << ") ";
170  if (vdet.detIdECAL.subdetId() == EcalBarrel)
171  std::cout << (EBDetId)(vdet.detIdECAL);
172  else
173  std::cout << (EEDetId)(vdet.detIdECAL);
174  std::cout << " HCAL (" << vdet.okHCAL << ") " << (HcalDetId)(vdet.detIdHCAL) << " Or " << (HcalDetId)(vdet.detIdEHCAL) << std::endl;
175  }
176 #endif
177  vdets.push_back(vdet);
178  }
179 #ifdef EDM_ML_DEBUG
180  if (debug) {
181  std::cout << "propagateCALO:: for " << vdets.size() << " tracks" << std::endl;
182  for (unsigned int i=0; i<vdets.size(); ++i) {
183  std::cout << "Track [" << i << "] Flag: " << vdets[i].ok << " ECAL (" << vdets[i].okECAL << ") ";
184  if (vdets[i].detIdECAL.subdetId() == EcalBarrel) {
185  std::cout << (EBDetId)(vdets[i].detIdECAL);
186  } else {
187  std::cout << (EEDetId)(vdets[i].detIdECAL);
188  }
189  std::cout << " HCAL (" << vdets[i].okHCAL << ") " << (HcalDetId)(vdets[i].detIdHCAL) << " Or " << (HcalDetId)(vdets[i].detIdEHCAL) << std::endl;
190  }
191  }
192 #endif
193  }
194 
195  void propagateCALO(edm::Handle<reco::TrackCollection>& trkCollection, const CaloGeometry* geo, const MagneticField* bField, std::string & theTrackQuality, std::vector<spr::propagatedTrackDirection>& trkDir, bool debug) {
196 
197  const EcalBarrelGeometry *barrelGeom = (dynamic_cast< const EcalBarrelGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalBarrel)));
198  const EcalEndcapGeometry *endcapGeom = (dynamic_cast< const EcalEndcapGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalEndcap)));
200  reco::TrackBase::TrackQuality trackQuality_=reco::TrackBase::qualityByName(theTrackQuality);
201 
202  unsigned int indx;
203  reco::TrackCollection::const_iterator trkItr;
204  for (trkItr = trkCollection->begin(),indx=0; trkItr != trkCollection->end(); ++trkItr,indx++) {
205  const reco::Track* pTrack = &(*trkItr);
207  trkD.trkItr = trkItr;
208  trkD.ok = (pTrack->quality(trackQuality_));
209  trkD.detIdECAL = DetId(0);
210  trkD.detIdHCAL = DetId(0);
211  trkD.detIdEHCAL= DetId(0);
212 #ifdef EDM_ML_DEBUG
213  if (debug) std::cout << "Propagate track " << indx << " p " << trkItr->p() << " eta " << trkItr->eta() << " phi " << trkItr->phi() << " Flag " << trkD.ok << std::endl;
214 #endif
215  spr::propagatedTrack info = spr::propagateTrackToECAL (pTrack, bField, debug);
216  GlobalPoint point(info.point.x(),info.point.y(),info.point.z());
217  trkD.okECAL = info.ok;
218  trkD.pointECAL = point;
219  trkD.directionECAL = info.direction;
220  if (trkD.okECAL) {
221  if (std::abs(info.point.eta())<spr::etaBEEcal) {
222  trkD.detIdECAL = barrelGeom->getClosestCell(point);
223  } else {
224  trkD.detIdECAL = endcapGeom->getClosestCell(point);
225  }
226  trkD.detIdEHCAL = gHB->getClosestCell(point);
227  }
228  info = spr::propagateTrackToHCAL (pTrack, bField, debug);
229  point = GlobalPoint(info.point.x(),info.point.y(),info.point.z());
230  trkD.okHCAL = info.ok;
231  trkD.pointHCAL = point;
232  trkD.directionHCAL = info.direction;
233  if (trkD.okHCAL) {
234  trkD.detIdHCAL = gHB->getClosestCell(point);
235  }
236  trkDir.push_back(trkD);
237  }
238 #ifdef EDM_ML_DEBUG
239  if (debug) {
240  std::cout << "propagateCALO:: for " << trkDir.size() << " tracks" << std::endl;
241  for (unsigned int i=0; i<trkDir.size(); ++i) {
242  std::cout << "Track [" << i << "] Flag: " << trkDir[i].ok << " ECAL (" << trkDir[i].okECAL << ")";
243  if (trkDir[i].okECAL) {
244  std::cout << " point " << trkDir[i].pointECAL << " direction "
245  << trkDir[i].directionECAL << " ";
246  if (trkDir[i].detIdECAL.subdetId() == EcalBarrel) {
247  std::cout << (EBDetId)(trkDir[i].detIdECAL);
248  } else {
249  std::cout << (EEDetId)(trkDir[i].detIdECAL);
250  }
251  }
252  std::cout << " HCAL (" << trkDir[i].okHCAL << ")";
253  if (trkDir[i].okHCAL) {
254  std::cout << " point " << trkDir[i].pointHCAL << " direction "
255  << trkDir[i].directionHCAL << " "
256  << (HcalDetId)(trkDir[i].detIdHCAL);
257  }
258  std::cout << " Or " << (HcalDetId)(trkDir[i].detIdEHCAL) << std::endl;
259  }
260  }
261 #endif
262  }
263 
265 
266  const EcalBarrelGeometry *barrelGeom = (dynamic_cast< const EcalBarrelGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalBarrel)));
267  const EcalEndcapGeometry *endcapGeom = (dynamic_cast< const EcalEndcapGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalEndcap)));
269 
271  vdet.ok = true;
272  vdet.detIdECAL = DetId(0);
273  vdet.detIdHCAL = DetId(0);
274  vdet.detIdEHCAL= DetId(0);
275 #ifdef EDM_ML_DEBUG
276  if (debug) std::cout << "Propagate track: p " << pTrack->p() << " eta " << pTrack->eta() << " phi " << pTrack->phi() << " Flag " << vdet.ok << std::endl;
277 #endif
278  std::pair<math::XYZPoint,bool> info = spr::propagateECAL (pTrack, bField, debug);
279  vdet.okECAL = info.second;
280  if (vdet.okECAL) {
281  const GlobalPoint point(info.first.x(),info.first.y(),info.first.z());
282  vdet.etaECAL = point.eta();
283  vdet.phiECAL = point.phi();
284  if (std::abs(point.eta())<spr::etaBEEcal) {
285  vdet.detIdECAL = barrelGeom->getClosestCell(point);
286  } else {
287  vdet.detIdECAL = endcapGeom->getClosestCell(point);
288  }
289  vdet.detIdEHCAL = gHB->getClosestCell(point);
290  }
291  info = spr::propagateHCAL (pTrack, bField, debug);
292  vdet.okHCAL = info.second;
293  if (vdet.okHCAL) {
294  const GlobalPoint point(info.first.x(),info.first.y(),info.first.z());
295  vdet.etaHCAL = point.eta();
296  vdet.phiHCAL = point.phi();
297  vdet.detIdHCAL = gHB->getClosestCell(point);
298  }
299 #ifdef EDM_ML_DEBUG
300  if (debug) {
301  std::cout << "propagateCALO:: for 1 track" << std::endl;
302  std::cout << "Track [0] Flag: " << vdet.ok << " ECAL (" << vdet.okECAL << ") ";
303  if (vdet.detIdECAL.subdetId() == EcalBarrel) {
304  std::cout << (EBDetId)(vdet.detIdECAL);
305  } else {
306  std::cout << (EEDetId)(vdet.detIdECAL);
307  }
308  std::cout << " HCAL (" << vdet.okHCAL << ") " << (HcalDetId)(vdet.detIdHCAL) << " Or " << (HcalDetId)(vdet.detIdEHCAL) << std::endl;
309  }
310 #endif
311  return vdet;
312  }
313 
314  std::vector<spr::propagatedGenTrackID> propagateCALO(const HepMC::GenEvent * genEvent, edm::ESHandle<ParticleDataTable>& pdt, const CaloGeometry* geo, const MagneticField* bField, double etaMax, bool debug) {
315 
316  const EcalBarrelGeometry *barrelGeom = (dynamic_cast< const EcalBarrelGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalBarrel)));
317  const EcalEndcapGeometry *endcapGeom = (dynamic_cast< const EcalEndcapGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalEndcap)));
319 
320  std::vector<spr::propagatedGenTrackID> trkDir;
321  unsigned int indx;
322  HepMC::GenEvent::particle_const_iterator p;
323  for (p=genEvent->particles_begin(),indx=0; p != genEvent->particles_end(); ++p,++indx) {
325  trkD.trkItr = p;
326  trkD.detIdECAL = DetId(0);
327  trkD.detIdHCAL = DetId(0);
328  trkD.detIdEHCAL= DetId(0);
329  trkD.pdgId = ((*p)->pdg_id());
330  trkD.charge = ((pdt->particle(trkD.pdgId))->ID().threeCharge())/3;
331  GlobalVector momentum = GlobalVector((*p)->momentum().px(), (*p)->momentum().py(), (*p)->momentum().pz());
332 #ifdef EDM_ML_DEBUG
333  if (debug) std::cout << "Propagate track " << indx << " pdg " << trkD.pdgId << " charge " << trkD.charge << " p " << momentum << std::endl;
334 #endif
335  // consider stable particles
336  if ( (*p)->status()==1 && std::abs((*p)->momentum().eta()) < etaMax ) {
337  GlobalPoint vertex = GlobalPoint(0.1*(*p)->production_vertex()->position().x(),
338  0.1*(*p)->production_vertex()->position().y(),
339  0.1*(*p)->production_vertex()->position().z());
340  trkD.ok = true;
341  spr::propagatedTrack info = spr::propagateCalo (vertex, momentum, trkD.charge, bField, spr::zFrontEE, spr::rFrontEB, spr::etaBEEcal, debug);
342  GlobalPoint point(info.point.x(),info.point.y(),info.point.z());
343  trkD.okECAL = info.ok;
344  trkD.pointECAL = point;
345  trkD.directionECAL = info.direction;
346  if (trkD.okECAL) {
347  if (std::abs(info.point.eta())<spr::etaBEEcal) {
348  trkD.detIdECAL = barrelGeom->getClosestCell(point);
349  } else {
350  trkD.detIdECAL = endcapGeom->getClosestCell(point);
351  }
352  trkD.detIdEHCAL = gHB->getClosestCell(point);
353  }
354 
355  info = spr::propagateCalo (vertex, momentum, trkD.charge, bField, spr::zFrontHE, spr::rFrontHB, spr::etaBEHcal, debug);
356  point = GlobalPoint(info.point.x(),info.point.y(),info.point.z());
357  trkD.okHCAL = info.ok;
358  trkD.pointHCAL = point;
359  trkD.directionHCAL = info.direction;
360  if (trkD.okHCAL) {
361  trkD.detIdHCAL = gHB->getClosestCell(point);
362  }
363  }
364  trkDir.push_back(trkD);
365  }
366 #ifdef EDM_ML_DEBUG
367  if (debug) {
368  std::cout << "propagateCALO:: for " << trkDir.size() << " tracks" << std::endl;
369  for (unsigned int i=0; i<trkDir.size(); ++i) {
370  if (trkDir[i].okECAL) std::cout << "Track [" << i << "] Flag: " << trkDir[i].ok << " ECAL (" << trkDir[i].okECAL << ")";
371  if (trkDir[i].okECAL) {
372  std::cout << " point " << trkDir[i].pointECAL << " direction "
373  << trkDir[i].directionECAL << " ";
374  if (trkDir[i].detIdECAL.subdetId() == EcalBarrel) {
375  std::cout << (EBDetId)(trkDir[i].detIdECAL);
376  } else {
377  std::cout << (EEDetId)(trkDir[i].detIdECAL);
378  }
379  }
380  if (trkDir[i].okECAL) std::cout << " HCAL (" << trkDir[i].okHCAL << ")";
381  if (trkDir[i].okHCAL) {
382  std::cout << " point " << trkDir[i].pointHCAL << " direction "
383  << trkDir[i].directionHCAL << " "
384  << (HcalDetId)(trkDir[i].detIdHCAL);
385  }
386  if (trkDir[i].okECAL) std::cout << " Or " << (HcalDetId)(trkDir[i].detIdEHCAL) << std::endl;
387  }
388  }
389 #endif
390  return trkDir;
391  }
392 
393  std::vector<spr::propagatedGenParticleID> propagateCALO(edm::Handle<reco::GenParticleCollection>& genParticles, edm::ESHandle<ParticleDataTable>& pdt, const CaloGeometry* geo, const MagneticField* bField, double etaMax, bool debug) {
394 
395  const EcalBarrelGeometry *barrelGeom = (dynamic_cast< const EcalBarrelGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalBarrel)));
396  const EcalEndcapGeometry *endcapGeom = (dynamic_cast< const EcalEndcapGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalEndcap)));
398 
399  std::vector<spr::propagatedGenParticleID> trkDir;
400  unsigned int indx;
401  reco::GenParticleCollection::const_iterator p;
402  for (p=genParticles->begin(),indx=0; p != genParticles->end(); ++p,++indx) {
404  trkD.trkItr = p;
405  trkD.detIdECAL = DetId(0);
406  trkD.detIdHCAL = DetId(0);
407  trkD.detIdEHCAL= DetId(0);
408  trkD.pdgId = (p->pdgId());
409  trkD.charge = p->charge();
410  GlobalVector momentum = GlobalVector(p->momentum().x(), p->momentum().y(), p->momentum().z());
411 #ifdef EDM_ML_DEBUG
412  if (debug) std::cout << "Propagate track " << indx << " pdg " << trkD.pdgId << " charge " << trkD.charge << " p " << momentum << std::endl;
413 #endif
414  // consider stable particles
415  if ( p->status()==1 && std::abs(momentum.eta()) < etaMax ) {
416  GlobalPoint vertex = GlobalPoint(p->vertex().x(), p->vertex().y(), p->vertex().z());
417  trkD.ok = true;
418  spr::propagatedTrack info = spr::propagateCalo (vertex, momentum, trkD.charge, bField, spr::zFrontEE, spr::rFrontEB, spr::etaBEEcal, debug);
419  GlobalPoint point(info.point.x(),info.point.y(),info.point.z());
420  trkD.okECAL = info.ok;
421  trkD.pointECAL = point;
422  trkD.directionECAL = info.direction;
423  if (trkD.okECAL) {
424  if (std::abs(info.point.eta())<spr::etaBEEcal) {
425  trkD.detIdECAL = barrelGeom->getClosestCell(point);
426  } else {
427  trkD.detIdECAL = endcapGeom->getClosestCell(point);
428  }
429  trkD.detIdEHCAL = gHB->getClosestCell(point);
430  }
431 
432  info = spr::propagateCalo (vertex, momentum, trkD.charge, bField, spr::zFrontHE, spr::rFrontHB, spr::etaBEHcal, debug);
433  point = GlobalPoint(info.point.x(),info.point.y(),info.point.z());
434  trkD.okHCAL = info.ok;
435  trkD.pointHCAL = point;
436  trkD.directionHCAL = info.direction;
437  if (trkD.okHCAL) {
438  trkD.detIdHCAL = gHB->getClosestCell(point);
439  }
440  }
441  trkDir.push_back(trkD);
442  }
443 #ifdef EDM_ML_DEBUG
444  if (debug) {
445  std::cout << "propagateCALO:: for " << trkDir.size() << " tracks" << std::endl;
446  for (unsigned int i=0; i<trkDir.size(); ++i) {
447  if (trkDir[i].okECAL) std::cout << "Track [" << i << "] Flag: " << trkDir[i].ok << " ECAL (" << trkDir[i].okECAL << ")";
448  if (trkDir[i].okECAL) {
449  std::cout << " point " << trkDir[i].pointECAL << " direction "
450  << trkDir[i].directionECAL << " ";
451  if (trkDir[i].detIdECAL.subdetId() == EcalBarrel) {
452  std::cout << (EBDetId)(trkDir[i].detIdECAL);
453  } else {
454  std::cout << (EEDetId)(trkDir[i].detIdECAL);
455  }
456  }
457  if (trkDir[i].okECAL) std::cout << " HCAL (" << trkDir[i].okHCAL << ")";
458  if (trkDir[i].okHCAL) {
459  std::cout << " point " << trkDir[i].pointHCAL << " direction "
460  << trkDir[i].directionHCAL << " "
461  << (HcalDetId)(trkDir[i].detIdHCAL);
462  }
463  if (trkDir[i].okECAL) std::cout << " Or " << (HcalDetId)(trkDir[i].detIdEHCAL) << std::endl;
464  }
465  }
466 #endif
467  return trkDir;
468  }
469 
471 
472  const EcalBarrelGeometry *barrelGeom = (dynamic_cast< const EcalBarrelGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalBarrel)));
473  const EcalEndcapGeometry *endcapGeom = (dynamic_cast< const EcalEndcapGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalEndcap)));
475 
476  spr::trackAtOrigin trk = spr::simTrackAtOrigin(thisTrk, SimTk, SimVtx, debug);
478  trkD.ok = trk.ok;
479  trkD.detIdECAL = DetId(0);
480  trkD.detIdHCAL = DetId(0);
481  trkD.detIdEHCAL= DetId(0);
482 #ifdef EDM_ML_DEBUG
483  if (debug) std::cout << "Propagate track " << thisTrk << " charge " << trk.charge << " position " << trk.position << " p " << trk.momentum << " Flag " << trkD.ok << std::endl;
484 #endif
485  if (trkD.ok) {
487  GlobalPoint point(info.point.x(),info.point.y(),info.point.z());
488  trkD.okECAL = info.ok;
489  trkD.pointECAL = point;
490  trkD.directionECAL = info.direction;
491  if (trkD.okECAL) {
492  if (std::abs(info.point.eta())<spr::etaBEEcal) {
493  trkD.detIdECAL = barrelGeom->getClosestCell(point);
494  } else {
495  trkD.detIdECAL = endcapGeom->getClosestCell(point);
496  }
497  trkD.detIdEHCAL = gHB->getClosestCell(point);
498  }
499 
500  info = spr::propagateCalo (trk.position, trk.momentum, trk.charge, bField, spr::zFrontHE, spr::rFrontHB, spr::etaBEHcal, debug);
501  point = GlobalPoint(info.point.x(),info.point.y(),info.point.z());
502  trkD.okHCAL = info.ok;
503  trkD.pointHCAL = point;
504  trkD.directionHCAL = info.direction;
505  if (trkD.okHCAL) {
506  trkD.detIdHCAL = gHB->getClosestCell(point);
507  }
508  }
509 #ifdef EDM_ML_DEBUG
510  if (debug) {
511  std::cout << "propagateCALO:: for track [" << thisTrk << "] Flag: " << trkD.ok << " ECAL (" << trkD.okECAL << ") HCAL (" << trkD.okHCAL << ")" << std::endl;
512  if (trkD.okECAL) {
513  std::cout << "ECAL point " << trkD.pointECAL << " direction "
514  << trkD.directionECAL << " ";
515  if (trkD.detIdECAL.subdetId() == EcalBarrel) {
516  std::cout << (EBDetId)(trkD.detIdECAL);
517  } else {
518  std::cout << (EEDetId)(trkD.detIdECAL);
519  }
520  }
521  if (trkD.okHCAL) {
522  std::cout << " HCAL point " << trkD.pointHCAL << " direction "
523  << trkD.directionHCAL << " " << (HcalDetId)(trkD.detIdHCAL);
524  }
525  if (trkD.okECAL) std::cout << " Or " << (HcalDetId)(trkD.detIdEHCAL);
526  std::cout << std::endl;
527  }
528 #endif
529  return trkD;
530  }
531 
533 
535  spr::trackAtOrigin trk = spr::simTrackAtOrigin(thisTrk, SimTk, SimVtx, debug);
537  trkD.ok = trk.ok;
538  trkD.detIdECAL = DetId(0);
539  trkD.detIdHCAL = DetId(0);
540  trkD.detIdEHCAL= DetId(0);
541 #ifdef EDM_ML_DEBUG
542  if (debug) std::cout << "Propagate track " << thisTrk << " charge " << trk.charge << " position " << trk.position << " p " << trk.momentum << " Flag " << trkD.ok << std::endl;
543 #endif
544  if (trkD.ok) {
546  GlobalPoint point = GlobalPoint(info.point.x(),info.point.y(),info.point.z());
547  trkD.okHCAL = info.ok;
548  trkD.pointHCAL = point;
549  trkD.directionHCAL = info.direction;
550  if (trkD.okHCAL) {
551  trkD.detIdHCAL = gHB->getClosestCell(point);
552  }
553  }
554 #ifdef EDM_ML_DEBUG
555  if (debug) {
556  std::cout << "propagateCALO:: for track [" << thisTrk << "] Flag: " << trkD.ok << " ECAL (" << trkD.okECAL << ") HCAL (" << trkD.okHCAL << ")" << std::endl;
557  if (trkD.okHCAL) {
558  std::cout << " HCAL point " << trkD.pointHCAL << " direction "
559  << trkD.directionHCAL << " " << (HcalDetId)(trkD.detIdHCAL);
560  }
561  }
562 #endif
563  return trkD;
564  }
565 
566 
567  std::pair<bool,HcalDetId> propagateHCALBack(const reco::Track* track, const CaloGeometry* geo, const MagneticField* bField, bool debug) {
569  GlobalPoint vertex (track->vx(), track->vy(), track->vz());
570  GlobalVector momentum (track->px(), track->py(), track->pz());
571  int charge (track->charge());
573  if (info.ok) {
574  const GlobalPoint point = GlobalPoint(info.point.x(),info.point.y(),info.point.z());
575  return std::pair<bool,HcalDetId>(true,HcalDetId(gHB->getClosestCell(point)));
576  } else {
577  return std::pair<bool,HcalDetId>(false,HcalDetId());
578  }
579  }
580 
582  GlobalPoint vertex (track->vx(), track->vy(), track->vz());
583  GlobalVector momentum (track->px(), track->py(), track->pz());
584  int charge (track->charge());
585  return spr::propagateCalo (vertex, momentum, charge, bfield, spr::zFrontEE, spr::rFrontEB, spr::etaBEEcal, debug);
586  }
587 
589 
590  spr::trackAtOrigin trk = spr::simTrackAtOrigin(thisTrk, SimTk, SimVtx, debug);
592  if (trk.ok)
593  ptrk = spr::propagateCalo (trk.position, trk.momentum, trk.charge, bfield, spr::zFrontEE, spr::rFrontEB, spr::etaBEEcal, debug);
594  return ptrk;
595  }
596 
597  std::pair<math::XYZPoint,bool> propagateECAL(const reco::Track *track, const MagneticField* bfield, bool debug) {
598  GlobalPoint vertex (track->vx(), track->vy(), track->vz());
599  GlobalVector momentum (track->px(), track->py(), track->pz());
600  int charge (track->charge());
601  return spr::propagateECAL (vertex, momentum, charge, bfield, debug);
602  }
603 
604  std::pair<math::XYZPoint,bool> propagateECAL(const GlobalPoint& vertex, const GlobalVector& momentum, int charge, const MagneticField* bfield, bool debug) {
605  spr::propagatedTrack track = spr::propagateCalo (vertex, momentum, charge, bfield, spr::zFrontEE, spr::rFrontEB, spr::etaBEEcal, debug);
606  return std::pair<math::XYZPoint,bool>(track.point,track.ok);
607  }
608 
610  GlobalPoint vertex (track->vx(), track->vy(), track->vz());
611  GlobalVector momentum (track->px(), track->py(), track->pz());
612  int charge (track->charge());
613  return spr::propagateCalo (vertex, momentum, charge, bfield, spr::zFrontHE, spr::rFrontHB, spr::etaBEHcal, debug);
614  }
615 
617  spr::trackAtOrigin trk = spr::simTrackAtOrigin(thisTrk, SimTk, SimVtx, debug);
619  if (trk.ok)
620  ptrk = spr::propagateCalo (trk.position, trk.momentum, trk.charge, bfield, spr::zFrontHE, spr::rFrontHB, spr::etaBEHcal, debug);
621  return ptrk;
622  }
623 
624  std::pair<math::XYZPoint,bool> propagateHCAL(const reco::Track *track, const MagneticField* bfield, bool debug) {
625  GlobalPoint vertex (track->vx(), track->vy(), track->vz());
626  GlobalVector momentum (track->px(), track->py(), track->pz());
627  int charge (track->charge());
628  return spr::propagateHCAL (vertex, momentum, charge, bfield, debug);
629  }
630 
631  std::pair<math::XYZPoint,bool> propagateHCAL(const GlobalPoint& vertex, const GlobalVector& momentum, int charge, const MagneticField* bfield, bool debug) {
632  spr::propagatedTrack track = spr::propagateCalo (vertex, momentum, charge, bfield, spr::zFrontHE, spr::rFrontHB, spr::etaBEHcal, debug);
633  return std::pair<math::XYZPoint,bool>(track.point,track.ok);
634  }
635 
636  std::pair<math::XYZPoint,bool> propagateTracker(const reco::Track *track, const MagneticField* bfield, bool debug) {
637  GlobalPoint vertex (track->vx(), track->vy(), track->vz());
638  GlobalVector momentum (track->px(), track->py(), track->pz());
639  int charge (track->charge());
640  spr::propagatedTrack track1 = spr::propagateCalo (vertex, momentum, charge, bfield, spr::zBackTE, spr::rBackTB, spr::etaBETrak, debug);
641  return std::pair<math::XYZPoint,bool>(track1.point,track1.ok);
642  }
643 
644  std::pair<math::XYZPoint,double> propagateTrackerEnd(const reco::Track *track,
645  const MagneticField* bField, bool
646 #ifdef EDM_ML_DEBUG
647  debug
648 #endif
649  ) {
650 
651  GlobalPoint vertex (track->vx(), track->vy(), track->vz());
652  GlobalVector momentum (track->px(), track->py(), track->pz());
653  int charge (track->charge());
654  float radius = track->outerPosition().Rho();
655  float zdist = track->outerPosition().Z();
656 #ifdef EDM_ML_DEBUG
657  if (debug) std::cout << "propagateTrackerEnd:: Vertex " << vertex << " Momentum " << momentum << " Charge " << charge << " Radius " << radius << " Z " << zdist << std::endl;
658 #endif
659  FreeTrajectoryState fts (vertex, momentum, charge, bField);
662 
663  AnalyticalPropagator myAP (bField, alongMomentum, 2*M_PI);
664 
665  TrajectoryStateOnSurface tsose = myAP.propagate(fts, *endcap);
666  TrajectoryStateOnSurface tsosb = myAP.propagate(fts, *barrel);
667 
668  math::XYZPoint point(-999.,-999.,-999.);
669  bool ok=false;
670  GlobalVector direction(0,0,1);
671  if (tsosb.isValid() && std::abs(zdist) < spr::zFrontTE) {
672  point.SetXYZ(tsosb.globalPosition().x(), tsosb.globalPosition().y(), tsosb.globalPosition().z());
673  direction = tsosb.globalDirection();
674  ok = true;
675  } else if (tsose.isValid()) {
676  point.SetXYZ(tsose.globalPosition().x(), tsose.globalPosition().y(), tsose.globalPosition().z());
677  direction = tsose.globalDirection();
678  ok = true;
679  }
680 
681  double length = -1;
682  if (ok) {
683  math::XYZPoint vDiff(point.x()-vertex.x(), point.y()-vertex.y(), point.z()-vertex.z());
684  double dphi = direction.phi()-momentum.phi();
685  double rdist = std::sqrt(vDiff.x()*vDiff.x()+vDiff.y()*vDiff.y());
686  double rat = 0.5*dphi/std::sin(0.5*dphi);
687  double dZ = vDiff.z();
688  double dS = rdist*rat; //dZ*momentum.z()/momentum.perp();
689  length = std::sqrt(dS*dS+dZ*dZ);
690 #ifdef EDM_ML_DEBUG
691  if (debug)
692  std::cout << "propagateTracker:: Barrel " << tsosb.isValid() << " Endcap " << tsose.isValid() << " OverAll " << ok << " Point " << point << " RDist " << rdist << " dS " << dS << " dS/pt " << rdist*rat/momentum.perp() << " zdist " << dZ << " dz/pz " << dZ/momentum.z() << " Length " << length << std::endl;
693 #endif
694  }
695 
696  return std::pair<math::XYZPoint,double>(point,length);
697  }
698 
700  const GlobalVector& tpMomentum,
701  int tpCharge, const MagneticField* bField,
702  float zdist, float radius, float corner, bool
703 #ifdef EDM_ML_DEBUG
704  debug
705 #endif
706  ) {
707 
709 #ifdef EDM_ML_DEBUG
710  if (debug) std::cout << "propagateCalo:: Vertex " << tpVertex << " Momentum " << tpMomentum << " Charge " << tpCharge << " Radius " << radius << " Z " << zdist << " Corner " << corner << std::endl;
711 #endif
712  FreeTrajectoryState fts (tpVertex, tpMomentum, tpCharge, bField);
713 
716 
718 
719  AnalyticalPropagator myAP (bField, alongMomentum, 2*M_PI);
720 
722  if (tpMomentum.eta() < 0) {
723  tsose = myAP.propagate(fts, *lendcap);
724  } else {
725  tsose = myAP.propagate(fts, *rendcap);
726  }
727 
728  TrajectoryStateOnSurface tsosb = myAP.propagate(fts, *barrel);
729 
730  track.ok=true;
731  if (tsose.isValid() && tsosb.isValid()) {
732  float absEta = std::abs(tsosb.globalPosition().eta());
733  if (absEta < corner) {
734  track.point.SetXYZ(tsosb.globalPosition().x(), tsosb.globalPosition().y(), tsosb.globalPosition().z());
735  track.direction = tsosb.globalDirection();
736  } else {
737  track.point.SetXYZ(tsose.globalPosition().x(), tsose.globalPosition().y(), tsose.globalPosition().z());
738  track.direction = tsose.globalDirection();
739  }
740  } else if (tsose.isValid()) {
741  track.point.SetXYZ(tsose.globalPosition().x(), tsose.globalPosition().y(), tsose.globalPosition().z());
742  track.direction = tsose.globalDirection();
743  } else if (tsosb.isValid()) {
744  track.point.SetXYZ(tsosb.globalPosition().x(), tsosb.globalPosition().y(), tsosb.globalPosition().z());
745  track.direction = tsosb.globalDirection();
746  } else {
747  track.point.SetXYZ(-999., -999., -999.);
748  track.direction = GlobalVector(0,0,1);
749  track.ok = false;
750  }
751 #ifdef EDM_ML_DEBUG
752  if (debug) {
753  std::cout << "propagateCalo:: Barrel " << tsosb.isValid() << " Endcap " << tsose.isValid() << " OverAll " << track.ok << " Point " << track.point << " Direction " << track.direction << std::endl;
754  if (track.ok) {
755  math::XYZPoint vDiff(track.point.x()-tpVertex.x(), track.point.y()-tpVertex.y(), track.point.z()-tpVertex.z());
756  double dphi = track.direction.phi()-tpMomentum.phi();
757  double rdist = std::sqrt(vDiff.x()*vDiff.x()+vDiff.y()*vDiff.y());
758  double pt = tpMomentum.perp();
759  double rat = 0.5*dphi/std::sin(0.5*dphi);
760  std::cout << "RDist " << rdist << " pt " << pt << " r/pt " << rdist*rat/pt << " zdist " << vDiff.z() << " pz " << tpMomentum.z() << " z/pz " << vDiff.z()/tpMomentum.z() << std::endl;
761  }
762  }
763 #endif
764  return track;
765  }
766 
767  spr::trackAtOrigin simTrackAtOrigin(unsigned int thisTrk,
770 #ifdef EDM_ML_DEBUG
771  debug
772 #endif
773  ) {
774 
775  spr::trackAtOrigin trk;
776 
777  edm::SimTrackContainer::const_iterator itr = SimTk->end();
778  for (edm::SimTrackContainer::const_iterator simTrkItr = SimTk->begin(); simTrkItr!= SimTk->end(); simTrkItr++) {
779  if ( simTrkItr->trackId() == thisTrk ) {
780 #ifdef EDM_ML_DEBUG
781  if (debug) std::cout << "matched trackId (maximum occurance) " << thisTrk << " type " << simTrkItr->type() << std::endl;
782 #endif
783  itr = simTrkItr;
784  break;
785  }
786  }
787 
788  if (itr != SimTk->end()) {
789  int vertIndex = itr->vertIndex();
790  if (vertIndex != -1 && vertIndex < (int)SimVtx->size()) {
791  edm::SimVertexContainer::const_iterator simVtxItr= SimVtx->begin();
792  for (int iv=0; iv<vertIndex; iv++) simVtxItr++;
793  const math::XYZTLorentzVectorD pos = simVtxItr->position();
794  const math::XYZTLorentzVectorD mom = itr->momentum();
795  trk.ok = true;
796  trk.charge = (int)(itr->charge());
797  trk.position = GlobalPoint(pos.x(), pos.y(), pos.z());
798  trk.momentum = GlobalVector(mom.x(), mom.y(), mom.z());
799  }
800  }
801 #ifdef EDM_ML_DEBUG
802  if (debug) std::cout << "Track flag " << trk.ok << " Position " << trk.position << " Momentum " << trk.momentum << std::endl;
803 #endif
804  return trk;
805  }
806 
807 }
double p() const
momentum vector magnitude
Definition: TrackBase.h:615
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:45
static const double etaBEEcal
Definition: CaloConstants.h:12
static const TGPicture * info(bool iBackgroundIsBlack)
#define EDM_ML_DEBUG
std::vector< spr::propagatedTrackID > propagateCALO(edm::Handle< reco::TrackCollection > &trkCollection, const CaloGeometry *geo, const MagneticField *bField, std::string &theTrackQuality, bool debug=false)
T perp() const
Definition: PV3DBase.h:72
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
DetId getClosestCell(const GlobalPoint &r) const override
static const double zBackTE
Definition: CaloConstants.h:21
static const double etaBEHcal
Definition: CaloConstants.h:15
reco::GenParticleCollection::const_iterator trkItr
TrackQuality
track quality
Definition: TrackBase.h:151
std::pair< math::XYZPoint, bool > propagateHCAL(const reco::Track *, const MagneticField *, bool debug=false)
static const double zFrontHE
Definition: CaloConstants.h:13
uint32_t ID
Definition: Definitions.h:26
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:63
#define X(str)
Definition: MuonsGrabber.cc:48
GlobalPoint globalPosition() const
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:645
spr::trackAtOrigin simTrackAtOrigin(unsigned int thisTrk, edm::Handle< edm::SimTrackContainer > &SimTk, edm::Handle< edm::SimVertexContainer > &SimVtx, bool debug=false)
static const double zBackHE
Definition: CaloConstants.h:16
spr::propagatedTrack propagateCalo(const GlobalPoint &vertex, const GlobalVector &momentum, int charge, const MagneticField *, float zdist, float radius, float corner, bool debug=false)
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:627
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:65
static const double rFrontHB
Definition: CaloConstants.h:14
genEvent
Definition: MCTruth.py:33
HepMC::GenEvent::particle_const_iterator trkItr
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:55
static const double rBackHB
Definition: CaloConstants.h:17
static CylinderPointer build(const PositionType &pos, const RotationType &rot, Scalar radius, Bounds *bounds=0)
Definition: Cylinder.h:51
reco::TrackCollection::const_iterator trkItr
static const double zFrontEE
Definition: CaloConstants.h:9
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:651
static const double rBackTB
Definition: CaloConstants.h:22
spr::propagatedTrackDirection propagateHCALBack(unsigned int thisTrk, edm::Handle< edm::SimTrackContainer > &SimTk, edm::Handle< edm::SimVertexContainer > &SimVtx, const CaloGeometry *geo, const MagneticField *bField, bool debug=false)
T sqrt(T t)
Definition: SSEVec.h:18
T phi() const
Definition: Phi.h:41
static PlanePointer build(Args &&...args)
Definition: Plane.h:33
T z() const
Definition: PV3DBase.h:64
static const double rFrontEB
Definition: CaloConstants.h:10
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::pair< math::XYZPoint, bool > propagateTracker(const reco::Track *, const MagneticField *, bool debug=false)
std::pair< math::XYZPoint, bool > propagateECAL(const reco::Track *, const MagneticField *, bool debug=false)
spr::propagatedTrack propagateTrackToECAL(const reco::Track *, const MagneticField *, bool debug=false)
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
#define M_PI
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:639
virtual DetId getClosestCell(const GlobalPoint &r) const
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:669
Definition: DetId.h:18
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:125
#define debug
Definition: HDRShower.cc:19
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:70
static const double zFrontTE
Definition: CaloConstants.h:20
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:53
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:510
T eta() const
Definition: PV3DBase.h:76
double vy() const
y coordinate of the reference point on track
Definition: TrackBase.h:663
std::pair< math::XYZPoint, double > propagateTrackerEnd(const reco::Track *, const MagneticField *, bool debug=false)
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:60
std::vector< spr::propagatedTrackID > propagateCosmicCALO(edm::Handle< reco::TrackCollection > &trkCollection, const CaloGeometry *geo, const MagneticField *bField, std::string &theTrackQuality, bool debug=false)
reco::TrackCollection::const_iterator trkItr
int charge() const
track electric charge
Definition: TrackBase.h:567
DetId getClosestCell(const GlobalPoint &r) const override
T x() const
Definition: PV3DBase.h:62
spr::propagatedTrack propagateTrackToHCAL(const reco::Track *, const MagneticField *, bool debug=false)
static const double etaBETrak
Definition: CaloConstants.h:23
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:633
double vx() const
x coordinate of the reference point on track
Definition: TrackBase.h:657
Global3DVector GlobalVector
Definition: GlobalVector.h:10
GlobalVector globalDirection() const