BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
RootEstTofCalibDataCnv.cxx
Go to the documentation of this file.
1// $Header:
2// /bes/bes/BossCvs/Calibration/CalibSvc/CalibROOTCnv/src/cnv/RootEstTofCalibDataCnv.cxx,v 1.9
3// 2019/09/20 07:01:13 sunss Exp $
5#include "CalibData/Tof/TofCalibData.h"
6#include "CalibData/Tof/bTofCalibBase.h"
7#include "CalibData/Tof/eTofCalibBase.h"
8#include "CalibData/Tof/etfCalibBase.h"
9#include "CalibDataSvc/IInstrumentName.h"
10#include "GaudiKernel/MsgStream.h"
11
12#include "TDirectory.h"
13#include "TFile.h"
14#include "TObject.h"
15#include "TTree.h"
16
17#include "GaudiKernel/DataObject.h"
18#include "GaudiKernel/GenericAddress.h"
19#include "GaudiKernel/IAddressCreator.h"
20#include "GaudiKernel/IConversionSvc.h"
21#include "GaudiKernel/IDataProviderSvc.h"
22#include "GaudiKernel/IOpaqueAddress.h"
23
24#include "CalibDataSvc/ICalibMetaCnvSvc.h"
25#include "CalibDataSvc/ICalibRootSvc.h" //maybe
26
27// Temporary. Hope to find a better way to do this
28#include "CalibData/CalibModel.h"
29using namespace CalibData;
30// static CnvFactory<RootEstTofCalibDataCnv> TofCalib_factory;
31// const ICnvFactory& RootEstTofCalibDataCnvFactory = TofCalib_factory;
32
33const unsigned int nBarPar = 10;
34const unsigned int nBarParOff = 20;
35const unsigned int nEndPar = 8;
36const unsigned int nEtfPar = 20;
37const unsigned int nBarOffset = 2;
38
41
43
45
46StatusCode RootEstTofCalibDataCnv::i_createObj( const std::string& fname,
47 DataObject*& refpObject ) {
48
49 MsgStream log( msgSvc(), "RootEstTofCalibDataCnv" );
50 log << MSG::DEBUG << "SetProperty" << endmsg;
51
52 // open the file
53 StatusCode sc = openRead( fname );
54 if ( !sc ) { log << MSG::ERROR << "unable to open files" << endmsg; }
55
61
62 std::vector<CalibData::bTofCalibBase> tmpbTof;
63 std::vector<CalibData::eTofCalibBase> tmpeTof;
64 std::vector<CalibData::etfCalibBase> tmpetf;
65 std::vector<CalibData::bTofCommonCalibBase> tmpbTofCommon;
66 std::vector<CalibData::tofCalibInfoBase> tofinfoCol;
67
68 // Read in the object
69 int cnt;
70 // read btoftree ------------------------------------------------------------
71 double cnvBarPar1[nBarPar];
72 double cnvBarPar2[nBarPar];
73 double cnvBarParOff1_bunch0[nBarParOff];
74 double cnvBarParOff2_bunch0[nBarParOff];
75 double cnvBarParOff1_bunch1[nBarParOff];
76 double cnvBarParOff2_bunch1[nBarParOff];
77 double cnvBarParOff1_bunch2[nBarParOff];
78 double cnvBarParOff2_bunch2[nBarParOff];
79 double cnvBarParOff1_bunch3[nBarParOff];
80 double cnvBarParOff2_bunch3[nBarParOff];
81
82 TTree* btoftree = (TTree*)m_inFile->Get( "BarTofPar" );
83
84 char brname[10];
85 for ( unsigned int i = 0; i < nBarPar; i++ )
86 {
87 sprintf( brname, "P%i", i );
88 btoftree->SetBranchAddress( brname, &cnvBarPar1[i] );
89 }
90 for ( unsigned int i = 0; i < nBarPar; i++ )
91 {
92 sprintf( brname, "P%i", i + nBarPar );
93 btoftree->SetBranchAddress( brname, &cnvBarPar2[i] );
94 }
95 for ( unsigned int i = 0; i < nBarParOff; i++ )
96 {
97 sprintf( brname, "Bunch0_Poff%i", i );
98 btoftree->SetBranchAddress( brname, &cnvBarParOff1_bunch0[i] );
99 }
100 for ( unsigned int i = 0; i < nBarParOff; i++ )
101 {
102 sprintf( brname, "Bunch0_Poff%i", i + nBarParOff );
103 btoftree->SetBranchAddress( brname, &cnvBarParOff2_bunch0[i] );
104 }
105 for ( unsigned int i = 0; i < nBarParOff; i++ )
106 {
107 sprintf( brname, "Bunch1_Poff%i", i );
108 btoftree->SetBranchAddress( brname, &cnvBarParOff1_bunch1[i] );
109 }
110 for ( unsigned int i = 0; i < nBarParOff; i++ )
111 {
112 sprintf( brname, "Bunch1_Poff%i", i + nBarParOff );
113 btoftree->SetBranchAddress( brname, &cnvBarParOff2_bunch1[i] );
114 }
115 for ( unsigned int i = 0; i < nBarParOff; i++ )
116 {
117 sprintf( brname, "Bunch2_Poff%i", i );
118 btoftree->SetBranchAddress( brname, &cnvBarParOff1_bunch2[i] );
119 }
120 for ( unsigned int i = 0; i < nBarParOff; i++ )
121 {
122 sprintf( brname, "Bunch2_Poff%i", i + nBarParOff );
123 btoftree->SetBranchAddress( brname, &cnvBarParOff2_bunch2[i] );
124 }
125 for ( unsigned int i = 0; i < nBarParOff; i++ )
126 {
127 sprintf( brname, "Bunch3_Poff%i", i );
128 btoftree->SetBranchAddress( brname, &cnvBarParOff1_bunch3[i] );
129 }
130 for ( unsigned int i = 0; i < nBarParOff; i++ )
131 {
132 sprintf( brname, "Bunch3_Poff%i", i + nBarParOff );
133 btoftree->SetBranchAddress( brname, &cnvBarParOff2_bunch3[i] );
134 }
135
136 for ( cnt = 0; cnt < btoftree->GetEntries(); cnt++ )
137 {
138 btoftree->GetEntry( cnt );
139 bTof.setP1( cnvBarPar1 );
140 bTof.setP2( cnvBarPar2 );
141 bTof.setPoff1_bunch0( cnvBarParOff1_bunch0 );
142 bTof.setPoff2_bunch0( cnvBarParOff2_bunch0 );
143 bTof.setPoff1_bunch1( cnvBarParOff1_bunch1 );
144 bTof.setPoff2_bunch1( cnvBarParOff2_bunch1 );
145 bTof.setPoff1_bunch2( cnvBarParOff1_bunch2 );
146 bTof.setPoff2_bunch2( cnvBarParOff2_bunch2 );
147 bTof.setPoff1_bunch3( cnvBarParOff1_bunch3 );
148 bTof.setPoff2_bunch3( cnvBarParOff2_bunch3 );
149 tmpbTof.push_back( bTof );
150 }
151
152 // read etoftree
153 double cnvEndPar[nEndPar];
154
155 TTree* etoftree = (TTree*)m_inFile->Get( "EndTofPar" );
156
157 char ecname[10];
158 for ( unsigned int i = 0; i < nEndPar; i++ )
159 {
160 sprintf( ecname, "P%i", i );
161 etoftree->SetBranchAddress( ecname, &cnvEndPar[i] );
162 }
163
164 for ( cnt = 0; cnt < etoftree->GetEntries(); cnt++ )
165 {
166 etoftree->GetEntry( cnt );
167 eTof.setP( cnvEndPar );
168 tmpeTof.push_back( eTof );
169 }
170
171 // read etftree
172 double cnvEtfPar[nEtfPar];
173 double cnvEtfPar1[nEtfPar];
174 double cnvEtfPar2[nEtfPar];
175
176 if ( NULL != m_inFile->Get( "EtfTofPar" ) )
177 {
178 TTree* etftree = (TTree*)m_inFile->Get( "EtfTofPar" );
179
180 char etfname[10];
181 for ( unsigned int i = 0; i < nEtfPar; i++ )
182 {
183 sprintf( etfname, "P%i", i );
184 etftree->SetBranchAddress( etfname, &cnvEtfPar[i] );
185 }
186 for ( unsigned int i = 0; i < nEtfPar; i++ )
187 {
188 sprintf( etfname, "P%i", i + nEtfPar );
189 etftree->SetBranchAddress( etfname, &cnvEtfPar1[i] );
190 }
191 for ( unsigned int i = 0; i < nEtfPar; i++ )
192 {
193 sprintf( etfname, "P%i", i + 2 * nEtfPar );
194 etftree->SetBranchAddress( etfname, &cnvEtfPar2[i] );
195 }
196
197 for ( cnt = 0; cnt < etftree->GetEntries(); cnt++ )
198 {
199 etftree->GetEntry( cnt );
200 etf.setP( cnvEtfPar );
201 etf.setP1( cnvEtfPar1 );
202 etf.setP2( cnvEtfPar2 );
203 tmpetf.push_back( etf );
204 }
205 }
206
207 // read bTofCommonCalibBase
208 double cnvBarOffset[nBarOffset];
209 TTree* btofcommontree = (TTree*)m_inFile->Get( "BarTofParCommon" );
210 for ( unsigned int i = 0; i < nBarOffset; i++ )
211 {
212 sprintf( brname, "t0offset%i", i );
213 btofcommontree->SetBranchAddress( brname, &cnvBarOffset[i] );
214 }
215
216 int entries = btofcommontree->GetEntries();
217 for ( cnt = 0; cnt < entries; cnt++ )
218 {
219 btofcommontree->GetEntry( cnt );
220 bTofCommon.setOffset( cnvBarOffset );
221 tmpbTofCommon.push_back( bTofCommon );
222 }
223
224 int m_runFrom, m_runTo, m_eventFrom, m_eventTo;
225
226 TTree* CalibInfo = (TTree*)m_inFile->Get( "CalibInfo" );
227
228 if ( CalibInfo->GetBranchStatus( "runFrom" ) )
229 {
230 CalibInfo->SetBranchAddress( "runFrom", &m_runFrom );
231 CalibInfo->SetBranchAddress( "runTo", &m_runTo );
232 CalibInfo->SetBranchAddress( "eventFrom", &m_eventFrom );
233 CalibInfo->SetBranchAddress( "eventTo", &m_eventTo );
234 }
235 else
236 {
237 m_runFrom = -1;
238 m_runTo = -1;
239 m_eventFrom = -1;
240 m_eventTo = -1;
241 }
242
243 entries = CalibInfo->GetEntries();
244 for ( cnt = 0; cnt < entries; cnt++ )
245 {
246 CalibInfo->GetEntry( cnt );
247 tofinfo.setRunFrom( m_runFrom );
248 tofinfo.setRunTo( m_runTo );
249 tofinfo.setEventFrom( m_eventFrom );
250 tofinfo.setEventTo( m_eventTo );
251 tofinfoCol.push_back( tofinfo );
252 }
253
254 CalibData::TofCalibData* tmpObject =
255 new CalibData::TofCalibData( tmpbTof, tmpbTofCommon, tmpeTof, tmpetf, tofinfoCol );
256
257 refpObject = tmpObject;
258
259 return StatusCode::SUCCESS;
260}
261
262StatusCode RootEstTofCalibDataCnv::createRoot( const std::string& fname,
263 CalibData::CalibBase1* pTDSObj ) {
264 MsgStream log( msgSvc(), "RootEstTofCalibDataCnv" );
265
266 // Open the file, create the branch
267 StatusCode sc = openWrite( fname );
268 if ( !sc ) { log << MSG::ERROR << "unable to open files" << endmsg; }
269 // write the Data in the TCDS to RootFile
270 CalibData::TofCalibData* btof = dynamic_cast<CalibData::TofCalibData*>( pTDSObj );
271
272 // write btoftree----------------------------------------------------------------
273 double cnvBarPar1[nBarPar];
274 double cnvBarPar2[nBarPar];
275
276 char brname[8], ibrname[8];
277 TTree* btoftree = new TTree( "BarTofPar", "BarTofPar" );
278 for ( unsigned int i = 0; i < nBarPar; i++ )
279 {
280 sprintf( brname, "P%i", i );
281 sprintf( ibrname, "P%i/D", i );
282 btoftree->Branch( brname, &cnvBarPar1[i], ibrname );
283 }
284
285 for ( int i = 0; i < 176; i++ )
286 {
287 for ( int j = 0; j < static_cast<int>( nBarPar ); j++ )
288 {
289 cnvBarPar1[j] = btof->getBTofPleft( i, j );
290 cnvBarPar2[j] = btof->getBTofPright( i, j );
291 }
292 btoftree->Fill();
293 }
294
295 // write etoftree----------------------------------------------------------------
296 double cnvEndPar[nEndPar];
297
298 char ecname[8], iecname[8];
299 TTree* etoftree = new TTree( "EndTofPar", "EndTofPar" );
300 for ( unsigned int i = 0; i < nEndPar; i++ )
301 {
302 sprintf( ecname, "P%i", i );
303 sprintf( iecname, "P%i/D", i );
304 etoftree->Branch( ecname, &cnvEndPar[i], iecname );
305 }
306
307 for ( int i = 0; i < 96; i++ )
308 {
309 for ( int j = 0; j < static_cast<int>( nEndPar ); j++ )
310 { cnvEndPar[j] = btof->getETofP( i, j ); }
311 etoftree->Fill();
312 }
313
314 // write etftree----------------------------------------------------------------
315 double cnvEtfPar[nEtfPar];
316 double cnvEtfPar1[nEtfPar];
317 double cnvEtfPar2[nEtfPar];
318
319 char etfname[8], ietfname[8];
320 TTree* etftree = new TTree( "EtfTofPar", "EtfTofPar" );
321 for ( unsigned int i = 0; i < nEtfPar; i++ )
322 {
323 sprintf( etfname, "P%i", i );
324 sprintf( ietfname, "P%i/D", i );
325 etftree->Branch( etfname, &cnvEtfPar[i], ietfname );
326 }
327 for ( unsigned int i = 0; i < nEtfPar; i++ )
328 {
329 sprintf( etfname, "P%i", i + nEtfPar );
330 sprintf( ietfname, "P%i/D", i + nEtfPar );
331 etftree->Branch( etfname, &cnvEtfPar1[i], ietfname );
332 }
333 for ( unsigned int i = 0; i < nEtfPar; i++ )
334 {
335 sprintf( etfname, "P%i", i + 2 * nEtfPar );
336 sprintf( ietfname, "P%i/D", i + 2 * nEtfPar );
337 etftree->Branch( etfname, &cnvEtfPar2[i], ietfname );
338 }
339
340 for ( int i = 0; i < 72; i++ )
341 {
342 for ( int k = 0; k < 12; k++ )
343 {
344 for ( int j = 0; j < static_cast<int>( nEtfPar ); j++ )
345 {
346 cnvEtfPar[j] = btof->getEtfPcombine( i, k, j );
347 cnvEtfPar1[j] = btof->getEtfPleft( i, k, j );
348 cnvEtfPar2[j] = btof->getEtfPright( i, k, j );
349 }
350 etftree->Fill();
351 }
352 }
353
354 // write all the trees
355 btoftree->Write();
356 etoftree->Write();
357 etftree->Write();
358 delete btoftree;
359 delete etoftree;
360 delete etftree;
361 closeWrite();
362 log << MSG::INFO << "successfully create RootFile" << endmsg;
363
364 return sc;
365}
sprintf(cut, "kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_" "pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
const unsigned int nBarOffset
const unsigned int nBarParOff
const unsigned int nEndPar
const unsigned int nEtfPar
const unsigned int nBarPar
IMessageSvc * msgSvc()
double getETofP(int index, int pardex)
double getEtfPleft(int index, int strip, int pardex)
double getEtfPcombine(int index, int strip, int pardex)
double getEtfPright(int index, int strip, int pardex)
double getBTofPleft(int index, int pardex)
double getBTofPright(int index, int pardex)
void setP2(const double *TofP2)
void setPoff1_bunch3(const double *TofPoff1_bunch3)
void setPoff2_bunch1(const double *TofPoff2_bunch1)
void setPoff1_bunch0(const double *TofPoff1_bunch0)
void setPoff2_bunch2(const double *TofPoff2_bunch2)
void setPoff1_bunch1(const double *TofPoff1_bunch1)
void setPoff1_bunch2(const double *TofPoff1_bunch2)
void setPoff2_bunch3(const double *TofPoff2_bunch3)
void setPoff2_bunch0(const double *TofPoff2_bunch0)
void setP1(const double *TofP1)
void setOffset(const double *offset)
void setP(const double *TofP)
void setP(const double *etfP)
void setP1(const double *etfP1)
void setP2(const double *etfP2)
StatusCode openRead(const std::string &fname)
RootCalBaseCnv(ISvcLocator *svc, const CLID &clid)
StatusCode closeWrite()
virtual StatusCode openWrite(const std::string &fname)
RootEstTofCalibDataCnv(ISvcLocator *svc)
virtual StatusCode createRoot(const std::string &fname, CalibData::CalibBase1 *pTDSObj)
static const CLID & classID()
virtual StatusCode i_createObj(const std::string &fname, DataObject *&refpObject)