Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:09:10

0001 #include "DPGAnalysis/SiStripTools/interface/DigiVertexCorrHistogramMaker.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/ServiceRegistry/interface/Service.h"
0006 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0007 #include "TH2F.h"
0008 #include "TProfile.h"
0009 
0010 #include "DPGAnalysis/SiStripTools/interface/SiStripTKNumbers.h"
0011 #include "DPGAnalysis/SiStripTools/interface/RunHistogramManager.h"
0012 
0013 DigiVertexCorrHistogramMaker::DigiVertexCorrHistogramMaker()
0014     : m_fhm(),
0015       m_runHisto(false),
0016       m_hitname(),
0017       m_nbins(500),
0018       m_scalefact(),
0019       m_maxnvtx(60),
0020       m_binmax(),
0021       m_labels(),
0022       m_nmultvsnvtx(),
0023       m_nmultvsnvtxprof(),
0024       m_nmultvsnvtxvsbxprofrun(),
0025       m_subdirs() {}
0026 
0027 DigiVertexCorrHistogramMaker::DigiVertexCorrHistogramMaker(const edm::ParameterSet& iConfig)
0028     : m_fhm(),
0029       m_runHisto(iConfig.getUntrackedParameter<bool>("runHisto", false)),
0030       m_hitname(iConfig.getUntrackedParameter<std::string>("hitName", "digi")),
0031       m_nbins(iConfig.getUntrackedParameter<int>("numberOfBins", 500)),
0032       m_scalefact(iConfig.getUntrackedParameter<int>("scaleFactor", 5)),
0033       m_maxnvtx(iConfig.getUntrackedParameter<int>("maxNvtx", 60)),
0034       m_labels(),
0035       m_nmultvsnvtx(),
0036       m_nmultvsnvtxprof(),
0037       m_subdirs() {
0038   std::vector<edm::ParameterSet> wantedsubds(iConfig.getUntrackedParameter<std::vector<edm::ParameterSet> >(
0039       "wantedSubDets", std::vector<edm::ParameterSet>()));
0040 
0041   for (std::vector<edm::ParameterSet>::iterator ps = wantedsubds.begin(); ps != wantedsubds.end(); ++ps) {
0042     m_labels[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<std::string>("detLabel");
0043     m_binmax[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<int>("binMax");
0044   }
0045 }
0046 
0047 DigiVertexCorrHistogramMaker::~DigiVertexCorrHistogramMaker() {
0048   for (std::map<unsigned int, std::string>::const_iterator lab = m_labels.begin(); lab != m_labels.end(); lab++) {
0049     const unsigned int i = lab->first;
0050     const std::string slab = lab->second;
0051 
0052     delete m_subdirs[i];
0053     delete m_fhm[i];
0054   }
0055 }
0056 
0057 void DigiVertexCorrHistogramMaker::book(const std::string dirname,
0058                                         const std::map<unsigned int, std::string>& labels,
0059                                         edm::ConsumesCollector&& iC) {
0060   m_labels = labels;
0061   book(dirname, iC);
0062 }
0063 
0064 void DigiVertexCorrHistogramMaker::book(const std::string dirname, edm::ConsumesCollector& iC) {
0065   edm::Service<TFileService> tfserv;
0066   TFileDirectory subev = tfserv->mkdir(dirname);
0067 
0068   SiStripTKNumbers trnumb;
0069 
0070   edm::LogInfo("NumberOfBins") << "Number of Bins: " << m_nbins;
0071   edm::LogInfo("ScaleFactors") << "y-axis range scale factor: " << m_scalefact;
0072   edm::LogInfo("MaxNvtx") << "maximum number of vertices: " << m_maxnvtx;
0073   edm::LogInfo("BinMaxValue") << "Setting bin max values";
0074 
0075   for (std::map<unsigned int, std::string>::const_iterator lab = m_labels.begin(); lab != m_labels.end(); lab++) {
0076     const unsigned int i = lab->first;
0077     const std::string slab = lab->second;
0078 
0079     if (m_binmax.find(i) == m_binmax.end()) {
0080       edm::LogVerbatim("NotConfiguredBinMax")
0081           << "Bin max for " << lab->second << " not configured: " << trnumb.nstrips(i) << " used";
0082       m_binmax[i] = trnumb.nstrips(i);
0083     }
0084 
0085     edm::LogVerbatim("BinMaxValue") << "Bin max for " << lab->second << " is " << m_binmax[i];
0086   }
0087 
0088   for (std::map<unsigned int, std::string>::const_iterator lab = m_labels.begin(); lab != m_labels.end(); ++lab) {
0089     const int i = lab->first;
0090     const std::string slab = lab->second;
0091 
0092     char name[200];
0093     char title[500];
0094 
0095     m_subdirs[i] = new TFileDirectory(subev.mkdir(slab));
0096     m_fhm[i] = new RunHistogramManager(iC, true);
0097 
0098     if (m_subdirs[i]) {
0099       sprintf(name, "n%sdigivsnvtx", slab.c_str());
0100       sprintf(title, "%s %s multiplicity vs Nvtx", slab.c_str(), m_hitname.c_str());
0101       m_nmultvsnvtx[i] = m_subdirs[i]->make<TH2F>(name,
0102                                                   title,
0103                                                   m_maxnvtx,
0104                                                   -0.5,
0105                                                   m_maxnvtx - 0.5,
0106                                                   m_nbins,
0107                                                   0.,
0108                                                   (1 + m_binmax[i] / (m_scalefact * m_nbins)) * m_nbins);
0109       m_nmultvsnvtx[i]->GetXaxis()->SetTitle("Number of Vertices");
0110       m_nmultvsnvtx[i]->GetYaxis()->SetTitle("Number of Hits");
0111       sprintf(name, "n%sdigivsnvtxprof", slab.c_str());
0112       m_nmultvsnvtxprof[i] = m_subdirs[i]->make<TProfile>(name, title, m_maxnvtx, -0.5, m_maxnvtx - 0.5);
0113       m_nmultvsnvtxprof[i]->GetXaxis()->SetTitle("Number of Vertices");
0114       m_nmultvsnvtxprof[i]->GetYaxis()->SetTitle("Number of Hits");
0115 
0116       if (m_runHisto) {
0117         edm::LogInfo("RunHistos") << "Pseudo-booking run histos " << slab.c_str();
0118         sprintf(name, "n%sdigivsnvtxvsbxprofrun", slab.c_str());
0119         sprintf(title, "%s %s multiplicity vs Nvtx vs BX", slab.c_str(), m_hitname.c_str());
0120         m_nmultvsnvtxvsbxprofrun[i] =
0121             m_fhm[i]->makeTProfile2D(name, title, 3564, -0.5, 3563.5, m_maxnvtx, -0.5, m_maxnvtx - 0.5);
0122       }
0123     }
0124   }
0125 }
0126 
0127 void DigiVertexCorrHistogramMaker::beginRun(const edm::Run& iRun) {
0128   edm::Service<TFileService> tfserv;
0129 
0130   for (std::map<unsigned int, std::string>::const_iterator lab = m_labels.begin(); lab != m_labels.end(); ++lab) {
0131     const int i = lab->first;
0132     const std::string slab = lab->second;
0133     m_fhm[i]->beginRun(iRun, *m_subdirs[i]);
0134     if (m_runHisto) {
0135       (*m_nmultvsnvtxvsbxprofrun[i])->GetXaxis()->SetTitle("BX");
0136       (*m_nmultvsnvtxvsbxprofrun[i])->GetYaxis()->SetTitle("Nvertices");
0137     }
0138   }
0139 }
0140 
0141 void DigiVertexCorrHistogramMaker::fill(const edm::Event& iEvent,
0142                                         const unsigned int nvtx,
0143                                         const std::map<unsigned int, int>& ndigi) {
0144   edm::Service<TFileService> tfserv;
0145 
0146   for (std::map<unsigned int, int>::const_iterator digi = ndigi.begin(); digi != ndigi.end(); digi++) {
0147     if (m_labels.find(digi->first) != m_labels.end()) {
0148       const unsigned int i = digi->first;
0149       m_nmultvsnvtx[i]->Fill(nvtx, digi->second);
0150       m_nmultvsnvtxprof[i]->Fill(nvtx, digi->second);
0151 
0152       if (m_nmultvsnvtxvsbxprofrun[i] && *m_nmultvsnvtxvsbxprofrun[i])
0153         (*m_nmultvsnvtxvsbxprofrun[i])->Fill(iEvent.bunchCrossing() % 3564, nvtx, digi->second);
0154     }
0155   }
0156 }