CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
27 
28 // Root
29 #include "TF1.h"
30 #include "TProfile.h"
31 
32 //C++ headers
33 #include <iostream>
34 #include <sstream>
35 
36 using namespace edm;
37 using namespace std;
38 
40  : wPhaseMapToken_(esConsumes<edm::Transition::BeginRun>()) {
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")) {
94  }
95 
96  bookingdone = true;
97 }
98 
100  // Loop over Trig & Hw sources
101  for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr) {
102  trigSource = (*iTr);
103  for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw) {
104  hwSource = (*iHw);
105  std::vector<const DTChamber*>::const_iterator chambIt = muonGeom->chambers().begin();
106  std::vector<const DTChamber*>::const_iterator chambEnd = muonGeom->chambers().end();
107  for (; chambIt != chambEnd; ++chambIt) {
108  DTChamberId chId = (*chambIt)->id();
109  uint32_t indexCh = chId.rawId();
110 
111  // Perform peak finding
112 
113  TH1F* numH = getHisto<TH1F>(igetter.get(getMEName(numHistoTag, "", chId)));
114  TH1F* denH = getHisto<TH1F>(igetter.get(getMEName(denHistoTag, "", chId)));
115 
116  if (numH && denH && numH->GetEntries() > minEntries && denH->GetEntries() > minEntries) {
117  std::map<std::string, MonitorElement*> innerME = chambME[indexCh];
118  MonitorElement* ratioH = innerME.find(fullName(ratioHistoTag))->second;
119  makeRatioME(numH, denH, ratioH);
120  try {
121  //Need our own copy to avoid threading problems
122  TF1 mypol8("mypol8", "pol8");
123  getHisto<TH1F>(ratioH)->Fit(&mypol8, "CQO");
124  } catch (cms::Exception& iException) {
125  edm::LogPrint(category()) << "[" << testName << "Test]: Error fitting " << ratioH->getName()
126  << " returned 0" << endl;
127  }
128  } else {
129  if (!numH || !denH) {
130  LogPrint(category()) << "[" << testName
131  << "Test]: At least one of the required Histograms was not found for chamber " << chId
132  << ". Peaks not computed" << endl;
133  } else {
134  LogPrint(category()) << "[" << testName << "Test]: Number of plots entries for " << chId
135  << " is less than minEntries=" << minEntries << ". Peaks not computed" << endl;
136  }
137  }
138  }
139  }
140  }
141 }
142 
144  DTLocalTriggerBaseTest::dqmEndJob(ibooker, igetter);
145 
146  if (parameters.getParameter<bool>("writeDB")) {
147  LogVerbatim(category()) << "[" << testName << "Test]: writeDB flag set to true. Producing peak position database."
148  << endl;
149 
150  DTTPGParameters* delayMap = new DTTPGParameters();
151  hwSource = "TM";
152  std::vector<const DTChamber*>::const_iterator chambIt = muonGeom->chambers().begin();
153  std::vector<const DTChamber*>::const_iterator chambEnd = muonGeom->chambers().end();
154  for (; chambIt != chambEnd; ++chambIt) {
155  DTChamberId chId = (*chambIt)->id();
156  float fineDelay = 0;
157  int coarseDelay = static_cast<int>(
158  (getFloatFromME(igetter, chId, "tTrig_SL1") + getFloatFromME(igetter, chId, "tTrig_SL3")) * 0.5 / bxTime);
159 
160  bool fineDiff = parameters.getParameter<bool>("fineParamDiff");
161  bool coarseDiff = parameters.getParameter<bool>("coarseParamDiff");
162 
163  TH1F* ratioH = getHisto<TH1F>(igetter.get(getMEName(ratioHistoTag, "", chId)));
164  if (ratioH->GetEntries() > minEntries) {
165  TF1* fitF = ratioH->GetFunction("mypol8");
166  if (fitF) {
167  fineDelay = fitF->GetMaximumX(0, bxTime);
168  }
169  } else {
170  LogInfo(category()) << "[" << testName << "Test]: Ratio histogram for chamber " << chId
171  << " is empty. Worst Phase value set to 0." << endl;
172  }
173 
174  if (fineDiff || coarseDiff) {
175  float wFine;
176  int wCoarse;
177  wPhaseMap->get(chId, wCoarse, wFine, DTTimeUnits::ns);
178  if (fineDiff) {
179  fineDelay = wFine - fineDelay;
180  }
181  if (coarseDiff) {
182  coarseDelay = wCoarse - coarseDelay;
183  }
184  }
185  delayMap->set(chId, coarseDelay, fineDelay, DTTimeUnits::ns);
186  }
187 
188  std::vector<std::pair<DTTPGParametersId, DTTPGParametersData> >::const_iterator dbIt = delayMap->begin();
189  std::vector<std::pair<DTTPGParametersId, DTTPGParametersData> >::const_iterator dbEnd = delayMap->end();
190  for (; dbIt != dbEnd; ++dbIt) {
191  LogVerbatim(category()) << "[" << testName << "Test]: DB entry for Wh " << (*dbIt).first.wheelId << " Sec "
192  << (*dbIt).first.sectorId << " St " << (*dbIt).first.stationId << " has coarse "
193  << (*dbIt).second.nClock << " and phase " << (*dbIt).second.tPhase << std::endl;
194  }
195 
196  string delayRecord = "DTTPGParametersRcd";
197  DTCalibDBUtils::writeToDB(delayRecord, delayMap);
198  }
199 }
200 
202  TH1F* efficiency = result->getTH1F();
203  efficiency->Divide(numerator, denominator, 1, 1, "");
204 }
205 
207  stringstream wheel;
208  wheel << chId.wheel();
209  stringstream station;
210  station << chId.station();
211  stringstream sector;
212  sector << chId.sector();
213 
214  string folderName = topFolder() + "Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str() + "/";
215 
216  string histoname =
217  sourceFolder + folderName + meType + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
218 
219  MonitorElement* me = igetter.get(histoname);
220  if (me) {
221  return me->getFloatValue();
222  } else {
223  LogProblem(category()) << "[" << testName << "Test]: " << histoname << " is not a valid ME. 0 returned"
224  << std::endl;
225  }
226 
227  return 0;
228 }
229 
231  DTChamberId chambId,
232  string htype,
233  string subfolder) {
234  stringstream wheel;
235  wheel << chambId.wheel();
236  stringstream station;
237  station << chambId.station();
238  stringstream sector;
239  sector << chambId.sector();
240 
241  string fullType = fullName(htype);
242  string HistoName = fullType + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
243 
244  string folder = topFolder() + "Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str();
245  if (!subfolder.empty()) {
246  folder += "7" + subfolder;
247  }
248 
249  ibooker.setCurrentFolder(folder);
250 
251  LogPrint(category()) << "[" << testName << "Test]: booking " << folder << "/" << HistoName;
252 
253  uint32_t indexChId = chambId.rawId();
254  float min = rangeInBX ? 0 : nBXLow * bxTime;
255  float max = rangeInBX ? bxTime : nBXHigh * bxTime;
256  int nbins = static_cast<int>(ceil(rangeInBX ? bxTime : (nBXHigh - nBXLow) * bxTime));
257 
258  chambME[indexChId][fullType] =
259  ibooker.book1D(HistoName.c_str(), "All/HH ratio vs Muon Arrival Time", nbins, min, max);
260 }
edm::ESGetToken< DTTPGParameters, DTTPGParametersRcd > wPhaseMapToken_
Log< level::Info, true > LogVerbatim
constexpr int32_t ceil(float num)
T getUntrackedParameter(std::string const &, T const &) const
std::vector< std::string > trigSources
const std::vector< const DTChamber * > & chambers() const
Return a vector of all Chamber.
Definition: DTGeometry.cc:84
const edm::EventSetup & c
std::string & topFolder()
Get top folder name.
list numerator
Definition: cuy.py:484
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
const_iterator begin() const
int set(int wheelId, int stationId, int sectorId, int nc, float ph, DTTimeUnits::type unit)
const DTTPGParameters * wPhaseMap
virtual TH1F * getTH1F() const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const std::string & getName() const
get name of ME
tuple result
Definition: mps_fire.py:311
void runClientDiagnostic(DQMStore::IBooker &, DQMStore::IGetter &) override
DQM Client Diagnostic.
bool getData(T &iHolder) const
Definition: EventSetup.h:128
list denominator
Definition: cuy.py:485
Definition: Fit.h:32
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:673
Transition
Definition: Transition.h:12
T min(T a, T b)
Definition: MathUtil.h:58
Log< level::Warning, true > LogPrint
const_iterator end() const
float getFloatFromME(DQMStore::IGetter &, DTChamberId chId, std::string meType)
Get float MEs.
std::string category()
Get message logger name.
void beginRun(edm::Run const &run, edm::EventSetup const &context) override
BeginRun.
Log< level::Info, false > LogInfo
DTLocalTriggerSynchTest(const edm::ParameterSet &ps)
Constructor.
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void beginRun(const edm::Run &run, const edm::EventSetup &c) override
begin Run
std::string HistoName
void makeRatioME(TH1F *numerator, TH1F *denominator, MonitorElement *result)
Compute efficiency plots.
std::string getMEName(std::string histoTag, std::string subfolder, const DTChamberId &chambid)
Get the ME name (by chamber)
std::map< uint32_t, std::map< std::string, MonitorElement * > > chambME
void bookChambHistos(DQMStore::IBooker &, DTChamberId chambId, std::string htype, std::string subfolder="")
Book the new MEs (for each chamber)
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
virtual double getFloatValue() const
int sector() const
Definition: DTChamberId.h:49
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &) override
Perform client diagnostic in online.
void setConfig(const edm::ParameterSet &ps, std::string name)
Set configuration variables.
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
int station() const
Return the station number.
Definition: DTChamberId.h:42
std::vector< std::string > hwSources
int get(int wheelId, int stationId, int sectorId, int &nc, float &ph, DTTimeUnits::type unit) const
get content
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
static void writeToDB(std::string record, T *payload)
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::string fullName(std::string htype)
Create fullname from histo partial name.
~DTLocalTriggerSynchTest() override
Destructor.
Definition: Run.h:45
Log< level::Error, true > LogProblem