CMS 3D CMS Logo

MCSmartSingleParticleFilter.cc
Go to the documentation of this file.
1 
4 
6 #include <iostream>
7 
8 using namespace edm;
9 using namespace std;
10 
11 
13 token_(consumes<edm::HepMCProduct>(edm::InputTag(iConfig.getUntrackedParameter("moduleLabel",std::string("generator")),"unsmeared"))),
14 betaBoost(iConfig.getUntrackedParameter("BetaBoost",0.))
15 {
16  //here do whatever other initialization is needed
17  vector<int> defpid ;
18  defpid.push_back(0) ;
19  particleID = iConfig.getUntrackedParameter< vector<int> >("ParticleID",defpid);
20  vector<double> defpmin ;
21  defpmin.push_back(0.);
22  pMin = iConfig.getUntrackedParameter< vector<double> >("MinP", defpmin);
23 
24  vector<double> defptmin ;
25  defptmin.push_back(0.);
26  ptMin = iConfig.getUntrackedParameter< vector<double> >("MinPt", defptmin);
27 
28  vector<double> defetamin ;
29  defetamin.push_back(-10.);
30  etaMin = iConfig.getUntrackedParameter< vector<double> >("MinEta", defetamin);
31  vector<double> defetamax ;
32  defetamax.push_back(10.);
33  etaMax = iConfig.getUntrackedParameter< vector<double> >("MaxEta", defetamax);
34  vector<int> defstat ;
35  defstat.push_back(0);
36  status = iConfig.getUntrackedParameter< vector<int> >("Status", defstat);
37 
38  vector<double> defDecayRadiusmin;
39  defDecayRadiusmin.push_back(-1.);
40  decayRadiusMin = iConfig.getUntrackedParameter< vector<double> >("MinDecayRadius", defDecayRadiusmin);
41 
42  vector<double> defDecayRadiusmax;
43  defDecayRadiusmax.push_back(1.e5);
44  decayRadiusMax = iConfig.getUntrackedParameter< vector<double> >("MaxDecayRadius", defDecayRadiusmax);
45 
46  vector<double> defDecayZmin;
47  defDecayZmin.push_back(-1.e5);
48  decayZMin = iConfig.getUntrackedParameter< vector<double> >("MinDecayZ", defDecayZmin);
49 
50  vector<double> defDecayZmax;
51  defDecayZmax.push_back(1.e5);
52  decayZMax = iConfig.getUntrackedParameter< vector<double> >("MaxDecayZ", defDecayZmax);
53 
54  // check for same size
55  if ( (pMin.size() > 1 && particleID.size() != pMin.size())
56  || (ptMin.size() > 1 && particleID.size() != ptMin.size())
57  || (etaMin.size() > 1 && particleID.size() != etaMin.size())
58  || (etaMax.size() > 1 && particleID.size() != etaMax.size())
59  || (status.size() > 1 && particleID.size() != status.size())
60  || (decayRadiusMin.size() > 1 && particleID.size() != decayRadiusMin.size())
61  || (decayRadiusMax.size() > 1 && particleID.size() != decayRadiusMax.size())
62  || (decayZMin.size() > 1 && particleID.size() != decayZMin.size())
63  || (decayZMax.size() > 1 && particleID.size() != decayZMax.size()) ) {
64  cout << "WARNING: MCPROCESSFILTER : size of MinPthat and/or MaxPthat not matching with ProcessID size!!" << endl;
65  }
66 
67  // if pMin size smaller than particleID , fill up further with defaults
68  if (particleID.size() > pMin.size() ){
69  for (unsigned int i = pMin.size(); i < particleID.size(); i++){ pMin.push_back(0.);}
70  }
71  // if ptMin size smaller than particleID , fill up further with defaults
72  if (particleID.size() > ptMin.size() ){
73  for (unsigned int i = ptMin.size(); i < particleID.size(); i++){ ptMin.push_back(0.);}
74  }
75  // if etaMin size smaller than particleID , fill up further with defaults
76  if (particleID.size() > etaMin.size() ){
77  for (unsigned int i = etaMin.size(); i < particleID.size(); i++){ etaMin.push_back(-10.);}
78  }
79  // if etaMax size smaller than particleID , fill up further with defaults
80  if (particleID.size() > etaMax.size() ){
81  for (unsigned int i = etaMax.size(); i < particleID.size(); i++){ etaMax.push_back(10.);}
82  }
83  // if status size smaller than particleID , fill up further with defaults
84  if (particleID.size() > status.size() ){
85  for (unsigned int i = status.size(); i < particleID.size(); i++){ status.push_back(0);}
86  }
87 
88  // if decayRadiusMin size smaller than particleID , fill up further with defaults
89  if (particleID.size() > decayRadiusMin.size() ){
90  for (unsigned int i = decayRadiusMin.size(); i < particleID.size(); i++){ decayRadiusMin.push_back(-10.);}
91  }
92  // if decayRadiusMax size smaller than particleID , fill up further with defaults
93  if (particleID.size() > decayRadiusMax.size() ){
94  for (unsigned int i = decayRadiusMax.size(); i < particleID.size(); i++){ decayRadiusMax.push_back(1.e5);}
95  }
96 
97  // if decayZMin size smaller than particleID , fill up further with defaults
98  if (particleID.size() > decayZMin.size() ){
99  for (unsigned int i = decayZMin.size(); i < particleID.size(); i++){ decayZMin.push_back(-1.e5);}
100  }
101  // if decayZMax size smaller than particleID , fill up further with defaults
102  if (particleID.size() > decayZMax.size() ){
103  for (unsigned int i = decayZMax.size(); i < particleID.size(); i++){ decayZMax.push_back(1.e5);}
104  }
105 
106  // check if beta is smaller than 1
107  if (std::abs(betaBoost) >= 1 ){
108  edm::LogError("MCSmartSingleParticleFilter") << "Input beta boost is >= 1 !";
109  }
110 
111 }
112 
113 
115 {
116 
117  // do anything here that needs to be done at desctruction time
118  // (e.g. close files, deallocate resources etc.)
119 
120 }
121 
122 
123 // ------------ method called to skim the data ------------
125 {
126  using namespace edm;
127  bool accepted = false;
129  iEvent.getByToken(token_, evt);
130 
131  const HepMC::GenEvent * myGenEvent = evt->GetEvent();
132 
133 
134  for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();
135  p != myGenEvent->particles_end(); ++p ) {
136 
137 
138  for (unsigned int i = 0; i < particleID.size(); i++){
139  if (particleID[i] == (*p)->pdg_id() || particleID[i] == 0) {
140 
141  if ( (*p)->momentum().perp() > ptMin[i]
142  && ((*p)->status() == status[i] || status[i] == 0)) {
143 
144  HepMC::FourVector mom = MCFilterZboostHelper::zboost((*p)->momentum(),betaBoost);
145  if ( mom.rho() > pMin[i]
146  && mom.eta() > etaMin[i] && mom.eta() < etaMax[i]) {
147 
148  if (!((*p)->production_vertex())) continue;
149 
150  double decx = (*p)->production_vertex()->position().x();
151  double decy = (*p)->production_vertex()->position().y();
152  double decrad = sqrt(decx*decx+decy*decy);
153  if (decrad<decayRadiusMin[i] ) continue;
154  if (decrad>decayRadiusMax[i] ) continue;
155 
156  double decz = (*p)->production_vertex()->position().z();
157  if (decz<decayZMin[i] ) continue;
158  if (decz>decayZMax[i] ) continue;
159 
160  accepted = true;
161  }
162 
163  }
164 
165  }
166  }
167 
168 
169  }
170 
171  if (accepted){ return true; } else {return false;}
172 
173 }
HepMC::FourVector zboost(const HepMC::FourVector &, double)
T getUntrackedParameter(std::string const &, T const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
bool filter(edm::Event &, const edm::EventSetup &) override
MCSmartSingleParticleFilter(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
T sqrt(T t)
Definition: SSEVec.h:18
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
edm::EDGetTokenT< edm::HepMCProduct > token_
bool accepted(std::vector< std::string_view > const &, std::string_view)
HLT enums.