Ok, I came back here for this issue which is related to creating TH2F by using two TH1F
My script is as in the following ,and runs…
1-The problem is that although the histograms GAIN_650 and GAIN_700 are filled and drew in root file, the content getting with GAIN_650->GetBinContent(qie) consists of zeros ! These histogram here are two TH2F histograms ,and the aim here is filling another TH2F histogram by using them with GetBinContent().
2-The same problem as above is that the content getting with GAIN650->GetBinContent(qie) consists of zeros !
These histogram here are two TH1F histograms ,and the aim here is creating TH2F histogram by using them with GetBinContent()
PS: “map.txt” and “Run_2983.root” are in the attachment being necessary for running the script ‘HFLED.C’
,and HFLED.C runs as root -l ‘HFLED.C(2983)’
Please, could you help me for handling this problem?
#include <iostream>
#include <fstream>
using namespace std;
char rootfile[200];
int qie,depth,ieta;
double GAINfor650,GAINfor700;
double GAIN;
//int runno; \
void HFLED(int runno){
gStyle->SetOptStat("nemrRM"); // "nemr" is the default \
sprintf(rootfile,"Run_%d.root",runno);
TFile *f = new TFile(rootfile);
stringstream outfile;
outfile<<runno<<"_Ntuple.root";
TFile *f1 = new TFile(outfile.str().c_str(),"RECREATE");
outfile.str("");
int HV[] = {650,700};
TCanvas *c3 = new TCanvas("GAIN for HV","GAIN for HV",600,400);
TCanvas *c4 = new TCanvas("GAINs","GAINs",600,400);
TH2F *GAINHV;
TH2F *GAIN_650;
TH2F *GAIN_700;
TH1F *GAIN650;
TH1F *GAIN700;
TH2F *GAINCorr;
GAIN_650 = new TH2F("GAIN for 650V","GAIN for 650V",48,500,800,48,0,2700000);
GAIN_700 = new TH2F("GAIN for 700V","GAIN for 700V",48,500,800,48,0,2700000);
GAINHV = new TH2F("GAIN for HV","GAIN for HV",96,500,800,96,0,2700000);
GAIN650 = new TH1F("GAIN650","GAIN650",48,100000,2700000);
GAIN700 = new TH1F("GAIN700","GAIN700",48,100000,2700000);
GAINCorr = new TH2F("GAINforHVs","GAINforHVs",96,100000,2700000,96,100000,2700000);
ifstream input("map.txt");
if (input.fail()){ cout<<"map.txt is not available"<<endl; }
int count = 0;
while( input>>qie>>ieta>>depth ){
for(int hv=0;hv<2;hv++){
for(int db=0;db<2;db++) {
TString histnameLED,histnamePED;
stringstream ledname,pedname;
histnameLED.Form("/Analyzer/QIEsSumLED%d_QiECh_%d_DBOX_%d_eta_%d_D_%d",HV[hv],qie,db,ieta,depth);
histnamePED.Form("/Analyzer/QIEsSumPED%d_QiECh_%d_DBOX_%d_eta_%d_D_%d",HV[hv],qie,db,ieta,depth);
pedname<<histnamePED;
ledname<<histnameLED;
// cout<<histnameLED<<endl;
TH1F *HistLED = (TH1F*)f->Get(ledname.str().c_str());
TH1F *HistPED = (TH1F*)f->Get(pedname.str().c_str());
ledname.str("");
pedname.str("");
// cout<<ledname.str().c_str()<<endl;
if(HistLED && HistPED) {
double LEDMEAN;
double PEDMEAN;
double LEDRMS;
double PEDRMS;
LEDMEAN = HistLED->GetMean();
PEDMEAN = HistPED->GetMean();
LEDRMS = HistLED->GetRMS();
PEDRMS = HistPED->GetRMS();
double TRUEMEAN = LEDMEAN - PEDMEAN;
double TRUERMS = sqrt(pow(LEDRMS,2)+pow(PEDRMS,2));
double NPE = 1.15*pow(TRUEMEAN,2)/pow(TRUERMS,2); // 1.15+-0.05 = ENF(Excess Noise Factor)
double GAIN = TRUEMEAN*2.6*10000/(NPE*1.6);
if (GAIN>0) {
GAINHV->Fill(HV[hv],GAIN);
GAINHV->SetMarkerStyle(8);
GAINHV->SetMarkerColor(kRed);
GAINHV->SetFillColor(2);
if(hv==0){
GAIN_650->Fill(650,GAIN);
double content_650 = GAIN_650->GetBinContent(qie);
cout<<"650_GetBinContent__"<<content_650<<endl;
GAIN_650->SetMarkerStyle(8);
GAIN_650->SetMarkerColor(kRed);
GAIN_650->SetFillColor(2);}
if(hv==1){
GAIN_700->Fill(700,GAIN);
GAIN_700->SetMarkerStyle(8);
GAIN_700->SetMarkerColor(kBlue);
GAIN_700->SetFillColor(3);}
if(hv==0){
cout<<"650__"<<GAIN<<endl;
GAIN650->Fill(GAIN);
double content650 = GAIN650->GetBinContent(qie);
cout<<"650GetBinContent__"<<content650<<endl;
GAIN650->SetMarkerColor(kRed);
GAIN650->SetFillColor(1);
GAIN650->SetMarkerStyle(8);}
if(hv==1){
cout<<"700__"<<GAIN<<endl;
GAIN700->Fill(GAIN);
GAIN700->SetMarkerColor(kBlue);
GAIN700->SetFillColor(2);
GAIN700->SetMarkerStyle(8);}
if(hv==1){
cout<<"700__"<<GAIN<<endl;
GAIN700->Fill(GAIN);
GAIN700->SetMarkerColor(kBlue);
GAIN700->SetFillColor(2);
GAIN700->SetMarkerStyle(8);}
}
}
}
}
GAINCorr->Fill(GAIN650->GetBinContent(qie),GAIN700->GetBinContent(qie));
GAINCorr->SetMarkerColor(kGreen);
GAINCorr->SetMarkerStyle(8);
GAINCorr->SetFillColor(3);
GAINCorr->GetXaxis()->SetTitle("GAIN650");
GAINCorr->GetYaxis()->SetTitle("GAIN700");
}
c4->cd();
GAINCorr->Draw("AXIS");
GAIN650->Draw("same");
GAIN700->Draw("same");
c3->cd();
GAINHV->Draw("AXIS");
GAIN_650->Draw("same");
GAIN_700->Draw("same");
c4->Write();
c3->Write();
}
Thanks for your help,
Cheers,
Ersel
Run_2983.root (731 KB)
map.txt (241 Bytes)