'''Example configuration file for an ee->ZH->mumubb analysis in heppy, with the FCC-ee

While studying this file, open it in ipython as well as in your editor to 
get more information: 

ipython
from analysis_ee_ZH_cfg import * 
'''

import os
import copy
import heppy.framework.config as cfg

import logging

# next 2 lines necessary to deal with reimports from ipython
logging.shutdown()
reload(logging)


# global logging level for the heppy framework.
# in addition, all the analyzers declared below have their own logger,
# an each of them can be set to a different logging level.
logging.basicConfig(level=logging.WARNING)

# setting the random seed for reproducible results
import heppy.statistics.rrandom as random
# do not forget to comment out the following line if you want to produce and combine
# several samples of events 
random.seed(0xdeadbeef)

# loading the FCC event data model library to decode
# the format of the events in the input file
# help(Events) for more information 
from ROOT import gSystem
gSystem.Load("libdatamodelDict")
from EventStore import EventStore as Events

# setting the event printout
# help(Event) for more information
from heppy.framework.event import Event
# comment the following line to see all the collections stored in the event 
# if collection is listed then print loop.event.papasevent will include the collections
# Event.print_patterns=['rec_particles', 'gen_particles_stable']
Event.print_patterns=['rec_particles', 'gen_particles_stable', 'sum_all*']

# definition of the collider
# help(Collider) for more information
from heppy.configuration import Collider
Collider.BEAMS = 'ee'
Collider.SQRTS = 240.

# definition of an input sample (also called a component)
comp = cfg.Component(
    'ee_Z_ee',
    files = [
        # here we have a single input root file.
        # the absolute path must be used to be able to run on the batch.
        os.environ['HEPPY'] + '/test/ee_Z_ee.root'
    ]
)

# selecting the list of components to be processed. Here only one. 
selectedComponents = [comp]

# read FCC EDM events from the input root file(s)
# do help(Reader) for more information
from heppy.analyzers.fcc.Reader import Reader
source = cfg.Analyzer(
    Reader,
    gen_particles = 'GenParticle',
    gen_vertices = 'GenVertex'
)

# importing the papas simulation and reconstruction sequence,
# as well as the detector used in papas
# check papas_cfg.py for more information
from heppy.test.papas_cfg import papas, papas_sequence, detector

from heppy.test.papas_cfg import papasdisplaycompare as display 


from heppy.analyzers.SingleJetBuilder import SingleJetBuilder
sum_particles = cfg.Analyzer(
    SingleJetBuilder, 
    output='sum_all_ptcs',
    particles='rec_particles'
)

sum_gen = cfg.Analyzer(
    SingleJetBuilder, 
    output='sum_all_gen',
    particles='gen_particles_stable'
)

from heppy.analyzers.GlobalEventTreeProducer import GlobalEventTreeProducer
tree = cfg.Analyzer(
    GlobalEventTreeProducer,
    sum_all='sum_all_ptcs',
    sum_all_gen='sum_all_gen'
    )


# definition of a sequence of analyzers,
# the analyzers will process each event in this order
sequence = cfg.Sequence(
    source,
    papas_sequence,
    sum_particles,
    sum_gen, 
    tree, 
    display
)   

# Specifics to read FCC events 
from ROOT import gSystem
gSystem.Load("libdatamodelDict")
from EventStore import EventStore as Events

config = cfg.Config(
    components = selectedComponents,
    sequence = sequence,
    services = [],
    events_class = Events
)
