Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:42:50

0001 #include "DQM/Physics/src/ExoticaDQM.h"
0002 
0003 using namespace edm;
0004 using namespace std;
0005 using namespace reco;
0006 
0007 typedef vector<string> vstring;
0008 
0009 //
0010 // -- Constructor
0011 //
0012 ExoticaDQM::ExoticaDQM(const edm::ParameterSet& ps) {
0013   edm::LogInfo("ExoticaDQM") << " Starting ExoticaDQM "
0014                              << "\n";
0015 
0016   typedef std::vector<edm::InputTag> vtag;
0017 
0018   // Get parameters from configuration file
0019   //
0020   VertexToken_ = consumes<reco::VertexCollection>(ps.getParameter<InputTag>("vertexCollection"));
0021   //
0022   ElectronToken_ = consumes<reco::GsfElectronCollection>(ps.getParameter<InputTag>("electronCollection"));
0023   //
0024   MuonToken_ = consumes<reco::MuonCollection>(ps.getParameter<InputTag>("muonCollection"));
0025   //
0026   PhotonToken_ = consumes<reco::PhotonCollection>(ps.getParameter<InputTag>("photonCollection"));
0027   //
0028   PFJetToken_ = consumes<reco::PFJetCollection>(ps.getParameter<InputTag>("pfJetCollection"));
0029   //
0030   DiJetPFJetCollection_ = ps.getParameter<std::vector<edm::InputTag> >("DiJetPFJetCollection");
0031   for (std::vector<edm::InputTag>::const_iterator jetlabel = DiJetPFJetCollection_.begin(),
0032                                                   jetlabelEnd = DiJetPFJetCollection_.end();
0033        jetlabel != jetlabelEnd;
0034        ++jetlabel) {
0035     DiJetPFJetToken_.push_back(consumes<reco::PFJetCollection>(*jetlabel));
0036   }
0037   //
0038   PFMETToken_ = consumes<reco::PFMETCollection>(ps.getParameter<InputTag>("pfMETCollection"));
0039   //
0040   ecalBarrelRecHitToken_ = consumes<EBRecHitCollection>(
0041       ps.getUntrackedParameter<InputTag>("ecalBarrelRecHit", InputTag("reducedEcalRecHitsEB")));
0042   //
0043   ecalEndcapRecHitToken_ = consumes<EERecHitCollection>(
0044       ps.getUntrackedParameter<InputTag>("ecalEndcapRecHit", InputTag("reducedEcalRecHitsEE")));
0045   //
0046   TrackToken_ = consumes<reco::TrackCollection>(ps.getParameter<InputTag>("trackCollection"));
0047   //
0048   MuonDispToken_ = consumes<reco::TrackCollection>(ps.getParameter<InputTag>("displacedMuonCollection"));
0049   //
0050   MuonDispSAToken_ = consumes<reco::TrackCollection>(ps.getParameter<InputTag>("displacedSAMuonCollection"));
0051   //
0052   GenParticleToken_ = consumes<reco::GenParticleCollection>(ps.getParameter<InputTag>("genParticleCollection"));
0053 
0054   JetCorrectorToken_ = consumes<reco::JetCorrector>(ps.getParameter<edm::InputTag>("jetCorrector"));
0055 
0056   magFieldToken_ = esConsumes();
0057   //Cuts - MultiJets
0058   jetID = new reco::helper::JetIDHelper(ps.getParameter<ParameterSet>("JetIDParams"), consumesCollector());
0059 
0060   //Varibles and Cuts for each Module:
0061   //Dijet
0062   dijet_PFJet1_pt_cut_ = ps.getParameter<double>("dijet_PFJet1_pt_cut");
0063   dijet_PFJet2_pt_cut_ = ps.getParameter<double>("dijet_PFJet2_pt_cut");
0064   //DiMuon
0065   dimuon_Muon1_pt_cut_ = ps.getParameter<double>("dimuon_Muon1_pt_cut");
0066   dimuon_Muon2_pt_cut_ = ps.getParameter<double>("dimuon_Muon2_pt_cut");
0067   //DiElectron
0068   dielectron_Electron1_pt_cut_ = ps.getParameter<double>("dielectron_Electron2_pt_cut");
0069   dielectron_Electron2_pt_cut_ = ps.getParameter<double>("dielectron_Electron2_pt_cut");
0070   //DiPhoton
0071   diphoton_Photon1_pt_cut_ = ps.getParameter<double>("diphoton_Photon2_pt_cut");
0072   diphoton_Photon2_pt_cut_ = ps.getParameter<double>("diphoton_Photon2_pt_cut");
0073   //MonoJet
0074   monojet_PFJet_pt_cut_ = ps.getParameter<double>("monojet_PFJet_pt_cut");
0075   monojet_PFJet_met_cut_ = ps.getParameter<double>("monojet_PFJet_met_cut");
0076   //MonoMuon
0077   monomuon_Muon_pt_cut_ = ps.getParameter<double>("monomuon_Muon_pt_cut");
0078   monomuon_Muon_met_cut_ = ps.getParameter<double>("monomuon_Muon_met_cut");
0079   //MonoElectron
0080   monoelectron_Electron_pt_cut_ = ps.getParameter<double>("monoelectron_Electron_pt_cut");
0081   monoelectron_Electron_met_cut_ = ps.getParameter<double>("monoelectron_Electron_met_cut");
0082   //MonoPhoton
0083   monophoton_Photon_pt_cut_ = ps.getParameter<double>("monophoton_Photon_pt_cut");
0084   monophoton_Photon_met_cut_ = ps.getParameter<double>("monophoton_Photon_met_cut");
0085   // Displaced lepton or jet
0086   dispFermion_eta_cut_ = ps.getParameter<double>("dispFermion_eta_cut");
0087   dispFermion_pt_cut_ = ps.getParameter<double>("dispFermion_pt_cut");
0088 }
0089 
0090 //
0091 // -- Destructor
0092 //
0093 ExoticaDQM::~ExoticaDQM() {
0094   edm::LogInfo("ExoticaDQM") << " Deleting ExoticaDQM "
0095                              << "\n";
0096 }
0097 
0098 //
0099 //  -- Book histograms
0100 //
0101 void ExoticaDQM::bookHistograms(DQMStore::IBooker& bei, edm::Run const&, edm::EventSetup const&) {
0102   bei.cd();
0103 
0104   //--- DiJet
0105   for (unsigned int icoll = 0; icoll < DiJetPFJetCollection_.size(); ++icoll) {
0106     std::stringstream ss;
0107     ss << "Physics/Exotica/Dijets/" << DiJetPFJetCollection_[icoll].label();
0108     bei.setCurrentFolder(ss.str());
0109     //bei.setCurrentFolder("Physics/Exotica/Dijets");
0110     dijet_PFJet_pt.push_back(bei.book1D("dijet_PFJet_pt", "Pt of PFJet (GeV)", 50, 30.0, 5000));
0111     dijet_PFJet_eta.push_back(bei.book1D("dijet_PFJet_eta", "#eta (PFJet)", 50, -2.5, 2.5));
0112     dijet_PFJet_phi.push_back(bei.book1D("dijet_PFJet_phi", "#phi (PFJet)", 50, -3.14, 3.14));
0113     dijet_PFJet_rapidity.push_back(bei.book1D("dijet_PFJet_rapidity", "Rapidity (PFJet)", 50, -6.0, 6.0));
0114     dijet_PFJet_mass.push_back(bei.book1D("dijet_PFJet_mass", "Mass (PFJets)", 50, 0., 500.));
0115     dijet_deltaPhiPFJet1PFJet2.push_back(
0116         bei.book1D("dijet_deltaPhiPFJet1PFJet2", "#Delta#phi(Leading PFJet, Sub PFJet)", 40, 0., 3.15));
0117     dijet_deltaEtaPFJet1PFJet2.push_back(
0118         bei.book1D("dijet_deltaEtaPFJet1PFJet2", "#Delta#eta(Leading PFJet, Sub PFJet)", 40, -5., 5.));
0119     dijet_deltaRPFJet1PFJet2.push_back(
0120         bei.book1D("dijet_deltaRPFJet1PFJet2", "#DeltaR(Leading PFJet, Sub PFJet)", 50, 0., 6.));
0121     dijet_invMassPFJet1PFJet2.push_back(
0122         bei.book1D("dijet_invMassPFJet1PFJet2", "Leading PFJet, SubLeading PFJet Invariant mass (GeV)", 50, 0., 8000.));
0123     dijet_PFchef.push_back(bei.book1D("dijet_PFchef", "Leading PFJet CHEF", 50, 0.0, 1.0));
0124     dijet_PFnhef.push_back(bei.book1D("dijet_PFnhef", "Leading PFJet NHEF", 50, 0.0, 1.0));
0125     dijet_PFcemf.push_back(bei.book1D("dijet_PFcemf", "Leading PFJet CEMF", 50, 0.0, 1.0));
0126     dijet_PFnemf.push_back(bei.book1D("dijet_PFnemf", "Leading PFJEt NEMF", 50, 0.0, 1.0));
0127     dijet_PFJetMulti.push_back(bei.book1D("dijet_PFJetMulti", "No. of PFJets", 10, 0., 10.));
0128   }
0129   //--- DiMuon
0130   bei.setCurrentFolder("Physics/Exotica/DiMuons");
0131   dimuon_Muon_pt = bei.book1D("dimuon_Muon_pt", "Pt of Muon (GeV)", 50, 30.0, 2000);
0132   dimuon_Muon_eta = bei.book1D("dimuon_Muon_eta", "#eta (Muon)", 50, -2.5, 2.5);
0133   dimuon_Muon_phi = bei.book1D("dimuon_Muon_phi", "#phi (Muon)", 50, -3.14, 3.14);
0134   dimuon_Charge = bei.book1D("dimuon_Charge", "Charge of the Muon", 10, -5., 5.);
0135   dimuon_deltaEtaMuon1Muon2 =
0136       bei.book1D("dimuon_deltaEtaMuon1Muon2", "#Delta#eta(Leading Muon, Sub Muon)", 40, -5., 5.);
0137   dimuon_deltaPhiMuon1Muon2 =
0138       bei.book1D("dimuon_deltaPhiMuon1Muon2", "#Delta#phi(Leading Muon, Sub Muon)", 40, 0., 3.15);
0139   dimuon_deltaRMuon1Muon2 = bei.book1D("dimuon_deltaRMuon1Muon2", "#DeltaR(Leading Muon, Sub Muon)", 50, 0., 6.);
0140   dimuon_invMassMuon1Muon2 =
0141       bei.book1D("dimuon_invMassMuon1Muon2", "Leading Muon, SubLeading Muon Low Invariant mass (GeV)", 50, 500., 4500.);
0142   dimuon_MuonMulti = bei.book1D("dimuon_MuonMulti", "No. of Muons", 10, 0., 10.);
0143   //--- DiElectrons
0144   bei.setCurrentFolder("Physics/Exotica/DiElectrons");
0145   dielectron_Electron_pt = bei.book1D("dielectron_Electron_pt", "Pt of Electron (GeV)", 50, 30.0, 2000);
0146   dielectron_Electron_eta = bei.book1D("dielectron_Electron_eta", "#eta (Electron)", 50, -2.5, 2.5);
0147   dielectron_Electron_phi = bei.book1D("dielectron_Electron_phi", "#phi (Electron)", 50, -3.14, 3.14);
0148   dielectron_Charge = bei.book1D("dielectron_Charge", "Charge of the Electron", 10, -5., 5.);
0149   dielectron_deltaEtaElectron1Electron2 =
0150       bei.book1D("dielectron_deltaEtaElectron1Electron2", "#Delta#eta(Leading Electron, Sub Electron)", 40, -5., 5.);
0151   dielectron_deltaPhiElectron1Electron2 =
0152       bei.book1D("dielectron_deltaPhiElectron1Electron2", "#Delta#phi(Leading Electron, Sub Electron)", 40, 0., 3.15);
0153   dielectron_deltaRElectron1Electron2 =
0154       bei.book1D("dielectron_deltaRElectron1Electron2", "#DeltaR(Leading Electron, Sub Electron)", 50, 0., 6.);
0155   dielectron_invMassElectron1Electron2 = bei.book1D("dielectron_invMassElectron1Electron2",
0156                                                     "Leading Electron, SubLeading Electron Invariant mass (GeV)",
0157                                                     50,
0158                                                     500.,
0159                                                     4500.);
0160   dielectron_ElectronMulti = bei.book1D("dielectron_ElectronMulti", "No. of Electrons", 10, 0., 10.);
0161   //--- DiPhotons
0162   bei.setCurrentFolder("Physics/Exotica/DiPhotons");
0163   diphoton_Photon_energy = bei.book1D("diphoton_Photon_energy", "Energy of Photon (GeV)", 50, 30.0, 300);
0164   diphoton_Photon_et = bei.book1D("diphoton_Photon_et", "Et of Photon (GeV)", 50, 30.0, 300);
0165   diphoton_Photon_pt = bei.book1D("diphoton_Photon_pt", "Pt of Photon (GeV)", 50, 30.0, 300);
0166   diphoton_Photon_eta = bei.book1D("diphoton_Photon_eta", "#eta (Photon)", 50, -2.5, 2.5);
0167   diphoton_Photon_etasc = bei.book1D("diphoton_Photon_etasc", "#eta sc(Photon)", 50, -2.5, 2.5);
0168   diphoton_Photon_phi = bei.book1D("diphoton_Photon_phi", "#phi (Photon)", 50, -3.14, 3.14);
0169   diphoton_Photon_hovere_eb = bei.book1D("diphoton_Photon_hovere_eb", "H/E (Photon) EB", 50, 0., 0.50);
0170   diphoton_Photon_hovere_ee = bei.book1D("diphoton_Photon_hovere_ee", "H/E (Photon) EE", 50, 0., 0.50);
0171   diphoton_Photon_sigmaietaieta_eb =
0172       bei.book1D("diphoton_Photon_sigmaietaieta_eb", "#sigma_{i #eta i #eta} (Photon) EB", 50, 0., 0.03);
0173   diphoton_Photon_sigmaietaieta_ee =
0174       bei.book1D("diphoton_Photon_sigmaietaieta_ee", "#sigma_{i #eta i #eta} (Photon) EE", 50, 0., 0.03);
0175   diphoton_Photon_trksumptsolidconedr03_eb =
0176       bei.book1D("diphoton_Photon_trksumptsolidconedr03_eb", "TrkSumPtDr03 (Photon) EB", 50, 0., 15.);
0177   diphoton_Photon_trksumptsolidconedr03_ee =
0178       bei.book1D("diphoton_Photon_trksumptsolidconedr03_ee", "TrkSumPtDr03 (Photon) EE", 50, 0., 15.);
0179   diphoton_Photon_e1x5e5x5_eb = bei.book1D("diphoton_Photon_e1x5e5x5_eb", "E_{1x5}/E_{5x5} (Photon) EB", 50, 0., 1.);
0180   diphoton_Photon_e1x5e5x5_ee = bei.book1D("diphoton_Photon_e1x5e5x5_ee", "E_{1x5}/E_{5x5} (Photon) EE", 50, 0., 1.);
0181   diphoton_Photon_e2x5e5x5_eb = bei.book1D("diphoton_Photon_e2x5e5x5_eb", "E_{2x5}/E_{5x5} (Photon) EB", 50, 0., 1.);
0182   diphoton_Photon_e2x5e5x5_ee = bei.book1D("diphoton_Photon_e2x5e5x5_ee", "E_{2x5}/E_{5x5} (Photon) EE", 50, 0., 1.);
0183   diphoton_deltaEtaPhoton1Photon2 =
0184       bei.book1D("diphoton_deltaEtaPhoton1Photon2", "#Delta#eta(SubLeading Photon, Sub Photon)", 40, -5., 5.);
0185   diphoton_deltaPhiPhoton1Photon2 =
0186       bei.book1D("diphoton_deltaPhiPhoton1Photon2", "#Delta#phi(SubLeading Photon, Sub Photon)", 40, 0., 3.15);
0187   diphoton_deltaRPhoton1Photon2 =
0188       bei.book1D("diphoton_deltaRPhoton1Photon2", "#DeltaR(SubLeading Photon, Sub Photon)", 50, 0., 6.);
0189   diphoton_invMassPhoton1Photon2 = bei.book1D(
0190       "diphoton_invMassPhoton1Photon2", "SubLeading Photon, SubSubLeading Photon Invariant mass (GeV)", 50, 500., 4500.);
0191   diphoton_PhotonMulti = bei.book1D("diphoton_PhotonMulti", "No. of Photons", 10, 0., 10.);
0192   //--- MonoJet
0193   bei.setCurrentFolder("Physics/Exotica/MonoJet");
0194   monojet_PFJet_pt = bei.book1D("monojet_PFJet_pt", "Pt of MonoJet (GeV)", 50, 30.0, 1000);
0195   monojet_PFJet_eta = bei.book1D("monojet_PFJet_eta", "#eta(MonoJet)", 50, -2.5, 2.5);
0196   monojet_PFJet_phi = bei.book1D("monojet_PFJet_phi", "#phi(MonoJet)", 50, -3.14, 3.14);
0197   monojet_PFMet = bei.book1D("monojet_PFMet", "Pt of PFMET (GeV)", 40, 0.0, 1000);
0198   monojet_PFMet_phi = bei.book1D("monojet_PFMet_phi", "#phi(PFMET #phi)", 50, -3.14, 3.14);
0199   monojet_PFJetPtOverPFMet = bei.book1D("monojet_PFJetPtOverPFMet", "Pt of MonoJet/MET (GeV)", 40, 0.0, 5.);
0200   monojet_deltaPhiPFJetPFMet = bei.book1D("monojet_deltaPhiPFJetPFMet", "#Delta#phi(MonoJet, PFMet)", 40, 0., 3.15);
0201   monojet_PFchef = bei.book1D("monojet_PFchef", "MonojetJet CHEF", 50, 0.0, 1.0);
0202   monojet_PFnhef = bei.book1D("monojet_PFnhef", "MonojetJet NHEF", 50, 0.0, 1.0);
0203   monojet_PFcemf = bei.book1D("monojet_PFcemf", "MonojetJet CEMF", 50, 0.0, 1.0);
0204   monojet_PFnemf = bei.book1D("monojet_PFnemf", "MonojetJet NEMF", 50, 0.0, 1.0);
0205   monojet_PFJetMulti = bei.book1D("monojet_PFJetMulti", "No. of PFJets", 10, 0., 10.);
0206   //--- MonoMuon
0207   bei.setCurrentFolder("Physics/Exotica/MonoMuon");
0208   monomuon_Muon_pt = bei.book1D("monomuon_Muon_pt", "Pt of Monomuon (GeV)", 50, 30.0, 2000);
0209   monomuon_Muon_eta = bei.book1D("monomuon_Muon_eta", "#eta(Monomuon)", 50, -2.5, 2.5);
0210   monomuon_Muon_phi = bei.book1D("monomuon_Muon_phi", "#phi(Monomuon)", 50, -3.14, 3.14);
0211   monomuon_Charge = bei.book1D("monomuon_Charge", "Charge of the MonoMuon", 10, -5., 5.);
0212   monomuon_PFMet = bei.book1D("monomuon_PFMet", "Pt of PFMET (GeV)", 40, 0.0, 2000);
0213   monomuon_PFMet_phi = bei.book1D("monomuon_PFMet_phi", "PFMET #phi", 50, -3.14, 3.14);
0214   monomuon_MuonPtOverPFMet = bei.book1D("monomuon_MuonPtOverPFMet", "Pt of Monomuon/PFMet", 40, 0.0, 5.);
0215   monomuon_deltaPhiMuonPFMet = bei.book1D("monomuon_deltaPhiMuonPFMet", "#Delta#phi(Monomuon, PFMet)", 40, 0., 3.15);
0216   monomuon_TransverseMass = bei.book1D("monomuon_TransverseMass", "Transverse Mass M_{T} GeV", 40, 200., 3000.);
0217   monomuon_MuonMulti = bei.book1D("monomuon_MuonMulti", "No. of Muons", 10, 0., 10.);
0218   //--- MonoElectron
0219   bei.setCurrentFolder("Physics/Exotica/MonoElectron");
0220   monoelectron_Electron_pt = bei.book1D("monoelectron_Electron_pt", "Pt of Monoelectron (GeV)", 50, 30.0, 4000);
0221   monoelectron_Electron_eta = bei.book1D("monoelectron_Electron_eta", "#eta(MonoElectron)", 50, -2.5, 2.5);
0222   monoelectron_Electron_phi = bei.book1D("monoelectron_Electron_phi", "#phi(MonoElectron)", 50, -3.14, 3.14);
0223   monoelectron_Charge = bei.book1D("monoelectron_Charge", "Charge of the MonoElectron", 10, -5., 5.);
0224   monoelectron_PFMet = bei.book1D("monoelectron_PFMet", "Pt of PFMET (GeV)", 40, 0.0, 4000);
0225   monoelectron_PFMet_phi = bei.book1D("monoelectron_PFMet_phi", "PFMET #phi", 50, -3.14, 3.14);
0226   monoelectron_ElectronPtOverPFMet =
0227       bei.book1D("monoelectron_ElectronPtOverPFMet", "Pt of Monoelectron/PFMet", 40, 0.0, 5.);
0228   monoelectron_deltaPhiElectronPFMet =
0229       bei.book1D("monoelectron_deltaPhiElectronPFMet", "#Delta#phi(MonoElectron, PFMet)", 40, 0., 3.15);
0230   monoelectron_TransverseMass = bei.book1D("monoelectron_TransverseMass", "Transverse Mass M_{T} GeV", 40, 200., 4000.);
0231   monoelectron_ElectronMulti = bei.book1D("monoelectron_ElectronMulti", "No. of Electrons", 10, 0., 10.);
0232 
0233   //--- DiPhotons
0234   bei.setCurrentFolder("Physics/Exotica/MonoPhotons");
0235   monophoton_Photon_energy = bei.book1D("monophoton_Photon_energy", "Energy of Leading Photon (GeV)", 50, 30.0, 1000);
0236   monophoton_Photon_et = bei.book1D("monophoton_Photon_et", "Et of Leading Photon (GeV)", 50, 30.0, 1000);
0237   monophoton_Photon_pt = bei.book1D("monophoton_Photon_pt", "Pt of Leading Photon (GeV)", 50, 30.0, 1000);
0238   monophoton_Photon_eta = bei.book1D("monophoton_Photon_eta", "#eta (Leading Photon)", 50, -2.5, 2.5);
0239   monophoton_Photon_etasc = bei.book1D("monophoton_Photon_etasc", "#eta sc(Leading Photon)", 50, -2.5, 2.5);
0240   monophoton_Photon_phi = bei.book1D("monophoton_Photon_phi", "#phi(Leading Photon)", 50, -3.14, 3.14);
0241   monophoton_Photon_hovere = bei.book1D("monophoton_Photon_hovere", "H/E (Leading Photon)", 50, 0., 0.50);
0242   monophoton_Photon_sigmaietaieta =
0243       bei.book1D("monophoton_Photon_sigmaietaieta", "#sigma_{i #eta i #eta} (Leading Photon)", 50, 0., 0.03);
0244   monophoton_Photon_trksumptsolidconedr03 =
0245       bei.book1D("monophoton_Photon_trksumptsolidconedr03", "TrkSumPtDr03 (Leading Photon)", 50, 0., 15.);
0246   monophoton_Photon_e1x5e5x5 = bei.book1D("monophoton_Photon_e1x5e5x5", "E_{1x5}/E_{5x5} (Leading Photon)", 50, 0., 1.);
0247   monophoton_Photon_e2x5e5x5 = bei.book1D("monophoton_Photon_e2x5e5x5", "E_{2x5}/E_{5x5} (Leading Photon)", 50, 0., 1.);
0248   monophoton_PFMet = bei.book1D("monophoton_PFMet", "Pt of PFMET (GeV)", 40, 0.0, 1000);
0249   monophoton_PFMet_phi = bei.book1D("monophoton_PFMet_phi", "PFMET #phi", 50, -3.14, 3.14);
0250   monophoton_PhotonPtOverPFMet = bei.book1D("monophoton_PhotonPtOverPFMet", "Pt of Monophoton/PFMet", 40, 0.0, 5.);
0251   monophoton_deltaPhiPhotonPFMet =
0252       bei.book1D("monophoton_deltaPhiPhotonPFMet", "#Delta#phi(SubLeading Photon, PFMet)", 40, 0., 3.15);
0253   monophoton_PhotonMulti = bei.book1D("monophoton_PhotonMulti", "No. of Photons", 10, 0., 10.);
0254 
0255   //--- Displaced Leptons (filled using only leptons from long-lived stop decay).
0256   bei.setCurrentFolder("Physics/Exotica/DisplacedFermions");
0257   dispElec_track_effi_lxy = bei.bookProfile("dispElec_track_effi_lxy",
0258                                             "Electron channel; transverse decay length (cm); track reco efficiency",
0259                                             10,
0260                                             0.,
0261                                             100.,
0262                                             -999.,
0263                                             999,
0264                                             "");
0265   dispElec_elec_effi_lxy = bei.bookProfile("dispElec_elec_effi_lxy",
0266                                            "Electron channel; transverse decay length (cm); electron reco efficiency",
0267                                            10,
0268                                            0.,
0269                                            100.,
0270                                            -999.,
0271                                            999,
0272                                            "");
0273   dispMuon_track_effi_lxy = bei.bookProfile("dispMuon_track_effi_lxy",
0274                                             "Muon channel; transverse decay length (cm); track reco efficiency",
0275                                             10,
0276                                             0.,
0277                                             100.,
0278                                             -999.,
0279                                             999,
0280                                             "");
0281   dispMuon_muon_effi_lxy = bei.bookProfile("dispMuon_muon_effi_lxy",
0282                                            "Muon channel; transverse decay length (cm); muon reco efficiency",
0283                                            10,
0284                                            0.,
0285                                            100.,
0286                                            -999.,
0287                                            999,
0288                                            "");
0289   dispMuon_muonDisp_effi_lxy =
0290       bei.bookProfile("dispMuon_muonDisp_effi_lxy",
0291                       "Muon channel; transverse decay length (cm); displacedMuon reco efficiency",
0292                       10,
0293                       0.,
0294                       100.,
0295                       -999.,
0296                       999,
0297                       "");
0298   dispMuon_muonDispSA_effi_lxy =
0299       bei.bookProfile("dispMuon_muonDispSA_effi_lxy",
0300                       "Muon channel; transverse decay length (cm); displacedSAMuon reco efficiency",
0301                       10,
0302                       0.,
0303                       400.,
0304                       -999.,
0305                       999,
0306                       "");
0307   //--- Displaced Jets (filled using only tracks or jets from long-lived stop decay).
0308   dispJet_track_effi_lxy = bei.bookProfile("dispJet_track_effi_lxy",
0309                                            "Jet channel; transverse decay length (cm); track reco efficiency",
0310                                            10,
0311                                            0.,
0312                                            100.,
0313                                            -999.,
0314                                            999,
0315                                            "");
0316 
0317   bei.cd();
0318 }
0319 
0320 //
0321 //  -- Analyze
0322 //
0323 void ExoticaDQM::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0324   // objects
0325 
0326   // Vertices
0327   bool ValidVertices = iEvent.getByToken(VertexToken_, VertexCollection_);
0328   if (!ValidVertices)
0329     return;
0330 
0331   // Electrons
0332   bool ValidGedGsfElectron = iEvent.getByToken(ElectronToken_, ElectronCollection_);
0333   if (!ValidGedGsfElectron)
0334     return;
0335 
0336   // Muons
0337   bool ValidPFMuon = iEvent.getByToken(MuonToken_, MuonCollection_);
0338   if (!ValidPFMuon)
0339     return;
0340 
0341   // Jets
0342   bool ValidPFJet = iEvent.getByToken(PFJetToken_, pfJetCollection_);
0343   pfjets = *pfJetCollection_;
0344   if (!ValidPFJet)
0345     return;
0346 
0347   // PFMETs
0348   bool ValidPFMET = iEvent.getByToken(PFMETToken_, pfMETCollection_);
0349   if (!ValidPFMET)
0350     return;
0351 
0352   // Photons
0353   bool ValidCaloPhoton = iEvent.getByToken(PhotonToken_, PhotonCollection_);
0354   if (!ValidCaloPhoton)
0355     return;
0356 
0357   // Tracks
0358   bool ValidTracks = iEvent.getByToken(TrackToken_, TrackCollection_);
0359   if (!ValidTracks)
0360     return;
0361 
0362   // Special collections for displaced particles
0363   iEvent.getByToken(MuonDispToken_, MuonDispCollection_);
0364   iEvent.getByToken(MuonDispSAToken_, MuonDispSACollection_);
0365 
0366   // MC truth
0367   bool ValidGenParticles = iEvent.getByToken(GenParticleToken_, GenCollection_);
0368 
0369   // JetCorrector
0370   bool ValidJetCorrector = iEvent.getByToken(JetCorrectorToken_, JetCorrector_);
0371 
0372   for (int i = 0; i < 2; i++) {
0373     //Jets
0374     PFJetPx[i] = 0.;
0375     PFJetPy[i] = 0.;
0376     PFJetPt[i] = 0.;
0377     PFJetEta[i] = 0.;
0378     PFJetPhi[i] = 0.;
0379     PFJetNHEF[i] = 0.;
0380     PFJetCHEF[i] = 0.;
0381     PFJetNEMF[i] = 0.;
0382     PFJetCEMF[i] = 0.;
0383     //Muons
0384     MuonPx[i] = 0.;
0385     MuonPy[i] = 0.;
0386     MuonPt[i] = 0.;
0387     MuonEta[i] = 0.;
0388     MuonPhi[i] = 0.;
0389     MuonCharge[i] = 0.;
0390     //Electrons
0391     ElectronPx[i] = 0.;
0392     ElectronPy[i] = 0.;
0393     ElectronPt[i] = 0.;
0394     ElectronEta[i] = 0.;
0395     ElectronPhi[i] = 0.;
0396     ElectronCharge[i] = 0.;
0397     //Photons
0398     PhotonEnergy[i] = 0.;
0399     PhotonPt[i] = 0.;
0400     PhotonEt[i] = 0.;
0401     PhotonEta[i] = 0.;
0402     PhotonEtaSc[i] = 0.;
0403     PhotonPhi[i] = 0.;
0404     PhotonHoverE[i] = 0.;
0405     PhotonSigmaIetaIeta[i] = 0.;
0406     PhotonTrkSumPtSolidConeDR03[i] = 0.;
0407     PhotonE1x5E5x5[i] = 0.;
0408     PhotonE2x5E5x5[i] = 0.;
0409   }
0410 
0411   //Getting information from the RecoObjects
0412   dijet_countPFJet_ = 0;
0413   monojet_countPFJet_ = 0;
0414 
0415   PFJetCollection::const_iterator pfjet_ = pfjets.begin();
0416   for (; pfjet_ != pfjets.end(); ++pfjet_) {
0417     double scale = 1.;
0418     if (ValidJetCorrector)
0419       scale = JetCorrector_->correction(*pfjet_);
0420     if (scale * pfjet_->pt() > PFJetPt[0]) {
0421       PFJetPt[1] = PFJetPt[0];
0422       PFJetPx[1] = PFJetPx[0];
0423       PFJetPy[1] = PFJetPy[0];
0424       PFJetEta[1] = PFJetEta[0];
0425       PFJetPhi[1] = PFJetPhi[0];
0426       PFJetRapidity[1] = PFJetRapidity[0];
0427       PFJetMass[1] = PFJetMass[0];
0428       PFJetNHEF[1] = PFJetNHEF[0];
0429       PFJetCHEF[1] = PFJetCHEF[0];
0430       PFJetNEMF[1] = PFJetNEMF[0];
0431       PFJetCEMF[1] = PFJetCEMF[0];
0432       //
0433       PFJetPt[0] = scale * pfjet_->pt();
0434       PFJetPx[0] = scale * pfjet_->px();
0435       PFJetPy[0] = scale * pfjet_->py();
0436       PFJetEta[0] = pfjet_->eta();
0437       PFJetPhi[0] = pfjet_->phi();
0438       PFJetRapidity[0] = pfjet_->rapidity();
0439       PFJetMass[0] = pfjet_->mass();
0440       PFJetNHEF[0] = pfjet_->neutralHadronEnergyFraction();
0441       PFJetCHEF[0] = pfjet_->chargedHadronEnergyFraction();
0442       PFJetNEMF[0] = pfjet_->neutralEmEnergyFraction();
0443       PFJetCEMF[0] = pfjet_->chargedEmEnergyFraction();
0444     } else if (scale * pfjet_->pt() < PFJetPt[0] && scale * pfjet_->pt() > PFJetPt[1]) {
0445       PFJetPt[1] = scale * pfjet_->pt();
0446       PFJetPx[1] = scale * pfjet_->px();
0447       PFJetPy[1] = scale * pfjet_->py();
0448       PFJetEta[1] = pfjet_->eta();
0449       PFJetPhi[1] = pfjet_->phi();
0450       PFJetRapidity[1] = pfjet_->rapidity();
0451       PFJetMass[1] = pfjet_->mass();
0452       PFJetNHEF[1] = pfjet_->neutralHadronEnergyFraction();
0453       PFJetCHEF[1] = pfjet_->chargedHadronEnergyFraction();
0454       PFJetNEMF[1] = pfjet_->neutralEmEnergyFraction();
0455       PFJetCEMF[1] = pfjet_->chargedEmEnergyFraction();
0456     } else {
0457     }
0458     if (scale * pfjet_->pt() > dijet_PFJet1_pt_cut_)
0459       dijet_countPFJet_++;
0460     if (scale * pfjet_->pt() > dijet_PFJet1_pt_cut_)
0461       monojet_countPFJet_++;
0462   }
0463 
0464   VertexCollection vertexCollection = *(VertexCollection_.product());
0465   reco::VertexCollection::const_iterator primaryVertex_ = vertexCollection.begin();
0466 
0467   dimuon_countMuon_ = 0;
0468   monomuon_countMuon_ = 0;
0469   reco::MuonCollection::const_iterator muon_ = MuonCollection_->begin();
0470   for (; muon_ != MuonCollection_->end(); muon_++) {
0471     // Muon High Pt ID
0472     bool HighPt = false;
0473     if (muon_->isGlobalMuon() && muon_->globalTrack()->hitPattern().numberOfValidMuonHits() > 0 &&
0474         muon_->numberOfMatchedStations() > 1 && muon_->innerTrack()->hitPattern().trackerLayersWithMeasurement() > 5 &&
0475         muon_->innerTrack()->hitPattern().numberOfValidPixelHits() > 0 &&
0476         muon_->muonBestTrack()->ptError() / muon_->muonBestTrack()->pt() < 0.3 &&
0477         fabs(muon_->muonBestTrack()->dxy(primaryVertex_->position())) < 0.2 &&
0478         fabs(muon_->bestTrack()->dz(primaryVertex_->position())) < 0.5 && fabs(muon_->eta()) < 2.1)
0479       HighPt = true;
0480 
0481     if (HighPt == true) {
0482       if (muon_->pt() > MuonPt[0]) {
0483         MuonPt[1] = MuonPt[0];
0484         MuonPx[1] = MuonPx[0];
0485         MuonPy[1] = MuonPy[0];
0486         MuonEta[1] = MuonEta[0];
0487         MuonPhi[1] = MuonPhi[0];
0488         MuonCharge[1] = MuonCharge[0];
0489         //
0490         MuonPt[0] = muon_->pt();
0491         MuonPx[0] = muon_->px();
0492         MuonPy[0] = muon_->py();
0493         MuonEta[0] = muon_->eta();
0494         MuonPhi[0] = muon_->phi();
0495         MuonCharge[0] = muon_->charge();
0496       } else if (muon_->pt() > MuonPt[1] && muon_->pt() < MuonPt[0]) {
0497         MuonPt[1] = muon_->pt();
0498         MuonPx[1] = muon_->px();
0499         MuonPy[1] = muon_->py();
0500         MuonEta[1] = muon_->eta();
0501         MuonPhi[1] = muon_->phi();
0502         MuonCharge[1] = muon_->charge();
0503       }
0504     }
0505     if (muon_->pt() > dimuon_Muon1_pt_cut_)
0506       dimuon_countMuon_++;
0507     if (muon_->pt() > monomuon_Muon_pt_cut_)
0508       monomuon_countMuon_++;
0509   }
0510 
0511   dielectron_countElectron_ = 0;
0512   monoelectron_countElectron_ = 0;
0513   reco::GsfElectronCollection::const_iterator electron_ = ElectronCollection_->begin();
0514   for (; electron_ != ElectronCollection_->end(); electron_++) {
0515     //HEEP Selection 4.1 (some cuts)
0516     if (electron_->e5x5() <= 0)
0517       continue;
0518     if (electron_->gsfTrack().isNull())
0519       continue;
0520     bool HEPP_ele = false;
0521     double sceta = electron_->caloPosition().eta();
0522     double dEtaIn = fabs(electron_->deltaEtaSuperClusterTrackAtVtx());
0523     double dPhiIn = fabs(electron_->deltaPhiSuperClusterTrackAtVtx());
0524     double HoverE = electron_->hadronicOverEm();
0525     int missingHits = electron_->gsfTrack()->hitPattern().numberOfLostTrackerHits(HitPattern::MISSING_INNER_HITS);
0526     double dxy = electron_->gsfTrack()->dxy(primaryVertex_->position());
0527     double tkIso = electron_->dr03TkSumPt();
0528     double e2x5Fraction = electron_->e2x5Max() / electron_->e5x5();
0529     double e1x5Fraction = electron_->e1x5() / electron_->e5x5();
0530     double scSigmaIetaIeta = electron_->scSigmaIEtaIEta();
0531     if (electron_->ecalDriven() && electron_->pt() > 35.) {
0532       if (fabs(sceta) < 1.442) {  // barrel
0533         if (fabs(dEtaIn) < 0.005 && fabs(dPhiIn) < 0.06 && HoverE < 0.05 && tkIso < 5. && missingHits <= 1 &&
0534             fabs(dxy) < 0.02 && (e2x5Fraction > 0.94 || e1x5Fraction > 0.83))
0535           HEPP_ele = true;
0536       } else if (fabs(sceta) > 1.56 && fabs(sceta) < 2.5) {  // endcap
0537         if (fabs(dEtaIn) < 0.007 && fabs(dPhiIn) < 0.06 && HoverE < 0.05 && tkIso < 5. && missingHits <= 1 &&
0538             fabs(dxy) < 0.02 && scSigmaIetaIeta < 0.03)
0539           HEPP_ele = true;
0540       }
0541     }
0542     //
0543     if (HEPP_ele == false)
0544       continue;
0545     if (electron_->pt() > ElectronPt[0]) {
0546       ElectronPt[1] = ElectronPt[0];
0547       ElectronPx[1] = ElectronPx[0];
0548       ElectronPy[1] = ElectronPy[0];
0549       ElectronEta[1] = ElectronEta[0];
0550       ElectronPhi[1] = ElectronPhi[0];
0551       ElectronCharge[1] = ElectronCharge[0];
0552       //
0553       ElectronPt[0] = electron_->pt();
0554       ElectronPx[0] = electron_->px();
0555       ElectronPy[0] = electron_->py();
0556       ElectronEta[0] = electron_->eta();
0557       ElectronPhi[0] = electron_->phi();
0558       ElectronCharge[0] = electron_->charge();
0559     } else if (electron_->pt() > ElectronPt[1] && electron_->pt() < ElectronPt[0]) {
0560       ElectronPt[1] = electron_->pt();
0561       ElectronPx[1] = electron_->px();
0562       ElectronPy[1] = electron_->py();
0563       ElectronEta[1] = electron_->eta();
0564       ElectronPhi[1] = electron_->phi();
0565       ElectronCharge[1] = electron_->charge();
0566     }
0567     if (electron_->pt() > dielectron_Electron1_pt_cut_)
0568       dielectron_countElectron_++;
0569     if (electron_->pt() > monoelectron_Electron_pt_cut_)
0570       monoelectron_countElectron_++;
0571   }
0572 
0573   diphoton_countPhoton_ = 0.;
0574   reco::PhotonCollection::const_iterator photon_ = PhotonCollection_->begin();
0575   for (; photon_ != PhotonCollection_->end(); ++photon_) {
0576     if (photon_->pt() > PhotonPt[0]) {
0577       PhotonEnergy[1] = PhotonEnergy[0];
0578       PhotonPt[1] = PhotonPt[0];
0579       PhotonEt[1] = PhotonEt[0];
0580       PhotonEta[1] = PhotonEta[0];
0581       PhotonEtaSc[1] = PhotonEtaSc[0];
0582       PhotonPhi[1] = PhotonPhi[0];
0583       PhotonHoverE[1] = PhotonHoverE[0];
0584       PhotonSigmaIetaIeta[1] = PhotonSigmaIetaIeta[0];
0585       PhotonTrkSumPtSolidConeDR03[1] = PhotonTrkSumPtSolidConeDR03[0];
0586       PhotonE1x5E5x5[1] = PhotonE1x5E5x5[0];
0587       PhotonE2x5E5x5[1] = PhotonE2x5E5x5[0];
0588       PhotonEnergy[0] = photon_->energy();
0589       PhotonPt[0] = photon_->pt();
0590       PhotonEt[0] = photon_->et();
0591       PhotonEta[0] = photon_->eta();
0592       PhotonEtaSc[0] = photon_->caloPosition().eta();
0593       PhotonPhi[0] = photon_->phi();
0594       PhotonHoverE[0] = photon_->hadronicOverEm();
0595       PhotonSigmaIetaIeta[0] = photon_->sigmaIetaIeta();
0596       PhotonTrkSumPtSolidConeDR03[0] = photon_->trkSumPtSolidConeDR03();
0597       PhotonE1x5E5x5[0] = photon_->e1x5() / photon_->e5x5();
0598       PhotonE2x5E5x5[0] = photon_->e2x5() / photon_->e5x5();
0599     } else if (photon_->pt() > PhotonPt[1] && photon_->pt() < PhotonPt[0]) {
0600       PhotonEnergy[1] = photon_->energy();
0601       PhotonPt[1] = photon_->pt();
0602       PhotonEt[1] = photon_->et();
0603       PhotonEta[1] = photon_->eta();
0604       PhotonEtaSc[1] = photon_->caloPosition().eta();
0605       PhotonPhi[1] = photon_->phi();
0606       PhotonHoverE[1] = photon_->hadronicOverEm();
0607       PhotonSigmaIetaIeta[1] = photon_->sigmaIetaIeta();
0608       PhotonTrkSumPtSolidConeDR03[1] = photon_->trkSumPtSolidConeDR03();
0609       PhotonE1x5E5x5[1] = photon_->e1x5() / photon_->e5x5();
0610       PhotonE2x5E5x5[1] = photon_->e2x5() / photon_->e5x5();
0611     }
0612     if (photon_->pt() > diphoton_Photon1_pt_cut_)
0613       diphoton_countPhoton_++;
0614   }
0615 
0616   //
0617   // Analyze
0618   //
0619 
0620   //Resonances
0621   analyzeDiJets(iEvent);
0622   analyzeDiMuons(iEvent);
0623   analyzeDiElectrons(iEvent);
0624   analyzeDiPhotons(iEvent);
0625 
0626   //MonoSearches
0627   analyzeMonoJets(iEvent);
0628   analyzeMonoMuons(iEvent);
0629   analyzeMonoElectrons(iEvent);
0630 
0631   //LongLived
0632   if (ValidGenParticles) {
0633     analyzeDisplacedLeptons(iEvent, iSetup);
0634     analyzeDisplacedJets(iEvent, iSetup);
0635   }
0636 }
0637 
0638 void ExoticaDQM::analyzeDisplacedLeptons(const Event& iEvent, const edm::EventSetup& iSetup) {
0639   //=== This is designed to run on MC events in which a pair of long-lived stop quarks each decay to a displaced lepton + displaced b jet.
0640 
0641   // Initialisation
0642 
0643   const unsigned int stop1 = 1000006;  // PDG identifier of top squark1
0644   const unsigned int stop2 = 2000006;  // PDG identifier of top squark2
0645   const float deltaRcut = 0.01;        // Cone size for matching reco to true leptons.
0646   const float invPtcut = 0.1;          // Cut in 1/Pt consistency for matching reco tracks to genParticles.
0647 
0648   //--- Measure the efficiency to reconstruct leptons from long-lived stop quark decay.
0649 
0650   for (const reco::GenParticle& gen : *GenCollection_) {
0651     unsigned int idPdg = abs(gen.pdgId());
0652     // Find electrons/muons from long-lived stop decay.
0653     if (idPdg == stop1 || idPdg == stop2) {
0654       unsigned int nDau = gen.numberOfDaughters();
0655       for (unsigned int i = 0; i < nDau; i++) {
0656         const reco::GenParticle* dau = (const reco::GenParticle*)gen.daughter(i);
0657         // Only measure efficiency using leptons passing pt & eta cuts. (The pt cut is almost irrelevant, since leptons from stop decay are hard).
0658         if (fabs(dau->eta()) < dispFermion_eta_cut_ && dau->pt() > dispFermion_pt_cut_) {
0659           unsigned int pdgIdDau = abs(dau->pdgId());
0660 
0661           if (pdgIdDau == 11 || pdgIdDau == 13) {  // electron or muon from stop decay
0662 
0663             // Get transverse decay length of stop quark.
0664             float lxy = dau->vertex().rho();
0665 
0666             // Get momentum vector of daughter genParticle trajectory extrapolated to beam-line.
0667             GlobalVector genP = this->getGenParticleTrajectoryAtBeamline(iSetup, dau);
0668 
0669             if (pdgIdDau == 11) {  // electron from stop decay
0670 
0671               // Find matching reco track if any.
0672               bool recoedTrk = false;
0673               for (const reco::Track& trk : *TrackCollection_) {
0674                 if (reco::deltaR(genP, trk) < deltaRcut && fabs(1 / dau->pt() - 1 / trk.pt()) < invPtcut) {
0675                   //cout<<"MATCH ELEC TRK "<<dau->pt()<<" "<<trk.pt()<<" "<<reco::deltaR(genP, trk)<<endl;
0676                   recoedTrk = true;
0677                 }
0678               }
0679               dispElec_track_effi_lxy->Fill(lxy, recoedTrk);
0680 
0681               // Find matching reco electron if any.
0682               bool recoedE = false;
0683               for (const reco::GsfElectron& eReco : *ElectronCollection_) {
0684                 if (reco::deltaR(genP, eReco) < deltaRcut && fabs(1 / dau->pt() - 1 / eReco.pt()) < invPtcut)
0685                   recoedE = true;
0686               }
0687               dispElec_elec_effi_lxy->Fill(lxy, recoedE);
0688 
0689             } else if (pdgIdDau == 13) {  // muon from stop decay
0690 
0691               // Find matching reco track if any.
0692               bool recoedTrk = false;
0693               for (const reco::Track& trk : *TrackCollection_) {
0694                 if (reco::deltaR(genP, trk) < deltaRcut && fabs(1 / dau->pt() - 1 / trk.pt()) < invPtcut) {
0695                   //cout<<"MATCH MUON TRK "<<dau->pt()<<" "<<trk.pt()<<" "<<reco::deltaR(genP, trk)<<endl;
0696                   recoedTrk = true;
0697                 }
0698               }
0699               dispMuon_track_effi_lxy->Fill(lxy, recoedTrk);
0700 
0701               // Find matching reco muon, if any, in normal global muon collection.
0702               bool recoedMu = false;
0703               for (const reco::Muon& muReco : *MuonCollection_) {
0704                 if (reco::deltaR(genP, muReco) < deltaRcut && fabs(1 / dau->pt() - 1 / muReco.pt()) < invPtcut)
0705                   recoedMu = true;
0706               }
0707               dispMuon_muon_effi_lxy->Fill(lxy, recoedMu);
0708 
0709               // Find matching reco muon, if any, in displaced global muon collection.
0710               bool recoedMuDisp = false;
0711               for (const reco::Track& muDispReco : *MuonDispCollection_) {
0712                 if (reco::deltaR(genP, muDispReco) < deltaRcut && fabs(1 / dau->pt() - 1 / muDispReco.pt()) < invPtcut)
0713                   recoedMuDisp = true;
0714               }
0715               dispMuon_muonDisp_effi_lxy->Fill(lxy, recoedMuDisp);
0716 
0717               // Find matching reco muon, if any, in displaced SA muon collection.
0718               bool recoedMuDispSA = false;
0719               for (const reco::Track& muDispSAReco : *MuonDispSACollection_) {
0720                 if (reco::deltaR(genP, muDispSAReco) < deltaRcut &&
0721                     fabs(1 / dau->pt() - 1 / muDispSAReco.pt()) < invPtcut)
0722                   recoedMuDispSA = true;
0723               }
0724               dispMuon_muonDispSA_effi_lxy->Fill(lxy, recoedMuDispSA);
0725             }
0726           }
0727         }
0728       }
0729     }
0730   }
0731 }
0732 void ExoticaDQM::analyzeDisplacedJets(const Event& iEvent, const edm::EventSetup& iSetup) {
0733   //=== This is designed to run on MC events in which a pair of long-lived stop quarks each decay to a displaced lepton + displaced b jet.
0734 
0735   // Initialisation
0736 
0737   // Define function to identify R-hadrons containing stop quarks from PDG particle code.
0738   // N.B. Jets originate not just from stop quark, but also from its partner SM quark inside the R hadron.
0739   auto isRhadron = [](unsigned int pdgId) { return (pdgId / 100) == 10006 || (pdgId / 1000) == 1006; };
0740 
0741   const float deltaRcut = 0.01;  // Cone size for matching reco tracks to genParticles.
0742   const float invPtcut = 0.1;    // Cut in 1/Pt consistency for matching reco tracks to genParticles.
0743 
0744   //--- Measure the efficiency to reconstruct tracks in jet(s) from long-lived stop quark decay.
0745 
0746   for (const reco::GenParticle& gen : *GenCollection_) {
0747     unsigned int idPdg = abs(gen.pdgId());
0748     // Only measure efficiency using charged e, mu pi, K, p
0749     if (idPdg == 11 || idPdg == 13 || idPdg == 211 || idPdg == 321 || idPdg == 2212) {
0750       // Only measure efficiency using leptons passing pt & eta cuts. (The pt cut is almost irrelevant, since leptons from stop decay are hard).
0751       if (fabs(gen.eta()) < dispFermion_eta_cut_ && gen.pt() > dispFermion_pt_cut_) {
0752         // Check if this particle came (maybe indirectly) from an R hadron decay.
0753         const reco::GenParticle* genMoth = &gen;
0754         const reco::GenParticle* genRhadron = nullptr;
0755         bool foundParton = false;
0756         while (genMoth->numberOfMothers() > 0) {
0757           genMoth = (const reco::GenParticle*)genMoth->mother(0);
0758           unsigned int idPdgMoth = abs(genMoth->pdgId());
0759           // Check that the R-hadron decayed via a quark/gluon before yielding genParticle "gen".
0760           // This ensures that gen is from the jet, and not a lepton produced directly from the stop quark decay.
0761           if ((idPdgMoth >= 1 && idPdgMoth <= 6) || idPdgMoth == 21)
0762             foundParton = true;
0763           // Note if ancestor was R hadron
0764           if (isRhadron(idPdgMoth)) {
0765             genRhadron = genMoth;
0766             break;
0767           }
0768         }
0769 
0770         if (foundParton && genRhadron != nullptr) {  // This GenParticle came (maybe indirectly) from an R hadron decay.
0771 
0772           // Get transverse decay length of R hadron.
0773           float lxy = genRhadron->daughter(0)->vertex().rho();
0774 
0775           // Get momentum vector of genParticle trajectory extrapolated to beam-line.
0776           GlobalVector genP = this->getGenParticleTrajectoryAtBeamline(iSetup, &gen);
0777 
0778           // Find matching reco track if any.
0779           bool recoedTrk = false;
0780           for (const reco::Track& trk : *TrackCollection_) {
0781             if (reco::deltaR(genP, trk) < deltaRcut && fabs(1 / gen.pt() - 1 / trk.pt()) < invPtcut) {
0782               //cout<<"MATCH TRK "<<gen.pt()<<" "<<trk.pt()<<" "<<reco::deltaR(gen, trk)<<endl;
0783               recoedTrk = true;
0784             }
0785           }
0786           dispJet_track_effi_lxy->Fill(lxy, recoedTrk);
0787         }
0788       }
0789     }
0790   }
0791 }
0792 GlobalVector ExoticaDQM::getGenParticleTrajectoryAtBeamline(const edm::EventSetup& iSetup,
0793                                                             const reco::GenParticle* gen) {
0794   //=== Estimate the momentum vector that a GenParticle would have at its trajectory's point of closest
0795   //=== approach to the beam-line.
0796 
0797   // Get the magnetic field
0798   const MagneticField* theMagField = &iSetup.getData(magFieldToken_);
0799 
0800   // Make FreeTrajectoryState of this gen particle
0801   FreeTrajectoryState fts(GlobalPoint(gen->vx(), gen->vy(), gen->vz()),
0802                           GlobalVector(gen->px(), gen->py(), gen->pz()),
0803                           gen->charge(),
0804                           theMagField);
0805 
0806   // Get trajectory closest to beam line
0807   TSCBLBuilderNoMaterial tscblBuilder;
0808   const BeamSpot beamspot;  // Simple beam-spot at (0,0,0). Good enough.
0809   TrajectoryStateClosestToBeamLine tsAtClosestApproach = tscblBuilder(fts, beamspot);
0810 
0811   GlobalVector p = tsAtClosestApproach.trackStateAtPCA().momentum();
0812 
0813   return p;
0814 }
0815 
0816 void ExoticaDQM::analyzeDiJets(const Event& iEvent) {
0817   for (unsigned int icoll = 0; icoll < DiJetPFJetCollection_.size(); ++icoll) {
0818     dijet_countPFJet_ = 0;
0819     bool ValidDiJetPFJets = iEvent.getByToken(DiJetPFJetToken_[icoll], DiJetpfJetCollection_);
0820     if (!ValidDiJetPFJets)
0821       continue;
0822     DiJetpfjets = *DiJetpfJetCollection_;
0823     for (int i = 0; i < 2; i++) {
0824       PFJetPx[i] = 0.;
0825       PFJetPy[i] = 0.;
0826       PFJetPt[i] = 0.;
0827       PFJetEta[i] = 0.;
0828       PFJetPhi[i] = 0.;
0829       PFJetNHEF[i] = 0.;
0830       PFJetCHEF[i] = 0.;
0831       PFJetNEMF[i] = 0.;
0832       PFJetCEMF[i] = 0.;
0833     }
0834     PFJetCollection::const_iterator DiJetpfjet_ = DiJetpfjets.begin();
0835     for (; DiJetpfjet_ != DiJetpfjets.end(); ++DiJetpfjet_) {
0836       double scale = 1.;
0837       if (scale * DiJetpfjet_->pt() > PFJetPt[0]) {
0838         PFJetPt[1] = PFJetPt[0];
0839         PFJetPx[1] = PFJetPx[0];
0840         PFJetPy[1] = PFJetPy[0];
0841         PFJetEta[1] = PFJetEta[0];
0842         PFJetPhi[1] = PFJetPhi[0];
0843         PFJetRapidity[1] = DiJetpfjet_->rapidity();
0844         PFJetMass[1] = DiJetpfjet_->mass();
0845         PFJetNHEF[1] = PFJetNHEF[0];
0846         PFJetCHEF[1] = PFJetCHEF[0];
0847         PFJetNEMF[1] = PFJetNEMF[0];
0848         PFJetCEMF[1] = PFJetCEMF[0];
0849         PFJetPt[0] = scale * DiJetpfjet_->pt();
0850         PFJetPx[0] = scale * DiJetpfjet_->px();
0851         PFJetPy[0] = scale * DiJetpfjet_->py();
0852         PFJetEta[0] = DiJetpfjet_->eta();
0853         PFJetPhi[0] = DiJetpfjet_->phi();
0854         PFJetRapidity[0] = DiJetpfjet_->rapidity();
0855         PFJetMass[0] = DiJetpfjet_->mass();
0856         PFJetNHEF[0] = DiJetpfjet_->neutralHadronEnergyFraction();
0857         PFJetCHEF[0] = DiJetpfjet_->chargedHadronEnergyFraction();
0858         PFJetNEMF[0] = DiJetpfjet_->neutralEmEnergyFraction();
0859         PFJetCEMF[0] = DiJetpfjet_->chargedEmEnergyFraction();
0860       } else if (scale * DiJetpfjet_->pt() < PFJetPt[0] && scale * DiJetpfjet_->pt() > PFJetPt[1]) {
0861         PFJetPt[1] = scale * DiJetpfjet_->pt();
0862         PFJetPx[1] = scale * DiJetpfjet_->px();
0863         PFJetPy[1] = scale * DiJetpfjet_->py();
0864         PFJetEta[1] = DiJetpfjet_->eta();
0865         PFJetPhi[1] = DiJetpfjet_->phi();
0866         PFJetRapidity[1] = DiJetpfjet_->rapidity();
0867         PFJetMass[1] = DiJetpfjet_->mass();
0868         PFJetNHEF[1] = DiJetpfjet_->neutralHadronEnergyFraction();
0869         PFJetCHEF[1] = DiJetpfjet_->chargedHadronEnergyFraction();
0870         PFJetNEMF[1] = DiJetpfjet_->neutralEmEnergyFraction();
0871         PFJetCEMF[1] = DiJetpfjet_->chargedEmEnergyFraction();
0872       } else {
0873       }
0874       if (scale * DiJetpfjet_->pt() > dijet_PFJet1_pt_cut_)
0875         dijet_countPFJet_++;
0876     }
0877     if (PFJetPt[0] > dijet_PFJet1_pt_cut_ && PFJetPt[1] > dijet_PFJet2_pt_cut_) {
0878       dijet_PFJet_pt[icoll]->Fill(PFJetPt[0]);
0879       dijet_PFJet_eta[icoll]->Fill(PFJetEta[0]);
0880       dijet_PFJet_phi[icoll]->Fill(PFJetPhi[0]);
0881       dijet_PFJet_rapidity[icoll]->Fill(PFJetRapidity[0]);
0882       dijet_PFJet_mass[icoll]->Fill(PFJetMass[0]);
0883       dijet_PFJet_pt[icoll]->Fill(PFJetPt[1]);
0884       dijet_PFJet_eta[icoll]->Fill(PFJetEta[1]);
0885       dijet_PFJet_phi[icoll]->Fill(PFJetPhi[1]);
0886       dijet_PFJet_rapidity[icoll]->Fill(PFJetRapidity[1]);
0887       dijet_PFJet_mass[icoll]->Fill(PFJetMass[1]);
0888       dijet_deltaPhiPFJet1PFJet2[icoll]->Fill(deltaPhi(PFJetPhi[0], PFJetPhi[1]));
0889       dijet_deltaEtaPFJet1PFJet2[icoll]->Fill(PFJetEta[0] - PFJetEta[1]);
0890       dijet_deltaRPFJet1PFJet2[icoll]->Fill(deltaR(PFJetEta[0], PFJetPhi[0], PFJetEta[1], PFJetPhi[1]));
0891       dijet_invMassPFJet1PFJet2[icoll]->Fill(
0892           sqrt(2 * PFJetPt[0] * PFJetPt[1] * (cosh(PFJetEta[0] - PFJetEta[1]) - cos(PFJetPhi[0] - PFJetPhi[1]))));
0893       dijet_PFchef[icoll]->Fill(PFJetCHEF[0]);
0894       dijet_PFnhef[icoll]->Fill(PFJetNHEF[0]);
0895       dijet_PFcemf[icoll]->Fill(PFJetCEMF[0]);
0896       dijet_PFnemf[icoll]->Fill(PFJetNEMF[0]);
0897       dijet_PFJetMulti[icoll]->Fill(dijet_countPFJet_);
0898     }
0899   }
0900 }
0901 
0902 void ExoticaDQM::analyzeDiMuons(const Event& iEvent) {
0903   if (MuonPt[0] > dimuon_Muon1_pt_cut_ && MuonPt[1] > dimuon_Muon2_pt_cut_ && MuonCharge[0] * MuonCharge[1] == -1) {
0904     dimuon_Muon_pt->Fill(MuonPt[0]);
0905     dimuon_Muon_eta->Fill(MuonEta[0]);
0906     dimuon_Muon_phi->Fill(MuonPhi[0]);
0907     dimuon_Muon_pt->Fill(MuonPt[1]);
0908     dimuon_Muon_eta->Fill(MuonEta[1]);
0909     dimuon_Muon_phi->Fill(MuonPhi[1]);
0910     dimuon_Charge->Fill(MuonCharge[0]);
0911     dimuon_Charge->Fill(MuonCharge[1]);
0912     dimuon_deltaPhiMuon1Muon2->Fill(deltaPhi(MuonPhi[0], MuonPhi[1]));
0913     dimuon_deltaEtaMuon1Muon2->Fill(MuonEta[0] - MuonEta[1]);
0914     dimuon_deltaRMuon1Muon2->Fill(deltaR(MuonEta[0], MuonPhi[0], MuonEta[1], MuonPhi[1]));
0915     dimuon_invMassMuon1Muon2->Fill(
0916         sqrt(2 * MuonPt[0] * MuonPt[1] * (cosh(MuonEta[0] - MuonEta[1]) - cos(MuonPhi[0] - MuonPhi[1]))));
0917     dimuon_MuonMulti->Fill(dimuon_countMuon_);
0918   }
0919 }
0920 
0921 void ExoticaDQM::analyzeDiElectrons(const Event& iEvent) {
0922   if (ElectronPt[0] > dielectron_Electron1_pt_cut_ && ElectronPt[1] > dielectron_Electron2_pt_cut_ &&
0923       ElectronCharge[0] * ElectronCharge[1] == -1.) {
0924     dielectron_Electron_pt->Fill(ElectronPt[0]);
0925     dielectron_Electron_eta->Fill(ElectronEta[0]);
0926     dielectron_Electron_phi->Fill(ElectronPhi[0]);
0927     dielectron_Electron_pt->Fill(ElectronPt[1]);
0928     dielectron_Electron_eta->Fill(ElectronEta[1]);
0929     dielectron_Electron_phi->Fill(ElectronPhi[1]);
0930     dielectron_Charge->Fill(ElectronCharge[0]);
0931     dielectron_Charge->Fill(ElectronCharge[1]);
0932     dielectron_deltaPhiElectron1Electron2->Fill(deltaPhi(ElectronPhi[0], ElectronPhi[1]));
0933     dielectron_deltaEtaElectron1Electron2->Fill(ElectronEta[0] - ElectronEta[1]);
0934     dielectron_deltaRElectron1Electron2->Fill(deltaR(ElectronEta[0], ElectronPhi[0], ElectronEta[1], ElectronPhi[1]));
0935     dielectron_invMassElectron1Electron2->Fill(
0936         sqrt(2 * ElectronPt[0] * ElectronPt[1] *
0937              (cosh(ElectronEta[0] - ElectronEta[1]) - cos(ElectronPhi[0] - ElectronPhi[1]))));
0938     dielectron_ElectronMulti->Fill(dielectron_countElectron_);
0939   }
0940 }
0941 
0942 void ExoticaDQM::analyzeDiPhotons(const Event& iEvent) {
0943   if (PhotonPt[0] > diphoton_Photon1_pt_cut_ && PhotonPt[1] > diphoton_Photon2_pt_cut_) {
0944     diphoton_Photon_energy->Fill(PhotonEnergy[0]);
0945     diphoton_Photon_pt->Fill(PhotonPt[0]);
0946     diphoton_Photon_et->Fill(PhotonEt[0]);
0947     diphoton_Photon_eta->Fill(PhotonEta[0]);
0948     diphoton_Photon_etasc->Fill(PhotonEtaSc[0]);
0949     diphoton_Photon_phi->Fill(PhotonPhi[0]);
0950     if (fabs(PhotonEtaSc[0]) < 1.442) {
0951       diphoton_Photon_hovere_eb->Fill(PhotonHoverE[0]);
0952       diphoton_Photon_sigmaietaieta_eb->Fill(PhotonSigmaIetaIeta[0]);
0953       diphoton_Photon_trksumptsolidconedr03_eb->Fill(PhotonTrkSumPtSolidConeDR03[0]);
0954       diphoton_Photon_e1x5e5x5_eb->Fill(PhotonE1x5E5x5[0]);
0955       diphoton_Photon_e2x5e5x5_eb->Fill(PhotonE2x5E5x5[0]);
0956     }
0957     if (fabs(PhotonEtaSc[0]) > 1.566 && fabs(PhotonEtaSc[0]) < 2.5) {
0958       diphoton_Photon_hovere_ee->Fill(PhotonHoverE[0]);
0959       diphoton_Photon_sigmaietaieta_ee->Fill(PhotonSigmaIetaIeta[0]);
0960       diphoton_Photon_trksumptsolidconedr03_ee->Fill(PhotonTrkSumPtSolidConeDR03[0]);
0961       diphoton_Photon_e1x5e5x5_ee->Fill(PhotonE1x5E5x5[0]);
0962       diphoton_Photon_e2x5e5x5_ee->Fill(PhotonE2x5E5x5[0]);
0963     }
0964     diphoton_Photon_energy->Fill(PhotonEnergy[1]);
0965     diphoton_Photon_pt->Fill(PhotonPt[1]);
0966     diphoton_Photon_et->Fill(PhotonEt[1]);
0967     diphoton_Photon_eta->Fill(PhotonEta[1]);
0968     diphoton_Photon_etasc->Fill(PhotonEtaSc[1]);
0969     diphoton_Photon_phi->Fill(PhotonPhi[1]);
0970     if (fabs(PhotonEtaSc[1]) < 1.4442) {
0971       diphoton_Photon_hovere_eb->Fill(PhotonHoverE[1]);
0972       diphoton_Photon_sigmaietaieta_eb->Fill(PhotonSigmaIetaIeta[1]);
0973       diphoton_Photon_trksumptsolidconedr03_eb->Fill(PhotonTrkSumPtSolidConeDR03[1]);
0974       diphoton_Photon_e1x5e5x5_eb->Fill(PhotonE1x5E5x5[1]);
0975       diphoton_Photon_e2x5e5x5_eb->Fill(PhotonE2x5E5x5[1]);
0976     }
0977     if (fabs(PhotonEtaSc[1]) > 1.566 && fabs(PhotonEtaSc[1]) < 2.5) {
0978       diphoton_Photon_hovere_ee->Fill(PhotonHoverE[1]);
0979       diphoton_Photon_sigmaietaieta_ee->Fill(PhotonSigmaIetaIeta[1]);
0980       diphoton_Photon_trksumptsolidconedr03_ee->Fill(PhotonTrkSumPtSolidConeDR03[1]);
0981       diphoton_Photon_e1x5e5x5_ee->Fill(PhotonE1x5E5x5[1]);
0982       diphoton_Photon_e2x5e5x5_ee->Fill(PhotonE2x5E5x5[1]);
0983     }
0984     diphoton_deltaPhiPhoton1Photon2->Fill(deltaPhi(PhotonPhi[0], PhotonPhi[1]));
0985     diphoton_deltaEtaPhoton1Photon2->Fill(PhotonEta[0] - PhotonEta[1]);
0986     diphoton_deltaRPhoton1Photon2->Fill(deltaR(PhotonEta[0], PhotonPhi[0], PhotonEta[1], PhotonPhi[1]));
0987     diphoton_invMassPhoton1Photon2->Fill(
0988         sqrt(2 * PhotonPt[0] * PhotonPt[1] * (cosh(PhotonEta[0] - PhotonEta[1]) - cos(PhotonPhi[0] - PhotonPhi[1]))));
0989     diphoton_PhotonMulti->Fill(diphoton_countPhoton_);
0990   }
0991 }
0992 
0993 void ExoticaDQM::analyzeMonoJets(const Event& iEvent) {
0994   const PFMETCollection* pfmetcol = pfMETCollection_.product();
0995   const PFMET pfmet = pfmetcol->front();
0996   if (PFJetPt[0] > monojet_PFJet_pt_cut_ && pfmet.et() > monojet_PFJet_met_cut_) {
0997     monojet_PFJet_pt->Fill(PFJetPt[0]);
0998     monojet_PFJet_eta->Fill(PFJetEta[0]);
0999     monojet_PFJet_phi->Fill(PFJetPhi[0]);
1000     monojet_PFMet->Fill(pfmet.et());
1001     monojet_PFMet_phi->Fill(pfmet.phi());
1002     monojet_PFJetPtOverPFMet->Fill(PFJetPt[0] / pfmet.et());
1003     monojet_deltaPhiPFJetPFMet->Fill(deltaPhi(PFJetPhi[0], pfmet.phi()));
1004     monojet_PFchef->Fill(PFJetCHEF[0]);
1005     monojet_PFnhef->Fill(PFJetNHEF[0]);
1006     monojet_PFcemf->Fill(PFJetCEMF[0]);
1007     monojet_PFnemf->Fill(PFJetNEMF[0]);
1008     monojet_PFJetMulti->Fill(monojet_countPFJet_);
1009   }
1010 }
1011 
1012 void ExoticaDQM::analyzeMonoMuons(const Event& iEvent) {
1013   const PFMETCollection* pfmetcol = pfMETCollection_.product();
1014   const PFMET pfmet = pfmetcol->front();
1015   if (MuonPt[0] > monomuon_Muon_pt_cut_ && pfmet.et() > monomuon_Muon_met_cut_) {
1016     monomuon_Muon_pt->Fill(MuonPt[0]);
1017     monomuon_Muon_eta->Fill(MuonEta[0]);
1018     monomuon_Muon_phi->Fill(MuonPhi[0]);
1019     monomuon_Charge->Fill(MuonCharge[0]);
1020     monomuon_PFMet->Fill(pfmet.et());
1021     monomuon_PFMet_phi->Fill(pfmet.phi());
1022     monomuon_MuonPtOverPFMet->Fill(MuonPt[0] / pfmet.et());
1023     monomuon_deltaPhiMuonPFMet->Fill(deltaPhi(MuonPhi[0], pfmet.phi()));
1024     monomuon_TransverseMass->Fill(sqrt(2 * MuonPt[0] * pfmet.et() * (1 - cos(deltaPhi(MuonPhi[0], pfmet.phi())))));
1025     monomuon_MuonMulti->Fill(monomuon_countMuon_);
1026   }
1027 }
1028 
1029 void ExoticaDQM::analyzeMonoElectrons(const Event& iEvent) {
1030   const PFMETCollection* pfmetcol = pfMETCollection_.product();
1031   const PFMET pfmet = pfmetcol->front();
1032   if (ElectronPt[0] > monoelectron_Electron_pt_cut_ && pfmet.et() > monoelectron_Electron_met_cut_) {
1033     monoelectron_Electron_pt->Fill(ElectronPt[0]);
1034     monoelectron_Electron_eta->Fill(ElectronEta[0]);
1035     monoelectron_Electron_phi->Fill(ElectronPhi[0]);
1036     monoelectron_Charge->Fill(ElectronCharge[0]);
1037     monoelectron_PFMet->Fill(pfmet.et());
1038     monoelectron_PFMet_phi->Fill(pfmet.phi());
1039     monoelectron_ElectronPtOverPFMet->Fill(ElectronPt[0] / pfmet.et());
1040     monoelectron_deltaPhiElectronPFMet->Fill(deltaPhi(ElectronPhi[0], pfmet.phi()));
1041     monoelectron_TransverseMass->Fill(
1042         sqrt(2 * ElectronPt[0] * pfmet.et() * (1 - cos(deltaPhi(ElectronPhi[0], pfmet.phi())))));
1043     monoelectron_ElectronMulti->Fill(monoelectron_countElectron_);
1044   }
1045 }
1046 
1047 void ExoticaDQM::analyzeMonoPhotons(const Event& iEvent) {
1048   const PFMETCollection* pfmetcol = pfMETCollection_.product();
1049   const PFMET pfmet = pfmetcol->front();
1050   if (PhotonPt[0] > monophoton_Photon_pt_cut_ && pfmet.et() > monophoton_Photon_met_cut_) {
1051     monophoton_Photon_energy->Fill(PhotonEnergy[0]);
1052     monophoton_Photon_pt->Fill(PhotonPt[0]);
1053     monophoton_Photon_et->Fill(PhotonEt[0]);
1054     monophoton_Photon_eta->Fill(PhotonEta[0]);
1055     monophoton_Photon_etasc->Fill(PhotonEtaSc[0]);
1056     monophoton_Photon_phi->Fill(PhotonPhi[0]);
1057     monophoton_Photon_hovere->Fill(PhotonHoverE[0]);
1058     monophoton_Photon_sigmaietaieta->Fill(PhotonSigmaIetaIeta[0]);
1059     monophoton_Photon_trksumptsolidconedr03->Fill(PhotonTrkSumPtSolidConeDR03[0]);
1060     monophoton_Photon_e1x5e5x5->Fill(PhotonE1x5E5x5[0]);
1061     monophoton_Photon_e2x5e5x5->Fill(PhotonE2x5E5x5[0]);
1062     monophoton_PFMet->Fill(pfmet.et());
1063     monophoton_PFMet_phi->Fill(pfmet.phi());
1064     monophoton_PhotonPtOverPFMet->Fill(PhotonPt[0] / pfmet.et());
1065     monophoton_deltaPhiPhotonPFMet->Fill(deltaPhi(PhotonPhi[0], pfmet.phi()));
1066     monophoton_PhotonMulti->Fill(monophoton_countPhoton_);
1067   }
1068 }