GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ReadMiniTree3.C
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998, Agata Experiment, All rights reserved. *
3  * *
4  * Author: The Agata Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 
16 
17 //
18 //
19 #if !defined(__CINT__) || defined(__MAKECINT__)
20 
21 #include <Riostream.h>
22 #include "TFile.h"
23 #include "TROOT.h"
24 #include "TCanvas.h"
25 #include "TFolder.h"
26 #include "TTree.h"
27 #include "TString.h"
28 #include "TH1F.h"
29 #include "TStopwatch.h"
30 #include "CorrelatedSpaceTree2I.h"
31 #include "CubicFilter.h"
32 
33 #endif
34 Int_t dim = 256;
35 Int_t nDiv = 8;
36 Int_t nTree = 512;
37 
38 //Int_t dim = 1024;
39 //Int_t nDiv = 2;
40 //Int_t nTree = 8;
41 
42 std::vector<int> idxTree;;
43 
44 void AddIdx(Int_t idx)
45 {
46  Bool_t flag = false;
47  for (UInt_t i = 0; i < idxTree.size(); ++i) {
48  if (idx == idxTree[i])
49  flag = true;
50  }
51  if (!flag)
52  idxTree.push_back(idx);
53 }
54 
55 void SetMiniCubeId(UShort_t* xCube, UShort_t* xEnergies, Int_t idx)
56 {
57  Int_t i = idx/(nDiv*nDiv);
58  Int_t j = (idx - i*(nDiv*nDiv))/nDiv;
59  Int_t k = (idx - i*(nDiv*nDiv) - j*nDiv);
60 
61  xEnergies[0] = (xCube[0] + i*dim);
62  xEnergies[1] = (xCube[1] + j*dim);
63  xEnergies[2] = (xCube[2] + k*dim);
64 }
65 
66 
67 //__________________________________________________________
68 Int_t IsInside(UShort_t* energies, Int_t mult, Short_t* inGate, Int_t* gateInf, Int_t* gateSup, Int_t multg)
69 {
70  Int_t nGate = 0;
71 
72  for(Int_t i = 0; i < mult; ++i) {
73 
74  inGate[i] = 0;
75  Bool_t IsInGate = false;
76 
77  for(Int_t k = 0; k < multg; ++k) {
78  if( (energies[i] >= gateInf[k]) && (energies[i] <= gateSup[k]) ) {
79  IsInGate = true;
80  }
81  }
82 
83  if (IsInGate) {
84  inGate[i] = 1;
85  nGate++;
86  }
87  }
88 
89  return nGate;
90 }
91 
92 //__________________________________________________________
93 Int_t IsInside(Int_t* energies, Int_t mult, Short_t* inGate, UShort_t* gateInf, UShort_t* gateSup, Int_t multg)
94 {
95  Int_t nGate = 0;
96  Int_t usedGate[multg];
97 
98  for(Int_t k = 0; k < multg; ++k)
99  usedGate[k] = 0;
100 
101  for(Int_t i = 0; i < mult; ++i) {
102 
103  inGate[i] = 0;
104  Bool_t IsInGate = false;
105 
106  for(Int_t k = 0; k < multg; ++k) {
107  if( (energies[i] >= gateInf[k]) && (energies[i] <= gateSup[k]) ) {
108  if (usedGate[k] == 0) {
109  IsInGate = true;
110  usedGate[k] = 1;
111  break;
112  }
113  }
114  }
115 
116  if (IsInGate) {
117  inGate[i] = 1;
118  nGate++;
119  }
120  }
121 
122  return nGate;
123 }
124 
125 //__________________________________________________________
126 void ReadMiniTree3(Int_t gateInf1 = 195, Int_t gateSup1 = 205, Int_t gateInf2 = 292, Int_t gateSup2 = 300,
127 //void ReadMiniTree3(Int_t gateInf1 = 195, Int_t gateSup1 = 205, Int_t gateInf2 = 1322, Int_t gateSup2 = 1330,
128  TString fileName = "test8.root")
129 {
130 
131  Int_t hDim = 2000;
132  TStopwatch watch;
133  UShort_t e[nTree][3];
134  UShort_t er[3];
135  UShort_t limInf[3] = {0, 0, 0};
136  UShort_t limSup[3] = {1023, 1023, 1023};
137  UShort_t limInfr[3];
138  UShort_t limSupr[3];
139 
140  Int_t gateInf[2] = {gateInf1, gateInf2};
141  Int_t gateSup[2] = {gateSup1, gateSup2};
142 
143  Int_t multg = 2;
144  Short_t inGate[3];
145  Int_t nofGates = 0;
146 
147 
148  Int_t idx = 0;
149 
150  for (Int_t iTree = 0; iTree < nTree; ++iTree) {
151  SetMiniCubeId(limInf, limInfr, iTree);
152  SetMiniCubeId(limSup, limSupr, iTree);
153  printf("%d %d %d %d\n", iTree, limInfr[0], limInfr[1], limInfr[2]);
154  printf("%d %d %d %d\n\n", iTree, limSupr[0], limSupr[1], limSupr[2]);
155  nofGates = IsInside(gateInf, 2, inGate, limInfr, limSupr, 3);
156  if (inGate[0]*inGate[1] == 1) {
157  AddIdx(iTree);
158  }
159  nofGates = IsInside(gateSup, 2, inGate, limInfr, limSupr, 3);
160 
161  if (inGate[0]*inGate[1] == 1) {
162  AddIdx(iTree);
163  }
164 
165  }
166 
167 
168 // idxTree.push_back(0);
169 // idxTree.push_back(1);
170 // idxTree.push_back(2);
171 // idxTree.push_back(3);
172 // idxTree.push_back(4);
173 // idxTree.push_back(5);
174 // idxTree.push_back(6);
175 // idxTree.push_back(7);
176 
177  TTree* oak[nTree];
178  TBranch* b[nTree];
179  TFile* fileIn = new TFile(fileName.Data(), "READ");
180  for (Int_t i = 0; i < nTree; ++i) {
181  oak[i] = (TTree*)fileIn->Get(Form("oak%d", i));
182  b[i] = oak[i]->GetBranch("e");
183  b[i]->SetAddress(&e[i]);
184  }
185 
186  TH1F* h = new TH1F("h", "Projection", hDim, 0, hDim);
187 
188  watch.Start();
189  for (UInt_t iTree = 0; iTree < idxTree.size(); ++iTree) {
190  idx = idxTree[iTree];
191 
192  Int_t nEntries = b[idx]->GetEntries();
193  printf("%d %d\n", idx, nEntries);
194 
195  for (Int_t i = 0; i < nEntries; ++i) {
196  b[idx]->GetEntry(i);
197  SetMiniCubeId(e[idx], er, idx);
198 
199  nofGates = IsInside(er, 3, inGate, gateInf, gateSup, multg);
200 
201  for (Int_t k= 0; k < 3; ++k) {
202  if (nofGates == 2) {
203  if (inGate[k] == 0) {
204  h->Fill(er[k]);
205  }
206  }
207  if (nofGates == 3) {
208  h->Fill(er[k]);
209  }
210  }
211  }
212  }
213  watch.Stop();
214  h->Draw();
215  printf("Real time %6.3f\n", watch.RealTime());
216 }
217 
TBrowser * b
printf("******************************************************************** \n")
void SetMiniCubeId(UShort_t *xCube, UShort_t *xEnergies, Int_t idx)
Definition: ReadMiniTree3.C:55
header file for all type of CorrelatedSpaceTree2I
Int_t IsInside(UShort_t *energies, Int_t mult, Short_t *inGate, Int_t *gateInf, Int_t *gateSup, Int_t multg)
Definition: ReadMiniTree3.C:68
void AddIdx(Int_t idx)
Definition: ReadMiniTree3.C:44
Int_t nDiv
Definition: ReadMiniTree3.C:35
void ReadMiniTree3(Int_t gateInf1=195, Int_t gateSup1=205, Int_t gateInf2=292, Int_t gateSup2=300, TString fileName="test8.root")
TTree * oak
Definition: ReadDaqAlone.C:30
Int_t dim
Definition: ReadMiniTree3.C:34
Int_t nTree
Definition: ReadMiniTree3.C:36
std::vector< int > idxTree
Definition: ReadMiniTree3.C:42