Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 3340)
+++ trunk/MagicSoft/Mars/Changelog	(revision 3341)
@@ -5,9 +5,15 @@
                                                  -*-*- END OF LINE -*-*-
  
+
+ 2004/02/27: Abelardo Moralejo
+   * macros/starmc.C
+     - added (optional) division of output into two, for use as train 
+       and test samples in g/h separation studies.
+
+
  2004/02/26: Hendrik Bartko
 
    * macros/dohtml.C
      - included the path msignals/
-
 
 
Index: trunk/MagicSoft/Mars/macros/starmc.C
===================================================================
--- trunk/MagicSoft/Mars/macros/starmc.C	(revision 3340)
+++ trunk/MagicSoft/Mars/macros/starmc.C	(revision 3341)
@@ -41,20 +41,28 @@
   // parameters from Magic Monte Carlo files (output of camera).
 
+  TString* CalibrationFilename;
+  TString* OutFilename1;
+  TString* OutFilename2;
 
   // ------------- user change -----------------
-
-  TString* CalibrationFilename;
-
-  //
-  // Comment out next line to disable calibration. In that case the units of the 
-  // MHillas.fSize parameter will be ADC counts (rather, equivalent ADC counts in
-  // inner pixels, since we correct for the possible differences in gain of outer 
-  // pixels)
-  //
-  CalibrationFilename = new TString("nonoise/Gamma_zbin0_0*.root");
+  //
+  // Comment line starting "CalibrationFileName" to disable calibration. In that 
+  // case the units of the MHillas.fSize parameter will be ADC counts (rather, 
+  // equivalent ADC counts in inner pixels, since we correct for the possible 
+  // differences in gain of outer pixels)
+  //
+  CalibrationFilename = new TString("nonoise/Gamma_zbin0_90_7_507*.root");
   // File to be used in the calibration (must be a camera file without added noise)
 
   Char_t* AnalysisFilename = "Gamma_zbin0*.root";  // File to be analyzed
-  Char_t* OutFilename      = "star_mc.root";       // Output file name
+
+  // ------------- user change -----------------
+  //
+  // Change output file names as desired. If you want only one output, comment
+  // the initialization of OutFilename2.
+
+  OutFilename1 = new TString("star_train.root");   // Output file name 1 (test)
+  //  OutFilename2 = new TString("star_test.root");    // Output file name 2 (train)
+
 
   Float_t CleanLev[2] = {4., 3.}; // Tail cuts for image analysis
@@ -129,15 +137,40 @@
 
   //
-  // Open output file:
-  //
-  MWriteRootFile write(OutFilename); // Writes output
-  write.AddContainer("MRawRunHeader", "RunHeaders");
-  write.AddContainer("MMcRunHeader",  "RunHeaders");
-  write.AddContainer("MSrcPosCam",    "RunHeaders");
-  write.AddContainer("MMcEvt",        "Events");
-  write.AddContainer("MHillas",       "Events");
-  write.AddContainer("MHillasExt",    "Events");
-  write.AddContainer("MHillasSrc",    "Events");
-  write.AddContainer("MNewImagePar",  "Events");
+  // Open output files:
+  //
+
+  MWriteRootFile write1(OutFilename1.Data()); // Writes output1
+  write1.AddContainer("MRawRunHeader", "RunHeaders");
+  write1.AddContainer("MMcRunHeader",  "RunHeaders");
+  write1.AddContainer("MSrcPosCam",    "RunHeaders");
+  write1.AddContainer("MMcEvt",        "Events");
+  write1.AddContainer("MHillas",       "Events");
+  write1.AddContainer("MHillasExt",    "Events");
+  write1.AddContainer("MHillasSrc",    "Events");
+  write1.AddContainer("MNewImagePar",  "Events");
+
+  if (OutFilename2)
+    {
+      MWriteRootFile write2(OutFilename2.Data()); // Writes output2
+      write2.AddContainer("MRawRunHeader", "RunHeaders");
+      write2.AddContainer("MMcRunHeader",  "RunHeaders");
+      write2.AddContainer("MSrcPosCam",    "RunHeaders");
+      write2.AddContainer("MMcEvt",        "Events");
+      write2.AddContainer("MHillas",       "Events");
+      write2.AddContainer("MHillasExt",    "Events");
+      write2.AddContainer("MHillasSrc",    "Events");
+      write2.AddContainer("MNewImagePar",  "Events");
+
+      //
+      // Divide output in train and test samples, using the event number
+      // (odd/even) to achieve otherwise unbiased event samples:
+      //
+      
+      MF filter1("{MMcEvt.fEvtNumber%2}>0.5");
+      MF filter2("{MMcEvt.fEvtNumber%2}<0.5");
+
+      write1.SetFilter(&filter1);
+      write2.SetFilter(&filter2);
+    }
 
   //
@@ -179,5 +212,15 @@
   tlist.AddToList(&scalc);            // Calculates Source-dependent Hillas parameters
 
-  tlist.AddToList(&write);            // Add task to write output.
+
+  // Add tasks to write output:
+
+  if (OutFilename2)
+    {
+      tlist.AddToList(&filter1);
+      tlist.AddToList(&filter2);
+      tlist.AddToList(&write2); 
+    }
+
+  tlist.AddToList(&write1); 
 
   if (!evtloop.Eventloop())
