CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
RootCnvSvc-04-01-15/src/Dst/CgemDedxCnv.cxx
Go to the documentation of this file.
1#ifndef DedxCnv_CXX
2#define DedxCnv_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#include "EventModel/EventModel.h"
11#include "DstEvent/DstEvent.h" //TDS object
12#include "DstEvent/DstCgemDedx.h" //TDS object
13#include "RootEventData/TCgemDedx.h" // standard root object
14#include "RootEventData/TDstEvent.h"
15
16#include "RootCnvSvc/Dst/DstCnv.h"
17#include "RootCnvSvc/Dst/CgemDedxCnv.h"
18#include "RootCnvSvc/RootAddress.h"
19
20
21// Instantiation of a static factory class used by clients to create
22// instances of this service
23//static CnvFactory<DedxCnv> s_factory;
24//const ICnvFactory& DedxCnvFactory = s_factory;
25
26CgemDedxCnv::CgemDedxCnv(ISvcLocator* svc)
27: RootEventBaseCnv(classID(), svc)
28{
29 // Here we associate this converter with the /Event path on the TDS.
30 MsgStream log(msgSvc(), "CgemDedxCnv");
31 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
32 m_rootBranchname ="m_cgemDedxCol";
33 //declareObject(EventModel::Dst::DstDedxCol, objType(), m_rootTreename, m_rootBranchname);
34 m_adresses.push_back(&m_cgemDedxCol);
35 m_cgemDedxCol=0;
36}
37
38StatusCode CgemDedxCnv::TObjectToDataObject(DataObject*& refpObject) {
39 // creation of TDS object from root object
40
41 MsgStream log(msgSvc(), "CgemDedxCnv");
42 log << MSG::DEBUG << "CgemDedxCnv::TObjectToDataObject" << endreq;
43 StatusCode sc=StatusCode::SUCCESS;
44
45 // create the TDS location for the Dedx Collection
46 DstCgemDedxCol* cgemDedxTdsCol = new DstCgemDedxCol;
47 refpObject=cgemDedxTdsCol;
48
49
50 // now convert
51 if (!m_cgemDedxCol) return sc;
52 TIter cgemDedxIter(m_cgemDedxCol);
53 TCgemDedx *cgemDedxRoot = 0;
54 while ((cgemDedxRoot = (TCgemDedx*)cgemDedxIter.Next())) {
55
56 int trackId = cgemDedxRoot->trackId();
57 int particleId = cgemDedxRoot->particleId();
58 int status = cgemDedxRoot->status();
59 int truncAlg = cgemDedxRoot->truncAlg();
60 /*
61 double pb[5];
62 for ( int i = 0; i < 5; i++)
63 pb[i] = dedxRoot->prob(i);
64
65 double numSigmaE = dedxRoot->numSigmaE();
66 double numSigmaMu = dedxRoot->numSigmaMu();
67 double numSigmaPi = dedxRoot->numSigmaPi();
68 double numSigmaK = dedxRoot->numSigmaK();
69 double numSigmaP = dedxRoot->numSigmaP();
70 */
71 double chi[5];
72 chi[0] = cgemDedxRoot->chiE();
73 chi[1] = cgemDedxRoot->chiMu();
74 chi[2] = cgemDedxRoot->chiPi();
75 chi[3] = cgemDedxRoot->chiK();
76 chi[4] = cgemDedxRoot->chiP();
77 int numGoodHits = cgemDedxRoot->numGoodHits();
78 int numTotalHits = cgemDedxRoot->numTotalHits();
79
80 double probPH = cgemDedxRoot->probPH();
81 double normPH = cgemDedxRoot->normPH();
82 double errorPH = cgemDedxRoot->errorPH();
83 double twentyPH = cgemDedxRoot->twentyPH();
84 //double fracErrPH = dedxRoot-> fracErrPH();
85 //double minIronPH = dedxRoot->minIronPH();
86 //double corrPH = dedxRoot->corrPH();
87
88 DstCgemDedx *cgemDedxTds = new DstCgemDedx();
89 m_common.m_rootCgemDedxMap[cgemDedxRoot] = cgemDedxTds;
90
91 cgemDedxTds->setTrackId(trackId);
92 cgemDedxTds->setParticleId(particleId);
93 cgemDedxTds->setStatus (status);
94 cgemDedxTds->setTruncAlg(truncAlg);
95 /*
96 dedxTds->setProb(pb);
97 dedxTds->setNumSigmaE(numSigmaE);
98 dedxTds->setNumSigmaMu(numSigmaMu);
99 dedxTds->setNumSigmaPi(numSigmaPi);
100 dedxTds->setNumSigmaK(numSigmaK);
101 dedxTds->setNumSigmaP(numSigmaP);
102 */
103 cgemDedxTds->setChi(chi);
104
105 cgemDedxTds->setNumGoodHits( numGoodHits);
106 cgemDedxTds->setNumTotalHits( numTotalHits);
107
108 cgemDedxTds->setProbPH(probPH);
109 cgemDedxTds->setNormPH(normPH);
110 cgemDedxTds->setErrorPH(errorPH);
111 cgemDedxTds->setTwentyPH(twentyPH);
112 //dedxTds->setFracErrPH(fracErrPH);
113 //dedxTds->setMinIronPH(minIronPH);
114 //dedxTds->setCorrPH(corrPH);
115
116 cgemDedxTdsCol->push_back(cgemDedxTds);
117 //delete dedxTds;
118 // dedxTds = NULL;
119 }
120 //m_dedxCol->Delete();
121 delete m_cgemDedxCol;
122 m_cgemDedxCol = 0;
123 return StatusCode::SUCCESS;
124}
125
126StatusCode CgemDedxCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
127
128 MsgStream log(msgSvc(), "CgemDedxCnv");
129 log << MSG::DEBUG << "CgemDedxCnv::DataObjectToTObject" << endreq;
130 StatusCode sc=StatusCode::SUCCESS;
131
132 DstCgemDedxCol * cgemDedxColTds=dynamic_cast<DstCgemDedxCol *> (obj);
133 if (!cgemDedxColTds) {
134 log << MSG::ERROR << "Could not downcast to CgemDedxCol" << endreq;
135 return StatusCode::FAILURE;
136 }
137
138 DataObject *evt;
139 m_eds->findObject(EventModel::Dst::Event,evt);
140 if (evt==NULL) {
141 log << MSG::ERROR << "Could not get DstEvent in TDS " << endreq;
142 return StatusCode::FAILURE;
143 }
144 DstEvent * devtTds=dynamic_cast<DstEvent *> (evt);
145 if (!devtTds) {
146 log << MSG::ERROR << "CgemDedxCnv:Could not downcast to TDS DstEvent" << endreq;
147 }
148 IOpaqueAddress *addr;
149
150 m_cnvSvc->getDstCnv()->createRep(evt,addr);
152
153 const TObjArray *m_cgemDedxCol = recEvt->getCgemDedxCol();
154 if (!m_cgemDedxCol) return sc;
155 recEvt->clearCgemDedxCol(); //necessary in case there is I/O at the same time since array is static
156 DstCgemDedxCol::const_iterator cgemDedxTds;
157
158 for (cgemDedxTds = cgemDedxColTds->begin(); cgemDedxTds != cgemDedxColTds->end(); cgemDedxTds++) {
159 Int_t trackId = (*cgemDedxTds)->trackId();
160 Int_t particleId = (*cgemDedxTds)->particleId();
161 Int_t status = (*cgemDedxTds)->status();
162 Int_t truncAlg =(*cgemDedxTds)->truncAlg();
163 /*
164 Double_t pb[5];
165 for (Int_t i = 0; i < 5; i++)
166 pb[i] = (*dedxTds)->prob(i);
167 */
168 Double_t chiE = (*cgemDedxTds)->chi(0);
169 Double_t chiMu = (*cgemDedxTds)->chi(1);
170 Double_t chiPi = (*cgemDedxTds)->chi(2);
171 Double_t chiK = (*cgemDedxTds)->chi(3);
172 Double_t chiP = (*cgemDedxTds)->chi(4);
173
174 Int_t numGoodHits = (*cgemDedxTds)->numGoodHits();
175 Int_t numTotalHits = (*cgemDedxTds)->numTotalHits();
176
177 Double_t probPH = (*cgemDedxTds)->probPH();
178 Double_t normPH = (*cgemDedxTds)->normPH();
179 Double_t errorPH = (*cgemDedxTds)->errorPH();
180 Double_t twentyPH =(*cgemDedxTds)->twentyPH();
181 //Double_t fracErrPH = (*dedxTds)-> fracErrPH();
182 //Double_t minIronPH = (*dedxTds)->minIronPH();
183 //Double_t corrPH = (*dedxTds)->corrPH();
184 log << MSG::INFO <<"check Reconstrunction root"<<" particle Id is : "<<particleId
185 <<"track id is : "<<trackId
186 <<" and status is : "<<status<<endreq;
187
188
189 TCgemDedx *cgemDedxRoot = new TCgemDedx();
190 //m_common.m_cgemDedxMap[(*cgemDedxTds)] = cgemDedxRoot;
191
192 cgemDedxRoot->setTrackId(trackId);
193 cgemDedxRoot->setParticleId(particleId);
194 cgemDedxRoot->setStatus (status);
195 cgemDedxRoot->setTruncAlg(truncAlg);
196 //dedxRoot->setProb(pb);
197 cgemDedxRoot->setChiE(chiE);
198 cgemDedxRoot->setChiMu(chiMu);
199 cgemDedxRoot->setChiPi(chiPi);
200 cgemDedxRoot->setChiK(chiK);
201 cgemDedxRoot->setChiP(chiP);
202
203 cgemDedxRoot->setNumGoodHits( numGoodHits);
204 cgemDedxRoot->setNumTotalHits( numTotalHits);
205
206 cgemDedxRoot->setProbPH(probPH);
207 cgemDedxRoot->setNormPH(normPH);
208 cgemDedxRoot->setErrorPH(errorPH);
209 cgemDedxRoot->setTwentyPH(twentyPH);
210 // dedxRoot->setFracErrPH(fracErrPH);
211 //dedxRoot->setMinIronPH(minIronPH);
212 //dedxRoot->setCorrPH(corrPH);
213 log << MSG::INFO << "check Reconstrunction root"<<" particle Id is : "<<particleId
214 <<"track id is : "<<trackId
215 <<" and status is : "<<status<<endreq;
216
217
218
219 recEvt->addCgemDedx(cgemDedxRoot);
220 }
221
222 return StatusCode::SUCCESS;
223}
224#endif
ObjectVector< DstCgemDedx > DstCgemDedxCol
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
static TDstEvent * 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.
const TObjArray * getCgemDedxCol() const
retrieve the whole TObjArray of Dedx Data
void addCgemDedx(TCgemDedx *Track)
Add a Dedx into the TOF Data collection.
static std::map< const TObject *, const DstCgemDedx * > m_rootCgemDedxMap