CMS 3D CMS Logo

CSCDQM_Summary.cc

Go to the documentation of this file.
00001 /*
00002  * =====================================================================================
00003  *
00004  *       Filename:  Summary.cc
00005  *
00006  *    Description:  Class Summary 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_Summary.h"
00020 
00021 namespace cscdqm {
00022 
00028 Summary::Summary() : detector(NTICS, NTICS) {
00029   Reset();
00030 }
00031 
00037 Summary::~Summary() {
00038   // Lets delete masked elements
00039   for (unsigned int r = 0; r < masked.size(); r++) { 
00040     delete (Address*) masked.at(r);
00041   }
00042 }
00043 
00048 void Summary::Reset() {
00049   Address adr;
00050 
00051   // Setting Zeros (no data) for each HW element (and beyond)
00052   adr.mask.side = adr.mask.station = adr.mask.layer = false;
00053   adr.mask.ring = adr.mask.chamber = adr.mask.cfeb = adr.mask.hv = true;
00054   for (adr.ring = 1; adr.ring <= N_RINGS; adr.ring++) { 
00055     for (adr.chamber = 1; adr.chamber <= N_CHAMBERS; adr.chamber++) {
00056        for (adr.cfeb = 1; adr.cfeb <= N_CFEBS; adr.cfeb++) {
00057           for (adr.hv = 1; adr.hv <= N_HVS; adr.hv++) {
00058             for (unsigned int bit = 0; bit < HWSTATUSBITSETSIZE; bit++) { 
00059               ReSetValue(adr, (HWStatusBit) bit);
00060             }
00061           }
00062        }
00063     }
00064   }
00065 }
00066 
00072 void Summary::ReadReportingChambers(const TH2*& h2, const double threshold) {
00073 
00074   if(h2->GetXaxis()->GetXmin() <= 1 && h2->GetXaxis()->GetXmax() >= 36 &&
00075      h2->GetYaxis()->GetXmin() <= 1 && h2->GetYaxis()->GetXmax() >= 18) {
00076 
00077     Address adr;
00078     double z = 0.0;
00079 
00080     for(unsigned int x = 1; x <= 36; x++) {
00081       for(unsigned int y = 1; y <= 18; y++) {
00082         z = h2->GetBinContent(x, y);
00083         if(ChamberCoordsToAddress(x, y, adr)) {
00084           if(z >= threshold) {
00085             SetValue(adr, DATA);
00086           } else {
00087             ReSetValue(adr, DATA);
00088           }
00089         }
00090       }
00091     }
00092   } else {
00093     LOG_WARN << "cscdqm::Summary.ReadReportingChambers routine. Wrong histogram dimensions!";
00094   }
00095 }
00096 
00106 void Summary::ReadReportingChambersRef(const TH2*& h2, const TH2*& refh2, const double cold_coef, const double cold_Sfail, const double hot_coef, const double hot_Sfail) {
00107 
00108   if(h2->GetXaxis()->GetXmin() <= 1 && h2->GetXaxis()->GetXmax() >= 36 &&
00109      h2->GetYaxis()->GetXmin() <= 1 && h2->GetYaxis()->GetXmax() >= 18 &&
00110      refh2->GetXaxis()->GetXmin() <= 1 && refh2->GetXaxis()->GetXmax() >= 36 &&
00111      refh2->GetYaxis()->GetXmin() <= 1 && refh2->GetYaxis()->GetXmax() >= 18) {
00112 
00113     // Rate Factor calculation
00114     double num = 1.0, denum = 1.0;
00115     for(unsigned int x = 1; x <= 36; x++) {
00116       for(unsigned int y = 1; y <= 18; y++) {
00117         double Nij = h2->GetBinContent(x, y);
00118         double Nrefij = refh2->GetBinContent(x, y);
00119         if (Nij > 0) {
00120           num += Nrefij;
00121           denum += pow(Nrefij, 2.0) / Nij;
00122         }
00123       }
00124     }
00125     double factor = num / denum, eps_meas = 0.0;
00126 
00127     Address adr;
00128     unsigned int N = 0, n = 0;
00129 
00130     for(unsigned int x = 1; x <= 36; x++) {
00131       for(unsigned int y = 1; y <= 18; y++) {
00132         
00133         N = int(refh2->GetBinContent(x, y) * factor);
00134         n = int(h2->GetBinContent(x, y));
00135 
00136         if(ChamberCoordsToAddress(x, y, adr)) {
00137           
00138           // Reset some bits
00139           ReSetValue(adr, HOT);
00140           ReSetValue(adr, COLD);
00141 
00142           /*
00143           std::cout << "adr = " << detector.AddressName(adr);
00144           std::cout << ", x = " << x << ", y = " << y;
00145           std::cout << ", value = " << GetValue(adr);
00146           std::cout << ", refh2 = " << refh2->GetBinContent(x, y);
00147           std::cout << ", factor = " << factor;
00148           std::cout << ", N = " << N;
00149           std::cout << ", n = " << n;
00150           std::cout << ", num = " << num;
00151           std::cout << ", denum = " << denum;
00152           std::cout << "\n";
00153           */
00154 
00155           if (n == 0) {
00156             ReSetValue(adr, DATA);
00157           } else {
00158             SetValue(adr, DATA);
00159           }
00160 
00161           if (N > 0) {
00162 
00163             eps_meas = (1.0 * n) / (1.0 * N);
00164             double S = 0;
00165 
00166             // Chamber is cold? It means error!
00167             if (eps_meas < cold_coef) {
00168 
00169               S = SignificanceLevel(N, n, cold_coef);
00170 
00171               if (S > cold_Sfail) {
00172 
00173                 /*
00174                 std::cout << "!COLD!";
00175                 std::cout << "adr = " << detector.AddressName(adr);
00176                 std::cout << ", n = " << n << ", N = " << N;
00177                 std::cout << ", eps_meas = " << eps_meas;
00178                 std::cout << ", cold_coef = " << cold_coef;
00179                 std::cout << ", cold_Sfail = " << cold_Sfail;
00180                 std::cout << ", S = " << S;
00181                 std::cout << "\n";
00182                 */
00183 
00184                 SetValue(adr, COLD);
00185               }
00186             } else {
00187             
00188               // Chamber is hot? It means error!
00189               if (eps_meas > hot_coef) {
00190 
00191                 S = SignificanceLevelHot(N, n);
00192 
00193                 if (S > hot_Sfail) {
00194 
00195                   /*
00196                   std::cout << "!HOT!";
00197                   std::cout << "adr = " << detector.AddressName(adr);
00198                   std::cout << ", n = " << n << ", N = " << N;
00199                   std::cout << ", eps_meas = " << eps_meas;
00200                   std::cout << ", hot_coef = " << hot_coef;
00201                   std::cout << ", hot_Sfail = " << hot_Sfail;
00202                   std::cout << ", S = " << S;
00203                   std::cout << "\n";
00204                   */
00205 
00206                   SetValue(adr, HOT);
00207                 }
00208               }
00209             }
00210 
00211 
00212           }
00213 
00214         }
00215 
00216       }
00217     }
00218 
00219   } else {
00220     LOG_WARN << "cscdqm::Summary.ReadReportingChambersRef routine. Wrong histogram dimensions!";
00221   }
00222 }
00223 
00233 void Summary::ReadErrorChambers(const TH2*& evs, const TH2*& err, const HWStatusBit bit, const double eps_max, const double Sfail) {
00234 
00235   if(evs->GetXaxis()->GetXmin() <= 1 && evs->GetXaxis()->GetXmax() >= 36 &&
00236      evs->GetYaxis()->GetXmin() <= 1 && evs->GetYaxis()->GetXmax() >= 18 &&
00237      err->GetXaxis()->GetXmin() <= 1 && err->GetXaxis()->GetXmax() >= 36 &&
00238      err->GetYaxis()->GetXmin() <= 1 && err->GetYaxis()->GetXmax() >= 18) {
00239 
00240     Address adr;
00241     unsigned int N = 0, n = 0; 
00242 
00243     for(unsigned int x = 1; x <= 36; x++) {
00244       for(unsigned int y = 1; y <= 18; y++) {
00245         N = int(evs->GetBinContent(x, y));
00246         n = int(err->GetBinContent(x, y));
00247         if (ChamberCoordsToAddress(x, y, adr)) {
00248           double eps_meas = (1.0 * n) / (1.0 * N);
00249           if (eps_meas > eps_max) { 
00250             if(SignificanceLevel(N, n, eps_max) > Sfail) { 
00251               SetValue(adr, bit);
00252             } else {
00253               ReSetValue(adr, bit);
00254             }
00255           }
00256         }
00257       }
00258     }
00259   } else {
00260     LOG_WARN << "cscdqm::Summary.ReadErrorChambers routine. Wrong histogram dimensions!";
00261   }
00262 }
00263 
00270 void Summary::Write(TH2*& h2, const unsigned int station) const {
00271   const AddressBox* box;
00272   Address adr, tadr;
00273   float area_all = 0.0, area_rep = 0.0;
00274 
00275   if(station < 1 || station > N_STATIONS) return; 
00276 
00277   adr.mask.side = adr.mask.ring = adr.mask.chamber = adr.mask.layer = adr.mask.cfeb = adr.mask.hv = false;
00278   adr.mask.station = true;
00279   adr.station = station;
00280 
00281   unsigned int i = 0;
00282 
00283   while (detector.NextAddressBox(i, box, adr)) { 
00284 
00285     unsigned int x = 1 + (box->adr.side - 1) * 9 + (box->adr.ring - 1) * 3 + (box->adr.hv - 1);
00286     unsigned int y = 1 + (box->adr.chamber - 1) * 5 + (box->adr.cfeb - 1);
00287 
00288     tadr = box->adr;
00289     HWStatusBitSet status = GetValue(tadr);
00290 
00291     float area_box = fabs((box->xmax - box->xmin) * (box->ymax - box->ymin));
00292     area_all += area_box;
00293 
00294     if (HWSTATUSANYERROR(status)) {
00295       h2->SetBinContent(x, y, -1.0);
00296     } else {
00297       area_rep += area_box;
00298       if (status.test(DATA)) {
00299         h2->SetBinContent(x, y, 1.0);
00300       } else {
00301         h2->SetBinContent(x, y, 0.0);
00302       }
00303     }
00304 
00305   }
00306 
00307   TString title = Form("ME%d Status: Physics Efficiency %.2f%%", station, (area_rep / area_all) * 100.0);
00308   h2->SetTitle(title);
00309 
00310 }
00311 
00317 void Summary::WriteMap(TH2*& h2) {
00318 
00319   unsigned int rep_el = 0, csc_el = 0;
00320 
00321   if(h2->GetXaxis()->GetXmin() <= 1 && h2->GetXaxis()->GetXmax() >= NTICS &&
00322      h2->GetYaxis()->GetXmin() <= 1 && h2->GetYaxis()->GetXmax() >= NTICS) {
00323 
00324     float xd = 5.0 / NTICS, yd = 1.0 * (2.0 * 3.14159) / NTICS;
00325 
00326     float xmin, xmax, ymin, ymax;
00327 
00328     for(unsigned int x = 0; x < NTICS; x++) {
00329 
00330       xmin = -2.5 + xd * x;
00331       xmax = xmin + xd;
00332 
00333       for(unsigned int y = 0; y < NTICS; y++) {
00334 
00335         double value = 0.0; 
00336 
00337         if (xmin == -2.5 || xmax == 2.5) continue;
00338         if (xmin >= -1 && xmax <= 1)     continue;
00339 
00340         ymin = yd * y;
00341         ymax = ymin + yd;
00342 
00343         switch(IsPhysicsReady(x, y)) {
00344           case -1:
00345             value = -1.0;
00346             break;
00347           case 0:
00348             value = 0.0;
00349             rep_el++;
00350             break;
00351           case 1:
00352             value = 1.0;
00353             rep_el++;
00354             break;
00355           case 2:
00356             value = 2.0;
00357             rep_el++;
00358         }
00359 
00360         h2->SetBinContent(x + 1, y + 1, value);
00361         csc_el++;
00362 
00363       }
00364     }
00365 
00366   } else {
00367     LOG_WARN << "cscdqm::Summary.WriteMap routine. Wrong histogram dimensions!";
00368   }
00369 
00370   TString title = Form("EMU Status: Physics Efficiency %.2f%%", (csc_el == 0 ? 0.0 : (1.0 * rep_el) / csc_el) * 100.0);
00371   h2->SetTitle(title);
00372 
00373 }
00374 
00375 
00384 void Summary::WriteChamberState(TH2*& h2, const int mask, const int value, const bool reset, const bool op_any) const {
00385 
00386   if(h2->GetXaxis()->GetXmin() <= 1 && h2->GetXaxis()->GetXmax() >= 36 &&
00387      h2->GetYaxis()->GetXmin() <= 1 && h2->GetYaxis()->GetXmax() >= 18) {
00388 
00389     unsigned int x, y;
00390     Address adr;
00391 
00392     adr.mask.side = adr.mask.station = adr.mask.ring = adr.mask.chamber = true;
00393     adr.mask.layer = adr.mask.cfeb = adr.mask.hv = false;
00394 
00395     for (adr.side = 1; adr.side <= N_SIDES; adr.side++) {
00396       for (adr.station = 1; adr.station <= N_STATIONS; adr.station++) {
00397         for (adr.ring = 1; adr.ring <= detector.NumberOfRings(adr.station); adr.ring++) {
00398           for (adr.chamber = 1; adr.chamber <= detector.NumberOfChambers(adr.station, adr.ring); adr.chamber++) {
00399             if (ChamberAddressToCoords(adr, x, y)) {
00400               bool hit = (op_any ? HWSTATUSANY(GetValue(adr), mask) : HWSTATUSEQUALS(GetValue(adr), mask));
00401               if (hit) {
00402                 h2->SetBinContent(x, y, 1.0 * value);
00403               } else if (reset) {
00404                 h2->SetBinContent(x, y, 0.0);
00405               }
00406             }
00407           }
00408         }
00409       }
00410     }
00411 
00412   } else {
00413     LOG_WARN << "cscdqm::Summary.WriteChamberState routine. Wrong histogram dimensions!";
00414   }
00415 
00416 }
00417 
00423 void Summary::ReSetValue(const HWStatusBit bit) {
00424   SetValue(bit, 0);
00425 }
00426 
00433 void Summary::ReSetValue(Address adr, const HWStatusBit bit) {
00434   SetValue(adr, bit, 0);
00435 }
00436 
00443 void Summary::SetValue(const HWStatusBit bit, const int value) {
00444   Address adr;
00445   adr.mask.side = adr.mask.station = adr.mask.ring = adr.mask.chamber = adr.mask.layer = adr.mask.cfeb = adr.mask.hv = false;
00446   SetValue(adr, bit, value);
00447 }
00448 
00456 void Summary::SetValue(Address adr, const HWStatusBit bit, const int value) {
00457 
00458   if (!adr.mask.side) {
00459     adr.mask.side = true;
00460     for (adr.side = 1; adr.side <= N_SIDES; adr.side++) SetValue(adr, bit, value);
00461     return;
00462   }
00463 
00464   if (!adr.mask.station) {
00465     adr.mask.station = true;
00466     for (adr.station = 1; adr.station <= N_STATIONS; adr.station++) SetValue(adr, bit, value);
00467     return;
00468   }
00469 
00470   if (!adr.mask.ring) {
00471     adr.mask.ring = true;
00472     for (adr.ring = 1; adr.ring <= detector.NumberOfRings(adr.station); adr.ring++) SetValue(adr, bit, value);
00473     return;
00474   }
00475 
00476   if (!adr.mask.chamber) {
00477     adr.mask.chamber = true;
00478     for (adr.chamber = 1; adr.chamber <= detector.NumberOfChambers(adr.station, adr.ring); adr.chamber++) SetValue(adr, bit, value);
00479     return;
00480   }
00481 
00482   if (!adr.mask.layer) {
00483     adr.mask.layer = true;
00484     for (adr.layer = 1; adr.layer <= N_LAYERS; adr.layer++) SetValue(adr, bit, value);
00485     return;
00486   }
00487 
00488   if (!adr.mask.cfeb) {
00489     adr.mask.cfeb = true;
00490     for (adr.cfeb = 1; adr.cfeb <= detector.NumberOfChamberCFEBs(adr.station, adr.ring); adr.cfeb++) SetValue(adr, bit, value);
00491     return;
00492   }
00493 
00494   if (!adr.mask.hv) {
00495     adr.mask.hv = true;
00496     for (adr.hv = 1; adr.hv <= detector.NumberOfChamberHVs(adr.station, adr.ring); adr.hv++) SetValue(adr, bit, value);
00497     return;
00498   }
00499 
00500   if( adr.side > 0 && adr.side <= N_SIDES && adr.station > 0 && adr.station <= N_STATIONS && 
00501       adr.ring > 0 && adr.ring <= N_RINGS && adr.chamber > 0 && adr.chamber <= N_CHAMBERS && 
00502       adr.layer > 0 && adr.layer <= N_LAYERS && adr.cfeb > 0 && adr.cfeb <= N_CFEBS && adr.hv > 0 && adr.hv <= N_HVS) {
00503 
00504     map[adr.side - 1][adr.station - 1][adr.ring - 1][adr.chamber - 1][adr.layer - 1][adr.cfeb - 1][adr.hv - 1].set(bit, value);
00505 
00506   }
00507 
00508 }
00509 
00520 const int Summary::IsPhysicsReady(const unsigned int px, const unsigned int py) {
00521 
00522   AddressBox *box;
00523 
00524   HWStatusBitSet status[N_STATIONS];
00525 
00526   unsigned int i = 0;
00527   while(detector.NextAddressBoxByPartition(i, px, py, box)) {
00528     status[box->adr.station - 1] |= GetValue(box->adr);
00529   }
00530 
00531   unsigned int cdata = 0, cerror = 0, cmask = 0;
00532   for (unsigned int i = 0; i < N_STATIONS; i++) {
00533     if (HWSTATUSANYERROR(status[i])) {
00534       cerror++;
00535     } else {
00536       if (status[i].test(MASKED)) cmask++;
00537       if (status[i].test(DATA)) cdata++;
00538     }
00539   }
00540 
00541   // If at least 2 stations with data and without errors = OK
00542   if (cdata > 1)  return 1;
00543   // Else, if at least one station errorous = ERROR
00544   if (cerror > 0) return -1;
00545   // Else, if at least one station masked = MASKED
00546   if (cmask > 0)  return 2;
00547   // Else, not sufficient data = OK
00548   return 0;
00549 
00550 }
00551 
00557 const double Summary::GetEfficiencyHW() const {
00558 
00559   Address adr;
00560   adr.mask.side = adr.mask.station = adr.mask.ring = adr.mask.chamber = adr.mask.layer = adr.mask.cfeb = adr.mask.hv = false;
00561   return GetEfficiencyHW(adr);
00562 
00563 }
00564 
00570 const double Summary::GetEfficiencyHW(const unsigned int station) const {
00571 
00572   Address adr;
00573   adr.mask.side = adr.mask.station = adr.mask.ring = adr.mask.chamber = adr.mask.layer = adr.mask.cfeb = adr.mask.hv = false;
00574 
00575   if (station > 0 && station <= N_STATIONS) {
00576     adr.mask.station = true;
00577     adr.station = station;
00578   } else {
00579     return 0.0;
00580   }
00581 
00582   return GetEfficiencyHW(adr);
00583 
00584 }
00585 
00591 const double Summary::GetEfficiencyHW(Address adr) const { 
00592   double sum = 0.0;
00593 
00594   if (!adr.mask.side) {
00595     adr.mask.side = true;
00596     for (adr.side = 1; adr.side <= N_SIDES; adr.side++) sum += GetEfficiencyHW(adr);
00597     return sum / N_SIDES;
00598   }
00599 
00600   if (!adr.mask.station) {
00601     adr.mask.station = true;
00602     for (adr.station = 1; adr.station <= N_STATIONS; adr.station++) sum += GetEfficiencyHW(adr);
00603     return sum / N_STATIONS;
00604   } 
00605 
00606   if (!adr.mask.ring) {
00607     adr.mask.ring = true;
00608     for (adr.ring = 1; adr.ring <= detector.NumberOfRings(adr.station); adr.ring++) sum += GetEfficiencyHW(adr);
00609     return sum / detector.NumberOfRings(adr.station);
00610   }
00611 
00612   if (!adr.mask.chamber) {
00613     adr.mask.chamber = true;
00614     for (adr.chamber = 1; adr.chamber <= detector.NumberOfChambers(adr.station, adr.ring); adr.chamber++) sum += GetEfficiencyHW(adr);
00615     return sum / detector.NumberOfChambers(adr.station, adr.ring);
00616   }
00617 
00618   if (!adr.mask.layer) {
00619     adr.mask.layer = true;
00620     for (adr.layer = 1; adr.layer <= N_LAYERS; adr.layer++) sum += GetEfficiencyHW(adr);
00621     return sum / N_LAYERS;
00622   }
00623 
00624   if (!adr.mask.cfeb) {
00625     adr.mask.cfeb = true;
00626     for (adr.cfeb = 1; adr.cfeb <= detector.NumberOfChamberCFEBs(adr.station, adr.ring); adr.cfeb++) sum += GetEfficiencyHW(adr);
00627     return sum / detector.NumberOfChamberCFEBs(adr.station, adr.ring);
00628   }
00629 
00630   if (!adr.mask.hv) {
00631     adr.mask.hv = true;
00632     for (adr.hv = 1; adr.hv <= detector.NumberOfChamberHVs(adr.station, adr.ring); adr.hv++) sum += GetEfficiencyHW(adr);
00633     return sum / detector.NumberOfChamberHVs(adr.station, adr.ring);
00634   }
00635 
00636   // if not error - then OK!
00637   HWStatusBitSet status = GetValue(adr); 
00638   if (HWSTATUSANYERROR(status)) return 0.0;
00639   return 1.0;
00640 
00641 }
00642 
00648 const double Summary::GetEfficiencyArea(const unsigned int station) const {
00649   if (station <= 0 || station > N_STATIONS) return 0.0;
00650 
00651   Address adr;
00652   adr.mask.side = adr.mask.ring = adr.mask.chamber = adr.mask.layer = adr.mask.cfeb = adr.mask.hv = false;
00653   adr.station   = true;
00654   adr.station   = station;
00655 
00656   return GetEfficiencyArea(adr);
00657 }
00658 
00664 const double Summary::GetEfficiencyArea(Address adr) const {
00665   double all_area = 1;
00666 
00667   if(adr.mask.side == adr.mask.ring == adr.mask.chamber == adr.mask.layer == adr.mask.cfeb == adr.mask.hv == false && adr.mask.station == true)
00668     all_area = detector.Area(adr.station);
00669   else
00670     all_area = detector.Area(adr);
00671 
00672   double rep_area = GetReportingArea(adr);
00673   return rep_area / all_area;
00674 }
00675 
00681 const double Summary::GetReportingArea(Address adr) const { 
00682   double sum = 0.0;
00683 
00684   if (!adr.mask.side) {
00685     adr.mask.side = true;
00686     for (adr.side = 1; adr.side <= N_SIDES; adr.side++) sum += GetReportingArea(adr);
00687     return sum;
00688   }
00689 
00690   if (!adr.mask.station) {
00691     adr.mask.station = true;
00692     for (adr.station = 1; adr.station <= N_STATIONS; adr.station++) sum += GetReportingArea(adr);
00693     return sum;
00694   } 
00695 
00696   if (!adr.mask.ring) {
00697     adr.mask.ring = true;
00698     for (adr.ring = 1; adr.ring <= detector.NumberOfRings(adr.station); adr.ring++) sum += GetReportingArea(adr);
00699     return sum;
00700   }
00701 
00702   if (!adr.mask.chamber) {
00703     adr.mask.chamber = true;
00704     for (adr.chamber = 1; adr.chamber <= detector.NumberOfChambers(adr.station, adr.ring); adr.chamber++) sum += GetReportingArea(adr);
00705     return sum;
00706   }
00707 
00708   if (!adr.mask.cfeb) {
00709     adr.mask.cfeb = true;
00710     for (adr.cfeb = 1; adr.cfeb <= detector.NumberOfChamberCFEBs(adr.station, adr.ring); adr.cfeb++) sum += GetReportingArea(adr);
00711     return sum;
00712   }
00713 
00714   if (!adr.mask.hv) {
00715     adr.mask.hv = true;
00716     for (adr.hv = 1; adr.hv <= detector.NumberOfChamberHVs(adr.station, adr.ring); adr.hv++) sum += GetReportingArea(adr);
00717     return sum;
00718   }
00719 
00720   adr.mask.layer = false;
00721    
00722   // NOT errorous! 
00723   HWStatusBitSet status = GetValue(adr);
00724   if (!HWSTATUSANYERROR(status)) {
00725     return detector.Area(adr);
00726   }
00727   return 0.0;
00728 
00729 }
00735 const HWStatusBitSet Summary::GetValue(Address adr) const {
00736 
00737   HWStatusBitSet state;
00738   state.reset();
00739 
00740   if (!adr.mask.side) {
00741     adr.mask.side = true;
00742     for (adr.side = 1; adr.side <= N_SIDES; adr.side++) state |= GetValue(adr);
00743     return state;
00744   }
00745 
00746   if (!adr.mask.station) {
00747     adr.mask.station = true;
00748     for (adr.station = 1; adr.station <= N_STATIONS; adr.station++) state |= GetValue(adr);
00749     return state;
00750   } 
00751 
00752   if (!adr.mask.ring) {
00753     adr.mask.ring = true;
00754     for (adr.ring = 1; adr.ring <= detector.NumberOfRings(adr.station); adr.ring++) state |= GetValue(adr);
00755     return state;
00756   }
00757 
00758   if (!adr.mask.chamber) {
00759     adr.mask.chamber = true;
00760     for (adr.chamber = 1; adr.chamber <= detector.NumberOfChambers(adr.station, adr.ring); adr.chamber++) state |= GetValue(adr);
00761     return state;
00762   }
00763 
00764   if (!adr.mask.layer) {
00765     adr.mask.layer = true;
00766     for (adr.layer = 1; adr.layer <= N_LAYERS; adr.layer++) state |= GetValue(adr);
00767     return state;
00768   }
00769 
00770   if (!adr.mask.cfeb) {
00771     adr.mask.cfeb = true;
00772     for (adr.cfeb = 1; adr.cfeb <= detector.NumberOfChamberCFEBs(adr.station, adr.ring); adr.cfeb++) state |= GetValue(adr);
00773     return state;
00774   }
00775 
00776   if (!adr.mask.hv) {
00777     adr.mask.hv = true;
00778     for (adr.hv = 1; adr.hv <= detector.NumberOfChamberHVs(adr.station, adr.ring); adr.hv++) state |= GetValue(adr);
00779     return state;
00780   }
00781 
00782   return map[adr.side - 1][adr.station - 1][adr.ring - 1][adr.chamber - 1][adr.layer - 1][adr.cfeb - 1][adr.hv - 1];
00783 
00784 }
00785 
00791 const unsigned int Summary::setMaskedHWElements(std::vector<std::string>& tokens) {
00792   unsigned int applied = 0;
00793   for (unsigned int r = 0; r < tokens.size(); r++) {
00794     std::string token = (std::string) tokens.at(r);
00795     Address adr;
00796     if (detector.AddressFromString(token, adr)) {
00797       SetValue(adr, MASKED);
00798       applied++; 
00799     }
00800   }
00801   return applied;
00802 }
00803 
00811 const bool Summary::ChamberCoordsToAddress(const unsigned int x, const unsigned int y, Address& adr) const {
00812 
00813   if( x < 1 || x > 36 || y < 1 || y > 18) return false;
00814 
00815   adr.mask.side = adr.mask.station = adr.mask.ring = adr.mask.chamber = true;
00816   adr.mask.layer = adr.mask.cfeb = adr.mask.hv = false;
00817 
00818   if ( y < 10 ) adr.side = 2;
00819   else adr.side = 1;
00820 
00821   adr.chamber = x;
00822 
00823   if (y == 1 || y == 18) {
00824     adr.station = 4;
00825     adr.ring    = 2;
00826   } else
00827   if (y == 2 || y == 17) {
00828     adr.station = 4;
00829     adr.ring    = 1;
00830   } else
00831   if (y == 3 || y == 16) {
00832     adr.station = 3;
00833     adr.ring    = 2;
00834   } else
00835   if (y == 4 || y == 15) {
00836     adr.station = 3;
00837     adr.ring    = 1;
00838   } else
00839   if (y == 5 || y == 14) {
00840     adr.station = 2;
00841     adr.ring    = 2;
00842   } else
00843   if (y == 6 || y == 13) {
00844     adr.station = 2;
00845     adr.ring    = 1;
00846   } else
00847   if (y == 7 || y == 12) {
00848     adr.station = 1;
00849     adr.ring    = 3;
00850   } else
00851   if (y == 8 || y == 11) {
00852     adr.station = 1;
00853     adr.ring    = 2;
00854   } else
00855   if (y == 9 || y == 10) {
00856     adr.station = 1;
00857     adr.ring    = 1;
00858   }
00859 
00860   return true;
00861 
00862 }
00863 
00871 const bool Summary::ChamberAddressToCoords(const Address& adr, unsigned int& x, unsigned int& y) const {
00872 
00873   if (!adr.mask.side || !adr.mask.station || !adr.mask.ring || !adr.mask.chamber) return false;
00874 
00875   x = adr.chamber;
00876   y = 0;
00877 
00878   if (adr.side == 1) {
00879     switch (adr.station) {
00880       case 1:
00881         y = 10;
00882         if (adr.ring == 2) y = 11;
00883         if (adr.ring == 3) y = 12;
00884         break;
00885       case 2:
00886         y = 13;
00887         if (adr.ring == 2) y = 14;
00888         break;
00889       case 3:
00890         y = 15;
00891         if (adr.ring == 2) y = 16;
00892         break;
00893       case 4:
00894         y = 17;
00895         if (adr.ring == 2) y = 18;
00896         break;
00897     }
00898   } else
00899   if (adr.side == 2) {
00900     switch (adr.station) {
00901       case 1:
00902         y = 7;
00903         if (adr.ring == 2) y = 8;
00904         if (adr.ring == 1) y = 9;
00905         break;
00906       case 2:
00907         y = 5;
00908         if (adr.ring == 1) y = 6;
00909         break;
00910       case 3:
00911         y = 3;
00912         if (adr.ring == 1) y = 4;
00913         break;
00914       case 4:
00915         y = 1;
00916         if (adr.ring == 1) y = 2;
00917         break;
00918     }
00919   }
00920 
00921   return true;
00922 
00923 }
00924 
00932 const double Summary::SignificanceLevel(const unsigned int N, const unsigned int n, const double eps) const {
00933 
00934   //std::cout << "N = " << N << ", n = " << n << ", eps = " << eps << "\n";
00935 
00936   double l_eps = eps;
00937   if (l_eps <= 0.0) l_eps = 0.000001;
00938   if (l_eps >= 1.0) l_eps = 0.999999;
00939 
00940   double eps_meas = (1.0 * n) / (1.0 * N);
00941   double a = 1.0, b = 1.0;
00942 
00943   if (n > 0) {
00944     for (unsigned int r = 0; r < n; r++) a = a * (eps_meas / l_eps);
00945   }
00946 
00947   if (n < N) {
00948     for (unsigned int r = 0; r < (N - n); r++) b = b * (1 - eps_meas) / (1 - l_eps);
00949   }
00950 
00951   return sqrt(2.0 * log(a * b));
00952 
00953 }
00954 
00963 const double Summary::SignificanceLevelHot(const unsigned int N, const unsigned int n) const {
00964   if (N > n) return 0.0;
00965   // no - n observed, ne - n expected
00966   double no = 1.0 * n, ne = 1.0 * N;
00967   return sqrt(2.0 * (no * (log(no / ne) - 1) + ne));
00968 }
00969 
00970 }

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