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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
// -*- C++ -*-
//
// Package:   ECALActivity
// Class:     ECALActivity
//
//
// Original Author:  Luca Malgeri

#include <memory>
#include <vector>
#include <map>
#include <set>

// user include files
#include "DPGAnalysis/Skims/interface/ECALActivity.h"

#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
#include "DataFormats/EcalDetId/interface/EBDetId.h"
#include "DataFormats/EcalDetId/interface/EEDetId.h"
#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"

using namespace edm;
using namespace std;

ECALActivity::ECALActivity(const edm::ParameterSet& iConfig) {
  EBRecHitCollection_ = iConfig.getParameter<edm::InputTag>("ebrechitcollection");
  EERecHitCollection_ = iConfig.getParameter<edm::InputTag>("ebrechitcollection");

  EBnum = iConfig.getUntrackedParameter<int>("EBnum");
  EBthresh = iConfig.getUntrackedParameter<double>("EBthresh");
  EEnum = iConfig.getUntrackedParameter<int>("EEnum");
  EEthresh = iConfig.getUntrackedParameter<double>("EEthresh");
  ETOTnum = iConfig.getUntrackedParameter<int>("ETOTnum");
  ETOTthresh = iConfig.getUntrackedParameter<double>("ETOTthresh");
  applyfilter = iConfig.getUntrackedParameter<bool>("applyfilter", true);
}

ECALActivity::~ECALActivity() {}

bool ECALActivity::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
  bool accepted = false;
  bool eb = false;
  bool ee = false;
  bool etot = false;

  //int ievt = iEvent.id().event();
  //int irun = iEvent.id().run();
  //int ils = iEvent.luminosityBlock();

  int ebabovethresh = 0;
  int eeabovethresh = 0;
  int etotabovethresh = 0;

  Handle<EBRecHitCollection> pEBRecHits;
  Handle<EERecHitCollection> pEERecHits;

  const EBRecHitCollection* EBRecHits = nullptr;
  const EERecHitCollection* EERecHits = nullptr;

  if (!EBRecHitCollection_.label().empty() && !EBRecHitCollection_.instance().empty()) {
    iEvent.getByLabel(EBRecHitCollection_, pEBRecHits);
    if (pEBRecHits.isValid()) {
      EBRecHits = pEBRecHits.product();  // get a ptr to the product
    } else {
      edm::LogError("EcalRecHitError") << "Error! can't get the product " << EBRecHitCollection_.label();
    }
  }

  if (!EERecHitCollection_.label().empty() && !EERecHitCollection_.instance().empty()) {
    iEvent.getByLabel(EERecHitCollection_, pEERecHits);

    if (pEERecHits.isValid()) {
      EERecHits = pEERecHits.product();  // get a ptr to the product
    } else {
      edm::LogError("EcalRecHitError") << "Error! can't get the product " << EERecHitCollection_.label();
    }
  }

  // now loop over them
  if (EBRecHits) {
    for (EBRecHitCollection::const_iterator it = EBRecHits->begin(); it != EBRecHits->end(); ++it) {
      if (it->energy() > EBthresh)
        ebabovethresh++;
      if (it->energy() > ETOTthresh)
        etotabovethresh++;
    }
  }
  if (EERecHits) {
    for (EERecHitCollection::const_iterator it = EERecHits->begin(); it != EERecHits->end(); ++it) {
      if (it->energy() > EEthresh)
        eeabovethresh++;
      if (it->energy() > ETOTthresh)
        etotabovethresh++;
    }
  }

  if (ebabovethresh >= EBnum)
    eb = true;
  if (eeabovethresh >= EEnum)
    ee = true;
  if (etotabovethresh >= ETOTnum)
    etot = true;

  accepted = eb | ee | etot;

  if (applyfilter)
    return accepted;
  else
    return true;
}

//define this as a plug-in
DEFINE_FWK_MODULE(ECALActivity);