From 59e95d014fb905bdc3ad561d51c5dcc3c8a2ac75 Mon Sep 17 00:00:00 2001 From: "Bastian M. Wojek" Date: Sun, 16 Nov 2008 17:14:37 +0000 Subject: [PATCH] Absorbed Andreas' fakeData in the TPofTCalc-class --- .../TFitPofB-lib/classes/TLondon1D.cpp | 4 +- .../TFitPofB-lib/classes/TPofTCalc.cpp | 208 +++++++++++++++++- src/external/TFitPofB-lib/include/TPofTCalc.h | 4 +- 3 files changed, 209 insertions(+), 7 deletions(-) diff --git a/src/external/TFitPofB-lib/classes/TLondon1D.cpp b/src/external/TFitPofB-lib/classes/TLondon1D.cpp index 1cf67040..06971a5e 100644 --- a/src/external/TFitPofB-lib/classes/TLondon1D.cpp +++ b/src/external/TFitPofB-lib/classes/TLondon1D.cpp @@ -1071,9 +1071,9 @@ TLondon1D3LSub::TLondon1D3LSub() : fCalcNeeded(true), fFirstCall(true), fWeights } //------------------ -// TLondon1D3L-Method that calls the procedures to create B(z), p(B) and P(t) +// TLondon1D3LSub-Method that calls the procedures to create B(z), p(B) and P(t) // It finally returns P(t) for a given t. -// Parameters: all the parameters for the function to be fitted through TLondon1D3L +// Parameters: all the parameters for the function to be fitted through TLondon1D3LSub //------------------ double TLondon1D3LSub::operator()(double t, const vector &par) const { diff --git a/src/external/TFitPofB-lib/classes/TPofTCalc.cpp b/src/external/TFitPofB-lib/classes/TPofTCalc.cpp index 1ad25e0b..273baa82 100644 --- a/src/external/TFitPofB-lib/classes/TPofTCalc.cpp +++ b/src/external/TFitPofB-lib/classes/TPofTCalc.cpp @@ -5,20 +5,55 @@ Author: Bastian M. Wojek e-mail: bastian.wojek@psi.ch - 2008/09/02 + 2008/11/16 ***************************************************************************/ +/*************************************************************************** + + TPofTCalc::FakeData Method based on Andreas Suter's fakeData + +***************************************************************************/ + +/*************************************************************************** + * Copyright (C) 2008 by Andreas Suter * + * andreas.suter@psi.ch * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + #include "TPofTCalc.h" #include "fftw3.h" #include #include #include +#include +#include +#include +#include +#include +#include + +#include "TLemRunHeader.h" + /* USED FOR DEBUGGING ----------------------- #include #include -/--------------------------------------------*/ +--------------------------------------------*/ //------------------ // Constructor of the TPofTCalc class - it creates the FFT plan @@ -120,15 +155,180 @@ void TPofTCalc::CalcPol(const vector &par) { } } +//--------------------- +// Method for generating fake LEM decay histograms from p(B) +// Parameters: par(dt, dB, timeres, channels, asyms, phases, t0s, N0s, bgs), output filename +//--------------------- + +void TPofTCalc::FakeData(const vector &par, const string &rootOutputFileName) { + + //determine the number of histograms to be built + unsigned int numHist(0); + if(!((par.size()-4)%5)) + numHist=(par.size()-4)/5; + + if(!numHist){ + cout << "The number of parameters for the histogram creation is not correct. Do nothing." << endl; + return; + } + + cout << numHist << " histograms to be built" << endl; + + vector param; + param.push_back(0.0); + param.push_back(par[0]); + param.push_back(par[1]); + + vector< vector > asy; + vector asydata; + double ttime(0.0); + double pol(0.0); + + for(unsigned int i(0); i > histo; + vector data; + double value; + + for (unsigned int i(0); i> histo " << i+1 << "/" << numHist << " done ..."; + } + + // add Poisson noise to the histograms + + cout << endl << ">> add Poisson noise ..." << endl; + + TH1F* theoHisto; + TH1F* fakeHisto; + vector histoData; + + TString name; + for (unsigned int i(0); iSetBinContent(j, histo[i][j]); + // fill fakeHisto + fakeHisto->FillRandom(theoHisto, (int)theoHisto->Integral()); + + // keep fake data + histoData.push_back(fakeHisto); + + // cleanup + if (theoHisto) { + delete theoHisto; + theoHisto = 0; + } + } + + // save the histograms as root files + // create run info folder and content + TFolder *runInfoFolder = new TFolder("RunInfo", "Run Info"); + TLemRunHeader *runHeader = new TLemRunHeader(); + //sprintf(str, "Fake Data generated from %s", pBFileName.Data()); + runHeader->SetRunTitle("Fake Data"); + float fval = par[2]*1000.; //us->ns + runHeader->SetTimeResolution(fval); + runHeader->SetNChannels(int(par[3])); + runHeader->SetNHist(histoData.size()); + double *t0array = new double[histoData.size()]; + for (unsigned int i(0); iSetTimeZero(t0array); + if (t0array) + delete t0array; + runInfoFolder->Add(runHeader); + + // create decay histo folder and content + TFolder *histoFolder = new TFolder("histos", "histos"); + TFolder *decayAnaModule = new TFolder("DecayAnaModule", "DecayAnaModule"); + histoFolder->Add(decayAnaModule); + // no post pileup corrected (NPP) + for (unsigned int i(0); iAdd(histoData[i]); + // post pileup corrected (PPC) + vector histoDataPPC; + for (unsigned int i(0); i(histoData[i]->Clone())); + if (i < 10) + name = "hDecay2"; + else + name = "hDecay"; + name += i; + histoDataPPC[i]->SetNameTitle(name.Data(), name.Data()); + decayAnaModule->Add(histoDataPPC[i]); + } + + // write file + TFile fdf(rootOutputFileName.c_str(), "recreate"); + runInfoFolder->Write("RunInfo", TObject::kSingleKey); + histoFolder->Write(); + fdf.Close(); + + // clean up + for (unsigned int i(0); i> DONE." << endl; + + return; +} + //--------------------- // Method for evaluating P(t) at a given t //--------------------- double TPofTCalc::Eval(double t) const { for (unsigned int i(0); i #define PI 3.14159265358979323846 +#define tauMu 2.197147 class TPofTCalc { @@ -29,6 +30,7 @@ public: vector DataPT() const {return fPT;} void DoFFT(const TPofBCalc&); void CalcPol(const vector&); + void FakeData(const vector&, const string&); double Eval(double) const; private: