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