CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/PhysicsTools/CandUtils/src/EventShapeVariables.cc

Go to the documentation of this file.
00001 #include "PhysicsTools/CandUtils/interface/EventShapeVariables.h"
00002 
00003 #include "TMath.h"
00004 
00006 EventShapeVariables::EventShapeVariables(const edm::View<reco::Candidate>& inputVectors)
00007 {
00008   std::cout << "inputVectors.size = " << inputVectors.size() << std::endl;
00009   inputVectors_.reserve( inputVectors.size() );
00010   for ( edm::View<reco::Candidate>::const_iterator vec = inputVectors.begin(); vec != inputVectors.end(); ++vec){
00011     inputVectors_.push_back(math::XYZVector(vec->px(), vec->py(), vec->pz()));
00012   }
00013 }
00014 
00016 EventShapeVariables::EventShapeVariables(const std::vector<math::XYZVector>& inputVectors) 
00017   : inputVectors_(inputVectors)
00018 {}
00019 
00021 EventShapeVariables::EventShapeVariables(const std::vector<math::RhoEtaPhiVector>& inputVectors)
00022 {
00023   inputVectors_.reserve( inputVectors.size() );
00024   for ( std::vector<math::RhoEtaPhiVector>::const_iterator vec = inputVectors.begin(); vec != inputVectors.end(); ++vec ){
00025     inputVectors_.push_back(math::XYZVector(vec->x(), vec->y(), vec->z()));
00026   }
00027 }
00028 
00030 EventShapeVariables::EventShapeVariables(const std::vector<math::RThetaPhiVector>& inputVectors)
00031 {
00032   inputVectors_.reserve( inputVectors.size() );
00033   for(std::vector<math::RThetaPhiVector>::const_iterator vec = inputVectors.begin(); vec != inputVectors.end(); ++vec ){
00034     inputVectors_.push_back(math::XYZVector(vec->x(), vec->y(), vec->z()));
00035   }
00036 }
00037   
00041 double 
00042 EventShapeVariables::isotropy(const unsigned int& numberOfSteps) const
00043 {
00044   const double deltaPhi=2*TMath::Pi()/numberOfSteps;
00045   double phi = 0, eIn =-1., eOut=-1.;
00046   for(unsigned int i=0; i<numberOfSteps; ++i){
00047     phi+=deltaPhi;
00048     double sum=0;
00049     for(unsigned int j=0; j<inputVectors_.size(); ++j){
00050       // sum over inner product of unit vectors and momenta
00051       sum+=TMath::Abs(TMath::Cos(phi)*inputVectors_[j].x()+TMath::Sin(phi)*inputVectors_[j].y());
00052     }
00053     if( eOut<0. || sum<eOut ) eOut=sum;
00054     if( eIn <0. || sum>eIn  ) eIn =sum;
00055   }
00056   return (eIn-eOut)/eIn;
00057 }
00058 
00061 double 
00062 EventShapeVariables::circularity(const unsigned int& numberOfSteps) const
00063 {
00064   const double deltaPhi=2*TMath::Pi()/numberOfSteps;
00065   double circularity=-1, phi=0, area = 0;
00066   for(unsigned int i=0;i<inputVectors_.size();i++) {
00067     area+=TMath::Sqrt(inputVectors_[i].x()*inputVectors_[i].x()+inputVectors_[i].y()*inputVectors_[i].y());
00068   }
00069   for(unsigned int i=0; i<numberOfSteps; ++i){
00070     phi+=deltaPhi;
00071     double sum=0, tmp=0.;
00072     for(unsigned int j=0; j<inputVectors_.size(); ++j){
00073       sum+=TMath::Abs(TMath::Cos(phi)*inputVectors_[j].x()+TMath::Sin(phi)*inputVectors_[j].y());
00074     }
00075     tmp=TMath::Pi()/2*sum/area;
00076     if( circularity<0 || tmp<circularity ){
00077       circularity=tmp;
00078     }
00079   }
00080   return circularity;
00081 }
00082 
00084 TMatrixDSym 
00085 EventShapeVariables::compMomentumTensor(double r) const
00086 {
00087   TMatrixDSym momentumTensor(3);
00088   momentumTensor.Zero();
00089 
00090   if ( inputVectors_.size() < 2 ){
00091     return momentumTensor;
00092   }
00093 
00094   // fill momentumTensor from inputVectors
00095   double norm = 1.;
00096   for ( int i = 0; i < (int)inputVectors_.size(); ++i ){
00097     double p2 = inputVectors_[i].Dot(inputVectors_[i]);
00098     double pR = ( r == 2. ) ? p2 : TMath::Power(p2, 0.5*r);
00099     norm += pR;
00100     double pRminus2 = ( r == 2. ) ? 1. : TMath::Power(p2, 0.5*r - 1.);
00101     momentumTensor(0,0) += pRminus2*inputVectors_[i].x()*inputVectors_[i].x();
00102     momentumTensor(0,1) += pRminus2*inputVectors_[i].x()*inputVectors_[i].y();
00103     momentumTensor(0,2) += pRminus2*inputVectors_[i].x()*inputVectors_[i].z();
00104     momentumTensor(1,0) += pRminus2*inputVectors_[i].y()*inputVectors_[i].x();
00105     momentumTensor(1,1) += pRminus2*inputVectors_[i].y()*inputVectors_[i].y();
00106     momentumTensor(1,2) += pRminus2*inputVectors_[i].y()*inputVectors_[i].z();
00107     momentumTensor(2,0) += pRminus2*inputVectors_[i].z()*inputVectors_[i].x();
00108     momentumTensor(2,1) += pRminus2*inputVectors_[i].z()*inputVectors_[i].y();
00109     momentumTensor(2,2) += pRminus2*inputVectors_[i].z()*inputVectors_[i].z();
00110   }
00111 
00112   //std::cout << "momentumTensor:" << std::endl;
00113   //std::cout << momentumTensor(0,0) << " " << momentumTensor(0,1) << " " << momentumTensor(0,2) 
00114   //          << momentumTensor(1,0) << " " << momentumTensor(1,1) << " " << momentumTensor(1,2) 
00115   //          << momentumTensor(2,0) << " " << momentumTensor(2,1) << " " << momentumTensor(2,2) << std::endl;
00116 
00117   // return momentumTensor normalized to determinant 1
00118   return (1./norm)*momentumTensor;
00119 }
00120 
00123 TVectorD
00124 EventShapeVariables::compEigenValues(double r) const
00125 {
00126   TVectorD eigenValues(3);
00127   TMatrixDSym myTensor = compMomentumTensor(r);
00128   if( myTensor.IsSymmetric() ){
00129     if( myTensor.NonZeros() != 0 ) myTensor.EigenVectors(eigenValues);
00130   }
00131 
00132   // CV: TMatrixDSym::EigenVectors returns eigen-values and eigen-vectors
00133   //     ordered by descending eigen-values, so no need to do any sorting here...
00134   //std::cout << "eigenValues(0) = " << eigenValues(0) << ","
00135   //          << " eigenValues(1) = " << eigenValues(1) << ","
00136   //          << " eigenValues(2) = " << eigenValues(2) << std::endl;
00137 
00138   return eigenValues;
00139 }
00140 
00143 double 
00144 EventShapeVariables::sphericity(double r) const
00145 {
00146   TVectorD eigenValues = compEigenValues(r);
00147   return 1.5*(eigenValues(1) + eigenValues(2));
00148 }
00149 
00152 double 
00153 EventShapeVariables::aplanarity(double r) const
00154 {
00155   TVectorD eigenValues = compEigenValues(r);
00156   return 1.5*eigenValues(2);
00157 }
00158 
00162 double 
00163 EventShapeVariables::C(double r) const
00164 {
00165   TVectorD eigenValues = compEigenValues(r);
00166   return 3.*(eigenValues(0)*eigenValues(1) + eigenValues(0)*eigenValues(2) + eigenValues(1)*eigenValues(2));
00167 }
00168 
00172 double 
00173 EventShapeVariables::D(double r) const
00174 {
00175   TVectorD eigenValues = compEigenValues(r);
00176   return 27.*eigenValues(0)*eigenValues(1)*eigenValues(2);
00177 }
00178 
00179 
00180