Belle II Software  release-05-02-19
SVDOccupancyAnalysisModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2011 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributor: Giulia Casarosa *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <svd/modules/svdPerformance/SVDOccupancyAnalysisModule.h>
12 #include <hlt/softwaretrigger/core/FinalTriggerDecisionCalculator.h>
13 
14 #include <TMath.h>
15 
16 using namespace std;
17 using namespace Belle2;
18 using namespace SoftwareTrigger;
19 
20 REG_MODULE(SVDOccupancyAnalysis)
21 
22 SVDOccupancyAnalysisModule::SVDOccupancyAnalysisModule() : Module()
23 {
24 
25  setDescription("This module check performances of SVD reconstruction of VXD TB data");
26 
27  addParam("outputFileName", m_rootFileName, "Name of output root file.", std::string("SVDOccupancyAnalysis_output.root"));
28 
29  addParam("skipHLTRejectedEvents", m_skipRejectedEvents, "If TRUE skip events rejected by HLT", bool(false));
30  addParam("groupNevents", m_group, "Number of events to group", float(10000));
31  addParam("FADCmode", m_FADCmode,
32  "FADC mode: if true the approximation to integer is done", bool(false));
33  addParam("minZScut", m_minZS, "Minimum ZS cut", float(3));
34  addParam("maxZScut", m_maxZS, "Maximum ZS cut", float(6));
35  addParam("pointsZScut", m_pointsZS, "Number of ZS cuts", int(8));
36 
37  addParam("ShaperDigitsName", m_ShaperDigitName, "Name of ShaperDigit Store Array.", std::string(""));
38 }
39 
40 SVDOccupancyAnalysisModule::~SVDOccupancyAnalysisModule()
41 {
42 
43 }
44 
46 {
47 
48  m_eventMetaData.isRequired();
49  m_svdShapers.isRequired(m_ShaperDigitName);
50  B2INFO(" ShaperDigits: " << m_ShaperDigitName);
51 
52  m_rootFilePtr = new TFile(m_rootFileName.c_str(), "RECREATE");
53 
54  m_nEvents = 0;
55 
56 }
57 
58 
60 {
61 
62 
63  m_occ_L3U = new TH1F("occL3U", "Occupancy Distribution for L3 U side", m_distr_Nbins, m_distr_min, m_distr_max);
64  m_occ_L3U->GetXaxis()->SetTitle("occupancy(%)");
65  m_occ_L3V = new TH1F("occL3V", "Occupancy Distribution for L3 V side", m_distr_Nbins, m_distr_min, m_distr_max);
66  m_occ_L3V->GetXaxis()->SetTitle("occupancy(%)");
67  m_occ_L4U = new TH1F("occL4U", "Occupancy Distribution for L4 U side", m_distr_Nbins, m_distr_min, m_distr_max);
68  m_occ_L4U->GetXaxis()->SetTitle("occupancy(%)");
69  m_occ_L4V = new TH1F("occL4V", "Occupancy Distribution for L4 V side", m_distr_Nbins, m_distr_min, m_distr_max);
70  m_occ_L4V->GetXaxis()->SetTitle("occupancy(%)");
71  m_occ_L5U = new TH1F("occL5U", "Occupancy Distribution for L5 U side", m_distr_Nbins, m_distr_min, m_distr_max);
72  m_occ_L5U->GetXaxis()->SetTitle("occupancy(%)");
73  m_occ_L5V = new TH1F("occL5V", "Occupancy Distribution for L5 V side", m_distr_Nbins, m_distr_min, m_distr_max);
74  m_occ_L5V->GetXaxis()->SetTitle("occupancy(%)");
75  m_occ_L6U = new TH1F("occL6U", "Occupancy Distribution for L6 U side", m_distr_Nbins, m_distr_min, m_distr_max);
76  m_occ_L6U->GetXaxis()->SetTitle("occupancy(%)");
77  m_occ_L6V = new TH1F("occL6V", "Occupancy Distribution for L6 V side", m_distr_Nbins, m_distr_min, m_distr_max);
78  m_occ_L6V->GetXaxis()->SetTitle("occupancy(%)");
79 
80 
82 
83  //collect the list of all SVD Modules in the geometry here
84  std::vector<VxdID> sensors = geo.getListOfSensors();
85  for (VxdID& aVxdID : sensors) {
86  VXD::SensorInfoBase info = geo.getSensorInfo(aVxdID);
87  if (info.getType() != VXD::SensorInfoBase::SVD) continue;
88  m_SVDModules.push_back(aVxdID); // reorder, sort would be better
89  }
90  std::sort(m_SVDModules.begin(), m_SVDModules.end()); // back to natural order
91 
92  m_hit = new SVDSummaryPlots("hits@view", "Number of hits on @view/@side Side");
93 
94  TH1F h_dist("dist_L@layerL@ladderS@sensor@view",
95  "Occupancy Distribution (layer @layer, ladder @ladder, sensor @sensor, side@view/@side)",
97  h_dist.GetXaxis()->SetTitle("occupancy (%)");
98  m_histo_dist = new SVDHistograms<TH1F>(h_dist);
99 
100  TH1F h_occ_768("occ768_L@layerL@ladderS@sensor@view", "Occupancy (layer @layer, ladder @ladder, sensor @sensor, side@view/@side)",
101  768, 0, 768);
102  h_occ_768.GetXaxis()->SetTitle("cellID");
103  TH1F h_occ_512("occ512_L@layerL@ladderS@sensor@view", "Occupancy (layer @layer, ladder @ladder, sensor @sensor, side@view/@side)",
104  512, 0, 512);
105  h_occ_512.GetXaxis()->SetTitle("cellID");
106  m_histo_occ = new SVDHistograms<TH1F>(h_occ_768, h_occ_768, h_occ_768, h_occ_512);
107 
108 
109  TH1F h_zsVSocc("occVSzs_L@layerL@ladderS@sensor@view",
110  "Average Occupancy VS Zero Suppression (layer @layer, ladder @ladder, sensor @sensor, side@view/@side)", m_pointsZS, m_minZS,
111  m_maxZS);
112  h_zsVSocc.GetXaxis()->SetTitle("ZS cut");
113  m_histo_zsOcc = new SVDHistograms<TH1F>(h_zsVSocc);
114 
115 
116  TH1F h_zsVSoccSQ("zsVSoccSQ_L@layerL@ladderS@sensor@view",
117  "Average Occupancy VS (ZS cut)^2 (layer @layer, ladder @ladder, sensor @sensor, side@view/@side)", 100, TMath::Power(m_minZS,
118  2) - 5, TMath::Power(m_maxZS, 2));
119  h_zsVSoccSQ.GetXaxis()->SetTitle("(ZS cut)^2");
120  m_histo_zsOccSQ = new SVDHistograms<TH1F>(h_zsVSoccSQ);
121 
122 
123  TH2F h_occtdep_768("occ768VSevt_L@layerL@ladderS@sensor@view",
124  "Average Occupancy VS Event Number (layer @layer, ladder @ladder, sensor @sensor, side@view/@side)",
125  1000, 0, 1000, 768, 0, 768);
126  h_occtdep_768.GetXaxis()->SetTitle(Form("evt number/%1.0f", m_group));
127  h_occtdep_768.GetYaxis()->SetTitle("cellID");
128 
129  TH2F h_occtdep_512("occ512VSevt_L@layerL@ladderS@sensor@view",
130  "Average Occupancy VS Event Number (layer @layer, ladder @ladder, sensor @sensor, side@view/@side)",
131  1000, 0, 1000, 512, 0, 512);
132  h_occtdep_512.GetXaxis()->SetTitle(Form("evt number/%1.0f", m_group));
133  h_occtdep_512.GetYaxis()->SetTitle("cellID");
134 
135  m_histo_occtdep = new SVDHistograms<TH2F>(h_occtdep_768, h_occtdep_768, h_occtdep_768, h_occtdep_512);
136 
137 }
138 
140 {
141 
143  const bool eventAccepted = FinalTriggerDecisionCalculator::getFinalTriggerDecision(*m_resultStoreObjectPointer);
144  if (!eventAccepted) return;
145  }
146 
147  m_nEvents++;
148  int nEvent = m_eventMetaData->getEvent();
149 
150  //shaper digits
151  for (int digi = 0 ; digi < m_svdShapers.getEntries(); digi++) {
152 
153 
154  VxdID::baseType theVxdID = (VxdID::baseType)m_svdShapers[digi]->getSensorID();
155  int side = m_svdShapers[digi]->isUStrip();
156 
157  //fill standard occupancy plot, for default zero suppression
158  m_histo_occtdep->fill(theVxdID, side, nEvent / m_group, m_svdShapers[digi]->getCellID());
159 
160  m_hit->fill(theVxdID, side, 1);
161 
162  m_histo_occ->fill(theVxdID, side, m_svdShapers[digi]->getCellID());
163 
164  float noise = m_NoiseCal.getNoise(theVxdID, side, m_svdShapers[digi]->getCellID());
165  float step = (m_maxZS - m_minZS) / m_pointsZS;
166 
167  for (int z = 0; z <= m_pointsZS; z++) {
168  int nOKSamples = 0;
169  float cutMinSignal = (m_minZS + step * z) * noise;
170 
171  if (m_FADCmode) {
172  cutMinSignal = cutMinSignal + 0.5;
173  cutMinSignal = (int)cutMinSignal;
174  }
175 
176 
177  Belle2::SVDShaperDigit::APVFloatSamples samples_vec = m_svdShapers[digi]->getSamples();
178 
179  for (int k = 0; k < 6; k ++)
180  if (samples_vec[k] > cutMinSignal)
181  nOKSamples++;
182 
183  if (nOKSamples > 0) {
184  m_histo_zsOcc->fill(theVxdID, side, m_minZS + z * step);
185  m_histo_zsOccSQ->fill(theVxdID, side, TMath::Power(m_minZS + z * step, 2));
186  }
187  }
188 
189  }
190 
191  //loop on sensors, fill and clear
192  for (unsigned int i = 0; i < m_SVDModules.size(); i++) {
193  B2DEBUG(10, "module " << i << "," << m_SVDModules[i]);
194  float nStripsV = 512;
195  if (m_SVDModules[i].getLayerNumber() == 3)
196  nStripsV = 768;
197 
198  double occU = 100. * m_hit->getValue(m_SVDModules[i], 1) / 768;
199  double occV = 100. * m_hit->getValue(m_SVDModules[i], 0) / nStripsV;
200 
201  m_histo_dist->fill(m_SVDModules[i], 1, occU);
202  m_histo_dist->fill(m_SVDModules[i], 0, occV);
203 
204  if (m_SVDModules[i].getLayerNumber() == 3) {
205  m_occ_L3U->Fill(occU);
206  m_occ_L3V->Fill(occV);
207  }
208  if (m_SVDModules[i].getLayerNumber() == 4) {
209  m_occ_L4U->Fill(occU);
210  m_occ_L4V->Fill(occV);
211  }
212  if (m_SVDModules[i].getLayerNumber() == 5) {
213  m_occ_L5U->Fill(occU);
214  m_occ_L5V->Fill(occV);
215  }
216  if (m_SVDModules[i].getLayerNumber() == 6) {
217  m_occ_L6U->Fill(occU);
218  m_occ_L6V->Fill(occV);
219  }
220 
221  }
222 
223  (m_hit->getHistogram(0))->Reset();
224  (m_hit->getHistogram(1))->Reset();
225 
226 }
227 
228 
230 {
231 
232 }
233 
234 
236 {
237 
238  if (m_rootFilePtr != NULL) {
239  m_rootFilePtr->cd();
240 
241  TDirectory* oldDir = gDirectory;
242 
243  m_occ_L3U->Write();
244  m_occ_L3V->Write();
245  m_occ_L4U->Write();
246  m_occ_L4V->Write();
247  m_occ_L5U->Write();
248  m_occ_L5V->Write();
249  m_occ_L6U->Write();
250  m_occ_L6V->Write();
251 
253 
254  for (auto layer : geoCache.getLayers(VXD::SensorInfoBase::SVD)) {
255  TString layerName = Form("occupancyL%d", layer.getLayerNumber());
256  TDirectory* dir_layer = oldDir->mkdir(layerName.Data());
257  dir_layer->cd();
258  for (auto ladder : geoCache.getLadders(layer))
259  for (Belle2::VxdID sensor : geoCache.getSensors(ladder))
260  for (int view = SVDHistograms<TH1F>::VIndex ; view < SVDHistograms<TH1F>::UIndex + 1; view++) {
261  (m_histo_dist->getHistogram(sensor, view))->Write();
262 
263  (m_histo_occ->getHistogram(sensor, view))->Scale(1. / m_nEvents);
264  (m_histo_occ->getHistogram(sensor, view))->Write();
265 
266  int nStrips = 768;
267  if (sensor.getLayerNumber() != 3 && view == SVDHistograms<TH1F>::VIndex)
268  nStrips = 512;
269 
270  (m_histo_zsOcc->getHistogram(sensor, view))->Scale(1. / m_nEvents / nStrips);
271  (m_histo_zsOcc->getHistogram(sensor, view))->Write();
272  (m_histo_zsOccSQ->getHistogram(sensor, view))->Scale(1. / m_nEvents / nStrips);
273  (m_histo_zsOccSQ->getHistogram(sensor, view))->Write();
274 
275  (m_histo_occtdep->getHistogram(sensor, view))->Scale(1. / m_group);
276  (m_histo_occtdep->getHistogram(sensor, view))->Write();
277  }
278  }
279 
280  m_rootFilePtr->Close();
281 
282  }
283 }
284 
285 
Belle2::SVDMaxStripTTreeModule::m_skipRejectedEvents
bool m_skipRejectedEvents
if true skip events rejected by HLT
Definition: SVDMaxStripTTreeModule.h:59
Belle2::SVDOccupancyAnalysisModule::m_skipRejectedEvents
bool m_skipRejectedEvents
if true skip events rejected by HLT
Definition: SVDOccupancyAnalysisModule.h:83
Belle2::SVDOccupancyAnalysisModule::m_SVDModules
std::vector< VxdID > m_SVDModules
IDs of all SVD Modules to iterate over.
Definition: SVDOccupancyAnalysisModule.h:93
Belle2::SVDOccupancyAnalysisModule::m_distr_max
float m_distr_max
max of occupancy distributions
Definition: SVDOccupancyAnalysisModule.h:98
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::SVDOccupancyAnalysisModule::m_ShaperDigitName
std::string m_ShaperDigitName
ShaperDigit StoreArray name.
Definition: SVDOccupancyAnalysisModule.h:68
Belle2::SVDOccupancyAnalysisModule::m_group
float m_group
number of events to comput occupancy for occ VS time
Definition: SVDOccupancyAnalysisModule.h:73
Belle2::SVDHistograms< TH1F >
Belle2::Module::setDescription
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:216
Belle2::SVDOccupancyAnalysisModule::m_svdShapers
StoreArray< SVDShaperDigit > m_svdShapers
SVDShaperDigit StoreArray.
Definition: SVDOccupancyAnalysisModule.h:86
Belle2::SVDOccupancyAnalysisModule::m_occ_L4V
TH1F * m_occ_L4V
occupancy distribution for L4 V-side sensors
Definition: SVDOccupancyAnalysisModule.h:103
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::SVDOccupancyAnalysisModule::m_histo_dist
SVDHistograms< TH1F > * m_histo_dist
occupancy distribution histograms
Definition: SVDOccupancyAnalysisModule.h:111
Belle2::SVDSummaryPlots::getHistogram
TH2F * getHistogram(int view)
get a reference to the histogram for
Definition: SVDSummaryPlots.h:68
Belle2::SVDOccupancyAnalysisModule::m_resultStoreObjectPointer
StoreObjPtr< SoftwareTriggerResult > m_resultStoreObjectPointer
if true, ZS done with same algorithm as on FADC
Definition: SVDOccupancyAnalysisModule.h:82
Belle2::SVDOccupancyAnalysisModule::m_nEvents
int m_nEvents
number of events
Definition: SVDOccupancyAnalysisModule.h:85
Belle2::SVDOccupancyAnalysisModule::beginRun
virtual void beginRun() override
Called when entering a new run.
Definition: SVDOccupancyAnalysisModule.cc:59
Belle2::SVDOccupancyAnalysisModule::m_histo_occtdep
SVDHistograms< TH2F > * m_histo_occtdep
occupancy VS event number
Definition: SVDOccupancyAnalysisModule.h:115
Belle2::SVDOccupancyAnalysisModule::m_minZS
float m_minZS
minimum zero suppresion cut
Definition: SVDOccupancyAnalysisModule.h:74
Belle2::VXD::SensorInfoBase
Base class to provide Sensor Information for PXD and SVD.
Definition: SensorInfoBase.h:40
Belle2::SVDSummaryPlots::fill
void fill(int layer, int ladder, int sensor, int view, float value)
fill the histogram for
Definition: SVDSummaryPlots.h:101
Belle2::SVDOccupancyAnalysisModule::m_occ_L3U
TH1F * m_occ_L3U
occupancy distribution for L3 U-side sensors
Definition: SVDOccupancyAnalysisModule.h:100
Belle2::SVDOccupancyAnalysisModule::terminate
virtual void terminate() override
This method is called at the end of the event processing.
Definition: SVDOccupancyAnalysisModule.cc:229
Belle2::SVDOccupancyAnalysisModule::m_occ_L5V
TH1F * m_occ_L5V
occupancy distribution for L5 V-side sensors
Definition: SVDOccupancyAnalysisModule.h:105
Belle2::VXD::GeoCache::getListOfSensors
const std::vector< VxdID > getListOfSensors() const
Get list of all sensors.
Definition: GeoCache.cc:60
Belle2::SVDMaxStripTTreeModule::m_rootFileName
std::string m_rootFileName
root file name
Definition: SVDMaxStripTTreeModule.h:61
Belle2::SVDOccupancyAnalysisModule::m_histo_occ
SVDHistograms< TH1F > * m_histo_occ
occupancy histograms
Definition: SVDOccupancyAnalysisModule.h:112
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::SVDShaperDigit::APVFloatSamples
std::array< APVFloatSampleType, c_nAPVSamples > APVFloatSamples
array of APVFloatSampleType objects
Definition: SVDShaperDigit.h:63
Belle2::VxdID::baseType
unsigned short baseType
The base integer type for VxdID.
Definition: VxdID.h:46
Belle2::SVDOccupancyAnalysisModule::m_hit
SVDSummaryPlots * m_hit
hit number summary histogram
Definition: SVDOccupancyAnalysisModule.h:110
Belle2::SVDOccupancyAnalysisModule::m_occ_L5U
TH1F * m_occ_L5U
occupancy distribution for L5 U-side sensors
Definition: SVDOccupancyAnalysisModule.h:104
Belle2::SVDOccupancyAnalysisModule::m_rootFileName
std::string m_rootFileName
root file name
Definition: SVDOccupancyAnalysisModule.h:67
Belle2::SVDOccupancyAnalysisModule::event
virtual void event() override
This method is the core of the module.
Definition: SVDOccupancyAnalysisModule.cc:139
Belle2::VXD::GeoCache::getInstance
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:215
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SVDOccupancyAnalysisModule::m_occ_L4U
TH1F * m_occ_L4U
occupancy distribution for L4 U-side sensors
Definition: SVDOccupancyAnalysisModule.h:102
Belle2::SVDOccupancyAnalysisModule::m_distr_Nbins
float m_distr_Nbins
number of bins of occupancy distributions
Definition: SVDOccupancyAnalysisModule.h:96
Belle2::SVDOccupancyAnalysisModule::endRun
virtual void endRun() override
This method is called if the current run ends.
Definition: SVDOccupancyAnalysisModule.cc:235
Belle2::SVDOccupancyAnalysisModule::m_distr_min
float m_distr_min
min of occupancy distributions
Definition: SVDOccupancyAnalysisModule.h:97
Belle2::SVDOccupancyAnalysisModule::m_histo_zsOcc
SVDHistograms< TH1F > * m_histo_zsOcc
occupancy VS ZScut histograms
Definition: SVDOccupancyAnalysisModule.h:113
Belle2::VXD::SensorInfoBase::SVD
@ SVD
SVD Sensor.
Definition: SensorInfoBase.h:45
Belle2::SVDSummaryPlots
class to summarize SVD quantities per sensor and side
Definition: SVDSummaryPlots.h:35
Belle2::SVDOccupancyAnalysisModule::m_occ_L6U
TH1F * m_occ_L6U
occupancy distribution for L6 U-side sensors
Definition: SVDOccupancyAnalysisModule.h:106
Belle2::SVDHistograms::fill
void fill(const VxdID &vxdID, int view, Types ... args)
fill the histogram for
Definition: SVDHistograms.h:89
Belle2::SVDOccupancyAnalysisModule::m_pointsZS
int m_pointsZS
max zero suppression cut
Definition: SVDOccupancyAnalysisModule.h:76
Belle2::Module::addParam
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:562
Belle2::VXD::GeoCache
Class to faciliate easy access to sensor information of the VXD like coordinate transformations or pi...
Definition: GeoCache.h:41
Belle2::SVDNoiseCalibrations::getNoise
float getNoise(const VxdID &sensorID, const bool &isU, const unsigned short &strip) const
This is the method for getting the noise.
Definition: SVDNoiseCalibrations.h:71
Belle2::SVDHistograms::getHistogram
H * getHistogram(const VxdID &vxdID, int view)
get a reference to the histogram for
Definition: SVDHistograms.h:68
Belle2::SVDOccupancyAnalysisModule::m_occ_L6V
TH1F * m_occ_L6V
occupancy distribution for L6 V-side sensors
Definition: SVDOccupancyAnalysisModule.h:107
Belle2::SVDOccupancyAnalysisModule::m_rootFilePtr
TFile * m_rootFilePtr
pointer at root file used for storing histograms
Definition: SVDOccupancyAnalysisModule.h:71
Belle2::VXD::GeoCache::getSensorInfo
const SensorInfoBase & getSensorInfo(Belle2::VxdID id) const
Return a referecne to the SensorInfo of a given SensorID.
Definition: GeoCache.cc:68
Belle2::SVDOccupancyAnalysisModule::initialize
virtual void initialize() override
Initialize the Module.
Definition: SVDOccupancyAnalysisModule.cc:45
Belle2::SVDOccupancyAnalysisModule::m_histo_zsOccSQ
SVDHistograms< TH1F > * m_histo_zsOccSQ
occupancy VS ZS cut swuared histograms
Definition: SVDOccupancyAnalysisModule.h:114
Belle2::SVDOccupancyAnalysisModule::m_occ_L3V
TH1F * m_occ_L3V
occupancy distribution for L3 V-side sensors
Definition: SVDOccupancyAnalysisModule.h:101
Belle2::SVDOccupancyAnalysisModule::m_eventMetaData
StoreObjPtr< EventMetaData > m_eventMetaData
Event Meta Data StoreObjectPointer.
Definition: SVDOccupancyAnalysisModule.h:87
Belle2::SVDOccupancyAnalysisModule::m_NoiseCal
SVDNoiseCalibrations m_NoiseCal
SVDNoise calibrations db object.
Definition: SVDOccupancyAnalysisModule.h:89
Belle2::SVDSummaryPlots::getValue
float getValue(const VxdID &vxdID, int view)
get the value contained in the corresponding bin, given VxdID and view
Definition: SVDSummaryPlots.h:83