CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DPGAnalysis/SiStripTools/src/DigiInvestigatorHistogramMaker.cc

Go to the documentation of this file.
00001 #include "DPGAnalysis/SiStripTools/interface/DigiInvestigatorHistogramMaker.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00004 #include "FWCore/ServiceRegistry/interface/Service.h"
00005 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00006 #include "TProfile.h"
00007 #include "TH1F.h"
00008 
00009 #include "DPGAnalysis/SiStripTools/interface/SiStripTKNumbers.h"
00010 
00011 
00012 DigiInvestigatorHistogramMaker::DigiInvestigatorHistogramMaker():
00013   _hitname(), _nbins(500), _norbbin(3600), _scalefact(), _runHisto(true), _binmax(), _labels(), _nmultvsorbrun(), _nmult() { }
00014 
00015 DigiInvestigatorHistogramMaker::DigiInvestigatorHistogramMaker(const edm::ParameterSet& iConfig):
00016   _hitname(iConfig.getUntrackedParameter<std::string>("hitName","digi")),
00017   _nbins(iConfig.getUntrackedParameter<int>("numberOfBins",500)),
00018   _norbbin(iConfig.getUntrackedParameter<int>("orbitNbin",3600)),
00019   _scalefact(iConfig.getUntrackedParameter<int>("scaleFactor",5)),
00020   _runHisto(iConfig.getUntrackedParameter<bool>("runHisto",true)),
00021   _labels(), _rhm(), _nmultvsorbrun(), _nmult(), _subdirs() 
00022 { 
00023 
00024   std::vector<edm::ParameterSet> 
00025     wantedsubds(iConfig.getUntrackedParameter<std::vector<edm::ParameterSet> >("wantedSubDets",std::vector<edm::ParameterSet>()));
00026   
00027   for(std::vector<edm::ParameterSet>::iterator ps=wantedsubds.begin();ps!=wantedsubds.end();++ps) {
00028     _labels[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<std::string>("detLabel");
00029     _binmax[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<int>("binMax");
00030   }
00031   
00032 
00033 }
00034 
00035 
00036 DigiInvestigatorHistogramMaker::~DigiInvestigatorHistogramMaker() {
00037 
00038   for(std::map<unsigned int,std::string>::const_iterator lab=_labels.begin();lab!=_labels.end();lab++) {
00039     
00040     const unsigned int i = lab->first; const std::string slab = lab->second;
00041     
00042     delete _subdirs[i];
00043   }
00044   
00045 }
00046 
00047 
00048 
00049 void DigiInvestigatorHistogramMaker::book(const std::string dirname, const std::map<unsigned int, std::string>& labels) {
00050 
00051   _labels = labels;
00052   book(dirname);
00053 
00054 }
00055 
00056 void DigiInvestigatorHistogramMaker::book(const std::string dirname) {
00057 
00058   edm::Service<TFileService> tfserv;
00059   TFileDirectory subev = tfserv->mkdir(dirname);
00060 
00061   SiStripTKNumbers trnumb;
00062   
00063   edm::LogInfo("NumberOfBins") << "Number of Bins: " << _nbins;
00064   edm::LogInfo("NumberOfOrbitBins") << "Number of Orbit Bins: " << _norbbin;
00065   edm::LogInfo("ScaleFactors") << "x-axis range scale factor: " << _scalefact;
00066   edm::LogInfo("BinMaxValue") << "Setting bin max values";
00067 
00068   for(std::map<unsigned int,std::string>::const_iterator lab=_labels.begin();lab!=_labels.end();lab++) {
00069     
00070     const unsigned int i = lab->first; const std::string slab = lab->second;
00071     
00072     if(_binmax.find(i)==_binmax.end()) {
00073       edm::LogVerbatim("NotConfiguredBinMax") << "Bin max for " << lab->second 
00074                                               << " not configured: " << trnumb.nstrips(i) << " used";
00075       _binmax[i] = trnumb.nstrips(i);
00076     }
00077  
00078     edm::LogVerbatim("BinMaxValue") << "Bin max for " << lab->second << " is " << _binmax[i];
00079 
00080   }
00081 
00082   for(std::map<unsigned int,std::string>::const_iterator lab=_labels.begin();lab!=_labels.end();++lab) {
00083 
00084     const int i = lab->first; const std::string slab = lab->second;
00085 
00086     char name[200];
00087     char title[500];
00088 
00089     _subdirs[i] = new TFileDirectory(subev.mkdir(slab.c_str()));
00090 
00091     if(_subdirs[i]) {
00092       sprintf(name,"n%sdigi",slab.c_str());
00093       sprintf(title,"%s %s multiplicity",slab.c_str(),_hitname.c_str());
00094       _nmult[i] = _subdirs[i]->make<TH1F>(name,title,_nbins,0.,_binmax[i]/(_scalefact*_nbins)*_nbins);
00095       _nmult[i]->GetXaxis()->SetTitle("Number of Hits");    _nmult[i]->GetYaxis()->SetTitle("Events");
00096       
00097       if(_runHisto) {
00098         sprintf(name,"n%sdigivsorbrun",slab.c_str());
00099         sprintf(title,"%s %s mean multiplicity vs orbit",slab.c_str(),_hitname.c_str());
00100         _nmultvsorbrun[i] = _rhm.makeTProfile(name,title,_norbbin,0.5,11223*_norbbin+0.5);
00101       }
00102 
00103     }
00104 
00105   }
00106 
00107 
00108 }
00109 
00110 void DigiInvestigatorHistogramMaker::beginRun(const unsigned int nrun) {
00111 
00112   //  char runname[100];
00113   //  sprintf(runname,"run_%d",nrun);
00114 
00115   edm::Service<TFileService> tfserv;
00116 
00117   //  currdir = &(*tfserv);
00118   //  _rhm.beginRun(nrun,*currdir);
00119 
00120   _rhm.beginRun(nrun,*tfserv);
00121 
00122 
00123   for(std::map<unsigned int,std::string>::const_iterator lab=_labels.begin();lab!=_labels.end();++lab) {
00124 
00125     const int i = lab->first; const std::string slab = lab->second;
00126 
00127     //    char name[200];
00128     //    char title[500];
00129 
00130     //    TFileDirectory subd =_subdirs[i]->mkdir(runname);
00131 
00132     //    sprintf(name,"n%sdigivsorbrun",slab.c_str());
00133     //    sprintf(title,"%s %s mean multiplicity vs orbit",slab.c_str(),_hitname.c_str());
00134     //    _nmultvsorbrun[i] = subd.make<TProfile>(name,title,_norbbin,0.5,11223*_norbbin+0.5);
00135     if(_runHisto) {
00136       (*_nmultvsorbrun[i])->GetXaxis()->SetTitle("time [orbit#]");    (*_nmultvsorbrun[i])->GetYaxis()->SetTitle("Hits");
00137       (*_nmultvsorbrun[i])->SetBit(TH1::kCanRebin);
00138     }
00139   }
00140 
00141 
00142 }
00143 
00144 void DigiInvestigatorHistogramMaker::fill(const unsigned int orbit, const std::map<unsigned int,int>& ndigi) {
00145   
00146   for(std::map<unsigned int,int>::const_iterator digi=ndigi.begin();digi!=ndigi.end();digi++) {
00147     
00148     if(_labels.find(digi->first) != _labels.end()) {
00149  
00150       const unsigned int i=digi->first;
00151       
00152       _nmult[i]->Fill(digi->second);
00153       if(_runHisto) {
00154         if(_nmultvsorbrun[i] && *_nmultvsorbrun[i]) (*_nmultvsorbrun[i])->Fill(orbit,digi->second);
00155       }
00156     }
00157     
00158   }
00159 }
00160