GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WriteInMiniTree3.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 "TMath.h"
24 #include "TRandom.h"
25 #include "TTree.h"
26 #include "TH2F.h"
27 #include "TObject.h"
28 
29 #endif
30 
31 Int_t dim = 256;
32 Int_t nDiv = 8;
33 Int_t nTree = 512;
34 
35 //Int_t dim = 1024;
36 //Int_t nDiv = 2;
37 //Int_t nTree = 8;
38 
39 Int_t GetMiniCubeId(UShort_t* xEnergies, UShort_t* xCube)
40 {
41 // Int_t index[3];
42 // TMath::Sort(3, xEnergies, index, false);
43 
44 // Int_t i = xEnergies[index[0]]/dim;
45 // Int_t j = xEnergies[index[1]]/dim;
46 // Int_t k = xEnergies[index[2]]/dim;
47 
48  Int_t i = xEnergies[0]/dim;
49  Int_t j = xEnergies[1]/dim;
50  Int_t k = xEnergies[2]/dim;
51 
52  Int_t idx = i*nDiv*nDiv + j*nDiv + k;
53 
54 // xCube[0] = (xEnergies[index[0]] % dim);
55 // xCube[1] = (xEnergies[index[1]] % dim);
56 // xCube[2] = (xEnergies[index[2]] % dim);
57 
58  xCube[0] = (xEnergies[0] % dim);
59  xCube[1] = (xEnergies[1] % dim);
60  xCube[2] = (xEnergies[2] % dim);
61 
62  return idx;
63 }
64 
66 {
67 
68  UShort_t x0[3];
69 
70  UShort_t e[nTree][3];
71  UShort_t x[3];
72  Float_t Xn[3];
73 
74  TFile* fileIn = new TFile("CubeTreeR_22_0_67.root ", "READ");
75  TTree* tree = (TTree*)fileIn->Get("treecube");
76 
77  TBranch* b = tree->GetBranch("e");
78  if (b == 0x0) {
79  printf("Branch not find in tree\n");
80  return;
81  }
82 
83  b->SetAddress(&Xn);
84 
85  TFile* fileOut = new TFile("test8.root", "RECREATE");
86  fileOut->cd();
87 
88  TTree* oak[nTree];
89  for (Int_t i = 0; i < nTree; ++i) {
90  oak[i] = new TTree(Form("oak%d", i), "3D tree");
91  oak[i]->Branch("e", &e[i], "e[3]/s");
92  }
93 
94  for (Int_t i = 0; i < 1000000; ++i) {
95  tree->GetEntry(i);
96  printf("%d\r", i);
97 
98  x[0] = Short_t(Xn[0]);
99  x[1] = Short_t(Xn[1]);
100  x[2] = Short_t(Xn[2]);
101  Int_t idx = GetMiniCubeId(x, x0);
102  e[idx][0] = x0[0];
103  e[idx][1] = x0[1];
104  e[idx][2] = x0[2];
105  oak[idx]->Fill();
106  }
107 
108  for (Int_t i = 0; i < nTree; ++i)
109  oak[i]->Write();
110 
111  printf("\n");
112  fileOut->Close();
113 }
114 
TBrowser * b
printf("******************************************************************** \n")
Int_t nDiv
Int_t GetMiniCubeId(UShort_t *xEnergies, UShort_t *xCube)
Int_t dim
TTree * oak
Definition: ReadDaqAlone.C:30
Int_t nTree
void WriteInMiniTree3()