Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DPGAnalysis/SiStripTools/interface/DigiPileupCorrHistogramMaker.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/Framework/interface/LuminosityBlock.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/ServiceRegistry/interface/Service.h"
0007 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0008 #include "DataFormats/Luminosity/interface/LumiDetails.h"
0009 #include "TH2F.h"
0010 #include "TProfile.h"
0011 #include "TProfile2D.h"
0012 
0013 #include "DPGAnalysis/SiStripTools/interface/SiStripTKNumbers.h"
0014 
0015 DigiPileupCorrHistogramMaker::DigiPileupCorrHistogramMaker(edm::ConsumesCollector&& iC)
0016     : m_pileupcollectionToken(iC.consumes<std::vector<PileupSummaryInfo> >(edm::InputTag("addPileupInfo"))),
0017       m_useVisibleVertices(false),
0018       m_hitname(),
0019       m_nbins(500),
0020       m_scalefact(),
0021       m_binmax(),
0022       m_labels(),
0023       m_nmultvsmclumi(),
0024       m_nmultvsmclumiprof(),
0025       m_nmultvsmcnvtx(),
0026       m_nmultvsmcnvtxprof(),
0027       m_nmultvsmcnvtxprof2d(),
0028       m_subdirs(),
0029       m_2dhisto(),
0030       m_ootBX(-1) {}
0031 
0032 DigiPileupCorrHistogramMaker::DigiPileupCorrHistogramMaker(const edm::ParameterSet& iConfig,
0033                                                            edm::ConsumesCollector&& iC)
0034     : m_pileupcollectionToken(
0035           iC.consumes<std::vector<PileupSummaryInfo> >(iConfig.getParameter<edm::InputTag>("pileupSummaryCollection"))),
0036       m_useVisibleVertices(iConfig.getParameter<bool>("useVisibleVertices")),
0037       m_hitname(iConfig.getUntrackedParameter<std::string>("hitName", "digi")),
0038       m_nbins(iConfig.getUntrackedParameter<int>("numberOfBins", 500)),
0039       m_scalefact(iConfig.getUntrackedParameter<int>("scaleFactor", 5)),
0040       m_labels(),
0041       m_nmultvsmclumi(),
0042       m_nmultvsmclumiprof(),
0043       m_nmultvsmcnvtx(),
0044       m_nmultvsmcnvtxprof(),
0045       m_nmultvsmcnvtxprof2d(),
0046       m_subdirs(),
0047       m_2dhisto(iConfig.getUntrackedParameter<bool>("wanted2DHisto", false)),
0048       m_ootBX(iConfig.getUntrackedParameter<int>("ootBX", -1)) {
0049   std::vector<edm::ParameterSet> wantedsubds(iConfig.getUntrackedParameter<std::vector<edm::ParameterSet> >(
0050       "wantedSubDets", std::vector<edm::ParameterSet>()));
0051 
0052   for (std::vector<edm::ParameterSet>::iterator ps = wantedsubds.begin(); ps != wantedsubds.end(); ++ps) {
0053     m_labels[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<std::string>("detLabel");
0054     m_binmax[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<int>("binMax");
0055   }
0056 }
0057 
0058 DigiPileupCorrHistogramMaker::~DigiPileupCorrHistogramMaker() {
0059   for (std::map<unsigned int, std::string>::const_iterator lab = m_labels.begin(); lab != m_labels.end(); lab++) {
0060     const unsigned int i = lab->first;
0061     const std::string slab = lab->second;
0062 
0063     delete m_subdirs[i];
0064   }
0065 }
0066 
0067 void DigiPileupCorrHistogramMaker::book(const std::string dirname, const std::map<unsigned int, std::string>& labels) {
0068   m_labels = labels;
0069   book(dirname);
0070 }
0071 
0072 void DigiPileupCorrHistogramMaker::book(const std::string dirname) {
0073   edm::Service<TFileService> tfserv;
0074   TFileDirectory subev = tfserv->mkdir(dirname);
0075 
0076   SiStripTKNumbers trnumb;
0077 
0078   edm::LogInfo("NumberOfBins") << "Number of Bins: " << m_nbins;
0079   edm::LogInfo("ScaleFactors") << "y-axis range scale factor: " << m_scalefact;
0080   edm::LogInfo("BinMaxValue") << "Setting bin max values";
0081 
0082   for (std::map<unsigned int, std::string>::const_iterator lab = m_labels.begin(); lab != m_labels.end(); lab++) {
0083     const unsigned int i = lab->first;
0084     const std::string slab = lab->second;
0085 
0086     if (m_binmax.find(i) == m_binmax.end()) {
0087       edm::LogVerbatim("NotConfiguredBinMax")
0088           << "Bin max for " << lab->second << " not configured: " << trnumb.nstrips(i) << " used";
0089       m_binmax[i] = trnumb.nstrips(i);
0090     }
0091 
0092     edm::LogVerbatim("BinMaxValue") << "Bin max for " << lab->second << " is " << m_binmax[i];
0093   }
0094 
0095   for (std::map<unsigned int, std::string>::const_iterator lab = m_labels.begin(); lab != m_labels.end(); ++lab) {
0096     const int i = lab->first;
0097     const std::string slab = lab->second;
0098 
0099     char name[200];
0100     char title[500];
0101 
0102     m_subdirs[i] = new TFileDirectory(subev.mkdir(slab));
0103 
0104     if (m_subdirs[i]) {
0105       sprintf(name, "n%sdigivsmclumi", slab.c_str());
0106       sprintf(title, "%s %s multiplicity ave pileup interactions", slab.c_str(), m_hitname.c_str());
0107       m_nmultvsmclumi[i] = m_subdirs[i]->make<TH2F>(
0108           name, title, 200, 0., 50., m_nbins, 0., m_binmax[i] / (m_scalefact * m_nbins) * m_nbins);
0109       m_nmultvsmclumi[i]->GetXaxis()->SetTitle("Average Pileup Interactions");
0110       m_nmultvsmclumi[i]->GetYaxis()->SetTitle("Number of Hits");
0111       sprintf(name, "n%sdigivsmclumiprof", slab.c_str());
0112       m_nmultvsmclumiprof[i] = m_subdirs[i]->make<TProfile>(name, title, 200, 0., 50.);
0113       m_nmultvsmclumiprof[i]->GetXaxis()->SetTitle("Average Pileup Interactions");
0114       m_nmultvsmclumiprof[i]->GetYaxis()->SetTitle("Number of Hits");
0115 
0116       sprintf(name, "n%sdigivsmcnvtx", slab.c_str());
0117       sprintf(title, "%s %s multiplicity vs pileup interactions", slab.c_str(), m_hitname.c_str());
0118       m_nmultvsmcnvtx[i] = m_subdirs[i]->make<TH2F>(
0119           name, title, 60, -0.5, 59.5, m_nbins, 0., m_binmax[i] / (m_scalefact * m_nbins) * m_nbins);
0120       m_nmultvsmcnvtx[i]->GetXaxis()->SetTitle("Pileup Interactions");
0121       m_nmultvsmcnvtx[i]->GetYaxis()->SetTitle("Number of Hits");
0122       sprintf(name, "n%sdigivsmcnvtxprof", slab.c_str());
0123       m_nmultvsmcnvtxprof[i] = m_subdirs[i]->make<TProfile>(name, title, 60, -0.5, 59.5);
0124       m_nmultvsmcnvtxprof[i]->GetXaxis()->SetTitle("Pileup Interactions");
0125       m_nmultvsmcnvtxprof[i]->GetYaxis()->SetTitle("Number of Hits");
0126       if (m_2dhisto) {
0127         sprintf(name, "n%sdigivsmcnvtxprof2d", slab.c_str());
0128         m_nmultvsmcnvtxprof2d[i] = m_subdirs[i]->make<TProfile2D>(name, title, 60, -0.5, 59.5, 60, -0.5, 59.5);
0129         m_nmultvsmcnvtxprof2d[i]->GetXaxis()->SetTitle("Pileup Interactions");
0130         m_nmultvsmcnvtxprof2d[i]->GetYaxis()->SetTitle("Pileup Interactions OOT");
0131         m_nmultvsmcnvtxprof2d[i]->GetZaxis()->SetTitle("Number of Hits");
0132       }
0133     }
0134   }
0135 }
0136 
0137 void DigiPileupCorrHistogramMaker::beginRun(const unsigned int nrun) {}
0138 
0139 void DigiPileupCorrHistogramMaker::fill(const edm::Event& iEvent, const std::map<unsigned int, int>& ndigi) {
0140   edm::Handle<std::vector<PileupSummaryInfo> > pileupinfos;
0141   iEvent.getByToken(m_pileupcollectionToken, pileupinfos);
0142 
0143   // look for the intime PileupSummaryInfo
0144 
0145   std::vector<PileupSummaryInfo>::const_iterator pileupinfoInTime = pileupinfos->end();
0146   std::vector<PileupSummaryInfo>::const_iterator pileupinfoMinusOne = pileupinfos->end();
0147 
0148   for (std::vector<PileupSummaryInfo>::const_iterator pileupinfo = pileupinfos->begin();
0149        pileupinfo != pileupinfos->end();
0150        ++pileupinfo) {
0151     if (pileupinfo->getBunchCrossing() == 0)
0152       pileupinfoInTime = pileupinfo;
0153     if (pileupinfo->getBunchCrossing() == m_ootBX)
0154       pileupinfoMinusOne = pileupinfo;
0155   }
0156 
0157   if (pileupinfoInTime == pileupinfos->end()) {
0158     edm::LogError("NoInTimePileUpInfo") << "Cannot find the in-time pileup info ";
0159 
0160   } else {
0161     int npileup = pileupinfoInTime->getPU_NumInteractions();
0162 
0163     if (m_useVisibleVertices)
0164       npileup = pileupinfoInTime->getPU_zpositions().size();
0165 
0166     for (std::map<unsigned int, int>::const_iterator digi = ndigi.begin(); digi != ndigi.end(); digi++) {
0167       if (m_labels.find(digi->first) != m_labels.end()) {
0168         const unsigned int i = digi->first;
0169         m_nmultvsmcnvtx[i]->Fill(npileup, digi->second);
0170         m_nmultvsmcnvtxprof[i]->Fill(npileup, digi->second);
0171         m_nmultvsmclumi[i]->Fill(pileupinfoInTime->getTrueNumInteractions(), digi->second);
0172         m_nmultvsmclumiprof[i]->Fill(pileupinfoInTime->getTrueNumInteractions(), digi->second);
0173         if (m_2dhisto) {
0174           if (pileupinfoMinusOne != pileupinfos->end()) {
0175             int npileupminusone = pileupinfoMinusOne->getPU_NumInteractions();
0176             if (m_useVisibleVertices)
0177               npileupminusone = pileupinfoMinusOne->getPU_zpositions().size();
0178             m_nmultvsmcnvtxprof2d[i]->Fill(npileup, npileupminusone, digi->second);
0179           }
0180         }
0181       }
0182     }
0183   }
0184 }