CGEM BOSS 6.6.5.g
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"
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<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 SmartDataPtr<RecCgemClusterCol> aCgemClusterCol(dataSvc,"/Event/Recon/RecCgemClusterCol");
82 if(!aCgemClusterCol) {
83 log << MSG::FATAL << "Could not find RecCgemClusterCol" << endreq;
84 return( StatusCode::FAILURE);
85 }
86 //---------------------------------------
87 mdcTrackIter = m_recMdcTrackCol;
88 TRecMdcTrack *recMdcTrackRoot = 0;
89 while ((recMdcTrackRoot = (TRecMdcTrack*)mdcTrackIter.Next())) {
90 int trackId = recMdcTrackRoot->trackId();
91 int charge = recMdcTrackRoot->charge();
92 double helix[5];
93 for(int i=0;i<5; i++){
94 helix[i] = recMdcTrackRoot->helix(i);
95 }
96 double pxy = recMdcTrackRoot->pxy();
97 double px = recMdcTrackRoot->px();
98 double py = recMdcTrackRoot->py();
99 double pz = recMdcTrackRoot->pz();
100 double p = recMdcTrackRoot->p();
101 double theta = recMdcTrackRoot->theta();
102 double phi = recMdcTrackRoot->phi();
103 double x = recMdcTrackRoot->x();
104 double y = recMdcTrackRoot->y();
105 double z = recMdcTrackRoot->z();
106 double r = recMdcTrackRoot->r();
107 int stat = recMdcTrackRoot->stat();
108 double chi = recMdcTrackRoot->chi2();
109 int ndof = recMdcTrackRoot->ndof();
110 int nlayer= recMdcTrackRoot->nlayer();
111 //int nCgemXClusters=recMdcTrackRoot->nCgemXClusters();
112 //int nCgemVClusters=recMdcTrackRoot->nCgemVClusters();
113 double err[15];
114 for (int i=0; i<15; i++){
115 err[i] = recMdcTrackRoot->err(i);
116 }
117 int nh = recMdcTrackRoot->nhits();
118 int ns = recMdcTrackRoot->nster();
119 // vector<int> vecHits = recMdcTrackRoot->vecHits();
120 double vx0 = recMdcTrackRoot->vx0();
121 double vy0 = recMdcTrackRoot->vy0();
122 double vz0 = recMdcTrackRoot->vz0();
123 double fiterm = recMdcTrackRoot->fiTerm();
124 RecMdcTrack *recMdcTrack = new RecMdcTrack();
125 m_common.m_rootRecMdcTrackMap[recMdcTrackRoot] = recMdcTrack;
126
127 recMdcTrack->setTrackId( trackId );
128 recMdcTrack->setCharge( charge );
129 recMdcTrack->setHelix( helix );
130 recMdcTrack->setPxy( pxy );
131 recMdcTrack->setPx( px );
132 recMdcTrack->setPy( py );
133 recMdcTrack->setPz( pz );
134 recMdcTrack->setP( p );
135 recMdcTrack->setTheta( theta );
136 recMdcTrack->setPhi( phi );
137 recMdcTrack->setX( x );
138 recMdcTrack->setY( y );
139 recMdcTrack->setZ( z );
140 recMdcTrack->setR( r );
141 recMdcTrack->setStat( stat );
142 recMdcTrack->setChi2( chi );
143 recMdcTrack->setNdof( ndof );
144 recMdcTrack->setError( err );
145 recMdcTrack->setNhits( nh );
146 recMdcTrack->setNster( ns );
147 recMdcTrack->setNlayer( nlayer );
148 // recMdcTrack->setVecHits( vecHits );
149 //rec
150 recMdcTrack->setVX0( vx0 );
151 recMdcTrack->setVY0( vy0 );
152 recMdcTrack->setVZ0( vz0 );
153 recMdcTrack->setFiTerm( fiterm );
154 //recMdcTrack->setNCgemXCluster( nCgemXClusters );
155 //recMdcTrack->setNCgemVCluster( nCgemVClusters );
156
157 HitRefVec theHitRefVec;
158
159 RecMdcHitCol::iterator iter = recMdcHitCol->begin();
160 for (;iter != recMdcHitCol->end(); iter++){
161
162 //cout<<" (*iter)->getTrkId(): "<<(*iter)->getTrkId()<<endl;
163 if((*iter)->getTrkId() == trackId){
164 SmartRef<RecMdcHit> refhit(*iter);
165 theHitRefVec.push_back(refhit);
166 }
167 }
168
169 recMdcTrack->setVecHits(theHitRefVec);
170
171 int nhits = recMdcTrack->getVecHits().size();
172
173 //std::cout<<" mdc hits: "<<nhits<< std::endl;
174
175 for(int ii=0; ii <nhits ; ii++){
176
177 //cout<<"ddl: "<<(recMdcTrack->getVecHits()[ii])->getDriftDistLeft()<<endl;
178 //cout<<"erddl: "<<(recMdcTrack->getVecHits()[ii])->getErrDriftDistLeft()<<endl;
179 Identifier id(recMdcTrack->getVecHits()[ii]->getMdcId());
180 int layer = MdcID::layer(id);
181 int wire = MdcID::wire(id);
182 //cout<<"layer: "<<layer<<" wire: "<<wire<<endl;
183 }
184
185 // --- CGEM clusters (added on 6 Apr, 2021, L.L. Wang)
186 ClusterRefVec clusterRefVec;
187 map<int,int> clusterFitStat;
188 vector<Int_t> vecClusterId = recMdcTrackRoot->vecClusterId();
189 cout<<"recMdcTrackRoot gets a vecClusterId with size "<<vecClusterId.size()<<endl;
190 vector<Int_t>::iterator it_clusterId = vecClusterId.begin();
191 RecCgemClusterCol::iterator iter_cluster=aCgemClusterCol->begin();
192 //for(; iter_cluster!=aCgemClusterCol->end(); iter_cluster++)
193 for(; it_clusterId!=vecClusterId.end(); it_clusterId++)
194 {
195 //if(trackId==(*iter_cluster)->getTrkId())
196 iter_cluster=aCgemClusterCol->begin()+(*it_clusterId);
197 if((*iter_cluster)->getclusterid()==(*it_clusterId))
198 {
199 const RecCgemCluster* recCgemCluster = (*iter_cluster);
200 clusterRefVec.push_back(recCgemCluster);
201 int clusterid = recCgemCluster->getclusterid();
202 clusterFitStat[clusterid] = 1;
203 }
204 else cout<<"wrong clusterRefVec assignment in RecMdcTrackCnv"<<endl;
205 }
206 //cout<<"recMdcTrack set a clusterRefVec with size "<<clusterRefVec.size()<<endl;
207 recMdcTrack->setVecClusters(clusterRefVec,clusterFitStat);
208
209 recMdcTrackCol->push_back(recMdcTrack);
210 }
211
212 delete m_recMdcTrackCol;
213 m_recMdcTrackCol = 0;
214 return StatusCode::SUCCESS;
215}
216
217
218
219
220StatusCode RecMdcTrackCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
221
222 MsgStream log(msgSvc(), "RecMdcTrackCnv");
223 log << MSG::DEBUG << "RecMdcTrackCnv::DataObjectToTObject" << endreq;
224
225 RecMdcTrackCol * mdcTrackColTds=dynamic_cast<RecMdcTrackCol *> (obj);
226 if (!mdcTrackColTds) {
227 log << MSG::ERROR << "Could not downcast to MdcTrackCol" << endreq;
228 return StatusCode::FAILURE;
229 }
230 DataObject *evt;
231 StatusCode sc = m_eds->findObject(EventModel::Recon::Event,evt);
232 if (!sc.isSuccess()) {
233 log << MSG::ERROR << "Could not get ReconEvent in TDS " << endreq;
234 return StatusCode::FAILURE;
235 }
236 ReconEvent * devtTds=dynamic_cast<ReconEvent *> (evt);
237 if (!devtTds) {
238 log << MSG::ERROR << "RecMdcTrackCnv:Could not downcast to TDS ReconEvent" << endreq;
239 }
240
241 IOpaqueAddress *addr;
242
243 m_cnvSvc->getRecTrackCnv()->createRep(evt,addr);
245
246 const TObjArray *m_recMdcTrackCol = recEvt->getRecMdcTrackCol();
247 if (!m_recMdcTrackCol) return StatusCode::SUCCESS;
248 //necessary in case there is I/O at the same time since array is static
249 recEvt->clearRecMdcTrackCol();
250
251 RecMdcTrackCol::const_iterator recMdcTrack;
252 for (recMdcTrack = mdcTrackColTds->begin(); recMdcTrack != mdcTrackColTds->end(); recMdcTrack++) {
253 Int_t trackId =(*recMdcTrack)->trackId();
254 Double_t helix[5];
255 for(int i=0;i<5;i++){
256 log<<MSG::INFO<<" recMdcTrack.helix("<<i<<"): "<<(*recMdcTrack)->helix(i)<<endreq;
257 helix[i] = (*recMdcTrack)->helix(i);
258 }
259
260 Int_t stat = (*recMdcTrack)->stat();
261 Double_t chi = (*recMdcTrack)->chi2();
262 Int_t ndof = (*recMdcTrack)->ndof();
263 Int_t ns = (*recMdcTrack)->nster();
264 Int_t nlayer =(*recMdcTrack)->nlayer();
265 //Int_t nCgemXCluster = (*recMdcTrack)->nCgemXCluster();
266 //Int_t nCgemVCluster = (*recMdcTrack)->nCgemVCluster();
267
268 Double_t er[15];
269 for (Int_t i=0; i<15; i++){
270 er[i] = (*recMdcTrack)->err(i);
271 }
272 Int_t nh = (*recMdcTrack)->getNhits();
273 // vector<Int_t> vecHits = (*recMdcTrack)->vecHits();
274 Double_t vx0 = (*recMdcTrack)->getVX0();
275 Double_t vy0 = (*recMdcTrack)->getVY0();
276 Double_t vz0 = (*recMdcTrack)->getVZ0();
277 Double_t fiterm =(*recMdcTrack)->getFiTerm();
278
279 TRecMdcTrack *recMdcTrackRoot = new TRecMdcTrack();
280 //m_common.m_recMdcTrackMap[(*recMdcTrack)] = recMdcTrackRoot;
281
282 recMdcTrackRoot->setTrackId( trackId );
283 recMdcTrackRoot->setHelix(helix);
284 log<<MSG::INFO<<" test,recMdcTrackRoot.px: "<<recMdcTrackRoot->px()
285 <<" recMdcTrackRoot.py: "<<recMdcTrackRoot->py()
286 <<" recMdcTrackRoot.pz: "<<recMdcTrackRoot->pz()
287 <<endreq;
288
289 recMdcTrackRoot->setStat( stat );
290 recMdcTrackRoot->setChi2( chi );
291 recMdcTrackRoot->setNdof( ndof );
292 recMdcTrackRoot->setNlayer( nlayer );
293 //recMdcTrackRoot->setNCgemXClusters(nCgemXCluster);
294 //recMdcTrackRoot->setNCgemVClusters(nCgemVCluster);
295 recMdcTrackRoot->setErr( er );
296 recMdcTrackRoot->setNhits( nh );
297 recMdcTrackRoot->setNster( ns );
298 // recMdcTrackRoot->setVecHits(vecHits);
299 recMdcTrackRoot->setVX0( vx0 );
300 recMdcTrackRoot->setVY0( vy0 );
301 recMdcTrackRoot->setVZ0( vz0 );
302 recMdcTrackRoot->setFiTerm( fiterm );
303
304 vector<Int_t> vecClusterId;
305 ClusterRefVec clusterRefVec = (*recMdcTrack)->getVecClusters();
306 ClusterRefVec::iterator itCluster=clusterRefVec.begin();
307 for(; itCluster!=clusterRefVec.end(); itCluster++)
308 {
309 Int_t clusterId= (*itCluster)->getclusterid();
310 vecClusterId.push_back(clusterId);
311 }
312 recMdcTrackRoot->setVecClusterId(vecClusterId);
313 //cout<<"recMdcTrackRoot set a vecClusterId with size "<<vecClusterId.size()<<endl;
314
315 recEvt->addRecMdcTrack(recMdcTrackRoot);
316 }
317
318
319 return StatusCode::SUCCESS;
320}
321#endif
Double_t x[10]
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
SmartRefVector< RecCgemCluster > ClusterRefVec
Definition: RecMdcTrack.h:28
ObjectVector< RecMdcTrack > RecMdcTrackCol
Definition: RecMdcTrack.h:102
SmartRefVector< RecMdcHit > HitRefVec
Definition: RecMdcTrack.h:26
IMessageSvc * msgSvc()
void setPxy(const double pxy)
Definition: DstMdcTrack.h:86
void setTrackId(const int trackId)
Definition: DstMdcTrack.h:84
void setPy(const double py)
Definition: DstMdcTrack.h:88
void setZ(const double z)
Definition: DstMdcTrack.h:95
void setNster(const int ns)
Definition: DstMdcTrack.h:100
void setX(const double x)
Definition: DstMdcTrack.h:93
void setError(double err[15])
void setNdof(const int ndof)
Definition: DstMdcTrack.h:99
void setTheta(const double theta)
Definition: DstMdcTrack.h:91
void setStat(const int stat)
Definition: DstMdcTrack.h:97
void setNlayer(const int nlayer)
Definition: DstMdcTrack.h:103
void setP(const double p)
Definition: DstMdcTrack.h:90
void setHelix(double helix[5])
void setR(const double r)
Definition: DstMdcTrack.h:96
void setCharge(const int charge)
Definition: DstMdcTrack.h:85
void setY(const double y)
Definition: DstMdcTrack.h:94
void setChi2(const double chi)
Definition: DstMdcTrack.h:98
void setPhi(const double phi)
Definition: DstMdcTrack.h:92
void setPz(const double pz)
Definition: DstMdcTrack.h:89
void setPx(const double px)
Definition: DstMdcTrack.h:87
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
int getclusterid(void) const
RecMdcTrackCnv(ISvcLocator *svc)
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
const HitRefVec getVecHits(void) const
Definition: RecMdcTrack.h:67
void setVecClusters(ClusterRefVec vecclusters)
Definition: RecMdcTrack.cxx:86
void setVZ0(double z0)
Definition: RecMdcTrack.h:76
void setVY0(double y0)
Definition: RecMdcTrack.h:75
void setVecHits(HitRefVec vechits)
Definition: RecMdcTrack.cxx:80
void setNhits(int nhits)
Definition: RecMdcTrack.h:78
void setFiTerm(double fiterm)
Definition: RecMdcTrack.h:77
void setVX0(double x0)
Definition: RecMdcTrack.h:74
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 x() const
void setVZ0(Double_t vz0)
Definition: TRecMdcTrack.h:67
const Double_t phi() const
const Double_t pz() const
void setStat(const Int_t stat)
Definition: TRecMdcTrack.h:51
void setVX0(Double_t vx0)
Definition: TRecMdcTrack.h:65
void setNdof(const Int_t ndof)
Definition: TRecMdcTrack.h:53
const Double_t z() const
const Int_t nster() const
Definition: TRecMdcTrack.h:36
const Double_t vz0(void) const
Definition: TRecMdcTrack.h:43
void setErr(const Double_t er[15])
Definition: TRecMdcTrack.h:55
void setHelix(const Double_t helix[5])
Definition: TRecMdcTrack.h:48
const Double_t p() const
const Double_t px() const
const Int_t nhits() const
Definition: TRecMdcTrack.h:35
const Double_t chi2() const
Definition: TRecMdcTrack.h:32
void setNhits(const Int_t nh)
Definition: TRecMdcTrack.h:59
const Int_t trackId() const
Definition: TRecMdcTrack.h:17
void setNster(const Int_t ns)
Definition: TRecMdcTrack.h:60
const Double_t y() const
void setNlayer(const Int_t nlayer)
Definition: TRecMdcTrack.h:61
void setChi2(const Double_t chi)
Definition: TRecMdcTrack.h:52
void setVecClusterId(vector< Int_t > &vecCluId)
Definition: TRecMdcTrack.h:63
const Int_t stat() const
Definition: TRecMdcTrack.h:31
const Double_t vy0(void) const
Definition: TRecMdcTrack.h:42
const Double_t fiTerm(void) const
Definition: TRecMdcTrack.h:44
void setTrackId(const Int_t trackId)
Definition: TRecMdcTrack.h:47
const Double_t pxy() const
const Double_t err(Int_t i) const
Definition: TRecMdcTrack.h:34
const Int_t ndof() const
Definition: TRecMdcTrack.h:33
const Double_t theta() const
void setFiTerm(Double_t fiterm)
Definition: TRecMdcTrack.h:68
vector< Int_t > vecClusterId() const
Definition: TRecMdcTrack.h:39
const Double_t r() const
const Int_t nlayer() const
Definition: TRecMdcTrack.h:37
void setVY0(Double_t vy0)
Definition: TRecMdcTrack.h:66
const Int_t charge() const
const Double_t vx0(void) const
Definition: TRecMdcTrack.h:41
const Double_t py() const
const Double_t helix(Int_t i) const
Definition: TRecMdcTrack.h:18
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
Definition: commonData.h:238
_EXTERN_ std::string Event
Definition: EventModel.h:90
#define ns(x)
Definition: xmltok.c:1504