Index: /branches/MarsGapdTimeJitter/Makefile.rules
===================================================================
--- /branches/MarsGapdTimeJitter/Makefile.rules	(revision 18281)
+++ /branches/MarsGapdTimeJitter/Makefile.rules	(revision 18282)
@@ -39,5 +39,5 @@
 	@echo " - Generating dictionary $(CINT)Cint.cc"
 	rootcint -f $(CINT)Cint.cc \
-	-c $(INCLUDES) $(LIBNOVA_INCLUDE_PATH) $(DEFINES) $(HEADERS) $(CINT)Incl.h $(CINT)LinkDef.h 
+	-c -p $(INCLUDES) $(LIBNOVA_INCLUDE_PATH) $(DEFINES) $(HEADERS) $(CINT)Incl.h $(CINT)LinkDef.h 
 
 %.d:
Index: /branches/MarsGapdTimeJitter/fact/analysis/callisto.C
===================================================================
--- /branches/MarsGapdTimeJitter/fact/analysis/callisto.C	(revision 18281)
+++ /branches/MarsGapdTimeJitter/fact/analysis/callisto.C	(revision 18282)
@@ -1,5 +1,8 @@
 #include "MLogManip.h"
 
-int callisto(const char *seqfile="seq/2012/01/23/20120123_023.seq", const char *outpath = "output", bool use_delays=false)
+int callisto(const char *seqfile="seq/2012/01/23/20120123_023.seq", const char *outpath = "output",
+//             TString drstime = "/gpfs0/fact/processing/drs_time_calib/20111115.time.drs.fits",
+             const char *drstime = "/gpfs0/fact/processing/drs_time_calib/20111115.time.drs.fits",
+             const char *delays="resources/delays-20150217.txt")
 {
     // ======================================================
@@ -107,5 +110,4 @@
     }
 
-    TString timfile = drs.GetFileName(0, MSequence::kFitsDat);
     TString drs1024 = drs.GetFileName(0, MSequence::kFitsDrs);
     TString pedfile = seq.GetFileName(0, MSequence::kFitsPed);
@@ -115,15 +117,19 @@
     gLog << "DRS calib     300: " << drsfile << '\n';
     gLog << "DRS calib    1024: " << drs1024 << "\n\n";
+    gLog << "DRS calib    Time: " << drstime << "\n\n";
+
+    MDrsCalibrationTime drscalibtime;
+    if (!drscalibtime.ReadFits(drstime)))
+        return 5;
 
     MDrsCalibration drscalib300;
     if (!drscalib300.ReadFits(drsfile.Data()))
-        return 5;
+        return 6;
 
     MDrsCalibration drscalib1024;
     if (!drscalib1024.ReadFits(drs1024.Data()))
-        return 6;
+        return 7;
 
     gLog << all;
-    gLog << "Time calibration : " << timfile << '\n';
     gLog << "Pedestal     file: " << pedfile << '\n';
     gLog << "Light Pulser file: " << calfile << '\n' << endl;
@@ -135,5 +141,5 @@
     {
         gLog << err << "ERROR - Sequence valid but without files." << endl;
-        return 7;
+        return 8;
     }
     iter.Print();
@@ -195,10 +201,10 @@
     // hrate.DefaultLabelY("ERROR");
 
-    MDrsCalibrationTime timecam;
+//    MDrsCalibrationTime timecam;
 
     gStyle->SetOptFit(kTRUE);
 
     // ======================================================
-
+/*
     gLog << endl;
     gLog.Separator("Processing DRS timing calibration run");
@@ -240,5 +246,5 @@
     if (!loop0.GetDisplay())
         return 9;
-
+*/
     /*
      MHDrsCalibrationT *t = (MHDrsCalibrationT*)plist4.FindObject("MHDrsCalibrationT");
@@ -258,5 +264,5 @@
     plist1.AddToList(&drscalib300);
     plist1.AddToList(&badpixels);
-    plist1.AddToList(&timecam);
+    plist1.AddToList(&drscalibtime);
 
     MEvtLoop loop1("DetermineCalConst");
@@ -348,12 +354,21 @@
     tlist1.AddToList(&fill1d);
 
-    if (!loop1.Eventloop(max1))
-        return 10;
-
-    if (!loop1.GetDisplay())
-        return 11;
-
-    if (use_delays)
-        timecam.SetDelays(*evt1h.GetHist());
+    //if (!loop1.Eventloop(max1))
+    //    return 10;
+
+    //if (!loop1.GetDisplay())
+    //    return 11;
+
+    if (delays)
+    {
+        TGraph g(delays);
+        if (g.GetN()!=1440)
+        {
+            gLog << err << "Error reading file " << delays << endl;
+            return 41;
+        }
+
+        drscalibtime.SetDelays(g);
+    }
 
     // ======================================================
@@ -368,5 +383,5 @@
     plist3.AddToList(&drscalib300);
     plist3.AddToList(&badpixels);
-    plist3.AddToList(&timecam);
+    plist3.AddToList(&drscalibtime);
 
     MEvtLoop loop3("DetermineRndmPed");
@@ -442,5 +457,5 @@
     plist4.AddToList(&drscalib300);
     plist4.AddToList(&badpixels);
-    plist4.AddToList(&timecam);
+    plist4.AddToList(&drscalibtime);
 
     MEvtLoop loop4("DetermineExtractedPed");
@@ -510,5 +525,5 @@
     plist5.AddToList(&drscalib300);
     plist5.AddToList(&badpixels);
-    plist5.AddToList(&timecam);
+    plist5.AddToList(&drscalibtime);
 
     MEvtLoop loop5("CalibratingData");
Index: /branches/MarsGapdTimeJitter/fact/analysis/callisto_data.C
===================================================================
--- /branches/MarsGapdTimeJitter/fact/analysis/callisto_data.C	(revision 18281)
+++ /branches/MarsGapdTimeJitter/fact/analysis/callisto_data.C	(revision 18282)
@@ -90,17 +90,21 @@
     // -------------------------------------------------------
 
-    TFile file(drstime);
-    if (file.IsZombie())
+    MDrsCalibrationTime timecam;
+    if (!timecam.ReadFits(drstime))
     {
-        gLog << err << "ERROR - Could not open " << drstime << endl;
+        gLog << err << "ERROR - Could not get MDrsCalibrationTime from " << drstime << endl;
         return 21;
     }
 
-    MDrsCalibrationTime *timecam = 0;
-    file.GetObject("MDrsCalibrationTime", timecam);
-    if (!timecam)
+    if (delays)
     {
-        gLog << err << "ERROR - Could not get MDrsCalibrationTime from " << drstime << endl;
-        return 22;
+        TGraph g(delays);
+        if (g.GetN()!=1440)
+        {
+            gLog << err << "Error reading file " << delays << endl;
+            return 22;
+        }
+
+        timecam.SetDelays(g);
     }
 
@@ -113,6 +117,15 @@
     // -------------------------------------------------------
 
-    //if (use_delays)
-    //    timecam.SetDelays(*evt1h.GetHist());
+    if (delays)
+    {
+        TGraph g(delays);
+        if (g.GetN()!=1440)
+        {
+            gLog << err << "Error reading file " << delays << endl;
+            return 41;
+        }
+
+        timecam.SetDelays(g);
+    }
 
     // -------------------------------------------------------
@@ -194,5 +207,5 @@
     plist5.AddToList(&drscalib300);
     plist5.AddToList(&badpixels);
-    plist5.AddToList(timecam);
+    plist5.AddToList(&timecam);
 
     MEvtLoop loop5("CalibratingData");
Index: /branches/MarsGapdTimeJitter/fact/plots/plotratescan.C
===================================================================
--- /branches/MarsGapdTimeJitter/fact/plots/plotratescan.C	(revision 18281)
+++ /branches/MarsGapdTimeJitter/fact/plots/plotratescan.C	(revision 18282)
@@ -129,5 +129,5 @@
 {
     TString query;
-    query += "SELECT fTimeBegin, fTimeEnd, fVoltageIsOn, fOvervoltage, fCurrentMedMean, fNight ";
+    query += "SELECT fTimeBegin, fTimeEnd, fVoltageIsOn, fOvervoltage, fCurrentMedMean, fNight, fAzMin, fAzMax, fZdMin, fZdMax ";
     query += "FROM Ratescan WHERE fRatescanID=";
     query += search_id;
@@ -149,4 +149,8 @@
     const char *time_end = (*row)[1];
     const char *night    = (*row)[5];
+    const char *az_beg = (*row)[6];
+    const char *az_end = (*row)[7];
+    const char *zd_beg = (*row)[8];
+    const char *zd_end = (*row)[9];
 
     int   voltage_on  = (*row)[2] ? atoi((*row)[2]) :   -1;
@@ -167,9 +171,12 @@
     leg.SetBorderSize(1);
     leg.SetFillColor(kWhite);
-    leg.AddText("Ratescan");
-    leg.AddText("");
-    leg.AddText(Form("Begin    %s", time_beg));
-    leg.AddText(Form("End       %s", time_end));
-    leg.AddText("");
+    leg.SetTextAlign(12);
+    leg.AddText(Form("Ratescan %d ", search_id));
+    //leg.AddText("");
+    leg.AddText(Form("Begin       %s", time_beg));
+    leg.AddText(Form("End          %s", time_end));
+    leg.AddText(Form("Az            %s#circ to %s#circ", az_beg, az_end));
+    leg.AddText(Form("Zd             %s#circ to %s#circ", zd_beg, zd_end));
+    //leg.AddText("");
     if (voltage_on==0)
         leg.AddText("Voltage off");
@@ -179,5 +186,5 @@
             leg.AddText(Form("Current     <I_{med}>  =  %.1f #muA", current));
         if (overvoltage>-70)
-            leg.AddText(Form("Voltage         #DeltaU  =  %+.2f V", overvoltage));
+            leg.AddText(Form("Voltage   #DeltaU  =  %+.2f V", overvoltage));
     }
 
@@ -209,4 +216,8 @@
     g.DrawClone("PL");
 
+    TGraph gr("good_ratescan_edit.txt", "%lg %lg");
+    gr.SetLineColor(12);
+    gr.DrawClone("L");
+
     c->Write();
 
@@ -216,7 +227,8 @@
     name += time_beg;
 
-    c->SaveAs(name+".pdf");
-    c->SaveAs(name+".eps");
-    c->SaveAs(name+".png");
+    //c->SaveAs(name+".pdf");
+    //c->SaveAs(name+".eps");
+    //c->SaveAs("/loc_data/analysis/"+name+".png");
+    c->SaveAs(Form("/loc_data/analysis/ratescans/%04d/%02d/%02d/%06d_%d.png", atoi(night)/10000, (atoi(night)/100)%100, atoi(night)%100, atoi(night), search_id));
 
     delete c;
@@ -305,7 +317,5 @@
 
     TString oname = Form("%06d-ratescan.root", night);
-
-    cout << "   " << oname << '\n' << endl;
-
+    //cout << "   " << oname << '\n' << endl;
     TFile rootfile(oname.Data(), "recreate");
 
Index: /branches/MarsGapdTimeJitter/fact/plots/quality.C
===================================================================
--- /branches/MarsGapdTimeJitter/fact/plots/quality.C	(revision 18281)
+++ /branches/MarsGapdTimeJitter/fact/plots/quality.C	(revision 18282)
@@ -95,8 +95,35 @@
     Double_t jd = time + 40587 + 2400000.5;
 
+    // Sun properties  	 	 
+    Nova::EquPosn  sun  = Nova::GetSolarEquCoords(jd);  	 	 
+    Nova::ZdAzPosn hrzs = Nova::GetHrzFromEqu(sun, jd);  	 	 
+
     // Get source position
     Nova::EquPosn pos = FindPointing(time);
 
-    return FACT::PredictI(jd, pos);
+
+    // Moon properties 
+    Nova::EquPosn moon = Nova::GetLunarEquCoords(jd, 0.01); 
+    Nova::HrzPosn hrzm = Nova::GetHrzFromEqu(moon, jd); 
+    double        disk = Nova::GetLunarDisk(jd); 
+
+    // Derived moon properties 
+    double angle = Nova::GetAngularSeparation(moon, pos); 
+    double edist = Nova::GetLunarEarthDist(jd)/384400; 
+
+    // Current prediction 
+    double sin_malt  = hrzm.alt<0 ? 0 : sin(hrzm.alt*TMath::DegToRad()); 
+    double cos_mdist = cos(angle*TMath::DegToRad()); 
+    double sin_szd   = sin(hrzs.zd*TMath::DegToRad()); 
+
+    double c0 = pow(disk,      2.63); 
+    double c1 = pow(sin_malt,  0.60); 
+    double c2 = pow(edist,    -2.00); 
+    double c3 = exp(0.67*cos_mdist*cos_mdist*cos_mdist*cos_mdist); 
+    double c4 = exp(-97.8+105.8*sin_szd*sin_szd); 
+
+    double cur = 6.2 + 95.7*c0*c1*c2*c3 + c4; 
+
+    return cur; 
 }
 
@@ -340,4 +367,252 @@
 }
 
+Int_t PlotSqm(TArrayD **vec, TString fname)
+{
+    fname += ".SQM_CONTROL_DATA.fits";
+
+    fits file(fname.Data());
+    if (!file)
+    {
+        cerr << fname << ": " << gSystem->GetError() << endl;
+        return -2;
+    }
+
+    //cout << fname << endl;
+
+    Double_t time;
+    Float_t mag; // magnitude
+
+    if (!file.SetPtrAddress("Time",  &time))
+        return -1;
+    if (!file.SetPtrAddress("Mag",  &mag))
+        return -1;
+
+    //const int marker_style = kFullDotMedium;
+    const int marker_style = kDot;
+
+    TGraph g1;
+    g1.SetName("SQM");
+
+
+    bool found_first_time = false;
+    while (file.GetNextRow())
+        if (Contains(vec, time))
+        {
+            g1.SetPoint(g1.GetN(), time*24*3600, mag);
+        }
+
+
+    g1.SetMinimum(19.0);
+    g1.SetMaximum(21.5);
+    g1.SetMarkerColor(kBlack);
+    g1.SetMarkerStyle(marker_style);
+    g1.GetXaxis()->SetTimeDisplay(true);
+    g1.GetXaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
+    g1.GetXaxis()->SetLabelSize(0.12);
+    g1.GetYaxis()->SetLabelSize(0.1);
+    g1.GetYaxis()->SetTitle("SQM [mag]");
+    g1.GetYaxis()->SetTitleOffset(0.2);
+    g1.GetYaxis()->SetTitleSize(0.1);
+    g1.DrawClone("AP");
+
+    return 0;
+}
+
+Int_t PlotSqmLinear(TArrayD **vec, TString fname)
+{
+    fname += ".SQM_CONTROL_DATA.fits";
+
+    fits file(fname.Data());
+    if (!file)
+    {
+        cerr << fname << ": " << gSystem->GetError() << endl;
+        return -2;
+    }
+
+    //cout << fname << endl;
+
+    Double_t time;
+    Float_t mag; // magnitude
+
+    if (!file.SetPtrAddress("Time",  &time))
+        return -1;
+    if (!file.SetPtrAddress("Mag",  &mag))
+        return -1;
+
+    //const int marker_style = kFullDotMedium;
+    const int marker_style = kDot;
+
+    TGraph g1;
+    g1.SetName("SQM");
+
+
+    bool found_first_time = false;
+    while (file.GetNextRow())
+        if (Contains(vec, time))
+        {
+            Double_t mag_double = 4.4 * pow(10, 20) * pow( 10, mag*(-0.4));
+            g1.SetPoint(g1.GetN(), time*24*3600, mag_double);
+        }
+
+
+    g1.SetMinimum(1.e12);
+    g1.SetMaximum(5.e12);
+    g1.SetMarkerColor(kBlack);
+    g1.SetMarkerStyle(marker_style);
+    g1.GetXaxis()->SetTimeDisplay(true);
+    g1.GetXaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
+    g1.GetXaxis()->SetLabelSize(0.12);
+    g1.GetYaxis()->SetLabelSize(0.1);
+    g1.GetYaxis()->SetTitle("SQM lin [phot./(s sr m^2)]");
+    g1.GetYaxis()->SetTitleOffset(0.2);
+    g1.GetYaxis()->SetTitleSize(0.1);
+    g1.DrawClone("AP");
+
+    return 0;
+}
+
+Int_t PlotHumidity(TArrayD **vec, TString fname)
+{
+    fname += ".FSC_CONTROL_HUMIDITY.fits";
+
+    fits file(fname.Data());
+    if (!file)
+    {
+        cerr << fname << ": " << gSystem->GetError() << endl;
+        return -2;
+    }
+
+    //cout << fname << endl;
+
+    Double_t time;
+    Float_t H[4];
+
+    if (!file.SetPtrAddress("Time",  &time))
+        return -1;
+    if (!file.SetPtrAddress("H",  H))
+        return -1;
+
+    //const int marker_style = kFullDotMedium;
+    const int marker_style = kDot;
+
+    TGraph g1;
+    TGraph g2;
+    TGraph g3;
+    TGraph g4;
+    //TGraph g5;
+    g1.SetName("H0");
+    g2.SetName("H1");
+    g3.SetName("H2");
+    g4.SetName("H3");
+    //g5.SetName("PFmini");
+
+
+    Double_t first_time, last_time;
+    bool found_first_time = false;
+    while (file.GetNextRow())
+        if (Contains(vec, time))
+        {
+            if (!found_first_time){
+              first_time = time*24*3600;
+              found_first_time = true;
+            }            
+            g1.SetPoint(g1.GetN(), time*24*3600, H[0]);
+            g2.SetPoint(g2.GetN(), time*24*3600, H[1]);
+            g3.SetPoint(g3.GetN(), time*24*3600, H[2]);
+            g4.SetPoint(g4.GetN(), time*24*3600, H[3]);
+            //g5.SetPoint(g5.GetN(), time*24*3600, I[319]);
+            last_time = time*24*3600;
+        }
+
+
+    g1.SetMinimum(10);
+    g1.SetMaximum(80);
+    g1.SetMarkerColor(kAzure);
+    g1.SetMarkerStyle(marker_style);
+    g1.GetXaxis()->SetTimeDisplay(true);
+    g1.GetXaxis()->SetTimeFormat("%H:%M %F1995-01-01 00:00:00 GMT");
+    g1.GetXaxis()->SetLabelSize(0.12);
+    g1.GetYaxis()->SetLabelSize(0.1);
+    g1.GetYaxis()->SetTitle("HUMITIDY");
+    g1.GetYaxis()->SetTitleOffset(0.2);
+    g1.GetYaxis()->SetTitleSize(0.1);
+    g1.DrawClone("AP");
+
+    g2.SetMarkerColor(kAzure+1);
+    g2.SetMarkerStyle(marker_style);
+    g2.DrawClone("P");
+    
+    g3.SetMarkerColor(kAzure+3);
+    g3.SetMarkerStyle(marker_style);
+    g3.DrawClone("P");
+    
+    g4.SetMarkerColor(kAzure+6);
+    g4.SetMarkerStyle(marker_style);
+    g4.DrawClone("P");
+    
+    //g5.SetMarkerColor(kAzure+1);
+    //g5.SetMarkerStyle(kFullDotMedium);
+    //g5.DrawClone("P");
+    
+    g1.DrawClone("P");
+
+    TLine l1(first_time-600, 40, last_time+600, 40);
+    l1.SetLineColor(kOrange);
+    l1.DrawClone();
+    TText t1(first_time-600, 41, "Please, note in logbook");
+    t1.SetTextSize(0.1);
+    t1.DrawClone();
+
+    
+    TLine l2(first_time-600, 55, last_time+600, 55);
+    l2.SetLineColor(kRed);
+    l2.DrawClone();
+    TText t2(first_time-600, 56, "Please, report to fact-online");
+    t2.SetTextSize(0.1);
+    t2.DrawClone();
+
+
+    return 0;
+}
+
+Int_t PlotHumidity2(TArrayD **vec, TString fname)
+{
+    fname += ".PFMINI_CONTROL_DATA.fits";
+
+    fits file(fname.Data());
+    if (!file)
+    {
+        cerr << fname << ": " << gSystem->GetError() << endl;
+        return -2;
+    }
+
+    //cout << fname << endl;
+
+    Double_t time;
+    Float_t H;
+
+    if (!file.SetPtrAddress("Time",  &time))
+        return -1;
+    if (!file.SetPtrAddress("Humidity", &H))
+        return -1;
+
+    const int marker_style = kFullDotMedium;
+    //const int marker_style = kDot;
+
+    TGraph g1;
+    g1.SetName("PFmini");
+
+
+    while (file.GetNextRow())
+        if (Contains(vec, time))
+        {
+            g1.SetPoint(g1.GetN(), time*24*3600, H);
+        }
+    
+    g1.SetMarkerStyle(marker_style);
+    g1.SetMarkerColor(kGreen);
+    g1.DrawClone("P");
+    return 0;
+}
 
 Int_t PlotPointing(TArrayD **vec, TString fname)
@@ -420,5 +695,5 @@
     g.GetXaxis()->SetLabelSize(0.1);
     g.GetYaxis()->SetLabelSize(0.1);
-    g.GetYaxis()->SetTitle("TEMP");
+    g.GetYaxis()->SetTitle("TEMPERATURE");
     g.GetYaxis()->SetTitleOffset(0.2);
     g.GetYaxis()->SetTitleSize(0.1);
@@ -542,6 +817,7 @@
     if (!file.SetPtrAddress("Time",  &time))
         return -1;
-    if (!file.SetPtrAddress("Data1", temp) &&
-        !file.SetPtrAddress("temp", temp))
+//    if (!file.SetPtrAddress("Data1", temp) &&
+//        !file.SetPtrAddress("temp", temp))
+    if (!file.SetPtrAddress("temp", temp))
         return -1;
 
@@ -669,6 +945,14 @@
     }
 
-    TCanvas *c = new TCanvas("quality", Form("Quality %04d/%02d/%02d", y, m, d), 1280, 960);
-    c->Divide(1, 6, 1e-5, 1e-5);
+    //check if the sqm was already installed on the telescope                                                                                                       
+    TCanvas *c = NULL;
+    TString datestring = Form("%04d%02d%02d", y, m, d);
+    if( datestring.Atoi() > 20140723 ) {
+      TCanvas *c = new TCanvas("quality", Form("Quality %04d/%02d/%02d", y, m, d), 1280, 1280);
+      c->Divide(1, 8, 1e-5, 1e-5);
+    }else{
+      TCanvas *c = new TCanvas("quality", Form("Quality %04d/%02d/%02d", y, m, d), 1280, 1120);
+      c->Divide(1, 7, 1e-5, 1e-5);
+    }
 
     gROOT->SetSelectedPad(0);
@@ -716,4 +1000,5 @@
     gPad->SetRightMargin(0.001);
     gPad->SetLeftMargin(0.04);
+    gPad->SetBottomMargin(0);
     cout << PlotTemperature1(runs, fname) << endl;
     cout << PlotTemperature2(runs, fname) << endl;
@@ -721,4 +1006,45 @@
     cout << PlotTemperature4(runs, fname) << endl;
 
+    gROOT->SetSelectedPad(0);
+    c->cd(7);
+    gPad->SetGrid();
+    gPad->SetTopMargin(0);
+    gPad->SetBottomMargin(0);
+    gPad->SetRightMargin(0.001);
+    gPad->SetLeftMargin(0.04);
+    cout << PlotHumidity(runs, fname) << endl;
+    cout << PlotHumidity2(runs, fname) << endl;
+
+    //check if the sqm was already installed
+    if( datestring.Atoi() > 20140723 ) {
+      gROOT->SetSelectedPad(0);
+      c->cd(7);
+      gPad->SetGrid();
+      gPad->SetTopMargin(0);
+      gPad->SetBottomMargin(0);
+      gPad->SetRightMargin(0.001);
+      gPad->SetLeftMargin(0.04);
+      cout << PlotHumidity(runs, fname) << endl;
+      cout << PlotHumidity2(runs, fname) << endl;
+
+      gROOT->SetSelectedPad(0);
+      c->cd(8);
+      gPad->SetGrid();
+      gPad->SetTopMargin(0);
+      gPad->SetRightMargin(0.001);
+      gPad->SetLeftMargin(0.04);
+      cout << PlotSqm(runs, fname) << endl;
+    }else{
+
+      gROOT->SetSelectedPad(0);
+      c->cd(7);
+      gPad->SetGrid();
+      gPad->SetTopMargin(0);
+      gPad->SetRightMargin(0.001);
+      gPad->SetLeftMargin(0.04);
+      cout << PlotHumidity(runs, fname) << endl;
+      cout << PlotHumidity2(runs, fname) << endl;
+    }
+
     c->SaveAs(Form("%s/%04d%02d%02d.png", outpath, y, m, d));
 
Index: /branches/MarsGapdTimeJitter/fact/processing/DataFromQLA.C
===================================================================
--- /branches/MarsGapdTimeJitter/fact/processing/DataFromQLA.C	(revision 18282)
+++ /branches/MarsGapdTimeJitter/fact/processing/DataFromQLA.C	(revision 18282)
@@ -0,0 +1,222 @@
+#include <iostream>
+#include <iomanip>
+#include <fstream>
+
+#include <TFile.h>
+#include <TSQLResult.h>
+#include <TSQLRow.h>
+#include <TPRegexp.h>
+
+#include "MSQLMagic.h"
+#include "MTime.h"
+#include "MMath.h"
+#include "MDirIter.h"
+
+using namespace std;
+
+void PrintRemarks(ofstream &fout, TString sourcename, TString firstnight, TString lastnight)
+{
+    MTime now(-1);
+
+    fout << "# " << endl;
+    fout << "# Please cite the FACT design paper and the QLA webpage when using these data." << endl;
+    fout << "#   FACT design paper: H. Anderhub et al. JINST 8 (2013) P6008 " << endl;
+    fout << "#                http://iopscience.iop.org/1748-0221/8/06/P06008 " << endl;
+    fout << "#   QLA webpage: http://www.fact-project.org/monitoring" << endl;
+    fout << "# If you intent to use the data, please let us know for reference. " << endl;
+    fout << "# " << endl;
+    fout << "# Remarks:" << endl;
+    fout << "#  * These are the results of a fast quick look analyis " << endl;
+    fout << "#    on site, i.e. they are preliminary. " << endl;
+    fout << "#  * The quick look analysis includes all data, " << endl;
+    fout << "#    i.e. no data selection done." << endl;
+    fout << "#  * The given values are not fluxes but excess rates " << endl;
+    fout << "#    (number of excess events per effective ontime), " << endl;
+    fout << "#    i.e. there is a dependence on trigger threshold and " << endl;
+    fout << "#    zenith distance of the observation (with the current " << endl;
+    fout << "#    analysis for zenith distance > 40 degree and trigger " << endl;
+    fout << "#    threshold > 500 DAC counts)." << endl;
+//    fout << "#  * The data are provided with 20 min binning and nightly binning." << endl;
+    fout << "#  * Nights with less than 20 minutes of data are neglected. " << endl;
+    fout << "#  * The QLA results are not reprocessed when a new software " << endl;
+    fout << "#    version is introduced. " << endl;
+    fout << "#  * In case, you need further details about the data or a" << endl;
+    fout << "#    different binning, please do not hesitate to contact us." << endl;
+    fout << "#  * The QLA contains all data since 12.12.2012. " << endl;
+    fout << "#    For older data, please contact us. " << endl;
+    fout << "# " << endl;
+    fout << "# Contact: Daniela Dorner dorner@astro.uni-wuerzburg.de " << endl;
+    fout << "# " << endl;
+    fout << "# This file was created at " << now.GetString() << endl;
+    fout << "# Source: " << sourcename << endl;
+    fout << "# Timerange: " << firstnight << " - " << lastnight << endl;
+    fout << "# " << endl;
+    fout << "# start(mjd) stop(mjd) excess-rate(evts/h) error-excess-rate " << endl;
+
+    return;
+}
+
+int DataFromQLA(Int_t sourcekey=1, Int_t nightmin=2011115, Int_t nightmax=20161231)
+{
+    MSQLServer serv("sql.rc");
+    if (!serv.IsConnected())
+    {
+        cout << "ERROR - Connection to database failed." << endl;
+        return 0;
+    }
+    Bool_t dch=kFALSE;
+
+    TString query=Form("SELECT fSourceName FROM Source WHERE fSourceKey=%d", sourcekey);
+    TSQLResult *res1 = serv.Query(query);
+    if (!res1)
+        return 1;
+    TSQLRow *row1=res1->Next();
+    TString sourcename=(*row1)[0];
+    delete res1;
+    sourcename.ReplaceAll(" ", "_");
+
+    // datacheck
+    TString datacheck=" ";
+    //remove data with wrong settings
+    datacheck+=" AND fNight>20120420 AND NOT fNight IN (20120406,20120410,20120503) AND";//data with different bias voltage
+    datacheck+=" NOT fNight BETWEEN 20121206 AND 20130110"; // broken bias channel
+    //datacheck+=" AND NOT (fNight=20120608 AND fRunID=65) "; // something went wrong with tracking?
+    // 24.6. new coefficients
+    TString zdparam=" pow(0.753833 * cos(Radians(fZenithDistanceMean)), 7.647435) * exp(-5.753686*pow(Radians(fZenithDistanceMean),2.089609))";
+    TString thparam=" pow((if(isnull(fThresholdMinSet),fThresholdMedian,fThresholdMinSet)-329.4203),2) * (-0.0000002044803) ";
+    TString param=" (fNumEvtsAfterBgCuts/5-fNumSigEvts)/fOnTimeAfterCuts - "+zdparam+" - "+thparam+" ";
+    datacheck+=" AND -0.085 < ("+param+") ";
+    datacheck+=" AND 0.25 > ("+param+") ";
+
+    TString select =" SELECT Min(fNight), Max(fNight), Sum(fOnTimeAfterCuts) as bla ";
+    TString fromjoinwhere=" FROM AnalysisResultsRunLP ";
+    fromjoinwhere+=" LEFT JOIN RunInfo USING(fNight, fRunID) ";
+    fromjoinwhere+=Form(" WHERE fSourceKey=%d", sourcekey);
+    fromjoinwhere+=Form(" AND fNight BETWEEN %d AND %d ", nightmin, nightmax);
+    fromjoinwhere+=" AND fOnTimeAfterCuts < 1000 "; //exclude runs with wrong/too high ontime
+    fromjoinwhere+=" AND fOnTimeAfterCuts > 10 "; //exclude runs with wrong/too small ontime
+    fromjoinwhere+=" AND NOT ISNULL(fNumExcEvts) ";// only where excess was extracted
+    if (dch)
+        fromjoinwhere+=datacheck;
+    query=select+fromjoinwhere;
+    query+=" GROUP BY fSourceKey ";
+    query+=" HAVING bla>20*60 ";
+    cout << "Q: " << query << endl;
+    TSQLResult *res2 = serv.Query(query);
+    if (!res2)
+        return 1;
+    TSQLRow *row2=res2->Next();
+    TString firstnight=(*row2)[0];
+    TString lastnight=(*row2)[1];
+    delete res2;
+
+    TString filename_nightly="FACT_QuickLookAnalysisResults_NightlyBinning_"+sourcename+".txt";
+    TString filename_min="FACT_QuickLookAnalysisResults_20MinuteBinning_"+sourcename+".txt";
+
+    ofstream nightly(filename_nightly);
+    ofstream min(filename_min);
+    if (!nightly)
+    {
+        cout << "ERROR - cannot write " << filename_nightly << endl;
+        return 2;
+    }
+    if (!min)
+    {
+        cout << "ERROR - cannot write " << filename_min << endl;
+        return 2;
+    }
+    PrintRemarks(nightly, sourcename, firstnight, lastnight);
+    PrintRemarks(min, sourcename, firstnight, lastnight);
+
+    // query data from AnalysisResultsRunLP
+    select =" SELECT Sum(fOnTimeAfterCuts) as bla, Sum(fNumExcEvts), Sum(fNumBgEvts), Sum(fNumSigEvts), ";
+    select+=" Min(fRunStart), Max(fRunStop), fNight, fRunID ";
+    query=select+fromjoinwhere;
+    query+=" GROUP BY fNight ";
+    query+=" HAVING bla>20*60 ";
+    query+=" ORDER BY fNight ";
+    //cout << "Q: " << query << endl;
+
+    //variables for calculations and graphs
+    TString excevts, bgevts, sigevts, ontime, night;
+    Float_t excevtssum=0;
+    Float_t bgevtssum=0;
+    Float_t sigevtssum=0;
+    Float_t ontimesum=0;
+    Float_t excerr=0;
+    MTime start;
+    MTime stop;
+    Double_t mjdstart=0;
+    Double_t mjdstop=0;
+    //Double_t mjd=0;
+    //Double_t mjddiff=0;
+    Int_t counter=0;
+
+    TSQLResult *res3 = serv.Query(query);
+    if (!res3)
+        return 1;
+    TSQLRow *row3=0;
+    while ((row3=res3->Next()))
+    {
+        ontime=(*row3)[0];
+        excevts=(*row3)[1];
+        bgevts=(*row3)[2];
+        sigevts=(*row3)[3];
+        start.SetSqlDateTime((*row3)[4]);
+        stop.SetSqlDateTime((*row3)[5]);
+        night=(*row3)[6];
+
+        mjdstart = start.GetMjd();
+        mjdstop = stop.GetMjd();
+        //mjd = mjdstart+(mjdstop-mjdstart)/2.;
+
+        //significance = MMath::SignificanceLiMaSigned(sigevts.Atof(), bgevts.Atof()*5, 0.2);
+        excerr = MMath::ErrorExc(sigevts.Atof(), bgevts.Atof()*5, 0.2)/ontime.Atof()*3600.;
+        nightly.precision(18);
+        //fout << (*row3)[6] << ": " << start.GetMjd() << " " << stop.GetMjd() << " " << excevts.Atof()/ontime.Atof() << " " << excerr << endl;
+        nightly << start.GetMjd() << " " << stop.GetMjd() << " " << excevts.Atof()/ontime.Atof()*3600 << " " << excerr << endl;
+        query="SELECT fOnTimeAfterCuts, fNumExcEvts, fNumBgEvts, fNumSigEvts, ";
+        query+=" fRunStart, fRunStop "+fromjoinwhere;
+        query+=" AND fNight="+night;
+        //cout << "Q: " << query << endl;
+        TSQLResult *res4 = serv.Query(query);
+        if (!res4)
+            return 1;
+        TSQLRow *row4=0;
+        counter=0;
+        while ((row4=res4->Next()))
+        {
+            ontime=(*row4)[0];
+            excevts=(*row4)[1];
+            bgevts=(*row4)[2];
+            sigevts=(*row4)[3];
+            if(counter==0)
+                start.SetSqlDateTime((*row4)[4]);
+
+            if (ontimesum+ontime.Atoi()>20*60)
+            {
+                excerr = MMath::ErrorExc(sigevtssum, bgevtssum*5, 0.2)/ontimesum*3600.;
+                min.precision(18);
+                min << start.GetMjd() << " " << stop.GetMjd() << " " << excevtssum/ontimesum*3600 << " " << excerr << endl;
+                start.SetSqlDateTime((*row4)[4]);
+                ontimesum=0;
+                excevtssum=0;
+                bgevtssum=0;
+                sigevtssum=0;
+            }
+            counter++;
+            stop.SetSqlDateTime((*row4)[5]);
+            ontimesum+=ontime.Atoi();
+            excevtssum+=excevts.Atof();
+            bgevtssum+=bgevts.Atof();
+            sigevtssum+=sigevts.Atof();
+        }
+    }
+
+    delete res3;
+    return 0;
+
+}
+
+
+
Index: /branches/MarsGapdTimeJitter/fact/processing/buildseqentries.C
===================================================================
--- /branches/MarsGapdTimeJitter/fact/processing/buildseqentries.C	(revision 18281)
+++ /branches/MarsGapdTimeJitter/fact/processing/buildseqentries.C	(revision 18282)
@@ -584,5 +584,5 @@
 
         TString query;
-        query  = "SELECT fRunID FROM runinfo WHERE fExcludedFDAKEY=1 AND ";
+        query  = "SELECT fRunID FROM RunInfo WHERE fExcludedFDAKEY=1 AND ";
         query += cond;
         query += " AND fRunTypeKEY=4 AND fRunID BETWEEN ";
@@ -599,5 +599,5 @@
 
             // Get DRS file with pedestal (roi<1024)
-            query  = "SELECT MAX(fRunID) FROM runinfo WHERE ";
+            query  = "SELECT MAX(fRunID) FROM RunInfo WHERE ";
             query += cond;
             query += " AND fHasDrsFile=1 AND (fDrsStep IS NULL OR fDrsStep=2) AND fRunTypeKEY=2";
Index: /branches/MarsGapdTimeJitter/fact/processing/drstemp.C
===================================================================
--- /branches/MarsGapdTimeJitter/fact/processing/drstemp.C	(revision 18281)
+++ /branches/MarsGapdTimeJitter/fact/processing/drstemp.C	(revision 18282)
@@ -163,9 +163,9 @@
 
     float temp[160];
-    if (file.SetPtrAddress("temp", temp, 82))
-    {
-        drstemp82(file, beg, end);
-        return;
-    }
+//    if (file.SetPtrAddress("temp", temp, 82))
+//    {
+//        drstemp82(file, beg, end);
+//        return;
+//    }
 
     file.SetPtrAddress("temp", temp, 160);
Index: /branches/MarsGapdTimeJitter/fact/processing/fillratescan.C
===================================================================
--- /branches/MarsGapdTimeJitter/fact/processing/fillratescan.C	(revision 18281)
+++ /branches/MarsGapdTimeJitter/fact/processing/fillratescan.C	(revision 18282)
@@ -48,5 +48,8 @@
 Float_t GetOffset(TString fname, Double_t beg, Double_t end)
 {
-    fname.ReplaceAll("RATE_SCAN_DATA", "FEEDBACK_DEVIATION");
+    if (end < 15937)
+        fname.ReplaceAll("RATE_SCAN_DATA", "FEEDBACK_DEVIATION");
+    else
+        fname.ReplaceAll("RATE_SCAN_DATA", "FEEDBACK_CALIBRATED_CURRENTS");
 
     fits file(fname.Data());
@@ -61,6 +64,14 @@
         return -100;
 
-    if (!file.SetPtrAddress("DeltaUser", &delta))
-        return -100;
+    if (end < 15937)
+    {
+        if (!file.SetPtrAddress("DeltaUser", &delta))
+            return -100;
+    }
+    else
+    {
+        if (!file.SetPtrAddress("U_nom", &delta))
+            return -100;
+    }
 
     //cout << "Search for: " << beg-15773 << " " << end-15773 << endl;
@@ -80,8 +91,10 @@
 Float_t GetCurrent(TString fname, Double_t beg, Double_t end)
 {
-    fname.ReplaceAll("RATE_SCAN_DATA", "CALIBRATED_CURRENTS");
-    fname = gSystem->BaseName(fname.Data());
-
-    fname.Prepend("/scratch_nfs/calibrated_currents/");
+    fname.ReplaceAll("RATE_SCAN_DATA", "FEEDBACK_CALIBRATED_CURRENTS");
+
+    //the next two lines are needed for ISDC and data before 11.3.2013
+    //fname.ReplaceAll("RATE_SCAN_DATA", "CALIBRATED_CURRENTS");
+    //fname = gSystem->BaseName(fname.Data());
+    //fname.Prepend("/scratch_nfs/calibrated_currents/");
 
     fits file(fname.Data());
@@ -326,5 +339,5 @@
         !file.SetPtrAddress(string(old ? "Data3" : "RelOnTime"), &ontime))
         return -1;
-    */
+        */
     Double_t  *ptime   = file.SetPtrAddress("Time");
     ULong64_t *pid     = file.SetPtrAddress(old ? "Data0" : "Id");
Index: /branches/MarsGapdTimeJitter/mbase/MStatusDisplay.cc
===================================================================
--- /branches/MarsGapdTimeJitter/mbase/MStatusDisplay.cc	(revision 18281)
+++ /branches/MarsGapdTimeJitter/mbase/MStatusDisplay.cc	(revision 18282)
@@ -2622,5 +2622,5 @@
 
     // FIXME: Use mkstemp instead
-    if (!mktemp(const_cast<char*>(tmp.Data())))
+    if (!mkstemp(const_cast<char*>(tmp.Data())))
     {
         *fLog << err << "ERROR - MStatusDisplay::UpdatePSHeader: mktemp failed." << endl;
Index: /branches/MarsGapdTimeJitter/mcore/DrsCalib.h
===================================================================
--- /branches/MarsGapdTimeJitter/mcore/DrsCalib.h	(revision 18281)
+++ /branches/MarsGapdTimeJitter/mcore/DrsCalib.h	(revision 18282)
@@ -964,4 +964,13 @@
 
         fStat.resize(samples*channels);
+    }
+
+    void Reset()
+    {
+        for (auto it=fStat.begin(); it!=fStat.end(); it++)
+        {
+            it->first = 0;
+            it->second = 0;
+        }
     }
 
@@ -1144,5 +1153,5 @@
                 const double valw = it->second;
 
-                it->first = sumv>0 ? n*(1-s*sumw/sumv) : 0;
+                it->first  = sumv>0 ? n*(1-s*sumw/sumv) : 0;
 
                 sumv += valv;
@@ -1163,5 +1172,5 @@
                 sumw += valw;
 
-                it->first = sumv>0 ? n*(s*sumw/sumv-1) : 0;
+                it->first  = sumv>0 ? n*(s*sumw/sumv-1) : 0;
             }
 
@@ -1197,4 +1206,101 @@
         return pos-Offset(ch, pos);
     }
+
+    /*
+    // See MDrsCalibrationTime
+    std::string ReadFitsImp(const std::string &str)
+    {
+        fits file(str);
+        if (!file)
+        {
+            std::ostringstream msg;
+            msg << "Could not open file '" << str << "': " << strerror(errno);
+            return msg.str();
+        }
+
+        if (file.GetStr("TELESCOP")!="FACT")
+        {
+            std::ostringstream msg;
+            msg << "Reading '" << str << "' failed: Not a valid FACT file (TELESCOP not FACT in header)";
+            return msg.str();
+        }
+
+        if (file.GetNumRows()!=1)
+        {
+            std::ostringstream msg;
+            msg << "Reading '" << str << "' failed: Number of rows in table is not 1.";
+            return msg.str();
+        }
+
+        fNumSamples  = file.GetUInt("NROI");
+        fNumChannels = file.GetUInt("NCH");
+        fNumEntries  = file.GetUInt("NBTIME");
+
+        fStat.resize(fNumSamples*fNumChannels);
+
+        double *f = reinterpret_cast<double*>(file.SetPtrAddress("CellWidthMean"));
+        double *s = reinterpret_cast<double*>(file.SetPtrAddress("CellWidthRms"));
+
+        if (!file.GetNextRow())
+        {
+            std::ostringstream msg;
+            msg << "Reading data from " << str << " failed.";
+            return msg.str();
+        }
+
+        for (uint32_t i=0; i<fNumSamples*fNumChannels; i++)
+        {
+            fStat[i].first  = f[i];
+            fStat[i].second = s[i];
+        }
+
+        return std::string();
+    }
+
+    std::string WriteFitsImp(const std::string &filename, uint32_t night=0) const
+    {
+        ofits file(filename.c_str());
+        if (!file)
+        {
+            std::ostringstream msg;
+            msg << "Could not open file '" << filename << "': " << strerror(errno);
+            return msg.str();
+        }
+
+        file.SetDefaultKeys();
+        file.AddColumnDouble(fStat.size(), "CellWidthMean", "ratio", "Relative cell width mean");
+        file.AddColumnDouble(fStat.size(), "CellWidthRms",  "ratio", "Relative cell width rms");
+
+        file.SetInt("ADCRANGE", 2000,    "Dynamic range of the ADC in mV");
+        file.SetInt("DACRANGE", 2500,    "Dynamic range of the DAC in mV");
+        file.SetInt("ADC",      12,      "Resolution of ADC in bits");
+        file.SetInt("DAC",      16,      "Resolution of DAC in bits");
+        file.SetInt("NPIX",     1440,    "Number of channels in the camera");
+        file.SetInt("NTM",      0,       "Number of time marker channels");
+        file.SetInt("NROI",     fNumSamples,  "Region of interest");
+        file.SetInt("NCH",      fNumChannels, "Number of chips");
+        file.SetInt("NBTIME",   fNumEntries,  "Num of entries for time calibration");
+
+        file.WriteTableHeader("DrsCellTimes");
+        if (night>0)
+            file.SetInt("NIGHT", night, "Night as int");
+
+        std::vector<double> data(fNumSamples*fNumChannels*2);
+
+        for (uint32_t i=0; i<fNumSamples*fNumChannels; i++)
+        {
+            data[i] = fStat[i].first;
+            data[fNumSamples*fNumChannels+i] = fStat[i].second;
+        }
+
+        if (!file.WriteRow(data.data(), data.size()*sizeof(double)))
+        {
+            std::ostringstream msg;
+            msg << "Writing data to " << filename << " failed.";
+            return msg.str();
+        }
+
+        return std::string();
+    }*/
 };
 
Index: /branches/MarsGapdTimeJitter/mcore/factfits.h
===================================================================
--- /branches/MarsGapdTimeJitter/mcore/factfits.h	(revision 18281)
+++ /branches/MarsGapdTimeJitter/mcore/factfits.h	(revision 18282)
@@ -37,4 +37,6 @@
             readDrsCalib(fname);
     }
+
+        const std::vector<int16_t> &GetOffsetCalibration() const { return fOffsetCalibration; }
 
 private:
Index: /branches/MarsGapdTimeJitter/mdrs/MCalibrateDrsTimes.cc
===================================================================
--- /branches/MarsGapdTimeJitter/mdrs/MCalibrateDrsTimes.cc	(revision 18281)
+++ /branches/MarsGapdTimeJitter/mdrs/MCalibrateDrsTimes.cc	(revision 18282)
@@ -152,7 +152,9 @@
             continue;
 
-        const Float_t signal = (*fSignals)[sw].GetArrivalTime();
+        const Float_t signal = (*fSignals)[sw].GetArrivalTimeHiGain();
+        const Float_t slope  = (*fSignals)[sw].GetArrivalTimeHiGainError();
         const Float_t offset = fCalib ? fCalib->GetOffset(hw, start[hw], signal) : 0;
-        const Float_t delay  = fCalib ? fCalib->GetDelay(sw) : 0;
+        const Float_t offset2 = (fCalib && (signal-slope)>=0) ? fCalib->GetOffset(hw, start[hw], signal-slope) : 0;
+        const Float_t delay  = fCalib ? fCalib->GetDelay(hw) : 0;
 
         //if (fIsTimeMarker)
@@ -160,6 +162,8 @@
 
         // convert from slices to ns
-        const Float_t utime = 1000*(signal       )/fFreq-delay; // [ns]
-        const Float_t time  = 1000*(signal-offset)/fFreq-delay; // [ns]
+        const Float_t utime      = 1000*(signal       )/fFreq-delay;  // [ns]
+        const Float_t time       = 1000*(signal-offset)/fFreq-delay;  // [ns]
+        const Float_t slopecal   = (slope-offset+offset2)<0 ? -1 : 1000*(slope-offset+offset2)/fFreq; // [ns]
+        const Float_t uslope     = slope<0 ? -1 : 1000*(slope)/fFreq;                // [ns]
 
         /*
@@ -172,6 +176,10 @@
         {
             (*fArrivalTime)[idx[j]].SetArrivalTime(time);
+            (*fArrivalTime)[idx[j]].SetTimeSlope(slopecal);
             if (fArrivalTimeU)
+            {
                 (*fArrivalTimeU)[idx[j]].SetArrivalTime(utime);
+                (*fArrivalTimeU)[idx[j]].SetTimeSlope(uslope);
+            }
         }
     }
Index: /branches/MarsGapdTimeJitter/mdrs/MDrsCalibration.h
===================================================================
--- /branches/MarsGapdTimeJitter/mdrs/MDrsCalibration.h	(revision 18281)
+++ /branches/MarsGapdTimeJitter/mdrs/MDrsCalibration.h	(revision 18282)
@@ -30,13 +30,25 @@
     }
 
-    bool ReadFits(TString str)
+    bool ReadFits(TString fname)
     {
-        gSystem->ExpandPathName(str);
+        gSystem->ExpandPathName(fname);
 
-        const std::string msg = ReadFitsImp(str.Data());
+        std::string msg;
+        try
+        {
+            msg = ReadFitsImp(fname.Data());
+        }
+        catch (const std::exception &e)
+        {
+            msg = e.what();
+        }
+
         if (msg.empty())
+        {
+            *fLog << inf << "Read DRS calibration file " << fname << std::endl;
             return true;
+        }
 
-        *fLog << err << msg << std::endl;
+        *fLog << err << "Error reading from " << fname << ": " << msg << std::endl;
         return false;
     }
Index: /branches/MarsGapdTimeJitter/mdrs/MDrsCalibrationTime.cc
===================================================================
--- /branches/MarsGapdTimeJitter/mdrs/MDrsCalibrationTime.cc	(revision 18281)
+++ /branches/MarsGapdTimeJitter/mdrs/MDrsCalibrationTime.cc	(revision 18282)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz  2013 <mailto:thomas.bretz@epfl.ch>
+!   Author(s): Thomas Bretz  2013 <mailto:tbretz@physik.rwth-aachen.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2013
+!   Copyright: MAGIC Software Development, 2000-2015
 !
 !
@@ -31,4 +31,5 @@
 
 #include <TH1.h>
+#include <TGraph.h>
 
 ClassImp(MDrsCalibrationTime);
@@ -48,2 +49,99 @@
     return true;
 }
+
+void MDrsCalibrationTime::SetDelays(const TGraph &g)
+{
+    fDelays.assign(g.GetY(), g.GetY()+g.GetN());
+}
+
+bool MDrsCalibrationTime::ReadFits(TString fname)
+{
+    gSystem->ExpandPathName(fname);
+
+    try
+    {
+        fits file(fname.Data());
+        if (!file)
+            throw runtime_error(strerror(errno));
+
+        if (file.GetStr("TELESCOP")!="FACT")
+        {
+            std::ostringstream msg;
+            msg << "Not a valid FACT file (TELESCOP not FACT in header)";
+            throw runtime_error(msg.str());
+        }
+
+        if (file.GetNumRows()!=1)
+            throw runtime_error("Number of rows in table is not 1.");
+
+        fNumSamples  = file.GetUInt("NROI");
+        fNumChannels = file.GetUInt("NCH");
+        fNumEntries  = file.GetUInt("NBTIME");
+
+        const double *d = reinterpret_cast<double*>(file.SetPtrAddress("CellOffset"));
+        if (!file.GetNextRow())
+            throw runtime_error("Read error.");
+
+        fOffsets.assign(d, d+fNumSamples*fNumChannels),
+        fDelays.resize(0);
+    }
+    catch (const exception &e)
+    {
+        *fLog << err << "Error reading from " << fname << ": " << e.what() << endl;
+        return false;
+    }
+
+    *fLog << inf << "Read DRS calibration file " << fname << endl;
+    return true;
+}
+
+bool MDrsCalibrationTime::WriteFits(const string &fname) const
+{
+    const Bool_t exists = !gSystem->AccessPathName(fname.c_str(), kFileExists);
+    if (exists)
+    {
+        *fLog << err << "File '" << fname << "' already exists." << endl;
+        return false;
+    }
+
+    try
+    {
+        ofits file(fname.c_str());
+        if (!file)
+            throw runtime_error(strerror(errno));
+
+        file.SetDefaultKeys();
+        file.AddColumnDouble(fNumSamples*fNumChannels, "CellOffset", "samples", "Integral cell offset");
+
+        file.SetInt("ADCRANGE", 2000,    "Dynamic range of the ADC in mV");
+        file.SetInt("DACRANGE", 2500,    "Dynamic range of the DAC in mV");
+        file.SetInt("ADC",      12,      "Resolution of ADC in bits");
+        file.SetInt("DAC",      16,      "Resolution of DAC in bits");
+        file.SetInt("NPIX",     1440,    "Number of channels in the camera");
+        file.SetInt("NTM",      0,       "Number of time marker channels");
+        file.SetInt("NROI",     fNumSamples,  "Region of interest");
+        file.SetInt("NCH",      fNumChannels, "Number of chips");
+        file.SetInt("NBTIME",   fNumEntries,  "Num of entries for time calibration");
+
+        file.WriteTableHeader("DrsCellTimes");
+        //file.SetInt("NIGHT", night, "Night as int");
+
+        /*
+        file.SetStr("DATE-OBS", fDateObs, "First event of whole DRS calibration");
+        file.SetStr("DATE-END", fDateEnd, "Last event of whole DRS calibration");
+        file.SetStr("RUN-BEG", fDateRunBeg[0], "First event of run 0");
+        file.SetStr("RUN-END", fDateRunEnd[0], "Last event of run 0");
+        */
+
+        if (!file.WriteRow(fOffsets.data(), fOffsets.size()*sizeof(double)))
+            throw runtime_error("Write error.");
+    }
+    catch (const exception &e)
+    {
+        *fLog << err << "Error writing to " << fname << ": " << e.what() << endl;
+        return false;
+    }
+
+    *fLog << inf << "Wrote DRS calibration file " << fname << endl;
+    return true;
+}
Index: /branches/MarsGapdTimeJitter/mdrs/MDrsCalibrationTime.h
===================================================================
--- /branches/MarsGapdTimeJitter/mdrs/MDrsCalibrationTime.h	(revision 18281)
+++ /branches/MarsGapdTimeJitter/mdrs/MDrsCalibrationTime.h	(revision 18282)
@@ -10,7 +10,14 @@
 
 class TH1;
+class TGraph;
 
-class MDrsCalibrationTime : public MParContainer, public DrsCalibrateTime
+class MDrsCalibrationTime : public MParContainer//, public DrsCalibrateTime
 {
+    int64_t fNumEntries;
+
+    size_t fNumSamples;
+    size_t fNumChannels;
+
+    std::vector<double> fOffsets;
     std::vector<double> fDelays;
 
@@ -18,5 +25,5 @@
     MDrsCalibrationTime(const char *name=0, const char *title=0)
     {
-        fName  = name ? name : "MDrsCalibrationTime";
+        fName  = name  ? name  : "MDrsCalibrationTime";
         fTitle = title ? title : "";
     }
@@ -24,28 +31,39 @@
     void InitSize(uint16_t channels, uint16_t samples)
     {
-        //fDelays.clear();
-        //fDelays.resize(channels);
-
-        DrsCalibrateTime::InitSize(channels, samples);
+        fNumSamples  = samples;
+        fNumChannels = channels;
     }
 
     void SetCalibration(const DrsCalibrateTime &cal)
     {
-        *static_cast<DrsCalibrateTime*>(this) = cal;
+        fNumEntries  = cal.fNumEntries,
+        fNumSamples  = cal.fNumSamples,
+        fNumChannels = cal.fNumChannels,
+
+        fOffsets.resize(fNumSamples*fNumChannels);
+
+        for (size_t c=0; c<fNumChannels; c++)
+            for (size_t s=0; s<fNumSamples; s++)
+                fOffsets[c*fNumSamples+s] = cal.Offset(c, s);
     }
 
     bool SetDelays(const TH1 &cam);
+    void SetDelays(const TGraph &g);
 
-    double GetOffset(int hw, int spos, float tm) const
+    double GetOffset(uint32_t hw, uint32_t spos, float tm) const
     {
-        return Offset(hw/9, fmod(tm+spos, 1024)) - Offset(hw/9, spos);
+        const uint32_t ch = (hw/9)*fNumSamples;
+        return fOffsets[ch + fmod(tm+spos, fNumSamples)] - fOffsets[ch + spos];
     }
 
-    double GetDelay(int sw) const
+    double GetDelay(int hw) const
     {
-        return fDelays.size()==0 ? 0 : fDelays[sw];
+        return fDelays.size()==0 ? 0 : fDelays[hw];
     }
 
-    ClassDef(MDrsCalibrationTime, 2) // A list of histograms storing the Fadc spektrum of one pixel
+    bool ReadFits(TString fname);
+    bool WriteFits(const std::string &fname) const;
+
+    ClassDef(MDrsCalibrationTime, 3) // A list of histograms storing the Fadc spektrum of one pixel
 };
 
Index: /branches/MarsGapdTimeJitter/mdrs/MHDrsCalibrationTime.cc
===================================================================
--- /branches/MarsGapdTimeJitter/mdrs/MHDrsCalibrationTime.cc	(revision 18281)
+++ /branches/MarsGapdTimeJitter/mdrs/MHDrsCalibrationTime.cc	(revision 18282)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz 2013 <mailto:tbretz@phys.ethz.ch>
-!
-!   Copyright: MAGIC Software Development, 2000-2014
+!   Author(s): Thomas Bretz 2013 <mailto:tbretz@physik.rwth-aachen.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2015
 !
 !
@@ -37,4 +37,5 @@
 #include "MStatusDisplay.h"
 
+#include "MDrsCalibrationTime.h"
 #include "MPedestalSubtractedEvt.h"
 
Index: /branches/MarsGapdTimeJitter/mdrs/MHDrsCalibrationTime.h
===================================================================
--- /branches/MarsGapdTimeJitter/mdrs/MHDrsCalibrationTime.h	(revision 18281)
+++ /branches/MarsGapdTimeJitter/mdrs/MHDrsCalibrationTime.h	(revision 18282)
@@ -2,6 +2,6 @@
 #define MARS_MHDrsCalibrationTime
 
-#ifndef MARS_DrsCalibrationTime
-#include "MDrsCalibrationTime.h"
+#ifndef MARS_DrsCalib
+#include "DrsCalib.h"
 #endif
 
@@ -23,5 +23,5 @@
     MDrsCalibrationTime    *fCal;     //!
 
-    MDrsCalibrationTime fData; //
+    DrsCalibrateTime fData; //
 
     void InitHistogram();
Index: /branches/MarsGapdTimeJitter/mfileio/FileIOLinkDef.h
===================================================================
--- /branches/MarsGapdTimeJitter/mfileio/FileIOLinkDef.h	(revision 18281)
+++ /branches/MarsGapdTimeJitter/mfileio/FileIOLinkDef.h	(revision 18282)
@@ -19,4 +19,5 @@
 #pragma link C++ class MWriteRootFile+;
 #pragma link C++ class MWriteFitsFile+;
+
 #pragma link C++ class MMatrix+;
 
Index: /branches/MarsGapdTimeJitter/mfileio/MFitsArray.h
===================================================================
--- /branches/MarsGapdTimeJitter/mfileio/MFitsArray.h	(revision 18281)
+++ /branches/MarsGapdTimeJitter/mfileio/MFitsArray.h	(revision 18282)
@@ -30,4 +30,6 @@
 
 public:
+    virtual ~MArrayHelperBase() { };
+
    ofits* GetFitsTable()     {return fFitsTable;}
    UInt_t *      GetArraySizePtr()  {return &fArraySize;}
Index: /branches/MarsGapdTimeJitter/mfileio/MWriteFitsFile.cc
===================================================================
--- /branches/MarsGapdTimeJitter/mfileio/MWriteFitsFile.cc	(revision 18281)
+++ /branches/MarsGapdTimeJitter/mfileio/MWriteFitsFile.cc	(revision 18282)
@@ -519,7 +519,8 @@
 
          // initialize all columns of the sub-table, defined by the current container
+         TString containerName = i_subTable->second.GetContainer()->GetName();
          TClass * cl = i_subTable->second.GetContainer()->IsA();
-         if (!InitColumns(i_table->first, TString(cl->GetName()) + ".",  fitsTable, 
-                          i_subTable->second.GetContainer(), cl)     ) 
+         if (!InitColumns(i_table->first, containerName + ".",  fitsTable,
+                          i_subTable->second.GetContainer(), cl)     )
             return kFALSE;
 
Index: /branches/MarsGapdTimeJitter/mfilter/MFMagicCuts.cc
===================================================================
--- /branches/MarsGapdTimeJitter/mfilter/MFMagicCuts.cc	(revision 18281)
+++ /branches/MarsGapdTimeJitter/mfilter/MFMagicCuts.cc	(revision 18282)
@@ -316,5 +316,5 @@
 
     //fMap[kELeakage] = fMatrix->AddColumn("log10(MNewImagePar.fLeakage1+1)");
-    fMap[kELeakage] = fMatrix->AddColumn("NewImagePar.fLeakage1");
+    fMap[kELeakage] = fMatrix->AddColumn("MNewImagePar.fLeakage1");
 
     fMap[kEAlpha]   = fMatrix->AddColumn("MHillasSrc.fAlpha");
Index: /branches/MarsGapdTimeJitter/mhist/MHEvent.cc
===================================================================
--- /branches/MarsGapdTimeJitter/mhist/MHEvent.cc	(revision 18281)
+++ /branches/MarsGapdTimeJitter/mhist/MHEvent.cc	(revision 18282)
@@ -194,4 +194,10 @@
         fHist->SetName("Island Index");
         fHist->SetYTitle("Index");
+	fHist->SetPrettyPalette();
+        break;
+     case kEvtTimeSlope:
+     case kEvtTimeSlopeCleaned:
+        fHist->SetName("Time Slope");
+        fHist->SetYTitle("delta_t [ns]");
 	fHist->SetPrettyPalette();
         break;
@@ -295,4 +301,10 @@
         fHist->SetCamContent(*event, 5);
         break;
+    case kEvtTimeSlope:
+        fHist->SetCamContent(*event, 13);
+        break; 
+    case kEvtTimeSlopeCleaned:
+        fHist->SetCamContent(*event, 14);
+        break; 
     default:
         *fLog << "ERROR - Case " << (int)fType << " not implemented..." << endl;
Index: /branches/MarsGapdTimeJitter/mhist/MHEvent.h
===================================================================
--- /branches/MarsGapdTimeJitter/mhist/MHEvent.h	(revision 18281)
+++ /branches/MarsGapdTimeJitter/mhist/MHEvent.h	(revision 18282)
@@ -27,5 +27,6 @@
         kEvtCleaningLevels, kEvtCleaningData,
         kEvtIdxMax, kEvtArrTime, kEvtArrTimeCleaned,
-        kEvtTrigPix, kEvtIslandIndex
+        kEvtTrigPix, kEvtIslandIndex, kEvtTimeSlope,
+        kEvtTimeSlopeCleaned
     };
 
Index: /branches/MarsGapdTimeJitter/mimage/MNewImagePar.cc
===================================================================
--- /branches/MarsGapdTimeJitter/mimage/MNewImagePar.cc	(revision 18281)
+++ /branches/MarsGapdTimeJitter/mimage/MNewImagePar.cc	(revision 18282)
@@ -220,8 +220,7 @@
         const Double_t dzx   =  hillas.GetCosDelta()*dx + hillas.GetSinDelta()*dy; // [mm]
         const Double_t dzy   = -hillas.GetSinDelta()*dx + hillas.GetCosDelta()*dy; // [mm]
-        const Double_t dz    =  gpix.GetT()*gpix.GetT()/4;
-        const Double_t tana  =  dzy*dzy/(dzx*dzx);
-        const Double_t distr =  (1+tana)/(rl + tana*rw);
-        if (distr>dist0-dz || dzx==0)
+        const Double_t dz    =  gpix.GetT()/2;
+        const Double_t distr =  (dzy*dzy+dzx*dzx)/(dzx*dzx*rl + dzy*dzy*rw);
+        if ((dzx==0 && dzy==0) || sqrt(distr)>sqrt(dist0)-dz)
             fConcCore += nphot;
 
Index: /branches/MarsGapdTimeJitter/mjobs/MJSimulation.cc
===================================================================
--- /branches/MarsGapdTimeJitter/mjobs/MJSimulation.cc	(revision 18281)
+++ /branches/MarsGapdTimeJitter/mjobs/MJSimulation.cc	(revision 18282)
@@ -244,6 +244,8 @@
     write.AddContainer("MRawEvtHeader",       "Events");
     write.AddContainer("MMcEvt",              "Events", kFALSE);
+    write.AddContainer("MMcEvtBasic",         "Events", kFALSE);
     write.AddContainer("IncidentAngle",       "Events", kFALSE);
     write.AddContainer("MPointingPos",        "Events", kFALSE);
+    write.AddContainer("MSimSourcePos",       "Events", kFALSE);
 }
 
@@ -439,8 +441,10 @@
     MParSpline splinecones("ConesAngularAcceptance");
     MParSpline splinecones2("ConesTransmission");
+    MParSpline splineAdditionalPhotonAcceptance("AdditionalPhotonAcceptance");
     plist.AddToList(&splinepde);
     plist.AddToList(&splinemirror);
     plist.AddToList(&splinecones);
     plist.AddToList(&splinecones2);
+    plist.AddToList(&splineAdditionalPhotonAcceptance);
 
     const TString sin2 = "sin(MCorsikaEvtHeader.fZd)*sin(MCorsikaRunHeader.fZdMin*TMath::DegToRad())";
@@ -458,4 +462,5 @@
     MSimAbsorption cones("SimConesAngularAcceptance");
     MSimAbsorption cones2("SimConesTransmission");
+    MSimAbsorption additionalPhotonAcceptance("SimAdditionalPhotonAcceptance");
     absapd.SetParName("PhotonDetectionEfficiency");
     absmir.SetParName("MirrorReflectivity");
@@ -463,4 +468,5 @@
     cones.SetUseTheta();
     cones2.SetParName("ConesTransmission");
+    additionalPhotonAcceptance.SetParName("AdditionalPhotonAcceptance");
  
     MSimPointingPos pointing;
@@ -654,5 +660,4 @@
     write3af.AddContainer("MRawEvtData",      "Events");
     write3af.AddContainer("MTruePhotonsPerPixelCont", "Events");
-    write3af.AddContainer("MPhotonEvent","Events");
 
     write3ar.AddContainer("ElectronicNoise",  "RunHeaders", kTRUE, 1);
@@ -804,4 +809,5 @@
             tasks.AddToList(&absapd);
             tasks.AddToList(&absmir);
+            tasks.AddToList(&additionalPhotonAcceptance);
             if (0)
                 tasks.AddToList(&simatm); // FASTER?
Index: /branches/MarsGapdTimeJitter/mjoptim/MJOptimizeCuts.cc
===================================================================
--- /branches/MarsGapdTimeJitter/mjoptim/MJOptimizeCuts.cc	(revision 18281)
+++ /branches/MarsGapdTimeJitter/mjoptim/MJOptimizeCuts.cc	(revision 18282)
@@ -95,5 +95,5 @@
 
 // Parameter container
-#include "MGeomCamMagic.h"
+#include "MGeomCamFACT.h"
 #include "MParameters.h"
 #include "MFilterList.h"
@@ -150,5 +150,5 @@
     MParList parlist;
 
-    MGeomCamMagic geom; // For GetConvMm2Deg
+    MGeomCamFACT geom; // For GetConvMm2Deg
     parlist.AddToList(&geom);
 
@@ -274,5 +274,5 @@
     MParList parlist;
 
-    MGeomCamMagic geom; // For GetConvMm2Deg
+    MGeomCamFACT geom; // For GetConvMm2Deg
     parlist.AddToList(&geom);
 
Index: /branches/MarsGapdTimeJitter/msignal/MExtractFACT.cc
===================================================================
--- /branches/MarsGapdTimeJitter/msignal/MExtractFACT.cc	(revision 18281)
+++ /branches/MarsGapdTimeJitter/msignal/MExtractFACT.cc	(revision 18282)
@@ -171,4 +171,5 @@
         //
         Float_t max  = -1;
+        Float_t tmax  = -1;
         if (pmax>pbeg && pmax<pend-1)
         {
@@ -194,7 +195,7 @@
                         max = exp(a + b*dx + c*dx*dx);
 
-                        // Time is position of maximum
-                        //time = dx;
-                        //time += Int_t(pmax-ptr);
+                        // tmax is position of maximum
+                        tmax = dx;
+                        tmax += Int_t(pmax-ptr);
                     }
                 }
@@ -203,4 +204,5 @@
 
         Float_t time = -1;
+        Float_t slope = -1;
         if (max>=0)
         {
@@ -208,5 +210,5 @@
 
             // Time is position of half hight leading edge
-            pend = std::max(pbeg, pmax-10);
+            pend = std::max(pbeg, pmax-15);
             for (;pmax>=pend; pmax--)
                 if (*pmax<max/2)
@@ -217,4 +219,5 @@
                 time = (max/2-pmax[0])/(pmax[1]-pmax[0]);
                 time += Int_t(pmax-ptr);
+                slope = tmax - time;
             }
         }
@@ -223,5 +226,5 @@
         {
             time = gRandom->Uniform(rangehi)+fHiGainFirst+1;
-            max  = pbeg[uint16_t(time)];
+            max  = ptr[uint16_t(time)];
         }
 
@@ -232,5 +235,5 @@
         pix.SetGainSaturation(0);
 
-        tix.SetArrivalTime(time);
+        tix.SetArrivalTime(time, slope);
         tix.SetGainSaturation(0);
     }
Index: /branches/MarsGapdTimeJitter/msignal/MSignalCam.cc
===================================================================
--- /branches/MarsGapdTimeJitter/msignal/MSignalCam.cc	(revision 18281)
+++ /branches/MarsGapdTimeJitter/msignal/MSignalCam.cc	(revision 18282)
@@ -584,4 +584,5 @@
 // 10: as 0, but returns kFALSE if signal <=0
 // 11: as 8, but returns kFALSE if signal <=0
+// 12: time slope
 //
 Bool_t MSignalCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
@@ -593,5 +594,5 @@
 
     // Used inlcudes status unampped
-    if (!pix.IsPixelUsed() && (type<6 || type==8))
+    if (!pix.IsPixelUsed() && (type<6 || type==8 || type==14))
         return kFALSE;
 
@@ -668,4 +669,14 @@
         return pix.GetNumPhotons()>0;
 
+    case 13: // time slope
+        val = pix.GetTimeSlope();
+        break;
+
+    case 14: // time slope
+        if (pix.IsPixelUnmapped())
+            return kFALSE;
+        val = pix.GetTimeSlope();
+        break;
+
     case 9:
     default:
Index: /branches/MarsGapdTimeJitter/msignal/MSignalPix.cc
===================================================================
--- /branches/MarsGapdTimeJitter/msignal/MSignalPix.cc	(revision 18281)
+++ /branches/MarsGapdTimeJitter/msignal/MSignalPix.cc	(revision 18282)
@@ -64,4 +64,8 @@
 //    size of the calibrated data by roughly 0.5%
 //
+// Version 8:
+// ----------
+//  - added new time variable fTimeSlope describing the width of the rise time
+//
 ////////////////////////////////////////////////////////////////////////////
 #include "MSignalPix.h"
@@ -80,5 +84,6 @@
 MSignalPix::MSignalPix(Float_t phot, Float_t errphot) :
     fIsCore(kFALSE), fRing(1), fIdxIsland(-1),
-    fPhot(phot), fErrPhot(errphot), fArrivalTime(-1)
+    fPhot(phot), fErrPhot(errphot), fArrivalTime(-1),
+    fTimeSlope(-1)
 {
     MMath::ReducePrecision(fPhot);
@@ -94,4 +99,5 @@
     fErrPhot     =  0;
     fArrivalTime = -1;
+    fTimeSlope = -1;
 }
 
Index: /branches/MarsGapdTimeJitter/msignal/MSignalPix.h
===================================================================
--- /branches/MarsGapdTimeJitter/msignal/MSignalPix.h	(revision 18281)
+++ /branches/MarsGapdTimeJitter/msignal/MSignalPix.h	(revision 18282)
@@ -19,4 +19,5 @@
     Float_t  fErrPhot;       // the error of fPhot
     Float_t  fArrivalTime;   // Calibrated Arrival Time
+    Float_t  fTimeSlope;     // Time between half rise time and position of maximum
 
 public:
@@ -24,5 +25,6 @@
     MSignalPix(const MSignalPix &pix)
         : fIsCore(pix.fIsCore), fRing(pix.fRing), fIdxIsland(pix.fIdxIsland),
-        fPhot(pix.fPhot), fErrPhot(pix.fErrPhot), fArrivalTime(pix.fArrivalTime)
+        fPhot(pix.fPhot), fErrPhot(pix.fErrPhot), fArrivalTime(pix.fArrivalTime),
+        fTimeSlope(pix.fTimeSlope)
     {
     }
@@ -39,4 +41,5 @@
         pix.fErrPhot     = fErrPhot;
         pix.fArrivalTime = fArrivalTime;
+        pix.fTimeSlope   = fTimeSlope;
     }
     void    Print(Option_t *opt = NULL) const;
@@ -46,4 +49,5 @@
     Float_t GetErrorPhot() const          { return fErrPhot; }
     Float_t GetArrivalTime() const        { return fArrivalTime; }
+    Float_t GetTimeSlope() const          { return fTimeSlope; }
 
     Bool_t  IsPixelUsed() const           { return fRing>0; }
@@ -65,9 +69,10 @@
     void    Set(Float_t np, Float_t ep)   { MMath::ReducePrecision(np); MMath::ReducePrecision(ep);  fPhot = np; fErrPhot = ep; }
     void    SetArrivalTime(Float_t tm)    { fArrivalTime = tm; }
+    void    SetTimeSlope(Float_t ts)      { fTimeSlope = ts; }
 
     //void    AddNumPhotons(Float_t f)      { fPhot += f; }
     //void    Scale(Float_t f)              { fPhot /= f; }
 
-    ClassDef(MSignalPix, 7)  // class containing information about the Cerenkov Photons in a pixel
+    ClassDef(MSignalPix, 8)  // class containing information about the Cerenkov Photons in a pixel
 };
 
Index: /branches/MarsGapdTimeJitter/msim/MSimPointingPos.cc
===================================================================
--- /branches/MarsGapdTimeJitter/msim/MSimPointingPos.cc	(revision 18281)
+++ /branches/MarsGapdTimeJitter/msim/MSimPointingPos.cc	(revision 18282)
@@ -39,5 +39,5 @@
 //
 // If no view cone option was given and off-target observations are switched
-// on by setting fOffTargetDistance!=0 the poitnting position is calculated:
+// on by setting fOffTargetDistance!=0 the pointing position is calculated:
 //
 //  1) fOffTargetDistance < 0:
@@ -51,4 +51,18 @@
 //     fOffTargetDistance. (phi==0 is the direction of positive theta)
 //
+// The original zenith and azimuth coordinates of the shower axis are stored in
+// the MSimSourcePos container.
+//
+// If the view cone option was given and off-target observations are switched on
+// the orientation is fixed to the main direction around the view cone was
+// produced.
+// In addition a 'quasi'-simulated source position is calculated,
+// depending on fOffTargetDistance and fOffTargetPhi (see 1) and 2) above).
+// The corresponding zenith and azimuth coordinates are stored in the
+// MSimSourcePos container. This is of course not a physical source position,
+// but it can be used to determine the performance of wobble analysis on
+// background events (which are homogenous distributed).
+//
+//
 //
 //  Input Containers:
@@ -58,4 +72,5 @@
 //  Output Containers:
 //   MPointingPos
+//   MSimSourcePos
 //
 //////////////////////////////////////////////////////////////////////////////
@@ -84,5 +99,5 @@
 //
 MSimPointingPos::MSimPointingPos(const char* name, const char *title)
-    : fRunHeader(0), fEvtHeader(0), fPointing(0),
+    : fRunHeader(0), fEvtHeader(0), fPointing(0), fSimSourcePosition(0),
     fOffTargetDistance(0), fOffTargetPhi(-1)
 
@@ -140,4 +155,8 @@
     fPointing = (MPointingPos*)pList->FindCreateObj("MPointingPos");
     if (!fPointing)
+        return kFALSE;
+
+    fSimSourcePosition = (MPointingPos*)pList->FindCreateObj("MPointingPos","MSimSourcePos");
+    if (!fSimSourcePosition)
         return kFALSE;
 
@@ -180,6 +199,6 @@
     {
         *fLog << warn;
-        *fLog << "WARNING - Combining the view cone option with off-target observations doesn't make sense." << endl;
-        *fLog << "          Option for off-target observations will be ignored." << endl;
+        *fLog << "WARNING - Combining the view cone option with off-target pointing can lead to not homogenous events." << endl;
+        *fLog << "          A simulated source position according to the off-target parameters will be created instead." << endl;
     }
     // FIXME: Check also the enlightened region on the ground!
@@ -209,35 +228,41 @@
 
     // Local sky coordinates (direction of telescope axis)
-    Double_t zd = viewcone ? fRunHeader->GetZdMin() : fEvtHeader->GetZd()*TMath::RadToDeg();  // x==north
-    Double_t az = viewcone ? fRunHeader->GetAzMin() : fEvtHeader->GetAz()*TMath::RadToDeg();  // y==west
-
-    if (!viewcone)
-    {
-        Double_t dtheta, dphi;
-        GetDelta(dtheta, dphi);
-
-        const Double_t theta = zd*TMath::DegToRad();
-        const Double_t phi   = az*TMath::DegToRad();
-
-        TVector3 src, pnt;
-        src.SetMagThetaPhi(1, theta,        phi);
-        pnt.SetMagThetaPhi(1, theta+dtheta, phi);
-
-        pnt.Rotate(dphi, src);
-
-        zd = pnt.Theta()*TMath::RadToDeg();
-        az = pnt.Phi()  *TMath::RadToDeg();
-    }
+    Double_t zdCorsika = viewcone ? fRunHeader->GetZdMin() : fEvtHeader->GetZd()*TMath::RadToDeg();  // x==north
+    Double_t azCorsika = viewcone ? fRunHeader->GetAzMin() : fEvtHeader->GetAz()*TMath::RadToDeg();  // y==west
+
+    // Calculate off target position in local sky coordinates
+    Double_t dtheta, dphi;
+    GetDelta(dtheta, dphi);
+
+    const Double_t theta = zdCorsika*TMath::DegToRad();
+    const Double_t phi   = azCorsika*TMath::DegToRad();
+
+    TVector3 originalVector, wobbleVector;
+    originalVector.SetMagThetaPhi(1, theta,        phi);
+    wobbleVector.SetMagThetaPhi(1, theta+dtheta, phi);
+
+    wobbleVector.Rotate(dphi, originalVector);
+
+    Double_t zdWobble, azWobble;
+    zdWobble = wobbleVector.Theta()*TMath::RadToDeg();
+    azWobble = wobbleVector.Phi()  *TMath::RadToDeg();
 
     // Transform the corsika coordinate system (north is magnetic north)
     // into the telescopes local coordinate system. Note, that all vectors
     // are already correctly oriented.
-    az += fRunHeader->GetMagneticFieldAz()*TMath::RadToDeg();
-
-    // Setup the pointing position
-    fPointing->SetLocalPosition(zd, az);
-
-    // Calculate incident angle between magnetic field direction
-    // and pointing direction ( phi and theta? )
+    azCorsika += fRunHeader->GetMagneticFieldAz()*TMath::RadToDeg();
+    azWobble += fRunHeader->GetMagneticFieldAz()*TMath::RadToDeg();
+
+    // Setup the pointing and the simulated source position
+    if (!viewcone)
+    {
+        fPointing->SetLocalPosition(zdWobble, azWobble);
+        fSimSourcePosition->SetLocalPosition(zdCorsika, azCorsika);
+    }
+    else
+    {
+        fPointing->SetLocalPosition(zdCorsika, azCorsika);
+        fSimSourcePosition->SetLocalPosition(zdWobble, azWobble);
+    }
 
     return kTRUE;
Index: /branches/MarsGapdTimeJitter/msim/MSimPointingPos.h
===================================================================
--- /branches/MarsGapdTimeJitter/msim/MSimPointingPos.h	(revision 18281)
+++ /branches/MarsGapdTimeJitter/msim/MSimPointingPos.h	(revision 18282)
@@ -16,5 +16,6 @@
     MCorsikaRunHeader *fRunHeader;  //! Header storing event information
     MCorsikaEvtHeader *fEvtHeader;  //! Header storing event information
-    MPointingPos      *fPointing;   //! Output storing telescope poiting position in local (telescope) coordinate system
+    MPointingPos      *fPointing;   //! Output storing telescope pointing position in local (telescope) coordinate system
+    MPointingPos      *fSimSourcePosition;   //! Output storing simulated source pointing position in local (telescope) coordinate system
 
     Double_t fOffTargetDistance;    // [rad] Distance of the observed off-target position from the source
Index: /branches/MarsGapdTimeJitter/msimcamera/MSimCamera.cc
===================================================================
--- /branches/MarsGapdTimeJitter/msimcamera/MSimCamera.cc	(revision 18281)
+++ /branches/MarsGapdTimeJitter/msimcamera/MSimCamera.cc	(revision 18282)
@@ -155,19 +155,20 @@
     }
     // Check all entries for inf and nan. Those are not accepted here.
-    for( std::vector< double > row : fFixTimeOffsetsBetweenPixelsInNs->fM ){
-        for( double number : row){
-
-            if( std::isnan(number) || std::isinf(number) ){
-
+    for( int row_index=0; row_index<fFixTimeOffsetsBetweenPixelsInNs->fM.size(); row_index++){
+        std::vector<double> row = fFixTimeOffsetsBetweenPixelsInNs->fM.at(row_index);
+        for( int col_index=0; col_index<row.size(); col_index++){
+            double specific_delay = row.at(col_index);
+            if( std::isnan(specific_delay) || std::isinf(specific_delay) ){
                 *fLog << err << "In Source: "<< __FILE__ <<" in line: ";
                 *fLog << __LINE__;
                 *fLog << " in function: "<< __func__ <<"\n";
-                *fLog << "There is a non normal number in the fix temporal ";
-                *fLog << "pixel offsets. This is at least one number is ";
-                *fLog << "NaN or Inf. This here is >"<< number;
+                *fLog << "There is a non normal specific_delay in the fix temporal ";
+                *fLog << "pixel offsets. This is that at least one specific_delay is ";
+                *fLog << "NaN or Inf. This here is >"<< specific_delay;
                 *fLog << "<... aborting." << endl;               
                 return kFALSE;
             }
         }
+
     }
     // -------------------------------------------------------------------
Index: /branches/MarsGapdTimeJitter/resources/delays-20150217.txt
===================================================================
--- /branches/MarsGapdTimeJitter/resources/delays-20150217.txt	(revision 18282)
+++ /branches/MarsGapdTimeJitter/resources/delays-20150217.txt	(revision 18282)
@@ -0,0 +1,1441 @@
+# delays [ns] / slices sorted by chid
+0 0.172905
+1 0.319128
+2 0.166794
+3 0.309198
+4 0.0087595
+5 0.29632
+6 0.136952
+7 0.129412
+8 0.181333
+9 0.366984
+10 0.240945
+11 0.316615
+12 0.197538
+13 0.225985
+14 0.19417
+15 0.155633
+16 0.0509615
+17 0.224877
+18 0.141319
+19 0.163913
+20 0.023589
+21 0.152206
+22 -0.103244
+23 0.235787
+24 0.133845
+25 0.147915
+26 0.048368
+27 0.307045
+28 -0.036907
+29 0.296245
+30 0.125564
+31 0.078489
+32 -0.009858
+33 0.223563
+34 -0.034215
+35 0.237397
+36 0.318351
+37 0.449135
+38 0.256949
+39 0.515848
+40 0.159097
+41 0.337693
+42 0.211063
+43 0.329898
+44 0.155964
+45 0.298297
+46 0.0530545
+47 0.202749
+48 0.236556
+49 0.146587
+50 0.024006
+51 0.162222
+52 -0.0720735
+53 0.053552
+54 0.234351
+55 0.22175
+56 0.043059
+57 0.181012
+58 -0.00436
+59 0.199327
+60 0.146314
+61 0.102121
+62 0.115345
+63 0.368358
+64 0.103873
+65 0.262455
+66 0.125747
+67 0.209332
+68 0.067542
+69 0.180889
+70 0.232068
+71 0.054701
+72 0.541798
+73 0.686346
+74 0.606684
+75 0.802686
+76 0.460045
+77 0.717163
+78 1.28569
+79 1.59414
+80 -0.429138
+81 0.401913
+82 0.276112
+83 0.452704
+84 0.256263
+85 0.161541
+86 0.163206
+87 0.38346
+88 0.156055
+89 0.337678
+90 0.343492
+91 0.40395
+92 0.27699
+93 0.437579
+94 0.171847
+95 0.267826
+96 0.308782
+97 0.330328
+98 0.164585
+99 0.500046
+100 0.242462
+101 0.434182
+102 0.401998
+103 0.428737
+104 0.280504
+105 0.358314
+106 0.100026
+107 0.282208
+108 -0.181279
+109 -0.0277325
+110 -0.170662
+111 0.053029
+112 -0.296459
+113 -0.0450535
+114 -0.19064
+115 -0.168832
+116 -0.287789
+117 -0.139725
+118 -0.312698
+119 -0.186494
+120 -0.295932
+121 -0.285288
+122 -0.343932
+123 -0.254866
+124 -0.380796
+125 -0.245443
+126 -0.149884
+127 -0.0193585
+128 -0.222543
+129 -0.033859
+130 -0.304654
+131 -0.101879
+132 -0.224264
+133 -0.0221155
+134 -0.269056
+135 -0.158894
+136 -0.373277
+137 -0.152344
+138 -0.199842
+139 -0.140396
+140 -0.307049
+141 -0.28898
+142 -0.467605
+143 -0.426941
+144 0.517551
+145 0.667674
+146 0.62592
+147 0.786975
+148 0.491115
+149 0.788989
+150 0.682506
+151 0.668573
+152 0.667959
+153 0.378663
+154 0.19019
+155 0.333128
+156 0.289455
+157 0.140546
+158 0.217163
+159 0.360403
+160 0.150111
+161 0.249908
+162 0.390881
+163 0.417712
+164 0.323605
+165 0.433459
+166 0.183075
+167 0.498978
+168 0.332261
+169 0.39139
+170 0.324464
+171 0.39799
+172 0.190741
+173 0.387397
+174 0.235247
+175 0.296337
+176 0.201721
+177 0.345755
+178 0.131207
+179 0.312399
+180 0.325674
+181 0.348025
+182 0.275367
+183 0.428098
+184 0.239869
+185 0.347901
+186 0.253064
+187 0.260916
+188 0.238266
+189 0.238149
+190 0.0233235
+191 0.196342
+192 0.0575315
+193 -0.060739
+194 -0.086026
+195 0.0576165
+196 -0.052698
+197 -0.010046
+198 0.0584595
+199 0.0372155
+200 -0.104507
+201 -0.00913
+202 -0.137883
+203 -0.010528
+204 -0.056028
+205 0.044703
+206 -0.078114
+207 0.0114355
+208 -0.213308
+209 0.0943015
+210 0.002272
+211 0.019112
+212 -0.132622
+213 -0.14066
+214 -0.302393
+215 -0.213854
+216 0.2107
+217 0.423966
+218 0.423111
+219 0.48981
+220 0.26607
+221 0.550461
+222 0.462233
+223 0.533388
+224 0.456296
+225 0.438835
+226 0.303986
+227 0.606047
+228 0.305473
+229 0.209301
+230 0.349282
+231 0.345157
+232 0.157944
+233 0.267483
+234 0.282542
+235 0.314171
+236 0.21269
+237 0.220697
+238 0.01121
+239 0.270257
+240 0.266429
+241 0.237443
+242 0.102823
+243 0.387232
+244 0.231705
+245 0.462756
+246 0.276653
+247 0.279348
+248 0.31115
+249 0.415482
+250 0.109152
+251 0.260665
+252 0.378381
+253 0.535973
+254 0.498701
+255 0.576638
+256 0.349977
+257 0.478635
+258 0.469421
+259 0.454228
+260 0.484717
+261 0.321715
+262 0.16297
+263 0.329695
+264 0.207403
+265 0.100086
+266 0.187959
+267 0.181799
+268 0.0412
+269 0.181563
+270 0.395317
+271 0.372869
+272 0.27488
+273 0.377063
+274 0.177407
+275 0.499918
+276 0.193744
+277 0.236741
+278 0.243031
+279 0.293149
+280 0.0447305
+281 0.258801
+282 0.251852
+283 0.210002
+284 0.179514
+285 0.215614
+286 0.0491885
+287 0.072583
+288 0.203785
+289 0.247762
+290 0.103158
+291 0.349966
+292 -0.031743
+293 0.23515
+294 0.093454
+295 0.153976
+296 0.129237
+297 -1.00039
+298 -0.168727
+299 0.0575165
+300 0.015515
+301 -0.0294335
+302 -0.0376815
+303 -0.04014
+304 -0.134211
+305 -0.022413
+306 0.0880105
+307 0.16447
+308 -0.016791
+309 0.0816445
+310 -0.15588
+311 0.173135
+312 0.008993
+313 0.122139
+314 -0.0445985
+315 0.211902
+316 -0.117309
+317 0.219187
+318 0.0661905
+319 0.100654
+320 -0.052375
+321 0.0152325
+322 -0.180751
+323 -0.052762
+324 0.0047005
+325 0.220211
+326 0.069824
+327 0.160471
+328 -0.067534
+329 0.113519
+330 0.070001
+331 0.0858025
+332 0.0761135
+333 -0.0731135
+334 -0.229285
+335 -0.0474905
+336 -0.156028
+337 -0.135658
+338 -0.119274
+339 -0.125978
+340 -0.328597
+341 -0.2248
+342 -0.091505
+343 -0.161967
+344 -0.0990565
+345 0.0884635
+346 -0.366502
+347 0.070449
+348 -0.271159
+349 -0.086887
+350 -0.217266
+351 0.108496
+352 -0.198388
+353 0.177588
+354 -0.0407035
+355 0.064532
+356 -0.0347905
+357 0.0973745
+358 -0.208863
+359 -0.159602
+360 0.131104
+361 0.224978
+362 0.155141
+363 0.367775
+364 0.038227
+365 0.35083
+366 0.085996
+367 0.130595
+368 0.169427
+369 0.023661
+370 -0.232492
+371 0.0044575
+372 -0.0759545
+373 -0.140465
+374 -0.146131
+375 0.063448
+376 -0.276626
+377 -0.0725935
+378 -0.0635475
+379 -0.18639
+380 -0.214154
+381 -0.001183
+382 -0.269444
+383 -0.0394015
+384 -0.095303
+385 -0.089435
+386 -0.136313
+387 0.249246
+388 -0.110247
+389 0.255894
+390 0.16427
+391 0.051469
+392 0.0758975
+393 0.0644145
+394 -0.12747
+395 0.133338
+396 -0.320864
+397 -0.244552
+398 -0.286453
+399 -0.100649
+400 -0.397106
+401 -0.209147
+402 -0.251463
+403 -0.290983
+404 -0.236971
+405 -0.277061
+406 -0.397008
+407 -0.337796
+408 -0.444339
+409 -0.533925
+410 -0.38769
+411 -0.381994
+412 -0.609587
+413 -0.480728
+414 -0.530035
+415 -0.438193
+416 -0.540924
+417 -0.453446
+418 -0.619242
+419 -0.481475
+420 -0.640696
+421 -0.568218
+422 -0.656609
+423 -0.420604
+424 -0.522277
+425 -0.373111
+426 -0.353771
+427 -0.352295
+428 -0.426107
+429 -0.431778
+430 -0.550405
+431 -0.380234
+432 0.0824445
+433 0.107266
+434 0.065363
+435 0.191413
+436 -0.112408
+437 0.140653
+438 0.121994
+439 0.062237
+440 0.0576375
+441 0.036838
+442 -0.132957
+443 0.011374
+444 -0.04533
+445 -0.181938
+446 -0.048352
+447 -0.085943
+448 -0.335506
+449 -0.092617
+450 -0.077088
+451 -0.062519
+452 -0.058979
+453 -0.0142085
+454 -0.264873
+455 -0.0109065
+456 -0.138248
+457 0.010231
+458 -0.098945
+459 0.177725
+460 -0.092713
+461 0.233984
+462 0.276597
+463 0.085163
+464 0.0879445
+465 0.056468
+466 -0.034508
+467 0.010197
+468 -0.0367615
+469 0.0487385
+470 0.054785
+471 0.175158
+472 0.0161795
+473 0.092409
+474 0.042147
+475 0.10208
+476 0.049083
+477 -0.112615
+478 -0.260747
+479 -0.0632155
+480 -0.171736
+481 -0.241679
+482 -0.267823
+483 -0.140823
+484 -0.331081
+485 -0.273116
+486 -0.276909
+487 -0.238176
+488 -0.349172
+489 -0.30014
+490 -0.417882
+491 -0.255985
+492 -0.325961
+493 -0.261815
+494 -0.309332
+495 -0.132725
+496 -0.280784
+497 -0.0829835
+498 -0.137498
+499 -0.0675995
+500 -0.158016
+501 -0.249042
+502 -0.328999
+503 -0.222223
+504 -0.583776
+505 -0.475214
+506 -0.570342
+507 -0.393051
+508 -0.621571
+509 -0.457242
+510 -0.553893
+511 -0.521879
+512 -0.486967
+513 -0.666763
+514 -0.756089
+515 -0.65354
+516 -0.830727
+517 -0.841959
+518 -0.784668
+519 -0.725599
+520 -0.86371
+521 -0.767543
+522 -0.463597
+523 -0.392769
+524 -0.491837
+525 -0.42232
+526 -0.623112
+527 -1.67296
+528 -1.58472
+529 -0.475804
+530 -0.507722
+531 -0.456657
+532 -0.654891
+533 -0.494944
+534 -0.419699
+535 -0.446093
+536 -0.557346
+537 -0.470637
+538 -0.718671
+539 -0.695816
+540 -0.0288875
+541 0.0812085
+542 0.0431935
+543 0.299619
+544 -0.025557
+545 0.147756
+546 -0.0312905
+547 0.13963
+548 -0.0160685
+549 -0.0593635
+550 -0.297707
+551 -0.125522
+552 -0.187616
+553 -0.265532
+554 -0.305486
+555 -0.144288
+556 -0.432455
+557 -0.330425
+558 -0.0179125
+559 0.0453115
+560 -0.0596855
+561 0.046409
+562 -0.044504
+563 0.029104
+564 -0.0667195
+565 -0.001313
+566 -0.143301
+567 0.0677195
+568 -0.122117
+569 0.028503
+570 -0.0416895
+571 0.056711
+572 -0.028342
+573 0.0069495
+574 -0.211373
+575 -0.171061
+576 -0.0354085
+577 0.189802
+578 -0.083689
+579 0.20514
+580 -0.196972
+581 0.0754525
+582 -0.0302255
+583 -0.033531
+584 -0.131194
+585 0.057334
+586 -0.0731845
+587 0.038646
+588 -0.050107
+589 -0.118064
+590 -0.107439
+591 -0.0120035
+592 -0.217289
+593 -0.148912
+594 -0.213851
+595 -0.119334
+596 -0.218047
+597 0.0250675
+598 -0.306447
+599 -0.02816
+600 -0.245274
+601 -0.116971
+602 -0.205404
+603 -0.092257
+604 -0.294676
+605 -0.016664
+606 -0.205452
+607 -0.165392
+608 -0.238358
+609 -0.075719
+610 -0.342792
+611 -0.163959
+612 -0.020252
+613 0.115161
+614 0.03787
+615 0.0838925
+616 -0.146196
+617 -0.0173015
+618 -0.0949195
+619 0.008336
+620 -0.0897085
+621 -0.408544
+622 -0.527197
+623 -0.406473
+624 -0.413067
+625 -0.517214
+626 -0.595426
+627 -0.376823
+628 -0.61919
+629 -0.553337
+630 -0.283811
+631 -0.174827
+632 -0.381913
+633 -0.252014
+634 -0.465274
+635 -0.243783
+636 -0.319112
+637 -0.254362
+638 -0.430627
+639 -0.498139
+640 -0.619202
+641 -0.401496
+642 -0.494702
+643 -0.491872
+644 -0.61507
+645 -0.527123
+646 -0.620065
+647 -0.566469
+648 0.096244
+649 0.123592
+650 0.0042415
+651 0.223175
+652 -0.093525
+653 0.107152
+654 -0.014294
+655 0.105857
+656 0.0599585
+657 0.118021
+658 -0.0955725
+659 0.104019
+660 -0.091845
+661 -0.142779
+662 -0.0266675
+663 0.0352185
+664 -0.27147
+665 -0.0957815
+666 -0.09536
+667 -0.173012
+668 -0.13677
+669 -0.050255
+670 -0.395267
+671 -0.170419
+672 -0.226197
+673 -0.170824
+674 -0.199955
+675 -0.253081
+676 -0.327649
+677 -0.181507
+678 -0.113033
+679 -0.126764
+680 -0.342277
+681 -0.274577
+682 -0.405782
+683 -0.338809
+684 0.0466395
+685 0.218304
+686 0.205074
+687 0.369161
+688 0.042851
+689 0.292353
+690 0.301768
+691 0.105655
+692 0.270556
+693 0.327582
+694 -0.029113
+695 0.09196
+696 0.043664
+697 0.040666
+698 -0.0766465
+699 -0.0005645
+700 -0.222094
+701 0.034061
+702 5.95e-05
+703 0.003233
+704 -0.094798
+705 0.118166
+706 -0.16737
+707 0.0558795
+708 -0.0776395
+709 -0.0941755
+710 -0.117546
+711 0.157397
+712 -0.136347
+713 0.086322
+714 0.0399695
+715 0.0567015
+716 -0.029567
+717 0.0818635
+718 -0.138043
+719 -0.116792
+720 0.243728
+721 -0.888722
+722 -0.35104
+723 0.501397
+724 0.205701
+725 0.276104
+726 0.232968
+727 0.94901
+728 0.260387
+729 0.198717
+730 0.151564
+731 0.151832
+732 0.163209
+733 0.0723255
+734 0.167135
+735 0.179351
+736 0.068332
+737 0.042566
+738 0.025151
+739 0.0339815
+740 -0.015972
+741 0.0380515
+742 -0.129266
+743 0.030281
+744 -0.0576005
+745 -0.0116245
+746 -0.0272215
+747 0.158354
+748 -0.0368925
+749 0.281857
+750 0.125808
+751 0.089007
+752 0.068334
+753 0.109541
+754 -0.0030315
+755 -0.001721
+756 -0.0675155
+757 -0.057824
+758 -0.162166
+759 0.092918
+760 -0.206068
+761 -0.035738
+762 -0.105873
+763 -0.11355
+764 -0.0698315
+765 -0.304756
+766 -0.360736
+767 -0.343261
+768 -0.364615
+769 -0.476672
+770 -0.431354
+771 -0.33896
+772 -0.499728
+773 -0.409301
+774 -0.283779
+775 -0.285137
+776 -0.396747
+777 -0.157698
+778 -0.445427
+779 -0.251331
+780 -0.320066
+781 -0.376731
+782 -0.451715
+783 -0.324344
+784 -0.51494
+785 -0.252136
+786 -0.40921
+787 -0.340128
+788 -0.490598
+789 -0.371289
+790 -0.498748
+791 -0.463235
+792 -0.127615
+793 0.11142
+794 -0.110258
+795 0.149378
+796 -0.128924
+797 0.128838
+798 -0.0565165
+799 -0.007938
+800 -0.0287715
+801 0.094932
+802 -0.105842
+803 0.0126905
+804 -0.0078835
+805 -0.16225
+806 -0.074021
+807 -0.063843
+808 -0.19639
+809 -0.227812
+810 -0.127006
+811 -0.138561
+812 -0.224495
+813 -0.117485
+814 -0.341321
+815 -0.058533
+816 -0.272684
+817 -0.156103
+818 -0.238288
+819 -0.0498415
+820 -0.317336
+821 0.0157535
+822 -0.18028
+823 -0.189615
+824 -0.189098
+825 -0.233204
+826 -0.408666
+827 -0.335275
+828 -0.0071995
+829 0.16518
+830 0.021386
+831 0.119
+832 -0.022239
+833 0.216354
+834 0.075015
+835 0.091309
+836 0.078046
+837 0.041649
+838 -0.188512
+839 -0.069713
+840 -0.190139
+841 -0.245571
+842 -0.226997
+843 -0.165336
+844 -0.331886
+845 -0.200924
+846 -0.014768
+847 0.059358
+848 -0.11021
+849 0.0133795
+850 -0.291596
+851 0.0857125
+852 -0.107268
+853 -0.015396
+854 -0.120783
+855 -0.0271515
+856 -0.206266
+857 0.0726795
+858 -0.0138085
+859 0.0254655
+860 -0.125331
+861 -0.221051
+862 -0.424292
+863 -1.12624
+864 -0.13719
+865 0.0191645
+866 -0.033441
+867 0.081872
+868 -1.0778
+869 -0.012432
+870 -0.054734
+871 -0.034379
+872 -0.124849
+873 -1.38766
+874 -0.374279
+875 -0.28699
+876 -0.280309
+877 -0.291674
+878 -0.365002
+879 -0.26695
+880 -0.480584
+881 -0.322333
+882 -0.374574
+883 -0.328201
+884 -0.419666
+885 -0.271495
+886 -0.46961
+887 -0.338003
+888 -0.43914
+889 -0.384048
+890 -0.433662
+891 -0.284333
+892 -0.444184
+893 -0.168006
+894 -0.248616
+895 -0.278122
+896 -0.409718
+897 -0.216257
+898 -0.502942
+899 -0.312165
+900 0.108095
+901 0.1743
+902 0.155772
+903 0.310455
+904 0.0265125
+905 0.206658
+906 0.0402525
+907 0.109637
+908 0.0498185
+909 -0.139673
+910 -0.32718
+911 -0.184466
+912 -0.160754
+913 -0.275902
+914 -0.346394
+915 -0.182605
+916 -0.405007
+917 -0.336608
+918 -0.19999
+919 -0.207938
+920 -0.332424
+921 -0.127078
+922 -0.334857
+923 -0.139515
+924 -0.357414
+925 -0.306934
+926 -0.357596
+927 -1.29816
+928 0.393941
+929 -0.116629
+930 -0.184043
+931 -0.23113
+932 -0.257418
+933 -0.260678
+934 -0.448526
+935 -0.35295
+936 0.161185
+937 0.33218
+938 0.250345
+939 0.329715
+940 0.143448
+941 0.213722
+942 0.196448
+943 0.275979
+944 0.155593
+945 0.019795
+946 -0.141517
+947 -0.064316
+948 -0.161385
+949 -0.170026
+950 -0.1239
+951 -0.08891
+952 -0.247695
+953 -0.0934155
+954 0.116715
+955 0.149657
+956 0.0122135
+957 0.156707
+958 -0.0772655
+959 0.147833
+960 0.092252
+961 0.100139
+962 0.0231045
+963 0.02173
+964 -0.218077
+965 0.126393
+966 -0.0908775
+967 -0.0730585
+968 -0.084355
+969 -0.0165365
+970 -0.280512
+971 -0.108416
+972 -0.180441
+973 -0.151644
+974 -0.119987
+975 -0.041746
+976 -0.28313
+977 0.0180015
+978 -0.134978
+979 -0.11499
+980 -0.125175
+981 -0.169271
+982 -0.351781
+983 -0.126946
+984 -0.29474
+985 -0.310391
+986 -0.275843
+987 -0.25939
+988 -0.424623
+989 -0.414805
+990 -0.250941
+991 -0.159475
+992 -0.294015
+993 -0.0910255
+994 -0.413683
+995 -0.124367
+996 -0.237717
+997 -0.171681
+998 -0.238849
+999 -0.038064
+1000 -0.415894
+1001 -0.0584865
+1002 -0.16757
+1003 -0.231637
+1004 -0.282881
+1005 -0.185094
+1006 -0.401274
+1007 -0.182911
+1008 -0.244273
+1009 -0.179219
+1010 -0.26875
+1011 -0.0150955
+1012 -0.370331
+1013 -0.077489
+1014 -0.10434
+1015 -0.18628
+1016 -0.171316
+1017 -0.281019
+1018 -0.536531
+1019 -0.273988
+1020 -0.452086
+1021 -0.483047
+1022 -0.509725
+1023 -0.378717
+1024 -0.623433
+1025 -0.446595
+1026 -0.266742
+1027 -0.215723
+1028 -0.407129
+1029 -0.253796
+1030 -0.524279
+1031 -0.21372
+1032 -0.363813
+1033 -0.301378
+1034 -0.333518
+1035 -0.192872
+1036 -0.5103
+1037 -0.197911
+1038 -0.360317
+1039 -0.344968
+1040 -0.461394
+1041 -0.315628
+1042 -0.620183
+1043 -0.480866
+1044 0.096089
+1045 0.212299
+1046 0.097673
+1047 0.283862
+1048 -0.0161355
+1049 0.221436
+1050 0.161375
+1051 0.269863
+1052 0.231555
+1053 -0.008624
+1054 -0.101303
+1055 -0.0116425
+1056 -0.117916
+1057 -0.103234
+1058 -0.151352
+1059 -0.177516
+1060 -0.324225
+1061 -0.183106
+1062 -0.0832275
+1063 0.002506
+1064 -0.173924
+1065 -0.045228
+1066 -0.270512
+1067 -0.014962
+1068 -0.145937
+1069 -0.120889
+1070 -0.203554
+1071 -0.068124
+1072 -0.246841
+1073 0.0601165
+1074 -0.0265005
+1075 -0.097395
+1076 -0.173148
+1077 -0.1711
+1078 -0.337946
+1079 -0.230368
+1080 0.255589
+1081 0.354729
+1082 0.29331
+1083 0.486226
+1084 0.265089
+1085 0.409917
+1086 0.236718
+1087 0.243773
+1088 0.314904
+1089 0.159006
+1090 0.051866
+1091 0.114336
+1092 0.003192
+1093 -1.20068
+1094 -1.05242
+1095 0.0563245
+1096 -0.090888
+1097 0.0194435
+1098 0.21794
+1099 0.20344
+1100 0.0334635
+1101 0.261385
+1102 0.0096135
+1103 0.159653
+1104 0.178744
+1105 0.116943
+1106 0.165038
+1107 0.144971
+1108 0.0164035
+1109 0.18822
+1110 0.098435
+1111 0.110334
+1112 0.148949
+1113 0.0360425
+1114 -0.0830505
+1115 -0.07341
+1116 0.308564
+1117 0.343651
+1118 0.245128
+1119 0.544407
+1120 0.159333
+1121 0.426845
+1122 0.355427
+1123 0.374495
+1124 0.294633
+1125 0.230443
+1126 0.059711
+1127 0.0864305
+1128 0.024587
+1129 0.040739
+1130 0.00636
+1131 0.053162
+1132 -0.161375
+1133 -0.023456
+1134 0.183326
+1135 0.290933
+1136 0.0663915
+1137 0.317151
+1138 0.131519
+1139 0.29331
+1140 0.10504
+1141 0.315202
+1142 0.0904885
+1143 0.188154
+1144 -0.051029
+1145 0.253526
+1146 0.139605
+1147 0.110064
+1148 0.04501
+1149 0.0951775
+1150 -0.0426595
+1151 0.0704655
+1152 0.618216
+1153 0.672584
+1154 0.639771
+1155 0.863371
+1156 0.537775
+1157 0.696674
+1158 0.643609
+1159 0.659193
+1160 0.662914
+1161 0.668161
+1162 0.362679
+1163 0.578465
+1164 0.369507
+1165 0.354498
+1166 0.491219
+1167 0.477189
+1168 0.255952
+1169 0.325888
+1170 0.446897
+1171 0.387259
+1172 0.372349
+1173 0.450765
+1174 0.198036
+1175 0.393201
+1176 0.309405
+1177 0.358689
+1178 0.323445
+1179 0.716231
+1180 0.493889
+1181 0.684353
+1182 0.591917
+1183 0.55014
+1184 0.453869
+1185 0.568646
+1186 0.352624
+1187 0.430328
+1188 0.181758
+1189 0.331934
+1190 0.359998
+1191 0.438937
+1192 0.160874
+1193 0.324512
+1194 0.272737
+1195 0.2875
+1196 0.27161
+1197 0.157592
+1198 0.0534575
+1199 0.0765135
+1200 0.0155585
+1201 -0.085435
+1202 0.026105
+1203 0.068931
+1204 -0.132214
+1205 -0.05046
+1206 -0.034095
+1207 0.0343175
+1208 -0.0395475
+1209 0.0075155
+1210 -0.143579
+1211 0.013087
+1212 -0.0633895
+1213 0.0056675
+1214 -0.08702
+1215 0.108337
+1216 -0.010989
+1217 0.129622
+1218 0.074858
+1219 0.082398
+1220 0.0285725
+1221 0.047371
+1222 -0.246359
+1223 0.0518125
+1224 0.34179
+1225 0.51127
+1226 0.43935
+1227 0.543986
+1228 0.281187
+1229 0.480607
+1230 0.398851
+1231 0.44015
+1232 0.371013
+1233 0.279021
+1234 0.217161
+1235 0.357089
+1236 0.233028
+1237 0.261086
+1238 0.17958
+1239 0.2315
+1240 0.117714
+1241 0.202487
+1242 -0.0680245
+1243 -0.067843
+1244 -0.200515
+1245 0.0698765
+1246 -0.218206
+1247 -0.0064745
+1248 -0.082787
+1249 0.0029195
+1250 -0.112999
+1251 0.259931
+1252 0.0510215
+1253 0.239019
+1254 0.143163
+1255 0.27978
+1256 0.061899
+1257 0.147185
+1258 -0.015429
+1259 -0.0247045
+1260 0.266377
+1261 0.361414
+1262 0.313375
+1263 0.420554
+1264 0.212638
+1265 0.409271
+1266 0.247079
+1267 0.301184
+1268 0.209752
+1269 0.360994
+1270 0.178984
+1271 0.209946
+1272 0.154142
+1273 0.247011
+1274 0.17483
+1275 0.181452
+1276 0.0053475
+1277 0.18218
+1278 -0.06315
+1279 0.0880675
+1280 -0.165098
+1281 -0.028996
+1282 -0.129029
+1283 0.1019
+1284 -0.010899
+1285 0.063385
+1286 -0.004791
+1287 2.24374
+1288 1.94398
+1289 1.90917
+1290 0.090541
+1291 0.118498
+1292 -0.032549
+1293 0.151972
+1294 -0.113374
+1295 0.003419
+1296 1.18174
+1297 1.229
+1298 1.16668
+1299 1.47253
+1300 1.05661
+1301 1.26882
+1302 1.16499
+1303 1.27657
+1304 1.18719
+1305 0.900694
+1306 0.730899
+1307 0.977402
+1308 0.819049
+1309 0.705135
+1310 0.796359
+1311 0.919251
+1312 0.679448
+1313 0.928825
+1314 0.783247
+1315 0.770005
+1316 0.603776
+1317 0.864691
+1318 0.597233
+1319 0.829414
+1320 0.691882
+1321 0.839889
+1322 0.722032
+1323 0.847363
+1324 0.482824
+1325 0.69772
+1326 0.573425
+1327 0.657265
+1328 0.513319
+1329 0.615395
+1330 0.432013
+1331 0.59449
+1332 0.108832
+1333 0.174849
+1334 0.143206
+1335 0.306065
+1336 0.058153
+1337 0.304217
+1338 0.162323
+1339 0.262814
+1340 0.163132
+1341 0.060647
+1342 -0.137255
+1343 -0.126075
+1344 0.0498325
+1345 -0.136674
+1346 -0.0725455
+1347 -0.029586
+1348 -0.222853
+1349 -0.096888
+1350 -0.208356
+1351 -0.0914795
+1352 -0.264319
+1353 -0.127576
+1354 -0.203171
+1355 -0.073227
+1356 -0.157248
+1357 -0.0781535
+1358 -0.177341
+1359 -0.177241
+1360 -0.400591
+1361 -0.0942785
+1362 -0.224755
+1363 -0.193999
+1364 -0.288187
+1365 -0.228344
+1366 -0.425115
+1367 -0.251545
+1368 0.017757
+1369 0.051214
+1370 0.08413
+1371 0.285972
+1372 -0.0679975
+1373 0.113084
+1374 -0.001906
+1375 0.0797215
+1376 0.0891815
+1377 -0.271274
+1378 -0.458011
+1379 -0.270414
+1380 -0.44522
+1381 -0.429194
+1382 -0.485832
+1383 -0.37287
+1384 -0.549944
+1385 -0.347369
+1386 -0.257288
+1387 -0.156577
+1388 -0.292592
+1389 -0.270541
+1390 -0.397919
+1391 -0.205118
+1392 -0.295864
+1393 -0.196562
+1394 -0.35091
+1395 -0.149661
+1396 -0.324718
+1397 -0.0894805
+1398 -0.206969
+1399 -0.180522
+1400 -0.277355
+1401 -0.193188
+1402 -0.435925
+1403 -0.276971
+1404 -0.0254015
+1405 0.041046
+1406 0.069163
+1407 0.338117
+1408 -0.081343
+1409 0.254675
+1410 0.02535
+1411 0.078878
+1412 0.0995835
+1413 0.045121
+1414 -0.165658
+1415 0.0172675
+1416 -0.121472
+1417 -0.225268
+1418 -0.157319
+1419 -0.121973
+1420 -0.211038
+1421 -0.116378
+1422 -0.099775
+1423 -0.129087
+1424 -0.318956
+1425 -0.148541
+1426 -0.404587
+1427 -0.127514
+1428 -0.294984
+1429 -0.198367
+1430 -0.394857
+1431 -0.142381
+1432 -0.346716
+1433 -0.207262
+1434 -0.253702
+1435 -0.184705
+1436 -0.421426
+1437 -0.258775
+1438 -0.491534
+1439 -0.412162
