CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LaserTask.cc
Go to the documentation of this file.
1 #include "../interface/LaserTask.h"
2 
3 #include <cmath>
4 #include <algorithm>
5 
8 
10 
11 namespace ecaldqm {
12 
13  LaserTask::LaserTask(const edm::ParameterSet &_params, const edm::ParameterSet& _paths) :
14  DQWorkerTask(_params, _paths, "LaserTask"),
15  laserWavelengths_(),
16  MGPAGainsPN_(),
17  pnAmp_()
18  {
19  using namespace std;
20 
22  (0x1 << kEcalRawData) |
23  (0x1 << kEBDigi) |
24  (0x1 << kEEDigi) |
25  (0x1 << kPnDiodeDigi) |
26  (0x1 << kEBUncalibRecHit) |
27  (0x1 << kEEUncalibRecHit);
28 
29  edm::ParameterSet const& commonParams(_params.getUntrackedParameterSet("Common"));
30  MGPAGainsPN_ = commonParams.getUntrackedParameter<std::vector<int> >("MGPAGainsPN");
31 
32  edm::ParameterSet const& taskParams(_params.getUntrackedParameterSet(name_));
33  laserWavelengths_ = taskParams.getUntrackedParameter<std::vector<int> >("laserWavelengths");
34 
35  for(std::vector<int>::iterator wlItr(laserWavelengths_.begin()); wlItr != laserWavelengths_.end(); ++wlItr)
36  if(*wlItr <= 0 || *wlItr >= 5) throw cms::Exception("InvalidConfiguration") << "Laser Wavelength" << std::endl;
37 
38  for(std::vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr)
39  if(*gainItr != 1 && *gainItr != 16) throw cms::Exception("InvalidConfiguration") << "PN diode gain" << std::endl;
40 
41  map<string, string> replacements;
42  stringstream ss;
43 
44  for(vector<int>::iterator wlItr(laserWavelengths_.begin()); wlItr != laserWavelengths_.end(); ++wlItr){
45  ss.str("");
46  ss << *wlItr;
47  replacements["wl"] = ss.str();
48 
49  unsigned offset(*wlItr - 1);
50 
51  MEs_[kAmplitudeSummary + offset]->name(replacements);
52  MEs_[kAmplitude + offset]->name(replacements);
53  MEs_[kOccupancy + offset]->name(replacements);
54  MEs_[kTiming + offset]->name(replacements);
55  MEs_[kShape + offset]->name(replacements);
56  MEs_[kAOverP + offset]->name(replacements);
57 
58  for(vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
59  ss.str("");
60  ss << *gainItr;
61  replacements["pngain"] = ss.str();
62 
63  offset = (*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1);
64 
65  MEs_[kPNAmplitude + offset]->name(replacements);
66  }
67  }
68  }
69 
71  {
72  }
73 
74  void
76  {
77  for(std::vector<int>::iterator wlItr(laserWavelengths_.begin()); wlItr != laserWavelengths_.end(); ++wlItr){
78  unsigned offset(*wlItr - 1);
79 
80  MEs_[kAmplitudeSummary + offset]->book();
81  MEs_[kAmplitude + offset]->book();
82  MEs_[kOccupancy + offset]->book();
83  MEs_[kTiming + offset]->book();
84  MEs_[kShape + offset]->book();
85  MEs_[kAOverP + offset]->book();
86 
87  for(std::vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
88  offset = (*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1);
89 
90  MEs_[kPNAmplitude + offset]->book();
91  }
92  }
93 
94  MEs_[kPNOccupancy]->book();
95  }
96 
97  void
99  {
100  for(int iDCC(0); iDCC < BinService::nDCC; iDCC++){
101  enable_[iDCC] = false;
102  wavelength_[iDCC] = -1;
103  }
104  pnAmp_.clear();
105  }
106 
107  void
109  {
110  for(int iDCC(0); iDCC < BinService::nDCC; iDCC++){
111  enable_[iDCC] = false;
112  wavelength_[iDCC] = -1;
113  }
114  pnAmp_.clear();
115  }
116 
117  bool
118  LaserTask::filterRunType(const std::vector<short>& _runType)
119  {
120  bool enable(false);
121 
122  for(int iDCC(0); iDCC < BinService::nDCC; iDCC++){
123  if(_runType[iDCC] == EcalDCCHeaderBlock::LASER_STD ||
124  _runType[iDCC] == EcalDCCHeaderBlock::LASER_GAP){
125  enable = true;
126  enable_[iDCC] = true;
127  }
128  }
129 
130  return enable;
131  }
132 
133  void
135  {
136  for(EcalRawDataCollection::const_iterator dcchItr(_dcchs.begin()); dcchItr != _dcchs.end(); ++dcchItr){
137  int iDCC(dcchItr->id() - 1);
138 
139  if(!enable_[iDCC]) continue;
140 
141  wavelength_[iDCC] = dcchItr->getEventSettings().wavelength + 1;
142 
143  if(std::find(laserWavelengths_.begin(), laserWavelengths_.end(), wavelength_[iDCC]) == laserWavelengths_.end()) enable_[iDCC] = false;
144  }
145  }
146 
147  void
149  {
150  for(EcalDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
151  const DetId& id(digiItr->id());
152 
153  int iDCC(dccId(id) - 1);
154 
155  if(!enable_[iDCC]) continue;
156 
157  EcalDataFrame dataFrame(*digiItr);
158 
159  unsigned offset(wavelength_[iDCC] - 1);
160 
161  MEs_[kOccupancy + offset]->fill(id);
162 
163  for(int iSample(0); iSample < 10; iSample++)
164  MEs_[kShape + offset]->fill(id, iSample + 0.5, float(dataFrame.sample(iSample).adc()));
165  }
166  }
167 
168  void
170  {
171  for(EcalPnDiodeDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
172  const EcalPnDiodeDetId& id(digiItr->id());
173 
174  int iDCC(dccId(id) - 1);
175 
176  if(!enable_[iDCC]) continue;
177 
178  MEs_[kPNOccupancy]->fill(id);
179 
180  float pedestal(0.);
181  for(int iSample(0); iSample < 4; iSample++)
182  pedestal += digiItr->sample(iSample).adc();
183  pedestal /= 4.;
184 
185  float max(0.);
186  for(int iSample(0); iSample < 50; iSample++){
187  EcalFEMSample sample(digiItr->sample(iSample));
188 
189  float amp(digiItr->sample(iSample).adc() - pedestal);
190 
191  if(amp > max) max = amp;
192  }
193 
194  int gain(digiItr->sample(0).gainId() == 0 ? 1 : 16);
195  max *= (16. / gain);
196 
197  unsigned offset((wavelength_[iDCC] - 1) * nPNGain + (gain == 1 ? 0 : 1));
198 
199  MEs_[kPNAmplitude + offset]->fill(id, max);
200 
201  if(pnAmp_.find(iDCC) == pnAmp_.end()) pnAmp_[iDCC].resize(10);
202  pnAmp_[iDCC][id.iPnId() - 1] = max;
203  }
204  }
205 
206  void
208  {
209  using namespace std;
210 
211  for(EcalUncalibratedRecHitCollection::const_iterator uhitItr(_uhits.begin()); uhitItr != _uhits.end(); ++uhitItr){
212  const DetId& id(uhitItr->id());
213 
214  int iDCC(dccId(id) - 1);
215 
216  if(!enable_[iDCC]) continue;
217 
218  unsigned offset(wavelength_[iDCC] - 1);
219 
220  float amp(max((double)uhitItr->amplitude(), 0.));
221  float jitter(max((double)uhitItr->jitter() + 5.0, 0.));
222 
223  MEs_[kAmplitudeSummary + offset]->fill(id, amp);
224  MEs_[kAmplitude + offset]->fill(id, amp);
225  MEs_[kTiming + offset]->fill(id, jitter);
226 
227  if(pnAmp_.find(iDCC) == pnAmp_.end()) continue;
228 
229  float aop(0.);
230  float pn0(0.), pn1(0.);
231  if(_collection == kEBUncalibRecHit){
232  EBDetId ebid(id);
233 
234  int lmmod(MEEBGeom::lmmod(ebid.ieta(), ebid.iphi()));
235  pair<int, int> pnPair(MEEBGeom::pn(lmmod));
236 
237  pn0 = pnAmp_[iDCC][pnPair.first];
238  pn1 = pnAmp_[iDCC][pnPair.second];
239  }else if(_collection == kEEUncalibRecHit){
240  EcalScDetId scid(EEDetId(id).sc());
241 
242  int dee(MEEEGeom::dee(scid.ix(), scid.iy(), scid.zside()));
243  int lmmod(MEEEGeom::lmmod(scid.ix(), scid.iy()));
244  pair<int, int> pnPair(MEEEGeom::pn(dee, lmmod));
245 
246  int pnAFED(getEEPnDCC(dee, 0)), pnBFED(getEEPnDCC(dee, 1));
247 
248  pn0 = pnAmp_[pnAFED][pnPair.first];
249  pn1 = pnAmp_[pnBFED][pnPair.second];
250  }
251 
252  if(pn0 < 10 && pn1 > 10){
253  aop = amp / pn1;
254  }else if(pn0 > 10 && pn1 < 10){
255  aop = amp / pn0;
256  }else if(pn0 + pn1 > 1){
257  aop = amp / (0.5 * (pn0 + pn1));
258  }else{
259  aop = 1000.;
260  }
261 
262  MEs_[kAOverP + offset]->fill(id, aop);
263  }
264  }
265 
266  /*static*/
267  void
268  LaserTask::setMEData(std::vector<MEData>& _data)
269  {
271  axis.nbins = 10;
272  axis.low = 0.;
273  axis.high = 10.;
274 
275  for(unsigned iWL(0); iWL < nWL; iWL++){
282  for(unsigned iPNGain(0); iPNGain < nPNGain; iPNGain++){
283  unsigned offset(iWL * nPNGain + iPNGain);
285  }
286  }
288  }
289 
291 }
static int lmmod(SuperCrysCoord iX, SuperCrysCoord iY)
Definition: MEEEGeom.cc:94
string fill
Definition: lumiContext.py:319
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
void runOnRawData(const EcalRawDataCollection &)
Definition: LaserTask.cc:134
unsigned getEEPnDCC(unsigned, unsigned)
void endEvent(const edm::Event &, const edm::EventSetup &)
Definition: LaserTask.cc:108
std::vector< int > MGPAGainsPN_
Definition: LaserTask.h:55
std::map< int, std::vector< float > > pnAmp_
Definition: LaserTask.h:59
std::vector< T >::const_iterator const_iterator
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:30
unsigned dccId(const DetId &)
const_iterator begin() const
void beginRun(const edm::Run &, const edm::EventSetup &)
Definition: LaserTask.cc:98
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
bool filterRunType(const std::vector< short > &)
Definition: LaserTask.cc:118
static std::pair< int, int > pn(int ilmmod)
Definition: MEEBGeom.cc:479
int iphi() const
get the crystal iphi
Definition: EBDetId.h:54
void runOnDigis(const EcalDigiCollection &)
Definition: LaserTask.cc:148
static std::pair< int, int > pn(int dee, int ilmod)
Definition: MEEEGeom.cc:615
const T & max(const T &a, const T &b)
int ix() const
Definition: EcalScDetId.h:72
ParameterSet const & getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
void runOnUncalibRecHits(const EcalUncalibratedRecHitCollection &, Collections)
Definition: LaserTask.cc:207
int ieta() const
get the crystal ieta
Definition: EBDetId.h:52
int wavelength_[BinService::nDCC]
Definition: LaserTask.h:58
unsigned int offset(bool)
static int lmmod(EBGlobalCoord ieta, EBGlobalCoord iphi)
Definition: MEEBGeom.cc:93
int iy() const
Definition: EcalScDetId.h:78
std::vector< int > laserWavelengths_
Definition: LaserTask.h:54
const_iterator end() const
Definition: DetId.h:20
std::vector< MESet * > MEs_
Definition: DQWorker.h:56
int zside() const
Definition: EcalScDetId.h:66
const_iterator end() const
bool enable_[BinService::nDCC]
Definition: LaserTask.h:57
static int dee(SuperCrysCoord iX, SuperCrysCoord iY, int iz)
Definition: MEEEGeom.cc:284
LaserTask(const edm::ParameterSet &, const edm::ParameterSet &)
Definition: LaserTask.cc:13
static void setMEData(std::vector< MEData > &)
Definition: LaserTask.cc:268
DEFINE_ECALDQM_WORKER(CertificationClient)
void runOnPnDigis(const EcalPnDiodeDigiCollection &)
Definition: LaserTask.cc:169
std::string name_
Definition: DQWorker.h:55
const_iterator begin() const
Definition: Run.h:36
int adc() const
get the ADC sample (12 bits)