Project
Loading...
Searching...
No Matches
export-to-tree.cxx
Go to the documentation of this file.
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
13#include <iostream>
14#include <fmt/format.h>
15#include <boost/program_options.hpp>
16#include <TTree.h>
17#include <TFile.h>
18#include <stdexcept>
19
20namespace po = boost::program_options;
21using namespace o2::mch::mapping;
22
23#ifdef RUN2
24constexpr bool run2{true};
25#else
26constexpr bool run2{false};
27#endif
28
29constexpr int MaxNofPadsPerDE{28672};
40
41void createPadBranches(TTree& tree, DePads& depads)
42{
43 tree.Branch("nDePad", &depads.nDePad, "nDePad/I")
44 ->SetTitle("Number of pads in detection element");
45 tree.Branch("deid", &depads.deid, "deid/I")
46 ->SetTitle("Detection element id");
47 tree.Branch(fmt::format("DePad_{}", run2 ? "manu" : "dsid").c_str(),
48 &depads.dsid,
49 fmt::format("DePad_{}[nDePad]/I", run2 ? "manu" : "dsid").c_str())
50 ->SetTitle("FEE id of n-th pad of this detection element (cm)");
51 tree.Branch(fmt::format("DePad_{}", run2 ? "ch" : "dsch").c_str(),
52 &depads.dsch,
53 fmt::format("DePad_{}[nDePad]/I", run2 ? "ch" : "dsch").c_str())
54 ->SetTitle("FEE channel of n-th pad of this detection element (cm)");
55 tree.Branch("DePad_x", &depads.x, "DePad_x[nDePad]/F")
56 ->SetTitle("x position of n-th pad of this detection element (cm)");
57 tree.Branch("DePad_y", &depads.y, "DePad_y[nDePad]/F")
58 ->SetTitle("y position of n-th pad of this detection element (cm)");
59 tree.Branch("DePad_dx", &depads.dx, "DePad_dx[nDePad]/F")
60 ->SetTitle("half size in x direction of n-th pad of this detection element (cm)");
61 tree.Branch("DePad_dy", &depads.dy, "DePad_dy[nDePad]/F")
62 ->SetTitle("half size in y direction of n-th pad of this detection element (cm)");
63}
64
78int main(int argc, char** argv)
79{
80 std::string outputFileName;
81 po::variables_map vm;
82 po::options_description options("options");
83 std::string defaultName = fmt::format("mch-mapping{}-tree.root", run2 ? "-run2" : "");
84 // clang-format off
85 options.add_options()
86 ("help,h", "produce help message")
87 ("outfile,o",po::value<std::string>(&outputFileName)->default_value(defaultName),"path to output file")
88 ;
89 // clang-format on
90
91 po::options_description cmdline;
92 cmdline.add(options);
93
94 po::store(po::command_line_parser(argc, argv).options(cmdline).run(), vm);
95
96 if (vm.count("help")) {
97 std::cout << fmt::format("This program exports the MCH {}mapping to a Root tree\n",
98 run2 ? "(Run2 version) " : "");
99 std::cout << " --outfile path to the output file containing the Root tree";
100 std::cout << options << "\n";
101 return 2;
102 }
103
104 try {
105 po::notify(vm);
106 } catch (boost::program_options::error& e) {
107 std::cout << "Error: " << e.what() << "\n";
108 exit(1);
109 }
110
111 TFile fout(outputFileName.c_str(), "RECREATE");
112 if (!fout.IsOpen()) {
113 std::cout << "Cannot open output file " << outputFileName << "\n";
114 exit(2);
115 }
116
117 TTree tree("mchpads", "Muon Chamber Pads");
118 DePads depads;
119 createPadBranches(tree, depads);
120
121 forEachDetectionElement([&depads, &tree](int deid) {
122 Segmentation seg{deid};
123 if (seg.nofPads() > MaxNofPadsPerDE) {
124 throw std::logic_error(fmt::format("Something is wrong : max number of pads should be below {} but got {}", MaxNofPadsPerDE, seg.nofPads()));
125 }
126 depads.nDePad = seg.nofPads();
127 depads.deid = deid;
128 for (auto padid = 0; padid < depads.nDePad; padid++) {
129 depads.dsid[padid] = seg.padDualSampaId(padid);
130 depads.dsch[padid] = seg.padDualSampaChannel(padid);
131 depads.x[padid] = seg.padPositionX(padid);
132 depads.y[padid] = seg.padPositionY(padid);
133 depads.dx[padid] = seg.padSizeX(padid) / 2.0;
134 depads.dy[padid] = seg.padSizeY(padid) / 2.0;
135 }
136 tree.Fill();
137 });
138
139 tree.Write();
140 return 0;
141}
o2::mch::mapping::CathodeSegmentation seg
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
double padSizeY(int catPadIndex) const
double padSizeX(int catPadIndex) const
int padDualSampaChannel(int catPadIndex) const
int padDualSampaId(int catPadIndex) const
double padPositionY(int catPadIndex) const
double padPositionX(int catPadIndex) const
A Segmentation lets you find pads of a detection element and then inspect those pads.
constexpr bool run2
void createPadBranches(TTree &tree, DePads &depads)
constexpr int MaxNofPadsPerDE
GLint GLenum GLint x
Definition glcorearb.h:403
GLint y
Definition glcorearb.h:270
void forEachDetectionElement(CALLABLE &&func)
float y[MaxNofPadsPerDE]
float dy[MaxNofPadsPerDE]
int dsch[MaxNofPadsPerDE]
float x[MaxNofPadsPerDE]
float dx[MaxNofPadsPerDE]
int dsid[MaxNofPadsPerDE]
#define main
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))