ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/Validation/src/GenRelValMod.cc
Revision: 1.8
Committed: Wed May 12 19:03:39 2010 UTC (14 years, 11 months ago) by ceballos
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_032, Mit_031, Mit_025c_branch2, Mit_025c_branch1, Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_025c_branch0, Mit_028, Mit_027a, Mit_027, Mit_026, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, Mit_014a, Mit_014, Mit_014pre3, HEAD
Branch point for: Mit_025c_branch
Changes since 1.7: +2 -2 lines
Log Message:
small if bug

File Contents

# Content
1 // $Id: GenRelValMod.cc,v 1.7 2009/06/15 15:00:18 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 }