Project
Loading...
Searching...
No Matches
ChamberEfficiencySpec.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
16
18
19#include <string>
20#include <unordered_map>
21#include <gsl/span>
22
23#include "TFile.h"
24#include "TH1.h"
25
27#include "Framework/Task.h"
28#include "Framework/Logger.h"
31#include "MIDBase/Mapping.h"
34
35namespace o2
36{
37namespace mid
38{
39
40using namespace o2::framework;
41
43{
44 public:
45 EfficiencyTask(bool selectMatched) : mSelectMatched(selectMatched){};
46
47 std::vector<TH1F> buildHistos()
48 {
49 Mapping mapping;
50 std::vector<TH1F> histos;
52 std::array<std::string, 4> names{"nFiredBP", "nFiredNBP", "nFiredBoth", "nTot"};
54 std::array<std::string, 3> elName{"Board", "RPC", "Plane"};
56 std::array<double, 3> firstVal{1., 0., 0.};
57 for (size_t iel = 0; iel < elTypes.size(); ++iel) {
58 for (size_t itype = 0; itype < types.size(); ++itype) {
59 std::string name = names[itype] + "per";
60 name += elName[iel];
61 histos.emplace_back(name.c_str(), name.c_str(), nBins[iel], firstVal[iel], nBins[iel] + static_cast<int>(firstVal[iel]));
62 histos.back().GetXaxis()->SetTitle(elName[iel].c_str());
63 for (auto& count : mEfficiency.getChamberEfficiency(elTypes[iel]).getCountersAsVector()) {
64 int ibin = count.deId + 1;
65 if (elTypes[iel] == Efficiency::ElementType::Board) {
66 int ich = detparams::getChamber(count.deId);
67 ibin = ich * detparams::NLocalBoards + mapping.getBoardId(count.lineId, count.columnId, count.deId);
68 }
69 histos.back().SetBinContent(ibin, count.getCounts(types[itype]));
70 }
71 }
72 }
73 return histos;
74 }
75
77 void init(InitContext& ic)
78 {
79
80 // auto config = ic.options().get<std::string>("mid-eff");
81 // if (!config.empty()) {
82 // conf::ConfigurableParam::updateFromFile(config, "MIDEff", true);
83 // }
84
85 auto stop = [this]() {
86 TFile fout("mid-efficiency.root", "RECREATE");
87 auto histos = buildHistos();
88 for (auto& histo : histos) {
89 histo.Write();
90 }
91 // fout.WriteObject(&mEfficiency.getChamberEfficiency().getCountersAsVector(), "counters");
92 fout.Close();
93 };
94 ic.services().get<o2::framework::CallbackService>().set<o2::framework::CallbackService::Id::Stop>(stop);
95 }
96
99 {
100 auto midTracks = pc.inputs().get<gsl::span<mid::Track>>("midtracks");
101 if (mSelectMatched) {
102 auto matchTracks = pc.inputs().get<gsl::span<dataformats::TrackMCHMID>>("matchtracks");
103 mSelectedTracks.clear();
104 mSelectedTracks.reserve(midTracks.size());
105 for (auto& matchTrack : matchTracks) {
106 auto idx = matchTrack.getMIDRef().getIndex();
107 mSelectedTracks.emplace_back(midTracks[idx]);
108 }
109 midTracks = gsl::span<mid::Track>(mSelectedTracks);
110 }
111
112 mEfficiency.process(midTracks);
113 }
114
115 private:
116 Efficiency mEfficiency{};
117 bool mSelectMatched;
118 std::vector<mid::Track> mSelectedTracks{}; // Vector with matched tracks
119};
120
122{
123
124 Inputs inputSpecs{InputSpec{"midtracks", "MID", "TRACKS", 0, Lifetime::Timeframe}};
125 if (selectMatched) {
126 inputSpecs.emplace_back(InputSpec{
127 "matchtracks", "GLO", "MTC_MCHMID", 0, Lifetime::Timeframe});
128 }
129
130 return DataProcessorSpec{
131 "MIDEfficiency",
132 inputSpecs,
133 Outputs{},
134 AlgorithmSpec{adaptFromTask<EfficiencyTask>(selectMatched)},
135 Options{
136 {"mid-eff", VariantType::String, "mid-efficiency.root", {"Root MID RPCs Efficiency"}}}};
137}
138
139} // namespace mid
140} // namespace o2
Reconstructed MID track.
Useful detector parameters for MID.
Mapping for MID.
Computes the MID chamber efficiency.
Definition of the MUON track.
ServiceRegistryRef services()
Definition InitContext.h:34
decltype(auto) get(R binding, int part=0) const
InputRecord & inputs()
The inputs associated with this processing context.
std::vector< ChEffCounter > getCountersAsVector() const
void init(InitContext &ic)
prepare the efficiency
EfficiencyTask(bool selectMatched)
std::vector< TH1F > buildHistos()
void run(ProcessingContext &pc)
run the efficiency
Class to estimate the MID chamber efficiency.
Definition Efficiency.h:31
const ChamberEfficiency & getChamberEfficiency(ElementType et) const
Returns the chamber efficiency.
Definition Efficiency.h:46
void process(gsl::span< const mid::Track > midTracks)
Fill the counters to estimate the chamber efficiency.
@ Plane
Efficiency per RPC.
@ RPC
Efficiency per board.
int getBoardId(int line, int column, int deId, bool warn=true) const
Definition Mapping.cxx:202
GLint GLsizei count
Definition glcorearb.h:399
GLsizei GLenum GLenum * types
Definition glcorearb.h:2516
GLuint const GLchar * name
Definition glcorearb.h:781
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > Inputs
std::vector< OutputSpec > Outputs
constexpr int NDetectionElements
Number of RPCs.
constexpr int NChambers
Number of chambers.
constexpr int NLocalBoards
Number of local boards per chamber.
@ BendPlane
Bending plane counters.
@ BothPlanes
Both plane counters.
@ AllTracks
All tracks counters.
@ NonBendPlane
Non-bending plane counters.
DataProcessorSpec getChamberEfficiencySpec(bool selectMatched)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...