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 
180 #ifdef EDM_ML_DEBUG
181  if (debug) {
182  std::cout << "propagateCALO:: for " << vdets.size() << " tracks" << std::endl;
183  for (unsigned int i=0; i<vdets.size(); ++i) {
184  std::cout << "Track [" << i << "] Flag: " << vdets[i].ok << " ECAL (" << vdets[i].okECAL << ") ";
185  if (vdets[i].detIdECAL.subdetId() == EcalBarrel) {
186  std::cout << (EBDetId)(vdets[i].detIdECAL);
187  } else {
188  std::cout << (EEDetId)(vdets[i].detIdECAL);
189  }
190  std::cout << " HCAL (" << vdets[i].okHCAL << ") " << (HcalDetId)(vdets[i].detIdHCAL) << " Or " << (HcalDetId)(vdets[i].detIdEHCAL) << std::endl;
191  }
192  }
193 #endif
194  }
195 
196  void propagateCALO(edm::Handle<reco::TrackCollection>& trkCollection, const CaloGeometry* geo, const MagneticField* bField, std::string & theTrackQuality, std::vector<spr::propagatedTrackDirection>& trkDir, bool debug) {
197 
198  const EcalBarrelGeometry *barrelGeom = (dynamic_cast< const EcalBarrelGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalBarrel)));
199  const EcalEndcapGeometry *endcapGeom = (dynamic_cast< const EcalEndcapGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalEndcap)));
201  reco::TrackBase::TrackQuality trackQuality_=reco::TrackBase::qualityByName(theTrackQuality);
202 
203  unsigned int indx;
204  reco::TrackCollection::const_iterator trkItr;
205  for (trkItr = trkCollection->begin(),indx=0; trkItr != trkCollection->end(); ++trkItr,indx++) {
206  const reco::Track* pTrack = &(*trkItr);
208  trkD.trkItr = trkItr;
209  trkD.ok = (pTrack->quality(trackQuality_));
210  trkD.detIdECAL = DetId(0);
211  trkD.detIdHCAL = DetId(0);
212  trkD.detIdEHCAL= DetId(0);
213 #ifdef EDM_ML_DEBUG
214  if (debug) std::cout << "Propagate track " << indx << " p " << trkItr->p() << " eta " << trkItr->eta() << " phi " << trkItr->phi() << " Flag " << trkD.ok << std::endl;
215 #endif
216  spr::propagatedTrack info = spr::propagateTrackToECAL (pTrack, bField, debug);
217  GlobalPoint point(info.point.x(),info.point.y(),info.point.z());
218  trkD.okECAL = info.ok;
219  trkD.pointECAL = point;
220  trkD.directionECAL = info.direction;
221  if (trkD.okECAL) {
222  if (std::abs(info.point.eta())<spr::etaBEEcal) {
223  trkD.detIdECAL = barrelGeom->getClosestCell(point);
224  } else {
225  trkD.detIdECAL = endcapGeom->getClosestCell(point);
226  }
227  trkD.detIdEHCAL = gHB->getClosestCell(point);
228  }
229  info = spr::propagateTrackToHCAL (pTrack, bField, debug);
230  point = GlobalPoint(info.point.x(),info.point.y(),info.point.z());
231  trkD.okHCAL = info.ok;
232  trkD.pointHCAL = point;
233  trkD.directionHCAL = info.direction;
234  if (trkD.okHCAL) {
235  trkD.detIdHCAL = gHB->getClosestCell(point);
236  }
237  trkDir.push_back(trkD);
238  }
239 
240 #ifdef EDM_ML_DEBUG
241  if (debug) {
242  std::cout << "propagateCALO:: for " << trkDir.size() << " tracks" << std::endl;
243  for (unsigned int i=0; i<trkDir.size(); ++i) {
244  std::cout << "Track [" << i << "] Flag: " << trkDir[i].ok << " ECAL (" << trkDir[i].okECAL << ")";
245  if (trkDir[i].okECAL) {
246  std::cout << " point " << trkDir[i].pointECAL << " direction "
247  << trkDir[i].directionECAL << " ";
248  if (trkDir[i].detIdECAL.subdetId() == EcalBarrel) {
249  std::cout << (EBDetId)(trkDir[i].detIdECAL);
250  } else {
251  std::cout << (EEDetId)(trkDir[i].detIdECAL);
252  }
253  }
254  std::cout << " HCAL (" << trkDir[i].okHCAL << ")";
255  if (trkDir[i].okHCAL) {
256  std::cout << " point " << trkDir[i].pointHCAL << " direction "
257  << trkDir[i].directionHCAL << " "
258  << (HcalDetId)(trkDir[i].detIdHCAL);
259  }
260  std::cout << " Or " << (HcalDetId)(trkDir[i].detIdEHCAL) << std::endl;
261  }
262  }
263 #endif
264  }
265 
267 
268  const EcalBarrelGeometry *barrelGeom = (dynamic_cast< const EcalBarrelGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalBarrel)));
269  const EcalEndcapGeometry *endcapGeom = (dynamic_cast< const EcalEndcapGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalEndcap)));
271 
273  vdet.ok = true;
274  vdet.detIdECAL = DetId(0);
275  vdet.detIdHCAL = DetId(0);
276  vdet.detIdEHCAL= DetId(0);
277 #ifdef EDM_ML_DEBUG
278  if (debug) std::cout << "Propagate track: p " << pTrack->p() << " eta " << pTrack->eta() << " phi " << pTrack->phi() << " Flag " << vdet.ok << std::endl;
279 #endif
280  std::pair<math::XYZPoint,bool> info = spr::propagateECAL (pTrack, bField, debug);
281  vdet.okECAL = info.second;
282  if (vdet.okECAL) {
283  const GlobalPoint point(info.first.x(),info.first.y(),info.first.z());
284  vdet.etaECAL = point.eta();
285  vdet.phiECAL = point.phi();
286  if (std::abs(point.eta())<spr::etaBEEcal) {
287  vdet.detIdECAL = barrelGeom->getClosestCell(point);
288  } else {
289  vdet.detIdECAL = endcapGeom->getClosestCell(point);
290  }
291  vdet.detIdEHCAL = gHB->getClosestCell(point);
292  }
293  info = spr::propagateHCAL (pTrack, bField, debug);
294  vdet.okHCAL = info.second;
295  if (vdet.okHCAL) {
296  const GlobalPoint point(info.first.x(),info.first.y(),info.first.z());
297  vdet.etaHCAL = point.eta();
298  vdet.phiHCAL = point.phi();
299  vdet.detIdHCAL = gHB->getClosestCell(point);
300  }
301 
302 #ifdef EDM_ML_DEBUG
303  if (debug) {
304  std::cout << "propagateCALO:: for 1 track" << std::endl;
305  std::cout << "Track [0] Flag: " << vdet.ok << " ECAL (" << vdet.okECAL << ") ";
306  if (vdet.detIdECAL.subdetId() == EcalBarrel) {
307  std::cout << (EBDetId)(vdet.detIdECAL);
308  } else {
309  std::cout << (EEDetId)(vdet.detIdECAL);
310  }
311  std::cout << " HCAL (" << vdet.okHCAL << ") " << (HcalDetId)(vdet.detIdHCAL) << " Or " << (HcalDetId)(vdet.detIdEHCAL) << std::endl;
312  }
313 #endif
314  return vdet;
315  }
316 
317  std::vector<spr::propagatedGenTrackID> propagateCALO(const HepMC::GenEvent * genEvent, edm::ESHandle<ParticleDataTable>& pdt, const CaloGeometry* geo, const MagneticField* bField, double etaMax, bool debug) {
318 
319  const EcalBarrelGeometry *barrelGeom = (dynamic_cast< const EcalBarrelGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalBarrel)));
320  const EcalEndcapGeometry *endcapGeom = (dynamic_cast< const EcalEndcapGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalEndcap)));
322 
323  std::vector<spr::propagatedGenTrackID> trkDir;
324  unsigned int indx;
325  HepMC::GenEvent::particle_const_iterator p;
326  for (p=genEvent->particles_begin(),indx=0; p != genEvent->particles_end(); ++p,++indx) {
328  trkD.trkItr = p;
329  trkD.detIdECAL = DetId(0);
330  trkD.detIdHCAL = DetId(0);
331  trkD.detIdEHCAL= DetId(0);
332  trkD.pdgId = ((*p)->pdg_id());
333  trkD.charge = ((pdt->particle(trkD.pdgId))->ID().threeCharge())/3;
334  GlobalVector momentum = GlobalVector((*p)->momentum().px(), (*p)->momentum().py(), (*p)->momentum().pz());
335 #ifdef EDM_ML_DEBUG
336  if (debug) std::cout << "Propagate track " << indx << " pdg " << trkD.pdgId << " charge " << trkD.charge << " p " << momentum << std::endl;
337 #endif
338  // consider stable particles
339  if ( (*p)->status()==1 && std::abs((*p)->momentum().eta()) < etaMax ) {
340  GlobalPoint vertex = GlobalPoint(0.1*(*p)->production_vertex()->position().x(),
341  0.1*(*p)->production_vertex()->position().y(),
342  0.1*(*p)->production_vertex()->position().z());
343  trkD.ok = true;
344  spr::propagatedTrack info = spr::propagateCalo (vertex, momentum, trkD.charge, bField, spr::zFrontEE, spr::rFrontEB, spr::etaBEEcal, debug);
345  GlobalPoint point(info.point.x(),info.point.y(),info.point.z());
346  trkD.okECAL = info.ok;
347  trkD.pointECAL = point;
348  trkD.directionECAL = info.direction;
349  if (trkD.okECAL) {
350  if (std::abs(info.point.eta())<spr::etaBEEcal) {
351  trkD.detIdECAL = barrelGeom->getClosestCell(point);
352  } else {
353  trkD.detIdECAL = endcapGeom->getClosestCell(point);
354  }
355  trkD.detIdEHCAL = gHB->getClosestCell(point);
356  }
357 
358  info = spr::propagateCalo (vertex, momentum, trkD.charge, bField, spr::zFrontHE, spr::rFrontHB, spr::etaBEHcal, debug);
359  point = GlobalPoint(info.point.x(),info.point.y(),info.point.z());
360  trkD.okHCAL = info.ok;
361  trkD.pointHCAL = point;
362  trkD.directionHCAL = info.direction;
363  if (trkD.okHCAL) {
364  trkD.detIdHCAL = gHB->getClosestCell(point);
365  }
366  }
367  trkDir.push_back(trkD);
368  }
369 
370 #ifdef EDM_ML_DEBUG
371  if (debug) {
372  std::cout << "propagateCALO:: for " << trkDir.size() << " tracks" << std::endl;
373  for (unsigned int i=0; i<trkDir.size(); ++i) {
374  if (trkDir[i].okECAL) std::cout << "Track [" << i << "] Flag: " << trkDir[i].ok << " ECAL (" << trkDir[i].okECAL << ")";
375  if (trkDir[i].okECAL) {
376  std::cout << " point " << trkDir[i].pointECAL << " direction "
377  << trkDir[i].directionECAL << " ";
378  if (trkDir[i].detIdECAL.subdetId() == EcalBarrel) {
379  std::cout << (EBDetId)(trkDir[i].detIdECAL);
380  } else {
381  std::cout << (EEDetId)(trkDir[i].detIdECAL);
382  }
383  }
384  if (trkDir[i].okECAL) std::cout << " HCAL (" << trkDir[i].okHCAL << ")";
385  if (trkDir[i].okHCAL) {
386  std::cout << " point " << trkDir[i].pointHCAL << " direction "
387  << trkDir[i].directionHCAL << " "
388  << (HcalDetId)(trkDir[i].detIdHCAL);
389  }
390  if (trkDir[i].okECAL) std::cout << " Or " << (HcalDetId)(trkDir[i].detIdEHCAL) << std::endl;
391  }
392  }
393 #endif
394  return trkDir;
395  }
396 
397  std::vector<spr::propagatedGenParticleID> propagateCALO(edm::Handle<reco::GenParticleCollection>& genParticles, edm::ESHandle<ParticleDataTable>& pdt, const CaloGeometry* geo, const MagneticField* bField, double etaMax, bool debug) {
398 
399  const EcalBarrelGeometry *barrelGeom = (dynamic_cast< const EcalBarrelGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalBarrel)));
400  const EcalEndcapGeometry *endcapGeom = (dynamic_cast< const EcalEndcapGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalEndcap)));
402 
403  std::vector<spr::propagatedGenParticleID> trkDir;
404  unsigned int indx;
405  reco::GenParticleCollection::const_iterator p;
406  for (p=genParticles->begin(),indx=0; p != genParticles->end(); ++p,++indx) {
408  trkD.trkItr = p;
409  trkD.detIdECAL = DetId(0);
410  trkD.detIdHCAL = DetId(0);
411  trkD.detIdEHCAL= DetId(0);
412  trkD.pdgId = (p->pdgId());
413  trkD.charge = p->charge();
414  GlobalVector momentum = GlobalVector(p->momentum().x(), p->momentum().y(), p->momentum().z());
415 #ifdef EDM_ML_DEBUG
416  if (debug) std::cout << "Propagate track " << indx << " pdg " << trkD.pdgId << " charge " << trkD.charge << " p " << momentum << std::endl;
417 #endif
418  // consider stable particles
419  if ( p->status()==1 && std::abs(momentum.eta()) < etaMax ) {
420  GlobalPoint vertex = GlobalPoint(p->vertex().x(), p->vertex().y(), p->vertex().z());
421  trkD.ok = true;
422  spr::propagatedTrack info = spr::propagateCalo (vertex, momentum, trkD.charge, bField, spr::zFrontEE, spr::rFrontEB, spr::etaBEEcal, debug);
423  GlobalPoint point(info.point.x(),info.point.y(),info.point.z());
424  trkD.okECAL = info.ok;
425  trkD.pointECAL = point;
426  trkD.directionECAL = info.direction;
427  if (trkD.okECAL) {
428  if (std::abs(info.point.eta())<spr::etaBEEcal) {
429  trkD.detIdECAL = barrelGeom->getClosestCell(point);
430  } else {
431  trkD.detIdECAL = endcapGeom->getClosestCell(point);
432  }
433  trkD.detIdEHCAL = gHB->getClosestCell(point);
434  }
435 
436  info = spr::propagateCalo (vertex, momentum, trkD.charge, bField, spr::zFrontHE, spr::rFrontHB, spr::etaBEHcal, debug);
437  point = GlobalPoint(info.point.x(),info.point.y(),info.point.z());
438  trkD.okHCAL = info.ok;
439  trkD.pointHCAL = point;
440  trkD.directionHCAL = info.direction;
441  if (trkD.okHCAL) {
442  trkD.detIdHCAL = gHB->getClosestCell(point);
443  }
444  }
445  trkDir.push_back(trkD);
446  }
447 
448 #ifdef EDM_ML_DEBUG
449  if (debug) {
450  std::cout << "propagateCALO:: for " << trkDir.size() << " tracks" << std::endl;
451  for (unsigned int i=0; i<trkDir.size(); ++i) {
452  if (trkDir[i].okECAL) std::cout << "Track [" << i << "] Flag: " << trkDir[i].ok << " ECAL (" << trkDir[i].okECAL << ")";
453  if (trkDir[i].okECAL) {
454  std::cout << " point " << trkDir[i].pointECAL << " direction "
455  << trkDir[i].directionECAL << " ";
456  if (trkDir[i].detIdECAL.subdetId() == EcalBarrel) {
457  std::cout << (EBDetId)(trkDir[i].detIdECAL);
458  } else {
459  std::cout << (EEDetId)(trkDir[i].detIdECAL);
460  }
461  }
462  if (trkDir[i].okECAL) std::cout << " HCAL (" << trkDir[i].okHCAL << ")";
463  if (trkDir[i].okHCAL) {
464  std::cout << " point " << trkDir[i].pointHCAL << " direction "
465  << trkDir[i].directionHCAL << " "
466  << (HcalDetId)(trkDir[i].detIdHCAL);
467  }
468  if (trkDir[i].okECAL) std::cout << " Or " << (HcalDetId)(trkDir[i].detIdEHCAL) << std::endl;
469  }
470  }
471 #endif
472  return trkDir;
473  }
474 
476 
477  const EcalBarrelGeometry *barrelGeom = (dynamic_cast< const EcalBarrelGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalBarrel)));
478  const EcalEndcapGeometry *endcapGeom = (dynamic_cast< const EcalEndcapGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalEndcap)));
480 
481  spr::trackAtOrigin trk = spr::simTrackAtOrigin(thisTrk, SimTk, SimVtx, debug);
483  trkD.ok = trk.ok;
484  trkD.detIdECAL = DetId(0);
485  trkD.detIdHCAL = DetId(0);
486  trkD.detIdEHCAL= DetId(0);
487 #ifdef EDM_ML_DEBUG
488  if (debug) std::cout << "Propagate track " << thisTrk << " charge " << trk.charge << " position " << trk.position << " p " << trk.momentum << " Flag " << trkD.ok << std::endl;
489 #endif
490  if (trkD.ok) {
492  GlobalPoint point(info.point.x(),info.point.y(),info.point.z());
493  trkD.okECAL = info.ok;
494  trkD.pointECAL = point;
495  trkD.directionECAL = info.direction;
496  if (trkD.okECAL) {
497  if (std::abs(info.point.eta())<spr::etaBEEcal) {
498  trkD.detIdECAL = barrelGeom->getClosestCell(point);
499  } else {
500  trkD.detIdECAL = endcapGeom->getClosestCell(point);
501  }
502  trkD.detIdEHCAL = gHB->getClosestCell(point);
503  }
504 
505  info = spr::propagateCalo (trk.position, trk.momentum, trk.charge, bField, spr::zFrontHE, spr::rFrontHB, spr::etaBEHcal, debug);
506  point = GlobalPoint(info.point.x(),info.point.y(),info.point.z());
507  trkD.okHCAL = info.ok;
508  trkD.pointHCAL = point;
509  trkD.directionHCAL = info.direction;
510  if (trkD.okHCAL) {
511  trkD.detIdHCAL = gHB->getClosestCell(point);
512  }
513  }
514 
515 #ifdef EDM_ML_DEBUG
516  if (debug) {
517  std::cout << "propagateCALO:: for track [" << thisTrk << "] Flag: " << trkD.ok << " ECAL (" << trkD.okECAL << ") HCAL (" << trkD.okHCAL << ")" << std::endl;
518  if (trkD.okECAL) {
519  std::cout << "ECAL point " << trkD.pointECAL << " direction "
520  << trkD.directionECAL << " ";
521  if (trkD.detIdECAL.subdetId() == EcalBarrel) {
522  std::cout << (EBDetId)(trkD.detIdECAL);
523  } else {
524  std::cout << (EEDetId)(trkD.detIdECAL);
525  }
526  }
527  if (trkD.okHCAL) {
528  std::cout << " HCAL point " << trkD.pointHCAL << " direction "
529  << trkD.directionHCAL << " " << (HcalDetId)(trkD.detIdHCAL);
530  }
531  if (trkD.okECAL) std::cout << " Or " << (HcalDetId)(trkD.detIdEHCAL);
532  std::cout << std::endl;
533  }
534 #endif
535  return trkD;
536  }
537 
538  std::pair<bool,HcalDetId> propagateHCALBack(const reco::Track* track, const CaloGeometry* geo, const MagneticField* bField, bool debug) {
540  GlobalPoint vertex (track->vx(), track->vy(), track->vz());
541  GlobalVector momentum (track->px(), track->py(), track->pz());
542  int charge (track->charge());
544  if (info.ok) {
545  const GlobalPoint point = GlobalPoint(info.point.x(),info.point.y(),info.point.z());
546  return std::pair<bool,HcalDetId>(true,HcalDetId(gHB->getClosestCell(point)));
547  } else {
548  return std::pair<bool,HcalDetId>(false,HcalDetId());
549  }
550  }
551 
553  GlobalPoint vertex (track->vx(), track->vy(), track->vz());
554  GlobalVector momentum (track->px(), track->py(), track->pz());
555  int charge (track->charge());
556  return spr::propagateCalo (vertex, momentum, charge, bfield, spr::zFrontEE, spr::rFrontEB, spr::etaBEEcal, debug);
557  }
558 
560 
561  spr::trackAtOrigin trk = spr::simTrackAtOrigin(thisTrk, SimTk, SimVtx, debug);
563  if (trk.ok)
564  ptrk = spr::propagateCalo (trk.position, trk.momentum, trk.charge, bfield, spr::zFrontEE, spr::rFrontEB, spr::etaBEEcal, debug);
565  return ptrk;
566  }
567 
568  std::pair<math::XYZPoint,bool> propagateECAL(const reco::Track *track, 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());
572  return spr::propagateECAL (vertex, momentum, charge, bfield, debug);
573  }
574 
575  std::pair<math::XYZPoint,bool> propagateECAL(const GlobalPoint& vertex, const GlobalVector& momentum, int charge, const MagneticField* bfield, bool debug) {
576  spr::propagatedTrack track = spr::propagateCalo (vertex, momentum, charge, bfield, spr::zFrontEE, spr::rFrontEB, spr::etaBEEcal, debug);
577  return std::pair<math::XYZPoint,bool>(track.point,track.ok);
578  }
579 
581  GlobalPoint vertex (track->vx(), track->vy(), track->vz());
582  GlobalVector momentum (track->px(), track->py(), track->pz());
583  int charge (track->charge());
584  return spr::propagateCalo (vertex, momentum, charge, bfield, spr::zFrontHE, spr::rFrontHB, spr::etaBEHcal, debug);
585  }
586 
588  spr::trackAtOrigin trk = spr::simTrackAtOrigin(thisTrk, SimTk, SimVtx, debug);
590  if (trk.ok)
591  ptrk = spr::propagateCalo (trk.position, trk.momentum, trk.charge, bfield, spr::zFrontHE, spr::rFrontHB, spr::etaBEHcal, debug);
592  return ptrk;
593  }
594 
595  std::pair<math::XYZPoint,bool> propagateHCAL(const reco::Track *track, const MagneticField* bfield, bool debug) {
596  GlobalPoint vertex (track->vx(), track->vy(), track->vz());
597  GlobalVector momentum (track->px(), track->py(), track->pz());
598  int charge (track->charge());
599  return spr::propagateHCAL (vertex, momentum, charge, bfield, debug);
600  }
601 
602  std::pair<math::XYZPoint,bool> propagateHCAL(const GlobalPoint& vertex, const GlobalVector& momentum, int charge, const MagneticField* bfield, bool debug) {
603  spr::propagatedTrack track = spr::propagateCalo (vertex, momentum, charge, bfield, spr::zFrontHE, spr::rFrontHB, spr::etaBEHcal, debug);
604  return std::pair<math::XYZPoint,bool>(track.point,track.ok);
605  }
606 
607  std::pair<math::XYZPoint,bool> propagateTracker(const reco::Track *track, const MagneticField* bfield, bool debug) {
608  GlobalPoint vertex (track->vx(), track->vy(), track->vz());
609  GlobalVector momentum (track->px(), track->py(), track->pz());
610  int charge (track->charge());
611  spr::propagatedTrack track1 = spr::propagateCalo (vertex, momentum, charge, bfield, spr::zBackTE, spr::rBackTB, spr::etaBETrak, debug);
612  return std::pair<math::XYZPoint,bool>(track1.point,track1.ok);
613  }
614 
615  std::pair<math::XYZPoint,double> propagateTrackerEnd(const reco::Track *track,
616  const MagneticField* bField, bool
617 #ifdef EDM_ML_DEBUG
618  debug
619 #endif
620  ) {
621 
622  GlobalPoint vertex (track->vx(), track->vy(), track->vz());
623  GlobalVector momentum (track->px(), track->py(), track->pz());
624  int charge (track->charge());
625  float radius = track->outerPosition().Rho();
626  float zdist = track->outerPosition().Z();
627 #ifdef EDM_ML_DEBUG
628  if (debug) std::cout << "propagateTrackerEnd:: Vertex " << vertex << " Momentum " << momentum << " Charge " << charge << " Radius " << radius << " Z " << zdist << std::endl;
629 #endif
630  FreeTrajectoryState fts (vertex, momentum, charge, bField);
633 
634  AnalyticalPropagator myAP (bField, alongMomentum, 2*M_PI);
635 
636  TrajectoryStateOnSurface tsose = myAP.propagate(fts, *endcap);
637  TrajectoryStateOnSurface tsosb = myAP.propagate(fts, *barrel);
638 
639  math::XYZPoint point(-999.,-999.,-999.);
640  bool ok=false;
641  GlobalVector direction(0,0,1);
642  if (tsosb.isValid() && std::abs(zdist) < spr::zFrontTE) {
643  point.SetXYZ(tsosb.globalPosition().x(), tsosb.globalPosition().y(), tsosb.globalPosition().z());
644  direction = tsosb.globalDirection();
645  ok = true;
646  } else if (tsose.isValid()) {
647  point.SetXYZ(tsose.globalPosition().x(), tsose.globalPosition().y(), tsose.globalPosition().z());
648  direction = tsose.globalDirection();
649  ok = true;
650  }
651 
652  double length = -1;
653  if (ok) {
654  math::XYZPoint vDiff(point.x()-vertex.x(), point.y()-vertex.y(), point.z()-vertex.z());
655  double dphi = direction.phi()-momentum.phi();
656  double rdist = std::sqrt(vDiff.x()*vDiff.x()+vDiff.y()*vDiff.y());
657  double rat = 0.5*dphi/std::sin(0.5*dphi);
658  double dZ = vDiff.z();
659  double dS = rdist*rat; //dZ*momentum.z()/momentum.perp();
660  length = std::sqrt(dS*dS+dZ*dZ);
661 #ifdef EDM_ML_DEBUG
662  if (debug)
663  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;
664 #endif
665  }
666  return std::pair<math::XYZPoint,double>(point,length);
667  }
668 
670  const GlobalVector& tpMomentum,
671  int tpCharge, const MagneticField* bField,
672  float zdist, float radius, float corner, bool
673 #ifdef EDM_ML_DEBUG
674  debug
675 #endif
676  ) {
677 
679 #ifdef EDM_ML_DEBUG
680  if (debug) std::cout << "propagateCalo:: Vertex " << tpVertex << " Momentum " << tpMomentum << " Charge " << tpCharge << " Radius " << radius << " Z " << zdist << " Corner " << corner << std::endl;
681 #endif
682  FreeTrajectoryState fts (tpVertex, tpMomentum, tpCharge, bField);
683 
686 
688 
689  AnalyticalPropagator myAP (bField, alongMomentum, 2*M_PI);
690 
692  if (tpMomentum.eta() < 0) {
693  tsose = myAP.propagate(fts, *lendcap);
694  } else {
695  tsose = myAP.propagate(fts, *rendcap);
696  }
697 
698  TrajectoryStateOnSurface tsosb = myAP.propagate(fts, *barrel);
699 
700  track.ok=true;
701  if (tsose.isValid() && tsosb.isValid()) {
702  float absEta = std::abs(tsosb.globalPosition().eta());
703  if (absEta < corner) {
704  track.point.SetXYZ(tsosb.globalPosition().x(), tsosb.globalPosition().y(), tsosb.globalPosition().z());
705  track.direction = tsosb.globalDirection();
706  } else {
707  track.point.SetXYZ(tsose.globalPosition().x(), tsose.globalPosition().y(), tsose.globalPosition().z());
708  track.direction = tsose.globalDirection();
709  }
710  } else if (tsose.isValid()) {
711  track.point.SetXYZ(tsose.globalPosition().x(), tsose.globalPosition().y(), tsose.globalPosition().z());
712  track.direction = tsose.globalDirection();
713  } else if (tsosb.isValid()) {
714  track.point.SetXYZ(tsosb.globalPosition().x(), tsosb.globalPosition().y(), tsosb.globalPosition().z());
715  track.direction = tsosb.globalDirection();
716  } else {
717  track.point.SetXYZ(-999., -999., -999.);
718  track.direction = GlobalVector(0,0,1);
719  track.ok = false;
720  }
721 #ifdef EDM_ML_DEBUG
722  if (debug) {
723  std::cout << "propagateCalo:: Barrel " << tsosb.isValid() << " Endcap " << tsose.isValid() << " OverAll " << track.ok << " Point " << track.point << " Direction " << track.direction << std::endl;
724  if (track.ok) {
725  math::XYZPoint vDiff(track.point.x()-tpVertex.x(), track.point.y()-tpVertex.y(), track.point.z()-tpVertex.z());
726  double dphi = track.direction.phi()-tpMomentum.phi();
727  double rdist = std::sqrt(vDiff.x()*vDiff.x()+vDiff.y()*vDiff.y());
728  double pt = tpMomentum.perp();
729  double rat = 0.5*dphi/std::sin(0.5*dphi);
730  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;
731  }
732  }
733 #endif
734  return track;
735  }
736 
737  spr::trackAtOrigin simTrackAtOrigin(unsigned int thisTrk,
739  SimTk, edm::Handle<edm::SimVertexContainer>& SimVtx, bool
740 #ifdef EDM_ML_DEBUG
741  debug
742 #endif
743  ) {
744 
745  spr::trackAtOrigin trk;
746 
747  edm::SimTrackContainer::const_iterator itr = SimTk->end();
748  for (edm::SimTrackContainer::const_iterator simTrkItr = SimTk->begin(); simTrkItr!= SimTk->end(); simTrkItr++) {
749  if ( simTrkItr->trackId() == thisTrk ) {
750 #ifdef EDM_ML_DEBUG
751  if (debug) std::cout << "matched trackId (maximum occurance) " << thisTrk << " type " << simTrkItr->type() << std::endl;
752 #endif
753  itr = simTrkItr;
754  break;
755  }
756  }
757 
758  if (itr != SimTk->end()) {
759  int vertIndex = itr->vertIndex();
760  if (vertIndex != -1 && vertIndex < (int)SimVtx->size()) {
761  edm::SimVertexContainer::const_iterator simVtxItr= SimVtx->begin();
762  for (int iv=0; iv<vertIndex; iv++) simVtxItr++;
763  const math::XYZTLorentzVectorD pos = simVtxItr->position();
764  const math::XYZTLorentzVectorD mom = itr->momentum();
765  trk.ok = true;
766  trk.charge = (int)(itr->charge());
767  trk.position = GlobalPoint(pos.x(), pos.y(), pos.z());
768  trk.momentum = GlobalVector(mom.x(), mom.y(), mom.z());
769  }
770  }
771 #ifdef EDM_ML_DEBUG
772  if (debug) std::cout << "Track flag " << trk.ok << " Position " << trk.position << " Momentum " << trk.momentum << std::endl;
773 #endif
774  return trk;
775  }
776 
777 }
virtual DetId getClosestCell(const GlobalPoint &r) const
double p() const
momentum vector magnitude
Definition: TrackBase.h:610
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)
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
static const double zBackTE
Definition: CaloConstants.h:21
static const double etaBEHcal
Definition: CaloConstants.h:15
virtual DetId getClosestCell(const GlobalPoint &r) const
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:640
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:622
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
#define EDM_ML_DEBUG
Definition: MPUnpacker.cc:1
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:646
static const double rBackTB
Definition: CaloConstants.h:22
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
std::pair< bool, HcalDetId > propagateHCALBack(const reco::Track *, const CaloGeometry *geo, const MagneticField *bField, bool debug=false)
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:634
virtual DetId getClosestCell(const GlobalPoint &r) const
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:664
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:505
T eta() const
Definition: PV3DBase.h:76
double vy() const
y coordinate of the reference point on track
Definition: TrackBase.h:658
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:562
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:628
double vx() const
x coordinate of the reference point on track
Definition: TrackBase.h:652
Global3DVector GlobalVector
Definition: GlobalVector.h:10
GlobalVector globalDirection() const