Changeset 7178 for trunk/MagicSoft/Mars/mranforest/MRFEnergyEst.cc
- Timestamp:
- 07/08/05 18:14:35 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mranforest/MRFEnergyEst.cc
r7169 r7178 69 69 // 70 70 MRFEnergyEst::MRFEnergyEst(const char *name, const char *title) 71 : fNumTrees(-1), fNumTry(-1), fNdSize(-1), fDebug(kFALSE), 72 fData(0), fEnergyEst(0), fTestMatrix(0), fEstimationMode(kMean) 71 : fDebug(kFALSE), fData(0), fEnergyEst(0), 72 fNumTrees(-1), fNumTry(-1), fNdSize(-1), 73 fTestMatrix(0), fEstimationMode(kMean) 73 74 { 74 75 fName = name ? name : gsDefName.Data(); 75 76 fTitle = title ? title : gsDefTitle.Data(); 77 } 78 79 MRFEnergyEst::~MRFEnergyEst() 80 { 81 fEForests.Delete(); 76 82 } 77 83 … … 163 169 MHMatrix matrix1(mat1, "MatrixHadrons"); 164 170 MHMatrix matrix0(mat0, "MatrixGammas"); 165 166 //matrix1.AddColumns(&usedrules);167 //matrix0.AddColumns(&usedrules);168 171 169 172 // training of RF … … 191 194 gLog.SetNullOutput(kFALSE); 192 195 193 const Double_t E = (log10(grid[ie])+log10(grid[ie+1]))/2; 196 // Calculate bin center 197 const Double_t E = (TMath::Log10(grid[ie])+TMath::Log10(grid[ie+1]))/2; 194 198 195 199 // save whole forest 196 200 MRanForest *forest=(MRanForest*)plist.FindObject("MRanForest"); 197 const TString title = Form("%.10f", E); 198 forest->SetTitle(title); 199 forest->Write(title); 201 forest->SetUserVal(E); 202 forest->Write(Form("%.10f", E)); 200 203 } 201 204 … … 203 206 usedrules.Write("rules"); 204 207 205 fileRF.Close();206 207 208 return kTRUE; 208 209 } … … 210 211 Int_t MRFEnergyEst::ReadForests(MParList &plist) 211 212 { 212 TFile fileRF(fFileName, "read");213 TFile fileRF(fFileName, "read"); 213 214 if (!fileRF.IsOpen()) 214 215 { … … 218 219 219 220 fEForests.Delete(); 220 221 Int_t i=0;222 221 223 222 TIter Next(fileRF.GetListOfKeys()); … … 230 229 continue; 231 230 232 forest->SetTitle(o->GetTitle()); 233 forest->SetBit(kCanDelete); 234 235 fBinning.Set(i+1); 236 fBinning[i++] = atof(o->GetTitle()); 231 forest->SetUserVal(atof(o->GetName())); 237 232 238 233 fEForests.Add(forest); … … 283 278 // 284 279 // 280 #include <TGraph.h> 281 #include <TF1.h> 285 282 Int_t MRFEnergyEst::Process() 286 283 { 284 static TF1 f1("f1", "gaus"); 285 287 286 TVector event; 288 287 if (fTestMatrix) … … 291 290 *fData >> event; 292 291 293 Double_t eest= 0;294 Double_t hsum= 0;292 Double_t sume = 0; 293 Double_t sumh = 0; 295 294 Double_t maxh = 0; 296 295 Double_t maxe = 0; 297 296 298 Int_t i=0; 297 Double_t max = -1e10; 298 Double_t min = 1e10; 299 300 //TH1C h("", "", fEForests.GetSize(), 0, 1); 299 301 300 302 TIter Next(&fEForests); 301 303 MRanForest *rf = 0; 304 305 TGraph g; 302 306 while ((rf=(MRanForest*)Next())) 303 307 { 304 308 const Double_t h = rf->CalcHadroness(event); 305 const Double_t e = fBinning[i++];306 307 hsum +=h;308 eest += e*h;309 const Double_t e = rf->GetUserVal(); 310 g.SetPoint(g.GetN(), e, h); 311 sume += e*h; 312 sumh += h; 309 313 if (h>maxh) 310 314 { … … 312 316 maxe = e; 313 317 } 318 if (e>max) 319 max = e; 320 if (e<min) 321 min = e; 314 322 } 315 323 … … 317 325 { 318 326 case kMean: 319 fEnergyEst->SetVal(pow(10, eest/hsum));327 fEnergyEst->SetVal(pow(10, sume/sumh)); 320 328 break; 321 329 case kMaximum: 322 330 fEnergyEst->SetVal(pow(10, maxe)); 323 331 break; 332 case kFit: 333 f1.SetParameter(0, maxh); 334 f1.SetParameter(1, maxe); 335 f1.SetParameter(2, 0.125); 336 g.Fit(&f1, "Q0N"); 337 fEnergyEst->SetVal(pow(10, f1.GetParameter(1))); 338 break; 339 324 340 } 325 341 fEnergyEst->SetReadyToSave(); … … 353 369 if (txt==(TString)"maximum") 354 370 fEstimationMode = kMaximum; 371 if (txt==(TString)"fit") 372 fEstimationMode = kFit; 355 373 rc = kTRUE; 356 374 }
Note:
See TracChangeset
for help on using the changeset viewer.