Fork me on GitHub

Opened 9 years ago

Last modified 8 years ago

#866 accepted How to

some questions on DelphesAnalysis ( python )

Reported by: Li Huang Owned by: Ali YILMAZ
Priority: minor Milestone:
Component: Delphes code Version: Delphes 3
Keywords: Cc:

Description (last modified by Pavel Demin)

Hi,

I have some questions to bother you, in the file Delphes/python/DelphesAnalysis/AnalysisEvent.py :


  1. self.BuildIndex("Event[0].Number") #: why Event[0].Number ? we have a tree named Event.Number but no tree named Event[0].Number
  2. how a TObjArray behaviour like a 'real' array ? This question may not be a Delphes's question but I find that in root's guide , it said using operate[], but I failed. I just want to display the content of the array as the 'real' one.
  3. return self.Event.At(0).Number #: when added branch Event, a bug:AttributeError: 'TObject' object has no attribute 'Number' . Also the same question, why it is Event.At(0).Number but not Event.Number 4. self._weightCache = {} self._weightEngines = {} self._collections = {} self._producers = {} I have some confusion about the usage of _collections and _producers , what are they used for ? And I am confused about since we have _weightEngines to store our weight dictionary , why we need a _weightCache ?


When I go through the AnalysisEvent.py file I got many confusions. Maybe I can learn something from your examples and understand your idea of design DelphesAnalysis better. But now I am so confusion why you not just provide a python version of ExRootAnalysis or something to read Trees using python. The way ( using a configure file , plot file ..etc) really bother me now.

And I can not follow the README:

. ./DelphesEnv.sh
cd python
# run the analysis
DelphesAnalysis/ControlPlots.py -i ../files/ -o controlPlots_demo.root --all -c topConfig.py

since I don't know the meaning of ". ./DelphesEnv.sh" , I guess I can instead it by "sh DelphesEnv.sh" ? and I don't know "DelphesAnalysis/ControlPlots.py -i ../files/ -o controlPlots_demo.root --all -c topConfig.py

" , as the bug said:

ui@ui:~/tools/package/Delphes-3.3.2/python$ DelphesAnalysis/ControlPlots.py -i ../files/ -o ../zhh.root --all -c topConfig.py
bash: DelphesAnalysis/ControlPlots.py: Permission denied
ui@ui:~/tools/package/Delphes-3.3.2/python$ sudo DelphesAnalysis/ControlPlots.py -i ../files/ -o ../zhh.root --all -c topConfig.py
[sudo] password for ui: 
sudo: DelphesAnalysis/ControlPlots.py: command not found
ui@ui:~/tools/package/Delphes-3.3.2/python$ python DelphesAnalysis/ControlPlots.py -i ../files/ -o ../zhh.root --all -c topConfig.py
Error in <TUnixSystem::DynamicPathName>: libDelphes[.so | .dll | .dylib | .sl | .dl | .a] does not exist in :/home/ui/tools/root/lib:.:/home/ui/tools/root/lib::/home/ui/tools/root/cint/cint/stl
Traceback (most recent call last):
  File "DelphesAnalysis/ControlPlots.py", line 45, in <module>
    import Delphes
  File "/home/ui/tools/package/Delphes-3.3.2/python/DelphesAnalysis/Delphes.py", line 14, in <module>
    _root.MakeRootClass( "Event" ).__str__    = _Event__str__
TypeError: requested class 'ROOT::Event' does not exist

I want to turn to python coding and I really appreciate you have provided a python interface for Delphes. But now I need some help to be familiar with it.

Best,
Li

Change History (8)

comment:1 by Pavel Demin, 9 years ago

Description: modified (diff)

comment:2 by Pavel Demin, 9 years ago

sh DelphesEnv.sh is not equivalent to . DelphesEnv.sh.

If . DelphesEnv.sh does not work on your system, could you try source DelphesEnv.sh?

comment:3 by Li Huang, 9 years ago

Hi,

I used source DelphesEnv.sh then chmod 777 ControlPlots.py ,and then ( I wonder what is the meaning of controlPlots_demo.root? the input file or what?)

there is a bug:

ui@ui:~/tools/package/Delphes/python$ DelphesAnalysis/ControlPlots.py -i ../files/ -o ../../zhh.root --all -c topConfig.py
TClass::TClass:0: RuntimeWarning: no dictionary for class CompBase is available
Traceback (most recent call last):
  File "DelphesAnalysis/ControlPlots.py", line 209, in <module>
    main(options)
  File "DelphesAnalysis/ControlPlots.py", line 89, in main
    runAnalysis(path=options.path,outputname=options.outputname, levels=levels, Njobs=options.Njobs, jobNumber=options.jobNumber)
  File "DelphesAnalysis/ControlPlots.py", line 116, in runAnalysis
    events = AnalysisEvent(files)
  File "/home/ui/tools/package/Delphes/python/DelphesAnalysis/AnalysisEvent.py", line 53, in __init__
    self._branches = dict((b,False) for b in map(lambda b:b.GetName(),self.GetListOfBranches()))
TypeError: argument 2 to map() must support iteration

Best,
Li

comment:4 by Christophe Delaere, 9 years ago

Hi Li,

I hope that you found the solution in the meanwhile.

The error comes simply from the fact that ../files/ does not exist.
You must give as input either a valid ROOT file from Delphes or a directory containing such ROOT files.

More information on the python analysis framework can be found in the workbook: https://cp3.irmp.ucl.ac.be/projects/delphes/wiki/WorkBook/DelphesAnalysis

Cheers,
Christophe.

comment:5 by Christophe Delaere, 9 years ago

Hi Li,

To answer your other questions:

  1. every branch in Delphes contains an array. Even for the event, there is an array of size 1.
  1. I cannot tell like this. The behavior may be different in C++ and in Python... the use of some ROOT classes in python sometimes requires a bit of experimentation. The way I use these arrays in python is through iterators (see below).
  1. the error says that array[0] is a TObject, which is true. Somehow python didn't get the underlying type. I would suggest to iterate on the event as we do on the other objects:
for e in event.Event: 
    print e.Number
  1. this is for optimization. _weightEngines is a vector of classes that know how to compute the weight. But the computation may be CPU intensive. Once calculated, the result is also stored in the cache, and returned from there is requested a second time.
  1. No additional code is needed if you want to read trees in python. The equivalent of ExRootAnalysis is already there out of the box once you load the Delphes library. Instead, DelphesAnalysis is an attempt to provide a full framework so that the code you need to write is minimal and can be reused easily. You can see that in the workbook: https://cp3.irmp.ucl.ac.be/projects/delphes/wiki/WorkBook/DelphesAnalysis#Implementingananalysis. But that's just one proposal. Python and ROOT are full of possibilities, and the output from Delphes is simple enough that you don't need much to write your analysis.

A last comment: the code in DelphesAnalysis uses some python features that are not "beginner level", but as a user you should not need to look at that code. The workbook and the two examples provided should be enough.

comment:6 by Ali YILMAZ, 8 years ago

Hi, I have some problems about running the python analysis in Delphes 3.4.0 with python2.7.13 on macos.
the error we got is seen in the below after following the instructions on README

the analysis example file in Mg5_2.5.2/Delphes/python directory:

Traceback (most recent call last):

File "DelphesAnalysis/ControlPlots.py", line 46, in <module>

import Delphes

File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ROOT.py", line 303, in _importhook

return _orig_ihook( name, *args, kwds )

File "/Users/aliyilmaz/programFiles/MG5_aMC_v2_5_2/HEPTools/Delphes/python/DelphesAnalysis/Delphes.py", line 14, in <module>

_root.MakeRootClass( "Event" ).str = _Eventstr

AttributeError: 'module' object has no attribute 'MakeRootClass'

I want to turn to python coding on my analysis .
thank you
Ali

comment:7 by Ali YILMAZ, 8 years ago

Owner: set to Ali YILMAZ
Status: newaccepted

comment:8 by Pavel Demin, 8 years ago

I want to turn to python coding on my analysis.

For a simple example I'd suggest to have a look at examples/Example1.py.

Note: See TracTickets for help on using tickets.