Skip to content

Commit caf9ca0

Browse files
files added
1 parent 614eafc commit caf9ca0

2 files changed

Lines changed: 296 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#ifndef STEER_DIGITIZERWORKFLOW_FOCALDIGITIZER_H_
2+
#define STEER_DIGITIZERWORKFLOW_FOCALDIGITIZER_H_
3+
4+
#include <memory>
5+
#include <vector>
6+
7+
#include "Framework/DataProcessorSpec.h"
8+
#include "Framework/Task.h"
9+
#include "DataFormatsFOCAL/Digit.h"
10+
#include "FOCALBase/Hit.h"
11+
#include "FOCALSimulation/Digitizer.h" //we dont have this one yet
12+
#include "FOCALSimulation/SDigitizer.h"
13+
#include "SimulationDataFormat/MCTruthContainer.h"
14+
#include <DetectorsBase/BaseDPLDigitizer.h>
15+
16+
class TChain;
17+
18+
namespace o2
19+
{
20+
21+
namespace steer
22+
{
23+
class MCKinematicsReader;
24+
}
25+
26+
namespace focal
27+
{
28+
29+
class DigitizerSpec final : public o2::base::BaseDPLDigitizer, public o2::framework::Task
30+
{
31+
public:
32+
using o2::base::BaseDPLDigitizer::init;
33+
/// \brief Constructor
34+
DigitizerSpec() : o2::base::BaseDPLDigitizer(o2::base::InitServices::GEOM), o2::framework::Task(){}
35+
36+
/// \brief Destructor
37+
~DigitizerSpec() final = default;
38+
39+
/// \brief init digitizer
40+
/// \param ctx Init context
41+
void initDigitizerTask(framework::InitContext& ctx) final;
42+
43+
void configure();
44+
45+
/// \brief run digitizer
46+
/// \param ctx Processing context
47+
///
48+
/// Handling of pileup events:
49+
/// - Open readout window when the event sets a trigger
50+
/// - Accumulate digits sampled via the time response from different bunch crossings
51+
/// - Retrieve digits when the readout window closes
52+
void run(framework::ProcessingContext& ctx) override;
53+
54+
private:
55+
Bool_t mFinished = false; ///< Flag for digitization finished
56+
bool mIsConfigured = false; ///< Initialization status of the digitizer
57+
bool mRunSDitizer = false; ///< Run SDigitization
58+
Digitizer mDigitizer; ///< Digitizer object
59+
o2::focal::SDigitizer mSumDigitizer; ///< Summed digitizer
60+
std::vector<Hit> mHits; ///< Vector with input hits
61+
std::vector<TChain*> mSimChains;
62+
o2::steer::MCKinematicsReader* mcReader; ///< reader to access MC collision information
63+
bool mRunDigitizer = true;
64+
};
65+
66+
/// \brief Create new digitizer spec
67+
/// \return Digitizer spec
68+
o2::framework::DataProcessorSpec getFOCALDigitizerSpec(int channel, bool mctruth = true);
69+
70+
} // namespace focal
71+
} // end namespace o2
72+
73+
#endif /* STEER_DIGITIZERWORKFLOW_FOCALDIGITIZER_H_ */
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
2+
#include "FOCALWorkflow/FOCALDigitizerSpec.h"
3+
#include "CommonConstants/Triggers.h"
4+
#include "Framework/ConfigParamRegistry.h"
5+
#include "Framework/ControlService.h"
6+
#include "Framework/DataProcessorSpec.h"
7+
#include "Framework/DataRefUtils.h"
8+
#include "Framework/Lifetime.h"
9+
#include "Headers/DataHeader.h"
10+
#include "TStopwatch.h"
11+
#include "Steer/HitProcessingManager.h" // for DigitizationContext
12+
#include "TChain.h"
13+
#include <TGeoManager.h>
14+
15+
#include "CommonDataFormat/EvIndex.h"
16+
#include "DetectorsCommonDataFormats/DetID.h"
17+
#include "DataFormatsParameters/GRPObject.h"
18+
#include "DataFormatsFOCAL/TriggerRecord.h"
19+
#include <Steer/MCKinematicsReader.h>
20+
21+
using namespace o2::framework;
22+
using SubSpecificationType = o2::framework::DataAllocator::SubSpecificationType;
23+
24+
namespace o2
25+
{
26+
namespace focal
27+
{
28+
29+
void DigitizerSpec::initDigitizerTask(framework::InitContext& ctx)
30+
{
31+
if (!gGeoManager) {
32+
LOG(error) << "Geometry needs to be loaded before";
33+
}
34+
35+
auto geom = o2::focal::Geometry::GetInstance();
36+
37+
mSumDigitizer.setGeometry(geom);
38+
mDigitizer.setGeometry(geom);
39+
40+
if (ctx.options().get<bool>("debug-stream")) {
41+
mDigitizer.setDebugStreaming(true);
42+
}
43+
44+
if (ctx.options().get<bool>("disable-dig")) {
45+
mRunDigitizer = false;
46+
}
47+
48+
mFinished = false;
49+
}
50+
51+
void DigitizerSpec::run(framework::ProcessingContext& ctx)
52+
{
53+
if (mFinished) {
54+
return;
55+
}
56+
57+
if (!mIsConfigured) {
58+
configure();
59+
mIsConfigured = true;
60+
}
61+
62+
o2::focal::SimParam::Instance().printKeyValues(true, true);
63+
64+
mDigitizer.flush();
65+
66+
auto context = ctx.inputs().get<o2::steer::DigitizationContext*>("collisioncontext");
67+
68+
auto intRate = context->getDigitizerInteractionRate();
69+
context->initSimChains(o2::detectors::DetID::FOC, mSimChains);
70+
71+
if (mcReader == nullptr) {
72+
mcReader = new o2::steer::MCKinematicsReader(context.get());
73+
}
74+
75+
auto& timesview = context->getEventRecords();
76+
LOG(debug) << "GOT " << timesview.size() << " COLLISSION TIMES";
77+
78+
if (timesview.size() == 0) {
79+
return;
80+
}
81+
82+
TStopwatch timer;
83+
timer.Start();
84+
85+
auto& eventParts = context->getEventParts();
86+
87+
int collisionN = 0;
88+
for (int collID = 0; collID < timesview.size(); ++collID) {
89+
90+
if (mRunDigitizer == false) {
91+
break;
92+
}
93+
94+
if (intRate < 10000.) {
95+
break;
96+
}
97+
98+
collisionN++;
99+
100+
mDigitizer.setEventTime(timesview[collID]);
101+
102+
for (auto& part : eventParts[collID]) {
103+
104+
mSumDigitizer.setCurrEvID(part.entryID);
105+
mSumDigitizer.setCurrSrcID(part.sourceID);
106+
107+
mHits.clear();
108+
context->retrieveHits(mSimChains, "FOCHit", part.sourceID, part.entryID, &mHits);
109+
110+
std::vector<o2::focal::LabeledDigit> summedLabeledDigits;
111+
std::vector<o2::focal::Digit> summedDigits;
112+
if (mRunSDitizer) {
113+
summedLabeledDigits = mSumDigitizer.process(mHits);
114+
for (auto labeledsummeddigit : summedLabeledDigits) {
115+
summedDigits.push_back(labeledsummeddigit.getDigit());
116+
}
117+
} else {
118+
for (auto& hit : mHits) {
119+
summedDigits.emplace_back(hit.GetDetectorID(), hit.GetEnergyLoss(), hit.GetTime());
120+
}
121+
}
122+
123+
mDigitizer.process(summedDigits);
124+
}
125+
}
126+
mDigitizer.finish();
127+
128+
LOG(info) << " CALLING FOCAL DIGITIZATION ";
129+
o2::dataformats::MCTruthContainer<o2::focal::MCLabel> labelAccum;
130+
131+
for (int collID = 0; collID < timesview.size(); ++collID) {
132+
133+
std::bitset<5> trigger{0x1};
134+
135+
if (!trigger.any()) {
136+
continue;
137+
}
138+
139+
mDigitizer.setEventTime(timesview[collID], trigger.any());
140+
if (!mDigitizer.isCurrentEventTriggered()) {
141+
LOG(debug) << "reject collision";
142+
continue;
143+
}
144+
LOG(debug) << "accept collision";
145+
146+
for (auto& part : eventParts[collID]) {
147+
148+
mSumDigitizer.setCurrEvID(part.entryID);
149+
mSumDigitizer.setCurrSrcID(part.sourceID);
150+
151+
auto& mcEventHeader = mcReader->getMCEventHeader(part.sourceID, part.entryID);
152+
mcEventHeader.print();
153+
154+
mHits.clear();
155+
context->retrieveHits(mSimChains, "FOCHit", part.sourceID, part.entryID, &mHits);
156+
157+
LOG(info) << "For collision " << collID << " eventID " << part.entryID << " found " << mHits.size() << " hits ";
158+
159+
std::vector<o2::focal::LabeledDigit> summedLabeledDigits;
160+
if (mRunSDitizer) {
161+
summedLabeledDigits = mSumDigitizer.process(mHits);
162+
} else {
163+
for (auto& hit : mHits) {
164+
o2::focal::MCLabel digitlabel(hit.GetTrackID(), part.entryID, part.sourceID, false, 1.);
165+
if (hit.GetEnergyLoss() < __DBL_EPSILON__) {
166+
digitlabel.setAmplitudeFraction(0);
167+
}
168+
summedLabeledDigits.emplace_back(hit.GetDetectorID(), hit.GetEnergyLoss(), hit.GetTime(), digitlabel);
169+
}
170+
}
171+
172+
mDigitizer.process(summedLabeledDigits);
173+
}
174+
}
175+
mDigitizer.finish();
176+
177+
ctx.outputs().snapshot(Output{"FOC", "DIGITS", 0}, mDigitizer.getDigits());
178+
if (ctx.outputs().isAllowed({"FOC", "DIGITSMCTR", 0})) {
179+
ctx.outputs().snapshot(Output{"FOC", "DIGITSMCTR", 0}, mDigitizer.getMCLabels());
180+
}
181+
const o2::parameters::GRPObject::ROMode roMode = o2::parameters::GRPObject::TRIGGERING;
182+
LOG(info) << "FOCAL: Sending ROMode= " << roMode << " to GRPUpdater";
183+
ctx.outputs().snapshot(Output{"FOC", "ROMode", 0}, roMode);
184+
185+
timer.Stop();
186+
LOG(info) << "Digitization took " << timer.CpuTime() << "s";
187+
ctx.services().get<ControlService>().readyToQuit(QuitRequest::Me);
188+
mFinished = true;
189+
}
190+
191+
void DigitizerSpec::configure()
192+
{
193+
mDigitizer.init();
194+
}
195+
196+
o2::framework::DataProcessorSpec getFOCALDigitizerSpec(int channel, bool mctruth)
197+
{
198+
199+
std::vector<OutputSpec> outputs;
200+
outputs.emplace_back("FOC", "DIGITS", 0, Lifetime::Timeframe);
201+
outputs.emplace_back("FOC", "TRGRDIG", 0, Lifetime::Timeframe);
202+
if (mctruth) {
203+
outputs.emplace_back("FOC", "DIGITSMCTR", 0, Lifetime::Timeframe);
204+
}
205+
outputs.emplace_back("FOC", "ROMode", 0, Lifetime::Timeframe);
206+
outputs.emplace_back("FOC", "TRIGGERINPUT", 0, Lifetime::Timeframe);
207+
208+
std::vector<o2::framework::InputSpec> inputs;
209+
inputs.emplace_back("collisioncontext", "SIM", "COLLISIONCONTEXT", static_cast<SubSpecificationType>(channel), Lifetime::Timeframe);
210+
211+
212+
return DataProcessorSpec{
213+
"FOCALDigitizer",
214+
inputs,
215+
outputs,
216+
Options{
217+
{"pileup", VariantType::Int, 1, {"whether to run in continuous time mode"}},
218+
{"disable-dig", VariantType::Bool, false, {"Disable digitisation"}},
219+
{"debug-stream", VariantType::Bool, false, {"Enable debug streaming"}}}
220+
};
221+
}
222+
} // end namespace focal
223+
} // end namespace o2

0 commit comments

Comments
 (0)