PythiaFilterHT

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
// -*- C++ -*-
//
// Package:    PythiaFilterHT
// Class:      PythiaFilterHT
//
/**\class PythiaFilterHT PythiaFilterHT.cc IOMC/PythiaFilterHT/src/PythiaFilterHT.cc

 Description: <one line class summary>

 Implementation:
     <Notes on implementation>
*/
//
// Original Author:  Alejandro Gomez Espinosa
//
//

#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/global/EDFilter.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"

#include <cmath>
#include <cstdlib>
#include <string>

class PythiaFilterHT : public edm::global::EDFilter<> {
public:
  explicit PythiaFilterHT(const edm::ParameterSet&);

  bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;

private:
  const edm::EDGetTokenT<edm::HepMCProduct> label_;
  const double minhtcut;
  const int motherID;
};

using namespace std;

PythiaFilterHT::PythiaFilterHT(const edm::ParameterSet& iConfig)
    : label_(consumes<edm::HepMCProduct>(
          edm::InputTag(iConfig.getUntrackedParameter("moduleLabel", std::string("generator")), "unsmeared"))),
      minhtcut(iConfig.getUntrackedParameter("MinHT", 0.)),
      motherID(iConfig.getUntrackedParameter("MotherID", 0)) {}

bool PythiaFilterHT::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const {
  bool accepted = false;
  edm::Handle<edm::HepMCProduct> evt;
  iEvent.getByToken(label_, evt);

  const HepMC::GenEvent* myGenEvent = evt->GetEvent();

  double HT = 0;

  for (HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin(); p != myGenEvent->particles_end();
       ++p) {
    if (((*p)->status() == 23) && ((abs((*p)->pdg_id()) < 6) || ((*p)->pdg_id() == 21))) {
      if (motherID == 0) {
        HT += (*p)->momentum().perp();
      } else {
        HepMC::GenParticle* mother = (*((*p)->production_vertex()->particles_in_const_begin()));
        if (abs(mother->pdg_id()) == abs(motherID)) {
          HT += (*p)->momentum().perp();
        }
      }
    }
  }
  if (HT > minhtcut)
    accepted = true;
  return accepted;
}

DEFINE_FWK_MODULE(PythiaFilterHT);