Skip to content

Commit 1fd68bc

Browse files
dstoccoaphecetche
authored andcommitted
Allow to set different thresholds for MID dead and noisy channels
1 parent abc954f commit 1fd68bc

13 files changed

Lines changed: 278 additions & 98 deletions

Detectors/MUON/MID/Calibration/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
o2_add_library(
1313
MIDCalibration
14-
SOURCES src/ChannelCalibrator.cxx
14+
SOURCES src/ChannelCalibrator.cxx src/ChannelCalibratorFinalizer.cxx src/ChannelCalibratorParam.cxx
1515
PUBLIC_LINK_LIBRARIES O2::DataFormatsMID O2::MIDFiltering
1616
O2::DetectorsCalibration O2::CCDB Microsoft.GSL::GSL)
1717

1818
o2_target_root_dictionary(MIDCalibration
19-
HEADERS include/MIDCalibration/ChannelCalibrator.h)
19+
HEADERS include/MIDCalibration/ChannelCalibrator.h include/MIDCalibration/ChannelCalibratorParam.h)
2020

2121
add_subdirectory(exe)

Detectors/MUON/MID/Calibration/include/MIDCalibration/ChannelCalibrator.h

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef O2_MID_CHANNELCALIBRATOR_H
1818
#define O2_MID_CHANNELCALIBRATOR_H
1919

20+
#include <array>
2021
#include <string>
2122
#include <vector>
2223
#include <gsl/span>
@@ -30,9 +31,9 @@ namespace o2
3031
namespace mid
3132
{
3233

33-
class NoiseData
34+
class CalibData
3435
{
35-
using Slot = o2::calibration::TimeSlot<NoiseData>;
36+
using Slot = o2::calibration::TimeSlot<CalibData>;
3637

3738
public:
3839
/// Fills the data
@@ -41,7 +42,7 @@ class NoiseData
4142

4243
/// Merges data
4344
/// \param prev Previous container
44-
void merge(const NoiseData* prev);
45+
void merge(const CalibData* prev);
4546

4647
/// Prints scalers
4748
void print();
@@ -52,13 +53,13 @@ class NoiseData
5253
private:
5354
ChannelScalers mChannelScalers;
5455

55-
ClassDefNV(NoiseData, 1);
56+
ClassDefNV(CalibData, 1);
5657
};
5758

58-
class ChannelCalibrator final : public o2::calibration::TimeSlotCalibration<ColumnData, NoiseData>
59+
class ChannelCalibrator final : public o2::calibration::TimeSlotCalibration<ColumnData, CalibData>
5960
{
6061
using TFType = o2::calibration::TFType;
61-
using Slot = o2::calibration::TimeSlot<NoiseData>;
62+
using Slot = o2::calibration::TimeSlot<CalibData>;
6263

6364
public:
6465
/// Initialize the output
@@ -79,25 +80,21 @@ class ChannelCalibrator final : public o2::calibration::TimeSlotCalibration<Colu
7980
/// \param tend End time
8081
Slot& emplaceNewSlot(bool front, TFType tstart, TFType tend) final;
8182

82-
/// Add number of calibration triggers processed
83-
/// \param nEvents Number of calibration triggers in this TF
84-
void addEvents(unsigned long int nEvents) { mEventsCounter += nEvents; }
83+
/// Add elapsed time or number of calibration triggers processed
84+
/// \param timeOrTriggers Elapsed time or number of calibration triggers processed in this TF
85+
void addTimeOrTriggers(double timeOrTriggers) { mTimeOrTriggers += timeOrTriggers; }
8586

8687
/// Returns the bad channels
8788
const std::vector<ColumnData>& getBadChannels() const { return mBadChannels; }
8889

89-
/// Returns mask as string
90-
std::string getMasksAsString() { return mMasksString; }
91-
92-
/// Sets reference masks
93-
void setReferenceMasks(const std::vector<ColumnData>& refMasks) { mRefMasks = refMasks; }
90+
/// Sets the threshold
91+
/// \param threshold Threshold
92+
void setThreshold(double threshold) { mThreshold = threshold; }
9493

9594
private:
9695
std::vector<ColumnData> mBadChannels; /// List of bad channels
97-
std::vector<ColumnData> mRefMasks; /// Reference masks
98-
std::string mMasksString; /// Masks as string
99-
double mThreshold = 0.9; /// Noise threshold
100-
unsigned long int mEventsCounter = 0; /// Events counter
96+
double mThreshold = 0.9; /// dead channels threshold
97+
double mTimeOrTriggers = 0; /// Events counter
10198

10299
ClassDefOverride(ChannelCalibrator, 1);
103100
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
12+
/// \file MIDCalibration/ChannelCalibratorFinalizer.h
13+
/// \brief MID noise and dead channels calibrator finalizer
14+
/// \author Diego Stocco <Diego.Stocco at cern.ch>
15+
/// \date 31 October 2022
16+
17+
#ifndef O2_MID_CHANNELCALIBRATORFINALIZER_H
18+
#define O2_MID_CHANNELCALIBRATORFINALIZER_H
19+
20+
#include <string>
21+
#include <vector>
22+
#include <gsl/span>
23+
#include "DataFormatsMID/ColumnData.h"
24+
25+
namespace o2
26+
{
27+
namespace mid
28+
{
29+
30+
class ChannelCalibratorFinalizer
31+
{
32+
public:
33+
/// Process the noisy and dead channels
34+
/// \param noise Vector of noisy channels
35+
/// \param dead Vector of dead channels
36+
void process(const gsl::span<const ColumnData> noise, const gsl::span<const ColumnData> dead);
37+
38+
/// Returns the bad channels
39+
const std::vector<ColumnData>& getBadChannels() const { return mBadChannels; }
40+
41+
/// Returns mask as string
42+
/// \return Masks as a string
43+
std::string getMasksAsString() { return mMasksString; }
44+
45+
/// Sets reference masks
46+
/// \param refMasks Reference masks
47+
void setReferenceMasks(const std::vector<ColumnData>& refMasks) { mRefMasks = refMasks; }
48+
49+
private:
50+
std::vector<ColumnData> mBadChannels; /// List of bad channels
51+
std::vector<ColumnData> mRefMasks; /// Reference masks
52+
std::string mMasksString; /// Masks as string
53+
};
54+
} // namespace mid
55+
} // namespace o2
56+
57+
#endif
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
12+
#ifndef O2_MID_CHANNELCALIBRATORPARAM_H
13+
#define O2_MID_CHANNELCALIBRATORPARAM_H
14+
15+
#include "CommonUtils/ConfigurableParam.h"
16+
#include "CommonUtils/ConfigurableParamHelper.h"
17+
18+
namespace o2
19+
{
20+
namespace mid
21+
{
22+
23+
/**
24+
* @class ChannelCalibratorParam
25+
* @brief Configurable parameters for the Bad Channel Calibrator
26+
*/
27+
struct ChannelCalibratorParam : public o2::conf::ConfigurableParamHelper<ChannelCalibratorParam> {
28+
29+
float maxNoise = 10000.f; ///< maximum allowed noise value (Hz)
30+
float maxDead = 0.9f; ///< maximum fraction of time a strip was not responding to FET
31+
32+
O2ParamDef(ChannelCalibratorParam, "MIDChannelCalibratorParam");
33+
};
34+
} // namespace mid
35+
} // namespace o2
36+
37+
#endif

Detectors/MUON/MID/Calibration/src/ChannelCalibrator.cxx

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,35 @@
2020
#include <sstream>
2121
#include "DetectorsCalibration/Utils.h"
2222
#include "MIDFiltering/MaskMaker.h"
23-
#include "MIDFiltering/ChannelMasksHandler.h"
24-
#include "MIDRaw/ColumnDataToLocalBoard.h"
25-
#include "MIDRaw/ROBoardConfigHandler.h"
2623

2724
namespace o2
2825
{
2926
namespace mid
3027
{
3128

32-
using Slot = o2::calibration::TimeSlot<NoiseData>;
29+
using Slot = o2::calibration::TimeSlot<CalibData>;
3330

34-
void NoiseData::fill(const gsl::span<const ColumnData> data)
31+
void CalibData::fill(const gsl::span<const ColumnData> data)
3532
{
3633
for (auto& col : data) {
3734
mChannelScalers.count(col);
3835
}
3936
}
4037

41-
void NoiseData::merge(const NoiseData* prev)
38+
void CalibData::merge(const CalibData* prev)
4239
{
4340
mChannelScalers.merge(prev->mChannelScalers);
4441
}
4542

46-
void NoiseData::print()
43+
void CalibData::print()
4744
{
4845
std::cout << mChannelScalers;
4946
}
5047

5148
void ChannelCalibrator::initOutput()
5249
{
5350
mBadChannels.clear();
54-
mEventsCounter = 0;
55-
mMasksString = "";
51+
mTimeOrTriggers = 0;
5652
}
5753

5854
bool ChannelCalibrator::hasEnoughData(const Slot& slot) const
@@ -67,37 +63,17 @@ Slot& ChannelCalibrator::emplaceNewSlot(bool front, TFType tstart, TFType tend)
6763
{
6864
auto& cont = getSlots();
6965
auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend);
70-
slot.setContainer(std::make_unique<NoiseData>());
66+
slot.setContainer(std::make_unique<CalibData>());
7167
return slot;
7268
}
7369

7470
void ChannelCalibrator::finalizeSlot(Slot& slot)
7571
{
76-
o2::mid::NoiseData* noiseData = slot.getContainer();
72+
o2::mid::CalibData* calibData = slot.getContainer();
7773
LOG(info) << "Finalize slot " << slot.getTFStart() << " <= TF <= " << slot.getTFEnd();
7874

7975
// Keep track of last TimeFrame, since the masks will be valid from now on
80-
mBadChannels = makeBadChannels(noiseData->getScalers(), mEventsCounter, mThreshold);
81-
82-
// Get the masks for the electronics
83-
// First convert the dead channels into masks
84-
ChannelMasksHandler masksHandler;
85-
masksHandler.switchOffChannels(mBadChannels);
86-
87-
// Complete with the expected masks from mapping
88-
masksHandler.merge(mRefMasks);
89-
90-
// Convert column data masks to local board masks
91-
ColumnDataToLocalBoard colToBoard;
92-
colToBoard.process(masksHandler.getMasks(), true);
93-
94-
// Update local board configuration with the masks
95-
ROBoardConfigHandler roBoardCfgHandler;
96-
roBoardCfgHandler.updateMasks(colToBoard.getData());
97-
std::stringstream ss;
98-
roBoardCfgHandler.write(ss);
99-
100-
mMasksString = ss.str();
76+
mBadChannels = makeBadChannels(calibData->getScalers(), mTimeOrTriggers, mThreshold);
10177
}
10278

10379
} // namespace mid
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
12+
/// \file MID/Calibration/src/ChannelCalibratorFinalizer.cxx
13+
/// \brief MID noise and dead channels calibrator finalizer
14+
/// \author Diego Stocco <Diego.Stocco at cern.ch>
15+
/// \date 31 October 2022
16+
17+
#include "MIDCalibration/ChannelCalibratorFinalizer.h"
18+
19+
#include <sstream>
20+
#include "MIDBase/ColumnDataHandler.h"
21+
#include "MIDFiltering/ChannelMasksHandler.h"
22+
#include "MIDRaw/ColumnDataToLocalBoard.h"
23+
#include "MIDRaw/ROBoardConfigHandler.h"
24+
25+
namespace o2
26+
{
27+
namespace mid
28+
{
29+
30+
void ChannelCalibratorFinalizer::process(const gsl::span<const ColumnData> noise, const gsl::span<const ColumnData> dead)
31+
{
32+
ColumnDataHandler colHandler;
33+
colHandler.merge(noise);
34+
colHandler.merge(dead);
35+
36+
// Keep track of last TimeFrame, since the masks will be valid from now on
37+
mBadChannels = colHandler.getMerged();
38+
39+
// Get the masks for the electronics
40+
// First convert the dead channels into masks
41+
ChannelMasksHandler masksHandler;
42+
masksHandler.switchOffChannels(mBadChannels);
43+
44+
// Complete with the expected masks from mapping
45+
masksHandler.merge(mRefMasks);
46+
47+
// Convert column data masks to local board masks
48+
ColumnDataToLocalBoard colToBoard;
49+
colToBoard.process(masksHandler.getMasks(), true);
50+
51+
// Update local board configuration with the masks
52+
ROBoardConfigHandler roBoardCfgHandler;
53+
roBoardCfgHandler.updateMasks(colToBoard.getData());
54+
std::stringstream ss;
55+
roBoardCfgHandler.write(ss);
56+
57+
mMasksString = ss.str();
58+
}
59+
60+
} // namespace mid
61+
} // namespace o2
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
12+
#include "MIDCalibration/ChannelCalibratorParam.h"
13+
14+
O2ParamImpl(o2::mid::ChannelCalibratorParam);

Detectors/MUON/MID/Calibration/src/MIDCalibrationLinkDef.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
#pragma link off all classes;
1616
#pragma link off all functions;
1717

18-
#pragma link C++ class o2::mid::NoiseData + ;
18+
#pragma link C++ class o2::mid::ChannelCalibratorParam + ;
19+
#pragma link C++ class o2::mid::CalibData + ;
1920
#pragma link C++ class o2::mid::ChannelCalibrator + ;
20-
#pragma link C++ class o2::calibration::TimeSlot < o2::mid::NoiseData> + ;
21-
#pragma link C++ class o2::calibration::TimeSlotCalibration < o2::mid::ColumnData, o2::mid::NoiseData> + ;
21+
#pragma link C++ class o2::calibration::TimeSlot < o2::mid::CalibData> + ;
22+
#pragma link C++ class o2::calibration::TimeSlotCalibration < o2::mid::ColumnData, o2::mid::CalibData> + ;
2223

2324
#endif

Detectors/MUON/MID/Filtering/include/MIDFiltering/MaskMaker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ namespace o2
2626
namespace mid
2727
{
2828

29-
std::vector<ColumnData> makeBadChannels(const ChannelScalers& scalers, unsigned long nEvents, double threshold = 0.9);
30-
std::vector<ColumnData> makeMasks(const ChannelScalers& scalers, unsigned long nEvents, double threshold = 0.9, const std::vector<ColumnData>& refMasks = {});
29+
std::vector<ColumnData> makeBadChannels(const ChannelScalers& scalers, double timeOrTriggers, double threshold);
30+
std::vector<ColumnData> makeMasks(const ChannelScalers& scalers, double timeOrTriggers, double threshold, const std::vector<ColumnData>& refMasks = {});
3131
std::vector<ColumnData> makeDefaultMasks();
3232
std::vector<ColumnData> makeDefaultMasksFromCrateConfig(const FEEIdConfig& feeIdConfig = FEEIdConfig(), const CrateMasks& crateMasks = CrateMasks());
3333

0 commit comments

Comments
 (0)