37 std::string histname, histtitle;
42 mADCDistLayer[
layer]->SetDirectory(
nullptr);
45 auto calibmethod = ctx.options().get<std::string>(
"calibmethod");
46 if (calibmethod ==
"mean") {
48 }
else if (calibmethod ==
"fit") {
51 LOG(
error) <<
"Unknown calibration method - using default (mean) instead";
53 LOG(info) <<
"Writing calibration histograms in path: " << mPath;
58 std::vector<char> rawbuffer;
60 if (rawData.header !=
nullptr && rawData.payload !=
nullptr) {
63 gsl::span<const char> databuffer(rawData.payload, payloadSize);
67 while (currentpos < databuffer.size()) {
68 auto rdh =
reinterpret_cast<const o2::header::RDHAny*
>(databuffer.data() + currentpos);
69 auto trigger = o2::raw::RDHUtils::getTriggerType(rdh);
72 if (o2::raw::RDHUtils::getStop(rdh)) {
74 if (rawbuffer.size()) {
76 if (currentfee == 0xcafe) {
77 processRawData(rawbuffer);
80 LOG(
debug) <<
"Payload size 0 - skip empty HBF";
84 currentfee = o2::raw::RDHUtils::getFEEID(rdh);
88 if (o2::raw::RDHUtils::getMemorySize(rdh) == o2::raw::RDHUtils::getHeaderSize(rdh)) {
90 currentpos += o2::raw::RDHUtils::getOffsetToNext(rdh);
95 auto payloadsize = o2::raw::RDHUtils::getMemorySize(rdh) - o2::raw::RDHUtils::getHeaderSize(rdh);
96 auto page_payload = databuffer.subspan(currentpos + o2::raw::RDHUtils::getHeaderSize(rdh), payloadsize);
97 std::copy(page_payload.begin(), page_payload.end(), std::back_inserter(rawbuffer));
98 currentpos += o2::raw::RDHUtils::getOffsetToNext(rdh);
106 LOG(info) <<
"Data collected - calculating pedestals and sending them";
107 calculatePedestals();
120 info.setPath(
"FOC/Calib/PadPedestals");
121 info.setObjectType(
"Pedestals");
122 info.setFileName(flName);
124 const auto now = std::chrono::system_clock::now();
125 long timeStart = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
126 info.setStartValidityTimestamp(timeStart);
128 std::map<std::string, std::string> md;
129 info.setMetaData(md);
131 LOG(info) <<
"Sending object FOC/Calib/PadPedestals";
139 TFile pedestalWriter(
"FOCALPedestalCalib.root",
"RECREATE");
141 pedestalWriter.WriteObjectAny(mPedestalContainer.get(), o2::focal::PadPedestal::Class(),
"ccdb_object");
145 std::filesystem::path filepath(mPath);
146 filepath.append(
"FOCALPadPedestals.root");
147 LOG(info) <<
"Writing ADC distribution to " << filepath.c_str();
148 TFile distwriter(filepath.c_str(),
"RECREATE");
151 mADCDistLayer[
layer]->Write();
155void PadPedestalCalibDevice::processRawData(
const gsl::span<const char> padWords)
157 constexpr std::size_t EVENTSIZEPADGBT = 1180,
158 EVENTSIZECHAR = EVENTSIZEPADGBT *
sizeof(
PadGBTWord) /
sizeof(
char);
159 auto nevents = padWords.size() / (EVENTSIZECHAR);
160 for (
int ievent = 0; ievent < nevents; ievent++) {
161 gsl::span<const PadGBTWord> padWordsGBT(
reinterpret_cast<const PadGBTWord*
>(padWords.data()), padWords.size() /
sizeof(
PadGBTWord));
168 mADCDistLayer[
layer]->Fill(chan, layerdata.getChannel(chan).getADC());
174void PadPedestalCalibDevice::calculatePedestals()
176 mPedestalContainer = std::make_unique<PadPedestal>();
180 std::unique_ptr<TH1> channelADC(mADCDistLayer[
layer]->ProjectionY(
"channelADC", channel + 1, channel + 1));
182 mPedestalContainer->setPedestal(
layer, channel, evaluatePedestal(channelADC.get()));
185 LOG(
error) <<
"Failure accessing setting pedestal: " <<
e.what();
189 LOG(info) <<
"Found pedestals for " << nPedestals <<
" channels";
192double PadPedestalCalibDevice::evaluatePedestal(TH1* channel)
195 switch (mExtractionMethod) {
198 int maxbin = channel->GetMaximumBin();
199 pedestal = channel->GetBinCenter(maxbin);
204 pedestal = channel->GetMean();
209 TF1 pedmodal(
"pedmodel",
"gaus", 0, 2000);
210 channel->Fit(&pedmodal,
"Q");
211 pedestal = pedmodal.GetParameter(1);
220 std::vector<o2::framework::OutputSpec> outputs;
227 o2::framework::adaptFromTask<o2::focal::PadPedestalCalibDevice>(updateCCDB,
path,
debug),
Definition of the 32 Central Trigger System (CTS) Trigger Types defined in https://twiki....
Utils and constants for calibration and related workflows.
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
char error[CURL_ERROR_SIZE]
static std::string generateFileName(const std::string &inp)
static std::unique_ptr< std::vector< char > > createObjectImage(const T *obj, CcdbObjectInfo *info=nullptr)
static constexpr long INFINITE_TIMESTAMP
const ASICData & getASIC() const
const ASICContainer & getDataForASIC(int index) const
const PadData & getData() const
void decodeEvent(gsl::span< const PadGBTWord > padpayload)
void init(framework::InitContext &ctx) final
void endOfStream(o2::framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
PadPedestalCalibDevice(bool updateCCDB, const std::string &path, bool debugMode)
void run(framework::ProcessingContext &ctx) final
DataAllocator & outputs()
GLsizei const GLchar *const * path
GLenum GLuint GLint GLint layer
constexpr int PADLAYER_MODULE_NCHANNELS
o2::framework::DataProcessorSpec getPadPedestalCalibDevice(bool updateCCDB, const std::string &path, bool debug)
std::vector< InputSpec > select(char const *matcher="")
std::string to_string(gsl::span< T, Size > span)
static constexpr o2::header::DataOrigin gDataOriginCDBWrapper
static constexpr o2::header::DataOrigin gDataOriginCDBPayload
static o2::header::DataHeader::PayloadSizeType getPayloadSize(const DataRef &ref)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"