CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PedestalTask.cc
Go to the documentation of this file.
1 #include "../interface/PedestalTask.h"
2 
3 #include <iomanip>
4 
7 
9 
11 
12 namespace ecaldqm
13 {
15  DQWorkerTask(),
16  gainToME_(),
17  pnGainToME_()
18  {
19  std::fill_n(enable_, nDCC, false);
20  }
21 
22  void
24  {
25  std::vector<int> MGPAGains(_params.getUntrackedParameter<std::vector<int> >("MGPAGains"));
26  std::vector<int> MGPAGainsPN(_params.getUntrackedParameter<std::vector<int> >("MGPAGainsPN"));
27 
29 
30  MESetMulti& pedestal(static_cast<MESetMulti&>(MEs_.at("Pedestal")));
31  unsigned nG(MGPAGains.size());
32  for(unsigned iG(0); iG != nG; ++iG){
33  int gain(MGPAGains[iG]);
34  if(gain != 1 && gain != 6 && gain != 12) throw cms::Exception("InvalidConfiguration") << "MGPA gain";
35  repl["gain"] = std::to_string(gain);
36  gainToME_[gain] = pedestal.getIndex(repl);
37  }
38 
39  repl.clear();
40 
41  MESetMulti& pnPedestal(static_cast<MESetMulti&>(MEs_.at("PNPedestal")));
42  unsigned nGPN(MGPAGainsPN.size());
43  for(unsigned iG(0); iG != nGPN; ++iG){
44  int gain(MGPAGainsPN[iG]);
45  if(gain != 1 && gain != 16) throw cms::Exception("InvalidConfiguration") << "PN MGPA gain";
46  repl["pngain"] = std::to_string(gain);
47  pnGainToME_[gain] = pnPedestal.getIndex(repl);
48  }
49  }
50 
51  bool
52  PedestalTask::filterRunType(short const* _runType)
53  {
54  bool enable(false);
55 
56  for(int iFED(0); iFED < nDCC; iFED++){
57  if(_runType[iFED] == EcalDCCHeaderBlock::PEDESTAL_STD ||
58  _runType[iFED] == EcalDCCHeaderBlock::PEDESTAL_GAP){
59  enable = true;
60  enable_[iFED] = true;
61  }
62  else
63  enable_[iFED] = false;
64  }
65 
66  return enable;
67  }
68 
69  template<typename DigiCollection>
70  void
71  PedestalTask::runOnDigis(DigiCollection const& _digis)
72  {
73  MESet& mePedestal(MEs_.at("Pedestal"));
74  MESet& meOccupancy(MEs_.at("Occupancy"));
75 
76  unsigned iME(-1);
77 
78  for(typename DigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
79  DetId id(digiItr->id());
80 
81  int iDCC(dccId(id) - 1);
82 
83  if(!enable_[iDCC]) continue;
84 
85  // EcalDataFrame is not a derived class of edm::DataFrame, but can take edm::DataFrame in the constructor
86  EcalDataFrame dataFrame(*digiItr);
87 
88  int gain(0);
89  switch(dataFrame.sample(0).gainId()){
90  case 1: gain = 12; break;
91  case 2: gain = 6; break;
92  case 3: gain = 1; break;
93  default: continue;
94  }
95 
96  if(gainToME_.find(gain) == gainToME_.end()) continue;
97 
98  if(iME != gainToME_[gain]){
99  iME = gainToME_[gain];
100  static_cast<MESetMulti&>(mePedestal).use(iME);
101  }
102 
103  meOccupancy.fill(id);
104 
105  for(int iSample(0); iSample < EcalDataFrame::MAXSAMPLES; iSample++)
106  mePedestal.fill(id, double(dataFrame.sample(iSample).adc()));
107  }
108  }
109 
110  void
112  {
113  MESet& mePNPedestal(MEs_.at("PNPedestal"));
114 
115  unsigned iME(-1);
116 
117  for(EcalPnDiodeDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
118  EcalPnDiodeDetId id(digiItr->id());
119 
120  int iDCC(dccId(id) - 1);
121 
122  if(!enable_[iDCC]) continue;
123 
124  int gain(0);
125  switch(digiItr->sample(0).gainId()){
126  case 0: gain = 1; break;
127  case 1: gain = 16; break;
128  default: continue;
129  }
130 
131  if(pnGainToME_.find(gain) == pnGainToME_.end()) continue;
132 
133  if(iME != pnGainToME_[gain]){
134  iME = pnGainToME_[gain];
135  static_cast<MESetMulti&>(mePNPedestal).use(iME);
136  }
137 
138  for(int iSample(0); iSample < 50; iSample++)
139  mePNPedestal.fill(id, double(digiItr->sample(iSample).adc()));
140  }
141  }
142 
144 }
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_ECALDQM_WORKER(TYPE)
Definition: DQWorker.h:108
bool filterRunType(short const *) override
Definition: PedestalTask.cc:52
std::vector< EcalPnDiodeDigi >::const_iterator const_iterator
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
void runOnDigis(DigiCollection const &)
Definition: PedestalTask.cc:71
int gainId() const
get the gainId (2 bits)
void fill(DetId const &_id, double _xyw=1., double _yw=1., double _w=1.) override
Definition: MESetMulti.h:30
std::map< int, unsigned > gainToME_
Definition: PedestalTask.h:27
std::string to_string(const T &t)
Definition: Logger.cc:26
const_iterator end() const
Definition: DetId.h:18
std::map< int, unsigned > pnGainToME_
Definition: PedestalTask.h:28
void setParams(edm::ParameterSet const &) override
Definition: PedestalTask.cc:23
MESetCollection MEs_
Definition: DQWorker.h:75
std::map< std::string, std::string > PathReplacements
Definition: MESet.h:31
unsigned dccId(DetId const &)
void runOnPnDigis(EcalPnDiodeDigiCollection const &)
static const int MAXSAMPLES
Definition: EcalDataFrame.h:48
unsigned getIndex(PathReplacements const &) const
Definition: MESetMulti.cc:155
const_iterator begin() const
int adc() const
get the ADC sample (12 bits)