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