Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-17 23:35:52

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  $Date: 2012/03/02 19:47:32 $
0005  *  $Revision: 1.11 $
0006  *  \author S. Maselli - INFN Torino
0007  *          A. Vilela Pereira
0008  */
0009 
0010 #include "DTTTrigCorrection.h"
0011 
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/Framework/interface/ESHandle.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 
0017 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0018 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0019 #include "Geometry/DTGeometry/interface/DTSuperLayer.h"
0020 
0021 #include "CondFormats/DTObjects/interface/DTTtrig.h"
0022 #include "CondFormats/DataRecord/interface/DTTtrigRcd.h"
0023 
0024 #include "CalibMuon/DTCalibration/interface/DTCalibDBUtils.h"
0025 
0026 #include "CalibMuon/DTCalibration/interface/DTTTrigCorrectionFactory.h"
0027 #include "CalibMuon/DTCalibration/interface/DTTTrigBaseCorrection.h"
0028 #include "FWCore/Framework/interface/ConsumesCollector.h"
0029 
0030 #include <iostream>
0031 #include <fstream>
0032 
0033 using namespace edm;
0034 using namespace std;
0035 
0036 DTTTrigCorrection::DTTTrigCorrection(const ParameterSet& pset)
0037     : correctionAlgo_{DTTTrigCorrectionFactory::get()->create(pset.getParameter<string>("correctionAlgo"),
0038                                                               pset.getParameter<ParameterSet>("correctionAlgoConfig"),
0039                                                               consumesCollector())} {
0040   ttrigToken_ =
0041       esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", pset.getUntrackedParameter<string>("dbLabel")));
0042   dtGeomToken_ = esConsumes<edm::Transition::BeginRun>();
0043   LogVerbatim("Calibration") << "[DTTTrigCorrection] Constructor called" << endl;
0044 }
0045 
0046 DTTTrigCorrection::~DTTTrigCorrection() {
0047   LogVerbatim("Calibration") << "[DTTTrigCorrection] Destructor called" << endl;
0048 }
0049 
0050 void DTTTrigCorrection::beginRun(const edm::Run& run, const edm::EventSetup& setup) {
0051   // Get tTrig record from DB
0052   ESHandle<DTTtrig> tTrig = setup.getHandle(ttrigToken_);
0053   tTrigMap_ = &*tTrig;
0054   LogVerbatim("Calibration") << "[DTTTrigCorrection]: TTrig version: " << tTrig->version() << endl;
0055 
0056   // Get geometry from Event Setup
0057   muonGeom_ = setup.getHandle(dtGeomToken_);
0058 
0059   // Pass EventSetup to correction Algo
0060   correctionAlgo_->setES(setup);
0061 }
0062 
0063 void DTTTrigCorrection::endJob() {
0064   // Create the object to be written to DB
0065   DTTtrig tTrigNewMap;
0066 
0067   for (vector<const DTSuperLayer*>::const_iterator sl = muonGeom_->superLayers().begin();
0068        sl != muonGeom_->superLayers().end();
0069        ++sl) {
0070     // Get old value from DB
0071     float tTrigMean, tTrigSigma, kFactor;
0072     int status = tTrigMap_->get((*sl)->id(), tTrigMean, tTrigSigma, kFactor, DTTimeUnits::ns);
0073 
0074     //Compute new ttrig
0075     try {
0076       dtCalibration::DTTTrigData tTrigCorr = correctionAlgo_->correction((*sl)->id());
0077       float tTrigMeanNew = tTrigCorr.mean;
0078       float tTrigSigmaNew = tTrigCorr.sigma;
0079       float kFactorNew = tTrigCorr.kFactor;
0080       tTrigNewMap.set((*sl)->id(), tTrigMeanNew, tTrigSigmaNew, kFactorNew, DTTimeUnits::ns);
0081 
0082       LogVerbatim("Calibration") << "New tTrig for: " << (*sl)->id() << " mean from " << tTrigMean << " to "
0083                                  << tTrigMeanNew << " sigma from " << tTrigSigma << " to " << tTrigSigmaNew
0084                                  << " kFactor from " << kFactor << " to " << kFactorNew << endl;
0085     } catch (cms::Exception& e) {
0086       LogError("Calibration") << e.explainSelf();
0087       // Set db to the old value, if it was there in the first place
0088       if (!status) {
0089         tTrigNewMap.set((*sl)->id(), tTrigMean, tTrigSigma, kFactor, DTTimeUnits::ns);
0090         LogVerbatim("Calibration") << "Keep old tTrig for: " << (*sl)->id() << " mean " << tTrigMean << " sigma "
0091                                    << tTrigSigma << " kFactor " << kFactor << endl;
0092       }
0093       continue;
0094     }
0095   }  //End of loop on superlayers
0096 
0097   //Write object to DB
0098   LogVerbatim("Calibration") << "[DTTTrigCorrection]: Writing ttrig object to DB!" << endl;
0099   string record = "DTTtrigRcd";
0100   DTCalibDBUtils::writeToDB<DTTtrig>(record, tTrigNewMap);
0101 }