CMS 3D CMS Logo

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

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