Difference: BenderScriptTutorial (4 vs. 5)

Revision 52016-02-05 - VanyaBelyaev

Line: 1 to 1
 
META TOPICPARENT name="LHCbSoftwareTutorials"

Getting started with BenderScript

Line: 27 to 27
 
    • large part of DaVinci tools is not working. It includes all tools and functionality related to e.g. actions with the associated best primary vertex. These manipulations are very complicated or some of them (e.g. PV-refit) is practically immpossible to perform in a correct way
    • some LoKi functors do not operate (mainly due to the issues from the previous item), e.g BPV*' or *DV or DTF_* - those are not easy to use from plain command line. There are some alternatives , but not for all functors.
Changed:
<
<

Start BenderScript session

>
>

Start of (interactive) BenderScript session

 

To start interactive BenderScript session bender command should be used. The command has many command line arguments, that can be inspected using -h key:

Line: 259 to 259
  %ENDSYNTAX%
Changed:
<
<

seek family of commands: seekForData, seekStripDecision, seekForODIN, seekForEvtRun, seekAlgDecision, seekforVoidDecision

>
>

seek family of commands

 

seekForData

This function allows to loop over events lookinng some data at given location. If data corresponds to container of elemements, containenr is required to be non-empty
Line: 295 to 294
 Maximal looping length is controlled by the second argument ( default is 1000 events)
Added:
>
>

seekStripDecision

seekForODIN

seekForEvtRun

seekAlgDecision

seekforVoidDecision

writeEvent: writing "interesting" events into separate output file

"Interesting" events can be copied into separate outptu file using command writeEvent

<!-- SyntaxHighlightingPlugin -->
> writeEvent() 
<!-- end SyntaxHighlightingPlugin -->

This command is activated if the output file name is provided for BenderScript using command line option -o/--output

<!-- SyntaxHighlightingPlugin -->
bender ....   -o interesting_events.dst 
<!-- end SyntaxHighlightingPlugin -->
 

Examples of basic actions:

Using the basic functions, described above one can easily code very simple analysis, e.g. one can loop over certain selected candiates for certain event and prints the decays of candidates found:
Line: 304 to 322
  data,nevt = seekForData('/Event/PSIX/Phys/SelPsi3KPiForPsiX/Particles' , 1000 ) print '#evnt %d, #B %d' % ( nevt , len(data) ) for b in data : print b.decay()
Added:
>
>
writeEvent()
  run(1) ....: In [50]:
Line: 320 to 339
 %ENDSYNTAX%
Changed:
<
<

Histograms&Tuples

>
>

Objects in BenderScript

Most popular objects, in particular particles (both reconstructed, LHCb::Particle and simulated, MC::Particle and HepMC::Particle), vertices, tracks, protoparticles, calorimeter clusters and hypos, as well as various containers (including corresponding SmartTefVectors) are decorated for more friendly (interactive) operations. One can e.g. compare "bare" GaudiPython with BenderScript:

<!-- SyntaxHighlightingPlugin -->
> python   ## start plain python session 
Python 2.7.10 (default, Nov 27 2015, 20:46:47)
[GCC 4.9.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cppyy
>>> cpp = cppyy.makeNamespace('')
>>> LHCb = cpp.LHCb
>>> p = LHCb.Particle( LHCb.ParticleID( 11))
>>> p
<ROOT.LHCb::Particle object at 0xbdaae10>
>>>
<!-- end SyntaxHighlightingPlugin -->
In BenderScript printout of objects is more informative (see above), and even for "empty" newly created particle is is more detailed:
<!-- SyntaxHighlightingPlugin -->
In [1]: p = LHCb.Particle(LHCb.ParticleID(11))
In [2]: p
Out[2]:
 0 |->e-                           M/PT/E/PX/PY/PZ:   1   /   0   /  -1  /   0  /   0  /   0   [GeV]
<!-- end SyntaxHighlightingPlugin -->
One can compare the output of help(LHCb.Paricle) and dir(LHCb.Particle) commands in GaudiPython and BenderScript and easily see a lot of newly added functions. E.g. for "bare" GaudiPython len(dir(LHCb.Particle)) reports 181, while in BenderScript context it reports 237. Important: all newly added mehtods are documented and command help provide good desription:

<!-- SyntaxHighlightingPlugin -->
In [2]: data, nevt = seekForData('/Event/PSIX/Phys/SelB2ChicPiPiForPsiX0/Particles')
In [3]: help(data.view)
Help on method view in module LoKiPhys.graph:

view(particle, command=None, format='png') method of cppyy.KeyedContainer<LHCb::Particle,Containers::KeyedObjectManager<Containers::hashmap> > instance
    Prepare the graph and vizualize it
    p = ...
    p.view ( format  = 'png' )
    p.view ( format  = 'png' , commmand = 'eog' )
<!-- end SyntaxHighlightingPlugin -->
Execution of this command will result in the following graph: aaa.png

In a similar way many other classes are decorated to be more friendly for usage with Bender and BenderScript.

"Decoration" also include simple intuitive looping over containers (E.g. automaticlaly resolving SmartRefs), easy selection of various daughter particles. tracks, etc:

<!-- SyntaxHighlightingPlugin -->
In [15]: B
Out[15]:
 0 |->B_s0                         M/PT/E/PX/PY/PZ: 4.8287/ 2.4833/ 95.65/ -2.36/-0.7732/ 95.5  [GeV]  #  0
                                       EndVertex  X/Y/Z:0.3624/0.0754/ 50.2  [mm]  Chi2/nDoF  18.21/5 #  0
 1    |->chi_c1(1P)                M/PT/E/PX/PY/PZ: 3.7328/ 1.6591/ 61.8 /-1.385/-0.9127/ 61.67 [GeV]  #  0
                                       EndVertex  X/Y/Z:0.3749/ 0.041/ 50.11 [mm]  Chi2/nDoF 0.5533/1 #  0
 2       |->J/psi(1S)              M/PT/E/PX/PY/PZ: 3.109 / 1.8157/ 57.85/-1.703/-0.6294/ 57.74 [GeV]  #  0
                                       EndVertex  X/Y/Z:0.3749/ 0.041/ 50.11 [mm]  Chi2/nDoF 0.5533/1 #  0
 3          |->mu+                 M/PT/E/PX/PY/PZ: 0.1057/ 1.5739/ 18.12/-1.103/ 1.123/ 18.05 [GeV]  #  2
 3          |->mu-                 M/PT/E/PX/PY/PZ: 0.1057/ 1.8517/ 39.74/-0.5996/-1.752/ 39.7  [GeV]  #  0
 2       |->gamma                  M/PT/E/PX/PY/PZ:   0   / 0.424 / 3.948/0.3165/-0.2822/ 3.925 [GeV]  # 18
 1    |->pi-                       M/PT/E/PX/PY/PZ: 0.1396/ 0.2581/ 16.29/-0.2547/-0.0418/ 16.29 [GeV]  #  9
 1    |->pi+                       M/PT/E/PX/PY/PZ: 0.1396/ 0.7438/ 17.56/-0.7207/0.1838/ 17.54 [GeV]  #  7

In [16]: for c in B.children() : print c.name()
chi_c1(1P)
pi-
pi+

In [19]: for c in B.children( LoKi.Child.Selector( PT > 1 * GeV ))  : print c.name()
B_s0
chi_c1(1P)
J/psi(1S)
mu+
mu-

In [23]: for t in B.tracks() : print t.pt() / GeV
1.57387760282
1.85170771471
0.258078675215
0.743781922842

In [30]: for t in B.tracks( 'mu+' == ABSID ) : print t.pt() / GeV
1.57387760282
1.85170771471
<!-- end SyntaxHighlightingPlugin -->

Histograms&Tuples: nTuple and book

  Surely one can rely on native ROOT histograms and TTrees, but for some cases it could have sense to rely on Gaudi's abilities to maintain histograms and tuples/trees. Gaudi's machinery requires the files for histograms and n-tuples/trees to be separated and to be declared at configuration time.
Line: 365 to 475
 In [11]: for b in data : h1.fill ( PT ( b ) / GeV ) %ENDSYNTAX%
Added:
>
>
The given histogram can be "dumped" as pseudographic, e.g. for quick inspection:
<!-- SyntaxHighlightingPlugin -->
In [2]: print h.dump(30,10)
 Histo TES   : "the_path"
 Histo Title : "title"
 Mean        :      2.8911 +- 0.04689
 Rms         :      2.1031 +- 0.08553
 Skewness    :      2.4874 +- 0.05453
 Kurtosis    :      11.309 +- 0.1088
 Entries     :
 |    All    |  In Range | Underflow |  Overflow | #Equivalent |   Integral  |    Total    |
 |    2012   |    2012   |     0     |     0     |     2012    |     2012    |     2012    |
 Annotation
 | Title                     : title                                         |
 | title                     : title                                         |
 | id                        : the_path                                      |

        550   ++----+----+----+----+----+
              ||*   .    .    .    .    |
              ||*   .    .    .    .    |
              ||*   .    .    .    .    |
              ||**  .    .    .    .    |
              ||**  .    .    .    .    |
              ||**  .    .    .    .    |
              ||**  .    .    .    .    |
        367   ++**......................+
              ||*** .    .    .    .    |
              ||*** .    .    .    .    |
              ||*** .    .    .    .    |
              ||*** .    .    .    .    |
              ||*** .    .    .    .    |
              |**** .    .    .    .    |
              |**** .    .    .    .    |
        183   +****.....................+
              |*****.    .    .    .    |
              |*****.    .    .    .    |
              |*****.    .    .    .    |
              |******    .    .    .    |
              |******    .    .    .    |
              |*******   .    .    .    |
              |********  .    .    .    |
          0 *-++----+--*****************->*
            U
            N                             O
            D                             V
            E                             E
            R                             R
            F                             F
            L                             L
            O            1    1    2    2 O
            W 00    5    0    5    0    5 W
<!-- end SyntaxHighlightingPlugin -->
 

Execution of scripts

Line: 398 to 562
 %ENDSYNTAX%
Added:
>
>

Operations with Tools, Services and Algorithms

 
Added:
>
>

Services

Many services are available directly from AppMgr instance:

  • Algorithm Context Service: cntxSvc
  • Detector Data Service: detSvc
  • Event Data Service: evtSvc
  • Event Selector Service: evtSel
  • File Record Service: filerecordsvc
  • Histogram Service: histSvc
  • Incident Service: incSvc
  • N-Tuple Service: ntupleSvc
  • (LHCb) Particle Property Service: ppSvc
  • Tool service: toolSvc
  • ...

<!-- SyntaxHighlightingPlugin -->
In [4]: gaudi.ppSvc()
Out[4]: <PartProp.Service.iParticlePropertySvc at 0x7ff644866110>
In [5]: gaudi.evtSvc()
Out[5]: <GaudiPython.Bindings.iDataSvc at 0x7ff644866310>
In [6]: gaudi.toolSvc()
Out[6]: <GaudiPython.Bindings.iToolSvc at 0x7ff644866210>
<!-- end SyntaxHighlightingPlugin -->
 
Added:
>
>
Some of them accessible direclty form BenderScript prompt, e.g. evtSvc, detSvc, toolSvc, and some others
<!-- SyntaxHighlightingPlugin -->
In [7]: toolSvc
Out[7]: <GaudiPython.Bindings.iToolSvc at 0x7ff659e4d050>
In [8]: detSvc
Out[8]: <GaudiPython.Bindings.iDataSvc at 0x7ff65acfffd0>
In [9]: evtSvc
Out[9]: <GaudiPython.Bindings.iDataSvc at 0x7ff65acffc50>
<!-- end SyntaxHighlightingPlugin -->

Many of them have much improved with respect to bare GaudiPython interface. All new and improved methods are well documented, use help command to get more information.

To get certain generic service by name one can use AppMgr.servicemethod:

<!-- SyntaxHighlightingPlugin -->
In [2]: mysvc = gaudi.service('MessageSvc')
In [3]: mysvc
Out[3]: <GaudiPython.Bindings.iService at 0x7f82e4ed7050>
<!-- end SyntaxHighlightingPlugin -->

Tools

Getting certain tools from tools service ...

---++ Algorithms

 -- VanyaBelyaev - 2016-01-29 \ No newline at end of file
Added:
>
>

META FILEATTACHMENT attachment="aaa.png" attr="h" comment="" date="1454663964" name="aaa.png" path="aaa.png" size="3994" user="ibelyaev" version="1"
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback