Index: trunk/MagicSoft/Cosy/tpoint/tpoint0509.txt
===================================================================
--- trunk/MagicSoft/Cosy/tpoint/tpoint0509.txt	(revision 7412)
+++ trunk/MagicSoft/Cosy/tpoint/tpoint0509.txt	(revision 7413)
@@ -1,7 +1,4 @@
 Magic Model  TPOINT data file
 : ALTAZ
-#
-# ***** After a refocussing of the mirror *****
-#
 
 ### 24.9.: tpoints always with the white paper screen
@@ -11,9 +8,9 @@
 1.742509 57.99808 144.2056 49.02492 0.945 60.71667 0.0005732658 0.007748751 53637.075763 216.1 2.654
 # Hamal,  mag=2.00, Zd=5
-139.6868 83.23968 281.6764 74.22004 2.119444 23.4625 -0.04332626 0.03920611 53637.11646 225.2 2.635
+##139.6868 83.23968 281.6764 74.22004 2.119444 23.4625 -0.04332626 0.03920611 53637.11646 225.2 2.635
 
 # --- 24.09.2005 --- 02:59:09.399
 # Hamal,  mag=2.00, Zd=5
-161.5844 84.46453 303.3778 75.43595 2.119444 23.4625 -0.009743542 0.1953913 53637.124414 225.2 2.665
+##161.5844 84.46453 303.3778 75.43595 2.119444 23.4625 -0.009743542 0.1953913 53637.124414 225.2 2.665
 # And-51, mag=3.57, Zd=21
 -21.2567 68.112 121.1535 59.26484 1.633333 48.62833 0.02363187 0.04614806 53637.142328 218.1 3.353
@@ -24,5 +21,5 @@
 # --- 25.09.2005 --- 03:41:32.305
 # Nothing in the runbook?
--35.99076 37.46571 106.0467 28.7287 22.48611 58.41528 0.1168588 0.4782401 53638.153846 0 6.58
+##-35.99076 37.46571 106.0467 28.7287 22.48611 58.41528 0.1168588 0.4782401 53638.153846 0 6.58
 -38.29146 35.14824 104.1974 26.30449 22.25056 57.04361 0.01046067 0.02796104 53638.15701 220.4 3.97
 ## seems to be wrongly identified
@@ -76,2 +73,9 @@
 112.9061  44.22773 255.4126 35.24166 7.655     5.225    -0.005348532  0.000207558 53639.239228 215.7 2.556
 
+####################################################################
+# Private communication with Adrian:
+# Als wir Ende September rausfanden, dass die Laser unzuverlaessig
+# sind, wurde da eine Quick-and-Dirty Kalibration gemacht (da kein
+# Experte auf La Palma war)
+####################################################################
+
Index: trunk/MagicSoft/Cosy/tpoint/tpoint0510.txt
===================================================================
--- trunk/MagicSoft/Cosy/tpoint/tpoint0510.txt	(revision 7412)
+++ trunk/MagicSoft/Cosy/tpoint/tpoint0510.txt	(revision 7413)
@@ -2,7 +2,16 @@
 : ALTAZ
 
+#
+# ***** New focussing after collabortaion meeting in Tenerife (19.10.?) *****
+#
+
 # --- 25.10.2005 --- 02:11:32.993
+# Diphda. Magn: 2.04 Zd:59.21 Az:222.64
 -137.4972 30.88874 5.015726 21.99765 0.7263889 -17.98667 -0.03588449 -0.01783158 53668.091354 237.2 2.802
+# Algenib. Magn:2.83 Zd:45.55 Az:263.21
 -96.64771 44.18443 45.84061 35.33164 0.2205556 15.18361 -0.0004117089 -0.002440412 53668.098033 235.3 3.151
+# Markab. Magn:2.49 Zd:65.51 Az:273.02
 -87.16777 27.87191 55.32808 19.00867 23.07944 15.20528 -0.008018477 0.009832391 53668.10233 237.3 3.096
+# Markab. Magn:2.49 Zd:63.7 Az:273.65
 -86.52195 26.6309 55.98938 17.74595 23.07944 15.20528 -0.02510043 -0.001211299 53668.106316 233.3 3.102
+
Index: trunk/MagicSoft/Cosy/tpoint/tpoint0511.txt
===================================================================
--- trunk/MagicSoft/Cosy/tpoint/tpoint0511.txt	(revision 7413)
+++ trunk/MagicSoft/Cosy/tpoint/tpoint0511.txt	(revision 7413)
@@ -0,0 +1,353 @@
+Magic Model  TPOINT data file
+: ALTAZ
+
+# not found...
+# Menkalinan       59    52
+
+# --- 10.11.2005 --- 22:29:55.818
+# no focussing
+# Deneb            50   306
+##-53.33306 40.97287  89.18352 32.17512 20.69056  45.28028 0.05858123 -0.009519365 53684.937452 221.3 2.936
+-53.24298 39.2576   89.28467 30.39965 20.69056  45.28028 -0.002789735 -0.01901759 53684.94446 227.6 2.64
+# Mirfak           35    42
+#42.36096  55.1629  184.9011  46.19138 3.405278  49.86111 0.01484523 -0.03366052 53684.950519 233.3 2.669
+42.35203  55.18335 184.8911  46.20575 3.405278  49.86111 0.006741879 -0.03320052 53684.950576 222.1 2.674
+# Atik             34    75
+#74.5586   55.45014 217.0796  46.47079 3.902222  31.88361 0.003998542 -0.02130962 53684.96173 226.7 3.109
+74.56675  55.49151 217.0855  46.50691 3.902222  31.88361 -0.001503694 -0.01921247 53684.961847 226.2 3.105
+# Mirfak           31    33
+39.13267  58.61137 181.6675  49.63042 3.405278  49.86111 0.005590119 -0.03905839 53684.967135 238.7 2.68
+# Algol            23    53
+52.3911   66.24102 194.8951  57.24358 3.136111  40.95556 -0.001575502 -0.03402223 53684.971644 228.5 2.739
+# Capella          45    52
+52.3088   43.9596  194.8774  34.98086 5.278056  45.99806 0.004237299 -0.04721641 53684.977218 237.3 2.564
+# Aldebaran        41    97
+97.3829   48.39425 239.9304  39.4044  4.598611  16.50917 -0.007722469 -0.04169748 53684.981496 226 2.565
+# Hamal             6   147
+#142.5234  83.46492 284.6891  74.4373  2.119444  23.4625 -0.01067181 -0.05863808 53684.986698 227.9 2.707
+142.6579  83.47064 284.8418  74.4493  2.119444  23.4625 -0.00510559 -0.06337461 53684.986757 226.8 2.703
+# Sheratan          8   188
+-177.2778 82.08688 324.9591  73.18059 1.910556  20.80806 -0.015636 -0.05626715 53684.991152 224 3.08
+###95.33548  66.52729 237.8078  57.52967 3.791389  24.105 -0.004042209 -0.0152961 53684.996808 240 3.207
+# Aldebaran        35   102
+102.4284  54.86752 244.9716  45.88314 4.598611  16.50917 -0.001592067 -0.0499018 53685.002294 210 2.566
+# Bellatrix        48   109
+#107.8841  40.86595 250.4326  31.89502 5.418889   6.349722 0.008040443 -0.03651743 53685.007268 238.2 2.617
+107.8972  40.87553 250.4461  31.91081 5.418889   6.349722 0.01628918 -0.03868437 53685.007327 224.9 2.619
+# Rigel            55   126
+125.6518  35.05451 268.2081  26.08821 5.242222  -8.201667 0.01616527 -0.0490274 53685.011537 240 2.566
+# Hamal             8   231
+-129.106  81.90822  13.08641 73.0289  2.119444  23.4625 0.01013481 -0.004836517 53685.017632 231.1 2.8
+###-125.0357 77.00276  17.29365 68.13426 1.910556  20.80806 0.01223445 -0.002037553 53685.021476 230.4 3.425
+# Menkar           25   172
+##171.0971  65.0153  313.5564  56.11543 3.038056   4.089722 0.09114391 -0.01599885 53685.026499 227.7 3.038
+# Alpheratz        37   280
+-78.89545 53.23702  63.60491 44.40686 0.1397222 29.09056 0.02564853 -0.01916526 53685.033386 219.2 2.866
+# Almach           18   320
+-38.3552  71.58575 104.1104  62.71678 2.065     42.32972 0.006907553 -0.0441346 53685.039029 223.7 2.791
+# Algol            11   354
+# while culmination problem.
+##-4.294531 77.86821 138.1426  68.86221 3.136111  40.95556 -0.1221204 -0.06828355 53685.044275 230.4 2.77
+# Per-Epsilon-45   13    30
+32.20238  76.28861 174.6306  67.28928 3.964167  40.01028 0.006784299 -0.03593259 53685.049077 230.5 3.184
+
+# --- 17.11.2005 --- 21:34:33.794
+# AMC in Test Mode (Az=900)
+##-53.23632 45.94963 89.28836 37.08098 20.69056 45.28028 -0.01423068 -0.02292014 53691.899002 233.3 2.597
+##45.33003 49.94975 187.8677 40.97063 3.405278 49.86111 0.005403622 -0.02236697 53691.907643 236 2.64
+51.56235 33.42948 194.1368 24.44883 5.278056 45.99806 6.12472e-05 -0.04384373 53691.915936 202.7 2.559
+
+# --- 17.11.2005 --- 22:14:02.563
+# Menkar  2.55   39  122
+122.0309 50.21466 264.5388 41.21659 3.038056 4.089722 -0.01743875 -0.01356435 53691.926419 240 2.793
+# Mirfak  1.81   33   41
+41.08085 56.74803 183.6022 47.74404 3.405278 49.86111 -0.01604328 -0.01723673 53691.938785 226.7 2.63
+41.01403 56.81374 183.5347 47.8175 3.405278 49.86111 -0.009117489 -0.01751813 53691.939134 216 2.647
+# Deneb   1.33   60  309
+-51.79435 30.29193 90.72644 21.4365 20.69056 45.28028 -0.0008283486 -0.005480915 53691.96102 234.7 2.814
+# Diphda  2.05   54  145
+-146.2857 35.96036 356.2055 27.08446 0.7263889 -17.98667 -0.02372779 -0.007524253 53691.999811 237.5 3.074
+# Sorry to say that scattered clouds may have passed by while doing the TPoint, so 
+# maybe you have to throw them to trash.
+# Now clouds cover everything.
+# Wait for an improvement
+# Algenib       2.83  42  260
+-98.81135 47.30629 43.67334 38.45381 0.2205556 15.18361 0.002548592 0.001292223 53692.02253 240 3.071
+# Deneb-Kaitos  2.04  60  224
+-135.9855 29.79184 6.517037 20.94392 0.7263889 -17.98667 0.00558226 -0.006424987 53692.03069 224 2.683
+# Hamal         2.00  17  256
+-101.2229 70.87153 41.18756 61.99165 2.119444 23.4625 -0.009133211 -0.00597267 53692.036466 232 2.696
+
+# Missing...
+# Menkar  2.55  27  208
+# Rigel   0.28  41  152
+
+# --- 18.11.2005 --- 01:10:38.545
+# Alnilam 1.72  36  142
+-154.3859 63.1341 348.0636 54.25876 3.038056 4.089722 -0.008364846 -0.003810019 53692.049057 230.5 2.746
+#after this I have relized that the Starguider LED brightness were
+#oscillating (I don't know since when). Go to the remote, check the
+#cable connections, reorient antena towards the camera, check intensity
+#in starguider window (need two iterations). Now it's ok. Resume tests:
+# Alnilam     1.72  33  149
+146.7726 55.42131 289.2781 46.40186 5.603611 -1.201944 -0.03602613 -0.02762634 53692.074116 240 2.593
+# Betelgeuse  0.57  28  134
+132.7432 60.827 275.3237 51.80709 5.919444 7.406944 -0.02859484 -0.1162972 53692.078903 232.9 2.558
+# Bellatrix   1.66  24  154
+150.9132 64.93869 293.4 55.92163 5.418889 6.349722 -0.02529905 -0.03820015 53692.083554 238.7 2.58
+# Alhena      2.02  27  110
+109.1654 61.15764 251.6739 52.16269 6.628611 16.39917 -0.00670304 -0.03408162 53692.088381 232.9 2.645
+# Procyon     0.40  44  114
+112.5609 43.93884 255.1218 34.9496 7.655 5.225 -0.009393286 -0.0540745 53692.093533 240 2.559
+# here again LED's are out of control (just before doing Starguider
+# analysis of Procyon I reoriented antena (put it vertical) and it gets
+# better) then proceed with Starguider analysis and continue with other
+# stars:
+# Capella     0.08  17    4
+# 6.957895 72.63665 149.5549 63.59346 5.278056 45.99806 -0.04324068 -0.1679624 53692.102428 231.1 2.563
+# Calx        2.90  15  107
+107.0553 72.73038 249.5008 63.71871 6.382778 22.51361 -0.0112791 -0.03531665 53692.107158 240 2.731
+# Alnitak     1.74  30  174
+# 174.9306 67.42154 317.4046 58.5348 5.418889 6.349722 0.1068053 -0.04367407 53692.11133 228.4 2.582
+
+# --- 18.11.2005 --- 02:48:18.186
+# Alnitak     1.74  30  174
+# 172.5212 58.9955 314.9896 50.10625 5.679167 -1.942778 0.09697925 -0.01659364 53692.116877 227.3 2.597
+# Menkar      2.55  44  244
+-117.3036 46.4656 25.18223 37.61571 3.038056 4.089722 0.00665884 0.0003887241 53692.122622 236.4 2.763
+# Zaurak      2.96  49  215
+-146.3878 41.15321 356.1018 32.30108 3.967222 -13.50861 0.004302663 0.0008693035 53692.126657 233.9 2.918
+# Cursa       2.79  35  199
+-163.4272 54.98066 339.0485 46.11012 5.130833 -5.086389 -0.01283984 -0.0133753 53692.130931 224.3 2.917
+# Rigel       0.28  38  196
+-165.4518 52.08184 337.084 43.1899 5.242222 -8.201667 -0.03432437 -0.06655793 53692.134311 231.6 2.568
+-165.4313 52.05332 337.1205 43.18485 5.242222 -8.201667 -0.01051018 -0.07939652 53692.13437 225.2 2.562
+# Bellatrix   1.66  24  203
+-159.2495 66.30473 343.2192 57.41084 5.418889 6.349722 -0.02428067 -0.04031334 53692.139569 221.5 2.6
+# Mirzam      1.96  46  175
+# 174.1992 42.97874 316.6979 34.12526 6.378333 -17.95583 0.1246833 -0.00796921 53692.144197 225.5 2.649
+# Sirius     -1.43  46  169
+# Alhena      2.02  12  163
+# Procyon     0.40  28  141
+# Gomeisa     2.89  23  146
+# Betelgeuse  0.57  23  205
+# Castor      1.58  10   70
+# Pollux      1.22  10   90
+# Menkalinan  1.90  19  327
+-30.6883 70.40841 111.7733 61.51092 5.992222 44.9475 -0.02717124 -0.02608279 53692.179384 227.6 2.623
+# Capella     0.08  27  316
+-43.07561 63.09935 99.50457 54.23317 5.278056 45.99806 -0.00376301 -0.1100728 53692.18396 235.6 2.558
+# Castor      1.58   5   53
+57.80852 83.88302 200.1237 74.84615 7.576667 31.88833 -0.01872547 -0.1849833 53692.189403 215.1 2.594
+# Pollux      1.22   5   97
+# Procyon     0.40  23  175
+# Alhena      2.02  18  232
+# Betelgeuse  0.57  33  236
+-125.5931 57.23878 16.95867 48.37683 5.919444 7.406944 -0.002405085 -0.08935168 53692.21057 209.2 2.558
+##-118.526 67.30761 23.92064 58.42263 6.628611 16.39917 -0.01745499 -0.01989757 53692.22435 211.6 2.632
+# Bellatrix   1.66  41  245
+# Alnilam     1.72  45  234
+# Alhena      2.02  63  242
+# Saiph       2.06  51  227
+# Pollux      1.22   7  265
+# Procyon     0.40  25  208
+-154.8319 64.40763 347.6879 55.51185 7.655 5.225 -0.02871712 -0.08110161 53692.239166 210.7 2.561
+# Aludra      2.46  60  197 (*)
+-163.7281 29.92588 338.7812 21.07687 7.401667 -29.30306 0.008528116 -0.004836706 53692.243824 231.6 2.849
+
+
+# --- 18.11.2005 --- 05:52:19.313
+# Wesen       1.84  59  203
+-163.4424 29.86248 339.0668 21.00248 7.401667 -29.30306 -0.003471366 -0.01272333 53692.244668 233.3 2.833
+# Castor      1.58  16  285
+-74.01682 74.63479 68.40574 65.76538 7.576667 31.88833 0.00882 -0.04214247 53692.254711 227.6 2.59
+# Menkalinan  1.90  38  307
+# Capella     0.08  46  307 (after astronomycal dawn)
+
+
+
+# --- 19.11.2005 --- 00:16:31.030
+# Algol            2.11    13   77
+9.713423 77.58746 152.1351 68.56959 3.136111 40.95556 -0.01075349 -0.04624896 53693.01147 213.4 2.725
+# Mirfak           1.81    21    6
+##8.791505 68.47184 151.2798 59.54924 3.405278 49.86111 0.07321356 -0.02584572 53693.016523 212.8 2.682
+# Per Epsilon-45A  2.91    14   35
+35.88479 75.55323 178.3531 66.53329 3.964167 40.01028 -0.0160192 -0.07169134 53693.022965 210.1 3.061
+# Ruchbah          2.68    37  335
+-24.07576 52.59619 118.4295 43.75658 1.430278 60.23528 0.01844797 -0.004008848 53693.031277 211.8 3.05
+# Per Zeta-44A     2.88     5   53
+53.26515 84.58796 195.4636 75.55089 3.902222 31.88361 -0.01836464 -0.1300112 53693.036741 216 3.009
+# Alcyone          2.87     4  162
+160.3021 85.12264 302.3016 76.07234 3.791389 24.105 -0.03117859 -0.05134193 53693.041342 206.9 3.026
+# Per Zeta-44A     2.88     3   23
+25.36356 86.52669 167.3087 77.48545 3.902222 31.88361 -0.02067727 -0.1788716 53693.046052 217.5 3.077
+# Mirfak           1.81    22  345
+-13.7746 68.05241 128.7109 59.16969 3.405278 49.86111 -0.01165857 -0.0271696 53693.052323 196.5 2.684
+# Algol            2.11	 16  321
+-38.80374 73.4509 103.6076 64.5791 3.136111 40.95556 0.007865213 -0.004910895 53693.057018 208.9 2.775
+# Caph             2.28	 51  324
+-35.22483 39.38956 107.2983 30.56228 0.1530556 59.14972 0.02585498 -0.008740766 53693.062595 220.3 2.871
+# Per Zeta-44A     2.88	  6  300     
+-58.38662 83.73528 83.76574 74.84051 3.902222 31.88361 0.001214819 -0.03409007 53693.068372 215.9 3.091
+# Capella          0.08	 19   25	  
+25.69894 70.27186 168.3332 61.25422 5.278056 45.99806 -0.01886337 -0.1803139 53693.074218 196.4 2.563
+# Rigel		 0.28	 38  165
+164.6734 51.97845 307.2183 42.97224 5.242222 -8.201667 -0.02419962 -0.06597684 53693.08045 205.9 2.559
+# Alcyone          2.87	 13  254
+-106.5902 76.36188 35.76273 67.50136 3.791389 24.105 0.02270353 -0.01152923 53693.086007 217.2 3.047
+# Arneb            2.59	 47  167 (only 40 s analysis)
+# Arneb            2.59	 47  168
+##167.2449 42.3776 309.7535 33.50231 5.545556 -17.82222 0.1032633 -0.01908787 53693.091929 216.8 2.949
+
+# Alnath/Elnath    1.68     4   90 (maybe wrong because Moon was too close)
+# here we have a problem: the star guider LEDs get out of control, go
+# check the remote control, nothing evident happens, when reorienting it
+# it goes back to life... continue...
+
+90.27715 85.49495 232.5633 76.44288 5.438056 28.6075 -0.03146283 -0.3382284 53693.100463 197.6 2.598
+# Pollux           1.22    29   83 
+83.3547 61.07259 225.8943 52.04639 7.755278 28.02611 -0.03853513 -0.05670296 53693.119563 206.9 2.564
+# Aur-iota-3       2.68    10  297
+-62.59163 79.41818 79.76437 70.53351 4.95 33.16611 0.002857573 -0.05658218 53693.125613 199.1 2.77
+# Menkalinan       1.90    16    7
+##7.040515 73.63366 149.4877 64.66454 5.992222 44.9475 0.03184843 -0.03102624 53693.130087 212.4 2.616
+# Dubne            1.82    59   33
+32.61584 31.17462 175.1803 22.21658 11.06222 61.75083 0.02238362 -0.03183222 53693.135331 221 2.663
+# Merak            2.35    58   39
+38.99071 31.68195 181.536 22.72107 11.03056 56.3825 0.01989991 -0.01312369 53693.138993 224.3 2.857
+# Pollux           1.22    21   86
+86.12663 68.80638 228.6275 59.78246 7.755278 28.02611 -0.02789551 -0.05323995 53693.144148 207.6 2.56
+# Castor           1.58    17   75
+74.731 72.52119 217.2117 63.4875 7.576667 31.88833 -0.03354795 -0.05802244 53693.148245 208.2 2.584
+# Alhena           2.02    13  163 (maybe wrong because Moon was too close)
+162.1973 77.1305 304.581 68.07518 6.628611 16.39917 -0.04916995 -0.04870143 53693.15294 218.7 2.662
+# Sirius          -1.43    46  175
+##174.4768 44.32402 317.0678 35.39014 6.7525 -16.71611 0.04438464 -0.1008655 53693.158119 218.8 2.563
+# Wesen            1.84    56  171
+##171.0157 34.20317 313.5328 25.31726 7.14 -26.39333 0.09211921 -0.01411622 53693.1625 206.7 2.666
+# Pollux           1.22    13   89
+89.40363 76.42206 231.8193 67.39766 7.755278 28.02611 -0.01838491 -0.04293298 53693.168274 203.5 2.56
+# Castor           1.58     9   68
+68.12716 80.59168 210.4925 71.54071 7.576667 31.88833 -0.03744638 -0.07208734 53693.175008 209.8 2.599
+
+
+Star             Mag    Zd    Az
+-----------------------------------
+
+
+A couple of times we have had the LED's out of control
+One time we have had one missidentified LED, we have increased the
+power but we do not know if that might have affected some of the
+TPoints.
+
+
+
+
+# --- 19.11.2005 --- 04:20:24.958
+# Algenubi         2.97    37   88
+88.01633 53.06152 230.5192 44.06802 9.764167 23.77417 -0.009191703 -0.002474573 53693.180844 203.9 3.127
+# Pollux           1.22     8   93 
+# (this last one could be wrong because RH went above 90% and guagua closed the lids automatically)
+93.06005 82.04841 235.433 72.99163 7.755278 28.02611 -0.04325701 -0.1462649 53693.185986 211.6 2.566
+93.79571 82.7235 236.0788 73.6627 7.755278 28.02611 -0.04440322 -0.09204096 53693.188121 209.5 2.564
+
+# --- 21.11.2005 --- 00:07:42.829
+# Ruchbah          2.68   35   340
+-19.39851 55.0307 123.1019 46.15904 1.430278 60.23528 -0.01178329 -0.002747289 53695.005357 221.7 3.184
+# Per Gamma-23A    2.94   25     0
+0.5465434 65.23242 143.0277 56.24389 3.08 53.50639 0.00259679 -0.004442015 53695.010308 214.5 3.332
+# Mirfak           1.81   21     6
+6.320905 68.71945 148.8018 59.71429 3.405278 49.86111 -0.01012885 -0.02490495 53695.015 207 2.709
+# Algol            2.11   12   349 
+# (do it twice up to TPoint and only second time do starguider analysis)
+##-8.333204 77.74401 134.0779 68.75136 3.136111 40.95556 -0.1088109 -0.04768316 53695.020173 215.2 2.865
+-9.941665 77.57662 132.466 68.68695 3.136111 40.95556 -0.005880015 -0.04754076 53695.021463 216.9 2.867
+# Per Epsilon-45A  2.91   13    27
+27.92726 76.97957 170.3541 67.97973 3.964167 40.01028 0.00717628 -0.04650552 53695.026129 211.7 3.245
+# Per Zeta-44A     2.88    5    51	
+52.1437 84.72058 194.3186 75.70198 3.902222 31.88361 0.0007036738 -0.1281018 53695.031882 219.6 3.255
+# Alcyone          2.87    5   190	
+163.9685 85.19842 305.9751 76.16817 3.791389 24.105 -0.01174545 -0.03528944 53695.036864 210.6 3.249
+
+# --- 21.11.2005 --- 01:01:29.688
+##-172.7512 85.47053 329.3041 76.4323 3.791389 24.105 -0.1422219 -0.123775 53695.042705 207.8 3.237
+# Ruchbah	         2.6    41   332
+-28.32705 49.21944 114.1799 40.377 1.430278 60.23528 0.0135589 -0.001316744 53695.049942 208.5 3.157
+# Per Gamma-23A    2.94   27   339
+-20.49285 62.7163 121.9874 53.84466 3.08 53.50639 -0.006139484 -0.006334611 53695.054785 222.2 3.341
+# Capella	         0.08   21    30	
+30.36726 69.06814 172.9886 60.0533 5.278056 45.99806 -0.02017053 -0.1659543 53695.060711 225.7 2.567
+# Per Zeta-44A     2.88    9   293
+-65.8741 81.58648 76.38503 72.69459 3.902222 31.88361 -0.0004023837 -0.02965922 53695.070579 232 3.241
+# Aur Iota-3       2.68    6    39
+42.05936 83.93919 184.2375 74.91534 4.95 33.16611 -0.006883834 -0.05024835 53695.075594 240 3.094
+# Aur Theta-37A    2.65   19    57
+56.93654 72.11446 199.4069 63.09118 5.995278 37.2125 -0.02089661 -0.03533632 53695.080168 240 3.052
+# Aur Iota-3       2.68    4    16
+16.99955 85.37844 159.1199 76.35111 4.95 33.16611 -0.008621755 -0.1533459 53695.084538 240 3.074
+
+# --- 21.11.2005 --- 02:04:43.739
+# Aur Iota-3       2.68    4     7
+9.394841 85.53326 151.4381 76.50252 4.95 33.16611 -0.01160676 -0.07618946 53695.086617 229.3 3.071
+# Tau Zeta-123     3.00   11   132
+131.1254 78.8946 273.4193 69.85839 5.6275 21.1425 -0.02860174 0.01926165 53695.092313 240 3.163
+# Betelgeuse       0.57   24   152
+150.9371 66.10044 293.4995 57.10722 5.919444 7.406944 -0.0008021126 -0.1247619 53695.097696 233.6 2.562
+# Alhena           2.02   23   119
+118.6392 67.39298 261.1108 58.37948 6.628611 16.39917 -0.02074373 -0.02546799 53695.101679 232.4 2.692
+# Gomeisa          2.89   36   119
+118.8102 54.31726 261.313 45.31668 7.4525 8.289444 -0.01553769 -0.01437185 53695.106798 240 3.106
+# Procyon          0.38   37   123
+120.945 51.13279 263.4987 42.12813 7.655 5.225 -0.02157411 -0.06066934 53695.110766 212.5 2.564
+122.8865 52.49353 265.4344 43.47813 7.655 5.225 -0.03057299 -0.06622591 53695.115804 240 2.559
+# Calx             2.88   11   124	
+122.8206 79.16072 265.1369 70.11984 6.382778 22.51361 -0.02992892 -0.01040129 53695.121202 240 3.007
+# Elnath           1.65    6   270
+##-89.95085 84.12565 52.07968 75.51054 5.438056 28.6075 0.2763374 0.01998722 53695.127004 0 4.201
+# Calx             2.88    7   149
+145.4004 82.52851 287.59 73.49029 6.382778 22.51361 -0.02325484 -0.02097986 53695.135833 226.7 2.995
+# Aur Theta-37     2.62    9   341
+-18.29252 81.07387 124.026 72.16635 5.995278 37.2125 -0.01935549 -0.03397963 53695.142219 232 3.109
+# Menkalinan       1.90   17   346	
+-13.46114 73.27331 128.9991 64.37864 5.992222 44.9475 -0.01689938 -0.04056909 53695.147419 236.8 2.762
+# Procyon          0.38   29   142
+141.7859 61.35367 284.3348 52.31961 7.655 5.225 -0.04545423 -0.08939356 53695.153418 236.4 2.563
+# Gomeisa          2.89   23   150
+149.5953 66.81713 292.0358 57.78786 7.4525 8.289444 -0.0352983 -0.005136182 53695.160763 238.2 3.116
+# Aur Iota-3       2.69   24   287
+-72.4764 65.70607 69.98095 56.82059 4.95 33.16611 -0.015638 -0.01046854 53695.166557 233.6 3.071
+# Algol            2.12   48   301
+-59.2317 42.49393 83.28415 33.64438 3.136111 40.95556 0.003494328 -0.01238776 53695.17177 212.3 2.867
+# Atik             2.85   41   287 
+-73.31572 49.12407 69.17717 40.26025 3.902222 31.88361 -0.0137088 -0.002336862 53695.177453 225.2 3.2
+135.3655 41.35791 277.8868 32.36135 9.459722 -8.658611 -0.01748914 -0.01957396 53695.187036 224 2.713
+
+# --- 21.11.2005 --- 04:31:45.424
+# Alphard          1.98   48   136	 
+135.9971 41.73244 278.5169 32.73314 9.459722 -8.658611 -0.02008771 -0.01797146 53695.18872 240 2.706
+# Procyon          0.38   24   174	
+173.1282 66.35884 315.6439 57.3251 7.655 5.225 -0.04138279 -0.08644531 53695.19383 236.8 2.558
+# Aldebaran        0.85   43   264	
+-96.46572 46.9506 46.04894 38.09473 4.598611 16.50917 -0.001188459 -0.02791443 53695.199224 238.2 2.561
+# Alcyone          2.87   53   280	
+-80.23616 37.11736 62.26642 28.26016 3.791389 24.105 -0.01279776 -0.000625742 53695.205655 230.4 3.218
+# Alphard          1.98   43   146	
+145.8643 46.51202 288.3652 37.5053 9.459722 -8.658611 -0.02506065 -0.01201373 53695.212635 224 2.678
+# Dubhe            1.79   44    29		 
+28.61427 46.01086 171.1543 37.03458 11.06222 61.75083 0.001945274 -0.02085836 53695.21936 230.7 2.695
+# Alioth           1.77   56    40	 
+39.69454 34.45477 182.2395 25.48611 12.90056 55.95972 0.01121355 -0.01453658 53695.22507 225.5 2.714
+# Merak            2.37   40    34	
+34.30208 50.39008 176.8293 41.39932 11.03056 56.3825 -0.01000619 -0.01319575 53695.229602 210.4 2.957
+# Phecda           2.44   45    41
+41.33961 45.03501 183.872 36.06151 11.89722 53.69472 0.004877249 -0.01154039 53695.233608 231.2 3.006
+# Alhena           1.93   30   252		 
+-108.0432 60.15783 34.43154 51.2914 6.628611 16.39917 -0.002325848 -0.01663785 53695.240673 216.9 2.715
+# Bellatrix        1.64   52   254	
+-105.8993 38.4042 36.60352 29.56264 5.418889 6.349722 0.01138032 -0.008900444 53695.245138 215.9 2.64
+# Betelgeuse       0.50   46   251
+-109.204 44.17446 33.34888 35.31499 5.919444 7.406944 -0.005226405 -0.06718146 53695.248743 204.5 2.56
+# Gomeisa          2.89   30   231		 
+-129.5217 60.51771 12.93498 51.63853 7.4525 8.289444 -0.01605401 -0.003262285 53695.255537 211.4 3.089
+# Procyon          0.38   31   224
+-136.0317 59.25554 6.466056 50.37589 7.655 5.225 -0.019558 -0.0500969 53695.259343 218.4 2.559
Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 7412)
+++ trunk/MagicSoft/Mars/Changelog	(revision 7413)
@@ -18,4 +18,73 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2005/11/21 Thomas Bretz
+
+   * mjtrain/*, macros/train/*.C:
+     - added new class to train the random forest
+
+   * Makefile:
+     - added mjtrain
+
+   * macros/dohtml.C, macros/rootlogon.C:
+     - added mjoptim and mjtrain
+
+   * mbase/MParList.[h,cc]:
+     - fixed copy constructor (it was crashing due to the
+       non-initialized lists)
+
+   * mhbase/MBinning.[h,cc]:
+     - renamed SetEdges to SetEdgesLin (SetEdges now is just and
+       abbreviation)
+     - added a check for the number of bins to all SetEdges*
+
+   * mhbase/MH3.cc:
+     - enable grid
+
+   * mhbase/MHMatrix.[h,cc]:
+     - new member function Addcolumns taking a TCollection
+
+   * mhist/MHHadronness.cc:
+     - align hadronnes into [0,1]
+
+   * mjobs/MDataSet.[h,cc]:
+     - call SetOwner for fSequencesOn and fSequencesOff
+     - added Copy member function
+
+   * mjobs/MJCut.[h,cc]:
+     - added new TaskEnv "CalcDisp" for a disp estimator
+
+   * mjoptim/MJOptimizeDisp.cc:
+     - fixed typo in a title
+     - added a new histogram showing theta-sq versus size
+
+   * mranforest/MHRanForestGini.[h,cc]:
+     - revised to display more information
+     - exchanged pointers to TGraph by objects
+
+   * mranforest/MRanForest.[h,cc]:
+     - replaced some weired copy of the train matrix by a direct access
+     - revised output
+     - pipe error/resolution to tree
+
+   * mranforest/MRanForestCalc.[h,cc]:
+     - copied code from MRFEnergyEst
+     - allow to set a name for the output container
+     - set numtry to 0 (auto)
+     - set ndsize to 1 (there is no auto mode)
+     - introduced variable for number of obsolete parameters
+
+   * mranforest/MRanTree.h:
+     - new data member to store resolution/error
+
+   * mranforest/Makefile, mranforest/RanForestLinkDef.h:
+     - removed MRFEnergyEst 
+     - added MRanForestCalc
+
+   * mtools/MTFillMatrix.[h,cc]:
+     - added the possibility to use PreCuts befre filling the matrix
+     - added ReadEnv
+
+
+
  2005/11/18 Thomas Bretz
 
Index: trunk/MagicSoft/Mars/Makefile
===================================================================
--- trunk/MagicSoft/Mars/Makefile	(revision 7412)
+++ trunk/MagicSoft/Mars/Makefile	(revision 7413)
@@ -67,4 +67,5 @@
           mjobs \
           mjoptim \
+          mjtrain \
           mtools \
           mmuon
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 7412)
+++ trunk/MagicSoft/Mars/NEWS	(revision 7413)
@@ -13,11 +13,19 @@
    - general: MTFillMatrix (the class to fill one or two MHMatrix from
      files) now allows adding a pre-cut like in the optimization. E.g. this
-     is useful to perform g/h-separation cuts before training the random forest.
-
-   - general: Updated the random forest classes to support also the
-     regression method implemented by Thomas H.
-
-   - general: added new tutorial macro how to train the random forest
-     for energy estimation (macros/optim/rfenergyest.C)
+     is useful to perform g/h-separation cuts before training the random
+     forest.
+
+   - RanForest:
+      + Updated the random forest classes to support also the
+        regression method implemented by Thomas H.
+      + added new tutorial macro how to train the random forest
+        for energy estimation (macros/optim/rfenergyest.C)
+      + new classes to train the random forest (still in development)
+        mjtrain/MJTrainEnergy, mjtrain/MJTrainDisp, mjtrain/MJTrainSeparation
+      + new tutorial macros for random forest training in macros/train
+        trainenergy.C, traindisp.C, trainseparation.C
+
+   - ganymed: In addition to the Hadronness calculator (CalcHadronness)
+     a new option was implemented to estimate Disp (CalcDisp)
 
    - ganymed: Implemented two new options which allow
Index: trunk/MagicSoft/Mars/ganymed.rc
===================================================================
--- trunk/MagicSoft/Mars/ganymed.rc	(revision 7412)
+++ trunk/MagicSoft/Mars/ganymed.rc	(revision 7413)
@@ -39,4 +39,20 @@
 BinningDist.Raw:         25    0    2
 BinningMaxDist.Raw:      25    0    2
+
+# -------------------------------------------------------------------------
+# Using the starguider for pointing correction. 
+# To switch it off use "MPointingDevCalc.MaxAbsDev: -1"
+# -------------------------------------------------------------------------
+#MPointingDevCalc.MaxAbsDev:   15
+#MPointingDevCalc.NumMinStars: 8
+#MPointingDevCalc.NsbLevel:    3.0
+#MPointingDevCalc.NsbMin:      30
+#MPointingDevCalc.NsbMax:      60
+
+# -------------------------------------------------------------------------
+# Setup the misfocussing correction
+# -------------------------------------------------------------------------
+#MSrcPosCorrect.Dx: 0
+#MSrcPosCorrect.Dy: 0
 
 # -------------------------------------------------------------------------
@@ -83,5 +99,5 @@
 Cut0.Condition: ({0} || {1}) && {2} && {3} && {4} && {5}
 Cut0.0: MImagePar.fNumSatPixelsHG < 1
-Cut0.1: MHillas.GetArea*(MGeomCam.fConvMm2Deg^2) > (0.002*MImagePar.fNumSatPixelsHG) + 0.025
+Cut0.1: MHillas.GetArea*(MGeomCam.fConvMm2Deg^2) > (0.003*MImagePar.fNumSatPixelsHG) + 0.0325
 Cut0.2: MNewImagePar.fNumUsedPixels>5
 Cut0.3: MNewImagePar.fLeakage1 < 0.3
@@ -90,8 +106,10 @@
 
 # ---------- SETUP FOR ONOFF-MODE -----------
+MAlphaFitter.ScaleMin: 0.137
+MAlphaFitter.ScaleMax: 0.640
 MAlphaFitter.BackgroundFitMin: 0.137
-MAlphaFitter.BackgroundFitMax: 0.64
+MAlphaFitter.BackgroundFitMax: 1.000
 MAlphaFitter.PolynomOrder: 1
-MAlphaFitter.ScaleMode: Background
+MAlphaFitter.ScaleMode: OffRegion
 MAlphaFitter.SignalFunction: ThetaSq
 
@@ -99,9 +117,9 @@
 Cut1.ThetaCut: None
 Cut1.Param0:  1.3245
-Cut1.Param1:  0.189
-Cut1.Param2:  0.230
-Cut1.Param3:  5.320
-Cut1.Param4:  0.100
-Cut1.Param5: -0.0636
+Cut1.Param1:  0.204
+Cut1.Param2:  0.228
+Cut1.Param3:  5.50
+Cut1.Param4:  0.088
+Cut1.Param5: -0.07
 Cut1.Param6:  8.2957
 Cut1.Param7:  0.8677
@@ -137,8 +155,17 @@
 
 # -------------------------------------------------------------------------
-# Use this to executa a task (eg to calc hadronness) after energy
-# before Cut1
+# Use this to executa a task (eg to calc hadronness) before Cut1
 # -------------------------------------------------------------------------
 # CalcHadronness: MRanForestCalc
-# CalcHadronness.File: /home/tbretz/Mars.cvs/RFspot3cmAll.root
+# CalcHadronness.File: rf-energy.root
+# CalcHadronness.NameOutput: Hadronness
 # CalcHadronness.Debug: No
+
+# -------------------------------------------------------------------------
+# Use this to executa a task (eg to calc disp) before Cut1
+# -------------------------------------------------------------------------
+# CalcDisp: MRanForestCalc
+# CalcDisp.File: rf-disp.root
+# CalcDisp.NameOutput: Disp
+# CalcDisp.Debug: No
+# Cut1.CalcDisp: No
Index: trunk/MagicSoft/Mars/macros/dohtml.C
===================================================================
--- trunk/MagicSoft/Mars/macros/dohtml.C	(revision 7412)
+++ trunk/MagicSoft/Mars/macros/dohtml.C	(revision 7413)
@@ -77,4 +77,6 @@
     sourcedir += "mimage:";
     sourcedir += "mjobs:";
+    sourcedir += "mjoptim:";
+    sourcedir += "mjtrain:";
     sourcedir += "mmain:";
     sourcedir += "mmc:";
Index: trunk/MagicSoft/Mars/macros/rootlogon.C
===================================================================
--- trunk/MagicSoft/Mars/macros/rootlogon.C	(revision 7412)
+++ trunk/MagicSoft/Mars/macros/rootlogon.C	(revision 7413)
@@ -144,4 +144,6 @@
     gInterpreter->AddIncludePath(dir+"mimage");
     gInterpreter->AddIncludePath(dir+"mjobs");
+    gInterpreter->AddIncludePath(dir+"mjoptim");
+    gInterpreter->AddIncludePath(dir+"mjtrain");
     gInterpreter->AddIncludePath(dir+"mmain");
     gInterpreter->AddIncludePath(dir+"mmc");
Index: trunk/MagicSoft/Mars/macros/train/traindisp.C
===================================================================
--- trunk/MagicSoft/Mars/macros/train/traindisp.C	(revision 7413)
+++ trunk/MagicSoft/Mars/macros/train/traindisp.C	(revision 7413)
@@ -0,0 +1,72 @@
+void traindisp()
+{
+    MDataSet set("mctesttrain.txt");
+    set.SetNumAnalysis(1);            // Necessary
+
+    MJTrainDisp opt;
+    //opt.SetDebug();
+
+    // ------- Parameters to train Random Forest --------
+    opt.AddParameter("MHillas.fLength");
+    opt.AddParameter("MHillas.fWidth");
+    opt.AddParameter("MHillas.fSize");
+    opt.AddParameter("MNewImagePar.fLeakage1");
+    opt.AddParameter("MNewImagePar.fLeakage2");
+    opt.AddParameter("MNewImagePar.fConc");
+    opt.AddParameter("MNewImagePar.fConc1");
+    opt.AddParameter("MPointingPos.fZd");
+    opt.AddParameter("MNewImagePar.fUsedArea");
+    opt.AddParameter("MNewImagePar.fCoreArea");
+    opt.AddParameter("MNewImagePar.fNumUsedPixels");
+    opt.AddParameter("MNewImagePar.fNumCorePixels");
+    opt.AddParameter("MImagePar.fSizeSinglePixels");
+    opt.AddParameter("MHillasExt.fM3Long*sign(MHillasSrc.fCosDeltaAlpha)");
+    opt.AddParameter("MHillasExt.fAsym*sign(MHillasSrc.fCosDeltaAlpha)");
+
+    // -------------------- Run ----------------------------
+
+    MStatusDisplay *d = new MStatusDisplay;
+    opt.SetDisplay(d);
+
+    /*
+     -------------------- Magic-Cuts ----------------------
+     MFMagicCuts cuts;
+     cuts.SetHadronnessCut(MFMagicCuts::kArea);
+     cuts.SetThetaCut(MFMagicCuts::kOn);
+
+     TArrayD arr(10);
+     arr[0]=  1.3245;
+     arr[1]=  0.208700;
+     arr[2]=  0.229200;
+     arr[3]=  5.305200;
+     arr[4]=  0.098930;
+     arr[5]= -0.082950;
+     arr[6]=  8.2957;
+     arr[7]=  0.8677;
+
+     cuts.SetVariables(arr);
+
+     opt.AddPreCut(&cuts);
+
+     -------------------- Energy Slope --------------------
+     MFEnergySlope slope(-2.8);
+     opt.AddPreCut(&slope);
+
+     -------------------- Other cuts ----------------------
+     opt.AddPreCut("MNewImagePar.fLeakage1<0.0001");
+    */
+
+     opt.AddPreCut("MHillas.fSize>200");
+     opt.AddPreCut("MHillasSrc.fDCA*MGeomCam.fConvMm2Deg<0.3");
+
+     opt.Train("rf-disp.root", set, 30000);
+}
+/*
+ // SequencesOn:   Monte Carlo Sequences used for training
+ // SequencesOff:  Monte Carlo Sequences used for testing
+
+ // Use:
+ // opt.AddPreCut    to use cut for test and training
+ // opt.AddTestCut   to use cut for test only
+ // opt.AddTrainCut  to use cut for train only
+ */
Index: trunk/MagicSoft/Mars/macros/train/trainenergy.C
===================================================================
--- trunk/MagicSoft/Mars/macros/train/trainenergy.C	(revision 7413)
+++ trunk/MagicSoft/Mars/macros/train/trainenergy.C	(revision 7413)
@@ -0,0 +1,65 @@
+void trainenergy()
+{
+    MDataSet set("mctesttrain.txt");
+    set.SetNumAnalysis(1);            // Necessary
+
+    MJTrainEnergy opt;
+    //opt.SetDebug();
+
+    // ------- Parameters to train Random Forest --------
+    opt.AddParameter("MHillas.fSize");
+    opt.AddParameter("MHillasSrc.fDist");
+    opt.AddParameter("MPointingPos.fZd");
+    opt.AddParameter("MHillas.GetArea");
+    opt.AddParameter("MNewImagePar.fUsedArea");
+    opt.AddParameter("MNewImagePar.fCoreArea");
+    opt.AddParameter("MNewImagePar.fLeakage1");
+    opt.AddParameter("MNewImagePar.fLeakage2");
+    opt.AddParameter("MNewImagePar.fConc");
+    opt.AddParameter("MNewImagePar.fConc1");
+
+    // -------------------- Run ----------------------------
+
+    MStatusDisplay *d = new MStatusDisplay;
+    opt.SetDisplay(d);
+
+    /*
+     -------------------- Magic-Cuts ----------------------
+     MFMagicCuts cuts;
+     cuts.SetHadronnessCut(MFMagicCuts::kArea);
+     cuts.SetThetaCut(MFMagicCuts::kOn);
+
+     TArrayD arr(10);
+     arr[0]=  1.3245;
+     arr[1]=  0.208700;
+     arr[2]=  0.229200;
+     arr[3]=  5.305200;
+     arr[4]=  0.098930;
+     arr[5]= -0.082950;
+     arr[6]=  8.2957;
+     arr[7]=  0.8677;
+
+     cuts.SetVariables(arr);
+
+     opt.AddPreCut(&cuts);
+
+     -------------------- Energy Slope --------------------
+     MFEnergySlope slope(-2.8);
+     opt.AddPreCut(&slope);
+
+     -------------------- Other cuts ----------------------
+     opt.AddPreCut("MHillasSrc.fDist*MGeomCam.fConvMm2Deg<1.0");
+     opt.AddPreCut("MHillas.fSize>200");
+    */
+
+     opt.Train("rf-energy.root", set, 30000);
+}
+/*
+ // SequencesOn:   Monte Carlo Sequences used for training
+ // SequencesOff:  Monte Carlo Sequences used for testing
+
+ // Use:
+ // opt.AddPreCut    to use cut for test and training
+ // opt.AddTestCut   to use cut for test only
+ // opt.AddTrainCut  to use cut for train only
+ */
Index: trunk/MagicSoft/Mars/macros/train/trainseparation.C
===================================================================
--- trunk/MagicSoft/Mars/macros/train/trainseparation.C	(revision 7413)
+++ trunk/MagicSoft/Mars/macros/train/trainseparation.C	(revision 7413)
@@ -0,0 +1,47 @@
+void trainseparation()
+{
+    MDataSet settrn;
+    MDataSet settst;
+    settrn.SetNumAnalysis(1);
+    settst.SetNumAnalysis(2);
+
+    MTTrainRFSeparate opt;
+    //opt.SetDebug();
+
+    // ------- Parameters to train Random Forest --------
+    opt.AddParameter("MHillas.fSize");
+    opt.AddParameter("MHillas.fWidth");
+    opt.AddParameter("MHillas.fLength");
+    opt.AddParameter("TMath::Abs(MHillasExt.fM3Long)");
+    opt.AddParameter("MNewImagePar.fConc");
+    opt.AddParameter("MNewImagePar.fConc1");
+
+    // -------------------- Run ----------------------------
+    MStatusDisplay *d = new MStatusDisplay;
+    opt.SetDispplay(d);
+
+    /*
+     -------------------- Energy Slope --------------------
+     MFEnergySlope slope(-2.8);
+     opt.AddPreCut(&slope);
+
+     -------------------- Other cuts ----------------------
+     opt.AddPreCut("MHillas.fSize>200");
+     opt.AddPreCut("MHillasSrc.fDCA*MGeomCam.fConvMm2Deg<0.3");
+    */
+
+    opt.SetDataSetTrain(settrn, 10000, 10000);
+    //opt.SetDataSetTest(settst);
+
+    opt.Train("rf-separation.root");
+}
+
+/*
+ // SequencesOn:   Monte Carlo sequences (gammas)
+ // SequencesOff:  Data sequences (background)
+
+ // Use:
+ // opt.AddPreCut    to use cut for test and training
+ // opt.AddTestCut   to use cut for test only
+ // opt.AddTrainCut  to use cut for train only
+ */
Index: trunk/MagicSoft/Mars/mbase/MParList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 7413)
@@ -62,8 +62,7 @@
 // --------------------------------------------------------------------------
 //
-//  default constructor
 //  creates an empty list
 //
-MParList::MParList(const char *name, const char *title)
+void MParList::Init(const char *name, const char *title)
 {
     fName  = name  ? name  : gsDefName.Data();
@@ -83,4 +82,15 @@
 }
 
+
+// --------------------------------------------------------------------------
+//
+//  default constructor
+//  creates an empty list
+//
+MParList::MParList(const char *name, const char *title)
+{
+    Init(name, title);
+}
+
 // --------------------------------------------------------------------------
 //
@@ -90,6 +100,8 @@
 //  entries)
 //
-MParList::MParList(MParList &ts)
-{
+MParList::MParList(const MParList &ts, const char *name, const char *title)
+{
+    Init(name, title);
+
     fContainer->AddAll(ts.fContainer);
 }
Index: trunk/MagicSoft/Mars/mbase/MParList.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParList.h	(revision 7412)
+++ trunk/MagicSoft/Mars/mbase/MParList.h	(revision 7413)
@@ -37,9 +37,11 @@
     void StreamPrimitive(ofstream &out) const;
 
+    void Init(const char *name, const char *title);
+
 public:
     enum { kDoNotReset = BIT(17), kIsProcessing = BIT(18) };
 
     MParList(const char *name=NULL, const char *title=NULL);
-    MParList(MParList &ts);
+    MParList(const MParList &ts, const char *name=NULL, const char *title=NULL);
 
     virtual ~MParList();
Index: trunk/MagicSoft/Mars/mhbase/MBinning.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MBinning.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mhbase/MBinning.cc	(revision 7413)
@@ -242,6 +242,21 @@
 // lowest <lo> and highest <up> Edge (of your histogram)
 //
-void MBinning::SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up)
-{
+void MBinning::SetEdgesLin(Int_t nbins, Axis_t lo, Axis_t up)
+{
+    if (nbins<=0)
+    {
+        *fLog << warn << "WARNING - Number of bins cannot be <= 0... reset to 1." << endl;
+        nbins = 1;
+    }
+
+    if (up<lo)
+    {
+        *fLog << warn << "WARNING - Upper edge must be greater than lower edge... exchanging." << endl;
+
+        const Axis_t dummy(lo);
+        lo = up;
+        up = dummy;
+    }
+
     const Double_t binsize = nbins<=0 ? 0 : (up-lo)/nbins;
     fEdges.Set(nbins+1);
@@ -402,7 +417,21 @@
 // lowest <lo> and highest <up> Edge (of your histogram)
 //
-void MBinning::SetEdgesLog(const Int_t nbins, const Axis_t lo, Axis_t up)
+void MBinning::SetEdgesLog(Int_t nbins, Axis_t lo, Axis_t up)
 {
     // if (lo==0) ...
+    if (nbins<=0)
+    {
+        *fLog << warn << "WARNING - Number of bins cannot be <= 0... reset to 1." << endl;
+        nbins = 1;
+    }
+
+    if (up<lo)
+    {
+        *fLog << warn << "WARNING - Upper edge must be greater than lower edge... exchanging." << endl;
+
+        const Axis_t dummy(lo);
+        lo = up;
+        up = dummy;
+    }
 
     const Double_t binsize = log10(up/lo)/nbins;
@@ -419,6 +448,21 @@
 // lowest [deg] <lo> and highest [deg] <up> Edge (of your histogram)
 //
-void MBinning::SetEdgesCos(const Int_t nbins, const Axis_t lo, Axis_t up)
-{
+void MBinning::SetEdgesCos(Int_t nbins, Axis_t lo, Axis_t up)
+{
+    if (nbins<=0)
+    {
+        *fLog << warn << "WARNING - Number of bins cannot be <= 0... reset to 1." << endl;
+        nbins = 1;
+    }
+
+    if (up<lo)
+    {
+        *fLog << warn << "WARNING - Upper edge must be greater than lower edge... exchanging." << endl;
+
+        const Axis_t dummy(lo);
+        lo = up;
+        up = dummy;
+    }
+
     // if (lo==0) ...
     const Axis_t ld = lo/kRad2Deg;
@@ -436,6 +480,21 @@
 // lowest [deg] <lo> and highest [deg] <up> Edge (of your histogram)
 //
-void MBinning::SetEdgesASin(const Int_t nbins, Axis_t lo, Axis_t up)
-{
+void MBinning::SetEdgesASin(Int_t nbins, Axis_t lo, Axis_t up)
+{
+    if (nbins<=0)
+    {
+        *fLog << warn << "WARNING - Number of bins cannot be <= 0... reset to 1." << endl;
+        nbins = 1;
+    }
+
+    if (up<lo)
+    {
+        *fLog << warn << "WARNING - Upper edge must be greater than lower edge... exchanging." << endl;
+
+        const Axis_t dummy(lo);
+        lo = up;
+        up = dummy;
+    }
+
     const Double_t binsize = nbins<=0 ? 0 : (up-lo)/nbins;
     fEdges.Set(nbins+1);
Index: trunk/MagicSoft/Mars/mhbase/MBinning.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MBinning.h	(revision 7412)
+++ trunk/MagicSoft/Mars/mhbase/MBinning.h	(revision 7413)
@@ -62,9 +62,10 @@
     void SetEdges(const MBinning &bins) { SetEdges(bins.fEdges); fType = bins.fType; fTitle = bins.fTitle; }
     void SetEdges(const TH1 &h, const Char_t axis='x');
-    void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up);
+    void SetEdges(Int_t nbins, const Axis_t lo, const Axis_t up) { SetEdgesLin(nbins, lo, up); }
     void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up, const char *opt);
-    void SetEdgesLog(const Int_t nbins, const Axis_t lo, Axis_t up);
-    void SetEdgesCos(const Int_t nbins, const Axis_t lo, Axis_t up);
-    void SetEdgesASin(const Int_t nbins, Axis_t lo, Axis_t up);
+    void SetEdgesLin(Int_t nbins, Axis_t lo, Axis_t up);
+    void SetEdgesLog(Int_t nbins, Axis_t lo, Axis_t up);
+    void SetEdgesCos(Int_t nbins, Axis_t lo, Axis_t up);
+    void SetEdgesASin(Int_t nbins, Axis_t lo, Axis_t up);
 
     Int_t FindLoEdge(Double_t val) const
Index: trunk/MagicSoft/Mars/mhbase/MH3.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH3.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mhbase/MH3.cc	(revision 7413)
@@ -561,4 +561,6 @@
     TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fHist);
     pad->SetBorderMode(0);
+    pad->SetGridx();
+    pad->SetGridy();
 
     fHist->SetFillStyle(4000);
Index: trunk/MagicSoft/Mars/mhbase/MHMatrix.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MHMatrix.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mhbase/MHMatrix.cc	(revision 7413)
@@ -209,4 +209,13 @@
 }
 
+void MHMatrix::AddColumns(const TCollection &list)
+{
+    TIter Next(&list);
+    TObject *obj = 0;
+    while ((obj=Next()))
+        AddColumn(obj->GetName());
+}
+
+
 // --------------------------------------------------------------------------
 //
Index: trunk/MagicSoft/Mars/mhbase/MHMatrix.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MHMatrix.h	(revision 7412)
+++ trunk/MagicSoft/Mars/mhbase/MHMatrix.h	(revision 7413)
@@ -73,4 +73,5 @@
     Int_t AddColumn(const char *name);
     void AddColumns(MDataArray *mat);
+    void AddColumns(const TCollection &list);
 
     //MDataArray *GetColumns() { return fData; }
Index: trunk/MagicSoft/Mars/mhist/MHHadronness.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHadronness.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mhist/MHHadronness.cc	(revision 7413)
@@ -209,5 +209,5 @@
     const MParameterD &had = par ? *(MParameterD*)par : *fHadronness;
 
-    const Double_t h = had.GetVal();
+    const Double_t h = TMath::Min(TMath::Max(had.GetVal(), 0.), 1.);
 
     if (TMath::IsNaN(h))
Index: trunk/MagicSoft/Mars/mjobs/MDataSet.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MDataSet.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mjobs/MDataSet.cc	(revision 7413)
@@ -196,4 +196,7 @@
     fName  = fname;
 
+    fSequencesOn.SetOwner();
+    fSequencesOff.SetOwner();
+
     const char *expname = gSystem->ExpandPathName(fname);
 
Index: trunk/MagicSoft/Mars/mjobs/MDataSet.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MDataSet.h	(revision 7412)
+++ trunk/MagicSoft/Mars/mjobs/MDataSet.h	(revision 7413)
@@ -54,6 +54,31 @@
 
 public:
-    MDataSet() : fNumAnalysis((UInt_t)-1) { }
+    MDataSet(Int_t num=(UInt_t)-1) : fNumAnalysis(num) { }
     MDataSet(const char *fname, TString sequences="", TString data="");
+
+    void Copy(TObject &obj) const
+    {
+        MDataSet &ds = (MDataSet&)obj;
+        ds.fNumAnalysis = fNumAnalysis;
+        ds.fNumSequencesOn = fNumSequencesOn;
+        ds.fNumSequencesOff = fNumSequencesOff;
+        ds.fNameSource = fNameSource;
+        ds.fCatalog = fCatalog;
+        ds.fComment = fComment;
+        ds.fIsWobbleMode = fIsWobbleMode;
+
+        TObject *o=0;
+
+        ds.fSequencesOn.Delete();
+        ds.fSequencesOff.Delete();
+
+        TIter NextOn(&fSequencesOn);
+        while ((o=NextOn()))
+            ds.fSequencesOn.Add(o->Clone());
+
+        TIter NextOff(&fSequencesOff);
+        while ((o=NextOff()))
+            ds.fSequencesOff.Add(o->Clone());
+    }
 
     // Getter
Index: trunk/MagicSoft/Mars/mjobs/MJCut.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mjobs/MJCut.cc	(revision 7413)
@@ -86,5 +86,5 @@
     : fStoreSummary(kFALSE), fStoreResult(kTRUE), fWriteOnly(kFALSE),
     fIsWobble(kFALSE), fIsMonteCarlo(kFALSE),  fFullDisplay(kTRUE),
-    fNameHist("MHThetaSq"), fCalcHadronness(0)
+    fNameHist("MHThetaSq"), fCalcHadronness(0), fCalcDisp(0)
 {
     fName  = name  ? name  : "MJCut";
@@ -102,4 +102,6 @@
     if (fCalcHadronness)
         delete fCalcHadronness;
+    if (fCalcDisp)
+        delete fCalcDisp;
 }
 
@@ -160,4 +162,15 @@
         delete fCalcHadronness;
     fCalcHadronness = task ? (MTask*)task->Clone() : 0;
+}
+
+// --------------------------------------------------------------------------
+//
+// Setup a task calculating disp. The given task is cloned.
+//
+void MJCut::SetDispCalculator(const MTask *task)
+{
+    if (fCalcDisp)
+        delete fCalcDisp;
+    fCalcDisp = task ? (MTask*)task->Clone() : 0;
 }
 
@@ -540,4 +553,7 @@
     taskenv2.SetDefault(fCalcHadronness);
 
+    MTaskEnv taskenv3("CalcDisp");
+    taskenv3.SetDefault(fCalcDisp);
+
     MFillH fill1a("MHHillasOffPre  [MHHillas]",      "MHillas",      "FillHillasPre");
     MFillH fill2a("MHHillasOffPost [MHHillas]",      "MHillas",      "FillHillasPost");
@@ -579,4 +595,5 @@
     //tlist2.AddToList(&taskenv1);
     tlist2.AddToList(&taskenv2);
+    tlist2.AddToList(&taskenv3);
     tlist2.AddToList(&cont0);
     if (write0)
Index: trunk/MagicSoft/Mars/mjobs/MJCut.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCut.h	(revision 7412)
+++ trunk/MagicSoft/Mars/mjobs/MJCut.h	(revision 7413)
@@ -33,4 +33,5 @@
     //MTask *fEstimateEnergy;
     MTask *fCalcHadronness;
+    MTask *fCalcDisp;
 
     TString  GetOutputFile(UInt_t num) const;
@@ -68,4 +69,5 @@
     //void SetEnergyEstimator(const MTask *task=0);
     void SetHadronnessCalculator(const MTask *task=0);
+    void SetDispCalculator(const MTask *task=0);
 
     ClassDef(MJCut, 0) // Standard program to perform g/h-separation cuts
Index: trunk/MagicSoft/Mars/mjoptim/MJOptimizeDisp.cc
===================================================================
--- trunk/MagicSoft/Mars/mjoptim/MJOptimizeDisp.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mjoptim/MJOptimizeDisp.cc	(revision 7413)
@@ -71,4 +71,6 @@
 
 // histograms
+#include "MH3.h"
+#include "MBinning.h"
 #include "../mhflux/MAlphaFitter.h"
 #include "../mhflux/MHThetaSq.h"
@@ -91,9 +93,9 @@
 //
 // Read all events from file which do match rules and optimize
-// energy estimator.
+// disp estimator.
 //
 Bool_t MJOptimizeDisp::RunDisp(const char *fname, const char *rule, MTask *weights)
 {
-    fLog->Separator("Preparing Energy optimization");
+    fLog->Separator("Preparing Disp optimization");
 
     MParList parlist;
@@ -124,10 +126,12 @@
     const Int_t num1 = m.AddColumn("MHillasSrc.fDist*MGeomCam.fConvMm2Deg");
     const Int_t num2 = m.AddColumn("MHillasSrc.fAlpha*kDegToRad");
+    const Int_t num3 = m.AddColumn("MHillas.fSize");
 
     MHThetaSq hist;
     hist.SkipHistTime();
     hist.SkipHistTheta();
-    hist.SkipHistEnergy();
-    hist.InitMapping(&m); 
+    //hist.SkipHistEnergy();
+    //hist.ForceUsingSize();
+    hist.InitMapping(&m, 1);
 
     MFDataMember filter("DataType.fVal", '>', 0.5);
@@ -171,4 +175,17 @@
     MMatrixLoop loop(&m);
 
+    const char *n3   = Form("M[%d]", num3);
+    MH3 hdisp(n3, "sqrt(ThetaSquared.fVal)");
+    hdisp.SetTitle("\\vartheta^{2} distribution vs. Size:Size [phe]:\\vartheta^{2} [\\circ^{2}]");
+
+    MBinning binsx(100, 10, 100000, "BinningMH3X", "log");
+    MBinning binsy(100, 0,  2,      "BinningMH3Y", "lin");
+
+    parlist.AddToList(&binsx);
+    parlist.AddToList(&binsy);
+
+    MFillH fillh2(&hdisp);
+    fillh2.SetDrawOption("blue profx");
+
     tasklist.AddToList(&loop);
     tasklist.AddToList(&calc1);
@@ -177,4 +194,5 @@
         tasklist.AddToList(weights);
     tasklist.AddToList(&fill);
+    tasklist.AddToList(&fillh2);
     tasklist.AddToList(&eval);
 
Index: trunk/MagicSoft/Mars/mranforest/MHRanForestGini.cc
===================================================================
--- trunk/MagicSoft/Mars/mranforest/MHRanForestGini.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mranforest/MHRanForestGini.cc	(revision 7413)
@@ -43,4 +43,5 @@
 #include "MRanTree.h"
 #include "MRanForest.h"
+#include "MDataArray.h"
 
 #include "MLog.h"
@@ -57,4 +58,5 @@
 //
 MHRanForestGini::MHRanForestGini(Int_t nbins, const char *name, const char *title)
+    : fRules(0.01, 0.01, 0.99, 0.99)
 {
     //
@@ -64,16 +66,15 @@
     fTitle = title ? title : "Measure of importance of Random Forest-input parameters";
 
-    fGraphGini = new TGraph;
-    fGraphGini->SetTitle("Importance of RF-input parameters measured by mean Gini decrease");
-    fGraphGini->SetMarkerStyle(kFullDotSmall);
-}
-
-// --------------------------------------------------------------------------
-//
-// Delete the histograms.
-//
-MHRanForestGini::~MHRanForestGini()
-{
-    delete fGraphGini;
+    fGraphGini.SetNameTitle("Gini", "Importance of RF-input parameters measured by mean Gini decrease");
+    fGraphGini.SetMarkerStyle(kFullDotMedium);
+
+    fGraphError.SetNameTitle("ResErr", "Resolution/Error versus train step");
+    fGraphError.SetMarkerStyle(kFullDotMedium);
+
+    fGraphNodes.SetNameTitle("Nodes", "Number of nodes versus train step");
+    fGraphNodes.SetMarkerStyle(kFullDotMedium);
+
+    fRules.SetTextAlign(13);
+    fRules.SetTextSize(0.05);
 }
 
@@ -104,6 +105,11 @@
 Bool_t MHRanForestGini::Fill(const MParContainer *par, const Stat_t w)
 {
+    MRanTree *t = fRanForest->GetCurTree();
+
     for (Int_t i=0;i<fRanForest->GetNumDim();i++)
-        fGini[i]+=fRanForest->GetCurTree()->GetGiniDec(i);
+        fGini[i] += t->GetGiniDec(i);
+
+    fGraphError.SetPoint(fGraphError.GetN(), GetNumExecutions(), t->GetError());
+    fGraphNodes.SetPoint(fGraphError.GetN(), GetNumExecutions(), t->GetNumEndNodes());
 
     return kTRUE;
@@ -117,27 +123,25 @@
     const Int_t n = fGini.GetSize();
 
-    fGraphGini->Set(n);
-
-    Stat_t max=0;
-    Stat_t min=0;
+    fGraphGini.Set(n);
+
     for (Int_t i=0; i<n; i++)
     {
-        fGini[i] /= fRanForest->GetNumTrees();
-        fGini[i] /= fRanForest->GetNumData();
-
-        const Stat_t ip = i+1;
-        const Stat_t ig = fGini[i];
-
-        if (ig>max) max=ig;
-        if (ig<min) min=ig;
-
-        fGraphGini->SetPoint(i,ip,ig);
-    }
-
-    // This is used in root>3.04/? so that SetMaximum/Minimum can succeed
-    fGraphGini->GetHistogram();
-
-    fGraphGini->SetMaximum(1.05*max);
-    fGraphGini->SetMinimum(0.95*min);
+        fGini[i] /= fRanForest->GetNumTrees()*fRanForest->GetNumData();
+        fGraphGini.SetPoint(i, i+1, fGini[i]);
+    }
+
+    fRules.AddText("");
+    const MDataArray &arr = *fRanForest->GetRules();
+    int i;
+    for (i=0; i<arr.GetNumEntries(); i++)
+    {
+        TString s;
+        s += i+1;
+        s += ") ";
+        s += arr.GetRule(i);
+        fRules.AddText(s);
+    }
+    for (; i<20; i++)
+        fRules.AddText("");
 
     return kTRUE;
@@ -150,5 +154,5 @@
 void MHRanForestGini::Draw(Option_t *)
 {
-    if (fGraphGini->GetN()==0)
+    if (fGraphGini.GetN()==0)
         return;
 
@@ -158,17 +162,42 @@
     AppendPad("");
 
-    fGraphGini->Draw("ALP");
-    pad->Modified();
-    pad->Update();
-
-    TH1 *h = fGraphGini->GetHistogram();
-    if (!h)
-        return;
-
-    //h->GetXaxis()->SetRangeUser(0, fGini.GetSize()+1);
-    h->SetXTitle("No.of RF-input parameter");
-    h->SetYTitle("Mean decrease in Gini-index [a.u.]");
-
-    pad->Modified();
-    pad->Update();
-}
+    pad->Divide(2,2);
+
+    pad->cd(1);
+    gPad->SetBorderMode(0);
+    gPad->SetGridx();
+    gPad->SetGridy();
+    fGraphGini.Draw("ALP");
+
+    TH1 *h = fGraphGini.GetHistogram();
+    if (h)
+    {
+        h->SetXTitle("No.of RF-input parameter");
+        h->SetYTitle("Mean decrease in Gini-index [au]");
+        h->GetXaxis()->SetNdivisions(10);
+    }
+
+    pad->cd(2);
+    gPad->SetBorderMode(0);
+    fGraphError.Draw("ALP");
+    h = fGraphError.GetHistogram();
+    if (h)
+    {
+        h->SetXTitle("Train step/Tree number");
+        h->SetYTitle("Error/Resolution");
+    }
+
+    pad->cd(3);
+    gPad->SetBorderMode(0);
+    fGraphNodes.Draw("ALP");
+    h = fGraphNodes.GetHistogram();
+    if (h)
+    {
+        h->SetXTitle("Train step/Tree number");
+        h->SetYTitle("Number of end nodes");
+    }
+
+    pad->cd(4);
+    gPad->SetBorderMode(0);
+    fRules.Draw();
+}
Index: trunk/MagicSoft/Mars/mranforest/MHRanForestGini.h
===================================================================
--- trunk/MagicSoft/Mars/mranforest/MHRanForestGini.h	(revision 7412)
+++ trunk/MagicSoft/Mars/mranforest/MHRanForestGini.h	(revision 7413)
@@ -9,7 +9,11 @@
 #include <TArrayF.h>
 #endif
+#ifndef ROOT_TGraph
+#include <TGraph.h>
+#endif
+#ifndef ROOT_TPaveText
+#include <TPaveText.h>
+#endif
 
-class TH1D;
-class TGraph;
 class MParList;
 class MRanForest;
@@ -22,11 +26,13 @@
 
     TArrayF fGini;           //!
-    TGraph *fGraphGini;      //->
+
+    TGraph  fGraphGini;
+    TGraph  fGraphError;
+    TGraph  fGraphNodes;
+
+    TPaveText fRules;
 
 public:
     MHRanForestGini(Int_t nbins=100, const char *name=NULL, const char *title=NULL);
-    ~MHRanForestGini();
-
-    TGraph *GetGraphGini() const  { return fGraphGini; }
 
     Bool_t SetupFill(const MParList *plist);
Index: trunk/MagicSoft/Mars/mranforest/MRanForest.cc
===================================================================
--- trunk/MagicSoft/Mars/mranforest/MRanForest.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mranforest/MRanForest.cc	(revision 7413)
@@ -166,5 +166,5 @@
         if(grid[i]>=grid[i+1])
         {
-            *fLog<<inf<<"Grid points must be in increasing order! Ignoring grid."<<endl;
+            *fLog<<warn<<"Grid points must be in increasing order! Ignoring grid."<<endl;
             return;
         }
@@ -225,6 +225,4 @@
             fClass[j] = int(fHadTrue[j]+0.5);
     }
-
-    return;
 }
 
@@ -272,5 +270,5 @@
 Bool_t MRanForest::AddTree(MRanTree *rantree=NULL)
 {
-    fRanTree = rantree ? rantree:fRanTree;
+    fRanTree = rantree ? rantree : fRanTree;
 
     if (!fRanTree) return kFALSE;
@@ -287,9 +285,8 @@
     // access matrix, copy last column (target) preliminarily
     // into fHadTrue
-    TMatrix mat_tmp = mat->GetM();
-    int dim         = mat_tmp.GetNcols();
-    int numdata     = mat_tmp.GetNrows();
-
-    fMatrix=new TMatrix(mat_tmp);
+    fMatrix = new TMatrix(mat->GetM());
+
+    int dim     = fMatrix->GetNcols()-1;
+    int numdata = fMatrix->GetNrows();
 
     fHadTrue.Set(numdata);
@@ -297,9 +294,8 @@
 
     for (Int_t j=0;j<numdata;j++)
-        fHadTrue[j] = (*fMatrix)(j,dim-1);
+        fHadTrue[j] = (*fMatrix)(j,dim);
 
     // remove last col
-    fMatrix->ResizeTo(numdata,dim-1);
-    dim=fMatrix->GetNcols();
+    fMatrix->ResizeTo(numdata,dim);
 
     //-------------------------------------------------------------------
@@ -308,12 +304,20 @@
     fClass.Reset(0);
 
-    if(fClassify) PrepareClasses();
+    if (fClassify)
+        PrepareClasses();
 
     //-------------------------------------------------------------------
     // allocating and initializing arrays
-    fHadEst.Set(numdata);       fHadEst.Reset(0);
-    fNTimesOutBag.Set(numdata); fNTimesOutBag.Reset(0);
-    fDataSort.Set(dim*numdata); fDataSort.Reset(0);
-    fDataRang.Set(dim*numdata); fDataRang.Reset(0);
+    fHadEst.Set(numdata);
+    fHadEst.Reset(0);
+
+    fNTimesOutBag.Set(numdata);
+    fNTimesOutBag.Reset(0);
+
+    fDataSort.Set(dim*numdata);
+    fDataSort.Reset(0);
+
+    fDataRang.Set(dim*numdata);
+    fDataRang.Reset(0);
 
     if(fWeight.GetSize()!=numdata)
@@ -326,5 +330,5 @@
     //-------------------------------------------------------------------
     // setup rules to be used for classification/regression
-    MDataArray *allrules=(MDataArray*)mat->GetColumns();
+    const MDataArray *allrules=(MDataArray*)mat->GetColumns();
     if(allrules==NULL)
     {
@@ -333,36 +337,28 @@
     }
 
-    fRules=new MDataArray(); fRules->Reset();
-    TString target_rule;
-
-    for(Int_t i=0;i<dim+1;i++)
-    {
-        MData &data=(*allrules)[i];
-        if(i<dim)
-            fRules->AddEntry(data.GetRule());
-        else
-            target_rule=data.GetRule();
-    }
-
-    *fLog << inf <<endl;
-    *fLog << inf <<"Setting up RF for training on target:"<<endl<<" "<<target_rule.Data()<<endl;
-    *fLog << inf <<"Following rules are used as input to RF:"<<endl;
-
-    for(Int_t i=0;i<dim;i++)
-    {
-        MData &data=(*fRules)[i];
-        *fLog<<inf<<" "<<i<<") "<<data.GetRule()<<endl<<flush;
-    }
-
-    *fLog << inf <<endl;
+    fRules = new MDataArray();
+    fRules->Reset();
+
+    const TString target_rule = (*allrules)[dim];
+    for (Int_t i=0;i<dim;i++)
+        fRules->AddEntry((*allrules)[i].GetRule());
+
+    *fLog << inf << endl;
+    *fLog << "Setting up RF for training on target:" << endl;
+    *fLog << " " << target_rule.Data() << endl;
+    *fLog << "Following rules are used as input to RF:" << endl;
+    for (Int_t i=0;i<dim;i++)
+        *fLog << " " << i << ") " << (*fRules)[i].GetRule() << endl;
+
+    *fLog << endl;
 
     //-------------------------------------------------------------------
     // prepare (sort) data for fast optimization algorithm
-    if(!CreateDataSort()) return kFALSE;
+    if (!CreateDataSort())
+        return kFALSE;
 
     //-------------------------------------------------------------------
     // access and init tree container
     fRanTree = (MRanTree*)plist->FindCreateObj("MRanTree");
-
     if(!fRanTree)
     {
@@ -371,25 +367,28 @@
     }
 
+    const Int_t tryest = TMath::Nint(TMath::Sqrt(dim)+0.5);
+
+    *fLog << inf << endl;
+    *fLog << "Following input for the tree growing are used:"<<endl;
+    *fLog << " Number of Trees : "<<fNumTrees<<endl;
+    *fLog << " Number of Trials: "<<(fNumTry==0?tryest:fNumTry)<<(fNumTry==0?" (auto)":"")<<endl;
+    *fLog << " Final Node size : "<<fNdSize<<endl;
+    *fLog << " Using Grid:       "<<(fGrid.GetSize()>0?"Yes":"No")<<endl;
+    *fLog << " Number of Events: "<<numdata<<endl;
+    *fLog << " Number of Params: "<<dim<<endl;
+
+    if(fNumTry==0)
+    {
+        fNumTry=tryest;
+        *fLog << inf << endl;
+        *fLog << "Set no. of trials to the recommended value of round("<< TMath::Sqrt(dim) <<") = ";
+        *fLog << fNumTry << endl;
+
+
+    }
+    fRanTree->SetNumTry(fNumTry);
     fRanTree->SetClassify(fClassify);
     fRanTree->SetNdSize(fNdSize);
 
-    if(fNumTry==0)
-    {
-        double ddim = double(dim);
-
-        fNumTry=int(sqrt(ddim)+0.5);
-        *fLog<<inf<<endl;
-        *fLog<<inf<<"Set no. of trials to the recommended value of round("<<sqrt(ddim)<<") = ";
-        *fLog<<inf<<fNumTry<<endl;
-
-    }
-    fRanTree->SetNumTry(fNumTry);
-
-    *fLog<<inf<<endl;
-    *fLog<<inf<<"Following settings for the tree growing are used:"<<endl;
-    *fLog<<inf<<" Number of Trees : "<<fNumTrees<<endl;
-    *fLog<<inf<<" Number of Trials: "<<fNumTry<<endl;
-    *fLog<<inf<<" Final Node size : "<<fNdSize<<endl;
-
     fTreeNo=0;
 
@@ -415,6 +414,5 @@
     if (fTreeNo==1)
     {
-        *fLog << inf << endl;
-        *fLog << underline;
+        *fLog << inf << endl << underline;
 
         if(calcResolution)
@@ -435,5 +433,6 @@
     TArrayF winbag(numdata); // Initialization includes filling with 0
 
-    float square=0; float mean=0;
+    float square=0;
+    float mean=0;
 
     for (Int_t n=0; n<numdata; n++)
@@ -483,5 +482,6 @@
     for (Int_t ievt=0;ievt<numdata;ievt++)
     {
-        if (jinbag[ievt]>0) continue;
+        if (jinbag[ievt]>0)
+            continue;
 
         fHadEst[ievt] +=fRanTree->TreeHad((*fMatrix), ievt);
@@ -491,5 +491,5 @@
 
     Int_t n=0;
-    double ferr=0;
+    Float_t ferr=0;
 
     for (Int_t ievt=0;ievt<numdata;ievt++)
@@ -508,8 +508,10 @@
     //-------------------------------------------------------------------
     // give running output
-    *fLog << inf << setw(5)  << fTreeNo;
-    *fLog << inf << setw(18) << fRanTree->GetNumEndNodes();
-    *fLog << inf << Form("%18.2f", ferr*100.);
-    *fLog << inf << endl;
+    *fLog << setw(5)  << fTreeNo;
+    *fLog << setw(18) << fRanTree->GetNumEndNodes();
+    *fLog << Form("%18.2f", ferr*100.);
+    *fLog << endl;
+
+    fRanTree->SetError(ferr);
 
     // adding tree to forest
Index: trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mranforest/MRanForestCalc.cc	(revision 7413)
@@ -16,7 +16,8 @@
 !
 !
-!   Author(s): Thomas Hengstebeck 3/2003 <mailto:hengsteb@alwa02.physik.uni-siegen.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2003
+!   Author(s): Thomas Hengstebeck 2/2005 <mailto:hengsteb@physik.hu-berlin.de>
+!   Author(s): Thomas Bretz 8/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2005
 !
 !
@@ -27,9 +28,4 @@
 //  MRanForestCalc
 //
-//  Calculates the hadroness of an event. It calculates a mean value of all
-//  classifications by the trees in a previously grown random forest.
-//
-//  To use only n trees for your calculation use:
-//  MRanForestCalc::SetUseNumTrees(n);
 //
 ////////////////////////////////////////////////////////////////////////////
@@ -38,26 +34,20 @@
 #include <TVector.h>
 
-#include "MHMatrix.h" // must be before MLogManip.h
-#include "MDataArray.h"
+#include "MHMatrix.h"
 
 #include "MLog.h"
 #include "MLogManip.h"
 
+#include "MData.h"
+#include "MDataArray.h"
+
+#include "MRanForest.h"
+#include "MParameters.h"
+
 #include "MParList.h"
-
-#include "MRanTree.h"
-#include "MRanForest.h"
-
-#include "MParameters.h"
-
+#include "MTaskList.h"
 #include "MEvtLoop.h"
-#include "MTaskList.h"
+#include "MRanForestGrow.h"
 #include "MFillH.h"
-#include "MStatusDisplay.h"
-#include "MRanForestGrow.h"
-#include "MRanForestFill.h"
-
-#include "MWriteRootFile.h"
-#include "MReadTree.h"
 
 ClassImp(MRanForestCalc);
@@ -65,85 +55,309 @@
 using namespace std;
 
-static const TString gsDefName  = "MRanForestCalc";
-static const TString gsDefTitle = "Tree Classification Loop 1/2";
-
-// --------------------------------------------------------------------------
-//
-// Setup histograms and the number of distances which are used for
-// avaraging in CalcDist
-//
+const TString MRanForestCalc::gsDefName    = "MRanForestCalc";
+const TString MRanForestCalc::gsDefTitle   = "RF for energy estimation";
+
+const TString MRanForestCalc::gsNameOutput = "RanForestOut";
+
 MRanForestCalc::MRanForestCalc(const char *name, const char *title)
-    : fNum(100), fHadronnessName("MHadronness"), fData(NULL), fRanForest(0), fRanTree(0)
-{
-    //
-    //   set the name and title of this object
-    //
+    : fDebug(kFALSE), fData(0), fRFOut(0),
+    fNumTrees(-1), fNumTry(-1), fNdSize(-1), fNumObsoleteVariables(1),
+    fTestMatrix(0), fEstimationMode(kMean)
+{
     fName  = name  ? name  : gsDefName.Data();
     fTitle = title ? title : gsDefTitle.Data();
-}
-
-// --------------------------------------------------------------------------
-//
-// Delete the data chains
-//
+
+    // FIXME:
+    fNumTrees = 100; //100
+    fNumTry   = 0;   //3   0 means: in MRanForest estimated best value will be calculated
+    fNdSize   = 1;   //1   
+}
+
 MRanForestCalc::~MRanForestCalc()
 {
-    if (!IsOwner())
-        return;
-
-    delete fRanForest;
-    delete fRanTree;
-}
-
-// --------------------------------------------------------------------------
-//
-// Needs:
-//  - MatrixGammas  [MHMatrix]
-//  - MatrixHadrons [MHMatrix]
-//  - MHadronness
-//  - all data containers used to build the matrixes
-//
-// The matrix object can be filles using MFillH. And must be of the same
-// number of columns (with the same meaning).
-//
+    fEForests.Delete();
+}
+
+Int_t MRanForestCalc::Train(const MHMatrix &matrixtrain, const TArrayD &grid, Int_t ver)
+{
+    gLog.Separator("MRanForestCalc - Train");
+
+    if (!matrixtrain.GetColumns())
+    {
+        *fLog << err << "ERROR - MHMatrix does not contain rules... abort." << endl;
+        return kFALSE;
+    }
+
+    const Int_t ncols = matrixtrain.GetM().GetNcols();
+    const Int_t nrows = matrixtrain.GetM().GetNrows();
+    if (ncols<=0 || nrows <=0)
+    {
+        *fLog << err << "ERROR - No. of columns or no. of rows of matrixtrain equal 0 ... abort." << endl;
+        return kFALSE;
+    }
+
+    // rules (= combination of image par) to be used for energy estimation
+    TFile fileRF(fFileName, "recreate");
+    if (!fileRF.IsOpen())
+    {
+        *fLog << err << "ERROR - File to store RFs could not be opened... abort." << endl;
+        return kFALSE;
+    }
+
+    const Int_t nobs = fNumObsoleteVariables; // Number of obsolete columns
+
+    const MDataArray &dcol = *matrixtrain.GetColumns();
+
+    MDataArray usedrules;
+    for (Int_t i=0; i<ncols; i++)
+        if (i<ncols-nobs)  // -3 is important!!!
+            usedrules.AddEntry(dcol[i].GetRule());
+        else
+            *fLog << inf << "Skipping " << dcol[i].GetRule() << " for training" << endl;
+
+    MDataArray rules(usedrules);
+    rules.AddEntry(ver<2?"Classification":dcol[ncols-1].GetRule());
+
+    // prepare matrix for current energy bin
+    TMatrix mat(matrixtrain.GetM());
+
+    // last column must be removed (true energy col.)
+    mat.ResizeTo(nrows, ncols-nobs+1);
+
+    if (fDebug)
+        gLog.SetNullOutput(kTRUE);
+
+    const Int_t nbins = ver>0 ? 1 : grid.GetSize()-1;
+    for (Int_t ie=0; ie<nbins; ie++)
+    {
+        switch (ver)
+        {
+        case 0: // Replace Energy Grid by classification
+            {
+                Int_t irows=0;
+                for (Int_t j=0; j<nrows; j++)
+                {
+                    const Double_t energy = matrixtrain.GetM()(j,ncols-1);
+                    const Bool_t   inside = energy>grid[ie] && energy<=grid[ie+1];
+
+                    mat(j, ncols-nobs) = inside ? 1 : 0;
+
+                    if (inside)
+                        irows++;
+                }
+                if (irows==0)
+                    *fLog << warn << "WARNING - Skipping";
+                else
+                    *fLog << inf << "Training RF for";
+
+                *fLog << " energy bin " << ie << " (" << grid[ie] << ", " << grid[ie+1] << ") " << irows << "/" << nrows << endl;
+
+                if (irows==0)
+                    continue;
+            }
+            break;
+
+        case 1: // Use Energy as classifier
+        case 2:
+            for (Int_t j=0; j<nrows; j++)
+                mat(j, ncols-nobs) = matrixtrain.GetM()(j,ncols-1);
+            break;
+        }
+
+        MHMatrix matrix(mat, &rules, "MatrixTrain");
+
+        MParList plist;
+        MTaskList tlist;
+        plist.AddToList(&tlist);
+        plist.AddToList(&matrix);
+
+        MRanForest rf;
+        rf.SetNumTrees(fNumTrees);
+        rf.SetNumTry(fNumTry);
+        rf.SetNdSize(fNdSize);
+        rf.SetClassify(ver<2 ? 1 : 0);
+        if (ver==1)
+            rf.SetGrid(grid);
+
+        plist.AddToList(&rf);
+
+        MRanForestGrow rfgrow;
+        tlist.AddToList(&rfgrow);
+
+        MFillH fillh("MHRanForestGini");
+        tlist.AddToList(&fillh);
+
+        MEvtLoop evtloop;
+        evtloop.SetParList(&plist);
+        evtloop.SetDisplay(fDisplay);
+        evtloop.SetLogStream(fLog);
+
+        if (!evtloop.Eventloop())
+            return kFALSE;
+
+        if (fDebug)
+            gLog.SetNullOutput(kFALSE);
+
+        if (ver==0)
+        {
+            // Calculate bin center
+            const Double_t E = (TMath::Log10(grid[ie])+TMath::Log10(grid[ie+1]))/2;
+
+            // save whole forest
+            rf.SetUserVal(E);
+            rf.SetName(Form("%.10f", E));
+        }
+
+        rf.Write();
+    }
+
+    // save rules
+    usedrules.Write("rules");
+
+    return kTRUE;
+}
+
+Int_t MRanForestCalc::ReadForests(MParList &plist)
+{
+    TFile fileRF(fFileName, "read");
+    if (!fileRF.IsOpen())
+    {
+        *fLog << err << dbginf << "File containing RFs could not be opened... aborting." << endl;
+        return kFALSE;
+    }
+
+    fEForests.Delete();
+
+    TIter Next(fileRF.GetListOfKeys());
+    TObject *o=0;
+    while ((o=Next()))
+    {
+        MRanForest *forest=0;
+        fileRF.GetObject(o->GetName(), forest);
+        if (!forest)
+            continue;
+
+        forest->SetUserVal(atof(o->GetName()));
+
+        fEForests.Add(forest);
+    }
+
+    // Maybe fEForests[0].fRules yould be used instead?
+
+    if (fData->Read("rules")<=0)
+    {
+        *fLog << err << "ERROR - Reading 'rules' from file " << fFileName << endl;
+        return kFALSE;
+    }
+
+    return kTRUE;
+}
+
 Int_t MRanForestCalc::PreProcess(MParList *plist)
 {
-    if (!fRanForest)
-    {
-        fRanForest = (MRanForest*)plist->FindObject("MRanForest");
-        if (!fRanForest)
+    fRFOut = (MParameterD*)plist->FindCreateObj("MParameterD", fNameOutput);
+    if (!fRFOut)
+        return kFALSE;
+
+    fData = (MDataArray*)plist->FindCreateObj("MDataArray");
+    if (!fData)
+        return kFALSE;
+
+    if (!ReadForests(*plist))
+    {
+        *fLog << err << "Reading RFs failed... aborting." << endl;
+        return kFALSE;
+    }
+
+    *fLog << inf << "RF read from " << fFileName << endl;
+
+    if (fTestMatrix)
+        return kTRUE;
+
+    fData->Print();
+
+    if (!fData->PreProcess(plist))
+    {
+        *fLog << err << "PreProcessing of the MDataArray failed... aborting." << endl;
+        return kFALSE;
+    }
+
+    return kTRUE;
+}
+
+#include <TGraph.h>
+#include <TF1.h>
+Int_t MRanForestCalc::Process()
+{
+    TVector event;
+    if (fTestMatrix)
+        *fTestMatrix >> event;
+    else
+        *fData >> event;
+
+    // --------------- Single Tree RF -------------------
+    if (fEForests.GetEntries()==1)
+    {
+        MRanForest *rf = (MRanForest*)fEForests[0];
+        fRFOut->SetVal(rf->CalcHadroness(event));
+        fRFOut->SetReadyToSave();
+
+        return kTRUE;
+    }
+
+    // --------------- Multi Tree RF -------------------
+    static TF1 f1("f1", "gaus");
+
+    Double_t sume = 0;
+    Double_t sumh = 0;
+    Double_t maxh = 0;
+    Double_t maxe = 0;
+
+    Double_t max  = -1e10;
+    Double_t min  =  1e10;
+
+    TIter Next(&fEForests);
+    MRanForest *rf = 0;
+
+    TGraph g;
+    while ((rf=(MRanForest*)Next()))
+    {
+        const Double_t h = rf->CalcHadroness(event);
+        const Double_t e = rf->GetUserVal();
+
+        g.SetPoint(g.GetN(), e, h);
+
+        sume += e*h;
+        sumh += h;
+
+        if (h>maxh)
         {
-            *fLog << err << dbginf << "MRanForest not found... aborting." << endl;
-            return kFALSE;
+            maxh = h;
+            maxe = e;
         }
-    }
-
-    if (!fRanTree)
-    {
-        fRanTree = (MRanTree*)plist->FindObject("MRanTree");
-        if (!fRanTree)
-        {
-            *fLog << err << dbginf << "MRanTree not found... aborting." << endl;
-            return kFALSE;
-        }
-    }
-
-    fData = fRanTree->GetRules();
-
-    if (!fData)
-    {
-        *fLog << err << dbginf << "Error matrix doesn't contain columns... aborting." << endl;
-        return kFALSE;
-    }
-
-    if (!fData->PreProcess(plist))
-    {
-        *fLog << err << dbginf << "PreProcessing of the MDataArray failed for the columns failed... aborting." << endl;
-        return kFALSE;
-    }
-
-    fHadroness = (MParameterD*)plist->FindCreateObj("MParameterD", fHadronnessName);
-    if (!fHadroness)
-        return kFALSE;
+        if (e>max)
+            max = e;
+        if (e<min)
+            min = e;
+    }
+
+    switch (fEstimationMode)
+    {
+    case kMean:
+        fRFOut->SetVal(pow(10, sume/sumh));
+        break;
+    case kMaximum:
+        fRFOut->SetVal(pow(10, maxe));
+        break;
+    case kFit:
+        f1.SetParameter(0, maxh);
+        f1.SetParameter(1, maxe);
+        f1.SetParameter(2, 0.125);
+        g.Fit(&f1, "Q0N");
+        fRFOut->SetVal(pow(10, f1.GetParameter(1)));
+        break;
+    }
+
+    fRFOut->SetReadyToSave();
 
     return kTRUE;
@@ -153,165 +367,35 @@
 //
 //
-Int_t MRanForestCalc::Process()
-{
-    // first copy the data from the data array to a vector event
-    TVector event;
-    *fData >> event;
-
-    Double_t hadroness=fRanForest->CalcHadroness(event);
-    fHadroness->SetVal(hadroness);
-
-    return kTRUE;
-}
-
-Bool_t MRanForestCalc::Grow(MHMatrix *matrixg,MHMatrix *matrixh,Int_t ntree,
-                            Int_t numtry,Int_t ndsize,const char* treefile,
-                            const char* treename,const char* contname,
-                            const char* hgininame)
-{
-
-    treename  = treename  ? treename  : "Tree";
-    contname  = contname  ? contname  : "MRanTree";
-    hgininame  = hgininame  ? hgininame  : "MHRanForestGini";
-
-    if (!matrixg->IsValid())
-    {
-        *fLog << err << dbginf << " MRanForestCalc::Grow - ERROR: matrixg not valid." << endl;
-        return kFALSE;
-    }
-    if(!matrixh->IsValid())
-    {
-        *fLog << err << dbginf << " MRanForestCalc::Grow - ERROR: matrixh not valid." << endl;
-        return kFALSE;
-    }
-
-    MEvtLoop run(GetName());
-    MTaskList tlist;
-    MParList plist;
-    plist.AddToList(&tlist);
-    plist.AddToList(matrixg);
-    plist.AddToList(matrixh);
-
-    // creating training task and setting parameters
-    MRanForestGrow rfgrow;
-    rfgrow.SetNumTrees(ntree); // number of trees
-    rfgrow.SetNumTry(numtry);  // number of trials in random split selection
-    rfgrow.SetNdSize(ndsize);  // limit for nodesize
-    tlist.AddToList(&rfgrow);
-
-    if(treefile){
-        MWriteRootFile rfwrite(treefile);
-        rfwrite.AddContainer(contname,treename);
-        tlist.AddToList(&rfwrite);
-    }
-
-    MFillH fillh(hgininame);
-    tlist.AddToList(&fillh);
-
-    run.SetParList(&plist);
-    
-    // Execute tree growing
-    if (!run.Eventloop())
-    {
-        *fLog << err << dbginf << "Evtloop in MRanForestCalc::Grow failed." << endl;
-        return kFALSE;
-    }
-    tlist.PrintStatistics(0, kTRUE);
-
-    if (TestBit(kEnableGraphicalOutput))
-        plist.FindObject(hgininame)->DrawClone();
-
-    return kTRUE;
-}
-
-Bool_t MRanForestCalc::Fill(Int_t ntree,const char* treefile,const char* treename)
-{
-    treefile  = treefile  ? treefile  : "RF.root";
-    treename  = treename  ? treename  : "Tree";
-
-    MParList  plist;
-
-    MTaskList tlist;
-    plist.AddToList(&tlist);
-
-    MReadTree read(treename,treefile);
-    read.DisableAutoScheme();
-
-    MRanForestFill rffill;
-    rffill.SetNumTrees(ntree);
-
-    tlist.AddToList(&read);
-    tlist.AddToList(&rffill);
-
-    MEvtLoop run(GetName());
-    run.SetParList(&plist);
-
-    //
-    // Execute tree reading
-    //
-    if (!run.Eventloop())
-    {
-        *fLog << err << dbginf << "Evtloop in MRanForestCalc::Fill failed." << endl;
-        return kFALSE;
-    }
-    tlist.PrintStatistics(0, kTRUE);
-
-    return kTRUE;
-}
-
 Int_t MRanForestCalc::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
 {
-    if (!IsEnvDefined(env, prefix, "File",     print))
-        return kFALSE;
-
-    TString fname = GetEnvValue(env, prefix, "File", "RF.root");
-    TString tname = GetEnvValue(env, prefix, "Tree", "Tree");
-    const Int_t   num   = GetEnvValue(env, prefix, "NumTrees", 100);
-    const Bool_t  debug = GetEnvValue(env, prefix, "Debug", kFALSE);
-
-    fname.ReplaceAll("\015", "");
-    tname.ReplaceAll("\015", "");
-
-    *fLog << inf << dbginf << "Reading " << num << " trees " << tname << " from file " << fname << endl;
-
-    gLog.SetNullOutput(!debug);
-    MEvtLoop evtloop;
-    MParList  plist;
-    evtloop.SetParList(&plist);
-    MLog l;
-    l.SetNullOutput(!debug);
-    evtloop.SetLogStream(&l);
-    gLog.SetNullOutput(debug);
-
-    if (IsOwner())
-    {
-        delete fRanForest;
-        delete fRanTree;
-    }
-    fRanForest = new MRanForest;
-    fRanTree   = new MRanTree;
-    SetOwner();
-
-    plist.AddToList(fRanForest);
-    plist.AddToList(fRanTree);
-
-    MTaskList tlist;
-    plist.AddToList(&tlist);
-
-    MReadTree read(tname, fname);
-    read.DisableAutoScheme();
-
-    MRanForestFill rffill;
-    rffill.SetNumTrees(num);
-
-    tlist.AddToList(&read);
-    tlist.AddToList(&rffill);
-
-    if (!evtloop.Eventloop())
-    {
-        *fLog << err << "ERROR - Reading " << tname << " from file " << fname << endl;
-        return kERROR;
-    }
-
-    return kTRUE;
-}
+    Bool_t rc = kFALSE;
+    if (IsEnvDefined(env, prefix, "FileName", print))
+    {
+        rc = kTRUE;
+        SetFileName(GetEnvValue(env, prefix, "FileName", fFileName));
+    }
+    if (IsEnvDefined(env, prefix, "Debug", print))
+    {
+        rc = kTRUE;
+        SetDebug(GetEnvValue(env, prefix, "Debug", fDebug));
+    }
+    if (IsEnvDefined(env, prefix, "NameOutput", print))
+    {
+        rc = kTRUE;
+        SetNameOutput(GetEnvValue(env, prefix, "NameOutput", fNameOutput));
+    }
+    if (IsEnvDefined(env, prefix, "EstimationMode", print))
+    {
+        TString txt = GetEnvValue(env, prefix, "EstimationMode", "");
+        txt = txt.Strip(TString::kBoth);
+        txt.ToLower();
+        if (txt==(TString)"mean")
+            fEstimationMode = kMean;
+        if (txt==(TString)"maximum")
+            fEstimationMode = kMaximum;
+        if (txt==(TString)"fit")
+            fEstimationMode = kFit;
+        rc = kTRUE;
+    }
+    return rc;
+}
Index: trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h	(revision 7412)
+++ trunk/MagicSoft/Mars/mranforest/MRanForestCalc.h	(revision 7413)
@@ -6,33 +6,64 @@
 #endif
 
-#ifndef MARS_MHMatrix
-#include "MHMatrix.h"
+#ifndef ROOT_TObjArray
+#include <TObjArray.h>
 #endif
 
-class MParList;
+#ifndef ROOT_TArrayD
+#include <TArrayD.h>
+#endif
+
+class MDataArray;
 class MParameterD;
-class MDataArray;
-class MRanTree;
-class MRanForest;
+class MHMatrix;
 
 class MRanForestCalc : public MTask
 {
+public:
+    enum EstimationMode_t
+    {
+        kMean,
+        kMaximum,
+        kFit
+    };
+
 private:
-    Int_t  fNum;              // number of trees used to compute hadronness
+    static const TString gsDefName;     //! Default Name
+    static const TString gsDefTitle;    //! Default Title
+    static const TString gsNameOutput;  //! Default Output name
 
-    TString fHadronnessName;  // Name of container storing hadronness
+    Bool_t       fDebug;      // Debugging of eventloop while training on/off
 
-    MParameterD *fHadroness;  //! Output container for calculated hadroness
+    TString      fFileName;   // File name to forest
+    TObjArray    fEForests;   // List of forests
+
+    TString      fNameOutput; // Name of output container
+
     MDataArray  *fData;       //! Used to store the MDataChains to get the event values
-    MRanForest  *fRanForest;
-    MRanTree    *fRanTree;
+    MParameterD *fRFOut;      //! Used to store result
 
+    Int_t        fNumTrees;   //! Training parameters
+    Int_t        fNumTry;     //! Training parameters
+    Int_t        fNdSize;     //! Training parameters
+
+    Int_t        fNumObsoleteVariables;
+
+    MHMatrix    *fTestMatrix; //! Test Matrix used in Process (together with MMatrixLoop)
+
+    EstimationMode_t fEstimationMode;
+
+private:
+    // MTask
     Int_t PreProcess(MParList *plist);
     Int_t Process();
 
-    enum { kIsOwner = BIT(14) };
+    // MRanForestCalc
+    Int_t ReadForests(MParList &plist);
 
-    Bool_t IsOwner() const { return TestBit(kIsOwner); }
-    void SetOwner() { SetBit(kIsOwner); }
+    // MParContainer
+    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
+
+    // Train Interface
+    Int_t Train(const MHMatrix &n, const TArrayD &grid, Int_t ver=2);
 
 public:
@@ -40,20 +71,32 @@
     ~MRanForestCalc();
 
-    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
+    // Setter for estimation
+    void SetFileName(TString filename)            { fFileName = filename; }
+    void SetEstimationMode(EstimationMode_t op)   { fEstimationMode = op; }
+    void SetNameOutput(TString name=gsNameOutput) { fNameOutput = name; }
 
-    void SetHadronnessName(const TString name) { fHadronnessName = name; }
-    TString GetHadronnessName() const { return fHadronnessName; }
+    // Setter for training
+    void SetNumTrees(UShort_t n=100) { fNumTrees = n; }
+    void SetNdSize(UShort_t n=5)     { fNdSize   = n; }
+    void SetNumTry(UShort_t n=0)     { fNumTry   = n; }
+    void SetDebug(Bool_t b=kTRUE)    { fDebug    = b; }
 
-    void SetUseNumTrees(UShort_t n=100) { fNum = n; }
+    void SetNumObsoleteVariables(Int_t n=1) { fNumObsoleteVariables = n; }
 
-    Bool_t Grow(MHMatrix *matrixg,MHMatrix *matrixh,Int_t ntree,
-                Int_t numtry,Int_t ndsize,const char* treefile=0,
-                const char* treename=0,const char* contname=0,
-                const char* hgininame=0);
+    // Train Interface
+    Int_t TrainMultiRF(const MHMatrix &n, const TArrayD &grid)
+    {
+        return Train(n, grid, 0);
+    }
+    Int_t TrainSingleRF(const MHMatrix &n, const TArrayD &grid=TArrayD())
+    {
+        return Train(n, grid, grid.GetSize()==0 ? 2 : 1);
+    }
 
-    Bool_t Fill(Int_t ntree,const char* treefile=0,const char* treename=0);
+    // Test Interface
+    void  SetTestMatrix(MHMatrix *m=0) { fTestMatrix=m; }
+    void  InitMapping(MHMatrix *m=0)   { fTestMatrix=m; }
 
-
-    ClassDef(MRanForestCalc, 0) // Task
+    ClassDef(MRanForestCalc, 0) // Task to calculate RF output and for RF training
 };
 
Index: trunk/MagicSoft/Mars/mranforest/MRanTree.h
===================================================================
--- trunk/MagicSoft/Mars/mranforest/MRanTree.h	(revision 7412)
+++ trunk/MagicSoft/Mars/mranforest/MRanTree.h	(revision 7413)
@@ -28,4 +28,5 @@
     Int_t fNumNodes;
     Int_t fNumEndNodes;
+    Float_t fError;
 
     TArrayI fBestVar;
@@ -70,4 +71,5 @@
     void SetNdSize(Int_t n);
     void SetNumTry(Int_t n);
+    void SetError(Float_t f) { fError = f; }
 
     Int_t GetNdSize() const { return fNdSize; }
@@ -75,4 +77,5 @@
     Int_t GetNumNodes()          const { return fNumNodes; }
     Int_t GetNumEndNodes()       const { return fNumEndNodes; }
+    Float_t GetError() const { return fError; }
 
     Int_t GetBestVar(Int_t i)    const { return fBestVar.At(i); }
Index: trunk/MagicSoft/Mars/mranforest/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mranforest/Makefile	(revision 7412)
+++ trunk/MagicSoft/Mars/mranforest/Makefile	(revision 7413)
@@ -25,7 +25,7 @@
            MRanForest.cc \
            MRanForestGrow.cc \
+           MRanForestCalc.cc \
 	   MHRanForest.cc \
-	   MHRanForestGini.cc \
-	   MRFEnergyEst.cc
+	   MHRanForestGini.cc
 
 ############################################################
Index: trunk/MagicSoft/Mars/mranforest/RanForestLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mranforest/RanForestLinkDef.h	(revision 7412)
+++ trunk/MagicSoft/Mars/mranforest/RanForestLinkDef.h	(revision 7413)
@@ -8,9 +8,8 @@
 #pragma link C++ class MRanForest+;
 #pragma link C++ class MRanForestGrow+;
+#pragma link C++ class MRanForestCalc+;
 
 #pragma link C++ class MHRanForest+;
 #pragma link C++ class MHRanForestGini+;
 
-#pragma link C++ class MRFEnergyEst+;
-
 #endif
Index: trunk/MagicSoft/Mars/mtools/MTFillMatrix.cc
===================================================================
--- trunk/MagicSoft/Mars/mtools/MTFillMatrix.cc	(revision 7412)
+++ trunk/MagicSoft/Mars/mtools/MTFillMatrix.cc	(revision 7413)
@@ -204,4 +204,17 @@
 }
 
+//------------------------------------------------------------------------
+//
+// Add all entries deriving from MFilter from list to PreCuts.
+// The ownership is not affected.
+//
+void MTFillMatrix::AddPreCuts(const TList &list)
+{
+    TIter Next(&list);
+    TObject *obj=0;
+    while ((obj=Next()))
+        if (obj->InheritsFrom(MFilter::Class()))
+            fPreCuts.Add(obj);
+}
 
 // --------------------------------------------------------------------------
@@ -209,5 +222,5 @@
 // Fill the matrix (FIXME: Flow diagram missing)
 //
-Bool_t MTFillMatrix::Process()
+Bool_t MTFillMatrix::Process(const MParList &parlist)
 {
     if (!fReader)
@@ -232,5 +245,6 @@
     // Create parameter list and task list, add tasklist to parlist
     //
-    MParList  plist;
+    parlist.Print();
+    MParList  plist(parlist);
     MTaskList tlist;
     plist.AddToList(&tlist);
@@ -372,2 +386,18 @@
     return WriteMatrix1(fname) && WriteMatrix2(fname);
 }
+
+Int_t MTFillMatrix::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    Bool_t rc = kFALSE;
+    if (IsEnvDefined(env, prefix, "NumDestEvents1", print))
+    {
+        rc = kTRUE;
+        SetNumDestEvents1(GetEnvValue(env, prefix, "NumDestEvents1", fNumDestEvents1));
+    }
+    if (IsEnvDefined(env, prefix, "NumDestEvents2", print))
+    {
+        rc = kTRUE;
+        SetNumDestEvents2(GetEnvValue(env, prefix, "NumDestEvents2", fNumDestEvents2));
+    }
+    return rc;
+}
Index: trunk/MagicSoft/Mars/mtools/MTFillMatrix.h
===================================================================
--- trunk/MagicSoft/Mars/mtools/MTFillMatrix.h	(revision 7412)
+++ trunk/MagicSoft/Mars/mtools/MTFillMatrix.h	(revision 7413)
@@ -1,4 +1,8 @@
 #ifndef MARS_MTFillMatrix
 #define MARS_MTFillMatrix
+
+#ifndef MARS_MParList
+#include "MParList.h"
+#endif
 
 #ifndef MARS_MH3
@@ -27,4 +31,6 @@
 
     TList     fPreCuts;
+
+    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
 
     Bool_t CheckResult(MHMatrix *m, Int_t num) const;
@@ -72,6 +78,7 @@
     void AddPreCut(const char *rule);
     void AddPreCut(MFilter *f);
+    void AddPreCuts(const TList &list);
 
-    Bool_t Process();
+    Bool_t Process(const MParList &plist=MParList());
     Bool_t WriteMatrix1(const TString &fname) const { return WriteMatrix(fDestMatrix1, fname, 1); }
     Bool_t WriteMatrix2(const TString &fname) const { return WriteMatrix(fDestMatrix2, fname, 2); }
