BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtRecVeeVertexCnv.cxx
Go to the documentation of this file.
1#include <algorithm>
2#include "GaudiKernel/MsgStream.h"
3
7
10
14
15#include "CLHEP/Matrix/Vector.h"
16#include "CLHEP/Matrix/SymMatrix.h"
17using CLHEP::HepVector;
18using CLHEP::HepSymMatrix;
19
21 : RootEventBaseCnv(classID(), svc)
22{
23 m_rootBranchname = "m_evtRecVeeVertexCol";
24 m_adresses.push_back(&m_evtRecVeeVertexCol);
25 m_evtRecVeeVertexCol = 0;
26}
27
28StatusCode EvtRecVeeVertexCnv::TObjectToDataObject(DataObject*& refpObject) {
29 // creation of TDS object from root object
30 MsgStream log(msgSvc(), "EvtRecVeeVertexCnv");
31 log << MSG::DEBUG << "EvtRecVeeVertexCnv::TObjectToDataObject" << endreq;
32
33 // create the TDS location for the EvtRecVeeVertex Collection
34 EvtRecVeeVertexCol* evtRecVeeVertexCol = new EvtRecVeeVertexCol;
35 refpObject = evtRecVeeVertexCol;
36
37 if ( ! m_evtRecVeeVertexCol ) return StatusCode::SUCCESS;
38
39 IDataProviderSvc* dataSvc = 0;
40 StatusCode sc = serviceLocator()->getService("EventDataSvc",
41 IDataProviderSvc::interfaceID(), (IInterface*&)dataSvc);
42 if ( sc.isFailure() ) {
43 log << MSG::FATAL << "Could not get EventDataSvc in EvtRecVeeVertexCnv" << endreq;
44 return sc;
45 }
46
47 SmartDataPtr<EvtRecTrackCol> evtRecTrackCol(dataSvc, EventModel::EvtRec::EvtRecTrackCol);
48 if ( ! evtRecTrackCol) {
49 log << MSG::INFO << "Could not find EvtRecTrackCol" << endreq;
50 }
51
52 // convert
53 TIter evtRecVeeVertexIter(m_evtRecVeeVertexCol);
54 TEvtRecVeeVertex* evtRecVeeVertexRoot = 0;
55 while ( (evtRecVeeVertexRoot = (TEvtRecVeeVertex*)evtRecVeeVertexIter.Next() ) ) {
56 EvtRecVeeVertex* evtRecVeeVertex = new EvtRecVeeVertex();
57 m_common.m_rootEvtRecVeeVertexMap[evtRecVeeVertexRoot] = evtRecVeeVertex;
58 // set ....
59 evtRecVeeVertex->setVertexId( evtRecVeeVertexRoot->vertexId() );
60 evtRecVeeVertex->setVertexType( evtRecVeeVertexRoot->vertexType() );
61 evtRecVeeVertex->setChi2( evtRecVeeVertexRoot->chi2() );
62 evtRecVeeVertex->setNdof( evtRecVeeVertexRoot->ndof() );
63 evtRecVeeVertex->setMass( evtRecVeeVertexRoot->mass() );
64
65 HepVector wTrackParameter(7, 0);
66 for (int i = 0; i < 7; i++) {
67 wTrackParameter[i] = evtRecVeeVertexRoot->w(i);
68 }
69 evtRecVeeVertex->setW( wTrackParameter );
70
71 HepSymMatrix EwTrackParameter(7, 0);
72 int i = 0;
73 for (int j = 0; j < 7; j++) {
74 for (int k = j; k < 7; k++) {
75 EwTrackParameter[j][k] = EwTrackParameter[k][j] = evtRecVeeVertexRoot->Ew(i);
76 i++;
77 }
78 }
79 evtRecVeeVertex->setEw( EwTrackParameter );
80
81 std::pair<int, int> pairId;
82 pairId.first = evtRecVeeVertexRoot->pair(0);
83 pairId.second = evtRecVeeVertexRoot->pair(1);
84 evtRecVeeVertex->setPair( pairId );
85 evtRecVeeVertex->setNCharge( evtRecVeeVertexRoot->nCharge() );
86 evtRecVeeVertex->setNTracks( evtRecVeeVertexRoot->nTracks() );
87 int evtRecTrackId0 = evtRecVeeVertexRoot->daughter(0);
88 if ( evtRecTrackId0 >= 0) {
89 evtRecVeeVertex->addDaughter(
90 dynamic_cast<EvtRecTrack*>(evtRecTrackCol->containedObject(evtRecTrackId0)), 0
91 );
92 }
93 int evtRecTrackId1 = evtRecVeeVertexRoot->daughter(1);
94 if ( evtRecTrackId1 >= 0) {
95 evtRecVeeVertex->addDaughter(
96 dynamic_cast<EvtRecTrack*>(evtRecTrackCol->containedObject(evtRecTrackId1)), 1
97 );
98 }
99
100 evtRecVeeVertexCol->push_back(evtRecVeeVertex);
101 }
102
103 delete m_evtRecVeeVertexCol;
104 m_evtRecVeeVertexCol = 0;
105 return StatusCode::SUCCESS;
106}
107
108StatusCode EvtRecVeeVertexCnv::DataObjectToTObject(DataObject* obj, RootAddress* rootaddr) {
109 MsgStream log(msgSvc(), "EvtRecVeeVertexCnv");
110 log << MSG::DEBUG << "EvtRecVeeVertexCnv::DataObjectToTObject" << endreq;
111
112 EvtRecVeeVertexCol* evtRecVeeVertexCol = dynamic_cast<EvtRecVeeVertexCol*> (obj);
113 if ( ! evtRecVeeVertexCol ) {
114 log << MSG::ERROR << "Could not downcast to EvtRecVeeVertexCol" << endreq;
115 return StatusCode::FAILURE;
116 }
117
118 DataObject* evt;
119 m_eds->findObject(EventModel::EvtRec::Event, evt);
120 if ( evt == NULL ) {
121 log << MSG::ERROR << "Could not get EvtRecObject in TDS" << endreq;
122 return StatusCode::FAILURE;
123 }
124 EvtRecObject* devtTds = dynamic_cast<EvtRecObject*> (evt);
125 if ( ! devtTds ) {
126 log << MSG::ERROR << "EvtRecVeeVertexCnv: Could not downcast to TDS EvtRecObject" << endreq;
127 }
128
129 IOpaqueAddress *addr;
130 m_cnvSvc->getEvtRecCnv()->createRep(evt, addr);
132
133 const TObjArray* m_evtRecVeeVertexCol = recEvt->getEvtRecVeeVertexCol();
134 if ( ! m_evtRecVeeVertexCol ) return StatusCode::SUCCESS;
135
136 IDataProviderSvc* dataSvc = 0;
137 StatusCode sc = serviceLocator()->getService("EventDataSvc",
138 IDataProviderSvc::interfaceID(), (IInterface*&)dataSvc);
139 if ( sc.isFailure() ) {
140 log << MSG::FATAL << "Could not get EventDataSvc in EvtRecVeeVertexCnv" << endreq;
141 return sc;
142 }
143
144 EvtRecTrackCol::iterator evtRecTrackColbegin, evtRecTrackColend;
145
146 SmartDataPtr<EvtRecTrackCol> evtRecTrackCol(dataSvc, EventModel::EvtRec::EvtRecTrackCol);
147 if ( ! evtRecTrackCol) {
148 log << MSG::INFO << "Could not find EvtRecTrackCol" << endreq;
149 }
150 else {
151 evtRecTrackColbegin = evtRecTrackCol->begin();
152 evtRecTrackColend = evtRecTrackCol->end();
153 }
154
155 // convert
156 recEvt->clearEvtRecVeeVertexCol();
157 EvtRecVeeVertexCol::const_iterator evtRecVeeVertex = evtRecVeeVertexCol->begin();
158
159 for ( ; evtRecVeeVertex != evtRecVeeVertexCol->end(); evtRecVeeVertex++) {
160 EvtRecVeeVertex* ptr = *evtRecVeeVertex;
161 TEvtRecVeeVertex* evtRecVeeVertexRoot = new TEvtRecVeeVertex();
162 // set ...
163 evtRecVeeVertexRoot->setVertexId( ptr->vertexId() );
164 evtRecVeeVertexRoot->setVertexType( ptr->vertexType() );
165 evtRecVeeVertexRoot->setChi2( ptr->chi2() );
166 evtRecVeeVertexRoot->setNdof( ptr->ndof() );
167 evtRecVeeVertexRoot->setMass( ptr->mass() );
168
169 double wTrackParameter[7];
170 for (int i = 0; i < 7; i++) {
171 wTrackParameter[i] = ptr->w()[i];
172 }
173 evtRecVeeVertexRoot->setW( wTrackParameter );
174 double EwTrackParameter[28];
175 int i = 0;
176 for (int j = 0; j < 7; j++) {
177 for (int k = j; k < 7; k++) {
178 EwTrackParameter[i] = ptr->Ew()[j][k];
179 i++;
180 }
181 }
182 assert(i == 28);
183 evtRecVeeVertexRoot->setEw( EwTrackParameter );
184 int pairId[2];
185 pairId[0] = ptr->pair(0);
186 pairId[1] = ptr->pair(1);
187 evtRecVeeVertexRoot->setPair( pairId );
188 evtRecVeeVertexRoot->setNCharge( ptr->nCharge() );
189 evtRecVeeVertexRoot->setNTracks( ptr->nTracks() );
190
191 int daughterId[2];
192 if ( ptr->daughter(0).target() != NULL && ptr->daughter(1).target() != NULL ) {
193 assert(evtRecTrackColbegin != evtRecTrackColend);
194 EvtRecTrackCol::iterator it0 = find(evtRecTrackColbegin,
195 evtRecTrackColend, ptr->daughter(0).target());
196 EvtRecTrackCol::iterator it1 = find(evtRecTrackColbegin,
197 evtRecTrackColend, ptr->daughter(1).target());
198 assert(it0 != evtRecTrackColend);
199 assert(it1 != evtRecTrackColend);
200 daughterId[0] = it0 - evtRecTrackColbegin;
201 daughterId[1] = it1 - evtRecTrackColbegin;
202 evtRecVeeVertexRoot->setDaughter( daughterId );
203 }
204 recEvt->addEvtRecVeeVertex(evtRecVeeVertexRoot);
205 }
206
207 return StatusCode::SUCCESS;
208}
ObjectVector< EvtRecVeeVertex > EvtRecVeeVertexCol
IMessageSvc * msgSvc()
static TEvtRecObject * getWriteObject()
Definition: EvtRecCnv.h:26
EvtRecVeeVertexCnv(ISvcLocator *svc)
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
const std::pair< int, int > & pair() const
void setVertexType(int vtxType)
void setChi2(double chi2)
int vertexType() const
SmartRef< EvtRecTrack > & daughter(int i)
void addDaughter(const SmartRef< EvtRecTrack > &track, int i)
int vertexId() const
void setEw(const HepSymMatrix &Ew)
double mass() const
void setMass(double mass)
void setNdof(int ndof)
void setNTracks(int nTracks)
void setVertexId(int vtxId)
void setPair(const std::pair< int, int > &pair)
const HepVector & w() const
int nTracks() const
int nCharge() const
double chi2() const
const HepSymMatrix & Ew() const
void setW(const HepVector &w)
int ndof() const
void setNCharge(int nCharge)
Definition of a Root address, derived from IOpaqueAddress.
Definition: RootAddress.h:21
EvtRecCnv * getEvtRecCnv()
Definition: RootCnvSvc.h:152
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.
void clearEvtRecVeeVertexCol()
Definition: TEvtRecObject.h:46
void addEvtRecVeeVertex(TEvtRecVeeVertex *veeVertex)
const TObjArray * getEvtRecVeeVertexCol() const
Definition: TEvtRecObject.h:43
Double_t chi2() const
Int_t nTracks() const
void setDaughter(Int_t daughter[2])
void setW(Double_t w[7])
void setVertexId(Int_t vtxId)
Int_t pair(Int_t i) const
Double_t w(Int_t i) const
void setPair(Int_t pair[2])
Int_t vertexType() const
Int_t nCharge() const
Int_t daughter(Int_t i) const
Int_t ndof() const
void setVertexType(Int_t vtxType)
void setEw(Double_t Ew[28])
Double_t mass() const
void setChi2(Double_t chi2)
Double_t Ew(Int_t i) const
Int_t vertexId() const
void setNTracks(Int_t nTracks)
void setNdof(Int_t ndof)
void setMass(Double_t mass)
void setNCharge(Int_t nCharge)
static std::map< const TObject *, const EvtRecVeeVertex * > m_rootEvtRecVeeVertexMap
Definition: commonData.h:250
_EXTERN_ std::string Event
Definition: EventModel.h:110
_EXTERN_ std::string EvtRecTrackCol
Definition: EventModel.h:112