CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DQM/CSCMonitorModule/interface/CSCDQM_Detector.h

Go to the documentation of this file.
00001 /*
00002  * =====================================================================================
00003  *
00004  *       Filename:  CSCDQM_Detector.h
00005  *
00006  *    Description:  CSC detector functions.
00007  *
00008  *        Version:  1.0
00009  *        Created:  05/19/2008 10:52:21 AM
00010  *       Revision:  none
00011  *       Compiler:  gcc
00012  *
00013  *         Author:  Valdas Rapsevicius (VR), Valdas.Rapsevicius@cern.ch
00014  *        Company:  CERN, CH
00015  *
00016  * =====================================================================================
00017  */
00018 
00019 #ifndef CSCDQM_Detector_H
00020 #define CSCDQM_Detector_H
00021 
00022 #include <math.h>
00023 #include <float.h>
00024 #include <map>
00025 #include <vector>
00026 #include <iostream>
00027 #include <sstream>
00028 #include <iomanip>
00029 
00030 #ifdef CSC_RENDER_PLUGIN
00031 #include "CSCDQM_Utility.h"
00032 #else
00033 #include "DQM/CSCMonitorModule/interface/CSCDQM_Utility.h"
00034 #endif
00035 
00036 namespace cscdqm {
00037 
00042 #define N_SIDES    2
00043 #define N_STATIONS 4
00044 #define N_RINGS    3
00045 #define N_CHAMBERS 36
00046 #define N_LAYERS   6
00047 #define N_CFEBS    5
00048 #define N_HVS      5
00049 
00051 #define ADDR_SIZE  7
00052 
00054 #define N_ELEMENTS 9540
00055 //(7740 + 1800)
00056 
00061 #define PARTITION_INDEX(x,y)  (x * partitions_y + y)
00062 #define PARTITION_STEP_X      (5.0 / partitions_x)
00063 #define PARTITION_STEP_Y      ((2.0 * 3.14159) / partitions_y)
00064 
00068 struct AddressMask {
00069   bool side;
00070   bool station;
00071   bool ring;
00072   bool chamber;
00073   bool layer;
00074   bool cfeb;
00075   bool hv;
00076 };
00077 
00082 struct Address {
00083 
00084   unsigned int side;
00085   unsigned int station;
00086   unsigned int ring;
00087   unsigned int chamber;
00088   unsigned int layer;
00089   unsigned int cfeb;
00090   unsigned int hv;
00091 
00092   AddressMask mask;
00093 
00094   const bool operator== (const Address& a) const {
00095     if (mask.side    == a.mask.side    && mask.side    == true && side    != a.side)    return false;
00096     if (mask.station == a.mask.station && mask.station == true && station != a.station) return false;
00097     if (mask.ring    == a.mask.ring    && mask.ring    == true && ring    != a.ring)    return false;
00098     if (mask.chamber == a.mask.chamber && mask.chamber == true && chamber != a.chamber) return false;
00099     if (mask.layer   == a.mask.layer   && mask.layer   == true && layer   != a.layer)   return false;
00100     if (mask.cfeb    == a.mask.cfeb    && mask.cfeb    == true && cfeb    != a.cfeb)    return false;
00101     if (mask.hv      == a.mask.hv      && mask.hv      == true && hv      != a.hv)      return false;
00102     return true;
00103   };
00104 
00105   const Address* operator= (const Address& a) {
00106     mask.side    = a.mask.side;
00107     side         = a.side;
00108     mask.station = a.mask.station;
00109     station      = a.station;
00110     mask.ring    = a.mask.ring;
00111     ring         = a.ring;
00112     mask.chamber = a.mask.chamber;
00113     chamber      = a.chamber;
00114     mask.layer   = a.mask.layer;
00115     layer        = a.layer;
00116     mask.cfeb    = a.mask.cfeb;
00117     cfeb         = a.cfeb;
00118     mask.hv      = a.mask.hv;
00119     hv           = a.hv;
00120     return this;
00121   };
00122 
00123   friend std::ostream& operator<<(std::ostream& out, const Address& adr) {
00124     out << adr.name();
00125     return out;
00126   }
00127 
00132   const std::string name() const {
00133     std::ostringstream oss;
00134     oss << "CSC";
00135     if (mask.side) {
00136       oss << "_Side" << (side == 1 ? "Plus" : "Minus");
00137       if (mask.station) {
00138         oss << "_Station" << std::setfill('0') << std::setw(2) << station;
00139         if (mask.ring) {
00140           oss << "_Ring" << std::setfill('0') << std::setw(2) << ring;
00141           if (mask.chamber) {
00142             oss << "_Chamber" << std::setfill('0') << std::setw(2) << chamber;
00143             if (mask.layer) {
00144               oss << "_Layer" << std::setfill('0') << std::setw(2) << layer;
00145               if (mask.cfeb) {
00146                 oss << "_CFEB" << std::setfill('0') << std::setw(2) << cfeb;
00147                 if (mask.hv) {
00148                   oss << "_HV" << std::setfill('0') << std::setw(2) << hv;
00149                 }
00150               }
00151             }
00152           }
00153         }
00154       }
00155     }
00156     return oss.str();
00157   }
00158   
00159 };
00160 
00164 struct AddressBox {
00165   Address adr;
00166   float xmin;
00167   float xmax;
00168   float ymin;
00169   float ymax;
00170 };
00171 
00172 
00174 typedef std::map<const unsigned int, std::vector<unsigned int> > PartitionMap;
00175 
00177 typedef PartitionMap::iterator PartitionMapIterator;
00178 
00183 class Detector {
00184 
00185   public:
00186 
00187     Detector(const unsigned int p_partitions_x = 0, const unsigned int p_partitions_y = 0);
00188 
00189     const bool NextAddress(unsigned int& i, const Address*& adr, const Address& mask) const;
00190     const bool NextAddressBox(unsigned int& i, const AddressBox*& box, const Address& mask) const;
00191     //const bool NextAddressBoxByPartition(unsigned int& i, unsigned int& px, unsigned int& py, const AddressBox*& box, const Address& mask, const float xmin, const float xmax, const float ymin, const float ymax);
00192     const bool NextAddressBoxByPartition (unsigned int& i, const unsigned int px, const unsigned int py, AddressBox*& box);
00193 
00194     const float Area(const unsigned int station) const;
00195     const float Area(const Address& adr) const;
00196 
00197     void PrintAddress(const Address& adr) const;
00198     const bool AddressFromString(const std::string& str_address, Address& adr) const;
00199 
00200     const unsigned int NumberOfRings(const unsigned int station) const;
00201     const unsigned int NumberOfChambers(const unsigned int station, const unsigned int ring) const;
00202     const unsigned int NumberOfChamberCFEBs(const unsigned int station, const unsigned int ring) const;
00203     const unsigned int NumberOfChamberHVs(const unsigned int station, const unsigned int ring) const;
00204     unsigned int GlobalChamberIndex(unsigned int side, unsigned int station, unsigned int ring, unsigned int chamber) const;
00205 
00206   private:
00207 
00208     const float Eta(const float r, const float z) const;
00209     const float EtaToX(const float eta) const;
00210     const float PhiToY(const float phi) const;
00211     const float Z(const int station, const int ring) const;
00212     const float RMinHV(const int station, const int ring, const int n_hv) const;
00213     const float RMaxHV(const int station, const int ring, const int n_hv) const;
00214     const float PhiMinCFEB(const int station, const int ring, const int chamber, const int cfeb) const;
00215     const float PhiMaxCFEB(const int station, const int ring, const int chamber, const int cfeb) const;
00216 
00218     AddressBox boxes[N_ELEMENTS];
00219 
00221     float station_area[N_STATIONS];
00222 
00224     unsigned int partitions_x;
00225 
00227     unsigned int partitions_y;
00228 
00230     PartitionMap partitions;
00231 
00232 };
00233 
00234 }
00235 
00236 #endif