File indexing completed on 2024-04-06 12:06:42
0001 #include "DPGAnalysis/SiStripTools/interface/DigiLumiCorrHistogramMaker.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 "TH2F.h"
0009 #include "TProfile.h"
0010
0011 #include "DPGAnalysis/SiStripTools/interface/SiStripTKNumbers.h"
0012 #include "DPGAnalysis/SiStripTools/interface/RunHistogramManager.h"
0013
0014 DigiLumiCorrHistogramMaker::DigiLumiCorrHistogramMaker(edm::ConsumesCollector&& iC)
0015 : m_lumiProducerToken(iC.consumes<LumiDetails, edm::InLumi>(edm::InputTag("lumiProducer"))),
0016 m_fhm(),
0017 m_runHisto(false),
0018 m_hitname(),
0019 m_nbins(500),
0020 m_scalefact(),
0021 m_maxlumi(10.),
0022 m_binmax(),
0023 m_labels(),
0024 m_nmultvslumi(),
0025 m_nmultvslumiprof(),
0026 m_subdirs() {}
0027
0028 DigiLumiCorrHistogramMaker::DigiLumiCorrHistogramMaker(const edm::ParameterSet& iConfig, edm::ConsumesCollector&& iC)
0029 : m_lumiProducerToken(iC.consumes<LumiDetails, edm::InLumi>(iConfig.getParameter<edm::InputTag>("lumiProducer"))),
0030 m_fhm(),
0031 m_runHisto(iConfig.getUntrackedParameter<bool>("runHisto", false)),
0032 m_hitname(iConfig.getUntrackedParameter<std::string>("hitName", "digi")),
0033 m_nbins(iConfig.getUntrackedParameter<int>("numberOfBins", 500)),
0034 m_scalefact(iConfig.getUntrackedParameter<int>("scaleFactor", 5)),
0035 m_maxlumi(iConfig.getUntrackedParameter<double>("maxLumi", 10.)),
0036 m_labels(),
0037 m_nmultvslumi(),
0038 m_nmultvslumiprof(),
0039 m_subdirs() {
0040 std::vector<edm::ParameterSet> wantedsubds(iConfig.getUntrackedParameter<std::vector<edm::ParameterSet> >(
0041 "wantedSubDets", std::vector<edm::ParameterSet>()));
0042
0043 for (std::vector<edm::ParameterSet>::iterator ps = wantedsubds.begin(); ps != wantedsubds.end(); ++ps) {
0044 m_labels[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<std::string>("detLabel");
0045 m_binmax[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<int>("binMax");
0046 }
0047 }
0048
0049 DigiLumiCorrHistogramMaker::~DigiLumiCorrHistogramMaker() {
0050 for (std::map<unsigned int, std::string>::const_iterator lab = m_labels.begin(); lab != m_labels.end(); lab++) {
0051 const unsigned int i = lab->first;
0052 const std::string slab = lab->second;
0053
0054 delete m_subdirs[i];
0055 delete m_fhm[i];
0056 }
0057 }
0058
0059 void DigiLumiCorrHistogramMaker::book(const std::string dirname,
0060 const std::map<unsigned int, std::string>& labels,
0061 edm::ConsumesCollector&& iC) {
0062 m_labels = labels;
0063 book(dirname, iC);
0064 }
0065
0066 void DigiLumiCorrHistogramMaker::book(const std::string dirname, edm::ConsumesCollector& iC) {
0067 edm::Service<TFileService> tfserv;
0068 TFileDirectory subev = tfserv->mkdir(dirname);
0069
0070 SiStripTKNumbers trnumb;
0071
0072 edm::LogInfo("NumberOfBins") << "Number of Bins: " << m_nbins;
0073 edm::LogInfo("ScaleFactors") << "y-axis range scale factor: " << m_scalefact;
0074 edm::LogInfo("MaxLumi") << "max lumi value: " << m_maxlumi;
0075 edm::LogInfo("BinMaxValue") << "Setting bin max values";
0076
0077 for (std::map<unsigned int, std::string>::const_iterator lab = m_labels.begin(); lab != m_labels.end(); lab++) {
0078 const unsigned int i = lab->first;
0079 const std::string slab = lab->second;
0080
0081 if (m_binmax.find(i) == m_binmax.end()) {
0082 edm::LogVerbatim("NotConfiguredBinMax")
0083 << "Bin max for " << lab->second << " not configured: " << trnumb.nstrips(i) << " used";
0084 m_binmax[i] = trnumb.nstrips(i);
0085 }
0086
0087 edm::LogVerbatim("BinMaxValue") << "Bin max for " << lab->second << " is " << m_binmax[i];
0088 }
0089
0090 for (std::map<unsigned int, std::string>::const_iterator lab = m_labels.begin(); lab != m_labels.end(); ++lab) {
0091 const int i = lab->first;
0092 const std::string slab = lab->second;
0093
0094 char name[200];
0095 char title[500];
0096
0097 m_subdirs[i] = new TFileDirectory(subev.mkdir(slab));
0098 m_fhm[i] = new RunHistogramManager(iC, true);
0099
0100 if (m_subdirs[i]) {
0101 sprintf(name, "n%sdigivslumi", slab.c_str());
0102 sprintf(title, "%s %s multiplicity vs BX lumi", slab.c_str(), m_hitname.c_str());
0103 m_nmultvslumi[i] = m_subdirs[i]->make<TH2F>(
0104 name, title, 250, 0., m_maxlumi, m_nbins, 0., (1 + m_binmax[i] / (m_scalefact * m_nbins)) * m_nbins);
0105 m_nmultvslumi[i]->GetXaxis()->SetTitle("BX lumi [10^{30}cm^{-2}s^{-1}]");
0106 m_nmultvslumi[i]->GetYaxis()->SetTitle("Number of Hits");
0107 sprintf(name, "n%sdigivslumiprof", slab.c_str());
0108 m_nmultvslumiprof[i] = m_subdirs[i]->make<TProfile>(name, title, 250, 0., m_maxlumi);
0109 m_nmultvslumiprof[i]->GetXaxis()->SetTitle("BX lumi [10^{30}cm^{-2}s^{-1}]");
0110 m_nmultvslumiprof[i]->GetYaxis()->SetTitle("Number of Hits");
0111
0112 if (m_runHisto) {
0113 edm::LogInfo("RunHistos") << "Pseudo-booking run histos " << slab.c_str();
0114 sprintf(name, "n%sdigivslumivsbxprofrun", slab.c_str());
0115 sprintf(title, "%s %s multiplicity vs BX lumi vs BX", slab.c_str(), m_hitname.c_str());
0116 m_nmultvslumivsbxprofrun[i] = m_fhm[i]->makeTProfile2D(name, title, 3564, -0.5, 3563.5, 250, 0., m_maxlumi);
0117 }
0118 }
0119 }
0120 }
0121
0122 void DigiLumiCorrHistogramMaker::beginRun(const edm::Run& iRun) {
0123 edm::Service<TFileService> tfserv;
0124
0125 for (std::map<unsigned int, std::string>::const_iterator lab = m_labels.begin(); lab != m_labels.end(); ++lab) {
0126 const int i = lab->first;
0127 const std::string slab = lab->second;
0128 m_fhm[i]->beginRun(iRun, *m_subdirs[i]);
0129 if (m_runHisto) {
0130 (*m_nmultvslumivsbxprofrun[i])->GetXaxis()->SetTitle("BX");
0131 (*m_nmultvslumivsbxprofrun[i])->GetYaxis()->SetTitle("BX lumi [10^{30}cm^{-2}s^{-1}]");
0132 }
0133 }
0134 }
0135
0136 void DigiLumiCorrHistogramMaker::fill(const edm::Event& iEvent, const std::map<unsigned int, int>& ndigi) {
0137 edm::Handle<LumiDetails> ld;
0138 iEvent.getLuminosityBlock().getByToken(m_lumiProducerToken, ld);
0139
0140 if (ld.isValid()) {
0141 if (ld->isValid()) {
0142 float bxlumi = ld->lumiValue(LumiDetails::kOCC1, iEvent.bunchCrossing()) * 6.37;
0143
0144 for (std::map<unsigned int, int>::const_iterator digi = ndigi.begin(); digi != ndigi.end(); digi++) {
0145 if (m_labels.find(digi->first) != m_labels.end()) {
0146 const unsigned int i = digi->first;
0147 m_nmultvslumi[i]->Fill(bxlumi, digi->second);
0148 m_nmultvslumiprof[i]->Fill(bxlumi, digi->second);
0149
0150 if (m_nmultvslumivsbxprofrun[i] && *m_nmultvslumivsbxprofrun[i])
0151 (*m_nmultvslumivsbxprofrun[i])->Fill(iEvent.bunchCrossing() % 3564, bxlumi, digi->second);
0152 }
0153 }
0154 }
0155 }
0156 }