TH2D histogram / 'unknown type name' errors

Hi,
i’m trying to create a TH2D histogram,
and i get the following errors (errors happen for all my histograms):

error: unknown type name
      'h_light_pass0'
   h_light_pass0->Divide(h_light0);
   ^
 error: cannot use arrow
      operator on a type
   h_light_pass0->Divide(h_light0);

Apparently, i am doing something very obvious and very wrong but I can’t figure it out…
Thanks in advance :slight_smile:

I attach my full code below (sorry for it being too long!):

#include <iostream>
#include <TString.h>
#include <TH1F.h>
#include <TTree.h>
#include <TFile.h>
#include "vector"
#include <TROOT.h>
#include <TStopwatch.h>
#include <TMath.h>
#include <stdlib.h>
#include <cmath>
#include "TH2.h"
#include <TClass.h>

using namespace std;

void finalobjects()

{
  gROOT->Reset();
  gROOT->SetStyle("Plain"); 
  gStyle->SetOptStat(1);
  gStyle->SetOptFit(1);
  gStyle->SetPadColor(0);
  gStyle->SetPalette(1);
  
  TFile *f = TFile::Open("flatTree_TT_TuneCUETP8M2T4_13TeV-powheg-pythia8.root", "READ");
  TTree *tree = (TTree*)f->Get("boosted/events");

  vector<float> *jetMassSoftDrop(0);
  vector<float> *jetMass(0);
  vector<float> *jetEta(0);
  vector<float> *jetPt(0);
  vector<float> *jetMassSub0(0);
  vector<float> *jetMassSub1(0);
  vector<bool> *triggerBit(0);
  vector<float> *jetNBSub(0);
  vector<float> *jetIsBtag(0);
  vector<float> *jetFlavor(0);
  float mva;
  int nJets, nBJets, nLeptons, category;  

  tree->SetBranchAddress("jetMassSoftDrop", &jetMassSoftDrop);  
  tree->SetBranchAddress("jetMass", &jetMass);  
  tree->SetBranchAddress("jetEta", &jetEta);
  tree->SetBranchAddress("jetPt", &jetPt);
  tree->SetBranchAddress("jetMassSub0", &jetMassSub0);
  tree->SetBranchAddress("jetMassSub1", &jetMassSub1);
  tree->SetBranchAddress("triggerBit", &triggerBit);
  tree->SetBranchAddress("jetNBSub", &jetNBSub);
  tree->SetBranchAddress("jetIsBtag", &jetIsBtag);  
  tree->SetBranchAddress("jetFlavor", &jetFlavor);  
  tree->SetBranchAddress("mva", &mva);
  tree->SetBranchAddress("nJets",&nJets);
  tree->SetBranchAddress("nBJets",&nBJets);
  tree->SetBranchAddress("nLeptons",&nLeptons);
  tree->SetBranchAddress("category", &category);

  //histograms for 1st leading jet ( [0] )
  TH2D *h_light0 = new TH2D ("h_light0", "h_light0",100, 0, 4, 100, 400, 1000);
  TH2D *h_light_pass0 = new TH2D ("h_light_pass0", "h_light_pass0",100, 0, 4, 100, 400, 1000);
  TH2D *h_c0 = new TH2D ("h_c0", "h_c0",100, 0, 4, 100, 400, 1000);
  TH2D *h_c_pass0 = new TH2D ("h_c_pass0", "h_c_pass0",100, 0, 4, 100, 400, 1000);
  TH2D *h_g0 = new TH2D ("h_g0", "h_g0",100, 0, 4, 100, 400, 1000);
  TH2D *h_g_pass0 = new TH2D ("h_g_pass0", "h_gt_pass0",100, 0, 4, 100, 400, 1000);

  //histograms for 2nd leading jet ( [1] )
  TH2D *h_light1 = new TH2D ("h_light1", "h_light1",100, 0, 4, 100, 400, 1000);
  TH2D *h_light_pass1 = new TH2D ("h_light_pass1", "h_light_pass1",100, 0, 4, 100, 400, 1000);
  TH2D *h_c1 = new TH2D ("h_c1", "h_c1",100, 0, 4, 100, 400, 1000);
  TH2D *h_c_pass1 = new TH2D ("h_c_pass1", "h_c_pass1",100, 0, 4, 100, 400, 1000);
  TH2D *h_g1 = new TH2D ("h_g1", "h_g1",100, 0, 4, 100, 400, 1000);
  TH2D *h_g_pass1 = new TH2D ("h_g_pass1", "h_g_pass1",100, 0, 4, 100, 400, 1000);
  
  Long64_t N = tree->GetEntries();
   for (Long64_t i=0;i<N;i++){
      tree->GetEntry(i);
     //mva>0.8
      if ((nJets>1) && (nLeptons==0) && ((*jetPt)[1]>400) && (mva>0.8) && ((*triggerBit)[2]==true) && (category==2)){
	if (((abs((*jetFlavor)[0])==1)||(abs((*jetFlavor)[0])==2)||(abs((*jetFlavor)[0])==3))
	    && ((abs((*jetFlavor)[1])==1)||(abs((*jetFlavor)[1])==2)||(abs((*jetFlavor)[1])==3))){//------u,d,s quarks
	  h_light0->Fill(abs((*jetEta)[0]),(*jetPt)[0]);
	  h_light1->Fill(abs((*jetEta)[1]),(*jetPt)[1]);
	  if ((*jetIsBtag)[0]!=0 && (*jetIsBtag)[1]!=0){       
	     h_light_pass0->Fill(abs((*jetEta)[0]),(*jetPt)[0]);
	     h_light_pass1->Fill(abs((*jetEta)[1]),(*jetPt)[1]);
	    }
         }
	else if ((abs((*jetFlavor)[0])==4)&&(abs((*jetFlavor)[1])==4)){//------c quark
	  h_c0->Fill(abs((*jetEta)[0]),(*jetPt)[0]);
	  h_c1->Fill(abs((*jetEta)[1]),(*jetPt)[1]);
	  if ((*jetIsBtag)[0]!=0 && (*jetIsBtag)[1]!=0){        // is btagged ?!?!?
	     h_c_pass0->Fill(abs((*jetEta)[0]),(*jetPt)[0]);
	     h_c_pass1->Fill(abs((*jetEta)[1]),(*jetPt)[1]);
            }
         }
	else if ((*jetFlavor)[0]==21 && (*jetFlavor)[1]==21){//------gluons
	  h_g0->Fill(abs((*jetEta)[0]),(*jetPt)[0]);
	  h_g1->Fill(abs((*jetEta)[1]),(*jetPt)[1]);
	  if ((*jetIsBtag)[0]!=0 && (*jetIsBtag)[1]!=0){       // is btagged ?!?!?
	     h_g_pass0->Fill(abs((*jetEta)[0]),(*jetPt)[0]);
	     h_g_pass1->Fill(abs((*jetEta)[1]),(*jetPt)[1]);
	    }
        }
   }//end of 1st if
      else continue;
  }
}//end of for loop

   h_light_pass0->Divide(h_light0);
   h_light_pass1->Divide(h_light1);
   h_c_pass0->Divide(h_c0);
   h_c_pass1->Divide(h_c1);
   h_g_pass0->Divide(h_g0);
   h_g_pass1->Divide(h_g1);

   TCanvas *can1 = new TCanvas ("can1", "can1", 600, 600);
   h_light_pass0->SetTitle("light quarks: u,d,s");
   h_light_pass0->GetXaxis()->SetTitle("jetPT [GeV]")
   h_light_pass0->GetYaxis()->SetTitle("|eta|");
//_light_pass0->GetYaxis()->SetRangeUser(-0.08,0.08);
   h_light_pass0->Draw();
   h_light_pass1->Draw("sames");

   TCanvas *can2 = new TCanvas ("can2", "can2", 600, 600);
   h_c_pass0->SetTitle("c quarks");
   h_c_pass0->GetXaxis()->SetTitle("jetPT [GeV]")
   h_c_pass0->GetYaxis()->SetTitle("|eta|");
//h_c_pass0->GetYaxis()->SetRangeUser(-0.08,0.08);
   h_c_pass0->Draw();
   h_c_pass1->Draw("sames");

   TCanvas *can3 = new TCanvas ("can3", "can3", 600, 600);
   h_g_pass0->SetTitle("gluons");
   h_g_pass0->GetXaxis()->SetTitle("jetPT [GeV]")
   h_g_pass0->GetYaxis()->SetTitle("|eta|");
//h_g_pass0->GetYaxis()->SetRangeUser(-0.08,0.08);
   h_g_pass0->Draw();
   h_g_pass1->Draw("sames");

}

I guess, it is your problem.
Just remove empty include

I have no empty # include
it’s the # include < iostream >
but for some reason it appears empty when i paste it here

// ... 
#include "TStyle.h"
#include "TCanvas.h"
// ...
  // gROOT->Reset();
// ...
// }//end of for loop
// ...
   h_light_pass0->GetXaxis()->SetTitle("jetPT [GeV]");
// ...
   h_c_pass0->GetXaxis()->SetTitle("jetPT [GeV]");
// ...
   h_g_pass0->GetXaxis()->SetTitle("jetPT [GeV]");
// ...

BTW. When you post “output” or “source code” here, do remember to enclose them into two lines which contain just three characters ``` (see how your post has been edited above).

will do, thank you!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.