BOSS 7.0.1
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcDedxCnv.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/DstMdcDedx.h" //TDS object
13#include "RootEventData/TMdcDedx.h" // standard root object
14#include "RootEventData/TDstEvent.h"
15
16#include "RootCnvSvc/Dst/DstCnv.h"
17#include "RootCnvSvc/Dst/MdcDedxCnv.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
26MdcDedxCnv::MdcDedxCnv(ISvcLocator* svc)
27: RootEventBaseCnv(classID(), svc)
28{
29 // Here we associate this converter with the /Event path on the TDS.
30 MsgStream log(msgSvc(), "MdcDedxCnv");
31 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
32 m_rootBranchname ="m_mdcDedxCol";
33 //declareObject(EventModel::Dst::DstDedxCol, objType(), m_rootTreename, m_rootBranchname);
34 m_adresses.push_back(&m_mdcDedxCol);
35 m_mdcDedxCol=0;
36}
37
38StatusCode MdcDedxCnv::TObjectToDataObject(DataObject*& refpObject) {
39 // creation of TDS object from root object
40
41 MsgStream log(msgSvc(), "MdcDedxCnv");
42 log << MSG::DEBUG << "MdcDedxCnv::TObjectToDataObject" << endreq;
43 StatusCode sc=StatusCode::SUCCESS;
44
45 // create the TDS location for the Dedx Collection
46 DstMdcDedxCol* mdcDedxTdsCol = new DstMdcDedxCol;
47 refpObject=mdcDedxTdsCol;
48
49
50 // now convert
51 if (!m_mdcDedxCol) return sc;
52 TIter mdcDedxIter(m_mdcDedxCol);
53 TMdcDedx *mdcDedxRoot = 0;
54 while ((mdcDedxRoot = (TMdcDedx*)mdcDedxIter.Next())) {
55
56 int trackId = mdcDedxRoot->trackId();
57 int particleId = mdcDedxRoot->particleId();
58 int status = mdcDedxRoot->status();
59 int truncAlg = mdcDedxRoot->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] = mdcDedxRoot->chiE();
73 chi[1] = mdcDedxRoot->chiMu();
74 chi[2] = mdcDedxRoot->chiPi();
75 chi[3] = mdcDedxRoot->chiK();
76 chi[4] = mdcDedxRoot->chiP();
77 int numGoodHits = mdcDedxRoot->numGoodHits();
78 int numTotalHits = mdcDedxRoot->numTotalHits();
79
80 double probPH = mdcDedxRoot->probPH();
81 double normPH = mdcDedxRoot->normPH();
82 double errorPH = mdcDedxRoot->errorPH();
83 double twentyPH = mdcDedxRoot->twentyPH();
84 //double fracErrPH = dedxRoot-> fracErrPH();
85 //double minIronPH = dedxRoot->minIronPH();
86 //double corrPH = dedxRoot->corrPH();
87
88 DstMdcDedx *mdcDedxTds = new DstMdcDedx();
89 m_common.m_rootMdcDedxMap[mdcDedxRoot] = mdcDedxTds;
90
91 mdcDedxTds->setTrackId(trackId);
92 mdcDedxTds->setParticleId(particleId);
93 mdcDedxTds->setStatus (status);
94 mdcDedxTds->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 mdcDedxTds->setChi(chi);
104
105 mdcDedxTds->setNumGoodHits( numGoodHits);
106 mdcDedxTds->setNumTotalHits( numTotalHits);
107
108 mdcDedxTds->setProbPH(probPH);
109 mdcDedxTds->setNormPH(normPH);
110 mdcDedxTds->setErrorPH(errorPH);
111 mdcDedxTds->setTwentyPH(twentyPH);
112 //dedxTds->setFracErrPH(fracErrPH);
113 //dedxTds->setMinIronPH(minIronPH);
114 //dedxTds->setCorrPH(corrPH);
115
116 mdcDedxTdsCol->push_back(mdcDedxTds);
117 //delete dedxTds;
118 // dedxTds = NULL;
119 }
120 //m_dedxCol->Delete();
121 delete m_mdcDedxCol;
122 m_mdcDedxCol = 0;
123 return StatusCode::SUCCESS;
124}
125
126StatusCode MdcDedxCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
127
128 MsgStream log(msgSvc(), "MdcDedxCnv");
129 log << MSG::DEBUG << "MdcDedxCnv::DataObjectToTObject" << endreq;
130 StatusCode sc=StatusCode::SUCCESS;
131
132 DstMdcDedxCol * mdcDedxColTds=dynamic_cast<DstMdcDedxCol *> (obj);
133 if (!mdcDedxColTds) {
134 log << MSG::ERROR << "Could not downcast to MdcDedxCol" << 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 << "MdcDedxCnv:Could not downcast to TDS DstEvent" << endreq;
147 }
148 IOpaqueAddress *addr;
149
150 m_cnvSvc->getDstCnv()->createRep(evt,addr);
152
153 const TObjArray *m_mdcDedxCol = recEvt->getMdcDedxCol();
154 if (!m_mdcDedxCol) return sc;
155 recEvt->clearMdcDedxCol(); //necessary in case there is I/O at the same time since array is static
156 DstMdcDedxCol::const_iterator mdcDedxTds;
157
158 for (mdcDedxTds = mdcDedxColTds->begin(); mdcDedxTds != mdcDedxColTds->end(); mdcDedxTds++) {
159 Int_t trackId = (*mdcDedxTds)->trackId();
160 Int_t particleId = (*mdcDedxTds)->particleId();
161 Int_t status = (*mdcDedxTds)->status();
162 Int_t truncAlg =(*mdcDedxTds)->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 = (*mdcDedxTds)->chi(0);
169 Double_t chiMu = (*mdcDedxTds)->chi(1);
170 Double_t chiPi = (*mdcDedxTds)->chi(2);
171 Double_t chiK = (*mdcDedxTds)->chi(3);
172 Double_t chiP = (*mdcDedxTds)->chi(4);
173
174 Int_t numGoodHits = (*mdcDedxTds)->numGoodHits();
175 Int_t numTotalHits = (*mdcDedxTds)->numTotalHits();
176
177 Double_t probPH = (*mdcDedxTds)->probPH();
178 Double_t normPH = (*mdcDedxTds)->normPH();
179 Double_t errorPH = (*mdcDedxTds)->errorPH();
180 Double_t twentyPH =(*mdcDedxTds)->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 TMdcDedx *mdcDedxRoot = new TMdcDedx();
190 //m_common.m_mdcDedxMap[(*mdcDedxTds)] = mdcDedxRoot;
191
192 mdcDedxRoot->setTrackId(trackId);
193 mdcDedxRoot->setParticleId(particleId);
194 mdcDedxRoot->setStatus (status);
195 mdcDedxRoot->setTruncAlg(truncAlg);
196 //dedxRoot->setProb(pb);
197 mdcDedxRoot->setChiE(chiE);
198 mdcDedxRoot->setChiMu(chiMu);
199 mdcDedxRoot->setChiPi(chiPi);
200 mdcDedxRoot->setChiK(chiK);
201 mdcDedxRoot->setChiP(chiP);
202
203 mdcDedxRoot->setNumGoodHits( numGoodHits);
204 mdcDedxRoot->setNumTotalHits( numTotalHits);
205
206 mdcDedxRoot->setProbPH(probPH);
207 mdcDedxRoot->setNormPH(normPH);
208 mdcDedxRoot->setErrorPH(errorPH);
209 mdcDedxRoot->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->addMdcDedx(mdcDedxRoot);
220 }
221
222 return StatusCode::SUCCESS;
223}
224#endif
ObjectVector< DstMdcDedx > DstMdcDedxCol
static TDstEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
MdcDedxCnv(ISvcLocator *svc)
Definition: MdcDedxCnv.cxx:26
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
Definition: MdcDedxCnv.cxx:38
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
Definition: MdcDedxCnv.cxx:126
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.
const TObjArray * getMdcDedxCol() const
retrieve the whole TObjArray of Dedx Data
void addMdcDedx(TMdcDedx *Track)
Add a Dedx into the TOF Data collection.
Definition: TDstEvent.cxx:163
static std::map< const TObject *, const DstMdcDedx * > m_rootMdcDedxMap