Index: /trunk/Mars/fact/analysis/mc/callisto.C
===================================================================
--- /trunk/Mars/fact/analysis/mc/callisto.C	(revision 17913)
+++ /trunk/Mars/fact/analysis/mc/callisto.C	(revision 17914)
@@ -32,5 +32,5 @@
 #include "MHSectorVsTime.h"
 #include "MHCamEvent.h"
-#include "MExtractTimeAndChargeSpline.h"
+#include "MExtractFACT.h"
 #include "MFillH.h"
 #include "MDrsCalibApply.h"
@@ -75,8 +75,8 @@
  */
 
-int callisto(const TString drsfile="test300samples.drs.fits",
+int callisto(const TString drsfile="test300samples2.drs.fits.gz",
              const TString pedfile="00000001.001_P_MonteCarlo000_Events.fits",
              const TString datfile="00000003.387_D_MonteCarlo010_Events.fits",
-             TString outfile = "",
+             TString outpath = "",
              TString displayfile = "", TString displaytitle = "")
 {
@@ -88,9 +88,11 @@
 
     FileStat_t fstat;
-    int rc = gSystem->GetPathInfo(outfile, fstat);
+    int rc = gSystem->GetPathInfo(outpath, fstat);
     bool isdir = !rc || R_ISDIR(fstat.fMode);
 
-    const char *buf = gSystem->ConcatFileName(outfile, "callisto.root");
-    outfile = buf;
+    TString filename = datfile + "_callisto.root";
+    filename.Replace(0, filename.Last('/')+1, "");
+    const char *buf = gSystem->ConcatFileName(outpath, filename);
+    TString outfile = buf;
     delete [] buf;
 
@@ -119,116 +121,7 @@
 
     // map file to use (get that from La Palma!)
-    const char *pmap = usemap ? "TestForThomas/FACT/FACTmap111030.txt" : NULL;
-
-    Bool_t maximum = kTRUE;
-
-    //const char *lp_template    = maximum ?
-    //    "/cm/shared/apps/fact/Mars_svn_LP/template-lp-extractor-maximum.root" :
-    //    "/cm/shared/apps/fact/Mars_svn_LP/template-lp-extractor-leading-edge.root";
-
-    const char *pulse_template = "TestForThomas/FACT/template-pulse.root";
+    const char *pmap = usemap ? "/home/isdc/toscanos/FACT/Mars_svn/resources/FACTmap111030.txt" : NULL;
 
     // ------------------------------------------------------
-
-    // Calib: 51 / 90 / 197 (20% TH)
-    // Data:  52 / 64 / 104 (20% TH)
-
-    // Extraction range in slices. It will always(!) contain the full range
-    // of integration
-    const int first_slice =  20; //  10ns
-    const int last_slice  = 250; // 125ns
-
-    // Note that rise and fall time mean different things whether you use IntegralFixed or IntegraRel:
-    //
-    //  IntegralFixed:
-    //    * fRiseTime: Number of slices left  from arrival time
-    //    * fFallTime: Number of slices right from arrival time
-    //  IntegralRel:
-    //    * fRiseTime: Number of slices left  from maximum time
-    //    * fFallTime: Number of slices right from maximum time
-    //
-    const int rise_time_cal = maximum ?  40 :  10; // was 13;   5ns
-    const int fall_time_cal = maximum ? 120 : 160; // was 23;  80ns
-
-    const int rise_time_dat = maximum ?  10 :   2; // was 13; was 10;   1ns
-    const int fall_time_dat = maximum ?  40 :  48; // was 23; was 40;  24ns
-
-    // Extraction type: Extract integral and half leading edge
-
-    const MExtralgoSpline::ExtractionType_t type = maximum ? (MExtralgoSpline::kIntegralRel) : (MExtralgoSpline::kIntegralFixed);
-    //const int type = MExtralgoSpline::kIntegralFixed;
-
-
-    const double heighttm   = 0.5; // IntegralAbs { 1.5pe * 9.6mV/pe } / IntegralRel { 0.5 }
-
-    Long_t max  =    0;  // All
-    Long_t max3 =  max;  // Pedestal Rndm
-    Long_t max4 =  max;  // Pedestal Ext
-
-    // ======================================================
-
-    if (pmap && gSystem->AccessPathName(pmap, kFileExists))
-    {
-        gLog << err << "ERROR - Cannot access mapping file '" << pmap << "'" << endl;
-        return 1;
-    }
-
-    gLog.Separator("Callisto");
-    gLog << all;
-    gLog << "Data File:     " << datfile << '\n';
-    gLog << "DRS calib 300: " << drsfile << endl;;
-
-    MDrsCalibration drscalib300;
-    if (!drscalib300.ReadFits(drsfile.Data())) {
-        gLog << err << "ERROR - Cannot access drscallib300 file '" << drsfile << "'" << endl;
-        return 5;
-    }
-    gLog << all;
-    gLog << "Pedestal file: " << pedfile << '\n';
-    gLog << "Output file:   " << outfile << '\n';
-    gLog << "Display file:  " << displayfile << '\n';
-    gLog << "Display title: " << displaytitle << endl;
-
-    // ------------------------------------------------------
-    MStatusArray arrt, arrp;
-
-    // TFile ft(lp_template);
-    // if (arrt.Read()<=0)
-    // {
-    //     gLog << err << "ERROR - Reading LP template from " << lp_template << endl;
-    //     return 100;
-    // }
-
-    // MHCamera *lpref = (MHCamera*)arrt.FindObjectInCanvas("ExtCalSig;avg", "MHCamera", "Cam");
-    // if (!lpref)
-    // {
-    //     gLog << err << "ERROR - LP Template not found in " << lp_template << endl;
-    //     return 101;
-    // }
-    // lpref->SetDirectory(0);
-
-    // MHCamera *gain = (MHCamera*)arrt.FindObjectInCanvas("gain", "MHCamera", "Gain");
-    // if (!gain)
-    // {
-    //     gLog << err << "ERROR - Gain not found in " << lp_template << endl;
-    //     return 101;
-    // }
-    // gain->SetDirectory(0);
-
-    TFile fp(pulse_template);
-    if (arrp.Read()<=0)
-    {
-        gLog << err << "ERROR - Reading Pulse template from " << pulse_template << endl;
-        return 102;
-    }
-
-    TH1F *hpulse = (TH1F*)arrp.FindObjectInCanvas("hPixelEdgeMean0_0", "TH1F", "cgpPixelPulses0");
-    if (!hpulse)
-    {
-        gLog << err << "ERROR - Pulse Template not found in " << pulse_template << endl;
-        return 103;
-    }
-    hpulse->SetDirectory(0);
-    // ======================================================
 
     MStatusDisplay *d = new MStatusDisplay;
@@ -236,5 +129,4 @@
     MBadPixelsCam badpixels;
     badpixels.InitSize(1440);
-    /*
     badpixels[ 424].SetUnsuitable(MBadPixelsPix::kUnsuitable);
     badpixels[ 583].SetUnsuitable(MBadPixelsPix::kUnsuitable);
@@ -243,5 +135,4 @@
     badpixels[1208].SetUnsuitable(MBadPixelsPix::kUnsuitable);
     badpixels[1399].SetUnsuitable(MBadPixelsPix::kUnsuitable);
-    */
     //  Twin pixel
     //     113
@@ -251,4 +142,91 @@
     //    1195
     //    1393
+
+    // ------------------------------------------------------
+
+    // Calib: 51 / 90 / 197 (20% TH)
+    // Data:  52 / 64 / 104 (20% TH)
+
+    // Extraction range in slices. It will always(!) contain the full range
+    // of integration
+    const int first_slice =  25; //  10ns
+    const int last_slice  = 225; // 125ns
+
+    Long_t max  =    0;  // All
+    Long_t max3 =  max;  // Pedestal Rndm
+    Long_t max4 =  max;  // Pedestal Ext
+
+    // ======================================================
+
+    //double scale = 0.1;
+    double scale = 0.1024;
+
+    // ======================================================
+
+    if (pmap && gSystem->AccessPathName(pmap, kFileExists))
+    {
+        gLog << err << "ERROR - Cannot access mapping file '" << pmap << "'" << endl;
+        return 1;
+    }
+
+    gLog.Separator("Callisto");
+    gLog << all;
+    gLog << "Data File:     " << datfile << '\n';
+    gLog << "DRS calib 300: " << drsfile << endl;;
+
+    MDrsCalibration drscalib300;
+    if (!drscalib300.ReadFits(drsfile.Data())) {
+        gLog << err << "ERROR - Cannot access drscallib300 file '" << drsfile << "'" << endl;
+        return 5;
+    }
+    gLog << all;
+    gLog << "Pedestal file: " << pedfile << '\n';
+    gLog << "Output file:   " << outfile << '\n';
+    gLog << "Display file:  " << displayfile << '\n';
+    gLog << "Display title: " << displaytitle << endl;
+
+    // ------------------------------------------------------
+/*
+    MStatusArray arrt, arrp;
+
+    TFile ft(lp_template);
+    if (arrt.Read()<=0)
+    {
+        gLog << err << "ERROR - Reading LP template from " << lp_template << endl;
+        return 100;
+    }
+
+    MHCamera *lpref = (MHCamera*)arrt.FindObjectInCanvas("ExtCalSig;avg", "MHCamera", "Cam");
+    if (!lpref)
+    {
+        gLog << err << "ERROR - LP Template not found in " << lp_template << endl;
+        return 101;
+    }
+    lpref->SetDirectory(0);
+
+    MHCamera *gain = (MHCamera*)arrt.FindObjectInCanvas("gain", "MHCamera", "Gain");
+    if (!gain)
+    {
+        gLog << err << "ERROR - Gain not found in " << lp_template << endl;
+        return 101;
+    }
+    gain->SetDirectory(0);
+
+    TFile fp(pulse_template);
+    if (arrp.Read()<=0)
+    {
+        gLog << err << "ERROR - Reading Pulse template from " << pulse_template << endl;
+        return 102;
+    }
+
+    TH1F *hpulse = (TH1F*)arrp.FindObjectInCanvas("hPixelEdgeMean0_0", "TH1F", "cgpPixelPulses0");
+    if (!hpulse)
+    {
+        gLog << err << "ERROR - Pulse Template not found in " << pulse_template << endl;
+        return 103;
+    }
+    hpulse->SetDirectory(0);
+    */
+    // ======================================================
 
     MDrsCalibrationTime timecam;
@@ -268,5 +246,5 @@
 
     // ========================= Result ==================================
-
+/*
     //~ Double_t avgS = evt1f.GetHist()->GetMean();
     //~ Double_t medS = evt1f.GetHist()->GetMedian();
@@ -340,5 +318,5 @@
     //hcalco.Scale(scale);
     hcalco.DrawCopy();
-
+*/
     // ======================================================
 
@@ -372,34 +350,15 @@
     MDrsCalibApply drsapply3;
 
+    MFilterData filterdata5;
+
     //---
 
-    MExtractTimeAndChargeSpline extractor3;
+    MExtractFACT extractor3;
     extractor3.SetRange(first_slice, last_slice);
-    extractor3.SetRiseTimeHiGain(rise_time_dat);
-    extractor3.SetFallTimeHiGain(fall_time_dat);
-    extractor3.SetHeightTm(heighttm);
-    extractor3.SetChargeType(type);
-    extractor3.SetSaturationLimit(600000);
     extractor3.SetNoiseCalculation(kTRUE);
-
-//    MHCamEvent evt2a(0, "PedRdm", "Extracted Pedestal Signal;;S");
-
-//    MFillH fill2a(&evt2a, "MExtractedSignalCam", "FillPedRndm");
-
-    // Use this for data, but not for calibration events
-//    evt2a.SetErrorSpread(kFALSE);
-
-    /*
-     MCalibrateData conv3;
-     conv3.SetCalibrationMode(MCalibrateData::kNone);
-     conv3.SetPedestalFlag(MCalibrateData::kNo);
-     conv3.SetCalibConvMinLimit(0);
-     conv3.SetCalibConvMaxLimit(10000);
-     conv3.SetScaleFactor(scale);
-     */
 
     MCalibrateFact conv3;
     conv3.SetScale(scale);
-    conv3.SetCalibConst(calib);
+    //conv3.SetCalibConst(calib);
 
     MBadPixelsTreat treat3;
@@ -420,4 +379,5 @@
     tlist3.AddToList(&drsapply3);
     tlist3.AddToList(&cont3);
+    tlist3.AddToList(&filterdata3);
     tlist3.AddToList(&extractor3);
 //    tlist3.AddToList(&fill3a);
@@ -461,30 +421,13 @@
     MDrsCalibApply drsapply4;
 
-    MExtractTimeAndChargeSpline extractor4;
+    MFilterData filterdata4;
+
+    MExtractFACT extractor4;
     extractor4.SetRange(first_slice, last_slice);
-    extractor4.SetRiseTimeHiGain(rise_time_dat);
-    extractor4.SetFallTimeHiGain(fall_time_dat);
-    extractor4.SetHeightTm(heighttm);
-    extractor4.SetChargeType(type);
-    extractor4.SetSaturationLimit(600000);
     extractor4.SetNoiseCalculation(kFALSE);
 
-    //    MHCamEvent evt3a(0, "PedExt", "Extracted Pedestal Signal;;S");
-
-    //    MFillH fill3a(&evt3a, "MExtractedSignalCam", "FillPedExt");
-
-    // Use this for data, but not for calibration events
-//    evt3a.SetErrorSpread(kFALSE);
-/*
-    MCalibrateData conv4;
-    conv4.SetCalibrationMode(MCalibrateData::kNone);
-    conv4.SetPedestalFlag(MCalibrateData::kNo);
-    conv4.SetCalibConvMinLimit(0);
-    conv4.SetCalibConvMaxLimit(10000);
-    conv4.SetScaleFactor(scale);
-*/
     MCalibrateFact conv4;
     conv4.SetScale(scale);
-    conv4.SetCalibConst(calib);
+    //conv4.SetCalibConst(calib);
 
     MBadPixelsTreat treat4;
@@ -504,6 +447,6 @@
     tlist4.AddToList(&drsapply4);
     tlist4.AddToList(&cont4);
+    tlist4.AddToList(&filterdata4);
     tlist4.AddToList(&extractor4);
-//    tlist4.AddToList(&fill4a);
     tlist4.AddToList(&conv4);
     tlist4.AddToList(&treat4);
@@ -550,4 +493,8 @@
     MDrsCalibApply drsapply5;
 
+    MTreatSaturation treatsat5;
+
+    MFilterData filterdata5;
+
     MFDataPhrase filterdat("(MRawEvtHeader.GetTriggerID&0xff00)==0",     "SelectDat");
     MFDataPhrase filtercal("(MRawEvtHeader.GetTriggerID&0xff00)==0x100", "SelectCal");
@@ -559,29 +506,14 @@
     // ---
 
-    MExtractTimeAndChargeSpline extractor5dat;
+    MExtractFACT extractor5dat;
     extractor5dat.SetRange(first_slice, last_slice);
-    extractor5dat.SetRiseTimeHiGain(rise_time_dat);
-    extractor5dat.SetFallTimeHiGain(fall_time_dat);
-    extractor5dat.SetHeightTm(heighttm);
-    extractor5dat.SetChargeType(type);
-    extractor5dat.SetSaturationLimit(600000);
     extractor5dat.SetNoiseCalculation(kFALSE);
 
-    MExtractTimeAndChargeSpline extractor5cal;
+    MExtractFACT extractor5cal;
     extractor5cal.SetRange(first_slice, last_slice);
-    extractor5cal.SetRiseTimeHiGain(rise_time_cal);
-    extractor5cal.SetFallTimeHiGain(fall_time_cal);
-    extractor5cal.SetHeightTm(heighttm);
-    extractor5cal.SetChargeType(type);
-    extractor5cal.SetSaturationLimit(600000);
     extractor5cal.SetNoiseCalculation(kFALSE);
 
-    MExtractTimeAndChargeSpline extractor5tm("ExtractTM");
+    MExtractFACT extractor5tm("ExtractTM");
     extractor5tm.SetRange(last_slice, 294);
-    extractor5tm.SetRiseTimeHiGain(1);
-    extractor5tm.SetFallTimeHiGain(1);
-    extractor5tm.SetHeightTm(0.5);
-    extractor5tm.SetChargeType(MExtralgoSpline::kAmplitudeRel);
-    extractor5tm.SetSaturationLimit(600000);
     extractor5tm.SetNoiseCalculation(kFALSE);
     extractor5tm.SetNameSignalCam("TimeMarkerAmplitude");
@@ -593,15 +525,7 @@
 
     // ---
-/*
-    MCalibrateData conv5;
-    conv5.SetCalibrationMode(MCalibrateData::kNone);
-    conv5.SetPedestalFlag(MCalibrateData::kNo);
-    conv5.SetCalibConvMinLimit(0);
-    conv5.SetCalibConvMaxLimit(10000);
-    conv5.SetScaleFactor(scale);
-*/
     MCalibrateFact conv5;
     conv5.SetScale(scale);
-    conv5.SetCalibConst(calib);
+    //conv5.SetCalibConst(calib);
 
     MCalibrateDrsTimes calctm5;
@@ -689,4 +613,6 @@
     tlist5.AddToList(&filterped);
     tlist5.AddToList(&fill5a);
+    tlist5.AddToList(&treatsat5);
+    tlist5.AddToList(&filterdata5);
     tlist5.AddToList(&extractor5dat);
     tlist5.AddToList(&extractor5cal);
