Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:07:22

0001 #include "DQM/EcalMonitorTasks/interface/TestPulseTask.h"
0002 
0003 #include <algorithm>
0004 #include <iomanip>
0005 
0006 #include "DataFormats/EcalRawData/interface/EcalDCCHeaderBlock.h"
0007 #include "DataFormats/DetId/interface/DetId.h"
0008 #include "DataFormats/EcalDigi/interface/EcalDataFrame.h"
0009 
0010 #include "DQM/EcalCommon/interface/MESetMulti.h"
0011 
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 
0014 namespace ecaldqm {
0015   TestPulseTask::TestPulseTask() : DQWorkerTask(), gainToME_(), pnGainToME_() {
0016     std::fill_n(enable_, nDCC, false);
0017     std::fill_n(gain_, nDCC, 0);
0018   }
0019 
0020   void TestPulseTask::setParams(edm::ParameterSet const& _params) {
0021     std::vector<int> MGPAGains(_params.getUntrackedParameter<std::vector<int> >("MGPAGains"));
0022     std::vector<int> MGPAGainsPN(_params.getUntrackedParameter<std::vector<int> >("MGPAGainsPN"));
0023 
0024     MESet::PathReplacements repl;
0025 
0026     MESetMulti& amplitude(static_cast<MESetMulti&>(MEs_.at("Amplitude")));
0027     unsigned nG(MGPAGains.size());
0028     for (unsigned iG(0); iG != nG; ++iG) {
0029       int gain(MGPAGains[iG]);
0030       if (gain != 1 && gain != 6 && gain != 12)
0031         throw cms::Exception("InvalidConfiguration") << "MGPA gain";
0032       repl["gain"] = std::to_string(gain);
0033       gainToME_[gain] = amplitude.getIndex(repl);
0034     }
0035 
0036     repl.clear();
0037 
0038     MESetMulti& pnAmplitude(static_cast<MESetMulti&>(MEs_.at("PNAmplitude")));
0039     unsigned nGPN(MGPAGainsPN.size());
0040     for (unsigned iG(0); iG != nGPN; ++iG) {
0041       int gain(MGPAGainsPN[iG]);
0042       if (gain != 1 && gain != 16)
0043         throw cms::Exception("InvalidConfiguration") << "PN MGPA gain";
0044       repl["pngain"] = std::to_string(gain);
0045       pnGainToME_[gain] = pnAmplitude.getIndex(repl);
0046     }
0047   }
0048 
0049   void TestPulseTask::addDependencies(DependencySet& _dependencies) {
0050     _dependencies.push_back(Dependency(kEBTestPulseUncalibRecHit, kEcalRawData));
0051     _dependencies.push_back(Dependency(kEETestPulseUncalibRecHit, kEcalRawData));
0052   }
0053 
0054   bool TestPulseTask::filterRunType(short const* _runType) {
0055     bool enable(false);
0056 
0057     for (int iFED(0); iFED < nDCC; iFED++) {
0058       if (_runType[iFED] == EcalDCCHeaderBlock::TESTPULSE_MGPA || _runType[iFED] == EcalDCCHeaderBlock::TESTPULSE_GAP) {
0059         enable = true;
0060         enable_[iFED] = true;
0061       } else
0062         enable_[iFED] = false;
0063     }
0064 
0065     return enable;
0066   }
0067 
0068   void TestPulseTask::runOnRawData(EcalRawDataCollection const& _rawData) {
0069     for (EcalRawDataCollection::const_iterator rItr(_rawData.begin()); rItr != _rawData.end(); ++rItr) {
0070       unsigned iDCC(rItr->id() - 1);
0071 
0072       if (!enable_[iDCC]) {
0073         gain_[iDCC] = 0;
0074         continue;
0075       }
0076       switch (rItr->getMgpaGain()) {
0077         case 1:
0078           gain_[iDCC] = 12;
0079           break;
0080         case 2:
0081           gain_[iDCC] = 6;
0082           break;
0083         case 3:
0084           gain_[iDCC] = 1;
0085           break;
0086         default:
0087           break;
0088       }
0089 
0090       if (gainToME_.find(gain_[iDCC]) == gainToME_.end())
0091         enable_[iDCC] = false;
0092     }
0093   }
0094 
0095   template <typename DigiCollection>
0096   void TestPulseTask::runOnDigis(DigiCollection const& _digis) {
0097     MESet& meOccupancy(MEs_.at("Occupancy"));
0098     MESet& meShape(MEs_.at("Shape"));
0099 
0100     unsigned iME(-1);
0101 
0102     for (typename DigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr) {
0103       DetId id(digiItr->id());
0104 
0105       meOccupancy.fill(getEcalDQMSetupObjects(), id);
0106 
0107       int iDCC(dccId(id, GetElectronicsMap()) - 1);
0108 
0109       if (!enable_[iDCC])
0110         continue;
0111 
0112       // EcalDataFrame is not a derived class of edm::DataFrame, but can take edm::DataFrame in the constructor
0113       EcalDataFrame dataFrame(*digiItr);
0114 
0115       if (iME != gainToME_[gain_[iDCC]]) {
0116         iME = gainToME_[gain_[iDCC]];
0117         static_cast<MESetMulti&>(meShape).use(iME);
0118       }
0119 
0120       for (int iSample(0); iSample < 10; iSample++)
0121         meShape.fill(getEcalDQMSetupObjects(), id, iSample + 0.5, float(dataFrame.sample(iSample).adc()));
0122     }
0123   }
0124 
0125   void TestPulseTask::runOnPnDigis(EcalPnDiodeDigiCollection const& _digis) {
0126     MESet& mePNAmplitude(MEs_.at("PNAmplitude"));
0127 
0128     unsigned iME(-1);
0129 
0130     for (EcalPnDiodeDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr) {
0131       EcalPnDiodeDetId const& id(digiItr->id());
0132 
0133       int iDCC(dccId(id, GetElectronicsMap()) - 1);
0134 
0135       if (!enable_[iDCC])
0136         continue;
0137 
0138       int gain(0);
0139       switch (digiItr->sample(0).gainId()) {
0140         case 0:
0141           gain = 1;
0142           break;
0143         case 1:
0144           gain = 16;
0145           break;
0146         default:
0147           continue;
0148       }
0149 
0150       if (pnGainToME_.find(gain) == pnGainToME_.end())
0151         continue;
0152 
0153       if (iME != pnGainToME_[gain]) {
0154         iME = pnGainToME_[gain];
0155         static_cast<MESetMulti&>(mePNAmplitude).use(iME);
0156       }
0157 
0158       float pedestal(0.);
0159       for (int iSample(0); iSample < 4; iSample++)
0160         pedestal += digiItr->sample(iSample).adc();
0161       pedestal /= 4.;
0162 
0163       float max(0.);
0164       for (int iSample(0); iSample < 50; iSample++)
0165         if (digiItr->sample(iSample).adc() > max)
0166           max = digiItr->sample(iSample).adc();
0167 
0168       double amplitude(max - pedestal);
0169 
0170       mePNAmplitude.fill(getEcalDQMSetupObjects(), id, amplitude);
0171     }
0172   }
0173 
0174   void TestPulseTask::runOnUncalibRecHits(EcalUncalibratedRecHitCollection const& _uhits) {
0175     MESet& meAmplitude(MEs_.at("Amplitude"));
0176 
0177     unsigned iME(-1);
0178 
0179     for (EcalUncalibratedRecHitCollection::const_iterator uhitItr(_uhits.begin()); uhitItr != _uhits.end(); ++uhitItr) {
0180       DetId id(uhitItr->id());
0181 
0182       int iDCC(dccId(id, GetElectronicsMap()) - 1);
0183 
0184       if (!enable_[iDCC])
0185         continue;
0186 
0187       if (iME != gainToME_[gain_[iDCC]]) {
0188         iME = gainToME_[gain_[iDCC]];
0189         static_cast<MESetMulti&>(meAmplitude).use(iME);
0190       }
0191 
0192       meAmplitude.fill(getEcalDQMSetupObjects(), id, uhitItr->amplitude());
0193     }
0194   }
0195 
0196   DEFINE_ECALDQM_WORKER(TestPulseTask);
0197 }  // namespace ecaldqm