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