test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EventShapeVariables.cc
Go to the documentation of this file.
2 
3 #include "TMath.h"
4 
7 {
8  std::cout << "inputVectors.size = " << inputVectors.size() << std::endl;
9  inputVectors_.reserve( inputVectors.size() );
10  for ( edm::View<reco::Candidate>::const_iterator vec = inputVectors.begin(); vec != inputVectors.end(); ++vec){
11  inputVectors_.push_back(math::XYZVector(vec->px(), vec->py(), vec->pz()));
12  }
13 }
14 
16 EventShapeVariables::EventShapeVariables(const std::vector<math::XYZVector>& inputVectors)
17  : inputVectors_(inputVectors)
18 {}
19 
21 EventShapeVariables::EventShapeVariables(const std::vector<math::RhoEtaPhiVector>& inputVectors)
22 {
23  inputVectors_.reserve( inputVectors.size() );
24  for ( std::vector<math::RhoEtaPhiVector>::const_iterator vec = inputVectors.begin(); vec != inputVectors.end(); ++vec ){
25  inputVectors_.push_back(math::XYZVector(vec->x(), vec->y(), vec->z()));
26  }
27 }
28 
30 EventShapeVariables::EventShapeVariables(const std::vector<math::RThetaPhiVector>& inputVectors)
31 {
32  inputVectors_.reserve( inputVectors.size() );
33  for(std::vector<math::RThetaPhiVector>::const_iterator vec = inputVectors.begin(); vec != inputVectors.end(); ++vec ){
34  inputVectors_.push_back(math::XYZVector(vec->x(), vec->y(), vec->z()));
35  }
36 }
37 
41 double
42 EventShapeVariables::isotropy(const unsigned int& numberOfSteps) const
43 {
44  const double deltaPhi=2*TMath::Pi()/numberOfSteps;
45  double phi = 0, eIn =-1., eOut=-1.;
46  for(unsigned int i=0; i<numberOfSteps; ++i){
47  phi+=deltaPhi;
48  double sum=0;
49  for(unsigned int j=0; j<inputVectors_.size(); ++j){
50  // sum over inner product of unit vectors and momenta
51  sum+=TMath::Abs(TMath::Cos(phi)*inputVectors_[j].x()+TMath::Sin(phi)*inputVectors_[j].y());
52  }
53  if( eOut<0. || sum<eOut ) eOut=sum;
54  if( eIn <0. || sum>eIn ) eIn =sum;
55  }
56  return (eIn-eOut)/eIn;
57 }
58 
61 double
62 EventShapeVariables::circularity(const unsigned int& numberOfSteps) const
63 {
64  const double deltaPhi=2*TMath::Pi()/numberOfSteps;
65  double circularity=-1, phi=0, area = 0;
66  for(unsigned int i=0;i<inputVectors_.size();i++) {
67  area+=TMath::Sqrt(inputVectors_[i].x()*inputVectors_[i].x()+inputVectors_[i].y()*inputVectors_[i].y());
68  }
69  for(unsigned int i=0; i<numberOfSteps; ++i){
70  phi+=deltaPhi;
71  double sum=0, tmp=0.;
72  for(unsigned int j=0; j<inputVectors_.size(); ++j){
73  sum+=TMath::Abs(TMath::Cos(phi)*inputVectors_[j].x()+TMath::Sin(phi)*inputVectors_[j].y());
74  }
75  tmp=TMath::Pi()/2*sum/area;
76  if( circularity<0 || tmp<circularity ){
77  circularity=tmp;
78  }
79  }
80  return circularity;
81 }
82 
84 TMatrixDSym
86 {
87  TMatrixDSym momentumTensor(3);
88  momentumTensor.Zero();
89 
90  if ( inputVectors_.size() < 2 ){
91  return momentumTensor;
92  }
93 
94  // fill momentumTensor from inputVectors
95  double norm = 0.;
96  for ( int i = 0; i < (int)inputVectors_.size(); ++i ){
97  double p2 = inputVectors_[i].Dot(inputVectors_[i]);
98  double pR = ( r == 2. ) ? p2 : TMath::Power(p2, 0.5*r);
99  norm += pR;
100  double pRminus2 = ( r == 2. ) ? 1. : TMath::Power(p2, 0.5*r - 1.);
101  momentumTensor(0,0) += pRminus2*inputVectors_[i].x()*inputVectors_[i].x();
102  momentumTensor(0,1) += pRminus2*inputVectors_[i].x()*inputVectors_[i].y();
103  momentumTensor(0,2) += pRminus2*inputVectors_[i].x()*inputVectors_[i].z();
104  momentumTensor(1,0) += pRminus2*inputVectors_[i].y()*inputVectors_[i].x();
105  momentumTensor(1,1) += pRminus2*inputVectors_[i].y()*inputVectors_[i].y();
106  momentumTensor(1,2) += pRminus2*inputVectors_[i].y()*inputVectors_[i].z();
107  momentumTensor(2,0) += pRminus2*inputVectors_[i].z()*inputVectors_[i].x();
108  momentumTensor(2,1) += pRminus2*inputVectors_[i].z()*inputVectors_[i].y();
109  momentumTensor(2,2) += pRminus2*inputVectors_[i].z()*inputVectors_[i].z();
110  }
111 
112  //std::cout << "momentumTensor:" << std::endl;
113  //std::cout << momentumTensor(0,0) << " " << momentumTensor(0,1) << " " << momentumTensor(0,2)
114  // << momentumTensor(1,0) << " " << momentumTensor(1,1) << " " << momentumTensor(1,2)
115  // << momentumTensor(2,0) << " " << momentumTensor(2,1) << " " << momentumTensor(2,2) << std::endl;
116 
117  // return momentumTensor normalized to determinant 1
118  return (1./norm)*momentumTensor;
119 }
120 
123 TVectorD
125 {
126  TVectorD eigenValues(3);
127  TMatrixDSym myTensor = compMomentumTensor(r);
128  if( myTensor.IsSymmetric() ){
129  if( myTensor.NonZeros() != 0 ) myTensor.EigenVectors(eigenValues);
130  }
131 
132  // CV: TMatrixDSym::EigenVectors returns eigen-values and eigen-vectors
133  // ordered by descending eigen-values, so no need to do any sorting here...
134  //std::cout << "eigenValues(0) = " << eigenValues(0) << ","
135  // << " eigenValues(1) = " << eigenValues(1) << ","
136  // << " eigenValues(2) = " << eigenValues(2) << std::endl;
137 
138  return eigenValues;
139 }
140 
143 double
145 {
146  TVectorD eigenValues = compEigenValues(r);
147  return 1.5*(eigenValues(1) + eigenValues(2));
148 }
149 
152 double
154 {
155  TVectorD eigenValues = compEigenValues(r);
156  return 1.5*eigenValues(2);
157 }
158 
162 double
164 {
165  TVectorD eigenValues = compEigenValues(r);
166  return 3.*(eigenValues(0)*eigenValues(1) + eigenValues(0)*eigenValues(2) + eigenValues(1)*eigenValues(2));
167 }
168 
172 double
174 {
175  TVectorD eigenValues = compEigenValues(r);
176  return 27.*eigenValues(0)*eigenValues(1)*eigenValues(2);
177 }
178 
179 
180 
const double Pi
TVectorD compEigenValues(double=2.) const
int i
Definition: DBlmapReader.cc:9
double C(double=2.) const
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
double circularity(const unsigned int &numberOfSteps=1000) const
EventShapeVariables(const edm::View< reco::Candidate > &inputVectors)
constructor from reco::Candidates
T Abs(T a)
Definition: MathUtil.h:49
int j
Definition: DBlmapReader.cc:9
double p2[4]
Definition: TauolaWrapper.h:90
double sphericity(double=2.) const
std::vector< math::XYZVector > inputVectors_
cashing of input vectors
TMatrixDSym compMomentumTensor(double=2.) const
helper function to fill the 3 dimensional momentum tensor from the inputVecotrs where needed ...
double D(double=2.) const
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
double isotropy(const unsigned int &numberOfSteps=1000) const
size_type size() const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
const_iterator begin() const
tuple cout
Definition: gather_cfg.py:121
const_iterator end() const
Definition: DDAxes.h:10
double aplanarity(double=2.) const
Definition: DDAxes.h:10