BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TofEnergyRec.cxx
Go to the documentation of this file.
1// add bhabha selection code 9/17
2//
3// Package: TofEnergyRec
4// BESIII Tof Energy Reconstruction Algorithm.
5// Created by He Miao (EPC IHEP)
6//
7#include "DstEvent/TofHitStatus.h"
8#include "EvTimeEvent/RecEsTime.h"
9#include "EventModel/EventHeader.h"
10#include "EventModel/EventModel.h"
11#include "ExtEvent/RecExtTrack.h"
12#include "GaudiKernel/IDataProviderSvc.h"
13#include "GaudiKernel/ISvcLocator.h"
14#include "GaudiKernel/MsgStream.h"
15#include "GaudiKernel/PropertyMgr.h"
16#include "GaudiKernel/SmartDataLocator.h"
17#include "GaudiKernel/SmartDataPtr.h"
18#include "McTruth/McParticle.h"
19#include "McTruth/TofMcHit.h"
20#include "RawDataProviderSvc/TofData.h"
21#include "ReconEvent/ReconEvent.h"
22#include "TofCaliSvc/ITofCaliSvc.h"
23#include "TofGeomSvc/ITofGeomSvc.h"
24#include "TofRecEvent/RecBTofCalHit.h"
25#include "TofRecEvent/RecBTofHit.h"
26#include "TofRecEvent/RecETofCalHit.h"
27#include "TofRecEvent/RecETofHit.h"
28#include "TofRecEvent/RecTofTrack.h"
29
30#include "RawDataProviderSvc/IRawDataProviderSvc.h"
31#include "TofEnergyRec.h"
32#include "TofShower.h"
33#include <iostream>
34
35using namespace std;
36using namespace Event;
37
38/////////////////////////////////////////////////////////////////////////////
39
42TofEnergyRec::TofEnergyRec( const std::string& name, ISvcLocator* pSvcLocator )
43 : Algorithm( name, pSvcLocator ) {
44 declareProperty( "Output", m_output = false );
45 declareProperty( "EventNb", m_eventNb = 0 );
46 declareProperty( "CalibConst", m_calibConst = 0.0085 );
47 declareProperty( "IsData", m_isData = true );
48}
49
50// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
51
53
54 MsgStream log( msgSvc(), name() );
55 log << MSG::INFO << "TofEnergyRec in initialize()" << endmsg;
56
57 m_event = 0;
58 m_tofShower = new TofShower;
59 m_tofShower->setCalibConst( m_calibConst );
60 m_tofShower->setIsData( m_isData );
61 // m_tofShower->readCalibPar();
62
63 if ( m_output )
64 {
65 cout << "--------Book Tof Energy Ntuple!" << endl;
66 NTuplePtr nt( ntupleSvc(), "FILE209/sci" );
67 NTuplePtr nt1( ntupleSvc(), "FILE209/shower" );
68 NTuplePtr nt2( ntupleSvc(), "FILE209/seed" );
69 if ( nt && nt1 && nt2 )
70 {
71 m_tuple = nt;
72 m_tuple1 = nt1;
73 m_tuple2 = nt2;
74 }
75 else
76 {
77 m_tuple = ntupleSvc()->book( "FILE209/sci", CLID_ColumnWiseTuple, "TofEnergyRec" );
78 m_tuple1 = ntupleSvc()->book( "FILE209/shower", CLID_ColumnWiseTuple, "TofEnergyRec" );
79 m_tuple2 = ntupleSvc()->book( "FILE209/seed", CLID_ColumnWiseTuple, "TofEnergyRec" );
80 if ( m_tuple && m_tuple1 && m_tuple2 )
81 { m_tofShower->BookNtuple( m_tuple, m_tuple1, m_tuple2 ); }
82 else
83 {
84 log << MSG::ERROR << " ----- TofShower cannot book N-tuple:" << long( m_tuple )
85 << endmsg;
86 }
87 }
88 }
89
90 return StatusCode::SUCCESS;
91}
92
93// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
94
96
97 MsgStream log( msgSvc(), name() );
98 log << MSG::INFO << "TofEnergyRec in execute()!!" << endmsg;
99
100 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
101 if ( !eventHeader )
102 {
103 log << MSG::FATAL << "TofEnergyRec could not find Event Header!" << endmsg;
104 return StatusCode::FAILURE;
105 }
106 int run = eventHeader->runNumber();
107 int event = eventHeader->eventNumber();
108 if ( m_eventNb != 0 && m_event % m_eventNb == 0 )
109 std::cout << "--------event: " << m_event << ", run= " << run << " event= " << event
110 << std::endl;
111 log << MSG::INFO << "run= " << run << " event= " << event << endmsg;
112 m_event++;
113
115 StatusCode sc = service( "RawDataProviderSvc", tofDigiSvc );
116 if ( sc != StatusCode::SUCCESS )
117 {
118 log << MSG::FATAL << "TofEnergyRec could not find RawDataProviderSvc!" << endmsg;
119 return StatusCode::SUCCESS;
120 }
121
122 // check whether the Recon has been already registered
123 DataObject* aReconEvent;
124 eventSvc()->findObject( "/Event/Recon", aReconEvent );
125 if ( aReconEvent == NULL )
126 {
127 log << MSG::INFO << "Register ReconEvent" << endmsg;
128 // then register Recon
129 aReconEvent = new ReconEvent();
130 sc = eventSvc()->registerObject( "/Event/Recon", aReconEvent );
131 if ( sc != StatusCode::SUCCESS )
132 {
133 log << MSG::FATAL << "Could not register ReconEvent" << endmsg;
134 return StatusCode::FAILURE;
135 }
136 }
137
138 // Register RecTofTrackCol
139 SmartDataPtr<RecTofTrackCol> tofTrackCol( eventSvc(), EventModel::Recon::RecTofTrackCol );
140 if ( !tofTrackCol )
141 {
142 log << MSG::INFO << "Register RecTofTrackCol!" << endmsg;
143 tofTrackCol = new RecTofTrackCol;
144 sc = eventSvc()->registerObject( EventModel::Recon::RecTofTrackCol, tofTrackCol );
145 if ( sc != StatusCode::SUCCESS )
146 { log << MSG::FATAL << "Could not register RecTofTrackCol!" << endmsg; }
147 }
148
149 // Retrieve RecEsTimeCol
150 SmartDataPtr<RecEsTimeCol> estimeCol( eventSvc(), "/Event/Recon/RecEsTimeCol" );
151 if ( !estimeCol || ( estimeCol->size() == 0 ) )
152 {
153 log << MSG::WARNING << "TofRec Could not find RecEsTimeCol! Run = " << run
154 << " Event = " << event << endmsg;
155 return StatusCode::SUCCESS;
156 }
157 RecEsTimeCol::iterator iter_ESTime = estimeCol->begin();
158
159 double t0 = 0;
160 t0 = ( *iter_ESTime )->getTest();
161 int t0Stat = ( *iter_ESTime )->getStat();
162
163 std::vector<TofData*> tofDataVec;
164 tofDataVec = tofDigiSvc->tofDataVectorTof();
165
166 m_tofShower->findShower( tofDataVec, tofTrackCol, t0 );
167
168 return StatusCode::SUCCESS;
169}
170
171// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
172
174 cout << "Total event:" << m_event << endl;
175 delete m_tofShower;
176 return StatusCode::SUCCESS;
177}
DECLARE_COMPONENT(BesBdkRc)
INTupleSvc * ntupleSvc()
IMessageSvc * msgSvc()
IRawDataProviderSvc * tofDigiSvc
StatusCode finalize()
TofEnergyRec(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initialize()
StatusCode execute()
void setCalibConst(const double cal)
Definition TofShower.h:38