Skip to content

Commit 7ba8397

Browse files
lubynetsalibuild
andauthored
[PWGHF] runMassFitter: add main() function and missing header, provide Readme (#11611)
Co-authored-by: ALICE Action Bot <alibuild@cern.ch>
1 parent 5e04fa8 commit 7ba8397

File tree

6 files changed

+140
-10
lines changed

6 files changed

+140
-10
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
project(HFInvMassFitter)
4+
5+
set(HFFITTER_RAPIDJSON_INCLUDE_DIRS "" CACHE STRING "Location of rapidjson include directories")
6+
7+
find_package(ROOT REQUIRED COMPONENTS RooFit RooFitCore)
8+
9+
include_directories(${ROOT_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR} ${HFFITTER_RAPIDJSON_INCLUDE_DIRS})
10+
11+
set(SOURCES
12+
HFInvMassFitter.cxx
13+
runMassFitter.C
14+
)
15+
16+
add_executable(runMassFitter ${SOURCES} "HFInvMassFitter.h")
17+
18+
ROOT_GENERATE_DICTIONARY(G__HFInvMassFitter
19+
HFInvMassFitter.h LINKDEF HFInvMassFitterLinkDef.h
20+
MODULE runMassFitter
21+
)
22+
23+
target_link_libraries(runMassFitter PRIVATE ${ROOT_LIBRARIES} ROOT::EG ROOT::RooFit ROOT::RooFitCore)

PWGHF/D2H/Macros/HFInvMassFitter.cxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
/// \author Mingyu Zhang <mingyu.zang@cern.ch>
1717
/// \author Xinye Peng <xinye.peng@cern.ch>
1818
/// \author Biao Zhang <biao.zhang@cern.ch>
19+
/// \author Oleksii Lubynets <oleksii.lubynets@cern.ch>
1920

2021
#include "HFInvMassFitter.h"
2122

@@ -33,9 +34,6 @@
3334
#include <RooPolynomial.h>
3435
#include <RooRealVar.h>
3536
#include <RooWorkspace.h>
36-
37-
#include <Rtypes.h>
38-
#include <RtypesCore.h>
3937
#include <TColor.h>
4038
#include <TDatabasePDG.h>
4139
#include <TLine.h>
@@ -45,6 +43,9 @@
4543
#include <TStyle.h>
4644
#include <TVirtualPad.h>
4745

46+
#include <Rtypes.h>
47+
#include <RtypesCore.h>
48+
4849
#include <array>
4950
#include <cmath>
5051
#include <cstring>

PWGHF/D2H/Macros/HFInvMassFitter.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,22 @@
1616
/// \author Mingyu Zhang <mingyu.zang@cern.ch>
1717
/// \author Xinye Peng <xinye.peng@cern.ch>
1818
/// \author Biao Zhang <biao.zhang@cern.ch>
19+
/// \author Oleksii Lubynets <oleksii.lubynets@cern.ch>
1920

2021
#ifndef PWGHF_D2H_MACROS_HFINVMASSFITTER_H_
2122
#define PWGHF_D2H_MACROS_HFINVMASSFITTER_H_
2223

2324
#include <RooPlot.h>
2425
#include <RooRealVar.h>
2526
#include <RooWorkspace.h>
26-
#include <Rtypes.h>
27-
#include <RtypesCore.h>
28-
2927
#include <TF1.h>
3028
#include <TH1.h>
3129
#include <TNamed.h>
3230
#include <TVirtualPad.h>
3331

32+
#include <Rtypes.h>
33+
#include <RtypesCore.h>
34+
3435
#include <cstdio>
3536

3637
class HFInvMassFitter : public TNamed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// \file HFInvMassFitterLinkDef.h
13+
/// \brief HFInvMassFitter dictionary definition file
14+
///
15+
/// \author Zhen Zhang <zhenz@cern.ch>
16+
/// \author Mingyu Zhang <mingyu.zang@cern.ch>
17+
/// \author Xinye Peng <xinye.peng@cern.ch>
18+
/// \author Biao Zhang <biao.zhang@cern.ch>
19+
/// \author Oleksii Lubynets <oleksii.lubynets@cern.ch>
20+
21+
#ifndef PWGHF_D2H_MACROS_HFINVMASSFITTERLINKDEF_H_
22+
#define PWGHF_D2H_MACROS_HFINVMASSFITTERLINKDEF_H_
23+
24+
#ifdef __CINT__
25+
#pragma link off all globals;
26+
#pragma link off all classes;
27+
#pragma link off all functions;
28+
#pragma link C++ class HFInvMassFitter + ;
29+
#endif
30+
31+
#endif // PWGHF_D2H_MACROS_HFINVMASSFITTERLINKDEF_H_

PWGHF/D2H/Macros/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Invariant-mass fitter
2+
Invariant-mass fitter is implemented in the class `HFInvMassFitter` (`HFInvMassFitter.cxx/h` files), and its run is executed via `runMassFitter.C` macro.
3+
Fitter is configured in `config_massfitter.json`.\
4+
The fitter is **not** a part of O2Physics source code.
5+
6+
## Dependencies
7+
1. ROOT
8+
2. RapidJSON. Download the header-only (no compilation needed) RapidJSON library, see the link <https://rapidjson.org>.
9+
10+
If you have O2Physics compilation you do not need to fulfill these dependencies explicitly.
11+
12+
## How to run
13+
### As a ROOT macro
14+
The `runMassFitter.C` can be compiled as ROOT macro.
15+
```bash
16+
cd path-to-o2physics-src/PWGHF/D2H/Macros
17+
source path-to-root-install/bin/thisroot.sh
18+
export ROOT_INCLUDE_PATH=$ROOT_INCLUDE_PATH:path-to-json-include
19+
root -l -x -b -q "HFInvMassFitter.cxx" "runMassFitter.C(\"config_massfitter.json\")"
20+
```
21+
If you have O2Physics compilation and enter into its environment there is no need to set environment variables (skip lines 2-3 above).
22+
23+
### As a CMake project
24+
It is also possible to compile the fitter as a CMake project or insert it into existing one if any.
25+
Use the `CMakeLists_HFInvMassFitter.txt` (rename it into `CMakeLists.txt` before usage).\
26+
Compile the fitter with the following steps:
27+
```bash
28+
cd path-to-o2physics-src/PWGHF/D2H/Macros
29+
mkdir build
30+
cd build
31+
source path-to-root-install/bin/thisroot.sh
32+
cmake -DHFFITTER_RAPIDJSON_INCLUDE_DIRS=path-to-json-include ../
33+
make
34+
```
35+
and run the fitter:
36+
```bash
37+
./runMassFitter ../config_massfitter.json
38+
```
39+
### Directly from the terminal
40+
Compile the fitter with the following steps:
41+
```bash
42+
cd path-to-o2physics-src/PWGHF/D2H/Macros
43+
mkdir build
44+
cd build
45+
source path-to-root-install/bin/thisroot.sh
46+
47+
# Generate ROOT dictionary:
48+
rootcling -f G__HFInvMassFitter.cxx -c ../HFInvMassFitter.h ../HFInvMassFitterLinkDef.h
49+
50+
# Compile source code:
51+
g++ -fPIC -I$(root-config --incdir) -I path-to-json-include -c ../HFInvMassFitter.cxx ../runMassFitter.C G__HFInvMassFitter.cxx
52+
53+
# Link the executable:
54+
g++ -o runMassFitter HFInvMassFitter.o runMassFitter.o G__HFInvMassFitter.o $(root-config --libs) -lRooFit -lRooFitCore -lEG
55+
```
56+
and run the fitter:
57+
```bash
58+
./runMassFitter ../config_massfitter.json
59+
```

PWGHF/D2H/Macros/runMassFitter.C

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@
1616
/// \author Mingyu Zhang <mingyu.zang@cern.ch>
1717
/// \author Xinye Peng <xinye.peng@cern.ch>
1818
/// \author Biao Zhang <biao.zhang@cern.ch>
19+
/// \author Oleksii Lubynets <oleksii.lubynets@cern.ch>
1920

2021
#if !defined(__CINT__) || defined(__CLING__)
2122

2223
#include "HFInvMassFitter.h"
2324

2425
// if .h file not found, please include your local rapidjson/document.h and rapidjson/filereadstream.h here
26+
#include <TCanvas.h>
27+
#include <TDatabasePDG.h>
28+
#include <TFile.h>
29+
#include <TH2F.h>
30+
2531
#include <rapidjson/document.h>
2632
#include <rapidjson/filereadstream.h>
2733

@@ -30,10 +36,6 @@
3036
#include <string> // std::string
3137
#include <vector> // std::vector
3238

33-
#include <TDatabasePDG.h>
34-
#include <TFile.h>
35-
#include <TH2F.h>
36-
3739
#endif
3840

3941
using namespace rapidjson;
@@ -672,3 +674,16 @@ void divideCanvas(TCanvas* canvas, int nSliceVarBins)
672674
}
673675
}
674676
}
677+
678+
int main(int argc, char* argv[])
679+
{
680+
if (argc == 1) {
681+
throw std::runtime_error("Not enough arguments. Please use\n./runMassFitter configFileName");
682+
}
683+
684+
const std::string configFileName = argv[1];
685+
686+
runMassFitter(configFileName);
687+
688+
return 0;
689+
}

0 commit comments

Comments
 (0)