CMS 3D CMS Logo

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