1 |
// $Id: GenRelValMod.cc,v 1.6 2009/03/23 22:15:16 loizides Exp $
|
2 |
|
3 |
#include "MitAna/Validation/interface/GenRelValMod.h"
|
4 |
#include "MitAna/DataTree/interface/MCParticleCol.h"
|
5 |
#include "MitAna/DataTree/interface/Names.h"
|
6 |
|
7 |
using namespace mithep;
|
8 |
|
9 |
ClassImp(mithep::GenRelValMod)
|
10 |
|
11 |
//--------------------------------------------------------------------------------------------------
|
12 |
GenRelValMod::GenRelValMod(const char *name, const char *title) :
|
13 |
BaseMod(name,title),
|
14 |
fMCPartName(Names::gkMCPartBrn),
|
15 |
fFileName("macro_output.txt"),
|
16 |
fPrint(1),
|
17 |
fWrite(0),
|
18 |
fParticles(0),
|
19 |
fOFile(0)
|
20 |
{
|
21 |
// Constructor.
|
22 |
}
|
23 |
|
24 |
//--------------------------------------------------------------------------------------------------
|
25 |
void GenRelValMod::SlaveBegin()
|
26 |
{
|
27 |
// Run startup code on the computer (slave) doing the actual analysis. Here, we typically
|
28 |
// initialize histograms and other analysis objects and request branches. For this module, we
|
29 |
// request a branch of the MitTree and open a text file for writing.
|
30 |
|
31 |
ReqBranch(fMCPartName,fParticles);
|
32 |
|
33 |
if (fWrite) {
|
34 |
fOFile = new std::ofstream(fFileName);
|
35 |
if (fOFile->bad()) {
|
36 |
SendError(kAbortAnalysis, "SlaveBegin", "Cannot open output file.");
|
37 |
}
|
38 |
}
|
39 |
}
|
40 |
|
41 |
//--------------------------------------------------------------------------------------------------
|
42 |
void GenRelValMod::Process()
|
43 |
{
|
44 |
// Process entries of the tree. For this module, we just load the branch and fill the histograms.
|
45 |
|
46 |
LoadBranch(fMCPartName);
|
47 |
|
48 |
for (UInt_t i=0; i<fParticles->GetEntries(); ++i) {
|
49 |
const MCParticle *p = fParticles->At(i);
|
50 |
if (!p->IsGenerated()) continue;
|
51 |
|
52 |
int I = i+1; // Particle index (starts at 1)
|
53 |
int KF = p->PdgId(); // Pdg code
|
54 |
double p_x = p->Px(); if (fabs(p_x)<0.0005) p_x = 0.; // Momenta. We only compare the
|
55 |
double p_y = p->Py(); if (fabs(p_y)<0.0005) p_y = 0.; // first 3 digits after the
|
56 |
double p_z = p->Pz(); if (fabs(p_z)<0.0005) p_z = 0.; // decimal.
|
57 |
double E = p->E(); if (fabs(E )<0.0005) E = 0.; // Energy
|
58 |
int mind=0;
|
59 |
if(p->HasMother()) {
|
60 |
const MCParticle *mother = p->Mother();
|
61 |
if(mother) {
|
62 |
for (UInt_t j=0; j<fParticles->GetEntries(); ++j) {
|
63 |
const MCParticle *test = fParticles->At(j);
|
64 |
if(test==mother) {
|
65 |
mind=j+1;
|
66 |
// hack to overcome ambiguity
|
67 |
if(mind==5 && I==7 || I==8) mind=0;
|
68 |
break;
|
69 |
}
|
70 |
}
|
71 |
}
|
72 |
}
|
73 |
char buf[1024];
|
74 |
sprintf(buf,"%5i%5i%5i%9.3f%9.3f%9.3f%9.3f\n",I,KF,mind,p_x,p_y,p_z,E);
|
75 |
if (fPrint) {
|
76 |
std::cout << buf;
|
77 |
}
|
78 |
if (fWrite)
|
79 |
*fOFile<<buf;
|
80 |
}
|
81 |
}
|
82 |
|
83 |
//--------------------------------------------------------------------------------------------------
|
84 |
void GenRelValMod::SlaveTerminate()
|
85 |
{
|
86 |
// Run finishing code on the computer (slave) that did the analysis. For this module, we close
|
87 |
// the text file.
|
88 |
|
89 |
if (fWrite) {
|
90 |
fOFile->close();
|
91 |
delete fOFile;
|
92 |
fOFile=0;
|
93 |
}
|
94 |
}
|