7 from PhysicsTools.HeppyCore.statistics.counter
import Counters
8 from PhysicsTools.HeppyCore.statistics.average
import Averages
11 """Base Analyzer class. Used in Looper.
13 Your custom analyzers should inherit from this class
16 def __init__(self, cfg_ana, cfg_comp, looperName ):
17 """Create an analyzer.
19 Parameters (also stored as attributes for later use):
20 cfg_ana: configuration parameters for this analyzer (e.g. a pt cut)
21 cfg_comp: configuration parameters for the data or MC component (e.g. DYJets)
22 looperName: name of the Looper which runs this analyzer.
25 dirName : analyzer directory, where you can write anything you want
34 if hasattr(cfg_ana,
"nosubdir")
and cfg_ana.nosubdir:
38 os.mkdir( self.dirName )
43 self.mainLogger = logging.getLogger( looperName )
47 """Automatically called by Looper, for all analyzers."""
50 self.mainLogger.warning(
'beginLoop ' + self.cfg_ana.name )
54 """Automatically called by Looper, for all analyzers."""
56 self.mainLogger.warning(
'' )
57 self.mainLogger.warning( str(self) )
58 self.mainLogger.warning(
'' )
61 """Automatically called by Looper, for all analyzers.
62 each analyzer in the sequence will be passed the same event instance.
63 each analyzer can access, modify, and store event information, of any type."""
64 print self.cfg_ana.name
68 """Called by Looper.write, for all analyzers.
69 Just overload it if you have histograms to write."""
70 self.counters.write( self.dirName )
71 self.averages.write( self.dirName )
74 """A multipurpose printout. Should do the job for most analyzers."""
78 if hasattr(self,
'counters')
and len( self.counters.counters ) > 0:
79 count =
'\n'.
join(
map(str, self.counters.counters))
80 if hasattr(self,
'averages')
and len( self.
averages ) > 0:
82 return '\n'.
join( [ana, count, ave] )
static std::string join(char **cmd)