CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TestPulseTask.cc
Go to the documentation of this file.
1 #include "../interface/TestPulseTask.h"
2 
3 #include <algorithm>
4 
8 
10 
11 namespace ecaldqm {
12 
14  DQWorkerTask(_params, _paths, "TestPulseTask"),
15  MGPAGains_(),
16  MGPAGainsPN_()
17  {
18  using namespace std;
19 
21  (0x1 << kEBDigi) |
22  (0x1 << kEEDigi) |
23  (0x1 << kPnDiodeDigi) |
24  (0x1 << kEBUncalibRecHit) |
25  (0x1 << kEEUncalibRecHit);
26 
27  edm::ParameterSet const& commonParams(_params.getUntrackedParameterSet("Common"));
28  MGPAGains_ = commonParams.getUntrackedParameter<std::vector<int> >("MGPAGains");
29  MGPAGainsPN_ = commonParams.getUntrackedParameter<std::vector<int> >("MGPAGainsPN");
30 
31  for(int idcc(0); idcc < 54; idcc++){
32  enable_[idcc] = false;
33  gain_[idcc] = 12;
34  }
35 
36  for(std::vector<int>::iterator gainItr(MGPAGains_.begin()); gainItr != MGPAGains_.end(); ++gainItr)
37  if(*gainItr != 1 && *gainItr != 6 && *gainItr != 12) throw cms::Exception("InvalidConfiguration") << "MGPA gain" << std::endl;
38 
39  for(std::vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr)
40  if(*gainItr != 1 && *gainItr != 16) throw cms::Exception("InvalidConfiguration") << "PN diode gain" << std::endl;
41 
42  map<string, string> replacements;
43  stringstream ss;
44 
45  for(vector<int>::iterator gainItr(MGPAGains_.begin()); gainItr != MGPAGains_.end(); ++gainItr){
46  ss.str("");
47  ss << *gainItr;
48  replacements["gain"] = ss.str();
49 
50  unsigned offset(0);
51  switch(*gainItr){
52  case 1: offset = 0; break;
53  case 6: offset = 1; break;
54  case 12: offset = 2; break;
55  default: break;
56  }
57 
58  MEs_[kOccupancy + offset]->name(replacements);
59  MEs_[kShape + offset]->name(replacements);
60  MEs_[kAmplitude + offset]->name(replacements);
61  }
62 
63  for(vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
64  ss.str("");
65  ss << *gainItr;
66  replacements["pngain"] = ss.str();
67 
68  unsigned offset(0);
69  switch(*gainItr){
70  case 1: offset = 0; break;
71  case 16: offset = 1; break;
72  default: break;
73  }
74 
75  MEs_[kPNOccupancy + offset]->name(replacements);
76  MEs_[kPNAmplitude + offset]->name(replacements);
77  }
78  }
79 
81  {
82  }
83 
84  void
86  {
87  for(std::vector<int>::iterator gainItr(MGPAGains_.begin()); gainItr != MGPAGains_.end(); ++gainItr){
88  unsigned offset(0);
89  switch(*gainItr){
90  case 1: offset = 0; break;
91  case 6: offset = 1; break;
92  case 12: offset = 2; break;
93  default: break;
94  }
95 
96  MEs_[kOccupancy + offset]->book();
97  MEs_[kShape + offset]->book();
98  MEs_[kAmplitude + offset]->book();
99  }
100  for(std::vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
101  unsigned offset(0);
102  switch(*gainItr){
103  case 1: offset = 0; break;
104  case 16: offset = 1; break;
105  default: break;
106  }
107 
108  MEs_[kPNOccupancy + offset]->book();
109  MEs_[kPNAmplitude + offset]->book();
110  }
111  }
112 
113  void
115  {
116  for(int idcc(0); idcc < 54; idcc++){
117  enable_[idcc] = false;
118  gain_[idcc] = 0;
119  }
120  }
121 
122  void
124  {
125  for(int idcc(0); idcc < 54; idcc++){
126  enable_[idcc] = false;
127  gain_[idcc] = 0;
128  }
129  }
130 
131  bool
132  TestPulseTask::filterRunType(const std::vector<short>& _runType)
133  {
134  bool enable(false);
135 
136  for(int iFED(0); iFED < 54; iFED++){
137  if(_runType[iFED] == EcalDCCHeaderBlock::TESTPULSE_MGPA ||
138  _runType[iFED] == EcalDCCHeaderBlock::TESTPULSE_GAP){
139  enable = true;
140  enable_[iFED] = true;
141  }
142  }
143 
144  return enable;
145  }
146 
147  void
149  {
150  for(EcalDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
151  DetId id(digiItr->id());
152 
153  int iDCC(dccId(id) - 1);
154 
155  if(!enable_[iDCC]) continue;
156 
157  // EcalDataFrame is not a derived class of edm::DataFrame, but can take edm::DataFrame in the constructor
158  EcalDataFrame dataFrame(*digiItr);
159 
160  unsigned offset(0);
161  switch(dataFrame.sample(0).gainId()){
162  case 1: offset = 2; gain_[iDCC] = 12; break;
163  case 2: offset = 1; gain_[iDCC] = 6; break;
164  case 3: offset = 0; gain_[iDCC] = 1; break;
165  default: continue;
166  }
167 
168  if(std::find(MGPAGains_.begin(), MGPAGains_.end(), gain_[iDCC]) == MGPAGains_.end()) continue;
169 
170  MEs_[kOccupancy + offset]->fill(id);
171 
172  for(int iSample(0); iSample < 10; iSample++)
173  MEs_[kShape + offset]->fill(id, iSample + 0.5, float(dataFrame.sample(iSample).adc()));
174  }
175  }
176 
177  void
179  {
180  for(EcalPnDiodeDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
181  EcalPnDiodeDetId id(digiItr->id());
182 
183  int iDCC(dccId(id) - 1);
184 
185  if(!enable_[iDCC]) continue;
186 
187  unsigned offset(0);
188  int gain(0);
189  switch(digiItr->sample(0).gainId()){
190  case 0: offset = 0; gain = 1; break;
191  case 1: offset = 1; gain = 16; break;
192  default: continue;
193  }
194 
195  if(std::find(MGPAGainsPN_.begin(), MGPAGainsPN_.end(), gain) == MGPAGainsPN_.end()) continue;
196 
197  MEs_[kPNOccupancy + offset]->fill(id);
198 
199  float pedestal(0.);
200  for(int iSample(0); iSample < 4; iSample++)
201  pedestal += digiItr->sample(iSample).adc();
202  pedestal /= 4.;
203 
204  float max(0.);
205  for(int iSample(0); iSample < 50; iSample++)
206  if(digiItr->sample(iSample).adc() > max) max = digiItr->sample(iSample).adc();
207 
208  float amplitude(max - pedestal);
209 
210  MEs_[kPNAmplitude + offset]->fill(id, amplitude);
211  }
212  }
213 
214  void
216  {
217  for(EcalUncalibratedRecHitCollection::const_iterator uhitItr(_uhits.begin()); uhitItr != _uhits.end(); ++uhitItr){
218  DetId id(uhitItr->id());
219 
220  int iDCC(dccId(id) - 1);
221 
222  if(!enable_[iDCC]) continue;
223 
224  unsigned offset(0);
225  switch(gain_[iDCC]){
226  case 1: offset = 0; break;
227  case 6: offset = 1; break;
228  case 12: offset = 2; break;
229  default: continue;
230  }
231 
232  MEs_[kAmplitude + offset]->fill(id, uhitItr->amplitude());
233  }
234  }
235 
236  /*static*/
237  void
238  TestPulseTask::setMEData(std::vector<MEData>& _data)
239  {
241  axis.nbins = 10;
242  axis.low = 0.;
243  axis.high = 10.;
244 
245  for(unsigned iGain(0); iGain < nGain; iGain++){
249  }
250  for(unsigned iPNGain(0); iPNGain < nPNGain; iPNGain++){
253  }
254  }
255 
257 }
string fill
Definition: lumiContext.py:319
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
std::vector< int > MGPAGains_
Definition: TestPulseTask.h:48
std::vector< T >::const_iterator const_iterator
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:30
unsigned dccId(const DetId &)
void beginRun(const edm::Run &, const edm::EventSetup &)
const_iterator begin() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
int gainId() const
get the gainId (2 bits)
static void setMEData(std::vector< MEData > &)
const T & max(const T &a, const T &b)
ParameterSet const & getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
TestPulseTask(const edm::ParameterSet &, const edm::ParameterSet &)
void runOnPnDigis(const EcalPnDiodeDigiCollection &)
unsigned int offset(bool)
const_iterator end() const
Definition: DetId.h:20
std::vector< MESet * > MEs_
Definition: DQWorker.h:56
bool filterRunType(const std::vector< short > &)
void endEvent(const edm::Event &, const edm::EventSetup &)
void runOnDigis(const EcalDigiCollection &)
std::vector< int > MGPAGainsPN_
Definition: TestPulseTask.h:49
const_iterator end() const
DEFINE_ECALDQM_WORKER(CertificationClient)
void runOnUncalibRecHits(const EcalUncalibratedRecHitCollection &)
const_iterator begin() const
Definition: Run.h:36
int adc() const
get the ADC sample (12 bits)