Skip to content

Commit

Permalink
Merge pull request #50 from willp240/formatting
Browse files Browse the repository at this point in the history
Formatting
willp240 authored Aug 27, 2024

Verified

This commit was signed with the committer’s verified signature.
renovate-bot Mend Renovate
2 parents 93b4f81 + 24aab8d commit c96170f
Showing 227 changed files with 9,791 additions and 8,638 deletions.
901 changes: 497 additions & 404 deletions HOWTO.md

Large diffs are not rendered by default.

36 changes: 16 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<h1> OXSX </h1>
Signal Extraction framework for the SNO+ experiment


<h2> Dependencies </h2>
1. GCC compiler capable of compiling C++ code to the C++17 standard

@@ -11,7 +10,7 @@ Signal Extraction framework for the SNO+ experiment

4. [SCons](http://www.scons.org/) Is used for the build, also a dependency for RAT

5. [HDF5](https://www.hdfgroup.org/HDF5/release/obtain5.html) Should be configured to install with c++ support ```./configure --enable-cxx && make && make install```
5. [HDF5](https://www.hdfgroup.org/HDF5/release/obtain5.html) Should be configured to install with c++ support `./configure --enable-cxx && make && make install`

6. [ROOT](https://root.cern.ch/downloading-root) Should be installed with Minuit2 enabled `./configure --enable-minuit2`

@@ -28,35 +27,32 @@ Signal Extraction framework for the SNO+ experiment
<h2>Installation Instructions </h2>
Follow the installation instructions for each of the above using either the default install location or a different directory if you would prefer. Be careful to start the install with a clean environment.

1. Clone this repository with ```git clone https://github.com/snoplus/oxsx.git```
1. Clone this repository with `git clone https://github.com/snoplus/oxsx.git`

2. If your dependencies are somewhere the compiler can't find them, copy `config/userconfig.ini.template` to `config/userconfig.ini` and add the relevant paths. Missing entries are assumed to be in standard locations. e.g.
```
[root]
header_path : <path/to/headers>
lib_path : <path/to/libraries>
```
3. Run ```scons && scons units```: this will compile the OXSX library and subsequently the unit tests.

4. Test the build was sucessful with ```./test/RunUnits```
```
[root]
header_path : <path/to/headers>
lib_path : <path/to/libraries>
```

3. Run `scons && scons units`: this will compile the OXSX library and subsequently the unit tests.

4. Test the build was sucessful with `./test/RunUnits`

<h3> Compiling Your Own Scripts</h3>

scons auto-generates a script that compiles and links your c++ against the source code and dependencies just run ```. <oxsx root>/bin/compile.sh <your cpp file>``` to produce an executible of the same name
scons auto-generates a script that compiles and links your c++ against the source code and dependencies just run `. <oxsx root>/bin/compile.sh <your cpp file>` to produce an executible of the same name

Look in `<oxsx root>/examples` for help getting started

<h2> Creating ntuples </h2>
One way to read in data is using a ROOT ntuple. If you are looking at SNO+ data, you probably have a flat root tree that can be easily pruned down into this format with only the branches you are interested in.

To create ntuples for oxsx run ```./util/prune_flat_tree <path_to_file_to_convert> -treename <name_of_the_tree> <branch1> <branch2> <branch3> -newtreename <name_of_your_tree> -outfile <name_of_your_file> -nevents <number_of_events>```
* The name of the tree in an input file is optional, as a default it is "output"
* The name of the output file is optional, as a default is is <the_name_of_input_file>+"_oxsx.root"
* The name of the tree in an output file is optional, as a default it is "oxsx"
* The number of events of an output file is optional
To create ntuples for oxsx run `./util/prune_flat_tree <path_to_file_to_convert> -treename <name_of_the_tree> <branch1> <branch2> <branch3> -newtreename <name_of_your_tree> -outfile <name_of_your_file> -nevents <number_of_events>`

- The name of the tree in an input file is optional, as a default it is "output"
- The name of the output file is optional, as a default is is <the_name_of_input_file>+"\_oxsx.root"
- The name of the tree in an output file is optional, as a default it is "oxsx"
- The number of events of an output file is optional
35 changes: 20 additions & 15 deletions bench/Bench.cpp
Original file line number Diff line number Diff line change
@@ -3,17 +3,19 @@
#include "Bench.h"
#include <iostream>

/* Taken from SO
http://stackoverflow.com/questions/1861294/how-to-calculate-execution-time-of-a-code-snippet-in-c. Answer
/* Taken from SO
http://stackoverflow.com/questions/1861294/how-to-calculate-execution-time-of-a-code-snippet-in-c. Answer
from Andreas Bonini */

/* Remove if already defined */
typedef long long int64; typedef unsigned long long uint64;
typedef long long int64;
typedef unsigned long long uint64;

/* Returns the amount of milliseconds elapsed since the UNIX epoch.*/

uint64
Bench::GetTimeMs64() const{
uint64
Bench::GetTimeMs64() const
{
/* Linux */
struct timeval tv;

@@ -29,31 +31,34 @@ Bench::GetTimeMs64() const{
return ret;
}

uint64
Bench::TimeElapsed() const{
uint64
Bench::TimeElapsed() const
{
uint64 start = GetTimeMs64();
fFunction();
return GetTimeMs64() - start;
}

long double
Bench::TimeRepetitions(unsigned iterations_){
long double
Bench::TimeRepetitions(unsigned iterations_)
{
fIterations = iterations_;
fMeanTime = 0;
for(unsigned i = 0; i < iterations_; i++){
for (unsigned i = 0; i < iterations_; i++)
{
double timeElapsed = TimeElapsed();
fMeanTime += timeElapsed;

if(!i || timeElapsed < fMinTime)
fMinTime = timeElapsed;
if (!i || timeElapsed < fMinTime)
fMinTime = timeElapsed;
}

fMeanTime = (double)(fMeanTime)/iterations_;
fMeanTime = (double)(fMeanTime) / iterations_;
return fMeanTime;
}

void
Bench::PrintResult() const{
void Bench::PrintResult() const
{
std::cout << "Test " << fName << " Results: " << std::endl;
std::cout << "Average of " << fMeanTime << "ms over " << fIterations << " iterations" << std::endl;
std::cout << "Min execution time " << fMinTime << "ms" << std::endl;
18 changes: 10 additions & 8 deletions bench/Bench.h
Original file line number Diff line number Diff line change
@@ -5,18 +5,20 @@
#define __BENCH__
#include <string>

class Bench{
public:
Bench(void (*func_)(), const std::string& name_ = " ") : fFunction(func_),
fMeanTime(-1), fName(name_), fMinTime(-1) {}
class Bench
{
public:
Bench(void (*func_)(), const std::string &name_ = " ") : fFunction(func_),
fMeanTime(-1), fName(name_), fMinTime(-1) {}

typedef long long int64;
typedef long long int64;
typedef unsigned long long uint64;

long double TimeRepetitions(unsigned iterations_);
void PrintResult() const;
private:
void (*fFunction)();

private:
void (*fFunction)();
uint64 GetTimeMs64() const;
uint64 TimeElapsed() const;
double fMeanTime;
14 changes: 7 additions & 7 deletions bench/BenchTests/PdfBuild.cpp
Original file line number Diff line number Diff line change
@@ -7,7 +7,8 @@
const std::string fileName = "/Users/Jack/snoplus/bbplus/ntuples/fake_pu_ntup.root";
const std::string treeName = "T";

void BuildAPdf(){
void BuildAPdf()
{
// Build the pdf
AxisCollection ax;
ax.AddAxis(BinAxis("energy", 0, 3, 100));
@@ -22,24 +23,23 @@ void BuildAPdf(){
indicies.push_back(3);
pdf.SetObservables(ObsSet(indicies));


// Get the data
ROOTNtuple rHandle(fileName, treeName);
unsigned nEntries = rHandle.GetNEntries();
std::cout << nEntries << " Entries to fill" << std::endl;
// Fill the Pdf
for(size_t i = 0; i < nEntries; i++){
for (size_t i = 0; i < nEntries; i++)
{
pdf.Fill(rHandle.GetEntry(i));
}

return;
}


int main(){
int main()
{
Bench b(&BuildAPdf, "Filling ");
b.TimeRepetitions(100);
b.PrintResult();
return 0;

}
16 changes: 8 additions & 8 deletions examples/Cuts.cpp
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
Cuts are functions that take an event and return true or false, depending on whether the event passes the cut or not.
Cuts can be grouped together into a cut collection, which returns true if all cuts are satisfied.
The CutCollection object is used to FillPdfs or generate data sets, only taking events that pass
The CutCollection object is used to FillPdfs or generate data sets, only taking events that pass
*/
#include <BoxCut.h>
#include <BoolCut.h>
@@ -11,12 +11,13 @@ The CutCollection object is used to FillPdfs or generate data sets, only taking
#include <Event.h>
#include <iostream>

int main(){
int main()
{
// Names for observables
const std::vector<std::string> observables = {"radius", "energy", "external_tag"};
// cut if radius is bigger than two i.e. a lower limit
LineCut lineCut("fv_cut", "radius", 2, "lower");

// cut if second observable is between 5 and 10
BoxCut boxCut("energy_cut", "energy", 5, 10);

@@ -39,22 +40,21 @@ int main(){
fakeEvent.SetObservableNames(&observables);

// test it
std::cout << "Event passes line cut "
std::cout << "Event passes line cut "
<< lineCut.PassesCut(fakeEvent)
<< std::endl;

std::cout << "Event passes box cut "
std::cout << "Event passes box cut "
<< boxCut.PassesCut(fakeEvent)
<< std::endl;

std::cout << "Event passes bool cut "
std::cout << "Event passes bool cut "
<< boolCut.PassesCut(fakeEvent)
<< std::endl;

std::cout << "Event passes all cuts "
std::cout << "Event passes all cuts "
<< combinedCuts.PassesCuts(fakeEvent)
<< std::endl;

return 0;

}
31 changes: 16 additions & 15 deletions examples/DataSetGeneration.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
#include <DataSetGenerator.h>
#include <OXSXDataSet.h>
#include <DataSetGenerator.h>
#include <OXSXDataSet.h>
#include <ROOTNtuple.h>
int main(){
// (filename, tree name)
int main()
{
// (filename, tree name)
ROOTNtuple zeroNuMC("<filename1>", "treename");
ROOTNtuple twoNuMC( "<filename2>", "treename");
ROOTNtuple b8NuMC( "<filename3>", "treename");
ROOTNtuple twoNuMC("<filename2>", "treename");
ROOTNtuple b8NuMC("<filename3>", "treename");

std::vector<bool> bootstraps;
// DataSetGenerator
DataSetGenerator dataGen;
dataGen.AddDataSet(&zeroNuMC, 5, false); // second arg is the expected rate

// DataSetGenerator
DataSetGenerator dataGen;
dataGen.AddDataSet(&zeroNuMC, 5, false); // second arg is the expected rate
bootstraps.push_back(true);
dataGen.AddDataSet(&twoNuMC, 50, false);
bootstraps.push_back(true);
dataGen.AddDataSet(&b8NuMC, 100, false);
bootstraps.push_back(true);

dataGen.SetBootstrap(bootstraps);
// Generate a data set
OXSXDataSet fakeData = dataGen.PoissonFluctuatedDataSet();

// Generate a data set
OXSXDataSet fakeData = dataGen.PoissonFluctuatedDataSet();
OXSXDataSet fakeData2 = dataGen.ExpectedRatesDataSet();
return 0;

return 0;
}
39 changes: 20 additions & 19 deletions examples/beestonBarlowLHH.cpp
Original file line number Diff line number Diff line change
@@ -13,15 +13,16 @@
#include <BinnedNLLH.h>
#include <ParameterDict.h>

const std::string bgMCfile = "";
const std::string sigMCfile = "";
const std::string bgTreeName = "";
const std::string bgMCfile = "";
const std::string sigMCfile = "";
const std::string bgTreeName = "";
const std::string sigTreeName = "";

const std::string dataFile = "";
const std::string dataTreeName = "";

int main(){
int main()
{
////////////////////
// 1. Set Up PDFs //
////////////////////
@@ -35,17 +36,17 @@ int main(){
dataObs.push_back("energy");

// Set up pdf with these bins in this observable
BinnedED bgPdf("bgPDF",axes);
BinnedED bgPdf("bgPDF", axes);
bgPdf.SetObservables(dataObs);

//Hard code bin contents of PDF
bgPdf.SetBinContent(0,20);
bgPdf.SetBinContent(1,35);
bgPdf.SetBinContent(2,30);
bgPdf.SetBinContent(3,15);
// Hard code bin contents of PDF
bgPdf.SetBinContent(0, 20);
bgPdf.SetBinContent(1, 35);
bgPdf.SetBinContent(2, 30);
bgPdf.SetBinContent(3, 15);
bgPdf.Normalise();

//Hard code generated number of events
// Hard code generated number of events
const int gen_rate = 1000;

std::cout << "Initialised PDF" << std::endl;
@@ -54,14 +55,14 @@ int main(){
// 2. Fill with data and normalise //
/////////////////////////////////////

BinnedED bgData("bgData",axes);
BinnedED bgData("bgData", axes);
bgData.SetObservables(dataObs);

//Hard code bin contents of data
bgData.SetBinContent(0,25);
bgData.SetBinContent(1,30);
bgData.SetBinContent(2,40);
bgData.SetBinContent(3,10);
// Hard code bin contents of data
bgData.SetBinContent(0, 25);
bgData.SetBinContent(1, 30);
bgData.SetBinContent(2, 40);
bgData.SetBinContent(3, 10);

std::cout << "Filled data " << std::endl;

@@ -79,10 +80,10 @@ int main(){

ParameterDict parameterValues;

//Set normalisation of PDF
// Set normalisation of PDF
parameterValues["bgPDF"] = 100;

//Calculate and print likelihood
// Calculate and print likelihood
lhFunction.SetParameters(parameterValues);
std::cout << "Total LogL = " << lhFunction.Evaluate() << std::endl;

Loading

0 comments on commit c96170f

Please sign in to comment.