1#include "GaudiKernel/MsgStream.h"
2#include "GaudiKernel/AlgFactory.h"
3#include "GaudiKernel/SmartDataPtr.h"
4#include "GaudiKernel/IDataProviderSvc.h"
5#include "GaudiKernel/PropertyMgr.h"
14#include "GaudiKernel/INTupleSvc.h"
15#include "GaudiKernel/NTuple.h"
16#include "GaudiKernel/Bootstrap.h"
17#include "GaudiKernel/IHistogramSvc.h"
18#include "CLHEP/Vector/ThreeVector.h"
19#include "CLHEP/Vector/LorentzVector.h"
20#include "CLHEP/Vector/TwoVector.h"
25#include "GaudiKernel/Bootstrap.h"
26#include "GaudiKernel/ISvcLocator.h"
27using CLHEP::Hep3Vector;
28using CLHEP::Hep2Vector;
29using CLHEP::HepLorentzVector;
30#include "CLHEP/Geometry/Point3D.h"
31#ifndef ENABLE_BACKWARDS_COMPATIBILITY
39typedef std::vector<int>
Vint;
40typedef std::vector<HepLorentzVector>
Vp4;
42const double mpi = 0.13957;
44int EventPreSelect::idmax[43]={40,44,48,56,64,72,80,80,76,76,
45 88,88,100,100,112,112,128,128,140,140,
46 160,160,160,160,176,176,176,176,208,208,
47 208,208,240,240,240,240,256,256,256,256,
52 Algorithm(name, pSvcLocator) {
55 declareProperty(
"Output", m_output =
false);
56 declareProperty(
"Ecm", m_ecm=3.686);
57 declareProperty(
"SelectBhabha", m_selectBhabha=
false);
58 declareProperty(
"SelectDimu", m_selectDimu=
false);
59 declareProperty(
"SelectHadron", m_selectHadron=
false);
60 declareProperty(
"SelectDiphoton", m_selectDiphoton=
false);
61 declareProperty(
"WriteDst", m_writeDst=
false);
62 declareProperty(
"WriteRec", m_writeRec=
false);
63 declareProperty(
"Vr0cut", m_vr0cut=1.0);
64 declareProperty(
"Vz0cut", m_vz0cut=5.0);
65 declareProperty(
"Pt0HighCut", m_pt0HighCut=5.0);
66 declareProperty(
"Pt0LowCut", m_pt0LowCut=0.05);
67 declareProperty(
"EnergyThreshold", m_energyThreshold=0.05);
68 declareProperty(
"GammaPhiCut", m_gammaPhiCut=20.0);
69 declareProperty(
"GammaThetaCut", m_gammaThetaCut=20.0);
71 declareProperty(
"BhabhaEmcECut", m_bhabhaEmcECut=0.7*m_ecm);
72 declareProperty(
"BhabhaMaxECut", m_bhabhaMaxECut=0.3*m_ecm);
73 declareProperty(
"BhabhaSecECut", m_bhabhaSecECut=0.1*m_ecm);
74 declareProperty(
"BhabhaDTheCut", m_bhabhaDTheCut=3.);
75 declareProperty(
"BhabhaDPhiCut1", m_bhabhaDPhiCut1=-25.);
76 declareProperty(
"BhabhaDPhiCut2", m_bhabhaDPhiCut2=-4.);
77 declareProperty(
"BhabhaDPhiCut3", m_bhabhaDPhiCut3=2.);
78 declareProperty(
"BhabhaDPhiCut4", m_bhabhaDPhiCut4=20.);
79 declareProperty(
"BhabhaMdcHitCutB", m_bhabhaMdcHitCutB=15);
80 declareProperty(
"BhabhaMdcHitCutE", m_bhabhaMdcHitCutE=5);
82 declareProperty(
"DimuEHighCut", m_dimuEHighCut=0.27*m_ecm);
83 declareProperty(
"DimuELowCut", m_dimuELowCut=0.027*m_ecm);
84 declareProperty(
"DimuDTheCut", m_dimuDTheCut=3.);
85 declareProperty(
"DimuDPhiCut", m_dimuDPhiCut=23.);
87 declareProperty(
"HadronChaECut", m_hadronChaECut=0.3*m_ecm);
88 declareProperty(
"HadronNeuECut", m_hadronNeuECut=0.3*m_ecm);
90 declareProperty(
"DiphotonEmcECut", m_diphotonEmcECut=0.7*m_ecm);
91 declareProperty(
"DiphotonSecECut", m_diphotonSecECut=0.3*m_ecm);
92 declareProperty(
"DiphotonDTheCut", m_diphotonDTheCut=3.);
93 declareProperty(
"DiphotonDPhiCut1", m_diphotonDPhiCut1=-4.);
94 declareProperty(
"DiphotonDPhiCut2", m_diphotonDPhiCut2=2.);
99 MsgStream log(
msgSvc(), name());
101 log << MSG::INFO <<
"in initialize()" << endmsg;
103 m_bhabhaEmcECut=0.7*m_ecm;
104 m_bhabhaMaxECut=0.3*m_ecm;
105 m_bhabhaSecECut=0.1*m_ecm;
106 m_dimuEHighCut=0.27*m_ecm;
107 m_dimuELowCut=0.027*m_ecm;
108 m_diphotonEmcECut=0.7*m_ecm;
109 m_diphotonSecECut=0.3*m_ecm;
110 m_hadronChaECut=0.3*m_ecm;
111 m_hadronNeuECut=0.3*m_ecm;
115 m_bhabhaEmcECut=0.7*m_ecm;
116 m_bhabhaMaxECut=0.15*m_ecm;
117 m_bhabhaSecECut=0.05*m_ecm;
118 m_diphotonEmcECut=0.7*m_ecm;
119 m_diphotonSecECut=0.2*m_ecm;
127 log << MSG::INFO <<
"creating sub-algorithms...." << endreq;
130 sc = createSubAlgorithm(
"EventWriter",
"SelectBarrelBhabha", m_subalg1);
131 if( sc.isFailure() ) {
132 log << MSG::ERROR <<
"Error creating Sub-Algorithm SelectBhabhaBarrel" <<endreq;
135 log << MSG::INFO <<
"Success creating Sub-Algorithm SelectBhabhaBarrel" <<endreq;
137 sc = createSubAlgorithm(
"EventWriter",
"SelectEndcapBhabha", m_subalg2);
138 if( sc.isFailure() ) {
139 log << MSG::ERROR <<
"Error creating Sub-Algorithm SelectBhabhaEndcap" <<endreq;
142 log << MSG::INFO <<
"Success creating Sub-Algorithm SelectBhabhaEndcap" <<endreq;
148 sc = createSubAlgorithm(
"EventWriter",
"SelectBarrelDimu", m_subalg3);
149 if( sc.isFailure() ) {
150 log << MSG::ERROR <<
"Error creating Sub-Algorithm SelectDimuBarrel" <<endreq;
153 log << MSG::INFO <<
"Success creating Sub-Algorithm SelectDimuBarrel" <<endreq;
155 sc = createSubAlgorithm(
"EventWriter",
"SelectEndcapDimu", m_subalg4);
156 if( sc.isFailure() ) {
157 log << MSG::ERROR <<
"Error creating Sub-Algorithm SelectDimuEndcap" <<endreq;
160 log << MSG::INFO <<
"Success creating Sub-Algorithm SelectDimuEndap" <<endreq;
165 sc = createSubAlgorithm(
"EventWriter",
"SelectHadron", m_subalg5);
166 if( sc.isFailure() ) {
167 log << MSG::ERROR <<
"Error creating Sub-Algorithm SelectHadron" <<endreq;
170 log << MSG::INFO <<
"Success creating Sub-Algorithm SelectHadron" <<endreq;
174 if(m_selectDiphoton) {
175 sc = createSubAlgorithm(
"EventWriter",
"SelectBarrelDiphoton", m_subalg6);
176 if( sc.isFailure() ) {
177 log << MSG::ERROR <<
"Error creating Sub-Algorithm SelectDiphotonBarrel" <<endreq;
180 log << MSG::INFO <<
"Success creating Sub-Algorithm SelectDiphotonBarrel" <<endreq;
182 sc = createSubAlgorithm(
"EventWriter",
"SelectEndcapDiphoton", m_subalg7);
183 if( sc.isFailure() ) {
184 log << MSG::ERROR <<
"Error creating Sub-Algorithm SelectDiphotonEndcap" <<endreq;
187 log << MSG::INFO <<
"Success creating Sub-Algorithm SelectDiphotonEndcap" <<endreq;
192 sc = createSubAlgorithm(
"EventWriter",
"WriteDst", m_subalg8);
193 if( sc.isFailure() ) {
194 log << MSG::ERROR <<
"Error creating Sub-Algorithm WriteDst" <<endreq;
197 log << MSG::INFO <<
"Success creating Sub-Algorithm WriteDst" <<endreq;
202 sc = createSubAlgorithm(
"EventWriter",
"WriteRec", m_subalg9);
203 if( sc.isFailure() ) {
204 log << MSG::ERROR <<
"Error creating Sub-Algorithm WriteRec" <<endreq;
207 log << MSG::INFO <<
"Success creating Sub-Algorithm WriteRec" <<endreq;
213 NTuplePtr nt0(
ntupleSvc(),
"FILE1/hadron");
214 if ( nt0 ) m_tuple0 = nt0;
216 m_tuple0 =
ntupleSvc()->book (
"FILE1/hadron", CLID_ColumnWiseTuple,
"N-Tuple example");
218 status = m_tuple0->addItem (
"esum", m_esum);
219 status = m_tuple0->addItem (
"eemc", m_eemc);
220 status = m_tuple0->addItem (
"etot", m_etot);
221 status = m_tuple0->addItem (
"nGood", m_nGood);
222 status = m_tuple0->addItem (
"nCharge", m_nCharge);
223 status = m_tuple0->addItem (
"nGam", m_nGam);
224 status = m_tuple0->addItem (
"ptot", m_ptot);
225 status = m_tuple0->addItem (
"pp", m_pp);
226 status = m_tuple0->addItem (
"pm", m_pm);
227 status = m_tuple0->addItem (
"run", m_runnb);
228 status = m_tuple0->addItem (
"event", m_evtnb);
229 status = m_tuple0->addItem (
"maxE", m_maxE);
230 status = m_tuple0->addItem (
"secE", m_secE);
231 status = m_tuple0->addItem (
"dthe", m_dThe);
232 status = m_tuple0->addItem (
"dphi", m_dPhi);
233 status = m_tuple0->addItem (
"mdcHit1", m_mdcHit1);
234 status = m_tuple0->addItem (
"mdcHit2", m_mdcHit2);
237 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(m_tuple0) << endmsg;
238 return StatusCode::FAILURE;
242 NTuplePtr nt1(
ntupleSvc(),
"FILE1/vxyz");
243 if ( nt1 ) m_tuple1 = nt1;
245 m_tuple1 =
ntupleSvc()->book (
"FILE1/vxyz", CLID_ColumnWiseTuple,
"ks N-Tuple example");
247 status = m_tuple1->addItem (
"vx0", m_vx0);
248 status = m_tuple1->addItem (
"vy0", m_vy0);
249 status = m_tuple1->addItem (
"vz0", m_vz0);
250 status = m_tuple1->addItem (
"vr0", m_vr0);
251 status = m_tuple1->addItem (
"theta0", m_theta0);
252 status = m_tuple1->addItem (
"p0", m_p0);
253 status = m_tuple1->addItem (
"pt0", m_pt0);
256 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(m_tuple1) << endmsg;
257 return StatusCode::FAILURE;
261 NTuplePtr nt2(
ntupleSvc(),
"FILE1/photon");
262 if ( nt2 ) m_tuple2 = nt2;
264 m_tuple2 =
ntupleSvc()->book (
"FILE1/photon", CLID_ColumnWiseTuple,
"ks N-Tuple example");
266 status = m_tuple2->addItem (
"dthe", m_dthe);
267 status = m_tuple2->addItem (
"dphi", m_dphi);
268 status = m_tuple2->addItem (
"dang", m_dang);
269 status = m_tuple2->addItem (
"eraw", m_eraw);
272 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(m_tuple2) << endmsg;
273 return StatusCode::FAILURE;
278 NTuplePtr nt3(
ntupleSvc(),
"FILE1/dimu");
279 if ( nt3 ) m_tuple3 = nt3;
281 m_tuple3 =
ntupleSvc()->book (
"FILE1/dimu", CLID_ColumnWiseTuple,
"ks N-Tuple example");
286 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(m_tuple3) << endmsg;
287 return StatusCode::FAILURE;
297 m_barrelBhabhaNumber=0;
298 m_endcapBhabhaNumber=0;
299 m_barrelDimuNumber=0;
300 m_endcapDimuNumber=0;
302 m_barrelDiphotonNumber=0;
303 m_endcapDiphotonNumber=0;
305 log << MSG::INFO <<
"successfully return from initialize()" <<endmsg;
306 return StatusCode::SUCCESS;
315 MsgStream log(
msgSvc(), name());
316 log << MSG::INFO <<
"in execute()" << endreq;
318 if( m_writeDst) m_subalg8->execute();
319 if( m_writeRec) m_subalg9->execute();
321 m_isBarrelBhabha =
false;
322 m_isEndcapBhabha =
false;
323 m_isBarrelDimu =
false;
324 m_isEndcapDimu =
false;
326 m_isBarrelDiphoton =
false;
327 m_isEndcapDiphoton =
false;
329 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
332 cout<<
" eventHeader "<<endl;
333 return StatusCode::FAILURE;
336 int run=eventHeader->runNumber();
337 int event=eventHeader->eventNumber();
339 if(m_events%1000==0) cout<< m_events <<
" -------- run,event: "<<run<<
","<<
event<<endl;
344 cout<<
" evtRecEvent "<<endl;
345 return StatusCode::FAILURE;
348 log << MSG::DEBUG <<
"ncharg, nneu, tottks = "
349 << evtRecEvent->totalCharged() <<
" , "
350 << evtRecEvent->totalNeutral() <<
" , "
351 << evtRecEvent->totalTracks() <<endreq;
354 cout<<
" evtRecTrkCol "<<endl;
355 return StatusCode::FAILURE;
358 if(evtRecEvent->totalTracks()!=evtRecTrkCol->size())
return StatusCode::SUCCESS;
364 for(
int i = 0;i < evtRecEvent->totalCharged(); i++)
368 if(!(*itTrk)->isMdcTrackValid())
continue;
370 double vx0 = mdcTrk->
x();
371 double vy0 = mdcTrk->
y();
372 double vz0 = mdcTrk->
z();
373 double vr0 = mdcTrk->
r();
374 double theta0 = mdcTrk->
theta();
375 double p0 = mdcTrk->
p();
376 double pt0 = mdcTrk->
pxy();
389 if(fabs(vz0) >= m_vz0cut)
continue;
390 if(vr0 >= m_vr0cut)
continue;
391 if(pt0 >= m_pt0HighCut)
continue;
392 if(pt0 <= m_pt0LowCut)
continue;
394 iGood.push_back((*itTrk)->trackId());
395 nCharge += mdcTrk->
charge();
397 int nGood = iGood.size();
402 for(
int i = evtRecEvent->totalCharged(); i< evtRecEvent->totalTracks(); i++) {
405 if(!(*itTrk)->isEmcShowerValid())
continue;
407 double eraw = emcTrk->
energy();
412 if(eraw < m_energyThreshold)
continue;
413 iGam.push_back((*itTrk)->trackId());
415 int nGam = iGam.size();
433 for(
int i = 0; i < nGood; i++) {
436 if((*itTrk)->isMdcTrackValid()) {
446 HepLorentzVector
ptrk;
458 ppip.push_back(
ptrk);
461 ppim.push_back(
ptrk);
467 if((*itTrk)->isEmcShowerValid()) {
470 double eraw = emcTrk->
energy();
471 double phi = emcTrk->
phi();
472 double the = emcTrk->
theta();
474 HepLorentzVector
ptrk;
494 for(
int i = 0; i < nGam; i++) {
497 double eraw = emcTrk->
energy();
498 double phi = emcTrk->
phi();
499 double the = emcTrk->
theta();
500 HepLorentzVector
ptrk;
506 pGam.push_back(
ptrk);
512 double esum = echarge + eneu;
517 double maxThe = 999.;
518 double maxPhi = 999.;
519 double secThe = 999.;
520 double secPhi = 999.;
527 SmartDataPtr<RecEmcShowerCol> aShowerCol(eventSvc(),
"/Event/Recon/RecEmcShowerCol");
529 log << MSG::WARNING <<
"Could not find RecEmcShowerCol" << endreq;
530 return( StatusCode::SUCCESS);
534 RecEmcShowerCol::iterator iShowerCol;
535 for(iShowerCol=aShowerCol->begin();
536 iShowerCol!=aShowerCol->end();
540 maxE = (*iShowerCol)->e5x5();
541 maxThe = (*iShowerCol)->theta();
542 maxPhi = (*iShowerCol)->phi();
543 npart = (*iShowerCol)->module();
544 }
else if(ishower == 1) {
545 secE = (*iShowerCol)->e5x5();
546 secThe = (*iShowerCol)->theta();
547 secPhi = (*iShowerCol)->phi();
548 }
else if(ishower == 2) {
556 if(aShowerCol->size() >= 2) {
558 dphi = (fabs(maxPhi-secPhi)-CLHEP::pi)*180./CLHEP::pi;
559 dthe = (fabs(maxThe+secThe)-CLHEP::pi)*180./CLHEP::pi;
561 double phi1 = maxPhi<0 ? maxPhi+CLHEP::twopi : maxPhi;
562 double phi2 = secPhi<0 ? secPhi+CLHEP::twopi : secPhi;
567 double phi12=(phi11+phi22-CLHEP::pi)*0.5;
568 double phi21=(phi11+phi22+CLHEP::pi)*0.5;
569 if(phi12<0.) phi12 += CLHEP::twopi;
570 if(phi21>CLHEP::twopi) phi21 -= CLHEP::twopi;
572 SmartDataPtr<MdcDigiCol> mdcDigiCol(evtSvc(),
"/Event/Digi/MdcDigiCol");
574 log << MSG::FATAL <<
"Could not find MdcDigiCol!" << endreq;
575 return StatusCode::FAILURE;
577 int hitnum = mdcDigiCol->size();
578 for (
int i = 0;i< hitnum;i++ ) {
579 MdcDigi* digi=
dynamic_cast<MdcDigi*
>(mdcDigiCol->containedObject(i));
582 if (
time == 0x7FFFFFFF ||
charge == 0x7FFFFFFF)
continue;
587 log << MSG::ERROR <<
"MDC(" << ilayer <<
","<<iphi <<
")"<<endreq;
588 double phi=CLHEP::twopi*iphi/idmax[ilayer];
601 if( eemc>m_bhabhaEmcECut && maxE>m_bhabhaMaxECut && secE>m_bhabhaSecECut
602 &&
abs(dthe)<m_bhabhaDTheCut &&
603 ( (dphi>m_bhabhaDPhiCut1&&dphi<m_bhabhaDPhiCut2) ||
604 (dphi>m_bhabhaDPhiCut3&&dphi<m_bhabhaDPhiCut4) ) ) {
605 if( npart==1 && mdcHit1>m_bhabhaMdcHitCutB && mdcHit2>m_bhabhaMdcHitCutB ) {
606 m_isBarrelBhabha =
true;
607 m_barrelBhabhaNumber++;
608 }
else if( ( npart==0 || npart==2 )
609 && mdcHit1>m_bhabhaMdcHitCutE && mdcHit2>m_bhabhaMdcHitCutE ) {
610 m_isEndcapBhabha =
true;
611 m_endcapBhabhaNumber++;
628 if( m_dimuAlg->
IsDimu() == 1 ) {
629 m_isBarrelDimu =
true;
630 m_barrelDimuNumber++;
631 }
else if(m_dimuAlg->
IsDimu() == 2 ) {
632 m_isEndcapDimu =
true;
633 m_endcapDimuNumber++;
638 if( (nGood>=1 && esum>m_hadronChaECut)
639 || (nGood==0 && esum>m_hadronNeuECut) ) {
645 if( nGood==0 && eemc>m_diphotonEmcECut && secE>m_diphotonSecECut
646 && fabs(dthe)<m_diphotonDTheCut
647 && dphi>m_diphotonDPhiCut1 && dphi<m_diphotonDPhiCut2 ) {
649 m_isBarrelDiphoton =
true;
650 m_barrelDiphotonNumber++;
651 }
else if( npart==0 || npart==2 ) {
652 m_isEndcapDiphoton =
true;
653 m_endcapDiphotonNumber++;
658 if( m_selectBhabha && m_isBarrelBhabha ) m_subalg1->execute();
659 if( m_selectBhabha && m_isEndcapBhabha ) m_subalg2->execute();
660 if( m_selectDimu && m_isBarrelDimu ) m_subalg3->execute();
661 if( m_selectDimu && m_isEndcapDimu ) m_subalg4->execute();
662 if( m_selectHadron && m_isHadron ) m_subalg5->execute();
663 if( m_selectDiphoton && m_isBarrelDiphoton ) m_subalg6->execute();
664 if( m_selectDiphoton && m_isEndcapDiphoton ) m_subalg7->execute();
688 return StatusCode::SUCCESS;
695 MsgStream log(
msgSvc(), name());
696 log << MSG::INFO <<
"in finalize()" << endmsg;
698 if(m_selectDimu&&m_output) {
702 cout<<
"Total events: "<<m_events<<endl;
705 cout <<
"Selected barrel bhabha: " << m_barrelBhabhaNumber << endl;
706 cout <<
"Selected endcap bhabha: " << m_endcapBhabhaNumber << endl;
711 cout <<
"Selected barrel dimu: " << m_barrelDimuNumber << endl;
712 cout <<
"Selected endcap dimu: " << m_endcapDimuNumber << endl;
716 cout <<
"Selected hadron: " << m_hadronNumber << endl;
719 if(m_selectDiphoton) {
720 cout <<
"Selected barrel diphoton: " << m_barrelDiphotonNumber << endl;
721 cout <<
"Selected endcap diphoton: " << m_endcapDiphotonNumber << endl;
724 return StatusCode::SUCCESS;
730 double delta=0.0610865;
735 if(
phi2>CLHEP::twopi)
phi2 -= CLHEP::twopi;
746 if(ph<=phi2&&ph>=
phi1)
return true;
double sin(const BesAngle a)
double cos(const BesAngle a)
HepGeom::Point3D< double > HepPoint3D
std::vector< HepLorentzVector > Vp4
EvtRecTrackCol::iterator EvtRecTrackIterator
std::vector< HepLorentzVector > Vp4
void BookNtuple(NTuple::Tuple *&tuple)
const double theta() const
bool WhetherSector(double ph, double ph1, double ph2)
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
_EXTERN_ std::string EvtRecEvent
_EXTERN_ std::string EvtRecTrackCol