BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
TreeDedxCalibDataCnv.cxx
Go to the documentation of this file.
1#include "GaudiKernel/MsgStream.h"
6#include "TFile.h"
7#include "TTree.h"
8#include "TDirectory.h"
9#include "TObject.h"
10#include "TBuffer.h"
11#include "TBufferFile.h"
12
13#include "GaudiKernel/CnvFactory.h"
14#include "GaudiKernel/IOpaqueAddress.h"
15#include "GaudiKernel/DataObject.h"
16#include "GaudiKernel/IAddressCreator.h"
17#include "GaudiKernel/IDataProviderSvc.h"
18#include "GaudiKernel/IConversionSvc.h"
19#include "GaudiKernel/GenericAddress.h"
20
21#include "CalibDataSvc/ICalibTreeSvc.h" //maybe
23
24// Temporary. Hope to find a better way to do this
26using namespace CalibData;
27//static CnvFactory<TreeDedxCalibDataCnv> DedxCal_factory;
28//const ICnvFactory& TreeDedxCalibDataCnvFactory = DedxCal_factory;
29
30
31
36
37
38const CLID& TreeDedxCalibDataCnv::objType() const {
39 return CLID_Calib_DedxCal;
40}
41
45
46StatusCode TreeDedxCalibDataCnv::i_createObj(IOpaqueAddress* addr,
47 DataObject*& refpObject) {
48
49 MsgStream log(msgSvc(), "TreeDedxCalibDataCnv");
50 log<<MSG::DEBUG<<"SetProperty"<<endreq;
51
53 TreeAddress* add = dynamic_cast<TreeAddress*>(addr);
54 DatabaseRecord *records=add->pp();
55
56 /*TBuffer *buf1 = new TBuffer(TBuffer::kRead);
57 TBuffer *buf2 = new TBuffer(TBuffer::kRead);
58 TBuffer *buf3 = new TBuffer(TBuffer::kRead);
59 TBuffer *buf4 = new TBuffer(TBuffer::kRead);
60 TBuffer *buf5 = new TBuffer(TBuffer::kRead);
61 TBuffer *buf6 = new TBuffer(TBuffer::kRead);
62 TBuffer *buf7 = new TBuffer(TBuffer::kRead);
63 TBuffer *buf8 = new TBuffer(TBuffer::kRead);
64 TBuffer *buf9 = new TBuffer(TBuffer::kRead);*/
65
66 TBufferFile *buf1 = new TBufferFile(TBuffer::kRead);
67 TBufferFile *buf2 = new TBufferFile(TBuffer::kRead);
68 TBufferFile *buf3 = new TBufferFile(TBuffer::kRead);
69 TBufferFile *buf4 = new TBufferFile(TBuffer::kRead);
70 TBufferFile *buf5 = new TBufferFile(TBuffer::kRead);
71 TBufferFile *buf6 = new TBufferFile(TBuffer::kRead);
72 TBufferFile *buf7 = new TBufferFile(TBuffer::kRead);
73 TBufferFile *buf8 = new TBufferFile(TBuffer::kRead);
74 TBufferFile *buf9 = new TBufferFile(TBuffer::kRead);
75
76 buf1->SetBuffer((*records)["DriftDist"],512000,kFALSE);
77 buf2->SetBuffer((*records)["EntranceAng"],512000,kFALSE);
78 buf3->SetBuffer((*records)["MeanGain"],512000,kFALSE);
79 buf4->SetBuffer((*records)["GasGain"],512000,kFALSE);
80 buf5->SetBuffer((*records)["LayerGain"],512000,kFALSE);
81 buf6->SetBuffer((*records)["Resolution"],512000,kFALSE);
82 buf7->SetBuffer((*records)["WireGain"],512000,kFALSE);
83 buf8->SetBuffer((*records)["ZDep"],512000,kFALSE);
84 buf9->SetBuffer((*records)["RunGain"],1024000,kFALSE);
85
86
87
88 std::cout<<" SftVer is "<<(*records)["SftVer"];
89 std::cout<<" CalVerSft is "<<(*records)["CalParVer"];
90 std::cout<<" File name is "<<(*records)["FileName"]<<std::endl;
91
92
93
94 TTree* ddgtree = new TTree();
95 ddgtree->Streamer(*buf1);
96
97 TTree* entratree = new TTree();
98 entratree->Streamer(*buf2);
99
100 TTree* gaintree= new TTree();
101 gaintree->Streamer(*buf3);
102
103 TTree* ggstree = new TTree();
104 ggstree->Streamer(*buf4);
105
106 TTree* layergtree = new TTree();
107 layergtree->Streamer(*buf5);
108
109 TTree* resoltree = new TTree();
110 resoltree->Streamer(*buf6);
111
112 TTree* wiregtree = new TTree();
113 wiregtree->Streamer(*buf7);
114
115 TTree* zdeptree = new TTree();
116 zdeptree->Streamer(*buf8);
117
118 TTree *rungtree = new TTree();
119 rungtree->Streamer(*buf9);
120
121 double rungain;
122 double runmean;
123 int runno, evtfrom, evtto;
124 double runresol;
125
126 rungtree -> SetBranchAddress("rungain", &rungain);
127 rungtree -> SetBranchAddress("runmean", &runmean);
128 rungtree -> SetBranchAddress("runno", &runno);
129 rungtree -> SetBranchAddress("runresol", &runresol);
130 if(rungtree->GetBranchStatus("evtfrom")){
131 rungtree -> SetBranchAddress("evtfrom", &evtfrom);
132 rungtree -> SetBranchAddress("evtto", &evtto);
133 }
134 else{
135 evtfrom = 0;
136 evtto = 1000000000;
137 }
138 int N = rungtree -> GetEntries();
139 tmpObject -> setrunNO(N);
140 for(int i=0; i<N; i++){
141 rungtree -> GetEntry(i);
142 tmpObject -> setrung(rungain,0);
143 tmpObject -> setrung(runmean,1);
144 tmpObject -> setrung(runno,2);
145 tmpObject -> setrung(runresol,3);
146 tmpObject -> setrung(evtfrom,4);
147 tmpObject -> setrung(evtto,5);
148 }
149
150
151 double ddg0[43];
152 double ddg1[43];
153 double ddg2[43];
154 double ddg3[43];
155 double id_doca[1600];
156 double iner_chi[1600];
157 double iner_gain[1600];
158 double iner_hits[1600];
159 double ip_eangle[1600];
160 double out_chi[1600];
161 double out_gain[1600];
162 double out_hits[1600];
163
164 ddgtree -> SetBranchAddress("ddg0", ddg0);
165 ddgtree -> SetBranchAddress("ddg1", ddg1);
166 ddgtree -> SetBranchAddress("ddg2", ddg2);
167 ddgtree -> SetBranchAddress("ddg3", ddg3);
168 TBranch *bbb = ddgtree->FindBranch("Id_doca");
169 if(bbb){
170 ddgtree -> SetBranchAddress("Id_doca", id_doca);
171 ddgtree -> SetBranchAddress("Iner_chi", iner_chi);
172 ddgtree -> SetBranchAddress("Iner_gain", iner_gain);
173 ddgtree -> SetBranchAddress("Iner_hits", iner_hits);
174 ddgtree -> SetBranchAddress("Ip_eangle", ip_eangle);
175 ddgtree -> SetBranchAddress("Out_chi", out_chi);
176 ddgtree -> SetBranchAddress("Out_gain", out_gain);
177 ddgtree -> SetBranchAddress("Out_hits", out_hits);
178 }
179
180 ddgtree -> GetEntry(0);
181 for(int i=0; i<43; i++){
182
183 tmpObject -> setddg(ddg0[i],0,i);
184 tmpObject -> setddg(ddg1[i],1,i);
185 tmpObject -> setddg(ddg2[i],2,i);
186 tmpObject -> setddg(ddg3[i],3,i);
187 }
188
189 for(int i=0; i<1600; i++){
190 if(!bbb){
191 id_doca[i]=0;
192 iner_chi[i]=0;
193 iner_gain[i]=0;
194 iner_hits[i]=0;
195 ip_eangle[i]=0;
196 out_chi[i]=0;
197 out_gain[i]=0;
198 out_hits[i]=0;
199 }
200 tmpObject -> set_id_doca(id_doca[i],i);
201 tmpObject -> set_iner_chi(iner_chi[i],i);
202 tmpObject -> set_iner_gain(iner_gain[i],i);
203 tmpObject -> set_iner_hits(iner_hits[i],i);
204 tmpObject -> set_ip_eangle(ip_eangle[i],i);
205 tmpObject -> set_out_chi(out_chi[i],i);
206 tmpObject -> set_out_gain(out_gain[i],i);
207 tmpObject -> set_out_hits(out_hits[i],i);
208 }
209
210
211 double entra0[43];
212 double entra1[43];
213 double entra2[43];
214 double entra3[43];
215 double engle[100];
216 int engle_no;
217 entratree -> SetBranchAddress("entra0", entra0);
218 entratree -> SetBranchAddress("entra1", entra1);
219 entratree -> SetBranchAddress("entra2", entra2);
220 entratree -> SetBranchAddress("entra3", entra3);
221 entratree -> SetBranchAddress("1denangle", engle);
222 entratree -> SetBranchAddress("1denangle_entry", &engle_no);
223 entratree -> GetEntry(0);
224 for(int i=0; i<43; i++){
225 tmpObject -> setenta(entra0[i],0,i);
226 tmpObject -> setenta(entra1[i],1,i);
227 tmpObject -> setenta(entra2[i],2,i);
228 tmpObject -> setenta(entra3[i],3,i);
229 }
230
231 tmpObject -> set_enanglesize(engle_no);
232 for(int i=0; i<engle_no; i++){
233 tmpObject -> set_enangle(engle[i],i);
234 }
235
236
237
238
239// read ggscalib ------------------------------------------------------------
240 double ggs0[43];
241 double ggs1[43];
242 double ggs2[43];
243 double ggs3[43];
244 double gcostheta[80];
245 int hadron_entry;
246 double hadron[20];
247 ggstree -> SetBranchAddress("ggs0", ggs0);
248 ggstree -> SetBranchAddress("ggs1", ggs1);
249 ggstree -> SetBranchAddress("ggs2", ggs2);
250 ggstree -> SetBranchAddress("ggs3", ggs3);
251 ggstree -> SetBranchAddress("hadron", hadron);
252 ggstree -> SetBranchAddress("hadronNo", &hadron_entry);
253 if(bbb){
254 ggstree -> SetBranchAddress("costheta", gcostheta);}
255 ggstree -> GetEntry(0);
256 for(int i=0; i<43;i++){
257 tmpObject -> setggs(ggs0[i],0,i);
258 tmpObject -> setggs(ggs1[i],1,i);
259 tmpObject -> setggs(ggs2[i],2,i);
260 tmpObject -> setggs(ggs3[i],3,i);
261 }
262 for(int i=0; i<80;i++){
263 if(!bbb) gcostheta[i]=0;
264 tmpObject ->set_costheta(gcostheta[i],i);
265 }
266 if(hadron_entry>20){
267 log<<MSG::FATAL<<"hadron entry is larger than 20, larger than designed"<<endreq;
268 return StatusCode::FAILURE;
269 }
270 tmpObject->set_hadronNo(hadron_entry);
271 for(int i=0;i<hadron_entry;i++){
272 tmpObject->set_hadron(hadron[i],i);
273 }
274
275
276// read zdepcalib ------------------------------------------------------------
277 double zdep0[43];
278 double zdep1[43];
279 double zdep2[43];
280 double zdep3[43];
281 zdeptree -> SetBranchAddress("zdep0", zdep0);
282 zdeptree -> SetBranchAddress("zdep1", zdep1);
283 zdeptree -> SetBranchAddress("zdep2", zdep2);
284 zdeptree -> SetBranchAddress("zdep3", zdep3);
285 zdeptree -> GetEntry(0);
286
287 for(int i=0; i<43;i++){
288 tmpObject -> setzdep(zdep0[i],0,i);
289 tmpObject -> setzdep(zdep1[i],1,i);
290 tmpObject -> setzdep(zdep2[i],2,i);
291 tmpObject -> setzdep(zdep3[i],3,i);
292 }
293// read gain ------------------------------------------------------------
294 double gain;
295 double gt0[35],gdedx[35];
296 gaintree -> SetBranchAddress("gain", &gain);
297 if(bbb){
298 gaintree -> SetBranchAddress("t0", gt0);
299 gaintree -> SetBranchAddress("dedx", gdedx);}
300 gaintree -> GetEntry(0);
301 tmpObject -> setgain(gain);
302 for(int i=0; i<35;i++){
303 if(!bbb){
304 gt0[i]=0;
305 gdedx[i]=0;
306 }
307 tmpObject->set_t0(gt0[i],i);
308 tmpObject->set_dedx(gdedx[i],i);
309 }
310
311// read resol----------------------------------------------------------------
312 double resol;
313 resoltree -> SetBranchAddress("resol", &resol);
314 resoltree -> GetEntry(0);
315 tmpObject -> setresol(resol);
316
317// read wireg----------------------------------------------------------------
318 double wireg[6796];
319 wiregtree -> SetBranchAddress("wireg",wireg);
320 wiregtree -> GetEntry(0);
321 for(int i=0;i<6796;i++){
322 if(wireg[i]>5||wireg[i]<0.2) wireg[i]=0;
323 tmpObject -> setwireg(wireg[i],i);
324 }
325
326// read layerg----------------------------------------------------------------
327 double layerg[43];
328 layergtree -> SetBranchAddress("layerg",layerg);
329 layergtree -> GetEntry(0);
330
331 for(int i=0;i<43;i++){
332 tmpObject -> setlayerg(layerg[i],i);
333 }
334
335
336
337 // Read in the object
338
339
340 refpObject=tmpObject;
341
342 delete ddgtree;
343 delete entratree;
344 delete gaintree;
345 delete ggstree;
346 delete layergtree;
347 delete resoltree;
348 delete wiregtree;
349 delete zdeptree;
350 delete rungtree;
351
352 return StatusCode::SUCCESS;
353
354
355}
356
const CLID CLID_Calib_DedxCal
Definition CalibModel.h:45
data GetEntry(0)
data SetBranchAddress("time",&time)
IMessageSvc * msgSvc()
void set_costheta(const double aa, int i)
void set_hadron(const double aa, int i)
void set_t0(const double aa, int i)
void set_dedx(const double aa, int i)
virtual DatabaseRecord * pp()
static const CLID & classID()
virtual StatusCode i_createObj(IOpaqueAddress *address, DataObject *&refpObject)
TreeDedxCalibDataCnv(ISvcLocator *svc)
const CLID & objType() const