BOSS 7.0.2
BESIII Offline Software System
Loading...
Searching...
No Matches
RecMdcDedxHitCnv.cxx
Go to the documentation of this file.
1#ifndef RecMdcDedxHitCnv_CXX
2#define RecMdcDedxHitCnv_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/RecMdcDedxHit.h"
10#include "Identifier/Identifier.h"
11
12#include "RootEventData/TRecMdcDedxHit.h" // standard root object
13#include "RootEventData/TRecTrackEvent.h"
14
15#include "RootCnvSvc/Rec/RecTrackCnv.h"
16#include "RootCnvSvc/Rec/RecMdcDedxHitCnv.h"
17#include "RootCnvSvc/RootAddress.h"
18
19#include <vector>
20
21using namespace std;
22
23// Instantiation of a static factory class used by clients to create
24// instances of this service
25//static CnvFactory<RecMdcDedxCnv> s_factory;
26//const ICnvFactory& RecMdcDedxCnvFactory = s_factory;
27
29: RootEventBaseCnv(classID(), svc)
30{
31
32 // Here we associate this converter with the /Event path on the TDS.
33 MsgStream log(msgSvc(), "RecMdcDedxHitCnv");
34 //log << MSG::DEBUG << "Constructor called for " << objType() << endreq;
35 //m_rootTreename ="Rec";
36 m_rootBranchname ="m_recMdcDedxHitCol";
37 // declareObject(EventModel::Recon::RecMdcDedxCol, objType(), m_rootTreename, m_rootBranchname);
38 m_adresses.push_back(&m_recMdcDedxHitCol);
39 m_recMdcDedxHitCol=0;
40}
41
42StatusCode RecMdcDedxHitCnv::TObjectToDataObject(DataObject*& refpObject) {
43 // creation of TDS object from root object
44 MsgStream log(msgSvc(), "RecMdcDedxHitCnv");
45 log << MSG::DEBUG << "RecMdcDedxHitCnv::TObjectToDataObject" << endreq;
46 StatusCode sc=StatusCode::SUCCESS;
47 // create the TDS location for the Dedx Collection
48 RecMdcDedxHitCol* recMdcDedxHitCol = new RecMdcDedxHitCol;
49 refpObject=recMdcDedxHitCol;
50
51 //***************************register rec hit data in TDS****************************
52 IDataProviderSvc* dataSvc = 0;
53 sc = serviceLocator()->getService("EventDataSvc",
54 IDataProviderSvc::interfaceID(), (IInterface*&)dataSvc);
55 if ( sc.isFailure() ) {
56 log << MSG::FATAL << "Could not get EventDataSvc in RecMdcDedxHitCnv" << endreq;
57 return sc;
58 }
59
60 // Retrieve Mdc Hit
61 SmartDataPtr<RecMdcHitCol> mdcHitCol(dataSvc, EventModel::Recon::RecMdcHitCol);
62 if(!mdcHitCol)
63 {
64 log << MSG::INFO << "Could not find RecMdcHitCol" << endreq;
65 }
66
67 // Retrieve MdcKal Helix Segment
68 SmartDataPtr<RecMdcKalHelixSegCol> mdcKalHelixSegCol(dataSvc, EventModel::Recon::RecMdcKalHelixSegCol);
69 if (!mdcKalHelixSegCol) {
70 log << MSG::INFO << "Could not find RecMdcKalHelixSegCol" << endreq;
71 }
72 //**********************************************************************
73
74
75 // now convert
76 if (!m_recMdcDedxHitCol) return sc;
77 TIter dedxIter(m_recMdcDedxHitCol);
78 TRecMdcDedxHit *recMdcDedxHitRoot = 0;
79 while ((recMdcDedxHitRoot = (TRecMdcDedxHit*)dedxIter.Next())) {
80 int trackId = recMdcDedxHitRoot->trkId();
81 //cout<<"trackId: "<<trackId<<endl;
82 int flagLR = recMdcDedxHitRoot->flagLR();
83 //cout<<"flagLR: "<<flagLR<<endl;
84 long int mdcId(recMdcDedxHitRoot->mdcId());
85 //cout<<"mdcID: "<<mdcId<<endl;
86 double pathlength = recMdcDedxHitRoot->pathLength();
87 //cout<<"pathlength: " <<pathlength<<endl;
88 double dedx = recMdcDedxHitRoot->getDedx();
89 //cout<<"dedx: "<<dedx<<endl;
90
91 log << MSG::DEBUG<<"TObjectToDataObject: check Reconstrunction of dE/dx Hit root::"<<" trackId: "<<trackId<<" flagLR: "<<flagLR<<" pathlength: "<<pathlength<<" dedx: "<<dedx<<endreq;
92 RecMdcDedxHit *recMdcDedxHit = new RecMdcDedxHit();
93 m_common.m_rootRecMdcDedxHitMap[recMdcDedxHitRoot] = recMdcDedxHit;
94 recMdcDedxHit->setTrkId(trackId);
95 recMdcDedxHit->setFlagLR(flagLR);
96 recMdcDedxHit->setMdcId( Identifier(mdcId) );
97 recMdcDedxHit->setPathLength( pathlength);
98 recMdcDedxHit->setDedx(dedx);
99 // log << MSG::DEBUG<<"check Reconstrunction of dE/dx Hit root"<<" pathlength 2 is : "<<(*recdedxhit)->getPathLength()<<endreq;
100
101 int mdcHitId = recMdcDedxHitRoot->mdcHitId();
102 //std::cout << __FILE__ << __LINE__ << " size: " << mdcHitCol->size() << " id: " << mdcHitId << std::endl;
103 if ( mdcHitId >= 0 ) {
104 recMdcDedxHit->setMdcHit( dynamic_cast<RecMdcHit*>(mdcHitCol->containedObject(mdcHitId)));
105 }
106 int mdcKalHelixSegId = recMdcDedxHitRoot->mdcKalHelixSegId();
107 //std::cout << __FILE__ << __LINE__ << " size: " << mdcKalHelixSegCol->size() << " id: " << mdcKalHelixSegId << std::endl;
108 if ( mdcKalHelixSegId >= 0 ) {
109 recMdcDedxHit->setMdcKalHelixSeg( dynamic_cast<RecMdcKalHelixSeg*>(mdcKalHelixSegCol->containedObject(mdcKalHelixSegId)));
110 }
111
112 recMdcDedxHitCol->push_back(recMdcDedxHit);
113 //delete dedxTds;
114 // dedxTds = NULL;
115 }
116 //m_dedxCol->Delete();
117 delete m_recMdcDedxHitCol;
118 m_recMdcDedxHitCol = 0;
119
120 return StatusCode::SUCCESS;
121}
122
123
124StatusCode RecMdcDedxHitCnv::DataObjectToTObject(DataObject* obj,RootAddress* rootaddr) {
125 MsgStream log(msgSvc(), "RecMdcDedxHitCnv");
126 log << MSG::DEBUG << "RecMdcDedxHitCnv::DataObjectToTObject" << endreq;
127 StatusCode sc=StatusCode::SUCCESS;
128
129 RecMdcDedxHitCol * recMdcDedxHitCol=dynamic_cast<RecMdcDedxHitCol *> (obj);
130 if (!recMdcDedxHitCol) {
131 log << MSG::ERROR << "Could not downcast to RecMdcDedxHitCol" << endreq;
132 return StatusCode::FAILURE;
133 }
134
135 DataObject *evt;
136 m_eds->findObject(EventModel::Recon::Event,evt);
137 if (evt==NULL) {
138 log << MSG::ERROR << "Could not get RecEvent in TDS " << endreq;
139 return StatusCode::FAILURE;
140 }
141 ReconEvent * devtTds=dynamic_cast<ReconEvent *> (evt);
142 if (!devtTds) {
143 log << MSG::ERROR << "RecMdcDedxHitCnv:Could not downcast to TDS RecEvent" << endreq;
144 }
145 IOpaqueAddress *addr;
146 m_cnvSvc->getRecTrackCnv()->createRep(evt,addr);
148 const TObjArray *m_recMdcDedxHitCol = recEvt->getRecMdcDedxHitCol();
149 if (!m_recMdcDedxHitCol) return sc;
150 recEvt->clearRecMdcDedxHitCol(); //necessary in case there is I/O at the same time since array is static
151
152 //******************** get according mdcHIt and mdcKalHelixSeg of MdcDedxHit ****************
153
154 RecMdcHitCol::iterator recMdcHitColbegin, recMdcHitColend;
155 RecMdcKalHelixSegCol::iterator recMdcKalHelixSegColbegin, recMdcKalHelixSegColend;
156
157 IDataProviderSvc* dataSvc = 0;
158 sc = serviceLocator()->getService("EventDataSvc",
159 IDataProviderSvc::interfaceID(), (IInterface*&)dataSvc);
160 if ( sc.isFailure() ) {
161 log << MSG::FATAL << "Could not get EventDataSvc in RecMdcDedxHitCnv" << endreq;
162 return sc;
163 }
164
165 // Retrieve Mdc Hit
166 SmartDataPtr<RecMdcHitCol> recMdcHitCol(dataSvc, EventModel::Recon::RecMdcHitCol);
167 if (!recMdcHitCol) {
168 log << MSG::ERROR << "Could not downcast to RecMdcHitCol" << endreq;
169 return StatusCode::FAILURE;
170 }
171 else {
172 recMdcHitColbegin = recMdcHitCol->begin();
173 recMdcHitColend = recMdcHitCol->end();
174 }
175
176 SmartDataPtr<RecMdcKalHelixSegCol> recMdcKalHelixSegCol(dataSvc, EventModel::Recon::RecMdcKalHelixSegCol);
177 if (!recMdcKalHelixSegCol) {
178 log << MSG::ERROR << "Could not downcast to RecMdcKalHelixSegCol" << endreq;
179 return StatusCode::FAILURE;
180 }
181 else {
182 recMdcKalHelixSegColbegin = recMdcKalHelixSegCol->begin();
183 recMdcKalHelixSegColend = recMdcKalHelixSegCol->end();
184 }
185 //******************************************************************************
186
187
188 RecMdcDedxHitCol::const_iterator recMdcDedxHit;
189 for (recMdcDedxHit = recMdcDedxHitCol->begin(); recMdcDedxHit != recMdcDedxHitCol->end(); recMdcDedxHit++) {
190 int trackId = (*recMdcDedxHit)->getTrkId();
191 int flagLR = (*recMdcDedxHit)->getFlagLR();
192 UInt_t mdcId =(*recMdcDedxHit)->getMdcId().get_value();
193 double pathlength = (*recMdcDedxHit)->getPathLength();
194 double dedx = (*recMdcDedxHit)->getDedx();
195
196 log << MSG::DEBUG<<"DataObjectToTObject: check Reconstrunction of dE/dx Hit::"<<" trackId: "<<trackId<<" flagLR: "<<flagLR<<" pathlength: "<<pathlength<<" dedx: "<<dedx<<endreq;
197 TRecMdcDedxHit *recMdcDedxHitRoot = new TRecMdcDedxHit();
198 //m_common.m_recMdcDedxHitMap[(*recMdcDedxHit)] = recMdcDedxHitRoot;
199 recMdcDedxHitRoot->setTrkId(trackId);
200 recMdcDedxHitRoot->setFlagLR(flagLR);
201 recMdcDedxHitRoot->setMdcId( mdcId );
202 recMdcDedxHitRoot->setPathLength( pathlength);
203 recMdcDedxHitRoot->setDedx(dedx);
204
205 //int trackId1 = recMdcDedxHitRoot->trkId();
206 //cout<<"trackId: "<<trackId1<<endl;
207 //int flagLR1 = recMdcDedxHitRoot->flagLR();
208 //cout<<"flagLR: "<<flagLR1<<endl;
209 //long int mdcId1(recMdcDedxHitRoot->mdcId());
210 //cout<<"mdcID: "<<mdcId1<<endl;
211 //double pathlength1 = recMdcDedxHitRoot->pathLength();
212 //cout<<"pathlength: " <<pathlength1<<endl;
213 //double dedx1 = recMdcDedxHitRoot->getDedx();
214 //cout<<"dedx: "<<dedx1<<endl;
215
216
217 if ( (*recMdcDedxHit)->isMdcHitValid() ) {
218 RecMdcHitCol::iterator it = find(recMdcHitColbegin, recMdcHitColend, (*recMdcDedxHit)->getMdcHit());
219 recMdcDedxHitRoot->setMdcHitId( it - recMdcHitColbegin );
220 }
221 else{
222 recMdcDedxHitRoot->setMdcHitId(-1);
223 }
224
225 if ( (*recMdcDedxHit)->isMdcKalHelixSegValid() ) {
226 RecMdcKalHelixSegCol::iterator it = find(recMdcKalHelixSegColbegin, recMdcKalHelixSegColend, (*recMdcDedxHit)->getMdcKalHelixSeg());
227 recMdcDedxHitRoot->setMdcKalHelixSegId( it - recMdcKalHelixSegColbegin );
228 }
229 else{
230 recMdcDedxHitRoot->setMdcKalHelixSegId(-1);
231 }
232
233 //log << MSG::DEBUG<<"check Reconstrunction of dE/dx Hit root"<<" pathlength 2 is : "<<(*recMdcDedxHit)->getPathLength()<<endreq;
234 recEvt->addRecMdcDedxHit(recMdcDedxHitRoot);
235 }
236
237 return StatusCode::SUCCESS;
238}
239
240#endif
ObjectVector< RecMdcDedxHit > RecMdcDedxHitCol
RecMdcDedxHitCnv(ISvcLocator *svc)
virtual StatusCode TObjectToDataObject(DataObject *&obj)
transformation from root
virtual StatusCode DataObjectToTObject(DataObject *obj, RootAddress *addr)
transformation to root
void setMdcKalHelixSeg(const RecMdcKalHelixSeg *mdcKalHelixSeg)
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.
const TObjArray * getRecMdcDedxHitCol() const
retrieve the whole TObjArray of Dedx Data
void addRecMdcDedxHit(TRecMdcDedxHit *Track)
Add a Dedx into the TOF Data collection.
static std::map< const TObject *, const RecMdcDedxHit * > m_rootRecMdcDedxHitMap