BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
RecMdcDedxCnv.cxx
Go to the documentation of this file.
1#ifndef RecMdcDedxCnv_CXX
2#define RecMdcDedxCnv_CXX 1
3#include "GaudiKernel/MsgStream.h"
4#include "GaudiKernel/DataObject.h"
5#include "GaudiKernel/ObjectVector.h"
6#include "TClonesArray.h"
7#include "EventModel/EventModel.h"
8#include "ReconEvent/ReconEvent.h"
9#include "MdcRecEvent/RecMdcTrack.h"
10#include "MdcRecEvent/RecMdcDedxHit.h"
11#include "MdcRecEvent/RecMdcKalTrack.h"
12#include "MdcRecEvent/RecMdcDedx.h"
13
14#include "RootEventData/TRecMdcDedx.h" // standard root object
15#include "RootEventData/TRecTrackEvent.h"
16
17#include "RootCnvSvc/Rec/RecTrackCnv.h"
18#include "RootCnvSvc/Rec/RecMdcDedxCnv.h"
19#include "RootCnvSvc/RootAddress.h"
20
21#include <vector>
22
23using namespace std;
24
25// Instantiation of a static factory class used by clients to create
26// instances of this service
27//static CnvFactory<RecMdcDedxCnv> s_factory;
28//const ICnvFactory& RecMdcDedxCnvFactory = s_factory;
29
31: RootEventBaseCnv(classID(), svc)
32{
33
34 // Here we associate this converter with the /Event path on the TDS.
35 MsgStream log(msgSvc(), "RecMdcDedxCnv");
36 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
37 //m_rootTreename ="Rec";
38 m_rootBranchname ="m_recMdcDedxCol";
39 // declareObject(EventModel::Recon::RecMdcDedxCol, objType(), m_rootTreename, m_rootBranchname);
40 m_adresses.push_back(&m_recMdcDedxCol);
41 m_recMdcDedxCol=0;
42}
43
44StatusCode RecMdcDedxCnv::TObjectToDataObject(DataObject*& refpObject) {
45 // creation of TDS object from root object
46 MsgStream log(msgSvc(), "RecMdcDedxCnv");
47 log << MSG::DEBUG << "RecMdcDedxCnv::TObjectToDataObject" << endreq;
48 StatusCode sc=StatusCode::SUCCESS;
49
50 // create the TDS location for the Dedx Collection
51 RecMdcDedxCol* recMdcDedxCol = new RecMdcDedxCol;
52 refpObject=recMdcDedxCol;
53
54 if (!m_recMdcDedxCol) return sc;
55
56 //*******************Dst to Rec convert in case of no Rec data in TDS****************************
57 IDataProviderSvc* dataSvc = 0;
58 sc = serviceLocator()->getService("EventDataSvc",
59 IDataProviderSvc::interfaceID(), (IInterface*&)dataSvc);
60 if ( sc.isFailure() ) {
61 log << MSG::FATAL << "Could not get EventDataSvc in RecMdcDedxCnv" << endreq;
62 return sc;
63 }
64
65 //----------get hit smartRefVector--------
66 SmartDataPtr<RecMdcDedxHitCol> recMdcDedxHitCol(dataSvc,"/Event/Recon/RecMdcDedxHitCol");
67 if (!recMdcDedxHitCol) {
68 log << MSG::FATAL << "Could not find RecMdcDedxHitCol" << endreq;
69 return( StatusCode::FAILURE);
70 }
71
72
73 int trackID;
74 // Retrieve Mdc Track
75 SmartDataPtr<RecMdcTrackCol> mdcTrackCol(dataSvc, EventModel::Recon::RecMdcTrackCol);
76 if(!mdcTrackCol)
77 {
78 log << MSG::INFO << "Could not find RecMdcTrackCol" << endreq;
79 SmartDataPtr<DstMdcTrackCol> dstMdcTrackCol(dataSvc,"/Event/Dst/DstMdcTrackCol");
80 if (!dstMdcTrackCol) {
81 log << MSG::INFO << "Could not find DstMdcTrackCol" << endreq;
82 }
83 else {
84 RecMdcTrackCol* mdcTrackCol = new RecMdcTrackCol();
85 DstMdcTrackCol::iterator iter_mdc = dstMdcTrackCol->begin();
86 trackID = 0;
87 for (;iter_mdc != dstMdcTrackCol->end(); iter_mdc++, trackID++) {
88 RecMdcTrack* recMdcTrack = new RecMdcTrack();
89 *recMdcTrack = **iter_mdc;
90 (*mdcTrackCol).push_back(recMdcTrack);
91 log << MSG::INFO
92 << " Mdc Track ID = " << trackID
93 << " Mdc Track Nster = " << (*iter_mdc)->nster()
94 << endreq;
95 }
96 sc = dataSvc->registerObject(EventModel::Recon::RecMdcTrackCol,mdcTrackCol);
97 }
98 }
99
100 // Retrieve MdcKal track
101 SmartDataPtr<RecMdcKalTrackCol> mdcKalTrackCol(dataSvc, EventModel::Recon::RecMdcKalTrackCol);
102 if (!mdcKalTrackCol) {
103 log << MSG::INFO << "Could not find RecMdcKalTrackCol" << endreq;
104 SmartDataPtr<DstMdcKalTrackCol> dstMdcKalTrackCol(dataSvc,"/Event/Dst/DstMdcKalTrackCol");
105 if(!dstMdcKalTrackCol) {
106 log << MSG::INFO << "Could not find DstMdcKalTrackCol" << endreq;
107 }
108 else {
109 RecMdcKalTrackCol* mdcKalTrackCol = new RecMdcKalTrackCol();
110 DstMdcKalTrackCol::iterator iter_mdc = dstMdcKalTrackCol->begin();
111 trackID = 0;
112 for (;iter_mdc != dstMdcKalTrackCol->end(); iter_mdc++, trackID++) {
113 RecMdcKalTrack* recMdcKalTrack = new RecMdcKalTrack();
114 *recMdcKalTrack = **iter_mdc;
115 (*mdcKalTrackCol).push_back(recMdcKalTrack);
116 log << MSG::INFO
117 << " MdcKalTrack ID = " << trackID
118 << " MdcKalTrack Nster = " << (*iter_mdc)->nster()
119 << " MdcKalTrack poca = " << (*iter_mdc)->poca()
120 << endreq;
121 }
122 sc = dataSvc->registerObject(EventModel::Recon::RecMdcKalTrackCol, mdcKalTrackCol);
123 }
124 }
125
126
127 //**********************************************************************
128 // now convert
129 TIter dedxIter(m_recMdcDedxCol);
130 TRecMdcDedx *recMdcDedxRoot = 0;
131 while ((recMdcDedxRoot = (TRecMdcDedx*)dedxIter.Next())) {
132 double dedxHit = recMdcDedxRoot->dedxHit();
133 double dedxEsat = recMdcDedxRoot->dedxEsat();
134 double dedxNoRun = recMdcDedxRoot->dedxNoRun();
135 double dedxMoment = recMdcDedxRoot->dedxMoment();
136
137 int trackId = recMdcDedxRoot->trackId();
138 int particleId = recMdcDedxRoot->particleId();
139 int status = recMdcDedxRoot->status();
140 int truncAlg = recMdcDedxRoot->truncAlg();
141 // double pb[5];
142 // for ( int i = 0; i < 5; i++)
143 // pb[i] = dedxRoot->prob(i);
144
145 // double numSigmaE = dedxRoot->numSigmaE();
146 // double numSigmaMu = dedxRoot->numSigmaMu();
147 // double numSigmaPi = dedxRoot->numSigmaPi();
148 // double numSigmaK = dedxRoot->numSigmaK();
149 // double numSigmaP = dedxRoot->numSigmaP();
150 double chi[5];
151 chi[0] = recMdcDedxRoot->chiE();
152 chi[1] = recMdcDedxRoot->chiMu();
153 chi[2] = recMdcDedxRoot->chiPi();
154 chi[3] = recMdcDedxRoot->chiK();
155 chi[4] = recMdcDedxRoot->chiP();
156 int numGoodHits = recMdcDedxRoot->numGoodHits();
157 int numTotalHits = recMdcDedxRoot->numTotalHits();
158
159 double probPH = recMdcDedxRoot->probPH();
160 double normPH = recMdcDedxRoot->normPH();
161 double errorPH = recMdcDedxRoot->errorPH();
162 double twentyPH = recMdcDedxRoot->twentyPH();
163 double dedxExpect[5],sigmaDedx[5],pidProb[5];
164
165 for (int i=0; i<5; i++){
166 dedxExpect[i] = recMdcDedxRoot->dedxExpect(i);
167 sigmaDedx[i] = recMdcDedxRoot->sigmaDedx(i);
168 pidProb[i] = recMdcDedxRoot->pidProb(i);}
169
170 log << MSG::DEBUG<<"TObjectToDataObject: check Reconstrunction of dE/dx root::"<<" trackId: "<<trackId<<" particleId: "<<particleId<<" status: "<<status<<" truncAlg: "<<truncAlg<<" chi[2]: "<<chi[2]<<" numTotalHits: "<<numTotalHits<<" probPH: "<<probPH<<" errorPH: "<<errorPH<<" dedxExpect[2]: "<<dedxExpect[2]<<endreq;
171
172 RecMdcDedx *recMdcDedx = new RecMdcDedx();
173 m_common.m_rootRecMdcDedxMap[recMdcDedxRoot] = recMdcDedx;
174
175 recMdcDedx->setTrackId(trackId);
176 recMdcDedx->setParticleId(particleId);
177 recMdcDedx->setStatus (status);
178 recMdcDedx->setTruncAlg(truncAlg);
179 // dedxTds->setProb(pb);
180 // dedxTds->setNumSigmaE(numSigmaE);
181 // dedxTds->setNumSigmaMu(numSigmaMu);
182 // dedxTds->setNumSigmaPi(numSigmaPi);
183 // dedxTds->setNumSigmaK(numSigmaK);
184 // dedxTds->setNumSigmaP(numSigmaP);
185 recMdcDedx->setChi(chi);
186 recMdcDedx->setNumGoodHits( numGoodHits);
187 recMdcDedx->setNumTotalHits( numTotalHits);
188
189 recMdcDedx->setProbPH(probPH);
190 recMdcDedx->setNormPH(normPH);
191 recMdcDedx->setErrorPH(errorPH);
192 recMdcDedx->setTwentyPH(twentyPH);
193 //for (int i=0; i<5; i++){
194 recMdcDedx->setDedxExpect(dedxExpect);
195 recMdcDedx->setSigmaDedx(sigmaDedx);
196 recMdcDedx->setPidProb(pidProb);
197
198 recMdcDedx->setDedxHit(dedxHit);
199 recMdcDedx->setDedxEsat(dedxEsat);
200 recMdcDedx->setDedxNoRun(dedxNoRun);
201 recMdcDedx->setDedxMoment(dedxMoment);
202 //}
203
204 DedxHitRefVec theDedxHitRefVec;
205 RecMdcDedxHitCol::iterator iter = recMdcDedxHitCol->begin();
206 for (;iter != recMdcDedxHitCol->end(); iter++){
207 if((*iter)->getTrkId() == trackId){
208 SmartRef<RecMdcDedxHit> refDedxHit(*iter);
209 theDedxHitRefVec.push_back(refDedxHit);
210 }
211 }
212 recMdcDedx->setVecDedxHits(theDedxHitRefVec);
213 int nhits = recMdcDedx->getVecDedxHits().size();
214 //std::cout<<" mdc hits: "<<nhits<< std::endl;
215 for(int ii=0; ii <nhits ; ii++){
216 Identifier id(recMdcDedx->getVecDedxHits()[ii]->getMdcId());
217 int layer = MdcID::layer(id);
218 int wire = MdcID::wire(id);
219 //cout<<"layer: "<<layer<<" wire: "<<wire<<endl;
220 }
221
222 int mdcTrackId = recMdcDedxRoot->mdcTrackId();
223 //std::cout << __FILE__ << __LINE__ << " size: " << mdcTrackCol->size() << " id: " << mdcTrackId << std::endl;
224 if ( mdcTrackId >= 0 ) {
225 recMdcDedx->setMdcTrack(
226 dynamic_cast<RecMdcTrack*>(mdcTrackCol->containedObject(mdcTrackId)));
227 }
228 int mdcKalTrackId = recMdcDedxRoot->mdcKalTrackId();
229 //std::cout << __FILE__ << __LINE__ << " size: " << mdcKalTrackCol->size() << " id: " << mdcKalTrackId<< std::endl;
230 if ( mdcKalTrackId >= 0 ) {
231 recMdcDedx->setMdcKalTrack(
232 dynamic_cast<RecMdcKalTrack*>(mdcKalTrackCol->containedObject(mdcKalTrackId)));
233 }
234
235 recMdcDedxCol->push_back(recMdcDedx);
236 //delete dedxTds;
237 // dedxTds = NULL;
238 }
239 //m_dedxCol->Delete();
240 delete m_recMdcDedxCol;
241 m_recMdcDedxCol = 0;
242
243 return StatusCode::SUCCESS;
244}
245
246
247StatusCode RecMdcDedxCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
248 MsgStream log(msgSvc(), "RecMdcDedxCnv");
249 log << MSG::DEBUG << "RecMdcDedxCnv::DataObjectToTObject" << endreq;
250 StatusCode sc=StatusCode::SUCCESS;
251
252 RecMdcDedxCol * recMdcDedxCol=dynamic_cast<RecMdcDedxCol *> (obj);
253 if (!recMdcDedxCol) {
254 log << MSG::ERROR << "Could not downcast to RecMdcDedxCol" << endreq;
255 return StatusCode::FAILURE;
256 }
257
258 DataObject *evt;
259 m_eds->findObject(EventModel::Recon::Event,evt);
260 if (evt==NULL) {
261 log << MSG::ERROR << "Could not get RecEvent in TDS " << endreq;
262 return StatusCode::FAILURE;
263 }
264 ReconEvent * devtTds=dynamic_cast<ReconEvent *> (evt);
265 if (!devtTds) {
266 log << MSG::ERROR << "RecMdcDedxCnv:Could not downcast to TDS RecEvent" << endreq;
267 }
268
269 IOpaqueAddress *addr;
270 m_cnvSvc->getRecTrackCnv()->createRep(evt,addr);
272
273 const TObjArray *m_recMdcDedxCol = recEvt->getRecMdcDedxCol();
274 if (!m_recMdcDedxCol) return sc;
275 recEvt->clearRecMdcDedxCol(); //necessary in case there is I/O at the same time since array is static
276
277 //******************** get according mdcTrack and MdcKalmanTrack of MdcDedx ****************
278
279 RecMdcTrackCol::iterator recMdcTrackColbegin, recMdcTrackColend;
280 RecMdcKalTrackCol::iterator recMdcKalTrackColbegin, recMdcKalTrackColend;
281
282 IDataProviderSvc* dataSvc = 0;
283 sc = serviceLocator()->getService("EventDataSvc",
284 IDataProviderSvc::interfaceID(), (IInterface*&)dataSvc);
285 if ( sc.isFailure() ) {
286 log << MSG::FATAL << "Could not get EventDataSvc in RecMdcDedxCnv" << endreq;
287 return sc;
288 }
289 SmartDataPtr<RecMdcTrackCol> recMdcTrackCol(dataSvc, EventModel::Recon::RecMdcTrackCol);
290 if (!recMdcTrackCol) {
291 log << MSG::ERROR << "Could not downcast to RecMdcTrackCol" << endreq;
292 return StatusCode::FAILURE;
293 }
294 else {
295 recMdcTrackColbegin = recMdcTrackCol->begin();
296 recMdcTrackColend = recMdcTrackCol->end();
297 }
298
299 SmartDataPtr<RecMdcKalTrackCol> recMdcKalTrackCol(dataSvc, EventModel::Recon::RecMdcKalTrackCol);
300 if (!recMdcKalTrackCol) {
301 log << MSG::ERROR << "Could not downcast to RecMdcKalTrackCol" << endreq;
302 return StatusCode::FAILURE;
303 }
304 else {
305 recMdcKalTrackColbegin = recMdcKalTrackCol->begin();
306 recMdcKalTrackColend = recMdcKalTrackCol->end();
307 }
308 //******************************************************************************
309
310 RecMdcDedxCol::const_iterator recMdcDedx;
311
312 for (recMdcDedx = recMdcDedxCol->begin(); recMdcDedx != recMdcDedxCol->end(); recMdcDedx++) {
313 Int_t trackId = (*recMdcDedx)->trackId();
314 Int_t particleId = (*recMdcDedx)->particleId();
315 Int_t status = (*recMdcDedx)->status();
316 Int_t truncAlg = (*recMdcDedx)->truncAlg();
317 // Double_t pb[5];
318 // for (Int_t i = 0; i < 5; i++)
319 // pb[i] = (*dedxTds)->prob(i);
320 Double_t dedxHit = (*recMdcDedx)->getDedxHit();
321 Double_t dedxEsat = (*recMdcDedx)->getDedxEsat();
322 Double_t dedxNoRun = (*recMdcDedx)->getDedxNoRun();
323 Double_t dedxMoment = (*recMdcDedx)->getDedxMoment();
324
325
326 Double_t chiE = (*recMdcDedx)->chi(0);
327 Double_t chiMu = (*recMdcDedx)->chi(1);
328 Double_t chiPi = (*recMdcDedx)->chi(2);
329 Double_t chiK = (*recMdcDedx)->chi(3);
330 Double_t chiP = (*recMdcDedx)->chi(4);
331
332 Int_t numGoodHits = (*recMdcDedx)->numGoodHits();
333 Int_t numTotalHits = (*recMdcDedx)->numTotalHits();
334
335 Double_t probPH = (*recMdcDedx)->probPH();
336 Double_t normPH = (*recMdcDedx)->normPH();
337 Double_t errorPH = (*recMdcDedx)->errorPH();
338 Double_t twentyPH = (*recMdcDedx)->twentyPH();
339 //Double_t fracErrPH = (*dedxTds)-> fracErrPH();
340 //Double_t minIronPH = (*dedxTds)->minIronPH();
341 //Double_t corrPH = (*dedxTds)->corrPH();
342 double dedxExpect[5],sigmaDedx[5],pidProb[5],chi[5];
343 for (int i=0; i<5; i++){
344 chi[i] = (*recMdcDedx)->chi(i);
345 dedxExpect[i] = (*recMdcDedx)->getDedxExpect(i);
346 sigmaDedx[i] = (*recMdcDedx)->getSigmaDedx(i);
347 pidProb[i] = (*recMdcDedx)->getPidProb(i);
348 }
349
350 log << MSG::DEBUG<<"DataObjectToTObject: check Reconstrunction of dE/dx::"<<" trackId: "<<trackId<<" particleId: "<<particleId<<" status: "<<status<<" truncAlg: "<<truncAlg<<" chiPi: "<<chiPi<<" numTotalHits: "<<numTotalHits<<" probPH: "<<probPH<<" errorPH: "<<errorPH<<" dedxExpect[2]: "<<dedxExpect[2]<<endreq;
351
352
353 TRecMdcDedx *recMdcDedxRoot = new TRecMdcDedx();
354 //m_common.m_recMdcDedxMap[(*recMdcDedx)] = recMdcDedxRoot;
355 //std::cout<<"check write to Reconstrunction root particle Id is "<<dedxRoot->particleId()<<endl;
356 recMdcDedxRoot->setTrackId(trackId);
357 recMdcDedxRoot->setParticleId(particleId);
358 recMdcDedxRoot->setStatus (status);
359 recMdcDedxRoot->setTruncAlg(truncAlg);
360
361 //dedxRoot->setProb(pb);
362 recMdcDedxRoot->setChiE(chiE);
363 recMdcDedxRoot->setChiMu(chiMu);
364 recMdcDedxRoot->setChiPi(chiPi);
365 recMdcDedxRoot->setChiK(chiK);
366 recMdcDedxRoot->setChiP(chiP);
367
368 recMdcDedxRoot->setNumGoodHits( numGoodHits);
369 recMdcDedxRoot->setNumTotalHits( numTotalHits);
370
371 recMdcDedxRoot->setProbPH(probPH);
372 recMdcDedxRoot->setNormPH(normPH);
373 recMdcDedxRoot->setErrorPH(errorPH);
374 recMdcDedxRoot->setTwentyPH(twentyPH);
375 // for (int i=0; i<5; i++){
376 recMdcDedxRoot->setChi(chi);
377 recMdcDedxRoot->setDedxExpect(dedxExpect);
378 recMdcDedxRoot->setSigmaDedx(sigmaDedx);
379 recMdcDedxRoot->setPidProb(pidProb);
380
381 recMdcDedxRoot->setDedxHit(dedxHit);
382 recMdcDedxRoot->setDedxEsat(dedxEsat);
383 recMdcDedxRoot->setDedxNoRun(dedxNoRun);
384 recMdcDedxRoot->setDedxMoment(dedxMoment);
385 //}
386
387 if ( (*recMdcDedx)->isMdcTrackValid() ) {
388 RecMdcTrackCol::iterator it = find(recMdcTrackColbegin, recMdcTrackColend, (*recMdcDedx)->getMdcTrack());
389 recMdcDedxRoot->setMdcTrackId( it - recMdcTrackColbegin );
390 }
391 else {
392 recMdcDedxRoot->setMdcTrackId( -1 );
393 }
394
395 if ( (*recMdcDedx)->isMdcKalTrackValid() ) {
396 RecMdcKalTrackCol::iterator it = find(recMdcKalTrackColbegin, recMdcKalTrackColend, (*recMdcDedx)->getMdcKalTrack());
397 recMdcDedxRoot->setMdcKalTrackId( it - recMdcKalTrackColbegin );
398 }
399 else {
400 recMdcDedxRoot->setMdcKalTrackId( -1 );
401 }
402
403 log << MSG::INFO<<"check Reconstrunction root"<<" particle Id is : "<<particleId
404 <<"track id is : "<<trackId
405 <<" and status is : "<<status<<endreq;
406
407 // dedxRoot->setFracErrPH(fracErrPH);
408 //dedxRoot->setMinIronPH(minIronPH);
409 //dedxRoot->setCorrPH(corrPH);
410 recEvt->addRecMdcDedx(recMdcDedxRoot);
411 }
412
413 return StatusCode::SUCCESS;
414}
415
416#endif
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
SmartRefVector< RecMdcDedxHit > DedxHitRefVec
ObjectVector< RecMdcDedx > RecMdcDedxCol
ObjectVector< RecMdcKalTrack > RecMdcKalTrackCol
ObjectVector< RecMdcTrack > RecMdcTrackCol
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
Definition: MdcID.cxx:49
static int wire(const Identifier &id)
Definition: MdcID.cxx:54
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
RecMdcDedxCnv(ISvcLocator *svc)
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
void setVecDedxHits(const DedxHitRefVec &vecdedxhit)
static TRecTrackEvent * 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 addRecMdcDedx(TRecMdcDedx *Track)
Add a Dedx into the TOF Data collection.
const TObjArray * getRecMdcDedxCol() const
retrieve the whole TObjArray of Dedx Data
static std::map< const TObject *, const RecMdcDedx * > m_rootRecMdcDedxMap