Main page

Useful links

Tools  Documentation   LHCb Gaudi DaVinci Bender

What is LoKi?

LoKi is C++ toolkit  for the simple and user-friendly data analysis. LoKi is based on Gaudi architecture. The functionality of LoKi includes the selection of particles, manipulation with predefined kinematical expressions, loops over combinations of selected particles, creation of composite particles from various combinations of particles, flexible manipulation with various kinematical constrains, simplified population of histograms, N-Tuples, Event Tag Collections and access to Monte Carlo truth information. It uses many tools and classes  from DaVinci/Phys/Analysis/LHCb/Gaudi projects. Also LoKi is the underlying package for Bender - Interactive Python-based Physics analysis Environment.

Some more words about LoKi

Close the tip

C++ is currently the best suited language for large scale OO software projects. Unfortunately C++ requires significant amount of efforts from beginners to obtain some first results of acceptable quality. Often a simple operation corresponding to one “physics” statement results in an enormous code with complicated and probably non-obvious content.

 1 ParticleVector::const_iterator im;
 2 for(im=vDsK.begin(); im!=vDsK.end(); im++) {
 3 if((*im)->particleID().pid()==m_DsPlusID||
 4  (*im)->particleID().pid()==m_DsMinusID)
 5   vDs.push_back(*im);
 6 elseif((*im)->particleID().pid()==m_KPPlusID||
 7  (*im)->particleID().pid()==m_KPMinusID)
 8  vK.push_back(*im);
 9 else{
 10  log<<MSG<<ERROR<<"some_message_here"<<endreq;
 11  return StatisCode::FAILURE;
 12 }}

The usage of comments becomes mandatory for understanding makes the code even longer and again results in additional complexity. The idea of LoKi  is to provide the users with possibility to write the code, which does not obscure the actual physics content by technical C++ semantic. The idea of user-friendly components for physics analysis were essentially induced by the spirit of following packages:

  • KAL language by geneous Hartwig Albrecht. KAL is an interpreter language written on Fortran. The user writes script-like ASCII file, which is interpreted and executed by standard KAL executable. The package was very successfully used for physics analysis by ARGUS collaboration.
  • PATTERN and GCOMBINER packages by Thorsten Glebe. These nice, powerful and friendly C++ components have been used with success for the physics analysis by HERA-B collaboration.
  • Some obsolete CLHEP classes, like HepChooser and HepCombiner.
  • Loki library by Andrei Alexandrescu. The library from one side is a “state-of-art” for so called generic meta-programming and compile time programming, and simultaneously from another side it is the excellent cook-book, which contains very interesting, non-trivial and non-obvious recipes for efficient solving of major common tasks and problems.

The attractiveness of specialized, physics-oriented code for physics analysis could be demonstrated e.g. with “typical” code fragment in KAL:

 3  IDENT PI + PI+
 4  IDENT K+ K+
 6  IDENT E+ E+
 10 IF P &qt 2 THEN
 11 SAVEFITM D0 DMASS 0 . 0 4 5 CHI2 16
 16 PLOT MASS L 2.0 H 2.100 NB 100 TEXT ’ Mass of D0 pi+’
 19 GO 1000000

This KAL pseudo-code gives an example of self-explanatory code. The physical content of selection of D*+→D0π+ followed by D0→Kπ0 decay is clear and unambigously visible between lines. Indeed no comments are needed for understanding the analysis within 2 minutes.

One could argue that it is not possible to get the similar transparency of the physical content of code with native C++. The best answer to this argument could be just an example from T. Glebe’s PATTERN of K0S→π+π reconstruction:

 1 TrackPattern piMinus=pi_minus.with(pt>0.1 & p>1);
 2 TrackPattern piPlus=piplus.with(pt>0.1 & p>1);
 3 TwoProngDecay kShort=K0S.decaysTo(PiPlus & PiMinus);
 4 kShort.with ( vz > 0 );
 5 kShort.with ( pt > 0.1 );

This code fragment is not so transparent as specialized KAL pseudo-code but it is easy-to-read, the physical content is clear, and it is just a native C++ ! I personally tend to consider the above code as an experimental prove of possibility to develop easy-to-use C++ package for physics analysis. Indeed the work has been started soon after I’ve seen these 5 lines.

Here it is a good moment to jump to the end of the whole story and present some LoKi fragment for illustration:

 1  select("Pi+", ID=="pi+" && CL>0.01 && P>5*GeV);
 2  select("K-", ID=="K-" && CL>0.01 && P>5*GeV);
 3  for (Loop D0 = loop("K- pi+", "D0"); D0; ++D0)
 4  {
 5   if(P(D0)>10*GeV){D0->save("D0");}
 6  }
 7  for(Loop Dstar=loop("D0 Pi+", "D*+"); Dstar; ++Dstar)
 8  {
 9   plot(M(Dsatr)/GeV,"Mass of D0 pi+ in GeV",2.0,2.1,100);
 10 }

The physical content of these lines is quite transparent.

Close the tip

LoKi Savannah portal

Savannah portal is established for LoKi project. Please use it for bug reports, browsing bugs history, submission and browsing of the patches. Please register on Savannah to be able to use all useful functionality of Savannah, including the important notifications concerning the project development and evolution. See the current list of project members. How to register?


Here you will fined related documentation: manuals, tutorials and also talks.

Bug reports

You can report bugs or view bug histories via LoKi Savannah portal. Also LoKi mailing list could be used for bug-reports.

Who is Loki?

Loki is a god of wit and mischief in Norse mythology. The god of fire. The one that always wanted to break the constant rules and to bring the breath of changing to the world;)