CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTtTrigDBValidation.cc
Go to the documentation of this file.
2 
3 // Framework
8 
12 
13 // Geometry
17 
18 // DataFormats
20 
21 // tTrig
24 
25 #include <stdio.h>
26 #include <sstream>
27 #include <math.h>
28 #include "TFile.h"
29 
30 using namespace edm;
31 using namespace std;
32 
34  metname_("TTrigDBValidation"),
35  labelDBRef_(pset.getParameter<string>("labelDBRef")),
36  labelDB_(pset.getParameter<string>("labelDB")),
37  lowerLimit_(pset.getUntrackedParameter<int>("lowerLimit",1)),
38  higherLimit_(pset.getUntrackedParameter<int>("higherLimit",3))
39  {
40 
41  LogVerbatim(metname_) << "[DTtTrigDBValidation] Constructor called!";
42 
43  // Get the DQM needed services
45  dbe_->setCurrentFolder("DT/DtCalib/TTrigDBValidation");
46 
47  outputMEsInRootFile_ = false;
48  if( pset.exists("OutputFileName") ){
49  outputMEsInRootFile_ = true;
50  outputFileName_ = pset.getParameter<std::string>("OutputFileName");
51  }
52 }
53 
55 
57 
58  LogVerbatim(metname_) << "[DTtTrigDBValidation] Parameters initialization";
59 
60  ESHandle<DTTtrig> tTrig_Ref;
61  setup.get<DTTtrigRcd>().get(labelDBRef_, tTrig_Ref);
62  const DTTtrig* DTTtrigRefMap = &*tTrig_Ref;
63  LogVerbatim(metname_) << "[DTtTrigDBValidation] reference Ttrig version: " << tTrig_Ref->version();
64 
65  ESHandle<DTTtrig> tTrig;
66  setup.get<DTTtrigRcd>().get(labelDB_, tTrig);
67  const DTTtrig* DTTtrigMap = &*tTrig;
68  LogVerbatim(metname_) << "[DTtTrigDBValidation] Ttrig to validate version: " << tTrig->version();
69 
70  //book&reset the summary histos
71  for(int wheel=-2; wheel<=2; wheel++){
72  bookHistos(wheel);
73  tTrigDiffWheel_[wheel]->Reset();
74  }
75 
76  // Get the geometry
77  setup.get<MuonGeometryRecord>().get(dtGeom_);
78 
79  // Loop over Ref DB entries
80  for(DTTtrig::const_iterator it = DTTtrigRefMap->begin();
81  it != DTTtrigRefMap->end(); ++it) {
82  DTSuperLayerId slId((*it).first.wheelId,
83  (*it).first.stationId,
84  (*it).first.sectorId,
85  (*it).first.slId);
86  float tTrigMean;
87  float tTrigRms;
88  float kFactor;
89  DTTtrigRefMap->get(slId, tTrigMean, tTrigRms, kFactor, DTTimeUnits::ns);
90  float tTrigCorr = tTrigMean + kFactor*tTrigRms;
91  LogTrace(metname_)<< "Ref Superlayer: " << slId << "\n"
92  << " Ttrig mean (ns): " << tTrigMean
93  << " Ttrig rms (ns): " << tTrigRms
94  << " Ttrig k-Factor: " << kFactor
95  << " Ttrig value (ns): " << tTrigCorr;
96 
97  //tTrigRefMap[slId] = std::pair<float,float>(tTrigmean,tTrigrms);
98  tTrigRefMap_[slId] = pair<float,float>(tTrigCorr,tTrigRms);
99  }
100 
101  // Loop over Ref DB entries
102  for(DTTtrig::const_iterator it = DTTtrigMap->begin();
103  it != DTTtrigMap->end(); ++it) {
104  DTSuperLayerId slId((*it).first.wheelId,
105  (*it).first.stationId,
106  (*it).first.sectorId,
107  (*it).first.slId);
108  float tTrigMean;
109  float tTrigRms;
110  float kFactor;
111  DTTtrigMap->get(slId, tTrigMean, tTrigRms, kFactor, DTTimeUnits::ns);
112  float tTrigCorr = tTrigMean + kFactor*tTrigRms;
113  LogTrace(metname_)<< "Superlayer: " << slId << "\n"
114  << " Ttrig mean (ns): " << tTrigMean
115  << " Ttrig rms (ns): " << tTrigRms
116  << " Ttrig k-Factor: " << kFactor
117  << " Ttrig value (ns): " << tTrigCorr;
118 
119  //tTrigMap[slId] = std::pair<float,float>(tTrigmean,tTrigrms);
120  tTrigMap_[slId] = pair<float,float>(tTrigCorr,tTrigRms);
121  }
122 
123  for(map<DTSuperLayerId, pair<float,float> >::const_iterator it = tTrigRefMap_.begin();
124  it != tTrigRefMap_.end(); ++it) {
125  if(tTrigMap_.find((*it).first) == tTrigMap_.end()) continue;
126 
127  // compute the difference
128  float difference = tTrigMap_[(*it).first].first - (*it).second.first;
129 
130  //book histo
131  int wheel = (*it).first.chamberId().wheel();
132  int sector = (*it).first.chamberId().sector();
133  if(tTrigDiffHistos_.find(make_pair(wheel,sector)) == tTrigDiffHistos_.end()) bookHistos(wheel,sector);
134 
135  LogTrace(metname_) << "Filling histos for super-layer: " << (*it).first << " difference: " << difference;
136 
137  // Fill the test histos
138  int entry = -1;
139  int station = (*it).first.chamberId().station();
140  if(station == 1) entry=0;
141  if(station == 2) entry=3;
142  if(station == 3) entry=6;
143  if(station == 4) entry=9;
144 
145  int slBin = entry + (*it).first.superLayer();
146  if(slBin == 12) slBin=11;
147 
148  tTrigDiffHistos_[make_pair(wheel,sector)]->setBinContent(slBin, difference);
149  if(abs(difference) < lowerLimit_){
150  tTrigDiffWheel_[wheel]->setBinContent(slBin,sector,1);
151  }else if(abs(difference) < higherLimit_){
152  tTrigDiffWheel_[wheel]->setBinContent(slBin,sector,2);
153  }else{
154  tTrigDiffWheel_[wheel]->setBinContent(slBin,sector,3);
155  }
156 
157 
158  } // Loop over the tTrig map reference
159 
160 }
161 
163 
165 
167  // write the histos on a file
169  }
170 }
171 
172 void DTtTrigDBValidation::bookHistos(int wheel, int sector) {
173 
174  LogTrace(metname_) << " Booking histos for Wheel, Sector: " << wheel << ", " << sector;
175 
176  // Compose the chamber name
177  stringstream str_wheel; str_wheel << wheel;
178  stringstream str_sector; str_sector << sector;
179 
180  string lHistoName = "_W" + str_wheel.str() + "_Sec" + str_sector.str();
181 
182  dbe_->setCurrentFolder("DT/DtCalib/TTrigDBValidation/Wheel" + str_wheel.str());
183 
184  // Create the monitor elements
185  MonitorElement * hDifference;
186  hDifference = dbe_->book1D("TTrigDifference"+lHistoName, "difference between the two tTrig values",11,0,11);
187 
188  pair<int,int> mypair(wheel,sector);
189  tTrigDiffHistos_[mypair] = hDifference;
190 
191  (tTrigDiffHistos_[mypair])->setBinLabel(1,"MB1_SL1",1);
192  (tTrigDiffHistos_[mypair])->setBinLabel(2,"MB1_SL2",1);
193  (tTrigDiffHistos_[mypair])->setBinLabel(3,"MB1_SL3",1);
194  (tTrigDiffHistos_[mypair])->setBinLabel(4,"MB2_SL1",1);
195  (tTrigDiffHistos_[mypair])->setBinLabel(5,"MB2_SL2",1);
196  (tTrigDiffHistos_[mypair])->setBinLabel(6,"MB2_SL3",1);
197  (tTrigDiffHistos_[mypair])->setBinLabel(7,"MB3_SL1",1);
198  (tTrigDiffHistos_[mypair])->setBinLabel(8,"MB3_SL2",1);
199  (tTrigDiffHistos_[mypair])->setBinLabel(9,"MB3_SL3",1);
200  (tTrigDiffHistos_[mypair])->setBinLabel(10,"MB4_SL1",1);
201  (tTrigDiffHistos_[mypair])->setBinLabel(11,"MB4_SL3",1);
202 
203 }
204 
205 // Book the summary histos
207 
208  stringstream wh; wh << wheel;
209 
210  dbe_->setCurrentFolder("DT/DtCalib/TTrigDBValidation");
211  tTrigDiffWheel_[wheel] = dbe_->book2D("TTrigDifference_W"+wh.str(), "W"+wh.str()+": summary of tTrig differences",11,1,12,14,1,15);
212  tTrigDiffWheel_[wheel]->setBinLabel(1,"MB1_SL1",1);
213  tTrigDiffWheel_[wheel]->setBinLabel(2,"MB1_SL2",1);
214  tTrigDiffWheel_[wheel]->setBinLabel(3,"MB1_SL3",1);
215  tTrigDiffWheel_[wheel]->setBinLabel(4,"MB2_SL1",1);
216  tTrigDiffWheel_[wheel]->setBinLabel(5,"MB2_SL2",1);
217  tTrigDiffWheel_[wheel]->setBinLabel(6,"MB2_SL3",1);
218  tTrigDiffWheel_[wheel]->setBinLabel(7,"MB3_SL1",1);
219  tTrigDiffWheel_[wheel]->setBinLabel(8,"MB3_SL2",1);
220  tTrigDiffWheel_[wheel]->setBinLabel(9,"MB3_SL3",1);
221  tTrigDiffWheel_[wheel]->setBinLabel(10,"MB4_SL1",1);
222  tTrigDiffWheel_[wheel]->setBinLabel(11,"MB4_SL3",1);
223 
224 }
225 
226 
228  return (int) (bin /3.1)+1;
229 }
230 
232  int ret = bin%3;
233  if(ret == 0 || bin == 11) ret = 3;
234 
235  return ret;
236 }
T getParameter(std::string const &) const
bool lowerLimit_
Definition: Combine.cc:70
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
void endRun(edm::Run const &, edm::EventSetup const &)
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2113
bool exists(std::string const &parameterName) const
checks if a parameter exists
#define abs(x)
Definition: mlp_lapack.h:159
std::map< int, MonitorElement * > tTrigDiffWheel_
int slFromBin(int bin) const
std::map< std::pair< int, int >, MonitorElement * > tTrigDiffHistos_
std::vector< std::pair< DTTtrigId, DTTtrigData > >::const_iterator const_iterator
Access methods to data.
Definition: DTTtrig.h:176
dictionary map
Definition: Association.py:205
edm::ESHandle< DTGeometry > dtGeom_
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
int stationFromBin(int bin) const
#define LogTrace(id)
virtual ~DTtTrigDBValidation()
Destructor.
std::map< DTSuperLayerId, std::pair< float, float > > tTrigRefMap_
DTtTrigDBValidation(const edm::ParameterSet &pset)
Constructor.
std::map< DTSuperLayerId, std::pair< float, float > > 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:87
void beginRun(edm::Run const &, edm::EventSetup const &)
Operations.
const T & get() const
Definition: EventSetup.h:55
const_iterator begin() const
Definition: DTTtrig.cc:377
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:845
const_iterator end() const
Definition: DTTtrig.cc:382
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
Definition: Run.h:33