CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PedestalsTask.cc
Go to the documentation of this file.
8 #include <algorithm>
9 #include <math.h>
10 
11 using namespace sistrip;
12 
13 // -----------------------------------------------------------------------------
14 //
16  const FedChannelConnection& conn ) :
17  CommissioningTask( dqm, conn, "PedestalsTask" ),
18  peds_(),
19  cm_()
20 {
22  << "[PedestalsTask::" << __func__ << "]"
23  << " Constructing object...";
24 }
25 
26 // -----------------------------------------------------------------------------
27 //
30  << "[PedestalsTask::" << __func__ << "]"
31  << " Destructing object...";
32 }
33 
34 // -----------------------------------------------------------------------------
35 //
37  LogTrace(mlDqmSource_) << "[PedestalsTask::" << __func__ << "]";
38 
39  uint16_t nbins;
41  std::string extra_info;
42  peds_.resize(2);
43  nbins = 256;
44 
45  // Pedestals histogram
46  extra_info = sistrip::extrainfo::pedestals_;
47  peds_[0].isProfile_ = true;
48 
52  fedKey(),
54  connection().lldChannel(),
55  extra_info ).title();
56 
57  peds_[0].histo( dqm()->bookProfile( title, title,
58  nbins, -0.5, nbins*1.-0.5,
59  1025, 0., 1025. ) );
60 
61  peds_[0].vNumOfEntries_.resize(nbins,0);
62  peds_[0].vSumOfContents_.resize(nbins,0);
63  peds_[0].vSumOfSquares_.resize(nbins,0);
64 
65  // Noise histogram
66  extra_info = sistrip::extrainfo::noise_;
67  peds_[1].isProfile_ = true;
68 
72  fedKey(),
74  connection().lldChannel(),
75  extra_info ).title();
76 
77  peds_[1].histo( dqm()->bookProfile( title, title,
78  nbins, -0.5, nbins*1.-0.5,
79  1025, 0., 1025. ) );
80 
81  peds_[1].vNumOfEntries_.resize(nbins,0);
82  peds_[1].vSumOfContents_.resize(nbins,0);
83  peds_[1].vSumOfSquares_.resize(nbins,0);
84 
85  // Common mode histograms
86  cm_.resize(2);
87  nbins = 1024;
88  for ( uint16_t iapv = 0; iapv < 2; iapv++ ) {
89 
93  fedKey(),
94  sistrip::APV,
95  connection().i2cAddr(iapv),
97 
98  cm_[iapv].histo( dqm()->book1D( title, title, nbins, -0.5, nbins*1.-0.5 ) );
99  cm_[iapv].isProfile_ = false;
100 
101  cm_[iapv].vNumOfEntries_.resize(nbins,0);
102  cm_[iapv].vNumOfEntries_.resize(nbins,0);
103 
104  }
105 
106 }
107 
108 // -----------------------------------------------------------------------------
109 //
111  const edm::DetSet<SiStripRawDigi>& digis ) {
112 
113  if ( digis.data.size() != peds_[0].vNumOfEntries_.size() ) {
115  << "[PedestalsTask::" << __func__ << "]"
116  << " Unexpected number of digis: "
117  << digis.data.size();
118  return;
119  }
120 
121  // Check number of digis
122  uint16_t nbins = peds_[0].vNumOfEntries_.size();
123  if ( digis.data.size() < nbins ) { nbins = digis.data.size(); }
124 
125  //@@ Inefficient!!!
126  uint16_t napvs = nbins / 128;
127  std::vector<uint32_t> cm; cm.resize(napvs,0);
128 
129  // Calc common mode for both APVs
130  std::vector<uint16_t> adc;
131  for ( uint16_t iapv = 0; iapv < napvs; iapv++ ) {
132  adc.clear(); adc.reserve(128);
133  for ( uint16_t ibin = 0; ibin < 128; ibin++ ) {
134  if ( (iapv*128)+ibin < nbins ) {
135  adc.push_back( digis.data[(iapv*128)+ibin].adc() ); //@@ VIRGIN RAW DATA (MUX, APV READOUT)
136  }
137  }
138  sort( adc.begin(), adc.end() );
139  uint16_t index = adc.size()%2 ? adc.size()/2 : adc.size()/2-1;
140  if ( !adc.empty() ) { cm[iapv] = static_cast<uint32_t>( adc[index] ); }
141  }
142 
143  for ( uint16_t ibin = 0; ibin < nbins; ibin++ ) {
144  updateHistoSet( peds_[0], ibin, digis.data[ibin].adc() ); // peds and raw noise
145  float diff = static_cast<float>( digis.data[ibin].adc() ) - static_cast<float>( cm[ibin/128] );
146  updateHistoSet( peds_[1], ibin, diff ); // residuals and real noise
147  }
148 
149  if ( cm.size() < cm_.size() ) {
151  << "[PedestalsTask::" << __func__ << "]"
152  << " Fewer CM values than expected: " << cm.size();
153  }
154 
155  updateHistoSet( cm_[0], cm[0] );
156  updateHistoSet( cm_[1], cm[1] );
157 
158 }
159 
160 // -----------------------------------------------------------------------------
161 //
163 
164  // Pedestals
165  updateHistoSet( peds_[0] );
166 
167  // Noise (cannot use HistoSet directly, as want to plot noise as "contents", not "error")
168  TProfile* histo = ExtractTObject<TProfile>().extract( peds_[1].histo() );
169  for ( uint16_t ii = 0; ii < peds_[1].vNumOfEntries_.size(); ++ii ) {
170 
171  float mean = 0.;
172  float spread = 0.;
173  float entries = peds_[1].vNumOfEntries_[ii];
174  if ( entries > 0. ) {
175  mean = peds_[1].vSumOfContents_[ii] / entries;
176  spread = sqrt( peds_[1].vSumOfSquares_[ii] / entries - mean * mean );
177  }
178 
179  float noise = spread;
180  float error = 0; // sqrt(entries) / entries;
181 
182  UpdateTProfile::setBinContent( histo, ii+1, entries, noise, error );
183 
184  }
185 
186  // Common mode
187  updateHistoSet( cm_[0] );
188  updateHistoSet( cm_[1] );
189 
190 }
191 
int adc(sample_type sample)
get the ADC sample (12 bits)
static const char noise_[]
Utility class that holds histogram title.
const std::string & title() const
static const char mlDqmSource_[]
virtual void book()
virtual void update()
int ii
Definition: cuy.py:588
void updateHistoSet(HistoSet &, const uint32_t &bin, const float &value)
PedestalsTask(DQMStore *, const FedChannelConnection &)
Class containning control, module, detector and connection information, at the level of a FED channel...
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< HistoSet > peds_
Definition: PedestalsTask.h:24
static void setBinContent(TProfile *const profile, const uint32_t &bin, const double &entries, const double &mean, const double &spread)
static const char commonMode_[]
#define LogTrace(id)
std::vector< HistoSet > cm_
Definition: PedestalsTask.h:25
int extract(std::vector< int > *output, const std::string &dati)
static const char pedestals_[]
DQMStore *const dqm() const
virtual ~PedestalsTask()
collection_type data
Definition: DetSet.h:78
const uint32_t & fedKey() const
const FedChannelConnection & connection() const
virtual void fill(const SiStripEventSummary &, const edm::DetSet< SiStripRawDigi > &)