CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalTools.cc
Go to the documentation of this file.
1 // $Id: EcalTools.cc,v 1.4 2011/05/19 14:39:29 argiro Exp $
2 
11 
12 float EcalTools::swissCross( const DetId& id,
13  const EcalRecHitCollection & recHits,
14  float recHitThreshold ,
15  bool avoidIeta85){
16  // compute swissCross
17  if ( id.subdetId() == EcalBarrel ) {
18  EBDetId ebId( id );
19  // avoid recHits at |eta|=85 where one side of the neighbours is missing
20  // (may improve considering also eta module borders, but no
21  // evidence for the time being that there the performance is
22  // different)
23  if ( abs(ebId.ieta())==85 && avoidIeta85) return 0;
24  // select recHits with Et above recHitThreshold
25  if ( recHitApproxEt( id, recHits ) < recHitThreshold ) return 0;
26  float s4 = 0;
27  float e1 = recHitE( id, recHits );
28  // protect against nan (if 0 threshold is given above)
29  if ( e1 == 0 ) return 0;
30  s4 += recHitE( id, recHits, 1, 0 );
31  s4 += recHitE( id, recHits, -1, 0 );
32  s4 += recHitE( id, recHits, 0, 1 );
33  s4 += recHitE( id, recHits, 0, -1 );
34  return 1 - s4 / e1;
35  } else if ( id.subdetId() == EcalEndcap ) {
36  EEDetId eeId( id );
37  // select recHits with E above recHitThreshold
38  float e1 = recHitE( id, recHits );
39  if ( e1 < recHitThreshold ) return 0;
40  float s4 = 0;
41  // protect against nan (if 0 threshold is given above)
42  if ( e1 == 0 ) return 0;
43  s4 += recHitE( id, recHits, 1, 0 );
44  s4 += recHitE( id, recHits, -1, 0 );
45  s4 += recHitE( id, recHits, 0, 1 );
46  s4 += recHitE( id, recHits, 0, -1 );
47  return 1 - s4 / e1;
48  }
49  return 0;
50 }
51 
52 
53 bool EcalTools::isNextToDead( const DetId& id, const edm::EventSetup& es){
54 
56  es.get<EcalNextToDeadChannelRcd>().get(dch);
57 
58  EcalNextToDeadChannel::const_iterator chIt = dch->find( id );
59 
60  if ( chIt != dch->end() ) {
61  return *chIt;
62  } else {
63  edm::LogError("EcalDBError")
64  << "No NextToDead status found for xtal "
65  << id.rawId() ;
66  }
67 
68  return false;
69 
70 }
71 
73  const EcalChannelStatus& chs,
74  int chStatusThreshold) {
75 
76  if (deadNeighbour(id,chs, chStatusThreshold, 1, 0)) return true;
77  if (deadNeighbour(id,chs, chStatusThreshold,-1, 0)) return true;
78  if (deadNeighbour(id,chs, chStatusThreshold, 0, 1)) return true;
79  if (deadNeighbour(id,chs, chStatusThreshold, 0,-1)) return true;
80  if (deadNeighbour(id,chs, chStatusThreshold, 1,-1)) return true;
81  if (deadNeighbour(id,chs, chStatusThreshold, 1, 1)) return true;
82  if (deadNeighbour(id,chs, chStatusThreshold,-1, 1)) return true;
83  if (deadNeighbour(id,chs, chStatusThreshold,-1,-1)) return true;
84 
85  return false;
86 }
87 
88 
90  const EcalChannelStatus& chs,
91  int chStatusThreshold,
92  int dx, int dy){
93 
94 
95  DetId nid;
96  if( id.subdetId() == EcalBarrel) nid = EBDetId::offsetBy( id, dx, dy );
97  else if( id.subdetId() == EcalEndcap) nid = EEDetId::offsetBy( id, dx, dy );
98 
99  if (!nid) return false;
100 
101  EcalChannelStatus::const_iterator chIt = chs.find( nid );
102  uint16_t dbStatus = 0;
103  if ( chIt != chs.end() ) {
104  // note that
105  dbStatus = chIt->getStatusCode() ;
106  } else {
107  edm::LogError("EcalDBError")
108  << "No channel status found for xtal "
109  << id.rawId()
110  << "! something wrong with EcalChannelStatus in your DB? ";
111  }
112 
113  return (dbStatus>=chStatusThreshold );
114 
115 }
116 
117 
118 
119 float EcalTools::recHitE( const DetId id,
120  const EcalRecHitCollection & recHits,
121  int di, int dj )
122 {
123  // in the barrel: di = dEta dj = dPhi
124  // in the endcap: di = dX dj = dY
125 
126  DetId nid;
127  if( id.subdetId() == EcalBarrel) nid = EBDetId::offsetBy( id, di, dj );
128  else if( id.subdetId() == EcalEndcap) nid = EEDetId::offsetBy( id, di, dj );
129 
130  return ( nid == DetId(0) ? 0 : recHitE( nid, recHits ) );
131 }
132 
133 float EcalTools::recHitE( const DetId id, const EcalRecHitCollection &recHits ){
134  if ( id == DetId(0) ) {
135  return 0;
136  } else {
137  EcalRecHitCollection::const_iterator it = recHits.find( id );
138  if ( it != recHits.end() ) return (*it).energy();
139  }
140  return 0;
141 }
142 
143 float EcalTools::recHitApproxEt( const DetId id, const EcalRecHitCollection &recHits ){
144  // for the time being works only for the barrel
145  if ( id.subdetId() == EcalBarrel ) {
146  return recHitE( id, recHits ) / cosh( EBDetId::approxEta( id ) );
147  }
148  return 0;
149 }
150 
151 
152 bool isNextToBoundary(const DetId& id){
153 
154  if ( id.subdetId() == EcalBarrel )
156  else if ( id.subdetId() == EcalEndcap )
158 
159  return false;
160 }
float approxEta() const
Definition: EBDetId.h:107
static bool isNextToBoundary(EEDetId id)
Definition: EEDetId.cc:361
static bool isNextToDead(const DetId &id, const edm::EventSetup &es)
true if the channel is near a dead one (in the 3x3)
Definition: EcalTools.cc:53
std::vector< EcalRecHit >::const_iterator const_iterator
#define abs(x)
Definition: mlp_lapack.h:159
EEDetId offsetBy(int nrStepsX, int nrStepsY) const
Definition: EEDetId.cc:474
static bool isNextToBoundary(EBDetId id)
Definition: EBDetId.cc:121
EBDetId offsetBy(int nrStepsEta, int nrStepsPhi) const
Definition: EBDetId.cc:61
int ieta() const
get the crystal ieta
Definition: EBDetId.h:52
bool isNextToBoundary(const DetId &id)
Definition: EcalTools.cc:152
const_iterator end() const
static bool isNextToDeadFromNeighbours(const DetId &id, const EcalChannelStatus &chs, int chStatusThreshold)
same as isNextToDead, but will use information from the neighbour
Definition: EcalTools.cc:72
Float e1
Definition: deltaR.h:22
Definition: DetId.h:20
const T & get() const
Definition: EventSetup.h:55
std::vector< Item >::const_iterator const_iterator
static float recHitE(const DetId id, const EcalRecHitCollection &recHits)
Definition: EcalTools.cc:133
static float swissCross(const DetId &id, const EcalRecHitCollection &recHits, float recHitThreshold, bool avoidIeta85=true)
the good old 1-e4/e1. Ignore hits below recHitThreshold
Definition: EcalTools.cc:12
static bool deadNeighbour(const DetId &id, const EcalChannelStatus &chs, int chStatusThreshold, int dx, int dy)
return true if the channel at offsets dx,dy is dead
Definition: EcalTools.cc:89
iterator find(key_type k)
static float recHitApproxEt(const DetId id, const EcalRecHitCollection &recHits)
Definition: EcalTools.cc:143
const_iterator find(uint32_t rawId) const
const_iterator end() const