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) {
87 stati.push_back(status);
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) {
121 stati.push_back(status);
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!";
207 next = theNavi->
north();
211 next = theNavi->
east();
215 next = theNavi->
south();
219 next = theNavi->
west();
229 std::map<CdOrientation, CdOrientation>::iterator oIt =
oppositeDirs.find(currDirection);
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>
314 template <
class EcalDetId>
317 template <
class EcalDetId>
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() <<
")";
359 bool reverseOrientation =
false;
362 EcalDetId
start = hitdetid;
363 EcalDetId current =
start;
364 int current_status = 0;
367 bool startAlgo =
false;
371 theEcalNav->setHome(current);
374 int status = (chit != ecalStatus->
end()) ? chit->getStatusCode() & 0x1F : -1;
376 stati.push_back(status);
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) {
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) {
415 stati.push_back(status);
418 nextStepFound =
true;
420 currDirection =
turnRight(currDirection, reverseOrientation);
422 }
else if (next == EcalDetId(0)) {
424 currDirection =
turnLeft(currDirection, reverseOrientation);
426 }
else if (status == 0) {
427 nextStepFound =
true;
432 <<
"EcalBoundaryInfoCalculator: No valid next direction can be found: This should never happen!";
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);
452 if (RecHits->
find(next) != RecHits->
end() && status == 0) {
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;
512 template <
class EcalDetId>
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() <<
")";
552 bool reverseOrientation =
false;
555 EcalDetId
start = hitdetid;
556 EcalDetId current =
start;
559 bool startAlgo =
false;
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) {
592 theEcalNav->setHome(current);
595 status = (chit != ecalStatus->
end()) ? chit->getStatusCode() & 0x1F : -1;
600 }
else if (next == EcalDetId(0)) {
602 currDirection =
turnLeft(currDirection, reverseOrientation);
603 }
else if (status == 0) {
604 if (RecHits->
find(next) != RecHits->
end()) {
605 nextStepFound =
true;
614 <<
"EcalBoundaryInfoCalculator: No valid next direction can be found: This should never happen!";
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);
639 if (RecHits->
find(next) != RecHits->
end()) {
642 gapRecHits.push_back(nexthit);
643 gapEnergy += nexthit.
energy();
645 eta = cellGeom->getPosition().eta();
646 gapET += nexthit.
energy() / cosh(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) {
671 theEcalNav->setHome(current);
674 status = (chit != ecalStatus->
end()) ? chit->getStatusCode() & 0x1F : -1;
679 }
else if (next == EcalDetId(0)) {
681 currDirection =
turnRight(currDirection, reverseOrientation);
682 }
else if (status == 0) {
683 if (RecHits->
find(next) != RecHits->
end()) {
684 nextStepFound =
true;
693 <<
"EcalBoundaryInfoCalculator: No valid next direction can be found: This should never happen!";
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);
711 if (RecHits->
find(next) != RecHits->
end()) {
714 gapRecHits.push_back(nexthit);
715 gapEnergy += nexthit.
energy();
717 eta = cellGeom->getPosition().eta();
718 gapET += nexthit.
energy() / cosh(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;
EcalBoundaryInfoCalculator()
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
bool checkRecHitHasInvalidNeighbour(const EcalRecHit &hit, const edm::ESHandle< EcalChannelStatus > ecalStatus) const
BoundaryInformation gapRecHits(const edm::Handle< EcalRecHitCollection > &, const EcalRecHit *, const edm::ESHandle< CaloTopology > theCaloTopology, const edm::ESHandle< EcalChannelStatus > ecalStatus, const edm::ESHandle< CaloGeometry > geometry) const
CdOrientation turnRight(CdOrientation currDirection, bool reverseOrientation) const
std::map< CdOrientation, CdOrientation > nextDirs
std::unique_ptr< CaloNavigator< EcalDetId > > initializeEcalNavigator(DetId startE, const edm::ESHandle< CaloTopology > theCaloTopology, EcalSubdetector ecalSubDet) const
EcalDetId makeStepInDirection(CdOrientation direction, const CaloNavigator< EcalDetId > *theNavi) const
static bool validDetId(int i, int j)
check if a valid index combination
int iphi() const
get the crystal iphi
void setHome(const T &startingPoint)
set the starting position
CdOrientation goBackOneCell(CdOrientation currDirection, EcalDetId prev, CaloNavigator< EcalDetId > *theEcalNav) const
BoundaryInformation boundaryRecHits(const edm::Handle< EcalRecHitCollection > &, const EcalRecHit *, const edm::ESHandle< CaloTopology > theCaloTopology, const edm::ESHandle< EcalChannelStatus > ecalStatus, const edm::ESHandle< CaloGeometry > geometry) const
T west() const
move the navigator west
T south() const
move the navigator south
int ieta() const
get the crystal ieta
T pos() const
get the current position
static const int ETAPHIMODE
const_iterator end() const
T east() const
move the navigator east
CdOrientation turnLeft(CdOrientation currDirection, bool reverseOrientation) const
DetId id() const
get the id
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
std::vector< Item >::const_iterator const_iterator
std::map< CdOrientation, CdOrientation > prevDirs
const CaloSubdetectorTopology * getSubdetectorTopology(const DetId &id) const
access the subdetector Topology for the given subdetector directly
std::map< CdOrientation, CdOrientation > oppositeDirs
iterator find(key_type k)
const_iterator find(uint32_t rawId) const
T north() const
move the navigator north
const_iterator end() const
~EcalBoundaryInfoCalculator()
bool checkRecHitHasDeadNeighbour(const EcalRecHit &hit, const edm::ESHandle< EcalChannelStatus > ecalStatus, std::vector< int > &stati) const