CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DQMOffline/CalibTracker/src/APVValidationPlots.cc

Go to the documentation of this file.
00001 // system include files
00002 #include <memory>
00003 
00004 // user include files
00005 #include "FWCore/Framework/interface/Frameworkfwd.h"
00006 #include "FWCore/Framework/interface/EDAnalyzer.h"
00007 
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "FWCore/Framework/interface/MakerMacros.h"
00010 
00011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00012 
00013 #include "FWCore/ServiceRegistry/interface/Service.h"
00014 
00015 #include "DataFormats/SiStripCluster/interface/SiStripClusterCollection.h"
00016 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00017 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00018 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00019 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00020 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00021 #include "DataFormats/Common/interface/DetSetVector.h"
00022 #include "DataFormats/Common/interface/DetSetVectorNew.h"
00023 
00024 #include "DQMServices/Core/interface/DQMStore.h"
00025 #include "DQMServices/Core/interface/MonitorElement.h"
00026 
00027 #include "TH1F.h"
00028 #include "TFile.h"
00029 #include "TCanvas.h"
00030 #include "TH1.h"
00031 #include "TH2F.h"
00032 #include "TH1D.h"
00033 #include "TProfile.h"
00034 #include "TStyle.h"
00035 #include "TTree.h"
00036 
00037 #include <sstream>
00038 #include <iostream>
00039 #include <vector>
00040 
00041 //
00042 // class decleration
00043 //
00044 
00045 class APVValidationPlots : public edm::EDAnalyzer {
00046    public:
00047       explicit APVValidationPlots(const edm::ParameterSet&);
00048       ~APVValidationPlots();
00049 
00050 
00051    private:
00052       virtual void beginJob() ;
00053       virtual void analyze(const edm::Event&, const edm::EventSetup&);
00054       virtual void endJob() ;
00055 
00056   std::ostringstream oss;
00057 
00058   DQMStore* dqmStore;
00059 
00060   MonitorElement* tmp;
00061 
00062   // Histograms
00063   // indexes in these arrays are [SubDetId-2][LayerN]
00064   // histograms for [SubDetId-2][0] are global for the subdetector
00065   // histogram for [0][0] is global for the tracker
00066   
00067   TH2F* medianVsAbsoluteOccupancy[5][10];
00068   TH1F* medianOccupancy[5][10];
00069   TH1F* absoluteOccupancy[5][10];
00070 
00071   std::vector<std::string> subDetName;
00072   std::vector<unsigned int> nLayers;
00073   std::vector<std::string> layerName;
00074 
00075   std::string infilename;
00076   std::string outfilename;
00077 
00078   TFile* infile;
00079   TTree* intree;
00080 
00081    // Declaration of leaf types
00082    Int_t           DetRawId;
00083    Int_t           SubDetId;
00084    Int_t           Layer_Ring;
00085    Int_t           Disc;
00086    Int_t           IsBack;
00087    Int_t           IsExternalString;
00088    Int_t           IsZMinusSide;
00089    Int_t           RodStringPetal;
00090    Int_t           IsStereo;
00091    Int_t           ModulePosition;
00092    Int_t           NumberOfStrips;
00093    Float_t         APVGlobalPositionX;
00094    Float_t         APVGlobalPositionY;
00095    Float_t         APVGlobalPositionZ;
00096    Int_t           APVNumber;
00097    Int_t           APVAbsoluteOccupancy;
00098    Double_t        APVMedianOccupancy;
00099 
00100 
00101 
00102       // ----------member data ---------------------------
00103 };
00104 
00105 //
00106 // constants, enums and typedefs
00107 //
00108 
00109 //
00110 // static data member definitions
00111 //
00112 
00113 //
00114 // constructors and destructor
00115 //
00116 APVValidationPlots::APVValidationPlots(const edm::ParameterSet& iConfig) : infilename(iConfig.getUntrackedParameter<std::string>("inputFilename","in.root")),
00117                                                                            outfilename(iConfig.getUntrackedParameter<std::string>("outputFilename","out.root"))
00118 
00119 {
00120    //now do what ever initialization is needed
00121 
00122 }
00123 
00124 
00125 APVValidationPlots::~APVValidationPlots()
00126 {
00127  
00128    // do anything here that needs to be done at desctruction time
00129    // (e.g. close files, deallocate resources etc.)
00130 
00131 }
00132 
00133 
00134 //
00135 // member functions
00136 //
00137 
00138 // ------------ method called to for each event  ------------
00139 void
00140 APVValidationPlots::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00141 {
00142 
00143 }
00144 
00145 
00146 // ------------ method called once each job just before starting event loop  ------------
00147 void 
00148 APVValidationPlots::beginJob()
00149 {
00150   oss.str("");
00151   oss << 1; //runNumber
00152 
00153   dqmStore = edm::Service<DQMStore>().operator->();
00154   dqmStore->setCurrentFolder("ChannelStatusPlots");
00155 
00156   // Initialize histograms
00157   subDetName.push_back(""); subDetName.push_back("TIB"); subDetName.push_back("TID"); subDetName.push_back("TOB"); subDetName.push_back("TEC");
00158   nLayers.push_back(0); nLayers.push_back(4); nLayers.push_back(3); nLayers.push_back(6); nLayers.push_back(9);
00159   layerName.push_back(""); layerName.push_back("Layer"); layerName.push_back("Disk"); layerName.push_back("Layer"); layerName.push_back("Disk");
00160   
00161   std::string histoName;
00162   std::string histoTitle;
00163   for(unsigned int i = 0; i < subDetName.size(); i++)
00164   {
00165     for(unsigned int j = 0; j <= nLayers[i]; j++)
00166     {
00167       histoName = "medianVsAbsoluteOccupancy" + subDetName[i];
00168       if(j!=0)
00169       {
00170         oss.str("");
00171         oss << j;
00172         histoName += layerName[i] + oss.str();
00173       }
00174       histoTitle = "Median APV occupancy vs. absolute APV occupancy";
00175       if(i!=0)
00176         histoTitle += " in " + subDetName[i];
00177       if(j!=0)
00178       {
00179         histoTitle += " " + layerName[i] + " " + oss.str();
00180       }
00181       tmp = dqmStore->book2D(histoName.c_str(), histoTitle.c_str(), 1000, 0., 6., 1000, -1., 3.);
00182       medianVsAbsoluteOccupancy[i][j] = tmp->getTH2F();
00183       medianVsAbsoluteOccupancy[i][j]->Rebin2D(10,10);
00184       medianVsAbsoluteOccupancy[i][j]->GetXaxis()->SetTitle("log_{10}(Abs. Occupancy)");
00185       medianVsAbsoluteOccupancy[i][j]->GetYaxis()->SetTitle("log_{10}(Median Occupancy)");
00186       //
00187       histoName = "medianOccupancy" + subDetName[i];
00188       if(j!=0)
00189       {
00190         oss.str("");
00191         oss << j;
00192         histoName += layerName[i] + oss.str();
00193       }
00194       histoTitle = "Median APV occupancy";
00195       if(i!=0)
00196         histoTitle += " in " + subDetName[i];
00197       if(j!=0)
00198       {
00199         histoTitle += " " + layerName[i] + " " + oss.str();
00200       }
00201       tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 1000, -1., 3.);
00202       medianOccupancy[i][j] = tmp->getTH1F();
00203       medianOccupancy[i][j]->GetXaxis()->SetTitle("log_{10}(Occupancy)");
00204       medianOccupancy[i][j]->GetYaxis()->SetTitle("APVs");
00205       //
00206       histoName = "absoluteOccupancy" + subDetName[i];
00207       if(j!=0)
00208       {
00209         oss.str("");
00210         oss << j;
00211         histoName += layerName[i] + oss.str();
00212       }
00213       histoTitle = "Absolute APV occupancy";
00214       if(i!=0)
00215         histoTitle += " in " + subDetName[i];
00216       if(j!=0)
00217       {
00218         histoTitle += " " + layerName[i] + " " + oss.str();
00219       }
00220       tmp = dqmStore->book1D(histoName.c_str(), histoTitle.c_str(), 1000, 0., 6.);
00221       absoluteOccupancy[i][j] = tmp->getTH1F();
00222       absoluteOccupancy[i][j]->GetXaxis()->SetTitle("log_{10}(Occupancy)");
00223       absoluteOccupancy[i][j]->GetYaxis()->SetTitle("APVs");
00224     }
00225   }
00226 
00227 }
00228 
00229 // ------------ method called once each job just after ending the event loop  ------------
00230 void 
00231 APVValidationPlots::endJob() {
00232 
00233   infile = new TFile(infilename.c_str(),"READ");
00234   intree = (TTree*)infile->Get("moduleOccupancy");
00235 
00236   intree->SetBranchAddress("DetRawId",             &DetRawId);
00237   intree->SetBranchAddress("SubDetId",             &SubDetId);
00238   intree->SetBranchAddress("Layer_Ring",           &Layer_Ring);
00239   intree->SetBranchAddress("Disc",                 &Disc);
00240   intree->SetBranchAddress("IsBack",               &IsBack);
00241   intree->SetBranchAddress("IsExternalString",     &IsExternalString);
00242   intree->SetBranchAddress("IsZMinusSide",         &IsZMinusSide);
00243   intree->SetBranchAddress("RodStringPetal",       &RodStringPetal);
00244   intree->SetBranchAddress("IsStereo",             &IsStereo);
00245   intree->SetBranchAddress("ModuleNumber",         &ModulePosition);
00246   intree->SetBranchAddress("NumberOfStrips",       &NumberOfStrips);
00247   intree->SetBranchAddress("APVGlobalPositionX",   &APVGlobalPositionX);
00248   intree->SetBranchAddress("APVGlobalPositionY",   &APVGlobalPositionY);
00249   intree->SetBranchAddress("APVGlobalPositionZ",   &APVGlobalPositionZ);
00250   intree->SetBranchAddress("APVNumber",            &APVNumber);
00251   intree->SetBranchAddress("APVAbsoluteOccupancy", &APVAbsoluteOccupancy);
00252   intree->SetBranchAddress("APVMedianOccupancy",   &APVMedianOccupancy);
00253 
00254   for (int i=0; i<intree->GetEntries(); i++)
00255     {
00256       intree->GetEntry(i);
00257 
00258       double logMedianOccupancy = -1;
00259       double logAbsoluteOccupancy = -1;
00260 
00261       if (APVMedianOccupancy>0) logMedianOccupancy = log10(APVMedianOccupancy);
00262       if (APVAbsoluteOccupancy>0) logAbsoluteOccupancy = log10(APVAbsoluteOccupancy);
00263 
00264       // The layer/disk information is stored in Layer_Ring for TIB/TOB and in Disc for TID/TEC
00265       unsigned int layer = 0;
00266       if(SubDetId==3 || SubDetId==5)
00267         layer=Layer_Ring;
00268       else
00269         layer=Disc;
00270 
00271       // Fill histograms for all the tracker
00272       medianVsAbsoluteOccupancy[0][0]->Fill(logAbsoluteOccupancy,logMedianOccupancy);
00273       medianOccupancy[0][0]->Fill(logMedianOccupancy);
00274       absoluteOccupancy[0][0]->Fill(logAbsoluteOccupancy);
00275       // Fill summary histograms for each subdetector
00276       medianVsAbsoluteOccupancy[SubDetId-2][0]->Fill(logAbsoluteOccupancy,logMedianOccupancy);
00277       medianOccupancy[SubDetId-2][0]->Fill(logMedianOccupancy);
00278       absoluteOccupancy[SubDetId-2][0]->Fill(logAbsoluteOccupancy);
00279       // Fill histograms for each layer/disk
00280       medianVsAbsoluteOccupancy[SubDetId-2][layer]->Fill(logAbsoluteOccupancy,logMedianOccupancy);
00281       medianOccupancy[SubDetId-2][layer]->Fill(logMedianOccupancy);
00282       absoluteOccupancy[SubDetId-2][layer]->Fill(logAbsoluteOccupancy);
00283     }
00284 
00285   dqmStore->cd();
00286   dqmStore->save(outfilename.c_str(),"ChannelStatusPlots");
00287 
00288 }
00289 
00290 //define this as a plug-in
00291 DEFINE_FWK_MODULE(APVValidationPlots);