1 #ifndef __JSUPERNOVA_JLIGHTCURVEBACKGROUNDGENERATOR__ 
    2 #define __JSUPERNOVA_JLIGHTCURVEBACKGROUNDGENERATOR__ 
   44     int n = in->GetNbinsX();
 
   48     for (
int i = 0; i < 
n; i++) {
 
   49       out[i] = in->GetBinContent(i + 1);
 
   91       TString rt_tag = 
".RT_DET_SUM";
 
   92       TString nc_tag = 
".NC_DET_SUM";
 
   93       TString rt2d_tag = 
".RT2D_DET";
 
   97       TIter iter(in->GetListOfKeys());
 
   99       for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
 
  101         const TString tag(key->GetName());
 
  104         if (tag.EndsWith(rt_tag)) {
 
  106           TString rt_hist_tag = tag;
 
  107           TString run_tag = TString(tag, tag.Length() - rt_tag.Length());
 
  109           TString nc_hist_tag = run_tag + nc_tag;
 
  111           TH1D* RT = (TH1D*) in->Get(rt_hist_tag);
 
  112           TH1D* NC = (TH1D*) in->Get(nc_hist_tag);
 
  117           int n = nc_buf.size();
 
  124           for (
int i = 0; i < 
n; i++) {
 
  127               nc.back().push_back( nc_buf[i] );
 
  128               for (
int j = 100 * i; 
j < 100 * (i + 1); 
j++) {
 
  129                 rt.back().push_back( rt_buf[
j] );
 
  135             TString rt2d_hist_tag = run_tag + rt2d_tag;
 
  136             h2d_t* RT2D = (
h2d_t*) in->Get(rt2d_hist_tag);
 
  139               RT2D->SetDirectory(0);
 
  140               rt2d.push_back(RT2D);
 
  181     void configureRatio(
const int inputNumberOfLines, 
const int outputNumberOfLines) {
 
  182       outputSize   = inputNumberOfLines;
 
  184       genRatio     = outputNumberOfLines / inputNumberOfLines;
 
  186       genScale     = outputNumberOfLines / (1.0 * inputNumberOfLines * genRatio);
 
  200       int k = rnd->Integer(rt.size());
 
  202       int limit = rt[k].size() - (genRatio * TWindow_ms);
 
  204       int start = rnd->Integer(limit);
 
  206       for (
int i = 0; i < genRatio; i++) {
 
  208         for (
int j = 0; 
j < TWindow_ms; 
j++) {
 
  210           int bin = start + (i * TWindow_ms) +  
j;
 
  212           out[0][
j] += genScale * rt[k].at(bin      );
 
  213           out[1][
j] += genScale * nc[k].at(bin / 100);
 
  229       double mu = outputSize * 18 * domRate_Hz * 1.0e-3; 
 
  231       for (
unsigned i = 0; i < out[0].size(); i++) {
 
  233         double count  = rnd->Poisson(mu);
 
  236         out[1][i] = outputSize * 18 * 31;
 
  254       int nRuns = rt.size();
 
  256       int k = rnd->Integer(nRuns);
 
  261       int offset = rnd->Integer(100);
 
  263       for (
int i = 0; i < genRatio; i++) {
 
  265         int start = 100 * rnd->Integer(nc[k].size() - ceil(TWindow_ms / 100.0)) + offset;
 
  267         for (
int j = 0; 
j < TWindow_ms; 
j++) {
 
  271           out[0][
j] += genScale * rt[k].at(bin      );
 
  272           out[1][
j] += genScale * nc[k].at(bin / 100);
 
  277           k = rnd->Integer(nRuns);
 
  291       h2d_t* proto = rt2d[k];
 
  293       int ny   = proto->GetNbinsY();
 
  294       int ymin = proto->GetYaxis()->GetXmin(); 
 
  295       int ymax = proto->GetYaxis()->GetXmax();
 
  297       h2d_t* out = 
new h2d_t(
"sample", NULL, TWindow_ms, 0, TWindow_ms, ny, ymin, ymax);        
 
  299       for (
int i = 0; i < genRatio; i++) {
 
  301         for (
int j = 0; 
j < TWindow_ms; 
j++) {
 
  303           int xbin = 1 + start + (i * TWindow_ms) +  
j;
 
  305           for (
int ybin = 1; ybin <= rt2d[k]->GetNbinsY(); ybin++) {
 
  307             double val = rt2d[k]->GetBinContent(xbin, ybin);    
 
  309             double bcx = ((TAxis*)out->GetXaxis())->GetBinCenter(
j + 1);
 
  310             double bcy = ((TAxis*)out->GetYaxis())->GetBinCenter(ybin);
 
  312             out->Fill(bcx, bcy, val);
 
  332       for (
int i = 0; i < genRatio; i++) {
 
  334         for (
int j = 0; 
j < TWindow_ms; 
j++) {
 
  336           int bin = start + (i * TWindow_ms) +  
j;
 
  338           out[
j] += genScale * nc[k].at(bin / 100);
 
  352       const int n = in.size();
 
  356       for (
int i = 0; i < 
n; i++) {
 
  371       if (rt2d.size() > 0) {
 
  373         int k = rnd->Integer(rt2d.size());
 
  375         int limit = rt2d[k]->GetNbinsX() - (genRatio * TWindow_ms);
 
  377         int start = rnd->Integer(limit);
 
  379         out = build_H2D(k, start);
 
  383       if (rb != 1) { out->RebinX(rb); }
 
  395       int n = in->GetNbinsX();
 
  403       for (
int bin = 1; bin <= 
n; bin++) {
 
  405         double sg = 0, bg = 0, er = 0;
 
  407         TH1D* h = in->ProjectionY(
"timeBin", bin, bin);
 
  409         if (h->GetEntries() > 0) {
 
  411           TF1 f(
"f", 
"[0]*exp(-0.5*(x-[1])*(x-[1])/([2]*[2]))/(TMath::Sqrt(2*TMath::Pi())*[2]) + [3]");
 
  413           f.SetParameter(0, h->GetMaximum());
 
  414           f.SetParameter(1, h->GetMean());
 
  415           f.SetParameter(2, h->GetRMS() * 0.25);
 
  416           f.SetParameter(3, h->GetMinimum());
 
  418           h->Fit(&f, 
"Q", 
"same");
 
  420           bg = f.GetParameter(3) * h->GetNbinsX();
 
  421           sg = h->GetSumOfWeights() - bg;
 
  422           er = f.GetParError(3) * h->GetNbinsX();
 
  449       int k = rnd->Integer(rt.size());
 
  451       int limit = rt[k].size() - (genRatio * TWindow_ms);
 
  453       int start = rnd->Integer(limit);
 
  455       h2d_t* sample = build_H2D(k, start);
 
  457       if (rb != 1) { sample->RebinX(rb); }
 
  461       out.push_back(fit[0]);
 
  466         out.push_back(build_NC(k, start));
 
  468         out.push_back(rebin(build_NC(k, start), rb));
 
  471       out.push_back(fit[1]);
 
  472       out.push_back(fit[2]);
 
Class to emulate L0 background for an arbitrarily sized detector.
 
h2d_t * generate_H2D(int rb=1)
Generate 2D sample.
 
bg_type generate_fitted(int rb=1)
Generate fitted L1 sample.
 
vector< double > build_NC(const int k, const int start)
Build NC sequence.
 
~JLightCurveBackgroundGenerator()
Destructor.
 
void configureRatio(const int inputNumberOfLines, const int outputNumberOfLines)
Configure generation ratio.
 
static vector< double > rebin(const vector< double > &in, const int rb)
Rebin vector.
 
bg_type generate_poisson(const int domRate_Hz=500)
Generate pure poissionian background.
 
vector< vector< double > > rt
 
bg_type generate_shuffled(bool randomizeRun=false)
Generate sample of L0 background The sampling of the L0 data is not sequential but random within the ...
 
h2d_t * build_H2D(const int k, const int start)
Generate 2D histogram.
 
void configureTimeWindow(const int T_ms)
Configure the duration of an output sample.
 
void setSeed(const UInt_t uSeed=0)
Set TRandom seed.
 
bg_type generate()
Generate sample of L0 background L0 data are randomly sampled from a single L0 dataset.
 
JLightCurveBackgroundGenerator(TFile *in, bool twoDim=false)
Default constructor.
 
static bg_type fit_H2D(h2d_t *in)
Fit 2D sample.
 
vector< vector< double > > nc
 
vector< double > loadHistogram(TH1D *in)
Load histogram values to vector, each bin is converted to an element.
 
vector< vector< double > > bg_type