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"
58 Algorithm(name, pSvcLocator)
60 declareProperty(
"AcceleratorStatus", m_acceleratorStatus );
61 declareProperty(
"MagneticField", m_magneticField );
62 declareProperty(
"FirstIteration", m_firstIteration );
63 declareProperty(
"PrintOutInfo", m_printOutInfo );
64 declareProperty(
"neighborhood", m_neighborhood=4 );
65 declareProperty(
"store_trans_time", m_store_trans_time=0);
76 MsgStream log(
msgSvc(), name());
77 log << MSG::INFO <<
"MrpcRecDBS in initialize()" << endreq;
80 StatusCode scg = service(
"TofGeomSvc",
tofGeomSvc);
81 if (scg== StatusCode::SUCCESS) {
82 log << MSG::INFO <<
"MrpcRecDBS Get Geometry Service Sucessfully!" << endreq;
84 log << MSG::ERROR <<
"MrpcRecDBS Get Geometry Service Failed !" << endreq;
85 return StatusCode::FAILURE;
89 StatusCode scc = service(
"TofCaliSvc",
tofCaliSvc);
90 if (scc == StatusCode::SUCCESS) {
91 log << MSG::INFO <<
"MrpcRecDBS Get Calibration Service Sucessfully!" << endreq;
93 log << MSG::ERROR <<
"MrpcRecDBS Get Calibration Service Failed !" << endreq;
94 return StatusCode::FAILURE;
98 StatusCode scd = service(
"RawDataProviderSvc",
tofDigiSvc);
99 if (scd == StatusCode::SUCCESS) {
100 log << MSG::INFO <<
"MrpcRecDBS Get Tof Raw Data Service Sucessfully!" << endreq;
102 log << MSG::ERROR <<
"MrpcRecDBS Get Tof Raw Data Service Failed !" << endreq;
103 return StatusCode::FAILURE;
113 if(m_store_trans_time==1)
115 FileName =
"output_mrpc_reconstructed.root";
116 m_TreeFile=
new TFile(TString(FileName),
"RECREATE",
"TreeFile");
117 m_tree_mrpc =
new TTree(
"tree_mrpc_rec",
"");
118 m_tree_mrpc->Branch(
"m_partId",&m_partID,
"m_partId/D");
119 m_tree_mrpc->Branch(
"m_stripidentifier",&m_stripidentifier,
"m_stripidentifier/D");
120 m_tree_mrpc->Branch(
"m_time_1",&m_time_1,
"m_time_1/D");
121 m_tree_mrpc->Branch(
"m_time_2",&m_time_2,
"m_time_2/D");
122 m_tree_mrpc->Branch(
"m_trans_time",&m_trans_time,
"m_trans_time/D");
123 m_tree_mrpc->Branch(
"m_r_ext",&m_r_ext,
"m_r_ext/D");
124 m_tree_mrpc->Branch(
"m_phi_ext",&m_phi_ext,
"m_phi_ext/D");
125 m_tree_mrpc->Branch(
"m_mrpc_dbs",&m_mrpc_dbs,
"m_mrpc_dbs/D");
126 m_tree_mrpc->Branch(
"m_mrpc_extrap",&m_mrpc_extrap,
"m_extrap/D");
127 m_tree_mrpc->Branch(
"m_mrpc_aver",&m_mrpc_aver,
"m_mrpc_aver/D");
128 m_tree_mrpc->Branch(
"m_transition_time_simulation",&m_transition_time_simulation,
"m_transition_time_simulation/D");
137 return StatusCode::SUCCESS;
141 MsgStream log(
msgSvc(), name());
142 log << MSG::INFO <<
"MrpcRecDBS begin_run!"<< endreq;
143 return StatusCode::SUCCESS;
152 MsgStream log(
msgSvc(), name());
153 log << MSG::INFO <<
"MrpcRecDBS in execute()!" << endreq;
155 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
157 log << MSG::FATAL <<
"MrpcRecDBS could not find Event Header!" << endreq;
158 return StatusCode::FAILURE;
160 int run = eventHeader->runNumber();
161 int event = eventHeader->eventNumber();
162 if( ( event % 1000 == 0 ) && m_printOutInfo ) {
163 std::cout <<
"run:" << run <<
" event: " <<
event << std::endl;
165 log << MSG::INFO <<
"run= " << run <<
" event= " <<
event << endreq;
171 if( m_acceleratorStatus ==
"Colliding" ) {
173 SmartDataPtr<RecEsTimeCol> estimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
174 if( !estimeCol || ( estimeCol->size() == 0 ) ) {
175 log << MSG::WARNING <<
"MrpcRecDBS Could not find RecEsTimeCol! Run = " << run <<
" Event = " <<
event << endreq;
176 return StatusCode::SUCCESS;
178 RecEsTimeCol::iterator iter_ESTime=estimeCol->begin();
179 double t0 = (*iter_ESTime)->getTest();
180 int t0Stat = (*iter_ESTime)->getStat();
181 log << MSG::INFO <<
"t0= " << t0 <<
" t0Stat= " << t0Stat << endreq;
187 SmartDataPtr<RecMdcKalTrackCol> mdcKalTrackCol(eventSvc(),
"/Event/Recon/RecMdcKalTrackCol");
188 if( !mdcKalTrackCol ) {
189 log << MSG::WARNING <<
"No MdcKalTrackCol in TDS! Run = " << run <<
" Event = " <<
event << endreq;
190 return StatusCode::SUCCESS;
196 SmartDataPtr<RecExtTrackCol> extTrackCol(eventSvc(),
"/Event/Recon/RecExtTrackCol");
198 log << MSG::WARNING <<
"No ExtTrackCol in TDS! Run = " << run <<
" Event = " <<
event << endreq;
199 return StatusCode::SUCCESS;
203 if( m_printOutInfo ) { m_printOut->
setExtTrackNum( extTrackCol->size() ); }
210 RecExtTrackCol::iterator iter_track = extTrackCol->begin();
211 for( ; iter_track < extTrackCol->end(); iter_track++ ) {
212 RecMdcKalTrackCol::iterator iter_kal = mdcKalTrackCol->begin();
213 for( ; iter_kal != mdcKalTrackCol->end(); iter_kal++ ) {
214 if( (*iter_kal)->trackId() == (*iter_track)->trackId() )
break;
217 if( iter_kal != mdcKalTrackCol->end() ) {
218 for(
unsigned int i=0; i<5; i++ ) {
219 kal[i] = (*iter_kal)->getStat( 1, i );
223 tof->
setExtTrack( (*iter_track), kal, t0, t0Stat );
225 if( tofTrackVec->size()>0 ) {
226 std::vector<MrpcDBSTrack*>::iterator iterExt = tofTrackVec->begin();
227 for( ; iterExt < tofTrackVec->end(); iterExt++ ) {
228 if( (*iterExt)->isNoHit() )
continue;
233 tofTrackVec->push_back( tof );
244 if( tofDataMap.empty() ) {
245 log << MSG::WARNING <<
"No Tof Data Map in RawDataProviderSvc! Run=" << run <<
" Event=" <<
event << endreq;
249 std::vector<MrpcDBSTrack*>::iterator
iter = tofTrackVec->begin();
250 for( ;
iter < tofTrackVec->end();
iter++ ) {
251 if( (*iter)->isNoHit() )
continue;
252 (*iter)->setTofData( tofDataMap,m_neighborhood );
254 if( (*iter)->isNoHit() )
continue;
255 (*iter)->match(tofTrackVec );
259 iter = tofTrackVec->begin();
261 for( ;
iter < tofTrackVec->end();
iter++ )
263 (*iter)->setCalibration();
270 if(m_store_trans_time==1)
275 m_mrpc_dbs=(*iter)->mrpc_dbs();
276 m_mrpc_extrap=(*iter)->mrpc_extra();
277 m_mrpc_aver=(*iter)->mrpc_aver();
279 m_partID=(*iter)->mrpc_partid();
280 m_stripidentifier=(*iter)->mrpc_stripidentifier();
281 m_time_1=(*iter)->mrpc_time_1();
282 m_time_2=(*iter)->mrpc_time_2();
283 m_trans_time=(*iter)->mrpc_trans_time();
285 m_r_ext=(*iter)->mrpc_r_ext();
286 m_phi_ext=(*iter)->mrpc_phi_ext();
290 SmartDataPtr<Event::TofMcHitCol> mcParticleCol(eventSvc(),
"/Event/MC/TofMcHitCol");
291 double mc_truth_x,mc_truth_y;
292 double mc_truth_trans_time;
293 bool write_root_data=
false;
302 std::cout <<
"Could not retrieve McParticelCol" << std::endl;
307 Event::TofMcHitCol::iterator iter_mc = mcParticleCol->begin();
308 for (; iter_mc != mcParticleCol->end(); iter_mc++)
313 mc_truth_x=(*iter_mc)->getPositionX();
314 mc_truth_y=(*iter_mc)->getPositionY();
315 const Identifier ident = (*iter_mc)->identify();
327 if(m_partID==mc_truth_partid && mc_truth_tofmod==((
int)m_stripidentifier/25) && ((
int)m_stripidentifier%25)==(mc_truth_tofstr))
329 write_root_data=
true;
336 if(mc_truth_trans_time==0) m_transition_time_simulation=-100;
337 else m_transition_time_simulation=mc_truth_trans_time;
339 if(write_root_data) m_tree_mrpc->Fill();
351 SmartDataPtr<RecTofTrackCol> tofTrackCol(eventSvc(),
"/Event/Recon/RecTofTrackCol");
353 log << MSG::FATAL <<
"MrpcRecDBS could not find RecTofTrackCol!" << endreq;
354 return StatusCode::FAILURE;
360 log << MSG::FATAL <<
"In MrpcRecDBS: AcceleratorStatus is NOT correct! m_acceleratorStatus = " << m_acceleratorStatus << endreq;
361 return StatusCode::FAILURE;
364 return StatusCode::SUCCESS;
371 if( m_printOutInfo ) {
378 if(m_store_trans_time==1)
386 return StatusCode::SUCCESS;
394 std::vector<MrpcDBSTrack*>::iterator
iter = tofTrackVec->begin();
395 for( ;
iter < tofTrackVec->end();
iter++ ) {
398 tofTrackVec->clear();
IRawDataProviderSvc * tofDigiSvc
IRawDataProviderSvc * tofDigiSvc
std::vector< MrpcTrack * > TofTrackVec
std::multimap< unsigned int, TofData * > TofDataMap
static G4int Get_module_mrpc_from_unique_identifier(G4int unique_identifier_f)
static double GetTransitionTime_extrap_track(G4double x_mm, G4double y_mm, int partId_f, int module_mrpc_f, int my_strip)
static G4int Get_stripnumber_from_unique_identifier(G4int unique_identifier_f)
virtual TofDataMap & tofDataMapTof(double estime=0)=0
void setTrack2(MrpcDBSTrack *&tof)
void setTrack1Col(std::vector< MrpcDBSTrack * > *&tofTrackVec)
void setExtTrackNum(unsigned int ntrk)
void setTrack3(MrpcDBSTrack *&tof)
void setTrack4(MrpcDBSTrack *&tof)
StatusCode RegisterNullRecTofTrackCol()
StatusCode RegisterTDS(std::vector< MrpcDBSTrack * > *&tofTrackVec)
void clearTofTrackVec(std::vector< MrpcDBSTrack * > *&tofTrackVec)
MrpcDBSRec(const std::string &name, ISvcLocator *pSvcLocator)
void setExtTrack(RecExtTrack *extTrack, int kal[5], double t0, int t0Stat)
void getMultiHit(MrpcDBSTrack *&)
static int phi_module(const Identifier &id)
static int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)