Esempio n. 1
0
    def __init__(self, options):
        self.rebin = options.rebin
        self.options = options
        self.pedfile_fullres_name = options.pedfile_fullres_name
        self.tmpname = options.tmpname
        geometryPSet = open(
            'modules_config/geometry_{det}.txt'.format(det=options.geometry),
            'r')
        geometryParams = eval(geometryPSet.read())
        self.cg = cameraGeometry(geometryParams)
        self.xmax = self.cg.npixx

        if not os.path.exists(self.pedfile_fullres_name):
            print("WARNING: pedestal file with full resolution ",
                  self.pedfile_fullres_name,
                  " not existing. First calculate them...")
            self.calcPedestal(options, 1)
        if not options.justPedestal:
            print("Pulling pedestals...")
            # first the one for clustering with rebin
            ctools = cameraTools(self.cg)
            # then the full resolution one
            pedrf_fr = ROOT.TFile.Open(self.pedfile_fullres_name)
            self.pedmap_fr = pedrf_fr.Get('pedmap').Clone()
            self.pedmap_fr.SetDirectory(0)
            self.pedarr_fr = hist2array(self.pedmap_fr).T
            self.noisearr_fr = ctools.noisearray(self.pedmap_fr).T
            pedrf_fr.Close()
            if options.vignetteCorr:
                self.vignmap = ctools.loadVignettingMap()
            else:
                self.vignmap = np.ones((self.xmax, self.xmax))
Esempio n. 2
0
    def __init__(self, options, shape, neighbor_window=6):
        self.options = options
        self.shape = shape
        self.neighbor_window = neighbor_window
        self.debug = options.debug_mode
        self.calibrate = self.options.calibrate_clusters

        # geometry
        geometryPSet = open(
            'modules_config/geometry_{det}.txt'.format(det=options.geometry),
            'r')
        geometryParams = eval(geometryPSet.read())
        self.cg = cameraGeometry(geometryParams)

        # supercluster energy calibration for the saturation effect
        filePar = open('modules_config/energyCalibrator.txt', 'r')
        params = eval(filePar.read())
        self.calibrator = EnergyCalibrator(params, self.debug)
Esempio n. 3
0
 def __init__(self, hits, rebin, img_fr, img_fr_zs, geometry, debug=False):
     self.hits = hits
     self.rebin = rebin
     self.debug = debug
     self.x = hits[:, 0]
     self.y = hits[:, 1]
     if img_fr.any() and img_fr_zs.any():
         self.hits_fr, self.hits_fr_zs = self.fullResHits(img_fr, img_fr_zs)
     else:
         print(
             "WARNING! Cluster created without underlying image... Are you using it standalone?"
         )
     self.mean_point = np.array([np.mean(self.x), np.mean(self.y)])
     self.EVs, self.theta = self.eigenvectors()
     self.widths = {}
     self.profiles = {}
     self.shapes = {}
     geometryPSet = open(
         'modules_config/geometry_{det}.txt'.format(det=geometry), 'r')
     geometryParams = eval(geometryPSet.read())
     self.cg = cameraGeometry(geometryParams)
     self.minDistKiller = self.cg.npixx
     self.nMatchKiller = 0
     self.nMatchKillerWeak = 0
Esempio n. 4
0
    def calcVignettingMap(self,
                          run,
                          pedfile,
                          outfile,
                          maxImages=1000,
                          rebin=12,
                          det='lime',
                          daq='midas'):

        ################ GEOMETRY ###
        geometryPSet = open(
            'modules_config/geometry_{det}.txt'.format(det=det), 'r')
        geometryParams = eval(geometryPSet.read())
        cg = cameraGeometry(geometryParams)
        ctools = cameraTools(cg)
        #############################

        # pedestal map, full reso
        pedrf_fr = ROOT.TFile.Open(pedfile)
        pedmap_fr = pedrf_fr.Get('pedmap').Clone()
        pedmap_fr.SetDirectory(0)
        pedarr_fr = hist2array(pedmap_fr).T
        noisearr_fr = ctools.noisearray(pedmap_fr).T
        pedrf_fr.Close()

        outname_base = os.path.basename(outfile).split('.')[0]
        tf_out = ROOT.TFile.Open(outname_base + '.root', 'recreate')

        N = cg.npixx
        nx = int(N / rebin)
        ny = int(N / rebin)
        normmap = ROOT.TH2D('normmap', 'normmap', nx, 0, N, nx, 0, N)

        mapsum = np.zeros((nx, nx))

        USER = os.environ['USER']
        if sw.checkfiletmp(int(run)):
            infile = "/tmp/%s/histograms_Run%05d.root" % (USER, int(run))
        else:
            print('Downloading file: ' + sw.swift_root_file('Data', int(run)))
            infile = sw.swift_download_root_file(
                sw.swift_root_file('Data', int(run)), int(run))

        tf_in = sw.swift_read_root_file(infile)

        framesize = 216 if det == 'lime' else 0

        #files = ["~/Work/data/cygnus/run03930.root","~/Work/data/cygnus/run03931.root","~/Work/data/cygnus/run03932.root"]
        #for f in files:
        tf_in = ROOT.TFile(f)

        # first calculate the mean
        for i, e in enumerate(tf_in.GetListOfKeys()):
            iev = i if daq != 'midas' else i / 2  # when PMT is present

            if maxImages > -1 and i < len(tf_in.GetListOfKeys()) - maxImages:
                continue
            name = e.GetName()
            obj = e.ReadObj()
            if not obj.InheritsFrom('TH2'): continue
            print("Calc pixel sums with event: ", name)
            arr = hist2array(obj)

            # Upper Threshold full image
            #img_cimax = np.where(arr < 300, arr, 0)
            img_cimax = arr
            img_fr_sub = ctools.pedsub(img_cimax, pedarr_fr)
            img_fr_zs = ctools.zsfullres(img_fr_sub, noisearr_fr,
                                         nsigma=1) * 1e-8

            # for lime, remove the borders of the sensor
            if det == 'lime':
                #img_fr_zs[:framesize,:]=0
                #img_fr_zs[-framesize:,:]=0
                img_fr_zs[:, :framesize] = 0
                img_fr_zs[:, -framesize:] = 0

            img_rb_zs = ctools.arrrebin(img_fr_zs, rebin)
            mapsum = np.add(mapsum, img_rb_zs)
        print(mapsum)

        # calc the normalized map wrt the center area
        CA = 16
        central_square = mapsum[int((N - CA) / rebin / 2):int((N + CA) /
                                                              rebin / 2),
                                int((N - CA) / rebin / 2):int((N + CA) /
                                                              rebin / 2)]
        print(central_square)
        norm = np.mean(central_square)
        print("Now normalizing to the central area value = ", norm)
        mapnorm = mapsum / float(norm)
        if det == 'lime':
            framesize_rb = int(framesize / rebin)
            #mapnorm[:framesize_rb,:]=1
            #mapnorm[-framesize_rb:,:]=1
            mapnorm[:, :framesize_rb] = 1
            mapnorm[:, -framesize_rb:] = 1

        # now save in a persistent ROOT object. Threshold to 1
        for ix in range(nx):
            for iy in range(nx):
                normmap.SetBinContent(ix + 1, iy + 1, min(mapnorm[ix, iy], 1.))
        tf_in.Close()

        tf_out.cd()
        normmap.Write()
        tf_out.Close()
        print(
            "Written the mean map with rebinning {rb}x{rb} into file {outf}.".
            format(rb=rebin, outf=outfile))