Index: trunk/MagicSoft/Mars/mtemp/mifae/macros/lightcurve.C
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/macros/lightcurve.C	(revision 4387)
+++ trunk/MagicSoft/Mars/mtemp/mifae/macros/lightcurve.C	(revision 4397)
@@ -22,5 +22,5 @@
     }
 
-    return chiq/nbinsnozero;
+    return (nbinsnozero>0?chiq/nbinsnozero:0);
 }
 
@@ -59,4 +59,8 @@
 
   gROOT->Reset();
+  gStyle->SetCanvasColor(0);
+  gStyle->SetCanvasBorderMode(0);
+  gStyle->SetPadBorderMode(0);
+  gStyle->SetFrameBorderMode(0);
   gStyle->SetTimeOffset(-3600);
 
@@ -64,10 +68,8 @@
   const Bool_t debug = kFALSE;
   const Double_t timebin = 480.; //[sec]
-  TString psname = "./20040422_Mrk421." + timebin + "s.ps";
-  cout << psname << endl;
-  return;
+  TString psname = "./20040420_Mrk421.480s.ps";
 
   //Constanst
-  const Double_t kConvDegToRad = TMath::ACos(-1)/180.;
+  const Double_t kConvDegToRad = TMath::Pi()/180.;
   const Double_t kSec = 1e6;  //[sec/microsec]
   const Double_t kDay = 24.*60.*60.;  //[Day/sec]
@@ -89,16 +91,4 @@
   
 
-  //none cuts
-//   Double_t sizemin   = 2000.; //[Photons]
-//   Double_t sizemax   = 10000000000.; //[Photons]
-//   Double_t widthmin  = 0.; 
-//   Double_t widthmax  = 2.0;
-//   Double_t lengthmin = 0.; 
-//   Double_t lengthmax = 2.0;
-//   Double_t distmin   = 0.; 
-//   Double_t distmax   = 4.0;
-//   Double_t alphamin   = 0.; 
-//   Double_t alphamax   = 90.;
-
   
   const Int_t numberSizeBins = 4;
@@ -106,6 +96,4 @@
 
   //cuts
-  Double_t sizemin = 2000.; //[Photons]
-  Double_t sizemax = 10E9.; //[Photons]
 
   Double_t widthmin[numberSizeBins]  = { 0.06, 0.06, 0.06, 0.06 }; 
@@ -135,101 +123,55 @@
   // ON containers
   MGeomCamMagic geomcam;
-  MSrcPosCam source_on;
-  MHillas hillas;
-  MHillasSrc hillasscr;
-  
+  MRawRunHeader runheader_on;
+  MRawEvtHeader evtheader_on;
+  MTime              time_on;
+  MHillas          hillas_on;
+  MHillasSrc    hillassrc_on;
+  MSrcPosCam       srcpos_on;
+  MReportDrive      drive_on;
+
   plist_on.AddToList(&geomcam);
-  plist_on.AddToList(&source_on);
-  plist_on.AddToList(&hillas);
-  plist_on.AddToList(&hillasscr);
-  
-  //create some 1-dim histo to test only for the ON distribution of dist, width , length, size...
-  MH3 hDist_on("MHillasSrc.fDist/MGeomCam.fConvMm2Deg");
-  hDist_on.SetName("Dist_on");
-  plist_on.AddToList(&hDist_on);
-  MBinning binsDist_on("BinningDist_on");
+  plist_on.AddToList(&runheader_on);
+  plist_on.AddToList(&evtheader_on);
+  plist_on.AddToList(&time_on);
+  plist_on.AddToList(&hillas_on);
+  plist_on.AddToList(&hillassrc_on);
+  plist_on.AddToList(&srcpos_on);
+  plist_on.AddToList(&drive_on);
+
+  Int_t nbins_Size = 60;
+  Double_t min_Size = log10(sizeBins[0])*0.8;
+  Double_t max_Size = log10(1000000)*1.2;
+  TH1F *hSize_on = new TH1F ("hSizeOn","",nbins_Size,min_Size,max_Size);
+
+  Int_t nbins_Width = 20;
+  Double_t min_Width = 0.;
+  Double_t max_Width = widthmax[numberSizeBins-1]*1.2;
+  TH1F *hWidth_on = new TH1F ("hWidthOn","",nbins_Width,min_Width,max_Width);
+
+  Int_t nbins_Length = 20;
+  Double_t min_Length = 0.;
+  Double_t max_Length =  lengthmax[numberSizeBins-1]*1.2;
+  TH1F *hLength_on = new TH1F ("hLengthOn","",nbins_Length,min_Length,max_Length);
+
   Int_t nbins_Dist = 20;
   Double_t min_Dist = 0.;
-  Double_t max_Dist = distmax[0]*1.2;
-  binsDist_on.SetEdges(nbins_Dist, min_Dist, max_Dist);
-  plist_on.AddToList(&binsDist_on);
-  
-  MH3 hWidth_on("MHillas.fWidth/MGeomCam.fConvMm2Deg");
-  hWidth_on.SetName("Width_on");
-  plist_on.AddToList(&hWidth_on);
-  MBinning binsWidth_on("BinningWidth_on");
-  Int_t nbins_Width = 20;
-  Double_t min_Width = 0.;
-  Double_t max_Width = widthmax[0]*1.2;
-  binsWidth_on.SetEdges(nbins_Width, min_Width, max_Width);
-  plist_on.AddToList(&binsWidth_on);
-  
-  MH3 hLength_on("MHillas.fLength/MGeomCam.fConvMm2Deg");
-  hLength_on.SetName("Length_on");
-  plist_on.AddToList(&hLength_on);
-  MBinning binsLength_on("BinningLength_on");
-  Int_t nbins_Length = 20;
-  Double_t min_Length = 0.;
-  Double_t max_Length =  lengthmax[0]*1.2;
-  binsLength_on.SetEdges(nbins_Length, min_Length, max_Length);
-  plist_on.AddToList(&binsLength_on);
-  
-  MH3 hSize_on("log10(MHillas.fSize)");
-  hSize_on.SetName("Size_on");
-  plist_on.AddToList(&hSize_on);
-  MBinning binsSize_on("BinningSize_on");
-  Int_t nbins_Size = 60;
-  Double_t min_Size = log10(sizemin)*0.8;
-  Double_t max_Size = log10(1000000)*1.2;
-  binsSize_on.SetEdges(nbins_Size, min_Size, max_Size);
-  plist_on.AddToList(&binsSize_on);
-    
-  //create a histo to fill the alpha values: one alpha plot form 0 to +90 deg in abs value
-  MH3 hAlpha_on_abs("abs(MHillasSrc.fAlpha)");
-  hAlpha_on_abs.SetName("Alpha_on_abs");
-  plist_on.AddToList(&hAlpha_on_abs);
-  MBinning binsAlpha_on_abs("BinningAlpha_on_abs");
+  Double_t max_Dist = distmax[numberSizeBins-1]*1.2;
+  TH1F *hDist_on = new TH1F ("hDistOn","",nbins_Dist,min_Dist,max_Dist);
+
   Int_t nbins_abs = 18;
   Double_t minalpha_abs = 0.;
   Double_t maxalpha_abs =90.;
-  binsAlpha_on_abs.SetEdges(nbins_abs, minalpha_abs, maxalpha_abs);
-  plist_on.AddToList(&binsAlpha_on_abs);
-  
-  //create a histo to fill the alpha values: one alpha plot form -90 to +90 deg.
-  MH3 hAlpha_on("MHillasSrc.fAlpha");
-  hAlpha_on.SetName("Alpha_on");
-  plist_on.AddToList(&hAlpha_on);
-  MBinning binsAlpha_on("BinningAlpha_on");
+  TH1F *hAlpha_on_abs = new TH1F ("hAbsAlphaOn","",nbins_abs,minalpha_abs,maxalpha_abs);
+
   Int_t nbins = nbins_abs*2;
   Double_t minalpha = -90.;
   Double_t maxalpha =  90.;
-  binsAlpha_on.SetEdges(nbins, minalpha, maxalpha);
-  plist_on.AddToList(&binsAlpha_on);
-    
-
-  //create a histo to fill the source position 
-  MH3 hSrcPos_on("MSrcPosCam.fX","MSrcPosCam.fY");
-  hSrcPos_on.SetName("SrcPos_on");
-  plist_on.AddToList(&hSrcPos_on);
-  MBinning binsSrcPos_onX("BinningSrcPos_onX");
-  MBinning binsSrcPos_onY("BinningSrcPos_onY");
+  TH1F *hAlpha_on = new TH1F ("hAlphaOn","",nbins,minalpha,maxalpha);
+
   Int_t nbins_srcpos = 400;
   Double_t minsrcpos = -600.;
-  Double_t maxsrcpos =  600.;
-  binsSrcPos_onX.SetEdges(nbins_srcpos, minsrcpos, maxsrcpos);
-  binsSrcPos_onY.SetEdges(nbins_srcpos, minsrcpos, maxsrcpos);
-  plist_on.AddToList(&binsSrcPos_onX);
-  plist_on.AddToList(&binsSrcPos_onY);
-  
-  MH3 hDAQEvtNumber_on("MRawEvtHeader.fDAQEvtNumber");
-  hDAQEvtNumber_on.SetName("DAQEvtNumber_on");
-  plist_on.AddToList(&hDAQEvtNumber_on);
-  MBinning binsDAQEvtNumber_onX("BinningDAQEvtNumber_onX");
-  Int_t nbins_evtnum = 1000;
-  Double_t minevtnum =  0.;
-  Double_t maxevtnum =  1000.;
-  binsDAQEvtNumber_onX.SetEdges(nbins_evtnum,minevtnum,maxevtnum);
-  plist_on.AddToList(&binsDAQEvtNumber_onX);
-  
+  Double_t maxsrcpos =  600.;  //[mm]  //!!! position precition 3mm ~ 0.01 deg
+  TH2F *hSrcPos_on = new TH2F ("hSrcPosOn","",nbins_srcpos,minsrcpos,maxsrcpos,nbins_srcpos,minsrcpos,maxsrcpos);
 
   //
@@ -241,65 +183,11 @@
  
   MSrcPlace srcplace;
-
-  //cuts
-  TString sizestr = "(MHillas.fSize < ";
-  sizestr += sizemin;
-  sizestr += ") || (";
-  sizestr += "MHillas.fSize > ";
-  sizestr += sizemax;
-  sizestr += ")";
-  MF sizefilter(sizestr);
-
-  TString widthstr = "({MHillas.fWidth/MGeomCam.fConvMm2Deg} < ";
-  widthstr += widthmin[0];
-  widthstr += ") || (";
-  widthstr += "{MHillas.fWidth/MGeomCam.fConvMm2Deg} > ";
-  widthstr += widthmax[0];
-  widthstr += ")";
-  MF widthfilter(widthstr);
-  
-  TString lengthstr = "({MHillas.fLength/MGeomCam.fConvMm2Deg} < ";
-  lengthstr += lengthmin[0];
-  lengthstr += ") || (";
-  lengthstr += "{MHillas.fLength/MGeomCam.fConvMm2Deg} > ";
-  lengthstr += lengthmax[0];
-  lengthstr += ")";
-  MF lengthfilter(lengthstr);
-  
-  TString diststr = "({MHillasSrc.fDist/MGeomCam.fConvMm2Deg} < ";
-  diststr += distmin[0];
-  diststr += ") || (";
-  diststr += "{MHillasSrc.fDist/MGeomCam.fConvMm2Deg} > ";
-  diststr += distmax[0];
-  diststr += ")";
-  MF distfilter(diststr);
-  
-  MF evenfilter("{MRawEvtHeader.fDAQEvtNumber%3}<0.5");
-  MF oddfilter("{MRawEvtHeader.fDAQEvtNumber%3}>0.5");
-  
-  MContinue cont_size(&sizefilter);
-  MContinue cont_width(&widthfilter);
-  MContinue cont_length(&lengthfilter);
-  MContinue cont_dist(&distfilter);
-  MContinue cont_even(&evenfilter);
-  MContinue cont_odd(&oddfilter);
-  
   MHillasSrcCalc csrc_on;
   
-  // fill all histograms
-  MFillH falpha_on_abs(&hAlpha_on_abs);
-  MFillH falpha_on(&hAlpha_on);
-  MFillH fdist_on(&hDist_on);
-  MFillH fwidth_on(&hWidth_on);
-  MFillH flength_on(&hLength_on);
-  MFillH fsize_on(&hSize_on);
-  MFillH fsrcpos_on(&hSrcPos_on);
-  MFillH fevtnum_on(&hDAQEvtNumber_on);
-  
-  // prints
-  MPrint pevent("MRawEvtHeader");
-  MPrint phillas("MHillas");
-  MPrint phillassrc("MHillasSrc");
-  MPrint psrcpos("MSrcPosCam");
+//   // prints
+//   MPrint pevent("MRawEvtHeader");
+//   MPrint phillas("MHillas");
+//   MPrint phillassrc("MHillasSrc");
+//   MPrint psrcpos("MSrcPosCam");
   
   //tasklist
@@ -307,17 +195,4 @@
   tlist_on.AddToList(&srcplace);
   tlist_on.AddToList(&csrc_on);
-  tlist_on.AddToList(&fsrcpos_on);
-  //  tlist_on.AddToList(&cont_odd);
-  tlist_on.AddToList(&cont_size);
-  tlist_on.AddToList(&cont_width);
-  tlist_on.AddToList(&cont_length);
-  tlist_on.AddToList(&cont_dist);
-  tlist_on.AddToList(&falpha_on_abs);
-  tlist_on.AddToList(&falpha_on);
-  tlist_on.AddToList(&fdist_on);
-  tlist_on.AddToList(&fwidth_on);
-  tlist_on.AddToList(&flength_on);
-  tlist_on.AddToList(&fsize_on);
-  //  tlist_on.AddToList(&fevtnum_on);
   
   // Create and setup the eventloop
@@ -335,13 +210,4 @@
     return;
   
-  MRawRunHeader* runheader_on = plist_on.FindObject("MRawRunHeader");
-  MRawEvtHeader* evtheader_on = plist_on.FindObject("MRawEvtHeader");
-  MTime* time_on = plist_on.FindObject("MTime");
-  MHillas* hillas_on = plist_on.FindObject("MHillas");
-  MHillasSrc* hillassrc_on = plist_on.FindObject("MHillasSrc");
-  MReportDrive* drive_on = plist_on.FindObject("MReportDrive");
-  MSrcPosCam* srcpos_on = plist_on.FindObject("MSrcPosCam");
-  
-
   Double_t mjdFirstEventofBin=0;
   Double_t mjdFirstEvent=0;
@@ -363,11 +229,11 @@
 
   //create histos needed in the time bins
+
   TString alphaTitle = Form("%s%02i","hAlphaOn",numberTimeBins-1);
   TH1F *hAlpha_on_abs_timebin = new TH1F (alphaTitle,"",nbins_abs,minalpha_abs,maxalpha_abs);
-  Int_t nbins_srcpos = 200;
-  Double_t minsrcpos = -600.; //[mm]
-  Double_t maxsrcpos = 600.;  //[mm]  //!!! position precition 3mm ~ 0.01 deg
+
   TString srcposTitle =  Form("%s%02i","hSrcPosOn",numberTimeBins-1);
   TH2F *hSrcPos_on_timebin = new TH2F (srcposTitle,"",nbins_srcpos,minsrcpos,maxsrcpos,nbins_srcpos,minsrcpos,maxsrcpos);
+
   Int_t nbins_coszenith = 200;
   Double_t mincoszenith = 0.;  
@@ -379,7 +245,7 @@
     {
       // Compute live time 
-      UInt_t   run = runheader_on->GetRunNumber();
-      UInt_t   evt = evtheader_on->GetDAQEvtNumber();
-      Double_t mjd = time_on->GetMjd();
+      UInt_t   run = runheader_on.GetRunNumber();
+      UInt_t   evt = evtheader_on.GetDAQEvtNumber();
+      Double_t mjd = time_on.GetMjd();
 
       if (mjd == 0)
@@ -393,5 +259,5 @@
 	      cout << "present event:\t run " << run << " event " << evt << " mjd " << mjd <<  endl;
 	      mtimeLastEvent.Print();
-	      time_on->Print();
+	      time_on.Print();
 	    }
 	  
@@ -408,5 +274,5 @@
 	      cout << "present event:\t run " << run << " event " << evt << " mjd " << mjd <<  endl;
 	      mtimeLastEvent.Print();
-	      time_on->Print();	
+	      time_on.Print();	
 	    }
 	  
@@ -423,5 +289,5 @@
 	      cout << "present event:\t run " << run << " event " << evt << " mjd " << mjd <<  endl;
 	      mtimeLastEvent.Print();
-	      time_on->Print();	
+	      time_on.Print();	
 	    }
 
@@ -438,5 +304,5 @@
 	      cout << "present event:\t run " << run << " event " << evt << " mjd " << mjd <<  endl;
 	      mtimeLastEvent.Print();
-	      time_on->Print();	
+	      time_on.Print();	
 	    }
 
@@ -454,5 +320,5 @@
 	      cout << "present event:\t run " << run << " event " << evt << " mjd " << mjd <<  endl;
 	      mtimeLastEvent.Print();
-	      time_on->Print();	
+	      time_on.Print();	
 	    }
 
@@ -470,5 +336,5 @@
 	      cout << "present event:\t run " << run << " event " << evt << " mjd " << mjd <<  endl;
 	      mtimeLastEvent.Print();
-	      time_on->Print();	
+	      time_on.Print();	
 	      
 	      flag = kFALSE;
@@ -489,5 +355,5 @@
 		      cout << "present event:\t run " << run << " event " << evt << " mjd " << mjd <<  endl;
 		      mtimeLastEvent.Print();
-		      time_on->Print();	
+		      time_on.Print();	
 		    }
 		  
@@ -506,16 +372,16 @@
 	  runLastEvent = run;
 	  mjdLastEvent = mjd;
-	  mtimeLastEvent = *time_on;
+	  mtimeLastEvent = time_on;
 
       
       
-	  Double_t size = hillas_on->GetSize();
-	  Double_t width = hillas_on->GetWidth()*geomcam.GetConvMm2Deg();
-	  Double_t length = hillas_on->GetLength()*geomcam.GetConvMm2Deg();
-	  Double_t dist = hillassrc_on->GetDist()*geomcam.GetConvMm2Deg();
-	  Double_t alpha = hillassrc_on->GetAlpha();
-	  Double_t srcposx = srcpos_on->GetX();
-	  Double_t srcposy = srcpos_on->GetY();
-	  Double_t zenith = drive_on->GetNominalZd();
+	  Double_t size = hillas_on.GetSize();
+	  Double_t width = hillas_on.GetWidth()*geomcam.GetConvMm2Deg();
+	  Double_t length = hillas_on.GetLength()*geomcam.GetConvMm2Deg();
+	  Double_t dist = hillassrc_on.GetDist()*geomcam.GetConvMm2Deg();
+	  Double_t alpha = hillassrc_on.GetAlpha();
+	  Double_t srcposx = srcpos_on.GetX();
+	  Double_t srcposy = srcpos_on.GetY();
+	  Double_t zenith = drive_on.GetNominalZd();
 	  
 
@@ -530,4 +396,15 @@
 		      if (dist > distmin[sizebin] && dist < distmax[sizebin])
 			{      
+
+			  //General histos
+			  hSize_on->Fill(log10(size));
+			  hWidth_on->Fill(width);
+			  hLength_on->Fill(length);
+			  hDist_on->Fill(dist);
+			  hAlpha_on_abs->Fill(TMath::Abs(alpha));
+			  hAlpha_on->Fill(alpha);
+			  hSrcPos_on->Fill(srcposx,srcposy);
+			  
+			  // Time bin histos
 			  hAlpha_on_abs_timebin->Fill(TMath::Abs(alpha));
 			  hSrcPos_on_timebin->Fill(srcposx,srcposy);
@@ -550,5 +427,5 @@
 	      //Compute the time on
 	      timeOn[numberTimeBins-1] += (mjdLastEvent-mjdFirstEvent)*kDay;
-	      widthTimeBinOn[numberTimeBins-1] = (mjd-mjdFirstEventofBin)/2;
+	      widthTimeBinOn[numberTimeBins-1] = (mjdLastEvent-mjdFirstEventofBin)/2;
 	      meanTimeBinOn[numberTimeBins-1] = mjdFirstEventofBin + widthTimeBinOn[numberTimeBins-1];
 	      
@@ -671,77 +548,29 @@
   plist_off.AddToList(&tlist_off);
   
-  MSrcPosCam source_off;
+  MRawRunHeader runheader_off;
+  MRawEvtHeader evtheader_off;
+  MTime              time_off;
+  MHillas          hillas_off;
+  MHillasSrc    hillassrc_off;
+  MSrcPosCam       srcpos_off;
+  MReportDrive      drive_off;
   
   plist_off.AddToList(&geomcam);
-  plist_off.AddToList(&source_off);
-  plist_off.AddToList(&hillas);
-  plist_off.AddToList(&hillasscr);
-  
-  //create some 1-dim histo to test only for the OFF distribution of dist, width , length, size...
-  MH3 hDist_off("MHillasSrc.fDist/MGeomCam.fConvMm2Deg");
-  hDist_off.SetName("Dist_off");
-  plist_off.AddToList(&hDist_off);
-  MBinning binsDist_off("BinningDist_off");
-  binsDist_off.SetEdges(nbins_Dist, min_Dist, max_Dist);
-  plist_off.AddToList(&binsDist_off);
-  
-  MH3 hWidth_off("MHillas.fWidth/MGeomCam.fConvMm2Deg");
-  hWidth_off.SetName("Width_off");
-  plist_off.AddToList(&hWidth_off);
-  MBinning binsWidth_off("BinningWidth_off");
-  binsWidth_off.SetEdges(nbins_Width, min_Width, max_Width);
-  plist_off.AddToList(&binsWidth_off);
-  
-  MH3 hLength_off("MHillas.fLength/MGeomCam.fConvMm2Deg");
-  hLength_off.SetName("Length_off");
-  plist_off.AddToList(&hLength_off);
-  MBinning binsLength_off("BinningLength_off");
-  binsLength_off.SetEdges(nbins_Length, min_Length, max_Length);
-  plist_off.AddToList(&binsLength_off);
-  
-  MH3 hSize_off("log10(MHillas.fSize)");
-  hSize_off.SetName("Size_off");
-  plist_off.AddToList(&hSize_off);
-  MBinning binsSize_off("BinningSize_off");
-  binsSize_off.SetEdges(nbins_Size, min_Size, max_Size);
-  plist_off.AddToList(&binsSize_off);
-  
-  //create a histo to fill the alpha values: from 0 to 90 deg -> abs value
-  MH3 hAlpha_off_abs("abs(MHillasSrc.fAlpha)");
-  hAlpha_off_abs.SetName("Alpha_off_abs");
-  plist_off.AddToList(&hAlpha_off_abs);
-  MBinning binsAlpha_off_abs("BinningAlpha_off_abs");
-  binsAlpha_off_abs.SetEdges(nbins_abs, minalpha_abs, maxalpha_abs);
-  plist_off.AddToList(&binsAlpha_off_abs);
-  
-  //create a histo to fill the alpha values: from -90 to 90 deg
-  MH3 hAlpha_off("MHillasSrc.fAlpha");
-  hAlpha_off.SetName("Alpha_off");
-  plist_off.AddToList(&hAlpha_off);
-  MBinning binsAlpha_off("BinningAlpha_off");
-  binsAlpha_off.SetEdges(nbins, minalpha, maxalpha);
-  plist_off.AddToList(&binsAlpha_off);
-  
-  
-  MH3 hSrcPos_off("MSrcPosCam.fX","MSrcPosCam.fY");
-  hSrcPos_off.SetName("SrcPos_off");
-  plist_off.AddToList(&hSrcPos_off);
-  MBinning binsSrcPos_offX("BinningSrcPos_offX");
-  MBinning binsSrcPos_offY("BinningSrcPos_offY");
-  binsSrcPos_offX.SetEdges(nbins_srcpos, minsrcpos, maxsrcpos);
-  binsSrcPos_offY.SetEdges(nbins_srcpos, minsrcpos, maxsrcpos);
-  plist_off.AddToList(&binsSrcPos_offX);
-  plist_off.AddToList(&binsSrcPos_offY);
-  
-  MH3 hDAQEvtNumber_off("MRawEvtHeader.fDAQEvtNumber");
-  hDAQEvtNumber_off.SetName("DAQEvtNumber_off");
-  plist_off.AddToList(&hDAQEvtNumber_off);
-  MBinning binsDAQEvtNumber_offX("BinningDAQEvtNumber_offX");
-  Int_t nbins_evtnum = 100;
-  Double_t minevtnum =  0.;
-  Double_t maxevtnum =  100.;
-  binsDAQEvtNumber_offX.SetEdges(nbins_evtnum,minevtnum,maxevtnum);
-  plist_off.AddToList(&binsDAQEvtNumber_offX);
-  
+  plist_off.AddToList(&runheader_off);
+  plist_off.AddToList(&evtheader_off);
+  plist_off.AddToList(&time_off);
+  plist_off.AddToList(&hillas_off);
+  plist_off.AddToList(&hillassrc_off);
+  plist_off.AddToList(&srcpos_off);
+  plist_off.AddToList(&drive_off);
+
+  TH1F *hSize_off      = new TH1F ("hSizeOff","",nbins_Size,min_Size,max_Size);
+  TH1F *hWidth_off     = new TH1F ("hWidthOff","",nbins_Width,min_Width,max_Width);
+  TH1F *hLength_off    = new TH1F ("hLengthOff","",nbins_Length,min_Length,max_Length);
+  TH1F *hDist_off      = new TH1F ("hDistOff","",nbins_Dist,min_Dist,max_Dist);
+  TH1F *hAlpha_off_abs = new TH1F ("hAbsAlphaOff","",nbins_abs,minalpha_abs,maxalpha_abs);
+  TH1F *hAlpha_off     = new TH1F ("hAlphaOff","",nbins,minalpha,maxalpha);
+  TH2F *hSrcPos_off    = new TH2F ("hSrcPosOff","",nbins_srcpos,minsrcpos,maxsrcpos,nbins_srcpos,minsrcpos,maxsrcpos);
+
   //tasks
   MReadTree read_off("Parameters", f_off_name);
@@ -755,36 +584,12 @@
   // --------------------------------------------------------------
 
-  srcplace.SetMode(MSrcPlace::kOff);
+  //  srcplace.SetMode(MSrcPlace::kOff);
   
   MHillasSrcCalc csrc_off;
-  
-  // fill all histograms
-  MFillH falpha_off_abs(&hAlpha_off_abs);
-  MFillH falpha_off(&hAlpha_off);
-  MFillH fdist_off(&hDist_off);
-  MFillH fwidth_off(&hWidth_off);
-  MFillH flength_off(&hLength_off);
-  MFillH fsize_off(&hSize_off);
-  MFillH fsrcpos_off(&hSrcPos_off);
-  MFillH fevtnum_off(&hDAQEvtNumber_off);
   
   //tasklist
   tlist_off.AddToList(&read_off);
-  tlist_off.AddToList(&srcplace);
-  tlist_off.AddToList(&csrc_off);
-  tlist_off.AddToList(&fsrcpos_off);
-//   tlist_off.AddToList(&cont_even);
-//   tlist_off.AddToList(&cont_size);
-//   tlist_off.AddToList(&cont_width);
-//   tlist_off.AddToList(&cont_length);
-//   tlist_off.AddToList(&cont_dist);
-//   tlist_off.AddToList(&falpha_off_abs);
-//   tlist_off.AddToList(&falpha_off);
-//   tlist_off.AddToList(&fdist_off);
-//   tlist_off.AddToList(&fwidth_off);
-//   tlist_off.AddToList(&flength_off);
-//   tlist_off.AddToList(&fsize_off);
-//   tlist_off.AddToList(&fevtnum_off);
   tlist_off.AddToList(&srcplace_timebin); // This is just to run the preprocess correctely
+  tlist_off.AddToList(&csrc_off); // This is just to run the preprocess correctely
   
   // Create and setup the eventloop
@@ -802,50 +607,57 @@
     return;
 
-
-  MHillas* hillas_off = plist_off.FindObject("MHillas");
-  MHillasSrc* hillassrc_off = plist_off.FindObject("MHillasSrc");
-  MReportDrive* drive_off = plist_off.FindObject("MReportDrive");
-  MSrcPosCam* srcpos_off = plist_off.FindObject("MSrcPosCam");
-
-  TArrayI sizecut(numberTimeBins);
-  TArrayI widthcut(numberTimeBins);
-  TArrayI lengthcut(numberTimeBins);
-  TArrayI distcut(numberTimeBins);
-  TArrayI alphacut(numberTimeBins);
-  
-  sizecut.Reset(0);
-  widthcut.Reset(0);
-  lengthcut.Reset(0);
-  distcut.Reset(0);
-  alphacut.Reset(0);
-
   while(tlist_off.Process())
     {
 
-      //Now fill just the alpha plot in the time/zenith bins defined in on
-      Double_t zenith = drive_off->GetNominalZd();
+      //First read the variables source(i.e. time bin) independent
+      Double_t zenith = drive_off.GetNominalZd();
+
+      Double_t size = hillas_off.GetSize();
+      Double_t width = hillas_off.GetWidth()*geomcam.GetConvMm2Deg();
+      Double_t length = hillas_off.GetLength()*geomcam.GetConvMm2Deg();
       
-      for (UInt_t bin=0; bin<numberTimeBins; bin++)
+      Int_t sizebin = GetBin(size,numberSizeBins,sizeBins);
+      
+      if (sizebin >= 0)
 	{
- 	  srcplace_timebin.SetPositionHisto((TH2F*)srcposHistoOn[bin]);
- 	  srcplace_timebin.CallProcess();
- 	  csrc_off.CallProcess();
-	  
-	  Double_t size = hillas_off->GetSize();
-	  Double_t width = hillas_off->GetWidth()*geomcam.GetConvMm2Deg();
-	  Double_t length = hillas_off->GetLength()*geomcam.GetConvMm2Deg();
-	  Double_t dist = hillassrc_off->GetDist()*geomcam.GetConvMm2Deg();
-	  Double_t alpha = hillassrc_off->GetAlpha();
-	  Double_t srcposx = srcpos_off->GetX();
-	  Double_t srcposy = srcpos_off->GetY();
-	  
-	  Int_t sizebin = GetBin(size,numberSizeBins,sizeBins);
-	  
-	  if (sizebin >= 0)
+	  if (width > widthmin[sizebin] && width < widthmax[sizebin])
 	    {
-	      if (width > widthmin[sizebin] && width < widthmax[sizebin])
+	      if (length > lengthmin[sizebin] && length < lengthmax[sizebin])
 		{
-		  if (length > lengthmin[sizebin] && length < lengthmax[sizebin])
+		  //General histos
+
+		  if (dist > distmin[sizebin] && dist < distmax[sizebin])
 		    {
+		      hSize_off->Fill(log10(size));
+		      hWidth_off->Fill(width);
+		      hLength_off->Fill(length);
+
+		      srcplace_timebin.SetPositionHisto(hSrcPos_on);
+		      srcplace_timebin.CallProcess();
+		      csrc_off.CallProcess();
+		  
+		      Double_t dist = hillassrc_off.GetDist()*geomcam.GetConvMm2Deg();
+		      Double_t alpha = hillassrc_off.GetAlpha();
+		      Double_t srcposx = srcpos_off.GetX();
+		      Double_t srcposy = srcpos_off.GetY();
+
+		      hDist_off->Fill(dist);
+		      hAlpha_off_abs->Fill(TMath::Abs(alpha));
+		      hAlpha_off->Fill(alpha);
+		      hSrcPos_off->Fill(srcposx,srcposy);
+		    }
+
+		  // Time bin histos
+		  for (UInt_t bin=0; bin<numberTimeBins; bin++)
+		    {
+		      srcplace_timebin.SetPositionHisto((TH2F*)srcposHistoOn[bin]);
+		      srcplace_timebin.CallProcess();
+		      csrc_off.CallProcess();
+		      
+		      Double_t dist = hillassrc_off.GetDist()*geomcam.GetConvMm2Deg();
+		      Double_t alpha = hillassrc_off.GetAlpha();
+		      Double_t srcposx = srcpos_off.GetX();
+		      Double_t srcposy = srcpos_off.GetY();
+		      
 		      if (dist > distmin[sizebin] && dist < distmax[sizebin])
 			{
@@ -853,20 +665,14 @@
 			  ((TH2F*)srcposHistoOff[bin])->Fill(srcposx,srcposy);
 			}
-		      else
-			distcut[bin]++;	    
 		    }
-		  else	
-		    lengthcut[bin]++;
 		}
-	      else
-		widthcut[bin]++;
 	    }
 	}
       
-//       if (zenith >  zenithMaximumOn[numberTimeBins-1])
-// 	{
-// 	  cout << "Exit loop because we arrive to zenith = " << zenith << endl;
-// 	  break;
-// 	}
+      //       if (zenith >  zenithMaximumOn[numberTimeBins-1])
+      // 	{
+      // 	  cout << "Exit loop because we arrive to zenith = " << zenith << endl;
+      // 	  break;
+      // 	}
     }
   
@@ -874,15 +680,4 @@
 
   tlist_off.PrintStatistics();
-
-//   for (UInt_t bin=0; bin<numberTimeBins; bin++)
-//     {
-//       cout <<  bin << ' '  << ((TH1F*)alphaHistoOff[bin])->GetEntries() << ' ' << ((TH2F*)srcposHistoOff[bin])->GetEntries() << endl;
-//       cout <<  "sizecut " << sizecut[bin] << endl;
-//       cout <<  "width   " << widthcut[bin] << endl;
-//       cout <<  "length  " << lengthcut[bin] << endl;
-//       cout <<  "dist    " << distcut[bin] << endl;
-//       cout <<  "alpha   " << alphacut[bin] << endl;
-//     }
-  
 
   TArrayD meanTimeBinOnInSec(numberTimeBins);
@@ -931,6 +726,6 @@
   TString closepsname = psname + ")";
 
-  TCanvas *c1 = new TCanvas;
-  c1->cd(1);
+  TCanvas *c0 = new TCanvas;
+  c0->cd(1);
   TGraphErrors* lightcurvegraph = new TGraphErrors(numberTimeBins,meanTimeBinOnInSec.GetArray(),numberExcessEventsPerMin.GetArray(),widthTimeBinOnInSec.GetArray(),errorNumberExcessEventsPerMin.GetArray());
   lightcurvegraph->SetTitle("LightCurve");
@@ -939,6 +734,8 @@
   lightcurvegraph->SetMarkerSize(0.03);
   lightcurvegraph->Draw("AP");
+  lightcurvegraph->GetYaxis()->SetTitle("Excess/min");
+  lightcurvegraph->GetXaxis()->SetTitle("UTC Time");
   lightcurvegraph->GetXaxis()->SetTimeDisplay(1);
-  c1->Print(openpsname);
+  c0->Print(openpsname);
       
   TCanvas** c = new TCanvas*[numberTimeBins];
@@ -999,44 +796,18 @@
   ((TH1F*)alphaHistoOn[numberTimeBins-1])->DrawCopy("E1PSAME");
   
-  c[numberTimeBins-1]->Print(closepsname);
-
-  TFile input("./prueba.root", "RECREATE");
-
-   for (UInt_t bin=0; bin<numberTimeBins; bin++)
-     {
-       ((TH1F*)alphaHistoOn[bin])->Write();
-       ((TH1F*)alphaHistoOff[bin])->Write();
-       ((TH2F*)srcposHistoOn[bin])->Write();
-       ((TH2F*)srcposHistoOff[bin])->Write();
-       ((TH1F*)coszenithHistoOn[bin])->Write();
-     }
-
-   input.Close();
-
-  if(kFALSE)
-    {
-
-  // ############################################################################
-  //  look for the histograms
-  // ############################################################################
-  
-  TH1F *hist_size_on = (TH1F*)hSize_on.GetHist();
-  TH1F *hist_size_off = (TH1F*)hSize_off.GetHist();
-  
-  TH1F *hist_dist_on = (TH1F*)hDist_on.GetHist();
-  TH1F *hist_dist_off = (TH1F*)hDist_off.GetHist();
-
-  TH1F *hist_width_on = (TH1F*)hWidth_on.GetHist();
-  TH1F *hist_width_off = (TH1F*)hWidth_off.GetHist();
-
-  TH1F *hist_length_on = (TH1F*)hLength_on.GetHist();
-  TH1F *hist_length_off = (TH1F*)hLength_off.GetHist();
-
-  TH1F *hist_on_abs = (TH1F*)hAlpha_on_abs.GetHist();
-  TH1F *hist_off_abs = (TH1F*)hAlpha_off_abs.GetHist();
-
-  TH1F *hist_on = (TH1F*)hAlpha_on.GetHist();
-  TH1F *hist_off = (TH1F*)hAlpha_off.GetHist();
-
+  c[numberTimeBins-1]->Print(psname);
+
+//   TFile input("./prueba.root", "RECREATE");
+
+//    for (UInt_t bin=0; bin<numberTimeBins; bin++)
+//      {
+//        ((TH1F*)alphaHistoOn[bin])->Write();
+//        ((TH1F*)alphaHistoOff[bin])->Write();
+//        ((TH2F*)srcposHistoOn[bin])->Write();
+//        ((TH2F*)srcposHistoOff[bin])->Write();
+//        ((TH1F*)coszenithHistoOn[bin])->Write();
+//      }
+
+//    input.Close();
 
   // ############################################################################
@@ -1044,64 +815,58 @@
   // ############################################################################
 
-  Double_t norm_on_abs  = (Double_t) hist_on_abs->Integral((Int_t)bkgnormmin*nbins_abs/90+1,(Int_t)bkgnormmax*nbins_abs/90+1);
-  Double_t exces_on_abs = (Double_t) hist_on_abs->Integral((Int_t)sigexccmin*nbins_abs/90+1,(Int_t)sigexccmax*nbins_abs/90+1);
-  Double_t norm_off_abs  = (Double_t) hist_off_abs->Integral((Int_t)bkgnormmin*nbins_abs/90+1,(Int_t)bkgnormmax*nbins_abs/90+1);
-  Double_t exces_off_abs = (Double_t) hist_off_abs->Integral((Int_t)sigexccmin*nbins_abs/90+1,(Int_t)sigexccmax*nbins_abs/90+1);
+  Double_t norm_on_abs  = (Double_t) hAlpha_on_abs->Integral((Int_t)bkgnormmin*nbins_abs/90+1,(Int_t)bkgnormmax*nbins_abs/90+1);
+  Double_t exces_on_abs = (Double_t) hAlpha_on_abs->Integral((Int_t)sigexccmin*nbins_abs/90+1,(Int_t)sigexccmax*nbins_abs/90+1);
+  Double_t norm_off_abs  = (Double_t) hAlpha_off_abs->Integral((Int_t)bkgnormmin*nbins_abs/90+1,(Int_t)bkgnormmax*nbins_abs/90+1);
+  Double_t exces_off_abs = (Double_t) hAlpha_off_abs->Integral((Int_t)sigexccmin*nbins_abs/90+1,(Int_t)sigexccmax*nbins_abs/90+1);
   Double_t norm = norm_on_abs/norm_off_abs;
 
   char text_tit_alpha[256];
   sprintf(text_tit_alpha, " Alpha Plot On and Off ");
-  hist_off_abs->SetTitle(text_tit_alpha);
-  hist_on_abs->SetTitle(text_tit_alpha);
+  hAlpha_off_abs->SetTitle(text_tit_alpha);
+  hAlpha_on_abs->SetTitle(text_tit_alpha);
 
   Double_t excess  = exces_on_abs - exces_off_abs*norm;
   Double_t sign    = excess / sqrt( exces_on_abs + norm*norm*exces_off_abs );
-  Double_t int_off = (Double_t) hist_off_abs->Integral(1, 18);
-  int hist_on_entries  = (int) hist_on_abs->GetEntries();
-  int hist_off_entries = (int) hist_off_abs->GetEntries();
+  Double_t int_off = (Double_t) hAlpha_off_abs->Integral(1, 18);
+  int hAlpha_on_entries  = (int) hAlpha_on_abs->GetEntries();
+  int hAlpha_off_entries = (int) hAlpha_off_abs->GetEntries();
     
   cout << "---> Normalization F factor =\t" << norm <<endl;
   cout << "---> Excess =\t\t\t" << excess <<endl;
   cout << "---> Significancia =\t\t" << sign <<endl;    
-  cout << "---> entries on   =\t\t" << hist_on_entries  <<endl;
-  cout << "---> entries off  =\t\t" << hist_off_entries <<endl;
+  cout << "---> entries on   =\t\t" << hAlpha_on_entries  <<endl;
+  cout << "---> entries off  =\t\t" << hAlpha_off_entries <<endl;
   cout << "---> integral off =\t\t" << int_off <<endl;
 
   Double_t shiftx;
 
-  //
-  //Create the display -> from now on, all histos are plotted
-  MStatusDisplay *display = new MStatusDisplay;
-  display->SetUpdateTime(3000);
-  display->Resize(850,700);
-  
   // ############################################################################
   // Draw SIZE
   // ############################################################################
-  display->AddTab("SIZE");
+  TCanvas *c1 = new TCanvas;
 
   gPad->cd();
 
   gPad->SetLogy();
-  hist_size_on->Sumw2();
-  hist_size_off->Sumw2();
-  hist_size_off->Scale(norm); 
-  hist_size_on->SetLineColor(kBlack);
-  hist_size_on->SetMarkerStyle(21);
-  hist_size_on->SetMarkerSize(0.7);
-  hist_size_on->SetMarkerColor(kBlack);
-  hist_size_off->SetFillColor(46);
-  hist_size_off->SetLineColor(46);
-  hist_size_off->SetFillStyle(3004); //(1001)-> To set the pad NOT transparent and solid; (3004)-> pattern lines
-  hist_size_off->SetMinimum(0.1);
-  hist_size_on->SetMinimum(0.1);
-  hist_size_on->SetTitle("SIZE distribution");
-  hist_size_off->SetTitle("SIZE distribution");
-
-  hist_size_on->DrawCopy("E1P");
+  hSize_on->Sumw2();
+  hSize_off->Sumw2();
+  hSize_off->Scale(norm); 
+  hSize_on->SetLineColor(kBlack);
+  hSize_on->SetMarkerStyle(21);
+  hSize_on->SetMarkerSize(0.7);
+  hSize_on->SetMarkerColor(kBlack);
+  hSize_off->SetFillColor(46);
+  hSize_off->SetLineColor(46);
+  hSize_off->SetFillStyle(3004); //(1001)-> To set the pad NOT transparent and solid; (3004)-> pattern lines
+  hSize_off->SetMinimum(0.1);
+  hSize_on->SetMinimum(0.1);
+  hSize_on->SetTitle("SIZE distribution");
+  hSize_off->SetTitle("SIZE distribution");
+
+  hSize_on->DrawCopy("E1P");
 
   // move stat box to make them all visible
   gPad->Update();
-  TPaveStats* pavs_on_size = (TPaveStats*) hist_size_on->GetListOfFunctions()->FindObject("stats");
+  TPaveStats* pavs_on_size = (TPaveStats*) hSize_on->GetListOfFunctions()->FindObject("stats");
   if(pavs_on_size){
     shiftx = pavs_on_size->GetX2NDC() - pavs_on_size->GetX1NDC();
@@ -1112,14 +877,14 @@
   gPad->Update();
 
-  hist_size_off->DrawCopy("HISTSAME");
-  hist_size_off->DrawCopy("ESAME");
+  hSize_off->DrawCopy("HISTSAME");
+  hSize_off->DrawCopy("ESAME");
 
   gPad->Modified();
   gPad->Update();
 
-  Double_t chisize = ChiSquareNDof((TH1D*)hist_size_on,(TH1D*)hist_size_off);
+  Double_t chisize = ChiSquareNDof((TH1D*)hSize_on,(TH1D*)hSize_off);
 
   Double_t x_label_pos  = log10(1000000)*0.7;
-  Double_t y_label_pos  = log10((hist_size_on->GetBinContent(hist_size_on->GetMaximumBin()))/2.);
+  Double_t y_label_pos  = log10((hSize_on->GetBinContent(hSize_on->GetMaximumBin()))/2.);
   Double_t textsize = 0.03;
 
@@ -1134,30 +899,32 @@
   gPad->Update();
 
+  c1->Print(psname);
+
   // ############################################################################
   // DrawCopy DIST
   // ############################################################################
-  display->AddTab("DIST");
+  TCanvas *c2 = new TCanvas;
 
   gPad->cd();
 
-  hist_dist_on->Sumw2();
-  hist_dist_off->Sumw2();
-  hist_dist_off->Scale(norm); 
-  hist_dist_on->SetLineColor(kBlack);
-  hist_dist_on->SetMarkerStyle(21);
-  hist_dist_on->SetMarkerSize(0.7);
-  hist_dist_on->SetMarkerColor(kBlack);
-  hist_dist_off->SetFillColor(46);
-  hist_dist_off->SetLineColor(46);
-  hist_dist_off->SetFillStyle(3004); //(1001)-> To set the pad NOT transparent and solid; (3004)-> pattern lines
-  hist_dist_off->SetMinimum(0.);
-  hist_dist_on->SetTitle("DIST distribution");
-  hist_dist_off->SetTitle("DIST distribution");
-
-  hist_dist_on->DrawCopy("E1P");
+  hDist_on->Sumw2();
+  hDist_off->Sumw2();
+  hDist_off->Scale(norm); 
+  hDist_on->SetLineColor(kBlack);
+  hDist_on->SetMarkerStyle(21);
+  hDist_on->SetMarkerSize(0.7);
+  hDist_on->SetMarkerColor(kBlack);
+  hDist_off->SetFillColor(46);
+  hDist_off->SetLineColor(46);
+  hDist_off->SetFillStyle(3004); //(1001)-> To set the pad NOT transparent and solid; (3004)-> pattern lines
+  hDist_off->SetMinimum(0.);
+  hDist_on->SetTitle("DIST distribution");
+  hDist_off->SetTitle("DIST distribution");
+
+  hDist_on->DrawCopy("E1P");
 
   // move stat box to make them all visible
   gPad->Update();
-  TPaveStats* pavs_on_dist = (TPaveStats*) hist_dist_on->GetListOfFunctions()->FindObject("stats");
+  TPaveStats* pavs_on_dist = (TPaveStats*) hDist_on->GetListOfFunctions()->FindObject("stats");
   if(pavs_on_dist){
     shiftx = pavs_on_dist->GetX2NDC() - pavs_on_dist->GetX1NDC();
@@ -1168,12 +935,12 @@
   gPad->Update();
 
-  hist_dist_off->DrawCopy("HISTSAME");
-  hist_dist_off->DrawCopy("ESAME");
-  hist_dist_on->DrawCopy("E1PSAME");
-
-  Double_t chidist = ChiSquareNDof((TH1D*)hist_dist_on,(TH1D*)hist_dist_off);
-
-  x_label_pos  = distmax[0]*0.7;
-  y_label_pos  = hist_dist_on->GetBinContent(hist_dist_on->GetMaximumBin())/2.;
+  hDist_off->DrawCopy("HISTSAME");
+  hDist_off->DrawCopy("ESAME");
+  hDist_on->DrawCopy("E1PSAME");
+
+  Double_t chidist = ChiSquareNDof((TH1D*)hDist_on,(TH1D*)hDist_off);
+
+  x_label_pos  = distmax[numberSizeBins-1]*0.7;
+  y_label_pos  = hDist_on->GetBinContent(hDist_on->GetMaximumBin())/2.;
 
   char text_dist[256];
@@ -1187,29 +954,31 @@
   gPad->Update();
 
+  c2->Print(psname);
+
    // ############################################################################
   // DrawCopy WIDTH
   // ############################################################################
-  display->AddTab("WIDTH");
+  TCanvas *c3 = new TCanvas;
 
   gPad->cd();
 
-  hist_width_off->Sumw2();
-  hist_width_off->Scale(norm); 
-  hist_width_on->SetLineColor(kBlack);
-  hist_width_on->SetMarkerStyle(21);
-  hist_width_on->SetMarkerSize(0.7);
-  hist_width_on->SetMarkerColor(kBlack);
-  hist_width_off->SetFillColor(46);
-  hist_width_off->SetLineColor(46);
-  hist_width_off->SetFillStyle(3004); //(1001)-> To set the pad NOT transparent and solid; (3004)-> pattern lines
-  hist_width_off->SetMinimum(0.);
-  hist_width_on->SetTitle("WIDTH distribution");
-  hist_width_off->SetTitle("WIDTH distribution");
-
-  hist_width_on->DrawCopy("E1P");
+  hWidth_off->Sumw2();
+  hWidth_off->Scale(norm); 
+  hWidth_on->SetLineColor(kBlack);
+  hWidth_on->SetMarkerStyle(21);
+  hWidth_on->SetMarkerSize(0.7);
+  hWidth_on->SetMarkerColor(kBlack);
+  hWidth_off->SetFillColor(46);
+  hWidth_off->SetLineColor(46);
+  hWidth_off->SetFillStyle(3004); //(1001)-> To set the pad NOT transparent and solid; (3004)-> pattern lines
+  hWidth_off->SetMinimum(0.);
+  hWidth_on->SetTitle("WIDTH distribution");
+  hWidth_off->SetTitle("WIDTH distribution");
+
+  hWidth_on->DrawCopy("E1P");
 
   // move stat box to make them all visible
   gPad->Update();
-  TPaveStats* pavs_on_width = (TPaveStats*) hist_width_on->GetListOfFunctions()->FindObject("stats");
+  TPaveStats* pavs_on_width = (TPaveStats*) hWidth_on->GetListOfFunctions()->FindObject("stats");
   if(pavs_on_width){
     shiftx = pavs_on_width->GetX2NDC() - pavs_on_width->GetX1NDC();
@@ -1220,12 +989,12 @@
   gPad->Update();
 
-  hist_width_off->DrawCopy("HISTSAME");
-  hist_width_off->DrawCopy("ESAME");
-  hist_width_on->DrawCopy("E1PSAME");
-
-  Double_t chiwidth = ChiSquareNDof((TH1D*)hist_width_on,(TH1D*)hist_width_off);
-
-  x_label_pos  = widthmax[0]*0.7;
-  y_label_pos  = hist_width_on->GetBinContent(hist_width_on->GetMaximumBin())/2.;
+  hWidth_off->DrawCopy("HISTSAME");
+  hWidth_off->DrawCopy("ESAME");
+  hWidth_on->DrawCopy("E1PSAME");
+
+  Double_t chiwidth = ChiSquareNDof((TH1D*)hWidth_on,(TH1D*)hWidth_off);
+
+  x_label_pos  = widthmax[numberSizeBins-1]*0.7;
+  y_label_pos  = hWidth_on->GetBinContent(hWidth_on->GetMaximumBin())/2.;
 
   char text_width[256];
@@ -1239,30 +1008,32 @@
   gPad->Update();
  
+  c3->Print(psname);
+
   // ############################################################################
   // DrawCopy LENGTH
   // ############################################################################
-  display->AddTab("LENGTH");
+  TCanvas *c4 = new TCanvas;
  
   gPad->cd();
 
-  hist_length_on->Sumw2();
-  hist_length_off->Sumw2();
-  hist_length_off->Scale(norm); 
-  hist_length_on->SetLineColor(kBlack);
-  hist_length_on->SetMarkerStyle(21);
-  hist_length_on->SetMarkerSize(0.7);
-  hist_length_on->SetMarkerColor(kBlack);
-  hist_length_off->SetFillColor(46);
-  hist_length_off->SetLineColor(46);
-  hist_length_off->SetFillStyle(3004); //(1001)-> To set the pad NOT transparent and solid; (3004)-> pattern lines
-  hist_length_off->SetMinimum(0.);
-  hist_length_on->SetTitle("LENGTH distribution");
-  hist_length_off->SetTitle("LENGTH distribution");
-
-  hist_length_on->DrawCopy("E1P");
+  hLength_on->Sumw2();
+  hLength_off->Sumw2();
+  hLength_off->Scale(norm); 
+  hLength_on->SetLineColor(kBlack);
+  hLength_on->SetMarkerStyle(21);
+  hLength_on->SetMarkerSize(0.7);
+  hLength_on->SetMarkerColor(kBlack);
+  hLength_off->SetFillColor(46);
+  hLength_off->SetLineColor(46);
+  hLength_off->SetFillStyle(3004); //(1001)-> To set the pad NOT transparent and solid; (3004)-> pattern lines
+  hLength_off->SetMinimum(0.);
+  hLength_on->SetTitle("LENGTH distribution");
+  hLength_off->SetTitle("LENGTH distribution");
+
+  hLength_on->DrawCopy("E1P");
 
   // move stat box to make them all visible
   gPad->Update();
-  TPaveStats* pavs_on_length = (TPaveStats*) hist_length_on->GetListOfFunctions()->FindObject("stats");
+  TPaveStats* pavs_on_length = (TPaveStats*) hLength_on->GetListOfFunctions()->FindObject("stats");
   if(pavs_on_length){
     shiftx = pavs_on_length->GetX2NDC() - pavs_on_length->GetX1NDC();
@@ -1273,12 +1044,12 @@
   gPad->Update();
 
-  hist_length_off->DrawCopy("HISTSAME");
-  hist_length_off->DrawCopy("ESAME");
-  hist_length_on->DrawCopy("E1PSAME");
-
-  Double_t chilength = ChiSquareNDof((TH1D*)hist_length_on,(TH1D*)hist_length_off);
-
-  x_label_pos  = lengthmax[0]*0.7;
-  y_label_pos  = hist_length_on->GetBinContent(hist_length_on->GetMaximumBin())/2.;
+  hLength_off->DrawCopy("HISTSAME");
+  hLength_off->DrawCopy("ESAME");
+  hLength_on->DrawCopy("E1PSAME");
+
+  Double_t chilength = ChiSquareNDof((TH1D*)hLength_on,(TH1D*)hLength_off);
+
+  x_label_pos  = lengthmax[numberSizeBins-1]*0.7;
+  y_label_pos  = hLength_on->GetBinContent(hLength_on->GetMaximumBin())/2.;
 
   char text_length[256];
@@ -1292,33 +1063,35 @@
   gPad->Update();
 
-  // ############################################################################
+  c4->Print(psname);
+
+ // ############################################################################
   // DrawCopy normalized ALPHA plot
   // ############################################################################
-  display->AddTab("ALPHA");
+  TCanvas *c5 = new TCanvas;
   
   gPad->cd();
 
-  hist_on_abs->Sumw2();
-  hist_off_abs->SetStats(0);
-  hist_off_abs->Sumw2();
-  hist_off_abs->Scale(norm); 
-  hist_on_abs->SetStats(0); //-> Do NOT show the legend with statistics
-  hist_on_abs->SetLineColor(kBlack);
-  hist_on_abs->SetMarkerStyle(21);
-  //hist_on_abs->SetMarkerSize();
-  hist_on_abs->SetMarkerColor(kBlack);
-  hist_on_abs->SetMarkerSize(0.7);
-  hist_off_abs->SetFillColor(46);
-  hist_off_abs->SetLineColor(46);
-  hist_off_abs->SetFillStyle(3004); //(1001)-> To set the pad NOT transparent and solid; (3004)-> pattern lines
-  hist_off_abs->SetMinimum(0.);
-  hist_on_abs->SetTitle("Alpha plot");
-  hist_off_abs->SetTitle("Alpha plot");
-
-  
-  hist_on_abs->DrawCopy("E1P");
-  hist_off_abs->DrawCopy("HISTSAME");
-  hist_off_abs->DrawCopy("ESAME");
-  hist_on_abs->DrawCopy("E1PSAME");
+  hAlpha_on_abs->Sumw2();
+  hAlpha_off_abs->SetStats(0);
+  hAlpha_off_abs->Sumw2();
+  hAlpha_off_abs->Scale(norm); 
+  hAlpha_on_abs->SetStats(0); //-> Do NOT show the legend with statistics
+  hAlpha_on_abs->SetLineColor(kBlack);
+  hAlpha_on_abs->SetMarkerStyle(21);
+  //hAlpha_on_abs->SetMarkerSize();
+  hAlpha_on_abs->SetMarkerColor(kBlack);
+  hAlpha_on_abs->SetMarkerSize(0.7);
+  hAlpha_off_abs->SetFillColor(46);
+  hAlpha_off_abs->SetLineColor(46);
+  hAlpha_off_abs->SetFillStyle(3004); //(1001)-> To set the pad NOT transparent and solid; (3004)-> pattern lines
+  hAlpha_off_abs->SetMinimum(0.);
+  hAlpha_on_abs->SetTitle("Alpha plot");
+  hAlpha_off_abs->SetTitle("Alpha plot");
+
+  
+  hAlpha_on_abs->DrawCopy("E1P");
+  hAlpha_off_abs->DrawCopy("HISTSAME");
+  hAlpha_off_abs->DrawCopy("ESAME");
+  hAlpha_on_abs->DrawCopy("E1PSAME");
 
 
@@ -1326,15 +1099,15 @@
   char text_Fnorm[256], text_excess[256], text_sign[256];
   char text_entries_on[256], text_entries_off[256], text_integral_off[256];
-  int hist_on_entries  = (int) hist_on_abs->GetEntries();
-  int hist_off_entries = (int) hist_off_abs->GetEntries();
+  int hAlpha_on_entries  = (int) hAlpha_on_abs->GetEntries();
+  int hAlpha_off_entries = (int) hAlpha_off_abs->GetEntries();
   sprintf(text_Fnorm,       " F norm =       %.3f", norm);
   sprintf(text_excess,      " Excess =       %.3f", excess);
   sprintf(text_sign,        " Significance = %.3f", sign);
-  sprintf(text_entries_on,  " Entries ON   = %d",  hist_on_entries);
-  sprintf(text_entries_off, " Entries OFF  = %d",  hist_off_entries);
+  sprintf(text_entries_on,  " Entries ON   = %d",  hAlpha_on_entries);
+  sprintf(text_entries_off, " Entries OFF  = %d",  hAlpha_off_entries);
   sprintf(text_integral_off," Integral OFF = %d",  int_off);
   
-  x_label_pos  = alphamax[0]*0.7;
-  y_label_pos  = (hist_on_abs->GetBinContent(hist_on_abs->GetMaximumBin()))/1.6; //2.;
+  x_label_pos  = 90.*0.7;
+  y_label_pos  = (hAlpha_on_abs->GetBinContent(hAlpha_on_abs->GetMaximumBin())); //2.;
   Double_t y_label_step = y_label_pos / 8.;
 
@@ -1359,7 +1132,7 @@
   
 
-  Double_t chialpha = ChiSquareNDof((TH1D*)hist_on_abs,(TH1D*)hist_off_abs);
-
-  y_label_pos  = (hist_on_abs->GetBinContent(hist_on_abs->GetMaximumBin()))/2.;
+  Double_t chialpha = ChiSquareNDof((TH1D*)hAlpha_on_abs,(TH1D*)hAlpha_off_abs);
+
+  y_label_pos  = (hAlpha_on_abs->GetBinContent(hAlpha_on_abs->GetMaximumBin()))/2.;
 
   char text_alpha[256];
@@ -1373,36 +1146,38 @@
   gPad->Update();
 
+  c5->Print(psname);
+
   // ############################################################################
   // DrawCopy normalized alpha histos for alpha form -90 to 90 deg.
   // ############################################################################
-  display->AddTab("ALPHA +-90");
+  TCanvas *c6 = new TCanvas;
 
   gPad->cd();
 
-  hist_on->Sumw2();
-  hist_off->SetStats(0);
-  hist_off->Sumw2();
-  hist_off->Scale(norm); 
-  hist_off->SetFillColor(46);
-  hist_off->SetLineColor(46);
-  hist_off->SetFillStyle(3004); //(1001)-> To set the pad NOT transparent and solid; (3004)-> pattern lines
-  hist_off->SetMinimum(0.); 
-  hist_on->SetStats(0); //-> Do NOT show the legend with statistics
-  hist_on->SetLineColor(kBlack);
-  hist_on->SetMarkerStyle(21);
-  hist_on->SetMarkerSize(0.7);
-  hist_on->SetMarkerColor(kBlack);
-  hist_on->SetTitle("Alpha plot form -90 to 90 deg");
-  hist_off->SetTitle("Alpha plot form -90 to 90 deg");
-
-  hist_on->DrawCopy("E1P");
-  hist_off->DrawCopy("HISTSAME");
-  hist_off->DrawCopy("ESAME");
-  hist_on->DrawCopy("E1PSAME");
-
-  Double_t chialpha90 = ChiSquareNDof((TH1D*)hist_on,(TH1D*)hist_off);
-
-  x_label_pos  = alphamax[0]*0.5;
-  y_label_pos  = hist_on->GetBinContent(hist_on->GetMaximumBin())/2.;
+  hAlpha_on->Sumw2();
+  hAlpha_off->SetStats(0);
+  hAlpha_off->Sumw2();
+  hAlpha_off->Scale(norm); 
+  hAlpha_off->SetFillColor(46);
+  hAlpha_off->SetLineColor(46);
+  hAlpha_off->SetFillStyle(3004); //(1001)-> To set the pad NOT transparent and solid; (3004)-> pattern lines
+  hAlpha_off->SetMinimum(0.); 
+  hAlpha_on->SetStats(0); //-> Do NOT show the legend with statistics
+  hAlpha_on->SetLineColor(kBlack);
+  hAlpha_on->SetMarkerStyle(21);
+  hAlpha_on->SetMarkerSize(0.7);
+  hAlpha_on->SetMarkerColor(kBlack);
+  hAlpha_on->SetTitle("Alpha plot form -90 to 90 deg");
+  hAlpha_off->SetTitle("Alpha plot form -90 to 90 deg");
+
+  hAlpha_on->DrawCopy("E1P");
+  hAlpha_off->DrawCopy("HISTSAME");
+  hAlpha_off->DrawCopy("ESAME");
+  hAlpha_on->DrawCopy("E1PSAME");
+
+  Double_t chialpha90 = ChiSquareNDof((TH1D*)hAlpha_on,(TH1D*)hAlpha_off);
+
+  x_label_pos  = 90.*0.5;
+  y_label_pos  = hAlpha_on->GetBinContent(hAlpha_on->GetMaximumBin())/2.;
 
   char text_alpha90[256];
@@ -1416,4 +1191,5 @@
   gPad->Modified();
 
+  c6->Print(psname);
 
   cout << "---> ChiSquare/NDof [Size] =\t\t" << chisize << endl;
@@ -1425,21 +1201,11 @@
 
 
-  display->AddTab("SRCPOS ON");
-  TH2F *hist_srcpos_on = (TH2F*)hSrcPos_on.GetHist();
-  hist_srcpos_on->DrawCopy("BOX");
-
-  display->AddTab("SRCPOS OFF");
-  TH2F *hist_srcpos_off = (TH2F*)hSrcPos_off.GetHist();
-  hist_srcpos_off->DrawCopy("BOX");
-
-//   display->AddTab("EVTNUM ON");
-//   TH1F *hist_evtnum_on = (TH1F*)hDAQEvtNumber_on.GetHist();
-//   hist_evtnum_on->DrawCopy();
-
-//   display->AddTab("EVTNUM OFF");
-//   TH1F *hist_evtnum_off = (TH1F*)hDAQEvtNumber_off.GetHist();
-//   hist_evtnum_off->DrawCopy();
-
-    }  
+  TCanvas *c7 = new TCanvas;
+  hSrcPos_on->DrawCopy("BOX");
+  c7->Print(psname);
+
+  TCanvas *c8 = new TCanvas;
+  hSrcPos_off->DrawCopy("BOX");
+  c8->Print(closepsname);
 
   cout << "Done!!" <<endl;
