本文整理汇总了C++中TTree::GetHistogram方法的典型用法代码示例。如果您正苦于以下问题:C++ TTree::GetHistogram方法的具体用法?C++ TTree::GetHistogram怎么用?C++ TTree::GetHistogram使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TTree
的用法示例。
在下文中一共展示了TTree::GetHistogram方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Execute
int Execute(int argc, char *argv[]){
if(argc > 1 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)){
help(argv[0]);
return 1;
}
else if(argc < 3){
std::cout << " Error: Invalid number of arguments to " << argv[0] << ". Expected 2, received " << argc-1 << ".\n";
help(argv[0]);
return 1;
}
std::string draw_string = "";
std::string save_filename = "";
std::string save_histname = "";
bool create_hist = false;
int index = 3;
while(index < argc){
if(strcmp(argv[index], "--draw") == 0){
if(index + 1 >= argc){
std::cout << " Error! Missing required argument to '--draw'!\n";
help(argv[0]);
return 1;
}
draw_string = std::string(argv[++index]);
create_hist = true;
}
else if(strcmp(argv[index], "--save") == 0){
if(index + 2 >= argc){
std::cout << " Error! Missing required argument to '--save'!\n";
help(argv[0]);
return 1;
}
save_filename = std::string(argv[++index]);
save_histname = std::string(argv[++index]);
}
else{
std::cout << " Error! Unrecognized option '" << argv[index] << "'!\n";
help(argv[0]);
return 1;
}
index++;
}
TApplication* rootapp = new TApplication("rootapp", 0, NULL);
TCanvas *can1 = new TCanvas("can1", "Canvas");
can1->cd()->SetLogz();
TH2 *hist = NULL;
TFile *file = new TFile(argv[1], "READ");
if(!file->IsOpen()){
std::cout << " Error! Failed to open input file '" << argv[1] << "'.\n";
return 1;
}
if(!create_hist){
hist = (TH2*)file->Get(argv[2]);
if(!hist){
std::cout << " Error! Failed to load input histogram '" << argv[2] << "'.\n";
file->Close();
return 1;
}
}
else{
TTree *tree = (TTree*)file->Get(argv[2]);
if(!tree){
std::cout << " Error! Failed to load input histogram '" << argv[2] << "'.\n";
file->Close();
return 1;
}
std::cout << " " << argv[2] << "->Draw(\"" << draw_string << "\", \"\", \"COLZ\");\n";
std::cout << " Filling TH2... " << std::flush;
//tree->Draw("vandle.loc:vandle.ctof>>(250,-80,-20,42,16,58)"); // VANDLE
//tree->Draw("liquidbar.loc:liquidbar.ctof>>(250,-80,-20,10,64,74)"); // NeuDLES
//tree->Draw("generic.loc:generic.tof>>(250,-80,-20,10,80,90)"); // HAGRiD
tree->Draw(draw_string.c_str(), "", "COLZ");
std::cout << "DONE\n";
hist = (TH2*)tree->GetHistogram();
}
if(!save_filename.empty()){
TFile *ofile = new TFile(save_filename.c_str(), "RECREATE");
ofile->cd();
hist->Write(save_histname.c_str());
ofile->Close();
std::cout << " Saved histogram '" << save_histname << "' to file '" << save_filename << "'.\n";
}
hist->Draw("COLZ");
can1->WaitPrimitive();
TCanvas *can2 = new TCanvas("can2", "Canvas");
Process(hist, can2);
file->Close();
can1->Close();
can2->Close();
//.........这里部分代码省略.........
示例2: process
//.........这里部分代码省略.........
stree->SetMarkerStyle(6);
stree->SetMarkerColor(2);
for (int jentry=0; jentry<chain->GetEntries(); ++jentry)
{
chain->GetEvent(jentry);
// sig
for (int i=0; i<512; ++i) {
sig[i] = raw[i] - pedestal[i];
}
// calc common mode
Int_t group32[32];
Int_t index32[32];
for (int igroup=0; igroup<16; ++igroup) {
for (int istrip=0; istrip<32; ++istrip) // istrip is number inside group of 32
{
group32[istrip] = sig[igroup*32 + istrip];
}
// sort array group32 in ascending order
TMath::Sort(32, group32, index32, kFALSE);
Int_t median = group32[index32[14]];
cm[igroup] = median;
}
// subtract common mode
for (int istrip=0; istrip<512; ++istrip) {
Int_t igroup = istrip/32;
cmsig[istrip] = sig[istrip] - cm[igroup];
}
// Fill sig, cmsig, cm
stree->Fill();
}
osfile->Write();
////////////////////////////////////////////////////////
//
// process trees
//
///////////////////////////////////////////////////////
cout<< "results" <<endl;
Double_t a, mean, sigma;
TH1F* h_sigma_bkg = new TH1F("h_sigma_bkg","CM subtr. noise for groups", 16,0,16);
TH1F* h_mean_sig = new TH1F("h_mean_sig","CM subtr. signal for groups", 16,0,16);
TH1F* h_SN = new TH1F("h_SN","Signal to Noise Ratio for groups", 16,0,16);
new TCanvas;
btree->Draw("cmsig","Iteration$>=0&&Iteration$<32");
fitgr(0,0, "Q", "goff", btree->GetHistogram());
pargaus(a,mean,sigma,"htemp");
//cout<< "mean = " << mean << " sigma = " << sigma <<endl;
//-- png("FZ320P_05_MSSD_2-bkg-ex");
new TCanvas;
// for (int igroup=0; igroup<16; ++igroup) {
for (int igroup=0; igroup<15; ++igroup) {
Int_t ch1 = igroup*32;
Int_t ch2 = (igroup+1)*32;
btree->Draw("cmsig",Form("Iteration$>=%d&&Iteration$<%d",ch1,ch2),"");
fitgr(0,0, "", "", btree->GetHistogram());
pargaus(a,mean,sigma,"htemp");
// h_sigma_bkg->Fill(igroup, sigma);
h_sigma_bkg->SetBinContent(igroup+1, sigma);
}
new TCanvas;
h_sigma_bkg->Draw();
//-- png("FZ320P_05_MSSD_2-bkg-allgroups");
// signal
new TCanvas;
stree->Draw("cmsig","cmsig>8 &&Iteration$>=0&&Iteration$<32");
//-- png("FZ320P_05_MSSD_2-sig-ex");
new TCanvas;
// for (int igroup=0; igroup<16; ++igroup) {
for (int igroup=0; igroup<15; ++igroup) {
Int_t ch1 = igroup*32;
Int_t ch2 = (igroup+1)*32;
stree->Draw("cmsig",Form("cmsig>8 &&Iteration$>=%d&&Iteration$<%d",ch1,ch2),"");
gPad->Update();
gPad->Modified();
mean = stree->GetHistogram()->GetMean();
h_mean_sig->SetBinContent(igroup+1, mean);
}
new TCanvas;
h_mean_sig->Draw();
//-- png("FZ320P_05_MSSD_2-signal-allgroups");
for (int igroup=0; igroup<16; ++igroup) {
Double_t signal32 = h_mean_sig->GetBinContent(igroup+1);
Double_t noise32 = h_sigma_bkg->GetBinContent(igroup+1);
Double_t snr = 0;
if (noise32 > 0) snr = signal32 / noise32;
h_SN->SetBinContent(igroup+1, snr);
}
new TCanvas;
h_SN->Draw();
//-- png("FZ320P_05_MSSD_2-SN-allgroups");
}
示例3: csv
void csv(TString input="tmva.csvoutput.txt", TString par1="par2", TString par2="par3", TString par3="", TString value="eventEffScaled_5") {
std::cout << "Usage:" << std::endl
<< ".x scripts/csv.C with default arguments" << std::endl
<< ".x scripts/csv.C(filename, par1, par2, value)" << std::endl
<< std::endl
<< " Optional arguments:" << std::endl
<< " filename path to CSV file" << std::endl
<< " par1 name of X-parameter branch" << std::endl
<< " par2 name of Y-parameter branch (if empty, efficiency is drawn as a function of par1)" << std::endl
<< " value name of result (efficiency) branch" << std::endl
<< std::endl;
TTree *tree = new TTree("data", "data");
tree->ReadFile(input);
gStyle->SetPalette(1);
gStyle->SetPadRightMargin(0.14);
TCanvas *canvas = new TCanvas("csvoutput", "CSV Output", 1200, 900);
tree->SetMarkerStyle(kFullDotMedium);
tree->SetMarkerColor(kRed);
if(par2.Length() > 0) {
//tree->Draw(Form("%s:%s", par2.Data(), par1.Data()));
if(par3.Length() > 0)
tree->Draw(Form("%s:%s:%s:%s", par1.Data(), par2.Data(), par3.Data(), value.Data()), "", "COLZ"); //, "", "Z");
else
tree->Draw(Form("%s:%s:%s", par2.Data(), par1.Data(), value.Data()), "", "COLZ"); //, "", "Z");
TH1 *histo = tree->GetHistogram();
if(!histo)
return;
histo->SetTitle(Form("%s with different classifier parameters", value.Data()));
histo->GetXaxis()->SetTitle(Form("Classifier parameter %s", par1.Data()));
histo->GetYaxis()->SetTitle(Form("Classifier parameter %s", par2.Data()));
if(par3.Length() > 0)
histo->GetZaxis()->SetTitle(Form("Classifier parameter %s", par3.Data()));
else
histo->GetZaxis()->SetTitle("");
if(par3.Length() == 0) {
float x = 0;
float y = 0;
float val = 0;
double maxVal = tree->GetMaximum(value);
double minVal = tree->GetMinimum(value);
tree->SetBranchAddress(par1, &x);
tree->SetBranchAddress(par2, &y);
tree->SetBranchAddress(value, &val);
TLatex l;
l.SetTextSize(0.03);
Long64_t nentries = tree->GetEntries();
for(Long64_t entry=0; entry < nentries; ++entry) {
tree->GetEntry(entry);
l.SetTextColor(textColor(val, maxVal, minVal));
l.DrawLatex(x, y, Form("%.3f", val*100));
}
}
}
else {
tree->Draw(Form("%s:%s", value.Data(), par1.Data()));
TH1 *histo = tree->GetHistogram();
if(!histo)
return;
histo->SetTitle(Form("%s with different classifier parameters", value.Data()));
histo->GetXaxis()->SetTitle(Form("Classifier parameter %s", par1.Data()));
histo->GetYaxis()->SetTitle(value);
}
}