CMS 3D CMS Logo

OptoScanTask.cc
Go to the documentation of this file.
6 #include <algorithm>
7 #include <cmath>
8 
10 #include <iomanip>
11 
12 
13 using namespace sistrip;
14 
15 
16 // -----------------------------------------------------------------------------
17 //
19  const FedChannelConnection & conn ) :
20  CommissioningTask( dqm, conn, "OptoScanTask" ),
21  opto_() {
22 }
23 
24 
25 // -----------------------------------------------------------------------------
26 //
28 }
29 
30 
31 // -----------------------------------------------------------------------------
32 //
34 
35  uint16_t nbins = 50;
36  uint16_t gains = 4;
37 
38  // Resize "histo sets"
39  opto_.resize( gains );
40  for ( uint16_t igain = 0; igain < opto_.size(); igain++ ) {
41  opto_[igain].resize(3);
42  }
43 
44  for ( uint16_t igain = 0; igain < opto_.size(); igain++ ) {
45  for ( uint16_t ihisto = 0; ihisto < 3; ihisto++ ) {
46 
47  // Extra info
48  std::stringstream extra_info;
49  extra_info << sistrip::extrainfo::gain_ << igain;
50  if ( ihisto == 0 || ihisto == 1 ) {
51  extra_info << sistrip::extrainfo::digital_ << ihisto;
52  } else {
54  }
55 
56  // Title
60  fedKey(),
62  connection().lldChannel(),
63  extra_info.str() ).title();
64 
65  // Book histo
66  opto_[igain][ihisto].histo( dqm()->bookProfile( title, title,
67  nbins, 0.5, nbins*1.+0.5, // range is bias setting (1-50)
68  1024, -0.5, 1023.5 ) );
69 
70  opto_[igain][ihisto].vNumOfEntries_.resize(nbins,0);
71  opto_[igain][ihisto].vSumOfContents_.resize(nbins,0);
72  opto_[igain][ihisto].vSumOfSquares_.resize(nbins,0);
73 
74  } // end loop on histos
75  } // end loop on gains
76 
77 }
78 
79 
80 // -----------------------------------------------------------------------------
81 //
83  const edm::DetSet<SiStripRawDigi> & digis ) {
84 
85  //@@ if scope mode length is in trigger fed, then
86  //@@ can add check here on number of digis
87  if ( digis.data.empty() ) {
89  << "[OptoScanTask::" << __func__ << "]"
90  << " Unexpected number of digis! "
91  << digis.data.size();
92  } else {
93 
94  // Retrieve opt bias and gain setting from SiStripEventSummary
95  uint16_t gain = summary.lldGain();
96  uint16_t bias = summary.lldBias();
97 
98  if ( gain >= opto_.size() ) {
99  opto_.resize( gain );
100  for ( uint16_t igain = 0; igain < opto_.size(); igain++ ) {
101  if ( opto_[gain].size() != 3 ) { opto_[gain].resize( 3 ); }
102  }
104  << "[OptoScanTask::" << __func__ << "]"
105  << " Unexpected gain value! " << gain;
106  }
107 
108  if ( bias > 50 ) { return; } // only use bias settings 1-50
109 
110  // Find digital "0" and digital "1" levels from tick marks within scope mode data
111  std::vector<float> baseline;
112  std::pair<float,float> digital_range;
113  digital_range.first = sistrip::invalid_;
114  digital_range.second = sistrip::invalid_;
115  float baseline_rms = sistrip::invalid_;
116 
117  locateTicks( digis, digital_range, baseline, baseline_rms );
118 
119  uint16_t bin = bias - 1; // fill "bins" (0-49), not bias (1-50)
120 
121  // Digital "0"
122  if ( digital_range.first < 1. * sistrip::valid_ ) {
123  updateHistoSet( opto_[gain][0], bin, digital_range.first );
124  }
125 
126  // Digital "1"
127  if ( digital_range.second < 1. * sistrip::valid_ ) {
128  updateHistoSet( opto_[gain][1], bin, digital_range.second );
129  }
130 
131  // Baseline rms
132  if ( baseline_rms < 1. * sistrip::valid_ ) {
133  updateHistoSet( opto_[gain][2], bin, baseline_rms );
134  }
135 
136  }
137 
138 }
139 
140 
141 // -----------------------------------------------------------------------------
142 //
144 
145  for ( uint16_t igain = 0; igain < opto_.size(); igain++ ) {
146  for ( uint16_t ihisto = 0; ihisto < opto_[igain].size(); ihisto++ ) {
147  updateHistoSet( opto_[igain][ihisto] );
148  }
149  }
150 
151 }
152 
153 
154 // -----------------------------------------------------------------------------
155 //
157  std::pair<float,float> & range,
158  std::vector<float> & baseline,
159  float & baseline_rms ) {
160 
161  // Copy ADC values and sort
162  std::vector<uint16_t> adc;
163  adc.reserve( digis.data.size() );
164  for ( uint16_t iadc = 0; iadc < digis.data.size(); iadc++ ) {
165  // only take the adc from the first APV (multiplexing alternates the digis)
166  // this was asked by Karl et al
167  if (iadc % 2 == 0) {
168  adc.push_back( digis.data[iadc].adc() );
169  }
170  }
171  sort( adc.begin(), adc.end() );
172 
173  // To make sure we have a tickmark, which comes every 70 bxs,
174  // fully contained in the scope 'frame' we are analyzing
175  // standard length is 280, sufficient to contain a full apv frame
176  // in this run there is no frame though, just baseline and tickmarks
177  if ( adc.size() > 70 ) {
178 
179  // Define tick mark top" level as "max" ADC values
180  range.second = adc.back();
181 
182  // Construct vector to hold "baseline samples" (exclude tick mark samples)
183  std::vector<uint16_t> truncated;
184  std::vector<uint16_t>::const_iterator ii = adc.begin();
185  // remove twice the expected number of tick samples, otherwise you bias the baseline mean and rms
186  std::vector<uint16_t>::const_iterator jj = adc.end() - 4 * ( ( adc.size() / 70 ) + 1 );
187  truncated.resize( jj - ii );
188  std::copy( ii, jj, truncated.begin() );
189  if ( truncated.empty() ) { return; }
190 
191  // Calc mean baseline level
192  float b_mean = 0.;
193  std::vector<uint16_t>::const_iterator iii = truncated.begin();
194  std::vector<uint16_t>::const_iterator jjj = truncated.end();
195  for ( ; iii != jjj; ++iii ) { b_mean += *iii; }
196  b_mean /= ( 1. * truncated.size() );
197  range.first = b_mean;
198 
199  // Calc baseline noise
200  float b_rms = 0.;
201  std::vector<uint16_t>::const_iterator iiii = truncated.begin();
202  std::vector<uint16_t>::const_iterator jjjj = truncated.end();
203  for ( ; iiii != jjjj; ++iiii ) { b_rms += fabs( *iiii - b_mean ); }
204  // Set baseline "noise" (requires any possible APV frames are filtered from the data!)
205  baseline_rms = sqrt ( b_rms / ( 1. * truncated.size() ) );
206 
207  } else {
209  << "[OptoScanTask::" << __func__ << "]"
210  << " Insufficient ADC values: " << adc.size();
211  }
212 
213 }
int adc(sample_type sample)
get the ADC sample (12 bits)
size
Write out results.
Utility class that holds histogram title.
~OptoScanTask() override
Definition: OptoScanTask.cc:27
std::vector< std::vector< HistoSet > > opto_
Definition: OptoScanTask.h:28
static const char mlDqmSource_[]
static const uint16_t valid_
Definition: Constants.h:17
const uint32_t & lldGain() const
sistrip classes
const uint32_t & lldBias() const
void updateHistoSet(HistoSet &, const uint32_t &bin, const float &value)
static const char baselineRms_[]
Class containning control, module, detector and connection information, at the level of a FED channel...
T sqrt(T t)
Definition: SSEVec.h:18
void book() override
Definition: OptoScanTask.cc:33
static const char digital_[]
void fill(const SiStripEventSummary &summary, const edm::DetSet< SiStripRawDigi > &digis) override
Definition: OptoScanTask.cc:82
ii
Definition: cuy.py:588
bin
set the eta bin as selection string.
OptoScanTask(DQMStore *dqm, const FedChannelConnection &conn)
Definition: OptoScanTask.cc:18
DQMStore *const dqm() const
static const uint16_t invalid_
Definition: Constants.h:16
collection_type data
Definition: DetSet.h:78
static const char gain_[]
const uint32_t & fedKey() const
const FedChannelConnection & connection() const
void locateTicks(const edm::DetSet< SiStripRawDigi > &scope_mode_data, std::pair< float, float > &digital_range, std::vector< float > &baseline, float &baseline_rms)
void update() override