00001 #ifndef TofTrackCnv_CXX
00002 #define TofTrackCnv_CXX 1
00003
00004 #include "GaudiKernel/MsgStream.h"
00005 #include "GaudiKernel/DataObject.h"
00006 #include "GaudiKernel/ObjectVector.h"
00007
00008 #include "TClonesArray.h"
00009
00010 #include "EventModel/EventModel.h"
00011
00012 #include "DstEvent/DstEvent.h"
00013 #include "DstEvent/DstTofTrack.h"
00014 #include "DstEvent/TofHitStatus.h"
00015 #include "RootEventData/TTofTrack.h"
00016 #include "RootEventData/TDstEvent.h"
00017
00018 #include "RootCnvSvc/Dst/DstCnv.h"
00019 #include "RootCnvSvc/Dst/TofTrackCnv.h"
00020 #include "RootCnvSvc/RootAddress.h"
00021
00022 #include <vector>
00023
00024 using namespace std;
00025
00026
00027
00028
00029
00030
00031 TofTrackCnv::TofTrackCnv(ISvcLocator* svc)
00032 : RootEventBaseCnv(classID(), svc)
00033 {
00034
00035 MsgStream log(msgSvc(), "TofTrackCnv");
00036
00037 m_rootBranchname ="m_tofTrackCol";
00038
00039 m_adresses.push_back(&m_tofTrackCol);
00040 m_tofTrackCol=0;
00041 }
00042
00043 StatusCode TofTrackCnv::TObjectToDataObject(DataObject*& refpObject) {
00044
00045
00046 MsgStream log(msgSvc(), "TofTrackCnv");
00047 log << MSG::DEBUG << "TofTrackCnv::TObjectToDataObject" << endreq;
00048 StatusCode sc=StatusCode::SUCCESS;
00049
00050 DstTofTrackCol* tofTrackTdsCol = new DstTofTrackCol;
00051 refpObject=tofTrackTdsCol;
00052
00053
00054
00055 if (!m_tofTrackCol) return sc;
00056 TIter tofTrackIter(m_tofTrackCol);
00057 TTofTrack *tofTrackRoot = 0;
00058 while ((tofTrackRoot = (TTofTrack*)tofTrackIter.Next())) {
00059
00060 int tofTrackID = tofTrackRoot->tofTrackID();
00061 int trackID = tofTrackRoot->trackID();
00062 int tofID = tofTrackRoot->tofID();
00063 unsigned int status = tofTrackRoot->status();
00064 double path = tofTrackRoot->path();
00065 double zrhit = tofTrackRoot->zrhit();
00066 double ph = tofTrackRoot->ph();
00067 double tof = tofTrackRoot->tof();
00068 double errtof = tofTrackRoot->errtof();
00069 double beta = tofTrackRoot->beta();
00070 double texpElectron = tofTrackRoot->texpElectron();
00071 double texpMuon = tofTrackRoot->texpMuon();
00072 double texpPion = tofTrackRoot->texpPion();
00073 double texpKaon = tofTrackRoot->texpKaon();
00074 double texpProton = tofTrackRoot->texpProton();
00075 double toffsetElectron = tofTrackRoot->toffsetElectron();
00076 double toffsetMuon = tofTrackRoot->toffsetMuon();
00077 double toffsetPion = tofTrackRoot->toffsetPion();
00078 double toffsetKaon = tofTrackRoot->toffsetKaon();
00079 double toffsetProton = tofTrackRoot->toffsetProton();
00080 double toffsetAntiProton = tofTrackRoot->toffsetAntiProton();
00081 double sigmaElectron = tofTrackRoot->sigmaElectron();
00082 double sigmaMuon = tofTrackRoot->sigmaMuon();
00083 double sigmaPion = tofTrackRoot->sigmaPion();
00084 double sigmaKaon = tofTrackRoot->sigmaKaon();
00085 double sigmaProton = tofTrackRoot->sigmaProton();
00086 double sigmaAntiProton = tofTrackRoot->sigmaAntiProton();
00087 int quality = tofTrackRoot->quality();
00088 double t0 = tofTrackRoot->t0();
00089 double errt0 = tofTrackRoot->errt0();
00090 double errz = tofTrackRoot->errz();
00091 double phi = tofTrackRoot->phi();
00092 double errphi = tofTrackRoot->errphi();
00093 double energy = tofTrackRoot->energy();
00094 double errenergy = tofTrackRoot->errenergy();
00095
00096 DstTofTrack *tofTrackTds = new DstTofTrack();
00097 m_common.m_rootTofTrackMap[tofTrackRoot] = tofTrackTds;
00098
00099 tofTrackTds->setTofTrackID(tofTrackID);
00100 tofTrackTds->setTrackID(trackID);
00101 tofTrackTds->setTofID(tofID);
00102 tofTrackTds->setStatus(status);
00103 tofTrackTds->setPath(path);
00104 tofTrackTds->setZrHit(zrhit);
00105 tofTrackTds->setPh(ph);
00106 tofTrackTds->setTof(tof);
00107 tofTrackTds->setErrTof(errtof);
00108 tofTrackTds->setBeta(beta);
00109 tofTrackTds->setTexpElectron(texpElectron);
00110 tofTrackTds->setTexpMuon(texpMuon);
00111 tofTrackTds->setTexpPion(texpPion);
00112 tofTrackTds->setTexpKaon(texpKaon);
00113 tofTrackTds->setTexpProton(texpProton);
00114 tofTrackTds->setToffsetElectron(toffsetElectron);
00115 tofTrackTds->setToffsetMuon(toffsetMuon);
00116 tofTrackTds->setToffsetPion(toffsetPion);
00117 tofTrackTds->setToffsetKaon(toffsetKaon);
00118 tofTrackTds->setToffsetProton(toffsetProton);
00119 tofTrackTds->setToffsetAntiProton(toffsetAntiProton);
00120 tofTrackTds->setSigmaElectron(sigmaElectron);
00121 tofTrackTds->setSigmaMuon(sigmaMuon);
00122 tofTrackTds->setSigmaPion(sigmaPion);
00123 tofTrackTds->setSigmaKaon(sigmaKaon);
00124 tofTrackTds->setSigmaProton(sigmaProton);
00125 tofTrackTds->setSigmaAntiProton(sigmaAntiProton);
00126 tofTrackTds->setQuality(quality);
00127 tofTrackTds->setT0(t0);
00128 tofTrackTds->setErrT0(errt0);
00129 tofTrackTds->setErrZ(errz);
00130 tofTrackTds->setPhi(phi);
00131 tofTrackTds->setErrPhi(errphi);
00132 tofTrackTds->setEnergy(energy);
00133 tofTrackTds->setErrEnergy(errenergy);
00134
00135 tofTrackTdsCol->push_back(tofTrackTds);
00136
00137
00138
00139 }
00140
00141
00142 delete m_tofTrackCol;
00143 m_tofTrackCol = 0;
00144 return StatusCode::SUCCESS;
00145 }
00146
00147 StatusCode TofTrackCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
00148
00149 MsgStream log(msgSvc(), "TofTrackCnv");
00150 log << MSG::DEBUG << "TofTrackCnv::DataObjectToTObject" << endreq;
00151 StatusCode sc=StatusCode::SUCCESS;
00152
00153 DstTofTrackCol * tofTrackColTds=dynamic_cast<DstTofTrackCol *> (obj);
00154 if (!tofTrackColTds) {
00155 log << MSG::ERROR << "Could not downcast to DstTofTrackCol" << endreq;
00156 return StatusCode::FAILURE;
00157 }
00158
00159 DataObject *evt;
00160 m_eds->findObject(EventModel::Dst::Event,evt);
00161 if (evt==NULL) {
00162 log << MSG::ERROR << "Could not get DstEvent in TDS " << endreq;
00163 return StatusCode::FAILURE;
00164 }
00165
00166 DstEvent * devtTds=dynamic_cast<DstEvent *> (evt);
00167 if (!devtTds) {
00168 log << MSG::ERROR << "TofTrackCnv:Could not downcast to TDS ReconEvent" << endreq;
00169 }
00170 IOpaqueAddress *addr;
00171
00172 m_cnvSvc->getDstCnv()->createRep(evt,addr);
00173 TDstEvent *recEvt=m_cnvSvc->getDstCnv()->getWriteObject();
00174
00175 const TObjArray *m_tofTrackCol = recEvt->getTofTrackCol();
00176 if (!m_tofTrackCol) return sc;
00177 recEvt->clearTofTrackCol();
00178 DstTofTrackCol::const_iterator tofTrackTds;
00179
00180 for (tofTrackTds = tofTrackColTds->begin(); tofTrackTds != tofTrackColTds->end(); tofTrackTds++) {
00181
00182 Int_t tofTrackID = (*tofTrackTds)->tofTrackID();
00183 Int_t trackID = (*tofTrackTds)->trackID();
00184 Int_t tofID = (*tofTrackTds)->tofID();
00185 Int_t strip = (*tofTrackTds)->strip();
00186 UInt_t status = (*tofTrackTds)->status();
00187 Double_t path = (*tofTrackTds)->path();
00188 Double_t zrhit = (*tofTrackTds)->zrhit();
00189 Double_t ph = (*tofTrackTds)->ph();
00190 Double_t tof = (*tofTrackTds)->tof();
00191 Double_t errtof = (*tofTrackTds)->errtof();
00192 Double_t beta = (*tofTrackTds)->beta();
00193 Double_t texpElectron = (*tofTrackTds)->texpElectron();
00194 Double_t texpMuon = (*tofTrackTds)->texpMuon();
00195 Double_t texpPion = (*tofTrackTds)->texpPion();
00196 Double_t texpKaon = (*tofTrackTds)->texpKaon();
00197 Double_t texpProton = (*tofTrackTds)->texpProton();
00198 Double_t toffsetElectron = (*tofTrackTds)->toffsetElectron();
00199 Double_t toffsetMuon = (*tofTrackTds)->toffsetMuon();
00200 Double_t toffsetPion = (*tofTrackTds)->toffsetPion();
00201 Double_t toffsetKaon = (*tofTrackTds)->toffsetKaon();
00202 Double_t toffsetProton = (*tofTrackTds)->toffsetProton();
00203 Double_t toffsetAntiProton = (*tofTrackTds)->toffsetAntiProton();
00204 Double_t sigmaElectron = (*tofTrackTds)->sigmaElectron();
00205 Double_t sigmaMuon = (*tofTrackTds)->sigmaMuon();
00206 Double_t sigmaPion = (*tofTrackTds)->sigmaPion();
00207 Double_t sigmaKaon = (*tofTrackTds)->sigmaKaon();
00208 Double_t sigmaProton = (*tofTrackTds)->sigmaProton();
00209 Double_t sigmaAntiProton = (*tofTrackTds)->sigmaAntiProton();
00210 Int_t quality = (*tofTrackTds)->quality();
00211 Double_t t0 = (*tofTrackTds)->t0();
00212 Double_t errt0 = (*tofTrackTds)->errt0();
00213 Double_t errz = (*tofTrackTds)->errz();
00214 Double_t phi = (*tofTrackTds)->phi();
00215 Double_t errphi = (*tofTrackTds)->errphi();
00216 Double_t energy = (*tofTrackTds)->energy();
00217 Double_t errenergy = (*tofTrackTds)->errenergy();
00218
00219 if( TofHitStatus::is_mrpc( status ) ) { tofID = tofID*12 + strip; }
00220
00221 TTofTrack *tofTrackRoot = new TTofTrack();
00222
00223
00224 tofTrackRoot->setTofTrackID(tofTrackID);
00225 tofTrackRoot->setTrackID(trackID);
00226 tofTrackRoot->setTofID(tofID);
00227 tofTrackRoot->setStatus(status);
00228 tofTrackRoot->setPath(path);
00229 tofTrackRoot->setZrHit(zrhit);
00230 tofTrackRoot->setPh(ph);
00231 tofTrackRoot->setTof(tof);
00232 tofTrackRoot->setErrTof(errtof);
00233 tofTrackRoot->setBeta(beta);
00234 tofTrackRoot->setTexpElectron(texpElectron);
00235 tofTrackRoot->setTexpMuon(texpMuon);
00236 tofTrackRoot->setTexpPion(texpPion);
00237 tofTrackRoot->setTexpKaon(texpKaon);
00238 tofTrackRoot->setTexpProton(texpProton);
00239 tofTrackRoot->setToffsetElectron(toffsetElectron);
00240 tofTrackRoot->setToffsetMuon(toffsetMuon);
00241 tofTrackRoot->setToffsetPion(toffsetPion);
00242 tofTrackRoot->setToffsetKaon(toffsetKaon);
00243 tofTrackRoot->setToffsetProton(toffsetProton);
00244 tofTrackRoot->setToffsetAntiProton(toffsetAntiProton);
00245 tofTrackRoot->setSigmaElectron(sigmaElectron);
00246 tofTrackRoot->setSigmaMuon(sigmaMuon);
00247 tofTrackRoot->setSigmaPion(sigmaPion);
00248 tofTrackRoot->setSigmaKaon(sigmaKaon);
00249 tofTrackRoot->setSigmaProton(sigmaProton);
00250 tofTrackRoot->setSigmaAntiProton(sigmaAntiProton);
00251 tofTrackRoot->setQuality(quality);
00252 tofTrackRoot->setT0(t0);
00253 tofTrackRoot->setErrT0(errt0);
00254 tofTrackRoot->setErrZ(errz);
00255 tofTrackRoot->setPhi(phi);
00256 tofTrackRoot->setErrPhi(errphi);
00257 tofTrackRoot->setEnergy(energy);
00258 tofTrackRoot->setErrEnergy(errenergy);
00259
00260 recEvt->addTofTrack(tofTrackRoot);
00261 }
00262
00263 return StatusCode::SUCCESS;
00264 }
00265 #endif