39#include <TStopwatch.h>
52 std::vector<OutputSpec> outputs;
53 for (uint32_t iLayer = 0; iLayer < static_cast<uint32_t>(nLayers); ++iLayer) {
54 outputs.emplace_back(detOrig,
"DIGITS", iLayer, Lifetime::Timeframe);
55 outputs.emplace_back(detOrig,
"DIGITSROF", iLayer, Lifetime::Timeframe);
57 outputs.emplace_back(detOrig,
"DIGITSMCTR", iLayer, Lifetime::Timeframe);
60 outputs.emplace_back(detOrig,
"ROMode", 0, Lifetime::Timeframe);
72 if constexpr (N == o2::detectors::DetID::TRK) {
83 static_assert(N == o2::detectors::DetID::TRK || N == o2::detectors::DetID::FT3,
"only TRK and FT3 digitizers are supported");
84 static constexpr o2::detectors::DetID ID{N == o2::detectors::DetID::TRK ? o2::detectors::DetID::TRK : o2::detectors::DetID::FT3};
92 mDisableQED = ic.
options().
get<
bool>(
"disable-qed");
93 mLocalRespFile = ic.
options().
get<std::string>(
"local-response-file");
108 const bool withQED = context->isQEDProvided() && !mDisableQED;
109 auto& timesview = context->getEventRecords(withQED);
110 LOG(info) <<
"GOT " << timesview.size() <<
" COLLISION TIMES";
111 LOG(info) <<
"SIMCHAINS " << mSimChains.size();
114 if (timesview.empty()) {
119 LOG(info) <<
" CALLING " <<
ID.
getName() <<
" DIGITIZATION ";
121 auto& eventParts = context->getEventParts(withQED);
123 for (uint32_t iLayer = 0; iLayer < static_cast<uint32_t>(mLayers); ++iLayer) {
124 mDigits[iLayer].clear();
125 mROFRecords[iLayer].clear();
126 mROFRecordsAccum[iLayer].clear();
128 mLabels[iLayer].clear();
129 mLabelsAccum[iLayer].clear();
143 mROFRecordsAccum[iLayer].reserve(nROFsTF);
145 auto accumulate = [
this, &digitsAccum, &iLayer]() {
148 if (mDigits[iLayer].
empty()) {
151 auto ndigAcc = digitsAccum.size();
152 std::copy(mDigits[iLayer].begin(), mDigits[iLayer].
end(), std::back_inserter(digitsAccum));
154 for (
auto& rof : mROFRecords[iLayer]) {
155 rof.setFirstEntry(ndigAcc + rof.getFirstEntry());
158 std::copy(mROFRecords[iLayer].begin(), mROFRecords[iLayer].
end(), std::back_inserter(mROFRecordsAccum[iLayer]));
160 mLabelsAccum[iLayer].mergeAtBack(mLabels[iLayer]);
162 LOG(info) <<
"Added " << mDigits[iLayer].size() <<
" digits on layer " << iLayer;
163 mLabels[iLayer].clear();
164 mDigits[iLayer].clear();
165 mROFRecords[iLayer].clear();
169 for (
size_t collID = 0; collID < timesview.size(); ++collID) {
170 auto irt = timesview[collID];
171 if (irt.toLong() < bcShift) {
178 for (
auto& part : eventParts[collID]) {
182 if (!mHits.empty()) {
183 LOG(
debug) <<
"For collision " << collID <<
" eventID " << part.entryID
184 <<
" found " << mHits.size() <<
" hits on layer " << iLayer;
185 mDigitizer.
process(&mHits, part.entryID, part.sourceID, iLayer);
192 nDigits += digitsAccum.size();
194 std::vector<o2::trkft3::ROFRecord> expDigitRofVec(nROFsTF);
195 for (
int iROF = 0; iROF < nROFsTF; ++iROF) {
196 auto& rof = expDigitRofVec[iROF];
200 rof.setROFrame(iROF);
202 rof.setFirstEntry(-1);
205 for (
const auto& rof : mROFRecordsAccum[iLayer]) {
206 const auto&
ir = rof.getBCData();
207 const auto irToFirst =
ir - firstIR;
208 const auto irROF = irToFirst.
toLong() / roFrameLengthInBC;
209 if (irROF < 0 || irROF >= nROFsTF) {
212 auto& expROF = expDigitRofVec[irROF];
213 expROF.setFirstEntry(rof.getFirstEntry());
214 expROF.setNEntries(rof.getNEntries());
215 if (expROF.getBCData() != rof.getBCData()) {
216 LOGP(fatal,
"detected mismatch between expected {} and received {}", expROF.asString(), rof.asString());
221 for (
auto& rof : expDigitRofVec) {
222 if (rof.getFirstEntry() < 0) {
223 rof.setFirstEntry(prevFirst);
225 prevFirst = rof.getFirstEntry();
231 mLabelsAccum[iLayer].flatten_to(sharedlabels);
232 mLabels[iLayer].clear_andfreememory();
233 mLabelsAccum[iLayer].clear_andfreememory();
236 LOG(info) <<
ID.
getName() <<
": Sending ROMode= " << mROMode <<
" to GRPUpdater";
240 LOG(info) <<
"Digitization took " << timer.CpuTime() <<
"s";
241 LOG(info) <<
"Produced " << nDigits <<
" digits";
251 std::unique_ptr<TFile> file(TFile::Open(mLocalRespFile.data(),
"READ"));
253 LOG(fatal) <<
"Cannot open response file " << mLocalRespFile;
260 static bool initOnce{
false};
267 if constexpr (N == o2::detectors::DetID::TRK) {
278 mLayers = getNLayers<N>();
283 mDigits.resize(mLayers);
284 mROFRecords.resize(mLayers);
285 mROFRecordsAccum.resize(mLayers);
286 mLabels.resize(mLayers);
287 mLabelsAccum.resize(mLayers);
289 for (
int iLayer = 0; iLayer < mLayers; ++iLayer) {
291 const auto roFrameLengthInBC = aopt.getROFLengthInBC(parLayer);
293 digipar.setROFrameLengthInBC(roFrameLengthInBC, iLayer);
295 digipar.setROFrameBiasInBC(aopt.getROFBiasInBC(parLayer) + aopt.getROFDelayInBC(parLayer), iLayer);
296 digipar.setStrobeDelay(aopt.getStrobeDelay(parLayer), iLayer);
297 const auto strobeLengthCont = aopt.getStrobeLengthCont(parLayer);
298 digipar.setStrobeLength(strobeLengthCont > 0 ? strobeLengthCont : frameNS - aopt.getStrobeDelay(parLayer), iLayer);
299 digipar.setROFrameLength(frameNS, iLayer);
302 digipar.getSignalShape().setParameters(dopt.strobeFlatTop, dopt.strobeMaxRiseTime, dopt.strobeQRiseTime0);
303 digipar.setChargeThreshold(dopt.chargeThreshold);
304 digipar.setNoisePerPixel(dopt.noisePerPixel);
305 digipar.setTimeOffset(dopt.timeOffset);
306 digipar.setNSimSteps(dopt.nSimSteps);
309 LOG(info) <<
ID.
getName() <<
" simulated in CONTINUOUS RO mode";
327 par.printKeyValues();
336 LOG(info) <<
ID.
getName() <<
" loaded APTSResponseData";
337 if (mLocalRespFile.empty()) {
338 LOG(info) <<
"Using CCDB/APTS response file";
342 LOG(info) <<
"Response function will be loaded from local file: " << mLocalRespFile;
350 bool mWithMCTruth{
true};
351 bool mFinished{
false};
352 bool mDisableQED{
false};
353 unsigned long mFirstOrbitTF = 0x0;
354 std::string mLocalRespFile{
""};
357 std::vector<std::vector<o2::trkft3::Digit>> mDigits{};
358 std::vector<std::vector<o2::trkft3::ROFRecord>> mROFRecords{};
359 std::vector<std::vector<o2::trkft3::ROFRecord>> mROFRecordsAccum{};
360 std::vector<o2::trkft3::Hit> mHits{};
361 std::vector<o2::trkft3::Hit>* mHitsP{&mHits};
362 std::vector<o2::dataformats::MCTruthContainer<o2::MCCompLabel>> mLabels{};
363 std::vector<o2::dataformats::MCTruthContainer<o2::MCCompLabel>> mLabelsAccum{};
364 std::vector<TChain*> mSimChains{};
372 std::vector<InputSpec> inputs;
373 inputs.emplace_back(
"collisioncontext",
"SIM",
"COLLISIONCONTEXT",
static_cast<SubSpecificationType>(channel), Lifetime::Timeframe);
378 inputs.emplace_back(
"TRK_aptsresp",
"TRK",
"APTSRESP", 0, Lifetime::Condition,
ccdbParamSpec(
"IT3/Calib/APTSResponse"));
381 inputs, makeOutChannels(detOrig, getNLayers<o2::detectors::DetID::TRK>(), mctruth),
382 AlgorithmSpec{adaptFromTask<TRKFT3DPLDigitizerTask<o2::detectors::DetID::TRK>>(mctruth)},
392 std::vector<InputSpec> inputs;
393 inputs.emplace_back(
"collisioncontext",
"SIM",
"COLLISIONCONTEXT",
static_cast<SubSpecificationType>(channel), Lifetime::Timeframe);
394 inputs.emplace_back(
"FT3_aptsresp",
"FT3",
"APTSRESP", 0, Lifetime::Condition,
ccdbParamSpec(
"IT3/Calib/APTSResponse"));
397 inputs, makeOutChannels(detOrig, getNLayers<o2::detectors::DetID::FT3>(), mctruth),
398 AlgorithmSpec{adaptFromTask<TRKFT3DPLDigitizerTask<o2::detectors::DetID::FT3>>(mctruth)},
Definition of the base digitizer task class.
A const (ready only) version of MCTruthContainer.
o2::framework::DataAllocator::SubSpecificationType SubSpecificationType
Header of the General Run Parameters object.
Definition of the GeometryTGeo class.
Definition of the TRK/FT3 digitizer.
virtual void init(o2::framework::InitContext &) final
static const HBFUtils & Instance()
Static class with identifiers, bitmasks and names for ALICE detectors.
static constexpr const char * getName(ID id)
names of defined detectors
static const std::array< std::vector< std::string >, DetID::nDetectors > DETECTORBRANCHNAMES
T get(const char *key) const
void snapshot(const Output &spec, T const &object)
o2::header::DataHeader::SubSpecificationType SubSpecificationType
decltype(auto) make(const Output &spec, Args... args)
ConfigParamRegistry const & options()
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
static GeometryTGeo * Instance()
bool initSimChains(o2::detectors::DetID detid, std::vector< TChain * > &simchains) const
static GeometryTGeo * Instance()
void setResponse(const o2::itsmft::AlpideSimResponse *)
int getROFrameBiasInBC(int layer) const
int getROFrameLengthInBC(int layer) const
void setROFRecords(std::vector< o2::trkft3::ROFRecord > *rec)
void setGeometry(const GeometryTGeo *gm)
void setEventTime(const o2::InteractionTimeRecord &irt, int layer)
void process(const std::vector< o2::trkft3::Hit > *hits, int evID, int srcID, int layer)
Steer conversion of hits to digits.
void resetROFrameBounds()
void setResponseName(const std::string &name)
void setMCLabels(o2::dataformats::MCTruthContainer< o2::MCCompLabel > *mclb)
void fillOutputContainer(uint32_t maxFrame, int layer)
void resetEventROFrames()
o2::trkft3::DigiParams< DetID > & getParams()
void setDigits(std::vector< o2::trkft3::Digit > *dig)
void run(framework::ProcessingContext &pc)
void initDigitizerTask(framework::InitContext &ic) override
void setLocalResponseFunction()
TRKFT3DPLDigitizerTask(bool mctruth=true)
void finaliseCCDB(ConcreteDataMatcher &matcher, void *obj)
static constexpr o2::header::DataOrigin Origin
static constexpr o2::detectors::DetID ID
void updateTimeDependentParams(ProcessingContext &pc)
constexpr o2::header::DataOrigin gDataOriginTRK
constexpr o2::header::DataOrigin gDataOriginFT3
constexpr int LHCMaxBunches
constexpr double LHCBunchSpacingNS
Defining ITS Vertex explicitly as messageable.
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
std::vector< ConfigParamSpec > Options
header::DataHeader::SubSpecificationType SubSpecificationType
DataProcessorSpec getTRKDigitizerSpec(int channel, bool mctruth)
DataProcessorSpec getFT3DigitizerSpec(int channel, bool mctruth)
class listing possible services
int getNOrbitsPerTF() const
get IR corresponding to start of the HBF
static constexpr size_t getNLayers()
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
o2::InteractionRecord ir(0, 0)