Project
Loading...
Searching...
No Matches
ITSBeamBackgroundStudy.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
17
25
26#include <set>
27#include <algorithm>
28#include <limits>
29#include <cmath>
30#include <cstdint>
31
32#include <TTree.h>
33#include <TH2.h>
34
35#include "Framework/Task.h"
36#include "Framework/Logger.h"
37
38// ZDC
40
41using namespace o2::framework;
42using namespace o2::globaltracking;
44
45namespace o2::its::study
46{
48{
49 public:
50 ITSBeamBackgroundStudy(std::shared_ptr<DataRequest> dr,
51 std::shared_ptr<o2::base::GRPGeomRequest> gr,
52 bool isMC) : mDataRequest{dr}, mGGCCDBRequest(gr), mUseMC(isMC) {}
53
54 void init(InitContext& ic) final;
55 void run(ProcessingContext&) final;
57 void finaliseCCDB(ConcreteDataMatcher&, void*) final;
58 void save_and_reset();
59
60 // Custom
63
64 private:
65 void prepareOutput();
66 void getClusterPatterns(gsl::span<const o2::itsmft::CompClusterExt>&, gsl::span<const unsigned char>&, const o2::itsmft::TopologyDictionary&);
67 std::vector<o2::itsmft::ClusterPattern> mPatterns;
68
69 // ITS layout
71 o2::itsmft::ChipMappingITS mChipMapping;
72 o2::its::GeometryTGeo* mGeom = nullptr;
73
74 // Utilities
75 double ChipToPhi(int chip);
76 bool searchBCfromMap(std::map<long, std::set<int>>& BCperorbit, long target_orbit, int target_bc);
77
78 std::shared_ptr<o2::base::GRPGeomRequest> mGGCCDBRequest;
79 std::shared_ptr<DataRequest> mDataRequest;
80 bool mUseMC;
81 const o2::itsmft::TopologyDictionary* mDict = nullptr;
82
83 int mTFn = 0;
84 int mTF_first_after_dump = 1;
85
86 int mStrobeFallBack = 594;
87 int mStrobe = mStrobeFallBack;
88
89 // TODO: the following should be made configurable
90
91 std::pair<double, double> TimeWindowZDC = std::make_pair(5., 11.);
92 std::pair<double, double> TimeWindowZNAr = std::make_pair(5.64507, 9.64507);
93 std::pair<double, double> TimeWindowZNCr = std::make_pair(4.21299, 8.21299);
94 std::pair<double, double> TimeWindowZNAl = std::make_pair(-11.3549, -8.35493);
95 std::pair<double, double> TimeWindowZNCl = std::make_pair(-12.787, -9.78701);
96
97 int targetClusterMinCol = 128; // definition of anomalous cluster
98 int targetClusterMaxRow = 29; // definition of anomalous cluster
99
100 int mDumpEveryTF = ITSBeamBackgroundStudyParamConfig::Instance().dumpEveryTF;
101 int mSkimmedOnlyAfterTF = ITSBeamBackgroundStudyParamConfig::Instance().skimmedOnlyAfterTF;
102 bool mSaveClusterParameters = ITSBeamBackgroundStudyParamConfig::Instance().saveClusterParameters;
103 std::string mOutputChip = "chipevents";
104 std::string mOutoutChipSkim = "chipeventstarget";
105
106 TH1F* TimeWindowCut;
107 TH1F* ZNACall;
108 TH1F* ZNCCall;
109 TH1F* ZDCAtagBC;
110 TH1F* ZDCCtagBC;
111 TH1I* Counters;
112 TTree* ITSChipEvtTree;
113 TTree* ITSChipEvtTargetTree;
114
115 // Tree variables
116 int Tbc;
117 long Torbit;
118 int Tchip;
119 double Tphi;
120 // Cluster vectors share the input cluster order within this chip/ROF.
121 // Positions are global: phi in radians [-pi, pi], r and z in cm.
122 std::vector<float> TclusterPhi, TclusterR, TclusterZ;
123 std::vector<int> TclusterSize, TclusterColSpan, TclusterRowSpan;
124 int TZDCtag;
125 int Tnhit, Tnclus, Tnhit_no1pix, Tnclus_no1pix;
126 int Tnclus_s20, Tnclus_s100, Tnclus_s150;
127 int Tnclus_c20, Tnclus_c100, Tnclus_c128;
128 int Tnclus_target;
129 double Tnhit1, Tnhit10;
130 int Tmissingafter, Tmissingafter2;
131 int Tmincol, Tmaxcol;
132};
133
135{
137 if (mSaveClusterParameters) {
139 mGeom->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::L2G));
140 }
141}
142
144{
145 LOGP(info, "Initializing ITSBeamBackgroundStudy");
147 LOGP(info, "Fetching ClusterDictionary");
149 mgr.setURL("http://alice-ccdb.cern.ch");
150 mgr.setTimestamp(o2::ccdb::getCurrentTimestamp());
151 mDict = mgr.get<o2::itsmft::TopologyDictionary>("ITS/Calib/ClusterDictionary");
152
153 prepareOutput();
154}
155
156void ITSBeamBackgroundStudy::prepareOutput()
157{
158 LOGP(info, "Setting up trees and histograms. They will be dumped on file every {} TFs", mDumpEveryTF);
159 LOGP(info, "Skimmed-only output after TF {}; saving cluster parameters: {}", mSkimmedOnlyAfterTF, mSaveClusterParameters);
160
161 TimeWindowCut = new TH1F("ZDC bkg region", "ZNAr, ZNCr, -ZNAl, -ZNCl", 8, 0, 8);
162 TimeWindowCut->SetBinContent(1, TimeWindowZNAr.first);
163 TimeWindowCut->SetBinContent(2, TimeWindowZNAr.second);
164 TimeWindowCut->SetBinContent(3, TimeWindowZNCr.first);
165 TimeWindowCut->SetBinContent(4, TimeWindowZNCr.second);
166 TimeWindowCut->SetBinContent(5, -TimeWindowZNAl.first);
167 TimeWindowCut->SetBinContent(6, -TimeWindowZNAl.second);
168 TimeWindowCut->SetBinContent(7, -TimeWindowZNCl.first);
169 TimeWindowCut->SetBinContent(8, -TimeWindowZNCl.second);
170 ZNACall = new TH1F("ZNACall", "ZNACall", 40, -20, 20);
171 ZNCCall = new TH1F("ZNCCall", "ZNCCall", 40, -20, 20);
172 ZDCAtagBC = new TH1F("ZDCA tagged BC", "ZDCA tagged bc", 3564, 0, 3564);
173 ZDCCtagBC = new TH1F("ZDCC tagged BC", "ZDCC tagged bc", 3564, 0, 3564);
174
175 Counters = new TH1I("Counters", "Counters", 20, 1, 21);
176 Counters->GetXaxis()->SetBinLabel(1, "TF");
177 Counters->GetXaxis()->SetBinLabel(2, "ROF");
178 Counters->GetXaxis()->SetBinLabel(3, "ZDCA evt");
179 Counters->GetXaxis()->SetBinLabel(4, "ROF-ZDCA tagged");
180 Counters->GetXaxis()->SetBinLabel(5, "ITStag any");
181 Counters->GetXaxis()->SetBinLabel(6, "ITStag TO");
182 Counters->GetXaxis()->SetBinLabel(7, "ITStag any + ZDC");
183 Counters->GetXaxis()->SetBinLabel(8, "ITStag TO + ZDC");
184 Counters->GetXaxis()->SetBinLabel(9, "ZDCC evt");
185 Counters->GetXaxis()->SetBinLabel(10, "ROF-ZDCC tagged");
186
187 ITSChipEvtTree = new TTree("chipevt", "chipevt");
188
189 // Chip event branches
190 ITSChipEvtTree->Branch("TFprogress", &mTFn, "TFprogress/I");
191 ITSChipEvtTree->Branch("orbit", &Torbit, "orbit/L");
192 ITSChipEvtTree->Branch("bc", &Tbc, "bc/I");
193 ITSChipEvtTree->Branch("chip", &Tchip, "chip/I");
194 ITSChipEvtTree->Branch("phi", &Tphi, "phi/D");
195 if (mSaveClusterParameters) {
196 ITSChipEvtTree->Branch("cluster_phi", &TclusterPhi);
197 ITSChipEvtTree->Branch("cluster_r", &TclusterR);
198 ITSChipEvtTree->Branch("cluster_z", &TclusterZ);
199 ITSChipEvtTree->Branch("cluster_size", &TclusterSize);
200 ITSChipEvtTree->Branch("cluster_colspan", &TclusterColSpan);
201 ITSChipEvtTree->Branch("cluster_rowspan", &TclusterRowSpan);
202 }
203 ITSChipEvtTree->Branch("zdctag", &TZDCtag, "zdctag/I");
204 ITSChipEvtTree->Branch("nhit", &Tnhit, "nhit/I");
205 ITSChipEvtTree->Branch("nhit_no1pix", &Tnhit_no1pix, "nhit_no1pix/I");
206 ITSChipEvtTree->Branch("size1", &Tnhit1, "size1/D");
207 ITSChipEvtTree->Branch("size10", &Tnhit10, "size10/D");
208 ITSChipEvtTree->Branch("nclus", &Tnclus, "nclus/I");
209 ITSChipEvtTree->Branch("nclus_no1pix", &Tnclus_no1pix, "nclus_no1pix/I");
210 ITSChipEvtTree->Branch("nclus_target", &Tnclus_target, "nclus_target/I");
211 ITSChipEvtTree->Branch("missingafter", &Tmissingafter, "missingafter/I");
212 ITSChipEvtTree->Branch("missingafter2", &Tmissingafter2, "missingafter2/I");
213 ITSChipEvtTree->Branch("mincol", &Tmincol, "mincol/I");
214 ITSChipEvtTree->Branch("maxcol", &Tmaxcol, "maxcol/I");
215
216 ITSChipEvtTargetTree = ITSChipEvtTree->CloneTree(0);
217 ITSChipEvtTargetTree->SetName("chipevttarget");
218 ITSChipEvtTargetTree->SetTitle("chipevttarget");
219}
220
222{
223
224 std::string outfile11 = mOutoutChipSkim + "_" + std::to_string(mTF_first_after_dump) + "_" + std::to_string(mTFn) + ".root";
225 LOGP(info, "Writing ROOT file {}", outfile11);
226 TFile* F11 = TFile::Open(outfile11.c_str(), "recreate");
227 TimeWindowCut->Write();
228 ZNACall->Write();
229 ZNCCall->Write();
230 ZDCAtagBC->Write();
231 ZDCCtagBC->Write();
232 Counters->Write();
233 ITSChipEvtTargetTree->Write();
234 F11->Close();
235 delete F11;
236
237 if (mTFn <= mSkimmedOnlyAfterTF) {
238 std::string outfile1 = mOutputChip + "_" + std::to_string(mTF_first_after_dump) + "_" + std::to_string(mTFn) + ".root";
239 LOGP(info, "Writing ROOT file {}", outfile1);
240 TFile* F1 = TFile::Open(outfile1.c_str(), "recreate");
241 TimeWindowCut->Write();
242 ZNACall->Write();
243 ZNCCall->Write();
244 ZDCAtagBC->Write();
245 ZDCCtagBC->Write();
246 Counters->Write();
247 ITSChipEvtTree->Write(); // chip events and the skimmed one
248 ITSChipEvtTargetTree->Write();
249 F1->Close();
250 delete F1;
251 }
252
253 LOGP(info, "Resetting historgrams and trees");
254 // Delete clears data but keep the branch setup intact
255 ITSChipEvtTree->Reset(); // Delete("");
256 ITSChipEvtTargetTree->Reset(); // Delete("");
257 ZNACall->Reset();
258 ZNCCall->Reset();
259 ZDCAtagBC->Reset();
260 ZDCCtagBC->Reset();
261 Counters->Reset();
262
263 mTF_first_after_dump = mTFn + 1;
264}
265
267{
268 LOGP(info, "End of stream for ITSBeamBackgroundStudy");
269
271
272 delete TimeWindowCut;
273 delete ZNACall;
274 delete ZNCCall;
275 delete ZDCAtagBC;
276 delete ZDCCtagBC;
277 delete Counters;
278 delete ITSChipEvtTree;
279 delete ITSChipEvtTargetTree;
280}
281
283{
284
285 if (mTFn == std::numeric_limits<int>::max()) {
286 LOGP(error, "Max {} TFs exceeded. Skipping all next events", mTFn);
287 return;
288 }
289
290 mTFn++;
291
292 if (mDumpEveryTF > 0 && mTFn > 0 && (mTFn % mDumpEveryTF) == 0) {
293 LOGP(info, "Reached TF #{}. Exporting new root files", mTFn);
295 }
296
298 recoData.collectData(pc, *mDataRequest.get());
300 LOGP(info, "Calling process() for TF: {}", mTFn);
301 process(recoData);
302}
303
308
309// Custom area
311{
312 if (recoData.getITSPerLayer()) {
313 // The study chains consecutive ROFs (ChipSeenInLastROF/ChipSeenInLast2ROF) into a single time
314 // series over the 3 inner barrel layers and derives the strobe length from the number of ROFs.
315 // With the staggered readout each layer has its own ROF length and numbering, so it has to be
316 // decided whether the 3 layers are followed as independent series (and how the ROF counters and
317 // the background tagging are then normalized).
318 LOGP(fatal, "ITSBeamBackgroundStudy does not support the per-layer (staggered) ITS clusters input yet");
319 }
320
321 LOGP(info, "Processing RecoContainer");
322 Counters->Fill(1);
323
324 LOGP(info, "Retrieving ZDC data");
325 auto RecBC = recoData.getZDCBCRecData();
326 auto Energy = recoData.getZDCEnergy();
327 auto TDCData = recoData.getZDCTDCData();
328 auto Info2 = recoData.getZDCInfo();
329 LOGP(info, "sizeof ZDC RC: {}, {}, {}, {}", RecBC.size(), Energy.size(), TDCData.size(), Info2.size());
330
331 LOGP(info, "Retrieving ITS clusters");
332 auto rofRecVec = recoData.getITSClustersROFRecords();
333 auto clusArr = recoData.getITSClusters();
334 auto clusPatt = recoData.getITSClustersPatterns();
335 LOGP(info, "sizeof ITS RC: {}, {}, {}", clusArr.size(), clusPatt.size(), rofRecVec.size());
336
337 // TODO: improve this
338 if (rofRecVec.size() == 576 || rofRecVec.size() == 192) {
339 mStrobe = 3564 / (rofRecVec.size() / 32);
340 LOGP(info, "Assuimg TF length = 32 orbits and setting strobe length to {} bc", mStrobe);
341 } else {
342 mStrobe = mStrobeFallBack;
343 LOGP(warning, "Unforeseen number of ROFs in the loop. Using the strobe length fall back value {}", mStrobe);
344 }
345
346 std::map<long, std::set<int>> ZNArtag{}; // ZDCAtag[orbit] = <list of bc...>
347 std::map<long, std::set<int>> ZNCrtag{};
348 std::map<long, std::set<int>> ZNAltag{};
349 std::map<long, std::set<int>> ZNCltag{};
350
351 // ________________________________________________________________
352 // FILLING ZDC ARRAY
354
355 ev.init(RecBC, Energy, TDCData, Info2);
356
357 int bkgcounterAr = 0, bkgcounterCr = 0;
358 int bkgcounterAl = 0, bkgcounterCl = 0;
359 while (ev.next()) {
360
361 int32_t itdcA = o2::zdc::TDCZNAC; // should be == 0
362 int32_t itdcC = o2::zdc::TDCZNCC;
363 long zdcorbit = (long)ev.ir.orbit;
364
365 // ZDC - A side
366 int nhitA = ev.NtdcV(itdcA);
367 for (int32_t ipos = 0; ipos < nhitA; ipos++) {
368
369 double mytdc = o2::zdc::FTDCVal * ev.TDCVal[itdcA][ipos];
370
371 ZNACall->Fill(mytdc);
372
373 if (mytdc >= TimeWindowZNAr.first && mytdc <= TimeWindowZNAr.second) {
374
375 // Backgroud event found here!
376 bkgcounterAr++;
377 Counters->Fill(3);
378 ZDCAtagBC->Fill(ev.ir.bc);
379
380 if (ZNArtag.find(zdcorbit) != ZNArtag.end()) {
381 bool double_count_bkg = ZNArtag[zdcorbit].insert((int)ev.ir.bc).second;
382 if (double_count_bkg) {
383 LOGP(warning, "Multiple ZDCAr counts in the same orbit/bc {}/{}", zdcorbit, ev.ir.bc);
384 }
385 } else {
386 std::set<int> zdcbcs{(int)ev.ir.bc};
387 ZNArtag[zdcorbit] = zdcbcs;
388 }
389
390 } // and of ZNAr time window
391
392 if (mytdc >= TimeWindowZNAl.first && mytdc <= TimeWindowZNAl.second) {
393
394 // Backgroud event found here!
395 bkgcounterAl++;
396 Counters->Fill(3);
397 ZDCAtagBC->Fill(ev.ir.bc);
398
399 if (ZNAltag.find(zdcorbit) != ZNAltag.end()) {
400 bool double_count_bkg = ZNAltag[zdcorbit].insert((int)ev.ir.bc).second;
401 if (double_count_bkg) {
402 LOGP(warning, "Multiple ZDCAl counts in the same orbit/bc {}/{}", zdcorbit, ev.ir.bc);
403 }
404 } else {
405 std::set<int> zdcbcs{(int)ev.ir.bc};
406 ZNAltag[zdcorbit] = zdcbcs;
407 }
408
409 } // and of ZNAl time window
410 }
411
412 // ZDC - C side
413 int nhitC = ev.NtdcV(itdcC);
414 for (int32_t ipos = 0; ipos < nhitC; ipos++) {
415
416 double mytdc = o2::zdc::FTDCVal * ev.TDCVal[itdcC][ipos];
417
418 ZNCCall->Fill(mytdc);
419
420 if (mytdc >= TimeWindowZNCr.first && mytdc <= TimeWindowZNCr.second) {
421
422 // Backgroud event found here!
423 bkgcounterCr++;
424 Counters->Fill(9);
425 ZDCCtagBC->Fill(ev.ir.bc);
426
427 if (ZNCrtag.find(zdcorbit) != ZNCrtag.end()) {
428 bool double_count_bkg = ZNCrtag[zdcorbit].insert((int)ev.ir.bc).second;
429 if (double_count_bkg) {
430 LOGP(warning, "Multiple ZNCr counts in the same orbit/bc {}/{}", zdcorbit, ev.ir.bc);
431 }
432 } else {
433 std::set<int> zdcbcs{(int)ev.ir.bc};
434 ZNCrtag[zdcorbit] = zdcbcs;
435 }
436
437 } // end of ZNCr time window
438
439 if (mytdc >= TimeWindowZNCl.first && mytdc <= TimeWindowZNCl.second) {
440
441 // Backgroud event found here!
442 bkgcounterCl++;
443 Counters->Fill(9);
444 ZDCCtagBC->Fill(ev.ir.bc);
445
446 if (ZNCltag.find(zdcorbit) != ZNCltag.end()) {
447 bool double_count_bkg = ZNCltag[zdcorbit].insert((int)ev.ir.bc).second;
448 if (double_count_bkg) {
449 LOGP(warning, "Multiple ZNCl counts in the same orbit/bc {}/{}", zdcorbit, ev.ir.bc);
450 }
451 } else {
452 std::set<int> zdcbcs{(int)ev.ir.bc};
453 ZNCltag[zdcorbit] = zdcbcs;
454 }
455
456 } // end of ZNCl time window
457 }
458 } // end of while ev.next()
459
460 LOGP(info, "Found background envents from ZNAright/left {}/{} -- from ZNCright/left {}/{}", bkgcounterAr, bkgcounterAl, bkgcounterCr, bkgcounterCl);
461 //__________________________________________________________________
462
463 getClusterPatterns(clusArr, clusPatt, *mDict);
464
465 int inTFROFcounter = -1;
466
467 std::vector<bool> ChipSeenInThisROF(N_CHIP_IB, false); // ChipSeenInThisROF[chipid] = true/false
468 std::vector<bool> ChipSeenInLastROF(N_CHIP_IB, false); // ChipSeenInLastROF[chipid] = true/false
469 std::vector<bool> ChipSeenInLast2ROF(N_CHIP_IB, false); // ChipSeenInLast2ROF[chipid] = true/false
470
471 // Begin loop over ROFs
472 for (auto it = rofRecVec.rbegin(); it != rofRecVec.rend(); ++it) {
473
474 auto& rofRec = *it;
475
476 inTFROFcounter++;
477
478 Counters->Fill(2);
479
480 ChipSeenInLast2ROF = ChipSeenInLastROF;
481 ChipSeenInLastROF = ChipSeenInThisROF;
482 std::fill(ChipSeenInThisROF.begin(), ChipSeenInThisROF.end(), false);
483
484 auto clustersInRof = rofRec.getROFData(clusArr);
485 auto patternsInRof = rofRec.getROFData(mPatterns);
486
487 Tbc = (int)rofRec.getBCData().bc;
488 Torbit = (long)rofRec.getBCData().orbit;
489
490 if (inTFROFcounter < 1) {
491 LOGP(info, "First of TF: ITS orbit/bc {}/{}", Torbit, Tbc);
492 }
493
494 // shifting by 60 bc
495 int eff_bc = Tbc + 60;
496 long eff_orbit = Torbit;
497 if (eff_bc > 3563) {
498 eff_bc -= 3564;
499 eff_orbit += 1;
500 }
501
502 // Making a bitmask with ZDC tags for this bc
503 bool isZNArtagged = searchBCfromMap(ZNArtag, (long)eff_orbit, eff_bc);
504 if (isZNArtagged) {
505 Counters->Fill(4);
506 }
507
508 bool isZNAltagged = searchBCfromMap(ZNAltag, (long)eff_orbit, eff_bc);
509 if (isZNAltagged) {
510 Counters->Fill(4);
511 }
512
513 bool isZNCrtagged = searchBCfromMap(ZNCrtag, (long)eff_orbit, eff_bc);
514 if (isZNCrtagged) {
515 Counters->Fill(10);
516 }
517
518 bool isZNCltagged = searchBCfromMap(ZNCltag, (long)eff_orbit, eff_bc);
519 if (isZNCltagged) {
520 Counters->Fill(10);
521 }
522
523 TZDCtag = 0;
524 TZDCtag |= (isZNArtagged << 0);
525 TZDCtag |= (isZNAltagged << 1);
526 TZDCtag |= (isZNCrtagged << 2);
527 TZDCtag |= (isZNCltagged << 3);
528
529 if (TZDCtag > 0) {
530 LOGP(info, "ZDC tag with mask {}: ZNAright = {} - ZNAleft = {} - ZNCright = {} - ZNCleft = {}",
531 TZDCtag, (TZDCtag >> 0) & 1, (TZDCtag >> 1) & 1, (TZDCtag >> 2) & 1, (TZDCtag >> 3) & 1);
532 }
533
534 // preparing arrays for clusters analysis
535 std::set<int> AvailableChips{};
536 std::map<int, std::vector<int>> MAPsize{}; // MAP[chip] = {list if sizes}
537 std::map<int, std::vector<int>> MAPcols{}; // MAP[chip] = {list of column span}
538 std::map<int, std::vector<int>> MAProws{}; // MAP[chip] = {list of row span}
539 std::map<int, std::vector<o2::math_utils::Point3D<float>>> MAPcoordinates{};
540 std::map<int, int> MAPntarget{}; // MAP[chip] = number of bad clusters in chip
541 std::map<int, int> MAPcoo_mincol{}; // MAP[chip] = minimum of column coordinate
542 std::map<int, int> MAPcoo_maxcol{}; // MAP[chip] = maximum of (column coordinate + colspan)
543
544 // Finally loop over clusters
545 int ntarget_in_rof = 0;
546 for (int iclus = 0; iclus < clustersInRof.size(); iclus++) {
547
548 const auto& compClus = clustersInRof[iclus];
549
550 auto chipid = compClus.getSensorID();
551
552 // Analyze only IB
553 if (o2::itsmft::ChipMappingITS::getLayer(chipid) > 2) {
554 continue;
555 }
556
557 ChipSeenInThisROF[chipid] = true;
558
559 int coo_col = (int)compClus.getCol();
560 int coo_row = (int)compClus.getRow();
561
562 const auto& patti = patternsInRof[iclus];
563 int npix = patti.getNPixels();
564 int colspan = patti.getColumnSpan();
565 int rowspan = patti.getRowSpan();
566
567 bool newchip = AvailableChips.insert(chipid).second;
568 if (newchip) {
569 MAPsize[chipid] = std::vector<int>{};
570 MAPcols[chipid] = std::vector<int>{};
571 MAPntarget[chipid] = 0;
572 MAPcoo_mincol[chipid] = coo_col;
573 MAPcoo_maxcol[chipid] = coo_col + colspan;
574 }
575
576 MAPsize[chipid].push_back(npix);
577 MAPcols[chipid].push_back(colspan);
578 if (mSaveClusterParameters) {
579 MAProws[chipid].push_back(rowspan);
580 // Grouped topologies store a rounded COG in the compact cluster; invalid
581 // pattern IDs store the bounding-box corner instead.
582 const auto pattID = compClus.getPatternID();
583 auto local = pattID == o2::itsmft::CompCluster::InvalidPatternID
584 ? mDict->getClusterCoordinates<float>(compClus, patti, false)
585 : (mDict->isGroup(pattID) ? mDict->getClusterCoordinates<float>(compClus, patti)
586 : mDict->getClusterCoordinates<float>(compClus));
587 MAPcoordinates[chipid].push_back(mGeom->getMatrixL2G(chipid)(local));
588 }
589 if (colspan >= targetClusterMinCol && rowspan <= targetClusterMaxRow) {
590 // Anomalous cluster found
591 MAPntarget[chipid] += 1;
592 ntarget_in_rof++;
593 }
594 MAPcoo_mincol[chipid] = TMath::Min(MAPcoo_mincol[chipid], coo_col);
595 MAPcoo_maxcol[chipid] = TMath::Max(MAPcoo_maxcol[chipid], coo_col + colspan);
596
597 } // end of loop over clusters in rof
598
599 if (ntarget_in_rof == 0 && static_cast<int64_t>(mTFn) > static_cast<int64_t>(mSkimmedOnlyAfterTF) + 2) { // extra 2 to avoid edge effects?
600 // do not need extra computations for this rof since it will not be saved in any case
601 continue;
602 }
603
604 for (int ic : AvailableChips) {
605
606 Tchip = ic;
607
608 if (inTFROFcounter < 1) {
609 Tmissingafter = -1;
610 } else if (ChipSeenInLastROF[ic]) {
611 Tmissingafter = 0;
612 } else {
613 Tmissingafter = 1;
614 }
615
616 if (inTFROFcounter < 2) {
617 Tmissingafter2 = -1;
618 } else if (ChipSeenInLast2ROF[ic]) {
619 Tmissingafter2 = 0;
620 } else {
621 Tmissingafter2 = 1;
622 }
623
624 Tphi = ChipToPhi(ic);
625
626 Tnclus = MAPsize[ic].size();
627 if (mSaveClusterParameters) {
628 TclusterSize = MAPsize[ic]; // Save before sorting the sizes for the summaries.
629 TclusterColSpan = MAPcols[ic];
630 TclusterRowSpan = MAProws[ic];
631 TclusterPhi.clear();
632 TclusterR.clear();
633 TclusterZ.clear();
634 for (const auto& global : MAPcoordinates[ic]) {
635 TclusterPhi.push_back(std::atan2(global.Y(), global.X()));
636 TclusterR.push_back(std::hypot(global.X(), global.Y()));
637 TclusterZ.push_back(global.Z());
638 }
639 }
640 Tmincol = MAPcoo_mincol[ic];
641 Tmaxcol = MAPcoo_maxcol[ic];
642
643 std::sort(MAPsize[ic].begin(), MAPsize[ic].end(), std::greater<>());
644
645 Tnhit = Tnclus_s20 = Tnclus_s100 = Tnclus_s150 = 0;
646 Tnhit1 = Tnhit10 = 0.;
647 Tnclus_c20 = Tnclus_c100 = Tnclus_c128 = 0;
648 Tnclus_target = MAPntarget[ic];
649 Tnhit_no1pix = 0;
650 Tnclus_no1pix = 0;
651
652 int nhit_no1pix = 0;
653 int nclus10 = 0, nclus1 = 0;
654
655 for (int nh : MAPsize[ic]) {
656
657 Tnhit += nh;
658
659 if (nh > 1) {
660 Tnhit_no1pix += nh;
661 Tnclus_no1pix += 1;
662 }
663
664 if (nclus10 < 10) {
665 nclus10++;
666 Tnhit10 += 1. * nh;
667 }
668
669 if (nclus1 < 1) {
670 nclus1++;
671 Tnhit1 += 1. * nh;
672 }
673
674 Tnclus_s20 += (nh >= 20);
675 Tnclus_s100 += (nh >= 100);
676 Tnclus_s150 += (nh >= 150);
677 }
678
679 Tnhit10 = (nclus10 == 0) ? 0. : 1. * Tnhit10 / nclus10;
680
681 for (int nc : MAPcols[ic]) {
682 Tnclus_c20 += (nc >= 20);
683 Tnclus_c100 += (nc >= 100);
684 Tnclus_c128 += (nc >= 128);
685 }
686
687 ITSChipEvtTree->Fill();
688 if (Tnclus_target > 0) {
689 ITSChipEvtTargetTree->Fill();
690 }
691
692 } // end of loop over available chips
693 } // end of loop over ROFs
694}
695
696double ITSBeamBackgroundStudy::ChipToPhi(int chip)
697{
698 int layer, stave, substave, module, chipInModule;
699 mChipMapping.expandChipInfoSW(chip, layer, stave, substave, module, chipInModule);
700 const int staveInLayer = stave - o2::itsmft::ChipMappingITS::getFirstStavesOnLr(layer);
701 return 2. * TMath::Pi() * (0.5 + staveInLayer) / o2::itsmft::ChipMappingITS::getNStavesOnLr(layer);
702}
703
704bool ITSBeamBackgroundStudy::searchBCfromMap(std::map<long, std::set<int>>& BCperorbit, long its_orbit, int its_bc)
705{
706 auto it = BCperorbit.find(its_orbit);
707 if (it == BCperorbit.end()) {
708 return false;
709 }
710
711 for (auto bc : it->second) {
712 if ((bc / mStrobe) == (its_bc / mStrobe)) {
713 return true;
714 }
715 }
716 return false;
717}
718
719void ITSBeamBackgroundStudy::getClusterPatterns(gsl::span<const o2::itsmft::CompClusterExt>& ITSclus, gsl::span<const unsigned char>& ITSpatt, const o2::itsmft::TopologyDictionary& mdict)
720{
721 mPatterns.clear();
722 mPatterns.reserve(ITSclus.size());
723 auto pattIt = ITSpatt.begin();
724
725 for (unsigned int iClus{0}; iClus < ITSclus.size(); ++iClus) {
726 auto& clus = ITSclus[iClus];
727
728 auto pattID = clus.getPatternID();
730
731 if (pattID == o2::itsmft::CompCluster::InvalidPatternID || mdict.isGroup(pattID)) {
732 patt.acquirePattern(pattIt);
733 } else {
734 patt = mdict.getPattern(pattID);
735 }
736
737 mPatterns.push_back(patt);
738 }
739}
740
741// getter
742DataProcessorSpec getITSBeamBackgroundStudy(mask_t srcTracksMask, mask_t srcClustersMask, bool useMC, bool itsStag)
743{
744
745 // std::cout<<"DEBBUG track and clus masks "<<srcTracksMask<<" "<<srcClustersMask<<" is ZDC in tracks: "<<(srcTracksMask & GTrackID::getSourcesMask("ZDC"))<<" is ITS in clus: "<<(srcClustersMask & GTrackID::getSourcesMask("ITS"))<<std::endl;
746
747 std::vector<OutputSpec> outputs;
748 auto dataRequest = std::make_shared<DataRequest>();
749 dataRequest->setITSPerLayer(itsStag);
750 dataRequest->requestClusters(srcClustersMask, useMC);
751 // dataRequest->requestTracks(GTrackID::getSourcesMask("ZDC"), useMC);
752
753 dataRequest->requestTracks(srcTracksMask, useMC);
754
758 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime
759 true, // GRPECS=true
760 false, // GRPLHCIF
761 false, // GRPMagField
762 false, // askMatLUT
763 geometry,
764 dataRequest->inputs,
765 true);
766 return DataProcessorSpec{
767 "its-beambkg-study-task",
768 dataRequest->inputs,
769 outputs,
770 AlgorithmSpec{adaptFromTask<ITSBeamBackgroundStudy>(dataRequest, ggRequest, useMC)},
771 Options{}};
772}
773
774} // namespace o2::its::study
Definition of the ITSMFT compact cluster.
Wrapper container for different reconstructed object types.
Definition of the ClusterTopology class.
uint64_t bc
Definition RawEventData.h:5
Helper for geometry and GRP related CCDB requests.
Header of the General Run Parameters object.
char error[CURL_ERROR_SIZE]
Definition of the GeometryTGeo class.
Definition of the ITSMFT ROFrame (trigger) record.
Class to decode the reconstructed ZDC event (single BC with signal in one of detectors)
void checkUpdates(o2::framework::ProcessingContext &pc)
bool finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
static BasicCCDBManager & instance()
const Mat3D & getMatrixL2G(int sensID) const
static GeometryTGeo * Instance()
void fillMatrixCache(int mask) override
void endOfStream(EndOfStreamContext &) final
This is invoked whenever we have an EndOfStream event.
void process(o2::globaltracking::RecoContainer &recoData)
void finaliseCCDB(ConcreteDataMatcher &, void *) final
ITSBeamBackgroundStudy(std::shared_ptr< DataRequest > dr, std::shared_ptr< o2::base::GRPGeomRequest > gr, bool isMC)
void updateTimeDependentParams(ProcessingContext &pc)
void expandChipInfoSW(int idSW, int &lay, int &sta, int &ssta, int &mod, int &chipInMod) const
expand SW chip ID to HW id's for layer, stave, substave, module, chipOnModule
static constexpr int IB
static constexpr int getNChips()
number of chips per barrel
static constexpr int getFirstStavesOnLr(int l)
numbes of chips per layer
static constexpr int getLayer(int chipSW)
static constexpr int getNStavesOnLr(int l)
first staves of layer
void acquirePattern(iterator &pattIt)
static constexpr unsigned short InvalidPatternID
Definition CompCluster.h:46
math_utils::Point3D< T > getClusterCoordinates(const CompCluster &cl) const
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.
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
long getCurrentTimestamp()
returns the timestamp in long corresponding to "now"
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
o2::framework::DataProcessorSpec getITSBeamBackgroundStudy(mask_t srcTracksMask, mask_t srcClustersMask, bool useMC, bool itsStag)
const int end
constexpr float FTDCVal
Definition Constants.h:103
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
uint32_t orbit
LHC orbit.
uint16_t bc
bunch crossing ID of interaction
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
int NtdcV(uint8_t ich) const
std::vector< float > TDCVal[NTDCChannels]
signal in ZDCs
o2::InteractionRecord ir
void init(const std::vector< o2::zdc::BCRecData > *RecBC, const std::vector< o2::zdc::ZDCEnergy > *Energy, const std::vector< o2::zdc::ZDCTDCData > *TDCData, const std::vector< uint16_t > *Info)
Trigger mask for printout.