CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
7 
8 // This class header
10 
11 // Framework headers
16 
17 // Geometry
21 
22 // DB & Calib
27 
28 
29 // Root
30 #include "TF1.h"
31 #include "TProfile.h"
32 
33 
34 //C++ headers
35 #include <iostream>
36 #include <sstream>
37 
38 using namespace edm;
39 using namespace std;
40 
41 
43 
44  setConfig(ps,"DTLocalTriggerSynch");
45  baseFolderDCC = "DT/90-LocalTriggerSynch/";
46  baseFolderDDU = "DT/90-LocalTriggerSynch/";
47 
48 }
49 
50 
52 
53 }
54 
55 
57 
58  numHistoTag = parameters.getParameter<string>("numHistoTag");
59  denHistoTag = parameters.getParameter<string>("denHistoTag");
60  ratioHistoTag = parameters.getParameter<string>("ratioHistoTag");
61  bxTime = parameters.getParameter<double>("bxTimeInterval");
62  rangeInBX = parameters.getParameter<bool>("rangeWithinBX");
63  nBXLow = parameters.getParameter<int>("nBXLow");
64  nBXHigh = parameters.getParameter<int>("nBXHigh");
65  minEntries = parameters.getParameter<int>("minEntries");
66 
67 }
68 
70 
72 
73  vector<string>::const_iterator iTr = trigSources.begin();
74  vector<string>::const_iterator trEnd = trigSources.end();
75  vector<string>::const_iterator iHw = hwSources.begin();
76  vector<string>::const_iterator hwEnd = hwSources.end();
77 
78  //Booking
79  if(parameters.getUntrackedParameter<bool>("staticBooking", true)){
80  for (; iTr != trEnd; ++iTr){
81  trigSource = (*iTr);
82  for (; iHw != hwEnd; ++iHw){
83  hwSource = (*iHw);
84  std::vector<const DTChamber*>::const_iterator chambIt = muonGeom->chambers().begin();
85  std::vector<const DTChamber*>::const_iterator chambEnd = muonGeom->chambers().end();
86  for (; chambIt!=chambEnd; ++chambIt) {
87  DTChamberId chId = ((*chambIt)->id());
88  bookChambHistos(chId,ratioHistoTag);
89  }
90  }
91  }
92  }
93 
94  LogVerbatim(category()) << "[" << testName << "Test]: beginRun" << endl;
95 
96  if (parameters.getParameter<bool>("fineParamDiff")) {
97  ESHandle<DTTPGParameters> wPhaseHandle;
98  c.get<DTTPGParametersRcd>().get(wPhaseHandle);
99  wPhaseMap = (*wPhaseHandle);
100  }
101 
102 }
103 
104 
105 
107 
108  // Loop over Trig & Hw sources
109  for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
110  trigSource = (*iTr);
111  for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
112  hwSource = (*iHw);
113  std::vector<const DTChamber*>::const_iterator chambIt = muonGeom->chambers().begin();
114  std::vector<const DTChamber*>::const_iterator chambEnd = muonGeom->chambers().end();
115  for (; chambIt!=chambEnd; ++chambIt) {
116  DTChamberId chId = (*chambIt)->id();
117  uint32_t indexCh = chId.rawId();
118 
119  // Perform peak finding
120  TH1F *numH = getHisto<TH1F>(dbe->get(getMEName(numHistoTag,"", chId)));
121  TH1F *denH = getHisto<TH1F>(dbe->get(getMEName(denHistoTag,"", chId)));
122 
123  if (numH && denH && numH->GetEntries()>minEntries && denH->GetEntries()>minEntries) {
124  std::map<std::string,MonitorElement*> innerME = chambME[indexCh];
125  MonitorElement* ratioH = innerME.find(fullName(ratioHistoTag))->second;
126  makeRatioME(numH,denH,ratioH);
127  try {
128  //Need our own copy to avoid threading problems
129  TF1 mypol8("mypol8","pol8");
130  getHisto<TH1F>(ratioH)->Fit(&mypol8,"CQO");
131  } catch (cms::Exception& iException) {
132  edm::LogPrint(category()) << "[" << testName
133  << "Test]: Error fitting "
134  << ratioH->getName() << " returned 0" << endl;
135  }
136  } else {
137  if (!numH || !denH) {
138  LogPrint(category()) << "[" << testName
139  << "Test]: At least one of the required Histograms was not found for chamber "
140  << chId << ". Peaks not computed" << endl;
141  } else {
142  LogPrint(category()) << "[" << testName
143  << "Test]: Number of plots entries for "
144  << chId << " is less than minEntries="
145  << minEntries <<". Peaks not computed" << endl;
146  }
147  }
148 
149  }
150  }
151  }
152 
153 }
154 
156 
158 
159  if ( parameters.getParameter<bool>("writeDB")) {
160  LogVerbatim(category()) << "[" << testName
161  << "Test]: writeDB flag set to true. Producing peak position database." << endl;
162 
163  DTTPGParameters* delayMap = new DTTPGParameters();
164  hwSource = parameters.getParameter<bool>("dbFromDCC") ? "DCC" : "DDU";
165  std::vector<const DTChamber*>::const_iterator chambIt = muonGeom->chambers().begin();
166  std::vector<const DTChamber*>::const_iterator chambEnd = muonGeom->chambers().end();
167  for (; chambIt!=chambEnd; ++chambIt) {
168 
169  DTChamberId chId = (*chambIt)->id();
170  float fineDelay = 0;
171  int coarseDelay = static_cast<int>((getFloatFromME(chId,"tTrig_SL1") + getFloatFromME(chId,"tTrig_SL3"))*0.5/bxTime);
172 
173  bool fineDiff = parameters.getParameter<bool>("fineParamDiff");
174  bool coarseDiff = parameters.getParameter<bool>("coarseParamDiff");
175 
176 
177  TH1F *ratioH = getHisto<TH1F>(dbe->get(getMEName(ratioHistoTag,"", chId)));
178  if (ratioH->GetEntries()>minEntries) {
179  TF1 *fitF=ratioH->GetFunction("mypol8");
180  if (fitF) { fineDelay=fitF->GetMaximumX(0,bxTime); }
181  } else {
182  LogInfo(category()) << "[" << testName
183  << "Test]: Ratio histogram for chamber " << chId
184  << " is empty. Worst Phase value set to 0." << endl;
185  }
186 
187  if (fineDiff || coarseDiff) {
188  float wFine;
189  int wCoarse;
190  wPhaseMap.get(chId,wCoarse,wFine,DTTimeUnits::ns);
191  if (fineDiff) { fineDelay = wFine - fineDelay; }
192  if (coarseDiff) { coarseDelay = wCoarse - coarseDelay; }
193  }
194  delayMap->set(chId,coarseDelay,fineDelay,DTTimeUnits::ns);
195  }
196 
197  std::vector< std::pair<DTTPGParametersId,DTTPGParametersData> >::const_iterator dbIt = delayMap->begin();
198  std::vector< std::pair<DTTPGParametersId,DTTPGParametersData> >::const_iterator dbEnd = delayMap->end();
199  for (; dbIt!=dbEnd; ++dbIt) {
200  LogVerbatim(category()) << "[" << testName << "Test]: DB entry for Wh " << (*dbIt).first.wheelId
201  << " Sec " << (*dbIt).first.sectorId
202  << " St " << (*dbIt).first.stationId
203  << " has coarse " << (*dbIt).second.nClock
204  << " and phase " << (*dbIt).second.tPhase << std::endl;
205  }
206 
207  string delayRecord = "DTTPGParametersRcd";
208  DTCalibDBUtils::writeToDB(delayRecord,delayMap);
209 
210  }
211 
212 }
213 
214 
215 
217 
218  TH1F* efficiency = result->getTH1F();
219  efficiency->Divide(numerator,denominator,1,1,"");
220 
221 }
222 
224 
225  stringstream wheel; wheel << chId.wheel();
226  stringstream station; station << chId.station();
227  stringstream sector; sector << chId.sector();
228 
229  string folderName = topFolder(hwSource=="DCC") + "Wheel" + wheel.str() +
230  "/Sector" + sector.str() + "/Station" + station.str() + "/" ;
231 
232  string histoname = sourceFolder + folderName
233  + meType
234  + "_W" + wheel.str()
235  + "_Sec" + sector.str()
236  + "_St" + station.str();
237 
238  MonitorElement* me = dbe->get(histoname);
239  if (me) {
240  return me->getFloatValue();
241  }
242  else {
243  LogProblem(category()) << "[" << testName << "Test]: " << histoname << " is not a valid ME. 0 returned" << std::endl;
244  }
245 
246  return 0;
247 
248  }
249 
250 void DTLocalTriggerSynchTest::bookChambHistos(DTChamberId chambId, string htype, string subfolder) {
251 
252  stringstream wheel; wheel << chambId.wheel();
253  stringstream station; station << chambId.station();
254  stringstream sector; sector << chambId.sector();
255 
256  string fullType = fullName(htype);
257  bool isDCC = hwSource=="DCC" ;
258  string HistoName = fullType + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
259 
260  string folder = topFolder(isDCC) + "Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str();
261  if ( subfolder!="") { folder += "7" + subfolder; }
262 
263  dbe->setCurrentFolder(folder);
264 
265  LogPrint(category()) << "[" << testName << "Test]: booking " << folder << "/" <<HistoName;
266 
267 
268  uint32_t indexChId = chambId.rawId();
269  float min = rangeInBX ? 0 : nBXLow*bxTime;
270  float max = rangeInBX ? bxTime : nBXHigh*bxTime;
271  int nbins = static_cast<int>(ceil( rangeInBX ? bxTime : (nBXHigh-nBXLow)*bxTime));
272 
273  chambME[indexChId][fullType] = dbe->book1D(HistoName.c_str(),"All/HH ratio vs Muon Arrival Time",nbins,min,max);
274 
275 }
const std::string & getName(void) const
get name of ME
dictionary parameters
Definition: Parameters.py:2
list numerator
Definition: cuy.py:483
const_iterator begin() const
int set(int wheelId, int stationId, int sectorId, int nc, float ph, DTTimeUnits::type unit)
void beginRun(edm::Run const &run, edm::EventSetup const &context)
BeginRun.
void beginRun(const edm::Run &run, const edm::EventSetup &c)
begin Run
float getFloatFromME(DTChamberId chId, std::string meType)
Get float MEs.
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
virtual ~DTLocalTriggerSynchTest()
Destructor.
list denominator
Definition: cuy.py:484
Definition: Fit.h:34
tuple result
Definition: query.py:137
double getFloatValue(void) const
EventID const & min(EventID const &lh, EventID const &rh)
Definition: EventID.h:137
const_iterator end() const
void runClientDiagnostic()
DQM Client Diagnostic.
DTLocalTriggerSynchTest(const edm::ParameterSet &ps)
Constructor.
string fullName
const T & get() const
Definition: EventSetup.h:55
TH1F * getTH1F(void) const
std::string HistoName
void makeRatioME(TH1F *numerator, TH1F *denominator, MonitorElement *result)
Compute efficiency plots.
int sector() const
Definition: DTChamberId.h:61
int station() const
Return the station number.
Definition: DTChamberId.h:51
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
void bookChambHistos(DTChamberId chambId, std::string htype, std::string subfolder="")
Book the new MEs (for each chamber)
static void writeToDB(std::string record, T *payload)
Definition: Run.h:41
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:142