10 |
|
//-------------------------------------------------------------------------------------------------- |
11 |
|
GenRelValMod::GenRelValMod(const char *name, const char *title) : |
12 |
|
BaseMod(name,title), |
13 |
< |
fGenPartName(Names::gkGenPartBrn), |
13 |
> |
fMCPartName(Names::gkMCPartBrn), |
14 |
> |
fFileName("macro_output.txt"), |
15 |
> |
fPrint(1), |
16 |
> |
fWrite(0), |
17 |
|
fParticles(0), |
18 |
|
ofile(0) |
19 |
|
{ |
27 |
|
// initialize histograms and other analysis objects and request branches. For this module, we |
28 |
|
// request a branch of the MitTree and open a text file for writing. |
29 |
|
|
30 |
< |
ReqBranch(fGenPartName,fParticles); |
30 |
> |
ReqBranch(fMCPartName,fParticles); |
31 |
|
|
32 |
< |
ofile = new std::ofstream("macro_output.txt"); |
33 |
< |
if (ofile->bad()) { |
34 |
< |
SendError(kAbortAnalysis, "SlaveBegin", "Can not open output file."); |
32 |
> |
if (fWrite) { |
33 |
> |
ofile = new std::ofstream(fFileName); |
34 |
> |
if (ofile->bad()) { |
35 |
> |
SendError(kAbortAnalysis, "SlaveBegin", "Cannot open output file."); |
36 |
> |
} |
37 |
|
} |
38 |
|
} |
39 |
|
|
42 |
|
{ |
43 |
|
// Process entries of the tree. For this module, we just load the branch and fill the histograms. |
44 |
|
|
45 |
< |
LoadBranch(fGenPartName); |
45 |
> |
LoadBranch(fMCPartName); |
46 |
|
|
47 |
|
for (UInt_t i=0; i<fParticles->GetEntries(); ++i) { |
48 |
< |
GenParticle* p = fParticles->At(i); |
48 |
> |
const MCParticle *p = fParticles->At(i); |
49 |
> |
if (!p->IsGenerated()) continue; |
50 |
> |
|
51 |
|
int I = i+1; // Particle index (starts at 1) |
52 |
|
int KF = p->PdgId(); // Pdg code |
53 |
|
double p_x = p->Px(); if (fabs(p_x)<0.0005) p_x = 0.; // Momenta. We only compare the |
56 |
|
double E = p->E(); if (fabs(E )<0.0005) E = 0.; // Energy |
57 |
|
int mind=0; |
58 |
|
if(p->HasMother()) { |
59 |
< |
const GenParticle *mother = p->Mother(); |
59 |
> |
const MCParticle *mother = p->Mother(); |
60 |
|
if(mother) { |
61 |
|
for (UInt_t j=0; j<fParticles->GetEntries(); ++j) { |
62 |
< |
const GenParticle *test = fParticles->At(j); |
62 |
> |
const MCParticle *test = fParticles->At(j); |
63 |
|
if(test==mother) { |
64 |
|
mind=j+1; |
65 |
|
// hack to overcome ambiguity |
71 |
|
} |
72 |
|
char buf[1024]; |
73 |
|
sprintf(buf,"%5i%5i%5i%9.3f%9.3f%9.3f%9.3f\n",I,KF,mind,p_x,p_y,p_z,E); |
74 |
< |
*ofile<<buf; |
74 |
> |
if (fPrint) { |
75 |
> |
std::cout << buf; |
76 |
> |
} |
77 |
> |
if (fWrite) |
78 |
> |
*ofile<<buf; |
79 |
|
} |
80 |
|
} |
81 |
|
|
85 |
|
// Run finishing code on the computer (slave) that did the analysis. For this module, we close |
86 |
|
// the text file. |
87 |
|
|
88 |
< |
ofile->close(); |
89 |
< |
delete ofile; |
90 |
< |
ofile=0; |
88 |
> |
if (fWrite) { |
89 |
> |
ofile->close(); |
90 |
> |
delete ofile; |
91 |
> |
ofile=0; |
92 |
> |
} |
93 |
|
} |