Index: trunk/MagicSoft/Mars/macros/PedCalcFromData.C
===================================================================
--- trunk/MagicSoft/Mars/macros/PedCalcFromData.C	(revision 4356)
+++ trunk/MagicSoft/Mars/macros/PedCalcFromData.C	(revision 4356)
@@ -0,0 +1,200 @@
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// Description: Macro that uses MPedCalcFromData to evaluate Pedestals from//
+//              Data Runs.                                                 //
+// Author:      Josep Flix (jflix@ifae.es)                                 //
+// Date:        25/06/2004                                                 //
+//                                                                         // 
+/////////////////////////////////////////////////////////////////////////////
+
+void PedCalcFromData()
+{
+
+    gROOT->Reset();
+    gStyle->SetCanvasColor(0);
+    gStyle->SetCanvasBorderMode(0);
+    gStyle->SetPadBorderMode(0);
+    gStyle->SetFrameBorderMode(0);
+    gStyle->SetOptStat(0000000);
+    gStyle->SetPalette(1);
+
+    TString pedfile("20040422_23229_P_Mrk421_E.root");
+    TString datafile("20040422_23230_D_Mrk421_E.root");
+    
+    gStyle->SetOptFit(0);
+    gStyle->SetOptStat(0000);
+    
+    MParList       plist;
+    MTaskList      tlist;
+    
+    MPedestalCam   cam;  
+    plist.AddToList(&cam);
+    
+    plist.AddToList(&tlist);
+    
+    MReadMarsFile read("Events", "/home/pepe/DATA_REAL/Mkn421/"+pedfile);
+    read.DisableAutoScheme();    
+    MGeomApply      geomapl;
+    MExtractFixedWindow    extractor;   
+    extractor.SetRange(2,14,4,14);
+   
+    MPedCalcPedRun ped;
+    ped.SetWindowSize(12);
+    ped.SetRange(2,14);
+    
+    tlist.AddToList(&read);
+    tlist.AddToList(&geomapl);
+    tlist.AddToList(&ped); 
+    
+    MEvtLoop evtloop;
+    
+    if (!tlist.PreProcess(&plist))
+	return;
+    
+    while (tlist.Process())
+    {
+    }
+    tlist.PostProcess();     
+    
+    
+    // ---------------------------------------------------------------
+    // 2nd evt loop
+    // ---------------------------------------------------------------
+
+    c1 = new TCanvas("c1","c1",0,0,600,300);
+    c1->Divide(2,1);
+    c1->SetBorderMode(0);
+    
+    TH2D *plot1 = new TH2D("","",1,0.1,175000,1,8,15);
+    TH2D *plot2 = new TH2D("","",1,0.1,175000,1,1,40);
+    c1->cd(1);
+    plot1->Draw();
+    c1->cd(2);
+    plot2->Draw();
+
+    Int_t COUNT=0;
+    
+    for (int j = 0; j < 6 ; j++){
+
+	if (j == 1)
+	    TString datafile("20040422_23231_D_Mrk421_E.root");
+	if (j == 2)
+	    TString datafile("20040422_23233_D_Mrk421_E.root");
+	if (j == 3)
+	    TString datafile("20040422_23234_D_Mrk421_E.root");
+	if (j == 4)
+	    TString datafile("20040422_23236_D_Mrk421_E.root");
+	if (j == 5)
+	    TString datafile("20040422_23237_D_Mrk421_E.root");
+
+	MParList  plist2;
+	MTaskList tlist2;
+	plist2.AddToList(&tlist2);
+	plist2.AddToList(&cam);
+	
+	MGeomCam *geomcam = (MGeomCam*)plist->FindObject("MGeomCam");
+	
+	MReadMarsFile read2("Events");
+	read2.DisableAutoScheme();
+    
+	read2.AddFile("/home/pepe/DATA_REAL/Mkn421/"+datafile);
+	MGeomApply        apply2;
+	
+	MPedCalcFromData  ped2;
+	ped2.SetDumpEvents(500);
+	ped2.SetLoRange(2,14);
+	ped2.SetHighGainThreshold(50);
+	
+	tlist2.AddToList(&read2);
+	tlist2.AddToList(&apply2);
+	tlist2.AddToList(&ped2);
+	
+	MEvtLoop evtloop2;
+	evtloop2.SetParList(&plist2);
+	
+	if (!tlist2.PreProcess(&plist2))
+	    return;
+	
+	TArrayD PedMean[577];
+	TArrayD PedRms[577];
+	for (int i = 0; i < 577 ; i++){
+	    PedMean[i].Set(20001);
+	    PedRms[i].Set(20001);
+	};
+	Double_t x[20001];
+	Double_t y[20001];
+	Int_t Cont = 0;
+	Int_t HOT = 0;
+	
+	while (tlist2.Process())
+	{
+	    
+	    COUNT++;
+	    
+	    if (read2.GetNumExecutions()==1 || read2.GetNumExecutions()%500==0){
+		
+		x[Cont] = COUNT;
+		for (int i = 1; i < 577; i++){
+		    
+		    PedMean[i](Cont) = cam[i]->GetPedestal();
+		    PedRms[i](Cont) = cam[i]->GetPedestalRms();
+		    
+		};
+		Cont++;
+	    };
+//         if (read2.GetNumExecutions() == 5000) break;
+	}
+	
+	tlist2.PostProcess();
+	cout << "EXEC = " << read2.GetNumExecutions() << '\t' << HOT << endl;
+	
+	for (int i = 1; i < 577; i++){
+	    
+	    if ( i == 8 || i ==146 || i ==200 || i ==269 || i==279 || i==400 || i==26 || i==439 || i==490 || i==39){
+		
+		for (int k = 0 ; k < 20000; k++)
+		    y[k] = PedMean[i](k);
+		
+		c1->cd(1);
+		
+		TGraph *graph1 = new TGraph(Cont,x,y);
+		graph1->SetLineColor((int)i/3);
+		graph1->SetMarkerColor((int)i/3);
+		graph1->SetMarkerSize(.4);
+		graph1->SetMarkerStyle(20);
+		graph1->Draw("PL");
+		
+		c1->cd(2);
+		for (int k = 0 ; k < 20000; k++)
+		    y[k] = PedRms[i](k);
+		
+		TGraph *graph2 = new TGraph(Cont,x,y);
+		graph2->SetMarkerSize(.4);
+		graph2->SetLineColor((int)i/3);
+		graph2->SetMarkerStyle(20);
+		graph2->SetMarkerColor((int)i/3);
+		graph2->Draw("PL");
+		
+		Char_t tit[100];
+		sprintf(tit,"Pixel %i",i);
+		TLatex *pix = new TLatex(20000.,38.-1.*HOT,tit);
+		pix->SetTextColor((int)i/3);
+		pix->SetTextSize(.03);
+		pix->Draw("");
+		HOT++;
+	    };
+	    
+	};
+	
+	TLine *line2 = new TLine(x[Cont-1],1.,x[Cont-1],40.);
+	line2->SetLineStyle(2);
+	TLine *line1 = new TLine(x[Cont-1],8.,x[Cont-1],15.);
+	line1->SetLineStyle(2);
+	c1->cd(1);
+	line1->Draw("");
+	c1->cd(2);
+	line2->Draw("");
+	
+    };    
+}
Index: trunk/MagicSoft/Mars/mpedestal/MPedCalcFromData.cc
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MPedCalcFromData.cc	(revision 4356)
+++ trunk/MagicSoft/Mars/mpedestal/MPedCalcFromData.cc	(revision 4356)
@@ -0,0 +1,202 @@
+/* ======================================================================== *\
+!
+! *
+! * 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 expressed
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Josep Flix 06/2004 <mailto:jflix@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+//   MPedCalcFromData                                                      //
+//                                                                         //
+//  Input Containers:                                                      //
+//   MRawEvtData                                                           //
+//                                                                         //
+//  Output Containers:                                                     //
+//   MPedestalCam                                                          //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#include "MPedCalcFromData.h"
+#include "MExtractor.h"
+
+#include "MParList.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MRawRunHeader.h"  
+#include "MRawEvtPixelIter.h"
+#include "MRawEvtData.h"
+
+#include "MPedestalPix.h"
+#include "MPedestalCam.h"
+
+ClassImp(MPedCalcFromData);
+
+using namespace std;
+
+MPedCalcFromData::MPedCalcFromData(const char *name, const char *title) 
+{
+    fName  = name  ? name  : "MPedCalcFromData";
+    fTitle = title ? title : "Task to calculate pedestals from data runs";
+
+    AddToBranchList("fHiGainPixId");
+    AddToBranchList("fHiGainFadcSamples");
+
+    SetRange(fgLoGainFirst, fgLoGainLast);
+    Clear();
+}
+
+void MPedCalcFromData::Clear(const Option_t *o)
+{
+
+  fRawEvt    = NULL;
+  fRunHeader = NULL;
+
+}
+
+void MPedCalcFromData::SetLoRange(Byte_t lofirst, Byte_t lolast)
+{
+    fgLoGainFirst = lofirst;
+    fgLoGainLast = lolast;
+    
+    fWindowSizeLoGain = lolast - lofirst;
+
+}
+
+Int_t MPedCalcFromData::PreProcess( MParList *pList )
+{
+    Clear();
+    
+    fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
+    if (!fRawEvt)
+    {
+	*fLog << err << "MRawEvtData not found... aborting." << endl;
+	return kFALSE;
+    }
+    
+    fRunHeader = (MRawRunHeader*)pList->FindObject(AddSerialNumber("MRawRunHeader"));
+    if (!fRunHeader)
+    {
+	*fLog << err << AddSerialNumber("MRawRunHeader") << " not found... aborting." << endl;
+	return kFALSE;
+    }
+    
+    fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
+    if (!fPedestals)
+	return kFALSE;
+    
+    return kTRUE;
+}
+
+
+Bool_t MPedCalcFromData::ReInit(MParList *pList)
+{
+  
+  Int_t npixels  = fPedestals->GetSize();
+  
+  if (fSumx.GetSize()==0)
+    {
+      fSumx. Set(npixels);
+      fSumx2.Set(npixels);
+      fEvtCounter.Set(npixels);
+      fTotalCounter.Set(npixels);
+
+      fEvtCounter.Reset();
+      fTotalCounter.Reset();
+      fSumx.Reset();
+      fSumx2.Reset();
+    }
+  
+  return kTRUE;
+      
+}
+
+Int_t MPedCalcFromData::Process()
+{
+
+  MRawEvtPixelIter pixel(fRawEvt);
+  
+  while (pixel.Next())
+    {
+
+      const UInt_t idx    = pixel.GetPixelId();
+      
+      if ( (UInt_t)pixel.GetMaxHiGainSample() < HighGainThreshold ) {
+	  
+	  fEvtCounter[idx]++;
+
+	  Byte_t *ptr = pixel.GetLoGainSamples() + fLoGainFirst;
+	  Byte_t *end = ptr + fWindowSizeLoGain;
+	  
+	  UInt_t sum = 0;
+	  UInt_t sqr = 0;
+	  
+	  if (fWindowSizeLoGain != 0)
+	  {
+	      do
+	      {
+		  sum += *ptr;
+		  sqr += *ptr * *ptr;
+	      }
+	      while (++ptr != end);
+	  }
+	  
+	  const Float_t msum = (Float_t)sum;
+	  fSumx[idx]          += msum;
+	  
+	  const Float_t sqrsum  = msum*msum;
+	  fSumx2[idx]          += sqrsum;
+
+	  if (fEvtCounter[idx] == fgDump){
+	      
+	      // Compute pedestals and rms from the sample
+	      const ULong_t n     = fWindowSizeLoGain*fgDump;
+
+	      const Float_t sum  = fSumx.At(idx);
+	      const Float_t sum2 = fSumx2.At(idx);
+	      const Float_t higainped = sum/n;	      
+
+	      // 1. Calculate the Variance of the sums:
+	      Float_t higainVar = (sum2-sum*sum/fgDump)/(fgDump-1.);
+	      // 2. Scale the variance to the number of slices:
+	      higainVar /= (Float_t)(fWindowSizeLoGain);
+	      // 3. Calculate the RMS from the Variance:
+	      (*fPedestals)[idx].Set(higainped, higainVar < 0 ? 0. : TMath::Sqrt(higainVar));
+
+	      fTotalCounter[idx]++;
+	      fEvtCounter[idx]=0;
+	      fSumx[idx]=0;
+	      fSumx2[idx]=0;
+	  };
+      }
+      
+    };
+  
+  fPedestals->SetReadyToSave();
+  return kTRUE;
+}
+
+
+Int_t MPedCalcFromData::PostProcess()
+{
+  return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mpedestal/MPedCalcFromData.h
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MPedCalcFromData.h	(revision 4356)
+++ trunk/MagicSoft/Mars/mpedestal/MPedCalcFromData.h	(revision 4356)
@@ -0,0 +1,64 @@
+#ifndef MARS_MPedCalcFromData
+#define MARS_MPedCalcFromData
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         
+// MPedCalcFromData
+//                                                                         
+// Evaluate the pedestal from real data. Uses pixels which have no switched to Low Gain
+// to take pedestals from Low Gain samples.
+//
+// Author: J. Flix (jflix@ifae.es)
+// Date: 25-06-2004
+//                                                                         
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef ROOT_TArrayD
+#include <TArrayD.h>
+#endif
+
+#ifndef ROOT_TArrayI
+#include <TArrayI.h>
+#endif
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+#ifndef MARS_MExtractor
+#include "MExtractor.h"
+#endif
+
+class MPedCalcFromData : public MExtractor
+{
+
+    UInt_t fgDump; // Number for dumping.
+    Byte_t fgLoGainFirst;      // First FADC slice Lo-Gain (currently set to: 3) 
+    Byte_t fgLoGainLast;       // Last FADC slice Lo-Gain (currently set to: 14) 
+    Byte_t fWindowSizeLoGain;             // Number of Lo Gain slices in window
+    Byte_t HighGainThreshold;
+
+    TArrayD fSumx;         // sum of values
+    TArrayD fSumx2;        // sum of squared values
+
+    TArrayI fEvtCounter; // Counter for dumping values to Pedestal Container
+    TArrayI fTotalCounter; // Counter for dumping values to Pedestal Container
+
+    Int_t  PreProcess ( MParList *pList );
+    Bool_t ReInit     ( MParList *pList );
+    Int_t  Process    ();
+    Int_t  PostProcess();
+
+public:
+
+    MPedCalcFromData(const char *name=NULL, const char *title=NULL);
+ 
+    void Clear(const Option_t *o="");
+    void SetDumpEvents(UInt_t dumpevents = 0){fgDump = dumpevents;}
+    void SetHighGainThreshold(Byte_t Threshold = 0){HighGainThreshold = Threshold;}
+    void SetLoRange(Byte_t lofirst=0, Byte_t lolast=0);
+
+    ClassDef(MPedCalcFromData, 0)   // Task to calculate pedestals from data runs 
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mtemp/Changelog
===================================================================
--- trunk/MagicSoft/Mars/mtemp/Changelog	(revision 4355)
+++ trunk/MagicSoft/Mars/mtemp/Changelog	(revision 4356)
@@ -18,4 +18,10 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2004/06/26: Eva Domingo - Pepe Flix
+
+   * mifae/library/MDisp.[h,cc]
+   * mifae/library/MDispCalc.[h,cc]
+      - Added classes for evaluation of DISP method.
 
  2004/06/25: Sebastian Commichau
Index: trunk/MagicSoft/Mars/mtemp/mifae/Changelog
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/Changelog	(revision 4355)
+++ trunk/MagicSoft/Mars/mtemp/mifae/Changelog	(revision 4356)
@@ -18,4 +18,10 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+  2004/06/26: Eva Domingo - Pepe Flix
+
+    * mifae/library/MDisp.[h,cc]
+    * mifae/library/MDispCalc.[h,cc]
+      - Added classes for evaluation of DISP method.
 
   2004/06/22  Javier Rico
