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"
17#include "GaudiKernel/INTupleSvc.h"
18#include "GaudiKernel/NTuple.h"
19#include "GaudiKernel/Bootstrap.h"
20#include "GaudiKernel/IHistogramSvc.h"
21#include "CLHEP/Vector/ThreeVector.h"
22using CLHEP::Hep3Vector;
23#include "CLHEP/Vector/LorentzVector.h"
24using CLHEP::HepLorentzVector;
25#include "CLHEP/Vector/TwoVector.h"
26using CLHEP::Hep2Vector;
27#include "CLHEP/Geometry/Point3D.h"
28#ifndef ENABLE_BACKWARDS_COMPATIBILITY
38typedef std::vector<int>
Vint;
39typedef std::vector<HepLorentzVector>
Vp4;
41const double velc = 299.792458;
42const double xmass[5] = {0.000511, 0.105658, 0.139570, 0.493677, 0.938272};
43const double pai=3.1415926;
48 Algorithm(name, pSvcLocator)
51 for(
int i = 0; i < 10; i++)
62 declareProperty(
"CmsEnergy", m_ecms = 3.686);
64 declareProperty(
"max1", m_max1 = 1.2);
65 declareProperty(
"max2", m_max2 = 0.8);
66 declareProperty(
"costheta", m_costheta = 0.8);
67 declareProperty(
"dphi1", m_dphi1 = 2.5);
68 declareProperty(
"dphi2", m_dphi2 = 5);
69 declareProperty(
"eff", m_eff = 0.07);
70 declareProperty(
"sec", m_sec = 184.1);
76 MsgStream log(
msgSvc(), name());
78 log << MSG::INFO <<
"in initialize()" << endmsg;
82 NTuplePtr nt1(
ntupleSvc(),
"FILE1/DiGam");
83 if ( nt1 ) m_tuple1 = nt1;
86 m_tuple1 =
ntupleSvc()->book (
"FILE1/DiGam", CLID_ColumnWiseTuple,
"DiGam N-Tuple signal");
89 status = m_tuple1->addItem (
"run", m_run );
90 status = m_tuple1->addItem (
"rec", m_rec );
91 status = m_tuple1->addItem (
"time", m_time );
93 status = m_tuple1->addItem (
"ngood", m_ngood);
94 status = m_tuple1->addItem (
"nchrg", m_nchrg);
96 status = m_tuple1->addItem (
"Cms_e1", m_e1);
97 status = m_tuple1->addItem (
"Cms_e2", m_e2);
98 status = m_tuple1->addItem (
"Cms_e", m_e);
99 status = m_tuple1->addItem (
"Cms_costheta1", m_costheta1);
100 status = m_tuple1->addItem (
"Cms_costheta2", m_costheta2);
101 status = m_tuple1->addItem (
"Cms_dltphi", m_dltphi);
102 status = m_tuple1->addItem (
"Cms_dltphi_1", m_dltphi_1);
103 status = m_tuple1->addItem (
"Cms_dlttheta", m_dlttheta);
104 status = m_tuple1->addItem (
"Cms_phi1", m_phi1);
105 status = m_tuple1->addItem (
"Cms_phi2", m_phi2);
107 status = m_tuple1->addItem (
"Lab_e1", m_e1_lab);
108 status = m_tuple1->addItem (
"Lab_e2", m_e2_lab);
109 status = m_tuple1->addItem (
"Lab_e", m_e_lab);
110 status = m_tuple1->addItem (
"Lab_costheta1", m_costheta1_lab);
111 status = m_tuple1->addItem (
"Lab_costheta2", m_costheta2_lab);
112 status = m_tuple1->addItem (
"Lab_dltphi", m_dltphi_lab);
113 status = m_tuple1->addItem (
"Lab_dlttheta", m_dlttheta_lab);
114 status = m_tuple1->addItem (
"Lab_phi1", m_phi1_lab);
115 status = m_tuple1->addItem (
"Lab_phi2", m_phi2_lab);
117 status = m_tuple1->addItem (
"xBoost", m_xBoost);
118 status = m_tuple1->addItem (
"yBoost", m_yBoost);
119 status = m_tuple1->addItem (
"zBoost", m_zBoost);
123 log << MSG::ERROR <<
"Cannot book N-tuple1:"<<long(m_tuple1)<<endmsg;
124 return StatusCode::FAILURE;
131 log << MSG::INFO <<
"successfully return from initialize()" <<endmsg;
132 return StatusCode::SUCCESS;
138 StatusCode sc=StatusCode::SUCCESS;
141 MsgStream log(
msgSvc(),name());
142 log<<MSG::INFO<<
"in execute()"<<endreq;
143 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
147 m_run = eventHeader->runNumber();
148 m_rec = eventHeader->eventNumber();
151 int time = eventHeader->time();
152 if(m_event > 1 &&
runNo != m_runNo)
return sc;
156 if(m_rec%1000==0)cout<<
"Run "<<m_run<<
" Event "<<m_rec<<endl;
158 HepLorentzVector p4psip(0.011*m_ecms, 0.0, 0.005, m_ecms);
159 double psipBeta = (p4psip.vect()).mag()/(p4psip.e());
163 int NCharge = evtRecEvent->totalCharged();
164 if(NCharge != 0)
return sc;
172 if(((evtRecEvent->totalTracks() - evtRecEvent->totalCharged() )<2) || ((evtRecEvent->totalTracks() - evtRecEvent->totalCharged() )>15))
return sc;
175 HepLorentzVector p4Gam_1;
176 HepLorentzVector p4Gam_2;
178 for(
int i=evtRecEvent->totalCharged(); i<evtRecEvent->totalTracks(); i++)
181 if(!(*itTrk)->isEmcShowerValid())
continue;
184 HepLorentzVector p4Gam;
185 double Phi = emcTrk->
phi();
186 double Theta = emcTrk->
theta();
187 double Ener=emcTrk->
energy();
189 p4Gam.setPx(Ener *
sin(Theta) *
cos(
Phi));
190 p4Gam.setPy(Ener *
sin(Theta) *
sin(
Phi));
191 p4Gam.setPz(Ener *
cos(Theta));
193 p4Gam.boost(-0.011, 0 ,-0.005 * 1.0 / 3.686);
213 m_e_lab = Emax1 + Emax2;
214 log << MSG::INFO <<
"Emax1 = " << Emax1 <<
"Emax2= "<<Emax2<< endreq;
215 if(Emax1 < m_max1 || Emax2 < m_max2)
return sc;
219 double emcphi[2],emctht[2];
220 for(
int i = 0;i < 2; i++)
222 if(i>=evtRecTrkCol->size())
break;
224 if(!(*itTrk)->isEmcShowerValid())
continue;
226 emcphi[i]=emcTrk->
phi();
227 emctht[i]=emcTrk->
theta();
229 double dltphi_lab = (fabs(emcphi[0] - emcphi[1]) -
pai) * 180.0 /
pai;
230 double dlttheta_lab = (fabs(emctht[0] + emctht[1]) -
pai) * 180.0 /
pai;
231 m_costheta1_lab =
cos(emctht[0]);
232 m_costheta2_lab =
cos(emctht[1]);
233 m_phi1_lab = emcphi[0] * 180.0 /
pai;
234 m_phi2_lab = emcphi[1] * 180.0 /
pai;
235 m_dlttheta_lab = dlttheta_lab;
236 m_dltphi_lab = dltphi_lab;
238 if(fabs(m_costheta1_lab) > m_costheta || fabs(m_costheta2_lab) > m_costheta)
return sc;
243 double px1 = p4Gam_1.px();
244 double py1 = p4Gam_1.py();
245 double pz1 = p4Gam_1.pz();
246 double pxy1 = sqrt(px1 * px1 + py1 * py1);
247 double e1 = p4Gam_1.e();
249 double px2 = p4Gam_2.px();
250 double py2 = p4Gam_2.py();
251 double pz2 = p4Gam_2.pz();
252 double pxy2 = sqrt(px2 * px2 + py2 * py2);
253 double e2 = p4Gam_2.e();
258 if(atan(py1 * 1.0 / px1) > 0){
259 if(px1 > 0)
phi1 = atan(py1 * 1.0 / px1);
260 else phi1 = -(
pai - atan(py1 * 1.0 / px1));
263 if(px1 > 0)
phi1 = atan(py1 * 1.0 / px1);
264 else phi1 =
pai + atan(py1 * 1.0 / px1);
267 if(atan(py2 * 1.0 / px2) > 0){
268 if(px2 > 0)
phi2 = atan(py2 * 1.0 / px2);
269 else phi2 = -(
pai - atan(py2 * 1.0 / px2));
272 if(px2 > 0)
phi2 = atan(py2 * 1.0 / px2);
273 else phi2 =
pai + atan(py2 * 1.0 / px2);
281 if(pz1 > 0)
theta1 = atan(pxy1 * 1.0 / pz1);
282 else theta1 = (
pai + atan(pxy1 * 1.0 / pz1));
284 if(pz2 > 0)
theta2 = atan(pxy2 * 1.0 / pz2);
285 else theta2 = (
pai + atan(pxy2 * 1.0 / pz2));
289 double xBoost = p4Gam_1.px() + p4Gam_2.px();
290 double yBoost = p4Gam_1.py() + p4Gam_2.py();
291 double zBoost = p4Gam_1.pz() + p4Gam_2.pz();
300 m_dlttheta = dlttheta;
307 if(fabs(m_dltphi) < m_dphi1) Ndata1++;
308 if(fabs(m_dltphi) > m_dphi1 && fabs(m_dltphi) < m_dphi2) Ndata2++;
314 return StatusCode::SUCCESS;
321 char foot[100] =
".txt";
322 sprintf(head,
"OffLineLum_%04d",m_runNo);
324 ofstream fout(head,ios::out);
325 fout<<
"==============================================="<<endl;
326 fout<<
"DESIGNED For OffLine Luminosity BY 2Gam Events"<<endl<<endl;
327 fout<<
"MANY THANKS to Prof. C.Z Yuan & Z.Y Wang"<<endl<<endl;
328 fout<<
" 2009/05"<<endl;
330 fout<<
"==============================================="<<endl<<endl<<endl;
332 double lum = (Ndata1 - Ndata2) * 1.0 / (m_eff * m_sec);
333 fout<<
" Table List "<<endl<<endl;
334 fout<<
"-----------------------------------------------"<<endl;
335 fout<<
"Firstly Energy Gamma "<<m_max1<<
" Gev"<<endl;
336 fout<<
"Secondly Energy Gamma "<<m_max2<<
" Gev"<<endl;
337 fout<<
"Solid Angle Acceptance "<<m_costheta<<endl;
338 fout<<
"QED XSection "<<m_sec<<
" NB"<<endl;
339 fout<<
"Monte Carto Efficiency "<<m_eff * 100<<
"%"<<endl<<endl;
340 fout<<
"runNo Luminosity "<<endl<<endl;
341 fout<<m_runNo<<
" "<<
lum<<
" nb^(-1)"<<endl;
342 fout<<
"-----------------------------------------------"<<endl;
345 MsgStream log(
msgSvc(), name());
346 cout<<
"in finalize()" <<endl;
347 cout<<
"all events " <<m_pass[0]<<endl;
348 cout<<
"NCharged==0 " <<m_pass[1]<<endl;
349 cout<<
"Number of Gam " <<m_pass[2]<<endl;
350 cout<<
"N events " <<m_pass[3]<<endl;
351 cout<<
"N events 0.8 " <<m_pass[4]<<endl;
352 return StatusCode::SUCCESS;
double sin(const BesAngle a)
double cos(const BesAngle a)
double Phi(RecMdcKalTrack *trk)
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
EvtRecTrackCol::iterator EvtRecTrackIterator
HepGeom::Point3D< double > HepPoint3D
std::vector< HepLorentzVector > Vp4
_EXTERN_ std::string EvtRecEvent
_EXTERN_ std::string EvtRecTrackCol