CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MCSingleParticleFilter.cc
Go to the documentation of this file.
1 
3 
5 #include <iostream>
6 
7 using namespace edm;
8 using namespace std;
9 
10 
12 token_(consumes<edm::HepMCProduct>(edm::InputTag(iConfig.getUntrackedParameter("moduleLabel",std::string("generator")),"unsmeared")))
13 {
14  //here do whatever other initialization is needed
15  vector<int> defpid ;
16  defpid.push_back(0) ;
17  particleID = iConfig.getUntrackedParameter< vector<int> >("ParticleID",defpid);
18  vector<double> defptmin ;
19  defptmin.push_back(0.);
20  ptMin = iConfig.getUntrackedParameter< vector<double> >("MinPt", defptmin);
21 
22  vector<double> defetamin ;
23  defetamin.push_back(-10.);
24  etaMin = iConfig.getUntrackedParameter< vector<double> >("MinEta", defetamin);
25  vector<double> defetamax ;
26  defetamax.push_back(10.);
27  etaMax = iConfig.getUntrackedParameter< vector<double> >("MaxEta", defetamax);
28  vector<int> defstat ;
29  defstat.push_back(0);
30  status = iConfig.getUntrackedParameter< vector<int> >("Status", defstat);
31 
32 
33  // check for same size
34  if ( (ptMin.size() > 1 && particleID.size() != ptMin.size())
35  || (etaMin.size() > 1 && particleID.size() != etaMin.size())
36  || (etaMax.size() > 1 && particleID.size() != etaMax.size())
37  || (status.size() > 1 && particleID.size() != status.size()) ) {
38  cout << "WARNING: MCPROCESSFILTER : size of MinPthat and/or MaxPthat not matching with ProcessID size!!" << endl;
39  }
40 
41  // if ptMin size smaller than particleID , fill up further with defaults
42  if (particleID.size() > ptMin.size() ){
43  vector<double> defptmin2 ;
44  for (unsigned int i = 0; i < particleID.size(); i++){ defptmin2.push_back(0.);}
45  ptMin = defptmin2;
46  }
47  // if etaMin size smaller than particleID , fill up further with defaults
48  if (particleID.size() > etaMin.size() ){
49  vector<double> defetamin2 ;
50  for (unsigned int i = 0; i < particleID.size(); i++){ defetamin2.push_back(-10.);}
51  etaMin = defetamin2;
52  }
53  // if etaMax size smaller than particleID , fill up further with defaults
54  if (particleID.size() > etaMax.size() ){
55  vector<double> defetamax2 ;
56  for (unsigned int i = 0; i < particleID.size(); i++){ defetamax2.push_back(10.);}
57  etaMax = defetamax2;
58  }
59  // if status size smaller than particleID , fill up further with defaults
60  if (particleID.size() > status.size() ){
61  vector<int> defstat2 ;
62  for (unsigned int i = 0; i < particleID.size(); i++){ defstat2.push_back(0);}
63  status = defstat2;
64  }
65 
66 
67 
68 }
69 
70 
72 {
73 
74  // do anything here that needs to be done at desctruction time
75  // (e.g. close files, deallocate resources etc.)
76 
77 }
78 
79 
80 // ------------ method called to skim the data ------------
82 {
83  using namespace edm;
84  bool accepted = false;
86  iEvent.getByToken(token_, evt);
87 
88  const HepMC::GenEvent * myGenEvent = evt->GetEvent();
89 
90 
91  for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();
92  p != myGenEvent->particles_end(); ++p ) {
93 
94 
95  for (unsigned int i = 0; i < particleID.size(); i++){
96  if (particleID[i] == (*p)->pdg_id() || particleID[i] == 0) {
97 
98  if ( (*p)->momentum().perp() > ptMin[i] && (*p)->momentum().eta() > etaMin[i]
99  && (*p)->momentum().eta() < etaMax[i] && ((*p)->status() == status[i] || status[i] == 0)) {
100  accepted = true;
101  }
102 
103  }
104  }
105 
106 
107  }
108 
109  if (accepted){ return true; } else {return false;}
110 
111 }
112 
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< double > ptMin
edm::EDGetTokenT< edm::HepMCProduct > token_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
std::vector< double > etaMin
int iEvent
Definition: GenABIO.cc:230
virtual bool filter(edm::Event &, const edm::EventSetup &)
std::vector< double > etaMax
std::vector< int > particleID
MCSingleParticleFilter(const edm::ParameterSet &)
tuple cout
Definition: gather_cfg.py:121