1 #ifndef ECALBOUNDARYINFOCALCULATOR_H_ 2 #define ECALBOUNDARYINFOCALCULATOR_H_ 44 EcalDetId hitdetid = EcalDetId(hit.
id());
50 int hitIeta = ebhitdetid.
ieta();
51 int hitIphi = ebhitdetid.
iphi();
53 for (
int ieta = -1; ieta <= 1; ieta++) {
54 for (
int iphi = -1; iphi <= 1; iphi++) {
55 if ((iphi == 0 && ieta == 0) || iphi * ieta != 0)
58 int neighbourIeta = hitIeta + ieta;
59 int neighbourIphi = hitIphi + iphi;
61 if (neighbourIphi < 1)
63 if (neighbourIphi > 360)
65 if (neighbourIeta == 0) {
66 neighbourIeta += ieta;
74 int status = (chit != ecalStatus->
end()) ? chit->getStatusCode() & 0x1F : -1;
78 for (std::vector<int>::const_iterator
s = stati.begin();
s != stati.end(); ++
s) {
85 stati.push_back(status);
94 int hitIx = eehitdetid.
ix();
95 int hitIy = eehitdetid.
iy();
96 int hitIz = eehitdetid.
zside();
98 for (
int ix = -1; ix <= 1; ix++) {
99 for (
int iy = -1; iy <= 1; iy++) {
100 if ((ix == 0 && iy == 0) || ix * iy != 0)
103 int neighbourIx = hitIx + ix;
104 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";
140 EcalDetId hitdetid = EcalDetId(hit.
id());
146 int hitIeta = ebhitdetid.
ieta();
147 int hitIphi = ebhitdetid.
iphi();
149 for (
int ieta = -1; ieta <= 1; ieta++) {
150 for (
int iphi = -1; iphi <= 1; iphi++) {
151 if ((iphi == 0 && ieta == 0) || iphi * ieta != 0)
154 int neighbourIeta = hitIeta + ieta;
155 int neighbourIphi = hitIphi + iphi;
157 if (neighbourIphi < 1)
158 neighbourIphi += 360;
159 if (neighbourIphi > 360)
160 neighbourIphi -= 360;
161 if (neighbourIeta == 0) {
162 neighbourIeta += ieta;
175 int hitIx = eehitdetid.
ix();
176 int hitIy = eehitdetid.
iy();
177 int hitIz = eehitdetid.
zside();
179 for (
int ix = -1; ix <= 1; ix++) {
180 for (
int iy = -1; iy <= 1; iy++) {
181 if ((ix == 0 && iy == 0) || ix * iy != 0)
184 int neighbourIx = hitIx + ix;
185 int neighbourIy = hitIy + iy;
194 edm::LogWarning(
"EcalBoundaryInfoCalculator") <<
"ERROR - RecHit belongs to wrong sub detector";
201 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"set Debug Mode!";
211 next = theNavi->
north();
215 next = theNavi->
east();
219 next = theNavi->
south();
223 next = theNavi->
west();
233 std::map<CdOrientation, CdOrientation>::iterator oIt =
oppositeDirs.find(currDirection);
236 oppDirection = oIt->second;
239 EcalDetId currDetId = theEcalNav->
pos();
246 std::map<CdOrientation, CdOrientation> turnMap =
nextDirs;
247 if (reverseOrientation)
249 std::map<CdOrientation, CdOrientation>::iterator nIt = turnMap.find(currDirection);
251 if (nIt != turnMap.end())
252 nextDirection = (*nIt).second;
254 edm::LogWarning(
"EcalBoundaryInfoCalculator") <<
"ERROR - no Next Direction found!?!?";
255 return nextDirection;
260 std::map<CdOrientation, CdOrientation> turnMap =
prevDirs;
261 if (reverseOrientation)
263 std::map<CdOrientation, CdOrientation>::iterator nIt = turnMap.find(currDirection);
265 if (nIt != turnMap.end())
266 nextDirection = (*nIt).second;
268 edm::LogWarning(
"EcalBoundaryInfoCalculator") <<
"ERROR - no Next Direction found!?!?";
269 return nextDirection;
274 std::unique_ptr<CaloNavigator<EcalDetId>> theEcalNav(
nullptr);
282 edm::LogWarning(
"EcalBoundaryInfoCalculator") <<
"initializeEcalNavigator not implemented for subDet: " << ecalSubDet;
327 std::vector<DetId> boundaryDetIds;
328 std::vector<int> stati;
330 double boundaryEnergy = 0;
331 double boundaryET = 0;
332 int beCellCounter = 0;
333 bool nextToBorder =
false;
335 boundaryRecHits.push_back(*hit);
337 boundaryEnergy += hit->
energy();
338 EcalDetId hitdetid = (EcalDetId) hit->
id();
339 boundaryDetIds.push_back(hitdetid);
342 double eta = cellGeom->getPosition().eta();
343 boundaryET += hit->
energy() / cosh(eta);
346 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"Find Boundary RecHits...";
349 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"Starting at : (" << ((
EBDetId) hitdetid).ieta() <<
"," << ((
EBDetId) hitdetid).iphi() <<
")";
351 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"Starting at : (" << ((
EEDetId) hitdetid).ix() <<
"," << ((
EEDetId) hitdetid).iy() <<
")";
358 bool reverseOrientation =
false;
361 EcalDetId
start = hitdetid;
362 EcalDetId current =
start;
363 int current_status = 0;
366 bool startAlgo =
false;
370 theEcalNav->setHome(current);
373 int status = (chit != ecalStatus->
end()) ? chit->getStatusCode() & 0x1F : -1;
375 stati.push_back(status);
379 currDirection =
turnLeft(currDirection, reverseOrientation);
383 <<
"EcalBoundaryInfoCalculator: No starting direction can be found: This should never happen if RecHit has a dead neighbour!";
388 currDirection =
turnRight(currDirection, reverseOrientation);
391 bool nextIsStart =
false;
392 bool atBorder =
false;
394 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!";
446 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"Next step: " << (EcalDetId) next <<
" Status: " << status <<
" Start: " << (EcalDetId)
start;
449 if ((!atBorder || status == 0) && !nextIsStart) {
450 boundaryDetIds.push_back(next);
451 if (RecHits->find(next) != RecHits->end() && status == 0) {
454 boundaryRecHits.push_back(nexthit);
455 boundaryEnergy += nexthit.
energy();
457 eta = cellGeom->getPosition().eta();
458 boundaryET += nexthit.
energy() / cosh(eta);
462 if (current_status == 0 && status == 0 && atBorder) {
464 currDirection =
turnRight(currDirection, reverseOrientation);
467 if (status == 0 && atBorder) {
469 currDirection =
turnLeft(currDirection, reverseOrientation);
473 currDirection =
turnLeft(currDirection, reverseOrientation);
476 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;
518 std::vector<DetId> gapDetIds;
520 double gapEnergy = 0;
522 int gapCellCounter = 0;
523 bool nextToBorder =
false;
525 gapRecHits.push_back(*hit);
527 gapEnergy += hit->
energy();
528 EcalDetId hitdetid = (EcalDetId) hit->
id();
529 gapDetIds.push_back(hitdetid);
532 double eta = cellGeom->getPosition().eta();
533 gapET += hit->
energy() / cosh(eta);
536 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"Find Border RecHits...";
539 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"Starting at : (" << ((
EBDetId) hitdetid).ieta() <<
"," << ((
EBDetId) hitdetid).iphi() <<
")";
541 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"Starting at : (" << ((
EEDetId) hitdetid).ix() <<
"," << ((
EEDetId) hitdetid).iy() <<
")";
548 bool reverseOrientation =
false;
551 EcalDetId
start = hitdetid;
552 EcalDetId current =
start;
555 bool startAlgo =
false;
559 theEcalNav->setHome(start);
561 if (next == EcalDetId(0)) {
566 currDirection =
turnLeft(currDirection, reverseOrientation);
570 <<
"EcalBoundaryInfoCalculator: No starting direction can be found: This should never happen if RecHit is at border!";
576 currDirection =
turnLeft(currDirection, reverseOrientation);
579 bool endIsFound =
false;
580 bool startIsEnd =
false;
582 while (!endIsFound) {
584 bool nextStepFound =
false;
587 while (!nextStepFound) {
589 theEcalNav->setHome(current);
592 status = (chit != ecalStatus->
end()) ? chit->getStatusCode() & 0x1F : -1;
597 }
else if (next == EcalDetId(0)) {
599 currDirection =
turnLeft(currDirection, reverseOrientation);
600 }
else if (status == 0) {
601 if (RecHits->find(next) != RecHits->end()) {
602 nextStepFound =
true;
611 <<
"EcalBoundaryInfoCalculator: No valid next direction can be found: This should never happen!";
623 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"Path along gap reached starting position!";
627 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"Next step: " << (EcalDetId) next <<
" Status: " << status <<
" Start: " << (EcalDetId)
start;
629 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"End of gap cluster is found going left";
634 gapDetIds.push_back(next);
635 if (RecHits->find(next) != RecHits->end()) {
638 gapRecHits.push_back(nexthit);
639 gapEnergy += nexthit.
energy();
641 eta = cellGeom->getPosition().eta();
642 gapET += nexthit.
energy() / cosh(eta);
647 currDirection =
turnRight(currDirection, reverseOrientation);
652 theEcalNav->setHome(start);
655 currDirection = startDirection;
656 currDirection =
turnRight(currDirection, reverseOrientation);
663 while (!endIsFound) {
665 bool nextStepFound =
false;
668 while (!nextStepFound) {
670 theEcalNav->setHome(current);
673 status = (chit != ecalStatus->
end()) ? chit->getStatusCode() & 0x1F : -1;
678 }
else if (next == EcalDetId(0)) {
680 currDirection =
turnRight(currDirection, reverseOrientation);
681 }
else if (status == 0) {
682 if (RecHits->find(next) != RecHits->end()) {
683 nextStepFound =
true;
692 <<
"EcalBoundaryInfoCalculator: No valid next direction can be found: This should never happen!";
701 edm::LogInfo(
"EcalBoundaryInfoCalculator")<<
"Next step: " << (EcalDetId) next <<
" Status: " << status <<
" Start: " << (EcalDetId)
start;
703 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"End of gap cluster is found going right";
708 gapDetIds.push_back(next);
709 if (RecHits->find(next) != RecHits->end()) {
712 gapRecHits.push_back(nexthit);
713 gapEnergy += nexthit.
energy();
715 eta = cellGeom->getPosition().eta();
716 gapET += nexthit.
energy() / cosh(eta);
721 currDirection =
turnLeft(currDirection, reverseOrientation);
727 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"<<<<<<<<<<<<<<< Final Gap object <<<<<<<<<<<<<<<";
728 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"No of RecHits along gap: " << gapRecHits.size();
729 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"No of DetIds along gap: " << gapDetIds.size();
730 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"Gap energy: " << gapEnergy;
731 edm::LogInfo(
"EcalBoundaryInfoCalculator") <<
"Gap ET: " << gapET;
735 gapInfo.
subdet = hitdetid.subdet();
736 gapInfo.
detIds = gapDetIds;
741 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
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
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