コード例 #1
0
    def createWeighterObjects(self, allsourcefiles):
        #
        # Calculates the weights needed for flattening the pt/eta spectrum

        from DeepJetCore.Weighter import Weighter
        weighter = Weighter()
        weighter.undefTruth = self.undefTruth
        weighter.class_weights = self.class_weights
        branches = [self.weightbranchX, self.weightbranchY]
        branches.extend(self.truth_branches)

        if self.remove:
            weighter.setBinningAndClasses([self.weight_binX, self.weight_binY],
                                          self.weightbranchX,
                                          self.weightbranchY,
                                          self.truth_branches,
                                          self.red_classes,
                                          self.truth_red_fusion,
                                          method=self.referenceclass)

        counter = 0
        import ROOT
        from root_numpy import tree2array, root2array
        if self.remove:
            for fname in allsourcefiles:
                fileTimeOut(fname, 120)
                nparray = uproot_root2array(fname,
                                            treename="ttree",
                                            stop=None,
                                            branches=branches)
                norm_hist = True
                if self.referenceclass == 'flatten':
                    norm_hist = False
                # from IPython import embed;embed()
                weighter.addDistributions(nparray, norm_h=norm_hist)
                #del nparray
                counter = counter + 1
            weighter.createRemoveProbabilitiesAndWeights(self.referenceclass)

        print("calculate means")
        print("debugging this point here!")
        from DeepJetCore.preprocessing import meanNormProd
        nparray = self.readTreeFromRootToTuple(
            allsourcefiles,
            branches=self.vtx_branches + self.eta_rel_branches +
            self.track_branches + self.global_branches,
            limit=500000)
        print("read tree from sourcefiles")
        for a in (self.vtx_branches + self.eta_rel_branches +
                  self.track_branches + self.global_branches):
            for b in range(len(nparray[a])):
                nparray[a][b] = np.where(
                    np.logical_and(np.isfinite(nparray[a][b]),
                                   np.abs(nparray[a][b]) < 100000.0),
                    nparray[a][b], 0)
        means = np.array([], dtype='float32')
        if len(nparray):
            means = meanNormProd(nparray)
        print("weigheter created")
        return {'weigther': weighter, 'means': means}
コード例 #2
0
    def createWeighterObjects(self, allsourcefiles):
        #
        # Calculates the weights needed for flattening the pt/eta spectrum

        from DeepJetCore.Weighter import Weighter
        weighter = Weighter()
        weighter.undefTruth = self.undefTruth
        branches = [self.weightbranchX, self.weightbranchY]
        branches.extend(self.truth_branches)

        if self.remove:
            weighter.setBinningAndClasses([self.weight_binX, self.weight_binY],
                                          self.weightbranchX,
                                          self.weightbranchY,
                                          self.truth_branches)

        counter = 0
        import ROOT
        from root_numpy import tree2array, root2array
        if self.remove:
            for fname in allsourcefiles:
                fileTimeOut(fname, 120)
                nparray = root2array(fname,
                                     treename="deepntuplizer/tree",
                                     stop=None,
                                     branches=branches)
                weighter.addDistributions(nparray)
                #del nparray
                counter = counter + 1
            weighter.createRemoveProbabilitiesAndWeights(self.referenceclass)
        return {'weigther': weighter}
    def createWeighterObjects(self, allsourcefiles):
        # Calculates the weights needed for flattening the pt/eta spectrum
        # by initializing a Weighter instance

        from DeepJetCore.Weighter import Weighter
        weighter = Weighter()
        weighter.undefTruth = self.undefTruth
        branches = [self.weightbranchX, self.weightbranchY]
        branches.extend(self.truth_branches)

        # if one uses the Weighter
        if self.remove:
            weighter.setBinningAndClasses([self.weight_binX, self.weight_binY],
                                          self.weightbranchX,
                                          self.weightbranchY,
                                          self.truth_branches,
                                          method=self.referenceclass)

        counter = 0
        import ROOT
        from root_numpy import tree2array, root2array
        if self.remove:
            for fname in allsourcefiles:
                fileTimeOut(fname, 120)
                nparray = root2array(fname,
                                     treename="tree",
                                     stop=None,
                                     branches=branches)
                norm_hist = True
                if self.referenceclass == 'flatten':
                    norm_hist = False
                weighter.addDistributions(nparray, norm_h=norm_hist)
                counter = counter + 1
            weighter.createRemoveProbabilitiesAndWeights(self.referenceclass)
        return {'weigther': weighter}
コード例 #4
0
    def createWeighterObjects(self, allsourcefiles):
        #
        # Calculates the weights needed for flattening the pt/eta spectrum

        from DeepJetCore.Weighter import Weighter
        weighter = Weighter()
        weighter.undefTruth = self.undefTruth
        branches = [self.weightbranchX, self.weightbranchY]
        branches.extend(self.truth_branches)

        if self.remove:
            weighter.setBinningAndClasses([self.weight_binX, self.weight_binY],
                                          self.weightbranchX,
                                          self.weightbranchY,
                                          self.truth_branches)

        counter = 0
        import ROOT
        from root_numpy import tree2array, root2array
        if self.remove:
            for fname in allsourcefiles:
                fileTimeOut(fname, 120)
                nparray = root2array(fname,
                                     treename="deepntuplizer/tree",
                                     stop=None,
                                     branches=branches)
                weighter.addDistributions(nparray)
                #del nparray
                counter = counter + 1
            weighter.createRemoveProbabilitiesAndWeights(self.referenceclass)

        print("calculate means")
        from DeepJetCore.preprocessing import meanNormProd
        nparray = self.readTreeFromRootToTuple(
            allsourcefiles,
            branches=self.vtx_branches + self.eta_rel_branches +
            self.track_branches + self.global_branches,
            limit=500000)
        for a in (self.vtx_branches + self.eta_rel_branches +
                  self.track_branches + self.global_branches):
            for b in range(len(nparray[a])):
                nparray[a][b] = np.where(nparray[a][b] < 100000.0,
                                         nparray[a][b], 0)
        means = np.array([], dtype='float32')
        if len(nparray):
            means = meanNormProd(nparray)
        return {'weigther': weighter, 'means': means}
コード例 #5
0
    def createWeighterObjects(self, allsourcefiles):
        #
        # Calculates the weights needed for flattening the pt/eta spectrum

        from DeepJetCore.Weighter import Weighter
        weighter = Weighter()
        weighter.undefTruth = self.undefTruth
        weighter.class_weights = self.class_weights
        branches = [self.weightbranchX, self.weightbranchY]
        branches.extend(self.truth_branches)

        if self.remove:
            weighter.setBinningAndClasses([self.weight_binX, self.weight_binY],
                                          self.weightbranchX,
                                          self.weightbranchY,
                                          self.truth_branches,
                                          self.red_classes,
                                          self.truth_red_fusion,
                                          method=self.referenceclass)

        counter = 0
        import ROOT
        from root_numpy import tree2array, root2array
        if self.remove:
            for fname in allsourcefiles:
                fileTimeOut(fname, 120)
                nparray = root2array(fname,
                                     treename="deepntuplizer/tree",
                                     stop=None,
                                     branches=branches)
                norm_hist = True
                if self.referenceclass == 'flatten':
                    norm_hist = False
                weighter.addDistributions(nparray, norm_h=norm_hist)
                #del nparray
                counter = counter + 1
            weighter.createRemoveProbabilitiesAndWeights(self.referenceclass)
            #weighter.printHistos('/afs/cern.ch/user/a/ademoor/Flatten/') #If you need to print the 2D histo, choose your output dir
            return {'weigther': weighter}