CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/DQM/EcalBarrelMonitorTasks/src/LaserTask.cc

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