00001 #ifndef RecEmcShowerCnv_CXX
00002 #define RecEmcShowerCnv_CXX 1
00003
00004 #include "GaudiKernel/MsgStream.h"
00005 #include "GaudiKernel/DataObject.h"
00006 #include "GaudiKernel/ObjectVector.h"
00007 #include "GaudiKernel/IDataProviderSvc.h"
00008 #include "GaudiKernel/Bootstrap.h"
00009
00010 #include "TClonesArray.h"
00011
00012 #include "EventModel/EventModel.h"
00013
00014 #include "ReconEvent/ReconEvent.h"
00015 #include "EmcRecEventModel/RecEmcEventModel.h"
00016
00017 #include "RootEventData/TRecEmcShower.h"
00018 #include "RootEventData/TRecTrackEvent.h"
00019
00020
00021 #include "RootCnvSvc/Rec/RecTrackCnv.h"
00022 #include "RootCnvSvc/Rec/RecEmcShowerCnv.h"
00023 #include "RootCnvSvc/RootAddress.h"
00024
00025 #include <vector>
00026
00027 using namespace std;
00028
00029
00030
00031
00032
00033
00034 RecEmcShowerCnv::RecEmcShowerCnv(ISvcLocator* svc)
00035 : RootEventBaseCnv(classID(), svc)
00036 {
00037
00038 RecEmcShower *aShower = new RecEmcShower();
00039
00040 delete aShower;
00041
00042
00043 MsgStream log(msgSvc(), "RecEmcShowerCnv");
00044
00045
00046 m_rootBranchname ="m_recEmcShowerCol";
00047
00048 m_adresses.push_back(&m_recEmcShowerCol);
00049 m_recEmcShowerCol=0;
00050 }
00051
00052 StatusCode RecEmcShowerCnv::TObjectToDataObject(DataObject*& refpObject) {
00053
00054
00055 MsgStream log(msgSvc(), "RecEmcShowerCnv");
00056 log << MSG::DEBUG << "RecEmcShowerCnv::TObjectToDataObject" << endreq;
00057
00058 StatusCode sc=StatusCode::SUCCESS;
00059
00060 IDataProviderSvc* eventSvc;
00061 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
00062
00063 SmartDataPtr<RecEmcHitCol> emcRecHitCol(eventSvc,
00064 EventModel::Recon::RecEmcHitCol);
00065 if(!emcRecHitCol) log << MSG::INFO << "can't retrieve RecEmcHitCol" << endreq;
00066
00067 SmartDataPtr<RecEmcClusterCol> emcRecClusterCol(eventSvc,
00068 EventModel::Recon::RecEmcClusterCol);
00069 if(!emcRecClusterCol) log << MSG::INFO << "can't retrieve RecEmcClusterCol" << endreq;
00070
00071
00072 RecEmcShowerCol* emcShowerTdsCol = new RecEmcShowerCol;
00073 refpObject=emcShowerTdsCol;
00074
00075
00076 if (!m_recEmcShowerCol) return sc;
00077 TIter emcShowerIter(m_recEmcShowerCol);
00078 TRecEmcShower *emcShowerRoot = 0;
00079 while ((emcShowerRoot = (TRecEmcShower*)emcShowerIter.Next())) {
00080 int trackId = emcShowerRoot->trackId();
00081 int numHits = emcShowerRoot->numHits();
00082 int status = emcShowerRoot->status();
00083 int cellId = emcShowerRoot->cellId();
00084 int module = emcShowerRoot->module();
00085 double x = emcShowerRoot->x();
00086 double y = emcShowerRoot->y();
00087 double z = emcShowerRoot->z();
00088 double theta = emcShowerRoot->theta();
00089 double dtheta = emcShowerRoot->dtheta();
00090 double phi = emcShowerRoot->phi();
00091 double dphi = emcShowerRoot->dphi();
00092 double energy = emcShowerRoot->energy();
00093 double dE = emcShowerRoot->dE();
00094 double eSeed = emcShowerRoot->eSeed();
00095 double e3x3 = emcShowerRoot->e3x3();
00096 double e5x5 = emcShowerRoot->e5x5();
00097 double eall = emcShowerRoot->eAll();
00098 double elepton = emcShowerRoot->eLepton();
00099 double time = emcShowerRoot->time();
00100 double secondMoment = emcShowerRoot->secondMoment();
00101 double latMoment = emcShowerRoot->latMoment();
00102 double a20Moment = emcShowerRoot->a20Moment();
00103 double a42Moment = emcShowerRoot->a42Moment();
00104
00105 HepSymMatrix matrix(3);
00106 matrix[0][0]=emcShowerRoot->err(0);
00107 matrix[1][1]=emcShowerRoot->err(1);
00108 matrix[2][2]=emcShowerRoot->err(2);
00109 matrix[0][1]=emcShowerRoot->err(3);
00110 matrix[0][2]=emcShowerRoot->err(4);
00111 matrix[1][2]=emcShowerRoot->err(5);
00112
00113 RecEmcID showerId(cellId);
00114 RecEmcID clusterId(emcShowerRoot->clusterId());
00115
00116 RecEmcIDVector id3x3;
00117 vector<Int_t> cellId3x3 = emcShowerRoot->cellId3x3();
00118 vector<Int_t>::iterator iCellId;
00119
00120 for(iCellId=cellId3x3.begin();
00121 iCellId!=cellId3x3.end();
00122 iCellId++) {
00123 RecEmcID id(*iCellId);
00124
00125 id3x3.push_back(id);
00126 }
00127
00128 RecEmcIDVector id5x5;
00129 vector<Int_t> cellId5x5 = emcShowerRoot->cellId5x5();
00130
00131 for(iCellId=cellId5x5.begin();
00132 iCellId!=cellId5x5.end();
00133 iCellId++) {
00134 RecEmcID id(*iCellId);
00135
00136 id5x5.push_back(id);
00137 }
00138
00139 RecEmcShower *emcShowerTds = new RecEmcShower();
00140 m_common.m_rootRecEmcShowerMap[emcShowerRoot] = emcShowerTds;
00141
00142 emcShowerTds->setTrackId(trackId );
00143 emcShowerTds->setNumHits(numHits );
00144 emcShowerTds->setStatus(status );
00145 emcShowerTds->setCellId( cellId );
00146 emcShowerTds->setModule( module);
00147
00148 HepPoint3D pos(x,y,z);
00149 emcShowerTds->setPosition(pos);
00150 emcShowerTds->setEnergy( energy );
00151 emcShowerTds->setDE( dE );
00152 emcShowerTds->setDtheta( dtheta );
00153 emcShowerTds->setDphi( dphi );
00154 emcShowerTds->setESeed(eSeed);
00155 emcShowerTds->setE3x3(e3x3);
00156 emcShowerTds->setE5x5(e5x5);
00157 emcShowerTds->EAll(eall);
00158 emcShowerTds->ELepton(elepton);
00159 emcShowerTds->setTime(time);
00160 emcShowerTds->setSecondMoment(secondMoment);
00161 emcShowerTds->setLatMoment(latMoment);
00162 emcShowerTds->setA20Moment(a20Moment);
00163 emcShowerTds->setA42Moment(a42Moment);
00164 emcShowerTds->setErrorMatrix( matrix );
00165
00166 emcShowerTds->ShowerId(showerId);
00167 emcShowerTds->ClusterId(clusterId);
00168 emcShowerTds->CellId3x3(id3x3);
00169 emcShowerTds->CellId5x5(id5x5);
00170
00171
00172 if(emcRecHitCol) {
00173 map<Int_t, Double_t> cellIdMap=emcShowerRoot->cellIdMap();
00174 map<Int_t, Double_t>::iterator iCellIdMap;
00175 for(iCellIdMap=cellIdMap.begin();
00176 iCellIdMap!=cellIdMap.end();
00177 iCellIdMap++) {
00178
00179 RecEmcID id(iCellIdMap->first);
00180
00181 RecEmcHitCol::iterator iHit;
00182 for(iHit=emcRecHitCol->begin();
00183 iHit!=emcRecHitCol->end();
00184 iHit++) {
00185
00186 RecEmcID idHit((*iHit)->getCellId());
00187
00188 if(id==idHit) {
00189 RecEmcFraction frac(*(*iHit));
00190 frac.Fraction(iCellIdMap->second);
00191 emcShowerTds->Insert(frac);
00192 break;
00193 }
00194 }
00195 }
00196 }
00197
00198 if(emcRecClusterCol) {
00199 RecEmcClusterCol::iterator iCluster;
00200 for(iCluster=emcRecClusterCol->begin();
00201 iCluster!=emcRecClusterCol->end();
00202 iCluster++) {
00203 if(clusterId==(*iCluster)->getClusterId()) {
00204 emcShowerTds->Cluster(*iCluster);
00205 break;
00206
00207 }
00208 }
00209 }
00210
00211 emcShowerTdsCol->push_back(emcShowerTds);
00212
00213
00214 }
00215
00216
00217 delete m_recEmcShowerCol;
00218 m_recEmcShowerCol = 0;
00219
00220 return StatusCode::SUCCESS;
00221 }
00222
00223 StatusCode RecEmcShowerCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr)
00224 {
00225 MsgStream log(msgSvc(), "RecEmcShowerCnv");
00226 log << MSG::DEBUG << "RecEmcShowerCnv::DataObjectToTObject" << endreq;
00227
00228 StatusCode sc=StatusCode::SUCCESS;
00229
00230 RecEmcShowerCol * emcShowerColTds=dynamic_cast<RecEmcShowerCol *> (obj);
00231 if (!emcShowerColTds) {
00232 log << MSG::ERROR << "Could not downcast to RecEmcShowerCol" << endreq;
00233 return StatusCode::FAILURE;
00234 }
00235
00236 DataObject *evt;
00237 m_eds->findObject(EventModel::Recon::Event,evt);
00238 if (evt==NULL) {
00239 log << MSG::ERROR << "Could not get RecEvent in TDS " << endreq;
00240 return StatusCode::FAILURE;
00241 }
00242 ReconEvent * devtTds=dynamic_cast<ReconEvent *> (evt);
00243 if (!devtTds) {
00244 log << MSG::ERROR << "RecEmcShowerCnv:Could not downcast to TDS DstEvent" << endreq;
00245 }
00246 IOpaqueAddress *addr;
00247
00248 m_cnvSvc->getRecTrackCnv()->createRep(evt,addr);
00249 TRecTrackEvent *recEvt=m_cnvSvc->getRecTrackCnv()->getWriteObject();
00250
00251 const TObjArray *m_emcShowerCol = recEvt->getEmcShowerCol();
00252 if (!m_emcShowerCol) return sc;
00253 recEvt->clearEmcShowerCol();
00254 RecEmcShowerCol::const_iterator emcShowerTds;
00255
00256 for (emcShowerTds = emcShowerColTds->begin(); emcShowerTds != emcShowerColTds->end(); emcShowerTds++) {
00257 Int_t trackId = (*emcShowerTds)->trackId();
00258 Int_t numHits = (*emcShowerTds)->numHits();
00259 Int_t status =(*emcShowerTds)->status();
00260 Int_t cellId =(*emcShowerTds)->getShowerId();
00261 Int_t clusterId = (*emcShowerTds)->getClusterId();
00262 Int_t module =(*emcShowerTds)->module();
00263 Double_t x = (*emcShowerTds)->x();
00264 Double_t y = (*emcShowerTds)->y();
00265 Double_t z = (*emcShowerTds)->z();
00266 Double_t theta = (*emcShowerTds)->theta();
00267 Double_t dtheta =(*emcShowerTds)->dtheta();
00268 Double_t phi =(*emcShowerTds)->phi();
00269 Double_t dphi =(*emcShowerTds)->dphi();
00270 Double_t energy = (*emcShowerTds)->energy();
00271 Double_t dE = (*emcShowerTds)->dE();
00272 Double_t eSeed = (*emcShowerTds)->eSeed();
00273 Double_t e3x3 = (*emcShowerTds)->e3x3();
00274 Double_t e5x5 = (*emcShowerTds)->e5x5();
00275 Double_t eall = (*emcShowerTds)->getEAll();
00276 Double_t elepton = (*emcShowerTds)->getELepton();
00277 Double_t time = (Int_t)(*emcShowerTds)->time();
00278 Double_t secondMoment = (*emcShowerTds)->secondMoment();
00279 Double_t latMoment = (*emcShowerTds)->latMoment();
00280 Double_t a20Moment = (*emcShowerTds)->a20Moment();
00281 Double_t a42Moment = (*emcShowerTds)->a42Moment();
00282
00283 HepSymMatrix matrix = (*emcShowerTds)->errorMatrix();
00284
00285 Double_t err[6];
00286 err[0] = matrix[0][0];
00287 err[1] = matrix[1][1];
00288 err[2] = matrix[2][2];
00289 err[3] = matrix[0][1];
00290 err[4] = matrix[0][2];
00291 err[5] = matrix[1][2];
00292
00293 map<Int_t, Double_t> cellIdMap;
00294 RecEmcFractionMap::const_iterator pFractionMap;
00295
00296 for(pFractionMap=(*emcShowerTds)->Begin();
00297 pFractionMap!=(*emcShowerTds)->End();
00298 pFractionMap++) {
00299 Int_t id = pFractionMap->first;
00300 Double_t frac = pFractionMap->second.getFraction();
00301 cellIdMap[id]=frac;
00302 }
00303
00304 vector<Int_t> cellId3x3;
00305 RecEmcIDVector id3x3 = (*emcShowerTds)->getCellId3x3();
00306 ci_RecEmcIDVector ciCellId;
00307 for(ciCellId=id3x3.begin();
00308 ciCellId!=id3x3.end();
00309 ciCellId++) {
00310 Int_t id = *ciCellId;
00311 cellId3x3.push_back(id);
00312 }
00313
00314 vector<Int_t> cellId5x5;
00315 RecEmcIDVector id5x5 = (*emcShowerTds)->getCellId5x5();
00316 for(ciCellId=id5x5.begin();
00317 ciCellId!=id5x5.end();
00318 ciCellId++) {
00319 Int_t id = *ciCellId;
00320 cellId5x5.push_back(id);
00321 }
00322
00323 TRecEmcShower *emcShowerRoot = new TRecEmcShower();
00324
00325
00326
00327 emcShowerRoot->setTrackId(trackId );
00328 emcShowerRoot->setNumHits(numHits );
00329 emcShowerRoot->setStatus(status );
00330 emcShowerRoot->setCellId( cellId );
00331 emcShowerRoot->setClusterId( clusterId );
00332 emcShowerRoot->setModule( module);
00333 emcShowerRoot->setX( x );
00334 emcShowerRoot->setY( y );
00335 emcShowerRoot->setZ( z );
00336 emcShowerRoot->setEnergy( energy );
00337 emcShowerRoot->setDE( dE );
00338 emcShowerRoot->setTheta( theta );
00339 emcShowerRoot->setDtheta( dtheta );
00340 emcShowerRoot->setPhi( phi );
00341 emcShowerRoot->setDphi( dphi );
00342 emcShowerRoot->setESeed( eSeed );
00343 emcShowerRoot->setE3x3( e3x3 );
00344 emcShowerRoot->setE5x5( e5x5 );
00345 emcShowerRoot->setEAll( eall );
00346 emcShowerRoot->setELepton( elepton );
00347 emcShowerRoot->setTime( time );
00348 emcShowerRoot->setSecondMoment(secondMoment);
00349 emcShowerRoot->setLatMoment(latMoment);
00350 emcShowerRoot->setA20Moment(a20Moment);
00351 emcShowerRoot->setA42Moment(a42Moment);
00352 emcShowerRoot->setErr( err );
00353
00354
00355 emcShowerRoot->setCellIdMap(cellIdMap);
00356 emcShowerRoot->setCellId3x3(cellId3x3);
00357 emcShowerRoot->setCellId5x5(cellId5x5);
00358
00359 recEvt->addEmcShower(emcShowerRoot);
00360 }
00361 return StatusCode::SUCCESS;
00362 }
00363 #endif