test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EBDetId.cc
Go to the documentation of this file.
3 
4 #include <algorithm>
5 const int EBDetId::kModuleBoundaries[4] = { 25, 45, 65, 85 };
6 
7 // pi / 180.
8 const float EBDetId::crystalUnitToEta = 0.017453292519943295;
9 
10 
11 EBDetId::EBDetId(int index1, int index2, int mode)
12  : DetId(Ecal,EcalBarrel)
13 {
14  int crystal_ieta;
15  int crystal_iphi;
16  if (mode == ETAPHIMODE) {
17  crystal_ieta = index1;
18  crystal_iphi = index2;
19  } else if (mode == SMCRYSTALMODE) {
20  int SM = index1;
21  int crystal = index2;
22  int i = (int) floor((crystal-1) / kCrystalsInPhi);
23  int j = ((crystal-1) - (kCrystalsInPhi*i));
24  if (SM <= 18) {
25  crystal_ieta = i + 1;
26  crystal_iphi = ((SM-1) * kCrystalsInPhi) + (kCrystalsInPhi-j);
27  } else {
28  crystal_ieta = -(i+1);
29  crystal_iphi = ((SM-19) * kCrystalsInPhi) + j+1;
30  }
31  } else {
32  throw cms::Exception("InvalidDetId") << "EBDetId: Cannot create object. Unknown mode for (int, int) constructor.";
33  }
34 
35  if ( !validDetId(crystal_ieta, crystal_iphi) ) {
36  // std::cout << "crystal_eta " << crystal_ieta << "crystal_phi " << crystal_iphi << std::endl;
37  throw cms::Exception("InvalidDetId") << "EBDetId: Cannot create object. Indexes out of bounds \n"
38  << "eta = " << crystal_ieta << " phi = " << crystal_iphi;
39  }
40  id_|=((crystal_ieta>0)?(0x10000|(crystal_ieta<<9)):((-crystal_ieta)<<9))|(crystal_iphi&0x1FF);
41 }
42 
43 
44 
45 //Following TB 2004 numbering scheme
46 int EBDetId::ic() const {
47  int ie = ietaAbs() -1;
48  return (ie * kCrystalsInPhi)
49  + ( positiveZ() ?
50  ( kCrystalsInPhi - ( (iphi() -1 ) % kCrystalsInPhi ) )
51  : ( ( iphi() -1 ) % kCrystalsInPhi + 1)
52  );
53 }
54 
55 
56 //Maintains SM crystals in bunch of 1700 indices
57 int EBDetId::numberBySM() const {
58  return (ism()-1) * kCrystalsPerSM + ic() -1;
59 }
60 
61 EBDetId EBDetId::offsetBy(int nrStepsEta, int nrStepsPhi ) const
62 {
63  int newEta = ieta()+nrStepsEta;
64  if( newEta*ieta() <= 0 ) {
65  if( ieta() < 0 ) {
66  newEta++;
67  } else if ( ieta() > 0 ) {
68  newEta--;
69  }
70  }
71  int newPhi = iphi() + nrStepsPhi;
72  while ( newPhi>360 ) newPhi -= 360;
73  while ( newPhi<=0 ) newPhi += 360;
74 
75  if( validDetId( newEta, newPhi ) ) {
76  return EBDetId( newEta, newPhi);
77  } else {
78  return EBDetId(0);
79  }
80 }
81 
83 {
84  int newEta = ieta()*-1;
85  if( validDetId( newEta, iphi() ) ) {
86  return EBDetId( newEta, iphi() );
87  } else {
88  return EBDetId(0);
89  }
90 }
91 
92 
93 DetId EBDetId::offsetBy(const DetId startId, int nrStepsEta, int nrStepsPhi )
94 {
95  if( startId.det() == DetId::Ecal && startId.subdetId() == EcalBarrel ) {
96  EBDetId ebStartId(startId);
97  return ebStartId.offsetBy( nrStepsEta, nrStepsPhi ).rawId();
98  } else {
99  return DetId(0);
100  }
101 }
102 
104 {
105  if( startId.det() == DetId::Ecal && startId.subdetId() == EcalBarrel ) {
106  EBDetId ebStartId(startId);
107  return ebStartId.switchZSide().rawId();
108  } else {
109  return DetId(0);
110  }
111 }
112 
113 //corrects for HB/EB differing iphi=1
114 int EBDetId::tower_iphi() const {
115  int iphi_simple=((iphi()-1)/5)+1;
116  iphi_simple-=2;
117  return ((iphi_simple<=0)?(iphi_simple+72):(iphi_simple));
118 }
119 
120 
122  return isNextToEtaBoundary( id ) || isNextToPhiBoundary( id );
123 }
124 
126  int ieta = id.ietaSM();
127  return ieta == 1 || (kModuleBoundaries + 4)!=std::find( kModuleBoundaries, kModuleBoundaries + 4, ieta );
128 }
129 
131  int iphi = id.iphiSM();
132  return iphi == 1 || iphi == 20;
133 }
134 
136 {
137  if (a.ieta() * b.ieta() > 0)
138  return abs(a.ieta()-b.ieta());
139  else
140  return abs(a.ieta()-b.ieta())-1;
141 }
142 
143 int EBDetId::distancePhi(const EBDetId& a,const EBDetId& b) {
144  int PI = 180;
145  int result = a.iphi() - b.iphi();
146 
147  while (result > PI) result -= 2*PI;
148  while (result <= -PI) result += 2*PI;
149  return abs(result);
150 
151 }
152 
153 float EBDetId::approxEta( const DetId id ) {
154  if( id.subdetId() == EcalBarrel ) {
155  EBDetId ebId( id );
156  return ebId.approxEta();
157  } else {
158  return 0;
159  }
160 }
161 
162 
163 #include<ostream>
164 std::ostream& operator<<(std::ostream& s,const EBDetId& id) {
165  return s << "(EB ieta " << id.ieta() << ", iphi " << id.iphi()
166  << " ; ism " << id.ism() << " , ic " << id.ic() << ')';
167 }
168 
float approxEta() const
Definition: EBDetId.h:106
int i
Definition: DBlmapReader.cc:9
static bool isNextToEtaBoundary(EBDetId id)
Definition: EBDetId.cc:125
#define PI
int tower_iphi() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.cc:114
EBDetId switchZSide() const
Definition: EBDetId.cc:82
int numberBySM() const
Definition: EBDetId.cc:57
static const int kCrystalsPerSM
Definition: EBDetId.h:151
DetId()
Create an empty or null id (also for persistence)
Definition: DetId.h:26
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:188
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
EBDetId()
Definition: EBDetId.h:23
int ism() const
get the ECAL/SM id
Definition: EBDetId.h:61
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:124
tuple result
Definition: mps_fire.py:83
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
static const int kCrystalsInPhi
Definition: EBDetId.h:149
static int distanceEta(const EBDetId &a, const EBDetId &b)
Definition: EBDetId.cc:135
static bool isNextToBoundary(EBDetId id)
Definition: EBDetId.cc:121
static int distancePhi(const EBDetId &a, const EBDetId &b)
Definition: EBDetId.cc:143
static bool isNextToPhiBoundary(EBDetId id)
Definition: EBDetId.cc:130
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
static const int kModuleBoundaries[4]
Definition: EBDetId.h:148
static const float crystalUnitToEta
Definition: EBDetId.h:160
EBDetId offsetBy(int nrStepsEta, int nrStepsPhi) const
Definition: EBDetId.cc:61
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
static const int ETAPHIMODE
Definition: EBDetId.h:166
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:46
Definition: DetId.h:18
bool positiveZ() const
Definition: EBDetId.h:78
uint32_t id_
Definition: DetId.h:55
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
static const int SMCRYSTALMODE
Definition: EBDetId.h:167
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
int ietaAbs() const
get the absolute value of the crystal ieta
Definition: EBDetId.h:49