Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:09:28

0001 /*
0002  * =====================================================================================
0003  *
0004  *       Filename:  CSCDQM_Detector.h
0005  *
0006  *    Description:  CSC detector functions.
0007  *
0008  *        Version:  1.0
0009  *        Created:  05/19/2008 10:52:21 AM
0010  *       Revision:  none
0011  *       Compiler:  gcc
0012  *
0013  *         Author:  Valdas Rapsevicius (VR), Valdas.Rapsevicius@cern.ch
0014  *        Company:  CERN, CH
0015  *
0016  * =====================================================================================
0017  */
0018 
0019 #ifndef CSCDQM_Detector_H
0020 #define CSCDQM_Detector_H
0021 
0022 #include <cmath>
0023 #include <cfloat>
0024 #include <map>
0025 #include <vector>
0026 #include <iostream>
0027 #include <sstream>
0028 #include <iomanip>
0029 
0030 #ifdef CSC_RENDER_PLUGIN
0031 #include "CSCDQM_Utility.h"
0032 #else
0033 #include "CSCDQM_Utility.h"
0034 #endif
0035 
0036 namespace cscdqm {
0037 
0038   /**
0039  * Number of Detector Components.
0040  */
0041 
0042 #define N_SIDES 2
0043 #define N_STATIONS 4
0044 #define N_RINGS 3
0045 #define N_CHAMBERS 36
0046 #define N_LAYERS 6
0047 #define N_CFEBS 5
0048 #define N_HVS 5
0049 
0050 /** Size of the address (number of components) */
0051 #define ADDR_SIZE 7
0052 
0053 /** Number of addressing elements in detector */
0054 #define N_ELEMENTS 9540
0055   //(7740 + 1800)
0056 
0057   /**
0058  * Partition function shortcuts
0059  */
0060 
0061 #define PARTITION_INDEX(x, y) (x * partitions_y + y)
0062 #define PARTITION_STEP_X (5.0 / partitions_x)
0063 #define PARTITION_STEP_Y ((2.0 * 3.14159) / partitions_y)
0064 
0065   /**
0066  * @brief  Mask of the address which is used to switch on and off appropriate Address fields.
0067  */
0068   struct AddressMask {
0069     bool side;
0070     bool station;
0071     bool ring;
0072     bool chamber;
0073     bool layer;
0074     bool cfeb;
0075     bool hv;
0076   };
0077 
0078   /**
0079  * @brief  Structure to store detector addresses of any granularity: from
0080  * whole detector to the single HV element.
0081  */
0082   struct Address {
0083     unsigned int side;
0084     unsigned int station;
0085     unsigned int ring;
0086     unsigned int chamber;
0087     unsigned int layer;
0088     unsigned int cfeb;
0089     unsigned int hv;
0090 
0091     AddressMask mask;
0092 
0093     const bool operator==(const Address& a) const {
0094       if (mask.side == a.mask.side && mask.side == true && side != a.side)
0095         return false;
0096       if (mask.station == a.mask.station && mask.station == true && station != a.station)
0097         return false;
0098       if (mask.ring == a.mask.ring && mask.ring == true && ring != a.ring)
0099         return false;
0100       if (mask.chamber == a.mask.chamber && mask.chamber == true && chamber != a.chamber)
0101         return false;
0102       if (mask.layer == a.mask.layer && mask.layer == true && layer != a.layer)
0103         return false;
0104       if (mask.cfeb == a.mask.cfeb && mask.cfeb == true && cfeb != a.cfeb)
0105         return false;
0106       if (mask.hv == a.mask.hv && mask.hv == true && hv != a.hv)
0107         return false;
0108       return true;
0109     };
0110 
0111     friend std::ostream& operator<<(std::ostream& out, const Address& adr) {
0112       out << adr.name();
0113       return out;
0114     }
0115 
0116     /**
0117    * @brief  Get the full name of the address prefixed with CSC_. It is being used by summaryReportContent variables
0118    * @return Address name as string
0119    */
0120     const std::string name() const {
0121       std::ostringstream oss;
0122       oss << "CSC";
0123       if (mask.side) {
0124         oss << "_Side" << (side == 1 ? "Plus" : "Minus");
0125         if (mask.station) {
0126           oss << "_Station" << std::setfill('0') << std::setw(2) << station;
0127           if (mask.ring) {
0128             oss << "_Ring" << std::setfill('0') << std::setw(2) << ring;
0129             if (mask.chamber) {
0130               oss << "_Chamber" << std::setfill('0') << std::setw(2) << chamber;
0131               if (mask.layer) {
0132                 oss << "_Layer" << std::setfill('0') << std::setw(2) << layer;
0133                 if (mask.cfeb) {
0134                   oss << "_CFEB" << std::setfill('0') << std::setw(2) << cfeb;
0135                   if (mask.hv) {
0136                     oss << "_HV" << std::setfill('0') << std::setw(2) << hv;
0137                   }
0138                 }
0139               }
0140             }
0141           }
0142         }
0143       }
0144       return oss.str();
0145     }
0146   };
0147 
0148   /**
0149  * @brief  Area covered by Address in eta/phy space
0150  */
0151   struct AddressBox {
0152     Address adr;
0153     float xmin;
0154     float xmax;
0155     float ymin;
0156     float ymax;
0157   };
0158 
0159   /** Map of partitions and partition covering adresses indexes type */
0160   typedef std::map<const unsigned int, std::vector<unsigned int> > PartitionMap;
0161 
0162   /** Iterator type of PartitionMap */
0163   typedef PartitionMap::iterator PartitionMapIterator;
0164 
0165   /**
0166  * @class Detector
0167  * @brief Detector geometry and addressing related imformation and routines
0168  */
0169   class Detector {
0170   public:
0171     Detector(const unsigned int p_partitions_x = 0, const unsigned int p_partitions_y = 0);
0172 
0173     const bool NextAddress(unsigned int& i, const Address*& adr, const Address& mask) const;
0174     const bool NextAddressBox(unsigned int& i, const AddressBox*& box, const Address& mask) const;
0175     //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);
0176     const bool NextAddressBoxByPartition(unsigned int& i,
0177                                          const unsigned int px,
0178                                          const unsigned int py,
0179                                          AddressBox*& box);
0180 
0181     const float Area(const unsigned int station) const;
0182     const float Area(const Address& adr) const;
0183 
0184     void PrintAddress(const Address& adr) const;
0185     const bool AddressFromString(const std::string& str_address, Address& adr) const;
0186 
0187     const unsigned int NumberOfRings(const unsigned int station) const;
0188     const unsigned int NumberOfChambers(const unsigned int station, const unsigned int ring) const;
0189     const unsigned int NumberOfChamberCFEBs(const unsigned int station, const unsigned int ring) const;
0190     const unsigned int NumberOfChamberHVs(const unsigned int station, const unsigned int ring) const;
0191     unsigned int GlobalChamberIndex(unsigned int side,
0192                                     unsigned int station,
0193                                     unsigned int ring,
0194                                     unsigned int chamber) const;
0195 
0196   private:
0197     const float Eta(const float r, const float z) const;
0198     const float EtaToX(const float eta) const;
0199     const float PhiToY(const float phi) const;
0200     const float Z(const int station, const int ring) const;
0201     const float RMinHV(const int station, const int ring, const int n_hv) const;
0202     const float RMaxHV(const int station, const int ring, const int n_hv) const;
0203     const float PhiMinCFEB(const int station, const int ring, const int chamber, const int cfeb) const;
0204     const float PhiMaxCFEB(const int station, const int ring, const int chamber, const int cfeb) const;
0205 
0206     /** Address boxes in epa/phi space */
0207     AddressBox boxes[N_ELEMENTS];
0208 
0209     /** Station areas precalculated */
0210     float station_area[N_STATIONS];
0211 
0212     /** Number of partitions in X axis */
0213     unsigned int partitions_x;
0214 
0215     /** Number of partitions in Y axis */
0216     unsigned int partitions_y;
0217 
0218     /** Map of partitions and list of it covering addresses indexes */
0219     PartitionMap partitions;
0220   };
0221 
0222 }  // namespace cscdqm
0223 
0224 #endif