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 // $Id: TrackAssociator.cc,v 1.8 2011/04/06 09:19:13 innocent Exp $
18 //
19 //
20 
22 
23 // user include files
24 
25 
30 
31 // calorimeter info
33 
34 
35 
36 
38 
41 #include <stack>
42 #include <set>
43 
44 
46 
47 
48 //
49 // class declaration
50 //
51 
52 using namespace reco;
53 
55 {
56  ivProp_ = 0;
57  defProp_ = 0;
58  debug_ = 0;
59  caloTowerMap_ = 0;
60  useDefaultPropagator_ = false;
61 }
62 
64 {
65  if (defProp_) delete defProp_;
66 }
67 
68 //-----------------------------------------------------------------------------
70  const std::string moduleLabel,
71  const std::string productInstanceLabel)
72 {
73  if (className == "EBRecHitCollection")
74  {
75  EBRecHitCollectionLabels.clear();
76  EBRecHitCollectionLabels.push_back(moduleLabel);
77  EBRecHitCollectionLabels.push_back(productInstanceLabel);
78  }
79  if (className == "EERecHitCollection")
80  {
81  EERecHitCollectionLabels.clear();
82  EERecHitCollectionLabels.push_back(moduleLabel);
83  EERecHitCollectionLabels.push_back(productInstanceLabel);
84  }
85  if (className == "HBHERecHitCollection")
86  {
87  HBHERecHitCollectionLabels.clear();
88  HBHERecHitCollectionLabels.push_back(moduleLabel);
89  HBHERecHitCollectionLabels.push_back(productInstanceLabel);
90  }
91  if (className == "CaloTowerCollection")
92  {
93  CaloTowerCollectionLabels.clear();
94  CaloTowerCollectionLabels.push_back(moduleLabel);
95  CaloTowerCollectionLabels.push_back(productInstanceLabel);
96  }
97 }
98 
99 
100 //-----------------------------------------------------------------------------
102 {
103  ivProp_ = ptr;
104  caloDetIdAssociator_.setPropagator(ivProp_);
105  ecalDetIdAssociator_.setPropagator(ivProp_);
106  hcalDetIdAssociator_.setPropagator(ivProp_);
107 }
108 
109 //-----------------------------------------------------------------------------
111 {
112  useDefaultPropagator_ = true;
113 }
114 
115 
116 //-----------------------------------------------------------------------------
118 {
119  // access the calorimeter geometry
120  iSetup.get<CaloGeometryRecord>().get(theCaloGeometry_);
121  if (!theCaloGeometry_.isValid())
122  throw cms::Exception("FatalError") << "Unable to find IdealGeometryRecord in event!\n";
123 
124  if (useDefaultPropagator_ && ! defProp_ ) {
125  // setup propagator
127  iSetup.get<IdealMagneticFieldRecord>().get(bField);
128 
130  prop->setMaterialMode(false);
131  prop->applyRadX0Correction(true);
132  // prop->setDebug(true); // tmp
133  defProp_ = prop;
134  setPropagator(defProp_);
135  }
136 
137 
138 }
139 
140 //-----------------------------------------------------------------------------
142  const edm::EventSetup& iSetup,
143  const FreeTrajectoryState& trackOrigin,
145 {
147  using namespace edm;
148  HTimerStack timers;
149 
150  init( iSetup );
151 
152  FreeTrajectoryState currentPosition(trackOrigin);
153 
154  if (parameters.useEcal) fillEcal( iEvent, iSetup, info, currentPosition,parameters.idREcal, parameters.dREcal);
155  if (parameters.useHcal) fillHcal( iEvent, iSetup, info, currentPosition,parameters.idRHcal,parameters.dRHcal);
156  if (parameters.useCalo) fillCaloTowers( iEvent, iSetup, info, currentPosition,parameters.idRCalo,parameters.dRCalo);
157 
158  return info;
159 }
160 
161 //-----------------------------------------------------------------------------
162 std::vector<EcalRecHit> HTrackAssociator::associateEcal( const edm::Event& iEvent,
163  const edm::EventSetup& iSetup,
164  const FreeTrajectoryState& trackOrigin,
165  const double dR )
166 {
168  parameters.useHcal = false;
169  parameters.dREcal = dR;
170  HTrackDetMatchInfo info( associate(iEvent, iSetup, trackOrigin, parameters ));
171  if (dR>0)
172  return info.coneEcalRecHits;
173  else
174  return info.crossedEcalRecHits;
175 }
176 
177 //-----------------------------------------------------------------------------
179  const edm::EventSetup& iSetup,
180  const FreeTrajectoryState& trackOrigin,
181  const double dR )
182 {
184  parameters.useHcal = false;
185  parameters.dREcal = dR;
186  HTrackDetMatchInfo info = associate(iEvent, iSetup, trackOrigin, parameters );
187  if(dR>0)
188  return info.ecalConeEnergyFromRecHits();
189  else
190  return info.ecalEnergyFromRecHits();
191 }
192 
193 //-----------------------------------------------------------------------------
194 std::vector<CaloTower> HTrackAssociator::associateHcal( const edm::Event& iEvent,
195  const edm::EventSetup& iSetup,
196  const FreeTrajectoryState& trackOrigin,
197  const double dR )
198 {
200  parameters.useEcal = false;
201  parameters.dRHcal = dR;
202  HTrackDetMatchInfo info( associate(iEvent, iSetup, trackOrigin, parameters ));
203  if (dR>0)
204  return info.coneTowers;
205  else
206  return info.crossedTowers;
207 
208 }
209 
210 //-----------------------------------------------------------------------------
212  const edm::EventSetup& iSetup,
213  const FreeTrajectoryState& trackOrigin,
214  const double dR )
215 {
217  parameters.useEcal = false;
218  parameters.dRHcal = dR;
219  HTrackDetMatchInfo info( associate(iEvent, iSetup, trackOrigin, parameters ));
220  if (dR>0)
221  return info.hcalConeEnergyFromRecHits();
222  else
223  return info.hcalEnergyFromRecHits();
224 }
225 
226 //-----------------------------------------------------------------------------
228  const edm::EventSetup& iSetup,
230  const FreeTrajectoryState& trajectoryPoint,
231  const int idR,
232  const double dR)
233 {
234  HTimerStack timers;
235  timers.push("HTrackAssociator::fillEcal");
236 
237  ecalDetIdAssociator_.setGeometry(&*theCaloGeometry_);
238 
239  timers.push("HTrackAssociator::fillEcal::propagation");
240  // ECAL points (EB+EE)
241  std::vector<GlobalPoint> ecalPoints;
242  ecalPoints.push_back(GlobalPoint(135.,0,310.));
243  ecalPoints.push_back(GlobalPoint(150.,0,340.));
244  ecalPoints.push_back(GlobalPoint(170.,0,370.));
245 
246  std::vector<GlobalPoint> ecalTrajectory = ecalDetIdAssociator_.getTrajectory(trajectoryPoint, ecalPoints);
247 // if(ecalTrajectory.empty()) throw cms::Exception("FatalError") << "Failed to propagate a track to ECAL\n";
248 
249  if(ecalTrajectory.empty()) {
250  LogTrace("HTrackAssociator::fillEcal") << "Failed to propagate a track to ECAL; moving on\n";
251  info.isGoodEcal = 0;
252  return;
253  }
254 
255  info.isGoodEcal = 1;
256 
257  info.trkGlobPosAtEcal = getPoint(ecalTrajectory[0]);
258 
259  // Find ECAL crystals
260  timers.pop_and_push("HTrackAssociator::fillEcal::access::EcalBarrel");
263 // if (EBRecHitCollectionLabels.empty())
264 // throw cms::Exception("FatalError") << "Module lable is not set for EBRecHitCollection.\n";
265 // else
266  iEvent.getByLabel (EBRecHitCollectionLabels[0], EBRecHitCollectionLabels[1], EBRecHits);
267 // if (!EBRecHits.isValid()) throw cms::Exception("FatalError") << "Unable to find EBRecHitCollection in event!\n";
268  if (EERecHitCollectionLabels[1]!=EBRecHitCollectionLabels[1]) iEvent.getByLabel (EERecHitCollectionLabels[0], EERecHitCollectionLabels[1], EERecHits);
269 // if (!EERecHits.isValid()) throw cms::Exception("FatalError") << "Unable to find EERecHitCollection in event!\n";
270 
271  timers.pop_and_push("HTrackAssociator::fillEcal::matching");
272  std::set<DetId> ecalIdsInRegion = ecalDetIdAssociator_.getDetIdsCloseToAPoint(ecalTrajectory[0],idR);
273  std::set<DetId> ecalIdsInACone = ecalDetIdAssociator_.getDetIdsInACone(ecalIdsInRegion, ecalTrajectory, dR);
274  std::set<DetId> crossedEcalIds = ecalDetIdAssociator_.getCrossedDetIds(ecalIdsInRegion, ecalTrajectory);
275 
276  // add EcalRecHits
277  timers.pop_and_push("HTrackAssociator::fillEcal::addEcalRecHits");
278  for(std::set<DetId>::const_iterator itr=crossedEcalIds.begin(); itr!=crossedEcalIds.end();itr++) {
279  std::vector<EcalRecHit>::const_iterator hit = (*EBRecHits).find(*itr);
280  if(hit != (*EBRecHits).end())
281  info.crossedEcalRecHits.push_back(*hit);
282  else
283  LogTrace("HTrackAssociator::fillEcal") << "EcalRecHit is not found for DetId: " << itr->rawId() <<"\n";
284  }
285  for(std::set<DetId>::const_iterator itr=ecalIdsInACone.begin(); itr!=ecalIdsInACone.end();itr++) {
286  std::vector<EcalRecHit>::const_iterator hit = (*EBRecHits).find(*itr);
287  if(hit != (*EBRecHits).end()) {
288  info.coneEcalRecHits.push_back(*hit);
289  }
290  else
291  LogTrace("HTrackAssociator::fillEcal") << "EcalRecHit is not found for DetId: " << itr->rawId() <<"\n";
292  }
293  if (EERecHitCollectionLabels[1]==EBRecHitCollectionLabels[1])return;
294  for(std::set<DetId>::const_iterator itr=crossedEcalIds.begin(); itr!=crossedEcalIds.end();itr++) {
295  std::vector<EcalRecHit>::const_iterator hit = (*EERecHits).find(*itr);
296  if(hit != (*EERecHits).end())
297  info.crossedEcalRecHits.push_back(*hit);
298  else
299  LogTrace("HTrackAssociator::fillEcal") << "EcalRecHit is not found for DetId: " << itr->rawId() <<"\n";
300  }
301  for(std::set<DetId>::const_iterator itr=ecalIdsInACone.begin(); itr!=ecalIdsInACone.end();itr++) {
302  std::vector<EcalRecHit>::const_iterator hit = (*EERecHits).find(*itr);
303  if(hit != (*EERecHits).end()) {
304  info.coneEcalRecHits.push_back(*hit);
305  }
306  else
307  LogTrace("HTrackAssociator::fillEcal") << "EcalRecHit is not found for DetId: " << itr->rawId() <<"\n";
308  }
309 }
310 
311 //-----------------------------------------------------------------------------
313  const edm::EventSetup& iSetup,
315  const FreeTrajectoryState& trajectoryPoint,
316  const int idR,
317  const double dR)
318 {
319  // ECAL hits are not used for the CaloTower identification
320  HTimerStack timers;
321  timers.push("HTrackAssociator::fillCaloTowers");
322 
323  caloDetIdAssociator_.setGeometry(&*theCaloGeometry_);
324 
325  // HCAL points (HB+HE)
326  timers.push("HTrackAssociator::fillCaloTowers::propagation");
327  std::vector<GlobalPoint> hcalPoints;
328  hcalPoints.push_back(GlobalPoint(135.,0,310.));
329  hcalPoints.push_back(GlobalPoint(150.,0,340.));
330  hcalPoints.push_back(GlobalPoint(170.,0,370.));
331  hcalPoints.push_back(GlobalPoint(190.,0,400.));
332  hcalPoints.push_back(GlobalPoint(240.,0,500.));
333  hcalPoints.push_back(GlobalPoint(280.,0,550.));
334 
335  std::vector<GlobalPoint> hcalTrajectory = caloDetIdAssociator_.getTrajectory(trajectoryPoint, hcalPoints);
336 // if(hcalTrajectory.empty()) throw cms::Exception("FatalError") << "Failed to propagate the track to HCAL\n";
337 
338  if(hcalTrajectory.empty()) {
339  LogTrace("HTrackAssociator::fillEcal") << "Failed to propagate a track to ECAL; moving on\n";
340  info.isGoodCalo = 0;
341  info.isGoodEcal = 0;
342  std::cout<<" HTrackAssociator::fillCaloTowers::Failed to propagate a track to ECAL "<<std::endl;
343  return;
344  }
345 
346  info.isGoodCalo = 1;
347  info.isGoodEcal = 1;
348  info.trkGlobPosAtEcal = getPoint(hcalTrajectory[0]);
349 
350  if(hcalTrajectory.size()<4) {
351  LogTrace("HTrackAssociator::fillEcal") << "Failed to propagate a track to HCAL; moving on\n";
352  info.isGoodHcal = 0;
353  }
354 
355  info.isGoodHcal = 1;
356 
357  info.trkGlobPosAtHcal = getPoint(hcalTrajectory[4]);
358 
359  // find crossed CaloTowers
360  timers.pop_and_push("HTrackAssociator::fillCaloTowers::access::CaloTowers");
362 
363  if (CaloTowerCollectionLabels.empty())
364  throw cms::Exception("FatalError") << "Module lable is not set for CaloTowers.\n";
365  else
366  iEvent.getByLabel (CaloTowerCollectionLabels[0], CaloTowerCollectionLabels[1], caloTowers);
367  if (!caloTowers.isValid()) throw cms::Exception("FatalError") << "Unable to find CaloTowers in event!\n";
368 
369  timers.push("HTrackAssociator::fillCaloTowers::matching");
370 
371 // first get DetIds in a predefined NxN region
372 // std::set<DetId> caloTowerIdsInBigRegion = caloDetIdAssociator_.getDetIdsCloseToAPoint(hcalTrajectory[0],idR+1);
373  std::set<DetId> caloTowerIdsInRegion = caloDetIdAssociator_.getDetIdsCloseToAPoint(hcalTrajectory[0],idR);
374 
375  std::set<DetId> caloTowerIdsInACone;
376  std::set<DetId> crossedCaloTowerIds;
377  std::set<DetId> caloTowerIdsInBox;
378  caloTowerIdsInACone = caloDetIdAssociator_.getDetIdsInACone(caloTowerIdsInRegion, hcalTrajectory, dR);
379 // get DetId of the most energetic tower in that region
380  crossedCaloTowerIds = caloDetIdAssociator_.getMaxEDetId(caloTowerIdsInRegion, caloTowers);
381 // get DetIds of the towers surrounding the most energetic one
382  caloTowerIdsInBox = caloDetIdAssociator_.getDetIdsInACone(crossedCaloTowerIds, hcalTrajectory, -1.);
383 
384 //
385 // Debug prints
386 //
387 // std::cout <<" Debug printout in CaloTowers "<<std::endl;
388 // std::cout <<" with position at outer layer:r,z,phi "<<trajectoryPoint.position().eta()<<
389 // " "<<trajectoryPoint.position().phi()<<
390 // " "<<trajectoryPoint.position().perp()<<
391 // " "<<trajectoryPoint.position().z()<<
392 // " "<<trajectoryPoint.charge()<<std::endl;
393 // std::cout <<" Trajectory point at ECAL surface:eta:phi:radius:z "<<(hcalTrajectory[0]).eta()<<
394 // " "<<(hcalTrajectory[0]).phi()<<
395 // " "<<(hcalTrajectory[0]).perp()<<
396 // " "<<(hcalTrajectory[0]).z()<<
397 // " momentum "<<trajectoryPoint.momentum().perp()<<std::endl;
398 //
399 // std::cout<<" Number of towers in the region "<<caloTowerIdsInRegion.size()<<" idR= "<<idR<<std::endl;
400 
401  // add CaloTowers
402  timers.push("HTrackAssociator::fillCaloTowers::addCaloTowers");
403  for(std::set<DetId>::const_iterator itr=crossedCaloTowerIds.begin(); itr!=crossedCaloTowerIds.end();itr++)
404  {
405  DetId id(*itr);
406  CaloTowerCollection::const_iterator tower = (*caloTowers).find(id);
407  if(tower != (*caloTowers).end())
408  info.crossedTowers.push_back(*tower);
409  else
410  LogTrace("HTrackAssociator::fillEcal") << "CaloTower is not found for DetId: " << id.rawId() << "\n";
411  }
412 
413  for(std::set<DetId>::const_iterator itr=caloTowerIdsInACone.begin(); itr!=caloTowerIdsInACone.end();itr++)
414  {
415  DetId id(*itr);
416  CaloTowerCollection::const_iterator tower = (*caloTowers).find(id);
417  if(tower != (*caloTowers).end()) {
418  info.coneTowers.push_back(*tower);
419  }
420  else
421  LogTrace("HTrackAssociator::fillEcal") << "CaloTower is not found for DetId: " << id.rawId() << "\n";
422  }
423 
424  for(std::set<DetId>::const_iterator itr=caloTowerIdsInBox.begin(); itr!=caloTowerIdsInBox.end();itr++)
425  {
426  DetId id(*itr);
427  CaloTowerCollection::const_iterator tower = (*caloTowers).find(id);
428  if(tower != (*caloTowers).end()) {
429  info.boxTowers.push_back(*tower);
430  }
431  else
432  LogTrace("HTrackAssociator::fillEcal") << "CaloTower is not found for DetId: " << id.rawId() << "\n";
433  }
434 
435  for(std::set<DetId>::const_iterator itr=caloTowerIdsInRegion.begin(); itr!=caloTowerIdsInRegion.end();itr++)
436  {
437  DetId id(*itr);
438  CaloTowerCollection::const_iterator tower = (*caloTowers).find(id);
439  if(tower != (*caloTowers).end()) {
440  info.regionTowers.push_back(*tower);
441  }
442  else
443  LogTrace("HTrackAssociator::fillEcal") << "CaloTower is not found for DetId: " << id.rawId() << "\n";
444  }
445 
446 }
447 
448 //-----------------------------------------------------------------------------
450  const edm::EventSetup& iSetup,
452  const FreeTrajectoryState& trajectoryPoint,
453  const int idR,
454  const double dR) {
455  HTimerStack timers;
456  timers.push("HTrackAssociator::fillHcal");
457 
458  hcalDetIdAssociator_.setGeometry(&*theCaloGeometry_);
459 
460 // HCAL points (HB+HE)
461  timers.push("HTrackAssociator::fillHcal::propagation");
462  std::vector<GlobalPoint> hcalPoints;
463  hcalPoints.push_back(GlobalPoint(190.,0,400.));
464  hcalPoints.push_back(GlobalPoint(240.,0,500.));
465  hcalPoints.push_back(GlobalPoint(280.,0,550.));
466 
467  std::vector<GlobalPoint> hcalTrajectory = hcalDetIdAssociator_.getTrajectory(trajectoryPoint, hcalPoints);
468 // if(hcalTrajectory.empty()) throw cms::Exception("FatalError") << "Failed to propagate the track to HCAL\n";
469 
470  if(hcalTrajectory.empty()) {
471  LogTrace("HTrackAssociator::fillHcal") << "Failed to propagate a track to HCAL; moving on\n";
472  info.isGoodHcal = 0;
473 // std::cout<<" HTrackAssociator::fillHcal::Failed to propagate a track to HCAL "<<std::endl;
474  return;
475  }
476 
477  info.isGoodHcal = 1;
478 
479  info.trkGlobPosAtHcal = getPoint(hcalTrajectory[0]);
480  timers.pop_and_push("HTrackAssociator::fillHcal::access::Hcal");
481 
483 // if (HBHERecHitCollectionLabels.empty())
484 // throw cms::Exception("FatalError") << "Module label is not set for HBHERecHitCollection.\n";
485 // else
486  iEvent.getByLabel (HBHERecHitCollectionLabels[0], HBHERecHitCollectionLabels[1], HBHERecHits);
487  if (!HBHERecHits.isValid()) throw cms::Exception("FatalError") << "Unable to find HBHERecHitCollection in event!\n";
488 
489  timers.pop_and_push("HTrackAssociator::fillHcal::matching");
490 
491 // first get DetIds in a predefined NxN region
492 // std::set<DetId> hcalIdsInBigRegion = hcalDetIdAssociator_.getDetIdsCloseToAPoint(hcalTrajectory[0],idR+1);
493  std::set<DetId> hcalIdsInRegion = hcalDetIdAssociator_.getDetIdsCloseToAPoint(hcalTrajectory[0],idR);
494 
495  std::set<DetId> hcalIdsInACone;
496  std::set<DetId> crossedHcalIds;
497  std::set<DetId> hcalIdsInBox;
498  hcalIdsInACone = hcalDetIdAssociator_.getDetIdsInACone(hcalIdsInRegion, hcalTrajectory, dR);
499 // get DetId of the most energetic tower in that region
500  crossedHcalIds = hcalDetIdAssociator_.getMaxEDetId(hcalIdsInRegion, HBHERecHits);
501 // get DetIds of the towers surrounding the most energetic one
502  hcalIdsInBox = hcalDetIdAssociator_.getDetIdsInACone(crossedHcalIds, hcalTrajectory, -1.);
503 
504 // add HcalRecHits
505  timers.pop_and_push("HTrackAssociator::fillHcal::addHcalRecHits");
506  for(std::set<DetId>::const_iterator itr=crossedHcalIds.begin(); itr!=crossedHcalIds.end();itr++) {
507  std::vector<HBHERecHit>::const_iterator hit = (*HBHERecHits).find(*itr);
508  if(hit != (*HBHERecHits).end())
509  info.crossedHcalRecHits.push_back(*hit);
510  else
511  LogTrace("HTrackAssociator::fillHcal") << "HcalRecHit is not found for DetId: " << itr->rawId() <<"\n";
512  }
513  for(std::set<DetId>::const_iterator itr=hcalIdsInACone.begin(); itr!=hcalIdsInACone.end();itr++) {
514  std::vector<HBHERecHit>::const_iterator hit = (*HBHERecHits).find(*itr);
515  if(hit != (*HBHERecHits).end())
516  info.coneHcalRecHits.push_back(*hit);
517  else
518  LogTrace("HTrackAssociator::fillHcal") << "HcalRecHit is not found for DetId: " << itr->rawId() <<"\n";
519  }
520  for(std::set<DetId>::const_iterator itr=hcalIdsInBox.begin(); itr!=hcalIdsInBox.end();itr++) {
521  std::vector<HBHERecHit>::const_iterator hit = (*HBHERecHits).find(*itr);
522  if(hit != (*HBHERecHits).end())
523  info.boxHcalRecHits.push_back(*hit);
524  else
525  LogTrace("HTrackAssociator::fillHcal") << "HcalRecHit is not found for DetId: " << itr->rawId() <<"\n";
526  }
527  for(std::set<DetId>::const_iterator itr=hcalIdsInRegion.begin(); itr!=hcalIdsInRegion.end();itr++) {
528  std::vector<HBHERecHit>::const_iterator hit = (*HBHERecHits).find(*itr);
529  if(hit != (*HBHERecHits).end())
530  info.regionHcalRecHits.push_back(*hit);
531  else
532  LogTrace("HTrackAssociator::fillHcal") << "HcalRecHit is not found for DetId: " << itr->rawId() <<"\n";
533  }
534 }
535 
536 //-----------------------------------------------------------------------------
538  const edm::EventSetup& iSetup,
540  const FreeTrajectoryState& trajectoryPoint,
541  const int idR,
542  const double dR)
543 {
544  // ECAL hits are not used for the CaloTower identification
545  HTimerStack timers;
546  timers.push("HTrackAssociator::fillCaloTowers");
547 
548  caloDetIdAssociator_.setGeometry(&*theCaloGeometry_);
549 
550  // HCAL points (HB+HE)
551  timers.push("HTrackAssociator::fillCaloTowers::propagation");
552  std::vector<GlobalPoint> hcalPoints;
553  hcalPoints.push_back(GlobalPoint(190.,0,400.));
554  hcalPoints.push_back(GlobalPoint(240.,0,500.));
555  hcalPoints.push_back(GlobalPoint(280.,0,550.));
556 
557  std::vector<GlobalPoint> hcalTrajectory = caloDetIdAssociator_.getTrajectory(trajectoryPoint, hcalPoints);
558 // if(hcalTrajectory.empty()) throw cms::Exception("FatalError") << "Failed to propagate the track to HCAL\n";
559 
560  if(hcalTrajectory.empty()) {
561  LogTrace("HTrackAssociator::fillEcal") << "Failed to propagate a track to HCAL; moving on\n";
562  info.isGoodCalo = 0;
563  std::cout<<" HTrackAssociator::fillCaloTowers::Failed to propagate a track to HCAL "<<std::endl;
564  return;
565  }
566 
567  info.isGoodCalo = 1;
568 
569  info.trkGlobPosAtHcal = getPoint(hcalTrajectory[0]);
570 
571  // find crossed CaloTowers
572  timers.pop_and_push("HTrackAssociator::fillCaloTowers::access::CaloTowers");
574 
575  if (CaloTowerCollectionLabels.empty())
576  throw cms::Exception("FatalError") << "Module lable is not set for CaloTowers.\n";
577  else
578  iEvent.getByLabel (CaloTowerCollectionLabels[0], CaloTowerCollectionLabels[1], caloTowers);
579  if (!caloTowers.isValid()) throw cms::Exception("FatalError") << "Unable to find CaloTowers in event!\n";
580 
581  timers.push("HTrackAssociator::fillCaloTowers::matching");
582 
583 // first get DetIds in a predefined NxN region
584  std::set<DetId> caloTowerIdsInBigRegion = caloDetIdAssociator_.getDetIdsCloseToAPoint(hcalTrajectory[0],idR+1);
585  std::set<DetId> caloTowerIdsInRegion = caloDetIdAssociator_.getDetIdsCloseToAPoint(hcalTrajectory[0],idR);
586 
587  std::set<DetId> caloTowerIdsInACone;
588  std::set<DetId> crossedCaloTowerIds;
589  std::set<DetId> caloTowerIdsInBox;
590  caloTowerIdsInACone = caloDetIdAssociator_.getDetIdsInACone(caloTowerIdsInBigRegion, hcalTrajectory, dR);
591 // get DetId of the most energetic tower in that region
592  crossedCaloTowerIds = caloDetIdAssociator_.getMaxEDetId(caloTowerIdsInRegion, caloTowers);
593 // get DetIds of the towers surrounding the most energetic one
594  caloTowerIdsInBox = caloDetIdAssociator_.getDetIdsInACone(crossedCaloTowerIds, hcalTrajectory, -1.);
595 
596  // add CaloTowers
597  timers.push("HTrackAssociator::fillCaloTowers::addCaloTowers");
598  for(std::set<DetId>::const_iterator itr=crossedCaloTowerIds.begin(); itr!=crossedCaloTowerIds.end();itr++)
599  {
600  DetId id(*itr);
601  CaloTowerCollection::const_iterator tower = (*caloTowers).find(id);
602  if(tower != (*caloTowers).end())
603  info.crossedTowers.push_back(*tower);
604  else
605  LogTrace("HTrackAssociator::fillEcal") << "CaloTower is not found for DetId: " << id.rawId() << "\n";
606  }
607 
608  for(std::set<DetId>::const_iterator itr=caloTowerIdsInACone.begin(); itr!=caloTowerIdsInACone.end();itr++)
609  {
610  DetId id(*itr);
611  CaloTowerCollection::const_iterator tower = (*caloTowers).find(id);
612  if(tower != (*caloTowers).end())
613  info.coneTowers.push_back(*tower);
614  else
615  LogTrace("HTrackAssociator::fillEcal") << "CaloTower is not found for DetId: " << id.rawId() << "\n";
616  }
617 
618 }
619 
620 //-----------------------------------------------------------------------------
622  const SimTrack& track,
623  const SimVertex& vertex )
624 {
626  iSetup.get<IdealMagneticFieldRecord>().get(bField);
627 
628  GlobalVector vector( track.momentum().x(), track.momentum().y(), track.momentum().z() );
629  // convert mm to cm
630  GlobalPoint point( vertex.position().x()*.1, vertex.position().y()*.1, vertex.position().z()*.1 );
631  int charge = track.type( )> 0 ? -1 : 1;
632  GlobalTrajectoryParameters tPars(point, vector, charge, &*bField);
633 
634  AlgebraicSymMatrix66 covT= AlgebraicMatrixID(); covT *= 1e-6; // initialize to sigma=1e-3
635  CartesianTrajectoryError tCov(covT);
636 
637  return FreeTrajectoryState(tPars, tCov);
638 }
639 
640 //-----------------------------------------------------------------------------
642  const reco::Track& track )
643 {
645  iSetup.get<IdealMagneticFieldRecord>().get(bField);
646 
647  GlobalVector vector( track.momentum().x(), track.momentum().y(), track.momentum().z() );
648 
649  GlobalPoint point( track.vertex().x(), track.vertex().y(), track.vertex().z() );
650 
651  GlobalTrajectoryParameters tPars(point, vector, track.charge(), &*bField);
652 
653  // FIX THIS !!!
654  // need to convert from perigee to global or helix (curvilinear) frame
655  // for now just an arbitrary matrix.
656  AlgebraicSymMatrix66 covT= AlgebraicMatrixID(); covT *= 1e-6; // initialize to sigma=1e-3
657  CartesianTrajectoryError tCov(covT);
658 
659  return FreeTrajectoryState(tPars, tCov);
660 }
661 
std::vector< CaloTower > crossedTowers
dictionary parameters
Definition: Parameters.py:2
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:150
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
void push(std::string name)
Definition: TimerStack.h:13
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
std::vector< EcalRecHit > crossedEcalRecHits
int init
Definition: HydjetWrapper.h:63
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)
double charge(const std::vector< uint8_t > &Ampls)
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
void pop_and_push(std::string name)
Definition: TimerStack.h:31
std::vector< EcalRecHit > coneEcalRecHits
double hcalEnergyFromRecHits()
HCAL energy.
int iEvent
Definition: GenABIO.cc:243
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:76
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:356
#define LogTrace(id)
void useDefaultPropagator()
use the default propagator
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:156
Definition: DetId.h:20
std::vector< CaloTower > regionTowers
const T & get() const
Definition: EventSetup.h:55
std::vector< CaloTower > coneTowers
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:40
const math::XYZTLorentzVectorD & momentum() const
particle info...
Definition: CoreSimTrack.h:36
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:121
int charge() const
track electric charge
Definition: TrackBase.h:113
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