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"
8#include "EventModel/EventModel.h"
9#include "EventModel/Event.h"
10#include "EventModel/EventHeader.h"
11#include "EvtRecEvent/EvtRecEvent.h"
12#include "EvtRecEvent/EvtRecTrack.h"
15#include "GaudiKernel/INTupleSvc.h"
16#include "GaudiKernel/NTuple.h"
17#include "GaudiKernel/Bootstrap.h"
18#include "GaudiKernel/IHistogramSvc.h"
19#include "CLHEP/Vector/ThreeVector.h"
20#include "CLHEP/Vector/LorentzVector.h"
21#include "CLHEP/Vector/TwoVector.h"
22#include "MdcRawEvent/MdcDigi.h"
23using CLHEP::Hep3Vector;
24using CLHEP::Hep2Vector;
25using CLHEP::HepLorentzVector;
26#include "CLHEP/Geometry/Point3D.h"
27#ifndef ENABLE_BACKWARDS_COMPATIBILITY
30#include "BhabhaPreSelect/BhabhaPreSelect.h"
31#include "BhabhaPreSelect/BhabhaType.h"
36typedef std::vector<int>
Vint;
37typedef std::vector<HepLorentzVector>
Vp4;
38const double PI = 3.1415927;
40int BhabhaPreSelect::idmax[43]={40,44,48,56,64,72,80,80,76,76,
41 88,88,100,100,112,112,128,128,140,140,
42 160,160,160,160,176,176,176,176,208,208,
43 208,208,240,240,240,240,256,256,256,256,
49 Algorithm(name, pSvcLocator) {
53 declareProperty (
"BarrelOrEndcap", m_BarrelOrEndcap = 1);
54 declareProperty (
"Output", m_output =
false);
61 MsgStream log(
msgSvc(), name());
63 log << MSG::INFO <<
"in initialize()" << endmsg;
64 cout<<
" BarrelOrEndcap "<<m_BarrelOrEndcap<<endl;
68 NTuplePtr nt1(
ntupleSvc(),
"FILE1/bhabha");
69 if ( nt1 ) m_tuple1 = nt1;
71 m_tuple1 =
ntupleSvc()->book (
"FILE1/bhabha", CLID_ColumnWiseTuple,
"N-Tuple example");
73 status = m_tuple1->addItem (
"sh1_ene",m_sh1_ene);
74 status = m_tuple1->addItem (
"sh1_theta", m_sh1_theta);
75 status = m_tuple1->addItem (
"sh1_phi", m_sh1_phi);
76 status = m_tuple1->addItem (
"sh2_ene",m_sh2_ene);
77 status = m_tuple1->addItem (
"sh2_theta", m_sh2_theta);
78 status = m_tuple1->addItem (
"sh2_phi", m_sh2_phi);
79 status = m_tuple1->addItem (
"di_phi", m_di_phi);
80 status = m_tuple1->addItem (
"di_the", m_di_the);
81 status = m_tuple1->addItem (
"acolli", m_acolli);
82 status = m_tuple1->addItem (
"etot", m_etot);
83 status = m_tuple1->addItem (
"mdc_hit1", m_mdc_hit1);
84 status = m_tuple1->addItem (
"mdc_hit2", m_mdc_hit2);
88 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(m_tuple1) << endmsg;
89 return StatusCode::FAILURE;
95 if ( nt2 ) m_tuple2 = nt2;
97 m_tuple2 =
ntupleSvc()->book (
"FILE1/bha1", CLID_ColumnWiseTuple,
"N-Tuple example");
99 status = m_tuple2->addItem (
"sh_ene",m_sh_ene);
100 status = m_tuple2->addItem (
"sh_theta", m_sh_theta);
101 status = m_tuple2->addItem (
"sh_phi", m_sh_phi);
104 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(m_tuple2) << endmsg;
105 return StatusCode::FAILURE;
117 m_oneProngsSelected=0;
118 m_twoProngsMatchedSelected=0;
119 m_twoProngsOneMatchedSelected=0;
120 m_selectedTrkID1=999;
121 m_selectedTrkID2=999;
123 log << MSG::INFO <<
"successfully return from initialize()" <<endmsg;
124 return StatusCode::SUCCESS;
131 MsgStream log(
msgSvc(), name());
132 log << MSG::INFO <<
"in execute()" << endreq;
134 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
141 int run=eventHeader->runNumber();
142 int event=eventHeader->eventNumber();
144 if(event%1000==0) cout<<
" run,event: "<<run<<
","<<
event<<endl;
148 cout<<
" evtRecEvent "<<endl;
149 return StatusCode::FAILURE;
152 log << MSG::DEBUG <<
"ncharg, nneu, tottks = "
153 << evtRecEvent->totalCharged() <<
" , "
154 << evtRecEvent->totalNeutral() <<
" , "
155 << evtRecEvent->totalTracks() <<endreq;
158 cout<<
" evtRecTrkCol "<<endl;
159 return StatusCode::FAILURE;
163 setFilterPassed(
false);
168 double ene5x5,theta,phi,eseed;
169 double showerX,showerY,showerZ;
170 long int thetaIndex,phiIndex;
182 vector<RecEmcShower* > GoodShowers;
185 for(
int i = 0; i< evtRecEvent->totalTracks(); i++) {
186 if(i>=evtRecTrkCol->size())
break;
188 if((*itTrk)->isEmcShowerValid()) {
193 ene5x5=theShower->
e5x5();
196 if (ene5x5>0.4&&ene5x5<4&&npart==1&&(m_BarrelOrEndcap==1)){
197 GoodShowers.push_back(theShower);
198 iGood.push_back((*itTrk)->trackId());
200 else if (ene5x5>0.4&&ene5x5<4&&(npart==2||npart==0)&&(m_BarrelOrEndcap==2)){
201 GoodShowers.push_back(theShower);
202 iGood.push_back((*itTrk)->trackId());
204 else if (ene5x5>0.4&&ene5x5<4&&(m_BarrelOrEndcap==0)){
205 GoodShowers.push_back(theShower);
206 iGood.push_back((*itTrk)->trackId());
214 double MaxE(0), MaxPhi, MaxThe;
216 double SecE(0), SecPhi, SecThe;
217 for(
int i=0; i<GoodShowers.size(); i++) {
219 double eraw = theShower->
energy();
223 MaxPhi = theShower->
phi();
224 MaxThe = theShower->
theta();
227 for(
int i=0; i<GoodShowers.size(); i++) {
229 double eraw = theShower->
energy();
230 if(i!=MaxId&&eraw>SecE) {
232 SecPhi = theShower->
phi();
233 SecThe = theShower->
theta();
237 double dphi = (fabs(MaxPhi-SecPhi)-
PI)*180./
PI;
238 double dthe = (fabs(MaxThe+SecThe)-
PI)*180./
PI;
242 if(GoodShowers.size()>=2 && MaxE>1.0 &&
abs(dthe)<3
243 && ((dphi>-25&&dphi<-4)||(dphi>2&&dphi<20)) &&
etot>2.7) {
245 double phi1 = MaxPhi<0 ? MaxPhi+CLHEP::twopi : MaxPhi;
246 double phi2 = SecPhi<0 ? SecPhi+CLHEP::twopi : SecPhi;
251 double phi12=(phi11+phi22-CLHEP::pi)*0.5;
252 double phi21=(phi11+phi22+CLHEP::pi)*0.5;
253 if(phi12<0.) phi12 += CLHEP::twopi;
254 if(phi21>CLHEP::twopi) phi21 -= CLHEP::twopi;
256 SmartDataPtr<MdcDigiCol> mdcDigiCol(evtSvc(),
"/Event/Digi/MdcDigiCol");
258 log << MSG::FATAL <<
"Could not find MdcDigiCol!" << endreq;
259 return StatusCode::FAILURE;
261 int hitnum = mdcDigiCol->size();
262 for (
int i = 0;i< hitnum;i++ ) {
263 MdcDigi* digi=
dynamic_cast<MdcDigi*
>(mdcDigiCol->containedObject(i));
266 if (
time == 0x7FFFFFFF ||
charge == 0x7FFFFFFF)
continue;
271 log << MSG::ERROR <<
"MDC(" << ilayer <<
","<<iphi <<
")"<<endreq;
272 double phi=CLHEP::twopi*iphi/idmax[ilayer];
279 if ( (m_BarrelOrEndcap==1&&total1>15 &&total2>15)
280 || (m_BarrelOrEndcap!=1&&total1>5 &&total2>5) ) {
281 setFilterPassed(
true);
291 m_sh1_theta = MaxThe;
294 m_sh2_theta = SecThe;
301 return StatusCode::SUCCESS;
308 MsgStream log(
msgSvc(), name());
309 log << MSG::INFO <<
"in finalize()" << endmsg;
310 cout<<
"m_events "<<m_events<<endl;
312 cout<<
"m_rejected "<<m_rejected<<endl;
313 cout<<
"m_oneProngsSelected "<<m_oneProngsSelected<<endl;
314 cout<<
"m_twoProngsMatchedSelected "<<m_twoProngsMatchedSelected<<endl;
315 cout<<
"m_twoProngsOneMatchedSelected "<<m_twoProngsOneMatchedSelected<<endl;
317 return StatusCode::SUCCESS;
323 double delta=0.0610865;
328 if(
phi2>CLHEP::twopi)
phi2 -= CLHEP::twopi;
339 if(ph<=phi2&&ph>=
phi1)
return true;
HepGeom::Point3D< double > HepPoint3D
std::vector< HepLorentzVector > Vp4
EvtRecTrackCol::iterator EvtRecTrackIterator
std::vector< HepLorentzVector > Vp4
BhabhaPreSelect(const std::string &name, ISvcLocator *pSvcLocator)
bool WhetherSector(double, double=0., double=CLHEP::twopi)
static unsigned int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
static unsigned int theta_module(const Identifier &id)
static unsigned int phi_module(const Identifier &id)
void clear()
Reset to invalid state.
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
static int wire(const Identifier &id)
virtual Identifier identify() const
unsigned int getChargeChannel() const
unsigned int getTimeChannel() const
RecEmcID getShowerId() const
_EXTERN_ std::string EvtRecEvent
_EXTERN_ std::string EvtRecTrackCol