CMS 3D CMS Logo

TestPulseTask.cc
Go to the documentation of this file.
2 
3 #include <algorithm>
4 #include <iomanip>
5 
9 
11 
13 
14 namespace ecaldqm {
15  TestPulseTask::TestPulseTask() : DQWorkerTask(), gainToME_(), pnGainToME_() {
16  std::fill_n(enable_, nDCC, false);
17  std::fill_n(gain_, nDCC, 0);
18  }
19 
21  std::vector<int> MGPAGains(_params.getUntrackedParameter<std::vector<int> >("MGPAGains"));
22  std::vector<int> MGPAGainsPN(_params.getUntrackedParameter<std::vector<int> >("MGPAGainsPN"));
23 
25 
26  MESetMulti& amplitude(static_cast<MESetMulti&>(MEs_.at("Amplitude")));
27  unsigned nG(MGPAGains.size());
28  for (unsigned iG(0); iG != nG; ++iG) {
29  int gain(MGPAGains[iG]);
30  if (gain != 1 && gain != 6 && gain != 12)
31  throw cms::Exception("InvalidConfiguration") << "MGPA gain";
32  repl["gain"] = std::to_string(gain);
33  gainToME_[gain] = amplitude.getIndex(repl);
34  }
35 
36  repl.clear();
37 
38  MESetMulti& pnAmplitude(static_cast<MESetMulti&>(MEs_.at("PNAmplitude")));
39  unsigned nGPN(MGPAGainsPN.size());
40  for (unsigned iG(0); iG != nGPN; ++iG) {
41  int gain(MGPAGainsPN[iG]);
42  if (gain != 1 && gain != 16)
43  throw cms::Exception("InvalidConfiguration") << "PN MGPA gain";
44  repl["pngain"] = std::to_string(gain);
45  pnGainToME_[gain] = pnAmplitude.getIndex(repl);
46  }
47  }
48 
52  }
53 
54  bool TestPulseTask::filterRunType(short const* _runType) {
55  bool enable(false);
56 
57  for (int iFED(0); iFED < nDCC; iFED++) {
58  if (_runType[iFED] == EcalDCCHeaderBlock::TESTPULSE_MGPA || _runType[iFED] == EcalDCCHeaderBlock::TESTPULSE_GAP) {
59  enable = true;
60  enable_[iFED] = true;
61  } else
62  enable_[iFED] = false;
63  }
64 
65  return enable;
66  }
67 
69  for (EcalRawDataCollection::const_iterator rItr(_rawData.begin()); rItr != _rawData.end(); ++rItr) {
70  unsigned iDCC(rItr->id() - 1);
71 
72  if (!enable_[iDCC]) {
73  gain_[iDCC] = 0;
74  continue;
75  }
76  switch (rItr->getMgpaGain()) {
77  case 1:
78  gain_[iDCC] = 12;
79  break;
80  case 2:
81  gain_[iDCC] = 6;
82  break;
83  case 3:
84  gain_[iDCC] = 1;
85  break;
86  default:
87  break;
88  }
89 
90  if (gainToME_.find(gain_[iDCC]) == gainToME_.end())
91  enable_[iDCC] = false;
92  }
93  }
94 
95  template <typename DigiCollection>
97  MESet& meOccupancy(MEs_.at("Occupancy"));
98  MESet& meShape(MEs_.at("Shape"));
99 
100  unsigned iME(-1);
101 
102  for (typename DigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr) {
103  DetId id(digiItr->id());
104 
105  meOccupancy.fill(getEcalDQMSetupObjects(), id);
106 
107  int iDCC(dccId(id, GetElectronicsMap()) - 1);
108 
109  if (!enable_[iDCC])
110  continue;
111 
112  // EcalDataFrame is not a derived class of edm::DataFrame, but can take edm::DataFrame in the constructor
113  EcalDataFrame dataFrame(*digiItr);
114 
115  if (iME != gainToME_[gain_[iDCC]]) {
116  iME = gainToME_[gain_[iDCC]];
117  static_cast<MESetMulti&>(meShape).use(iME);
118  }
119 
120  for (int iSample(0); iSample < 10; iSample++)
121  meShape.fill(getEcalDQMSetupObjects(), id, iSample + 0.5, float(dataFrame.sample(iSample).adc()));
122  }
123  }
124 
126  MESet& mePNAmplitude(MEs_.at("PNAmplitude"));
127 
128  unsigned iME(-1);
129 
130  for (EcalPnDiodeDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr) {
131  EcalPnDiodeDetId const& id(digiItr->id());
132 
133  int iDCC(dccId(id, GetElectronicsMap()) - 1);
134 
135  if (!enable_[iDCC])
136  continue;
137 
138  int gain(0);
139  switch (digiItr->sample(0).gainId()) {
140  case 0:
141  gain = 1;
142  break;
143  case 1:
144  gain = 16;
145  break;
146  default:
147  continue;
148  }
149 
150  if (pnGainToME_.find(gain) == pnGainToME_.end())
151  continue;
152 
153  if (iME != pnGainToME_[gain]) {
154  iME = pnGainToME_[gain];
155  static_cast<MESetMulti&>(mePNAmplitude).use(iME);
156  }
157 
158  float pedestal(0.);
159  for (int iSample(0); iSample < 4; iSample++)
160  pedestal += digiItr->sample(iSample).adc();
161  pedestal /= 4.;
162 
163  float max(0.);
164  for (int iSample(0); iSample < 50; iSample++)
165  if (digiItr->sample(iSample).adc() > max)
166  max = digiItr->sample(iSample).adc();
167 
168  double amplitude(max - pedestal);
169 
170  mePNAmplitude.fill(getEcalDQMSetupObjects(), id, amplitude);
171  }
172  }
173 
175  MESet& meAmplitude(MEs_.at("Amplitude"));
176 
177  unsigned iME(-1);
178 
179  for (EcalUncalibratedRecHitCollection::const_iterator uhitItr(_uhits.begin()); uhitItr != _uhits.end(); ++uhitItr) {
180  DetId id(uhitItr->id());
181 
182  int iDCC(dccId(id, GetElectronicsMap()) - 1);
183 
184  if (!enable_[iDCC])
185  continue;
186 
187  if (iME != gainToME_[gain_[iDCC]]) {
188  iME = gainToME_[gain_[iDCC]];
189  static_cast<MESetMulti&>(meAmplitude).use(iME);
190  }
191 
192  meAmplitude.fill(getEcalDQMSetupObjects(), id, uhitItr->amplitude());
193  }
194  }
195 
197 } // namespace ecaldqm
#define DEFINE_ECALDQM_WORKER(TYPE)
Definition: DQWorker.h:168
MESet & at(const std::string &key)
Definition: MESet.h:399
std::vector< T >::const_iterator const_iterator
std::map< int, unsigned > gainToME_
Definition: TestPulseTask.h:34
static std::string to_string(const XMLCh *ch)
void fill(EcalDQMSetupObjects const edso, DetId const &_id, double _xyw=1., double _yw=1., double _w=1.) override
Definition: MESetMulti.h:29
std::map< int, unsigned > pnGainToME_
Definition: TestPulseTask.h:35
bool filterRunType(short const *) override
void setParams(edm::ParameterSet const &) override
void runOnDigis(DigiCollection const &)
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
unsigned dccId(DetId const &, EcalElectronicsMapping const *)
const_iterator begin() const
enable
Messages.
Definition: DiMuonV_cfg.py:93
const_iterator end() const
EcalElectronicsMapping const * GetElectronicsMap()
Definition: DQWorker.cc:150
EcalDQMSetupObjects const getEcalDQMSetupObjects()
Definition: DQWorker.cc:170
Definition: DetId.h:17
unsigned getIndex(PathReplacements const &) const
Definition: MESetMulti.cc:140
void runOnPnDigis(EcalPnDiodeDigiCollection const &)
static constexpr int nDCC
MESetCollection MEs_
Definition: DQWorker.h:131
int adc() const
get the ADC sample (12 bits)
void addDependencies(DependencySet &) override
void runOnUncalibRecHits(EcalUncalibratedRecHitCollection const &)
std::map< std::string, std::string > PathReplacements
Definition: MESet.h:46
void push_back(Dependency const &_d)
Definition: DQWorkerTask.h:46
void runOnRawData(EcalRawDataCollection const &)