Project
Loading...
Searching...
No Matches
Digitizer.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
16#include "TRandom.h"
17#include <cassert>
18#include <fairlogger/Logger.h>
19#include <bitset>
20
21#include <boost/algorithm/string/case_conv.hpp>
22
23using namespace o2::ctp;
24
26// Trigger detector config needed here.
27std::vector<CTPDigit> Digitizer::process(const gsl::span<o2::ctp::CTPInputDigit> detinputs)
28{
29 if (!mCTPConfiguration) {
31 }
32 std::map<o2::detectors::DetID::ID, std::vector<CTPInput>> det2ctpinp = mCTPConfiguration->getDet2InputMap();
33 // To be taken from config database ?
34 std::map<std::string, uint64_t> detInputName2Mask =
35 {{"MVBA", 1}, {"MVOR", 2}, {"MVNC", 4}, {"MVCH", 8}, {"MVIR", 0x10}, {"MT0A", 1}, {"MT0C", 2}, {"MTSC", 4}, {"MTCE", 8}, {"MTVX", 0x10}, {"0U0A", 1}, {"0U0C", 2}, {"0USC", 4}, {"0UCE", 8}, {"0UVX", 0x10}, {"EMBA", 0x1}, {"0EMC", 0x2}, {"0DMC", 0x4}};
36
37 // pre-sorting detector inputs per interaction record
38 std::map<o2::InteractionRecord, std::vector<const CTPInputDigit*>> predigits;
39 for (auto const& inp : detinputs) {
40 predigits[inp.intRecord].push_back(&inp);
41 }
42
43 std::vector<CTPDigit> digits;
44 for (auto const& hits : predigits) {
45 std::bitset<CTP_NINPUTS> inpmaskcoll = 0;
46 auto currentIR = hits.first;
47 for (auto const inp : hits.second) {
48 switch (inp->detector) {
50 // see dummy database above
51 for (auto const& ctpinp : det2ctpinp[o2::detectors::DetID::FT0]) {
52 uint64_t mask = (inp->inputsMask).to_ullong() & detInputName2Mask[ctpinp.name];
53 if (mask) {
54 inpmaskcoll |= std::bitset<CTP_NINPUTS>(ctpinp.inputMask);
55 }
56 }
57 break;
58 }
60 for (auto const& ctpinp : det2ctpinp[o2::detectors::DetID::FV0]) {
61 uint64_t mask = (inp->inputsMask).to_ullong() & detInputName2Mask[ctpinp.name];
62 if (mask) {
63 inpmaskcoll |= std::bitset<CTP_NINPUTS>(ctpinp.inputMask);
64 }
65 }
66 break;
67 }
69 for (auto const& ctpinp : det2ctpinp[o2::detectors::DetID::FDD]) {
70 uint64_t mask = (inp->inputsMask).to_ullong() & detInputName2Mask[ctpinp.name];
71 if (mask) {
72 inpmaskcoll |= std::bitset<CTP_NINPUTS>(ctpinp.inputMask);
73 }
74 }
75 break;
76 }
78 // uint64_t inpmaskdebug = 1;
79 uint64_t inpmaskdebug = (inp->inputsMask).to_ullong();
80 if (inpmaskdebug & detInputName2Mask["EMBA"]) {
81 // MB-accept must be treated separately, as it is not a CTP input
82 std::bitset<CTP_NINPUTS> emcMBaccept;
83 emcMBaccept.set(CTP_NINPUTS - 1, 1);
84 inpmaskcoll |= emcMBaccept;
85 } // else { // needs to be done always, remove else
86 for (auto const& ctpinp : det2ctpinp[o2::detectors::DetID::EMC]) {
87 uint64_t mask = inpmaskdebug & detInputName2Mask[ctpinp.name];
88 // uint64_t mask = (inp->inputsMask).to_ullong() & detInputName2Mask[ctpinp.name];
89 if (mask) {
90 inpmaskcoll |= std::bitset<CTP_NINPUTS>(ctpinp.inputMask);
91 }
92 }
93 // }
94 // LOG(info) << "EMC input mask:" << inpmaskcoll << " with IR = " << currentIR.bc << ", orbit = " << currentIR.orbit;
95 break;
96 }
98 for (auto const& ctpinp : det2ctpinp[o2::detectors::DetID::PHS]) {
99 uint64_t mask = (inp->inputsMask).to_ullong() & detInputName2Mask[ctpinp.name];
100 if (mask) {
101 inpmaskcoll |= std::bitset<CTP_NINPUTS>(ctpinp.inputMask);
102 }
103 }
104 break;
105 }
107 for (auto const& ctpinp : det2ctpinp[o2::detectors::DetID::ZDC]) {
108 uint64_t mask = (inp->inputsMask).to_ullong() & detInputName2Mask[ctpinp.name];
109 if (mask) {
110 inpmaskcoll |= std::bitset<CTP_NINPUTS>(ctpinp.inputMask);
111 }
112 }
113 break;
114 }
115 default:
116 // Error
117 LOG(error) << "CTP Digitizer: unknown detector:" << inp->detector;
118 break;
119 }
120 // inpmaskcoll.reset(); // debug
121 // inpmaskcoll[47] = 1; // debug
122 } // end loop over trigger input for this interaction
123 if (inpmaskcoll.to_ullong()) {
124 // we put the trigger only when non-trivial
125 std::bitset<64> classmask;
126 calculateClassMask(inpmaskcoll, classmask);
127 if (classmask.to_ulong() == 0) {
128 // No class accepted
129 continue;
130 }
132 data.intRecord = hits.first;
133 data.CTPInputMask = inpmaskcoll;
134 data.CTPClassMask = classmask;
135 digits.emplace_back(data);
136 LOG(info) << "Trigger-Event " << data.intRecord.bc << " " << data.intRecord.orbit << " Input mask:" << inpmaskcoll << " with IR = " << data.intRecord.bc << ", orbit = " << data.intRecord.orbit;
137 // LOG(info) << "Trigger-Event " << data.intRecord.bc << " " << data.intRecord.orbit << " Class mask:" << data.CTPClassMask << " with IR = " << data.intRecord.bc << ", orbit = " << data.intRecord.orbit;
138 }
139 }
140 return std::move(digits);
141}
142void Digitizer::calculateClassMask(const std::bitset<CTP_NINPUTS> ctpinpmask, std::bitset<CTP_NCLASSES>& classmask)
143{
144 classmask = 0;
145 for (auto const& tcl : mCTPConfiguration->getCTPClasses()) {
146 auto clustername = boost::algorithm::to_lower_copy(tcl.cluster->name); // make case-insensitive for string comparison
147 if (clustername == "emc") {
148 // check if Min Bias EMC class
149 bool tvxMBemc = tcl.name.find("C0TVX-B-NOPF-EMC") != std::string::npos; // 2023
150 tvxMBemc |= tcl.name.find("C0TVX-A-NOPF-EMC") != std::string::npos;
151 tvxMBemc |= tcl.name.find("C0TVX-C-NOPF-EMC") != std::string::npos;
152 tvxMBemc |= tcl.name.find("C0TVX-E-NOPF-EMC") != std::string::npos;
153 if (clustername == "emc") {
154 tvxMBemc |= tcl.name.find("minbias_TVX_L0") != std::string::npos; // 2022
155 }
156 if (tvxMBemc || (ctpinpmask.to_ullong() & tcl.descriptor->getInputsMask()) == tcl.descriptor->getInputsMask()) {
157 // require real physics input in any case
158 if (tvxMBemc) {
159 // if the class is a min. bias class accept it only if the MB-accept bit is set in addition
160 // (fake trigger input)
161 if (ctpinpmask[CTP_NINPUTS - 1]) {
162 classmask |= tcl.classMask;
163 LOG(info) << "adding MBA:" << tcl.name;
164 }
165 } // else {
166 // EMCAL rare triggers - physical trigger input
167 // class identification can be handled like in the case of the other
168 // classes as EMCAL trigger input is required
169 classmask |= tcl.classMask;
170 // }
171 }
172 } else {
173 if (tcl.descriptor && ((ctpinpmask.to_ullong() & tcl.descriptor->getInputsMask()) == tcl.descriptor->getInputsMask())) {
174 classmask |= tcl.classMask;
175 }
176 }
177 }
178 LOG(info) << "input mask:" << ctpinpmask;
179 LOG(info) << "class mask:" << classmask;
180}
181
183{
184 mCTPConfiguration = config;
185 LOG(info) << *mCTPConfiguration;
186}
187
189{
190 // CTP Configuration
191 if (mCCDBServer.empty()) {
192 LOG(fatal) << "CTP digitizer: CCDB server is not set";
193 } else {
194 LOG(info) << "CTP digitizer:: CCDB server:" << mCCDBServer;
195 }
197 mgr.setURL(mCCDBServer);
198 map<string, string> metadata = {};
199 long timestamp = 1546300800000;
200
201 auto config = mgr.getSpecific<CTPConfiguration>(o2::ctp::CCDBPathCTPConfig, timestamp, metadata);
202 LOG(info) << " @@@ CTP Digitizer:: CCDB connected " << std::endl;
203 return config;
204}
205
207{
208}
ClassImp(Digitizer)
static BasicCCDBManager & instance()
std::vector< CTPClass > & getCTPClasses()
std::map< o2::detectors::DetID::ID, std::vector< CTPInput > > getDet2InputMap()
o2::ctp::CTPConfiguration * getDefaultCTPConfiguration()
std::vector< CTPDigit > process(const gsl::span< o2::ctp::CTPInputDigit > detinputs)
Definition Digitizer.cxx:27
void setCTPConfiguration(o2::ctp::CTPConfiguration *config)
void calculateClassMask(const std::bitset< CTP_NINPUTS > ctpinpmask, std::bitset< CTP_NCLASSES > &classmask)
static constexpr ID FV0
Definition DetID.h:76
static constexpr ID PHS
Definition DetID.h:67
static constexpr ID ZDC
Definition DetID.h:74
static constexpr ID FT0
Definition DetID.h:75
static constexpr ID EMC
Definition DetID.h:69
static constexpr ID FDD
Definition DetID.h:77
GLboolean * data
Definition glcorearb.h:298
GLint GLuint mask
Definition glcorearb.h:291
const std::string CCDBPathCTPConfig
Database constants.
uint16_t bc
bunch crossing ID of interaction
o2::InteractionRecord intRecord
Definition Digits.h:51
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Digit > digits