Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-16 05:48:10

0001 
0002 #include "DQMOffline/EGamma/plugins/ElectronGeneralAnalyzer.h"
0003 
0004 #include "DQMServices/Core/interface/DQMStore.h"
0005 
0006 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0007 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0008 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
0009 #include "DataFormats/Common/interface/Handle.h"
0010 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0011 #include "DataFormats/Common/interface/TriggerResults.h"
0012 
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/MakerMacros.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/ServiceRegistry/interface/Service.h"
0018 
0019 //#include "CLHEP/Units/GlobalPhysicalConstants.h"
0020 //#include "TMath.h"
0021 
0022 #include <iostream>
0023 
0024 using namespace reco;
0025 
0026 ElectronGeneralAnalyzer::ElectronGeneralAnalyzer(const edm::ParameterSet& conf) : ElectronDqmAnalyzerBase(conf) {
0027   // collection input tags
0028   electronCollection_ = consumes<GsfElectronCollection>(conf.getParameter<edm::InputTag>("ElectronCollection"));
0029   matchingObjectCollection_ =
0030       consumes<reco::SuperClusterCollection>(conf.getParameter<edm::InputTag>("MatchingObjectCollection"));
0031   trackCollection_ = consumes<reco::TrackCollection>(conf.getParameter<edm::InputTag>("TrackCollection"));
0032   vertexCollection_ = consumes<reco::VertexCollection>(conf.getParameter<edm::InputTag>("VertexCollection"));
0033   gsftrackCollection_ = consumes<reco::GsfTrackCollection>(conf.getParameter<edm::InputTag>("GsfTrackCollection"));
0034   beamSpotTag_ = consumes<reco::BeamSpot>(conf.getParameter<edm::InputTag>("BeamSpot"));
0035   triggerResults_ = consumes<edm::TriggerResults>(conf.getParameter<edm::InputTag>("TriggerResults"));
0036 
0037   //  // for trigger
0038   //  HLTPathsByName_= conf.getParameter<std::vector<std::string > >("HltPaths");
0039   //  HLTPathsByIndex_.resize(HLTPathsByName_.size());
0040 }
0041 
0042 ElectronGeneralAnalyzer::~ElectronGeneralAnalyzer() {}
0043 
0044 void ElectronGeneralAnalyzer::bookHistograms(DQMStore::IBooker& iBooker, edm::Run const&, edm::EventSetup const&) {
0045   h2_ele_beamSpotXvsY =
0046       bookH2(iBooker, "beamSpotXvsY", "beam spot x vs y", 100, -0.2, 0.2, 100, -0.2, 0.2, "x (cm)", "y (cm)");
0047   py_ele_nElectronsVsLs =
0048       bookP1(iBooker, "nElectronsVsLs", "# gsf electrons vs LS", 150, 0., 1500., 0., 20., "LS", "<N_{ele}>");
0049   py_ele_nClustersVsLs =
0050       bookP1(iBooker, "nClustersVsLs", "# clusters vs LS", 150, 0., 1500., 0., 100., "LS", "<N_{SC}>");
0051   py_ele_nGsfTracksVsLs =
0052       bookP1(iBooker, "nGsfTracksVsLs", "# gsf tracks vs LS", 150, 0., 1500., 0., 20., "LS", "<N_{GSF tk}>");
0053   py_ele_nTracksVsLs = bookP1(iBooker, "nTracksVsLs", "# tracks vs LS", 150, 0., 1500., 0., 100., "LS", "<N_{gen tk}>");
0054   py_ele_nVerticesVsLs =
0055       bookP1(iBooker, "nVerticesVsLs", "# vertices vs LS", 150, 0., 1500., 0., 10., "LS", "<N_{vert}>");
0056   h1_ele_triggers = bookH1(iBooker, "triggers", "hlt triggers", 256, 0., 256., "HLT bit");
0057 }
0058 
0059 void ElectronGeneralAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0060   edm::Handle<GsfElectronCollection> gsfElectrons;
0061   iEvent.getByToken(electronCollection_, gsfElectrons);
0062   edm::Handle<reco::SuperClusterCollection> recoClusters;
0063   iEvent.getByToken(matchingObjectCollection_, recoClusters);
0064   edm::Handle<reco::TrackCollection> tracks;
0065   iEvent.getByToken(trackCollection_, tracks);
0066   edm::Handle<reco::GsfTrackCollection> gsfTracks;
0067   iEvent.getByToken(gsftrackCollection_, gsfTracks);
0068   edm::Handle<reco::VertexCollection> vertices;
0069   iEvent.getByToken(vertexCollection_, vertices);
0070   edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
0071   iEvent.getByToken(beamSpotTag_, recoBeamSpotHandle);
0072   const BeamSpot bs = *recoBeamSpotHandle;
0073 
0074   edm::EventNumber_t ievt = iEvent.id().event();
0075   edm::RunNumber_t irun = iEvent.id().run();
0076   edm::LuminosityBlockNumber_t ils = iEvent.luminosityBlock();
0077 
0078   edm::LogInfo("ElectronGeneralAnalyzer::analyze")
0079       << "Treating " << gsfElectrons.product()->size() << " electrons"
0080       << " from event " << ievt << " in run " << irun << " and lumiblock " << ils;
0081 
0082   h2_ele_beamSpotXvsY->Fill(bs.position().x(), bs.position().y());
0083   py_ele_nElectronsVsLs->Fill(float(ils), (*gsfElectrons).size());
0084   py_ele_nClustersVsLs->Fill(float(ils), (*recoClusters).size());
0085   py_ele_nGsfTracksVsLs->Fill(float(ils), (*gsfTracks).size());
0086   py_ele_nTracksVsLs->Fill(float(ils), (*tracks).size());
0087   py_ele_nVerticesVsLs->Fill(float(ils), (*vertices).size());
0088 
0089   // trigger
0090   edm::Handle<edm::TriggerResults> triggerResults;
0091   iEvent.getByToken(triggerResults_, triggerResults);
0092   if (triggerResults.isValid()) {
0093     unsigned int i, n = triggerResults->size();
0094     for (i = 0; i != n; ++i) {
0095       if (triggerResults->accept(i)) {
0096         h1_ele_triggers->Fill(float(i));
0097       }
0098     }
0099   }
0100 }