CGEM BOSS 6.6.5.h
BESIII Offline Software System
Loading...
Searching...
No Matches
RecEmcShowerCnv.cxx
Go to the documentation of this file.
1#ifndef RecEmcShowerCnv_CXX
2#define RecEmcShowerCnv_CXX 1
3
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/DataObject.h"
6#include "GaudiKernel/ObjectVector.h"
7#include "GaudiKernel/IDataProviderSvc.h"
8#include "GaudiKernel/Bootstrap.h"
9
10#include "TClonesArray.h"
11
13
16
19
20
24
25#include <vector>
26
27using namespace std;
28
29// Instantiation of a static factory class used by clients to create
30// instances of this service
31//static CnvFactory<RecEmcShowerCnv> s_factory;
32//const ICnvFactory& RecEmcShowerCnvFactory = s_factory;
33
35: RootEventBaseCnv(classID(), svc)
36{
37
38 RecEmcShower *aShower = new RecEmcShower();
39 //cout<<"in RecEmcShowerCnv::constructor:: showid= "<<aShower->clID()<<endl;
40 delete aShower;
41
42 // Here we associate this converter with the /Event path on the TDS.
43 MsgStream log(msgSvc(), "RecEmcShowerCnv");
44 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
45 //m_rootTreename ="Rec";
46 m_rootBranchname ="m_recEmcShowerCol";
47 //declareObject(EventModel::Recon::RecEmcShowerCol, objType(), m_rootTreename, m_rootBranchname);
48 m_adresses.push_back(&m_recEmcShowerCol);
49 m_recEmcShowerCol=0;
50}
51
52StatusCode RecEmcShowerCnv::TObjectToDataObject(DataObject*& refpObject) {
53 // creation of TDS object from root object
54
55 MsgStream log(msgSvc(), "RecEmcShowerCnv");
56 log << MSG::DEBUG << "RecEmcShowerCnv::TObjectToDataObject" << endreq;
57 //cout << "RecEmcShowerCnv::TObjectToDataObject" << endl;
58 StatusCode sc=StatusCode::SUCCESS;
59
60 IDataProviderSvc* eventSvc;
61 Gaudi::svcLocator()->service("EventDataSvc", eventSvc);
62
63 SmartDataPtr<RecEmcHitCol> emcRecHitCol(eventSvc,
65 if(!emcRecHitCol) log << MSG::INFO << "can't retrieve RecEmcHitCol" << endreq;
66
67 SmartDataPtr<RecEmcClusterCol> emcRecClusterCol(eventSvc,
69 if(!emcRecClusterCol) log << MSG::INFO << "can't retrieve RecEmcClusterCol" << endreq;
70
71 // create the TDS location for the RecEmcShower Collection
72 RecEmcShowerCol* emcShowerTdsCol = new RecEmcShowerCol;
73 refpObject=emcShowerTdsCol;
74
75 // now convert
76 if (!m_recEmcShowerCol) return sc;
77 TIter emcShowerIter(m_recEmcShowerCol);
78 TRecEmcShower *emcShowerRoot = 0;
79 while ((emcShowerRoot = (TRecEmcShower*)emcShowerIter.Next())) {
80 int trackId = emcShowerRoot->trackId();
81 int numHits = emcShowerRoot->numHits();
82 int status = emcShowerRoot->status();
83 int cellId = emcShowerRoot->cellId();
84 int module = emcShowerRoot->module();
85 double x = emcShowerRoot->x();
86 double y = emcShowerRoot->y();
87 double z = emcShowerRoot->z();
88 double theta = emcShowerRoot->theta();
89 double dtheta = emcShowerRoot->dtheta();
90 double phi = emcShowerRoot->phi();
91 double dphi = emcShowerRoot->dphi();
92 double energy = emcShowerRoot->energy();
93 double dE = emcShowerRoot->dE();
94 double eSeed = emcShowerRoot->eSeed();
95 double e3x3 = emcShowerRoot->e3x3();
96 double e5x5 = emcShowerRoot->e5x5();
97 double eall = emcShowerRoot->eAll();
98 double elepton = emcShowerRoot->eLepton();
99 double time = emcShowerRoot->time();
100 double secondMoment = emcShowerRoot->secondMoment();
101 double latMoment = emcShowerRoot->latMoment();
102 double a20Moment = emcShowerRoot->a20Moment();
103 double a42Moment = emcShowerRoot->a42Moment();
104
105 HepSymMatrix matrix(3);
106 matrix[0][0]=emcShowerRoot->err(0);
107 matrix[1][1]=emcShowerRoot->err(1);
108 matrix[2][2]=emcShowerRoot->err(2);
109 matrix[0][1]=emcShowerRoot->err(3);
110 matrix[0][2]=emcShowerRoot->err(4);
111 matrix[1][2]=emcShowerRoot->err(5);
112
113 RecEmcID showerId(cellId);
114 RecEmcID clusterId(emcShowerRoot->clusterId());
115
116 RecEmcIDVector id3x3;
117 vector<Int_t> cellId3x3 = emcShowerRoot->cellId3x3();
118 vector<Int_t>::iterator iCellId;
119 //cout<<"id3x3"<<endl;
120 for(iCellId=cellId3x3.begin();
121 iCellId!=cellId3x3.end();
122 iCellId++) {
123 RecEmcID id(*iCellId);
124 //cout<<"id="<<id<<endl;
125 id3x3.push_back(id);
126 }
127
128 RecEmcIDVector id5x5;
129 vector<Int_t> cellId5x5 = emcShowerRoot->cellId5x5();
130 //cout<<"id5x5"<<endl;
131 for(iCellId=cellId5x5.begin();
132 iCellId!=cellId5x5.end();
133 iCellId++) {
134 RecEmcID id(*iCellId);
135 //cout<<"id="<<id<<endl;
136 id5x5.push_back(id);
137 }
138
139 RecEmcShower *emcShowerTds = new RecEmcShower();
140 m_common.m_rootRecEmcShowerMap[emcShowerRoot] = emcShowerTds;
141
142 emcShowerTds->setTrackId(trackId );
143 emcShowerTds->setNumHits(numHits );
144 emcShowerTds->setStatus(status );
145 emcShowerTds->setCellId( cellId );
146 emcShowerTds->setModule( module);
147
148 HepPoint3D pos(x,y,z);
149 emcShowerTds->setPosition(pos);
150 emcShowerTds->setEnergy( energy );
151 emcShowerTds->setDE( dE );
152 emcShowerTds->setDtheta( dtheta );
153 emcShowerTds->setDphi( dphi );
154 emcShowerTds->setESeed(eSeed);
155 emcShowerTds->setE3x3(e3x3);
156 emcShowerTds->setE5x5(e5x5);
157 emcShowerTds->EAll(eall);
158 emcShowerTds->ELepton(elepton);
159 emcShowerTds->setTime(time);
160 emcShowerTds->setSecondMoment(secondMoment);
161 emcShowerTds->setLatMoment(latMoment);
162 emcShowerTds->setA20Moment(a20Moment);
163 emcShowerTds->setA42Moment(a42Moment);
164 emcShowerTds->setErrorMatrix( matrix );
165
166 emcShowerTds->ShowerId(showerId);
167 emcShowerTds->ClusterId(clusterId);
168 emcShowerTds->CellId3x3(id3x3);
169 emcShowerTds->CellId5x5(id5x5);
170
171 //put fraction map into shower
172 if(emcRecHitCol) {
173 map<Int_t, Double_t> cellIdMap=emcShowerRoot->cellIdMap();
174 map<Int_t, Double_t>::iterator iCellIdMap;
175 for(iCellIdMap=cellIdMap.begin();
176 iCellIdMap!=cellIdMap.end();
177 iCellIdMap++) {
178
179 RecEmcID id(iCellIdMap->first);
180
181 RecEmcHitCol::iterator iHit;
182 for(iHit=emcRecHitCol->begin();
183 iHit!=emcRecHitCol->end();
184 iHit++) {
185
186 RecEmcID idHit((*iHit)->getCellId());
187
188 if(id==idHit) {
189 RecEmcFraction frac(*(*iHit));
190 frac.Fraction(iCellIdMap->second);
191 emcShowerTds->Insert(frac);
192 break;
193 }
194 } //RecEmcHitCol
195 } //CellIdMap
196 }
197
198 if(emcRecClusterCol) {
199 RecEmcClusterCol::iterator iCluster;
200 for(iCluster=emcRecClusterCol->begin();
201 iCluster!=emcRecClusterCol->end();
202 iCluster++) {
203 if(clusterId==(*iCluster)->getClusterId()) {
204 emcShowerTds->Cluster(*iCluster);
205 break;
206 //emcRecClusterCol->InsertShower(*iCluster);
207 }
208 }
209 }
210
211 emcShowerTdsCol->push_back(emcShowerTds);
212 // delete emcShowerTds;
213 // emcShowerTds = NULL;
214 }
215
216 //m_recEmcShowerCol->Delete(); // wensp add 2005/12/30
217 delete m_recEmcShowerCol;
218 m_recEmcShowerCol = 0;
219
220 return StatusCode::SUCCESS;
221}
222
223StatusCode RecEmcShowerCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr)
224{
225 MsgStream log(msgSvc(), "RecEmcShowerCnv");
226 log << MSG::DEBUG << "RecEmcShowerCnv::DataObjectToTObject" << endreq;
227 //cout << "RecEmcShowerCnv::DataObjectToTObject" << endl;
228 StatusCode sc=StatusCode::SUCCESS;
229
230 RecEmcShowerCol * emcShowerColTds=dynamic_cast<RecEmcShowerCol *> (obj);
231 if (!emcShowerColTds) {
232 log << MSG::ERROR << "Could not downcast to RecEmcShowerCol" << endreq;
233 return StatusCode::FAILURE;
234 }
235
236 DataObject *evt;
237 m_eds->findObject(EventModel::Recon::Event,evt);
238 if (evt==NULL) {
239 log << MSG::ERROR << "Could not get RecEvent in TDS " << endreq;
240 return StatusCode::FAILURE;
241 }
242 ReconEvent * devtTds=dynamic_cast<ReconEvent *> (evt);
243 if (!devtTds) {
244 log << MSG::ERROR << "RecEmcShowerCnv:Could not downcast to TDS DstEvent" << endreq;
245 }
246 IOpaqueAddress *addr;
247
248 m_cnvSvc->getRecTrackCnv()->createRep(evt,addr);
250
251 const TObjArray *m_emcShowerCol = recEvt->getEmcShowerCol();
252 if (!m_emcShowerCol) return sc;
253 recEvt->clearEmcShowerCol(); //necessary in case there is I/O at the same time since array is static
254 RecEmcShowerCol::const_iterator emcShowerTds;
255
256 for (emcShowerTds = emcShowerColTds->begin(); emcShowerTds != emcShowerColTds->end(); emcShowerTds++) {
257 Int_t trackId = (*emcShowerTds)->trackId();
258 Int_t numHits = (*emcShowerTds)->numHits();
259 Int_t status =(*emcShowerTds)->status();
260 Int_t cellId =(*emcShowerTds)->getShowerId();
261 Int_t clusterId = (*emcShowerTds)->getClusterId();
262 Int_t module =(*emcShowerTds)->module();
263 Double_t x = (*emcShowerTds)->x();
264 Double_t y = (*emcShowerTds)->y();
265 Double_t z = (*emcShowerTds)->z();
266 Double_t theta = (*emcShowerTds)->theta();
267 Double_t dtheta =(*emcShowerTds)->dtheta();
268 Double_t phi =(*emcShowerTds)->phi();
269 Double_t dphi =(*emcShowerTds)->dphi();
270 Double_t energy = (*emcShowerTds)->energy();
271 Double_t dE = (*emcShowerTds)->dE();
272 Double_t eSeed = (*emcShowerTds)->eSeed();
273 Double_t e3x3 = (*emcShowerTds)->e3x3();
274 Double_t e5x5 = (*emcShowerTds)->e5x5();
275 Double_t eall = (*emcShowerTds)->getEAll();
276 Double_t elepton = (*emcShowerTds)->getELepton();
277 Double_t time = (Int_t)(*emcShowerTds)->time();
278 Double_t secondMoment = (*emcShowerTds)->secondMoment();
279 Double_t latMoment = (*emcShowerTds)->latMoment();
280 Double_t a20Moment = (*emcShowerTds)->a20Moment();
281 Double_t a42Moment = (*emcShowerTds)->a42Moment();
282
283 HepSymMatrix matrix = (*emcShowerTds)->errorMatrix();
284 //cout<<"matrix: \n"<<matrix<<endl;
285 Double_t err[6];
286 err[0] = matrix[0][0];
287 err[1] = matrix[1][1];
288 err[2] = matrix[2][2];
289 err[3] = matrix[0][1];
290 err[4] = matrix[0][2];
291 err[5] = matrix[1][2];
292
293 map<Int_t, Double_t> cellIdMap;
294 RecEmcFractionMap::const_iterator pFractionMap;
295
296 for(pFractionMap=(*emcShowerTds)->Begin();
297 pFractionMap!=(*emcShowerTds)->End();
298 pFractionMap++) {
299 Int_t id = pFractionMap->first;
300 Double_t frac = pFractionMap->second.getFraction();
301 cellIdMap[id]=frac;
302 }
303
304 vector<Int_t> cellId3x3;
305 RecEmcIDVector id3x3 = (*emcShowerTds)->getCellId3x3();
306 ci_RecEmcIDVector ciCellId;
307 for(ciCellId=id3x3.begin();
308 ciCellId!=id3x3.end();
309 ciCellId++) {
310 Int_t id = *ciCellId;
311 cellId3x3.push_back(id);
312 }
313
314 vector<Int_t> cellId5x5;
315 RecEmcIDVector id5x5 = (*emcShowerTds)->getCellId5x5();
316 for(ciCellId=id5x5.begin();
317 ciCellId!=id5x5.end();
318 ciCellId++) {
319 Int_t id = *ciCellId;
320 cellId5x5.push_back(id);
321 }
322
323 TRecEmcShower *emcShowerRoot = new TRecEmcShower();
324 //m_common.m_recEmcShowerMap[(*emcShowerTds)] = emcShowerRoot;
325
326 //emcShowerRoot->initialize(numHits ,status ,cellId ,module ,x ,dx,y ,dy,z ,dz,theta ,dtheta ,phi,dphi ,energy ,dE,cosx ,cosy ,cosz);
327 emcShowerRoot->setTrackId(trackId );
328 emcShowerRoot->setNumHits(numHits );
329 emcShowerRoot->setStatus(status );
330 emcShowerRoot->setCellId( cellId );
331 emcShowerRoot->setClusterId( clusterId );
332 emcShowerRoot->setModule( module);
333 emcShowerRoot->setX( x );
334 emcShowerRoot->setY( y );
335 emcShowerRoot->setZ( z );
336 emcShowerRoot->setEnergy( energy );
337 emcShowerRoot->setDE( dE );
338 emcShowerRoot->setTheta( theta );
339 emcShowerRoot->setDtheta( dtheta );
340 emcShowerRoot->setPhi( phi );
341 emcShowerRoot->setDphi( dphi );
342 emcShowerRoot->setESeed( eSeed );
343 emcShowerRoot->setE3x3( e3x3 );
344 emcShowerRoot->setE5x5( e5x5 );
345 emcShowerRoot->setEAll( eall );
346 emcShowerRoot->setELepton( elepton );
347 emcShowerRoot->setTime( time );
348 emcShowerRoot->setSecondMoment(secondMoment);
349 emcShowerRoot->setLatMoment(latMoment);
350 emcShowerRoot->setA20Moment(a20Moment);
351 emcShowerRoot->setA42Moment(a42Moment);
352 emcShowerRoot->setErr( err );
353 //emcShowerRoot->setVecHits(vecHits);
354
355 emcShowerRoot->setCellIdMap(cellIdMap);
356 emcShowerRoot->setCellId3x3(cellId3x3);
357 emcShowerRoot->setCellId5x5(cellId5x5);
358
359 recEvt->addEmcShower(emcShowerRoot);
360 }
361 return StatusCode::SUCCESS;
362}
363#endif
Double_t x[10]
Double_t time
************Class m_ypar INTEGER m_KeyWgt INTEGER m_nphot 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
RecEmcIDVector::const_iterator ci_RecEmcIDVector
vector< RecEmcID > RecEmcIDVector
ObjectVector< RecEmcShower > RecEmcShowerCol
IMessageSvc * msgSvc()
void setDphi(double dpi)
void setE3x3(double e3x3)
void setDtheta(double dt)
void setStatus(int st)
void setNumHits(int hit)
void setSecondMoment(double secondMoment)
void setA20Moment(double a20Moment)
void setPosition(const HepPoint3D &pos)
void setDE(double de)
void setA42Moment(double a42Moment)
void setESeed(double eSeed)
void setTime(double time)
void setModule(int mod)
void setCellId(int id)
void setLatMoment(double latMoment)
void setErrorMatrix(const HepSymMatrix &error)
void setTrackId(int trackId)
void setEnergy(double e)
void setE5x5(double e5x5)
RecEmcFrac Fraction(const RecEmcFrac &Fraction)
RecEmcShowerCnv(ISvcLocator *svc)
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
void CellId3x3(RecEmcIDVector &id3x3)
RecEmcEnergy EAll(RecEmcEnergy e)
RecEmcEnergy ELepton(RecEmcEnergy e)
void ClusterId(const RecEmcID id)
RecEmcID ShowerId(RecEmcID id)
void Cluster(RecEmcCluster *pCluster)
void Insert(const RecEmcFraction &aFraction)
void CellId5x5(RecEmcIDVector &id5x5)
static TRecTrackEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition RecTrackCnv.h:36
Definition of a Root address, derived from IOpaqueAddress.
Definition RootAddress.h:21
RecTrackCnv * getRecTrackCnv()
Definition RootCnvSvc.h:166
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.
Int_t module() const
Double_t e3x3() const
Double_t phi() const
void setDphi(const Double_t dpi)
Double_t z() const
void setTime(const Double_t time)
void setCellIdMap(const map< Int_t, Double_t > &cellIdMap)
void setY(const Double_t y)
void setX(const Double_t x)
Double_t err(Int_t i) const
void setELepton(const Double_t elepton)
void setDtheta(const Double_t dt)
Double_t dtheta() const
Double_t dphi() const
Double_t a20Moment() const
Int_t cellId() const
void setA20Moment(const Double_t a20Moment)
Double_t latMoment() const
void setStatus(const Int_t st)
void setClusterId(const Int_t clusterId)
map< Int_t, Double_t > cellIdMap() const
void setModule(const Int_t mod)
void setTheta(const Double_t theta)
Double_t secondMoment() const
Double_t theta() const
Int_t clusterId() const
void setEnergy(const Double_t e)
void setSecondMoment(const Double_t secondMoment)
Double_t x() const
void setE3x3(const Double_t e3x3)
Double_t eLepton() const
void setZ(const Double_t z)
Double_t eAll() const
void setCellId5x5(const vector< Int_t > &cellId5x5)
void setE5x5(const Double_t e5x5)
vector< Int_t > cellId5x5() const
void setCellId3x3(const vector< Int_t > &cellId3x3)
Int_t status() const
Double_t time() const
vector< Int_t > cellId3x3() const
void setEAll(const Double_t eall)
void setCellId(const Int_t id)
void setESeed(const Double_t eSeed)
Double_t dE() const
void setNumHits(const Int_t hit)
Double_t energy() const
Double_t a42Moment() const
void setErr(const Double_t err[6])
void setDE(const Double_t de)
Double_t eSeed() const
Double_t y() const
Int_t trackId() const
void setA42Moment(const Double_t a42Moment)
Double_t e5x5() const
void setPhi(const Double_t pi)
void setTrackId(const Int_t trackId)
Int_t numHits() const
void setLatMoment(const Double_t latMoment)
void clearEmcShowerCol()
clear the whole array (necessary because of the consts-s) *‍/
void addEmcShower(TRecEmcShower *Track)
Add a TkrTrack into the Emc data collection *‍/.
const TObjArray * getEmcShowerCol() const
retrieve the whole TObjArray of EmcShower Data
static std::map< const TObject *, const RecEmcShower * > m_rootRecEmcShowerMap
Definition commonData.h:270
_EXTERN_ std::string RecEmcClusterCol
Definition EventModel.h:108
_EXTERN_ std::string RecEmcHitCol
Definition EventModel.h:107
_EXTERN_ std::string Event
Definition EventModel.h:90