CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTTTrigCorrection.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * \author S. Maselli - INFN Torino
6  * A. Vilela Pereira
7  */
8 
9 #include "DTTTrigCorrection.h"
10 
15 
19 
22 
24 
27 
28 #include <iostream>
29 #include <fstream>
30 
31 using namespace edm;
32 using namespace std;
33 
35  dbLabel_( pset.getUntrackedParameter<string>("dbLabel", "") ) {
36 
37  LogVerbatim("Calibration") << "[DTTTrigCorrection] Constructor called" << endl;
38 
39  // Get the concrete algo from the factory
40  string theAlgoName = pset.getParameter<string>("correctionAlgo");
41  correctionAlgo_ = DTTTrigCorrectionFactory::get()->create(theAlgoName,pset.getParameter<ParameterSet>("correctionAlgoConfig"));
42 }
43 
45  LogVerbatim("Calibration") << "[DTTTrigCorrection] Destructor called" << endl;
46  delete correctionAlgo_;
47 }
48 
50  // Get tTrig record from DB
51  ESHandle<DTTtrig> tTrig;
52  setup.get<DTTtrigRcd>().get(dbLabel_,tTrig);
53  tTrigMap_ = &*tTrig;
54  LogVerbatim("Calibration") << "[DTTTrigCorrection]: TTrig version: " << tTrig->version() << endl;
55 
56  // Get geometry from Event Setup
57  setup.get<MuonGeometryRecord>().get(muonGeom_);
58 
59  // Pass EventSetup to correction Algo
60  correctionAlgo_->setES(setup);
61 }
62 
64  // Create the object to be written to DB
65  DTTtrig* tTrigNewMap = new DTTtrig();
66 
67  for(auto sl = muonGeom_->superLayers().begin();
68  sl != muonGeom_->superLayers().end(); ++sl) {
69  // Get old value from DB
70  float tTrigMean,tTrigSigma,kFactor;
71  int status = tTrigMap_->get((*sl)->id(),tTrigMean,tTrigSigma,kFactor,DTTimeUnits::ns);
72 
73  //Compute new ttrig
74  try{
75  dtCalibration::DTTTrigData tTrigCorr = correctionAlgo_->correction((*sl)->id());
76  float tTrigMeanNew = tTrigCorr.mean;
77  float tTrigSigmaNew = tTrigCorr.sigma;
78  float kFactorNew = tTrigCorr.kFactor;
79  tTrigNewMap->set((*sl)->id(),tTrigMeanNew,tTrigSigmaNew,kFactorNew,DTTimeUnits::ns);
80 
81  LogVerbatim("Calibration") << "New tTrig for: " << (*sl)->id()
82  << " mean from " << tTrigMean << " to " << tTrigMeanNew
83  << " sigma from " << tTrigSigma << " to " << tTrigSigmaNew
84  << " kFactor from " << kFactor << " to " << kFactorNew << endl;
85  } catch(cms::Exception& e){
86  LogError("Calibration") << e.explainSelf();
87  // Set db to the old value, if it was there in the first place
88  if(!status){
89  tTrigNewMap->set((*sl)->id(),tTrigMean,tTrigSigma,kFactor,DTTimeUnits::ns);
90  LogVerbatim("Calibration") << "Keep old tTrig for: " << (*sl)->id()
91  << " mean " << tTrigMean
92  << " sigma " << tTrigSigma
93  << " kFactor " << kFactor << endl;
94  }
95  continue;
96  }
97  }//End of loop on superlayers
98 
99  //Write object to DB
100  LogVerbatim("Calibration") << "[DTTTrigCorrection]: Writing ttrig object to DB!" << endl;
101  string record = "DTTtrigRcd";
102  DTCalibDBUtils::writeToDB<DTTtrig>(record, tTrigNewMap);
103 }
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
virtual DTTTrigData correction(const DTSuperLayerId &)=0
JetCorrectorParameters::Record record
Definition: classes.h:7
virtual std::string explainSelf() const
Definition: Exception.cc:146
virtual void setES(const edm::EventSetup &setup)=0
virtual void endJob()
virtual void beginRun(const edm::Run &run, const edm::EventSetup &setup)
virtual ~DTTTrigCorrection()
Destructor.
const DTTtrig * tTrigMap_
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_
const T & get() const
Definition: EventSetup.h:56
dtCalibration::DTTTrigBaseCorrection * correctionAlgo_
tuple status
Definition: ntuplemaker.py:245
DTTTrigCorrection(const edm::ParameterSet &pset)
Constructor.
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
T get(const Candidate &c)
Definition: component.h:55
Definition: Run.h:43