Dear Experts,
I have a root tree and I made a class from the tree getting file.C, file.h
In the file.C I’m reading input root files and from each file I get the tree and try to fill histograms with variable name depending in some cuts. For every cut I want to fill histogram with different name. I get error
warning: invalid memory pointer passed to a callee:
if(f_pfmet >j )h_bkg_num[j]->Fill(f_pfmet,f_weight);
here is my code
#define Roc_vrs_Met_cxx
#include "Roc_vrs_Met.h"
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>
#include <TLorentzVector.h>
#include <TNtuple.h>
#include <TSpline.h>
#include <TMath.h>
#include <math.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <stdlib.h>
#include <iomanip>
#include <vector>
#include <string>
#include <cstdlib>
#include <stdio.h>
using namespace std;
void Roc_vrs_Met::Loop()
{
if (fChain == 0) return;
Long64_t nentries = fChain->GetEntriesFast();
Long64_t nbytes = 0, nb = 0;
//---
//Reading bkg files
std::vector<string> Vbkg;
std::vector<string> Vsig;
std::ifstream infile;
infile.open("filelist_bkg_signal.txt");
string inputfilename;
//creating the vector with roottuples
while(std::getline(infile,inputfilename)){
Vbkg.push_back(inputfilename);
}
infile.close();
//Histos
TH1F *h_signal_den = new TH1F("","",1000, 0, 1000);
TH1F *h_bkg_den = new TH1F("","",1000, 0, 1000);
TH1F *h_signal_num[10];
TH1F *h_bkg_num[10];
char *histname = new char[10];
char *histname2 = new char[10];
int nbins=1000,nhistos=200;
float xmin=0,xmax=1000;
for (int i=20; i<=nhistos; i+=20) {
sprintf(histname,"h_signal_num%d",i);
sprintf(histname2,"h_bkg_num%d",i);
h_signal_num[i] = new TH1F(histname,"",nbins,xmin,xmax);
h_bkg_num[i] = new TH1F(histname2,"",nbins,xmin,xmax);
}
Float_t f_weight=-999, f_Z2mass=-999, f_pfmet=-999;
//loop
for(unsigned int ifile=0; ifile<(unsigned int)Vbkg.size(); ifile++){
char dataset[328];
sprintf(dataset,"%s",Vbkg.at(ifile).c_str());
cout << "Root-ple= " << dataset << endl;
TFile *file = TFile::Open(dataset);
cout<<"file opeed"<<endl;
TTree *tree = (TTree*)file->Get("ReducedTree");
unsigned int ntree = tree->GetEntries();
cout<<"tree opend"<<endl;
tree->SetBranchAddress("f_pfmet",&f_pfmet);
tree->SetBranchAddress("f_weight",&f_weight);
tree->SetBranchAddress("f_Z2mass",&f_Z2mass);
//for(unsigned int iev=0; iev<ntree; ++iev){
for(unsigned int iev=0; iev<10; ++iev){
tree->GetEntry(iev);
cout<<"entry = "<<iev<<" met = "<<f_pfmet<<endl;
for(int j=20; j<=200; j+=20){
if(f_pfmet >j )h_bkg_num[j]->Fill(f_pfmet,f_weight);
}
}//iev
}//bkg files
TFile *out = new TFile("out.root","RECREATE");
out->cd();
for(int j=50; j<200; j+=50){
h_bkg_num[j]->Write();
}
out->Close();
cout<<"Done" <<endl;
}
I appreciate if someone help me to solve this problem.