Project
Loading...
Searching...
No Matches
AnomalyStudy.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
15
16#include "Framework/Task.h"
17#include "ITStracking/IOUtils.h"
22
23#include <TH2F.h>
24#include <TF1.h>
25#include <TCanvas.h>
26#include <TStopwatch.h>
27
28namespace o2::its::study
29{
30using namespace o2::framework;
31using namespace o2::globaltracking;
34class AnomalyStudy : public Task
35{
36 static constexpr int nChipStavesIB{9};
37
38 public:
39 AnomalyStudy(std::shared_ptr<DataRequest> dr,
40 std::shared_ptr<o2::base::GRPGeomRequest> gr,
41 bool isMC) : mDataRequest{dr}, mGGCCDBRequest(gr), mUseMC(isMC) {}
42 void init(InitContext& ic) final;
43 void run(ProcessingContext&) final;
45 void finaliseCCDB(ConcreteDataMatcher&, void*) final;
46
47 // custom
48 void prepareOutput();
52
53 private:
54 bool mUseMC;
55 int mTFCount{0};
56 TStopwatch mStopwatch;
57 const int mNumberOfStaves[7] = {12, 16, 20, 24, 30, 42, 48};
58 std::shared_ptr<o2::base::GRPGeomRequest> mGGCCDBRequest;
59 std::shared_ptr<DataRequest> mDataRequest;
60 const o2::itsmft::TopologyDictionary* mDict = nullptr;
61
62 // utils
63 void getClusterPatterns(gsl::span<const o2::itsmft::CompClusterExt>&, gsl::span<const unsigned char>&, const o2::itsmft::TopologyDictionary&);
64 std::vector<o2::itsmft::ClusterPattern> mPatterns;
66 o2::itsmft::ChipMappingITS mChipMapping;
67
68 // Histos
69 std::vector<std::unique_ptr<TH2F>> mTFvsPhiHist;
70 std::vector<std::unique_ptr<TH2F>> mTFvsPhiClusSizeHist;
71 std::vector<std::unique_ptr<TH2F>> mROFvsPhiHist;
72 std::vector<std::unique_ptr<TH2F>> mROFvsPhiClusSizeHist;
73};
74
76{
78 static bool initOnceDone = false;
79 if (!initOnceDone) { // this param need to be queried only once
80 initOnceDone = true;
82 mGeom->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::T2L, o2::math_utils::TransformType::T2GRot, o2::math_utils::TransformType::T2G));
83 }
84}
85
87{
90
91 auto nLayProc = o2::its::study::AnomalyStudyParamConfig::Instance().nLayersToProcess;
92 auto nTF = o2::its::study::AnomalyStudyParamConfig::Instance().nTimeFramesOffset;
93 auto nROF = o2::its::study::AnomalyStudyParamConfig::Instance().nRofTimeFrames;
94 auto doROFAnalysis = o2::its::study::AnomalyStudyParamConfig::Instance().doROFAnalysis;
95
96 mTFvsPhiHist.resize(nLayProc);
97 mTFvsPhiClusSizeHist.resize(nLayProc);
98 if (doROFAnalysis) {
99 mROFvsPhiHist.resize(nLayProc);
100 mROFvsPhiClusSizeHist.resize(nLayProc);
101 }
102 for (unsigned int i = 0; i < nLayProc; i++) {
103 int phiBins = o2::its::study::AnomalyStudyParamConfig::Instance().nPhiBinsMultiplier * mNumberOfStaves[i];
104 mTFvsPhiHist[i].reset(new TH2F(Form("tf_phi_occup_layer_%d", i), Form("Occupancy layer %d ; #phi ; # TF; Counts", i), phiBins, -TMath::Pi(), TMath::Pi(), nTF, 0.5, nTF + 0.5));
105 mTFvsPhiClusSizeHist[i].reset(new TH2F(Form("tf_phi_clsize_layer_%d", i), Form("Cluster size layer %d ; #phi; # TF ; #lt Cluster Size #gt", i), phiBins, -TMath::Pi(), TMath::Pi(), nTF, 0.5, nTF + 0.5));
106 if (doROFAnalysis) {
107 mROFvsPhiHist[i].reset(new TH2F(Form("rof_phi_occup_layer_%d", i), Form("Occupancy layer %d ; #phi; # ROF; Counts", i), phiBins, -TMath::Pi(), TMath::Pi(), nROF * nTF, 0.5, nROF * nTF + 0.5));
108 mROFvsPhiClusSizeHist[i].reset(new TH2F(Form("rof_phi_clsize_layer_%d", i), Form("Cluster size layer %d; #phi; # ROF; #lt Cluster Size #gt", i), phiBins, -TMath::Pi(), TMath::Pi(), nROF * nTF, 0.5, nROF * nTF + 0.5));
109 }
110 }
111}
112
114{
116 recoData.collectData(pc, *mDataRequest.get());
117 updateTimeDependentParams(pc); // Make sure this is called after recoData.collectData, which may load some conditions
118 process(recoData);
119}
120
122{
123 TFile* f = TFile::Open(o2::its::study::AnomalyStudyParamConfig::Instance().outFileName.c_str(), "recreate");
124 auto nLayProc = o2::its::study::AnomalyStudyParamConfig::Instance().nLayersToProcess;
125 auto doROFAnalysis = o2::its::study::AnomalyStudyParamConfig::Instance().doROFAnalysis;
126
127 // Iterate over all the histograms and compute the averages
128 for (unsigned int i = 0; i < nLayProc; i++) {
129 mTFvsPhiClusSizeHist[i]->Divide(mTFvsPhiHist[i].get());
130 if (doROFAnalysis) {
131 mROFvsPhiClusSizeHist[i]->Divide(mROFvsPhiHist[i].get());
132 }
133 }
134
135 // Fit slices along x of the 2D histograms
136 for (unsigned int iLayer = 0; iLayer < nLayProc; ++iLayer) {
137 int phiBins = o2::its::study::AnomalyStudyParamConfig::Instance().nPhiBinsMultiplier * mNumberOfStaves[iLayer];
138 TObjArray aSlices;
139 auto* f1 = new TF1(Form("f1_%d", iLayer), "pol0", -TMath::Pi(), TMath::Pi());
140 auto* hPValue = new TH1F(Form("pValue_%d", iLayer), Form("pValue_%d", iLayer), mTFvsPhiClusSizeHist[iLayer]->GetNbinsY(), 0.5, mTFvsPhiClusSizeHist[iLayer]->GetNbinsY() + 0.5);
141 mTFvsPhiClusSizeHist[iLayer]->FitSlicesX(f1, 0, -1, 0, "QNR", &aSlices);
142 auto* hChi2 = (TH1D*)aSlices.At(1);
143 for (auto iTF{0}; iTF < hChi2->GetEntries(); ++iTF) {
144 auto pValue = TMath::Prob(hChi2->GetBinContent(iTF + 1) * (phiBins - 1), phiBins - 1);
145 // LOGP(info, "Layer: {} TF: {} Chi2: {} Pvalue: {}", iLayer, iTF, hChi2->GetBinContent(iTF + 1), pValue);
146 hPValue->SetBinContent(iTF + 1, pValue);
147 }
148 hPValue->Write();
149 // Save slices to file
150 for (unsigned int j = 0; j < aSlices.GetEntries(); ++j) {
151 auto h = (TH1D*)aSlices.At(j);
152 h->SetMinimum(0);
153 h->Write();
154 }
155
156 // Do the same for ROFs
157 if (doROFAnalysis) {
158 TObjArray aSlicesROF;
159 auto f1ROF = new TF1(Form("f1ROF_%d", iLayer), "pol0", -TMath::Pi(), TMath::Pi());
160 mROFvsPhiClusSizeHist[iLayer]->FitSlicesX(f1ROF, 0, -1, 0, "QNR", &aSlicesROF);
161 // Save slices to file
162 for (unsigned int j = 0; j < aSlicesROF.GetEntries(); ++j) {
163 auto h = (TH1D*)aSlicesROF.At(j);
164 h->SetMinimum(0);
165 h->Write();
166 }
167 }
168 }
169
170 for (unsigned int i = 0; i < nLayProc; i++) {
171 mTFvsPhiHist[i]->Write();
172 mTFvsPhiClusSizeHist[i]->Write();
173 if (doROFAnalysis) {
174 mROFvsPhiHist[i]->Write();
175 mROFvsPhiClusSizeHist[i]->Write();
176 }
177 }
178 f->Close();
179}
180
182{
184 return;
185 }
186 if (matcher == ConcreteDataMatcher("ITS", "CLUSDICT", 0)) {
188 return;
189 }
190}
191
192// custom
194{
195 mStopwatch.Start();
196 mTFCount++;
197 auto nROF = o2::its::study::AnomalyStudyParamConfig::Instance().nRofTimeFrames;
198 auto nLayProc = o2::its::study::AnomalyStudyParamConfig::Instance().nLayersToProcess;
199 auto doROFAnalysis = o2::its::study::AnomalyStudyParamConfig::Instance().doROFAnalysis;
200 int lay, sta, ssta, mod, chipInMod;
201 // in the staggered readout the clusters and their ROFs are provided per layer, every layer having its
202 // own ROF length and numbering; all the filled histograms are per layer, hence each layer slot is
203 // processed with its own ROF counter
204 int nLr = recoData.getITSPerLayer() ? o2::globaltracking::MaxITSLayers : 1;
205 for (int lr = 0; lr < nLr; lr++) { // with a single (monolithic) input all clusters are in the layer slot 0
206 int rofCount = 0;
207 auto clusRofRecords = recoData.getITSClustersROFRecords(lr);
208 auto compClus = recoData.getITSClusters(lr);
209 auto clusPatt = recoData.getITSClustersPatterns(lr);
210
211 getClusterPatterns(compClus, clusPatt, *mDict);
212
213 auto pattIt = clusPatt.begin();
214 std::vector<ITSCluster> globalClusters;
215 o2::its::ioutils::convertCompactClusters(compClus, pattIt, globalClusters, mDict);
216
217 for (auto& rofRecord : clusRofRecords) {
218 auto clustersInRof = rofRecord.getROFData(compClus);
219 auto patternsInRof = rofRecord.getROFData(mPatterns);
220 auto locClustersInRof = rofRecord.getROFData(globalClusters);
221 for (unsigned int clusInd{0}; clusInd < clustersInRof.size(); clusInd++) {
222 const auto& compClus = clustersInRof[clusInd];
223 auto& locClus = locClustersInRof[clusInd];
224 auto& clusPattern = patternsInRof[clusInd];
225 auto gloC = locClus.getXYZGlo(*mGeom);
226 mChipMapping.expandChipInfoHW(compClus.getChipID(), lay, sta, ssta, mod, chipInMod);
227 if (lay >= nLayProc) {
228 continue;
229 }
230 float phi = TMath::ATan2(gloC.Y(), gloC.X());
231 mTFvsPhiHist[lay]->Fill(phi, mTFCount);
232 mTFvsPhiClusSizeHist[lay]->Fill(phi, mTFCount, clusPattern.getNPixels());
233 if (doROFAnalysis) {
234 mROFvsPhiHist[lay]->Fill(phi, (mTFCount - 1) * nROF + rofCount);
235 mROFvsPhiClusSizeHist[lay]->Fill(phi, (mTFCount - 1) * nROF + rofCount, clusPattern.getNPixels());
236 }
237 }
238 ++rofCount;
239 }
240 } // loop over the layer slots
241 mStopwatch.Stop();
242 LOGP(info, "Processed TF: {} in {} s", mTFCount, mStopwatch.RealTime());
243}
244
248
249void AnomalyStudy::getClusterPatterns(gsl::span<const o2::itsmft::CompClusterExt>& ITSclus, gsl::span<const unsigned char>& ITSpatt, const o2::itsmft::TopologyDictionary& mdict)
250{
251 mPatterns.clear();
252 mPatterns.reserve(ITSclus.size());
253 auto pattIt = ITSpatt.begin();
254
255 for (unsigned int iClus{0}; iClus < ITSclus.size(); ++iClus) {
256 auto& clus = ITSclus[iClus];
257
258 auto pattID = clus.getPatternID();
260
261 if (pattID == o2::itsmft::CompCluster::InvalidPatternID || mdict.isGroup(pattID)) {
262 patt.acquirePattern(pattIt);
263 } else {
264 patt = mdict.getPattern(pattID);
265 }
266
267 mPatterns.push_back(patt);
268 }
269}
270
271// getter
272DataProcessorSpec getAnomalyStudy(mask_t srcClustersMask, bool useMC, bool itsStag)
273{
274 std::vector<OutputSpec> outputs;
275 auto dataRequest = std::make_shared<DataRequest>();
276 dataRequest->setITSPerLayer(itsStag);
277 dataRequest->requestClusters(srcClustersMask, useMC);
278 dataRequest->requestTracks(GTrackID::getSourcesMask(""), useMC);
279
280 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime
281 true, // GRPECS=true
282 false, // GRPLHCIF
283 false, // GRPMagField
284 false, // askMatLUT
286 dataRequest->inputs,
287 true);
288 return DataProcessorSpec{
289 "its-anomaly-study",
290 dataRequest->inputs,
291 outputs,
292 AlgorithmSpec{adaptFromTask<AnomalyStudy>(dataRequest, ggRequest, useMC)},
293 Options{}};
294}
295} // namespace o2::its::study
Wrapper container for different reconstructed object types.
int32_t i
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 process
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 Directory with events to Events directory is and not inside events d
Helper for geometry and GRP related CCDB requests.
Header of the General Run Parameters object.
Definition of the GeometryTGeo class.
uint32_t j
Definition RawData.h:0
Class for time synchronization of RawReader instances.
void checkUpdates(o2::framework::ProcessingContext &pc)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
static mask_t getSourcesMask(const std::string_view srcList)
static GeometryTGeo * Instance()
void fillMatrixCache(int mask) override
void run(ProcessingContext &) final
AnomalyStudy(std::shared_ptr< DataRequest > dr, std::shared_ptr< o2::base::GRPGeomRequest > gr, bool isMC)
void process(o2::globaltracking::RecoContainer &recoData)
void setClusterDictionary(const o2::itsmft::TopologyDictionary *d)
void finaliseCCDB(ConcreteDataMatcher &, void *) final
void endOfStream(EndOfStreamContext &) final
This is invoked whenever we have an EndOfStream event.
void init(InitContext &ic) final
void updateTimeDependentParams(ProcessingContext &pc)
void expandChipInfoHW(int idSW, int &lay, int &sta, int &ssta, int &mod, int &chipInMod) const
convert global SW chip ID to name in HW conventions
void acquirePattern(iterator &pattIt)
static constexpr unsigned short InvalidPatternID
Definition CompCluster.h:46
const ClusterPattern & getPattern(int n) const
Returns the pattern of the topology.
bool isGroup(int n) const
Returns true if the element corresponds to a group of rare topologies.
GLdouble f
Definition glcorearb.h:310
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
constexpr int MaxITSLayers
auto get(const std::byte *buffer, size_t=0)
Definition DataHeader.h:457
void convertCompactClusters(gsl::span< const itsmft::CompClusterExt > clusters, gsl::span< const unsigned char >::iterator &pattIt, std::vector< o2::BaseCluster< float > > &output, const itsmft::TopologyDictionary *dict)
convert compact clusters to 3D spacepoints
Definition IOUtils.cxx:35
o2::framework::DataProcessorSpec getAnomalyStudy(mask_t srcClustersMask, bool useMC, bool itsStag)
auto getITSClustersROFRecords(int layer=0) const
auto getITSClustersPatterns(int layer=0) const
void collectData(o2::framework::ProcessingContext &pc, const DataRequest &request)
auto getITSClusters(int layer=0) const