BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Mcgpj.cxx
Go to the documentation of this file.
1//*****************************************************************************
2//
3// Mcgpj.cxx
4//
5// General 2-body generator for e^+e^-, mu^+mu^-, pi^+pi^-, tau^+tau^-,
6// K_S K_L, K^+K^-, gamma gamma with precision better 0.2 %
7//
8// Mar 2009 Original BES3 code by Alexei Sibidanov
9//
10//*****************************************************************************
11
12// Header for this module:-
13#include "Mcgpj.h"
14
15// Framework Related Headers:-
16#include "HepMC/GenEvent.h"
17#include "HepMC/GenParticle.h"
18#include "HepMC/GenVertex.h"
19
20#include "BesRndmGenSvc/IBesRndmGenSvc.h"
21#include "CLHEP/Vector/LorentzVector.h"
22
23#include "GaudiKernel/SmartDataPtr.h"
24
25#include "GeneratorObject/McGenEvent.h"
26
27#include "TEPCrossPart.h"
28#include "TGGCrossPart.h"
29#include "TKcCrossPart.h"
30#include "TKinemCut.h"
31#include "TKnCrossPart.h"
32#include "TMuCrossPart.h"
33#include "TPiCrossPart.h"
34#include "TRadCor.h"
35#include "TRadGlobal.h"
36#include "TRandom3.h"
37
38#include "T3piCrossPart.h"
39#include "T4piCrossPart.h"
40#include "T5piCrossPart.h"
41#include "TDFun_o.h"
42#include "TPhoton_o.h"
43
44using namespace CLHEP;
45
52//-------------------------
53
55Mcgpj::Mcgpj( const std::string& name, ISvcLocator* pSvcLocator )
56 : Algorithm( name, pSvcLocator ) {
57 declareProperty( "Data", m_datapath = "${MCGPJROOT}/data" ); // Path to data files
58 declareProperty( "VpolFname",
59 m_vpolfname = "vpol.dat" ); // Vacuum polarization data file name
60 declareProperty( "CMEnergy", cmE = 3.097 ); // 2*Ebeam [GeV]
61 declareProperty( "Process", proc = 0 ); // process
62 declareProperty( "NRad", NRad = 20000 );
63 declareProperty( "HardPhoton", IsHardPhoton = 1 );
64 declareProperty( "NoVacPol", IsNoVacPol = 0 );
65 declareProperty( "FSR", IsFSR = 1 );
66 declareProperty( "AcolAngle", pc = 0. );
67 declareProperty( "DeltaE", de = -1. ); // [GeV]
68 declareProperty( "NTheta0", nt0 = -1. ); // [1/sqrt(gamma)]
69 declareProperty( "DeltaTheta", dt = 0.5 ); //[rad]
70 declareProperty( "DeltaPhi", dp = 0.3 ); // [rad]
71 declareProperty( "AverageTheta", at = 1.1 ); //[rad]
72 declareProperty( "ThetaDetector", td = 1.1 - 0.5 / 2 ); //[rad]
73 declareProperty( "AverageMomentum", am = 0.090 ); //[GeV/c]
74 declareProperty( "CrossMomentum", cm = 0.090 ); //[GeV/c]
75 declareProperty( "MinimumEnergy", em = 0.050 ); //[GeV]
76 declareProperty( "ThetaIntermediate", ti = 0.473 ); // [rad]
77 declareProperty( "AlphaScale", al = 1. );
78 declareProperty( "ThetaMinus", thm = -1. ); //[rad]
79 declareProperty( "ThetaPlus", thp = -1. ); //[rad]
80 declareProperty( "AbsoluteError", te = 0.05 ); // absolute error in [nb]
81 declareProperty( "RelativeError", re = 0.05 ); // realative error
82 // declareProperty("InitialSeed", Seed = 0);
83 declareProperty( "BeamSpread", spread = -1 ); // [MeV]
84 // declareProperty("PhaseShift", phase = -90);// [deg]
85 declareProperty( "Mode5pi", m_fmode5pi = 0 ); // 0 - via b1+/- pi-/+, 1 via b10 pi0
86}
87
88StatusCode Mcgpj::initialize() {
89 MsgStream log( msgSvc(), name() );
90
91 log << MSG::INFO << "Mcgpj initialize" << endmsg;
92
93 static const bool CREATEIFNOTTHERE( true );
94 StatusCode RndmStatus = service( "BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE );
95 if ( !RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc )
96 {
97 log << MSG::ERROR << " Could not initialize Random Number Service" << endmsg;
98 return RndmStatus;
99 }
100 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->GetEngine( "Mcgpj" );
101 engine->showStatus();
102
103 // GeV -> MeV
104 cmE *= 1e3;
105 de *= 1e3;
106 am *= 1e3;
107 cm *= 1e3;
108 em *= 1e3;
109
110 if ( gRandom ) delete gRandom;
111 gRandom = new TRandom3();
112 gRandom->SetSeed( engine->getSeed() );
113 // gRandom->Dump();
114
115 if ( proc < 100 )
116 {
117
118 gConst = new TConstants();
119 gGlobal = new TRadGlobal();
120 gCut = new TKinemCut();
121
122 if ( ( proc % 10 ) == 3 )
123 {
124 td = 0.025;
125 dt = 10;
126 dp = 10;
127 cm = 0;
128 am = 0;
129 }
130
131 const int MaxList = 20;
132 bool InList[MaxList];
133 for ( int j = 0; j < MaxList; j++ ) InList[j] = true;
134
135 double EBeam = 0.5 * cmE;
136
137 if ( ( EBeam < 100 || EBeam > 2500 ) && !IsNoVacPol )
138 {
139 log << MSG::ERROR << "Invalid value of beam energy:" << EBeam << endmsg;
140 return StatusCode::FAILURE;
141 }
142
143 gGlobal->Set_TotalError( te );
144
145 gGlobal->Set_RelativeError( re );
146
147 gGlobal->Set_Type( ( proc % 10 ) );
148
149 gGlobal->Set_E( EBeam );
150
151 gGlobal->Set_ThetaInt( ti );
152
153 if ( 0 > td ) gGlobal->Set_ThetaMin( at - dt / 2 );
154 else gGlobal->Set_ThetaMin( td );
155
156 if ( 0 > de )
157 {
158 if ( ( proc % 10 ) == 0 ) gGlobal->Set_dE_Abs( 0.015 * EBeam );
159 else gGlobal->Set_dE_Abs( 0.0003 * EBeam );
160 }
161 else gGlobal->Set_dE_Abs( de );
162
163 if ( 0 > nt0 )
164 {
165 if ( proc > 10 ) gGlobal->Set_Theta0_Rel( 0.0 );
166 else gGlobal->Set_Theta0_Rel( 1.5 );
167 }
168 else gGlobal->Set_Theta0_Rel( nt0 );
169
170 if ( 0 < thm )
171 {
172 gCut->ThetaMinM( thm );
173 gGlobal->Set_ThetaMin( thm );
174 }
175
176 if ( 0 < thp ) gCut->ThetaMinP( thp );
177
178 gCut->CosPsi( cos( pc ) );
179
180 gCut->DeltaTheta( dt );
181
182 gCut->AverageTheta( at );
183
184 gCut->DeltaPhi( dp );
185
186 gCut->PAverage( am );
187
188 gCut->PCross( cm );
189
190 gCut->EMin( em );
191
192 gConst->SetAlphaScale( al );
193
194 gConst->Print();
195
196 try
197 { gGlobal->Init(); } catch ( std::logic_error lge )
198 {
199 log << MSG::ERROR << lge.what() << endmsg;
200 return StatusCode::FAILURE;
201 }
202
203 gGlobal->SetDatadir( m_datapath );
204 gGlobal->SetVpolFname( m_vpolfname );
205 // gGlobal->SetIntFname("");
206
207 gGlobal->Print();
208
209 gCut->Init();
210 gCut->Print();
211
212 log << MSG::INFO << "Cross-section statistical precision will be better than "
213 << gGlobal->Get_TotalError() << " nb and " << gGlobal->Get_RelativeError() * 100 << "%"
214 << endmsg;
215
216 if ( !IsHardPhoton )
217 log << MSG::INFO << "Hard photon on big angle is not included!" << endmsg;
218
219 if ( IsNoVacPol ) log << MSG::INFO << "Vacuum polarization is not included!" << endmsg;
220
221 if ( !IsFSR ) log << MSG::INFO << "Final state radiation is not included!" << endmsg;
222
223 if ( proc > 10 ) log << MSG::INFO << "Alpha order generation only!" << endmsg;
224
225 log << std::flush;
226
227 if ( proc == 0 )
228 {
230 InList[18] = false;
231 }
232 else if ( proc == 1 || proc == 5 ) MatrixElements = new TMuCrossPart();
233 else if ( proc == 2 ) MatrixElements = new TPiCrossPart();
234 else if ( proc == 3 ) MatrixElements = new TKnCrossPart();
235 else if ( proc == 4 ) MatrixElements = new TKcCrossPart();
236 else if ( proc == 6 ) MatrixElements = new TGGCrossPart();
237 else if ( proc == 10 )
238 {
240 for ( int j = 0; j < MaxList; j++ ) InList[j] = false;
241 InList[16] = true;
242 InList[17] = true;
243 InList[18] = true;
244 }
245 else return StatusCode::FAILURE;
246
247 if ( IsNoVacPol ) MatrixElements->SetZeroVP();
248
249 if ( !IsFSR ) MatrixElements->SetNoFSR();
250
251 gRad = new TRadCor( MatrixElements );
252 gRad->SetNEvents( NRad );
253 gRad->SetPartList( InList );
254 gRad->Init();
255
256 MatrixElements->SetHardPhoton( IsHardPhoton );
257 gRad->MakeCrossSection();
258 if ( ( proc % 10 ) == 2 ) ( (TPiCrossPart*)MatrixElements )->GetFormFactor()->Print();
259
260 if ( ( proc % 10 ) == 0 )
261 {
262 fpid[0] = 11;
263 fpid[1] = -11;
264 fM = 0.51099891;
265 }
266 if ( ( proc % 10 ) == 1 )
267 {
268 fpid[0] = 13;
269 fpid[1] = -13;
270 fM = 105.658367;
271 }
272 if ( ( proc % 10 ) == 2 )
273 {
274 fpid[0] = 211;
275 fpid[1] = -211;
276 fM = 139.57018;
277 }
278 if ( ( proc % 10 ) == 3 )
279 {
280 fpid[0] = 130;
281 fpid[1] = 310;
282 fM = 497.614;
283 }
284 if ( ( proc % 10 ) == 4 )
285 {
286 fpid[0] = 321;
287 fpid[1] = -321;
288 fM = 493.677;
289 }
290 if ( ( proc % 10 ) == 5 )
291 {
292 fpid[0] = 15;
293 fpid[1] = -15;
294 fM = 1776.84;
295 }
296 if ( ( proc % 10 ) == 6 )
297 {
298 fpid[0] = 22;
299 fpid[1] = 22;
300 fM = 0;
301 }
302 }
303 else
304 {
305 double EBeam = 0.5 * cmE;
306 if ( 0 > de ) de = 0.005 * EBeam;
307
308 if ( 0 > nt0 ) nt0 = 1;
309
310 if ( proc == 100 )
311 {
312 CS = new T3piCrossPart( EBeam, de, nt0 );
313 if ( spread > 0 ) CS->SetBeamSpread( spread );
314 }
315 else if ( proc == 101 )
316 {
317 CS = new T4piCrossPart( EBeam, de, nt0 );
318 if ( spread > 0 ) CS->SetBeamSpread( spread );
319 }
320 else if ( proc == 102 )
321 {
322 CS = new T5piCrossPart( EBeam, de, nt0, m_fmode5pi );
323 if ( spread > 0 ) CS->SetBeamSpread( spread );
324 }
325 CS->MakeParts( te );
326 }
327
328 log << MSG::INFO << "Mcgpj initialize finished" << endmsg;
329
330 return StatusCode::SUCCESS;
331}
332
333StatusCode Mcgpj::execute() {
334 MsgStream log( msgSvc(), name() );
335 log << MSG::INFO << "Mcgpj executing" << endmsg;
336 log << MSG::WARNING << "execute start" << endmsg;
337
338 // Fill event information
339 GenEvent* evt = new GenEvent( 1, 1 );
340
341 GenVertex* prod_vtx = new GenVertex();
342
343 evt->add_vertex( prod_vtx );
344
345 // incoming beam e+
346 GenParticle* p =
347 new GenParticle( HepLorentzVector( 0, 0, 0.5 * cmE * 1e-3, 0.5 * cmE * 1e-3 ), -11, 3 );
348 p->suggest_barcode( 1 );
349 prod_vtx->add_particle_in( p );
350
351 // incoming beam e-
352 p = new GenParticle( HepLorentzVector( 0, 0, 0.5 * cmE * 1e-3, 0.5 * cmE * 1e-3 ), 11, 3 );
353 p->suggest_barcode( 2 );
354 prod_vtx->add_particle_in( p );
355
356 int npart = 2;
357 if ( proc < 100 )
358 {
359 double mom[4 * 6];
360 int np;
361 gRad->MakeEvent( mom, np );
362
363 // final particle 1
364 for ( int i = 0; i < np; i++ )
365 {
366 double ptot = mom[i * 4 + 3];
367 double px = ptot * mom[i * 4 + 0];
368 double py = ptot * mom[i * 4 + 1];
369 double pz = ptot * mom[i * 4 + 2];
370 double mass = 0;
371 int pid = 22;
372 if ( i < 2 )
373 {
374 pid = fpid[i];
375 mass = fM;
376 }
377 double etot = sqrt( ptot * ptot + mass * mass * 1e-6 );
378 p = new GenParticle( HepLorentzVector( px, py, pz, etot ), pid, 1 );
379 p->suggest_barcode( i + 3 );
380 prod_vtx->add_particle_out( p );
381 npart++;
382 }
383 }
384 else
385 {
386 int ipart = CS->GenUnWeightedEvent();
387 size_t nmax = CS->GetNfinal() + ( ( ipart == 0 ) ? 1 : 2 );
388 for ( size_t i = 0; i < nmax; i++ )
389 {
390 TLorentzVector& q = *( CS->GetParticles()[i] );
391 int pid = CS->GetPid( i );
392 p = new GenParticle(
393 HepLorentzVector( q.X() * 1e-3, q.Y() * 1e-3, q.Z() * 1e-3, q.T() * 1e-3 ), pid, 1 );
394 p->suggest_barcode( i + 3 );
395 prod_vtx->add_particle_out( p );
396 npart++;
397 }
398 }
399
400 if ( log.level() < MSG::INFO ) { evt->print(); }
401
402 // Check if the McCollection already exists
403 SmartDataPtr<McGenEventCol> anMcCol( eventSvc(), "/Event/Gen" );
404 if ( anMcCol != 0 )
405 {
406 // Add event to existing collection
407 log << MSG::WARNING << "add event" << endmsg;
408 MsgStream log( msgSvc(), name() );
409 log << MSG::INFO << "Add McGenEvent to existing collection" << endmsg;
410 McGenEvent* mcEvent = new McGenEvent( evt );
411 anMcCol->push_back( mcEvent );
412 }
413 else
414 {
415 // Create Collection and add to the transient store
416 log << MSG::WARNING << "create collection" << endmsg;
417 McGenEventCol* mcColl = new McGenEventCol;
418 McGenEvent* mcEvent = new McGenEvent( evt );
419 mcColl->push_back( mcEvent );
420 StatusCode sc = eventSvc()->registerObject( "/Event/Gen", mcColl );
421 if ( sc != StatusCode::SUCCESS )
422 {
423 log << MSG::ERROR << "Could not register McGenEvent" << endmsg;
424 delete mcColl;
425 delete evt;
426 delete mcEvent;
427 return StatusCode::FAILURE;
428 }
429 else
430 {
431 log << MSG::INFO << "McGenEventCol created and " << npart
432 << " particles stored in McGenEvent" << endmsg;
433 }
434 }
435
436 log << MSG::WARNING << "execute end" << endmsg;
437 return StatusCode::SUCCESS;
438}
439
440StatusCode Mcgpj::finalize() {
441 MsgStream log( msgSvc(), name() );
442
443 delete gRad;
444 delete MatrixElements;
445 delete gRandom;
446 delete gConst;
447 delete gGlobal;
448 delete gCut;
449
450 log << MSG::INFO << "Mcgpj finalized" << endmsg;
451
452 return StatusCode::SUCCESS;
453}
DECLARE_COMPONENT(BesBdkRc)
const double EBeam
double mass
Double_t etot
ObjectVector< McGenEvent > McGenEventCol
****INTEGER imax DOUBLE PRECISION m_pi *DOUBLE PRECISION m_amfin DOUBLE PRECISION m_Chfin DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_sinw2 DOUBLE PRECISION m_GFermi DOUBLE PRECISION m_MfinMin DOUBLE PRECISION m_ta2 INTEGER m_out INTEGER m_KeyFSR INTEGER m_KeyQCD *COMMON c_Semalib $ !copy of input $ !CMS energy $ !beam mass $ !final mass $ !beam charge $ !final charge $ !smallest final mass $ !Z mass $ !Z width $ !EW mixing angle $ !Gmu Fermi $ alphaQED at q
Definition KKsem.h:33
TRadCor * gRad
Definition Mcgpj.cxx:46
TVCrossPart * MatrixElements
Definition Mcgpj.cxx:50
TCrossPart * CS
Definition Mcgpj.cxx:51
IMessageSvc * msgSvc()
TConstants * gConst
Definition Mcgpj.cxx:49
TKinemCut * gCut
Definition Mcgpj.cxx:48
TRadGlobal * gGlobal
Definition Mcgpj.cxx:47
Definition Mcgpj.h:20
StatusCode initialize()
Definition Mcgpj.cxx:88
StatusCode finalize()
Definition Mcgpj.cxx:440
StatusCode execute()
Definition Mcgpj.cxx:333
Mcgpj(const std::string &name, ISvcLocator *pSvcLocator)
Definition Mcgpj.cxx:55