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 <cmath>
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 //
25 //
26 
28  // eventVec_(0),
29  signifmatrix_(2,2),
30  set_worker_(0),
31  xmet_(0),
32  ymet_(0)
33 
34 {
35  // std::cout << "in constructor ! " << std::endl;
37 }
38 
39 
40 //******* 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)!
41 const void
43  // check that the matrix is size 2:
44  if(input.GetNrows()==2 && input.GetNcols()==2) {
45  signifmatrix_+=input;
46  }
47  return;
48 }
51 
52 const void
53 metsig::significanceAlgo::setSignifMatrix(const TMatrixD &input,const double &met_r, const double &met_phi, const double &met_set){
54  // check that the matrix is size 2:
55  if(input.GetNrows()==2 && input.GetNcols()==2) {
56  signifmatrix_=input;
57  set_worker_=met_set;
58  xmet_=met_r*cos(met_phi);
59  ymet_=met_r*sin(met_phi);
60  }
61  return;
62 }
63 
64 // ********destructor ********
65 
67 }
68 
69 // //*** rotate a 2D matrix by angle theta **********************//
70 
71 void
73 {
74  // I suggest not using this to rotate trivial matrices.
75  TMatrixD r(2,2);
76  TMatrixD rInv(2,2);
77 
78  r(0,0) = cos(theta); r(0,1) = sin(theta); r(1,0) = -sin(theta); r(1,1) = cos(theta);
79  rInv = r;
80  rInv.Invert();
81  //-- Rotate v --//
82  v = rInv * v * r;
83 }
84 //************************************************************//
85 
86 
87 const void
88 metsig::significanceAlgo::subtractObjects(const std::vector<metsig::SigInputObj>& eventVec)
89 {
90  TMatrixD v_tot = signifmatrix_;
91  //--- Loop over physics objects in the event ---//
92  // for(unsigned int objnum=1; objnum < EventVec.size(); objnum++ ) {
93  for(std::vector<SigInputObj>::const_iterator obj = eventVec.begin(); obj!= eventVec.end(); ++obj){
94  double et_tmp = obj->get_energy();
95  double phi_tmp = obj->get_phi();
96  double sigma_et = obj->get_sigma_e();
97  double sigma_tan = obj->get_sigma_tan();
98 
99  double cosphi=cos(phi_tmp);
100  double sinphi=sin(phi_tmp);
101  double xval = et_tmp * cosphi;
102  double yval = et_tmp * sinphi;
103  xmet_ += xval;
104  ymet_ += yval;
105  set_worker_ -= et_tmp;
106 
107  double sigma0_2=sigma_et*sigma_et;
108  double sigma1_2=sigma_tan*sigma_tan;
109 
110  v_tot(0,0)-= sigma0_2*cosphi*cosphi + sigma1_2*sinphi*sinphi;
111  v_tot(0,1)-= cosphi*sinphi*(sigma0_2 - sigma1_2);
112  v_tot(1,0)-= cosphi*sinphi*(sigma0_2 - sigma1_2);
113  v_tot(1,1)-= sigma1_2*cosphi*cosphi + sigma0_2*sinphi*sinphi;
114 
115  }
116  signifmatrix_=v_tot;
117 }
118 //************************************************************//
119 
120 
121 const void
122 metsig::significanceAlgo::addObjects(const std::vector<metsig::SigInputObj>& eventVec)
123 {
124  TMatrixD v_tot = signifmatrix_;
125  //--- Loop over physics objects in the event ---//
126  // for(unsigned int objnum=1; objnum < EventVec.size(); objnum++ ) {
127  for(std::vector<SigInputObj>::const_iterator obj = eventVec.begin(); obj!= eventVec.end(); ++obj){
128  double et_tmp = obj->get_energy();
129  double phi_tmp = obj->get_phi();
130  double sigma_et = obj->get_sigma_e();
131  double sigma_tan = obj->get_sigma_tan();
132 
133  double cosphi=cos(phi_tmp);
134  double sinphi=sin(phi_tmp);
135  double xval = et_tmp * cosphi;
136  double yval = et_tmp * sinphi;
137  xmet_ -= xval;
138  ymet_ -= yval;
139  set_worker_ += et_tmp;
140 
141  double sigma0_2=sigma_et*sigma_et;
142  double sigma1_2=sigma_tan*sigma_tan;
143 
144  v_tot(0,0)+= sigma0_2*cosphi*cosphi + sigma1_2*sinphi*sinphi;
145  v_tot(0,1)+= cosphi*sinphi*(sigma0_2 - sigma1_2);
146  v_tot(1,0)+= cosphi*sinphi*(sigma0_2 - sigma1_2);
147  v_tot(1,1)+= sigma1_2*cosphi*cosphi + sigma0_2*sinphi*sinphi;
148 
149  }
150  signifmatrix_=v_tot;
151 }
152 
153 //************************************************************//
154 const double
155 metsig::significanceAlgo::significance(double &met_r, double &met_phi, double &met_set)
156 {
157 
158  if(signifmatrix_(0,0)==0 && signifmatrix_(1,1)==0 && signifmatrix_(1,0)==0 && signifmatrix_(0,1)==0){
159  //edm::LogWarning("SignCaloSpecificAlgo") << "Event Vector is empty! Return significance -1";
160  return(-1);
161  }
162 
163  //--- Temporary variables ---//
164 
165  TMatrixD v_tot(2,2);
166  TVectorD metvec(2);
167 
168  //--- Initialize sum of rotated covariance matrices ---//
169  v_tot=signifmatrix_;
170  // std::cout << "INPUT:\n"<< v_tot(0,0) << "," << v_tot(0,1) << "\n" << v_tot(1,0) << "," << v_tot(1,1) << std::endl;
171 
172 
173 
174  //--- Calculate magnitude and angle of MET, store in returned variables ---//
175  met_r = sqrt(xmet_*xmet_ + ymet_*ymet_);
176  met_set = set_worker_;
177  met_phi= TMath::ATan2(ymet_, xmet_);
178 
179  // one other option: if particles cancel there could be small numbers.
180  // this check fixes this, added by F.Blekman
181  if(fabs(v_tot.Determinant())<0.000001)
182  return -1;
183 
184 
185  // save matrix into object:
186  // std::cout << "SAVED:\n"<< v_tot(0,0) << "," << v_tot(0,1) << "\n" << v_tot(1,0) << "," << v_tot(1,1) << std::endl;
187  v_tot.Invert();
188  // std::cout << "INVERTED:\n"<< v_tot(0,0) << "," << v_tot(0,1) << "\n" << v_tot(1,0) << "," << v_tot(1,1) << std::endl;
189 
190 
191 
192  metvec(0) = xmet_; metvec(1) = ymet_;
193  double lnSignificance = metvec * (v_tot * metvec);
194 
195  // v_tot.Invert();
196  // std::cout << "INVERTED AGAIN:\n"<< v_tot(0,0) << "," << v_tot(0,1) << "\n" << v_tot(1,0) << "," << v_tot(1,1) << std::endl;
197  return lnSignificance;
198 }
199 //*** 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)
static std::string const input
Definition: EdmProvDump.cc:44
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 ...