BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
EmcMcHitCnv.cxx
Go to the documentation of this file.
1#ifndef EmcMcHitCnv_CXX
2#define EmcMcHitCnv_CXX 1
3
4#include "GaudiKernel/DataObject.h"
5#include "GaudiKernel/MsgStream.h"
6#include "GaudiKernel/ObjectVector.h"
7
8#include "TClonesArray.h"
9
10#include "Identifier/Identifier.h"
11
12#include "EventModel/EventModel.h"
13#include "McTruth/EmcMcHit.h" //TDS object
14#include "McTruth/McEvent.h" //TDS object
15#include "RootCnvSvc/Mc/EmcMcHitCnv.h"
16#include "RootCnvSvc/Mc/McCnv.h"
17#include "RootCnvSvc/RootAddress.h"
18#include "RootEventData/TEmcMc.h" // standard root object
19#include "RootEventData/TMcEvent.h"
20
21// Instantiation of a static factory class used by clients to create
22// instances of this service
23// static CnvFactory<EmcMcHitCnv> s_factory;
24// const ICnvFactory& EmcMcHitCnvFactory = s_factory;
25
26EmcMcHitCnv::EmcMcHitCnv( ISvcLocator* svc ) : RootEventBaseCnv( classID(), svc ) {
27 // Here we associate this converter with the /Event path on the TDS.
28 MsgStream log( msgSvc(), "EmcMcHitCnv" );
29 // log << MSG::DEBUG << "Constructor called for " << objType() << endmsg;
30 m_rootBranchname = "m_emcMcHitCol";
31 // declareObject(EventModel::MC::EmcMcHitCol, objType(), m_rootTreename, m_rootBranchname);
32 m_adresses.push_back( &m_emcMcHitCol );
33 m_emcMcHitCol = 0;
34}
35
36StatusCode EmcMcHitCnv::TObjectToDataObject( DataObject*& refpObject ) {
37 // creation of TDS object from root object
38
39 MsgStream log( msgSvc(), "EmcMcHitCnv" );
40 log << MSG::DEBUG << "EmcMcHitCnv::TObjectToDataObject" << endmsg;
41 StatusCode sc = StatusCode::SUCCESS;
42
43 // create the TDS location for the MdcMc Collection
44 EmcMcHitCol* emcMcTdsCol = new EmcMcHitCol;
45 refpObject = emcMcTdsCol;
46
47 // now convert
48 if ( !m_emcMcHitCol ) return sc;
49 TIter emcMcIter( m_emcMcHitCol );
50 TEmcMc* emcMcRoot = 0;
51 while ( ( emcMcRoot = (TEmcMc*)emcMcIter.Next() ) )
52 {
53 // unsigned int id = emcMcRoot ->getId();
54 Identifier id;
55 unsigned int id_root = emcMcRoot->getId();
56 id = id_root;
57 unsigned int trackIndex = emcMcRoot->getTrackIndex();
58
59 int hitEmc = emcMcRoot->getHitEmc();
60 int PDGCode = emcMcRoot->getPDGCode();
61 double PDGCharge = emcMcRoot->getPDGCharge();
62 double time = emcMcRoot->getTime();
63
64 double xPosition = emcMcRoot->getPositionX();
65 double yPosition = emcMcRoot->getPositionY();
66 double zPosition = emcMcRoot->getPositionZ();
67 double px = emcMcRoot->getPx();
68 double py = emcMcRoot->getPy();
69 double pz = emcMcRoot->getPz();
70 double depositEnergy = emcMcRoot->getDepositEnergy();
71
72 EmcMcHit* emcMcTds = new EmcMcHit();
73 m_common.m_rootEmcMcHitMap[emcMcRoot] = emcMcTds;
74
75 emcMcTds->setIdentifier( id );
76
77 map<Int_t, Double_t> hitMap = emcMcRoot->getHitMap();
79 map<Int_t, Double_t> HitMap = emcMcRoot->getHitMap();
81 for ( iHitMap = HitMap.begin(); iHitMap != HitMap.end(); iHitMap++ )
82 {
83
84 Identifier id( iHitMap->first );
85 pair<Identifier, Double_t> TdsHit( id, iHitMap->second );
86 TdshitMap.insert( TdsHit );
87
88 // RecEmcHitCol::iterator iHit;
89 // for(iHit=emcRecHitCol->begin();
90 // iHit!=emcRecHitCol->end();
91 // iHit++) {
92
93 // RecEmcID idHit((*iHit)->getCellId());
94
95 // if(id==idHit) {
96 // RecEmcFraction frac(*(*iHit));
97 // frac.Fraction(iHitMap->second);
98 // emcShowerTds->Insert(frac);
99 // break;
100 // }
101 //} //RecEmcHitCol
102 } // CellIdMap
103 emcMcTds->setHitMap( TdshitMap );
104
105 emcMcTds->setHitEmc( hitEmc );
106 emcMcTds->setPDGCode( PDGCode );
107 emcMcTds->setPDGCharge( PDGCharge );
108 emcMcTds->setTime( time );
109
110 emcMcTds->setTrackIndex( trackIndex );
111 emcMcTds->setPositionX( xPosition );
112 emcMcTds->setPositionY( yPosition );
113 emcMcTds->setPositionZ( zPosition );
114 emcMcTds->setPx( px );
115 emcMcTds->setPy( py );
116 emcMcTds->setPz( pz );
117 emcMcTds->setDepositEnergy( depositEnergy );
118
119 emcMcTdsCol->push_back( emcMcTds );
120 }
121 // m_emcMcHitCol->Delete(); // wensp add 2005/12/30
122 delete m_emcMcHitCol;
123 m_emcMcHitCol = 0;
124 return StatusCode::SUCCESS;
125}
126
127StatusCode EmcMcHitCnv::DataObjectToTObject( DataObject* obj, RootAddress* rootaddr ) {
128
129 MsgStream log( msgSvc(), "EmcMcHitCnv" );
130 log << MSG::DEBUG << "EmcMcHitCnv::DataObjectToTObject" << endmsg;
131 StatusCode sc = StatusCode::SUCCESS;
132
133 EmcMcHitCol* emcMcHitCnvTds = dynamic_cast<EmcMcHitCol*>( obj );
134 if ( !emcMcHitCnvTds )
135 {
136 log << MSG::ERROR << "Could not downcast to EmcMcHitCol" << endmsg;
137 return StatusCode::FAILURE;
138 }
139
140 DataObject* evt;
141 m_eds->findObject( EventModel::MC::Event, evt );
142 if ( evt == NULL )
143 {
144 log << MSG::ERROR << "Could not get McEvent in TDS " << endmsg;
145 return StatusCode::FAILURE;
146 }
147 McEvent* devtTds = dynamic_cast<McEvent*>( evt );
148 if ( !devtTds )
149 { log << MSG::ERROR << "EmcMcHitCnv:Could not downcast to TDS McEvent" << endmsg; }
150 IOpaqueAddress* addr;
151
152 m_cnvSvc->getMcCnv()->createRep( evt, addr );
153 TMcEvent* McEvt = m_cnvSvc->getMcCnv()->getWriteObject();
154
155 const TObjArray* m_emcMcHitCol = McEvt->getEmcMcHitCol();
156 if ( !m_emcMcHitCol ) return sc;
157 McEvt->clearEmcMcHitCol(); // necessary in case there is I/O at the same time since array is
158 // static
159 EmcMcHitCol::const_iterator emcMcTds;
160
161 for ( emcMcTds = emcMcHitCnvTds->begin(); emcMcTds != emcMcHitCnvTds->end(); emcMcTds++ )
162 {
163 UInt_t id = ( ( *emcMcTds )->identify() ).get_value();
164 UInt_t trackIndex = ( *emcMcTds )->getTrackIndex();
165
166 int hitEmc = ( *emcMcTds )->getHitEmc();
167 int PDGCode = ( *emcMcTds )->getPDGCode();
168 double PDGCharge = ( *emcMcTds )->getPDGCharge();
169 double time = ( *emcMcTds )->getTime();
170 std::map<Identifier, Double_t> TdshitMap = ( *emcMcTds )->getHitMap();
171
174 for ( iHitMap = TdshitMap.begin(); iHitMap != TdshitMap.end(); iHitMap++ )
175 {
176
177 Int_t id( iHitMap->first.get_value() );
178 pair<Int_t, Double_t> Hit( id, iHitMap->second );
179 HitMap.insert( Hit );
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(iHitMap->second);
191 // emcShowerTds->Insert(frac);
192 // break;
193 // }
194 //} //RecEmcHitCol
195 } // CellIdMap
196
197 Double_t xPosition = ( *emcMcTds )->getPositionX();
198 Double_t yPosition = ( *emcMcTds )->getPositionY();
199 Double_t zPosition = ( *emcMcTds )->getPositionZ();
200 Double_t px = ( *emcMcTds )->getPx();
201 Double_t py = ( *emcMcTds )->getPy();
202 Double_t pz = ( *emcMcTds )->getPz();
203 Double_t depositEnergy = ( *emcMcTds )->getDepositEnergy();
204
205 TEmcMc* emcMcRoot = new TEmcMc();
206 // m_common.m_emcMcHitMap[(*emcMcTds)] = emcMcRoot;
207
208 emcMcRoot->setId( id );
209 emcMcRoot->setHitMap( HitMap );
210
211 emcMcRoot->setHitEmc( hitEmc );
212 emcMcRoot->setPDGCode( PDGCode );
213 emcMcRoot->setPDGCharge( PDGCharge );
214 emcMcRoot->setTime( time );
215 // emcMcRoot->setHitMap(hitMap);
216
217 emcMcRoot->setTrackIndex( trackIndex );
218 emcMcRoot->setPositionX( xPosition );
219 emcMcRoot->setPositionY( yPosition );
220 emcMcRoot->setPositionZ( zPosition );
221 emcMcRoot->setPx( px );
222 emcMcRoot->setPy( py );
223 emcMcRoot->setPz( pz );
224 emcMcRoot->setDepositEnergy( depositEnergy );
225
226 McEvt->addEmcMc( emcMcRoot );
227 }
228
229 return StatusCode::SUCCESS;
230}
231#endif
Double_t time
ObjectVector< EmcMcHit > EmcMcHitCol
IMessageSvc * msgSvc()
EmcMcHitCnv(ISvcLocator *svc)
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
void setPositionX(double positionX)
void setDepositEnergy(double depositEnergy)
void setHitMap(std::map< Identifier, double > &hitMap)
void setTrackIndex(unsigned int trackIndex)
void setIdentifier(Identifier &id)
void setPositionY(double positionY)
void setPositionZ(double positionZ)
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 setHitMap(std::map< Int_t, Double_t > hitMap)
std::map< Int_t, Double_t > getHitMap() const
void setDepositEnergy(Double_t depositEnergy)
void addEmcMc(TEmcMc *mcHit)
Emc.
Definition TMcEvent.cxx:91