CMS 3D CMS Logo

DTVDriftSegment.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * \author A. Vilela Pereira
6  */
7 
8 #include "DTVDriftSegment.h"
9 
14 
21 
25 #include <string>
26 #include <vector>
27 
28 #include "TH1F.h"
29 #include "TFile.h"
30 
31 using namespace std;
32 using namespace edm;
33 
34 namespace dtCalibration {
35 
36  DTVDriftSegment::DTVDriftSegment(const ParameterSet& pset, edm::ConsumesCollector cc)
37  : nSigmas_(pset.getUntrackedParameter<unsigned int>("nSigmasFitRange", 1)),
38  mTimeMap_(nullptr),
39  vDriftMap_(nullptr) {
40  string rootFileName = pset.getParameter<string>("rootFileName");
41  rootFile_ = new TFile(rootFileName.c_str(), "READ");
42 
43  bool debug = pset.getUntrackedParameter<bool>("debug", false);
45  //if(debug) fitter_->setVerbosity(1);
46 
47  readLegacyVDriftDB = pset.getParameter<bool>("readLegacyVDriftDB");
48  if (readLegacyVDriftDB) {
50  } else {
52  }
53  }
54 
56  rootFile_->Close();
57  delete fitter_;
58  }
59 
61  // Get the map of vdrift from the setup
62  if (readLegacyVDriftDB) {
63  mTimeMap_ = &setup.getData(mTimeMapToken_);
64  } else {
65  vDriftMap_ = &setup.getData(vDriftMapToken_);
66  // Consistency check: no parametrization is implemented for the time being
67  int version = vDriftMap_->version();
68  if (version != 1) {
69  throw cms::Exception("Configuration") << "only version 1 is presently supported for VDriftDB";
70  }
71  }
72  }
73 
75  // Get original value from DB; vdrift is cm/ns , resolution is cm
76  // Note that resolution is irrelevant as it is no longer used anywhere in reconstruction.
77 
78  float vDrift = 0., resolution = 0.;
79  if (readLegacyVDriftDB) { // Legacy format
81  if (status != 0)
82  throw cms::Exception("DTCalibration") << "Could not find vDrift entry in DB for" << slId << endl;
83  } else { // New DB format
84  vDrift = vDriftMap_->get(DTWireId(slId.rawId()));
85  }
86 
87  // For RZ superlayers use original value
88  if (slId.superLayer() == 2) {
89  LogTrace("Calibration") << "[DTVDriftSegment]: RZ superlayer\n"
90  << " Will use original vDrift and resolution.";
91  return DTVDriftData(vDrift, resolution);
92  } else {
93  TH1F* vDriftCorrHisto = getHisto(slId);
94  // If empty histogram
95  if (vDriftCorrHisto->GetEntries() == 0) {
96  LogError("Calibration") << "[DTVDriftSegment]: Histogram " << vDriftCorrHisto->GetName() << " is empty.\n"
97  << " Will use original vDrift and resolution.";
98  return DTVDriftData(vDrift, resolution);
99  }
100 
101  LogTrace("Calibration") << "[DTVDriftSegment]: Fitting histogram " << vDriftCorrHisto->GetName();
102  DTResidualFitResult fitResult = fitter_->fitResiduals(*vDriftCorrHisto, nSigmas_);
103  LogTrace("Calibration") << "[DTVDriftSegment]: \n"
104  << " Fit Mean = " << fitResult.fitMean << " +/- " << fitResult.fitMeanError << "\n"
105  << " Fit Sigma = " << fitResult.fitSigma << " +/- " << fitResult.fitSigmaError;
106 
107  float vDriftCorr = fitResult.fitMean;
108  float vDriftNew = vDrift * (1. - vDriftCorr);
109  float resolutionNew = resolution;
110  return DTVDriftData(vDriftNew, resolutionNew);
111  }
112  }
113 
115  string histoName = getHistoName(slId);
116  TH1F* histo = static_cast<TH1F*>(rootFile_->Get(histoName.c_str()));
117  if (!histo)
118  throw cms::Exception("DTCalibration") << "v-drift correction histogram not found:" << histoName << endl;
119  return histo;
120  }
121 
123  DTChamberId chId = slId.chamberId();
124 
125  // Compose the chamber name
129 
130  string chHistoName = "_W" + wheel + "_St" + station + "_Sec" + sector;
131 
132  return (slId.superLayer() != 2) ? ("hRPhiVDriftCorr" + chHistoName) : ("hRZVDriftCorr" + chHistoName);
133  }
134 
135 } // namespace dtCalibration
int station() const
Return the station number.
Definition: DTChamberId.h:45
float get(const DTWireId &wireid, double *x=nullptr) const
Get the value correspoding to the given WireId, / using x[] as parameters of the parametrization when...
int superLayer() const
Return the superlayer number.
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
int version() const
Version numer specifying the structure of the payload. See .cc file for details.
int get(int wheelId, int stationId, int sectorId, int slId, float &mTime, float &mTrms, DTTimeUnits::type unit) const
Definition: DTMtime.cc:56
Log< level::Error, false > LogError
static std::string to_string(const XMLCh *ch)
#define LogTrace(id)
std::string getHistoName(const DTSuperLayerId &)
DTChamberId chamberId() const
Return the corresponding ChamberId.
edm::ESGetToken< DTMtime, DTMtimeRcd > mTimeMapToken_
void setES(const edm::EventSetup &setup) override
edm::ESGetToken< DTRecoConditions, DTRecoConditionsVdriftRcd > vDriftMapToken_
const DTRecoConditions * vDriftMap_
DTResidualFitResult fitResiduals(TH1F &histo, int nSigmas=1)
#define debug
Definition: HDRShower.cc:19
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:42
HLT enums.
int sector() const
Definition: DTChamberId.h:52
TH1F * getHisto(const DTSuperLayerId &)
DTVDriftData compute(const DTSuperLayerId &) override