CMS 3D CMS Logo

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

#include <MCParticlePairFilter.h>

Inheritance diagram for MCParticlePairFilter:
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
 
 MCParticlePairFilter (const edm::ParameterSet &)
 
 ~MCParticlePairFilter () 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 Member Functions

int charge (int Id) const
 

Private Attributes

const double betaBoost
 
std::vector< double > etaMax
 
std::vector< double > etaMin
 
const double maxDeltaPhi
 
const double maxDeltaR
 
const double maxInvMass
 
const double minDeltaPhi
 
const double minDeltaR
 
const double minInvMass
 
const int particleCharge
 
std::vector< int > particleID1
 
std::vector< int > particleID2
 
std::vector< double > pMin
 
std::vector< double > ptMin
 
std::vector< int > status
 
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

Definition at line 42 of file MCParticlePairFilter.h.

Constructor & Destructor Documentation

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

Definition at line 14 of file MCParticlePairFilter.cc.

References gather_cfg::cout, etaMax, etaMin, edm::ParameterSet::getUntrackedParameter(), mps_fire::i, particleID1, particleID2, pMin, ptMin, and status.

14  :
15 token_(consumes<edm::HepMCProduct>(edm::InputTag(iConfig.getUntrackedParameter("moduleLabel",std::string("generator")),"unsmeared"))),
16 particleCharge(iConfig.getUntrackedParameter("ParticleCharge",0)),
17 minInvMass(iConfig.getUntrackedParameter("MinInvMass", 0.)),
18 maxInvMass(iConfig.getUntrackedParameter("MaxInvMass", 14000.)),
19 minDeltaPhi(iConfig.getUntrackedParameter("MinDeltaPhi", 0.)),
20 maxDeltaPhi(iConfig.getUntrackedParameter("MaxDeltaPhi", 6.3)),
21 minDeltaR(iConfig.getUntrackedParameter("MinDeltaR",0.)),
22 maxDeltaR(iConfig.getUntrackedParameter("MaxDeltaR",10000.)),
23 betaBoost(iConfig.getUntrackedParameter("BetaBoost",0.))
24 {
25  //here do whatever other initialization is needed
26  vector<int> defpid1;
27  defpid1.push_back(0);
28  particleID1 = iConfig.getUntrackedParameter< vector<int> >("ParticleID1",defpid1);
29  vector<int> defpid2;
30  defpid2.push_back(0);
31  particleID2 = iConfig.getUntrackedParameter< vector<int> >("ParticleID2",defpid2);
32  vector<double> defptmin;
33  defptmin.push_back(0.);
34  ptMin = iConfig.getUntrackedParameter< vector<double> >("MinPt", defptmin);
35  vector<double> defpmin;
36  defpmin.push_back(0.);
37  pMin = iConfig.getUntrackedParameter< vector<double> >("MinP", defpmin);
38 
39  vector<double> defetamin;
40  defetamin.push_back(-10.);
41  etaMin = iConfig.getUntrackedParameter< vector<double> >("MinEta", defetamin);
42  vector<double> defetamax ;
43  defetamax.push_back(10.);
44  etaMax = iConfig.getUntrackedParameter< vector<double> >("MaxEta", defetamax);
45  vector<int> defstat ;
46  defstat.push_back(0);
47  status = iConfig.getUntrackedParameter< vector<int> >("Status", defstat);
48 
49 
50  // check for correct size
51  if (ptMin.size() != 2
52  || pMin.size() != 2
53  || etaMin.size() != 2
54  || etaMax.size() != 2
55  || status.size() != 2 ) {
56  cout << "WARNING: MCParticlePairFilter : size of some vectors not matching with 2!!" << endl;
57  }
58 
59  // if ptMin size smaller than 2, fill up further with defaults
60  if (2 > ptMin.size() ){
61  vector<double> defptmin2 ;
62  for (unsigned int i = 0; i < 2; i++){ defptmin2.push_back(0.);}
63  ptMin = defptmin2;
64  }
65  // if pMin size smaller than 2, fill up further with defaults
66  if (2 > pMin.size() ){
67  vector<double> defpmin2 ;
68  for (unsigned int i = 0; i < 2; i++){ defpmin2.push_back(0.);}
69  pMin = defpmin2;
70  }
71  // if etaMin size smaller than 2, fill up further with defaults
72  if (2 > etaMin.size() ){
73  vector<double> defetamin2 ;
74  for (unsigned int i = 0; i < 2; i++){ defetamin2.push_back(-10.);}
75  etaMin = defetamin2;
76  }
77  // if etaMax size smaller than 2, fill up further with defaults
78  if (2 > etaMax.size() ){
79  vector<double> defetamax2 ;
80  for (unsigned int i = 0; i < 2; i++){ defetamax2.push_back(10.);}
81  etaMax = defetamax2;
82  }
83  // if status size smaller than 2, fill up further with defaults
84  if (2 > status.size() ){
85  vector<int> defstat2 ;
86  for (unsigned int i = 0; i < 2; i++){ defstat2.push_back(0);}
87  status = defstat2;
88  }
89 
90 }
T getUntrackedParameter(std::string const &, T const &) const
std::vector< double > ptMin
std::vector< double > pMin
std::vector< double > etaMin
std::vector< int > particleID1
std::vector< double > etaMax
std::vector< int > particleID2
const edm::EDGetTokenT< edm::HepMCProduct > token_
std::vector< int > status
MCParticlePairFilter::~MCParticlePairFilter ( )
override

Definition at line 93 of file MCParticlePairFilter.cc.

94 {
95 
96  // do anything here that needs to be done at desctruction time
97  // (e.g. close files, deallocate resources etc.)
98 
99 }

Member Function Documentation

int MCParticlePairFilter::charge ( int  Id) const
private

Definition at line 265 of file MCParticlePairFilter.cc.

References funct::abs(), and constexpr.

Referenced by filter().

265  {
266 
267 
268  //...Purpose: to give three times the charge for a particle/parton.
269 
270  // ID = particle ID
271  // hepchg = particle charge times 3
272 
273  int kqa,kq1,kq2,kq3,kqj,irt,kqx,kqn;
274  int hepchg;
275 
276 
277  constexpr const int ichg[109]={-1,2,-1,2,-1,2,-1,2,0,0,-3,0,-3,0,-3,0,
278 -3,0,0,0,0,0,0,3,0,0,0,0,0,0,3,0,3,6,0,0,3,6,0,0,-1,2,-1,2,-1,2,0,0,0,0,
279 -3,0,-3,0,-3,0,0,0,0,0,-1,2,-1,2,-1,2,0,0,0,0,
280 -3,0,-3,0,-3,0,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
281 
282 
283  //...Initial values. Simple case of direct readout.
284  hepchg=0;
285  kqa=abs(Id);
286  kqn=kqa/1000000000%10;
287  kqx=kqa/1000000%10;
288  kq3=kqa/1000%10;
289  kq2=kqa/100%10;
290  kq1=kqa/10%10;
291  kqj=kqa%10;
292  irt=kqa%10000;
293 
294  //...illegal or ion
295  //...set ion charge to zero - not enough information
296  if(kqa==0 || kqa >= 10000000) {
297 
298  if(kqn==1) {hepchg=0;}
299  }
300  //... direct translation
301  else if(kqa<=100) {hepchg = ichg[kqa-1];}
302  //... KS and KL (and undefined)
303  else if(kqj == 0) {hepchg = 0;}
304  //C... direct translation
305  else if(kqx>0 && irt<100)
306  {
307  hepchg = ichg[irt-1];
308  if(kqa==1000017 || kqa==1000018) {hepchg = 0;}
309  if(kqa==1000034 || kqa==1000052) {hepchg = 0;}
310  if(kqa==1000053 || kqa==1000054) {hepchg = 0;}
311  if(kqa==5100061 || kqa==5100062) {hepchg = 6;}
312  }
313  //...Construction from quark content for heavy meson, diquark, baryon.
314  //...Mesons.
315  else if(kq3==0)
316  {
317  hepchg = ichg[kq2-1]-ichg[kq1-1];
318  //...Strange or beauty mesons.
319  if((kq2==3) || (kq2==5)) {hepchg = ichg[kq1-1]-ichg[kq2-1];}
320  }
321  else if(kq1 == 0) {
322  //...Diquarks.
323  hepchg = ichg[kq3-1] + ichg[kq2-1];
324  }
325 
326  else{
327  //...Baryons
328  hepchg = ichg[kq3-1]+ichg[kq2-1]+ichg[kq1-1];
329  }
330 
331  //... fix sign of charge
332  if(Id<0 && hepchg!=0) {hepchg = -1*hepchg;}
333 
334  // cout << hepchg<< endl;
335  return hepchg;
336 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define constexpr
bool MCParticlePairFilter::filter ( edm::StreamID  ,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
override

Definition at line 103 of file MCParticlePairFilter.cc.

References funct::abs(), cms::dd::accepted(), betaBoost, charge(), boostedElectronIsolation_cff::deltaR, etaMax, etaMin, edm::Event::getByToken(), edm::HepMCProduct::GetEvent(), mps_fire::i, maxDeltaPhi, maxDeltaR, maxInvMass, minDeltaPhi, minDeltaR, minInvMass, AlCaHLTBitMon_ParallelJobs::p, particleCharge, particleID1, particleID2, HiggsValidation_cfi::pdg_id, pi, pMin, ptMin, mathSSE::sqrt(), status, token_, and MCFilterZboostHelper::zboost().

104 {
105  using namespace edm;
106  bool accepted = false;
108  iEvent.getByToken(token_, evt);
109  const double pi = 3.14159;
110 
111  vector<HepMC::GenParticle*> typeApassed;
112  vector<HepMC::GenParticle*> typeBpassed;
113 
114 
115  const HepMC::GenEvent * myGenEvent = evt->GetEvent();
116 
117 
118  for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();
119  p != myGenEvent->particles_end(); ++p ) {
120 
121  // check for type A conditions
122  bool gottypeAID = false;
123  for(unsigned int j=0; j<particleID1.size(); ++j) {
124  if(abs((*p)->pdg_id()) == abs(particleID1[j]) || particleID1[j] == 0) {
125  gottypeAID = true;
126  break;
127  }
128  }
129  if(gottypeAID) {
130  HepMC::FourVector mom = MCFilterZboostHelper::zboost((*p)->momentum(),betaBoost);
131  if ( mom.perp() > ptMin[0] && mom.rho() > pMin[0] && mom.eta() > etaMin[0]
132  && mom.eta() < etaMax[0] && ((*p)->status() == status[0] || status[0] == 0)) {
133  // passed A type conditions ...
134  // ... now check pair-conditions with B type passed particles
135  unsigned int i=0;
136  double deltaphi;
137  double phi1 = mom.phi();
138  double phi2;
139  double deltaeta;
140  double eta1 = mom.eta();
141  double eta2;
142  double deltaR;
143 
144  double tot_x= 0.;
145  double tot_y= 0.;
146  double tot_z= 0.;
147  double tot_e= 0.;
148  double invmass =0.;
149  int charge1 = 0;
150  int combcharge = 0;
151  while(!accepted && i<typeBpassed.size()) {
152  tot_x=mom.px();
153  tot_y=mom.py();
154  tot_z=mom.pz();
155  tot_e=mom.e();
156  charge1 = charge((*p)->pdg_id());
157  HepMC::FourVector mom_i = MCFilterZboostHelper::zboost(typeBpassed[i]->momentum(),betaBoost);
158  tot_x += mom_i.px();
159  tot_y += mom_i.py();
160  tot_z += mom_i.pz();
161  tot_e += mom_i.e();
162  invmass=sqrt(tot_e*tot_e-tot_x*tot_x-tot_y*tot_y-tot_z*tot_z);
163  combcharge = charge1 * charge(typeBpassed[i]->pdg_id());
164  if(invmass > minInvMass && invmass < maxInvMass) {
165  phi2 = mom_i.phi();
166  deltaphi = fabs(phi1-phi2);
167  if(deltaphi > pi) deltaphi = 2.*pi-deltaphi;
168  if(deltaphi > minDeltaPhi && deltaphi < maxDeltaPhi) {
169  eta2 = mom_i.eta();
170  deltaeta=fabs(eta1-eta2);
171  deltaR = sqrt(deltaeta*deltaeta+deltaphi*deltaphi);
172  if(deltaR > minDeltaR && deltaR < maxDeltaR) {
173  if(combcharge*particleCharge>=0) {
174  accepted = true;
175  }
176  }
177  }
178  }
179  i++;
180  }
181  // if we found a matching pair quit the loop
182  if(accepted) break;
183  else{
184  typeApassed.push_back(*p); // else remember the particle to have passed type A conditions
185  }
186  }
187  }
188 
189  // check for type B conditions
190 
191  bool gottypeBID = false;
192  for(unsigned int j=0; j<particleID2.size(); ++j) {
193  if(abs((*p)->pdg_id()) == abs(particleID2[j]) || particleID2[j] == 0) {
194  gottypeBID = true;
195  break;
196  }
197  }
198  if(gottypeBID) {
199  HepMC::FourVector mom = MCFilterZboostHelper::zboost((*p)->momentum(),betaBoost);
200  if ( mom.perp() > ptMin[1] && mom.rho() > pMin[1] && mom.eta() > etaMin[1]
201  && mom.eta() < etaMax[1] && ((*p)->status() == status[1] || status[1] == 0)) {
202  // passed B type conditions ...
203  // ... now check pair-conditions with A type passed particles vector
204  unsigned int i=0;
205  double deltaphi;
206  double phi1 = mom.phi();
207  double phi2;
208  double deltaeta;
209  double eta1 = mom.eta();
210  double eta2;
211  double deltaR;
212 
213  double tot_x= 0.;
214  double tot_y= 0.;
215  double tot_z= 0.;
216  double tot_e= 0.;
217  double invmass =0.;
218  int charge1 = 0;
219  int combcharge = 0;
220  while(!accepted && i<typeApassed.size()) {
221  if((*p) != typeApassed[i]) {
222  tot_x=mom.px();
223  tot_y=mom.py();
224  tot_z=mom.pz();
225  tot_e=mom.e();
226  charge1 = charge((*p)->pdg_id());
227  HepMC::FourVector mom_i = MCFilterZboostHelper::zboost(typeApassed[i]->momentum(),betaBoost);
228  tot_x += mom_i.px();
229  tot_y += mom_i.py();
230  tot_z += mom_i.pz();
231  tot_e += mom_i.e();
232  invmass=sqrt(tot_e*tot_e-tot_x*tot_x-tot_y*tot_y-tot_z*tot_z);
233  combcharge = charge1 * charge(typeApassed[i]->pdg_id());
234  if(invmass > minInvMass && invmass < maxInvMass) {
235  phi2 = mom_i.phi();
236  deltaphi = fabs(phi1-phi2);
237  if(deltaphi > pi) deltaphi = 2.*pi-deltaphi;
238  if(deltaphi > minDeltaPhi && deltaphi < maxDeltaPhi) {
239  eta2 = mom_i.eta();
240  deltaeta=fabs(eta1-eta2);
241  deltaR = sqrt(deltaeta*deltaeta+deltaphi*deltaphi);
242  if(deltaR > minDeltaR && deltaR < maxDeltaR) {
243  if(combcharge*particleCharge>=0) {
244  accepted = true;
245  }
246  }
247  }
248  }
249  }
250  i++;
251  }
252  // if we found a matching pair quit the loop
253  if(accepted) break;
254  else {
255  typeBpassed.push_back(*p); // else remember the particle to have passed type B conditions
256  }
257  }
258  }
259  }
260 
261  if (accepted){ return true; } else {return false;}
262 
263 }
HepMC::FourVector zboost(const HepMC::FourVector &, double)
std::vector< double > ptMin
std::vector< double > pMin
std::vector< double > etaMin
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::vector< int > particleID1
std::vector< double > etaMax
std::vector< int > particleID2
const Double_t pi
T sqrt(T t)
Definition: SSEVec.h:18
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const edm::EDGetTokenT< edm::HepMCProduct > token_
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
bool accepted(std::vector< std::string_view > const &, std::string_view)
HLT enums.
std::vector< int > status
int charge(int Id) const

Member Data Documentation

const double MCParticlePairFilter::betaBoost
private

Definition at line 70 of file MCParticlePairFilter.h.

Referenced by filter().

std::vector<double> MCParticlePairFilter::etaMax
private

Definition at line 61 of file MCParticlePairFilter.h.

Referenced by filter(), and MCParticlePairFilter().

std::vector<double> MCParticlePairFilter::etaMin
private

Definition at line 60 of file MCParticlePairFilter.h.

Referenced by filter(), and MCParticlePairFilter().

const double MCParticlePairFilter::maxDeltaPhi
private

Definition at line 67 of file MCParticlePairFilter.h.

Referenced by filter().

const double MCParticlePairFilter::maxDeltaR
private

Definition at line 69 of file MCParticlePairFilter.h.

Referenced by filter().

const double MCParticlePairFilter::maxInvMass
private

Definition at line 65 of file MCParticlePairFilter.h.

Referenced by filter().

const double MCParticlePairFilter::minDeltaPhi
private

Definition at line 66 of file MCParticlePairFilter.h.

Referenced by filter().

const double MCParticlePairFilter::minDeltaR
private

Definition at line 68 of file MCParticlePairFilter.h.

Referenced by filter().

const double MCParticlePairFilter::minInvMass
private

Definition at line 64 of file MCParticlePairFilter.h.

Referenced by filter().

const int MCParticlePairFilter::particleCharge
private

Definition at line 63 of file MCParticlePairFilter.h.

Referenced by filter().

std::vector<int> MCParticlePairFilter::particleID1
private

Definition at line 56 of file MCParticlePairFilter.h.

Referenced by filter(), and MCParticlePairFilter().

std::vector<int> MCParticlePairFilter::particleID2
private

Definition at line 57 of file MCParticlePairFilter.h.

Referenced by filter(), and MCParticlePairFilter().

std::vector<double> MCParticlePairFilter::pMin
private

Definition at line 59 of file MCParticlePairFilter.h.

Referenced by filter(), and MCParticlePairFilter().

std::vector<double> MCParticlePairFilter::ptMin
private

Definition at line 58 of file MCParticlePairFilter.h.

Referenced by filter(), and MCParticlePairFilter().

std::vector<int> MCParticlePairFilter::status
private
const edm::EDGetTokenT<edm::HepMCProduct> MCParticlePairFilter::token_
private

Definition at line 55 of file MCParticlePairFilter.h.

Referenced by filter().