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 )
48 """Automatically called by Looper, for all analyzers."""
51 self.mainLogger.info(
'beginLoop ' + self.cfg_ana.name )
55 """Automatically called by Looper, for all analyzers."""
57 self.mainLogger.info(
'' )
58 self.mainLogger.info( str(self) )
59 self.mainLogger.info(
'' )
62 """Automatically called by Looper, for all analyzers.
63 each analyzer in the sequence will be passed the same event instance.
64 each analyzer can access, modify, and store event information, of any type."""
65 print self.cfg_ana.name
69 """Called by Looper.write, for all analyzers.
70 Just overload it if you have histograms to write."""
71 self.counters.write( self.dirName )
72 self.averages.write( self.dirName )
75 """A multipurpose printout. Should do the job for most analyzers."""
79 if hasattr(self,
'counters')
and len( self.counters.counters ) > 0:
80 count =
'\n'.
join(map(str, self.counters.counters))
81 if hasattr(self,
'averages')
and len( self.
averages ) > 0:
83 return '\n'.
join( [ana, count, ave] )
static std::string join(char **cmd)