CMS 3D CMS Logo

MCParticlePairFilter.cc
Go to the documentation of this file.
1 
2 //-ap #include "Configuration/CSA06Skimming/interface/MCParticlePairFilter.h"
3 
6 
8 #include <iostream>
9 
10 using namespace edm;
11 using namespace std;
12 
13 
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 }
91 
92 
94 {
95 
96  // do anything here that needs to be done at desctruction time
97  // (e.g. close files, deallocate resources etc.)
98 
99 }
100 
101 
102 // ------------ method called to skim the data ------------
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 }
264 
265 int MCParticlePairFilter::charge(int Id) const {
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 }
HepMC::FourVector zboost(const HepMC::FourVector &, double)
T getUntrackedParameter(std::string const &, T const &) const
std::vector< double > ptMin
std::vector< double > pMin
std::vector< double > etaMin
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
MCParticlePairFilter(const edm::ParameterSet &)
bool filter(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
std::vector< int > particleID1
std::vector< double > etaMax
std::vector< int > particleID2
const Double_t pi
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 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
#define constexpr