Kalanand's March 2009 Log
March 3rd
Computing cosine θ* for the system X → YZ
Here is the code to compute θ*
Float_t CosThetaStar(TLorentzVector *daughter, TLorentzVector *parent)
{
// angle between mother and daughter in mother's rest frame
TVector3 boostvect = -(*parent).BoostVector();
//boost the daughter to mother's rest frame
(*daughter).Boost(boostvect);
// get the unit vectors for the mother and daughter
TVector3 dunit = (*daughter).Vect().Unit();
TVector3 punit = (*parent).Vect().Unit();
// take their dot product
return dunit.Dot(punit);
}
March 18th
Functions to plot n histograms on a canvas
Here is the code to easily plot a number of histograms on a canvas with
proper labels etc.
// Plot on canvas: one histogram
TCanvas* PlotOnCanvas(TString plotname, TH1& h, char* drawOption="e") {
TCanvas* can = new TCanvas( plotname, plotname, 500, 500 );
gStyle->SetOptStat(0);
h.Draw(drawOption);
can->SaveAs( plotname+TString(".pdf") );
return can;
}
// Plot on canvas: two histograms
TCanvas* PlotTwoOnCanvas(TString plotname, TH1& h1, TString label1,
TH1& h2, TString label2, float x0=0.63,
float y0=0.8, float x1=0.9, float y1=0.9,
char* opt1 = "HIST e", char* opt2 = "Hist esame") {
double i1 = h1.Integral();
double i2 = h2.Integral();
TCanvas* can = new TCanvas( plotname, plotname, 500, 500 );
gStyle->SetOptStat(0);
if( !(i1==0.0 || i2==0.0) ) {
h1.Draw("Hist e");
h2.Draw("Hist esame");
}
else if(i2==0.0) h1.Draw("e");
else h2.Draw("e");
TLegend* leg = new TLegend(x0,y0,x1,y1);
leg->AddEntry( &h1, label1,"L");
leg->AddEntry( &h2, label2,"L");
leg->SetMargin(0.15);
leg->SetFillColor(0);
if( !(i1==0.0 || i2==0.0) ) leg->Draw();
// gPad->SetLogy();
// gPad->SetGridx();
can->SaveAs( plotname+TString(".pdf") );
return can;
}
// Plot on canvas: three histograms
TCanvas* PlotThreeOnCanvas(TString plotname, TH1& h1, TString label1,
TH1& h2, TString label2, TH1& h3, TString label3,
float x0=0.63,
float y0=0.8, float x1=0.9, float y1=0.9) {
TCanvas* can = new TCanvas( plotname, plotname, 500, 500 );
h1.Draw("Hist e");
h2.Draw("Hist esame");
h3.Draw("Hist esame");
TLegend* leg = new TLegend(x0,y0,x1,y1);
leg->AddEntry( &h1, label1,"L");
leg->AddEntry( &h2, label2,"L");
leg->AddEntry( &h3, label3,"L");
leg->SetMargin(0.15);
leg->SetFillColor(0);
leg->Draw();
// gPad->SetLogy();
gPad->SetGridx();
can->SaveAs( plotname+TString(".pdf") );
return can;
}
// Plot on canvas: four histograms
TCanvas* PlotFourOnCanvas(TString plotname, TH1& h1, TString label1,
TH1& h2, TString label2, TH1& h3, TString label3,
TH1& h4, TString label4, float x0=0.63,
float y0=0.8, float x1=0.9, float y1=0.9) {
TCanvas* can = new TCanvas( plotname, plotname, 500, 500 );
h1.Draw("Hist e");
h2.Draw("Hist esame");
h3.Draw("Hist esame");
h4.Draw("Hist esame");
TLegend* leg = new TLegend(x0,y0,x1,y1);
leg->AddEntry( &h1, label1,"L");
leg->AddEntry( &h2, label2,"L");
leg->AddEntry( &h3, label3,"L");
leg->AddEntry( &h4, label4,"L");
leg->SetMargin(0.15);
leg->SetFillColor(0);
leg->Draw();
// gPad->SetLogy();
// gPad->SetGridx();
can->SaveAs( plotname+TString(".pdf") );
return can;
}
// Plot on canvas: five histograms
TCanvas* PlotFiveOnCanvas(TString plotname, TH1& h1, TString label1,
TH1& h2, TString label2, TH1& h3, TString label3,
TH1& h4, TString label4, TH1& h5, TString label5,
float x0=0.63,
float y0=0.8, float x1=0.9, float y1=0.9) {
TCanvas* can = new TCanvas( plotname, plotname, 500, 500 );
h1.Draw("Hist e");
h2.Draw("Hist esame");
h3.Draw("Hist esame");
h4.Draw("Hist esame");
h5.Draw("Hist esame");
TLegend* leg = new TLegend(x0,y0,x1,y1);
leg->AddEntry( &h1, label1,"L");
leg->AddEntry( &h2, label2,"L");
leg->AddEntry( &h3, label3,"L");
leg->AddEntry( &h4, label4,"L");
leg->AddEntry( &h5, label5,"L");
leg->SetMargin(0.15);
leg->SetFillColor(0);
leg->Draw();
// gPad->SetLogy();
gPad->SetGridx();
can->SaveAs( plotname+TString(".pdf") );
return can;
}
Go to February's log
Last modified: Thu Mar 19 05:37:41 CST 2009