Project
Loading...
Searching...
No Matches
ClustererTask.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
14
17#include "MathUtils/Cartesian.h"
18#include "MathUtils/Utils.h"
19#include <fairlogger/Logger.h>
20#include <TFile.h>
21#include <TTree.h>
22
23using namespace o2::its;
24
25//_____________________________________________________________________
26ClustererTask::ClustererTask(bool useMC, bool raw) : mRawDataMode(raw),
27 mUseMCTruth(useMC && (!raw))
28{
29 LOG(info) << Class()->GetName() << ": MC digits mode: " << (mRawDataMode ? "OFF" : "ON")
30 << " | Use MCtruth: " << (mUseMCTruth ? "ON" : "OFF");
31
33}
34
35//_____________________________________________________________________
37{
38 mCompClus.clear();
39 mClsLabels.clear();
40}
41
42//_____________________________________________________________________
44{
46
47 if (mReader) {
48 return; // already initialized
49 }
50
51 // create reader according to requested raw of MC mode
52 if (mRawDataMode) {
53 mReaderRaw = std::make_unique<o2::itsmft::RawPixelReader<o2::itsmft::ChipMappingITS>>();
54 mReader = mReaderRaw.get();
55 } else { // clusterizer of digits
56 mReaderMC = std::make_unique<o2::itsmft::DigitPixelReader>();
57 mReader = mReaderMC.get();
58 }
59
60 mClusterer.print();
61
62 return;
63}
64
65//_____________________________________________________________________
66void ClustererTask::run(const std::string inpName, const std::string outName)
67{
68 // standalone execution
69 Init(); // create reader, clusterer
70
71 if (mRawDataMode) {
72
73 mReaderRaw->openInput(inpName);
74 mClusterer.process(1, *mReaderRaw.get(), &mCompClus, &mPatterns, &mROFRecVec, nullptr);
75
76 auto basename = outName.substr(0, outName.size() - sizeof("root"));
77 auto nFiles = int(mROFRecVec.size() / maxROframe);
78 int i = 0;
79 for (; i < nFiles; i++) {
80 writeTree(basename, i);
81 }
82 writeTree(basename, i); // The remainder
83
84 } else {
85
86 mReaderMC->openInput(inpName, o2::detectors::DetID("ITS"));
87
88 TFile outFile(outName.data(), "new");
89 if (!outFile.IsOpen()) {
90 LOG(fatal) << "Failed to open output file " << outName;
91 }
92
93 TTree outTree("o2sim", "ITS Clusters");
94
95 auto compClusPtr = &mCompClus;
96 outTree.Branch("ITSClusterComp", &compClusPtr);
97
98 auto rofRecVecPtr = &mROFRecVec;
99 outTree.Branch("ITSClustersROF", &rofRecVecPtr);
100
101 auto clsLabelsPtr = &mClsLabels;
102 if (mUseMCTruth && mReaderMC->getDigitsMCTruth()) {
103 // digit labels are provided directly to clusterer
104 outTree.Branch("ITSClusterMCTruth", &clsLabelsPtr);
105 } else {
106 mUseMCTruth = false;
107 }
108 LOG(info) << Class()->GetName() << " | MCTruth: " << (mUseMCTruth ? "ON" : "OFF");
109
110 outTree.Branch("ITSClusterPatt", &mPatterns);
111
112 std::vector<o2::itsmft::MC2ROFRecord> mc2rof, *mc2rofPtr = &mc2rof;
113 if (mUseMCTruth) {
114 auto mc2rofOrig = mReaderMC->getMC2ROFRecords();
115 mc2rof.reserve(mc2rofOrig.size());
116 for (const auto& m2r : mc2rofOrig) { // clone from the span
117 mc2rof.push_back(m2r);
118 }
119 outTree.Branch("ITSClustersMC2ROF", mc2rofPtr);
120 }
121
122 // loop over entries of the input tree
123 while (mReaderMC->readNextEntry()) {
124 mClusterer.process(1, *mReaderMC.get(), &mCompClus, &mPatterns, &mROFRecVec, &mClsLabels);
125 }
126
127 outTree.Fill();
128 outTree.Write();
129 }
130
131 mClusterer.clear();
132}
133
134void ClustererTask::writeTree(std::string basename, int i)
135{
136 auto name = basename + std::to_string(i) + ".root";
137 TFile outFile(name.data(), "new");
138 if (!outFile.IsOpen()) {
139 LOG(fatal) << "Failed to open output file " << name;
140 }
141 TTree outTree("o2sim", "ITS Clusters");
142
143 size_t max = (i + 1) * maxROframe;
144 auto lastf = (max < mROFRecVec.size()) ? mROFRecVec.begin() + max : mROFRecVec.end();
145 std::vector<o2::itsmft::ROFRecord> rofRecBuffer(mROFRecVec.begin() + i * maxROframe, lastf);
146 std::vector<o2::itsmft::ROFRecord>* rofRecPtr = &rofRecBuffer;
147 outTree.Branch("ITSClustersROF", rofRecPtr);
148
149 auto first = rofRecBuffer[0].getFirstEntry();
150 auto last = rofRecBuffer.back().getFirstEntry() + rofRecBuffer.back().getNEntries();
151
152 std::vector<CompClusterExt> compClusBuffer, *compClusPtr = &compClusBuffer;
153 compClusBuffer.assign(&mCompClus[first], &mCompClus[last]);
154 outTree.Branch("ITSClusterComp", &compClusPtr);
155 outTree.Branch("ITSClusterPatt", &mPatterns);
156
157 for (auto& rof : rofRecBuffer) {
158 rof.setFirstEntry(rof.getFirstEntry() - first);
159 }
160
161 outTree.Fill();
162 outTree.Write();
163}
General auxilliary methods.
int32_t i
Definition of the ITS cluster finder task.
Static class with identifiers, bitmasks and names for ALICE detectors.
Definition DetID.h:58
void run(const std::string inpName, const std::string outName)
ClustererTask(bool useMC=true, bool raw=false)
void writeTree(std::string basename, int i)
static constexpr int getNChips()
number of chips per barrel
void process(int nThreads, PixelReader &r, CompClusCont *compClus, PatternCont *patterns, ROFRecCont *vecROFRec, MCTruth *labelsCl=nullptr)
Definition Clusterer.cxx:27
void setNChips(int n)
load the dictionary of cluster topologies
Definition Clusterer.h:226
GLuint const GLchar * name
Definition glcorearb.h:781
GLint first
Definition glcorearb.h:399
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
constexpr size_t max
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"