Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-17 02:46:43

0001 #include "DQM/TrackingMonitor/interface/V0Monitor.h"
0002 #include "CommonTools/TriggerUtils/interface/GenericTriggerEventFlag.h"
0003 
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 
0006 #include "RecoVertex/VertexTools/interface/VertexDistance3D.h"
0007 #include "DataFormats/VertexReco/interface/Vertex.h"
0008 
0009 #include "DQM/TrackingMonitor/interface/GetLumi.h"
0010 
0011 // -----------------------------
0012 //  constructors and destructor
0013 // -----------------------------
0014 
0015 V0Monitor::V0Monitor(const edm::ParameterSet& iConfig)
0016     : folderName_(iConfig.getParameter<std::string>("FolderName")),
0017       v0Token_(consumes<reco::VertexCompositeCandidateCollection>(iConfig.getParameter<edm::InputTag>("v0"))),
0018       bsToken_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot"))),
0019       pvToken_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("primaryVertex"))),
0020       lumiscalersToken_(consumes<LumiScalersCollection>(iConfig.getParameter<edm::InputTag>("lumiScalers"))),
0021       metaDataToken_(consumes<OnlineLuminosityRecord>(iConfig.getParameter<edm::InputTag>("metadata"))),
0022       forceSCAL_(iConfig.getParameter<bool>("forceSCAL")),
0023       pvNDOF_(iConfig.getParameter<int>("pvNDOF")),
0024       genTriggerEventFlag_(new GenericTriggerEventFlag(
0025           iConfig.getParameter<edm::ParameterSet>("genericTriggerEventPSet"), consumesCollector(), *this)) {
0026   v0_N_ = nullptr;
0027   v0_mass_ = nullptr;
0028   v0_pt_ = nullptr;
0029   v0_eta_ = nullptr;
0030   v0_phi_ = nullptr;
0031   v0_Lxy_ = nullptr;
0032   v0_Lxy_wrtBS_ = nullptr;
0033   v0_chi2oNDF_ = nullptr;
0034   v0_mass_vs_p_ = nullptr;
0035   v0_mass_vs_pt_ = nullptr;
0036   v0_mass_vs_eta_ = nullptr;
0037   v0_deltaMass_ = nullptr;
0038   v0_deltaMass_vs_pt_ = nullptr;
0039   v0_deltaMass_vs_eta_ = nullptr;
0040 
0041   v0_Lxy_vs_deltaMass_ = nullptr;
0042   v0_Lxy_vs_pt_ = nullptr;
0043   v0_Lxy_vs_eta_ = nullptr;
0044 
0045   n_vs_BX_ = nullptr;
0046   v0_N_vs_BX_ = nullptr;
0047   v0_mass_vs_BX_ = nullptr;
0048   v0_Lxy_vs_BX_ = nullptr;
0049   v0_deltaMass_vs_BX_ = nullptr;
0050 
0051   n_vs_lumi_ = nullptr;
0052   v0_N_vs_lumi_ = nullptr;
0053   v0_mass_vs_lumi_ = nullptr;
0054   v0_Lxy_vs_lumi_ = nullptr;
0055   v0_deltaMass_vs_lumi_ = nullptr;
0056 
0057   n_vs_PU_ = nullptr;
0058   v0_N_vs_PU_ = nullptr;
0059   v0_mass_vs_PU_ = nullptr;
0060   v0_Lxy_vs_PU_ = nullptr;
0061   v0_deltaMass_vs_PU_ = nullptr;
0062 
0063   n_vs_LS_ = nullptr;
0064   v0_N_vs_LS_ = nullptr;
0065 
0066   edm::ParameterSet histoPSet = iConfig.getParameter<edm::ParameterSet>("histoPSet");
0067   getHistoPSet(histoPSet.getParameter<edm::ParameterSet>("massPSet"), mass_binning_);
0068   getHistoPSet(histoPSet.getParameter<edm::ParameterSet>("ptPSet"), pt_binning_);
0069   getHistoPSet(histoPSet.getParameter<edm::ParameterSet>("etaPSet"), eta_binning_);
0070   getHistoPSet(histoPSet.getParameter<edm::ParameterSet>("LxyPSet"), Lxy_binning_);
0071   getHistoPSet(histoPSet.getParameter<edm::ParameterSet>("chi2oNDFPSet"), chi2oNDF_binning_);
0072   getHistoPSet(histoPSet.getParameter<edm::ParameterSet>("lumiPSet"), lumi_binning_);
0073   getHistoPSet(histoPSet.getParameter<edm::ParameterSet>("puPSet"), pu_binning_);
0074   getHistoPSet(histoPSet.getParameter<edm::ParameterSet>("lsPSet"), ls_binning_);
0075 }
0076 
0077 V0Monitor::~V0Monitor() {
0078   if (genTriggerEventFlag_)
0079     delete genTriggerEventFlag_;
0080 }
0081 
0082 void V0Monitor::getHistoPSet(edm::ParameterSet pset, MEbinning& mebinning) {
0083   mebinning.nbins = pset.getParameter<int32_t>("nbins");
0084   mebinning.xmin = pset.getParameter<double>("xmin");
0085   mebinning.xmax = pset.getParameter<double>("xmax");
0086 }
0087 
0088 V0Monitor::MonitorElement* V0Monitor::bookHisto1D(DQMStore::IBooker& ibooker,
0089                                                   std::string name,
0090                                                   std::string title,
0091                                                   std::string xaxis,
0092                                                   std::string yaxis,
0093                                                   MEbinning binning) {
0094   std::string title_w_axes = title + ";" + xaxis + ";" + yaxis;
0095   return ibooker.book1D(name, title_w_axes, binning.nbins, binning.xmin, binning.xmax);
0096 }
0097 V0Monitor::MonitorElement* V0Monitor::bookHisto2D(DQMStore::IBooker& ibooker,
0098                                                   std::string name,
0099                                                   std::string title,
0100                                                   std::string xaxis,
0101                                                   std::string yaxis,
0102                                                   MEbinning xbinning,
0103                                                   MEbinning ybinning) {
0104   std::string title_w_axes = title + ";" + xaxis + ";" + yaxis;
0105   return ibooker.book2D(
0106       name, title_w_axes, xbinning.nbins, xbinning.xmin, xbinning.xmax, ybinning.nbins, ybinning.xmin, ybinning.xmax);
0107 }
0108 V0Monitor::MonitorElement* V0Monitor::bookProfile(DQMStore::IBooker& ibooker,
0109                                                   std::string name,
0110                                                   std::string title,
0111                                                   std::string xaxis,
0112                                                   std::string yaxis,
0113                                                   MEbinning xbinning,
0114                                                   MEbinning ybinning) {
0115   std::string title_w_axes = title + ";" + xaxis + ";" + yaxis;
0116   return ibooker.bookProfile(
0117       name, title_w_axes, xbinning.nbins, xbinning.xmin, xbinning.xmax, ybinning.xmin, ybinning.xmax);
0118 }
0119 
0120 void V0Monitor::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) {
0121   std::string histname, histtitle;
0122 
0123   std::string currentFolder = folderName_;
0124   ibooker.setCurrentFolder(currentFolder);
0125 
0126   MEbinning N_binning;
0127   N_binning.nbins = 15;
0128   N_binning.xmin = -0.5;
0129   N_binning.xmax = 14.5;
0130   v0_N_ = bookHisto1D(ibooker, "v0_N", "# v0", "# v0", "events", N_binning);
0131   v0_mass_ = bookHisto1D(ibooker, "v0_mass", "mass", "mass [GeV]", "events", mass_binning_);
0132   v0_pt_ = bookHisto1D(ibooker, "v0_pt", "pt", "p_{T} [GeV]", "events", pt_binning_);
0133   v0_eta_ = bookHisto1D(ibooker, "v0_eta", "eta", "#eta", "events", eta_binning_);
0134   MEbinning phi_binning;
0135   phi_binning.nbins = 34;
0136   phi_binning.xmin = -3.2;
0137   phi_binning.xmax = 3.2;
0138   v0_phi_ = bookHisto1D(ibooker, "v0_phi", "phi", "#phi [rad]", "events", phi_binning);
0139   v0_Lxy_ = bookHisto1D(ibooker, "v0_Lxy", "Lxy", "L_{xy} w.r.t. PV [cm]", "events", Lxy_binning_);
0140   v0_Lxy_wrtBS_ = bookHisto1D(ibooker, "v0_Lxy_wrtBS", "Lxy", "L_{xy} w.r.t. BS [cm]", "events", Lxy_binning_);
0141   v0_chi2oNDF_ =
0142       bookHisto1D(ibooker, "v0_chi2oNDF", "chi2oNDF", "vertex normalized #chi^{2}", "events", chi2oNDF_binning_);
0143 
0144   v0_mass_vs_p_ =
0145       bookProfile(ibooker, "v0_mass_vs_p", "mass vs p", "p [GeV]", "mass [GeV]", pt_binning_, mass_binning_);
0146   v0_mass_vs_pt_ =
0147       bookProfile(ibooker, "v0_mass_vs_pt", "mass vs pt", "p_{T} [GeV]", "mass [GeV]", pt_binning_, mass_binning_);
0148   v0_mass_vs_eta_ =
0149       bookProfile(ibooker, "v0_mass_vs_eta", "mass vs eta", "#eta", "mass [GeV]", eta_binning_, mass_binning_);
0150 
0151   MEbinning delta_binning;
0152   delta_binning.nbins = 150;
0153   delta_binning.xmin = -0.15;
0154   delta_binning.xmax = 0.15;
0155   v0_deltaMass_ = bookHisto1D(ibooker, "v0_deltaMass", "deltaMass", "m-m_{PDG}/m_{DPG}", "events", delta_binning);
0156   v0_deltaMass_vs_pt_ = bookProfile(
0157       ibooker, "v0_deltaMass_vs_pt", "deltaMass vs pt", "p_{T} [GeV]", "m-m_{PDG}/m_{DPG}", pt_binning_, delta_binning);
0158   v0_deltaMass_vs_eta_ = bookProfile(
0159       ibooker, "v0_deltaMass_vs_eta", "deltaMass vs eta", "#eta", "m-m_{PDG}/m_{DPG}", eta_binning_, delta_binning);
0160 
0161   v0_Lxy_vs_deltaMass_ = bookProfile(ibooker,
0162                                      "v0_Lxy_vs_deltaMass",
0163                                      "L_{xy} vs deltaMass",
0164                                      "m-m_{PDG}/m_{DPG}",
0165                                      "L_{xy} [cm]",
0166                                      delta_binning,
0167                                      Lxy_binning_);
0168   v0_Lxy_vs_pt_ =
0169       bookProfile(ibooker, "v0_Lxy_vs_pt", "L_{xy} vs p_{T}", "p_{T} [GeV]", "L_{xy} [cm]", pt_binning_, Lxy_binning_);
0170   v0_Lxy_vs_eta_ =
0171       bookProfile(ibooker, "v0_Lxy_vs_eta", "L_{xy} vs #eta", "#eta", "L_{xy} [cm]", eta_binning_, Lxy_binning_);
0172 
0173   MEbinning bx_binning;
0174   bx_binning.nbins = 3564;
0175   bx_binning.xmin = 0.5;
0176   bx_binning.xmax = 3564.5;
0177   n_vs_BX_ = bookHisto1D(ibooker, "n_vs_BX", "# events vs BX", "BX", "# events", bx_binning);
0178   v0_N_vs_BX_ = bookProfile(ibooker, "v0_N_vs_BX", "# v0 vs BX", "BX", "# v0", bx_binning, N_binning);
0179   v0_mass_vs_BX_ = bookProfile(ibooker, "v0_mass_vs_BX", "mass vs BX", "BX", "mass [GeV]", bx_binning, mass_binning_);
0180   v0_Lxy_vs_BX_ = bookProfile(ibooker, "v0_Lxy_vs_BX", "L_{xy} vs BX", "BX", "L_{xy} [cm]", bx_binning, Lxy_binning_);
0181   v0_deltaMass_vs_BX_ = bookProfile(
0182       ibooker, "v0_deltaMass_vs_BX", "deltaMass vs BX", "BX", "m-m_{PDG}/m_{DPG}", bx_binning, delta_binning);
0183 
0184   n_vs_lumi_ = bookHisto1D(
0185       ibooker, "n_vs_lumi", "# events vs lumi", "inst. lumi x10^{30} [Hz cm^{-2}]", "# events", lumi_binning_);
0186   v0_N_vs_lumi_ = bookProfile(
0187       ibooker, "v0_N_vs_lumi", "# v0 vs lumi", "inst. lumi x10^{30} [Hz cm^{-2}]", "# v0", lumi_binning_, N_binning);
0188   v0_mass_vs_lumi_ = bookProfile(ibooker,
0189                                  "v0_mass_vs_lumi",
0190                                  "mass vs lumi",
0191                                  "inst. lumi x10^{30} [Hz cm^{-2}]",
0192                                  "mass [GeV]",
0193                                  lumi_binning_,
0194                                  mass_binning_);
0195   v0_Lxy_vs_lumi_ = bookProfile(ibooker,
0196                                 "v0_Lxy_vs_lumi",
0197                                 "L_{xy} vs lumi",
0198                                 "inst. lumi x10^{30} [Hz cm^{-2}]",
0199                                 "L_{xy} [cm]",
0200                                 lumi_binning_,
0201                                 Lxy_binning_);
0202   v0_deltaMass_vs_lumi_ = bookProfile(ibooker,
0203                                       "v0_deltaMass_vs_lumi",
0204                                       "deltaMass vs lumi",
0205                                       "inst. lumi x10^{30} [Hz cm^{-2}]",
0206                                       "m-m_{PDG}/m_{DPG}",
0207                                       lumi_binning_,
0208                                       delta_binning);
0209 
0210   n_vs_PU_ = bookHisto1D(ibooker, "n_vs_PU", "# events vs PU", "# good PV", "# events", pu_binning_);
0211   v0_N_vs_PU_ = bookProfile(ibooker, "v0_N_vs_PU", "# v0 vs PU", "# good PV", "# v0", pu_binning_, N_binning);
0212   v0_mass_vs_PU_ =
0213       bookProfile(ibooker, "v0_mass_vs_PU", "mass vs PU", "# good PV", "mass [GeV]", pu_binning_, mass_binning_);
0214   v0_Lxy_vs_PU_ =
0215       bookProfile(ibooker, "v0_Lxy_vs_PU", "L_{xy} vs PU", "# good PV", "L_{xy} [cm]", pu_binning_, Lxy_binning_);
0216   v0_deltaMass_vs_PU_ = bookProfile(
0217       ibooker, "v0_deltaMass_vs_PU", "deltaMass vs PU", "# good PV", "m-m_{PDG}/m_{DPG}", pu_binning_, delta_binning);
0218 
0219   n_vs_LS_ = bookHisto1D(ibooker, "n_vs_LS", "# events vs LS", "LS", "# events", ls_binning_);
0220   v0_N_vs_LS_ = bookProfile(ibooker, "v0_N_vs_LS", "# v0 vs LS", "LS", "# v0", ls_binning_, N_binning);
0221   v0_N_vs_LS_->getTH1()->SetCanExtend(TH1::kAllAxes);
0222 
0223   // Initialize the GenericTriggerEventFlag
0224   if (genTriggerEventFlag_->on())
0225     genTriggerEventFlag_->initRun(iRun, iSetup);
0226 }
0227 
0228 void V0Monitor::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
0229   // Filter out events if Trigger Filtering is requested
0230   if (genTriggerEventFlag_->on() && !genTriggerEventFlag_->accept(iEvent, iSetup))
0231     return;
0232 
0233   //  int ls = iEvent.id().luminosityBlock();
0234 
0235   size_t bx = iEvent.bunchCrossing();
0236   n_vs_BX_->Fill(bx);
0237 
0238   float lumi = -1.;
0239   if (forceSCAL_) {
0240     edm::Handle<LumiScalersCollection> lumiScalers = iEvent.getHandle(lumiscalersToken_);
0241     if (lumiScalers.isValid() && !lumiScalers->empty()) {
0242       LumiScalersCollection::const_iterator scalit = lumiScalers->begin();
0243       lumi = scalit->instantLumi();
0244     }
0245   } else {
0246     edm::Handle<OnlineLuminosityRecord> metaData = iEvent.getHandle(metaDataToken_);
0247     if (metaData.isValid())
0248       lumi = metaData->instLumi();
0249   }
0250 
0251   n_vs_lumi_->Fill(lumi);
0252 
0253   edm::Handle<reco::BeamSpot> beamspotHandle = iEvent.getHandle(bsToken_);
0254   reco::BeamSpot const* bs = nullptr;
0255   if (beamspotHandle.isValid())
0256     bs = &(*beamspotHandle);
0257 
0258   edm::Handle<reco::VertexCollection> pvHandle = iEvent.getHandle(pvToken_);
0259   reco::Vertex const* pv = nullptr;
0260   size_t nPV = 0;
0261   if (pvHandle.isValid()) {
0262     pv = &pvHandle->front();
0263     //--- pv fake (the pv collection should have size==1 and the pv==beam spot)
0264     if (pv->isFake() ||
0265         pv->tracksSize() == 0
0266         // definition of goodOfflinePrimaryVertex
0267         || pv->ndof() < pvNDOF_ || pv->z() > 24.)
0268       pv = nullptr;
0269 
0270     for (const auto& v : *pvHandle) {
0271       if (v.isFake())
0272         continue;
0273       if (v.ndof() < pvNDOF_)
0274         continue;
0275       if (v.z() > 24.)
0276         continue;
0277       ++nPV;
0278     }
0279   }
0280   n_vs_PU_->Fill(nPV);
0281 
0282   float nLS = static_cast<float>(iEvent.id().luminosityBlock());
0283   n_vs_LS_->Fill(nLS);
0284 
0285   edm::Handle<reco::VertexCompositeCandidateCollection> v0Handle = iEvent.getHandle(v0Token_);
0286   int n = (v0Handle.isValid() ? v0Handle->size() : -1);
0287   v0_N_->Fill(n);
0288   v0_N_vs_BX_->Fill(bx, n);
0289   v0_N_vs_lumi_->Fill(lumi, n);
0290   v0_N_vs_PU_->Fill(nPV, n);
0291   v0_N_vs_LS_->Fill(nLS, n);
0292 
0293   if (!v0Handle.isValid() or n == 0)
0294     return;
0295 
0296   reco::VertexCompositeCandidateCollection v0s = *v0Handle.product();
0297   for (const auto& v0 : v0s) {
0298     float mass = v0.mass();
0299     float pt = v0.pt();
0300     float p = v0.p();
0301     float eta = v0.eta();
0302     float phi = v0.phi();
0303     int pdgID = v0.pdgId();
0304     float chi2oNDF = v0.vertexNormalizedChi2();
0305     GlobalPoint displacementFromPV =
0306         (pv == nullptr ? GlobalPoint(-9., -9., 0) : GlobalPoint((pv->x() - v0.vx()), (pv->y() - v0.vy()), 0.));
0307     GlobalPoint displacementFromBS =
0308         (bs == nullptr
0309              ? GlobalPoint(-9., -9., 0.)
0310              : GlobalPoint(-1 * ((bs->position().x() - v0.vx()) + (v0.vz() - bs->position().z()) * bs->dxdz()),
0311                            -1 * ((bs->position().y() - v0.vy()) + (v0.vz() - bs->position().z()) * bs->dydz()),
0312                            0));
0313     float lxy = (pv == nullptr ? -9. : displacementFromPV.perp());
0314     float lxyWRTbs = (bs == nullptr ? -9. : displacementFromBS.perp());
0315 
0316     v0_mass_->Fill(mass);
0317     v0_pt_->Fill(pt);
0318     v0_eta_->Fill(eta);
0319     v0_phi_->Fill(phi);
0320     v0_Lxy_->Fill(lxy);
0321     v0_Lxy_wrtBS_->Fill(lxyWRTbs);
0322     v0_chi2oNDF_->Fill(chi2oNDF);
0323 
0324     v0_mass_vs_p_->Fill(p, mass);
0325     v0_mass_vs_pt_->Fill(pt, mass);
0326     v0_mass_vs_eta_->Fill(eta, mass);
0327     v0_mass_vs_BX_->Fill(bx, mass);
0328     v0_mass_vs_lumi_->Fill(lumi, mass);
0329     v0_mass_vs_PU_->Fill(nPV, mass);
0330 
0331     v0_Lxy_vs_BX_->Fill(bx, lxy);
0332     v0_Lxy_vs_lumi_->Fill(lumi, lxy);
0333     v0_Lxy_vs_PU_->Fill(nPV, lxy);
0334 
0335     float PDGmass = -9999.;
0336     switch (pdgID) {
0337       case 130:              // K_s
0338       case 310:              // K_L
0339         PDGmass = 0.497614;  // GeV
0340         break;
0341       case 3122:             // Lambda
0342       case -3122:            // Lambda
0343         PDGmass = 1.115683;  // GeV
0344         break;
0345       case 4122:   // Lambda_c
0346       case -4122:  // Lambda_c
0347       case 5122:   // Lambda_b
0348       case -5122:  // Lambda_b
0349       default:
0350         break;
0351     }
0352     float delta = (PDGmass > 0. ? (mass - PDGmass) / PDGmass : -9.);
0353     v0_deltaMass_->Fill(delta);
0354     v0_deltaMass_vs_pt_->Fill(pt, delta);
0355     v0_deltaMass_vs_eta_->Fill(eta, delta);
0356     v0_deltaMass_vs_BX_->Fill(bx, delta);
0357     v0_deltaMass_vs_lumi_->Fill(lumi, delta);
0358     v0_deltaMass_vs_PU_->Fill(nPV, delta);
0359 
0360     v0_Lxy_vs_deltaMass_->Fill(delta, lxy);
0361     v0_Lxy_vs_pt_->Fill(pt, lxy);
0362     v0_Lxy_vs_eta_->Fill(eta, lxy);
0363   }
0364 }
0365 
0366 // Define this as a plug-in
0367 #include "FWCore/Framework/interface/MakerMacros.h"
0368 DEFINE_FWK_MODULE(V0Monitor);