Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 3753)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 3754)
@@ -21,7 +21,11 @@
 
    * macros/calibration.C
-     - added a function FindColor to extract the colour by filename, 
+     - added a function FindColor() to extract the colour by filename, 
        works if there is indeed a colour or if the run nubmer is smaller 
        than 20000 -> take ct1
+
+   * macros/bootcampstandardanalysis.C
+     - updated the macro to the cvs-standard used at the Udine bootcamp
+
 
    * mcalib/MCalibrateRelTimes.[h,cc]
Index: /trunk/MagicSoft/Mars/macros/bootcampstandardanalysis.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/bootcampstandardanalysis.C	(revision 3753)
+++ /trunk/MagicSoft/Mars/macros/bootcampstandardanalysis.C	(revision 3754)
@@ -17,9 +17,330 @@
 !
 !   Author(s): Javier López, 12/2003 <mailto:jlopez@ifae.es>
-!
-!   Copyright: MAGIC Software Development, 2000-2003
+!              Markus Gaug , 04/2004 <mailto:markus@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
 !
 !
 \* ======================================================================== */
+/////////////////////////////////////////////////////////////////////////////
+//
+//  bootcampstandardanalysis.C
+//
+//  Updated version of the macro designed at the Wuerzburg bootcamp and 
+//  compatible with the latest changes in Mars for general usage at the
+//  Udine bootcamp. 
+//
+//  Needs as arguments the run number of a pedestal file ("*_P_*.root"), 
+//  one of a calibration file ("*_C_*.root") and one of a data file 
+//  ("*_D_*.root"). Performs the pedestal calculation, the calibration 
+/// constants calculation and the calibration of the data. 
+//
+//  The TString inpath has to be set correctly.
+//
+//  The macro searches for the pulser colour which corresponds to the calibration
+//  run number. If the run number is smaller than 20000, pulser colour "CT1" 
+//  is assumed, otherwise, it searches for the strings "green", "blue", "uv" or 
+//  "ct1" in the filenames. If no colour or multiple colours are found, the 
+//  execution is aborted.  
+//
+//////////////////////////////////////////////////////////////////////////////////
+const TString inpath = "/mnt/Data/rootdata/CrabNebula/2004_02_10/";
+const Int_t dpedrun  = 14607;
+const Int_t dcalrun1 = 14608;
+const Int_t dcalrun2 = 0;
+const Int_t ddatrun1 = 14609;
+const Int_t ddatrun2 = 14614;
+const Bool_t usedisplay = kTRUE;
+
+void bootcampstandardanalysis(const Int_t prun=dpedrun, // pedestal file
+                              const Int_t crun1=dcalrun1, const Int_t crun2=dcalrun2, // calibration file(s)
+                              const Int_t drun1=ddatrun1, const Int_t drun2=ddatrun2 // data files(s)
+                              )
+                              
+{
+
+  MRunIter pruns;
+  MRunIter cruns;
+  MRunIter druns;
+
+  pruns.AddRun(prun,inpath);
+
+  if (crun2==0)
+    cruns.AddRun(crun1,inpath);
+  else
+    cruns.AddRuns(crun1,crun2,inpath);
+
+  MCalibrationCam::PulserColor_t color;
+
+  if (crun1 < 20000)
+    color = MCalibrationCam::kCT1;
+  else
+    color = FindColor((MDirIter*)&cruns);
+
+  if (color == MCalibrationCam::kNONE)
+    {
+      TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
+      
+      while (1)
+        {
+          timer.TurnOn();
+          TString input = Getline("Could not find the correct colour: Type 'q' to exit, "
+                                  "green, blue, uv or ct1 to go on: ");
+          timer.TurnOff();
+          
+          if (input=="q\n")
+            return ;
+          
+          if (input=="green")
+            color = MCalibrationCam::kGREEN;
+          if (input=="blue")
+            color = MCalibrationCam::kBLUE;
+          if (input=="uv")
+            color = MCalibrationCam::kUV;
+          if (input=="ct1")
+            color = MCalibrationCam::kCT1;
+        }
+    }
+  
+  if (drun2==0)
+    druns.AddRun(drun1,inpath);
+  else
+    druns.AddRuns(drun1,drun2,inpath);
+  
+  //
+  // Now setup the tasks and tasklist for the pedestals:
+  // ---------------------------------------------------
+  //
+  MBadPixelsCam     badcam;
+  MGeomCamMagic     geomcam;
+  MGeomApply        geomapl;
+  //
+  // If you want to exclude pixels from the beginning, read 
+  // an ascii-file with the corr. pixel numbers (see MBadPixelsCam)
+  //
+  //  badcam.AsciiRead("badpixels.dat");
+  
+  /************************************/
+  /* FIRST LOOP: PEDESTAL COMPUTATION */
+  /************************************/
+
+  MJPedestal pedloop;
+  pedloop.SetInput(&pruns);
+  if (usedisplay)
+    {
+      MStatusDisplay *display = new MStatusDisplay;
+      display->SetUpdateTime(3000);
+      display->Resize(850,700);
+      pedloop.SetDisplay(display);
+    }
+  pedloop.SetBadPixels(badcam);
+
+  if (!pedloop.Process())
+    return;
+
+  /****************************************/
+  /* SECOND LOOP: CALIBRATION COMPUTATION */
+  /****************************************/
+
+  //
+  // Now setup the new tasks for the calibration:
+  // ---------------------------------------------------
+  //
+  MCalibrationQECam qecam;
+  MJCalibration     calloop;
+  calloop.SetColor(color);
+  calloop.SetInput(&cruns);
+  //
+  // Use as signal extractor MExtractSignal:
+  //
+  calloop.SetExtractorLevel(1);
+  //
+  // Set the corr. cams:
+  //
+  calloop.SetQECam(qecam);
+  calloop.SetBadPixels(pedloop.GetBadPixels());
+  //
+  // The next two commands are for the display:
+  //
+  if (usedisplay)
+    {
+      calloop.SetDisplay(display);
+      calloop.SetDataCheck();
+    }
+  
+  //
+  // Apply rel. time calibration:
+  //
+  calloop.SetRelTimeCalibration();
+  //
+  // Use as arrival time extractor MArrivalTimeCalc2:
+  //
+  calloop.SetArrivalTimeLevel(2);
+  
+  //
+  // Do the event-loop:
+  //
+  if (!calloop.Process(pedloop.GetPedestalCam()))
+    return;
+  
+
+  /*************************************/
+  /* THIRD LOOP: PEDESTAL CALIBRATION  */
+  /*************************************/
+
+  //
+  // Create a empty Parameter List and an empty Task List
+  //
+  MParList  plist3;
+  MTaskList tlist3;
+  plist3.AddToList(&tlist3);
+  
+  //
+  // Now setup the tasks and tasklist to calculate the pedestal rms in number of photons
+  // -----------------------------------------------------------------------------------
+  //
+  
+  MCerPhotEvt    nphot;
+  MPedPhotCam    nphotrms;
+  
+  plist3.AddToList(&geomcam);
+
+  //
+  // Retrieve the cameras from the previous runs:
+  //
+  plist3.AddToList(&pedloop.GetPedestalCam());
+  plist3.AddToList(&calloop.GetCalibrationCam());
+  plist3.AddToList(&calloop.GetQECam());
+  plist3.AddToList(&calloop.GetRelTimeCam());
+  plist3.AddToList(&calloop.GetBadPixels());
+  plist3.AddToList(&nphot);
+  plist3.AddToList(&nphotrms);
+  
+  //tasks
+  MReadMarsFile read3("Events");
+  read3.DisableAutoScheme();
+  static_cast<MRead&>(read3).AddFiles(pruns);  
+
+  MExtractSignal   extsig;
+  MCalibrate       photcalc;
+  photcalc.SetCalibrationMode(MCalibrate::kFfactor);
+  //    MPedPhotCalc  photrmscalc;  //It doesn't exist yet
+  
+  tlist3.AddToList(&read3);
+  tlist3.AddToList(&geomapl);
+  tlist3.AddToList(&extsig);
+  tlist3.AddToList(&photcalc);
+  //    tlist3.AddToList(&photrmscalc);
+  
+  //
+  // Create and setup the eventloop
+  //
+  MEvtLoop evtloop3;
+  evtloop3.SetParList(&plist3);
+  
+  //
+  // Execute first analysis
+  //
+  if (!evtloop3.Eventloop())
+    return;
+  
+  tlist3.PrintStatistics();
+  
+  /*************************************/
+  /* FOURTH LOOP: DATA CALIBRATION     */
+  /*************************************/
+
+  //
+  // Create a empty Parameter List and an empty Task List
+  //
+  MParList  plist4;
+  MTaskList tlist4;
+  plist4.AddToList(&tlist4);
+  
+  //
+  // Now setup the tasks and tasklist to analize the data
+  // -----------------------------------------------------
+  //
+  
+  plist4.AddToList(&geomcam);
+  //
+  // Retrieve the cameras from the previous runs:
+  //
+  plist4.AddToList(&pedloop.GetPedestalCam());
+  plist4.AddToList(&calloop.GetCalibrationCam());
+  plist4.AddToList(&calloop.GetQECam());
+  plist4.AddToList(&calloop.GetRelTimeCam());
+  plist4.AddToList(&calloop.GetBadPixels());
+  plist4.AddToList(&nphot);
+  plist4.AddToList(&nphotrms);
+
+  MArrivalTime times;
+  plist4.AddToList(&times);
+  
+  //tasks
+  MReadMarsFile read4("Events");
+  read4.DisableAutoScheme();
+  static_cast<MRead&>(read4).AddFiles(druns);  
+  
+  MArrivalTimeCalc2   timecalc;
+  MCalibrateRelTimes  timecal;
+
+  tlist4.AddToList(&read4);
+  tlist4.AddToList(&geomapl);
+  tlist4.AddToList(&extsig);
+  tlist4.AddToList(&timecalc);
+  tlist4.AddToList(&photcalc);
+  tlist4.AddToList(&timecal);
+  
+  //
+  // Create and setup the eventloop
+  //
+  MEvtLoop evtloop4;
+  evtloop4.SetParList(&plist4);
+
+  if (!evtloop4.PreProcess())
+
+    return;
+  
+  TCanvas *c1 = new TCanvas;
+  MHCamera disp1(geomcam);
+  disp1.SetPrettyPalette();
+  //disp1.SetInvDeepBlueSeaPalette()
+  disp1.Draw();
+  gPad->SetLogy();
+  gPad->cd(1);
+  
+  /*
+  TCanvas *c2 = new TCanvas;
+  MHCamera disp2(geomcam);
+  disp2.SetPrettyPalette();
+  //disp2.SetInvDeepBlueSeaPalette()
+  disp2.Draw();
+  gPad->SetLogy();
+  gPad->cd(1);
+  */
+  while (tlist4.Process())
+    {
+      disp1.SetCamContent(nphot);
+      
+      gPad->Modified();
+      gPad->Update();
+
+      /*    
+      disp2.SetCamContent(times);
+      
+      gPad->Modified();
+      gPad->Update();
+      */
+
+      // Remove the comments if you want to go through the file
+      // event-by-event:
+      if (!HandleInput())
+	break;
+    }
+
+  evtloop4.PostProcess();
+  
+}
 
 Bool_t HandleInput()
@@ -46,260 +367,72 @@
 }
 
-void bootcampstandardanalysis(
-TString pedname="/mnt/magic_data/Data/rootdata/2003_11_29/20031128_03127_P_Crab-Nebula_E.root",
-TString calname="/mnt/magic_data/Data/rootdata/2003_11_29/20031128_03128_C_Crab-Nebula_E.root", 
-TString dataname="/mnt/magic_data/Data/rootdata/2003_11_29/20031128_03200_D_Crab-Nebula_E.root")
+MCalibrationCam::PulserColor_t FindColor(MDirIter* run) 
 {
-
-// Before starting be sure you have the pedestal, calibration and data runs names
-//    if (pedname != NULL)
-//	cout << endl << "usage: bootcampstandardanalysis.C()" << endl; 
-
-    //
-    // Create a empty Parameter List and an empty Task List
-    // The tasklist is identified in the eventloop by its name
-    //
-    MParList plist;
-
-    MTaskList tlist;
-    plist.AddToList(&tlist);
-
-    //
-    // Now setup the tasks and tasklist for the pedestals:
-    // ---------------------------------------------------
-    //
-
-    MPedestalCam   pedcam;
-    plist.AddToList(&pedcam);
-
-
-    //tasks
-    MReadMarsFile read("Events", pedname);
-    read.DisableAutoScheme();
-
-    MGeomApply     geomapl;
-    MPedCalcPedRun pedcalc;
-    MGeomCamMagic  geomcam;
-
-    tlist.AddToList(&read);
-    tlist.AddToList(&geomapl);
-    tlist.AddToList(&pedcalc);
-
-    //
-    // Create and setup the eventloop
-    //
-    MEvtLoop evtloop;
-    evtloop.SetParList(&plist);
-
-    //
-    // Execute first analysis
-    //
-    if (!evtloop.Eventloop())
-        return;
-
-    tlist.PrintStatistics();
-
-    //
-    // Create a empty Parameter List and an empty Task List
-    //
-    MParList  plist2;
-
-    MTaskList tlist2;
-    plist2.AddToList(&tlist2);
-
-
-    //
-    // Now setup the new tasks and tasklist for the calibration
-    // ---------------------------------------------------
-    //
-    
-    MBadPixelsCam           badcam;
-    MCalibrationChargeCam   calcam;
-    MExtractedSignalCam     sigcam;
-    MCalibrationChargePINDiode pindiode;
-    MCalibrationChargeBlindPix blindpix;
-    
-    //
-    // As long, as we don't have digital modules, 
-    // we have to set the color of the pulser LED by hand
-    //
-    //    calcam.SetColor(MCalibrationChargeCam::kECT1);
-    blindpix.SetColor(MCalibrationChargeBlindpix:kECT1);
-
-    plist2.AddToList(&geomcam);
-    plist2.AddToList(&badcam);
-    plist2.AddToList(&pedcam);
-    plist2.AddToList(&calcam);
-    plist2.AddToList(&sigcam);
-    plist2.AddToList(&pindiode);
-    plist2.AddToList(&blindpix);
-
-   // hists
-    MFillH fillpin(  "MHCalibrationChargePINDiode", "MExtractedSignalPINDiode");
-    MFillH fillblind("MHCalibrationChargeBlindPix", "MExtractedSignalBlindPix");
-    MFillH fillcam(  "MHCalibrationChargeCam"     , "MExtractedSignalCam");
-
-    //tasks
-    MReadMarsFile read2("Events", calname);
-    read2.DisableAutoScheme();
-
-    MExtractPINDiode       pincalc;
-    MExtractBlindPixel     blindcalc;
-    MExtractSignal         sigsig;
-    MCalibrationChargeCalc calcalc;
-
-    // 
-    // Apply a filter against cosmics
-    // (was directly in MCalibrationCalc in earlier versions)
-    //
-    MFCosmics            cosmics;
-    MContinue            cont(&cosmics);
-
-    tlist2.AddToList(&read2);
-    tlist2.AddToList(&geomapl);
-    tlist2.AddToList(&blindcalc);
-    tlist2.AddToList(&pincalc);
-    tlist2.AddToList(&sigsig);
-    //
-    // In case, you want to skip the cosmics rejection, 
-    // uncomment the next line
-    //
-    tlist2.AddToList(&cont);
-    //
-    //    tlist2.AddToList(&fillpin);
-    tlist2.AddToList(&fillblind);
-    tlist2.AddToList(&fillcam); 
-    tlist2.AddToList(&calcalc);
-    //
-    // Create and setup the eventloop
-    //
-    MEvtLoop evtloop2;
-    evtloop2.SetParList(&plist2);
-
-    //
-    // Execute second analysis
-    //
-    if (!evtloop2.Eventloop())
-        return;
-
-    tlist2.PrintStatistics();
- 
-
-    //
-    // Create a empty Parameter List and an empty Task List
-    //
-    MParList  plist3;
-
-    MTaskList tlist3;
-    plist3.AddToList(&tlist3);
-
-    //
-    // Now setup the tasks and tasklist to calculate the pedestal rms in number of photons
-    // -----------------------------------------------------------------------------------
-    //
-
-    MCerPhotEvt    nphot;
-    MPedPhotCam    nphotrms;
-
-    plist3.AddToList(&geomcam);
-    plist3.AddToList(&pedcam);
-    plist3.AddToList(&calcam);
-    plist3.AddToList(&nphot);
-    plist3.AddToList(&nphotrms);
-
-    //tasks
-    MReadMarsFile read3("Events", pedname);
-    read3.DisableAutoScheme();
-
-    MExtractSignal     extsig;
-    MCalibrate       photcalc;
-//    MPedPhotCalc  photrmscalc;  //It doesn't exist yet
-
-    tlist3.AddToList(&read3);
-    tlist3.AddToList(&geomapl);
-    tlist3.AddToList(&extsig);
-    tlist3.AddToList(&photcalc);
-//    tlist3.AddToList(&photrmscalc);
-
-    //
-    // Create and setup the eventloop
-    //
-    MEvtLoop evtloop3;
-    evtloop3.SetParList(&plist3);
-
-
-    //
-    // Execute first analysis
-    //
-    if (!evtloop3.Eventloop())
-        return;
-
-    tlist3.PrintStatistics();
-
-    //
-    // Create a empty Parameter List and an empty Task List
-    //
-    MParList  plist4;
-
-    MTaskList tlist4;
-    plist4.AddToList(&tlist4);
-
-    //
-    // Now setup the tasks and tasklist to analize the data
-    // -----------------------------------------------------
-    //
-
-    plist4.AddToList(&geomcam);
-    plist4.AddToList(&pedcam);
-    plist4.AddToList(&calcam);
-    plist4.AddToList(&nphot);
-    plist4.AddToList(&nphotrms);
-
-    //tasks
-    MReadMarsFile read4("Events", dataname);
-    read4.DisableAutoScheme();
-
-
-    MExtractSignal     extsig;
-    MCalibrate       photcalc;
-
-    tlist4.AddToList(&read4);
-    tlist4.AddToList(&geomapl);
-    tlist4.AddToList(&extsig);
-    tlist4.AddToList(&photcalc);
-
-    //
-    // Create and setup the eventloop
-    //
-    MEvtLoop evtloop4;
-    evtloop4.SetParList(&plist4);
-
-    if (!evtloop4.PreProcess())
-        return;
-
-    TCanvas *c = new TCanvas;
-    MHCamera display(geomcam);
-    display.SetPrettyPalette();
-    //display.SetInvDeepBlueSeaPalette()
-    display.Draw();
-    gPad->SetLogy();
-    gPad->cd(1);
-
-    while (tlist4.Process())
-    {
-      display.SetCamContent(nphot);
-
-      gPad->Modified();
-      gPad->Update();
-
-      // Remove the comments if you want to go through the file
-      // event-by-event:
-      if (!HandleInput())
-	break;
+  
+  MCalibrationCam::PulserColor_t col = MCalibrationCam::kNONE;
+
+  TString filenames;
+
+  while (!(filenames=run->Next()).IsNull())
+    {
+
+      filenames.ToLower();
+
+      if (filenames.Contains("green"))
+        if (col == MCalibrationCam::kNONE)
+          {
+            cout << "Found colour: Green  in " << filenames << endl;
+            col = MCalibrationCam::kGREEN;
+          }
+        else if (col != MCalibrationCam::kGREEN)
+          {
+            cout << "Different colour found in " << filenames << "... abort" << endl;
+            return MCalibrationCam::kNONE;
+          }
+
+      if (filenames.Contains("blue"))
+        if (col == MCalibrationCam::kNONE)
+          {
+            cout << "Found colour: Blue  in " << filenames << endl;
+            col = MCalibrationCam::kBLUE;
+          }
+        else if (col != MCalibrationCam::kBLUE)
+          {
+            cout << "Different colour found in " << filenames << "... abort" << endl;
+            return MCalibrationCam::kNONE;
+          }
+
+      if (filenames.Contains("uv"))
+        if (col == MCalibrationCam::kNONE)
+          {
+            cout << "Found colour: Uv  in " << filenames << endl;
+            col = MCalibrationCam::kUV;
+          }
+        else if (col != MCalibrationCam::kUV)
+          {
+            cout << "Different colour found in " << filenames << "... abort" << endl;
+            return MCalibrationCam::kNONE;
+          }
+
+      if (filenames.Contains("ct1"))
+        if (col == MCalibrationCam::kNONE)
+          {
+            cout << "Found colour: Ct1  in " << filenames << endl;
+            col = MCalibrationCam::kCT1;
+          }
+        else if (col != MCalibrationCam::kCT1)
+          {
+            cout << "Different colour found in " << filenames << "... abort" << endl;
+            return MCalibrationCam::kNONE;
+          }
+      
     }
-
-
-    
-    evtloop4.PostProcess();
-
+  
+
+      
+  if (col == MCalibrationCam::kNONE)
+    cout <<  "No colour found in filenames of runs: " << ((MRunIter*)run)->GetRunsAsString() 
+         << "... abort" << endl;
+  
+  return col;      
 }
