Index: /trunk/MagicSoft/Mars/macros/calibration.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/calibration.C	(revision 5682)
+++ /trunk/MagicSoft/Mars/macros/calibration.C	(revision 5683)
@@ -59,6 +59,6 @@
 #include "MJPedestal.h"
 #include "MJCalibration.h"
-#include "MJExtractSignal.h"
 #include "MJExtractCalibTest.h"
+#include "MJCalibrateSignalFromOutside.h"
 #include "MRunIter.h"
 #include "MStatusDisplay.h"
@@ -69,4 +69,5 @@
 #include "MArray.h"
 #include "MParContainer.h"
+#include "MGeomCamMagic.h"
 
 #include "TStyle.h"
@@ -98,4 +99,13 @@
 static  const Int_t calrun2 = 0;
 //
+// the default start data run 
+//
+static const Int_t   datrun1 = 39900;
+//
+// the default last calibration run (if 0, only one run is taken, otherwise consecutive runs 
+// between calrun1 and calrun2)
+//
+static  const Int_t datrun2 = 0;
+//
 // A switch to output debugging information about Objects use
 //
@@ -120,20 +130,21 @@
 // Tell if you want to test the intensity calibration
 //
-static Bool_t useIntensity = kFALSE;
+static Bool_t useIntensity  = kFALSE;
 //
 // Tell if you want to store and read the F0 and F1- files
 //
-static Bool_t usestorage   = kFALSE;
+static Bool_t usestorage   = kTRUE;
 //
 // Tell which extractor you want to use. The flags are counted according 
 // to the extractor-TDAS
 // 
-static Int_t extractorflag = 1;
+static Int_t extractorflag = 33;
 //
 Int_t calibration(const UInt_t extflag=extractorflag, const Int_t prun=pedrun, 
-                  const Int_t crun1=calrun1, const Int_t crun2=calrun2)
+                  const Int_t crun1=calrun1, const Int_t crun2=calrun2, 
+                  const Int_t drun1=datrun1, const Int_t drun2=datrun2)
 {
 
-  MExtractor *extractor = getExtractor(extflag);
+  MExtractor *extractor = getExtractor(extflag==33 ? 32 : extflag);
 
   if (!extractor)
@@ -164,4 +175,5 @@
     cruns.AddRuns(crun1,crun2,inpath);
 
+  
   MStatusDisplay *display = NULL;
 
@@ -179,6 +191,8 @@
   // Hand over to the jobs a QE Cam with Cornings initialized
   // 
+  MGeomCamMagic          geomcam;
   MCalibrationQECamMagic qecam;
   MBadPixelsCam          badcam;
+  badcam.InitSize(geomcam.GetNumPixels());
   //
   // If you want to exclude pixels from the beginning, read 
@@ -193,5 +207,5 @@
 
   MJPedestal pedloop1;
-  pedloop1.SetNoStorage(!usestorage);
+  pedloop1.SetNoStorage();
   pedloop1.SetEnvDebug(debug);
   pedloop1.SetExtractor(extractor);
@@ -218,9 +232,9 @@
     {
       /***********************************************************/
-      /* NEEDE FOR SECOND LOOP: EXTRACTOR RESOLUTION COMPUTATION */
+      /* NEEDED FOR SECOND LOOP: EXTRACTOR RESOLUTION COMPUTATION */
       /***********************************************************/
       
       pedloop2.SetUseData();
-      pedloop2.SetNoStorage(!usestorage);
+      pedloop2.SetNoStorage();
       pedloop2.SetEnvDebug(debug);
       pedloop2.SetExtractor(extractor);
@@ -239,5 +253,4 @@
         return 1;
       
-      extractor->SetNoiseCalculation(kFALSE);
       calloop.SetExtractorCam(pedloop2.GetPedestalCam());
     }
@@ -252,4 +265,5 @@
   //  calloop.SetHistsStorage();
   calloop.SetNoStorage(!usestorage);
+  calloop.SetRelTimeCalibration(kTRUE);
   //
   // If you want to set a colour explicitely from outside (not recommanded!)
@@ -277,9 +291,11 @@
   calloop.SetUsePINDiode(pindiode);
   calloop.SetQECam(qecam);
-  calloop.SetBadPixels(pedloop1.GetBadPixels());
+  calloop.SetBadPixels(badcam);
 
   if (!calloop.Process(pedcam))
     return 2;
 
+  //  return 0;
+
   //
   // The next lines are the use the Print() function and have 
@@ -288,7 +304,7 @@
   if (debug)
     {
-      MCalibrationChargeCam &chargecam   = calloop.GetCalibrationCam();
       MCalibrationQECam     &nqecam      = calloop.GetQECam();
       MBadPixelsCam         &badbad      = calloop.GetBadPixels();
+      MCalibrationChargeCam &chargecam   = calloop.GetCalibrationCam();
       chargecam.Print();
       nqecam.Print();
@@ -318,7 +334,16 @@
         return 3;
       
-      return 4;
-      
-    }
+   }
+
+  if (drun1 == 0)
+    return 4;
+
+  MRunIter druns;
+
+  if (drun2==0)
+    druns.AddRun(drun1,inpath);
+  else
+    druns.AddRuns(drun1,drun2,inpath);
+
 
   /********************************************************************/
@@ -326,14 +351,21 @@
   /********************************************************************/
 
-  MJExtractSignal pedphotloop;
-
-  pedphotloop.SetExtractor(extractor);
-  pedphotloop.SetInput(&pruns);
-  pedphotloop.SetOutputPath(outpath);
+  if (extflag == 33)
+    {
+      delete extractor;
+      extractor = getExtractor(28);
+    }
+  
+  MJCalibrateSignalFromOutside calibloop;
+
+  calibloop.SetExtractor(extractor);
+  calibloop.SetInput(&druns);
+  //  calibloop.SetOutputPath(outpath);
   if (useDisplay)
-    pedphotloop.SetDisplay(display);
-  pedphotloop.SetBadPixels(calloop.GetBadPixels());
-  
-  if (!pedphotloop.ProcessP(pedloop1.GetPedestalCam(),calloop.GetCalibrationCam(),calloop.GetQECam()))
+    calibloop.SetDisplay(display);
+  calibloop.SetBadPixels(calloop.GetBadPixels());
+  calibloop.SetNoStorage(!usestorage);
+  
+  if (!calibloop.ProcessFile(pedloop1.GetPedestalCam(),timeandcharge ? pedloop2.GetPedestalCam() : pedloop1.GetPedestalCam(), calloop.GetCalibrationCam(),calloop.GetQECam(), calloop.GetRelTimeCam()))
     return 5;
 
@@ -347,4 +379,5 @@
     gObjectTable->Print();
 
+
   return 0;
 }
@@ -355,15 +388,21 @@
     gLog << "Usage:" << endl;
     gLog << endl;
-    gLog << "   calibration [ped.run nr.] [first cal.run nr.] [last cal.run nr.]" << endl ;
+    gLog << "   calibration [ped.run nr.] [first cal.run nr.] [last cal.run nr.] [first dat.run nr.] [last dat.run nr.]" << endl ;
     gLog << endl;
     gLog << "   ped.run.nr:        Run number of the pedestal file." << endl;
     gLog << "   first cal.run nr.: Run number of the first calibration file." << endl;
     gLog << "   last  cal.run nr.: Run number of the last  calibration file." << endl;
-    gLog << endl;
-    gLog << "All calibration runs between (first cal.run nr.) and (last  cal.run nr.) will be used" << endl;
+    gLog << "   first dat.run nr.: Run number of the first data file to be calibrated." << endl;
+    gLog << "   last  dat.run nr.: Run number of the last  data file to be calibrated." << endl;
+    gLog << endl;
+    gLog << "All calibration runs between (first cal.run nr.) and (last cal.run nr.) will be used" << endl;
     gLog << "If last.cal.run.nr is 0 (default), only one calibration run is taken"                  << endl;
+    gLog << endl;
+    gLog << "All data runs between (first dat.run nr.) and (last dat.run nr.) will be used" << endl;
+    gLog << "If last.dat.run.nr is 0 (default), only one data run is taken"                  << endl;
     gLog << endl;
     gLog << "Additional Options: " << endl;
     gLog << "     --extractor=#    Choose one of the following possible extractors (integer)" << endl;
+    gLog << "                      (default: Nr. 33)                                        " << endl;
     gLog << endl;
     gLog << "    Nr.    Extractor   Parameters " << endl;
@@ -372,5 +411,5 @@
     gLog << "           with the following parameters, if 'maxbin' defines the mean position" << endl;
     gLog << "           of the High-Gain FADC slice carrying the pulse maximum: " << endl;
-    gLog << "     1:           SetRange('maxbin}}-1,'maxbin}}+2,'maxbin}}+0.5,'maxbin}}+3.5) " << endl;
+    gLog << "     1:           SetRange('maxbin'-1,'maxbin'+2,'maxbin'+0.5,'maxbin'+3.5) " << endl;
     gLog << "     2:           SetRange('maxbin'-1,'maxbin'+2,'maxbin'-0.5,'maxbin'+4.5)" << endl;
     gLog << "     3:           SetRange('maxbin'-2,'maxbin'+3,'maxbin'-0.5,'maxbin'+4.5)" << endl;
@@ -415,8 +454,5 @@
     gLog << "     31:          SetNameWeightsFile('msignal/cosmics_weights_logain4.dat')" << endl;
     gLog << "     32:          SetNameWeightsFile('msignal/calibration_weights_UV.dat')" << endl;
-    gLog << "     33:          SetNameWeightsFile('msignal/calibration_weights_UV4.dat')" << endl;
-    gLog << "     34:          SetNameWeightsFile('msignal/calibration_weights_UV_logain6.dat')" << endl;
-    gLog << "     35:          SetNameWeightsFile('msignal/calibration_weights_UV_logain4.dat')" << endl;
-    gLog << "     36:  Real Fit: (not yet implemented)" << endl;
+    gLog << "     33:          Use calibration weights for calibration events and cosmics weights for data events" << endl;
     gLog << endl;
     gLog << "     --inpath=#          Find the data in inpath"                      << endl;
Index: /trunk/MagicSoft/Mars/mjobs/JobsLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/JobsLinkDef.h	(revision 5682)
+++ /trunk/MagicSoft/Mars/mjobs/JobsLinkDef.h	(revision 5683)
@@ -12,4 +12,5 @@
 #pragma link C++ class MJCalibration+;
 #pragma link C++ class MJCalibrateSignal+;
+#pragma link C++ class MJCalibrateSignalFromOutside+;
 #pragma link C++ class MJExtractSignal+;
 #pragma link C++ class MJExtractCalibTest+;
Index: /trunk/MagicSoft/Mars/mjobs/MJCalibrateSignalFromOutside.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MJCalibrateSignalFromOutside.cc	(revision 5683)
+++ /trunk/MagicSoft/Mars/mjobs/MJCalibrateSignalFromOutside.cc	(revision 5683)
@@ -0,0 +1,346 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//  MJCalibrateSignalFromOutside
+//
+// This class is reading the output written by callisto. It calibrates
+// signal and time.
+//
+// The signal and time extractors are read from the callisto-output. In
+// pricipal you could overwrite these default using the resource file,
+// but this is NOT recommended!
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MJCalibrateSignalFromOutside.h"
+
+#include <TEnv.h>
+#include <TFile.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MDirIter.h"
+#include "MRunIter.h"
+#include "MParList.h"
+#include "MTaskList.h"
+#include "MEvtLoop.h"
+
+#include "MStatusDisplay.h"
+
+#include "MGeomCam.h"
+#include "MHCamEvent.h"
+#include "MPedestalCam.h"
+#include "MBadPixelsCam.h"
+
+#include "MCalibrationQECam.h"
+#include "MCalibrationBlindCam.h"
+#include "MCalibrationChargeCam.h"
+#include "MCalibrationRelTimeCam.h"
+#include "MCalibrationChargePINDiode.h"
+
+#include "MReadReports.h"
+#include "MReadMarsFile.h"
+#include "MRawFileRead.h"
+#include "MGeomApply.h"
+#include "MMcPedestalCopy.h"
+#include "MPointingPosCalc.h"
+#include "MPedCalcFromLoGain.h"
+#include "MExtractor.h"
+#include "MTaskEnv.h"
+#include "MCalibrateData.h"
+#include "MCalibrateRelTimes.h"
+#include "MBadPixelsMerge.h"
+#include "MBadPixelsCalc.h"
+#include "MBadPixelsTreat.h"
+#include "MFillH.h"
+#include "MWriteRootFile.h"
+
+ClassImp(MJCalibrateSignalFromOutside);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default constructor. 
+//
+// Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
+//
+MJCalibrateSignalFromOutside::MJCalibrateSignalFromOutside(const char *name, const char *title)
+    : fIsDataCheck(kFALSE), fGeometry("MGeomCamMagic")
+{
+    fName  = name  ? name  : "MJCalibrateSignalFromOutside";
+    fTitle = title ? title : "Tool to calibrate data";
+}
+
+Bool_t MJCalibrateSignalFromOutside::WriteResult()
+{
+    if (fPathOut.IsNull())
+    {
+        *fLog << inf << "No output path specified via SetPathOut - no output written." << endl;
+        return kTRUE;
+    }
+
+    const TString oname = Form("%s/signal%06d.root", (const char*)fPathOut, fSequence.GetSequence());
+
+    *fLog << inf << "Writing to file: " << oname << endl;
+
+    TFile file(oname, "RECREATE");
+
+    *fLog << inf << " - MStatusDisplay..." << flush;
+    if (fDisplay && fDisplay->Write()<=0)
+    {
+        *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
+        return kFALSE;
+    }
+    *fLog << inf << "ok." << endl;
+
+    return kTRUE;
+}
+
+Bool_t MJCalibrateSignalFromOutside::ProcessFile(MPedestalCam &pedcamab, MPedestalCam &pedcamrms, MCalibrationChargeCam &chargecam, MCalibrationQECam &qecam, MCalibrationRelTimeCam &relcam, Byte_t filetype)
+{
+    // --------------------------------------------------------------------------------
+
+    *fLog << inf;
+    fLog->Separator(GetDescriptor());
+
+    *fLog << "Calibrate data from ";
+    *fLog << "Runs " << fRuns->GetRunsAsString() << endl;
+    *fLog << endl;
+
+    MDirIter iter;
+
+    *fLog << all;
+    if (fExtractor)
+    {
+        *fLog << underline << "Signal Extractor found in calibration file" << endl;
+        fExtractor->Print();
+        *fLog << endl;
+    }
+    else
+      {
+        *fLog << inf << "No Signal Extractor: ExtractSignal in file." << endl;
+        return kFALSE;
+      }
+    
+    fExtractor->SetPedestals(&pedcamab);
+
+    // Setup Parlist
+    MParList plist;
+    plist.AddToList(this); // take care of fDisplay!
+    plist.AddToList(&fBadPixels);
+    plist.AddToList(&pedcamrms);
+    plist.AddToList(&chargecam);
+    plist.AddToList(&qecam);
+    plist.AddToList(&relcam);
+
+    // Setup Tasklist
+    MTaskList tlist;
+    plist.AddToList(&tlist);
+
+    MReadReports readreal;
+    readreal.AddTree("Events", "MTime.", kTRUE);
+    readreal.AddTree("Trigger");
+    readreal.AddTree("Camera");
+    readreal.AddTree("Drive");
+    readreal.AddTree("CC");
+    readreal.AddTree("Currents");
+
+    //    MReadMarsFile read("Events");
+    //    read.DisableAutoScheme();
+    MRawFileRead rawread(NULL);
+    if (IsDataCheck())
+        rawread.AddFiles(*fRuns);
+    else
+      {
+        //        read.AddFiles(*fRuns);
+        readreal.AddFiles(*fRuns);
+      }
+
+    MGeomApply             apply; // Only necessary to create geometry
+    apply.SetGeometry(fGeometry);
+    MBadPixelsMerge        merge(&fBadPixels);
+
+    MPedCalcFromLoGain     pedlo1("MPedCalcMeanFromLoGain");
+    pedlo1.SetPedestalUpdate(kTRUE);
+    pedlo1.SetPedestalsOut(&pedcamab);
+
+    MPedCalcFromLoGain     pedlo2("MPedCalcRmsFromLoGain");
+    pedlo2.SetPedestalUpdate(kTRUE);
+    pedlo2.SetPedestalsIn(&pedcamab);
+    pedlo2.SetPedestalsOut(&pedcamrms);
+
+    if (fExtractor->InheritsFrom("MExtractTimeAndCharge"))
+      pedlo2.SetExtractor((MExtractTimeAndCharge*)fExtractor);
+
+    MMcPedestalCopy        pcopy;
+    MTaskEnv taskenv1("ExtractSignal");
+    taskenv1.SetDefault(fExtractor);
+    MCalibrateData         calib;
+    if (filetype==3) // MC file
+    {
+        calib.SetCalibrationMode(MCalibrateData::kFfactor);
+        calib.SetPedestalFlag(MCalibrateData::kRun);
+    }
+    else
+    {
+        calib.SetPedestalCamMean(&pedcamab);
+        calib.SetPedestalCamRms(&pedcamrms);
+        calib.SetPedestalFlag(MCalibrateData::kEvent);
+    }
+
+    MCalibrateRelTimes     caltm;
+    MBadPixelsCalc         bpcal;
+    MBadPixelsTreat        treat;
+
+    MHCamEvent evt0(0, "PedFLG",      "Pedestal from Lo Gain;;P [fadc/sl]");
+    MHCamEvent evt1(2, "PedRmsFLG",   "Pedestal RMS from Lo Gain;;\\sigma_{p} [fadc/sl]");
+    MHCamEvent evt2(0, "Extra'd",     "Extracted Signal;;S [fadc/sl]");
+    MHCamEvent evt3(0, "PedPhot",     "Calibrated Pedestal;;P [\\gamma]");
+    MHCamEvent evt4(1, "PedRMS",      "Calibrated Pedestal RMS;;\\sigma_{p} [\\gamma]");
+    MHCamEvent evt5(0, "Interp'd",    "Interpolated Signal;;S [\\gamma]");
+    MHCamEvent evt6(2, "Unsuitable",  "Unsuitable event ratio;;%");
+    MHCamEvent evt7(0, "Times",       "Arrival Time;;T [slice]");
+    evt0.EnableVariance();
+    evt1.EnableVariance();
+    evt2.EnableVariance();
+    evt3.EnableVariance();
+    evt4.EnableVariance();
+    evt5.EnableVariance();
+    evt7.EnableVariance();
+
+    MFillH fill0(&evt0, &pedcamab,             "FillPedFLG");
+    MFillH fill1(&evt1, "MPedestalCam",        "FillPedRmsFLG");
+    MFillH fill2(&evt2, "MExtractedSignalCam", "FillExtracted");
+    MFillH fill3(&evt3, "MPedPhotCam",         "FillPedPhot");
+    MFillH fill4(&evt4, "MPedPhotCam",         "FillPedRMS");
+    MFillH fill5(&evt5, "MCerPhotEvt",         "FillInterpolated");
+    MFillH fill6(&evt6, "MBadPixelsCam",       "FillUnsuitable");
+    MFillH fill7(&evt7, "MArrivalTime",        "FillTimes");
+
+    MWriteRootFile write(2, Form("%s{s/_D_/_Y_}", fPathOut.Data()), fOverwrite);
+    // Run Header
+    write.AddContainer("MRawRunHeader",       "RunHeaders");
+    write.AddContainer("MBadPixelsCam",       "RunHeaders");
+    write.AddContainer("MGeomCam",            "RunHeaders");
+    // Monte Carlo Headers
+    write.AddContainer("MMcTrigHeader",       "RunHeaders", kFALSE);
+    write.AddContainer("MMcConfigRunHeader",  "RunHeaders", kFALSE);
+    write.AddContainer("MMcCorsikaRunHeader", "RunHeaders", kFALSE);
+    // Monte Carlo
+    write.AddContainer("MMcEvt",              "Events", kFALSE);
+    write.AddContainer("MMcTrig",             "Events", kFALSE);
+    // Data
+    write.AddContainer("MCerPhotEvt",         "Events");
+    write.AddContainer("MPedPhotCam",         "Events");
+    write.AddContainer("MTime",               "Events", kFALSE);
+    write.AddContainer("MRawEvtHeader",       "Events");
+    write.AddContainer("MArrivalTime",        "Events");
+    // Slow-Control: Current
+    write.AddContainer("MTimeCurrents",       "Currents", kFALSE);
+    write.AddContainer("MCameraDC",           "Currents", kFALSE);
+    write.AddContainer("MReportCurrents",     "Currents", kFALSE);
+    // Slow-Control: Camera
+    write.AddContainer("MReportCamera",       "Camera", kFALSE);
+    write.AddContainer("MTimeCamera",         "Camera", kFALSE);
+    write.AddContainer("MCameraAUX",          "Camera", kFALSE);
+    write.AddContainer("MCameraCalibration",  "Camera", kFALSE);
+    write.AddContainer("MCameraCooling",      "Camera", kFALSE);
+    write.AddContainer("MCameraHV",           "Camera", kFALSE);
+    write.AddContainer("MCameraLV",           "Camera", kFALSE);
+    write.AddContainer("MCameraLids",         "Camera", kFALSE);
+    // Slow-Control: Trigger
+    write.AddContainer("MReportTrigger",      "Trigger", kFALSE);
+    write.AddContainer("MTimeTrigger",        "Trigger", kFALSE);
+    // Slow-Control: Drive
+    write.AddContainer("MPointingPos",        "Drive", kFALSE);
+    write.AddContainer("MReportDrive",        "Drive", kFALSE);
+    write.AddContainer("MTimeDrive",          "Drive", kFALSE);
+    // Slow-Control: Central Control
+    write.AddContainer("MReportCC",           "CC", kFALSE);
+    write.AddContainer("MTimeCC",             "CC", kFALSE);
+
+    // Now setup tasklist for events
+    MTaskList tlist2;
+    tlist2.AddToList(&apply);
+    tlist2.AddToList(&merge);
+    if (filetype==3)
+        tlist2.AddToList(&pcopy);
+    else
+    {
+        tlist2.AddToList(&pedlo1);
+        tlist2.AddToList(&pedlo2);
+    }
+    tlist2.AddToList(&fill0);
+    tlist2.AddToList(&fill1);
+    tlist2.AddToList(&taskenv1);
+    tlist2.AddToList(&fill2);
+    tlist2.AddToList(&calib);
+    if (&relcam)
+      tlist2.AddToList(&caltm);
+    tlist2.AddToList(&fill3);
+    tlist2.AddToList(&bpcal);
+    tlist2.AddToList(&treat);
+    tlist2.AddToList(&fill4);
+    tlist2.AddToList(&fill5);
+    tlist2.AddToList(&fill6);
+    tlist2.AddToList(&fill7);
+
+    // Setup List for Drive-tree
+    MPointingPosCalc pcalc;
+
+    // Now setup main tasklist
+    tlist.AddToList(IsDataCheck() ? (MTask*)&rawread : (MTask*)&readreal);
+    tlist.AddToList(&tlist2, IsDataCheck()?"All":"Events");
+    if (!IsDataCheck())
+        tlist.AddToList(&pcalc, "Drive");
+    tlist.AddToList(&write);
+
+    // Create and setup the eventloop
+    MEvtLoop evtloop(fName);
+    evtloop.SetParList(&plist);
+    evtloop.SetDisplay(fDisplay);
+    evtloop.SetLogStream(fLog);
+    if (!SetupEnv(evtloop))
+        return kFALSE;
+
+    // Execute first analysis
+    if (!evtloop.Eventloop(fMaxEvents))
+    {
+        *fLog << err << GetDescriptor() << ": Failed." << endl;
+        return kFALSE;
+    }
+
+    tlist.PrintStatistics();
+
+    if (!WriteResult())
+        return kFALSE;
+
+    *fLog << all << GetDescriptor() << ": Done." << endl;
+    *fLog << endl << endl;
+
+    return kTRUE;
+}
Index: /trunk/MagicSoft/Mars/mjobs/MJCalibrateSignalFromOutside.h
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MJCalibrateSignalFromOutside.h	(revision 5683)
+++ /trunk/MagicSoft/Mars/mjobs/MJCalibrateSignalFromOutside.h	(revision 5683)
@@ -0,0 +1,75 @@
+#ifndef MARS_MJCalibrateSignalFromOutside
+#define MARS_MJCalibrateSignalFromOutside
+
+#ifndef MARS_MJob
+#include "MJob.h"
+#endif
+#ifndef MARS_MBadPixelsCam
+#include "MBadPixelsCam.h"
+#endif
+
+class TEnv;
+class TList;
+
+class MTask;
+class MParList;
+class MGeomCam;
+class MSequence;
+class MExtractor;
+class MPedestalCam;
+class MBadPixelsCam;
+class MRunIter;
+class MCalibrationChargeCam;
+class MCalibrationQECam;
+class MCalibrationRelTimeCam;
+
+class MJCalibrateSignalFromOutside : public MJob
+{
+private:
+    Bool_t fIsDataCheck;
+    TString fGeometry;                // Class name geometry
+    
+    MRunIter       *fRuns;            // Data files
+    MExtractor     *fExtractor;       // Signal extractor 
+
+    MBadPixelsCam  fBadPixels;        // Bad Pixels cam, can be set from previous runs  
+    
+    enum  Storage_t                    // Possible devices for calibration
+      {
+        kNoStorage,
+        kHistsStorage
+      };                              // Possible flags for the storage of results
+    
+    Byte_t fStorage;                  // Bit-field for chosen storage type
+
+    Bool_t IsNoStorage    () const { return TESTBIT(fStorage,kNoStorage);    }
+    Bool_t IsHistsStorage () const { return TESTBIT(fStorage,kHistsStorage); }
+
+    Bool_t WriteResult();
+
+    Bool_t IsDataCheck() const { return fIsDataCheck; }
+    void SetDataCheck(Bool_t b) { fIsDataCheck = b; }
+
+public:
+    MJCalibrateSignalFromOutside(const char *name=NULL, const char *title=NULL);
+
+    //    const char* GetOutputFile() const;
+
+    void SetBadPixels  ( const MBadPixelsCam &bad)     { bad.Copy(fBadPixels); }
+    void SetExtractor  ( MExtractor* ext)              { fExtractor = ext;     }
+    void SetInput     ( MRunIter *iter)               { fRuns = iter;         }
+
+    // Camera Geomtry
+    void SetGeometry(const char *geom) { fGeometry = geom; }
+  
+    // Storage
+    void SetNoStorage    ( const Bool_t b=kTRUE ) { b ? SETBIT(fStorage,kNoStorage)    : CLRBIT(fStorage,kNoStorage); }
+    void SetHistsStorage ( const Bool_t b=kTRUE ) { b ? SETBIT(fStorage,kHistsStorage) : CLRBIT(fStorage,kHistsStorage); }
+    
+    Bool_t ProcessFile(MPedestalCam &camab, MPedestalCam &cam, MCalibrationChargeCam &chargecam,
+                       MCalibrationQECam &qecam, MCalibrationRelTimeCam &relcam, Byte_t filetype=2);
+
+    ClassDef(MJCalibrateSignalFromOutside, 0) // Tool to create a pedestal file (MPedestalCam)
+};
+
+#endif
Index: /trunk/MagicSoft/Mars/mjobs/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/Makefile	(revision 5682)
+++ /trunk/MagicSoft/Mars/mjobs/Makefile	(revision 5683)
@@ -30,4 +30,5 @@
            MJCalibration.cc \
            MJCalibrateSignal.cc \
+           MJCalibrateSignalFromOutside.cc \
            MJExtractSignal.cc \
            MJExtractCalibTest.cc
