Difference: BenderScriptTutorial (7 vs. 8)

Revision 82016-02-06 - VanyaBelyaev

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

Getting started with BenderScript

Changed:
<
<
This "pseudo-hands-on" tutorial is an introduction to BenderScript a powerful Bender-based enhancement of GaudiPython
>
>
This "pseudo-hands-on" tutorial is an introduction to BenderScript a powerful Bender-based enhancement of GaudiPython
  Dedicated tutorials on Bender and GaudiPython could be useful here
Line: 20 to 22
  "First steps in LHCb" starter kit could be considered as a right prerequisite to BenderScript.
Added:
>
>

IMPORTANT Vladimir Romanovsky is working now on integration of BenderScript with Ganga

 

Pros and Contras

BenderScript shares all pros and contras with GaudiPython

Line: 577 to 584
 
  • File Record Service: filerecordsvc
  • Histogram Service: histSvc
  • Incident Service: incSvc
Changed:
<
<
  • N-Tuple Service: ntupleSvc
>
>
  • N-Tuple Service: ntupleSvc
 
  • (LHCb) Particle Property Service: ppSvc
  • Tool service: toolSvc
  • ...
Line: 616 to 623
 

Tools

Changed:
<
<
Getting certain tools from tools service ...
>
>

Acquiring tools

Getting certain tools from Tool Service is easy:

<!-- SyntaxHighlightingPlugin -->
In [2]: tool = toolSvc.tool('DaVinci::ParticleTransporter', interface  = cpp.IParticleTransporter )
In [3]: tool
Out[3]: iAlgTool('DaVinci::ParticleTransporter',interface=IParticleTransporter)
<!-- end SyntaxHighlightingPlugin -->
Warning concerning usage of private tools from python prompt:
  • aqcuiring of private tools form the command prompt has not much sense, and could be very fragile
  • using of private tools via python prompt is very fragile and unsafe

Using tools

<!-- SyntaxHighlightingPlugin -->
In [4]: tool = toolSvc.tool('DaVinci::ParticleTransporter', interface  = cpp.IParticleTransporter )
In [5]: data, nevt = seekForData('/Event/PSIX/Phys/SelB2ChicPiPiForPsiX0/Particles')
In [6]: B = data[0]
In [7]: print B
 0 |->B_s0                         M/PT/E/PX/PY/PZ: 4.7175/ 0.9365/ 51.63/0.5916/-0.726/ 51.4  [GeV]  #  0
                                       EndVertex  X/Y/Z:0.6053/0.1641/-25.71 [mm]  Chi2/nDoF  18.45/5 #  0
 1    |->chi_c1(1P)                M/PT/E/PX/PY/PZ: 3.5344/ 0.9029/ 33.37/0.4004/-0.8092/ 33.17 [GeV]  #  0
                                       EndVertex  X/Y/Z:0.5967/0.1681/-25.71 [mm]  Chi2/nDoF 0.03611/1 #  0
 2       |->J/psi(1S)              M/PT/E/PX/PY/PZ: 3.1004/ 0.4001/ 29.79/ 0.183/-0.3558/ 29.63 [GeV]  #  0
                                       EndVertex  X/Y/Z:0.5967/0.1681/-25.71 [mm]  Chi2/nDoF 0.03611/1 #  0
 3          |->mu+                 M/PT/E/PX/PY/PZ: 0.1057/ 1.7593/ 16.71/0.8563/-1.537/ 16.61 [GeV]  #  2
 3          |->mu-                 M/PT/E/PX/PY/PZ: 0.1057/ 1.3595/ 13.08/-0.6735/ 1.181/ 13.01 [GeV]  #  1
 2       |->gamma                  M/PT/E/PX/PY/PZ:   0   / 0.5039/ 3.577/ 0.218/-0.4543/ 3.541 [GeV]  #  0
 1    |->pi-                       M/PT/E/PX/PY/PZ: 0.1396/ 0.3579/ 9.828/-0.3188/0.1625/ 9.82  [GeV]  #  5
 1    |->pi+                       M/PT/E/PX/PY/PZ: 0.1396/ 0.5121/ 8.431/0.5051/-0.0849/ 8.415 [GeV]  #  1
In [8]: B.referencePoint()
Out[8]: ( 0.605291, 0.164137, -25.7105)
In [9]: transported_B = LHCb.Particle()

In [11]: tool.transport( B , B.referencePoint().Z() + 5*mm , transported_B )
Out[11]: SUCCESS
In [12]: transported_B
Out[12]:
 0 |->B_s0                         M/PT/E/PX/PY/PZ: 4.7175/ 0.9365/ 51.63/0.5916/-0.726/ 51.4  [GeV]
                                       EndVertex  X/Y/Z:0.6053/0.1641/-25.71 [mm]  Chi2/nDoF  18.45/5 #  0
 1    |->chi_c1(1P)                M/PT/E/PX/PY/PZ: 3.5344/ 0.9029/ 33.37/0.4004/-0.8092/ 33.17 [GeV]  #  0
                                       EndVertex  X/Y/Z:0.5967/0.1681/-25.71 [mm]  Chi2/nDoF 0.03611/1 #  0
 2       |->J/psi(1S)              M/PT/E/PX/PY/PZ: 3.1004/ 0.4001/ 29.79/ 0.183/-0.3558/ 29.63 [GeV]  #  0
                                       EndVertex  X/Y/Z:0.5967/0.1681/-25.71 [mm]  Chi2/nDoF 0.03611/1 #  0
 3          |->mu+                 M/PT/E/PX/PY/PZ: 0.1057/ 1.7593/ 16.71/0.8563/-1.537/ 16.61 [GeV]  #  2
 3          |->mu-                 M/PT/E/PX/PY/PZ: 0.1057/ 1.3595/ 13.08/-0.6735/ 1.181/ 13.01 [GeV]  #  1
 2       |->gamma                  M/PT/E/PX/PY/PZ:   0   / 0.5039/ 3.577/ 0.218/-0.4543/ 3.541 [GeV]  #  0
 1    |->pi-                       M/PT/E/PX/PY/PZ: 0.1396/ 0.3579/ 9.828/-0.3188/0.1625/ 9.82  [GeV]  #  5
 1    |->pi+                       M/PT/E/PX/PY/PZ: 0.1396/ 0.5121/ 8.431/0.5051/-0.0849/ 8.415 [GeV]  #  1

In [13]: transported_B.referencePoint()
Out[13]: ( 0.662837, 0.0935148, -20.7105)
<!-- end SyntaxHighlightingPlugin -->

Manipulaitons with tools

Tools and their properties

Get and (re)set properties:

<!-- SyntaxHighlightingPlugin -->
In [12]: tool.OutputLevel
Out[12]: 1
In [13]: tool.OutputLevel = 3
In [14]: tool.OutputLevel
Out[14]: 3
<!-- end SyntaxHighlightingPlugin -->
Warning redefinition of certain properties for certain tools is taken into account only before tool is initialized.

Get list of all declared properties fro the given tool:

 
Added:
>
>
<!-- SyntaxHighlightingPlugin -->
In [15]: tool.properties()
Out[15]:
{'AuditFinalize': <GaudiPython.Bindings.PropertyEntry at 0x7f3d40905c90>,
 'AuditInitialize': <GaudiPython.Bindings.PropertyEntry at 0x7f3d40905e90>,
 'AuditStart': <GaudiPython.Bindings.PropertyEntry at 0x7f3d40905bd0>,
 'AuditStop': <GaudiPython.Bindings.PropertyEntry at 0x7f3d40905a10>,
 'AuditTools': <GaudiPython.Bindings.PropertyEntry at 0x7f3d40905e10>,
 'Context': <GaudiPython.Bindings.PropertyEntry at 0x7f3d40905ed0>,
 'ContextService': <GaudiPython.Bindings.PropertyEntry at 0x7f3d4090f510>,
 'CounterList': <GaudiPython.Bindings.PropertyEntry at 0x7f3d4090f210>,
 'EfficiencyRowFormat': <GaudiPython.Bindings.PropertyEntry at 0x7f3d40905cd0>,
 'ErrorsPrint': <GaudiPython.Bindings.PropertyEntry at 0x7f3d40905d10>,
 'Extrapolator1': <GaudiPython.Bindings.PropertyEntry at 0x7f3d4090f190>,
 'Extrapolator2': <GaudiPython.Bindings.PropertyEntry at 0x7f3d4090f050>,
 'GlobalTimeOffset': <GaudiPython.Bindings.PropertyEntry at 0x7f3d40905dd0>,
 'MeasureCPUPerformance': <GaudiPython.Bindings.PropertyEntry at 0x7f3d4090f250>,
 'MonitorService': <GaudiPython.Bindings.PropertyEntry at 0x7f3d418fdad0>,
 'OutputLevel': <GaudiPython.Bindings.PropertyEntry at 0x7f3d40905f90>,
 'Particle2State': <GaudiPython.Bindings.PropertyEntry at 0x7f3d4090f150>,
 'PropertiesPrint': <GaudiPython.Bindings.PropertyEntry at 0x7f3d40905f50>,
 'RegularRowFormat': <GaudiPython.Bindings.PropertyEntry at 0x7f3d40905fd0>,
 'RootInTES': <GaudiPython.Bindings.PropertyEntry at 0x7f3d40905d50>,
 'StatEntityList': <GaudiPython.Bindings.PropertyEntry at 0x7f3d4090f110>,
 'StatPrint': <GaudiPython.Bindings.PropertyEntry at 0x7f3d40905c50>,
 'StatTableHeader': <GaudiPython.Bindings.PropertyEntry at 0x7f3d40905f10>,
 'TrackStateProvider': <GaudiPython.Bindings.PropertyEntry at 0x7f3d4090f2d0>,
 'TrajectoryRegion': <GaudiPython.Bindings.PropertyEntry at 0x7f3d4090f490>,
 'TypePrint': <GaudiPython.Bindings.PropertyEntry at 0x7f3d40905b90>,
 'UseEfficiencyRowFormat': <GaudiPython.Bindings.PropertyEntry at 0x7f3d4090f390>}
In [16]: tool.properties().keys()
Out[16]:
['StatTableHeader',
 'ErrorsPrint',
 'MonitorService',
 'RootInTES',
 'Particle2State',
 'AuditFinalize',
 'RegularRowFormat',
 'UseEfficiencyRowFormat',
 'ContextService',
 'AuditTools',
 'StatEntityList',
 'AuditInitialize',
 'OutputLevel',
 'TrajectoryRegion',
 'TypePrint',
 'StatPrint',
 'AuditStop',
 'Context',
 'PropertiesPrint',
 'GlobalTimeOffset',
 'Extrapolator1',
 'Extrapolator2',
 'MeasureCPUPerformance',
 'TrackStateProvider',
 'AuditStart',
 'EfficiencyRowFormat',
 'CounterList']
<!-- end SyntaxHighlightingPlugin -->

For tools, inherited from GaudiTool (that accounts a bulk of tools used in LHCb) some additional functionality is available:

<!-- SyntaxHighlightingPlugin -->
In [18]: tool.PropertiesPrint = True
ToolSvc.DaVinci...SUCCESS List of ALL properties of DaVinci::ParticleTransporter/ToolSvc.DaVinci::ParticleTransporter  #properties = 27
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'MeasureCPUPerformance':False
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'TrajectoryRegion':( -300.00000 , 1000.0000 )
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'Extrapolator2':TrackRungeKuttaExtrapolator:PUBLIC
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'Extrapolator1':TrackParabolicExtrapolator:PUBLIC
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'Particle2State':Particle2State:PUBLIC
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'TrackStateProvider':TrackStateProvider:PUBLIC
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'ContextService':AlgContextSvc
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'StatEntityList':[  ]
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'CounterList':[ '.*' ]
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'UseEfficiencyRowFormat':True
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'EfficiencyRowFormat': |*%|-48.48s|%|50t||%|10d| |%|11.5g| |(%|#9.6g| +- %|-#9.6g|)%%|   -------   |   -------   |
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'RegularRowFormat': | %|-48.48s|%|50t||%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'StatTableHeader': |    Counter                                      |     #     |    sum     | mean/eff^* | rms/err^*  |     min     |     max     |
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'GlobalTimeOffset':0.0000000
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'RootInTES':
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'Context':
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'TypePrint':True
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'StatPrint':True
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'PropertiesPrint':True
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'ErrorsPrint':True
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'AuditFinalize':False
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'AuditStop':False
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'AuditStart':False
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'AuditInitialize':False
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'AuditTools':False
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'OutputLevel':3
ToolSvc.DaVinci...SUCCESS Property ['Name': Value] =  'MonitorService':MonitorSvc
<!-- end SyntaxHighlightingPlugin -->
(and similar for tool.StatPrint = True)
 

Algorithms

Added:
>
>
One can get list of (already) created algorithms from AlgorithmManager
<!-- SyntaxHighlightingPlugin -->
In [22]: gaudi.algorithms()
Out[22]:
['DaVinciEventSeq',
 'DaVinciInitAlg',
 'FilteredEventSeq',
 'LumiSeq',
 'DaVinciEventInitSeq',
 'DaVinciAnalysisSeq',
 'KillDAQ',
 'DaVinciUserSequence',
 'MonitoringSequence',
 'EventAccount']
<!-- end SyntaxHighlightingPlugin -->

The algorithm can be picked up by name:

<!-- SyntaxHighlightingPlugin -->
In [6]: alg = gaudi.algorithm('DaVinciInitAlg')
In [7]: alg
Out[7]: <GaudiPython.Bindings.iAlgorithm at 0x7fc422714a10>
<!-- end SyntaxHighlightingPlugin -->

All functionality described above is also applicable for algorithms, e.g.

<!-- SyntaxHighlightingPlugin -->
In [8]: alg.PropertiesPrint = True
DaVinciInitAlg    SUCCESS List of ALL properties of DaVinciInit/DaVinciInitAlg  #properties = 46
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'PrintEvent':False
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'MinMemoryDelta':16
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'MemoryPurgeLimit':3400000
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'Increment':1000
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'EvtCounter':EvtCounter
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'PrintEventTime':False
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'PrintFreq':1
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'PreloadGeometry':False
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'SingleSeed':False
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'SkipFactor':0
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'RequireObjects':[  ]
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'VetoObjects':[  ]
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'StatEntityList':[  ]
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'CounterList':[ '.*' ]
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'UseEfficiencyRowFormat':True
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'EfficiencyRowFormat': |*%|-48.48s|%|50t||%|10d| |%|11.5g| |(%|#9.6g| +- %|-#9.6g|)%%|   -------   |   -------   |
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'RegularRowFormat': | %|-48.48s|%|50t||%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'StatTableHeader': |    Counter                                      |     #     |    sum     | mean/eff^* | rms/err^*  |     min     |     max     |
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'GlobalTimeOffset':0.0000000
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'RootInTES':
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'Context':
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'TypePrint':True
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'StatPrint':True
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'PropertiesPrint':True
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'ErrorsPrint':True
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'NeededResources':[  ]
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'Cardinality':1
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'IsClonable':False
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'RegisterForContextService':True
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'MonitorService':MonitorSvc
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'AuditStop':True
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'AuditStart':True
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'AuditEndRun':True
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'AuditBeginRun':True
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'AuditFinalize':True
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'AuditExecute':True
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'AuditRestart':True
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'AuditReinitialize':True
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'AuditInitialize':True
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'AuditAlgorithms':True
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'DataOutputs':
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'DataInputs':
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'ErrorCounter':0
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'ErrorMax':1
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'Enable':True
DaVinciInitAlg    SUCCESS Property ['Name': Value] =  'OutputLevel':3
<!-- end SyntaxHighlightingPlugin -->

histograms and counters

<!-- SyntaxHighlightingPlugin -->
[ibelyaev@lbcsrv01]~/cmtuser/BenderDev_HEAD% bender -t MyTuples.root --histo MyHistos.root /lhcb/MC/2011/ALLSTREAMS.DST/00032102/0000/00032102_00000002_1.allstreams.dst /lhcb/MC/2011/ALLSTREAMS.DST/00032102/0000/00032102_00000017_1.allstreams.dst /lhcb/MC/2011/ALLSTREAMS.DST/00032102/0000/00032102_00000013_1.allstreams.dst
<!-- end SyntaxHighlightingPlugin -->

Lets implicitly call few algorithms (via Data-on-Demand Service)

<!-- SyntaxHighlightingPlugin -->
In [3]: for i in range(0,20) :
    run(1)
    print len(get('/Event/Phys/StdAllLoosePions/Particles'))
<!-- end SyntaxHighlightingPlugin -->
... and then inspect the algorithm:
<!-- SyntaxHighlightingPlugin -->
In [4]: pions = gaudi.algorithm('StdAllLoosePions')
In [5]: pions.Counters()
Out[5]: {'#accept': #=20      Sum=20          Mean=     1.000 +- 0.0000     Min/Max=     1.000/1.000     }
In [7]: for c in pions.Counters() : print c
#accept
In [8]: print pions.Counters('#accept')
#=20      Sum=20          Mean=     1.000 +- 0.0000     Min/Max=     1.000/1.000
 
<!-- end SyntaxHighlightingPlugin -->

In a similar way if algorithm ( or tool) internally creates histograms using GaudiHisto approach) they can be extracted and inspected using the method Histos()

 -- VanyaBelyaev - 2016-01-29

 
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