Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-19 10:28:04

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  \author A. Vilela Pereira
0005  */
0006 
0007 #include "DTTTrigFillWithAverage.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0011 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0012 #include "DataFormats/MuonDetId/interface/DTSuperLayerId.h"
0013 #include "CondFormats/DTObjects/interface/DTTtrig.h"
0014 #include "CondFormats/DataRecord/interface/DTTtrigRcd.h"
0015 
0016 using namespace std;
0017 using namespace edm;
0018 
0019 namespace dtCalibration {
0020 
0021   DTTTrigFillWithAverage::DTTTrigFillWithAverage(const ParameterSet& pset, edm::ConsumesCollector cc)
0022       : foundAverage_(false) {
0023     ttrigToken_ =
0024         cc.esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", pset.getUntrackedParameter<string>("dbLabel")));
0025     dtGeomToken_ = cc.esConsumes<edm::Transition::BeginRun>();
0026   }
0027 
0028   DTTTrigFillWithAverage::~DTTTrigFillWithAverage() {}
0029 
0030   void DTTTrigFillWithAverage::setES(const EventSetup& setup) {
0031     // Get tTrig record from DB
0032     ESHandle<DTTtrig> tTrig;
0033     tTrig = setup.getHandle(ttrigToken_);
0034     tTrigMap_ = &*tTrig;
0035 
0036     // Get geometry from Event Setup
0037     muonGeom_ = setup.getHandle(dtGeomToken_);
0038   }
0039 
0040   DTTTrigData DTTTrigFillWithAverage::correction(const DTSuperLayerId& slId) {
0041     float tTrigMean, tTrigSigma, kFactor;
0042     int status = tTrigMap_->get(slId, tTrigMean, tTrigSigma, kFactor, DTTimeUnits::ns);
0043     if (!status) {
0044       return DTTTrigData(tTrigMean, tTrigSigma, kFactor);
0045     } else {
0046       if (!foundAverage_)
0047         getAverage();
0048       float corrMean = initialTTrig_.aveMean;
0049       float corrSigma = initialTTrig_.aveSigma;
0050       float corrKFactor = initialTTrig_.aveKFactor;
0051       return DTTTrigData(corrMean, corrSigma, corrKFactor);  //FIXME: kFactor is not anymore a unique one
0052     }
0053   }
0054 
0055   void DTTTrigFillWithAverage::getAverage() {
0056     //Get the superlayers list
0057     vector<const DTSuperLayer*> dtSupLylist = muonGeom_->superLayers();
0058 
0059     float aveMean = 0.;
0060     float ave2Mean = 0.;
0061     float aveSigma = 0.;
0062     float ave2Sigma = 0.;
0063     float aveKFactor = 0.;
0064     int nIter = 0;
0065 
0066     for (auto sl = muonGeom_->superLayers().begin(); sl != muonGeom_->superLayers().end(); ++sl) {
0067       float tTrigMean, tTrigSigma, kFactor;
0068       int status = tTrigMap_->get((*sl)->id(), tTrigMean, tTrigSigma, kFactor, DTTimeUnits::ns);
0069       if (!status) {
0070         ++nIter;
0071         aveMean += tTrigMean;
0072         ave2Mean += tTrigMean * tTrigMean;
0073         aveSigma += tTrigSigma;
0074         ave2Sigma += tTrigSigma * tTrigSigma;
0075         aveKFactor += kFactor;
0076       }
0077     }
0078 
0079     // Compute average
0080     aveMean /= nIter;
0081     float rmsMean = ave2Mean / (nIter - 1) - aveMean * aveMean;
0082     rmsMean = sqrt(rmsMean);
0083     aveSigma /= nIter;
0084     float rmsSigma = ave2Sigma / (nIter - 1) - aveSigma * aveSigma;
0085     rmsSigma = sqrt(rmsSigma);
0086     aveKFactor /= nIter;
0087 
0088     initialTTrig_.aveMean = aveMean;
0089     initialTTrig_.rmsMean = rmsMean;
0090     initialTTrig_.aveSigma = aveSigma;
0091     initialTTrig_.rmsSigma = rmsSigma;
0092     initialTTrig_.aveKFactor = aveKFactor;
0093 
0094     LogVerbatim("Calibration") << "[DTTTrigFillWithAverage] Found from " << nIter << " SL's\n"
0095                                << "                               average tTrig mean: " << aveMean << "\n"
0096                                << "                               tTrig mean RMS: " << rmsMean << "\n"
0097                                << "                               average tTrig sigma: " << aveSigma << "\n"
0098                                << "                               tTrig sigma RMS: " << rmsSigma << "\n"
0099                                << "                               kFactor mean: " << aveKFactor;
0100     foundAverage_ = true;
0101   }
0102 
0103 }  // namespace dtCalibration