CMS 3D CMS Logo

NoiseTask.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <ostream>
3 
17 
19 
20 using namespace sistrip;
21 
22 std::ostream &operator <<( std::ostream &rOut,
24 {
25  for( ApvAnalysis::PedestalType::const_iterator pedsIter = rPEDS.begin();
26  pedsIter != rPEDS.end();
27  ++pedsIter)
28  {
29  rOut << ' ' << *pedsIter;
30  }
31 
32  return rOut;
33 }
34 
35 // -----------------------------------------------------------------------------
36 //
38  const FedChannelConnection &conn)
39  : CommissioningTask( dqm, conn, "NoiseTask")
40 {
41  //@@ NOT GUARANTEED TO BE THREAD SAFE!
42  pApvFactory_ = edm::Service<ApvFactoryService>().operator->()->getApvFactory();
43 
45  << "[NoiseTask::" << __func__ << "]"
46  << " Constructing object...";
47 }
48 
49 // -----------------------------------------------------------------------------
50 //
52 {
54  << "[NoiseTask::" << __func__ << "]"
55  << " Destructing object...";
56 
57  // Have to delete pApvFactory_ manually even though we didn't create it
58  // ourself. :(
59  if( pApvFactory_) { delete pApvFactory_; }
60 }
61 
62 // -----------------------------------------------------------------------------
63 //
65 {
66  LogTrace( mlDqmSource_) << "[NoiseTask::" << __func__ << "]";
67 
68  // CACHING
69  static std::auto_ptr<SiStripPedestals> pDBPedestals;
70  static std::auto_ptr<SiStripNoises> pDBNoises;
71 
72  const uint16_t nBINS = 256;
73 
74  {
75  // Pedestals
79  fedKey(),
81  connection().lldChannel(),
83 
84  HistoSet oHSet;
85  oHSet.isProfile_ = true;
86 
87  oHSet.vNumOfEntries_.resize( nBINS, 0);
88  oHSet.vSumOfContents_.resize( nBINS, 0);
89  oHSet.vSumOfSquares_.resize( nBINS, 0);
90 
91  oHSet.histo( dqm()->bookProfile( title, title,
92  nBINS, -0.5, nBINS * 1. - 0.5,
93  1025, 0., 1025.) );
94 
95  peds_.push_back( oHSet);
96  }
97 
98  {
99  // Corrected Noise
103  fedKey(),
105  connection().lldChannel(),
107 
108  HistoSet oHSet;
109  oHSet.isProfile_ = true;
110 
111  oHSet.vNumOfEntries_.resize( nBINS, 0);
112  oHSet.vSumOfContents_.resize( nBINS, 0);
113  oHSet.vSumOfSquares_.resize( nBINS, 0);
114 
115  oHSet.histo( dqm()->bookProfile( title, title,
116  nBINS, -0.5, nBINS * 1. - 0.5,
117  1025, 0., 1025.) );
118 
119  peds_.push_back( oHSet);
120  }
121 
122  const uint16_t nCM_BINS = 1024;
123  for( uint16_t nApv = 0; 2 > nApv; ++nApv)
124  {
128  fedKey(),
129  sistrip::APV,
130  connection().i2cAddr( nApv),
132 
133  HistoSet oHSet;
134 
135  oHSet.isProfile_ = false;
136 
137  oHSet.vNumOfEntries_.resize( nCM_BINS, 0);
138 
139  oHSet.histo( dqm()->book1D( title, title,
140  nCM_BINS,
141  nCM_BINS/2 * -1. - 0.5,
142  nCM_BINS/2 * 1. - 0.5 ) );
143 
144  cm_.push_back( oHSet);
145  }
146 
147  // Initialize Apv
148  pApvFactory_->instantiateApvs( connection().detId(), connection().nApvs() );
149 
150  // --[ RETRIEVE PEDESTALS FROM DB ]--
151  // Operation should be performed only once
152  if( !pDBPedestals.get()) {
154  << "[NoiseTask::" << __func__ << "] "
155  << "Retrieving Pedestals from DB";
156 
157  // Directly retrieve Pedestals from EventSetup
159  eventSetup()->get<SiStripPedestalsRcd>().get( pedestals);
160 
161  // Cache Pedestals
162  pDBPedestals.reset( new SiStripPedestals( *pedestals) );
163 
165  << "[NoiseTask::" << __func__ << "] "
166  << "Done Retrieving Pedestals from DB";
167  } // End retrieve Pedestals from DB
168 
169  // --[ RETRIEVE NOISES FROM DB ]--
170  // Operation should be performed only once
171  if( !pDBNoises.get()) {
173  << "[NoiseTask::" << __func__ << "] "
174  << "Retrieving Noises from DB";
175 
176  // Directly retrieve Noises from EventSetup
178  eventSetup()->get<SiStripNoisesRcd>().get( noises);
179 
180  // Cache Pedestals
181  pDBNoises.reset( new SiStripNoises( *noises) );
182 
184  << "[NoiseTask::" << __func__ << "] "
185  << "Done Retrieving Noises from DB";
186  } // End retrieve Noises from DB
187 
188 
189  // Get ApvAnalysis associated with given DetId
191  apvAnalysisVector( pApvFactory_->getApvAnalysis( connection().detId()));
192 
193  SiStripPedestals::Range pedestalsRange(
194  pDBPedestals->getRange( connection().detId() ) );
195  SiStripNoises::Range noisesRange(
196  pDBNoises->getRange( connection().detId() ) );
197 
198  // Cache Apv Pair #
199  const uint16_t nAPV_PAIR = connection().apvPairNumber();
200 
201  for( uint16_t nLclApv = 0; 2 > nLclApv; ++nLclApv) {
202  // Retrieve pedestals and noises associated with given DetId/Apv
203  ApvAnalysis::PedestalType pedestals;
205  for( uint16_t nStrip = nAPV_PAIR * 256 + nLclApv * 128,
206  nMaxStrip = nStrip + 128;
207  nMaxStrip > nStrip;
208  ++nStrip)
209  {
210  pedestals.push_back( pDBPedestals->getPed( nStrip, pedestalsRange));
211  noises.push_back( pDBNoises->getNoise( nStrip, noisesRange));
212  }
213 
214  try {
215  // Checked access
217  apvAnalysisVector.at( nAPV_PAIR * 2 + nLclApv);
218 
219  rApvAnalysis->pedestalCalculator().setPedestals( pedestals);
220  rApvAnalysis->pedestalCalculator().setNoise( noises);
221 
222  /*
223  std::stringstream out;
224  LogTrace( mlDqmSource_)
225  << "[NoiseTask::" << __func__ << "] "
226  << "DetId|Apv# -> "
227  << connection().detId() << '|' << ( nAPV_PAIR * 2 + nLclApv)
228  << " Pedestals: "
229  << ( out << pedestals
230  << " Noises: " << noises, out.str());
231  */
232  } catch( std::out_of_range) {
233  // Hmm, didn't find appropriate Apv :((( -> VERY, VERY BAD
235  << "[NoiseTask::" << __func__ << "] "
236  << "Could not set Pedestals/Noises for DetId|Apv# -> "
237  << connection().detId() << '|' << ( nAPV_PAIR * 2 + nLclApv)
238  << ". !!! POSSIBLE BUG !!!";
239  } // End Try block
240  } // End Local Apvs loop
241 }
242 
243 // -----------------------------------------------------------------------------
244 //
245 void NoiseTask::fill( const SiStripEventSummary &rSummary,
246  const edm::DetSet<SiStripRawDigi> &rDigis)
247 {
248  pApvFactory_->updatePair( connection().detId(),
249  connection().apvPairNumber(),
250  rDigis);
251 }
252 
253 // -----------------------------------------------------------------------------
254 //
256 {
257  static UpdateTProfile updateTProfile;
258 
259  TProfile *pedsProf = ExtractTObject<TProfile>().extract( peds_[0].histo() );
260  TProfile *noiseProf = ExtractTObject<TProfile>().extract( peds_[1].histo() );
261 
262  for( uint16_t nLclApv = 2 * connection().apvPairNumber(),
263  nMaxLclApv = nLclApv + 2,
264  nApv = 0;
265  nMaxLclApv > nLclApv;
266  ++nLclApv, ++nApv)
267  {
268  ApvAnalysis::PedestalType lclPedestals;
269  ApvAnalysis::PedestalType lclNoises;
270  ApvAnalysis::PedestalType lclCommonMode(
271  pApvFactory_->getCommonMode( connection().detId(), nLclApv) );
272 
273  pApvFactory_->getPedestal ( connection().detId(), nLclApv, lclPedestals);
274  pApvFactory_->getNoise ( connection().detId(), nLclApv, lclNoises );
275 
276  const uint16_t nSTART_BIN = 128 * ( nLclApv % 2);
277 
278  for( uint16_t nBin = 0,
279  nAbsBin = nSTART_BIN + nBin + 1;
280  128 > nBin;
281  ++nBin, ++nAbsBin)
282  {
283  updateTProfile.setBinContent( pedsProf, nAbsBin, 5,
284  lclPedestals[nBin], lclNoises[nBin]);
285  updateTProfile.setBinContent( noiseProf, nAbsBin, 5,
286  lclNoises[nBin], 0);
287  } // End loop over BINs
288 
289  // Samvel: Assume Once CM value is calculated per chip.
290  // In principle Chip can be divided into a several ranges. Then CM
291  // will be calculated per range. !!! UPDATE CODE THEN !!!
292  for( ApvAnalysis::PedestalType::const_iterator cmIterator
293  = lclCommonMode.begin();
294  cmIterator != lclCommonMode.end();
295  ++cmIterator)
296  {
297  //uint32_t nCM = static_cast<uint32_t>( *cmIterator);
298  //if( nCM >= 1024) nCM = 1023;
299  //updateHistoSet( cm_[nApv], nCM);
300  float nCM = static_cast<float>( *cmIterator );
301  updateHistoSet( cm_[nApv], nCM );
302  }
303 
304  std::stringstream out;
306  << "[NoiseTask::" << __func__ << "] "
307  << "DET ID [" << connection().detId()
308  << "] has Common Mode size " << lclCommonMode.size() << " : "
309  << ( out << lclCommonMode, out.str());
310  } // End loop over Local Apvs
311 
312  updateHistoSet( cm_[0]);
313  updateHistoSet( cm_[1]);
314 }
static const char noise_[]
NoiseTask(DQMStore *, const FedChannelConnection &)
Definition: NoiseTask.cc:37
std::vector< float > vNumOfEntries_
void update() override
Definition: NoiseTask.cc:255
std::vector< float > PedestalType
Definition: ApvAnalysis.h:48
Utility class that holds histogram title.
const std::string & title() const
void getPedestal(uint32_t det_id, int apvNumber, ApvAnalysis::PedestalType &peds)
void getNoise(uint32_t det_id, int apvNumber, ApvAnalysis::PedestalType &noise)
static const char mlDqmSource_[]
uint16_t apvPairNumber() const
std::vector< float > vSumOfContents_
ApvAnalysisFactory * pApvFactory_
Definition: NoiseTask.h:34
std::pair< ContainerIterator, ContainerIterator > Range
std::ostream & operator<<(std::ostream &os, const FEDBufferFormat &value)
sistrip classes
void updateHistoSet(HistoSet &, const uint32_t &bin, const float &value)
void updatePair(uint32_t det_id, size_t apvPair, const edm::DetSet< SiStripRawDigi > &in)
const uint32_t & detId() const
Class containning control, module, detector and connection information, at the level of a FED channel...
bool instantiateApvs(uint32_t det_id, int numberOfApvs)
std::vector< HistoSet > cm_
Definition: NoiseTask.h:32
static void setBinContent(TProfile *const profile, const uint32_t &bin, const double &entries, const double &mean, const double &spread)
static const char commonMode_[]
void fill(const SiStripEventSummary &, const edm::DetSet< SiStripRawDigi > &) override
Definition: NoiseTask.cc:245
#define LogTrace(id)
void getCommonMode(uint32_t det_id, ApvAnalysis::PedestalType &tmp)
std::vector< HistoSet > peds_
Definition: NoiseTask.h:31
int extract(std::vector< int > *output, const std::string &dati)
static const char pedestals_[]
DQMStore *const dqm() const
~NoiseTask() override
Definition: NoiseTask.cc:51
ApvAnalysisVector getApvAnalysis(const uint32_t nDET_ID)
void histo(MonitorElement *)
T get() const
Definition: EventSetup.h:63
const edm::EventSetup *const eventSetup() const
void book() override
Definition: NoiseTask.cc:64
const uint32_t & fedKey() const
std::vector< double > vSumOfSquares_
const FedChannelConnection & connection() const
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:50
std::vector< ApvAnalysis * > ApvAnalysisVector