EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GFDafHit.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GFDafHit.cxx
1 /* Copyright 2011, Technische Universitaet Muenchen,
2 Authors: Karl Bicker
3 
4 This file is part of GENFIT.
5 
6 GENFIT is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10 
11 GENFIT is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15 
16 You should have received a copy of the GNU Lesser General Public License
17 along with GENFIT. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include<GFDafHit.h>
21 
22 GFDafHit::GFDafHit(std::vector<GFAbsRecoHit*> HitsInPlane) {
23 
24  fRawHits = HitsInPlane;
25  fWeights.assign(fRawHits.size(),1.);
26  fHitUpd = false;
27 
28 }
29 
31 
32  return fRawHits.at(ihit);
33 
34 }
35 
36 void GFDafHit::setWeights(std::vector<double> weights) {
37 
38  fWeights = weights;
39  fHitUpd = false;
40 }
41 
43 
44  return fRawHits.at(0)->getDetPlane(rep);
45 
46 }
47 
48 void GFDafHit::getMeasurement(const GFAbsTrackRep* rep,const GFDetPlane& pl,const TMatrixT<double>& statePred,const TMatrixT<double>& covPred,TMatrixT<double>& m, TMatrixT<double>& V) {
49 
50  /*
51  if(fHitUpd && fPl != pl) {
52  GFException exc("GFDafHit::getMeasurement(): pl!=fPl",__LINE__,__FILE__);
53  exc.setFatal();
54  throw exc;
55  }
56  */
57 
58  if(fHitUpd && fPl == pl) {
59  m.ResizeTo(fHitCoord);
60  V.ResizeTo(fHitCov);
61  m = fHitCoord;
62  V = fHitCov;
63  return;
64  }
65 
66  if(fRawHits.size() == 1) {
67  fRawHits.at(0)->getMeasurement(rep,pl,statePred,covPred,fHitCoord,fHitCov);
68  static const double maxCovSize = 1.e10;
69  if( 1.0/fWeights.at(0) < maxCovSize) {
70  fHitCov = (1.0 / fWeights.at(0)) * fHitCov;
71  }
72  else {
73  fHitCov = maxCovSize * fHitCov;
74  }
75  }
76 
77  else {
78  //set the weighted-mean cov
79  // this might seem like kind of a waste, but we need to make sure that fHitCov has the right dimensionality
80  // and we dont know it from elsewhere
81  fRawHits.at(0)->getMeasurement(rep,pl,statePred,covPred,fHitCoord,fHitCov);
82  fHitCoord.Zero();
83  fHitCov.Zero();
84  fCovInvs.clear();
85  TMatrixT<double> CovInv;
86  TMatrixT<double>* coordTemp;
87  TMatrixT<double> covTemp;
88  std::vector<TMatrixT<double>* > coords;
89  for(unsigned int i=0;i<fRawHits.size();i++) {
90  coordTemp = new TMatrixT<double>;
91  try{
92  fRawHits.at(i)->getMeasurement(rep,pl,statePred,covPred,*coordTemp,covTemp);
93  coords.push_back(coordTemp);
94  GFTools::invertMatrix(covTemp, CovInv);
95  }
96  catch(GFException& e){
97  for(unsigned int j=0;j<coords.size();++j) delete coords[j];
98  delete coordTemp;
99  throw e;
100  }
101  fCovInvs.push_back(CovInv);
102  fHitCov += fWeights.at(i) * CovInv;
103  }
104  TMatrixT<double> HitCovTemp(fHitCov);
105 
106  try{
107  GFTools::invertMatrix(HitCovTemp, fHitCov);
108  }
109  catch(GFException& e){
110  for(unsigned int j=0;j<coords.size();++j) delete coords[j];
111  throw e;
112  }
113 
114 
115  //set the weighted-mean coord
116  //fRawHits.size()==coords.size() is a certainty here
117  for(unsigned int i=0;i<fRawHits.size();i++) {
118  fHitCoord += fWeights.at(i) * fCovInvs.at(i) * (*(coords.at(i)));
119  }
120  for(unsigned int j=0;j<coords.size();++j) delete coords[j];
122  }
123  //return by refernce
124  m.ResizeTo(fHitCoord);
125  V.ResizeTo(fHitCov);
126  m = fHitCoord;
127  V = fHitCov;
128  fPl = pl;
129  fHitUpd = true;
130 }
131 
132 
133 TMatrixT<double> GFDafHit::getHMatrix(const GFAbsTrackRep* rep) {
134 
135  return fRawHits.at(0)->getHMatrix(rep);
136 
137 }
138 
140 
141  GFDafHit* retval = new GFDafHit(fRawHits);
142  retval->setWeights(fWeights);
143  return retval;
144 
145 }
146 
147 const std::string& GFDafHit::getPolicyName(){
148 
149  return fRawHits.at(0)->getPolicyName();
150 
151 }
152