BatchSimulator Class Reference

#include <BatchSimulator.h>

List of all members.

Public Member Functions

 BatchSimulator ()
virtual ~BatchSimulator ()
virtual void CreateSmearedTimeList (Double_t smearing)
virtual void CreateMonteCarloTimeList (Int_t nEvts)
virtual Double_t Offset () const
virtual void Offset (const Double_t offset)
virtual TH1D PlotTrueTimes () const
virtual TH1D PlotSmearedTimes () const
virtual TH1D PlotMonteCarloTimes () const
virtual Double_t Width () const
virtual void Width (const Double_t width)
virtual TH1D WrappedPlotOfTrueTimes () const
virtual TH1D WrappedPlotOfSmearedTimes () const
virtual TH1D WrappedPlotOfMonteCarloTimes () const
virtual void WriteTrueTimesToFile (const char *filename) const
virtual void WriteSmearedTimesToFile (const char *filename) const
virtual void WriteMonteCarloTimesToFile (const char *filename) const
virtual void GenerateMC (int nSamples, int nEventsPerSample, double offset, double smearing, TString outDir)

Private Member Functions

virtual vector< Double_t > CreateTrueTimeList () const
virtual Double_t EventsPerBunch () const
virtual TH1D HistogramTheSpill (const vector< Double_t > &timeList) const
virtual void WriteToFile (const vector< Double_t > &timeList, const char *filename) const
virtual vector< Double_t > TrueTimeList () const
virtual TH1D WrappedBatchPlot (const vector< Double_t > &timeList) const

Private Attributes

Int_t fNumBatches
Int_t fEventsPerBunch
Double_t fOffset
Double_t fWidth
vector< Double_t > fTrueTimeList
vector< Double_t > fSmearedTimeList
vector< Double_t > fMonteCarloTimeList
TRandom3 fRandomator

Detailed Description

Definition at line 17 of file BatchSimulator.h.


Constructor & Destructor Documentation

BatchSimulator::BatchSimulator (  ) 

Definition at line 29 of file BatchSimulator.cxx.

References CreateTrueTimeList(), and fTrueTimeList.

00030 : fNumBatches(6),
00031   fEventsPerBunch(100000),
00032   fOffset(0.0),
00033   fWidth(0.0),
00034   fSmearedTimeList(0),
00035   fRandomator()
00036 
00037 {
00038         fTrueTimeList = this->CreateTrueTimeList();
00039 }

virtual BatchSimulator::~BatchSimulator (  )  [inline, virtual]

Definition at line 21 of file BatchSimulator.h.

00021 {};


Member Function Documentation

void BatchSimulator::CreateMonteCarloTimeList ( Int_t  nEvts  )  [virtual]

Definition at line 135 of file BatchSimulator.cxx.

References fMonteCarloTimeList, fRandomator, and fSmearedTimeList.

Referenced by GenerateMC().

00136 {
00137         vector<Double_t> MCList;
00138         for (Int_t i = 0; i<nEvts; i++){
00139                 Double_t r1 = fRandomator.Integer(fSmearedTimeList.size());
00140                 Double_t MCTime = fSmearedTimeList.at(r1);
00141                 MCList.push_back(MCTime);
00142         }
00143 
00144         fMonteCarloTimeList = MCList;
00145 }

void BatchSimulator::CreateSmearedTimeList ( Double_t  smearing  )  [virtual]

Definition at line 81 of file BatchSimulator.cxx.

References fRandomator, fSmearedTimeList, fTrueTimeList, and it.

Referenced by GenerateMC().

00082 {
00083         vector<Double_t> smearedTimeList;
00084         for (vector<Double_t>::const_iterator it = fTrueTimeList.begin();
00085                         it != fTrueTimeList.end();
00086                         ++it){
00087                 Double_t r1 = fRandomator.Gaus(0,sigma);
00088                 Double_t unsmearedTime = *it;
00089                 Double_t smearedTime = unsmearedTime+r1;
00090                 smearedTimeList.push_back(smearedTime);
00091                 //    std::cout<<smearedTime<<std::endl;
00092         }
00093 
00094         fSmearedTimeList = smearedTimeList;
00095 }

vector< Double_t > BatchSimulator::CreateTrueTimeList (  )  const [private, virtual]

Definition at line 42 of file BatchSimulator.cxx.

References EventsPerBunch(), and Munits::ns.

Referenced by BatchSimulator(), and WrappedPlotOfTrueTimes().

00043 {
00044 
00045         //6 ns of beam every 18.83 ns
00046         //This happens 81 times, then there's a 5-bunch gap
00047 
00048         Double_t bunchBeamLength = 6*Munits::ns;
00049         Double_t bunchSpacing = 18.83*Munits::ns;
00050         Double_t batchSpacing = 86*bunchSpacing;
00051         Int_t filledBunchesPerBatch = 81;
00052 
00053         vector<Double_t> trueTimeList;
00054 
00055         //Loop over the batches in the spill
00056         for (Int_t batchNumber = 0; batchNumber < 6; ++batchNumber){
00057                 Double_t tBatchStart = batchNumber * batchSpacing;
00058 
00059                 cout << "Simulating batch " << batchNumber << endl;
00060 
00061                 //Loop over the bunches in the batch; set the time of the first
00062                 //proton in each case
00063                 for (Int_t bunchNumber = 0; bunchNumber < filledBunchesPerBatch; ++bunchNumber){
00064 
00065                         Double_t tBunchStart = bunchNumber * bunchSpacing;
00066 
00067                         //Loop over the prtons within the bunch
00068                         for (Double_t tWithinBunch = bunchBeamLength / (2.*this->EventsPerBunch());
00069                                         tWithinBunch <= bunchBeamLength;
00070                                         tWithinBunch += bunchBeamLength / this->EventsPerBunch()){
00071 
00072                                 Double_t tWithinSpill = tBunchStart + tWithinBunch + tBatchStart;
00073                                 trueTimeList.push_back(tWithinSpill);
00074                         }
00075                 }
00076         }
00077         return trueTimeList;
00078 }

virtual Double_t BatchSimulator::EventsPerBunch (  )  const [inline, private, virtual]

Definition at line 54 of file BatchSimulator.h.

References fEventsPerBunch.

Referenced by CreateTrueTimeList().

00054 {return fEventsPerBunch;};

void BatchSimulator::GenerateMC ( int  nSamples,
int  nEventsPerSample,
double  offset,
double  smearing,
TString  outDir 
) [virtual]

Definition at line 236 of file BatchSimulator.cxx.

References CreateMonteCarloTimeList(), CreateSmearedTimeList(), Form(), PlotMonteCarloTimes(), WrappedPlotOfMonteCarloTimes(), and WriteMonteCarloTimesToFile().

00238 {
00239         std::cout<<"Generating "<<nSamples<<" fake spill distributions."<<std::endl;
00240         std::cout<<nEventsPerSample<<" events per distribution."<<std::endl;
00241         std::cout<<"Sampling from PDF with gaussian smearing of "<<smearing<<" s"<<std::endl;
00242         std::cout<<"and offset by "<<offset<<" s."<<std::endl;
00243 
00244         this->CreateSmearedTimeList(smearing);
00245         for (int i = 0; i<nSamples; i++){
00246                 TString fileName = Form("tofMC_n%d_s%.0f_o%.0f_%d", nEventsPerSample,
00247                                 smearing*1e9, offset*1e9, i);
00248                 cout<<"Creating file "<<(outDir+fileName+".root").Data()<<endl;
00249 
00250                 this->CreateMonteCarloTimeList(nEventsPerSample);
00251                 TH1D hMCBatch = this->PlotMonteCarloTimes();
00252                 TH1D hMCBatchWrapped = this->WrappedPlotOfMonteCarloTimes();
00253 
00254                 TFile* f = new TFile(outDir+fileName+".root", "RECREATE");
00255                 hMCBatch.Write();
00256                 hMCBatchWrapped.Write();
00257                 f->Close();
00258 
00259                 this->WriteMonteCarloTimesToFile(outDir+fileName+".txt");
00260         }
00261 }

TH1D BatchSimulator::HistogramTheSpill ( const vector< Double_t > &  timeList  )  const [private, virtual]

Definition at line 98 of file BatchSimulator.cxx.

References MuELoss::e, and it.

Referenced by PlotMonteCarloTimes(), PlotSmearedTimes(), and PlotTrueTimes().

00099 {
00100         //   TH1D hSpillTimes("hSpillTimes", "", 2400,-1e-6,12e-6);
00101         TH1D hSpillTimes("hSpillTimes", "", 13e-6/1e-9,-1e-6,12e-6);
00102 
00103         for (vector<Double_t>::const_iterator it = timeList.begin();
00104                         it != timeList.end();
00105                         ++it){
00106                 hSpillTimes.Fill(*it);
00107         }
00108 
00109         return hSpillTimes;
00110 }

virtual void BatchSimulator::Offset ( const Double_t  offset  )  [inline, virtual]

Definition at line 27 of file BatchSimulator.h.

References fOffset.

00027 {fOffset = offset;};

virtual Double_t BatchSimulator::Offset (  )  const [inline, virtual]

Definition at line 26 of file BatchSimulator.h.

References fOffset.

Referenced by WrappedBatchPlot().

00026 {return fOffset;};

TH1D BatchSimulator::PlotMonteCarloTimes (  )  const [virtual]

Definition at line 158 of file BatchSimulator.cxx.

References fMonteCarloTimeList, and HistogramTheSpill().

Referenced by GenerateMC().

00159 {
00160         cout << "Plotting MC times" << endl;
00161         return this->HistogramTheSpill(fMonteCarloTimeList);
00162 }

TH1D BatchSimulator::PlotSmearedTimes (  )  const [virtual]

Definition at line 149 of file BatchSimulator.cxx.

References fSmearedTimeList, and HistogramTheSpill().

00150 {
00151         cout << "Plotting smeared times" << endl;
00152         return this->HistogramTheSpill(fSmearedTimeList);
00153 }

TH1D BatchSimulator::PlotTrueTimes (  )  const [virtual]

Definition at line 167 of file BatchSimulator.cxx.

References HistogramTheSpill(), and TrueTimeList().

00168 {
00169         cout << "Plotting true times" << endl;
00170         return this->HistogramTheSpill(this->TrueTimeList());
00171 }

virtual vector<Double_t> BatchSimulator::TrueTimeList (  )  const [inline, private, virtual]

Definition at line 57 of file BatchSimulator.h.

References fTrueTimeList.

Referenced by PlotTrueTimes().

00057 {return fTrueTimeList;};

virtual void BatchSimulator::Width ( const Double_t  width  )  [inline, virtual]

Definition at line 32 of file BatchSimulator.h.

References fWidth.

00032 {fWidth = width;};

virtual Double_t BatchSimulator::Width (  )  const [inline, virtual]

Definition at line 31 of file BatchSimulator.h.

References fWidth.

00031 {return fWidth;};

TH1D BatchSimulator::WrappedBatchPlot ( const vector< Double_t > &  timeList  )  const [private, virtual]

Definition at line 114 of file BatchSimulator.cxx.

References it, and Offset().

Referenced by WrappedPlotOfMonteCarloTimes(), WrappedPlotOfSmearedTimes(), and WrappedPlotOfTrueTimes().

00115 {
00116         Double_t tempIntPart = 0;
00117         Double_t batchLength = 86*18.83e-9;
00118         Double_t arbitraryOffset = 0.4e-5;
00119 
00120         TH1D hWrappedBatchStructure("hWrappedBatchStructure","",
00121                         86,0,1);
00122 
00123         for (vector<Double_t>::const_iterator it = timeList.begin();
00124                         it != timeList.end();
00125                         ++it){
00126                 Double_t time = *it;
00127                 hWrappedBatchStructure.Fill(modf((time+arbitraryOffset+this->Offset())/batchLength,
00128                                 &tempIntPart));
00129         }
00130 
00131         return hWrappedBatchStructure;
00132 }

TH1D BatchSimulator::WrappedPlotOfMonteCarloTimes (  )  const [virtual]

Definition at line 184 of file BatchSimulator.cxx.

References fMonteCarloTimeList, and WrappedBatchPlot().

Referenced by GenerateMC().

00185 {
00186         return this->WrappedBatchPlot(fMonteCarloTimeList);
00187 }

TH1D BatchSimulator::WrappedPlotOfSmearedTimes (  )  const [virtual]

Definition at line 176 of file BatchSimulator.cxx.

References fSmearedTimeList, and WrappedBatchPlot().

00177 {
00178         return this->WrappedBatchPlot(fSmearedTimeList);
00179 }

TH1D BatchSimulator::WrappedPlotOfTrueTimes (  )  const [virtual]

Definition at line 193 of file BatchSimulator.cxx.

References CreateTrueTimeList(), and WrappedBatchPlot().

00194 {
00195         return this->WrappedBatchPlot(this->CreateTrueTimeList());
00196 }

void BatchSimulator::WriteMonteCarloTimesToFile ( const char *  filename  )  const [virtual]

Definition at line 229 of file BatchSimulator.cxx.

References fMonteCarloTimeList, and WriteToFile().

Referenced by GenerateMC().

00230 {
00231         this->WriteToFile(fMonteCarloTimeList, filename);
00232 }

void BatchSimulator::WriteSmearedTimesToFile ( const char *  filename  )  const [virtual]

Definition at line 213 of file BatchSimulator.cxx.

References fSmearedTimeList, and WriteToFile().

00214 {
00215         this->WriteToFile(fSmearedTimeList, filename);
00216 }

void BatchSimulator::WriteToFile ( const vector< Double_t > &  timeList,
const char *  filename 
) const [private, virtual]

Definition at line 201 of file BatchSimulator.cxx.

References it.

Referenced by WriteMonteCarloTimesToFile(), WriteSmearedTimesToFile(), and WriteTrueTimesToFile().

00202 {
00203         std::ofstream fOut(filename);
00204 
00205         for (vector<Double_t>::const_iterator it = timeList.begin();
00206                         it != timeList.end();
00207                         ++it){
00208                 fOut<<*it<<std::endl;
00209         }
00210         fOut.close();
00211 }

void BatchSimulator::WriteTrueTimesToFile ( const char *  filename  )  const [virtual]

Definition at line 221 of file BatchSimulator.cxx.

References fTrueTimeList, and WriteToFile().

00222 {
00223         this->WriteToFile(fTrueTimeList, filename);
00224 }


Member Data Documentation

Definition at line 45 of file BatchSimulator.h.

Referenced by EventsPerBunch().

vector<Double_t> BatchSimulator::fMonteCarloTimeList [private]
Int_t BatchSimulator::fNumBatches [private]

Definition at line 44 of file BatchSimulator.h.

Double_t BatchSimulator::fOffset [private]

Definition at line 46 of file BatchSimulator.h.

Referenced by Offset().

TRandom3 BatchSimulator::fRandomator [private]

Definition at line 51 of file BatchSimulator.h.

Referenced by CreateMonteCarloTimeList(), and CreateSmearedTimeList().

vector<Double_t> BatchSimulator::fSmearedTimeList [private]
vector<Double_t> BatchSimulator::fTrueTimeList [private]
Double_t BatchSimulator::fWidth [private]

Definition at line 47 of file BatchSimulator.h.

Referenced by Width().


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1