CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/CalibTracker/SiPixelTools/plugins/SiPixelDQMRocLevelAnalyzer.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiPixelTools/interface/SiPixelDQMRocLevelAnalyzer.h"
00002 
00003 SiPixelDQMRocLevelAnalyzer::SiPixelDQMRocLevelAnalyzer(const edm::ParameterSet& iConfig):conf_(iConfig)
00004 {
00005 
00006 
00007 }
00008 
00009 
00010 SiPixelDQMRocLevelAnalyzer::~SiPixelDQMRocLevelAnalyzer()
00011 {
00012 
00013 
00014 }
00015 
00016 // ------------ method called to for each event  ------------
00017 void
00018 SiPixelDQMRocLevelAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00019 {
00020    using namespace edm;
00021 
00022 
00023 #ifdef THIS_IS_AN_EVENT_EXAMPLE
00024    Handle<ExampleData> pIn;
00025    iEvent.getByLabel("example",pIn);
00026 #endif
00027    
00028 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
00029    ESHandle<SetupData> pSetup;
00030    iSetup.get<SetupRecord>().get(pSetup);
00031 #endif
00032 }
00033 
00034 
00035 // ------------ method called once each job just before starting event loop  ------------
00036 void 
00037 SiPixelDQMRocLevelAnalyzer::beginJob()
00038 {
00039   std::string filename = conf_.getUntrackedParameter<std::string>("fileName");
00040   bRS = conf_.getUntrackedParameter<bool>("barrelRocStud");
00041   fRS = conf_.getUntrackedParameter<bool>("endcapRocStud");
00042   bPixelAlive = conf_.getUntrackedParameter<bool>("pixelAliveStudy");
00043   double pixelAliveThresh = conf_.getUntrackedParameter<double>("pixelAliveThreshold");
00044   bool bThreshold = conf_.getUntrackedParameter<bool>("thresholdStudy");
00045   bool bNoise = conf_.getUntrackedParameter<bool>("noiseStudy");
00046   bool bGain = conf_.getUntrackedParameter<bool>("gainStudy");
00047   bool bPedestal = conf_.getUntrackedParameter<bool>("pedestalStudy");
00048 
00049   if(!bRS && !fRS) return;
00050 
00051   //Open file and get MEs
00052   dbe = edm::Service<DQMStore>().operator->();
00053   dbe->open(filename);
00054   mes = dbe->getAllContents("");
00055   std::cout << "found " << mes.size() << " monitoring elements!" << std::endl;
00056 
00057 
00058   //BARREL
00059   if(bRS){
00060     //PIXELALIVE
00061     if(bPixelAlive){
00062       bhPixelAlive = fs_->make<TH1F>("bpixAlive","PixelAliveSummary_mean_Barrel",11520, 0., 11520.);
00063       bhPixelAlive_dist = fs_->make<TH1F>("bpixAliveDist","Mean PixelAliveSummary_mean_Barrel Disbribution", 110, 0., 1.1);
00064     }
00065     //THRESHOLD
00066     if(bThreshold){
00067       bhThresholdMean = fs_->make<TH1F>("bthreshMean","ScurveThresholdSummary_mean_Barrel",11520,0.,11520.);
00068       bhThresholdMean_dist = fs_->make<TH1F>("bthreshMeanDist","Mean ScurveThresholdSummary_mean_Barrel Distribution",600,0.,150.);
00069       bhThresholdRMS = fs_->make<TH1F>("bthreshRMS","ScurveThresholdSummary_RMS_Barrel",11520,0.,11520.);
00070       bhThresholdRMS_dist = fs_->make<TH1F>("bthreshRMSDist","Mean ScurveThresholdSummary_RMS_Barrel Distribution",800,0.,80.);
00071     }
00072     //NOISE
00073     if(bNoise){
00074       bhNoiseMean = fs_->make<TH1F>("bnoiseMean","ScurveSigmasSummary_mean_Barrel",11520,0.,11520.);
00075       bhNoiseMean_dist = fs_->make<TH1F>("bnoiseMeanDist","Mean ScurveSigmasSummary_mean_Barrel Distribution",256,-2.,6.);
00076       bhNoiseRMS = fs_->make<TH1F>("bnoiseRMS","ScurveSigmasSummary_RMS_Barrel",11520,0.,11520.);
00077       bhNoiseRMS_dist = fs_->make<TH1F>("bnoiseRMSDist","Mean ScurveSigmasSummary_RMS_Barrel Distribution",768,0.,8.);
00078     }
00079     //GAIN
00080     if(bGain){
00081       bhGainMean = fs_->make<TH1F>("bgainMean","ScurveGainSummary_mean_Barrel",11520,0.,11520.);
00082       bhGainMean_dist = fs_->make<TH1F>("bgainMeanDist","Mean ScurveGainSummary_mean_Barrel Distribution",80,0.,8.);
00083       bhGainRMS = fs_->make<TH1F>("bgainRMS","ScurveGainSummary_RMS_Barrel",11520,0.,11520.);
00084       bhGainRMS_dist = fs_->make<TH1F>("bgainRMSDist","Mean ScurveGainSummary_RMS_Barrel Distribution",100,0.,10.);
00085     }
00086     //PEDESTAL
00087     if(bPedestal){
00088       bhPedestalMean = fs_->make<TH1F>("bpedestalMean","ScurvePedestalSummary_mean_Barrel",11520,0.,11520.);
00089       bhPedestalMean_dist = fs_->make<TH1F>("bpedestalMeanDist","Mean ScurvePedestalSummary_mean_Barrel Distribution",600,0.,300.);
00090       bhPedestalRMS = fs_->make<TH1F>("bpedestalRMS","ScurvePedestalSummary_RMS_Barrel",11520,0.,11520.);
00091       bhPedestalRMS_dist = fs_->make<TH1F>("bpedestalRMSDist","Mean ScurvePedestalSummary_RMS_Barrel Distribution",1000,0.,100.);
00092     }
00093   }
00094 
00095   //ENDCAP
00096   if(fRS){
00097     //PIXELALIVE
00098     if(bPixelAlive){
00099       ehPixelAlive = fs_->make<TH1F>("fpixAlive","PixelAliveSummary_mean_Endcap",4320, 0., 4320.);
00100       ehPixelAlive_dist = fs_->make<TH1F>("fpixAliveDist","Mean PixelAliveSummary_mean_Endcap Disbribution", 110, 0., 1.1);
00101     }
00102     //THRESHOLD
00103     if(bThreshold){
00104       ehThresholdMean = fs_->make<TH1F>("fthreshMean","ScurveThresholdSummary_mean_Endcap",4320,0.,4320.);
00105       ehThresholdMean_dist = fs_->make<TH1F>("fthreshMeanDist","Mean ScurveThresholdSummary_mean_Endcap Distribution",600,0.,150.);
00106       ehThresholdRMS = fs_->make<TH1F>("fthreshRMS","ScurveThresholdSummary_RMS_Endcap",4320,0.,4320.);
00107       ehThresholdRMS_dist = fs_->make<TH1F>("fthreshRMSDist","Mean ScurveThresholdSummary_RMS_Endcap Distribution",800,0.,80.);
00108     }
00109     //NOISE
00110     if(bNoise){
00111       ehNoiseMean = fs_->make<TH1F>("fnoiseMean","ScurveSigmasSummary_mean_Endcap",4320,0.,4320.);
00112       ehNoiseMean_dist = fs_->make<TH1F>("fnoiseMeanDist","Mean ScurveSigmasSummary_mean_Endcap Distribution",256,-2.,6.);
00113       ehNoiseRMS = fs_->make<TH1F>("fnoiseRMS","ScurveSigmasSummary_RMS_Endcap",4320,0.,4320.);
00114       ehNoiseRMS_dist = fs_->make<TH1F>("fnoiseRMSDist","Mean ScurveSigmasSummary_RMS_Endcap Distribution",384,0.,4.);
00115     }
00116     //GAIN
00117     if(bGain){
00118       ehGainMean = fs_->make<TH1F>("fgainMean","ScurveGainSummary_mean_Endcap",4320,0.,4320.);
00119       ehGainMean_dist = fs_->make<TH1F>("fgainMeanDist","Mean ScurveGainSummary_mean_Endcap Distribution",600,0.,150.);
00120       ehGainRMS = fs_->make<TH1F>("fgainRMS","ScurveGainSummary_RMS_Endcap",4320,0.,4320.);
00121       ehGainRMS_dist = fs_->make<TH1F>("fgainRMSDist","Mean ScurveGainSummary_RMS_Endcap Distribution",800,0.,80.);
00122     }
00123     //PEDESTAL
00124     if(bPedestal){
00125       ehPedestalMean = fs_->make<TH1F>("fpedestalMean","ScurvePedestalSummary_mean_Endcap",4320,0.,4320.);
00126       ehPedestalMean_dist = fs_->make<TH1F>("fpedestalMeanDist","Mean ScurvePedestalSummary_mean_Endcap Distribution",600,0.,150.);
00127       ehPedestalRMS = fs_->make<TH1F>("fpedestalRMS","ScurvePedestalSummary_RMS_Endcap",4320,0.,4320.);
00128       ehPedestalRMS_dist = fs_->make<TH1F>("fpedestalRMSDist","Mean ScurvePedestalSummary_RMS_Endcap Distribution",800,0.,80.);
00129     }
00130   }
00131   //PIXELALIVE
00132   if(bPixelAlive){
00133     RocSummary("pixelAlive_siPixelCalibDigis_");
00134     if(bRS){
00135       FillRocLevelHistos(bhPixelAlive, bhPixelAlive_dist, vbpixCN, vbpixM);
00136 
00137       //print a list of pixels with pixelAlive quantity below pixelAliveThresh
00138       for(unsigned int i=0; i<vbpixCN.size(); i++){
00139         
00140         if(vbpixM[i]<pixelAliveThresh){
00141           double temp = vbpixCN[i];
00142           int shell = (int)((temp-1)/2880); //0 mi, 1 mo, 2 pi, 3 po
00143           temp -= shell *2880;
00144           int lay = 1;
00145           if(temp>576){
00146             temp -= 576; lay++; 
00147           } 
00148           if(temp>960){
00149             temp -= 960; lay++;
00150           }
00151           int lad = 1; 
00152           if(temp > 32){
00153             temp -=32; lad++;
00154           }
00155           while(temp>64){
00156             temp -=64; lad++;
00157           }
00158           int mod =1; int modsize = 16;
00159           if(lad ==1 || (lay == 1 && lad == 10) || (lay == 2 && lad == 16) || (lay == 3 && lad == 22) ) modsize = 8; 
00160           while(temp>modsize){
00161             temp -= modsize; mod ++;
00162           }
00163           std::cout << vbpixCN[i] << " " << vbpixM[i] << ":\n";
00164           std::cout << "Shell "; 
00165           switch(shell){
00166           case 0: std::cout << "mI"; break;
00167           case 1: std::cout << "mO"; break;
00168           case 2: std::cout << "pI"; break;
00169           case 3: std::cout << "pO"; break;
00170           } 
00171           std::cout << " Lay" << lay << " Lad" << lad << " Mod" << mod << " Chip" << temp << "\n\n"; 
00172           
00173         }
00174         
00175       }
00176     }
00177     if(fRS){
00178       FillRocLevelHistos(ehPixelAlive, ehPixelAlive_dist, vfpixCN, vfpixM);
00179       //print a list of pixels with pixelAlive quantity below pixelAliveThresh
00180       for(unsigned int i=0; i<vfpixCN.size(); i++){
00181         if(vfpixM[i]<pixelAliveThresh){
00182           double temp = vfpixCN[i];
00183           int hcyl = (int)((temp-1)/1080); //0 mi, 1 mo, 2 pi, 3 po
00184           temp -= hcyl *1080; 
00185           int disk = 1; 
00186           if(temp > 540){
00187             temp -= 540; disk++;
00188           }
00189           int blade = 1;
00190           while(temp>45){
00191             temp-=45; blade++;
00192           }
00193           int panel = 1, mod = 1;
00194           if(temp<22){
00195             //panel 1
00196             if(temp>16){
00197               temp-=16; mod = 4;
00198             }
00199             else if(temp>8){
00200               temp-=8; mod = 3;
00201             }
00202             else if(temp>2){
00203               temp-=2; mod = 2;
00204             }
00205           } 
00206           else{
00207             //panel 2
00208             temp-=21; panel++;
00209             if(temp>14){
00210               temp-=14; mod = 3;
00211             }
00212             else if(temp>6){
00213               temp-=6; mod = 2;
00214             }
00215           }
00216           
00217           std::cout << vfpixCN[i] << " " << vfpixM[i] << ":\n";
00218           std::cout << "HalfCylinder "; 
00219           switch(hcyl){
00220           case 0: std::cout << "mI"; break;
00221           case 1: std::cout << "mO"; break;
00222           case 2: std::cout << "pI"; break;
00223           case 3: std::cout << "pO"; break;
00224           } 
00225           std::cout << " Disk" << disk << " Blade" << blade << " Panel" << panel << " Mod" << mod << " Chip" << temp << "\n\n"; 
00226           
00227         }
00228       }
00229     }
00230 
00231   }
00232   //THRESHOLD
00233   if(bThreshold) {
00234     vbpixCN.clear(); 
00235     vbpixM.clear();
00236     vbpixSD.clear();
00237     vfpixCN.clear(); 
00238     vfpixM.clear();
00239     vfpixSD.clear();
00240 
00241     RocSummary("ScurveThresholds_siPixelCalibDigis_");
00242     if(bRS){
00243       FillRocLevelHistos(bhThresholdMean, bhThresholdMean_dist, vbpixCN, vbpixM);
00244       FillRocLevelHistos(bhThresholdRMS, bhThresholdRMS_dist, vbpixCN, vbpixSD);
00245   }
00246     if(fRS){
00247       FillRocLevelHistos(ehThresholdMean, ehThresholdMean_dist, vfpixCN, vfpixM);
00248       FillRocLevelHistos(ehThresholdRMS, ehThresholdRMS_dist, vfpixCN, vfpixSD);
00249     }
00250   }
00251   //NOISE
00252   if(bNoise){
00253     vbpixCN.clear(); 
00254     vbpixM.clear();
00255     vbpixSD.clear();
00256     vfpixCN.clear(); 
00257     vfpixM.clear();
00258     vfpixSD.clear();
00259 
00260     RocSummary("ScurveSigmas_siPixelCalibDigis_");
00261     if(bRS){
00262       FillRocLevelHistos(bhNoiseMean, bhNoiseMean_dist, vbpixCN, vbpixM);
00263       FillRocLevelHistos(bhNoiseRMS, bhNoiseRMS_dist, vbpixCN, vbpixSD);
00264     }
00265     if(fRS){
00266       FillRocLevelHistos(ehNoiseMean, ehNoiseMean_dist, vfpixCN, vfpixM);
00267       FillRocLevelHistos(ehNoiseRMS, ehNoiseRMS_dist, vfpixCN, vfpixSD);
00268     }
00269   }
00270   //GAIN
00271   if(bGain){
00272     vbpixCN.clear(); 
00273     vbpixM.clear();
00274     vbpixSD.clear();
00275     vfpixCN.clear(); 
00276     vfpixM.clear();
00277     vfpixSD.clear();
00278 
00279     RocSummary("Gain2d_siPixelCalibDigis_");
00280     if(bRS){
00281       FillRocLevelHistos(bhGainMean, bhGainMean_dist, vbpixCN, vbpixM);
00282       FillRocLevelHistos(bhGainRMS, bhGainRMS_dist, vbpixCN, vbpixSD);
00283     }
00284     if(fRS){
00285       FillRocLevelHistos(ehGainMean, ehGainMean_dist, vfpixCN, vfpixM);
00286       FillRocLevelHistos(ehGainRMS, ehGainRMS_dist, vfpixCN, vfpixSD);
00287     }
00288   }
00289   //PEDESTAL
00290   if(bPedestal){
00291     vbpixCN.clear(); 
00292     vbpixM.clear();
00293     vbpixSD.clear();
00294     vfpixCN.clear(); 
00295     vfpixM.clear();
00296     vfpixSD.clear();
00297 
00298     RocSummary("Pedestal2d_siPixelCalibDigis_");
00299     if(bRS){
00300       FillRocLevelHistos(bhPedestalMean, bhPedestalMean_dist, vbpixCN, vbpixM);
00301       FillRocLevelHistos(bhPedestalRMS, bhPedestalRMS_dist, vbpixCN, vbpixSD);
00302     }
00303     if(fRS){
00304       FillRocLevelHistos(ehPedestalMean, ehPedestalMean_dist, vfpixCN, vfpixM);
00305       FillRocLevelHistos(ehPedestalRMS, ehPedestalRMS_dist, vfpixCN, vfpixSD);
00306     }
00307   }
00308 }
00309 
00310 // ------------ method called once each job just after ending the event loop  ------------
00311 void 
00312 SiPixelDQMRocLevelAnalyzer::endJob() {
00313 }
00314 
00315 void 
00316 SiPixelDQMRocLevelAnalyzer::RocSummary(std::string tagname){
00317     
00318   int maxcrow, maxccol;
00319   std::string name, path = "first"; 
00320   std::string oldPath = ""; 
00321   int moduleNumber = 0;
00322   int bchipNumber = 0; 
00323   int fchipNumber = 0;
00324   bool bbarrel = false, bforward = false, bhalfMod = false, bwasHM = false;
00325   bool bPFFM = false;
00326   bool bMNCS = false; 
00327   int panelNumber = -1;
00328 
00329   for(std::vector<MonitorElement*>::const_iterator ime = mes.begin(); ime!=mes.end(); ++ime){
00330     bwasHM = bhalfMod;
00331     //set default values
00332     bMNCS = false;
00333     bbarrel = false; bforward = false; bhalfMod = false;
00334     //set name, (old) path
00335     name = (*ime)->getName();
00336     oldPath = path; 
00337     path = (*ime)->getPathname();
00338  
00339     //determine module number if any
00340     if(path.find("Module_")<path.size()){
00341       if(path!=oldPath) {
00342         moduleNumber++;
00343         if(moduleNumber!=1) bMNCS = true;
00344         
00345       } 
00346     }
00347     else {
00348       if(moduleNumber>0) bMNCS = true;
00349       moduleNumber =0;
00350     }
00351 
00352     
00353     //find out location (barrel (hm), endcap)
00354     if(path.find("Barrel/") < path.size()) {
00355       bbarrel = true;
00356       if(path.find("H/") < path.size()) bhalfMod = true;
00357       }
00358     if(path.find("Endcap/") < path.size()) {
00359       bforward = true;
00360       panelNumber = -1;
00361       if(path.find("Panel_1") < path.size()) panelNumber = 1;
00362       if(path.find("Panel_2") < path.size()) panelNumber = 2; 
00363 
00364     }
00365     
00366     
00367     //find tagname in histoname
00368     if(name.find(tagname)<name.size()) bPFFM = true;
00369     else{
00370       //adjust chip number if necessary, skip ME
00371       if(bMNCS){
00372         if(!bPFFM){
00373           if(bbarrel && bRS){
00374             if(bPixelAlive){
00375               int a = 16; 
00376               if(bwasHM) a = 8; 
00377               for(int i=0; i<a; i++){
00378                 bchipNumber++;
00379                 vbpixCN.push_back(bchipNumber);
00380                 vbpixM.push_back(0);
00381               }
00382             }
00383             else{
00384               if(bwasHM) bchipNumber += 8;
00385               else bchipNumber += 16; 
00386             }
00387           }
00388           if(bforward && fRS){   
00389 
00390             int maxcol = 2; 
00391             int mod = moduleNumber; 
00392             if(mod>1) mod--;
00393             else{
00394               if(panelNumber == 1) mod = 4; 
00395               else mod = 3;
00396             }
00397             if(panelNumber==1 && (mod==1 || mod==4)) maxcol = 1;
00398             if(bPixelAlive){
00399               for(int i=0; i<maxcol*(mod + panelNumber); i++){
00400                 fchipNumber++;
00401                 vfpixCN.push_back(fchipNumber);
00402                 vfpixM.push_back(0);
00403               }
00404             }
00405             else{
00406               fchipNumber += maxcol * (mod + panelNumber);
00407             }
00408           }
00409         }
00410         else bPFFM = false;
00411       }     
00412       continue;
00413     }
00414 
00415     //BARREL ROC LEVEL PLOTS
00416 
00417     if(bbarrel && bRS){
00418       maxccol=8, maxcrow=2;
00419       if(bhalfMod) {
00420         maxcrow=1;
00421       }
00422 
00423       RocSumOneModule(maxcrow, maxccol, (*ime), vbpixCN, vbpixM, vbpixSD, bchipNumber);
00424 
00425     }
00426 
00427 
00428     //ENDCAP ROC LEVEL PLOTS
00429     if(bforward && fRS){
00430       maxccol = moduleNumber + panelNumber; 
00431       maxcrow = 2; 
00432       if(panelNumber==1 && (moduleNumber==1 || moduleNumber==4)) maxcrow = 1;
00433 
00434       RocSumOneModule(maxcrow, maxccol, (*ime), vfpixCN, vfpixM, vfpixSD, fchipNumber);
00435     }
00436   }
00437 
00438   std::cout << "Number of Chips: b" << bchipNumber << " f" << fchipNumber << " " << tagname << std::endl;
00439 
00440 }
00441 
00442 void 
00443 SiPixelDQMRocLevelAnalyzer::RocSumOneModule(int maxr, int maxc, MonitorElement* const &me, std::vector<double> &vecCN, std::vector<double> &vecMean, std::vector<double> &vecSD, int &chipNumber){
00444 
00445   float temp, sum, nentries; 
00446   for(int cr=0; cr<maxr; cr++){
00447     for(int cc=0; cc<maxc; cc++){
00448       //compute mean of 1 ROC
00449       chipNumber++;
00450       sum = 0; 
00451       nentries = 0;
00452       //sum for 1 ROC
00453       for(int c=1; c<53; c++){
00454         for(int r=1; r<81; r++){         
00455           
00456           temp = me->getBinContent(52*cc+c, 80*cr+r);
00457           
00458           if(temp!=0.){
00459             sum += temp;
00460             nentries++;
00461           }
00462         }
00463       }
00464       if(nentries==0 && bPixelAlive){
00465         vecCN.push_back(chipNumber);
00466         vecMean.push_back(0);
00467       }
00468       if(nentries!=0){
00469         double mean = sum/nentries;
00470         double avsd = 0.; 
00471         int ne = 0; 
00472         vecCN.push_back(chipNumber);
00473         vecMean.push_back(mean);
00474         
00475         //computing std dev.
00476         for(int c=1; c<53; c++){
00477           for(int r=1; r<81; r++){         
00478             temp = me->getBinContent(52*cc+c, 80*cr+r);
00479             if(temp!=0){ 
00480               avsd += (temp-mean)*(temp-mean);
00481               ne++;
00482               
00483             }
00484           }
00485         }
00486         avsd = avsd/ne; 
00487         avsd = sqrt(avsd);
00488         vecSD.push_back(avsd);
00489       }
00490       
00491     }
00492   }
00493 }
00494 
00495 void 
00496 SiPixelDQMRocLevelAnalyzer::FillRocLevelHistos(TH1F *hrocdep, TH1F *hdist, std::vector<double> &vecx, std::vector<double> &vecy){
00497   if(vecx.size() == vecy.size()){
00498     for(unsigned int i=0; i<vecx.size(); i++){
00499       hrocdep->Fill(vecx[i],vecy[i]);
00500       hdist->Fill(vecy[i]);
00501     }
00502   }
00503 }
00504 
00505 // //define this as a plug-in
00506 // DEFINE_FWK_MODULE(SiPixelDQMRocLevelAnalyzer);