CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
significanceAlgo.cc
Go to the documentation of this file.
2 #include <iostream>
3 #include <string>
4 #include "TMath.h"
5 #include "math.h"
6 #include "TROOT.h"
8 
9 // -*- C++ -*-
10 //
11 // Package: METAlgorithms
12 // Class: SignAlgoResolutions
13 //
21 //
22 // Original Author: Kyle Story, Freya Blekman (Cornell University)
23 // Created: Fri Apr 18 11:58:33 CEST 2008
24 // $Id: significanceAlgo.cc,v 1.15 2010/04/20 14:56:07 fblekman Exp $
25 //
26 //
27 
29  // eventVec_(0),
30  signifmatrix_(2,2),
31  set_worker_(0),
32  xmet_(0),
33  ymet_(0)
34 
35 {
36  // std::cout << "in constructor ! " << std::endl;
38 }
39 
40 
41 //******* Add an existing significance matrix to the algo, so that the vector sum can be continued. Only makes sense if matrix is empty or you want to purposefully increase uncertainties (for example in systematic studies)!
42 const void
44  // check that the matrix is size 2:
45  if(input.GetNrows()==2 && input.GetNcols()==2) {
46  signifmatrix_+=input;
47  }
48  return;
49 }
52 
53 const void
54 metsig::significanceAlgo::setSignifMatrix(const TMatrixD &input,const double &met_r, const double &met_phi, const double &met_set){
55  // check that the matrix is size 2:
56  if(input.GetNrows()==2 && input.GetNcols()==2) {
57  signifmatrix_=input;
58  set_worker_=met_set;
59  xmet_=met_r*cos(met_phi);
60  ymet_=met_r*sin(met_phi);
61  }
62  return;
63 }
64 
65 // ********destructor ********
66 
68 }
69 
70 // //*** rotate a 2D matrix by angle theta **********************//
71 
72 void
74 {
75  // I suggest not using this to rotate trivial matrices.
76  TMatrixD r(2,2);
77  TMatrixD rInv(2,2);
78 
79  r(0,0) = cos(theta); r(0,1) = sin(theta); r(1,0) = -sin(theta); r(1,1) = cos(theta);
80  rInv = r;
81  rInv.Invert();
82  //-- Rotate v --//
83  v = rInv * v * r;
84 }
85 //************************************************************//
86 
87 
88 const void
89 metsig::significanceAlgo::subtractObjects(const std::vector<metsig::SigInputObj>& eventVec)
90 {
91  TMatrixD v_tot = signifmatrix_;
92  //--- Loop over physics objects in the event ---//
93  // for(unsigned int objnum=1; objnum < EventVec.size(); objnum++ ) {
94  for(std::vector<SigInputObj>::const_iterator obj = eventVec.begin(); obj!= eventVec.end(); ++obj){
95  double et_tmp = obj->get_energy();
96  double phi_tmp = obj->get_phi();
97  double sigma_et = obj->get_sigma_e();
98  double sigma_tan = obj->get_sigma_tan();
99 
100  double cosphi=cos(phi_tmp);
101  double sinphi=sin(phi_tmp);
102  double xval = et_tmp * cosphi;
103  double yval = et_tmp * sinphi;
104  xmet_ += xval;
105  ymet_ += yval;
106  set_worker_ -= et_tmp;
107 
108  double sigma0_2=sigma_et*sigma_et;
109  double sigma1_2=sigma_tan*sigma_tan;
110 
111  v_tot(0,0)-= sigma0_2*cosphi*cosphi + sigma1_2*sinphi*sinphi;
112  v_tot(0,1)-= cosphi*sinphi*(sigma0_2 - sigma1_2);
113  v_tot(1,0)-= cosphi*sinphi*(sigma0_2 - sigma1_2);
114  v_tot(1,1)-= sigma1_2*cosphi*cosphi + sigma0_2*sinphi*sinphi;
115 
116  }
117  signifmatrix_=v_tot;
118 }
119 //************************************************************//
120 
121 
122 const void
123 metsig::significanceAlgo::addObjects(const std::vector<metsig::SigInputObj>& eventVec)
124 {
125  TMatrixD v_tot = signifmatrix_;
126  //--- Loop over physics objects in the event ---//
127  // for(unsigned int objnum=1; objnum < EventVec.size(); objnum++ ) {
128  for(std::vector<SigInputObj>::const_iterator obj = eventVec.begin(); obj!= eventVec.end(); ++obj){
129  double et_tmp = obj->get_energy();
130  double phi_tmp = obj->get_phi();
131  double sigma_et = obj->get_sigma_e();
132  double sigma_tan = obj->get_sigma_tan();
133 
134  double cosphi=cos(phi_tmp);
135  double sinphi=sin(phi_tmp);
136  double xval = et_tmp * cosphi;
137  double yval = et_tmp * sinphi;
138  xmet_ -= xval;
139  ymet_ -= yval;
140  set_worker_ += et_tmp;
141 
142  double sigma0_2=sigma_et*sigma_et;
143  double sigma1_2=sigma_tan*sigma_tan;
144 
145  v_tot(0,0)+= sigma0_2*cosphi*cosphi + sigma1_2*sinphi*sinphi;
146  v_tot(0,1)+= cosphi*sinphi*(sigma0_2 - sigma1_2);
147  v_tot(1,0)+= cosphi*sinphi*(sigma0_2 - sigma1_2);
148  v_tot(1,1)+= sigma1_2*cosphi*cosphi + sigma0_2*sinphi*sinphi;
149 
150  }
151  signifmatrix_=v_tot;
152 }
153 
154 //************************************************************//
155 const double
156 metsig::significanceAlgo::significance(double &met_r, double &met_phi, double &met_set)
157 {
158 
159  if(signifmatrix_(0,0)==0 && signifmatrix_(1,1)==0 && signifmatrix_(1,0)==0 && signifmatrix_(0,1)==0){
160  //edm::LogWarning("SignCaloSpecificAlgo") << "Event Vector is empty! Return significance -1";
161  return(-1);
162  }
163 
164  //--- Temporary variables ---//
165 
166  TMatrixD v_tot(2,2);
167  TVectorD metvec(2);
168 
169  //--- Initialize sum of rotated covariance matrices ---//
170  v_tot=signifmatrix_;
171  // std::cout << "INPUT:\n"<< v_tot(0,0) << "," << v_tot(0,1) << "\n" << v_tot(1,0) << "," << v_tot(1,1) << std::endl;
172 
173 
174 
175  //--- Calculate magnitude and angle of MET, store in returned variables ---//
176  met_r = sqrt(xmet_*xmet_ + ymet_*ymet_);
177  met_set = set_worker_;
178  met_phi= TMath::ATan2(ymet_, xmet_);
179 
180  // one other option: if particles cancel there could be small numbers.
181  // this check fixes this, added by F.Blekman
182  if(fabs(v_tot.Determinant())<0.000001)
183  return -1;
184 
185 
186  // save matrix into object:
187  // std::cout << "SAVED:\n"<< v_tot(0,0) << "," << v_tot(0,1) << "\n" << v_tot(1,0) << "," << v_tot(1,1) << std::endl;
188  v_tot.Invert();
189  // std::cout << "INVERTED:\n"<< v_tot(0,0) << "," << v_tot(0,1) << "\n" << v_tot(1,0) << "," << v_tot(1,1) << std::endl;
190 
191 
192 
193  metvec(0) = xmet_; metvec(1) = ymet_;
194  double lnSignificance = metvec * (v_tot * metvec);
195 
196  // v_tot.Invert();
197  // std::cout << "INVERTED AGAIN:\n"<< v_tot(0,0) << "," << v_tot(0,1) << "\n" << v_tot(1,0) << "," << v_tot(1,1) << std::endl;
198  return lnSignificance;
199 }
200 //*** End of Significance calculation ********************************//
const void addObjects(const std::vector< metsig::SigInputObj > &EventVec)
void rotateMatrix(Double_t theta, TMatrixD &v)
const double significance(double &met_r, double &met_phi, double &met_set)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
const void subtractObjects(const std::vector< metsig::SigInputObj > &EventVec)
T sqrt(T t)
Definition: SSEVec.h:48
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
const void addSignifMatrix(const TMatrixD &input)
const void setSignifMatrix(const TMatrixD &input, const double &met_r, const double &met_phi, const double &met_set)
reset the signficance matrix (this is the most likely case), so that the vector sum can be continued ...