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