# No matching member function for call to 'Get' (TTree)

**URL:** <https://root-forum.cern.ch/t/no-matching-member-function-for-call-to-get-ttree/43292>\
**Category:** Newbie\
**Tags:** tree\
**Created:** [January 27, 2021, 1:27pm UTC](https://root-forum.cern.ch/t/no-matching-member-function-for-call-to-get-ttree/43292 "2021-01-27T13:27:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alobasenko](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@alobasenko](https://root-forum.cern.ch/u/alobasenko)\
**Post date:** [January 27, 2021, 1:27pm UTC](https://root-forum.cern.ch/t/no-matching-member-function-for-call-to-get-ttree/43292/1 "2021-01-27T13:27:14Z")

</div>

_ROOT Version:_ 6.20/00  
_Platform:_ ubuntu 20.04  
_Compiler:_ g++ 9.3.0

* * *

Hi,

In my macro, I am writing a function that should copy the content of one branch to the histogram.  
Part of my code that involved in this:

```auto
#include <TFile.h>
#include <TRandom3.h>
#include <TTree.h>
#include <TStopwatch.h>
#include <TH1.h>
#include <TF1.h>
#include <TCanvas.h>
#include <TCut.h>
#include <TStyle.h>
#include <TPaveStats.h>
#include <TMath.h>

#include <string.h>

using namespace std;

vector<double> FindROI(const TFile* fTracks_ideal, const double& mu_potential){   
    vector<double> roi;
    auto t_ana_uncut = fTracks_ideal->Get<TTree>("AnalysisTree");
    TH1F *hspectrum_uncut = new TH1F("hspectrum_uncut", "Energy spectrum of a reconstructed events without cut strips.", 100,1800,2620);
    
    //filling the histogram
    t_ana_uncut->Project("hspectrum_uncut", "tckAna_trackEnergy");

    ~~~
    The rest of my code
    ~~~

    return roi;
}

void cut_ROI_Xe136()
{
    Double_t xpeak = 2420.; 

    TFile *f_tracks2 = new TFile("my_file.root");
    vector<double> ROI_vec = FindROI(f_tracks2, xpeak);
    return 0;
}

```

When I execute my code I receive such an error:

```auto
cut_ROI_Xe136.C:55:39: error: no matching member function for call to 'Get'
    auto t_ana_uncut = fTracks_ideal->Get<TTree>("AnalysisTree");
                       ~~~~~~~~~~~~~~~^~~~~~~~~~
note: candidate function not viable: no known conversion from 'const TFile' to 'TDirectoryFile' for object argument
   template <class T> inline T* Get(const char* namecycle)
                                ^

```

Which is confusing as if I am just adding a line `TTree *t_ana_uncut = (TTree*)f_tracks2->Get("AnalysisTree");` in my main macro after opening my file and not using FindROI function, everything is working fine.

Do you have an idea what am I doing wrong?  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [January 27, 2021, 2:06pm UTC](https://root-forum.cern.ch/t/no-matching-member-function-for-call-to-get-ttree/43292/2 "2021-01-27T14:06:28Z")

</div>

Hi @alobasenko,  
the important part of the error message is:

```auto
no known conversion from 'const TFile' to 'TDirectoryFile'

```

and the `const` in particular: you can’t call `Get` on a const TFile because the method is not const (it modifies the file’s state).

Changing the declaration of `FindROI` to accept a pointer to non-const TFile should fix the issue.

Also note that to use the templated `Get<TTree>` (as opposed to the other invocation you mention at the end of your post) you need a recent ROOT version (but if the templated version is not present the compiler error will say so).

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![alobasenko](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@alobasenko](https://root-forum.cern.ch/u/alobasenko)\
**Post date:** [January 27, 2021, 9:17pm UTC](https://root-forum.cern.ch/t/no-matching-member-function-for-call-to-get-ttree/43292/3 "2021-01-27T21:17:08Z")

</div>

Hi @eguiraud ,

thank you very much for your help!
