CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/DQM/EcalBarrelMonitorTasks/src/LedTask.cc

Go to the documentation of this file.
00001 #include "../interface/LedTask.h"
00002 
00003 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEEBGeom.h"
00004 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEEEGeom.h"
00005 
00006 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
00007 
00008 namespace ecaldqm {
00009 
00010   LedTask::LedTask(const edm::ParameterSet &_params, const edm::ParameterSet& _paths) :
00011     DQWorkerTask(_params, _paths, "LedTask"),
00012     ledWavelengths_(),
00013     MGPAGainsPN_(),
00014     pnAmp_()
00015   {
00016     using namespace std;
00017 
00018     collectionMask_ = 
00019       (0x1 << kEcalRawData) |
00020       (0x1 << kEEDigi) |
00021       (0x1 << kPnDiodeDigi) |
00022       (0x1 << kEBUncalibRecHit) |
00023       (0x1 << kEEUncalibRecHit);
00024 
00025     edm::ParameterSet const& commonParams(_params.getUntrackedParameterSet("Common"));
00026     MGPAGainsPN_ = commonParams.getUntrackedParameter<std::vector<int> >("MGPAGainsPN");
00027 
00028     edm::ParameterSet const& taskParams(_params.getUntrackedParameterSet(name_));
00029     ledWavelengths_ = taskParams.getUntrackedParameter<std::vector<int> >("ledWavelengths");
00030 
00031     for(std::vector<int>::iterator wlItr(ledWavelengths_.begin()); wlItr != ledWavelengths_.end(); ++wlItr)
00032       if(*wlItr != 1 && *wlItr != 2) throw cms::Exception("InvalidConfiguration") << "Led Wavelength" << std::endl;
00033 
00034     for(std::vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr)
00035       if(*gainItr != 1 && *gainItr != 16) throw cms::Exception("InvalidConfiguration") << "PN diode gain" << std::endl; 
00036 
00037     map<string, string> replacements;
00038     stringstream ss;
00039 
00040     for(vector<int>::iterator wlItr(ledWavelengths_.begin()); wlItr != ledWavelengths_.end(); ++wlItr){
00041       ss.str("");
00042       ss << *wlItr;
00043       replacements["wl"] = ss.str();
00044 
00045       unsigned offset(*wlItr - 1);
00046 
00047       MEs_[kAmplitudeSummary + offset]->name(replacements);
00048       MEs_[kAmplitude + offset]->name(replacements);
00049       MEs_[kOccupancy + offset]->name(replacements);
00050       MEs_[kShape + offset]->name(replacements);
00051       MEs_[kTiming + offset]->name(replacements);
00052       MEs_[kAOverP + offset]->name(replacements);
00053 
00054       for(vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
00055         ss.str("");
00056         ss << *gainItr;
00057         replacements["pngain"] = ss.str();
00058 
00059         offset = (*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1);
00060 
00061         MEs_[kPNAmplitude + offset]->name(replacements);
00062       }
00063     }
00064   }
00065 
00066   LedTask::~LedTask()
00067   {
00068   }
00069 
00070   void
00071   LedTask::bookMEs()
00072   {
00073     for(std::vector<int>::iterator wlItr(ledWavelengths_.begin()); wlItr != ledWavelengths_.end(); ++wlItr){
00074       unsigned offset(*wlItr - 1);
00075 
00076       MEs_[kAmplitudeSummary + offset]->book();
00077       MEs_[kAmplitude + offset]->book();
00078       MEs_[kOccupancy + offset]->book();
00079       MEs_[kTiming + offset]->book();
00080       MEs_[kShape + offset]->book();
00081       MEs_[kAOverP + offset]->book();
00082 
00083       for(std::vector<int>::iterator gainItr(MGPAGainsPN_.begin()); gainItr != MGPAGainsPN_.end(); ++gainItr){
00084         offset = (*wlItr - 1) * nPNGain + (*gainItr == 1 ? 0 : 1);
00085 
00086         MEs_[kPNAmplitude + offset]->book();
00087       }
00088     }
00089 
00090     MEs_[kPNOccupancy]->book();
00091   }
00092 
00093   void
00094   LedTask::beginRun(const edm::Run &, const edm::EventSetup &_es)
00095   {
00096     for(int iDCC(0); iDCC < BinService::nDCC; iDCC++){
00097       enable_[iDCC] = false;
00098       wavelength_[iDCC] = -1;
00099     }
00100     pnAmp_.clear();
00101   }
00102 
00103   void
00104   LedTask::endEvent(const edm::Event &, const edm::EventSetup &)
00105   {
00106     for(int iDCC(0); iDCC < BinService::nDCC; iDCC++){
00107       enable_[iDCC] = false;
00108       wavelength_[iDCC] = -1;
00109     }
00110     pnAmp_.clear();
00111   }
00112 
00113   bool
00114   LedTask::filterRunType(const std::vector<short>& _runType)
00115   {
00116     bool enable(false);
00117 
00118     for(int iDCC(0); iDCC < BinService::nDCC; iDCC++){
00119       if(_runType[iDCC] == EcalDCCHeaderBlock::LED_STD ||
00120          _runType[iDCC] == EcalDCCHeaderBlock::LED_GAP){
00121         enable = true;
00122         enable_[iDCC] = true;
00123       }
00124     }
00125 
00126     return enable;
00127   }
00128 
00129   void
00130   LedTask::runOnRawData(const EcalRawDataCollection &_dcchs)
00131   {
00132     for(EcalRawDataCollection::const_iterator dcchItr(_dcchs.begin()); dcchItr != _dcchs.end(); ++dcchItr){
00133       int iDCC(dcchItr->id() - 1);
00134 
00135       if(!enable_[iDCC]) continue;
00136 
00137       wavelength_[iDCC] = dcchItr->getEventSettings().wavelength + 1;
00138 
00139       if(std::find(ledWavelengths_.begin(), ledWavelengths_.end(), wavelength_[iDCC]) == ledWavelengths_.end()) enable_[iDCC] = false;
00140     }
00141   }
00142 
00143   void
00144   LedTask::runOnDigis(const EcalDigiCollection &_digis)
00145   {
00146     for(EcalDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
00147       const DetId& id(digiItr->id());
00148 
00149       int iDCC(dccId(id) - 1);
00150 
00151       if(!enable_[iDCC]) continue;
00152 
00153       unsigned offset(-1);
00154       switch(wavelength_[iDCC]){
00155       case 1: offset = 0; break;
00156       case 3: offset = 1; break;
00157       default: continue;
00158       }
00159 
00160       MEs_[kOccupancy + offset]->fill(id);
00161 
00162       // EcalDataFrame is not a derived class of edm::DataFrame, but can take edm::DataFrame in the constructor
00163       EcalDataFrame dataFrame(*digiItr);
00164 
00165       for(int iSample(0); iSample < 10; iSample++)
00166         MEs_[kShape + offset]->fill(id, iSample + 0.5, float(dataFrame.sample(iSample).adc()));
00167     }
00168   }
00169 
00170   void
00171   LedTask::runOnPnDigis(const EcalPnDiodeDigiCollection &_digis)
00172   {
00173     for(EcalPnDiodeDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
00174       const EcalPnDiodeDetId& id(digiItr->id());
00175 
00176       int iDCC(dccId(id) - 1);
00177 
00178       if(!enable_[iDCC]) continue;
00179 
00180       MEs_[kPNOccupancy]->fill(id);
00181 
00182       float pedestal(0.);
00183       for(int iSample(0); iSample < 4; iSample++)
00184         pedestal += digiItr->sample(iSample).adc();
00185       pedestal /= 4.;
00186 
00187       float max(0.);
00188       for(int iSample(0); iSample < 50; iSample++){
00189         EcalFEMSample sample(digiItr->sample(iSample));
00190 
00191         float amp(digiItr->sample(iSample).adc() - pedestal);
00192 
00193         if(amp > max) max = amp;
00194       }
00195 
00196       int gain(digiItr->sample(0).gainId() == 0 ? 1 : 16);
00197       max *= (16. / gain);
00198 
00199       unsigned offset(-1);
00200       switch(wavelength_[iDCC]){
00201       case 1: offset = (gain == 1 ? 0 : 1); break;
00202       case 3: offset = nPNGain + (gain == 1 ? 0 : 1); break;
00203       default: continue;
00204       }
00205 
00206       MEs_[kPNAmplitude + offset]->fill(id, max);
00207 
00208       if(pnAmp_.find(iDCC) == pnAmp_.end()) pnAmp_[iDCC].resize(10);
00209       pnAmp_[iDCC][id.iPnId() - 1] = max;
00210     }
00211   }
00212 
00213   void
00214   LedTask::runOnUncalibRecHits(const EcalUncalibratedRecHitCollection &_uhits)
00215   {
00216     using namespace std;
00217 
00218     for(EcalUncalibratedRecHitCollection::const_iterator uhitItr(_uhits.begin()); uhitItr != _uhits.end(); ++uhitItr){
00219       EEDetId id(uhitItr->id());
00220 
00221       int iDCC(dccId(id) - 1);
00222 
00223       if(!enable_[iDCC]) continue;
00224 
00225       unsigned offset(-1);
00226       switch(wavelength_[iDCC]){
00227       case 1: offset = 0; break;
00228       case 3: offset = 1; break;
00229       default: continue;
00230       }
00231 
00232       float amp(max((double)uhitItr->amplitude(), 0.));
00233       float jitter(max((double)uhitItr->jitter() + 5.0, 0.));
00234 
00235       MEs_[kAmplitudeSummary + offset]->fill(id, amp);
00236       MEs_[kAmplitude + offset]->fill(id, amp);
00237       MEs_[kTiming + offset]->fill(id, jitter);
00238 
00239       if(pnAmp_.find(iDCC) == pnAmp_.end()) continue;
00240 
00241       float aop(0.);
00242       float pn0(0.), pn1(0.);
00243 
00244       EcalScDetId scid(id.sc());
00245 
00246       int dee(MEEEGeom::dee(scid.ix(), scid.iy(), scid.zside()));
00247       int lmmod(MEEEGeom::lmmod(scid.ix(), scid.iy()));
00248       pair<int, int> pnPair(MEEEGeom::pn(dee, lmmod));
00249 
00250       int pnAFED(getEEPnDCC(dee, 0)), pnBFED(getEEPnDCC(dee, 1));
00251 
00252       pn0 = pnAmp_[pnAFED][pnPair.first];
00253       pn1 = pnAmp_[pnBFED][pnPair.second];
00254 
00255       if(pn0 < 10 && pn1 > 10){
00256         aop = amp / pn1;
00257       }else if(pn0 > 10 && pn1 < 10){
00258         aop = amp / pn0;
00259       }else if(pn0 + pn1 > 1){
00260         aop = amp / (0.5 * (pn0 + pn1));
00261       }else{
00262         aop = 1000.;
00263       }
00264 
00265       MEs_[kAOverP + offset]->fill(id, aop);
00266     }
00267   }
00268 
00269   /*static*/
00270   void
00271   LedTask::setMEData(std::vector<MEData>& _data)
00272   {
00273     BinService::AxisSpecs axis;
00274     axis.nbins = 10;
00275     axis.low = 0.;
00276     axis.high = 10.;
00277 
00278     for(unsigned iWL(0); iWL < nWL; iWL++){
00279       _data[kAmplitudeSummary + iWL] = MEData("AmplitudeSummary", BinService::kEcal2P, BinService::kSuperCrystal, MonitorElement::DQM_KIND_TPROFILE2D);
00280       _data[kAmplitude + iWL] = MEData("Amplitude", BinService::kSM, BinService::kSuperCrystal, MonitorElement::DQM_KIND_TPROFILE2D);
00281       _data[kOccupancy + iWL] = MEData("Occupancy", BinService::kEcal2P, BinService::kSuperCrystal, MonitorElement::DQM_KIND_TH2F);
00282       _data[kShape + iWL] = MEData("Shape", BinService::kSM, BinService::kSuperCrystal, MonitorElement::DQM_KIND_TPROFILE2D, 0, &axis);
00283       _data[kTiming + iWL] = MEData("Timing", BinService::kSM, BinService::kSuperCrystal, MonitorElement::DQM_KIND_TPROFILE2D);
00284       _data[kAOverP + iWL] = MEData("AOverP", BinService::kSM, BinService::kSuperCrystal, MonitorElement::DQM_KIND_TPROFILE2D);
00285 
00286       for(unsigned iPNGain(0); iPNGain < nPNGain; iPNGain++){
00287         unsigned offset(iWL * nPNGain + iPNGain);
00288         _data[kPNAmplitude + offset] = MEData("PNAmplitude", BinService::kSMMEM, BinService::kCrystal, MonitorElement::DQM_KIND_TPROFILE);
00289       }
00290     }
00291     _data[kPNOccupancy] = MEData("PNOccupancy", BinService::kEcalMEM2P, BinService::kCrystal, MonitorElement::DQM_KIND_TH2F);
00292   }
00293 
00294   DEFINE_ECALDQM_WORKER(LedTask);
00295 }