Ejemplo n.º 1
0
 def tearDown(self):
     self.userConf = None
     self.engine = None
     EventStore.reset()
     ApplicationStore.reset()
     FileFactory.reset()
     FileStore.reset()
Ejemplo n.º 2
0
class EventStoreTestCase(unittest.TestCase):
    '''Test the python event store interface.'''
    
    def setUp(self):
        self.filename = 'example.root'
        self.assertTrue( os.path.isfile(self.filename) )
        self.store = EventStore(self.filename)
        
    def test_eventloop(self):
        '''Test that 
        - the store contains events, 
        - the length of the store is the number of entries, 
        - one can loop on the events.
        '''
        self.assertTrue( self.store.getEntries() >= 0 )
        self.assertEqual( self.store.getEntries(), len(self.store) )
        for iev, event in enumerate(self.store):
            self.assertTrue( True )

    def test_read_particles(self):
        '''Test that
        - the GenParticle objects can be used 
        - the processing is faster than 100 Hz. 
        '''
        start = datetime.now()
        for iev, event in enumerate(self.store):
            genptcs = event.get('GenParticle')
            self.assertTrue(len(genptcs)>0.)
            for ptc in genptcs:
                self.assertTrue(ptc.Core().P4.Pz!=0.)
        stop = datetime.now()
        time_per_event = float( (stop - start).seconds )/ len(self.store) 
        self.assertLess(time_per_event, 1e-2) # 3e-4 on Colin's mac  
                
    def test_direct_navigation(self):
        '''Test that 
        - one can move to a given event
        '''
        event0 = self.store[0]
        # event is of the store class
        self.assertEqual( event0.__class__, self.store.__class__)

    def test_collections(self):
        '''test that an existing collection can be read, 
        and that a non existing collection gives None.
        '''
        evinfo = self.store.get("EventInfo")
        self.assertTrue( len(evinfo)>0 )
        particles = self.store.get("CollectionNotThere")
        self.assertFalse(particles is None)
Ejemplo n.º 3
0
 def test_chain(self):
     self.store = EventStore([self.filename, self.filename])
     rootfile = TFile(self.filename)
     events = rootfile.Get(str('events'))
     numbers = []
     for iev, event in enumerate(self.store):
         evinfo = self.store.get("info")
         numbers.append(evinfo[0].Number())
     self.assertEqual(iev + 1, 2 * events.GetEntries())
     # testing that numbers is [0, .. 1999, 0, .. 1999]
     self.assertEqual(numbers, list(range(events.GetEntries())) * 2)
     # trying to go to an event beyond the last one
     self.assertRaises(ValueError, self.store.__getitem__, 4001)
     # this is in the first event in the second file,
     # so its event number should be 0.
     self.assertEqual(self.store[2000].get("info")[0].Number(), 0)
Ejemplo n.º 4
0
class EventStoreTestCase(unittest.TestCase):

    def setUp(self):
        self.filename = 'example.root'
        self.assertTrue( os.path.isfile(self.filename) )
        self.store = EventStore(self.filename)

    def test_eventloop(self):
        self.assertTrue( self.store.getEntries() >= 0 )
        self.assertEqual( self.store.getEntries(), len(self.store) )
        for iev, event in enumerate(self.store):
            self.assertTrue( True )
            if iev>5:
                break
        event0 = self.store[0]
        self.assertEqual( event0.__class__, self.store.__class__)

    def test_collections(self):
        evinfo = self.store.get("clusters")
        self.assertTrue( len(evinfo)>0 )
        particles = self.store.get("CollectionNotThere")
        self.assertFalse(particles)
Ejemplo n.º 5
0
    def sendEventsToStore(self):
        """Send this app's Events to the EventStore, and clear them."""
        # Get the EventStore
        from EventStore import EventStore
        eventStore = EventStore.get()

        # Send each Event, after updating it to point to the updated self.
        for event in self.events:
            event.actor = self
            eventStore.append(event)

        # Clear events, to save RAM.
        self.clearEvents()
Ejemplo n.º 6
0
 def test_chain(self):
     self.store = EventStore([self.filename, self.filename])
     rootfile = TFile(self.filename)
     events = rootfile.Get("events")
     numbers = []
     for iev, event in enumerate(self.store):
         evinfo = self.store.get("info")
         numbers.append(evinfo[0].Number())
     self.assertEqual(iev + 1, 2 * events.GetEntries())
     # testing that numbers is [0, .. 1999, 0, .. 1999]
     self.assertEqual(numbers, range(events.GetEntries()) * 2)
     # trying to go to an event in the second file
     self.assertRaises(ValueError, self.store.__getitem__, events.GetEntries() + 1)
Ejemplo n.º 7
0
class EventStoreTestCase(unittest.TestCase):
    def setUp(self):
        self.filename = "example.root"
        self.assertTrue(os.path.isfile(self.filename))
        self.store = EventStore([self.filename])

    def test_eventloop(self):
        self.assertTrue(self.store.getEntries() >= 0)
        self.assertEqual(self.store.getEntries(), len(self.store))
        for iev, event in enumerate(self.store):
            self.assertTrue(True)
            if iev > 5:
                break

    def test_navigation(self):
        event0 = self.store[0]
        self.assertEqual(event0.__class__, self.store.__class__)

    def test_collections(self):
        evinfo = self.store.get("info")
        self.assertTrue(len(evinfo) > 0)
        particles = self.store.get("CollectionNotThere")
        self.assertFalse(particles)

    def test_chain(self):
        self.store = EventStore([self.filename, self.filename])
        rootfile = TFile(self.filename)
        events = rootfile.Get("events")
        numbers = []
        for iev, event in enumerate(self.store):
            evinfo = self.store.get("info")
            numbers.append(evinfo[0].Number())
        self.assertEqual(iev + 1, 2 * events.GetEntries())
        # testing that numbers is [0, .. 1999, 0, .. 1999]
        self.assertEqual(numbers, range(events.GetEntries()) * 2)
        # trying to go to an event in the second file
        self.assertRaises(ValueError, self.store.__getitem__, events.GetEntries() + 1)
    def setUp(self):
        self.eventStore = EventStore.get()
        self.appStore = ApplicationStore.get()
        self.fileFactory = FileFactory.get()
        self.fileStore = FileStore.get()
        self.userConf = UserConfigLoader.get("user.ini")

        self.ar1 = Application("ristretto.desktop",
                               pid=21,
                               tstart=1,
                               tend=2000)
        self.ar2 = Application("ristretto.desktop",
                               pid=22,
                               tstart=2600,
                               tend=2900)
        self.ag1 = Application("gimp.desktop", pid=23, tstart=1, tend=4000)
        self.ag2 = Application("gimp.desktop", pid=24, tstart=4500, tend=4590)
        self.appStore.insert(self.ar1)
        self.appStore.insert(self.ar2)
        self.appStore.insert(self.ag1)
        self.appStore.insert(self.ag2)

        # Insert a file that will bridge r1 and g1.
        s2 = "open64|/home/user/Images/Picture.jpg|fd 4: with flag 524288, e0|"
        e2 = Event(actor=self.ag1, time=10, syscallStr=s2)
        self.eventStore.append(e2)
        e2b = Event(actor=self.ar1, time=12, syscallStr=s2)
        self.eventStore.append(e2b)

        # Insert a file that will bridge r1 and r2.
        s3 = "open64|/home/user/Images/Photo.jpg|fd 10: with flag 524288, e0|"
        e3 = Event(actor=self.ar1, time=10, syscallStr=s3)
        self.eventStore.append(e3)
        e3b = Event(actor=self.ar2, time=2710, syscallStr=s3)
        self.eventStore.append(e3b)

        # Insert a file that will bridge g1 and g2.
        s4 = "open64|/home/user/Images/Art.xcf|fd 10: with flag 524288, e0|"
        e4 = Event(actor=self.ag1, time=10, syscallStr=s4)
        self.eventStore.append(e4)
        e4b = Event(actor=self.ag2, time=4540, syscallStr=s4)
        self.eventStore.append(e4b)

        # Simulate.
        self.eventStore.simulateAllEvents()
Ejemplo n.º 9
0
 def test_chain(self):
     self.store = EventStore([self.filename,
                              self.filename])
     rootfile = TFile(self.filename)
     events = rootfile.Get('events')
     numbers = []
     for iev, event in enumerate(self.store):
         evinfo = self.store.get("info")
         numbers.append(evinfo[0].Number())
     self.assertEqual(iev+1, 2*events.GetEntries())
     # testing that numbers is [0, .. 1999, 0, .. 1999]
     self.assertEqual(numbers, range(events.GetEntries())*2)
     # trying to go to an event beyond the last one
     self.assertRaises(ValueError, self.store.__getitem__,
                       4001)
     # this is in the first event in the second file,
     # so its event number should be 0.
     self.assertEqual(self.store[2000].get("info")[0].Number(), 0)
Ejemplo n.º 10
0
 def setUp(self):
     self.eventStore = EventStore.get()
     self.appStore = ApplicationStore.get()
     self.fileFactory = FileFactory.get()
     self.userConf = UserConfigLoader.get("user.ini")
     self.engine = PolicyEngine()
     self.ar1 = Application("ristretto.desktop",
                            pid=21,
                            tstart=1,
                            tend=2000)
     self.ar2 = Application("ristretto.desktop",
                            pid=22,
                            tstart=2600,
                            tend=2900)
     self.ag1 = Application("gimp.desktop", pid=23, tstart=1, tend=4000)
     self.ag2 = Application("gimp.desktop", pid=24, tstart=4500, tend=4590)
     self.appStore.insert(self.ar1)
     self.appStore.insert(self.ar2)
     self.appStore.insert(self.ag1)
     self.appStore.insert(self.ag2)
Ejemplo n.º 11
0
    id = (no & mask)
    id = id >> offset
    if (signed):
        id = id - 2**bitfieldsize if id >= 2**(bitfieldsize - 1) else id
    return id


def sublayer(cellId):
    # for bitfield system:4,subsystem:1,type:3,subtype:3,layer:8,sublayer:8,eta:10,phi:10
    return retrieve(cellId, 0b00000000000000000000111111110000000000000000000,
                    19)


if __name__ == "__main__":
    gSystem.Load("libdatamodelDict")
    store = EventStore(["positions_ecalNegativeEndcapSim.root"])

    for iev, event in enumerate(store):
        positions = event.get('caloPositions')
        for pos in positions:
            x = pos.position().x
            y = pos.position().y
            z = pos.position().z
            cellId = pos.core().cellId
            layerId = sublayer(cellId)
            # - 1 because the ID starts form ID=1
            layerId -= 1
            # detector begins at 5300, cryostat thickness of 50, bath of 90, margin 1.65, readout 1.2  => 5442.85
            if layerId == 0:
                # first active half-disc
                layer_z = -5443.1
Ejemplo n.º 12
0
    def setUp(self):
        self.userConf = UserConfigLoader.get("user.ini")
        self.appStore = ApplicationStore.get()
        self.eventStore = EventStore.get()
        self.fileStore = FileStore.get()
        self.fileFactory = FileFactory.get()
        self.sim = AttackSimulator()
        self.a1 = Application("ristretto.desktop", pid=1, tstart=1, tend=2000)
        self.a2 = Application("firefox.desktop", pid=2, tstart=1, tend=2000)
        self.a3 = Application("ristretto.desktop", pid=3, tstart=3000,
                              tend=6000)
        self.ac = Application("catfish.desktop", pid=100, tstart=1, tend=2900)
        self.appStore.insert(self.a1)
        self.appStore.insert(self.a2)
        self.appStore.insert(self.a3)
        self.appStore.insert(self.ac)

        self.p001 = "/home/user/.cache/firefox/file"
        s001 = "open64|%s|fd 10: with flag 524288, e0|" % self.p001
        e001 = Event(actor=self.a1, time=10, syscallStr=s001)
        e001.evflags &= ~EventFileFlags.designation  # not by designation
        self.eventStore.append(e001)
        e001b = Event(actor=self.a2, time=11, syscallStr=s001)
        e001b.evflags &= ~EventFileFlags.designation  # not by designation
        self.eventStore.append(e001b)

        self.p002 = "/home/user/Images/picture.jpg"
        s002 = "open64|%s|fd 10: with flag 524288, e0|" % self.p002
        e002 = Event(actor=self.a1, time=12, syscallStr=s002)
        e002.evflags &= ~EventFileFlags.designation  # not by designation
        self.eventStore.append(e002)
        e002b = Event(actor=self.ac, time=30, syscallStr=s002)
        e002b.evflags &= ~EventFileFlags.designation  # not by designation
        self.eventStore.append(e002b)

        self.p003 = "/home/user/Downloads/logo.jpg"
        s003 = "open64|%s|fd 10: with flag 524288, e0|" % self.p003
        e003 = Event(actor=self.a1, time=13, syscallStr=s003)
        e003.evflags |= EventFileFlags.designation  # this event by designation
        self.eventStore.append(e003)
        e003b = Event(actor=self.a3, time=3003, syscallStr=s003)
        e003b.evflags &= ~EventFileFlags.designation  # not by designation
        self.eventStore.append(e003b)

        self.p004 = "/home/user/Downloads/logo.png"
        s004 = "open64|%s|fd 10: with flag 64, e0|" % self.p004
        e004 = Event(actor=self.a1, time=14, syscallStr=s004)
        e004.evflags &= ~EventFileFlags.designation  # not by designation
        self.eventStore.append(e004)

        self.p005 = "/home/user/Dropbox/Photos/holidays.jpg"
        s005 = "open64|%s|fd 10: with flag 524288, e0|" % self.p005
        e005 = Event(actor=self.a1, time=15, syscallStr=s005)
        e005.evflags &= ~EventFileFlags.designation  # not by designation
        self.eventStore.append(e005)
        e005b = Event(actor=self.a1, time=1005, syscallStr=s005)
        e005b.evflags &= ~EventFileFlags.designation  # not by designation
        self.eventStore.append(e005b)

        self.p006 = "/home/user/Images/random.txt"
        s006 = "open64|%s|fd 10: with flag 524288, e0|" % self.p006
        e006 = Event(actor=self.a1, time=16, syscallStr=s006)
        e006.evflags &= ~EventFileFlags.designation  # not by designation
        self.eventStore.append(e006)

        self.p007 = "/home/user/Images/file.jpg"
        s007 = "open64|%s|fd 10: with flag 524288, e0|" % self.p007
        e007 = Event(actor=self.a1, time=17, syscallStr=s007)
        e007.evflags |= EventFileFlags.designation  # this event by designation
        self.eventStore.append(e007)

        self.p008 = "/home/user/Images/other.foo"
        s008 = "open64|%s|fd 10: with flag 64, e0|" % self.p008
        e008 = Event(actor=self.a1, time=18, syscallStr=s008)
        e008.evflags &= ~EventFileFlags.designation  # not by designation
        self.eventStore.append(e008)

        self.p009 = "/home/user/Downloads/unknown.data"
        s009 = "open64|%s|fd 10: with flag 64, e0|" % self.p009
        # e009 = Event(actor=self.a1, time=18, syscallStr=s009)
        # e009.evflags |= EventFileFlags.designation  # this event by designation
        # self.eventStore.append(e009)
        e009b = Event(actor=self.a3, time=3009, syscallStr=s009)
        e009b.evflags &= ~EventFileFlags.designation  # not by designation
        self.eventStore.append(e009b)

        self.p010 = "/home/user/Dropbox/Photos/holidays.metadata"
        s010 = "open64|%s|fd 10: with flag 524288, e0|" % self.p010
        e010 = Event(actor=self.a1, time=20, syscallStr=s010)
        e010.evflags &= ~EventFileFlags.designation  # not by designation
        self.eventStore.append(e010)

        self.p011 = "/home/user/Dropbox/Photos/holidays.evenmoremetadata"
        s011 = "open64|%s|fd 11: with flag 524288, e0|" % self.p011
        e011 = Event(actor=self.a3, time=3020, syscallStr=s011)
        e011.evflags &= ~EventFileFlags.designation  # not by designation
        self.eventStore.append(e011)

        self.eventStore.simulateAllEvents()

        self.acCache = AccessListCache.get()
        self.lookUps = dict()
        self.allowedCache = dict()
Ejemplo n.º 13
0
from ROOT import gSystem
from EventStore import EventStore

gSystem.Load("libdatamodelDict")
store = EventStore(["./out_fast_simple.root"])

for iev, event in enumerate(store):
    particles = event.get('smearedParticles')
    print(len(particles))
    assert (len(particles) > 0)
Ejemplo n.º 14
0
    return retrieve(sign, cellId, 0b000011110000,1*bitfieldsize)

def x(cellId, sign):
    return retrieve(sign, cellId, 0b111100000000,2*bitfieldsize)

def cellPosDd4hep(cellId, sign):
    if(sign):
        return array('d',(x(cellId, sign)*cellSize,y(cellId, sign)*cellSize,z(cellId, sign)*cellSize))
    return array('d',((x(cellId, sign)-cellNo/2)*cellSize,
                      (y(cellId, sign)-cellNo/2)*cellSize,
                      (z(cellId, sign)-cellNo/2)*cellSize))


if __name__ == "__main__":
    gSystem.Load("libdatamodelDict")
    storeSeg = EventStore(["testCellId_dd4hep_segmentation.root"])
    storeVol = EventStore(["testCellId_dd4hep_volumes.root"])

    segPos = []
    for iev, event in enumerate(storeSeg):
        hits = event.get('caloHits')
        for hit in hits:
            cellId = hit.Core().Cellid
            segPos.append(cellPosDd4hep(cellId,True))
    volPos = []
    for iev, event in enumerate(storeVol):
        hits = event.get('caloHits')
        for hit in hits:
            cellId = hit.Core().Cellid
            volPos.append(cellPosDd4hep(cellId,False))
    assert(segPos == volPos)
 def tearDown(self):
     EventStore.reset()
Ejemplo n.º 16
0
from ROOT import gSystem
from EventStore import EventStore
import csv

gSystem.Load("libdatamodelDict")

filename = "test"
store = EventStore([filename + ".root"])

with open(filename + '.csv', 'w') as csvfile:
    csv_writer = csv.writer(csvfile, delimiter=',')
    csv_writer.writerow(["x", "y", "z", "cellId", "energy", "time"])
    for event in store:
        hits = event.get("positionedHits")

        print "====================", hits.size()
        for i in range(0, hits.size()):
            print "x=", hits[i].position().x
            print "y=", hits[i].position().y
            print "z=", hits[i].position().z
            cellid = hits[i].core().cellId
            print "system=", cellid % 16
            #csv_writer.writerow([hits[i].position().x, hits[i].position().y, hits[i].position().z, hits[i].core().cellId, hits[i].core().energy, hits[i].core().time])

        bla = raw_input()
Ejemplo n.º 17
0
class EventStoreTestCase(unittest.TestCase):

    def setUp(self):
        self.filename = 'example1.root'
        self.assertTrue(os.path.isfile(self.filename))
        self.store = EventStore([self.filename])

    def test_eventloop(self):
        self.assertTrue(len(self.store) >= 0)
        self.assertEqual(self.store.current_store.getEntries(),
                         len(self.store))
        for iev, event in enumerate(self.store):
            self.assertTrue(True)
            if iev > 5:
                break

    def test_navigation(self):
        event0 = self.store[0]
        self.assertEqual(event0.__class__, self.store.__class__)

    def test_collections(self):
        evinfo = self.store.get("info")
        self.assertTrue(len(evinfo) > 0)
        particles = self.store.get("CollectionNotThere")
        self.assertFalse(particles)

    def test_read_only(self):
        hits = self.store.get("hits")
        # testing that one can't modify attributes in
        # read-only pods
        self.assertEqual(hits[0].energy(), 23.)
        hits[0].energy(10)
        self.assertEqual(hits[0].energy(), 10)  # oops
        # self.assertEqual(type(hits[0]), ConstExampleHit) # should be True

    def test_one_to_many(self):
        clusters = self.store.get("clusters")
        ref_hits = []
        # testing that cluster hits can be accessed and make sense
        for cluster in clusters:
            sume = 0
            for ihit in range(cluster.Hits_size()):
                hit = cluster.Hits(ihit)
                ref_hits.append(hit)
                sume += hit.energy()
            self.assertEqual(cluster.energy(), sume)
        hits = self.store.get("hits")
        # testing that the hits stored as a one to many relation
        # in the cluster can be found in the hit collection
        for hit in ref_hits:
            self.assertTrue(hit in hits)

    def test_hash(self):
        clusters = self.store.get("clusters")
        ref_hits = []
        # testing that cluster hits can be accessed and make sense
        for cluster in clusters:
            sume = 0
            for ihit in range(cluster.Hits_size()):
                hit = cluster.Hits(ihit)
                ref_hits.append(hit)
                sume += hit.energy()
            self.assertEqual(cluster.energy(), sume)
        hits = self.store.get("hits")
        if hits[0] == ref_hits[0]:
            self.assertEqual(hits[0].getObjectID().index,
                             ref_hits[0].getObjectID().index)
            self.assertEqual(hits[0].getObjectID().collectionID,
                             ref_hits[0].getObjectID().collectionID)
            self.assertEqual(hits[0].getObjectID(), ref_hits[0].getObjectID())
        # testing that the hits stored as a one to many relation
        # import pdb; pdb.set_trace()

    def test_chain(self):
        self.store = EventStore([self.filename,
                                 self.filename])
        rootfile = TFile(self.filename)
        events = rootfile.Get('events')
        numbers = []
        for iev, event in enumerate(self.store):
            evinfo = self.store.get("info")
            numbers.append(evinfo[0].Number())
        self.assertEqual(iev+1, 2*events.GetEntries())
        # testing that numbers is [0, .. 1999, 0, .. 1999]
        self.assertEqual(numbers, range(events.GetEntries())*2)
        # trying to go to an event beyond the last one
        self.assertRaises(ValueError, self.store.__getitem__,
                          4001)
        # this is in the first event in the second file,
        # so its event number should be 0.
        self.assertEqual(self.store[2000].get("info")[0].Number(), 0)

    def test_context_managers(self):
        with EventStore([self.filename]) as store:
            self.assertTrue(len(store) >= 0)
            self.assertTrue(store.isValid())

    def test_no_file(self):
        '''Test that non-accessible files are gracefully handled.'''
        with self.assertRaises(ValueError):
            self.store = EventStore('foo.root')
Ejemplo n.º 18
0
outtree.Branch("rechit_detid", rec_detid)
outtree.Branch("rechit_bits", rec_bits)

outtree.Branch("gen_pt", gen_pt)
outtree.Branch("gen_x", gen_x)
outtree.Branch("gen_y", gen_y)
outtree.Branch("gen_z", gen_z)
outtree.Branch("gen_eta", gen_eta)
outtree.Branch("gen_phi", gen_phi)
outtree.Branch("gen_energy", gen_energy)
outtree.Branch("gen_status", gen_status)
outtree.Branch("gen_pdgid", gen_pdgid)
outtree.Branch("gen_bits", gen_bits)

numEvent = 0
with EventStore([infile_name
                 ]) as evs:  # p.ex output of Examples/options/simple_pythia.py
    for ev in evs:

        ev_num[0] = numEvent
        numHits = 0
        E = .0
        Ebench = .0
        Eem = .0
        Ehad = .0
        EemLast = .0
        EhadFirst = .0
        etaGen = .0
        phiGen = .0
        energyGen = .0

        if ev.get("GenParticles"):
Ejemplo n.º 19
0
def main():
    import argparse

    #parse arguments from command line

    parser = argparse.ArgumentParser(
        description=
        'This script does some validation plotting. One can simply pass teh input digit file and get some histograms. If one also passes the hits file, one gets direct comparisons of the two estimates of quantities'
    )

    parser.add_argument(
        '--input',
        dest='ifile',
        help=
        'Input file name. Leave empty to run with no input file (for example to debug sensor properties)'
    )
    parser.add_argument('--outputROOT',
                        dest='ofile',
                        help='Output file name',
                        default='output_digit.podio.root')
    parser.add_argument('--inputHits',
                        dest='hitfile',
                        help='Optiona input hits file')
    parser.add_argument('--debug',
                        action='store_true',
                        dest='debug',
                        default=False,
                        help='Print more debugging information')
    parser.add_argument('--outputPdf',
                        dest='outPDF',
                        default='validation_output.pdf',
                        help='Name of teh output pdf file')

    par = parser.parse_args()

    filename = par.ifile
    hitfilename = par.hitfile
    ofilename = par.ofile

    store = EventStore(filename)
    storehit = None

    ofile = ROOT.TFile(ofilename, "recreate")
    ofile.mkdir("Digitization")

    ofile.cd("Digitization")

    h_list = []

    h_c_fiber_energy = ROOT.TH1F("h_c_fiber_energy", "", 100, 0, -1)
    h_c_fiber_energy.SetXTitle("Individual C fibre energy (arbitrary units)")
    h_list.append(h_c_fiber_energy)
    h_s_fiber_energy = ROOT.TH1F("h_s_fiber_energy", "", 100, 0, -1)
    h_s_fiber_energy.SetXTitle("Individual S fibre energy (arbitrary units)")
    h_list.append(h_s_fiber_energy)
    h_c_fiber_time = ROOT.TH1F("h_c_fiber_time", "", 100, 0, -1)
    h_c_fiber_time.SetXTitle("Individual C fibre time [ns]")
    h_list.append(h_c_fiber_time)
    h_s_fiber_time = ROOT.TH1F("h_s_fiber_time", "", 100, 0, -1)
    h_s_fiber_time.SetXTitle("Individual S fibre time [ns]")
    h_list.append(h_s_fiber_time)

    h_c_energy = ROOT.TH1F("h_c_energy", "", 100, 0, -1)
    h_c_energy.SetXTitle("Total C Energy (a.u.)")
    h_list.append(h_c_energy)
    h_s_energy = ROOT.TH1F("h_s_energy", "", 100, 0, -1)
    h_s_energy.SetXTitle("Total S Energy (a.u.)")
    h_list.append(h_s_energy)
    h_c_time = ROOT.TH1F("h_c_time", "", 100, 0, -1)
    h_c_time.SetXTitle("Average C time [ns]")
    h_list.append(h_c_time)
    h_s_time = ROOT.TH1F("h_s_time", "", 100, 0, -1)
    h_s_time.SetXTitle("Average C time [ns]")
    h_list.append(h_s_time)

    h_n_s_fiber = ROOT.TH1F("h_n_s_fiber", "", 100, 0, -1)
    h_n_s_fiber.SetXTitle("S fibre multiplicity")
    h_list.append(h_n_s_fiber)
    h_n_c_fiber = ROOT.TH1F("h_n_c_fiber", "", 100, 0, -1)
    h_n_c_fiber.SetXTitle("C fibre multiplicity")
    h_list.append(h_n_c_fiber)

    c = ROOT.TCanvas()

    if hitfilename != None:
        storehit = EventStore(hitfilename)
        ofile.mkdir("DigiVsHits")
        ofile.cd("DigiVsHits")
        h_c_ratio_simdigi = ROOT.TH1F("h_c_ratio_simdigi", "", 100, 0, -1)
        h_c_ratio_simdigi.SetXTitle("Hit energy/Digi energy")
        h_list.append(h_c_ratio_simdigi)
        h_s_ratio_simdigi = ROOT.TH1F("h_s_ratio_simdigi", "", 100, 0, -1)
        h_s_ratio_simdigi.SetXTitle("Hit energy/Digi energy")
        h_list.append(h_s_ratio_simdigi)

    for i, event in enumerate(store):
        if i % 1000 == 0:
            print('reading event', i)
        c_hits = event.get("C_CalorimeterHits")
        s_hits = event.get("S_CalorimeterHits")
        tot_s_energy = 0
        tot_c_energy = 0
        tot_s_time = 0
        tot_c_time = 0
        n_s_fiber = 0
        n_c_fiber = 0
        for hit in c_hits:
            h_c_fiber_energy.Fill(hit.getEnergy())
            h_c_fiber_time.Fill(hit.getTime())
            tot_c_energy = tot_c_energy + hit.getEnergy()
            tot_c_time = tot_c_time + hit.getTime()
            n_c_fiber = n_c_fiber + 1
        for hit in s_hits:
            h_s_fiber_energy.Fill(hit.getEnergy())
            h_s_fiber_time.Fill(hit.getTime())
            tot_s_energy = tot_s_energy + hit.getEnergy()
            tot_s_time = tot_s_time + hit.getTime()
            n_s_fiber = n_s_fiber + 1

        if (n_s_fiber != 0):
            tot_s_time = tot_s_time / n_s_fiber
        if (n_c_fiber != 0):
            tot_c_time = tot_c_time / n_c_fiber

        h_c_energy.Fill(tot_c_energy)
        h_s_energy.Fill(tot_s_energy)
        h_c_time.Fill(tot_c_time)
        h_s_time.Fill(tot_s_time)

        h_n_s_fiber.Fill(n_s_fiber + 0.5)
        h_n_c_fiber.Fill(n_c_fiber + 0.5)

        # ok done, now let's try to access the hits as well

        if hitfilename != None:

            eventhits = storehit[i]
            c_simhits = eventhits.get("C_caloHits")
            s_simhits = eventhits.get("S_caloHits")

            tot_s_hitenergy = 0
            tot_c_hitenergy = 0

            for hit in c_simhits:
                tot_c_hitenergy = tot_c_hitenergy + hit.getEnergy()
            for hit in s_simhits:
                tot_s_hitenergy = tot_s_hitenergy + hit.getEnergy()

            if (tot_c_energy != 0):
                h_c_ratio_simdigi.Fill(tot_c_hitenergy / tot_c_energy)
            if (tot_s_energy != 0):
                h_s_ratio_simdigi.Fill(tot_s_hitenergy / tot_s_energy)

    c.Print(par.outPDF + '[')
    for h in h_list:
        c.Clear()
        h.Draw()
        c.Print(par.outPDF)
    c.Print(par.outPDF + ']')

    ofile.Write()
    ofile.Close()
Ejemplo n.º 20
0
 def test_no_file(self):
     '''Test that non-accessible files are gracefully handled.'''
     with self.assertRaises(ValueError):
         self.store = EventStore('foo.root')
Ejemplo n.º 21
0
from ROOT import gSystem
from EventStore import EventStore

gSystem.Load("libdatamodelDict")
storeExt = EventStore(["out_simpleTrackerSD_2cm.root"])
for iev, event in enumerate(storeExt):
    genptcs = event.get('allGenParticles')
    assert (len(genptcs) == 1.)
    hits = event.get('hits')
    hitsExt = len(hits)

storeInt = EventStore(["out_simpleTrackerSD_2cm.root"])
for iev, event in enumerate(storeInt):
    genptcs = event.get('allGenParticles')
    assert (len(genptcs) == 1.)
    hits = event.get('hits')
    hitsInt = len(hits)

assert (hitsExt == hitsInt)
Ejemplo n.º 22
0
def z(cellId):
    return retrieve(cellId, 0b000000000000111111,0)

def y(cellId):
    return retrieve(cellId, 0b000000111111000000,1*bitfieldsize)

def x(cellId):
    return retrieve(cellId, 0b111111000000000000,2*bitfieldsize)

def cell(cellId):
    return array('d',(x(cellId),y(cellId),z(cellId)))

if __name__ == "__main__":
    gSystem.Load("libdatamodelDict")
    store1 = EventStore(["./out_dd4hepTrackerSD_2cm.root"])
    store2 = EventStore(["./out_simpleTrackerSD_2cm.root"])
    bins = array('i',(cellNo, cellNo, cellNo))
    axisMin = array('d',(-cellNo/2-0.5, -cellNo/2-0.5, -cellNo/2-0.5))
    axisMax = array('d',(cellNo/2+0.5, cellNo/2+0.5, cellNo/2+0.5))
    hist1 = THnSparseD('hist1','hist1', 3, bins, axisMin, axisMax)
    hist2 = THnSparseD('hist2','hist2', 3, bins, axisMin, axisMax)
    for iev, event in enumerate(store1):
        hits = event.get('hits')
        for hit in hits:
            cellId = hit.cellId()
            hE = hit.energy()
            hist1.Fill(cell(cellId),hE)
    for iev, event in enumerate(store2):
        hits = event.get('hits')
        for hit in hits:
Ejemplo n.º 23
0
import unittest
from EventStore import EventStore

if __name__ == '__main__':

    filename = 'example.root'
    store = EventStore([filename])
    for i, event in enumerate(store):
        if i % 1000 == 0:
            print 'reading event', i
        evinfo = store.get("info")[0]
        clusters = store.get("clusters")
        for cluster in clusters:
            for ihit in range(cluster.Hits_size()):
                hit = cluster.Hits(ihit)
                print ' Referenced hit has an energy of', hit.energy()
Ejemplo n.º 24
0
from ROOT import gSystem
from EventStore import EventStore

gSystem.Load("libdatamodelDict")
store = EventStore(['out_full_moreEvents.root'])

entries = [300, 622, 942, 152, 135, 233, 501, 286, 77, 820]

for iev, event in enumerate(store):
    if (iev < 10):
        particles = event.get('allGenParticles')
        print(entries[iev], len(particles))
        assert (len(particles) == entries[iev])
Ejemplo n.º 25
0
    id = (no & mask)
    id = id >> offset
    if (signed):
        id = id - 2**bitfieldsize if id >= 2**(bitfieldsize - 1) else id
    return id


def sublayer(cellId):
    # for bitfield system:4,subsystem:1,type:3,subtype:3,layer:8,sublayer:8,eta:10,phi:10
    return retrieve(cellId, 0b00000000000000000000111111110000000000000000000,
                    19)


if __name__ == "__main__":
    gSystem.Load("libdatamodelDict")
    store = EventStore(["positions_ecalEndcapSim.root"])

    for iev, event in enumerate(store):
        positions = event.get('caloPositions')
        for pos in positions:
            x = pos.position().x
            y = pos.position().y
            z = pos.position().z
            cellId = pos.core().cellId
            layerId = sublayer(cellId)
            # - 1 because the sublayer ID starts form ID=1
            layerId -= 1
            # detector begins at 5300, cryostat thickness of 50, bath of 90, margin 1.65, readout 1.2  => 5442.85
            if layerId == 0:
                # first active half-disc
                layer_z = 5443.1
Ejemplo n.º 26
0
from EventStore import EventStore
import os.path
import numpy as np

gROOT.ProcessLine(".L ~/CLICdpStyle/rootstyle/CLICdpStyle.C")
CLICdpStyle()
gStyle.SetOptStat(0)
gStyle.SetPadRightMargin(0.17)
gROOT.ForceStyle()

histNbLayers = TH2F("nb. of layers", "; #phi [deg]; Number of wires", 1440,
                    -180, 180, 5, 0, 5)
hist = TH1F("nb. of layers", "; #phi [deg]; Number of wires", 180, -180, 180)

filename = "/afs/cern.ch/work/n/nali/Fellow/SoftwareFCC/FCCSW/angleScan_layer1.root"
store = EventStore([filename])

pos = {}

for event in store:
    hits = event.get("positionedHits")

    phi = []
    nb = hits.size()
    #print "hit: ", hits.size()
    for i in range(0, hits.size()):
        xpos = hits[i].position().x
        ypos = hits[i].position().y
        cellID = hits[i].core().cellId

        pos[cellId].append((x, y, z))
Ejemplo n.º 27
0
from ROOT import gSystem
from EventStore import EventStore

gSystem.Load("libdatamodelDict")
#store = EventStore(["./pythia_test.root"])
store_after = EventStore(["./test.root"])
#print store
print(store_after)

for event in store_after:

    particles_before = event.get("allGenParticles")
    print(len(particles_before))
 def setUp(self):
     self.store = EventStore.get()
Ejemplo n.º 29
0
class EventStoreTestCase(unittest.TestCase):

  def setUp(self):
    self.filename = str('example.root')
    self.assertTrue(os.path.isfile(self.filename))
    self.store = EventStore([self.filename])

  def test_eventloop(self):
    self.assertTrue(len(self.store) >= 0)
    self.assertEqual(self.store.current_store.getEntries(),
                     len(self.store))
    for iev, event in enumerate(self.store):
      self.assertTrue(True)
      if iev > 5:
        break

  def test_navigation(self):
    event0 = self.store[0]
    self.assertEqual(event0.__class__, self.store.__class__)

  def test_collections(self):
    evinfo = self.store.get("info")
    self.assertTrue(len(evinfo) > 0)
    particles = self.store.get("CollectionNotThere")
    self.assertFalse(particles)

  def test_read_only(self):
    hits = self.store.get("hits")
    # testing that one can't modify attributes in
    # read-only pods
    self.assertEqual(hits[0].energy(), 23.)
    hits[0].energy(10)
    self.assertEqual(hits[0].energy(), 10)  # oops

  def test_one_to_many(self):
    clusters = self.store.get("clusters")
    ref_hits = []
    # testing that cluster hits can be accessed and make sense
    for cluster in clusters:
      sume = 0
      for ihit in range(cluster.Hits_size()):
        hit = cluster.Hits(ihit)
        ref_hits.append(hit)
        sume += hit.energy()
      self.assertEqual(cluster.energy(), sume)
    hits = self.store.get("hits")
    # testing that the hits stored as a one to many relation
    # in the cluster can be found in the hit collection
    for hit in ref_hits:
      self.assertTrue(hit in hits)

  def test_relation_range(self):
    """Test that the RelationRange functionality is also accessible in python"""
    clusters = self.store.get("clusters")
    hits = self.store.get("hits")

    for cluster in clusters:
      sume = 0
      for hit in cluster.Hits():
        self.assertTrue(hit in hits)
        sume += hit.energy()
      self.assertEqual(cluster.energy(), sume)

  def test_hash(self):
    clusters = self.store.get("clusters")
    ref_hits = []
    # testing that cluster hits can be accessed and make sense
    for cluster in clusters:
      sume = 0
      for ihit in range(cluster.Hits_size()):
        hit = cluster.Hits(ihit)
        ref_hits.append(hit)
        sume += hit.energy()
      self.assertEqual(cluster.energy(), sume)
    hits = self.store.get("hits")
    if hits[0] == ref_hits[0]:
      self.assertEqual(hits[0].getObjectID().index,
                       ref_hits[0].getObjectID().index)
      self.assertEqual(hits[0].getObjectID().collectionID,
                       ref_hits[0].getObjectID().collectionID)
      self.assertEqual(hits[0].getObjectID(), ref_hits[0].getObjectID())
    # testing that the hits stored as a one to many relation
    # import pdb; pdb.set_trace()

  def test_chain(self):
    self.store = EventStore([self.filename,
                             self.filename])
    rootfile = TFile(self.filename)
    events = rootfile.Get(str('events'))
    numbers = []
    for iev, event in enumerate(self.store):
      evinfo = self.store.get("info")
      numbers.append(evinfo[0].Number())
    self.assertEqual(iev + 1, 2 * events.GetEntries())
    # testing that numbers is [0, .. 1999, 0, .. 1999]
    self.assertEqual(numbers, list(range(events.GetEntries())) * 2)
    # trying to go to an event beyond the last one
    self.assertRaises(ValueError, self.store.__getitem__, 4001)
    # this is in the first event in the second file,
    # so its event number should be 0.
    self.assertEqual(self.store[2000].get("info")[0].Number(), 0)

  def test_context_managers(self):
    with EventStore([self.filename]) as store:
      self.assertTrue(len(store) >= 0)
      self.assertTrue(store.isValid())

  def test_no_file(self):
    '''Test that non-accessible files are gracefully handled.'''
    with self.assertRaises(ValueError):
      self.store = EventStore('foo.root')
Ejemplo n.º 30
0
import unittest
from EventStore import EventStore

if __name__ == '__main__':
    
    filename = 'example.root'
    store = EventStore([filename])
    for i, event in enumerate(store):
        if i%1000 == 0:
            print 'reading event', i
        evinfo = store.get("info")[0]
        clusters = store.get("clusters")
        for cluster in clusters:
            for ihit in range(cluster.Hits_size()):
                hit = cluster.Hits(ihit)
                print ' Referenced hit has an energy of', hit.energy()
Ejemplo n.º 31
0
 def test_context_managers(self):
   with EventStore([self.filename]) as store:
     self.assertTrue(len(store) >= 0)
     self.assertTrue(store.isValid())
histFCC_1 = TH1F("FCCee_1", "; z [mm]; hits / cm^{2} / BX", 25, -125, 125)
histFCC_2 = TH1F("FCCee_2", "; z [mm]; hits / cm^{2} / BX", 25, -125, 125)
histFCC_3 = TH1F("FCCee_3", "; z [mm]; hits / cm^{2} / BX", 25, -125, 125)
histFCC_4 = TH1F("FCCee_4", "; z [mm]; hits / cm^{2} / BX", 25, -125, 125)
histFCC_5 = TH1F("FCCee_5", "; z [mm]; hits / cm^{2} / BX", 25, -125, 125)
histFCC_6 = TH1F("FCCee", "; z [mm]; hits / cm^{2} / BX", 25, -125, 125)
histR_2d = TH2F("FCCee", "; z [mm]; Radius [mm]", 25, -125, 125, 6, 0, 60)
histR = TH1F("FCCee", "; Radius [mm]; Occupancy", 6, 0, 60)

index = 22

directory = "shielding"
fcc_file_name = "/afs/cern.ch/work/n/nali/Fellow/SoftwareFCC/FCCSW/SimuOutput/" + directory + "/allEvents.root"

store = EventStore([fcc_file_name])

radius_1 = 1  # cm
radius_2 = 1  # cm
radius_3 = 1  # cm
radius_4 = 1  # cm
radius_5 = 1  # cm
radius_6 = 1  # cm

for event in store:
    hits = event.get(readout)

    for i in range(0, hits.size()):
        energy = hits[i].core().energy * 1e6
        cellid = hits[i].core().cellId
        zpos = hits[i].position().z
Ejemplo n.º 33
0
 def test_no_file(self):
   '''Test that non-accessible files are gracefully handled.'''
   with self.assertRaises(ValueError):
     self.store = EventStore('foo.root')
Ejemplo n.º 34
0
def cellPosGdml(cellId):
    z = (cellId % cellNo - cellNo / 2) * cellSize
    x = ((cellId / (cellNo * cellNo)) - cellNo / 2) * cellSize
    y = ((cellId / cellNo % cellNo) - cellNo / 2) * cellSize
    return array('d', (x, y, z))


def cmpId(cellIdGdml, cellIdDd4hep):
    IdGdml = cellIdGdml(cellIdGdml)
    IdDd4hep = cellIdDd4hep(cellIdDd4hep)
    return bool(IdGdml == IdDd4hep)


if __name__ == "__main__":
    gSystem.Load("libdatamodelDict")
    storeGdml = EventStore(["testCellId_gdml.root"])
    storeDD4hep = EventStore(["testCellId_dd4hep.root"])

    gdmlPos = []
    for iev, event in enumerate(storeGdml):
        hits = event.get('caloHits')
        for hit in hits:
            cellId = hit.Core().Cellid
            gdmlPos.append(cellPosGdml(cellId))
    dd4hepPos = []
    for iev, event in enumerate(storeDD4hep):
        hits = event.get('caloHits')
        for hit in hits:
            cellId = hit.Core().Cellid
            dd4hepPos.append(cellPosDd4hep(cellId))
    assert (gdmlPos == dd4hepPos)
Ejemplo n.º 35
0
"""
Quick script to dump FCCSW tracker validation data to plaintext spacepoints.
Requires podio, fcc-edm in pythonpath and ld-library-path.
"""

from EventStore import EventStore
import numpy as np
import sys

filename = sys.argv[1]
basefilename = filename.replace(".root", "")
events = EventStore([filename])
print 'number of events: ', len(events)
pos_b = []
ids_b = []
pos_e = []
ids_e = []
barrel_ids = []
nEventsMax = 100000
#nEventsMax = 1
for i, store in enumerate(events):

    # Only run over 100000 events
    if i > nEventsMax:
        break

    # <class 'ROOT.fcc.PositionedTrackHitCollection'>
    clusters = store.get('positionedHits')

    #print clusters
    layerIdmax = 0
Ejemplo n.º 36
0
 def setUp(self):
     self.filename = 'example.root'
     self.assertTrue( os.path.isfile(self.filename) )
     self.store = EventStore(self.filename)
Ejemplo n.º 37
0
print "creating root file and trees ..."
f = ROOT.TFile(args.output, "recreate")
t = ROOT.TTree('processedEvents', 'tree with processed fcc data')
psvb = t.Branch("primaryStartVertices", primaryStartVertexVector)
pevb = t.Branch("primaryEndVertices", primaryEndVertexVector)
ssvb = t.Branch("secondaryStartVertices", secondaryStartVertexVector)
sevb = t.Branch("secondaryEndVertices", secondaryEndVertexVector)
hb = t.Branch("hitProducingStartVertices", hitProducingStartVertices)


def r(point):
    return np.sqrt(point.x**2 + point.y**2 + point.z**2)


events = EventStore([args.filename])
if args.nevents == -1:
    args.nevents = len(events)
print len(events), " events in rootfile ", args.filename

j = 0
k = 0
print ""
for i, store in enumerate(events):
    print ".",
    if i > args.nevents:
        break
    trackId2Vertex = {}
    trackId2Particle = {}
    graph = nx.DiGraph()
    simparticles = store.get("simParticles")