Home | News | Documentation | Download

Difference between arrays


#1

Hi, I plotted an array setting 4 conditiions in this way:

t->Draw( TString::Format("Calo_EnDep[%d] >> htemp(5000., 0., 5000.)", a), TString::Format("TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) ", a, b, p1, csig, p2, a, c, p13sub, csig, p23sub,a, d, p14sub, csig, p24sub) );

Moreover, I plotted the same data adding a fifth condition in this way.

t->Draw( TString::Format("Calo_EnDep[%d] >> htemp(5000., 0., 5000.)", a), TString::Format("TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f)", a, b, p1, csig, p2, a, c, p13sub, csig, p23sub,a, d, p14sub, csig, p24sub,a, e, p15sub, csig, p25sub) );

Now I need to delete from the sample having the 4 condition, the sub-sample having 5 conditions. Then I wrote:

t->Draw( (TString::Format("Calo_EnDep[%d] >> htemp(5000., 0., 5000.)", a), TString::Format("TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f)", a, b, p1, csig, p2, a, c, p13sub, csig, p23sub,a, d, p14sub, csig, p24sub))   -   (TString::Format("Calo_EnDep[%d] >> htemp(5000., 0., 5000.)", a), TString::Format("TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f)", a, b, p1, csig, p2, a, c, p13sub, csig, p23sub,a, d, p14sub, csig, p24sub,a, e, p15sub, csig, p25sub)));

What I mean, is to delete from the sample having 4 conditions, the data having one condition more.
When I run Root, I get this error

How should I do, what I need?


ROOT Version: 5.34/38
Platform: Windows
Compiler: Not Provided



#2

I have no idea what you want but maybe this is it:

TString what = TString::Format("Calo_EnDep[%d] >> htemp(5000., 0., 5000.)", a);
TCut cut1 = TString::Format("TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f)", a, b, p1, csig, p2, a, c, p13sub, csig, p23sub,a, d, p14sub, csig, p24sub).Data();
TCut cut2 = TString::Format("TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f)", a, b, p1, csig, p2, a, c, p13sub, csig, p23sub,a, d, p14sub, csig, p24sub,a, e, p15sub, csig, p25sub).Data();
t->Draw(what, cut1 && !cut2);

#3

Thank you wile! it was that I want!


#4

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)


#5

Hi @Wile_E_Coyote, following your reply, I made 1D plot about an array Calo_EnDep in this way

TCanvas *c20 = new TCanvas("c20",canvtitle,1280,1024);
			c20->Divide (2,2);
			TCut cut1 = TString::Format("TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f)", a, b, p1, csig, p2, a, c, p13sub, csig, p23sub,a, d, p14sub, csig, p24sub).Data();
			TCut cut2 = TString::Format("TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f)", a, b, p1, csig, p2, a, c, p13sub, csig, p23sub,a, d, p14sub, csig, p24sub,a, e, p15sub, csig, p25sub).Data();
			TCut cut3 = TString::Format("TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f)", a, b, p1, csig, p2, a, c, p13sub, csig, p23sub,a, d, p14sub, csig, p24sub,a, e2, p15sub2, csig, p25sub2).Data();
 			c20->cd(1);
 			t->SetLineColor(kBlue);
 			TString henea4substringcut = TString::Format("Calo_EnDep[%d] >> htemp(5000., 0., 5000.)", a);
			t->Draw(henea4substringcut, cut1 && !cut2 && !cut3);
			gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
			t->GetHistogram()->SetTitle(cdenenamea);
 			TH1F *henea4subcut = (TH1F*)gPad->GetPrimitive("htemp"); 
			henea4subcut->GetXaxis()->SetTitle(cdeneXnameab); 
			henea4subcut->GetYaxis()->SetTitle(cdeneYnameab);
			henea4subcut->GetYaxis()->SetTitleSize(c2_YTitleSize);
			henea4subcut->GetYaxis()->SetTitleFont(c2_YTitleFont);
			henea4subcut->GetYaxis()->SetTitleOffset(c2_YTitleOffset);
			henea4subcut->GetYaxis()->SetLabelFont(c2_YLabelFont); 
			henea4subcut->GetYaxis()->SetLabelSize(c2_YLabelSize);
			henea4subcut->GetXaxis()->SetTitleSize(c2_XTitleSize);
			henea4subcut->GetXaxis()->SetTitleFont(c2_XTitleFont);
			henea4subcut->GetXaxis()->SetTitleOffset(c2_XTitleOffset);
			henea4subcut->GetXaxis()->SetLabelFont(c2_XLabelFont); 
			henea4subcut->GetXaxis()->SetLabelSize(c2_XLabelSize);
			henea4subcut->SetFillColorAlpha(kBlue, heneabfillcolor);
			henea4subcut->Draw(); 	
			henea4subcut->SetName(heneabname);
			//henea->GetXaxis()->SetRangeUser(c2_XSetRangem,c2_XSetRangeMa);
   			gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn

Should it also possible to make a 2D plot of 2 arrays?
I mean to plot a TH2F having on x-axis a culomn of the Calo_EnDep [a] array and on y-axis one other culomn Calo_EnDep[b]…then I would define for example:

TString heneasubstringcutrelab = TString::Format("Calo_EnDep[%d] >> htemp(5000., 0., 5000.)", a);
TString henebsubstringcutrelab = TString::Format("Calo_EnDep[%d] >> htemp(5000., 0., 5000.)", b);

then to plot them in a 2D plot setting the condition
cut1 yes
cut2 no (discard)
cut3 no (discard)

just like in the 1D plot

t->Draw(henea4substringcut, cut1 && !cut2 && !cut3);

Thank you


#6

Try:

TString what = TString::Format("Calo_EnDep[%d] : Calo_EnDep[%d] >> htemp(100, 0., 5000., 100, 0., 5000.)", b, a);
t->Draw(what, cut1 && !cut2 && !cut3);

#7

Hi @Wile_E_Coyote thank you for your reply. Your code works, I get the plot just writing

TCanvas *c25 = new TCanvas("c25",canvtitle,1280,1024);
 			t->SetLineColor(kBlue);
 			TString henecdsubstringcutrel = TString::Format("Calo_EnDep[%d] :  Calo_EnDep[%d]>> htemp(4500., 0., 4500.)", c,d);
 			t->Draw(henecdsubstringcutrel, cut1 && !cut2 && !cut3);

but it looks like having problem because:

  1. If I add the code
TH2F *henecdsubstringcutrelTHF = (TH2F*)gPad->GetPrimitive("htemp"); 
			henecdsubstringcutrelTHF->GetXaxis()->SetTitle(cdeneXnameab); 
			henecdsubstringcutrelTHF->GetYaxis()->SetTitle(cdeneXnameab);
			henecdsubstringcutrelTHF->GetYaxis()->SetTitleSize(c2_YTitleSize);
			henecdsubstringcutrelTHF->GetYaxis()->SetTitleFont(c2_YTitleFont);
			henecdsubstringcutrelTHF->GetYaxis()->SetTitleOffset(c2_YTitleOffset);
			henecdsubstringcutrelTHF->GetYaxis()->SetLabelFont(c2_YLabelFont); 
			henecdsubstringcutrelTHF->GetYaxis()->SetLabelSize(c2_YLabelSize);
			henecdsubstringcutrelTHF->GetXaxis()->SetTitleSize(c2_XTitleSize);
			henecdsubstringcutrelTHF->GetXaxis()->SetTitleFont(c2_XTitleFont);
			henecdsubstringcutrelTHF->GetXaxis()->SetTitleOffset(c2_XTitleOffset);
			henecdsubstringcutrelTHF->GetXaxis()->SetLabelFont(c2_XLabelFont); 
			henecdsubstringcutrelTHF->GetXaxis()->SetLabelSize(c2_XLabelSize);
			henecdsubstringcutrelTHF->SetMarkerColor(kBlue);
			henecdsubstringcutrelTHF->Draw(); 	
			henecdsubstringcutrelTHF->SetName(heneabname);
			//henea->GetXaxis()->SetRangeUser(c2_XSetRangem,c2_XSetRangeMa);
   			gPad->Modified();
			gPad->Update(); // make sure it's really (re)drawn
   			TLegend* leghenecdsubstringcutrelTHF = new TLegend(0.65, 0.7, .75, .75);
   			leghenecdsubstringcutrelTHF->SetHeader("Legend");
			leghenecdsubstringcutrelTHF->SetNColumns(1);
			leghenecdsubstringcutrelTHF->AddEntry(leghenecdsubstringcutrelTHF, "Data", "l");
			leghenecdsubstringcutrelTHF->Draw(); 
			gPad->Update();
			TPaveStats *statsghenecdsubstringcutrelTHF = (TPaveStats*)henecdsubstringcutrelTHF->GetListOfFunctions()->FindObject("stats");
			statsghenecdsubstringcutrelTHF->SetTextColor(kBlue);
			statsghenecdsubstringcutrelTHF->SetX1NDC(0.80); statsghenecdsubstringcutrelTHF->SetX2NDC(0.98);
			statsghenecdsubstringcutrelTHF->SetY1NDC(0.77); statsghenecdsubstringcutrelTHF->SetY2NDC(0.92)
			gPad->Update();

I get the error due to the TStats:

  1. If I don’t add the TStats, I don’t get any error, but the plot is white and ROOT doesn’t add my personal title of the plot

It’s strange, because I use these codes in other plots from tree (but in TH1F typology)

  1. Lastly,I would like to plot using the “COLZ” typology then I tried to write
TString henecdsubstringcutrel = TString::Format("Calo_EnDep[%d] :  Calo_EnDep[%d]>> htemp(4500., 0., 4500.)", c,d);
 			t->Draw("COLZ",henecdsubstringcutrel, cut1 && !cut2 && !cut3);

but I get error

Thank you