Exemple #1
0
def staff():

    staff = ROOT.staff_t()

    # The input file cern.dat is a copy of the CERN staff data base
    # from 1988

    f = TFile('staff.root', 'RECREATE')
    tree = TTree('T', 'staff data from ascii file')
    tree.Branch('staff', staff,
                'Category/I:Flag:Age:Service:Children:Grade:Step:Hrweek:Cost')
    tree.Branch('Divisions', addressof(staff, 'Division'), 'Division/C')
    tree.Branch('Nation', addressof(staff, 'Nation'), 'Nation/C')

    # note that the branches Division and Nation cannot be on the first branch
    fname = os.path.join(str(ROOT.gROOT.GetTutorialDir()), 'tree',
                         'cernstaff.dat')
    for line in open(fname).readlines():
        t = list(filter(lambda x: x, re.split('\s+', line)))
        staff.Category = int(t[0])  # assign as integers
        staff.Flag = int(t[1])
        staff.Age = int(t[2])
        staff.Service = int(t[3])
        staff.Children = int(t[4])
        staff.Grade = int(t[5])
        staff.Step = int(t[6])
        staff.Hrweek = int(t[7])
        staff.Cost = int(t[8])
        staff.Division = t[9]  # assign as strings
        staff.Nation = t[10]

        tree.Fill()

    tree.Print()
    tree.Write()
Exemple #2
0
def make_prim_tree():

    #input
    #inp = TFile.Open("../../lmon.root")
    inp = TFile.Open("../../data/ew/ew1bx1.root")
    tree = inp.Get("DetectorTree")

    #number of events, negative for all
    nev = -1

    #output
    out = TFile("prim_bx1.root", "recreate")
    gROOT.ProcessLine("struct EntryF {Float_t v;};")
    x = rt.EntryF()
    y = rt.EntryF()
    z = rt.EntryF()
    en = rt.EntryF()
    otree = TTree("prim_tree", "prim_tree")
    otree.Branch("x", addressof(x, "v"), "x/F")
    otree.Branch("y", addressof(y, "v"), "y/F")
    otree.Branch("z", addressof(z, "v"), "z/F")
    otree.Branch("en", addressof(en, "v"), "en/F")

    hits = ew_hits("ew", tree)

    if nev < 0: nev = tree.GetEntries()
    for ievt in range(nev):
        tree.GetEntry(ievt)

        #print("Next event")

        for ihit in range(hits.get_n()):

            hit = hits.get_hit(ihit)

            #hit by primary photon
            if hit.prim == 0 or hit.pdg != 22: continue

            hit.global_to_zpos(-18644)  # mm

            x.v = hit.x
            y.v = hit.y
            z.v = hit.z
            z.en = hit.en

            otree.Fill()

            #print(hit.x, hit.y, hit.z) # , hit.en
            #print(hit.pdg, hit.prim, hit.conv)

            #only first hit by primary particle
            break

    otree.Write()
    out.Close()
Exemple #3
0
    def test12VoidPointerPassing(self):
        """Test passing of variants of void pointer arguments"""

        gROOT.LoadMacro("PointerPassing.C+")

        Z = ROOT.Z

        o = TObject()
        oaddr = addressof(o)

        self.assertEqual(oaddr, Z.GimeAddressPtr(o))
        self.assertEqual(oaddr, Z.GimeAddressPtrRef(o))

        pZ = Z.getZ(0)
        self.assertEqual(Z.checkAddressOfZ(pZ), True)
        self.assertEqual(pZ, Z.getZ(1))

        import array
        # Not supported in p2.2
        # and no 8-byte integer type array on Windows 64b
        if hasattr(array.array, 'buffer_info') and IS_WINDOWS != 64:
            if not self.legacy_pyroot:
                # New cppyy uses unsigned long to represent void* returns, as in DynamicCast.
                # To prevent an overflow error when converting the Python integer returned by
                # DynamicCast into a 4-byte signed long in 32 bits, we use unsigned long ('L')
                # as type of the array.array.
                array_t = 'L'
            else:
                # Old PyROOT returns Long_t buffers for void*
                array_t = 'l'
            addressofo = array.array(
                array_t, [o.IsA()._TClass__DynamicCast(o.IsA(), o)[0]])
            self.assertEqual(addressofo.buffer_info()[0],
                             Z.GimeAddressPtrPtr(addressofo))

        self.assertEqual(0, Z.GimeAddressPtr(0))
        self.assertEqual(0, Z.GimeAddressObject(0))
        if self.legacy_pyroot:
            # The conversion None -> ptr is not supported in new Cppyy
            self.assertEqual(0, Z.GimeAddressPtr(None))
            self.assertEqual(0, Z.GimeAddressObject(None))

        ptr = MakeNullPointer(TObject)
        if not self.legacy_pyroot:
            # New Cppyy does not raise ValueError,
            # it just returns zero
            self.assertEqual(addressof(ptr), 0)
        else:
            self.assertRaises(ValueError, AddressOf, ptr)
        Z.SetAddressPtrRef(ptr)

        self.assertEqual(addressof(ptr), 0x1234)
        Z.SetAddressPtrPtr(ptr)
        self.assertEqual(addressof(ptr), 0x4321)
Exemple #4
0
    def test09_write_struct_separate_branches(self):
        f, t = self.create_file_and_tree()

        ms = ROOT.MyStruct()
        ms.myint1, ms.myint2 = self.ival, 2 * self.ival

        # Use `addressof` to get the address of the struct members
        t.Branch('myint1b', addressof(ms, 'myint1'), 'myint1balias/I')
        t.Branch('myint2b', addressof(ms, 'myint2'), 'myint2balias/I')

        self.fill_and_close(f, t)
Exemple #5
0
    def make_root(self, parse):

        #ROOT output

        nam = parse.get("main", "nam").strip("\"'") + ".root"
        print("ROOT output name:", nam)

        self.out_root = TFile(nam, "recreate")
        #tree variables, all Double_t
        tlist = ["phot_en", "phot_theta", "phot_phi"]
        tlist += ["el_en", "el_theta", "el_phi"]
        #C structure holding the variables
        struct = "struct tree_out { Double_t "
        for i in tlist:
            struct += i + ", "
        struct = struct[:-2] + ";};"
        gROOT.ProcessLine(struct)
        #create the output tree
        self.tree_out = rt.tree_out()  # instance of the C structure
        self.ltree = TTree("ltree", "ltree")
        for i in tlist:
            exec("self.tree_out." + i + "=0")
            self.ltree.Branch(i, addressof(self.tree_out, i), i + "/D")

        #particles array
        self.particles_out = TClonesArray("TParticle")
        self.particles_out.SetOwner(True)
        self.ltree.Branch("particles", self.particles_out)

        atexit.register(self.close_root)
   def test05WriteSomeDataObjectBranched( self ):
      """Test writing of a complex object across different branches"""

      f = TFile( self.fname, 'RECREATE' )
      t = TTree( self.tname, self.ttitle )

      d = SomeDataStruct()

    # note: for p2.2, which has incomplete support of property types,
    # we need to keep a reference alive to the result of the property
    # call, or it will be deleted too soon; for later pythons, it is
    # safe to use d.Floats directly in the Branch() call
      fl = d.Floats
      t.Branch( 'floats', fl )

      if exp_pyroot:
          # The Branch pythonization expects an integer with the
          # address of the field of the struct
          addressof_nlabel = addressof( d, 'NLabel' )
          addressof_label  = addressof( d, 'Label' )
      else:
          # Old PyROOT has a bug in AddressOf(o, 'field').
          # Instead of returning a buffer whose first position
          # contains the address of the field, it just returns the
          # address of the field (which is what we need here).
          # addressof(o, 'field'), which is what we should really
          # use, is also broken in old PyROOT, so we need to use
          # AddressOf here
          addressof_nlabel = AddressOf( d, 'NLabel' )
          addressof_label  = AddressOf( d, 'Label' )

      t.Branch( 'nlabel', addressof_nlabel, 'NLabel/I' )
      t.Branch( 'label',  addressof_label,  'Label/C' )

      for i in range( self.N ):
         for j in range( self.M ):
            d.Floats.push_back( i*self.M+j )

         d.NLabel = i
         d.Label  = '%d' % i

         t.Fill()

      f.Write()
      f.Close()
Exemple #7
0
def make_branch(name, tree, entry, dat="D"):

    #create tree branch of a given data type

    x = entry()
    x.v = 0
    tree.Branch(name, addressof(x, "v"), name + "/" + dat)

    return x
Exemple #8
0
    def test14OpaquePointerPassing(self):
        """Test passing around of opaque pointers"""

        import ROOT

        s = TString("Hello World!")
        co = AsCObject(s)

        ad = addressof(s)

        self.assert_(s == BindObject(co, s.__class__))
        self.assert_(s == BindObject(co, "TString"))
        self.assert_(s == BindObject(ad, s.__class__))
        self.assert_(s == BindObject(ad, "TString"))
Exemple #9
0
    def make_tree(self, tree, tnam):

        #create the tree variables
        tcmd = "struct gen_out { Double_t "
        for i in tnam:
            tcmd += i + ", "
        tcmd = tcmd[:-2] + ";};"
        gROOT.ProcessLine( tcmd )
        self.out = rt.gen_out()

        #put zero to all variables
        for i in tnam:
            exec("self.out."+i+"=0")

        #set the variables in the tree
        if tree is not None:
            for i in tnam:
                tree.Branch(i, addressof(self.out, i), i+"/D")

        return self.out
	def __init__(self, runNum, nuPrdStrt, outputFilename="nuStorm.root"):
# first a TTree with the run information - written once
		self.outputFilename = outputFilename
		self.outfile = TFile( self.outputFilename, 'RECREATE', 'ROOT file with an NTuple' )
# first a TTree with the run information - written once
		self.runInfo = ROOT.information()
		self.infoTree = TTree('runInfo', 'run information')
		self.infoTree.Branch( 'information', self.runInfo, 'runNumber/F:Version:FluxPlaneW:FluxPlaneH:PZ:DetectW:DetecH:DetecD:DetecZ:Emit')
#		self.infoTree.Branch( 'Flux Plane', AddressOf( self.runInfo, 'PWidth'), 'Width/F:Height:Z')
#		self.infoTree.Branch( 'Detector Box', AddressOf( self.runInfo, 'DBWidth'), 'Width/F:Height:Depth:Z')

# Parameters for the run
		self.runInfo.runNumber = runNum
		self.runInfo.Version = self.Version

# Parameters for the flux plane
		self.runInfo.PWidth = 10.0
		self.runInfo.PHeight = 10.0
		self.runInfo.PZ = nuPrdStrt.HallWallDist()
# Parameters for the detector box
		self.runInfo.DBWidth = nuPrdStrt.DetHlfWdth()*2.0
		self.runInfo.DBHeight = nuPrdStrt.DetHlfWdth()*2.0
		self.runInfo.DBDepth = nuPrdStrt.DetLngth()
		self.runInfo.DBZ = nuPrdStrt.Hall2Det()
		self.emittanceUnits = 'mm'

		self.infoTree.Fill()
		self.infoTree.Write()

# a TTree for the production data from every event
		self.event = ROOT.event_t()
		self.evTree = TTree('beam', 'nuStorm Event')
		self.evTree.Branch( 'pion', self.event, 'E/F:pX:pY:pZ' )
		self.evTree.Branch( 'muon', addressof( self.event, 'Emu'), 'E/F:pX:pY:pZ' )
		self.evTree.Branch( 'Decay', addressof( self.event, 's'), 's/F:x:y:z:xp:yp:t')
		self.evTree.Branch( 'Electron', addressof( self.event, 'Ee'), 'E/F:pX:pY:pZ')
		self.evTree.Branch( 'NuMu', addressof( self.event, 'Enumu'), 'E/F:pX:pY:pZ')
		self.evTree.Branch( 'Nue', addressof( self.event, 'Enue'), 'E/F:pX:pY:pZ')

# a TTree for the flux data
		self.flux = ROOT.flux_t()
		self.fluxTree = TTree('flux', 'nuStorm Event')
		self.fluxTree.Branch( 'NuE', addressof( self.flux, 'nuEx'), 'x/F:y:px:py:pz:E')
		self.fluxTree.Branch( 'NuMu', addressof( self.flux, 'nuMux'), 'x/F:y:px:py:pz:E')
   def test13WriteMisnamedLeaf( self ):
      """Test writing of an differently named leaf"""

      f = TFile( self.fname, 'RECREATE' )
      t = TTree( self.tname, self.ttitle )
      s = SomeDataStruct()

      # Same reason for this difference as in test05WriteSomeDataObjectBranched
      if exp_pyroot:
         addressof_nlabel = addressof(s, 'NLabel')
      else:
         addressof_nlabel = AddressOf(s, 'NLabel')

      t.Branch( 'cpu_packet_time', addressof_nlabel, 'time/I' );

      for i in range(self.N):
         s.NLabel = i
         t.Fill()

      f.Write()
      f.Close()
Exemple #12
0
    def set_tree(self, tree, tlist):

        #set output to the tree

        #tree variables
        struct = "struct gen_Lifshitz_93p16 { Double_t "
        for i in tlist:
            struct += i + ", "
        struct = struct[:-2] + ";};"
        gROOT.ProcessLine(struct)
        tree_out = rt.gen_Lifshitz_93p16()

        #put zero to all variables
        for i in tlist:
            exec("tree_out." + i + "=0")

        #add variables to the tree
        if tree is not None:
            for i in tlist:
                tree.Branch(i, addressof(tree_out, i), i + "/D")

        return tree_out
Exemple #13
0
    ")

#Creo oggetti su python
evid = ctypes.c_int()  #per interi o double singoli basta chiamare ctype
plab = ROOT.p()
xs = ROOT.sigma()

f = TFile('hfile.root', 'recreate')  #file su cui vado a scrivere il tree
tree = TTree('T', 'tree con dati pbard')  #dichiarazione del tree

#dichiarazione branch in C++
#tree->Branch("nome branch",&oggetto) dove & prende l'indirizzo
#tree->Branch("nome branch",&nomestruct.primoelemento,"elementodouble/D:elementointero/I:elementochar/C")

#dichiarazione branch in python
tree.Branch('eventID', addressof(evid), 'evid/I')
tree.Branch('plab[GeV/c]', addressof(plab, 'pmed'), 'pmed/D:pmin/D:pmax/D')
tree.Branch('CrossSection[mb]', addressof(xs, 'sig'),
            'sig/D:statpos/D:statneg/D:sys/D')

#leggiamo il file
for line in open(filename, 'r'):
    words = line.split()
    if (len(words) != ncol): continue
    else:
        evid = ctypes.c_int(
            int(words[0])
        )  #per chiamare addressof serve un ctype che però richiede un intero per la conversione
        plab.pmed = float(words[1])
        plab.pmin = float(words[2])
        plab.pmax = float(words[3])
Exemple #14
0
def make_ew_trees(inlist, outfile):

    #input
    tree = TChain("DetectorTree")
    for i in inlist:
        tree.Add(i)

    #output
    out = TFile(outfile, "recreate")
    gROOT.ProcessLine("struct EntryF {Float_t v;};")
    gROOT.ProcessLine("struct EntryB {Bool_t v;};")

    #hits by primary photons
    x = rt.EntryF()
    y = rt.EntryF()
    z = rt.EntryF()
    en = rt.EntryF()
    otree = TTree("prim_tree", "prim_tree")
    otree.Branch("x", addressof(x, "v"), "x/F")
    otree.Branch("y", addressof(y, "v"), "y/F")
    otree.Branch("z", addressof(z, "v"), "z/F")
    otree.Branch("en", addressof(en, "v"), "en/F")

    #conversions
    gen_en = rt.EntryF()
    conv = rt.EntryB()
    clean = rt.EntryB()
    adep = rt.EntryF()
    conv_tree = TTree("conv_tree", "conv_tree")
    conv_tree.Branch("gen_en", addressof(gen_en, "v"), "gen_en/F")
    conv_tree.Branch("conv", addressof(conv, "v"), "conv/O")
    conv_tree.Branch("clean", addressof(clean, "v"), "clean/O")
    conv_tree.Branch("adep", addressof(adep, "v"), "adep/F")

    #input hits
    hits = ew_hits("ew", tree)

    #input generated particles
    inp_pdg = std.vector(int)()
    inp_en = std.vector(float)()
    tree.SetBranchAddress("gen_pdg", inp_pdg)
    tree.SetBranchAddress("gen_en", inp_en)

    #number of events with primary photon
    nprim = 0

    #event loop
    nev = tree.GetEntries()
    for ievt in range(nev):
        #for ievt in range(12):
        tree.GetEntry(ievt)

        #print("Next event")

        #generated photon energy
        gen_en.v = -1.
        for imc in range(inp_pdg.size()):
            if inp_pdg.at(imc) == 22: gen_en.v = inp_en.at(imc)

        #primary photon
        was_prim = False

        #conversion in the event
        conv.v = False

        #all secondaries and deposited energy in event
        asec = 0
        adep.v = 0.

        #hit loop
        for ihit in range(hits.get_n()):

            hit = hits.get_hit(ihit)

            hit.global_to_zpos(-18500)  # mm

            #hit by primary photon
            if hit.prim != 0 and hit.pdg == 22 and was_prim != True:

                was_prim = True

                x.v = hit.x
                y.v = hit.y
                z.v = hit.z
                en.v = hit.en

                otree.Fill()

            #conversion in the event
            if hit.prim == 1 and hit.conv == 1: conv.v = True

            #all secondaries and deposited energy
            asec += hit.nsec
            adep.v += hit.edep

        #hit loop

        #increment the photon count
        if was_prim is True:
            nprim += 1

        #evaluate clean conversion
        clean.v = False
        if conv.v and asec == 2: clean.v = True

        conv_tree.Fill()

    #event loop

    print("All events:     ", nev)
    print("Primary photons:", nprim)

    otree.Write()
    conv_tree.Write()
    out.Close()
Exemple #15
0
def make_conv_tree():

    #input
    #inp = TFile.Open("../../lmon.root")
    inp = TFile.Open("../../data/ew/ew1b.root")
    #inp = TFile.Open("../../data/ew/ew1c.root")
    #inp = TFile.Open("../../data/ew/ew1d.root")
    #inp = TFile.Open("../../data/ew/ew1e.root")
    tree = inp.Get("DetectorTree")

    #number of events, negative for all
    nev = -1

    #output
    out = TFile("conv_b.root", "recreate")
    gROOT.ProcessLine("struct EntryF {Float_t v;};")
    gROOT.ProcessLine("struct EntryB {Bool_t v;};")
    gen_en = rt.EntryF()
    conv = rt.EntryB()
    clean = rt.EntryB()
    adep = rt.EntryF()
    otree = TTree("conv_tree", "conv_tree")
    otree.Branch("gen_en", addressof(gen_en, "v"), "gen_en/F")
    otree.Branch("conv", addressof(conv, "v"), "conv/O")
    otree.Branch("clean", addressof(clean, "v"), "clean/O")
    otree.Branch("adep", addressof(adep, "v"), "adep/F")

    #exit window hits
    hits = ew_hits("ew", tree)

    #generated particles
    pdg = std.vector(int)()
    en = std.vector(float)()
    tree.SetBranchAddress("gen_pdg", pdg)
    tree.SetBranchAddress("gen_en", en)

    if nev < 0: nev = tree.GetEntries()
    for ievt in range(nev):
        tree.GetEntry(ievt)

        #print("Next event")

        #generated photon energy
        gen_en.v = -1.
        for imc in range(pdg.size()):
            if pdg.at(imc) == 22: gen_en.v = en.at(imc)

        #conversion in the event
        conv.v = False

        #all secondaries and deposited energy in event
        asec = 0
        adep.v = 0.

        for ihit in range(hits.get_n()):

            hit = hits.get_hit(ihit)
            hit.global_to_zpos(-18644)  # mm

            #print(hit.pdg, hit.prim, hit.conv, hit.nsec, hit.edep, hit.en)

            #conversion in the event
            if hit.prim == 1 and hit.conv == 1: conv.v = True

            #all secondaries and deposited energy
            asec += hit.nsec
            adep.v += hit.edep

        #evaluate clean conversion
        clean.v = False
        if conv.v and asec == 2: clean.v = True

        #print(conv.v, clean.v, adep.v, gen_en.v)

        otree.Fill()

    otree.Write()
    out.Close()
Exemple #16
0
    def __init__(self, parse, tree, hepmc_attrib):

        print("Quasi-real configuration:")

        #electron and proton beam energy, GeV
        self.Ee = parse.getfloat("main", "Ee")
        self.Ep = parse.getfloat("main", "Ep")
        print("Ee =", self.Ee, "GeV")
        print("Ep =", self.Ep, "GeV")

        #electron and proton mass
        self.me = TDatabasePDG.Instance().GetParticle(11).Mass()
        mp = TDatabasePDG.Instance().GetParticle(2212).Mass()

        #boost vector pbvec of proton beam
        pbeam = TLorentzVector()
        pbeam.SetPxPyPzE(0, 0, TMath.Sqrt(self.Ep**2-mp**2), self.Ep)
        self.pbvec = pbeam.BoostVector()

        #electron beam energy Ee_p in proton beam rest frame
        ebeam = TLorentzVector()
        ebeam.SetPxPyPzE(0, 0, -TMath.Sqrt(self.Ee**2-self.me**2), self.Ee)
        ebeam.Boost(-self.pbvec.x(), -self.pbvec.y(), -self.pbvec.z()) # transform to proton beam frame
        self.Ee_p = ebeam.E()

        #center-of-mass squared s, GeV^2
        self.s = self.get_s(self.Ee, self.Ep)
        print("s =", self.s, "GeV^2")
        print("sqrt(s) =", TMath.Sqrt(self.s), "GeV")

        #range in x
        xmin = parse.getfloat("main", "xmin")
        xmax = parse.getfloat("main", "xmax")
        print("xmin =", xmin)
        print("xmax =", xmax)

        #range in u = log_10(x)
        umin = TMath.Log10(xmin)
        umax = TMath.Log10(xmax)
        print("umin =", umin)
        print("umax =", umax)

        #range in y
        ymin = parse.getfloat("main", "ymin")
        ymax = parse.getfloat("main", "ymax")

        #range in W
        wmin = -1.
        wmax = -1.
        if parse.has_option("main", "Wmin"):
            wmin = parse.getfloat("main", "Wmin")
            print("Wmin =", wmin)
        if parse.has_option("main", "Wmax"):
            wmax = parse.getfloat("main", "Wmax")
            print("Wmax =", wmax)

        #adjust range in y according to W
        if wmin > 0 and ymin < wmin**2/self.s:
            ymin = wmin**2/self.s
        if wmax > 0 and ymax > wmax**2/self.s:
            ymax = wmax**2/self.s

        print("ymin =", ymin)
        print("ymax =", ymax)

        #range in v = log_10(y)
        vmin = TMath.Log10(ymin)
        vmax = TMath.Log10(ymax)
        print("vmin =", vmin)
        print("vmax =", vmax)

        #range in Q2
        self.Q2min = parse.getfloat("main", "Q2min")
        self.Q2max = parse.getfloat("main", "Q2max")
        print("Q2min =", self.Q2min)
        print("Q2max =", self.Q2max)

        #constant term in the cross section
        self.const = TMath.Log(10)*TMath.Log(10)*(1./137)/(2.*math.pi)

        #cross section formula for d^2 sigma / dxdy, Eq. II.6
        #transformed as x -> u = log_10(x) and y -> v = log_10(y)
        self.eq_II6_uv_par = self.eq_II6_uv(self)
        self.eq = TF2("d2SigDuDvII6", self.eq_II6_uv_par, umin, umax, vmin, vmax)

        self.eq.SetNpx(1000)
        self.eq.SetNpy(1000)

        #uniform generator for azimuthal angles
        self.rand = TRandom3()
        self.rand.SetSeed(5572323)

        #generator event variables in output tree
        tnam = ["gen_u", "gen_v", "true_x", "true_y", "true_Q2", "true_W2"]
        tnam += ["true_el_Q2"]
        tnam += ["true_el_pT", "true_el_theta", "true_el_phi", "true_el_E"]

        #create the tree variables
        tcmd = "struct gen_out { Double_t "
        for i in tnam:
            tcmd += i + ", "
        tcmd = tcmd[:-2] + ";};"
        gROOT.ProcessLine( tcmd )
        self.out = rt.gen_out()

        #put zero to all variables
        for i in tnam:
            exec("self.out."+i+"=0")

        #set the variables in the tree
        if tree is not None:
            for i in tnam:
                tree.Branch(i, addressof(self.out, i), i+"/D")

        #event attributes for hepmc
        self.hepmc_attrib = hepmc_attrib

        #counters for all generated and selected events
        self.nall = 0
        self.nsel = 0

        #print generator statistics at the end
        atexit.register(self.show_stat)

        #total integrated cross section
        self.sigma_tot = self.eq.Integral(umin, umax, vmin, vmax)
        print("Total integrated cross section for a given x and y range:", self.sigma_tot, "mb")

        print("Quasi-real photoproduction initialized")
Exemple #17
0
    def CreateTree1(self):
        info = ROOT.info_t()

        iddevicedetail = array('f', [0])
        afRxcapacity = array('f', [0])
        afRxchanbw = array('f', [0])
        afRxfreq = array('f', [0])
        afRxpower0 = array('f', [0])
        afRxpower1 = array('f', [0])
        afTxcapacity = array('f', [0])
        afTxchanbw = array('f', [0])
        afTxfreq = array('f', [0])
        afTxpower = array('f', [0])
        afTxpowerEirp = array('f', [0])
        airTime = array('f', [0])
        altitude = array('f', [0])
        chain0Signal = array('f', [0])
        chain1Signal = array('f', [0])
        chanbw = array('f', [0])
        cinr = array('f', [0])
        cpuUsage = array('f', [0])
        distance = array('f', [0])
        evm = array('f', [0])
        freq = array('f', [0])
        gpsFixed = array('f', [0])
        lanPlugged = array('f', [0])
        lanRxBytes = array('f', [0])
        lanRxErrors = array('f', [0])
        lanRxPackets = array('f', [0])
        lanTxBytes = array('f', [0])
        lanTxErrors = array('f', [0])
        lanTxPackets = array('f', [0])
        loadavg = array('f', [0])
        memBuffers = array('f', [0])
        memFree = array('f', [0])
        memTotal = array('f', [0])
        noise = array('f', [0])
        signal = array('f', [0])
        status_flags = array('f', [0])
        uptime = array('f', [0])
        wlanConnections = array('f', [0])
        wlanDownlinkCapacity = array('f', [0])
        wlanPolling = array('f', [0])
        wlanRxBytes = array('f', [0])
        wlanRxErrBmiss = array('f', [0])
        wlanRxErrCrypt = array('f', [0])
        wlanRxErrFrag = array('f', [0])
        wlanRxErrNwid = array('f', [0])
        wlanRxErrors = array('f', [0])
        wlanRxErrOther = array('f', [0])
        wlanRxErrRetries = array('f', [0])
        wlanRxPackets = array('f', [0])
        wlanRxRate = array('f', [0])
        wlanTxBytes = array('f', [0])
        wlanTxErrors = array('f', [0])
        wlanTxLatency = array('f', [0])
        wlanTxPackets = array('f', [0])
        wlanTxRate = array('f', [0])
        wlanUplinkCapacity = array('f', [0])

        self.output_tree.Branch("iddevicedetail", iddevicedetail,
                                'iddevicedetail/F')
        self.output_tree.Branch("afDuplex", addressof(info, 'afDuplex'),
                                'afDuplex/C')
        self.output_tree.Branch("afLinkState", addressof(info, 'afLinkState'),
                                'afLinkState/C')
        self.output_tree.Branch("afOpmode", addressof(info, 'afOpmode'),
                                'afOpmode/C')
        self.output_tree.Branch("afRxcapacity", afRxcapacity, 'afRxcapacity/F')
        self.output_tree.Branch("afRxchanbw", afRxchanbw, 'afRxchanbw/F')
        self.output_tree.Branch("afRxfreq", afRxfreq, 'afRxfreq/F')
        self.output_tree.Branch("afRxpower0", afRxpower0, 'afRxpower0/F')
        self.output_tree.Branch("afRxpower1", afRxpower1, 'afRxpower1/F')
        self.output_tree.Branch("afTxcapacity", afTxcapacity, 'afTxcapacity/F')
        self.output_tree.Branch("afTxchanbw", afTxchanbw, 'afTxchanbw/F')
        self.output_tree.Branch("afTxfreq", afTxfreq, 'afTxfreq/F')
        self.output_tree.Branch("afTxmodrate", addressof(info, 'afTxmodrate'),
                                'afTxmodrate/C')
        self.output_tree.Branch("afTxpower", afTxpower, 'afTxpower/F')
        self.output_tree.Branch("afTxpowerEirp", afTxpowerEirp,
                                'afTxpowerEirp/F')
        self.output_tree.Branch("airTime", airTime, 'airTime/F')
        self.output_tree.Branch("altitude", altitude, 'altitude/F')
        self.output_tree.Branch("apMac", addressof(info, 'apMac'), 'apMac/C')
        self.output_tree.Branch("boardCrc", addressof(info, 'boardCrc'),
                                'boardCrc/C')
        self.output_tree.Branch("cfgCrc", addressof(info, 'cfgCrc'),
                                'cfgCrc/C')
        self.output_tree.Branch("chain0Signal", chain0Signal, 'chain0Signal/F')
        self.output_tree.Branch("chain1Signal", chain1Signal, 'chain1Signal/F')
        self.output_tree.Branch("chanbw", chanbw, 'chanbw/F')
        self.output_tree.Branch("cinr", cinr, 'cinr/F')
        self.output_tree.Branch("cpuUsage", cpuUsage, 'cpuUsage/F')
        self.output_tree.Branch("deviceID", addressof(info, 'deviceID'),
                                'deviceID/C')
        self.output_tree.Branch("deviceIp", addressof(info, 'deviceIp'),
                                'deviceIp/C')
        self.output_tree.Branch("deviceName", addressof(info, 'deviceName'),
                                'deviceName/C')
        self.output_tree.Branch("distance", distance, 'distance/F')
        self.output_tree.Branch("dtCreate", addressof(info, 'dtCreate'),
                                'dtCreate/C')
        self.output_tree.Branch("essid", addressof(info, 'essid'), 'essid/C')
        self.output_tree.Branch("evm", evm, 'evm/F')
        self.output_tree.Branch("firmwareVersion",
                                addressof(info, 'firmwareVersion'),
                                'firmwareVersion/C')
        self.output_tree.Branch("freq", freq, 'freq/F')
        self.output_tree.Branch("gpsFixed", gpsFixed, 'gpsFixed/F')
        self.output_tree.Branch("lanIpAddress",
                                addressof(info,
                                          'lanIpAddress'), 'lanIpAddress/C')
        self.output_tree.Branch("lanPlugged", lanPlugged, 'lanPlugged/F')
        self.output_tree.Branch("lanRxBytes", lanRxBytes, 'lanRxBytes/F')
        self.output_tree.Branch("lanRxErrors", lanRxErrors, 'lanRxErrors/F')
        self.output_tree.Branch("lanRxPackets", lanRxPackets, 'lanRxPackets/F')
        self.output_tree.Branch("lanSpeed", addressof(info, 'lanSpeed'),
                                'lanSpeed/C')
        self.output_tree.Branch("lanTxBytes", lanTxBytes, 'lanTxBytes/F')
        self.output_tree.Branch("lanTxErrors", lanTxErrors, 'lanTxErrors/F')
        self.output_tree.Branch("lanTxPackets", lanTxPackets, 'lanTxPackets/F')
        self.output_tree.Branch("latitude", addressof(info, 'latitude'),
                                'latitude/C')
        self.output_tree.Branch("loadavg", loadavg, 'loadavg/F')
        self.output_tree.Branch("longitude", addressof(info, 'longitude'),
                                'longitude/C')
        self.output_tree.Branch("memBuffers", memBuffers, 'memBuffers/F')
        self.output_tree.Branch("memFree", memFree, 'memFree/F')
        self.output_tree.Branch("memTotal", memTotal, 'memTotal/F')
        self.output_tree.Branch("noise", noise, 'noise/F')
        self.output_tree.Branch("platform", addressof(info, 'platform'),
                                'platform/C')
        self.output_tree.Branch("remoteIP", addressof(info, 'remoteIP'),
                                'remoteIP/C')
        self.output_tree.Branch("remoteMac", addressof(info, 'remoteMac'),
                                'remoteMac/C')
        self.output_tree.Branch("rxModRate", addressof(info, 'rxModRate'),
                                'rxModRate/C')
        self.output_tree.Branch("signal", signal, 'signal/F')
        self.output_tree.Branch("status_flags", status_flags, 'status_flags/F')
        self.output_tree.Branch("txModRate", addressof(info, 'txModRate'),
                                'txModRate/C')
        self.output_tree.Branch("uptime", uptime, 'uptime/F')
        self.output_tree.Branch("wlanConnections", wlanConnections,
                                'wlanConnections/F')
        self.output_tree.Branch("wlanDownlinkCapacity", wlanDownlinkCapacity,
                                'wlanDownlinkCapacity/F')
        self.output_tree.Branch("wlanIpAddress",
                                addressof(info, 'wlanIpAddress'),
                                'wlanIpAddress/C')
        self.output_tree.Branch("wlanOpmode", addressof(info, 'wlanOpmode'),
                                'wlanOpmode/C')
        self.output_tree.Branch("wlanPolling", wlanPolling, 'wlanPolling/F')
        self.output_tree.Branch("wlanRxBytes", wlanRxBytes, 'wlanRxBytes/F')
        self.output_tree.Branch("wlanRxErrBmiss", wlanRxErrBmiss,
                                'wlanRxErrBmiss/F')
        self.output_tree.Branch("wlanRxErrCrypt", wlanRxErrCrypt,
                                'wlanRxErrCrypt/F')
        self.output_tree.Branch("wlanRxErrFrag", wlanRxErrFrag,
                                'wlanRxErrFrag/F')
        self.output_tree.Branch("wlanRxErrNwid", wlanRxErrNwid,
                                'wlanRxErrNwid/F')
        self.output_tree.Branch("wlanRxErrors", wlanRxErrors, 'wlanRxErrors/F')
        self.output_tree.Branch("wlanRxErrOther", wlanRxErrOther,
                                'wlanRxErrOther/F')
        self.output_tree.Branch("wlanRxErrRetries", wlanRxErrRetries,
                                'wlanRxErrRetries/F')
        self.output_tree.Branch("wlanRxPackets", wlanRxPackets,
                                'wlanRxPackets/F')
        self.output_tree.Branch("wlanRxRate", wlanRxRate, 'wlanRxRate/F')
        self.output_tree.Branch("wlanTxBytes", wlanTxBytes, 'wlanTxBytes/F')
        self.output_tree.Branch("wlanTxErrors", wlanTxErrors, 'wlanTxErrors/F')
        self.output_tree.Branch("wlanTxLatency", wlanTxLatency,
                                'wlanTxLatency/F')
        self.output_tree.Branch("wlanTxPackets", wlanTxPackets,
                                'wlanTxPackets/F')
        self.output_tree.Branch("wlanTxRate", wlanTxRate, 'wlanTxRate/F')
        self.output_tree.Branch("wlanUplinkCapacity", wlanUplinkCapacity,
                                'wlanUplinkCapacity/F')

        count = 0

        for line in (self.file_lines):
            if (count > 0):
                a = line.split(',')
                try:
                    a[79] = a[79].strip('\n')
                except:
                    print(count)
                for p in range(0, len(a)):
                    if (a[p] == ''):
                        a[p] = '0.0'

                iddevicedetail[0] = float(a[0])
                info.afDuplex = a[1]
                info.afLinkState = a[2]
                info.afOpmode = a[3]
                afRxcapacity[0] = float(a[4])
                afRxchanbw[0] = float(a[5])
                afRxfreq[0] = float(a[6])
                afRxpower0[0] = float(a[7])
                afRxpower1[0] = float(a[8])
                afTxcapacity[0] = float(a[9])
                afTxchanbw[0] = float(a[10])
                afTxfreq[0] = float(a[11])
                info.afTxmodrate = a[12]
                afTxpower[0] = float(a[13])
                afTxpowerEirp[0] = float(a[14])
                airTime[0] = float(a[15])
                altitude[0] = float(a[16])
                info.apMac = a[17]
                info.boardCrc = a[18]
                info.cfgCrc = a[19]
                chain0Signal[0] = float(a[20])
                chain1Signal[0] = float(a[21])
                chanbw[0] = float(a[22])
                cinr[0] = float(a[23])
                cpuUsage[0] = float(a[24])
                info.deviceID = a[25]
                info.deviceIp = a[26]
                info.deviceName = a[27]
                distance[0] = float(a[28])
                info.dtCreate = a[29]
                info.essid = a[30]
                evm[0] = float(a[31])
                info.firmwareVersion = a[32]
                freq[0] = float(a[33])
                gpsFixed[0] = float(a[34])
                info.lanIpAddress = a[35]
                lanPlugged[0] = float(a[36])
                lanRxBytes[0] = float(a[37])
                lanRxErrors[0] = float(a[38])
                lanRxPackets[0] = float(a[39])
                info.lanSpeed = a[40]
                lanTxBytes[0] = float(a[41])
                lanTxErrors[0] = float(a[42])
                lanTxPackets[0] = float(a[43])
                info.latitude = a[44]
                loadavg[0] = float(a[45])
                info.longitude = a[46]
                memBuffers[0] = float(a[47])
                memFree[0] = float(a[48])
                memTotal[0] = float(a[49])
                noise[0] = float(a[50])
                info.platform = a[51]
                info.remoteIP = a[52]
                info.remoteMac = a[53]
                info.rxModRate = a[54]
                signal[0] = float(a[55])
                status_flags[0] = float(a[56])
                info.txModRate = a[57]
                uptime[0] = float(a[58])
                wlanConnections[0] = float(a[59])
                wlanDownlinkCapacity[0] = float(a[60])
                info.wlanIpAddress = a[61]
                info.wlanOpmode = a[62]
                wlanPolling[0] = float(a[63])
                wlanRxBytes[0] = float(a[64])
                wlanRxErrBmiss[0] = float(a[65])
                wlanRxErrCrypt[0] = float(a[66])
                wlanRxErrFrag[0] = float(a[67])
                wlanRxErrNwid[0] = float(a[68])
                wlanRxErrors[0] = float(a[69])
                wlanRxErrOther[0] = float(a[70])
                wlanRxErrRetries[0] = float(a[71])
                wlanRxPackets[0] = float(a[72])
                wlanRxRate[0] = float(a[73])
                wlanTxBytes[0] = float(a[74])
                wlanTxErrors[0] = float(a[75])
                wlanTxLatency[0] = float(a[76])
                wlanTxPackets[0] = float(a[77])
                wlanTxRate[0] = float(a[78])
                wlanUplinkCapacity[0] = float(a[79])

                self.output_tree.Fill()
            count += 1

        self.output_file.Write()
        self.output_file.Close()
Exemple #18
0
 def _preSetsLoop(self):
     self.otree = ROOT.TTree("tree", "")
     self.treeContent = ROOT.MyTreeContent()
     self.otree.Branch("index", ROOT.addressof(self.treeContent, 'index'),
                       'index/I')
     self.otree.Branch("fl", addressof(self.treeContent, 'fl'), 'fl/D')
     self.otree.Branch("afb", addressof(self.treeContent, 'afb'), 'afb/D')
     self.otree.Branch("status", addressof(self.treeContent, 'status'),
                       'status/D')
     self.otree.Branch("hesse", addressof(self.treeContent, 'hesse'),
                       'hesse/D')
     self.otree.Branch("covQual", addressof(self.treeContent, 'covQual'),
                       'covQual/D')
     #self.otree.Branch("minos", addressof(self.treeContent, 'minos'), 'minos/D')
     if self.process.cfg['args'].SimFit:
         self.otree.Branch("events16",
                           ROOT.addressof(self.treeContent, 'events16'),
                           'events16/D')
         self.otree.Branch("events17",
                           ROOT.addressof(self.treeContent, 'events17'),
                           'events17/D')
         self.otree.Branch("events18",
                           ROOT.addressof(self.treeContent, 'events18'),
                           'events18/D')
         self.otree.Branch("Wevents16",
                           ROOT.addressof(self.treeContent, 'Wevents16'),
                           'Wevents16/D')
         self.otree.Branch("Wevents17",
                           ROOT.addressof(self.treeContent, 'Wevents17'),
                           'Wevents17/D')
         self.otree.Branch("Wevents18",
                           ROOT.addressof(self.treeContent, 'Wevents18'),
                           'Wevents18/D')
         self.otree.Branch("nSig16",
                           ROOT.addressof(self.treeContent, 'nSig16'),
                           'nSig16/D')
         self.otree.Branch("nSig17",
                           ROOT.addressof(self.treeContent, 'nSig17'),
                           'nSig17/D')
         self.otree.Branch("nSig18",
                           ROOT.addressof(self.treeContent, 'nSig18'),
                           'nSig18/D')
         self.otree.Branch("nBkgComb16",
                           ROOT.addressof(self.treeContent, 'nBkgComb16'),
                           'nBkgComb16/D')
         self.otree.Branch("nBkgComb17",
                           ROOT.addressof(self.treeContent, 'nBkgComb17'),
                           'nBkgComb17/D')
         self.otree.Branch("nBkgComb18",
                           ROOT.addressof(self.treeContent, 'nBkgComb18'),
                           'nBkgComb18/D')
         self.otree.Branch("nBkgPeak16",
                           ROOT.addressof(self.treeContent, 'nBkgPeak16'),
                           'nBkgPeak16/D')
         self.otree.Branch("nBkgPeak17",
                           ROOT.addressof(self.treeContent, 'nBkgPeak17'),
                           'nBkgPeak17/D')
         self.otree.Branch("nBkgPeak18",
                           ROOT.addressof(self.treeContent, 'nBkgPeak18'),
                           'nBkgPeak18/D')
     else:
         self.otree.Branch("entries", addressof(self.treeContent,
                                                'entries'), 'entries/D')
         self.otree.Branch("sigEntries",
                           addressof(self.treeContent, 'sigEntries'),
                           'sigEntries/D')
     self.otree.Branch("nSig", addressof(self.treeContent, 'nSig'),
                       'nSig/D')
     self.otree.Branch("nBkgComb", addressof(self.treeContent, 'nBkgComb'),
                       'nBkgComb/D')
     self.otree.Branch("nBkgPeak", addressof(self.treeContent, 'nBkgPeak'),
                       'nBkgPeak/D')
     self.otree.Branch("nll", addressof(self.treeContent, 'nll'), 'nll/D')
     pass