Beispiel #1
0
class PFSim(Analyzer):

    def __init__(self, *args, **kwargs):
        super(PFSim, self).__init__(*args, **kwargs)
        self.detector = CMS()
        self.simulator = Simulator(self.detector, self.mainLogger)
        self.is_display = self.cfg_ana.display
        if self.is_display:
            self.init_display()        
        
    def init_display(self):
        self.display = Display(['xy','yz', 'ECAL_thetaphi', 'HCAL_thetaphi'])
        self.gdetector = GDetector(self.detector)
        self.display.register(self.gdetector, layer=0, clearable=False)
        self.is_display = True
        
    def process(self, event):
        if self.is_display:
            self.display.clear()
        pfsim_particles = []
        # import pdb; pdb.set_trace()
        for ptc in event.gen_particles_stable:
            if not math.isnan(ptc.pt()) and ptc.pt()>1.:
                pfsimptc = pfsimparticle(ptc)
                pfsim_particles.append(pfsimptc)
                if self.cfg_ana.verbose:
                    print ptc
        self.simulator.simulate( pfsim_particles )
        if self.is_display:
            self.display.register( GTrajectories(pfsim_particles), layer=1)        
        event.simparticles = sorted( pfsim_particles,
                                     key = lambda ptc: ptc.e(), reverse=True)
        event.particles = sorted( self.simulator.pfsequence.pfreco.particles,
                                  key = lambda ptc: ptc.e(), reverse=True)
Beispiel #2
0
 def init_display(self):
     self.display = Display(['xy','yz', 'ECAL_thetaphi', 'HCAL_thetaphi'])
     self.gdetector = GDetector(self.detector)
     self.display.register(self.gdetector, layer=0, clearable=False)
     self.is_display = True
Beispiel #3
0
 def init_display(self):
     self.display = Display(['xy', 'yz'])
     self.gdetector = GDetector(self.detector)
     self.display.register(self.gdetector, layer=0, clearable=False)
     self.is_display = True
Beispiel #4
0
class PFSim(Analyzer):
    '''Runs PAPAS, the PArametrized Particle Simulation.

    Example configuration: 

    from heppy_fcc.analyzers.PFSim import PFSim
    from heppy_fcc.fastsim.detectors.CMS import CMS
    papas = cfg.Analyzer(
        PFSim,
        instance_label = 'papas',              
        detector = CMS(),
        gen_particles = 'gen_particles_stable',
        sim_particles = 'sim_particles',
        rec_particles = 'rec_particles',
        display = False,                   
        verbose = False
    )

    detector:      Detector model to be used. 
    gen_particles: Name of the input gen particle collection
    sim_particles: Name extension for the output sim particle collection. 
                   Note that the instance label is prepended to this name. 
                   Therefore, in this particular case, the name of the output 
                   sim particle collection is "papas_sim_particles".
    rec_particles: Name extension for the output reconstructed particle collection.
                   Same comments as for the sim_particles parameter above. 
    display      : Enable the event display
    verbose      : Enable the detailed printout.
    '''

    def __init__(self, *args, **kwargs):
        super(PFSim, self).__init__(*args, **kwargs)
        self.detector = self.cfg_ana.detector
        self.simulator = Simulator(self.detector,
                                   self.mainLogger)
        self.simname = '_'.join([self.instance_label,  self.cfg_ana.sim_particles])
        self.recname = '_'.join([self.instance_label,  self.cfg_ana.rec_particles])
        self.is_display = self.cfg_ana.display
        if self.is_display:
            self.init_display()        
        
    def init_display(self):
        self.display = Display(['xy','yz', 'ECAL_thetaphi', 'HCAL_thetaphi'])
        self.gdetector = GDetector(self.detector)
        self.display.register(self.gdetector, layer=0, clearable=False)
        self.is_display = True
        
    def process(self, event):
        event.simulator = self 
        if self.is_display:
            self.display.clear()
        pfsim_particles = []
        gen_particles = getattr(event, self.cfg_ana.gen_particles)
        self.simulator.simulate( gen_particles )
        pfsim_particles = self.simulator.ptcs
        if self.is_display:
            self.display.register( GTrajectories(pfsim_particles),
                                   layer=1)
        simparticles = sorted( pfsim_particles,
                               key = lambda ptc: ptc.e(), reverse=True)
        particles = sorted( self.simulator.particles,
                            key = lambda ptc: ptc.e(), reverse=True)
        setattr(event, self.simname, simparticles)
        setattr(event, self.recname, particles)
Beispiel #5
0
class PFSim(Analyzer):
    '''Runs PAPAS, the PArametrized Particle Simulation.

    Example configuration: 

    from heppy_fcc.analyzers.PFSim import PFSim
    from heppy_fcc.fastsim.detectors.CMS import CMS
    papas = cfg.Analyzer(
        PFSim,
        instance_label = 'papas',              
        detector = CMS(),
        gen_particles = 'gen_particles_stable',
        sim_particles = 'sim_particles',
        rec_particles = 'rec_particles',
        display = False,                   
        verbose = False
    )

    detector:      Detector model to be used. 
    gen_particles: Name of the input gen particle collection
    sim_particles: Name extension for the output sim particle collection. 
                   Note that the instance label is prepended to this name. 
                   Therefore, in this particular case, the name of the output 
                   sim particle collection is "papas_sim_particles".
    rec_particles: Name extension for the output reconstructed particle collection.
                   Same comments as for the sim_particles parameter above. 
    display      : Enable the event display
    verbose      : Enable the detailed printout.
    '''
    def __init__(self, *args, **kwargs):
        super(PFSim, self).__init__(*args, **kwargs)
        self.detector = self.cfg_ana.detector
        self.simulator = Simulator(self.detector, self.mainLogger)
        self.simname = '_'.join(
            [self.instance_label, self.cfg_ana.sim_particles])
        self.recname = '_'.join(
            [self.instance_label, self.cfg_ana.rec_particles])
        self.is_display = self.cfg_ana.display
        if self.is_display:
            self.init_display()

    def init_display(self):
        self.display = Display(['xy', 'yz'])
        self.gdetector = GDetector(self.detector)
        self.display.register(self.gdetector, layer=0, clearable=False)
        self.is_display = True

    def process(self, event):
        event.simulator = self
        if self.is_display:
            self.display.clear()
        pfsim_particles = []
        gen_particles = getattr(event, self.cfg_ana.gen_particles)
        self.simulator.simulate(gen_particles)
        pfsim_particles = self.simulator.ptcs
        if self.is_display:
            self.display.register(GTrajectories(pfsim_particles), layer=1)
        simparticles = sorted(pfsim_particles,
                              key=lambda ptc: ptc.e(),
                              reverse=True)
        particles = sorted(self.simulator.particles,
                           key=lambda ptc: ptc.e(),
                           reverse=True)
        setattr(event, self.simname, simparticles)
        setattr(event, self.recname, particles)
Beispiel #6
0
                box.Draw('samel')
        elif 'thetaphi' in projection:
            pass
        else:
            raise ValueError('implement drawing for projection ' + projection )


class GDetector(object):
    def __init__(self, description):
        self.desc = description
        self.elements = [GDetectorElement(elem) for elem in self.desc.elements.values()]
            
    def draw(self, projection):
        for elem in self.elements:
            elem.draw(projection)


            
if __name__ == '__main__':

    from ROOT import TCanvas, TH2F
    from heppy_fcc.fastsim.detectors.CMS import CMS
    from heppy_fcc.display.core import Display

    cms = CMS()
    gcms = GDetector(cms)

    display = Display()
    display.register(gcms, 0)
    display.draw()
Beispiel #7
0
            # display.register(gtraj,1)

    def draw(self, projection):
        for traj in self:
            traj.draw(projection)


if __name__ == '__main__':
    import math
    from heppy_fcc.fastsim.detectors.CMS import CMS
    from heppy_fcc.fastsim.simulator import Simulator
    from heppy_fcc.fastsim.vectors import Point
    from heppy_fcc.fastsim.toyevents import particles
    from heppy_fcc.display.core import Display
    from heppy_fcc.display.geometry import GDetector

    cms = CMS()
    simulator = Simulator(cms)

    particles = list(
        particles(5, 211, math.pi / 5., 4 * math.pi / 5., 10., 10.,
                  Point(0.5, 0.5, 0)))
    simulator.simulate(particles)

    display = Display()
    gcms = GDetector(cms)
    display.register(gcms, 0)
    gtrajectories = GTrajectories(particles)
    display.register(gtrajectories, 1)
    display.draw()
Beispiel #8
0
    detector = cms

    logging.basicConfig(level='ERROR')
    logger = logging.getLogger('Simulator')
    logger.addHandler( logging.StreamHandler(sys.stdout) )
    
    for i in range(1):
        if not i%100:
            print i
        simulator = Simulator(detector, logger)
        # particles = monojet([211, -211, 130, 22, 22, 22], math.pi/2., math.pi/2., 2, 50)
        particles = [
            # particle(211, math.pi/2., math.pi/2., 100),
            particle(211, math.pi/2 + 0.5, 0., 20.),
            # particle(130, math.pi/2., math.pi/2.+0., 100.),
            particle(22, math.pi/2., math.pi/2.+0.0, 10.)
        ]
        simulator.simulate(particles)
        
    if display_on:
        display = Display(['xy', 'yz',
                           'ECAL_thetaphi',
                           'HCAL_thetaphi'
                       ])
        gdetector = GDetector(detector)
        display.register(gdetector, 0)
        gtrajectories = GTrajectories(particles)
        display.register(gtrajectories,1)
        display.draw()
    
Beispiel #9
0
            gtraj = TrajClass(ptc)
            self.append(gtraj)
            # display.register(gtraj,1)

    def draw(self, projection):
        for traj in self:
            traj.draw(projection)
        
if __name__ == '__main__':
    import math
    from heppy_fcc.fastsim.detectors.CMS import CMS
    from heppy_fcc.fastsim.simulator import Simulator
    from heppy_fcc.fastsim.vectors import Point
    from heppy_fcc.fastsim.toyevents import particles
    from heppy_fcc.display.core import Display
    from heppy_fcc.display.geometry import GDetector

    cms = CMS()
    simulator = Simulator(cms)
    
    particles = list( particles(5, 211, math.pi/5., 4*math.pi/5.,
                                10., 10., Point(0.5,0.5,0)) )
    simulator.simulate(particles)
    
    display = Display()
    gcms = GDetector(cms)
    display.register(gcms, 0)
    gtrajectories = GTrajectories(particles)
    display.register(gtrajectories,1)
    display.draw()