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