Project
Loading...
Searching...
No Matches
DigitizerTask.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
19#include "MFTBase/GeometryTGeo.h"
20#include "MathUtils/Utils.h"
21
22#include <fairlogger/Logger.h> // for LOG
23#include "FairRootManager.h" // for FairRootManager
24
26
27using namespace o2::mft;
28using namespace o2::detectors;
29using namespace o2::utils;
30
32
33//_____________________________________________________________________________
34DigitizerTask::DigitizerTask() : FairTask("MFTDigitizerTask"), mDigitizer() {}
35//_____________________________________________________________________________
37{
38 mDigitsArray.clear();
39 mMCTruthArray.clear();
40 delete mHitsArrayQED; // this special branch is managed by the task
41}
42
47{
48 FairRootManager* mgr = FairRootManager::Instance();
49 if (!mgr) {
50 LOG(error) << "Could not instantiate FairRootManager. Exiting ...";
51 return kERROR;
52 }
53
54 mHitsArray = mgr->InitObjectAs<const std::vector<o2::itsmft::Hit>*>("MFTHit");
55 if (!mHitsArray) {
56 LOG(error) << "MFT hits not registered in the FairRootManager. Exiting ...";
57 return kERROR;
58 }
59
60 // Register output container
61 mgr->RegisterAny("MFTDigit", mDigitsArrayPtr, kTRUE);
62 mgr->RegisterAny("MFTDigitMCTruth", mMCTruthArrayPtr, kTRUE);
63
65 geom->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::L2G)); // make sure L2G matrices are loaded
66 mDigitizer.setGeometry(geom);
67
68 mDigitizer.setDigits(mDigitsArrayPtr);
69 mDigitizer.setMCLabels(mMCTruthArrayPtr);
70
71 mDigitizer.init();
72
73 return kSUCCESS;
74}
75
76//________________________________________________________
77void DigitizerTask::Exec(Option_t* option)
78{
79 FairRootManager* mgr = FairRootManager::Instance();
80
81 mDigitsArray.clear();
82 mMCTruthArray.clear();
83
84 double tEvent = mgr->GetEventTime() * mFairTimeUnitInNS; // event time in ns
85
86 // is there QED backgroung provided? Fill QED slots until provided collision time
87 if (mQEDBranch) {
88 processQEDBackground(tEvent);
89 }
90 //
91 mDigitizer.setEventTime(tEvent);
92 // the type of digitization is steered by the DigiParams object of the Digitizer
93 LOG(debug) << "Running digitization on new event " << mEventID << " from source " << mSourceID;
94
95 mDigitizer.process(mHitsArray, mEventID, mSourceID);
96
97 mEventID++;
98}
99
100//________________________________________________________
102{
103 // finalize digitization, if needed, flash remaining digits
104
105 if (!mDigitizer.getParams().isContinuous()) {
106 return;
107 }
108
109 // is there QED backgroung provided? Fill QED slots up to the end of reserved ROFrames
110 if (mQEDBranch) {
111 processQEDBackground(mDigitizer.getEndTimeOfROFMax());
112 }
113
114 FairRootManager* mgr = FairRootManager::Instance();
115 mgr->SetLastFill(kTRUE);
116 mDigitsArray.clear();
117 mMCTruthArray.clear();
118 mDigitizer.fillOutputContainer();
119}
120
121//________________________________________________________
122void DigitizerTask::processQEDBackground(double tMax)
123{
124 // process QED time-slots until provided collision time (in ns)
125
126 double tQEDNext = mLastQEDTimeNS + mQEDEntryTimeBinNS;
127
128 while (tQEDNext < tMax) {
129 mLastQEDTimeNS = tQEDNext; // time used for current QED slot
130 tQEDNext += mQEDEntryTimeBinNS; // prepare time for next QED slot
131 if (++mLastQEDEntry >= mQEDBranch->GetEntries()) {
132 mLastQEDEntry = 0; // wrapp if needed
133 }
134 mQEDBranch->GetEntry(mLastQEDEntry);
135 mDigitizer.setEventTime(mLastQEDTimeNS);
136 mDigitizer.process(mHitsArrayQED, mLastQEDEntry, mQEDSourceID);
137 //
138 }
139}
140
141//________________________________________________________
142void DigitizerTask::setQEDInput(TBranch* qed, float timebin, UChar_t srcID)
143{
144 // assign the branch containing hits from QED electrons, whith every entry integrating
145 // timebin ns of collisions
146
147 LOG(info) << "Attaching QED ITS hits as sourceID=" << int(srcID) << ", entry integrates "
148 << timebin << " ns";
149
150 mQEDBranch = qed;
151 mQEDEntryTimeBinNS = timebin;
152 if (mQEDBranch) {
153 assert(mQEDEntryTimeBinNS >= 1.0);
154 mLastQEDTimeNS = -mQEDEntryTimeBinNS / 2; // time will be assigned to the middle of the bin
155 mQEDBranch->SetAddress(&mHitsArrayQED);
156 mLastQEDEntry = -1;
157 mQEDSourceID = srcID;
158 assert(mHitsArrayQED);
159 assert(srcID < o2::MCCompLabel::maxSourceID());
160 }
161}
General auxilliary methods.
Definition of the ITSMFT Hit class.
ClassImp(o2::mft::DigitizerTask)
Task driving the conversion from points to digits (MFT)
std::ostringstream debug
static constexpr int maxSourceID()
bool isContinuous() const
Definition DigiParams.h:52
double getEndTimeOfROFMax() const
Definition Digitizer.h:71
void setEventTime(const o2::InteractionTimeRecord &irt)
void setGeometry(const o2::itsmft::GeometryTGeo *gm)
Definition Digitizer.h:85
void setMCLabels(o2::dataformats::MCTruthContainer< o2::MCCompLabel > *mclb)
Definition Digitizer.h:57
void setDigits(std::vector< o2::itsmft::Digit > *dig)
Definition Digitizer.h:56
o2::itsmft::DigiParams & getParams()
Definition Digitizer.h:59
void process(const std::vector< Hit > *hits, int evID, int srcID)
Steer conversion of hits to digits.
void fillOutputContainer(uint32_t maxFrame=0xffffffff)
void FinishTask() override
InitStatus Init() override
Init function.
void setQEDInput(TBranch *qed, float timebin, UChar_t srcID)
void Exec(Option_t *option) override
void fillMatrixCache(Int_t mask) override
static GeometryTGeo * Instance()
static constexpr int L2G
Definition Cartesian.h:54
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"