Changeset 7413 for trunk/MagicSoft
- Timestamp:
- 11/21/05 11:09:12 (19 years ago)
- Location:
- trunk/MagicSoft
- Files:
-
- 5 added
- 31 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/tpoint/tpoint0509.txt
r7391 r7413 1 1 Magic Model TPOINT data file 2 2 : ALTAZ 3 #4 # ***** After a refocussing of the mirror *****5 #6 3 7 4 ### 24.9.: tpoints always with the white paper screen … … 11 8 1.742509 57.99808 144.2056 49.02492 0.945 60.71667 0.0005732658 0.007748751 53637.075763 216.1 2.654 12 9 # Hamal, mag=2.00, Zd=5 13 139.6868 83.23968 281.6764 74.22004 2.119444 23.4625 -0.04332626 0.03920611 53637.11646 225.2 2.63510 ##139.6868 83.23968 281.6764 74.22004 2.119444 23.4625 -0.04332626 0.03920611 53637.11646 225.2 2.635 14 11 15 12 # --- 24.09.2005 --- 02:59:09.399 16 13 # Hamal, mag=2.00, Zd=5 17 161.5844 84.46453 303.3778 75.43595 2.119444 23.4625 -0.009743542 0.1953913 53637.124414 225.2 2.66514 ##161.5844 84.46453 303.3778 75.43595 2.119444 23.4625 -0.009743542 0.1953913 53637.124414 225.2 2.665 18 15 # And-51, mag=3.57, Zd=21 19 16 -21.2567 68.112 121.1535 59.26484 1.633333 48.62833 0.02363187 0.04614806 53637.142328 218.1 3.353 … … 24 21 # --- 25.09.2005 --- 03:41:32.305 25 22 # Nothing in the runbook? 26 -35.99076 37.46571 106.0467 28.7287 22.48611 58.41528 0.1168588 0.4782401 53638.153846 0 6.5823 ##-35.99076 37.46571 106.0467 28.7287 22.48611 58.41528 0.1168588 0.4782401 53638.153846 0 6.58 27 24 -38.29146 35.14824 104.1974 26.30449 22.25056 57.04361 0.01046067 0.02796104 53638.15701 220.4 3.97 28 25 ## seems to be wrongly identified … … 76 73 112.9061 44.22773 255.4126 35.24166 7.655 5.225 -0.005348532 0.000207558 53639.239228 215.7 2.556 77 74 75 #################################################################### 76 # Private communication with Adrian: 77 # Als wir Ende September rausfanden, dass die Laser unzuverlaessig 78 # sind, wurde da eine Quick-and-Dirty Kalibration gemacht (da kein 79 # Experte auf La Palma war) 80 #################################################################### 81 -
trunk/MagicSoft/Cosy/tpoint/tpoint0510.txt
r7391 r7413 2 2 : ALTAZ 3 3 4 # 5 # ***** New focussing after collabortaion meeting in Tenerife (19.10.?) ***** 6 # 7 4 8 # --- 25.10.2005 --- 02:11:32.993 9 # Diphda. Magn: 2.04 Zd:59.21 Az:222.64 5 10 -137.4972 30.88874 5.015726 21.99765 0.7263889 -17.98667 -0.03588449 -0.01783158 53668.091354 237.2 2.802 11 # Algenib. Magn:2.83 Zd:45.55 Az:263.21 6 12 -96.64771 44.18443 45.84061 35.33164 0.2205556 15.18361 -0.0004117089 -0.002440412 53668.098033 235.3 3.151 13 # Markab. Magn:2.49 Zd:65.51 Az:273.02 7 14 -87.16777 27.87191 55.32808 19.00867 23.07944 15.20528 -0.008018477 0.009832391 53668.10233 237.3 3.096 15 # Markab. Magn:2.49 Zd:63.7 Az:273.65 8 16 -86.52195 26.6309 55.98938 17.74595 23.07944 15.20528 -0.02510043 -0.001211299 53668.106316 233.3 3.102 17 -
trunk/MagicSoft/Mars/Changelog
r7409 r7413 18 18 19 19 -*-*- END OF LINE -*-*- 20 2005/11/21 Thomas Bretz 21 22 * mjtrain/*, macros/train/*.C: 23 - added new class to train the random forest 24 25 * Makefile: 26 - added mjtrain 27 28 * macros/dohtml.C, macros/rootlogon.C: 29 - added mjoptim and mjtrain 30 31 * mbase/MParList.[h,cc]: 32 - fixed copy constructor (it was crashing due to the 33 non-initialized lists) 34 35 * mhbase/MBinning.[h,cc]: 36 - renamed SetEdges to SetEdgesLin (SetEdges now is just and 37 abbreviation) 38 - added a check for the number of bins to all SetEdges* 39 40 * mhbase/MH3.cc: 41 - enable grid 42 43 * mhbase/MHMatrix.[h,cc]: 44 - new member function Addcolumns taking a TCollection 45 46 * mhist/MHHadronness.cc: 47 - align hadronnes into [0,1] 48 49 * mjobs/MDataSet.[h,cc]: 50 - call SetOwner for fSequencesOn and fSequencesOff 51 - added Copy member function 52 53 * mjobs/MJCut.[h,cc]: 54 - added new TaskEnv "CalcDisp" for a disp estimator 55 56 * mjoptim/MJOptimizeDisp.cc: 57 - fixed typo in a title 58 - added a new histogram showing theta-sq versus size 59 60 * mranforest/MHRanForestGini.[h,cc]: 61 - revised to display more information 62 - exchanged pointers to TGraph by objects 63 64 * mranforest/MRanForest.[h,cc]: 65 - replaced some weired copy of the train matrix by a direct access 66 - revised output 67 - pipe error/resolution to tree 68 69 * mranforest/MRanForestCalc.[h,cc]: 70 - copied code from MRFEnergyEst 71 - allow to set a name for the output container 72 - set numtry to 0 (auto) 73 - set ndsize to 1 (there is no auto mode) 74 - introduced variable for number of obsolete parameters 75 76 * mranforest/MRanTree.h: 77 - new data member to store resolution/error 78 79 * mranforest/Makefile, mranforest/RanForestLinkDef.h: 80 - removed MRFEnergyEst 81 - added MRanForestCalc 82 83 * mtools/MTFillMatrix.[h,cc]: 84 - added the possibility to use PreCuts befre filling the matrix 85 - added ReadEnv 86 87 88 20 89 2005/11/18 Thomas Bretz 21 90 -
trunk/MagicSoft/Mars/Makefile
r7149 r7413 67 67 mjobs \ 68 68 mjoptim \ 69 mjtrain \ 69 70 mtools \ 70 71 mmuon -
trunk/MagicSoft/Mars/NEWS
r7409 r7413 13 13 - general: MTFillMatrix (the class to fill one or two MHMatrix from 14 14 files) now allows adding a pre-cut like in the optimization. E.g. this 15 is useful to perform g/h-separation cuts before training the random forest. 16 17 - general: Updated the random forest classes to support also the 18 regression method implemented by Thomas H. 19 20 - general: added new tutorial macro how to train the random forest 21 for energy estimation (macros/optim/rfenergyest.C) 15 is useful to perform g/h-separation cuts before training the random 16 forest. 17 18 - RanForest: 19 + Updated the random forest classes to support also the 20 regression method implemented by Thomas H. 21 + added new tutorial macro how to train the random forest 22 for energy estimation (macros/optim/rfenergyest.C) 23 + new classes to train the random forest (still in development) 24 mjtrain/MJTrainEnergy, mjtrain/MJTrainDisp, mjtrain/MJTrainSeparation 25 + new tutorial macros for random forest training in macros/train 26 trainenergy.C, traindisp.C, trainseparation.C 27 28 - ganymed: In addition to the Hadronness calculator (CalcHadronness) 29 a new option was implemented to estimate Disp (CalcDisp) 22 30 23 31 - ganymed: Implemented two new options which allow -
trunk/MagicSoft/Mars/ganymed.rc
r7362 r7413 39 39 BinningDist.Raw: 25 0 2 40 40 BinningMaxDist.Raw: 25 0 2 41 42 # ------------------------------------------------------------------------- 43 # Using the starguider for pointing correction. 44 # To switch it off use "MPointingDevCalc.MaxAbsDev: -1" 45 # ------------------------------------------------------------------------- 46 #MPointingDevCalc.MaxAbsDev: 15 47 #MPointingDevCalc.NumMinStars: 8 48 #MPointingDevCalc.NsbLevel: 3.0 49 #MPointingDevCalc.NsbMin: 30 50 #MPointingDevCalc.NsbMax: 60 51 52 # ------------------------------------------------------------------------- 53 # Setup the misfocussing correction 54 # ------------------------------------------------------------------------- 55 #MSrcPosCorrect.Dx: 0 56 #MSrcPosCorrect.Dy: 0 41 57 42 58 # ------------------------------------------------------------------------- … … 83 99 Cut0.Condition: ({0} || {1}) && {2} && {3} && {4} && {5} 84 100 Cut0.0: MImagePar.fNumSatPixelsHG < 1 85 Cut0.1: MHillas.GetArea*(MGeomCam.fConvMm2Deg^2) > (0.00 2*MImagePar.fNumSatPixelsHG) + 0.025101 Cut0.1: MHillas.GetArea*(MGeomCam.fConvMm2Deg^2) > (0.003*MImagePar.fNumSatPixelsHG) + 0.0325 86 102 Cut0.2: MNewImagePar.fNumUsedPixels>5 87 103 Cut0.3: MNewImagePar.fLeakage1 < 0.3 … … 90 106 91 107 # ---------- SETUP FOR ONOFF-MODE ----------- 108 MAlphaFitter.ScaleMin: 0.137 109 MAlphaFitter.ScaleMax: 0.640 92 110 MAlphaFitter.BackgroundFitMin: 0.137 93 MAlphaFitter.BackgroundFitMax: 0.64111 MAlphaFitter.BackgroundFitMax: 1.000 94 112 MAlphaFitter.PolynomOrder: 1 95 MAlphaFitter.ScaleMode: Background113 MAlphaFitter.ScaleMode: OffRegion 96 114 MAlphaFitter.SignalFunction: ThetaSq 97 115 … … 99 117 Cut1.ThetaCut: None 100 118 Cut1.Param0: 1.3245 101 Cut1.Param1: 0. 189102 Cut1.Param2: 0.2 30103 Cut1.Param3: 5. 320104 Cut1.Param4: 0. 100105 Cut1.Param5: -0.0 636119 Cut1.Param1: 0.204 120 Cut1.Param2: 0.228 121 Cut1.Param3: 5.50 122 Cut1.Param4: 0.088 123 Cut1.Param5: -0.07 106 124 Cut1.Param6: 8.2957 107 125 Cut1.Param7: 0.8677 … … 137 155 138 156 # ------------------------------------------------------------------------- 139 # Use this to executa a task (eg to calc hadronness) after energy 140 # before Cut1 157 # Use this to executa a task (eg to calc hadronness) before Cut1 141 158 # ------------------------------------------------------------------------- 142 159 # CalcHadronness: MRanForestCalc 143 # CalcHadronness.File: /home/tbretz/Mars.cvs/RFspot3cmAll.root 160 # CalcHadronness.File: rf-energy.root 161 # CalcHadronness.NameOutput: Hadronness 144 162 # CalcHadronness.Debug: No 163 164 # ------------------------------------------------------------------------- 165 # Use this to executa a task (eg to calc disp) before Cut1 166 # ------------------------------------------------------------------------- 167 # CalcDisp: MRanForestCalc 168 # CalcDisp.File: rf-disp.root 169 # CalcDisp.NameOutput: Disp 170 # CalcDisp.Debug: No 171 # Cut1.CalcDisp: No -
trunk/MagicSoft/Mars/macros/dohtml.C
r7301 r7413 77 77 sourcedir += "mimage:"; 78 78 sourcedir += "mjobs:"; 79 sourcedir += "mjoptim:"; 80 sourcedir += "mjtrain:"; 79 81 sourcedir += "mmain:"; 80 82 sourcedir += "mmc:"; -
trunk/MagicSoft/Mars/macros/rootlogon.C
r5694 r7413 144 144 gInterpreter->AddIncludePath(dir+"mimage"); 145 145 gInterpreter->AddIncludePath(dir+"mjobs"); 146 gInterpreter->AddIncludePath(dir+"mjoptim"); 147 gInterpreter->AddIncludePath(dir+"mjtrain"); 146 148 gInterpreter->AddIncludePath(dir+"mmain"); 147 149 gInterpreter->AddIncludePath(dir+"mmc"); -
trunk/MagicSoft/Mars/mbase/MParList.cc
r6915 r7413 62 62 // -------------------------------------------------------------------------- 63 63 // 64 // default constructor65 64 // creates an empty list 66 65 // 67 MParList::MParList(const char *name, const char *title)66 void MParList::Init(const char *name, const char *title) 68 67 { 69 68 fName = name ? name : gsDefName.Data(); … … 83 82 } 84 83 84 85 // -------------------------------------------------------------------------- 86 // 87 // default constructor 88 // creates an empty list 89 // 90 MParList::MParList(const char *name, const char *title) 91 { 92 Init(name, title); 93 } 94 85 95 // -------------------------------------------------------------------------- 86 96 // … … 90 100 // entries) 91 101 // 92 MParList::MParList(MParList &ts) 93 { 102 MParList::MParList(const MParList &ts, const char *name, const char *title) 103 { 104 Init(name, title); 105 94 106 fContainer->AddAll(ts.fContainer); 95 107 } -
trunk/MagicSoft/Mars/mbase/MParList.h
r4828 r7413 37 37 void StreamPrimitive(ofstream &out) const; 38 38 39 void Init(const char *name, const char *title); 40 39 41 public: 40 42 enum { kDoNotReset = BIT(17), kIsProcessing = BIT(18) }; 41 43 42 44 MParList(const char *name=NULL, const char *title=NULL); 43 MParList( MParList &ts);45 MParList(const MParList &ts, const char *name=NULL, const char *title=NULL); 44 46 45 47 virtual ~MParList(); -
trunk/MagicSoft/Mars/mhbase/MBinning.cc
r7151 r7413 242 242 // lowest <lo> and highest <up> Edge (of your histogram) 243 243 // 244 void MBinning::SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up) 245 { 244 void MBinning::SetEdgesLin(Int_t nbins, Axis_t lo, Axis_t up) 245 { 246 if (nbins<=0) 247 { 248 *fLog << warn << "WARNING - Number of bins cannot be <= 0... reset to 1." << endl; 249 nbins = 1; 250 } 251 252 if (up<lo) 253 { 254 *fLog << warn << "WARNING - Upper edge must be greater than lower edge... exchanging." << endl; 255 256 const Axis_t dummy(lo); 257 lo = up; 258 up = dummy; 259 } 260 246 261 const Double_t binsize = nbins<=0 ? 0 : (up-lo)/nbins; 247 262 fEdges.Set(nbins+1); … … 402 417 // lowest <lo> and highest <up> Edge (of your histogram) 403 418 // 404 void MBinning::SetEdgesLog( const Int_t nbins, constAxis_t lo, Axis_t up)419 void MBinning::SetEdgesLog(Int_t nbins, Axis_t lo, Axis_t up) 405 420 { 406 421 // if (lo==0) ... 422 if (nbins<=0) 423 { 424 *fLog << warn << "WARNING - Number of bins cannot be <= 0... reset to 1." << endl; 425 nbins = 1; 426 } 427 428 if (up<lo) 429 { 430 *fLog << warn << "WARNING - Upper edge must be greater than lower edge... exchanging." << endl; 431 432 const Axis_t dummy(lo); 433 lo = up; 434 up = dummy; 435 } 407 436 408 437 const Double_t binsize = log10(up/lo)/nbins; … … 419 448 // lowest [deg] <lo> and highest [deg] <up> Edge (of your histogram) 420 449 // 421 void MBinning::SetEdgesCos(const Int_t nbins, const Axis_t lo, Axis_t up) 422 { 450 void MBinning::SetEdgesCos(Int_t nbins, Axis_t lo, Axis_t up) 451 { 452 if (nbins<=0) 453 { 454 *fLog << warn << "WARNING - Number of bins cannot be <= 0... reset to 1." << endl; 455 nbins = 1; 456 } 457 458 if (up<lo) 459 { 460 *fLog << warn << "WARNING - Upper edge must be greater than lower edge... exchanging." << endl; 461 462 const Axis_t dummy(lo); 463 lo = up; 464 up = dummy; 465 } 466 423 467 // if (lo==0) ... 424 468 const Axis_t ld = lo/kRad2Deg; … … 436 480 // lowest [deg] <lo> and highest [deg] <up> Edge (of your histogram) 437 481 // 438 void MBinning::SetEdgesASin(const Int_t nbins, Axis_t lo, Axis_t up) 439 { 482 void MBinning::SetEdgesASin(Int_t nbins, Axis_t lo, Axis_t up) 483 { 484 if (nbins<=0) 485 { 486 *fLog << warn << "WARNING - Number of bins cannot be <= 0... reset to 1." << endl; 487 nbins = 1; 488 } 489 490 if (up<lo) 491 { 492 *fLog << warn << "WARNING - Upper edge must be greater than lower edge... exchanging." << endl; 493 494 const Axis_t dummy(lo); 495 lo = up; 496 up = dummy; 497 } 498 440 499 const Double_t binsize = nbins<=0 ? 0 : (up-lo)/nbins; 441 500 fEdges.Set(nbins+1); -
trunk/MagicSoft/Mars/mhbase/MBinning.h
r7142 r7413 62 62 void SetEdges(const MBinning &bins) { SetEdges(bins.fEdges); fType = bins.fType; fTitle = bins.fTitle; } 63 63 void SetEdges(const TH1 &h, const Char_t axis='x'); 64 void SetEdges( const Int_t nbins, const Axis_t lo, Axis_t up);64 void SetEdges(Int_t nbins, const Axis_t lo, const Axis_t up) { SetEdgesLin(nbins, lo, up); } 65 65 void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up, const char *opt); 66 void SetEdgesLog(const Int_t nbins, const Axis_t lo, Axis_t up); 67 void SetEdgesCos(const Int_t nbins, const Axis_t lo, Axis_t up); 68 void SetEdgesASin(const Int_t nbins, Axis_t lo, Axis_t up); 66 void SetEdgesLin(Int_t nbins, Axis_t lo, Axis_t up); 67 void SetEdgesLog(Int_t nbins, Axis_t lo, Axis_t up); 68 void SetEdgesCos(Int_t nbins, Axis_t lo, Axis_t up); 69 void SetEdgesASin(Int_t nbins, Axis_t lo, Axis_t up); 69 70 70 71 Int_t FindLoEdge(Double_t val) const -
trunk/MagicSoft/Mars/mhbase/MH3.cc
r6917 r7413 561 561 TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fHist); 562 562 pad->SetBorderMode(0); 563 pad->SetGridx(); 564 pad->SetGridy(); 563 565 564 566 fHist->SetFillStyle(4000); -
trunk/MagicSoft/Mars/mhbase/MHMatrix.cc
r7399 r7413 209 209 } 210 210 211 void MHMatrix::AddColumns(const TCollection &list) 212 { 213 TIter Next(&list); 214 TObject *obj = 0; 215 while ((obj=Next())) 216 AddColumn(obj->GetName()); 217 } 218 219 211 220 // -------------------------------------------------------------------------- 212 221 // -
trunk/MagicSoft/Mars/mhbase/MHMatrix.h
r7399 r7413 73 73 Int_t AddColumn(const char *name); 74 74 void AddColumns(MDataArray *mat); 75 void AddColumns(const TCollection &list); 75 76 76 77 //MDataArray *GetColumns() { return fData; } -
trunk/MagicSoft/Mars/mhist/MHHadronness.cc
r6890 r7413 209 209 const MParameterD &had = par ? *(MParameterD*)par : *fHadronness; 210 210 211 const Double_t h = had.GetVal();211 const Double_t h = TMath::Min(TMath::Max(had.GetVal(), 0.), 1.); 212 212 213 213 if (TMath::IsNaN(h)) -
trunk/MagicSoft/Mars/mjobs/MDataSet.cc
r7409 r7413 196 196 fName = fname; 197 197 198 fSequencesOn.SetOwner(); 199 fSequencesOff.SetOwner(); 200 198 201 const char *expname = gSystem->ExpandPathName(fname); 199 202 -
trunk/MagicSoft/Mars/mjobs/MDataSet.h
r7380 r7413 54 54 55 55 public: 56 MDataSet( ) : fNumAnalysis((UInt_t)-1) { }56 MDataSet(Int_t num=(UInt_t)-1) : fNumAnalysis(num) { } 57 57 MDataSet(const char *fname, TString sequences="", TString data=""); 58 59 void Copy(TObject &obj) const 60 { 61 MDataSet &ds = (MDataSet&)obj; 62 ds.fNumAnalysis = fNumAnalysis; 63 ds.fNumSequencesOn = fNumSequencesOn; 64 ds.fNumSequencesOff = fNumSequencesOff; 65 ds.fNameSource = fNameSource; 66 ds.fCatalog = fCatalog; 67 ds.fComment = fComment; 68 ds.fIsWobbleMode = fIsWobbleMode; 69 70 TObject *o=0; 71 72 ds.fSequencesOn.Delete(); 73 ds.fSequencesOff.Delete(); 74 75 TIter NextOn(&fSequencesOn); 76 while ((o=NextOn())) 77 ds.fSequencesOn.Add(o->Clone()); 78 79 TIter NextOff(&fSequencesOff); 80 while ((o=NextOff())) 81 ds.fSequencesOff.Add(o->Clone()); 82 } 58 83 59 84 // Getter -
trunk/MagicSoft/Mars/mjobs/MJCut.cc
r7390 r7413 86 86 : fStoreSummary(kFALSE), fStoreResult(kTRUE), fWriteOnly(kFALSE), 87 87 fIsWobble(kFALSE), fIsMonteCarlo(kFALSE), fFullDisplay(kTRUE), 88 fNameHist("MHThetaSq"), fCalcHadronness(0) 88 fNameHist("MHThetaSq"), fCalcHadronness(0), fCalcDisp(0) 89 89 { 90 90 fName = name ? name : "MJCut"; … … 102 102 if (fCalcHadronness) 103 103 delete fCalcHadronness; 104 if (fCalcDisp) 105 delete fCalcDisp; 104 106 } 105 107 … … 160 162 delete fCalcHadronness; 161 163 fCalcHadronness = task ? (MTask*)task->Clone() : 0; 164 } 165 166 // -------------------------------------------------------------------------- 167 // 168 // Setup a task calculating disp. The given task is cloned. 169 // 170 void MJCut::SetDispCalculator(const MTask *task) 171 { 172 if (fCalcDisp) 173 delete fCalcDisp; 174 fCalcDisp = task ? (MTask*)task->Clone() : 0; 162 175 } 163 176 … … 540 553 taskenv2.SetDefault(fCalcHadronness); 541 554 555 MTaskEnv taskenv3("CalcDisp"); 556 taskenv3.SetDefault(fCalcDisp); 557 542 558 MFillH fill1a("MHHillasOffPre [MHHillas]", "MHillas", "FillHillasPre"); 543 559 MFillH fill2a("MHHillasOffPost [MHHillas]", "MHillas", "FillHillasPost"); … … 579 595 //tlist2.AddToList(&taskenv1); 580 596 tlist2.AddToList(&taskenv2); 597 tlist2.AddToList(&taskenv3); 581 598 tlist2.AddToList(&cont0); 582 599 if (write0) -
trunk/MagicSoft/Mars/mjobs/MJCut.h
r7109 r7413 33 33 //MTask *fEstimateEnergy; 34 34 MTask *fCalcHadronness; 35 MTask *fCalcDisp; 35 36 36 37 TString GetOutputFile(UInt_t num) const; … … 68 69 //void SetEnergyEstimator(const MTask *task=0); 69 70 void SetHadronnessCalculator(const MTask *task=0); 71 void SetDispCalculator(const MTask *task=0); 70 72 71 73 ClassDef(MJCut, 0) // Standard program to perform g/h-separation cuts -
trunk/MagicSoft/Mars/mjoptim/MJOptimizeDisp.cc
r7169 r7413 71 71 72 72 // histograms 73 #include "MH3.h" 74 #include "MBinning.h" 73 75 #include "../mhflux/MAlphaFitter.h" 74 76 #include "../mhflux/MHThetaSq.h" … … 91 93 // 92 94 // Read all events from file which do match rules and optimize 93 // energyestimator.95 // disp estimator. 94 96 // 95 97 Bool_t MJOptimizeDisp::RunDisp(const char *fname, const char *rule, MTask *weights) 96 98 { 97 fLog->Separator("Preparing Energyoptimization");99 fLog->Separator("Preparing Disp optimization"); 98 100 99 101 MParList parlist; … … 124 126 const Int_t num1 = m.AddColumn("MHillasSrc.fDist*MGeomCam.fConvMm2Deg"); 125 127 const Int_t num2 = m.AddColumn("MHillasSrc.fAlpha*kDegToRad"); 128 const Int_t num3 = m.AddColumn("MHillas.fSize"); 126 129 127 130 MHThetaSq hist; 128 131 hist.SkipHistTime(); 129 132 hist.SkipHistTheta(); 130 hist.SkipHistEnergy(); 131 hist.InitMapping(&m); 133 //hist.SkipHistEnergy(); 134 //hist.ForceUsingSize(); 135 hist.InitMapping(&m, 1); 132 136 133 137 MFDataMember filter("DataType.fVal", '>', 0.5); … … 171 175 MMatrixLoop loop(&m); 172 176 177 const char *n3 = Form("M[%d]", num3); 178 MH3 hdisp(n3, "sqrt(ThetaSquared.fVal)"); 179 hdisp.SetTitle("\\vartheta^{2} distribution vs. Size:Size [phe]:\\vartheta^{2} [\\circ^{2}]"); 180 181 MBinning binsx(100, 10, 100000, "BinningMH3X", "log"); 182 MBinning binsy(100, 0, 2, "BinningMH3Y", "lin"); 183 184 parlist.AddToList(&binsx); 185 parlist.AddToList(&binsy); 186 187 MFillH fillh2(&hdisp); 188 fillh2.SetDrawOption("blue profx"); 189 173 190 tasklist.AddToList(&loop); 174 191 tasklist.AddToList(&calc1); … … 177 194 tasklist.AddToList(weights); 178 195 tasklist.AddToList(&fill); 196 tasklist.AddToList(&fillh2); 179 197 tasklist.AddToList(&eval); 180 198 -
trunk/MagicSoft/Mars/mranforest/MHRanForestGini.cc
r2296 r7413 43 43 #include "MRanTree.h" 44 44 #include "MRanForest.h" 45 #include "MDataArray.h" 45 46 46 47 #include "MLog.h" … … 57 58 // 58 59 MHRanForestGini::MHRanForestGini(Int_t nbins, const char *name, const char *title) 60 : fRules(0.01, 0.01, 0.99, 0.99) 59 61 { 60 62 // … … 64 66 fTitle = title ? title : "Measure of importance of Random Forest-input parameters"; 65 67 66 fGraphGini = new TGraph; 67 fGraphGini->SetTitle("Importance of RF-input parameters measured by mean Gini decrease"); 68 fGraphGini->SetMarkerStyle(kFullDotSmall); 69 } 70 71 // -------------------------------------------------------------------------- 72 // 73 // Delete the histograms. 74 // 75 MHRanForestGini::~MHRanForestGini() 76 { 77 delete fGraphGini; 68 fGraphGini.SetNameTitle("Gini", "Importance of RF-input parameters measured by mean Gini decrease"); 69 fGraphGini.SetMarkerStyle(kFullDotMedium); 70 71 fGraphError.SetNameTitle("ResErr", "Resolution/Error versus train step"); 72 fGraphError.SetMarkerStyle(kFullDotMedium); 73 74 fGraphNodes.SetNameTitle("Nodes", "Number of nodes versus train step"); 75 fGraphNodes.SetMarkerStyle(kFullDotMedium); 76 77 fRules.SetTextAlign(13); 78 fRules.SetTextSize(0.05); 78 79 } 79 80 … … 104 105 Bool_t MHRanForestGini::Fill(const MParContainer *par, const Stat_t w) 105 106 { 107 MRanTree *t = fRanForest->GetCurTree(); 108 106 109 for (Int_t i=0;i<fRanForest->GetNumDim();i++) 107 fGini[i]+=fRanForest->GetCurTree()->GetGiniDec(i); 110 fGini[i] += t->GetGiniDec(i); 111 112 fGraphError.SetPoint(fGraphError.GetN(), GetNumExecutions(), t->GetError()); 113 fGraphNodes.SetPoint(fGraphError.GetN(), GetNumExecutions(), t->GetNumEndNodes()); 108 114 109 115 return kTRUE; … … 117 123 const Int_t n = fGini.GetSize(); 118 124 119 fGraphGini->Set(n); 120 121 Stat_t max=0; 122 Stat_t min=0; 125 fGraphGini.Set(n); 126 123 127 for (Int_t i=0; i<n; i++) 124 128 { 125 fGini[i] /= fRanForest->GetNumTrees() ;126 fG ini[i] /= fRanForest->GetNumData();127 128 const Stat_t ip = i+1; 129 const Stat_t ig = fGini[i];130 131 if (ig>max) max=ig;132 if (ig<min) min=ig;133 134 fGraphGini->SetPoint(i,ip,ig);135 }136 137 // This is used in root>3.04/? so that SetMaximum/Minimum can succeed138 fGraphGini->GetHistogram();139 140 f GraphGini->SetMaximum(1.05*max);141 fGraphGini->SetMinimum(0.95*min);129 fGini[i] /= fRanForest->GetNumTrees()*fRanForest->GetNumData(); 130 fGraphGini.SetPoint(i, i+1, fGini[i]); 131 } 132 133 fRules.AddText(""); 134 const MDataArray &arr = *fRanForest->GetRules(); 135 int i; 136 for (i=0; i<arr.GetNumEntries(); i++) 137 { 138 TString s; 139 s += i+1; 140 s += ") "; 141 s += arr.GetRule(i); 142 fRules.AddText(s); 143 } 144 for (; i<20; i++) 145 fRules.AddText(""); 142 146 143 147 return kTRUE; … … 150 154 void MHRanForestGini::Draw(Option_t *) 151 155 { 152 if (fGraphGini ->GetN()==0)156 if (fGraphGini.GetN()==0) 153 157 return; 154 158 … … 158 162 AppendPad(""); 159 163 160 fGraphGini->Draw("ALP"); 161 pad->Modified(); 162 pad->Update(); 163 164 TH1 *h = fGraphGini->GetHistogram(); 165 if (!h) 166 return; 167 168 //h->GetXaxis()->SetRangeUser(0, fGini.GetSize()+1); 169 h->SetXTitle("No.of RF-input parameter"); 170 h->SetYTitle("Mean decrease in Gini-index [a.u.]"); 171 172 pad->Modified(); 173 pad->Update(); 174 } 164 pad->Divide(2,2); 165 166 pad->cd(1); 167 gPad->SetBorderMode(0); 168 gPad->SetGridx(); 169 gPad->SetGridy(); 170 fGraphGini.Draw("ALP"); 171 172 TH1 *h = fGraphGini.GetHistogram(); 173 if (h) 174 { 175 h->SetXTitle("No.of RF-input parameter"); 176 h->SetYTitle("Mean decrease in Gini-index [au]"); 177 h->GetXaxis()->SetNdivisions(10); 178 } 179 180 pad->cd(2); 181 gPad->SetBorderMode(0); 182 fGraphError.Draw("ALP"); 183 h = fGraphError.GetHistogram(); 184 if (h) 185 { 186 h->SetXTitle("Train step/Tree number"); 187 h->SetYTitle("Error/Resolution"); 188 } 189 190 pad->cd(3); 191 gPad->SetBorderMode(0); 192 fGraphNodes.Draw("ALP"); 193 h = fGraphNodes.GetHistogram(); 194 if (h) 195 { 196 h->SetXTitle("Train step/Tree number"); 197 h->SetYTitle("Number of end nodes"); 198 } 199 200 pad->cd(4); 201 gPad->SetBorderMode(0); 202 fRules.Draw(); 203 } -
trunk/MagicSoft/Mars/mranforest/MHRanForestGini.h
r2173 r7413 9 9 #include <TArrayF.h> 10 10 #endif 11 #ifndef ROOT_TGraph 12 #include <TGraph.h> 13 #endif 14 #ifndef ROOT_TPaveText 15 #include <TPaveText.h> 16 #endif 11 17 12 class TH1D;13 class TGraph;14 18 class MParList; 15 19 class MRanForest; … … 22 26 23 27 TArrayF fGini; //! 24 TGraph *fGraphGini; //-> 28 29 TGraph fGraphGini; 30 TGraph fGraphError; 31 TGraph fGraphNodes; 32 33 TPaveText fRules; 25 34 26 35 public: 27 36 MHRanForestGini(Int_t nbins=100, const char *name=NULL, const char *title=NULL); 28 ~MHRanForestGini();29 30 TGraph *GetGraphGini() const { return fGraphGini; }31 37 32 38 Bool_t SetupFill(const MParList *plist); -
trunk/MagicSoft/Mars/mranforest/MRanForest.cc
r7409 r7413 166 166 if(grid[i]>=grid[i+1]) 167 167 { 168 *fLog<< inf<<"Grid points must be in increasing order! Ignoring grid."<<endl;168 *fLog<<warn<<"Grid points must be in increasing order! Ignoring grid."<<endl; 169 169 return; 170 170 } … … 225 225 fClass[j] = int(fHadTrue[j]+0.5); 226 226 } 227 228 return;229 227 } 230 228 … … 272 270 Bool_t MRanForest::AddTree(MRanTree *rantree=NULL) 273 271 { 274 fRanTree = rantree ? rantree :fRanTree;272 fRanTree = rantree ? rantree : fRanTree; 275 273 276 274 if (!fRanTree) return kFALSE; … … 287 285 // access matrix, copy last column (target) preliminarily 288 286 // into fHadTrue 289 TMatrix mat_tmp = mat->GetM(); 290 int dim = mat_tmp.GetNcols(); 291 int numdata = mat_tmp.GetNrows(); 292 293 fMatrix=new TMatrix(mat_tmp); 287 fMatrix = new TMatrix(mat->GetM()); 288 289 int dim = fMatrix->GetNcols()-1; 290 int numdata = fMatrix->GetNrows(); 294 291 295 292 fHadTrue.Set(numdata); … … 297 294 298 295 for (Int_t j=0;j<numdata;j++) 299 fHadTrue[j] = (*fMatrix)(j,dim -1);296 fHadTrue[j] = (*fMatrix)(j,dim); 300 297 301 298 // remove last col 302 fMatrix->ResizeTo(numdata,dim-1); 303 dim=fMatrix->GetNcols(); 299 fMatrix->ResizeTo(numdata,dim); 304 300 305 301 //------------------------------------------------------------------- … … 308 304 fClass.Reset(0); 309 305 310 if(fClassify) PrepareClasses(); 306 if (fClassify) 307 PrepareClasses(); 311 308 312 309 //------------------------------------------------------------------- 313 310 // allocating and initializing arrays 314 fHadEst.Set(numdata); fHadEst.Reset(0); 315 fNTimesOutBag.Set(numdata); fNTimesOutBag.Reset(0); 316 fDataSort.Set(dim*numdata); fDataSort.Reset(0); 317 fDataRang.Set(dim*numdata); fDataRang.Reset(0); 311 fHadEst.Set(numdata); 312 fHadEst.Reset(0); 313 314 fNTimesOutBag.Set(numdata); 315 fNTimesOutBag.Reset(0); 316 317 fDataSort.Set(dim*numdata); 318 fDataSort.Reset(0); 319 320 fDataRang.Set(dim*numdata); 321 fDataRang.Reset(0); 318 322 319 323 if(fWeight.GetSize()!=numdata) … … 326 330 //------------------------------------------------------------------- 327 331 // setup rules to be used for classification/regression 328 MDataArray *allrules=(MDataArray*)mat->GetColumns();332 const MDataArray *allrules=(MDataArray*)mat->GetColumns(); 329 333 if(allrules==NULL) 330 334 { … … 333 337 } 334 338 335 fRules=new MDataArray(); fRules->Reset(); 336 TString target_rule; 337 338 for(Int_t i=0;i<dim+1;i++) 339 { 340 MData &data=(*allrules)[i]; 341 if(i<dim) 342 fRules->AddEntry(data.GetRule()); 343 else 344 target_rule=data.GetRule(); 345 } 346 347 *fLog << inf <<endl; 348 *fLog << inf <<"Setting up RF for training on target:"<<endl<<" "<<target_rule.Data()<<endl; 349 *fLog << inf <<"Following rules are used as input to RF:"<<endl; 350 351 for(Int_t i=0;i<dim;i++) 352 { 353 MData &data=(*fRules)[i]; 354 *fLog<<inf<<" "<<i<<") "<<data.GetRule()<<endl<<flush; 355 } 356 357 *fLog << inf <<endl; 339 fRules = new MDataArray(); 340 fRules->Reset(); 341 342 const TString target_rule = (*allrules)[dim]; 343 for (Int_t i=0;i<dim;i++) 344 fRules->AddEntry((*allrules)[i].GetRule()); 345 346 *fLog << inf << endl; 347 *fLog << "Setting up RF for training on target:" << endl; 348 *fLog << " " << target_rule.Data() << endl; 349 *fLog << "Following rules are used as input to RF:" << endl; 350 for (Int_t i=0;i<dim;i++) 351 *fLog << " " << i << ") " << (*fRules)[i].GetRule() << endl; 352 353 *fLog << endl; 358 354 359 355 //------------------------------------------------------------------- 360 356 // prepare (sort) data for fast optimization algorithm 361 if(!CreateDataSort()) return kFALSE; 357 if (!CreateDataSort()) 358 return kFALSE; 362 359 363 360 //------------------------------------------------------------------- 364 361 // access and init tree container 365 362 fRanTree = (MRanTree*)plist->FindCreateObj("MRanTree"); 366 367 363 if(!fRanTree) 368 364 { … … 371 367 } 372 368 369 const Int_t tryest = TMath::Nint(TMath::Sqrt(dim)+0.5); 370 371 *fLog << inf << endl; 372 *fLog << "Following input for the tree growing are used:"<<endl; 373 *fLog << " Number of Trees : "<<fNumTrees<<endl; 374 *fLog << " Number of Trials: "<<(fNumTry==0?tryest:fNumTry)<<(fNumTry==0?" (auto)":"")<<endl; 375 *fLog << " Final Node size : "<<fNdSize<<endl; 376 *fLog << " Using Grid: "<<(fGrid.GetSize()>0?"Yes":"No")<<endl; 377 *fLog << " Number of Events: "<<numdata<<endl; 378 *fLog << " Number of Params: "<<dim<<endl; 379 380 if(fNumTry==0) 381 { 382 fNumTry=tryest; 383 *fLog << inf << endl; 384 *fLog << "Set no. of trials to the recommended value of round("<< TMath::Sqrt(dim) <<") = "; 385 *fLog << fNumTry << endl; 386 387 388 } 389 fRanTree->SetNumTry(fNumTry); 373 390 fRanTree->SetClassify(fClassify); 374 391 fRanTree->SetNdSize(fNdSize); 375 392 376 if(fNumTry==0)377 {378 double ddim = double(dim);379 380 fNumTry=int(sqrt(ddim)+0.5);381 *fLog<<inf<<endl;382 *fLog<<inf<<"Set no. of trials to the recommended value of round("<<sqrt(ddim)<<") = ";383 *fLog<<inf<<fNumTry<<endl;384 385 }386 fRanTree->SetNumTry(fNumTry);387 388 *fLog<<inf<<endl;389 *fLog<<inf<<"Following settings for the tree growing are used:"<<endl;390 *fLog<<inf<<" Number of Trees : "<<fNumTrees<<endl;391 *fLog<<inf<<" Number of Trials: "<<fNumTry<<endl;392 *fLog<<inf<<" Final Node size : "<<fNdSize<<endl;393 394 393 fTreeNo=0; 395 394 … … 415 414 if (fTreeNo==1) 416 415 { 417 *fLog << inf << endl; 418 *fLog << underline; 416 *fLog << inf << endl << underline; 419 417 420 418 if(calcResolution) … … 435 433 TArrayF winbag(numdata); // Initialization includes filling with 0 436 434 437 float square=0; float mean=0; 435 float square=0; 436 float mean=0; 438 437 439 438 for (Int_t n=0; n<numdata; n++) … … 483 482 for (Int_t ievt=0;ievt<numdata;ievt++) 484 483 { 485 if (jinbag[ievt]>0) continue; 484 if (jinbag[ievt]>0) 485 continue; 486 486 487 487 fHadEst[ievt] +=fRanTree->TreeHad((*fMatrix), ievt); … … 491 491 492 492 Int_t n=0; 493 doubleferr=0;493 Float_t ferr=0; 494 494 495 495 for (Int_t ievt=0;ievt<numdata;ievt++) … … 508 508 //------------------------------------------------------------------- 509 509 // give running output 510 *fLog << inf << setw(5) << fTreeNo; 511 *fLog << inf << setw(18) << fRanTree->GetNumEndNodes(); 512 *fLog << inf << Form("%18.2f", ferr*100.); 513 *fLog << inf << endl; 510 *fLog << setw(5) << fTreeNo; 511 *fLog << setw(18) << fRanTree->GetNumEndNodes(); 512 *fLog << Form("%18.2f", ferr*100.); 513 *fLog << endl; 514 515 fRanTree->SetError(ferr); 514 516 515 517 // adding tree to forest -
trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc
r6893 r7413 16 16 ! 17 17 ! 18 ! Author(s): Thomas Hengstebeck 3/2003 <mailto:hengsteb@alwa02.physik.uni-siegen.de> 19 ! 20 ! Copyright: MAGIC Software Development, 2000-2003 18 ! Author(s): Thomas Hengstebeck 2/2005 <mailto:hengsteb@physik.hu-berlin.de> 19 ! Author(s): Thomas Bretz 8/2005 <mailto:tbretz@astro.uni-wuerzburg.de> 20 ! 21 ! Copyright: MAGIC Software Development, 2000-2005 21 22 ! 22 23 ! … … 27 28 // MRanForestCalc 28 29 // 29 // Calculates the hadroness of an event. It calculates a mean value of all30 // classifications by the trees in a previously grown random forest.31 //32 // To use only n trees for your calculation use:33 // MRanForestCalc::SetUseNumTrees(n);34 30 // 35 31 //////////////////////////////////////////////////////////////////////////// … … 38 34 #include <TVector.h> 39 35 40 #include "MHMatrix.h" // must be before MLogManip.h 41 #include "MDataArray.h" 36 #include "MHMatrix.h" 42 37 43 38 #include "MLog.h" 44 39 #include "MLogManip.h" 45 40 41 #include "MData.h" 42 #include "MDataArray.h" 43 44 #include "MRanForest.h" 45 #include "MParameters.h" 46 46 47 #include "MParList.h" 47 48 #include "MRanTree.h" 49 #include "MRanForest.h" 50 51 #include "MParameters.h" 52 48 #include "MTaskList.h" 53 49 #include "MEvtLoop.h" 54 #include "M TaskList.h"50 #include "MRanForestGrow.h" 55 51 #include "MFillH.h" 56 #include "MStatusDisplay.h"57 #include "MRanForestGrow.h"58 #include "MRanForestFill.h"59 60 #include "MWriteRootFile.h"61 #include "MReadTree.h"62 52 63 53 ClassImp(MRanForestCalc); … … 65 55 using namespace std; 66 56 67 static const TString gsDefName = "MRanForestCalc"; 68 static const TString gsDefTitle = "Tree Classification Loop 1/2"; 69 70 // -------------------------------------------------------------------------- 71 // 72 // Setup histograms and the number of distances which are used for 73 // avaraging in CalcDist 74 // 57 const TString MRanForestCalc::gsDefName = "MRanForestCalc"; 58 const TString MRanForestCalc::gsDefTitle = "RF for energy estimation"; 59 60 const TString MRanForestCalc::gsNameOutput = "RanForestOut"; 61 75 62 MRanForestCalc::MRanForestCalc(const char *name, const char *title) 76 : fNum(100), fHadronnessName("MHadronness"), fData(NULL), fRanForest(0), fRanTree(0) 77 { 78 // 79 // set the name and title of this object 80 // 63 : fDebug(kFALSE), fData(0), fRFOut(0), 64 fNumTrees(-1), fNumTry(-1), fNdSize(-1), fNumObsoleteVariables(1), 65 fTestMatrix(0), fEstimationMode(kMean) 66 { 81 67 fName = name ? name : gsDefName.Data(); 82 68 fTitle = title ? title : gsDefTitle.Data(); 83 } 84 85 // -------------------------------------------------------------------------- 86 // 87 // Delete the data chains 88 // 69 70 // FIXME: 71 fNumTrees = 100; //100 72 fNumTry = 0; //3 0 means: in MRanForest estimated best value will be calculated 73 fNdSize = 1; //1 74 } 75 89 76 MRanForestCalc::~MRanForestCalc() 90 77 { 91 if (!IsOwner()) 92 return; 93 94 delete fRanForest; 95 delete fRanTree; 96 } 97 98 // -------------------------------------------------------------------------- 99 // 100 // Needs: 101 // - MatrixGammas [MHMatrix] 102 // - MatrixHadrons [MHMatrix] 103 // - MHadronness 104 // - all data containers used to build the matrixes 105 // 106 // The matrix object can be filles using MFillH. And must be of the same 107 // number of columns (with the same meaning). 108 // 78 fEForests.Delete(); 79 } 80 81 Int_t MRanForestCalc::Train(const MHMatrix &matrixtrain, const TArrayD &grid, Int_t ver) 82 { 83 gLog.Separator("MRanForestCalc - Train"); 84 85 if (!matrixtrain.GetColumns()) 86 { 87 *fLog << err << "ERROR - MHMatrix does not contain rules... abort." << endl; 88 return kFALSE; 89 } 90 91 const Int_t ncols = matrixtrain.GetM().GetNcols(); 92 const Int_t nrows = matrixtrain.GetM().GetNrows(); 93 if (ncols<=0 || nrows <=0) 94 { 95 *fLog << err << "ERROR - No. of columns or no. of rows of matrixtrain equal 0 ... abort." << endl; 96 return kFALSE; 97 } 98 99 // rules (= combination of image par) to be used for energy estimation 100 TFile fileRF(fFileName, "recreate"); 101 if (!fileRF.IsOpen()) 102 { 103 *fLog << err << "ERROR - File to store RFs could not be opened... abort." << endl; 104 return kFALSE; 105 } 106 107 const Int_t nobs = fNumObsoleteVariables; // Number of obsolete columns 108 109 const MDataArray &dcol = *matrixtrain.GetColumns(); 110 111 MDataArray usedrules; 112 for (Int_t i=0; i<ncols; i++) 113 if (i<ncols-nobs) // -3 is important!!! 114 usedrules.AddEntry(dcol[i].GetRule()); 115 else 116 *fLog << inf << "Skipping " << dcol[i].GetRule() << " for training" << endl; 117 118 MDataArray rules(usedrules); 119 rules.AddEntry(ver<2?"Classification":dcol[ncols-1].GetRule()); 120 121 // prepare matrix for current energy bin 122 TMatrix mat(matrixtrain.GetM()); 123 124 // last column must be removed (true energy col.) 125 mat.ResizeTo(nrows, ncols-nobs+1); 126 127 if (fDebug) 128 gLog.SetNullOutput(kTRUE); 129 130 const Int_t nbins = ver>0 ? 1 : grid.GetSize()-1; 131 for (Int_t ie=0; ie<nbins; ie++) 132 { 133 switch (ver) 134 { 135 case 0: // Replace Energy Grid by classification 136 { 137 Int_t irows=0; 138 for (Int_t j=0; j<nrows; j++) 139 { 140 const Double_t energy = matrixtrain.GetM()(j,ncols-1); 141 const Bool_t inside = energy>grid[ie] && energy<=grid[ie+1]; 142 143 mat(j, ncols-nobs) = inside ? 1 : 0; 144 145 if (inside) 146 irows++; 147 } 148 if (irows==0) 149 *fLog << warn << "WARNING - Skipping"; 150 else 151 *fLog << inf << "Training RF for"; 152 153 *fLog << " energy bin " << ie << " (" << grid[ie] << ", " << grid[ie+1] << ") " << irows << "/" << nrows << endl; 154 155 if (irows==0) 156 continue; 157 } 158 break; 159 160 case 1: // Use Energy as classifier 161 case 2: 162 for (Int_t j=0; j<nrows; j++) 163 mat(j, ncols-nobs) = matrixtrain.GetM()(j,ncols-1); 164 break; 165 } 166 167 MHMatrix matrix(mat, &rules, "MatrixTrain"); 168 169 MParList plist; 170 MTaskList tlist; 171 plist.AddToList(&tlist); 172 plist.AddToList(&matrix); 173 174 MRanForest rf; 175 rf.SetNumTrees(fNumTrees); 176 rf.SetNumTry(fNumTry); 177 rf.SetNdSize(fNdSize); 178 rf.SetClassify(ver<2 ? 1 : 0); 179 if (ver==1) 180 rf.SetGrid(grid); 181 182 plist.AddToList(&rf); 183 184 MRanForestGrow rfgrow; 185 tlist.AddToList(&rfgrow); 186 187 MFillH fillh("MHRanForestGini"); 188 tlist.AddToList(&fillh); 189 190 MEvtLoop evtloop; 191 evtloop.SetParList(&plist); 192 evtloop.SetDisplay(fDisplay); 193 evtloop.SetLogStream(fLog); 194 195 if (!evtloop.Eventloop()) 196 return kFALSE; 197 198 if (fDebug) 199 gLog.SetNullOutput(kFALSE); 200 201 if (ver==0) 202 { 203 // Calculate bin center 204 const Double_t E = (TMath::Log10(grid[ie])+TMath::Log10(grid[ie+1]))/2; 205 206 // save whole forest 207 rf.SetUserVal(E); 208 rf.SetName(Form("%.10f", E)); 209 } 210 211 rf.Write(); 212 } 213 214 // save rules 215 usedrules.Write("rules"); 216 217 return kTRUE; 218 } 219 220 Int_t MRanForestCalc::ReadForests(MParList &plist) 221 { 222 TFile fileRF(fFileName, "read"); 223 if (!fileRF.IsOpen()) 224 { 225 *fLog << err << dbginf << "File containing RFs could not be opened... aborting." << endl; 226 return kFALSE; 227 } 228 229 fEForests.Delete(); 230 231 TIter Next(fileRF.GetListOfKeys()); 232 TObject *o=0; 233 while ((o=Next())) 234 { 235 MRanForest *forest=0; 236 fileRF.GetObject(o->GetName(), forest); 237 if (!forest) 238 continue; 239 240 forest->SetUserVal(atof(o->GetName())); 241 242 fEForests.Add(forest); 243 } 244 245 // Maybe fEForests[0].fRules yould be used instead? 246 247 if (fData->Read("rules")<=0) 248 { 249 *fLog << err << "ERROR - Reading 'rules' from file " << fFileName << endl; 250 return kFALSE; 251 } 252 253 return kTRUE; 254 } 255 109 256 Int_t MRanForestCalc::PreProcess(MParList *plist) 110 257 { 111 if (!fRanForest) 112 { 113 fRanForest = (MRanForest*)plist->FindObject("MRanForest"); 114 if (!fRanForest) 258 fRFOut = (MParameterD*)plist->FindCreateObj("MParameterD", fNameOutput); 259 if (!fRFOut) 260 return kFALSE; 261 262 fData = (MDataArray*)plist->FindCreateObj("MDataArray"); 263 if (!fData) 264 return kFALSE; 265 266 if (!ReadForests(*plist)) 267 { 268 *fLog << err << "Reading RFs failed... aborting." << endl; 269 return kFALSE; 270 } 271 272 *fLog << inf << "RF read from " << fFileName << endl; 273 274 if (fTestMatrix) 275 return kTRUE; 276 277 fData->Print(); 278 279 if (!fData->PreProcess(plist)) 280 { 281 *fLog << err << "PreProcessing of the MDataArray failed... aborting." << endl; 282 return kFALSE; 283 } 284 285 return kTRUE; 286 } 287 288 #include <TGraph.h> 289 #include <TF1.h> 290 Int_t MRanForestCalc::Process() 291 { 292 TVector event; 293 if (fTestMatrix) 294 *fTestMatrix >> event; 295 else 296 *fData >> event; 297 298 // --------------- Single Tree RF ------------------- 299 if (fEForests.GetEntries()==1) 300 { 301 MRanForest *rf = (MRanForest*)fEForests[0]; 302 fRFOut->SetVal(rf->CalcHadroness(event)); 303 fRFOut->SetReadyToSave(); 304 305 return kTRUE; 306 } 307 308 // --------------- Multi Tree RF ------------------- 309 static TF1 f1("f1", "gaus"); 310 311 Double_t sume = 0; 312 Double_t sumh = 0; 313 Double_t maxh = 0; 314 Double_t maxe = 0; 315 316 Double_t max = -1e10; 317 Double_t min = 1e10; 318 319 TIter Next(&fEForests); 320 MRanForest *rf = 0; 321 322 TGraph g; 323 while ((rf=(MRanForest*)Next())) 324 { 325 const Double_t h = rf->CalcHadroness(event); 326 const Double_t e = rf->GetUserVal(); 327 328 g.SetPoint(g.GetN(), e, h); 329 330 sume += e*h; 331 sumh += h; 332 333 if (h>maxh) 115 334 { 116 *fLog << err << dbginf << "MRanForest not found... aborting." << endl;117 return kFALSE;335 maxh = h; 336 maxe = e; 118 337 } 119 } 120 121 if (!fRanTree) 122 { 123 fRanTree = (MRanTree*)plist->FindObject("MRanTree"); 124 if (!fRanTree) 125 { 126 *fLog << err << dbginf << "MRanTree not found... aborting." << endl; 127 return kFALSE; 128 } 129 } 130 131 fData = fRanTree->GetRules(); 132 133 if (!fData) 134 { 135 *fLog << err << dbginf << "Error matrix doesn't contain columns... aborting." << endl; 136 return kFALSE; 137 } 138 139 if (!fData->PreProcess(plist)) 140 { 141 *fLog << err << dbginf << "PreProcessing of the MDataArray failed for the columns failed... aborting." << endl; 142 return kFALSE; 143 } 144 145 fHadroness = (MParameterD*)plist->FindCreateObj("MParameterD", fHadronnessName); 146 if (!fHadroness) 147 return kFALSE; 338 if (e>max) 339 max = e; 340 if (e<min) 341 min = e; 342 } 343 344 switch (fEstimationMode) 345 { 346 case kMean: 347 fRFOut->SetVal(pow(10, sume/sumh)); 348 break; 349 case kMaximum: 350 fRFOut->SetVal(pow(10, maxe)); 351 break; 352 case kFit: 353 f1.SetParameter(0, maxh); 354 f1.SetParameter(1, maxe); 355 f1.SetParameter(2, 0.125); 356 g.Fit(&f1, "Q0N"); 357 fRFOut->SetVal(pow(10, f1.GetParameter(1))); 358 break; 359 } 360 361 fRFOut->SetReadyToSave(); 148 362 149 363 return kTRUE; … … 153 367 // 154 368 // 155 Int_t MRanForestCalc::Process()156 {157 // first copy the data from the data array to a vector event158 TVector event;159 *fData >> event;160 161 Double_t hadroness=fRanForest->CalcHadroness(event);162 fHadroness->SetVal(hadroness);163 164 return kTRUE;165 }166 167 Bool_t MRanForestCalc::Grow(MHMatrix *matrixg,MHMatrix *matrixh,Int_t ntree,168 Int_t numtry,Int_t ndsize,const char* treefile,169 const char* treename,const char* contname,170 const char* hgininame)171 {172 173 treename = treename ? treename : "Tree";174 contname = contname ? contname : "MRanTree";175 hgininame = hgininame ? hgininame : "MHRanForestGini";176 177 if (!matrixg->IsValid())178 {179 *fLog << err << dbginf << " MRanForestCalc::Grow - ERROR: matrixg not valid." << endl;180 return kFALSE;181 }182 if(!matrixh->IsValid())183 {184 *fLog << err << dbginf << " MRanForestCalc::Grow - ERROR: matrixh not valid." << endl;185 return kFALSE;186 }187 188 MEvtLoop run(GetName());189 MTaskList tlist;190 MParList plist;191 plist.AddToList(&tlist);192 plist.AddToList(matrixg);193 plist.AddToList(matrixh);194 195 // creating training task and setting parameters196 MRanForestGrow rfgrow;197 rfgrow.SetNumTrees(ntree); // number of trees198 rfgrow.SetNumTry(numtry); // number of trials in random split selection199 rfgrow.SetNdSize(ndsize); // limit for nodesize200 tlist.AddToList(&rfgrow);201 202 if(treefile){203 MWriteRootFile rfwrite(treefile);204 rfwrite.AddContainer(contname,treename);205 tlist.AddToList(&rfwrite);206 }207 208 MFillH fillh(hgininame);209 tlist.AddToList(&fillh);210 211 run.SetParList(&plist);212 213 // Execute tree growing214 if (!run.Eventloop())215 {216 *fLog << err << dbginf << "Evtloop in MRanForestCalc::Grow failed." << endl;217 return kFALSE;218 }219 tlist.PrintStatistics(0, kTRUE);220 221 if (TestBit(kEnableGraphicalOutput))222 plist.FindObject(hgininame)->DrawClone();223 224 return kTRUE;225 }226 227 Bool_t MRanForestCalc::Fill(Int_t ntree,const char* treefile,const char* treename)228 {229 treefile = treefile ? treefile : "RF.root";230 treename = treename ? treename : "Tree";231 232 MParList plist;233 234 MTaskList tlist;235 plist.AddToList(&tlist);236 237 MReadTree read(treename,treefile);238 read.DisableAutoScheme();239 240 MRanForestFill rffill;241 rffill.SetNumTrees(ntree);242 243 tlist.AddToList(&read);244 tlist.AddToList(&rffill);245 246 MEvtLoop run(GetName());247 run.SetParList(&plist);248 249 //250 // Execute tree reading251 //252 if (!run.Eventloop())253 {254 *fLog << err << dbginf << "Evtloop in MRanForestCalc::Fill failed." << endl;255 return kFALSE;256 }257 tlist.PrintStatistics(0, kTRUE);258 259 return kTRUE;260 }261 262 369 Int_t MRanForestCalc::ReadEnv(const TEnv &env, TString prefix, Bool_t print) 263 370 { 264 if (!IsEnvDefined(env, prefix, "File", print)) 265 return kFALSE; 266 267 TString fname = GetEnvValue(env, prefix, "File", "RF.root"); 268 TString tname = GetEnvValue(env, prefix, "Tree", "Tree"); 269 const Int_t num = GetEnvValue(env, prefix, "NumTrees", 100); 270 const Bool_t debug = GetEnvValue(env, prefix, "Debug", kFALSE); 271 272 fname.ReplaceAll("\015", ""); 273 tname.ReplaceAll("\015", ""); 274 275 *fLog << inf << dbginf << "Reading " << num << " trees " << tname << " from file " << fname << endl; 276 277 gLog.SetNullOutput(!debug); 278 MEvtLoop evtloop; 279 MParList plist; 280 evtloop.SetParList(&plist); 281 MLog l; 282 l.SetNullOutput(!debug); 283 evtloop.SetLogStream(&l); 284 gLog.SetNullOutput(debug); 285 286 if (IsOwner()) 287 { 288 delete fRanForest; 289 delete fRanTree; 290 } 291 fRanForest = new MRanForest; 292 fRanTree = new MRanTree; 293 SetOwner(); 294 295 plist.AddToList(fRanForest); 296 plist.AddToList(fRanTree); 297 298 MTaskList tlist; 299 plist.AddToList(&tlist); 300 301 MReadTree read(tname, fname); 302 read.DisableAutoScheme(); 303 304 MRanForestFill rffill; 305 rffill.SetNumTrees(num); 306 307 tlist.AddToList(&read); 308 tlist.AddToList(&rffill); 309 310 if (!evtloop.Eventloop()) 311 { 312 *fLog << err << "ERROR - Reading " << tname << " from file " << fname << endl; 313 return kERROR; 314 } 315 316 return kTRUE; 317 } 371 Bool_t rc = kFALSE; 372 if (IsEnvDefined(env, prefix, "FileName", print)) 373 { 374 rc = kTRUE; 375 SetFileName(GetEnvValue(env, prefix, "FileName", fFileName)); 376 } 377 if (IsEnvDefined(env, prefix, "Debug", print)) 378 { 379 rc = kTRUE; 380 SetDebug(GetEnvValue(env, prefix, "Debug", fDebug)); 381 } 382 if (IsEnvDefined(env, prefix, "NameOutput", print)) 383 { 384 rc = kTRUE; 385 SetNameOutput(GetEnvValue(env, prefix, "NameOutput", fNameOutput)); 386 } 387 if (IsEnvDefined(env, prefix, "EstimationMode", print)) 388 { 389 TString txt = GetEnvValue(env, prefix, "EstimationMode", ""); 390 txt = txt.Strip(TString::kBoth); 391 txt.ToLower(); 392 if (txt==(TString)"mean") 393 fEstimationMode = kMean; 394 if (txt==(TString)"maximum") 395 fEstimationMode = kMaximum; 396 if (txt==(TString)"fit") 397 fEstimationMode = kFit; 398 rc = kTRUE; 399 } 400 return rc; 401 } -
trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h
r6893 r7413 6 6 #endif 7 7 8 #ifndef MARS_MHMatrix9 #include "MHMatrix.h"8 #ifndef ROOT_TObjArray 9 #include <TObjArray.h> 10 10 #endif 11 11 12 class MParList; 12 #ifndef ROOT_TArrayD 13 #include <TArrayD.h> 14 #endif 15 16 class MDataArray; 13 17 class MParameterD; 14 class MDataArray; 15 class MRanTree; 16 class MRanForest; 18 class MHMatrix; 17 19 18 20 class MRanForestCalc : public MTask 19 21 { 22 public: 23 enum EstimationMode_t 24 { 25 kMean, 26 kMaximum, 27 kFit 28 }; 29 20 30 private: 21 Int_t fNum; // number of trees used to compute hadronness 31 static const TString gsDefName; //! Default Name 32 static const TString gsDefTitle; //! Default Title 33 static const TString gsNameOutput; //! Default Output name 22 34 23 TString fHadronnessName; // Name of container storing hadronness35 Bool_t fDebug; // Debugging of eventloop while training on/off 24 36 25 MParameterD *fHadroness; //! Output container for calculated hadroness 37 TString fFileName; // File name to forest 38 TObjArray fEForests; // List of forests 39 40 TString fNameOutput; // Name of output container 41 26 42 MDataArray *fData; //! Used to store the MDataChains to get the event values 27 MRanForest *fRanForest; 28 MRanTree *fRanTree; 43 MParameterD *fRFOut; //! Used to store result 29 44 45 Int_t fNumTrees; //! Training parameters 46 Int_t fNumTry; //! Training parameters 47 Int_t fNdSize; //! Training parameters 48 49 Int_t fNumObsoleteVariables; 50 51 MHMatrix *fTestMatrix; //! Test Matrix used in Process (together with MMatrixLoop) 52 53 EstimationMode_t fEstimationMode; 54 55 private: 56 // MTask 30 57 Int_t PreProcess(MParList *plist); 31 58 Int_t Process(); 32 59 33 enum { kIsOwner = BIT(14) }; 60 // MRanForestCalc 61 Int_t ReadForests(MParList &plist); 34 62 35 Bool_t IsOwner() const { return TestBit(kIsOwner); } 36 void SetOwner() { SetBit(kIsOwner); } 63 // MParContainer 64 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print); 65 66 // Train Interface 67 Int_t Train(const MHMatrix &n, const TArrayD &grid, Int_t ver=2); 37 68 38 69 public: … … 40 71 ~MRanForestCalc(); 41 72 42 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print); 73 // Setter for estimation 74 void SetFileName(TString filename) { fFileName = filename; } 75 void SetEstimationMode(EstimationMode_t op) { fEstimationMode = op; } 76 void SetNameOutput(TString name=gsNameOutput) { fNameOutput = name; } 43 77 44 void SetHadronnessName(const TString name) { fHadronnessName = name; } 45 TString GetHadronnessName() const { return fHadronnessName; } 78 // Setter for training 79 void SetNumTrees(UShort_t n=100) { fNumTrees = n; } 80 void SetNdSize(UShort_t n=5) { fNdSize = n; } 81 void SetNumTry(UShort_t n=0) { fNumTry = n; } 82 void SetDebug(Bool_t b=kTRUE) { fDebug = b; } 46 83 47 void Set UseNumTrees(UShort_t n=100) { fNum= n; }84 void SetNumObsoleteVariables(Int_t n=1) { fNumObsoleteVariables = n; } 48 85 49 Bool_t Grow(MHMatrix *matrixg,MHMatrix *matrixh,Int_t ntree, 50 Int_t numtry,Int_t ndsize,const char* treefile=0, 51 const char* treename=0,const char* contname=0, 52 const char* hgininame=0); 86 // Train Interface 87 Int_t TrainMultiRF(const MHMatrix &n, const TArrayD &grid) 88 { 89 return Train(n, grid, 0); 90 } 91 Int_t TrainSingleRF(const MHMatrix &n, const TArrayD &grid=TArrayD()) 92 { 93 return Train(n, grid, grid.GetSize()==0 ? 2 : 1); 94 } 53 95 54 Bool_t Fill(Int_t ntree,const char* treefile=0,const char* treename=0); 96 // Test Interface 97 void SetTestMatrix(MHMatrix *m=0) { fTestMatrix=m; } 98 void InitMapping(MHMatrix *m=0) { fTestMatrix=m; } 55 99 56 57 ClassDef(MRanForestCalc, 0) // Task 100 ClassDef(MRanForestCalc, 0) // Task to calculate RF output and for RF training 58 101 }; 59 102 -
trunk/MagicSoft/Mars/mranforest/MRanTree.h
r7396 r7413 28 28 Int_t fNumNodes; 29 29 Int_t fNumEndNodes; 30 Float_t fError; 30 31 31 32 TArrayI fBestVar; … … 70 71 void SetNdSize(Int_t n); 71 72 void SetNumTry(Int_t n); 73 void SetError(Float_t f) { fError = f; } 72 74 73 75 Int_t GetNdSize() const { return fNdSize; } … … 75 77 Int_t GetNumNodes() const { return fNumNodes; } 76 78 Int_t GetNumEndNodes() const { return fNumEndNodes; } 79 Float_t GetError() const { return fError; } 77 80 78 81 Int_t GetBestVar(Int_t i) const { return fBestVar.At(i); } -
trunk/MagicSoft/Mars/mranforest/Makefile
r7396 r7413 25 25 MRanForest.cc \ 26 26 MRanForestGrow.cc \ 27 MRanForestCalc.cc \ 27 28 MHRanForest.cc \ 28 MHRanForestGini.cc \ 29 MRFEnergyEst.cc 29 MHRanForestGini.cc 30 30 31 31 ############################################################ -
trunk/MagicSoft/Mars/mranforest/RanForestLinkDef.h
r7396 r7413 8 8 #pragma link C++ class MRanForest+; 9 9 #pragma link C++ class MRanForestGrow+; 10 #pragma link C++ class MRanForestCalc+; 10 11 11 12 #pragma link C++ class MHRanForest+; 12 13 #pragma link C++ class MHRanForestGini+; 13 14 14 #pragma link C++ class MRFEnergyEst+;15 16 15 #endif -
trunk/MagicSoft/Mars/mtools/MTFillMatrix.cc
r7401 r7413 204 204 } 205 205 206 //------------------------------------------------------------------------ 207 // 208 // Add all entries deriving from MFilter from list to PreCuts. 209 // The ownership is not affected. 210 // 211 void MTFillMatrix::AddPreCuts(const TList &list) 212 { 213 TIter Next(&list); 214 TObject *obj=0; 215 while ((obj=Next())) 216 if (obj->InheritsFrom(MFilter::Class())) 217 fPreCuts.Add(obj); 218 } 206 219 207 220 // -------------------------------------------------------------------------- … … 209 222 // Fill the matrix (FIXME: Flow diagram missing) 210 223 // 211 Bool_t MTFillMatrix::Process( )224 Bool_t MTFillMatrix::Process(const MParList &parlist) 212 225 { 213 226 if (!fReader) … … 232 245 // Create parameter list and task list, add tasklist to parlist 233 246 // 234 MParList plist; 247 parlist.Print(); 248 MParList plist(parlist); 235 249 MTaskList tlist; 236 250 plist.AddToList(&tlist); … … 372 386 return WriteMatrix1(fname) && WriteMatrix2(fname); 373 387 } 388 389 Int_t MTFillMatrix::ReadEnv(const TEnv &env, TString prefix, Bool_t print) 390 { 391 Bool_t rc = kFALSE; 392 if (IsEnvDefined(env, prefix, "NumDestEvents1", print)) 393 { 394 rc = kTRUE; 395 SetNumDestEvents1(GetEnvValue(env, prefix, "NumDestEvents1", fNumDestEvents1)); 396 } 397 if (IsEnvDefined(env, prefix, "NumDestEvents2", print)) 398 { 399 rc = kTRUE; 400 SetNumDestEvents2(GetEnvValue(env, prefix, "NumDestEvents2", fNumDestEvents2)); 401 } 402 return rc; 403 } -
trunk/MagicSoft/Mars/mtools/MTFillMatrix.h
r7402 r7413 1 1 #ifndef MARS_MTFillMatrix 2 2 #define MARS_MTFillMatrix 3 4 #ifndef MARS_MParList 5 #include "MParList.h" 6 #endif 3 7 4 8 #ifndef MARS_MH3 … … 27 31 28 32 TList fPreCuts; 33 34 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print); 29 35 30 36 Bool_t CheckResult(MHMatrix *m, Int_t num) const; … … 72 78 void AddPreCut(const char *rule); 73 79 void AddPreCut(MFilter *f); 80 void AddPreCuts(const TList &list); 74 81 75 Bool_t Process( );82 Bool_t Process(const MParList &plist=MParList()); 76 83 Bool_t WriteMatrix1(const TString &fname) const { return WriteMatrix(fDestMatrix1, fname, 1); } 77 84 Bool_t WriteMatrix2(const TString &fname) const { return WriteMatrix(fDestMatrix2, fname, 2); }
Note:
See TracChangeset
for help on using the changeset viewer.