def model_landau(self, seed=None, h=None, m=10000, s=1000, show=True, thresh=False): seed = self.Ana.draw_signal_distribution( show=False) if seed is None else seed h = deepcopy(seed) if h is None else h h.SetName('h_ml') n = seed.GetEntries() h.Reset() thresholds = [47 * i for i in [150, 160, 170]] for _ in range(int(n)): v = gRandom.Landau(m, s) threshold = thresholds[int(gRandom.Rndm() * len(thresholds))] h.Fill(v if v > threshold else 0 if thresh else v) # h.Fill(v if v > 11421 else 0 if thresh else v) delta = mean([(h.GetBinContent(i) - seed.GetBinContent(i))**2 for i in range(h.GetNbinsX()) if i is not h.FindBin(0)]) seed.SetFillColor(2) h.SetFillColor(Draw.FillColor) seed.SetFillStyle(3017) h.SetFillStyle(3018) l1 = Draw.make_legend(y2=.76) l1.AddEntry(h, 'Simulation', 'f') l1.AddEntry(seed, 'Original', 'f') self.Draw(h, show=show, leg=l1) self.Draw(seed, show=show, draw_opt='same', canvas=gROOT.GetListOfCanvases()[-1]) seed.Draw('same') return delta
def accept(self, x): result = True if self.leff: p = self.efficiency(x) r = gRandom.Rndm() if r > p: result = False return result
def smear(xt): xeff = 0.3 + (1.0 - 0.3) / 20 * (xt + 10.0) # efficiency x = gRandom.Rndm() if x > xeff: return None xsmear = gRandom.Gaus(-2.5, 0.2) # bias and smear return xt + xsmear
def mkBG2(): hlim=1. llim=eta nbins=10000 xx=[(hlim-llim)*ra.random()+llim for i in range(nbins-1)]+[hlim] xx.sort() xbin=[xx[0]-llim]+[xx[i]-xx[i-1] for i in range(1,nbins)] areaswap=[dsigmade(xx[i])*xbin[i] for i in range(nbins)] area=[] area.append(areaswap[0]) for i in range(1,nbins): area.append(area[i-1]+areaswap[i]) area=[area[i]/area[-1] for i in range(nbins)] output=[] for i in range(nn): random0=gRandom.Rndm() for j in range(nbins): if random0<=area[j]: output.append((j+1)*(hlim-llim)/nbins+llim) break return output
def acceptance(acc=0.8): if gRandom.Rndm() < acc: return True else: return False
DDG4.Geant4Random.setMainInstance(rndm1.get()) rndm1.showStatus() # Move main geant random instance from rndm1 to rndm2: # See how gRandom and HepRandom instances move DDG4.Geant4Random.setMainInstance(rndm1.get()) print 'DEFAULT Engine:', DDG4.CLHEP.HepRandom.getTheEngine().name() print 'DDG4 DEFAULT:', DDG4.Geant4Random.instance().engine().name() rndm = DDG4.Geant4Random.instance() rndm.setSeed(1234) rndm.showStatus() for i in xrange(10): print rndm.name( ), ' -- 0 gRandome.Rndm() -- Shoot random[', i, ']= ', gRandom.Rndm( ) rndm.setSeed(1234) for i in xrange(10): print rndm.name( ), ' -- 1 gRandome.Rndm() -- Shoot random[', i, ']= ', gRandom.Rndm( ) rndm.setSeed(1234) for i in xrange(10): print rndm.name( ), ' -- 2 Geant4Random(CLHEP) -- Shoot random[', i, ']= ', rndm.rndm_clhep( ) rndm.setSeed(1234) for i in xrange(10):
# open connection to MySQL server on localhost db = TSQLServer.Connect("mysql://localhost/test", "nobody", "") # first clean table of old entries res = db.Query("DELETE FROM runcatalog") # start timer timer = TStopwatch() timer.Start() # fill run catalog for i in range(nfiles): dataset = "testrun_%d" % i rawfile = "/v1/data/lead/test/run_%d.root" % i tag = int(gRandom.Rndm() * 10.) sql = ins % (dataset, i, evt, evt + 10000, tag, 25.5, "test", "lead", rawfile, "test run dummy data") evt += 10000 res = db.Query(sql) # print("%s" % sql) # stop timer and print results timer.Stop() rtime = timer.RealTime() ctime = timer.CpuTime() print("") print("%d files in run catalog" % nfiles) print("RealTime=%f seconds, CpuTime=%f seconds" % (rtime, ctime))
# Move main geant random instance from rndm1 to rndm2: # See how gRandom and HepRandom instances move DDG4.Geant4Random.setMainInstance(rndm1.get()) logging.info('DEFAULT Engine: %s', DDG4.CLHEP.HepRandom.getTheEngine().name()) logging.info('DDG4 DEFAULT: %s', DDG4.Geant4Random.instance().engine().name()) rndm = DDG4.Geant4Random.instance() rndm.setSeed(1234) rndm.showStatus() for i in xrange(10): logging.info( "%s -- 0 gRandome.Rndm() -- Shoot random[[%d]= %f", rndm.name(), i, gRandom.Rndm()) rndm.setSeed(1234) for i in xrange(10): logging.info( "%s -- 1 gRandome.Rndm() -- Shoot random[[%d]= %f", rndm.name(), i, gRandom.Rndm()) rndm.setSeed(1234) for i in xrange(10): logging.info( "%s -- 2 Geant4Random(CLHEP) -- Shoot random[[%d]= %f", rndm.name(), i, rndm.rndm_clhep()) rndm.setSeed(1234) for i in xrange(10):
# rndm2.showStatus() DDG4.Geant4Random.setMainInstance(rndm1.get()) rndm1.showStatus() # Move main geant random instance from rndm1 to rndm2: # See how gRandom and HepRandom instances move DDG4.Geant4Random.setMainInstance(rndm1.get()) logger.info('DEFAULT Engine: %s', DDG4.CLHEP.HepRandom.getTheEngine().name()) logger.info('DDG4 DEFAULT: %s', DDG4.Geant4Random.instance().engine().name()) rndm = DDG4.Geant4Random.instance() rndm.setSeed(1234) rndm.showStatus() for i in range(10): logger.info("%s -- 0 gRandome.Rndm() -- Shoot random[[%d]= %f", rndm.name(), i, gRandom.Rndm()) rndm.setSeed(1234) for i in range(10): logger.info("%s -- 1 gRandome.Rndm() -- Shoot random[[%d]= %f", rndm.name(), i, gRandom.Rndm()) rndm.setSeed(1234) for i in range(10): logger.info("%s -- 2 Geant4Random(CLHEP) -- Shoot random[[%d]= %f", rndm.name(), i, rndm.rndm_clhep()) rndm.setSeed(1234) for i in range(10): logger.info("%s -- 3 Geant4Random(CLHEP) -- Shoot random[[%d]= %f", rndm.name(), i, rndm.rndm_clhep()) rndm.setSeed(1234) for i in range(10):
output_file.cd() output_ntuple = TNtupleD( "neutrino_tracks", "neutrino_tracks", (":".join(variables_names_list[0:nb_saved_variables]))) event_container[variables_names_list.index( "R_Earth_emitted" )] = parameters["earth_radius"] + parameters["neutrino_altitude"] energy = c_double() c_theta = c_double() print(toolbox.info, "Generating neutrino tracks...") for i_event in tqdm(range(parameters["nb_events"])): # sampling neutrino type, then sample energy / cos_theta random_number = gRandom.Rndm() * neutrino_global_normalisation for neutrino_name in neutrino_names_list: if random_number < neutrino_type_threshold[neutrino_name]: event_container[variables_names_list.index( "PDG_code")] = neutrinos_PDG_codes[neutrino_name] neutrino_spectra_dict[neutrino_name].GetRandom2(energy, c_theta) break event_container[variables_names_list.index("E_nu")] = energy.value event_container[variables_names_list.index("cos_theta_SK")] = c_theta.value event_container[variables_names_list.index( "phi")] = gRandom.Rndm() * 2 * math.pi # calculations event_container[variables_names_list.index("delta_R_SK")] = 4 event_container[variables_names_list.index("delta_R_SK")] *= \ ( event_container[variables_names_list.index("R_Earth_emitted")]**2 ) + \