Index: /trunk/MagicSoft/Mars/mtemp/mmpi/macros/SCDynamicalSupercutsApplied.C
===================================================================
--- /trunk/MagicSoft/Mars/mtemp/mmpi/macros/SCDynamicalSupercutsApplied.C	(revision 4412)
+++ /trunk/MagicSoft/Mars/mtemp/mmpi/macros/SCDynamicalSupercutsApplied.C	(revision 4412)
@@ -0,0 +1,273 @@
+// The aim of this macro is to show the cuts applied to the 
+// events that survive the g/h separation cuts + the alpha cut.
+// The macro can be modified easily to show other things...
+
+// This program reads a TTree (specified by the user) and 
+// stores the array containing the variables specified by 
+// the user into pointer to arrays. This is done through 
+// the member function TTree::Draw()
+
+// Selection rules (cuts) are allowed. In such case, only 
+// the variables of the events that pass the cuts specified are 
+// stored into the arrays. 
+
+
+// It  works with arrays of pointers 
+// and plot N quantities in the N pads of the same Canvas.
+// single strings that contain
+// the quantities to be plotted are used.
+
+// This program is an alternative to another (faster?) more 
+// professional way of getting info from a Tree.
+
+
+// As input, this macro needs a root file that is 
+// generated by the SupercutsONOFF programs, which is 
+// the root file containing the TTrees with the needed info.
+
+// The user must write
+
+// 1) Name of the root file with the info (Path included!!)
+
+// 2) Name of the output ps file produced by the macro (with path included!!)
+
+
+gROOT -> Reset();
+
+void SCDynamicalSupercutsApplied()
+{
+
+
+
+
+  char* RootFile = {"/.magic/magicserv01/scratch/Daniel/SuperCuts/Mrk421/2004_04_22/4slices_3520_nc/E800_1200_Opt_MC/RootFileDynCuts.root"};
+
+  char* OutputPsFilename = {"/.magic/magicserv01/scratch/Daniel/SuperCuts/Mrk421/2004_04_22/4slices_3520_nc/E800_1200_Opt_MC/DynamicalCutsLengthWidthDistApplied.eps"};
+  
+  
+  char* Xaxis = "log(SIZE/[photons])";
+  
+  char* YaxisVector[6] = {"LENGTH UP [\\circ]", "LENGTH LOW [\\circ]", 
+		       "WIDTH UP [\\circ]", "WIDTH LOW [\\circ]", 
+		       "DIST UP [\\circ]", "DIST LOW [\\circ]"}; 
+
+  
+  
+
+
+  
+  
+ 
+
+
+// Name of the root file that contains the Tree
+    char* TreeName = {"SupercutsAppliedTrainONThetaRange0_1570mRad"}; // Name of the Tree that contains the variables that have to plotted
+   
+
+    
+    const Int_t NQuantitiesToBePlot = 6;
+
+    // Write here the quantities to be plot
+    
+    TString QuantitiesToBePlot[NQuantitiesToBePlot] = 
+    {"SupercutsApplied.LengthUp:log10(ShowerParameters.Size)", 
+     "SupercutsApplied.LengthLow:log10(ShowerParameters.Size)", 
+     "SupercutsApplied.WidthUp:log10(ShowerParameters.Size)", 
+     "SupercutsApplied.WidthLow:log10(ShowerParameters.Size)",
+     "SupercutsApplied.DistUp:log10(ShowerParameters.Size)", 
+     "SupercutsApplied.DistLow:log10(ShowerParameters.Size)"};
+
+
+    // Write here the number of rows and columns in the ps file
+
+    const Int_t Nrows = 2;
+    const Int_t Ncolumns = 3;
+
+    // Title of Canvas.. not really important...
+
+    TString CanvasTitle = ("Dynamical cuts in Length, Width and Dist");
+
+    // 0 for not using and 1 for using Selection cut
+    Int_t UseSelectionCut = 1; 
+    // Section rule to be applied in the data to be plotted
+    char* SelectionCut = {"(SupercutsApplied.Hadronness < 0.5) && ShowerParameters.Alpha < 12"}; 
+    
+    
+
+    // Vectors where variables will be stored
+    Int_t ArrayDimension[NQuantitiesToBePlot];
+    Double_t* VarYArray[NQuantitiesToBePlot];
+    Double_t* VarXArray[NQuantitiesToBePlot];
+
+
+    
+
+    // Vector  of pointers to TFile objects and TTree objects that will be used to retrieve 
+    // requested info from root file. 
+
+    TFile* FileVector[NQuantitiesToBePlot];
+    TTree* TreeVector[NQuantitiesToBePlot];
+
+    // Vector of pointers to graph objects where quantities will be plot
+
+    TGraph* GraphVector[NQuantitiesToBePlot];
+
+
+    // Options available for plotting the histo are the following ones:
+    // "prof" -->> Profile
+    // "goff" -->> No draw variables in TTree::Draw()
+    // ""     -->> No special option is set
+
+    char* DrawingOption = {"goff"};
+
+
+    TString selection = UseSelectionCut ? SelectionCut : NULL;
+
+
+
+    // Tree is read and stored in dynamic memory pointed by pointer tree.
+    
+    //  TFile file (RootFile);
+    // TTree* tree = (TTree*) file.Get(TreeName);
+
+
+  
+
+    // Loop in which arrays are retrieved from root file and 
+    // array dimensions (with events surviving the selection)
+    // are retrieved too.
+
+    for (Int_t i = 0; i < NQuantitiesToBePlot; i++)
+      {
+
+
+	FileVector[i] = new TFile(RootFile, "READ");
+
+	TreeVector[i] = (TTree*) FileVector[i] -> Get(TreeName);
+	
+	 // Array dimension of temporal vectors where the variables 
+	// that will be plotted are stored can be modify accordingly 
+	// with the nnumber of events of the Tree
+	
+	TreeVector[i] -> SetEstimate(TreeVector[i] -> GetEntries());
+
+	// Requested info is "plotted"
+
+	TreeVector[i]  -> Draw(QuantitiesToBePlot[i].Data(), selection, DrawingOption);
+
+	
+	// Let's find out the REAL length of the vectors we want 
+	// to get from the tree (Selection rules may have removed some events)
+	
+	ArrayDimension[i] = TreeVector[i] -> GetSelectedRows();
+	
+	// Vectors are retrieved
+
+	VarYArray[i] = TreeVector[i] -> GetV1();
+	VarXArray[i] = TreeVector[i] -> GetV2();
+
+      }
+
+  
+   
+    // Silly info is displayed for testing...
+
+
+   
+    for (Int_t i = 0; i < NQuantitiesToBePlot; i++)
+      {
+	cout << "Events that passed the selection for quantity " 
+	     << QuantitiesToBePlot[i] << " : " << ArrayDimension[i] << endl;
+      }
+
+   
+    // Initialization of the graphs with the info contained in the vectors
+    // Kind of default features are set for all graphs
+
+
+     TAxis* axispointer;
+      
+     
+
+    for (Int_t i = 0; i < NQuantitiesToBePlot; i++)
+      {	
+	GraphVector[i] = new TGraph (ArrayDimension[i], VarXArray[i], VarYArray[i]);
+	
+	GraphVector[i] -> SetTitle(QuantitiesToBePlot[i].Data());
+
+	
+	GraphVector[i]->SetFillColor(19);
+	GraphVector[i]->SetMarkerColor(2);
+	GraphVector[i]->SetMarkerStyle(21);
+	GraphVector[i]->SetMarkerSize(0.5);
+
+	axispointer = GraphVector[i] -> GetXaxis();
+	axispointer -> SetTitle(Xaxis);
+	axispointer -> SetTitleOffset(1.3);
+	axispointer -> SetTitleSize(0.05);
+
+
+	axispointer =  GraphVector[i] -> GetYaxis();
+	axispointer -> SetTitle(YaxisVector[i]);
+	axispointer -> SetTitleOffset(1.5);
+	axispointer -> SetTitleSize(0.05);
+	
+
+      }
+
+
+
+   
+    /*
+    // Let's output some of their components:
+    
+    for ( Int_t i = 0; i < ArrayDimension[]0; i++)
+    {
+	cout << VarXArray[0][i] << "  " <<  VarYArray[0][i] << endl;
+
+    }
+    */
+
+    
+    // TCanvas is defined with the NQuantitiesToBePlot Pads where the graphs 
+    // will be plotted
+
+    TCanvas* Canvas = new TCanvas(CanvasTitle, CanvasTitle, 600, 800);
+    Canvas -> SetBorderMode(0);
+    Canvas -> Divide(Nrows, Ncolumns);
+    
+    
+    // gStyle -> SetFrameFillColor(10);
+    gStyle -> SetPadLeftMargin (0.15);
+    gStyle -> SetPadRightMargin (0.05);
+    gStyle -> SetPadTopMargin (0.00);
+    gStyle -> SetPadBottomMargin (0.20);
+    
+    gStyle -> SetOptTitle(0);
+
+    // Graphs are plot in canvas
+    
+    for (Int_t i = 0; i < NQuantitiesToBePlot; i++)
+      {	
+	Canvas -> cd(i+1);
+	gPad -> SetBorderMode(0);
+	gPad->SetGridx();
+	gPad->SetGridy(); 
+	//gPad -> SetPadTopMargin (0.05);
+	//gPad -> SetPadBottomMargin (0.15);
+	
+	GraphVector[i] -> Draw("AP");
+      }
+    
+    
+
+    Canvas -> SaveAs(OutputPsFilename);
+
+
+}
+    
+
+
+
+
+
Index: /trunk/MagicSoft/Mars/mtemp/mmpi/macros/SCNexSignificanceVSAlphaCut.C
===================================================================
--- /trunk/MagicSoft/Mars/mtemp/mmpi/macros/SCNexSignificanceVSAlphaCut.C	(revision 4412)
+++ /trunk/MagicSoft/Mars/mtemp/mmpi/macros/SCNexSignificanceVSAlphaCut.C	(revision 4412)
@@ -0,0 +1,466 @@
+// This program produces a ps file with 
+// two graphs in the same TPad, but 
+// with different axis. 
+
+// The aim is to plot Nex and significance vs 
+// cut in alpha parameter.
+
+// As input, this macro needs a root file that is 
+// generated by the SupercutsONOFF programs.
+
+// It will read the histograms where Nex and significance 
+// vs alpha are stored and will plot this info in a single 
+// ps file. 
+
+// The user must write
+
+// 1) Name of the root file with the info (Path included!!)
+
+// 2) Name of the output ps file (with path included!!)
+
+// Depending on the values to be plotted the axis scale
+// as well as the axis offsets for labels might have to be 
+// modified. If I have time I will modify the program to 
+// make it automatic...
+
+
+
+
+#include <string.h>
+#include <iostream.h>
+#include <fstream.h>
+#include <iomanip.h>
+#include <stdlib.h>
+#include <math.h>
+
+
+gROOT -> Reset();
+
+void SCNexSignificanceVSAlphaCut() 
+{
+
+  
+  
+  char* SCRootFile = {"/.magic/magicserv01/scratch/Daniel/SuperCuts/Mrk421/2004_04_22/4slices_3520_nc/E800_1200_Opt/RootFileDynCuts.root"};
+
+  char* output_ps_file = {"/.magic/magicserv01/scratch/Daniel/SuperCuts/Mrk421/2004_04_22/4slices_3520_nc/E800_1200_Opt/NexSignificanceVSCutinAlpha.ps"};
+
+  
+ 
+  char* ps_title = 
+    {"Excess events (green) and significance (red) vs cut in alpha"};
+
+
+
+
+  // Name of the histograms (contained in root file) that contain the number of 
+  // excess events and significance vs alpha cut
+
+  TString ExcessEventsHistoName = ("NexVSAlphaTrainThetaRange0_1570mRad");
+  TString SignificanceHistoName = ("SignificanceVSAlphaTrainThetaRange0_1570mRad");
+
+
+  // Axis titles
+
+  char* xaxis_title = "Cut in alpha (degrees)";
+  char* yaxis_title = "Excess events";
+  char* yaxis_2_title = "Significance";
+
+  // Axis for plot
+
+  const Double_t pad_xlow = 0;
+  const Double_t pad_ylow = 0;
+  const Double_t pad_xup = 30;
+  const Double_t pad_yup = 1000;
+
+  
+  
+  
+  // Axis labels offsets for plot
+ 
+  const Double_t xaxis_label_xoffset_pad = 8;
+  const Double_t xaxis_label_yoffset_pad = -300;
+  const Double_t yaxis_label_xoffset_pad = -5;
+  const Double_t yaxis_label_yoffset_pad = 1200;
+  const Double_t yaxis_2_label_xoffset_pad = 35;
+  const Double_t yaxis_2_label_yoffset_pad = 1200;
+
+ 
+
+  // Vector of pointer to histograms that will be plotted
+  // Colors and marker types are also defined 
+
+
+  const Int_t n_graphs = 2; 
+  TGraph* graph_vector [n_graphs];
+  Int_t graph_colors_vector[n_graphs] = {3,2};
+  Int_t polimarker_style_vector[n_graphs] = {21,25};
+  char* additional_info_vector[n_graphs] = 
+    {"Excess events", "Significance"};
+
+
+
+  // TMP VARIABLES
+
+  Int_t tmp_int = 0;
+
+  TH1F* histo1;
+  TH1F* histo2;
+
+
+ 
+  Double_t y_axis_2_min_value = 0.0;
+  Double_t y_axis_2_max_value = 0.0;
+  
+  Double_t graph_y_minmax_vector [n_graphs][2];
+  // It contains y values min and max for graphs that 
+  // are plotted.
+  
+  Double_t graph_2_scale_factor = 0.0;
+
+  // ******************************************************************
+  // Data is read from the histograms contained in the input root file 
+  // and stored in vectors 
+  // ******************************************************************
+  
+  TFile rootfile (SCRootFile, "READ");
+
+  histo1 = (TH1F*) rootfile.Get(ExcessEventsHistoName);
+  histo2 = (TH1F*) rootfile.Get(SignificanceHistoName);
+
+  
+
+  // check that dimension is the same 
+
+  if (histo1 -> GetNbinsX() != histo2 -> GetNbinsX())
+    {
+      cout << "Dimension of histogram " << ExcessEventsHistoName 
+	   << " is not equal to dimension of histogram "<< SignificanceHistoName << endl
+	   << "Aborting ..." << endl;
+      
+      Exit(1);
+    }
+
+  
+  tmp_int = histo1 -> GetNbinsX();
+  
+  const Int_t vectors_dimension = tmp_int;
+
+
+  // Vectors that will be used to plot graphs are defined and filled
+
+  Double_t alpha_cut_vector[vectors_dimension] = {0.0};
+  Double_t excess_events_vector[vectors_dimension] = {0.0};
+  Double_t significance_vector[vectors_dimension] = {0.0};
+
+
+  for (Int_t i = 0 ; i < vectors_dimension; i++)
+    {
+      alpha_cut_vector[i] =  histo1-> GetBinCenter(i+1) + ((histo1->GetBinWidth(i+1))/2);
+      excess_events_vector[i] = histo1-> GetBinContent(i+1);
+      significance_vector[i] = histo2-> GetBinContent(i+1);
+    }
+
+  
+  
+
+   // Dynamic memory from is released and root file closed 
+
+  delete histo1;
+  delete histo2;
+
+  rootfile.Close();
+
+
+    // Information retrieved from histos is displayed in terminal
+  
+  cout << endl
+       << "Cut in alpha, excess events and significance values retrieved from root file: "
+       << endl;
+
+  for (Int_t i = 0 ; i < vectors_dimension; i++)
+    {
+      cout << alpha_cut_vector[i] << "        " 
+	   << excess_events_vector[i] << "        " 
+	   << significance_vector[i] << endl;
+    }
+  
+
+
+
+
+
+  //******************************************************
+  // Graph 2 is scaled so that it can be plotted in the 
+  // same TPad... kind of a trick in root.
+
+  // First, values min and max are needed for the 
+  // graphs to be plotted.
+
+  graph_y_minmax_vector [0][0] = pad_ylow;
+  graph_y_minmax_vector [0][1] = find_max (excess_events_vector, 
+					   vectors_dimension);
+    
+cout << " min set to : " <<  graph_y_minmax_vector [0][0] << endl;
+cout << " max set to : " <<  graph_y_minmax_vector [0][1] << endl;
+
+  graph_y_minmax_vector [1][0] = 0;
+					
+  graph_y_minmax_vector [1][1] = find_max (significance_vector, 
+					   vectors_dimension);
+  //TEST
+  /*
+  cout << graph_y_minmax_vector [0][1] << "  "  
+       << graph_y_minmax_vector [0][0] << endl;
+
+   cout << graph_y_minmax_vector [1][1] << "  "  
+       << graph_y_minmax_vector [1][0] << endl;
+   */
+
+
+   
+  graph_2_scale_factor = 
+    (graph_y_minmax_vector [0][1] - 
+     graph_y_minmax_vector [0][0])/(graph_y_minmax_vector [1][1] 
+				    - graph_y_minmax_vector [1][0]);
+
+  //  cout << "scale factor :  " << graph_2_scale_factor << endl;
+
+  for (Int_t i = 0 ; i < vectors_dimension; i++)
+    { 
+      
+      significance_vector[i] = ((graph_2_scale_factor * significance_vector[i])
+			   + graph_y_minmax_vector [0][0]);
+    }
+  
+  // ***********  END OF SCALING   ********************************
+
+  // Graphs are initialized and filled with vectors
+
+   
+  // Graph i initialized and filled 
+  graph_vector[0] = new TGraph(vectors_dimension,
+			       alpha_cut_vector, 
+			       excess_events_vector);
+      
+
+  graph_vector[1] = new TGraph(vectors_dimension,
+			       alpha_cut_vector, 
+			       significance_vector);
+  
+  // Some properties of graphs are set
+
+  for (Int_t i = 0; i < n_graphs; i++)
+    {
+      graph_vector[i]->SetTitle();
+      graph_vector[i]->SetFillColor(19);
+      graph_vector[i]->SetLineColor(graph_colors_vector[i]);
+      graph_vector[i]->SetLineWidth(1);
+      graph_vector[i]->SetMarkerColor(graph_colors_vector[i]);
+      graph_vector[i]->SetMarkerStyle(polimarker_style_vector[i]);
+      graph_vector[i]->SetMarkerSize(1);
+    }
+
+
+// Graphgrams are plotted
+
+
+ TCanvas *Window = new TCanvas("Plot","Plot",600,600); 
+  
+ gStyle->SetOptStat(0);   
+ // So that statistic information is not printed
+
+  Window -> SetFillColor(10);
+  gStyle -> SetFrameFillColor(10);
+  gStyle -> SetPadLeftMargin (0.15);
+  gStyle -> SetPadRightMargin (0.15);
+  gStyle -> SetPadTopMargin (0.05);
+  gStyle -> SetPadBottomMargin (0.15);
+
+  TPaveText *title = new TPaveText (.05,.95,.95,.99);
+  title -> SetFillColor (38);  
+  title -> AddText (ps_title);
+  title -> Draw();
+
+ 
+  
+  
+  /* TPad(const char *name, const char *title, 
+     Double_t xlow, Double_t ylow, 
+     Double_t xup, Double_t yup, Color_t color, 
+     Short_t bordersize,Short_t bordermode) 
+     : TVirtualPad(name,title,xlow,ylow,xup,yup,color,
+     bordersize,bordermode) 
+  */
+
+  TPad *pad = new TPad ("plot", "plot",0.0, 0.0, 1.0, 0.92, 
+			10, 0, 0); 
+  // I do not want any border effect.
+  pad -> Draw();
+   
+   
+  // Axis and axis labels for pad1 are created and drawn.
+
+  pad -> cd();
+  pad -> SetGrid(1,1); // Grid for x axis and for y axis.
+  pad -> DrawFrame(pad_xlow,pad_ylow,pad_xup,pad_yup); 
+  // dimensions of the pad are set.
+  
+  
+   
+  // Labels of the graph are set
+
+  TText *t = new TText();
+  t->SetTextFont(62);
+  t->SetTextColor(1);
+  t->SetTextSize(0.05);
+  t->SetTextAlign(11);
+
+  // X axis
+  t->SetTextAngle(0);
+  t->DrawText(xaxis_label_xoffset_pad,
+	      xaxis_label_yoffset_pad,
+	      xaxis_title);
+  // Y axis
+  t->SetTextAngle(90); 
+  t->DrawText(yaxis_2_label_xoffset_pad,
+	      yaxis_2_label_yoffset_pad, 
+	      yaxis_2_title);
+
+ 
+  
+
+  // Graphs are plotted in pad
+
+
+  for (Int_t j = 0; j < n_graphs; j++)
+    {  
+      
+      pad -> cd();
+      graph_vector[j]-> Draw("LP");
+      // "A" option is removed in order to 
+      //control de dimensionsn of the pad, 
+      // by means of the " DrawFrame()" function.
+      
+    }
+  
+  // **************************************************
+  // Second Axis is drawn with its label
+  
+  // First of all we must look for units at
+  // bottom and top of axis. This is found 
+
+  
+  y_axis_2_min_value = ((pad_ylow - graph_y_minmax_vector [0][0])/
+			graph_2_scale_factor);
+
+  y_axis_2_max_value = ((pad_yup - graph_y_minmax_vector [0][0])/
+			graph_2_scale_factor);
+
+  
+
+  TGaxis *axis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),
+			    gPad->GetUxmax(), gPad->GetUymax(),
+			    y_axis_2_min_value,
+			    y_axis_2_max_value,510,"+L");
+
+   axis->SetLineColor(1);
+   axis->SetTextColor(1);
+   axis->Draw();
+
+    // Y axis 2
+  t->SetTextAngle(90); 
+  t->DrawText(yaxis_label_xoffset_pad,
+	      yaxis_label_yoffset_pad, 
+	      yaxis_title);
+
+  // Graph information is produced and drawn.
+
+  // Spectrum names
+  /*
+  char info_string[150] = 0;
+  char info_string_tmp [20] = 0;
+  Double_t xpos = 0;
+  Double_t ypos = 0;
+  TText *tt = new TText();
+  tt->SetTextFont(62);
+  tt->SetTextSize(0.04);
+  tt->SetTextAlign(12);
+  tt->SetTextAngle(0);
+  
+  for (Int_t i = 0; i < n_graphs; i++)
+    {
+      if (i < 1)
+	{xpos = 0.15; ypos =  0.91;} 
+      else 
+	{xpos = 0.15; ypos = 0.85;}
+      
+      //xpos = 0.02 + i*0.12 + i*(i-1)*0.15; //for three curves
+      //xpos = 0.1 + i*0.4; // for two curves
+      strcpy(info_string, additional_info_vector[i]);
+      tt->SetTextColor(graph_colors_vector[i]);
+      Window -> cd();
+      tt->DrawText(xpos,ypos,info_string);
+    }
+  */
+
+
+  Window -> SaveAs(output_ps_file);
+
+}
+
+
+
+
+// FUNCTION DEFINITIONS
+
+
+
+
+
+Double_t find_value (Double_t vector[], Int_t dimension, Int_t min_max)
+{
+  Double_t value = vector[0];
+  if (min_max < 0.5) // we look for min
+    {
+      for (Int_t i = 1; i < dimension; i++)
+	{
+	  if (value > vector[i])
+	    {
+	      value = vector[i];
+	    }
+	}
+    }
+
+  else // we look for max
+    {
+      for (Int_t i = 1; i < dimension; i++)
+	{
+	  if (value < vector[i])
+	    {
+	      value = vector[i];
+	    }
+	}
+    }
+
+  return value;
+}
+  
+
+
+Double_t find_min (Double_t vector[], Int_t dimension)
+{
+  Double_t min = 0.0;
+  min = find_value (vector, dimension, 0);
+  return min;
+}
+
+
+
+Double_t find_max (Double_t vector[], Int_t dimension)
+{
+  Double_t max = 0.0;
+  max = find_value (vector, dimension, 1);
+  return max;
+}
+
Index: /trunk/MagicSoft/Mars/mtemp/mmpi/macros/SuperCutsONOFFMacro.C
===================================================================
--- /trunk/MagicSoft/Mars/mtemp/mmpi/macros/SuperCutsONOFFMacro.C	(revision 4412)
+++ /trunk/MagicSoft/Mars/mtemp/mmpi/macros/SuperCutsONOFFMacro.C	(revision 4412)
@@ -0,0 +1,426 @@
+// Silly macro to run the classes that optimize supercuts 
+// using ON and OFF data.
+
+// The user only needs to fill/change the variables that control 
+// the optimization procedure.
+
+
+gROOT -> Reset();
+
+void SuperCutsONOFFMacro()
+{
+  gLog.SetNoColors();
+
+    // File containing the data (ON/OFF DATA and path for files (root/ps))
+
+    // From magicserv01
+    TString  ONDataFilename("/.magic/data16a/mazin/data/Mrk421/2004_04_22/4slices/Hillas_20040422_4sl_time_clean/Mrk421_*_HillasON.root");
+                                       
+    TString  OFFDataFilename("/.magic/data16a/mazin/data/Mrk421/2004_04_22/4slices/Hillas_20040422_4sl_time_clean/Mrk421_*_HillasOFF.root");
+
+    
+    TString PathForFiles ("/mnt/magicserv01/scratch/David/SillyTestForCommiting_July20_2004/");
+
+    
+    // **********************************************
+    // Boolean variables defining the job of the 
+    // macro
+    // **********************************************
+
+    
+
+    // Boolean variable that decides wether data is read from files specified above
+    // (ON/OFF) or read from already existing Matrices (which are obviously stored
+    // in a root file). The names of the files storing those matrices are produced 
+    // automatically using information provided by some of the next variables whose 
+    // values must be specified by user.
+
+    // kTRUE reads alredy existing matrices, and kFALSE read data and produce matrices.
+
+    Bool_t ReadMatrixFromRootFiles = kTRUE; 
+  
+
+    // Boolean variable that controls wether to use the 
+    // TRAIN sample or not.
+    
+
+    Bool_t TrainParams   = kTRUE;  
+
+
+
+    // Variable that allows the user to skip the optimization on the 
+    // train sample. If optimization is skipped (value kTRUE), the
+    // previously optimized supercuts (stored in root file
+    // which is called OptSCParametersONOFFThetaRangeXXXXXmRad.root, and located 
+    // in the directory specified by variable PathForFiles) are used 
+    // on the train and/or the test sample.
+
+    // If value kFALSE, the cuts are optimized.
+    // The optimized cuts will be  written in root file
+    // located in directory specified before. Name of 
+    // the root files is created automatically.
+    
+    Bool_t SkipOptimization = kTRUE;
+  
+
+
+
+
+    // Boolean variable that allows the user to write the initial parameters 
+    // into the root file that will be used to store the optimum cuts.
+    // If ApplyInitialParams = kTRUE , the initial 
+    // parameters are written into this root file, and they 
+    // will be applied to the data (TRAIN/TEST ) 
+    // IF NO OPTIMIZATION PROCEDURE IS PERFORMED.
+    
+    // If cuts are optimized (ie, variable SkipOptimization = kFALSE), 
+    // the cuts applied to the data are the optimized cuts.
+  
+    // NOTE: be aware that, if ApplyInitialSCParams = kTRUE and 
+    // there was a root file with the optimized cuts 
+    // (previously computed), it will be overwritten with the initial 
+    // SC parameters. 
+
+    Bool_t ApplyInitialSCParams = kTRUE;
+    
+
+
+    // Boolean variable that controls wether to use the 
+    // TEST sample or not.
+    
+
+    Bool_t TestParams = kFALSE;  
+
+
+    // Boolean variable that controls wether to combine, OR not, the 
+    // alpha distributions computed (after cuts) for the several theta bins
+    // in which the TRAIN sample was divided.
+
+    Bool_t CombineCosThetaBinsForTrainSample = kFALSE; 
+    
+    // Boolean variable that controls wether to combine, OR not, the 
+    // alpha distribution computed (after cuts) for the several theta bins
+    // in which the TEST sample was divided.
+
+    Bool_t CombineCosThetaBinsForTestSample = kFALSE; 
+    
+
+    // Fraction of ON events used for the training/testing
+    Double_t whichfractiontrain = 0.999;
+    Double_t whichfractiontest = 0.001;
+
+    // Fraction of OFF events used for the training/testing 
+    Double_t whichfractiontrainOFF = 0.999;
+    Double_t whichfractiontestOFF = 0.001;
+
+
+    // Efficiency for gammas when using this set of dynamical cuts
+    // (i.e., fraction of initial gammas that remain after cuts)
+
+    // Current value is the first estimation of the efficiency of cuts
+    // on Mkn421 at a SIZE > 2000 photons
+
+    Double_t gammaeff = 0.6;  
+                         
+
+    // Alpha value (degrees) below which signal is expected
+    
+    Double_t alphasig = 12; 
+
+    // Definition of alpha bkg region (where no signal is expected)
+
+    Double_t alphabkgmin = 30;
+    Double_t alphabkgmax = 90;
+    
+    // Definition of the Size range
+
+    Double_t SizeLow = 800;
+    Double_t SizeUp = 1200;
+//    Double_t SizeUp = 1000000;
+    
+
+     // Definition of binning of alpha plots
+    Int_t NAlphaBins = 35;
+    Double_t AlphaBinLow = -9;
+    Double_t AlphaBinUp = 96;
+
+ 
+    // Boolean variable used to determine wether the normalization factor is 
+    // computed from method 1) or 2)
+    // 1) Using total number of ON and OFF events before cuts, and tuning the factor 
+    //    correcting for "contamination" of gamma events in ON sample 
+    // 2) Using number of ON and OFF events after cuts in the background 
+    //    region determined by variables fAlphaBkgMin-fAlphaBkgMax
+    
+    Bool_t NormFactorFromAlphaBkg = kTRUE; // if kTRUE, method 2) is used
+
+
+    // Boolean variable used to disable the usage ("serious" usage) of the 
+    // quantities computed from fits. This will be useful in those cases 
+    // where there is too few events to perform a decent fit to the 
+    // alpha histograms.
+    
+    Bool_t UseFittedQuantities = kTRUE;
+
+
+    // Boolean variable used to control wether to use theta information 
+    // in the computation of teh dynamical cuts that take place within
+    // class MCT1SupercutsCalc
+    Bool_t NotUseTheta = kTRUE; // kTRUE renoves theta from the parameterization of cuts
+
+    // Boolean variable used to decide wether to use dynamical cuts or static cuts
+    // kTRUE means that static cuts are used.
+    Bool_t UseStaticCuts = kFALSE;
+
+
+
+
+
+    // Name of the Postscript document where all plots
+    // will be saved.
+    // STORAGE OF PSFILE IS NOT WORKING PROPERLY
+    // For the time being, several ps files are produced 
+    // and saved in the directory specified by PathForFiles
+
+    /*
+    TString PsFileName = ("PsTest23.ps");
+    TString CompletePsFileName = (PathForFiles);
+    CompletePsFileName += PsFileName;
+    TPostScript* PsFile = new TPostScript(CompletePsFileName, 111);
+    */
+
+    // Boolean variable used to decide wether initial parameters are 
+    // read from ascii file or not. If kTRUE, parameters are retrieved 
+    // from ascii file. Otherwise, default parameters from MSupercuts 
+    // class are used.
+
+    Bool_t ReadInitParamsFromAsciiFile = kTRUE;
+
+    // Number of SC parameters. The aim of this variable is to cross check 
+    // that the number of parameters read from an ascii file 
+    // is teh one the user wants. 
+
+    Int_t NInitSCPar = 104;
+
+    // Name of  the ascii file containing the 2 columns, the first one 
+    // for initial parameters and the second one for the steps
+    // Name must contain also the path.
+ 
+    const char* InitSCParamAsciiFile = 
+      // {"../InitialSCParametersSteps/InitSCParamsAndStepsDanielModified1.txt"};
+      // {"../InitialSCParametersSteps/FixedStaticCutsInLengthWidthDist.txt"};
+      // {"../InitialSCParametersSteps/FixedStaticCutsInLengthWidthDist11.txt"};
+      // {"../InitialSCParametersSteps/InitSCParamsAndStepsDanielModified1.txt"};
+      // {"../InitialSCParametersSteps/StartingValuesForOptimizationMkn421.txt"};
+      // {"../InitialSCParametersSteps/StartingValuesForOptimizationMkn421DynStaticCutsFixedPol2SizeCut3000.txt"};
+      // {"../InitialSCParametersSteps/StartingValuesForOptimizationMkn421DynWithDistParametersFixed.txt"};
+      // {"../InitialSCParametersSteps/StartingValuesForOptimizationMkn421DynStaticCutsVariablePol2.txt"};
+      // {"../InitialSCParametersSteps/StartingValuesForOptimizationMkn421DynStaticCutsVariablePol2WidthCutLowFixed.txt"};
+      // {"../InitialSCParametersSteps/StartingValuesForOptimizationMkn421DynCutsOnSize.txt"};
+      // {"../InitialSCParametersSteps/StartingValuesForOptimizationMkn421DynCutsOnSizeAndDist.txt"};
+      {"mtemp/mmpi/asciifiles/OptimizedMkn421DynCutsGridWithSelected22pointsMay19.txt"};
+
+
+    // Name of the root file where alpha distributions, TTree objects
+    // with info about the events and cuts applied and  info support histograms 
+    // will be stored. 
+    // Write only the name of the file. The Path 
+    // is the one defined previously
+
+    TString RootFilename = ("RootFileDynCuts.root");
+
+    
+
+    
+    
+
+    // Vector containing the theta bins in which data (ON/OFF train/test)
+    // will be divided. Actually this vector contains the cosinus of 
+    // these theta bins. The dimension of the vector is N+1, where 
+    // N is the number of theta bins intended. The first component of the 
+    // vector is the low bin edge of the first bin, and the last 
+    // vector component the upper bin edge of the last bin.
+
+
+    TArrayD CosThetaRangeVector(2);
+    CosThetaRangeVector[0] = 0.0;
+    //CosThetaRangeVector[1] = 0.825;
+    //CosThetaRangeVector[2] = 0.921; 
+    //CosThetaRangeVector[3] = 0.961; 
+    CosThetaRangeVector[1] = 1.0;
+
+
+    /*
+    TArrayD CosThetaRangeVector(2);
+    CosThetaRangeVector[0] = 0.622;
+    // CosThetaRangeVector[1] = 0.825;
+    //CosThetaRangeVector[2] = 0.921; 
+    //CosThetaRangeVector[0] = 0.961; 
+    CosThetaRangeVector[1] = 0.984;
+    
+    */
+    // Object of MCT1FindSupercutsONOFFThetaLoop created, data that was specified 
+    // above is introduced and ... and the party starts.
+     
+    MFindSupercutsONOFFThetaLoop FindSupercuts("MFindSupercutsONOFFThetaLoop", 
+					       "Optimizer for the supercuts");
+
+    
+    FindSupercuts.SetPathForFiles(PathForFiles);
+
+    FindSupercuts.SetDataONOFFRootFilenames(ONDataFilename, OFFDataFilename);
+
+    FindSupercuts.SetFractionTrainTestOnOffEvents(whichfractiontrain, 
+						  whichfractiontest, 
+						  whichfractiontrainOFF, 
+						  whichfractiontestOFF);
+
+
+    FindSupercuts.SetGammaEfficiency(gammaeff);
+
+
+    FindSupercuts.SetAlphaSig(alphasig);
+
+    // Bkg alpha region is set 
+    FindSupercuts.SetAlphaBkgMin(alphabkgmin);
+    FindSupercuts.SetAlphaBkgMax(alphabkgmax);
+
+    // alpha bkg and signal region set in object FindSupercuts
+    // are re-checked in order to be sure that make sense
+	
+    FindSupercuts.CheckAlphaSigBkg();
+
+
+    // binning for alpha plots is defined
+
+    FindSupercuts.SetAlphaPlotBinining(NAlphaBins, AlphaBinLow, 
+				       AlphaBinUp);
+
+
+
+
+    // Size range is defined
+
+    FindSupercuts.SetSizeRange(SizeLow, SizeUp);
+
+
+
+    FindSupercuts.SetNormFactorFromAlphaBkg(NormFactorFromAlphaBkg);
+
+    FindSupercuts.SetUseFittedQuantities(UseFittedQuantities);
+
+    FindSupercuts.SetVariableUseStaticCuts(UseStaticCuts);
+
+    FindSupercuts.SetVariableNotUseTheta(NotUseTheta);
+
+    FindSupercuts.SetReadMatricesFromFile(ReadMatrixFromRootFiles);
+
+    FindSupercuts.SetTrainParameters(TrainParams);
+    FindSupercuts.SetSkipOptimization(SkipOptimization);
+    FindSupercuts.SetUseInitialSCParams(ApplyInitialSCParams);
+
+    FindSupercuts.SetTestParameters(TestParams);
+
+   
+    
+    FindSupercuts.SetHadronnessName("MHadSC");
+    FindSupercuts.SetHadronnessNameOFF("MHadOFFSC");
+    
+    FindSupercuts.SetAlphaDistributionsRootFilename (RootFilename);
+    
+    // FindSupercuts.SetPostScriptFile (PsFile);
+
+    FindSupercuts.SetCosThetaRangeVector (CosThetaRangeVector);
+    
+
+    // Names for all root files (matrices, alpha distributions...)
+    // are created 
+    FindSupercuts.SetALLNames();
+
+    if(ReadInitParamsFromAsciiFile)
+    {
+	// Initial SC Parameters and steps are retrieved from 
+	// Ascii file
+	if(!FindSupercuts.ReadSCParamsFromAsciiFile(InitSCParamAsciiFile,
+						    NInitSCPar))
+	{
+	    cout << "Initial SC Parameters could not be read from Ascii file "
+		 << InitSCParamAsciiFile << endl
+		 << "Aborting execution of macro... " << endl;
+	    return;
+
+	}
+    }
+ 
+   
+
+
+    // Finally loop over all theta bins defined is executed
+    
+    if (!FindSupercuts.LoopOverThetaRanges())
+      {
+	cout << "Function MFindSupercutsONOFFThetaLoop::LoopOverThetaRanges()" << endl
+	     << "could not be performed" << endl;
+
+      }
+
+    
+
+    // Nex and Significance are computed vs alphasig
+    
+    if (!FindSupercuts.ComputeNexSignificanceVSAlphaSig())
+      {
+	cout << "Function MFindSupercutsONOFFThetaLoop::ComputeNexSignificanceVSAlphaSig()" << endl
+	     << "could not be performed" << endl;
+	
+
+      }
+    
+
+
+
+    // Option to store ps files in a single ps document is still not working
+    /*
+    PsFile -> Close();
+    PsFile = NULL;
+    */
+
+    // Several theta bins are combined to produced a single alpha plot (for train and test)
+    // with single Nex and significances
+
+    if (CombineCosThetaBinsForTrainSample || CombineCosThetaBinsForTestSample)
+    {
+	if(!FindSupercuts.ComputeOverallSignificance(CombineCosThetaBinsForTrainSample, 
+						     CombineCosThetaBinsForTestSample))
+	  {
+	    cout << "Function MFindSupercutsONOFFThetaLoop::ComputeOverallSignificance" << endl
+		 << "could not be performed" << endl;
+	  }
+       
+
+    }
+
+
+   
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
