BOSS 7.1.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 "GaudiKernel/MsgStream.h"
8#include "GaudiKernel/AlgFactory.h"
9#include "GaudiKernel/ISvcLocator.h"
10#include "GaudiKernel/SmartDataPtr.h"
11#include "GaudiKernel/SmartDataLocator.h"
12#include "GaudiKernel/IDataProviderSvc.h"
13#include "GaudiKernel/PropertyMgr.h"
17#include "McTruth/McParticle.h"
18#include "McTruth/TofMcHit.h"
31
35#include <iostream>
36
37
38using namespace std;
39using namespace Event;
40
41/////////////////////////////////////////////////////////////////////////////
42
44DECLARE_COMPONENT(TofEnergyRec)
45TofEnergyRec::TofEnergyRec(const std::string& name, ISvcLocator* pSvcLocator) :
46 Algorithm(name, pSvcLocator)
47{
48 declareProperty("Output", m_output = false);
49 declareProperty("EventNb", m_eventNb = 0);
50 declareProperty("CalibConst", m_calibConst = 0.0085);
51 declareProperty("IsData", m_isData = true);
52}
53
54// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
55
57
58 MsgStream log(msgSvc(), name());
59 log << MSG::INFO << "TofEnergyRec in initialize()" << endreq;
60
61 m_event = 0;
62 m_tofShower = new TofShower;
63 m_tofShower->setCalibConst(m_calibConst);
64 m_tofShower->setIsData(m_isData);
65 //m_tofShower->readCalibPar();
66
67 if(m_output) {
68 cout<<"--------Book Tof Energy Ntuple!"<<endl;
69 NTuplePtr nt(ntupleSvc(), "FILE209/sci");
70 NTuplePtr nt1(ntupleSvc(), "FILE209/shower");
71 NTuplePtr nt2(ntupleSvc(), "FILE209/seed");
72 if ( nt&&nt1&&nt2 ) {
73 m_tuple = nt;
74 m_tuple1 = nt1;
75 m_tuple2 = nt2;
76 } else {
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 }
83 else {
84 log << MSG::ERROR << " ----- TofShower cannot book N-tuple:" << long(m_tuple) << endmsg;
85 }
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()!!" << endreq;
99
100 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
101 if( !eventHeader ) {
102 log << MSG::FATAL << "TofEnergyRec could not find Event Header!" << endreq;
103 return StatusCode::FAILURE;
104 }
105 int run = eventHeader->runNumber();
106 int event = eventHeader->eventNumber();
107 if( m_eventNb!=0 && m_event%m_eventNb== 0 ) std::cout << "--------event: " << m_event
108 << ", run= " << run << " event= " << event << std::endl;
109 log << MSG::INFO << "run= " << run << " event= " << event << endreq;
110 m_event++;
111
112
114 StatusCode sc = service("RawDataProviderSvc", tofDigiSvc);
115 if(sc != StatusCode::SUCCESS) {
116 log << MSG::FATAL << "TofEnergyRec could not find RawDataProviderSvc!" << endreq;
117 return StatusCode::SUCCESS;
118 }
119
120 //check whether the Recon has been already registered
121 DataObject *aReconEvent;
122 eventSvc()->findObject("/Event/Recon",aReconEvent);
123 if(aReconEvent==NULL) {
124 log << MSG::INFO << "Register ReconEvent" << endreq;
125 //then register Recon
126 aReconEvent = new ReconEvent();
127 sc = eventSvc()->registerObject("/Event/Recon",aReconEvent);
128 if(sc!=StatusCode::SUCCESS) {
129 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
130 return StatusCode::FAILURE;
131 }
132 }
133
134 //Register RecTofTrackCol
135 SmartDataPtr<RecTofTrackCol> tofTrackCol(eventSvc(),EventModel::Recon::RecTofTrackCol);
136 if (!tofTrackCol) {
137 log << MSG::INFO << "Register RecTofTrackCol!" << endreq;
138 tofTrackCol = new RecTofTrackCol;
139 sc = eventSvc()->registerObject(EventModel::Recon::RecTofTrackCol, tofTrackCol);
140 if(sc!=StatusCode::SUCCESS) {
141 log << MSG::FATAL << "Could not register RecTofTrackCol!" <<endreq;
142 }
143 }
144
145
146
147 //Retrieve RecEsTimeCol
148 SmartDataPtr<RecEsTimeCol> estimeCol(eventSvc(),"/Event/Recon/RecEsTimeCol");
149 if( !estimeCol || ( estimeCol->size() == 0 ) ) {
150 log << MSG::WARNING << "TofRec Could not find RecEsTimeCol! Run = " << run << " Event = " << event << endreq;
151 return StatusCode::SUCCESS;
152 }
153 RecEsTimeCol::iterator iter_ESTime=estimeCol->begin();
154 double t0=0;
155 t0 = (*iter_ESTime)->getTest();
156 int t0Stat = (*iter_ESTime)->getStat();
157
158
159 std::vector<TofData*> tofDataVec;
160 tofDataVec = tofDigiSvc->tofDataVectorTof();
161
162
163 m_tofShower->findShower(tofDataVec, tofTrackCol, t0);
164
165 return StatusCode::SUCCESS;
166
167}
168
169// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
170
172 cout << "Total event:" << m_event << endl;
173 delete m_tofShower;
174 return StatusCode::SUCCESS;
175}
ObjectVector< RecTofTrack > RecTofTrackCol
Definition: RecTofTrack.h:33
INTupleSvc * ntupleSvc()
IMessageSvc * msgSvc()
IRawDataProviderSvc * tofDigiSvc
#define NULL
virtual TofDataVector & tofDataVectorTof(double estime=0)=0
StatusCode finalize()
StatusCode initialize()
StatusCode execute()
void setCalibConst(const double cal)
Definition: TofShower.h:39
void BookNtuple(NTuple::Tuple *&tuple, NTuple::Tuple *&tuple1, NTuple::Tuple *&tuple2)
Definition: TofShower.cxx:39
void setIsData(const bool isData)
Definition: TofShower.h:42
void findShower(vector< TofData * > &tofDataVec, RecTofTrackCol *recTofTrackCol, double)
Definition: TofShower.cxx:540
_EXTERN_ std::string RecTofTrackCol
Definition: EventModel.h:97
Definition: Event.h:21