Fork me on GitHub

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

--

Here is a very preliminary description of the Delphes library interface.

Installation

Sources are in the attachment.

Commands to download and build the library:

  setup ROOT environment variables

  wget --no-check-certificate https://server06.fynu.ucl.ac.be/projects/delphes/raw-attachment/wiki/LibraryInterface/ModularDelphes.tar.gz
  tar -zxf ModularDelphes.tar.gz

  cd ModularDelphes
  make -j 4

  # library
  ls libDelphes.so

  # headers
  ls external/ExRootAnalysis/*.h

  # config file
  ls etc/delphes_card_CMS.tcl

Complete example

A fully functional application using the Delphes library can be found in

  ModularDelphes/src/DelphesSTDHEP.cpp

Simplified example

ReadEvent() and ReadParticle() should be implemented by the library's user.

#include <stdexcept>
#include <iostream>

#include "TROOT.h"
#include "TApplication.h"

#include "TObjArray.h"
#include "TLorentzVector.h"

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

void ConvertEvent(ExRootFactory *factory, TObjArray *outputArray);
void ReadResults(ExRootAnalysis *modularDelphes);

int main()
{
  // Declaration of variables
  ExRootConfReader *confReader;
  ExRootAnalysis *modularDelphes;
  ExRootFactory *factory;
  TObjArray *particleOutputArray;
  TObjArray *partonOutputArray;

  gROOT->SetBatch();

  int appargc = 1;
  char *appName = "DelphesExample";
  char *appargv[] = {appName};
  TApplication app(appName, &appargc, appargv);

  try
  {
    // Initialization
    confReader = new ExRootConfReader;
    confReader->ReadFile("etc/delphes_card_CMS.tcl");

    modularDelphes = new ExRootAnalysis("Delphes");
    modularDelphes->SetConfReader(confReader);
    modularDelphes->SetTreeWriter(treeWriter);
    
    factory = modularDelphes->GetFactory();
    particleOutputArray = modularDelphes->ExportArray("particles");
    partonOutputArray = modularDelphes->ExportArray("partons");

    modularDelphes->InitTask();

    // Event loop
    while(ReadEvent())
    {
      modularDelphes->Clear();
      ConvertInput(factory, particleOutputArray, partonOutputArray); 
      modularDelphes->ProcessTask();
      ConvertOutput(modularDelphes);
    }

    // Finalisation
    modularDelphes->FinishTask();
    delete modularDelphes;
    delete confReader;
    return 0;
  }
  catch(runtime_error &e)
  {
    cerr << "** ERROR: " << e.what() << endl;
    return 1;
  }
}

void ConvertInput(ExRootFactory *factory, TObjArray *particleOutputArray, TObjArray *partonOutputArray)
{
  ExRootCandidate *candidate;
  TLorentzVector candidateMomentum, candidatePosition;
  Int_t pid, status;
  Double_t px, py, pz, e, m;  
  Double_t x, y, z, t;  

  while(ReadParticle())
  {
    if(status == 1 || status == 2)
    {
      candidate = factory->NewCandidate();

      candidate->SetType(pid);

      candidateMomentum.SetPxPyPzE(px, py, pz, e);
      candidate->SetMomentum(candidateMomentum);

      candidatePosition.SetXYZT(x, y, z, t);
      candidate->SetPosition(candidatePosition);

      if(status == 1)
      {
        particleOutputArray->Add(candidate);
      }
      else if(status == 2)
      {
        partonOutputArray->Add(candidate);
      }
    }
  }
}

void ConvertOutput(ExRootAnalysis *modularDelphes)
{
  TObjArray *arrayJets = modularDelphes->ImportArray("FastJetFinder/jets");
  TIter iteratorJets(arrayJets);
  ExRootCandidate *candidate;

  iteratorJets->Reset();
  while((candidate = static_cast<ExRootCandidate*>(iteratorJets->Next())))
  {
    const TLorentzVector &momentum = candidate->GetMomentum();
  }
}
Note: See TracWiki for help on using the wiki.