CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EventShape.cc
Go to the documentation of this file.
3 #include <TVector3.h>
4 #include <vector>
5 #include <TMatrixDSym.h>
6 #include <TMatrixDSymEigen.h>
7 #include <TVectorD.h>
8 
9 using namespace edm;
10 using namespace reco;
11 using namespace std;
13 
15 {
16  for(reco::TrackCollection::const_iterator itTrack = tracks.begin(); itTrack<tracks.end(); ++itTrack) {
17  p.push_back(TVector3(itTrack->px(),itTrack->py(),itTrack->pz()));
18  }
19 
20  // first fill the momentum tensor
21  TMatrixDSym MomentumTensor(3);
22  for(std::vector<TVector3>::const_iterator momentum = p.begin();momentum<p.end();++momentum) {
23  for(unsigned int i=0;i<3;i++)
24  for(unsigned int j=0;j<=i;j++) {
25  MomentumTensor[i][j] += momentum[i]*momentum[j];
26  }
27  }
28  MomentumTensor*=1/(MomentumTensor[0][0]+MomentumTensor[1][1]+MomentumTensor[2][2]);
29  // find the eigen values
30  TMatrixDSymEigen eigen(MomentumTensor);
31  TVectorD eigenvals = eigen.GetEigenValues();
32  eigenvalues[0] = eigenvals[0];
33  eigenvalues[1] = eigenvals[1];
34  eigenvalues[2] = eigenvals[2];
35  sort(eigenvalues.begin(),eigenvalues.end());
36 }
37 
39 {
41  TVector3 qtbo;
42  TVector3 zero(0.,0.,0.);
43  float vnew = 0.;
44  uint32_t Np = p.size();
45 
46  // for more than 2 tracks
47  if (Np > 2) {
48  float vmax = 0.;
49  TVector3 vn, vm, vc, vl;
50  for(unsigned int i=0; i< Np-1; i++)
51  for(unsigned int j=i+1; j < Np; j++) {
52  vc = p[i].Cross(p[j]);
53  vl = zero;
54  for(unsigned int k=0; k<Np; k++)
55  if ((k != i) && (k != j)) {
56  if (p[k].Dot(vc) >= 0.) vl = vl + p[k];
57  else vl = vl - p[k];
58  }
59  // make all four sign-combinations for i,j
60  vn = vl + p[j] + p[i];
61  vnew = vn.Mag2();
62  if (vnew > vmax) {
63  vmax = vnew;
64  vm = vn;
65  }
66  vn = vl + p[j] - p[i];
67  vnew = vn.Mag2();
68  if (vnew > vmax) {
69  vmax = vnew;
70  vm = vn;
71  }
72  vn = vl - p[j] + p[i];
73  vnew = vn.Mag2();
74  if (vnew > vmax) {
75  vmax = vnew;
76  vm = vn;
77  }
78  vn = vl - p[j] - p[i];
79  vnew = vn.Mag2();
80  if (vnew > vmax) {
81  vmax = vnew;
82  vm = vn;
83  }
84  }
85  // sum momenta of all particles and iterate
86  for(int iter=1; iter<=4; iter++) {
87  qtbo = zero;
88  for(unsigned int i=0; i< Np; i++)
89  if (vm.Dot(p[i]) >= 0.)
90  qtbo = qtbo + p[i];
91  else
92  qtbo = qtbo - p[i];
93  vnew = qtbo.Mag2();
94  if (vnew == vmax) break;
95  vmax = vnew;
96  vm = qtbo;
97  }
98  } // of if Np > 2
99  else
100  if (Np == 2)
101  if (p[0].Dot(p[1]) >= 0.)
102  qtbo = p[0] + p[1];
103  else
104  qtbo = p[0] - p[1];
105  else if (Np == 1)
106  qtbo = p[0];
107  else {
108  qtbo = zero;
109  return output;
110  }
111  // normalize thrust -division by total momentum-
112  float vsum = 0.;
113  for(unsigned int i=0; i < Np; i++) vsum = vsum + p[i].Mag();
114  vnew = qtbo.Mag();
115  float v = vnew/vsum;
116  float x = qtbo.X()/vnew;
117  float y = qtbo.Y()/vnew;
118  float z = qtbo.Z()/vnew;
119  output.SetPxPyPzE(x, y, z, v);
120  return output;
121 }
122 
124 {
125  std::vector<TVector3> pp;
126  uint32_t Np = tracks.size();
128  for(reco::TrackCollection::const_iterator itTrack = tracks.begin(); itTrack<tracks.end(); ++itTrack) {
129  pp.push_back(TVector3(itTrack->px(),itTrack->py(),itTrack->pz()));
130  }
131  TVector3 qtbo;
132  TVector3 zero(0.,0.,0.);
133  float vnew = 0.;
134 
135  // for more than 2 tracks
136  if (Np > 2) {
137  float vmax = 0.;
138  TVector3 vn, vm, vc, vl;
139  for(unsigned int i=0; i< Np-1; i++)
140  for(unsigned int j=i+1; j < Np; j++) {
141  vc = pp[i].Cross(pp[j]);
142  vl = zero;
143  for(unsigned int k=0; k<Np; k++)
144  if ((k != i) && (k != j)) {
145  if (pp[k].Dot(vc) >= 0.) vl = vl + pp[k];
146  else vl = vl - pp[k];
147  }
148  // make all four sign-combinations for i,j
149  vn = vl + pp[j] + pp[i];
150  vnew = vn.Mag2();
151  if (vnew > vmax) {
152  vmax = vnew;
153  vm = vn;
154  }
155  vn = vl + pp[j] - pp[i];
156  vnew = vn.Mag2();
157  if (vnew > vmax) {
158  vmax = vnew;
159  vm = vn;
160  }
161  vn = vl - pp[j] + pp[i];
162  vnew = vn.Mag2();
163  if (vnew > vmax) {
164  vmax = vnew;
165  vm = vn;
166  }
167  vn = vl - pp[j] - pp[i];
168  vnew = vn.Mag2();
169  if (vnew > vmax) {
170  vmax = vnew;
171  vm = vn;
172  }
173  }
174  // sum momenta of all particles and iterate
175  for(int iter=1; iter<=4; iter++) {
176  qtbo = zero;
177  for(unsigned int i=0; i< Np; i++)
178  if (vm.Dot(pp[i]) >= 0.)
179  qtbo = qtbo + pp[i];
180  else
181  qtbo = qtbo - pp[i];
182  vnew = qtbo.Mag2();
183  if (vnew == vmax) break;
184  vmax = vnew;
185  vm = qtbo;
186  }
187  } // of if Np > 2
188  else
189  if (Np == 2)
190  if (pp[0].Dot(pp[1]) >= 0.)
191  qtbo = pp[0] + pp[1];
192  else
193  qtbo = pp[0] - pp[1];
194  else if (Np == 1)
195  qtbo = pp[0];
196  else {
197  qtbo = zero;
198  return output;
199  }
200  // normalize thrust -division by total momentum-
201  float vsum = 0.;
202  for(unsigned int i=0; i < Np; i++) vsum = vsum + pp[i].Mag();
203  vnew = qtbo.Mag();
204  float v = vnew/vsum;
205  float x = qtbo.X()/vnew;
206  float y = qtbo.Y()/vnew;
207  float z = qtbo.Z()/vnew;
208  output.SetPxPyPzE(x, y, z, v);
209  return output;
210 }
211 
213 {
214  // a critical check
215  if(tracks.size()==0) return 0;
216 
217  // first fill the momentum tensor
218  TMatrixDSym MomentumTensor(3);
219  for(reco::TrackCollection::const_iterator itTrack = tracks.begin(); itTrack<tracks.end(); ++itTrack) {
220  std::vector<double> momentum(3);
221  momentum[0] = itTrack->px();
222  momentum[1] = itTrack->py();
223  momentum[2] = itTrack->pz();
224  for(unsigned int i=0;i<3;i++)
225  for(unsigned int j=0;j<=i;j++) {
226  MomentumTensor[i][j] += momentum[i]*momentum[j];
227  }
228  }
229  MomentumTensor*=1/(MomentumTensor[0][0]+MomentumTensor[1][1]+MomentumTensor[2][2]);
230  // find the eigen values
231  TMatrixDSymEigen eigen(MomentumTensor);
232  TVectorD eigenvals = eigen.GetEigenValues();
233  vector<float> eigenvaluess(3);
234  eigenvaluess[0] = eigenvals[0];
235  eigenvaluess[1] = eigenvals[1];
236  eigenvaluess[2] = eigenvals[2];
237  sort(eigenvaluess.begin(),eigenvaluess.end());
238  // compute spericity
239  float sph = ( 1.5*(1-eigenvaluess[2]));
240  return sph;
241 }
242 
244 {
245  // a critical check
246  if (tracks.size()==0) return 0;
247  // first fill the momentum tensor
248  TMatrixDSym MomentumTensor(3);
249  for(reco::TrackCollection::const_iterator itTrack = tracks.begin(); itTrack<tracks.end(); ++itTrack) {
250  std::vector<double> momentum(3);
251  momentum[0] = itTrack->px();
252  momentum[1] = itTrack->py();
253  momentum[2] = itTrack->pz();
254  for(unsigned int i=0;i<3;i++)
255  for(unsigned int j=0;j<=i;j++) {
256  MomentumTensor[i][j] += momentum[i]*momentum[j];
257  }
258  }
259  MomentumTensor*=1/(MomentumTensor[0][0]+MomentumTensor[1][1]+MomentumTensor[2][2]);
260  // find the eigen values
261  TMatrixDSymEigen eigen(MomentumTensor);
262  TVectorD eigenvals = eigen.GetEigenValues();
263  vector<float> eigenvaluess(3);
264  eigenvaluess[0] = eigenvals[0];
265  eigenvaluess[1] = eigenvals[1];
266  eigenvaluess[2] = eigenvals[2];
267  sort(eigenvaluess.begin(),eigenvaluess.end());
268  // compute aplanarity
269  return ( 1.5*eigenvaluess[0]);
270 }
271 
273 {
274  // First a critical check
275  if (tracks.size()==0) return 0;
276  // first fill the momentum tensor
277  TMatrixDSym MomentumTensor(3);
278  for(reco::TrackCollection::const_iterator itTrack = tracks.begin(); itTrack<tracks.end(); ++itTrack) {
279  std::vector<double> momentum(3);
280  momentum[0] = itTrack->px();
281  momentum[1] = itTrack->py();
282  momentum[2] = itTrack->pz();
283  for(unsigned int i=0;i<3;i++)
284  for(unsigned int j=0;j<=i;j++) {
285  MomentumTensor[i][j] += momentum[i]*momentum[j];
286  }
287  }
288  MomentumTensor*=1/(MomentumTensor[0][0]+MomentumTensor[1][1]+MomentumTensor[2][2]);
289  // find the eigen values
290  TMatrixDSymEigen eigen(MomentumTensor);
291  TVectorD eigenvals = eigen.GetEigenValues();
292  vector<float> eigenvaluess(3);
293  eigenvaluess[0] = eigenvals[0];
294  eigenvaluess[1] = eigenvals[1];
295  eigenvaluess[2] = eigenvals[2];
296  sort(eigenvaluess.begin(),eigenvaluess.end());
297  // compute planarity
298  return (eigenvaluess[0]/eigenvaluess[1]);
299 }
300 
302 {
303  // compute sphericity
304  return ( 1.5*(1-eigenvalues[2]));
305 }
306 
308 {
309  // compute aplanarity
310  return ( 1.5*eigenvalues[0]);
311 }
312 
314 {
315  // compute planarity
316  return (eigenvalues[0]/eigenvalues[1]);
317 }
int i
Definition: DBlmapReader.cc:9
float aplanarity() const
Definition: EventShape.cc:307
tuple pp
Definition: createTree.py:15
EventShape(reco::TrackCollection &)
Definition: EventShape.cc:14
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:13
math::XYZTLorentzVectorF thrust() const
Definition: EventShape.cc:38
float float float z
int j
Definition: DBlmapReader.cc:9
std::vector< float > eigenvalues
Definition: EventShape.h:25
int k[5][pyjets_maxn]
tuple tracks
Definition: testEve_cfg.py:39
float sphericity() const
Definition: EventShape.cc:301
float planarity() const
Definition: EventShape.cc:313
Definition: DDAxes.h:10
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< float > > XYZTLorentzVectorF
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:22
std::vector< TVector3 > p
Definition: EventShape.h:24