Hello Rene,
we continued trying to find the root of problem and arrived at the following piece of code. With tree->Draw(“s0:event>>h2”,c1,“N”) it works but without …,“N”) it does not work (see code).
Can you please tell us why?
Thanks,
Gerolf
PS.: Code and Data file are attached
PPS.: I hope this time the code is really ‘standalone’
#include
#include
#include
#include <Riostream.h>
#include <TSystem.h>
#include <stdio.h>
#include <TROOT.h>
#include <TRootApplication.h>
#include <TRootEmbeddedCanvas.h>
#include <TH2F.h>
#include <TFile.h>
#include <TCut.h>
#include <TTree.h>
#include <TCanvas.h>
#include <TApplication.h>
#include <TQObject.h>
#include <TVirtualX.h>
int main(int argc, char ** argv)
{
char line[40];
char tmp[70];
int ichan=1;
TH2F *h2 = 0;
struct event_t {
int evt;
int pmt;
int gain;
int s0;
int s1;
int s2;
int s3;
int s4;
int s5;
int s6;
};
event_t event;
//TApplication app(“test”,&argc,argv); // For compiling in Visual C++
TCanvas *c = new TCanvas("Canvas");
FILE *fp = fopen("test2.txt","r");
TFile *f = new TFile("test.root","RECREATE");
TTree *tree = new TTree("tree","pedestals");
tree->Branch("event",&event.evt,"evt/I:pmt:gain:s0:s1:s2:s3:s4:s5:s6");
while (fgets(line,40,fp)) {
sscanf(line," %d %d %d,%d,%d,%d,%d,%d,%d,%d\n",&event.evt,&event.pmt,&event.gain,&event.s0,&event.s1,&event.s2,&event.s3,&event.s4,&event.s5,&event.s6);
tree->Fill();
}
c->GetCanvas()->Divide(2,2);
while(ichan<=4) {
sprintf(tmp,"pmt==%d",ichan);
TCut c1 = tmp;
c->GetCanvas()->cd(ichan);
if (h2) {
delete h2;
h2=0;
}
tree->Draw("s0:event>>h2",c1,"N"); // works !!!!!!!!
//tree->Draw("s0:event>>h2",c1); // doesn't work !!!!!!!!!
h2 = (TH2F*)gPad->GetPrimitive("h2");
gPad->Update();
if (h2 != (TH2F*)gDirectory->Get("h2")) {
cout << "Different " << hex <<
(int) h2 << " " << (int) (TH2F*)gDirectory->Get("h2") << dec << endl;
}
gSystem->Sleep(500);
gPad->Clear();
h2->Print();
h2->DrawCopy();
gPad->Update();
ichan++;
}
fclose(fp);
//app.Run(kTRUE); // For compiling in Visual C++
return 0;
}
test2.txt (553 KB)