Given a file with TTree “MyTree” containing branch “waves” which is a vector, where wave.size() == 1500, I can do this:
TFile *f = new TFile("myfile.root", "READ");
TTree *t;
f->GetObject("MyTree", t);
TH1I *hWaves = new TH1I("hWaves", "Waveforms", 1500, 0, 1499);
t->Draw("waves >> hWaves", "", "");
And this will fill a histogram the same as:
TFile *f = new TFile("myfile.root", "READ");
TTree *t;
vector<double> wave;
f->GetObject("MyTree", t);
t->SetBranchAddress("waves", &wave);
TH1I *hWaves = new TH1I("hWaves", "Waveforms", 1500, 0, 1499);
for(int i=0;i < t->GetEntries();i++)
{
t->GetEntry(i);
for(int k=0;k < wave.size();k++)
hWaves->Fill(waves[k]);
}
However I’m interested in (quickly) plotting an average waveform. What I would like to do, using TTree::Draw(), is the analog to:
TFile *f = new TFile("myfile.root", "READ");
TTree *t;
vector<double> wave;
f->GetObject("MyTree", t);
t->SetBranchAddress("waves", &wave);
TH1I *hWaves = new TH1I("hWaves", "Waveforms", 1500, 0, 1499);
for(int i=0;i < t->GetEntries();i++)
{
t->GetEntry(i);
for(int k=0;k < wave.size();k++)
hWaves->Fill(k, waves[k]);
}
hWaves->Divide(t->GetEntries());
Which would also allow me to easily make a selection based on other branches or friend trees. Is this possible? It seems like it should be and I’m overlooking something simple in the TTree::Draw() syntax. Thanks!