CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
RootCnvSvc-04-01-15/src/Mc/CgemMcHitCnv.cxx
Go to the documentation of this file.
1#ifndef CgemMcHitCnv_CXX
2#define CgemMcHitCnv_CXX 1
3
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/DataObject.h"
6#include "GaudiKernel/ObjectVector.h"
7
8#include "TClonesArray.h"
9#include "TArrayI.h"
10
11#include "EventModel/EventModel.h"
12#include "McTruth/McEvent.h" //TDS object
13#include "McTruth/CgemMcHit.h" //TDS object
14#include "RootEventData/TCgemMc.h" // standard root object
15#include "RootEventData/TMcEvent.h"
16#include "RootCnvSvc/Mc/McCnv.h"
17#include "RootCnvSvc/Mc/CgemMcHitCnv.h"
18#include "RootCnvSvc/RootAddress.h"
19
20// Instantiation of a static factory class used by clients to create
21// instances of this service
22//static CnvFactory<CgemMcHitCnv> s_factory;
23//const ICnvFactory& CgemMcHitCnvFactory = s_factory;
24
25CgemMcHitCnv::CgemMcHitCnv(ISvcLocator* svc)
26: RootEventBaseCnv(classID(), svc)
27{
28 // Here we associate this converter with the /Event path on the TDS.
29 MsgStream log(msgSvc(), "CgemMcHitCnv");
30 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
31 m_rootBranchname ="m_cgemMcHitCol";
32 //declareObject(EventModel::MC::CgemMcHitCol, objType(), m_rootTreename, m_rootBranchname);
33 m_adresses.push_back(&m_cgemMcHitCol);
34 m_cgemMcHitCol=0;
35}
36
37StatusCode CgemMcHitCnv::TObjectToDataObject(DataObject*& refpObject) {
38 // creation of TDS object from root object
39
40 MsgStream log(msgSvc(), "CgemMcHitCnv");
41 log << MSG::DEBUG << "CgemMcHitCnv::TObjectToDataObject" << endreq;
42 StatusCode sc=StatusCode::SUCCESS;
43
44 // create the TDS location for the CgemMc Collection
45 CgemMcHitCol* cgemMcTdsCol = new CgemMcHitCol;
46 refpObject=cgemMcTdsCol;
47
48
49 // now convert
50 if (!m_cgemMcHitCol) return sc;
51 TIter cgemMcIter(m_cgemMcHitCol);
52 TCgemMc *cgemMcRoot = 0;
53 while ((cgemMcRoot = (TCgemMc*)cgemMcIter.Next()))
54 {
55 unsigned int ID_track = cgemMcRoot->GetTrackID ();
56 unsigned int ID_layer = cgemMcRoot->GetLayerID ();
57 //Add by sunxh
58 unsigned int pdg_code = cgemMcRoot->GetPDGCode ();
59 unsigned int ID_parent = cgemMcRoot->GetParentID ();
60 //end
61 double E_deposit = cgemMcRoot->GetTotalEnergyDeposit ();
62 double XYZ_pre_x = cgemMcRoot->GetPositionXOfPrePoint ();
63 double XYZ_pre_y = cgemMcRoot->GetPositionYOfPrePoint ();
64 double XYZ_pre_z = cgemMcRoot->GetPositionZOfPrePoint ();
65 double XYZ_post_x = cgemMcRoot->GetPositionXOfPostPoint ();
66 double XYZ_post_y = cgemMcRoot->GetPositionYOfPostPoint ();
67 double XYZ_post_z = cgemMcRoot->GetPositionZOfPostPoint ();
68 double P_pre_x = cgemMcRoot->GetMomentumXOfPrePoint ();
69 double P_pre_y = cgemMcRoot->GetMomentumYOfPrePoint ();
70 double P_pre_z = cgemMcRoot->GetMomentumZOfPrePoint ();
71 double P_post_x = cgemMcRoot->GetMomentumXOfPostPoint ();
72 double P_post_y = cgemMcRoot->GetMomentumYOfPostPoint ();
73 double P_post_z = cgemMcRoot->GetMomentumZOfPostPoint ();
74 //Add by sunxh
75 TArrayI ID_Identifier = cgemMcRoot->GetIdentifier ();
76 //end
77 TString creatorProcess = cgemMcRoot->GetCreatorProcess();
78
79 //log << MSG::INFO << "My Message::CgemMcHitCnv::TObjectToDataObject::idMSB="<<idMSB<<" idLSB="<<idLSB<<",trackID="<<trackIndex<<",edep="<<depositEnergy <<" x="<<xPosition<<" y="<<yPosition<<" z="<<zPosition<< endreq;
80
81 CgemMcHit *cgemMcTds = new CgemMcHit;
82 m_common.m_rootCgemMcHitMap[cgemMcRoot] = cgemMcTds;
83
84 cgemMcTds->SetTrackID ( ID_track );
85 cgemMcTds->SetLayerID ( ID_layer );
86 //Add by sunxh
87 cgemMcTds->SetPDGCode ( pdg_code );
88 cgemMcTds->SetParentID ( ID_parent );
89 //end
90 cgemMcTds->SetTotalEnergyDeposit ( E_deposit );
91 cgemMcTds->SetPositionXOfPrePoint ( XYZ_pre_x );
92 cgemMcTds->SetPositionYOfPrePoint ( XYZ_pre_y );
93 cgemMcTds->SetPositionZOfPrePoint ( XYZ_pre_z );
94 cgemMcTds->SetPositionXOfPostPoint ( XYZ_post_x );
95 cgemMcTds->SetPositionYOfPostPoint ( XYZ_post_y );
96 cgemMcTds->SetPositionZOfPostPoint ( XYZ_post_z );
97 cgemMcTds->SetMomentumXOfPrePoint ( P_pre_x );
98 cgemMcTds->SetMomentumYOfPrePoint ( P_pre_y );
99 cgemMcTds->SetMomentumZOfPrePoint ( P_pre_z );
100 cgemMcTds->SetMomentumXOfPostPoint ( P_post_x );
101 cgemMcTds->SetMomentumYOfPostPoint ( P_post_y );
102 cgemMcTds->SetMomentumZOfPostPoint ( P_post_z );
103 cgemMcTds->SetCreatorProcess ( creatorProcess.Data());
104 //Add by sunxh
105 int tmp[2000];
106 for(int j = 0; j < ID_Identifier.GetSize(); j++){
107 tmp[j] = ID_Identifier.GetAt(j);
108 }
109 cgemMcTds->AddIdentifier(tmp, ID_Identifier.GetSize());
110 //end
111 cgemMcTdsCol->push_back(cgemMcTds);
112 }
113 //m_cgemMcHitCol->Delete(); // wensp add 2005/12/30
114 delete m_cgemMcHitCol;
115 m_cgemMcHitCol = 0;
116 return StatusCode::SUCCESS;
117}
118
119StatusCode CgemMcHitCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
120
121 MsgStream log(msgSvc(), "CgemMcHitCnv");
122 log << MSG::DEBUG << "CgemMcHitCnv::DataObjectToTObject" << endreq;
123 StatusCode sc=StatusCode::SUCCESS;
124
125 CgemMcHitCol * cgemMcHitCnvTds=dynamic_cast<CgemMcHitCol *> (obj);
126 if (!cgemMcHitCnvTds) {
127 log << MSG::ERROR << "Could not downcast to CgemMcHitCol" << endreq;
128 return StatusCode::FAILURE;
129 }
130
131 DataObject *evt;
132 m_eds->findObject(EventModel::MC::Event,evt);
133 if (evt==NULL) {
134 log << MSG::ERROR << "Could not get McEvent in TDS " << endreq;
135 return StatusCode::FAILURE;
136 }
137 McEvent * devtTds=dynamic_cast<McEvent *> (evt);
138 if (!devtTds) {
139 log << MSG::ERROR << "CgemMcHitCnv:Could not downcast to TDS McEvent" << endreq;
140 }
141 IOpaqueAddress *addr;
142
143 m_cnvSvc->getMcCnv()->createRep(evt,addr);
145
146 const TObjArray *m_cgemMcHitCol = McEvt->getCgemMcHitCol();
147 if (!m_cgemMcHitCol) return sc;
148 McEvt->clearCgemMcHitCol(); //necessary in case there is I/O at the same time since array is static
149 CgemMcHitCol::const_iterator cgemMcTds;
150
151 for (cgemMcTds = cgemMcHitCnvTds->begin(); cgemMcTds != cgemMcHitCnvTds->end(); cgemMcTds++)
152 {
153 unsigned int ID_track = (*cgemMcTds)->GetTrackID ();
154 unsigned int ID_layer = (*cgemMcTds)->GetLayerID ();
155 //Add by sunxh
156 unsigned int pdg_code = (*cgemMcTds)->GetPDGCode ();
157 unsigned int ID_parent = (*cgemMcTds)->GetParentID ();
158 //end
159 double E_deposit = (*cgemMcTds)->GetTotalEnergyDeposit ();
160 double XYZ_pre_x = (*cgemMcTds)->GetPositionXOfPrePoint ();
161 double XYZ_pre_y = (*cgemMcTds)->GetPositionYOfPrePoint ();
162 double XYZ_pre_z = (*cgemMcTds)->GetPositionZOfPrePoint ();
163 double XYZ_post_x = (*cgemMcTds)->GetPositionXOfPostPoint ();
164 double XYZ_post_y = (*cgemMcTds)->GetPositionYOfPostPoint ();
165 double XYZ_post_z = (*cgemMcTds)->GetPositionZOfPostPoint ();
166 double P_pre_x = (*cgemMcTds)->GetMomentumXOfPrePoint ();
167 double P_pre_y = (*cgemMcTds)->GetMomentumYOfPrePoint ();
168 double P_pre_z = (*cgemMcTds)->GetMomentumZOfPrePoint ();
169 double P_post_x = (*cgemMcTds)->GetMomentumXOfPostPoint ();
170 double P_post_y = (*cgemMcTds)->GetMomentumYOfPostPoint ();
171 double P_post_z = (*cgemMcTds)->GetMomentumZOfPostPoint ();
172 //Add by sunxh
173 TArrayI ID_Identifier = (*cgemMcTds)->GetIdentifier ();
174 //end
175 string creatorProcess = (*cgemMcTds)->GetCreatorProcess();
176
177 //log << MSG::INFO << "My Message::CgemMcHitCnv::DataObjectToTObject::idMSB="<<idMSB<<" idLSB="<<idLSB<<",trackID="<<trackIndex<<",edep="<<depositEnergy <<" x="<<xPosition<<" y="<<yPosition<<" z="<<zPosition<< endreq;
178
179 TCgemMc *cgemMcRoot = new TCgemMc();
180 //m_common.m_cgemMcHitMap[(*cgemMcTds)] = cgemMcRoot;
181
182 cgemMcRoot->SetTrackID ( ID_track );
183 cgemMcRoot->SetLayerID ( ID_layer );
184 cgemMcRoot->SetPDGCode ( pdg_code );
185 cgemMcRoot->SetParentID ( ID_parent );
186 cgemMcRoot->SetTotalEnergyDeposit ( E_deposit );
187 cgemMcRoot->SetPositionXOfPrePoint ( XYZ_pre_x );
188 cgemMcRoot->SetPositionYOfPrePoint ( XYZ_pre_y );
189 cgemMcRoot->SetPositionZOfPrePoint ( XYZ_pre_z );
190 cgemMcRoot->SetPositionXOfPostPoint ( XYZ_post_x );
191 cgemMcRoot->SetPositionYOfPostPoint ( XYZ_post_y );
192 cgemMcRoot->SetPositionZOfPostPoint ( XYZ_post_z );
193 cgemMcRoot->SetMomentumXOfPrePoint ( P_pre_x );
194 cgemMcRoot->SetMomentumYOfPrePoint ( P_pre_y );
195 cgemMcRoot->SetMomentumZOfPrePoint ( P_pre_z );
196 cgemMcRoot->SetMomentumXOfPostPoint ( P_post_x );
197 cgemMcRoot->SetMomentumYOfPostPoint ( P_post_y );
198 cgemMcRoot->SetMomentumZOfPostPoint ( P_post_z );
199 //Add by sunxh
200 int tmp[2000];
201 for(int j = 0; j < ID_Identifier.GetSize(); j++){
202 tmp[j] = ID_Identifier.GetAt(j);
203 }
204 cgemMcRoot->AddIdentifier(tmp, ID_Identifier.GetSize());
205 //end
206 cgemMcRoot->SetCreatorProcess(creatorProcess);
207 McEvt->addCgemMc(cgemMcRoot);
208 }
209
210 return StatusCode::SUCCESS;
211}
212#endif
213
214
215
216
217
218
219
220
221
222
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
static TMcEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition of a Root address, derived from IOpaqueAddress.
virtual StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress)
Convert the transient object to the requested representation.
void AddIdentifier(Int_t f_ID_Identifier[2000], Int_t N_dim)
void addCgemMc(TCgemMc *mcHit)
Cgem.
static std::map< const TObject *, const CgemMcHit * > m_rootCgemMcHitMap
ObjectVector< CgemMcHit > CgemMcHitCol