Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:35:38

0001 #ifndef ECAL_COND_OBJECT_CONTAINER_HH
0002 #define ECAL_COND_OBJECT_CONTAINER_HH
0003 
0004 #include "CondFormats/Serialization/interface/Serializable.h"
0005 
0006 #include "DataFormats/EcalDetId/interface/EcalContainer.h"
0007 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0008 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0009 
0010 #include <vector>
0011 
0012 template <typename T>
0013 class EcalCondObjectContainer {
0014 public:
0015   typedef T Item;
0016   typedef Item value_type;
0017   typedef EcalCondObjectContainer<T> self;
0018   typedef typename std::vector<Item> Items;
0019   typedef typename std::vector<Item>::const_iterator const_iterator;
0020   typedef typename std::vector<Item>::iterator iterator;
0021 
0022   EcalCondObjectContainer() {}
0023   ~EcalCondObjectContainer() {}
0024 
0025   void clear() {
0026     eb_.clear();
0027     ee_.clear();
0028   }
0029 
0030   inline const Items &barrelItems() const { return eb_.items(); };
0031 
0032   inline const Items &endcapItems() const { return ee_.items(); };
0033 
0034   inline const Item &barrel(size_t hashedIndex) const { return eb_.item(hashedIndex); }
0035 
0036   inline const Item &endcap(size_t hashedIndex) const { return ee_.item(hashedIndex); }
0037 
0038   inline void insert(std::pair<uint32_t, Item> const &a) {
0039     DetId id(a.first);
0040     switch (id.subdetId()) {
0041       case EcalBarrel: {
0042         eb_.insert(a);
0043       } break;
0044       case EcalEndcap: {
0045         ee_.insert(a);
0046       } break;
0047       default:
0048         // FIXME (add throw)
0049         return;
0050     }
0051   }
0052 
0053   inline const_iterator find(uint32_t rawId) const {
0054     DetId id(rawId);
0055     switch (id.subdetId()) {
0056       case EcalBarrel: {
0057         const_iterator it = eb_.find(rawId);
0058         if (it != eb_.end()) {
0059           return it;
0060         } else {
0061           return ee_.end();
0062         }
0063       } break;
0064       case EcalEndcap: {
0065         return ee_.find(rawId);
0066       } break;
0067       default:
0068         // FIXME (add throw)
0069         return ee_.end();
0070     }
0071     return ee_.end();
0072   }
0073 
0074   inline const_iterator end() const { return ee_.end(); }
0075 
0076   inline void setValue(const uint32_t id, const Item &item) { (*this)[id] = item; }
0077 
0078   inline const self &getMap() const { return *this; }
0079 
0080   inline size_t size() const { return eb_.size() + ee_.size(); }
0081   // add coherent operator++, not needed now -- FIXME
0082 
0083   inline Item &operator[](uint32_t rawId) {
0084     DetId id(rawId);
0085     return (id.subdetId() == EcalBarrel) ? eb_[rawId] : ee_[rawId];
0086   }
0087 
0088   inline Item operator[](uint32_t rawId) const {
0089     DetId id(rawId);
0090     switch (id.subdetId()) {
0091       case EcalBarrel: {
0092         return eb_[rawId];
0093       } break;
0094       case EcalEndcap: {
0095         return ee_[rawId];
0096       } break;
0097       default:
0098         // FIXME (add throw)
0099         // sizeof(Item) <= sizeof(int64_t) for all Items.
0100         return Item();
0101     }
0102   }
0103 
0104   void summary(float &arg_mean_x_EB,
0105                float &arg_rms_EB,
0106                int &arg_num_x_EB,
0107                float &arg_mean_x_EE,
0108                float &arg_rms_EE,
0109                int &arg_num_x_EE) const {
0110     //std::stringstream ss;
0111 
0112     const int kSides = 2;
0113     const int kBarlRings = EBDetId::MAX_IETA;
0114     const int kBarlWedges = EBDetId::MAX_IPHI;
0115     const int kEndcWedgesX = EEDetId::IX_MAX;
0116     const int kEndcWedgesY = EEDetId::IY_MAX;
0117 
0118     /// calculate mean and sigma
0119 
0120     float mean_x_EB = 0;
0121     float mean_xx_EB = 0;
0122     int num_x_EB = 0;
0123 
0124     float mean_x_EE = 0;
0125     float mean_xx_EE = 0;
0126     int num_x_EE = 0;
0127 
0128     for (int sign = 0; sign < kSides; sign++) {
0129       int thesign = sign == 1 ? 1 : -1;
0130 
0131       for (int ieta = 0; ieta < kBarlRings; ieta++) {
0132         for (int iphi = 0; iphi < kBarlWedges; iphi++) {
0133           EBDetId id((ieta + 1) * thesign, iphi + 1);
0134 
0135           //float x= object()[id.rawId()];
0136           float x = eb_[id.rawId()];
0137           num_x_EB++;
0138           mean_x_EB = mean_x_EB + x;
0139           mean_xx_EB = mean_xx_EB + x * x;
0140         }
0141       }
0142 
0143       for (int ix = 0; ix < kEndcWedgesX; ix++) {
0144         for (int iy = 0; iy < kEndcWedgesY; iy++) {
0145           if (!EEDetId::validDetId(ix + 1, iy + 1, thesign))
0146             continue;
0147 
0148           EEDetId id(ix + 1, iy + 1, thesign);
0149           //float x=object()[id.rawId()];
0150           float x = ee_[id.rawId()];
0151           num_x_EE++;
0152           mean_x_EE = mean_x_EE + x;
0153           mean_xx_EE = mean_xx_EE + x * x;
0154 
0155         }  //iy
0156       }  //ix
0157     }
0158 
0159     mean_x_EB = mean_x_EB / num_x_EB;
0160     mean_x_EE = mean_x_EE / num_x_EE;
0161     mean_xx_EB = mean_xx_EB / num_x_EB;
0162     mean_xx_EE = mean_xx_EE / num_x_EE;
0163     float rms_EB = (mean_xx_EB - mean_x_EB * mean_x_EB);
0164     float rms_EE = (mean_xx_EE - mean_x_EE * mean_x_EE);
0165 
0166     arg_mean_x_EB = mean_x_EB;
0167     arg_rms_EB = rms_EB;
0168     arg_num_x_EB = num_x_EB;
0169 
0170     arg_mean_x_EE = mean_x_EE;
0171     arg_rms_EE = rms_EE;
0172     arg_num_x_EE = num_x_EE;
0173 
0174     //ss << "ECAL BARREL Mean: "<< mean_x_EB <<" RMS: "<<  rms_EB << " Nchan: "<< num_x_EB<< std::endl
0175     //   << "ECAL Endcap Mean: "<< mean_x_EE <<" RMS: "<<  rms_EE << " Nchan: "<< num_x_EE<< std::endl ;
0176 
0177     //return ss.str();
0178   }
0179 
0180 private:
0181   EcalContainer<EBDetId, Item> eb_;
0182   EcalContainer<EEDetId, Item> ee_;
0183 
0184   COND_SERIALIZABLE;
0185 };
0186 
0187 typedef EcalCondObjectContainer<float> EcalFloatCondObjectContainer;
0188 #endif