/*************************************************************************** TPofTCalc.cpp Author: Bastian M. Wojek e-mail: bastian.wojek@psi.ch 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 #include "TLemRunHeader.h" /* USED FOR DEBUGGING ----------------------- #include #include --------------------------------------------*/ //------------------ // Constructor of the TPofTCalc class - it creates the FFT plan // Parameters: phase, dt, dB //------------------ TPofTCalc::TPofTCalc (const string &wisdom, const vector &par) : fWisdom(wisdom) { int init_threads(fftw_init_threads()); if (!init_threads) cout << "TPofTCalc::TPofTCalc: Couldn't initialize multiple FFTW-threads ..." << endl; else fftw_plan_with_nthreads(2); fNFFT = ( int(1.0/gBar/par[1]/par[2]+1.0) % 2 ) ? int(1.0/gBar/par[1]/par[2]+2.0) : int(1.0/gBar/par[1]/par[2]+1.0); fTBin = 1.0/gBar/double(fNFFT-1)/par[2]; fT.resize(fNFFT/2+1); fPT.resize(fNFFT/2+1); int i; #pragma omp parallel for default(shared) private(i) schedule(dynamic) for (i=0; i pB(PofB.DataPB()); /* USED FOR DEBUGGING ----------------------- time_t seconds; seconds = time(NULL); vector B(PofB.DataB()); double Bmin(PofB.GetBmin()); char debugfile[50]; int n = sprintf (debugfile, "test_PB_%ld_%f.dat", seconds, Bmin); if (n > 0) { ofstream of(debugfile); for (unsigned int i(0); i &par) { double sinph(sin(par[0]*PI/180.0)), cosph(cos(par[0]*PI/180.0)); int i; #pragma omp parallel for default(shared) private(i) schedule(dynamic) for (i=0; i &par) { //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 << "TPofTCalc::FakeData: The number of parameters for the histogram creation is not correct. Do nothing." << endl; return; } cout << "TPofTCalc::FakeData: " << numHist << " histograms to be built" << endl; int nChannels = int(par[3]); vector t0; vector asy0; vector phase0; vector N0; vector bg; for(unsigned int i(0); i param; // Parameters for TPofTCalc::CalcPol param.push_back(0.0); // phase param.push_back(par[0]); // dt param.push_back(par[1]); // dB vector< vector > asy; vector asydata(nChannels); double ttime(0.0); int j,k; for(unsigned int i(0); i > histo; vector data(nChannels); for (unsigned int i(0); i histoData; TString name; for (unsigned int i(0); iSetBinContent(j, histo[i][j]); // end omp // 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(nChannels); runHeader->SetNHist(histoData.size()); double *t0array = new double[histoData.size()]; for (unsigned int i(0); iSetTimeZero(t0array); if (t0array) { delete t0array; t0array = 0; } 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