Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
// This class is used to test the functionalities of the package

#include "DQM/DataScouting/plugins/ScoutingTestAnalyzer.h"
#include "DataFormats/JetReco/interface/CaloJet.h"

// A simple constructor which takes as inoput only the name of the PF jet
// collection
ScoutingTestAnalyzer::ScoutingTestAnalyzer(const edm::ParameterSet &conf) : ScoutingAnalyzerBase(conf) {
  m_pfJetsCollectionTag = conf.getUntrackedParameter<edm::InputTag>("pfJetsCollectionName");
  // set Token(-s)
  m_pfJetsCollectionTagToken_ =
      consumes<reco::CaloJetCollection>(conf.getUntrackedParameter<edm::InputTag>("pfJetsCollectionName"));
}

ScoutingTestAnalyzer::~ScoutingTestAnalyzer() {}

// Function to book the Monitoring Elements.
void ScoutingTestAnalyzer::bookHistograms(DQMStore::IBooker &iBooker, edm::Run const &, edm::EventSetup const &) {
  ScoutingAnalyzerBase::prepareBooking(iBooker);
  std::string collection_name = m_pfJetsCollectionTag.label();

  /* This method allows us to book an Histogram in one line in a completely
   * transparent way. Take your time to put axis titles!!!!*/
  m_jetPt = bookH1withSumw2(
      iBooker, collection_name + "_pt", collection_name + " Jet P_{T}", 50, 0., 500., "Jet P_{T} [GeV]");

  m_jetEtaPhi = bookH2withSumw2(iBooker,
                                collection_name + "_etaphi",
                                collection_name + " #eta #phi",
                                50,
                                -5,
                                5,
                                50,
                                -3.1415,
                                +3.1415,
                                "#eta^{Jet}",
                                "#phi^{Jet}");
}

// Usual analyze method
void ScoutingTestAnalyzer::analyze(const edm::Event &iEvent, const edm::EventSetup &c) {
  edm::Handle<reco::CaloJetCollection> calojets_handle;
  iEvent.getByToken(m_pfJetsCollectionTagToken_, calojets_handle);
  /* This is an example of how C++11 can simplify or lifes. The auto keyword
     make the compiler figure out by itself which is the type of the pfjets
     object. The qualifier const of course still apply. Poor's man explaination:
     "compiler, make pfjets a const ref and figure out for me the type"*/
  auto const &calojets = *calojets_handle;

  // Again, C++11. A loop on a std::vector becomes as simple as this!
  for (auto const &calojet : calojets) {
    m_jetPt->Fill(calojet.pt());
    m_jetEtaPhi->Fill(calojet.eta(), calojet.phi());
  }
}