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