Belle II Software  release-06-00-14
SVDB4CommissioningPlotsModule.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 <svd/modules/svdPerformance/SVDB4CommissioningPlotsModule.h>
9 #include <framework/datastore/RelationVector.h>
10 #include <time.h>
11 #include <mdst/dataobjects/HitPatternVXD.h>
12 #include <vxd/geometry/GeoCache.h>
13 
14 #include <boost/foreach.hpp>
15 
16 using namespace std;
17 using namespace Belle2;
18 
19 REG_MODULE(SVDB4CommissioningPlots)
20 
21 SVDB4CommissioningPlotsModule::SVDB4CommissioningPlotsModule() : Module()
22  , m_nTracks(0), m_Pvalue(), m_mom(0), m_nSVDhits(0)
23 {
24 
25  setDescription("This module check performances of SVD reconstruction on Commissioning data");
26 
27  addParam("outputFileName", m_rootFileName, "Name of output root file.", std::string("SVDB4CommissioningPlots_output.root"));
28 
29  addParam("RecoDigitsName", m_RecoDigitName, "Name of RecoDigit Store Array.", std::string("SVDRecoDigits"));
30  addParam("ClustersName", m_ClusterName, "Name of Cluster Store Array.", std::string("SVDClusters"));
31  addParam("TrackListName", m_TrackName, "Name of Track Store Array.", std::string("Tracks"));
32  addParam("TrackFitResultListName", m_TrackFitResultName, "Name of TracksFitResult Store Array.", std::string("TrackFitResults"));
33 }
34 
35 SVDB4CommissioningPlotsModule::~SVDB4CommissioningPlotsModule()
36 {
37 
38 }
39 
41 {
42 
43  m_svdRecos.isOptional(m_RecoDigitName);
45  m_Tracks.isOptional(m_TrackName);
46  m_recoTracks.isOptional();
47  m_tfr.isOptional(m_TrackFitResultName);
48 
49 
50  B2INFO(" RecoDigits: " << m_RecoDigitName);
51  B2INFO(" Clusters: " << m_ClusterName);
52  B2INFO(" Tracks: " << m_TrackName);
53  B2INFO(" TrackFitResults: " << m_TrackFitResultName);
54 
55 
56 
57  m_rootFilePtr = new TFile(m_rootFileName.c_str(), "RECREATE");
58 
59  m_ntracks = 0;
60 }
61 
63 {
64  m_nEvents = 0;
65 
66  //RECO DIGITS
67  TH1F hRecoCharge("reco_charge_L@layerL@ladderS@sensor@view",
68  "Charge of RecoDigits in @layer.@ladder.@sensor @view/@side side",
69  100, 0 , 1000);
70  hRecoCharge.GetXaxis()->SetTitle("charge (ke-)");
71  h_recoCharge = new SVDHistograms<TH1F>(hRecoCharge);
72 
73  TH1F hRecoEnergy("reco_energy_L@layerL@ladderS@sensor@view",
74  "Energy of RecoDigits in @layer.@ladder.@sensor @view/@side side",
75  100, 0 , 360);
76  hRecoEnergy.GetXaxis()->SetTitle("energy (keV)");
77  h_recoEnergy = new SVDHistograms<TH1F>(hRecoEnergy);
78 
79  TH1F hRecoTime("reco_time_L@layerL@ladderS@sensor@view",
80  "Time of RecoDigits in @layer.@ladder.@sensor @view/@side side",
81  200, -100 , 100);
82  hRecoTime.GetXaxis()->SetTitle("time (ns)");
83  h_recoTime = new SVDHistograms<TH1F>(hRecoTime);
84 
85  TH1F hRecoNoise("reco_noise_L@layerL@ladderS@sensor@view",
86  "Noise of RecoDigits in @layer.@ladder.@sensor @view/@side side",
87  200, 300 , 1800);
88  hRecoNoise.GetXaxis()->SetTitle("strip noise (e-)");
89  h_recoNoise = new SVDHistograms<TH1F>(hRecoNoise);
90 
91  //CLUSTER NOT RELATED TO TRACKS
92  TH1F hClusterCharge("cluster_charge_L@layerL@ladderS@sensor@view",
93  "Charge of Clusters in @layer.@ladder.@sensor @view/@side side",
94  100, 0 , 100);
95  hClusterCharge.GetXaxis()->SetTitle("charge (ke-)");
96  h_clusterCharge = new SVDHistograms<TH1F>(hClusterCharge);
97 
98  TH1F hClusterSize("cluster_size_L@layerL@ladderS@sensor@view",
99  "Clusters Size for @layer.@ladder.@sensor @view/@side side",
100  20, 0 , 20);
101  hClusterSize.GetXaxis()->SetTitle("cluster size");
102  h_clusterSize = new SVDHistograms<TH1F>(hClusterSize);
103 
104  TH1F hClusterSNR("cluster_SNR_L@layerL@ladderS@sensor@view",
105  "SNR of Clusters in @layer.@ladder.@sensor @view/@side side",
106  100, 0 , 140);
107  hClusterSNR.GetXaxis()->SetTitle("SNR");
108  h_clusterSNR = new SVDHistograms<TH1F>(hClusterSNR);
109 
110  TH1F hClusterEnergy("cluster_energy_L@layerL@ladderS@sensor@view",
111  "Energy of Clusters in @layer.@ladder.@sensor @view/@side side",
112  100, 0 , 360);
113  hClusterEnergy.GetXaxis()->SetTitle("energy (keV)");
114  h_clusterEnergy = new SVDHistograms<TH1F>(hClusterEnergy);
115 
116  TH1F hClusterTime("cluster_time_L@layerL@ladderS@sensor@view",
117  "Time of Clusters in @layer.@ladder.@sensor @view/@side side",
118  200, -100 , 100);
119  hClusterTime.GetXaxis()->SetTitle("time (ns)");
120  h_clusterTime = new SVDHistograms<TH1F>(hClusterTime);
121 
122  //CLUSTER RELATED TO TRACKS
123  TH1F hClusterTrkCharge("clusterTrk_charge_L@layerL@ladderS@sensor@view",
124  "Charge of Clusters Related to Tracks in @layer.@ladder.@sensor @view/@side side",
125  100, 0 , 100);
126  hClusterTrkCharge.GetXaxis()->SetTitle("charge (ke-)");
127  h_clusterTrkCharge = new SVDHistograms<TH1F>(hClusterTrkCharge);
128 
129  TH1F hClusterTrkSize("clusterTrk_size_L@layerL@ladderS@sensor@view",
130  "Cluster Size for @layer.@ladder.@sensor @view/@side side",
131  20, 0 , 20);
132  hClusterTrkSize.GetXaxis()->SetTitle("cluster size");
133  h_clusterTrkSize = new SVDHistograms<TH1F>(hClusterTrkSize);
134 
135  TH1F hClusterTrkSNR("clusterTrk_SNR_L@layerL@ladderS@sensor@view",
136  "SNR of Clusters Related to Tracks in @layer.@ladder.@sensor @view/@side side",
137  100, 0 , 140);
138  hClusterTrkSNR.GetXaxis()->SetTitle("SNR");
139  h_clusterTrkSNR = new SVDHistograms<TH1F>(hClusterTrkSNR);
140 
141  TH1F hClusterTrkEnergy("clusterTrk_energy_L@layerL@ladderS@sensor@view",
142  "Energy of Clusters Related to Tracks in @layer.@ladder.@sensor @view/@side side",
143  100, 0 , 360);
144  hClusterTrkEnergy.GetXaxis()->SetTitle("energy (keV)");
145  h_clusterTrkEnergy = new SVDHistograms<TH1F>(hClusterTrkEnergy);
146 
147  TH1F hClusterTrkTime("clusterTrk_time_L@layerL@ladderS@sensor@view",
148  "Time of Clusters Related to Tracks in @layer.@ladder.@sensor @view/@side side",
149  200, -100 , 100);
150  hClusterTrkTime.GetXaxis()->SetTitle("time (ns)");
151  h_clusterTrkTime = new SVDHistograms<TH1F>(hClusterTrkTime);
152 
153  TH1F hClusterTrkInterstripPos("clusterTrk_interstripPos_L@layerL@ladderS@sensor@view",
154  "Interstrip Position of Clusters Related to Tracks in @layer.@ladder.@sensor @view/@side side",
155  400, 0 , 1);
156  hClusterTrkInterstripPos.GetXaxis()->SetTitle("interstrip position");
157  h_clusterTrkInterstripPos = new SVDHistograms<TH1F>(hClusterTrkInterstripPos);
158 
159  //tracks
160  m_nTracks = new TH1F("h1nTracks", "number of Tracks per event", 50, 0, 50);
161  m_nTracks->GetXaxis()->SetTitle("n Tracks");
162  m_Pvalue = new TH1F("h1pValue", "Tracks p value", 100, 0, 1);
163  m_Pvalue->GetXaxis()->SetTitle("p value");
164  m_mom = new TH1F("h1momentum", " Tracks Momentum", 200, 0, 10);
165  m_mom->GetXaxis()->SetTitle("p (GeV/c)");
166  m_nSVDhits = new TH1F("h1nSVDhits", "# SVD hits per track", 20, 0, 20);
167  m_nSVDhits->GetXaxis()->SetTitle("# SVD hits");
168 
169 
170 }
171 
173 {
174 
175  // StoreObjPtr<EventMetaData> eventMD;
176 
177  m_nEvents++;
178  float c_eTOkeV = 3.6 / 1000; //keV = e * c_eTOkeV
179 
180  //tracks
181  if (m_Tracks) {
182  m_nTracks->Fill(m_Tracks.getEntries());
183  m_ntracks += m_Tracks.getEntries();
184  }
185  BOOST_FOREACH(Track & track, m_Tracks) {
186 
187  const TrackFitResult* tfr = track.getTrackFitResultWithClosestMass(Const::pion);
188  if (tfr) {
189  m_Pvalue->Fill(tfr->getPValue());
190  m_mom->Fill(tfr->getMomentum().Mag());
191  m_nSVDhits->Fill((tfr->getHitPatternVXD()).getNSVDHits());
192  }
193 
194  RelationVector<RecoTrack> theRC = DataStore::getRelationsWithObj<RecoTrack>(&track);
195  RelationVector<SVDCluster> svdClustersTrack = DataStore::getRelationsWithObj<SVDCluster>(theRC[0]);
196 
197  for (int cl = 0 ; cl < (int)svdClustersTrack.size(); cl++) {
198 
199  float clCharge = svdClustersTrack[cl]->getCharge();
200  float clEnergy = svdClustersTrack[cl]->getCharge() * c_eTOkeV;
201  int clSize = svdClustersTrack[cl]->getSize();
202  float clSN = svdClustersTrack[cl]->getSNR();
203  float clTime = svdClustersTrack[cl]->getClsTime();
204  float clPosition = svdClustersTrack[cl]->getPosition();
205  VxdID::baseType theVxdID = (VxdID::baseType)svdClustersTrack[cl]->getSensorID();
206  int side = svdClustersTrack[cl]->isUCluster();
207 
208  const VXD::SensorInfoBase* aSensorInfo = &VXD::GeoCache::getInstance().getSensorInfo(theVxdID);
209  float pitch = aSensorInfo->getVPitch();
210  if (side == 1)
211  pitch = aSensorInfo->getUPitch();
212  float clInterstripPos = fmod(clPosition, pitch) / pitch;
213 
214  h_clusterTrkCharge->fill(theVxdID, side, clCharge / 1000.);
215  h_clusterTrkSize->fill(theVxdID, side, clSize);
216  h_clusterTrkSNR->fill(theVxdID, side, clSN);
217  h_clusterTrkEnergy->fill(theVxdID, side, clEnergy);
218  h_clusterTrkTime->fill(theVxdID, side, clTime);
219  h_clusterTrkInterstripPos->fill(theVxdID, side, clInterstripPos);
220 
221  // if(svdClustersTrack.size()%2 != 0)
222  // B2INFO(" Event Number = "<<eventMD->getEvent()<<" "<<theVxdID<<"."<<side<<" position = "<<svdClustersTrack[cl]->getPosition()<<" charge = "<<svdClustersTrack[cl]->getCharge());
223 
224  }
225  }
226 
227  if (m_Tracks)
228  B2DEBUG(1, "%%%%%%%% NEW EVENT, number of Tracks = " << m_Tracks.getEntries());
229 
230 
231  //reco digits
232  if (m_svdRecos.isValid()) {
233  for (int digi = 0 ; digi < m_svdRecos.getEntries(); digi++) {
234 
235  VxdID::baseType theVxdID = (VxdID::baseType)m_svdRecos[digi]->getSensorID();
236  int side = m_svdRecos[digi]->isUStrip();
237  int cellID = m_svdRecos[digi]->getCellID();
238 
239  float thisNoise = m_NoiseCal.getNoiseInElectrons(theVxdID, side, cellID);
240 
241  h_recoNoise->fill(theVxdID, side, thisNoise);
242  h_recoCharge->fill(theVxdID, side, m_svdRecos[digi]->getCharge() / 1000.);
243  h_recoEnergy->fill(theVxdID, side, m_svdRecos[digi]->getCharge()*c_eTOkeV);
244  h_recoTime->fill(theVxdID, side, m_svdRecos[digi]->getTime());
245  }
246  }
247 
248  //clusters NOT related to tracks
249  for (int cl = 0 ; cl < m_svdClusters.getEntries(); cl++) {
250 
251  float clCharge = m_svdClusters[cl]->getCharge();
252  float clEnergy = m_svdClusters[cl]->getCharge() * c_eTOkeV;
253  int clSize = m_svdClusters[cl]->getSize();
254  float clTime = m_svdClusters[cl]->getClsTime();
255  float clSN = m_svdClusters[cl]->getSNR();
256 
257  RelationVector<RecoTrack> theRC = DataStore::getRelationsWithObj<RecoTrack>(m_svdClusters[cl]);
258 
259  bool isAssigned = false;
260  // for(int r = 0; r<(int)theRC.size(); r++){
261  if (theRC.size() > 0) {
262  RelationVector<Track> theT = DataStore::getRelationsWithObj<Track>(theRC[0]);
263  if (theT.size() > 0)
264  isAssigned = true;
265  // }
266  }
267 
268  if (isAssigned)
269  continue;
270 
271  VxdID::baseType theVxdID = (VxdID::baseType)m_svdClusters[cl]->getSensorID();
272  int side = m_svdClusters[cl]->isUCluster();
273 
274  h_clusterCharge->fill(theVxdID, side, clCharge / 1000.);
275  h_clusterSize->fill(theVxdID, side, clSize);
276  h_clusterSNR->fill(theVxdID, side, clSN);
277  h_clusterEnergy->fill(theVxdID, side, clEnergy);
278  h_clusterTime->fill(theVxdID, side, clTime);
279  }
280 }
281 
282 
284 {
285  B2INFO("SVDB4CommissioningPlotsModule::endRun(), writing the histograms");
286 
287  if (m_rootFilePtr != nullptr) {
288  m_rootFilePtr->cd();
289 
290  TDirectory* oldDir = gDirectory;
291 
292  TDirectory* dir_track = oldDir->mkdir("tracks");
293  dir_track->cd();
294  m_nTracks->Write();
295  m_Pvalue->Write();
296  m_mom->Write();
297  m_nSVDhits->Write();
298 
299  TDirectory* dir_reco = oldDir->mkdir("recoDigits");
300  TDirectory* dir_clusterAssigned = oldDir->mkdir("clusters_assigned");
301  TDirectory* dir_clusterNotAssigned = oldDir->mkdir("clusters_not_assigned");
302 
304 
305  for (auto layer : geoCache.getLayers(VXD::SensorInfoBase::SVD)) {
306  TString layerName = Form("layer%d", layer.getLayerNumber());
307  TDirectory* dir_reco_layer = dir_reco->mkdir(layerName.Data());
308  TDirectory* dir_clusterAssigned_layer = dir_clusterAssigned->mkdir(layerName.Data());
309  TDirectory* dir_clusterNotAssigned_layer = dir_clusterNotAssigned->mkdir(layerName.Data());
310  for (auto ladder : geoCache.getLadders(layer))
311  for (Belle2::VxdID sensor : geoCache.getSensors(ladder))
312  for (int view = SVDHistograms<TH1F>::VIndex ; view < SVDHistograms<TH1F>::UIndex + 1; view++) {
313 
314  dir_reco_layer->cd();
315  (h_recoCharge->getHistogram(sensor, view))->Write();
316  (h_recoEnergy->getHistogram(sensor, view))->Write();
317  (h_recoTime->getHistogram(sensor, view))->Write();
318  (h_recoNoise->getHistogram(sensor, view))->Write();
319  dir_clusterAssigned_layer->cd();
320  (h_clusterTrkCharge->getHistogram(sensor, view))->Write();
321  (h_clusterTrkSNR->getHistogram(sensor, view))->Write();
322  (h_clusterTrkSize->getHistogram(sensor, view))->Write();
323  (h_clusterTrkEnergy->getHistogram(sensor, view))->Write();
324  (h_clusterTrkTime->getHistogram(sensor, view))->Write();
325  (h_clusterTrkInterstripPos->getHistogram(sensor, view))->Write();
326  dir_clusterNotAssigned_layer->cd();
327  (h_clusterCharge->getHistogram(sensor, view))->Write();
328  (h_clusterSNR->getHistogram(sensor, view))->Write();
329  (h_clusterSize->getHistogram(sensor, view))->Write();
330  (h_clusterEnergy->getHistogram(sensor, view))->Write();
331  (h_clusterTime->getHistogram(sensor, view))->Write();
332  }
333  }
334 
335  m_rootFilePtr->Close();
336 
337  }
338 
339 }
340 
341 
342 
344 {
345 }
static const ChargedStable pion
charged pion particle
Definition: Const.h:542
Base class for Modules.
Definition: Module.h:72
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
SVDHistograms< TH1F > * h_clusterTrkSNR
SVDClusters SNR.
SVDHistograms< TH1F > * h_clusterTrkCharge
SVDClusters Charge.
virtual void initialize() override
Initialize the Module.
StoreArray< SVDCluster > m_svdClusters
SVDCluster StoreArray.
virtual void event() override
This method is the core of the module.
StoreArray< TrackFitResult > m_tfr
TrackFitResult StoreArray.
SVDNoiseCalibrations m_NoiseCal
SVDNoise Calibrations db object.
virtual void endRun() override
This method is called if the current run ends.
SVDHistograms< TH1F > * h_recoEnergy
SVDRecoDigits Energy.
virtual void terminate() override
This method is called at the end of the event processing.
SVDHistograms< TH1F > * h_clusterTrkEnergy
SVDClusters Energy.
SVDHistograms< TH1F > * h_clusterEnergy
SVDClusters Energy.
SVDHistograms< TH1F > * h_clusterSNR
SVDClusters SNR.
std::string m_TrackName
Track StoreArray name.
std::string m_RecoDigitName
SVDRecoDigit StoreArray name.
SVDHistograms< TH1F > * h_recoNoise
SVDRecoDigits Noise.
virtual void beginRun() override
Called when entering a new run.
std::string m_TrackFitResultName
TrackFitResult name.
SVDHistograms< TH1F > * h_clusterSize
SVDClusters Size.
SVDHistograms< TH1F > * h_recoCharge
SVDRecoDigits Charge.
SVDHistograms< TH1F > * h_clusterTime
SVDClusters Time.
SVDHistograms< TH1F > * h_recoTime
SVDRecoDigits Time.
StoreArray< RecoTrack > m_recoTracks
RecoTrack StoreArray.
std::string m_ClusterName
SVDCluster StoreArray name.
StoreArray< SVDRecoDigit > m_svdRecos
SVDRecoDigit StoreArray.
SVDHistograms< TH1F > * h_clusterTrkTime
SVDClusters Time.
SVDHistograms< TH1F > * h_clusterCharge
SVDClusters Charge.
StoreArray< Track > m_Tracks
Track StoreArray.
TFile * m_rootFilePtr
pointer at root file used for storing histograms
SVDHistograms< TH1F > * h_clusterTrkSize
SVDClusters Size.
SVDHistograms< TH1F > * h_clusterTrkInterstripPos
SVDClusters InterstripPosition.
void fill(const VxdID &vxdID, int view, Types ... args)
fill the histogram for
Definition: SVDHistograms.h:77
H * getHistogram(const VxdID &vxdID, int view)
get a reference to the histogram for
Definition: SVDHistograms.h:56
float getNoiseInElectrons(const VxdID &sensorID, const bool &isU, const unsigned short &strip) const
This method provides the correct noise conversion into electrons, taking into account that the noise ...
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
Values of the result of a track fit with a given particle hypothesis.
double getPValue() const
Getter for Chi2 Probability of the track fit.
TVector3 getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
HitPatternVXD getHitPatternVXD() const
Getter for the hit pattern in the VXD;.
Class that bundles various TrackFitResults.
Definition: Track.h:25
Class to faciliate easy access to sensor information of the VXD like coordinate transformations or pi...
Definition: GeoCache.h:39
const SensorInfoBase & getSensorInfo(Belle2::VxdID id) const
Return a referecne to the SensorInfo of a given SensorID.
Definition: GeoCache.cc:66
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:213
Base class to provide Sensor Information for PXD and SVD.
double getUPitch(double v=0) const
Return the pitch of the sensor.
double getVPitch(double v=0) const
Return the pitch of the sensor.
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
#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.