CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
RecCgemTrackCnv.cxx
Go to the documentation of this file.
1#ifndef RecCgemTrackCnv_CXX
2#define RecCgemTrackCnv_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/CgemID.h"
11
13
19
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<RecCgemTrackCnv> s_factory;
31//const ICnvFactory& RecCgemTrackCnvFactory = 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(), "RecCgemTrackCnv");
38 //m_rootTreename ="Rec";
39 m_rootBranchname ="m_recCgemTrackCol";
40 //declareObject(EventModel::Recon::RecCgemTrackCol, objType(), m_rootTreename, m_rootBranchname);
41 m_adresses.push_back(&m_recCgemTrackCol);
42 m_recCgemTrackCol=0;
43}
44
45StatusCode RecCgemTrackCnv::TObjectToDataObject(DataObject*& refpObject) {
46 // creation of TDS object from root object
47 MsgStream log(msgSvc(), "RecCgemTrackCnv");
48 log << MSG::DEBUG << "RecCgemTrackCnv::TObjectToDataObject" << endreq;
49
50 // create the TDS location for the RecCgemTrack Collection
51 RecCgemTrackCol* recCgemTrackCol = new RecCgemTrackCol;
52 refpObject = recCgemTrackCol;
53 // now convert
54 if (!m_recCgemTrackCol) return StatusCode::SUCCESS;
55 TIter cgemTrackIter(m_recCgemTrackCol);
56
57 //----------get hit smartRefVector--------
58 //HitRefVec *hitRefVec;
59 //int nTk=0;
60 //while (cgemTrackIter.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 RecCgemTrackCnv" << endreq;
68 return( StatusCode::FAILURE);
69 }
70 SmartDataPtr<RecCgemHitCol> recCgemHitCol(dataSvc,"/Event/Recon/RecCgemHitCol");
71 if (!recCgemHitCol) {
72 log << MSG::FATAL << "Could not find RecCgemHitCol" << endreq;
73 return( StatusCode::FAILURE);
74 }
75 //RecCgemHitCol::iterator iter = recCgemHitCol->begin();
76 //for (;iter != recCgemHitCol->end(); iter++ ) {
77 // int tkId = (*iter)->getTrkId();
78 // hitRefVec[tkId].push_back(*iter);
79 //}
80
81 //---------------------------------------
82 cgemTrackIter = m_recCgemTrackCol;
83 TRecCgemTrack *recCgemTrackRoot = 0;
84 while ((recCgemTrackRoot = (TRecCgemTrack*)cgemTrackIter.Next())) {
85 int trackId = recCgemTrackRoot->trackId();
86 int charge = recCgemTrackRoot->charge();
87 double cgemHelix[5];
88 for(int i=0;i<5; i++){
89 cgemHelix[i] = recCgemTrackRoot->helix(i);
90 }
91 double pxy = recCgemTrackRoot->pxy();
92 double px = recCgemTrackRoot->px();
93 double py = recCgemTrackRoot->py();
94 double pz = recCgemTrackRoot->pz();
95 double p = recCgemTrackRoot->p();
96 double theta = recCgemTrackRoot->theta();
97 double phi = recCgemTrackRoot->phi();
98 double x = recCgemTrackRoot->x();
99 double y = recCgemTrackRoot->y();
100 double z = recCgemTrackRoot->z();
101 double r = recCgemTrackRoot->r();
102 int stat = recCgemTrackRoot->stat();
103 double chi = recCgemTrackRoot->chi2();
104 int ndof = recCgemTrackRoot->ndof();
105 double err[15];
106 for (int i=0; i<15; i++){
107 err[i] = recCgemTrackRoot->err(i);
108 }
109 int nh = recCgemTrackRoot->nhits();
110 // vector<int> vecHits = recCgemTrackRoot->vecHits();
111 double vx0 = recCgemTrackRoot->vx0();
112 double vy0 = recCgemTrackRoot->vy0();
113 double vz0 = recCgemTrackRoot->vz0();
114 double fiterm = recCgemTrackRoot->fiTerm();
115 RecCgemTrack *recCgemTrack = new RecCgemTrack();
116 m_common.m_rootRecCgemTrackMap[recCgemTrackRoot] = recCgemTrack;
117
118 recCgemTrack->setTrackId( trackId );
119 recCgemTrack->setCharge( charge );
120 recCgemTrack->setHelix( cgemHelix );
121 recCgemTrack->setPxy( pxy );
122 recCgemTrack->setPx( px );
123 recCgemTrack->setPy( py );
124 recCgemTrack->setPz( pz );
125 recCgemTrack->setP( p );
126 recCgemTrack->setTheta( theta );
127 recCgemTrack->setPhi( phi );
128 recCgemTrack->setX( x );
129 recCgemTrack->setY( y );
130 recCgemTrack->setZ( z );
131 recCgemTrack->setR( r );
132 recCgemTrack->setStat( stat );
133 recCgemTrack->setChi2( chi );
134 recCgemTrack->setNdof( ndof );
135 recCgemTrack->setError( err );
136 recCgemTrack->setNhits( nh );
137 // recCgemTrack->setVecHits( vecHits );
138 //rec
139 recCgemTrack->setVX0( vx0 );
140 recCgemTrack->setVY0( vy0 );
141 recCgemTrack->setVZ0( vz0 );
142 recCgemTrack->setFiTerm( fiterm );
143
144 RecCgemHitRefVec theHitRefVec;
145
146 RecCgemHitCol::iterator iter = recCgemHitCol->begin();
147 for (;iter != recCgemHitCol->end(); iter++){
148
149 //cout<<" (*iter)->getTrkId(): "<<(*iter)->getTrkId()<<endl;
150 if((*iter)->getTrkId() == trackId){
151 SmartRef<RecCgemHit> refhit(*iter);
152 theHitRefVec.push_back(refhit);
153 }
154 }
155
156 recCgemTrack->setVecHits(theHitRefVec);
157
158 int nhits = recCgemTrack->getVecHits().size();
159
160 //std::cout<<" cgem hits: "<<nhits<< std::endl;
161
162 for(int ii=0; ii <nhits ; ii++){
163
164 //cout<<"ddl: "<<(recCgemTrack->getVecHits()[ii])->getDriftDistLeft()<<endl;
165 //cout<<"erddl: "<<(recCgemTrack->getVecHits()[ii])->getErrDriftDistLeft()<<endl;
166 Identifier id(recCgemTrack->getVecHits()[ii]->getCgemId());
167 int layer = CgemID::layer(id);
168 int sheet = CgemID::sheet(id);
169 int strip = CgemID::strip(id);
170 //cout<<"layer: "<<layer<<" wire: "<<wire<<endl;
171 }
172 recCgemTrackCol->push_back(recCgemTrack);
173 }
174
175 delete m_recCgemTrackCol;
176 m_recCgemTrackCol = 0;
177 return StatusCode::SUCCESS;
178}
179
180
181
182
183StatusCode RecCgemTrackCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
184
185 MsgStream log(msgSvc(), "RecCgemTrackCnv");
186 log << MSG::DEBUG << "RecCgemTrackCnv::DataObjectToTObject" << endreq;
187
188 RecCgemTrackCol * cgemTrackColTds=dynamic_cast<RecCgemTrackCol *> (obj);
189 if (!cgemTrackColTds) {
190 log << MSG::ERROR << "Could not downcast to CgemTrackCol" << endreq;
191 return StatusCode::FAILURE;
192 }
193 DataObject *evt;
194 StatusCode sc = m_eds->findObject(EventModel::Recon::Event,evt);
195 if (!sc.isSuccess()) {
196 log << MSG::ERROR << "Could not get ReconEvent in TDS " << endreq;
197 return StatusCode::FAILURE;
198 }
199 ReconEvent * devtTds=dynamic_cast<ReconEvent *> (evt);
200 if (!devtTds) {
201 log << MSG::ERROR << "RecCgemTrackCnv:Could not downcast to TDS ReconEvent" << endreq;
202 }
203
204 IOpaqueAddress *addr;
205
206 m_cnvSvc->getRecTrackCnv()->createRep(evt,addr);
208
209 const TObjArray *m_recCgemTrackCol = recEvt->getRecCgemTrackCol();
210 if (!m_recCgemTrackCol) return StatusCode::SUCCESS;
211 //necessary in case there is I/O at the same time since array is static
212 recEvt->clearRecCgemTrackCol();
213
214 RecCgemTrackCol::const_iterator recCgemTrack;
215 for (recCgemTrack = cgemTrackColTds->begin(); recCgemTrack != cgemTrackColTds->end(); recCgemTrack++) {
216 Int_t trackId =(*recCgemTrack)->trackId();
217 Double_t cgemHelix[5];
218 for(int i=0;i<5;i++){
219 log<<MSG::INFO<<" recCgemTrack.cgemHelix("<<i<<"): "<<(*recCgemTrack)->helix(i)<<endreq;
220 cgemHelix[i] = (*recCgemTrack)->helix(i);
221 }
222
223 Int_t stat = (*recCgemTrack)->stat();
224 Double_t chi = (*recCgemTrack)->chi2();
225 Int_t ndof = (*recCgemTrack)->ndof();
226
227 Double_t er[15];
228 for (Int_t i=0; i<15; i++){
229 er[i] = (*recCgemTrack)->err(i);
230 }
231 Int_t nh = (*recCgemTrack)->getNhits();
232 // vector<Int_t> vecHits = (*recCgemTrack)->vecHits();
233 Double_t vx0 = (*recCgemTrack)->getVX0();
234 Double_t vy0 = (*recCgemTrack)->getVY0();
235 Double_t vz0 = (*recCgemTrack)->getVZ0();
236 Double_t fiterm =(*recCgemTrack)->getFiTerm();
237
238 TRecCgemTrack *recCgemTrackRoot = new TRecCgemTrack();
239 //m_common.m_recCgemTrackMap[(*recCgemTrack)] = recCgemTrackRoot;
240
241 recCgemTrackRoot->setTrackId( trackId );
242 recCgemTrackRoot->setHelix(cgemHelix);
243 log<<MSG::INFO<<" test,recCgemTrackRoot.px: "<<recCgemTrackRoot->px()
244 <<" recCgemTrackRoot.py: "<<recCgemTrackRoot->py()
245 <<" recCgemTrackRoot.pz: "<<recCgemTrackRoot->pz()
246 <<endreq;
247
248 recCgemTrackRoot->setStat( stat );
249 recCgemTrackRoot->setChi2( chi );
250 recCgemTrackRoot->setNdof( ndof );
251 recCgemTrackRoot->setErr( er );
252 recCgemTrackRoot->setNhits( nh );
253 // recCgemTrackRoot->setVecHits(vecHits);
254 recCgemTrackRoot->setVX0( vx0 );
255 recCgemTrackRoot->setVY0( vy0 );
256 recCgemTrackRoot->setVZ0( vz0 );
257 recCgemTrackRoot->setFiTerm( fiterm );
258
259 recEvt->addRecCgemTrack(recCgemTrackRoot);
260 }
261
262
263 return StatusCode::SUCCESS;
264}
265#endif
Double_t x[10]
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
SmartRefVector< RecCgemHit > RecCgemHitRefVec
ObjectVector< RecCgemTrack > RecCgemTrackCol
Definition: RecCgemTrack.h:79
IMessageSvc * msgSvc()
static int strip(const Identifier &id)
Definition: CgemID.cxx:83
static int sheet(const Identifier &id)
Definition: CgemID.cxx:77
static int layer(const Identifier &id)
Definition: CgemID.cxx:71
void setStat(const int stat)
Definition: DstCgemTrack.h:93
void setPx(const double px)
Definition: DstCgemTrack.h:83
void setPhi(const double phi)
Definition: DstCgemTrack.h:88
void setTheta(const double theta)
Definition: DstCgemTrack.h:87
void setCharge(const int charge)
Definition: DstCgemTrack.h:81
void setHelix(double helix[5])
void setZ(const double z)
Definition: DstCgemTrack.h:91
void setP(const double p)
Definition: DstCgemTrack.h:86
void setTrackId(const int trackId)
Definition: DstCgemTrack.h:80
void setError(double err[15])
void setPxy(const double pxy)
Definition: DstCgemTrack.h:82
void setPy(const double py)
Definition: DstCgemTrack.h:84
void setY(const double y)
Definition: DstCgemTrack.h:90
void setX(const double x)
Definition: DstCgemTrack.h:89
void setNdof(const int ndof)
Definition: DstCgemTrack.h:95
void setR(const double r)
Definition: DstCgemTrack.h:92
void setPz(const double pz)
Definition: DstCgemTrack.h:85
void setChi2(const double chi)
Definition: DstCgemTrack.h:94
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
RecCgemTrackCnv(ISvcLocator *svc)
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
const RecCgemHitRefVec getVecHits(void) const
Definition: RecCgemTrack.h:60
void setVecHits(RecCgemHitRefVec vechits)
Definition: RecCgemTrack.h:69
void setVX0(double x0)
Definition: RecCgemTrack.h:63
void setNhits(int nhits)
Definition: RecCgemTrack.h:67
void setVZ0(double z0)
Definition: RecCgemTrack.h:65
void setFiTerm(double fiterm)
Definition: RecCgemTrack.h:66
void setVY0(double y0)
Definition: RecCgemTrack.h:64
static TRecTrackEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition: RecTrackCnv.h:36
Definition of a Root address, derived from IOpaqueAddress.
Definition: RootAddress.h:21
RecTrackCnv * getRecTrackCnv()
Definition: RootCnvSvc.h:166
Base class for all Root Converters.
std::vector< void * > m_adresses
each converter knows the corresponding adresses
RootCnvSvc * m_cnvSvc
IDataProviderSvc * m_eds
pointer to eventdataservice
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 phi() const
const Double_t chi2() const
Definition: TRecCgemTrack.h:32
const Int_t ndof() const
Definition: TRecCgemTrack.h:33
void setVY0(Double_t vy0)
Definition: TRecCgemTrack.h:60
const Int_t nhits() const
Definition: TRecCgemTrack.h:35
void setChi2(const Double_t chi)
Definition: TRecCgemTrack.h:49
void setNdof(const Int_t ndof)
Definition: TRecCgemTrack.h:50
void setHelix(const Double_t helix[5])
Definition: TRecCgemTrack.h:45
const Int_t trackId() const
Definition: TRecCgemTrack.h:17
const Double_t vy0(void) const
Definition: TRecCgemTrack.h:39
const Int_t stat() const
Definition: TRecCgemTrack.h:31
const Double_t y() const
const Double_t x() const
void setErr(const Double_t er[15])
Definition: TRecCgemTrack.h:52
const Double_t r() const
const Double_t pz() const
const Double_t py() const
const Double_t pxy() const
const Double_t px() const
const Double_t p() const
const Double_t vx0(void) const
Definition: TRecCgemTrack.h:38
void setTrackId(const Int_t trackId)
Definition: TRecCgemTrack.h:44
void setVX0(Double_t vx0)
Definition: TRecCgemTrack.h:59
const Double_t helix(Int_t i) const
Definition: TRecCgemTrack.h:18
const Double_t z() const
const Int_t charge() const
const Double_t vz0(void) const
Definition: TRecCgemTrack.h:40
void setFiTerm(Double_t fiterm)
Definition: TRecCgemTrack.h:62
const Double_t theta() const
const Double_t fiTerm(void) const
Definition: TRecCgemTrack.h:41
const Double_t err(Int_t i) const
Definition: TRecCgemTrack.h:34
void setVZ0(Double_t vz0)
Definition: TRecCgemTrack.h:61
void setNhits(const Int_t nh)
Definition: TRecCgemTrack.h:56
void setStat(const Int_t stat)
Definition: TRecCgemTrack.h:48
void addRecCgemTrack(TRecCgemTrack *Track)
Add a TkrTrack into the Cgem data collection.
const TObjArray * getRecCgemTrackCol() const
retrieve the whole TObjArray of RecCgemTrack Data
void clearRecCgemTrackCol()
clear the whole array (necessary because of the consts-s)
static std::map< const TObject *, const RecCgemTrack * > m_rootRecCgemTrackMap
Definition: commonData.h:244
_EXTERN_ std::string Event
Definition: EventModel.h:90