BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcPrintSvc.cxx
Go to the documentation of this file.
2#include "GaudiKernel/Kernel.h"
3#include "GaudiKernel/IInterface.h"
4#include "GaudiKernel/StatusCode.h"
5#include "GaudiKernel/SvcFactory.h"
6#include "GaudiKernel/MsgStream.h"
7#include "GaudiKernel/ISvcLocator.h"
8#include "GaudiKernel/Bootstrap.h"
9#include "GaudiKernel/IDataProviderSvc.h"
10#include "GaudiKernel/DataSvc.h"
12#include "GaudiKernel/SmartDataPtr.h"
13
14#include "Identifier/MdcID.h"
16#include "MdcRawEvent/MdcDigi.h"
20#include "McTruth/McParticle.h"
21#include "McTruth/MdcMcHit.h"
23
24#include <iomanip>
25#include <iostream>
26
27using namespace std;
28using namespace Event;
29
30MdcPrintSvc::MdcPrintSvc( const string& name, ISvcLocator* svcloc) :
31 Service (name, svcloc) {
32
33 // declare properties
34 declareProperty("printHit", m_printHit=1);
35 declareProperty("printTrackDetail", m_printTrackDetail=1);
36 declareProperty("printErrMat", m_printErrMat=0);
37 declareProperty("printTdcAdc", m_printTdcAdc=0);
38 declareProperty("printMcTk", m_printMcTk=0);
39 }
40
42}
43
45 MsgStream log(messageService(), name());
46 log << MSG::INFO << "MdcPrintSvc::initialize()" << endreq;
47
48 StatusCode sc = Service::initialize();
49 if( sc.isFailure() ) return sc;
50
51 ISvcLocator* svcLocator = Gaudi::svcLocator();
52 svcLocator->service("EventDataSvc",eventSvc,true);
53 if (NULL == eventSvc){
54 std::cout << "ERROR Could not load service DataSvc" << std::endl;
55 return StatusCode::FAILURE;
56 }
57
58 IRawDataProviderSvc* irawDataProviderSvc;
59 sc = service ("RawDataProviderSvc", irawDataProviderSvc);
60 m_rawDataProviderSvc = dynamic_cast<RawDataProviderSvc*> (irawDataProviderSvc);
61 if ( sc.isFailure() ){
62 log << MSG::FATAL << "Could not load RawDataProviderSvc!" << endreq;
63 return StatusCode::FAILURE;
64 }
65
66
67 return StatusCode::SUCCESS;
68}
69
71 MsgStream log(messageService(), name());
72 log << MSG::INFO << "MdcPrintSvc::finalize()" << endreq;
73
74 return StatusCode::SUCCESS;
75}
76
77StatusCode MdcPrintSvc::queryInterface(const InterfaceID& riid, void** ppvInterface){
78 if( IID_IMdcPrintSvc.versionMatch(riid) ){
79 *ppvInterface = static_cast<IMdcPrintSvc*> (this);
80 } else{
81 return Service::queryInterface(riid, ppvInterface);
82 }
83 return StatusCode::SUCCESS;
84}
85
86void MdcPrintSvc::printDigi(uint32_t getDigiFlag)const{
87 MdcDigiVec mdcDigiVec = m_rawDataProviderSvc->getMdcDigiVec(getDigiFlag);
88 MdcDigiCol::iterator iter = mdcDigiVec.begin();
89 std::cout<<"//==== "<<name()<<" print MdcDigiVec, nDigi="<<mdcDigiVec.size()<<" :"<<std::endl;
90 for (int iDigi=0;iter!= mdcDigiVec.end(); iter++,iDigi++ ) {
91 long l = MdcID::layer((*iter)->identify());
92 long w = MdcID::wire((*iter)->identify());
93 cout<<"("<<l<<","<<w;
94 if(m_printMcTk) {
95 int tkTruth = (*iter)->getTrackIndex();
96 cout<<";"<<tkTruth;
97 }
98 if(m_printTdcAdc) {
99 double tdc = RawDataUtil::MdcTime((*iter)->getTimeChannel());
100 double adc = RawDataUtil::MdcCharge((*iter)->getChargeChannel());
101 cout<<",t "<<tdc<<",c "<<adc;
102 }
103 cout<<")";
104 if(iDigi%4==0) std::cout<<std::endl;
105 }
106 std::cout<<std::endl;
107}
108
110 MsgStream log(messageService(), name());
111
112 SmartDataPtr<RecMdcTrackCol> recMdcTrackCol(eventSvc,"/Event/Recon/RecMdcTrackCol");
113 if (!recMdcTrackCol) {
114 log << MSG::WARNING << "Could not find RecMdcTrackCol" << endreq;
115 return;
116 }
117
118 std::cout<< "//======= "<<name()<<" RecMdcTrackCol size = "<<recMdcTrackCol->size() << std::endl;
119 RecMdcTrackCol::iterator it = recMdcTrackCol->begin();
120 for (;it!= recMdcTrackCol->end();it++){
121 printRecMdcTrack(*it);
122 }
123
124}
125
127 std::cout<< "//==== "<<name()<<" print RecMdcTrack No."<<tk->trackId()<<" :"<< std::endl;
128 cout <<" dr "<<tk->helix(0)
129 <<" phi0 "<<tk->helix(1)
130 <<" cpa "<<tk->helix(2)
131 <<" z0 "<<tk->helix(3)
132 <<" tanl "<<tk->helix(4)
133 <<endl;
134 if(m_printTrackDetail){
135 std::cout<<" q "<<tk->charge()
136 <<" theta "<<tk->theta()
137 <<" phi "<<tk->phi()
138 <<" x0 "<<tk->x()
139 <<" y0 "<<tk->y()
140 <<" z0 "<<tk->z()
141 <<" r0 "<<tk->r()
142 <<endl;
143 std::cout <<" p "<<tk->p()
144 <<" pt "<<tk->pxy()
145 <<" pxyz("<<tk->px()
146 <<","<<tk->py()
147 <<","<<tk->pz()
148 <<")"<<endl;
149 std::cout<<" tkStat "<<tk->stat()
150 <<" chi2 "<<tk->chi2()
151 <<" ndof "<<tk->ndof()
152 <<" nhit "<<tk->getNhits()
153 <<" nst "<<tk->nster()
154 <<endl;
155 if(m_printErrMat){
156 std::cout<< "errmat " << std::endl;
157 for (int i=0; i<15; i++){ std::cout<< " "<<tk->err(i); }
158 std::cout<< " " << std::endl;
159 }
160 }
161
162 if(m_printHit){
163 int haveDigi[43][288];
164 if(m_printMcTk) {
165 for(int ii=0;ii<43;ii++){
166 for(int jj=0;jj<43;jj++){
167 haveDigi[ii][jj]=-9999;
168 }
169 }
170 MdcDigiVec mdcDigiVec = m_rawDataProviderSvc->getMdcDigiVec();
171 MdcDigiCol::iterator iter = mdcDigiVec.begin();
172 std::cout<<name()<<"//==== "<<name()<<" print MdcDigiVec, nDigi="<<mdcDigiVec.size()<<" :"<<std::endl;
173 for (int iDigi=0;iter!= mdcDigiVec.end(); iter++,iDigi++ ) {
174 long l = MdcID::layer((*iter)->identify());
175 long w = MdcID::wire((*iter)->identify());
176 haveDigi[l][w]=(*iter)->getTrackIndex();
177 }
178 }
179
180 int nhits = tk->getVecHits().size();
181 std::cout<<"nHits=" <<nhits<< std::endl;
182 cout<<"No. ";
183 if(m_printMcTk) cout<<"mcTkId ";
184 cout<<"(layer,wire,lr) stat z"<<endl;
185 for(int ii=0; ii <nhits ; ii++){
186 Identifier id(tk->getVecHits()[ii]->getMdcId());
187 int layer = MdcID::layer(id);
188 int wire = MdcID::wire(id);
189 cout<<ii<<":";
190 if(m_printMcTk) { cout<<haveDigi[layer][wire]; }
191 cout<<" ("<<layer<<","<<wire
192 <<","<<tk->getVecHits()[ii]->getFlagLR()
193 <<") "<<tk->getVecHits()[ii]->getStat()
194 <<" "<<tk->getVecHits()[ii]->getZhit()<< " "<<std::endl;
195 }//end of hit list
196 std::cout << " "<< std::endl;
197 }
198}
199
201 MsgStream log(messageService(), name());
202
203 SmartDataPtr<MdcMcHitCol> mdcMcHitCol(eventSvc,"/Event/MC/MdcMcHitCol");
204 if (!mdcMcHitCol) {
205 log << MSG::WARNING << "Could not find MdcMcHitCol" << endreq;
206 return;
207 }
208
209 int ihit= 0;
210 cout<< "//==== "<<name()<<" print MdcMcHitCol nMcHit="<<mdcMcHitCol->size()<< endl;
211 if (mdcMcHitCol->size()>0){
212 cout<<"No. (layer,wire) mcTk (x,y,z) lr driftdist(cm) energy"<<endl;
213 }
214 MdcMcHitCol::iterator iter_mchit = mdcMcHitCol->begin();
215 for (;iter_mchit != mdcMcHitCol->end(); iter_mchit++,ihit++ ) {
216 const Identifier id= (*iter_mchit)->identify();
217 int layer = MdcID::layer(id);
218 int wire = MdcID::wire(id);
219 int iMcTk = (*iter_mchit)->getTrackIndex();
220 double mcX = (*iter_mchit)->getPositionX()/10.;
221 double mcY = (*iter_mchit)->getPositionY()/10.;
222 double mcZ = (*iter_mchit)->getPositionZ()/10.;
223 double mcLR = (*iter_mchit)->getPositionFlag();
224 double mcDrift = (*iter_mchit)->getDriftDistance()/10.;
225 double mcEnergy = (*iter_mchit)->getDepositEnergy()/10.;
226 if (mcLR == 0) mcLR = -1;
227 cout<<ihit <<" ("<<layer<<","<<wire<<") "<< iMcTk
228 <<" ("<< mcX<<"," <<mcY<<","<< mcZ
229 <<") " <<mcLR
230 <<" " <<mcDrift
231 <<" " <<mcEnergy
232 <<endl;
233 }
234}
double w
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
std::vector< MdcDigi * > MdcDigiVec
const double theta() const
Definition: DstMdcTrack.h:59
const double r() const
Definition: DstMdcTrack.h:64
const double py() const
Definition: DstMdcTrack.h:56
const HepSymMatrix err() const
const double chi2() const
Definition: DstMdcTrack.h:66
const int charge() const
Definition: DstMdcTrack.h:53
const int trackId() const
Definition: DstMdcTrack.h:52
const double px() const
Definition: DstMdcTrack.h:55
const double phi() const
Definition: DstMdcTrack.h:60
const double pz() const
Definition: DstMdcTrack.h:57
const double pxy() const
Definition: DstMdcTrack.h:54
const int ndof() const
Definition: DstMdcTrack.h:67
const int stat() const
Definition: DstMdcTrack.h:65
const HepVector helix() const
......
const double z() const
Definition: DstMdcTrack.h:63
const double p() const
Definition: DstMdcTrack.h:58
const int nster() const
Definition: DstMdcTrack.h:68
const double y() const
Definition: DstMdcTrack.h:62
const double x() const
Definition: DstMdcTrack.h:61
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
StatusCode finalize()
Definition: MdcPrintSvc.cxx:70
StatusCode initialize()
Definition: MdcPrintSvc.cxx:44
void printDigi(uint32_t getDigiFlag=0) const
Definition: MdcPrintSvc.cxx:86
void printRecMdcTrack(const RecMdcTrack *tk) const
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
Definition: MdcPrintSvc.cxx:77
MdcPrintSvc(const std::string &name, ISvcLocator *svcloc)
Definition: MdcPrintSvc.cxx:30
void printMdcMcHitCol() const
void printRecMdcTrackCol() const
MdcDigiVec & getMdcDigiVec(uint32_t control=0)
static double MdcTime(int timeChannel)
Definition: RawDataUtil.h:8
static double MdcCharge(int chargeChannel)
Definition: RawDataUtil.h:11
const HitRefVec getVecHits(void) const
Definition: RecMdcTrack.h:60
const int getNhits() const
Definition: RecMdcTrack.h:49
Definition: Event.h:21
int nhits