Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DPGAnalysis/SiStripTools/interface/DigiInvestigatorHistogramMaker.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 "TProfile.h"
0008 #include "TH1F.h"
0009 
0010 #include "DPGAnalysis/SiStripTools/interface/SiStripTKNumbers.h"
0011 
0012 DigiInvestigatorHistogramMaker::DigiInvestigatorHistogramMaker(edm::ConsumesCollector&& iC)
0013     : _hitname(),
0014       _nbins(500),
0015       m_maxLS(100),
0016       m_LSfrac(4),
0017       _scalefact(),
0018       _runHisto(true),
0019       _fillHisto(false),
0020       _binmax(),
0021       _labels(),
0022       _rhm(iC),
0023       _fhm(iC, true),
0024       _nmultvsorbrun(),
0025       _nmultvsbxrun(),
0026       _nmultvsbxfill(),
0027       _nmult() {}
0028 
0029 DigiInvestigatorHistogramMaker::DigiInvestigatorHistogramMaker(const edm::ParameterSet& iConfig,
0030                                                                edm::ConsumesCollector&& iC)
0031     : _hitname(iConfig.getUntrackedParameter<std::string>("hitName", "digi")),
0032       _nbins(iConfig.getUntrackedParameter<int>("numberOfBins", 500)),
0033       m_maxLS(iConfig.getUntrackedParameter<unsigned int>("maxLSBeforeRebin", 100)),
0034       m_LSfrac(iConfig.getUntrackedParameter<unsigned int>("startingLSFraction", 4)),
0035       _scalefact(iConfig.getUntrackedParameter<int>("scaleFactor", 5)),
0036       _runHisto(iConfig.getUntrackedParameter<bool>("runHisto", true)),
0037       _fillHisto(iConfig.getUntrackedParameter<bool>("fillHisto", false)),
0038       _labels(),
0039       _rhm(iC),
0040       _fhm(iC, true),
0041       _nmultvsorbrun(),
0042       _nmultvsbxrun(),
0043       _nmultvsbxfill(),
0044       _nmult(),
0045       _subdirs() {
0046   std::vector<edm::ParameterSet> wantedsubds(iConfig.getUntrackedParameter<std::vector<edm::ParameterSet> >(
0047       "wantedSubDets", std::vector<edm::ParameterSet>()));
0048 
0049   for (std::vector<edm::ParameterSet>::iterator ps = wantedsubds.begin(); ps != wantedsubds.end(); ++ps) {
0050     _labels[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<std::string>("detLabel");
0051     _binmax[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<int>("binMax");
0052   }
0053 }
0054 
0055 DigiInvestigatorHistogramMaker::~DigiInvestigatorHistogramMaker() {
0056   for (std::map<unsigned int, std::string>::const_iterator lab = _labels.begin(); lab != _labels.end(); lab++) {
0057     const unsigned int i = lab->first;
0058     const std::string slab = lab->second;
0059 
0060     delete _subdirs[i];
0061   }
0062 }
0063 
0064 void DigiInvestigatorHistogramMaker::book(const std::string dirname,
0065                                           const std::map<unsigned int, std::string>& labels) {
0066   _labels = labels;
0067   book(dirname);
0068 }
0069 
0070 void DigiInvestigatorHistogramMaker::book(const std::string dirname) {
0071   edm::Service<TFileService> tfserv;
0072   TFileDirectory subev = tfserv->mkdir(dirname);
0073 
0074   SiStripTKNumbers trnumb;
0075 
0076   edm::LogInfo("NumberOfBins") << "Number of Bins: " << _nbins;
0077   edm::LogInfo("NumberOfMaxLS") << "Max number of LS before rebinning: " << m_maxLS;
0078   edm::LogInfo("StartingLSFrac") << "Fraction of LS in one bin before rebinning: " << m_LSfrac;
0079   edm::LogInfo("ScaleFactors") << "x-axis range scale factor: " << _scalefact;
0080   edm::LogInfo("BinMaxValue") << "Setting bin max values";
0081 
0082   for (std::map<unsigned int, std::string>::const_iterator lab = _labels.begin(); lab != _labels.end(); lab++) {
0083     const unsigned int i = lab->first;
0084     const std::string slab = lab->second;
0085 
0086     if (_binmax.find(i) == _binmax.end()) {
0087       edm::LogVerbatim("NotConfiguredBinMax")
0088           << "Bin max for " << lab->second << " not configured: " << trnumb.nstrips(i) << " used";
0089       _binmax[i] = trnumb.nstrips(i);
0090     }
0091 
0092     edm::LogVerbatim("BinMaxValue") << "Bin max for " << lab->second << " is " << _binmax[i];
0093   }
0094 
0095   for (std::map<unsigned int, std::string>::const_iterator lab = _labels.begin(); lab != _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     _subdirs[i] = new TFileDirectory(subev.mkdir(slab));
0103 
0104     if (_subdirs[i]) {
0105       sprintf(name, "n%sdigi", slab.c_str());
0106       sprintf(title, "%s %s multiplicity", slab.c_str(), _hitname.c_str());
0107       _nmult[i] = _subdirs[i]->make<TH1F>(name, title, _nbins, 0., (1 + _binmax[i] / (_scalefact * _nbins)) * _nbins);
0108       _nmult[i]->GetXaxis()->SetTitle("Number of Hits");
0109       _nmult[i]->GetYaxis()->SetTitle("Events");
0110 
0111       if (_runHisto) {
0112         sprintf(name, "n%sdigivsorbrun", slab.c_str());
0113         sprintf(title, "%s %s mean multiplicity vs orbit", slab.c_str(), _hitname.c_str());
0114         _nmultvsorbrun[i] = _rhm.makeTProfile(name, title, m_LSfrac * m_maxLS, 0, m_maxLS * 262144);
0115         sprintf(name, "n%sdigivsbxrun", slab.c_str());
0116         sprintf(title, "%s %s mean multiplicity vs BX", slab.c_str(), _hitname.c_str());
0117         _nmultvsbxrun[i] = _rhm.makeTProfile(name, title, 3564, -0.5, 3563.5);
0118       }
0119       if (_fillHisto) {
0120         sprintf(name, "n%sdigivsbxfill", slab.c_str());
0121         sprintf(title, "%s %s mean multiplicity vs BX", slab.c_str(), _hitname.c_str());
0122         _nmultvsbxfill[i] = _fhm.makeTProfile(name, title, 3564, -0.5, 3563.5);
0123       }
0124     }
0125   }
0126 }
0127 
0128 void DigiInvestigatorHistogramMaker::beginRun(const edm::Run& iRun) {
0129   //  char runname[100];
0130   //  sprintf(runname,"run_%d",nrun);
0131 
0132   edm::Service<TFileService> tfserv;
0133 
0134   //  currdir = &(*tfserv);
0135   //  _rhm.beginRun(nrun,*currdir);
0136 
0137   _rhm.beginRun(iRun, tfserv->tFileDirectory());
0138   _fhm.beginRun(iRun, tfserv->tFileDirectory());
0139 
0140   for (std::map<unsigned int, std::string>::const_iterator lab = _labels.begin(); lab != _labels.end(); ++lab) {
0141     const int i = lab->first;
0142     const std::string slab = lab->second;
0143 
0144     //    char name[200];
0145     //    char title[500];
0146 
0147     //    TFileDirectory subd =_subdirs[i]->mkdir(runname);
0148 
0149     //    sprintf(name,"n%sdigivsorbrun",slab.c_str());
0150     //    sprintf(title,"%s %s mean multiplicity vs orbit",slab.c_str(),_hitname.c_str());
0151     //    _nmultvsorbrun[i] = subd.make<TProfile>(name,title,_norbbin,0.5,11223*_norbbin+0.5);
0152     if (_runHisto) {
0153       if (*_nmultvsorbrun[i]) {
0154         (*_nmultvsorbrun[i])->GetXaxis()->SetTitle("time [orbit#]");
0155         (*_nmultvsorbrun[i])->GetYaxis()->SetTitle("Hits");
0156         (*_nmultvsorbrun[i])->SetCanExtend(TH1::kXaxis);
0157       }
0158       if (*_nmultvsbxrun[i]) {
0159         (*_nmultvsbxrun[i])->GetXaxis()->SetTitle("BX#");
0160         (*_nmultvsbxrun[i])->GetYaxis()->SetTitle("Mean Number of Hits");
0161       }
0162     }
0163     if (_fillHisto) {
0164       if (*_nmultvsbxfill[i]) {
0165         (*_nmultvsbxfill[i])->GetXaxis()->SetTitle("BX#");
0166         (*_nmultvsbxfill[i])->GetYaxis()->SetTitle("Mean Number of Hits");
0167       }
0168     }
0169   }
0170 }
0171 
0172 void DigiInvestigatorHistogramMaker::fill(const edm::Event& iEvent, const std::map<unsigned int, int>& ndigi) {
0173   for (std::map<unsigned int, int>::const_iterator digi = ndigi.begin(); digi != ndigi.end(); digi++) {
0174     if (_labels.find(digi->first) != _labels.end()) {
0175       const unsigned int i = digi->first;
0176 
0177       _nmult[i]->Fill(digi->second);
0178       if (_runHisto) {
0179         if (_nmultvsorbrun[i] && *_nmultvsorbrun[i])
0180           (*_nmultvsorbrun[i])->Fill(iEvent.orbitNumber(), digi->second);
0181         if (_nmultvsbxrun[i] && *_nmultvsbxrun[i])
0182           (*_nmultvsbxrun[i])->Fill(iEvent.bunchCrossing() % 3564, digi->second);
0183       }
0184       if (_fillHisto) {
0185         if (_nmultvsbxfill[i] && *_nmultvsbxfill[i])
0186           (*_nmultvsbxfill[i])->Fill(iEvent.bunchCrossing() % 3564, digi->second);
0187       }
0188     }
0189   }
0190 }