CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DQM/CSCMonitorModule/plugins/CSCDQM_Detector.cc

Go to the documentation of this file.
00001 /*
00002  * =====================================================================================
00003  *
00004  *       Filename:  Detector.cc
00005  *
00006  *    Description:  Class Detector implementation
00007  *
00008  *        Version:  1.0
00009  *        Created:  05/19/2008 10:59:34 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 #ifdef CSC_RENDER_PLUGIN
00020 #include "CSCDQM_Detector.h"
00021 #else
00022 #include "CSCDQM_Detector.h"
00023 #endif
00024 
00025 namespace cscdqm {
00026 
00033   Detector::Detector(const unsigned int p_partitions_x, const unsigned int p_partitions_y) {
00034   
00035     partitions_x = p_partitions_x;
00036     partitions_y = p_partitions_y;
00037   
00038     unsigned int i = 0; 
00039     Address adr;
00040   
00041     adr.mask.layer = false;
00042     adr.mask.side = adr.mask.station = adr.mask.ring = adr.mask.chamber = adr.mask.cfeb = adr.mask.hv = true;
00043   
00045     for (adr.side = 1; adr.side <= N_SIDES; adr.side++) { 
00046       float sign = +1.0;
00047       if(adr.side == 2) sign = -1.0;
00048       for (adr.station = 1; adr.station <= N_STATIONS; adr.station++) {
00049         for (adr.ring = 1; adr.ring <= NumberOfRings(adr.station); adr.ring++) { 
00050           for (adr.chamber = 1; adr.chamber <= NumberOfChambers(adr.station, adr.ring); adr.chamber++) {
00051             for (adr.cfeb = 1; adr.cfeb <= NumberOfChamberCFEBs(adr.station, adr.ring); adr.cfeb++) {
00052               for (adr.hv = 1; adr.hv <= NumberOfChamberHVs(adr.station, adr.ring); adr.hv++) {
00053   
00054                 float z = Z(adr.station, adr.ring);
00055                 float r_min = RMinHV(adr.station, adr.ring, adr.hv);
00056                 float r_max = RMaxHV(adr.station, adr.ring, adr.hv);
00057                 float eta_min = sign * Eta(r_min, z);
00058                 float eta_max = sign * Eta(r_max, z);
00059                 float x_min = EtaToX(eta_min);
00060                 float x_max = EtaToX(eta_max);
00061                 float phi_min = 0;
00062                 float phi_max = 0;
00063   
00064                 if(adr.station == 1 && adr.ring == 1 && adr.hv == 1) {
00065                   phi_min = PhiMinCFEB(adr.station, adr.ring, adr.chamber, 1);
00066                   phi_max = PhiMaxCFEB(adr.station, adr.ring, adr.chamber, NumberOfChamberCFEBs(adr.station, adr.ring));
00067                 } else {
00068                   phi_min = PhiMinCFEB(adr.station, adr.ring, adr.chamber, adr.cfeb);
00069                   phi_max = PhiMaxCFEB(adr.station, adr.ring, adr.chamber, adr.cfeb);
00070                 }
00071   
00072                 float y_min = PhiToY(phi_min);
00073                 float y_max = PhiToY(phi_max);
00074                   
00075                 boxes[i].adr = adr;
00076   
00077                 float xboxmin = (x_min < x_max ? x_min : x_max);
00078                 float xboxmax = (x_max > x_min ? x_max : x_min);
00079                 float yboxmin = (y_min < y_max ? y_min : y_max);
00080                 float yboxmax = (y_max > y_min ? y_max : y_min);
00081   
00082                 boxes[i].xmin = xboxmin;
00083                 boxes[i].xmax = xboxmax;
00084                 boxes[i].ymin = yboxmin;
00085                 boxes[i].ymax = yboxmax;
00086   
00090                 unsigned int x1 = int(floor(xboxmin / PARTITION_STEP_X)) + int(partitions_x / 2);
00091                 unsigned int x2 = int( ceil(xboxmax / PARTITION_STEP_X)) + int(partitions_x / 2);
00092                 unsigned int y1 = int(floor(yboxmin / PARTITION_STEP_Y));
00093                 unsigned int y2 = int( ceil(yboxmax / PARTITION_STEP_Y));
00094   
00095                 for (unsigned int x = x1; x < x2; x++) {
00096                   for (unsigned int y = y1; y < y2; y++) {
00097                     
00098                     unsigned int index = PARTITION_INDEX(x, y);
00099                     PartitionMapIterator iter = partitions.find(index);
00100                     if (iter == partitions.end()) {
00101                       std::vector<unsigned int> v;
00102                       partitions.insert(std::make_pair(index, v));
00103                     }
00104                     partitions[index].push_back(i);
00105   
00106                   }
00107                 }
00108   
00109                 i++;
00110   
00111               }
00112             }
00113           }
00114         }
00115       }
00116   
00117     }
00118   
00120     adr.mask.side = adr.mask.ring = adr.mask.chamber = adr.mask.layer = adr.mask.cfeb = adr.mask.hv = false;
00121     adr.mask.station = true;
00122     adr.station = 1;
00123     station_area[0] = Area(adr);
00124     adr.station = 2;
00125     station_area[1] = Area(adr);
00126     adr.station = 3;
00127     station_area[2] = Area(adr);
00128     adr.station = 4;
00129     station_area[3] = Area(adr);
00130   
00131   }
00132   
00138   const float Detector::Area(const unsigned int station) const {
00139     if (station > 0 && station <= N_STATIONS) {
00140       return station_area[station - 1];
00141     }
00142     return 0;
00143   }
00144   
00153   unsigned int Detector::GlobalChamberIndex(unsigned int side, unsigned int station, unsigned int ring, unsigned int chamber) const {
00154     Address adr, iadr;
00155     adr.mask.side = adr.mask.station = adr.mask.ring = adr.mask.chamber = true;
00156     adr.mask.layer = adr.mask.cfeb = adr.mask.hv = false;
00157     adr.side = side;
00158     adr.station = station;
00159     adr.ring = ring;
00160     adr.chamber = chamber;
00161     iadr = adr;
00162 
00163     unsigned int i = 1;
00164     for (iadr.side = 1; iadr.side <= N_SIDES; iadr.side++) { 
00165       for (iadr.station = 1; iadr.station <= N_STATIONS; iadr.station++) {
00166         for (iadr.ring = 1; iadr.ring <= NumberOfRings(iadr.station); iadr.ring++) { 
00167           for (iadr.chamber = 1; iadr.chamber <= NumberOfChambers(iadr.station, iadr.ring); iadr.chamber++) {
00168             if (iadr == adr) {
00169               return i;
00170             }
00171             i += 1;
00172           }
00173         }
00174       }
00175     }
00176     return 0;
00177   }
00178 
00184   const float Detector::Area(const Address& adr) const {
00185     float a = 0;
00186     for(unsigned int i = 0; i < N_ELEMENTS; i++ ) {
00187       if (boxes[i].adr == adr) {
00188         a += fabs((boxes[i].xmax - boxes[i].xmin) * (boxes[i].ymax - boxes[i].ymin));
00189       }
00190     }
00191     return a;
00192   }
00193   
00199   const unsigned int Detector::NumberOfRings(const unsigned int station) const {
00200     if (station == 1) return 3;
00201     if (station == 2) return 2;
00202     if (station == 3) return 2;
00203     if (station == 4) return 2;
00204     return 0;
00205   }
00206   
00213   const unsigned int Detector::NumberOfChambers(const unsigned int station, const unsigned int ring) const {
00214     if(station == 1 && ring == 1) return 36;
00215     if(station == 1 && ring == 2) return 36;
00216     if(station == 1 && ring == 3) return 36;
00217     if(station == 2 && ring == 1) return 18;
00218     if(station == 2 && ring == 2) return 36;
00219     if(station == 3 && ring == 1) return 18;
00220     if(station == 3 && ring == 2) return 36;
00221     if(station == 4 && ring == 1) return 18;
00222     if(station == 4 && ring == 2) return 36;
00223     return 0;
00224   }
00225   
00232   const unsigned int Detector::NumberOfChamberCFEBs(const unsigned int station, const unsigned int ring) const {
00233     if(station == 1 && ring == 1) return 4;
00234     if(station == 1 && ring == 2) return 5;
00235     if(station == 1 && ring == 3) return 4;
00236     if(station == 2 && ring == 1) return 5;
00237     if(station == 2 && ring == 2) return 5;
00238     if(station == 3 && ring == 1) return 5;
00239     if(station == 3 && ring == 2) return 5;
00240     if(station == 4 && ring == 1) return 5;
00241     if(station == 4 && ring == 2) return 5;
00242     return 0;
00243   }
00244   
00251   const unsigned int Detector::NumberOfChamberHVs(const unsigned int station, const unsigned int ring) const {
00252     if(station == 1 && ring == 1) return 2;
00253     if(station == 1 && ring == 2) return 3;
00254     if(station == 1 && ring == 3) return 3;
00255     if(station == 2 && ring == 1) return 3;
00256     if(station == 2 && ring == 2) return 5;
00257     if(station == 3 && ring == 1) return 3;
00258     if(station == 3 && ring == 2) return 5;
00259     if(station == 4 && ring == 1) return 3;
00260     if(station == 4 && ring == 2) return 5;
00261     return 0;
00262   }
00263   
00269   void Detector::PrintAddress(const Address& adr) const {
00270   
00271     std::cout << "Side (" << std::boolalpha << adr.mask.side << ")"; 
00272     if (adr.mask.side) std::cout <<  " = " << adr.side;
00273   
00274     std::cout << ", Station (" << std::boolalpha << adr.mask.station << ")"; 
00275     if (adr.mask.station) std::cout << " = " << adr.station;
00276   
00277     std::cout << ", Ring (" << std::boolalpha << adr.mask.ring << ")"; 
00278     if (adr.mask.ring) std::cout << " = " << adr.ring;
00279   
00280     std::cout << ", Chamber (" << std::boolalpha << adr.mask.chamber << ")"; 
00281     if (adr.mask.chamber) std::cout << " = " << adr.chamber;
00282   
00283     std::cout << ", Layer (" << std::boolalpha << adr.mask.layer << ")"; 
00284     if (adr.mask.layer) std::cout << " = " << adr.layer;
00285   
00286     std::cout << ", CFEB (" << std::boolalpha << adr.mask.cfeb << ")"; 
00287     if (adr.mask.cfeb) std::cout << " = " << adr.cfeb;
00288   
00289     std::cout << ", HV (" << std::boolalpha << adr.mask.hv << ")"; 
00290     if (adr.mask.hv) std::cout << " = " << adr.hv;
00291   
00292     std::cout << std::endl;
00293   }
00294   
00302   const bool Detector::NextAddress(unsigned int& i, const Address*& adr, const Address& mask) const {
00303     for(; i < N_ELEMENTS; i++ ) {
00304       if (boxes[i].adr == mask) {
00305           adr = &boxes[i].adr;
00306           i++;
00307           return true; 
00308       }
00309     }
00310     return false;
00311   }
00312   
00320   const bool Detector::NextAddressBox(unsigned int& i, const AddressBox*& box, const Address& mask) const {
00321   
00322     for(; i < N_ELEMENTS; i++ ) {
00323       if (boxes[i].adr == mask) {
00324           box = &boxes[i];
00325           i++;
00326           return true; 
00327         }
00328     }
00329     return false;
00330   }
00331   
00340   const bool Detector::NextAddressBoxByPartition (unsigned int& i, const unsigned int px, const unsigned int py, AddressBox*& box) {
00341   
00342     unsigned int index = PARTITION_INDEX(px, py);
00343   
00344     PartitionMapIterator iter = partitions.find(index);
00345     if (iter != partitions.end()) {
00346       if (i < partitions[index].size()) {
00347         box = &boxes[partitions[index].at(i)];
00348         i++;
00349         return true; 
00350       }
00351     }
00352     return false;
00353   
00354   }
00355   
00356   const float Detector::Eta(const float r, const float z) const {
00357     if(r > 0.0 || z > 0.0) {
00358       float sin_theta = r / sqrt(r * r + z * z);
00359       float cos_theta = z / sqrt(r * r + z * z);
00360       return - log(sin_theta / (cos_theta + 1));
00361     }
00362     if(r == 0.0) return FLT_MAX;
00363     return 0.0;
00364   }
00365   
00366   
00372   const float Detector::EtaToX(const float eta) const {
00373     float x_min   = -2.5;
00374     float x_max   =  2.5;
00375     float eta_min = -2.5;
00376     float eta_max =  2.5;
00377     float a = (x_max - x_min) / (eta_max - eta_min);
00378     float b = (eta_max * x_min - eta_min * x_max) / (eta_max - eta_min);
00379     return a * eta + b;
00380   }
00381   
00387   const float Detector::PhiToY(const float phi) const {
00388     float y_min   = 0.0;
00389     float y_max   = 2.0 * 3.14159;
00390     float phi_min = 0.0;
00391     float phi_max = 2.0 * 3.14159;
00392     float a = (y_max - y_min) / (phi_max - phi_min);
00393     float b = (phi_max * y_min - phi_min * y_max) / (phi_max - phi_min);
00394     return a * phi + b;
00395   }
00396   
00403   const float Detector::Z(const int station, const int ring) const {
00404     float z_csc = 0;
00405     
00406     if(station == 1 && ring == 1) z_csc = (5834.5 + 6101.5) / 2.0;
00407     if(station == 1 && ring == 2) z_csc = (6790.0 + 7064.3) / 2.0;
00408     if(station == 1 && ring == 3) z_csc = 6888.0;
00409     if(station == 2) z_csc = (8098.0 + 8346.0) / 2.0;
00410     if(station == 3) z_csc = (9414.8 + 9166.8) / 2.0;
00411     if(station == 4) z_csc = 10630.0; // has to be corrected
00412     
00413     return z_csc;
00414   }
00415   
00423   const float Detector::RMinHV(const int station, const int ring, const int n_hv) const {
00424     float r_min_hv = 0;
00425     
00426     if(station == 1 && ring == 1) {
00427       if(n_hv == 1) r_min_hv = 1060.0;
00428       if(n_hv == 2) r_min_hv = 1500.0;
00429     }
00430     
00431     if(station == 1 && ring == 2) {
00432       if(n_hv == 1) r_min_hv = 2815.0;
00433       if(n_hv == 2) r_min_hv = 3368.2;
00434       if(n_hv == 3) r_min_hv = 4025.7;
00435     }
00436     
00437     if(station == 1 && ring == 3) {
00438       if(n_hv == 1) r_min_hv = 5120.0;
00439       if(n_hv == 2) r_min_hv = 5724.1;
00440       if(n_hv == 3) r_min_hv = 6230.2;
00441     }
00442     
00443     if(station == 2 && ring == 1) {
00444       if(n_hv == 1) r_min_hv = 1469.2;
00445       if(n_hv == 2) r_min_hv = 2152.3;
00446       if(n_hv == 3) r_min_hv = 2763.7;
00447     }
00448     
00449     if(station == 3 && ring == 1) {
00450       if(n_hv == 1) r_min_hv = 1668.9;
00451       if(n_hv == 2) r_min_hv = 2164.9;
00452       if(n_hv == 3) r_min_hv = 2763.8;
00453     }
00454     
00455     if(station == 4 && ring == 1) {
00456       if(n_hv == 1) r_min_hv = 1876.1;
00457       if(n_hv == 2) r_min_hv = 2365.9;
00458       if(n_hv == 3) r_min_hv = 2865.0;
00459     }
00460     
00461     if((station == 2 || station == 3 || station == 4) && ring == 2) {
00462       if(n_hv == 1) r_min_hv = 3640.2;
00463       if(n_hv == 2) r_min_hv = 4446.3;
00464       if(n_hv == 3) r_min_hv = 5053.2;
00465       if(n_hv == 4) r_min_hv = 5660.1;
00466       if(n_hv == 5) r_min_hv = 6267.0;
00467     }
00468     
00469     return r_min_hv;
00470   }
00471   
00479   const float Detector::RMaxHV(const int station, const int ring, const int n_hv) const {
00480     float r_max_hv = 0;
00481     
00482     if(station == 1 && ring == 1) {
00483       if(n_hv == 1) r_max_hv = 1500.0;
00484       if(n_hv == 2) r_max_hv = 2565.0;
00485     }
00486     
00487     if(station == 1 && ring == 2) {
00488       if(n_hv == 1) r_max_hv = 3368.2;
00489       if(n_hv == 2) r_max_hv = 4025.7;
00490       if(n_hv == 3) r_max_hv = 4559.9;
00491     }
00492     
00493     if(station == 1 && ring == 3) {
00494       if(n_hv == 1) r_max_hv = 5724.1;
00495       if(n_hv == 2) r_max_hv = 6230.2;
00496       if(n_hv == 3) r_max_hv = 6761.5;
00497     }
00498     
00499     if(station == 2 && ring == 1) {
00500       if(n_hv == 1) r_max_hv = 2152.3;
00501       if(n_hv == 2) r_max_hv = 2763.7;
00502       if(n_hv == 3) r_max_hv = 3365.8;
00503     }
00504     
00505     if(station == 3 && ring == 1) {
00506       if(n_hv == 1) r_max_hv = 2164.9;
00507       if(n_hv == 2) r_max_hv = 2763.8;
00508       if(n_hv == 3) r_max_hv = 3365.8;
00509     }
00510     
00511     if(station == 4 && ring == 1) {
00512       if(n_hv == 1) r_max_hv = 2365.9;
00513       if(n_hv == 2) r_max_hv = 2865.0;
00514       if(n_hv == 3) r_max_hv = 3356.3;
00515     }
00516     
00517     if((station == 2 || station == 3 || station == 4) && ring == 2) {
00518       if(n_hv == 1) r_max_hv = 4446.3;
00519       if(n_hv == 2) r_max_hv = 5053.2;
00520       if(n_hv == 3) r_max_hv = 5660.1;
00521       if(n_hv == 4) r_max_hv = 6267.0;
00522       if(n_hv == 5) r_max_hv = 6870.8;
00523     }
00524     
00525     return r_max_hv;
00526   }
00527   
00536   const float Detector::PhiMinCFEB(const int station, const int ring, const int chamber, const int cfeb) const {
00537     float phi_min_cfeb;
00538     
00539     int n_cfeb = NumberOfChamberCFEBs(station, ring);
00540     int n_chambers = NumberOfChambers(station, ring);
00541     
00542     phi_min_cfeb = 0.0 + 2.0 * 3.14159 / ((float) (n_chambers)) * ((float) (chamber - 1) + (float) (cfeb - 1) / (float) (n_cfeb));
00543     
00544     return phi_min_cfeb;
00545   }
00546   
00555   const float Detector::PhiMaxCFEB(const int station, const int ring, const int chamber, const int cfeb) const {
00556     float phi_max_cfeb;
00557     
00558     int n_cfeb = NumberOfChamberCFEBs(station, ring);
00559     int n_chambers = NumberOfChambers(station, ring);
00560     
00561     phi_max_cfeb = 0.0 + 2.0 * 3.14159 / (float) n_chambers * ((float) (chamber - 1) + (float) (cfeb) / (float) n_cfeb);
00562     
00563     return phi_max_cfeb;
00564   }
00565   
00572   const bool Detector::AddressFromString(const std::string& str_address, Address& adr) const {
00573     
00574     std::vector<std::string> tokens;
00575     Utility::splitString(str_address, ",", tokens);
00576   
00577     if (tokens.size() != ADDR_SIZE) return false;
00578   
00579     for (unsigned int r = 0; r < ADDR_SIZE; r++) {
00580   
00581       std::string token = tokens.at(r);
00582       Utility::trimString(token);
00583       bool mask = false;
00584       unsigned int num  = 0;
00585   
00586       if (token.compare("*") != 0) {
00587         if(stringToNumber<unsigned int>(num, token, std::dec)) {
00588           mask = true;
00589         } else {
00590           return false;
00591         }
00592       }
00593   
00594       switch (r) {
00595         case 0:
00596           adr.mask.side = mask;
00597           adr.side = num;
00598           break;
00599         case 1:
00600           adr.mask.station = mask;
00601           adr.station = num;
00602           break;
00603         case 2:
00604           adr.mask.ring = mask;
00605           adr.ring = num;
00606           break;
00607         case 3:
00608           adr.mask.chamber = mask;
00609           adr.chamber = num;
00610           break;
00611         case 4:
00612           adr.mask.layer = mask;
00613           adr.layer = num;
00614           break;
00615         case 5:
00616           adr.mask.cfeb = mask;
00617           adr.cfeb = num;
00618           break;
00619         case 6:
00620           adr.mask.hv = mask;
00621           adr.hv = num;
00622       }
00623   
00624     } 
00625   
00626     return true;
00627   
00628   }
00629 
00630 }