35 :
debug(pset.getUntrackedParameter<bool>(
"debug")),
37 theFile(pset.getUntrackedParameter<
string>(
"rootFileName",
"DTT0PerLayer.root").c_str(),
"RECREATE"),
41 tpPeakWidth(pset.getParameter<double>(
"tpPeakWidth")),
44 hLayerPeaks(
"hLayerPeaks",
"", 3000, 0, 3000),
49 cout <<
"[DTT0Calibration]Constructor called!" << endl;
58 cout <<
"[DTT0CalibrationPerLayer] chosen wheel " << selWheel << endl;
69 cout <<
"[DTT0CalibrationPerLayer] chosen sector " << selSector << endl;
72 vector<string> defaultCell;
73 const auto& cellsWithHistos = pset.
getUntrackedParameter<vector<string> >(
"cellsWithHisto", defaultCell);
74 for (
const auto& cell : cellsWithHistos) {
78 linestr >> wheel >> sector >> station >> sl >> layer >> wire;
86 cout <<
"[DTT0Calibration]Destructor called!" << endl;
104 for (
const auto& digis_per_layer : *digis) {
110 const DTLayerId layerId = digis_per_layer.first;
120 const double t0 = digi->countsTDC();
121 const DTWireId wireIdtmp(layerId, (*digi).wire());
128 "T0 from pulses by layer (TDC counts, 1 TDC count = 0.781 ns)",
141 const DTWireId wireId(layerId, (*digi).wire());
143 cout <<
" Wire: " << wireId << endl <<
" time (TDC counts): " << (*digi).countsTDC() << endl;
153 "T0 from pulses by wire (TDC counts, 1 TDC count = 0.781 ns)",
166 cout <<
"digi skipped because t0 too far from peak " <<
theTPPeakMap[layerId] << endl;
200 const auto& layerId = lHisto.first;
201 const auto&
hist = lHisto.second;
203 cout <<
"Reading histogram " <<
hist.GetName() <<
" with mean " <<
hist.GetMean() <<
" and RMS "
204 <<
hist.GetRMS() << endl;
209 double* peaks =
spectrum.GetPositionX();
211 vector<double> peakMeans(peaks, peaks + npeaks);
213 sort(peakMeans.begin(), peakMeans.end());
215 if (peakMeans.empty()) {
217 std::cout <<
"No peaks found by peakfinder in layer " << layerId <<
". Taking maximum bin at "
218 <<
theTPPeakMap[layerId] <<
". Please check!" << std::endl;
220 }
else if (fabs(
hist.GetXaxis()->FindBin(peakMeans.front()) -
hist.GetXaxis()->FindBin(peakMeans.back())) <
222 theTPPeakMap[layerId] = peakMeans[peakMeans.size() / 2];
224 bool peak_set =
false;
225 for (
const auto& peak : peakMeans) {
232 sum +=
hist.GetBinContent(ibin);
235 if (sum <
hist.GetMaximum() / 2)
244 std::cout <<
"Peaks to far away from each other in layer " << layerId
245 <<
". Maybe cross talk? Taking first good peak at " <<
theTPPeakMap[layerId] <<
". Please check!"
250 std::cout <<
"Peaks to far away from each other in layer " << layerId
251 <<
" and no good peak found. Taking maximum bin at " <<
theTPPeakMap[layerId] <<
". Please check!"
256 if (peakMeans.size() > 5) {
257 std::cout <<
"Found more than 5 peaks in layer " << layerId <<
". Please check!" << std::endl;
264 for (
int ibin = 0; ibin <
hist.GetNbinsX(); ibin++) {
265 if (
hist.GetBinContent(ibin + 1) >
hist.GetMaximum() * 0.001)
269 std::cout <<
"Found a lot of (>50) small spikes in layer " << layerId
270 <<
". Please check if all wires are functioning as expected!" << std::endl;
286 cout <<
"[DTT0CalibrationPerLayer]Writing histos to file!" << endl;
292 wHisto.second.Write();
295 lHisto.second.Write();
299 cout <<
"[DTT0Calibration] Compute and store t0 and sigma per wire" << endl;
303 auto& wireId = wiret0.first;
317 auto unweighted_mean_function = [](
const std::list<double>&
values,
const std::list<double>& sigmas) {
319 for (
auto&
value : values) {
322 mean /= values.size();
324 double uncertainty = 0;
325 for (
auto&
value : values) {
326 uncertainty +=
pow(
value - mean, 2);
328 uncertainty /= values.size();
329 uncertainty =
sqrt(uncertainty);
330 return std::make_pair(mean, uncertainty);
334 std::map<DTSuperLayerId, std::pair<double, double> > mean_sigma_even;
335 std::map<DTSuperLayerId, std::pair<double, double> > mean_sigma_odd;
336 for (
const auto& superlayer :
dtGeom->superLayers()) {
337 const auto superlayer_id = superlayer->id();
338 std::list<double> values_even;
339 std::list<double> sigmas_even;
340 std::list<double> values_odd;
341 std::list<double> sigmas_odd;
343 for (
const auto& wiret0 : theAbsoluteT0PerWire) {
344 const auto& wireId = wiret0.first;
345 if (wireId.layerId().superlayerId() == superlayer_id) {
347 if (wireId.layerId().layer() % 2) {
348 values_odd.push_back(
t0);
351 values_even.push_back(
t0);
357 mean_sigma_even.emplace(superlayer_id, unweighted_mean_function(values_even, sigmas_even));
358 mean_sigma_odd.emplace(superlayer_id, unweighted_mean_function(values_odd, sigmas_odd));
362 for (
const auto& superlayer :
dtGeom->superLayers()) {
363 const auto superlayer_id = superlayer->id();
364 std::list<double> values_even;
365 std::list<double> sigmas_even;
366 std::list<double> values_odd;
367 std::list<double> sigmas_odd;
369 for (
const auto& wiret0 : theAbsoluteT0PerWire) {
370 const auto& wireId = wiret0.first;
371 if (wireId.layerId().superlayerId() == superlayer_id) {
373 if (wireId.layerId().layer() % 2 and
374 abs(
t0 - mean_sigma_odd[superlayer_id].
first) < 2 * mean_sigma_odd[superlayer_id].second) {
375 values_odd.push_back(
t0);
378 if (
abs(
t0 - mean_sigma_even[superlayer_id].first) < 2 * mean_sigma_even[superlayer_id].
second) {
379 values_even.push_back(
t0);
386 mean_sigma_even[superlayer_id] = unweighted_mean_function(values_even, sigmas_even);
387 mean_sigma_odd[superlayer_id] = unweighted_mean_function(values_odd, sigmas_odd);
391 for (
auto& wiret0 : theAbsoluteT0PerWire) {
392 const auto& wire_id = wiret0.first;
393 const auto& superlayer_id = wiret0.first.layerId().superlayerId();
394 const auto&
layer = wiret0.first.layerId().layer();
395 auto&
t0 = wiret0.second;
400 t0 += mean_sigma_even[superlayer_id].first - mean_sigma_odd[superlayer_id].first;
402 pow(mean_sigma_odd[superlayer_id].
second, 2) +
pow(mean_sigma_even[superlayer_id].second, 2);
406 std::map<DTChamberId, std::list<double> > values_per_chamber;
407 std::map<DTChamberId, std::list<double> > sigmas_per_chamber;
408 for (
const auto& wire_t0 : theAbsoluteT0PerWire) {
409 const auto& wire_id = wire_t0.first;
410 const auto& chamber_id = wire_id.chamberId();
411 const auto&
t0 = wire_t0.second;
412 values_per_chamber[chamber_id].push_back(
t0);
416 std::map<DTChamberId, std::pair<double, double> > mean_per_chamber;
417 for (
const auto& chamber_mean : values_per_chamber) {
418 const auto& chamber_id = chamber_mean.first;
419 const auto& means = chamber_mean.second;
420 const auto& sigmas = sigmas_per_chamber[chamber_id];
421 mean_per_chamber.emplace(chamber_id, unweighted_mean_function(means, sigmas));
425 for (
const auto& wire_t0 : theAbsoluteT0PerWire) {
426 const auto& wire_id = wire_t0.first;
427 const auto& chamber_id = wire_id.chamberId();
428 const auto&
t0 = wire_t0.second;
431 <<
" (relative, after even-odd layer corrections) "
436 const auto& wire_id = wire_t0.first;
437 const auto&
t0 = wire_t0.second;
443 cout <<
"[DTT0Calibration]Writing values in DB!" << endl;
445 string t0Record =
"DTT0Rcd";
448 delete t0sWRTChamber;
453 stringstream theStream;
455 << wId.
layer() <<
"_W" << wId.
wire() <<
"_hT0Histo";
456 theStream >> histoName;
462 stringstream theStream;
464 << lId.
layer() <<
"_hT0Histo";
465 theStream >> histoName;
std::vector< DTLayerId > layerIdWithWireHistos
int set(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, float t0mean, float t0rms, DTTimeUnits::type unit)
double tpPeakWidthPerLayer
T getUntrackedParameter(std::string const &, T const &) const
std::map< DTLayerId, TH1I > theHistoLayerMap
std::map< DTWireId, double > theAbsoluteT0PerWire
void endJob() override
Compute the mean and the RMS of the t0 from the maps and write them to the DB with channel granularit...
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
DTChamberId chamberId() const
Return the corresponding ChamberId.
std::vector< DTWireId > wireIdWithHistos
std::string theCalibWheel
std::string getHistoName(const DTWireId &wId) const
std::map< DTWireId, double > mK_ref
tuple tpPeakWidthPerLayer
int layer() const
Return the layer number.
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
edm::ESHandle< DTGeometry > dtGeom
unsigned int eventsForLayerT0
constexpr std::array< uint8_t, layerIndexSize > layer
U second(std::pair< T, U > const &p)
std::map< DTLayerId, double > theTPPeakMap
std::map< DTWireId, double > theSigmaT0PerWire
unsigned int rejectDigiFromPeak
Abs< T >::type abs(const T &t)
~DTT0Calibration() override
Destructor.
std::string theCalibSector
edm::EDGetTokenT< DTDigiCollection > digiToken
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
Fill the maps with t0 (by channel)
int wire() const
Return the wire number.
int superlayer() const
Return the superlayer number (deprecated method name)
std::map< DTWireId, int > nDigiPerWire
std::map< DTWireId, double > mK
std::map< DTWireId, int > nDigiPerWire_ref
std::pair< const_iterator, const_iterator > Range
std::vector< DigiType >::const_iterator const_iterator
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > dtGeomToken_
std::map< DTWireId, double > theRelativeT0PerWire
std::map< DTWireId, double > qK
std::map< DTWireId, TH1I > theHistoWireMap
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
int station() const
Return the station number.
DTT0Calibration(const edm::ParameterSet &pset)
Constructor.
int wheel() const
Return the wheel number.
static void writeToDB(std::string record, T *payload)
unsigned int eventsForWireT0
Power< A, B >::type pow(const A &a, const B &b)