forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTRDPulseHeightSpec.h
More file actions
135 lines (117 loc) · 4.58 KB
/
TRDPulseHeightSpec.h
File metadata and controls
135 lines (117 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef O2_TRD_PULSEHEIGHTSPEC_H
#define O2_TRD_PULSEHEIGHTSPEC_H
/// \file TRDPulseHeightSpec.h
/// \brief DPL device for creating a pulse height spectrum with digits on tracks
#include "Framework/Task.h"
#include "Framework/ConfigParamRegistry.h"
#include "Framework/ControlService.h"
#include "Framework/WorkflowSpec.h"
#include "DetectorsBase/GRPGeomHelper.h"
#include "ReconstructionDataFormats/GlobalTrackID.h"
#include "TRDCalibration/PulseHeight.h"
#include "DataFormatsTRD/PHData.h"
#include <cstring>
using namespace o2::framework;
using GID = o2::dataformats::GlobalTrackID;
namespace o2
{
namespace trd
{
class PuseHeightDevice : public o2::framework::Task
{
public:
PuseHeightDevice(std::shared_ptr<DataRequest> dr) : mDataRequest(dr) {}
void init(o2::framework::InitContext& ic) final
{
mPulseHeight = std::make_unique<PulseHeight>();
if (ic.options().get<bool>("enable-root-output")) {
mPulseHeight->createOutputFile();
}
if (getenv("ALIEN_JDL_LPMPRODUCTIONTYPE") && std::strcmp(getenv("ALIEN_JDL_LPMPRODUCTIONTYPE"), "MC") == 0) {
// apply artificial pad shift in case non-ideal alignment is used to compensate for shift in current alignment from real data
mPulseHeight->setApplyShift(false);
}
}
void run(o2::framework::ProcessingContext& pc) final
{
const auto& tinfo = pc.services().get<o2::framework::TimingInfo>();
if (tinfo.globalRunNumberChanged) { // new run is starting
mRunStopRequested = false;
}
if (mRunStopRequested) {
std::vector<PHData> mPHValues{}; // the calibration expects data at every TF, so inject dummy
pc.outputs().snapshot(Output{"TRD", "PULSEHEIGHT", 0}, mPHValues);
std::vector<PHDataHD> mPHValuesHD{}; // the calibration expects data at every TF, so inject dummy
pc.outputs().snapshot(Output{"TRD", "PULSEHEIGHTHD", 0}, mPHValuesHD);
return;
}
RecoContainer recoData;
recoData.collectData(pc, *mDataRequest.get());
auto digits = pc.inputs().get<gsl::span<o2::trd::Digit>>("digits");
mPulseHeight->setInput(recoData, &digits);
mPulseHeight->reset();
mPulseHeight->process();
pc.outputs().snapshot(Output{"TRD", "PULSEHEIGHT", 0}, mPulseHeight->getPHData());
if (pc.transitionState() == TransitionHandlingState::Requested) {
LOG(info) << "Run stop requested, finalizing";
mRunStopRequested = true;
}
}
void endOfStream(o2::framework::EndOfStreamContext& ec) final
{
mPulseHeight->closeOutputFile();
if (mRunStopRequested) {
return;
}
}
void stop() final
{
}
private:
std::shared_ptr<DataRequest> mDataRequest;
std::unique_ptr<o2::trd::PulseHeight> mPulseHeight;
bool mRunStopRequested = false; // flag that run was stopped (and the last output is sent)
};
} // namespace trd
namespace framework
{
DataProcessorSpec getTRDPulseHeightSpec(GID::mask_t src, bool digitsFromReader)
{
std::vector<OutputSpec> outputs;
outputs.emplace_back(o2::header::gDataOriginTRD, "PULSEHEIGHT", 0, Lifetime::Timeframe);
bool isTPCavailable = false;
if (GID::includesSource(GID::Source::ITSTPC, src)) {
LOGF(debug, "Found ITS-TPC tracks as input, loading ITS-TPC-TRD");
src |= GID::getSourcesMask("ITS-TPC-TRD");
}
if (GID::includesSource(GID::Source::TPC, src)) {
LOGF(debug, "Found TPC tracks as input, loading TPC-TRD");
src |= GID::getSourcesMask("TPC-TRD");
isTPCavailable = true;
}
GID::mask_t srcClu = GID::getSourcesMask("TRD"); // we don't need all clusters, only TRD tracklets
auto dataRequest = std::make_shared<DataRequest>();
dataRequest->requestTracks(src, false);
dataRequest->requestClusters(srcClu, false);
dataRequest->inputs.emplace_back("digits", "TRD", "DIGITS", digitsFromReader ? 1 : 0);
return DataProcessorSpec{
"trd-pulseheight",
dataRequest->inputs,
outputs,
AlgorithmSpec{adaptFromTask<o2::trd::PuseHeightDevice>(dataRequest)},
Options{
{"enable-root-output", VariantType::Bool, false, {"output PH and debug data to root file"}}}};
}
} // namespace framework
} // namespace o2
#endif // O2_TRD_PULSEHEIGHTSPEC_H