CGEM BOSS 6.6.5.h
BESIII Offline Software System
Loading...
Searching...
No Matches
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
12#include "McTruth/McEvent.h" //TDS object
13#include "McTruth/CgemMcHit.h" //TDS object
14#include "RootEventData/TCgemMc.h" // standard root object
16#include "RootCnvSvc/Mc/McCnv.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
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
37// --- root to tds
38StatusCode CgemMcHitCnv::TObjectToDataObject(DataObject*& refpObject) {
39 // creation of TDS object from root object
40
41 MsgStream log(msgSvc(), "CgemMcHitCnv");
42 log << MSG::DEBUG << "CgemMcHitCnv::TObjectToDataObject" << endreq;
43 StatusCode sc=StatusCode::SUCCESS;
44
45 // create the TDS location for the CgemMc Collection
46 CgemMcHitCol* cgemMcTdsCol = new CgemMcHitCol;
47 refpObject=cgemMcTdsCol;
48
49
50 // now convert
51 if (!m_cgemMcHitCol) return sc;
52 TIter cgemMcIter(m_cgemMcHitCol);
53 TCgemMc *cgemMcRoot = 0;
54 while ((cgemMcRoot = (TCgemMc*)cgemMcIter.Next()))
55 {
56 unsigned int ID_track = cgemMcRoot->GetTrackID ();
57 unsigned int ID_layer = cgemMcRoot->GetLayerID ();
58 //Add by sunxh
59 unsigned int pdg_code = cgemMcRoot->GetPDGCode ();
60 unsigned int ID_parent = cgemMcRoot->GetParentID ();
61 //end
62 double E_deposit = cgemMcRoot->GetTotalEnergyDeposit ();
63 double XYZ_pre_x = cgemMcRoot->GetPositionXOfPrePoint ();
64 double XYZ_pre_y = cgemMcRoot->GetPositionYOfPrePoint ();
65 double XYZ_pre_z = cgemMcRoot->GetPositionZOfPrePoint ();
66 double XYZ_post_x = cgemMcRoot->GetPositionXOfPostPoint ();
67 double XYZ_post_y = cgemMcRoot->GetPositionYOfPostPoint ();
68 double XYZ_post_z = cgemMcRoot->GetPositionZOfPostPoint ();
69 double P_pre_x = cgemMcRoot->GetMomentumXOfPrePoint ();
70 double P_pre_y = cgemMcRoot->GetMomentumYOfPrePoint ();
71 double P_pre_z = cgemMcRoot->GetMomentumZOfPrePoint ();
72 double P_post_x = cgemMcRoot->GetMomentumXOfPostPoint ();
73 double P_post_y = cgemMcRoot->GetMomentumYOfPostPoint ();
74 double P_post_z = cgemMcRoot->GetMomentumZOfPostPoint ();
75 //Add by sunxh
76 TArrayI ID_Identifier = cgemMcRoot->GetIdentifier ();
77 //end
78 TString creatorProcess = cgemMcRoot->GetCreatorProcess();
79 unsigned int isSecondary= cgemMcRoot->GetIsSecondary();
80 double trkLen_pre = cgemMcRoot->GetFlightLengthPrePoint();
81 double trkLen_post= cgemMcRoot->GetFlightLengthPostPoint();
82 const vector<int>& DigiIdxVec = cgemMcRoot->GetDigiIdxVec();
83 const vector<int>& XclusterIdxVec = cgemMcRoot->GetXclusterIdxVec();
84 const vector<int>& VclusterIdxVec = cgemMcRoot->GetVclusterIdxVec();
85
86 //log << MSG::INFO << "My Message::CgemMcHitCnv::TObjectToDataObject::idMSB="<<idMSB<<" idLSB="<<idLSB<<",trackID="<<trackIndex<<",edep="<<depositEnergy <<" x="<<xPosition<<" y="<<yPosition<<" z="<<zPosition<< endreq;
87
88 CgemMcHit *cgemMcTds = new CgemMcHit;
89 m_common.m_rootCgemMcHitMap[cgemMcRoot] = cgemMcTds;
90
91 cgemMcTds->SetTrackID ( ID_track );
92 cgemMcTds->SetLayerID ( ID_layer );
93 //Add by sunxh
94 cgemMcTds->SetPDGCode ( pdg_code );
95 cgemMcTds->SetParentID ( ID_parent );
96 //end
97 cgemMcTds->SetTotalEnergyDeposit ( E_deposit );
98 cgemMcTds->SetPositionXOfPrePoint ( XYZ_pre_x );
99 cgemMcTds->SetPositionYOfPrePoint ( XYZ_pre_y );
100 cgemMcTds->SetPositionZOfPrePoint ( XYZ_pre_z );
101 cgemMcTds->SetPositionXOfPostPoint ( XYZ_post_x );
102 cgemMcTds->SetPositionYOfPostPoint ( XYZ_post_y );
103 cgemMcTds->SetPositionZOfPostPoint ( XYZ_post_z );
104 cgemMcTds->SetMomentumXOfPrePoint ( P_pre_x );
105 cgemMcTds->SetMomentumYOfPrePoint ( P_pre_y );
106 cgemMcTds->SetMomentumZOfPrePoint ( P_pre_z );
107 cgemMcTds->SetMomentumXOfPostPoint ( P_post_x );
108 cgemMcTds->SetMomentumYOfPostPoint ( P_post_y );
109 cgemMcTds->SetMomentumZOfPostPoint ( P_post_z );
110 cgemMcTds->SetCreatorProcess ( creatorProcess.Data());
111 //Add by sunxh
112 int tmp[2000];
113 for(int j = 0; j < ID_Identifier.GetSize(); j++){
114 tmp[j] = ID_Identifier.GetAt(j);
115 }
116 cgemMcTds->AddIdentifier(tmp, ID_Identifier.GetSize());
117 //end
118 cgemMcTds->SetIsSecondary(isSecondary);
119 cgemMcTds->SetFlightLengthPrePoint(trkLen_pre);
120 cgemMcTds->SetFlightLengthPostPoint(trkLen_post);
121 cgemMcTds->SetDigiIdxVec(DigiIdxVec);
122 cgemMcTds->SetXclusterIdxVec(XclusterIdxVec);
123 cgemMcTds->SetVclusterIdxVec(VclusterIdxVec);
124 cgemMcTdsCol->push_back(cgemMcTds);
125 }
126 //m_cgemMcHitCol->Delete(); // wensp add 2005/12/30
127 delete m_cgemMcHitCol;
128 m_cgemMcHitCol = 0;
129 return StatusCode::SUCCESS;
130}
131
132// --- tds to root
133StatusCode CgemMcHitCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
134
135 MsgStream log(msgSvc(), "CgemMcHitCnv");
136 log << MSG::DEBUG << "CgemMcHitCnv::DataObjectToTObject" << endreq;
137 StatusCode sc=StatusCode::SUCCESS;
138
139 CgemMcHitCol * cgemMcHitCnvTds=dynamic_cast<CgemMcHitCol *> (obj);
140 if (!cgemMcHitCnvTds) {
141 log << MSG::ERROR << "Could not downcast to CgemMcHitCol" << endreq;
142 return StatusCode::FAILURE;
143 }
144
145 DataObject *evt;
146 m_eds->findObject(EventModel::MC::Event,evt);
147 if (evt==NULL) {
148 log << MSG::ERROR << "Could not get McEvent in TDS " << endreq;
149 return StatusCode::FAILURE;
150 }
151 McEvent * devtTds=dynamic_cast<McEvent *> (evt);
152 if (!devtTds) {
153 log << MSG::ERROR << "CgemMcHitCnv:Could not downcast to TDS McEvent" << endreq;
154 }
155 IOpaqueAddress *addr;
156
157 m_cnvSvc->getMcCnv()->createRep(evt,addr);
159
160 const TObjArray *m_cgemMcHitCol = McEvt->getCgemMcHitCol();
161 if (!m_cgemMcHitCol) return sc;
162 McEvt->clearCgemMcHitCol(); //necessary in case there is I/O at the same time since array is static
163 CgemMcHitCol::const_iterator cgemMcTds;
164
165 for (cgemMcTds = cgemMcHitCnvTds->begin(); cgemMcTds != cgemMcHitCnvTds->end(); cgemMcTds++)
166 {
167 unsigned int ID_track = (*cgemMcTds)->GetTrackID ();
168 unsigned int ID_layer = (*cgemMcTds)->GetLayerID ();
169 //Add by sunxh
170 unsigned int pdg_code = (*cgemMcTds)->GetPDGCode ();
171 unsigned int ID_parent = (*cgemMcTds)->GetParentID ();
172 //end
173 double E_deposit = (*cgemMcTds)->GetTotalEnergyDeposit ();
174 double XYZ_pre_x = (*cgemMcTds)->GetPositionXOfPrePoint ();
175 double XYZ_pre_y = (*cgemMcTds)->GetPositionYOfPrePoint ();
176 double XYZ_pre_z = (*cgemMcTds)->GetPositionZOfPrePoint ();
177 double XYZ_post_x = (*cgemMcTds)->GetPositionXOfPostPoint ();
178 double XYZ_post_y = (*cgemMcTds)->GetPositionYOfPostPoint ();
179 double XYZ_post_z = (*cgemMcTds)->GetPositionZOfPostPoint ();
180 double P_pre_x = (*cgemMcTds)->GetMomentumXOfPrePoint ();
181 double P_pre_y = (*cgemMcTds)->GetMomentumYOfPrePoint ();
182 double P_pre_z = (*cgemMcTds)->GetMomentumZOfPrePoint ();
183 double P_post_x = (*cgemMcTds)->GetMomentumXOfPostPoint ();
184 double P_post_y = (*cgemMcTds)->GetMomentumYOfPostPoint ();
185 double P_post_z = (*cgemMcTds)->GetMomentumZOfPostPoint ();
186 //Add by sunxh
187 TArrayI ID_Identifier = (*cgemMcTds)->GetIdentifier ();
188 //end
189 string creatorProcess = (*cgemMcTds)->GetCreatorProcess();
190 unsigned int isSecondary= (*cgemMcTds)->GetIsSecondary();
191 double trkLen_pre = (*cgemMcTds)->GetFlightLengthPrePoint();
192 double trkLen_post= (*cgemMcTds)->GetFlightLengthPostPoint();
193 const vector<int>& DigiIdxVec = (*cgemMcTds)->GetDigiIdxVec();
194 const vector<int>& XclusterIdxVec= (*cgemMcTds)->GetXclusterIdxVec();
195 const vector<int>& VclusterIdxVec= (*cgemMcTds)->GetVclusterIdxVec();
196
197 //log << MSG::INFO << "My Message::CgemMcHitCnv::DataObjectToTObject::idMSB="<<idMSB<<" idLSB="<<idLSB<<",trackID="<<trackIndex<<",edep="<<depositEnergy <<" x="<<xPosition<<" y="<<yPosition<<" z="<<zPosition<< endreq;
198
199 TCgemMc *cgemMcRoot = new TCgemMc();
200 //m_common.m_cgemMcHitMap[(*cgemMcTds)] = cgemMcRoot;
201
202 cgemMcRoot->SetTrackID ( ID_track );
203 cgemMcRoot->SetLayerID ( ID_layer );
204 cgemMcRoot->SetPDGCode ( pdg_code );
205 cgemMcRoot->SetParentID ( ID_parent );
206 cgemMcRoot->SetTotalEnergyDeposit ( E_deposit );
207 cgemMcRoot->SetPositionXOfPrePoint ( XYZ_pre_x );
208 cgemMcRoot->SetPositionYOfPrePoint ( XYZ_pre_y );
209 cgemMcRoot->SetPositionZOfPrePoint ( XYZ_pre_z );
210 cgemMcRoot->SetPositionXOfPostPoint ( XYZ_post_x );
211 cgemMcRoot->SetPositionYOfPostPoint ( XYZ_post_y );
212 cgemMcRoot->SetPositionZOfPostPoint ( XYZ_post_z );
213 cgemMcRoot->SetMomentumXOfPrePoint ( P_pre_x );
214 cgemMcRoot->SetMomentumYOfPrePoint ( P_pre_y );
215 cgemMcRoot->SetMomentumZOfPrePoint ( P_pre_z );
216 cgemMcRoot->SetMomentumXOfPostPoint ( P_post_x );
217 cgemMcRoot->SetMomentumYOfPostPoint ( P_post_y );
218 cgemMcRoot->SetMomentumZOfPostPoint ( P_post_z );
219 //Add by sunxh
220 int tmp[2000];
221 for(int j = 0; j < ID_Identifier.GetSize(); j++){
222 tmp[j] = ID_Identifier.GetAt(j);
223 }
224 cgemMcRoot->AddIdentifier(tmp, ID_Identifier.GetSize());
225 //end
226 cgemMcRoot->SetCreatorProcess(creatorProcess);
227 cgemMcRoot->SetIsSecondary(isSecondary);
228 cgemMcRoot->SetFlightLengthPrePoint(trkLen_pre);
229 cgemMcRoot->SetFlightLengthPostPoint(trkLen_post);
230 cgemMcRoot->SetDigiIdxVec(DigiIdxVec);
231 cgemMcRoot->SetXclusterIdxVec(XclusterIdxVec);
232 cgemMcRoot->SetVclusterIdxVec(VclusterIdxVec);
233 McEvt->addCgemMc(cgemMcRoot);
234 }
235
236 return StatusCode::SUCCESS;
237}
238#endif
239
240
241
242
243
244
245
246
247
248
IMessageSvc * msgSvc()
CgemMcHitCnv(ISvcLocator *svc)
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
void SetMomentumXOfPostPoint(double f_P_post_x)
Definition CgemMcHit.h:65
void SetMomentumZOfPostPoint(double f_P_post_z)
Definition CgemMcHit.h:67
void AddIdentifier(Int_t f_ID_Identifier[2000], Int_t N_dim)
Definition CgemMcHit.h:73
void SetFlightLengthPrePoint(double f_len)
Definition CgemMcHit.h:68
void SetPositionXOfPrePoint(double f_XYZ_pre_x)
Definition CgemMcHit.h:56
void SetPositionZOfPrePoint(double f_XYZ_pre_z)
Definition CgemMcHit.h:58
void SetXclusterIdxVec(const vector< int > &vec)
Definition CgemMcHit.h:79
void SetIsSecondary(int isSec)
Definition CgemMcHit.h:51
void SetDigiIdxVec(const vector< int > &vec)
Definition CgemMcHit.h:78
void SetMomentumYOfPostPoint(double f_P_post_y)
Definition CgemMcHit.h:66
void SetFlightLengthPostPoint(double f_len)
Definition CgemMcHit.h:69
void SetMomentumZOfPrePoint(double f_P_pre_z)
Definition CgemMcHit.h:64
void SetParentID(int f_ID_parent)
Definition CgemMcHit.h:54
void SetTrackID(int f_ID_track)
Definition CgemMcHit.h:49
void SetMomentumXOfPrePoint(double f_P_pre_x)
Definition CgemMcHit.h:62
void SetPositionXOfPostPoint(double f_XYZ_post_x)
Definition CgemMcHit.h:59
void SetPositionYOfPrePoint(double f_XYZ_pre_y)
Definition CgemMcHit.h:57
void SetVclusterIdxVec(const vector< int > &vec)
Definition CgemMcHit.h:80
void SetCreatorProcess(string creatorProcess)
Definition CgemMcHit.h:74
void SetTotalEnergyDeposit(double f_E_deposit)
Definition CgemMcHit.h:55
void SetPositionYOfPostPoint(double f_XYZ_post_y)
Definition CgemMcHit.h:60
void SetLayerID(int f_ID_layer)
Definition CgemMcHit.h:52
void SetPositionZOfPostPoint(double f_XYZ_post_z)
Definition CgemMcHit.h:61
void SetMomentumYOfPrePoint(double f_P_pre_y)
Definition CgemMcHit.h:63
void SetPDGCode(int pdg)
Definition CgemMcHit.h:53
static TMcEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition McCnv.h:35
Definition of a Root address, derived from IOpaqueAddress.
Definition RootAddress.h:21
McCnv * getMcCnv()
Definition RootCnvSvc.h:149
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.
void SetIsSecondary(UInt_t isSec)
Definition TCgemMc.h:35
Double_t GetPositionXOfPrePoint() const
Definition TCgemMc.h:66
Double_t GetMomentumYOfPostPoint() const
Definition TCgemMc.h:76
void AddIdentifier(Int_t f_ID_Identifier[2000], Int_t N_dim)
Definition TCgemMc.h:56
void SetMomentumZOfPrePoint(Double_t f_P_pre_z)
Definition TCgemMc.h:31
Double_t GetMomentumYOfPrePoint() const
Definition TCgemMc.h:73
Double_t GetPositionYOfPrePoint() const
Definition TCgemMc.h:67
UInt_t GetPDGCode() const
Definition TCgemMc.h:63
Double_t GetPositionZOfPostPoint() const
Definition TCgemMc.h:71
void SetMomentumYOfPostPoint(Double_t f_P_post_y)
Definition TCgemMc.h:33
void SetPositionZOfPostPoint(Double_t f_XYZ_post_z)
Definition TCgemMc.h:28
Double_t GetPositionZOfPrePoint() const
Definition TCgemMc.h:68
Double_t GetFlightLengthPrePoint() const
Definition TCgemMc.h:79
void SetMomentumXOfPrePoint(Double_t f_P_pre_x)
Definition TCgemMc.h:29
void SetCreatorProcess(std::string creatorProcess)
Definition TCgemMc.h:57
void SetVclusterIdxVec(const std::vector< int > &vec)
Definition TCgemMc.h:40
void SetParentID(UInt_t f_ID_parent)
Definition TCgemMc.h:21
void SetPositionXOfPrePoint(Double_t f_XYZ_pre_x)
Definition TCgemMc.h:23
Double_t GetMomentumZOfPostPoint() const
Definition TCgemMc.h:77
void SetTrackID(UInt_t f_ID_track)
Definition TCgemMc.h:18
UInt_t GetTrackID() const
Definition TCgemMc.h:61
void SetPositionZOfPrePoint(Double_t f_XYZ_pre_z)
Definition TCgemMc.h:25
void SetMomentumYOfPrePoint(Double_t f_P_pre_y)
Definition TCgemMc.h:30
void SetLayerID(UInt_t f_ID_layer)
Definition TCgemMc.h:19
const std::vector< int > & GetXclusterIdxVec() const
Definition TCgemMc.h:82
UInt_t GetIsSecondary() const
Definition TCgemMc.h:78
void SetPDGCode(UInt_t f_pdg_code)
Definition TCgemMc.h:20
void SetPositionYOfPrePoint(Double_t f_XYZ_pre_y)
Definition TCgemMc.h:24
Double_t GetMomentumXOfPostPoint() const
Definition TCgemMc.h:75
UInt_t GetLayerID() const
Definition TCgemMc.h:62
const std::vector< int > & GetDigiIdxVec() const
Definition TCgemMc.h:81
Double_t GetMomentumZOfPrePoint() const
Definition TCgemMc.h:74
Double_t GetPositionYOfPostPoint() const
Definition TCgemMc.h:70
void SetPositionYOfPostPoint(Double_t f_XYZ_post_y)
Definition TCgemMc.h:27
Double_t GetPositionXOfPostPoint() const
Definition TCgemMc.h:69
Double_t GetTotalEnergyDeposit() const
Definition TCgemMc.h:65
void SetPositionXOfPostPoint(Double_t f_XYZ_post_x)
Definition TCgemMc.h:26
UInt_t GetParentID() const
Definition TCgemMc.h:64
Double_t GetFlightLengthPostPoint() const
Definition TCgemMc.h:80
void SetMomentumXOfPostPoint(Double_t f_P_post_x)
Definition TCgemMc.h:32
void SetXclusterIdxVec(const std::vector< int > &vec)
Definition TCgemMc.h:39
void SetMomentumZOfPostPoint(Double_t f_P_post_z)
Definition TCgemMc.h:34
void SetFlightLengthPrePoint(Double_t f_len)
Definition TCgemMc.h:36
void SetDigiIdxVec(const std::vector< int > &vec)
Definition TCgemMc.h:38
Double_t GetMomentumXOfPrePoint() const
Definition TCgemMc.h:72
TArrayI GetIdentifier() const
Definition TCgemMc.h:99
void SetFlightLengthPostPoint(Double_t f_len)
Definition TCgemMc.h:37
const std::vector< int > & GetVclusterIdxVec() const
Definition TCgemMc.h:83
void SetTotalEnergyDeposit(Double_t f_E_deposit)
Definition TCgemMc.h:22
TString GetCreatorProcess() const
Definition TCgemMc.h:100
const TObjArray * getCgemMcHitCol() const
Definition TMcEvent.h:38
void addCgemMc(TCgemMc *mcHit)
Cgem.
Definition TMcEvent.cxx:124
void clearCgemMcHitCol()
Definition TMcEvent.h:41
static std::map< const TObject *, const CgemMcHit * > m_rootCgemMcHitMap
Definition commonData.h:205
_EXTERN_ std::string Event
Definition EventModel.h:39
ObjectVector< CgemMcHit > CgemMcHitCol
Definition CgemMcHit.h:186