CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
MrpcRec.cxx
Go to the documentation of this file.
1// Package: MrpcRec
2// BESIII Tof Reconstruction Algorithm.
3// Created by Sun Shengsen (EPC IHEP)
4//
5#include "GaudiKernel/MsgStream.h"
6#include "GaudiKernel/AlgFactory.h"
7#include "GaudiKernel/ISvcLocator.h"
8#include "GaudiKernel/SmartDataPtr.h"
9#include "GaudiKernel/SmartDataLocator.h"
10#include "GaudiKernel/IDataProviderSvc.h"
11#include "GaudiKernel/PropertyMgr.h"
15#include "McTruth/McParticle.h"
16#include "McTruth/TofMcHit.h"
17#include "McTruth/McParticle.h"
28#include "MrpcRec/MrpcRec.h"
29#include "MrpcRec/MrpcTrack.h"
30#include "MrpcRec/MrpcCount.h"
31#include "MrpcRec/MrpcRecTDS.h"
32#include <iostream>
33
36
37using namespace std;
38using namespace Event;
39
40/////////////////////////////////////////////////////////////////////////////
41
44// ITofQCorrSvc* tofQCorrSvc;
45// ITofQElecSvc* tofQElecSvc;
47
48MrpcRec::MrpcRec(const std::string& name, ISvcLocator* pSvcLocator) :
49 Algorithm(name, pSvcLocator)
50{
51 declareProperty( "AcceleratorStatus", m_acceleratorStatus );
52 declareProperty( "MagneticField", m_magneticField );
53 declareProperty( "FirstIteration", m_firstIteration );
54 declareProperty( "PrintOutInfo", m_printOutInfo );
55 declareProperty( "neighborhood", m_neighborhood=6 );//For the time being: 6 is the standardvalue -> It yield the highest reconstruction efficiency!
56}
57
58// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
59
61
62 MsgStream log(msgSvc(), name());
63 log << MSG::INFO << "MrpcRec in initialize()" << endreq;
64
65 //Get TOF Geomertry Service
66 StatusCode scg = service("TofGeomSvc", tofGeomSvc);
67 if (scg== StatusCode::SUCCESS) {
68 log << MSG::INFO << "MrpcRec Get Geometry Service Sucessfully!" << endreq;
69 }else {
70 log << MSG::ERROR << "MrpcRec Get Geometry Service Failed !" << endreq;
71 return StatusCode::FAILURE;
72 }
73
74 //Get TOF Calibtration Service
75 StatusCode scc = service("TofCaliSvc", tofCaliSvc);
76 if (scc == StatusCode::SUCCESS) {
77 log << MSG::INFO << "MrpcRec Get Calibration Service Sucessfully!" << endreq;
78 } else {
79 log << MSG::ERROR << "MrpcRec Get Calibration Service Failed !" << endreq;
80 return StatusCode::FAILURE;
81 }
82
83 //Get TOF Raw Data Provider Service
84 StatusCode scd = service("RawDataProviderSvc", tofDigiSvc);
85 if (scd == StatusCode::SUCCESS) {
86 log << MSG::INFO << "MrpcRec Get Tof Raw Data Service Sucessfully!" << endreq;
87 } else {
88 log << MSG::ERROR << "MrpcRec Get Tof Raw Data Service Failed !" << endreq;
89 return StatusCode::FAILURE;
90 }
91
92
93 if( m_printOutInfo ) { m_printOut = new MrpcCount; }
94
95 return StatusCode::SUCCESS;
96}
97
98StatusCode MrpcRec::beginRun(){
99 MsgStream log(msgSvc(), name());
100 log << MSG::INFO <<"MrpcRec begin_run!"<< endreq;
101 return StatusCode::SUCCESS;
102}
103
104// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
105
106StatusCode MrpcRec::execute() {
107
108 MsgStream log(msgSvc(), name());
109 log << MSG::INFO << "MrpcRec in execute()!" << endreq;
110
111 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
112 if( !eventHeader ) {
113 log << MSG::FATAL << "MrpcRec could not find Event Header!" << endreq;
114 return StatusCode::FAILURE;
115 }
116 int run = eventHeader->runNumber();
117 int event = eventHeader->eventNumber();
118 if( ( event % 1000 == 0 ) && m_printOutInfo ) {
119 std::cout << "run:" << run << " event: " << event << std::endl;
120 }
121 log << MSG::INFO << "run= " << run << " event= " << event << endreq;
122
123 MrpcRecTDS tds;
125
126 // Magnetic Field: Colliding data and Cosmic Ray
127 if( m_acceleratorStatus == "Colliding" ) {
128 // Retrieve Event Start Time
129 SmartDataPtr<RecEsTimeCol> estimeCol(eventSvc(),"/Event/Recon/RecEsTimeCol");
130 if( !estimeCol || ( estimeCol->size() == 0 ) ) {
131 log << MSG::WARNING << "MrpcRec Could not find RecEsTimeCol! Run = " << run << " Event = " << event << endreq;
132 return StatusCode::SUCCESS;
133 }
134 RecEsTimeCol::iterator iter_ESTime=estimeCol->begin();
135 double t0 = (*iter_ESTime)->getTest();
136 int t0Stat = (*iter_ESTime)->getStat();
137 log << MSG::INFO << "t0= " << t0 << " t0Stat= " << t0Stat << endreq;
138
139
140
141 // Kalman Filter Track
142 SmartDataPtr<RecMdcKalTrackCol> mdcKalTrackCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
143 if( !mdcKalTrackCol ) {
144 log << MSG::WARNING << "No MdcKalTrackCol in TDS! Run = " << run << " Event = " << event << endreq;
145 return StatusCode::SUCCESS;
146 }
147
148
149
150 // Tof Get Extrapolated Track
151 SmartDataPtr<RecExtTrackCol> extTrackCol(eventSvc(),"/Event/Recon/RecExtTrackCol");
152 if( !extTrackCol ) {
153 log << MSG::WARNING << "No ExtTrackCol in TDS! Run = " << run << " Event = " << event << endreq;
154 return StatusCode::SUCCESS;
155 }
156 else {
157 if( m_printOutInfo ) { m_printOut->setExtTrackNum( extTrackCol->size() ); }
158 }
159
160
161
162 TofTrackVec* tofTrackVec = new TofTrackVec;
163 RecExtTrackCol::iterator iter_track = extTrackCol->begin();
164 for( ; iter_track < extTrackCol->end(); iter_track++ ) {
165 RecMdcKalTrackCol::iterator iter_kal = mdcKalTrackCol->begin();
166 for( ; iter_kal != mdcKalTrackCol->end(); iter_kal++ ) {
167 if( (*iter_kal)->trackId() == (*iter_track)->trackId() ) break;
168 }
169 int kal[5] = {-1};
170 if( iter_kal != mdcKalTrackCol->end() ) {
171 for( unsigned int i=0; i<5; i++ ) {
172 kal[i] = (*iter_kal)->getStat( 1, i );
173 }
174 }
175 MrpcTrack* tof = new MrpcTrack;
176 tof->setExtTrack( (*iter_track), kal, t0, t0Stat );
177
178 if( tofTrackVec->size()>0 ) {
179 std::vector<MrpcTrack*>::iterator iterExt = tofTrackVec->begin();
180 for( ; iterExt < tofTrackVec->end(); iterExt++ ) {
181 if( (*iterExt)->isNoHit() ) continue;
182 tof->getMultiHit( *iterExt );
183 }
184 }
185
186 tofTrackVec->push_back( tof );
187 }
188
189 if( m_printOutInfo ) {
190 m_printOut->setTrack1Col( tofTrackVec );
191 }
192
193 // Retrieve Tof Digi Data
194 TofDataMap tofDataMap = tofDigiSvc->tofDataMapTof( t0 );
195 if( tofDataMap.empty() ) {
196 log << MSG::WARNING << "No Tof Data Map in RawDataProviderSvc! Run=" << run << " Event=" << event << endreq;
197 }
198
199
200 std::vector<MrpcTrack*>::iterator iter = tofTrackVec->begin();
201 for( ; iter < tofTrackVec->end(); iter++ ) {
202 if( (*iter)->isNoHit() ) continue;
203 (*iter)->setTofData( tofDataMap,m_neighborhood );
204 if( m_printOutInfo ) { m_printOut->setTrack2( (*iter) ); }
205 if( (*iter)->isNoHit() ) continue;
206 (*iter)->match(tofTrackVec );
207 if( m_printOutInfo ) { m_printOut->setTrack3( (*iter) ); }
208 }
209
210 iter = tofTrackVec->begin();
211 for( ; iter < tofTrackVec->end(); iter++ )
212 {
213 (*iter)->setCalibration();
214 }
215
216 tds.RegisterTDS( eventHeader->runNumber(), eventHeader->eventNumber(), tofTrackVec );
217
218 clearTofTrackVec( tofTrackVec );
219
220// Check RecTofTrackCol Registered
221 SmartDataPtr<RecTofTrackCol> tofTrackCol(eventSvc(),"/Event/Recon/RecTofTrackCol");
222 if (!tofTrackCol) {
223 log << MSG::FATAL << "MrpcRec could not find RecTofTrackCol!" << endreq;
224 return StatusCode::FAILURE;
225 }
226
227 }
228 else {
229 log << MSG::FATAL << "In MrpcRec: AcceleratorStatus is NOT correct! m_acceleratorStatus = " << m_acceleratorStatus << endreq;
230 return StatusCode::FAILURE;
231 }
232
233 return StatusCode::SUCCESS;
234
235}
236
237// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
238
239StatusCode MrpcRec::finalize() {
240 if( m_printOutInfo ) {
241 m_printOut->final();
242 delete m_printOut;
243 }
244 return StatusCode::SUCCESS;
245}
246
247
248//----------------------------------------------------------------------------
249
250void MrpcRec::clearTofTrackVec( std::vector<MrpcTrack*>*& tofTrackVec) {
251 if( tofTrackVec ) {
252 std::vector<MrpcTrack*>::iterator iter = tofTrackVec->begin();
253 for( ; iter < tofTrackVec->end(); iter++ ) {
254 delete (*iter);
255 }
256 tofTrackVec->clear();
257 delete tofTrackVec;
258 }
259 return;
260}
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
ITofGeomSvc * tofGeomSvc
Definition: MrpcRec.cxx:42
ITofCaliSvc * tofCaliSvc
Definition: MrpcRec.cxx:43
IRawDataProviderSvc * tofDigiSvc
Definition: MrpcRec.cxx:46
std::vector< MrpcTrack * > TofTrackVec
Definition: MrpcTrack.h:220
IMessageSvc * msgSvc()
std::multimap< unsigned int, TofData * > TofDataMap
Definition: TofData.h:244
ITofCaliSvc * tofCaliSvc
virtual TofDataMap & tofDataMapTof(double estime=0)=0
void setExtTrackNum(unsigned int ntrk)
Definition: MrpcCount.cxx:122
void setTrack3(MrpcTrack *&tof)
Definition: MrpcCount.cxx:169
void setTrack2(MrpcTrack *&tof)
Definition: MrpcCount.cxx:152
void final()
Definition: MrpcCount.cxx:229
void setTrack1Col(std::vector< MrpcTrack * > *&tofTrackVec)
Definition: MrpcCount.cxx:143
StatusCode RegisterNullRecTofTrackCol()
Definition: MrpcRecTDS.cxx:20
StatusCode RegisterTDS(int runNumber, int eventNumber, std::vector< MrpcTrack * > *&tofTrackVec)
Definition: MrpcRecTDS.cxx:56
StatusCode beginRun()
Definition: MrpcRec.cxx:98
MrpcRec(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MrpcRec.cxx:48
StatusCode execute()
Definition: MrpcRec.cxx:106
StatusCode initialize()
Definition: MrpcRec.cxx:60
StatusCode finalize()
Definition: MrpcRec.cxx:239
void clearTofTrackVec(std::vector< MrpcTrack * > *&tofTrackVec)
Definition: MrpcRec.cxx:250
void getMultiHit(MrpcTrack *&)
Definition: MrpcTrack.cxx:349
void setExtTrack(RecExtTrack *extTrack, int kal[5], double t0, int t0Stat)
Definition: MrpcTrack.cxx:158
Definition: Event.h:21