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$
2 
6 
7 float EcalTools::swissCross( const DetId& id,
8  const EcalRecHitCollection & recHits,
9  float recHitThreshold ,
10  bool avoidIeta85){
11  // compute swissCross
12  if ( id.subdetId() == EcalBarrel ) {
13  EBDetId ebId( id );
14  // avoid recHits at |eta|=85 where one side of the neighbours is missing
15  // (may improve considering also eta module borders, but no
16  // evidence for the time being that there the performance is
17  // different)
18  if ( abs(ebId.ieta())==85 && avoidIeta85) return 0;
19  // select recHits with Et above recHitThreshold
20  if ( recHitApproxEt( id, recHits ) < recHitThreshold ) return 0;
21  float s4 = 0;
22  float e1 = recHitE( id, recHits );
23  // protect against nan (if 0 threshold is given above)
24  if ( e1 == 0 ) return 0;
25  s4 += recHitE( id, recHits, 1, 0 );
26  s4 += recHitE( id, recHits, -1, 0 );
27  s4 += recHitE( id, recHits, 0, 1 );
28  s4 += recHitE( id, recHits, 0, -1 );
29  return 1 - s4 / e1;
30  } else if ( id.subdetId() == EcalEndcap ) {
31  EEDetId eeId( id );
32  // select recHits with E above recHitThreshold
33  float e1 = recHitE( id, recHits );
34  if ( e1 < recHitThreshold ) return 0;
35  float s4 = 0;
36  // protect against nan (if 0 threshold is given above)
37  if ( e1 == 0 ) return 0;
38  s4 += recHitE( id, recHits, 1, 0 );
39  s4 += recHitE( id, recHits, -1, 0 );
40  s4 += recHitE( id, recHits, 0, 1 );
41  s4 += recHitE( id, recHits, 0, -1 );
42  return 1 - s4 / e1;
43  }
44  return 0;
45 }
46 
47 
48 float EcalTools::recHitE( const DetId id,
49  const EcalRecHitCollection & recHits,
50  int di, int dj )
51 {
52  // in the barrel: di = dEta dj = dPhi
53  // in the endcap: di = dX dj = dY
54 
55  DetId nid;
56  if( id.subdetId() == EcalBarrel) nid = EBDetId::offsetBy( id, di, dj );
57  else if( id.subdetId() == EcalEndcap) nid = EEDetId::offsetBy( id, di, dj );
58 
59  return ( nid == DetId(0) ? 0 : recHitE( nid, recHits ) );
60 }
61 
62 float EcalTools::recHitE( const DetId id, const EcalRecHitCollection &recHits ){
63  if ( id == DetId(0) ) {
64  return 0;
65  } else {
66  EcalRecHitCollection::const_iterator it = recHits.find( id );
67  if ( it != recHits.end() ) return (*it).energy();
68  }
69  return 0;
70 }
71 
72 float EcalTools::recHitApproxEt( const DetId id, const EcalRecHitCollection &recHits ){
73  // for the time being works only for the barrel
74  if ( id.subdetId() == EcalBarrel ) {
75  return recHitE( id, recHits ) / cosh( EBDetId::approxEta( id ) );
76  }
77  return 0;
78 }
float approxEta() const
Definition: EBDetId.h:93
std::vector< T >::const_iterator const_iterator
#define abs(x)
Definition: mlp_lapack.h:159
EEDetId offsetBy(int nrStepsX, int nrStepsY) const
Definition: EEDetId.cc:490
EBDetId offsetBy(int nrStepsEta, int nrStepsPhi) const
Definition: EBDetId.cc:111
int ieta() const
get the crystal ieta
Definition: EBDetId.h:44
const_iterator end() const
Definition: DetId.h:20
static float recHitE(const DetId id, const EcalRecHitCollection &recHits)
Definition: EcalTools.cc:62
static float swissCross(const DetId &id, const EcalRecHitCollection &recHits, float recHitThreshold, bool avoidIeta85=true)
Definition: EcalTools.cc:7
iterator find(key_type k)
static float recHitApproxEt(const DetId id, const EcalRecHitCollection &recHits)
Definition: EcalTools.cc:72