CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
PythiaDauVFilterMatchID Class Reference

#include <PythiaDauVFilterMatchID.h>

Inheritance diagram for PythiaDauVFilterMatchID:
edm::global::EDFilter<> edm::global::EDFilterBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

bool filter (edm::StreamID, edm::Event &, const edm::EventSetup &) const override
 
 PythiaDauVFilterMatchID (const edm::ParameterSet &)
 
 ~PythiaDauVFilterMatchID () override
 
- Public Member Functions inherited from edm::global::EDFilter<>
 EDFilter ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::EDFilterBase
 EDFilterBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDFilterBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Attributes

const bool chargeconju
 
std::vector< int > dauIDs
 
std::unique_ptr< Pythia8::Pythia > fLookupGen
 
const int fVerbose
 
std::vector< double > maxetacut
 
const double maxptcut
 
std::vector< double > minetacut
 
std::vector< double > minptcut
 
const int motherID
 
const int ndaughters
 
const int particleID
 
const edm::EDGetTokenT< edm::HepMCProducttoken_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDFilterBase
typedef EDFilterBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::global::EDFilterBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Description: Filter events using MotherId and ChildrenIds infos

Implementation: <Notes on="" implementation>="">

Definition at line 50 of file PythiaDauVFilterMatchID.h.

Constructor & Destructor Documentation

PythiaDauVFilterMatchID::PythiaDauVFilterMatchID ( const edm::ParameterSet iConfig)
explicit

Definition at line 11 of file PythiaDauVFilterMatchID.cc.

References dauIDs, fLookupGen, edm::ParameterSet::getUntrackedParameter(), mps_fire::i, maxetacut, maxptcut, minetacut, minptcut, motherID, and particleID.

11  :
12  fVerbose(iConfig.getUntrackedParameter("verbose",0)),
13  token_(consumes<edm::HepMCProduct>(edm::InputTag(iConfig.getUntrackedParameter("moduleLabel",std::string("generator")),"unsmeared"))),
14  particleID(iConfig.getUntrackedParameter("ParticleID", 0)),
15  motherID(iConfig.getUntrackedParameter("MotherID", 0)),
16  chargeconju(iConfig.getUntrackedParameter("ChargeConjugation", true)),
17  ndaughters(iConfig.getUntrackedParameter("NumberDaughters", 0)),
18  maxptcut(iConfig.getUntrackedParameter("MaxPt", 14000.))
19 {
20  //now do what ever initialization is needed
21  vector<int> defdauID;
22  defdauID.push_back(0);
23  dauIDs = iConfig.getUntrackedParameter< vector<int> >("DaughterIDs",defdauID);
24  vector<double> defminptcut;
25  defminptcut.push_back(0.);
26  minptcut = iConfig.getUntrackedParameter< vector<double> >("MinPt",defminptcut);
27  vector<double> defminetacut;
28  defminetacut.push_back(-10.);
29  minetacut = iConfig.getUntrackedParameter< vector<double> >("MinEta",defminetacut);
30  vector<double> defmaxetacut;
31  defmaxetacut.push_back(10.);
32  maxetacut = iConfig.getUntrackedParameter< vector<double> >("MaxEta",defmaxetacut);
33 
34  edm::LogInfo("PythiaDauVFilterMatchID") << "----------------------------------------------------------------------" << endl;
35  edm::LogInfo("PythiaDauVFilterMatchID") << "--- PythiaDauVFilterMatchID" << endl;
36  for (unsigned int i=0; i<dauIDs.size(); ++i) {
37  edm::LogInfo("PythiaDauVFilterMatchID") << "ID: " << dauIDs[i] << " pT > " << minptcut[i] << " " << minetacut[i] << " eta < " << maxetacut[i] << endl;
38  }
39  edm::LogInfo("PythiaDauVFilterMatchID") << "maxptcut = " << maxptcut << endl;
40  edm::LogInfo("PythiaDauVFilterMatchID") << "particleID = " << particleID << endl;
41  edm::LogInfo("PythiaDauVFilterMatchID") << "motherID = " << motherID << endl;
42 
43  // create pythia8 instance to access particle data
44  edm::LogInfo("PythiaDauVFilterMatchID") << "Creating pythia8 instance for particle properties" << endl;
45  if(!fLookupGen.get()) fLookupGen.reset(new Pythia());
46 }
std::unique_ptr< Pythia8::Pythia > fLookupGen
T getUntrackedParameter(std::string const &, T const &) const
std::vector< double > minetacut
std::vector< double > maxetacut
std::vector< double > minptcut
const edm::EDGetTokenT< edm::HepMCProduct > token_
PythiaDauVFilterMatchID::~PythiaDauVFilterMatchID ( )
override

Definition at line 49 of file PythiaDauVFilterMatchID.cc.

50 {
51 
52  // do anything here that needs to be done at desctruction time
53  // (e.g. close files, deallocate resources etc.)
54 
55 }

Member Function Documentation

bool PythiaDauVFilterMatchID::filter ( edm::StreamID  ,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
override

Definition at line 63 of file PythiaDauVFilterMatchID.cc.

References funct::abs(), Abs(), cms::dd::accepted(), chargeconju, class-composition::children, dauIDs, fLookupGen, fVerbose, edm::Event::getByToken(), edm::HepMCProduct::GetEvent(), mps_fire::i, decayTarget::maxEta, maxetacut, decayTarget::maxPt, maxptcut, decayTarget::minEta, minetacut, decayTarget::minPt, minptcut, motherID, ndaughters, AlCaHLTBitMon_ParallelJobs::p, particleID, decayTarget::pdgID, edmPickEvents::target, and token_.

63  {
64  using namespace edm;
65  bool accepted = false;
67  iEvent.getByToken(token_, evt);
68 
69  int OK(1);
70  vector<int> vparticles;
71 
72  HepMC::GenEvent *myGenEvent = new HepMC::GenEvent(*(evt->GetEvent()));
73 
74  if (fVerbose > 5) {
75  edm::LogInfo("PythiaDauVFilterMatchID") << "looking for " << particleID << endl;
76  }
77 
78  for (HepMC::GenEvent::particle_iterator p = myGenEvent->particles_begin(); p != myGenEvent->particles_end(); ++p) {
79 
80  if ((*p)->pdg_id() != particleID) continue ;
81 
82  // -- Check for mother of this particle
83  if (0 != motherID) {
84  OK = 0;
85  for (HepMC::GenVertex::particles_in_const_iterator des = (*p)->production_vertex()->particles_in_const_begin();
86  des != (*p)->production_vertex()->particles_in_const_end();
87  ++des) {
88  if (fVerbose > 10) {
89  edm::LogInfo("PythiaDauVFilterMatchID") << "mother: " << (*des)->pdg_id() << " pT: " << (*des)->momentum().perp() << " eta: " << (*des)->momentum().eta() << endl;
90  }
91  if (abs(motherID) == abs((*des)->pdg_id())) {
92  OK = 1;
93  break;
94  }
95  }
96  }
97  if (0 == OK) continue;
98 
99  //generate targets
100  std::vector<decayTarget> targets;
101  for (unsigned int i=0;i<dauIDs.size();i++)
102  {
104  target.pdgID = dauIDs[i];
105  target.minPt = minptcut[i];
106  target.maxPt = maxptcut;
107  target.minEta = minetacut[i];
108  target.maxEta = maxetacut[i];
109  targets.push_back(target);
110  }
111  if (fVerbose>10)
112  {
113  edm::LogInfo("PythiaDauVFilterMatchID") << "created target: ";
114  for (unsigned int i=0;i<targets.size();i++) {edm::LogInfo("PythiaDauVFilterMatchID") << targets[i].pdgID << " ";}
115  edm::LogInfo("PythiaDauVFilterMatchID") << endl;
116  }
117 
118  // -- check for daugthers
119  int ndau = 0;
120  if (fVerbose > 5) {
121  edm::LogInfo("PythiaDauVFilterMatchID") << "found ID: " << (*p)->pdg_id() << " pT: " << (*p)->momentum().perp() << " eta: " << (*p)->momentum().eta() << endl;
122  }
123  vparticles.push_back((*p)->pdg_id());
124  if ((*p)->end_vertex()) {
125  for (HepMC::GenVertex::particle_iterator des=(*p)->end_vertex()->particles_begin(HepMC::children);
126  des != (*p)->end_vertex()->particles_end(HepMC::children);
127  ++des) {
128  if ( TMath::Abs((*des)->pdg_id()) == 22 ) {continue;}
129  ++ndau;
130  if (fVerbose > 5) {
131  edm::LogInfo("PythiaDauVFilterMatchID") << "ID: " << (*des)->pdg_id() << " pT: " << (*des)->momentum().perp() << " eta: " << (*des)->momentum().eta() << endl;
132  }
133  { // protect matchedIdx
134  int matchedIdx=-1;
135  for (unsigned int i=0;i<targets.size();i++)
136  {
137  if ( (*des)->pdg_id() != targets[i].pdgID ) {continue;}
138  if (fVerbose>5) {edm::LogInfo("PythiaDauVFilterMatchID") << "i = " << i << " pT = " << (*des)->momentum().perp() << " eta = " << (*des)->momentum().eta() << endl;}
139 
140  if ((*des)->momentum().perp() > targets[i].minPt &&
141  (*des)->momentum().perp() < targets[i].maxPt &&
142  (*des)->momentum().eta() > targets[i].minEta &&
143  (*des)->momentum().eta() < targets[i].maxEta )
144  {
145  vparticles.push_back((*des)->pdg_id());
146  if (fVerbose > 2) {
147  edm::LogInfo("PythiaDauVFilterMatchID") << " accepted this particle " << (*des)->pdg_id()
148  << " pT = " << (*des)->momentum().perp() << " eta = " << (*des)->momentum().eta() << endl;
149  }
150  matchedIdx=i;
151  break;
152  }
153  }
154  if (matchedIdx>-1) {targets.erase(targets.begin()+matchedIdx);}
155  if (fVerbose>10)
156  {
157  edm::LogInfo("PythiaDauVFilterMatchID") << "remaining targets: ";
158  for (unsigned int i=0;i<targets.size();i++) {edm::LogInfo("PythiaDauVFilterMatchID") << targets[i].pdgID << " ";}
159  edm::LogInfo("PythiaDauVFilterMatchID") << endl;
160  }
161  }
162  }
163  }
164 
165  if (ndau == ndaughters && targets.size() == 0 )
166  {
167  accepted=true;
168  if (fVerbose > 0) {
169  edm::LogInfo("PythiaDauVFilterMatchID") << " accepted this decay: ";
170  for (unsigned int iv = 0; iv < vparticles.size(); ++iv) edm::LogInfo("PythiaDauVFilterMatchID") << vparticles[iv] << " ";
171  edm::LogInfo("PythiaDauVFilterMatchID") << " from mother = " << motherID << endl;
172  }
173  break;
174  }
175 
176  }
177 
178 
179  int anti_particleID = -particleID;
180  if ( !(fLookupGen->particleData.isParticle( anti_particleID )) ) {
181  anti_particleID = 0;
182  if (fVerbose > 5) edm::LogInfo("PythiaDauVFilterMatchID") << "Particle " << particleID << " is its own anti-particle, skipping further testing " << endl;
183  }
184  if (!accepted && chargeconju && anti_particleID) {
185  OK = 1;
186 
187  for (HepMC::GenEvent::particle_iterator p = myGenEvent->particles_begin();
188  p != myGenEvent->particles_end(); ++p) {
189 
190  if ((*p)->pdg_id() != anti_particleID) continue ;
191 
192  // -- Check for mother of this particle
193  if (0 != motherID) {
194  OK = 0;
195  for (HepMC::GenVertex::particles_in_const_iterator des = (*p)->production_vertex()->particles_in_const_begin();
196  des != (*p)->production_vertex()->particles_in_const_end();
197  ++des) {
198  if (fVerbose > 10) {
199  edm::LogInfo("PythiaDauVFilterMatchID") << "mother: " << (*des)->pdg_id() << " pT: " << (*des)->momentum().perp() << " eta: " << (*des)->momentum().eta() << endl;
200  }
201  if (abs(motherID) == abs((*des)->pdg_id())) {
202  OK = 1;
203  break;
204  }
205  }
206  }
207  if (0 == OK) continue;
208 
209  //generate anti targets
210  std::vector<decayTarget> targets;
211  for (unsigned int i=0;i<dauIDs.size();i++)
212  {
214  int IDanti = -dauIDs[i];
215  if ( !(fLookupGen->particleData.isParticle( IDanti )) ) IDanti = dauIDs[i];
216  target.pdgID = IDanti;
217  target.minPt = minptcut[i];
218  target.maxPt = maxptcut;
219  target.minEta = minetacut[i];
220  target.maxEta = maxetacut[i];
221  targets.push_back(target);
222  }
223  if (fVerbose>10)
224  {
225  edm::LogInfo("PythiaDauVFilterMatchID") << "created anti target: ";
226  for (unsigned int i=0;i<targets.size();i++) {edm::LogInfo("PythiaDauVFilterMatchID") << targets[i].pdgID << " ";}
227  edm::LogInfo("PythiaDauVFilterMatchID") << endl;
228  }
229 
230  if (fVerbose > 5) {
231  edm::LogInfo("PythiaDauVFilterMatchID") << "found ID: " << (*p)->pdg_id() << " pT: " << (*p)->momentum().perp() << " eta: " << (*p)->momentum().eta() << endl;
232  }
233  vparticles.push_back((*p)->pdg_id());
234  int ndau = 0;
235  if ((*p)->end_vertex()) {
236  for (HepMC::GenVertex::particle_iterator des=(*p)->end_vertex()->particles_begin(HepMC::children);
237  des != (*p)->end_vertex()->particles_end(HepMC::children);
238  ++des) {
239  if ( TMath::Abs((*des)->pdg_id()) == 22 ) {continue;}
240  ++ndau;
241  if (fVerbose > 5) {
242  edm::LogInfo("PythiaDauVFilterMatchID") << "ID: " << (*des)->pdg_id() << " pT: " << (*des)->momentum().perp() << " eta: " << (*des)->momentum().eta() << endl;
243  }
244  { // protect matchedIdx
245  int matchedIdx=-1;
246  for (unsigned int i=0;i<targets.size();i++)
247  {
248  if ( (*des)->pdg_id() != targets[i].pdgID ) {continue;}
249  if (fVerbose>5) {edm::LogInfo("PythiaDauVFilterMatchID") << "i = " << i << " pT = " << (*des)->momentum().perp() << " eta = " << (*des)->momentum().eta() << endl;}
250 
251  if ((*des)->momentum().perp() > targets[i].minPt &&
252  (*des)->momentum().perp() < targets[i].maxPt &&
253  (*des)->momentum().eta() > targets[i].minEta &&
254  (*des)->momentum().eta() < targets[i].maxEta )
255  {
256  vparticles.push_back((*des)->pdg_id());
257  if (fVerbose > 2) {
258  edm::LogInfo("PythiaDauVFilterMatchID") << " accepted this particle " << (*des)->pdg_id()
259  << " pT = " << (*des)->momentum().perp() << " eta = " << (*des)->momentum().eta() << endl;
260  }
261  matchedIdx=i;
262  break;
263  }
264  }
265  if (matchedIdx>-1) {targets.erase(targets.begin()+matchedIdx);}
266  if (fVerbose>10)
267  {
268  edm::LogInfo("PythiaDauVFilterMatchID") << "remaining targets: ";
269  for (unsigned int i=0;i<targets.size();i++) {edm::LogInfo("PythiaDauVFilterMatchID") << targets[i].pdgID << " ";}
270  edm::LogInfo("PythiaDauVFilterMatchID") << endl;
271  }
272  }
273  }
274  }
275  if (ndau == ndaughters && targets.size() == 0 )
276  {
277  accepted=true;
278  if (fVerbose > 0) {
279  edm::LogInfo("PythiaDauVFilterMatchID") << " accepted this decay: ";
280  for (unsigned int iv = 0; iv < vparticles.size(); ++iv) edm::LogInfo("PythiaDauVFilterMatchID") << vparticles[iv] << " ";
281  edm::LogInfo("PythiaDauVFilterMatchID") << " from mother = " << motherID << endl;
282  }
283  break;
284  }
285  }
286 
287  }
288 
289  delete myGenEvent;
290  return accepted;
291 
292 }
std::unique_ptr< Pythia8::Pythia > fLookupGen
std::vector< double > minetacut
std::vector< double > maxetacut
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::vector< double > minptcut
const edm::EDGetTokenT< edm::HepMCProduct > token_
T Abs(T a)
Definition: MathUtil.h:49
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::pair< int, edm::FunctionWithDict > OK
Definition: findMethod.cc:136
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
bool accepted(std::vector< std::string_view > const &, std::string_view)
HLT enums.

Member Data Documentation

const bool PythiaDauVFilterMatchID::chargeconju
private

Definition at line 63 of file PythiaDauVFilterMatchID.h.

Referenced by filter().

std::vector<int> PythiaDauVFilterMatchID::dauIDs
private

Definition at line 60 of file PythiaDauVFilterMatchID.h.

Referenced by filter(), and PythiaDauVFilterMatchID().

std::unique_ptr<Pythia8::Pythia> PythiaDauVFilterMatchID::fLookupGen
private

Definition at line 69 of file PythiaDauVFilterMatchID.h.

Referenced by filter(), and PythiaDauVFilterMatchID().

const int PythiaDauVFilterMatchID::fVerbose
private

Definition at line 58 of file PythiaDauVFilterMatchID.h.

Referenced by filter().

std::vector<double> PythiaDauVFilterMatchID::maxetacut
private

Definition at line 68 of file PythiaDauVFilterMatchID.h.

Referenced by filter(), and PythiaDauVFilterMatchID().

const double PythiaDauVFilterMatchID::maxptcut
private

Definition at line 66 of file PythiaDauVFilterMatchID.h.

Referenced by filter(), and PythiaDauVFilterMatchID().

std::vector<double> PythiaDauVFilterMatchID::minetacut
private

Definition at line 67 of file PythiaDauVFilterMatchID.h.

Referenced by filter(), and PythiaDauVFilterMatchID().

std::vector<double> PythiaDauVFilterMatchID::minptcut
private

Definition at line 65 of file PythiaDauVFilterMatchID.h.

Referenced by filter(), and PythiaDauVFilterMatchID().

const int PythiaDauVFilterMatchID::motherID
private

Definition at line 62 of file PythiaDauVFilterMatchID.h.

Referenced by filter(), and PythiaDauVFilterMatchID().

const int PythiaDauVFilterMatchID::ndaughters
private

Definition at line 64 of file PythiaDauVFilterMatchID.h.

Referenced by filter().

const int PythiaDauVFilterMatchID::particleID
private

Definition at line 61 of file PythiaDauVFilterMatchID.h.

Referenced by filter(), and PythiaDauVFilterMatchID().

const edm::EDGetTokenT<edm::HepMCProduct> PythiaDauVFilterMatchID::token_
private

Definition at line 59 of file PythiaDauVFilterMatchID.h.

Referenced by filter().