ATLAS Offline Software
SCTTrackTiming.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 
9 #include <TH1.h>
10 #include <TClass.h>
11 
12 #include "dqm_core/exceptions.h"
13 #include "dqm_core/AlgorithmManager.h"
14 #include "dqm_core/AlgorithmConfig.h"
15 #include "dqm_core/Result.h"
16 #include <cmath>
17 #include <iostream>
18 #include <map>
19 
20 static dqm_algorithms::SCTTrackTiming staticInstance;
21 
22 namespace dqm_algorithms {
23 
24  // *********************************************************************
25  // Public Methods
26  // *********************************************************************
27 
28  void
30  printDescription(std::ostream& out)
31  {
32  std::string message;
33  message += "\n";
34  message += "Algorithm: \"" + m_name + "\"\n";
35  message += "Description: For use with SCT Track Time Bins ONLY!\n";
36  message += " Prints the ratio of 010 : 01X hits.\n";
37  message += " Prints the mean hit time, with 100 as -1 BunchCrossing (early) and 001 as +1 BunchCrossing (late)\n";
38  message += " where 011 would contribute half a hit to 0 BC (timed in) and half a hit to +1 BC (late)\n";
39  message += " and the hit patterns 000, 111, and 101 will be ignored.\n";
40  message += "\n";
41 
42  out << message;
43  }
44 
47  : m_name("SCTTrackTiming")
48  , m_NbinsX(8)
49  {
50  dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
51  }
52 
53 
56  clone()
57  {
58  return new SCTTrackTiming(*this);
59  }
60 
61 
64  execute( const std::string& name, const TObject& data, const dqm_core::AlgorithmConfig& /* config */)
65  {
66  //No status flags are set
69 
70  const TH1* h;
71  if(data.IsA()->InheritsFrom( "TH1" )) {
72  h = static_cast<const TH1*>(&data);
73  if (h->GetDimension() > 1 ) {
74  throw dqm_core::BadConfig( ERS_HERE, name, "Not SCT Time Bins: Hist. Dimension > 1 " );
75  }
76  if (h->GetNbinsX() != 8) {
77  throw dqm_core::BadConfig( ERS_HERE, name, "Not SCT Time Bins: Hist. NBins != 8 " );
78  }
79  } else {
80  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1");
81  }
82 
83  //Histogram is assumed to be SCT Time Bins.
84  m_NbinsX = 8;
85 
86  //Get the ratio & average for hit times
87  double Hits010 = 0.;
88  double Hits011 = 0.;
89  double EarlyHits = 0.;
90  double InTimeHits = 0.;
91  double LateHits = 0.;
92  double AllEntries = 0.;
93 
94  double TBin = 0.;
95 
96  TBin = h->GetBinContent(0+1); //000
97  AllEntries += TBin;
98 
99  TBin = h->GetBinContent(1+1); //001
100  LateHits += TBin;
101  AllEntries += TBin;
102 
103  TBin = h->GetBinContent(2+1); //010
104  Hits010 += TBin;
105  InTimeHits += TBin;
106  AllEntries += TBin;
107 
108  TBin = h->GetBinContent(3+1); //011
109  Hits011 += TBin;
110  InTimeHits += TBin/2;
111  LateHits += TBin/2;
112  AllEntries += TBin;
113 
114  TBin = h->GetBinContent(4+1); //100
115  EarlyHits += TBin;
116  AllEntries += TBin;
117 
118  TBin = h->GetBinContent(5+1); //101
119  AllEntries += TBin;
120 
121  TBin = h->GetBinContent(6+1); //110
122  EarlyHits += TBin/2;
123  InTimeHits += TBin/2;
124  AllEntries += TBin;
125 
126  TBin = h->GetBinContent(7+1); //111
127  AllEntries += TBin;
128 
129  //NOTE: If some quantity cannot be calculated it should not be printed at all.
130  //Printing a default value will simply skew the scale of history plots.
131 
132  if (Hits010 + Hits011 > 0.) { //sufficient entries
133  double HitBin_ratio = Hits010 / (Hits010 + Hits011);
134  std::string HitBin_ratio_name = Form("%s_Ratio_010_over_01X", name.c_str());
135  result->tags_[HitBin_ratio_name.c_str()] = HitBin_ratio;
136  }
137 
138  if (AllEntries > 0.) { //sufficient entries
139  double Edge0_ratio = Hits010 / AllEntries;
140  std::string Edge0_name = Form("%s_Ratio_010_over_XXX", name.c_str());
141  result->tags_[Edge0_name.c_str()] = Edge0_ratio;
142  }
143 
144  if (AllEntries > 0.) { //sufficient entries
145  double Edge1_ratio = Hits011 / AllEntries;
146  std::string Edge1_name = Form("%s_Ratio_011_over_XXX", name.c_str());
147  result->tags_[Edge1_name.c_str()] = Edge1_ratio;
148  }
149 
150  if (AllEntries > 0.) { //sufficient entries
151  double EdgeX_ratio = (Hits010 + Hits011) / AllEntries;
152  std::string EdgeX_name = Form("%s_Ratio_01X_over_XXX", name.c_str());
153  result->tags_[EdgeX_name.c_str()] = EdgeX_ratio;
154  }
155 
156  if (LateHits + InTimeHits + EarlyHits > 0.) { //sufficient entries
157  double HitMean_time = (LateHits - EarlyHits) / (LateHits + InTimeHits + EarlyHits);
158  std::string HitMean_name = Form("%s_MeanHitTimeBC", name.c_str());
159  result->tags_[HitMean_name.c_str()] = HitMean_time;
160 
161  double HitWidth_time = (LateHits + EarlyHits) / (LateHits + InTimeHits + EarlyHits);
162  HitWidth_time = std::sqrt(HitWidth_time - HitMean_time*HitMean_time);
163  std::string HitWidth_name = Form("%s_VarianceHitTimeBC", name.c_str());
164  result->tags_[HitWidth_name.c_str()] = HitWidth_time;
165  }
166 
167  return result;
168  }
169 
170 }
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
Undefined
@ Undefined
Definition: MaterialTypes.h:8
get_generator_info.result
result
Definition: get_generator_info.py:21
dqm_algorithms::SCTTrackTiming::execute
virtual dqm_core::Result * execute(const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config)
Definition: SCTTrackTiming.cxx:64
dqm_algorithms::SCTTrackTiming::m_name
std::string m_name
Definition: SCTTrackTiming.h:31
python.FakeAthena.Algorithm
def Algorithm(name)
Definition: FakeAthena.py:41
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
dqm_algorithms::SCTTrackTiming::m_NbinsX
int m_NbinsX
Definition: SCTTrackTiming.h:33
dqm_algorithms::SCTTrackTiming
Definition: SCTTrackTiming.h:16
ReweightUtils.message
message
Definition: ReweightUtils.py:15
SCTTrackTiming.h
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
dqm_algorithms::SCTTrackTiming::printDescription
void printDescription(std::ostream &out)
Definition: SCTTrackTiming.cxx:30
extractSporadic.h
list h
Definition: extractSporadic.py:97
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
dqm_algorithms::SCTTrackTiming::clone
virtual dqm_core::Algorithm * clone()
Definition: SCTTrackTiming.cxx:56
dqm_algorithms::SCTTrackTiming::SCTTrackTiming
SCTTrackTiming()
Definition: SCTTrackTiming.cxx:46
dqm_algorithms
Definition: AddReference.h:17
h
TH1
Definition: rootspy.cxx:268