CMS 3D CMS Logo

DTLocalTriggerSynchTest.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author C. Battilana - CIEMAT
5  *
6  * threadsafe version (//-) oct/nov 2014 - WATWanAbdullah -ncpp-um-my
7  *
8  */
9 
10 // This class header
12 
13 // Framework headers
17 
18 // Geometry
22 
23 // DB & Calib
28 
29 // Root
30 #include "TF1.h"
31 #include "TProfile.h"
32 
33 //C++ headers
34 #include <iostream>
35 #include <sstream>
36 
37 using namespace edm;
38 using namespace std;
39 
41  setConfig(ps, "DTLocalTriggerSynch");
42  baseFolderTM = "DT/90-LocalTriggerSynch/";
43 
44  bookingdone = false;
45 }
46 
48 
50  numHistoTag = parameters.getParameter<string>("numHistoTag");
51  denHistoTag = parameters.getParameter<string>("denHistoTag");
52  ratioHistoTag = parameters.getParameter<string>("ratioHistoTag");
53  bxTime = parameters.getParameter<double>("bxTimeInterval");
54  rangeInBX = parameters.getParameter<bool>("rangeWithinBX");
55  nBXLow = parameters.getParameter<int>("nBXLow");
56  nBXHigh = parameters.getParameter<int>("nBXHigh");
57  minEntries = parameters.getParameter<int>("minEntries");
58 
60 }
61 
63  DQMStore::IGetter& igetter,
64  edm::LuminosityBlock const& lumiSeg,
65  edm::EventSetup const& c) {
66  if (bookingdone)
67  return;
68 
69  vector<string>::const_iterator iTr = trigSources.begin();
70  vector<string>::const_iterator trEnd = trigSources.end();
71  vector<string>::const_iterator iHw = hwSources.begin();
72  vector<string>::const_iterator hwEnd = hwSources.end();
73 
74  //Booking
75  if (parameters.getUntrackedParameter<bool>("staticBooking", true)) {
76  for (; iTr != trEnd; ++iTr) {
77  trigSource = (*iTr);
78  for (; iHw != hwEnd; ++iHw) {
79  hwSource = (*iHw);
80  std::vector<const DTChamber*>::const_iterator chambIt = muonGeom->chambers().begin();
81  std::vector<const DTChamber*>::const_iterator chambEnd = muonGeom->chambers().end();
82  for (; chambIt != chambEnd; ++chambIt) {
83  DTChamberId chId = ((*chambIt)->id());
84  bookChambHistos(ibooker, chId, ratioHistoTag);
85  }
86  }
87  }
88  }
89 
90  LogVerbatim(category()) << "[" << testName << "Test]: book Histograms" << endl;
91 
92  if (parameters.getParameter<bool>("fineParamDiff")) {
93  ESHandle<DTTPGParameters> wPhaseHandle;
94  c.get<DTTPGParametersRcd>().get(wPhaseHandle);
95  wPhaseMap = (*wPhaseHandle);
96  }
97 
98  bookingdone = true;
99 }
100 
102  // Loop over Trig & Hw sources
103  for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr) {
104  trigSource = (*iTr);
105  for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw) {
106  hwSource = (*iHw);
107  std::vector<const DTChamber*>::const_iterator chambIt = muonGeom->chambers().begin();
108  std::vector<const DTChamber*>::const_iterator chambEnd = muonGeom->chambers().end();
109  for (; chambIt != chambEnd; ++chambIt) {
110  DTChamberId chId = (*chambIt)->id();
111  uint32_t indexCh = chId.rawId();
112 
113  // Perform peak finding
114 
115  TH1F* numH = getHisto<TH1F>(igetter.get(getMEName(numHistoTag, "", chId)));
116  TH1F* denH = getHisto<TH1F>(igetter.get(getMEName(denHistoTag, "", chId)));
117 
118  if (numH && denH && numH->GetEntries() > minEntries && denH->GetEntries() > minEntries) {
119  std::map<std::string, MonitorElement*> innerME = chambME[indexCh];
120  MonitorElement* ratioH = innerME.find(fullName(ratioHistoTag))->second;
121  makeRatioME(numH, denH, ratioH);
122  try {
123  //Need our own copy to avoid threading problems
124  TF1 mypol8("mypol8", "pol8");
125  getHisto<TH1F>(ratioH)->Fit(&mypol8, "CQO");
126  } catch (cms::Exception& iException) {
127  edm::LogPrint(category()) << "[" << testName << "Test]: Error fitting " << ratioH->getName()
128  << " returned 0" << endl;
129  }
130  } else {
131  if (!numH || !denH) {
132  LogPrint(category()) << "[" << testName
133  << "Test]: At least one of the required Histograms was not found for chamber " << chId
134  << ". Peaks not computed" << endl;
135  } else {
136  LogPrint(category()) << "[" << testName << "Test]: Number of plots entries for " << chId
137  << " is less than minEntries=" << minEntries << ". Peaks not computed" << endl;
138  }
139  }
140  }
141  }
142  }
143 }
144 
146  DTLocalTriggerBaseTest::dqmEndJob(ibooker, igetter);
147 
148  if (parameters.getParameter<bool>("writeDB")) {
149  LogVerbatim(category()) << "[" << testName << "Test]: writeDB flag set to true. Producing peak position database."
150  << endl;
151 
152  DTTPGParameters* delayMap = new DTTPGParameters();
153  hwSource = "TM";
154  std::vector<const DTChamber*>::const_iterator chambIt = muonGeom->chambers().begin();
155  std::vector<const DTChamber*>::const_iterator chambEnd = muonGeom->chambers().end();
156  for (; chambIt != chambEnd; ++chambIt) {
157  DTChamberId chId = (*chambIt)->id();
158  float fineDelay = 0;
159  int coarseDelay = static_cast<int>(
160  (getFloatFromME(igetter, chId, "tTrig_SL1") + getFloatFromME(igetter, chId, "tTrig_SL3")) * 0.5 / bxTime);
161 
162  bool fineDiff = parameters.getParameter<bool>("fineParamDiff");
163  bool coarseDiff = parameters.getParameter<bool>("coarseParamDiff");
164 
165  TH1F* ratioH = getHisto<TH1F>(igetter.get(getMEName(ratioHistoTag, "", chId)));
166  if (ratioH->GetEntries() > minEntries) {
167  TF1* fitF = ratioH->GetFunction("mypol8");
168  if (fitF) {
169  fineDelay = fitF->GetMaximumX(0, bxTime);
170  }
171  } else {
172  LogInfo(category()) << "[" << testName << "Test]: Ratio histogram for chamber " << chId
173  << " is empty. Worst Phase value set to 0." << endl;
174  }
175 
176  if (fineDiff || coarseDiff) {
177  float wFine;
178  int wCoarse;
179  wPhaseMap.get(chId, wCoarse, wFine, DTTimeUnits::ns);
180  if (fineDiff) {
181  fineDelay = wFine - fineDelay;
182  }
183  if (coarseDiff) {
184  coarseDelay = wCoarse - coarseDelay;
185  }
186  }
187  delayMap->set(chId, coarseDelay, fineDelay, DTTimeUnits::ns);
188  }
189 
190  std::vector<std::pair<DTTPGParametersId, DTTPGParametersData> >::const_iterator dbIt = delayMap->begin();
191  std::vector<std::pair<DTTPGParametersId, DTTPGParametersData> >::const_iterator dbEnd = delayMap->end();
192  for (; dbIt != dbEnd; ++dbIt) {
193  LogVerbatim(category()) << "[" << testName << "Test]: DB entry for Wh " << (*dbIt).first.wheelId << " Sec "
194  << (*dbIt).first.sectorId << " St " << (*dbIt).first.stationId << " has coarse "
195  << (*dbIt).second.nClock << " and phase " << (*dbIt).second.tPhase << std::endl;
196  }
197 
198  string delayRecord = "DTTPGParametersRcd";
199  DTCalibDBUtils::writeToDB(delayRecord, delayMap);
200  }
201 }
202 
204  TH1F* efficiency = result->getTH1F();
205  efficiency->Divide(numerator, denominator, 1, 1, "");
206 }
207 
209  stringstream wheel;
210  wheel << chId.wheel();
211  stringstream station;
212  station << chId.station();
213  stringstream sector;
214  sector << chId.sector();
215 
216  string folderName = topFolder() + "Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str() + "/";
217 
218  string histoname =
219  sourceFolder + folderName + meType + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
220 
221  MonitorElement* me = igetter.get(histoname);
222  if (me) {
223  return me->getFloatValue();
224  } else {
225  LogProblem(category()) << "[" << testName << "Test]: " << histoname << " is not a valid ME. 0 returned"
226  << std::endl;
227  }
228 
229  return 0;
230 }
231 
233  DTChamberId chambId,
234  string htype,
235  string subfolder) {
236  stringstream wheel;
237  wheel << chambId.wheel();
238  stringstream station;
239  station << chambId.station();
240  stringstream sector;
241  sector << chambId.sector();
242 
243  string fullType = fullName(htype);
244  string HistoName = fullType + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
245 
246  string folder = topFolder() + "Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str();
247  if (!subfolder.empty()) {
248  folder += "7" + subfolder;
249  }
250 
251  ibooker.setCurrentFolder(folder);
252 
253  LogPrint(category()) << "[" << testName << "Test]: booking " << folder << "/" << HistoName;
254 
255  uint32_t indexChId = chambId.rawId();
256  float min = rangeInBX ? 0 : nBXLow * bxTime;
257  float max = rangeInBX ? bxTime : nBXHigh * bxTime;
258  int nbins = static_cast<int>(ceil(rangeInBX ? bxTime : (nBXHigh - nBXLow) * bxTime));
259 
260  chambME[indexChId][fullType] =
261  ibooker.book1D(HistoName.c_str(), "All/HH ratio vs Muon Arrival Time", nbins, min, max);
262 }
dtLocalTriggerSynchTest_cfi.denHistoTag
denHistoTag
Definition: dtLocalTriggerSynchTest_cfi.py:26
DTTPGParameters::set
int set(int wheelId, int stationId, int sectorId, int nc, float ph, DTTimeUnits::type unit)
Definition: DTTPGParameters.cc:123
taus_updatedMVAIds_cff.category
category
Definition: taus_updatedMVAIds_cff.py:31
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:29
DTTrigGeomUtils.h
DTLocalTriggerBaseTest::dqmEndJob
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
Definition: DTLocalTriggerBaseTest.cc:65
MessageLogger.h
DTLocalTriggerBaseTest::beginRun
void beginRun(edm::Run const &run, edm::EventSetup const &context) override
BeginRun.
Definition: DTLocalTriggerBaseTest.cc:37
dtLocalTriggerSynchTest_cfi.numHistoTag
numHistoTag
Definition: dtLocalTriggerSynchTest_cfi.py:25
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::Run
Definition: Run.h:45
printsummarytable.folder
folder
Definition: printsummarytable.py:7
relativeConstraints.station
station
Definition: relativeConstraints.py:67
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::max
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:118
edm::min
EventID const & min(EventID const &lh, EventID const &rh)
Definition: EventID.h:116
edm::LogPrint
Log< level::Warning, true > LogPrint
Definition: MessageLogger.h:130
dtLocalTriggerSynchTest_cfi.nBXLow
nBXLow
Definition: dtLocalTriggerSynchTest_cfi.py:19
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
DTLocalTriggerSynchTest::runClientDiagnostic
void runClientDiagnostic(DQMStore::IBooker &, DQMStore::IGetter &) override
DQM Client Diagnostic.
Definition: DTLocalTriggerSynchTest.cc:101
dtLocalTriggerSynchTest_cfi.ratioHistoTag
ratioHistoTag
Definition: dtLocalTriggerSynchTest_cfi.py:27
dtFineDelayCorr_cfi.minEntries
minEntries
Definition: dtFineDelayCorr_cfi.py:30
DQMStore.h
DTStatusFlagRcd.h
dqm::legacy::MonitorElement
Definition: MonitorElement.h:461
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
L1TObjectsTimingClient_cff.efficiency
efficiency
Definition: L1TObjectsTimingClient_cff.py:10
dtLocalTriggerSynchTest_cfi.nBXHigh
nBXHigh
Definition: dtLocalTriggerSynchTest_cfi.py:18
tools.TF1
TF1
Definition: tools.py:23
reco::ceil
constexpr int32_t ceil(float num)
Definition: constexpr_cmath.h:7
edm::LogProblem
Log< level::Error, true > LogProblem
Definition: MessageLogger.h:131
DTTimeUnits::ns
Definition: DTTimeUnits.h:32
edm::ESHandle
Definition: DTSurvey.h:22
LaserClient_cfi.nbins
nbins
Definition: LaserClient_cfi.py:51
L1TBPTX_cfi.testName
testName
Definition: L1TBPTX_cfi.py:24
DTLocalTriggerSynchTest::getFloatFromME
float getFloatFromME(DQMStore::IGetter &, DTChamberId chId, std::string meType)
Get float MEs.
Definition: DTLocalTriggerSynchTest.cc:208
DTStatusFlag.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
newFWLiteAna.fullName
fullName
Definition: newFWLiteAna.py:122
DTGeometry.h
DTTPGParametersRcd
Definition: DTTPGParametersRcd.h:5
edm::ParameterSet
Definition: ParameterSet.h:47
DTTPGParameters
Definition: DTTPGParameters.h:62
DTTPGParameters::begin
const_iterator begin() const
Definition: DTTPGParameters.cc:166
edm::get
T const & get(Event const &event, InputTag const &tag) noexcept(false)
Definition: Event.h:671
dtFineDelayCorr_cfi.hwSource
hwSource
Definition: dtFineDelayCorr_cfi.py:26
makeMuonMisalignmentScenario.wheel
wheel
Definition: makeMuonMisalignmentScenario.py:319
DTCalibDBUtils.h
cscdqm::HistoName
std::string HistoName
Definition: CSCDQM_HistoDef.h:32
dtFineDelayCorr_cfi.hwSources
hwSources
Definition: dtFineDelayCorr_cfi.py:9
HLTTauDQMOffline_cfi.numerator
numerator
Definition: HLTTauDQMOffline_cfi.py:179
edm::EventSetup
Definition: EventSetup.h:57
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
DTLocalTriggerSynchTest.h
ALCARECODTCalibSynchCosmicsDQM_cff.folderName
folderName
Definition: ALCARECODTCalibSynchCosmicsDQM_cff.py:9
DTLocalTriggerSynchTest::makeRatioME
void makeRatioME(TH1F *numerator, TH1F *denominator, MonitorElement *result)
Compute efficiency plots.
Definition: DTLocalTriggerSynchTest.cc:203
DTLocalTriggerSynchTest::bookChambHistos
void bookChambHistos(DQMStore::IBooker &, DTChamberId chambId, std::string htype, std::string subfolder="")
Book the new MEs (for each chamber)
Definition: DTLocalTriggerSynchTest.cc:232
DTTPGParametersRcd.h
HLTTauDQMOffline_cfi.denominator
denominator
Definition: HLTTauDQMOffline_cfi.py:180
DTChamberId::sector
int sector() const
Definition: DTChamberId.h:49
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
writedatasetfile.run
run
Definition: writedatasetfile.py:27
DTTPGParameters::end
const_iterator end() const
Definition: DTTPGParameters.cc:168
DTLocalTriggerSynchTest::beginRun
void beginRun(const edm::Run &run, const edm::EventSetup &c) override
begin Run
Definition: DTLocalTriggerSynchTest.cc:49
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
dqm::implementation::IGetter
Definition: DQMStore.h:484
DTLocalTriggerSynchTest::DTLocalTriggerSynchTest
DTLocalTriggerSynchTest(const edm::ParameterSet &ps)
Constructor.
Definition: DTLocalTriggerSynchTest.cc:40
DTLocalTriggerSynchTest::dqmEndLuminosityBlock
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &) override
Perform client diagnostic in online.
Definition: DTLocalTriggerSynchTest.cc:62
L1DTConfigParams_cff.DTTPGParameters
DTTPGParameters
Definition: L1DTConfigParams_cff.py:12
DTLocalTriggerSynchTest::~DTLocalTriggerSynchTest
~DTLocalTriggerSynchTest() override
Destructor.
Definition: DTLocalTriggerSynchTest.cc:47
dqm::impl::MonitorElement::getName
const std::string & getName() const
get name of ME
Definition: MonitorElement.h:250
dqm::implementation::IGetter::get
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:651
EventSetup.h
DTLocalTriggerSynchTest::dqmEndJob
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
Definition: DTLocalTriggerSynchTest.cc:145
dqm::implementation::IBooker
Definition: DQMStore.h:43
mps_fire.result
result
Definition: mps_fire.py:311
cms::Exception
Definition: Exception.h:70
DTChamberId
Definition: DTChamberId.h:14
MuonGeometryRecord.h
hlt_dqm_clientPB-live_cfg.me
me
Definition: hlt_dqm_clientPB-live_cfg.py:61
hgcalDigitizer_cfi.bxTime
bxTime
Definition: hgcalDigitizer_cfi.py:80
DTChamberId::wheel
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
DTCalibDBUtils::writeToDB
static void writeToDB(std::string record, T *payload)
Definition: DTCalibDBUtils.h:28
DTChamberId::station
int station() const
Return the station number.
Definition: DTChamberId.h:42
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98