00001
00002 #include "NuMatrix.h"
00003 #include "NuMatrixCPT.h"
00004
00005 #include "MessageService/MsgService.h"
00006
00007 #include "TMath.h"
00008
00009 CVSID("$Id: NuMatrixCPT.cxx,v 1.2 2010/01/11 09:43:30 nickd Exp $");
00010
00011 ClassImp(NuMatrixCPT)
00012
00013
00014
00015
00016 NuMatrixCPT::NuMatrixCPT() : NuMatrix(), fPQMatrix(0), fNQMatrix(0)
00017 {
00018
00019 }
00020
00021 NuMatrixCPT::NuMatrixCPT(Double_t POT) : NuMatrix(POT), fPQMatrix(0), fNQMatrix(0)
00022 {
00023
00024 }
00025
00026 NuMatrixCPT::NuMatrixCPT(const NuMatrixCPT& orig) : NuMatrix(orig), fPQMatrix(0), fNQMatrix(0)
00027 {
00028
00029 if (orig.fPQMatrix) fPQMatrix = orig.fPQMatrix->Copy();
00030 if (orig.fNQMatrix) fNQMatrix = orig.fNQMatrix->Copy();
00031 }
00032
00033 NuMatrixCPT &NuMatrixCPT::operator=(const NuMatrixCPT& orig)
00034 {
00035
00036 this->NuMatrix::operator=(orig);
00037
00038
00039 if (fPQMatrix) delete fPQMatrix; fPQMatrix = 0;
00040 if (fNQMatrix) delete fNQMatrix; fNQMatrix = 0;
00041
00042
00043 if (orig.fPQMatrix) fPQMatrix = orig.fPQMatrix->Copy();
00044 if (orig.fNQMatrix) fNQMatrix = orig.fNQMatrix->Copy();
00045
00046 return *this;
00047 }
00048
00049
00050 NuMatrixCPT::NuMatrixCPT(const NuMatrix* NQ, const NuMatrix* PQ)
00051 : NuMatrix(),
00052 fPQMatrix(0),
00053 fNQMatrix(0)
00054 {
00055
00056 vector<Double_t> pots;
00057
00058 if (NQ) {
00059 fNQMatrix = NQ->Copy();
00060 pots.push_back(fNQMatrix->GetPOT());
00061 }
00062 if (PQ) {
00063 fPQMatrix = PQ->Copy();
00064 pots.push_back(fPQMatrix->GetPOT());
00065 }
00066
00067
00068
00069
00070
00071
00072 if (fPQMatrix && fNQMatrix) {
00073 if (TMath::Abs(NQ->GetPOT() - PQ->GetPOT()) > 1e-5) {
00074 MSG("NuMatrixCPT",Msg::kWarning) << "POT count for pre-initialised NuMatrix objects differ." << endl;
00075 MSG("NuMatrixCPT",Msg::kWarning) << " PQ: " << fPQMatrix->GetPOT() << endl;
00076 MSG("NuMatrixCPT",Msg::kWarning) << " NQ: " << fNQMatrix->GetPOT() << endl;
00077 MSG("NuMatrixCPT",Msg::kWarning) << "Storing POT of NQ in object" << endl;
00078 }
00079 }
00080
00081
00082 if (pots.size()) ResetPOT(pots[0]);
00083
00084 }
00085
00086
00087
00088 NuMatrixCPT::NuMatrixCPT( const TString &filename,
00089 const TString &NQhistname,
00090 const TString &PQhistname,
00091 const TString &pothistname )
00092 : NuMatrix(),
00093 fPQMatrix(0),
00094 fNQMatrix(0)
00095 {
00096
00097 fNQMatrix = new NuMatrix1D(filename, NQhistname, pothistname);
00098 fPQMatrix = new NuMatrix1D(filename, PQhistname, pothistname);
00099
00100
00101 Double_t potPQ = 0.0, potNQ = 0.0;
00102 potPQ = fPQMatrix->GetPOT();
00103 potNQ = fNQMatrix->GetPOT();
00104
00105 if (potPQ != potNQ)
00106 {
00107 MSG("NuMatrixCPT",Msg::kWarning) << "POT read from file "
00108 << filename << " does not seem to match between histograms."
00109 << endl;
00110 } else {
00111 this->ResetPOT(potNQ);
00112 }
00113
00114 }
00115
00116 NuMatrixCPT::~NuMatrixCPT()
00117 {
00118 if (fPQMatrix) delete fPQMatrix; fPQMatrix = 0;
00119 if (fNQMatrix) delete fNQMatrix; fNQMatrix = 0;
00120 }
00121
00122
00124
00126
00127 Double_t NuMatrixCPT::StatsLikelihood(const NuMatrix* with) const
00128 {
00129 Double_t like = 0.0;
00130 if (fPQMatrix) like += fPQMatrix->StatsLikelihood(with);
00131 if (fNQMatrix) like += fNQMatrix->StatsLikelihood(with);
00132
00133 return like;
00134 }
00135
00137
00138 void NuMatrixCPT::ScaleToPOT(Double_t new_POT)
00139 {
00140 if (fPQMatrix) fPQMatrix->ScaleToPOT(new_POT);
00141 if (fNQMatrix) fNQMatrix->ScaleToPOT(new_POT);
00142 this->ResetPOT(new_POT);
00143 }
00144
00146
00147 void NuMatrixCPT::Scale(Double_t value)
00148 {
00149 if (fPQMatrix) fPQMatrix->Scale(value);
00150 if (fNQMatrix) fNQMatrix->Scale(value);
00151 }
00152
00154
00155 void NuMatrixCPT::Divide(const NuMatrix &correction)
00156 {
00157
00158 const NuMatrixCPT *other = dynamic_cast<const NuMatrixCPT*>(&correction);
00159 if (other == 0) {
00160 MSG("NuMatrixCPT",Msg::kWarning) << "Attempting to divide a NuMatrixCPT by something other than a NuMatrixCPT" << endl;
00161 }
00162
00163 this->Divide(*other);
00164 }
00165
00167
00168 void NuMatrixCPT::Divide(const NuMatrixCPT &correction)
00169 {
00170 if (fPQMatrix && correction.PQ()) fPQMatrix->Divide(*correction.PQ());
00171 if (fNQMatrix && correction.NQ()) fNQMatrix->Divide(*correction.NQ());
00172 }
00173
00175
00176 void NuMatrixCPT::Divide(const TH1& correction, const Option_t *option)
00177 {
00178 if (fPQMatrix) fPQMatrix->Divide(correction, option);
00179 if (fNQMatrix) fNQMatrix->Divide(correction, option);
00180 }
00181
00183
00184 void NuMatrixCPT::Divide(const TGraph &correction)
00185 {
00186 if (fPQMatrix) fPQMatrix->Divide(correction);
00187 if (fNQMatrix) fNQMatrix->Divide(correction);
00188 }
00189
00191
00192 void NuMatrixCPT::Divide(const std::pair<const TH1D*,const TH1D*> &corr)
00193 {
00194 if (fNQMatrix && corr.first) fNQMatrix->Divide(*corr.first);
00195 if (fPQMatrix && corr.second) fPQMatrix->Divide(*corr.second);
00196 }
00197
00199
00200 void NuMatrixCPT::Divide(const std::pair<const TGraph*,const TGraph*> &corr)
00201 {
00202 if (fNQMatrix && corr.first) fNQMatrix->Divide(*corr.first);
00203 if (fPQMatrix && corr.second) fPQMatrix->Divide(*corr.second);
00204 }
00205
00207
00208 void NuMatrixCPT::Multiply(const NuMatrix &correction)
00209 {
00210
00211 const NuMatrixCPT *other = dynamic_cast<const NuMatrixCPT*>(&correction);
00212 if (other == 0) {
00213 MSG("NuMatrixCPT",Msg::kWarning) << "Attempting to multiply a NuMatrixCPT by something other than a NuMatrixCPT" << endl;
00214 }
00215
00216 this->Multiply(*other);
00217 }
00218
00220
00221 void NuMatrixCPT::Multiply(const NuMatrixCPT &correction)
00222 {
00223 if (fPQMatrix && correction.PQ()) fPQMatrix->Multiply(*correction.PQ());
00224 if (fNQMatrix && correction.NQ()) fNQMatrix->Multiply(*correction.NQ());
00225 }
00226
00228
00229 void NuMatrixCPT::Multiply(const TH1& correction, const Option_t *option)
00230 {
00231 if (fPQMatrix) fPQMatrix->Multiply(correction, option);
00232 if (fNQMatrix) fNQMatrix->Multiply(correction, option);
00233 }
00234
00236
00237 void NuMatrixCPT::Multiply(const TGraph &correction)
00238 {
00239 if (fPQMatrix) fPQMatrix->Multiply(correction);
00240 if (fNQMatrix) fNQMatrix->Multiply(correction);
00241 }
00243
00244 void NuMatrixCPT::Multiply(const std::pair<const TH1D*,const TH1D*> &corr)
00245 {
00246 if (fNQMatrix && corr.first) fNQMatrix->Multiply(*corr.first);
00247 if (fPQMatrix && corr.second) fPQMatrix->Multiply(*corr.second);
00248 }
00249
00251
00252 void NuMatrixCPT::Multiply(const std::pair<const TGraph*,const TGraph*> &corr)
00253 {
00254 if (fNQMatrix && corr.first) fNQMatrix->Multiply(*corr.first);
00255 if (fPQMatrix && corr.second) fPQMatrix->Multiply(*corr.second);
00256 }
00257
00259
00260 Int_t NuMatrixCPT::Write(const TString &name)
00261 {
00262 MSG("NuMatrixCPT",Msg::kWarning) << "Histogram writing properly implemented: Only uses PQ/NQ suffixes." << endl;
00263
00264 Int_t bytetotal = 0;
00265
00266
00267 if (name=="")
00268 {
00269
00270
00271 MSG("NuMatrixCPT",Msg::kWarning) << "Must specify a name when writing. Current limitation of NuMatrix framework." << endl;
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285 } else {
00286 if (fPQMatrix) bytetotal += fPQMatrix->Write(name + "_PQ");
00287 if (fNQMatrix) bytetotal += fNQMatrix->Write(name + "_NQ");
00288 }
00289
00290 return bytetotal;
00291 }
00292
00294
00295 void NuMatrixCPT::ResetPOT(Double_t new_POT)
00296 {
00297 fPot = new_POT;
00298 if (fPQMatrix) fPQMatrix->ResetPOT(new_POT);
00299 if (fNQMatrix) fNQMatrix->ResetPOT(new_POT);
00300 }
00301
00303
00304 void NuMatrixCPT::Draw(Option_t*)
00305 {
00306 MSG("NuMatrixCPT",Msg::kInfo) << "Cannot draw CPT matrix directly at this time. Draw NQ() and PQ() independently." << endl;
00307
00308 }
00309
00311
00312 void NuMatrixCPT::Oscillate(const NuMMParameters &p)
00313 {
00314 Oscillate(p.Dm2(), p.Sn2(),p.Dm2Bar(),p.Sn2Bar());
00315
00316 }
00317
00318 void NuMatrixCPT::Oscillate(const Double_t dm2, const Double_t sn2, const Double_t dm2bar, const Double_t sn2bar)
00319 {
00320 if (fPQMatrix) fPQMatrix->Oscillate(dm2bar, sn2bar);
00321 if (fNQMatrix) fNQMatrix->Oscillate(dm2, sn2);
00322 }
00323
00325
00326 void NuMatrixCPT::SetValue(Double_t val)
00327 {
00328 if (fPQMatrix) fPQMatrix->SetValue(val);
00329 if (fNQMatrix) fNQMatrix->SetValue(val);
00330 }
00331
00333
00334 void NuMatrixCPT::RecoToTrue(const TH2D &)
00335 {
00336 MSG("NuMatrixCPT",Msg::kError) << "Trying to Reco->True a CPT matrix with only one histogram!" << endl;
00337 }
00338
00340
00341 void NuMatrixCPT::TrueToReco(const TH2D &)
00342 {
00343 MSG("NuMatrixCPT",Msg::kError) << "Trying to True-Reco a CPT matrix with only one histogram!" << endl;
00344 }
00345
00347
00348 void NuMatrixCPT::ExtrapolateNDToFD(const TH2D &)
00349 {
00350 MSG("NuMatrixCPT",Msg::kError) << "Trying to extrapolate a CPT matrix with only one histogram!" << endl;
00351 }
00352
00354
00355 void NuMatrixCPT::RecoToTrue(const std::pair<const TH2D*,const TH2D*> &correction)
00356 {
00357 if (fNQMatrix) fNQMatrix->RecoToTrue(*correction.first);
00358 if (fPQMatrix) fPQMatrix->RecoToTrue(*correction.second);
00359 }
00360
00362
00363 void NuMatrixCPT::TrueToReco(const std::pair<const TH2D*,const TH2D*> &correction)
00364 {
00365 if (fNQMatrix) fNQMatrix->TrueToReco(*correction.first);
00366 if (fPQMatrix) fPQMatrix->TrueToReco(*correction.second);
00367 }
00368
00370
00371 void NuMatrixCPT::ExtrapolateNDToFD(const std::pair<const TH2D*,const TH2D*> &beammatrix)
00372 {
00373 if (fNQMatrix) fNQMatrix->ExtrapolateNDToFD(*beammatrix.first);
00374 if (fPQMatrix) fPQMatrix->ExtrapolateNDToFD(*beammatrix.second);
00375 }
00376
00377
00380
00381
00382