36#include <TStopwatch.h>
49 std::vector<OutputSpec> outputs;
50 outputs.emplace_back(detOrig,
"DIGITS", 0, Lifetime::Timeframe);
51 outputs.emplace_back(detOrig,
"DIGITSROF", 0, Lifetime::Timeframe);
53 outputs.emplace_back(detOrig,
"DIGITSMC2ROF", 0, Lifetime::Timeframe);
54 outputs.emplace_back(detOrig,
"DIGITSMCTR", 0, Lifetime::Timeframe);
56 outputs.emplace_back(detOrig,
"ROMode", 0, Lifetime::Timeframe);
73 mDisableQED = ic.
options().
get<
bool>(
"disable-qed");
74 mLocalRespFile = ic.
options().
get<std::string>(
"local-response-file");
89 const bool withQED = context->isQEDProvided() && !mDisableQED;
90 auto& timesview = context->getEventRecords(withQED);
91 LOG(info) <<
"GOT " << timesview.size() <<
" COLLISION TIMES";
92 LOG(info) <<
"SIMCHAINS " << mSimChains.size();
95 if (timesview.empty()) {
100 LOG(info) <<
" CALLING TRK DIGITIZATION ";
107 auto& digitsAccum = pc.
outputs().
make<std::vector<itsmft::Digit>>(
Output{mOrigin,
"DIGITS", 0});
112 mROFRecordsAccum.reserve(nROFsTF);
114 auto accumulate = [
this, &digitsAccum]() {
117 if (mDigits.empty()) {
118 LOG(
debug) <<
"No digits to accumulate";
121 LOG(
debug) <<
"Accumulating " << mDigits.size() <<
" digits ";
122 auto ndigAcc = digitsAccum.size();
123 std::copy(mDigits.begin(), mDigits.end(), std::back_inserter(digitsAccum));
126 auto nROFRecsOld = mROFRecordsAccum.size();
128 for (
int i = 0;
i < mROFRecords.size();
i++) {
129 auto& rof = mROFRecords[
i];
130 rof.setFirstEntry(ndigAcc + rof.getFirstEntry());
133 if (mFixMC2ROF < mMC2ROFRecordsAccum.size()) {
134 for (
int m2rid = mFixMC2ROF; m2rid < mMC2ROFRecordsAccum.size(); m2rid++) {
136 auto& mc2rof = mMC2ROFRecordsAccum[m2rid];
137 if (rof.getROFrame() == mc2rof.minROF) {
139 mc2rof.rofRecordID = nROFRecsOld +
i;
146 std::copy(mROFRecords.begin(), mROFRecords.end(), std::back_inserter(mROFRecordsAccum));
150 LOG(info) <<
"Added " << mDigits.size() <<
" digits ";
157 auto& eventParts = context->getEventParts(withQED);
161 for (
size_t collID = 0; collID < timesview.size(); ++collID) {
162 auto irt = timesview[collID];
163 if (irt.toLong() < bcShift) {
172 for (
auto& part : eventParts[collID]) {
178 if (!mHits.empty()) {
179 LOG(
debug) <<
"For collision " << collID <<
" eventID " << part.entryID
180 <<
" found " << mHits.size() <<
" hits ";
181 mDigitizer.
process(&mHits, part.entryID, part.sourceID);
188 LOG(
debug) <<
"mDigits size after fill: " << mDigits.size();
192 std::vector<o2::itsmft::ROFRecord> expDigitRofVec(nROFsTF);
193 for (
int iROF = 0; iROF < nROFsTF; ++iROF) {
194 auto& rof = expDigitRofVec[iROF];
198 rof.setROFrame(iROF);
200 rof.setFirstEntry(-1);
203 for (
const auto& rof : mROFRecordsAccum) {
204 const auto&
ir = rof.getBCData();
205 const auto irToFirst =
ir - firstIR;
206 const auto irROF = irToFirst.
toLong() / roFrameLengthInBC;
207 if (irROF < 0 || irROF >= nROFsTF) {
210 auto& expROF = expDigitRofVec[irROF];
211 expROF.setFirstEntry(rof.getFirstEntry());
212 expROF.setNEntries(rof.getNEntries());
213 if (expROF.getBCData() != rof.getBCData()) {
214 LOGP(fatal,
"detected mismatch between expected {} and received {}", expROF.asString(), rof.asString());
219 for (
auto& rof : expDigitRofVec) {
220 if (rof.getFirstEntry() < 0) {
221 rof.setFirstEntry(prevFirst);
223 prevFirst = rof.getFirstEntry();
228 std::vector<o2::itsmft::MC2ROFRecord> clippedMC2ROFRecords;
229 clippedMC2ROFRecords.reserve(mMC2ROFRecordsAccum.size());
230 for (
auto mc2rof : mMC2ROFRecordsAccum) {
231 if (mc2rof.rofRecordID < 0 || mc2rof.minROF >=
static_cast<uint32_t
>(nROFsTF)) {
232 mc2rof.rofRecordID = -1;
236 mc2rof.maxROF = std::min<uint32_t>(mc2rof.maxROF, nROFsTF - 1);
237 if (mc2rof.minROF > mc2rof.maxROF) {
238 mc2rof.rofRecordID = -1;
242 mc2rof.rofRecordID = mc2rof.minROF;
245 clippedMC2ROFRecords.push_back(mc2rof);
254 LOG(info) << mID.
getName() <<
": Sending ROMode= " << mROMode <<
" to GRPUpdater";
258 LOG(info) <<
"Digitization took " << timer.CpuTime() <<
"s";
268 std::unique_ptr<TFile> file(TFile::Open(mLocalRespFile.data(),
"READ"));
270 LOG(fatal) <<
"Cannot open response file " << mLocalRespFile;
277 static bool initOnce{
false};
292 digipar.setContinuous(
true);
293 digipar.setROFrameBiasInBC(aopt.roFrameBiasInBC);
294 digipar.setROFrameLengthInBC(aopt.roFrameLengthInBC);
295 digipar.setROFrameLength(frameNS);
296 digipar.setStrobeDelay(aopt.strobeDelay);
297 digipar.setStrobeLength(aopt.strobeLengthCont > 0 ? aopt.strobeLengthCont : frameNS - aopt.strobeDelay);
299 digipar.getSignalShape().setParameters(dopt.strobeFlatTop, dopt.strobeMaxRiseTime, dopt.strobeQRiseTime0);
300 digipar.setChargeThreshold(dopt.chargeThreshold);
301 digipar.setNoisePerPixel(dopt.noisePerPixel);
302 digipar.setTimeOffset(dopt.timeOffset);
303 digipar.setNSimSteps(dopt.nSimSteps);
306 LOG(info) << mID.
getName() <<
" simulated in CONTINUOUS RO mode";
322 LOG(info) << mID.
getName() <<
" Almira param updated";
324 par.printKeyValues();
333 LOG(info) << mID.
getName() <<
" loaded APTSResponseData";
334 if (mLocalRespFile.empty()) {
335 LOG(info) <<
"Using CCDB/APTS response file";
339 LOG(info) <<
"Response function will be loaded from local file: " << mLocalRespFile;
347 bool mWithMCTruth{
true};
348 bool mFinished{
false};
349 bool mDisableQED{
false};
350 unsigned long mFirstOrbitTF = 0x0;
351 std::string mLocalRespFile{
""};
355 std::vector<o2::itsmft::Digit> mDigits{};
356 std::vector<o2::itsmft::ROFRecord> mROFRecords{};
357 std::vector<o2::itsmft::ROFRecord> mROFRecordsAccum{};
358 std::vector<o2::trk::Hit> mHits{};
359 std::vector<o2::trk::Hit>* mHitsP{&mHits};
362 std::vector<o2::itsmft::MC2ROFRecord> mMC2ROFRecordsAccum{};
363 std::vector<TChain*> mSimChains{};
373 std::vector<InputSpec> inputs;
374 inputs.emplace_back(
"collisioncontext",
"SIM",
"COLLISIONCONTEXT",
static_cast<SubSpecificationType>(channel), Lifetime::Timeframe);
379 inputs.emplace_back(
"TRK_aptsresp",
"TRK",
"APTSRESP", 0, Lifetime::Condition,
ccdbParamSpec(
"IT3/Calib/APTSResponse"));
382 inputs, makeOutChannels(detOrig, 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 TRK 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.
bool initSimChains(o2::detectors::DetID detid, std::vector< TChain * > &simchains) const
void setResponse(const o2::itsmft::AlpideSimResponse *)
int getROFrameBiasInBC() const
int getROFrameLengthInBC() const
void setEventTime(const o2::InteractionTimeRecord &irt)
void fillOutputContainer(uint32_t maxFrame=0xffffffff)
o2::trk::DigiParams & getParams()
void setResponseName(const std::string &name)
void process(const std::vector< o2::trk::Hit > *hits, int evID, int srcID)
Steer conversion of hits to digits.
uint32_t getEventROFrameMin() const
void setDigits(std::vector< o2::itsmft::Digit > *dig)
void setROFRecords(std::vector< o2::itsmft::ROFRecord > *rec)
void setMCLabels(o2::dataformats::MCTruthContainer< o2::MCCompLabel > *mclb)
void setGeometry(const o2::trk::GeometryTGeo *gm)
uint32_t getEventROFrameMax() const
void resetEventROFrames()
void Print(Option_t *opt="") const
void fillMatrixCache(int mask)
static GeometryTGeo * Instance()
TRKDPLDigitizerTask(bool mctruth=true)
void run(framework::ProcessingContext &pc)
void updateTimeDependentParams(ProcessingContext &pc)
void finaliseCCDB(ConcreteDataMatcher &matcher, void *obj)
void setLocalResponseFunction()
void initDigitizerTask(framework::InitContext &ic) override
constexpr o2::header::DataOrigin gDataOriginTRK
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)
class listing possible services
int getNOrbitsPerTF() const
get IR corresponding to start of the HBF
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
o2::InteractionRecord ir(0, 0)