CMS 3D CMS Logo

MCZll.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MCZll
4 // Class: MCZll
5 //
6 /*
7 
8  Description: filter events based on the Pythia ProcessID and the Pt_hat
9 
10  Implementation: inherits from generic EDFilter
11 
12 */
13 //
14 // Original Author: Paolo Meridiani
15 //
16 //
17 
28 
29 #include <cmath>
30 #include <cstdlib>
31 #include <memory>
32 #include <sstream>
33 #include <string>
34 #include <utility>
35 
36 class MCZll : public edm::global::EDFilter<> {
37 public:
38  explicit MCZll(const edm::ParameterSet&);
39 
40  bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
41 
42 private:
45  double leptonPtMin_;
46  double leptonPtMax_;
47  double leptonEtaMin_;
48  double leptonEtaMax_;
49  std::pair<double, double> zMassRange_;
50  bool filter_;
51 };
52 
53 using namespace edm;
54 using namespace std;
55 
57  : token_(consumes<edm::HepMCProduct>(
58  edm::InputTag(iConfig.getUntrackedParameter("moduleLabel", std::string("generator")), "unsmeared"))) {
59  leptonFlavour_ = iConfig.getUntrackedParameter<int>("leptonFlavour", 11);
60  leptonPtMin_ = iConfig.getUntrackedParameter<double>("leptonPtMin", 5.);
61  leptonPtMax_ = iConfig.getUntrackedParameter<double>("leptonPtMax", 99999.);
62  leptonEtaMin_ = iConfig.getUntrackedParameter<double>("leptonEtaMin", 0.);
63  leptonEtaMax_ = iConfig.getUntrackedParameter<double>("leptonEtaMax", 2.7);
64  zMassRange_.first = iConfig.getUntrackedParameter<double>("zMassMin", 60.);
65  zMassRange_.second = iConfig.getUntrackedParameter<double>("zMassMax", 120.);
66  filter_ = iConfig.getUntrackedParameter<bool>("filter", true);
67  std::ostringstream str;
68  str << "=========================================================\n"
69  << "Filter MCZll being constructed with parameters: "
70  << "\nleptonFlavour " << leptonFlavour_ << "\nleptonPtMin " << leptonPtMin_ << "\nleptonPtMax " << leptonPtMax_
71  << "\nleptonEtaMin " << leptonEtaMin_ << "\nleptonEtaMax " << leptonEtaMax_ << "\nzMassMin " << zMassRange_.first
72  << "\nzMassMax " << zMassRange_.second << "\n=========================================================";
73  edm::LogVerbatim("MCZllInfo") << str.str();
74  if (filter_)
75  produces<HepMCProduct>();
76 }
77 
79  std::unique_ptr<HepMCProduct> bare_product(new HepMCProduct());
80 
81  bool accepted = false;
83  iEvent.getByToken(token_, evt);
84  HepMC::GenEvent* myGenEvent = new HepMC::GenEvent(*(evt->GetEvent()));
85  HepMC::GenEvent* zEvent = new HepMC::GenEvent();
86 
87  if (myGenEvent->signal_process_id() != 1) {
88  delete myGenEvent;
89  delete zEvent;
90  return false;
91  }
92 
93  //found a prompt Z
94 
95  for (HepMC::GenEvent::particle_iterator p = myGenEvent->particles_begin(); p != myGenEvent->particles_end(); ++p) {
96  if (!accepted && ((*p)->pdg_id() == 23) && (*p)->status() == 3) {
97  accepted = true;
98  HepMC::GenVertex* zVertex = new HepMC::GenVertex();
99  HepMC::GenParticle* myZ = new HepMC::GenParticle(*(*p));
100  zVertex->add_particle_in(myZ);
101  // std::cout << (*p)->momentum().invariantMass() << std::endl;
102  if ((*p)->momentum().m() < zMassRange_.first || (*p)->momentum().m() > zMassRange_.second)
103  accepted = false;
104  std::vector<HepMC::GenParticle*> children;
105  HepMC::GenVertex* outVertex = (*p)->end_vertex();
106  for (HepMC::GenVertex::particles_out_const_iterator iter = outVertex->particles_out_const_begin();
107  iter != outVertex->particles_out_const_end();
108  iter++)
109  children.push_back(*iter);
110  std::vector<HepMC::GenParticle*>::const_iterator aDaughter;
111  for (aDaughter = children.begin(); aDaughter != children.end(); aDaughter++) {
112  HepMC::GenParticle* myDa = new HepMC::GenParticle(*(*aDaughter));
113  zVertex->add_particle_out(myDa);
114  if ((*aDaughter)->status() == 2)
115  continue;
116  // (*aDaughter)->print();
117 
118  if (!(abs((*aDaughter)->pdg_id()) == abs(leptonFlavour_)))
119  accepted = false;
120  // std::cout << (*aDaughter)->momentum().perp() << " " << (*aDaughter)->momentum().eta() << std::endl;
121  if ((*aDaughter)->momentum().perp() < leptonPtMin_)
122  accepted = false;
123  if ((*aDaughter)->momentum().perp() > leptonPtMax_)
124  accepted = false;
125  if (fabs((*aDaughter)->momentum().eta()) > leptonEtaMax_)
126  accepted = false;
127  if (fabs((*aDaughter)->momentum().eta()) < leptonEtaMin_)
128  accepted = false;
129  }
130  zEvent->add_vertex(zVertex);
131  if (accepted)
132  break;
133  }
134  }
135 
136  if (accepted) {
137  if (zEvent)
138  bare_product->addHepMCData(zEvent);
139  if (filter_)
140  iEvent.put(std::move(bare_product));
141  LogDebug("MCZll") << "Event " << iEvent.id().event() << " accepted" << std::endl;
142  delete myGenEvent;
143  return true;
144  }
145 
146  delete myGenEvent;
147  delete zEvent;
148  return false;
149 }
150 
Log< level::Info, true > LogVerbatim
bool filter_
Definition: MCZll.cc:50
double leptonPtMin_
Definition: MCZll.cc:45
double leptonEtaMin_
Definition: MCZll.cc:47
Definition: MCZll.cc:36
int leptonFlavour_
Definition: MCZll.cc:44
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double leptonEtaMax_
Definition: MCZll.cc:48
const edm::EDGetTokenT< edm::HepMCProduct > token_
Definition: MCZll.cc:43
T getUntrackedParameter(std::string const &, T const &) const
int iEvent
Definition: GenABIO.cc:224
bool filter(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: MCZll.cc:78
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double leptonPtMax_
Definition: MCZll.cc:46
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
std::pair< double, double > zMassRange_
Definition: MCZll.cc:49
HLT enums.
MCZll(const edm::ParameterSet &)
Definition: MCZll.cc:56
#define str(s)
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)