BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TwoGamma.cxx
Go to the documentation of this file.
1#include "CLHEP/Vector/LorentzVector.h"
2#include "CLHEP/Vector/ThreeVector.h"
3#include "CLHEP/Vector/TwoVector.h"
4#include "GaudiKernel/Bootstrap.h"
5#include "GaudiKernel/INTupleSvc.h"
6#include "GaudiKernel/ISvcLocator.h"
7#include "GaudiKernel/MsgStream.h"
8#include "GaudiKernel/NTuple.h"
9#include "GaudiKernel/SmartDataPtr.h"
10#include "TH1F.h"
11#include "TMath.h"
12#include <fstream>
13#include <vector>
14
15#include "EventModel/EventHeader.h"
16#include "EventModel/EventModel.h"
17#include "EvtRecEvent/EvtRecEvent.h"
18#include "EvtRecEvent/EvtRecTrack.h"
19#include "VertexFit/Helix.h"
20
21using CLHEP::Hep2Vector;
22using CLHEP::Hep3Vector;
23using CLHEP::HepLorentzVector;
24#include "CLHEP/Geometry/Point3D.h"
25#ifndef ENABLE_BACKWARDS_COMPATIBILITY
26typedef HepGeom::Point3D<double> HepPoint3D;
27#endif
28
29#include "TwoGamma.h"
30
31typedef std::vector<int> Vint;
32typedef std::vector<HepLorentzVector> Vp4;
33const double ecms = 3.686;
34const double velc = 299.792458;
35const double xmass[5] = { 0.000511, 0.105658, 0.139570, 0.493677, 0.938272 };
36const double pai = 3.1415926;
37
39////////////////////////////////////////////////////////////////////
40TwoGamma::TwoGamma( const std::string& name, ISvcLocator* pSvcLocator )
41 : Algorithm( name, pSvcLocator ) {
42 // m_tuple1 = 0;
43 for ( int i = 0; i < 10; i++ ) { m_pass[i] = 0; }
44 m_event = 0;
45
46 Ndata1 = 0;
47 Ndata2 = 0;
48 m_runNo = 0;
49
50 // Declare the properties
51 declareProperty( "CmsEnergy", m_ecms = 3.686 );
52
53 declareProperty( "max1", m_max1 = 1.2 );
54 declareProperty( "max2", m_max2 = 0.8 );
55 declareProperty( "costheta", m_costheta = 0.8 );
56 declareProperty( "dphi1", m_dphi1 = 2.5 );
57 declareProperty( "dphi2", m_dphi2 = 5 );
58 declareProperty( "eff", m_eff = 0.07 );
59 declareProperty( "sec", m_sec = 184.1 );
60}
61
62// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
64 MsgStream log( msgSvc(), name() );
65
66 log << MSG::INFO << "in initialize()" << endmsg;
67
68 StatusCode status;
69
70 NTuplePtr nt1( ntupleSvc(), "FILE1/DiGam" );
71 if ( nt1 ) m_tuple1 = nt1;
72 else
73 {
74 m_tuple1 =
75 ntupleSvc()->book( "FILE1/DiGam", CLID_ColumnWiseTuple, "DiGam N-Tuple signal" );
76 if ( m_tuple1 )
77 {
78 status = m_tuple1->addItem( "run", m_run );
79 status = m_tuple1->addItem( "rec", m_rec );
80 status = m_tuple1->addItem( "time", m_time );
81
82 status = m_tuple1->addItem( "ngood", m_ngood );
83 status = m_tuple1->addItem( "nchrg", m_nchrg );
84
85 status = m_tuple1->addItem( "Cms_e1", m_e1 );
86 status = m_tuple1->addItem( "Cms_e2", m_e2 );
87 status = m_tuple1->addItem( "Cms_e", m_e );
88 status = m_tuple1->addItem( "Cms_costheta1", m_costheta1 );
89 status = m_tuple1->addItem( "Cms_costheta2", m_costheta2 );
90 status = m_tuple1->addItem( "Cms_dltphi", m_dltphi );
91 status = m_tuple1->addItem( "Cms_dltphi_1", m_dltphi_1 );
92 status = m_tuple1->addItem( "Cms_dlttheta", m_dlttheta );
93 status = m_tuple1->addItem( "Cms_phi1", m_phi1 );
94 status = m_tuple1->addItem( "Cms_phi2", m_phi2 );
95
96 status = m_tuple1->addItem( "Lab_e1", m_e1_lab );
97 status = m_tuple1->addItem( "Lab_e2", m_e2_lab );
98 status = m_tuple1->addItem( "Lab_e", m_e_lab );
99 status = m_tuple1->addItem( "Lab_costheta1", m_costheta1_lab );
100 status = m_tuple1->addItem( "Lab_costheta2", m_costheta2_lab );
101 status = m_tuple1->addItem( "Lab_dltphi", m_dltphi_lab );
102 status = m_tuple1->addItem( "Lab_dlttheta", m_dlttheta_lab );
103 status = m_tuple1->addItem( "Lab_phi1", m_phi1_lab );
104 status = m_tuple1->addItem( "Lab_phi2", m_phi2_lab );
105
106 status = m_tuple1->addItem( "xBoost", m_xBoost );
107 status = m_tuple1->addItem( "yBoost", m_yBoost );
108 status = m_tuple1->addItem( "zBoost", m_zBoost );
109 }
110 else
111 {
112 log << MSG::ERROR << "Cannot book N-tuple1:" << long( m_tuple1 ) << endmsg;
113 return StatusCode::FAILURE;
114 }
115 }
116 Ndata1 = 0;
117 Ndata2 = 0;
118 m_runNo = 0;
119
120 log << MSG::INFO << "successfully return from initialize()" << endmsg;
121 return StatusCode::SUCCESS;
122}
123
124//*********************************************************************************************************************
125StatusCode TwoGamma::execute() {
126 StatusCode sc = StatusCode::SUCCESS;
127 m_event++;
128
129 MsgStream log( msgSvc(), name() );
130 log << MSG::INFO << "in execute()" << endmsg;
131 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
132 SmartDataPtr<EvtRecEvent> evtRecEvent( eventSvc(), EventModel::EvtRec::EvtRecEvent );
133 SmartDataPtr<EvtRecTrackCol> evtRecTrkCol( eventSvc(), EventModel::EvtRec::EvtRecTrackCol );
134
135 m_run = eventHeader->runNumber();
136 m_rec = eventHeader->eventNumber();
137 int runNo = m_run;
138 int event = m_rec;
139 int time = eventHeader->time();
140 if ( m_event > 1 && runNo != m_runNo ) return sc;
141 m_runNo = runNo;
142 m_time = time;
143
144 if ( m_rec % 1000 == 0 ) cout << "Run " << m_run << " Event " << m_rec << endl;
145
146 HepLorentzVector p4psip( 0.011 * m_ecms, 0.0, 0.005, m_ecms );
147 double psipBeta = ( p4psip.vect() ).mag() / ( p4psip.e() );
148
149 m_pass[0] += 1;
150
151 int NCharge = evtRecEvent->totalCharged();
152 if ( NCharge != 0 ) return sc;
153
154 m_pass[1] += 1;
155
156 double Emax1 = 0.0;
157 double Emax2 = 0.0;
158 int Imax[2];
159
160 if ( ( ( evtRecEvent->totalTracks() - evtRecEvent->totalCharged() ) < 2 ) ||
161 ( ( evtRecEvent->totalTracks() - evtRecEvent->totalCharged() ) > 15 ) )
162 return sc;
163 m_pass[2] += 1;
164
165 HepLorentzVector p4Gam_1;
166 HepLorentzVector p4Gam_2;
167
168 for ( int i = evtRecEvent->totalCharged(); i < evtRecEvent->totalTracks(); i++ )
169 {
170 EvtRecTrackIterator itTrk = evtRecTrkCol->begin() + i;
171 if ( !( *itTrk )->isEmcShowerValid() ) continue;
172 RecEmcShower* emcTrk = ( *itTrk )->emcShower();
173
174 HepLorentzVector p4Gam;
175 double Phi = emcTrk->phi();
176 double Theta = emcTrk->theta();
177 double Ener = emcTrk->energy();
178
179 p4Gam.setPx( Ener * sin( Theta ) * cos( Phi ) );
180 p4Gam.setPy( Ener * sin( Theta ) * sin( Phi ) );
181 p4Gam.setPz( Ener * cos( Theta ) );
182 p4Gam.setE( Ener );
183 p4Gam.boost( -0.011, 0, -0.005 * 1.0 / 3.686 );
184
185 if ( Ener > Emax2 )
186 {
187 Emax2 = Ener;
188 Imax[1] = i;
189 p4Gam_2 = p4Gam;
190 }
191 if ( Ener > Emax1 )
192 {
193 Emax2 = Emax1;
194 p4Gam_2 = p4Gam_1;
195 Imax[1] = Imax[0];
196 Emax1 = Ener;
197 p4Gam_1 = p4Gam;
198 Imax[0] = i;
199 }
200 }
201 m_e1_lab = Emax1;
202 m_e2_lab = Emax2;
203 m_e_lab = Emax1 + Emax2;
204 log << MSG::INFO << "Emax1 = " << Emax1 << "Emax2= " << Emax2 << endmsg;
205 if ( Emax1 < m_max1 || Emax2 < m_max2 ) return sc;
206 m_pass[3] += 1;
207
208 // P4 in Lab
209 double emcphi[2], emctht[2];
210 for ( int i = 0; i < 2; i++ )
211 {
212 if ( i >= evtRecTrkCol->size() ) break;
213 EvtRecTrackIterator itTrk = evtRecTrkCol->begin() + Imax[i];
214 if ( !( *itTrk )->isEmcShowerValid() ) continue;
215 RecEmcShower* emcTrk = ( *itTrk )->emcShower();
216 emcphi[i] = emcTrk->phi();
217 emctht[i] = emcTrk->theta();
218 }
219 double dltphi_lab = ( fabs( emcphi[0] - emcphi[1] ) - pai ) * 180.0 / pai;
220 double dlttheta_lab = ( fabs( emctht[0] + emctht[1] ) - pai ) * 180.0 / pai;
221 m_costheta1_lab = cos( emctht[0] );
222 m_costheta2_lab = cos( emctht[1] );
223 m_phi1_lab = emcphi[0] * 180.0 / pai;
224 m_phi2_lab = emcphi[1] * 180.0 / pai;
225 m_dlttheta_lab = dlttheta_lab;
226 m_dltphi_lab = dltphi_lab;
227
228 if ( fabs( m_costheta1_lab ) > m_costheta || fabs( m_costheta2_lab ) > m_costheta )
229 return sc;
230 m_pass[4] += 1;
231 // P4 in Lab
232
233 // P4 in Cms
234 double px1 = p4Gam_1.px();
235 double py1 = p4Gam_1.py();
236 double pz1 = p4Gam_1.pz();
237 double pxy1 = sqrt( px1 * px1 + py1 * py1 );
238 double e1 = p4Gam_1.e();
239
240 double px2 = p4Gam_2.px();
241 double py2 = p4Gam_2.py();
242 double pz2 = p4Gam_2.pz();
243 double pxy2 = sqrt( px2 * px2 + py2 * py2 );
244 double e2 = p4Gam_2.e();
245
246 double phi1 = 0;
247 double phi2 = 0;
248 if ( atan( py1 * 1.0 / px1 ) > 0 )
249 {
250 if ( px1 > 0 ) phi1 = atan( py1 * 1.0 / px1 );
251 else phi1 = -( pai - atan( py1 * 1.0 / px1 ) );
252 }
253 else
254 {
255 if ( px1 > 0 ) phi1 = atan( py1 * 1.0 / px1 );
256 else phi1 = pai + atan( py1 * 1.0 / px1 );
257 }
258
259 if ( atan( py2 * 1.0 / px2 ) > 0 )
260 {
261 if ( px2 > 0 ) phi2 = atan( py2 * 1.0 / px2 );
262 else phi2 = -( pai - atan( py2 * 1.0 / px2 ) );
263 }
264 else
265 {
266 if ( px2 > 0 ) phi2 = atan( py2 * 1.0 / px2 );
267 else phi2 = pai + atan( py2 * 1.0 / px2 );
268 }
269
270 double dltphi = ( fabs( phi1 - phi2 ) - pai ) * 180.0 / pai;
271
272 double theta1 = 0;
273 double theta2 = 0;
274
275 if ( pz1 > 0 ) theta1 = atan( pxy1 * 1.0 / pz1 );
276 else theta1 = ( pai + atan( pxy1 * 1.0 / pz1 ) );
277
278 if ( pz2 > 0 ) theta2 = atan( pxy2 * 1.0 / pz2 );
279 else theta2 = ( pai + atan( pxy2 * 1.0 / pz2 ) );
280
281 double dlttheta = ( theta1 + theta2 - pai ) * 180.0 / pai;
282
283 double xBoost = p4Gam_1.px() + p4Gam_2.px();
284 double yBoost = p4Gam_1.py() + p4Gam_2.py();
285 double zBoost = p4Gam_1.pz() + p4Gam_2.pz();
286 m_xBoost = xBoost;
287 m_yBoost = yBoost;
288 m_zBoost = zBoost;
289
290 m_costheta1 = cos( theta1 );
291 m_costheta2 = cos( theta2 );
292 m_phi1 = phi1 * 180.0 / pai;
293 m_phi2 = phi2 * 180.0 / pai;
294 m_dlttheta = dlttheta;
295 m_dltphi = dltphi;
296 m_e1 = e1;
297 m_e2 = e2;
298 m_e = e1 + e2;
299 // P4 in Cms
300
301 if ( fabs( m_dltphi ) < m_dphi1 ) Ndata1++;
302 if ( fabs( m_dltphi ) > m_dphi1 && fabs( m_dltphi ) < m_dphi2 ) Ndata2++;
303
304 m_tuple1->write().ignore();
305 // runNo = 0;
306
307 return StatusCode::SUCCESS;
308}
309
310//*************************************************************************************************************
311StatusCode TwoGamma::finalize() {
312 char head[100];
313 char foot[100] = ".txt";
314 sprintf( head, "OffLineLum_%04d", m_runNo );
315 strcat( head, foot );
316 ofstream fout( head, ios::out );
317 fout << "===============================================" << endl;
318 fout << "DESIGNED For OffLine Luminosity BY 2Gam Events" << endl << endl;
319 fout << "MANY THANKS to Prof. C.Z Yuan & Z.Y Wang" << endl << endl;
320 fout << " 2009/05" << endl;
321 // fout<<" Charmonium Group"<<endl;
322 fout << "===============================================" << endl << endl << endl;
323
324 double lum = ( Ndata1 - Ndata2 ) * 1.0 / ( m_eff * m_sec );
325 fout << " Table List " << endl << endl;
326 fout << "-----------------------------------------------" << endl;
327 fout << "Firstly Energy Gamma " << m_max1 << " Gev" << endl;
328 fout << "Secondly Energy Gamma " << m_max2 << " Gev" << endl;
329 fout << "Solid Angle Acceptance " << m_costheta << endl;
330 fout << "QED XSection " << m_sec << " NB" << endl;
331 fout << "Monte Carto Efficiency " << m_eff * 100 << "%" << endl << endl;
332 fout << "runNo Luminosity " << endl << endl;
333 fout << m_runNo << " " << lum << " nb^(-1)" << endl;
334 fout << "-----------------------------------------------" << endl;
335 fout.close();
336
337 MsgStream log( msgSvc(), name() );
338 cout << "in finalize()" << endl;
339 cout << "all events " << m_pass[0] << endl;
340 cout << "NCharged==0 " << m_pass[1] << endl;
341 cout << "Number of Gam " << m_pass[2] << endl;
342 cout << "N events " << m_pass[3] << endl;
343 cout << "N events 0.8 " << m_pass[4] << endl;
344 return StatusCode::SUCCESS;
345}
const double pai
Definition BbEmc.cxx:47
DECLARE_COMPONENT(BesBdkRc)
double Phi(RecMdcKalTrack *trk)
HepGeom::Point3D< double > HepPoint3D
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)
int runNo
Definition DQA_TO_DB.cxx:13
Double_t phi2
Double_t lum[10]
Double_t dltphi
Double_t phi1
Double_t time
Double_t e1
Double_t e2
EvtRecTrackCol::iterator EvtRecTrackIterator
std::vector< HepLorentzVector > Vp4
Definition Gam4pikp.cxx:38
const double xmass[5]
Definition Gam4pikp.cxx:35
const double velc
Definition Gam4pikp.cxx:36
std::vector< int > Vint
Definition Gam4pikp.cxx:37
INTupleSvc * ntupleSvc()
IMessageSvc * msgSvc()
StatusCode execute()
Definition TwoGamma.cxx:125
TwoGamma(const std::string &name, ISvcLocator *pSvcLocator)
Definition TwoGamma.cxx:40
StatusCode finalize()
Definition TwoGamma.cxx:311
StatusCode initialize()
Definition TwoGamma.cxx:63
const double ecms
Definition inclkstar.cxx:26