Index: /trunk/MagicSoft/Mars/mtemp/mifae/library/MControlPlots.cc
===================================================================
--- /trunk/MagicSoft/Mars/mtemp/mifae/library/MControlPlots.cc	(revision 4364)
+++ /trunk/MagicSoft/Mars/mtemp/mifae/library/MControlPlots.cc	(revision 4364)
@@ -0,0 +1,176 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Javier Rico     04/2004 <mailto:jrico@ifae.es>
+!
+!   Copyright: MAGIC Software Development, 2000-2004
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// MControlPlots
+//
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <fstream>
+
+#include "MParList.h"
+#include "MControlPlots.h"
+#include "MIslands.h"
+#include "MHCamera.h"
+#include "MGeomCamMagic.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MControlPlots);
+
+using namespace std;
+
+static const TString gsDefName  = "MControlPlots";
+static const TString gsDefTitle = "Produce some control plots";
+
+// -------------------------------------------------------------------------
+//
+// Constructor
+//
+MControlPlots::MControlPlots(TString filename,const char* name, const char* title)
+  : fMode(kOn), fFileName(filename), fGeomCam(NULL), fIslands(NULL), fProduceFile(kTRUE)
+{
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
+
+    fCameraHisto[kOn] = NULL;
+    fCameraHisto[kOff] = NULL;
+}
+// -------------------------------------------------------------------------
+//
+// Destructor
+//
+MControlPlots::~MControlPlots()
+{
+  if(fGeomCam)
+    delete fGeomCam;
+
+  if(fCameraHisto[kOn])
+    delete fCameraHisto[kOn];
+  if(fCameraHisto[kOff])
+    delete fCameraHisto[kOff];
+}
+
+
+// -------------------------------------------------------------------------
+//
+// Look for needed containers.
+//
+Int_t MControlPlots::PreProcess(MParList* pList)
+{ 
+  // FIXME! only valid for Magic geometry for the time being!
+  fGeomCam = new MGeomCamMagic;
+
+  // look for MIslands object
+  fIslands = (MIslands*)pList->FindObject("MIslands1");
+  if (!fIslands)
+    *fLog << warn << AddSerialNumber("MIslands") << " [MIslands] not found... Some control plots will not be produced" << endl;
+  else
+    fCameraHisto[fMode] = new MHCamera(*fGeomCam,"Survive","Pixels surviving Image Cleaning");
+
+  return kTRUE;
+}
+
+// -------------------------------------------------------------------------
+//
+//
+Int_t MControlPlots::Process()
+{  
+  if(!fIslands) return kTRUE;
+
+  for (UInt_t i=0;i<fGeomCam->GetNumPixels();i++)
+    {
+      //      cout << fIslands->GetIslId(i) << " ";
+      if (fIslands->GetIslId(i)>=0)
+	{
+	  fCameraHisto[fMode]->Fill(i,1);
+	  fCameraHisto[fMode]->SetUsed(i);
+	}
+    }
+  //  cout << endl;
+  return kTRUE;
+}
+
+// -------------------------------------------------------------------------
+//
+//
+Int_t MControlPlots::PostProcess()
+{
+  fCameraHisto[fMode]->SetEntries(fGeomCam->GetNumPixels());
+
+  if(!fProduceFile) return kTRUE;
+  if(fProduceFile && !fFileName.Length())
+    {
+      *fLog << warn <<  "MControlPlots::PostProcess Warning: output file requested but no name for it" << endl;
+      return kTRUE;
+    }
+
+  TCanvas* c = new TCanvas("survivals","Pixels surviving Image Cleaning",800,800);
+
+  // in case both on and off histos are present, print both and the difference between them
+  if(fCameraHisto[kOn] && fCameraHisto[kOff])
+    {      
+      MHCamera diff(*fGeomCam,"Diff","Pixels surviving Image Cleaning");
+  
+      for(Int_t i=1;i<=diff.GetSize()-2;i++)
+	{
+	  diff.SetBinContent(i,(Double_t)fCameraHisto[kOn]->GetBinContent(i)-fCameraHisto[kOff]->GetBinContent(i));
+	  diff.SetUsed(i);
+	}      
+      fCameraHisto[kOn]->SetPrettyPalette();
+      fCameraHisto[kOff]->SetPrettyPalette();
+      diff.SetPrettyPalette();
+
+      c->Divide(2,2);
+          
+      c->cd(1);
+      fCameraHisto[kOn]->Draw();
+      gPad->Modified();
+      gPad->Update();
+
+      c->cd(2);
+      fCameraHisto[kOff]->Draw();
+      gPad->Modified();
+      gPad->Update();
+
+      c->cd(3);
+      diff.Draw();
+      gPad->Modified();
+      gPad->Update();      
+    }
+  // plot the existing histo
+  else
+    {
+      c->cd(1);
+      fCameraHisto[fMode]->Draw();
+      gPad->Modified();
+      gPad->Update();
+    }
+  
+  c->SaveAs(fFileName);
+  delete c;  
+  return kTRUE;
+}
Index: /trunk/MagicSoft/Mars/mtemp/mifae/library/MControlPlots.h
===================================================================
--- /trunk/MagicSoft/Mars/mtemp/mifae/library/MControlPlots.h	(revision 4364)
+++ /trunk/MagicSoft/Mars/mtemp/mifae/library/MControlPlots.h	(revision 4364)
@@ -0,0 +1,43 @@
+#ifndef MARS_MControlPlots
+#define MARS_MControlPlots
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class TString;
+class MIslands;
+class MGeomCam;
+class MHCamera;
+
+class MControlPlots : public MTask
+{
+ public:
+  enum OnOffMode_t {kOn=0,kOff};
+  
+ private:
+  OnOffMode_t  fMode;           // On/Off data mode 
+  TString      fFileName;       // name of the ps file
+  MGeomCam*    fGeomCam;        // pointer to camera geometry object
+  MIslands*    fIslands;        // pointer to the island object
+  MHCamera*    fCameraHisto[2]; // pointer to camera histos
+  Bool_t       fProduceFile;    // flag to produce the ouput (ps) file
+  
+  Int_t PreProcess(MParList *plist);
+  Int_t Process();
+  Int_t PostProcess();
+
+ public:
+  MControlPlots(TString filename="",const char* name=NULL, const char* title=NULL);
+
+  virtual ~MControlPlots();
+
+  void SetFilename(TString fname)           {fFileName=fname;}
+  void SetMode(OnOffMode_t mode)            {fMode=mode;}
+  void SetProduceFile(Bool_t mod=kTRUE)     {fProduceFile=mod;}  
+
+  ClassDef(MControlPlots, 0) // task to produce some control plots
+};
+
+#endif
+
