13#include "GaudiKernel/MsgStream.h"
33 std::shared_ptr<const T0MTSettings> settings,
34 const std::vector<int> &sort_by,
35 const std::vector<int> &adc_sort_by) :
44 std::string HistoFileName =
"T0MT_" +
m_name +
".root";
45 m_file = std::make_unique<TFile>(HistoFileName.c_str(),
"recreate");
65 int nML =
id.mdtMultilayer();
66 int nL =
id.mdtTubeLayer();
67 int nT =
id.mdtTube();
71 std::map<NtupleStationId, MdtTubeFitContainer *>::const_iterator res_it(
m_result.find(sid));
73 const MdtIdHelper& idHelper{res_it->second->idHelperSvc()->mdtIdHelper()};
75 id.
eta(),
id.
phi(), nML, nL, nT);
76 stc = res_it->second->getCalib(tubeId);
83 log << MSG::WARNING <<
"no Single Tube Calib info found for ML=" << nML <<
" L=" << nL <<
" T=" << nT <<
endmsg;
87 for (
unsigned int i = 0; i <
m_sort_by.size(); i++) {
89 histos->GetTSpec()->Fill(hit->driftTime() + oldT0 + hit->tubeT0());
93 adc_histos->
GetADCSpec()->Fill(hit->adcCount());
103 std::map<int, MdtTubeFitContainer::SingleTubeFit> full;
104 std::map<int, MdtTubeFitContainer::SingleTubeCalib> st;
105 std::map<int, std::string> fit_by;
111 for (
auto & it : full) {
112 if (it.first == 0)
continue;
124 fId.
eta(), fId.
phi(), nML, nL, nT);
126 bool setInfo =
m_result[sid]->setCalib(stc, tubeId, log);
128 log << MSG::WARNING <<
"T0CalibrationMT::PROBLEM! could not set SingleTubeCalib info" <<
endmsg;
132 setInfo =
m_result[sid]->setFit(std::move(fi), tubeId, log);
135 log << MSG::WARNING <<
"T0CalibrationMT::PROBLEM! could not set SingleTubeFit info" <<
endmsg;
145 std::map<int, MdtTubeFitContainer::SingleTubeCalib> &st, std::map<int, std::string> &fit_by_map) {
150 std::string fit_by(
"UNKNOWN");
168 std::map<int, MdtTubeFitContainer::SingleTubeCalib> &st) {
182 std::map<int, MdtTubeFitContainer::SingleTubeFit> &fim,
183 std::map<int, MdtTubeFitContainer::SingleTubeCalib> &stcm, std::map<int, std::string> &fit_by_map,
184 const std::string &fit_by) {
185 TDirectory *
cwd = gDirectory;
189 if (fit_by ==
"CHAMBER")
191 else if (fit_by ==
"MULTILAYER")
193 else if (fit_by ==
"LAYER")
195 else if (fit_by ==
"MEZZ_CARD")
199 for (
auto tube_id : tube_ids) {
200 if (tube_id.getIdInt() == 0)
continue;
210 fi.
par[0] = fun->GetParameter(T0MTHistos ::T0_PAR_NR_BACK);
211 fi.
cov[0] = fun->GetParError(T0MTHistos ::T0_PAR_NR_BACK);
212 fi.
par[4] = fun->GetParameter(T0MTHistos ::T0_PAR_NR_T0) + rel_t0;
213 fi.
cov[4] = fun->GetParError(T0MTHistos ::T0_PAR_NR_T0);
214 fi.
par[6] = fun->GetParameter(T0MTHistos ::T0_PAR_NR_T);
215 fi.
cov[6] = fun->GetParError(T0MTHistos ::T0_PAR_NR_T);
216 stc.
t0 = fun->GetParameter(T0MTHistos ::T0_PAR_NR_T0) + rel_t0;
219 fit_by_map[tube_id.getIdInt()] = fit_by;
225 for (
auto tube_id : tube_ids) {
226 if (tube_id.getIdInt() == 0)
continue;
229 fi.
par[5] = fun->GetParameter(T0MTHistos ::TMAX_PAR_NR_TMAX);
230 fi.
cov[5] = fun->GetParError(T0MTHistos ::TMAX_PAR_NR_TMAX);
231 fi.
chi2TdcEnd = fun->GetChisquare() / fun->GetNDF();
238 std::map<int, MdtTubeFitContainer::SingleTubeFit> &fim,
239 std::map<int, MdtTubeFitContainer::SingleTubeCalib> &stcm) {
242 if (fun ==
nullptr)
return;
243 for (
auto tube_id : tube_ids) {
244 if (tube_id.getIdInt() == 0)
continue;
248 stc.
adcCal = fun->GetParameter(1);
249 for (
int i = 0; (i < fun->GetNpar() && i < 4); i++) {
250 fi.
adc_par[i] = fun->GetParameter(i);
251 fi.
adc_err[i] = fun->GetParError(i);
253 fi.
adc_chi2 = fun->GetChisquare() / fun->GetNDF();
264 TDirectory *
cwd = gDirectory;
266 m_adc_histos[nr][id] = std::make_unique<ADCMTHistos>(
id.getIdInt(),
m_settings.get(),
id.HistogramName().c_str());
277 TDirectory *
cwd = gDirectory;
279 m_histos[nr][id] = std::make_unique<T0MTHistos>(
id.getIdInt(),
m_settings.get(),
id.HistogramName().c_str());
294 if (!calib_in || !t0Input)
return;
297 it.second->setImplementation(
"T0CalibrationMT");
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
TGraphErrors * GetEntries(TH2F *histo)
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int tubeLayer, int tube) const
Histogram and fitter class for drift time and pulsehight spectra The rising slope is fitted by a ferm...
TF1 * GetAdcFunction() const
returnd function fitted to adc-spectrum
TH1F * GetADCSpec()
get adc spectrum
Identifier class for drift time histograms.
static const int TUBE
valid values of the sort_by argument of the Initialize function
static const int MEZZ_CARD
static const int MULTILAYER
Interface to pass calibration output during calibration.
IMdtCalibration(const std::string &name)
constructor, string used to identify the instance
virtual std::string name() const
returns name (region) of instance
std::shared_ptr< IMdtCalibrationOutput > MdtCalibOutputPtr
std::vector< std::shared_ptr< MuonCalibSegment > > MuonSegVec
A MuonCalibSegment is a reconstructed three dimensional track segment in the MuonSpectrometer.
std::shared_ptr< MdtCalibHitBase > MdtHitPtr
typedef for a collection of MdtCalibHitBase s
const MdtHitVec & mdtHOT() const
retrieve the full set of MdtCalibHitBase s assigned to this segment
Implements fixed identifiers not dependent upon Athena Identifier for internal use in the calibration...
int mdtTubeLayer() const
Mdt specific:
int mdtTube() const
Mdt specific:
unsigned int getIdInt() const
std::string stationNameString() const
int mdtMultilayer() const
Mdt specific:
Station Identifier for sorting calibration data.
void SetMultilayer(const int &ml)
std::unique_ptr< TFile > m_file
pointer to the histogram file
void doTimeFit(T0MTHistos *T0h, const std::set< MuonFixedId > &tube_ids, std::map< int, MdtTubeFitContainer::SingleTubeFit > &fim, std::map< int, MdtTubeFitContainer::SingleTubeCalib > &stcm, std::map< int, std::string > &fit_by_map, const std::string &fit_by)
fit time spectrum
std::vector< std::map< HistogramId, std::unique_ptr< ADCMTHistos > > > m_adc_histos
vector of pointers tube histograms
virtual IMdtCalibration::MdtCalibOutputPtr getResults() const override
T0MTHistos * getHistos(const MuonFixedId &idtube, unsigned int nr)
retrieve pointer for tube idtube histograms
bool analyse_adc(const int &nr, std::map< int, MdtTubeFitContainer::SingleTubeFit > &full, std::map< int, MdtTubeFitContainer::SingleTubeCalib > &st)
std::shared_ptr< const T0MTSettings > m_settings
pointer to the settings
void setInput(const IMdtCalibrationOutput *input) override
unused
void doAdcFit(ADCMTHistos *T0h, const std::set< MuonFixedId > &tube_ids, std::map< int, MdtTubeFitContainer::SingleTubeFit > &fim, std::map< int, MdtTubeFitContainer::SingleTubeCalib > &stcm)
fit adc spectrum
std::vector< std::map< HistogramId, std::set< MuonFixedId > > > m_adc_tube_ids
int m_currentItnum
current iteration (always 1?)
bool m_converged
convergence status
bool handleSegment(MuonCalibSegment &seg)
fill tube spectra
std::vector< std::map< HistogramId, std::set< MuonFixedId > > > m_tube_ids
bool analyse()
extract parameters from spectra
std::map< int, int > m_nhits_per_tube
number of hits per tube
std::map< NtupleStationId, MdtTubeFitContainer * > m_result
tube constants
T0CalibrationMT(const std::string &name, std::shared_ptr< const T0MTSettings > settings, const std::vector< int > &sort_by, const std::vector< int > &adc_sort_by)
constructor
TDirectory * m_regiondir
pointer to the ROOT directory
const std::vector< int > & m_sort_by
std::vector< std::map< HistogramId, std::unique_ptr< T0MTHistos > > > m_histos
vector of pointers tube histograms
virtual IMdtCalibration::MdtCalibOutputPtr analyseSegments(const MuonSegVec &segs) override
new interface function
bool converged() const
return m_converged
bool analyse_tdc(const int &nr, std::map< int, MdtTubeFitContainer::SingleTubeFit > &full, std::map< int, MdtTubeFitContainer::SingleTubeCalib > &st, std::map< int, std::string > &fit_by_map)
std::map< NtupleStationId, MdtRelativeTubeT0 > m_rel_tube_t0s
ADCMTHistos * getADCHistos(const MuonFixedId &idtube, unsigned int nr)
retrieve pointer for tube idtube histograms
const std::vector< int > & m_adc_sort_by
~T0CalibrationMT()
destructor
std::string m_name
calibration region name
class for the communication of the results of T0 calibration algorithms
std::map< NtupleStationId, MdtTubeFitContainer * > & GetMap()
Histogram and fitter class for drift time and pulsehight spectra The rising slope is fitted by a ferm...
TH1F * GetTSpec() const
get drift time spectrum
int StatusCode() const
returns status code - the status code applies only to the t0 fit
double T0Chi2() const
returns t0 chi2
bool FitT0()
Perform t0-fit Returns true if fit is successfull.
bool FitTmax()
Performs tmax-fit Returns true if fit is successfull.
const TF1 * GetT0Function() const
returns function fitted to the riding edge of the spectrum
const TF1 * GetTMaxFunction() const
returns function fitted to the riding edge of the spectrum
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
float adcCal
quality flag for the SingleTubeCalib constants: 0 all ok, 1 no hits found, 2 too few hits,...
float t0
< relative t0 in chamber (ns)
int n_hits_above_adc_cut
number of hits above adc cut
std::array< float, 8 > par
std::array< float, 4 > adc_par
std::array< float, 36 > cov
int statistics
< number of hits used for the fit
std::array< float, 4 > adc_err
float chi2TdcEnd
for MTT0 chi2 of trailing edge fit