Hi,
I am not able to fill a TH2F properly in function TH2F *footprint, that is, value = h1_spectrum->GetBinContent(st); but value is not encoded properly at h2fp->Fill(ch,st,value);
What did I miss? Many thanks
TH2F* createScan(char* fn, int mi, int ma, int step, int nch) {
char fname[1000];
TH1F *hdum;int z=5;
TH2F *h2 = new TH2F("h2","",nch,-0.5,nch-0.5,((ma-mi)/step)+1,mi-(Double_t)step/2.,ma+(Double_t)step/2.);
h2->SetStats(kFALSE);
for (int i=mi; i<ma+1; i=i+step) {
sprintf(fname,fn,i);
hdum=readDataFile(fname, nch);
for (int j=0; j<nch; j++)
h2->Fill(j,i,hdum->GetBinContent(j+1));
delete hdum;
}
return h2;
}
TH1F* getCh(TH2F* h2, int chan) {
int nstep=h2->GetYaxis()->GetNbins();
Double_t mi=h2->GetYaxis()->GetXmin();
Double_t ma=h2->GetYaxis()->GetXmax();
TH1F* h1=new TH1F("h1", "",nstep,mi,ma);
for (int i=1; i<nstep+1; i++) {
h1->SetBinContent(i, h2->GetBinContent(chan+1,i));
}
h1->GetXaxis()->SetTitle("Threshold(DACu)");
h1->GetYaxis()->SetTitle("Counts");
h1->SetLineWidth(6);
return h1;
}
TH1F* spectrumFromCh(TH1F* hch) {
int thr;
float th,hi,lo,de, elo,ehi, eth;
Int_t nst;
Double_t mi,ma,st;
TAxis *ax=hch->GetXaxis();
ma=ax->GetXmax();
mi=ax->GetXmin();
st=ax->GetBinWidth(1); //step size
nst=(ax->GetNbins()); //number of steps
TH1F *hspectrum=new TH1F("hs", "",nst,mi,ma);
for (float i=1; i<nst; i++) {
thr=mi+(i)*st;
th=hch->GetBinContent(i+1);
lo=hch->GetBinContent(i);
de=(th-lo);
hspectrum->SetBinContent(i, de/st);
elo=hch->GetBinError(i);
if (elo<=0)
elo=TMath::Sqrt(lo);
eth=hch->GetBinError(i+1);
if (eth<=0)
eth=TMath::Sqrt(eth);
//hspectrum->SetBinError(i, TMath::Sqrt(eth*eth+elo*elo)/st);
}
return hspectrum;
}
TH2F *footprint(int minChan, int maxChan, TH2F *h2, int stepInterval) {
int totalChannels = maxChan-minChan;
int totalSteps = h2->GetYaxis()->GetNbins();
int step_low = (h2->GetYaxis()->GetXmin()) +1;
int step_high = h2->GetYaxis()->GetXmax();
Double_t step;
Double_t value;
TH2F *h2fp = new TH2F ("h2fp", "", totalChannels,minChan-0.5, maxChan+0.5, ((step_low-step_high)/stepInterval)+1, step_low-(Double_t)stepInterval/2.,step_high + (Double_t) stepInterval/2.);
h2fp->SetStats(kFALSE);
for (int ch=minChan;ch<maxChan; ch++){
TH1F *h1 = getCh(h2, ch);
TH1F *h1_spectrum = spectrumFromCh(h1);
for (int st =step_low ; st<step_high+1; st=st+stepInterval){
value= h1_spectrum->GetBinContent(st);
h2fp->Fill(ch,st,value);
//h2fp->SetBinContent(st,ch,value);
}
delete h1;
delete h1_spectrum;
}
return h2fp;
}