Belle II Software prerelease-11-00-00a
BadBoardADCDetector.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <tracking/trackFindingCDC/findlets/minimal/BadBoardADCDetector.h>
9
10#include <tracking/trackingUtilities/rootification/StoreWrappedObjPtr.h>
11#include <tracking/trackingUtilities/rootification/StoreWrapper.h>
12#include <tracking/trackingUtilities/utilities/StringManipulation.h>
13#include <framework/core/ModuleParamList.templateDetails.h>
14#include <cdc/geometry/CDCGeometryPar.h>
15#include <cdc/dataobjects/CDCHit.h>
16
17#include <map>
18
19using namespace Belle2;
20using namespace TrackFindingCDC;
21
25
31
33{
34 // checking validity once per run should be sufficient
35 if (not m_badBoardsFromDB.isValid()) B2FATAL("CDCBadBoards payload not found!");
36}
37
39{
40 return "Detect boards with bad ADC values and mark hits accordingly";
41}
42
44 const std::string& prefix)
45{
46 moduleParamList->addParameter(TrackingUtilities::prefixed(prefix, "badADCaverageMin"),
48 "Minimal value of average ADC to consider board bad",
50 moduleParamList->addParameter(TrackingUtilities::prefixed(prefix, "badADCaverageMax"),
52 "Maximal value of average ADC to consider a board as bad",
54 moduleParamList->addParameter(TrackingUtilities::prefixed(prefix, "badTOTaverageMin"),
56 "Minimal value of average TOT to consider board bad",
58}
59
60void BadBoardADCDetector::apply(std::vector<TrackingUtilities::CDCWireHit>& wireHits)
61{
63 // first loop: average ADC per board
64 std::map <int, double> BoardADC;
65 std::map <int, double> BoardTOT;
66 std::map <int, int> BoardCount;
67 for (auto& wireHit : wireHits) {
68 auto board = geometryPar.getBoardID(wireHit.getWireID());
69 BoardCount[board] += 1;
70 BoardADC[board] += (*wireHit.getHit()).getADCCount();
71 BoardTOT[board] += (*wireHit.getHit()).getTOT();
72 };
73 // now compute the averages:
74 for (auto& pair : BoardADC) {
75 int board = pair.first;
76 BoardADC[board] /= BoardCount[board];
77 BoardTOT[board] /= BoardCount[board];
78 }
79
80 // second loop, set flag if board is problematic:
81 for (auto& wireHit : wireHits) {
82 auto board = geometryPar.getBoardID(wireHit.getWireID());
83 if ((BoardADC[board] > m_badADCaverageMin) || (BoardADC[board] <= m_badADCaverageMax))
84 wireHit->setBoardWithBadADCFlag();
85 if (BoardTOT[board] > m_badTOTaverageMin)
86 wireHit->setBoardWithBadTOTFlag();
87 }
88
89 // 3rd loop, over all boards, update list of them. Include boards with no hits at all
91
92 storeVector.create();
93
94 // TODO: decide if need the dead boards from the payload. Should be not possible that this method fails to detect those!?
95 double dummyEff = 0; // needed by isDeadBoard function else unused
96 // Note that board 0 is absent, the loop starts from 1.
97 for (unsigned int iBoard = 1; iBoard < c_nBoards; iBoard += 1) {
98 if (BoardCount.find(iBoard) == BoardCount.end() || m_badBoardsFromDB->isDeadBoard(iBoard, dummyEff)) {
99 storeVector->push_back(iBoard);
100 }
101 }
102}
The Class for CDC Geometry Parameters.
unsigned short getBoardID(const WireID &wID) const
Returns frontend board id. corresponding to the wire id.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
The Module parameter list class.
bool create(bool replace=false)
Create a default object in the data store.
int m_badTOTaverageMin
Min TOT value for the average.
int m_badADCaverageMin
Min ADC value for the average.
DBObjPtr< CDCBadBoards > m_badBoardsFromDB
Pointer to the CDCBadBoards payload.
std::string getDescription() final
Short description of the findlet.
void apply(std::vector< TrackingUtilities::CDCWireHit > &wireHits) final
Main algorithm marking hit as background.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
int m_badADCaverageMax
Max ADC value for the average.
This class is for convenience access and registration of objects, that are stored inside the StoreWra...
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_DontWriteOut|DataStore::c_ErrorIfAlreadyRegistered)
Register the object/array in the DataStore.
STL class.
void addParameter(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
Abstract base class for different kinds of events.