TH2F ProjectionY with TCutG problem

Hello there,
I was looking anywhere for solution, but I couldn’t find it.
I’ve got 2 .root files: one with TH2F histograms, second with TCutG cuts corresponding to these histograms. I need to cut data from histograms and then project them on axis. There are loads of them so I’m trying to do it automatically. To check if it works firstly I draw histogram with [cutg] option and it looks how it should. However, projection with [cutg] option results with all data being projected. What have I done wrong?

I’m using root 5.34

Here’s the code:

[code]void kalibracja()
{
gROOT->ProcessLine(".cd D:\mgr\kalibracja450\");
TFile *expData = new TFile(“450MeV_particles_residue_and_fast_slow_in_csi.root”,“READ”);
TFile *expCuts = new TFile(“cuts_particles_450MeV_garf.root”,“READ”);
int i=0;
int j=0;
char bufor[30];

if(expData->IsOpen() && expCuts->IsOpen())
{
for(i=0; i<4; i++)
for(j=0; j<24; j++)
{
TCanvas *kanwa = new TCanvas(“kanwa”);
kanwa->SetLogz();

TCutG *cutHis2A = new TCutG();
TH2F *expHis2 = new TH2F();	   
   
TH1D *expHisACut = new TH1D();
TH1D *expHisPCut = new TH1D();     
  	   
sprintf(bufor, "co_csi_dsp_s_vs_f[%d][%d]",i,j); 
expHis2 = (TH2F*)expData->Get(bufor);
		    
expHis2->DrawCopy("colz");

sprintf(bufor, "a_%d_%d",i,j);
TCutG *cutHis2A = (TCutG*)expCuts->Get(bufor);	

cutHis2A->SetName("cutHis2A");
expHis2->DrawCopy("colz [cutHis2A]");	
sprintf(bufor, "a_exp_check_%d_%d.pdf",i,j);
kanwa->SaveAs(bufor);		 	

expHisACut=expHis2->ProjectionY("projy", 0, -1, "[cutHis2A]"); 
expHisACut->SetStats(0);

expHisACut->Rebin(10);	
	
expHisACut->DrawCopy("e");

sprintf(bufor, "a_exp_cut_proj_%d_%d.pdf",i,j);
kanwa->SaveAs(bufor);	

delete expHisACut;	
delete cutHis2A;
delete expHis2;    
delete kanwa;

}
}

expData->Close();
expCuts->Close();

delete expData;
delete expCuts;
}[/code]

Thanks for your help in advance.

Hi,

  1. you are using cutHis2A twice:
    TCutG *cutHis2A = new TCutG();
    and
    TCutG cutHis2A = (TCutG)expCuts->Get(bufor);

  2. I would reinvent new names (“projy” ) for each projection:
    expHisACut=expHis2->ProjectionY(“projy”, 0, -1, “[cutHis2A]”);

The att macro demonstrates the possible problem:
I changed the name of the cut ahead of the second ProjectionY on purpose,
this changes the first ProjectionY also. If I give the second ProjectionY a different
name the first remains ok, for the second the cut is just ignored.

Cheers
Otto
tc.C (613 Bytes)

Hello,
thank you for your reply. I’ve changed the code accordingly to your suggestions, but it didn’t help.

Here’s changed code:

[code]void kalibracja()
{
gROOT->ProcessLine(".cd D:\mgr\kalibracja450\");
TFile *expData = new TFile(“450MeV_particles_residue_and_fast_slow_in_csi.root”,“READ”);
TFile *expCuts = new TFile(“cuts_particles_450MeV_garf.root”,“READ”);
int i=0;
int j=0;
char bufor[30];
char bufor2[30];

TCanvas *kanwa = new TCanvas(“kanwa”);
kanwa->SetLogz();

TCutG *cutHis2A = new TCutG();

if(expData->IsOpen() && expCuts->IsOpen())
{
for(i=0; i<4; i++)
for(j=0; j<24; j++)
{
TH2F *expHis2 = new TH2F();

TH1D *expHisACut = new TH1D(); 
  	   
sprintf(bufor, "co_csi_dsp_s_vs_f[%d][%d]",i,j); 
expHis2 = (TH2F*)expData->Get(bufor);

 sprintf(bufor, "a_%d_%d",i,j);
          cutHis2A = (TCutG*)expCuts->Get(bufor);	


sprintf(bufor, "cutHis2A%d%d", i, j);
cutHis2A->SetName(bufor);

sprintf(bufor, "colz [cutHis2A%d%d]", i, j);	
expHis2->DrawCopy(bufor);
kanwa->SetLogy(0);	
sprintf(bufor, "a_exp_check_%d_%d.pdf",i,j);
kanwa->SaveAs(bufor);

          sprintf(bufor, "projy%d%d", i, j);
sprintf(bufor2, "[cutHis2A%d%d]", i, j);
expHisACut=expHis2->ProjectionY(bufor, 0, -1, bufor2); 
expHisACut->SetStats(0);

expHisACut->Rebin(10);		
expHisACut->DrawCopy("e");
kanwa->SetLogy();		

sprintf(bufor, "a_exp_cut_proj_%d_%d.pdf",i,j);
kanwa->SaveAs(bufor);
	 		

delete expHisACut;

delete myCutsA;
delete myCutsP;  
delete expHis2; 

cutHis2A->Clear();		
cutHis2P->Clear();

kanwa->Clear();

}
}

expData->Close();
expCuts->Close();

delete expData;
delete expCuts;
delete kanwa;
delete cutHis2A;
}[/code]

And here’s example of the results: