1 #ifndef ECALBOUNDARYINFOCALCULATOR_H_
2 #define ECALBOUNDARYINFOCALCULATOR_H_
26 template <
class EcalDetId>
46 std::vector<int>& stati)
const {
48 EcalDetId hitdetid = EcalDetId(
hit.
id());
53 int hitIeta = ebhitdetid.
ieta();
54 int hitIphi = ebhitdetid.
iphi();
61 int neighbourIeta = hitIeta +
ieta;
62 int neighbourIphi = hitIphi +
iphi;
64 if (neighbourIphi < 1)
66 if (neighbourIphi > 360)
68 if (neighbourIeta == 0) {
69 neighbourIeta +=
ieta;
76 int status = (chit != ecalStatus->
end()) ? chit->getStatusCode() & 0x1F : -1;
80 for (std::vector<int>::const_iterator
s = stati.begin();
s != stati.end(); ++
s) {
95 int hitIx = eehitdetid.
ix();
96 int hitIy = eehitdetid.
iy();
97 int hitIz = eehitdetid.
zside();
99 for (
int ix = -1; ix <= 1; ix++) {
100 for (
int iy = -1; iy <= 1; iy++) {
101 if ((ix == 0 && iy == 0) || ix * iy != 0)
104 int neighbourIx = hitIx + ix;
105 int neighbourIy = hitIy + iy;
110 int status = (chit != ecalStatus->
end()) ? chit->getStatusCode() & 0x1F : -1;
113 bool present =
false;
114 for (std::vector<int>::const_iterator
s = stati.begin();
s != stati.end(); ++
s) {
128 edm::LogWarning(
"EcalBoundaryInfoCalculator") <<
"ERROR - RecHit belongs to wrong sub detector";
139 EcalDetId hitdetid = EcalDetId(
hit.
id());
144 int hitIeta = ebhitdetid.
ieta();
145 int hitIphi = ebhitdetid.
iphi();
152 int neighbourIeta = hitIeta +
ieta;
153 int neighbourIphi = hitIphi +
iphi;
155 if (neighbourIphi < 1)
156 neighbourIphi += 360;
157 if (neighbourIphi > 360)
158 neighbourIphi -= 360;
159 if (neighbourIeta == 0) {
160 neighbourIeta +=
ieta;
172 int hitIx = eehitdetid.
ix();
173 int hitIy = eehitdetid.
iy();
174 int hitIz = eehitdetid.
zside();
176 for (
int ix = -1; ix <= 1; ix++) {
177 for (
int iy = -1; iy <= 1; iy++) {
178 if ((ix == 0 && iy == 0) || ix * iy != 0)
181 int neighbourIx = hitIx + ix;
182 int neighbourIy = hitIy + iy;
191 edm::LogWarning(
"EcalBoundaryInfoCalculator") <<
"ERROR - RecHit belongs to wrong sub detector";
198 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"set Debug Mode!";
232 oppDirection = oIt->second;
235 EcalDetId currDetId = theEcalNav->
pos();
242 std::map<CdOrientation, CdOrientation> turnMap =
nextDirs;
243 if (reverseOrientation)
245 std::map<CdOrientation, CdOrientation>::iterator nIt = turnMap.find(currDirection);
247 if (nIt != turnMap.end())
248 nextDirection = (*nIt).second;
250 edm::LogWarning(
"EcalBoundaryInfoCalculator") <<
"ERROR - no Next Direction found!?!?";
251 return nextDirection;
256 std::map<CdOrientation, CdOrientation> turnMap =
prevDirs;
257 if (reverseOrientation)
259 std::map<CdOrientation, CdOrientation>::iterator nIt = turnMap.find(currDirection);
261 if (nIt != turnMap.end())
262 nextDirection = (*nIt).second;
264 edm::LogWarning(
"EcalBoundaryInfoCalculator") <<
"ERROR - no Next Direction found!?!?";
265 return nextDirection;
271 std::unique_ptr<CaloNavigator<EcalDetId>> theEcalNav(
nullptr);
280 <<
"initializeEcalNavigator not implemented for subDet: " << ecalSubDet;
291 template <
class EcalDetId>
305 oppositeDirs.clear();
314 template <
class EcalDetId>
317 template <
class EcalDetId>
325 std::vector<EcalRecHit> boundaryRecHits;
326 std::vector<DetId> boundaryDetIds;
327 std::vector<int> stati;
329 double boundaryEnergy = 0;
330 double boundaryET = 0;
331 int beCellCounter = 0;
332 bool nextToBorder =
false;
334 boundaryRecHits.push_back(*
hit);
336 boundaryEnergy +=
hit->energy();
337 EcalDetId hitdetid = (EcalDetId)
hit->
id();
338 boundaryDetIds.push_back(hitdetid);
341 double eta = cellGeom->getPosition().eta();
342 boundaryET +=
hit->energy() / cosh(
eta);
345 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"Find Boundary RecHits...";
349 <<
"Starting at : (" << ((
EBDetId)hitdetid).ieta() <<
"," << ((
EBDetId)hitdetid).iphi() <<
")";
352 <<
"Starting at : (" << ((
EEDetId)hitdetid).ix() <<
"," << ((
EEDetId)hitdetid).iy() <<
")";
357 auto theEcalNav = initializeEcalNavigator(hitdetid, theCaloTopology, EcalDetId::subdet());
359 bool reverseOrientation =
false;
362 EcalDetId
start = hitdetid;
363 EcalDetId current =
start;
364 int current_status = 0;
367 bool startAlgo =
false;
370 next = makeStepInDirection(currDirection, theEcalNav.get());
371 theEcalNav->setHome(current);
374 int status = (chit != ecalStatus->
end()) ? chit->getStatusCode() & 0x1F : -1;
380 currDirection = turnLeft(currDirection, reverseOrientation);
383 throw cms::Exception(
"NoStartingDirection") <<
"EcalBoundaryInfoCalculator: No starting direction can be found: "
384 "This should never happen if RecHit has a dead neighbour!";
389 currDirection = turnRight(currDirection, reverseOrientation);
392 bool nextIsStart =
false;
393 bool atBorder =
false;
395 while (!nextIsStart) {
396 bool nextStepFound =
false;
399 while (!nextStepFound) {
400 next = makeStepInDirection(currDirection, theEcalNav.get());
401 theEcalNav->setHome(current);
404 status = (chit != ecalStatus->
end()) ? chit->getStatusCode() & 0x1F : -1;
407 bool present =
false;
408 for (std::vector<int>::const_iterator
s = stati.begin();
s != stati.end(); ++
s) {
418 nextStepFound =
true;
420 currDirection = turnRight(currDirection, reverseOrientation);
422 }
else if (
next == EcalDetId(0)) {
424 currDirection = turnLeft(currDirection, reverseOrientation);
427 nextStepFound =
true;
432 <<
"EcalBoundaryInfoCalculator: No valid next direction can be found: This should never happen!";
437 next = makeStepInDirection(currDirection, theEcalNav.get());
442 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"Boundary path reached starting position!";
447 <<
"Next step: " << (EcalDetId)
next <<
" Status: " <<
status <<
" Start: " << (EcalDetId)
start;
450 if ((!atBorder ||
status == 0) && !nextIsStart) {
451 boundaryDetIds.push_back(
next);
455 boundaryRecHits.push_back(nexthit);
456 boundaryEnergy += nexthit.
energy();
458 eta = cellGeom->getPosition().eta();
459 boundaryET += nexthit.
energy() / cosh(
eta);
463 if (current_status == 0 &&
status == 0 && atBorder) {
465 currDirection = turnRight(currDirection, reverseOrientation);
468 if (
status == 0 && atBorder) {
470 currDirection = turnLeft(currDirection, reverseOrientation);
474 currDirection = turnLeft(currDirection, reverseOrientation);
477 currDirection = turnRight(currDirection, reverseOrientation);
487 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"<<<<<<<<<<<<<<< Final Boundary object <<<<<<<<<<<<<<<";
488 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"no of neighbouring RecHits: " << boundaryRecHits.size();
489 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"no of neighbouring DetIds: " << boundaryDetIds.size();
490 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"boundary energy: " << boundaryEnergy;
491 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"boundary ET: " << boundaryET;
492 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"no of cells contributing to boundary energy: " << beCellCounter;
493 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"Channel stati: ";
494 for (std::vector<int>::iterator it = stati.begin(); it != stati.end(); ++it) {
495 edm::LogInfo(
"EcalBoundaryInfoCalculator") << *it <<
" ";
501 boundInfo.
subdet = hitdetid.subdet();
502 boundInfo.
detIds = boundaryDetIds;
503 boundInfo.
recHits = boundaryRecHits;
512 template <
class EcalDetId>
519 std::vector<EcalRecHit> gapRecHits;
520 std::vector<DetId> gapDetIds;
522 double gapEnergy = 0;
524 int gapCellCounter = 0;
525 bool nextToBorder =
false;
527 gapRecHits.push_back(*
hit);
529 gapEnergy +=
hit->energy();
530 EcalDetId hitdetid = (EcalDetId)
hit->
id();
531 gapDetIds.push_back(hitdetid);
534 double eta = cellGeom->getPosition().eta();
535 gapET +=
hit->energy() / cosh(
eta);
538 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"Find Border RecHits...";
542 <<
"Starting at : (" << ((
EBDetId)hitdetid).ieta() <<
"," << ((
EBDetId)hitdetid).iphi() <<
")";
545 <<
"Starting at : (" << ((
EEDetId)hitdetid).ix() <<
"," << ((
EEDetId)hitdetid).iy() <<
")";
550 auto theEcalNav = initializeEcalNavigator(hitdetid, theCaloTopology, EcalDetId::subdet());
552 bool reverseOrientation =
false;
555 EcalDetId
start = hitdetid;
556 EcalDetId current =
start;
559 bool startAlgo =
false;
562 next = makeStepInDirection(currDirection, theEcalNav.get());
563 theEcalNav->setHome(
start);
565 if (
next == EcalDetId(0)) {
570 currDirection = turnLeft(currDirection, reverseOrientation);
573 throw cms::Exception(
"NoStartingDirection") <<
"EcalBoundaryInfoCalculator: No starting direction can be found: "
574 "This should never happen if RecHit is at border!";
580 currDirection = turnLeft(currDirection, reverseOrientation);
583 bool endIsFound =
false;
584 bool startIsEnd =
false;
586 while (!endIsFound) {
587 bool nextStepFound =
false;
590 while (!nextStepFound) {
591 next = makeStepInDirection(currDirection, theEcalNav.get());
592 theEcalNav->setHome(current);
595 status = (chit != ecalStatus->
end()) ? chit->getStatusCode() & 0x1F : -1;
600 }
else if (
next == EcalDetId(0)) {
602 currDirection = turnLeft(currDirection, reverseOrientation);
605 nextStepFound =
true;
614 <<
"EcalBoundaryInfoCalculator: No valid next direction can be found: This should never happen!";
619 next = makeStepInDirection(currDirection, theEcalNav.get());
626 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"Path along gap reached starting position!";
631 <<
"Next step: " << (EcalDetId)
next <<
" Status: " <<
status <<
" Start: " << (EcalDetId)
start;
633 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"End of gap cluster is found going left";
638 gapDetIds.push_back(
next);
642 gapRecHits.push_back(nexthit);
643 gapEnergy += nexthit.
energy();
645 eta = cellGeom->getPosition().eta();
651 currDirection = turnRight(currDirection, reverseOrientation);
655 theEcalNav->setHome(
start);
658 currDirection = startDirection;
659 currDirection = turnRight(currDirection, reverseOrientation);
665 while (!endIsFound) {
666 bool nextStepFound =
false;
669 while (!nextStepFound) {
670 next = makeStepInDirection(currDirection, theEcalNav.get());
671 theEcalNav->setHome(current);
674 status = (chit != ecalStatus->
end()) ? chit->getStatusCode() & 0x1F : -1;
679 }
else if (
next == EcalDetId(0)) {
681 currDirection = turnRight(currDirection, reverseOrientation);
684 nextStepFound =
true;
693 <<
"EcalBoundaryInfoCalculator: No valid next direction can be found: This should never happen!";
698 next = makeStepInDirection(currDirection, theEcalNav.get());
703 <<
"Next step: " << (EcalDetId)
next <<
" Status: " <<
status <<
" Start: " << (EcalDetId)
start;
705 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"End of gap cluster is found going right";
710 gapDetIds.push_back(
next);
714 gapRecHits.push_back(nexthit);
715 gapEnergy += nexthit.
energy();
717 eta = cellGeom->getPosition().eta();
723 currDirection = turnLeft(currDirection, reverseOrientation);
728 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"<<<<<<<<<<<<<<< Final Gap object <<<<<<<<<<<<<<<";
729 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"No of RecHits along gap: " << gapRecHits.size();
730 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"No of DetIds along gap: " << gapDetIds.size();
731 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"Gap energy: " << gapEnergy;
732 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"Gap ET: " << gapET;
736 gapInfo.
subdet = hitdetid.subdet();
737 gapInfo.
detIds = gapDetIds;
742 std::vector<int> stati;