1#include "GaudiKernel/MsgStream.h"
2#include "GaudiKernel/AlgFactory.h"
3#include "GaudiKernel/ISvcLocator.h"
4#include "GaudiKernel/SmartDataPtr.h"
5#include "GaudiKernel/IDataProviderSvc.h"
6#include "GaudiKernel/PropertyMgr.h"
21#include "GaudiKernel/INTupleSvc.h"
22#include "GaudiKernel/NTuple.h"
23#include "GaudiKernel/Bootstrap.h"
24#include "GaudiKernel/IHistogramSvc.h"
25#include "CLHEP/Vector/ThreeVector.h"
26using CLHEP::Hep3Vector;
27#include "CLHEP/Vector/LorentzVector.h"
28using CLHEP::HepLorentzVector;
29#include "CLHEP/Vector/TwoVector.h"
30using CLHEP::Hep2Vector;
31#include "CLHEP/Geometry/Point3D.h"
32#ifndef ENABLE_BACKWARDS_COMPATIBILITY
44typedef std::vector<int>
Vint;
45typedef std::vector<HepLorentzVector>
Vp4;
46const double velc = 299.792458;
47const double xmass[5] = {0.000511, 0.105658, 0.139570, 0.493677, 0.938272};
48const double pai=3.1415926;
52DECLARE_COMPONENT(
BbEmc)
54 Algorithm(name, pSvcLocator) {
57 declareProperty(
"hist", m_hist=
false);
58 declareProperty(
"Trigger", m_trigger_flag=
true);
59 declareProperty(
"Hlt", m_hlt_flag=
true);
60 declareProperty(
"Estime", m_est_flag=
true);
62 declareProperty(
"KalTrk", m_kalTrk_flag=
true);
64 declareProperty(
"EneCut", m_energy_cut=1.2);
65 declareProperty(
"MomCut", m_mom_cut=0.04);
66 declareProperty(
"DangCut", m_dangCut= 2.5);
68 declareProperty(
"Vr0cut", m_vr0cut=1.0);
69 declareProperty(
"Vz0cut", m_vz0cut=5.0);
74 MsgStream log(
msgSvc(), name());
75 log << MSG::INFO <<
"in initialize()" << endmsg;
80 NTuplePtr nt1(
ntupleSvc(),
"FILEBbEmc/bbEmc");
81 if ( nt1 ) m_tuple1 = nt1;
83 m_tuple1 =
ntupleSvc()->book (
"FILEBbEmc/bbEmc", CLID_ColumnWiseTuple,
"BbEmc N-Tuple example");
85 status = m_tuple1->addItem (
"run", m_run);
86 status = m_tuple1->addItem (
"event", m_event);
87 status = m_tuple1->addItem (
"numCtrk", m_num_Ctrk);
88 status = m_tuple1->addItem (
"numNtrk", m_num_Ntrk);
89 status = m_tuple1->addItem (
"numGtrk", m_num_Gtrk);
91 status = m_tuple1->addItem (
"trigindex", m_trig_index, 0, 48);
92 status = m_tuple1->addIndexedItem(
"trigcond", m_trig_index, m_trig_cond);
93 status = m_tuple1->addIndexedItem(
"trigchan", m_trig_index, m_trig_chan);
94 status = m_tuple1->addItem (
"timewindow", m_trig_timewindow);
95 status = m_tuple1->addItem (
"timetype", m_trig_timetype);
96 status = m_tuple1->addItem (
"hlttype", m_hlt_type );
98 status = m_tuple1->addItem (
"estime", m_est_start);
99 status = m_tuple1->addItem (
"status", m_est_status);
100 status = m_tuple1->addItem (
"quality", m_est_quality);
102 status = m_tuple1->addItem (
"dang", m_dang);
103 status = m_tuple1->addItem (
"index", m_index,0,2);
104 status = m_tuple1->addIndexedItem (
"theta", m_index, m_theta);
105 status = m_tuple1->addIndexedItem (
"phi", m_index, m_phi);
106 status = m_tuple1->addIndexedItem (
"ene", m_index, m_ene);
108 log << MSG::ERROR <<
"Cannot book N-tuple theone"<<endmsg;
109 return StatusCode::FAILURE;
113 log << MSG::INFO <<
"end initialize()" << endmsg;
117 return StatusCode::SUCCESS;
124 MsgStream log(
msgSvc(),name());
125 log<<MSG::INFO<<
"in execute()"<<endreq;
129 setFilterPassed(
false);
131 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
132 int runNum= eventHeader->runNumber();
133 int eventNum= eventHeader->eventNumber();
134 if(m_cout_all %1000 ==0) {
135 std::cout<<name()<<
"::"<< m_cout_all <<
" events executed"<<std::endl;
138 SmartDataPtr<EvtRecEvent> evtRecEvent(eventSvc(),
"/Event/EvtRec/EvtRecEvent");
139 log << MSG::DEBUG <<
"ncharg, nneu, tottks = "
140 << evtRecEvent->totalCharged() <<
" , "
141 << evtRecEvent->totalNeutral() <<
" , "
142 << evtRecEvent->totalTracks() <<endreq;
144 SmartDataPtr<EvtRecTrackCol> evtRecTrkCol(eventSvc(),
"/Event/EvtRec/EvtRecTrackCol");
145 if((evtRecEvent->totalTracks()<2) || (evtRecEvent->totalTracks()>30)){
146 return StatusCode::SUCCESS;
153 SmartDataPtr<HltInf> hlt(eventSvc(),
"/Event/Hlt/HltInf");
156 log << MSG::WARNING <<
"Could not find Event HltInf, try DstHltInf now" << endreq;
157 SmartDataPtr<DstHltInf> hltDst(eventSvc(),
"/Event/Hlt/DstHltInf");
159 log << MSG::ERROR <<
"Could not find Event DstHltInf too, please re-generate data" << endreq;
160 return StatusCode::FAILURE;
169 for(
int i=0; i<32; i++){
170 if(temp_type & mask){
179 SmartDataPtr<TrigData> trigData(eventSvc(),
"/Event/Trig/TrigData");
180 if(m_trigger_flag & runNum>0){
182 log << MSG::FATAL <<
"Could not find TrigData in TDS" << endreq;
183 return StatusCode::FAILURE;
186 log << MSG::DEBUG <<
"Trigger conditions: " << endreq;
187 for(
int trig_id=0; trig_id < 48; trig_id++){
188 log << MSG::DEBUG <<
"i:" << trig_id
189 <<
" name:" << trigData->getTrigCondName(trig_id)
190 <<
" cond:" << trigData->getTrigCondition(trig_id) << endreq;
195 SmartDataPtr<RecEsTimeCol> recEstimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
196 if(m_est_flag & runNum>0){
198 log << MSG::WARNING <<
"Can not get RecEsTimeCol" << endreq;
199 return StatusCode::SUCCESS;
201 log << MSG::DEBUG <<
"size of EsTime: " << recEstimeCol->size() << endreq;
206 HepLorentzVector m_lv_ele;
207 for(
int i=0; i<evtRecEvent->totalTracks(); i++){
208 if(i>=evtRecTrkCol->size())
break;
211 if(!(*itTrk)->isEmcShowerValid())
continue;
214 if(emcTrk->
energy()<m_energy_cut)
continue;
216 Hep3Vector emcpos(emcTrk->
x(), emcTrk->
y(), emcTrk->
z());
217 m_lv_ele.setVect(emcpos);
218 m_lv_ele.setE(emcTrk->
energy());
219 vGood.push_back(m_lv_ele);
223 if(vGood.size() - 2)
return SUCCESS;
227 double dang = vGood[0].vect().angle(vGood[1].vect());
228 if(dang < m_dangCut)
return SUCCESS;
231 if(vGood[0].e() > vGood[1].e()) swap(vGood[0],vGood[1]);
235 double d0,z0,cosTheta,phi,mom;
236 Vint iGood; iGood.clear();
237 for(
int i = 0; i < evtRecEvent->totalCharged(); i++){
241 itTrk=evtRecTrkCol->begin() + i;
242 if(!(*itTrk)->isMdcKalTrackValid())
continue;
247 if(!(*itTrk)->isMdcTrackValid())
continue;
252 if(fabs(m_vz) >= m_vz0cut)
continue;
253 if(m_vr >= m_vr0cut)
continue;
261 m_num_Ctrk = evtRecEvent->totalCharged();
262 m_num_Ntrk = evtRecEvent->totalNeutral();
263 m_num_Gtrk = iGood.size();
265 for(
int trig_id=0; trig_id < 48; trig_id++){
266 m_trig_index = trig_id;
268 m_trig_chan[m_trig_index] = trigData->getTrigChannel(m_trig_index);
270 m_trig_cond[m_trig_index] = trigData->getTrigCondition(m_trig_index);
272 m_trig_timewindow = trigData->getTimeWindow();
273 m_trig_timetype = trigData->getTimingType();
276 m_hlt_type = hlt_type;
279 m_est_start = (*(recEstimeCol->begin()))->getTest();
280 m_est_status = (*(recEstimeCol->begin()))->getStat();
281 m_est_quality = (*(recEstimeCol->begin()))->getQuality();
285 for(
int i=0; i<2; i++){
287 m_theta[m_index] = vGood[m_index].vect().theta();
288 m_phi[m_index] = vGood[m_index].vect().phi();
289 m_ene[m_index] = vGood[m_index].e();
295 setFilterPassed(
true);
297 return StatusCode::SUCCESS;
301 MsgStream log(
msgSvc(),name());
302 log<<MSG::INFO<<
"in finalize()"<<endreq;
304 std::cout <<name()<<
" total event: "<< m_cout_all << std::endl;
305 std::cout <<name()<<
" total tracks >= 2, <= 30: "<<
m_cout_tracks << std::endl;
306 std::cout <<name()<<
" good showers = 2: "<<
m_cout_good << std::endl;
307 std::cout <<name()<<
" angle between two showers: "<<
m_cout_dang << std::endl;
309 return StatusCode::SUCCESS;
HepGeom::Point3D< double > HepPoint3D
std::vector< HepLorentzVector > Vp4
static long m_cout_good(0)
static long m_cout_tracks(0)
static long m_cout_dang(0)
EvtRecTrackCol::iterator EvtRecTrackIterator
std::vector< HepLorentzVector > Vp4
uint32_t getEventType() const