48 caloTowerMap_ =
nullptr;
49 useDefaultPropagator_ =
false;
62 EBRecHitCollectionLabels.clear();
64 EBRecHitCollectionLabels.push_back(productInstanceLabel);
67 EERecHitCollectionLabels.clear();
69 EERecHitCollectionLabels.push_back(productInstanceLabel);
71 if (
className ==
"HBHERecHitCollection") {
72 HBHERecHitCollectionLabels.clear();
74 HBHERecHitCollectionLabels.push_back(productInstanceLabel);
77 CaloTowerCollectionLabels.clear();
79 CaloTowerCollectionLabels.push_back(productInstanceLabel);
86 caloDetIdAssociator_.setPropagator(ivProp_);
87 ecalDetIdAssociator_.setPropagator(ivProp_);
88 hcalDetIdAssociator_.setPropagator(ivProp_);
98 if (!theCaloGeometry_.isValid())
99 throw cms::Exception(
"FatalError") <<
"Unable to find IdealGeometryRecord in event!\n";
101 if (useDefaultPropagator_ && !defProp_) {
111 setPropagator(defProp_);
147 return info.coneEcalRecHits;
149 return info.crossedEcalRecHits;
162 return info.ecalConeEnergyFromRecHits();
164 return info.ecalEnergyFromRecHits();
177 return info.coneTowers;
179 return info.crossedTowers;
192 return info.hcalConeEnergyFromRecHits();
194 return info.hcalEnergyFromRecHits();
204 ecalDetIdAssociator_.setGeometry(&*theCaloGeometry_);
207 std::vector<GlobalPoint> ecalPoints;
212 std::vector<GlobalPoint> ecalTrajectory = ecalDetIdAssociator_.getTrajectory(trajectoryPoint, ecalPoints);
215 if (ecalTrajectory.empty()) {
216 LogTrace(
"HTrackAssociator::fillEcal") <<
"Failed to propagate a track to ECAL; moving on\n";
217 info.isGoodEcal =
false;
221 info.isGoodEcal =
true;
223 info.trkGlobPosAtEcal = getPoint(ecalTrajectory[0]);
231 iEvent.getByLabel(EBRecHitCollectionLabels[0], EBRecHitCollectionLabels[1],
EBRecHits);
233 if (EERecHitCollectionLabels[1] != EBRecHitCollectionLabels[1])
234 iEvent.getByLabel(EERecHitCollectionLabels[0], EERecHitCollectionLabels[1],
EERecHits);
237 std::set<DetId> ecalIdsInRegion = ecalDetIdAssociator_.getDetIdsCloseToAPoint(ecalTrajectory[0], idR);
238 std::set<DetId> ecalIdsInACone = ecalDetIdAssociator_.getDetIdsInACone(ecalIdsInRegion, ecalTrajectory,
dR);
239 std::set<DetId> crossedEcalIds = ecalDetIdAssociator_.getCrossedDetIds(ecalIdsInRegion, ecalTrajectory);
242 for (std::set<DetId>::const_iterator
itr = crossedEcalIds.begin();
itr != crossedEcalIds.end();
itr++) {
243 std::vector<EcalRecHit>::const_iterator
hit = (*EBRecHits).find(*
itr);
244 if (
hit != (*EBRecHits).end())
245 info.crossedEcalRecHits.push_back(*
hit);
247 LogTrace(
"HTrackAssociator::fillEcal") <<
"EcalRecHit is not found for DetId: " <<
itr->rawId() <<
"\n";
249 for (std::set<DetId>::const_iterator
itr = ecalIdsInACone.begin();
itr != ecalIdsInACone.end();
itr++) {
250 std::vector<EcalRecHit>::const_iterator
hit = (*EBRecHits).find(*
itr);
251 if (
hit != (*EBRecHits).end()) {
252 info.coneEcalRecHits.push_back(*
hit);
254 LogTrace(
"HTrackAssociator::fillEcal") <<
"EcalRecHit is not found for DetId: " <<
itr->rawId() <<
"\n";
256 if (EERecHitCollectionLabels[1] == EBRecHitCollectionLabels[1])
258 for (std::set<DetId>::const_iterator
itr = crossedEcalIds.begin();
itr != crossedEcalIds.end();
itr++) {
259 std::vector<EcalRecHit>::const_iterator
hit = (*EERecHits).find(*
itr);
260 if (
hit != (*EERecHits).end())
261 info.crossedEcalRecHits.push_back(*
hit);
263 LogTrace(
"HTrackAssociator::fillEcal") <<
"EcalRecHit is not found for DetId: " <<
itr->rawId() <<
"\n";
265 for (std::set<DetId>::const_iterator
itr = ecalIdsInACone.begin();
itr != ecalIdsInACone.end();
itr++) {
266 std::vector<EcalRecHit>::const_iterator
hit = (*EERecHits).find(*
itr);
267 if (
hit != (*EERecHits).end()) {
268 info.coneEcalRecHits.push_back(*
hit);
270 LogTrace(
"HTrackAssociator::fillEcal") <<
"EcalRecHit is not found for DetId: " <<
itr->rawId() <<
"\n";
282 caloDetIdAssociator_.setGeometry(&*theCaloGeometry_);
285 std::vector<GlobalPoint> hcalPoints;
293 std::vector<GlobalPoint> hcalTrajectory = caloDetIdAssociator_.getTrajectory(trajectoryPoint, hcalPoints);
296 if (hcalTrajectory.empty()) {
297 LogTrace(
"HTrackAssociator::fillEcal") <<
"Failed to propagate a track to ECAL; moving on\n";
298 info.isGoodCalo =
false;
299 info.isGoodEcal =
false;
300 std::cout <<
" HTrackAssociator::fillCaloTowers::Failed to propagate a track to ECAL " << std::endl;
304 info.isGoodCalo =
true;
305 info.isGoodEcal =
true;
306 info.trkGlobPosAtEcal = getPoint(hcalTrajectory[0]);
308 if (hcalTrajectory.size() < 4) {
309 LogTrace(
"HTrackAssociator::fillEcal") <<
"Failed to propagate a track to HCAL; moving on\n";
310 info.isGoodHcal =
false;
313 info.isGoodHcal =
true;
315 info.trkGlobPosAtHcal = getPoint(hcalTrajectory[4]);
320 if (CaloTowerCollectionLabels.empty())
321 throw cms::Exception(
"FatalError") <<
"Module lable is not set for CaloTowers.\n";
323 iEvent.getByLabel(CaloTowerCollectionLabels[0], CaloTowerCollectionLabels[1],
caloTowers);
325 throw cms::Exception(
"FatalError") <<
"Unable to find CaloTowers in event!\n";
329 std::set<DetId> caloTowerIdsInRegion = caloDetIdAssociator_.getDetIdsCloseToAPoint(hcalTrajectory[0], idR);
331 std::set<DetId> caloTowerIdsInACone;
332 std::set<DetId> crossedCaloTowerIds;
333 std::set<DetId> caloTowerIdsInBox;
334 caloTowerIdsInACone = caloDetIdAssociator_.getDetIdsInACone(caloTowerIdsInRegion, hcalTrajectory,
dR);
336 crossedCaloTowerIds = caloDetIdAssociator_.getMaxEDetId(caloTowerIdsInRegion,
caloTowers);
338 caloTowerIdsInBox = caloDetIdAssociator_.getDetIdsInACone(crossedCaloTowerIds, hcalTrajectory, -1.);
358 for (std::set<DetId>::const_iterator
itr = crossedCaloTowerIds.begin();
itr != crossedCaloTowerIds.end();
itr++) {
361 if (
tower != (*caloTowers).end())
364 LogTrace(
"HTrackAssociator::fillEcal") <<
"CaloTower is not found for DetId: " <<
id.rawId() <<
"\n";
367 for (std::set<DetId>::const_iterator
itr = caloTowerIdsInACone.begin();
itr != caloTowerIdsInACone.end();
itr++) {
370 if (
tower != (*caloTowers).end()) {
373 LogTrace(
"HTrackAssociator::fillEcal") <<
"CaloTower is not found for DetId: " <<
id.rawId() <<
"\n";
376 for (std::set<DetId>::const_iterator
itr = caloTowerIdsInBox.begin();
itr != caloTowerIdsInBox.end();
itr++) {
379 if (
tower != (*caloTowers).end()) {
382 LogTrace(
"HTrackAssociator::fillEcal") <<
"CaloTower is not found for DetId: " <<
id.rawId() <<
"\n";
385 for (std::set<DetId>::const_iterator
itr = caloTowerIdsInRegion.begin();
itr != caloTowerIdsInRegion.end();
itr++) {
388 if (
tower != (*caloTowers).end()) {
391 LogTrace(
"HTrackAssociator::fillEcal") <<
"CaloTower is not found for DetId: " <<
id.rawId() <<
"\n";
402 hcalDetIdAssociator_.setGeometry(&*theCaloGeometry_);
405 std::vector<GlobalPoint> hcalPoints;
410 std::vector<GlobalPoint> hcalTrajectory = hcalDetIdAssociator_.getTrajectory(trajectoryPoint, hcalPoints);
413 if (hcalTrajectory.empty()) {
414 LogTrace(
"HTrackAssociator::fillHcal") <<
"Failed to propagate a track to HCAL; moving on\n";
415 info.isGoodHcal =
false;
420 info.isGoodHcal =
true;
422 info.trkGlobPosAtHcal = getPoint(hcalTrajectory[0]);
428 iEvent.getByLabel(HBHERecHitCollectionLabels[0], HBHERecHitCollectionLabels[1],
HBHERecHits);
430 throw cms::Exception(
"FatalError") <<
"Unable to find HBHERecHitCollection in event!\n";
434 std::set<DetId> hcalIdsInRegion = hcalDetIdAssociator_.getDetIdsCloseToAPoint(hcalTrajectory[0], idR);
436 std::set<DetId> hcalIdsInACone;
437 std::set<DetId> crossedHcalIds;
438 std::set<DetId> hcalIdsInBox;
439 hcalIdsInACone = hcalDetIdAssociator_.getDetIdsInACone(hcalIdsInRegion, hcalTrajectory,
dR);
441 crossedHcalIds = hcalDetIdAssociator_.getMaxEDetId(hcalIdsInRegion,
HBHERecHits);
443 hcalIdsInBox = hcalDetIdAssociator_.getDetIdsInACone(crossedHcalIds, hcalTrajectory, -1.);
446 for (std::set<DetId>::const_iterator
itr = crossedHcalIds.begin();
itr != crossedHcalIds.end();
itr++) {
447 std::vector<HBHERecHit>::const_iterator
hit = (*HBHERecHits).find(*
itr);
448 if (
hit != (*HBHERecHits).end())
449 info.crossedHcalRecHits.push_back(*
hit);
451 LogTrace(
"HTrackAssociator::fillHcal") <<
"HcalRecHit is not found for DetId: " <<
itr->rawId() <<
"\n";
453 for (std::set<DetId>::const_iterator
itr = hcalIdsInACone.begin();
itr != hcalIdsInACone.end();
itr++) {
454 std::vector<HBHERecHit>::const_iterator
hit = (*HBHERecHits).find(*
itr);
455 if (
hit != (*HBHERecHits).end())
456 info.coneHcalRecHits.push_back(*
hit);
458 LogTrace(
"HTrackAssociator::fillHcal") <<
"HcalRecHit is not found for DetId: " <<
itr->rawId() <<
"\n";
460 for (std::set<DetId>::const_iterator
itr = hcalIdsInBox.begin();
itr != hcalIdsInBox.end();
itr++) {
461 std::vector<HBHERecHit>::const_iterator
hit = (*HBHERecHits).find(*
itr);
462 if (
hit != (*HBHERecHits).end())
463 info.boxHcalRecHits.push_back(*
hit);
465 LogTrace(
"HTrackAssociator::fillHcal") <<
"HcalRecHit is not found for DetId: " <<
itr->rawId() <<
"\n";
467 for (std::set<DetId>::const_iterator
itr = hcalIdsInRegion.begin();
itr != hcalIdsInRegion.end();
itr++) {
468 std::vector<HBHERecHit>::const_iterator
hit = (*HBHERecHits).find(*
itr);
469 if (
hit != (*HBHERecHits).end())
470 info.regionHcalRecHits.push_back(*
hit);
472 LogTrace(
"HTrackAssociator::fillHcal") <<
"HcalRecHit is not found for DetId: " <<
itr->rawId() <<
"\n";
484 caloDetIdAssociator_.setGeometry(&*theCaloGeometry_);
487 std::vector<GlobalPoint> hcalPoints;
492 std::vector<GlobalPoint> hcalTrajectory = caloDetIdAssociator_.getTrajectory(trajectoryPoint, hcalPoints);
495 if (hcalTrajectory.empty()) {
496 LogTrace(
"HTrackAssociator::fillEcal") <<
"Failed to propagate a track to HCAL; moving on\n";
497 info.isGoodCalo =
false;
498 std::cout <<
" HTrackAssociator::fillCaloTowers::Failed to propagate a track to HCAL " << std::endl;
502 info.isGoodCalo =
true;
504 info.trkGlobPosAtHcal = getPoint(hcalTrajectory[0]);
509 if (CaloTowerCollectionLabels.empty())
510 throw cms::Exception(
"FatalError") <<
"Module lable is not set for CaloTowers.\n";
512 iEvent.getByLabel(CaloTowerCollectionLabels[0], CaloTowerCollectionLabels[1],
caloTowers);
514 throw cms::Exception(
"FatalError") <<
"Unable to find CaloTowers in event!\n";
517 std::set<DetId> caloTowerIdsInBigRegion = caloDetIdAssociator_.getDetIdsCloseToAPoint(hcalTrajectory[0], idR + 1);
518 std::set<DetId> caloTowerIdsInRegion = caloDetIdAssociator_.getDetIdsCloseToAPoint(hcalTrajectory[0], idR);
520 std::set<DetId> caloTowerIdsInACone;
521 std::set<DetId> crossedCaloTowerIds;
522 std::set<DetId> caloTowerIdsInBox;
523 caloTowerIdsInACone = caloDetIdAssociator_.getDetIdsInACone(caloTowerIdsInBigRegion, hcalTrajectory,
dR);
525 crossedCaloTowerIds = caloDetIdAssociator_.getMaxEDetId(caloTowerIdsInRegion,
caloTowers);
527 caloTowerIdsInBox = caloDetIdAssociator_.getDetIdsInACone(crossedCaloTowerIds, hcalTrajectory, -1.);
530 for (std::set<DetId>::const_iterator
itr = crossedCaloTowerIds.begin();
itr != crossedCaloTowerIds.end();
itr++) {
533 if (
tower != (*caloTowers).end())
536 LogTrace(
"HTrackAssociator::fillEcal") <<
"CaloTower is not found for DetId: " <<
id.rawId() <<
"\n";
539 for (std::set<DetId>::const_iterator
itr = caloTowerIdsInACone.begin();
itr != caloTowerIdsInACone.end();
itr++) {
542 if (
tower != (*caloTowers).end())
545 LogTrace(
"HTrackAssociator::fillEcal") <<
"CaloTower is not found for DetId: " <<
id.rawId() <<
"\n";