1#ifndef CgemKalTrackCnv_CXX
2#define CgemKalTrackCnv_CXX 1
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/DataObject.h"
6#include "GaudiKernel/ObjectVector.h"
8#include "TClonesArray.h"
10#include "EventModel/EventModel.h"
11#include "DstEvent/DstEvent.h"
12#include "DstEvent/DstCgemKalTrack.h"
13#include "CgemRecEvent/RecCgemKalTrack.h"
14#include "RootEventData/TCgemKalTrack.h"
15#include "RootEventData/TDstEvent.h"
17#include "RootCnvSvc/Dst/DstCnv.h"
18#include "RootCnvSvc/Dst/CgemKalTrackCnv.h"
19#include "RootCnvSvc/RootAddress.h"
21#include "CLHEP/Matrix/Vector.h"
22#include "CLHEP/Matrix/SymMatrix.h"
23#include "CLHEP/Vector/ThreeVector.h"
24#include "CLHEP/Geometry/Point3D.h"
29using CLHEP::HepVector;
30using CLHEP::HepSymMatrix;
37 MsgStream log(
msgSvc(),
"CgemKalTrackCnv");
46 MsgStream log(
msgSvc(),
"CgemKalTrackCnv");
47 log << MSG::DEBUG <<
"CgemKalTrackCnv::TObjectToDataObject" << endreq;
48 StatusCode sc=StatusCode::SUCCESS;
52 refpObject=cgemKalTrackTdsCol;
55 if (!m_cgemKalTrackCol)
return sc;
56 TIter cgemKalTrackIter(m_cgemKalTrackCol);
58 while ((cgemKalTrackRoot = (
TCgemKalTrack*)cgemKalTrackIter.Next())) {
59 std::vector<HepVector> zhelixs;
60 std::vector<HepSymMatrix> zerrors;
61 std::vector<HepPoint3D> pocas;
62 std::vector<HepVector> fhelixs;
63 std::vector<HepSymMatrix> ferrors;
66 HepSymMatrix zerror(5);
69 HepVector zhelix_e(5);
70 HepSymMatrix zerror_e(5);
73 HepVector zhelix_mu(5);
74 HepSymMatrix zerror_mu(5);
77 HepVector zhelix_k(5);
78 HepSymMatrix zerror_k(5);
81 HepVector zhelix_p(5);
82 HepSymMatrix zerror_p(5);
86 HepSymMatrix ferror(5);
88 HepVector fhelix_e(5);
89 HepSymMatrix ferror_e(5);
91 HepVector fhelix_mu(5);
92 HepSymMatrix ferror_mu(5);
94 HepVector fhelix_k(5);
95 HepSymMatrix ferror_k(5);
97 HepVector fhelix_p(5);
98 HepSymMatrix ferror_p(5);
114 log<<MSG::DEBUG<<
"T to DST, poca: "<<poca<<endreq;
116 for (
int i=0; i<5; i++){
117 zhelix[i] = cgemKalTrackRoot->
getZHelix(i);
118 zhelix_e[i] = cgemKalTrackRoot->
getZHelixE(i);
120 zhelix_k[i] = cgemKalTrackRoot->
getZHelixK(i);
121 zhelix_p[i] = cgemKalTrackRoot->
getZHelixP(i);
123 fhelix[i] = cgemKalTrackRoot->
getFHelix(i);
124 fhelix_e[i] = cgemKalTrackRoot->
getFHelixE(i);
126 fhelix_k[i] = cgemKalTrackRoot->
getFHelixK(i);
127 fhelix_p[i] = cgemKalTrackRoot->
getFHelixP(i);
129 for (
int j=0; j<=i; j++){
130 zerror[i][j] = cgemKalTrackRoot->
getZError(i,j);
131 zerror_e[i][j] = cgemKalTrackRoot->
getZErrorE(i,j);
132 zerror_mu[i][j] = cgemKalTrackRoot->
getZErrorMu(i,j);
133 zerror_k[i][j] = cgemKalTrackRoot->
getZErrorK(i,j);
134 zerror_p[i][j] = cgemKalTrackRoot->
getZErrorP(i,j);
136 zerror[j][i] = zerror[i][j];
137 zerror_e[j][i] = zerror_e[i][j];
138 zerror_mu[j][i] = zerror_mu[i][j];
139 zerror_k[j][i] = zerror_k[i][j];
140 zerror_p[j][i] = zerror_p[i][j];
142 ferror[i][j] = cgemKalTrackRoot->
getFError(i,j);
143 ferror_e[i][j] = cgemKalTrackRoot->
getFErrorE(i,j);
144 ferror_mu[i][j] = cgemKalTrackRoot->
getFErrorMu(i,j);
145 ferror_k[i][j] = cgemKalTrackRoot->
getFErrorK(i,j);
146 ferror_p[i][j] = cgemKalTrackRoot->
getFErrorP(i,j);
148 ferror[j][i] = ferror[i][j];
149 ferror_e[j][i] = ferror_e[i][j];
150 ferror_mu[j][i] = ferror_mu[i][j];
151 ferror_k[j][i] = ferror_k[i][j];
152 ferror_p[j][i] = ferror_p[i][j];
157 double dr = zhelix[0];
158 double phi0 = zhelix[1];
159 double kappa = zhelix[2];
160 double dz = zhelix[3];
161 double tanl = zhelix[4];
162 poca[0]=dr*
cos(phi0);
163 poca[1]=dr*
sin(phi0);
171 poca_e[0]=dr*
cos(phi0);
172 poca_e[1]=dr*
sin(phi0);
177 kappa = zhelix_mu[2];
180 poca_mu[0]=dr*
cos(phi0);
181 poca_mu[1]=dr*
sin(phi0);
189 poca_k[0]=dr*
cos(phi0);
190 poca_k[1]=dr*
sin(phi0);
198 poca_p[0]=dr*
cos(phi0);
199 poca_p[1]=dr*
sin(phi0);
203 log<<MSG::DEBUG<<
"T to DST, zhelix: "<<zhelix<<endreq;
204 log<<MSG::DEBUG<<
"T to DST, zerror: "<<zerror<<endreq;
206 zhelixs.push_back(zhelix_e);
207 zhelixs.push_back(zhelix_mu);
208 zhelixs.push_back(zhelix);
209 zhelixs.push_back(zhelix_k);
210 zhelixs.push_back(zhelix_p);
211 zerrors.push_back(zerror_e);
212 zerrors.push_back(zerror_mu);
213 zerrors.push_back(zerror);
214 zerrors.push_back(zerror_k);
215 zerrors.push_back(zerror_p);
217 fhelixs.push_back(fhelix_e);
218 fhelixs.push_back(fhelix_mu);
219 fhelixs.push_back(fhelix);
220 fhelixs.push_back(fhelix_k);
221 fhelixs.push_back(fhelix_p);
222 ferrors.push_back(ferror_e);
223 ferrors.push_back(ferror_mu);
224 ferrors.push_back(ferror);
225 ferrors.push_back(ferror_k);
226 ferrors.push_back(ferror_p);
228 pocas.push_back(poca_e);
229 pocas.push_back(poca_mu);
230 pocas.push_back(poca);
231 pocas.push_back(poca_k);
232 pocas.push_back(poca_p);
234 for(
int m=0; m<5; m++){
236 double pxy(0.),px(0.),py(0.),pz(0.),ptot(0.),dr(0.),phi0(0.),kappa(0.),dz(0.),tanl(0.),
x(0.),y(0.),z(0.),vx0(0.),vy0(0.),vz0(0.);
238 phi0 = zhelixs[m][1];
239 kappa = zhelixs[m][2];
241 tanl = zhelixs[m][4];
253 if (kappa > 0.0000000001)
255 else if (kappa < -0.0000000001)
260 if(kappa!=0) pxy = 1.0/fabs(kappa);
263 px = pxy * (-
sin(phi0));
264 py = pxy *
cos(phi0);
266 ptot = sqrt(px*px+py*py+pz*pz);
269 cgemKalTrackTds->
setPxy(pxy,m);
270 cgemKalTrackTds->
setPx(px,m);
271 cgemKalTrackTds->
setPy(py,m);
272 cgemKalTrackTds->
setPz(pz,m);
273 cgemKalTrackTds->
setP(ptot,m);
274 cgemKalTrackTds->
setTheta(acos(pz/ptot),m);
275 cgemKalTrackTds->
setPhi(atan2(py,px),m);
276 cgemKalTrackTds->
setX(
x,m);
277 cgemKalTrackTds->
setY(y,m);
278 cgemKalTrackTds->
setZ(z,m);
279 cgemKalTrackTds->
setR(sqrt(
x*
x+y*y),m);
284 cgemKalTrackTds->
setNdf(cgemKalTrackRoot->
getNdf(m),0,m);
289 for(
int jj=0; jj<5; jj++){
290 cgemKalTrackTds->
setZHelix(zhelixs[jj],jj);
291 cgemKalTrackTds->
setZError(zerrors[jj],jj);
292 cgemKalTrackTds->
setFHelix(fhelixs[jj],jj);
293 cgemKalTrackTds->
setFError(ferrors[jj],jj);
294 cgemKalTrackTds->
setPoca(pocas[jj],jj);
297 cgemKalTrackTdsCol->push_back(cgemKalTrackTds);
300 delete m_cgemKalTrackCol;
301 m_cgemKalTrackCol = 0;
302 return StatusCode::SUCCESS;
307 MsgStream log(
msgSvc(),
"CgemKalTrackCnv");
308 log << MSG::DEBUG <<
"CgemKalTrackCnv::DataObjectToTObject" << endreq;
309 StatusCode sc=StatusCode::SUCCESS;
313 if (!cgemKalTrackColTds) {
314 log << MSG::ERROR <<
"Could not downcast to DstCgemKalTrackCol" << endreq;
315 return StatusCode::FAILURE;
321 log << MSG::ERROR <<
"Could not get ReconEvent in TDS " << endreq;
322 return StatusCode::FAILURE;
327 log << MSG::ERROR <<
"CgemKalTrackCnv:Could not downcast to TDS Dst Event" << endreq;
329 IOpaqueAddress *addr;
336 if (!m_cgemKalTrackCol)
return sc;
339 DstCgemKalTrackCol::const_iterator cgemKalTrackTds;
341 for (cgemKalTrackTds = cgemKalTrackColTds->begin(); cgemKalTrackTds != cgemKalTrackColTds->end(); cgemKalTrackTds++) {
347 Double_t zerror[5][5];
350 Double_t zhelix_e[5];
351 Double_t zerror_e[5][5];
354 Double_t zhelix_mu[5];
355 Double_t zerror_mu[5][5];
358 Double_t zhelix_k[5];
359 Double_t zerror_k[5][5];
362 Double_t zhelix_p[5];
363 Double_t zerror_p[5][5];
366 Double_t ferror[5][5];
367 Double_t fhelix_e[5];
368 Double_t ferror_e[5][5];
369 Double_t fhelix_mu[5];
370 Double_t ferror_mu[5][5];
371 Double_t fhelix_k[5];
372 Double_t ferror_k[5][5];
373 Double_t fhelix_p[5];
374 Double_t ferror_p[5][5];
380 for(
int k=0; k<5; k++){
381 cgemKalTrackRoot->
setStat((*cgemKalTrackTds)->getStat(k),k);
383 cgemKalTrackRoot->
setChisq((*cgemKalTrackTds)->getChisq(k),k);
384 cgemKalTrackRoot->
setNdf((*cgemKalTrackTds)->getNdf(k),k);
385 cgemKalTrackRoot->
setFirstLayer((*cgemKalTrackTds)->getFirstLayer(k),k);
386 cgemKalTrackRoot->
setLastLayer((*cgemKalTrackTds)->getLastLayer(k),k);
390 HepVector h_zhelix = (*cgemKalTrackTds)->getZHelix(2);
391 HepSymMatrix h_zerror = (*cgemKalTrackTds)->getZError(2);
394 HepVector h_zhelix_e = (*cgemKalTrackTds)->getZHelix(0);
395 HepSymMatrix h_zerror_e = (*cgemKalTrackTds)->getZError(0);
398 HepVector h_zhelix_mu = (*cgemKalTrackTds)->getZHelix(1);
399 HepSymMatrix h_zerror_mu = (*cgemKalTrackTds)->getZError(1);
402 HepVector h_zhelix_k = (*cgemKalTrackTds)->getZHelix(3);
403 HepSymMatrix h_zerror_k = (*cgemKalTrackTds)->getZError(3);
406 HepVector h_zhelix_p = (*cgemKalTrackTds)->getZHelix(4);
407 HepSymMatrix h_zerror_p = (*cgemKalTrackTds)->getZError(4);
409 HepVector h_fhelix = (*cgemKalTrackTds)->getFHelix(2);
410 HepSymMatrix h_ferror = (*cgemKalTrackTds)->getFError(2);
411 HepVector h_fhelix_e = (*cgemKalTrackTds)->getFHelix(0);
412 HepSymMatrix h_ferror_e = (*cgemKalTrackTds)->getFError(0);
413 HepVector h_fhelix_mu = (*cgemKalTrackTds)->getFHelix(1);
414 HepSymMatrix h_ferror_mu = (*cgemKalTrackTds)->getFError(1);
415 HepVector h_fhelix_k = (*cgemKalTrackTds)->getFHelix(3);
416 HepSymMatrix h_ferror_k = (*cgemKalTrackTds)->getFError(3);
417 HepVector h_fhelix_p = (*cgemKalTrackTds)->getFHelix(4);
418 HepSymMatrix h_ferror_p = (*cgemKalTrackTds)->getFError(4);
420 cgemKalTrackRoot->
setTrackId((*cgemKalTrackTds)->getTrackId());
432 for (
int i=0; i<5; i++){
433 zhelix[i] = h_zhelix[i];
434 zhelix_e[i] = h_zhelix_e[i];
435 zhelix_mu[i] = h_zhelix_mu[i];
436 zhelix_p[i] = h_zhelix_p[i];
437 zhelix_k[i] = h_zhelix_k[i];
438 fhelix[i] = h_fhelix[i];
439 fhelix_e[i] = h_fhelix_e[i];
440 fhelix_mu[i] = h_fhelix_mu[i];
441 fhelix_p[i] = h_fhelix_p[i];
442 fhelix_k[i] = h_fhelix_k[i];
443 for (
int j=0; j<=i; j++){
444 zerror[i][j] = h_zerror[i][j];
445 zerror_e[i][j] = h_zerror_e[i][j];
446 zerror_mu[i][j] = h_zerror_mu[i][j];
447 zerror_p[i][j] = h_zerror_p[i][j];
448 zerror_k[i][j] = h_zerror_k[i][j];
449 zerror[j][i] = h_zerror[i][j];
450 zerror_e[j][i] = h_zerror_e[i][j];
451 zerror_mu[j][i] = h_zerror_mu[i][j];
452 zerror_p[j][i] = h_zerror_p[i][j];
453 zerror_k[j][i] = h_zerror_k[i][j];
454 ferror[i][j] = h_ferror[i][j];
455 ferror_e[i][j] = h_ferror_e[i][j];
456 ferror_mu[i][j] = h_ferror_mu[i][j];
457 ferror_p[i][j] = h_ferror_p[i][j];
458 ferror_k[i][j] = h_ferror_k[i][j];
459 ferror[j][i] = h_ferror[i][j];
460 ferror_e[j][i] = h_ferror_e[i][j];
461 ferror_mu[j][i] = h_ferror_mu[i][j];
462 ferror_p[j][i] = h_ferror_p[i][j];
463 ferror_k[j][i] = h_ferror_k[i][j];
505 return StatusCode::SUCCESS;
ObjectVector< DstCgemKalTrack > DstCgemKalTrackCol
double sin(const BesAngle a)
double cos(const BesAngle a)
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
CgemKalTrackCnv(ISvcLocator *svc)
void setStat(int stat, int i, int pid)
void setCharge(const int charge, const int pid)
void setChisq(double chisq, int i, int pid)
void setZ(const double z, const int pid)
void setX(const double x, const int pid)
void setPy(const double py, const int pid)
void setR(const double r, const int pid)
void setPoca(const HepPoint3D &poca, const int pid)
void setP(const double p, const int pid)
void setTrackId(int trackId)
void setPz(const double pz, const int pid)
void setZHelix(const HepVector &helix, const int pid)
void setY(const double y, const int pid)
void setTheta(const double theta, const int pid)
void setPhi(const double phi, const int pid)
void setNdf(int ndf, int i, int pid)
void setZError(const HepSymMatrix &error, const int pid)
void setPxy(const double pxy, const int pid)
void setFError(const HepSymMatrix &ferror, const int pid)
void setPx(const double px, const int pid)
void setFHelix(const HepVector &fhelix, const int pid)
static TDstEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
int getStat(int i, int pid) const
Definition of a Root address, derived from IOpaqueAddress.
Base class for all Root Converters.
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.
void setZErrorK(const Double_t zerror_k[5][5])
void setTrackId(const Int_t trackId)
void setZHelix(const Double_t zhelix[5])
Double_t getZHelixE(Int_t i) const
Int_t getNdf(const Int_t pid) const
void setFErrorK(const Double_t ferror_k[5][5])
Double_t getZErrorMu(Int_t i, Int_t j) const
Double_t getZErrorP(Int_t i, Int_t j) const
void setZErrorP(const Double_t zerror_p[5][5])
void setFHelixK(const Double_t fhelix_k[5])
void setFHelixMu(const Double_t fhelix_mu[5])
void setStat(const Int_t stat, const Int_t pid)
Double_t getFHelixE(Int_t i) const
void setFHelixP(const Double_t fhelix_p[5])
void setFError(const Double_t ferror[5][5])
Double_t getZHelixMu(Int_t i) const
Double_t getFHelixMu(Int_t i) const
void setZHelixK(const Double_t zhelix_k[5])
void setFirstLayer(const Int_t fL, const Int_t pid)
Double_t getFErrorE(Int_t i, Int_t j) const
void setFHelix(const Double_t fhelix[5])
void setZHelixP(const Double_t zhelix_p[5])
Double_t getChisq(const Int_t pid) const
Double_t getZErrorK(Int_t i, Int_t j) const
Double_t getZHelixK(Int_t i) const
void setZHelixMu(const Double_t zhelix_mu[5])
Double_t getFHelix(Int_t i) const
void setNdf(const Int_t ndf, const Int_t pid)
void setLastLayer(const Int_t lL, const Int_t pid)
Int_t getStat2(const Int_t pid) const
void setFErrorP(const Double_t ferror_p[5][5])
void setZErrorMu(const Double_t zerror_mu[5][5])
Double_t getFErrorK(Int_t i, Int_t j) const
Double_t getFErrorMu(Int_t i, Int_t j) const
Int_t getStat(const Int_t pid) const
Double_t getFHelixK(Int_t i) const
void setZHelixE(const Double_t zhelix_e[5])
void setZErrorE(const Double_t zerror_e[5][5])
void setFHelixE(const Double_t fhelix_e[5])
Double_t getZHelixP(Int_t i) const
void setFErrorMu(const Double_t ferror_mu[5][5])
void setStat2(const Int_t stat, const Int_t pid)
Double_t getZHelix(Int_t i) const
void setZError(const Double_t zerror[5][5])
Double_t getZErrorE(Int_t i, Int_t j) const
void setChisq(const Double_t chisq, const Int_t pid)
Double_t getFErrorP(Int_t i, Int_t j) const
Double_t getZError(Int_t i, Int_t j) const
Double_t getFHelixP(Int_t i) const
void setFErrorE(const Double_t ferror_e[5][5])
Double_t getFError(Int_t i, Int_t j) const
const TObjArray * getCgemKalTrackCol() const
void addCgemKalTrack(TCgemKalTrack *Track)
void clearCgemKalTrackCol()
static std::map< const TObject *, const DstCgemKalTrack * > m_rootCgemKalTrackMap
_EXTERN_ std::string Event