Go to the documentation of this file.00001 #include "../interface/TestPulseTask.h"
00002
00003 #include <algorithm>
00004
00005 #include "DataFormats/EcalRawData/interface/EcalDCCHeaderBlock.h"
00006 #include "DataFormats/DetId/interface/DetId.h"
00007 #include "DataFormats/EcalDigi/interface/EcalDataFrame.h"
00008
00009 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
00010
00011 namespace ecaldqm {
00012
00013 TestPulseTask::TestPulseTask(const edm::ParameterSet &_params, const edm::ParameterSet& _paths) :
00014 DQWorkerTask(_params, _paths, "TestPulseTask"),
00015 MGPAGains_(),
00016 MGPAGainsPN_()
00017 {
00018 using namespace std;
00019
00020 collectionMask_ =
00021 (0x1 << kEBDigi) |
00022 (0x1 << kEEDigi) |
00023 (0x1 << kPnDiodeDigi) |
00024 (0x1 << kEBUncalibRecHit) |
00025 (0x1 << kEEUncalibRecHit);
00026
00027 edm::ParameterSet const& commonParams(_params.getUntrackedParameterSet("Common"));
00028 MGPAGains_ = commonParams.getUntrackedParameter<std::vector<int> >("MGPAGains");
00029 MGPAGainsPN_ = commonParams.getUntrackedParameter<std::vector<int> >("MGPAGainsPN");
00030
00031 for(int idcc(0); idcc < 54; idcc++){
00032 enable_[idcc] = false;
00033 gain_[idcc] = 12;
00034 }
00035
00036 for(std::vector<int>::iterator gainItr(MGPAGains_.begin()); gainItr != MGPAGains_.end(); ++gainItr)
00037 if(*gainItr != 1 && *gainItr != 6 && *gainItr != 12) throw cms::Exception("InvalidConfiguration") << "MGPA gain" << std::endl;
00038
00039 for(std::vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr)
00040 if(*gainItr != 1 && *gainItr != 16) throw cms::Exception("InvalidConfiguration") << "PN diode gain" << std::endl;
00041
00042 map<string, string> replacements;
00043 stringstream ss;
00044
00045 for(vector<int>::iterator gainItr(MGPAGains_.begin()); gainItr != MGPAGains_.end(); ++gainItr){
00046 ss.str("");
00047 ss << *gainItr;
00048 replacements["gain"] = ss.str();
00049
00050 unsigned offset(0);
00051 switch(*gainItr){
00052 case 1: offset = 0; break;
00053 case 6: offset = 1; break;
00054 case 12: offset = 2; break;
00055 default: break;
00056 }
00057
00058 MEs_[kOccupancy + offset]->name(replacements);
00059 MEs_[kShape + offset]->name(replacements);
00060 MEs_[kAmplitude + offset]->name(replacements);
00061 }
00062
00063 for(vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
00064 ss.str("");
00065 ss << *gainItr;
00066 replacements["pngain"] = ss.str();
00067
00068 unsigned offset(0);
00069 switch(*gainItr){
00070 case 1: offset = 0; break;
00071 case 16: offset = 1; break;
00072 default: break;
00073 }
00074
00075 MEs_[kPNOccupancy + offset]->name(replacements);
00076 MEs_[kPNAmplitude + offset]->name(replacements);
00077 }
00078 }
00079
00080 TestPulseTask::~TestPulseTask()
00081 {
00082 }
00083
00084 void
00085 TestPulseTask::bookMEs()
00086 {
00087 for(std::vector<int>::iterator gainItr(MGPAGains_.begin()); gainItr != MGPAGains_.end(); ++gainItr){
00088 unsigned offset(0);
00089 switch(*gainItr){
00090 case 1: offset = 0; break;
00091 case 6: offset = 1; break;
00092 case 12: offset = 2; break;
00093 default: break;
00094 }
00095
00096 MEs_[kOccupancy + offset]->book();
00097 MEs_[kShape + offset]->book();
00098 MEs_[kAmplitude + offset]->book();
00099 }
00100 for(std::vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
00101 unsigned offset(0);
00102 switch(*gainItr){
00103 case 1: offset = 0; break;
00104 case 16: offset = 1; break;
00105 default: break;
00106 }
00107
00108 MEs_[kPNOccupancy + offset]->book();
00109 MEs_[kPNAmplitude + offset]->book();
00110 }
00111 }
00112
00113 void
00114 TestPulseTask::beginRun(const edm::Run&, const edm::EventSetup&)
00115 {
00116 for(int idcc(0); idcc < 54; idcc++){
00117 enable_[idcc] = false;
00118 gain_[idcc] = 0;
00119 }
00120 }
00121
00122 void
00123 TestPulseTask::endEvent(const edm::Event&, const edm::EventSetup&)
00124 {
00125 for(int idcc(0); idcc < 54; idcc++){
00126 enable_[idcc] = false;
00127 gain_[idcc] = 0;
00128 }
00129 }
00130
00131 bool
00132 TestPulseTask::filterRunType(const std::vector<short>& _runType)
00133 {
00134 bool enable(false);
00135
00136 for(int iFED(0); iFED < 54; iFED++){
00137 if(_runType[iFED] == EcalDCCHeaderBlock::TESTPULSE_MGPA ||
00138 _runType[iFED] == EcalDCCHeaderBlock::TESTPULSE_GAP){
00139 enable = true;
00140 enable_[iFED] = true;
00141 }
00142 }
00143
00144 return enable;
00145 }
00146
00147 void
00148 TestPulseTask::runOnDigis(const EcalDigiCollection &_digis)
00149 {
00150 for(EcalDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
00151 DetId id(digiItr->id());
00152
00153 int iDCC(dccId(id) - 1);
00154
00155 if(!enable_[iDCC]) continue;
00156
00157
00158 EcalDataFrame dataFrame(*digiItr);
00159
00160 unsigned offset(0);
00161 switch(dataFrame.sample(0).gainId()){
00162 case 1: offset = 2; gain_[iDCC] = 12; break;
00163 case 2: offset = 1; gain_[iDCC] = 6; break;
00164 case 3: offset = 0; gain_[iDCC] = 1; break;
00165 default: continue;
00166 }
00167
00168 if(std::find(MGPAGains_.begin(), MGPAGains_.end(), gain_[iDCC]) == MGPAGains_.end()) continue;
00169
00170 MEs_[kOccupancy + offset]->fill(id);
00171
00172 for(int iSample(0); iSample < 10; iSample++)
00173 MEs_[kShape + offset]->fill(id, iSample + 0.5, float(dataFrame.sample(iSample).adc()));
00174 }
00175 }
00176
00177 void
00178 TestPulseTask::runOnPnDigis(const EcalPnDiodeDigiCollection &_digis)
00179 {
00180 for(EcalPnDiodeDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
00181 EcalPnDiodeDetId id(digiItr->id());
00182
00183 int iDCC(dccId(id) - 1);
00184
00185 if(!enable_[iDCC]) continue;
00186
00187 unsigned offset(0);
00188 int gain(0);
00189 switch(digiItr->sample(0).gainId()){
00190 case 0: offset = 0; gain = 1; break;
00191 case 1: offset = 1; gain = 16; break;
00192 default: continue;
00193 }
00194
00195 if(std::find(MGPAGainsPN_.begin(), MGPAGainsPN_.end(), gain) == MGPAGainsPN_.end()) continue;
00196
00197 MEs_[kPNOccupancy + offset]->fill(id);
00198
00199 float pedestal(0.);
00200 for(int iSample(0); iSample < 4; iSample++)
00201 pedestal += digiItr->sample(iSample).adc();
00202 pedestal /= 4.;
00203
00204 float max(0.);
00205 for(int iSample(0); iSample < 50; iSample++)
00206 if(digiItr->sample(iSample).adc() > max) max = digiItr->sample(iSample).adc();
00207
00208 float amplitude(max - pedestal);
00209
00210 MEs_[kPNAmplitude + offset]->fill(id, amplitude);
00211 }
00212 }
00213
00214 void
00215 TestPulseTask::runOnUncalibRecHits(const EcalUncalibratedRecHitCollection &_uhits)
00216 {
00217 for(EcalUncalibratedRecHitCollection::const_iterator uhitItr(_uhits.begin()); uhitItr != _uhits.end(); ++uhitItr){
00218 DetId id(uhitItr->id());
00219
00220 int iDCC(dccId(id) - 1);
00221
00222 if(!enable_[iDCC]) continue;
00223
00224 unsigned offset(0);
00225 switch(gain_[iDCC]){
00226 case 1: offset = 0; break;
00227 case 6: offset = 1; break;
00228 case 12: offset = 2; break;
00229 default: continue;
00230 }
00231
00232 MEs_[kAmplitude + offset]->fill(id, uhitItr->amplitude());
00233 }
00234 }
00235
00236
00237 void
00238 TestPulseTask::setMEData(std::vector<MEData>& _data)
00239 {
00240 BinService::AxisSpecs axis;
00241 axis.nbins = 10;
00242 axis.low = 0.;
00243 axis.high = 10.;
00244
00245 for(unsigned iGain(0); iGain < nGain; iGain++){
00246 _data[kOccupancy + iGain] = MEData("Occupancy", BinService::kEcal2P, BinService::kSuperCrystal, MonitorElement::DQM_KIND_TH2F);
00247 _data[kShape + iGain] = MEData("Shape", BinService::kSM, BinService::kSuperCrystal, MonitorElement::DQM_KIND_TPROFILE2D, 0, &axis);
00248 _data[kAmplitude + iGain] = MEData("Amplitude", BinService::kSM, BinService::kCrystal, MonitorElement::DQM_KIND_TPROFILE2D);
00249 }
00250 for(unsigned iPNGain(0); iPNGain < nPNGain; iPNGain++){
00251 _data[kPNOccupancy + iPNGain] = MEData("PNOccupancy", BinService::kEcalMEM2P, BinService::kCrystal, MonitorElement::DQM_KIND_TH2F);
00252 _data[kPNAmplitude + iPNGain] = MEData("PNPedestal", BinService::kSMMEM, BinService::kCrystal, MonitorElement::DQM_KIND_TPROFILE);
00253 }
00254 }
00255
00256 DEFINE_ECALDQM_WORKER(TestPulseTask);
00257 }