Index: trunk/MagicSoft/Mars/mtemp/mifae/programs/optimizeCuts.cc
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/programs/optimizeCuts.cc	(revision 4225)
+++ trunk/MagicSoft/Mars/mtemp/mifae/programs/optimizeCuts.cc	(revision 4234)
@@ -36,5 +36,7 @@
 Float_t  lowdistcut=0;
 Float_t  uppdistcut=10;
-Float_t  sizecut=1800;
+Float_t  lowsizecut=1800;
+Float_t  uppsizecut=1800;
+Int_t    nsizebins=1;
 UInt_t   onRate=1;
 Float_t  lowlgcut=0.01;
@@ -130,78 +132,97 @@
   char evecut[256];
   sprintf(evecut,"event%%%d==0",onRate);
-  sprintf(gencut,"size>%f && dist>%f && dist<%f",sizecut,lowdistcut,uppdistcut);
+  sprintf(gencut,"dist>%f && dist<%f",lowdistcut,uppdistcut);
   cout << "General cut " << gencut << " (" << evecut << " for on-data)" << endl;
 
-  // loop on widht and length cuts
-  Float_t length=lowlgcut;
-  while(length<=upplgcut)
-    {
-      Float_t width=lowwdcut;
-      while(width<=uppwdcut)
-	{
-	  TH1F* onhisto  = new TH1F("OnHist" ,"Alpha Plot",nbins,0,90);
-	  TH1F* offhisto = new TH1F("OffHist","Alpha Plot",nbins,0,90);    
-
-	  // define the width/length cut
-	  char varcut[256];
-	  sprintf(varcut,"length<%f && width<%f",length,width);
-	  cout << "Cutting " << varcut << endl;
-	  
-	  // define the on/off data cut
-	  char offcut[1024];
-	  sprintf(offcut,"%s && %s",gencut,varcut);
-	  char oncut[1024];
-	  sprintf(oncut,"%s && %s",evecut,offcut);
-
-	  // Fill the histos
-	  ton->Draw("alpha>>OnHist",oncut);
-	  toff->Draw("alpha>>OffHist",offcut);
-	  
-	  // Normalize histos
-	  const Int_t inibin = (Int_t)(frontiere/90.*nbins+1);
-	  Float_t level=0;
-	  Float_t leveloff=0;
-	  for(Int_t ibin = inibin; ibin<=nbins;ibin++)
+  Bool_t isDiff = kFALSE;
+  if(nsizebins<0)
+    {
+      nsizebins*=-1;
+      isDiff=kTRUE;
+    }
+  else
+    nsizebins+=1;
+
+  // loop on size, width and length cuts
+  for(Int_t isb=0;isb<nsizebins;isb++) // loop on size
+    {      
+      cout << isb << endl;      
+      Float_t minsize = isDiff ? 
+	TMath::Power(10,TMath::Log10(lowsizecut)+isb*(TMath::Log10(uppsizecut)-TMath::Log10(lowsizecut))/nsizebins) :
+	TMath::Power(10,TMath::Log10(lowsizecut)+isb*(TMath::Log10(uppsizecut)-TMath::Log10(lowsizecut))/(nsizebins-1));
+      Float_t maxsize = isDiff ? TMath::Power(10,TMath::Log10(lowsizecut)+(isb+1)*(TMath::Log10(uppsizecut)-TMath::Log10(lowsizecut))/nsizebins) : 9999999999.;
+      
+      Float_t length=lowlgcut;
+      while(length<=upplgcut) // loop on length
+	{
+	  Float_t width=lowwdcut;
+	  while(width<=uppwdcut) // loop on width
 	    {
-	      level+=onhisto->GetBinContent(ibin);
-	      leveloff+=offhisto->GetBinContent(ibin);
+	      TH1F* onhisto  = new TH1F("OnHist" ,"Alpha Plot",nbins,0,90);
+	      TH1F* offhisto = new TH1F("OffHist","Alpha Plot",nbins,0,90);    
+	      
+	      // define the width/length cut
+	      char varcut[256];
+	      sprintf(varcut,"size>%f && size<%f && length<%f && width<%f",minsize,maxsize,length,width);
+	      cout << "Cutting " << varcut << endl;
+	      
+	      // define the on/off data cut
+	      char offcut[1024];
+	      sprintf(offcut,"%s && %s",gencut,varcut);
+	      char oncut[1024];
+	      sprintf(oncut,"%s && %s",evecut,offcut);
+	      
+	      // Fill the histos
+	      ton->Draw("alpha>>OnHist",oncut);
+	      toff->Draw("alpha>>OffHist",offcut);
+	      
+	      // Normalize histos
+	      const Int_t inibin = (Int_t)(frontiere/90.*nbins+1);
+	      Float_t level=0;
+	      Float_t leveloff=0;
+	      for(Int_t ibin = inibin; ibin<=nbins;ibin++)
+		{
+		  level+=onhisto->GetBinContent(ibin);
+		  leveloff+=offhisto->GetBinContent(ibin);
+		}
+	      offhisto->Sumw2(); // needed to compute correct errors after normalization
+	      const Float_t norm = leveloff ? level/leveloff: 1;
+	      cout << "Normalizing by factor " << norm <<endl;
+	      offhisto->Scale(norm);    
+	      
+	      // compute significance/excess
+	      Float_t sig=0,bg=0,esig=0,ebg=0;
+	      Float_t significance=0;
+	      const Int_t signbins = inibin-1;
+	      for(Int_t ibin = 1; ibin<=signbins;ibin++)
+		{
+		  sig  += onhisto->GetBinContent(ibin);
+		  esig += onhisto->GetBinError(ibin)*onhisto->GetBinError(ibin);
+		  bg   += offhisto->GetBinContent(ibin);
+		  ebg  += offhisto->GetBinError(ibin)*offhisto->GetBinError(ibin);
+		}
+	      Float_t error= TMath::Sqrt(esig+ebg);
+	      significance = error ? (sig-bg)/error : 0; 
+	      
+	      cout << "Excess: " << sig-bg << endl;
+	      cout << "N bkg: "  << bg << endl; 
+	      cout << "Significance: " << significance << endl;	  
+	      
+	      // save the result in file
+	      fout << minsize << '\t' 
+		   << maxsize << '\t' 
+		   << width << '\t' 
+		   << length << '\t'
+		   << sig-bg << '\t'
+		   << significance << '\t' << endl;
+	      
+	      delete onhisto;
+	      delete offhisto;
+	      
+	      width+=wdstep;
 	    }
-	  offhisto->Sumw2(); // needed to compute correct errors after normalization
-	  const Float_t norm = leveloff ? level/leveloff: 1;
-	  cout << "Normalizing by factor " << norm <<endl;
-	  offhisto->Scale(norm);    
-
-	  // compute significance/excess
-	  Float_t sig=0,bg=0,esig=0,ebg=0;
-	  Float_t significance=0;
-	  const Int_t signbins = inibin-1;
-	  for(Int_t ibin = 1; ibin<=signbins;ibin++)
-	    {
-	      sig  += onhisto->GetBinContent(ibin);
-	      esig += onhisto->GetBinError(ibin)*onhisto->GetBinError(ibin);
-	      bg   += offhisto->GetBinContent(ibin);
-	      ebg  += offhisto->GetBinError(ibin)*offhisto->GetBinError(ibin);
-	    }
-	  Float_t error= TMath::Sqrt(esig+ebg);
-	  significance = error ? (sig-bg)/error : 0; 
-	  
-	  cout << "Excess: " << sig-bg << endl;
-	  cout << "N bkg: "  << bg << endl; 
-	  cout << "Significance: " << significance << endl;	  
-	  
-	  // save the result in file
-	  fout << width << '\t' 
-	       << length << '\t'
-	       << sig-bg << '\t'
-	       << significance << '\t' << endl;
-	  
-	  delete onhisto;
-	  delete offhisto;
-	  
-	  width+=wdstep;
-	}
-      length+=lgstep;
-    }
-  
+	  length+=lgstep;
+	}
+    }
   fout.close();
 }
@@ -260,7 +281,11 @@
 	}
 
-      // size cut
-      if(strcmp(word.Data(),"SIZECUT")==0)
-	ifun >> sizecut;
+      // size cuts
+      if(strcmp(word.Data(),"SIZECUTS")==0)
+	{
+	  ifun >> lowsizecut;
+	  ifun >> uppsizecut;
+	  ifun >> nsizebins;
+	}
 
       // dist cuts
@@ -317,6 +342,6 @@
   cout << "Off-data input file name(s): " << offFile << endl;
   cout << "Output file name: " << outputFile << endl;
-  cout << "Size cut: " << sizecut << endl;
   cout << "Dist cuts (deg): [" << lowdistcut<< ","<<uppdistcut<< "]" << endl;
+  cout << "Scanning size range: [" << lowsizecut << "," << uppsizecut << "]"<< " in " << nsizebins << " steps" << endl;
   cout << "Scanning length range (deg): [" << lowlgcut<< ","<<upplgcut<< "], with step (deg): "<< lgstep << endl;
   cout << "Scanning width range (deg): [" << lowwdcut<< ","<<uppwdcut<< "], with step (deg): "<< wdstep << endl;
Index: trunk/MagicSoft/Mars/mtemp/mifae/programs/optimizecuts.datacard
===================================================================
--- trunk/MagicSoft/Mars/mtemp/mifae/programs/optimizecuts.datacard	(revision 4225)
+++ trunk/MagicSoft/Mars/mtemp/mifae/programs/optimizecuts.datacard	(revision 4234)
@@ -1,2 +1,11 @@
+/////////////////////////////////////////////////////////
+// Data card template for optimizeCuts executable      //
+//                                                     //
+// *** Compulsory cards are:                           //
+// ONFILES, OFFFILES, OUTFILE                          //
+//                                                     //
+// the rest are optional                               //
+// *** Do NEVER add a datacard with no value after it  //
+/////////////////////////////////////////////////////////
 
 // Maximun number of on and off events to be processed)
@@ -4,24 +13,30 @@
 
 // On data acceptance rate (e.g 4 for taking 1/4 of whole data sample)
-ONRATE 2
+ONRATE 3
 
 // Input file name pattern (On data)
-ONFILES  /mnt/users/jrico/magic/mars/Mars_Standard02/mtemp/mifae/hillas/crab20040215OnRotateCalA-D.root
+ONFILES  /mnt/users/jrico/magic/mars/Mars_Standard02/mtemp/mifae/hillas/mrk20040215OnRotateNoCalB.root
 
 // Input file name pattern (Off data)
-OFFFILES  /mnt/users/jrico/magic/mars/Mars_Standard02/mtemp/mifae/hillas/crab20040215OffRotateCalA-H.root
+OFFFILES  /mnt/users/jrico/magic/mars/Mars_Standard02/mtemp/mifae/hillas/mrk20040215OffRotateA-C.root
 
 // output file name
-OUTFILE  ./optimizeCrab_cal_fine.out
+OUTFILE  ./prueba.out
 
-// Preliminar cuts (size in size units, distance in deg)
-SIZECUT  2000
-DISTCUTS 0.2 1.1
 
-// Length initial, final and step values
-LENGTHCUTS 0.15 0.35 0.005 
+// Preliminary distance lower and upper cuts (in deg)
+DISTCUTS 0.3 1.2
 
-// Width initial, final and step values
-WIDTHCUTS 0.05 0.15 0.005 
+// Size initial, final and number of steps 
+// it will take logarithmic constant intervals
+// positive number of steps means lower cut (integral)
+// negative number of steps means lower and upper cuts (diferential)
+SIZECUTS  500 10000 3
+
+// Length initial, final and step values (in deg)
+LENGTHCUTS 0.15 0.35 0.1 
+
+// Width initial, final and step values (in deg)
+WIDTHCUTS 0.05 0.15 0.1 
 
 
