How to load 2 different TTree in the same myfile.C created with MakeClass?

Hello everybody,
I’m trying to analyze two different TTree of data (data and pedestal). I created two different class (MyReco.C and ped.C) with MakeClass, but now i want to analyze all the data in one single macro (MyReco.C).
I’ve included ped.h in header file of MyReco, but it is non enough.
I include the listing of header file for grater clarity.

1. #ifndef prova_h
2. #define prova_h

3. #include "ped.h"
4. #include <TROOT.h>
5. #include <TChain.h>
6. #include <TFile.h>
7. #include <TH1F.h>
8. #include <TH2F.h>

9. // Header file for the classes stored in the TTree if any.
10. #include "vector"
11. #include "vector"
12. #include "vector"
13. #include "vector"
14. #include "vector"

15. class prova {
16. public :
17.    TTree          *fChain;   //!pointer to the analyzed TTree or TChain
18.    Int_t           fCurrent; //!current Tree number in a TChain
19.    ped 			  *fOther;

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

21.    // Declaration of leaf types
22.    ULong64_t       evt;
23.    UInt_t          error;
24.    Int_t           daqTimeSec;
25.    Int_t           daqTimeMicroSec;
26.    Int_t           srsTimeStamp;
27.    UInt_t          srsTrigger;
28.    vector<unsigned int> *srsFec;
29.    vector<unsigned int> *srsChip;
30.    vector<unsigned int> *srsChan;
31.    vector<string>  *mmChamber;
32.    vector<int>     *mmLayer;
33.    vector<char>    *mmReadout;
34.    vector<int>     *mmStrip;
35.    vector<vector<short> > *raw_q;
36.    vector<short>   *max_q;
37.    vector<int>     *t_max_q;

38.     // List of branches
39.     TBranch        *b_evt;   //!
40.     TBranch        *b_error;   //!
41.     TBranch        *b_daqTimeSec;   //!
42.     TBranch        *b_daqTimeMicroSec;   //!
43.     TBranch        *b_srsTimeStamp;   //!
44.     TBranch        *b_srsTrigger;   //!
45.     TBranch        *b_srsFec;   //!
46.     TBranch        *b_srsChip;   //!
47.     TBranch        *b_srsChan;   //!
48.     TBranch        *b_mmChamber;   //!
49.     TBranch        *b_mmLayer;   //!
50.    	TBranch        *b_mmReadout;   //!
51.    	TBranch        *b_mmStrip;   //!
52.    	TBranch        *b_raw_q;   //!
53.    	TBranch        *b_max_q;   //!
54.    	TBranch        *b_t_max_q;   //!

55.    prova(TTree *tree=0);
56.    virtual ~prova();
57.    virtual Int_t    Cut(Long64_t entry);
58.    virtual Int_t    GetEntry(Long64_t entry);
59.    virtual Long64_t LoadTree(Long64_t entry);
60.    virtual void     Init(TTree *tree);
61.    virtual void     Loop();
62.    virtual Bool_t   Notify();
63.    virtual void     Show(Long64_t entry = -1);
64.    virtual void 	Cluster(map<int,int>&, string&, Int_t&, vector<int>&, vector<int>&, vector<double>&, vector<string>&, vector<int>&, vector<int>&);
65.    virtual void		Mapping(map<int,int>&,map<int,int>&,string&);	
66.    virtual void		Mapping_1(map<int,int>&,map<int,int>&,string&);	
67.    virtual int		EventSelection(Int_t&,Int_t&,Int_t&,Int_t&,Int_t&,Int_t&,vector<string>&, Int_t&);
68. 	private:
69. 	 //TFile *_fout;
70. 	 TString _outdirname;		
71. };

72. #endif

73. #ifdef prova_cxx
74. prova::prova(TTree *tree) : fChain(0) 
75. {
76. // if parameter tree is not specified (or zero), connect the file
77. // used to generate this class and read the Tree.
78.    if (tree == 0) {
79.       TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("/data/run177.root");
80.       if (!f) {
81.          f = new TFile("/data/run177.root");
82.       }
83.       f->GetObject("apv_raw",tree);
84.    }
85.    Init(tree);
86.    TFile *g = (TFile*)gROOT->GetListOfFiles()->FindObject("/data/run177.root");
87.    if (!g) {
88.       g = new TFile("/data/run177.root");
89.    }
90.    g->GetObject("apv_raw_ped",tree);
91.    fOther = new ped( apv_raw_ped ); 
92. }

93. prova::~prova()
94. {
95.    if (!fChain) return;
96.    delete fChain->GetCurrentFile();
97. }

98. Int_t prova::GetEntry(Long64_t entry)
99. {
100. // Read contents of entry.
101.    if (!fChain) return 0;
102.    return fChain->GetEntry(entry);
103. }
104. Long64_t prova::LoadTree(Long64_t entry)
105. {
106. // Set the environment to read one entry
107.    if (!fChain) return -5;
108.    Long64_t centry = fChain->LoadTree(entry);
109.    if (centry < 0) return centry;
110.    if (fChain->GetTreeNumber() != fCurrent) {
111.       fCurrent = fChain->GetTreeNumber();
112.       Notify();
113.    }
114.    return centry;
115. }

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

125.    // Set object pointer
126.    srsFec = 0;
127.    srsChip = 0;
128.    srsChan = 0;
129.    mmChamber = 0;
130.    mmLayer = 0;
131.    mmReadout = 0;
132.    mmStrip = 0;
133.    raw_q = 0;
134.    max_q = 0;
135.    t_max_q = 0;

136. // Set branch addresses and branch pointers
137.    if (!tree) return;
138.    fChain = tree;
139.    fCurrent = -1;
140.    fChain->SetMakeClass(1);

141.    fChain->SetBranchAddress("evt", &evt, &b_evt);
142.    fChain->SetBranchAddress("error", &error, &b_error);
143.    fChain->SetBranchAddress("daqTimeSec", &daqTimeSec, &b_daqTimeSec);
144.    fChain->SetBranchAddress("daqTimeMicroSec", &daqTimeMicroSec, &b_daqTimeMicroSec);
145.    fChain->SetBranchAddress("srsTimeStamp", &srsTimeStamp, &b_srsTimeStamp);
146.    fChain->SetBranchAddress("srsTrigger", &srsTrigger, &b_srsTrigger);
147.    fChain->SetBranchAddress("srsFec", &srsFec, &b_srsFec);
148.    fChain->SetBranchAddress("srsChip", &srsChip, &b_srsChip);
149.    fChain->SetBranchAddress("srsChan", &srsChan, &b_srsChan);
150.    fChain->SetBranchAddress("mmChamber", &mmChamber, &b_mmChamber);
151.    fChain->SetBranchAddress("mmLayer", &mmLayer, &b_mmLayer);
152.    fChain->SetBranchAddress("mmReadout", &mmReadout, &b_mmReadout);
153.    fChain->SetBranchAddress("mmStrip", &mmStrip, &b_mmStrip);
154.    fChain->SetBranchAddress("raw_q", &raw_q, &b_raw_q);
155.    fChain->SetBranchAddress("max_q", &max_q, &b_max_q);
156.    fChain->SetBranchAddress("t_max_q", &t_max_q, &b_t_max_q);
157. /*
158.    h_sum_q_cluster_ch1 = new TH1F("h_sum_q_cluster_ch1","Distribution sum of charge in cluster P1_M01;sum_q_P1_M01;Entry",150,0.0,5000.);	
159.    h_sum_q_cluster_ch2 = new TH1F("h_sum_q_cluster_ch2","Distribution sum of charge in cluster P2_M01;sum_q_P2_M01;Entry",150,0.0,5000.);	
160.    h_sum_q_cluster_ch3 = new TH1F("h_sum_q_cluster_ch3","Distribution sum of charge in cluster P3_M01;sum_q_P3_M01;Entry",150,0.0,5000.);	
161.    h_sum_q_cluster_ch4 = new TH1F("h_sum_q_cluster_ch4","Distribution sum of charge in cluster P4_M01;sum_q_P4_M01;Entry",150,0.0,5000.);	
162.    h_sum_q_centroid_ch1 = new TH2F("h_sum_q_centroid_ch1","Histo sum of charge vs centroid P1_M01;sum_q;Centroid",150,0.0,5000.,512,500.,1124.);	
163.    h_sum_q_centroid_ch2 = new TH2F("h_sum_q_centroid_ch2","Histo sum of charge vs centroid P2_M01;sum_q;Centroid",150,0.0,5000.,512,500.,1124.);	
164.    h_sum_q_centroid_ch3 = new TH2F("h_sum_q_centroid_ch3","Histo sum of charge vs centroid P3_M01;sum_q;Centroid",150,0.0,5000.,512,500.,1124.);	
165.    h_sum_q_centroid_ch4 = new TH2F("h_sum_q_centroid_ch4","Histo sum of charge vs centroid P4_M01;sum_q;Centroid",150,0.0,5000.,512,500.,1124.);	
166.   */
167.    Notify();
168. }

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

176.    return kTRUE;
177. }

178. void prova::Show(Long64_t entry)
179. {
180. // Print contents of entry.
181. // If entry is not specified, print current entry
182.    if (!fChain) return;
183.    fChain->Show(entry);
184. }
185. Int_t prova::Cut(Long64_t entry)
186. {
187. // This function may be called from Loop.
188. // returns  1 if entry is accepted.
189. // returns -1 otherwise.
190.    return 1;
191. }
192. #endif // #ifdef prova_cxx

thank you in advance

@pcanal maybe can you help here please?
Update: I think it is duplicated post with MakeClass with multiple trees

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