ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/Validation/src/GenRelValMod.cc
Revision: 1.5
Committed: Fri Nov 21 20:12:26 2008 UTC (16 years, 5 months ago) by loizides
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_008pre2, Mit_008pre1, Mit_006b, Mit_006a
Changes since 1.4: +22 -9 lines
Log Message:
Have switch to print to screen.

File Contents

# User Rev Content
1 loizides 1.5 // $Id: GenRelValMod.cc,v 1.4 2008/07/25 12:41:41 loizides Exp $
2 loizides 1.1
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 loizides 1.4 fMCPartName(Names::gkMCPartBrn),
14 loizides 1.5 fFileName("macro_output.txt"),
15     fPrint(1),
16     fWrite(0),
17 loizides 1.1 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 loizides 1.4 ReqBranch(fMCPartName,fParticles);
31 loizides 1.1
32 loizides 1.5 if (fWrite) {
33     ofile = new std::ofstream(fFileName);
34     if (ofile->bad()) {
35     SendError(kAbortAnalysis, "SlaveBegin", "Can not open output file.");
36     }
37 loizides 1.1 }
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 loizides 1.4 LoadBranch(fMCPartName);
46 loizides 1.1
47     for (UInt_t i=0; i<fParticles->GetEntries(); ++i) {
48 loizides 1.4 const MCParticle *p = fParticles->At(i);
49 loizides 1.5 if (!p->IsGenerated()) continue;
50    
51 loizides 1.1 int I = i+1; // Particle index (starts at 1)
52 loizides 1.3 int KF = p->PdgId(); // Pdg code
53 loizides 1.1 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 loizides 1.4 const MCParticle *mother = p->Mother();
60 loizides 1.1 if(mother) {
61     for (UInt_t j=0; j<fParticles->GetEntries(); ++j) {
62 loizides 1.5 const MCParticle *test = fParticles->At(j);
63 loizides 1.1 if(test==mother) {
64     mind=j+1;
65 loizides 1.2 // hack to overcome ambiguity
66     if(mind==5 && I==7 || I==8) mind=0;
67 loizides 1.1 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 loizides 1.5 if (fPrint) {
75     std::cout << buf;
76     }
77     if (fWrite)
78     *ofile<<buf;
79 loizides 1.1 }
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 loizides 1.5 if (fWrite) {
89     ofile->close();
90     delete ofile;
91     ofile=0;
92     }
93 loizides 1.1 }