Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:06:42

0001 #include "DPGAnalysis/SiStripTools/interface/DigiVtxPosCorrHistogramMaker.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/Utilities/interface/InputTag.h"
0004 #include "DataFormats/Common/interface/Handle.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/ServiceRegistry/interface/Service.h"
0008 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0009 #include "TH2F.h"
0010 #include "TProfile.h"
0011 
0012 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
0013 #include "DPGAnalysis/SiStripTools/interface/SiStripTKNumbers.h"
0014 
0015 DigiVtxPosCorrHistogramMaker::DigiVtxPosCorrHistogramMaker(edm::ConsumesCollector&& iC)
0016     : m_mcvtxcollectionToken(iC.consumes<edm::HepMCProduct>(edm::InputTag("generatorSmeared"))),
0017       m_hitname(),
0018       m_nbins(500),
0019       m_scalefact(),
0020       m_binmax(),
0021       m_labels(),
0022       m_nmultvsvtxpos(),
0023       m_nmultvsvtxposprof(),
0024       m_subdirs() {}
0025 
0026 DigiVtxPosCorrHistogramMaker::DigiVtxPosCorrHistogramMaker(const edm::ParameterSet& iConfig,
0027                                                            edm::ConsumesCollector&& iC)
0028     : m_mcvtxcollectionToken(iC.consumes<edm::HepMCProduct>(iConfig.getParameter<edm::InputTag>("mcVtxCollection"))),
0029       m_hitname(iConfig.getUntrackedParameter<std::string>("hitName", "digi")),
0030       m_nbins(iConfig.getUntrackedParameter<int>("numberOfBins", 500)),
0031       m_scalefact(iConfig.getUntrackedParameter<int>("scaleFactor", 5)),
0032       m_labels(),
0033       m_nmultvsvtxpos(),
0034       m_nmultvsvtxposprof(),
0035       m_subdirs() {
0036   std::vector<edm::ParameterSet> wantedsubds(iConfig.getUntrackedParameter<std::vector<edm::ParameterSet> >(
0037       "wantedSubDets", std::vector<edm::ParameterSet>()));
0038 
0039   for (std::vector<edm::ParameterSet>::iterator ps = wantedsubds.begin(); ps != wantedsubds.end(); ++ps) {
0040     m_labels[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<std::string>("detLabel");
0041     m_binmax[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<int>("binMax");
0042   }
0043 }
0044 
0045 DigiVtxPosCorrHistogramMaker::~DigiVtxPosCorrHistogramMaker() {
0046   for (std::map<unsigned int, std::string>::const_iterator lab = m_labels.begin(); lab != m_labels.end(); lab++) {
0047     const unsigned int i = lab->first;
0048     const std::string slab = lab->second;
0049 
0050     delete m_subdirs[i];
0051   }
0052 }
0053 
0054 void DigiVtxPosCorrHistogramMaker::book(const std::string dirname, const std::map<unsigned int, std::string>& labels) {
0055   m_labels = labels;
0056   book(dirname);
0057 }
0058 
0059 void DigiVtxPosCorrHistogramMaker::book(const std::string dirname) {
0060   edm::Service<TFileService> tfserv;
0061   TFileDirectory subev = tfserv->mkdir(dirname);
0062 
0063   SiStripTKNumbers trnumb;
0064 
0065   edm::LogInfo("NumberOfBins") << "Number of Bins: " << m_nbins;
0066   edm::LogInfo("ScaleFactors") << "y-axis range scale factor: " << m_scalefact;
0067   edm::LogInfo("BinMaxValue") << "Setting bin max values";
0068 
0069   for (std::map<unsigned int, std::string>::const_iterator lab = m_labels.begin(); lab != m_labels.end(); lab++) {
0070     const unsigned int i = lab->first;
0071     const std::string slab = lab->second;
0072 
0073     if (m_binmax.find(i) == m_binmax.end()) {
0074       edm::LogVerbatim("NotConfiguredBinMax")
0075           << "Bin max for " << lab->second << " not configured: " << trnumb.nstrips(i) << " used";
0076       m_binmax[i] = trnumb.nstrips(i);
0077     }
0078 
0079     edm::LogVerbatim("BinMaxValue") << "Bin max for " << lab->second << " is " << m_binmax[i];
0080   }
0081 
0082   for (std::map<unsigned int, std::string>::const_iterator lab = m_labels.begin(); lab != m_labels.end(); ++lab) {
0083     const int i = lab->first;
0084     const std::string slab = lab->second;
0085 
0086     char name[200];
0087     char title[500];
0088 
0089     m_subdirs[i] = new TFileDirectory(subev.mkdir(slab));
0090 
0091     if (m_subdirs[i]) {
0092       sprintf(name, "n%sdigivsvtxpos", slab.c_str());
0093       sprintf(title, "%s %s multiplicity vx MC vertex z position", slab.c_str(), m_hitname.c_str());
0094       m_nmultvsvtxpos[i] = m_subdirs[i]->make<TH2F>(
0095           name, title, 200, -20., 20., m_nbins, 0., m_binmax[i] / (m_scalefact * m_nbins) * m_nbins);
0096       m_nmultvsvtxpos[i]->GetXaxis()->SetTitle("MC vertex z position (cm)");
0097       m_nmultvsvtxpos[i]->GetYaxis()->SetTitle("Number of Hits");
0098       sprintf(name, "n%sdigivsvtxposprof", slab.c_str());
0099       m_nmultvsvtxposprof[i] = m_subdirs[i]->make<TProfile>(name, title, 200, -20., 20.);
0100       m_nmultvsvtxposprof[i]->GetXaxis()->SetTitle("MC vertex z position (cm)");
0101       m_nmultvsvtxposprof[i]->GetYaxis()->SetTitle("Number of Hits");
0102     }
0103   }
0104 }
0105 
0106 void DigiVtxPosCorrHistogramMaker::beginRun(const unsigned int nrun) {}
0107 
0108 void DigiVtxPosCorrHistogramMaker::fill(const edm::Event& iEvent, const std::map<unsigned int, int>& ndigi) {
0109   // main interaction part
0110 
0111   edm::Handle<edm::HepMCProduct> EvtHandle;
0112   iEvent.getByToken(m_mcvtxcollectionToken, EvtHandle);
0113 
0114   if (EvtHandle.isValid()) {
0115     const HepMC::GenEvent* Evt = EvtHandle->GetEvent();
0116 
0117     // get the first vertex
0118 
0119     if (Evt->vertices_begin() != Evt->vertices_end()) {
0120       double vtxz = (*Evt->vertices_begin())->point3d().z() / 10.;
0121 
0122       for (std::map<unsigned int, int>::const_iterator digi = ndigi.begin(); digi != ndigi.end(); digi++) {
0123         if (m_labels.find(digi->first) != m_labels.end()) {
0124           const unsigned int i = digi->first;
0125           m_nmultvsvtxpos[i]->Fill(vtxz, digi->second);
0126           m_nmultvsvtxposprof[i]->Fill(vtxz, digi->second);
0127         }
0128       }
0129     }
0130   }
0131 }