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