1 #ifndef ECALBOUNDARYINFOCALCULATOR_H_
2 #define ECALBOUNDARYINFOCALCULATOR_H_
43 EcalDetId hitdetid = EcalDetId(hit.
id());
49 int hitIeta = ebhitdetid.
ieta();
50 int hitIphi = ebhitdetid.
iphi();
52 for (
int ieta = -1; ieta <= 1; ieta++) {
53 for (
int iphi = -1; iphi <= 1; iphi++) {
54 if ((iphi == 0 && ieta == 0) || iphi * ieta != 0)
57 int neighbourIeta = hitIeta + ieta;
58 int neighbourIphi = hitIphi + iphi;
60 if (neighbourIphi < 1)
62 if (neighbourIphi > 360)
64 if (neighbourIeta == 0) {
65 neighbourIeta += ieta;
73 int status = (chit != ecalStatus->end()) ? chit->getStatusCode() & 0x1F : -1;
77 for (std::vector<int>::const_iterator
s = stati.begin();
s != stati.end(); ++
s) {
84 stati.push_back(status);
93 int hitIx = eehitdetid.
ix();
94 int hitIy = eehitdetid.
iy();
95 int hitIz = eehitdetid.
zside();
97 for (
int ix = -1; ix <= 1; ix++) {
98 for (
int iy = -1; iy <= 1; iy++) {
99 if ((ix == 0 && iy == 0) || ix * iy != 0)
102 int neighbourIx = hitIx + ix;
103 int neighbourIy = hitIy + iy;
109 int status = (chit != ecalStatus->end()) ? chit->getStatusCode() & 0x1F : -1;
112 bool present =
false;
113 for (std::vector<int>::const_iterator
s = stati.begin();
s != stati.end(); ++
s) {
120 stati.push_back(status);
127 std::cout <<
"ERROR - RecHit belongs to wrong sub detector" << std::endl;
130 if (stati.size() > 0)
139 EcalDetId hitdetid = EcalDetId(hit.
id());
145 int hitIeta = ebhitdetid.
ieta();
146 int hitIphi = ebhitdetid.
iphi();
148 for (
int ieta = -1; ieta <= 1; ieta++) {
149 for (
int iphi = -1; iphi <= 1; iphi++) {
150 if ((iphi == 0 && ieta == 0) || iphi * ieta != 0)
153 int neighbourIeta = hitIeta + ieta;
154 int neighbourIphi = hitIphi + iphi;
156 if (neighbourIphi < 1)
157 neighbourIphi += 360;
158 if (neighbourIphi > 360)
159 neighbourIphi -= 360;
160 if (neighbourIeta == 0) {
161 neighbourIeta += ieta;
174 int hitIx = eehitdetid.
ix();
175 int hitIy = eehitdetid.
iy();
176 int hitIz = eehitdetid.
zside();
178 for (
int ix = -1; ix <= 1; ix++) {
179 for (
int iy = -1; iy <= 1; iy++) {
180 if ((ix == 0 && iy == 0) || ix * iy != 0)
183 int neighbourIx = hitIx + ix;
184 int neighbourIy = hitIy + iy;
193 std::cout <<
"ERROR - RecHit belongs to wrong sub detector" << std::endl;
200 std::cout <<
"set Debug Mode!" << std::endl;
211 next = theNavi->
north();
216 next = theNavi->
east();
221 next = theNavi->
south();
226 next = theNavi->
west();
236 std::map<CdOrientation, CdOrientation>::iterator oIt =
oppositeDirs.find(currDirection);
239 oppDirection = oIt->second;
249 std::map<CdOrientation, CdOrientation> turnMap =
nextDirs;
250 if (reverseOrientation)
252 std::map<CdOrientation, CdOrientation>::iterator nIt = turnMap.find(currDirection);
254 if (nIt != turnMap.end())
255 nextDirection = (*nIt).second;
257 std::cout <<
"ERROR - no Next Direction found!?!?" << std::endl;
258 return nextDirection;
263 std::map<CdOrientation, CdOrientation> turnMap =
prevDirs;
264 if (reverseOrientation)
266 std::map<CdOrientation, CdOrientation>::iterator nIt = turnMap.find(currDirection);
268 if (nIt != turnMap.end())
269 nextDirection = (*nIt).second;
271 std::cout <<
"ERROR - no Next Direction found!?!?" << std::endl;
272 return nextDirection;
292 std::cout <<
"initializeEcalNavigator not implemented for subDet: " << ecalSubDet << std::endl;
319 oppositeDirs.clear();
339 std::vector<EcalRecHit> boundaryRecHits;
340 std::vector<DetId> boundaryDetIds;
341 std::vector<int> stati;
343 double boundaryEnergy = 0;
344 double boundaryET = 0;
345 int beCellCounter = 0;
346 bool nextToBorder =
false;
348 boundaryRecHits.push_back(*hit);
350 boundaryEnergy += hit->
energy();
351 EcalDetId hitdetid = (EcalDetId) hit->
id();
352 boundaryDetIds.push_back(hitdetid);
356 boundaryET += hit->
energy() / cosh(eta);
359 std::cout <<
"Find Boundary RecHits..." << std::endl;
372 initializeEcalNavigator(hitdetid, theCaloTopology, EcalDetId::subdet());
374 bool reverseOrientation =
false;
377 EcalDetId
start = hitdetid;
379 int current_status = 0;
382 bool startAlgo =
false;
385 next = makeStepInDirection(currDirection, theEcalNav);
386 theEcalNav->setHome(current);
389 int status = (chit != ecalStatus->end()) ? chit->getStatusCode() & 0x1F : -1;
391 stati.push_back(status);
395 currDirection = turnLeft(currDirection, reverseOrientation);
399 std::cout <<
"No starting direction can be found: This should never happen if RecHit has a dead neighbour!" << std::endl;
406 currDirection = turnRight(currDirection, reverseOrientation);
409 bool nextIsStart =
false;
410 bool atBorder =
false;
412 while (!nextIsStart) {
414 bool nextStepFound =
false;
417 while (!nextStepFound) {
418 next = makeStepInDirection(currDirection, theEcalNav);
419 theEcalNav->setHome(current);
422 status = (chit != ecalStatus->end()) ? chit->getStatusCode() & 0x1F : -1;
425 bool present =
false;
426 for (std::vector<int>::const_iterator
s = stati.begin();
s != stati.end(); ++
s) {
433 stati.push_back(status);
436 nextStepFound =
true;
438 currDirection = turnRight(currDirection, reverseOrientation);
440 }
else if (next == EcalDetId(0)) {
442 currDirection = turnLeft(currDirection, reverseOrientation);
444 }
else if (status == 0) {
445 nextStepFound =
true;
449 std::cout <<
"No valid next direction can be found: This should never happen!" << std::endl;
456 next = makeStepInDirection(currDirection, theEcalNav);
461 std::cout <<
"Boundary path reached starting position!" << std::endl;
465 std::cout <<
"Next step: " << (EcalDetId) next <<
" Status: " << status <<
" Start: " << (EcalDetId) start << std::endl;
468 if ((!atBorder || status == 0) && !nextIsStart) {
469 boundaryDetIds.push_back(next);
470 if (RecHits->find(next) != RecHits->end() && status == 0) {
473 boundaryRecHits.push_back(nexthit);
474 boundaryEnergy += nexthit.
energy();
477 boundaryET += nexthit.
energy() / cosh(eta);
481 if (current_status == 0 && status == 0 && atBorder) {
483 currDirection = turnRight(currDirection, reverseOrientation);
486 if (status == 0 && atBorder) {
488 currDirection = turnLeft(currDirection, reverseOrientation);
492 currDirection = turnLeft(currDirection, reverseOrientation);
495 currDirection = turnRight(currDirection, reverseOrientation);
506 std::cout <<
"<<<<<<<<<<<<<<< Final Boundary object <<<<<<<<<<<<<<<" << std::endl;
507 std::cout <<
"no of neighbouring RecHits: " << boundaryRecHits.size() << std::endl;
508 std::cout <<
"no of neighbouring DetIds: " << boundaryDetIds.size() << std::endl;
509 std::cout <<
"boundary energy: " << boundaryEnergy << std::endl;
510 std::cout <<
"boundary ET: " << boundaryET << std::endl;
511 std::cout <<
"no of cells contributing to boundary energy: " << beCellCounter << std::endl;
513 for (std::vector<int>::iterator it = stati.begin(); it != stati.end(); ++it) {
520 boundInfo.
subdet = hitdetid.subdet();
521 boundInfo.
detIds = boundaryDetIds;
522 boundInfo.
recHits = boundaryRecHits;
528 if (theEcalNav != 0) {
540 std::vector<EcalRecHit> gapRecHits;
541 std::vector<DetId> gapDetIds;
543 double gapEnergy = 0;
545 int gapCellCounter = 0;
546 bool nextToBorder =
false;
548 gapRecHits.push_back(*hit);
550 gapEnergy += hit->
energy();
551 EcalDetId hitdetid = (EcalDetId) hit->
id();
552 gapDetIds.push_back(hitdetid);
556 gapET += hit->
energy() / cosh(eta);
559 std::cout <<
"Find Border RecHits..." << std::endl;
572 initializeEcalNavigator(hitdetid, theCaloTopology, EcalDetId::subdet());
574 bool reverseOrientation =
false;
577 EcalDetId
start = hitdetid;
581 bool startAlgo =
false;
584 next = makeStepInDirection(currDirection, theEcalNav);
585 theEcalNav->setHome(start);
587 if (next == EcalDetId(0)) {
592 currDirection = turnLeft(currDirection, reverseOrientation);
596 std::cout <<
"No starting direction can be found: This should never happen if RecHit is at border!" << std::endl;
604 currDirection = turnLeft(currDirection, reverseOrientation);
607 bool endIsFound =
false;
608 bool startIsEnd =
false;
610 while (!endIsFound) {
612 bool nextStepFound =
false;
615 while (!nextStepFound) {
616 next = makeStepInDirection(currDirection, theEcalNav);
617 theEcalNav->setHome(current);
620 status = (chit != ecalStatus->end()) ? chit->getStatusCode() & 0x1F : -1;
625 }
else if (next == EcalDetId(0)) {
627 currDirection = turnLeft(currDirection, reverseOrientation);
628 }
else if (status == 0) {
629 if (RecHits->find(next) != RecHits->end()) {
630 nextStepFound =
true;
638 std::cout <<
"No valid next direction can be found: This should never happen!" << std::endl;
645 next = makeStepInDirection(currDirection, theEcalNav);
652 std::cout <<
"Path along gap reached starting position!" << std::endl;
656 std::cout <<
"Next step: " << (EcalDetId) next <<
" Status: " << status <<
" Start: " << (EcalDetId) start << std::endl;
658 std::cout <<
"End of gap cluster is found going left" << std::endl;
663 gapDetIds.push_back(next);
664 if (RecHits->find(next) != RecHits->end()) {
667 gapRecHits.push_back(nexthit);
668 gapEnergy += nexthit.
energy();
671 gapET += nexthit.
energy() / cosh(eta);
676 currDirection = turnRight(currDirection, reverseOrientation);
681 theEcalNav->setHome(start);
684 currDirection = startDirection;
685 currDirection = turnRight(currDirection, reverseOrientation);
692 while (!endIsFound) {
694 bool nextStepFound =
false;
697 while (!nextStepFound) {
698 next = makeStepInDirection(currDirection, theEcalNav);
699 theEcalNav->setHome(current);
702 status = (chit != ecalStatus->end()) ? chit->getStatusCode() & 0x1F : -1;
707 }
else if (next == EcalDetId(0)) {
709 currDirection = turnRight(currDirection, reverseOrientation);
710 }
else if (status == 0) {
711 if (RecHits->find(next) != RecHits->end()) {
712 nextStepFound =
true;
720 std::cout <<
"No valid next direction can be found: This should never happen!" << std::endl;
727 next = makeStepInDirection(currDirection, theEcalNav);
731 std::cout <<
"Next step: " << (EcalDetId) next <<
" Status: " << status <<
" Start: " << (EcalDetId) start
734 std::cout <<
"End of gap cluster is found going right" << std::endl;
739 gapDetIds.push_back(next);
740 if (RecHits->find(next) != RecHits->end()) {
743 gapRecHits.push_back(nexthit);
744 gapEnergy += nexthit.
energy();
747 gapET += nexthit.
energy() / cosh(eta);
752 currDirection = turnLeft(currDirection, reverseOrientation);
758 std::cout <<
"<<<<<<<<<<<<<<< Final Gap object <<<<<<<<<<<<<<<" << std::endl;
759 std::cout <<
"No of RecHits along gap: " << gapRecHits.size() << std::endl;
760 std::cout <<
"No of DetIds along gap: " << gapDetIds.size() << std::endl;
761 std::cout <<
"Gap energy: " << gapEnergy << std::endl;
762 std::cout <<
"Gap ET: " << gapET << std::endl;
766 gapInfo.
subdet = hitdetid.subdet();
767 gapInfo.
detIds = gapDetIds;
772 std::vector<int> stati;
775 if (theEcalNav != 0) {
EcalBoundaryInfoCalculator()
tuple start
Check for commandline option errors.
CdOrientation turnRight(CdOrientation currDirection, bool reverseOrientation)
CdOrientation goBackOneCell(CdOrientation currDirection, EcalDetId prev)
std::map< CdOrientation, CdOrientation > nextDirs
BoundaryInformation gapRecHits(const edm::Handle< EcalRecHitCollection > &, const EcalRecHit *, const edm::ESHandle< CaloTopology > theCaloTopology, const edm::ESHandle< EcalChannelStatus > ecalStatus, const edm::ESHandle< CaloGeometry > geometry)
bool checkRecHitHasDeadNeighbour(const EcalRecHit &hit, const edm::ESHandle< EcalChannelStatus > ecalStatus, std::vector< int > &stati)
BoundaryInformation boundaryRecHits(const edm::Handle< EcalRecHitCollection > &, const EcalRecHit *, const edm::ESHandle< CaloTopology > theCaloTopology, const edm::ESHandle< EcalChannelStatus > ecalStatus, const edm::ESHandle< CaloGeometry > geometry)
void initializeEcalNavigator(DetId startE, const edm::ESHandle< CaloTopology > theCaloTopology, EcalSubdetector ecalSubDet)
virtual 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 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
CaloNavigator< EcalDetId > * theEcalNav
T west() const
move the navigator west
CdOrientation turnLeft(CdOrientation currDirection, bool reverseOrientation)
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
EcalDetId makeStepInDirection(CdOrientation direction, CaloNavigator< EcalDetId > *theNavi)
T east() const
move the navigator east
DetId id() const
get the id
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
std::vector< Item >::const_iterator const_iterator
std::map< CdOrientation, CdOrientation > prevDirs
std::map< CdOrientation, CdOrientation > oppositeDirs
bool checkRecHitHasInvalidNeighbour(const EcalRecHit &hit, const edm::ESHandle< EcalChannelStatus > ecalStatus)
ESHandle< TrackerGeometry > geometry
T north() const
move the navigator north
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
~EcalBoundaryInfoCalculator()