BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
RootDedxCalibDataCnv.cxx
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/CalibSvc/CalibROOTCnv/src/cnv/RootDedxCalibDataCnv.cxx,v 1.13 2019/09/23 05:15:18 zhuk Exp $
2#include "GaudiKernel/MsgStream.h"
6
7#include "TFile.h"
8#include "TTree.h"
9#include "TDirectory.h"
10#include "TObject.h"
11#include <iostream>
12#include <fstream>
13#include <string>
14
15#include "GaudiKernel/CnvFactory.h"
16#include "GaudiKernel/IOpaqueAddress.h"
17#include "GaudiKernel/DataObject.h"
18#include "GaudiKernel/IAddressCreator.h"
19#include "GaudiKernel/IDataProviderSvc.h"
20#include "GaudiKernel/IConversionSvc.h"
21#include "GaudiKernel/GenericAddress.h"
22
26
27// Temporary. Hope to find a better way to do this
29using namespace CalibData;
30//static CnvFactory<RootDedxCalibDataCnv> DedxCal_factory;
31//const ICnvFactory& RootDedxCalibDataCnvFactory = DedxCal_factory;
32
33
34
37}
38
39
40const CLID& RootDedxCalibDataCnv::objType() const {
41 return CLID_Calib_DedxCal;
42}
43
45 return CLID_Calib_DedxCal;
46}
47
48StatusCode RootDedxCalibDataCnv::i_createObj(const std::string& fname,
49 DataObject*& refpObject) {
50
51 MsgStream log(msgSvc(), "RootDedxCalibDataCnv");
52 log<<MSG::DEBUG<<"SetProperty"<<endreq;
53 StatusCode sc = openRead(fname);
54 if(!sc)
55 { log<<MSG::ERROR<<"unable to open files"<<endreq;
56 }
57
59 // Read in our object
60 int i;
61 // read rungcalib ------------------------------------------------------------
62 double rungain;
63 double runmean;
64 int runno, evtfrom, evtto;
65 double runresol;
66 TTree *rungtree = (TTree*)m_inFile -> Get("runcalib");
67 rungtree -> SetBranchAddress("rungain", &rungain);
68 rungtree -> SetBranchAddress("runmean", &runmean);
69 rungtree -> SetBranchAddress("runno", &runno);
70 rungtree -> SetBranchAddress("runresol", &runresol);
71 if(rungtree->GetBranchStatus("evtfrom")){ rungtree -> SetBranchAddress("evtfrom", &evtfrom); rungtree -> SetBranchAddress("evtto", &evtto); } else{ evtfrom = 0; evtto = 1000000000; }
72 int N = rungtree -> GetEntries();
73 tmpObject -> setrunNO(N);
74 //std::cout<<"N = "<<N<<std::endl;
75 for(i=0; i<N; i++){
76 rungtree -> GetEntry(i);
77 //std::cout<<rungain<<" "<<runmean<<" "<<runno<<" "<<runresol<<std::endl;
78 tmpObject -> setrung(rungain,0);
79 tmpObject -> setrung(runmean,1);
80 tmpObject -> setrung(runno,2);
81 tmpObject -> setrung(runresol,3);
82 tmpObject -> setrung(evtfrom,4);
83 tmpObject -> setrung(evtto,5);
84 }
85
86
87
88 // read ddgcalib ------------------------------------------------------------
89 double ddg0[43];
90 double ddg1[43];
91 double ddg2[43];
92 double ddg3[43];
93 double id_doca[1600];
94 double iner_chi[1600];
95 double iner_gain[1600];
96 double iner_hits[1600];
97 double ip_eangle[1600];
98 double out_chi[1600];
99 double out_gain[1600];
100 double out_hits[1600];
101
102 TTree *ddgtree = (TTree*)m_inFile -> Get("ddgcalib");
103 ddgtree -> SetBranchAddress("ddg0", ddg0);
104 ddgtree -> SetBranchAddress("ddg1", ddg1);
105 ddgtree -> SetBranchAddress("ddg2", ddg2);
106 ddgtree -> SetBranchAddress("ddg3", ddg3);
107 TBranch *bbb = ddgtree->FindBranch("Id_doca");
108 if(bbb){
109 ddgtree -> SetBranchAddress("Id_doca", id_doca);
110 ddgtree -> SetBranchAddress("Iner_chi", iner_chi);
111 ddgtree -> SetBranchAddress("Iner_gain", iner_gain);
112 ddgtree -> SetBranchAddress("Iner_hits", iner_hits);
113 ddgtree -> SetBranchAddress("Ip_eangle", ip_eangle);
114 ddgtree -> SetBranchAddress("Out_chi", out_chi);
115 ddgtree -> SetBranchAddress("Out_gain", out_gain);
116 ddgtree -> SetBranchAddress("Out_hits", out_hits);
117 }
118 ddgtree -> GetEntry(0);
119 for(i=0; i<43; i++){
120 tmpObject -> setddg(ddg0[i],0,i);
121 tmpObject -> setddg(ddg1[i],1,i);
122 tmpObject -> setddg(ddg2[i],2,i);
123 tmpObject -> setddg(ddg3[i],3,i);
124 }
125
126 for(i=0; i<1600; i++){
127 if(!bbb){
128 id_doca[i]=0;
129 iner_chi[i]=0;
130 iner_gain[i]=0;
131 iner_hits[i]=0;
132 ip_eangle[i]=0;
133 out_chi[i]=0;
134 out_gain[i]=0;
135 out_hits[i]=0;
136 }
137 tmpObject -> set_id_doca(id_doca[i],i);
138 tmpObject -> set_iner_chi(iner_chi[i],i);
139 tmpObject -> set_iner_gain(iner_gain[i],i);
140 tmpObject -> set_iner_hits(iner_hits[i],i);
141 tmpObject -> set_ip_eangle(ip_eangle[i],i);
142 tmpObject -> set_out_chi(out_chi[i],i);
143 tmpObject -> set_out_gain(out_gain[i],i);
144 tmpObject -> set_out_hits(out_hits[i],i);
145 }
146
147// read entratree---------------------------------------------
148 double entra0[43];
149 double entra1[43];
150 double entra2[43];
151 double entra3[43];
152 double engle[100];
153 int engle_no;
154 TTree *entratree = (TTree*)m_inFile -> Get("entracalib");
155 entratree -> SetBranchAddress("entra0", entra0);
156 entratree -> SetBranchAddress("entra1", entra1);
157 entratree -> SetBranchAddress("entra2", entra2);
158 entratree -> SetBranchAddress("entra3", entra3);
159 entratree -> SetBranchAddress("1denangle", engle);
160 entratree -> SetBranchAddress("1denangle_entry", &engle_no);
161 entratree -> GetEntry(0);
162 for(i=0; i<43; i++){
163 tmpObject -> setenta(entra0[i],0,i);
164 tmpObject -> setenta(entra1[i],1,i);
165 tmpObject -> setenta(entra2[i],2,i);
166 tmpObject -> setenta(entra3[i],3,i);
167 }
168 tmpObject -> set_enanglesize(engle_no);
169 for(i=0; i<engle_no; i++){
170 tmpObject -> set_enangle(engle[i],i);
171 }
172
173
174
175// read ggscalib ------------------------------------------------------------
176 double ggs0[43];
177 double ggs1[43];
178 double ggs2[43];
179 double ggs3[43];
180 double gcostheta[80];
181 int hadron_entry;
182 double hadron[20];
183 TTree *ggstree = (TTree*)m_inFile -> Get("ggscalib");
184 ggstree -> SetBranchAddress("ggs0", ggs0);
185 ggstree -> SetBranchAddress("ggs1", ggs1);
186 ggstree -> SetBranchAddress("ggs2", ggs2);
187 ggstree -> SetBranchAddress("ggs3", ggs3);
188 ggstree -> SetBranchAddress("hadron", hadron);
189 ggstree -> SetBranchAddress("hadronNo", &hadron_entry);
190 if(bbb){
191 ggstree -> SetBranchAddress("costheta", gcostheta);
192 }
193 ggstree -> GetEntry(0);
194 for(i=0; i<43;i++){
195 tmpObject -> setggs(ggs0[i],0,i);
196 tmpObject -> setggs(ggs1[i],1,i);
197 tmpObject -> setggs(ggs2[i],2,i);
198 tmpObject -> setggs(ggs3[i],3,i);
199 }
200
201 for(i=0; i<80;i++){
202 if(!bbb) gcostheta[i]=0;
203 tmpObject ->set_costheta(gcostheta[i],i);
204 }
205
206 if(hadron_entry>20){
207 log<<MSG::FATAL<<"hadron entry is larger than 20, larger than designed"<<endreq;
208 return StatusCode::FAILURE;
209 }
210
211 tmpObject->set_hadronNo(hadron_entry);
212
213 for(i=0;i<hadron_entry;i++){
214 tmpObject->set_hadron(hadron[i],i);
215 }
216
217
218// read zdepcalib ------------------------------------------------------------
219 double zdep0[43];
220 double zdep1[43];
221 double zdep2[43];
222 double zdep3[43];
223 TTree *zdeptree = (TTree*)m_inFile -> Get("zdepcalib");
224 zdeptree -> SetBranchAddress("zdep0", zdep0);
225 zdeptree -> SetBranchAddress("zdep1", zdep1);
226 zdeptree -> SetBranchAddress("zdep2", zdep2);
227 zdeptree -> SetBranchAddress("zdep3", zdep3);
228 zdeptree -> GetEntry(0);
229
230 for(i=0; i<43;i++){
231 tmpObject -> setzdep(zdep0[i],0,i);
232 tmpObject -> setzdep(zdep1[i],1,i);
233 tmpObject -> setzdep(zdep2[i],2,i);
234 tmpObject -> setzdep(zdep3[i],3,i);
235 }
236
237// read gain ------------------------------------------------------------
238 double gain;
239 double gt0[35],gdedx[35];
240 TTree *gaintree = (TTree*)m_inFile -> Get("gaincalib");
241 gaintree -> SetBranchAddress("gain", &gain);
242 if(bbb){
243 gaintree -> SetBranchAddress("t0", gt0);
244 gaintree -> SetBranchAddress("dedx", gdedx);
245 }
246 gaintree -> GetEntry(0);
247 tmpObject -> setgain(gain);
248 for(i=0; i<35;i++){
249 if(!bbb){
250 gt0[i]=0;
251 gdedx[i]=0;
252 }
253 tmpObject->set_t0(gt0[i],i);
254 tmpObject->set_dedx(gdedx[i],i);
255 }
256
257// read resol----------------------------------------------------------------
258 double resol;
259 TTree *resoltree = (TTree*)m_inFile -> Get("resolcalib");
260 resoltree -> SetBranchAddress("resol", &resol);
261 resoltree -> GetEntry(0);
262 tmpObject -> setresol(resol);
263
264// read wireg----------------------------------------------------------------
265 double wireg[6796];
266 TTree *wiregtree = (TTree*)m_inFile -> Get("wiregcalib");
267 wiregtree -> SetBranchAddress("wireg",wireg);
268 wiregtree -> GetEntry(0);
269 for(i=0;i<6796;i++){
270 tmpObject -> setwireg(wireg[i],i);
271 }
272
273// read layerg----------------------------------------------------------------
274 double layerg[43];
275 TTree *layergtree = (TTree*)m_inFile -> Get("layergcalib");
276 layergtree -> SetBranchAddress("layerg",layerg);
277 layergtree -> GetEntry(0);
278
279 for(i=0;i<43;i++){
280 tmpObject -> setlayerg(layerg[i],i);
281 }
282
283 refpObject=tmpObject;
284 // delete pObj;
285 // std::cout<<"pObj.m_t0[Cell]="<<*(pObj->gett0()+Cell-1);
286 // dynamic_cast<CalibData::Mdct0& >(refpObject);
287 //refpObject = pObj;
288 // std::cout<<"refObject.m_t0[Cell]="<<*(refpObject->gett0()+Cell-1);
289 // refpObject = new Mdct0(&t0_tmp[0]);
290 return StatusCode::SUCCESS;
291}
292
293StatusCode RootDedxCalibDataCnv::createRoot(const std::string& fname,
294 CalibData::CalibBase1* pTDSObj) {
295
296 MsgStream log(msgSvc(), "RootDedxCalibDataCnv");
297
298 // Open the file, create the branch
299 StatusCode sc = openWrite(fname);
300 if(!sc)
301 { log<<MSG::ERROR<<"unable to open files"<<endreq;
302 }
303 // write the Data in the TCDS to RootFile
304 int i;
305 CalibData::DedxCalibData* tmpObject = dynamic_cast<CalibData::DedxCalibData*>(pTDSObj);
306 // write rungcalib ------------------------------------------------------------
307 double rungain;
308 double runmean;
309 double runno;
310 double runresol;
311 TTree *rungcalibtree = new TTree("rungcalib", "rungCalib");
312 rungcalibtree -> Branch("rungain", &rungain, "S/D");
313 rungcalibtree -> Branch("runmean", &runmean, "S/D");
314 rungcalibtree -> Branch("runno", &runno, "S/D");
315 rungcalibtree -> Branch("runresol", &runresol, "S/D");
316 int N = tmpObject->getrunNO();
317 for(i=0; i<N; i++){
318 rungain = tmpObject->getrung(0,i);
319 runmean = tmpObject->getrung(1,i);
320 runno = tmpObject->getrung(2,i);
321 runresol = tmpObject->getrung(3,i);
322 rungcalibtree -> Fill();
323 }
324
325
326
327 // write ddgcalib----------------------------------------------------------------
328 double ddg0;
329 double ddg1;
330 double ddg2;
331 double ddg3;
332 TTree *ddgcalibtree = new TTree("ddgcalib", "ddgCalib");
333 ddgcalibtree -> Branch("ddg0", &ddg0, "S/D");
334 ddgcalibtree -> Branch("ddg1", &ddg1, "S/D");
335 ddgcalibtree -> Branch("ddg2", &ddg2, "S/D");
336 ddgcalibtree -> Branch("ddg3", &ddg3, "S/D");
337 for(i=0; i<43; i++){
338 ddg0 = tmpObject->getddg(0,i);
339 ddg1 = tmpObject->getddg(1,i);
340 ddg2 = tmpObject->getddg(2,i);
341 ddg3 = tmpObject->getddg(3,i);
342 ddgcalibtree -> Fill();
343 }
344
345 // write ggscalib----------------------------------------------------------------
346 double ggs0;
347 double ggs1;
348 double ggs2;
349 double ggs3;
350 TTree *ggscalibtree = new TTree("ggscalib", "ggsCalib");
351 ggscalibtree -> Branch("ggs0", &ggs0, "S/D");
352 ggscalibtree -> Branch("ggs1", &ggs1, "S/D");
353 ggscalibtree -> Branch("ggs2", &ggs2, "S/D");
354 ggscalibtree -> Branch("ggs3", &ggs3, "S/D");
355 for(i=0; i<43; i++){
356 ggs0 = tmpObject->getggs(0,i);
357 ggs1 = tmpObject->getggs(1,i);
358 ggs2 = tmpObject->getggs(2,i);
359 ggs3 = tmpObject->getggs(3,i);
360 ggscalibtree -> Fill();
361 }
362
363// write zdepcalib----------------------------------------------------------------
364 double zdep0;
365 double zdep1;
366 double zdep2;
367 double zdep3;
368 TTree *zdepcalibtree = new TTree("zdepcalib", "zdepCalib");
369 zdepcalibtree -> Branch("zdep0", &zdep0, "S/D");
370 zdepcalibtree -> Branch("zdep1", &zdep1, "S/D");
371 zdepcalibtree -> Branch("zdep2", &zdep2, "S/D");
372 zdepcalibtree -> Branch("zdep3", &zdep3, "S/D");
373 for(i=0; i<43; i++){
374 zdep0 = tmpObject->getzdep(0,i);
375 zdep1 = tmpObject->getzdep(1,i);
376 zdep2 = tmpObject->getzdep(2,i);
377 zdep3 = tmpObject->getzdep(3,i);
378 zdepcalibtree -> Fill();
379 }
380
381// write entacalib----------------------------------------------------------------
382 double enta0;
383 double enta1;
384 double enta2;
385 double enta3;
386 TTree *entacalibtree = new TTree("entacalib", "entaCalib");
387 entacalibtree -> Branch("enta0", &enta0, "S/D");
388 entacalibtree -> Branch("enta1", &enta1, "S/D");
389 entacalibtree -> Branch("enta2", &enta2, "S/D");
390 entacalibtree -> Branch("enta3", &enta3, "S/D");
391 for(i=0; i<43; i++){
392 enta0 = tmpObject->getenta(0,i);
393 enta1 = tmpObject->getenta(1,i);
394 enta2 = tmpObject->getenta(2,i);
395 enta3 = tmpObject->getenta(3,i);
396 entacalibtree -> Fill();
397 }
398
399
400
401// write gain---------------------------------------------------------------------
402 double gain;
403 TTree *gaintree = new TTree("gaincalib", "gainCalib");
404 gaintree -> Branch("gain", &gain, "S/D");
405 gain = tmpObject->getgain();
406 gaintree -> Fill();
407
408// write resol---------------------------------------------------------------------
409 double resol;
410 TTree *resoltree = new TTree("resolcalib", "resolCalib");
411 resoltree -> Branch("resol", &resol, "S/D");
412 resol = tmpObject->getresol();
413 resoltree -> Fill();
414
415
416// write wiregcalib----------------------------------------------------------------
417 double wireg;
418 TTree *wiregcalibtree = new TTree("wiregcalib", "wiregCalib");
419 wiregcalibtree -> Branch("wireg", &wireg, "S/D");
420 for(i=0; i<6796; i++){
421 wireg = tmpObject->getwireg(i);
422 wiregcalibtree -> Fill();
423 }
424
425// write layergcalib----------------------------------------------------------------
426 double layerg;
427 TTree *layergcalibtree = new TTree("layergcalib", "layergCalib");
428 layergcalibtree -> Branch("layerg", &layerg, "S/D");
429 for(i=0; i<43; i++){
430 layerg = tmpObject->getlayerg(i);
431 layergcalibtree -> Fill();
432 }
433
434// write all the trees
435 rungcalibtree -> Write();
436 ddgcalibtree -> Write();
437 ggscalibtree -> Write();
438 zdepcalibtree -> Write();
439 entacalibtree -> Write();
440 gaintree -> Write();
441 resoltree -> Write();
442 wiregcalibtree -> Write();
443 layergcalibtree -> Write();
444
445 delete rungcalibtree;
446 delete ddgcalibtree;
447 delete ggscalibtree;
448 delete zdepcalibtree;
449 delete entacalibtree;
450 delete gaintree;
451 delete resoltree;
452 delete wiregcalibtree;
453 delete layergcalibtree;
454 closeWrite();
455 log<<MSG::INFO<<"successfully create RootFile"<<endreq;
456 return sc;
457
458}
const CLID CLID_Calib_DedxCal
Definition: CalibModel.h:45
curve Branch("CurveSize",&CurveSize,"CurveSize/I")
curve Fill()
curve Write()
data GetEntry(0)
data SetBranchAddress("time",&time)
IMessageSvc * msgSvc()
double getenta(int i, int j) const
Definition: DedxCalibData.h:70
double getzdep(int i, int j) const
Definition: DedxCalibData.h:64
void set_costheta(const double aa, int i)
double getrung(int i, int j) const
Definition: DedxCalibData.h:73
double getresol() const
Definition: DedxCalibData.h:66
double getlayerg(int i) const
Definition: DedxCalibData.h:68
void set_hadron(const double aa, int i)
void set_t0(const double aa, int i)
double getwireg(int i) const
Definition: DedxCalibData.h:60
double getddg(int i, int j) const
Definition: DedxCalibData.h:56
double getggs(int i, int j) const
Definition: DedxCalibData.h:58
void set_dedx(const double aa, int i)
double getgain() const
Definition: DedxCalibData.h:62
StatusCode openRead(const std::string &fname)
StatusCode closeWrite()
virtual StatusCode openWrite(const std::string &fname)
const CLID & objType() const
static const CLID & classID()
virtual StatusCode createRoot(const std::string &fname, CalibData::CalibBase1 *pTDSObj)
virtual StatusCode i_createObj(const std::string &fname, DataObject *&refpObject)
RootDedxCalibDataCnv(ISvcLocator *svc)