My problem is the following: I want to write a macro which draws an histogram for each event in a tree, and let hte user change it from time to time. Here’s the code:
#include "TGraphAsymmErrors.h"
#include "TString.h"
#include "TFile.h"
#include "TH1F.h"
#include "TRandom3.h"
#include "TCanvas.h"
#include "TMath.h"
//#include "Math/SpecFuncMath.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <cmath>
#include <math.h>
void DrawPads(const char * file_name){
TH2I * mmq = new TH2I ("mmq","q in pads",35,-2,33,31,0,31);
TFile * inFile =NULL;
inFile=TFile::Open(file_name);
if (inFile->IsOpen()){
cout << "Processing: " << file_name << " ... " << endl;
}
else{
cout<<"failed opening of" << file_name <<endl;
return;
}
TCanvas *cq = new TCanvas("cq"," charge in pads",1);
TH2F * opening = new TH2F("histos","_histos",35,-1,34,31,0,31);
opening->Draw("");
int padx[70][10];
int pady[70][10];
int x,y,t;
int padq[70][10];
int clusters;
int multiplicity[70];
TTree *intree = (TTree*)inFile->Get("outtree");
intree->SetBranchAddress("pad_charge",&padq);
intree->SetBranchAddress("pad_x",&padx);
intree->SetBranchAddress("pad_y",&pady);
intree->SetBranchAddress("rob_clusters",&clusters);
intree->SetBranchAddress("multiplicity",&multiplicity);
int i=0;
int control=1;
while(control){
cout << "select event. -1 to exit\n"<<endl;
cin >> i;
if(i==-1){break;}
intree->GetEntry(i);
for(int j=0;j<clusters;j++){
for(int k=0;k<multiplicity[j];k++){
mmq->SetBinContent(padx[j][k],pady[j][k],padq[j][k]);
}
}
cq->cd();
mmq->Draw("colz");
}
return ;
}
It all works well except that the histogram is drawn only when the “-1” command is given, that is when the user stops the program (only last event is shown) and return is read.
What am I doing wrong? thank you
Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided