Version 247 (modified by 5 years ago) ( diff ) | ,
---|
Table of Contents
Spectrum Analysis
The differential flux
per area, time and energy interval is defined asOften
is also referred to as as observation time and effective collection area is a constant. The effective area is then defined as . Note that at large distances the efficiency vanishes, so that the effective area is an (energy dependent) constant while and the efficiency are mutually dependent.For an observation with an effective observation time
, this yields in a given Energy interval :For simplicity, in the following,
will be replaced by just but always refers to to a given energy interval. If data is binned in a histogram, the relation between the x-value for the bin and the corresponding interval is not well defined. Resonable definitions are the bin center (usually in logarithmic bins) or the average energy.The total area
and the corresponding efficiency are of course only available for simulated data. For simulated data, is the production area and the corresponding energy dependent efficiency of the analysis chain. For a given energy bin, the efficiency is then defined as
where
is the number of simulated events in this energy bin and the number of *excess* events that are produced by the analysis chain.Note that the exact calculation of the efficiency
depends on prior knowledge of the correct source spectrum . Therefore, it is strictly speaking only correct if the simulated spectrum and the real spectrum are identical. As the real spectrum is unknown, special care has to be taken of the systematic introduced by the assumption of .Excess
The number of excess events, for data and simulations, is defined as
where
is the number of events identified as potential gammas from the source direction ('on-source') and the number of gamma-like events measured 'off-source'. Note that for Simulations, is not necessarily zero for wobble-mode observations as an event can survive the analysis for on- and off-events, if this is not prevented by the analysis (cuts).The average number of background events
is the total number of background events from all off-regions times the corresponding weight (often referred to as ). For five off-regions, this yields
Assuming Gaussian errors, the statistical error is thus
For data this immediately resolves to
with the Poisson (counting) error
.Code
In the following
refers to a number of simulated events and to a number of measured (excess) events.is the number of produced events in the energy interval and the zenith angle interval . The weighted number of events in that interval is then
Since
with the spectral weight to adapt the spectral shape of the simulated spectrum to the real (measured) spectrum of the source and the weight to adapt to oberservation time versus zenith angle.
The weighted number of produced events
in the total energy interval and the total zenith angle interval is then
with
being the total number of produced events.For a sum of weights, e.g.
the corresponding error isAs the energy is well defined,
and thus
The weights are defined as follow:
where
is the simulated spectrum and the (unknown) real source spectrum. is a normalization constant. The zenith angle weights in the interval are defined as
where
is the number of produced events in the interval and is the total observation time in the same zenith angle interval. is the normalization constant. The error on the weight in each individual -bin with and is then
While
is given by the data acquisition and 1s per 5min run, is just the statistical error of the number of events.As the efficiency
for an energy interval is calculated as
and
and are both expressed as the sum given above, the constants and cancel.The differential flux in an energy interval
is then given as
Where
is total area of production and the total observation time. The number of measured excess events is in that energy interval is .Using Gaussian error propagation, the error in a given energy interval
is then given by
with
.
Define Binnings
Get Data File List
A list with file IDs containing the events to be analyed is required a.t.m. The following query retrieves such a list and fills a temporary table (DataFiles
) with the IDs.
CREATE TEMPORARY TABLE DataFiles ( FileId INT UNSIGNED NOT NULL, PRIMARY KEY (FileId) USING HASH ) ENGINE=Memory AS ( SELECT FileId FROM factdata.RunInfo WHERE %0:where ORDER BY FileId )
%0:where
is a placeholder, for example for
fZenithDistanceMean<30 AND fThresholdMinSet<350 AND fSourceKEY=5 AND fRunTypeKEY=1 AND fNight>20161201 AND fNight<20170201 AND fR750Cor>0.9e0*fR750Ref
Get Observation Time
The following query bins the effective observation time of the runs listed above in zenith angle bins and stores the result in a temporary table (ObservationTime
). Note that the result contains only those bins which have entries.
CREATE TEMPORARY TABLE ObservationTime ( `.theta` SMALLINT UNSIGNED NOT NULL, OnTime FLOAT NOT NULL, PRIMARY KEY (`.theta`) USING HASH ) ENGINE=Memory AS ( SELECT INTERVAL(fZenithDistanceMean, %0:bins) AS `.theta`, SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))*fEffectiveOn) AS OnTime FROM DataFiles LEFT JOIN factdata.RunInfo USING (FileId) GROUP BY `.theta` ORDER BY `.theta` )
%0:bins
is a placeholder for the bin boundaries, e.g. 5, 10, 15, 20, 25, 30
(five bins between 5° and 30° plus underflow and overflow).
Get Monte Carlo File List
The next query obtains all Monte Carlo runs which have their ThetaMin or ThetaMax within one of the bins obtained in the previous query (so all MC runs that correspond to bins in which data is available). Strictly speaking, this step is not necessary, but it accelerats further processing. In addition (here as an example) only runs with even FileIDs are obtained as test-runs (assuming that odd runs were used for training). The resulting FileIDs are stored in a temporary table (MonteCarloFiles
).
CREATE TEMPORARY TABLE MonteCarloFiles ( FileId INT UNSIGNED NOT NULL, PRIMARY KEY (FileId) USING HASH ) ENGINE=Memory AS ( SELECT FileId FROM ObservationTime LEFT JOIN BinningTheta ON `.theta`=bin LEFT JOIN factmc.RunInfoMC ON (ThetaMin>=lo AND ThetaMin<hi) OR (ThetaMax>lo AND ThetaMax<=hi) WHERE PartId=1 AND FileId%%2=0 ORDER BY FileId )
Get Zenith Angle Histogram
The following table creates a temporaray table (EventCount
) internally which bins the MonetCarlo files from the file list in MonteCarloFiles in zenith angle bins. This temporary table ois then joined with table containing the binning for the data files (EventCount) and for each bin, the ratio (ZdWeight) and the corresponding error (ErrZdWeight) is calculated (assuming an error on the on-time of 1s per 5min).
CREATE TEMPORARY TABLE ThetaHist ( `.theta` SMALLINT UNSIGNED NOT NULL, lo DOUBLE NOT NULL COMMENT 'Lower edge of zenith distance bin in degree', hi DOUBLE NOT NULL COMMENT 'Upper edge of zenith distance bin in degree', CountN INT UNSIGNED NOT NULL, OnTime FLOAT NOT NULL, ZdWeight DOUBLE NOT NULL COMMENT 'tau(delta theta)', ErrZdWeight DOUBLE NOT NULL COMMENT 'sigma(tau)', PRIMARY KEY (`.theta`) USING HASH ) ENGINE=Memory AS ( WITH EventCount AS ( SELECT INTERVAL(DEGREES(Theta), %0:bins) AS `.theta`, COUNT(*) AS CountN FROM MonteCarloFiles LEFT JOIN factmc.OriginalMC USING(FileId) GROUP BY `.theta` ) SELECT `.theta`, lo, hi, CountN, OnTime, OnTime/CountN AS ZdWeight, (OnTime/CountN)*SQRT(POW(1/300, 2) + 1/CountN) AS ErrZdWeight FROM ObservationTime LEFT JOIN EventCount USING(`.theta`) LEFT JOIN BinningTheta ON `.theta`=bin ORDER BY `.theta` )
%0:bins
is a placeholder for the bin boundaries, e.g. 5, 10, 15, 20, 25, 30
(five bins between 5° and 30° plus underflow and overflow). It should be identical to the binning used for data files in DataFiles.
Analyze Data
Analyze Monte Carlo Data
Summarize Corsika Production
CREATE TEMPORARY TABLE SimulatedSpectrum ( `.energy` SMALLINT UNSIGNED NOT NULL COMMENT 'Bin Index [MC Energy]', CountN DOUBLE NOT NULL, CountW DOUBLE NOT NULL, CountW2 DOUBLE NOT NULL, PRIMARY KEY (`.energy`) USING HASH ) ENGINE=Memory AS ( SELECT INTERVAL(LOG10(Energy), %0:energyest) AS `.energy`, COUNT(*) AS CountN, SUM( (%2:spectrum)/pow(Energy, SpectralIndex) ) AS CountW, SUM(POW((%2:spectrum)/pow(Energy, SpectralIndex),2)) AS CountW2 FROM MonteCarloFiles LEFT JOIN factmc.RunInfoMC USING (FileId) LEFT JOIN factmc.OriginalMC USING (FileId) GROUP BY `.energy` ORDER BY `.energy` )