ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/Validation/src/GenRelValMod.cc
Revision: 1.1
Committed: Thu Jul 10 14:56:27 2008 UTC (16 years, 10 months ago) by loizides
Content type: text/plain
Branch: MAIN
Log Message:
Added simple genparticle relval module

File Contents

# Content
1 // $Id:$
2
3 #include "MitAna/Validation/interface/GenRelValMod.h"
4
5 #include "MitAna/DataTree/interface/Names.h"
6 //#include <stdio.h>
7 //#include <iostream>
8 //#include <fstream>
9
10 using namespace mithep;
11
12 ClassImp(mithep::GenRelValMod)
13
14 //--------------------------------------------------------------------------------------------------
15 GenRelValMod::GenRelValMod(const char *name, const char *title) :
16 BaseMod(name,title),
17 fGenPartName(Names::gkGenPartBrn),
18 fParticles(0),
19 ofile(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 // Request the branches
32 ReqBranch(fGenPartName,fParticles);
33
34 // Open file for writing
35 ofile = new std::ofstream("macro_output.txt");
36 if (ofile->bad()) {
37 std::cout<<"Problem opening output file\n";
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(fGenPartName);
47
48 for (UInt_t i=0; i<fParticles->GetEntries(); ++i) {
49 GenParticle* p = fParticles->At(i);
50 int I = i+1; // Particle index (starts at 1)
51 int KF = p->GetPdgId(); // Pdg code
52 double p_x = p->Px(); if (fabs(p_x)<0.0005) p_x = 0.; // Momenta. We only compare the
53 double p_y = p->Py(); if (fabs(p_y)<0.0005) p_y = 0.; // first 3 digits after the
54 double p_z = p->Pz(); if (fabs(p_z)<0.0005) p_z = 0.; // decimal.
55 double E = p->E(); if (fabs(E )<0.0005) E = 0.; // Energy
56 int mind=0;
57 if(p->HasMother()) {
58 const GenParticle *mother = p->GetMother();
59 if(mother) {
60 for (UInt_t j=0; j<fParticles->GetEntries(); ++j) {
61 const GenParticle *test = fParticles->At(j);
62 if(test==mother) {
63 mind=j+1;
64 break;
65 }
66 }
67 }
68 }
69 char buf[1024];
70 sprintf(buf,"%5i%5i%5i%9.3f%9.3f%9.3f%9.3f\n",I,KF,mind,p_x,p_y,p_z,E);
71 *ofile<<buf;
72 }
73 }
74
75 //--------------------------------------------------------------------------------------------------
76 void GenRelValMod::SlaveTerminate()
77 {
78 // Run finishing code on the computer (slave) that did the analysis. For this module, we close
79 // the text file.
80
81 ofile->close();
82 delete ofile;
83 ofile=0;
84 }