BOSS 7.0.8
BESIII Offline Software System
Loading...
Searching...
No Matches
EmcTrackCnv.cxx
Go to the documentation of this file.
1#ifndef EmcTrackCnv_CXX
2#define EmcTrackCnv_CXX 1
3
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/DataObject.h"
6#include "GaudiKernel/ObjectVector.h"
7
8#include "TClonesArray.h"
9
11
12#include "DstEvent/DstEvent.h" //TDS object
13#include "DstEvent/DstEmcShower.h" //TDS object
14#include "RootEventData/TEmcTrack.h" // standard root object
16
20
21#include <vector>
22
23using namespace std;
24
25// Instantiation of a static factory class used by clients to create
26// instances of this service
27//static CnvFactory<EmcTrackCnv> s_factory;
28//const ICnvFactory& EmcTrackCnvFactory = s_factory;
29
30EmcTrackCnv::EmcTrackCnv(ISvcLocator* svc)
31: RootEventBaseCnv(classID(), svc)
32{
33 // Here we associate this converter with the /Event path on the TDS.
34 MsgStream log(msgSvc(), "EmcTrackCnv");
35 // log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
36 m_rootTreename ="Rec";
37 m_rootBranchname ="m_emcTrackCol";
38 //declareObject(EventModel::Dst::DstEmcShowerCol, objType(), m_rootTreename, m_rootBranchname);
39 m_adresses.push_back(&m_emcTrackCol);
40 m_emcTrackCol=0;
41
42}
43
44StatusCode EmcTrackCnv::TObjectToDataObject(DataObject*& refpObject) {
45 // creation of TDS object from root object
46
47 MsgStream log(msgSvc(), "EmcTrackCnv");
48 log << MSG::DEBUG << "EmcTrackCnv::TObjectToDataObject" << endreq;
49 StatusCode sc=StatusCode::SUCCESS;
50
51 // create the TDS location for the EmcTrack Collection
52 DstEmcShowerCol* emcTrackTdsCol = new DstEmcShowerCol;
53 refpObject=emcTrackTdsCol;
54
55
56 // now convert
57 if (!m_emcTrackCol) return sc;
58 TIter emcTrackIter(m_emcTrackCol);
59 TEmcTrack *emcTrackRoot = 0;
60 while ((emcTrackRoot = (TEmcTrack*)emcTrackIter.Next())) {
61 int trackId = emcTrackRoot->trackId();
62 int numHits = emcTrackRoot->numHits();
63 int status = emcTrackRoot->status();
64 int cellId = emcTrackRoot->cellId();
65 int module = emcTrackRoot->module();
66 double x = emcTrackRoot->x();
67 double y = emcTrackRoot->y();
68 double z = emcTrackRoot->z();
69 double dtheta = emcTrackRoot->dtheta();
70 double dphi = emcTrackRoot->dphi();
71 double energy = emcTrackRoot->energy();
72 double dE = emcTrackRoot->dE();
73 double eSeed = emcTrackRoot->eSeed();
74 double e3x3 = emcTrackRoot->e3x3();
75 double e5x5 = emcTrackRoot->e5x5();
76 double time = emcTrackRoot->time();
77 double secondMoment = emcTrackRoot->secondMoment();
78 double latMoment = emcTrackRoot->latMoment();
79 double a20Moment = emcTrackRoot->a20Moment();
80 double a42Moment = emcTrackRoot->a42Moment();
81
82 HepSymMatrix matrix(3);
83 matrix[0][0]=emcTrackRoot->err(0);
84 matrix[1][1]=emcTrackRoot->err(1);
85 matrix[2][2]=emcTrackRoot->err(2);
86 matrix[0][1]=emcTrackRoot->err(3);
87 matrix[0][2]=emcTrackRoot->err(4);
88 matrix[1][2]=emcTrackRoot->err(5);
89
90 DstEmcShower *emcTrackTds = new DstEmcShower();
91 m_common.m_rootEmcShowerMap[emcTrackRoot] = emcTrackTds;
92
93 emcTrackTds->setTrackId(trackId );
94 emcTrackTds->setNumHits(numHits );
95 emcTrackTds->setStatus(status );
96 emcTrackTds->setCellId( cellId );
97 emcTrackTds->setModule( module);
98 HepPoint3D pos(x,y,z);
99 emcTrackTds->setPosition(pos);
100 emcTrackTds->setEnergy( energy );
101 emcTrackTds->setDE( dE );
102 emcTrackTds->setDtheta( dtheta );
103 emcTrackTds->setDphi( dphi );
104 emcTrackTds->setESeed(eSeed);
105 emcTrackTds->setE3x3(e3x3);
106 emcTrackTds->setE5x5(e5x5);
107 emcTrackTds->setTime(time);
108 emcTrackTds->setSecondMoment(secondMoment);
109 emcTrackTds->setLatMoment(latMoment);
110 emcTrackTds->setA20Moment(a20Moment);
111 emcTrackTds->setA42Moment(a42Moment);
112 emcTrackTds->setErrorMatrix( matrix );
113
114 emcTrackTdsCol->push_back(emcTrackTds);
115 // delete emcTrackTds;
116 // emcTrackTds = NULL;
117 }
118
119 //m_emcTrackCol->Delete(); // wensp add 2005/12/30
120 delete m_emcTrackCol;
121 m_emcTrackCol = 0;
122 return StatusCode::SUCCESS;
123}
124
125StatusCode EmcTrackCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
126
127 MsgStream log(msgSvc(), "EmcTrackCnv");
128 log << MSG::DEBUG << "EmcTrackCnv::DataObjectToTObject" << endreq;
129 StatusCode sc=StatusCode::SUCCESS;
130
131 DstEmcShowerCol * emcTrackColTds=dynamic_cast<DstEmcShowerCol *> (obj);
132 if (!emcTrackColTds) {
133 log << MSG::ERROR << "Could not downcast to EmcTrackCol" << endreq;
134 return StatusCode::FAILURE;
135 }
136
137 DataObject *evt;
138 m_eds->findObject(EventModel::Dst::Event,evt);
139 if (evt==NULL) {
140 log << MSG::ERROR << "Could not get DstEvent in TDS " << endreq;
141 return StatusCode::FAILURE;
142 }
143 DstEvent * devtTds=dynamic_cast<DstEvent *> (evt);
144 if (!devtTds) {
145 log << MSG::ERROR << "EmcTrackCnv:Could not downcast to TDS DstEvent" << endreq;
146 }
147 IOpaqueAddress *addr;
148
149 m_cnvSvc->getDstCnv()->createRep(evt,addr);
151
152 const TObjArray *m_emcTrackCol = recEvt->getEmcTrackCol();
153 if (!m_emcTrackCol) return sc;
154 recEvt->clearEmcTrackCol(); //necessary in case there is I/O at the same time since array is static
155 DstEmcShowerCol::const_iterator emcTrackTds;
156
157 for (emcTrackTds = emcTrackColTds->begin(); emcTrackTds != emcTrackColTds->end(); emcTrackTds++) {
158 Int_t trackId = (*emcTrackTds)->trackId();
159 Int_t numHits = (*emcTrackTds)->numHits();
160 Int_t status =(*emcTrackTds)->status();
161 Int_t cellId =(*emcTrackTds)->cellId();
162 Int_t module =(*emcTrackTds)->module();
163 Double_t x = (*emcTrackTds)->x();
164 Double_t y = (*emcTrackTds)->y();
165 Double_t z = (*emcTrackTds)->z();
166 Double_t dtheta =(*emcTrackTds)->dtheta();
167 Double_t dphi =(*emcTrackTds)->dphi();
168 Double_t energy = (*emcTrackTds)->energy();
169 Double_t dE = (*emcTrackTds)->dE();
170 Double_t eSeed = (*emcTrackTds)->eSeed();
171 Double_t e3x3 = (*emcTrackTds)->e3x3();
172 Double_t e5x5 = (*emcTrackTds)->e5x5();
173 Double_t time = (*emcTrackTds)->time();
174 Double_t secondMoment = (*emcTrackTds)->secondMoment();
175 Double_t latMoment = (*emcTrackTds)->latMoment();
176 Double_t a20Moment = (*emcTrackTds)->a20Moment();
177 Double_t a42Moment = (*emcTrackTds)->a42Moment();
178
179 HepSymMatrix matrix = (*emcTrackTds)->errorMatrix();
180 Double_t err[6];
181 err[0] = matrix[0][0];
182 err[1] = matrix[1][1];
183 err[2] = matrix[2][2];
184 err[3] = matrix[0][1];
185 err[4] = matrix[0][2];
186 err[5] = matrix[1][2];
187
188 TEmcTrack *emcTrackRoot = new TEmcTrack();
189 //m_common.m_emcShowerMap[(*emcTrackTds)] = emcTrackRoot;
190
191 //emcTrackRoot->initialize(numHits ,status ,cellId ,module ,x ,dx,y ,dy,z ,dz,theta ,dtheta ,phi,dphi ,energy ,dE,cosx ,cosy ,cosz);
192 emcTrackRoot->setTrackId(trackId );
193 emcTrackRoot->setNumHits(numHits );
194 emcTrackRoot->setStatus(status );
195 emcTrackRoot->setCellId( cellId );
196 emcTrackRoot->setModule( module);
197 emcTrackRoot->setX( x );
198 emcTrackRoot->setY( y );
199 emcTrackRoot->setZ( z );
200 emcTrackRoot->setEnergy( energy );
201 emcTrackRoot->setDE( dE );
202 emcTrackRoot->setDtheta( dtheta );
203 emcTrackRoot->setDphi( dphi );
204 emcTrackRoot->setESeed( eSeed );
205 emcTrackRoot->setE3x3( e3x3 );
206 emcTrackRoot->setE5x5( e5x5 );
207 emcTrackRoot->setTime( time );
208 emcTrackRoot->setSecondMoment(secondMoment);
209 emcTrackRoot->setLatMoment(latMoment);
210 emcTrackRoot->setA20Moment(a20Moment);
211 emcTrackRoot->setA42Moment(a42Moment);
212 emcTrackRoot->setErr( err );
213
214 recEvt->addEmcTrack(emcTrackRoot);
215 }
216
217 return StatusCode::SUCCESS;
218}
219#endif
Double_t x[10]
Double_t time
ObjectVector< DstEmcShower > DstEmcShowerCol
Definition: DstEmcShower.h:102
************Class m_ypar INTEGER m_KeyWgt INTEGER m_KeyIHVP INTEGER m_KeyGPS INTEGER m_IsBeamPolarized INTEGER m_EvtGenInterface DOUBLE PRECISION m_Emin DOUBLE PRECISION m_sphot DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_q2 DOUBLE PRECISION m_PolBeam2 DOUBLE PRECISION m_xErrPb *COMMON c_KK2f $ !CMS energy average $ !Spin Polarization vector first beam $ !Spin Polarization vector second beam $ !Beam energy spread[GeV] $ !minimum hadronization energy[GeV] $ !input READ never touch them !$ !debug facility $ !maximum weight $ !inverse alfaQED $ !minimum real photon energy
Definition: KK2f.h:50
IMessageSvc * msgSvc()
#define NULL
static TDstEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition: DstCnv.h:36
void setDphi(double dpi)
Definition: DstEmcShower.h:66
void setE3x3(double e3x3)
Definition: DstEmcShower.h:68
void setDtheta(double dt)
Definition: DstEmcShower.h:65
void setStatus(int st)
Definition: DstEmcShower.h:59
void setNumHits(int hit)
Definition: DstEmcShower.h:58
void setSecondMoment(double secondMoment)
Definition: DstEmcShower.h:71
void setA20Moment(double a20Moment)
Definition: DstEmcShower.h:73
void setPosition(const HepPoint3D &pos)
Definition: DstEmcShower.h:62
void setDE(double de)
Definition: DstEmcShower.h:64
void setA42Moment(double a42Moment)
Definition: DstEmcShower.h:74
void setESeed(double eSeed)
Definition: DstEmcShower.h:67
void setTime(double time)
Definition: DstEmcShower.h:70
void setModule(int mod)
Definition: DstEmcShower.h:61
void setCellId(int id)
Definition: DstEmcShower.h:60
void setLatMoment(double latMoment)
Definition: DstEmcShower.h:72
void setErrorMatrix(const HepSymMatrix &error)
Definition: DstEmcShower.h:75
void setTrackId(int trackId)
Definition: DstEmcShower.h:57
void setEnergy(double e)
Definition: DstEmcShower.h:63
void setE5x5(double e5x5)
Definition: DstEmcShower.h:69
EmcTrackCnv(ISvcLocator *svc)
Definition: EmcTrackCnv.cxx:30
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
Definition: EmcTrackCnv.cxx:44
Definition of a Root address, derived from IOpaqueAddress.
Definition: RootAddress.h:21
DstCnv * getDstCnv()
Definition: RootCnvSvc.h:155
Base class for all Root Converters.
std::string m_rootTreename
each converter knows it's treename
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 addEmcTrack(TEmcTrack *Track)
Add a TkrTrack into the Emc data collection.
Definition: TDstEvent.cxx:130
const TObjArray * getEmcTrackCol() const
retrieve the whole TObjArray of EmcTrack Data
Definition: TDstEvent.h:48
void clearEmcTrackCol()
clear the whole array (necessary because of the consts-s)
Definition: TDstEvent.h:57
Double_t time() const
Definition: TEmcTrack.h:42
void setTrackId(const Int_t trackId)
Definition: TEmcTrack.h:50
void setA20Moment(const Double_t a20Moment)
Definition: TEmcTrack.h:68
Double_t a42Moment() const
Definition: TEmcTrack.h:46
void setEnergy(const Double_t e)
Definition: TEmcTrack.h:58
void setESeed(const Double_t eSeed)
Definition: TEmcTrack.h:62
void setNumHits(const Int_t hit)
Definition: TEmcTrack.h:51
void setDtheta(const Double_t dt)
Definition: TEmcTrack.h:60
Int_t trackId() const
Definition: TEmcTrack.h:19
void setX(const Double_t x)
Definition: TEmcTrack.h:55
void setErr(const Double_t err[6])
Definition: TEmcTrack.cxx:20
Double_t eSeed() const
Definition: TEmcTrack.h:39
Double_t err(Int_t i) const
Definition: TEmcTrack.h:47
void setModule(const Int_t mod)
Definition: TEmcTrack.h:54
Int_t status() const
Definition: TEmcTrack.h:21
void setSecondMoment(const Double_t secondMoment)
Definition: TEmcTrack.h:66
void setDE(const Double_t de)
Definition: TEmcTrack.h:59
Double_t energy() const
Definition: TEmcTrack.h:37
Double_t y() const
Definition: TEmcTrack.h:25
Double_t dtheta() const
Definition: TEmcTrack.h:35
void setY(const Double_t y)
Definition: TEmcTrack.h:56
Double_t e3x3() const
Definition: TEmcTrack.h:40
void setA42Moment(const Double_t a42Moment)
Definition: TEmcTrack.h:69
Double_t secondMoment() const
Definition: TEmcTrack.h:43
Int_t module() const
Definition: TEmcTrack.h:23
void setZ(const Double_t z)
Definition: TEmcTrack.h:57
Double_t x() const
Definition: TEmcTrack.h:24
Double_t a20Moment() const
Definition: TEmcTrack.h:45
Double_t z() const
Definition: TEmcTrack.h:26
Double_t dE() const
Definition: TEmcTrack.h:38
void setTime(const Double_t time)
Definition: TEmcTrack.h:65
Int_t cellId() const
Definition: TEmcTrack.h:22
void setCellId(const Int_t id)
Definition: TEmcTrack.h:53
void setE3x3(const Double_t e3x3)
Definition: TEmcTrack.h:63
Int_t numHits() const
Definition: TEmcTrack.h:20
void setE5x5(const Double_t e5x5)
Definition: TEmcTrack.h:64
Double_t e5x5() const
Definition: TEmcTrack.h:41
Double_t dphi() const
Definition: TEmcTrack.h:36
void setStatus(const Int_t st)
Definition: TEmcTrack.h:52
void setLatMoment(const Double_t latMoment)
Definition: TEmcTrack.h:67
Double_t latMoment() const
Definition: TEmcTrack.h:44
void setDphi(const Double_t dpi)
Definition: TEmcTrack.h:61
static std::map< const TObject *, const DstEmcShower * > m_rootEmcShowerMap
Definition: commonData.h:143
double y[1000]
_EXTERN_ std::string Event
Definition: EventModel.h:128