CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackAssociator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HTrackAssociator
4 // Class: HTrackAssociator
5 //
6 /*
7 
8  Description: <one line class summary>
9 
10  Implementation:
11  <Notes on implementation>
12 */
13 //
14 // Original Author: Dmytro Kovalskyi
15 // Modified for ECAL+HCAL by: Michal Szleper
16 // Created: Fri Apr 21 10:59:41 PDT 2006
17 //
18 //
19 
21 
22 // user include files
23 
24 
29 
30 // calorimeter info
32 
33 
34 
35 
37 
39 #include <stack>
40 #include <set>
41 
42 
43 
44 //
45 // class declaration
46 //
47 
48 using namespace reco;
49 
51 {
52  ivProp_ = 0;
53  defProp_ = 0;
54  debug_ = 0;
55  caloTowerMap_ = 0;
56  useDefaultPropagator_ = false;
57 }
58 
60 {
61  if (defProp_) delete defProp_;
62 }
63 
64 //-----------------------------------------------------------------------------
66  const std::string moduleLabel,
67  const std::string productInstanceLabel)
68 {
69  if (className == "EBRecHitCollection")
70  {
71  EBRecHitCollectionLabels.clear();
72  EBRecHitCollectionLabels.push_back(moduleLabel);
73  EBRecHitCollectionLabels.push_back(productInstanceLabel);
74  }
75  if (className == "EERecHitCollection")
76  {
77  EERecHitCollectionLabels.clear();
78  EERecHitCollectionLabels.push_back(moduleLabel);
79  EERecHitCollectionLabels.push_back(productInstanceLabel);
80  }
81  if (className == "HBHERecHitCollection")
82  {
83  HBHERecHitCollectionLabels.clear();
84  HBHERecHitCollectionLabels.push_back(moduleLabel);
85  HBHERecHitCollectionLabels.push_back(productInstanceLabel);
86  }
87  if (className == "CaloTowerCollection")
88  {
89  CaloTowerCollectionLabels.clear();
90  CaloTowerCollectionLabels.push_back(moduleLabel);
91  CaloTowerCollectionLabels.push_back(productInstanceLabel);
92  }
93 }
94 
95 
96 //-----------------------------------------------------------------------------
98 {
99  ivProp_ = ptr;
100  caloDetIdAssociator_.setPropagator(ivProp_);
101  ecalDetIdAssociator_.setPropagator(ivProp_);
102  hcalDetIdAssociator_.setPropagator(ivProp_);
103 }
104 
105 //-----------------------------------------------------------------------------
107 {
108  useDefaultPropagator_ = true;
109 }
110 
111 
112 //-----------------------------------------------------------------------------
114 {
115  // access the calorimeter geometry
116  iSetup.get<CaloGeometryRecord>().get(theCaloGeometry_);
117  if (!theCaloGeometry_.isValid())
118  throw cms::Exception("FatalError") << "Unable to find IdealGeometryRecord in event!\n";
119 
120  if (useDefaultPropagator_ && ! defProp_ ) {
121  // setup propagator
123  iSetup.get<IdealMagneticFieldRecord>().get(bField);
124 
126  prop->setMaterialMode(false);
127  prop->applyRadX0Correction(true);
128  // prop->setDebug(true); // tmp
129  defProp_ = prop;
130  setPropagator(defProp_);
131  }
132 
133 
134 }
135 
136 //-----------------------------------------------------------------------------
138  const edm::EventSetup& iSetup,
139  const FreeTrajectoryState& trackOrigin,
141 {
143  using namespace edm;
144 
145  init( iSetup );
146 
147  FreeTrajectoryState currentPosition(trackOrigin);
148 
149  if (parameters.useEcal) fillEcal( iEvent, iSetup, info, currentPosition,parameters.idREcal, parameters.dREcal);
150  if (parameters.useHcal) fillHcal( iEvent, iSetup, info, currentPosition,parameters.idRHcal,parameters.dRHcal);
151  if (parameters.useCalo) fillCaloTowers( iEvent, iSetup, info, currentPosition,parameters.idRCalo,parameters.dRCalo);
152 
153  return info;
154 }
155 
156 //-----------------------------------------------------------------------------
157 std::vector<EcalRecHit> HTrackAssociator::associateEcal( const edm::Event& iEvent,
158  const edm::EventSetup& iSetup,
159  const FreeTrajectoryState& trackOrigin,
160  const double dR )
161 {
163  parameters.useHcal = false;
164  parameters.dREcal = dR;
165  HTrackDetMatchInfo info( associate(iEvent, iSetup, trackOrigin, parameters ));
166  if (dR>0)
167  return info.coneEcalRecHits;
168  else
169  return info.crossedEcalRecHits;
170 }
171 
172 //-----------------------------------------------------------------------------
174  const edm::EventSetup& iSetup,
175  const FreeTrajectoryState& trackOrigin,
176  const double dR )
177 {
179  parameters.useHcal = false;
180  parameters.dREcal = dR;
181  HTrackDetMatchInfo info = associate(iEvent, iSetup, trackOrigin, parameters );
182  if(dR>0)
183  return info.ecalConeEnergyFromRecHits();
184  else
185  return info.ecalEnergyFromRecHits();
186 }
187 
188 //-----------------------------------------------------------------------------
189 std::vector<CaloTower> HTrackAssociator::associateHcal( const edm::Event& iEvent,
190  const edm::EventSetup& iSetup,
191  const FreeTrajectoryState& trackOrigin,
192  const double dR )
193 {
195  parameters.useEcal = false;
196  parameters.dRHcal = dR;
197  HTrackDetMatchInfo info( associate(iEvent, iSetup, trackOrigin, parameters ));
198  if (dR>0)
199  return info.coneTowers;
200  else
201  return info.crossedTowers;
202 
203 }
204 
205 //-----------------------------------------------------------------------------
207  const edm::EventSetup& iSetup,
208  const FreeTrajectoryState& trackOrigin,
209  const double dR )
210 {
212  parameters.useEcal = false;
213  parameters.dRHcal = dR;
214  HTrackDetMatchInfo info( associate(iEvent, iSetup, trackOrigin, parameters ));
215  if (dR>0)
216  return info.hcalConeEnergyFromRecHits();
217  else
218  return info.hcalEnergyFromRecHits();
219 }
220 
221 //-----------------------------------------------------------------------------
223  const edm::EventSetup& iSetup,
225  const FreeTrajectoryState& trajectoryPoint,
226  const int idR,
227  const double dR)
228 {
229  ecalDetIdAssociator_.setGeometry(&*theCaloGeometry_);
230 
231  // ECAL points (EB+EE)
232  std::vector<GlobalPoint> ecalPoints;
233  ecalPoints.push_back(GlobalPoint(135.,0,310.));
234  ecalPoints.push_back(GlobalPoint(150.,0,340.));
235  ecalPoints.push_back(GlobalPoint(170.,0,370.));
236 
237  std::vector<GlobalPoint> ecalTrajectory = ecalDetIdAssociator_.getTrajectory(trajectoryPoint, ecalPoints);
238 // if(ecalTrajectory.empty()) throw cms::Exception("FatalError") << "Failed to propagate a track to ECAL\n";
239 
240  if(ecalTrajectory.empty()) {
241  LogTrace("HTrackAssociator::fillEcal") << "Failed to propagate a track to ECAL; moving on\n";
242  info.isGoodEcal = 0;
243  return;
244  }
245 
246  info.isGoodEcal = 1;
247 
248  info.trkGlobPosAtEcal = getPoint(ecalTrajectory[0]);
249 
250  // Find ECAL crystals
253 // if (EBRecHitCollectionLabels.empty())
254 // throw cms::Exception("FatalError") << "Module lable is not set for EBRecHitCollection.\n";
255 // else
256  iEvent.getByLabel (EBRecHitCollectionLabels[0], EBRecHitCollectionLabels[1], EBRecHits);
257 // if (!EBRecHits.isValid()) throw cms::Exception("FatalError") << "Unable to find EBRecHitCollection in event!\n";
258  if (EERecHitCollectionLabels[1]!=EBRecHitCollectionLabels[1]) iEvent.getByLabel (EERecHitCollectionLabels[0], EERecHitCollectionLabels[1], EERecHits);
259 // if (!EERecHits.isValid()) throw cms::Exception("FatalError") << "Unable to find EERecHitCollection in event!\n";
260 
261  std::set<DetId> ecalIdsInRegion = ecalDetIdAssociator_.getDetIdsCloseToAPoint(ecalTrajectory[0],idR);
262  std::set<DetId> ecalIdsInACone = ecalDetIdAssociator_.getDetIdsInACone(ecalIdsInRegion, ecalTrajectory, dR);
263  std::set<DetId> crossedEcalIds = ecalDetIdAssociator_.getCrossedDetIds(ecalIdsInRegion, ecalTrajectory);
264 
265  // add EcalRecHits
266  for(std::set<DetId>::const_iterator itr=crossedEcalIds.begin(); itr!=crossedEcalIds.end();itr++) {
267  std::vector<EcalRecHit>::const_iterator hit = (*EBRecHits).find(*itr);
268  if(hit != (*EBRecHits).end())
269  info.crossedEcalRecHits.push_back(*hit);
270  else
271  LogTrace("HTrackAssociator::fillEcal") << "EcalRecHit is not found for DetId: " << itr->rawId() <<"\n";
272  }
273  for(std::set<DetId>::const_iterator itr=ecalIdsInACone.begin(); itr!=ecalIdsInACone.end();itr++) {
274  std::vector<EcalRecHit>::const_iterator hit = (*EBRecHits).find(*itr);
275  if(hit != (*EBRecHits).end()) {
276  info.coneEcalRecHits.push_back(*hit);
277  }
278  else
279  LogTrace("HTrackAssociator::fillEcal") << "EcalRecHit is not found for DetId: " << itr->rawId() <<"\n";
280  }
281  if (EERecHitCollectionLabels[1]==EBRecHitCollectionLabels[1])return;
282  for(std::set<DetId>::const_iterator itr=crossedEcalIds.begin(); itr!=crossedEcalIds.end();itr++) {
283  std::vector<EcalRecHit>::const_iterator hit = (*EERecHits).find(*itr);
284  if(hit != (*EERecHits).end())
285  info.crossedEcalRecHits.push_back(*hit);
286  else
287  LogTrace("HTrackAssociator::fillEcal") << "EcalRecHit is not found for DetId: " << itr->rawId() <<"\n";
288  }
289  for(std::set<DetId>::const_iterator itr=ecalIdsInACone.begin(); itr!=ecalIdsInACone.end();itr++) {
290  std::vector<EcalRecHit>::const_iterator hit = (*EERecHits).find(*itr);
291  if(hit != (*EERecHits).end()) {
292  info.coneEcalRecHits.push_back(*hit);
293  }
294  else
295  LogTrace("HTrackAssociator::fillEcal") << "EcalRecHit is not found for DetId: " << itr->rawId() <<"\n";
296  }
297 }
298 
299 //-----------------------------------------------------------------------------
301  const edm::EventSetup& iSetup,
303  const FreeTrajectoryState& trajectoryPoint,
304  const int idR,
305  const double dR)
306 {
307  // ECAL hits are not used for the CaloTower identification
308  caloDetIdAssociator_.setGeometry(&*theCaloGeometry_);
309 
310  // HCAL points (HB+HE)
311  std::vector<GlobalPoint> hcalPoints;
312  hcalPoints.push_back(GlobalPoint(135.,0,310.));
313  hcalPoints.push_back(GlobalPoint(150.,0,340.));
314  hcalPoints.push_back(GlobalPoint(170.,0,370.));
315  hcalPoints.push_back(GlobalPoint(190.,0,400.));
316  hcalPoints.push_back(GlobalPoint(240.,0,500.));
317  hcalPoints.push_back(GlobalPoint(280.,0,550.));
318 
319  std::vector<GlobalPoint> hcalTrajectory = caloDetIdAssociator_.getTrajectory(trajectoryPoint, hcalPoints);
320 // if(hcalTrajectory.empty()) throw cms::Exception("FatalError") << "Failed to propagate the track to HCAL\n";
321 
322  if(hcalTrajectory.empty()) {
323  LogTrace("HTrackAssociator::fillEcal") << "Failed to propagate a track to ECAL; moving on\n";
324  info.isGoodCalo = 0;
325  info.isGoodEcal = 0;
326  std::cout<<" HTrackAssociator::fillCaloTowers::Failed to propagate a track to ECAL "<<std::endl;
327  return;
328  }
329 
330  info.isGoodCalo = 1;
331  info.isGoodEcal = 1;
332  info.trkGlobPosAtEcal = getPoint(hcalTrajectory[0]);
333 
334  if(hcalTrajectory.size()<4) {
335  LogTrace("HTrackAssociator::fillEcal") << "Failed to propagate a track to HCAL; moving on\n";
336  info.isGoodHcal = 0;
337  }
338 
339  info.isGoodHcal = 1;
340 
341  info.trkGlobPosAtHcal = getPoint(hcalTrajectory[4]);
342 
343  // find crossed CaloTowers
345 
346  if (CaloTowerCollectionLabels.empty())
347  throw cms::Exception("FatalError") << "Module lable is not set for CaloTowers.\n";
348  else
349  iEvent.getByLabel (CaloTowerCollectionLabels[0], CaloTowerCollectionLabels[1], caloTowers);
350  if (!caloTowers.isValid()) throw cms::Exception("FatalError") << "Unable to find CaloTowers in event!\n";
351 
352 // first get DetIds in a predefined NxN region
353 // std::set<DetId> caloTowerIdsInBigRegion = caloDetIdAssociator_.getDetIdsCloseToAPoint(hcalTrajectory[0],idR+1);
354  std::set<DetId> caloTowerIdsInRegion = caloDetIdAssociator_.getDetIdsCloseToAPoint(hcalTrajectory[0],idR);
355 
356  std::set<DetId> caloTowerIdsInACone;
357  std::set<DetId> crossedCaloTowerIds;
358  std::set<DetId> caloTowerIdsInBox;
359  caloTowerIdsInACone = caloDetIdAssociator_.getDetIdsInACone(caloTowerIdsInRegion, hcalTrajectory, dR);
360 // get DetId of the most energetic tower in that region
361  crossedCaloTowerIds = caloDetIdAssociator_.getMaxEDetId(caloTowerIdsInRegion, caloTowers);
362 // get DetIds of the towers surrounding the most energetic one
363  caloTowerIdsInBox = caloDetIdAssociator_.getDetIdsInACone(crossedCaloTowerIds, hcalTrajectory, -1.);
364 
365 //
366 // Debug prints
367 //
368 // std::cout <<" Debug printout in CaloTowers "<<std::endl;
369 // std::cout <<" with position at outer layer:r,z,phi "<<trajectoryPoint.position().eta()<<
370 // " "<<trajectoryPoint.position().phi()<<
371 // " "<<trajectoryPoint.position().perp()<<
372 // " "<<trajectoryPoint.position().z()<<
373 // " "<<trajectoryPoint.charge()<<std::endl;
374 // std::cout <<" Trajectory point at ECAL surface:eta:phi:radius:z "<<(hcalTrajectory[0]).eta()<<
375 // " "<<(hcalTrajectory[0]).phi()<<
376 // " "<<(hcalTrajectory[0]).perp()<<
377 // " "<<(hcalTrajectory[0]).z()<<
378 // " momentum "<<trajectoryPoint.momentum().perp()<<std::endl;
379 //
380 // std::cout<<" Number of towers in the region "<<caloTowerIdsInRegion.size()<<" idR= "<<idR<<std::endl;
381 
382  // add CaloTowers
383  for(std::set<DetId>::const_iterator itr=crossedCaloTowerIds.begin(); itr!=crossedCaloTowerIds.end();itr++)
384  {
385  DetId id(*itr);
386  CaloTowerCollection::const_iterator tower = (*caloTowers).find(id);
387  if(tower != (*caloTowers).end())
388  info.crossedTowers.push_back(*tower);
389  else
390  LogTrace("HTrackAssociator::fillEcal") << "CaloTower is not found for DetId: " << id.rawId() << "\n";
391  }
392 
393  for(std::set<DetId>::const_iterator itr=caloTowerIdsInACone.begin(); itr!=caloTowerIdsInACone.end();itr++)
394  {
395  DetId id(*itr);
396  CaloTowerCollection::const_iterator tower = (*caloTowers).find(id);
397  if(tower != (*caloTowers).end()) {
398  info.coneTowers.push_back(*tower);
399  }
400  else
401  LogTrace("HTrackAssociator::fillEcal") << "CaloTower is not found for DetId: " << id.rawId() << "\n";
402  }
403 
404  for(std::set<DetId>::const_iterator itr=caloTowerIdsInBox.begin(); itr!=caloTowerIdsInBox.end();itr++)
405  {
406  DetId id(*itr);
407  CaloTowerCollection::const_iterator tower = (*caloTowers).find(id);
408  if(tower != (*caloTowers).end()) {
409  info.boxTowers.push_back(*tower);
410  }
411  else
412  LogTrace("HTrackAssociator::fillEcal") << "CaloTower is not found for DetId: " << id.rawId() << "\n";
413  }
414 
415  for(std::set<DetId>::const_iterator itr=caloTowerIdsInRegion.begin(); itr!=caloTowerIdsInRegion.end();itr++)
416  {
417  DetId id(*itr);
418  CaloTowerCollection::const_iterator tower = (*caloTowers).find(id);
419  if(tower != (*caloTowers).end()) {
420  info.regionTowers.push_back(*tower);
421  }
422  else
423  LogTrace("HTrackAssociator::fillEcal") << "CaloTower is not found for DetId: " << id.rawId() << "\n";
424  }
425 
426 }
427 
428 //-----------------------------------------------------------------------------
430  const edm::EventSetup& iSetup,
432  const FreeTrajectoryState& trajectoryPoint,
433  const int idR,
434  const double dR) {
435  hcalDetIdAssociator_.setGeometry(&*theCaloGeometry_);
436 
437 // HCAL points (HB+HE)
438  std::vector<GlobalPoint> hcalPoints;
439  hcalPoints.push_back(GlobalPoint(190.,0,400.));
440  hcalPoints.push_back(GlobalPoint(240.,0,500.));
441  hcalPoints.push_back(GlobalPoint(280.,0,550.));
442 
443  std::vector<GlobalPoint> hcalTrajectory = hcalDetIdAssociator_.getTrajectory(trajectoryPoint, hcalPoints);
444 // if(hcalTrajectory.empty()) throw cms::Exception("FatalError") << "Failed to propagate the track to HCAL\n";
445 
446  if(hcalTrajectory.empty()) {
447  LogTrace("HTrackAssociator::fillHcal") << "Failed to propagate a track to HCAL; moving on\n";
448  info.isGoodHcal = 0;
449 // std::cout<<" HTrackAssociator::fillHcal::Failed to propagate a track to HCAL "<<std::endl;
450  return;
451  }
452 
453  info.isGoodHcal = 1;
454 
455  info.trkGlobPosAtHcal = getPoint(hcalTrajectory[0]);
456 
458 // if (HBHERecHitCollectionLabels.empty())
459 // throw cms::Exception("FatalError") << "Module label is not set for HBHERecHitCollection.\n";
460 // else
461  iEvent.getByLabel (HBHERecHitCollectionLabels[0], HBHERecHitCollectionLabels[1], HBHERecHits);
462  if (!HBHERecHits.isValid()) throw cms::Exception("FatalError") << "Unable to find HBHERecHitCollection in event!\n";
463 
464 // first get DetIds in a predefined NxN region
465 // std::set<DetId> hcalIdsInBigRegion = hcalDetIdAssociator_.getDetIdsCloseToAPoint(hcalTrajectory[0],idR+1);
466  std::set<DetId> hcalIdsInRegion = hcalDetIdAssociator_.getDetIdsCloseToAPoint(hcalTrajectory[0],idR);
467 
468  std::set<DetId> hcalIdsInACone;
469  std::set<DetId> crossedHcalIds;
470  std::set<DetId> hcalIdsInBox;
471  hcalIdsInACone = hcalDetIdAssociator_.getDetIdsInACone(hcalIdsInRegion, hcalTrajectory, dR);
472 // get DetId of the most energetic tower in that region
473  crossedHcalIds = hcalDetIdAssociator_.getMaxEDetId(hcalIdsInRegion, HBHERecHits);
474 // get DetIds of the towers surrounding the most energetic one
475  hcalIdsInBox = hcalDetIdAssociator_.getDetIdsInACone(crossedHcalIds, hcalTrajectory, -1.);
476 
477 // add HcalRecHits
478  for(std::set<DetId>::const_iterator itr=crossedHcalIds.begin(); itr!=crossedHcalIds.end();itr++) {
479  std::vector<HBHERecHit>::const_iterator hit = (*HBHERecHits).find(*itr);
480  if(hit != (*HBHERecHits).end())
481  info.crossedHcalRecHits.push_back(*hit);
482  else
483  LogTrace("HTrackAssociator::fillHcal") << "HcalRecHit is not found for DetId: " << itr->rawId() <<"\n";
484  }
485  for(std::set<DetId>::const_iterator itr=hcalIdsInACone.begin(); itr!=hcalIdsInACone.end();itr++) {
486  std::vector<HBHERecHit>::const_iterator hit = (*HBHERecHits).find(*itr);
487  if(hit != (*HBHERecHits).end())
488  info.coneHcalRecHits.push_back(*hit);
489  else
490  LogTrace("HTrackAssociator::fillHcal") << "HcalRecHit is not found for DetId: " << itr->rawId() <<"\n";
491  }
492  for(std::set<DetId>::const_iterator itr=hcalIdsInBox.begin(); itr!=hcalIdsInBox.end();itr++) {
493  std::vector<HBHERecHit>::const_iterator hit = (*HBHERecHits).find(*itr);
494  if(hit != (*HBHERecHits).end())
495  info.boxHcalRecHits.push_back(*hit);
496  else
497  LogTrace("HTrackAssociator::fillHcal") << "HcalRecHit is not found for DetId: " << itr->rawId() <<"\n";
498  }
499  for(std::set<DetId>::const_iterator itr=hcalIdsInRegion.begin(); itr!=hcalIdsInRegion.end();itr++) {
500  std::vector<HBHERecHit>::const_iterator hit = (*HBHERecHits).find(*itr);
501  if(hit != (*HBHERecHits).end())
502  info.regionHcalRecHits.push_back(*hit);
503  else
504  LogTrace("HTrackAssociator::fillHcal") << "HcalRecHit is not found for DetId: " << itr->rawId() <<"\n";
505  }
506 }
507 
508 //-----------------------------------------------------------------------------
510  const edm::EventSetup& iSetup,
512  const FreeTrajectoryState& trajectoryPoint,
513  const int idR,
514  const double dR)
515 {
516  // ECAL hits are not used for the CaloTower identification
517  caloDetIdAssociator_.setGeometry(&*theCaloGeometry_);
518 
519  // HCAL points (HB+HE)
520  std::vector<GlobalPoint> hcalPoints;
521  hcalPoints.push_back(GlobalPoint(190.,0,400.));
522  hcalPoints.push_back(GlobalPoint(240.,0,500.));
523  hcalPoints.push_back(GlobalPoint(280.,0,550.));
524 
525  std::vector<GlobalPoint> hcalTrajectory = caloDetIdAssociator_.getTrajectory(trajectoryPoint, hcalPoints);
526 // if(hcalTrajectory.empty()) throw cms::Exception("FatalError") << "Failed to propagate the track to HCAL\n";
527 
528  if(hcalTrajectory.empty()) {
529  LogTrace("HTrackAssociator::fillEcal") << "Failed to propagate a track to HCAL; moving on\n";
530  info.isGoodCalo = 0;
531  std::cout<<" HTrackAssociator::fillCaloTowers::Failed to propagate a track to HCAL "<<std::endl;
532  return;
533  }
534 
535  info.isGoodCalo = 1;
536 
537  info.trkGlobPosAtHcal = getPoint(hcalTrajectory[0]);
538 
539  // find crossed CaloTowers
541 
542  if (CaloTowerCollectionLabels.empty())
543  throw cms::Exception("FatalError") << "Module lable is not set for CaloTowers.\n";
544  else
545  iEvent.getByLabel (CaloTowerCollectionLabels[0], CaloTowerCollectionLabels[1], caloTowers);
546  if (!caloTowers.isValid()) throw cms::Exception("FatalError") << "Unable to find CaloTowers in event!\n";
547 
548 
549 // first get DetIds in a predefined NxN region
550  std::set<DetId> caloTowerIdsInBigRegion = caloDetIdAssociator_.getDetIdsCloseToAPoint(hcalTrajectory[0],idR+1);
551  std::set<DetId> caloTowerIdsInRegion = caloDetIdAssociator_.getDetIdsCloseToAPoint(hcalTrajectory[0],idR);
552 
553  std::set<DetId> caloTowerIdsInACone;
554  std::set<DetId> crossedCaloTowerIds;
555  std::set<DetId> caloTowerIdsInBox;
556  caloTowerIdsInACone = caloDetIdAssociator_.getDetIdsInACone(caloTowerIdsInBigRegion, hcalTrajectory, dR);
557 // get DetId of the most energetic tower in that region
558  crossedCaloTowerIds = caloDetIdAssociator_.getMaxEDetId(caloTowerIdsInRegion, caloTowers);
559 // get DetIds of the towers surrounding the most energetic one
560  caloTowerIdsInBox = caloDetIdAssociator_.getDetIdsInACone(crossedCaloTowerIds, hcalTrajectory, -1.);
561 
562  // add CaloTowers
563  for(std::set<DetId>::const_iterator itr=crossedCaloTowerIds.begin(); itr!=crossedCaloTowerIds.end();itr++)
564  {
565  DetId id(*itr);
566  CaloTowerCollection::const_iterator tower = (*caloTowers).find(id);
567  if(tower != (*caloTowers).end())
568  info.crossedTowers.push_back(*tower);
569  else
570  LogTrace("HTrackAssociator::fillEcal") << "CaloTower is not found for DetId: " << id.rawId() << "\n";
571  }
572 
573  for(std::set<DetId>::const_iterator itr=caloTowerIdsInACone.begin(); itr!=caloTowerIdsInACone.end();itr++)
574  {
575  DetId id(*itr);
576  CaloTowerCollection::const_iterator tower = (*caloTowers).find(id);
577  if(tower != (*caloTowers).end())
578  info.coneTowers.push_back(*tower);
579  else
580  LogTrace("HTrackAssociator::fillEcal") << "CaloTower is not found for DetId: " << id.rawId() << "\n";
581  }
582 
583 }
584 
585 //-----------------------------------------------------------------------------
587  const SimTrack& track,
588  const SimVertex& vertex )
589 {
591  iSetup.get<IdealMagneticFieldRecord>().get(bField);
592 
593  GlobalVector vector( track.momentum().x(), track.momentum().y(), track.momentum().z() );
594  // convert mm to cm
595  GlobalPoint point( vertex.position().x()*.1, vertex.position().y()*.1, vertex.position().z()*.1 );
596  int charge = track.type( )> 0 ? -1 : 1;
597  GlobalTrajectoryParameters tPars(point, vector, charge, &*bField);
598 
599  AlgebraicSymMatrix66 covT= AlgebraicMatrixID(); covT *= 1e-6; // initialize to sigma=1e-3
600  CartesianTrajectoryError tCov(covT);
601 
602  return FreeTrajectoryState(tPars, tCov);
603 }
604 
605 //-----------------------------------------------------------------------------
607  const reco::Track& track )
608 {
610  iSetup.get<IdealMagneticFieldRecord>().get(bField);
611 
612  GlobalVector vector( track.momentum().x(), track.momentum().y(), track.momentum().z() );
613 
614  GlobalPoint point( track.vertex().x(), track.vertex().y(), track.vertex().z() );
615 
616  GlobalTrajectoryParameters tPars(point, vector, track.charge(), &*bField);
617 
618  // FIX THIS !!!
619  // need to convert from perigee to global or helix (curvilinear) frame
620  // for now just an arbitrary matrix.
621  AlgebraicSymMatrix66 covT= AlgebraicMatrixID(); covT *= 1e-6; // initialize to sigma=1e-3
622  CartesianTrajectoryError tCov(covT);
623 
624  return FreeTrajectoryState(tPars, tCov);
625 }
626 
std::vector< CaloTower > crossedTowers
static const TGPicture * info(bool iBackgroundIsBlack)
FreeTrajectoryState getFreeTrajectoryState(const edm::EventSetup &, const reco::Track &)
get FreeTrajectoryState from different track representations
double getHcalEnergy(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const double dR=-1)
std::vector< HBHERecHit > coneHcalRecHits
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
std::vector< EcalRecHit > crossedEcalRecHits
int init
Definition: HydjetWrapper.h:67
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< CaloTower >::const_iterator const_iterator
std::vector< CaloTower > boxTowers
double getEcalEnergy(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const double dR=-1)
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:670
std::vector< HBHERecHit > regionHcalRecHits
void setPropagator(Propagator *)
use a user configured propagator
void addDataLabels(const std::string className, const std::string moduleLabel, const std::string productInstanceLabel="")
specify names of EDProducts to use for different input data types
std::vector< EcalRecHit > coneEcalRecHits
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:682
double hcalEnergyFromRecHits()
HCAL energy.
int iEvent
Definition: GenABIO.cc:230
math::XYZPoint trkGlobPosAtHcal
std::vector< HBHERecHit > boxHcalRecHits
void applyRadX0Correction(bool applyRadX0Correction)
void fillEcal(const edm::Event &, const edm::EventSetup &, HTrackDetMatchInfo &, const FreeTrajectoryState &, const int, const double)
std::vector< HBHERecHit > crossedHcalRecHits
void fillHcal(const edm::Event &, const edm::EventSetup &, HTrackDetMatchInfo &, const FreeTrajectoryState &, const int, const double)
double ecalConeEnergyFromRecHits()
const math::XYZTLorentzVectorD & position() const
Definition: CoreSimVertex.h:26
HTrackDetMatchInfo associate(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const HAssociatorParameters &)
double ecalEnergyFromRecHits()
ECAL energy.
bool isValid() const
Definition: HandleBase.h:75
void fillHcalTowers(const edm::Event &, const edm::EventSetup &, HTrackDetMatchInfo &, const FreeTrajectoryState &, const int, const double)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:418
#define LogTrace(id)
void useDefaultPropagator()
use the default propagator
Definition: DetId.h:18
std::vector< CaloTower > regionTowers
const T & get() const
Definition: EventSetup.h:56
std::vector< CaloTower > coneTowers
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:25
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:22
math::XYZPoint trkGlobPosAtEcal
double hcalConeEnergyFromRecHits()
void fillCaloTowers(const edm::Event &, const edm::EventSetup &, HTrackDetMatchInfo &, const FreeTrajectoryState &, const int, const double)
void init(const edm::EventSetup &)
tuple cout
Definition: gather_cfg.py:145
int charge() const
track electric charge
Definition: TrackBase.h:562
std::vector< EcalRecHit > associateEcal(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const double dR=-1)
std::vector< CaloTower > associateHcal(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const double dR=-1)
void setMaterialMode(bool noMaterial)
Switch for material effects mode: no material effects if true.
*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
std::string className(const T &t)
Definition: ClassName.h:30