Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  \author:  Mia Tosi,40 3-B32,+41227671609 
0005  */
0006 
0007 #include "DQM/TrackingMonitor/interface/GetLumi.h"
0008 
0009 #include "FWCore/Framework/interface/LuminosityBlock.h"
0010 #include "DataFormats/Luminosity/interface/LumiDetails.h"
0011 #include "DataFormats/Luminosity/interface/LumiSummary.h"
0012 
0013 GetLumi::GetLumi(const edm::ParameterSet& iConfig)
0014     : lumiInputTag_(iConfig.getParameter<edm::InputTag>("lumi")),
0015       lumiScale_(iConfig.getParameter<double>("lumiScale")) {}
0016 
0017 GetLumi::GetLumi(const edm::InputTag& lumiInputTag, double lumiScale)
0018     : lumiInputTag_(lumiInputTag), lumiScale_(lumiScale) {}
0019 
0020 GetLumi::GetLumi(const edm::ParameterSet& iConfig, edm::ConsumesCollector& iC) : GetLumi(iConfig) {
0021   lumiDetailsToken_ = iC.consumes<LumiDetails>(lumiInputTag_);
0022   lumiSummaryToken_ = iC.consumes<LumiSummary, edm::InLumi>(lumiInputTag_);
0023 }
0024 
0025 GetLumi::GetLumi(const edm::InputTag& lumiInputTag, double lumiScale, edm::ConsumesCollector& iC)
0026     : GetLumi(lumiInputTag, lumiScale) {
0027   lumiDetailsToken_ = iC.consumes<LumiDetails>(lumiInputTag_);
0028   lumiSummaryToken_ = iC.consumes<LumiSummary, edm::InLumi>(lumiInputTag_);
0029 }
0030 
0031 GetLumi::~GetLumi() = default;
0032 
0033 double GetLumi::getRawValue(const edm::Event& iEvent) {
0034   // taken from
0035   // DPGAnalysis/SiStripTools/src/DigiLumiCorrHistogramMaker.cc
0036   // the scale factor 6.37 should follow the lumi prescriptions
0037   edm::Handle<LumiDetails> lumi;
0038   iEvent.getLuminosityBlock().getByToken(lumiSummaryToken_, lumi);
0039 
0040   double bxlumi = -1.;
0041   if (lumi->isValid()) {
0042     bxlumi = lumi->lumiValue(LumiDetails::kOCC1, iEvent.bunchCrossing());
0043   }
0044 
0045   return bxlumi;
0046 }
0047 
0048 double GetLumi::getValue(const edm::Event& iEvent) {
0049   //    bxlumi = lumi->lumiValue(LumiDetails::kOCC1,iEvent.bunchCrossing())*6.37;
0050   return getRawValue(iEvent) * lumiScale_;
0051 }
0052 
0053 double GetLumi::getRawValue(edm::LuminosityBlock const& lumiBlock, edm::EventSetup const& eSetup) {
0054   double lumi = -1.;
0055   double intDelLumi = -1.;
0056 
0057   //  size_t LS = lumiBlock.luminosityBlockAuxiliary().luminosityBlock();
0058   // accumulate HF data at every LS as it is closed.
0059   // note: lumi unit from DIPLumiSummary and Detail is microbarns
0060   edm::Handle<LumiSummary> lumiSummary_;
0061   lumiBlock.getByToken(lumiSummaryToken_, lumiSummary_);
0062   if (lumiSummary_->isValid()) {
0063     lumi = lumiSummary_->avgInsDelLumi();
0064     intDelLumi = lumiSummary_->intgDelLumi();
0065     edm::LogInfo("GetLumi") << "Luminosity in this Lumi Section " << lumi << " --> " << intDelLumi << std::endl;
0066   } else {
0067     edm::LogWarning("GetLumi") << "No valid data found!" << std::endl;
0068   }
0069 
0070   return lumi;
0071 }
0072 
0073 double GetLumi::getValue(edm::LuminosityBlock const& lumiBlock, edm::EventSetup const& eSetup) {
0074   return getRawValue(lumiBlock, eSetup) * lumiScale_;
0075 }
0076 
0077 double GetLumi::convert2PU(double instLumi,
0078                            double inelastic_xSec = GetLumi::INELASTIC_XSEC_8TeV)  // inelastic_xSec in mb
0079 {
0080   // from https://cmswbm.web.cern.ch/cmswbm/images/pileup.png
0081   return instLumi * inelastic_xSec / FREQ_ORBIT;
0082 }
0083 
0084 double GetLumi::convert2PU(double instLumi, int sqrt_s = GetLumi::SQRT_S_8TeV) {
0085   double inelastic_xSec = 0.;
0086 
0087   switch (sqrt_s) {
0088     case GetLumi::SQRT_S_7TeV:
0089       inelastic_xSec = GetLumi::INELASTIC_XSEC_7TeV;
0090       break;
0091     case GetLumi::SQRT_S_8TeV:
0092       inelastic_xSec = GetLumi::INELASTIC_XSEC_8TeV;
0093       break;
0094     default:
0095       break;
0096   }
0097 
0098   return convert2PU(instLumi, inelastic_xSec);
0099 }