CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PythiaFilterIsolatedTrack.cc
Go to the documentation of this file.
6 #include <iostream>
7 #include<list>
8 #include<vector>
9 #include<cmath>
10 
11 //using namespace edm;
12 //using namespace std;
13 
14 std::pair<double,double> PythiaFilterIsolatedTrack::GetEtaPhiAtEcal(double etaIP, double phiIP, double pT, int charge, double vtxZ)
15 {
16  double deltaPhi;
17  double etaEC=100;
18  double phiEC=100;
19  double Rcurv=pT*33.3*100/38; //r(m)=pT(GeV)*33.3/B(kG)
20  double ecDist=317; //distance to ECAL andcap from IP (cm), 317 - ecal (not preshower), preshower -300
21  double ecRad=129; //radius of ECAL barrel (cm)
22  double theta=2*atan(exp(-etaIP));
23  double zNew;
24  if (theta>0.5*acos(-1)) theta=acos(-1)-theta;
25  if (fabs(etaIP)<1.479) {
26  deltaPhi=-charge*asin(0.5*ecRad/Rcurv);
27  double alpha1=2*asin(0.5*ecRad/Rcurv);
28  double z=ecRad/tan(theta);
29  if (etaIP>0) zNew=z*(Rcurv*alpha1)/ecRad+vtxZ; //new z-coordinate of track
30  else zNew=-z*(Rcurv*alpha1)/ecRad+vtxZ; //new z-coordinate of track
31  double zAbs=fabs(zNew);
32  if (zAbs<ecDist) {
33  etaEC=-log(tan(0.5*atan(ecRad/zAbs)));
34  deltaPhi=-charge*asin(0.5*ecRad/Rcurv);
35  }
36  if (zAbs>ecDist) {
37  zAbs=(fabs(etaIP)/etaIP)*ecDist;
38  double Zflight=fabs(zAbs-vtxZ);
39  double alpha=(Zflight*ecRad)/(z*Rcurv);
40  double Rec=2*Rcurv*sin(alpha/2);
41  deltaPhi=-charge*alpha/2;
42  etaEC=-log(tan(0.5*atan(Rec/ecDist)));
43  }
44  } else {
45  zNew=(fabs(etaIP)/etaIP)*ecDist;
46  double Zflight=fabs(zNew-vtxZ);
47  double Rvirt=fabs(Zflight*tan(theta));
48  double Rec=2*Rcurv*sin(Rvirt/(2*Rcurv));
49  deltaPhi=-(charge)*(Rvirt/(2*Rcurv));
50  etaEC=-log(tan(0.5*atan(Rec/ecDist)));
51  }
52 
53  if (zNew<0) etaEC=-etaEC;
54  phiEC=phiIP+deltaPhi;
55 
56  if (phiEC<-acos(-1)) phiEC=2*acos(-1)+phiEC;
57  if (phiEC>acos(-1)) phiEC=-2*acos(-1)+phiEC;
58 
59  std::pair<double,double> retVal(etaEC,phiEC);
60  return retVal;
61 }
62 
63 double PythiaFilterIsolatedTrack::getDistInCM(double eta1, double phi1, double eta2, double phi2)
64 {
65  double dR, Rec;
66  if (fabs(eta1)<1.479) Rec=129;
67  else Rec=317;
68  double ce1=cosh(eta1);
69  double ce2=cosh(eta2);
70  double te1=tanh(eta1);
71  double te2=tanh(eta2);
72 
73  double z=cos(phi1-phi2)/ce1/ce2+te1*te2;
74  if(z!=0) dR=fabs(Rec*ce1*sqrt(1./z/z-1.));
75  else dR=999999.;
76  return dR;
77 }
78 
80  ModuleLabel_(iConfig.getUntrackedParameter("ModuleLabel",std::string("generator"))),
81  MaxSeedEta_(iConfig.getUntrackedParameter<double>("MaxSeedEta", 2.3)),
82  MinSeedMom_(iConfig.getUntrackedParameter<double>("MinSeedMom", 20.)),
83  MinIsolTrackMom_(iConfig.getUntrackedParameter<double>("MinIsolTrackMom",2.0)),
84  IsolCone_(iConfig.getUntrackedParameter<double>("IsolCone", 40.0)),
85  PixelEfficiency_(iConfig.getUntrackedParameter<double>("PixelEfficiency", 0.8))
86 {
87 
88  // initialize the random number generator service
89  if(!rng_.isAvailable()) {
90  throw cms::Exception("Configuration") << "PythiaFilterIsolatedTrack requires the RandomNumberGeneratorService\n";
91  }
92  CLHEP::HepRandomEngine& engine = rng_->getEngine();
93  flatDistribution_ = new CLHEP::RandFlat(engine, 0.0, 1.0);
94 }
95 
96 
98 {
99  delete flatDistribution_;
100 }
101 
102 
103 // ------------ method called to produce the data ------------
105 
107  iSetup.getData( pdt );
108 
110  iEvent.getByLabel(ModuleLabel_, evt);
111 
112  const HepMC::GenEvent* myGenEvent = evt->GetEvent();
113 
114  // all of the stable, charged particles with momentum>MinIsolTrackMom_ and |eta|<MaxSeedEta_+0.5
115  std::vector<const HepMC::GenParticle *> chargedParticles;
116 
117  // all of the stable, charged particles with momentum>MinSeedMom_ and |eta|<MaxSeedEta_
118  std::vector<const HepMC::GenParticle *> seeds;
119 
120  // fill the vector of charged particles and seeds in the event
121  for(HepMC::GenEvent::particle_const_iterator iter=myGenEvent->particles_begin(); iter!=myGenEvent->particles_end(); ++iter) {
122  const HepMC::GenParticle *p=*iter;
123  int charge3 = pdt->particle(p->pdg_id())->ID().threeCharge();
124  int status = p->status();
125  double momentum = p->momentum().rho();
126  double abseta = fabs(p->momentum().eta());
127 
128  // only consider stable, charged particles
129  if(abs(charge3)==3 && status==1 && momentum>MinIsolTrackMom_ && abseta<MaxSeedEta_+0.5) {
130  chargedParticles.push_back(p);
131  if(momentum>MinSeedMom_ && abseta<MaxSeedEta_) {
132  seeds.push_back(p);
133  }
134  }
135  }
136 
137  // loop over all the seeds and see if any of them are isolated
138  for(std::vector<const HepMC::GenParticle *>::const_iterator it1=seeds.begin(); it1!=seeds.end(); ++it1) {
139  const HepMC::GenParticle *p1=*it1;
140 
141  std::pair<double,double> EtaPhi1=GetEtaPhiAtEcal(p1->momentum().eta(),
142  p1->momentum().phi(),
143  p1->momentum().perp(),
144  (pdt->particle(p1->pdg_id()))->ID().threeCharge()/3,
145  0.0);
146 
147  // loop over all of the other charged particles in the event, and see if any are close by
148  bool failsIso=false;
149  for(std::vector<const HepMC::GenParticle *>::const_iterator it2=chargedParticles.begin(); it2!=chargedParticles.end(); ++it2) {
150  const HepMC::GenParticle *p2=*it2;
151 
152  // don't consider the seed particle among the other charge particles
153  if(p1==p2) continue;
154 
155  std::pair<double,double> EtaPhi2=GetEtaPhiAtEcal(p2->momentum().eta(),
156  p2->momentum().phi(),
157  p2->momentum().perp(),
158  (pdt->particle(p2->pdg_id()))->ID().threeCharge()/3,
159  0.0);
160 
161  // find out how far apart the particles are
162  // if the seed fails the isolation requirement, try a different seed
163  // occasionally allow a seed to pass to isolation requirement
164  if(getDistInCM(EtaPhi1.first, EtaPhi1.second, EtaPhi2.first, EtaPhi2.second) < IsolCone_ &&
166  failsIso=true;
167  break;
168  }
169  }
170 
171  if(!failsIso) return true;
172 
173  } //loop over seeds
174 
175  return false;
176 }
float alpha
Definition: AMPTWrapper.h:95
uint32_t ID
Definition: Definitions.h:26
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
#define abs(x)
Definition: mlp_lapack.h:159
double charge(const std::vector< uint8_t > &Ampls)
double double double z
void getData(T &iHolder) const
Definition: EventSetup.h:67
int iEvent
Definition: GenABIO.cc:243
T sqrt(T t)
Definition: SSEVec.h:46
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
bool isAvailable() const
Definition: Service.h:47
virtual bool filter(edm::Event &, const edm::EventSetup &)
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
double p2[4]
Definition: TauolaWrapper.h:90
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
static double getDistInCM(double eta1, double phi1, double eta2, double phi2)
PythiaFilterIsolatedTrack(const edm::ParameterSet &)
edm::Service< edm::RandomNumberGenerator > rng_
double p1[4]
Definition: TauolaWrapper.h:89
tuple status
Definition: ntuplemaker.py:245
static std::pair< double, double > GetEtaPhiAtEcal(double etaIP, double phiIP, double pT, int charge, double vtxZ)