Belle II Software release-09-00-02
SVDDQMEfficiencyModule.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
9#include <svd/modules/svdDQM/SVDDQMEfficiencyModule.h>
10#include <hlt/softwaretrigger/core/FinalTriggerDecisionCalculator.h>
11#include <svd/dataobjects/SVDEventInfo.h>
12
13#include "TDirectory.h"
14
15using namespace Belle2;
16using namespace SoftwareTrigger;
17
18//-----------------------------------------------------------------
19// Register the Module
20//-----------------------------------------------------------------
21REG_MODULE(SVDDQMEfficiency);
22
23//-----------------------------------------------------------------
24// Implementation
25//-----------------------------------------------------------------
26
27SVDDQMEfficiencyModule::SVDDQMEfficiencyModule() : HistoModule(), m_geoCache(VXD::GeoCache::getInstance())
28{
29 // Set module properties
30 setDescription("Create basic histograms to compute the average sensor efficiency.");
31
32 // What exactly is needed for this to be true?
34
35 // Parameter definitions
36 addParam("Clusters", m_svdClustersName, "name of StoreArray with SVD cluster.", std::string(""));
37 addParam("Intercepts", m_interceptsName, "name of StoreArray with SVDIntercepts.", std::string(""));
38
39 addParam("histogramDirectoryName", m_histogramDirectoryName, "Name of the directory where histograms will be placed.",
40 std::string("SVDEfficiency"));
41
42 addParam("binsU", m_u_bins, "histogram bins in u direction.", int(4));
43 addParam("binsV", m_v_bins, "histogram bins in v direction.", int(6));
44
45
46 addParam("saveExpertHistos", m_saveExpertHistos, "if True, save additional histograms.", bool(false));
47
48 addParam("minSVDHits", m_minSVDHits, "Number of SVD hits required in a track to be considered.", 1u);
49 addParam("minCDCHits", m_minCDCHits, "Number of CDC hits required in a track to be considered.", 20u);
50
51 addParam("pValCut", m_pcut, "Set a cut on the track p-value.", double(0));
52 // addParam("d0Cut", m_d0cut, "|d0| smaller than the cut", double(0.5));
53 // addParam("z0Cut", m_z0cut, "|z0| smaller than the cut", double(2));
54
55 addParam("momCut", m_momCut, "Set a cut on the track momentum.", double(0));
56 addParam("ptCut", m_ptCut, "Set a cut on the track transverse momentum.", double(1));
57
58 addParam("fiducialU", m_fiducialU, "Fiducial Area, U direction.", float(0.5));
59 addParam("fiducialV", m_fiducialV, "Fiducial Area, V direction.", float(0.5));
60 addParam("maxHalfResidU", m_maxResidU, "half window for cluster search around intercept, U direction.", float(0.05));
61 addParam("maxHalfResidV", m_maxResidV, "half window for cluster search around intercept, V direction.", float(0.05));
62 addParam("useParamFromDB", m_useParamFromDB, "use SVDDQMPlotsConfiguration from DB", bool(true));
63 addParam("skipHLTRejectedEvents", m_skipRejectedEvents, "If True, skip events rejected by HLT.", bool(false));
64 addParam("samples3", m_3Samples, "if True 3 samples histograms analysis is performed", bool(false));
65}
66
67
69{
70 //calls the define histogram function
71 REG_HISTOGRAM;
72
73 //register the required arrays
74 //Register as optional so validation for cases where they are not available still succeeds, but module will not do any meaningful work without them
78
79}
80
81
83{
86 if (!eventAccepted) return;
87 }
88
89 if (!m_svdClusters.isValid()) {
90 B2INFO("SVDClusters array is missing, no SVD efficiencies");
91 return;
92 }
93 if (!m_intercepts.isValid()) {
94 B2INFO("SVDIntercepts array is missing, no SVD efficiencies");
95 return;
96 }
97
98 if (!m_recoTracks.isValid()) {
99 B2INFO("RecoTracks array is missing, no SVD efficiencies");
100 return;
101 }
102
103 std::string m_svdEventInfoName = "SVDEventInfo";
104 StoreObjPtr<SVDEventInfo> eventinfo(m_svdEventInfoName);
105
106 int nSamples = 0;
107 if (eventinfo.isValid())
108 nSamples = eventinfo->getNSamples();
109 else
110 return;
111
112 //intercepts
113 for (int inter = 0 ; inter < m_intercepts.getEntries(); inter++) {
114
115 if (!isGoodIntercept(m_intercepts[inter]))
116 continue;
117
118 B2DEBUG(10, "this intercept is related to a good track");
119
120 VxdID::baseType theVxdID = (VxdID::baseType)m_intercepts[inter]->getSensorID();
121 double coorU = m_intercepts[inter]->getCoorU();
122 double coorV = m_intercepts[inter]->getCoorV();
124 int cellU = info.getUCellID(coorU);
125 int cellV = info.getVCellID(coorV);
126
127 const VXD::SensorInfoBase& theSensorInfo = m_geoCache.getSensorInfo(theVxdID);
128 if (theSensorInfo.inside(coorU, coorV, -m_fiducialU, -m_fiducialV)) {
129
130 //This track should be on the sensor
132 m_h_track_hits[theVxdID]->Fill(cellU, cellV);
133
134 m_TrackHits->fill(theVxdID, 0, 1);
135 m_TrackHits->fill(theVxdID, 1, 1);
136
137 if (m_3Samples) {
138 if (nSamples == 3) {
139 m_TrackHits3Sample->fill(theVxdID, 0, 1);
140 m_TrackHits3Sample->fill(theVxdID, 1, 1);
141 } else {
142 m_TrackHits6Sample->fill(theVxdID, 0, 1);
143 m_TrackHits6Sample->fill(theVxdID, 1, 1);
144 }
145 }
146
147 bool foundU = false;
148 bool foundV = false;
149
150 //loop on clusters
151 for (int cls = 0 ; cls < m_svdClusters.getEntries(); cls++) {
152
153 VxdID::baseType clVxdID = (VxdID::baseType)m_svdClusters[cls]->getSensorID();
154 if (clVxdID != theVxdID)
155 continue;
156
157 double maxResid = m_maxResidV;
158 double interCoor = coorV;
159 double resid = interCoor - m_svdClusters[cls]->getPosition();
160 if (m_svdClusters[cls]->isUCluster()) {
161 interCoor = coorU;
162 maxResid = m_maxResidU;
163 resid = interCoor - m_svdClusters[cls]->getPosition(coorV);
164 }
165
166
167 if (abs(resid) < maxResid) {
168 if (m_svdClusters[cls]->isUCluster()) {
169 foundU = true;
170 } else
171 foundV = true;
172 }
173
174 if (foundU && foundV)
175 break;
176 }
177
178 if (foundU) {
179 m_MatchedHits->fill(theVxdID, 1, 1);
180 if (m_3Samples) {
181 if (nSamples == 3)
182 m_MatchedHits3Sample->fill(theVxdID, 1, 1);
183 else
184 m_MatchedHits6Sample->fill(theVxdID, 1, 1);
185 }
186
187 if (m_saveExpertHistos) {
188 m_h_matched_clusterU[theVxdID]->Fill(cellU, cellV);
189 if (m_3Samples) {
190 if (nSamples == 3)
191 m_h_matched3_clusterU[theVxdID]->Fill(cellU, cellV);
192 else
193 m_h_matched6_clusterU[theVxdID]->Fill(cellU, cellV);
194 }
195 }
196 }
197
198 if (foundV) {
199 m_MatchedHits->fill(theVxdID, 0, 1);
200 if (m_3Samples) {
201 if (nSamples == 3)
202 m_MatchedHits3Sample->fill(theVxdID, 0, 1);
203 else
204 m_MatchedHits6Sample->fill(theVxdID, 0, 1);
205 }
206
207 if (m_saveExpertHistos) {
208 m_h_matched_clusterV[theVxdID]->Fill(cellU, cellV);
209 if (m_3Samples) {
210 if (nSamples == 3)
211 m_h_matched3_clusterV[theVxdID]->Fill(cellU, cellV);
212 else
213 m_h_matched6_clusterV[theVxdID]->Fill(cellU, cellV);
214 }
215 }
216 }
217
218 }
219 }
220}
221
223{
224 if (m_useParamFromDB) {
225 if (!m_svdPlotsConfig.isValid())
226 B2FATAL("no valid configuration found for SVD reconstruction");
227 else {
228 B2DEBUG(20, "SVDRecoConfiguration: from now on we are using " << m_svdPlotsConfig->get_uniqueID());
229 m_3Samples = m_svdPlotsConfig->isPlotsFor3SampleMonitoring();
230 m_skipRejectedEvents = m_svdPlotsConfig->isSkipHLTRejectedEvents();
231 }
232 }
233
234 // Create a separate histogram directory and cd into it.
235 TDirectory* oldDir = gDirectory;
236 if (m_histogramDirectoryName != "") {
237 oldDir->mkdir(m_histogramDirectoryName.c_str());
238 oldDir->cd(m_histogramDirectoryName.c_str());
239 }
240 m_TrackHits = new SVDSummaryPlots("TrackHits@view", "Number of Tracks intercepting the @view/@side Side");
241 m_MatchedHits = new SVDSummaryPlots("MatchedHits@view", "Number of Matched Clusters on the @view/@side Side");
242
243 if (m_3Samples) {
244 m_TrackHits3Sample = new SVDSummaryPlots("TrackHits3@view", "Number of Tracks intercepting the @view/@side Side for 3 samples");
245 m_TrackHits6Sample = new SVDSummaryPlots("TrackHits6@view", "Number of Tracks intercepting the @view/@side Side for 6 samples");
246 m_MatchedHits3Sample = new SVDSummaryPlots("MatchedHits3@view", "Number of Matched Clusters on the @view/@side Side for 3 samples");
247 m_MatchedHits6Sample = new SVDSummaryPlots("MatchedHits6@view", "Number of Matched Clusters on the @view/@side Side for 6 samples");
248 }
249
250 if (!m_saveExpertHistos) {
251 oldDir->cd();
252 return;
253 }
254
255 std::vector<VxdID> sensors = m_geoCache.getListOfSensors();
256 for (VxdID& avxdid : sensors) {
258 if (info.getType() != VXD::SensorInfoBase::SVD) continue;
259 //Only interested in SVD sensors
260
261 TString buff = (std::string)avxdid;
262 buff.ReplaceAll(".", "_");
263
264 int nu = info.getUCells();
265 int nv = info.getVCells();
266
267 m_h_track_hits[avxdid] = new TH2D("track_hits_" + buff, "tracks through sensor " + buff,
268 m_u_bins, -0.5, nu - 0.5, m_v_bins, -0.5, nv - 0.5);
269 m_h_matched_clusterU[avxdid] = new TH2D("matched_clusterU_" + buff, "track intersections with a matched U cluster" + buff,
270 m_u_bins, -0.5, nu - 0.5, m_v_bins, -0.5, nv - 0.5);
271 m_h_matched_clusterV[avxdid] = new TH2D("matched_clusterV_" + buff, "track intersections with a matched V cluster" + buff,
272 m_u_bins, -0.5, nu - 0.5, m_v_bins, -0.5, nv - 0.5);
273
274 if (m_3Samples) {
275 m_h_matched3_clusterU[avxdid] = new TH2D("matched3_clusterU_" + buff,
276 "track intersections with a matched U cluster for 3 samples" + buff,
277 m_u_bins, -0.5, nu - 0.5, m_v_bins, -0.5, nv - 0.5);
278 m_h_matched3_clusterV[avxdid] = new TH2D("matched3_clusterV_" + buff,
279 "track intersections with a matched V cluster for 3 samples" + buff,
280 m_u_bins, -0.5, nu - 0.5, m_v_bins, -0.5, nv - 0.5);
281
282 m_h_matched6_clusterU[avxdid] = new TH2D("matched6_clusterU_" + buff,
283 "track intersections with a matched U cluster for 6 samples" + buff,
284 m_u_bins, -0.5, nu - 0.5, m_v_bins, -0.5, nv - 0.5);
285 m_h_matched6_clusterV[avxdid] = new TH2D("matched6_clusterV_" + buff,
286 "track intersections with a matched V cluster for 6 samples" + buff,
287 m_u_bins, -0.5, nu - 0.5, m_v_bins, -0.5, nv - 0.5);
288 }
289 }
290 // cd back to root directory
291 oldDir->cd();
292}
293
294
295
297{
298
299 RelationVector<RecoTrack> theRC = DataStore::getRelationsWithObj<RecoTrack>(inter);
300
301 if (theRC.size() == 0)
302 return false;
303
304 //If fit failed assume position pointed to is useless anyway
305 if (!theRC[0]->wasFitSuccessful()) return false;
306
307 if (theRC[0]->getNumberOfSVDHits() < m_minSVDHits) return false;
308
309 if (theRC[0]->getNumberOfCDCHits() < m_minCDCHits) return false;
310
311 const genfit::FitStatus* fitstatus = theRC[0]->getTrackFitStatus();
312 if (fitstatus->getPVal() < m_pcut) return false;
313
314 genfit::MeasuredStateOnPlane trackstate;
315 trackstate = theRC[0]->getMeasuredStateOnPlaneFromFirstHit();
316 if (trackstate.getMom().Mag() < m_momCut) return false;
317
318 if (trackstate.getMom().Perp() < m_ptCut) return false;
319
320 return true;
321
322}
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
float m_fiducialV
stay away from the U border by m_fiducialU (in cm)
bool m_useParamFromDB
if true read back from DB configuration parameters
SVDDQMEfficiencyModule()
Constructor: Sets the description, the properties and the parameters of the module.
std::string m_svdClustersName
SVDClusters StoreArray name.
std::map< VxdID, TH2D * > m_h_track_hits
track hits histogram map to sensorID
void initialize() override final
initializes the need store arrays, trees and histograms
unsigned int m_minCDCHits
Required hits in CDC for tracks.
bool m_saveExpertHistos
save additional histograms id set True
std::map< VxdID, TH2D * > m_h_matched6_clusterV
matched V-hits histogram map to sensorID for 6 samples
StoreArray< SVDIntercept > m_intercepts
SVDIntercept StoreArray.
bool m_skipRejectedEvents
if true skip events rejected by HLT
SVDSummaryPlots * m_MatchedHits3Sample
matched hits summary plot for 3 samples
VXD::GeoCache & m_geoCache
BelleII Geometry.
std::map< VxdID, TH2D * > m_h_matched3_clusterV
matched V-hits histogram map to sensorID for 3 samples
unsigned int m_minSVDHits
Required hits in SVD strips for tracks.
StoreArray< SVDCluster > m_svdClusters
SVDCluster StoreArray.
double m_momCut
Cut on fitted track momentum.
int m_u_bins
number of U-bins for expert histogram
std::map< VxdID, TH2D * > m_h_matched_clusterU
matched U-hits histogram map to sensorID
std::map< VxdID, TH2D * > m_h_matched6_clusterU
matched U-hits histogram map to sensorID for 6 samples
float m_fiducialU
stay away from the U border by m_fiducialU (in cm)
void defineHisto() override final
actually defines the trees and histograms
DBObjPtr< SVDDQMPlotsConfiguration > m_svdPlotsConfig
SVD DQM plots configuration.
double m_pcut
pValue-Cut for tracks
bool isGoodIntercept(SVDIntercept *inter)
returns true if the track related to the intercept passes the selection cuts
void event() override final
main function which fills trees and histograms
std::string m_histogramDirectoryName
name of the directory where to store the histograms
float m_maxResidV
max distance cut in cm V side
bool m_3Samples
if true enable 3 samples histograms analysis
SVDSummaryPlots * m_MatchedHits6Sample
matched hits summary plot for 6 samples
std::map< VxdID, TH2D * > m_h_matched3_clusterU
matched U-hits histogram map to sensorID for 3 samples
int m_v_bins
number of V-bins for expert histogram
SVDSummaryPlots * m_MatchedHits
matched hits summary plot
SVDSummaryPlots * m_TrackHits
track hits summary plot
StoreArray< RecoTrack > m_recoTracks
RecoTrack StoreArray.
double m_ptCut
Cut on fitted track pt.
StoreObjPtr< SoftwareTriggerResult > m_resultStoreObjectPointer
Store Object for reading the trigger decision.
std::string m_interceptsName
SVDIntercepts StoreArray name.
SVDSummaryPlots * m_TrackHits3Sample
track hits summary plot for 3 samples
std::map< VxdID, TH2D * > m_h_matched_clusterV
matched V-hits histogram map to sensorID
SVDSummaryPlots * m_TrackHits6Sample
track hits summary plot for 6 samples
float m_maxResidU
max distance cut in cm U side
SVDIntercept stores the U,V coordinates and uncertainties of the intersection of a track with an SVD ...
Definition: SVDIntercept.h:22
class to summarize SVD quantities per sensor and side
void fill(int layer, int ladder, int sensor, int view, float value)
fill the histogram for
static bool getFinalTriggerDecision(const SoftwareTriggerResult &result, bool forgetTotalResult=false)
Calculate the final cut decision using all "total_results" of all sub triggers in the software trigge...
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
bool isValid() const
Check wether the array was registered.
Definition: StoreArray.h:288
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
const std::vector< VxdID > getListOfSensors() const
Get list of all sensors.
Definition: GeoCache.cc:59
const SensorInfoBase & getSensorInfo(Belle2::VxdID id) const
Return a referecne to the SensorInfo of a given SensorID.
Definition: GeoCache.cc:67
Base class to provide Sensor Information for PXD and SVD.
bool inside(double u, double v, double uTolerance=DBL_EPSILON, double vTolerance=DBL_EPSILON) const
Check wether a given point is inside the active area.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
unsigned short baseType
The base integer type for VxdID.
Definition: VxdID.h:36
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.