Project
Loading...
Searching...
No Matches
TrackDumperSpec.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
12#include "TrackDumperSpec.h"
13
19#include "Framework/Lifetime.h"
20#include "Framework/Logger.h"
21#include "Framework/Task.h"
23#include <iostream>
24#include <vector>
25
26using namespace o2::framework;
27
28namespace o2::mch
29{
30void dump(std::ostream& os, const o2::mch::TrackMCH& t)
31{
32 auto pt = std::sqrt(t.getPx() * t.getPx() + t.getPy() * t.getPy());
33 os << fmt::format("({:s}) p {:7.2f} pt {:7.2f} nclusters: {} \n", t.getSign() == -1 ? "-" : "+", t.getP(), pt, t.getNClusters());
34}
35
37
38 bool mUseMC{false};
39
40 TrackDumper(bool useMC) : mUseMC(useMC) {}
41
42 void init(InitContext& ic)
43 {
44 }
45
46 void process(gsl::span<const o2::mch::ROFRecord> rofs,
47 gsl::span<const o2::mch::TrackMCH> tracks,
48 gsl::span<const o2::MCCompLabel> labels)
49 {
50 for (const auto& rof : rofs) {
51 const auto& tracksInRof = tracks.subspan(rof.getFirstIdx(), rof.getNEntries());
52 for (auto i = 0; i < tracksInRof.size(); i++) {
53 const auto& t = tracksInRof[i];
54 std::cout << fmt::format("Track {:4d}/{:4d} : ", i + 1, tracksInRof.size());
55 dump(std::cout, t);
56 if (!labels.empty()) {
57 const auto& labelsInRof = labels.subspan(rof.getFirstIdx(), rof.getNEntries());
58 labelsInRof[i].print();
59 }
60 }
61 }
62 }
63
65 {
66 auto tracks = pc.inputs().get<gsl::span<o2::mch::TrackMCH>>("tracks");
67 auto rofs = pc.inputs().get<gsl::span<o2::mch::ROFRecord>>("trackrofs");
68 if (mUseMC) {
69 auto labels = pc.inputs().get<gsl::span<o2::MCCompLabel>>("tracklabels");
70 process(rofs, tracks, labels);
71 } else {
72 process(rofs, tracks, {});
73 }
74 }
75};
76
78{
79 Inputs inputs{};
80 inputs.emplace_back("trackrofs", "MCH", "TRACKROFS", 0, Lifetime::Timeframe);
81 inputs.emplace_back("tracks", "MCH", "TRACKS", 0, Lifetime::Timeframe);
82 if (useMC) {
83 inputs.emplace_back("tracklabels", "MCH", "TRACKLABELS", 0, Lifetime::Timeframe);
84 }
85
86 return DataProcessorSpec{
88 inputs,
89 {},
90 adaptFromTask<TrackDumper>(useMC),
91 {}};
92}
93} // namespace o2::mch
int32_t i
Definition of the MCH ROFrame record.
Definition of the MCH track.
const char * specName
decltype(auto) get(R binding, int part=0) const
InputRecord & inputs()
The inputs associated with this processing context.
MCH track external format.
Definition TrackMCH.h:34
double getP() const
Definition TrackMCH.cxx:68
double getPx() const
Definition TrackMCH.cxx:43
int getNClusters() const
get the number of clusters attached to the track
Definition TrackMCH.h:106
double getPy() const
Definition TrackMCH.cxx:50
short getSign() const
get the muon sign
Definition TrackMCH.h:65
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< InputSpec > Inputs
DataProcessorSpec getTrackDumperSpec(bool useMC, const char *specName)
void dump(std::ostream &os, const o2::mch::TrackMCH &t)
void process(gsl::span< const o2::mch::ROFRecord > rofs, gsl::span< const o2::mch::TrackMCH > tracks, gsl::span< const o2::MCCompLabel > labels)
void init(InitContext &ic)
void run(ProcessingContext &pc)