ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/Validation/src/GenRelValMod.cc
Revision: 1.3
Committed: Mon Jul 14 20:59:56 2008 UTC (16 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
Changes since 1.2: +3 -3 lines
Log Message:
Adapt to new getters.

File Contents

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