Changeset 8698 for trunk/MagicSoft
- Timestamp:
- 08/23/07 11:26:38 (17 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r8696 r8698 18 18 19 19 -*-*- END OF LINE -*-*- 20 21 22 2007/08/23 Thomas Bretz 23 24 * mhbase/MH3.[h,cc]: 25 - added new data members fBins, allowing to set bins from the outside 26 - removed obsolete SetColors 27 - set palette automatically if it is a 2D histogram (more flexible 28 solution pending) 29 30 * mhbase/MHn.cc: 31 - added comments 32 - allow setting of binning without parlist 33 - added functions to set Scale, Log, AutoRange and Sumw2 34 - delete obsolete pads, if any 35 36 * mjoptim/MJOptimizeBase.h: 37 - added new data meber fTestTasks to be executed only for testing 38 - added comments 39 40 * mjtrain/MJTrainRanForest.cc: 41 - removed obsolete code already in comments 42 43 * mranforest/MRanForestCalc.[h,cc]: 44 - added the possibility to set a function which converts the 45 result of the rf. eg "pow(10, x)" 46 20 47 21 48 -
trunk/MagicSoft/Mars/NEWS
r8689 r8698 26 26 - general: The "Status Display: " was removed from the window title 27 27 within an Eventloop. 28 29 - general: added a new flexible histogram-class (MHn) which can be used 30 for example in testing after optimizations or training to produce 31 user defined histograms. 28 32 29 33 - merpp: Merpp can read file format version 9 now. Please realize -
trunk/MagicSoft/Mars/mhbase/MH3.cc
r8695 r8698 88 88 // Class Version 3: 89 89 // ---------------- 90 // - Byte_t fStyleBits 90 // - Byte_t fStyleBits 91 // + MBinning fBins[3] 91 92 // 92 93 ///////////////////////////////////////////////////////////////////////////// … … 145 146 fData[2] = NULL; 146 147 148 fBins[0] = NULL; 149 fBins[1] = NULL; 150 fBins[2] = NULL; 151 147 152 fName = gsDefName; 148 153 fTitle = gsDefTitle; … … 172 177 fData[1] = NULL; 173 178 fData[2] = NULL; 179 180 fBins[0] = NULL; 181 fBins[1] = NULL; 182 fBins[2] = NULL; 174 183 175 184 fName = gsDefName; … … 197 206 fData[2] = NULL; 198 207 208 fBins[0] = NULL; 209 fBins[1] = NULL; 210 fBins[2] = NULL; 211 199 212 switch (fDimension) 200 213 { … … 233 246 fData[2] = NULL; 234 247 248 fBins[0] = NULL; 249 fBins[1] = NULL; 250 fBins[2] = NULL; 251 235 252 fName = gsDefName; 236 253 fTitle = gsDefTitle; … … 260 277 fData[2] = new MDataPhrase(memberz); 261 278 279 fBins[0] = NULL; 280 fBins[1] = NULL; 281 fBins[2] = NULL; 282 262 283 fName = gsDefName; 263 284 fTitle = gsDefTitle; … … 339 360 { 340 361 case 3: 341 binsz = (MBinning*)plist->FindObject(bz, "MBinning");362 binsz = fBins[2] ? fBins[2] : (MBinning*)plist->FindObject(bz, "MBinning"); 342 363 if (!binsz) 343 364 { … … 354 375 fHist->SetBit(kIsLogz); 355 376 case 2: 356 binsy = (MBinning*)plist->FindObject(by, "MBinning");377 binsy = fBins[1] ? fBins[1] : (MBinning*)plist->FindObject(by, "MBinning"); 357 378 if (!binsy) 358 379 { … … 369 390 fHist->SetBit(kIsLogy); 370 391 case 1: 371 binsx = (MBinning*)plist->FindObject(bx, "MBinning");392 binsx = fBins[0] ? fBins[0] : (MBinning*)plist->FindObject(bx, "MBinning"); 372 393 if (!binsx) 373 394 { … … 507 528 { 508 529 GetRangeX(*fHist, lo, hi); 509 cout << "====> " << GetName() << " " << fHist->GetName() << ": " << lo << " " << hi <<" " << fHist->GetNbinsX() << endl;510 530 fHist->GetXaxis()->SetRange(lo-2, hi+1); 511 531 } … … 525 545 } 526 546 527 // --------------------------------------------------------------------------528 //529 // Setup a inversed deep blue sea palette for the fCenter histogram.530 //531 void MH3::SetColors() const532 {533 // FIXME: This must be redone each time the canvas is repainted....534 gStyle->SetPalette(51, NULL);535 Int_t c[50];536 for (int i=0; i<50; i++)537 c[49-i] = gStyle->GetColorPalette(i);538 gStyle->SetPalette(50, c);539 }540 541 547 void MH3::Paint(Option_t *o) 542 548 { 543 549 TProfile *p=0; 550 551 if (fDimension==2) 552 MH::SetPalette("pretty"); 544 553 545 554 const TString pfx(Form("%sProfX", fHist->GetName())); -
trunk/MagicSoft/Mars/mhbase/MH3.h
r8695 r8698 11 11 class TH1; 12 12 class MData; 13 class MBinning; 13 14 14 15 class MH3 : public MH … … 23 24 TH1 *fHist; // Histogram to fill 24 25 MData *fData[3]; // Object from which the data is filled 26 MBinning *fBins[3]; // Binning set omitting the parlist access 25 27 Double_t fScale[3]; // Scale for the three axis (eg unit) 26 28 Byte_t fStyleBits; // Set the range of a histogram automatically in Finalize … … 58 60 void SetAutoRange(Bool_t x=kTRUE, Bool_t y=kTRUE, Bool_t z=kTRUE) { SetAutoRangeX(x); SetAutoRangeY(y); SetAutoRangeZ(z); } 59 61 62 void SetBinningX(MBinning *x) { fBins[0] = x; } 63 void SetBinningY(MBinning *y) { fBins[1] = y; } 64 void SetBinningZ(MBinning *z) { fBins[2] = z; } 65 void SetBinnings(MBinning *x=0, MBinning *y=0, MBinning *z=0) { SetBinningX(x); SetBinningY(y); SetBinningZ(z); } 66 60 67 void Sumw2() const { if (fHist) fHist->Sumw2(); } 61 68 … … 90 97 void SetTitle(const char *title); 91 98 92 void SetColors() const;93 99 void Draw(Option_t *opt=NULL); 94 100 void Paint(Option_t *opt=""); -
trunk/MagicSoft/Mars/mhbase/MHn.cc
r8697 r8698 27 27 // MHn 28 28 // 29 // +-----------------+ 30 // |1 | 31 // | | 32 // | | 33 // | | 34 // | | 35 // +-----------------+ 36 // 37 // +-----------------+ +--------+--------+ 38 // |1 | |1 |2 | 39 // | | | | | 40 // +-----------------+ | | | 41 // |2 | | | | 42 // | | | | | 43 // +-----------------+ +--------+--------+ 44 // 45 // +--------+--------+ +-----+-----+-----+ 46 // |1 |2 | |1 |3 | 47 // | | | | | | 48 // +--------+--------+ +-----+ + 49 // |3 | | |2 | | 50 // | | | | | | 51 // +--------+--------+ +-----+-----+-----+ 52 // 53 // +--------+--------+ +------+----------+ 54 // |1 |2 | |1 |4 | 55 // | | | +------+ | 56 // +--------+--------+ |2 | | 57 // |3 |4 | +------+ | 58 // | | | |3 | | 59 // +--------+--------+ +------+----------+ 60 // 61 // +-----+-----+-----+ +--------+--------+ 62 // |1 |2 |3 | |1 |2 | 63 // | | | | +--------+--------| 64 // +-----+-----+-----+ |3 |4 | 65 // |4 |5 | | +--------+ | 66 // | | | | |5 | | 67 // +-----+-----+-----+ +--------+--------+ 68 // 69 // +-----+-----+-----+ +--------+--------+ 70 // |1 |2 |3 | |1 |2 | 71 // | | | | +--------+--------+ 72 // +-----+-----+-----+ |3 |4 | 73 // |4 |5 |6 | +--------+--------+ 74 // | | | | |5 |6 | 75 // +-----+-----+-----+ +--------+--------+ 29 // 30 // Initialization 31 // -------------- 32 // 33 // MHn is a histogram class which derives from MH as all Mars histogram 34 // classes do, i.e. to fill the histogram use MFillH. (Example below) 35 // 36 // After instantisation of MHn add the histograms of your interest using 37 // AddHist. Before the next AddHist is called you can now set the options 38 // of your histogram using InitName, InitTitle, SetLog, SetAutoRange, 39 // SetScale and SetDrawOption. 40 // 41 // 42 // Layout 43 // ------ 44 // 45 // The layout of the histograms on the screen depends on the number of 46 // initialized histograms and the option SetLayout. For details see below. 47 // 48 // SetLayout(MHn::kSimple) 49 // < default > SetLayout(MHn::kComplex) 50 // ========================= ========================== 51 // +-----------------+ 52 // |1 | 53 // | | 54 // | | 55 // | | 56 // | | 57 // +-----------------+ 58 // 59 // +-----------------+ +--------+--------+ 60 // |1 | |1 |2 | 61 // | | | | | 62 // +-----------------+ | | | 63 // |2 | | | | 64 // | | | | | 65 // +-----------------+ +--------+--------+ 66 // 67 // +--------+--------+ +-----+-----+-----+ 68 // |1 |2 | |1 |3 | 69 // | | | | | | 70 // +--------+--------+ +-----+ + 71 // |3 | | |2 | | 72 // | | | | | | 73 // +--------+--------+ +-----+-----+-----+ 74 // 75 // +--------+--------+ +------+----------+ 76 // |1 |2 | |1 |4 | 77 // | | | +------+ | 78 // +--------+--------+ |2 | | 79 // |3 |4 | +------+ | 80 // | | | |3 | | 81 // +--------+--------+ +------+----------+ 82 // 83 // +-----+-----+-----+ +--------+--------+ 84 // |1 |2 |3 | |1 |2 | 85 // | | | | +--------+--------| 86 // +-----+-----+-----+ |3 |4 | 87 // |4 |5 | | +--------+ | 88 // | | | | |5 | | 89 // +-----+-----+-----+ +--------+--------+ 90 // 91 // +-----+-----+-----+ +--------+--------+ 92 // |1 |2 |3 | |1 |2 | 93 // | | | | +--------+--------+ 94 // +-----+-----+-----+ |3 |4 | 95 // |4 |5 |6 | +--------+--------+ 96 // | | | | |5 |6 | 97 // +-----+-----+-----+ +--------+--------+ 76 98 // 77 99 // 78 100 // For example: 79 // MHn myhist 80 // ... 101 // ------------ 102 // // Instatiate the MHn class with default name and title 103 // MHn hres("Energy2", "Energy Residual (lg E_{est} - lg E_{mc})"); 104 // 105 // // Initialize your first histogram (here a 2D histogram with x- and y-axis) 106 // hres.AddHist("MMcEvt.fEnergy", "log10(MEnergyEst.fVal)-log10(MMcEvt.fEnergy)"); 107 // // Initialize the name of the histogram (ResEmc) and the title of the 108 // // binnings ((here BinningEnergy for x-axis and BinningEnergyResidual for y-axis) 109 // hres.InitName("ResEmc;Energy;EnergyResidual"); 110 // // Initialize the title of the histogram and the axis titles 111 // hres.InitTitle(";E_{mc} [GeV];\\Delta lg E;"); 112 // // Initialize the draw option for the histogram 113 // hres.SetDrawOption("colz profx"); 114 // // for more details on the options and more options see below 115 // // or the class reference of MH3 116 // 117 // // Initialize a second histogram 118 // hres.AddHist("MPointingPos.fZd", "log10(MEnergyEst.fVal)-log10(MMcEvt.fEnergy)"); 119 // hres.InitName("ResTheta;Theta;EnergyResidual"); 120 // hres.InitTitle(";Zd [\\circ];\\Delta lg E;"); 121 // hres.SetDrawOption("colz profx"); 122 // 123 // // Note that only AddHist is mandatory. All other options can be omitted 124 // 125 // // Initialize the filling task which can now be added to the tasklist 126 // MFillH fill(&hres); 127 // ... 81 128 // 82 129 ///////////////////////////////////////////////////////////////////////////// … … 268 315 269 316 return kTRUE; 317 } 318 319 void MHn::SetScale(Double_t x, Double_t y, Double_t z) const 320 { 321 if (fHist[fNum-1]) 322 fHist[fNum-1]->SetScale(x, y, z); 323 } 324 325 void MHn::SetLog(Bool_t x, Bool_t y, Bool_t z) const 326 { 327 if (fHist[fNum-1]) 328 fHist[fNum-1]->SetLog(x, y, z); 329 } 330 void MHn::SetAutoRange(Bool_t x, Bool_t y, Bool_t z) const 331 { 332 if (fHist[fNum-1]) 333 fHist[fNum-1]->SetAutoRange(x, y, z); 334 } 335 336 void MHn::Sumw2() const 337 { 338 if (fHist[fNum-1]) 339 fHist[fNum-1]->Sumw2(); 340 } 341 342 void MHn::SetBinnings(MBinning *x, MBinning *y, MBinning *z) const 343 { 344 if (fHist[fNum-1]) 345 fHist[fNum-1]->SetBinnings(x, y, z); 270 346 } 271 347 … … 337 413 break; 338 414 case 3: // 3 339 case 4: // 4340 415 pad->Divide(2,2); 416 delete pad->GetPad(4); 417 break; 418 case 4: // 4 419 pad->Divide(2,2); 341 420 break; 342 421 case 5: // 5 422 pad->Divide(3,2); 423 delete pad->GetPad(6); 424 break; 343 425 case 6: // 6 344 426 pad->Divide(3,2); -
trunk/MagicSoft/Mars/mjoptim/MJOptimizeBase.h
r8643 r8698 13 13 protected: 14 14 Int_t fDebug; 15 Bool_t fEnableWeights; 15 Bool_t fEnableWeights; // Enable using weights 16 16 17 TList fRules; 17 TList fRules; // Contains the parameters which can be accessed by matrix column 18 TList fTrainParameters; // Parameters in the last columns 18 19 19 TList fPreCuts; 20 TList fTrainCuts; 21 TList fTestCuts; 22 TList fPreTasks; 23 TList fPostTasks; 20 TList fPreCuts; // Cuts executed for training and testing 21 TList fTrainCuts; // Cuts executed only in training 22 TList fTestCuts; // Cuts executed only in testing 23 TList fPreTasks; // Tasks executed before cut execution 24 TList fPostTasks; // Tasks executed after cut execution 25 TList fTestTasks; // Tasks executed after cut execution for testing 24 26 25 27 void AddCut(TList &l, const char *rule); … … 39 41 void AddPostTask(const char *rule, 40 42 const char *name="MWeight") { AddPar(fPostTasks, rule, name); } 43 44 void AddTestTask(MTask *t) { Add(fTestTasks, t); } 45 void AddTestTask(const char *rule, 46 const char *name="MWeight") { AddPar(fTestTasks, rule, name); } 41 47 42 48 void SetDebug(Bool_t b=kTRUE) { fDebug = b; } -
trunk/MagicSoft/Mars/mjtrain/MJTrainRanForest.cc
r8643 r8698 43 43 #include "MJTrainRanForest.h" 44 44 45 #include <TFile.h>46 47 #include "MLog.h"48 #include "MLogManip.h"49 50 #include "MFDataPhrase.h"51 #include "MParameterCalc.h"52 53 #include "MStatusDisplay.h"54 55 45 ClassImp(MJTrainRanForest); 56 46 57 47 using namespace std; 58 /*59 //------------------------------------------------------------------------60 //61 // Add a cut which is used to fill the matrix, eg "MMcEvt.fPartId<1.5"62 // (The rule is applied, not inverted: The matrix is filled with63 // the events fullfilling the condition)64 //65 void MJTrainRanForest::AddCut(TList &l, const char *rule)66 {67 MFilter *f = new MFDataPhrase(rule);68 f->SetBit(kCanDelete); //FIXME!!!! Why does not any other list delete it???69 Add(l, f);70 }71 72 //------------------------------------------------------------------------73 //74 // Add an additional parameter (MParameterCalc), eg "0.5", "MWeight"75 // The default container name is "MWeight"76 //77 void MJTrainRanForest::AddPar(TList &l, const char *rule, const char *pname)78 {79 TString tname(pname);80 tname += "Calc";81 82 MParameterCalc *par = new MParameterCalc(rule, tname);83 par->SetNameParameter(pname);84 // par->SetBit(kCanDelete); //FIXME!!!! MTaskList is deleting it85 Add(l, par);86 }87 88 //------------------------------------------------------------------------89 //90 // Add a task/cut which is used to fill the matrix. If kCanDelete is set91 // MJOptimize takes the ownership.92 //93 void MJTrainRanForest::Add(TList &l, MTask *f)94 {95 l.Add(f);96 }97 98 //------------------------------------------------------------------------99 //100 // Add a parameter used in your filters (see AddFilter) The parameter101 // index is returned,102 //103 // Int_t idx = AddParameter("log10(MHillas.fSize)");104 //105 // The indices are starting with 0 always.106 //107 Int_t MJTrainRanForest::AddParameter(const char *rule)108 {109 fRules.Add(new TNamed(rule, ""));110 return fRules.GetSize()-1;111 }112 113 Bool_t MJTrainRanForest::WriteDisplay(const char *fname) const114 {115 TFile file(fname, "UPDATE");116 if (!file.IsOpen())117 {118 *fLog << err << "ERROR - Couldn't open file " << fname << " for writing." << endl;119 return kFALSE;120 }121 122 *fLog << inf << "Wrinting to " << fname << ":" << endl;123 *fLog << " - MStatusDisplay..." << flush;124 if (fDisplay && fDisplay->Write()<=0)125 {126 *fLog << err << "Unable to write MStatusDisplay to " << fname << endl;127 return kFALSE;128 }129 *fLog << inf << "ok." << endl;130 131 return kTRUE;132 }133 */ -
trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc
r8646 r8698 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: MRanForestCalc.cc,v 1.2 7 2007-07-26 11:13:00tbretz Exp $2 ! $Name: not supported by cvs2svn $:$Id: MRanForestCalc.cc,v 1.28 2007-08-23 10:25:08 tbretz Exp $ 3 3 ! -------------------------------------------------------------------------- 4 4 ! … … 66 66 67 67 MRanForestCalc::MRanForestCalc(const char *name, const char *title) 68 : fData(0), fRFOut(0), fTestMatrix(0), 68 : fData(0), fRFOut(0), fTestMatrix(0), fFunc("Function", "x"), 69 69 fNumTrees(-1), fNumTry(-1), fNdSize(-1), fNumObsoleteVariables(1), 70 70 fLastDataColumnHasWeights(kFALSE), … … 73 73 fName = name ? name : gsDefName.Data(); 74 74 fTitle = title ? title : gsDefTitle.Data(); 75 76 gROOT->GetListOfFunctions()->Remove(&fFunc); 75 77 76 78 // FIXME: … … 83 85 { 84 86 fEForests.Delete(); 87 } 88 89 // -------------------------------------------------------------------------- 90 // 91 // Set a function which is applied to the output of the random forest 92 // 93 Bool_t MRanForestCalc::SetFunction(const char *func) 94 { 95 return !fFunc.Compile(func); 85 96 } 86 97 … … 291 302 } 292 303 304 if (fileRF.GetListOfKeys()->FindObject("Function")) 305 fFunc.Read("Function"); 306 293 307 return kTRUE; 294 308 } … … 326 340 } 327 341 328 Int_t MRanForestCalc::Process() 342 Double_t MRanForestCalc::Eval() const 329 343 { 330 344 TVector event; … … 338 352 { 339 353 MRanForest *rf = static_cast<MRanForest*>(fEForests.UncheckedAt(0)); 340 fRFOut->SetVal(rf->CalcHadroness(event)); 341 fRFOut->SetReadyToSave(); 342 343 return kTRUE; 354 return rf->CalcHadroness(event); 344 355 } 345 356 … … 383 394 { 384 395 case kMean: 385 fRFOut->SetVal(pow(10, sume/sumh)); 386 break; 396 return sume/sumh; 387 397 case kMaximum: 388 fRFOut->SetVal(pow(10, maxe)); 389 break; 398 return maxe; 390 399 case kFit: 391 400 f1.SetParameter(0, maxh); … … 393 402 f1.SetParameter(2, 0.125); 394 403 g.Fit(&f1, "Q0N"); 395 fRFOut->SetVal(pow(10, f1.GetParameter(1))); 396 break; 397 } 398 404 return f1.GetParameter(1); 405 } 406 407 return 0; 408 } 409 410 Int_t MRanForestCalc::Process() 411 { 412 const Double_t val = Eval(); 413 414 fRFOut->SetVal(fFunc.Eval(val)); 399 415 fRFOut->SetReadyToSave(); 400 416 -
trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h
r7687 r8698 12 12 #ifndef ROOT_TArrayD 13 13 #include <TArrayD.h> 14 #endif 15 16 #ifndef ROOT_TF1 17 #include <TF1.h> 14 18 #endif 15 19 … … 36 40 MParameterD *fRFOut; //! Used to store result 37 41 MHMatrix *fTestMatrix; //! Test Matrix used in Process (together with MMatrixLoop) 42 TF1 fFunc; //! Function to apply to the result 38 43 39 44 TObjArray fEForests; //! List of forests read or to be written … … 60 65 // MRanForestCalc 61 66 Int_t ReadForests(MParList &plist); 67 Double_t Eval() const; 62 68 63 69 // MParContainer … … 84 90 void SetNumTry(UShort_t n=0) { fNumTry = n; } 85 91 void SetDebug(Bool_t b=kTRUE) { fDebug = b; } 92 93 Bool_t SetFunction(const char *name="x"); 86 94 87 95 void SetNumObsoleteVariables(Int_t n=1) { fNumObsoleteVariables = n; }
Note:
See TracChangeset
for help on using the changeset viewer.