CMS 3D CMS Logo

EcalCondObjectContainer.h
Go to the documentation of this file.
1 #ifndef ECAL_COND_OBJECT_CONTAINER_HH
2 #define ECAL_COND_OBJECT_CONTAINER_HH
3 
5 
9 
10 #include <vector>
11 
12 template <typename T>
14 public:
15  typedef T Item;
16  typedef Item value_type;
18  typedef typename std::vector<Item> Items;
19  typedef typename std::vector<Item>::const_iterator const_iterator;
20  typedef typename std::vector<Item>::iterator iterator;
21 
24 
25  void clear() {
26  eb_.clear();
27  ee_.clear();
28  }
29 
30  inline const Items &barrelItems() const { return eb_.items(); };
31 
32  inline const Items &endcapItems() const { return ee_.items(); };
33 
34  inline const Item &barrel(size_t hashedIndex) const { return eb_.item(hashedIndex); }
35 
36  inline const Item &endcap(size_t hashedIndex) const { return ee_.item(hashedIndex); }
37 
38  inline void insert(std::pair<uint32_t, Item> const &a) {
39  DetId id(a.first);
40  switch (id.subdetId()) {
41  case EcalBarrel: {
42  eb_.insert(a);
43  } break;
44  case EcalEndcap: {
45  ee_.insert(a);
46  } break;
47  default:
48  // FIXME (add throw)
49  return;
50  }
51  }
52 
53  inline const_iterator find(uint32_t rawId) const {
54  DetId id(rawId);
55  switch (id.subdetId()) {
56  case EcalBarrel: {
57  const_iterator it = eb_.find(rawId);
58  if (it != eb_.end()) {
59  return it;
60  } else {
61  return ee_.end();
62  }
63  } break;
64  case EcalEndcap: {
65  return ee_.find(rawId);
66  } break;
67  default:
68  // FIXME (add throw)
69  return ee_.end();
70  }
71  return ee_.end();
72  }
73 
74  inline const_iterator end() const { return ee_.end(); }
75 
76  inline void setValue(const uint32_t id, const Item &item) { (*this)[id] = item; }
77 
78  inline const self &getMap() const { return *this; }
79 
80  inline size_t size() const { return eb_.size() + ee_.size(); }
81  // add coherent operator++, not needed now -- FIXME
82 
83  inline Item &operator[](uint32_t rawId) {
84  DetId id(rawId);
85  return (id.subdetId() == EcalBarrel) ? eb_[rawId] : ee_[rawId];
86  }
87 
88  inline Item operator[](uint32_t rawId) const {
89  DetId id(rawId);
90  switch (id.subdetId()) {
91  case EcalBarrel: {
92  return eb_[rawId];
93  } break;
94  case EcalEndcap: {
95  return ee_[rawId];
96  } break;
97  default:
98  // FIXME (add throw)
99  // sizeof(Item) <= sizeof(int64_t) for all Items.
100  return Item();
101  }
102  }
103 
104  void summary(float &arg_mean_x_EB,
105  float &arg_rms_EB,
106  int &arg_num_x_EB,
107  float &arg_mean_x_EE,
108  float &arg_rms_EE,
109  int &arg_num_x_EE) const {
110  //std::stringstream ss;
111 
112  const int kSides = 2;
113  const int kBarlRings = EBDetId::MAX_IETA;
114  const int kBarlWedges = EBDetId::MAX_IPHI;
115  const int kEndcWedgesX = EEDetId::IX_MAX;
116  const int kEndcWedgesY = EEDetId::IY_MAX;
117 
119 
120  float mean_x_EB = 0;
121  float mean_xx_EB = 0;
122  int num_x_EB = 0;
123 
124  float mean_x_EE = 0;
125  float mean_xx_EE = 0;
126  int num_x_EE = 0;
127 
128  for (int sign = 0; sign < kSides; sign++) {
129  int thesign = sign == 1 ? 1 : -1;
130 
131  for (int ieta = 0; ieta < kBarlRings; ieta++) {
132  for (int iphi = 0; iphi < kBarlWedges; iphi++) {
133  EBDetId id((ieta + 1) * thesign, iphi + 1);
134 
135  //float x= object()[id.rawId()];
136  float x = eb_[id.rawId()];
137  num_x_EB++;
138  mean_x_EB = mean_x_EB + x;
139  mean_xx_EB = mean_xx_EB + x * x;
140  }
141  }
142 
143  for (int ix = 0; ix < kEndcWedgesX; ix++) {
144  for (int iy = 0; iy < kEndcWedgesY; iy++) {
145  if (!EEDetId::validDetId(ix + 1, iy + 1, thesign))
146  continue;
147 
148  EEDetId id(ix + 1, iy + 1, thesign);
149  //float x=object()[id.rawId()];
150  float x = ee_[id.rawId()];
151  num_x_EE++;
152  mean_x_EE = mean_x_EE + x;
153  mean_xx_EE = mean_xx_EE + x * x;
154 
155  } //iy
156  } //ix
157  }
158 
159  mean_x_EB = mean_x_EB / num_x_EB;
160  mean_x_EE = mean_x_EE / num_x_EE;
161  mean_xx_EB = mean_xx_EB / num_x_EB;
162  mean_xx_EE = mean_xx_EE / num_x_EE;
163  float rms_EB = (mean_xx_EB - mean_x_EB * mean_x_EB);
164  float rms_EE = (mean_xx_EE - mean_x_EE * mean_x_EE);
165 
166  arg_mean_x_EB = mean_x_EB;
167  arg_rms_EB = rms_EB;
168  arg_num_x_EB = num_x_EB;
169 
170  arg_mean_x_EE = mean_x_EE;
171  arg_rms_EE = rms_EE;
172  arg_num_x_EE = num_x_EE;
173 
174  //ss << "ECAL BARREL Mean: "<< mean_x_EB <<" RMS: "<< rms_EB << " Nchan: "<< num_x_EB<< std::endl
175  // << "ECAL Endcap Mean: "<< mean_x_EE <<" RMS: "<< rms_EE << " Nchan: "<< num_x_EE<< std::endl ;
176 
177  //return ss.str();
178  }
179 
180 private:
183 
185 };
186 
188 #endif
std::vector< Item >::iterator iterator
size_t size() const
Definition: EcalContainer.h:84
static const int kBarlRings
EcalContainer< EEDetId, Item > ee_
void summary(float &arg_mean_x_EB, float &arg_rms_EB, int &arg_num_x_EB, float &arg_mean_x_EE, float &arg_rms_EE, int &arg_num_x_EE) const
const Items & endcapItems() const
Item & operator[](uint32_t rawId)
const Item & item(size_t hashid) const
Definition: EcalContainer.h:34
static const int kSides
EcalContainer< EBDetId, Item > eb_
const Item & barrel(size_t hashedIndex) const
static const int kBarlWedges
void setValue(const uint32_t id, const Item &item)
int hashedIndex(int ieta, int iphi)
Definition: EcalPyUtils.cc:36
const Item & endcap(size_t hashedIndex) const
static const int kEndcWedgesX
const Items & items() const
Definition: EcalContainer.h:36
const_iterator find(uint32_t rawId) const
void insert(std::pair< uint32_t, Item > const &a)
static const int IX_MAX
Definition: EEDetId.h:298
const Items & barrelItems() const
Definition: DetId.h:17
static const int MAX_IPHI
Definition: EBDetId.h:137
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
std::vector< Item >::const_iterator const_iterator
const_iterator end() const
Definition: EcalContainer.h:82
static const int MAX_IETA
Definition: EBDetId.h:136
#define COND_SERIALIZABLE
Definition: Serializable.h:39
void insert(std::pair< uint32_t, Item > const &a)
Definition: EcalContainer.h:32
double a
Definition: hdecay.h:119
const_iterator end() const
static const int IY_MAX
Definition: EEDetId.h:302
const_iterator find(uint32_t rawId) const
Definition: EcalContainer.h:73
long double T
Item operator[](uint32_t rawId) const
EcalCondObjectContainer< float > EcalFloatCondObjectContainer
static const int kEndcWedgesY