Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 6402)
+++ trunk/MagicSoft/Mars/Changelog	(revision 6403)
@@ -26,4 +26,22 @@
    * mtemp/mpadova/macros/wobblemap.C
      - Added. Macro to do some studies on wobble mode data.
+
+   * macros/mccalibrate.C
+     - Added option to divide the output in a train and a test sample.
+       Included in output new container MMcEvtBasic (if found in input 
+       files) for later use in effective areas calculations.
+
+   * macros/starmc2.C
+     - Added writing out of new container MMcEvtBasic. Removed 
+       possibility of splitting output in train and test samples, since
+       this has now to be done in mccalibrate.C to make possible that 
+       the tree OriginalMC containing MMcEvtBasic has all the original
+       MC events (and only those) from which the events present in the
+       Events tree derive.
+
+   * macros/starmc.C
+     - Changed a couple of wrong "." by "->" in function calls. Changed
+       default tail cuts.
+
 
  2005/02/12 Markus Gaug
Index: trunk/MagicSoft/Mars/macros/mccalibrate.C
===================================================================
--- trunk/MagicSoft/Mars/macros/mccalibrate.C	(revision 6402)
+++ trunk/MagicSoft/Mars/macros/mccalibrate.C	(revision 6403)
@@ -29,4 +29,5 @@
 //
 //  This macro converts raw MC data into calibrated data (photons per pixel) 
+//  It optionally divides the output into a train and a test sample
 //
 /////////////////////////////////////////////////////////////////////////////
@@ -37,7 +38,7 @@
 {
   //
-  // This is a demonstration program which reads in MC camera files
-  // and produces and output with calibrated events (signal in photons
-  // for all pixels, in MCerPhotEvt containers).
+  // This macro reads in MC camera files and produces and output with 
+  // calibrated events (signal in photons for all pixels, in MCerPhotEvt 
+  // containers).
   //
 
@@ -47,13 +48,24 @@
   CalibrationFilename = new TString("/users/emc/moralejo/mcdata/Period021_0.73_mirror/gammas_nonoise/Gamma_*root");  // File to be used for the calibration (must be a camera file without added noise)
 
-  Char_t* AnalysisFilename = "Gamma_*.root";  // File to be analyzed
-
-  Char_t* OutFilename      = "calibrated_gamma.root";  // Output file name
-
-
-  // (other extraction methods can be used)
+  Char_t* AnalysisFilename = "Gamma_zbin*w0.root";  // File to be analyzed
+
+
+  TString* OutFilename1;
+  TString* OutFilename2;
+
+  // Output file names
+  OutFilename1 = new TString("calibrated_gamma_train.root");
+  OutFilename2 = new TString("calibrated_gamma_test.root"); 
+
+  // To get only one output file, just comment out the second 
+  // one of the above lines
+
+
+  //
+  //  Set signal extractor
+  //
   //    MExtractFixedWindowPeakSearch sigextract;
   //    sigextract.SetWindows(6, 6, 4);
-
+  //
   MExtractTimeAndChargeDigitalFilter sigextract;
   sigextract.SetNameWeightsFile("/users/emc/moralejo/Mars/msignal/MC_weights.dat");
@@ -100,14 +112,17 @@
 
   MPointingPosCalc pointcalc;
-  // Creates MPointingPos object and fill it with the telescope orientation
-  // information taken from MMcEvt.
+  // Creates MPointingPos object and fills it with the telescope 
+  // orientation information taken from MMcEvt.
 
   MCalibrateData calib; 
-  // MCalibrateData transforms signals from ADC counts into photons. In the first
-  // loop it applies a "dummy" calibration supplied by MMcCalibrationUpdate, just 
-  // to equalize inner and outer pixels. At the end of the first loop, in the
-  // PostProcess of MMcCalibrationCalc (see below) the true calibration constants
+  //
+  // MCalibrateData transforms signals from ADC counts into photons or phe-
+  // (this can be selected anove). In the first loop it applies a "dummy" 
+  // calibration supplied by MMcCalibrationUpdate, just to equalize inner 
+  // and outer pixels, and calculates SIZE in "equivalent number of inner 
+  // ADC counts". At the end of the first loop, in the PostProcess of 
+  // MMcCalibrationCalc (see below) the true calibration constants
   // are calculated.
-
+  //
   calib.SetCalibrationMode(MCalibrateData::kFfactor);
   // Do not change the CalibrationMode above for MC...!
@@ -124,13 +139,18 @@
   //
 
-  MHillasCalc hcalc; // Calculates Hillas parameters not dependent on source position.
+  MHillasCalc hcalc; 
   hcalc.Disable(MHillasCalc::kCalcHillasSrc);
+  // Calculates Hillas parameters not dependent on source position.
 
   MMcCalibrationCalc mccalibcalc; 
   // Calculates calibration constants to convert from ADC counts to photons.
-  
 
   tlist.AddToList(&read);
   tlist.AddToList(&geom);
+
+  MF notrigger("MMcTrig.fNumFirstLevel<1");
+  MContinue skipnotrig(&notrigger);
+  tlist.AddToList(&skipnotrig);
+
   tlist.AddToList(&pcopy);
   tlist.AddToList(&pointcalc);
@@ -144,22 +164,65 @@
 
   //
-  // Open output file:
-  //
-  MWriteRootFile write(OutFilename); // Writes output
-  write.AddContainer("MGeomCam",            "RunHeaders");
-  write.AddContainer("MMcConfigRunHeader",  "RunHeaders");
-  write.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
-  write.AddContainer("MMcFadcHeader",       "RunHeaders");
-  write.AddContainer("MMcRunHeader",        "RunHeaders");
-  write.AddContainer("MMcTrigHeader",       "RunHeaders");
-  write.AddContainer("MRawRunHeader",       "RunHeaders");
-
-
-  write.AddContainer("MMcEvt",        "Events");
-  write.AddContainer("MMcTrig",       "Events");
-  write.AddContainer("MPointingPos",  "Events");
-  write.AddContainer("MRawEvtHeader", "Events");
-  write.AddContainer("MCerPhotEvt",   "Events");
-  write.AddContainer("MPedPhotCam",   "Events");
+  // Open output files:
+  //
+  MWriteRootFile write1(OutFilename1->Data()); // Writes output
+
+  MWriteRootFile write1_b(OutFilename1->Data());
+  write1_b.AddContainer("MMcEvtBasic", "OriginalMC", kFALSE);
+  // Add the MMcEvtBasic container only in case it exists in 
+  // the input camera files
+
+  write1.AddContainer("MGeomCam",            "RunHeaders");
+  write1.AddContainer("MMcConfigRunHeader",  "RunHeaders");
+  write1.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
+  write1.AddContainer("MMcFadcHeader",       "RunHeaders");
+  write1.AddContainer("MMcRunHeader",        "RunHeaders");
+  write1.AddContainer("MMcTrigHeader",       "RunHeaders");
+  write1.AddContainer("MRawRunHeader",       "RunHeaders");
+
+  write1.AddContainer("MMcEvt",        "Events");
+  write1.AddContainer("MMcTrig",       "Events");
+  write1.AddContainer("MPointingPos",  "Events");
+  write1.AddContainer("MRawEvtHeader", "Events");
+  write1.AddContainer("MCerPhotEvt",   "Events");
+  write1.AddContainer("MPedPhotCam",   "Events");
+
+  if (OutFilename2)
+    {
+      MWriteRootFile write2(OutFilename2->Data()); // Writes output    
+
+      MWriteRootFile write2_b(OutFilename2->Data());
+      write2_b.AddContainer("MMcEvtBasic", "OriginalMC", kFALSE);
+      // Add the MMcEvtBasic container only in case it exists in 
+      // the input camera files
+
+      write2.AddContainer("MGeomCam",            "RunHeaders");
+      write2.AddContainer("MMcConfigRunHeader",  "RunHeaders");
+      write2.AddContainer("MMcCorsikaRunHeader", "RunHeaders");
+      write2.AddContainer("MMcFadcHeader",       "RunHeaders");
+      write2.AddContainer("MMcRunHeader",        "RunHeaders");
+      write2.AddContainer("MMcTrigHeader",       "RunHeaders");
+      write2.AddContainer("MRawRunHeader",       "RunHeaders");
+
+      write2.AddContainer("MMcEvt",        "Events");
+      write2.AddContainer("MMcTrig",       "Events");
+      write2.AddContainer("MPointingPos",  "Events");
+      write2.AddContainer("MRawEvtHeader", "Events");
+      write2.AddContainer("MCerPhotEvt",   "Events");
+      write2.AddContainer("MPedPhotCam",   "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);
+
+      write1_b.SetFilter(&filter1);
+      write2_b.SetFilter(&filter2);
+    }
 
   //
@@ -180,5 +243,7 @@
       mccalibcalc->GetHistADC2PhotEl()->Write();
       mccalibcalc->GetHistPhot2PhotEl()->Write();
-      // Writes out the histograms used for calibration.
+      // Writes out the histograms used for calibration. In case of
+      // aslit output in train and test file, this is written only
+      // in the test file for now.
     }
 
@@ -198,4 +263,16 @@
   tlist.RemoveFromList(&read);
 
+  // Now add tasks to write MMcEvtBasic to the OriginalMC tree:
+  tlist.AddToListBefore(&write1_b, &skipnotrig, "All");
+  if (OutFilename2)
+    tlist.AddToListBefore(&write2_b, &skipnotrig, "All");
+
+
+  if (OutFilename2) // Add filters to split output in train and test
+    {
+      tlist.AddToListBefore(&filter1, &write1_b, "All");
+      tlist.AddToListBefore(&filter2, &write1_b, "All");
+    }
+
   bar.SetWindowName("Writing...");
 
@@ -204,5 +281,7 @@
   tlist.RemoveFromList(&mccalibcalc);
 
-  tlist.AddToList(&write);            // Add task to write output.
+  tlist.AddToList(&write1);
+  tlist.AddToList(&write2); 
+  // Add tasks to write the Events and RunHeaders trees to output.
 
   if (!evtloop.Eventloop())
Index: trunk/MagicSoft/Mars/macros/starmc.C
===================================================================
--- trunk/MagicSoft/Mars/macros/starmc.C	(revision 6402)
+++ trunk/MagicSoft/Mars/macros/starmc.C	(revision 6403)
@@ -74,5 +74,5 @@
   Float_t accepted_fraction = 1.;
 
-  Float_t CleanLev[2] = {5.75, 3.84}; 
+  Float_t CleanLev[2] = {5., 4.}; 
   // User change: tail cuts for image analysis
 
@@ -175,5 +175,5 @@
   //
 
-  MWriteRootFile write1(OutFilename1.Data()); // Writes output1
+  MWriteRootFile write1(OutFilename1->Data()); // Writes output1
   write1.AddContainer("MRawRunHeader", "RunHeaders");
   write1.AddContainer("MMcRunHeader",  "RunHeaders");
@@ -197,5 +197,5 @@
   if (OutFilename2)
     {
-      MWriteRootFile write2(OutFilename2.Data()); // Writes output2
+      MWriteRootFile write2(OutFilename2->Data()); // Writes output2
       write2.AddContainer("MRawRunHeader", "RunHeaders");
       write2.AddContainer("MMcRunHeader",  "RunHeaders");
Index: trunk/MagicSoft/Mars/macros/starmc2.C
===================================================================
--- trunk/MagicSoft/Mars/macros/starmc2.C	(revision 6402)
+++ trunk/MagicSoft/Mars/macros/starmc2.C	(revision 6403)
@@ -38,13 +38,12 @@
 void starmc2()
 {
-  Char_t* AnalysisFilename = "calibrated_gamma.root"; // File to be analyzed
+  Char_t* AnalysisFilename = "calibrated_gamma_train.root"; // File to be analyzed
+  //  Char_t* AnalysisFilename = "calibrated_gamma_test.root"; // File to be analyzed
 
-  TString* OutFilename1;
-  TString* OutFilename2;
+  TString* OutFilename;
 
-  // Change output file names as desired. If you want only one output, comment
-  // out the initialization of OutFilename2:
-  OutFilename1 = new TString("star_gamma_train.root");   // Output file name 1 (test)
-  OutFilename2 = new TString("star_gamma_test.root");    // Output file name 2 (train)
+  // Output file name
+  OutFilename = new TString("star_gamma_train.root");   // Output file name
+  //  OutFilename = new TString("star_gamma_test.root");   // Output file name
 
   MImgCleanStd      clean(4.5, 3.); // Applies tail cuts to image.
@@ -67,5 +66,7 @@
   //
   // FOR WOBBLE MODE!! Set source position on camera here.
-  //  src.SetX(120.);  // units: mm
+  //  src.SetX(120.);  
+  // units: mm. This 120 mm correspond to MC wobble mode w+ for zbin>0
+  //
 
   src.SetReadyToSave();
@@ -80,5 +81,4 @@
 
   read.AddFile(AnalysisFilename);
-
   read.DisableAutoScheme();
 
@@ -94,72 +94,30 @@
   // Open output file(s):
   //
-  MWriteRootFile write1(OutFilename1->Data()); // Writes output   
+  MWriteRootFile write(OutFilename->Data()); // Writes output   
   //
-  // Add MC containers only if they exist. In this way you can also run on real calibrated data.
+  // Add MC containers only if they exist. 
+  // In this way you can also run on real calibrated data.
   //
-  write1.AddContainer("MRawRunHeader", "RunHeaders");
-  write1.AddContainer("MMcRunHeader",  "RunHeaders", kFALSE);
-  write1.AddContainer("MGeomCam",      "RunHeaders", kFALSE);
-  write1.AddContainer("MMcConfigRunHeader",  "RunHeaders", kFALSE);
-  write1.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
-  write1.AddContainer("MMcFadcHeader",  "RunHeaders", kFALSE);
-  write1.AddContainer("MMcTrigHeader",  "RunHeaders", kFALSE);
+  write.AddContainer("MRawRunHeader", "RunHeaders");
+  write.AddContainer("MMcRunHeader",  "RunHeaders", kFALSE);
+  write.AddContainer("MGeomCam",      "RunHeaders", kFALSE);
+  write.AddContainer("MMcConfigRunHeader",  "RunHeaders", kFALSE);
+  write.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
+  write.AddContainer("MMcFadcHeader",  "RunHeaders", kFALSE);
+  write.AddContainer("MMcTrigHeader",  "RunHeaders", kFALSE);
+       
+  write.AddContainer("MMcEvt",        "Events", kFALSE);
+  write.AddContainer("MPointingPos",  "Events", kFALSE);
+  write.AddContainer("MMcTrig",       "Events", kFALSE);
+  write.AddContainer("MSrcPosCam",    "Events", kFALSE);
+  write.AddContainer("MRawEvtHeader", "Events");
+  write.AddContainer("MHillas",       "Events");
+  write.AddContainer("MHillasExt",    "Events");
+  write.AddContainer("MHillasSrc",    "Events");
+  write.AddContainer("MImagePar",     "Events");
+  write.AddContainer("MNewImagePar",  "Events");
+  write.AddContainer("MConcentration","Events");
 
-  write1.AddContainer("MMcEvt",        "Events", kFALSE);
-  write1.AddContainer("MPointingPos",  "Events", kFALSE);
-  write1.AddContainer("MMcTrig",       "Events", kFALSE);
-  write1.AddContainer("MSrcPosCam",    "Events", kFALSE);
-  write1.AddContainer("MRawEvtHeader", "Events");
-  write1.AddContainer("MHillas",       "Events");
-  write1.AddContainer("MHillasExt",    "Events");
-  write1.AddContainer("MHillasSrc",    "Events");
-  write1.AddContainer("MImagePar",     "Events");
-  write1.AddContainer("MNewImagePar",  "Events");
-  write1.AddContainer("MConcentration","Events");
-
-  if (OutFilename2) // Second output file, in case we want a split output
-    {
-      MWriteRootFile write2(OutFilename2->Data()); // Writes output
-      write2.AddContainer("MRawRunHeader", "RunHeaders");
-      write2.AddContainer("MMcRunHeader",  "RunHeaders", kFALSE);
-      write2.AddContainer("MGeomCam",      "RunHeaders", kFALSE);
-      write2.AddContainer("MMcConfigRunHeader",  "RunHeaders", kFALSE);
-      write2.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
-      write2.AddContainer("MMcFadcHeader",  "RunHeaders", kFALSE);
-      write2.AddContainer("MMcTrigHeader",  "RunHeaders", kFALSE);
-
-      write2.AddContainer("MMcEvt",        "Events", kFALSE);
-      write2.AddContainer("MPointingPos",  "Events", kFALSE);
-      write2.AddContainer("MMcTrig",       "Events", kFALSE);
-      write2.AddContainer("MSrcPosCam",    "Events", kFALSE);
-      write2.AddContainer("MRawEvtHeader", "Events");
-      write2.AddContainer("MHillas",       "Events");
-      write2.AddContainer("MHillasExt",    "Events");
-      write2.AddContainer("MHillasSrc",    "Events");
-      write2.AddContainer("MImagePar",     "Events");
-      write2.AddContainer("MNewImagePar",  "Events");
-      write2.AddContainer("MConcentration","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);
-
-      tlist.AddToList(&filter1);
-      tlist.AddToList(&filter2);
-    }
-
-
-  tlist.AddToList(&write1);
-
-  if (OutFilename2)
-    tlist.AddToList(&write2);   
-  
+  tlist.AddToList(&write);
 
   //
@@ -178,4 +136,35 @@
   tlist.PrintStatistics();
 
+  ////////////////////////////////////////////////////////////////////
+  //
+  // Second event loop: simply copy the tree MMcEvtBasic in the tree 
+  // "OriginalMC" from the input file to the output file:
+
+  MParList  plist2;
+  MTaskList tlist2;
+
+  plist2.AddToList(&tlist2);
+
+  MReadMarsFile read2("OriginalMC");
+  read2.AddFile(AnalysisFilename);
+  read2.DisableAutoScheme();
+
+  tlist2.AddToList(&read2);
+
+  MWriteRootFile writeOrig(OutFilename->Data(),"UPDATE");
+  writeOrig.AddContainer("MMcEvtBasic", "OriginalMC", kFALSE);
+
+  tlist2.AddToList(&writeOrig);
+
+  MEvtLoop evtloop2;
+  bar.SetWindowName("Copying OriginalMC tree...");
+  evtloop2.SetProgressBar(&bar);
+  evtloop2.SetParList(&plist2);
+  
+  if (!evtloop2.Eventloop())
+    return;
+
+  tlist2.PrintStatistics();
+
   return;
 }
