示例#1
0
import pyWIMP.DMModels.wimp_model as wimp_model
from pyWIMP.DMModels.base_model import BaseVariables
import ROOT
import re
#ROOT.gROOT.SetBatch()
basevars = BaseVariables(0, 1, 0, 3.5)
time = basevars.get_time()
time.setConstant()
time.setVal(0)
mass_of_wimp = 10
wm = wimp_model.WIMPModel(basevars, mass_of_wimp)
c1 = ROOT.TCanvas()
c1.SetLogy()
#test = ROOT.MGMWimpHelmFFSquared("model", "model", q, r, s)
#energy = q
test = wm.get_helm_form_factor()
test1 = wm.get_WIMP_model()
test2 = wm.get_WIMP_model_with_escape_vel()
test3 = wm.get_WIMP_model_with_escape_vel_no_ff()
energy = basevars.get_energy()
frame = energy.frame()
energy.setVal(0)
print test1.getVal(), test2.getVal(), test3.getVal(), test.getVal()
variables = ROOT.RooArgSet(basevars.get_energy())

integral = test1.createIntegral(variables)
orig = integral.getVal()

integral = test.createIntegral(variables)
ff_int = integral.getVal()
示例#2
0
wimp_mass = float(sys.argv[1])

#####################################
"""
Initialization stuff
"""
#####################################

ROOT.RooRandom.randomGenerator().SetSeed(0)
ROOT.RooMsgService.instance().setSilentMode(True)
ROOT.RooMsgService.instance().setGlobalKillBelow(5)
total_mc_entries = 1000
#total_mc_entries = 10
total_entries = 400 
exponential_total = 190
basevars = BaseVariables(0, 0.1444,0.5, 3.5) 
basevars.get_time().setConstant(True)

# Set up the WIMP class
wimp_class = WIMPModel(basevars, 
                       mass_of_wimp = wimp_mass,
                       kilograms=0.4,
                       constant_quenching=False)
model = wimp_class.get_model()

# Set up the background class
background = TestModel(basevars)
list_of_models, list_of_coefficients = \
                          background.get_list_components()

exp_coef = list_of_coefficients.at(
示例#3
0
    def initialize(self):

        if self.is_initialized: return
        from pyWIMP.DMModels.wimp_model import WIMPModel
        from pyWIMP.DMModels.base_model import BaseVariables
        from pyWIMP.DMModels.flat_model import FlatModel

        self.total_counts = int(self.mass_of_detector*
                                self.background_rate*
                                (self.energy_max-self.threshold)*
                                self.total_time*365)
        self.basevars = BaseVariables(time_beginning=0,
            time_in_years=self.total_time,
            energy_threshold=self.threshold,
            energy_max=self.energy_max)

        if self.num_energy_bins != 0: self.basevars.get_energy().setBins(int(self.num_energy_bins))
        if self.num_time_bins != 0: self.basevars.get_time().setBins(int(self.num_time_bins))
        self.variables = ROOT.RooArgSet()
        if self.constant_time:
            self.basevars.get_time().setVal(0)
            self.basevars.get_time().setConstant(True)
        else:
            self.variables.add(self.basevars.get_time())
        if not self.constant_energy:
            self.variables.add(self.basevars.get_energy())


        self.calculation_class = \
            ec.ExclusionCalculation(self.exit_manager)
 
        # This is where we define our models
        self.backgroundClass = TritiumDecayModel(self.basevars, 
                                                 self.tritium_exposure_time, 
                                                 self.tritium_activation_rate,
                                                 self.mass_of_detector,
                                                 self.background_rate)

        # This model is already an extended model
        self.background_model =  self.backgroundClass.get_model()

        self.background_extend = self.background_model
        if not self.do_axioelectric:
            # The following has not been normalized to per-nucleon yet.
            self.model_normal = ROOT.RooRealVar("model_normal", 
                                                "WIMP-nucleus #sigma", 
                                                0, -1e-15, 0.1, 'pb')
            self.wimpClass = WIMPModel(self.basevars,
                mass_of_wimp=self.wimp_mass,
                kilograms = self.mass_of_detector,
                constant_quenching=(not self.variable_quenching))

            self.model = self.wimpClass.get_model()
            self.norm = self.wimpClass.get_normalization().getVal()
            self.model_extend = ROOT.RooExtendPdf("model_extend", 
                                                   "model_extend", 
                                                   self.model, 
                                                   self.model_normal)
        else:
            # wimpClass is of course a misnomer here, but we use it for now
            self.wimpClass = GaussianSignalModel(self.basevars,
                                                 mean_of_signal=self.axion_mass)
 
            self.model_normal = ROOT.RooRealVar("model_normal", 
                                                "Counts", 
                                                0, -10, 1000)
            # This is where we define our model
            self.model = self.wimpClass.get_model()
            self.norm = self.wimpClass.get_normalization()*self.model.getNorm(
                        ROOT.RooArgSet(self.basevars.get_energy())) 

            # We actually want the inverse of the normaliation, since this is later multiplied 
            # and we want the total counts in a particular gaussian.
            self.norm = 1./self.norm
            self.model_extend = ROOT.RooExtendPdf("model_extend", 
                                                   "model_extend", 
                                                   self.model, 
                                                   self.model_normal)


        self.added_pdf = ROOT.RooAddPdf("b+s", 
                                        "Background + Signal", 
                                        ROOT.RooArgList(
                                        self.background_extend, 
                                        self.model_extend))
 
        self.test_variable = self.model_normal
        self.data_set_model = self.background_extend
        self.fitting_model = self.added_pdf
        self.is_initialized = True
示例#4
0
    def initialize(self):

        if self.is_initialized: return
        from pyWIMP.DMModels.base_model import BaseVariables
        from pyWIMP.DMModels.flat_model import FlatModel
        from pyWIMP.DMModels.oscillation_model import OscillationModel
        self.basevars = BaseVariables(time_beginning=0,
            time_in_years=self.total_time,
            energy_threshold=self.threshold,
            energy_max=self.energy_max)

        self.oscClass = OscillationModel(self.basevars)

        self.flatClass = FlatModel(self.basevars)


        self.calculation_class = \
            osc.OscillationSensitivityCalculation(self.exit_manager)

        self.variables = ROOT.RooArgSet()
        self.variables.add(self.basevars.get_time())

        self.basevars.get_energy().setVal(0)
        self.basevars.get_energy().setConstant(True)

        # This is where we define our models
        self.background =  self.flatClass.get_model()
        self.model = self.oscClass.get_model()
        self.norm = 1 
        self.is_initialized = True

        
        if self.model_amplitude > 1: self.model_amplitude = 1
        elif self.model_amplitude < 0: self.model_amplitude = 0
        self.signal_percentage = ROOT.RooRealVar("signal_percentage", 
                                            "signal_percentage", 
                                            self.model_amplitude)
        self.background_model = ROOT.RooAddPdf(
                                "background",
                                "Data Model",
                                self.model,
                                self.background,
                                self.signal_percentage)

        self.model_normal = ROOT.RooRealVar("model_normal", 
                                            "model_normal", 
                                            self.model_amplitude, 
                                            0, 1)

        self.total_fit_counts = ROOT.RooRealVar("total_fit_counts", 
                                            "total_fit_counts", 
                                            self.total_counts, 
                                            0, 3*self.total_counts)
        self.added_pdf = ROOT.RooAddPdf(
                                "added_pdf",
                                "Fit Model",
                                self.model,
                                self.background,
                                self.model_normal)

        self.model_extend = ROOT.RooExtendPdf("model_extend",
                                              "Signal + Background",
                                              self.added_pdf,
                                              self.total_fit_counts)

        self.test_variable = self.model_normal
        self.data_set_model = self.background_model
        self.fitting_model = self.model_extend 
示例#5
0
    def initialize(self):
        # The background model is the same, but now we switch it to the data model
        from pyWIMP.DMModels.low_energy_background import LowEnergyBackgroundModel
        from pyWIMP.DMModels.base_model import BaseVariables
        from pyWIMP.DMModels.wimp_model import WIMPModel
        self.total_counts = None
        open_file = ROOT.TFile(self.data_file)
        self.workspace = open_file.Get(self.object_name)
        # Do some introspection, we can handle TH1s, and RooAbsData 
        self.basevars = BaseVariables(time_beginning=0,
            time_in_years=self.total_time,
            energy_threshold=self.threshold,
            energy_max=self.energy_max,
            use_tag=False)

        self.variables = ROOT.RooArgSet()

        if self.workspace.InheritsFrom(ROOT.TH1.Class()):
            self.variables.add(self.basevars.get_energy())
            self.basevars.get_time().setVal(0)
            self.basevars.get_time().setConstant(True)

            self.data_set_model = ROOT.RooDataHist("data", "data", 
                                    ROOT.RooArgList(self.basevars.get_energy()),
                                    self.workspace)
        elif self.workspace.InheritsFrom(ROOT.TTree.Class()):
            # Default to setting them to constant.
            self.basevars.get_time().setVal(0)
            self.basevars.get_time().setConstant(True)
            self.basevars.get_energy().setVal(0)
            self.basevars.get_energy().setConstant(True)
            if self.num_energy_bins != 0:
                self.basevars.get_energy().setBins(int(self.num_energy_bins))
            if self.num_time_bins != 0:
                self.basevars.get_time().setBins(int(self.num_time_bins))

            branches = self.workspace.GetListOfBranches()
            efficiency = "" 
            branch_arg_list = []

            for i in range(branches.GetEntries()):
                branch_name = branches[i].GetName()
                if branch_name == "ee_energy": 
                    self.basevars.get_energy().setConstant(False)
                    self.variables.add(self.basevars.get_energy())
                    branch_arg_list.append((self.basevars.get_energy(), 
                                            branch_name))
                if branch_name == "time": 
                    self.basevars.get_time().setConstant(False)
                    self.variables.add(self.basevars.get_time())
                    branch_arg_list.append((self.basevars.get_time(), 
                                            branch_name))
                elif branch_name == "weight":
                    efficiency = branch_name 
                    self.variables.add(self.basevars.get_weighting())

            if not self.data_set_cuts:
                # Load the DataSet the easy way
                self.data_set_model = ROOT.RooDataSet("data", "data", 
                                        self.workspace,
                                        self.variables,
                                        efficiency)
            else:
                # Otherwise, we have to get the correct events,
                # which requires stepping through all events
                self.data_set_model = ROOT.RooDataSet("data", "data", 
                                        self.variables,
                                        efficiency)
                # Get an event list with the correct cut events
                ROOT.gROOT.cd()
                el = ROOT.TEventList("el", "el")
                cuts = self.data_set_cuts
                iter = self.variables.createIterator()
                while 1: 
                    obj = iter.Next()
                    if not obj: break
                    if obj.GetTitle() == 'weight': continue
                    cuts += " && ((%s <= %f) && (%s >= %f))" % (obj.GetName(),
                                                                obj.getMax(),
                                                                obj.GetName(),
                                                                obj.getMin())
                self.workspace.Draw(">>%s" % el.GetName(), cuts, "goff")
                event_list = [el.GetEntry(i) for i in range(el.GetN())] 
                #event_list = [i for i in range(self.workspace.GetEntries())] 
                for j in event_list: 
                    self.workspace.GetEntry(j)
                    eff_val = 1.
                    if efficiency: 
                        eff_val = getattr(self.workspace, efficiency)
                    for val in branch_arg_list: 
                        val[0].setVal(getattr(self.workspace, val[1]))
                    if eff_val != 0: self.data_set_model.add(self.variables, eff_val)
                     
        else:
            print "Requested: %s, isn't a TTree or TH1!" % self.data_set_name
            raise TypeError

        if self.num_energy_bins != 0 or self.num_time_bins != 0:
            self.original_data_set = self.data_set_model
            self.data_set_model = self.original_data_set.binnedClone()

        if self.data_set_model.isWeighted(): print "Data set is weighted"
        print "Data set has %i entries." % self.data_set_model.sumEntries()


        if not self.do_axioelectric:
            self.wimpClass = WIMPModel(self.basevars,
                mass_of_wimp=self.wimp_mass,
                kilograms = self.mass_of_detector,
                constant_quenching=(not self.variable_quenching))
 
            # This is where we define our model
            self.model = self.wimpClass.get_model()
            #self.model = self.wimpClass.get_simple_model()
            self.norm = self.wimpClass.get_normalization().getVal()

            # The following has not been normalized to per-nucleon yet.
            self.model_normal = ROOT.RooRealVar("model_normal", 
                                                "WIMP-nucleus #sigma", 
                                                1, -10, 100, 
                                                "pb")
            self.model_extend = ROOT.RooExtendPdf("model_extend", 
                                                   "model_extend", 
                                                   self.model, 
                                                   self.model_normal)
            # Getting the number of events for a model_normal of 1 
            # This gives us number of events per model_normal value
            scaler = self.model_extend.expectedEvents(self.variables)
            self.model_normal.setMax(2*self.data_set_model.sumEntries()/scaler)
        else:
            # wimpClass is of course a misnomer here, but we use it for now
            self.wimpClass = GaussianSignalModel(self.basevars,
                                                 mean_of_signal=self.axion_mass)
 
            self.model_normal = ROOT.RooRealVar("model_normal", 
                                                "Counts", 
                                                0, -10, 1000)
            # This is where we define our model
            self.model = self.wimpClass.get_model()
            self.norm = self.wimpClass.get_normalization()*self.model.getNorm(
                        ROOT.RooArgSet(self.basevars.get_energy())) 

            # We actually want the inverse of the normaliation, since this is later multiplied 
            # and we want the total counts in a particular gaussian.
            self.norm = 1./self.norm
            self.model_extend = ROOT.RooExtendPdf("model_extend", 
                                                   "model_extend", 
                                                   self.model, 
                                                   self.model_normal)

        self.is_initialized = True

        self.calculation_class = \
            dat.DataCalculation(self.exit_manager)
        self.low_energy = LowEnergyBackgroundModel(self.basevars, 
                                                   use_ratio=self.fix_l_line_ratio)

        list_of_models, list_of_coefficients = self.low_energy.get_list_components()
        self.extended_models = []
        i = 0
        while 1: 
            amod = list_of_models.at(i)
            avar = list_of_coefficients.at(i)
            if not amod: break
            i += 1
            extend = ROOT.RooExtendPdf("extend%s" % amod.GetName(),
                                       "extend%s" % amod.GetName(),
                                       amod, avar)
            self.extended_models.append(extend)
        temp_list = ROOT.RooArgList()
        temp_list.add(self.model_extend)
        for amod in self.extended_models:
            temp_list.add(amod)
        self.added_pdf = ROOT.RooAddPdf("b+s", 
                                        "Background + Signal", 
                                        temp_list)
        self.test_variable = self.model_normal
        self.fitting_model = self.added_pdf
示例#6
0
# Now string_np holds all the necessary values, with the first value being the best fit

#####################################
"""
Initialization stuff
"""
#####################################

ROOT.RooRandom.randomGenerator().SetSeed(0)
ROOT.RooMsgService.instance().setSilentMode(True)
ROOT.RooMsgService.instance().setGlobalKillBelow(5)
total_mc_entries = 500
total_mc_entries = 400

basevars = BaseVariables(0, 0.14887063655, 0.5, 3.5)
basevars.get_time().setConstant(True)

# Set up the WIMP class
wimp_class = WIMPModel(basevars,
                       mass_of_wimp=wimp_mass,
                       kilograms=0.4,
                       constant_quenching=False)
model = wimp_class.get_model()
normalization = wimp_class.get_normalization().getVal()
# Set up the background class
low_energy = LowEnergyBackgroundModel(basevars)
low_energy_model = low_energy.get_model()

list_of_models, list_of_coefficients = low_energy.get_list_components()
background_normal = ROOT.RooRealVar("flat_normal", "Background event number",
示例#7
0
#!/usr/bin/env python

from pyWIMP.DMModels.base_model import BaseVariables
import pyWIMP.DMModels.wimp_model as wimp_model
import ROOT
import re
mass_of_wimp = 7
basevars = BaseVariables(0.0, 4.0, 0, 10, True, 0.0)
time = basevars.get_time()
time.setConstant()
time.setVal(0)
wm = wimp_model.WIMPModel(basevars, mass_of_wimp, nucl_recoil=True)
model = wm.get_WIMP_model()
expected_events = model.expectedEvents(ROOT.RooArgSet(basevars.get_energy()))
hist = model.createHistogram("hist", basevars.get_energy(), \
                          ROOT.RooFit.Binning(200),\
                          ROOT.RooFit.YVar(basevars.get_time(), \
                          ROOT.RooFit.Binning(4*36)))
hist.SetLineColor(4)
hist.GetXaxis().CenterTitle()
hist.GetXaxis().SetTitle("Energy (keVnr)")
hist.GetXaxis().SetTitleOffset(1.5)
hist.GetYaxis().CenterTitle()
hist.GetYaxis().SetTitle("Time (years)")
hist.GetYaxis().SetTitleOffset(1.5)
hist.GetYaxis().SetNdivisions(507)
hist.GetZaxis().CenterTitle()
hist.GetZaxis().SetTitle("Amplitude (a.u.)")
hist.GetZaxis().SetTitle("#frac{dR}{dE} #sigma^{-1} (counts/keV/kg/yr/pb)")
hist.GetZaxis().SetTitleOffset(1.1)
hist.GetZaxis().SetNdivisions(509)