CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/DQM/EcalBarrelMonitorClient/src/LaserClient.cc

Go to the documentation of this file.
00001 #include "../interface/LaserClient.h"
00002 
00003 #include "DataFormats/EcalDetId/interface/EcalPnDiodeDetId.h"
00004 
00005 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
00006 
00007 #include <cmath>
00008 
00009 namespace ecaldqm {
00010 
00011   LaserClient::LaserClient(const edm::ParameterSet& _params, const edm::ParameterSet& _paths) :
00012     DQWorkerClient(_params, _paths, "LaserClient"),
00013     laserWavelengths_(),
00014     MGPAGainsPN_(),
00015     minChannelEntries_(0),
00016     expectedAmplitude_(),
00017     amplitudeThreshold_(),
00018     amplitudeRMSThreshold_(),
00019     expectedTiming_(),
00020     timingThreshold_(),
00021     timingRMSThreshold_(),
00022     expectedPNAmplitude_(),
00023     pnAmplitudeThreshold_(),
00024     pnAmplitudeRMSThreshold_(),
00025     towerThreshold_()
00026   {
00027     using namespace std;
00028 
00029     edm::ParameterSet const& commonParams(_params.getUntrackedParameterSet("Common"));
00030     MGPAGainsPN_ = commonParams.getUntrackedParameter<vector<int> >("MGPAGainsPN");
00031 
00032     edm::ParameterSet const& taskParams(_params.getUntrackedParameterSet(name_));
00033     laserWavelengths_ = taskParams.getUntrackedParameter<vector<int> >("laserWavelengths");
00034     minChannelEntries_ = taskParams.getUntrackedParameter<int>("minChannelEntries");
00035     expectedAmplitude_ = taskParams.getUntrackedParameter<vector<double> >("expectedAmplitude");
00036     amplitudeThreshold_ = taskParams.getUntrackedParameter<vector<double> >("amplitudeThreshold");
00037     amplitudeRMSThreshold_ = taskParams.getUntrackedParameter<vector<double> >("amplitudeRMSThreshold");
00038     expectedTiming_ = taskParams.getUntrackedParameter<vector<double> >("expectedTiming");
00039     timingThreshold_ = taskParams.getUntrackedParameter<vector<double> >("timingThreshold");
00040     timingRMSThreshold_ = taskParams.getUntrackedParameter<vector<double> >("timingRMSThreshold");
00041     expectedPNAmplitude_ = taskParams.getUntrackedParameter<vector<double> >("expectedPNAmplitude");
00042     pnAmplitudeThreshold_ = taskParams.getUntrackedParameter<vector<double> >("pnAmplitudeThreshold");
00043     pnAmplitudeRMSThreshold_ = taskParams.getUntrackedParameter<vector<double> >("pnAmplitudeRMSThreshold");
00044     towerThreshold_ = taskParams.getUntrackedParameter<double>("towerThreshold");
00045 
00046     for(vector<int>::iterator wlItr(laserWavelengths_.begin()); wlItr != laserWavelengths_.end(); ++wlItr)
00047       if(*wlItr <= 0 || *wlItr >= 5) throw cms::Exception("InvalidConfiguration") << "Laser Wavelength" << endl;
00048 
00049     for(vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr)
00050       if(*gainItr != 1 && *gainItr != 16) throw cms::Exception("InvalidConfiguration") << "PN diode gain" << endl;
00051 
00052     if(expectedAmplitude_.size() != nWL ||
00053        amplitudeThreshold_.size() != nWL ||
00054        amplitudeRMSThreshold_.size() != nWL ||
00055        expectedTiming_.size() != nWL ||
00056        timingThreshold_.size() != nWL ||
00057        timingRMSThreshold_.size() != nWL ||
00058        expectedPNAmplitude_.size() != nWL * nPNGain ||
00059        pnAmplitudeThreshold_.size() != nWL * nPNGain ||
00060        pnAmplitudeRMSThreshold_.size() != nWL * nPNGain)
00061       throw cms::Exception("InvalidConfiguration") << "Size of quality cut parameter vectors" << endl;
00062 
00063     map<string, string> replacements;
00064     stringstream ss;
00065 
00066     edm::ParameterSet const& sources(_params.getUntrackedParameterSet("sources"));
00067     for(vector<int>::iterator wlItr(laserWavelengths_.begin()); wlItr != laserWavelengths_.end(); ++wlItr){
00068       ss.str("");
00069       ss << *wlItr;
00070       replacements["wl"] = ss.str();
00071 
00072       unsigned offset(*wlItr - 1);
00073       source_(sAmplitude + offset, "LaserTask", LaserTask::kAmplitude + offset, sources);
00074       source_(sTiming + offset, "LaserTask", LaserTask::kTiming + offset, sources);
00075 
00076       sources_[sAmplitude + offset]->name(replacements);
00077       sources_[sTiming + offset]->name(replacements);
00078 
00079       for(vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
00080         ss.str("");
00081         ss << *gainItr;
00082         replacements["pngain"] = ss.str();
00083 
00084         offset = (*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1);
00085         source_(sPNAmplitude + offset, "LaserTask", LaserTask::kPNAmplitude, sources);
00086 
00087         sources_[sPNAmplitude + offset]->name(replacements);
00088       }
00089     }
00090 
00091     BinService::AxisSpecs axis;
00092 
00093     for(vector<int>::iterator wlItr(laserWavelengths_.begin()); wlItr != laserWavelengths_.end(); ++wlItr){
00094       ss.str("");
00095       ss << *wlItr;
00096       replacements["wl"] = ss.str();
00097 
00098       unsigned offset(*wlItr - 1);
00099 
00100       MEs_[kQuality + offset]->name(replacements);
00101       MEs_[kQualitySummary + offset]->name(replacements);
00102       MEs_[kAmplitudeMean + offset]->name(replacements);
00103       MEs_[kAmplitudeRMS + offset]->name(replacements);
00104       MEs_[kTimingMean + offset]->name(replacements);
00105       MEs_[kTimingRMS + offset]->name(replacements);
00106       MEs_[kPNQualitySummary + offset]->name(replacements);
00107 
00108       for(vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
00109         ss.str("");
00110         ss << *gainItr;
00111         replacements["pngain"] = ss.str();
00112 
00113         offset = (*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1);
00114 
00115         MEs_[kPNAmplitudeMean + offset]->name(replacements);
00116         MEs_[kPNAmplitudeRMS + offset]->name(replacements);
00117       }
00118     }
00119   }
00120 
00121   void
00122   LaserClient::initialize()
00123   {
00124     initialized_ = true;
00125 
00126     for(std::vector<int>::iterator wlItr(laserWavelengths_.begin()); wlItr != laserWavelengths_.end(); ++wlItr){
00127       unsigned offset(*wlItr - 1);
00128 
00129       initialized_ &= sources_[sAmplitude + offset]->retrieve();
00130       initialized_ &= sources_[sTiming + offset]->retrieve();
00131 
00132       for(std::vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
00133         offset = (*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1);
00134 
00135         initialized_ &= sources_[sPNAmplitude + offset]->retrieve();
00136       }
00137     }
00138   }
00139 
00140   void
00141   LaserClient::bookMEs()
00142   {
00143     for(std::vector<int>::iterator wlItr(laserWavelengths_.begin()); wlItr != laserWavelengths_.end(); ++wlItr){
00144       unsigned offset(*wlItr - 1);
00145 
00146       MEs_[kQuality + offset]->book();
00147       MEs_[kQualitySummary + offset]->book();
00148       MEs_[kAmplitudeMean + offset]->book();
00149       MEs_[kAmplitudeRMS + offset]->book();
00150       MEs_[kTimingMean + offset]->book();
00151       MEs_[kTimingRMS + offset]->book();
00152       MEs_[kPNQualitySummary + offset]->book();
00153 
00154       for(std::vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
00155         offset = (*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1);
00156 
00157         MEs_[kPNAmplitudeMean + offset]->book();
00158         MEs_[kPNAmplitudeRMS + offset]->book();
00159       }
00160     }
00161   }
00162 
00163   void
00164   LaserClient::beginRun(const edm::Run &, const edm::EventSetup &)
00165   {
00166     for(std::vector<int>::iterator wlItr(laserWavelengths_.begin()); wlItr != laserWavelengths_.end(); ++wlItr){
00167       unsigned offset(*wlItr - 1);
00168       MEs_[kQuality + offset]->resetAll(-1.);
00169       MEs_[kQualitySummary + offset]->resetAll(-1.);
00170 
00171       for(std::vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
00172         offset = (*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1);
00173         MEs_[kPNQualitySummary + offset]->resetAll(-1.);
00174       }
00175     }
00176   }
00177 
00178   void
00179   LaserClient::producePlots()
00180   {
00181     using namespace std;
00182 
00183     for(vector<int>::iterator wlItr(laserWavelengths_.begin()); wlItr != laserWavelengths_.end(); ++wlItr){
00184 
00185       unsigned offset(*wlItr - 1);
00186 
00187       MEs_[kQuality + offset]->reset(2.);
00188       MEs_[kQualitySummary + offset]->reset(2.);
00189       MEs_[kPNQualitySummary + offset]->reset(2.);
00190 
00191       MEs_[kAmplitudeMean + offset]->reset();
00192       MEs_[kAmplitudeRMS + offset]->reset();
00193       MEs_[kTimingMean + offset]->reset();
00194       MEs_[kTimingRMS + offset]->reset();
00195 
00196       for(vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
00197         unsigned suboffset((*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1));
00198 
00199         MEs_[kPNAmplitudeMean + suboffset]->reset();
00200         MEs_[kPNAmplitudeRMS + suboffset]->reset();
00201       }
00202 
00203       for(unsigned dccid(1); dccid <= 54; dccid++){
00204 
00205         for(unsigned tower(1); tower <= getNSuperCrystals(dccid); tower++){
00206           std::vector<DetId> ids(getElectronicsMap()->dccTowerConstituents(dccid, tower));
00207 
00208           if(ids.size() == 0) continue;
00209 
00210           float nBad(0.);
00211 
00212           for(std::vector<DetId>::iterator idItr(ids.begin()); idItr != ids.end(); ++idItr){
00213             float aEntries(sources_[sAmplitude + offset]->getBinEntries(*idItr));
00214 
00215             if(aEntries < minChannelEntries_) continue;
00216 
00217             float aMean(sources_[sAmplitude + offset]->getBinContent(*idItr));
00218             float aRms(sources_[sAmplitude + offset]->getBinError(*idItr) * std::sqrt(aEntries));
00219 
00220             MEs_[kAmplitudeMean + offset]->fill(*idItr, aMean);
00221             MEs_[kAmplitudeRMS + offset]->fill(*idItr, aRms);
00222 
00223             float tEntries(sources_[sTiming + offset]->getBinEntries(*idItr));
00224 
00225             if(tEntries < minChannelEntries_) continue;
00226 
00227             float tMean(sources_[sTiming + offset]->getBinContent(*idItr));
00228             float tRms(sources_[sTiming + offset]->getBinError(*idItr) * std::sqrt(tEntries));
00229 
00230             MEs_[kTimingMean + offset]->fill(*idItr, tMean);
00231             MEs_[kTimingRMS + offset]->fill(*idItr, tRms);
00232 
00233             if(std::abs(aMean - expectedAmplitude_[offset]) > amplitudeThreshold_[offset] || aRms > amplitudeRMSThreshold_[offset] ||
00234                std::abs(tMean - expectedTiming_[offset]) > timingThreshold_[offset] || tRms > timingRMSThreshold_[offset]){
00235               MEs_[kQuality + offset]->setBinContent(*idItr, 0.);
00236               nBad += 1.;
00237             }
00238             else
00239               MEs_[kQuality + offset]->setBinContent(*idItr, 1.);
00240           }
00241 
00242           if(nBad / ids.size() > towerThreshold_)
00243             MEs_[kQualitySummary + offset]->setBinContent(ids[0], 0.);
00244           else
00245             MEs_[kQualitySummary + offset]->setBinContent(ids[0], 1.);
00246         }
00247 
00248         unsigned subdet;
00249         if(dccid <= 9 || dccid >= 46) subdet = EcalEndcap;
00250         else subdet = EcalBarrel;
00251 
00252         for(unsigned pn(1); pn <= 10; pn++){
00253           EcalPnDiodeDetId pnid(subdet, dccid, pn);
00254 
00255           bool bad(false);
00256           for(vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
00257             unsigned suboffset((*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1));
00258 
00259             float pEntries(sources_[sPNAmplitude + suboffset]->getBinEntries(pnid));
00260 
00261             if(pEntries < minChannelEntries_) continue;
00262 
00263             float pMean(sources_[sPNAmplitude + suboffset]->getBinContent(pnid));
00264             float pRms(sources_[sPNAmplitude + suboffset]->getBinError(pnid) * std::sqrt(pEntries));
00265 
00266             MEs_[kPNAmplitudeMean + suboffset]->fill(pnid, pMean);
00267             MEs_[kPNAmplitudeRMS + suboffset]->fill(pnid, pRms);
00268 
00269             if(std::abs(pMean - expectedPNAmplitude_[suboffset]) > pnAmplitudeThreshold_[suboffset] || pRms > pnAmplitudeRMSThreshold_[suboffset])
00270               bad = true;
00271           }
00272 
00273           if(bad)
00274             MEs_[kPNQualitySummary + offset]->setBinContent(pnid, 0.);
00275           else
00276             MEs_[kPNQualitySummary + offset]->setBinContent(pnid, 1.);
00277         }
00278 
00279       }
00280     }
00281   }
00282 
00283   /*static*/
00284   void
00285   LaserClient::setMEData(std::vector<MEData>& _data)
00286   {
00287     BinService::AxisSpecs axis;
00288 
00289     for(unsigned iWL(0); iWL < nWL; iWL++){
00290       _data[kQuality + iWL] = MEData("Quality", BinService::kSM, BinService::kCrystal, MonitorElement::DQM_KIND_TH2F);
00291 
00292       axis.nbins = 100;
00293       axis.low = 0.;
00294       axis.high = 4096.;
00295       _data[kAmplitudeMean + iWL] = MEData("AmplitudeMean", BinService::kSM, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &axis);
00296 
00297       axis.low = 0.;
00298       axis.high = 400.;
00299       _data[kAmplitudeRMS + iWL] = MEData("AmplitudeRMS", BinService::kSM, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &axis);
00300 
00301       axis.low = 3.5;
00302       axis.high = 5.5;
00303       _data[kTimingMean + iWL] = MEData("TimingMean", BinService::kSM, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &axis);
00304 
00305       axis.low = 0.;
00306       axis.high = 0.5;
00307       _data[kTimingRMS + iWL] = MEData("TimingRMS", BinService::kSM, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &axis);
00308 
00309       _data[kQualitySummary + iWL] = MEData("QualitySummary", BinService::kEcal2P, BinService::kSuperCrystal, MonitorElement::DQM_KIND_TH2F);
00310       _data[kPNQualitySummary + iWL] = MEData("PNQualitySummary", BinService::kEcalMEM2P, BinService::kCrystal, MonitorElement::DQM_KIND_TH2F);
00311 
00312       for(unsigned iPNGain(0); iPNGain < nPNGain; iPNGain++){
00313         unsigned offset(iWL * nPNGain + iPNGain);
00314 
00315         axis.low = 0.;
00316         axis.high = 4096.;
00317         _data[kPNAmplitudeMean + offset] = MEData("PNAmplitudeMean", BinService::kSMMEM, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &axis);
00318 
00319         axis.low = 0.;
00320         axis.high = 200.;
00321         _data[kPNAmplitudeRMS + offset] = MEData("PNAmplitudeRMS", BinService::kSMMEM, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &axis);
00322       }
00323     }
00324   }
00325 
00326   DEFINE_ECALDQM_WORKER(LaserClient);
00327 }