CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MCParticlePairFilter.cc
Go to the documentation of this file.
1 
2 //-ap #include "Configuration/CSA06Skimming/interface/MCParticlePairFilter.h"
3 
5 
7 #include <iostream>
8 
9 using namespace edm;
10 using namespace std;
11 
12 
14 label_(iConfig.getUntrackedParameter("moduleLabel",std::string("generator"))),
15 particleCharge(iConfig.getUntrackedParameter("ParticleCharge",0)),
16 minInvMass(iConfig.getUntrackedParameter("MinInvMass", 0.)),
17 maxInvMass(iConfig.getUntrackedParameter("MaxInvMass", 14000.)),
18 minDeltaPhi(iConfig.getUntrackedParameter("MinDeltaPhi", 0.)),
19 maxDeltaPhi(iConfig.getUntrackedParameter("MaxDeltaPhi", 6.3)),
20 minDeltaR(iConfig.getUntrackedParameter("MinDeltaR",0.)),
21 maxDeltaR(iConfig.getUntrackedParameter("MaxDeltaR",10000.))
22 {
23  //here do whatever other initialization is needed
24  vector<int> defpid1;
25  defpid1.push_back(0);
26  particleID1 = iConfig.getUntrackedParameter< vector<int> >("ParticleID1",defpid1);
27  vector<int> defpid2;
28  defpid2.push_back(0);
29  particleID2 = iConfig.getUntrackedParameter< vector<int> >("ParticleID2",defpid2);
30  vector<double> defptmin;
31  defptmin.push_back(0.);
32  ptMin = iConfig.getUntrackedParameter< vector<double> >("MinPt", defptmin);
33  vector<double> defpmin;
34  defpmin.push_back(0.);
35  pMin = iConfig.getUntrackedParameter< vector<double> >("MinP", defpmin);
36 
37  vector<double> defetamin;
38  defetamin.push_back(-10.);
39  etaMin = iConfig.getUntrackedParameter< vector<double> >("MinEta", defetamin);
40  vector<double> defetamax ;
41  defetamax.push_back(10.);
42  etaMax = iConfig.getUntrackedParameter< vector<double> >("MaxEta", defetamax);
43  vector<int> defstat ;
44  defstat.push_back(0);
45  status = iConfig.getUntrackedParameter< vector<int> >("Status", defstat);
46 
47 
48  // check for correct size
49  if (ptMin.size() != 2
50  || pMin.size() != 2
51  || etaMin.size() != 2
52  || etaMax.size() != 2
53  || status.size() != 2 ) {
54  cout << "WARNING: MCParticlePairFilter : size of some vectors not matching with 2!!" << endl;
55  }
56 
57  // if ptMin size smaller than 2, fill up further with defaults
58  if (2 > ptMin.size() ){
59  vector<double> defptmin2 ;
60  for (unsigned int i = 0; i < 2; i++){ defptmin2.push_back(0.);}
61  ptMin = defptmin2;
62  }
63  // if pMin size smaller than 2, fill up further with defaults
64  if (2 > pMin.size() ){
65  vector<double> defpmin2 ;
66  for (unsigned int i = 0; i < 2; i++){ defpmin2.push_back(0.);}
67  pMin = defpmin2;
68  }
69  // if etaMin size smaller than 2, fill up further with defaults
70  if (2 > etaMin.size() ){
71  vector<double> defetamin2 ;
72  for (unsigned int i = 0; i < 2; i++){ defetamin2.push_back(-10.);}
73  etaMin = defetamin2;
74  }
75  // if etaMax size smaller than 2, fill up further with defaults
76  if (2 > etaMax.size() ){
77  vector<double> defetamax2 ;
78  for (unsigned int i = 0; i < 2; i++){ defetamax2.push_back(10.);}
79  etaMax = defetamax2;
80  }
81  // if status size smaller than 2, fill up further with defaults
82  if (2 > status.size() ){
83  vector<int> defstat2 ;
84  for (unsigned int i = 0; i < 2; i++){ defstat2.push_back(0);}
85  status = defstat2;
86  }
87 
88 }
89 
90 
92 {
93 
94  // do anything here that needs to be done at desctruction time
95  // (e.g. close files, deallocate resources etc.)
96 
97 }
98 
99 
100 // ------------ method called to skim the data ------------
102 {
103  using namespace edm;
104  bool accepted = false;
106  iEvent.getByLabel(label_, evt);
107  const double pi = 3.14159;
108 
109  vector<HepMC::GenParticle*> typeApassed;
110  vector<HepMC::GenParticle*> typeBpassed;
111 
112 
113  const HepMC::GenEvent * myGenEvent = evt->GetEvent();
114 
115 
116  for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();
117  p != myGenEvent->particles_end(); ++p ) {
118 
119  // check for type A conditions
120  bool gottypeAID = false;
121  for(unsigned int j=0; j<particleID1.size(); ++j) {
122  if(abs((*p)->pdg_id()) == abs(particleID1[j]) || particleID1[j] == 0) {
123  gottypeAID = true;
124  break;
125  }
126  }
127  if(gottypeAID) {
128  if ( (*p)->momentum().perp() > ptMin[0] && (*p)->momentum().rho() > pMin[0] && (*p)->momentum().eta() > etaMin[0]
129  && (*p)->momentum().eta() < etaMax[0] && ((*p)->status() == status[0] || status[0] == 0)) {
130  // passed A type conditions ...
131  // ... now check pair-conditions with B type passed particles
132  unsigned int i=0;
133  double deltaphi;
134  double phi1 = (*p)->momentum().phi();
135  double phi2;
136  double deltaeta;
137  double eta1 = (*p)->momentum().eta();
138  double eta2;
139  double deltaR;
140  //HepLorentzVector momentum1 = (*p)->momentum();
141  //HepLorentzVector totmomentum;
142  double tot_x= 0.;
143  double tot_y= 0.;
144  double tot_z= 0.;
145  double tot_e= 0.;
146  double invmass =0.;
147  int charge1 = 0;
148  int combcharge = 0;
149  while(!accepted && i<typeBpassed.size()) {
150  tot_x=(*p)->momentum().px();
151  tot_y=(*p)->momentum().py();
152  tot_z=(*p)->momentum().pz();
153  tot_e=(*p)->momentum().e();
154  charge1 = charge((*p)->pdg_id());
155  //totmomentum = momentum1 + typeBpassed[i]->momentum();
156  //invmass = totmomentum.m();
157  tot_x += typeBpassed[i]->momentum().px();
158  tot_y += typeBpassed[i]->momentum().py();
159  tot_z += typeBpassed[i]->momentum().pz();
160  tot_e += typeBpassed[i]->momentum().e();
161  invmass=sqrt(tot_e*tot_e-tot_x*tot_x-tot_y*tot_y-tot_z*tot_z);
162  combcharge = charge1 * charge(typeBpassed[i]->pdg_id());
163  if(invmass > minInvMass && invmass < maxInvMass) {
164  phi2 = typeBpassed[i]->momentum().phi();
165  deltaphi = fabs(phi1-phi2);
166  if(deltaphi > pi) deltaphi = 2.*pi-deltaphi;
167  if(deltaphi > minDeltaPhi && deltaphi < maxDeltaPhi) {
168  eta2 = typeBpassed[i]->momentum().eta();
169  deltaeta=fabs(eta1-eta2);
170  deltaR = sqrt(deltaeta*deltaeta+deltaphi*deltaphi);
171  if(deltaR > minDeltaR && deltaR < maxDeltaR) {
172  if(combcharge*particleCharge>=0) {
173  accepted = true;
174  }
175  }
176  }
177  }
178  i++;
179  }
180  // if we found a matching pair quit the loop
181  if(accepted) break;
182  else{
183  typeApassed.push_back(*p); // else remember the particle to have passed type A conditions
184  }
185  }
186  }
187 
188  // check for type B conditions
189 
190  bool gottypeBID = false;
191  for(unsigned int j=0; j<particleID2.size(); ++j) {
192  if(abs((*p)->pdg_id()) == abs(particleID2[j]) || particleID2[j] == 0) {
193  gottypeBID = true;
194  break;
195  }
196  }
197  if(gottypeBID) {
198  if ( (*p)->momentum().perp() > ptMin[1] && (*p)->momentum().rho() > pMin[1] && (*p)->momentum().eta() > etaMin[1]
199  && (*p)->momentum().eta() < etaMax[1] && ((*p)->status() == status[1] || status[1] == 0)) {
200  // passed B type conditions ...
201  // ... now check pair-conditions with A type passed particles vector
202  unsigned int i=0;
203  double deltaphi;
204  double phi1 = (*p)->momentum().phi();
205  double phi2;
206  double deltaeta;
207  double eta1 = (*p)->momentum().eta();
208  double eta2;
209  double deltaR;
210  //HepLorentzVector momentum1 = (*p)->momentum();
211  //HepLorentzVector totmomentum;
212  double tot_x= 0.;
213  double tot_y= 0.;
214  double tot_z= 0.;
215  double tot_e= 0.;
216  double invmass =0.;
217  int charge1 = 0;
218  int combcharge = 0;
219  while(!accepted && i<typeApassed.size()) {
220  if((*p) != typeApassed[i]) {
221  tot_x=(*p)->momentum().px();
222  tot_y=(*p)->momentum().py();
223  tot_z=(*p)->momentum().pz();
224  tot_e=(*p)->momentum().e();
225  charge1 = charge((*p)->pdg_id());
226  //totmomentum = momentum1 + typeApassed[i]->momentum();
227  //invmass = totmomentum.m();
228  tot_x += typeApassed[i]->momentum().px();
229  tot_y += typeApassed[i]->momentum().py();
230  tot_z += typeApassed[i]->momentum().pz();
231  tot_e += typeApassed[i]->momentum().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 = typeApassed[i]->momentum().phi();
236  deltaphi = fabs(phi1-phi2);
237  if(deltaphi > pi) deltaphi = 2.*pi-deltaphi;
238  if(deltaphi > minDeltaPhi && deltaphi < maxDeltaPhi) {
239  eta2 = typeApassed[i]->momentum().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(const int& Id){
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  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 }
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< double > ptMin
std::vector< double > pMin
std::vector< double > etaMin
virtual bool filter(edm::Event &, const edm::EventSetup &)
MCParticlePairFilter(const edm::ParameterSet &)
#define abs(x)
Definition: mlp_lapack.h:159
std::vector< int > particleID1
std::vector< double > etaMax
std::vector< int > particleID2
const Double_t pi
int iEvent
Definition: GenABIO.cc:243
T sqrt(T t)
Definition: SSEVec.h:46
int j
Definition: DBlmapReader.cc:9
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
int charge(const int &Id)
std::vector< int > status
tuple cout
Definition: gather_cfg.py:121