Belle II Software  release-05-01-25
SVDOccupancyCalibrationsCollectorModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Laura Zani (2019) *
7  * *
8  * *
9  * This software is provided "as is" without any warranty. *
10  **************************************************************************/
11 #include <svd/modules/svdOccupancyCalibrationsCollector/SVDOccupancyCalibrationsCollectorModule.h>
12 
13 #include <TH2F.h>
14 
15 using namespace std;
16 using namespace Belle2;
17 
18 //-----------------------------------------------------------------
19 // Register the Module
20 //-----------------------------------------------------------------
21 REG_MODULE(SVDOccupancyCalibrationsCollector)
22 
23 //-----------------------------------------------------------------
24 // Implementation
25 //-----------------------------------------------------------------
26 
28 {
29  //Set module properties
30 
31  setDescription("This module collects hits from shaper digits to compute per sensor SVD occupancy ");
32  setPropertyFlags(c_ParallelProcessingCertified);
33 
34  addParam("SVDShaperDigitsName", m_svdShaperDigitName, "Name of the SVDClusters list", std::string("SVDShaperDigits"));
35 
36  addParam("HistogramTree", m_tree, "Name of the tree in which the histograms are saved", std::string("tree"));
37 }
38 
39 void SVDOccupancyCalibrationsCollectorModule::prepare()
40 {
41 
42  m_eventMetaData.isRequired();
43  m_storeDigits.isRequired(m_svdShaperDigitName);
44 
45  //create histograms
46 
47  TH1F hOccupancy768("Occupancy768_L@layerL@ladderS@sensor@view", "Strip Occupancy of @layer.@ladder.@sensor @view/@side side", 768,
48  0,
49  768);
50  hOccupancy768.GetXaxis()->SetTitle("cellID");
51  TH1F hOccupancy512("Occupancy512_L@layerL@ladderS@sensor@view", "Strip Occupancy of @layer.@ladder.@sensor @view/@side side", 512,
52  0,
53  512);
54  hOccupancy512.GetXaxis()->SetTitle("cellID");
55  hm_occupancy = new SVDHistograms<TH1F>(hOccupancy768, hOccupancy768, hOccupancy768, hOccupancy512);
56 
57  m_histogramTree = new TTree("tree", "tree");
58  m_histogramTree->Branch("hist", "TH1F", &m_hist, 32000, 0);
59  m_histogramTree->Branch("layer", &m_layer, "layer/I");
60  m_histogramTree->Branch("ladder", &m_ladder, "ladder/I");
61  m_histogramTree->Branch("sensor", &m_sensor, "sensor/I");
62  m_histogramTree->Branch("view", &m_side, "view/I");
63 
64  m_hnevents = new TH1F("hnevents", "Number of events", 1, 0, 1);
65 
66  //register objects needed to collect input to fill payloads
67  registerObject<TTree>("HTreeOccupancyCalib", m_histogramTree);
68 
69 }
70 
71 void SVDOccupancyCalibrationsCollectorModule::startRun()
72 {
73 
74  VXD::GeoCache& geoCache = VXD::GeoCache::getInstance();
75 
76  for (auto layer : geoCache.getLayers(VXD::SensorInfoBase::SVD)) {
77  for (auto ladder : geoCache.getLadders(layer)) {
78  for (Belle2::VxdID sensor : geoCache.getSensors(ladder)) {
79  for (int view = SVDHistograms<TH2F>::VIndex ; view < SVDHistograms<TH2F>::UIndex + 1; view++) {
80  // std::string s = std::string(sensor);
81  // std::string v = std::to_string(view);
82  // std::string name = string("eventT0vsCog_")+s+string("_")+v;
83  // registerObject<TH2F>(name.c_str(),hm_occupancy->getHistogram(sensor, view));
84  (hm_occupancy->getHistogram(sensor, view))->Reset();
85  }
86  }
87  }
88  }
89  m_hnevents->Reset();
90 
91 }
92 
93 
94 void SVDOccupancyCalibrationsCollectorModule::collect()
95 {
96 
97  int nDigits = m_storeDigits.getEntries();
98  m_hnevents->Fill(0.0); // check if HLT did not filter out the event (no rawSVD)
99 
100  if (nDigits == 0)
101  return;
102 
103  //loop over the SVDShaperDigits
104  int i = 0;
105  while (i < nDigits) {
106  VxdID theVxdID = m_storeDigits[i]->getSensorID();
107  int side = m_storeDigits[i]->isUStrip();
108  int CellID = m_storeDigits[i]->getCellID();
109 
110  hm_occupancy->fill(theVxdID, side, CellID);
111 
112  i++;
113  }
114 
115 
116 }
117 
118 void SVDOccupancyCalibrationsCollectorModule::finish()
119 {
120 }
121 
122 void SVDOccupancyCalibrationsCollectorModule::closeRun()
123 {
124 
125  int nevents = m_hnevents->GetEntries(); //number of events processed in events
126  //getObjectPtr<TH1F>("HNevents")->GetEntries(); //number of events processed in events
127 
128  B2RESULT("number of events " << nevents);
129 
130  VXD::GeoCache& aGeometry = VXD::GeoCache::getInstance();
131  std::set<Belle2::VxdID> svdLayers = aGeometry.getLayers(VXD::SensorInfoBase::SVD);
132  std::set<Belle2::VxdID>::iterator itSvdLayers = svdLayers.begin();
133  //int itsensor = 0; //sensor numbering
134  while ((itSvdLayers != svdLayers.end())
135  && (itSvdLayers->getLayerNumber() != 7)) { //loop on Layers
136 
137  std::set<Belle2::VxdID> svdLadders = aGeometry.getLadders(*itSvdLayers);
138  std::set<Belle2::VxdID>::iterator itSvdLadders = svdLadders.begin();
139 
140  while (itSvdLadders != svdLadders.end()) { //loop on Ladders
141 
142  std::set<Belle2::VxdID> svdSensors = aGeometry.getSensors(*itSvdLadders);
143  std::set<Belle2::VxdID>::iterator itSvdSensors = svdSensors.begin();
144 
145  while (itSvdSensors != svdSensors.end()) { //loop on sensors
146 
147  for (int k = 0; k < m_nSides; k ++) { //loop on Sides , k = isU(), k=0 is v-side, k=1 is u-side
148 
149  (hm_occupancy->getHistogram(*itSvdSensors, k))->Scale(1. / nevents);
150  B2INFO("occupancy histo scaled by the number of events");
151  m_hist = hm_occupancy->getHistogram(*itSvdSensors, k);
152  m_layer = itSvdSensors->getLayerNumber();
153  m_ladder = itSvdSensors->getLadderNumber();
154  m_sensor = itSvdSensors->getSensorNumber();
155  m_side = k;
156 
157  getObjectPtr<TTree>("HTreeOccupancyCalib")->Fill();
158  B2INFO("Filled sensors:" << m_layer << "." << m_ladder << "." << m_sensor << "." << m_side);
159  }
160  ++itSvdSensors;
161  }
162  ++itSvdLadders;
163  }
164  ++itSvdLayers;
165  }
166 
167 
168 }
Belle2::CalibrationCollectorModule
Calibration collector module base class.
Definition: CalibrationCollectorModule.h:44
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::SVDHistograms< TH1F >
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::VXD::GeoCache::getLayers
const std::set< Belle2::VxdID > getLayers(SensorInfoBase::SensorType sensortype=SensorInfoBase::VXD)
Return a set of all known Layers.
Definition: GeoCache.cc:177
Belle2::VXD::GeoCache::getSensors
const std::set< Belle2::VxdID > & getSensors(Belle2::VxdID ladder) const
Return a set of all sensor IDs belonging to a given ladder.
Definition: GeoCache.cc:205
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::VXD::GeoCache
Class to faciliate easy access to sensor information of the VXD like coordinate transformations or pi...
Definition: GeoCache.h:41
Belle2::VXD::GeoCache::getLadders
const std::set< Belle2::VxdID > & getLadders(Belle2::VxdID layer) const
Return a set of all ladder IDs belonging to a given layer.
Definition: GeoCache.cc:194
Belle2::SVDOccupancyCalibrationsCollectorModule
This This module collects hits from shaper digits to compute per sensor SVD occupancy using mu+mu- ev...
Definition: SVDOccupancyCalibrationsCollectorModule.h:46