35 debug(pset.getUntrackedParameter<
bool>(
"debug")),
37 theFile(pset.getUntrackedParameter<
string>(
"rootFileName",
"DTT0PerLayer.root").c_str(),
"RECREATE"),
39 eventsForLayerT0(pset.getParameter<unsigned
int>(
"eventsForLayerT0")),
40 eventsForWireT0(pset.getParameter<unsigned
int>(
"eventsForWireT0")),
41 tpPeakWidth(pset.getParameter<double>(
"tpPeakWidth")),
42 tpPeakWidthPerLayer(pset.getParameter<double>(
"tpPeakWidthPerLayer")),
43 rejectDigiFromPeak(pset.getParameter<unsigned
int>(
"rejectDigiFromPeak")),
44 hLayerPeaks(
"hLayerPeaks",
"", 3000, 0, 3000),
50 cout <<
"[DTT0Calibration]Constructor called!" << endl;
58 cout <<
"[DTT0CalibrationPerLayer] chosen wheel " << selWheel << endl;
68 cout <<
"[DTT0CalibrationPerLayer] chosen sector " << selSector << endl;
71 vector<string> defaultCell;
72 const auto& cellsWithHistos = pset.
getUntrackedParameter<vector<string> >(
"cellsWithHisto", defaultCell);
73 for(
const auto& cell : cellsWithHistos){
77 linestr >> wheel >> sector >> station >> sl >> layer >> wire;
85 cout <<
"[DTT0Calibration]Destructor called!" << endl;
103 for (
const auto& digis_per_layer : *digis)
110 const DTLayerId layerId = digis_per_layer.first;
120 digi != digiRange.second;
123 const double t0 = digi->countsTDC();
124 const DTWireId wireIdtmp(layerId, (*digi).wire());
131 "T0 from pulses by layer (TDC counts, 1 TDC count = 0.781 ns)",
145 const DTWireId wireId(layerId, (*digi).wire());
147 cout <<
" Wire: " << wireId << endl
148 <<
" time (TDC counts): " << (*digi).countsTDC()<< endl;
158 "T0 from pulses by wire (TDC counts, 1 TDC count = 0.781 ns)",
172 cout<<
"digi skipped because t0 too far from peak " <<
theTPPeakMap[layerId] << endl;
206 const auto& layerId = lHisto.first;
207 const auto&
hist = lHisto.second;
209 cout <<
"Reading histogram " <<
hist.GetName() <<
" with mean " <<
hist.GetMean() <<
" and RMS " <<
hist.GetRMS() << endl;
214 double *peaks =
spectrum.GetPositionX();
216 vector<double> peakMeans(peaks, peaks + npeaks);
218 sort(peakMeans.begin(), peakMeans.end());
220 if (peakMeans.empty())
223 std::cout <<
"No peaks found by peakfinder in layer " << layerId <<
". Taking maximum bin at " <<
theTPPeakMap[layerId] <<
". Please check!" << std::endl;
228 theTPPeakMap[layerId] = peakMeans[peakMeans.size() / 2];
232 bool peak_set =
false;
233 for (
const auto& peak : peakMeans)
242 sum +=
hist.GetBinContent(ibin);
245 if (sum <
hist.GetMaximum() / 2)
255 std::cout <<
"Peaks to far away from each other in layer " << layerId <<
". Maybe cross talk? Taking first good peak at " <<
theTPPeakMap[layerId] <<
". Please check!" << std::endl;
261 std::cout <<
"Peaks to far away from each other in layer " << layerId <<
" and no good peak found. Taking maximum bin at " <<
theTPPeakMap[layerId] <<
". Please check!" << std::endl;
265 if (peakMeans.size() > 5)
267 std::cout <<
"Found more than 5 peaks in layer " << layerId <<
". Please check!" << std::endl;
273 for (
int ibin=0; ibin<
hist.GetNbinsX(); ibin++)
275 if (
hist.GetBinContent(ibin + 1) >
hist.GetMaximum() * 0.001)
280 std::cout <<
"Found a lot of (>50) small spikes in layer " << layerId <<
". Please check if all wires are functioning as expected!" << std::endl;
296 cout <<
"[DTT0CalibrationPerLayer]Writing histos to file!" << endl;
302 wHisto.second.Write();
305 lHisto.second.Write();
309 cout <<
"[DTT0Calibration] Compute and store t0 and sigma per wire" << endl;
314 auto& wireId = wiret0.first;
329 auto unweighted_mean_function = [] (
const std::list<double>&
values,
const std::list<double>& sigmas)
332 for (
auto&
value : values)
336 mean /= values.size();
338 double uncertainty = 0;
339 for (
auto&
value : values)
341 uncertainty +=
pow(
value - mean, 2);
343 uncertainty /= values.size();
344 uncertainty =
sqrt(uncertainty);
345 return std::make_pair(mean, uncertainty);
349 std::map<DTSuperLayerId, std::pair<double, double> > mean_sigma_even;
350 std::map<DTSuperLayerId, std::pair<double, double> > mean_sigma_odd;
353 const auto superlayer_id = superlayer->id();
354 std::list<double> values_even;
355 std::list<double> sigmas_even;
356 std::list<double> values_odd;
357 std::list<double> sigmas_odd;
359 for (
const auto& wiret0 : theAbsoluteT0PerWire)
361 const auto& wireId = wiret0.first;
362 if (wireId.layerId().superlayerId() == superlayer_id)
365 if (wireId.layerId().layer() % 2)
367 values_odd.push_back(
t0);
372 values_even.push_back(
t0);
378 mean_sigma_even.emplace(superlayer_id, unweighted_mean_function(values_even, sigmas_even));
379 mean_sigma_odd.emplace(superlayer_id, unweighted_mean_function(values_odd, sigmas_odd));
385 const auto superlayer_id = superlayer->id();
386 std::list<double> values_even;
387 std::list<double> sigmas_even;
388 std::list<double> values_odd;
389 std::list<double> sigmas_odd;
391 for (
const auto& wiret0 : theAbsoluteT0PerWire)
393 const auto& wireId = wiret0.first;
394 if (wireId.layerId().superlayerId() == superlayer_id)
397 if (wireId.layerId().layer() % 2 and
abs(
t0 - mean_sigma_odd[superlayer_id].
first) < 2 * mean_sigma_odd[superlayer_id].second)
399 values_odd.push_back(
t0);
404 if (
abs(
t0 - mean_sigma_even[superlayer_id].first) < 2 * mean_sigma_even[superlayer_id].
second)
406 values_even.push_back(
t0);
413 mean_sigma_even[superlayer_id] = unweighted_mean_function(values_even, sigmas_even);
414 mean_sigma_odd[superlayer_id] = unweighted_mean_function(values_odd, sigmas_odd);
418 for (
auto& wiret0 : theAbsoluteT0PerWire)
420 const auto& wire_id = wiret0.first;
421 const auto& superlayer_id = wiret0.first.layerId().superlayerId();
422 const auto& layer = wiret0.first.layerId().layer();
423 auto&
t0 = wiret0.second;
428 t0 += mean_sigma_even[superlayer_id].first - mean_sigma_odd[superlayer_id].first;
433 std::map<DTChamberId, std::list<double> > values_per_chamber;
434 std::map<DTChamberId, std::list<double> > sigmas_per_chamber;
435 for (
const auto& wire_t0 : theAbsoluteT0PerWire)
437 const auto& wire_id = wire_t0.first;
438 const auto& chamber_id = wire_id.chamberId();
439 const auto&
t0 = wire_t0.second;
440 values_per_chamber[chamber_id].push_back(
t0);
444 std::map<DTChamberId, std::pair<double, double> > mean_per_chamber;
445 for (
const auto& chamber_mean : values_per_chamber)
447 const auto& chamber_id = chamber_mean.first;
448 const auto& means = chamber_mean.second;
449 const auto& sigmas = sigmas_per_chamber[chamber_id];
450 mean_per_chamber.emplace(chamber_id, unweighted_mean_function(means, sigmas));
454 for (
const auto& wire_t0 : theAbsoluteT0PerWire)
456 const auto& wire_id = wire_t0.first;
457 const auto& chamber_id = wire_id.chamberId();
458 const auto&
t0 = wire_t0.second;
460 cout <<
"[DTT0Calibration] Wire " << wire_id <<
" has t0 "<<
theRelativeT0PerWire[wire_id] <<
" (relative, after even-odd layer corrections) " 466 const auto& wire_id = wire_t0.first;
467 const auto&
t0 = wire_t0.second;
468 t0sWRTChamber->
set(wire_id,
477 cout <<
"[DTT0Calibration]Writing values in DB!" << endl;
479 string t0Record =
"DTT0Rcd";
482 delete t0sWRTChamber;
487 stringstream theStream;
490 theStream >> histoName;
496 stringstream theStream;
499 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
void endJob() override
Compute the mean and the RMS of the t0 from the maps and write them to the DB with channel granularit...
std::map< DTWireId, double > theAbsoluteT0PerWire
DTChamberId chamberId() const
Return the corresponding ChamberId.
std::map< DTLayerId, double > theTPPeakMap
std::map< DTWireId, int > nDigiPerWire
std::vector< DTWireId > wireIdWithHistos
std::string theCalibWheel
std::string getHistoName(const DTWireId &wId) const
std::map< DTWireId, double > theSigmaT0PerWire
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
std::map< DTWireId, double > mK
unsigned int eventsForLayerT0
U second(std::pair< T, U > const &p)
unsigned int rejectDigiFromPeak
std::map< DTWireId, double > theRelativeT0PerWire
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::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Abs< T >::type abs(const T &t)
~DTT0Calibration() override
Destructor.
std::string theCalibSector
std::map< DTWireId, double > qK
edm::EDGetTokenT< DTDigiCollection > digiToken
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
Fill the maps with t0 (by channel)
std::map< DTWireId, double > mK_ref
int wire() const
Return the wire number.
int superlayer() const
Return the superlayer number (deprecated method name)
std::map< DTWireId, TH1I > theHistoWireMap
std::vector< DigiType >::const_iterator const_iterator
std::pair< const_iterator, const_iterator > Range
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)
const std::vector< const DTSuperLayer * > & superLayers() const
Return a vector of all SuperLayer.
std::map< DTWireId, int > nDigiPerWire_ref