137 def writeToFile(self,filename) :
138 from ROOT import TFile,TTree,TParameter
139 from ROOT import gROOT, addressof
140 gROOT.ProcessLine(
141 "struct MyMetaStruct {\
142 Char_t detector[40];\
143 Char_t release[40];\
144 Char_t geometry[40];\
145 Char_t geant[40];\
146 Char_t phys[40];\
147 Char_t comment[400];\
148 Int_t particle;\
149 };" )
150 from ROOT import MyMetaStruct
151 gROOT.ProcessLine(
152 "struct MyStruct {\
153 Float_t x;\
154 Float_t y;\
155 Float_t z;\
156 Float_t e;\
157 Float_t time;\
158 };" )
159 from ROOT import MyStruct
160
161 tfile = TFile(filename,"RECREATE")
162
163 ver = TParameter(int)("version",10)
164 ver.Write("version")
165
166 meta = TTree()
167 libr = TTree()
168
169 mmstruct = MyMetaStruct()
170
171 mmstruct.detector = "%s" % (str(self.detector))
172 mmstruct.particle = int(self.particle)
173 mmstruct.release = "%s" % (str(self.release))
174 mmstruct.geometry = "%s" % (str(self.geometry))
175 mmstruct.geant = "%s" % (str(self.geant))
176 mmstruct.phys = "%s" % (str(self.phys))
177 mmstruct.comment = "%s" % (str(self.comment))
178
179 meta.Branch("detector",addressof(mmstruct,"detector"),"detector/C")
180 meta.Branch("particle",addressof(mmstruct,"particle"),"particle/I")
181 meta.Branch("release",addressof(mmstruct,"release"),"release/C")
182 meta.Branch("geometry",addressof(mmstruct,"geometry"),"geometry/C")
183 meta.Branch("geantVersion",addressof(mmstruct,"geant"),"geantVersion/C")
184 meta.Branch("physicsList",addressof(mmstruct,"phys"),"physicsList/C")
185 meta.Branch("comment",addressof(mmstruct,"comment"),"physicsList/C")
186
187 meta.Fill()
188
189 mstruct = MyStruct()
190
191 libr.Branch("x",addressof(mstruct,"x"),"x/F")
192 libr.Branch("y",addressof(mstruct,"y"),"y/F")
193 libr.Branch("z",addressof(mstruct,"z"),"z/F")
194 libr.Branch("e",addressof(mstruct,"e"),"e/F")
195 libr.Branch("time",addressof(mstruct,"time"),"time/F")
196
197 for storedShower in self.library :
198 mstruct.x = storedShower.vertex.x
199 mstruct.y = storedShower.vertex.y
200 mstruct.z = storedShower.vertex.z
201 mstruct.time = storedShower.zsize
202 mstruct.e = len(storedShower.shower)
203 libr.Fill()
204 mstruct.x = storedShower.momentum.x
205 mstruct.y = storedShower.momentum.y
206 mstruct.z = storedShower.momentum.z
207 mstruct.e = storedShower.momentum.e
208 mstruct.time = storedShower.rsize
209 libr.Fill()
210 for hit in storedShower.shower:
211 mstruct.e = hit.e
212 mstruct.x = hit.x
213 mstruct.y = hit.y
214 mstruct.z = hit.z
215 mstruct.time = hit.time
216 libr.Fill()
217 meta.Write("meta")
218 libr.Write("library")
219 tfile.Close()