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;
53 Algorithm(name, pSvcLocator) {
56 declareProperty(
"hist", m_hist=
false);
57 declareProperty(
"Trigger", m_trigger_flag=
true);
58 declareProperty(
"Hlt", m_hlt_flag=
true);
59 declareProperty(
"Estime", m_est_flag=
true);
61 declareProperty(
"KalTrk", m_kalTrk_flag=
true);
63 declareProperty(
"EneCut", m_energy_cut=1.2);
64 declareProperty(
"MomCut", m_mom_cut=0.04);
65 declareProperty(
"DangCut", m_dangCut= 2.5);
67 declareProperty(
"Vr0cut", m_vr0cut=1.0);
68 declareProperty(
"Vz0cut", m_vz0cut=5.0);
73 MsgStream log(
msgSvc(), name());
74 log << MSG::INFO <<
"in initialize()" << endmsg;
79 NTuplePtr nt1(
ntupleSvc(),
"FILEBbEmc/bbEmc");
80 if ( nt1 ) m_tuple1 = nt1;
82 m_tuple1 =
ntupleSvc()->book (
"FILEBbEmc/bbEmc", CLID_ColumnWiseTuple,
"BbEmc N-Tuple example");
84 status = m_tuple1->addItem (
"run", m_run);
85 status = m_tuple1->addItem (
"event", m_event);
86 status = m_tuple1->addItem (
"numCtrk", m_num_Ctrk);
87 status = m_tuple1->addItem (
"numNtrk", m_num_Ntrk);
88 status = m_tuple1->addItem (
"numGtrk", m_num_Gtrk);
90 status = m_tuple1->addItem (
"trigindex", m_trig_index, 0, 48);
91 status = m_tuple1->addIndexedItem(
"trigcond", m_trig_index, m_trig_cond);
92 status = m_tuple1->addIndexedItem(
"trigchan", m_trig_index, m_trig_chan);
93 status = m_tuple1->addItem (
"timewindow", m_trig_timewindow);
94 status = m_tuple1->addItem (
"timetype", m_trig_timetype);
95 status = m_tuple1->addItem (
"hlttype", m_hlt_type );
97 status = m_tuple1->addItem (
"estime", m_est_start);
98 status = m_tuple1->addItem (
"status", m_est_status);
99 status = m_tuple1->addItem (
"quality", m_est_quality);
101 status = m_tuple1->addItem (
"dang", m_dang);
102 status = m_tuple1->addItem (
"index", m_index,0,2);
103 status = m_tuple1->addIndexedItem (
"theta", m_index, m_theta);
104 status = m_tuple1->addIndexedItem (
"phi", m_index, m_phi);
105 status = m_tuple1->addIndexedItem (
"ene", m_index, m_ene);
107 log << MSG::ERROR <<
"Cannot book N-tuple theone"<<endmsg;
108 return StatusCode::FAILURE;
112 log << MSG::INFO <<
"end initialize()" << endmsg;
116 return StatusCode::SUCCESS;
123 MsgStream log(
msgSvc(),name());
124 log<<MSG::INFO<<
"in execute()"<<endreq;
128 setFilterPassed(
false);
130 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
131 int runNum= eventHeader->runNumber();
132 int eventNum= eventHeader->eventNumber();
133 if(m_cout_all %1000 ==0) {
134 std::cout<<name()<<
"::"<< m_cout_all <<
" events executed"<<std::endl;
137 SmartDataPtr<EvtRecEvent> evtRecEvent(eventSvc(),
"/Event/EvtRec/EvtRecEvent");
138 log << MSG::DEBUG <<
"ncharg, nneu, tottks = "
139 << evtRecEvent->totalCharged() <<
" , "
140 << evtRecEvent->totalNeutral() <<
" , "
141 << evtRecEvent->totalTracks() <<endreq;
143 SmartDataPtr<EvtRecTrackCol> evtRecTrkCol(eventSvc(),
"/Event/EvtRec/EvtRecTrackCol");
144 if((evtRecEvent->totalTracks()<2) || (evtRecEvent->totalTracks()>30)){
145 return StatusCode::SUCCESS;
152 SmartDataPtr<HltInf> hlt(eventSvc(),
"/Event/Hlt/HltInf");
155 log << MSG::WARNING <<
"Could not find Event HltInf, try DstHltInf now" << endreq;
156 SmartDataPtr<DstHltInf> hltDst(eventSvc(),
"/Event/Hlt/DstHltInf");
158 log << MSG::ERROR <<
"Could not find Event DstHltInf too, please re-generate data" << endreq;
159 return StatusCode::FAILURE;
168 for(
int i=0; i<32; i++){
169 if(temp_type & mask){
178 SmartDataPtr<TrigData> trigData(eventSvc(),
"/Event/Trig/TrigData");
179 if(m_trigger_flag & runNum>0){
181 log << MSG::FATAL <<
"Could not find TrigData in TDS" << endreq;
182 return StatusCode::FAILURE;
185 log << MSG::DEBUG <<
"Trigger conditions: " << endreq;
186 for(
int trig_id=0; trig_id < 48; trig_id++){
187 log << MSG::DEBUG <<
"i:" << trig_id
188 <<
" name:" << trigData->getTrigCondName(trig_id)
189 <<
" cond:" << trigData->getTrigCondition(trig_id) << endreq;
194 SmartDataPtr<RecEsTimeCol> recEstimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
195 if(m_est_flag & runNum>0){
197 log << MSG::WARNING <<
"Can not get RecEsTimeCol" << endreq;
198 return StatusCode::SUCCESS;
200 log << MSG::DEBUG <<
"size of EsTime: " << recEstimeCol->size() << endreq;
205 HepLorentzVector m_lv_ele;
206 for(
int i=0; i<evtRecEvent->totalTracks(); i++){
207 if(i>=evtRecTrkCol->size())
break;
210 if(!(*itTrk)->isEmcShowerValid())
continue;
213 if(emcTrk->
energy()<m_energy_cut)
continue;
215 Hep3Vector emcpos(emcTrk->
x(), emcTrk->
y(), emcTrk->
z());
216 m_lv_ele.setVect(emcpos);
217 m_lv_ele.setE(emcTrk->
energy());
218 vGood.push_back(m_lv_ele);
222 if(vGood.size() - 2)
return SUCCESS;
226 double dang = vGood[0].vect().angle(vGood[1].vect());
227 if(dang < m_dangCut)
return SUCCESS;
230 if(vGood[0].e() > vGood[1].e()) swap(vGood[0],vGood[1]);
234 double d0,z0,cosTheta,phi,mom;
235 Vint iGood; iGood.clear();
236 for(
int i = 0; i < evtRecEvent->totalCharged(); i++){
240 itTrk=evtRecTrkCol->begin() + i;
241 if(!(*itTrk)->isMdcKalTrackValid())
continue;
246 if(!(*itTrk)->isMdcTrackValid())
continue;
251 if(fabs(m_vz) >= m_vz0cut)
continue;
252 if(m_vr >= m_vr0cut)
continue;
260 m_num_Ctrk = evtRecEvent->totalCharged();
261 m_num_Ntrk = evtRecEvent->totalNeutral();
262 m_num_Gtrk = iGood.size();
264 for(
int trig_id=0; trig_id < 48; trig_id++){
265 m_trig_index = trig_id;
267 m_trig_chan[m_trig_index] = trigData->getTrigChannel(m_trig_index);
269 m_trig_cond[m_trig_index] = trigData->getTrigCondition(m_trig_index);
271 m_trig_timewindow = trigData->getTimeWindow();
272 m_trig_timetype = trigData->getTimingType();
275 m_hlt_type = hlt_type;
278 m_est_start = (*(recEstimeCol->begin()))->getTest();
279 m_est_status = (*(recEstimeCol->begin()))->getStat();
280 m_est_quality = (*(recEstimeCol->begin()))->getQuality();
284 for(
int i=0; i<2; i++){
286 m_theta[m_index] = vGood[m_index].vect().theta();
287 m_phi[m_index] = vGood[m_index].vect().phi();
288 m_ene[m_index] = vGood[m_index].e();
294 setFilterPassed(
true);
296 return StatusCode::SUCCESS;
300 MsgStream log(
msgSvc(),name());
301 log<<MSG::INFO<<
"in finalize()"<<endreq;
303 std::cout <<name()<<
" total event: "<< m_cout_all << std::endl;
304 std::cout <<name()<<
" total tracks >= 2, <= 30: "<<
m_cout_tracks << std::endl;
305 std::cout <<name()<<
" good showers = 2: "<<
m_cout_good << std::endl;
306 std::cout <<name()<<
" angle between two showers: "<<
m_cout_dang << std::endl;
308 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
BbEmc(const std::string &name, ISvcLocator *pSvcLocator)
uint32_t getEventType() const