CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CalibTracker/SiStripQuality/src/SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiStripQuality/interface/SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy.h"
00002 
00003 #include "FWCore/ServiceRegistry/interface/Service.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 #include "DataFormats/DetId/interface/DetId.h"
00006 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
00007 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00008 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
00009 #include "Geometry/CommonTopologies/interface/StripTopology.h"
00010 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
00011 
00012 
00013 SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy::SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy(const edm::ParameterSet& iConfig, const TrackerTopology* theTopo):
00014   lowoccupancy_(0),
00015   highoccupancy_(100),
00016   absolutelow_(0),
00017   numberiterations_(2),
00018   Nevents_(0),
00019   absolute_occupancy_(0),
00020   OutFileName_("Occupancy.root"),
00021   DQMOutfileName_("DQMOutput"),
00022   UseInputDB_(iConfig.getUntrackedParameter<bool>("UseInputDB",false)),
00023   tTopo(theTopo)
00024   {
00025     minNevents_=Nevents_*absolute_occupancy_;
00026   }
00027 
00028 SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy::~SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy(){
00029   LogTrace("SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy")<<"[SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy::~SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy] "<<std::endl;
00030 }
00031 
00032 void SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy::extractBadAPVSandStrips(SiStripQuality* siStripQuality,HistoMap& DM, edm::ESHandle<SiStripQuality>& inSiStripQuality){
00033 
00034   LogTrace("SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy")<<"[SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy::extractBadAPVs] "<<std::endl;
00035 
00036   if (WriteOutputFile_== true)
00037     {
00038       f = new TFile(OutFileName_.c_str(),"RECREATE");
00039       f->cd();
00040 
00041       apvtree = new TTree("moduleOccupancy","tree");
00042 
00043       apvtree->Branch("DetRawId",                &detrawid,                "DetRawId/I");
00044       apvtree->Branch("SubDetId",                &subdetid,                "SubDetId/I");
00045       apvtree->Branch("Layer_Ring",              &layer_ring,              "Layer_Ring/I");
00046       apvtree->Branch("Disc",                    &disc,                    "Disc/I");
00047       apvtree->Branch("IsBack",                  &isback,                  "IsBack/I");
00048       apvtree->Branch("IsExternalString",        &isexternalstring,        "IsExternalString/I");
00049       apvtree->Branch("IsZMinusSide",            &iszminusside,            "IsZMinusSide/I");
00050       apvtree->Branch("RodStringPetal",          &rodstringpetal,          "RodStringPetal/I");
00051       apvtree->Branch("IsStereo",                &isstereo,                "IsStereo/I");
00052       apvtree->Branch("ModuleNumber",            &module_number,           "ModuleNumber/I");
00053       apvtree->Branch("NumberOfStrips",          &number_strips,           "NumberOfStrips/I");
00054       apvtree->Branch("APVGlobalPositionX",      &global_position_x,       "APVGlobalPositionX/F");
00055       apvtree->Branch("APVGlobalPositionY",      &global_position_y,       "APVGlobalPositionY/F");
00056       apvtree->Branch("APVGlobalPositionZ",      &global_position_z,       "APVGlobalPositionZ/F");
00057       apvtree->Branch("APVNumber",               &apv_number,              "APVNumber/I");
00058       apvtree->Branch("APVAbsoluteOccupancy",    &apvAbsoluteOccupancy,    "apvAbsoluteOccupancy/I");
00059       apvtree->Branch("APVMedianOccupancy",      &apvMedianOccupancy,      "apvMedianOccupancy/D");
00060       apvtree->Branch("IsBad",                   &isBad,                   "IsBad/I");
00061 
00062       striptree = new TTree("stripOccupancy","tree");
00063 
00064       striptree->Branch("DetRawId",             &detrawid,          "DetRawId/I");
00065       striptree->Branch("SubDetId",             &subdetid,          "SubDetId/I");
00066       striptree->Branch("Layer_Ring",           &layer_ring,        "Layer_Ring/I");
00067       striptree->Branch("Disc",                 &disc,              "Disc/I");
00068       striptree->Branch("IsBack",               &isback,            "IsBack/I");
00069       striptree->Branch("IsExternalString",     &isexternalstring,  "IsExternalString/I");
00070       striptree->Branch("IsZMinusSide",         &iszminusside,      "IsZMinusSide/I");
00071       striptree->Branch("RodStringPetal",       &rodstringpetal,    "RodStringPetal/I");
00072       striptree->Branch("IsStereo",             &isstereo,          "IsStereo/I");
00073       striptree->Branch("ModulePosition",       &module_number,     "ModulePosition/I");
00074       striptree->Branch("NumberOfStrips",       &number_strips,     "NumberOfStrips/I");
00075       striptree->Branch("StripNumber",          &strip_number,      "StripNumber/I");
00076       striptree->Branch("APVChannel",           &apv_channel,       "APVChannel/I");
00077       striptree->Branch("StripGlobalPositionX", &strip_global_position_x, "StripGlobalPositionX/F");
00078       striptree->Branch("StripGlobalPositionY", &strip_global_position_y, "StripGlobalPositionY/F");
00079       striptree->Branch("StripGlobalPositionZ", &strip_global_position_z, "StripGlobalPositionZ/F");
00080       striptree->Branch("IsHot",                &isHot,             "IsHot/I");
00081       striptree->Branch("HotStripsPerAPV",      &hotStripsPerAPV,   "HotStripsPerAPV/I");
00082       striptree->Branch("HotStripsPerModule",   &hotStripsPerModule,"HotStripsPerModule/I");
00083       striptree->Branch("StripOccupancy",       &singleStripOccupancy, "StripOccupancy/D");
00084       striptree->Branch("StripHits",            &stripHits,         "StripHits/I");
00085       striptree->Branch("PoissonProb",          &poissonProb,       "PoissonProb/D");
00086     }
00087 
00088   HistoMap::iterator it=DM.begin();
00089   HistoMap::iterator itEnd=DM.end();
00090   std::vector<unsigned int> badStripList;
00091   uint32_t detid;
00092   for (;it!=itEnd;++it){
00093 
00094     Apv APV;
00095 
00096     for (int apv=0; apv<6; apv++)
00097       {
00098         APV.apvMedian[apv]            = 0;
00099         APV.apvabsoluteOccupancy[apv] = 0;
00100         APV.NEntries[apv]            = 0;
00101         APV.NEmptyBins[apv]          = 0;
00102 
00103         for (int strip=0; strip<128; strip++)
00104           {
00105             stripOccupancy[apv][strip] = 0;
00106             stripWeight[apv][strip]    = 0;
00107           }
00108       }
00109 
00110     number_strips  = (int)((it->second.get())->GetNbinsX());
00111     number_apvs    = number_strips/128;
00112     APV.numberApvs = number_apvs;
00113 
00114     for (int apv=0; apv<number_apvs; apv++)
00115       {
00116         APV.th1f[apv] = new TH1F("tmp","tmp",128,0.5,128.5);
00117         int NumberEntriesPerAPV=0;
00118 
00119         for (int strip=0; strip<128; strip++)
00120           {
00121             stripOccupancy[apv][strip] = (it->second.get())->GetBinContent((apv*128)+strip+1); // Remember: Bin=0 is underflow bin!
00122             stripWeight[apv][strip]    = 1;
00123             APV.apvabsoluteOccupancy[apv] += (it->second.get())->GetBinContent((apv*128)+strip+1); // Remember: Bin=0 is underflow bin!
00124             APV.th1f[apv]->SetBinContent(strip+1,(it->second.get())->GetBinContent((apv*128)+strip+1));
00125             NumberEntriesPerAPV += (int)(it->second.get())->GetBinContent((apv*128)+strip+1);
00126           }
00127 
00128         APV.th1f[apv]->SetEntries(NumberEntriesPerAPV);
00129         APV.NEntries[apv]=(int)APV.th1f[apv]->GetEntries();
00130       }
00131 
00132     for (int apv=0; apv<number_apvs; apv++)
00133       {
00134         APV.apvMedian[apv] = TMath::Median(128,stripOccupancy[apv],stripWeight[apv]);
00135       }
00136 
00137     detid=it->first;
00138     DetId detectorId=DetId(detid);
00139 
00140     if (edm::isDebugEnabled())
00141       LogTrace("SiStripBadAPV") << "Analyzing detid " << detid<< std::endl;
00142 
00143     detrawid     = detid;
00144     APV.detrawId = detrawid;
00145     subdetid     = detectorId.subdetId();
00146 
00147     switch (detectorId.subdetId())
00148       {
00149       case StripSubdetector::TIB :
00150         layer_ring         = tTopo->tibLayer(detrawid);
00151         module_number      = tTopo->tibModule(detrawid);
00152         APV.modulePosition = module_number;
00153 
00154         if      (layer_ring == 1) medianValues_TIB_Layer1.push_back(APV);
00155         else if (layer_ring == 2) medianValues_TIB_Layer2.push_back(APV);
00156         else if (layer_ring == 3) medianValues_TIB_Layer3.push_back(APV);
00157         else if (layer_ring == 4) medianValues_TIB_Layer4.push_back(APV);
00158         break;
00159 
00160       case StripSubdetector::TID :
00161         layer_ring         = tTopo->tidRing(detrawid);
00162         disc               = tTopo->tidWheel(detrawid);
00163         APV.modulePosition = layer_ring;
00164 
00165         if (tTopo->tidIsZMinusSide(detrawid)) iszminusside = 1;
00166         else                                   iszminusside = 0;
00167 
00168         if (iszminusside==0)
00169           {
00170             if      (disc==1) medianValues_TIDPlus_Disc1.push_back(APV);
00171             else if (disc==2) medianValues_TIDPlus_Disc2.push_back(APV);
00172             else if (disc==3) medianValues_TIDPlus_Disc3.push_back(APV);
00173           }
00174         else if (iszminusside==1)
00175           {
00176             if      (disc==1) medianValues_TIDMinus_Disc1.push_back(APV);
00177             else if (disc==2) medianValues_TIDMinus_Disc2.push_back(APV);
00178             else if (disc==3) medianValues_TIDMinus_Disc3.push_back(APV);
00179           }
00180         break;
00181 
00182       case StripSubdetector::TOB :
00183         layer_ring         = tTopo->tobLayer(detrawid);
00184         module_number      = tTopo->tobModule(detrawid);
00185         APV.modulePosition = module_number;
00186 
00187         if      (layer_ring == 1) medianValues_TOB_Layer1.push_back(APV);
00188         else if (layer_ring == 2) medianValues_TOB_Layer2.push_back(APV);
00189         else if (layer_ring == 3) medianValues_TOB_Layer3.push_back(APV);
00190         else if (layer_ring == 4) medianValues_TOB_Layer4.push_back(APV);
00191         else if (layer_ring == 5) medianValues_TOB_Layer5.push_back(APV);
00192         else if (layer_ring == 6) medianValues_TOB_Layer6.push_back(APV);
00193         break;
00194 
00195       case StripSubdetector::TEC :
00196         layer_ring         = tTopo->tecRing(detrawid);
00197         disc               = tTopo->tecWheel(detrawid);
00198         APV.modulePosition = layer_ring;
00199 
00200         if (tTopo->tecIsZMinusSide(detrawid)) iszminusside = 1;
00201         else                                   iszminusside = 0;
00202 
00203         if (iszminusside==0)
00204           {
00205             if      (disc==1) medianValues_TECPlus_Disc1.push_back(APV);
00206             else if (disc==2) medianValues_TECPlus_Disc2.push_back(APV);
00207             else if (disc==3) medianValues_TECPlus_Disc3.push_back(APV);
00208             else if (disc==4) medianValues_TECPlus_Disc4.push_back(APV);
00209             else if (disc==5) medianValues_TECPlus_Disc5.push_back(APV);
00210             else if (disc==6) medianValues_TECPlus_Disc6.push_back(APV);
00211             else if (disc==7) medianValues_TECPlus_Disc7.push_back(APV);
00212             else if (disc==8) medianValues_TECPlus_Disc8.push_back(APV);
00213             else if (disc==9) medianValues_TECPlus_Disc9.push_back(APV);
00214           }
00215         else if (iszminusside==1)
00216           {
00217             if      (disc==1) medianValues_TECMinus_Disc1.push_back(APV);
00218             else if (disc==2) medianValues_TECMinus_Disc2.push_back(APV);
00219             else if (disc==3) medianValues_TECMinus_Disc3.push_back(APV);
00220             else if (disc==4) medianValues_TECMinus_Disc4.push_back(APV);
00221             else if (disc==5) medianValues_TECMinus_Disc5.push_back(APV);
00222             else if (disc==6) medianValues_TECMinus_Disc6.push_back(APV);
00223             else if (disc==7) medianValues_TECMinus_Disc7.push_back(APV);
00224             else if (disc==8) medianValues_TECMinus_Disc8.push_back(APV);
00225             else if (disc==9) medianValues_TECMinus_Disc9.push_back(APV);
00226           }
00227         break;
00228 
00229       default :
00230         std::cout << "### Detector does not belong to TIB, TID, TOB or TEC !? ###" << std::endl;
00231         std::cout << "### DetRawId: " << detrawid << " ###" << std::endl;
00232       }
00233 
00234   } // end loop on modules
00235 
00236   // Calculate Mean and RMS for each Layer
00237   CalculateMeanAndRMS(medianValues_TIB_Layer1,MeanAndRms_TIB_Layer1,numberiterations_);
00238   CalculateMeanAndRMS(medianValues_TIB_Layer2,MeanAndRms_TIB_Layer2,numberiterations_);
00239   CalculateMeanAndRMS(medianValues_TIB_Layer3,MeanAndRms_TIB_Layer3,numberiterations_);
00240   CalculateMeanAndRMS(medianValues_TIB_Layer4,MeanAndRms_TIB_Layer4,numberiterations_);
00241 
00242   CalculateMeanAndRMS(medianValues_TOB_Layer1,MeanAndRms_TOB_Layer1,numberiterations_);
00243   CalculateMeanAndRMS(medianValues_TOB_Layer2,MeanAndRms_TOB_Layer2,numberiterations_);
00244   CalculateMeanAndRMS(medianValues_TOB_Layer3,MeanAndRms_TOB_Layer3,numberiterations_);
00245   CalculateMeanAndRMS(medianValues_TOB_Layer4,MeanAndRms_TOB_Layer4,numberiterations_);
00246   CalculateMeanAndRMS(medianValues_TOB_Layer5,MeanAndRms_TOB_Layer5,numberiterations_);
00247   CalculateMeanAndRMS(medianValues_TOB_Layer6,MeanAndRms_TOB_Layer6,numberiterations_);
00248 
00249   CalculateMeanAndRMS(medianValues_TIDPlus_Disc1,MeanAndRms_TIDPlus_Disc1,numberiterations_);
00250   CalculateMeanAndRMS(medianValues_TIDPlus_Disc2,MeanAndRms_TIDPlus_Disc2,numberiterations_);
00251   CalculateMeanAndRMS(medianValues_TIDPlus_Disc3,MeanAndRms_TIDPlus_Disc3,numberiterations_);
00252   CalculateMeanAndRMS(medianValues_TIDMinus_Disc1,MeanAndRms_TIDMinus_Disc1,numberiterations_);
00253   CalculateMeanAndRMS(medianValues_TIDMinus_Disc2,MeanAndRms_TIDMinus_Disc2,numberiterations_);
00254   CalculateMeanAndRMS(medianValues_TIDMinus_Disc3,MeanAndRms_TIDMinus_Disc3,numberiterations_);
00255 
00256   CalculateMeanAndRMS(medianValues_TECPlus_Disc1,MeanAndRms_TECPlus_Disc1,numberiterations_);
00257   CalculateMeanAndRMS(medianValues_TECPlus_Disc2,MeanAndRms_TECPlus_Disc2,numberiterations_);
00258   CalculateMeanAndRMS(medianValues_TECPlus_Disc3,MeanAndRms_TECPlus_Disc3,numberiterations_);
00259   CalculateMeanAndRMS(medianValues_TECPlus_Disc4,MeanAndRms_TECPlus_Disc4,numberiterations_);
00260   CalculateMeanAndRMS(medianValues_TECPlus_Disc5,MeanAndRms_TECPlus_Disc5,numberiterations_);
00261   CalculateMeanAndRMS(medianValues_TECPlus_Disc6,MeanAndRms_TECPlus_Disc6,numberiterations_);
00262   CalculateMeanAndRMS(medianValues_TECPlus_Disc7,MeanAndRms_TECPlus_Disc7,numberiterations_);
00263   CalculateMeanAndRMS(medianValues_TECPlus_Disc8,MeanAndRms_TECPlus_Disc8,numberiterations_);
00264   CalculateMeanAndRMS(medianValues_TECPlus_Disc9,MeanAndRms_TECPlus_Disc9,numberiterations_);
00265 
00266   CalculateMeanAndRMS(medianValues_TECMinus_Disc1,MeanAndRms_TECMinus_Disc1,numberiterations_);
00267   CalculateMeanAndRMS(medianValues_TECMinus_Disc2,MeanAndRms_TECMinus_Disc2,numberiterations_);
00268   CalculateMeanAndRMS(medianValues_TECMinus_Disc3,MeanAndRms_TECMinus_Disc3,numberiterations_);
00269   CalculateMeanAndRMS(medianValues_TECMinus_Disc4,MeanAndRms_TECMinus_Disc4,numberiterations_);
00270   CalculateMeanAndRMS(medianValues_TECMinus_Disc5,MeanAndRms_TECMinus_Disc5,numberiterations_);
00271   CalculateMeanAndRMS(medianValues_TECMinus_Disc6,MeanAndRms_TECMinus_Disc6,numberiterations_);
00272   CalculateMeanAndRMS(medianValues_TECMinus_Disc7,MeanAndRms_TECMinus_Disc7,numberiterations_);
00273   CalculateMeanAndRMS(medianValues_TECMinus_Disc8,MeanAndRms_TECMinus_Disc8,numberiterations_);
00274   CalculateMeanAndRMS(medianValues_TECMinus_Disc9,MeanAndRms_TECMinus_Disc9,numberiterations_);
00275 
00276   pQuality=siStripQuality;
00277   badStripList.clear();
00278 
00279   // Initialize the DQM output histograms
00280   initializeDQMHistograms();
00281 
00282   // Analyze the Occupancy for both APVs and Strips
00283   AnalyzeOccupancy(siStripQuality,medianValues_TIB_Layer1,MeanAndRms_TIB_Layer1,badStripList,inSiStripQuality);
00284   AnalyzeOccupancy(siStripQuality,medianValues_TIB_Layer2,MeanAndRms_TIB_Layer2,badStripList,inSiStripQuality);
00285   AnalyzeOccupancy(siStripQuality,medianValues_TIB_Layer3,MeanAndRms_TIB_Layer3,badStripList,inSiStripQuality);
00286   AnalyzeOccupancy(siStripQuality,medianValues_TIB_Layer4,MeanAndRms_TIB_Layer4,badStripList,inSiStripQuality);
00287 
00288   AnalyzeOccupancy(siStripQuality,medianValues_TOB_Layer1,MeanAndRms_TOB_Layer1,badStripList,inSiStripQuality);
00289   AnalyzeOccupancy(siStripQuality,medianValues_TOB_Layer2,MeanAndRms_TOB_Layer2,badStripList,inSiStripQuality);
00290   AnalyzeOccupancy(siStripQuality,medianValues_TOB_Layer3,MeanAndRms_TOB_Layer3,badStripList,inSiStripQuality);
00291   AnalyzeOccupancy(siStripQuality,medianValues_TOB_Layer4,MeanAndRms_TOB_Layer4,badStripList,inSiStripQuality);
00292   AnalyzeOccupancy(siStripQuality,medianValues_TOB_Layer5,MeanAndRms_TOB_Layer5,badStripList,inSiStripQuality);
00293   AnalyzeOccupancy(siStripQuality,medianValues_TOB_Layer6,MeanAndRms_TOB_Layer6,badStripList,inSiStripQuality);
00294 
00295   AnalyzeOccupancy(siStripQuality,medianValues_TIDPlus_Disc1,MeanAndRms_TIDPlus_Disc1,badStripList,inSiStripQuality);
00296   AnalyzeOccupancy(siStripQuality,medianValues_TIDPlus_Disc2,MeanAndRms_TIDPlus_Disc2,badStripList,inSiStripQuality);
00297   AnalyzeOccupancy(siStripQuality,medianValues_TIDPlus_Disc3,MeanAndRms_TIDPlus_Disc3,badStripList,inSiStripQuality);
00298   AnalyzeOccupancy(siStripQuality,medianValues_TIDMinus_Disc1,MeanAndRms_TIDMinus_Disc1,badStripList,inSiStripQuality);
00299   AnalyzeOccupancy(siStripQuality,medianValues_TIDMinus_Disc2,MeanAndRms_TIDMinus_Disc2,badStripList,inSiStripQuality);
00300   AnalyzeOccupancy(siStripQuality,medianValues_TIDMinus_Disc3,MeanAndRms_TIDMinus_Disc3,badStripList,inSiStripQuality);
00301 
00302   AnalyzeOccupancy(siStripQuality,medianValues_TECPlus_Disc1,MeanAndRms_TECPlus_Disc1,badStripList,inSiStripQuality);
00303   AnalyzeOccupancy(siStripQuality,medianValues_TECPlus_Disc2,MeanAndRms_TECPlus_Disc2,badStripList,inSiStripQuality);
00304   AnalyzeOccupancy(siStripQuality,medianValues_TECPlus_Disc3,MeanAndRms_TECPlus_Disc3,badStripList,inSiStripQuality);
00305   AnalyzeOccupancy(siStripQuality,medianValues_TECPlus_Disc4,MeanAndRms_TECPlus_Disc4,badStripList,inSiStripQuality);
00306   AnalyzeOccupancy(siStripQuality,medianValues_TECPlus_Disc5,MeanAndRms_TECPlus_Disc5,badStripList,inSiStripQuality);
00307   AnalyzeOccupancy(siStripQuality,medianValues_TECPlus_Disc6,MeanAndRms_TECPlus_Disc6,badStripList,inSiStripQuality);
00308   AnalyzeOccupancy(siStripQuality,medianValues_TECPlus_Disc7,MeanAndRms_TECPlus_Disc7,badStripList,inSiStripQuality);
00309   AnalyzeOccupancy(siStripQuality,medianValues_TECPlus_Disc8,MeanAndRms_TECPlus_Disc8,badStripList,inSiStripQuality);
00310   AnalyzeOccupancy(siStripQuality,medianValues_TECPlus_Disc9,MeanAndRms_TECPlus_Disc9,badStripList,inSiStripQuality);
00311 
00312   AnalyzeOccupancy(siStripQuality,medianValues_TECMinus_Disc1,MeanAndRms_TECMinus_Disc1,badStripList,inSiStripQuality);
00313   AnalyzeOccupancy(siStripQuality,medianValues_TECMinus_Disc2,MeanAndRms_TECMinus_Disc2,badStripList,inSiStripQuality);
00314   AnalyzeOccupancy(siStripQuality,medianValues_TECMinus_Disc3,MeanAndRms_TECMinus_Disc3,badStripList,inSiStripQuality);
00315   AnalyzeOccupancy(siStripQuality,medianValues_TECMinus_Disc4,MeanAndRms_TECMinus_Disc4,badStripList,inSiStripQuality);
00316   AnalyzeOccupancy(siStripQuality,medianValues_TECMinus_Disc5,MeanAndRms_TECMinus_Disc5,badStripList,inSiStripQuality);
00317   AnalyzeOccupancy(siStripQuality,medianValues_TECMinus_Disc6,MeanAndRms_TECMinus_Disc6,badStripList,inSiStripQuality);
00318   AnalyzeOccupancy(siStripQuality,medianValues_TECMinus_Disc7,MeanAndRms_TECMinus_Disc7,badStripList,inSiStripQuality);
00319   AnalyzeOccupancy(siStripQuality,medianValues_TECMinus_Disc8,MeanAndRms_TECMinus_Disc8,badStripList,inSiStripQuality);
00320   AnalyzeOccupancy(siStripQuality,medianValues_TECMinus_Disc9,MeanAndRms_TECMinus_Disc9,badStripList,inSiStripQuality);
00321 
00322   siStripQuality->fillBadComponents();
00323 
00324   // Fill DQM histograms
00325   for(unsigned int i = 0; i < subDetName.size(); i++)
00326     {
00327       projYDistanceVsStripNumber[i]->Add((TH1F*)distanceVsStripNumber[i]->ProjectionY());
00328       pfxDistanceVsStripNumber[i]->Add(distanceVsStripNumber[i]->ProfileX(pfxDistanceVsStripNumber[i]->GetName(),1,998));
00329       projYNHitsVsStripNumber[i]->Add(nHitsVsStripNumber[i]->ProjectionY());
00330       projYNHitsGoodStripsVsStripNumber[i]->Add(nHitsGoodStripsVsStripNumber[i]->ProjectionY());
00331       projYNHitsHotStripsVsStripNumber[i]->Add(nHitsHotStripsVsStripNumber[i]->ProjectionY());
00332       projYOccupancyVsStripNumber[i]->Add(occupancyVsStripNumber[i]->ProjectionY());
00333       projYOccupancyGoodStripsVsStripNumber[i]->Add(occupancyGoodStripsVsStripNumber[i]->ProjectionY());
00334       projYOccupancyHotStripsVsStripNumber[i]->Add(occupancyHotStripsVsStripNumber[i]->ProjectionY());
00335       pfxOccupancyVsStripNumber[i]->Add(occupancyVsStripNumber[i]->ProfileX(pfxOccupancyVsStripNumber[i]->GetName(),-8.,0.));
00336       pfxOccupancyGoodStripsVsStripNumber[i]->Add(occupancyGoodStripsVsStripNumber[i]->ProfileX(pfxOccupancyGoodStripsVsStripNumber[i]->GetName(),-8.,0.));
00337       pfxOccupancyHotStripsVsStripNumber[i]->Add(occupancyHotStripsVsStripNumber[i]->ProfileX(pfxOccupancyHotStripsVsStripNumber[i]->GetName(),-8.,0.));
00338       projYPoissonProbVsStripNumber[i]->Add(poissonProbVsStripNumber[i]->ProjectionY());
00339       projYPoissonProbGoodStripsVsStripNumber[i]->Add(poissonProbGoodStripsVsStripNumber[i]->ProjectionY());
00340       projYPoissonProbHotStripsVsStripNumber[i]->Add(poissonProbHotStripsVsStripNumber[i]->ProjectionY());
00341       pfxPoissonProbVsStripNumber[i]->Add(poissonProbVsStripNumber[i]->ProfileX(pfxPoissonProbVsStripNumber[i]->GetName(),-18., 0.));
00342       pfxPoissonProbGoodStripsVsStripNumber[i]->Add(poissonProbGoodStripsVsStripNumber[i]->ProfileX(pfxPoissonProbGoodStripsVsStripNumber[i]->GetName(),-18., 0.));
00343       pfxPoissonProbHotStripsVsStripNumber[i]->Add(poissonProbHotStripsVsStripNumber[i]->ProfileX(pfxPoissonProbHotStripsVsStripNumber[i]->GetName(),-18., 0.));
00344       projXDistanceVsStripNumber[i]->Add(distanceVsStripNumber[i]->ProjectionX(projXDistanceVsStripNumber[i]->GetName(),1,998));
00345 
00346     }
00347 
00348   // Save output files
00349 
00350   if (WriteOutputFile_==true){
00351   f->cd();
00352   apvtree->Write();
00353   striptree->Write();
00354   f->Close();
00355   }
00356 
00357   if (WriteDQMHistograms_==true){
00358     dqmStore->cd();
00359     dqmStore->save(DQMOutfileName_.c_str());
00360   }
00361 
00362   LogTrace("SiStripBadAPV") << ss.str() << std::endl;
00363 }
00364 
00365 
00366 void SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy::CalculateMeanAndRMS(std::vector<Apv> a, std::pair<double,double>* MeanRMS, int number_iterations)
00367 {
00368   Double_t tot[7], tot2[7];
00369   Double_t n[7];
00370 
00371   Double_t Mean[7] = {0};
00372   Double_t Rms[7]  = {1000,1000,1000,1000,1000,1000,1000};
00373 
00374   int Moduleposition;
00375 
00376   for (int i=0; i<number_iterations; i++)
00377     {
00378       for (int j=0; j<7; j++)
00379         {
00380           n[j]    = 0;
00381           tot[j]  = 0;
00382           tot2[j] = 0;
00383         }
00384 
00385       for (uint32_t it=0; it<a.size(); it++)
00386         {
00387           Moduleposition = (a[it].modulePosition)-1;
00388 
00389           for (int apv=0; apv<a[it].numberApvs; apv++)
00390             {
00391               if (i>0)
00392                 {
00393                   if (a[it].apvMedian[apv]<(Mean[Moduleposition]-3*Rms[Moduleposition]) || (a[it].apvMedian[apv]>(Mean[Moduleposition]+5*Rms[Moduleposition])))
00394                     {
00395                       continue;
00396                     }
00397                 }
00398               tot[Moduleposition]  += a[it].apvMedian[apv];
00399               tot2[Moduleposition] += (a[it].apvMedian[apv])*(a[it].apvMedian[apv]);
00400               n[Moduleposition]++;
00401             }
00402         }
00403 
00404       for (int j=0; j<7; j++)
00405         {
00406           if (n[j]!=0)
00407             {
00408               Mean[j] = tot[j]/n[j];
00409               Rms[j]  = TMath::Sqrt(TMath::Abs(tot2[j]/n[j] -Mean[j]*Mean[j]));
00410             }
00411         }
00412     }
00413 
00414   for (int j=0; j<7; j++)
00415     {
00416       MeanRMS[j] = std::make_pair(Mean[j],Rms[j]);
00417     }
00418 
00419 }
00420 
00421 void SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy::AnalyzeOccupancy(SiStripQuality* quality, std::vector<Apv>& medianValues, std::pair<double,double>* MeanAndRms, std::vector<unsigned int>& BadStripList, edm::ESHandle<SiStripQuality>& InSiStripQuality)
00422 {
00423   int Moduleposition;
00424   uint32_t Detid;
00425 
00426   for (uint32_t it=0; it<medianValues.size(); it++)
00427     {
00428       Moduleposition = (medianValues[it].modulePosition)-1;
00429       Detid          = medianValues[it].detrawId;
00430 
00431       setBasicTreeParameters(Detid);
00432 
00433       DetId DetectorId=DetId(Detid);
00434       const StripGeomDetUnit*  TheStripDet   = dynamic_cast<const StripGeomDetUnit*>( (TkGeom->idToDet(DetectorId)) );
00435       const StripTopology*     TheStripTopol = dynamic_cast<const StripTopology*>( &(TheStripDet->specificTopology()) );
00436 
00437       //Analyze the occupancies
00438       hotstripspermodule = 0;
00439       vHotStripsInModule.clear();
00440 
00441       for (int apv=0; apv<medianValues[it].numberApvs; apv++)
00442         {
00443           double logMedianOccupancy = -1;
00444           double logAbsoluteOccupancy = -1;
00445 
00446           for (int i=0; i<128; i++)
00447             {
00448               ishot[i]               = 0;
00449               stripoccupancy[i]      = 0;
00450               striphits[i]           = 0;
00451               poissonprob[i]         = 0;
00452             }
00453 
00454           number_strips        = (medianValues[it].numberApvs)*128;
00455           apv_number           = apv+1;
00456           apvMedianOccupancy   = medianValues[it].apvMedian[apv];
00457           apvAbsoluteOccupancy = medianValues[it].apvabsoluteOccupancy[apv];
00458           isBad                = 0;
00459           hotstripsperapv[apv] = 0;
00460 
00461           LocalPoint  pos_apv_local  = TheStripTopol->localPosition((apv*128));
00462           GlobalPoint pos_apv_global = (TkGeom->idToDet(DetectorId))->surface().toGlobal(pos_apv_local);
00463 
00464           global_position_x = pos_apv_global.x();
00465           global_position_y = pos_apv_global.y();
00466           global_position_z = pos_apv_global.z();
00467 
00468           if (apvMedianOccupancy>0) logMedianOccupancy = log10(apvMedianOccupancy);
00469           if (apvAbsoluteOccupancy>0) logAbsoluteOccupancy = log10(apvAbsoluteOccupancy);
00470 
00471           //Fill the DQM histograms
00472           unsigned int layer = 0;
00473           if(subdetid==3 || subdetid==5)
00474             layer=layer_ring;
00475           else
00476             layer=disc;
00477 
00478           // Fill histograms for all the tracker
00479           medianVsAbsoluteOccupancy[0][0]->Fill(logAbsoluteOccupancy,logMedianOccupancy);
00480           medianOccupancy[0][0]->Fill(logMedianOccupancy);
00481           absoluteOccupancy[0][0]->Fill(logAbsoluteOccupancy);
00482           // Fill summary histograms for each subdetector
00483           medianVsAbsoluteOccupancy[subdetid-2][0]->Fill(logAbsoluteOccupancy,logMedianOccupancy);
00484           medianOccupancy[subdetid-2][0]->Fill(logMedianOccupancy);
00485           absoluteOccupancy[subdetid-2][0]->Fill(logAbsoluteOccupancy);
00486           // Fill histograms for each layer/disk
00487           medianVsAbsoluteOccupancy[subdetid-2][layer]->Fill(logAbsoluteOccupancy,logMedianOccupancy);
00488           medianOccupancy[subdetid-2][layer]->Fill(logMedianOccupancy);
00489           absoluteOccupancy[subdetid-2][layer]->Fill(logAbsoluteOccupancy);
00490 
00491           if(UseInputDB_)
00492             {
00493               if(InSiStripQuality->IsApvBad(Detid,apv) )
00494                 {
00495                   if (WriteOutputFile_==true)
00496                     {
00497                       apvtree->Fill();
00498                       for (int strip=0; strip<128; strip++)
00499                         {
00500                           strip_number         = (apv*128)+strip+1;
00501                           apv_channel          = apv+1;
00502                           isHot                = ishot[strip];
00503                           singleStripOccupancy = stripoccupancy[strip];
00504                           stripHits            = striphits[strip];
00505                           poissonProb          = poissonprob[strip];
00506 
00507                           hotStripsPerModule = hotstripspermodule;
00508                           hotStripsPerAPV    = hotstripsperapv[apv];
00509 
00510                           LocalPoint  pos_strip_local  = TheStripTopol->localPosition(strip);
00511                           GlobalPoint pos_strip_global = (TkGeom->idToDet(DetectorId))->surface().toGlobal(pos_strip_local);
00512 
00513                           strip_global_position_x = pos_strip_global.x();
00514                           strip_global_position_y = pos_strip_global.y();
00515                           strip_global_position_z = pos_strip_global.z();
00516                           striptree->Fill();
00517 
00518                           // Fill the strip DQM Plots
00519                           fillStripDQMHistograms();
00520                         }
00521      
00522                       if(vHotStripsInModule.size()==1)
00523                         {
00524                           distance = 999;
00525                           distanceVsStripNumber[0]->Fill(vHotStripsInModule[0], distance);
00526                           distanceVsStripNumber[subdetid-2]->Fill(vHotStripsInModule[0], distance);
00527                         }
00528                       else if(vHotStripsInModule.size()>1)
00529                         {
00530                           for(unsigned int iVec = 0; iVec != vHotStripsInModule.size(); iVec++)
00531                             {
00532                               if(iVec==0)
00533                                 distance = vHotStripsInModule[1] - vHotStripsInModule[0];
00534                               else if(iVec==vHotStripsInModule.size()-1)
00535                                 {
00536                                   distance = vHotStripsInModule[vHotStripsInModule.size()-1] - vHotStripsInModule[vHotStripsInModule.size() -2];
00537                                 }
00538                               else if(vHotStripsInModule.size()>2)
00539                                 {
00540                                   distanceR = vHotStripsInModule[iVec + 1] -  vHotStripsInModule[iVec];
00541                                   distanceL = vHotStripsInModule[iVec] - vHotStripsInModule[iVec - 1];
00542                                   distance = distanceL>distanceR?distanceR:distanceL;
00543                                 }
00544                               else
00545                                 {
00546                                   std::cout << "ERROR! distance is never computed!!!\n";
00547                                 }
00548                               distanceVsStripNumber[0]->Fill(vHotStripsInModule[iVec], distance);
00549                               distanceVsStripNumber[subdetid-2]->Fill(vHotStripsInModule[iVec], distance);
00550                             }
00551                         }
00552 
00553                     }
00554                   continue;//if the apv is already flagged as bad, continue.
00555                 }
00556             }
00557 
00558           if (medianValues[it].apvMedian[apv] > minNevents_)
00559             {
00560               if ((medianValues[it].apvMedian[apv]>(MeanAndRms[Moduleposition].first+highoccupancy_*MeanAndRms[Moduleposition].second)) && (medianValues[it].apvMedian[apv]>absolutelow_))
00561                 {
00562                   BadStripList.push_back(pQuality->encode((apv*128),128,0));
00563                   isBad = 1;
00564                 }
00565             }
00566           else if (medianValues[it].apvMedian[apv]<(MeanAndRms[Moduleposition].first-lowoccupancy_*MeanAndRms[Moduleposition].second) && (MeanAndRms[Moduleposition].first>2 || medianValues[it].apvabsoluteOccupancy[apv]==0))
00567             {
00568               BadStripList.push_back(pQuality->encode((apv*128),128,0));
00569               isBad = 1;
00570             }
00571 
00572           if (isBad!=1)
00573             {
00574               iterativeSearch(medianValues[it],BadStripList,apv);
00575             }
00576 
00577           if (WriteOutputFile_==true)
00578             {
00579               apvtree->Fill();
00580               for (int strip=0; strip<128; strip++)
00581                 {
00582                   strip_number         = (apv*128)+strip+1;
00583                   apv_channel          = apv+1;
00584                   isHot                = ishot[strip];
00585                   singleStripOccupancy = stripoccupancy[strip];
00586                   stripHits            = striphits[strip];
00587                   poissonProb          = poissonprob[strip];
00588 
00589                   hotStripsPerModule = hotstripspermodule;
00590                   hotStripsPerAPV    = hotstripsperapv[apv];
00591 
00592                   LocalPoint  pos_strip_local  = TheStripTopol->localPosition(strip);
00593                   GlobalPoint pos_strip_global = (TkGeom->idToDet(DetectorId))->surface().toGlobal(pos_strip_local);
00594 
00595                   strip_global_position_x = pos_strip_global.x();
00596                   strip_global_position_y = pos_strip_global.y();
00597                   strip_global_position_z = pos_strip_global.z();
00598                   striptree->Fill();
00599 
00600                   // Fill the strip DQM Plots
00601                   fillStripDQMHistograms();
00602                 }
00603               if(vHotStripsInModule.size()==1)
00604                 {
00605                   distance = 999;
00606                   distanceVsStripNumber[0]->Fill(vHotStripsInModule[0], distance);
00607                   distanceVsStripNumber[subdetid-2]->Fill(vHotStripsInModule[0], distance);
00608                 }
00609               else if(vHotStripsInModule.size()>1)
00610                 {
00611                   for(unsigned int iVec = 0; iVec != vHotStripsInModule.size(); iVec++)
00612                     {
00613                       if(iVec==0)
00614                         distance = vHotStripsInModule[1] - vHotStripsInModule[0];
00615                       else if(iVec==vHotStripsInModule.size()-1)
00616                         {
00617                           distance = vHotStripsInModule[vHotStripsInModule.size()-1] - vHotStripsInModule[vHotStripsInModule.size() -2];
00618                         }
00619                       else if(vHotStripsInModule.size()>2)
00620                         {
00621                           distanceR = vHotStripsInModule[iVec + 1] -  vHotStripsInModule[iVec];
00622                           distanceL = vHotStripsInModule[iVec] - vHotStripsInModule[iVec - 1];
00623                           distance = distanceL>distanceR?distanceR:distanceL;
00624                         }
00625                       else
00626                         {
00627                           std::cout << "ERROR! distance is never computed!!!\n";
00628                         }
00629                       distanceVsStripNumber[0]->Fill(vHotStripsInModule[iVec], distance);
00630                       distanceVsStripNumber[subdetid-2]->Fill(vHotStripsInModule[iVec], distance);
00631                     }
00632                 }
00633             }
00634         }
00635 
00636       if (BadStripList.begin()!=BadStripList.end())
00637         {
00638           quality->compact(Detid,BadStripList);
00639           SiStripQuality::Range range(BadStripList.begin(),BadStripList.end());
00640           quality->put(Detid,range);
00641         }
00642       BadStripList.clear();
00643     }
00644 }
00645 
00646 void SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy::iterativeSearch(Apv& histo,std::vector<unsigned int>& vect, int apv){
00647   if (!histo.NEntries[apv] || histo.NEntries[apv] <=MinNumEntries_ || histo.NEntries[apv] <= minNevents_)
00648     return;
00649   
00650   size_t startingSize=vect.size();
00651   long double diff=1.-prob_; 
00652   
00653   size_t Nbins     = histo.th1f[apv]->GetNbinsX();
00654   size_t ibinStart = 1; 
00655   size_t ibinStop  = Nbins+1; 
00656   int MaxEntry  = (int)histo.th1f[apv]->GetMaximum();
00657 
00658   std::vector<long double> vPoissonProbs(MaxEntry+1,0);
00659   long double meanVal=1.*histo.NEntries[apv]/(1.*Nbins-histo.NEmptyBins[apv]); 
00660   evaluatePoissonian(vPoissonProbs,meanVal);
00661 
00662   for (size_t i=ibinStart; i<ibinStop; ++i){
00663     unsigned int entries= (unsigned int)histo.th1f[apv]->GetBinContent(i);
00664 
00665     if (ishot[i-1]==0){
00666       stripoccupancy[i-1] = entries/(double) Nevents_;
00667       striphits[i-1]      = entries;
00668       poissonprob[i-1]    = 1-vPoissonProbs[entries];
00669     }
00670 
00671     if (entries<=MinNumEntriesPerStrip_ || entries <= minNevents_)
00672       continue;
00673 
00674     if(diff<vPoissonProbs[entries]){
00675       ishot[i-1] = 1;
00676       hotstripspermodule++;
00677       hotstripsperapv[apv]++;
00678       histo.th1f[apv]->SetBinContent(i,0.);
00679       histo.NEntries[apv]-=entries;
00680       histo.NEmptyBins[apv]++;
00681       if (edm::isDebugEnabled())
00682         LogTrace("SiStripHotStrip")<< " rejecting strip " << (apv*128)+i-1 << " value " << entries << " diff  " << diff << " prob " << vPoissonProbs[entries]<< std::endl;
00683       vect.push_back(pQuality->encode((apv*128)+i-1,1,0));
00684     }
00685 
00686   }
00687   if (edm::isDebugEnabled())
00688     LogTrace("SiStripHotStrip") << " [SiStripHotStripAlgorithmFromClusterOccupancy::iterativeSearch] Nbins="<< Nbins << " MaxEntry="<<MaxEntry << " meanVal=" << meanVal << " NEmptyBins="<<histo.NEmptyBins[apv]<< " NEntries=" << histo.NEntries[apv] << " thEntries " << histo.th1f[apv]->GetEntries()<< " startingSize " << startingSize << " vector.size " << vect.size() << std::endl;
00689 
00690   if (vect.size()!=startingSize)
00691     iterativeSearch(histo,vect,apv);
00692 }
00693 
00694 void SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy::evaluatePoissonian(std::vector<long double>& vPoissonProbs, long double& meanVal){
00695   for(size_t i=0;i<vPoissonProbs.size();++i){
00696     vPoissonProbs[i]= (i==0)?TMath::Poisson(i,meanVal):vPoissonProbs[i-1]+TMath::Poisson(i,meanVal);
00697   }
00698 }
00699 
00700 void SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy::setBasicTreeParameters(int detid){
00701   DetId DetectorID=DetId(detid);
00702 
00703   detrawid = detid;
00704   subdetid = DetectorID.subdetId();
00705 
00706   if (SiStripDetId(detid).stereo() !=0 ) isstereo = 1; // It's a stereo module
00707   else                                   isstereo = 0; // It's an rphi module
00708   switch (DetectorID.subdetId())
00709     {
00710     case StripSubdetector::TIB :
00711       layer_ring = tTopo->tibLayer(detid);
00712       disc       = -1;
00713       isback     = -1;
00714       if (tTopo->tibIsExternalString(detid)) isexternalstring = 1;
00715       else                                    isexternalstring = 0;
00716       if (tTopo->tibIsZMinusSide(detid)) iszminusside = 1;
00717       else                                iszminusside = 0;
00718       rodstringpetal     = tTopo->tibString(detid);
00719       module_number      = tTopo->tibModule(detid);
00720 
00721       break;
00722 
00723     case StripSubdetector::TID :
00724       layer_ring = tTopo->tidRing(detid);
00725       disc       = tTopo->tidWheel(detid);
00726       if (tTopo->tidIsBackRing(detid)) isback = 1;
00727       else                              isback = 0;
00728       if (tTopo->tidIsZMinusSide(detid)) iszminusside = 1;
00729       else                                iszminusside = 0;
00730       isexternalstring   = -1;
00731       rodstringpetal     = -1;
00732       module_number      = tTopo->tidModule(detid);
00733 
00734       break;
00735 
00736     case StripSubdetector::TOB :
00737       layer_ring = tTopo->tobLayer(detid);
00738       disc       = -1;
00739       isback     = -1;
00740       if (tTopo->tobIsZMinusSide(detid)) iszminusside = 1;
00741       else                                iszminusside = 0;
00742       isexternalstring   = -1;
00743       rodstringpetal     = tTopo->tobRod(detid);
00744       module_number      = tTopo->tobModule(detid);
00745 
00746       break;
00747 
00748     case StripSubdetector::TEC :
00749       layer_ring = tTopo->tecRing(detid);
00750       disc       = tTopo->tecWheel(detid);
00751       if (tTopo->tecIsBackPetal(detid)) isback = 1;
00752       else                               isback = 0;
00753       if (tTopo->tecIsZMinusSide(detid)) iszminusside = 1;
00754       else                                iszminusside = 0;
00755       isexternalstring   = -1;
00756       rodstringpetal     = tTopo->tecPetalNumber(detid);
00757       module_number      = tTopo->tecModule(detid);
00758 
00759       break;
00760 
00761     default :
00762       std::cout << "### Detector does not belong to TIB, TID, TOB or TEC !? ###" << std::endl;
00763       std::cout << "### DetRawId: " << detid << " ###" << std::endl;
00764     }
00765 }
00766 
00767 void SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy::setMinNumOfEvents()
00768 {
00769   minNevents_=absolute_occupancy_*Nevents_;
00770 }
00771 
00772 void SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy::initializeDQMHistograms()
00773 {
00774   oss.str("");
00775   oss << 1; //runNumber
00776 
00777   dqmStore = edm::Service<DQMStore>().operator->();
00778   dqmStore->setCurrentFolder("ChannelStatusPlots");
00779 
00780   // Initialize histograms
00781   subDetName.push_back(""); subDetName.push_back("TIB"); subDetName.push_back("TID"); subDetName.push_back("TOB"); subDetName.push_back("TEC");
00782   nLayers.push_back(0); nLayers.push_back(4); nLayers.push_back(3); nLayers.push_back(6); nLayers.push_back(9);
00783   layerName.push_back(""); layerName.push_back("Layer"); layerName.push_back("Disk"); layerName.push_back("Layer"); layerName.push_back("Disk");
00784   
00785   std::string histoName;
00786   std::string histoTitle;
00787 
00788   for(unsigned int i = 0; i < subDetName.size(); i++)
00789   {
00790     histoName = "distanceVsStripNumber" + subDetName[i];
00791     histoTitle = "Distance between hot strips vs. strip number";
00792     if(i!=0)
00793       histoTitle += " in " + subDetName[i];
00794     tmp = dqmStore->book2D(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5, 999, 0.5, 999.5);
00795     distanceVsStripNumber.push_back(tmp->getTH2F());
00796 
00797     histoName = "pfxDistanceVsStripNumber" + subDetName[i];
00798     tmp_prof = new TProfile(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5);
00799     tmp = dqmStore->bookProfile(histoName.c_str(), tmp_prof);
00800     pfxDistanceVsStripNumber.push_back(tmp->getTProfile());
00801     pfxDistanceVsStripNumber[i]->GetXaxis()->SetTitle("Strip");
00802     pfxDistanceVsStripNumber[i]->GetYaxis()->SetTitle("Distance");
00803 
00804     histoName = "projXDistanceVsStripNumber" + subDetName[i];
00805     histoTitle = "Number of hot strips vs. strip number";
00806     if(i!=0)
00807       histoTitle += " in " + subDetName[i];
00808     tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5);
00809     projXDistanceVsStripNumber.push_back(tmp->getTH1F());
00810     projXDistanceVsStripNumber[i]->GetXaxis()->SetTitle("Strip");
00811     projXDistanceVsStripNumber[i]->GetYaxis()->SetTitle("N_{hot}");
00812     
00813     histoName = "projYDistanceVsStripNumber" + subDetName[i];
00814     histoTitle = "Distribution of distance between hot strips";
00815     if(i!=0)
00816       histoTitle += " in " + subDetName[i];
00817     tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 999, 0.5, 999.5);
00818     projYDistanceVsStripNumber.push_back(tmp->getTH1F());
00819     projYDistanceVsStripNumber[i]->GetXaxis()->SetTitle("Distance");
00820     projYDistanceVsStripNumber[i]->GetYaxis()->SetTitle("N_{strips}");
00821     
00822     //
00823     histoName = "occupancyVsStripNumber" + subDetName[i];
00824     histoTitle = "Occupancy of strips vs. strip number";
00825     if(i!=0)
00826       histoTitle += " in " + subDetName[i];
00827     tmp = dqmStore->book2D(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5, 1000, -8.,0.);
00828     occupancyVsStripNumber.push_back(tmp->getTH2F());
00829     
00830     histoName = "pfxOccupancyVsStripNumber" + subDetName[i];
00831     tmp_prof = new TProfile(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5);
00832     tmp = dqmStore->bookProfile(histoName.c_str(), tmp_prof);
00833     pfxOccupancyVsStripNumber.push_back(tmp->getTProfile());
00834     pfxOccupancyVsStripNumber[i]->GetXaxis()->SetTitle("Strip");
00835     pfxOccupancyVsStripNumber[i]->GetYaxis()->SetTitle("log_{10}(Occupancy)");
00836     
00837     histoName = "projYOccupancyVsStripNumber" + subDetName[i];
00838     histoTitle = "Distribution of strip occupancy";
00839     if(i!=0)
00840       histoTitle += " in " + subDetName[i];
00841     tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 1000, -8., 0.);
00842     projYOccupancyVsStripNumber.push_back(tmp->getTH1F());
00843     projYOccupancyVsStripNumber[i]->GetXaxis()->SetTitle("log_{10}(Occupancy)");
00844     projYOccupancyVsStripNumber[i]->GetYaxis()->SetTitle("N_{strips}");
00845     
00846     //
00847     histoName = "occupancyHotStripsVsStripNumber" + subDetName[i];
00848     histoTitle = "Occupancy of hot strips vs. strip number";
00849     if(i!=0)
00850       histoTitle += " in " + subDetName[i];
00851     tmp = dqmStore->book2D(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5, 1000, -8., 0.);
00852     occupancyHotStripsVsStripNumber.push_back(tmp->getTH2F());
00853     
00854     histoName = "pfxOccupancyHotStripsVsStripNumber" + subDetName[i];
00855     tmp_prof = new TProfile(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5);
00856     tmp = dqmStore->bookProfile(histoName.c_str(), tmp_prof);
00857     pfxOccupancyHotStripsVsStripNumber.push_back(tmp->getTProfile());
00858     pfxOccupancyHotStripsVsStripNumber[i]->GetXaxis()->SetTitle("Strip");
00859     pfxOccupancyHotStripsVsStripNumber[i]->GetYaxis()->SetTitle("log_{10}(Occupancy)");
00860     
00861     histoName = "projYOccupancyHotStripsVsStripNumber" + subDetName[i];
00862     histoTitle = "Distribution of hot strip occupancy";
00863     if(i!=0)
00864       histoTitle += " in " + subDetName[i];
00865     tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 1000, -8., 0.);
00866     projYOccupancyHotStripsVsStripNumber.push_back(tmp->getTH1F());
00867     projYOccupancyHotStripsVsStripNumber[i]->GetXaxis()->SetTitle("log_{10}(Occupancy)");
00868     projYOccupancyHotStripsVsStripNumber[i]->GetYaxis()->SetTitle("N_{strips}");
00869     
00870     //
00871     histoName = "occupancyGoodStripsVsStripNumber" + subDetName[i];
00872     histoTitle = "Occupancy of good strips vs. strip number";
00873     if(i!=0)
00874       histoTitle += " in " + subDetName[i];
00875     tmp = dqmStore->book2D(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5, 1000, -8., 0.);
00876     occupancyGoodStripsVsStripNumber.push_back(tmp->getTH2F());
00877     
00878     histoName = "pfxOccupancyGoodStripsVsStripNumber" + subDetName[i];
00879     tmp_prof = new TProfile(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5);
00880     tmp = dqmStore->bookProfile(histoName.c_str(), tmp_prof);
00881     pfxOccupancyGoodStripsVsStripNumber.push_back(tmp->getTProfile());
00882     pfxOccupancyGoodStripsVsStripNumber[i]->GetXaxis()->SetTitle("Strip");
00883     pfxOccupancyGoodStripsVsStripNumber[i]->GetYaxis()->SetTitle("log_{10}(Occupancy)");
00884     
00885     histoName = "projYOccupancyGoodStripsVsStripNumber" + subDetName[i];
00886     histoTitle = "Distribution of good strip occupancy";
00887     if(i!=0)
00888       histoTitle += " in " + subDetName[i];
00889     tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 1000, -8., 0.);
00890     projYOccupancyGoodStripsVsStripNumber.push_back(tmp->getTH1F());
00891     projYOccupancyGoodStripsVsStripNumber[i]->GetXaxis()->SetTitle("log_{10}(Occupancy)");
00892     projYOccupancyGoodStripsVsStripNumber[i]->GetYaxis()->SetTitle("N_{strips}");
00893     
00894     //
00895     histoName = "poissonProbVsStripNumber" + subDetName[i];
00896     histoTitle = "Poisson probability of strips vs. strip number";
00897     if(i!=0)
00898       histoTitle += " in " + subDetName[i];
00899     tmp = dqmStore->book2D(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5, 1000, -18., 0.);
00900     poissonProbVsStripNumber.push_back(tmp->getTH2F());
00901     
00902     histoName = "pfxPoissonProbVsStripNumber" + subDetName[i];
00903     tmp_prof = new TProfile(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5);
00904     tmp = dqmStore->bookProfile(histoName.c_str(), tmp_prof);
00905     pfxPoissonProbVsStripNumber.push_back(tmp->getTProfile());
00906     pfxPoissonProbVsStripNumber[i]->GetXaxis()->SetTitle("Strip");
00907     pfxPoissonProbVsStripNumber[i]->GetYaxis()->SetTitle("log_{10}(Probability)");
00908     
00909     histoName = "projYPoissonProbVsStripNumber" + subDetName[i];
00910     histoTitle = "Distribution of strip Poisson probability";
00911     if(i!=0)
00912       histoTitle += " in " + subDetName[i];
00913     tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 1000, -18., 0.);
00914     projYPoissonProbVsStripNumber.push_back(tmp->getTH1F());
00915     projYPoissonProbVsStripNumber[i]->GetXaxis()->SetTitle("log_{10}(Probability)");
00916     projYPoissonProbVsStripNumber[i]->GetYaxis()->SetTitle("N_{strips}");
00917     
00918     //
00919     histoName = "poissonProbHotStripsVsStripNumber" + subDetName[i];
00920     histoTitle = "Poisson probability of hot strips vs. strip number";
00921     if(i!=0)
00922       histoTitle += " in " + subDetName[i];
00923     tmp = dqmStore->book2D(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5, 1000, -18., 0.);
00924     poissonProbHotStripsVsStripNumber.push_back(tmp->getTH2F());
00925     
00926     histoName = "pfxPoissonProbHotStripsVsStripNumber" + subDetName[i];
00927     tmp_prof = new TProfile(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5);
00928     tmp = dqmStore->bookProfile(histoName.c_str(), tmp_prof);
00929     pfxPoissonProbHotStripsVsStripNumber.push_back(tmp->getTProfile());
00930     pfxPoissonProbHotStripsVsStripNumber[i]->GetXaxis()->SetTitle("Strip");
00931     pfxPoissonProbHotStripsVsStripNumber[i]->GetYaxis()->SetTitle("log_{10}(Probability)");
00932     
00933     histoName = "projYPoissonProbHotStripsVsStripNumber" + subDetName[i];
00934     histoTitle = "Distribution of hot strip Poisson probability";
00935     if(i!=0)
00936       histoTitle += " in " + subDetName[i];
00937     tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 1000, -18., 0.);
00938     projYPoissonProbHotStripsVsStripNumber.push_back(tmp->getTH1F());
00939     projYPoissonProbHotStripsVsStripNumber[i]->GetXaxis()->SetTitle("log_{10}(Probability)");
00940     projYPoissonProbHotStripsVsStripNumber[i]->GetYaxis()->SetTitle("N_{strips}");
00941     
00942     //
00943     histoName = "poissonProbGoodStripsVsStripNumber" + subDetName[i];
00944     histoTitle = "Poisson probability of good strips vs. strip number";
00945     if(i!=0)
00946       histoTitle += " in " + subDetName[i];
00947     tmp = dqmStore->book2D(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5, 1000, -18., 0.);
00948     poissonProbGoodStripsVsStripNumber.push_back(tmp->getTH2F());
00949     
00950     histoName = "pfxPoissonProbGoodStripsVsStripNumber" + subDetName[i];
00951     tmp_prof = new TProfile(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5);
00952     tmp = dqmStore->bookProfile(histoName.c_str(), tmp_prof);
00953     pfxPoissonProbGoodStripsVsStripNumber.push_back(tmp->getTProfile());
00954     pfxPoissonProbGoodStripsVsStripNumber[i]->GetXaxis()->SetTitle("Strip");
00955     pfxPoissonProbGoodStripsVsStripNumber[i]->GetYaxis()->SetTitle("log_{10}(Probability)");
00956     
00957     histoName = "projYPoissonProbGoodStripsVsStripNumber" + subDetName[i];
00958     histoTitle = "Distribution of good strip Poisson probability";
00959     if(i!=0)
00960       histoTitle += " in " + subDetName[i];
00961     tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 1000, -18., 0.);
00962     projYPoissonProbGoodStripsVsStripNumber.push_back(tmp->getTH1F());
00963     projYPoissonProbGoodStripsVsStripNumber[i]->GetXaxis()->SetTitle("log_{10}(Probability)");
00964     projYPoissonProbGoodStripsVsStripNumber[i]->GetYaxis()->SetTitle("N_{strips}");
00965 
00966     //
00967     histoName = "nHitsVsStripNumber" + subDetName[i];
00968     histoTitle = "NHits in strips vs. strip number";
00969     if(i!=0)
00970       histoTitle += " in " + subDetName[i];
00971     tmp = dqmStore->book2D(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5, 10000, -0.5, 9999.5);
00972     nHitsVsStripNumber.push_back(tmp->getTH2F());
00973     
00974     histoName = "pfxNHitsVsStripNumber" + subDetName[i];
00975     tmp_prof = new TProfile(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5);
00976     tmp = dqmStore->bookProfile(histoName.c_str(), tmp_prof);
00977     pfxNHitsVsStripNumber.push_back(tmp->getTProfile());
00978     
00979     histoName = "projXNHitsVsStripNumber" + subDetName[i];
00980     histoTitle = "Cumulative nHits in strips vs. strip number";
00981     if(i!=0)
00982       histoTitle += " in " + subDetName[i];
00983     tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5);
00984     projXNHitsVsStripNumber.push_back(tmp->getTH1F());
00985     
00986     histoName = "projYNHitsVsStripNumber" + subDetName[i];
00987     histoTitle = "Distribution of nHits for all strips";
00988     if(i!=0)
00989       histoTitle += " in " + subDetName[i];
00990     tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 10000, -0.5, 9999.5);
00991     projYNHitsVsStripNumber.push_back(tmp->getTH1F());
00992     projYNHitsVsStripNumber[i]->GetXaxis()->SetTitle("N_{hits}");
00993     projYNHitsVsStripNumber[i]->GetYaxis()->SetTitle("N_{strips}");
00994     
00995     //
00996     histoName = "nHitsHotStripsVsStripNumber" + subDetName[i];
00997     histoTitle = "NHits in hot strips vs. strip number";
00998     if(i!=0)
00999       histoTitle += " in " + subDetName[i];
01000     tmp = dqmStore->book2D(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5, 10000, -0.5, 9999.5);
01001     nHitsHotStripsVsStripNumber.push_back(tmp->getTH2F());
01002     
01003     histoName = "pfxNHitsHotStripsVsStripNumber" + subDetName[i];
01004     tmp_prof = new TProfile(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5);
01005     tmp = dqmStore->bookProfile(histoName.c_str(), tmp_prof);
01006     pfxNHitsHotStripsVsStripNumber.push_back(tmp->getTProfile());
01007     
01008     histoName = "projXNHitsHotStripsVsStripNumber" + subDetName[i];
01009     histoTitle = "Cumulative nHits in hot strips vs. strip number";
01010     if(i!=0)
01011       histoTitle += " in " + subDetName[i];
01012     tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5);
01013     projXNHitsHotStripsVsStripNumber.push_back(tmp->getTH1F());
01014     
01015     histoName = "projYNHitsHotStripsVsStripNumber" + subDetName[i];
01016     histoTitle = "Distribution of nHits for hot strips";
01017     if(i!=0)
01018       histoTitle += " in " + subDetName[i];
01019     tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 10000, -0.5, 9999.5);
01020     projYNHitsHotStripsVsStripNumber.push_back(tmp->getTH1F());
01021     projYNHitsHotStripsVsStripNumber[i]->GetXaxis()->SetTitle("N_{hits}");
01022     projYNHitsHotStripsVsStripNumber[i]->GetYaxis()->SetTitle("N_{strips}");
01023     
01024     //
01025     histoName = "nHitsGoodStripsVsStripNumber" + subDetName[i];
01026     histoTitle = "NHits in good strips vs. strip number";
01027     if(i!=0)
01028       histoTitle += " in " + subDetName[i];
01029     tmp = dqmStore->book2D(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5, 10000, -0.5, 9999.5);
01030     nHitsGoodStripsVsStripNumber.push_back(tmp->getTH2F());
01031     
01032     histoName = "pfxNHitsGoodStripsVsStripNumber" + subDetName[i];
01033     tmp_prof = new TProfile(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5);
01034     tmp = dqmStore->bookProfile(histoName.c_str(), tmp_prof);
01035     pfxNHitsGoodStripsVsStripNumber.push_back(tmp->getTProfile());
01036     
01037     histoName = "projXNHitsGoodStripsVsStripNumber" + subDetName[i];
01038     histoTitle = "Cumulative nHits in good strips vs. strip number";
01039     if(i!=0)
01040       histoTitle += " in " + subDetName[i];
01041     tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 768, 0.5, 768.5);
01042     projXNHitsGoodStripsVsStripNumber.push_back(tmp->getTH1F());
01043     
01044     histoName = "projYNHitsGoodStripsVsStripNumber" + subDetName[i];
01045     histoTitle = "Distribution of nHits for good strips";
01046     if(i!=0)
01047       histoTitle += " in " + subDetName[i];
01048     tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 10000, -0.5, 9999.5);
01049     projYNHitsGoodStripsVsStripNumber.push_back(tmp->getTH1F());
01050     projYNHitsGoodStripsVsStripNumber[i]->GetXaxis()->SetTitle("N_{hits}");
01051     projYNHitsGoodStripsVsStripNumber[i]->GetYaxis()->SetTitle("N_{strips}");
01052 
01053     for(unsigned int j = 0; j <= nLayers[i]; j++)
01054     {
01055       histoName = "medianVsAbsoluteOccupancy" + subDetName[i];
01056       if(j!=0)
01057       {
01058         oss.str("");
01059         oss << j;
01060         histoName += layerName[i] + oss.str();
01061       }
01062       histoTitle = "Median APV occupancy vs. absolute APV occupancy";
01063       if(i!=0)
01064         histoTitle += " in " + subDetName[i];
01065       if(j!=0)
01066       {
01067         histoTitle += " " + layerName[i] + " " + oss.str();
01068       }
01069       tmp = dqmStore->book2D(histoName.c_str(), histoTitle.c_str(), 1000, 0., 6., 1000, -1., 3.);
01070       medianVsAbsoluteOccupancy[i][j] = tmp->getTH2F();
01071       medianVsAbsoluteOccupancy[i][j]->Rebin2D(10,10);
01072       medianVsAbsoluteOccupancy[i][j]->GetXaxis()->SetTitle("log_{10}(Abs. Occupancy)");
01073       medianVsAbsoluteOccupancy[i][j]->GetYaxis()->SetTitle("log_{10}(Median Occupancy)");
01074       //
01075       histoName = "medianOccupancy" + subDetName[i];
01076       if(j!=0)
01077       {
01078         oss.str("");
01079         oss << j;
01080         histoName += layerName[i] + oss.str();
01081       }
01082       histoTitle = "Median APV occupancy";
01083       if(i!=0)
01084         histoTitle += " in " + subDetName[i];
01085       if(j!=0)
01086       {
01087         histoTitle += " " + layerName[i] + " " + oss.str();
01088       }
01089       tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 1000, -1., 3.);
01090       medianOccupancy[i][j] = tmp->getTH1F();
01091       medianOccupancy[i][j]->GetXaxis()->SetTitle("log_{10}(Occupancy)");
01092       medianOccupancy[i][j]->GetYaxis()->SetTitle("APVs");
01093       //
01094       histoName = "absoluteOccupancy" + subDetName[i];
01095       if(j!=0)
01096       {
01097         oss.str("");
01098         oss << j;
01099         histoName += layerName[i] + oss.str();
01100       }
01101       histoTitle = "Absolute APV occupancy";
01102       if(i!=0)
01103         histoTitle += " in " + subDetName[i];
01104       if(j!=0)
01105       {
01106         histoTitle += " " + layerName[i] + " " + oss.str();
01107       }
01108       tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 1000, 0., 6.);
01109       absoluteOccupancy[i][j] = tmp->getTH1F();
01110       absoluteOccupancy[i][j]->GetXaxis()->SetTitle("log_{10}(Occupancy)");
01111       absoluteOccupancy[i][j]->GetYaxis()->SetTitle("APVs");
01112     }
01113   }
01114 }
01115 
01116 void SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy::fillStripDQMHistograms()
01117 {
01118   double logStripOccupancy = -1;
01119   double logPoissonProb = -1;
01120 
01121   if (singleStripOccupancy>0) logStripOccupancy = log10(singleStripOccupancy);
01122   if (poissonProb>0) logPoissonProb = log10(fabs(poissonProb));
01123 
01124   occupancyVsStripNumber[0]->Fill(strip_number,logStripOccupancy);
01125   occupancyVsStripNumber[subdetid-2]->Fill(strip_number,logStripOccupancy);
01126   poissonProbVsStripNumber[0]->Fill(strip_number,logPoissonProb);
01127   poissonProbVsStripNumber[subdetid-2]->Fill(strip_number,logPoissonProb);
01128   nHitsVsStripNumber[0]->Fill(strip_number,stripHits);
01129   nHitsVsStripNumber[subdetid-2]->Fill(strip_number,stripHits);
01130        
01131   if(isHot)
01132     {
01133       vHotStripsInModule.push_back(strip_number);
01134       occupancyHotStripsVsStripNumber[0]->Fill(strip_number,logStripOccupancy);
01135       occupancyHotStripsVsStripNumber[subdetid-2]->Fill(strip_number,logStripOccupancy);
01136       poissonProbHotStripsVsStripNumber[0]->Fill(strip_number,logPoissonProb);
01137       poissonProbHotStripsVsStripNumber[subdetid-2]->Fill(strip_number,logPoissonProb);
01138       nHitsHotStripsVsStripNumber[0]->Fill(strip_number,stripHits);
01139       nHitsHotStripsVsStripNumber[subdetid-2]->Fill(strip_number,stripHits);
01140     }
01141   else
01142     {
01143       occupancyGoodStripsVsStripNumber[0]->Fill(strip_number,logStripOccupancy);
01144       occupancyGoodStripsVsStripNumber[subdetid-2]->Fill(strip_number,logStripOccupancy);
01145       poissonProbGoodStripsVsStripNumber[0]->Fill(strip_number,logPoissonProb);
01146       poissonProbGoodStripsVsStripNumber[subdetid-2]->Fill(strip_number,logPoissonProb);
01147       nHitsGoodStripsVsStripNumber[0]->Fill(strip_number,stripHits);
01148       nHitsGoodStripsVsStripNumber[subdetid-2]->Fill(strip_number,stripHits);
01149     }
01150 }