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
290 LOGP(info, "Processing RecoContainer");
291 Counters->Fill(1);
292
293 LOGP(info, "Retrieving ZDC data");
294 auto RecBC = recoData.getZDCBCRecData();
295 auto Energy = recoData.getZDCEnergy();
296 auto TDCData = recoData.getZDCTDCData();
297 auto Info2 = recoData.getZDCInfo();
298 LOGP(info, "sizeof ZDC RC: {}, {}, {}, {}", RecBC.size(), Energy.size(), TDCData.size(), Info2.size());
299
300 LOGP(info, "Retrieving ITS clusters");
301 auto rofRecVec = recoData.getITSClustersROFRecords();
302 auto clusArr = recoData.getITSClusters();
303 auto clusPatt = recoData.getITSClustersPatterns();
304 LOGP(info, "sizeof ITS RC: {}, {}, {}", clusArr.size(), clusPatt.size(), rofRecVec.size());
305
306 // TODO: improve this
307 if (rofRecVec.size() == 576 || rofRecVec.size() == 192) {
308 mStrobe = 3564 / (rofRecVec.size() / 32);
309 LOGP(info, "Assuimg TF length = 32 orbits and setting strobe length to {} bc", mStrobe);
310 } else {
311 mStrobe = mStrobeFallBack;
312 LOGP(warning, "Unforeseen number of ROFs in the loop. Using the strobe length fall back value {}", mStrobe);
313 }
314
315 std::map<long, std::set<int>> ZNArtag{}; // ZDCAtag[orbit] = <list of bc...>
316 std::map<long, std::set<int>> ZNCrtag{};
317 std::map<long, std::set<int>> ZNAltag{};
318 std::map<long, std::set<int>> ZNCltag{};
319
320 // ________________________________________________________________
321 // FILLING ZDC ARRAY
323
324 ev.init(RecBC, Energy, TDCData, Info2);
325
326 int bkgcounterAr = 0, bkgcounterCr = 0;
327 int bkgcounterAl = 0, bkgcounterCl = 0;
328 while (ev.next()) {
329
330 int32_t itdcA = o2::zdc::TDCZNAC; // should be == 0
331 int32_t itdcC = o2::zdc::TDCZNCC;
332 long zdcorbit = (long)ev.ir.orbit;
333
334 // ZDC - A side
335 int nhitA = ev.NtdcV(itdcA);
336 for (int32_t ipos = 0; ipos < nhitA; ipos++) {
337
338 double mytdc = o2::zdc::FTDCVal * ev.TDCVal[itdcA][ipos];
339
340 ZNACall->Fill(mytdc);
341
342 if (mytdc >= TimeWindowZNAr.first && mytdc <= TimeWindowZNAr.second) {
343
344 // Backgroud event found here!
345 bkgcounterAr++;
346 Counters->Fill(3);
347 ZDCAtagBC->Fill(ev.ir.bc);
348
349 if (ZNArtag.find(zdcorbit) != ZNArtag.end()) {
350 bool double_count_bkg = ZNArtag[zdcorbit].insert((int)ev.ir.bc).second;
351 if (double_count_bkg) {
352 LOGP(warning, "Multiple ZDCAr counts in the same orbit/bc {}/{}", zdcorbit, ev.ir.bc);
353 }
354 } else {
355 std::set<int> zdcbcs{(int)ev.ir.bc};
356 ZNArtag[zdcorbit] = zdcbcs;
357 }
358
359 } // and of ZNAr time window
360
361 if (mytdc >= TimeWindowZNAl.first && mytdc <= TimeWindowZNAl.second) {
362
363 // Backgroud event found here!
364 bkgcounterAl++;
365 Counters->Fill(3);
366 ZDCAtagBC->Fill(ev.ir.bc);
367
368 if (ZNAltag.find(zdcorbit) != ZNAltag.end()) {
369 bool double_count_bkg = ZNAltag[zdcorbit].insert((int)ev.ir.bc).second;
370 if (double_count_bkg) {
371 LOGP(warning, "Multiple ZDCAl counts in the same orbit/bc {}/{}", zdcorbit, ev.ir.bc);
372 }
373 } else {
374 std::set<int> zdcbcs{(int)ev.ir.bc};
375 ZNAltag[zdcorbit] = zdcbcs;
376 }
377
378 } // and of ZNAl time window
379 }
380
381 // ZDC - C side
382 int nhitC = ev.NtdcV(itdcC);
383 for (int32_t ipos = 0; ipos < nhitC; ipos++) {
384
385 double mytdc = o2::zdc::FTDCVal * ev.TDCVal[itdcC][ipos];
386
387 ZNCCall->Fill(mytdc);
388
389 if (mytdc >= TimeWindowZNCr.first && mytdc <= TimeWindowZNCr.second) {
390
391 // Backgroud event found here!
392 bkgcounterCr++;
393 Counters->Fill(9);
394 ZDCCtagBC->Fill(ev.ir.bc);
395
396 if (ZNCrtag.find(zdcorbit) != ZNCrtag.end()) {
397 bool double_count_bkg = ZNCrtag[zdcorbit].insert((int)ev.ir.bc).second;
398 if (double_count_bkg) {
399 LOGP(warning, "Multiple ZNCr counts in the same orbit/bc {}/{}", zdcorbit, ev.ir.bc);
400 }
401 } else {
402 std::set<int> zdcbcs{(int)ev.ir.bc};
403 ZNCrtag[zdcorbit] = zdcbcs;
404 }
405
406 } // end of ZNCr time window
407
408 if (mytdc >= TimeWindowZNCl.first && mytdc <= TimeWindowZNCl.second) {
409
410 // Backgroud event found here!
411 bkgcounterCl++;
412 Counters->Fill(9);
413 ZDCCtagBC->Fill(ev.ir.bc);
414
415 if (ZNCltag.find(zdcorbit) != ZNCltag.end()) {
416 bool double_count_bkg = ZNCltag[zdcorbit].insert((int)ev.ir.bc).second;
417 if (double_count_bkg) {
418 LOGP(warning, "Multiple ZNCl counts in the same orbit/bc {}/{}", zdcorbit, ev.ir.bc);
419 }
420 } else {
421 std::set<int> zdcbcs{(int)ev.ir.bc};
422 ZNCltag[zdcorbit] = zdcbcs;
423 }
424
425 } // end of ZNCl time window
426 }
427 } // end of while ev.next()
428
429 LOGP(info, "Found background envents from ZNAright/left {}/{} -- from ZNCright/left {}/{}", bkgcounterAr, bkgcounterAl, bkgcounterCr, bkgcounterCl);
430 //__________________________________________________________________
431
432 getClusterPatterns(clusArr, clusPatt, *mDict);
433
434 int inTFROFcounter = -1;
435
436 std::vector<bool> ChipSeenInThisROF(N_CHIP_IB, false); // ChipSeenInThisROF[chipid] = true/false
437 std::vector<bool> ChipSeenInLastROF(N_CHIP_IB, false); // ChipSeenInLastROF[chipid] = true/false
438 std::vector<bool> ChipSeenInLast2ROF(N_CHIP_IB, false); // ChipSeenInLast2ROF[chipid] = true/false
439
440 // Begin loop over ROFs
441 for (auto it = rofRecVec.rbegin(); it != rofRecVec.rend(); ++it) {
442
443 auto& rofRec = *it;
444
445 inTFROFcounter++;
446
447 Counters->Fill(2);
448
449 ChipSeenInLast2ROF = ChipSeenInLastROF;
450 ChipSeenInLastROF = ChipSeenInThisROF;
451 std::fill(ChipSeenInThisROF.begin(), ChipSeenInThisROF.end(), false);
452
453 auto clustersInRof = rofRec.getROFData(clusArr);
454 auto patternsInRof = rofRec.getROFData(mPatterns);
455
456 Tbc = (int)rofRec.getBCData().bc;
457 Torbit = (long)rofRec.getBCData().orbit;
458
459 if (inTFROFcounter < 1) {
460 LOGP(info, "First of TF: ITS orbit/bc {}/{}", Torbit, Tbc);
461 }
462
463 // shifting by 60 bc
464 int eff_bc = Tbc + 60;
465 long eff_orbit = Torbit;
466 if (eff_bc > 3563) {
467 eff_bc -= 3564;
468 eff_orbit += 1;
469 }
470
471 // Making a bitmask with ZDC tags for this bc
472 bool isZNArtagged = searchBCfromMap(ZNArtag, (long)eff_orbit, eff_bc);
473 if (isZNArtagged) {
474 Counters->Fill(4);
475 }
476
477 bool isZNAltagged = searchBCfromMap(ZNAltag, (long)eff_orbit, eff_bc);
478 if (isZNAltagged) {
479 Counters->Fill(4);
480 }
481
482 bool isZNCrtagged = searchBCfromMap(ZNCrtag, (long)eff_orbit, eff_bc);
483 if (isZNCrtagged) {
484 Counters->Fill(10);
485 }
486
487 bool isZNCltagged = searchBCfromMap(ZNCltag, (long)eff_orbit, eff_bc);
488 if (isZNCltagged) {
489 Counters->Fill(10);
490 }
491
492 TZDCtag = 0;
493 TZDCtag |= (isZNArtagged << 0);
494 TZDCtag |= (isZNAltagged << 1);
495 TZDCtag |= (isZNCrtagged << 2);
496 TZDCtag |= (isZNCltagged << 3);
497
498 if (TZDCtag > 0) {
499 LOGP(info, "ZDC tag with mask {}: ZNAright = {} - ZNAleft = {} - ZNCright = {} - ZNCleft = {}",
500 TZDCtag, (TZDCtag >> 0) & 1, (TZDCtag >> 1) & 1, (TZDCtag >> 2) & 1, (TZDCtag >> 3) & 1);
501 }
502
503 // preparing arrays for clusters analysis
504 std::set<int> AvailableChips{};
505 std::map<int, std::vector<int>> MAPsize{}; // MAP[chip] = {list if sizes}
506 std::map<int, std::vector<int>> MAPcols{}; // MAP[chip] = {list of column span}
507 std::map<int, int> MAPntarget{}; // MAP[chip] = number of bad clusters in chip
508 std::map<int, int> MAPcoo_mincol{}; // MAP[chip] = minimum of column coordinate
509 std::map<int, int> MAPcoo_maxcol{}; // MAP[chip] = maximum of (column coordinate + colspan)
510
511 // Finally loop over clusters
512 int ntarget_in_rof = 0;
513 for (int iclus = 0; iclus < clustersInRof.size(); iclus++) {
514
515 const auto& compClus = clustersInRof[iclus];
516
517 auto chipid = compClus.getSensorID();
518
519 // Analyze only IB
520 if (ChipToLayer(chipid) > 2) {
521 continue;
522 }
523
524 ChipSeenInThisROF[chipid] = true;
525
526 int coo_col = (int)compClus.getCol();
527 int coo_row = (int)compClus.getRow();
528
529 auto patti = patternsInRof[iclus];
530 int npix = patti.getNPixels();
531 int colspan = patti.getColumnSpan();
532 int rowspan = patti.getRowSpan();
533
534 bool newchip = AvailableChips.insert(chipid).second;
535 if (newchip) {
536 MAPsize[chipid] = std::vector<int>{};
537 MAPcols[chipid] = std::vector<int>{};
538 MAPntarget[chipid] = 0;
539 MAPcoo_mincol[chipid] = coo_col;
540 MAPcoo_maxcol[chipid] = coo_col + colspan;
541 }
542
543 MAPsize[chipid].push_back(npix);
544 MAPcols[chipid].push_back(colspan);
545 if (colspan >= targetClusterMinCol && rowspan <= targetClusterMaxRow) {
546 // Anomalous cluster found
547 MAPntarget[chipid] += 1;
548 ntarget_in_rof++;
549 }
550 MAPcoo_mincol[chipid] = TMath::Min(MAPcoo_mincol[chipid], coo_col);
551 MAPcoo_maxcol[chipid] = TMath::Max(MAPcoo_maxcol[chipid], coo_col + colspan);
552
553 } // end of loop over clusters in rof
554
555 if (ntarget_in_rof == 0 && mTFn > mSkimmedOnlyAfterTF + 2) { // extra 2 to avoid edge effects?
556 // do not need extra computations for this rof since it will not be saved in any case
557 continue;
558 }
559
560 for (int ic : AvailableChips) {
561
562 Tchip = ic;
563
564 if (inTFROFcounter < 1) {
565 Tmissingafter = -1;
566 } else if (ChipSeenInLastROF[ic]) {
567 Tmissingafter = 0;
568 } else {
569 Tmissingafter = 1;
570 }
571
572 if (inTFROFcounter < 2) {
573 Tmissingafter2 = -1;
574 } else if (ChipSeenInLast2ROF[ic]) {
575 Tmissingafter2 = 0;
576 } else {
577 Tmissingafter2 = 1;
578 }
579
580 Tphi = ChipToPhi(ic);
581
582 Tnclus = MAPsize[ic].size();
583 Tmincol = MAPcoo_mincol[ic];
584 Tmaxcol = MAPcoo_maxcol[ic];
585
586 std::sort(MAPsize[ic].begin(), MAPsize[ic].end(), std::greater<>());
587
588 Tnhit = Tnclus_s20 = Tnclus_s100 = Tnclus_s150 = 0;
589 Tnhit1 = Tnhit10 = 0.;
590 Tnclus_c20 = Tnclus_c100 = Tnclus_c128 = 0;
591 Tnclus_target = MAPntarget[ic];
592 Tnhit_no1pix = 0;
593 Tnclus_no1pix = 0;
594
595 int nhit_no1pix = 0;
596 int nclus10 = 0, nclus1 = 0;
597
598 for (int nh : MAPsize[ic]) {
599
600 Tnhit += nh;
601
602 if (nh > 1) {
603 Tnhit_no1pix += nh;
604 Tnclus_no1pix += 1;
605 }
606
607 if (nclus10 < 10) {
608 nclus10++;
609 Tnhit10 += 1. * nh;
610 }
611
612 if (nclus1 < 1) {
613 nclus1++;
614 Tnhit1 += 1. * nh;
615 }
616
617 Tnclus_s20 += (nh >= 20);
618 Tnclus_s100 += (nh >= 100);
619 Tnclus_s150 += (nh >= 150);
620 }
621
622 Tnhit10 = (nclus10 == 0) ? 0. : 1. * Tnhit10 / nclus10;
623
624 for (int nc : MAPcols[ic]) {
625 Tnclus_c20 += (nc >= 20);
626 Tnclus_c100 += (nc >= 100);
627 Tnclus_c128 += (nc >= 128);
628 }
629
630 ITSChipEvtTree->Fill();
631 if (Tnclus_target > 0) {
632 ITSChipEvtTargetTree->Fill();
633 }
634
635 } // end of loop over available chips
636 } // end of loop over ROFs
637}
638
639// TODO: To be improved using geometry tools
640int ITSBeamBackgroundStudy::ChipToLayer(int chip)
641{
642 if (chip < 108) {
643 return 0;
644 }
645 if (chip < 252) {
646 return 1;
647 }
648 if (chip < 432) {
649 return 2;
650 }
651 if (chip < 3120) {
652 return 3;
653 }
654 if (chip < 6480) {
655 return 4;
656 }
657 if (chip < 14712) {
658 return 5;
659 }
660 return 6;
661}
662
663// TODO: To be improved using geometry tools
664double ITSBeamBackgroundStudy::ChipToPhi(int chip)
665{
666 int staveinlayer = (int)(chip / 9);
667 for (int il = 0; il < ChipToLayer(chip); il++) {
668 staveinlayer -= NStaves[il];
669 }
670 return 2. * TMath::Pi() * (0.5 + staveinlayer) / NStaves[ChipToLayer(chip)];
671}
672
673bool ITSBeamBackgroundStudy::searchBCfromMap(std::map<long, std::set<int>>& BCperorbit, long its_orbit, int its_bc)
674{
675 auto it = BCperorbit.find(its_orbit);
676 if (it == BCperorbit.end()) {
677 return false;
678 }
679
680 for (auto bc : it->second) {
681 if ((bc / mStrobe) == (its_bc / mStrobe)) {
682 return true;
683 }
684 }
685 return false;
686}
687
688void ITSBeamBackgroundStudy::getClusterPatterns(gsl::span<const o2::itsmft::CompClusterExt>& ITSclus, gsl::span<const unsigned char>& ITSpatt, const o2::itsmft::TopologyDictionary& mdict)
689{
690 mPatterns.clear();
691 mPatterns.reserve(ITSclus.size());
692 auto pattIt = ITSpatt.begin();
693
694 for (unsigned int iClus{0}; iClus < ITSclus.size(); ++iClus) {
695 auto& clus = ITSclus[iClus];
696
697 auto pattID = clus.getPatternID();
699
700 if (pattID == o2::itsmft::CompCluster::InvalidPatternID || mdict.isGroup(pattID)) {
701 patt.acquirePattern(pattIt);
702 } else {
703 patt = mdict.getPattern(pattID);
704 }
705
706 mPatterns.push_back(patt);
707 }
708}
709
710// getter
711DataProcessorSpec getITSBeamBackgroundStudy(mask_t srcTracksMask, mask_t srcClustersMask, bool useMC)
712{
713
714 // 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;
715
716 std::vector<OutputSpec> outputs;
717 auto dataRequest = std::make_shared<DataRequest>();
718 dataRequest->requestClusters(srcClustersMask, useMC);
719 // dataRequest->requestTracks(GTrackID::getSourcesMask("ZDC"), useMC);
720
721 dataRequest->requestTracks(srcTracksMask, useMC);
722
723 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime
724 true, // GRPECS=true
725 false, // GRPLHCIF
726 false, // GRPMagField
727 false, // askMatLUT
729 dataRequest->inputs,
730 true);
731 return DataProcessorSpec{
732 "its-beambkg-study",
733 dataRequest->inputs,
734 outputs,
735 AlgorithmSpec{adaptFromTask<ITSBeamBackgroundStudy>(dataRequest, ggRequest, useMC)},
736 Options{}};
737}
738
739} // 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.
GLuint GLuint end
Definition glcorearb.h:469
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)
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
void collectData(o2::framework::ProcessingContext &pc, const DataRequest &request)
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.