Belle II Software development
GlobalCalibrationManager Class Reference

Class to hold hierarchy of whole Belle2. More...

#include <Manager.h>

Public Member Functions

 ~GlobalCalibrationManager ()
 Destructor.
 
void sortUniqueVector (std::vector< EventMetaData > &vec)
 Sort vector of EventMetaData and make it unique to process user defined time splittings of the constants.
 
void initialize (const std::vector< std::string > &components={}, const std::vector< EventMetaData > &timeSlices={})
 Initialize the manager with given configuration (from MillepedeCollector)
 
void preCollect (const EventMetaData &emd)
 Notice manager of a comming event (from MillepedeCollector)
 
RigidBodyHierarchygetAlignmentHierarchy () const
 Get the rigid body alignment hierarchy.
 
LorentShiftHierarchygetLorentzShiftHierarchy () const
 Get the Lorentz shift hierarchy.
 
Constraints & getConstraints ()
 Get the constraints collected so far.
 
void writeConstraints (std::string txtFilename)
 Write-out complete hierarchy to a text file.
 

Static Public Member Functions

static GlobalCalibrationManagergetInstance ()
 Get instance of the Manager auto& gcm = GlobalCalibrationManager::getInstance();.
 
static void initGlobalVector (GlobalParamVector &vector)
 Initialize a given GlobalParamVector with all DB objects and interfaces.
 

Public Attributes

std::function< bool(const EventMetaData &, const EventMetaData &)> cmpEventMetaData
 Comparison function for EventMetaData.
 

Private Member Functions

 GlobalCalibrationManager ()
 Singleton class, hidden constructor.
 
 GlobalCalibrationManager (const GlobalCalibrationManager &)
 Singleton class, hidden copy constructor.
 
GlobalCalibrationManageroperator= (const GlobalCalibrationManager &)
 Singleton class, hidden assignment operator.
 
int updateTimeDepGlobalLabels (const EventMetaData &event)
 Update the current time ID in the GlobalLabel.
 

Private Attributes

bool m_initialized {false}
 Finished initialization?
 
std::unique_ptr< RigidBodyHierarchym_alignment {new RigidBodyHierarchy()}
 The alignment hierarchy.
 
std::unique_ptr< LorentShiftHierarchym_lorentzShift {new LorentShiftHierarchy()}
 Hierarchy for Lorentz shift corrections.
 
std::unique_ptr< GlobalParamVectorm_globalVector {new GlobalParamVector()}
 The global vector for unified access to DB constants.
 
std::map< long, Constraint > m_constraints {}
 Map of constraints {unique label, labels and coefficients}.
 
std::vector< EventMetaDatam_dbTimeSlicing {}
 Vector of EventMetaData containing the time slicing of the calibration job.
 
alignment::timeline::TimeTable m_iniTimeTable {}
 The initial time table generated from time intervals in GlobalLabel used to check if payload (labels) can change and update the hierarchy if so.
 

Detailed Description

Class to hold hierarchy of whole Belle2.

Definition at line 50 of file Manager.h.

Constructor & Destructor Documentation

◆ ~GlobalCalibrationManager()

Destructor.

Definition at line 70 of file Manager.h.

70{}

◆ GlobalCalibrationManager()

GlobalCalibrationManager ( )
inlineprivate

Singleton class, hidden constructor.

Definition at line 117 of file Manager.h.

117{};

Member Function Documentation

◆ getAlignmentHierarchy()

RigidBodyHierarchy & getAlignmentHierarchy ( ) const
inline

Get the rigid body alignment hierarchy.


Definition at line 106 of file Manager.h.

106{ return *m_alignment; }
std::unique_ptr< RigidBodyHierarchy > m_alignment
The alignment hierarchy.
Definition: Manager.h:133

◆ getConstraints()

Constraints & getConstraints ( )
inline

Get the constraints collected so far.

Definition at line 110 of file Manager.h.

110{ return m_constraints; }
std::map< long, Constraint > m_constraints
Map of constraints {unique label, labels and coefficients}.
Definition: Manager.h:139

◆ getInstance()

GlobalCalibrationManager & getInstance ( )
static

Get instance of the Manager auto& gcm = GlobalCalibrationManager::getInstance();.

Note you actually initialize the Manager with your specific selection of DB objects to calibrate (or select all for global calibration -default) and other options.

Definition at line 27 of file Manager.cc.

28 {
29 static std::unique_ptr<GlobalCalibrationManager> instance(new GlobalCalibrationManager());
30 return *instance;
31 }
GlobalCalibrationManager()
Singleton class, hidden constructor.
Definition: Manager.h:117

◆ getLorentzShiftHierarchy()

LorentShiftHierarchy & getLorentzShiftHierarchy ( ) const
inline

Get the Lorentz shift hierarchy.

Definition at line 108 of file Manager.h.

108{ return *m_lorentzShift; }
std::unique_ptr< LorentShiftHierarchy > m_lorentzShift
Hierarchy for Lorentz shift corrections.
Definition: Manager.h:135

◆ initGlobalVector()

void initGlobalVector ( GlobalParamVector vector)
static

Initialize a given GlobalParamVector with all DB objects and interfaces.

  auto gpv = GlobalParamVector({"BeamSpot"});
  GlobalCalibrationManager::initGlobalVector(gpv);

This one central function should be used to prepare the global vectors even for local calibrations using Millepede. By setting the components argument of GlobalParamVector one can limit which addDBObj<>() calls are actually executed

Definition at line 33 of file Manager.cc.

34 {
35 // Interfaces for sub-detectors
36 auto cdcInterface = std::shared_ptr<IGlobalParamInterface>(new CDCGlobalParamInterface());
37 auto vxdInterface = std::shared_ptr<IGlobalParamInterface>(new VXDGlobalParamInterface());
38
39 // Try add all supported DB objects
40 // - will be not added if not in selected components of the 'vector'
41 vector.addDBObj<BeamSpot>();
42 vector.addDBObj<VXDAlignment>(vxdInterface);
43 vector.addDBObj<CDCAlignment>(cdcInterface);
44 vector.addDBObj<CDCTimeZeros>(cdcInterface);
45 vector.addDBObj<CDCTimeWalks>(cdcInterface);
46 vector.addDBObj<CDCXtRelations>(cdcInterface);
47 vector.addDBObj<BKLMAlignment>();
48 vector.addDBObj<EKLMAlignment>();
49 vector.addDBObj<EKLMSegmentAlignment>();
50 }

◆ initialize()

void initialize ( const std::vector< std::string > &  components = {},
const std::vector< EventMetaData > &  timeSlices = {} 
)

Initialize the manager with given configuration (from MillepedeCollector)


To be used by MillepedeCollector

Definition at line 52 of file Manager.cc.

54 {
55 // Reset the config of global vector to restrict components if needed
56 m_globalVector.reset(new GlobalParamVector(components));
57 // Fill with DB objects and interfaces according to components
59 // Set the components for global label system
60 GlobalLabel::setComponents(m_globalVector->getComponentsIDs());
61
62 // Reset time intervals and add pre-defined times where
63 // constants can change (in addition of what is already in DB)
64 m_dbTimeSlicing = timeSlices;
66
67 GlobalLabel label;
68 m_iniTimeTable = alignment::timeline::makeInitialTimeTable(m_dbTimeSlicing, label);
69
70 StoreObjPtr<EventMetaData> emd;
71 if (emd.isValid()) updateTimeDepGlobalLabels(*emd);
72
73 // already during initialization (due to geometry) we know the first event
74 // to be processed, so we can actually load the consts here - and construct the vector
75 //
76 // m_globalVector->loadFromDB();
77 // m_globalVector->listGlobalParams().size();
78
79 // event data loaded
80 // gearbox loaded
81 // geometry loaded
82 // extrapolation setup
83
84 // Try to build hierarchy now by interfaces
85 //TODO by restricting components you stop to observe some hierarchy changes!
86 m_globalVector->postHierarchyChanged(getAlignmentHierarchy());
87 m_globalVector->postHierarchyChanged(getLorentzShiftHierarchy());
90
91 // Try to init as much as possible before event processing
92 // geometry, reconstruction config -> recohits & derivatives
93
94 m_initialized = true;
95
96 }
static void setComponents(const std::set< unsigned short > &components)
Set which DB objects have non-zero labels (by their id)
Definition: GlobalLabel.h:107
bool m_initialized
Finished initialization?
Definition: Manager.h:130
LorentShiftHierarchy & getLorentzShiftHierarchy() const
Get the Lorentz shift hierarchy.
Definition: Manager.h:108
std::vector< EventMetaData > m_dbTimeSlicing
Vector of EventMetaData containing the time slicing of the calibration job.
Definition: Manager.h:142
void sortUniqueVector(std::vector< EventMetaData > &vec)
Sort vector of EventMetaData and make it unique to process user defined time splittings of the consta...
Definition: Manager.cc:190
std::unique_ptr< GlobalParamVector > m_globalVector
The global vector for unified access to DB constants.
Definition: Manager.h:137
int updateTimeDepGlobalLabels(const EventMetaData &event)
Update the current time ID in the GlobalLabel.
Definition: Manager.cc:196
static void initGlobalVector(GlobalParamVector &vector)
Initialize a given GlobalParamVector with all DB objects and interfaces.
Definition: Manager.cc:33
RigidBodyHierarchy & getAlignmentHierarchy() const
Get the rigid body alignment hierarchy.
Definition: Manager.h:106
alignment::timeline::TimeTable m_iniTimeTable
The initial time table generated from time intervals in GlobalLabel used to check if payload (labels)...
Definition: Manager.h:146
void buildConstraints(Constraints &constraints)
Adds constraints from current hierarchy to a constraints vector.
Definition: Hierarchy.cc:24

◆ preCollect()

void preCollect ( const EventMetaData emd)

Notice manager of a comming event (from MillepedeCollector)

Definition at line 98 of file Manager.cc.

99 {
100 // TODO Really?? Move elsewhere
101 // Add time slices when objects change automatically
102 /*
103 if (m_globalVector->hasBeenChangedInDB({}, false)) {
104 // Add time slices
105 m_dbTimeSlicing.push_back(EventMetaData(emd));
106 sortUniqueVector(m_dbTimeSlicing);
107
108 for (auto& handler : m_globalVector->getGlobalParamSets()) {
109 if (not handler.second->hasBeenChangedInDB(false))
110 continue;
111 //TODO listGlobalParams not fully implemented by DB objects
112 for (auto& params : handler.second->listGlobalParams()) {
113 GlobalLabel label;
114 label.construct(handler.second->getGlobalUniqueID(), params.first, params.second);
115 label.registerTimeDependent(GlobalLabel::getCurrentTimeInterval());
116 }
117 }
118 }
119 */
120
121 // Generate time id from current EventMetaData
122 // range for time dependent calibration consts
123 auto subrun = updateTimeDepGlobalLabels(emd);
124
125 // WARNING: TODO: This is actually a bug, but as we loop exactly over all timeline events
126 // to generate constraints in practice (separately from collection), it does not reveal itself
127 // usually (needs to have more runs in one job + also timdep cal. has be in effect)
128 // -> can't think of easy fix now -> rebuild constraints
129 // after each subrun change?
130 bool alignmentHierarchyChanged = false;
131 bool lorentzHierarchyChanged = false;
132 for (auto& uid : getAlignmentHierarchy().getUsedDBObjUniqueIDs()) {
133 if (alignment::timeline::getContinuousIndexByTimeID(m_iniTimeTable, uid, subrun) == 1) {
134 alignmentHierarchyChanged = true;
135 break;
136 }
137 }
138 for (auto& uid : getLorentzShiftHierarchy().getUsedDBObjUniqueIDs()) {
139 if (alignment::timeline::getContinuousIndexByTimeID(m_iniTimeTable, uid, subrun) == 1) {
140 lorentzHierarchyChanged = true;
141 break;
142 }
143 }
144
145 //TODO: this is now probably redundant. If time-dependence is not set, constraints coefficients will
146 // be just overriden...
147 if (m_globalVector->hasBeenChangedInDB(getAlignmentHierarchy().getUsedDBObjUniqueIDs(), false)) {
148 lorentzHierarchyChanged = true;
149 }
150 if (m_globalVector->hasBeenChangedInDB(getLorentzShiftHierarchy().getUsedDBObjUniqueIDs(), false)) {
151 lorentzHierarchyChanged = true;
152 }
153
154 // Update hierarchy and constraints if DB objects changed
155 if (alignmentHierarchyChanged) {
156 m_globalVector->postHierarchyChanged(getAlignmentHierarchy());
158 }
159 if (lorentzHierarchyChanged) {
160 m_globalVector->postHierarchyChanged(getLorentzShiftHierarchy());
162 }
163
164 // reset the hasBeenChanged state, ignore return value
165 // TODO move to postCollect()?
166 m_globalVector->hasBeenChangedInDB();
167 }

◆ sortUniqueVector()

void sortUniqueVector ( std::vector< EventMetaData > &  vec)

Sort vector of EventMetaData and make it unique to process user defined time splittings of the constants.

Definition at line 190 of file Manager.cc.

191 {
192 std::sort(vec.begin(), vec.end(), cmpEventMetaData);
193 vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
194 }
std::function< bool(const EventMetaData &, const EventMetaData &)> cmpEventMetaData
Comparison function for EventMetaData.
Definition: Manager.h:57

◆ updateTimeDepGlobalLabels()

int updateTimeDepGlobalLabels ( const EventMetaData event)
private

Update the current time ID in the GlobalLabel.

Parameters
eventcurrent event EventMetaData - generated time ID will be the index of the smallest slice larger than (or. equal) to EventMetaData

Definition at line 196 of file Manager.cc.

197 {
198 //sortUniqueVector(m_dbTimeSlicing);
199
200 if (m_dbTimeSlicing.empty()) {
202 return 0;
203 }
204
205 for (unsigned int index = 0; index < m_dbTimeSlicing.size() - 1; ++index) {
206 if (event == m_dbTimeSlicing[index + 1]) {
208 return index + 1;
209 }
210 if (cmpEventMetaData(event, m_dbTimeSlicing[index + 1])) {
212 return index;
213 }
214 }
215
217 return m_dbTimeSlicing.size() - 1;
218 }
static void setCurrentTimeInterval(gidTYPE time)
Sets current time id.
Definition: GlobalLabel.h:207

◆ writeConstraints()

void writeConstraints ( std::string  txtFilename)

Write-out complete hierarchy to a text file.

Definition at line 169 of file Manager.cc.

170 {
171 std::ofstream txt(txtFilename);
172 // Last update before write-out
173 m_alignment->buildConstraints(m_constraints);
174 m_lorentzShift->buildConstraints(m_constraints);
175 for (auto& name_elements : m_constraints) {
176 auto name = name_elements.first;
177 if (!name) continue;
178
179 txt << "Constraint 0. ! Constraint for global label: " << name << std::endl;
180 auto& elements = name_elements.second;
181 for (auto& label_coefficient : elements) {
182 auto label = label_coefficient.first;
183 auto coeff = label_coefficient.second;
184 txt << label << " " << coeff << std::endl;
185 }
186 txt << std::endl << std::endl;
187 }
188 }

Member Data Documentation

◆ cmpEventMetaData

std::function<bool(const EventMetaData&, const EventMetaData&)> cmpEventMetaData
Initial value:
= [](const EventMetaData& lhs,
const EventMetaData& rhs) -> bool {
if (lhs.getExperiment() < rhs.getExperiment()) return true;
if (lhs.getExperiment() > rhs.getExperiment()) return false;
if (lhs.getRun() < rhs.getRun()) return true;
if (lhs.getRun() > rhs.getRun()) return false;
if (lhs.getEvent() < rhs.getEvent()) return true;
return false;
}

Comparison function for EventMetaData.

Definition at line 57 of file Manager.h.

◆ m_alignment

std::unique_ptr<RigidBodyHierarchy> m_alignment {new RigidBodyHierarchy()}
private

The alignment hierarchy.

Definition at line 133 of file Manager.h.

◆ m_constraints

std::map<long, Constraint> m_constraints {}
private

Map of constraints {unique label, labels and coefficients}.

Definition at line 139 of file Manager.h.

◆ m_dbTimeSlicing

std::vector<EventMetaData> m_dbTimeSlicing {}
private

Vector of EventMetaData containing the time slicing of the calibration job.

Definition at line 142 of file Manager.h.

◆ m_globalVector

std::unique_ptr<GlobalParamVector> m_globalVector {new GlobalParamVector()}
private

The global vector for unified access to DB constants.

Definition at line 137 of file Manager.h.

◆ m_initialized

bool m_initialized {false}
private

Finished initialization?

Definition at line 130 of file Manager.h.

◆ m_iniTimeTable

alignment::timeline::TimeTable m_iniTimeTable {}
private

The initial time table generated from time intervals in GlobalLabel used to check if payload (labels) can change and update the hierarchy if so.

Definition at line 146 of file Manager.h.

◆ m_lorentzShift

std::unique_ptr<LorentShiftHierarchy> m_lorentzShift {new LorentShiftHierarchy()}
private

Hierarchy for Lorentz shift corrections.

Definition at line 135 of file Manager.h.


The documentation for this class was generated from the following files: