Graphical Cut and Projection on a 2D Histogram

I am trying to select a specific region on a 2D Histogram and project it on X or Y axis. This histogram comes from data processing(I am providing the code at the end of my post).

The first thing to do was to try ProjectionX in the event browser, using right click on the histo and selecting ProjectionX. After reading the documentation(http://root.cern.ch/root/html/TH2.html#TH2:ProjectionX) I used the option “d”.

The next step was to use TCutG in order to define a region so as to project that region. After reading the documentation(http://root.cern.ch/root/html/TCutG.html) I followed the instructions

[quote]A TCutG object is a closed polygon defining a closed region in a x,y plot. It can be created via the graphics editor option “CutG” or directly by invoking its constructor. The first and last points should be the same.

To create a TCutG via the graphics editor, use the left button to select the points building the contour of the cut. Click on the right button to close the TCutG. When it is created via the graphics editor, the TCutG object is named “CUTG”. It is recommended to immediatly change the name by using the context menu item “SetName”.[/quote]

but when I define my region ans right click, I get a pop-up menu about the canvas with the option “SetEditable” ticked. I untick it and the next step is right click, so as to project the region.

The problem is that I get a menu about the canvas and not the histogram, which means there is no “ProjectionX” option.

What is wrong there?

My code that processes the data and creates the histograms is the following

The macro that creates the ntuple

[code]#include "Riostream.h"
void ntuple(char * file_c) {

//*****************************************************
//* First executes the script “evnt2dat”.
//* The script accepts as an input a .evnt file
//* and creates a .dat file.
//* Then root creates the ntuple, histogram from each detector
//* and the DE-E scatter plot
//*
//* Execute it using
//* root -l ‘ntuple.C(“filename”)’
//* Note that the extension .evnt MUST NOT be used
//* and evnt2dat script must be on the same directory as
//* this macro.
//*****************************************************

TString file(file_c);
gSystem->Exec(TString::Format("./evnt2dat %s",file.Data()));//Executes the script evnt2dat
TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
dir.ReplaceAll(“ntuple.C”,"");
dir.ReplaceAll("/./","/");
ifstream in;
in.open(TString::Format("%s%s_Processed.dat",dir.Data(),file.Data()));

Float_t de1,e1,de2,e2;
Int_t events = 0;
Int_t channels=4096;//Change it according to the acquisition channels
TFile *f = new TFile(“ntuple.root”,“RECREATE”);
//Create the histograms
TH1F *histo_de1 = new TH1F(“histo_de1”,"#Delta E_{1}",channels,1,channels);
TH1F *histo_e1 = new TH1F(“histo_e1”,“E_{1}”,channels,1,channels);
TH1F *histo_de2 = new TH1F(“histo_de2”,"#Delta E_{2}",channels,1,channels);
TH1F *histo_e2 = new TH1F(“histo_e2”,“E_{2}”,channels,1,channels);
TH2F dee1 = new TH2F(“dee1”, “#Delta E_{1} vs E_{1}”,channels,1,channels,channels,1,channels);
TH2F dee2 = new TH2F(“dee2”, “#Delta E_{2} vs E_{2}”,channels,1,channels,channels,1,channels);
/

//Create the e histos
std::vector my_e_hists;
for(Int_t i=1;i<3;i++)
{
TString name = TString::Format(“histo_e%d”,i);
TH1F temp(name,name,channels,1,channels);
my_e_hists.push_back(temp);
}
//Create the de histos
std::vector my_de_hists;
for(Int_t j=1;j<3;j++)
{
TString name = TString::Format(“histo_de%d”,i);
TH1F temp(name,name,channels,1,channels);
my_de_hists.push_back(temp);
}
/

//Create the ntuple
TNtuple *ntuple = new TNtuple(“ntuple”,“data from ascii file”,“de1:e1:de2:e2”);

//Fill the histos and the ntuple
while (1) {
in >> de1 >> e1 >> de2 >> e2;
if (!in.good()) break;
//if (nlines < 5) printf(“x=%8f, y=%8f, z=%8f\n”,x,y,z);
histo_de1->Fill(de1);
histo_e1->Fill(e1);
histo_de2->Fill(de2);
histo_e2->Fill(e2);
dee1->Fill(de1, e1);
dee2->Fill(de2, e2);
/for(Int_t k=1;k<3;k++)
{
histo_e$k->Fill(e_k);
}
for(Int_t l=1;l<3;l++)
{
histo_e$l->Fill(de_l);
}
/
ntuple->Fill(de1,e1,de2,e2);
events++;
}
//printf(“Found %d detectors\n”,detectors);
printf(“Found %d events\n”,events);

in.close();

f->Write();
histo_de1->Draw();
dee1->Draw(“COLZ”);
}[/code]

The script that root runs

[code]#!/bin/bash

if test $1 ; then
if [ -f $1.evnt ] ; then
rm -f $1.dat
sed -n ‘2p’ $1.evnt | (read v1 v2 v3
for filename in $1*.evnt ; do
echo -e “Processing file $filename"
sed ‘$d’ < $filename > $1_tmp
sed -i ‘/Kmax/d’ $1_tmp
sed -i ‘/^’”$v1"’ ‘"$v2"’ /d’ $1_tmp
cat $1_tmp >> $1.dat
done
v3=wc -l $1.dat | awk '{print $1}'
echo -e “$v1 $v2 $v3” > .$1.dat
rm -f $1_tmp)
else
echo -e "\a!!!"
echo -e " Event file $1.evnt doesn’t exist !!!"
echo -e "!!!"
fi
else
echo -e "\a!!!"
echo -e "!!! Give name for event files !!!"
echo -e "!!!"
fi
awk -v channels=4096 ‘NR<=2{next}{for (i=1;i<=NF;i++) $i=$i-(i-1)*channels} END{printf "There are %d detectors\n ",detectors=NF;}1’ $1.dat >$1_Processed.dat
rm -f $1.dat
exit 0
[/code]

I execute this macro using