1 |
loizides |
1.7 |
// $Id: GenRelValMod.cc,v 1.6 2009/03/23 22:15:16 loizides Exp $
|
2 |
loizides |
1.1 |
|
3 |
|
|
#include "MitAna/Validation/interface/GenRelValMod.h"
|
4 |
loizides |
1.7 |
#include "MitAna/DataTree/interface/MCParticleCol.h"
|
5 |
loizides |
1.1 |
#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 |
loizides |
1.4 |
fMCPartName(Names::gkMCPartBrn),
|
15 |
loizides |
1.5 |
fFileName("macro_output.txt"),
|
16 |
|
|
fPrint(1),
|
17 |
|
|
fWrite(0),
|
18 |
loizides |
1.1 |
fParticles(0),
|
19 |
loizides |
1.7 |
fOFile(0)
|
20 |
loizides |
1.1 |
{
|
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 |
loizides |
1.4 |
ReqBranch(fMCPartName,fParticles);
|
32 |
loizides |
1.1 |
|
33 |
loizides |
1.5 |
if (fWrite) {
|
34 |
loizides |
1.7 |
fOFile = new std::ofstream(fFileName);
|
35 |
|
|
if (fOFile->bad()) {
|
36 |
loizides |
1.6 |
SendError(kAbortAnalysis, "SlaveBegin", "Cannot open output file.");
|
37 |
loizides |
1.5 |
}
|
38 |
loizides |
1.1 |
}
|
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 |
loizides |
1.4 |
LoadBranch(fMCPartName);
|
47 |
loizides |
1.1 |
|
48 |
|
|
for (UInt_t i=0; i<fParticles->GetEntries(); ++i) {
|
49 |
loizides |
1.4 |
const MCParticle *p = fParticles->At(i);
|
50 |
loizides |
1.5 |
if (!p->IsGenerated()) continue;
|
51 |
|
|
|
52 |
loizides |
1.1 |
int I = i+1; // Particle index (starts at 1)
|
53 |
loizides |
1.3 |
int KF = p->PdgId(); // Pdg code
|
54 |
loizides |
1.1 |
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 |
loizides |
1.4 |
const MCParticle *mother = p->Mother();
|
61 |
loizides |
1.1 |
if(mother) {
|
62 |
|
|
for (UInt_t j=0; j<fParticles->GetEntries(); ++j) {
|
63 |
loizides |
1.5 |
const MCParticle *test = fParticles->At(j);
|
64 |
loizides |
1.1 |
if(test==mother) {
|
65 |
|
|
mind=j+1;
|
66 |
loizides |
1.2 |
// hack to overcome ambiguity
|
67 |
|
|
if(mind==5 && I==7 || I==8) mind=0;
|
68 |
loizides |
1.1 |
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 |
loizides |
1.5 |
if (fPrint) {
|
76 |
|
|
std::cout << buf;
|
77 |
|
|
}
|
78 |
|
|
if (fWrite)
|
79 |
loizides |
1.7 |
*fOFile<<buf;
|
80 |
loizides |
1.1 |
}
|
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 |
loizides |
1.5 |
if (fWrite) {
|
90 |
loizides |
1.7 |
fOFile->close();
|
91 |
|
|
delete fOFile;
|
92 |
|
|
fOFile=0;
|
93 |
loizides |
1.5 |
}
|
94 |
loizides |
1.1 |
}
|