ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/Validation/src/GenRelValMod.cc
Revision: 1.6
Committed: Mon Mar 23 22:15:16 2009 UTC (16 years, 1 month ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_009a, Mit_009, Mit_008
Changes since 1.5: +2 -2 lines
Log Message:
Cosmetics

File Contents

# Content
1 // $Id: GenRelValMod.cc,v 1.5 2008/11/21 20:12:26 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 fMCPartName(Names::gkMCPartBrn),
14 fFileName("macro_output.txt"),
15 fPrint(1),
16 fWrite(0),
17 fParticles(0),
18 ofile(0)
19 {
20 // Constructor.
21 }
22
23 //--------------------------------------------------------------------------------------------------
24 void GenRelValMod::SlaveBegin()
25 {
26 // Run startup code on the computer (slave) doing the actual analysis. Here, we typically
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(fMCPartName,fParticles);
31
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
40 //--------------------------------------------------------------------------------------------------
41 void GenRelValMod::Process()
42 {
43 // Process entries of the tree. For this module, we just load the branch and fill the histograms.
44
45 LoadBranch(fMCPartName);
46
47 for (UInt_t i=0; i<fParticles->GetEntries(); ++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
54 double p_y = p->Py(); if (fabs(p_y)<0.0005) p_y = 0.; // first 3 digits after the
55 double p_z = p->Pz(); if (fabs(p_z)<0.0005) p_z = 0.; // decimal.
56 double E = p->E(); if (fabs(E )<0.0005) E = 0.; // Energy
57 int mind=0;
58 if(p->HasMother()) {
59 const MCParticle *mother = p->Mother();
60 if(mother) {
61 for (UInt_t j=0; j<fParticles->GetEntries(); ++j) {
62 const MCParticle *test = fParticles->At(j);
63 if(test==mother) {
64 mind=j+1;
65 // hack to overcome ambiguity
66 if(mind==5 && I==7 || I==8) mind=0;
67 break;
68 }
69 }
70 }
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 if (fPrint) {
75 std::cout << buf;
76 }
77 if (fWrite)
78 *ofile<<buf;
79 }
80 }
81
82 //--------------------------------------------------------------------------------------------------
83 void GenRelValMod::SlaveTerminate()
84 {
85 // Run finishing code on the computer (slave) that did the analysis. For this module, we close
86 // the text file.
87
88 if (fWrite) {
89 ofile->close();
90 delete ofile;
91 ofile=0;
92 }
93 }