Changeset 8644 for trunk/MagicSoft/Mars
- Timestamp:
- 07/24/07 14:36:39 (17 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r8643 r8644 18 18 19 19 -*-*- END OF LINE -*-*- 20 21 2007/07/24 Thomas Bretz 22 23 * mbase/MEvtLoop.cc: 24 - removed the "Status Display" in front of the window name 25 26 * mcalib/MCalibrationChargeCalc.cc: 27 - initialized some more variables in the constructor as suggested 28 by valgrind 29 30 * mjobs/MJCut.cc: 31 - reset number of off-source positions in on-/off-mode to one 32 33 * mjobs/MJob.[h,cc]: 34 - added many comments 35 - simplified the functions for setting a new resource file 36 - replaced some repeated code by new function CombinePath 37 - added new member function HasWritePermission 38 39 * mjoptim/MJOptimize.cc: 40 - set title as window title of eventloop 41 42 * mjoptim/MJOptimizeCuts.cc: 43 - stop if filter is set and it is not MFMagicCuts 44 45 * mjoptim/MJOptimizeCuts.cc, mjoptim/MJOptimizeDisp.cc, 46 mjoptim/MJOptimizeEnergy.cc: 47 - set window title of status display 48 49 * mjtrain/MJTrainDisp.cc, mjtrain/MJTrainEnergy.cc, 50 mjtrain/MJTrainSeparation.cc: 51 - set window title of status display 52 - check for write permission of the output file 53 54 * mjtrain/MJTrainDisp.[h,cc]: 55 - implemented new plots showing the result in a more 56 convinient way 57 - allow to set a different result value than dist 58 59 * mranforest/MRanForest.[h,cc]: 60 - improvement to output when training. Moved code to a 61 new member function 62 63 * mranforest/MRanForestCalc.cc: 64 - set window title of status display 65 66 * mtools/MTFillMatrix.[h,cc]: 67 - implemented setting name and title in the constructor 68 - set window title when wvent loop is started to title 69 20 70 21 71 -
trunk/MagicSoft/Mars/mbase/MEvtLoop.cc
r8642 r8644 240 240 fDisplay->SetNoContextMenu(); 241 241 // Set window and icon name 242 fDisplay->SetWindowName( TString("Status Display: ")+fName);242 fDisplay->SetWindowName(fName); 243 243 fDisplay->SetIconName(fName); 244 244 // Start automatic update -
trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc
r8580 r8644 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: MCalibrationChargeCalc.cc,v 1.18 2 2007-06-18 14:36:16tbretz Exp $2 ! $Name: not supported by cvs2svn $:$Id: MCalibrationChargeCalc.cc,v 1.183 2007-07-24 13:36:35 tbretz Exp $ 3 3 ! -------------------------------------------------------------------------- 4 4 ! … … 302 302 // 303 303 MCalibrationChargeCalc::MCalibrationChargeCalc(const char *name, const char *title) 304 : fGeom(NULL), fSignal(NULL), fCalibPattern(NULL), fExtractor(NULL) 304 : fPulserColor(MCalibrationCam::kNONE), fContinousCalibration(kFALSE), 305 fGeom(NULL), fSignal(NULL), fCalibPattern(NULL), fExtractor(NULL) 305 306 { 306 307 -
trunk/MagicSoft/Mars/mjobs/MJCut.cc
r8636 r8644 553 553 554 554 // -------------------------------------------------------------------------------- 555 556 if (!set.IsWobbleMode() && fNumOffSourcePos!=1) 557 { 558 *fLog << inf << "No wobble mode but NumOffSoucePos!=1 (" << fNumOffSourcePos << ")... reset to 1." << endl; 559 fNumOffSourcePos = 1; 560 } 555 561 556 562 // Possible source position (eg. Wobble Mode) -
trunk/MagicSoft/Mars/mjobs/MJob.cc
r8587 r8644 18 18 ! Author(s): Thomas Bretz, 8/2004 <mailto:tbretz@astro.uni-wuerzburg.de> 19 19 ! 20 ! Copyright: MAGIC Software Development, 2000-200 420 ! Copyright: MAGIC Software Development, 2000-2007 21 21 ! 22 22 ! … … 34 34 // SetDebugEnv(3) // do 2) and debug setting env completely 35 35 // 36 // To allow overwriting the output files call SetOverwrite() 37 // 36 38 ///////////////////////////////////////////////////////////////////////////// 37 39 #include "MJob.h" … … 66 68 } 67 69 70 //------------------------------------------------------------------------ 71 // 72 // If MJob is the owner of fEnv delete fEnv. 73 // 74 // Reset the owenership bit. 75 // 76 // Set fEnv to NULL. 77 // 68 78 void MJob::ClearEnv() 69 79 { … … 74 84 } 75 85 86 //------------------------------------------------------------------------ 87 // 88 // ClearEnv() 89 // 76 90 MJob::~MJob() 77 91 { … … 79 93 } 80 94 81 Bool_t MJob::SetEnv(const char *env, const char *prefix) 82 { 83 ClearEnv(); 84 85 fEnv = new MEnv(env); 86 SetBit(kIsOwner); 87 88 if (!fEnv->IsValid()) 89 { 90 ClearEnv(); 91 return kFALSE; 92 } 93 95 //------------------------------------------------------------------------ 96 // 97 // If prefix==0 the prefix is taken from fName up to the first 98 // whitespace. 99 // 100 // A trailing dot is removed.void MJob::SetPrefix(const char *prefix) 101 void MJob::SetPrefix(const char *prefix) 102 { 94 103 fEnvPrefix = prefix; 104 95 105 if (!prefix) 96 106 fEnvPrefix = fName.First(' ')>0 ? fName(0, fName.First(' ')) : fName; … … 98 108 if (fEnvPrefix.EndsWith(".")) 99 109 fEnvPrefix.Remove(fEnvPrefix.Length()-1); 100 101 return kTRUE; 102 } 103 110 } 111 112 //------------------------------------------------------------------------ 113 // 114 // Create a new MEnv from the file env. MJob takes of course the 115 // ownership of the newly created MEnv. 116 // 117 // SetPrefix(prefix) 118 // 119 // return kFALSE if MEnv is invalid 120 // 121 Bool_t MJob::SetEnv(const char *env, const char *prefix) 122 { 123 SetEnv(new MEnv(env), prefix); 124 125 // Take the owenership of the MEnv instance 126 SetBit(kIsOwner); 127 128 return fEnv->IsValid(); 129 } 130 131 //------------------------------------------------------------------------ 132 // 133 // Set a new fEnv and a new general prefix. 134 // 135 // Calls SetPrefix(prefix) 136 // 137 // MJob does not take the owenership of the MEnv instance. 138 // 104 139 void MJob::SetEnv(MEnv *env, const char *prefix) 105 140 { … … 108 143 fEnv = env; 109 144 110 fEnvPrefix = prefix; 111 if (!prefix) 112 fEnvPrefix = fName.First(' ')>0 ? fName(0, fName.First(' ')) : fName; 113 114 if (fEnvPrefix.EndsWith(".")) 115 fEnvPrefix.Remove(fEnvPrefix.Length()-1); 116 } 117 118 void MJob::FixPath(TString &path) const 145 SetPrefix(prefix); 146 } 147 148 //------------------------------------------------------------------------ 149 // 150 // Removes LF's from the path (necessary if the resource file was written 151 // with a different operating system than Linux. 152 // 153 // Removes a trailing slash if the path is not the root-path. 154 // 155 // Adds fname to the path if given. 156 // 157 void MJob::FixPath(TString &path) 119 158 { 120 159 path.ReplaceAll("\015", ""); … … 127 166 } 128 167 168 //------------------------------------------------------------------------ 169 // 170 // Calls FixPath 171 // 172 // Adds fname to the path if given. 173 // 174 TString MJob::CombinePath(TString path, TString fname) 175 { 176 FixPath(path); 177 178 if (fname.IsNull()) 179 return path; 180 181 if (path!=(TString)"/") 182 path += "/"; 183 184 path += fname; 185 186 return path; 187 } 188 189 //------------------------------------------------------------------------ 190 // 191 // Sets the output path. The exact meaning (could also be a file) is 192 // deined by the derived class. 193 // 129 194 void MJob::SetPathOut(const char *path) 130 195 { … … 133 198 } 134 199 200 //------------------------------------------------------------------------ 201 // 202 // Sets the input path. The exact meaning (could also be a file) is 203 // deined by the derived class. 204 // 135 205 void MJob::SetPathIn(const char *path) 136 206 { … … 139 209 } 140 210 211 //------------------------------------------------------------------------ 212 // 213 // Returns the TEnv 214 // 141 215 const TEnv *MJob::GetEnv() const 142 216 { … … 144 218 } 145 219 220 //------------------------------------------------------------------------ 221 // 222 // Checks GetEnvValue(*fEnv, fEnvPrefix, name, dftl) 223 // For details see MParContainer 224 // 146 225 Int_t MJob::GetEnv(const char *name, Int_t dflt) const 147 226 { … … 149 228 } 150 229 230 //------------------------------------------------------------------------ 231 // 232 // Checks GetEnvValue(*fEnv, fEnvPrefix, name, dftl) 233 // For details see MParContainer 234 // 151 235 Double_t MJob::GetEnv(const char *name, Double_t dflt) const 152 236 { … … 154 238 } 155 239 240 //------------------------------------------------------------------------ 241 // 242 // Checks GetEnvValue(*fEnv, fEnvPrefix, name, dftl) 243 // For details see MParContainer 244 // 156 245 const char *MJob::GetEnv(const char *name, const char *dflt) const 157 246 { … … 159 248 } 160 249 250 //------------------------------------------------------------------------ 251 // 252 // Checks IsEnvDefined(*fEnv, fEnvPrefix, name, fEnvDebug>2) 253 // For details see MParContainer 254 // 161 255 Bool_t MJob::HasEnv(const char *name) const 162 256 { … … 164 258 } 165 259 260 //------------------------------------------------------------------------ 261 // 262 // Check the resource file for 263 // PathOut 264 // PathIn 265 // MaxEvents 266 // Overwrite 267 // EnvDebug 268 // 269 // and call the virtual function CheckEnvLocal 270 // 166 271 Bool_t MJob::CheckEnv() 167 272 { … … 202 307 } 203 308 309 //------------------------------------------------------------------------ 310 // 311 // Call the eventsloops ReadEnv and print untouched resources afterwards 312 // if fEnvDebug>1 313 // 204 314 Bool_t MJob::SetupEnv(MEvtLoop &loop) const 205 315 { … … 214 324 215 325 return kTRUE; 326 } 327 328 //------------------------------------------------------------------------ 329 // 330 // Checks whether write permissions to fname exists including 331 // the fOverwrite data amember. 332 // 333 Bool_t MJob::HasWritePermission(TString fname) const 334 { 335 gSystem->ExpandPathName(fname); 336 337 const Bool_t exists = !gSystem->AccessPathName(fname, kFileExists); 338 if (!exists) 339 return kTRUE; 340 341 const Bool_t write = !gSystem->AccessPathName(fname, kWritePermission); 342 if (!write) 343 { 344 *fLog << err << "ERROR - No permission to write to " << fname << endl; 345 return kFALSE; 346 } 347 348 if (!fOverwrite) 349 return kTRUE; 350 351 *fLog << err; 352 *fLog << "ERROR - File " << fname << " already exists and overwrite not allowed." << endl; 353 354 return kFALSE; 216 355 } 217 356 … … 274 413 //------------------------------------------------------------------------ 275 414 // 276 // Write containers in cont (and - if available) the status display to277 // fPathOut+"/"+name415 // Write containers in cont to fPathOut+"/"+name, or fPathOut only 416 // if name is empty. 278 417 // 279 418 Bool_t MJob::WriteContainer(TCollection &cont, const char *name, const char *option, const int compr) const … … 285 424 } 286 425 287 TString oname(fPathOut); 288 if (!TString(name).IsNull()) 289 { 290 if (oname!="/") 291 oname += "/"; 292 oname += name; 293 } 426 const TString oname = CombinePath(fPathOut, name); 294 427 295 428 *fLog << inf << "Writing to file: " << oname << endl; 296 429 297 TString title("File Written by ");430 TString title("File written by "); 298 431 title += fName; 299 432 … … 308 441 } 309 442 443 //------------------------------------------------------------------------ 444 // 445 // return kTRUE if no display is set. 446 // 447 // Write the display to the TFile with name name, options option and 448 // compression level comp. 449 // 450 // If name IsNull fPathOut is assumed to contain the name, otherwise 451 // name is appended to fPathOut. fPathOut might be null. 452 // 310 453 Bool_t MJob::WriteDisplay(const char *name, const char *option, const int compr) const 311 454 { … … 348 491 349 492 // check if path ends with a slash 350 if (!path.EndsWith("/")) 351 path += "/"; 352 353 // compile full qualified path 354 path += fname; 493 path = CombinePath(path, fname); 355 494 356 495 gLog << dbg << "MJob::ExpandPath - Filename expanded to " << path << endl; … … 360 499 } 361 500 501 //------------------------------------------------------------------------ 502 // 503 // Sorts the array. 504 // 362 505 void MJob::SortArray(TArrayI &arr) 363 506 { -
trunk/MagicSoft/Mars/mjobs/MJob.h
r8518 r8644 14 14 enum { kIsOwner = BIT(14) }; 15 15 16 void FixPath(TString &path) const; 16 // Helper functions for paths 17 static TString CombinePath(TString path, TString fname); 18 static void FixPath(TString &path); 19 20 // Helper functions to set a new fEnv 21 void SetPrefix(const char *prefix); 17 22 void ClearEnv(); 18 23 24 // Data members for resource files 19 25 const MEnv *fEnv; // Resource file 20 26 TString fEnvPrefix; // Prefix for resources … … 28 34 Int_t fMaxEvents; // Maximum number of events 29 35 36 // FIXME: Split into MJobSequence and MJobDataSet 30 37 MSequence fSequence; // Sequence 31 38 … … 71 78 TString GetPathIn() const { return fPathIn; } 72 79 80 Bool_t HasWritePermission(TString fname) const; 81 73 82 // Others 74 83 MStatusDisplay *GetDisplay() { return fDisplay; } -
trunk/MagicSoft/Mars/mjoptim/MJOptimize.cc
r8643 r8644 647 647 648 648 // Setup eventloop 649 MEvtLoop evtloop ;649 MEvtLoop evtloop(fTitle); 650 650 evtloop.SetParList(&parlist); 651 651 evtloop.SetDisplay(fDisplay); // set display for evtloop and all childs … … 734 734 tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime); 735 735 736 MEvtLoop fillloop ;736 MEvtLoop fillloop(fTitle); 737 737 fillloop.SetParList(&parlist); 738 738 fillloop.SetDisplay(fDisplay); -
trunk/MagicSoft/Mars/mjoptim/MJOptimizeCuts.cc
r8374 r8644 85 85 #include "MLog.h" 86 86 #include "MLogManip.h" 87 #include "MStatusDisplay.h" 87 88 88 89 // Eventloop … … 138 139 Bool_t MJOptimizeCuts::RunOnOffCore(MHAlpha &histon, MHAlpha &histof, const char *fname, MFilter *filter, MAlphaFitter *fit, const char *tree) 139 140 { 141 SetTitle(Form("OptimizeCuts: %s", fname)); 142 143 if (fDisplay) 144 fDisplay->SetTitle(fTitle); 145 140 146 fLog->Separator("Preparing On/Off-optimization"); 141 147 … … 162 168 histof.InitMapping(&m, 1); 163 169 164 if (filter && filter->InheritsFrom(MFMagicCuts::Class())) 165 ((MFMagicCuts*)filter)->InitMapping(&m); 170 if (filter) 171 { 172 if (filter->InheritsFrom(MFMagicCuts::Class())) 173 ((MFMagicCuts*)filter)->InitMapping(&m); 174 else 175 { 176 *fLog << err << "ERROR - Currently only MFMagicCuts is supported." << endl; 177 return kFALSE; 178 } 179 } 166 180 167 181 parlist.AddToList(&histon); … … 249 263 Bool_t MJOptimizeCuts::RunOnCore(MHAlpha &hist, const char *fname, MFilter *filter, MAlphaFitter *fit) 250 264 { 265 SetTitle(Form("OptimizeCuts: %s", fname)); 266 267 if (fDisplay) 268 fDisplay->SetTitle(fTitle); 269 251 270 fLog->Separator("Preparing On-only-optimization"); 252 271 -
trunk/MagicSoft/Mars/mjoptim/MJOptimizeDisp.cc
r8636 r8644 60 60 #include "MLog.h" 61 61 #include "MLogManip.h" 62 #include "MStatusDisplay.h" 62 63 63 64 // eventloop … … 97 98 Bool_t MJOptimizeDisp::RunDisp(const char *fname, const char *rule, MTask *weights) 98 99 { 100 SetTitle(Form("OptimizeDisp: %s", fname)); 101 102 if (fDisplay) 103 fDisplay->SetTitle(fTitle); 104 99 105 fLog->Separator("Preparing Disp optimization"); 100 106 -
trunk/MagicSoft/Mars/mjoptim/MJOptimizeEnergy.cc
r8223 r8644 53 53 #include "MLog.h" 54 54 #include "MLogManip.h" 55 #include "MStatusDisplay.h" 55 56 56 57 // eventloop … … 86 87 Bool_t MJOptimizeEnergy::RunEnergy(const char *fname, const char *rule, MTask *weights) 87 88 { 89 SetTitle(Form("OptimizeEnergy: %s", fname)); 90 91 if (fDisplay) 92 fDisplay->SetTitle(fTitle); 93 88 94 fLog->Separator("Preparing Energy optimization"); 89 95 -
trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.cc
r8643 r8644 18 18 ! Author(s): Thomas Bretz 11/2005 <mailto:tbretz@astro.uni-wuerzburg.de> 19 19 ! 20 ! Copyright: MAGIC Software Development, 2005 20 ! Copyright: MAGIC Software Development, 2005-2007 21 21 ! 22 22 ! … … 55 55 #include "MJTrainDisp.h" 56 56 57 #include <TLine.h> 58 #include <TCanvas.h> 59 57 60 #include "MHMatrix.h" 58 61 … … 64 67 #include "MTFillMatrix.h" 65 68 #include "MChisqEval.h" 69 #include "MStatusDisplay.h" 66 70 67 71 // eventloop … … 92 96 using namespace std; 93 97 98 const TString MJTrainDisp::fgTrainParameter = "MHillasSrc.fDist*MGeomCam.fConvMm2Deg"; 99 100 // -------------------------------------------------------------------------- 101 // 102 // Display a result histogram either vs. size or energy 103 // FIXME: Could be moved into a new histogram class. 104 // 105 void MJTrainDisp::DisplayHist(TCanvas &c, Int_t i, MH3 &mh3) const 106 { 107 MH::SetPalette("pretty"); 108 109 TH1 &hist = *(TH1*)mh3.GetHist().Clone(); 110 hist.SetBit(TH1::kNoStats); 111 hist.SetDirectory(0); 112 113 TLine line; 114 line.SetLineStyle(kDashed); 115 line.SetLineWidth(1); 116 117 c.cd(i); 118 gPad->SetBorderMode(0); 119 gPad->SetFrameBorderMode(0); 120 //gPad->SetFillColor(kWhite); 121 gPad->SetLogx(); 122 gPad->SetGridx(); 123 gPad->SetGridy(); 124 //gPad->SetLeftMargin(0.12); 125 //gPad->SetRightMargin(0.12); 126 127 for (int x=0; x<=hist.GetNbinsX(); x++) 128 { 129 Float_t n = 0; 130 for (int y=1; y<=2; y++) 131 n += hist.GetBinContent(x,y); 132 133 if (n==0) 134 continue; 135 136 for (int y=0; y<=hist.GetNbinsY(); y++) 137 hist.SetBinContent(x, y, 200*hist.GetBinContent(x,y)/n); 138 } 139 140 hist.SetMaximum(100); 141 hist.DrawCopy("colz"); 142 143 line.DrawLine(10, 0.04, 31623, 0.04); 144 145 c.cd(i+2); 146 gPad->SetBorderMode(0); 147 gPad->SetFrameBorderMode(0); 148 //gPad->SetFillColor(kWhite); 149 gPad->SetLogx(); 150 gPad->SetGridx(); 151 gPad->SetGridy(); 152 //gPad->SetLeftMargin(0.12); 153 //gPad->SetRightMargin(0.12); 154 155 for (int x=0; x<=hist.GetNbinsX(); x++) 156 { 157 Float_t n = 0; 158 for (int y=0; y<=hist.GetNbinsY(); y++) 159 n += hist.GetBinContent(x,y); 160 161 if (n==0) 162 continue; 163 164 for (int y=0; y<=hist.GetNbinsY(); y++) 165 hist.SetBinContent(x, y, 100*hist.GetBinContent(x,y)/n); 166 } 167 168 hist.SetMaximum(25); 169 hist.DrawCopy("colz"); 170 171 line.DrawLine(10, 0.04, 31623, 0.04); 172 } 173 174 // -------------------------------------------------------------------------- 175 // 176 // Display the result histograms in a new tab. 177 // 178 void MJTrainDisp::DisplayResult(MH3 &hsize, MH3 &henergy) 179 { 180 TCanvas &c = fDisplay->AddTab("Disp"); 181 c.Divide(2,2); 182 183 DisplayHist(c, 1, hsize); 184 DisplayHist(c, 2, henergy); 185 } 186 187 // -------------------------------------------------------------------------- 188 // 189 // Run Disp optimization 190 // 94 191 Bool_t MJTrainDisp::Train(const char *out, const MDataSet &set, Int_t num) 95 192 { 193 SetTitle(Form("TrainDisp: %s", out)); 194 195 if (fDisplay) 196 fDisplay->SetTitle(fTitle); 197 96 198 if (!set.IsValid()) 97 199 { … … 99 201 return kFALSE; 100 202 } 203 204 if (!HasWritePermission(out)) 205 return kFALSE; 101 206 102 207 *fLog << inf; … … 119 224 if (fEnableWeights) 120 225 train.AddColumn("MWeight.fVal"); 121 train.AddColumn("MHillasSrc.fDist*MGeomCam.fConvMm2Deg"); 122 //train.AddColumn("TMath::Hypot(MHillasSrc.fDCA, MHillasSrc.fDist)*MGeomCam.fConvMm2Deg"); 226 train.AddColumn(fgTrainParameter); 123 227 124 228 // ----------------------- Fill Matrix RF ---------------------- 125 MTFillMatrix fill ;229 MTFillMatrix fill(fTitle); 126 230 fill.SetDisplay(fDisplay); 127 231 fill.SetLogStream(fLog); … … 136 240 137 241 // ------------------------ Train RF -------------------------- 138 MRanForestCalc rf ;242 MRanForestCalc rf(fTitle); 139 243 rf.SetNumTrees(fNumTrees); 140 244 rf.SetNdSize(fNdSize); … … 212 316 eval.SetY1("sqrt(ThetaSquared.fVal)"); 213 317 214 MH3 hdisp1("MHillas.fSize", " sqrt(ThetaSquared.fVal)");215 MH3 hdisp2("MMcEvt.fEnergy", " sqrt(ThetaSquared.fVal)");318 MH3 hdisp1("MHillas.fSize", "ThetaSquared.fVal"); 319 MH3 hdisp2("MMcEvt.fEnergy", "ThetaSquared.fVal"); 216 320 hdisp1.SetTitle("\\vartheta distribution vs. Size:Size [phe]:\\vartheta [\\circ]"); 217 321 hdisp2.SetTitle("\\vartheta distribution vs. Energy:Enerhy [GeV]:\\vartheta [\\circ]"); 218 322 219 MBinning binsx( 50, 10, 100000, "BinningMH3X", "log");220 MBinning binsy( 50, 0, 1,"BinningMH3Y", "lin");323 MBinning binsx( 70, 10, 31623, "BinningMH3X", "log"); 324 MBinning binsy( 75, 0, 0.3, "BinningMH3Y", "lin"); 221 325 222 326 plist.AddToList(&binsx); … … 239 343 tlist.AddToList(&eval); 240 344 241 MEvtLoop loop ;345 MEvtLoop loop(fTitle); 242 346 loop.SetLogStream(fLog); 243 347 loop.SetDisplay(fDisplay); 244 348 loop.SetParList(&plist); 349 //if (!SetupEnv(loop)) 350 // return kFALSE; 245 351 246 352 if (!loop.Eventloop()) … … 251 357 hist.GetAlphaFitter().Print("result"); 252 358 253 if (!WriteDisplay(out, "UPDATE")) 359 DisplayResult(hdisp1, hdisp2); 360 361 SetPathOut(out); 362 if (!WriteDisplay(0, "UPDATE")) 254 363 return kFALSE; 255 364 -
trunk/MagicSoft/Mars/mjtrain/MJTrainDisp.h
r7412 r8644 6 6 #endif 7 7 8 class TCanvas; 9 10 class MH3; 8 11 class MDataSet; 9 12 10 13 class MJTrainDisp : public MJTrainRanForest 11 14 { 15 private: 16 static const TString fgTrainParameter; 17 18 TString fTrainParameter; 19 20 void DisplayHist(TCanvas &c, Int_t i, MH3 &mh3) const; 21 void DisplayResult(MH3 &hsize, MH3 &henergy); 22 12 23 public: 13 MJTrainDisp() { } 24 MJTrainDisp() : fTrainParameter(fgTrainParameter) { } 25 26 void SetTrainParameter(const char *txt) { fTrainParameter=txt; } 27 14 28 Bool_t Train(const char *out, const MDataSet &set, Int_t num); 15 29 -
trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc
r8643 r8644 62 62 #include "MDataSet.h" 63 63 #include "MTFillMatrix.h" 64 #include "MStatusDisplay.h" 64 65 65 66 // eventloop … … 86 87 Bool_t MJTrainEnergy::Train(const char *out, const MDataSet &set, Int_t num) 87 88 { 89 SetTitle(Form("TrainEnergy: %s", out)); 90 91 if (fDisplay) 92 fDisplay->SetTitle(fTitle); 93 88 94 if (!set.IsValid()) 89 95 { … … 91 97 return kFALSE; 92 98 } 99 100 if (!HasWritePermission(out)) 101 return kFALSE; 93 102 94 103 *fLog << inf; … … 102 111 103 112 if (!set.AddFilesOn(readtrn)) 104 return kFALSE; 113 { 114 *fLog << err << "ERROR - Adding SequencesOn." << endl; 115 return kFALSE; 116 } 105 117 if (!set.AddFilesOff(readtst)) 106 return kFALSE; 118 { 119 *fLog << err << "ERROR - Adding SequencesOff." << endl; 120 return kFALSE; 121 } 107 122 108 123 // ----------------------- Setup Matrix ------------------ … … 117 132 118 133 // ----------------------- Fill Matrix RF ---------------------- 119 MTFillMatrix fill ;134 MTFillMatrix fill(fTitle); 120 135 fill.SetDisplay(fDisplay); 121 136 fill.SetLogStream(fLog); … … 130 145 131 146 // ------------------------ Train RF -------------------------- 132 MRanForestCalc rf ;147 MRanForestCalc rf(fTitle); 133 148 rf.SetNumTrees(fNumTrees); 134 149 rf.SetNdSize(fNdSize); … … 185 200 tlist.AddToList(&fillh); 186 201 187 MEvtLoop loop ;202 MEvtLoop loop(fTitle); 188 203 loop.SetLogStream(fLog); 189 204 loop.SetDisplay(fDisplay); 190 205 loop.SetParList(&plist); 206 //if (!SetupEnv(loop)) 207 // return kFALSE; 191 208 192 209 if (!loop.Eventloop()) 193 210 return kFALSE; 194 211 195 if (!WriteDisplay(out, "UPDATE")) 212 SetPathOut(out); 213 if (!WriteDisplay(0, "UPDATE")) 196 214 return kFALSE; 197 215 -
trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc
r8643 r8644 589 589 Bool_t MJTrainSeparation::Train(const char *out) 590 590 { 591 if (fDisplay) 592 fDisplay->SetTitle(out); 593 591 594 if (!fDataSetTrain.IsValid()) 592 595 { … … 606 609 } 607 610 608 TStopwatch clock; 611 if (!HasWritePermission(out)) 612 return kFALSE; 613 614 TStopwatch clock; 609 615 clock.Start(); 610 616 … … 939 945 loop.SetLogStream(fLog); 940 946 loop.SetParList(&plist); 947 //if (!SetupEnv(loop)) 948 // return kFALSE; 941 949 942 950 wgt.SetVal(1); … … 1039 1047 1040 1048 // Write the display 1041 if (!WriteDisplay(out, "UPDATE")) 1049 SetPathOut(out); 1050 if (!WriteDisplay(0, "UPDATE")) 1042 1051 return kFALSE; 1043 1052 -
trunk/MagicSoft/Mars/mranforest/MRanForest.cc
r8203 r8644 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: MRanForest.cc,v 1.2 6 2006-11-02 08:57:00tbretz Exp $2 ! $Name: not supported by cvs2svn $:$Id: MRanForest.cc,v 1.27 2007-07-24 13:35:39 tbretz Exp $ 3 3 ! -------------------------------------------------------------------------- 4 4 ! … … 124 124 125 125 fNTimesOutBag = rf.fNTimesOutBag; 126 127 126 } 128 127 … … 435 434 // initialize running output 436 435 437 float minfloat= fHadTrue[TMath::LocMin(fHadTrue.GetSize(),fHadTrue.GetArray())];438 Bool_t calcResolution=(minfloat> 0.001);436 float minfloat=TMath::MinElement(fHadTrue.GetSize(),fHadTrue.GetArray()); 437 Bool_t calcResolution=(minfloat>FLT_MIN); 439 438 440 439 if (fTreeNo==1) … … 443 442 444 443 if(calcResolution) 445 *fLog << "TreeNum BagSize NumNodes TestSize res/% (from oob-data -> overest. of error)" << endl;444 *fLog << "TreeNum BagSize NumNodes TestSize Bias/% var/% res/% (from oob-data)" << endl; 446 445 else 447 *fLog << "TreeNum BagSize NumNodes TestSize rms/% (from oob-data -> overest. of error)" << endl;446 *fLog << "TreeNum BagSize NumNodes TestSize Bias/au var/au rms/au (from oob-data)" << endl; 448 447 // 12345678901234567890123456789012345678901234567890 449 448 } … … 498 497 jinbag,winbag,nclass); 499 498 500 //------------------------------------------------------------------- 501 // error-estimates from out-of-bag data (oob data): 502 // 503 // For a single tree the events not(!) contained in the bootstrap 504 // sample of this tree can be used to obtain estimates for the 505 // classification error of this tree. 506 // If you take a certain event, it is contained in the oob-data of 507 // 1/3 of the trees (see comment to ModifyData). This means that the 508 // classification error determined from oob-data is underestimated, 509 // but can still be taken as upper limit. 499 const Double_t ferr = EstimateError(jinbag, calcResolution); 500 501 fRanTree->SetError(ferr); 502 503 // adding tree to forest 504 AddTree(); 505 506 return fTreeNo<fNumTrees; 507 } 508 509 //------------------------------------------------------------------- 510 // error-estimates from out-of-bag data (oob data): 511 // 512 // For a single tree the events not(!) contained in the bootstrap 513 // sample of this tree can be used to obtain estimates for the 514 // classification error of this tree. 515 // If you take a certain event, it is contained in the oob-data of 516 // 1/3 of the trees (see comment to ModifyData). This means that the 517 // classification error determined from oob-data is underestimated, 518 // but can still be taken as upper limit. 519 // 520 Double_t MRanForest::EstimateError(const MArrayI &jinbag, Bool_t calcResolution) 521 { 522 const Int_t numdata = GetNumData(); 523 510 524 Int_t ninbag = 0; 511 525 for (Int_t ievt=0;ievt<numdata;ievt++) … … 522 536 523 537 Int_t n=0; 524 Float_t ferr=0; 525 526 for (Int_t ievt=0;ievt<numdata;ievt++) 527 { 528 if(fNTimesOutBag[ievt]!=0) 529 { 530 float val = fHadEst[ievt]/float(fNTimesOutBag[ievt])-fHadTrue[ievt]; 531 if(calcResolution) val/=fHadTrue[ievt]; 532 533 ferr += val*val; 534 n++; 535 } 536 } 537 ferr = TMath::Sqrt(ferr/n); 538 539 Double_t sum=0; 540 Double_t sq =0; 541 for (Int_t i=0; i<numdata; i++) 542 { 543 if (fNTimesOutBag[i]==0) 544 continue; 545 546 const Float_t hadest = fHadEst[i]/fNTimesOutBag[i]; 547 548 const Float_t val = calcResolution ? 549 hadest/fHadTrue[i] - 1 : hadest - fHadTrue[i]; 550 551 sum += val; 552 sq += val*val; 553 n++; 554 } 555 556 if (calcResolution) 557 { 558 sum *= 100; 559 sq *= 10000; 560 } 561 562 sum /= n; 563 sq /= n; 564 565 const Double_t var = TMath::Sqrt(sq-sum*sum); 566 const Double_t ferr = TMath::Sqrt(sq); 538 567 539 568 //------------------------------------------------------------------- … … 543 572 *fLog << setw(9) << fRanTree->GetNumEndNodes(); 544 573 *fLog << Form(" %9.1f", 100.*n/numdata); 545 *fLog << Form("%18.2f", ferr*100.); 574 *fLog << Form(" %7.2f", sum); 575 *fLog << Form(" %7.2f", var); 576 *fLog << Form(" %7.2f", ferr); 546 577 *fLog << endl; 547 578 548 fRanTree->SetError(ferr); 549 550 // adding tree to forest 551 AddTree(); 552 553 return fTreeNo<fNumTrees; 579 return ferr; 554 580 } 555 581 -
trunk/MagicSoft/Mars/mranforest/MRanForest.h
r7749 r8644 74 74 Double_t fUserVal; // A user value describing this tree (eg E-mc) 75 75 76 Double_t EstimateError(const MArrayI &jinbag, Bool_t calcResolution); 77 76 78 protected: 77 79 // create and modify (->due to bagging) fDataSort -
trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc
r8203 r8644 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: MRanForestCalc.cc,v 1.2 5 2006-11-02 08:57:00tbretz Exp $2 ! $Name: not supported by cvs2svn $:$Id: MRanForestCalc.cc,v 1.26 2007-07-24 13:35:39 tbretz Exp $ 3 3 ! -------------------------------------------------------------------------- 4 4 ! … … 229 229 tlist.AddToList(&fillh); 230 230 231 MEvtLoop evtloop ;231 MEvtLoop evtloop(fName); 232 232 evtloop.SetParList(&plist); 233 233 evtloop.SetDisplay(fDisplay); -
trunk/MagicSoft/Mars/mtools/MTFillMatrix.cc
r8091 r8644 154 154 } 155 155 156 void MTFillMatrix::Init(const char *name, const char *title) 157 { 158 fName = name ? name : "MFillMatrix"; 159 fTitle = title ? title : "Tool to fill MHMatrix from file"; 160 } 161 162 MTFillMatrix::MTFillMatrix(const char *name, const char *title) 163 : fReference(0), fReader(0), fDestMatrix1(0), fDestMatrix2(0), 164 fNumDestEvents1(0), fNumDestEvents2(0), fWriteFile1(0), fWriteFile2(0) 165 { 166 Init(name, title); 167 } 168 156 169 // -------------------------------------------------------------------------- 157 170 // … … 164 177 // the predefined size, but it is much faster. 165 178 // 166 MTFillMatrix::MTFillMatrix(const MH3 *ref )179 MTFillMatrix::MTFillMatrix(const MH3 *ref, const char *name, const char *title) 167 180 : fReference(0), fReader(0), fDestMatrix1(0), fDestMatrix2(0), 168 181 fNumDestEvents1(0), fNumDestEvents2(0), fWriteFile1(0), fWriteFile2(0) 169 182 { 170 fName = "MFillMatrix"; 171 fTitle = "Tool to fill MHMatrix from file"; 172 183 Init(name, title); 173 184 if (ref) 174 185 fReference = (MH3*)ref->Clone(); -
trunk/MagicSoft/Mars/mtools/MTFillMatrix.h
r7714 r8644 34 34 TList fPostTasks; 35 35 36 void Init(const char *name, const char *title); 37 36 38 void Add(const TList &src, const TClass *cls, TList &dest); 37 39 … … 42 44 43 45 public: 44 MTFillMatrix(const MH3 *ref=NULL); 46 MTFillMatrix(const char *name=0, const char *title=0); 47 MTFillMatrix(const MH3 *ref, const char *name=0, const char *title=0); 45 48 ~MTFillMatrix(); 46 49
Note:
See TracChangeset
for help on using the changeset viewer.