CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
MrpcDBSRec.cxx
Go to the documentation of this file.
1// Package: MrpcDBSRec
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"
12#include "EventModel/EventHeader.h"
13#include "EventModel/EventModel.h"
14#include "ReconEvent/ReconEvent.h"
15#include "McTruth/McParticle.h"
16#include "McTruth/TofMcHit.h"
17#include "McTruth/McParticle.h"
18#include "EvTimeEvent/RecEsTime.h"
19#include "ExtEvent/RecExtTrack.h"
20#include "DstEvent/TofHitStatus.h"
21#include "TofRecEvent/RecTofTrack.h"
22
23//#include "TofRecEvent/RecBTofCalHit.h"
24//#include "TofRecEvent/RecETofCalHit.h"
25
26#include "TofGeomSvc/ITofGeomSvc.h"
27#include "TofCaliSvc/ITofCaliSvc.h"
28#include "RawDataProviderSvc/IRawDataProviderSvc.h"
29#include "RawDataProviderSvc/TofData.h"
30#include "MrpcRecDBS/MrpcDBSRec.h"
31#include "MrpcRecDBS/MrpcDBSTrack.h"
32#include "MrpcRecDBS/MrpcDBSCount.h"
33#include "MrpcRecDBS/MrpcDBSRecTDS.h"
34#include <iostream>
35#include "ReconEvent/ReconEvent.h"
36#include "McTruth/McParticle.h"
37#include "McTruth/TofMcHit.h"
38#include "McTruth/McParticle.h"
39#include "MdcRecEvent/RecMdcTrack.h"
40#include "EmcRecEventModel/RecEmcShower.h"
41
42#include "TofSim/BesTofDigitizerEcV4_dbs.hh"
43#include "Identifier/TofID.h"
44
45
46using namespace std;
47using namespace Event;
48
49/////////////////////////////////////////////////////////////////////////////
50
53// ITofQCorrSvc* tofQCorrSvc;
54// ITofQElecSvc* tofQElecSvc;
56
57MrpcDBSRec::MrpcDBSRec(const std::string& name, ISvcLocator* pSvcLocator) :
58 Algorithm(name, pSvcLocator)
59{
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 );//For the time being: 5 is the standardvalue -> It yield the highest reconstruction efficiency!
65 declareProperty( "store_trans_time", m_store_trans_time=0);//Usually the root file is not produced!
66}
67
68// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
69
71
72
73
74
75
76 MsgStream log(msgSvc(), name());
77 log << MSG::INFO << "MrpcRecDBS in initialize()" << endreq;
78
79 //Get TOF Geomertry Service
80 StatusCode scg = service("TofGeomSvc", tofGeomSvc);
81 if (scg== StatusCode::SUCCESS) {
82 log << MSG::INFO << "MrpcRecDBS Get Geometry Service Sucessfully!" << endreq;
83 }else {
84 log << MSG::ERROR << "MrpcRecDBS Get Geometry Service Failed !" << endreq;
85 return StatusCode::FAILURE;
86 }
87
88 //Get TOF Calibtration Service
89 StatusCode scc = service("TofCaliSvc", tofCaliSvc);
90 if (scc == StatusCode::SUCCESS) {
91 log << MSG::INFO << "MrpcRecDBS Get Calibration Service Sucessfully!" << endreq;
92 } else {
93 log << MSG::ERROR << "MrpcRecDBS Get Calibration Service Failed !" << endreq;
94 return StatusCode::FAILURE;
95 }
96
97 //Get TOF Raw Data Provider Service
98 StatusCode scd = service("RawDataProviderSvc", tofDigiSvc);
99 if (scd == StatusCode::SUCCESS) {
100 log << MSG::INFO << "MrpcRecDBS Get Tof Raw Data Service Sucessfully!" << endreq;
101 } else {
102 log << MSG::ERROR << "MrpcRecDBS Get Tof Raw Data Service Failed !" << endreq;
103 return StatusCode::FAILURE;
104 }
105
106 if( m_printOutInfo ) { m_printOut = new MrpcDBSCount; }
107
108
109
110
111
112 //Store data of MRPC RECONSTRUCTION
113 if(m_store_trans_time==1)
114 {
115 FileName = "output_mrpc_reconstructed.root";
116 m_TreeFile=new TFile(TString(FileName),"RECREATE","TreeFile");
117 m_tree_mrpc = new TTree("tree_mrpc_rec", ""); //Create Tree
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");
129
130 }
131
132
133
134
135
136
137 return StatusCode::SUCCESS;
138}
139
141 MsgStream log(msgSvc(), name());
142 log << MSG::INFO <<"MrpcRecDBS begin_run!"<< endreq;
143 return StatusCode::SUCCESS;
144}
145
146// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
147
149
150
151
152 MsgStream log(msgSvc(), name());
153 log << MSG::INFO << "MrpcRecDBS in execute()!" << endreq;
154
155 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
156 if( !eventHeader ) {
157 log << MSG::FATAL << "MrpcRecDBS could not find Event Header!" << endreq;
158 return StatusCode::FAILURE;
159 }
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;
164 }
165 log << MSG::INFO << "run= " << run << " event= " << event << endreq;
166
167 MrpcDBSRecTDS tds;
169
170 // Magnetic Field: Colliding data and Cosmic Ray
171 if( m_acceleratorStatus == "Colliding" ) {
172 // Retrieve Event Start Time
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;
177 }
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;
182
183
184
185
186 // Kalman Filter Track
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;
191 }
192
193
194
195 // Tof Get Extrapolated Track
196 SmartDataPtr<RecExtTrackCol> extTrackCol(eventSvc(),"/Event/Recon/RecExtTrackCol");
197 if( !extTrackCol ) {
198 log << MSG::WARNING << "No ExtTrackCol in TDS! Run = " << run << " Event = " << event << endreq;
199 return StatusCode::SUCCESS;
200 }
201 else
202 {
203 if( m_printOutInfo ) { m_printOut->setExtTrackNum( extTrackCol->size() ); }
204 }
205
206
207
208
209 TofTrackVec* tofTrackVec = new TofTrackVec;
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;
215 }
216 int kal[5] = {-1};
217 if( iter_kal != mdcKalTrackCol->end() ) {
218 for( unsigned int i=0; i<5; i++ ) {
219 kal[i] = (*iter_kal)->getStat( 1, i );
220 }
221 }
222 MrpcDBSTrack* tof = new MrpcDBSTrack;
223 tof->setExtTrack( (*iter_track), kal, t0, t0Stat );
224
225 if( tofTrackVec->size()>0 ) {
226 std::vector<MrpcDBSTrack*>::iterator iterExt = tofTrackVec->begin();
227 for( ; iterExt < tofTrackVec->end(); iterExt++ ) {
228 if( (*iterExt)->isNoHit() ) continue;
229 tof->getMultiHit( *iterExt );
230 }
231 }
232
233 tofTrackVec->push_back( tof );
234 }
235
236
237 if( m_printOutInfo )
238 {
239 m_printOut->setTrack1Col( tofTrackVec );
240 }
241
242 // Retrieve Tof Digi Data
243 TofDataMap tofDataMap = tofDigiSvc->tofDataMapTof( t0 );
244 if( tofDataMap.empty() ) {
245 log << MSG::WARNING << "No Tof Data Map in RawDataProviderSvc! Run=" << run << " Event=" << event << endreq;
246 }
247
248
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 );
253 if( m_printOutInfo ) { m_printOut->setTrack2( (*iter) ); }
254 if( (*iter)->isNoHit() ) continue;
255 (*iter)->match(tofTrackVec );
256 if( m_printOutInfo ) { m_printOut->setTrack3( (*iter) ); }
257 }
258
259 iter = tofTrackVec->begin();
260
261 for( ; iter < tofTrackVec->end(); iter++ )
262 {
263 (*iter)->setCalibration();
264 if( m_printOutInfo ) { m_printOut->setTrack4( (*iter) ); }
265
266
267
268
269 //Store MRPC Rootfile! //Variables are set in the Calibration Process!
270 if(m_store_trans_time==1)
271 {
272
273
274 //How was the transmission time calculated
275 m_mrpc_dbs=(*iter)->mrpc_dbs();
276 m_mrpc_extrap=(*iter)->mrpc_extra();
277 m_mrpc_aver=(*iter)->mrpc_aver();
278
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();
284
285 m_r_ext=(*iter)->mrpc_r_ext();
286 m_phi_ext=(*iter)->mrpc_phi_ext();
287
288
289 //Retrieve the simulated transitiontime
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;
294 bool help=false;
295 if(!mcParticleCol) help==true ;
296
297
298
299
300 if (!mcParticleCol)
301 {
302 std::cout << "Could not retrieve McParticelCol" << std::endl;
303 }
304 else
305 {
306
307 Event::TofMcHitCol::iterator iter_mc = mcParticleCol->begin();
308 for (; iter_mc != mcParticleCol->end(); iter_mc++)
309 {
310
311
312
313 mc_truth_x=(*iter_mc)->getPositionX();
314 mc_truth_y=(*iter_mc)->getPositionY();
315 const Identifier ident = (*iter_mc)->identify();
316 int mc_truth_partid=TofID::barrel_ec(ident);
317 int mc_truth_tof_id=TofID::phi_module(ident);
318 int mc_truth_tofmod=BesTofDigitizerEcV4_dbs::Get_module_mrpc_from_unique_identifier(mc_truth_tof_id);
319 int mc_truth_tofstr=BesTofDigitizerEcV4_dbs::Get_stripnumber_from_unique_identifier(mc_truth_tof_id);
320
321 mc_truth_trans_time = BesTofDigitizerEcV4_dbs::GetTransitionTime_extrap_track(mc_truth_x,mc_truth_y,mc_truth_partid,mc_truth_tofmod,mc_truth_tofstr);
322
323
324
325
326
327 if(m_partID==mc_truth_partid && mc_truth_tofmod==((int)m_stripidentifier/25) && ((int)m_stripidentifier%25)==(mc_truth_tofstr))
328 {
329 write_root_data=true;
330 break;
331 }
332
333 }
334
335 }
336 if(mc_truth_trans_time==0) m_transition_time_simulation=-100;
337 else m_transition_time_simulation=mc_truth_trans_time;
338
339 if(write_root_data) m_tree_mrpc->Fill();
340 }
341
342
343
344 }//close for loop
345
346 tds.RegisterTDS(tofTrackVec);
347
348 clearTofTrackVec( tofTrackVec );
349
350// Check RecTofTrackCol Registered
351 SmartDataPtr<RecTofTrackCol> tofTrackCol(eventSvc(),"/Event/Recon/RecTofTrackCol");
352 if (!tofTrackCol) {
353 log << MSG::FATAL << "MrpcRecDBS could not find RecTofTrackCol!" << endreq;
354 return StatusCode::FAILURE;
355 }
356
357
358 }
359 else {
360 log << MSG::FATAL << "In MrpcRecDBS: AcceleratorStatus is NOT correct! m_acceleratorStatus = " << m_acceleratorStatus << endreq;
361 return StatusCode::FAILURE;
362 }
363
364 return StatusCode::SUCCESS;
365
366}
367
368// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
369
371 if( m_printOutInfo ) {
372
373 m_printOut->final();
374 delete m_printOut;
375 }
376
377 //Store data for MRPC
378 if(m_store_trans_time==1)
379 {
380 m_TreeFile->Write();
381 m_TreeFile->Close();
382 }
383
384
385
386 return StatusCode::SUCCESS;
387}
388
389
390//----------------------------------------------------------------------------
391
392void MrpcDBSRec::clearTofTrackVec( std::vector<MrpcDBSTrack*>*& tofTrackVec) {
393 if( tofTrackVec ) {
394 std::vector<MrpcDBSTrack*>::iterator iter = tofTrackVec->begin();
395 for( ; iter < tofTrackVec->end(); iter++ ) {
396 delete (*iter);
397 }
398 tofTrackVec->clear();
399 delete tofTrackVec;
400 }
401 return;
402}
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
std::string help()
Definition: HelloServer.cpp:35
std::vector< MrpcTrack * > TofTrackVec
ITofGeomSvc * tofGeomSvc
Definition: MrpcDBSRec.cxx:51
ITofCaliSvc * tofCaliSvc
Definition: MrpcDBSRec.cxx:52
IRawDataProviderSvc * tofDigiSvc
Definition: MrpcDBSRec.cxx:55
ITofGeomSvc * tofGeomSvc
Definition: MrpcRec.cxx:42
IRawDataProviderSvc * tofDigiSvc
Definition: MrpcRec.cxx:46
ITofCaliSvc * tofCaliSvc
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)
StatusCode initialize()
Definition: MrpcDBSRec.cxx:70
StatusCode beginRun()
Definition: MrpcDBSRec.cxx:140
StatusCode execute()
Definition: MrpcDBSRec.cxx:148
StatusCode finalize()
Definition: MrpcDBSRec.cxx:370
void clearTofTrackVec(std::vector< MrpcDBSTrack * > *&tofTrackVec)
Definition: MrpcDBSRec.cxx:392
MrpcDBSRec(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MrpcDBSRec.cxx:57
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)