Index: trunk/Mars/fact/analysis/callisto.C
===================================================================
--- trunk/Mars/fact/analysis/callisto.C	(revision 17877)
+++ trunk/Mars/fact/analysis/callisto.C	(revision 17878)
@@ -13,5 +13,5 @@
     // map file to use (get that from La Palma!)
     const char *map = usemap ? "/home/fact/FACT++/FACTmap111030.txt" : NULL;
-
+/*
     Bool_t maximum = kTRUE;
 
@@ -21,10 +21,13 @@
 
     const char *pulse_template = "template-pulse.root";
-
+*/
     // ------------------------------------------------------
 
-    bool use_delays=false;
+    //bool use_delays=false;
 
     int spike_removal=3;
+
+    // The gain as extracted from our dark count spectra
+    double gain = 258;
 
     // ------------------------------------------------------
@@ -32,6 +35,6 @@
     // 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
+    const int first_slice =  25; //  10ns
+    const int last_slice  = 225; // 125ns
 
     // Note that rise and fall time mean different things whether you use IntegralFixed or IntegraRel:
@@ -44,4 +47,5 @@
     //    * 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
@@ -57,5 +61,5 @@
 
     const double heighttm   = 0.5; // IntegralAbs { 1.5pe * 9.6mV/pe } / IntegralRel { 0.5 }
-
+*/
     Long_t max  =    0;  // All
     Long_t max0 =  max;  // Time marker
@@ -277,5 +281,5 @@
 
     // ======================================================
-
+/*
     gLog << endl;
     gLog.Separator("Processing external light pulser run");
@@ -489,4 +493,43 @@
     //hcalco.Scale(scale);
     hcalco.DrawCopy();
+*/
+
+    TF1 f("f", "[0]*(1-1/(1+exp(x/[1])))*exp(-x/[2])", -15, 150);
+    f.SetParameter(0, gain*0.05143);
+    f.SetParameter(1, 1.075);
+    f.SetParameter(2, 19.3);
+    f.SetNpx(2*165); //2GHz
+
+    // Convert to graph
+    TGraph g(&f);
+
+    // Convert to float
+    MArrayF x(g.GetN());
+    MArrayF y(g.GetN());
+    for (int i=0; i<g.GetN(); i++)
+    {
+        x[i] = g.GetX()[i];
+        y[i] = g.GetY()[i];
+    }
+
+    MFilterData filter;
+    filter.Filter(1, g.GetN(), y.GetArray(), y.GetArray());
+
+    // Define spline
+    MArrayF der1(g.GetN());
+    MArrayF der2(g.GetN());
+
+    MExtralgoSpline spline(y.GetArray(), y.GetSize(),
+                           der1.GetArray(), der2.GetArray());
+
+    spline.SetExtractionType(MExtralgoSpline::kAmplitudeRel);
+    spline.SetHeightTm(0.5);
+
+    // Estimate where the maximum is and extract signal
+    Long64_t maxi = TMath::LocMax(y.GetSize(), y.GetArray());
+    spline.Extract(maxi);
+
+    // Scale factor for signal extraction
+    double scale = 1./spline.GetSignal();
 
     // ======================================================
@@ -676,13 +719,10 @@
     // ---
 
-    MExtractTimeAndChargeSpline extractor5dat;
+    MTreatSaturation treatsat5;
+    MFilterData filterdata5;
+
+    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;
     extractor5cal.SetRange(first_slice, last_slice);
@@ -704,7 +744,7 @@
     extractor5tm.SetNameSignalCam("TimeMarkerAmplitude");
     extractor5tm.SetNameTimeCam("TimeMarkerTime");
-
+*/
     extractor5dat.SetFilter(&filterncl);
-    extractor5cal.SetFilter(&filtercal);
+    //extractor5cal.SetFilter(&filtercal);
     //extractor4tm.SetFilter(&filtercal);
 
@@ -716,5 +756,5 @@
     MCalibrateDrsTimes calctm5;
     calctm5.SetNameUncalibrated("UncalibratedTimes");
-
+/*
     MCalibrateDrsTimes calctm5tm("CalibrateTimeMarker");
     calctm5tm.SetNameArrivalTime("TimeMarkerTime");
@@ -766,10 +806,10 @@
     //fill5w.SetDrawOption("gaus");
     //fill5x.SetDrawOption("gaus");
-
+*/
 
     MBadPixelsTreat treat5;
     treat5.SetProcessPedestalRun(kFALSE);
     treat5.SetProcessPedestalEvt(kFALSE);
-
+/*
     MHSectorVsTime hist5cal("CalVsTm");
     MHSectorVsTime hist5ped("PedVsTm");
@@ -789,5 +829,5 @@
     fill5cal.SetFilter(&filtercal);
     fill5ped.SetFilter(&filterped);
-
+*/
     MHCamEvent evt5b(0, "ExtSig",   "Extracted signal;;S [mV·sl]");
     MHCamEvent evt5c(0, "CalSig",   "Calibrated and interpolated signal;;S [~phe]");
@@ -831,5 +871,5 @@
     MContinue test;
     test.SetFilter(&filterncl);
-
+/*
     MTaskList tlist5tm;
     tlist5tm.AddToList(&extractor5tm);
@@ -846,5 +886,5 @@
     tlist5tm.AddToList(&fill5x);
     tlist5tm.SetFilter(&filtercal);
-
+*/
     MTaskList tlist5dat;
     tlist5dat.AddToList(&fill5b);
@@ -863,12 +903,14 @@
     tlist5.AddToList(&filterped);
     tlist5.AddToList(&fill5a);
+    tlist5.AddToList(&treatsat5);
+    tlist5.AddToList(&filterdata5);
     tlist5.AddToList(&extractor5dat);
-    tlist5.AddToList(&extractor5cal);
+    //tlist5.AddToList(&extractor5cal);
     tlist5.AddToList(&calctm5);
-    tlist5.AddToList(&tlist5tm);
+    //tlist5.AddToList(&tlist5tm);
     tlist5.AddToList(&conv5);
     tlist5.AddToList(&treat5);
-    tlist5.AddToList(&fill5ped);
-    tlist5.AddToList(&fill5cal);
+    //tlist5.AddToList(&fill5ped);
+    //tlist5.AddToList(&fill5cal);
     tlist5.AddToList(&tlist5dat);
     tlist5.AddToList(&write5);
