BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
TofTrackCnv.cxx
Go to the documentation of this file.
1#ifndef TofTrackCnv_CXX
2#define TofTrackCnv_CXX 1
3
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/DataObject.h"
6#include "GaudiKernel/ObjectVector.h"
7
8#include "TClonesArray.h"
9
10#include "EventModel/EventModel.h"
11
12#include "DstEvent/DstEvent.h" //TDS object
13#include "DstEvent/DstTofTrack.h" //TDS object
14#include "DstEvent/TofHitStatus.h"
15#include "RootEventData/TTofTrack.h" // standard root object
16#include "RootEventData/TDstEvent.h"
17
18#include "RootCnvSvc/Dst/DstCnv.h"
19#include "RootCnvSvc/Dst/TofTrackCnv.h"
20#include "RootCnvSvc/RootAddress.h"
21
22#include <vector>
23
24using namespace std;
25
26// Instantiation of a static factory class used by clients to create
27// instances of this service
28//static CnvFactory<TofTrackCnv> s_factory;
29//const ICnvFactory& TofTrackCnvFactory = s_factory;
30
31TofTrackCnv::TofTrackCnv(ISvcLocator* svc)
32: RootEventBaseCnv(classID(), svc)
33{
34 // Here we associate this converter with the /Event path on the TDS.
35 MsgStream log(msgSvc(), "TofTrackCnv");
36 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
37 m_rootBranchname ="m_tofTrackCol";
38 //declareObject(EventModel::Dst::DstTofTrackCol, objType(), m_rootTreename, m_rootBranchname);
39 m_adresses.push_back(&m_tofTrackCol);
40 m_tofTrackCol=0;
41}
42
43StatusCode TofTrackCnv::TObjectToDataObject(DataObject*& refpObject) {
44 // creation of TDS object from root object
45
46 MsgStream log(msgSvc(), "TofTrackCnv");
47 log << MSG::DEBUG << "TofTrackCnv::TObjectToDataObject" << endreq;
48 StatusCode sc=StatusCode::SUCCESS;
49 // create the TDS location for the TofTrack Collection
50 DstTofTrackCol* tofTrackTdsCol = new DstTofTrackCol;
51 refpObject=tofTrackTdsCol;
52
53
54 // now convert
55 if (!m_tofTrackCol) return sc;
56 TIter tofTrackIter(m_tofTrackCol);
57 TTofTrack *tofTrackRoot = 0;
58 while ((tofTrackRoot = (TTofTrack*)tofTrackIter.Next())) {
59
60 int tofTrackID = tofTrackRoot->tofTrackID();
61 int trackID = tofTrackRoot->trackID();
62 int tofID = tofTrackRoot->tofID();
63 unsigned int status = tofTrackRoot->status();
64 double path = tofTrackRoot->path();
65 double zrhit = tofTrackRoot->zrhit();
66 double ph = tofTrackRoot->ph();
67 double tof = tofTrackRoot->tof();
68 double errtof = tofTrackRoot->errtof();
69 double beta = tofTrackRoot->beta();
70 double texpElectron = tofTrackRoot->texpElectron();
71 double texpMuon = tofTrackRoot->texpMuon();
72 double texpPion = tofTrackRoot->texpPion();
73 double texpKaon = tofTrackRoot->texpKaon();
74 double texpProton = tofTrackRoot->texpProton();
75 double toffsetElectron = tofTrackRoot->toffsetElectron();
76 double toffsetMuon = tofTrackRoot->toffsetMuon();
77 double toffsetPion = tofTrackRoot->toffsetPion();
78 double toffsetKaon = tofTrackRoot->toffsetKaon();
79 double toffsetProton = tofTrackRoot->toffsetProton();
80 double toffsetAntiProton = tofTrackRoot->toffsetAntiProton();
81 double sigmaElectron = tofTrackRoot->sigmaElectron();
82 double sigmaMuon = tofTrackRoot->sigmaMuon();
83 double sigmaPion = tofTrackRoot->sigmaPion();
84 double sigmaKaon = tofTrackRoot->sigmaKaon();
85 double sigmaProton = tofTrackRoot->sigmaProton();
86 double sigmaAntiProton = tofTrackRoot->sigmaAntiProton();
87 int quality = tofTrackRoot->quality();
88 double t0 = tofTrackRoot->t0();
89 double errt0 = tofTrackRoot->errt0();
90 double errz = tofTrackRoot->errz();
91 double phi = tofTrackRoot->phi();
92 double errphi = tofTrackRoot->errphi();
93 double energy = tofTrackRoot->energy();
94 double errenergy = tofTrackRoot->errenergy();
95
96 DstTofTrack *tofTrackTds = new DstTofTrack();
97 m_common.m_rootTofTrackMap[tofTrackRoot] = tofTrackTds;
98
99 tofTrackTds->setTofTrackID(tofTrackID);
100 tofTrackTds->setTrackID(trackID);
101 tofTrackTds->setTofID(tofID);
102 tofTrackTds->setStatus(status);
103 tofTrackTds->setPath(path);
104 tofTrackTds->setZrHit(zrhit);
105 tofTrackTds->setPh(ph);
106 tofTrackTds->setTof(tof);
107 tofTrackTds->setErrTof(errtof);
108 tofTrackTds->setBeta(beta);
109 tofTrackTds->setTexpElectron(texpElectron);
110 tofTrackTds->setTexpMuon(texpMuon);
111 tofTrackTds->setTexpPion(texpPion);
112 tofTrackTds->setTexpKaon(texpKaon);
113 tofTrackTds->setTexpProton(texpProton);
114 tofTrackTds->setToffsetElectron(toffsetElectron);
115 tofTrackTds->setToffsetMuon(toffsetMuon);
116 tofTrackTds->setToffsetPion(toffsetPion);
117 tofTrackTds->setToffsetKaon(toffsetKaon);
118 tofTrackTds->setToffsetProton(toffsetProton);
119 tofTrackTds->setToffsetAntiProton(toffsetAntiProton);
120 tofTrackTds->setSigmaElectron(sigmaElectron);
121 tofTrackTds->setSigmaMuon(sigmaMuon);
122 tofTrackTds->setSigmaPion(sigmaPion);
123 tofTrackTds->setSigmaKaon(sigmaKaon);
124 tofTrackTds->setSigmaProton(sigmaProton);
125 tofTrackTds->setSigmaAntiProton(sigmaAntiProton);
126 tofTrackTds->setQuality(quality);
127 tofTrackTds->setT0(t0);
128 tofTrackTds->setErrT0(errt0);
129 tofTrackTds->setErrZ(errz);
130 tofTrackTds->setPhi(phi);
131 tofTrackTds->setErrPhi(errphi);
132 tofTrackTds->setEnergy(energy);
133 tofTrackTds->setErrEnergy(errenergy);
134
135 tofTrackTdsCol->push_back(tofTrackTds);
136
137 // delete tofTrackTds; // wensp add 2005/12/31
138 // tofTrackTds = NULL;
139 }
140
141 //m_tofTrackCol->Delete(); // wensp add 2005/12/30
142 delete m_tofTrackCol;
143 m_tofTrackCol = 0;
144 return StatusCode::SUCCESS;
145}
146
147StatusCode TofTrackCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
148
149 MsgStream log(msgSvc(), "TofTrackCnv");
150 log << MSG::DEBUG << "TofTrackCnv::DataObjectToTObject" << endreq;
151 StatusCode sc=StatusCode::SUCCESS;
152
153 DstTofTrackCol * tofTrackColTds=dynamic_cast<DstTofTrackCol *> (obj);
154 if (!tofTrackColTds) {
155 log << MSG::ERROR << "Could not downcast to DstTofTrackCol" << endreq;
156 return StatusCode::FAILURE;
157 }
158
159 DataObject *evt;
160 m_eds->findObject(EventModel::Dst::Event,evt);
161 if (evt==NULL) {
162 log << MSG::ERROR << "Could not get DstEvent in TDS " << endreq;
163 return StatusCode::FAILURE;
164 }
165
166 DstEvent * devtTds=dynamic_cast<DstEvent *> (evt);
167 if (!devtTds) {
168 log << MSG::ERROR << "TofTrackCnv:Could not downcast to TDS ReconEvent" << endreq;
169 }
170 IOpaqueAddress *addr;
171
172 m_cnvSvc->getDstCnv()->createRep(evt,addr);
174
175 const TObjArray *m_tofTrackCol = recEvt->getTofTrackCol();
176 if (!m_tofTrackCol) return sc;
177 recEvt->clearTofTrackCol(); //necessary in case there is I/O at the same time since array is static
178 DstTofTrackCol::const_iterator tofTrackTds;
179
180 for (tofTrackTds = tofTrackColTds->begin(); tofTrackTds != tofTrackColTds->end(); tofTrackTds++) {
181
182 Int_t tofTrackID = (*tofTrackTds)->tofTrackID();
183 Int_t trackID = (*tofTrackTds)->trackID();
184 Int_t tofID = (*tofTrackTds)->tofID();
185 Int_t strip = (*tofTrackTds)->strip();
186 UInt_t status = (*tofTrackTds)->status();
187 Double_t path = (*tofTrackTds)->path();
188 Double_t zrhit = (*tofTrackTds)->zrhit();
189 Double_t ph = (*tofTrackTds)->ph();
190 Double_t tof = (*tofTrackTds)->tof();
191 Double_t errtof = (*tofTrackTds)->errtof();
192 Double_t beta = (*tofTrackTds)->beta();
193 Double_t texpElectron = (*tofTrackTds)->texpElectron();
194 Double_t texpMuon = (*tofTrackTds)->texpMuon();
195 Double_t texpPion = (*tofTrackTds)->texpPion();
196 Double_t texpKaon = (*tofTrackTds)->texpKaon();
197 Double_t texpProton = (*tofTrackTds)->texpProton();
198 Double_t toffsetElectron = (*tofTrackTds)->toffsetElectron();
199 Double_t toffsetMuon = (*tofTrackTds)->toffsetMuon();
200 Double_t toffsetPion = (*tofTrackTds)->toffsetPion();
201 Double_t toffsetKaon = (*tofTrackTds)->toffsetKaon();
202 Double_t toffsetProton = (*tofTrackTds)->toffsetProton();
203 Double_t toffsetAntiProton = (*tofTrackTds)->toffsetAntiProton();
204 Double_t sigmaElectron = (*tofTrackTds)->sigmaElectron();
205 Double_t sigmaMuon = (*tofTrackTds)->sigmaMuon();
206 Double_t sigmaPion = (*tofTrackTds)->sigmaPion();
207 Double_t sigmaKaon = (*tofTrackTds)->sigmaKaon();
208 Double_t sigmaProton = (*tofTrackTds)->sigmaProton();
209 Double_t sigmaAntiProton = (*tofTrackTds)->sigmaAntiProton();
210 Int_t quality = (*tofTrackTds)->quality();
211 Double_t t0 = (*tofTrackTds)->t0();
212 Double_t errt0 = (*tofTrackTds)->errt0();
213 Double_t errz = (*tofTrackTds)->errz();
214 Double_t phi = (*tofTrackTds)->phi();
215 Double_t errphi = (*tofTrackTds)->errphi();
216 Double_t energy = (*tofTrackTds)->energy();
217 Double_t errenergy = (*tofTrackTds)->errenergy();
218
219 if( TofHitStatus::is_mrpc( status ) ) { tofID = tofID*12 + strip; }
220
221 TTofTrack *tofTrackRoot = new TTofTrack();
222 //m_common.m_tofTrackMap[(*tofTrackTds)] = tofTrackRoot;
223
224 tofTrackRoot->setTofTrackID(tofTrackID);
225 tofTrackRoot->setTrackID(trackID);
226 tofTrackRoot->setTofID(tofID);
227 tofTrackRoot->setStatus(status);
228 tofTrackRoot->setPath(path);
229 tofTrackRoot->setZrHit(zrhit);
230 tofTrackRoot->setPh(ph);
231 tofTrackRoot->setTof(tof);
232 tofTrackRoot->setErrTof(errtof);
233 tofTrackRoot->setBeta(beta);
234 tofTrackRoot->setTexpElectron(texpElectron);
235 tofTrackRoot->setTexpMuon(texpMuon);
236 tofTrackRoot->setTexpPion(texpPion);
237 tofTrackRoot->setTexpKaon(texpKaon);
238 tofTrackRoot->setTexpProton(texpProton);
239 tofTrackRoot->setToffsetElectron(toffsetElectron);
240 tofTrackRoot->setToffsetMuon(toffsetMuon);
241 tofTrackRoot->setToffsetPion(toffsetPion);
242 tofTrackRoot->setToffsetKaon(toffsetKaon);
243 tofTrackRoot->setToffsetProton(toffsetProton);
244 tofTrackRoot->setToffsetAntiProton(toffsetAntiProton);
245 tofTrackRoot->setSigmaElectron(sigmaElectron);
246 tofTrackRoot->setSigmaMuon(sigmaMuon);
247 tofTrackRoot->setSigmaPion(sigmaPion);
248 tofTrackRoot->setSigmaKaon(sigmaKaon);
249 tofTrackRoot->setSigmaProton(sigmaProton);
250 tofTrackRoot->setSigmaAntiProton(sigmaAntiProton);
251 tofTrackRoot->setQuality(quality);
252 tofTrackRoot->setT0(t0);
253 tofTrackRoot->setErrT0(errt0);
254 tofTrackRoot->setErrZ(errz);
255 tofTrackRoot->setPhi(phi);
256 tofTrackRoot->setErrPhi(errphi);
257 tofTrackRoot->setEnergy(energy);
258 tofTrackRoot->setErrEnergy(errenergy);
259
260 recEvt->addTofTrack(tofTrackRoot);
261 }
262
263 return StatusCode::SUCCESS;
264}
265#endif
ObjectVector< DstTofTrack > DstTofTrackCol
************Class m_ypar INTEGER m_KeyWgt INTEGER m_KeyIHVP INTEGER m_KeyGPS INTEGER m_IsBeamPolarized INTEGER m_EvtGenInterface DOUBLE PRECISION m_Emin DOUBLE PRECISION m_sphot DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_q2 DOUBLE PRECISION m_PolBeam2 DOUBLE PRECISION m_xErrPb *COMMON c_KK2f $ !CMS energy average $ !Spin Polarization vector first beam $ !Spin Polarization vector second beam $ !Beam energy spread[GeV] $ !minimum hadronization energy[GeV] $ !input READ never touch them !$ !debug facility $ !maximum weight $ !inverse alfaQED $ !minimum real photon energy
Definition: KK2f.h:50
static TDstEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition of a Root address, derived from IOpaqueAddress.
IDataProviderSvc * m_eds
pointer to eventdataservice
std::vector< void * > m_adresses
each converter knows the corresponding adresses
std::string m_rootBranchname
root branchname (may be concatenated of severals)
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)
Convert the transient object to the requested representation.
const TObjArray * getTofTrackCol() const
retrieve the whole TObjArray of TofTrack Data
void addTofTrack(TTofTrack *Track)
Add a TofTrack into the TOF Data collection.
Definition: TDstEvent.cxx:141
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
Definition: TofTrackCnv.cxx:43
TofTrackCnv(ISvcLocator *svc)
Definition: TofTrackCnv.cxx:31
static std::map< const TObject *, const DstTofTrack * > m_rootTofTrackMap