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 
edm::StreamID
Definition: StreamID.h:30
MCZll::leptonEtaMax_
double leptonEtaMax_
Definition: MCZll.cc:48
MCZll::token_
const edm::EDGetTokenT< edm::HepMCProduct > token_
Definition: MCZll.cc:43
Handle.h
MessageLogger.h
edm::EDGetTokenT< edm::HepMCProduct >
edm
HLT enums.
Definition: AlignableModifier.h:19
class-composition.children
children
Definition: class-composition.py:98
ZgammaFilter_cfi.HepMCProduct
HepMCProduct
Definition: ZgammaFilter_cfi.py:9
MCZll::leptonEtaMin_
double leptonEtaMin_
Definition: MCZll.cc:47
MCZll
Definition: MCZll.cc:36
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
MCZll::filter
bool filter(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: MCZll.cc:78
edm::Handle
Definition: AssociativeIterator.h:50
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
MCZll::filter_
bool filter_
Definition: MCZll.cc:50
HLT_FULL_cff.zVertex
zVertex
Definition: HLT_FULL_cff.py:113803
MCZll::leptonPtMax_
double leptonPtMax_
Definition: MCZll.cc:46
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
str
#define str(s)
Definition: TestProcessor.cc:53
EDGetToken.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
Event.h
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:58
MCZll::MCZll
MCZll(const edm::ParameterSet &)
Definition: MCZll.cc:56
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
InputTag.h
GenParticle.GenParticle
GenParticle
Definition: GenParticle.py:18
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
MCZll::leptonPtMin_
double leptonPtMin_
Definition: MCZll.cc:45
edm::global::EDFilter
Definition: EDFilter.h:32
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::HepMCProduct
Definition: HepMCProduct.h:21
ParameterSet.h
HepMCProduct.h
edm::Event
Definition: Event.h:73
EDFilter.h
edm::InputTag
Definition: InputTag.h:15
MCZll::leptonFlavour_
int leptonFlavour_
Definition: MCZll.cc:44
MCZll::zMassRange_
std::pair< double, double > zMassRange_
Definition: MCZll.cc:49