CMS 3D CMS Logo

DTTTrigCorrection.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * $Date: 2012/03/02 19:47:32 $
5  * $Revision: 1.11 $
6  * \author S. Maselli - INFN Torino
7  * A. Vilela Pereira
8  */
9 
10 #include "DTTTrigCorrection.h"
11 
16 
20 
23 
25 
28 
29 #include <iostream>
30 #include <fstream>
31 
32 using namespace edm;
33 using namespace std;
34 
36  dbLabel_( pset.getUntrackedParameter<string>("dbLabel", "") ),
37  correctionAlgo_{DTTTrigCorrectionFactory::get()->create(pset.getParameter<string>("correctionAlgo"),
38  pset.getParameter<ParameterSet>("correctionAlgoConfig"))}
39 {
40  LogVerbatim("Calibration") << "[DTTTrigCorrection] Constructor called" << endl;
41 }
42 
44  LogVerbatim("Calibration") << "[DTTTrigCorrection] Destructor called" << endl;
45 }
46 
48  // Get tTrig record from DB
49  ESHandle<DTTtrig> tTrig;
50  setup.get<DTTtrigRcd>().get(dbLabel_,tTrig);
51  tTrigMap_ = &*tTrig;
52  LogVerbatim("Calibration") << "[DTTTrigCorrection]: TTrig version: " << tTrig->version() << endl;
53 
54  // Get geometry from Event Setup
55  setup.get<MuonGeometryRecord>().get(muonGeom_);
56 
57  // Pass EventSetup to correction Algo
58  correctionAlgo_->setES(setup);
59 }
60 
62  // Create the object to be written to DB
63  DTTtrig* tTrigNewMap = new DTTtrig();
64 
65  for(vector<const DTSuperLayer*>::const_iterator sl = muonGeom_->superLayers().begin();
66  sl != muonGeom_->superLayers().end(); ++sl) {
67  // Get old value from DB
68  float tTrigMean,tTrigSigma,kFactor;
69  int status = tTrigMap_->get((*sl)->id(),tTrigMean,tTrigSigma,kFactor,DTTimeUnits::ns);
70 
71  //Compute new ttrig
72  try{
73  dtCalibration::DTTTrigData tTrigCorr = correctionAlgo_->correction((*sl)->id());
74  float tTrigMeanNew = tTrigCorr.mean;
75  float tTrigSigmaNew = tTrigCorr.sigma;
76  float kFactorNew = tTrigCorr.kFactor;
77  tTrigNewMap->set((*sl)->id(),tTrigMeanNew,tTrigSigmaNew,kFactorNew,DTTimeUnits::ns);
78 
79  LogVerbatim("Calibration") << "New tTrig for: " << (*sl)->id()
80  << " mean from " << tTrigMean << " to " << tTrigMeanNew
81  << " sigma from " << tTrigSigma << " to " << tTrigSigmaNew
82  << " kFactor from " << kFactor << " to " << kFactorNew << endl;
83  } catch(cms::Exception& e){
84  LogError("Calibration") << e.explainSelf();
85  // Set db to the old value, if it was there in the first place
86  if(!status){
87  tTrigNewMap->set((*sl)->id(),tTrigMean,tTrigSigma,kFactor,DTTimeUnits::ns);
88  LogVerbatim("Calibration") << "Keep old tTrig for: " << (*sl)->id()
89  << " mean " << tTrigMean
90  << " sigma " << tTrigSigma
91  << " kFactor " << kFactor << endl;
92  }
93  continue;
94  }
95  }//End of loop on superlayers
96 
97  //Write object to DB
98  LogVerbatim("Calibration") << "[DTTTrigCorrection]: Writing ttrig object to DB!" << endl;
99  string record = "DTTtrigRcd";
100  DTCalibDBUtils::writeToDB<DTTtrig>(record, tTrigNewMap);
101 }
T getParameter(std::string const &) const
int set(int wheelId, int stationId, int sectorId, int slId, float tTrig, float tTrms, float kFact, DTTimeUnits::type unit)
Definition: DTTtrig.cc:248
JetCorrectorParameters::Record record
Definition: classes.h:7
virtual std::string explainSelf() const
Definition: Exception.cc:108
void endJob() override
const std::string & version() const
access version
Definition: DTTtrig.cc:231
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
~DTTTrigCorrection() override
Destructor.
const DTTtrig * tTrigMap_
std::unique_ptr< dtCalibration::DTTTrigBaseCorrection > correctionAlgo_
int get(int wheelId, int stationId, int sectorId, int slId, float &tTrig, float &tTrms, float &kFact, DTTimeUnits::type unit) const
get content
Definition: DTTtrig.cc:85
edm::ESHandle< DTGeometry > muonGeom_
HLT enums.
T get() const
Definition: EventSetup.h:71
void beginRun(const edm::Run &run, const edm::EventSetup &setup) override
DTTTrigCorrection(const edm::ParameterSet &pset)
Constructor.
T get(const Candidate &c)
Definition: component.h:55
Definition: Run.h:45
const std::vector< const DTSuperLayer * > & superLayers() const
Return a vector of all SuperLayer.
Definition: DTGeometry.cc:107