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