Fork me on GitHub

Changes between Version 5 and Version 6 of WorkBook/ModuleSystem


Ignore:
Timestamp:
Jun 22, 2012, 8:40:52 AM (12 years ago)
Author:
Pavel Demin
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WorkBook/ModuleSystem

    v5 v6  
    1111Additional classes {{{ExRootTask}}} and {{{ExRootModule}}} has been developed to provide frequently used services for Delphes. All Delphes' modules inherit from {{{ExRootModule}}}.
    1212
     13Here is an example of a module declartion:
     14
    1315{{{
    1416#ifndef ExampleModule_h
     
    1719#include "ExRootAnalysis/ExRootModule.h"
    1820
     21#include <deque>
     22
    1923class TObjArray;
     24class TFormula;
    2025
    2126class ExampleModule: public ExRootModule
     
    3237private:
    3338
     39  Int_t fIntParam;
     40  Double_t fDoubleParam;
     41 
     42  std::deque <Double_t> fArrayParam;
     43 
     44  TFormula *fFormula; //!
     45
    3446  TIterator *fItInputArray; //!
    3547
     
    4355#endif
    4456}}}
     57
     58and here is its implementation:
     59
     60{{{
     61
     62#include "modules/ExampleModule.h"
     63
     64#include "ExRootAnalysis/ExRootResult.h"
     65#include "ExRootAnalysis/ExRootClasses.h"
     66
     67#include "ExRootAnalysis/ExRootFilter.h"
     68#include "ExRootAnalysis/ExRootClassifier.h"
     69
     70#include "ExRootAnalysis/ExRootFactory.h"
     71#include "ExRootAnalysis/ExRootCandidate.h"
     72
     73#include "TMath.h"
     74#include "TRandom.h"
     75#include "TString.h"
     76#include "TFormula.h"
     77#include "TLorentzVector.h"
     78#include "TDatabasePDG.h"
     79#include "TClonesArray.h"
     80
     81#include <iostream>
     82#include <stdexcept>
     83#include <sstream>
     84#include <deque>
     85
     86using namespace std;
     87
     88//------------------------------------------------------------------------------
     89
     90ExampleModule::ExampleModule() :
     91  fFormula(0), fItInputArray(0)
     92{
     93  fFormula = new TFormula;
     94}
     95
     96//------------------------------------------------------------------------------
     97
     98ExampleModule::~ExampleModule()
     99{
     100  if(fFormula) delete fFormula;
     101}
     102
     103//------------------------------------------------------------------------------
     104
     105void ExampleModule::Init()
     106{
     107  fIntParam = GetInt("IntParam", 10);
     108
     109  fDoubleParam = GetDouble("DoubleParam", 1.0);
     110
     111  fFormula->Compile(GetString("EfficiencyFormula", "0.4"));
     112
     113  ExRootConfParam param = GetParam("ArrayParam");
     114  Long_t i, size;
     115  fArrayParam.clear();
     116
     117  size = param.GetSize();
     118  for(i = 0; i < size; ++i)
     119  {
     120    fArrayParam.push_back(param[i].GetDouble());
     121  }
     122 
     123  // import input array(s)
     124
     125  fInputArray = ImportArray(GetString("InputArray", "FastJetFinder/jets"));
     126  fItInputArray = fInputArray->MakeIterator();
     127
     128  // create output array(s)
     129
     130  fOutputArray = ExportArray(GetString("OutputArray", "jets"));
     131
     132}
     133
     134//------------------------------------------------------------------------------
     135
     136void ExampleModule::Finish()
     137{
     138  if(fItInputArray) delete fItInputArray;
     139}
     140
     141//------------------------------------------------------------------------------
     142
     143void ExampleModule::Process()
     144{
     145  ExRootCandidate *candidate;
     146  TLorentzVector candidatePosition, candidateMomentum;
     147
     148  // loop over all input candidates
     149  fItInputArray->Reset();
     150  while((candidate = static_cast<ExRootCandidate*>(fItInputArray->Next())))
     151  {
     152    candidatePosition = candidate->GetPosition();
     153    candidateMomentum = candidate->GetMomentum();
     154
     155    // apply an efficency formula
     156    if(gRandom->Uniform() < fFormula->Eval(candidatePosition.Eta(), candidateMomentum.Pt()))
     157    {
     158      fOutputArray->Add(candidate);
     159    }
     160  }
     161}
     162}}}