Fork me on GitHub

Version 6 (modified by Pavel Demin, 12 years ago) ( diff )

--

Delphes' module system is inspired by the 'Folders and Tasks' chapter from the ROOT Users Guide and it's based on the TTask and TFolder classes.

http://root.cern.ch/download/doc/ROOTUsersGuideHTML/ch10.html

All Delphes' modules consume and produce TObjArrays of ExRootCandidates. Every Delphes' module has a corresponding TFolder that is used to store TObjArrays produced by this module. Any Delphes' module can access TObjArrays produced by other Delphes' module using ImportArray("ModuleInstanceName/arrayName") method.

The contents of all Delphes' TFolders and TObjArrays is browsable. All the modules are accessible from the '/Delphes/Delphes' folder and all the TObjArrays are accessible from the '/Delphes/Export' folder.

No image "delphes_folders.png" attached to WorkBook/ModuleSystem

Additional classes ExRootTask and ExRootModule has been developed to provide frequently used services for Delphes. All Delphes' modules inherit from ExRootModule.

Here is an example of a module declartion:

#ifndef ExampleModule_h
#define ExampleModule_h

#include "ExRootAnalysis/ExRootModule.h"

#include <deque>

class TObjArray;
class TFormula;

class ExampleModule: public ExRootModule
{
public:

  ExampleModule();
  ~ExampleModule();

  void Init();
  void Process();
  void Finish();

private:

  Int_t fIntParam;
  Double_t fDoubleParam;
  
  std::deque <Double_t> fArrayParam;
  
  TFormula *fFormula; //!

  TIterator *fItInputArray; //!

  const TObjArray *fInputArray; //!

  TObjArray *fOutputArray; //!

  ClassDef(ExampleModule, 1)
};

#endif

and here is its implementation:

#include "modules/ExampleModule.h"

#include "ExRootAnalysis/ExRootResult.h"
#include "ExRootAnalysis/ExRootClasses.h"

#include "ExRootAnalysis/ExRootFilter.h"
#include "ExRootAnalysis/ExRootClassifier.h"

#include "ExRootAnalysis/ExRootFactory.h"
#include "ExRootAnalysis/ExRootCandidate.h"

#include "TMath.h"
#include "TRandom.h"
#include "TString.h"
#include "TFormula.h"
#include "TLorentzVector.h"
#include "TDatabasePDG.h"
#include "TClonesArray.h"

#include <iostream>
#include <stdexcept>
#include <sstream>
#include <deque>

using namespace std;

//------------------------------------------------------------------------------

ExampleModule::ExampleModule() :
  fFormula(0), fItInputArray(0)
{
  fFormula = new TFormula;
}

//------------------------------------------------------------------------------

ExampleModule::~ExampleModule()
{
  if(fFormula) delete fFormula;
}

//------------------------------------------------------------------------------

void ExampleModule::Init()
{
  fIntParam = GetInt("IntParam", 10);

  fDoubleParam = GetDouble("DoubleParam", 1.0);

  fFormula->Compile(GetString("EfficiencyFormula", "0.4"));

  ExRootConfParam param = GetParam("ArrayParam");
  Long_t i, size;
  fArrayParam.clear();

  size = param.GetSize();
  for(i = 0; i < size; ++i)
  {
    fArrayParam.push_back(param[i].GetDouble());
  }
  
  // import input array(s)

  fInputArray = ImportArray(GetString("InputArray", "FastJetFinder/jets"));
  fItInputArray = fInputArray->MakeIterator();

  // create output array(s)

  fOutputArray = ExportArray(GetString("OutputArray", "jets"));

}

//------------------------------------------------------------------------------

void ExampleModule::Finish()
{
  if(fItInputArray) delete fItInputArray;
}

//------------------------------------------------------------------------------

void ExampleModule::Process()
{
  ExRootCandidate *candidate;
  TLorentzVector candidatePosition, candidateMomentum;

  // loop over all input candidates
  fItInputArray->Reset();
  while((candidate = static_cast<ExRootCandidate*>(fItInputArray->Next())))
  {
    candidatePosition = candidate->GetPosition();
    candidateMomentum = candidate->GetMomentum();

    // apply an efficency formula
    if(gRandom->Uniform() < fFormula->Eval(candidatePosition.Eta(), candidateMomentum.Pt()))
    {
      fOutputArray->Add(candidate);
    }
  }
}

Attachments (2)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.