Wrong pointer type (ROOT CERN)

324 Views Asked by At

I'm trying to make histograms from a specific file I was given but I'm getting the following error:

Error in <TTree::SetBranchAddress>: The pointer type given "Double_t" (8) does not correspond to the type needed "vector<float>" by the branch: mu_phi

I'm guessing the issue is that the variables I'm trying to put in are in form of vectors but I have no idea how to fix it. The canvas I get after running this (all values whether it's eta, phi, energy...) just contain the number of entries, mean value and lines representing that and they all look the same.

I'm new at this so bear with me. Any help would be appreciated!

My script (without headers):

void script(){
  
  TFile *file = TFile::Open("output_data.root");

  TTree* tree = (TTree*)file->Get("nominal");

  TChain* fchain = new TChain("nominal");
  fchain->Add("output_data.root");
                                                            
  Double_t mu_pt, mu_e, mu_eta, mu_phi;

   //set branches to variables
  tree->SetBranchAddress("mu_pt", &mu_pt);
  tree->SetBranchAddress("mu_e", &mu_e);
  tree->SetBranchAddress("mu_eta", &mu_eta);
  tree->SetBranchAddress("mu_phi", &mu_phi);

  TH1D *muPt = new TH1D("muPt", ";p_{T} [GeV/c];Events", 100, 0., 200.);
  TH1D *muEta = new TH1D("muEta", ";#eta;Events", 50, -3, 3);
  TH1D *muE = new TH1D("muE", ";Energy;Events", 50, 0, 200);
  TH1D *muPhi = new TH1D("muPhi", ";#phi;Events", 50, -4, 4);
  TH1D *mass = new TH1D("mass", ";mass;Events", 50, 0, 200);

  Long64_t nentries = fchain->GetEntries();

  for (int i=0; i<nentries ; i++) {

  Long64_t ientry = fchain->LoadTree(i);
  if (ientry <0 ) break;

  fchain->GetEntry(i);

  muEta->Fill(mu_eta);
  muPt->Fill(mu_pt);
  muPhi->Fill(mu_phi);
  muE->Fill(mu_e);
}
   cout << "entries = " << nentries << endl;

   TCanvas *c1 = new TCanvas("Eta","Eta",800 ,800);
   c1->cd();
   muEta->Draw();

}

ROOT Version: 6.26/10 Platform: Not Provided Compiler: Not Provided


I tried switching Double_t for vector<float> but that gave me more errors.

error: no matching member function for call to 'Fill'
  muEta->Fill(mu_eta);
  ~~~~~~~^~~~
/snap/root-framework/838/usr/local/include/TH1.h:219:21: note: candidate function not viable: no known conversion from 'vector<float>' to 'Double_t' (aka 'double') for 1st argument
   virtual Int_t    Fill(Double_t x);
                    ^
/snap/root-framework/838/usr/local/include/TH1.h:220:21: note: candidate function not viable: requires 2 arguments, but 1 was provided
   virtual Int_t    Fill(Double_t x, Double_t w);
                    ^
/snap/root-framework/838/usr/local/include/TH1.h:221:21: note: candidate function not viable: requires 2 arguments, but 1 was provided
   virtual Int_t    Fill(const char *name, Double_t w);

There probably is a different way to approach this whole problem I just can't find it.

1

There are 1 best solutions below

0
mims21 On

I don't understand why you use TChain. However, once you open the root file and get the tree, you can use the tree->Draw(varaible>>histogram,"goff") command with the "goff" condition to draw it later in your TCanvas with histogram->Draw( ). You can also check the contents of your.root file using TBrowser