CMS 3D CMS Logo

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 #include "DQM/CSCMonitorModule/interface/CSCDQM_Detector.h"
00020 
00021 namespace cscdqm {
00022 
00028 Detector::Detector(const unsigned int p_partitions_x, const unsigned int p_partitions_y) {
00029 
00030   partitions_x = p_partitions_x;
00031   partitions_y = p_partitions_y;
00032 
00033   unsigned int i = 0; 
00034   Address adr;
00035 
00036   adr.mask.layer = false;
00037   adr.mask.side = adr.mask.station = adr.mask.ring = adr.mask.chamber = adr.mask.cfeb = adr.mask.hv = true;
00038 
00039   // Creating real eta/phi boxes for available addresses
00040   for (adr.side = 1; adr.side <= N_SIDES; adr.side++) { 
00041     float sign = +1.0;
00042     if(adr.side == 2) sign = -1.0;
00043     for (adr.station = 1; adr.station <= N_STATIONS; adr.station++) {
00044       station_partitions[adr.station - 1].from[adr.side - 1] = i;
00045       for (adr.ring = 1; adr.ring <= NumberOfRings(adr.station); adr.ring++) { 
00046         for (adr.chamber = 1; adr.chamber <= NumberOfChambers(adr.station, adr.ring); adr.chamber++) {
00047           for (adr.cfeb = 1; adr.cfeb <= NumberOfChamberCFEBs(adr.station, adr.ring); adr.cfeb++) {
00048             for (adr.hv = 1; adr.hv <= NumberOfChamberHVs(adr.station, adr.ring); adr.hv++) {
00049 
00050               float z = Z(adr.station, adr.ring);
00051               float r_min = RMinHV(adr.station, adr.ring, adr.hv);
00052               float r_max = RMaxHV(adr.station, adr.ring, adr.hv);
00053               float eta_min = sign * Eta(r_min, z);
00054               float eta_max = sign * Eta(r_max, z);
00055               float x_min = EtaToX(eta_min);
00056               float x_max = EtaToX(eta_max);
00057               float phi_min = 0;
00058               float phi_max = 0;
00059 
00060               if(adr.station == 1 && adr.ring == 1 && adr.hv == 1) {
00061                 phi_min = PhiMinCFEB(adr.station, adr.ring, adr.chamber, 1);
00062                 phi_max = PhiMaxCFEB(adr.station, adr.ring, adr.chamber, NumberOfChamberCFEBs(adr.station, adr.ring));
00063               } else {
00064                 phi_min = PhiMinCFEB(adr.station, adr.ring, adr.chamber, adr.cfeb);
00065                 phi_max = PhiMaxCFEB(adr.station, adr.ring, adr.chamber, adr.cfeb);
00066               }
00067               float y_min = PhiToY(phi_min);
00068               float y_max = PhiToY(phi_max);
00069                 
00070               boxes[i].adr = adr;
00071 
00072               float xboxmin = (x_min < x_max ? x_min : x_max);
00073               float xboxmax = (x_max > x_min ? x_max : x_min);
00074               float yboxmin = (y_min < y_max ? y_min : y_max);
00075               float yboxmax = (y_max > y_min ? y_max : y_min);
00076 
00077               boxes[i].xmin = xboxmin;
00078               boxes[i].xmax = xboxmax;
00079               boxes[i].ymin = yboxmin;
00080               boxes[i].ymax = yboxmax;
00081 
00082               unsigned int x1 = int(floor(xboxmin / PARTITION_STEP_X)) + int(partitions_x / 2);
00083               unsigned int x2 = int( ceil(xboxmax / PARTITION_STEP_X)) + int(partitions_x / 2);
00084               unsigned int y1 = int(floor(yboxmin / PARTITION_STEP_Y));
00085               unsigned int y2 = int( ceil(yboxmax / PARTITION_STEP_Y));
00086 
00087               for (unsigned int x = x1; x < x2; x++) {
00088                 for (unsigned int y = y1; y < y2; y++) {
00089                   
00090                   unsigned int index = PARTITION_INDEX(x, y);
00091                   PartitionMapIterator iter = partitions.find(index);
00092                   if (iter == partitions.end()) {
00093                     std::vector<unsigned int> v;
00094                     partitions.insert(std::make_pair(index, v));
00095                   }
00096                   partitions[index].push_back(i);
00097 
00098                   //LOGINFO("Debug") << index << " = " << partitions[index]->size();
00099 
00100                 }
00101               }
00102 
00103               i++;
00104 
00105             }
00106           }
00107         }
00108       }
00109       station_partitions[adr.station - 1].to[adr.side - 1] = i - 1;
00110     }
00111 
00112   }
00113 
00114   // Cached the most frequently used areas
00115   adr.mask.side = adr.mask.ring = adr.mask.chamber = adr.mask.layer = adr.mask.cfeb = adr.mask.hv = false;
00116   adr.mask.station = true;
00117   adr.station = 1;
00118   station_area[0] = Area(adr);
00119   adr.station = 2;
00120   station_area[1] = Area(adr);
00121   adr.station = 3;
00122   station_area[2] = Area(adr);
00123   adr.station = 4;
00124   station_area[3] = Area(adr);
00125 
00126 }
00127 
00133 const float Detector::Area(const unsigned int station) const {
00134   if (station > 0 && station <= N_STATIONS) {
00135     return station_area[station - 1];
00136   }
00137   return 0;
00138 }
00139 
00145 const float Detector::Area(const Address& adr) const {
00146   float a = 0;
00147   for(unsigned int i = 0; i < N_ELEMENTS; i++ ) {
00148     if (boxes[i].adr == adr) {
00149       a += fabs((boxes[i].xmax - boxes[i].xmin) * (boxes[i].ymax - boxes[i].ymin));
00150     }
00151   }
00152   return a;
00153 }
00154 
00160 const unsigned int Detector::NumberOfRings(const unsigned int station) const {
00161   switch (station) {
00162     case 1:
00163       return 3;
00164     case 2:
00165       return 2;
00166     case 3:
00167       return 2;
00168     case 4:
00169       return 1;
00170   }
00171   return 0;
00172 }
00173 
00180 const unsigned int Detector::NumberOfChambers(const unsigned int station, const unsigned int ring) const {
00181   if(station == 1 && ring == 1) return 36;
00182   if(station == 1 && ring == 2) return 36;
00183   if(station == 1 && ring == 3) return 36;
00184   if(station == 2 && ring == 1) return 18;
00185   if(station == 2 && ring == 2) return 36;
00186   if(station == 3 && ring == 1) return 18;
00187   if(station == 3 && ring == 2) return 36;
00188   if(station == 4 && ring == 1) return 18;
00189   return 0;
00190 }
00191 
00198 const unsigned int Detector::NumberOfChamberCFEBs(const unsigned int station, const unsigned int ring) const {
00199   if(station == 1 && ring == 1) return 4;
00200   if(station == 1 && ring == 2) return 5;
00201   if(station == 1 && ring == 3) return 4;
00202   if(station == 2 && ring == 1) return 5;
00203   if(station == 2 && ring == 2) return 5;
00204   if(station == 3 && ring == 1) return 5;
00205   if(station == 3 && ring == 2) return 5;
00206   if(station == 4 && ring == 1) return 5;
00207   return 0;
00208 }
00209 
00216 const unsigned int Detector::NumberOfChamberHVs(const unsigned int station, const unsigned int ring) const {
00217   if(station == 1 && ring == 1) return 2;
00218   if(station == 1 && ring == 2) return 3;
00219   if(station == 1 && ring == 3) return 3;
00220   if(station == 2 && ring == 1) return 3;
00221   if(station == 2 && ring == 2) return 5;
00222   if(station == 3 && ring == 1) return 3;
00223   if(station == 3 && ring == 2) return 5;
00224   if(station == 4 && ring == 1) return 3;
00225   return 0;
00226 }
00227 
00233 void Detector::PrintAddress(const Address& adr) const {
00234 
00235   std::cout << "Side (" << std::boolalpha << adr.mask.side << ")"; 
00236   if (adr.mask.side) std::cout <<  " = " << adr.side;
00237 
00238   std::cout << ", Station (" << std::boolalpha << adr.mask.station << ")"; 
00239   if (adr.mask.station) std::cout << " = " << adr.station;
00240 
00241   std::cout << ", Ring (" << std::boolalpha << adr.mask.ring << ")"; 
00242   if (adr.mask.ring) std::cout << " = " << adr.ring;
00243 
00244   std::cout << ", Chamber (" << std::boolalpha << adr.mask.chamber << ")"; 
00245   if (adr.mask.chamber) std::cout << " = " << adr.chamber;
00246 
00247   std::cout << ", Layer (" << std::boolalpha << adr.mask.layer << ")"; 
00248   if (adr.mask.layer) std::cout << " = " << adr.layer;
00249 
00250   std::cout << ", CFEB (" << std::boolalpha << adr.mask.cfeb << ")"; 
00251   if (adr.mask.cfeb) std::cout << " = " << adr.cfeb;
00252 
00253   std::cout << ", HV (" << std::boolalpha << adr.mask.hv << ")"; 
00254   if (adr.mask.hv) std::cout << " = " << adr.hv;
00255 
00256   std::cout << std::endl;
00257 }
00258 
00259 const bool Detector::NextAddress(unsigned int& i, const Address*& adr, const Address& mask) const {
00260   for(; i < N_ELEMENTS; i++ ) {
00261     if (boxes[i].adr == mask) {
00262         adr = &boxes[i].adr;
00263         i++;
00264         return true; 
00265     }
00266   }
00267   return false;
00268 }
00269 
00270 const bool Detector::NextAddressBox(unsigned int& i, const AddressBox*& box, const Address& mask) const {
00271 
00272   /*
00273   if (mask.mask.station) {
00274     unsigned int side = 1;
00275     if (mask.mask.side) side = mask.side;
00276     if (i == 0) 
00277       i = station_partitions[mask.station - 1].from[side - 1];
00278     else {
00279       if (mask.mask.side) {
00280         if (i > station_partitions[mask.station - 1].to[side - 1])
00281           i = N_ELEMENTS;
00282       } else {
00283         if (i > station_partitions[mask.station - 1].to[0] && i < station_partitions[mask.station - 1].from[1])
00284           i = station_partitions[mask.station - 1].from[1];
00285         else
00286           if (i > station_partitions[mask.station - 1].to[1])
00287             i = N_ELEMENTS;
00288       }
00289     }    
00290   }
00291   */
00292 
00293   for(; i < N_ELEMENTS; i++ ) {
00294     if (boxes[i].adr == mask) {
00295         box = &boxes[i];
00296         i++;
00297         return true; 
00298       }
00299   }
00300   return false;
00301 }
00302 
00303 const bool Detector::NextAddressBoxByPartition (unsigned int& i, const unsigned int px, const unsigned int py, AddressBox*& box) {
00304 
00305 /*
00306 const bool Detector::NextAddressBoxByPartition (
00307     unsigned int& i,
00308     unsigned int& px,
00309     unsigned int& py,
00310     const AddressBox*& box,
00311     const Address& mask,
00312     const float xmin, const float xmax,
00313     const float ymin, const float ymax) {
00314 
00315   for(; i < N_ELEMENTS; i++ ) {
00316     if (boxes[i].adr == mask); else continue; 
00317     if ((xmin < boxes[i].xmin && xmax < boxes[i].xmin) || (xmin > boxes[i].xmax && xmax > boxes[i].xmax)) continue;
00318     if ((ymin < boxes[i].ymin && ymax < boxes[i].ymin) || (ymin > boxes[i].ymax && ymax > boxes[i].ymax)) continue;
00319     box = &boxes[i];
00320     i++;
00321     return true; 
00322   }
00323   return false;
00324   */
00325 
00326   unsigned int index = PARTITION_INDEX(px, py);
00327 
00328   PartitionMapIterator iter = partitions.find(index);
00329   if (iter != partitions.end()) {
00330     if (i < partitions[index].size()) {
00331       box = &boxes[partitions[index].at(i)];
00332       i++;
00333       return true; 
00334     }
00335   }
00336   return false;
00337 
00338 }
00339 
00340 const float Detector::Eta(const float r, const float z) const {
00341   if(r > 0.0 || z > 0.0) {
00342     float sin_theta, cos_theta;
00343     sin_theta = r/sqrt(r*r+z*z);
00344     cos_theta = z/sqrt(r*r+z*z);
00345     return  - log(sin_theta/(cos_theta + 1));
00346   }
00347   if(r == 0.0) return FLT_MAX;
00348   return 0.0;
00349 }
00350 
00351 
00352 // Transform eta coordinate to local canvas coordinate
00353 const float Detector::EtaToX(const float eta) const {
00354   float x_min   = -2.5;
00355   float x_max   =  2.5;
00356   float eta_min = -2.5;
00357   float eta_max =  2.5;
00358   float a = (x_max - x_min) / (eta_max - eta_min);
00359   float b = (eta_max * x_min - eta_min * x_max) / (eta_max - eta_min);
00360   return a * eta + b;
00361 }
00362 
00363 // Transform phi coordinate to local canvas coordinate
00364 const float Detector::PhiToY(const float phi) const {
00365   float y_min   = 0.0;
00366   float y_max   = 2.0 * 3.14159;
00367   float phi_min = 0.0;
00368   float phi_max = 2.0 * 3.14159;
00369   float a = (y_max - y_min) / (phi_max - phi_min);
00370   float b = (phi_max * y_min - phi_min * y_max) / (phi_max - phi_min);
00371   return a * phi + b;
00372 }
00373 
00374 const float Detector::Z(const int station, const int ring) const {
00375   float z_csc = 0;
00376   
00377   if(station == 1 && ring == 1) z_csc = (5834.5 + 6101.5) / 2.0;
00378   if(station == 1 && ring == 2) z_csc = (6790.0 + 7064.3) / 2.0;
00379   if(station == 1 && ring == 3) z_csc = 6888.0;
00380   if(station == 2) z_csc = (8098.0 + 8346.0) / 2.0;
00381   if(station == 3) z_csc = (9414.8 + 9166.8) / 2.0;
00382   if(station == 4) z_csc = 10630.0; // has to be corrected
00383   
00384   return z_csc;
00385 }
00386 
00387 const float Detector::RMinHV(const int station, const int ring, const int n_hv) const {
00388   float r_min_hv = 0;
00389   
00390   if(station == 1 && ring == 1) {
00391     if(n_hv == 1) r_min_hv = 1060.0;
00392     if(n_hv == 2) r_min_hv = 1500.0;
00393   }
00394   
00395   if(station == 1 && ring == 2) {
00396     if(n_hv == 1) r_min_hv = 2815.0;
00397     if(n_hv == 2) r_min_hv = 3368.2;
00398     if(n_hv == 3) r_min_hv = 4025.7;
00399   }
00400   
00401   if(station == 1 && ring == 3) {
00402     if(n_hv == 1) r_min_hv = 5120.0;
00403     if(n_hv == 2) r_min_hv = 5724.1;
00404     if(n_hv == 3) r_min_hv = 6230.2;
00405   }
00406   
00407   if(station == 2 && ring == 1) {
00408     if(n_hv == 1) r_min_hv = 1469.2;
00409     if(n_hv == 2) r_min_hv = 2152.3;
00410     if(n_hv == 3) r_min_hv = 2763.7;
00411   }
00412   
00413   if(station == 3 && ring == 1) {
00414     if(n_hv == 1) r_min_hv = 1668.9;
00415     if(n_hv == 2) r_min_hv = 2164.9;
00416     if(n_hv == 3) r_min_hv = 2763.8;
00417   }
00418   
00419   if(station == 4 && ring == 1) {
00420     if(n_hv == 1) r_min_hv = 1876.1;
00421     if(n_hv == 2) r_min_hv = 2365.9;
00422     if(n_hv == 3) r_min_hv = 2865.0;
00423   }
00424   
00425   if((station == 2 || station == 3 || station == 4) && ring == 2) {
00426     if(n_hv == 1) r_min_hv = 3640.2;
00427     if(n_hv == 2) r_min_hv = 4446.3;
00428     if(n_hv == 3) r_min_hv = 5053.2;
00429     if(n_hv == 4) r_min_hv = 5660.1;
00430     if(n_hv == 5) r_min_hv = 6267.0;
00431   }
00432   
00433   return r_min_hv;
00434 }
00435 
00436 const float Detector::RMaxHV(const int station, const int ring, const int n_hv) const {
00437   float r_max_hv = 0;
00438   
00439   if(station == 1 && ring == 1) {
00440     if(n_hv == 1) r_max_hv = 1500.0;
00441     if(n_hv == 2) r_max_hv = 2565.0;
00442   }
00443   
00444   if(station == 1 && ring == 2) {
00445     if(n_hv == 1) r_max_hv = 3368.2;
00446     if(n_hv == 2) r_max_hv = 4025.7;
00447     if(n_hv == 3) r_max_hv = 4559.9;
00448   }
00449   
00450   if(station == 1 && ring == 3) {
00451     if(n_hv == 1) r_max_hv = 5724.1;
00452     if(n_hv == 2) r_max_hv = 6230.2;
00453     if(n_hv == 3) r_max_hv = 6761.5;
00454   }
00455   
00456   if(station == 2 && ring == 1) {
00457     if(n_hv == 1) r_max_hv = 2152.3;
00458     if(n_hv == 2) r_max_hv = 2763.7;
00459     if(n_hv == 3) r_max_hv = 3365.8;
00460   }
00461   
00462   if(station == 3 && ring == 1) {
00463     if(n_hv == 1) r_max_hv = 2164.9;
00464     if(n_hv == 2) r_max_hv = 2763.8;
00465     if(n_hv == 3) r_max_hv = 3365.8;
00466   }
00467   
00468   if(station == 4 && ring == 1) {
00469     if(n_hv == 1) r_max_hv = 2365.9;
00470     if(n_hv == 2) r_max_hv = 2865.0;
00471     if(n_hv == 3) r_max_hv = 3356.3;
00472   }
00473   
00474   if((station == 2 || station == 3 || station == 4) && ring == 2) {
00475     if(n_hv == 1) r_max_hv = 4446.3;
00476     if(n_hv == 2) r_max_hv = 5053.2;
00477     if(n_hv == 3) r_max_hv = 5660.1;
00478     if(n_hv == 4) r_max_hv = 6267.0;
00479     if(n_hv == 5) r_max_hv = 6870.8;
00480   }
00481   
00482   return r_max_hv;
00483 }
00484 
00485 const float Detector::PhiMinCFEB(const int station, const int ring, const int chamber, const int cfeb) const {
00486   float phi_min_cfeb;
00487   
00488   int n_cfeb = NumberOfChamberCFEBs(station, ring);
00489   int n_chambers = NumberOfChambers(station, ring);
00490   
00491   phi_min_cfeb = 0.0 + 2.0 * 3.14159 / ((float) (n_chambers)) * ((float) (chamber - 1) + (float) (cfeb - 1) / (float) (n_cfeb));
00492   
00493   return phi_min_cfeb;
00494 }
00495 
00496 const float Detector::PhiMaxCFEB(const int station, const int ring, const int chamber, const int cfeb) const {
00497   float phi_max_cfeb;
00498   
00499   int n_cfeb = NumberOfChamberCFEBs(station, ring);
00500   int n_chambers = NumberOfChambers(station, ring);
00501   
00502   phi_max_cfeb = 0.0 + 2.0 * 3.14159 / (float) n_chambers * ((float) (chamber - 1) + (float) (cfeb) / (float) n_cfeb);
00503   
00504   return phi_max_cfeb;
00505 }
00506 
00512 const std::string Detector::AddressName(const Address& adr) const {
00513   std::ostringstream oss;
00514   oss << "CSC";
00515   if (adr.mask.side) {
00516     oss << "_Side" << (adr.side == 1 ? "Plus" : "Minus");
00517     if (adr.mask.station) {
00518       oss << "_Station" << std::setfill('0') << std::setw(2) << adr.station;
00519       if (adr.mask.ring) {
00520         oss << "_Ring" << std::setfill('0') << std::setw(2) << adr.ring;
00521         if (adr.mask.chamber) {
00522           oss << "_Chamber" << std::setfill('0') << std::setw(2) << adr.chamber;
00523           if (adr.mask.layer) {
00524             oss << "_Layer" << std::setfill('0') << std::setw(2) << adr.layer;
00525             if (adr.mask.cfeb) {
00526               oss << "_CFEB" << std::setfill('0') << std::setw(2) << adr.cfeb;
00527               if (adr.mask.hv) {
00528                 oss << "_HV" << std::setfill('0') << std::setw(2) << adr.hv;
00529               }
00530             }
00531           }
00532         }
00533       }
00534     }
00535   }
00536   return oss.str();
00537 }
00538 
00539 const bool Detector::AddressFromString(const std::string str_address, Address& adr) const {
00540   
00541   std::vector<std::string> tokens;
00542   Utility::splitString(str_address, ",", tokens);
00543 
00544   if (tokens.size() != ADDR_SIZE) return false;
00545 
00546   for (unsigned int r = 0; r < ADDR_SIZE; r++) {
00547 
00548     std::string token = tokens.at(r);
00549     Utility::trimString(token);
00550     bool mask = false;
00551     unsigned int num  = 0;
00552 
00553     if (token.compare("*") != 0) {
00554       if(stringToNumber<unsigned int>(num, token, std::dec)) {
00555         mask = true;
00556       } else {
00557         return false;
00558       }
00559     }
00560 
00561     switch (r) {
00562       case 0:
00563         adr.mask.side = mask;
00564         adr.side = num;
00565         break;
00566       case 1:
00567         adr.mask.station = mask;
00568         adr.station = num;
00569         break;
00570       case 2:
00571         adr.mask.ring = mask;
00572         adr.ring = num;
00573         break;
00574       case 3:
00575         adr.mask.chamber = mask;
00576         adr.chamber = num;
00577         break;
00578       case 4:
00579         adr.mask.layer = mask;
00580         adr.layer = num;
00581         break;
00582       case 5:
00583         adr.mask.cfeb = mask;
00584         adr.cfeb = num;
00585         break;
00586       case 6:
00587         adr.mask.hv = mask;
00588         adr.hv = num;
00589     }
00590 
00591   } 
00592 
00593   return true;
00594 
00595 }
00596 
00597 }

Generated on Tue Jun 9 17:32:33 2009 for CMSSW by  doxygen 1.5.4