BOSS 7.0.2
BESIII Offline Software System
Loading...
Searching...
No Matches
MucTrackCnv.cxx
Go to the documentation of this file.
1#ifndef MucTrackCnv_CXX
2#define MucTrackCnv_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/DstMucTrack.h" //TDS object
14#include "RootEventData/TMucTrack.h" // standard root object
15#include "RootEventData/TDstEvent.h"
16
17#include "RootCnvSvc/Dst/DstCnv.h"
18#include "RootCnvSvc/Dst/MucTrackCnv.h"
19#include "RootCnvSvc/RootAddress.h"
20
21#include <vector>
22
23using namespace std;
24
25// Instantiation of a static factory class used by clients to create
26// instances of this service
27//static CnvFactory<MucTrackCnv> s_factory;
28//const ICnvFactory& MucTrackCnvFactory = s_factory;
29
30MucTrackCnv::MucTrackCnv(ISvcLocator* svc)
31: RootEventBaseCnv(classID(), svc)
32{
33 // Here we associate this converter with the /Event path on the TDS.
34 MsgStream log(msgSvc(), "MucTrackCnv");
35 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
36 m_rootBranchname ="m_mucTrackCol";
37 //declareObject(EventModel::Dst::DstMucTrackCol, objType(), m_rootTreename, m_rootBranchname);
38 m_adresses.push_back(&m_mucTrackCol);
39 m_mucTrackCol=0;
40}
41
42StatusCode MucTrackCnv::TObjectToDataObject(DataObject*& refpObject) {
43 // creation of TDS object from root object
44
45 MsgStream log(msgSvc(), "MucTrackCnv");
46 log << MSG::DEBUG << "MucTrackCnv::TObjectToDataObject" << endreq;
47 StatusCode sc=StatusCode::SUCCESS;
48
49 // create the TDS location for the MucTrack Collection
50 DstMucTrackCol* mucTrackTdsCol = new DstMucTrackCol;
51 refpObject=mucTrackTdsCol;
52
53
54 // now convert
55 if (!m_mucTrackCol) return sc;
56 TIter mucTrackIter(m_mucTrackCol);
57 TMucTrack *mucTrackRoot = 0;
58 while ((mucTrackRoot = (TMucTrack*)mucTrackIter.Next())) {
59
60 int trackId = mucTrackRoot->trackId();
61 int id = mucTrackRoot-> id();
62 int st = mucTrackRoot->status();
63 int type = mucTrackRoot->type();
64
65 int startPart = mucTrackRoot->startPart();
66 int endPart = mucTrackRoot->endPart();
67 int brLastLayer = mucTrackRoot->brLastLayer();
68 int ecLastLayer = mucTrackRoot->ecLastLayer();
69 int numHits = mucTrackRoot->numHits();
70 int numLayers = mucTrackRoot->numLayers();
71 int maxHitsInLayer = mucTrackRoot->maxHitsInLayer();
72
73 double depth = mucTrackRoot->depth();
74 double chi2 = mucTrackRoot->chi2();
75 int dof = mucTrackRoot->dof();
76 double rms = mucTrackRoot->rms();
77
78 double xPos = mucTrackRoot->xPos() ;
79 double yPos = mucTrackRoot->yPos() ;
80 double zPos = mucTrackRoot->zPos() ;
81
82 double xPosSigma = mucTrackRoot->xPosSigma() ;
83 double yPosSigma = mucTrackRoot->yPosSigma() ;
84 double zPosSigma = mucTrackRoot->zPosSigma() ;
85
86 double px = mucTrackRoot->px() ;
87 double py = mucTrackRoot->py() ;
88 double pz = mucTrackRoot->pz() ;
89
90 double distance = mucTrackRoot->distance();
91 double deltaphi = mucTrackRoot->deltaPhi();
92 //vector<int> vecHits = mucTrackRoot->vecHits();
93 //added by LI Chunhua
94 double krechi2 = mucTrackRoot->kalRechi2();
95 int kdof = mucTrackRoot->kaldof();
96 double kdepth = mucTrackRoot->kaldepth();
97 int kbrlay = mucTrackRoot->kalbrLastLayer();
98 int keclay = mucTrackRoot->kalecLastLayer();
99 //*********************
100
101 DstMucTrack *mucTrackTds = new DstMucTrack();
102 m_common.m_rootMucTrackMap[mucTrackRoot] = mucTrackTds;
103
104 mucTrackTds->setTrackId( trackId );
105 mucTrackTds->setId( id );
106 mucTrackTds->setStatus( st );
107 mucTrackTds->setType( type );
108
109 mucTrackTds->setStartPart( startPart );
110 mucTrackTds->setEndPart( endPart );
111 mucTrackTds->setBrLastLayer( brLastLayer );
112 mucTrackTds->setEcLastLayer( ecLastLayer );
113 mucTrackTds->setNumHits( numHits );
114 mucTrackTds->setNumLayers( numLayers );
115 mucTrackTds->setMaxHitsInLayer( maxHitsInLayer );
116
117 mucTrackTds->setDepth( depth );
118 mucTrackTds->setChi2( chi2 );
119 mucTrackTds->setDof( dof );
120 mucTrackTds->setRms( rms );
121
122 mucTrackTds->setXPos( xPos );
123 mucTrackTds->setYPos( yPos );
124 mucTrackTds->setZPos( zPos );
125
126 mucTrackTds->setXPosSigma( xPosSigma );
127 mucTrackTds->setYPosSigma( yPosSigma );
128 mucTrackTds->setZPosSigma( zPosSigma );
129
130 mucTrackTds->setPx( px );
131 mucTrackTds->setPy( py );
132 mucTrackTds->setPz( pz );
133
134 mucTrackTds->setDistance(distance);
135 mucTrackTds->setDeltaPhi(deltaphi);
136
137 //mucTrackTds->setVecHits(vecHits);
138 //added by LI Chunhua 2013/02/01
139 mucTrackTds->setkalRechi2(krechi2);
140 mucTrackTds->setkalDof(kdof);
141 mucTrackTds->setkalDepth(kdepth);
142 mucTrackTds->setkalbrLastLayer(kbrlay);
143 mucTrackTds->setkalecLastLayer(keclay);
144 //******************
145 mucTrackTdsCol->push_back(mucTrackTds);
146 //delete mucTrackTds; // wensp add 2005/12/31
147 // mucTrackTds = NULL;
148 }
149
150 // m_mucTrackCol->Delete(); // wensp add 2005/12/30
151 delete m_mucTrackCol;
152 m_mucTrackCol = 0;
153 return StatusCode::SUCCESS;
154}
155
156StatusCode MucTrackCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
157
158 MsgStream log(msgSvc(), "MucTrackCnv");
159 log << MSG::DEBUG << "MucTrackCnv::DataObjectToTObject" << endreq;
160 StatusCode sc=StatusCode::SUCCESS;
161
162 DstMucTrackCol * mucTrackColTds=dynamic_cast<DstMucTrackCol *> (obj);
163 if (!mucTrackColTds) {
164 log << MSG::ERROR << "Could not downcast to MucTrackCol" << endreq;
165 return StatusCode::FAILURE;
166 }
167
168 DataObject *evt;
169 m_eds->findObject(EventModel::Dst::Event,evt);
170 if (evt==NULL) {
171 log << MSG::ERROR << "Could not get DstEvent in TDS " << endreq;
172 return StatusCode::FAILURE;
173 }
174 DstEvent * devtTds=dynamic_cast<DstEvent *> (evt);
175 if (!devtTds) {
176 log << MSG::ERROR << "MucTrackCnv:Could not downcast to TDS DigiEvent" << endreq;
177 }
178 IOpaqueAddress *addr;
179
180 m_cnvSvc->getDstCnv()->createRep(evt,addr);
182
183 const TObjArray *m_mucTrackCol = recEvt->getMucTrackCol();
184 if (!m_mucTrackCol) return sc;
185 recEvt->clearMucTrackCol(); //necessary in case there is I/O at the same time since array is static
186 DstMucTrackCol::const_iterator mucTrackTds;
187
188 for (mucTrackTds = mucTrackColTds->begin(); mucTrackTds != mucTrackColTds->end(); mucTrackTds++) {
189 Int_t trackId = (*mucTrackTds)->trackId();
190 Int_t id = (*mucTrackTds)-> id();
191 Int_t st = (*mucTrackTds)->status();
192 Int_t type = (*mucTrackTds)->type();
193
194 Int_t startPart = (*mucTrackTds)->startPart();
195 Int_t endPart = (*mucTrackTds)->endPart();
196 Int_t brLastLayer = (*mucTrackTds)->brLastLayer();
197 Int_t ecLastLayer = (*mucTrackTds)->ecLastLayer();
198 Int_t numHits = (*mucTrackTds)->numHits();
199 Int_t numLayers = (*mucTrackTds)->numLayers();
200 Int_t maxHitsInLayer = (*mucTrackTds)->maxHitsInLayer();
201
202 Double_t depth = (*mucTrackTds)->depth();
203 Double_t chi2 = (*mucTrackTds)->chi2();
204 Int_t dof = (*mucTrackTds)->dof();
205 Double_t rms = (*mucTrackTds)->rms();
206
207 Double_t xPos = (*mucTrackTds)->xPos() ;
208 Double_t yPos = (*mucTrackTds)->yPos() ;
209 Double_t zPos = (*mucTrackTds)->zPos() ;
210
211 Double_t xPosSigma = (*mucTrackTds)->xPosSigma() ;
212 Double_t yPosSigma = (*mucTrackTds)->yPosSigma() ;
213 Double_t zPosSigma = (*mucTrackTds)->zPosSigma() ;
214
215 Double_t px = (*mucTrackTds)->px() ;
216 Double_t py = (*mucTrackTds)->py() ;
217 Double_t pz = (*mucTrackTds)->pz() ;
218
219 Double_t distance = (*mucTrackTds)->distance();
220 Double_t deltaphi = (*mucTrackTds)->deltaPhi();
221 //added by LI Chunhua
222 Double_t krechi2 = (*mucTrackTds)->kalRechi2();
223 Int_t kdof = (*mucTrackTds)->kaldof();
224 Double_t kdepth = (*mucTrackTds)->kaldepth();
225 Int_t kbrlay = (*mucTrackTds)->kalbrLastLayer();
226 Int_t keclay = (*mucTrackTds)->kalecLastLayer();
227 //*********************
228
229 //vector<Int_t> vecHits = (*mucTrackTds)->vecHits();
230
231 TMucTrack *mucTrackRoot = new TMucTrack();
232 //m_common.m_mucTrackMap[(*mucTrackTds)] = mucTrackRoot;
233
234 mucTrackRoot->setTrackId( trackId );
235 mucTrackRoot->setId( id );
236 mucTrackRoot->setStatus( st );
237 mucTrackRoot->setType( type );
238
239 mucTrackRoot->setStartPart( startPart );
240 mucTrackRoot->setEndPart( endPart );
241 mucTrackRoot->setBrLastLayer( brLastLayer );
242 mucTrackRoot->setEcLastLayer( ecLastLayer );
243 mucTrackRoot->setNumHits( numHits );
244 mucTrackRoot->setNumLayers( numLayers );
245 mucTrackRoot->setMaxHitsInLayer( maxHitsInLayer );
246
247 mucTrackRoot->setDepth( depth );
248 mucTrackRoot->setChi2( chi2 );
249 mucTrackRoot->setDof( dof );
250 mucTrackRoot->setRms( rms );
251
252 mucTrackRoot->setXPos( xPos );
253 mucTrackRoot->setYPos( yPos );
254 mucTrackRoot->setZPos( zPos );
255
256 mucTrackRoot->setXPosSigma( xPosSigma );
257 mucTrackRoot->setYPosSigma( yPosSigma );
258 mucTrackRoot->setZPosSigma( zPosSigma );
259
260 mucTrackRoot->setPx( px );
261 mucTrackRoot->setPy( py );
262 mucTrackRoot->setPz( pz );
263
264 mucTrackRoot->setDistance(distance);
265 mucTrackRoot->setDeltaPhi(deltaphi);
266 //added by LI Chunhua 2013/02/01
267 mucTrackRoot->setkalRechi2(krechi2);
268 mucTrackRoot->setkalDof(kdof);
269 mucTrackRoot->setkalDepth(kdepth);
270 mucTrackRoot->setkalbrLastLayer(kbrlay);
271 mucTrackRoot->setkalecLastLayer(keclay);
272 //******************
273 //mucTrackRoot->setVecHits(vecHits);
274
275 recEvt->addMucTrack(mucTrackRoot);
276 }
277
278 return StatusCode::SUCCESS;
279}
280#endif
ObjectVector< DstMucTrack > DstMucTrackCol
static TDstEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
MucTrackCnv(ISvcLocator *svc)
Definition: MucTrackCnv.cxx:30
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
Definition: MucTrackCnv.cxx:42
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
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.
void addMucTrack(TMucTrack *Track)
Add a MucTrack into the TOF Data collection.
Definition: TDstEvent.cxx:152
const TObjArray * getMucTrackCol() const
retrieve the whole TObjArray of MucTrack Data
static std::map< const TObject *, const DstMucTrack * > m_rootMucTrackMap