Belle II Software  release-08-01-10
SVDClusterEvaluationTrueInfoModule.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/svdPerformance/SVDClusterEvaluationTrueInfoModule.h>
10 #include <framework/datastore/StoreArray.h>
11 #include <mdst/dataobjects/MCParticle.h>
12 #include <svd/dataobjects/SVDShaperDigit.h>
13 #include <svd/dataobjects/SVDRecoDigit.h>
14 #include <svd/dataobjects/SVDCluster.h>
15 #include <svd/dataobjects/SVDTrueHit.h>
16 
17 #include <TCanvas.h>
18 #include <TFile.h>
19 #include <TGraphErrors.h>
20 #include <TText.h>
21 
22 #include <string>
23 
24 
25 using namespace Belle2;
26 
27 
28 REG_MODULE(SVDClusterEvaluationTrueInfo);
29 
30 
32 {
33  setDescription("This modules generates performance plots on SVD clustering.");
34 
35  addParam("outputFileName", m_outputFileName, "output rootfile name", std::string("SVDClusterEvaluationTrueInfo.root"));
36  addParam("SVDEventInfo", m_svdEventInfoName, "Defines the name of the EventInfo", std::string(""));
37 }
38 
39 
40 SVDClusterEvaluationTrueInfoModule::~SVDClusterEvaluationTrueInfoModule()
41 {
42 }
43 
44 
46 {
47 
48  /* initialize useful store array */
49  StoreArray<SVDShaperDigit> SVDShaperDigits;
50  StoreArray<SVDRecoDigit> SVDRecoDigits;
51  StoreArray<SVDCluster> SVDClusters;
52  StoreArray<SVDTrueHit> SVDTrueHits;
53 
54  SVDShaperDigits.isRequired();
55  SVDRecoDigits.isRequired();
56  SVDClusters.isRequired();
57  SVDTrueHits.isRequired();
58  if (!m_storeSVDEvtInfo.isOptional(m_svdEventInfoName)) m_svdEventInfoName = "SVDEventInfoSim";
60 
61 
62  m_outputFile = new TFile(m_outputFileName.c_str(), "RECREATE");
63 
66  m_histoList_ClusterTimePull = new TList;
69  m_histo2DList_TresVsPosres = new TList;
73  m_histoList_THinCluster = new TList;
74  m_histoList_THinClusterTM = new TList;
77  m_graphList = new TList;
78  //Control List
79  m_histoList_Control = new TList;
80 
81  for (int i = 0; i < m_Nsets; i ++) {
82 
83  if (i % 2 == 0) { //even index, U side
84  NameOfHisto = "histo_ClusterUPositionResolution_" + IntExtFromIndex(i) + "_" + FWFromIndex(i);
85  TitleOfHisto = "U-Cluster Position Resolution (" + IntExtFromIndex(i) + ", " + FWFromIndex(i) + ")";
87  "U_reco - U_true (cm)",
89 
90  NameOfHisto = "histo_ClusterUPositionPull_" + IntExtFromIndex(i) + "_" + FWFromIndex(i);
91  TitleOfHisto = "U-Cluster Position Pull (" + IntExtFromIndex(i) + ", " + FWFromIndex(i) + ")";
93  "(U_reco - U_true)/U_sigma",
95  } else { //odd index, V side
96  NameOfHisto = "histo_ClusterVPositionResolution_" + IntExtFromIndex(i) + "_" + FWFromIndex(i);
97  TitleOfHisto = "V-Cluster Position Resolution (" + IntExtFromIndex(i) + ", " + FWFromIndex(i) + ")";
99  "V_reco - V_true (cm)", m_histoList_ClusterPositionResolution);
100 
101  NameOfHisto = "histo_ClusterVPositionPull_" + IntExtFromIndex(i) + "_" + FWFromIndex(i);
102  TitleOfHisto = "Cluster V Position Pull (" + IntExtFromIndex(i) + ", " + FWFromIndex(i) + ")";
104  "(V_reco- V_true)/V_sigma", m_histoList_ClusterPositionPull);
105  }
106 
107  NameOfHisto = "histo_StripTimeResolution_" + IntExtFromIndex(i) + "_" + FWFromIndex(i) + "_Side" + UVFromIndex(i);
108  TitleOfHisto = "Strip Time Resolution (" + IntExtFromIndex(i) + ", " + FWFromIndex(i) + ", side" + UVFromIndex(i) + ")";
109  m_histo_StripTimeResolution[i] = createHistogram1D(NameOfHisto, TitleOfHisto, 400, -100, 100, "t_reco - t_true (ns)",
111 
112  NameOfHisto = "histo_ClusterTimeResolution_" + IntExtFromIndex(i) + "_" + FWFromIndex(i) + "_Side" + UVFromIndex(i);
113  TitleOfHisto = "Cluster Time Resolution (" + IntExtFromIndex(i) + ", " + FWFromIndex(i) + ", side" + UVFromIndex(i) + ")";
114  m_histo_ClusterTimeResolution[i] = createHistogram1D(NameOfHisto, TitleOfHisto, 400, -100, 100, "t_reco - t_true (ns)",
116 
117  NameOfHisto = "histo_ClusterTimeResolution_bin1_" + IntExtFromIndex(i) + "_" + FWFromIndex(i) + "_Side" + UVFromIndex(i);
118  TitleOfHisto = "Cluster Time Resolution TriggerBin=1(" + IntExtFromIndex(i) + ", " + FWFromIndex(i) + ", side" + UVFromIndex(
119  i) + ")";
120  m_histo_ClusterTimeResolution_bin1[i] = createHistogram1D(NameOfHisto, TitleOfHisto, 400, -100, 100, "t_reco - t_true (ns)",
122  NameOfHisto = "histo_ClusterTimeResolution_bin2_" + IntExtFromIndex(i) + "_" + FWFromIndex(i) + "_Side" + UVFromIndex(i);
123  TitleOfHisto = "Cluster Time Resolution TriggerBin=2(" + IntExtFromIndex(i) + ", " + FWFromIndex(i) + ", side" + UVFromIndex(
124  i) + ")";
125  m_histo_ClusterTimeResolution_bin2[i] = createHistogram1D(NameOfHisto, TitleOfHisto, 400, -100, 100, "t_reco - t_true (ns)",
127  NameOfHisto = "histo_ClusterTimeResolution_bin3_" + IntExtFromIndex(i) + "_" + FWFromIndex(i) + "_Side" + UVFromIndex(i);
128  TitleOfHisto = "Cluster Time Resolution TriggerBin=3(" + IntExtFromIndex(i) + ", " + FWFromIndex(i) + ", side" + UVFromIndex(
129  i) + ")";
130  m_histo_ClusterTimeResolution_bin3[i] = createHistogram1D(NameOfHisto, TitleOfHisto, 400, -100, 100, "t_reco - t_true (ns)",
132  NameOfHisto = "histo_ClusterTimeResolution_bin4_" + IntExtFromIndex(i) + "_" + FWFromIndex(i) + "_Side" + UVFromIndex(i);
133  TitleOfHisto = "Cluster Time Resolution TriggerBin=4(" + IntExtFromIndex(i) + ", " + FWFromIndex(i) + ", side" + UVFromIndex(
134  i) + ")";
135  m_histo_ClusterTimeResolution_bin4[i] = createHistogram1D(NameOfHisto, TitleOfHisto, 400, -100, 100, "t_reco - t_true (ns)",
137 
138  NameOfHisto = "histo_ClusterTimePull_" + IntExtFromIndex(i) + "_" + FWFromIndex(i) + "_Side" + UVFromIndex(i);
139  TitleOfHisto = "Cluster Time Pull (" + IntExtFromIndex(i) + ", " + FWFromIndex(i) + ", side" + UVFromIndex(i) + ")";
140  m_histo_ClusterTimePull[i] = createHistogram1D(NameOfHisto, TitleOfHisto, 210, -10, 11, "(t_reco - t_true)/t_sigma",
142 
143  NameOfHisto = "histo2D_TresVsPosres_" + IntExtFromIndex(i) + "_" + FWFromIndex(i) + "_Side" + UVFromIndex(i);
144  TitleOfHisto = "Time Residuals Vs U/V Position Residuals (" + IntExtFromIndex(
145  i) + ", " + FWFromIndex(i) + ", side" + UVFromIndex(i) + ")";
146  m_histo2D_TresVsPosres[i] = createHistogram2D(NameOfHisto, TitleOfHisto, 200, -0.1, 0.1, "U/V_reco - U/V_true (cm)", 180, -120, 60,
147  "t_reco - t_true (ns)", m_histo2DList_TresVsPosres);
148 
149  NameOfHisto = "histo_PurityInsideTMCluster_" + IntExtFromIndex(i) + "_" + FWFromIndex(i) + "_Side" + UVFromIndex(i);
150  TitleOfHisto = "Fraction of Truth-Matched RecoDigits inside a Truth-Matched Cluster (" + IntExtFromIndex(i) + ", " + FWFromIndex(
151  i) + ", side" + UVFromIndex(i) + ")";
153  "number of TM recoDigits / cluster size",
155 
156  NameOfHisto = "histo2D_PurityInsideTMCluster_" + IntExtFromIndex(i) + "_" + FWFromIndex(i) + "_Side" + UVFromIndex(i);
157  TitleOfHisto = "Number of Truth-matched Recos vs Number of Recos inside a Truth-matched Cluster (" + IntExtFromIndex(
158  i) + ", " + FWFromIndex(i) + ", side" + UVFromIndex(i) + ")";
159  m_histo2D_PurityInsideTMCluster[i] = createHistogram2D(NameOfHisto, TitleOfHisto, 42, 0, 42, "cluster size", 42, 0, 42,
160  "number of TM recos", m_histo2DList_PurityInsideTMCluster);
161 
162  NameOfHisto = "histo_PurityInsideNOTMCluster_" + IntExtFromIndex(i) + "_" + FWFromIndex(i) + "_Side" + UVFromIndex(i);
163  TitleOfHisto = "Fraction of Truth-matched RecoDigits inside a NOT Truth-matched Cluster (" + IntExtFromIndex(
164  i) + ", " + FWFromIndex(
165  i) + ", side" + UVFromIndex(i) + ")";
167  "number of TM recoDigits / cluster size",
169 
170  NameOfHisto = "histo_THinCluster_" + IntExtFromIndex(i) + "_" + FWFromIndex(i) + "_Side" + UVFromIndex(i);
171  TitleOfHisto = "Number of True Hits inside a Cluster (" + IntExtFromIndex(i) + ", " + FWFromIndex(i) + ", side" + UVFromIndex(
172  i) + ")";
173  m_histo_THinCluster[i] = createHistogram1D(NameOfHisto, TitleOfHisto, 15, 0, 15, "number of TH per cluster",
175 
176  NameOfHisto = "histo_THinClusterTM_" + IntExtFromIndex(i) + "_" + FWFromIndex(i) + "_Side" + UVFromIndex(i);
177  TitleOfHisto = "Number of True Hits inside a Truth-matched Cluster (" + IntExtFromIndex(i) + ", " + FWFromIndex(
178  i) + ", side" + UVFromIndex(i) + ")";
179  m_histo_THinClusterTM[i] = createHistogram1D(NameOfHisto, TitleOfHisto, 15, 0, 15, "number of TH per TM cluster",
181 
182  NameOfHisto = "histo_GoodTHinClusterTM_" + IntExtFromIndex(i) + "_" + FWFromIndex(i) + "_Side" + UVFromIndex(i);
183  TitleOfHisto = "Number of Good True Hits inside a Truth-matched Cluster (" + IntExtFromIndex(i) + ", " + FWFromIndex(
184  i) + ", side" + UVFromIndex(i) + ")";
185  m_histo_GoodTHinClusterTM[i] = createHistogram1D(NameOfHisto, TitleOfHisto, 15, 0, 15, "number of Good TH per TM cluster",
187 
188  NameOfHisto = "histo_GoodTHinClusterTMGood_" + IntExtFromIndex(i) + "_" + FWFromIndex(i) + "_Side" + UVFromIndex(i);
189  TitleOfHisto = "Number of Good True Hits inside a Good Truth-matched Cluster (" + IntExtFromIndex(i) + ", " + FWFromIndex(
190  i) + ", side" + UVFromIndex(i) + ")";
191  m_histo_GoodTHinClusterTMGood[i] = createHistogram1D(NameOfHisto, TitleOfHisto, 15, 0, 15, "number of Good TH per Good TM cluster",
193  }
194 
195  //Control Histos
196  m_histoControl_MCcharge = createHistogram1D("m_histoControl_MCcharge", "m_histoControl_MCcharge", 5, -2, 3,
197  "charge of the first MC particle related to a True Hit", m_histoList_Control);
198  m_histoControl_MCisPrimary = createHistogram1D("m_histoControl_MCisPrimary", "m_histoControl_MCisPrimary", 2, 0, 2,
199  "isPrimary of the first MC particle related to a True Hit", m_histoList_Control);
200  m_histoControl_THToMCsize = createHistogram1D("m_histoControl_THToMCsize", "m_histoControl_THToMCsize", 10, -1, 9,
201  "size of the THToMC relation arrau", m_histoList_Control);
202 }
203 
204 
206 {
207 }
208 
209 
211 {
212 
213  SVDModeByte modeByte = m_storeSVDEvtInfo->getModeByte();
214 
215  StoreArray<SVDShaperDigit> SVDShaperDigits;
216  StoreArray<SVDRecoDigit> SVDRecoDigits;
217  StoreArray<SVDCluster> SVDClusters;
218  StoreArray<SVDTrueHit> SVDTrueHits;
219 
221  //STRIPS//
223 
224  //loop on ShaperDigits
225  for (const SVDShaperDigit& shape : SVDShaperDigits) {
226  indexForHistosAndGraphs = indexFromLayerSensorSide(shape.getSensorID().getLayerNumber(), shape.getSensorID().getSensorNumber(),
227  shape.isUStrip());
228 
229  RelationVector<SVDRecoDigit> relatVectorShaperToReco = DataStore::getRelationsWithObj<SVDRecoDigit>(&shape);
230 
231  //efficiency shaper to reco
233  if (relatVectorShaperToReco.size() > 0)
235  }
236  //close loop on ShaperDigits
237 
238  //loop on RecoDigits
239  for (const SVDRecoDigit& reco : SVDRecoDigits) {
240  indexForHistosAndGraphs = indexFromLayerSensorSide(reco.getSensorID().getLayerNumber(), reco.getSensorID().getSensorNumber(),
241  reco.isUStrip());
242 
243  RelationVector<SVDTrueHit> relatVectorRecoToTH = DataStore::getRelationsWithObj<SVDTrueHit>(&reco);
244 
245  //strip time resolution
246  if (relatVectorRecoToTH.size() > 0)
247  m_histo_StripTimeResolution[indexForHistosAndGraphs]->Fill(reco.getTime() - (relatVectorRecoToTH[0])->getGlobalTime());
248 
249  }
250  //close loop on RecoDigits
251 
253  //CLUSTERS//
255 
256  //loop on TrueHits
257  for (const SVDTrueHit& trhi : SVDTrueHits) {
258 
259  if (goodTrueHit(&trhi)) { //enter only if the TH is related to a primary and charged MC particle
260  indexForHistosAndGraphs = indexFromLayerSensorSide(trhi.getSensorID().getLayerNumber(), trhi.getSensorID().getSensorNumber(), 1);
261 
262  RelationVector<SVDCluster> relatVectorTHToClus = DataStore::getRelationsWithObj<SVDCluster>(&trhi);
263 
264  //efficiencies TH to cluster
267 
268  bool hasU = false;
269  bool hasV = false;
270 
271  for (int j = 0; j < (int) relatVectorTHToClus.size(); j ++) {
272  indexForHistosAndGraphs = indexFromLayerSensorSide(relatVectorTHToClus[j]->getSensorID().getLayerNumber(),
273  relatVectorTHToClus[j]->getSensorID().getSensorNumber(), relatVectorTHToClus[j]->isUCluster());
274 
275  if (relatVectorTHToClus[j]->isUCluster() && ! hasU) {
277  hasU = true;
278  } else if (!relatVectorTHToClus[j]->isUCluster() && ! hasV) {
280  hasV = true;
281  }
282  }
283  }
284  }
285  //close loop on TrueHits
286 
287  //loop on Clusters
288  for (const SVDCluster& clus : SVDClusters) {
289  indexForHistosAndGraphs = indexFromLayerSensorSide(clus.getSensorID().getLayerNumber(), clus.getSensorID().getSensorNumber(),
290  clus.isUCluster());
291 
292  RelationVector<SVDTrueHit> relatVectorClusToTH = DataStore::getRelationsWithObj<SVDTrueHit>(&clus);
293 
294  //purity "outside" clusters
296  if (relatVectorClusToTH.size() > 0)
298 
299  //fill the THinCluster histo with the number of TH a cluster is composed of
300  m_histo_THinCluster[indexForHistosAndGraphs]->Fill(relatVectorClusToTH.size());
301 
302  //loop on the TH related to the cluster
303  for (int q = 0; q < (int)relatVectorClusToTH.size(); q ++) {
304  //cluster time resolution and pull
305  m_histo_ClusterTimeResolution[indexForHistosAndGraphs]->Fill(clus.getClsTime() - (relatVectorClusToTH[q])->getGlobalTime());
306 
307  //get trigger bin
308  int triggerBin = 0;
309  triggerBin = (int)modeByte.getTriggerBin();
310 
311  if (triggerBin == 0)
312  m_histo_ClusterTimeResolution_bin1[indexForHistosAndGraphs]->Fill(clus.getClsTime() - (relatVectorClusToTH[q])->getGlobalTime());
313  else if (triggerBin == 1)
314  m_histo_ClusterTimeResolution_bin2[indexForHistosAndGraphs]->Fill(clus.getClsTime() - (relatVectorClusToTH[q])->getGlobalTime());
315  else if (triggerBin == 2)
316  m_histo_ClusterTimeResolution_bin3[indexForHistosAndGraphs]->Fill(clus.getClsTime() - (relatVectorClusToTH[q])->getGlobalTime());
317  else if (triggerBin == 3)
318  m_histo_ClusterTimeResolution_bin4[indexForHistosAndGraphs]->Fill(clus.getClsTime() - (relatVectorClusToTH[q])->getGlobalTime());
319 
320  m_histo_ClusterTimePull[indexForHistosAndGraphs]->Fill((clus.getClsTime() - (relatVectorClusToTH[q])->getGlobalTime()) /
321  (clus.getClsTimeSigma()));
322 
323  //cluster position resolution and pull, also correlation between time res and position res
324  if (clus.isUCluster()) {
325  m_histo_ClusterUPositionResolution[indexForHistosAndGraphs / 2]->Fill(clus.getPosition((relatVectorClusToTH[q])->getV()) -
326  (relatVectorClusToTH[q])->getU());
327  m_histo_ClusterUPositionPull[indexForHistosAndGraphs / 2]->Fill((clus.getPosition((relatVectorClusToTH[q])->getV()) -
328  (relatVectorClusToTH[q])->getU()) / (clus.getPositionSigma()));
329  m_histo2D_TresVsPosres[indexForHistosAndGraphs]->Fill((clus.getPosition((relatVectorClusToTH[q])->getV()) -
330  (relatVectorClusToTH[q])->getU()), (clus.getClsTime() - (relatVectorClusToTH[q])->getGlobalTime()));
331  } else {
332  m_histo_ClusterVPositionResolution[(indexForHistosAndGraphs - 1) / 2]->Fill(clus.getPosition() - (relatVectorClusToTH[q])->getV());
333  m_histo_ClusterVPositionPull[(indexForHistosAndGraphs - 1) / 2]->Fill((clus.getPosition() - (relatVectorClusToTH[q])->getV()) /
334  (clus.getPositionSigma()));
335  m_histo2D_TresVsPosres[indexForHistosAndGraphs]->Fill((clus.getPosition() - (relatVectorClusToTH[q])->getV()),
336  (clus.getClsTime() - (relatVectorClusToTH[q])->getGlobalTime()));
337  }
338  }
339 
340  RelationVector<SVDRecoDigit> relatVectorClusToReco = DataStore::getRelationsWithObj<SVDRecoDigit>(&clus);
341  //enter only if the cluster is TM
342  if (relatVectorClusToTH.size() > 0) {
343 
344  //fill the THinCluster histo with the number of TH (and good TH) a TM cluster (and a Good TM cluster) is composed of
345  m_histo_THinClusterTM[indexForHistosAndGraphs]->Fill(relatVectorClusToTH.size());
346  int numberOfGoodTHInACluster = 0;
347  int numberOfGoodTHInAClusterGood = 0;
348  for (int k = 0; k < (int)(relatVectorClusToTH.size()); k ++) {
349  if (goodTrueHit(relatVectorClusToTH[k])) {
350  numberOfGoodTHInACluster ++;
351  numberOfGoodTHInAClusterGood ++;
352  }
353  }
354  m_histo_GoodTHinClusterTM[indexForHistosAndGraphs]->Fill(numberOfGoodTHInACluster);
355  if (numberOfGoodTHInAClusterGood > 0)
356  m_histo_GoodTHinClusterTMGood[indexForHistosAndGraphs]->Fill(numberOfGoodTHInAClusterGood);
357 
358  //count number of recodigit, composing the Truth-matched cluster, that are linked with a TH (internal purity)
360  for (int k = 0; k < (int)relatVectorClusToReco.size(); k++) { //loop on the recodigits composing the TM cluster
361  RelationVector<SVDTrueHit> relatVectorRecoFromClusToTH = DataStore::getRelationsWithObj<SVDTrueHit>(relatVectorClusToReco[k]);
362 
363  if (relatVectorRecoFromClusToTH.size() > 0)
365  }
366 
369 
370  }
371  //count number of recodigit, composing a NOT Truth-matched cluster, that are linked with a TH
372  else {
373 
375  for (int k = 0; k < (int)relatVectorClusToReco.size(); k++) { //loop on the recodigits composing the NOTM cluster
376  RelationVector<SVDTrueHit> relatVectorRecoFromClusToTH = DataStore::getRelationsWithObj<SVDTrueHit>(relatVectorClusToReco[k]);
377 
378  if (relatVectorRecoFromClusToTH.size() > 0)
380  }
381 
383 
384  }
385  }
386  //close loop on clusters
387 }
388 
389 
391 {
392 
393  //extract mean and sigma values from histos to plot them in graphs
394  for (int k = 0; k < m_Nsets; k ++) {
397 
400 
403 
404  m_mean_THinCluster[k] = m_histo_THinCluster[k]->GetMean();
405  m_RMS_THinCluster[k] = m_histo_THinCluster[k]->GetRMS() / sqrt(m_histo_THinCluster[k]->GetEntries());
406 
407  m_mean_THinClusterTM[k] = m_histo_THinClusterTM[k]->GetMean();
408  m_RMS_THinClusterTM[k] = m_histo_THinClusterTM[k]->GetRMS() / sqrt(m_histo_THinClusterTM[k]->GetEntries());
409 
412 
415  }
416  for (int k = 0; k < m_NsetsRed; k ++) {
419 
422  }
423 
424  //GRAPHS
425  createEfficiencyGraph("recoEff", "Strip Fit Efficiency ( RecoDigits / ShaperDigits )", m_NumberOfRecoDigit, m_NumberOfShaperDigit,
426  "set", "efficiency", m_graphList);
427 
428  createEfficiencyGraph("clusterEff", "Clustering Efficiency ( Truth-Matched Clusters / TrueHits )", m_NumberOfClustersRelatedToTH,
429  m_NumberOfTH, "set", "efficiency", m_graphList);
430 
431  createEfficiencyGraph("clusterPurity", "Purity of Clusters ( Truth-Matched Clusters / All Clusters )", m_NumberOfTMClusters,
432  m_NumberOfClusters, "set", "purity", m_graphList);
433 
434  //means-from-histos graphs
435  createArbitraryGraphErrorChooser("stripTime_Means", "Strip Time Resolution", m_OrderingVec, m_NullVec, m_mean_StripTimeResolution,
436  m_RMS_StripTimeResolution, "set", "time residuals (ns)", m_graphList, m_Nsets);
437 
438  createArbitraryGraphErrorChooser("clusterTime_Means", "Cluster Time Resolution", m_OrderingVec, m_NullVec,
440 
441  createArbitraryGraphErrorChooser("clusterUposition_Means", "Cluster U Position Resolution", m_OrderingVec, m_NullVec,
443  m_NsetsRed);
444 
445  createArbitraryGraphErrorChooser("clusterVposition_Means", "Cluster V Position Resolution", m_OrderingVec, m_NullVec,
447  m_NsetsRed);
448 
449  createArbitraryGraphErrorChooser("clusterInternalPurity_Means", "Fraction of Truth-matched Recos inside a Truth-matched Cluster",
451  "number of TM recos / cluster size", m_graphList, m_Nsets);
452 
453  createArbitraryGraphErrorChooser("THinCluster_Means", "Number of True Hits inside a Cluster", m_OrderingVec, m_NullVec,
454  m_mean_THinCluster, m_RMS_THinCluster, "set", "number of TH per cluster", m_graphList, m_Nsets);
455 
456  createArbitraryGraphErrorChooser("THinClusterTM_Means", "Number of True Hits inside a TM Cluster", m_OrderingVec, m_NullVec,
457  m_mean_THinClusterTM, m_RMS_THinClusterTM, "set", "number of TH per TM cluster", m_graphList, m_Nsets);
458 
459  createArbitraryGraphErrorChooser("goodTHinClusterTM_Means", "Number of Good True Hits inside a TM Cluster", m_OrderingVec,
460  m_NullVec,
461  m_mean_GoodTHinClusterTM, m_RMS_GoodTHinClusterTM, "set", "number of Good TH per TM cluster", m_graphList, m_Nsets);
462 
463  createArbitraryGraphErrorChooser("goodTHinClusterTMGood_Means", "Number of Good True Hits inside a Good TM Cluster", m_OrderingVec,
464  m_NullVec,
465  m_mean_GoodTHinClusterTMGood, m_RMS_GoodTHinClusterTMGood, "set", "number of Good TH per Good TM cluster", m_graphList, m_Nsets);
467  //WRITE HISTOS AND GRAPHS//
469 
470  if (m_outputFile != nullptr) {
471  m_outputFile->cd();
472 
473  TDirectory* oldDir = gDirectory;
474  TObject* obj;
475 
476  TDirectory* dir_strtime = oldDir->mkdir("strip_time");
477  dir_strtime->cd();
478  TIter nextH_strtime(m_histoList_StripTimeResolution);
479  while ((obj = nextH_strtime()))
480  obj->Write();
481 
482  TDirectory* dir_cltime = oldDir->mkdir("cluster_time");
483  dir_cltime->cd();
484  TIter nextH_cltime(m_histoList_ClusterTimeResolution);
485  while ((obj = nextH_cltime()))
486  obj->Write();
487 
488  TDirectory* dir_cltimepull = oldDir->mkdir("cluster_time_pull");
489  dir_cltimepull->cd();
490  TIter nextH_cltimepull(m_histoList_ClusterTimePull);
491  while ((obj = nextH_cltimepull()))
492  obj->Write();
493 
494  TDirectory* dir_clpos = oldDir->mkdir("cluster_position");
495  dir_clpos->cd();
496  TIter nextH_clpos(m_histoList_ClusterPositionResolution);
497  while ((obj = nextH_clpos()))
498  obj->Write();
499 
500  TDirectory* dir_clpospull = oldDir->mkdir("cluster_position_pull");
501  dir_clpospull->cd();
502  TIter nextH_clpospull(m_histoList_ClusterPositionPull);
503  while ((obj = nextH_clpospull()))
504  obj->Write();
505 
506  TDirectory* dir_clpostime = oldDir->mkdir("cluster_timeVSposition");
507  dir_clpostime->cd();
508  TIter nextH_clpostime(m_histo2DList_TresVsPosres);
509  while ((obj = nextH_clpostime()))
510  obj->Write();
511 
512  TDirectory* dir_clinpurTM = oldDir->mkdir("intra_cluster_purity_TM");
513  dir_clinpurTM->cd();
514  TIter nextH_clinpurTM(m_histoList_PurityInsideTMCluster);
515  while ((obj = nextH_clinpurTM()))
516  obj->Write();
517 
518  TDirectory* dir_clinpurTM2D = oldDir->mkdir("intra_cluster_purity_TM2D");
519  dir_clinpurTM2D->cd();
520  TIter nextH_clinpurTM2D(m_histo2DList_PurityInsideTMCluster);
521  while ((obj = nextH_clinpurTM2D()))
522  obj->Write();
523 
524  TDirectory* dir_clinpurNOTM = oldDir->mkdir("intra_cluster_purity_NOTM");
525  dir_clinpurNOTM->cd();
526  TIter nextH_clinpurNOTM(m_histoList_PurityInsideNOTMCluster);
527  while ((obj = nextH_clinpurNOTM()))
528  obj->Write();
529 
530  TDirectory* dir_puddle = oldDir->mkdir("trueHits_in_cluster");
531  dir_puddle->cd();
532  TIter nextH_puddle(m_histoList_THinCluster);
533  while ((obj = nextH_puddle()))
534  obj->Write();
535 
536  TDirectory* dir_puddleTM = oldDir->mkdir("trueHits_in_TMcluster");
537  dir_puddleTM->cd();
538  TIter nextH_puddleTM(m_histoList_THinClusterTM);
539  while ((obj = nextH_puddleTM()))
540  obj->Write();
541 
542  TDirectory* dir_goodPuddleTM = oldDir->mkdir("goodTrueHits_in_TMcluster");
543  dir_goodPuddleTM->cd();
544  TIter nextH_GoodPuddleTM(m_histoList_GoodTHinClusterTM);
545  while ((obj = nextH_GoodPuddleTM()))
546  obj->Write();
547 
548  TDirectory* dir_goodPuddleTMGood = oldDir->mkdir("goodTrueHits_in_GoodTMcluster");
549  dir_goodPuddleTMGood->cd();
550  TIter nextH_GoodPuddleTMGood(m_histoList_GoodTHinClusterTMGood);
551  while ((obj = nextH_GoodPuddleTMGood()))
552  obj->Write();
553 
554  TDirectory* dir_graph = oldDir->mkdir("graphs");
555  dir_graph->cd();
556  TIter nextH_graph(m_graphList);
557  while ((obj = nextH_graph()))
558  obj->Write();
559 
560  TDirectory* dir_controlsMC = oldDir->mkdir("controlMC");
561  dir_controlsMC->cd();
562  TIter nextH_controlsMC(m_histoList_Control);
563  while ((obj = nextH_controlsMC()))
564  obj->Write();
565 
566  m_outputFile->Close();
567  }
568 }
569 
570 
572 {
573 }
574 
575 
577 //EXTRA FUNCTIONS//
579 
580 TH1F* SVDClusterEvaluationTrueInfoModule::createHistogram1D(const char* name, const char* title,
581  Int_t nbins, Double_t min, Double_t max,
582  const char* xtitle, TList* histoList)
583 {
584  TH1F* h = new TH1F(name, title, nbins, min, max);
585 
586  h->GetXaxis()->SetTitle(xtitle);
587 
588  if (histoList)
589  histoList->Add(h);
590 
591  return h;
592 }
593 
594 TH2F* SVDClusterEvaluationTrueInfoModule::createHistogram2D(const char* name, const char* title,
595  Int_t nbinsX, Double_t minX, Double_t maxX,
596  const char* titleX,
597  Int_t nbinsY, Double_t minY, Double_t maxY,
598  const char* titleY, TList* histoList)
599 {
600 
601  TH2F* h = new TH2F(name, title, nbinsX, minX, maxX, nbinsY, minY, maxY);
602 
603  h->GetXaxis()->SetTitle(titleX);
604  h->GetYaxis()->SetTitle(titleY);
605 
606  if (histoList)
607  histoList->Add(h);
608 
609  return h;
610 }
611 
612 int SVDClusterEvaluationTrueInfoModule::indexFromLayerSensorSide(int LayerNumber, int SensorNumber, int UVNumber)
613 {
614  int Index;
615 
616  if (LayerNumber == 3) { //L3
617  if (UVNumber) //U
618  Index = 0;
619  else //V
620  Index = 1;
621  } else { //L456
622  if (SensorNumber == 1) { //FW
623  if (UVNumber) //U
624  Index = 2;
625  else //V
626  Index = 3;
627  } else { //barrel
628  if (UVNumber) //U
629  Index = 4;
630  else //V
631  Index = 5;
632  }
633  }
634 
635  return Index;
636 }
637 
639 {
640  TString name = "";
641 
642  if (idx < 2)
643  name = "L3";
644  else
645  name = "L456";
646 
647  return name;
648 }
649 
651 {
652  TString name = "";
653 
654  if (idx == 2 || idx == 3)
655  name = "FWD";
656  else
657  name = "Barrel";
658 
659  return name;
660 }
661 
663 {
664  TString name = "";
665 
666  if (idx % 2 == 0)
667  name = "U";
668  else
669  name = "V";
670 
671  return name;
672 }
673 
674 void SVDClusterEvaluationTrueInfoModule::createEfficiencyGraph(const char* name, const char* title, int vNum[m_Nsets],
675  int vDen[m_Nsets],
676  TString xTitle, TString yTitle, TList* list)
677 {
678 
679  float ratio[m_Nsets];
680  float ratioErr[m_Nsets];
681  float x[m_Nsets];
682  float xErr[m_Nsets];
683 
684  for (int set = 0; set < m_Nsets; set++) {
685 
686  x[set] = set + 1;
687  xErr[set] = 0;
688 
689  if (vDen[set] > 0) {
690  ratio[set] = (float)vNum[set] / (float)vDen[set];
691  ratioErr[set] = sqrt(ratio[set] * (1 - ratio[set]) / (float)vDen[set]);
692  }
693 
694  }
695 
696  TCanvas* c = new TCanvas(name, title);
697  TGraphErrors* g = new TGraphErrors(m_Nsets, x, ratio, xErr, ratioErr);
698  g->SetName(name);
699  g->SetTitle(title);
700  g->GetXaxis()->SetTitle(xTitle.Data());
701  g->GetYaxis()->SetTitle(yTitle.Data());
702  g->GetYaxis()->SetRangeUser(0.00001, 1.10);
703  g->Draw("AP");
704  g->SetMarkerStyle(20);
705  g->SetMarkerSize(0.8);
706  TAxis* xAxis = g->GetXaxis();
707 
708  TText* t = new TText();
709  t->SetTextAlign(32);
710  t->SetTextSize(0.035);
711  t->SetTextFont(72);
712  TString labels[m_Nsets] = {"3U", "3V", "456FU", "456FV", "456BU", "456BV"};
713  for (Int_t i = 0; i < m_Nsets; i++) {
714  xAxis->SetBinLabel(xAxis->FindBin(i + 1), labels[i].Data());
715  }
716 
717  if (list)
718  list->Add(c);
719 
720 }
721 
722 void SVDClusterEvaluationTrueInfoModule::createArbitraryGraphErrorChooser(const char* name, const char* title, float x[m_Nsets],
723  float xErr[m_Nsets], float y[m_Nsets], float yErr[m_Nsets], TString xTitle, TString yTitle, TList* list, int len)
724 {
725  if (len == m_NsetsRed)
726  createArbitraryGraphError_Red(name, title, x, xErr, y, yErr, xTitle, yTitle, list);
727  else if (len == m_Nsets)
728  createArbitraryGraphError_Std(name, title, x, xErr, y, yErr, xTitle, yTitle, list);
729  else
730  B2INFO("ERROR, WRONG LENGTH FOR MEANS TGRAPH CREATION!!!");
731 }
732 
733 void SVDClusterEvaluationTrueInfoModule::createArbitraryGraphError_Std(const char* name, const char* title, float x[m_Nsets],
734  float xErr[m_Nsets], float y[m_Nsets], float yErr[m_Nsets], TString xTitle, TString yTitle, TList* list)
735 {
736 
737  TCanvas* c = new TCanvas(name, title);
738  TGraphErrors* g = new TGraphErrors(m_Nsets, x, y, xErr, yErr);
739  g->SetName(name);
740  g->SetTitle(title);
741  g->GetXaxis()->SetTitle(xTitle.Data());
742  g->GetYaxis()->SetTitle(yTitle.Data());
743  g->Draw("AP");
744  g->SetMarkerStyle(20);
745  g->SetMarkerSize(0.8);
746  TAxis* xAxis = g->GetXaxis();
747 
748  TText* t = new TText();
749  t->SetTextAlign(32);
750  t->SetTextSize(0.035);
751  t->SetTextFont(72);
752  TString labels[m_Nsets] = {"3U", "3V", "456FU", "456FV", "456BU", "456BV"};
753  for (Int_t i = 0; i < m_Nsets; i++) {
754  xAxis->SetBinLabel(xAxis->FindBin(i + 1), labels[i].Data());
755  }
756 
757  if (list)
758  list->Add(c);
759 
760 }
761 
762 void SVDClusterEvaluationTrueInfoModule::createArbitraryGraphError_Red(const char* name, const char* title, float x[m_NsetsRed],
763  float xErr[m_NsetsRed], float y[m_NsetsRed], float yErr[m_NsetsRed], TString xTitle, TString yTitle, TList* list)
764 {
765 
766  TCanvas* c = new TCanvas(name, title);
767  TGraphErrors* g = new TGraphErrors(m_NsetsRed, x, y, xErr, yErr);
768  g->SetName(name);
769  g->SetTitle(title);
770  g->GetXaxis()->SetTitle(xTitle.Data());
771  g->GetYaxis()->SetTitle(yTitle.Data());
772  g->Draw("AP");
773  g->SetMarkerStyle(20);
774  g->SetMarkerSize(0.8);
775  TAxis* xAxis = g->GetXaxis();
776 
777  TText* t = new TText();
778  t->SetTextAlign(32);
779  t->SetTextSize(0.035);
780  t->SetTextFont(72);
781  TString labels[m_NsetsRed] = {"3", "456F", "456B"};
782  for (Int_t i = 0; i < m_NsetsRed; i++) {
783  xAxis->SetBinLabel(xAxis->FindBin(i + 1), labels[i].Data());
784  }
785 
786  if (list)
787  list->Add(c);
788 
789 }
790 
792 {
793 
794 
795  bool isGood = false;
796 
797  RelationVector<MCParticle> relatVectorTHToMC = thino->getRelationsFrom<MCParticle>();
798 
799  if (relatVectorTHToMC.size() > 0) {
800 
801  m_histoControl_THToMCsize->Fill(relatVectorTHToMC.size());
802 
803  float charge = relatVectorTHToMC[0]->getCharge();
804  bool primary = relatVectorTHToMC[0]->isPrimaryParticle();
805 
806  m_histoControl_MCcharge->Fill(charge);
807  m_histoControl_MCisPrimary->Fill(primary);
808 
809  if (charge != 0 && primary)
810  isGood = true;
811  }
812 
813  return isGood;
814 }
815 
816 
817 
818 
819 
820 
821 
822 
823 
824 
825 
826 
827 
828 
829 
830 
831 
832 
833 
834 
835 
836 
837 
838 
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
RelationVector< FROM > getRelationsFrom(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from another store array to this object.
TH1F * m_histo_StripTimeResolution[m_Nsets]
Vector of histograms depicting Strip Time Residuals.
TList * m_histoList_StripTimeResolution
Lists used to easily Draw the corresponding histos; last one is used to draw the TGraphs.
float m_RMS_GoodTHinClusterTM[m_Nsets]
good true hits in cluster truth matched rms
float m_mean_ClusterTimeResolution[m_Nsets]
average cl time resid
TString NameOfHisto
Strings to pass names of the histos in the vectors of hitos.
TString UVFromIndex(int idx)
Function returning "U" or "V" depending on the index.
int m_NumberOfClustersRelatedToTH[m_Nsets]
number of clusters related to true hits
TString TitleOfHisto
Strings to pass titles of the histos in the vectors of hitos.
TH1F * m_histoControl_MCcharge
Control Histos and List to check if the function used to define a TH as "good" is working fine.
void createArbitraryGraphErrorChooser(const char *name, const char *title, float x[m_Nsets], float xErr[m_Nsets], float y[m_Nsets], float yErr[m_Nsets], TString xTitle, TString yTitle, TList *list, int len)
Function choosing between the two following functions depending on the length of the provided arrays.
TList * m_histoList_PurityInsideTMCluster
histo list truth matched cluster purity (2D)
float m_RMS_ClusterTimeResolution[m_Nsets]
rms cluster time resid
TH1F * m_histo_ClusterUPositionPull[m_NsetsRed]
Vector of histograms depicting Cluster U Position Pull (Reduced length!)
void createArbitraryGraphError_Red(const char *name, const char *title, float x[m_NsetsRed], float xErr[m_NsetsRed], float y[m_NsetsRed], float yErr[m_NsetsRed], TString xTitle, TString yTitle, TList *list)
Function returning an arbitrarly defined TGraph with arrays length equal to m_NsetsRed.
TH1F * m_histo_ClusterUPositionResolution[m_NsetsRed]
Vector of histograms depicting Cluster U Position Residual (Reduced length!)
TList * m_histoList_ClusterTimeResolution
histo list cluster time resolution
int m_NumberOfShaperDigit[m_Nsets]
Vectors used to compute the quantities depicted in Histos and Graphs.
float m_RMS_THinClusterTM[m_Nsets]
true hits in truth matched cluster rms
float m_RMS_THinCluster[m_Nsets]
true hits in cluster rms
virtual void initialize() override
Initialize the SVDClusterEvaluationTrueInfo.
TList * m_histo2DList_TresVsPosres
histo list ime tresol VS position resol
int m_NumberOfTMRecoInNOTMCluster
number of truth matched reco digits in not truth matched clusters
int indexForHistosAndGraphs
Index used for the lists and for the vectors of histograms: it indicates the set of sensors we are lo...
TH1F * m_histo_ClusterVPositionPull[m_NsetsRed]
Vector of histograms depicting Cluster U Position Pull (Reduced length!)
virtual void event() override
This method is the core of the SVDClusterEvaluationTrueInfo.
float m_mean_GoodTHinClusterTM[m_Nsets]
good true hits in cluster truth matched average
int m_NumberOfTMClusters[m_Nsets]
number of truth matched clusters
float m_mean_ClusterVPositionResolution[m_Nsets]
average cl V position reosl
TH2F * createHistogram2D(const char *name, const char *title, Int_t nbinsX, Double_t minX, Double_t maxX, const char *titleX, Int_t nbinsY, Double_t minY, Double_t maxY, const char *titleY, TList *histoList)
Function returning TH2F.
TH1F * m_histo_ClusterTimeResolution_bin1[m_Nsets]
Vector of histograms depicting Cluster Time Residuals, divided by TriggerBin.
TH1F * m_histo_THinCluster[m_Nsets]
Vector of histograms depicting Number of TH inside a Cluster.
virtual void endRun() override
This method is called if the current run ends.
float m_mean_ClusterUPositionResolution[m_Nsets]
average cl U position resol
TH2F * m_histo2D_TresVsPosres[m_Nsets]
Vector of 2D histograms depicting Time Residuals Vs Position (U/V) Residuals for Histos.
virtual void terminate() override
This method is called at the end of the event processing.
TH1F * m_histo_GoodTHinClusterTM[m_Nsets]
Vector of histograms depicting Number of Good TH inside a TM Cluster.
TList * m_histoList_ClusterTimePull
histo list cluster time pull
TList * m_histoList_GoodTHinClusterTMGood
histo list goo true hits in cluster truth match good
float m_RMS_StripTimeResolution[m_Nsets]
rms of strip time residual
float m_mean_THinClusterTM[m_Nsets]
true hits in truth matched cluster average
float m_RMS_ClusterVPositionResolution[m_Nsets]
rms cl V position resol
float m_OrderingVec[m_Nsets]
Vectors used to Draw the TGraphs (defined in the cc) depicting the averages and the means of the hist...
TList * m_histoList_ClusterPositionPull
histo list cluster position pull
TList * m_histo2DList_PurityInsideTMCluster
histo list truth matched cluster purity (2D)
TList * m_histoList_PurityInsideNOTMCluster
histo list not truth matched cluster purity
TH1F * m_histo_PurityInsideTMCluster[m_Nsets]
Vector of histograms depicting Cluster Internal Purity (TM Recos over Reco inside a Cluster)
TString FWFromIndex(int idx)
Function returning "Forward" or "Backword" depending on the index.
virtual void beginRun() override
Called when entering a new run.
TH1F * m_histo_ClusterTimeResolution[m_Nsets]
Vector of histograms depicting Cluster Time Residuals.
TH1F * m_histo_ClusterTimePull[m_Nsets]
Vector of histograms depicting Cluster Time Pull.
int indexFromLayerSensorSide(int LayerNumber, int SensorNumber, int UVNumber)
Function returning the index used for Histos.
static const int m_NsetsRed
numbner of reduced sets
TList * m_histoList_GoodTHinClusterTM
histo list good true hits in cluster truth matched
float m_mean_PurityInsideTMCluster[m_Nsets]
cluster purity average
bool goodTrueHit(const SVDTrueHit *thino)
Function defining if a TH is good (based on charge and primaryness)
float m_RMS_ClusterUPositionResolution[m_Nsets]
rms cl U position resol
TString IntExtFromIndex(int idx)
Function returning "Internal" or "External" depending on the index.
float m_RMS_GoodTHinClusterTMGood[m_Nsets]
good true hits in cluster truth match good rms
std::string m_svdEventInfoName
Name of the SVDEventInfo object.
void createEfficiencyGraph(const char *name, const char *title, int vNum[m_Nsets], int vDen[m_Nsets], TString xTitle, TString yTitle, TList *list)
Function returning a TGraph with Y axis limited to 1 given numerator and denumerator vectors and plot...
TH1F * m_histo_GoodTHinClusterTMGood[m_Nsets]
Vector of histograms depicting Number of Good TH inside a Good TM Cluster.
TH1F * createHistogram1D(const char *name, const char *title, Int_t nbins, Double_t min, Double_t max, const char *xtitle, TList *histoList)
Function returning a TH1F.
TH1F * m_histoControl_THToMCsize
control histo: true hit to mc size
TH1F * m_histo_ClusterVPositionResolution[m_NsetsRed]
Vector of histograms depicting Cluster V Position Residual (Reduced length!)
TList * m_histoList_THinCluster
histo list true hits in cluster
TH2F * m_histo2D_PurityInsideTMCluster[m_Nsets]
Vector of 2D histograms depicting TM Reco Vs Total Reco inside a TM Cluster.
float m_mean_GoodTHinClusterTMGood[m_Nsets]
good true hits in cluster truth match good average
StoreObjPtr< SVDEventInfo > m_storeSVDEvtInfo
Storage for SVDEventInfo object.
TList * m_histoList_ClusterPositionResolution
histo list cluster position resolution
void createArbitraryGraphError_Std(const char *name, const char *title, float x[m_Nsets], float xErr[m_Nsets], float y[m_Nsets], float yErr[m_Nsets], TString xTitle, TString yTitle, TList *list)
Function returning an arbitrarly defined TGraph with arrays length equal to m_Nsets.
TH1F * m_histo_PurityInsideNOTMCluster[m_Nsets]
Vector of histograms depicting TM Cluster Internal Purity (TM Recos over Reco inside a Cluster)
static const int m_Nsets
number of sets: L3-barrel-U, L3-barrel-V, L456-barrel-U, L456-barrel-V, L456-slanted-U,...
int m_NumberOfTMRecoInTMCluster
numnber of true match reco digit in truth match cluster
float m_mean_StripTimeResolution[m_Nsets]
Vectors of floats containing the mean and the RMS from the corresponding histo.
TH1F * m_histo_THinClusterTM[m_Nsets]
Vector of histograms depicting Number of TH inside a TM Cluster.
TList * m_histoList_THinClusterTM
histo list true hits in clsuter truth match
float m_mean_THinCluster[m_Nsets]
true hits in cluster average
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:29
Class to store SVD mode information.
Definition: SVDModeByte.h:69
baseType getTriggerBin() const
Get the triggerBin id.
Definition: SVDModeByte.h:140
The SVD RecoDigit class.
Definition: SVDRecoDigit.h:43
The SVD ShaperDigit class.
Class SVDTrueHit - Records of tracks that either enter or leave the sensitive volume.
Definition: SVDTrueHit.h:33
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
REG_MODULE(arichBtest)
Register the Module.
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
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.