CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ApvLatencyAlgorithm.cc
Go to the documentation of this file.
6 #include "TProfile.h"
7 #include <iostream>
8 #include <cmath>
9 
10 using namespace sistrip;
11 
12 // ----------------------------------------------------------------------------
13 //
15  : CommissioningAlgorithm(anal),
16  histo_(0,"")
17 {;}
18 
19 // ----------------------------------------------------------------------------
20 //
21 void ApvLatencyAlgorithm::extract( const std::vector<TH1*>& histos ) {
22 
23  if ( !anal() ) {
25  << "[ApvLatencyAlgorithm::" << __func__ << "]"
26  << " NULL pointer to Analysis object!";
27  return;
28  }
29 
30  // Check
31  if ( histos.size() != 1 ) {
33  }
34 
35  // Extract FED key from histo title
36  if ( !histos.empty() ) { anal()->fedKey( extractFedKey( histos.front() ) ); }
37 
38  // Extract histograms
39  std::vector<TH1*>::const_iterator ihis = histos.begin();
40  for ( ; ihis != histos.end(); ihis++ ) {
41 
42  // Check for NULL pointer
43  if ( !(*ihis) ) { continue; }
44 
45  // Check name
46  SiStripHistoTitle title( (*ihis)->GetName() );
47  if ( title.runType() != sistrip::APV_LATENCY ) {
49  continue;
50  }
51 
52  // Extract timing histo
53  histo_.first = *ihis;
54  histo_.second = (*ihis)->GetName();
55 
56  }
57 
58 }
59 
60 // ----------------------------------------------------------------------------
61 //
63 
64  if ( !anal() ) {
66  << "[ApvLatencyAlgorithm::" << __func__ << "]"
67  << " NULL pointer to base Analysis object!";
68  return;
69  }
70 
72  ApvLatencyAnalysis* anal = dynamic_cast<ApvLatencyAnalysis*>( tmp );
73  if ( !anal ) {
75  << "[ApvLatencyAlgorithm::" << __func__ << "]"
76  << " NULL pointer to derived Analysis object!";
77  return;
78  }
79 
80  // was in deprecated()
81 
82  std::vector<const TProfile*> histos;
83  std::vector<unsigned short> monitorables;
84 
85  // was in analysis()
86 
87  histos.clear();
88  histos.push_back( const_cast<const TProfile*>( dynamic_cast<TProfile*>(histo_.first) ) );
89  if ( !histos[0] ) {
91  return;
92  }
93 
94  monitorables.clear();
95 
96  //LogDebug("Commissioning|Algorithm") << "[ApvLatencyAlgorithm::analysis]";
97 
98  //extract root histogram
99  //check
100  if (histos.size() != 1) {
101  // edm::LogWarning("Commissioning|Algorithm") << "[ApvLatencyAlgorithm::analysis]: Requires \"const std::vector<const TH1F*>& \" argument to have size 1. Actual size: " << histos.size() << ". Monitorables set to 0.";
102  monitorables.push_back(0);
103  return;
104  }
105  const TProfile* histo = histos[0];
106 
107  //monitorable
108  unsigned short latency;
109 
110  std::vector<unsigned short> binContent; binContent.reserve((unsigned short)histo->GetNbinsX()); binContent.resize((unsigned short)histo->GetNbinsX(), 0);
111 
112  for (unsigned short k = 0; k < (unsigned short)histo->GetNbinsX(); k++) { // k is bin number
113 
114  //fill std::vector with histogram contents
115  binContent.push_back((unsigned int)(histo->GetBinContent(k)));}
116 
117  //calculate median
118 
119  sort(binContent.begin(), binContent.end());
120 
121  //calculate mean and mean2 of the readout within cutoffs
122 
123  float meanNoise = 0.;//M.W method
124  float mean2Noise = 0.;
125 
126  for (unsigned short k = (unsigned short)(binContent.size()*.1); k < (unsigned short)(binContent.size()*.9); k++) {
127  meanNoise += binContent[k];
128  mean2Noise += binContent[k]*binContent[k];;
129  }
130 
131  meanNoise = meanNoise * binContent.size() * 0.8;
132  mean2Noise = mean2Noise * binContent.size() * 0.8;
133  float sigmaNoise = sqrt(fabs(meanNoise*meanNoise - mean2Noise));
134 
135  //loop to look for signal > 5* sigma_noise
136  unsigned short count = 0;
137  unsigned short maxlatency = 0;
138  unsigned int maxhits = 0;
139 
140  for (unsigned short k = 1; k < ((unsigned short)histo->GetNbinsX() + 1); k++) { // k is bin number
141  if (histo->GetBinContent((Int_t)k) > maxhits) maxlatency = k - 1;
142  if ((float)histo->GetBinContent((Int_t)k) > (meanNoise + 5 * sigmaNoise)) {
143  latency = k - 1; count++;
144  }
145  }
146 
147  if (!count) {
148  // LogDebug("Commissioning|Algorithm") << "[ApvLatencyAlgorithm::analysis]: Warning: no signal found > mean + 5*sigma(noise). Returning latency of highest number of recorded hits.";
149  latency = maxlatency;
150  }
151 
152  if (count > 1) {
153  // LogDebug("Commissioning|Algorithm") << "[ApvLatencyAlgorithm::analysis]: Warning: more than one signal found > mean + 5*sigma(noise). Returning latency of highest number of recorded hits.";
154  latency = maxlatency;
155  }
156 
157  //set monitorables
158  monitorables.clear();
159  monitorables.push_back(latency);
160 
161  anal->latency_ = monitorables[0];
162 
163 }
static const char unexpectedTask_[]
const uint32_t & fedKey() const
Utility class that holds histogram title.
const Histo & histo() const
static const char numberOfHistos_[]
static const char mlCommissioning_[]
T sqrt(T t)
Definition: SSEVec.h:48
uint32_t extractFedKey(const TH1 *const )
virtual void addErrorCode(const std::string &error)
void extract(const std::vector< TH1 * > &)
Analysis for APV latency scan.
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
Abstract base for derived classes that provide analysis of commissioning histograms.
CommissioningAnalysis *const anal() const
static const char nullPtr_[]