BOSS 7.0.3
BESIII Offline Software System
Loading...
Searching...
No Matches
RecMdcTrackCnv.cxx
Go to the documentation of this file.
1#ifndef RecMdcTrackCnv_CXX
2#define RecMdcTrackCnv_CXX 1
3
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/DataObject.h"
6#include "GaudiKernel/ObjectVector.h"
7
8#include "TClonesArray.h"
9#include "Identifier/MdcID.h"
10#include "Identifier/Identifier.h"
11
12#include "EventModel/EventModel.h"
13
14#include "ReconEvent/ReconEvent.h"
15#include "MdcRecEvent/RecMdcTrack.h"
16#include "MdcRecEvent/RecMdcHit.h"
17#include "RootEventData/TRecMdcTrack.h"
18#include "RootEventData/TRecTrackEvent.h"
19
20#include "RootCnvSvc/Rec/RecTrackCnv.h"
21#include "RootCnvSvc/Rec/RecMdcTrackCnv.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<RecMdcTrackCnv> s_factory;
31//const ICnvFactory& RecMdcTrackCnvFactory = s_factory;
32
34: RootEventBaseCnv(classID(), svc)
35{
36 // Here we associate this converter with the /Event path on the TDS.
37 MsgStream log(msgSvc(), "RecMdcTrackCnv");
38 //m_rootTreename ="Rec";
39 m_rootBranchname ="m_recMdcTrackCol";
40 //declareObject(EventModel::Recon::RecMdcTrackCol, objType(), m_rootTreename, m_rootBranchname);
41 m_adresses.push_back(&m_recMdcTrackCol);
42 m_recMdcTrackCol=0;
43}
44
45StatusCode RecMdcTrackCnv::TObjectToDataObject(DataObject*& refpObject) {
46 // creation of TDS object from root object
47 MsgStream log(msgSvc(), "RecMdcTrackCnv");
48 log << MSG::DEBUG << "RecMdcTrackCnv::TObjectToDataObject" << endreq;
49
50 // create the TDS location for the RecMdcTrack Collection
51 RecMdcTrackCol* recMdcTrackCol = new RecMdcTrackCol;
52 refpObject = recMdcTrackCol;
53 // now convert
54 if (!m_recMdcTrackCol) return StatusCode::SUCCESS;
55 TIter mdcTrackIter(m_recMdcTrackCol);
56
57 //----------get hit smartRefVector--------
58 //HitRefVec *hitRefVec;
59 //int nTk=0;
60 //while (mdcTrackIter.Next()){ nTk++; }
61 //hitRefVec = new HitRefVec[nTk];
62
63 IDataProviderSvc* dataSvc = 0;
64 StatusCode sc = serviceLocator()->getService ("EventDataSvc",
65 IDataProviderSvc::interfaceID(), (IInterface*&)dataSvc);
66 if (!sc.isSuccess()) {
67 log << MSG::FATAL << "Could not get EventDataSvc in RecMdcTrackCnv" << endreq;
68 return( StatusCode::FAILURE);
69 }
70 SmartDataPtr<RecMdcHitCol> recMdcHitCol(dataSvc,"/Event/Recon/RecMdcHitCol");
71 if (!recMdcHitCol) {
72 log << MSG::FATAL << "Could not find RecMdcHitCol" << endreq;
73 return( StatusCode::FAILURE);
74 }
75 //RecMdcHitCol::iterator iter = recMdcHitCol->begin();
76 //for (;iter != recMdcHitCol->end(); iter++ ) {
77 // int tkId = (*iter)->getTrkId();
78 // hitRefVec[tkId].push_back(*iter);
79 //}
80
81 //---------------------------------------
82 mdcTrackIter = m_recMdcTrackCol;
83 TRecMdcTrack *recMdcTrackRoot = 0;
84 while ((recMdcTrackRoot = (TRecMdcTrack*)mdcTrackIter.Next())) {
85 int trackId = recMdcTrackRoot->trackId();
86 int charge = recMdcTrackRoot->charge();
87 double helix[5];
88 for(int i=0;i<5; i++){
89 helix[i] = recMdcTrackRoot->helix(i);
90 }
91 double pxy = recMdcTrackRoot->pxy();
92 double px = recMdcTrackRoot->px();
93 double py = recMdcTrackRoot->py();
94 double pz = recMdcTrackRoot->pz();
95 double p = recMdcTrackRoot->p();
96 double theta = recMdcTrackRoot->theta();
97 double phi = recMdcTrackRoot->phi();
98 double x = recMdcTrackRoot->x();
99 double y = recMdcTrackRoot->y();
100 double z = recMdcTrackRoot->z();
101 double r = recMdcTrackRoot->r();
102 int stat = recMdcTrackRoot->stat();
103 double chi = recMdcTrackRoot->chi2();
104 int ndof = recMdcTrackRoot->ndof();
105 int nlayer= recMdcTrackRoot->nlayer();
106 double err[15];
107 for (int i=0; i<15; i++){
108 err[i] = recMdcTrackRoot->err(i);
109 }
110 int nh = recMdcTrackRoot->nhits();
111 int ns = recMdcTrackRoot->nster();
112 // vector<int> vecHits = recMdcTrackRoot->vecHits();
113 double vx0 = recMdcTrackRoot->vx0();
114 double vy0 = recMdcTrackRoot->vy0();
115 double vz0 = recMdcTrackRoot->vz0();
116 double fiterm = recMdcTrackRoot->fiTerm();
117 RecMdcTrack *recMdcTrack = new RecMdcTrack();
118 m_common.m_rootRecMdcTrackMap[recMdcTrackRoot] = recMdcTrack;
119
120 recMdcTrack->setTrackId( trackId );
121 recMdcTrack->setCharge( charge );
122 recMdcTrack->setHelix( helix );
123 recMdcTrack->setPxy( pxy );
124 recMdcTrack->setPx( px );
125 recMdcTrack->setPy( py );
126 recMdcTrack->setPz( pz );
127 recMdcTrack->setP( p );
128 recMdcTrack->setTheta( theta );
129 recMdcTrack->setPhi( phi );
130 recMdcTrack->setX( x );
131 recMdcTrack->setY( y );
132 recMdcTrack->setZ( z );
133 recMdcTrack->setR( r );
134 recMdcTrack->setStat( stat );
135 recMdcTrack->setChi2( chi );
136 recMdcTrack->setNdof( ndof );
137 recMdcTrack->setError( err );
138 recMdcTrack->setNhits( nh );
139 recMdcTrack->setNster( ns );
140 recMdcTrack->setNlayer( nlayer );
141 // recMdcTrack->setVecHits( vecHits );
142 //rec
143 recMdcTrack->setVX0( vx0 );
144 recMdcTrack->setVY0( vy0 );
145 recMdcTrack->setVZ0( vz0 );
146 recMdcTrack->setFiTerm( fiterm );
147
148 HitRefVec theHitRefVec;
149
150 RecMdcHitCol::iterator iter = recMdcHitCol->begin();
151 for (;iter != recMdcHitCol->end(); iter++){
152
153 //cout<<" (*iter)->getTrkId(): "<<(*iter)->getTrkId()<<endl;
154 if((*iter)->getTrkId() == trackId){
155 SmartRef<RecMdcHit> refhit(*iter);
156 theHitRefVec.push_back(refhit);
157 }
158 }
159
160 recMdcTrack->setVecHits(theHitRefVec);
161
162 int nhits = recMdcTrack->getVecHits().size();
163
164 //std::cout<<" mdc hits: "<<nhits<< std::endl;
165
166 for(int ii=0; ii <nhits ; ii++){
167
168 //cout<<"ddl: "<<(recMdcTrack->getVecHits()[ii])->getDriftDistLeft()<<endl;
169 //cout<<"erddl: "<<(recMdcTrack->getVecHits()[ii])->getErrDriftDistLeft()<<endl;
170 Identifier id(recMdcTrack->getVecHits()[ii]->getMdcId());
171 int layer = MdcID::layer(id);
172 int wire = MdcID::wire(id);
173 //cout<<"layer: "<<layer<<" wire: "<<wire<<endl;
174 }
175 recMdcTrackCol->push_back(recMdcTrack);
176 }
177
178 delete m_recMdcTrackCol;
179 m_recMdcTrackCol = 0;
180 return StatusCode::SUCCESS;
181}
182
183
184
185
186StatusCode RecMdcTrackCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
187
188 MsgStream log(msgSvc(), "RecMdcTrackCnv");
189 log << MSG::DEBUG << "RecMdcTrackCnv::DataObjectToTObject" << endreq;
190
191 RecMdcTrackCol * mdcTrackColTds=dynamic_cast<RecMdcTrackCol *> (obj);
192 if (!mdcTrackColTds) {
193 log << MSG::ERROR << "Could not downcast to MdcTrackCol" << endreq;
194 return StatusCode::FAILURE;
195 }
196 DataObject *evt;
197 StatusCode sc = m_eds->findObject(EventModel::Recon::Event,evt);
198 if (!sc.isSuccess()) {
199 log << MSG::ERROR << "Could not get ReconEvent in TDS " << endreq;
200 return StatusCode::FAILURE;
201 }
202 ReconEvent * devtTds=dynamic_cast<ReconEvent *> (evt);
203 if (!devtTds) {
204 log << MSG::ERROR << "RecMdcTrackCnv:Could not downcast to TDS ReconEvent" << endreq;
205 }
206
207 IOpaqueAddress *addr;
208
209 m_cnvSvc->getRecTrackCnv()->createRep(evt,addr);
211
212 const TObjArray *m_recMdcTrackCol = recEvt->getRecMdcTrackCol();
213 if (!m_recMdcTrackCol) return StatusCode::SUCCESS;
214 //necessary in case there is I/O at the same time since array is static
215 recEvt->clearRecMdcTrackCol();
216
217 RecMdcTrackCol::const_iterator recMdcTrack;
218 for (recMdcTrack = mdcTrackColTds->begin(); recMdcTrack != mdcTrackColTds->end(); recMdcTrack++) {
219 Int_t trackId =(*recMdcTrack)->trackId();
220 Double_t helix[5];
221 for(int i=0;i<5;i++){
222 log<<MSG::INFO<<" recMdcTrack.helix("<<i<<"): "<<(*recMdcTrack)->helix(i)<<endreq;
223 helix[i] = (*recMdcTrack)->helix(i);
224 }
225
226 Int_t stat = (*recMdcTrack)->stat();
227 Double_t chi = (*recMdcTrack)->chi2();
228 Int_t ndof = (*recMdcTrack)->ndof();
229 Int_t ns = (*recMdcTrack)->nster();
230 Int_t nlayer =(*recMdcTrack)->nlayer();
231
232 Double_t er[15];
233 for (Int_t i=0; i<15; i++){
234 er[i] = (*recMdcTrack)->err(i);
235 }
236 Int_t nh = (*recMdcTrack)->getNhits();
237 // vector<Int_t> vecHits = (*recMdcTrack)->vecHits();
238 Double_t vx0 = (*recMdcTrack)->getVX0();
239 Double_t vy0 = (*recMdcTrack)->getVY0();
240 Double_t vz0 = (*recMdcTrack)->getVZ0();
241 Double_t fiterm =(*recMdcTrack)->getFiTerm();
242
243 TRecMdcTrack *recMdcTrackRoot = new TRecMdcTrack();
244 //m_common.m_recMdcTrackMap[(*recMdcTrack)] = recMdcTrackRoot;
245
246 recMdcTrackRoot->setTrackId( trackId );
247 recMdcTrackRoot->setHelix(helix);
248 log<<MSG::INFO<<" test,recMdcTrackRoot.px: "<<recMdcTrackRoot->px()
249 <<" recMdcTrackRoot.py: "<<recMdcTrackRoot->py()
250 <<" recMdcTrackRoot.pz: "<<recMdcTrackRoot->pz()
251 <<endreq;
252
253 recMdcTrackRoot->setStat( stat );
254 recMdcTrackRoot->setChi2( chi );
255 recMdcTrackRoot->setNdof( ndof );
256 recMdcTrackRoot->setNlayer( nlayer );
257 recMdcTrackRoot->setErr( er );
258 recMdcTrackRoot->setNhits( nh );
259 recMdcTrackRoot->setNster( ns );
260 // recMdcTrackRoot->setVecHits(vecHits);
261 recMdcTrackRoot->setVX0( vx0 );
262 recMdcTrackRoot->setVY0( vy0 );
263 recMdcTrackRoot->setVZ0( vz0 );
264 recMdcTrackRoot->setFiTerm( fiterm );
265
266 recEvt->addRecMdcTrack(recMdcTrackRoot);
267 }
268
269
270 return StatusCode::SUCCESS;
271}
272#endif
Double_t x[10]
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
ObjectVector< RecMdcTrack > RecMdcTrackCol
SmartRefVector< RecMdcHit > HitRefVec
void setError(double err[15])
void setHelix(double helix[5])
Definition: DstMdcTrack.cxx:98
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
Definition: MdcID.cxx:49
static int wire(const Identifier &id)
Definition: MdcID.cxx:54
RecMdcTrackCnv(ISvcLocator *svc)
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
static TRecTrackEvent * 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 Double_t x() const
const Double_t phi() const
const Double_t pz() const
const Double_t z() const
const Double_t p() const
const Double_t px() const
const Double_t y() const
const Double_t pxy() const
const Double_t theta() const
const Double_t r() const
const Int_t charge() const
const Double_t py() const
void addRecMdcTrack(TRecMdcTrack *Track)
Add a TkrTrack into the Mdc data collection.
void clearRecMdcTrackCol()
clear the whole array (necessary because of the consts-s)
const TObjArray * getRecMdcTrackCol() const
retrieve the whole TObjArray of RecMdcTrack Data
static std::map< const TObject *, const RecMdcTrack * > m_rootRecMdcTrackMap
#define ns(x)
Definition: xmltok.c:1504