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) {
49 case o2::detectors::DetID::FT0: {
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 }
59 case o2::detectors::DetID::FV0: {
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 }
68 case o2::detectors::DetID::FDD: {
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 }
77 case o2::detectors::DetID::EMC: {
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 }
97 case o2::detectors::DetID::PHS: {
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 }
106 case o2::detectors::DetID::ZDC: {
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 // require real physics input in any case
157 if (tvxMBemc) {
158 // if the class is a min. bias class accept it only if the MB-accept bit is set in addition
159 // (fake trigger input)
160 if (ctpinpmask[CTP_NINPUTS - 1]) {
161 classmask |= tcl.classMask;
162 LOG(info) << "adding MBA:" << tcl.name;
163 }
164 } else if ((ctpinpmask.to_ullong() & tcl.descriptor->getInputsMask()) == tcl.descriptor->getInputsMask()) {
165 // EMCAL rare triggers - physical trigger input
166 // class identification can be handled like in the case of the other
167 // classes as EMCAL trigger input is required
168 LOG(info) << "adding EMCal rare trigger:" << tcl.name;
169 classmask |= tcl.classMask;
170 }
171 } else {
172 if (tcl.descriptor && ((ctpinpmask.to_ullong() & tcl.descriptor->getInputsMask()) == tcl.descriptor->getInputsMask())) {
173 classmask |= tcl.classMask;
174 }
175 }
176 }
177 LOG(info) << "input mask:" << ctpinpmask;
178 LOG(info) << "class mask:" << classmask;
179}
180
182{
183 mCTPConfiguration = config;
184 LOG(info) << *mCTPConfiguration;
185}
186
188{
189 // CTP Configuration
190 if (mCCDBServer.empty()) {
191 LOG(fatal) << "CTP digitizer: CCDB server is not set";
192 } else {
193 LOG(info) << "CTP digitizer:: CCDB server:" << mCCDBServer;
194 }
196 mgr.setURL(mCCDBServer);
197 std::map<std::string, std::string> metadata = {};
198 long timestamp = 1546300800000;
199
200 auto config = mgr.getSpecific<CTPConfiguration>(o2::ctp::CCDBPathCTPConfig, timestamp, metadata);
201 LOG(info) << " @@@ CTP Digitizer:: CCDB connected " << std::endl;
202 return config;
203}
204
206{
207}
ClassImp(Digitizer)
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 Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
char error[CURL_ERROR_SIZE]
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)
GLint GLuint mask
Definition glcorearb.h:291
const std::string CCDBPathCTPConfig
Database constants.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Digit > digits