Index: trunk/MagicSoft/Mars/mtemp/mifae/Changelog
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/Changelog	(revision 5207)
+++ trunk/MagicSoft/Mars/mtemp/mifae/Changelog	(revision 5208)
@@ -19,4 +19,11 @@
                                                  -*-*- END OF LINE -*-*-
 
+  2004/10/08  Javier Rico
+    * programs/makeHillas.cc, programs/makehillas.datacard
+     - Include possibility to select signal extractor in datacard
+     - Include possitility to compute pedestals from data themselves, 
+       by selecting word PRUNS 0. For the time being, the old option
+       of computing them from a pedestal run is still available
+	
   2004/10/05  Javier Rico
     * programs/srcPos.cc
Index: trunk/MagicSoft/Mars/mtemp/mifae/programs/makeHillas.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/programs/makeHillas.cc	(revision 5207)
+++ trunk/MagicSoft/Mars/mtemp/mifae/programs/makeHillas.cc	(revision 5208)
@@ -22,5 +22,7 @@
 #include "MExtractor.h"
 #include "MExtractFixedWindow.h"
+#include "MExtractFixedWindowPeakSearch.h"
 #include "MExtractSlidingWindow.h"
+#include "MPedCalcFromLoGain.h"
 #include "MExtractSignal.h"
 #include "MCalibrationChargeCalc.h"
@@ -30,5 +32,5 @@
 #include "MCerPhotEvt.h"
 #include "MPedPhotCam.h"
-#include "MCalibrate.h"
+#include "MCalibrateData.h"
 #include "MPedPhotCalc.h"
 #include "MHillas.h"
@@ -65,9 +67,4 @@
 void makeHillas();
 
-// initial and final time slices to be used in signal extraction
-const Byte_t hifirst = 1;
-const Byte_t hilast  = 14;
-const Byte_t lofirst = 3;
-const Byte_t lolast  = 14;
 
 // declaration of variables read from datacards
@@ -84,7 +81,7 @@
 ULong_t  nmaxevents= 999999999;
 Short_t  calflag   = 1;
-Bool_t  caltimeflag   = kFALSE;
+Bool_t   caltimeflag   = kFALSE;
 Short_t  cleanflag   = 1;
-UShort_t  lrings     = 1;
+UShort_t lrings     = 1;
 Float_t  lcore     = 3.0;
 Float_t  ltail     = 1.5;
@@ -94,6 +91,13 @@
 Int_t    kalgorithm = 1;
 Int_t    nfiles    = 0;
+Int_t    hifirst = 0;
+Int_t    hilast  = 14;
+Int_t    lofirst = 2;
+Int_t    lolast  = 14;
+Int_t    wsize   = 6;
+Int_t    sext    = 0;
 
 const TString defaultcard="makehillas.datacard";
+char* chext[3]={"Fixed window","Sliding window","Peak Search"};
 /*************************************************************/
 static void Usage()
@@ -102,5 +106,5 @@
   gLog << "Usage is:" << endl;
   gLog << "   makeHillas [-h] [-?] <datacards>" << endl << endl;
-  gLog << "     <datacards>: datacards file name (dafault input.datacards)" << endl;
+  gLog << "     <datacards>: datacards file name (dafault makehillas.datacards)" << endl;
   gLog << "     -?/-h: This help" << endl << endl;
 }
@@ -135,18 +139,30 @@
 void makeHillas()
 {
-  // Set the general tasks/containers
-  MExtractFixedWindow    extractor;
-  extractor.SetRange(hifirst,hilast,lofirst,lolast);
+  // Set the signal extractor
+  MExtractor* extractor;
+  switch(sext)
+    {
+    case 0:
+      extractor = new MExtractFixedWindow();
+      break;
+    case 1:
+      extractor = new MExtractSlidingWindow();
+      ((MExtractSlidingWindow*)extractor)->SetWindowSize(wsize,wsize);
+      break;
+    case 2:
+      extractor = new MExtractFixedWindowPeakSearch();
+      ((MExtractFixedWindowPeakSearch*)extractor)->SetWindows(wsize,wsize,4);
+      break;
+    default:
+      extractor = new MExtractFixedWindow();
+      break;
+    }
+
+  extractor->SetRange(hifirst,hilast,lofirst,lolast);
  
-  //MExtractSlidingWindow    extractor;
-  //extractor.SetRange(hifirst,hilast,lofirst,lolast);
-  //extractor.SetWindowSize(4,4);
-  
-  MGeomCamMagic       geomcam;
-  MGeomApply          geomapl;
-
-  /************************************/
-  /* FIRST LOOP: PEDESTAL COMPUTATION */
-  /************************************/
+
+  /****************************************************/
+  /* FIRST LOOP: PEDESTAL COMPUTATION FOR CALIBRATION */
+  /****************************************************/
 
   // If you want to exclude pixels from the beginning, read 
@@ -155,6 +171,6 @@
 
   MJPedestal pedcalloop;
-  pedcalloop.SetInput(&pediter);
-  pedcalloop.SetExtractor(&extractor);
+  pedcalloop.SetInput(&pedcaliter);
+  pedcalloop.SetExtractor(extractor);
   //  pedloop.SetBadPixels(badcam);
   //pedcalloop.SetOutputPath(outpath.Data());
@@ -171,5 +187,5 @@
 
   calloop.SetRelTimeCalibration(caltimeflag);
-  calloop.SetExtractor(&extractor);
+  calloop.SetExtractor(extractor);
   calloop.SetInput(&caliter);
   calloop.SetBadPixels(pedcalloop.GetBadPixels());
@@ -180,234 +196,464 @@
       return;
 
-
-  /************************************************************************/
-  /*                THIRD LOOP: PEDESTAL CALIBRATION INTO PHOTONS         */
-  /************************************************************************/
-  // First Compute the pedestals
-  MJPedestal pedloop;
-  pedloop.SetInput(&pediter);
-
-  if (!pedloop.Process())
-    return;
-
-  MParList  plist3;
-  MTaskList tlist3;
-  plist3.AddToList(&tlist3);
-  
-  // containers
-  MCerPhotEvt         nphot;
-  MPedPhotCam         nphotrms;
-  MExtractedSignalCam sigcam;
-
-  plist3.AddToList(&geomcam);
-  plist3.AddToList(&pedloop.GetPedestalCam());
-  plist3.AddToList(&calloop.GetCalibrationCam());
-  plist3.AddToList(&calloop.GetQECam());
-  plist3.AddToList(&calloop.GetRelTimeCam());
-  plist3.AddToList(&calloop.GetBadPixels());
-  plist3.AddToList(&sigcam);
-  plist3.AddToList(&nphot);
-  plist3.AddToList(&nphotrms);
-
-  
-  MCalibrate::CalibrationMode_t calMode=MCalibrate::kDefault;  
-  if(calflag==0)
-    calMode=MCalibrate::kNone;
-  if(calflag==-1)
-    calMode=MCalibrate::kDummy;
-
-  //tasks
-  MReadMarsFile read3("Events");
-  static_cast<MRead&>(read3).AddFiles(pediter); 
-  read3.DisableAutoScheme();
- 
-  MCalibrate      photcalc(calMode);
-  MPedPhotCalc    photrmscalc; 
-  
-  tlist3.AddToList(&read3);
-  tlist3.AddToList(&geomapl);
-  tlist3.AddToList(&extractor);
-  tlist3.AddToList(&photcalc);
-  tlist3.AddToList(&photrmscalc);
-
-  // Create and setup the eventloop
-  MEvtLoop evtloop3;
-  evtloop3.SetParList(&plist3);
-  if (!evtloop3.Eventloop())
-    return;
-  
-  tlist3.PrintStatistics();
-
-  /************************************************************************/
-  /*                FOURTH LOOP: DATA CALIBRATION INTO PHOTONS            */
-  /************************************************************************/
-
-  MParList  plist4;
-  MTaskList tlist4;
-  plist4.AddToList(&tlist4);
-  
-  // containers 
-  MHillas       hillas;
-  MNewImagePar  newimagepar;
-  MSrcPosCam    source;
-  MRawRunHeader runhead;
-
-  MArrivalTimeCam   timecam;
-
-
-  // islands
-  MIslands      isl;
-  MIslands      isl2;
-  MIslands      isl3;
-
-  isl.SetName("MIslands");  
-  isl2.SetName("MIslands2");
-  isl3.SetName("MIslands3");
-
-  plist4.AddToList(&timecam);
-  plist4.AddToList(&isl);
-  
-  if (islflag == 2)
-    plist4.AddToList(&isl2);
-  if (islflag == 3)
-    plist4.AddToList(&isl3);
-  
-  plist4.AddToList(&geomcam);
-  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);
-  plist4.AddToList(&source);
-  plist4.AddToList(&hillas);
-  plist4.AddToList(&newimagepar);
-  plist4.AddToList(&runhead);
-
-  // cuts
-  MF cut(filter);
-  
-  //tasks
-  MReadMarsFile read4("Events");
-  static_cast<MRead&>(read4).AddFiles(datiter); 
-  read4.DisableAutoScheme();
-  
-  MImgCleanStd      clean(lcore,ltail);
-  clean.SetCleanRings(lrings);
-  MImgCleanStd::CleaningMethod_t cleanMeth= MImgCleanStd::kStandard;  
-  if(cleanflag==2)
-    cleanMeth=MImgCleanStd::kDemocratic;
-  clean.SetMethod(cleanMeth);
-
-  MArrivalTimeCalc2 timecalc;
-  MIslandsCalc       island;
-  island.SetOutputName("MIslands");
-  island.SetAlgorithm(kalgorithm);
-
-  MBadPixelsTreat   interpolatebadpixels;
-  interpolatebadpixels.SetUseInterpolation();
-  interpolatebadpixels.SetProcessPedestal();
-  //  interpolatebadpixels.SetSloppyTreatment();
-
-  MIslandsClean      islclean(lnew);
-  islclean.SetInputName("MIslands");
-  islclean.SetMethod(kmethod);
-      
-  MIslandsCalc       island2;
-  island2.SetOutputName("MIslands2");  
-  island2.SetAlgorithm(kalgorithm);
-
-  MIslandsCalc       island3;
-  island3.SetOutputName("MIslands3");  
-  
-  
-  MHillasCalc       hcalc;
-  MHillasSrcCalc    csrc1;
-  
-  MContinue applycut(&cut);
-  applycut.SetInverted(kTRUE);
-  MWriteRootFile write(outname,"RECREATE");
-  
-  MHillasDisplay*  disphillas=NULL;
-
-  write.AddContainer("MHillas"        , "Parameters");
-  write.AddContainer("MHillasSrc"     , "Parameters");
-  write.AddContainer("MHillasExt"     , "Parameters");
-  write.AddContainer("MNewImagePar"   , "Parameters");
-  write.AddContainer("MRawEvtHeader"  , "Parameters");
-  write.AddContainer("MRawRunHeader"  , "Parameters");
-  write.AddContainer("MTime"          , "Parameters");
-  write.AddContainer("MConcentration" , "Parameters");
-  write.AddContainer("MSrcPosCam"     , "Parameters");
-  write.AddContainer("MIslands"       , "Parameters");
-
-  if (islflag == 2) 
-    write.AddContainer("MIslands2" , "Parameters");
-  if (islflag == 3) 
-    write.AddContainer("MIslands3" , "Parameters");
-
-
-  if(display)
-    {
-      disphillas = new MHillasDisplay(&nphot,&geomcam);
-      disphillas->SetIslandsName("MIslands");
+  // Next loops are different if we take pedestals from data or from pedestal files
+  if(pediter.GetNumRuns()==0)
+    {
+      /************************************************************************/
+      /*                 THIRD (SMALL) LOOP TO GET INITIAl PEDESTALS          */
+      /************************************************************************/      
+      MParList  plist3;
+      MTaskList tlist3;
+      
+      // containers
+      MPedestalCam  pedcamdata;      
+      MGeomCamMagic geomcam;
+      
+      plist3.AddToList(&tlist3);
+      plist3.AddToList(&geomcam);
+      plist3.AddToList(&pedcamdata);
+            
+      //tasks
+      MReadMarsFile read3("Events");
+      static_cast<MRead&>(read3).AddFiles(datiter); 
+      read3.DisableAutoScheme();
+
+      MGeomApply      geomapl;
+
+      MPedCalcFromLoGain peddatacalc;
+      peddatacalc.SetPedestalUpdate(kFALSE);
+      peddatacalc.SetRange(hifirst,hilast,lofirst,lolast);
+      peddatacalc.SetWindowSize(wsize,wsize);
+      peddatacalc.SetNumEventsDump(500);
+      peddatacalc.SetMaxHiGainVar(40);
+      
+      tlist3.AddToList(&read3);
+      tlist3.AddToList(&geomapl);
+      tlist3.AddToList(&peddatacalc);
+      
+      // Create and setup the eventloop
+      MEvtLoop evtloop3;
+      evtloop3.SetParList(&plist3);
+      if (!evtloop3.Eventloop(500))
+	return;
+      
+      tlist3.PrintStatistics();
+      
+      /************************************************************************/
+      /*       FOURTH LOOP: PEDESTAL+DATA CALIBRATION INTO PHOTONS            */
+      /************************************************************************/
+      
+      MParList  plist4;
+      MTaskList tlist4;
+      plist4.AddToList(&tlist4);
+      
+      // containers 
+      MCerPhotEvt     nphot;
+      MPedPhotCam     nphotrms;
+      MHillas         hillas;
+      MNewImagePar    newimagepar;
+      MSrcPosCam      source;
+      MRawRunHeader   runhead;      
+      MArrivalTimeCam timecam;      
+      // islands
+      MIslands      isl;
+      MIslands      isl2;
+      MIslands      isl3;
+      
+      isl.SetName("MIslands");  
+      isl2.SetName("MIslands2");
+      isl3.SetName("MIslands3");
+      
+      plist4.AddToList(&timecam);
+      plist4.AddToList(&isl);
+      
       if (islflag == 2)
-	disphillas->SetIslandsName("MIslands2");
+	plist4.AddToList(&isl2);
       if (islflag == 3)
-	disphillas->SetIslandsName("MIslands3");
-    }      
-
-  tlist4.AddToList(&read4);
-  tlist4.AddToList(&geomapl);
-  tlist4.AddToList(&extractor);
-  tlist4.AddToList(&photcalc);
-  if(calflag==11 || calflag==21)
-    tlist4.AddToList(&interpolatebadpixels);
-  tlist4.AddToList(&clean);
-  tlist4.AddToList(&timecalc);
-  tlist4.AddToList(&island);
-
-  if (islflag == 2)
-    {
-      tlist4.AddToList(&islclean);
-      tlist4.AddToList(&island2);
-    }
-
-  if (islflag == 3)
-    {
-      tlist4.AddToList(&islclean);
-      tlist4.AddToList(&island3);
-    }
-  
-  tlist4.AddToList(&hcalc);
-  tlist4.AddToList(&csrc1);
-  if(filter.Length())
-    tlist4.AddToList(&applycut);
-  tlist4.AddToList(&write);
-  if(display)
-    {
-      disphillas->SetPSFile();
-      disphillas->SetPSFileName(psfilename);
-      if(display==2) 
-	disphillas->SetPause(kFALSE);	
-      tlist4.AddToList(disphillas);
-    }
-
-  // Create and setup the eventloop
-  MEvtLoop datloop;
-  datloop.SetParList(&plist4);
-
-  cout << "*************************************************************" << endl;
-  cout << "***   COMPUTING DATA USING EXTRACTED SIGNAL (IN PHOTONS)  ***" << endl;
-  cout << "*************************************************************" << endl;
-  
-  if (!datloop.Eventloop(nmaxevents))
-    return;
-
-  tlist4.PrintStatistics();    
-
+	plist4.AddToList(&isl3);
+      
+      plist4.AddToList(&geomcam);
+      plist4.AddToList(&pedcamdata);
+      plist4.AddToList(&calloop.GetCalibrationCam());
+      plist4.AddToList(&calloop.GetQECam());
+      plist4.AddToList(&calloop.GetRelTimeCam());
+      plist4.AddToList(&calloop.GetBadPixels());
+      plist4.AddToList(&nphot);
+      plist4.AddToList(&nphotrms);
+      plist4.AddToList(&source);
+      plist4.AddToList(&hillas);
+      plist4.AddToList(&newimagepar);
+      plist4.AddToList(&runhead);
+      
+      // cuts
+      MF cut(filter);
+      
+      //tasks
+      MReadMarsFile read4("Events");
+      static_cast<MRead&>(read4).AddFiles(datiter); 
+      read4.DisableAutoScheme();
+            
+      peddatacalc.SetPedestalUpdate(kTRUE);
+
+      MCalibrateData::CalibrationMode_t calMode=MCalibrateData::kDefault;  
+      if(calflag==0)
+	calMode=MCalibrateData::kNone;
+      if(calflag==-1)
+	calMode=MCalibrateData::kDummy;
+      MCalibrateData  photcalc;
+      photcalc.SetCalibrationMode(calMode);
+      photcalc.EnablePedestalType(MCalibrateData::kRun);
+      photcalc.EnablePedestalType(MCalibrateData::kEvent);
+
+      MImgCleanStd      clean(lcore,ltail);
+      clean.SetCleanRings(lrings);
+      MImgCleanStd::CleaningMethod_t cleanMeth= MImgCleanStd::kStandard;  
+      if(cleanflag==2)
+	cleanMeth=MImgCleanStd::kDemocratic;
+      clean.SetMethod(cleanMeth);
+      
+      MArrivalTimeCalc2 timecalc;
+      MIslandsCalc       island;
+      island.SetOutputName("MIslands");
+      island.SetAlgorithm(kalgorithm);
+      
+      MBadPixelsTreat   interpolatebadpixels;
+      interpolatebadpixels.SetUseInterpolation();
+      interpolatebadpixels.SetProcessPedestal();
+      
+      MIslandsClean      islclean(lnew);
+      islclean.SetInputName("MIslands");
+      islclean.SetMethod(kmethod);
+      
+      MIslandsCalc       island2;
+      island2.SetOutputName("MIslands2");  
+      island2.SetAlgorithm(kalgorithm);
+      
+      MIslandsCalc       island3;
+      island3.SetOutputName("MIslands3");  
+      
+      
+      MHillasCalc       hcalc;
+      MHillasSrcCalc    csrc1;
+      
+      MContinue applycut(&cut);
+      applycut.SetInverted(kTRUE);
+      MWriteRootFile write(outname,"RECREATE");
+      
+      MHillasDisplay*  disphillas=NULL;
+      
+      write.AddContainer("MHillas"        , "Parameters");
+      write.AddContainer("MHillasSrc"     , "Parameters");
+      write.AddContainer("MHillasExt"     , "Parameters");
+      write.AddContainer("MNewImagePar"   , "Parameters");
+      write.AddContainer("MRawEvtHeader"  , "Parameters");
+      write.AddContainer("MRawRunHeader"  , "Parameters");
+      write.AddContainer("MTime"          , "Parameters");
+      write.AddContainer("MConcentration" , "Parameters");
+      write.AddContainer("MSrcPosCam"     , "Parameters");
+      write.AddContainer("MIslands"       , "Parameters");
+      
+      if (islflag == 2) 
+	write.AddContainer("MIslands2" , "Parameters");
+      if (islflag == 3) 
+	write.AddContainer("MIslands3" , "Parameters");
+      
+      
+      if(display)
+	{
+	  disphillas = new MHillasDisplay(&nphot,&geomcam);
+	  disphillas->SetIslandsName("MIslands");
+	  if (islflag == 2)
+	    disphillas->SetIslandsName("MIslands2");
+	  if (islflag == 3)
+	    disphillas->SetIslandsName("MIslands3");
+	}      
+      
+      tlist4.AddToList(&read4);
+      tlist4.AddToList(&geomapl);
+      tlist4.AddToList(&peddatacalc);
+      tlist4.AddToList(extractor);
+      tlist4.AddToList(&timecalc);
+      tlist4.AddToList(&photcalc);
+      if(calflag==11 || calflag==21)
+      	tlist4.AddToList(&interpolatebadpixels);
+      tlist4.AddToList(&clean);
+      tlist4.AddToList(&island);
+      
+      if (islflag == 2)
+	{
+	  tlist4.AddToList(&islclean);
+	  tlist4.AddToList(&island2);
+	}
+      
+      if (islflag == 3)
+	{
+	  tlist4.AddToList(&islclean);
+	  tlist4.AddToList(&island3);
+	}
+      
+      tlist4.AddToList(&hcalc);
+      tlist4.AddToList(&csrc1);
+      if(filter.Length())
+	tlist4.AddToList(&applycut);
+      tlist4.AddToList(&write);
+      if(display)
+	{
+	  disphillas->SetPSFile();
+	  disphillas->SetPSFileName(psfilename);
+	  if(display==2) 
+	    disphillas->SetPause(kFALSE);	
+	  tlist4.AddToList(disphillas);
+	}
+      
+      // Create and setup the eventloop
+      MEvtLoop datloop;
+      datloop.SetParList(&plist4);
+      
+      cout << "*************************************************************" << endl;
+      cout << "***   COMPUTING DATA USING EXTRACTED SIGNAL (IN PHOTONS)  ***" << endl;
+      cout << "*************************************************************" << endl;
+      
+      if (!datloop.Eventloop(nmaxevents))
+	return;
+      
+      tlist4.PrintStatistics();    
+      delete extractor;
+    }
+  else
+    {      
+      /************************************************************************/
+      /*                THIRD LOOP: PEDESTAL CALIBRATION INTO PHOTONS         */
+      /************************************************************************/
+      
+      // First Compute the pedestals
+      MJPedestal pedloop;
+      pedloop.SetInput(&pediter);
+      
+      if (!pedloop.Process())
+	return;
+      
+      MParList  plist3;
+      MTaskList tlist3;
+      plist3.AddToList(&tlist3);
+      
+      // containers
+      MGeomCamMagic       geomcam;
+      MCerPhotEvt         nphot;
+      MPedPhotCam         nphotrms;
+      MExtractedSignalCam sigcam;
+      
+      plist3.AddToList(&geomcam);
+      plist3.AddToList(&pedloop.GetPedestalCam());
+      plist3.AddToList(&calloop.GetCalibrationCam());
+      plist3.AddToList(&calloop.GetQECam());
+      plist3.AddToList(&calloop.GetRelTimeCam());
+      plist3.AddToList(&calloop.GetBadPixels());
+      plist3.AddToList(&sigcam);
+      plist3.AddToList(&nphot);
+      plist3.AddToList(&nphotrms);
+      
+      
+      MCalibrateData::CalibrationMode_t calMode=MCalibrateData::kDefault;  
+      if(calflag==0)
+	calMode=MCalibrateData::kNone;
+      if(calflag==-1)
+	calMode=MCalibrateData::kDummy;
+      
+      //tasks
+      MReadMarsFile read3("Events");
+      static_cast<MRead&>(read3).AddFiles(pediter); 
+      read3.DisableAutoScheme();
+      
+      MGeomApply      geomapl;
+      MPedPhotCalc    photrmscalc; 
+      MCalibrateData  photcalc;
+      photcalc.SetCalibrationMode(calMode);
+      
+      tlist3.AddToList(&read3);
+      tlist3.AddToList(&geomapl);
+      tlist3.AddToList(extractor);
+      tlist3.AddToList(&photcalc);
+      tlist3.AddToList(&photrmscalc);
+      
+      // Create and setup the eventloop
+      MEvtLoop evtloop3;
+      evtloop3.SetParList(&plist3);
+      if (!evtloop3.Eventloop())
+	return;
+      
+      tlist3.PrintStatistics();
+      
+      /************************************************************************/
+      /*                FOURTH LOOP: DATA CALIBRATION INTO PHOTONS            */
+      /************************************************************************/
+      
+      MParList  plist4;
+      MTaskList tlist4;
+      plist4.AddToList(&tlist4);
+      
+      // containers 
+      MHillas       hillas;
+      MNewImagePar  newimagepar;
+      MSrcPosCam    source;
+      MRawRunHeader runhead;
+      
+      MArrivalTimeCam   timecam;
+      
+      
+      // islands
+      MIslands      isl;
+      MIslands      isl2;
+      MIslands      isl3;
+      
+      isl.SetName("MIslands");  
+      isl2.SetName("MIslands2");
+      isl3.SetName("MIslands3");
+      
+      plist4.AddToList(&timecam);
+      plist4.AddToList(&isl);
+      
+      if (islflag == 2)
+	plist4.AddToList(&isl2);
+      if (islflag == 3)
+	plist4.AddToList(&isl3);
+      
+      plist4.AddToList(&geomcam);
+      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);
+      plist4.AddToList(&source);
+      plist4.AddToList(&hillas);
+      plist4.AddToList(&newimagepar);
+      plist4.AddToList(&runhead);
+      
+      // cuts
+      MF cut(filter);
+      
+      //tasks
+      MReadMarsFile read4("Events");
+      static_cast<MRead&>(read4).AddFiles(datiter); 
+      read4.DisableAutoScheme();
+      
+      MImgCleanStd      clean(lcore,ltail);
+      clean.SetCleanRings(lrings);
+      MImgCleanStd::CleaningMethod_t cleanMeth= MImgCleanStd::kStandard;  
+      if(cleanflag==2)
+	cleanMeth=MImgCleanStd::kDemocratic;
+      clean.SetMethod(cleanMeth);
+      
+      MArrivalTimeCalc2 timecalc;
+      MIslandsCalc       island;
+      island.SetOutputName("MIslands");
+      island.SetAlgorithm(kalgorithm);
+      
+      MBadPixelsTreat   interpolatebadpixels;
+      interpolatebadpixels.SetUseInterpolation();
+      interpolatebadpixels.SetProcessPedestal();
+      //  interpolatebadpixels.SetSloppyTreatment();
+      
+      MIslandsClean      islclean(lnew);
+      islclean.SetInputName("MIslands");
+      islclean.SetMethod(kmethod);
+      
+      MIslandsCalc       island2;
+      island2.SetOutputName("MIslands2");  
+      island2.SetAlgorithm(kalgorithm);
+      
+      MIslandsCalc       island3;
+      island3.SetOutputName("MIslands3");  
+      
+      
+      MHillasCalc       hcalc;
+      MHillasSrcCalc    csrc1;
+      
+      MContinue applycut(&cut);
+      applycut.SetInverted(kTRUE);
+      MWriteRootFile write(outname,"RECREATE");
+      
+      MHillasDisplay*  disphillas=NULL;
+      
+      write.AddContainer("MHillas"        , "Parameters");
+      write.AddContainer("MHillasSrc"     , "Parameters");
+      write.AddContainer("MHillasExt"     , "Parameters");
+      write.AddContainer("MNewImagePar"   , "Parameters");
+      write.AddContainer("MRawEvtHeader"  , "Parameters");
+      write.AddContainer("MRawRunHeader"  , "Parameters");
+      write.AddContainer("MTime"          , "Parameters");
+      write.AddContainer("MConcentration" , "Parameters");
+      write.AddContainer("MSrcPosCam"     , "Parameters");
+      write.AddContainer("MIslands"       , "Parameters");
+      
+      if (islflag == 2) 
+	write.AddContainer("MIslands2" , "Parameters");
+      if (islflag == 3) 
+	write.AddContainer("MIslands3" , "Parameters");
+      
+      
+      if(display)
+	{
+	  disphillas = new MHillasDisplay(&nphot,&geomcam);
+	  disphillas->SetIslandsName("MIslands");
+	  if (islflag == 2)
+	    disphillas->SetIslandsName("MIslands2");
+	  if (islflag == 3)
+	    disphillas->SetIslandsName("MIslands3");
+	}      
+      
+      tlist4.AddToList(&read4);
+      tlist4.AddToList(&geomapl);
+      tlist4.AddToList(extractor);
+      tlist4.AddToList(&photcalc);
+      if(calflag==11 || calflag==21)
+	tlist4.AddToList(&interpolatebadpixels);
+      tlist4.AddToList(&clean);
+      tlist4.AddToList(&timecalc);
+      tlist4.AddToList(&island);
+      
+      if (islflag == 2)
+	{
+	  tlist4.AddToList(&islclean);
+	  tlist4.AddToList(&island2);
+	}
+      
+      if (islflag == 3)
+	{
+	  tlist4.AddToList(&islclean);
+	  tlist4.AddToList(&island3);
+	}
+      
+      tlist4.AddToList(&hcalc);
+      tlist4.AddToList(&csrc1);
+      if(filter.Length())
+	tlist4.AddToList(&applycut);
+      tlist4.AddToList(&write);
+      if(display)
+	{
+	  disphillas->SetPSFile();
+	  disphillas->SetPSFileName(psfilename);
+	  if(display==2) 
+	    disphillas->SetPause(kFALSE);	
+	  tlist4.AddToList(disphillas);
+	}
+      
+      // Create and setup the eventloop
+      MEvtLoop datloop;
+      datloop.SetParList(&plist4);
+      
+      cout << "*************************************************************" << endl;
+      cout << "***   COMPUTING DATA USING EXTRACTED SIGNAL (IN PHOTONS)  ***" << endl;
+      cout << "*************************************************************" << endl;
+      
+      if (!datloop.Eventloop(nmaxevents))
+	return;
+      
+      tlist4.PrintStatistics();    
+      delete extractor;
+    }
 }
-//-------------------------------------------------------------------------------
+  //-------------------------------------------------------------------------------
 
 Bool_t readDatacards(TString& filename)
@@ -450,5 +696,6 @@
 	    cout << "readDataCards Warning: adding pedestal runs to the existing list" << endl;
 	  ifun >> word;
-	  pediter.AddRuns(word.Data(),idirname.Data());
+	  if(strcmp(word.Data(),"0")!=0)
+	    pediter.AddRuns(word.Data(),idirname.Data());
 	}
 
@@ -530,4 +777,8 @@
 	}
       
+      // cleaning level
+      if(strcmp(word.Data(),"EXTRACTOR")==0)
+	ifun >> sext >> hifirst >> hilast >> lofirst >> lolast >> wsize;
+      
       if(strcmp(word.Data(),"ISLFLAG")==0)
 	{
@@ -549,4 +800,5 @@
 
   pediter.Reset();
+  pedcaliter.Reset();
   caliter.Reset();
   datiter.Reset();
@@ -557,10 +809,18 @@
   cout << "* Datacards read from file " << filename << endl;
   cout << "************************************************" << endl;
-  cout << "Pedestal file (s): "  << endl;
-  while(!(pfile=pediter.Next()).IsNull())
+  cout << "Pedestal file (s) for calibration: "  << endl;
+  while(!(pfile=pedcaliter.Next()).IsNull())
     cout << pfile << endl;
   cout << "Calibration file (s): "  << endl;
   while(!(pfile=caliter.Next()).IsNull())
     cout << pfile << endl;
+  if(pediter.GetNumRuns()>0)
+    {
+      cout << "Pedestal file (s): "  << endl;
+      while(!(pfile=pediter.Next()).IsNull())
+	cout << pfile << endl;
+    }
+  else 
+    cout << "Warning: Pedestals for data will be computed from data themselves" << endl;
   cout << "Data file (s): "  << endl;
   while(!(pfile=datiter.Next()).IsNull())
@@ -572,7 +832,8 @@
   if(display)
     cout << "Generating PS file: " << psfilename << endl;
+  cout << "Signal Extractor: " << chext[sext] << " with bounds ("<<hifirst<<","<<hilast<<","<<lofirst<<","<<lolast<<"), window size " << wsize << endl;
   cout << "Calibration: ";
   if(calflag==0)    
-    cout << "Pixel area proportional intercalibration" << endl;
+    cout << "Pixel area proportional intercalibration (kNone)" << endl;
   else if(calflag==-1)    
     cout << "No calibration whatsoever" << endl;
@@ -582,5 +843,5 @@
     cout << "Default calibration + bad pixels interpolation" << endl;
   cout << "Cleaning level: ("<<lcore<<","<<ltail<<") - " << lrings << "ring" << endl;
-  cout << "Cleaning methode: "<< cleanflag << endl;
+  cout << "Cleaning method: "<< cleanflag << endl;
   if (islflag == 1 || islflag == 2)
     cout << "Island calcultation..." << "using algorithm #" << kalgorithm <<endl;
@@ -591,7 +852,7 @@
   cout << "***********" << endl << endl;
   
-  if(!pediter.GetNumEntries())
-    {
-      cout << "No pedestal file name specified" << endl;
+  if(!pedcaliter.GetNumEntries())
+    {
+      cout << "No pedestal file for calibration specified" << endl;
       return kFALSE;
     }
Index: trunk/MagicSoft/Mars/mtemp/mifae/programs/makehillas.datacard
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/programs/makehillas.datacard	(revision 5207)
+++ trunk/MagicSoft/Mars/mtemp/mifae/programs/makehillas.datacard	(revision 5208)
@@ -11,17 +11,21 @@
 
 // Maximun number of (data) events to be processed)
-NEVENTS 9999999
+NEVENTS 99999999
 
 // data file directory
-IDIR /local_disk/jrico/rootdata/Crab20040215/
+IDIR /mnt/magic/Data/rootdata/CrabNebula/Period021/2004_09_22/
 
 // Pedestal (PRUNS), calibration (CRUNS) and data runs (DRUNS), e.g 1500-23444,25444,25455-26544
-PRUNS 16743
-CRUNS 16744
-DRUNS 16745
+// if PRUNS 0, take pedestals from low gains
+PCRUNS 39313
+CRUNS  39315
+PRUNS 0
+DRUNS 39261,39262,39264,39265,39269,39271,39273,39274,39276,39277,39279,39280,39282,39283,39285
+//,39286,39288,39290,39292-39294,39296-39299,39301,39302,39304-39306,39308,39309,39311,39318,39319,39321,39322,39324,39325,39327,39328,39330,39331,39333,39334,39336-39338,39340-39342,39344,39348-39350,39352-39355,39357,39358,39360-39362,39364-39366,39368-39370,39372,39373
+// 37478-37480,37482-37484,37486,37487,37489-37491,37493-37495,37497-37499,37501-37502,37504-37505,37507-37508,37510-37512,37514,37516-37519,37521,37522,37524,37525,37527-37529,37531,37532,37534,37535,37537-37539,37541-37544,37546-37551,37553-37555
 
 // output file name
 // OUTFILE ~/magic/mars/mars/hillasCrab/crab20040215OnA.root
-OUTFILE ./prueba.root
+OUTFILE /local_disk/jrico/prueba2.root
 
 // Selection cut. 
@@ -40,4 +44,8 @@
 PSFILENAME makehillas.ps
 
+// Signal extractor, higain first, higainlast, logainfirst, logainlast, window size
+// signal extractors: 0 fixed window, 1 sliding window, 2 peak search
+EXTRACTOR 2 0 14 2 14 6
+
 // calibration flag:
 // -1: kDummy
@@ -47,17 +55,17 @@
 // 11: kDefault(F factor) + bad pixel interpolation
 // 21: kDemocratic + bad pixel interpolation
-CALFLAG 0
+CALFLAG 1
 
 // calibration time:
 //   0: kFALSE (no time calibration)
 //   1: kTRUE  (time calibration)
-//CALTIME 1
+CALTIME 1
 
 
 // Cleaning level (tail cut, boundary cut, number of rings, cleaning method - 1=standard, 2=democratic)
-CLEANLEVEL 3.0 1.5 1 1
+CLEANLEVEL 2.5 2.0 1 1
 
 //Island calculations
-// 0  nothing about islands    1:normal algorithm 
+// 0  same as 1                1:normal algorithm 
 // 1  islands w/o cleaning     2:alternative algorithm
 // 2  islands  w  cleaning
