Fork me on GitHub

Version 8 (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 https://server06.fynu.ucl.ac.be/projects/delphes/raw-attachment/wiki/LibraryInterface/ModularDelphes.tar.gz
  tar -zxf ModularDelphes.tar.gz
  cd ModularDelphes
  make
  # library
  ls -l libDelphes.so
  # headers
  ls external/ExRootAnalysis/*.h

Example

#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 *outputArray;

  gROOT->SetBatch();

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

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

    modularDelphes = new ExRootAnalysis("Delphes");
    modularDelphes->SetConfReader(confReader);
    modularDelphes->SetTreeWriter(treeWriter);
    
    factory = modularDelphes->GetFactory();
    outputArray = modularDelphes->NewArray("candidates");

    modularDelphes->InitTask();

    // Event loop
    while(ReadEvent())
    {
      modularDelphes->Clear();
      ConvertEvent(factory, outputArray);         
      modularDelphes->ProcessTask();
      ReadResults(modularDelphes);
    }

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


void ConvertEvent(ExRootFactory *factory, TObjArray *outputArray)
{
  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)
    {
      candidate = factory->NewCandidate();
      
      candidate->SetType(pid);

      candidateMomentum.SetPxPyPzE(px, py, pz, e);
      candidate->SetMomentum(candidateMomentum);
      
      candidatePosition.SetXYZT(x, y, z, t);
      candidate->SetPosition(candidatePosition);
      
      outputArray->Add(candidate);
    }
  }
}

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

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