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, ApvAnalysis::PedestalType &rPEDS) {
23  for (ApvAnalysis::PedestalType::const_iterator pedsIter = rPEDS.begin(); pedsIter != rPEDS.end(); ++pedsIter) {
24  rOut << ' ' << *pedsIter;
25  }
26 
27  return rOut;
28 }
29 
30 // -----------------------------------------------------------------------------
31 //
33  //@@ NOT GUARANTEED TO BE THREAD SAFE!
34  pApvFactory_ = edm::Service<ApvFactoryService>().operator->()->getApvFactory();
35 
36  LogTrace(mlDqmSource_) << "[NoiseTask::" << __func__ << "]"
37  << " Constructing object...";
38 }
39 
40 // -----------------------------------------------------------------------------
41 //
43  LogTrace(mlDqmSource_) << "[NoiseTask::" << __func__ << "]"
44  << " Destructing object...";
45 
46  // Have to delete pApvFactory_ manually even though we didn't create it
47  // ourself. :(
48  if (pApvFactory_) {
49  delete pApvFactory_;
50  }
51 }
52 
53 // -----------------------------------------------------------------------------
54 //
56  LogTrace(mlDqmSource_) << "[NoiseTask::" << __func__ << "]";
57 
58  // CACHING
59  static std::unique_ptr<SiStripPedestals> pDBPedestals;
60  static std::unique_ptr<SiStripNoises> pDBNoises;
61 
62  const uint16_t nBINS = 256;
63 
64  {
65  // Pedestals
69  fedKey(),
71  connection().lldChannel(),
73  .title();
74 
75  HistoSet oHSet;
76  oHSet.isProfile_ = true;
77 
78  oHSet.vNumOfEntries_.resize(nBINS, 0);
79  oHSet.vSumOfContents_.resize(nBINS, 0);
80  oHSet.vSumOfSquares_.resize(nBINS, 0);
81 
82  oHSet.histo(dqm()->bookProfile(title, title, nBINS, -0.5, nBINS * 1. - 0.5, 1025, 0., 1025.));
83 
84  peds_.push_back(oHSet);
85  }
86 
87  {
88  // Corrected Noise
92  fedKey(),
94  connection().lldChannel(),
96  .title();
97 
98  HistoSet oHSet;
99  oHSet.isProfile_ = true;
100 
101  oHSet.vNumOfEntries_.resize(nBINS, 0);
102  oHSet.vSumOfContents_.resize(nBINS, 0);
103  oHSet.vSumOfSquares_.resize(nBINS, 0);
104 
105  oHSet.histo(dqm()->bookProfile(title, title, nBINS, -0.5, nBINS * 1. - 0.5, 1025, 0., 1025.));
106 
107  peds_.push_back(oHSet);
108  }
109 
110  const uint16_t nCM_BINS = 1024;
111  for (uint16_t nApv = 0; 2 > nApv; ++nApv) {
115  fedKey(),
116  sistrip::APV,
117  connection().i2cAddr(nApv),
119  .title();
120 
121  HistoSet oHSet;
122 
123  oHSet.isProfile_ = false;
124 
125  oHSet.vNumOfEntries_.resize(nCM_BINS, 0);
126 
127  oHSet.histo(dqm()->book1D(title, title, nCM_BINS, nCM_BINS / 2 * -1. - 0.5, nCM_BINS / 2 * 1. - 0.5));
128 
129  cm_.push_back(oHSet);
130  }
131 
132  // Initialize Apv
133  pApvFactory_->instantiateApvs(connection().detId(), connection().nApvs());
134 
135  // --[ RETRIEVE PEDESTALS FROM DB ]--
136  // Operation should be performed only once
137  if (!pDBPedestals.get()) {
138  LogTrace(mlDqmSource_) << "[NoiseTask::" << __func__ << "] "
139  << "Retrieving Pedestals from DB";
140 
141  // Directly retrieve Pedestals from EventSetup
143  eventSetup()->get<SiStripPedestalsRcd>().get(pedestals);
144 
145  // Cache Pedestals
146  pDBPedestals.reset(new SiStripPedestals(*pedestals));
147 
148  LogTrace(mlDqmSource_) << "[NoiseTask::" << __func__ << "] "
149  << "Done Retrieving Pedestals from DB";
150  } // End retrieve Pedestals from DB
151 
152  // --[ RETRIEVE NOISES FROM DB ]--
153  // Operation should be performed only once
154  if (!pDBNoises.get()) {
155  LogTrace(mlDqmSource_) << "[NoiseTask::" << __func__ << "] "
156  << "Retrieving Noises from DB";
157 
158  // Directly retrieve Noises from EventSetup
160  eventSetup()->get<SiStripNoisesRcd>().get(noises);
161 
162  // Cache Pedestals
163  pDBNoises.reset(new SiStripNoises(*noises));
164 
165  LogTrace(mlDqmSource_) << "[NoiseTask::" << __func__ << "] "
166  << "Done Retrieving Noises from DB";
167  } // End retrieve Noises from DB
168 
169  // Get ApvAnalysis associated with given DetId
171 
172  SiStripPedestals::Range pedestalsRange(pDBPedestals->getRange(connection().detId()));
173  SiStripNoises::Range noisesRange(pDBNoises->getRange(connection().detId()));
174 
175  // Cache Apv Pair #
176  const uint16_t nAPV_PAIR = connection().apvPairNumber();
177 
178  for (uint16_t nLclApv = 0; 2 > nLclApv; ++nLclApv) {
179  // Retrieve pedestals and noises associated with given DetId/Apv
180  ApvAnalysis::PedestalType pedestals;
182  for (uint16_t nStrip = nAPV_PAIR * 256 + nLclApv * 128, nMaxStrip = nStrip + 128; nMaxStrip > nStrip; ++nStrip) {
183  pedestals.push_back(pDBPedestals->getPed(nStrip, pedestalsRange));
184  noises.push_back(pDBNoises->getNoise(nStrip, noisesRange));
185  }
186 
187  try {
188  // Checked access
189  ApvAnalysisFactory::ApvAnalysisVector::reference rApvAnalysis = apvAnalysisVector.at(nAPV_PAIR * 2 + nLclApv);
190 
191  rApvAnalysis->pedestalCalculator().setPedestals(pedestals);
192  rApvAnalysis->pedestalCalculator().setNoise(noises);
193 
194  /*
195  std::stringstream out;
196  LogTrace( mlDqmSource_)
197  << "[NoiseTask::" << __func__ << "] "
198  << "DetId|Apv# -> "
199  << connection().detId() << '|' << ( nAPV_PAIR * 2 + nLclApv)
200  << " Pedestals: "
201  << ( out << pedestals
202  << " Noises: " << noises, out.str());
203  */
204  } catch (std::out_of_range const &) {
205  // Hmm, didn't find appropriate Apv :((( -> VERY, VERY BAD
206  LogTrace(mlDqmSource_) << "[NoiseTask::" << __func__ << "] "
207  << "Could not set Pedestals/Noises for DetId|Apv# -> " << connection().detId() << '|'
208  << (nAPV_PAIR * 2 + nLclApv) << ". !!! POSSIBLE BUG !!!";
209  } // End Try block
210  } // End Local Apvs loop
211 }
212 
213 // -----------------------------------------------------------------------------
214 //
216  pApvFactory_->updatePair(connection().detId(), connection().apvPairNumber(), rDigis);
217 }
218 
219 // -----------------------------------------------------------------------------
220 //
222  static UpdateTProfile updateTProfile;
223 
224  TProfile *pedsProf = ExtractTObject<TProfile>().extract(peds_[0].histo());
225  TProfile *noiseProf = ExtractTObject<TProfile>().extract(peds_[1].histo());
226 
227  for (uint16_t nLclApv = 2 * connection().apvPairNumber(), nMaxLclApv = nLclApv + 2, nApv = 0; nMaxLclApv > nLclApv;
228  ++nLclApv, ++nApv) {
229  ApvAnalysis::PedestalType lclPedestals;
230  ApvAnalysis::PedestalType lclNoises;
231  ApvAnalysis::PedestalType lclCommonMode(pApvFactory_->getCommonMode(connection().detId(), nLclApv));
232 
233  pApvFactory_->getPedestal(connection().detId(), nLclApv, lclPedestals);
234  pApvFactory_->getNoise(connection().detId(), nLclApv, lclNoises);
235 
236  const uint16_t nSTART_BIN = 128 * (nLclApv % 2);
237 
238  for (uint16_t nBin = 0, nAbsBin = nSTART_BIN + nBin + 1; 128 > nBin; ++nBin, ++nAbsBin) {
239  updateTProfile.setBinContent(pedsProf, nAbsBin, 5, lclPedestals[nBin], lclNoises[nBin]);
240  updateTProfile.setBinContent(noiseProf, nAbsBin, 5, lclNoises[nBin], 0);
241  } // End loop over BINs
242 
243  // Samvel: Assume Once CM value is calculated per chip.
244  // In principle Chip can be divided into a several ranges. Then CM
245  // will be calculated per range. !!! UPDATE CODE THEN !!!
246  for (ApvAnalysis::PedestalType::const_iterator cmIterator = lclCommonMode.begin();
247  cmIterator != lclCommonMode.end();
248  ++cmIterator) {
249  //uint32_t nCM = static_cast<uint32_t>( *cmIterator);
250  //if( nCM >= 1024) nCM = 1023;
251  //updateHistoSet( cm_[nApv], nCM);
252  float nCM = static_cast<float>(*cmIterator);
253  updateHistoSet(cm_[nApv], nCM);
254  }
255 
256  std::stringstream out;
257  LogTrace(mlDqmSource_) << "[NoiseTask::" << __func__ << "] "
258  << "DET ID [" << connection().detId() << "] has Common Mode size " << lclCommonMode.size()
259  << " : " << (out << lclCommonMode, out.str());
260  } // End loop over Local Apvs
261 
262  updateHistoSet(cm_[0]);
263  updateHistoSet(cm_[1]);
264 }
static const char noise_[]
NoiseTask(DQMStore *, const FedChannelConnection &)
Definition: NoiseTask.cc:32
std::vector< float > vNumOfEntries_
void update() override
Definition: NoiseTask.cc:221
std::vector< float > PedestalType
Definition: ApvAnalysis.h:44
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:32
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
DQMStore *const dqm() 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:30
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:215
#define LogTrace(id)
void getCommonMode(uint32_t det_id, ApvAnalysis::PedestalType &tmp)
std::vector< ApvAnalysis * > ApvAnalysisVector
std::vector< HistoSet > peds_
Definition: NoiseTask.h:29
int extract(std::vector< int > *output, const std::string &dati)
static const char pedestals_[]
~NoiseTask() override
Definition: NoiseTask.cc:42
ApvAnalysisVector getApvAnalysis(const uint32_t nDET_ID)
void histo(MonitorElement *)
T get() const
Definition: EventSetup.h:73
const edm::EventSetup *const eventSetup() const
void book() override
Definition: NoiseTask.cc:55
const uint32_t & fedKey() const
std::vector< double > vSumOfSquares_
const FedChannelConnection & connection() const
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:47