ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitAna/Validation/src/GenRelValMod.cc
(Generate patch)

Comparing UserCode/MitAna/Validation/src/GenRelValMod.cc (file contents):
Revision 1.3 by loizides, Mon Jul 14 20:59:56 2008 UTC vs.
Revision 1.7 by loizides, Mon Jun 15 15:00:18 2009 UTC

# Line 1 | Line 1
1   // $Id$
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;
# Line 10 | Line 11 | ClassImp(mithep::GenRelValMod)
11   //--------------------------------------------------------------------------------------------------
12   GenRelValMod::GenRelValMod(const char *name, const char *title) :
13    BaseMod(name,title),
14 <  fGenPartName(Names::gkGenPartBrn),
14 >  fMCPartName(Names::gkMCPartBrn),
15 >  fFileName("macro_output.txt"),
16 >  fPrint(1),
17 >  fWrite(0),
18    fParticles(0),
19 <  ofile(0)
19 >  fOFile(0)
20   {
21    // Constructor.
22   }
# Line 24 | Line 28 | void GenRelValMod::SlaveBegin()
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(fGenPartName,fParticles);
31 >  ReqBranch(fMCPartName,fParticles);
32  
33 <  ofile = new std::ofstream("macro_output.txt");
34 <  if (ofile->bad()) {
35 <    SendError(kAbortAnalysis, "SlaveBegin", "Can not open output file.");
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  
# Line 37 | Line 43 | 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);
46 >  LoadBranch(fMCPartName);
47  
48    for (UInt_t i=0; i<fParticles->GetEntries(); ++i) {
49 <    GenParticle* p = fParticles->At(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
# Line 49 | Line 57 | void GenRelValMod::Process()
57      double E   = p->E();  if (fabs(E  )<0.0005) E   = 0.;    // Energy
58      int mind=0;
59      if(p->HasMother()) {
60 <      const GenParticle *mother = p->Mother();
60 >      const MCParticle *mother = p->Mother();
61        if(mother) {
62          for (UInt_t j=0; j<fParticles->GetEntries(); ++j) {
63 <          const  GenParticle *test = fParticles->At(j);
63 >          const MCParticle *test = fParticles->At(j);
64            if(test==mother) {
65              mind=j+1;
66              // hack to overcome ambiguity
# Line 64 | Line 72 | void GenRelValMod::Process()
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 <    *ofile<<buf;
75 >    if (fPrint) {
76 >      std::cout << buf;
77 >    }
78 >    if (fWrite)
79 >      *fOFile<<buf;
80    }
81   }
82  
# Line 74 | Line 86 | void GenRelValMod::SlaveTerminate()
86    // Run finishing code on the computer (slave) that did the analysis. For this module, we close
87    // the text file.
88  
89 <  ofile->close();
90 <  delete ofile;
91 <  ofile=0;
89 >  if (fWrite) {
90 >    fOFile->close();
91 >    delete fOFile;
92 >    fOFile=0;
93 >  }
94   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines