No matching constructor for initialization

Hello , I’m trying run many files. My goal is to add *.root files from a specified directory to a TChain for processing in ROOT. When I’m trying to run it using .L evnts.C and then evnts l; it give me some errors like that

ROOT_prompt_1:1:7: error: no matching constructor for initialization of 'evnts'
evnts l;
/evnts.h:21:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 0 were provided
class evnts {
/evnts.h:227:8: note: candidate constructor not viable: requires at least argument 'name', but no arguments were provided
evnts::evnts(std::string name, TTree* tree) : fChain(0)

Here is related code:

#ifndef evnts_h
#define evnts_h

#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>

#include <iostream>
#include <fstream>
#include <string>

// Header file for the classes stored in the TTree if any.

class evnts {
    TTree  *fChain;   //!pointer to the analyzed TTree or TChain
    Int_t  fCurrent; //!current Tree number in a TChain

    // Fixed size dimensions of array or collections stored in the TTree if any.

       // Declaration of leaf types
    Int_t           run;
    Float_t         magfld;
    UInt_t          orbit;
    Double_t        time;
    UShort_t        trig_mask;
    Float_t         centV0;
    Float_t         centCL0;
    Float_t         centCL1;
    Int_t           nITSCls;
    Int_t           nITSTrkls;
    Int_t           multTr;
    Int_t           multV0Tot;
    Int_t           multV0On;
    Int_t           tpcClsTot;
    UShort_t        bx;
    Float_t         vx;
    Float_t         vy;
    Float_t         vz;
    Float_t         tpc_mult;
    Float_t         voa_mult;
    Float_t         voc_mult;
    Float_t         vx_min;
    Float_t         vx_max;
    Float_t         vy_min;
    Float_t         vy_max;
    Float_t         zax1;
    Float_t         zcx1;
    Float_t         zay1;
    Float_t         zcy1;
    Float_t         zax2;
    Float_t         zcx2;
    Float_t         zay2;
    Float_t         zcy2;
    Float_t         zae;
    Float_t         zce;
    Float_t         zna[5];
    Float_t         znc[5];
    Float_t         uax1;
    Float_t         ucx1;
    Float_t         uay1;
    Float_t         ucy1;
    Float_t         uax2;
    Float_t         ucx2;
    Float_t         uay2;
    Float_t         ucy2;
    Float_t         vax1[4];
    Float_t         vcx1[4];
    Float_t         vay1[4];
    Float_t         vcy1[4];
    Float_t         vax2[4];
    Float_t         vcx2[4];
    Float_t         vay2[4];
    Float_t         vcy2[4];
    Float_t         vae[4];
    Float_t         vce[4];
    Float_t         txpl[7];
    Float_t         typl[7];
    Float_t         txpr[7];
    Float_t         typr[7];
    Float_t         txnl[7];
    Float_t         tynl[7];
    Float_t         txnr[7];
    Float_t         tynr[7];
    Int_t           nv;
    Float_t         pt[300];   //[nv]
    Float_t         eta[300];   //[nv]
    Float_t         phi[300];   //[nv]
    Float_t         rap[300];   //[nv]
    Float_t         dca[300];   //[nv]
    Float_t         angle[300];   //[nv]
    Float_t         path[300];   //[nv]
    Float_t         dcapn[300];   //[nv]
    Short_t         v[300];   //[nv]
    Float_t         m[300];   //[nv]
    Float_t         ptp[300];   //[nv]
    Float_t         etap[300];   //[nv]
    Float_t         phip[300];   //[nv]
    Float_t         dcap[300];   //[nv]
    Float_t         nrowp[300];   //[nv]
    Float_t         nclusp[300];   //[nv]
    Float_t         nsgmp[300];   //[nv]
    Float_t         ptn[300];   //[nv]
    Float_t         etan[300];   //[nv]
    Float_t         phin[300];   //[nv]
    Float_t         dcan[300];   //[nv]
    Float_t         nrown[300];   //[nv]
    Float_t         nclusn[300];   //[nv]
    Float_t         nsgmn[300];   //[nv]
    Float_t         phistar[300];   //[nv]
    Float_t         thetastar[300];   //[nv]

    // List of branches
    TBranch* b_run;   //!
    TBranch* b_magfld;   //!
    TBranch* b_orbit;   //!
    TBranch* b_time;   //!
    TBranch* b_trig_mask;   //!
    TBranch* b_centV0;   //!
    TBranch* b_centCL0;   //!
    TBranch* b_centCL1;   //!
    TBranch* b_nITSCls;   //!
    TBranch* b_nITSTrkls;   //!
    TBranch* b_multTrk;   //!
    TBranch* b_multV0Tot;   //!
    TBranch* b_multV0On;   //!
    TBranch* b_tpcClsTot;   //!
    TBranch* b_bx;   //!
    TBranch* b_vx;   //!
    TBranch* b_vy;   //!
    TBranch* b_vz;   //!
    TBranch* b_tpc_mult;   //!
    TBranch* b_voa_mult;   //!
    TBranch* b_voc_mult;   //!
    TBranch* b_vx_min;   //!
    TBranch* b_vx_max;   //!
    TBranch* b_vy_min;   //!
    TBranch* b_vy_max;   //!
    TBranch* b_zax1;   //!
    TBranch* b_zcx1;   //!
    TBranch* b_zay1;   //!
    TBranch* b_zcy1;   //!
    TBranch* b_zax2;   //!
    TBranch* b_zcx2;   //!
    TBranch* b_zay2;   //!
    TBranch* b_zcy2;   //!
    TBranch* b_zae;   //!
    TBranch* b_zce;   //!
    TBranch* b_zna;   //!
    TBranch* b_znc;   //!
    TBranch* b_uax1;   //!
    TBranch* b_ucx1;   //!
    TBranch* b_uay1;   //!
    TBranch* b_ucy1;   //!
    TBranch* b_uax2;   //!
    TBranch* b_ucx2;   //!
    TBranch* b_uay2;   //!
    TBranch* b_ucy2;   //!
    TBranch* b_vax1;   //!
    TBranch* b_vcx1;   //!
    TBranch* b_vay1;   //!
    TBranch* b_vcy1;   //!
    TBranch* b_vax2;   //!
    TBranch* b_vcx2;   //!
    TBranch* b_vay2;   //!
    TBranch* b_vcy2;   //!
    TBranch* b_vae;   //!
    TBranch* b_vce;   //!
    TBranch* b_txpl;   //!
    TBranch* b_typl;   //!
    TBranch* b_txpr;   //!
    TBranch* b_typr;   //!
    TBranch* b_txnl;   //!
    TBranch* b_tynl;   //!
    TBranch* b_txnr;   //!
    TBranch* b_tynr;   //!
    TBranch* b_nv;   //!
    TBranch* b_pt;   //!
    TBranch* b_eta;   //!
    TBranch* b_phi;   //!
    TBranch* b_rap;   //!
    TBranch* b_dca;   //!
    TBranch* b_angle;   //!
    TBranch* b_path;   //!
    TBranch* b_dcapn;   //!
    TBranch* b_v;   //!
    TBranch* b_m;   //!
    TBranch* b_ptp;   //!
    TBranch* b_etap;   //!
    TBranch* b_phip;   //!
    TBranch* b_dcap;   //!
    TBranch* b_nrowp;   //!
    TBranch* b_nclusp;   //!
    TBranch* b_nsgmp;   //!
    TBranch* b_ptn;   //!
    TBranch* b_etan;   //!
    TBranch* b_phin;   //!
    TBranch* b_dcan;   //!
    TBranch* b_nrown;   //!
    TBranch* b_nclusn;   //!
    TBranch* b_nsgmn;   //!
    TBranch* b_phistar;   //!
    TBranch* b_thetastar;   //!

    evnts(std::string name, TTree* tree = 0);
    virtual ~evnts();
    virtual Int_t    Cut(Long64_t entry);
    virtual Int_t    GetEntry(Long64_t entry);
    virtual Long64_t LoadTree(Long64_t entry);
    virtual void     Init(TTree* tree);
    virtual void     Loop();
    virtual Bool_t   Notify();
    virtual void     Show(Long64_t entry = -1);
    std::string runName; //**************


#ifdef evnts_cxx
evnts::evnts(std::string name, TTree* tree) : fChain(0)
    // if parameter tree is not specified (or zero), connect the file
    // used to generate this class and read the Tree.
  if (tree == 0) {

     //      std::cout<<"Enter Run name (e.g. V6): ";
     //      std::cin >> runName;

      TChain * chain = new TChain("tree","");
      char runlist[40];

      char fileName[40];
      std::string runN;
      std::ifstream	llist(runlist);
      //int nfile=0;
      int nfileOpen=0; 
      int nfileNot=0; 
      for (int i=0; i < 100000; i++)
	  if (!(llist >> runN)) break;
	  ifstream ifile(fileName);
	  if( {
	    cout<<fileName<<" file does not exist"<<endl;

	  //cout<<"adding file ="<<fileName<<endl;
      //  chain->GetListOfLeaves()->ls();
      //      cout <<"Init chain OK"<<endl;
      cout <<"Init chain OK; "<<nfileOpen<<" files in chain    "<<nfileNot<<"not found"<<endl;

      tree = chain;


    if (!fChain) return;
    delete fChain->GetCurrentFile();

Int_t evnts::GetEntry(Long64_t entry)
    // Read contents of entry.
    if (!fChain) return 0;
    return fChain->GetEntry(entry);
Long64_t evnts::LoadTree(Long64_t entry)
    // Set the environment to read one entry
    if (!fChain) return -5;
    Long64_t centry = fChain->LoadTree(entry);
    if (centry < 0) return centry;
    if (fChain->GetTreeNumber() != fCurrent) {
        fCurrent = fChain->GetTreeNumber();
    return centry;

void evnts::Init(TTree* tree)
    // The Init() function is called when the selector needs to initialize
    // a new tree or chain. Typically here the branch addresses and branch
    // pointers of the tree will be set.
    // It is normally not necessary to make changes to the generated
    // code, but the routine can be extended by the user if needed.
    // Init() will be called many times when running on PROOF
    // (once per file to be processed).

    // Set branch addresses and branch pointers
    if (!tree) return;
    fChain = tree;
    fCurrent = -1;

    fChain->SetBranchAddress("run", &run, &b_run);
    fChain->SetBranchAddress("magfld", &magfld, &b_magfld);
    fChain->SetBranchAddress("orbit", &orbit, &b_orbit);
    fChain->SetBranchAddress("time", &time, &b_time);
    fChain->SetBranchAddress("trig_mask", &trig_mask, &b_trig_mask);
    fChain->SetBranchAddress("centV0", &centV0, &b_centV0);
    fChain->SetBranchAddress("centCL0", &centCL0, &b_centCL0);
    fChain->SetBranchAddress("centCL1", &centCL1, &b_centCL1);
    fChain->SetBranchAddress("nITSCls", &nITSCls, &b_nITSCls);
    fChain->SetBranchAddress("nITSTrkls", &nITSTrkls, &b_nITSTrkls);
    // fChain->SetBranchAddress("multTrk", &multTrk, &b_multTrk);
    fChain->SetBranchAddress("multV0Tot", &multV0Tot, &b_multV0Tot);
    fChain->SetBranchAddress("multV0On", &multV0On, &b_multV0On);
    fChain->SetBranchAddress("tpcClsTot", &tpcClsTot, &b_tpcClsTot);
    fChain->SetBranchAddress("bx", &bx, &b_bx);
    fChain->SetBranchAddress("vx", &vx, &b_vx);
    fChain->SetBranchAddress("vy", &vy, &b_vy);
    fChain->SetBranchAddress("vz", &vz, &b_vz);
    fChain->SetBranchAddress("tpc_mult", &tpc_mult, &b_tpc_mult);
    fChain->SetBranchAddress("voa_mult", &voa_mult, &b_voa_mult);
    fChain->SetBranchAddress("voc_mult", &voc_mult, &b_voc_mult);
    fChain->SetBranchAddress("vx_min", &vx_min, &b_vx_min);
    fChain->SetBranchAddress("vx_max", &vx_max, &b_vx_max);
    fChain->SetBranchAddress("vy_min", &vy_min, &b_vy_min);
    fChain->SetBranchAddress("vy_max", &vy_max, &b_vy_max);
    fChain->SetBranchAddress("zax1", &zax1, &b_zax1);
    fChain->SetBranchAddress("zcx1", &zcx1, &b_zcx1);
    fChain->SetBranchAddress("zay1", &zay1, &b_zay1);
    fChain->SetBranchAddress("zcy1", &zcy1, &b_zcy1);
    fChain->SetBranchAddress("zax2", &zax2, &b_zax2);
    fChain->SetBranchAddress("zcx2", &zcx2, &b_zcx2);
    fChain->SetBranchAddress("zay2", &zay2, &b_zay2);
    fChain->SetBranchAddress("zcy2", &zcy2, &b_zcy2);
    fChain->SetBranchAddress("zae", &zae, &b_zae);
    fChain->SetBranchAddress("zce", &zce, &b_zce);
    fChain->SetBranchAddress("zna", zna, &b_zna);
    fChain->SetBranchAddress("znc", znc, &b_znc);
    fChain->SetBranchAddress("uax1", &uax1, &b_uax1);
    fChain->SetBranchAddress("ucx1", &ucx1, &b_ucx1);
    fChain->SetBranchAddress("uay1", &uay1, &b_uay1);
    fChain->SetBranchAddress("ucy1", &ucy1, &b_ucy1);
    fChain->SetBranchAddress("uax2", &uax2, &b_uax2);
    fChain->SetBranchAddress("ucx2", &ucx2, &b_ucx2);
    fChain->SetBranchAddress("uay2", &uay2, &b_uay2);
    fChain->SetBranchAddress("ucy2", &ucy2, &b_ucy2);
    fChain->SetBranchAddress("vax1", vax1, &b_vax1);
    fChain->SetBranchAddress("vcx1", vcx1, &b_vcx1);
    fChain->SetBranchAddress("vay1", vay1, &b_vay1);
    fChain->SetBranchAddress("vcy1", vcy1, &b_vcy1);
    fChain->SetBranchAddress("vax2", vax2, &b_vax2);
    fChain->SetBranchAddress("vcx2", vcx2, &b_vcx2);
    fChain->SetBranchAddress("vay2", vay2, &b_vay2);
    fChain->SetBranchAddress("vcy2", vcy2, &b_vcy2);
    fChain->SetBranchAddress("vae", vae, &b_vae);
    fChain->SetBranchAddress("vce", vce, &b_vce);
    fChain->SetBranchAddress("txpl", txpl, &b_txpl);
    fChain->SetBranchAddress("typl", typl, &b_typl);
    fChain->SetBranchAddress("txpr", txpr, &b_txpr);
    fChain->SetBranchAddress("typr", typr, &b_typr);
    fChain->SetBranchAddress("txnl", txnl, &b_txnl);
    fChain->SetBranchAddress("tynl", tynl, &b_tynl);
    fChain->SetBranchAddress("txnr", txnr, &b_txnr);
    fChain->SetBranchAddress("tynr", tynr, &b_tynr);
    fChain->SetBranchAddress("nv", &nv, &b_nv);
    fChain->SetBranchAddress("pt", pt, &b_pt);
    fChain->SetBranchAddress("eta", eta, &b_eta);
    fChain->SetBranchAddress("phi", phi, &b_phi);
    fChain->SetBranchAddress("rap", rap, &b_rap);
    fChain->SetBranchAddress("dca", dca, &b_dca);
    fChain->SetBranchAddress("angle", angle, &b_angle);
    fChain->SetBranchAddress("path", path, &b_path);
    fChain->SetBranchAddress("dcapn", dcapn, &b_dcapn);
    fChain->SetBranchAddress("v", v, &b_v);
    fChain->SetBranchAddress("m", m, &b_m);
    fChain->SetBranchAddress("ptp", ptp, &b_ptp);
    fChain->SetBranchAddress("etap", etap, &b_etap);
    fChain->SetBranchAddress("phip", phip, &b_phip);
    fChain->SetBranchAddress("dcap", dcap, &b_dcap);
    fChain->SetBranchAddress("nrowp", nrowp, &b_nrowp);
    fChain->SetBranchAddress("nclusp", nclusp, &b_nclusp);
    fChain->SetBranchAddress("nsgmp", nsgmp, &b_nsgmp);
    fChain->SetBranchAddress("ptn", ptn, &b_ptn);
    fChain->SetBranchAddress("etan", etan, &b_etan);
    fChain->SetBranchAddress("phin", phin, &b_phin);
    fChain->SetBranchAddress("dcan", dcan, &b_dcan);
    fChain->SetBranchAddress("nrown", nrown, &b_nrown);
    fChain->SetBranchAddress("nclusn", nclusn, &b_nclusn);
    fChain->SetBranchAddress("nsgmn", nsgmn, &b_nsgmn);
    fChain->SetBranchAddress("phistar", phistar, &b_phistar);
    fChain->SetBranchAddress("thetastar", thetastar, &b_thetastar);

Bool_t evnts::Notify()
    // The Notify() function is called when a new file is opened. This
    // can be either for a new TTree in a TChain or when when a new TTree
    // is started when using PROOF. It is normally not necessary to make changes
    // to the generated code, but the routine can be extended by the
    // user if needed. The return value is currently not used.

    return kTRUE;

void evnts::Show(Long64_t entry)
    // Print contents of entry.
    // If entry is not specified, print current entry
    if (!fChain) return;
Int_t evnts::Cut(Long64_t entry)
    // This function may be called from Loop.
    // returns  1 if entry is accepted.
    // returns -1 otherwise.
    return 1;
#endif // #ifdef evnts_cxx


Thanks for posting this question.
The error message is perhaps already pointing to the solution:

/evnts.h:227:8: note: candidate constructor not viable: requires at least argument 'name', but no arguments were provided
evnts::evnts(std::string name, TTree* tree) : fChain(0)

This is saying that your constructor needs at least two parameters. If one looks at the code, it can be seen that it’s true:

evnts::evnts(std::string name, TTree* tree) : fChain(0)
    // if parameter tree is not specified (or zero), connect the file
    // used to generate this class and read the Tree.

Moreover, the second parameter can even be a nullptr.

Said that, these days we always propose to migrate all analyses to the powerful RDataFrame interface.

I hope this helps.


The problem is same approach works in another macro but not in this one

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