Fork me on GitHub

Changes between Version 2 and Version 3 of WorkBook/DelphesAnalysis


Ignore:
Timestamp:
May 23, 2013, 11:51:16 PM (11 years ago)
Author:
Christophe Delaere
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WorkBook/DelphesAnalysis

    v2 v3  
     1[[TOC]]
     2
    13Delphes comes with all the !ExRootAnalysis framework/facilities. It is powerful and very practical. Written in C++, it has all the nice (fast) and bad (heavy) aspects of that language.
    24On the contrary, Python is an interpreted scripting language that allows for a fast development cycle.
     
    3032{{{
    3133#!div style="font-size: 80%"
    32   {{{#!python
    33   hello = lambda: "world"
     34  {{{
     35    class AnalysisEvent(ROOT.TChain)
     36     |
     37     |  __init__(self, inputFiles='', maxEvents=0)
     38     |      Initialize the AnalysisEvent like a standard Event, plus additional features.
     39     |
     40     |  addCollection(self, name, inputTag)
     41     |      Register an event collection as used by the analysis.
     42     |      Example: addCollection("myjets","jets")
     43     |      Note that the direct access to the branch is still possible but unsafe.
     44     | 
     45     |  removeCollection(self, name)
     46     |      Forget about the named event collection.
     47     |      This method will delete both the product from the cache (if any) and the definition.
     48     |      To simply clear the cache, use "del event.name" instead.
     49     | 
     50     |  getCollection(self, name)
     51     |      Retrieve the event product or return the cached collection.
     52     |      Note that the prefered way to get the collection is instead to access the "event.name" attribute.
     53     | 
     54     |  addProducer(self, name, producer, **kwargs)
     55     |      Register a producer to create new high-level analysis objects.
     56     | 
     57     |  removeProducer(self, name)
     58     |      Forget about the producer.
     59     |      This method will delete both the product from the cache (if any) and the producer.
     60     |      To simply clear the cache, use "del event.name" instead.
     61     | 
     62     |  addWeight(self, name, weightClass)
     63     |      Declare a new class (engine) to compute the weights.
     64     |      weightClass must have a weight() method returning a float.
     65     | 
     66     |  delWeight(self, name)
     67     |      Remove one weight engine from the internal list.
     68     | 
     69     |  weight(self, weightList=None, **kwargs)
     70     |      Return the event weight. Arguments:
     71     |       * weightList is the list of engines to use, as a list of strings.
     72     |            Default: all defined engines.
     73     |       * the other named arguments are forwarded to the engines.
     74     |      The output is the product of the selected individual weights.
     75     |
     76     |  event(self)
     77     |      Event number
     78     | 
     79     |  to(self, event)
     80     |      Jump to some event
     81     |
     82     |  (...)
    3483  }}}
    3584}}}
     
    4594{{{
    4695#!div style="font-size: 80%"
    47   {{{#!python
    48   hello = lambda: "world"
     96  {{{
     97    class BaseControlPlots
     98     |
     99     |  __init__(self, dir=None, purpose='generic', dataset=None, mode='plots')
     100     |      Initialize the ControlPlots, creating output file if needed. If no file is given, it means it is delegated.
     101     | 
     102     |  add(self, *args)
     103     |      Add one item to the list of products. Arguments are as for TH1F.
     104     | 
     105     |  beginJob(self)
     106     |      Declare histograms, and for derived classes instantiate handles. Must be overloaded.
     107     | 
     108     |  defineCategories(self, categories)
     109     |      Define the categories, given a list of names. Only works for datasets
     110     | 
     111     |  endJob(self)
     112     |      Save and close.
     113     | 
     114     |  fill(self, data, weight=1.0)
     115     |      Fills whatever must be filled in
     116     | 
     117     |  process(self, event)
     118     |      Process event data to extract histogrammables. Must be overloaded.
     119     | 
     120     |  processEvent(self, event, weight=1.0)
     121     |      process event and fill histograms
     122     | 
     123     |  setCategories(self, categories)
     124     |      Set the categories, given a list of booleans. Only works for datasets
     125     |
     126     |  (...)
    49127  }}}
    50128}}}
     
    58136{{{
    59137#!div style="font-size: 80%"
    60   {{{#!python
    61   hello = lambda: "world"
     138  {{{
     139    class BaseWeightClass
     140     | 
     141     |  weight(self, event)
     142     |      Lepton eff weight
    62143  }}}
    63144}}}
     
    72153{{{
    73154#!div style="font-size: 80%"
     155  {{{
     156FUNCTIONS
     157    eventCategory(event)
     158        Check analysis requirements for various steps
     159        and return a tuple of data used to decide
     160        to what category an event belong
     161   
     162    isInCategory(category, categoryData)
     163        Check if the event enters category X, given the tuple computed by eventCategory.
     164
     165DATA
     166    categoryNames = [ ]
     167  }}}
     168}}}
     169
     170== Steering code and Configuration file ==
     171
     172The framework is contained in python/DelphesAnalsys. No file in that directory should ever be modified.
     173
     174The main script is !ControlPlots. This is a single code to generate a full set of histograms for your analysis, organized in logical groups by !ControlPlot class and by category. The same code will generate a ntuple if the proper parameter is changed in the configuration file. Internally, !ControlPlots steers the user-defined codes: event selection and control plots.
     175
     176!DumpEventInfo is another script that will output all the information available on a given event.
     177
     178All that is configured through a simple configuration script. The script used is defined via the !DelphesAnalysisCfg environment variable, or optionally via the command line in the case of !ControlPlots. The config file is where the control plot class and event selection module are declared and where the event collections, producers and weights are set.
     179
     180{{{
     181#!div style="font-size: 80%"
    74182  {{{#!python
    75   hello = lambda: "world"
    76   }}}
    77 }}}
    78 
    79 == Steering code and Configuration file ==
    80 
    81 The framework is contained in python/DelphesAnalsys. No file in that directory should ever be modified.
    82 
    83 The main script is ControlPlots.
    84 
    85 DumpEventInfo is another script that will output all the information available on a given event.
    86 
    87 All that is configured through a simple configuration script.
     183#configuration of the ControlPlot machinery
     184
     185from collections import namedtuple
     186controlPlot     = namedtuple("controlPlot",    ["label","module","classname","kwargs"])
     187eventCollection = namedtuple("eventCollection",["label","collection"])
     188eventProducer   = namedtuple("eventProducer",  ["label","module","function","kwargs"])
     189eventWeight     = namedtuple("eventWeight",    ["label","module","classname","kwargs"])
     190
     191class configuration:
     192  # default I/O
     193  defaultFilename = "controlPlots"
     194  RDSname = "rds_delphes"
     195  WSname = "workspace_ras"
     196
     197  # mode: plots or dataset
     198  runningMode = "plots"
     199
     200  # event selection class
     201  eventSelection = ""
     202
     203  # control plot classes
     204  controlPlots = [ ]
     205
     206  # event content: lists of eventCollection, eventProducer, and eventWeight objects respectively.
     207  eventCollections = [ ]
     208  eventProducers   = [ ]
     209  eventWeights     = [ ]
     210
     211class eventDumpConfig:
     212  # fine-tuning of the event content for display
     213  productsToPrint   = [ ] # list of product to display (use the producer label)
     214  collectionsToHide = [ ] # collections used in the analysis but not printed (use the collection label)
     215
     216# import the actual implementation of the configuration
     217import os
     218theConfig = os.getenv("DelphesAnalysisCfg")
     219if theConfig is not None:
     220  configImplementation = __import__(os.path.splitext(theConfig)[0])
     221  configuration = configImplementation.configuration
     222  eventDumpConfig = configImplementation.eventDumpConfig
     223  }}}
     224}}}
    88225
    89226== Implementing an analysis ==
    90227
    91 what should be touched to implement an example?
    92 * config.py (name given as argument of ControlPlots or set as DelphesAnalysisCfg env var.
    93 * specific EventSelection class
    94 * specific controlPlots class(es)
    95 
    96 == Examples ==
     228In order to implement an analysis, one should
     229* implement the specific control plot class(es), with the plots that you want to see.
     230* implement an event selection module, with the cuts that should be applied.
     231* declare everything in the configuration file (name given as argument of ControlPlots or set as DelphesAnalysisCfg env var).
    97232
    98233The release includes two examples.
     
    110245
    111246The following commands can be run from the Delphes ROOT directory:
     247{{{
     248#!div style="font-size: 90%"
    112249{{{#!sh
    113250# setup path
     
    122259for i in `cat eventlist.txt| cut -d' ' -f 2`; { python DelphesAnalysis/DumpEventInfo.py $i ../delphes_output.root; }
    123260}}}
     261}}}