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

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