Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
/*
 *  See header file for a description of this class.
 *
 *  \author A. Vilela Pereira
 */

#include "DTTTrigMatchRPhi.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "DataFormats/MuonDetId/interface/DTSuperLayerId.h"
#include "CondFormats/DTObjects/interface/DTTtrig.h"
#include "CondFormats/DataRecord/interface/DTTtrigRcd.h"

#include <cmath>

using namespace std;
using namespace edm;

namespace dtCalibration {

  DTTTrigMatchRPhi::DTTTrigMatchRPhi(const ParameterSet& pset, edm::ConsumesCollector cc) {
    ttrigToken_ =
        cc.esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", pset.getUntrackedParameter<string>("dbLabel")));
  }

  DTTTrigMatchRPhi::~DTTTrigMatchRPhi() {}

  void DTTTrigMatchRPhi::setES(const EventSetup& setup) {
    // Get tTrig record from DB
    ESHandle<DTTtrig> tTrig = setup.getHandle(ttrigToken_);
    tTrigMap_ = &*tTrig;
  }

  DTTTrigData DTTTrigMatchRPhi::correction(const DTSuperLayerId& slId) {
    float tTrigMean, tTrigSigma, kFactor;
    int status = tTrigMap_->get(slId, tTrigMean, tTrigSigma, kFactor, DTTimeUnits::ns);
    // RZ superlayers return the current value
    if (slId.superLayer() == 2) {
      if (status != 0)
        throw cms::Exception("[DTTTrigMatchRPhi]") << "Could not find tTrig entry in DB for" << slId << endl;
      return DTTTrigData(tTrigMean, tTrigSigma, kFactor);
    } else {
      DTSuperLayerId partnerSLId(slId.chamberId(), (slId.superLayer() == 1) ? 3 : 1);
      float tTrigMeanNew, tTrigSigmaNew, kFactorNew;
      if (!status) {  // Gets average of both SuperLayer's
        if (!tTrigMap_->get(partnerSLId, tTrigMeanNew, tTrigSigmaNew, kFactorNew, DTTimeUnits::ns)) {
          tTrigMeanNew = (tTrigMean + tTrigMeanNew) / 2.;
          //         tTrigSigmaNew = sqrt(tTrigSigmaNew*tTrigSigmaNew + tTrigSigma*tTrigSigma)/2.;
          tTrigSigmaNew = (tTrigSigmaNew + tTrigSigma) / 2.;

          kFactorNew = kFactor;
          return DTTTrigData(tTrigMeanNew, tTrigSigmaNew, kFactorNew);
        } else
          return DTTTrigData(tTrigMean, tTrigSigma, kFactor);
      } else {  // If there is no entry tries to find partner SL and retrieves its value
        if (!tTrigMap_->get(partnerSLId, tTrigMeanNew, tTrigSigmaNew, kFactorNew, DTTimeUnits::ns))
          return DTTTrigData(tTrigMeanNew, tTrigSigmaNew, kFactorNew);
        else {  // Both RPhi SL's not present in DB
          throw cms::Exception("[DTTTrigMatchRPhi]") << "Could not find tTrig entry in DB for" << slId << "\n"
                                                     << partnerSLId << endl;
        }
      }
    }
  }

}  // namespace dtCalibration