From f1c99ce7d6bbb2a5eb7c1e7f3b738869b5d42653 Mon Sep 17 00:00:00 2001 From: Maksim Penzin <penzin.maksim@gmail.com> Date: Tue, 1 Sep 2020 10:17:56 +0200 Subject: [PATCH] Style fix (auto) --- .../src/CalibCscStripFitter.cxx | 660 +++--- .../src/CalibCscStripFitter.h | 76 +- .../src/CscBipolarStripFitter.cxx | 1078 +++++---- .../src/CscBipolarStripFitter.h | 123 +- .../src/CscClusterUtilTool.cxx | 317 +-- .../src/CscClusterUtilTool.h | 75 +- .../CscPeakThresholdClusterBuilderTool.cxx | 1063 ++++----- .../src/CscPeakThresholdClusterBuilderTool.h | 141 +- .../src/CscSplitClusterFitter.cxx | 604 +++--- .../src/CscSplitClusterFitter.h | 62 +- .../src/CscThresholdClusterBuilder.cxx | 86 +- .../src/CscThresholdClusterBuilder.h | 53 +- .../src/CscThresholdClusterBuilderTool.cxx | 1771 +++++++-------- .../src/CscThresholdClusterBuilderTool.h | 160 +- .../src/QratCscClusterFitter.cxx | 1396 ++++++------ .../src/QratCscClusterFitter.h | 115 +- .../src/SimpleCscClusterFitter.cxx | 566 ++--- .../src/SimpleCscClusterFitter.h | 73 +- .../src/MuonClusterizationAlg.cxx | 75 +- .../src/MuonClusterizationAlg.h | 34 +- .../MuonTGMeasAssocAlg/MuonTGMeasAssocAlg.h | 255 +-- .../src/MuonTGMeasAssocAlg.cxx | 1930 +++++++++-------- 22 files changed, 5423 insertions(+), 5290 deletions(-) diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CalibCscStripFitter.cxx b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CalibCscStripFitter.cxx index 96c23ee9dea4..9a8951b2dd71 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CalibCscStripFitter.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CalibCscStripFitter.cxx @@ -3,346 +3,386 @@ */ #include "CalibCscStripFitter.h" -#include "MuonPrepRawData/CscStripPrepData.h" #include <cmath> +#include "MuonPrepRawData/CscStripPrepData.h" + using Muon::CscStripPrepData; -typedef ICscStripFitter::Result Result; +typedef ICscStripFitter::Result Result; typedef ICscStripFitter::ChargeList ChargeList; //********************************************************************** -CalibCscStripFitter::CalibCscStripFitter(std::string type, std::string aname, const IInterface* parent) : - AthAlgTool(type, aname, parent),m_noiseOption(rms), - m_cscCalibTool("CscCalibTool/CscCalibTool", this) { - declareInterface<ICscStripFitter>(this); - declareProperty("timeError", m_terr =5.0); - declareProperty("failTimeError", m_terr_fail =50.0); - declareProperty("chargeCalibrationError", m_qerrprop = 0.000); - declareProperty("cscCalibTool", m_cscCalibTool); - declareProperty("noiseOption", m_noiseOptionStr="f001"); - declareProperty("doCorrection", m_doCorrection=true); - declareProperty("chargeErrorScaler", m_chargeErrorScaler = 1.0); +CalibCscStripFitter::CalibCscStripFitter(std::string type, std::string aname, const IInterface* parent) + : AthAlgTool(type, aname, parent), m_noiseOption(rms), m_cscCalibTool("CscCalibTool/CscCalibTool", this) +{ + declareInterface<ICscStripFitter>(this); + declareProperty("timeError", m_terr = 5.0); + declareProperty("failTimeError", m_terr_fail = 50.0); + declareProperty("chargeCalibrationError", m_qerrprop = 0.000); + declareProperty("cscCalibTool", m_cscCalibTool); + declareProperty("noiseOption", m_noiseOptionStr = "f001"); + declareProperty("doCorrection", m_doCorrection = true); + declareProperty("chargeErrorScaler", m_chargeErrorScaler = 1.0); } //********************************************************************** -StatusCode CalibCscStripFitter::initialize() { - - ATH_MSG_DEBUG ( "Initializing " << name() ); - - ATH_MSG_DEBUG ( "Properties for " << name() << ":" ); - ATH_MSG_DEBUG ( " Time error: " << m_terr ); - ATH_MSG_DEBUG ( " Fail time error: " << m_terr_fail ); - ATH_MSG_DEBUG ( " Charge calibration error: " << m_qerrprop ); - ATH_MSG_DEBUG ( " Charge Error Option is " << m_noiseOptionStr); - ATH_MSG_DEBUG ( " Charge Error Scaler is " << m_chargeErrorScaler); - ATH_MSG_DEBUG ( " Correction applied for para to bipolar is " << m_doCorrection); - - if ( m_noiseOptionStr != "rms" - && m_noiseOptionStr != "sigma" - && m_noiseOptionStr != "f001" ) { - ATH_MSG_DEBUG (" noiseOption is not among rms/sigma/f001. rms is used for default!!"); - m_noiseOptionStr = "rms"; - } - if( m_noiseOptionStr == "rms" ) m_noiseOption = rms; - else if( m_noiseOptionStr == "sigma" ) m_noiseOption = sigma; - else if( m_noiseOptionStr == "f001" ) m_noiseOption = f001; - - // ATH_MSG_DEBUG ( " (failed) Charge error is noise(DB)*1.03588 = 4300 " << m_errorScaler ); - /** CSC calibratin tool for the Condtiions Data base access */ - if ( m_cscCalibTool.retrieve().isFailure() ) { - ATH_MSG_ERROR ( "Can't get handle on CSC calibration tools" ); - return StatusCode::RECOVERABLE; - } - - // Retrieve the detector descriptor. - ATH_CHECK(m_idHelperSvc.retrieve()); - - return StatusCode::SUCCESS; +StatusCode +CalibCscStripFitter::initialize() +{ + + ATH_MSG_DEBUG("Initializing " << name()); + + ATH_MSG_DEBUG("Properties for " << name() << ":"); + ATH_MSG_DEBUG(" Time error: " << m_terr); + ATH_MSG_DEBUG(" Fail time error: " << m_terr_fail); + ATH_MSG_DEBUG(" Charge calibration error: " << m_qerrprop); + ATH_MSG_DEBUG(" Charge Error Option is " << m_noiseOptionStr); + ATH_MSG_DEBUG(" Charge Error Scaler is " << m_chargeErrorScaler); + ATH_MSG_DEBUG(" Correction applied for para to bipolar is " << m_doCorrection); + + if (m_noiseOptionStr != "rms" && m_noiseOptionStr != "sigma" && m_noiseOptionStr != "f001") { + ATH_MSG_DEBUG(" noiseOption is not among rms/sigma/f001. rms is used for default!!"); + m_noiseOptionStr = "rms"; + } + if (m_noiseOptionStr == "rms") + m_noiseOption = rms; + else if (m_noiseOptionStr == "sigma") + m_noiseOption = sigma; + else if (m_noiseOptionStr == "f001") + m_noiseOption = f001; + + // ATH_MSG_DEBUG ( " (failed) Charge error is noise(DB)*1.03588 = 4300 " << m_errorScaler ); + /** CSC calibratin tool for the Condtiions Data base access */ + if (m_cscCalibTool.retrieve().isFailure()) { + ATH_MSG_ERROR("Can't get handle on CSC calibration tools"); + return StatusCode::RECOVERABLE; + } + + // Retrieve the detector descriptor. + ATH_CHECK(m_idHelperSvc.retrieve()); + + return StatusCode::SUCCESS; } //********************************************************************** -Result CalibCscStripFitter::fit(const ChargeList& chgs, - double period, bool samplingPhase, - Identifier& stripId) const { - // period ==> frequency either 50ns or 25ns - - Result res; - - // It has been used 4300e- as charge error so far. - // 3.5 ADC was noise -> 4151.06 e- (as of Mar 10, 2009) - // From DB, we got it as noise. error scaler is from 4300/3546.03; - // double errorScaler = 4300./4151.06; // 1.03588 - - IdentifierHash stripHash; - if (m_idHelperSvc->cscIdHelper().get_channel_hash(stripId, stripHash)){ - ATH_MSG_WARNING ( "Unable to get CSC striphash id " << " the identifier is " ); - stripId.show(); - } - - int zsec = m_idHelperSvc->cscIdHelper().stationEta(stripId); - int phisec = m_idHelperSvc->cscIdHelper().stationPhi(stripId); - int station = m_idHelperSvc->cscIdHelper().stationName(stripId) - 49; - - int sector = zsec*(2*phisec-station+1); - - int wlay = m_idHelperSvc->cscIdHelper().wireLayer(stripId); - int measphi = m_idHelperSvc->cscIdHelper().measuresPhi(stripId); - int istrip = m_idHelperSvc->cscIdHelper().strip(stripId); - - - double ped = m_cscCalibTool->stripPedestal(stripHash); - // Get noise information - double noise =0; - if (m_noiseOption == rms) { - noise = m_cscCalibTool->stripRMS(stripHash); - } else if (m_noiseOption == sigma) { - noise = m_cscCalibTool->stripNoise(stripHash); - } else if (m_noiseOption == f001) { // f001 is rawADC +1 - noise = m_cscCalibTool->stripF001(stripHash) - m_cscCalibTool->stripPedestal(stripHash); - noise /= 3.251; - } - - // bool isGood = m_cscCalibTool->isGood(stripHash); - int stripStatusWord = m_cscCalibTool->stripStatusBit(stripHash); - - bool showDetail = false; - if (noise <=0.0 ) { - showDetail = true; - ATH_MSG_DEBUG (" Noise is zero!! DB needs to be fixed for this channel. 4151.06 (3.5ADC) is assigned."); - noise = 4151.06; - } - - noise = m_chargeErrorScaler*noise; - - if (ped < 1.0) { - showDetail = true; - ATH_MSG_DEBUG (" Pedestal is zero!! DB needs to be fixed for this channel. 2048*1013 (2048ADC) is assigned."); - // ped = 0; // 2048 ADC as a default... - // unrealistic.... DB should be corrupted.... - } - - if (showDetail) - ATH_MSG_DEBUG ("noiseOption " << m_noiseOptionStr << " noise= " << noise << " pedestal= " << ped - << " strIdentifier= " << stripId << " strHash= " << (unsigned int) stripHash - << " zsec:phisec:istation sector " << zsec << ":" << phisec << ":" << station << " " << sector - << " wlay:measphi:istr = " << wlay << " " << measphi << " " << istrip - << " Charges: " << chgs << " (Sample time: " << period << " ns)" ); - - // Fit with calib tool. - res.phase = samplingPhase; - res.dcharge = noise; - - if ( m_cscCalibTool->findCharge(period, samplingPhase, chgs, res.charge, res.time) ) { // success - res.stripStatus = Muon::CscStrStatSuccess; - res.status += 1; - } else { - res.stripStatus = Muon::CscStrStatParabolaFailed; - res.status += 2; - } - - res.charge_beforeBPCorr = res.charge; - res.time_beforeBPCorr = res.time; - - if(samplingPhase==1) // This is bipolar correction purpose and will be subtracted... - res.time=res.time+25; - - if(m_doCorrection) { // m_ denotes global variables... - - bool doPositionCorrection = false; - - ATH_MSG_DEBUG ( "Without any correction res.time = " << res.time ); - ATH_MSG_DEBUG ( "Without any correction res.charge = " << res.charge ); - - double parabolapTime[150]; - for (int i=0; i<150; ++i) { - parabolapTime[i] = 0.5 +i; +Result +CalibCscStripFitter::fit(const ChargeList& chgs, double period, bool samplingPhase, Identifier& stripId) const +{ + // period ==> frequency either 50ns or 25ns + + Result res; + + // It has been used 4300e- as charge error so far. + // 3.5 ADC was noise -> 4151.06 e- (as of Mar 10, 2009) + // From DB, we got it as noise. error scaler is from 4300/3546.03; + // double errorScaler = 4300./4151.06; // 1.03588 + + IdentifierHash stripHash; + if (m_idHelperSvc->cscIdHelper().get_channel_hash(stripId, stripHash)) { + ATH_MSG_WARNING("Unable to get CSC striphash id " + << " the identifier is "); + stripId.show(); } - - double bipolarpTime[150] = {7.2767,14.6497,14.9118,15.3129,15.5765,15.8889,16.2474,16.6022,16.9897,17.3629,17.7400,18.2157,18.6235,19.0662,19.4730,19.9940,20.4652,20.9776,21.4932,22.0852,22.6554,23.2433,23.8237,24.5097,25.1759,25.8815,26.6378,27.4112,28.2157,29.0271,29.9248,30.7977,31.7510,32.7041,33.7583,34.8513,35.9103,37.1485,38.3861,39.7035,41.0022,42.3003,43.6234,45.0080,46.3782,47.7918,49.1901,50.6580,52.0537,53.4410,54.8608,56.2165,57.5229,58.8066,60.0287,61.2283,62.3879,63.5055,64.5241,65.5107,66.4050,67.3491,68.2172,68.9896,69.8158,70.4611,71.1646,71.7663,72.4042,73.0496,73.5342,74.1307,74.5450,75.0907,75.6212,76.0865,76.8541,77.6080,78.4420,79.2248,80.0880,81.0277,81.9300,82.9188,83.9960,85.0072,86.1661,87.2706,88.4430,89.6940,90.9562,92.2918,93.6533,95.0087,96.3996,97.7745,99.1749,100.6474,102.0441,103.4479,104.8626,106.2086,107.5305,108.8386,110.0599,111.2366,112.4078,113.4710,114.5671,115.5359,116.4890,117.3761,118.1778,119.0282,119.7657,120.4136,121.1364,121.8754,122.4186,123.0246,123.5694,124.1640,124.5444,125.1546,125.5514,126.0263,126.4062,126.8301,127.1727,127.5432,127.7796,128.2254,128.4639,128.7937,129.1810,129.3844,129.6880,129.9609,130.1609,130.4174,130.6324,130.8404,131.0484,131.3148,131.5413,131.6463,131.8371,132.1471,132.1629,132.3846}; - double amplCorrValue[150] ={0.0011,0.0019,0.0028,0.0047,0.0077,0.0111,0.0145,0.0207,0.0261,0.0322,0.0412,0.0491,0.0576,0.0663,0.0749,0.0830,0.0875,0.0912,0.0929,0.0931,0.0920,0.0901,0.0875,0.0841,0.0800,0.0756,0.0711,0.0663,0.0609,0.0557,0.0506,0.0453,0.0402,0.0351,0.0299,0.0260,0.0216,0.0173,0.0141,0.0109,0.0076,0.0049,0.0022,0.0003,-0.0014,-0.0021,-0.0029,-0.0029,-0.0025,-0.0023,-0.0013,0.0004,0.0017,0.0043,0.0072,0.0104,0.0141,0.0181,0.0232,0.0277,0.0338,0.0387,0.0451,0.0514,0.0582,0.0648,0.0720,0.0787,0.0855,0.0924,0.0992,0.1064,0.1125,0.1187,0.1232,0.1079,0.0779,0.0672,0.0622,0.0570,0.0515,0.0463,0.0415,0.0362,0.0314,0.0266,0.0221,0.0181,0.0143,0.0103,0.0073,0.0047,0.0021,0.0003,-0.0010,-0.0024,-0.0027,-0.0030,-0.0026,-0.0022,-0.0012,0.0003,0.0019,0.0045,0.0071,0.0108,0.0141,0.0186,0.0233,0.0285,0.0340,0.0388,0.0451,0.0512,0.0575,0.0645,0.0715,0.0788,0.0856,0.0924,0.0992,0.1064,0.1126,0.1186,0.1236,0.1283,0.1320,0.1346,0.1360,0.1351,0.1318,0.1253,0.1148,0.1030,0.0908,0.0796,0.0702,0.0597,0.0506,0.0424,0.0345,0.0283,0.0220,0.0165,0.0122,0.0082,0.0051,0.0027,0.0013,0.0004}; + int zsec = m_idHelperSvc->cscIdHelper().stationEta(stripId); + int phisec = m_idHelperSvc->cscIdHelper().stationPhi(stripId); + int station = m_idHelperSvc->cscIdHelper().stationName(stripId) - 49; + int sector = zsec * (2 * phisec - station + 1); - unsigned int j; - for(j=0; j<150; j++) { - if(res.time < parabolapTime[j]) { - //with that way we keep the index, from which bin we get values from the tables - break; - } + int wlay = m_idHelperSvc->cscIdHelper().wireLayer(stripId); + int measphi = m_idHelperSvc->cscIdHelper().measuresPhi(stripId); + int istrip = m_idHelperSvc->cscIdHelper().strip(stripId); + + + double ped = m_cscCalibTool->stripPedestal(stripHash); + // Get noise information + double noise = 0; + if (m_noiseOption == rms) { + noise = m_cscCalibTool->stripRMS(stripHash); + } else if (m_noiseOption == sigma) { + noise = m_cscCalibTool->stripNoise(stripHash); + } else if (m_noiseOption == f001) { // f001 is rawADC +1 + noise = m_cscCalibTool->stripF001(stripHash) - m_cscCalibTool->stripPedestal(stripHash); + noise /= 3.251; + } + + // bool isGood = m_cscCalibTool->isGood(stripHash); + int stripStatusWord = m_cscCalibTool->stripStatusBit(stripHash); + + bool showDetail = false; + if (noise <= 0.0) { + showDetail = true; + ATH_MSG_DEBUG(" Noise is zero!! DB needs to be fixed for this channel. 4151.06 (3.5ADC) is assigned."); + noise = 4151.06; + } + + noise = m_chargeErrorScaler * noise; + + if (ped < 1.0) { + showDetail = true; + ATH_MSG_DEBUG(" Pedestal is zero!! DB needs to be fixed for this channel. 2048*1013 (2048ADC) is assigned."); + // ped = 0; // 2048 ADC as a default... + // unrealistic.... DB should be corrupted.... + } + + if (showDetail) + ATH_MSG_DEBUG("noiseOption " << m_noiseOptionStr << " noise= " << noise << " pedestal= " << ped + << " strIdentifier= " << stripId << " strHash= " << (unsigned int)stripHash + << " zsec:phisec:istation sector " << zsec << ":" << phisec << ":" << station + << " " << sector << " wlay:measphi:istr = " << wlay << " " << measphi << " " + << istrip << " Charges: " << chgs << " (Sample time: " << period << " ns)"); + + // Fit with calib tool. + res.phase = samplingPhase; + res.dcharge = noise; + + if (m_cscCalibTool->findCharge(period, samplingPhase, chgs, res.charge, res.time)) { // success + res.stripStatus = Muon::CscStrStatSuccess; + res.status += 1; + } else { + res.stripStatus = Muon::CscStrStatParabolaFailed; + res.status += 2; } - if ( j>0 && j < 149 ) { // j should be at least 1 and at most 148.. - double a=0.; - double b=0.; - double c=0.; - - double a1 = (bipolarpTime[j]-bipolarpTime[j-1]); - //std::cout << "a1 = " << a1 << std::endl; - double a2 = (parabolapTime[j-1]+parabolapTime[j]); - //std::cout << "a2 = " << a2 << std::endl; - double a3 = ((std::pow(parabolapTime[j+1],2)-std::pow(parabolapTime[j-1],2))*(bipolarpTime[j]-bipolarpTime[j-1])-(bipolarpTime[j+1]-bipolarpTime[j-1])*(std::pow(parabolapTime[j],2)-std::pow(parabolapTime[j-1],2))); - //std::cout << "a3 = " << a3 << std::endl; - double a4 = (parabolapTime[j-1]+parabolapTime[j+1])*((parabolapTime[j-1]-parabolapTime[j+1])*(parabolapTime[j-1]+parabolapTime[j])+std::pow(parabolapTime[j],2)-std::pow(parabolapTime[j-1],2)); - //std::cout << "a4 = " << a4 << std::endl; - double a5 = std::pow(parabolapTime[j],2)-std::pow(parabolapTime[j-1],2); - //std::cout << "a5 = " << a5 << std::endl; - - //first constant - a = (a1 + (a2 * a3 / a4)) / a5 ; - - //std::cout << "a = " << a << std::endl; - double b1 = (bipolarpTime[j+1]-bipolarpTime[j-1]); - double b2 = std::pow(parabolapTime[j],2)-std::pow(parabolapTime[j-1],2); - double b3 = std::pow(parabolapTime[j+1],2)-std::pow(parabolapTime[j-1],2); - double b4 = (bipolarpTime[j]-bipolarpTime[j-1]); - double b5 = (parabolapTime[j-1]+parabolapTime[j+1]); - double b6 = (parabolapTime[j-1]-parabolapTime[j+1])*(parabolapTime[j-1]+parabolapTime[j])+std::pow(parabolapTime[j],2) - std::pow(parabolapTime[j-1],2); - //second constant - b = (b1 * b2 - b3 * b4) / (b5 * b6) ; - //std::cout << "b = " << b << std::endl; - - //third constant - c = bipolarpTime[j-1] - a * std::pow(parabolapTime[j-1],2) + b * parabolapTime[j-1]; - - //std::cout << "c = " << c << std::endl; - - double correctedTime = a*res.time*res.time + b*res.time + c; - - if (correctedTime != 0.0) - { - doPositionCorrection = true; - - if(samplingPhase==0) - res.time = correctedTime; - if(samplingPhase==1) - res.time = correctedTime-25; - } - - ATH_MSG_DEBUG( "After Correction time = " << res.time ); - } //if ( j>0 && j < 149 ) { - - - if(doPositionCorrection) { - - unsigned int l; - for(l=0; l<150; l++) { - if(res.time < parabolapTime[l]) { - //with that way we keep the index, from which bin we get values from the tables - break; + res.charge_beforeBPCorr = res.charge; + res.time_beforeBPCorr = res.time; + + if (samplingPhase == 1) // This is bipolar correction purpose and will be subtracted... + res.time = res.time + 25; + + if (m_doCorrection) { // m_ denotes global variables... + + bool doPositionCorrection = false; + + ATH_MSG_DEBUG("Without any correction res.time = " << res.time); + ATH_MSG_DEBUG("Without any correction res.charge = " << res.charge); + + double parabolapTime[150]; + for (int i = 0; i < 150; ++i) { + parabolapTime[i] = 0.5 + i; } - } - - if(l>0 && l<149) { - - double a_1 = (amplCorrValue[l]-amplCorrValue[l-1]); - double a_2 = (parabolapTime[l-1]+parabolapTime[l]); - double a_3 = ((std::pow(parabolapTime[l+1],2)-std::pow(parabolapTime[l-1],2))*(amplCorrValue[l]-amplCorrValue[l-1])-(amplCorrValue[l+1]-amplCorrValue[l-1])*(std::pow(parabolapTime[l],2)-std::pow(parabolapTime[l-1],2))); - double a_4 = (parabolapTime[l-1]+parabolapTime[l+1])*((parabolapTime[l-1]-parabolapTime[l+1])*(parabolapTime[l-1]+parabolapTime[l])+std::pow(parabolapTime[l],2)-std::pow(parabolapTime[l-1],2)); - double a_5 = std::pow(parabolapTime[l],2)-std::pow(parabolapTime[l-1],2); - //first constant - double aConst = (a_1 + (a_2 * a_3 / a_4)) / a_5 ; - - double b_1 = (amplCorrValue[l+1]-amplCorrValue[l-1]); - double b_2 = std::pow(parabolapTime[l],2)-std::pow(parabolapTime[l-1],2); - double b_3 = std::pow(parabolapTime[l+1],2)-std::pow(parabolapTime[l-1],2); - double b_4 = (amplCorrValue[l]-amplCorrValue[l-1]); - double b_5 = (parabolapTime[l-1]+parabolapTime[l+1]); - double b_6 = (parabolapTime[l-1]-parabolapTime[l+1])*(parabolapTime[l-1]+parabolapTime[l])+std::pow(parabolapTime[l],2) - std::pow(parabolapTime[l-1],2); - //second constant - double bConst = (b_1 * b_2 - b_3 * b_4) / (b_5 * b_6) ; - - //third constant - double cConst = amplCorrValue[l-1] - aConst * std::pow(parabolapTime[l-1],2) + bConst * parabolapTime[l-1]; - double fixedValue = aConst*res.time*res.time + bConst*res.time + cConst; - - res.charge = res.charge / (1 - fixedValue); - - ATH_MSG_DEBUG( "After Correction charge = " << res.charge ); - } - } // if(doPositionCorrection) - - - ////////////// TO Correction///////////////////////// - - res.time_beforeT0Corr = res.time; - - double t0base = m_cscCalibTool->stripT0base(stripHash); - int t0phase = int(m_cscCalibTool->stripT0phase(stripHash)); - - - res.time = res.time_beforeT0Corr - t0base - 12.5*t0phase; - - } - - for (unsigned int i=0; i<chgs.size(); ++i) { - if (m_cscCalibTool->numberOfElectronsToADCCount(stripHash,int(ped+chgs[i]) ) >= 4090 ) {// ADC unit - res.stripStatus = Muon::CscStrStatSaturated; - res.status += 4; + + double bipolarpTime[150] = { + 7.2767, 14.6497, 14.9118, 15.3129, 15.5765, 15.8889, 16.2474, 16.6022, 16.9897, 17.3629, + 17.7400, 18.2157, 18.6235, 19.0662, 19.4730, 19.9940, 20.4652, 20.9776, 21.4932, 22.0852, + 22.6554, 23.2433, 23.8237, 24.5097, 25.1759, 25.8815, 26.6378, 27.4112, 28.2157, 29.0271, + 29.9248, 30.7977, 31.7510, 32.7041, 33.7583, 34.8513, 35.9103, 37.1485, 38.3861, 39.7035, + 41.0022, 42.3003, 43.6234, 45.0080, 46.3782, 47.7918, 49.1901, 50.6580, 52.0537, 53.4410, + 54.8608, 56.2165, 57.5229, 58.8066, 60.0287, 61.2283, 62.3879, 63.5055, 64.5241, 65.5107, + 66.4050, 67.3491, 68.2172, 68.9896, 69.8158, 70.4611, 71.1646, 71.7663, 72.4042, 73.0496, + 73.5342, 74.1307, 74.5450, 75.0907, 75.6212, 76.0865, 76.8541, 77.6080, 78.4420, 79.2248, + 80.0880, 81.0277, 81.9300, 82.9188, 83.9960, 85.0072, 86.1661, 87.2706, 88.4430, 89.6940, + 90.9562, 92.2918, 93.6533, 95.0087, 96.3996, 97.7745, 99.1749, 100.6474, 102.0441, 103.4479, + 104.8626, 106.2086, 107.5305, 108.8386, 110.0599, 111.2366, 112.4078, 113.4710, 114.5671, 115.5359, + 116.4890, 117.3761, 118.1778, 119.0282, 119.7657, 120.4136, 121.1364, 121.8754, 122.4186, 123.0246, + 123.5694, 124.1640, 124.5444, 125.1546, 125.5514, 126.0263, 126.4062, 126.8301, 127.1727, 127.5432, + 127.7796, 128.2254, 128.4639, 128.7937, 129.1810, 129.3844, 129.6880, 129.9609, 130.1609, 130.4174, + 130.6324, 130.8404, 131.0484, 131.3148, 131.5413, 131.6463, 131.8371, 132.1471, 132.1629, 132.3846}; + + double amplCorrValue[150] = { + 0.0011, 0.0019, 0.0028, 0.0047, 0.0077, 0.0111, 0.0145, 0.0207, 0.0261, 0.0322, 0.0412, 0.0491, + 0.0576, 0.0663, 0.0749, 0.0830, 0.0875, 0.0912, 0.0929, 0.0931, 0.0920, 0.0901, 0.0875, 0.0841, + 0.0800, 0.0756, 0.0711, 0.0663, 0.0609, 0.0557, 0.0506, 0.0453, 0.0402, 0.0351, 0.0299, 0.0260, + 0.0216, 0.0173, 0.0141, 0.0109, 0.0076, 0.0049, 0.0022, 0.0003, -0.0014, -0.0021, -0.0029, -0.0029, + -0.0025, -0.0023, -0.0013, 0.0004, 0.0017, 0.0043, 0.0072, 0.0104, 0.0141, 0.0181, 0.0232, 0.0277, + 0.0338, 0.0387, 0.0451, 0.0514, 0.0582, 0.0648, 0.0720, 0.0787, 0.0855, 0.0924, 0.0992, 0.1064, + 0.1125, 0.1187, 0.1232, 0.1079, 0.0779, 0.0672, 0.0622, 0.0570, 0.0515, 0.0463, 0.0415, 0.0362, + 0.0314, 0.0266, 0.0221, 0.0181, 0.0143, 0.0103, 0.0073, 0.0047, 0.0021, 0.0003, -0.0010, -0.0024, + -0.0027, -0.0030, -0.0026, -0.0022, -0.0012, 0.0003, 0.0019, 0.0045, 0.0071, 0.0108, 0.0141, 0.0186, + 0.0233, 0.0285, 0.0340, 0.0388, 0.0451, 0.0512, 0.0575, 0.0645, 0.0715, 0.0788, 0.0856, 0.0924, + 0.0992, 0.1064, 0.1126, 0.1186, 0.1236, 0.1283, 0.1320, 0.1346, 0.1360, 0.1351, 0.1318, 0.1253, + 0.1148, 0.1030, 0.0908, 0.0796, 0.0702, 0.0597, 0.0506, 0.0424, 0.0345, 0.0283, 0.0220, 0.0165, + 0.0122, 0.0082, 0.0051, 0.0027, 0.0013, 0.0004}; + + + unsigned int j; + for (j = 0; j < 150; j++) { + if (res.time < parabolapTime[j]) { + // with that way we keep the index, from which bin we get values from the tables + break; + } + } + + if (j > 0 && j < 149) { // j should be at least 1 and at most 148.. + double a = 0.; + double b = 0.; + double c = 0.; + + double a1 = (bipolarpTime[j] - bipolarpTime[j - 1]); + // std::cout << "a1 = " << a1 << std::endl; + double a2 = (parabolapTime[j - 1] + parabolapTime[j]); + // std::cout << "a2 = " << a2 << std::endl; + double a3 = ((std::pow(parabolapTime[j + 1], 2) - std::pow(parabolapTime[j - 1], 2)) + * (bipolarpTime[j] - bipolarpTime[j - 1]) + - (bipolarpTime[j + 1] - bipolarpTime[j - 1]) + * (std::pow(parabolapTime[j], 2) - std::pow(parabolapTime[j - 1], 2))); + // std::cout << "a3 = " << a3 << std::endl; + double a4 = (parabolapTime[j - 1] + parabolapTime[j + 1]) + * ((parabolapTime[j - 1] - parabolapTime[j + 1]) * (parabolapTime[j - 1] + parabolapTime[j]) + + std::pow(parabolapTime[j], 2) - std::pow(parabolapTime[j - 1], 2)); + // std::cout << "a4 = " << a4 << std::endl; + double a5 = std::pow(parabolapTime[j], 2) - std::pow(parabolapTime[j - 1], 2); + // std::cout << "a5 = " << a5 << std::endl; + + // first constant + a = (a1 + (a2 * a3 / a4)) / a5; + + // std::cout << "a = " << a << std::endl; + double b1 = (bipolarpTime[j + 1] - bipolarpTime[j - 1]); + double b2 = std::pow(parabolapTime[j], 2) - std::pow(parabolapTime[j - 1], 2); + double b3 = std::pow(parabolapTime[j + 1], 2) - std::pow(parabolapTime[j - 1], 2); + double b4 = (bipolarpTime[j] - bipolarpTime[j - 1]); + double b5 = (parabolapTime[j - 1] + parabolapTime[j + 1]); + double b6 = (parabolapTime[j - 1] - parabolapTime[j + 1]) * (parabolapTime[j - 1] + parabolapTime[j]) + + std::pow(parabolapTime[j], 2) - std::pow(parabolapTime[j - 1], 2); + // second constant + b = (b1 * b2 - b3 * b4) / (b5 * b6); + // std::cout << "b = " << b << std::endl; + + // third constant + c = bipolarpTime[j - 1] - a * std::pow(parabolapTime[j - 1], 2) + b * parabolapTime[j - 1]; + + // std::cout << "c = " << c << std::endl; + + double correctedTime = a * res.time * res.time + b * res.time + c; + + if (correctedTime != 0.0) { + doPositionCorrection = true; + + if (samplingPhase == 0) res.time = correctedTime; + if (samplingPhase == 1) res.time = correctedTime - 25; + } + + ATH_MSG_DEBUG("After Correction time = " << res.time); + } // if ( j>0 && j < 149 ) { + + + if (doPositionCorrection) { + + unsigned int l; + for (l = 0; l < 150; l++) { + if (res.time < parabolapTime[l]) { + // with that way we keep the index, from which bin we get values from the tables + break; + } + } + + if (l > 0 && l < 149) { + + double a_1 = (amplCorrValue[l] - amplCorrValue[l - 1]); + double a_2 = (parabolapTime[l - 1] + parabolapTime[l]); + double a_3 = ((std::pow(parabolapTime[l + 1], 2) - std::pow(parabolapTime[l - 1], 2)) + * (amplCorrValue[l] - amplCorrValue[l - 1]) + - (amplCorrValue[l + 1] - amplCorrValue[l - 1]) + * (std::pow(parabolapTime[l], 2) - std::pow(parabolapTime[l - 1], 2))); + double a_4 = + (parabolapTime[l - 1] + parabolapTime[l + 1]) + * ((parabolapTime[l - 1] - parabolapTime[l + 1]) * (parabolapTime[l - 1] + parabolapTime[l]) + + std::pow(parabolapTime[l], 2) - std::pow(parabolapTime[l - 1], 2)); + double a_5 = std::pow(parabolapTime[l], 2) - std::pow(parabolapTime[l - 1], 2); + // first constant + double aConst = (a_1 + (a_2 * a_3 / a_4)) / a_5; + + double b_1 = (amplCorrValue[l + 1] - amplCorrValue[l - 1]); + double b_2 = std::pow(parabolapTime[l], 2) - std::pow(parabolapTime[l - 1], 2); + double b_3 = std::pow(parabolapTime[l + 1], 2) - std::pow(parabolapTime[l - 1], 2); + double b_4 = (amplCorrValue[l] - amplCorrValue[l - 1]); + double b_5 = (parabolapTime[l - 1] + parabolapTime[l + 1]); + double b_6 = (parabolapTime[l - 1] - parabolapTime[l + 1]) * (parabolapTime[l - 1] + parabolapTime[l]) + + std::pow(parabolapTime[l], 2) - std::pow(parabolapTime[l - 1], 2); + // second constant + double bConst = (b_1 * b_2 - b_3 * b_4) / (b_5 * b_6); + + // third constant + double cConst = + amplCorrValue[l - 1] - aConst * std::pow(parabolapTime[l - 1], 2) + bConst * parabolapTime[l - 1]; + double fixedValue = aConst * res.time * res.time + bConst * res.time + cConst; + + res.charge = res.charge / (1 - fixedValue); + + ATH_MSG_DEBUG("After Correction charge = " << res.charge); + } + } // if(doPositionCorrection) + + + ////////////// TO Correction///////////////////////// + + res.time_beforeT0Corr = res.time; + + double t0base = m_cscCalibTool->stripT0base(stripHash); + int t0phase = int(m_cscCalibTool->stripT0phase(stripHash)); + + + res.time = res.time_beforeT0Corr - t0base - 12.5 * t0phase; } - } - - if (stripStatusWord & 0x1) { - res.stripStatus = Muon::CscStrStatHot; - res.status += 8; - } else if ( (stripStatusWord >>1) & 0x1 ) { - res.stripStatus = Muon::CscStrStatDead; - res.status += 16; - } - - float max = -4090000; - //unsigned int imax =0; - for (unsigned int i=0; i<chgs.size(); ++i) { - if (chgs[i]>max) { - max =chgs[i]; - //imax = i; + + for (unsigned int i = 0; i < chgs.size(); ++i) { + if (m_cscCalibTool->numberOfElectronsToADCCount(stripHash, int(ped + chgs[i])) >= 4090) { // ADC unit + res.stripStatus = Muon::CscStrStatSaturated; + res.status += 4; + } } - } + if (stripStatusWord & 0x1) { + res.stripStatus = Muon::CscStrStatHot; + res.status += 8; + } else if ((stripStatusWord >> 1) & 0x1) { + res.stripStatus = Muon::CscStrStatDead; + res.status += 16; + } - if (res.stripStatus == Muon::CscStrStatSuccess - || res.stripStatus == Muon::CscStrStatSaturated) { - res.timeStatus = Muon::CscTimeSuccess; - if (res.time < -500) { - res.timeStatus = Muon::CscTimeEarly; - } else if (res.time > 500) { - res.timeStatus = Muon::CscTimeLate; + float max = -4090000; + // unsigned int imax =0; + for (unsigned int i = 0; i < chgs.size(); ++i) { + if (chgs[i] > max) { + max = chgs[i]; + // imax = i; + } } - } else if (res.stripStatus == Muon::CscStrStatUndefined) { - res.timeStatus = Muon::CscTimeStatusUndefined; - } else { - res.timeStatus = Muon::CscTimeUnavailable; - } - - - /* - Completed later - - if (imax <= 1 && chgs[imax+1] <= chgs[imax+2] ) { - res.stripStatus = Muon::CscStrStatNoBipolarShape; - } - */ - - res.dtime = !res.stripStatus ? m_terr : m_terr_fail; - - // Add an error proportional to the charge. - double dqprop = m_qerrprop*res.charge; - res.dcharge = sqrt(res.dcharge*res.dcharge + dqprop*dqprop); - - // if (res.charge ==0) res.charge =40; - - return res; -} -//********************************************************************** - // for (int i=1; i<2000; i++){ - // ATH_MSG_DEBUG ( " ADC counts: " << 1.0*i - // << " Charges: " << m_cscCalibTool->adcCountToNumberOfElectrons(i) << endl; - // } + if (res.stripStatus == Muon::CscStrStatSuccess || res.stripStatus == Muon::CscStrStatSaturated) { + res.timeStatus = Muon::CscTimeSuccess; + if (res.time < -500) { + res.timeStatus = Muon::CscTimeEarly; + } else if (res.time > 500) { + res.timeStatus = Muon::CscTimeLate; + } + } else if (res.stripStatus == Muon::CscStrStatUndefined) { + res.timeStatus = Muon::CscTimeStatusUndefined; + } else { + res.timeStatus = Muon::CscTimeUnavailable; + } + + + /* + Completed later + + if (imax <= 1 && chgs[imax+1] <= chgs[imax+2] ) { + res.stripStatus = Muon::CscStrStatNoBipolarShape; + } + */ + res.dtime = !res.stripStatus ? m_terr : m_terr_fail; + // Add an error proportional to the charge. + double dqprop = m_qerrprop * res.charge; + res.dcharge = sqrt(res.dcharge * res.dcharge + dqprop * dqprop); + + // if (res.charge ==0) res.charge =40; + + return res; +} + + +//********************************************************************** +// for (int i=1; i<2000; i++){ +// ATH_MSG_DEBUG ( " ADC counts: " << 1.0*i +// << " Charges: " << m_cscCalibTool->adcCountToNumberOfElectrons(i) << endl; +// } diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CalibCscStripFitter.h b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CalibCscStripFitter.h index 43b98f99270b..0ecab23df312 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CalibCscStripFitter.h +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CalibCscStripFitter.h @@ -10,62 +10,58 @@ // // Strip fitter using the parabolic fit fron the CSC calibration tool. -#include "CscClusterization/ICscStripFitter.h" +#include <string> +#include <vector> + #include "AthenaBaseComps/AthAlgTool.h" +#include "CscCalibTools/ICscCalibTool.h" +#include "CscClusterization/ICscStripFitter.h" #include "GaudiKernel/ServiceHandle.h" #include "GaudiKernel/ToolHandle.h" - #include "MuonIdHelpers/IMuonIdHelperSvc.h" -#include "CscCalibTools/ICscCalibTool.h" - -#include <vector> -#include <string> class CalibCscStripFitter : virtual public ICscStripFitter, public AthAlgTool { -public: // Ctors and dtor. - enum NoiseOption { - rms = 0, sigma, f001 - }; - - CalibCscStripFitter(std::string, std::string, const IInterface*); - - ~CalibCscStripFitter()=default; - -public: // AlgTool methods - - StatusCode initialize(); + public: // Ctors and dtor. + enum NoiseOption { rms = 0, sigma, f001 }; -public: // Interface methods + CalibCscStripFitter(std::string, std::string, const IInterface*); - // Tell compiler not to hide other fit methods. - using ICscStripFitter::fit; + ~CalibCscStripFitter() = default; - // Fit a list of sample charges using the calibration tool. - // If that fit fails, the peak channel is used. - // Result fit(const ChargeList& charges, double samplingTime, IdentifierHash& stripHashId ) const; - // Result fit(const ChargeList& charges, double samplingTime, Identifier& stripId ) const; - Result fit(const ChargeList& ChargeList, - double samplingTime, bool samplingPhase, Identifier& sid) const; + public: // AlgTool methods + StatusCode initialize(); -private: // data + public: // Interface methods + // Tell compiler not to hide other fit methods. + using ICscStripFitter::fit; - // Job options. - // double m_qerr; // Charge error for a successful fit. - double m_terr; // Time error for a succcessful fit. - // double m_qerr_fail; // Charge error for a failed fit. - double m_terr_fail; // Time error for a failed fit. - double m_qerrprop; // Charge calibration error - bool m_doCorrection; // Correction for para to bipolar - double m_chargeErrorScaler; // Charge error scaler + // Fit a list of sample charges using the calibration tool. + // If that fit fails, the peak channel is used. + // Result fit(const ChargeList& charges, double samplingTime, IdentifierHash& stripHashId ) const; + // Result fit(const ChargeList& charges, double samplingTime, Identifier& stripId ) const; + Result fit(const ChargeList& ChargeList, double samplingTime, bool samplingPhase, Identifier& sid) const; - std::string m_noiseOptionStr; - NoiseOption m_noiseOption; + private: // data + // Job options. + // double m_qerr; // Charge error for a successful fit. + double m_terr; // Time error for a succcessful fit. + // double m_qerr_fail; // Charge error for a failed fit. + double m_terr_fail; // Time error for a failed fit. + double m_qerrprop; // Charge calibration error + bool m_doCorrection; // Correction for para to bipolar + double m_chargeErrorScaler; // Charge error scaler - ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}; + std::string m_noiseOptionStr; + NoiseOption m_noiseOption; - ToolHandle<ICscCalibTool> m_cscCalibTool; + ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc{ + this, + "MuonIdHelperSvc", + "Muon::MuonIdHelperSvc/MuonIdHelperSvc", + }; + ToolHandle<ICscCalibTool> m_cscCalibTool; }; #endif diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscBipolarStripFitter.cxx b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscBipolarStripFitter.cxx index b014ff63c946..13f69995e5c4 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscBipolarStripFitter.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscBipolarStripFitter.cxx @@ -1,13 +1,14 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // CscBipolarStripFitter.cxx #include "CscBipolarStripFitter.h" + #include "CscCalibTools/ICscCalibTool.h" +#include "MuonIdHelpers/CscIdHelper.h" #include "MuonPrepRawData/CscStripPrepData.h" #include "MuonReadoutGeometry/MuonDetectorManager.h" -#include "MuonIdHelpers/CscIdHelper.h" /////////////////////////////////////////// // K. Nikolopoulos @@ -18,609 +19,596 @@ // // -using std::string; using Muon::CscStripPrepData; +using std::string; -typedef ICscStripFitter::Result Result; +typedef ICscStripFitter::Result Result; typedef ICscStripFitter::ChargeList ChargeList; //********************************************************************** -CscBipolarStripFitter:: -CscBipolarStripFitter(string type, string aname, const IInterface* parent) -: AthAlgTool(type, aname, parent), m_pmuon_detmgr(0), m_phelper(0), - m_cscCalibTool(""), m_n(0), m_n2(0), m_zmax(0), m_bipolarNormalization(0), - m_tsampling(0), m_powcachez(0), m_powcachezn(0) { - - declareInterface<ICscStripFitter>(this); - declareProperty("chargeError", m_qerr =5500.0); - declareProperty("timeError", m_terr =5.0); - declareProperty("failChargeError", m_qerr_fail =5000.0); - declareProperty("failTimeError", m_terr_fail =50.0); - declareProperty("chargeCalibrationError", m_qerrprop = 0.002); - declareProperty("cscCalibTool", m_cscCalibTool); +CscBipolarStripFitter::CscBipolarStripFitter(string type, string aname, const IInterface *parent) + : AthAlgTool(type, aname, parent), + m_pmuon_detmgr(0), + m_phelper(0), + m_cscCalibTool(""), + m_n(0), + m_n2(0), + m_zmax(0), + m_bipolarNormalization(0), + m_tsampling(0), + m_powcachez(0), + m_powcachezn(0) +{ + declareInterface<ICscStripFitter>(this); + declareProperty("chargeError", m_qerr = 5500.0); + declareProperty("timeError", m_terr = 5.0); + declareProperty("failChargeError", m_qerr_fail = 5000.0); + declareProperty("failTimeError", m_terr_fail = 50.0); + declareProperty("chargeCalibrationError", m_qerrprop = 0.002); + declareProperty("cscCalibTool", m_cscCalibTool); } //********************************************************************** -CscBipolarStripFitter::~CscBipolarStripFitter() { } +CscBipolarStripFitter::~CscBipolarStripFitter() {} //********************************************************************** -StatusCode CscBipolarStripFitter::initialize() { - - ATH_MSG_DEBUG ( "Initializing " << name() ); - - ATH_MSG_DEBUG ( "Properties for " << name() << ":" ); - ATH_MSG_DEBUG ( " Charge error: " << m_qerr ); - ATH_MSG_DEBUG ( " Time error: " << m_terr ); - ATH_MSG_DEBUG ( " Fail charge error: " << m_qerr_fail ); - ATH_MSG_DEBUG ( " Fail time error: " << m_terr_fail ); - ATH_MSG_DEBUG ( " Charge calibration error: " << m_qerrprop ); - - /** CSC calibratin tool for the Condtiions Data base access */ - if ( m_cscCalibTool.retrieve().isFailure()) { - ATH_MSG_ERROR ( "Can't get handle on CSC calibration tools" ); - return StatusCode::RECOVERABLE; - } - // Retrieve the detector descriptor. - if ( detStore()->retrieve(m_pmuon_detmgr).isFailure() ) { - ATH_MSG_ERROR ( " Cannot retrieve MuonGeoModel " ); - return StatusCode::RECOVERABLE; - } - ATH_MSG_DEBUG ( "Retrieved geometry." ); - m_phelper = m_pmuon_detmgr->cscIdHelper(); - - - m_n =m_cscCalibTool->getNumberOfIntegration();//12.; - m_n2 =m_cscCalibTool->getNumberOfIntegration2();//11.66; - m_powcachez = -9999.; - m_powcachezn= -9999.; - m_zmax= m_n+m_n2+2.-sqrt((m_n+2.+m_n2)*(m_n+2.+m_n2)-4.*m_n*(m_n2+1)); - m_zmax*=0.5; - //m_n+1 - sqrt(m_n+1.0); - m_bipolarNormalization = FindPow(m_zmax)*(1-m_zmax/(m_n2+1))*exp(-m_zmax); - // FindPow(m_zmax)*(1-m_zmax/(m_n+1))*exp(-m_zmax); - m_tsampling = m_cscCalibTool->getSamplingTime()/2.;// 50/2 = 25.; - - - return StatusCode::SUCCESS; +StatusCode +CscBipolarStripFitter::initialize() +{ + + ATH_MSG_DEBUG("Initializing " << name()); + + ATH_MSG_DEBUG("Properties for " << name() << ":"); + ATH_MSG_DEBUG(" Charge error: " << m_qerr); + ATH_MSG_DEBUG(" Time error: " << m_terr); + ATH_MSG_DEBUG(" Fail charge error: " << m_qerr_fail); + ATH_MSG_DEBUG(" Fail time error: " << m_terr_fail); + ATH_MSG_DEBUG(" Charge calibration error: " << m_qerrprop); + + /** CSC calibratin tool for the Condtiions Data base access */ + if (m_cscCalibTool.retrieve().isFailure()) { + ATH_MSG_ERROR("Can't get handle on CSC calibration tools"); + return StatusCode::RECOVERABLE; + } + // Retrieve the detector descriptor. + if (detStore()->retrieve(m_pmuon_detmgr).isFailure()) { + ATH_MSG_ERROR(" Cannot retrieve MuonGeoModel "); + return StatusCode::RECOVERABLE; + } + ATH_MSG_DEBUG("Retrieved geometry."); + m_phelper = m_pmuon_detmgr->cscIdHelper(); + + + m_n = m_cscCalibTool->getNumberOfIntegration(); // 12.; + m_n2 = m_cscCalibTool->getNumberOfIntegration2(); // 11.66; + m_powcachez = -9999.; + m_powcachezn = -9999.; + m_zmax = m_n + m_n2 + 2. - sqrt((m_n + 2. + m_n2) * (m_n + 2. + m_n2) - 4. * m_n * (m_n2 + 1)); + m_zmax *= 0.5; + // m_n+1 - sqrt(m_n+1.0); + m_bipolarNormalization = FindPow(m_zmax) * (1 - m_zmax / (m_n2 + 1)) * exp(-m_zmax); + // FindPow(m_zmax)*(1-m_zmax/(m_n+1))*exp(-m_zmax); + m_tsampling = m_cscCalibTool->getSamplingTime() / 2.; // 50/2 = 25.; + + + return StatusCode::SUCCESS; } //********************************************************************** -StatusCode CscBipolarStripFitter::finalize() { - ATH_MSG_DEBUG ( "Finalizing " << name() ); - return StatusCode::SUCCESS; +StatusCode +CscBipolarStripFitter::finalize() +{ + ATH_MSG_DEBUG("Finalizing " << name()); + return StatusCode::SUCCESS; } //********************************************************************** -Result CscBipolarStripFitter::fit(const ChargeList& chgs, double period, Identifier& stripId) const { +Result +CscBipolarStripFitter::fit(const ChargeList &chgs, double period, Identifier &stripId) const +{ - ATH_MSG_DEBUG ( "Fitting with sample time " << period ); - ATH_MSG_DEBUG ( " Number of charges =" << chgs.size() << " Charges: " << chgs ); - Result res; + ATH_MSG_DEBUG("Fitting with sample time " << period); + ATH_MSG_DEBUG(" Number of charges =" << chgs.size() << " Charges: " << chgs); + Result res; IdentifierHash stripHash; - if (m_phelper->get_channel_hash(stripId, stripHash)){ - ATH_MSG_WARNING ( "Unable to get CSC striphash id " << " the identifier is " ); - stripId.show(); - } - ATH_MSG_DEBUG ( "CalibCscStripFitter:: "<< stripId << " " << (unsigned int) stripHash ); - - - ////// double m_x[4]; - ////// for(unsigned int i=0;i<chgs.size();i++) { - ////// m_x[i] = chgs[i]; - ////// } - double initValues[3]; - for (int i=0; i<3; ++i) { - initValues[i] =0.; - } - // int imax = -1; - initValues[2]= 8.;//m_width - ////// double samplemax = FindInitValues(m_x,initValues,&imax); - - double noise = m_cscCalibTool->stripNoise(stripHash); - res.status = 0; - if (m_qerr > 0) - res.dcharge = m_qerr; - else - res.dcharge = noise; - - res.dtime = m_terr; - res.charge = initValues[0]; - res.time = initValues[1]; - - initValues[1] = res.time - 2.5; - // int imeas =4; - // int meas[4] = {true,true,true,true}; - // int ipar = 3; - // int par[3] = {true,true,false}; - // double m_chi2; - double result[3]; - ////// int FitStatus = TheFitter(m_x,noise,initValues,imeas,meas,ipar,par,&m_chi2,result); - - // Add an error proportional to the charge. - double dqprop = m_qerrprop*res.charge; - res.dcharge = sqrt(res.dcharge*res.dcharge + dqprop*dqprop); - // Display result. - ATH_MSG_DEBUG ( " Status: " << res.status ); - ATH_MSG_DEBUG ( " Charge: " << res.charge ); - ATH_MSG_DEBUG ( " Charge err: " << res.dcharge ); - ATH_MSG_DEBUG ( " Time: " << res.time ); - ATH_MSG_DEBUG ( " fit : " << result[0] << " "<< result[1] << " "<< result[2] ); - return res; + if (m_phelper->get_channel_hash(stripId, stripHash)) { + ATH_MSG_WARNING("Unable to get CSC striphash id " + << " the identifier is "); + stripId.show(); + } + ATH_MSG_DEBUG("CalibCscStripFitter:: " << stripId << " " << (unsigned int)stripHash); + + + ////// double m_x[4]; + ////// for(unsigned int i=0;i<chgs.size();i++) { + ////// m_x[i] = chgs[i]; + ////// } + double initValues[3]; + for (int i = 0; i < 3; ++i) { + initValues[i] = 0.; + } + // int imax = -1; + initValues[2] = 8.; // m_width + ////// double samplemax = FindInitValues(m_x,initValues,&imax); + + double noise = m_cscCalibTool->stripNoise(stripHash); + res.status = 0; + if (m_qerr > 0) + res.dcharge = m_qerr; + else + res.dcharge = noise; + + res.dtime = m_terr; + res.charge = initValues[0]; + res.time = initValues[1]; + + initValues[1] = res.time - 2.5; + // int imeas =4; + // int meas[4] = {true,true,true,true}; + // int ipar = 3; + // int par[3] = {true,true,false}; + // double m_chi2; + double result[3]; + ////// int FitStatus = TheFitter(m_x,noise,initValues,imeas,meas,ipar,par,&m_chi2,result); + + // Add an error proportional to the charge. + double dqprop = m_qerrprop * res.charge; + res.dcharge = sqrt(res.dcharge * res.dcharge + dqprop * dqprop); + // Display result. + ATH_MSG_DEBUG(" Status: " << res.status); + ATH_MSG_DEBUG(" Charge: " << res.charge); + ATH_MSG_DEBUG(" Charge err: " << res.dcharge); + ATH_MSG_DEBUG(" Time: " << res.time); + ATH_MSG_DEBUG(" fit : " << result[0] << " " << result[1] << " " << result[2]); + return res; } -double CscBipolarStripFitter::FindInitValues(double *x,double *initValues,int *maxsample) const{ - // find maximum sample imax: - double peakingTime=-99.; // interpolated peaking time in samples - double amplitude=-99.; // interpolated amplitude - double amin, amax; - int imax = 0; - const int numSample=4; - amax = x[0]; - amin = x[0]; - for(int j=1; j<numSample; j++) - { - if(amax<x[j]) - { - amax = x[j]; - imax = j; - } - if(amin>x[j]) - amin = x[j]; +double +CscBipolarStripFitter::FindInitValues(double *x, double *initValues, int *maxsample) const +{ + // find maximum sample imax: + double peakingTime = -99.; // interpolated peaking time in samples + double amplitude = -99.; // interpolated amplitude + double amin, amax; + int imax = 0; + const int numSample = 4; + amax = x[0]; + amin = x[0]; + for (int j = 1; j < numSample; j++) { + if (amax < x[j]) { + amax = x[j]; + imax = j; + } + if (amin > x[j]) amin = x[j]; } - - // calculate peak and amplitude: - (*maxsample)=imax; - if((imax==0) || (imax==numSample-1)) // no interpolation possible + + // calculate peak and amplitude: + (*maxsample) = imax; + if ((imax == 0) || (imax == numSample - 1)) // no interpolation possible { - peakingTime = imax; - amplitude = amax; - } - else // do parabolic interpolation - { - double a, b, c; // coeffients of parabola y=a*x*x+b*x+c - a = 0.5*(x[imax+1]+x[imax-1]-2.0*x[imax]); - b = 0.5*(x[imax+1]-x[imax-1]); - c = x[imax]; - - peakingTime = -0.5*b/a; - amplitude = a*peakingTime*peakingTime + b*peakingTime + c; - peakingTime += imax; // it was relative to imax + peakingTime = imax; + amplitude = amax; + } else // do parabolic interpolation + { + double a, b, c; // coeffients of parabola y=a*x*x+b*x+c + a = 0.5 * (x[imax + 1] + x[imax - 1] - 2.0 * x[imax]); + b = 0.5 * (x[imax + 1] - x[imax - 1]); + c = x[imax]; + + peakingTime = -0.5 * b / a; + amplitude = a * peakingTime * peakingTime + b * peakingTime + c; + peakingTime += imax; // it was relative to imax } - initValues[0] = amplitude; - initValues[1] = peakingTime; - // - m_zmax*initValues[2]/m_tsampling; - return x[imax]; + initValues[0] = amplitude; + initValues[1] = peakingTime; + // - m_zmax*initValues[2]/m_tsampling; + return x[imax]; } -double +double CscBipolarStripFitter::FindPow(double z) const { - if(fabs(m_powcachez-z)<1.e-4) - return m_powcachezn; - - //double zpower = z*z*z; - //zpower *= zpower; - //zpower *= zpower; - double zpower = exp(m_n*log(z)); - m_powcachez = z; - m_powcachezn= zpower; - return zpower; + if (fabs(m_powcachez - z) < 1.e-4) return m_powcachezn; + + // double zpower = z*z*z; + // zpower *= zpower; + // zpower *= zpower; + double zpower = exp(m_n * log(z)); + m_powcachez = z; + m_powcachezn = zpower; + return zpower; } -void -CscBipolarStripFitter::InvertMatrix(double matrix[][3],const int dim,int*correspdim) const +void +CscBipolarStripFitter::InvertMatrix(double matrix[][3], const int dim, int *correspdim) const { - // invert 2x2 or 3x3 symmetric matrix - if(dim==1) - { - int ii=correspdim[0]; - matrix[ii][ii] = 1./matrix[ii][ii]; - - } - else if(dim==2) - { - int ii=correspdim[0]; - int jj=correspdim[1]; - double determinant= -matrix[jj][ii]*matrix[ii][jj] +matrix[ii][ii]*matrix[jj][jj]; - //if(fabs(determinant)<1.e-13) - //std::cout<<" zero determinant "<<std::endl; - double i00 = matrix[ii][ii]; - matrix[ii][ii] = matrix[jj][jj]/determinant; - matrix[jj][jj] = i00/determinant; - matrix[ii][jj] = -matrix[ii][jj]/determinant; - matrix[jj][ii] = matrix[ii][jj]; - - } - else if(dim==3) - { - double sm12 = matrix[0][1]*matrix[0][1]; - double sm13 = matrix[0][2]*matrix[0][2]; - double sm23 = matrix[1][2]*matrix[1][2]; - double determinant = matrix[0][0]*matrix[1][1]*matrix[2][2] - -matrix[0][0]*sm23-sm12*matrix[2][2] - +2.*matrix[0][1]*matrix[0][2]*matrix[1][2] - -matrix[1][1]*sm13; - - //if(fabs(determinant)<1.e-13) - //std::cout << "zero determinant"<<std::endl; - double i00 = matrix[1][1]*matrix[2][2]-sm23; - double i11 = matrix[0][0]*matrix[2][2]-sm13; - double i22 = matrix[0][0]*matrix[1][1]-sm12; - - matrix[1][0] = (matrix[0][2]*matrix[1][2]-matrix[2][2]*matrix[0][1])/determinant; - matrix[2][0] = (matrix[0][1]*matrix[1][2]-matrix[0][2]*matrix[1][1])/determinant; - matrix[2][1] = (matrix[0][1]*matrix[0][2]-matrix[0][0]*matrix[1][2])/determinant; - matrix[0][1] = matrix[1][0]; - matrix[0][2] = matrix[2][0]; - matrix[1][2] = matrix[2][1]; - matrix[0][0] = i00/determinant; - matrix[1][1] = i11/determinant; - matrix[2][2] = i22/determinant; - - } - else - { - //int ierr; - //matrix.invert(ierr); - printf("this is not a 1x1 or 2x2 or 3x3 matrix\n"); + // invert 2x2 or 3x3 symmetric matrix + if (dim == 1) { + int ii = correspdim[0]; + matrix[ii][ii] = 1. / matrix[ii][ii]; + + } else if (dim == 2) { + int ii = correspdim[0]; + int jj = correspdim[1]; + double determinant = -matrix[jj][ii] * matrix[ii][jj] + matrix[ii][ii] * matrix[jj][jj]; + // if(fabs(determinant)<1.e-13) + // std::cout<<" zero determinant "<<std::endl; + double i00 = matrix[ii][ii]; + matrix[ii][ii] = matrix[jj][jj] / determinant; + matrix[jj][jj] = i00 / determinant; + matrix[ii][jj] = -matrix[ii][jj] / determinant; + matrix[jj][ii] = matrix[ii][jj]; + + } else if (dim == 3) { + double sm12 = matrix[0][1] * matrix[0][1]; + double sm13 = matrix[0][2] * matrix[0][2]; + double sm23 = matrix[1][2] * matrix[1][2]; + double determinant = matrix[0][0] * matrix[1][1] * matrix[2][2] - matrix[0][0] * sm23 - sm12 * matrix[2][2] + + 2. * matrix[0][1] * matrix[0][2] * matrix[1][2] - matrix[1][1] * sm13; + + // if(fabs(determinant)<1.e-13) + // std::cout << "zero determinant"<<std::endl; + double i00 = matrix[1][1] * matrix[2][2] - sm23; + double i11 = matrix[0][0] * matrix[2][2] - sm13; + double i22 = matrix[0][0] * matrix[1][1] - sm12; + + matrix[1][0] = (matrix[0][2] * matrix[1][2] - matrix[2][2] * matrix[0][1]) / determinant; + matrix[2][0] = (matrix[0][1] * matrix[1][2] - matrix[0][2] * matrix[1][1]) / determinant; + matrix[2][1] = (matrix[0][1] * matrix[0][2] - matrix[0][0] * matrix[1][2]) / determinant; + matrix[0][1] = matrix[1][0]; + matrix[0][2] = matrix[2][0]; + matrix[1][2] = matrix[2][1]; + matrix[0][0] = i00 / determinant; + matrix[1][1] = i11 / determinant; + matrix[2][2] = i22 / determinant; + + } else { + // int ierr; + // matrix.invert(ierr); + printf("this is not a 1x1 or 2x2 or 3x3 matrix\n"); } } -void +void CscBipolarStripFitter::InvertSymmetric4x4(double W[][4]) const { - double Determinant = W[0][3]*W[0][3]*W[1][2]*W[1][2] - 2.*W[0][2]*W[0][3]*W[1][2]*W[1][3] - +W[0][2]*W[0][2]*W[1][3]*W[1][3]-W[0][3]*W[0][3]*W[1][1]*W[2][2] + 2.*W[0][1]*W[0][3]*W[1][3]*W[2][2] - W[0][0]*W[1][3]*W[1][3]*W[2][2]+2.*W[0][2]*W[0][3]*W[1][1]*W[2][3] - - 2.*W[0][1]*W[0][3]*W[1][2]*W[2][3] - 2.*W[0][1]*W[0][2]*W[1][3]*W[2][3]+2.*W[0][0]*W[1][2]*W[1][3]*W[2][3]+W[0][1]*W[0][1]*W[2][3]*W[2][3]-W[0][0]*W[1][1]*W[2][3]*W[2][3]-W[0][2]*W[0][2]*W[1][1]*W[3][3]+2.*W[0][1]*W[0][2]*W[1][2]*W[3][3]-W[0][0]*W[1][2]*W[1][2]*W[3][3]-W[0][1]*W[0][1]*W[2][2]*W[3][3]+W[0][0]*W[1][1]*W[2][2]*W[3][3]; - - W[0][1] = W[3][0]*W[3][1]*W[2][2]-W[3][0]*W[2][1]*W[3][2] - W[2][0]*W[3][1]*W[3][2]+W[1][0]*W[3][2]*W[3][2]+W[2][0]*W[2][1]*W[3][3]-W[1][0]*W[2][2]*W[3][3]; - W[0][2] = -W[3][0]*W[2][1]*W[3][1]+W[2][0]*W[3][1]*W[3][1]+W[3][0]*W[1][1]*W[3][2]-W[1][0]*W[3][1]*W[3][2]-W[2][0]*W[1][1]*W[3][3]+W[1][0]*W[2][1]*W[3][3]; - W[0][3] = W[3][0]*W[2][1]*W[2][1]-W[2][0]*W[2][1]*W[3][1]-W[3][0]*W[1][1]*W[2][2]+W[1][0]*W[3][1]*W[2][2]+W[2][0]*W[1][1]*W[3][2]-W[1][0]*W[2][1]*W[3][2]; - W[1][2] = W[3][0]*W[3][0]*W[2][1]-W[2][0]*W[3][0]*W[3][1]-W[1][0]*W[3][0]*W[3][2]+W[0][0]*W[3][1]*W[3][2]+W[1][0]*W[2][0]*W[3][3]-W[0][0]*W[2][1]*W[3][3]; - - W[1][3] = -W[2][0]*W[3][0]*W[2][1]+W[2][0]*W[2][0]*W[3][1]+W[1][0]*W[3][0]*W[2][2]-W[0][0]*W[3][1]*W[2][2]-W[1][0]*W[2][0]*W[3][2]+W[0][0]*W[2][1]*W[3][2]; - W[2][3] = W[2][0]*W[3][0]*W[1][1]-W[1][0]*W[3][0]*W[2][1]-W[1][0]*W[2][0]*W[3][1]+W[0][0]*W[2][1]*W[3][1]+W[1][0]*W[1][0]*W[3][2]-W[0][0]*W[1][1]*W[3][2]; - - double W00 = -W[3][1]*W[3][1]*W[2][2]+2.*W[2][1]*W[3][1]*W[3][2]-W[1][1]*W[3][2]*W[3][2]-W[2][1]*W[2][1]*W[3][3]+W[1][1]*W[2][2]*W[3][3]; - double W11 = -W[3][0]*W[3][0]*W[2][2]+2.*W[2][0]*W[3][0]*W[3][2]-W[0][0]*W[3][2]*W[3][2]-W[2][0]*W[2][0]*W[3][3]+W[0][0]*W[2][2]*W[3][3]; - double W22 = -W[3][0]*W[3][0]*W[1][1]+2.*W[1][0]*W[3][0]*W[3][1]-W[0][0]*W[3][1]*W[3][1]-W[1][0]*W[1][0]*W[3][3]+W[0][0]*W[1][1]*W[3][3]; - double W33 = -W[2][0]*W[2][0]*W[1][1]+2.*W[1][0]*W[2][0]*W[2][1]-W[0][0]*W[2][1]*W[2][1]-W[1][0]*W[1][0]*W[2][2]+W[0][0]*W[1][1]*W[2][2]; - - for(int i=0;i<3;i++) - { - for(int j=1;j<4;j++) - { - if(i>=j) - continue; - W[i][j] = W[i][j]/Determinant; - W[j][i] = W[i][j]; - } + double Determinant = W[0][3] * W[0][3] * W[1][2] * W[1][2] - 2. * W[0][2] * W[0][3] * W[1][2] * W[1][3] + + W[0][2] * W[0][2] * W[1][3] * W[1][3] - W[0][3] * W[0][3] * W[1][1] * W[2][2] + + 2. * W[0][1] * W[0][3] * W[1][3] * W[2][2] - W[0][0] * W[1][3] * W[1][3] * W[2][2] + + 2. * W[0][2] * W[0][3] * W[1][1] * W[2][3] - 2. * W[0][1] * W[0][3] * W[1][2] * W[2][3] + - 2. * W[0][1] * W[0][2] * W[1][3] * W[2][3] + 2. * W[0][0] * W[1][2] * W[1][3] * W[2][3] + + W[0][1] * W[0][1] * W[2][3] * W[2][3] - W[0][0] * W[1][1] * W[2][3] * W[2][3] + - W[0][2] * W[0][2] * W[1][1] * W[3][3] + 2. * W[0][1] * W[0][2] * W[1][2] * W[3][3] + - W[0][0] * W[1][2] * W[1][2] * W[3][3] - W[0][1] * W[0][1] * W[2][2] * W[3][3] + + W[0][0] * W[1][1] * W[2][2] * W[3][3]; + + W[0][1] = W[3][0] * W[3][1] * W[2][2] - W[3][0] * W[2][1] * W[3][2] - W[2][0] * W[3][1] * W[3][2] + + W[1][0] * W[3][2] * W[3][2] + W[2][0] * W[2][1] * W[3][3] - W[1][0] * W[2][2] * W[3][3]; + W[0][2] = -W[3][0] * W[2][1] * W[3][1] + W[2][0] * W[3][1] * W[3][1] + W[3][0] * W[1][1] * W[3][2] + - W[1][0] * W[3][1] * W[3][2] - W[2][0] * W[1][1] * W[3][3] + W[1][0] * W[2][1] * W[3][3]; + W[0][3] = W[3][0] * W[2][1] * W[2][1] - W[2][0] * W[2][1] * W[3][1] - W[3][0] * W[1][1] * W[2][2] + + W[1][0] * W[3][1] * W[2][2] + W[2][0] * W[1][1] * W[3][2] - W[1][0] * W[2][1] * W[3][2]; + W[1][2] = W[3][0] * W[3][0] * W[2][1] - W[2][0] * W[3][0] * W[3][1] - W[1][0] * W[3][0] * W[3][2] + + W[0][0] * W[3][1] * W[3][2] + W[1][0] * W[2][0] * W[3][3] - W[0][0] * W[2][1] * W[3][3]; + + W[1][3] = -W[2][0] * W[3][0] * W[2][1] + W[2][0] * W[2][0] * W[3][1] + W[1][0] * W[3][0] * W[2][2] + - W[0][0] * W[3][1] * W[2][2] - W[1][0] * W[2][0] * W[3][2] + W[0][0] * W[2][1] * W[3][2]; + W[2][3] = W[2][0] * W[3][0] * W[1][1] - W[1][0] * W[3][0] * W[2][1] - W[1][0] * W[2][0] * W[3][1] + + W[0][0] * W[2][1] * W[3][1] + W[1][0] * W[1][0] * W[3][2] - W[0][0] * W[1][1] * W[3][2]; + + double W00 = -W[3][1] * W[3][1] * W[2][2] + 2. * W[2][1] * W[3][1] * W[3][2] - W[1][1] * W[3][2] * W[3][2] + - W[2][1] * W[2][1] * W[3][3] + W[1][1] * W[2][2] * W[3][3]; + double W11 = -W[3][0] * W[3][0] * W[2][2] + 2. * W[2][0] * W[3][0] * W[3][2] - W[0][0] * W[3][2] * W[3][2] + - W[2][0] * W[2][0] * W[3][3] + W[0][0] * W[2][2] * W[3][3]; + double W22 = -W[3][0] * W[3][0] * W[1][1] + 2. * W[1][0] * W[3][0] * W[3][1] - W[0][0] * W[3][1] * W[3][1] + - W[1][0] * W[1][0] * W[3][3] + W[0][0] * W[1][1] * W[3][3]; + double W33 = -W[2][0] * W[2][0] * W[1][1] + 2. * W[1][0] * W[2][0] * W[2][1] - W[0][0] * W[2][1] * W[2][1] + - W[1][0] * W[1][0] * W[2][2] + W[0][0] * W[1][1] * W[2][2]; + + for (int i = 0; i < 3; i++) { + for (int j = 1; j < 4; j++) { + if (i >= j) continue; + W[i][j] = W[i][j] / Determinant; + W[j][i] = W[i][j]; + } } - W[0][0] = W00/Determinant; - W[1][1] = W11/Determinant; - W[2][2] = W22/Determinant; - W[3][3] = W33/Determinant; + W[0][0] = W00 / Determinant; + W[1][1] = W11 / Determinant; + W[2][2] = W22 / Determinant; + W[3][3] = W33 / Determinant; } -void -CscBipolarStripFitter::Derivative(double A[][3],double fp[][1], double p0[][1],int imeas, int*meas) const +void +CscBipolarStripFitter::Derivative(double A[][3], double fp[][1], double p0[][1], int imeas, int *meas) const { - //calculate the derivatives and the 0th order approximation - //around the ADC samplings - double norm = p0[0][0]; - //double parm[3]={1.,p0[1][0],p0[2][0]}; - for(int i=0;i<imeas;i++) - { - int ii = meas[i]; - double z = (ii-p0[1][0])*m_tsampling/p0[2][0]; - double repquant = 0.; - double dFdzNormalized = 0.; - if(z>0.) - { - repquant = FindPow(z)*exp(-z)/m_bipolarNormalization; - dFdzNormalized= repquant*(m_n/z+z/(m_n2+1)-(m_n+1.)/(m_n2+1.)-1.);//repquant*(m_n/z+z/(m_n+1)-2.); - } - - A[ii][0] = repquant*(1.-z/(m_n2+1.));//repquant*(1.-z/(m_n+1.)); - //A[ii][0] = bipolar(&z,parm); - fp[ii][0] = norm * A[ii][0]; - - //double normOverZmax = norm/m_bipolarNormalization; - double commonpart = norm* dFdzNormalized;//(z,parm); - A[ii][1] = commonpart * (-m_tsampling/p0[2][0]); - A[ii][2] = commonpart * (-z/p0[2][0]); + // calculate the derivatives and the 0th order approximation + // around the ADC samplings + double norm = p0[0][0]; + // double parm[3]={1.,p0[1][0],p0[2][0]}; + for (int i = 0; i < imeas; i++) { + int ii = meas[i]; + double z = (ii - p0[1][0]) * m_tsampling / p0[2][0]; + double repquant = 0.; + double dFdzNormalized = 0.; + if (z > 0.) { + repquant = FindPow(z) * exp(-z) / m_bipolarNormalization; + dFdzNormalized = + repquant + * (m_n / z + z / (m_n2 + 1) - (m_n + 1.) / (m_n2 + 1.) - 1.); // repquant*(m_n/z+z/(m_n+1)-2.); + } + + A[ii][0] = repquant * (1. - z / (m_n2 + 1.)); // repquant*(1.-z/(m_n+1.)); + // A[ii][0] = bipolar(&z,parm); + fp[ii][0] = norm * A[ii][0]; + + // double normOverZmax = norm/m_bipolarNormalization; + double commonpart = norm * dFdzNormalized; //(z,parm); + A[ii][1] = commonpart * (-m_tsampling / p0[2][0]); + A[ii][2] = commonpart * (-z / p0[2][0]); } - // end of derivative/zeroth order calculations + // end of derivative/zeroth order calculations } int -CscBipolarStripFitter::TheFitter(double*x,const double ex,double *initValues, int imeas, int *meas, int ipar, int *par,double *chi2,double *result) const +CscBipolarStripFitter::TheFitter(double *x, const double ex, double *initValues, int imeas, int *meas, int ipar, + int *par, double *chi2, double *result) const { - // maximum iterations - const int maxIter = 7; - // tolerances - double fitTolerance0 = 0.1; - double fitTolerance1 = 0.01; - //CLHEP::HepMatrix p0(3,1,0); // the matrix of the initial fit parameters - double p0[3][1]; - for(int j=0;j<3;j++) - p0[j][0] = initValues[j]; - - //CLHEP::HepMatrix m(4,1,0); // the matrix of ADC measurements (samples: 0,1,2,3) - double m[4][1]; - //CLHEP::HepMatrix W(4,4,0); // the error matrix of the ADC measurements - double W[4][4]; - for(int i=0;i<4;i++) { - m[i][0] = x[i]; - W[i][i] = ex*ex; - } - // covariances - W[0][1] = 0.03*ex*ex; - W[0][2] = -0.411*ex*ex; - W[0][3] = -0.188*ex*ex; - W[1][2] = 0.0275*ex*ex; - W[1][3] = -0.4303*ex*ex; - W[2][3] = 0.*ex*ex; - W[1][0] = W[0][1]; - W[2][0] = W[0][2]; - W[3][0] = W[0][3]; - W[2][1] = W[1][2]; - W[3][1] = W[1][3]; - W[3][2] = W[2][3]; - - //WW.invert(ierr); - InvertSymmetric4x4(W); - - // Taylor expansion of the bipolar pulse model around the - // samplings : F(x) = F(p0) + A *(p-p0) + higher.order - //CLHEP::HepMatrix fp(4,1,0); // the matrix of 0th order approximation - double fp[4][1]; - //CLHEP::HepMatrix A(4,3,0); // the matrix of derivatives - double A[4][3]; - for (int i=0; i<4; ++i) { - fp[i][0] =0.; - for (int j=0; j<3; ++j) { - A[i][j] =0.; + // maximum iterations + const int maxIter = 7; + // tolerances + double fitTolerance0 = 0.1; + double fitTolerance1 = 0.01; + // CLHEP::HepMatrix p0(3,1,0); // the matrix of the initial fit parameters + double p0[3][1]; + for (int j = 0; j < 3; j++) p0[j][0] = initValues[j]; + + // CLHEP::HepMatrix m(4,1,0); // the matrix of ADC measurements (samples: 0,1,2,3) + double m[4][1]; + // CLHEP::HepMatrix W(4,4,0); // the error matrix of the ADC measurements + double W[4][4]; + for (int i = 0; i < 4; i++) { + m[i][0] = x[i]; + W[i][i] = ex * ex; } - } - // remarks : - // if the pulse peaks in the last sampling fit with a constant shaping time - // if the pulse peaks in the first sampling fit without using the last sampling - // (too large contribution to the chi2 - int counter=0; - bool converged=false; - double amplitudeChangeOld = 0.; - bool diverganceCandidate = false; - //CLHEP::HepMatrix weight(3,3,1); // weight matrix allocated once - // the non-fitted parts are taken care appropriately - // at least if the fitting parameters or measurements - // don't change during the fitting procedure - double weight[3][3]; - - //CLHEP::HepMatrix residFactor(3,4,0); // residFactor allocated once - double residFactor[3][4]; - - for (int i=0; i<3; ++i) { - for (int j=0; j<4; ++j) { - if (j<3) { - weight[i][j] =0.; - } - residFactor[i][j] =0.; + // covariances + W[0][1] = 0.03 * ex * ex; + W[0][2] = -0.411 * ex * ex; + W[0][3] = -0.188 * ex * ex; + W[1][2] = 0.0275 * ex * ex; + W[1][3] = -0.4303 * ex * ex; + W[2][3] = 0. * ex * ex; + W[1][0] = W[0][1]; + W[2][0] = W[0][2]; + W[3][0] = W[0][3]; + W[2][1] = W[1][2]; + W[3][1] = W[1][3]; + W[3][2] = W[2][3]; + + // WW.invert(ierr); + InvertSymmetric4x4(W); + + // Taylor expansion of the bipolar pulse model around the + // samplings : F(x) = F(p0) + A *(p-p0) + higher.order + // CLHEP::HepMatrix fp(4,1,0); // the matrix of 0th order approximation + double fp[4][1]; + // CLHEP::HepMatrix A(4,3,0); // the matrix of derivatives + double A[4][3]; + for (int i = 0; i < 4; ++i) { + fp[i][0] = 0.; + for (int j = 0; j < 3; ++j) { + A[i][j] = 0.; + } + } + // remarks : + // if the pulse peaks in the last sampling fit with a constant shaping time + // if the pulse peaks in the first sampling fit without using the last sampling + // (too large contribution to the chi2 + int counter = 0; + bool converged = false; + double amplitudeChangeOld = 0.; + bool diverganceCandidate = false; + // CLHEP::HepMatrix weight(3,3,1); // weight matrix allocated once + // the non-fitted parts are taken care appropriately + // at least if the fitting parameters or measurements + // don't change during the fitting procedure + double weight[3][3]; + + // CLHEP::HepMatrix residFactor(3,4,0); // residFactor allocated once + double residFactor[3][4]; + + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 4; ++j) { + if (j < 3) { + weight[i][j] = 0.; + } + residFactor[i][j] = 0.; + } } - } - weight[0][0]=1.; - weight[1][1]=1.; - weight[2][2]=1.; + weight[0][0] = 1.; + weight[1][1] = 1.; + weight[2][2] = 1.; - while(!converged && counter<maxIter) // fit loop + while (!converged && counter < maxIter) // fit loop { - Derivative(A,fp,p0,imeas,meas);// calculate the matrix of derivatives and 0th order approximation - // matrix multiplication - // the weight matrix is symmetric - // weight= A.T()*W*A;//.assign(A.T()*W*A); - - double helpmatrix[4][3]; - for (int i=0; i<4; ++i) { - for (int j=0; j<3; ++j) { - helpmatrix[i][j] =0.; + Derivative(A, fp, p0, imeas, meas); // calculate the matrix of derivatives and 0th order approximation + // matrix multiplication + // the weight matrix is symmetric + // weight= A.T()*W*A;//.assign(A.T()*W*A); + + double helpmatrix[4][3]; + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 3; ++j) { + helpmatrix[i][j] = 0.; + } } - } - - for(int i=0;i<imeas;i++) - { - int ii=meas[i]; - for(int j=0;j<ipar;j++) - { - int jj=par[j]; - for(int k=0;k<imeas;k++) - { - int kk=meas[k]; - helpmatrix[ii][jj] += W[ii][kk]*A[kk][jj]; - } - } - } - for(int i=0;i<ipar;i++) - { - int ii=par[i]; - for(int j=i;j<ipar;j++) - { - int jj=par[j]; - weight[ii][jj] = 0.; - for(int k=0;k<imeas;k++) - { - int kk=meas[k]; - weight[ii][jj] += A[kk][ii]*helpmatrix[kk][jj];//A[kk][ii]*A[kk][jj]; - } - //weight[ii][jj]*=W[0][0]; - weight[jj][ii] =weight[ii][jj]; - } - } - //weight.invert(ierr); // inversion of weight matrix - // hand-made inversion of 2x2 or 3x3 symmetric matrix - InvertMatrix(weight,ipar,par); - - //calculate W*(A.T()*W) - //residFactor = weight*(A.T()*W); - double helpmatrix2[3][4]; - for (int i=0; i<3; ++i) { - for (int j=0; j<4; ++j) { - helpmatrix2[i][j] =0.; + + for (int i = 0; i < imeas; i++) { + int ii = meas[i]; + for (int j = 0; j < ipar; j++) { + int jj = par[j]; + for (int k = 0; k < imeas; k++) { + int kk = meas[k]; + helpmatrix[ii][jj] += W[ii][kk] * A[kk][jj]; + } + } + } + for (int i = 0; i < ipar; i++) { + int ii = par[i]; + for (int j = i; j < ipar; j++) { + int jj = par[j]; + weight[ii][jj] = 0.; + for (int k = 0; k < imeas; k++) { + int kk = meas[k]; + weight[ii][jj] += A[kk][ii] * helpmatrix[kk][jj]; // A[kk][ii]*A[kk][jj]; + } + // weight[ii][jj]*=W[0][0]; + weight[jj][ii] = weight[ii][jj]; + } + } + // weight.invert(ierr); // inversion of weight matrix + // hand-made inversion of 2x2 or 3x3 symmetric matrix + InvertMatrix(weight, ipar, par); + + // calculate W*(A.T()*W) + // residFactor = weight*(A.T()*W); + double helpmatrix2[3][4]; + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 4; ++j) { + helpmatrix2[i][j] = 0.; + } } - } - for(int i=0;i<ipar;i++) - { - int ii=par[i]; - for(int j=0;j<imeas;j++) - { - int jj=meas[j]; - for(int k=0;k<imeas;k++) - { - int kk=meas[k]; - helpmatrix2[ii][jj] += A[kk][ii] * W[kk][jj]; - } - } - } - - for(int i=0;i<ipar;i++) - { - int ii = par[i]; - for(int j=0;j<imeas;j++) - { - int jj=meas[j]; - residFactor[ii][jj]=0.; - for(int k=0;k<ipar;k++) - { - int kk=par[k]; - residFactor[ii][jj] += weight[ii][kk]*helpmatrix2[kk][jj]; - } - //residFactor[ii][jj]*=W[0][0]; - } - } - - double paramDiff[3]; - for (int i=0; i<3; ++i) { - paramDiff[i] = 0.; - } - - for(int i=0;i<ipar;i++) - { - int ii=par[i]; - //estimation of new parameters - //paramDiff[i][0] += (weight*(A.T()*W)*(m-fp))[i][0]; - for(int j=0;j<imeas;j++) - { - int jj = meas[j]; - paramDiff[ii] += residFactor[ii][jj]*(m[jj][0]-fp[jj][0]); - } - p0[ii][0] += paramDiff[ii]; - } - std::cout << "##### "<<p0[0][0]<< " "<<p0[1][0] << " "<<p0[2][0]<<std::endl; - // if the parameters are not physical, keep them sensible - //if peaking time less than -0.5 - double peakingTime = p0[1][0] + m_zmax*p0[2][0]/m_tsampling; - if(peakingTime<-0.5 || peakingTime>3.) - p0[1][0] = initValues[1]; - - if(p0[0][0]<0.) - p0[0][0] = initValues[0]; - double amplitudeChangeNew = fabs(paramDiff[0]); - if(fabs(paramDiff[0])<fitTolerance0 && fabs(paramDiff[1])<fitTolerance1) - { - converged = true; - // calculate chi2 - // (m-fp).T()*W*(m-fp) - double residual[4]; - for (int i=0; i<4; ++i) { - residual[i] = 0.; - } - - for(int i=0;i<imeas;i++) - { - int ii=meas[i]; - residual[i] = m[ii][0]-fp[ii][0]; - } - - double tmpChi2 = 0.; - double helpmatrixchi2[4][1]; - for (int i=0; i<4; ++i) { - helpmatrixchi2[i][0] = 0.; - } - for(int i=0;i<imeas;i++) - { - int ii=meas[i]; - for(int k=0;k<imeas;k++) - { - int kk=meas[k]; - helpmatrixchi2[ii][0] += W[ii][kk]*residual[kk]; - } - } - for(int k=0;k<imeas;k++) - { - int kk=meas[k]; - tmpChi2 += residual[kk]*helpmatrixchi2[kk][0]; - //std::cout << residual[kk] << " ";//*W[kk][kk]*residual[kk]<< " "; - } - // std::cout<<std::endl; - (*chi2) = tmpChi2; - } - else if(counter>4 && (amplitudeChangeNew>4.*amplitudeChangeOld)) - { - if(diverganceCandidate) - { - //diverging fit - //return parabola interpolation - printf("%3.2f %3.2f %3.2f %3.2f\n ", x[0],x[1],x[2],x[3]); - printf("Diverging fit\n"); - return 4; - } - else - diverganceCandidate = true; - } - if(p0[0][0]<0.) - { - //negative amplitude - //fit diverged - // return parabola - return 4; - } - //if after a couple of iterations the amplitude is low - // reduce the tolerances (or the maximum iterations) - // low amplitude pulses tend to oscillate and exhaust all iterations - if(p0[0][0]<20.) - { - fitTolerance0 = 0.1; - fitTolerance1 = 0.05; - } - amplitudeChangeOld = amplitudeChangeNew; - counter++; - } - /* - std::cout << " Error matrix "<<std::endl; - for(int i=0;i<3;i++) - { - for(int j=0;j<3;j++) - std::cout << weight[i][j]<<"\t"; - std::cout<<std::endl; + for (int i = 0; i < ipar; i++) { + int ii = par[i]; + for (int j = 0; j < imeas; j++) { + int jj = meas[j]; + for (int k = 0; k < imeas; k++) { + int kk = meas[k]; + helpmatrix2[ii][jj] += A[kk][ii] * W[kk][jj]; + } + } + } + + for (int i = 0; i < ipar; i++) { + int ii = par[i]; + for (int j = 0; j < imeas; j++) { + int jj = meas[j]; + residFactor[ii][jj] = 0.; + for (int k = 0; k < ipar; k++) { + int kk = par[k]; + residFactor[ii][jj] += weight[ii][kk] * helpmatrix2[kk][jj]; + } + // residFactor[ii][jj]*=W[0][0]; + } + } + + double paramDiff[3]; + for (int i = 0; i < 3; ++i) { + paramDiff[i] = 0.; + } + + for (int i = 0; i < ipar; i++) { + int ii = par[i]; + // estimation of new parameters + // paramDiff[i][0] += (weight*(A.T()*W)*(m-fp))[i][0]; + for (int j = 0; j < imeas; j++) { + int jj = meas[j]; + paramDiff[ii] += residFactor[ii][jj] * (m[jj][0] - fp[jj][0]); + } + p0[ii][0] += paramDiff[ii]; + } + std::cout << "##### " << p0[0][0] << " " << p0[1][0] << " " << p0[2][0] << std::endl; + // if the parameters are not physical, keep them sensible + // if peaking time less than -0.5 + double peakingTime = p0[1][0] + m_zmax * p0[2][0] / m_tsampling; + if (peakingTime < -0.5 || peakingTime > 3.) p0[1][0] = initValues[1]; + + if (p0[0][0] < 0.) p0[0][0] = initValues[0]; + double amplitudeChangeNew = fabs(paramDiff[0]); + if (fabs(paramDiff[0]) < fitTolerance0 && fabs(paramDiff[1]) < fitTolerance1) { + converged = true; + // calculate chi2 + // (m-fp).T()*W*(m-fp) + double residual[4]; + for (int i = 0; i < 4; ++i) { + residual[i] = 0.; + } + + for (int i = 0; i < imeas; i++) { + int ii = meas[i]; + residual[i] = m[ii][0] - fp[ii][0]; + } + + double tmpChi2 = 0.; + double helpmatrixchi2[4][1]; + for (int i = 0; i < 4; ++i) { + helpmatrixchi2[i][0] = 0.; + } + for (int i = 0; i < imeas; i++) { + int ii = meas[i]; + for (int k = 0; k < imeas; k++) { + int kk = meas[k]; + helpmatrixchi2[ii][0] += W[ii][kk] * residual[kk]; + } + } + for (int k = 0; k < imeas; k++) { + int kk = meas[k]; + tmpChi2 += residual[kk] * helpmatrixchi2[kk][0]; + // std::cout << residual[kk] << " ";//*W[kk][kk]*residual[kk]<< " "; + } + // std::cout<<std::endl; + (*chi2) = tmpChi2; + } else if (counter > 4 && (amplitudeChangeNew > 4. * amplitudeChangeOld)) { + if (diverganceCandidate) { + // diverging fit + // return parabola interpolation + printf("%3.2f %3.2f %3.2f %3.2f\n ", x[0], x[1], x[2], x[3]); + printf("Diverging fit\n"); + return 4; + } else + diverganceCandidate = true; + } + if (p0[0][0] < 0.) { + // negative amplitude + // fit diverged + // return parabola + return 4; + } + // if after a couple of iterations the amplitude is low + // reduce the tolerances (or the maximum iterations) + // low amplitude pulses tend to oscillate and exhaust all iterations + if (p0[0][0] < 20.) { + fitTolerance0 = 0.1; + fitTolerance1 = 0.05; + } + amplitudeChangeOld = amplitudeChangeNew; + counter++; } - */ - - - result[0]=p0[0][0]; - result[1]=m_zmax*p0[2][0]/m_tsampling+p0[1][0]; - result[2]=p0[2][0]; - - if(counter==maxIter) - return 3; - return 0; + /* + std::cout << " Error matrix "<<std::endl; + for(int i=0;i<3;i++) + { + for(int j=0;j<3;j++) + std::cout << weight[i][j]<<"\t"; + std::cout<<std::endl; + } + */ + + + result[0] = p0[0][0]; + result[1] = m_zmax * p0[2][0] / m_tsampling + p0[1][0]; + result[2] = p0[2][0]; + + if (counter == maxIter) return 3; + return 0; } //********************************************************************** diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscBipolarStripFitter.h b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscBipolarStripFitter.h index c7d5af32ba19..5e24b8c135ad 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscBipolarStripFitter.h +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscBipolarStripFitter.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // CscBipolarStripFitter.h @@ -10,83 +10,80 @@ // K. Nikolopoulos // V. Chernyatin and M. Schernau // Oct 2007 -// +// // CSC Strip fitter using the bipolar waveform of the pulse // -// +// #include <vector> + #include "AthenaBaseComps/AthAlgTool.h" -#include "GaudiKernel/ToolHandle.h" #include "CscClusterization/ICscStripFitter.h" +#include "GaudiKernel/ToolHandle.h" class ICscCalibTool; class CscIdHelper; namespace Muon { - class CscStripPrepData; +class CscStripPrepData; } -namespace MuonGM -{ - class MuonDetectorManager; +namespace MuonGM { +class MuonDetectorManager; } class CscBipolarStripFitter : virtual public ICscStripFitter, public AthAlgTool { -public: // Ctors and dtor. - - // Constructor. - CscBipolarStripFitter(std::string, std::string, const IInterface*); - - // Destructor. - ~CscBipolarStripFitter(); - -public: // AlgTool methods - - // Initialization. - StatusCode initialize(); - - // Finalization. - StatusCode finalize(); - -public: // Interface methods - - // Tell compiler not to hide other fit methods. - using ICscStripFitter::fit; - - // Fit a list of sample charges using the calibration tool. - // If that fit fails, the peak channel is used. - Result fit(const ChargeList& charges, double samplingTime, Identifier& stripId) const; - -private: // data - - // Pointer to muon geometry manager. - const MuonGM::MuonDetectorManager* m_pmuon_detmgr; - const CscIdHelper* m_phelper; - - // Calibration tool. - ToolHandle<ICscCalibTool> m_cscCalibTool; - - double FindInitValues(double *x,double *initValues,int *maxsample) const; - double FindPow(double z) const; - void InvertMatrix(double matrix[][3],const int dim,int*) const; - void InvertSymmetric4x4(double W[][4]) const; - void Derivative(double A[][3],double fp[][1], double p0[][1],int imeas, int*meas) const; - int TheFitter(double*x,const double ex,double *initValues, int imeas, int *meas, int ipar, int *par,double *chi2,double *result) const; - - // Job options. - double m_qerr; // Charge error for a successful fit. - double m_terr; // Time error for a succcessful fit. - double m_qerr_fail; // Charge error for a failed fit. - double m_terr_fail; // Time error for a failed fit. - double m_qerrprop; // Charge calibration error - double m_n; - double m_n2; - double m_zmax; - double m_bipolarNormalization; - double m_tsampling; - - mutable double m_powcachez; - mutable double m_powcachezn; + public: // Ctors and dtor. + // Constructor. + CscBipolarStripFitter(std::string, std::string, const IInterface *); + + // Destructor. + ~CscBipolarStripFitter(); + + public: // AlgTool methods + // Initialization. + StatusCode initialize(); + + // Finalization. + StatusCode finalize(); + + public: // Interface methods + // Tell compiler not to hide other fit methods. + using ICscStripFitter::fit; + + // Fit a list of sample charges using the calibration tool. + // If that fit fails, the peak channel is used. + Result fit(const ChargeList &charges, double samplingTime, Identifier &stripId) const; + + private: // data + // Pointer to muon geometry manager. + const MuonGM::MuonDetectorManager *m_pmuon_detmgr; + const CscIdHelper * m_phelper; + + // Calibration tool. + ToolHandle<ICscCalibTool> m_cscCalibTool; + + double FindInitValues(double *x, double *initValues, int *maxsample) const; + double FindPow(double z) const; + void InvertMatrix(double matrix[][3], const int dim, int *) const; + void InvertSymmetric4x4(double W[][4]) const; + void Derivative(double A[][3], double fp[][1], double p0[][1], int imeas, int *meas) const; + int TheFitter(double *x, const double ex, double *initValues, int imeas, int *meas, int ipar, int *par, + double *chi2, double *result) const; + + // Job options. + double m_qerr; // Charge error for a successful fit. + double m_terr; // Time error for a succcessful fit. + double m_qerr_fail; // Charge error for a failed fit. + double m_terr_fail; // Time error for a failed fit. + double m_qerrprop; // Charge calibration error + double m_n; + double m_n2; + double m_zmax; + double m_bipolarNormalization; + double m_tsampling; + + mutable double m_powcachez; + mutable double m_powcachezn; }; #endif diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscClusterUtilTool.cxx b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscClusterUtilTool.cxx index f4959afdbc3e..571900b8c903 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscClusterUtilTool.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscClusterUtilTool.cxx @@ -1,213 +1,216 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // CscClusterUtilTool.cxx #include "CscClusterUtilTool.h" -#include "MuonPrepRawData/CscStripPrepDataContainer.h" -#include "MuonPrepRawData/CscStripPrepDataCollection.h" +#include "CscClusterization/ICscClusterFitter.h" +#include "CscClusterization/ICscStripFitter.h" +#include "MuonIdHelpers/CscIdHelper.h" #include "MuonPrepRawData/CscPrepData.h" +#include "MuonPrepRawData/CscStripPrepDataCollection.h" +#include "MuonPrepRawData/CscStripPrepDataContainer.h" +#include "MuonRIO_OnTrack/CscClusterOnTrack.h" #include "MuonReadoutGeometry/MuonDetectorManager.h" -#include "MuonIdHelpers/CscIdHelper.h" -#include "CscClusterization/ICscStripFitter.h" -#include "CscClusterization/ICscClusterFitter.h" - #include "TrkRIO_OnTrack/RIO_OnTrack.h" -#include "MuonRIO_OnTrack/CscClusterOnTrack.h" -using std::vector; -using std::string; using Muon::CscPrepData; -using Muon::CscStripPrepDataContainer; -using Muon::CscStripPrepDataCollection; using Muon::CscStripPrepData; +using Muon::CscStripPrepDataCollection; +using Muon::CscStripPrepDataContainer; +using std::string; +using std::vector; //********************************************************************** -CscClusterUtilTool:: -CscClusterUtilTool(string type, string aname, const IInterface* parent) - : AthAlgTool(type, aname, parent), - m_pmuon_detmgr(0), m_phelper(0), - m_stripFitter("CalibCscStripFitter/CalibCscStripFitter", this), - m_precClusterFitter("QratCscClusterFitter/QratCscClusterFitter", this), - m_cscStripLocation("CSC_Measurements") +CscClusterUtilTool::CscClusterUtilTool(string type, string aname, const IInterface* parent) + : AthAlgTool(type, aname, parent), + m_pmuon_detmgr(0), + m_phelper(0), + m_stripFitter("CalibCscStripFitter/CalibCscStripFitter", this), + m_precClusterFitter("QratCscClusterFitter/QratCscClusterFitter", this), + m_cscStripLocation("CSC_Measurements") { - declareInterface<ICscClusterUtilTool>(this); - declareProperty("strip_fitter", m_stripFitter); - declareProperty("precision_fitter", m_precClusterFitter); - declareProperty("CscStripPrepDataLocation", m_cscStripLocation ); + declareInterface<ICscClusterUtilTool>(this); + declareProperty("strip_fitter", m_stripFitter); + declareProperty("precision_fitter", m_precClusterFitter); + declareProperty("CscStripPrepDataLocation", m_cscStripLocation); } //********************************************************************** -CscClusterUtilTool::~CscClusterUtilTool() { } +CscClusterUtilTool::~CscClusterUtilTool() {} //********************************************************************** -StatusCode CscClusterUtilTool::initialize() { - - ATH_MSG_DEBUG ( "Initializing " << name() ); - ATH_MSG_DEBUG ( " Strip fitter is " << m_stripFitter.typeAndName() ); - ATH_CHECK( m_cscStripLocation.initialize() ); - ATH_MSG_DEBUG ( " CscStripPrepDataLocation is " << m_cscStripLocation.key() ); - - // Retrieve the strip fitting tool. - if ( m_stripFitter.retrieve().isFailure() ) { - ATH_MSG_FATAL ( "Unable to retrieve strip fitting tool " << m_stripFitter ); - return StatusCode::FAILURE; - } - ATH_MSG_DEBUG ( "Retrieved strip fitting tool " << m_stripFitter ); - - // Retrieve the precision cluster fitting tool. - if ( m_precClusterFitter.retrieve().isFailure() ) { - ATH_MSG_FATAL ( "Unable to retrieve CSC precision cluster fitting tool " - << m_precClusterFitter->name() ); - return StatusCode::FAILURE; - } - ATH_MSG_DEBUG ( "Retrieved CSC precision cluster fitting tool" ); - - // Retrieve the detector descriptor. - if ( detStore()->retrieve(m_pmuon_detmgr).isFailure() ) { - ATH_MSG_ERROR ( " Cannot retrieve MuonGeoModel " ); - return StatusCode::RECOVERABLE; - } - ATH_MSG_DEBUG ( "Retrieved geometry." ); - m_phelper = m_pmuon_detmgr->cscIdHelper(); - - - return StatusCode::SUCCESS; +StatusCode +CscClusterUtilTool::initialize() +{ + + ATH_MSG_DEBUG("Initializing " << name()); + ATH_MSG_DEBUG(" Strip fitter is " << m_stripFitter.typeAndName()); + ATH_CHECK(m_cscStripLocation.initialize()); + ATH_MSG_DEBUG(" CscStripPrepDataLocation is " << m_cscStripLocation.key()); + + // Retrieve the strip fitting tool. + if (m_stripFitter.retrieve().isFailure()) { + ATH_MSG_FATAL("Unable to retrieve strip fitting tool " << m_stripFitter); + return StatusCode::FAILURE; + } + ATH_MSG_DEBUG("Retrieved strip fitting tool " << m_stripFitter); + + // Retrieve the precision cluster fitting tool. + if (m_precClusterFitter.retrieve().isFailure()) { + ATH_MSG_FATAL("Unable to retrieve CSC precision cluster fitting tool " << m_precClusterFitter->name()); + return StatusCode::FAILURE; + } + ATH_MSG_DEBUG("Retrieved CSC precision cluster fitting tool"); + + // Retrieve the detector descriptor. + if (detStore()->retrieve(m_pmuon_detmgr).isFailure()) { + ATH_MSG_ERROR(" Cannot retrieve MuonGeoModel "); + return StatusCode::RECOVERABLE; + } + ATH_MSG_DEBUG("Retrieved geometry."); + m_phelper = m_pmuon_detmgr->cscIdHelper(); + + + return StatusCode::SUCCESS; } //********************************************************************** -StatusCode CscClusterUtilTool::finalize() { - ATH_MSG_VERBOSE ( "Finalizing " << name() ); - return StatusCode::SUCCESS; +StatusCode +CscClusterUtilTool::finalize() +{ + ATH_MSG_VERBOSE("Finalizing " << name()); + return StatusCode::SUCCESS; } //********************************************************************** -void CscClusterUtilTool::getStripFits(const Trk::RIO_OnTrack* rot, - ICscClusterFitter::StripFitList& sfits) const { +void +CscClusterUtilTool::getStripFits(const Trk::RIO_OnTrack* rot, ICscClusterFitter::StripFitList& sfits) const +{ - if ( !rot ) { - ATH_MSG_WARNING ( " Trk::RIO_OnTrack* rot is empty !" ); - return; - } - const Muon::CscClusterOnTrack* pclu = dynamic_cast<const Muon::CscClusterOnTrack*>(rot); - if ( !pclu ) { - ATH_MSG_WARNING ( " Muon::CscClusterOnTrack* pclu is empty !" ); - return; - } - getStripFits(pclu, sfits); + if (!rot) { + ATH_MSG_WARNING(" Trk::RIO_OnTrack* rot is empty !"); + return; + } + const Muon::CscClusterOnTrack* pclu = dynamic_cast<const Muon::CscClusterOnTrack*>(rot); + if (!pclu) { + ATH_MSG_WARNING(" Muon::CscClusterOnTrack* pclu is empty !"); + return; + } + getStripFits(pclu, sfits); - return; + return; } -void CscClusterUtilTool::getStripFits(const Muon::CscClusterOnTrack* pclu, - ICscClusterFitter::StripFitList& sfits) const { - - if ( !pclu ) { - ATH_MSG_WARNING ( " Muon::CscClusterOnTrack* pclu is empty !" ); - return; - } - const Muon::CscPrepData* pprd = pclu->prepRawData(); - if ( !pprd ) { - ATH_MSG_WARNING ( " Muon::CscPrepData* pprd is empty !" ); - return; - } +void +CscClusterUtilTool::getStripFits(const Muon::CscClusterOnTrack* pclu, ICscClusterFitter::StripFitList& sfits) const +{ - getStripFits(pprd, sfits); - return; + if (!pclu) { + ATH_MSG_WARNING(" Muon::CscClusterOnTrack* pclu is empty !"); + return; + } + const Muon::CscPrepData* pprd = pclu->prepRawData(); + if (!pprd) { + ATH_MSG_WARNING(" Muon::CscPrepData* pprd is empty !"); + return; + } + getStripFits(pprd, sfits); + return; } //////////////////////////////////////////////////////////// -void CscClusterUtilTool::getStripFits(const CscPrepData* MClus, - ICscClusterFitter::StripFitList& sfits) const { +void +CscClusterUtilTool::getStripFits(const CscPrepData* MClus, ICscClusterFitter::StripFitList& sfits) const +{ + + if (!MClus) { + ATH_MSG_WARNING(" Muon::CscPrepData* pprd is empty !"); + return; + } - if ( !MClus ) { - ATH_MSG_WARNING ( " Muon::CscPrepData* pprd is empty !" ); + sfits.clear(); + + vector<const CscStripPrepData*> strPrepDatas = getStrips(MClus); + for (unsigned int i = 0; i < strPrepDatas.size(); ++i) { + ICscClusterFitter::StripFit sfit; + sfit = m_stripFitter->fit(*strPrepDatas[i]); + ATH_MSG_VERBOSE(" in loop charge " << sfit.charge); + // if (sfit.charge == 0.) // It's the case of narrow strips...in QratStripFitter + // sfit.charge = 40.; // 0 charge is set to minimal non zero to do fit e.g. dead channel case + sfits.push_back(sfit); + } return; - } - - sfits.clear(); - - vector<const CscStripPrepData*> strPrepDatas =getStrips(MClus); - for (unsigned int i=0; i<strPrepDatas.size(); ++i) { - ICscClusterFitter::StripFit sfit; - sfit = m_stripFitter->fit(*strPrepDatas[i]); - ATH_MSG_VERBOSE ( " in loop charge " << sfit.charge ); - // if (sfit.charge == 0.) // It's the case of narrow strips...in QratStripFitter - // sfit.charge = 40.; // 0 charge is set to minimal non zero to do fit e.g. dead channel case - sfits.push_back(sfit); - } - return; } /////////////////////////////////////////////////////////// -ICscClusterFitter::Results CscClusterUtilTool::getRefitCluster(const CscPrepData* MClus, - double tantheta) const { +ICscClusterFitter::Results +CscClusterUtilTool::getRefitCluster(const CscPrepData* MClus, double tantheta) const +{ - ICscClusterFitter::Results results; - if ( !MClus ) { - ATH_MSG_WARNING ( " Muon::CscPrepData* pprd is empty !" ); - return results; - } + ICscClusterFitter::Results results; + if (!MClus) { + ATH_MSG_WARNING(" Muon::CscPrepData* pprd is empty !"); + return results; + } - ICscClusterFitter::StripFitList sfits; - sfits.clear(); + ICscClusterFitter::StripFitList sfits; + sfits.clear(); - getStripFits(MClus, sfits); - results = m_precClusterFitter->fit(sfits,tantheta); + getStripFits(MClus, sfits); + results = m_precClusterFitter->fit(sfits, tantheta); - return results; + return results; } ///////////////////////////////////////////////////////////////////////////// -vector<const CscStripPrepData*> CscClusterUtilTool::getStrips(const CscPrepData* MClus) const { +vector<const CscStripPrepData*> +CscClusterUtilTool::getStrips(const CscPrepData* MClus) const +{ - vector<const CscStripPrepData*> strips; - if ( !MClus ) { - ATH_MSG_WARNING ( " Muon::CscPrepData* pprd is empty !" ); - return strips; - } + vector<const CscStripPrepData*> strips; + if (!MClus) { + ATH_MSG_WARNING(" Muon::CscPrepData* pprd is empty !"); + return strips; + } - vector<Identifier> prd_digit_ids = MClus->rdoList(); + vector<Identifier> prd_digit_ids = MClus->rdoList(); - SG::ReadHandle<Muon::CscStripPrepDataContainer> pdigcont(m_cscStripLocation); + SG::ReadHandle<Muon::CscStripPrepDataContainer> pdigcont(m_cscStripLocation); - if ( !pdigcont.isValid() ) { - ATH_MSG_WARNING ( "Strip container " << m_cscStripLocation.key() << " not found in StoreGate!" ); - return strips; - } - ATH_MSG_DEBUG ( "Retrieved " << m_cscStripLocation.key() << " successfully. " ); - - - IdentifierHash elhash=MClus->collectionHash(); - auto it = pdigcont->indexFindPtr(elhash); - - ATH_MSG_VERBOSE ( "Hash " << elhash << " converted to iterator of container successfully"); - - if (it != nullptr) { - ATH_MSG_VERBOSE ( " it == pdigcont.end() passed"); - for ( unsigned int istrip=0; istrip<prd_digit_ids.size(); ++istrip ) { - const CscStripPrepDataCollection& col = *it; - // Loop over digits and fill these arrays. - for ( CscStripPrepDataCollection::const_iterator idig=col.begin(); - idig!=col.end(); ++idig ) { - const CscStripPrepData& dig = **idig; - Identifier stid = dig.identify(); - if (stid!=prd_digit_ids[istrip]) continue; - const CscStripPrepData* pstrip = &dig; - ATH_MSG_VERBOSE ( "strip " << pstrip->timeOfFirstSample() ); - - strips.push_back(pstrip); - break; - } + if (!pdigcont.isValid()) { + ATH_MSG_WARNING("Strip container " << m_cscStripLocation.key() << " not found in StoreGate!"); + return strips; } - } - return strips; + ATH_MSG_DEBUG("Retrieved " << m_cscStripLocation.key() << " successfully. "); + + + IdentifierHash elhash = MClus->collectionHash(); + auto it = pdigcont->indexFindPtr(elhash); + + ATH_MSG_VERBOSE("Hash " << elhash << " converted to iterator of container successfully"); + + if (it != nullptr) { + ATH_MSG_VERBOSE(" it == pdigcont.end() passed"); + for (unsigned int istrip = 0; istrip < prd_digit_ids.size(); ++istrip) { + const CscStripPrepDataCollection& col = *it; + // Loop over digits and fill these arrays. + for (CscStripPrepDataCollection::const_iterator idig = col.begin(); idig != col.end(); ++idig) { + const CscStripPrepData& dig = **idig; + Identifier stid = dig.identify(); + if (stid != prd_digit_ids[istrip]) continue; + const CscStripPrepData* pstrip = &dig; + ATH_MSG_VERBOSE("strip " << pstrip->timeOfFirstSample()); + + strips.push_back(pstrip); + break; + } + } + } + return strips; } - - - diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscClusterUtilTool.h b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscClusterUtilTool.h index b0ca4a8da592..0eb7ff03730c 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscClusterUtilTool.h +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscClusterUtilTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // CscClusterUtilTool.h @@ -13,65 +13,58 @@ // Strip fitter using the parabolic fit fron the CSC calibration tool. #include <vector> + #include "AthenaBaseComps/AthAlgTool.h" -#include "GaudiKernel/ToolHandle.h" #include "CscClusterization/ICscClusterUtilTool.h" +#include "GaudiKernel/ToolHandle.h" class CscIdHelper; -namespace MuonGM -{ - class MuonDetectorManager; +namespace MuonGM { +class MuonDetectorManager; } namespace Muon { - class CscClusterOnTrack; - class CscPrepData; - class CscStripPrepData; -} +class CscClusterOnTrack; +class CscPrepData; +class CscStripPrepData; +} // namespace Muon namespace Trk { - class RIO_OnTrack; +class RIO_OnTrack; } class CscClusterUtilTool : virtual public ICscClusterUtilTool, public AthAlgTool { -public: // Ctors and dtor. - - // Constructor. - CscClusterUtilTool(std::string, std::string, const IInterface*); - - // Destructor. - ~CscClusterUtilTool(); - -public: // AlgTool methods - - // Initialization. - StatusCode initialize(); + public: // Ctors and dtor. + // Constructor. + CscClusterUtilTool(std::string, std::string, const IInterface*); - // Finalization. - StatusCode finalize(); + // Destructor. + ~CscClusterUtilTool(); -public: - ICscClusterFitter::Results getRefitCluster(const Muon::CscPrepData* MClus, double tantheta) const; + public: // AlgTool methods + // Initialization. + StatusCode initialize(); - void getStripFits(const Trk::RIO_OnTrack* rot, ICscClusterFitter::StripFitList& sfits) const; - void getStripFits(const Muon::CscClusterOnTrack* pclu, ICscClusterFitter::StripFitList& sfits) const; - void getStripFits(const Muon::CscPrepData*, ICscClusterFitter::StripFitList&) const; + // Finalization. + StatusCode finalize(); - std::vector<const Muon::CscStripPrepData*> getStrips(const Muon::CscPrepData* MClus) const; + public: + ICscClusterFitter::Results getRefitCluster(const Muon::CscPrepData* MClus, double tantheta) const; - + void getStripFits(const Trk::RIO_OnTrack* rot, ICscClusterFitter::StripFitList& sfits) const; + void getStripFits(const Muon::CscClusterOnTrack* pclu, ICscClusterFitter::StripFitList& sfits) const; + void getStripFits(const Muon::CscPrepData*, ICscClusterFitter::StripFitList&) const; -private: // data - // Pointer to muon geometry manager. - const MuonGM::MuonDetectorManager* m_pmuon_detmgr; - const CscIdHelper* m_phelper; + std::vector<const Muon::CscStripPrepData*> getStrips(const Muon::CscPrepData* MClus) const; - // Strip fitter. - ToolHandle<ICscStripFitter> m_stripFitter; - ToolHandle<ICscClusterFitter> m_precClusterFitter; - SG::ReadHandleKey<Muon::CscStripPrepDataContainer> m_cscStripLocation; - + private: // data + // Pointer to muon geometry manager. + const MuonGM::MuonDetectorManager* m_pmuon_detmgr; + const CscIdHelper* m_phelper; - + // Strip fitter. + ToolHandle<ICscStripFitter> m_stripFitter; + ToolHandle<ICscClusterFitter> m_precClusterFitter; + SG::ReadHandleKey<Muon::CscStripPrepDataContainer> m_cscStripLocation; }; #endif diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscPeakThresholdClusterBuilderTool.cxx b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscPeakThresholdClusterBuilderTool.cxx index 91fb74640c8e..84313668cb5a 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscPeakThresholdClusterBuilderTool.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscPeakThresholdClusterBuilderTool.cxx @@ -1,27 +1,23 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // CscPeakThresholdClusterBuilderTool.cxx #include "CscPeakThresholdClusterBuilderTool.h" + +#include <sstream> + +#include "EventPrimitives/EventPrimitives.h" +#include "EventPrimitives/EventPrimitivesHelpers.h" +#include "EventPrimitives/EventPrimitivesToStringConverter.h" #include "Gaudi/Property.h" +#include "MuonPrepRawData/CscClusterStatus.h" #include "MuonPrepRawData/CscPrepDataContainer.h" -#include "MuonPrepRawData/CscStripPrepDataContainer.h" #include "MuonPrepRawData/CscStripPrepData.h" +#include "MuonPrepRawData/CscStripPrepDataContainer.h" #include "MuonReadoutGeometry/CscReadoutElement.h" #include "TrkSurfaces/Surface.h" -#include "MuonPrepRawData/CscClusterStatus.h" - -#include "EventPrimitives/EventPrimitivesToStringConverter.h" -#include "EventPrimitives/EventPrimitives.h" -#include "EventPrimitives/EventPrimitivesHelpers.h" -#include <sstream> - -using std::ostringstream; -using std::vector; -using std::setw; -using MuonGM::CscReadoutElement; using Muon::CscClusterStatus; using Muon::CscPrepData; using Muon::CscPrepDataCollection; @@ -29,6 +25,10 @@ using Muon::CscPrepDataContainer; using Muon::CscStripPrepData; using Muon::CscStripPrepDataCollection; using Muon::CscStripPrepDataContainer; +using MuonGM::CscReadoutElement; +using std::ostringstream; +using std::setw; +using std::vector; //****************************************************************************** // Local definitions. @@ -36,357 +36,364 @@ namespace { //****************************************************************************** // Convert chamber identifier to string. -std::string chamber(int istation, int zsec, int phi) { - ostringstream ssout; - if ( istation == 1 ) ssout << "CSS"; - else if ( istation ==2 ) ssout << "CSL"; - else ssout << "???"; - if ( zsec == -1 ) ssout << "-"; - else if ( zsec == 1 ) ssout << "+"; - else ssout << "?"; - ssout << phi; - return ssout.str(); +std::string +chamber(int istation, int zsec, int phi) +{ + ostringstream ssout; + if (istation == 1) + ssout << "CSS"; + else if (istation == 2) + ssout << "CSL"; + else + ssout << "???"; + if (zsec == -1) + ssout << "-"; + else if (zsec == 1) + ssout << "+"; + else + ssout << "?"; + ssout << phi; + return ssout.str(); } // Convert measphi to string. -std::string setaphi(bool measphi) { - if (measphi) return "phi"; - return "eta"; +std::string +setaphi(bool measphi) +{ + if (measphi) return "phi"; + return "eta"; } //****************************************************************************** } // end unnamed namespace //****************************************************************************** -CscPeakThresholdClusterBuilderTool:: -CscPeakThresholdClusterBuilderTool(const std::string &type, const std::string &aname, const IInterface* parent) - : AthAlgTool(type, aname, parent), - m_digit_key("CSC_Measurements"), m_cluster_handle("CSC_Clusters"), - m_pstrip_fitter("CalibCscStripFitter/CalibCscStripFitter"), - m_pfitter_def("SimpleCscClusterFitter/SimpleCscClusterFitter"), - m_pfitter_prec("QratCscClusterFitter/QratCscClusterFitter"), - m_pfitter_split("CscSplitClusterFitter/CscSplitClusterFitter"), - m_fullEventDone(false) +CscPeakThresholdClusterBuilderTool::CscPeakThresholdClusterBuilderTool(const std::string& type, + const std::string& aname, + const IInterface* parent) + : AthAlgTool(type, aname, parent), + m_digit_key("CSC_Measurements"), + m_cluster_handle("CSC_Clusters"), + m_pstrip_fitter("CalibCscStripFitter/CalibCscStripFitter"), + m_pfitter_def("SimpleCscClusterFitter/SimpleCscClusterFitter"), + m_pfitter_prec("QratCscClusterFitter/QratCscClusterFitter"), + m_pfitter_split("CscSplitClusterFitter/CscSplitClusterFitter"), + m_fullEventDone(false) { - declareInterface<ICscClusterBuilder>(this); - - declareProperty("qpeak_threshold_eta", m_qpeak_threshold_eta = 21000.0); - declareProperty("qpeak_threshold_phi", m_qpeak_threshold_phi = 33000.0); - declareProperty("q3sum_threshold_eta", m_q3sum_threshold_eta = 38000.0); - declareProperty("q3sum_threshold_phi", m_q3sum_threshold_phi = 33000.0); - declareProperty("digit_key", m_digit_key ); - declareProperty("cluster_key", m_cluster_handle ); - declareProperty("strip_fitter", m_pstrip_fitter); - declareProperty("default_fitter", m_pfitter_def); - declareProperty("precision_fitter", m_pfitter_prec); - declareProperty("split_fitter", m_pfitter_split); + declareInterface<ICscClusterBuilder>(this); + + declareProperty("qpeak_threshold_eta", m_qpeak_threshold_eta = 21000.0); + declareProperty("qpeak_threshold_phi", m_qpeak_threshold_phi = 33000.0); + declareProperty("q3sum_threshold_eta", m_q3sum_threshold_eta = 38000.0); + declareProperty("q3sum_threshold_phi", m_q3sum_threshold_phi = 33000.0); + declareProperty("digit_key", m_digit_key); + declareProperty("cluster_key", m_cluster_handle); + declareProperty("strip_fitter", m_pstrip_fitter); + declareProperty("default_fitter", m_pfitter_def); + declareProperty("precision_fitter", m_pfitter_prec); + declareProperty("split_fitter", m_pfitter_split); } //****************************************************************************** // Destructor. -CscPeakThresholdClusterBuilderTool::~CscPeakThresholdClusterBuilderTool() -{ } +CscPeakThresholdClusterBuilderTool::~CscPeakThresholdClusterBuilderTool() {} //****************************************************************************** -StatusCode CscPeakThresholdClusterBuilderTool::initialize(){ - ATH_MSG_DEBUG ( "Initializing " << name() ); - ATH_CHECK( m_digit_key.initialize() ); - // Display algorithm properties. - ATH_MSG_DEBUG ( "Properties for " << name() << ":" ); - ATH_MSG_DEBUG ( " Cluster qpeak threshold is eta/phi " << m_qpeak_threshold_eta << "/" << m_qpeak_threshold_phi); - ATH_MSG_DEBUG ( " Cluster q3sum threshold is eta/phi " << m_q3sum_threshold_eta << "/" << m_q3sum_threshold_phi); - ATH_MSG_DEBUG ( " Strip fitter is " << m_pstrip_fitter.typeAndName() ); - ATH_MSG_DEBUG ( " Default cluster fitter is " << m_pfitter_def.typeAndName() ); - ATH_MSG_DEBUG ( " Precision cluster fitter is " << m_pfitter_prec.typeAndName() ); - ATH_MSG_DEBUG ( " Split cluster fitter is " << m_pfitter_split.typeAndName() ); - ATH_MSG_DEBUG ( " Input digit key is " << m_digit_key.key() ); - ATH_MSG_DEBUG ( " Output cluster key is " << m_cluster_handle.key() ); - - // Retrieve the strip fitting tool. - if ( m_pstrip_fitter.retrieve().isFailure() ) { - ATH_MSG_FATAL ( "Unable to retrieve strip fitting tool " << m_pstrip_fitter ); - return StatusCode::FAILURE; - } - ATH_MSG_DEBUG ( "Retrieved strip fitting tool " << m_pstrip_fitter ); - - // Retrieve the default cluster fitting tool. - if ( m_pfitter_def.retrieve().isFailure() ) { - ATH_MSG_FATAL ( "Unable to retrieve CSC default cluster fitting tool " - << m_pfitter_def->name() ); - return StatusCode::FAILURE; - } - ATH_MSG_DEBUG ( "Retrieved CSC default cluster fitting tool" ); - - // Retrieve the precision cluster fitting tool. - if ( m_pfitter_prec.retrieve().isFailure() ) { - ATH_MSG_FATAL ( "Unable to retrieve CSC precision cluster fitting tool " - << m_pfitter_prec->name() ); - return StatusCode::FAILURE; - } - ATH_MSG_DEBUG ( "Retrieved CSC precision cluster fitting tool" ); - - // Retrieve the split cluster fitting tool. - if ( m_pfitter_split.retrieve().isFailure() ) { - ATH_MSG_FATAL ( "Unable to retrieve CSC split cluster fitting tool " - << m_pfitter_split->name() ); - return StatusCode::FAILURE; - } - ATH_MSG_DEBUG ( "Retrieved CSC split cluster fitting tool" ); - - // retrieve MuonDetectorManager from the conditions store - ATH_CHECK(m_DetectorManagerKey.initialize()); - ATH_CHECK(m_idHelperSvc.retrieve()); - - return StatusCode::SUCCESS; +StatusCode +CscPeakThresholdClusterBuilderTool::initialize() +{ + ATH_MSG_DEBUG("Initializing " << name()); + ATH_CHECK(m_digit_key.initialize()); + // Display algorithm properties. + ATH_MSG_DEBUG("Properties for " << name() << ":"); + ATH_MSG_DEBUG(" Cluster qpeak threshold is eta/phi " << m_qpeak_threshold_eta << "/" << m_qpeak_threshold_phi); + ATH_MSG_DEBUG(" Cluster q3sum threshold is eta/phi " << m_q3sum_threshold_eta << "/" << m_q3sum_threshold_phi); + ATH_MSG_DEBUG(" Strip fitter is " << m_pstrip_fitter.typeAndName()); + ATH_MSG_DEBUG(" Default cluster fitter is " << m_pfitter_def.typeAndName()); + ATH_MSG_DEBUG(" Precision cluster fitter is " << m_pfitter_prec.typeAndName()); + ATH_MSG_DEBUG(" Split cluster fitter is " << m_pfitter_split.typeAndName()); + ATH_MSG_DEBUG(" Input digit key is " << m_digit_key.key()); + ATH_MSG_DEBUG(" Output cluster key is " << m_cluster_handle.key()); + + // Retrieve the strip fitting tool. + if (m_pstrip_fitter.retrieve().isFailure()) { + ATH_MSG_FATAL("Unable to retrieve strip fitting tool " << m_pstrip_fitter); + return StatusCode::FAILURE; + } + ATH_MSG_DEBUG("Retrieved strip fitting tool " << m_pstrip_fitter); + + // Retrieve the default cluster fitting tool. + if (m_pfitter_def.retrieve().isFailure()) { + ATH_MSG_FATAL("Unable to retrieve CSC default cluster fitting tool " << m_pfitter_def->name()); + return StatusCode::FAILURE; + } + ATH_MSG_DEBUG("Retrieved CSC default cluster fitting tool"); + + // Retrieve the precision cluster fitting tool. + if (m_pfitter_prec.retrieve().isFailure()) { + ATH_MSG_FATAL("Unable to retrieve CSC precision cluster fitting tool " << m_pfitter_prec->name()); + return StatusCode::FAILURE; + } + ATH_MSG_DEBUG("Retrieved CSC precision cluster fitting tool"); + + // Retrieve the split cluster fitting tool. + if (m_pfitter_split.retrieve().isFailure()) { + ATH_MSG_FATAL("Unable to retrieve CSC split cluster fitting tool " << m_pfitter_split->name()); + return StatusCode::FAILURE; + } + ATH_MSG_DEBUG("Retrieved CSC split cluster fitting tool"); + + // retrieve MuonDetectorManager from the conditions store + ATH_CHECK(m_DetectorManagerKey.initialize()); + ATH_CHECK(m_idHelperSvc.retrieve()); + + return StatusCode::SUCCESS; } //****************************************************************************** -StatusCode CscPeakThresholdClusterBuilderTool::getClusters(std::vector<IdentifierHash>& givenIDs, std::vector<IdentifierHash>& decodedIds) { +StatusCode +CscPeakThresholdClusterBuilderTool::getClusters(std::vector<IdentifierHash>& givenIDs, + std::vector<IdentifierHash>& decodedIds) +{ + + // clear output vector of selected data collections containing data + decodedIds.clear(); - // clear output vector of selected data collections containing data - decodedIds.clear(); + if (!m_cluster_handle.isPresent()) { + /// clean up the PrepRawData container + auto object = std::make_unique<CscPrepDataContainer>(m_idHelperSvc->cscIdHelper().module_hash_max()); - if (!m_cluster_handle.isPresent()) { - /// clean up the PrepRawData container - auto object = std::make_unique<CscPrepDataContainer>(m_idHelperSvc->cscIdHelper().module_hash_max()); - - /// record the container in storeGate - if ( m_cluster_handle.record(std::move(object)).isFailure() ) { - ATH_MSG_ERROR ( "Could not record container of CSC Cluster PrepData at " - << m_cluster_handle.key() ); - return StatusCode::RECOVERABLE; - } - m_fullEventDone=false; - if (givenIDs.size() == 0) m_fullEventDone=true; - - } else { - ATH_MSG_DEBUG ( "CSC Cluster PrepData Container is already in StoreGate " ); - if (m_fullEventDone) { - ATH_MSG_DEBUG ( "Whole event has already been processed; nothing to do"); - return StatusCode::SUCCESS; + /// record the container in storeGate + if (m_cluster_handle.record(std::move(object)).isFailure()) { + ATH_MSG_ERROR("Could not record container of CSC Cluster PrepData at " << m_cluster_handle.key()); + return StatusCode::RECOVERABLE; + } + m_fullEventDone = false; + if (givenIDs.size() == 0) m_fullEventDone = true; + + } else { + ATH_MSG_DEBUG("CSC Cluster PrepData Container is already in StoreGate "); + if (m_fullEventDone) { + ATH_MSG_DEBUG("Whole event has already been processed; nothing to do"); + return StatusCode::SUCCESS; + } + if (givenIDs.size() == 0) m_fullEventDone = true; } - if (givenIDs.size() == 0) m_fullEventDone = true; - } - - if (givenIDs.size()!=0) { - for (unsigned int i=0; i<givenIDs.size(); ++i) { - if ( getClusters(givenIDs[i],decodedIds).isFailure() ) { - ATH_MSG_ERROR ( "Unable to decode CSC RDO " << i << "th into CSC PrepRawData" ); - return StatusCode::RECOVERABLE; - } - } - } else { - // Clusterization is done for every area - if ( getClusters(decodedIds).isFailure()) { - ATH_MSG_ERROR ( "Unable to decode CSC RDO into CSC PrepRawData" ); - return StatusCode::RECOVERABLE; + + if (givenIDs.size() != 0) { + for (unsigned int i = 0; i < givenIDs.size(); ++i) { + if (getClusters(givenIDs[i], decodedIds).isFailure()) { + ATH_MSG_ERROR("Unable to decode CSC RDO " << i << "th into CSC PrepRawData"); + return StatusCode::RECOVERABLE; + } + } + } else { + // Clusterization is done for every area + if (getClusters(decodedIds).isFailure()) { + ATH_MSG_ERROR("Unable to decode CSC RDO into CSC PrepRawData"); + return StatusCode::RECOVERABLE; + } } - } - return StatusCode::SUCCESS; + return StatusCode::SUCCESS; } //****************************************************************************** -StatusCode CscPeakThresholdClusterBuilderTool::getClusters(IdentifierHash givenHashId, std::vector<IdentifierHash>& decodedIds) { +StatusCode +CscPeakThresholdClusterBuilderTool::getClusters(IdentifierHash givenHashId, std::vector<IdentifierHash>& decodedIds) +{ - // identifiers of collections already decoded and stored in the container will be skipped - if (m_cluster_handle->indexFindPtr(givenHashId) != nullptr) { - decodedIds.push_back(givenHashId); - ATH_MSG_DEBUG ( "A collection already exists in the container for offline id hash. " - << (int) givenHashId ); - return StatusCode::SUCCESS; - } + // identifiers of collections already decoded and stored in the container will be skipped + if (m_cluster_handle->indexFindPtr(givenHashId) != nullptr) { + decodedIds.push_back(givenHashId); + ATH_MSG_DEBUG("A collection already exists in the container for offline id hash. " << (int)givenHashId); + return StatusCode::SUCCESS; + } - // Retrieve the CSC digits for this event. - SG::ReadHandle<CscStripPrepDataContainer> pdigcon(m_digit_key); - if ( pdigcon.isValid() ) { - ATH_MSG_DEBUG ( "Retrieved strip container " << m_digit_key.key() << " with " - << pdigcon->size() << " entries." ); - } else { - ATH_MSG_WARNING ( "Failure to retrieve strip container " << m_digit_key.key() ); - return StatusCode::SUCCESS; - } - - - //********************************************** - // retrieve specific collection for the givenID - const CscStripPrepDataCollection * col = pdigcon->indexFindPtr(givenHashId); - if (nullptr == col) { - unsigned int coll_hash = givenHashId; - ATH_MSG_WARNING ( "Specific CSC Strip PrepData collection retrieving failed for collection hash = " - << coll_hash ); - return StatusCode::SUCCESS; - } - - ATH_MSG_DEBUG ( "Retrieved " << col->size() << " CSC Strip PrepDatas." ); - - Identifier colid = col->identify(); - int istation = m_idHelperSvc->cscIdHelper().stationName(colid) - 49; - int zsec = m_idHelperSvc->cscIdHelper().stationEta(colid); - int phisec = m_idHelperSvc->cscIdHelper().stationPhi(colid); - - ATH_MSG_DEBUG ( " Strip collection " << chamber(istation, zsec, phisec) - << " has " << col->size() << " strips" ); - - // Create arrays to hold digits and cathode plane parameters. - vector<const CscStripPrepData*> strips[8]; - int maxstrip[8] = {0, 0, 0, 0, 0, 0, 0, 0}; - - // retrieve MuonDetectorManager from the conditions store - SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey}; - const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr(); - if(MuonDetMgr==nullptr){ - ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object"); - return StatusCode::FAILURE; - } - - IdentifierHash hash; - // Loop over digits and fill these arrays. - for ( CscStripPrepDataCollection::const_iterator idig=col->begin(); - idig!=col->end(); ++idig ) { - const CscStripPrepData& dig = **idig; - Identifier did = dig.identify(); - hash=dig.collectionHash(); - const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(did); - int wlay = m_idHelperSvc->cscIdHelper().wireLayer(did); - int measphi = m_idHelperSvc->cscIdHelper().measuresPhi(did); - int idx = 2*(wlay-1) + measphi; - // First entry for a cathode plane, initialize. - if ( maxstrip[idx] == 0 ) { - maxstrip[idx] = pro->maxNumberOfStrips(measphi); - for ( int istrip=0; istrip<maxstrip[idx]; ++istrip ) - strips[idx].push_back(0); - } - int istrip = m_idHelperSvc->cscIdHelper().strip(did) - 1; - if ( istrip<0 || istrip>=maxstrip[idx] ) { - ATH_MSG_WARNING ( "Invalid strip number" ); - continue; + // Retrieve the CSC digits for this event. + SG::ReadHandle<CscStripPrepDataContainer> pdigcon(m_digit_key); + if (pdigcon.isValid()) { + ATH_MSG_DEBUG("Retrieved strip container " << m_digit_key.key() << " with " << pdigcon->size() << " entries."); + } else { + ATH_MSG_WARNING("Failure to retrieve strip container " << m_digit_key.key()); + return StatusCode::SUCCESS; } - strips[idx][istrip] = &dig; - } - - // Cluster. - CscPrepDataCollection* newCollection = 0; - for ( int measphi=0; measphi<2; ++measphi ) { - for ( int wlay=1; wlay<5; ++wlay ) { - int idx = 2*(wlay-1) + measphi; - if ( maxstrip[idx] ) { - make_clusters(measphi, strips[idx],newCollection); - ATH_MSG_DEBUG ( " " << wlay << "th layer "); - } - } - } - if (newCollection){ - if ( m_cluster_handle->addCollection(newCollection, hash).isFailure() ) { - ATH_MSG_ERROR ( "Couldn't add CscPrepdataCollection to container!" ); - return StatusCode::FAILURE; + + + //********************************************** + // retrieve specific collection for the givenID + const CscStripPrepDataCollection* col = pdigcon->indexFindPtr(givenHashId); + if (nullptr == col) { + unsigned int coll_hash = givenHashId; + ATH_MSG_WARNING("Specific CSC Strip PrepData collection retrieving failed for collection hash = " << coll_hash); + return StatusCode::SUCCESS; } - decodedIds.push_back(hash); //Record that this collection contains data - } - - return StatusCode::SUCCESS; -} + ATH_MSG_DEBUG("Retrieved " << col->size() << " CSC Strip PrepDatas."); -//****************************************************************************** + Identifier colid = col->identify(); + int istation = m_idHelperSvc->cscIdHelper().stationName(colid) - 49; + int zsec = m_idHelperSvc->cscIdHelper().stationEta(colid); + int phisec = m_idHelperSvc->cscIdHelper().stationPhi(colid); + + ATH_MSG_DEBUG(" Strip collection " << chamber(istation, zsec, phisec) << " has " << col->size() << " strips"); -StatusCode CscPeakThresholdClusterBuilderTool::getClusters(std::vector<IdentifierHash>& decodedIds) { - - // Retrieve the CSC digits for this event. - - SG::ReadHandle<CscStripPrepDataContainer> pdigcon(m_digit_key); - if ( pdigcon.isValid() ) { - ATH_MSG_DEBUG ( "Retrieved strip container " << m_digit_key.key() << " with " - << pdigcon->size() << " entries." ); - } else { - ATH_MSG_WARNING ( "Failure to retrieve strip container " << m_digit_key.key() ); - return StatusCode::SUCCESS; - } - - // Loop over digit collections. - // This a loop over chambers (each with 4 wire planes). - const CscStripPrepDataContainer& con = *pdigcon; - for (CscStripPrepDataContainer::const_iterator icol=con.begin(); - icol!=con.end(); ++icol) { - const CscStripPrepDataCollection& col = **icol; - Identifier colid = col.identify(); - int istation = m_idHelperSvc->cscIdHelper().stationName(colid) - 49; - int zsec = m_idHelperSvc->cscIdHelper().stationEta(colid); - int phisec = m_idHelperSvc->cscIdHelper().stationPhi(colid); - ATH_MSG_DEBUG ( " Strip collection " << chamber(istation, zsec, phisec) - << " has " << col.size() << " strips" ); - // Create arrays to hold digits and cathode plane parameters. vector<const CscStripPrepData*> strips[8]; - int maxstrip[8] = {0, 0, 0, 0, 0, 0, 0, 0}; - - // retrieve MuonDetectorManager from the conditions store - SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey}; - const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr(); - if(MuonDetMgr==nullptr){ - ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object"); - return StatusCode::FAILURE; + int maxstrip[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + + // retrieve MuonDetectorManager from the conditions store + SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey}; + const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr(); + if (MuonDetMgr == nullptr) { + ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object"); + return StatusCode::FAILURE; } IdentifierHash hash; // Loop over digits and fill these arrays. - for ( CscStripPrepDataCollection::const_iterator idig=col.begin(); - idig!=col.end(); ++idig ) { - const CscStripPrepData& dig = **idig; - Identifier did = dig.identify(); - hash=dig.collectionHash(); - const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(did); - int wlay = m_idHelperSvc->cscIdHelper().wireLayer(did); - int measphi = m_idHelperSvc->cscIdHelper().measuresPhi(did); - int idx = 2*(wlay-1) + measphi; - // First entry for a cathode plane, initialize. - if ( maxstrip[idx] == 0 ) { - maxstrip[idx] = pro->maxNumberOfStrips(measphi); - for ( int istrip=0; istrip<maxstrip[idx]; ++istrip ) - strips[idx].push_back(0); - } - int istrip = m_idHelperSvc->cscIdHelper().strip(did) - 1; - if ( istrip<0 || istrip>=maxstrip[idx] ) { - ATH_MSG_WARNING ( "Invalid strip number" ); - continue; - } - strips[idx][istrip] = &dig; + for (CscStripPrepDataCollection::const_iterator idig = col->begin(); idig != col->end(); ++idig) { + const CscStripPrepData& dig = **idig; + Identifier did = dig.identify(); + hash = dig.collectionHash(); + const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(did); + int wlay = m_idHelperSvc->cscIdHelper().wireLayer(did); + int measphi = m_idHelperSvc->cscIdHelper().measuresPhi(did); + int idx = 2 * (wlay - 1) + measphi; + // First entry for a cathode plane, initialize. + if (maxstrip[idx] == 0) { + maxstrip[idx] = pro->maxNumberOfStrips(measphi); + for (int istrip = 0; istrip < maxstrip[idx]; ++istrip) strips[idx].push_back(0); + } + int istrip = m_idHelperSvc->cscIdHelper().strip(did) - 1; + if (istrip < 0 || istrip >= maxstrip[idx]) { + ATH_MSG_WARNING("Invalid strip number"); + continue; + } + strips[idx][istrip] = &dig; } - + // Cluster. CscPrepDataCollection* newCollection = 0; - for ( int measphi=0; measphi<2; ++measphi ) { - for ( int wlay=1; wlay<5; ++wlay ) { - int idx = 2*(wlay-1) + measphi; - if ( maxstrip[idx] ) { - make_clusters(measphi, strips[idx],newCollection); - ATH_MSG_DEBUG ( " " << wlay << "th layer "); + for (int measphi = 0; measphi < 2; ++measphi) { + for (int wlay = 1; wlay < 5; ++wlay) { + int idx = 2 * (wlay - 1) + measphi; + if (maxstrip[idx]) { + make_clusters(measphi, strips[idx], newCollection); + ATH_MSG_DEBUG(" " << wlay << "th layer "); + } } - } } - if (newCollection){ - if ( m_cluster_handle->addCollection(newCollection, hash).isFailure() ) { - ATH_MSG_ERROR ( "Couldn't add CscPrepdataCollection to container!" ); - return StatusCode::FAILURE; - } - decodedIds.push_back(hash); //Record that this collection contains data + if (newCollection) { + if (m_cluster_handle->addCollection(newCollection, hash).isFailure()) { + ATH_MSG_ERROR("Couldn't add CscPrepdataCollection to container!"); + return StatusCode::FAILURE; + } + decodedIds.push_back(hash); // Record that this collection contains data } - } // end loop over chambers - - return StatusCode::SUCCESS; + + return StatusCode::SUCCESS; +} + + +//****************************************************************************** + +StatusCode +CscPeakThresholdClusterBuilderTool::getClusters(std::vector<IdentifierHash>& decodedIds) +{ + + // Retrieve the CSC digits for this event. + + SG::ReadHandle<CscStripPrepDataContainer> pdigcon(m_digit_key); + if (pdigcon.isValid()) { + ATH_MSG_DEBUG("Retrieved strip container " << m_digit_key.key() << " with " << pdigcon->size() << " entries."); + } else { + ATH_MSG_WARNING("Failure to retrieve strip container " << m_digit_key.key()); + return StatusCode::SUCCESS; + } + + // Loop over digit collections. + // This a loop over chambers (each with 4 wire planes). + const CscStripPrepDataContainer& con = *pdigcon; + for (CscStripPrepDataContainer::const_iterator icol = con.begin(); icol != con.end(); ++icol) { + const CscStripPrepDataCollection& col = **icol; + Identifier colid = col.identify(); + int istation = m_idHelperSvc->cscIdHelper().stationName(colid) - 49; + int zsec = m_idHelperSvc->cscIdHelper().stationEta(colid); + int phisec = m_idHelperSvc->cscIdHelper().stationPhi(colid); + ATH_MSG_DEBUG(" Strip collection " << chamber(istation, zsec, phisec) << " has " << col.size() << " strips"); + + // Create arrays to hold digits and cathode plane parameters. + vector<const CscStripPrepData*> strips[8]; + int maxstrip[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + + // retrieve MuonDetectorManager from the conditions store + SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey}; + const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr(); + if (MuonDetMgr == nullptr) { + ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object"); + return StatusCode::FAILURE; + } + + IdentifierHash hash; + // Loop over digits and fill these arrays. + for (CscStripPrepDataCollection::const_iterator idig = col.begin(); idig != col.end(); ++idig) { + const CscStripPrepData& dig = **idig; + Identifier did = dig.identify(); + hash = dig.collectionHash(); + const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(did); + int wlay = m_idHelperSvc->cscIdHelper().wireLayer(did); + int measphi = m_idHelperSvc->cscIdHelper().measuresPhi(did); + int idx = 2 * (wlay - 1) + measphi; + // First entry for a cathode plane, initialize. + if (maxstrip[idx] == 0) { + maxstrip[idx] = pro->maxNumberOfStrips(measphi); + for (int istrip = 0; istrip < maxstrip[idx]; ++istrip) strips[idx].push_back(0); + } + int istrip = m_idHelperSvc->cscIdHelper().strip(did) - 1; + if (istrip < 0 || istrip >= maxstrip[idx]) { + ATH_MSG_WARNING("Invalid strip number"); + continue; + } + strips[idx][istrip] = &dig; + } + + // Cluster. + CscPrepDataCollection* newCollection = 0; + for (int measphi = 0; measphi < 2; ++measphi) { + for (int wlay = 1; wlay < 5; ++wlay) { + int idx = 2 * (wlay - 1) + measphi; + if (maxstrip[idx]) { + make_clusters(measphi, strips[idx], newCollection); + ATH_MSG_DEBUG(" " << wlay << "th layer "); + } + } + } + if (newCollection) { + if (m_cluster_handle->addCollection(newCollection, hash).isFailure()) { + ATH_MSG_ERROR("Couldn't add CscPrepdataCollection to container!"); + return StatusCode::FAILURE; + } + decodedIds.push_back(hash); // Record that this collection contains data + } + } // end loop over chambers + + return StatusCode::SUCCESS; } //****************************************************************************** -StatusCode CscPeakThresholdClusterBuilderTool::finalize() { - ATH_MSG_VERBOSE ( "Finalizing " << name() ); - return StatusCode::SUCCESS; +StatusCode +CscPeakThresholdClusterBuilderTool::finalize() +{ + ATH_MSG_VERBOSE("Finalizing " << name()); + return StatusCode::SUCCESS; } //****************************************************************************** @@ -398,242 +405,238 @@ StatusCode CscPeakThresholdClusterBuilderTool::finalize() { // Note strip numbering is 0, maxstA, shifted by 1 from ATLAS strip numbers. // Center of strip is at pitch * (istrip + 0.5 - maxstrip/2). -int CscPeakThresholdClusterBuilderTool:: -make_clusters(bool measphi, const vector<const CscStripPrepData*>& strips,CscPrepDataCollection *&newCollection) { - - //CscPrepDataCollection* newCollection = 0; - - // Loop over channels. - unsigned int maxstrip = strips.size(); - - ATH_MSG_DEBUG ( " Clustering for " - << setaphi(measphi) << " plane with " << maxstrip << " strips" ); - - // Loop over strips and fetch the charge and time for each. - // Also set flag indicating if this strip is active, i.e. should be included - // in a cluster. - ICscClusterFitter::StripFitList stripfits; - std::vector<bool> astrip; - IdentifierHash cscHashId; - - for ( unsigned int istrip=0; istrip<strips.size(); ++istrip ) { - const CscStripPrepData* pstrip = strips[istrip]; - ICscClusterFitter::StripFit res; - res.charge = 0.0; - res.time = -666.; - bool active = false; - - if ( pstrip ) { - if (!newCollection) { - Identifier elementId = m_idHelperSvc->cscIdHelper().elementID(pstrip->identify()); - cscHashId=pstrip->collectionHash(); - newCollection = new CscPrepDataCollection(cscHashId); - newCollection->setIdentifier(elementId); - } - if ( ! m_pstrip_fitter ) { - ATH_MSG_WARNING ( "Unable to locate strip fitter" ); - return 1; - } - res = m_pstrip_fitter->fit(*pstrip); - active = res.charge > 0.0; // Allow all the positive charged strips... - // Log message. - ATH_MSG_DEBUG ( " Strip " << setw(3) << istrip+1 - << ": charge= " << setw(7) << int(res.charge) - << " time=" << setw(3) << int(res.time+0.5) ); - // if ( active ) *m_log << " *"; - // else *m_log << " ."; - // if ( res.status ) *m_log << " x"; - // else *m_log << " o"; - // *m_log ); - - } - - // if (res.charge == 0.0) res.charge =40.; - stripfits.push_back(res); - astrip.push_back(active); - } - - // Loop over strips and create clusters. - bool incluster = false; - int first_strip = 0; // First strip in the cluster. - double qpeak =0; - ICscClusterFitter::StripFitList sfits; - std::vector<const CscStripPrepData*> clusterStrips; - std::vector<Identifier> prd_digit_ids; - for ( unsigned int istrip=0; istrip<strips.size(); ++istrip ) { - const CscStripPrepData* pstrip = strips[istrip]; - ICscClusterFitter::StripFit sfit = stripfits[istrip]; - double q = sfit.charge; - - // If the current strip is not active, skip it. - if ( ! astrip[istrip] ) continue; - assert( pstrip != 0 ); - - // First strip in cluster: initialize a new cluster. - if ( ! incluster ) { - incluster = true; - qpeak = q; - first_strip = istrip; - sfits.clear(); - clusterStrips.clear(); - prd_digit_ids.clear(); - incluster = true; +int +CscPeakThresholdClusterBuilderTool::make_clusters(bool measphi, const vector<const CscStripPrepData*>& strips, + CscPrepDataCollection*& newCollection) +{ + + // CscPrepDataCollection* newCollection = 0; + + // Loop over channels. + unsigned int maxstrip = strips.size(); + + ATH_MSG_DEBUG(" Clustering for " << setaphi(measphi) << " plane with " << maxstrip << " strips"); + + // Loop over strips and fetch the charge and time for each. + // Also set flag indicating if this strip is active, i.e. should be included + // in a cluster. + ICscClusterFitter::StripFitList stripfits; + std::vector<bool> astrip; + IdentifierHash cscHashId; + + for (unsigned int istrip = 0; istrip < strips.size(); ++istrip) { + const CscStripPrepData* pstrip = strips[istrip]; + ICscClusterFitter::StripFit res; + res.charge = 0.0; + res.time = -666.; + bool active = false; + + if (pstrip) { + if (!newCollection) { + Identifier elementId = m_idHelperSvc->cscIdHelper().elementID(pstrip->identify()); + cscHashId = pstrip->collectionHash(); + newCollection = new CscPrepDataCollection(cscHashId); + newCollection->setIdentifier(elementId); + } + if (!m_pstrip_fitter) { + ATH_MSG_WARNING("Unable to locate strip fitter"); + return 1; + } + res = m_pstrip_fitter->fit(*pstrip); + active = res.charge > 0.0; // Allow all the positive charged strips... + // Log message. + ATH_MSG_DEBUG(" Strip " << setw(3) << istrip + 1 << ": charge= " << setw(7) << int(res.charge) + << " time=" << setw(3) << int(res.time + 0.5)); + // if ( active ) *m_log << " *"; + // else *m_log << " ."; + // if ( res.status ) *m_log << " x"; + // else *m_log << " o"; + // *m_log ); + } + + // if (res.charge == 0.0) res.charge =40.; + stripfits.push_back(res); + astrip.push_back(active); } - // Add strip to the current cluster. - sfits.push_back(sfit); - clusterStrips.push_back(pstrip); - prd_digit_ids.push_back(pstrip->identify()); - if ( q > qpeak ) qpeak = q; + // Loop over strips and create clusters. + bool incluster = false; + int first_strip = 0; // First strip in the cluster. + double qpeak = 0; + ICscClusterFitter::StripFitList sfits; + std::vector<const CscStripPrepData*> clusterStrips; + std::vector<Identifier> prd_digit_ids; + for (unsigned int istrip = 0; istrip < strips.size(); ++istrip) { + const CscStripPrepData* pstrip = strips[istrip]; + ICscClusterFitter::StripFit sfit = stripfits[istrip]; + double q = sfit.charge; + + // If the current strip is not active, skip it. + if (!astrip[istrip]) continue; + assert(pstrip != 0); + + // First strip in cluster: initialize a new cluster. + if (!incluster) { + incluster = true; + qpeak = q; + first_strip = istrip; + sfits.clear(); + clusterStrips.clear(); + prd_digit_ids.clear(); + incluster = true; + } + + // Add strip to the current cluster. + sfits.push_back(sfit); + clusterStrips.push_back(pstrip); + prd_digit_ids.push_back(pstrip->identify()); + if (q > qpeak) qpeak = q; - - // If this is not the last strip in the plane, and the next - // strip is active, add the next strip to the cluster. - if ( istrip!=maxstrip-1 && astrip[istrip+1] ) continue; - /////////////////////////// - // Create a cluster - ATH_MSG_VERBOSE ( " Creating cluster" ); + // If this is not the last strip in the plane, and the next + // strip is active, add the next strip to the cluster. + if (istrip != maxstrip - 1 && astrip[istrip + 1]) continue; - // QPeak Threshold Requirement................. + /////////////////////////// + // Create a cluster + ATH_MSG_VERBOSE(" Creating cluster"); - if ( qpeak < (measphi ? m_qpeak_threshold_phi : m_qpeak_threshold_eta) ) { // discard cluster and find new one.... - incluster = false; - continue; - } + // QPeak Threshold Requirement................. - int fitresult = 99; - std::vector<ICscClusterFitter::Result> results; - // Precision fit. - if ( ! measphi && m_pfitter_prec ) { - ATH_MSG_VERBOSE ( " Performing precision fit with " << m_pfitter_prec ); + if (qpeak < (measphi ? m_qpeak_threshold_phi : m_qpeak_threshold_eta)) + { // discard cluster and find new one.... + incluster = false; + continue; + } - results = m_pfitter_prec->fit(sfits); - fitresult = results[0].fitStatus; + int fitresult = 99; + std::vector<ICscClusterFitter::Result> results; + // Precision fit. + if (!measphi && m_pfitter_prec) { + ATH_MSG_VERBOSE(" Performing precision fit with " << m_pfitter_prec); - ATH_MSG_VERBOSE ( " Precision fit result return=" << fitresult ); - } + results = m_pfitter_prec->fit(sfits); + fitresult = results[0].fitStatus; - if (fitresult ==6) { // in case of multipeak cluster - ATH_MSG_VERBOSE ( " Performing split fit with " << m_pfitter_split ); + ATH_MSG_VERBOSE(" Precision fit result return=" << fitresult); + } - results = m_pfitter_split->fit(sfits); - fitresult = results[0].fitStatus; + if (fitresult == 6) { // in case of multipeak cluster + ATH_MSG_VERBOSE(" Performing split fit with " << m_pfitter_split); - for (unsigned int i=0; i<results.size(); ++i) - ATH_MSG_VERBOSE ( " Split fit result return=" << results[i].fitStatus ); - } - // if splitcluster is succeeded, fitresult should be either 20 or 21 - // if not, it's 19. - - // Default fit. - if ( measphi || (fitresult >0 && fitresult <20) ) { // including measphi case - ATH_MSG_VERBOSE ( " Performing default fit with " << m_pfitter_def ); - ICscClusterFitter::Result res; - if (!measphi) res = results[0]; - CscClusterStatus oldclustatus = res.clusterStatus; - results = m_pfitter_def->fit(sfits); - res = results[0]; - fitresult = results[0].fitStatus; - if ( fitresult ) { - ATH_MSG_VERBOSE ( " Default fit failed: return=" << fitresult ); - return 1; - } else { - ATH_MSG_VERBOSE ( " Default fit succeeded" ); - } - // Keep the status from the first fit if it is defined. - if ( oldclustatus != Muon::CscStatusUndefined ) { - res.clusterStatus = oldclustatus; - // we want to keep oldcluster status - results[0] = res; - } - } - - // retrieve MuonDetectorManager from the conditions store - SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey}; - const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr(); - if(MuonDetMgr==nullptr){ - ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object"); - return 0; - } + results = m_pfitter_split->fit(sfits); + fitresult = results[0].fitStatus; - // Check results. - unsigned int nresults = results.size(); - for (unsigned int ire=0; ire<nresults; ++ire) { - - if ( results[ire].qpeak - < (measphi ? m_qpeak_threshold_phi : m_qpeak_threshold_eta) ) continue; - double q3sum = results[ire].qleft+results[ire].qpeak+results[ire].qright; - if ( q3sum - < (measphi ? m_q3sum_threshold_phi : m_q3sum_threshold_eta) ) continue; - - CscClusterStatus clustatus = results[ire].clusterStatus; - Muon::CscTimeStatus timeStatus = results[ire].timeStatus; - double pos = results[ire].position; - double err = results[ire].dposition; - unsigned int id_strip = results[ire].strip; - double cluster_charge = results[ire].charge; - double cluster_time = results[ire].time; - if ( clustatus == Muon::CscStatusUndefined ) - ATH_MSG_DEBUG ( " Csc Cluster Status is not defined." ); - - if ( id_strip >= sfits.size() ) { - ATH_MSG_WARNING ( " Fit size check failed: " ); - return 1; - } - // Fetch the strip used to identify this cluster. - const CscStripPrepData* pstrip_id = 0; - if ( id_strip < clusterStrips.size() ) pstrip_id = clusterStrips[id_strip]; - if ( ! pstrip_id ) { - ATH_MSG_WARNING ( " Fit ID check failed: " ); - return 1; - } - - // Create ATLAS CSC cluster. - Identifier cluster_id = pstrip_id->identify(); - IdentifierHash cluster_hash = pstrip_id->collectionHash(); - int zsec = m_idHelperSvc->cscIdHelper().stationEta(cluster_id); - int wlay = m_idHelperSvc->cscIdHelper().wireLayer(cluster_id); - // This local position is in the muon (not tracking) coordinate system. - // const CscReadoutElement* pro = pstrip_id->detectorElement(); - const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(cluster_id); - Amg::Vector3D local_pos = pro->nominalLocalClusterPos(zsec, wlay, measphi, pos); - Amg::MatrixX* cov = new Amg::MatrixX(1,1); - (*cov)(0,0) = err*err; - Amg::Vector2D plpos( measphi ? local_pos.y(): local_pos.z(), measphi ? local_pos.z(): local_pos.y()); - - if( msgLvl(MSG::DEBUG) ){ - ATH_MSG_DEBUG ( " Cluster parameters: " << nresults ); - ATH_MSG_DEBUG ( " ID strip: " << first_strip + id_strip - << "(" << first_strip << ":" << id_strip << ")" ); - ATH_MSG_DEBUG ( " local position: " - << plpos.x() << " " << plpos.y() ); - ATH_MSG_DEBUG ( " error: " << Amg::toString(*cov) ); - ATH_MSG_DEBUG ( " charge: " << cluster_charge ); - ATH_MSG_DEBUG ( " time: " << cluster_time ); - ATH_MSG_DEBUG ( " status: " << Muon::toString(clustatus) ); - } - std::vector<Identifier> prd_digit_ids_submit; - unsigned int fstrip =results[ire].fstrip; - unsigned int lstrip =results[ire].lstrip; - prd_digit_ids_submit.reserve(lstrip+1); - for ( unsigned int ids_index=fstrip; ids_index<lstrip+1; ++ids_index ) { - if( ids_index >= prd_digit_ids.size() ) ATH_MSG_WARNING(" bad index " << ids_index << " maximum " << prd_digit_ids.size() ); - else prd_digit_ids_submit.push_back(prd_digit_ids[ids_index]); - } - - CscPrepData* pclus = new CscPrepData(cluster_id, cluster_hash, plpos, prd_digit_ids_submit, - cov, pro, int(cluster_charge+0.5), cluster_time, - clustatus, timeStatus); - pclus->setHashAndIndex(newCollection->identifyHash(), newCollection->size()); - - newCollection->push_back(pclus); + for (unsigned int i = 0; i < results.size(); ++i) + ATH_MSG_VERBOSE(" Split fit result return=" << results[i].fitStatus); + } + // if splitcluster is succeeded, fitresult should be either 20 or 21 + // if not, it's 19. + + // Default fit. + if (measphi || (fitresult > 0 && fitresult < 20)) { // including measphi case + ATH_MSG_VERBOSE(" Performing default fit with " << m_pfitter_def); + ICscClusterFitter::Result res; + if (!measphi) res = results[0]; + CscClusterStatus oldclustatus = res.clusterStatus; + results = m_pfitter_def->fit(sfits); + res = results[0]; + fitresult = results[0].fitStatus; + if (fitresult) { + ATH_MSG_VERBOSE(" Default fit failed: return=" << fitresult); + return 1; + } else { + ATH_MSG_VERBOSE(" Default fit succeeded"); + } + // Keep the status from the first fit if it is defined. + if (oldclustatus != Muon::CscStatusUndefined) { + res.clusterStatus = oldclustatus; + // we want to keep oldcluster status + results[0] = res; + } + } - } - // Reset incluster. - incluster = false; - } // end loop over strips - return 0; + // retrieve MuonDetectorManager from the conditions store + SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey}; + const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr(); + if (MuonDetMgr == nullptr) { + ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object"); + return 0; + } + + // Check results. + unsigned int nresults = results.size(); + for (unsigned int ire = 0; ire < nresults; ++ire) { + + if (results[ire].qpeak < (measphi ? m_qpeak_threshold_phi : m_qpeak_threshold_eta)) continue; + double q3sum = results[ire].qleft + results[ire].qpeak + results[ire].qright; + if (q3sum < (measphi ? m_q3sum_threshold_phi : m_q3sum_threshold_eta)) continue; + + CscClusterStatus clustatus = results[ire].clusterStatus; + Muon::CscTimeStatus timeStatus = results[ire].timeStatus; + double pos = results[ire].position; + double err = results[ire].dposition; + unsigned int id_strip = results[ire].strip; + double cluster_charge = results[ire].charge; + double cluster_time = results[ire].time; + if (clustatus == Muon::CscStatusUndefined) ATH_MSG_DEBUG(" Csc Cluster Status is not defined."); + + if (id_strip >= sfits.size()) { + ATH_MSG_WARNING(" Fit size check failed: "); + return 1; + } + // Fetch the strip used to identify this cluster. + const CscStripPrepData* pstrip_id = 0; + if (id_strip < clusterStrips.size()) pstrip_id = clusterStrips[id_strip]; + if (!pstrip_id) { + ATH_MSG_WARNING(" Fit ID check failed: "); + return 1; + } + + // Create ATLAS CSC cluster. + Identifier cluster_id = pstrip_id->identify(); + IdentifierHash cluster_hash = pstrip_id->collectionHash(); + int zsec = m_idHelperSvc->cscIdHelper().stationEta(cluster_id); + int wlay = m_idHelperSvc->cscIdHelper().wireLayer(cluster_id); + // This local position is in the muon (not tracking) coordinate system. + // const CscReadoutElement* pro = pstrip_id->detectorElement(); + const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(cluster_id); + Amg::Vector3D local_pos = pro->nominalLocalClusterPos(zsec, wlay, measphi, pos); + Amg::MatrixX* cov = new Amg::MatrixX(1, 1); + (*cov)(0, 0) = err * err; + Amg::Vector2D plpos(measphi ? local_pos.y() : local_pos.z(), measphi ? local_pos.z() : local_pos.y()); + + if (msgLvl(MSG::DEBUG)) { + ATH_MSG_DEBUG(" Cluster parameters: " << nresults); + ATH_MSG_DEBUG(" ID strip: " << first_strip + id_strip << "(" << first_strip << ":" + << id_strip << ")"); + ATH_MSG_DEBUG(" local position: " << plpos.x() << " " << plpos.y()); + ATH_MSG_DEBUG(" error: " << Amg::toString(*cov)); + ATH_MSG_DEBUG(" charge: " << cluster_charge); + ATH_MSG_DEBUG(" time: " << cluster_time); + ATH_MSG_DEBUG(" status: " << Muon::toString(clustatus)); + } + std::vector<Identifier> prd_digit_ids_submit; + unsigned int fstrip = results[ire].fstrip; + unsigned int lstrip = results[ire].lstrip; + prd_digit_ids_submit.reserve(lstrip + 1); + for (unsigned int ids_index = fstrip; ids_index < lstrip + 1; ++ids_index) { + if (ids_index >= prd_digit_ids.size()) + ATH_MSG_WARNING(" bad index " << ids_index << " maximum " << prd_digit_ids.size()); + else + prd_digit_ids_submit.push_back(prd_digit_ids[ids_index]); + } + + CscPrepData* pclus = new CscPrepData(cluster_id, cluster_hash, plpos, prd_digit_ids_submit, cov, pro, + int(cluster_charge + 0.5), cluster_time, clustatus, timeStatus); + pclus->setHashAndIndex(newCollection->identifyHash(), newCollection->size()); + + newCollection->push_back(pclus); + } + // Reset incluster. + incluster = false; + } // end loop over strips + return 0; } //****************************************************************************** diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscPeakThresholdClusterBuilderTool.h b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscPeakThresholdClusterBuilderTool.h index 6d6d5ad1bf78..db7c77350abb 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscPeakThresholdClusterBuilderTool.h +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscPeakThresholdClusterBuilderTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // CscPeakThresholdClusterBuilderTool.h @@ -55,83 +55,88 @@ // Algorithm to construct CSC clusters from digits. #include "AthenaBaseComps/AthAlgTool.h" +#include "CscClusterization/ICscClusterBuilder.h" +#include "CscClusterization/ICscClusterFitter.h" +#include "CscClusterization/ICscStripFitter.h" #include "GaudiKernel/ToolHandle.h" +#include "MuonIdHelpers/IMuonIdHelperSvc.h" #include "MuonPrepRawData/MuonPrepDataContainer.h" -#include "CscClusterization/ICscStripFitter.h" -#include "CscClusterization/ICscClusterFitter.h" -#include "CscClusterization/ICscClusterBuilder.h" - #include "MuonReadoutGeometry/MuonDetectorManager.h" -#include "MuonIdHelpers/IMuonIdHelperSvc.h" namespace Muon { - class CscPrepData; - class CscStripPrepData; -} +class CscPrepData; +class CscStripPrepData; +} // namespace Muon typedef Muon::CscPrepData MyCscDigit; class CscDigit; class CscPeakThresholdClusterBuilderTool : virtual public ICscClusterBuilder, public AthAlgTool { - -public: // methods - - // Constructor. - CscPeakThresholdClusterBuilderTool(const std::string &type, const std::string &aname, const IInterface* ); - - // Destructor. - ~CscPeakThresholdClusterBuilderTool(); - - /** AlgTool InterfaceID - */ - // static const InterfaceID& interfaceID( ) ; - - - // Initialization. - StatusCode initialize(); - - // Event processing. - StatusCode getClusters(std::vector<IdentifierHash>& idVect, std::vector<IdentifierHash>& selectedIdVect); - - // Finalization. - StatusCode finalize(); - -private: // Private methods. - - // Cluster a cathode plane. - // int make_clusters(bool dump, int maxstrip, double pitch, - // const std::vector<MyCscDigit*>& idstrip, const std::vector<double>& qstrip); - // int make_clusters(bool dump, int maxstrip, double pitch, const std::vector<Muon::CscStripPrepData*>& strips); - int make_clusters(bool measphi, const std::vector<const Muon::CscStripPrepData*>& strips,Muon::CscPrepDataCollection *&collection); - StatusCode getClusters(IdentifierHash idVect, std::vector<IdentifierHash>& selectedIdVect); - StatusCode getClusters(std::vector<IdentifierHash>& selectedIdVect); -private: // data - - // Properties. - double m_qpeak_threshold_eta; // Charge qpeak threshold to include strip in cluster - double m_qpeak_threshold_phi; // Charge qpeak threshold to include strip in cluster - double m_q3sum_threshold_eta; // Charge qleft+qpeak+qright threshold to include strip in cluster - double m_q3sum_threshold_phi; // Charge qleft+qpeak+qright threshold to include strip in cluster - SG::ReadHandleKey<Muon::CscStripPrepDataContainer> m_digit_key; // SG key for input digits - SG::WriteHandle<Muon::CscPrepDataContainer> m_cluster_handle; // SG key for output clusters - - // Strip fitter. - ToolHandle<ICscStripFitter> m_pstrip_fitter; - - // Cluster fitters. - ToolHandle<ICscClusterFitter> m_pfitter_def; - ToolHandle<ICscClusterFitter> m_pfitter_prec; - ToolHandle<ICscClusterFitter> m_pfitter_split; - - ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}; - - /** retrieve MuonDetectorManager from the conditions store */ - SG::ReadCondHandleKey<MuonGM::MuonDetectorManager> m_DetectorManagerKey {this, "DetectorManagerKey", - "MuonDetectorManager", "Key of input MuonDetectorManager condition data"}; - - // keep track of full event being already processed - bool m_fullEventDone; - + + public: // methods + // Constructor. + CscPeakThresholdClusterBuilderTool(const std::string& type, const std::string& aname, const IInterface*); + + // Destructor. + ~CscPeakThresholdClusterBuilderTool(); + + /** AlgTool InterfaceID + */ + // static const InterfaceID& interfaceID( ) ; + + + // Initialization. + StatusCode initialize(); + + // Event processing. + StatusCode getClusters(std::vector<IdentifierHash>& idVect, std::vector<IdentifierHash>& selectedIdVect); + + // Finalization. + StatusCode finalize(); + + private: // Private methods. + // Cluster a cathode plane. + // int make_clusters(bool dump, int maxstrip, double pitch, + // const std::vector<MyCscDigit*>& idstrip, const std::vector<double>& qstrip); + // int make_clusters(bool dump, int maxstrip, double pitch, const std::vector<Muon::CscStripPrepData*>& strips); + int make_clusters(bool measphi, const std::vector<const Muon::CscStripPrepData*>& strips, + Muon::CscPrepDataCollection*& collection); + StatusCode getClusters(IdentifierHash idVect, std::vector<IdentifierHash>& selectedIdVect); + StatusCode getClusters(std::vector<IdentifierHash>& selectedIdVect); + + private: // data + // Properties. + double m_qpeak_threshold_eta; // Charge qpeak threshold to include strip in cluster + double m_qpeak_threshold_phi; // Charge qpeak threshold to include strip in cluster + double m_q3sum_threshold_eta; // Charge qleft+qpeak+qright threshold to include strip in cluster + double m_q3sum_threshold_phi; // Charge qleft+qpeak+qright threshold to include strip in cluster + SG::ReadHandleKey<Muon::CscStripPrepDataContainer> m_digit_key; // SG key for input digits + SG::WriteHandle<Muon::CscPrepDataContainer> m_cluster_handle; // SG key for output clusters + + // Strip fitter. + ToolHandle<ICscStripFitter> m_pstrip_fitter; + + // Cluster fitters. + ToolHandle<ICscClusterFitter> m_pfitter_def; + ToolHandle<ICscClusterFitter> m_pfitter_prec; + ToolHandle<ICscClusterFitter> m_pfitter_split; + + ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc{ + this, + "MuonIdHelperSvc", + "Muon::MuonIdHelperSvc/MuonIdHelperSvc", + }; + + /** retrieve MuonDetectorManager from the conditions store */ + SG::ReadCondHandleKey<MuonGM::MuonDetectorManager> m_DetectorManagerKey{ + this, + "DetectorManagerKey", + "MuonDetectorManager", + "Key of input MuonDetectorManager condition data", + }; + + // keep track of full event being already processed + bool m_fullEventDone; }; #endif diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscSplitClusterFitter.cxx b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscSplitClusterFitter.cxx index eeb86a61ad77..0395a5b015d4 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscSplitClusterFitter.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscSplitClusterFitter.cxx @@ -4,346 +4,348 @@ #include "CscSplitClusterFitter.h" +#include <iomanip> +#include <sstream> + #include "MuonPrepRawData/CscClusterStatus.h" #include "MuonPrepRawData/CscPrepData.h" #include "MuonPrepRawData/CscStripPrepData.h" #include "MuonReadoutGeometry/CscReadoutElement.h" -#include <sstream> -#include <iomanip> - using Muon::CscClusterStatus; using Muon::CscPrepData; using Muon::CscStripPrepData; using MuonGM::CscReadoutElement; typedef ICscClusterFitter::DataNames DataNames; -typedef ICscClusterFitter::Result Result; -typedef std::vector<Result> Results; +typedef ICscClusterFitter::Result Result; +typedef std::vector<Result> Results; enum CscStation { UNKNOWN_STATION, CSS, CSL }; enum CscPlane { CSS_ETA, CSL_ETA, CSS_PHI, CSL_PHI, UNKNOWN_PLANE }; //****************************************************************************** -CscSplitClusterFitter::CscSplitClusterFitter(std::string type, std::string aname, const IInterface* parent) : - AthAlgTool(type, aname, parent), - m_pfitter_def("SimpleCscClusterFitter/SimpleCscClusterFitter"), - m_pfitter_prec("QratCscClusterFitter/QratCscClusterFitter") +CscSplitClusterFitter::CscSplitClusterFitter(std::string type, std::string aname, const IInterface* parent) + : AthAlgTool(type, aname, parent), + m_pfitter_def("SimpleCscClusterFitter/SimpleCscClusterFitter"), + m_pfitter_prec("QratCscClusterFitter/QratCscClusterFitter") { - declareInterface<ICscClusterFitter>(this); - declareProperty("default_fitter", m_pfitter_def); - declareProperty("precision_fitter", m_pfitter_prec); - declareProperty("min_dist", m_min_dist = 2); // Minimum distance between peaks and valley - declareProperty("max_qratio", m_max_qratio = 0.15); // Maximum charge ratio between peak strip and valley strip + declareInterface<ICscClusterFitter>(this); + declareProperty("default_fitter", m_pfitter_def); + declareProperty("precision_fitter", m_pfitter_prec); + declareProperty("min_dist", m_min_dist = 2); // Minimum distance between peaks and valley + declareProperty("max_qratio", m_max_qratio = 0.15); // Maximum charge ratio between peak strip and valley strip } //********************************************************************** -StatusCode CscSplitClusterFitter::initialize() { - ATH_MSG_DEBUG ("Initalizing " << name()); - - ATH_CHECK(m_idHelperSvc.retrieve()); - - // Retrieve the default cluster fitting tool. - if ( m_pfitter_def.retrieve().isFailure() ) { - ATH_MSG_ERROR ( "Unable to retrieve Csc default cluster fitting tool " << name() - << ": unable to retrieve cluster fitter " << m_pfitter_def ); - return StatusCode::RECOVERABLE; - } - ATH_MSG_DEBUG ( "CscClusterization " << name() << ": retrieved " << m_pfitter_def ); - - // Retrieve the precision cluster fitting tool. - if ( m_pfitter_prec.retrieve().isFailure() ) { - ATH_MSG_ERROR ( "Unable to retrieve Csc default cluster fitting tool " << name() - << ": unable to retrieve cluster fitter " << m_pfitter_prec ); - return StatusCode::RECOVERABLE; - } - ATH_MSG_DEBUG ( "CscClusterization " << name() << ": retrieved " << m_pfitter_prec ); - - ATH_MSG_DEBUG ( "Properties for " << name() << ":" ); - ATH_MSG_DEBUG ( " Default cluster fitter is " << m_pfitter_def.typeAndName() ); - ATH_MSG_DEBUG ( " Precision cluster fitter is " << m_pfitter_prec.typeAndName() ); - ATH_MSG_DEBUG ( " Min dist peak to valley: " << m_min_dist ); - ATH_MSG_DEBUG ( " Max qratio qval / qpeak: " << m_max_qratio ); - - return StatusCode::SUCCESS; +StatusCode +CscSplitClusterFitter::initialize() +{ + ATH_MSG_DEBUG("Initalizing " << name()); + + ATH_CHECK(m_idHelperSvc.retrieve()); + + // Retrieve the default cluster fitting tool. + if (m_pfitter_def.retrieve().isFailure()) { + ATH_MSG_ERROR("Unable to retrieve Csc default cluster fitting tool " + << name() << ": unable to retrieve cluster fitter " << m_pfitter_def); + return StatusCode::RECOVERABLE; + } + ATH_MSG_DEBUG("CscClusterization " << name() << ": retrieved " << m_pfitter_def); + + // Retrieve the precision cluster fitting tool. + if (m_pfitter_prec.retrieve().isFailure()) { + ATH_MSG_ERROR("Unable to retrieve Csc default cluster fitting tool " + << name() << ": unable to retrieve cluster fitter " << m_pfitter_prec); + return StatusCode::RECOVERABLE; + } + ATH_MSG_DEBUG("CscClusterization " << name() << ": retrieved " << m_pfitter_prec); + + ATH_MSG_DEBUG("Properties for " << name() << ":"); + ATH_MSG_DEBUG(" Default cluster fitter is " << m_pfitter_def.typeAndName()); + ATH_MSG_DEBUG(" Precision cluster fitter is " << m_pfitter_prec.typeAndName()); + ATH_MSG_DEBUG(" Min dist peak to valley: " << m_min_dist); + ATH_MSG_DEBUG(" Max qratio qval / qpeak: " << m_max_qratio); + + return StatusCode::SUCCESS; } //********************************************************************** -Results CscSplitClusterFitter::fit(const StripFitList& sfits) const { - - Results results; - // Check input has at least three strips. - unsigned int nstrip = sfits.size(); - // Use the first strip to extract the layer parameters. - const CscStripPrepData* pstrip = sfits[0].strip; - Identifier idStrip0 = pstrip->identify(); - bool measphi = m_idHelperSvc->cscIdHelper().CscIdHelper::measuresPhi(idStrip0); - - // Display input strips. - ATH_MSG_DEBUG ( "CscStrip fittter input has " << nstrip << " strips" ); - - for (unsigned int istrip=0; istrip<nstrip; ++istrip ) { - Identifier id = sfits[istrip].strip->identify(); - ATH_MSG_VERBOSE ( " " << istrip << " " << m_idHelperSvc->cscIdHelper().strip(id) << " " << sfits[istrip].charge ); - } - // Find the peak strip and valley strip - // Loop over strips - std::vector<float>istrip_peaks; - std::vector<float>istrip_vals; - - - // Start peak all the time... - for ( unsigned int istrip=1; istrip<nstrip-1; ++istrip ) { - StripFit sfit = sfits[istrip]; - float qthis = sfit.charge; - float qlast = sfits[istrip-1].charge; - float qnext = sfits[istrip+1].charge; - // Peak at first - if (istrip==1 && qlast>qthis) istrip_peaks.push_back(0); - // Peak at last - if (istrip+2==nstrip && qthis<qnext) istrip_peaks.push_back(nstrip-1); - // Peak if the adjacent strips have less charge. - bool ispeak = qthis > qlast && qthis > qnext; - bool isval = qthis < qlast && qthis < qnext; - // Record if peak. - - if ( ispeak ) istrip_peaks.push_back(istrip); - if ( isval ) istrip_vals.push_back(istrip); - if (ispeak || isval) continue; - - //It's only for istrip==1 and 0th and 1st charges are same.... - if ( istrip==1 && qlast == qthis ) { - float nstripsameCharge =2.; - unsigned int theStrip=0; - for ( unsigned int mstrip=istrip+1; mstrip<nstrip-1; ++mstrip ) { - theStrip = mstrip; - if (qthis == sfits[mstrip].charge) - nstripsameCharge+=1.; - else - break; - } - ispeak = (qthis > sfits[theStrip].charge); - isval = (qthis < sfits[theStrip].charge); - float offset = 0.5*(nstripsameCharge-1); - if ( ispeak ) istrip_peaks.push_back(offset); - // We want to start peak all the time... - // if ( isval ) istrip_vals.push_back(offset); - istrip+= int(nstripsameCharge)-2; - continue; +Results +CscSplitClusterFitter::fit(const StripFitList& sfits) const +{ + + Results results; + // Check input has at least three strips. + unsigned int nstrip = sfits.size(); + // Use the first strip to extract the layer parameters. + const CscStripPrepData* pstrip = sfits[0].strip; + Identifier idStrip0 = pstrip->identify(); + bool measphi = m_idHelperSvc->cscIdHelper().CscIdHelper::measuresPhi(idStrip0); + + // Display input strips. + ATH_MSG_DEBUG("CscStrip fittter input has " << nstrip << " strips"); + + for (unsigned int istrip = 0; istrip < nstrip; ++istrip) { + Identifier id = sfits[istrip].strip->identify(); + ATH_MSG_VERBOSE(" " << istrip << " " << m_idHelperSvc->cscIdHelper().strip(id) << " " << sfits[istrip].charge); } + // Find the peak strip and valley strip + // Loop over strips + std::vector<float> istrip_peaks; + std::vector<float> istrip_vals; + + + // Start peak all the time... + for (unsigned int istrip = 1; istrip < nstrip - 1; ++istrip) { + StripFit sfit = sfits[istrip]; + float qthis = sfit.charge; + float qlast = sfits[istrip - 1].charge; + float qnext = sfits[istrip + 1].charge; + // Peak at first + if (istrip == 1 && qlast > qthis) istrip_peaks.push_back(0); + // Peak at last + if (istrip + 2 == nstrip && qthis < qnext) istrip_peaks.push_back(nstrip - 1); + // Peak if the adjacent strips have less charge. + bool ispeak = qthis > qlast && qthis > qnext; + bool isval = qthis < qlast && qthis < qnext; + // Record if peak. + + if (ispeak) istrip_peaks.push_back(istrip); + if (isval) istrip_vals.push_back(istrip); + if (ispeak || isval) continue; + + // It's only for istrip==1 and 0th and 1st charges are same.... + if (istrip == 1 && qlast == qthis) { + float nstripsameCharge = 2.; + unsigned int theStrip = 0; + for (unsigned int mstrip = istrip + 1; mstrip < nstrip - 1; ++mstrip) { + theStrip = mstrip; + if (qthis == sfits[mstrip].charge) + nstripsameCharge += 1.; + else + break; + } + ispeak = (qthis > sfits[theStrip].charge); + isval = (qthis < sfits[theStrip].charge); + float offset = 0.5 * (nstripsameCharge - 1); + if (ispeak) istrip_peaks.push_back(offset); + // We want to start peak all the time... + // if ( isval ) istrip_vals.push_back(offset); + istrip += int(nstripsameCharge) - 2; + continue; + } - // Special case: next strip has the same charge. - // Require the previous strip has less charge and the next following - // strip be absent or have less charge. - if ( qthis == qnext ) { - float nstripsameCharge =2.; - unsigned int theStrip=0; - bool sameCharge =1; - for ( unsigned int mstrip=istrip+2; mstrip<nstrip-1; ++mstrip ) { - theStrip = mstrip; - if (qthis == sfits[mstrip].charge) - nstripsameCharge+=1.; - else { - sameCharge =0; - break; + // Special case: next strip has the same charge. + // Require the previous strip has less charge and the next following + // strip be absent or have less charge. + if (qthis == qnext) { + float nstripsameCharge = 2.; + unsigned int theStrip = 0; + bool sameCharge = 1; + for (unsigned int mstrip = istrip + 2; mstrip < nstrip - 1; ++mstrip) { + theStrip = mstrip; + if (qthis == sfits[mstrip].charge) + nstripsameCharge += 1.; + else { + sameCharge = 0; + break; + } + } + if (sameCharge) { + ispeak = (qthis > qlast); + isval = (qthis < qlast); + } else { + ispeak = (qthis > qlast) && (qthis > sfits[theStrip].charge); + isval = (qthis < qlast) && (qthis < sfits[theStrip].charge); + } + float offset = 0.5 * (nstripsameCharge - 1); + if (ispeak) istrip_peaks.push_back(istrip + offset); + if (isval) istrip_vals.push_back(istrip + offset); + istrip += int(nstripsameCharge) - 1; + continue; } - } - if (sameCharge) { - ispeak = ( qthis > qlast ); - isval = ( qthis < qlast ); - } else { - ispeak = ( qthis > qlast ) && (qthis > sfits[theStrip].charge); - isval = ( qthis < qlast ) && (qthis < sfits[theStrip].charge); - } - float offset = 0.5*(nstripsameCharge-1); - if ( ispeak ) istrip_peaks.push_back(istrip+offset); - if ( isval ) istrip_vals.push_back(istrip+offset); - istrip+= int(nstripsameCharge)-1; - continue; - } - } - - ATH_MSG_DEBUG ( " #Peak is " << istrip_peaks.size() ); - - // Decide in which valley strip we split cluster - // Starting from Peak all the time!!! - // Regular case : #peaks - #vals =1 - // If #peaks == $vals, avoid it at the end of vals.. - - std::vector<unsigned int>splitOnValley; - for ( unsigned int ival=0; - ival<istrip_vals.size() && ival+1 < istrip_peaks.size(); - ++ival ) { - - // Set initial strip position. - float istrip_peak0 = istrip_peaks[ival]; - float istrip_peak1 = istrip_peaks[ival+1]; - float istrip_val = istrip_vals[ival]; - - float dist_ptov =istrip_val-istrip_peak0; - float dist_vtop =istrip_peak1-istrip_val; - - ATH_MSG_DEBUG ( " [ " << istrip_peak0 << ", " << istrip_val << ", " << istrip_peak1 << "] " - << "dist p2v:v2p " << dist_ptov << " : " << dist_vtop ); - - - if (dist_ptov <0 || dist_vtop <0) { - ATH_MSG_WARNING ( " Peak-to-Val dist is " << dist_ptov - << " Val-to-Peak dist is " << dist_vtop - << " Shouldnot be negative value :" - << istrip_peak0 << " " << istrip_val << " " << istrip_peak1 ); } - float qlpeak = sfits[int(istrip_peak0)].charge; - float qval = sfits[int(istrip_val)].charge; - float qrpeak = sfits[int(istrip_peak1)].charge; - - ATH_MSG_DEBUG ( "qlpk:qval:qrpk " << qlpeak << " " << qval << " " << qrpeak << " " - << qval/qlpeak << " " << qval/qrpeak << " " << m_max_qratio ); - - if (dist_ptov < m_min_dist || dist_vtop < m_min_dist || - qval/qlpeak > m_max_qratio || qval/qrpeak > m_max_qratio) - splitOnValley.push_back(0); - else - splitOnValley.push_back(1); - } - - unsigned int cnt=0; - for (unsigned int ii=0; ii<splitOnValley.size(); ii++) - if (splitOnValley[ii]==1) cnt++; - - if (cnt==0) { - ATH_MSG_DEBUG ( "No split cluster " ); - ICscClusterFitter::Result res; - res.fitStatus=6; - res.clusterStatus = Muon::CscStatusWide; - results.push_back(res); - return results; - } - ATH_MSG_DEBUG ( "Cluster is split " ); - - // For the last cluster and strip - unsigned int nvals = splitOnValley.size(); - if (istrip_vals[nvals-1] != nstrip-1) { - istrip_vals.push_back(nstrip-1); - splitOnValley.push_back(1); - nvals = splitOnValley.size(); - } - - // if (splitOnValley.size() != istrip_peaks.size()) - // ATH_MSG_ERROR << " splitOnValley.size() should be same as istrip_peaks.size()" ); - - // Rearrange strips to submit in fitter - StripFitList sfits_split; - unsigned int firstStripID =0; - unsigned int thisfirstStripID =0; - for ( unsigned int isplit=0; isplit<nvals; ++isplit ) { - - if (splitOnValley[isplit]) { - sfits_split.clear(); - - for ( unsigned int ist=firstStripID; ist<=istrip_vals[isplit]; ++ist){ - ATH_MSG_DEBUG ( ist << " " << firstStripID << " " << istrip_vals - << " lsplit " << splitOnValley ); - - sfits_split.push_back(sfits[ist]); - } - // unsigned int split_nstrip = istrip_vals[isplit]-firstStripID; - // bool ledge = (isplit==0 && strip0 <=0) ? 1 : 0; - // bool redge = (isplit==nvals-1 && strip0+nstrip>maxstrip) ? 1 : 0; - - thisfirstStripID = firstStripID; - firstStripID = int(istrip_vals[isplit]); - - int fitresult = 99; - std::vector<ICscClusterFitter::Result> local_results; - ICscClusterFitter::Result res; - // Precision fit. - if ( !measphi && m_pfitter_prec ) { - ATH_MSG_VERBOSE ( " In CscSplit performing precision fit with " << m_pfitter_prec ); - - local_results = m_pfitter_prec->fit(sfits_split); - res = local_results[0]; - fitresult = res.fitStatus; - if ( fitresult ) { - ATH_MSG_VERBOSE ( " Precision fit failed: return=" << fitresult ); - } else { - ATH_MSG_VERBOSE ( " Precision fit succeeded" ); - } - } - - int prec_fitresult = fitresult; - CscClusterStatus oldclustatus = res.clusterStatus; - // Default fit. - if ( fitresult ) { // including measphi case - ATH_MSG_VERBOSE ( " Performing default fit with " << m_pfitter_def ); - local_results = m_pfitter_def->fit(sfits_split); - res = local_results[0]; - fitresult = res.fitStatus; - if ( fitresult ) { - ATH_MSG_VERBOSE ( " Default fit failed: return=" << fitresult ); - } else { - ATH_MSG_VERBOSE ( " Default fit succeeded" ); + ATH_MSG_DEBUG(" #Peak is " << istrip_peaks.size()); + + // Decide in which valley strip we split cluster + // Starting from Peak all the time!!! + // Regular case : #peaks - #vals =1 + // If #peaks == $vals, avoid it at the end of vals.. + + std::vector<unsigned int> splitOnValley; + for (unsigned int ival = 0; ival < istrip_vals.size() && ival + 1 < istrip_peaks.size(); ++ival) { + + // Set initial strip position. + float istrip_peak0 = istrip_peaks[ival]; + float istrip_peak1 = istrip_peaks[ival + 1]; + float istrip_val = istrip_vals[ival]; + + float dist_ptov = istrip_val - istrip_peak0; + float dist_vtop = istrip_peak1 - istrip_val; + + ATH_MSG_DEBUG(" [ " << istrip_peak0 << ", " << istrip_val << ", " << istrip_peak1 << "] " + << "dist p2v:v2p " << dist_ptov << " : " << dist_vtop); + + + if (dist_ptov < 0 || dist_vtop < 0) { + ATH_MSG_WARNING(" Peak-to-Val dist is " << dist_ptov << " Val-to-Peak dist is " << dist_vtop + << " Shouldnot be negative value :" << istrip_peak0 << " " + << istrip_val << " " << istrip_peak1); } - // Keep the status from the first fit if it is defined. - if ( oldclustatus != Muon::CscStatusUndefined ) - res.clusterStatus = oldclustatus; - } - - if (prec_fitresult) { // precision fitter is failed... - res.fitStatus = 20 + prec_fitresult; - - if ( oldclustatus == Muon::CscStatusSimple ) - res.clusterStatus = Muon::CscStatusSplitSimple; - else if ( oldclustatus == Muon::CscStatusEdge ) - res.clusterStatus = Muon::CscStatusSplitEdge; - else if ( oldclustatus == Muon::CscStatusMultiPeak ) - res.clusterStatus = Muon::CscStatusSplitMultiPeak; - else if ( oldclustatus == Muon::CscStatusNarrow ) - res.clusterStatus = Muon::CscStatusSplitNarrow; - else if ( oldclustatus == Muon::CscStatusWide ) - res.clusterStatus = Muon::CscStatusSplitWide; - else if ( oldclustatus == Muon::CscStatusSkewed ) - res.clusterStatus = Muon::CscStatusSplitSkewed; - else if ( oldclustatus == Muon::CscStatusQratInconsistent ) - res.clusterStatus = Muon::CscStatusSplitQratInconsistent; - else if ( oldclustatus == Muon::CscStatusStripFitFailed) - res.clusterStatus = Muon::CscStatusSplitStripFitFailed; - else if ( oldclustatus == Muon::CscStatusSaturated) - res.clusterStatus = Muon::CscStatusSplitSaturated; - - } else { // precision fit is successful - res.fitStatus = 20; - res.clusterStatus = Muon::CscStatusSplitUnspoiled; - } - // strip in Result class is filled by Qrat or SimpleClusterFitter which is only relevant to the cluster - // passed by CscSplitCluster. This should be corrected here. - // fstrip and lstrip should be defined in CscSplitClusterFitter but not for the other fitter. - res.strip = res.strip +thisfirstStripID; - res.fstrip = res.fstrip+thisfirstStripID; - res.lstrip = res.lstrip+thisfirstStripID; - - ATH_MSG_DEBUG ( " res.fitStatus " << res.fitStatus << " fitresult " - << fitresult ); - - results.push_back(res); + + float qlpeak = sfits[int(istrip_peak0)].charge; + float qval = sfits[int(istrip_val)].charge; + float qrpeak = sfits[int(istrip_peak1)].charge; + + ATH_MSG_DEBUG("qlpk:qval:qrpk " << qlpeak << " " << qval << " " << qrpeak << " " << qval / qlpeak << " " + << qval / qrpeak << " " << m_max_qratio); + + if (dist_ptov < m_min_dist || dist_vtop < m_min_dist || qval / qlpeak > m_max_qratio + || qval / qrpeak > m_max_qratio) + splitOnValley.push_back(0); + else + splitOnValley.push_back(1); + } + + unsigned int cnt = 0; + for (unsigned int ii = 0; ii < splitOnValley.size(); ii++) + if (splitOnValley[ii] == 1) cnt++; + + if (cnt == 0) { + ATH_MSG_DEBUG("No split cluster "); + ICscClusterFitter::Result res; + res.fitStatus = 6; + res.clusterStatus = Muon::CscStatusWide; + results.push_back(res); + return results; } - } //for + ATH_MSG_DEBUG("Cluster is split "); + + // For the last cluster and strip + unsigned int nvals = splitOnValley.size(); + if (istrip_vals[nvals - 1] != nstrip - 1) { + istrip_vals.push_back(nstrip - 1); + splitOnValley.push_back(1); + nvals = splitOnValley.size(); + } + + // if (splitOnValley.size() != istrip_peaks.size()) + // ATH_MSG_ERROR << " splitOnValley.size() should be same as istrip_peaks.size()" ); + + // Rearrange strips to submit in fitter + StripFitList sfits_split; + unsigned int firstStripID = 0; + unsigned int thisfirstStripID = 0; + for (unsigned int isplit = 0; isplit < nvals; ++isplit) { + + if (splitOnValley[isplit]) { + sfits_split.clear(); + + for (unsigned int ist = firstStripID; ist <= istrip_vals[isplit]; ++ist) { + ATH_MSG_DEBUG(ist << " " << firstStripID << " " << istrip_vals << " lsplit " << splitOnValley); + + sfits_split.push_back(sfits[ist]); + } + // unsigned int split_nstrip = istrip_vals[isplit]-firstStripID; + // bool ledge = (isplit==0 && strip0 <=0) ? 1 : 0; + // bool redge = (isplit==nvals-1 && strip0+nstrip>maxstrip) ? 1 : 0; + + thisfirstStripID = firstStripID; + firstStripID = int(istrip_vals[isplit]); + + int fitresult = 99; + std::vector<ICscClusterFitter::Result> local_results; + ICscClusterFitter::Result res; + // Precision fit. + if (!measphi && m_pfitter_prec) { + ATH_MSG_VERBOSE(" In CscSplit performing precision fit with " << m_pfitter_prec); + + local_results = m_pfitter_prec->fit(sfits_split); + res = local_results[0]; + fitresult = res.fitStatus; + if (fitresult) { + ATH_MSG_VERBOSE(" Precision fit failed: return=" << fitresult); + } else { + ATH_MSG_VERBOSE(" Precision fit succeeded"); + } + } + + int prec_fitresult = fitresult; + CscClusterStatus oldclustatus = res.clusterStatus; + // Default fit. + if (fitresult) { // including measphi case + ATH_MSG_VERBOSE(" Performing default fit with " << m_pfitter_def); + local_results = m_pfitter_def->fit(sfits_split); + res = local_results[0]; + fitresult = res.fitStatus; + if (fitresult) { + ATH_MSG_VERBOSE(" Default fit failed: return=" << fitresult); + } else { + ATH_MSG_VERBOSE(" Default fit succeeded"); + } + // Keep the status from the first fit if it is defined. + if (oldclustatus != Muon::CscStatusUndefined) res.clusterStatus = oldclustatus; + } + + if (prec_fitresult) { // precision fitter is failed... + res.fitStatus = 20 + prec_fitresult; + + if (oldclustatus == Muon::CscStatusSimple) + res.clusterStatus = Muon::CscStatusSplitSimple; + else if (oldclustatus == Muon::CscStatusEdge) + res.clusterStatus = Muon::CscStatusSplitEdge; + else if (oldclustatus == Muon::CscStatusMultiPeak) + res.clusterStatus = Muon::CscStatusSplitMultiPeak; + else if (oldclustatus == Muon::CscStatusNarrow) + res.clusterStatus = Muon::CscStatusSplitNarrow; + else if (oldclustatus == Muon::CscStatusWide) + res.clusterStatus = Muon::CscStatusSplitWide; + else if (oldclustatus == Muon::CscStatusSkewed) + res.clusterStatus = Muon::CscStatusSplitSkewed; + else if (oldclustatus == Muon::CscStatusQratInconsistent) + res.clusterStatus = Muon::CscStatusSplitQratInconsistent; + else if (oldclustatus == Muon::CscStatusStripFitFailed) + res.clusterStatus = Muon::CscStatusSplitStripFitFailed; + else if (oldclustatus == Muon::CscStatusSaturated) + res.clusterStatus = Muon::CscStatusSplitSaturated; + + } else { // precision fit is successful + res.fitStatus = 20; + res.clusterStatus = Muon::CscStatusSplitUnspoiled; + } + // strip in Result class is filled by Qrat or SimpleClusterFitter which is only relevant to the cluster + // passed by CscSplitCluster. This should be corrected here. + // fstrip and lstrip should be defined in CscSplitClusterFitter but not for the other fitter. + res.strip = res.strip + thisfirstStripID; + res.fstrip = res.fstrip + thisfirstStripID; + res.lstrip = res.lstrip + thisfirstStripID; + + ATH_MSG_DEBUG(" res.fitStatus " << res.fitStatus << " fitresult " << fitresult); + + results.push_back(res); + } + } // for + - - return results; + return results; } //********************************************************************** -Results CscSplitClusterFitter::fit(const StripFitList& sfits, double) const { - return fit(sfits); +Results +CscSplitClusterFitter::fit(const StripFitList& sfits, double) const +{ + return fit(sfits); } //********************************************************************** -double CscSplitClusterFitter::getCorrectedError(const CscPrepData* /*pclu*/, double /*slope*/) const { - return 0; +double +CscSplitClusterFitter::getCorrectedError(const CscPrepData* /*pclu*/, double /*slope*/) const +{ + return 0; } diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscSplitClusterFitter.h b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscSplitClusterFitter.h index 16906ed8390e..c0d4ebfa6cef 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscSplitClusterFitter.h +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscSplitClusterFitter.h @@ -10,47 +10,47 @@ // // Tool to fit a CSC cluster using adjacent charge ratios. -#include "CscClusterization/ICscClusterFitter.h" #include "AthenaBaseComps/AthAlgTool.h" +#include "CscClusterization/ICscClusterFitter.h" #include "GaudiKernel/ServiceHandle.h" #include "GaudiKernel/ToolHandle.h" - #include "MuonIdHelpers/IMuonIdHelperSvc.h" #include "MuonPrepRawData/CscClusterStatus.h" namespace Muon { - class CscPrepData; +class CscPrepData; } class CscSplitClusterFitter : virtual public ICscClusterFitter, public AthAlgTool { - -public: - - CscSplitClusterFitter(std::string, std::string, const IInterface*); - - ~CscSplitClusterFitter()=default; - - StatusCode initialize(); - - // Inherited methods. - Results fit(const StripFitList& sfits) const; - Results fit(const StripFitList& sfits, double dposdz) const; - double getCorrectedError(const Muon::CscPrepData* pclu, double slope) const; - -private: - - // Properties - // Minimum distance between peaks and valley - int m_min_dist; - // Maximum charge ratio between peak strip and valley strip - float m_max_qratio; - - ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}; - - // Cluster fitters. - ToolHandle<ICscClusterFitter> m_pfitter_def; - ToolHandle<ICscClusterFitter> m_pfitter_prec; - + + public: + CscSplitClusterFitter(std::string, std::string, const IInterface*); + + ~CscSplitClusterFitter() = default; + + StatusCode initialize(); + + // Inherited methods. + Results fit(const StripFitList& sfits) const; + Results fit(const StripFitList& sfits, double dposdz) const; + double getCorrectedError(const Muon::CscPrepData* pclu, double slope) const; + + private: + // Properties + // Minimum distance between peaks and valley + int m_min_dist; + // Maximum charge ratio between peak strip and valley strip + float m_max_qratio; + + ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc{ + this, + "MuonIdHelperSvc", + "Muon::MuonIdHelperSvc/MuonIdHelperSvc", + }; + + // Cluster fitters. + ToolHandle<ICscClusterFitter> m_pfitter_def; + ToolHandle<ICscClusterFitter> m_pfitter_prec; }; #endif diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilder.cxx b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilder.cxx index aa4f6b890ff3..1f89eb098565 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilder.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilder.cxx @@ -1,76 +1,84 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // CscThresholdClusterBuilder.cxx #include "CscThresholdClusterBuilder.h" -#include "Gaudi/Property.h" + #include <sstream> -using std::string; +#include "Gaudi/Property.h" + using std::ostringstream; +using std::string; using std::vector; //****************************************************************************** -CscThresholdClusterBuilder:: -CscThresholdClusterBuilder(const std::string& aname, ISvcLocator* pSvcLocator) : - AthAlgorithm(aname, pSvcLocator), - m_cluster_builder("CscThresholdClusterBuilderTool/CscThresholdClusterBuilderTool"){ +CscThresholdClusterBuilder::CscThresholdClusterBuilder(const std::string& aname, ISvcLocator* pSvcLocator) + : AthAlgorithm(aname, pSvcLocator), + m_cluster_builder("CscThresholdClusterBuilderTool/CscThresholdClusterBuilderTool") +{ - declareProperty("cluster_builder", m_cluster_builder); + declareProperty("cluster_builder", m_cluster_builder); } //****************************************************************************** // Destructor. -CscThresholdClusterBuilder::~CscThresholdClusterBuilder() { } +CscThresholdClusterBuilder::~CscThresholdClusterBuilder() {} //****************************************************************************** -StatusCode CscThresholdClusterBuilder::initialize(){ +StatusCode +CscThresholdClusterBuilder::initialize() +{ - ATH_MSG_DEBUG ( "Initializing " << name() ); + ATH_MSG_DEBUG("Initializing " << name()); - // Retrieve the strip fitting tool. - if ( m_cluster_builder.retrieve().isFailure() ) { - ATH_MSG_ERROR ( "Unable to retrieve strip fitting tool " << m_cluster_builder ); - return StatusCode::FAILURE; - } + // Retrieve the strip fitting tool. + if (m_cluster_builder.retrieve().isFailure()) { + ATH_MSG_ERROR("Unable to retrieve strip fitting tool " << m_cluster_builder); + return StatusCode::FAILURE; + } - ATH_MSG_DEBUG ( "Retrieved strip fitting tool " << m_cluster_builder ); - return StatusCode::SUCCESS; + ATH_MSG_DEBUG("Retrieved strip fitting tool " << m_cluster_builder); + return StatusCode::SUCCESS; } //****************************************************************************** -StatusCode CscThresholdClusterBuilder::execute() { - - ATH_MSG_DEBUG ( "Processing event " ); - - // Cleanup the cluster container - ready for filling - if ( m_cluster_builder ) { - std::vector<IdentifierHash> givenIDs; - std::vector<IdentifierHash> decodedIDs; - - if ( m_cluster_builder->getClusters(givenIDs, decodedIDs).isFailure() ) { - ATH_MSG_ERROR ( "Cannot record CSC Cluster Container " ); - return StatusCode::FAILURE; +StatusCode +CscThresholdClusterBuilder::execute() +{ + + ATH_MSG_DEBUG("Processing event "); + + // Cleanup the cluster container - ready for filling + if (m_cluster_builder) { + std::vector<IdentifierHash> givenIDs; + std::vector<IdentifierHash> decodedIDs; + + if (m_cluster_builder->getClusters(givenIDs, decodedIDs).isFailure()) { + ATH_MSG_ERROR("Cannot record CSC Cluster Container "); + return StatusCode::FAILURE; + } + } else { + ATH_MSG_ERROR("Initialization failed"); + return StatusCode::FAILURE; } - } else { - ATH_MSG_ERROR ( "Initialization failed" ); - return StatusCode::FAILURE; - } - return StatusCode::SUCCESS; + return StatusCode::SUCCESS; } //****************************************************************************** -StatusCode CscThresholdClusterBuilder::finalize() { - ATH_MSG_VERBOSE ( "Finalizing " << name() ); - // m_pclusters->release(); - return StatusCode::SUCCESS; +StatusCode +CscThresholdClusterBuilder::finalize() +{ + ATH_MSG_VERBOSE("Finalizing " << name()); + // m_pclusters->release(); + return StatusCode::SUCCESS; } //****************************************************************************** diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilder.h b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilder.h index 6e7408c30dc3..454449db2b98 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilder.h +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilder.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // CscThresholdClusterBuilder.h @@ -55,45 +55,44 @@ // Algorithm to construct CSC clusters from digits. #include "AthenaBaseComps/AthAlgorithm.h" -#include "GaudiKernel/ToolHandle.h" -#include "MuonPrepRawData/MuonPrepDataContainer.h" -#include "CscClusterization/ICscStripFitter.h" #include "CscClusterization/ICscClusterBuilder.h" #include "CscClusterization/ICscClusterFitter.h" +#include "CscClusterization/ICscStripFitter.h" +#include "GaudiKernel/ToolHandle.h" +#include "MuonPrepRawData/MuonPrepDataContainer.h" namespace MuonGM { - class MuonDetectorManager; +class MuonDetectorManager; } class CscIdHelper; namespace Muon { - class CscPrepData; - class CscStripPrepData; -} +class CscPrepData; +class CscStripPrepData; +} // namespace Muon typedef Muon::CscPrepData MyCscDigit; class CscDigit; class CscThresholdClusterBuilder : public AthAlgorithm { - -public: // methods - - // Constructor. - CscThresholdClusterBuilder(const std::string& name, ISvcLocator* pSvcLocator); - - // Destructor. - ~CscThresholdClusterBuilder(); - - // Initialization. - StatusCode initialize(); - - // Event processing. - StatusCode execute(); - // Finalization. - StatusCode finalize(); + public: // methods + // Constructor. + CscThresholdClusterBuilder(const std::string& name, ISvcLocator* pSvcLocator); + + // Destructor. + ~CscThresholdClusterBuilder(); + + // Initialization. + StatusCode initialize(); + + // Event processing. + StatusCode execute(); + + // Finalization. + StatusCode finalize(); -private: // data - // Strip fitter. - ToolHandle<ICscClusterBuilder> m_cluster_builder; + private: // data + // Strip fitter. + ToolHandle<ICscClusterBuilder> m_cluster_builder; }; #endif diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilderTool.cxx b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilderTool.cxx index a7b870edb616..9766b053122d 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilderTool.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilderTool.cxx @@ -1,30 +1,27 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // CscThresholdClusterBuilderTool.cxx #include "CscThresholdClusterBuilderTool.h" + #include <sstream> + +#include "CscCalibTools/ICscCalibTool.h" +#include "CscClusterization/ICscClusterFitter.h" +#include "CscClusterization/ICscStripFitter.h" +#include "EventPrimitives/EventPrimitives.h" +#include "EventPrimitives/EventPrimitivesHelpers.h" +#include "EventPrimitives/EventPrimitivesToStringConverter.h" #include "Gaudi/Property.h" +#include "MuonPrepRawData/CscClusterStatus.h" #include "MuonPrepRawData/CscPrepDataContainer.h" -#include "MuonPrepRawData/CscStripPrepDataContainer.h" #include "MuonPrepRawData/CscStripPrepData.h" +#include "MuonPrepRawData/CscStripPrepDataContainer.h" #include "MuonReadoutGeometry/CscReadoutElement.h" #include "TrkSurfaces/Surface.h" -#include "MuonPrepRawData/CscClusterStatus.h" -#include "CscClusterization/ICscStripFitter.h" -#include "CscClusterization/ICscClusterFitter.h" -#include "CscCalibTools/ICscCalibTool.h" -#include "EventPrimitives/EventPrimitivesToStringConverter.h" -#include "EventPrimitives/EventPrimitives.h" -#include "EventPrimitives/EventPrimitivesHelpers.h" - -using std::ostringstream; -using std::vector; -using std::setw; -using MuonGM::CscReadoutElement; using Muon::CscClusterStatus; using Muon::CscPrepData; using Muon::CscPrepDataCollection; @@ -32,6 +29,10 @@ using Muon::CscPrepDataContainer; using Muon::CscStripPrepData; using Muon::CscStripPrepDataCollection; using Muon::CscStripPrepDataContainer; +using MuonGM::CscReadoutElement; +using std::ostringstream; +using std::setw; +using std::vector; //****************************************************************************** // Local definitions. @@ -39,384 +40,396 @@ namespace { //****************************************************************************** // Convert chamber identifier to string. -std::string chamber(int istation, int zsec, int phi) { - ostringstream ssout; - if ( istation == 1 ) ssout << "CSS"; - else if ( istation ==2 ) ssout << "CSL"; - else ssout << "???"; - if ( zsec == -1 ) ssout << "-"; - else if ( zsec == 1 ) ssout << "+"; - else ssout << "?"; - ssout << phi; - return ssout.str(); +std::string +chamber(int istation, int zsec, int phi) +{ + ostringstream ssout; + if (istation == 1) + ssout << "CSS"; + else if (istation == 2) + ssout << "CSL"; + else + ssout << "???"; + if (zsec == -1) + ssout << "-"; + else if (zsec == 1) + ssout << "+"; + else + ssout << "?"; + ssout << phi; + return ssout.str(); } // Convert measphi to string. -std::string setaphi(bool measphi) { - if (measphi) return "phi"; - return "eta"; +std::string +setaphi(bool measphi) +{ + if (measphi) return "phi"; + return "eta"; } //****************************************************************************** } // end unnamed namespace //****************************************************************************** -CscThresholdClusterBuilderTool:: -CscThresholdClusterBuilderTool(const std::string &type, const std::string &aname, const IInterface* parent) - : AthAlgTool(type, aname, parent),m_noiseOption(rms), - m_digit_key("CSC_Measurements"), - m_pclusters("CSC_Clusters"), - m_cscCalibTool("CscCalibTool/CscCalibTool"), - m_pstrip_fitter("CalibCscStripFitter/CalibCscStripFitter"), - m_pfitter_def("SimpleCscClusterFitter/SimpleCscClusterFitter"), - m_pfitter_prec("QratCscClusterFitter/QratCscClusterFitter"), - m_pfitter_split("CscSplitClusterFitter/CscSplitClusterFitter"), - m_fullEventDone(false){ - - declareInterface<ICscClusterBuilder>(this); - - declareProperty("threshold", m_threshold = 20000.0); - declareProperty("kFactor", m_kFactor = 6.5); - declareProperty("noiseOption", m_noiseOptionStr = "f001"); - declareProperty("digit_key", m_digit_key ); - declareProperty("cluster_key", m_pclusters ); - declareProperty("cscCalibTool", m_cscCalibTool); - declareProperty("strip_fitter", m_pstrip_fitter); - declareProperty("default_fitter", m_pfitter_def); - declareProperty("precision_fitter", m_pfitter_prec); - declareProperty("split_fitter", m_pfitter_split); - declareProperty("makeNarrowClusterThreeStrips", m_makeNarrowClusterThreeStrips=true); +CscThresholdClusterBuilderTool::CscThresholdClusterBuilderTool(const std::string& type, const std::string& aname, + const IInterface* parent) + : AthAlgTool(type, aname, parent), + m_noiseOption(rms), + m_digit_key("CSC_Measurements"), + m_pclusters("CSC_Clusters"), + m_cscCalibTool("CscCalibTool/CscCalibTool"), + m_pstrip_fitter("CalibCscStripFitter/CalibCscStripFitter"), + m_pfitter_def("SimpleCscClusterFitter/SimpleCscClusterFitter"), + m_pfitter_prec("QratCscClusterFitter/QratCscClusterFitter"), + m_pfitter_split("CscSplitClusterFitter/CscSplitClusterFitter"), + m_fullEventDone(false) +{ + + declareInterface<ICscClusterBuilder>(this); + + declareProperty("threshold", m_threshold = 20000.0); + declareProperty("kFactor", m_kFactor = 6.5); + declareProperty("noiseOption", m_noiseOptionStr = "f001"); + declareProperty("digit_key", m_digit_key); + declareProperty("cluster_key", m_pclusters); + declareProperty("cscCalibTool", m_cscCalibTool); + declareProperty("strip_fitter", m_pstrip_fitter); + declareProperty("default_fitter", m_pfitter_def); + declareProperty("precision_fitter", m_pfitter_prec); + declareProperty("split_fitter", m_pfitter_split); + declareProperty("makeNarrowClusterThreeStrips", m_makeNarrowClusterThreeStrips = true); } //****************************************************************************** // Destructor. -CscThresholdClusterBuilderTool::~CscThresholdClusterBuilderTool() -{ } +CscThresholdClusterBuilderTool::~CscThresholdClusterBuilderTool() {} //****************************************************************************** -StatusCode CscThresholdClusterBuilderTool::initialize(){ - - // Display algorithm properties. - ATH_MSG_DEBUG ( "Properties for " << name() << ":" ); - ATH_MSG_DEBUG ( " Strip threshold is Max( " << m_threshold << ", " - << m_kFactor << "*stripNoise ) where stripNoise is from " << m_noiseOptionStr ); - - ATH_CHECK( m_digit_key.initialize() ); - ATH_CHECK(m_pclusters.initialize()); - if ( m_noiseOptionStr != "rms" - && m_noiseOptionStr != "sigma" - && m_noiseOptionStr != "f001" ) { - ATH_MSG_DEBUG (" noiseOption is not among rms/sigma/f001. rms is used for default!!"); - m_noiseOptionStr = "rms"; - } - if( m_noiseOptionStr == "rms" ) m_noiseOption = rms; - else if( m_noiseOptionStr == "sigma" ) m_noiseOption = sigma; - else if( m_noiseOptionStr == "f001" ) m_noiseOption = f001; - - ATH_MSG_DEBUG ( " Strip fitter is " << m_pstrip_fitter.typeAndName() ); - ATH_MSG_DEBUG ( " Default cluster fitter is " << m_pfitter_def.typeAndName() ); - ATH_MSG_DEBUG ( " Precision cluster fitter is " << m_pfitter_prec.typeAndName() ); - ATH_MSG_DEBUG ( " Split cluster fitter is " << m_pfitter_split.typeAndName() ); - ATH_MSG_DEBUG ( " Input digit key is " << m_digit_key.key() ); - ATH_MSG_DEBUG ( " Output cluster key is " << m_pclusters.key() ); - - // CSC calibratin tool for the Condtiions Data base access // - if ( m_cscCalibTool.retrieve().isFailure() ) { - ATH_MSG_ERROR ( "Can't get handle on CSC calibration tools" ); - return StatusCode::RECOVERABLE; - } - - // Retrieve the strip fitting tool. - if ( m_pstrip_fitter.retrieve().isFailure() ) { - ATH_MSG_ERROR ( "Unable to retrieve strip fitting tool " << m_pstrip_fitter ); - return StatusCode::RECOVERABLE; - } - ATH_MSG_DEBUG ( "Retrieved strip fitting tool " << m_pstrip_fitter ); - - // Retrieve the default cluster fitting tool. - if ( m_pfitter_def.retrieve().isFailure() ) { - ATH_MSG_ERROR ( "Unable to retrieve CSC default cluster fitting tool " - << m_pfitter_def->name() ); - return StatusCode::RECOVERABLE; - } - ATH_MSG_DEBUG ( "Retrieved CSC default cluster fitting tool" ); - - // Retrieve the precision cluster fitting tool. - if ( m_pfitter_prec.retrieve().isFailure() ) { - ATH_MSG_ERROR ( "Unable to retrieve CSC precision cluster fitting tool " - << m_pfitter_prec->name() ); - return StatusCode::RECOVERABLE; - } - ATH_MSG_DEBUG ( "Retrieved CSC precision cluster fitting tool" ); - - // Retrieve the split cluster fitting tool. - if ( m_pfitter_split.retrieve().isFailure() ) { - ATH_MSG_ERROR ( "Unable to retrieve CSC split cluster fitting tool " - << m_pfitter_split->name() ); - return StatusCode::RECOVERABLE; - } - ATH_MSG_DEBUG ( "Retrieved CSC split cluster fitting tool" ); - - // retrieve MuonDetectorManager from the conditions store - ATH_CHECK(m_DetectorManagerKey.initialize()); - ATH_CHECK(m_idHelperSvc.retrieve()); - - return StatusCode::SUCCESS; -} +StatusCode +CscThresholdClusterBuilderTool::initialize() +{ -//****************************************************************************** + // Display algorithm properties. + ATH_MSG_DEBUG("Properties for " << name() << ":"); + ATH_MSG_DEBUG(" Strip threshold is Max( " << m_threshold << ", " << m_kFactor + << "*stripNoise ) where stripNoise is from " << m_noiseOptionStr); -StatusCode CscThresholdClusterBuilderTool::getClusters(std::vector<IdentifierHash>& givenIDs, std::vector<IdentifierHash>& decodedIds) { - - // clear output vector of selected data collections containing data - decodedIds.clear(); - SG::WriteHandle<Muon::CscPrepDataContainer> wh_pclusters(m_pclusters); - CscPrepDataContainer *object = new CscPrepDataContainer(m_idHelperSvc->cscIdHelper().module_hash_max()); - - if (!wh_pclusters.isPresent()) { - /// record the container in storeGate - if ( wh_pclusters.record(std::unique_ptr<Muon::CscPrepDataContainer>(object)).isFailure() ) { - ATH_MSG_ERROR ( "Could not record container of CSC Cluster PrepData at " - << m_pclusters.key() ); - return StatusCode::RECOVERABLE; - } - m_fullEventDone=false; - if (givenIDs.size() == 0) m_fullEventDone=true; - - } else { - ATH_MSG_DEBUG ( "CSC Cluster PrepData Container is already in StoreGate " ); - if (m_fullEventDone) { - ATH_MSG_DEBUG ( "Whole event has already been processed; nothing to do"); - return StatusCode::SUCCESS; - } - if (givenIDs.size() == 0) m_fullEventDone = true; - } - - if (givenIDs.size()!=0) { - for (unsigned int i=0; i<givenIDs.size(); ++i) { - if ( getClusters(givenIDs[i],decodedIds, object).isFailure() ) { - ATH_MSG_ERROR ( "Unable to decode CSC RDO " << i << "th into CSC PrepRawData" ); + ATH_CHECK(m_digit_key.initialize()); + ATH_CHECK(m_pclusters.initialize()); + if (m_noiseOptionStr != "rms" && m_noiseOptionStr != "sigma" && m_noiseOptionStr != "f001") { + ATH_MSG_DEBUG(" noiseOption is not among rms/sigma/f001. rms is used for default!!"); + m_noiseOptionStr = "rms"; + } + if (m_noiseOptionStr == "rms") + m_noiseOption = rms; + else if (m_noiseOptionStr == "sigma") + m_noiseOption = sigma; + else if (m_noiseOptionStr == "f001") + m_noiseOption = f001; + + ATH_MSG_DEBUG(" Strip fitter is " << m_pstrip_fitter.typeAndName()); + ATH_MSG_DEBUG(" Default cluster fitter is " << m_pfitter_def.typeAndName()); + ATH_MSG_DEBUG(" Precision cluster fitter is " << m_pfitter_prec.typeAndName()); + ATH_MSG_DEBUG(" Split cluster fitter is " << m_pfitter_split.typeAndName()); + ATH_MSG_DEBUG(" Input digit key is " << m_digit_key.key()); + ATH_MSG_DEBUG(" Output cluster key is " << m_pclusters.key()); + + // CSC calibratin tool for the Condtiions Data base access // + if (m_cscCalibTool.retrieve().isFailure()) { + ATH_MSG_ERROR("Can't get handle on CSC calibration tools"); return StatusCode::RECOVERABLE; - } - } - } else { - // Clusterization is done for every area - if ( getClusters(decodedIds, object).isFailure()) { - ATH_MSG_ERROR ( "Unable to decode CSC RDO into CSC PrepRawData" ); - return StatusCode::RECOVERABLE; } - } - - return StatusCode::SUCCESS; -} + // Retrieve the strip fitting tool. + if (m_pstrip_fitter.retrieve().isFailure()) { + ATH_MSG_ERROR("Unable to retrieve strip fitting tool " << m_pstrip_fitter); + return StatusCode::RECOVERABLE; + } + ATH_MSG_DEBUG("Retrieved strip fitting tool " << m_pstrip_fitter); + + // Retrieve the default cluster fitting tool. + if (m_pfitter_def.retrieve().isFailure()) { + ATH_MSG_ERROR("Unable to retrieve CSC default cluster fitting tool " << m_pfitter_def->name()); + return StatusCode::RECOVERABLE; + } + ATH_MSG_DEBUG("Retrieved CSC default cluster fitting tool"); + // Retrieve the precision cluster fitting tool. + if (m_pfitter_prec.retrieve().isFailure()) { + ATH_MSG_ERROR("Unable to retrieve CSC precision cluster fitting tool " << m_pfitter_prec->name()); + return StatusCode::RECOVERABLE; + } + ATH_MSG_DEBUG("Retrieved CSC precision cluster fitting tool"); -//****************************************************************************** + // Retrieve the split cluster fitting tool. + if (m_pfitter_split.retrieve().isFailure()) { + ATH_MSG_ERROR("Unable to retrieve CSC split cluster fitting tool " << m_pfitter_split->name()); + return StatusCode::RECOVERABLE; + } + ATH_MSG_DEBUG("Retrieved CSC split cluster fitting tool"); -StatusCode CscThresholdClusterBuilderTool::getClusters(IdentifierHash givenHashId, std::vector<IdentifierHash>& decodedIds, Muon::CscPrepDataContainer *pclusters) { + // retrieve MuonDetectorManager from the conditions store + ATH_CHECK(m_DetectorManagerKey.initialize()); + ATH_CHECK(m_idHelperSvc.retrieve()); - // identifiers of collections already decoded and stored in the container will be skipped - if (pclusters->indexFindPtr(givenHashId) != nullptr) { - decodedIds.push_back(givenHashId); - ATH_MSG_DEBUG ( "A collection already exists in the container for offline id hash. " - << (int) givenHashId ); return StatusCode::SUCCESS; - } +} +//****************************************************************************** - // Retrieve the CSC digits for this event. - SG::ReadHandle<CscStripPrepDataContainer> pdigcon(m_digit_key); - if ( pdigcon.isValid() ) { - ATH_MSG_DEBUG ( "Retrieved strip container " << m_digit_key.key() << " with " - << pdigcon->size() << " entries." ); - } else { - ATH_MSG_WARNING ( "Failure to retrieve strip container " << m_digit_key.key() ); - return StatusCode::SUCCESS; - } - - - //********************************************** - // retrieve specific collection for the givenID - const CscStripPrepDataCollection * col = pdigcon->indexFindPtr(givenHashId); - if (nullptr == col) { - unsigned int coll_hash = givenHashId; - ATH_MSG_WARNING ( "Specific CSC Strip PrepData collection retrieving failed for collection hash = " - << coll_hash ); - return StatusCode::SUCCESS; - } - - ATH_MSG_DEBUG ( "Retrieved " << col->size() << " CSC Strip PrepDatas." ); - - Identifier colid = col->identify(); - int istation = m_idHelperSvc->cscIdHelper().stationName(colid) - 49; - int zsec = m_idHelperSvc->cscIdHelper().stationEta(colid); - int phisec = m_idHelperSvc->cscIdHelper().stationPhi(colid); - - ATH_MSG_DEBUG ( " Strip collection " << chamber(istation, zsec, phisec) - << " has " << col->size() << " strips" ); - - // Create arrays to hold digits and cathode plane parameters. - vector<const CscStripPrepData*> strips[8]; - int maxstrip[8] = {0, 0, 0, 0, 0, 0, 0, 0}; - - // retrieve MuonDetectorManager from the conditions store - SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey}; - const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr(); - if(MuonDetMgr==nullptr){ - ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object"); - return StatusCode::FAILURE; - } - - IdentifierHash hash; - // Loop over digits and fill these arrays. - for ( CscStripPrepDataCollection::const_iterator idig=col->begin(); - idig!=col->end(); ++idig ) { - const CscStripPrepData& dig = **idig; - Identifier did = dig.identify(); - hash=dig.collectionHash(); - const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(did); - int wlay = m_idHelperSvc->cscIdHelper().wireLayer(did); - int measphi = m_idHelperSvc->cscIdHelper().measuresPhi(did); - int idx = 2*(wlay-1) + measphi; - // First entry for a cathode plane, initialize. - if ( maxstrip[idx] == 0 ) { - maxstrip[idx] = pro->maxNumberOfStrips(measphi); - for ( int istrip=0; istrip<maxstrip[idx]; ++istrip ) - strips[idx].push_back(0); - } - int istrip = m_idHelperSvc->cscIdHelper().strip(did) - 1; - if ( istrip<0 || istrip>=maxstrip[idx] ) { - ATH_MSG_WARNING ( "Invalid strip number" ); - continue; - } - strips[idx][istrip] = &dig; - } - - // Cluster. - CscPrepDataCollection* newCollection = 0; - for ( int measphi=0; measphi<2; ++measphi ) { - for ( int wlay=1; wlay<5; ++wlay ) { - int idx = 2*(wlay-1) + measphi; - if ( maxstrip[idx] ) { - make_clusters(measphi, strips[idx],newCollection); - ATH_MSG_DEBUG ( " " << wlay << "th layer "); - } +StatusCode +CscThresholdClusterBuilderTool::getClusters(std::vector<IdentifierHash>& givenIDs, + std::vector<IdentifierHash>& decodedIds) +{ + + // clear output vector of selected data collections containing data + decodedIds.clear(); + SG::WriteHandle<Muon::CscPrepDataContainer> wh_pclusters(m_pclusters); + CscPrepDataContainer* object = new CscPrepDataContainer(m_idHelperSvc->cscIdHelper().module_hash_max()); + + if (!wh_pclusters.isPresent()) { + /// record the container in storeGate + if (wh_pclusters.record(std::unique_ptr<Muon::CscPrepDataContainer>(object)).isFailure()) { + ATH_MSG_ERROR("Could not record container of CSC Cluster PrepData at " << m_pclusters.key()); + return StatusCode::RECOVERABLE; + } + m_fullEventDone = false; + if (givenIDs.size() == 0) m_fullEventDone = true; + + } else { + ATH_MSG_DEBUG("CSC Cluster PrepData Container is already in StoreGate "); + if (m_fullEventDone) { + ATH_MSG_DEBUG("Whole event has already been processed; nothing to do"); + return StatusCode::SUCCESS; + } + if (givenIDs.size() == 0) m_fullEventDone = true; } - } - if (newCollection){ - if ( pclusters->addCollection(newCollection, hash).isFailure() ) { - ATH_MSG_ERROR ( "Couldn't add CscPrepdataCollection to container!" ); - return StatusCode::RECOVERABLE; + + if (givenIDs.size() != 0) { + for (unsigned int i = 0; i < givenIDs.size(); ++i) { + if (getClusters(givenIDs[i], decodedIds, object).isFailure()) { + ATH_MSG_ERROR("Unable to decode CSC RDO " << i << "th into CSC PrepRawData"); + return StatusCode::RECOVERABLE; + } + } + } else { + // Clusterization is done for every area + if (getClusters(decodedIds, object).isFailure()) { + ATH_MSG_ERROR("Unable to decode CSC RDO into CSC PrepRawData"); + return StatusCode::RECOVERABLE; + } } - decodedIds.push_back(hash); //Record that this collection contains data - } - - return StatusCode::SUCCESS; + + + return StatusCode::SUCCESS; } //****************************************************************************** -StatusCode CscThresholdClusterBuilderTool::getClusters(std::vector<IdentifierHash>& decodedIds, Muon::CscPrepDataContainer *pclusters) { - - // Retrieve the CSC digits for this event. - SG::ReadHandle<CscStripPrepDataContainer> pdigcon(m_digit_key); - if ( pdigcon.isValid() ) { - ATH_MSG_DEBUG ( "Retrieved strip container " << m_digit_key.key() << " with " - << pdigcon->size() << " entries." ); - } else { - ATH_MSG_WARNING ( "Failure to retrieve strip container " << m_digit_key.key() ); - return StatusCode::SUCCESS; - } - - // Loop over digit collections. - // This a loop over chambers (each with 4 wire planes). - const CscStripPrepDataContainer& con = *pdigcon; - for (CscStripPrepDataContainer::const_iterator icol=con.begin(); - icol!=con.end(); ++icol) { - const CscStripPrepDataCollection& col = **icol; - //check if the collection is already used - if (pclusters->indexFindPtr(col.identifyHash()) != nullptr) { - //store the identifier hash and continue - decodedIds.push_back(col.identifyHash()); - continue; +StatusCode +CscThresholdClusterBuilderTool::getClusters(IdentifierHash givenHashId, std::vector<IdentifierHash>& decodedIds, + Muon::CscPrepDataContainer* pclusters) +{ + + // identifiers of collections already decoded and stored in the container will be skipped + if (pclusters->indexFindPtr(givenHashId) != nullptr) { + decodedIds.push_back(givenHashId); + ATH_MSG_DEBUG("A collection already exists in the container for offline id hash. " << (int)givenHashId); + return StatusCode::SUCCESS; + } + + + // Retrieve the CSC digits for this event. + SG::ReadHandle<CscStripPrepDataContainer> pdigcon(m_digit_key); + if (pdigcon.isValid()) { + ATH_MSG_DEBUG("Retrieved strip container " << m_digit_key.key() << " with " << pdigcon->size() << " entries."); + } else { + ATH_MSG_WARNING("Failure to retrieve strip container " << m_digit_key.key()); + return StatusCode::SUCCESS; } - Identifier colid = col.identify(); - int istation = m_idHelperSvc->cscIdHelper().stationName(colid) - 49; - int zsec = m_idHelperSvc->cscIdHelper().stationEta(colid); - int phisec = m_idHelperSvc->cscIdHelper().stationPhi(colid); - ATH_MSG_DEBUG ( "**Strip collection " << chamber(istation, zsec, phisec) << " sector " << m_idHelperSvc->cscIdHelper().sector(colid) - << " has " << col.size() << " strips" ); - + + + //********************************************** + // retrieve specific collection for the givenID + const CscStripPrepDataCollection* col = pdigcon->indexFindPtr(givenHashId); + if (nullptr == col) { + unsigned int coll_hash = givenHashId; + ATH_MSG_WARNING("Specific CSC Strip PrepData collection retrieving failed for collection hash = " << coll_hash); + return StatusCode::SUCCESS; + } + + ATH_MSG_DEBUG("Retrieved " << col->size() << " CSC Strip PrepDatas."); + + Identifier colid = col->identify(); + int istation = m_idHelperSvc->cscIdHelper().stationName(colid) - 49; + int zsec = m_idHelperSvc->cscIdHelper().stationEta(colid); + int phisec = m_idHelperSvc->cscIdHelper().stationPhi(colid); + + ATH_MSG_DEBUG(" Strip collection " << chamber(istation, zsec, phisec) << " has " << col->size() << " strips"); + // Create arrays to hold digits and cathode plane parameters. vector<const CscStripPrepData*> strips[8]; - int maxstrip[8] = {0, 0, 0, 0, 0, 0, 0, 0}; - - // retrieve MuonDetectorManager from the conditions store - SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey}; - const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr(); - if(MuonDetMgr==nullptr){ - ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object"); - return StatusCode::FAILURE; + int maxstrip[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + + // retrieve MuonDetectorManager from the conditions store + SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey}; + const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr(); + if (MuonDetMgr == nullptr) { + ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object"); + return StatusCode::FAILURE; } IdentifierHash hash; // Loop over digits and fill these arrays. - for ( CscStripPrepDataCollection::const_iterator idig=col.begin(); - idig!=col.end(); ++idig ) { - const CscStripPrepData& dig = **idig; - Identifier did = dig.identify(); - hash=dig.collectionHash(); - const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(did); - int wlay = m_idHelperSvc->cscIdHelper().wireLayer(did); - int measphi = m_idHelperSvc->cscIdHelper().measuresPhi(did); - int idx = 2*(wlay-1) + measphi; - // First entry for a cathode plane, initialize. - if ( maxstrip[idx] == 0 ) { - maxstrip[idx] = pro->maxNumberOfStrips(measphi); - for ( int istrip=0; istrip<maxstrip[idx]; ++istrip ) - strips[idx].push_back(0); - } - int istrip = m_idHelperSvc->cscIdHelper().strip(did) - 1; - if ( istrip<0 || istrip>=maxstrip[idx] ) { - ATH_MSG_WARNING ( "Invalid strip number" ); - continue; - } - strips[idx][istrip] = &dig; + for (CscStripPrepDataCollection::const_iterator idig = col->begin(); idig != col->end(); ++idig) { + const CscStripPrepData& dig = **idig; + Identifier did = dig.identify(); + hash = dig.collectionHash(); + const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(did); + int wlay = m_idHelperSvc->cscIdHelper().wireLayer(did); + int measphi = m_idHelperSvc->cscIdHelper().measuresPhi(did); + int idx = 2 * (wlay - 1) + measphi; + // First entry for a cathode plane, initialize. + if (maxstrip[idx] == 0) { + maxstrip[idx] = pro->maxNumberOfStrips(measphi); + for (int istrip = 0; istrip < maxstrip[idx]; ++istrip) strips[idx].push_back(0); + } + int istrip = m_idHelperSvc->cscIdHelper().strip(did) - 1; + if (istrip < 0 || istrip >= maxstrip[idx]) { + ATH_MSG_WARNING("Invalid strip number"); + continue; + } + strips[idx][istrip] = &dig; } - + // Cluster. CscPrepDataCollection* newCollection = 0; - for ( int measphi=0; measphi<2; ++measphi ) { - for ( int wlay=1; wlay<5; ++wlay ) { - int idx = 2*(wlay-1) + measphi; - if ( maxstrip[idx] ) { - ATH_MSG_DEBUG ("*** " << chamber(istation, zsec, phisec) << " sector " - << m_idHelperSvc->cscIdHelper().sector(colid) << " " << wlay << "th layer "); - make_clusters(measphi, strips[idx], newCollection); + for (int measphi = 0; measphi < 2; ++measphi) { + for (int wlay = 1; wlay < 5; ++wlay) { + int idx = 2 * (wlay - 1) + measphi; + if (maxstrip[idx]) { + make_clusters(measphi, strips[idx], newCollection); + ATH_MSG_DEBUG(" " << wlay << "th layer "); + } } - } } - if (newCollection){ - if ( pclusters->addCollection(newCollection, hash).isFailure() ) { - ATH_MSG_ERROR ( "Couldn't add CscPrepdataCollection to container!" ); - return StatusCode::FAILURE; - } - decodedIds.push_back(hash); //Record that this collection contains data + if (newCollection) { + if (pclusters->addCollection(newCollection, hash).isFailure()) { + ATH_MSG_ERROR("Couldn't add CscPrepdataCollection to container!"); + return StatusCode::RECOVERABLE; + } + decodedIds.push_back(hash); // Record that this collection contains data } - } // end loop over chambers - - return StatusCode::SUCCESS; + + return StatusCode::SUCCESS; } + + //****************************************************************************** -StatusCode CscThresholdClusterBuilderTool::finalize() { - ATH_MSG_VERBOSE ( "Finalizing " << name() ); - return StatusCode::SUCCESS; +StatusCode +CscThresholdClusterBuilderTool::getClusters(std::vector<IdentifierHash>& decodedIds, + Muon::CscPrepDataContainer* pclusters) +{ + + // Retrieve the CSC digits for this event. + SG::ReadHandle<CscStripPrepDataContainer> pdigcon(m_digit_key); + if (pdigcon.isValid()) { + ATH_MSG_DEBUG("Retrieved strip container " << m_digit_key.key() << " with " << pdigcon->size() << " entries."); + } else { + ATH_MSG_WARNING("Failure to retrieve strip container " << m_digit_key.key()); + return StatusCode::SUCCESS; + } + + // Loop over digit collections. + // This a loop over chambers (each with 4 wire planes). + const CscStripPrepDataContainer& con = *pdigcon; + for (CscStripPrepDataContainer::const_iterator icol = con.begin(); icol != con.end(); ++icol) { + const CscStripPrepDataCollection& col = **icol; + // check if the collection is already used + if (pclusters->indexFindPtr(col.identifyHash()) != nullptr) { + // store the identifier hash and continue + decodedIds.push_back(col.identifyHash()); + continue; + } + Identifier colid = col.identify(); + int istation = m_idHelperSvc->cscIdHelper().stationName(colid) - 49; + int zsec = m_idHelperSvc->cscIdHelper().stationEta(colid); + int phisec = m_idHelperSvc->cscIdHelper().stationPhi(colid); + ATH_MSG_DEBUG("**Strip collection " << chamber(istation, zsec, phisec) << " sector " + << m_idHelperSvc->cscIdHelper().sector(colid) << " has " << col.size() + << " strips"); + + // Create arrays to hold digits and cathode plane parameters. + vector<const CscStripPrepData*> strips[8]; + int maxstrip[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + + // retrieve MuonDetectorManager from the conditions store + SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey}; + const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr(); + if (MuonDetMgr == nullptr) { + ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object"); + return StatusCode::FAILURE; + } + + IdentifierHash hash; + // Loop over digits and fill these arrays. + for (CscStripPrepDataCollection::const_iterator idig = col.begin(); idig != col.end(); ++idig) { + const CscStripPrepData& dig = **idig; + Identifier did = dig.identify(); + hash = dig.collectionHash(); + const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(did); + int wlay = m_idHelperSvc->cscIdHelper().wireLayer(did); + int measphi = m_idHelperSvc->cscIdHelper().measuresPhi(did); + int idx = 2 * (wlay - 1) + measphi; + // First entry for a cathode plane, initialize. + if (maxstrip[idx] == 0) { + maxstrip[idx] = pro->maxNumberOfStrips(measphi); + for (int istrip = 0; istrip < maxstrip[idx]; ++istrip) strips[idx].push_back(0); + } + int istrip = m_idHelperSvc->cscIdHelper().strip(did) - 1; + if (istrip < 0 || istrip >= maxstrip[idx]) { + ATH_MSG_WARNING("Invalid strip number"); + continue; + } + strips[idx][istrip] = &dig; + } + + // Cluster. + CscPrepDataCollection* newCollection = 0; + for (int measphi = 0; measphi < 2; ++measphi) { + for (int wlay = 1; wlay < 5; ++wlay) { + int idx = 2 * (wlay - 1) + measphi; + if (maxstrip[idx]) { + ATH_MSG_DEBUG("*** " << chamber(istation, zsec, phisec) << " sector " + << m_idHelperSvc->cscIdHelper().sector(colid) << " " << wlay << "th layer "); + make_clusters(measphi, strips[idx], newCollection); + } + } + } + if (newCollection) { + if (pclusters->addCollection(newCollection, hash).isFailure()) { + ATH_MSG_ERROR("Couldn't add CscPrepdataCollection to container!"); + return StatusCode::FAILURE; + } + decodedIds.push_back(hash); // Record that this collection contains data + } + } // end loop over chambers + + return StatusCode::SUCCESS; +} +//****************************************************************************** + +StatusCode +CscThresholdClusterBuilderTool::finalize() +{ + ATH_MSG_VERBOSE("Finalizing " << name()); + return StatusCode::SUCCESS; } //****************************************************************************** @@ -431,576 +444,580 @@ StatusCode CscThresholdClusterBuilderTool::finalize() { // NOTE: vector<CscStripPrepData*> strips is filled up with full strips (48/192) // some of them have null pointer. Useful to find adjacent strip CscStripPrepData... -int CscThresholdClusterBuilderTool:: -make_clusters(bool measphi, const vector<const CscStripPrepData*>& strips, - CscPrepDataCollection *&newCollection) { - - // Loop over channels. - unsigned int maxstrip = strips.size(); - - ATH_MSG_DEBUG ( " Clustering for " << setaphi(measphi) << " plane with " << maxstrip << " strips" ); - - //////////////////////////////////////////////////////////////////// - // Phase I: - // - // Loop over strips and fetch the charge and time for each. - // Also set flag indicating if this strip has pointer and charge is above threshold(active) - ///////////////// - ICscClusterFitter::StripFitList allStripfits; - std::vector<bool> astrip; // check active strip - std::vector<bool> bstrip; // check bad strip - IdentifierHash cscHashId; - - // Always [0, 191] or [0, 47] - for ( unsigned int istrip=0; istrip<strips.size(); ++istrip ) { - const CscStripPrepData* pstrip = strips[istrip]; - ICscClusterFitter::StripFit res; - bool active = false; - bool isBadChannel = false; - if ( pstrip ) { - if (!newCollection) { - Identifier elementId = m_idHelperSvc->cscIdHelper().elementID(pstrip->identify()); - cscHashId=pstrip->collectionHash(); - newCollection = new CscPrepDataCollection(cscHashId); - newCollection->setIdentifier(elementId); - } - res = m_pstrip_fitter->fit(*pstrip); - - - IdentifierHash stripHash; - Identifier stripId = pstrip->identify(); - if (m_idHelperSvc->cscIdHelper().get_channel_hash(stripId, stripHash)){ - ATH_MSG_WARNING ( "Unable to get CSC striphash id " << " the identifier is " ); - stripId.show(); - } - - if ( res.stripStatus == Muon::CscStrStatHot || - res.stripStatus == Muon::CscStrStatDead ) isBadChannel = true; - - float stripNoise = 0; - if (m_noiseOption == rms) { - stripNoise = m_cscCalibTool->stripRMS(stripHash); - } else if (m_noiseOption == sigma) { - stripNoise = m_cscCalibTool->stripNoise(stripHash); - } else if (m_noiseOption == f001) { // f001 is rawADC +1 - stripNoise = m_cscCalibTool->stripF001(stripHash) - m_cscCalibTool->stripPedestal(stripHash); - stripNoise /= 3.251; - } - - active = res.charge >= m_threshold - && res.charge >= m_kFactor*stripNoise; - if (isBadChannel) active = false; // Let's remove Bad channel First... - - if(msgLvl(MSG::DEBUG)) { - // Log message. - ostringstream strlog; - strlog << " Strip " << setw(3) << istrip+1 - << ": charge= " << setw(7) << int(res.charge) - << " dcharge= " << setw(7) << int(res.dcharge); - if(std::fabs(res.time)<1e8) - strlog<< " time=" << setw(3) << int(res.time+0.5); - else - strlog<< " time=OVERFLOW"; - if ( active ) strlog << " *"; - else if (isBadChannel) strlog << " b"; - else strlog << " ."; - if ( res.status ) strlog << " x"; - else strlog << " o"; - strlog << " :" << res.status; - ATH_MSG_DEBUG ( strlog.str() ); - } - } - allStripfits.push_back(res); - astrip.push_back(active); - bstrip.push_back(isBadChannel); - } - - ////////////////////////////////////////////////////// - // Phase II: - // - // Bad Channel recovery in case of strip above strip being nearby - ///////////////////////////////////////////////////////// - - // 1. identify strips to recover - std::vector<bool> rstrip; // check recover strip - bool IsAnyStripRecovered = false; - for ( unsigned int istrip=0; istrip<strips.size(); ++istrip ) { - bool adjacentActive =false; - if ( bstrip[istrip] ) { - if (istrip>0 && astrip[istrip-1]) adjacentActive =true; - if (istrip+1<strips.size() && astrip[istrip+1]) adjacentActive =true; - if (adjacentActive) IsAnyStripRecovered =true; - } - rstrip.push_back(adjacentActive); - } +int +CscThresholdClusterBuilderTool::make_clusters(bool measphi, const vector<const CscStripPrepData*>& strips, + CscPrepDataCollection*& newCollection) +{ + + // Loop over channels. + unsigned int maxstrip = strips.size(); + + ATH_MSG_DEBUG(" Clustering for " << setaphi(measphi) << " plane with " << maxstrip << " strips"); - // 2. make it active if strip to recover is not active - if (IsAnyStripRecovered) { // This loop is needed if there is any bad strip recovered because of adjacent active strip + //////////////////////////////////////////////////////////////////// + // Phase I: + // + // Loop over strips and fetch the charge and time for each. + // Also set flag indicating if this strip has pointer and charge is above threshold(active) + ///////////////// + ICscClusterFitter::StripFitList allStripfits; + std::vector<bool> astrip; // check active strip + std::vector<bool> bstrip; // check bad strip + IdentifierHash cscHashId; + + // Always [0, 191] or [0, 47] + for (unsigned int istrip = 0; istrip < strips.size(); ++istrip) { + const CscStripPrepData* pstrip = strips[istrip]; + ICscClusterFitter::StripFit res; + bool active = false; + bool isBadChannel = false; + if (pstrip) { + if (!newCollection) { + Identifier elementId = m_idHelperSvc->cscIdHelper().elementID(pstrip->identify()); + cscHashId = pstrip->collectionHash(); + newCollection = new CscPrepDataCollection(cscHashId); + newCollection->setIdentifier(elementId); + } + res = m_pstrip_fitter->fit(*pstrip); - if(msgLvl(MSG::DEBUG)) { - ostringstream checklog1; - ostringstream checklog2; + IdentifierHash stripHash; + Identifier stripId = pstrip->identify(); + if (m_idHelperSvc->cscIdHelper().get_channel_hash(stripId, stripHash)) { + ATH_MSG_WARNING("Unable to get CSC striphash id " + << " the identifier is "); + stripId.show(); + } - for ( unsigned int istrip=0; istrip<strips.size(); ++istrip ) { - if (istrip%24==0) checklog1 << "\n"; - checklog1 << int(astrip[istrip]) << " "; - - if (!astrip[istrip] && rstrip[istrip] ) { // not active but bad strip with adjacent strip active - ATH_MSG_DEBUG("**** Strip " << istrip << " is recovered!!"); + if (res.stripStatus == Muon::CscStrStatHot || res.stripStatus == Muon::CscStrStatDead) isBadChannel = true; + + float stripNoise = 0; + if (m_noiseOption == rms) { + stripNoise = m_cscCalibTool->stripRMS(stripHash); + } else if (m_noiseOption == sigma) { + stripNoise = m_cscCalibTool->stripNoise(stripHash); + } else if (m_noiseOption == f001) { // f001 is rawADC +1 + stripNoise = m_cscCalibTool->stripF001(stripHash) - m_cscCalibTool->stripPedestal(stripHash); + stripNoise /= 3.251; + } + + active = res.charge >= m_threshold && res.charge >= m_kFactor * stripNoise; + if (isBadChannel) active = false; // Let's remove Bad channel First... + + if (msgLvl(MSG::DEBUG)) { + // Log message. + ostringstream strlog; + strlog << " Strip " << setw(3) << istrip + 1 << ": charge= " << setw(7) << int(res.charge) + << " dcharge= " << setw(7) << int(res.dcharge); + if (std::fabs(res.time) < 1e8) + strlog << " time=" << setw(3) << int(res.time + 0.5); + else + strlog << " time=OVERFLOW"; + if (active) + strlog << " *"; + else if (isBadChannel) + strlog << " b"; + else + strlog << " ."; + if (res.status) + strlog << " x"; + else + strlog << " o"; + strlog << " :" << res.status; + ATH_MSG_DEBUG(strlog.str()); + } } - if (istrip%24==0) checklog2 << "\n"; - checklog2 << int(astrip[istrip]) << " "; - } - ATH_MSG_DEBUG("Strip active map before and after"); - ATH_MSG_DEBUG(checklog1.str()); - ATH_MSG_DEBUG(checklog2.str()); + allStripfits.push_back(res); + astrip.push_back(active); + bstrip.push_back(isBadChannel); } - for ( unsigned int istrip=0; istrip<strips.size(); ++istrip ) { - if (!astrip[istrip] && rstrip[istrip] ) { // not active but bad strip with adjacent strip active - astrip[istrip] = rstrip[istrip]; // insert true - } + ////////////////////////////////////////////////////// + // Phase II: + // + // Bad Channel recovery in case of strip above strip being nearby + ///////////////////////////////////////////////////////// + + // 1. identify strips to recover + std::vector<bool> rstrip; // check recover strip + bool IsAnyStripRecovered = false; + for (unsigned int istrip = 0; istrip < strips.size(); ++istrip) { + bool adjacentActive = false; + if (bstrip[istrip]) { + if (istrip > 0 && astrip[istrip - 1]) adjacentActive = true; + if (istrip + 1 < strips.size() && astrip[istrip + 1]) adjacentActive = true; + if (adjacentActive) IsAnyStripRecovered = true; + } + rstrip.push_back(adjacentActive); } + // 2. make it active if strip to recover is not active + if (IsAnyStripRecovered) + { // This loop is needed if there is any bad strip recovered because of adjacent active strip - - } - ////////////////////////////////////////////////////// - // Phase III: - // - // Find clusters : save first strip and nstrip - ///////////////////////////////////////////////////////// - vector <unsigned int> strip0s; - vector <unsigned int> nstrips; - - // Loop over strips and create clusters. - int nstrip = 0; - int first_strip = 0; // First strip in the cluster. - bool incluster = false; - for ( unsigned int istrip=0; istrip<strips.size(); ++istrip ) { - // If the current strip is not active, skip it. - if ( ! astrip[istrip] ) continue; - assert( strips[istrip] != 0 ); // CscStripPrepData* pstrip = strips[istrip]; - - if ( ! incluster ) { - incluster = true; - nstrip = 0; - first_strip = istrip; - } - ++nstrip; - - // If this is not the last strip in the plane, and the next - // strip is active, add the next strip to the cluster. - if ( istrip!=maxstrip-1 && astrip[istrip+1] ) continue; - - // Recover narrow cluster - if (!measphi && nstrip<3) { - bool collectLeftStrip = false; - bool collectRightStrip = false; - - if (nstrip == 1) { - if ( int(istrip)>=nstrip //left adjacent strip should be inside of CSC chamber >0 - && istrip+1 < maxstrip // the other side strip should be available < 192 - && (allStripfits[istrip-1].charge >0.1 && allStripfits[istrip+1].charge >0.1) // charge should be positive - && strips[istrip-1] && strips[istrip+1] ) { // both adjacent strip identifier should exist - collectLeftStrip = true; - collectRightStrip = true; - } - } else if (nstrip == 2) { - if ( allStripfits[istrip-1].charge > allStripfits[istrip].charge) { // In case of left strip not fired - if ( int(istrip)>=nstrip // nstrip 2 - && allStripfits[istrip-2].charge >0.1 // charge should be positive - && strips[istrip-2] ) // left strip Identifier should exist - collectLeftStrip = true; - } else { // In case of right strip not fired - if ( istrip+1 < maxstrip - && allStripfits[istrip+1].charge >0.1 // charge should be positive if 0, then 0.341E-134 will enter - && strips[istrip+1] ) // right strip Identifier should exist - collectRightStrip = true; - } - } - - if (collectLeftStrip) { - first_strip = first_strip-1; - nstrip +=1; - } - if (collectRightStrip) { - nstrip +=1; - } - - - if(msgLvl(MSG::DEBUG)) { - // Log message. - ostringstream narrowlog; - narrowlog << " ** narrow Clusters " << first_strip+1 << " " << nstrip - << " L:R " << collectLeftStrip << " " << collectRightStrip; - for (int i=0; i<nstrip; ++i) { - narrowlog << " " << allStripfits[first_strip+i].charge; + if (msgLvl(MSG::DEBUG)) { + + ostringstream checklog1; + ostringstream checklog2; + + for (unsigned int istrip = 0; istrip < strips.size(); ++istrip) { + if (istrip % 24 == 0) checklog1 << "\n"; + checklog1 << int(astrip[istrip]) << " "; + + if (!astrip[istrip] && rstrip[istrip]) { // not active but bad strip with adjacent strip active + ATH_MSG_DEBUG("**** Strip " << istrip << " is recovered!!"); + } + if (istrip % 24 == 0) checklog2 << "\n"; + checklog2 << int(astrip[istrip]) << " "; + } + ATH_MSG_DEBUG("Strip active map before and after"); + ATH_MSG_DEBUG(checklog1.str()); + ATH_MSG_DEBUG(checklog2.str()); } - for (int i=0; i<nstrip; ++i) { - narrowlog << " " << strips[first_strip+i]; + + for (unsigned int istrip = 0; istrip < strips.size(); ++istrip) { + if (!astrip[istrip] && rstrip[istrip]) { // not active but bad strip with adjacent strip active + astrip[istrip] = rstrip[istrip]; // insert true + } } - ATH_MSG_DEBUG (narrowlog.str()); - } - } // Only for eta plane nstrip <3 - - strip0s.push_back(first_strip); - nstrips.push_back(nstrip); - - // Reset incluster. - incluster = false; - } - - - ////////////////////////////////////////////////////// - // Phase IV: - // - // Merge narrow cluster into adjacent cluster if any exists. - // Only for eta strips... - ///////////////////////////////////////////////////////// - vector <unsigned int> newStrip0s; - vector <unsigned int> newNstrips; - - int nMerged =0; // the difference b/w old Nclu and new Nclu - for ( unsigned int icl =0; icl<nstrips.size(); ++icl ) { - unsigned int nstrip = nstrips[icl]; - unsigned int strip0 = strip0s[icl]; - - ATH_MSG_VERBOSE (" " << icl << "th cluster merger " << strip0 << " " << nstrip ); - - //#### if you find narrow cluster - if (!measphi) { - if ( nstrip <3 ) { - // at least one cluster before to check left cluster and continuous - if ( icl>0 && (strip0 == strip0s[icl-1]+nstrips[icl-1]) ) { - unsigned int newStrip0 = strip0s[icl-1]; - unsigned int newNstrip = nstrips[icl-1]+nstrip; - - ATH_MSG_DEBUG ( " " << icl << " ** narrow Cluster merger Type I" << newStrip0 << " " << newNstrip ); - - newStrip0s[icl-1-nMerged] = newStrip0; - newNstrips[icl-1-nMerged] = newNstrip; - ++nMerged; - continue; + } + ////////////////////////////////////////////////////// + // Phase III: + // + // Find clusters : save first strip and nstrip + ///////////////////////////////////////////////////////// + vector<unsigned int> strip0s; + vector<unsigned int> nstrips; + + // Loop over strips and create clusters. + int nstrip = 0; + int first_strip = 0; // First strip in the cluster. + bool incluster = false; + for (unsigned int istrip = 0; istrip < strips.size(); ++istrip) { + // If the current strip is not active, skip it. + if (!astrip[istrip]) continue; + assert(strips[istrip] != 0); // CscStripPrepData* pstrip = strips[istrip]; + + if (!incluster) { + incluster = true; + nstrip = 0; + first_strip = istrip; } - // at least one cluster after to check right cluster and continuous - if ( icl+1 <nstrips.size() && ( strip0+nstrip == strip0s[icl+1] ) ) { - unsigned int newStrip0 = strip0; - unsigned int newNstrip = nstrip+nstrips[icl+1]; + ++nstrip; + + // If this is not the last strip in the plane, and the next + // strip is active, add the next strip to the cluster. + if (istrip != maxstrip - 1 && astrip[istrip + 1]) continue; + + // Recover narrow cluster + if (!measphi && nstrip < 3) { + bool collectLeftStrip = false; + bool collectRightStrip = false; + + if (nstrip == 1) { + if (int(istrip) >= nstrip // left adjacent strip should be inside of CSC chamber >0 + && istrip + 1 < maxstrip // the other side strip should be available < 192 + && (allStripfits[istrip - 1].charge > 0.1 + && allStripfits[istrip + 1].charge > 0.1) // charge should be positive + && strips[istrip - 1] && strips[istrip + 1]) + { // both adjacent strip identifier should exist + collectLeftStrip = true; + collectRightStrip = true; + } + } else if (nstrip == 2) { + if (allStripfits[istrip - 1].charge > allStripfits[istrip].charge) { // In case of left strip not fired + if (int(istrip) >= nstrip // nstrip 2 + && allStripfits[istrip - 2].charge > 0.1 // charge should be positive + && strips[istrip - 2]) // left strip Identifier should exist + collectLeftStrip = true; + } else { // In case of right strip not fired + if (istrip + 1 < maxstrip + && allStripfits[istrip + 1].charge + > 0.1 // charge should be positive if 0, then 0.341E-134 will enter + && strips[istrip + 1]) // right strip Identifier should exist + collectRightStrip = true; + } + } - ATH_MSG_DEBUG ( " " << icl << " ** narrow Cluster merger Type II" << newStrip0 << " " << newNstrip ); + if (collectLeftStrip) { + first_strip = first_strip - 1; + nstrip += 1; + } + if (collectRightStrip) { + nstrip += 1; + } - newStrip0s.push_back(newStrip0); - newNstrips.push_back(newNstrip); - icl +=1; - ++nMerged; - continue; - } - } - } // !measphi - // if nstrip >2 OR - // still narrow strip then just keep it... - newStrip0s.push_back(strip0); - newNstrips.push_back(nstrip); - } // for - - if ( strip0s.size() != newStrip0s.size() ) { - ATH_MSG_DEBUG ( " Phase II -> III Merged " << strip0s.size() << ":" << nstrips.size() << " " - << newStrip0s.size() << ":" << newNstrips.size() ); - for (unsigned int icl =0; icl < nstrips.size(); ++icl) - ATH_MSG_DEBUG ( " *** " << icl << " [" << strip0s[icl] << "," << strip0s[icl]+nstrips[icl]-1 << "] " << nstrips[icl]); - for (unsigned int icl =0; icl < newNstrips.size(); ++icl) - ATH_MSG_DEBUG ( " ****** " << icl << " [" << newStrip0s[icl] << "," << newStrip0s[icl]+newNstrips[icl]-1 << "] " << newNstrips[icl]); - } - - - - ////////////////////////////////////////////////////// - // Phase V: - // - // Using strip0 and nstrip fill up collection - ///////////////////////////////////////////////////////// - - ICscClusterFitter::StripFitList sfits; - std::vector<const CscStripPrepData*> clusterStrips; - clusterStrips.reserve(50); - std::vector<Identifier> prd_digit_ids; - prd_digit_ids.reserve(50); - - for ( unsigned int icl =0; icl<newNstrips.size(); ++icl ) { // for each cluster - - ATH_MSG_VERBOSE ( " Creating " << icl << "th cluster" ); - - unsigned int nstrip = newNstrips[icl];// only used here - unsigned int strip0 = newStrip0s[icl];// only used here - - - sfits.clear(); - clusterStrips.clear(); - prd_digit_ids.clear(); - - for (unsigned int ist = strip0; ist<strip0+nstrip; ++ist) { - const CscStripPrepData* pstrip = strips[ist]; - ICscClusterFitter::StripFit sfit = allStripfits[ist]; - - sfits.push_back(sfit); - clusterStrips.push_back(pstrip); - prd_digit_ids.push_back(pstrip->identify()); + if (msgLvl(MSG::DEBUG)) { + // Log message. + ostringstream narrowlog; + narrowlog << " ** narrow Clusters " << first_strip + 1 << " " << nstrip << " L:R " + << collectLeftStrip << " " << collectRightStrip; + for (int i = 0; i < nstrip; ++i) { + narrowlog << " " << allStripfits[first_strip + i].charge; + } + for (int i = 0; i < nstrip; ++i) { + narrowlog << " " << strips[first_strip + i]; + } + ATH_MSG_DEBUG(narrowlog.str()); + } + } // Only for eta plane nstrip <3 + + strip0s.push_back(first_strip); + nstrips.push_back(nstrip); + + // Reset incluster. + incluster = false; } - ATH_MSG_VERBOSE(" ++++++++++++++ nstrip +++++ " << nstrip ); - ////////////////////////////////////////////////////////// - if (nstrip<3 && m_makeNarrowClusterThreeStrips) { - //////////////////////////////////////////////////////////////////////////////////// - /// Make every cluster have three strips /////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////// - - bool leftToFill = false; bool rightToFill = false; - if (nstrip ==1) { - leftToFill = true; rightToFill = true; - } else { - if ( sfits[0].charge > sfits[1].charge ) { - leftToFill = true; - } else if ( sfits[0].charge < sfits[1].charge ) { - rightToFill = true; - } else { - ATH_MSG_WARNING (" It should be CHECKED!!! "); - if(strip0>0){ - if ( strips[strip0-1] ) { - leftToFill = true; - } - else if (strips[strip0+2]) { - rightToFill = true; + + ////////////////////////////////////////////////////// + // Phase IV: + // + // Merge narrow cluster into adjacent cluster if any exists. + // Only for eta strips... + ///////////////////////////////////////////////////////// + vector<unsigned int> newStrip0s; + vector<unsigned int> newNstrips; + + int nMerged = 0; // the difference b/w old Nclu and new Nclu + for (unsigned int icl = 0; icl < nstrips.size(); ++icl) { + unsigned int nstrip = nstrips[icl]; + unsigned int strip0 = strip0s[icl]; + + ATH_MSG_VERBOSE(" " << icl << "th cluster merger " << strip0 << " " << nstrip); + + //#### if you find narrow cluster + if (!measphi) { + if (nstrip < 3) { + // at least one cluster before to check left cluster and continuous + if (icl > 0 && (strip0 == strip0s[icl - 1] + nstrips[icl - 1])) { + unsigned int newStrip0 = strip0s[icl - 1]; + unsigned int newNstrip = nstrips[icl - 1] + nstrip; + + ATH_MSG_DEBUG(" " << icl << " ** narrow Cluster merger Type I" << newStrip0 << " " + << newNstrip); + + newStrip0s[icl - 1 - nMerged] = newStrip0; + newNstrips[icl - 1 - nMerged] = newNstrip; + ++nMerged; + continue; + } + // at least one cluster after to check right cluster and continuous + if (icl + 1 < nstrips.size() && (strip0 + nstrip == strip0s[icl + 1])) { + unsigned int newStrip0 = strip0; + unsigned int newNstrip = nstrip + nstrips[icl + 1]; + + ATH_MSG_DEBUG(" " << icl << " ** narrow Cluster merger Type II" << newStrip0 << " " + << newNstrip); + + newStrip0s.push_back(newStrip0); + newNstrips.push_back(newNstrip); + + icl += 1; + ++nMerged; + continue; + } } - } - else if (strips[strip0+2]) { - rightToFill = true; - } - } - } - - ATH_MSG_VERBOSE( " strip0 nstrip filling left or right " - << strip0 << " " << nstrip << " "<< leftToFill << " " << rightToFill ); - ATH_MSG_VERBOSE( " sfits[0] " << sfits[0].charge ); - if (nstrip==2) - ATH_MSG_VERBOSE( " sfits[1] " << sfits[1].charge ); - - for (unsigned int i=0; i< allStripfits.size(); ++i) { - ATH_MSG_VERBOSE( "index " << i << " " << allStripfits[i].charge); - } - - - if (leftToFill) { - // ATH_MSG_DEBUG( " Left to fill " << allStripfits[strip0-1].charge); - bool fillTheOtherSide = false; - if (strip0==0) { - fillTheOtherSide = true; - } else { - if (strips[strip0-1]==NULL) - fillTheOtherSide = true; - } + } // !measphi + // if nstrip >2 OR + // still narrow strip then just keep it... + newStrip0s.push_back(strip0); + newNstrips.push_back(nstrip); + } // for + + if (strip0s.size() != newStrip0s.size()) { + ATH_MSG_DEBUG(" Phase II -> III Merged " << strip0s.size() << ":" << nstrips.size() << " " << newStrip0s.size() + << ":" << newNstrips.size()); + for (unsigned int icl = 0; icl < nstrips.size(); ++icl) + ATH_MSG_DEBUG(" *** " << icl << " [" << strip0s[icl] << "," << strip0s[icl] + nstrips[icl] - 1 << "] " + << nstrips[icl]); + for (unsigned int icl = 0; icl < newNstrips.size(); ++icl) + ATH_MSG_DEBUG(" ****** " << icl << " [" << newStrip0s[icl] << "," + << newStrip0s[icl] + newNstrips[icl] - 1 << "] " << newNstrips[icl]); + } + + + ////////////////////////////////////////////////////// + // Phase V: + // + // Using strip0 and nstrip fill up collection + ///////////////////////////////////////////////////////// + + ICscClusterFitter::StripFitList sfits; + std::vector<const CscStripPrepData*> clusterStrips; + clusterStrips.reserve(50); + std::vector<Identifier> prd_digit_ids; + prd_digit_ids.reserve(50); + + for (unsigned int icl = 0; icl < newNstrips.size(); ++icl) { // for each cluster + + ATH_MSG_VERBOSE(" Creating " << icl << "th cluster"); + + unsigned int nstrip = newNstrips[icl]; // only used here + unsigned int strip0 = newStrip0s[icl]; // only used here - if (strip0+nstrip >= allStripfits.size()) { - fillTheOtherSide = false; - } + sfits.clear(); + clusterStrips.clear(); + prd_digit_ids.clear(); - if (! fillTheOtherSide ) { - if (strips[strip0-1]) { - sfits.insert(sfits.begin(), allStripfits[strip0-1]); - clusterStrips.insert(clusterStrips.begin(), strips[strip0-1]); - prd_digit_ids.insert(prd_digit_ids.begin(), strips[strip0-1]->identify()); - strip0--; - nstrip = prd_digit_ids.size(); - } - } else { - if (strips[strip0+nstrip]) { // for edge this can happen - sfits.push_back(allStripfits[strip0+nstrip]); // This is the case for example - // 12799.6 39183.9 39698 - clusterStrips.push_back(strips[strip0+nstrip]); - prd_digit_ids.push_back(strips[strip0+nstrip]->identify()); - nstrip = prd_digit_ids.size(); - } + for (unsigned int ist = strip0; ist < strip0 + nstrip; ++ist) { + const CscStripPrepData* pstrip = strips[ist]; + ICscClusterFitter::StripFit sfit = allStripfits[ist]; + + sfits.push_back(sfit); + clusterStrips.push_back(pstrip); + prd_digit_ids.push_back(pstrip->identify()); } - } - if (rightToFill) { + ATH_MSG_VERBOSE(" ++++++++++++++ nstrip +++++ " << nstrip); + ////////////////////////////////////////////////////////// + if (nstrip < 3 && m_makeNarrowClusterThreeStrips) { + //////////////////////////////////////////////////////////////////////////////////// + /// Make every cluster have three strips /////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////// + + bool leftToFill = false; + bool rightToFill = false; + if (nstrip == 1) { + leftToFill = true; + rightToFill = true; + } else { + if (sfits[0].charge > sfits[1].charge) { + leftToFill = true; + } else if (sfits[0].charge < sfits[1].charge) { + rightToFill = true; + } else { + ATH_MSG_WARNING(" It should be CHECKED!!! "); + if (strip0 > 0) { + if (strips[strip0 - 1]) { + leftToFill = true; + } else if (strips[strip0 + 2]) { + rightToFill = true; + } + } else if (strips[strip0 + 2]) { + rightToFill = true; + } + } + } + + ATH_MSG_VERBOSE(" strip0 nstrip filling left or right " << strip0 << " " << nstrip << " " << leftToFill + << " " << rightToFill); + ATH_MSG_VERBOSE(" sfits[0] " << sfits[0].charge); + if (nstrip == 2) ATH_MSG_VERBOSE(" sfits[1] " << sfits[1].charge); + + for (unsigned int i = 0; i < allStripfits.size(); ++i) { + ATH_MSG_VERBOSE("index " << i << " " << allStripfits[i].charge); + } - bool fillTheOtherSide = false; - if (strip0+nstrip >= allStripfits.size()) { - fillTheOtherSide = true; - } else { - if (strips[strip0+nstrip]==NULL) - fillTheOtherSide = true; + + if (leftToFill) { + // ATH_MSG_DEBUG( " Left to fill " << allStripfits[strip0-1].charge); + bool fillTheOtherSide = false; + if (strip0 == 0) { + fillTheOtherSide = true; + } else { + if (strips[strip0 - 1] == NULL) fillTheOtherSide = true; + } + + if (strip0 + nstrip >= allStripfits.size()) { + fillTheOtherSide = false; + } + + + if (!fillTheOtherSide) { + if (strips[strip0 - 1]) { + sfits.insert(sfits.begin(), allStripfits[strip0 - 1]); + clusterStrips.insert(clusterStrips.begin(), strips[strip0 - 1]); + prd_digit_ids.insert(prd_digit_ids.begin(), strips[strip0 - 1]->identify()); + strip0--; + nstrip = prd_digit_ids.size(); + } + } else { + if (strips[strip0 + nstrip]) { // for edge this can happen + sfits.push_back(allStripfits[strip0 + nstrip]); // This is the case for example + // 12799.6 39183.9 39698 + clusterStrips.push_back(strips[strip0 + nstrip]); + prd_digit_ids.push_back(strips[strip0 + nstrip]->identify()); + nstrip = prd_digit_ids.size(); + } + } + } + + if (rightToFill) { + + bool fillTheOtherSide = false; + if (strip0 + nstrip >= allStripfits.size()) { + fillTheOtherSide = true; + } else { + if (strips[strip0 + nstrip] == NULL) fillTheOtherSide = true; + } + + if (strip0 == 0) { + fillTheOtherSide = false; + } + + if (!fillTheOtherSide) { + if (strips[strip0 + nstrip]) { + sfits.push_back(allStripfits[strip0 + nstrip]); + clusterStrips.push_back(strips[strip0 + nstrip]); + prd_digit_ids.push_back(strips[strip0 + nstrip]->identify()); + nstrip = prd_digit_ids.size(); + } + } else { + if (strips[strip0 - 1]) { // for edge this can happen + sfits.insert(sfits.begin(), allStripfits[strip0 - 1]); + clusterStrips.insert(clusterStrips.begin(), strips[strip0 - 1]); + prd_digit_ids.insert(prd_digit_ids.begin(), strips[strip0 - 1]->identify()); + strip0--; + nstrip = prd_digit_ids.size(); + } + } + } } + /////////////////////////////////////////////////////////////////////////// - if (strip0 == 0) { - fillTheOtherSide = false; - } - - if (! fillTheOtherSide ) { - if (strips[strip0+nstrip]) { - sfits.push_back(allStripfits[strip0+nstrip]); - clusterStrips.push_back(strips[strip0+nstrip]); - prd_digit_ids.push_back(strips[strip0+nstrip]->identify()); - nstrip = prd_digit_ids.size(); - } - } else { - if (strips[strip0-1]) { // for edge this can happen - sfits.insert(sfits.begin(), allStripfits[strip0-1]); - clusterStrips.insert(clusterStrips.begin(), strips[strip0-1]); - prd_digit_ids.insert(prd_digit_ids.begin(), strips[strip0-1]->identify()); - strip0--; - nstrip = prd_digit_ids.size(); - } - } - } - } - /////////////////////////////////////////////////////////////////////////// - - - int fitresult = 99; - std::vector<ICscClusterFitter::Result> results; - - // Precision fit. - if ( ! measphi ) { - results = m_pfitter_prec->fit(sfits); - fitresult = results[0].fitStatus; - ATH_MSG_VERBOSE ( " Performing precision fit " << m_pfitter_prec << " result return=" << fitresult ); - - // in case of multipeak cluster - if (fitresult ==6) { - results = m_pfitter_split->fit(sfits); - fitresult = results[0].fitStatus; - for (unsigned int i=0; i<results.size(); ++i) - ATH_MSG_VERBOSE ( " Performing split fit with " << m_pfitter_split << " result return=" << results[i].fitStatus ); - } - } - - bool precisionFitFailed = fitresult >0 && fitresult <20; // splitclusterFit fail => 19 - // Default fit for phi and eta failed - if ( measphi || precisionFitFailed) { - ICscClusterFitter::Result res; - CscClusterStatus oldclustatus; - if (!measphi) { - res = results[0]; - oldclustatus =res.clusterStatus; - } else { - oldclustatus =Muon::CscStatusSimple; - } - results = m_pfitter_def->fit(sfits); - if( !results.empty() ) { - res = results[0]; - fitresult = results[0].fitStatus; - if( msgLvl(MSG::VERBOSE ) ){ - ostringstream deflog; - deflog << " Performing default fit with " << m_pfitter_def; - if ( fitresult ) { - deflog << " failed: return=" << fitresult; - } else { - deflog << " succeeded"; - } - ATH_MSG_VERBOSE ( deflog.str() ); + + int fitresult = 99; + std::vector<ICscClusterFitter::Result> results; + + // Precision fit. + if (!measphi) { + results = m_pfitter_prec->fit(sfits); + fitresult = results[0].fitStatus; + ATH_MSG_VERBOSE(" Performing precision fit " << m_pfitter_prec << " result return=" << fitresult); + + // in case of multipeak cluster + if (fitresult == 6) { + results = m_pfitter_split->fit(sfits); + fitresult = results[0].fitStatus; + for (unsigned int i = 0; i < results.size(); ++i) + ATH_MSG_VERBOSE(" Performing split fit with " << m_pfitter_split + << " result return=" << results[i].fitStatus); + } } - // Keep the status from the first fit if it is defined. - if ( oldclustatus != Muon::CscStatusUndefined ) { - res.clusterStatus = oldclustatus; - // we want to keep oldcluster status - results[0] = res; + + bool precisionFitFailed = fitresult > 0 && fitresult < 20; // splitclusterFit fail => 19 + // Default fit for phi and eta failed + if (measphi || precisionFitFailed) { + ICscClusterFitter::Result res; + CscClusterStatus oldclustatus; + if (!measphi) { + res = results[0]; + oldclustatus = res.clusterStatus; + } else { + oldclustatus = Muon::CscStatusSimple; + } + results = m_pfitter_def->fit(sfits); + if (!results.empty()) { + res = results[0]; + fitresult = results[0].fitStatus; + if (msgLvl(MSG::VERBOSE)) { + ostringstream deflog; + deflog << " Performing default fit with " << m_pfitter_def; + if (fitresult) { + deflog << " failed: return=" << fitresult; + } else { + deflog << " succeeded"; + } + ATH_MSG_VERBOSE(deflog.str()); + } + // Keep the status from the first fit if it is defined. + if (oldclustatus != Muon::CscStatusUndefined) { + res.clusterStatus = oldclustatus; + // we want to keep oldcluster status + results[0] = res; + } + } } - } - } - //////// - // - // Phase V. For multiple results, fill up collection - // - /////////////// - unsigned int nresults = results.size(); - for (unsigned int ire=0; ire<nresults; ++ire) { - CscClusterStatus clustatus = results[ire].clusterStatus; - Muon::CscTimeStatus timeStatus = results[ire].timeStatus; - double pos = results[ire].position; - double err = results[ire].dposition; - unsigned int id_strip = results[ire].strip; // return peak strip index (unsigned integer) - double cluster_charge = results[ire].charge; - double cluster_time = results[ire].time; - if ( clustatus == Muon::CscStatusUndefined ) - ATH_MSG_DEBUG ( " Csc Cluster Status is not defined." ); - - if ( id_strip >= sfits.size() ) { - ATH_MSG_WARNING ( " Fit size check failed: " ); - continue; - } - // Fetch the strip used to identify this cluster. - const CscStripPrepData* pstrip_id = 0; - if ( id_strip < clusterStrips.size() ) pstrip_id = clusterStrips[id_strip]; - if ( ! pstrip_id ) { - ATH_MSG_WARNING ( " Fit ID check failed: " ); - continue; - } - - // Create ATLAS CSC cluster. - Identifier cluster_id = pstrip_id->identify(); - IdentifierHash cluster_hash = pstrip_id->collectionHash(); - int zsec = m_idHelperSvc->cscIdHelper().stationEta(cluster_id); - int wlay = m_idHelperSvc->cscIdHelper().wireLayer(cluster_id); - // This local position is in the muon (not tracking) coordinate system. - // retrieve MuonDetectorManager from the conditions store - SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey}; - const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr(); - if(MuonDetMgr==nullptr){ - ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object"); - return 0; - } - const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(cluster_id); - //Amg::Vector3D local_pos = pro->localClusterPos(zsec, wlay, measphi, pos); - Amg::Vector3D localTrk_pos = pro->nominalLocalClusterPos(zsec, wlay, measphi, pos); - - Amg::MatrixX* cov = new Amg::MatrixX(1,1); - (*cov)(0,0) = err*err; - Amg::Vector2D plpos( measphi ? localTrk_pos.y() : localTrk_pos.z(), measphi ? localTrk_pos.z() : localTrk_pos.y()); - if( msgLvl(MSG::DEBUG) ){ - - ATH_MSG_DEBUG ( " Cluster parameters: " << nresults ); - ATH_MSG_DEBUG ( " ID strip: " << first_strip + id_strip - << "(" << first_strip << ":" << id_strip << ")" ); - ATH_MSG_DEBUG ( " local position: " << plpos.x() << " " << plpos.y() - << " error: " << Amg::toString(*cov) ); - ATH_MSG_DEBUG ( " charge: " << cluster_charge ); - ATH_MSG_DEBUG ( " time: " << cluster_time ); - ATH_MSG_DEBUG ( " status: " << Muon::toString(clustatus) ); - } - unsigned int fstrip =results[ire].fstrip; - unsigned int lstrip =results[ire].lstrip; - std::vector<Identifier> prd_digit_ids_submit; - for ( unsigned int ids_index=fstrip; ids_index<lstrip+1; ++ids_index ) { - if( ids_index >= prd_digit_ids.size() ){ - ATH_MSG_WARNING("index out of range " << ids_index << " size " << prd_digit_ids.size() ); - continue; + //////// + // + // Phase V. For multiple results, fill up collection + // + /////////////// + unsigned int nresults = results.size(); + for (unsigned int ire = 0; ire < nresults; ++ire) { + CscClusterStatus clustatus = results[ire].clusterStatus; + Muon::CscTimeStatus timeStatus = results[ire].timeStatus; + double pos = results[ire].position; + double err = results[ire].dposition; + unsigned int id_strip = results[ire].strip; // return peak strip index (unsigned integer) + double cluster_charge = results[ire].charge; + double cluster_time = results[ire].time; + if (clustatus == Muon::CscStatusUndefined) ATH_MSG_DEBUG(" Csc Cluster Status is not defined."); + + if (id_strip >= sfits.size()) { + ATH_MSG_WARNING(" Fit size check failed: "); + continue; + } + // Fetch the strip used to identify this cluster. + const CscStripPrepData* pstrip_id = 0; + if (id_strip < clusterStrips.size()) pstrip_id = clusterStrips[id_strip]; + if (!pstrip_id) { + ATH_MSG_WARNING(" Fit ID check failed: "); + continue; + } + + // Create ATLAS CSC cluster. + Identifier cluster_id = pstrip_id->identify(); + IdentifierHash cluster_hash = pstrip_id->collectionHash(); + int zsec = m_idHelperSvc->cscIdHelper().stationEta(cluster_id); + int wlay = m_idHelperSvc->cscIdHelper().wireLayer(cluster_id); + // This local position is in the muon (not tracking) coordinate system. + // retrieve MuonDetectorManager from the conditions store + SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey}; + const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr(); + if (MuonDetMgr == nullptr) { + ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object"); + return 0; + } + const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(cluster_id); + // Amg::Vector3D local_pos = pro->localClusterPos(zsec, wlay, measphi, pos); + Amg::Vector3D localTrk_pos = pro->nominalLocalClusterPos(zsec, wlay, measphi, pos); + + Amg::MatrixX* cov = new Amg::MatrixX(1, 1); + (*cov)(0, 0) = err * err; + Amg::Vector2D plpos(measphi ? localTrk_pos.y() : localTrk_pos.z(), + measphi ? localTrk_pos.z() : localTrk_pos.y()); + if (msgLvl(MSG::DEBUG)) { + + ATH_MSG_DEBUG(" Cluster parameters: " << nresults); + ATH_MSG_DEBUG(" ID strip: " << first_strip + id_strip << "(" << first_strip << ":" + << id_strip << ")"); + ATH_MSG_DEBUG(" local position: " << plpos.x() << " " << plpos.y() + << " error: " << Amg::toString(*cov)); + ATH_MSG_DEBUG(" charge: " << cluster_charge); + ATH_MSG_DEBUG(" time: " << cluster_time); + ATH_MSG_DEBUG(" status: " << Muon::toString(clustatus)); + } + unsigned int fstrip = results[ire].fstrip; + unsigned int lstrip = results[ire].lstrip; + std::vector<Identifier> prd_digit_ids_submit; + for (unsigned int ids_index = fstrip; ids_index < lstrip + 1; ++ids_index) { + if (ids_index >= prd_digit_ids.size()) { + ATH_MSG_WARNING("index out of range " << ids_index << " size " << prd_digit_ids.size()); + continue; + } + prd_digit_ids_submit.push_back(prd_digit_ids[ids_index]); + } + unsigned int nstrip = prd_digit_ids_submit.size(); + ATH_MSG_DEBUG(" size: " << nstrip << " " << sfits.size()); + ATH_MSG_DEBUG(" all size: " << strips.size() << " " << allStripfits.size()); + + + // allStripfits.push_back(res); + + CscPrepData* pclus = new CscPrepData(cluster_id, cluster_hash, plpos, prd_digit_ids_submit, cov, pro, + int(cluster_charge + 0.5), cluster_time, clustatus, timeStatus); + pclus->setHashAndIndex(newCollection->identifyHash(), newCollection->size()); + + newCollection->push_back(pclus); } - prd_digit_ids_submit.push_back(prd_digit_ids[ids_index]); - } - unsigned int nstrip = prd_digit_ids_submit.size(); - ATH_MSG_DEBUG ( " size: " << nstrip << " " << sfits.size()); - ATH_MSG_DEBUG ( " all size: " << strips.size() << " " << allStripfits.size()); - - - // allStripfits.push_back(res); - - CscPrepData* pclus = new CscPrepData(cluster_id, cluster_hash, plpos, prd_digit_ids_submit, - cov, pro, int(cluster_charge+0.5), cluster_time, - clustatus, timeStatus); - pclus->setHashAndIndex(newCollection->identifyHash(), newCollection->size()); - - newCollection->push_back(pclus); - - } - } // end loop over clusters + } // end loop over clusters - return 0; + return 0; } //****************************************************************************** diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilderTool.h b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilderTool.h index 1343046d4351..8a34695e763b 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilderTool.h +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/CscThresholdClusterBuilderTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // CscThresholdClusterBuilderTool.h @@ -55,98 +55,102 @@ // Algorithm to construct CSC clusters from digits. #include "AthenaBaseComps/AthAlgTool.h" -#include "GaudiKernel/ToolHandle.h" -#include "MuonPrepRawData/MuonPrepDataContainer.h" #include "CscClusterization/ICscClusterBuilder.h" +#include "GaudiKernel/ToolHandle.h" +#include "MuonIdHelpers/IMuonIdHelperSvc.h" #include "MuonPrepRawData/CscPrepDataContainer.h" #include "MuonPrepRawData/CscStripPrepDataContainer.h" - +#include "MuonPrepRawData/MuonPrepDataContainer.h" #include "MuonReadoutGeometry/MuonDetectorManager.h" -#include "MuonIdHelpers/IMuonIdHelperSvc.h" class ICscCalibTool; class ICscStripFitter; class ICscClusterFitter; namespace Muon { - class CscPrepData; - class CscStripPrepData; -} +class CscPrepData; +class CscStripPrepData; +} // namespace Muon typedef Muon::CscPrepData MyCscDigit; class CscDigit; class CscThresholdClusterBuilderTool : virtual public ICscClusterBuilder, public AthAlgTool { - -public: // methods - - enum NoiseOption { - rms = 0, sigma, f001 - }; - - - // Constructor. - CscThresholdClusterBuilderTool(const std::string &type, const std::string &aname, const IInterface* ); - - // Destructor. - ~CscThresholdClusterBuilderTool(); - - /** AlgTool InterfaceID - */ - // static const InterfaceID& interfaceID( ) ; - - - // Initialization. - StatusCode initialize(); - - // Event processing. - StatusCode getClusters(std::vector<IdentifierHash>& idVect, std::vector<IdentifierHash>& selectedIdVect); - - // Finalization. - StatusCode finalize(); - -private: // Private methods. - - // Cluster a cathode plane. - // int make_clusters(bool dump, int maxstrip, double pitch, - // const std::vector<MyCscDigit*>& idstrip, const std::vector<double>& qstrip); - // int make_clusters(bool dump, int maxstrip, double pitch, const std::vector<Muon::CscStripPrepData*>& strips); - int make_clusters(bool measphi, const std::vector<const Muon::CscStripPrepData*>& strips,Muon::CscPrepDataCollection *&collection); - StatusCode getClusters(IdentifierHash idVect, std::vector<IdentifierHash>& selectedIdVect); - StatusCode getClusters(IdentifierHash idVect, std::vector<IdentifierHash>& selectedIdVect, Muon::CscPrepDataContainer *pclusters); - StatusCode getClusters(std::vector<IdentifierHash>& selectedIdVect, Muon::CscPrepDataContainer *pclusters); -private: // data - - // Properties. - double m_threshold; // Charge threshold to include strip in cluster - float m_kFactor; - std::string m_noiseOptionStr; - NoiseOption m_noiseOption; - SG::ReadHandleKey<Muon::CscStripPrepDataContainer> m_digit_key; // SG key for input digits - SG::WriteHandleKey<Muon::CscPrepDataContainer> m_pclusters; // SG key for output clusters - - // Calibration tool. - ToolHandle<ICscCalibTool> m_cscCalibTool; - - // Strip fitter. - ToolHandle<ICscStripFitter> m_pstrip_fitter; - - // Cluster fitters. - ToolHandle<ICscClusterFitter> m_pfitter_def; - ToolHandle<ICscClusterFitter> m_pfitter_prec; - ToolHandle<ICscClusterFitter> m_pfitter_split; - - ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}; - - /** retrieve MuonDetectorManager from the conditions store */ - SG::ReadCondHandleKey<MuonGM::MuonDetectorManager> m_DetectorManagerKey {this, "DetectorManagerKey", - "MuonDetectorManager", "Key of input MuonDetectorManager condition data"}; - - // keep track of full event being already processed - bool m_fullEventDone; - - bool m_makeNarrowClusterThreeStrips; - + + public: // methods + enum NoiseOption { rms = 0, sigma, f001 }; + + + // Constructor. + CscThresholdClusterBuilderTool(const std::string& type, const std::string& aname, const IInterface*); + + // Destructor. + ~CscThresholdClusterBuilderTool(); + + /** AlgTool InterfaceID + */ + // static const InterfaceID& interfaceID( ) ; + + + // Initialization. + StatusCode initialize(); + + // Event processing. + StatusCode getClusters(std::vector<IdentifierHash>& idVect, std::vector<IdentifierHash>& selectedIdVect); + + // Finalization. + StatusCode finalize(); + + private: // Private methods. + // Cluster a cathode plane. + // int make_clusters(bool dump, int maxstrip, double pitch, + // const std::vector<MyCscDigit*>& idstrip, const std::vector<double>& qstrip); + // int make_clusters(bool dump, int maxstrip, double pitch, const std::vector<Muon::CscStripPrepData*>& strips); + int make_clusters(bool measphi, const std::vector<const Muon::CscStripPrepData*>& strips, + Muon::CscPrepDataCollection*& collection); + StatusCode getClusters(IdentifierHash idVect, std::vector<IdentifierHash>& selectedIdVect); + StatusCode getClusters(IdentifierHash idVect, std::vector<IdentifierHash>& selectedIdVect, + Muon::CscPrepDataContainer* pclusters); + StatusCode getClusters(std::vector<IdentifierHash>& selectedIdVect, Muon::CscPrepDataContainer* pclusters); + + private: // data + // Properties. + double m_threshold; // Charge threshold to include strip in cluster + float m_kFactor; + std::string m_noiseOptionStr; + NoiseOption m_noiseOption; + SG::ReadHandleKey<Muon::CscStripPrepDataContainer> m_digit_key; // SG key for input digits + SG::WriteHandleKey<Muon::CscPrepDataContainer> m_pclusters; // SG key for output clusters + + // Calibration tool. + ToolHandle<ICscCalibTool> m_cscCalibTool; + + // Strip fitter. + ToolHandle<ICscStripFitter> m_pstrip_fitter; + + // Cluster fitters. + ToolHandle<ICscClusterFitter> m_pfitter_def; + ToolHandle<ICscClusterFitter> m_pfitter_prec; + ToolHandle<ICscClusterFitter> m_pfitter_split; + + ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc{ + this, + "MuonIdHelperSvc", + "Muon::MuonIdHelperSvc/MuonIdHelperSvc", + }; + + /** retrieve MuonDetectorManager from the conditions store */ + SG::ReadCondHandleKey<MuonGM::MuonDetectorManager> m_DetectorManagerKey{ + this, + "DetectorManagerKey", + "MuonDetectorManager", + "Key of input MuonDetectorManager condition data", + }; + + // keep track of full event being already processed + bool m_fullEventDone; + + bool m_makeNarrowClusterThreeStrips; }; #endif diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/QratCscClusterFitter.cxx b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/QratCscClusterFitter.cxx index d75e378db937..3010bb8df977 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/QratCscClusterFitter.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/QratCscClusterFitter.cxx @@ -4,110 +4,125 @@ #include "QratCscClusterFitter.h" +#include <iomanip> +#include <sstream> + +#include "EventPrimitives/EventPrimitives.h" +#include "EventPrimitives/EventPrimitivesHelpers.h" #include "MuonPrepRawData/CscClusterStatus.h" -#include "MuonPrepRawData/CscStripPrepData.h" #include "MuonPrepRawData/CscPrepData.h" +#include "MuonPrepRawData/CscStripPrepData.h" #include "MuonReadoutGeometry/CscReadoutElement.h" -#include "TrkEventPrimitives/ParamDefs.h" #include "TrkEventPrimitives/LocalDirection.h" -#include "EventPrimitives/EventPrimitives.h" -#include "EventPrimitives/EventPrimitivesHelpers.h" - -#include <sstream> -#include <iomanip> +#include "TrkEventPrimitives/ParamDefs.h" using Muon::CscClusterStatus; -using Muon::CscStripPrepData; using Muon::CscPrepData; +using Muon::CscStripPrepData; using MuonGM::CscReadoutElement; typedef ICscClusterFitter::DataNames DataNames; -typedef ICscClusterFitter::Result Result; -typedef std::vector<Result> Results; +typedef ICscClusterFitter::Result Result; +typedef std::vector<Result> Results; enum CscStation { UNKNOWN_STATION, CSS, CSL }; enum CscPlane { CSS_ETA, CSL_ETA, CSS_PHI, CSL_PHI, UNKNOWN_PLANE }; namespace { - std::string splane(CscPlane plane) { - switch(plane) { - case CSS_ETA: return "CSS eta"; - case CSL_ETA: return "CSL eta"; - case CSS_PHI: return "CSS phi"; - case CSL_PHI: return "CSL phi"; - case UNKNOWN_PLANE: return "no such plane"; +std::string +splane(CscPlane plane) +{ + switch (plane) { + case CSS_ETA: + return "CSS eta"; + case CSL_ETA: + return "CSL eta"; + case CSS_PHI: + return "CSS phi"; + case CSL_PHI: + return "CSL phi"; + case UNKNOWN_PLANE: + return "no such plane"; } return "no such plane"; - } - - CscPlane findPlane(int station, bool measphi){ - if ( station == 1 ) { - if ( measphi ) return CSS_PHI; - else return CSS_ETA; - } else if ( station == 2 ) { - if ( measphi ) return CSL_PHI; - else return CSL_ETA; +} + +CscPlane +findPlane(int station, bool measphi) +{ + if (station == 1) { + if (measphi) + return CSS_PHI; + else + return CSS_ETA; + } else if (station == 2) { + if (measphi) + return CSL_PHI; + else + return CSL_ETA; } return UNKNOWN_PLANE; - } } +} // namespace //****************************************************************************** -int qrat_correction(CscPlane plane, double qrat, double& cor, double& dcordqrat) { - std::vector<double> pfac; - if ( plane == CSS_ETA ) { - if ( qrat < 0.095 ) return 1; - if ( qrat > 1.01 ) return 1; - if ( qrat < 0.15 ) { - pfac.push_back(-5.483); - pfac.push_back(130.6); - pfac.push_back(-1296.); - pfac.push_back(5994.); - pfac.push_back(-10580.); - } else if ( qrat < 0.30 ) { - pfac.push_back(-0.9225); - pfac.push_back(5.569); - pfac.push_back(2.908); - pfac.push_back(-66.19); - pfac.push_back(108.5); +int +qrat_correction(CscPlane plane, double qrat, double& cor, double& dcordqrat) +{ + std::vector<double> pfac; + if (plane == CSS_ETA) { + if (qrat < 0.095) return 1; + if (qrat > 1.01) return 1; + if (qrat < 0.15) { + pfac.push_back(-5.483); + pfac.push_back(130.6); + pfac.push_back(-1296.); + pfac.push_back(5994.); + pfac.push_back(-10580.); + } else if (qrat < 0.30) { + pfac.push_back(-0.9225); + pfac.push_back(5.569); + pfac.push_back(2.908); + pfac.push_back(-66.19); + pfac.push_back(108.5); + } else { + pfac.push_back(-0.4246); + pfac.push_back(2.619); + pfac.push_back(-3.642); + pfac.push_back(2.837); + pfac.push_back(-0.8916); + } + } else if (plane == CSL_ETA) { + if (qrat < 0.105) return 1; + if (qrat > 1.01) return 1; + if (qrat < 0.25) { + pfac.push_back(-2.823); + pfac.push_back(42.71); + pfac.push_back(-279.1); + pfac.push_back(879.2); + pfac.push_back(-1062.); + } else { + pfac.push_back(-0.5409); + pfac.push_back(3.110); + pfac.push_back(-4.630); + pfac.push_back(3.800); + pfac.push_back(-1.241); + } } else { - pfac.push_back(-0.4246); - pfac.push_back(2.619); - pfac.push_back(-3.642); - pfac.push_back(2.837); - pfac.push_back(-0.8916); + return 3; } - } else if ( plane == CSL_ETA ) { - if ( qrat < 0.105 ) return 1; - if ( qrat > 1.01 ) return 1; - if ( qrat < 0.25 ) { - pfac.push_back(-2.823); - pfac.push_back(42.71); - pfac.push_back(-279.1); - pfac.push_back(879.2); - pfac.push_back(-1062.); - } else { - pfac.push_back(-0.5409); - pfac.push_back(3.110); - pfac.push_back(-4.630); - pfac.push_back(3.800); - pfac.push_back(-1.241); + cor = 0.0; + dcordqrat = 0.0; + double term = 1.0; + for (unsigned int ipow = 0; ipow < pfac.size(); ++ipow) { + dcordqrat += ipow * pfac[ipow] * term; + if (ipow) term *= qrat; + cor += pfac[ipow] * term; } - } else { - return 3; - } - cor = 0.0; - dcordqrat = 0.0; - double term = 1.0; - for ( unsigned int ipow=0; ipow<pfac.size(); ++ipow ) { - dcordqrat += ipow*pfac[ipow]*term; - if ( ipow ) term *= qrat; - cor += pfac[ipow]*term; - } - return 0; + return 0; } - + //****************************************************************************** // Calculate QRAT correction by interpolation. @@ -120,57 +135,58 @@ int qrat_correction(CscPlane plane, double qrat, double& cor, double& dcordqrat) // cor = output correction // dcordqrat = derivative of cor w.r.t. qrat -int qrat_interpolation(double qrmin, const std::vector<double>& corvals, - double qrat, double& cor, double& dcordqrat) { - int nbin = corvals.size(); - if ( ! nbin ) return 1; - // Treat any QRAT below the minimum as if it were at the minumum. - if ( qrat < qrmin ) qrat = qrmin; - // Find the bin holding dqrat. - double dqrat = 1.0/nbin; - int bin = int(qrat/dqrat); - // Extract the value for this bin (x1) and the preceding (x0) - // and the following (x2). - double x1 = corvals[bin]; - if ( x1 == 0.0 ) return 2; - double x0 = bin==0 ? 0.0 : corvals[bin-1]; - double x2 = bin==nbin-1 ? 1.0 : corvals[bin+1]; - // Assign the qrat values for these bins. If this is the first - // bin with data, then use the input qrmin. - double qrat0 = dqrat*bin; - double qrat1 = qrat0 + dqrat; - - if ( x0 == 0.0 ) { - if ( qrmin > qrat0 && qrmin < qrat1 ) { - qrat0 = qrmin; +int +qrat_interpolation(double qrmin, const std::vector<double>& corvals, double qrat, double& cor, double& dcordqrat) +{ + int nbin = corvals.size(); + if (!nbin) return 1; + // Treat any QRAT below the minimum as if it were at the minumum. + if (qrat < qrmin) qrat = qrmin; + // Find the bin holding dqrat. + double dqrat = 1.0 / nbin; + int bin = int(qrat / dqrat); + // Extract the value for this bin (x1) and the preceding (x0) + // and the following (x2). + double x1 = corvals[bin]; + if (x1 == 0.0) return 2; + double x0 = bin == 0 ? 0.0 : corvals[bin - 1]; + double x2 = bin == nbin - 1 ? 1.0 : corvals[bin + 1]; + // Assign the qrat values for these bins. If this is the first + // bin with data, then use the input qrmin. + double qrat0 = dqrat * bin; + double qrat1 = qrat0 + dqrat; + + if (x0 == 0.0) { + if (qrmin > qrat0 && qrmin < qrat1) { + qrat0 = qrmin; + } + } + // Calculate correction and derivative. + // Use quadratic interpolation with the high edge of this bin, + // the preceding and the following. For the last bin, use linear + // interpolation. + if (bin == nbin - 1) { + double a = x0; + double b = (x1 - x0) / dqrat; + cor = a + b * (qrat - qrat0); + dcordqrat = b; + } else { + double d0 = qrat1 - qrat0; + double d = dqrat; + double w = 1.0 / (d0 * d * d + d0 * d0 * d); + double a = x1; + double b = w * d * d * (x1 - x0) + w * d0 * d0 * (x2 - x1); + double c = w * d0 * (x2 - x1) - w * d * (x1 - x0); + cor = a + b * (qrat - qrat1) + c * (qrat - qrat1) * (qrat - qrat1); + dcordqrat = b + 2.0 * c * (qrat - qrat1); } - } - // Calculate correction and derivative. - // Use quadratic interpolation with the high edge of this bin, - // the preceding and the following. For the last bin, use linear - // interpolation. - if ( bin == nbin-1 ) { - double a = x0; - double b = (x1-x0)/dqrat; - cor = a + b*(qrat-qrat0); - dcordqrat = b; - } else { - double d0 = qrat1 - qrat0; - double d = dqrat; - double w = 1.0/(d0*d*d+d0*d0*d); - double a = x1; - double b = w*d*d*(x1-x0) + w*d0*d0*(x2-x1); - double c = w*d0*(x2-x1) - w*d*(x1-x0); - cor = a + b*(qrat-qrat1) + c*(qrat-qrat1)*(qrat-qrat1); - dcordqrat = b + 2.0*c*(qrat-qrat1); - } - if ( cor < 0.0 ) cor = 0.0; - // Shift correction to center of bin. - cor -= 0.50; - return 0; + if (cor < 0.0) cor = 0.0; + // Shift correction to center of bin. + cor -= 0.50; + return 0; } - + //**************************************************************************** /** Calculate QRAT correction from inverse hyperbolic tangent @@ -190,616 +206,620 @@ int qrat_interpolation(double qrmin, const std::vector<double>& corvals, @param dcordqrat = derivative of cor w.r.t. qrat for error estimates @return 0 if no error, 1 if qrat is negative */ -int qrat_atanh(const double a, const double b, double c, const double x0, - double qrat, double& cor, double& dcordqrat) { - if (qrat<=0) return 1; // avoid trouble in error calculation - // minimum qrat value (at pos=-1) or use pos = -0.5? - double qrmin = a + b*tanh(c*(-1-x0)); - - // Treat any QRAT below the minimum as if it were at the minumum. - if ( qrat < qrmin ) qrat = qrmin; - double z = (qrat-a)/b; - cor = atanh(z)/c+x0; - dcordqrat = 1.0/(1.0-z*z)/b/c; - - return 0; +int +qrat_atanh(const double a, const double b, double c, const double x0, double qrat, double& cor, double& dcordqrat) +{ + if (qrat <= 0) return 1; // avoid trouble in error calculation + // minimum qrat value (at pos=-1) or use pos = -0.5? + double qrmin = a + b * tanh(c * (-1 - x0)); + + // Treat any QRAT below the minimum as if it were at the minumum. + if (qrat < qrmin) qrat = qrmin; + double z = (qrat - a) / b; + cor = atanh(z) / c + x0; + dcordqrat = 1.0 / (1.0 - z * z) / b / c; + + return 0; } //**************************************************************************** -QratCscClusterFitter::QratCscClusterFitter(std::string type, std::string aname, const IInterface* parent) : - AthAlgTool(type, aname, parent), - m_alignmentTool("CscAlignmentTool/CscAlignmentTool", this) +QratCscClusterFitter::QratCscClusterFitter(std::string type, std::string aname, const IInterface* parent) + : AthAlgTool(type, aname, parent), m_alignmentTool("CscAlignmentTool/CscAlignmentTool", this) { - declareInterface<ICscClusterFitter>(this); - m_max_width.push_back(5); // CSS eta - m_max_width.push_back(5); // CSL eta - m_max_width.push_back(3); // CSS phi - m_max_width.push_back(2); // CSL phi - declareProperty("max_width", m_max_width); // Maximum width (strips) for unspoiled clusters - declareProperty("position_option_eta", m_posopt_eta = "ATANH"); - declareProperty("position_option_phi", m_posopt_phi = "NONE"); - declareProperty("error_option_eta", m_erropt_eta = "CHARGE"); - declareProperty("error_option_phi", m_erropt_phi = "NONE"); - declareProperty("error_eta", m_error_eta = 0.050); // in mm this is for fixed error - declareProperty("error_phi", m_error_phi = 0.140); // in mm this is for fixed error - - declareProperty("precisionErrorScaler", m_precisionErrorScaler = 1.0); // in mm this is for fixed error - - declareProperty("qrat_maxdiff", m_qrat_maxdiff = 0.15); // in strips - declareProperty("qrat_maxsig", m_qrat_maxsig = 6.0); // in strips - declareProperty("error_tantheta", m_error_tantheta = 0.57); // in mm - declareProperty("xtan_css_eta_offset", m_xtan_css_eta_offset = 0.0015); // in mm - declareProperty("xtan_css_eta_slope", m_xtan_css_eta_slope = 0.000137); // in mm - declareProperty("xtan_csl_eta_offset", m_xtan_csl_eta_offset = -0.0045); // in mm - declareProperty("xtan_csl_eta_slope", m_xtan_csl_eta_slope = 0.000131); // in mm - declareProperty("qratmin_css_eta", m_qratmin_css_eta = 0.0940459); - declareProperty("qratmin_csl_eta", m_qratmin_csl_eta = 0.108975); - declareProperty("qratcor_css_eta", m_qratcor_css_eta); // in strips - declareProperty("qratcor_csl_eta", m_qratcor_csl_eta); // in strips - - - declareProperty("atanh_a_css_eta", m_atanh_a_css_eta = 1.5); - declareProperty("atanh_b_css_eta", m_atanh_b_css_eta = 1.411); - declareProperty("atanh_c_css_eta", m_atanh_c_css_eta = 2.329); - declareProperty("atanh_x0_css_eta", m_atanh_x0_css_eta = 0.6601); - declareProperty("atanh_a_csl_eta", m_atanh_a_csl_eta = 1.516); - declareProperty("atanh_b_csl_eta", m_atanh_b_csl_eta = 1.427); - declareProperty("atanh_c_csl_eta", m_atanh_c_csl_eta = 2.35); - declareProperty("atanh_x0_csl_eta",m_atanh_x0_csl_eta = 0.6615); - - declareProperty("dposmin", m_dposmin = 0.082); - - declareProperty("CscAlignmentTool", m_alignmentTool ); - + declareInterface<ICscClusterFitter>(this); + m_max_width.push_back(5); // CSS eta + m_max_width.push_back(5); // CSL eta + m_max_width.push_back(3); // CSS phi + m_max_width.push_back(2); // CSL phi + declareProperty("max_width", m_max_width); // Maximum width (strips) for unspoiled clusters + declareProperty("position_option_eta", m_posopt_eta = "ATANH"); + declareProperty("position_option_phi", m_posopt_phi = "NONE"); + declareProperty("error_option_eta", m_erropt_eta = "CHARGE"); + declareProperty("error_option_phi", m_erropt_phi = "NONE"); + declareProperty("error_eta", m_error_eta = 0.050); // in mm this is for fixed error + declareProperty("error_phi", m_error_phi = 0.140); // in mm this is for fixed error + + declareProperty("precisionErrorScaler", m_precisionErrorScaler = 1.0); // in mm this is for fixed error + + declareProperty("qrat_maxdiff", m_qrat_maxdiff = 0.15); // in strips + declareProperty("qrat_maxsig", m_qrat_maxsig = 6.0); // in strips + declareProperty("error_tantheta", m_error_tantheta = 0.57); // in mm + declareProperty("xtan_css_eta_offset", m_xtan_css_eta_offset = 0.0015); // in mm + declareProperty("xtan_css_eta_slope", m_xtan_css_eta_slope = 0.000137); // in mm + declareProperty("xtan_csl_eta_offset", m_xtan_csl_eta_offset = -0.0045); // in mm + declareProperty("xtan_csl_eta_slope", m_xtan_csl_eta_slope = 0.000131); // in mm + declareProperty("qratmin_css_eta", m_qratmin_css_eta = 0.0940459); + declareProperty("qratmin_csl_eta", m_qratmin_csl_eta = 0.108975); + declareProperty("qratcor_css_eta", m_qratcor_css_eta); // in strips + declareProperty("qratcor_csl_eta", m_qratcor_csl_eta); // in strips + + + declareProperty("atanh_a_css_eta", m_atanh_a_css_eta = 1.5); + declareProperty("atanh_b_css_eta", m_atanh_b_css_eta = 1.411); + declareProperty("atanh_c_css_eta", m_atanh_c_css_eta = 2.329); + declareProperty("atanh_x0_css_eta", m_atanh_x0_css_eta = 0.6601); + declareProperty("atanh_a_csl_eta", m_atanh_a_csl_eta = 1.516); + declareProperty("atanh_b_csl_eta", m_atanh_b_csl_eta = 1.427); + declareProperty("atanh_c_csl_eta", m_atanh_c_csl_eta = 2.35); + declareProperty("atanh_x0_csl_eta", m_atanh_x0_csl_eta = 0.6615); + + declareProperty("dposmin", m_dposmin = 0.082); + + declareProperty("CscAlignmentTool", m_alignmentTool); } //********************************************************************** -StatusCode QratCscClusterFitter::initialize() { - - ATH_MSG_VERBOSE ( "Initalizing " << name() ); - - // retrieve MuonDetectorManager from the conditions store - ATH_CHECK(m_DetectorManagerKey.initialize()); - - ATH_CHECK(m_idHelperSvc.retrieve()); - - if ( m_alignmentTool.retrieve().isFailure() ) { - ATH_MSG_WARNING ( name() << ": unable to retrieve cluster fitter " << m_alignmentTool ); - } else { - ATH_MSG_DEBUG ( name() << ": retrieved " << m_alignmentTool ); - } - - - - ATH_MSG_DEBUG ( "Properties for " << name() << ":" ); - ATH_MSG_DEBUG ( " Eta position option: " << m_posopt_eta ); - ATH_MSG_DEBUG ( " Phi position option: " << m_posopt_phi ); - ATH_MSG_DEBUG ( " Eta error option: " << m_erropt_eta ); - ATH_MSG_DEBUG ( " Phi error option: " << m_erropt_phi ); - ATH_MSG_DEBUG ( " Eta assigned error: " << m_error_eta ); - ATH_MSG_DEBUG ( " Phi assigned error: " << m_error_phi ); - ATH_MSG_DEBUG ( " Max strip pos diff: " << m_qrat_maxdiff ); - ATH_MSG_DEBUG ( " Max strip pos sig: " << m_qrat_maxsig ); - ATH_MSG_DEBUG ( " Non-normal error coeff: " << m_error_tantheta ); - ATH_MSG_DEBUG ( " CSS eta pos-slope offset: " << m_xtan_css_eta_offset ); - ATH_MSG_DEBUG ( " CSS eta pos-slope slope: " << m_xtan_css_eta_slope ); - ATH_MSG_DEBUG ( " CSL eta pos-slope offset: " << m_xtan_csl_eta_offset ); - ATH_MSG_DEBUG ( " CSL eta pos-slope slope: " << m_xtan_csl_eta_slope ); - ATH_MSG_DEBUG ( " CSS eta table offset: " << m_qratmin_css_eta ); - ATH_MSG_DEBUG ( " CSL eta table offset: " << m_qratmin_csl_eta ); - ATH_MSG_DEBUG ( " CSS eta table size: " << m_qratcor_css_eta.size() ); - ATH_MSG_DEBUG ( " CSL eta table size: " << m_qratcor_csl_eta.size() ); - - ATH_MSG_DEBUG ( "atanh_a_css_eta: " << m_atanh_a_css_eta ); - ATH_MSG_DEBUG ( "atanh_b_css_eta: " << m_atanh_b_css_eta ); - ATH_MSG_DEBUG ( "atanh_c_css_eta: " << m_atanh_c_css_eta ); - ATH_MSG_DEBUG ( "atanh_x0_css_eta: " << m_atanh_x0_css_eta ); - ATH_MSG_DEBUG ( "atanh_a_csl_eta: " << m_atanh_a_csl_eta ); - ATH_MSG_DEBUG ( "atanh_b_csl_eta: " << m_atanh_b_csl_eta ); - ATH_MSG_DEBUG ( "atanh_c_csl_eta: " << m_atanh_c_csl_eta ); - ATH_MSG_DEBUG ( "atanh_x0_csl_eta: " << m_atanh_x0_csl_eta ); - - ATH_MSG_DEBUG ( "Minimum pos error: " << m_dposmin ); - - return StatusCode::SUCCESS; +StatusCode +QratCscClusterFitter::initialize() +{ + + ATH_MSG_VERBOSE("Initalizing " << name()); + + // retrieve MuonDetectorManager from the conditions store + ATH_CHECK(m_DetectorManagerKey.initialize()); + + ATH_CHECK(m_idHelperSvc.retrieve()); + + if (m_alignmentTool.retrieve().isFailure()) { + ATH_MSG_WARNING(name() << ": unable to retrieve cluster fitter " << m_alignmentTool); + } else { + ATH_MSG_DEBUG(name() << ": retrieved " << m_alignmentTool); + } + + + ATH_MSG_DEBUG("Properties for " << name() << ":"); + ATH_MSG_DEBUG(" Eta position option: " << m_posopt_eta); + ATH_MSG_DEBUG(" Phi position option: " << m_posopt_phi); + ATH_MSG_DEBUG(" Eta error option: " << m_erropt_eta); + ATH_MSG_DEBUG(" Phi error option: " << m_erropt_phi); + ATH_MSG_DEBUG(" Eta assigned error: " << m_error_eta); + ATH_MSG_DEBUG(" Phi assigned error: " << m_error_phi); + ATH_MSG_DEBUG(" Max strip pos diff: " << m_qrat_maxdiff); + ATH_MSG_DEBUG(" Max strip pos sig: " << m_qrat_maxsig); + ATH_MSG_DEBUG(" Non-normal error coeff: " << m_error_tantheta); + ATH_MSG_DEBUG(" CSS eta pos-slope offset: " << m_xtan_css_eta_offset); + ATH_MSG_DEBUG(" CSS eta pos-slope slope: " << m_xtan_css_eta_slope); + ATH_MSG_DEBUG(" CSL eta pos-slope offset: " << m_xtan_csl_eta_offset); + ATH_MSG_DEBUG(" CSL eta pos-slope slope: " << m_xtan_csl_eta_slope); + ATH_MSG_DEBUG(" CSS eta table offset: " << m_qratmin_css_eta); + ATH_MSG_DEBUG(" CSL eta table offset: " << m_qratmin_csl_eta); + ATH_MSG_DEBUG(" CSS eta table size: " << m_qratcor_css_eta.size()); + ATH_MSG_DEBUG(" CSL eta table size: " << m_qratcor_csl_eta.size()); + + ATH_MSG_DEBUG("atanh_a_css_eta: " << m_atanh_a_css_eta); + ATH_MSG_DEBUG("atanh_b_css_eta: " << m_atanh_b_css_eta); + ATH_MSG_DEBUG("atanh_c_css_eta: " << m_atanh_c_css_eta); + ATH_MSG_DEBUG("atanh_x0_css_eta: " << m_atanh_x0_css_eta); + ATH_MSG_DEBUG("atanh_a_csl_eta: " << m_atanh_a_csl_eta); + ATH_MSG_DEBUG("atanh_b_csl_eta: " << m_atanh_b_csl_eta); + ATH_MSG_DEBUG("atanh_c_csl_eta: " << m_atanh_c_csl_eta); + ATH_MSG_DEBUG("atanh_x0_csl_eta: " << m_atanh_x0_csl_eta); + + ATH_MSG_DEBUG("Minimum pos error: " << m_dposmin); + + return StatusCode::SUCCESS; } //********************************************************************** -const DataNames& QratCscClusterFitter::dataNames() const { - auto init = [&](){ - DataNames dnames; - bool dofixed = false; - bool docharge = false; - if ( m_posopt_phi == "POLYNOMIAL" || m_posopt_phi == "TABLE" || m_posopt_phi == "ATANH") { - if ( m_erropt_phi == "FIXED" ) dofixed = true; - if ( m_erropt_phi == "CHARGE" ) docharge = true; - } - if ( m_posopt_eta == "POLYNOMIAL" || m_posopt_eta == "TABLE" || m_posopt_eta == "ATANH" ) { - if ( m_erropt_eta == "FIXED" ) dofixed = true; - if ( m_erropt_eta == "CHARGE" ) docharge = true; - } - if ( dofixed || docharge ) { - dnames.push_back("scor1"); - dnames.push_back("scor2"); - dnames.push_back("scor"); - } - if ( docharge ) { - dnames.push_back("dscor1"); - dnames.push_back("dscor2"); - dnames.push_back("dscor"); - dnames.push_back("scordiff"); - dnames.push_back("dscordiff"); - } +const DataNames& +QratCscClusterFitter::dataNames() const +{ + auto init = [&]() { + DataNames dnames; + bool dofixed = false; + bool docharge = false; + if (m_posopt_phi == "POLYNOMIAL" || m_posopt_phi == "TABLE" || m_posopt_phi == "ATANH") { + if (m_erropt_phi == "FIXED") dofixed = true; + if (m_erropt_phi == "CHARGE") docharge = true; + } + if (m_posopt_eta == "POLYNOMIAL" || m_posopt_eta == "TABLE" || m_posopt_eta == "ATANH") { + if (m_erropt_eta == "FIXED") dofixed = true; + if (m_erropt_eta == "CHARGE") docharge = true; + } + if (dofixed || docharge) { + dnames.push_back("scor1"); + dnames.push_back("scor2"); + dnames.push_back("scor"); + } + if (docharge) { + dnames.push_back("dscor1"); + dnames.push_back("dscor2"); + dnames.push_back("dscor"); + dnames.push_back("scordiff"); + dnames.push_back("dscordiff"); + } + return dnames; + }; + static DataNames dnames ATLAS_THREAD_SAFE = init(); return dnames; - }; - static DataNames dnames ATLAS_THREAD_SAFE = init(); - return dnames; } - + //********************************************************************** -Results QratCscClusterFitter::fit(const StripFitList& sfits, double tantheta) const { - ATH_MSG_VERBOSE ( "QRAT fit with tool " << name() ); - - Results results; - - // Check input has at least three strips. - unsigned int nstrip = sfits.size(); - if ( nstrip < 3 ) { - ATH_MSG_VERBOSE ( " Input has fewer than three strips." ); - if (nstrip ==2) { - Muon::CscTimeStatus tstatus = (sfits[0].charge > sfits[1].charge) ? sfits[0].timeStatus : sfits[1].timeStatus; - results.push_back(Result(1, Muon::CscStatusNarrow, tstatus)); - } else if (nstrip==1) { - Muon::CscTimeStatus tstatus = sfits[0].timeStatus; - results.push_back(Result(1, Muon::CscStatusNarrow, tstatus)); - } - return results; - } +Results +QratCscClusterFitter::fit(const StripFitList& sfits, double tantheta) const +{ + ATH_MSG_VERBOSE("QRAT fit with tool " << name()); + + Results results; + + // Check input has at least three strips. + unsigned int nstrip = sfits.size(); + if (nstrip < 3) { + ATH_MSG_VERBOSE(" Input has fewer than three strips."); + if (nstrip == 2) { + Muon::CscTimeStatus tstatus = + (sfits[0].charge > sfits[1].charge) ? sfits[0].timeStatus : sfits[1].timeStatus; + results.push_back(Result(1, Muon::CscStatusNarrow, tstatus)); + } else if (nstrip == 1) { + Muon::CscTimeStatus tstatus = sfits[0].timeStatus; + results.push_back(Result(1, Muon::CscStatusNarrow, tstatus)); + } + return results; + } - // Fetch the number of strips and check the input arrays. - for ( unsigned int istrip=0; istrip<nstrip; ++istrip ) { - if ( sfits[istrip].strip == 0 ) { - ATH_MSG_WARNING ( "Strip pointer is null." ); - results.push_back(Result(2)); - return results; + // Fetch the number of strips and check the input arrays. + for (unsigned int istrip = 0; istrip < nstrip; ++istrip) { + if (sfits[istrip].strip == 0) { + ATH_MSG_WARNING("Strip pointer is null."); + results.push_back(Result(2)); + return results; + } } - } - - // Use the first strip to extract the layer parameters. - const CscStripPrepData* pstrip = sfits[0].strip; - Identifier idStrip0 = pstrip->identify(); - - // retrieve MuonDetectorManager from the conditions store - SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey}; - const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr(); - if(MuonDetMgr==nullptr){ - ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object"); - return results; - } - const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(idStrip0); - - bool measphi = m_idHelperSvc->cscIdHelper().CscIdHelper::measuresPhi(idStrip0); - double pitch = pro->cathodeReadoutPitch(0, measphi); - unsigned int maxstrip = pro->maxNumberOfStrips(measphi); - unsigned int strip0 = m_idHelperSvc->cscIdHelper().strip(idStrip0) - 1; - int station = m_idHelperSvc->cscIdHelper().stationName(idStrip0) - 49; // 1=CSS, 2=CSL - - CscPlane plane = findPlane(station, measphi); - if ( plane == UNKNOWN_PLANE ) { - ATH_MSG_WARNING ( "Invalid CSC plane: station=" << station << "; measphi=" << measphi ); - results.push_back(Result(3)); - return results; - } - - // Display input strips. - ATH_MSG_VERBOSE ( "QRAT fittter input has " << nstrip << " strips" ); - for ( unsigned int istrip=0; istrip<nstrip; ++istrip ) { - Identifier id = sfits[istrip].strip->identify(); - ATH_MSG_VERBOSE ( " " << station << " : " << measphi << " " << m_idHelperSvc->cscIdHelper().wireLayer(id) - << " " << istrip << " " << m_idHelperSvc->cscIdHelper().strip(id) - << " " << sfits[istrip].charge ); - } - - // Find the peak strip and check the shape. - unsigned int istrip_peak = 0; // strip number within cluster - // Loop over strips excluding the edges. - double charge_clu = sfits[0].charge + sfits[nstrip-1].charge; - for ( unsigned int istrip=1; istrip<nstrip-1; ++istrip ) { - StripFit sfit = sfits[istrip]; - float qthis = sfit.charge; - float qlast = sfits[istrip-1].charge; - float qnext = sfits[istrip+1].charge; - charge_clu += qthis; - // Peak if the adjacent strips have less charge. - bool ispeak = qthis > qlast && qthis > qnext; - // Special case: next strip has the same charge. - // Require the previous strip has less charge and the next following - // strip be absent or have less charge. - if ( ! ispeak ) { - if ( qthis == qnext ) { - ispeak = ( qthis > qlast ) && - ( istrip+2 == nstrip || sfits[istrip+2].charge < qthis ); - } + + // Use the first strip to extract the layer parameters. + const CscStripPrepData* pstrip = sfits[0].strip; + Identifier idStrip0 = pstrip->identify(); + + // retrieve MuonDetectorManager from the conditions store + SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey}; + const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr(); + if (MuonDetMgr == nullptr) { + ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object"); + return results; + } + const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(idStrip0); + + bool measphi = m_idHelperSvc->cscIdHelper().CscIdHelper::measuresPhi(idStrip0); + double pitch = pro->cathodeReadoutPitch(0, measphi); + unsigned int maxstrip = pro->maxNumberOfStrips(measphi); + unsigned int strip0 = m_idHelperSvc->cscIdHelper().strip(idStrip0) - 1; + int station = m_idHelperSvc->cscIdHelper().stationName(idStrip0) - 49; // 1=CSS, 2=CSL + + CscPlane plane = findPlane(station, measphi); + if (plane == UNKNOWN_PLANE) { + ATH_MSG_WARNING("Invalid CSC plane: station=" << station << "; measphi=" << measphi); + results.push_back(Result(3)); + return results; + } + + // Display input strips. + ATH_MSG_VERBOSE("QRAT fittter input has " << nstrip << " strips"); + for (unsigned int istrip = 0; istrip < nstrip; ++istrip) { + Identifier id = sfits[istrip].strip->identify(); + ATH_MSG_VERBOSE(" " << station << " : " << measphi << " " << m_idHelperSvc->cscIdHelper().wireLayer(id) + << " " << istrip << " " << m_idHelperSvc->cscIdHelper().strip(id) << " " + << sfits[istrip].charge); } - // Special case: first and second strips have the same charge. - // Require the third strip has less charge. - if ( ! ispeak ) { - if ( istrip == 1 ) { - if ( qthis == qlast ) { - ispeak = qthis > qnext; // bug found 10/13/07 + + // Find the peak strip and check the shape. + unsigned int istrip_peak = 0; // strip number within cluster + // Loop over strips excluding the edges. + double charge_clu = sfits[0].charge + sfits[nstrip - 1].charge; + for (unsigned int istrip = 1; istrip < nstrip - 1; ++istrip) { + StripFit sfit = sfits[istrip]; + float qthis = sfit.charge; + float qlast = sfits[istrip - 1].charge; + float qnext = sfits[istrip + 1].charge; + charge_clu += qthis; + // Peak if the adjacent strips have less charge. + bool ispeak = qthis > qlast && qthis > qnext; + // Special case: next strip has the same charge. + // Require the previous strip has less charge and the next following + // strip be absent or have less charge. + if (!ispeak) { + if (qthis == qnext) { + ispeak = (qthis > qlast) && (istrip + 2 == nstrip || sfits[istrip + 2].charge < qthis); + } + } + // Special case: first and second strips have the same charge. + // Require the third strip has less charge. + if (!ispeak) { + if (istrip == 1) { + if (qthis == qlast) { + ispeak = qthis > qnext; // bug found 10/13/07 + } + } + } + // Record if peak. + if (ispeak) { + if (istrip_peak) { // Error if multiple peaks are found. + results.push_back( + Result(6, Muon::CscStatusMultiPeak)); // Time status should be defined in SimpleClusterFit... + return results; + } + istrip_peak = istrip; } - } } - // Record if peak. - if ( ispeak ) { - if ( istrip_peak ) { // Error if multiple peaks are found. - results.push_back(Result(6, Muon::CscStatusMultiPeak)); // Time status should be defined in SimpleClusterFit... + ATH_MSG_VERBOSE(" Peak is at " << istrip_peak << "th strip in cluster"); + + // Check we are not on the edge. + if (strip0 <= 0 || strip0 + nstrip > maxstrip) { + results.push_back(Result(4, Muon::CscStatusEdge, sfits[istrip_peak].timeStatus)); return results; - } - istrip_peak = istrip; } - } - ATH_MSG_VERBOSE ( " Peak is at " << istrip_peak << "th strip in cluster"); - // Check we are not on the edge. - if ( strip0<=0 || strip0+nstrip>maxstrip ) { - results.push_back(Result(4, Muon::CscStatusEdge, sfits[istrip_peak].timeStatus)); - return results; - } - - // MS: remove this check since width is amplitude dependent. - // use saturation check instead - /************************************** - if ( nstrip > m_max_width[plane] ) { - // if ( nstrip_threshold > m_max_width[plane] ) { - results.push_back(Result(5, Muon::CscStatusWide, sfits[istrip_peak].timeStatus)); - return results; - } - ***************************************/ - - // Cluster is spoiled if peak is not at the center. - bool is_even = 2*(nstrip/2) == nstrip; - bool atcenter = istrip_peak == nstrip/2 || - (is_even && istrip_peak+1 == nstrip/2); - if ( ! atcenter ) { - results.push_back(Result(7, Muon::CscStatusSkewed, sfits[istrip_peak].timeStatus)); - return results; - } + // MS: remove this check since width is amplitude dependent. + // use saturation check instead + /************************************** + if ( nstrip > m_max_width[plane] ) { + // if ( nstrip_threshold > m_max_width[plane] ) { + results.push_back(Result(5, Muon::CscStatusWide, sfits[istrip_peak].timeStatus)); + return results; + } + ***************************************/ + // Cluster is spoiled if peak is not at the center. + bool is_even = 2 * (nstrip / 2) == nstrip; + bool atcenter = istrip_peak == nstrip / 2 || (is_even && istrip_peak + 1 == nstrip / 2); + if (!atcenter) { + results.push_back(Result(7, Muon::CscStatusSkewed, sfits[istrip_peak].timeStatus)); + return results; + } - if ( sfits[istrip_peak].stripStatus == Muon::CscStrStatSaturated - || sfits[istrip_peak-1].stripStatus == Muon::CscStrStatSaturated - || sfits[istrip_peak+1].stripStatus == Muon::CscStrStatSaturated ) { - results.push_back(Result(15, Muon::CscStatusSaturated, sfits[istrip_peak].timeStatus)); - return results; - } + if (sfits[istrip_peak].stripStatus == Muon::CscStrStatSaturated + || sfits[istrip_peak - 1].stripStatus == Muon::CscStrStatSaturated + || sfits[istrip_peak + 1].stripStatus == Muon::CscStrStatSaturated) + { + results.push_back(Result(15, Muon::CscStatusSaturated, sfits[istrip_peak].timeStatus)); + return results; + } - // left/peak/right strip should have good time information.... - if ( sfits[istrip_peak].stripStatus != Muon::CscStrStatSuccess - // || sfits[istrip_peak-1].stripStatus != Muon::CscStrStatSuccess - // || sfits[istrip_peak+1].stripStatus != Muon::CscStrStatSuccess ) { - ) { - results.push_back(Result(14, Muon::CscStatusStripFitFailed, sfits[istrip_peak].timeStatus)); - return results; - } else - if ( sfits[istrip_peak-1].stripStatus == Muon::CscStrStatHot - || sfits[istrip_peak-1].stripStatus == Muon::CscStrStatDead - || sfits[istrip_peak+1].stripStatus == Muon::CscStrStatHot - || sfits[istrip_peak+1].stripStatus == Muon::CscStrStatDead ) { - results.push_back(Result(14, Muon::CscStatusStripFitFailed, sfits[istrip_peak].timeStatus)); - return results; - } - - - /////////////////////////////////////////////////////////////// - // Set initial strip position. - double savg = istrip_peak; - - // Calculate QRAT correction to strip position. - std::string posopt = m_posopt_eta; - std::string erropt = m_erropt_eta; - double dpos = 0.0; - if ( measphi ) { - posopt = m_posopt_phi; - erropt = m_erropt_phi; - } - double q1 = sfits[istrip_peak-1].charge; - double q0 = sfits[istrip_peak].charge; - double q2 = sfits[istrip_peak+1].charge; - double qrat1 = q1/q0; - double qrat2 = q2/q0; - double dq1 = sfits[istrip_peak-1].dcharge; - double dq0 = sfits[istrip_peak].dcharge; - double dq2 = sfits[istrip_peak+1].dcharge; - - ATH_MSG_VERBOSE ( " QRAT charge ratios: " << qrat1 << " " << qrat2 ); - double scor1 = 0.; // left side correction. - double dscordqrat1 =0.; - double scor2 = 0; // right side correction. - double dscordqrat2 = 0.; - int stat1 = 0; - int stat2 = 0; - if ( posopt == "POLYNOMIAL" ) { - stat1 = qrat_correction(plane, qrat1, scor1, dscordqrat1); - stat2 = qrat_correction(plane, qrat2, scor2, dscordqrat2); - } else if ( posopt == "TABLE" ) { - double qrmin = 0.0; - const std::vector<double>* pcor = 0; - if ( plane == CSS_ETA ) { - qrmin = m_qratmin_css_eta; - pcor = &m_qratcor_css_eta; - } else if ( plane == CSL_ETA ) { - qrmin = m_qratmin_csl_eta; - pcor = &m_qratcor_csl_eta; - } else { - ATH_MSG_WARNING ( " Invalid QRAT plane: " << splane(plane) ); - results.push_back(Result(8)); - return results; + + // left/peak/right strip should have good time information.... + if (sfits[istrip_peak].stripStatus != Muon::CscStrStatSuccess + // || sfits[istrip_peak-1].stripStatus != Muon::CscStrStatSuccess + // || sfits[istrip_peak+1].stripStatus != Muon::CscStrStatSuccess ) { + ) + { + results.push_back(Result(14, Muon::CscStatusStripFitFailed, sfits[istrip_peak].timeStatus)); + return results; + } else if (sfits[istrip_peak - 1].stripStatus == Muon::CscStrStatHot + || sfits[istrip_peak - 1].stripStatus == Muon::CscStrStatDead + || sfits[istrip_peak + 1].stripStatus == Muon::CscStrStatHot + || sfits[istrip_peak + 1].stripStatus == Muon::CscStrStatDead) + { + results.push_back(Result(14, Muon::CscStatusStripFitFailed, sfits[istrip_peak].timeStatus)); + return results; } - if ( pcor ) { - stat1 = qrat_interpolation(qrmin, *pcor, qrat1, scor1, dscordqrat1); - stat2 = qrat_interpolation(qrmin, *pcor, qrat2, scor2, dscordqrat2); - } else { - stat1 = 99; + + + /////////////////////////////////////////////////////////////// + // Set initial strip position. + double savg = istrip_peak; + + // Calculate QRAT correction to strip position. + std::string posopt = m_posopt_eta; + std::string erropt = m_erropt_eta; + double dpos = 0.0; + if (measphi) { + posopt = m_posopt_phi; + erropt = m_erropt_phi; } - } else if ( posopt == "ATANH" ) { // MS: atanh parametrization - double a, b, c, x0; // parameters - if ( plane == CSS_ETA ) { - a = m_atanh_a_css_eta; - b = m_atanh_b_css_eta; - c = m_atanh_c_css_eta; - x0 = m_atanh_x0_css_eta; - } else if ( plane == CSL_ETA ) { - a = m_atanh_a_csl_eta; - b = m_atanh_b_csl_eta; - c = m_atanh_c_csl_eta; - x0 = m_atanh_x0_csl_eta; + double q1 = sfits[istrip_peak - 1].charge; + double q0 = sfits[istrip_peak].charge; + double q2 = sfits[istrip_peak + 1].charge; + double qrat1 = q1 / q0; + double qrat2 = q2 / q0; + double dq1 = sfits[istrip_peak - 1].dcharge; + double dq0 = sfits[istrip_peak].dcharge; + double dq2 = sfits[istrip_peak + 1].dcharge; + + ATH_MSG_VERBOSE(" QRAT charge ratios: " << qrat1 << " " << qrat2); + double scor1 = 0.; // left side correction. + double dscordqrat1 = 0.; + double scor2 = 0; // right side correction. + double dscordqrat2 = 0.; + int stat1 = 0; + int stat2 = 0; + if (posopt == "POLYNOMIAL") { + stat1 = qrat_correction(plane, qrat1, scor1, dscordqrat1); + stat2 = qrat_correction(plane, qrat2, scor2, dscordqrat2); + } else if (posopt == "TABLE") { + double qrmin = 0.0; + const std::vector<double>* pcor = 0; + if (plane == CSS_ETA) { + qrmin = m_qratmin_css_eta; + pcor = &m_qratcor_css_eta; + } else if (plane == CSL_ETA) { + qrmin = m_qratmin_csl_eta; + pcor = &m_qratcor_csl_eta; + } else { + ATH_MSG_WARNING(" Invalid QRAT plane: " << splane(plane)); + results.push_back(Result(8)); + return results; + } + if (pcor) { + stat1 = qrat_interpolation(qrmin, *pcor, qrat1, scor1, dscordqrat1); + stat2 = qrat_interpolation(qrmin, *pcor, qrat2, scor2, dscordqrat2); + } else { + stat1 = 99; + } + } else if (posopt == "ATANH") { // MS: atanh parametrization + double a, b, c, x0; // parameters + if (plane == CSS_ETA) { + a = m_atanh_a_css_eta; + b = m_atanh_b_css_eta; + c = m_atanh_c_css_eta; + x0 = m_atanh_x0_css_eta; + } else if (plane == CSL_ETA) { + a = m_atanh_a_csl_eta; + b = m_atanh_b_csl_eta; + c = m_atanh_c_csl_eta; + x0 = m_atanh_x0_csl_eta; + } else { + ATH_MSG_WARNING(" Invalid QRAT plane: " << splane(plane)); + results.push_back(Result(8)); + return results; + } + stat1 = qrat_atanh(a, b, c, x0, qrat1, scor1, dscordqrat1); + stat2 = qrat_atanh(a, b, c, x0, qrat2, scor2, dscordqrat2); + } else { - ATH_MSG_WARNING ( " Invalid QRAT plane: " << splane(plane) ); - results.push_back(Result(8)); - return results; + ATH_MSG_WARNING(" Invalid position option: " << posopt); + results.push_back(Result(9)); + return results; } - stat1 = qrat_atanh (a, b, c, x0, qrat1, scor1, dscordqrat1); - stat2 = qrat_atanh (a, b, c, x0, qrat2, scor2, dscordqrat2); - - } else { - ATH_MSG_WARNING ( " Invalid position option: " << posopt ); - results.push_back(Result(9)); - return results; - } - if ( stat1 || stat2 ) { - ATH_MSG_VERBOSE ( " QRAT correction failed: SPOILED" ); - results.push_back(Result(10)); - return results; - } - ATH_MSG_VERBOSE ( " QRAT strip corrs: " << scor1 << " " << scor2 ); - ATH_MSG_VERBOSE ( " QRAT derivatives: " << dscordqrat1 << " " << dscordqrat2 ); - - // Compare left and right. - // Flip sign of the left side correction. - scor1 = -scor1; - dscordqrat1 = -dscordqrat1; - double scor = 0.0; - DataMap dmap; - // Calculation weighting corrections by their derivatives, i.e. assuming the - // two charge ratios have the same error. - if ( erropt == "FIXED" ) { - double w1 = 1/(dscordqrat1*dscordqrat1); - double w2 = 1/(dscordqrat2*dscordqrat2); - scor = (w1*scor1 + w2*scor2)/(w1+w2); - double scor_diff = std::abs(scor2 - scor1); - ATH_MSG_VERBOSE ( " Combined corr: " << scor ); - dpos = measphi ? m_error_phi : m_error_eta; - // Fill data map. - dmap["scor1"] = scor1; - dmap["scor2"] = scor2; - dmap["scor"] = scor; - // Exit if measurements are inconsistent. - if ( scor_diff > m_qrat_maxdiff ) { - ATH_MSG_VERBOSE ( " SPOILED (scor_diff=" << scor_diff << ")" ); - results.push_back(Result(11, Muon::CscStatusQratInconsistent)); - return results; + if (stat1 || stat2) { + ATH_MSG_VERBOSE(" QRAT correction failed: SPOILED"); + results.push_back(Result(10)); + return results; } - // Calculation using the (independent) errors in the three charges. - } else if ( erropt == "CHARGE" ) { - // Calculate intermediate variables. - double x1 = dscordqrat1*qrat1; - double x2 = dscordqrat2*qrat2; - double dqq0 = dq0/q0; - double dqq1 = dq1/q1; - double dqq2 = dq2/q2; - double rnum = (-x1*x1*dqq1*dqq1 + x2*x2*dqq2*dqq2 + (x2*x2-x1*x1)*dqq0*dqq0); - double rden = (x1*x1*dqq1*dqq1 + x2*x2*dqq2*dqq2 + (x2-x1)*(x2-x1)*dqq0*dqq0); - double rfac = rnum/rden; - // Calculate the significance of the difference between the measurements. - double dscor_diff = sqrt(rden); - double scor_diff = scor2 - scor1; - double scor_sig = std::abs(scor_diff)/dscor_diff; - // Calculate the weighted average of the corrections. - double w1 = 0.5*(1.0+rfac); - double w2 = 0.5*(1.0-rfac); - scor = w1*scor1 + w2*scor2; - // Calculate the error in this average. - double ddscor1 = w1*x1*dqq1; - double ddscor2 = w2*x2*dqq2; - double ddscor0 = (w1*x1 + w2*x2)*dqq0; - double dscor = sqrt(ddscor1*ddscor1 + ddscor2*ddscor2 + ddscor0*ddscor0); - dpos = pitch*dscor; - // add minimum error (in mm) in quadrature: - dpos = sqrt(dpos*dpos + m_dposmin*m_dposmin); - // Fill data map. - double dscor1 = std::abs(x1)*sqrt(dqq1*dqq1+dqq0*dqq0); - double dscor2 = std::abs(x2)*sqrt(dqq2*dqq2+dqq0*dqq0); - dmap["scor1"] = scor1; - dmap["dscor1"] = dscor1; - dmap["scor2"] = scor2; - dmap["dscor2"] = dscor2; - dmap["scordiff"] = scor_diff; - dmap["dscordiff"] = dscor_diff; - dmap["scor"] = scor; - dmap["dscor"] = dscor; - // Debugging. - ATH_MSG_VERBOSE ( "QRAT CHARGE calculation" ); - ATH_MSG_VERBOSE ( " q1, q0, q2: " << q1 << " " << q0 << " " << q2 ); - ATH_MSG_VERBOSE ( " dq1, dq0, dq2: " << dq1 << " " << dq0 << " " << dq2 ); - ATH_MSG_VERBOSE ( " dscordqrat1, x1: " << dscordqrat1 << " " << x1 ); - ATH_MSG_VERBOSE ( " dscordqrat2, x2: " << dscordqrat2 << " " << x2 ); - ATH_MSG_VERBOSE ( " scor1 = " << scor1 << " +/- " << dscor1 ); - ATH_MSG_VERBOSE ( " scor2 = " << scor2 << " +/- " << dscor2 ); - ATH_MSG_VERBOSE ( " scor = " << scor << " +/- " << dscor ); - ATH_MSG_VERBOSE ( " scordiff = " << scor_diff << " +/- " << dscor_diff ); - ATH_MSG_VERBOSE ( " scor_sig = " << scor_sig); - - // Exit if measurements are inconsistent. - if ( scor_sig > m_qrat_maxsig ) { - ATH_MSG_VERBOSE ( " SPOILED (scor_sig=" << scor_sig << ")" ); - results.push_back(Result(12, Muon::CscStatusQratInconsistent, sfits[istrip_peak].timeStatus)); - return results; + ATH_MSG_VERBOSE(" QRAT strip corrs: " << scor1 << " " << scor2); + ATH_MSG_VERBOSE(" QRAT derivatives: " << dscordqrat1 << " " << dscordqrat2); + + // Compare left and right. + // Flip sign of the left side correction. + scor1 = -scor1; + dscordqrat1 = -dscordqrat1; + double scor = 0.0; + DataMap dmap; + // Calculation weighting corrections by their derivatives, i.e. assuming the + // two charge ratios have the same error. + if (erropt == "FIXED") { + double w1 = 1 / (dscordqrat1 * dscordqrat1); + double w2 = 1 / (dscordqrat2 * dscordqrat2); + scor = (w1 * scor1 + w2 * scor2) / (w1 + w2); + double scor_diff = std::abs(scor2 - scor1); + ATH_MSG_VERBOSE(" Combined corr: " << scor); + dpos = measphi ? m_error_phi : m_error_eta; + // Fill data map. + dmap["scor1"] = scor1; + dmap["scor2"] = scor2; + dmap["scor"] = scor; + // Exit if measurements are inconsistent. + if (scor_diff > m_qrat_maxdiff) { + ATH_MSG_VERBOSE(" SPOILED (scor_diff=" << scor_diff << ")"); + results.push_back(Result(11, Muon::CscStatusQratInconsistent)); + return results; + } + // Calculation using the (independent) errors in the three charges. + } else if (erropt == "CHARGE") { + // Calculate intermediate variables. + double x1 = dscordqrat1 * qrat1; + double x2 = dscordqrat2 * qrat2; + double dqq0 = dq0 / q0; + double dqq1 = dq1 / q1; + double dqq2 = dq2 / q2; + double rnum = (-x1 * x1 * dqq1 * dqq1 + x2 * x2 * dqq2 * dqq2 + (x2 * x2 - x1 * x1) * dqq0 * dqq0); + double rden = (x1 * x1 * dqq1 * dqq1 + x2 * x2 * dqq2 * dqq2 + (x2 - x1) * (x2 - x1) * dqq0 * dqq0); + double rfac = rnum / rden; + // Calculate the significance of the difference between the measurements. + double dscor_diff = sqrt(rden); + double scor_diff = scor2 - scor1; + double scor_sig = std::abs(scor_diff) / dscor_diff; + // Calculate the weighted average of the corrections. + double w1 = 0.5 * (1.0 + rfac); + double w2 = 0.5 * (1.0 - rfac); + scor = w1 * scor1 + w2 * scor2; + // Calculate the error in this average. + double ddscor1 = w1 * x1 * dqq1; + double ddscor2 = w2 * x2 * dqq2; + double ddscor0 = (w1 * x1 + w2 * x2) * dqq0; + double dscor = sqrt(ddscor1 * ddscor1 + ddscor2 * ddscor2 + ddscor0 * ddscor0); + dpos = pitch * dscor; + // add minimum error (in mm) in quadrature: + dpos = sqrt(dpos * dpos + m_dposmin * m_dposmin); + // Fill data map. + double dscor1 = std::abs(x1) * sqrt(dqq1 * dqq1 + dqq0 * dqq0); + double dscor2 = std::abs(x2) * sqrt(dqq2 * dqq2 + dqq0 * dqq0); + dmap["scor1"] = scor1; + dmap["dscor1"] = dscor1; + dmap["scor2"] = scor2; + dmap["dscor2"] = dscor2; + dmap["scordiff"] = scor_diff; + dmap["dscordiff"] = dscor_diff; + dmap["scor"] = scor; + dmap["dscor"] = dscor; + // Debugging. + ATH_MSG_VERBOSE("QRAT CHARGE calculation"); + ATH_MSG_VERBOSE(" q1, q0, q2: " << q1 << " " << q0 << " " << q2); + ATH_MSG_VERBOSE(" dq1, dq0, dq2: " << dq1 << " " << dq0 << " " << dq2); + ATH_MSG_VERBOSE(" dscordqrat1, x1: " << dscordqrat1 << " " << x1); + ATH_MSG_VERBOSE(" dscordqrat2, x2: " << dscordqrat2 << " " << x2); + ATH_MSG_VERBOSE(" scor1 = " << scor1 << " +/- " << dscor1); + ATH_MSG_VERBOSE(" scor2 = " << scor2 << " +/- " << dscor2); + ATH_MSG_VERBOSE(" scor = " << scor << " +/- " << dscor); + ATH_MSG_VERBOSE(" scordiff = " << scor_diff << " +/- " << dscor_diff); + ATH_MSG_VERBOSE(" scor_sig = " << scor_sig); + + // Exit if measurements are inconsistent. + if (scor_sig > m_qrat_maxsig) { + ATH_MSG_VERBOSE(" SPOILED (scor_sig=" << scor_sig << ")"); + results.push_back(Result(12, Muon::CscStatusQratInconsistent, sfits[istrip_peak].timeStatus)); + return results; + } + } else { + ATH_MSG_WARNING(" Invalid error option: " << erropt); + results.push_back(Result(13, Muon::CscStatusUndefined, sfits[istrip_peak].timeStatus)); + return results; } - } else { - ATH_MSG_WARNING ( " Invalid error option: " << erropt ); - results.push_back(Result(13, Muon::CscStatusUndefined, sfits[istrip_peak].timeStatus)); + + // Correct strip position. + savg += scor + strip0; + ATH_MSG_VERBOSE(" QRAT corr " << splane(plane) << " nstrip=" << nstrip << " savg=" << savg << " qrat1=" << qrat1 + << " qrat2=" << qrat2 << " scor1=" << scor1 << " scor2=" << scor2); + + // Error due to incident angle. + double dpostht = m_error_tantheta * std::abs(tantheta); + + // Scale error on dpos + dpos = dpos * m_precisionErrorScaler; + + // Set return values. + Result res(0, Muon::CscStatusUnspoiled); + res.strip = istrip_peak; + res.position = pitch * (savg + 0.5 - 0.5 * maxstrip); + + // internal alignment ... + Identifier id = sfits[res.strip].strip->identify(); + double offset = m_alignmentTool->getAlignmentOffset(id); + res.position -= offset; + + + res.dposition = sqrt(dpos * dpos + dpostht * dpostht); + + res.fstrip = 0; + res.lstrip = nstrip - 1; + res.time = sfits[istrip_peak].time; + res.time_beforeT0Corr = sfits[istrip_peak].time_beforeT0Corr; + res.time_beforeBPCorr = sfits[istrip_peak].time_beforeBPCorr; + res.timeStatus = sfits[istrip_peak].timeStatus; + + + res.qleft = q1; + res.qpeak = q0; + res.qright = q2; + + // res.diff = dmap["scordiff"]; + // res.sig = dmap["scordiff"]/dmap["dscordiff"]; + + // cluster charge should be qsum over three strip... 3/21/2011 + res.charge = res.qleft + res.qpeak + res.qright; + res.charge_beforeBPCorr = sfits[istrip_peak].charge_beforeBPCorr + sfits[istrip_peak - 1].charge_beforeBPCorr + + sfits[istrip_peak + 1].charge_beforeBPCorr; + + res.dataMap = dmap; + + ATH_MSG_VERBOSE(" Position :: pos=" << res.position << " dpos:dtht=" << dpos << ":" << dpostht << " ==>" + << res.dposition << " at tanth=" << tantheta); + + results.push_back(res); return results; - } - - // Correct strip position. - savg += scor+strip0; - ATH_MSG_VERBOSE ( " QRAT corr " << splane(plane) << " nstrip=" << nstrip - << " savg=" << savg << " qrat1=" << qrat1 << " qrat2=" << qrat2 - << " scor1=" << scor1 << " scor2=" << scor2 ); - - // Error due to incident angle. - double dpostht = m_error_tantheta*std::abs(tantheta); - - // Scale error on dpos - dpos = dpos*m_precisionErrorScaler; - - // Set return values. - Result res(0, Muon::CscStatusUnspoiled); - res.strip = istrip_peak; - res.position = pitch*(savg + 0.5 - 0.5*maxstrip); - - // internal alignment ... - Identifier id = sfits[res.strip].strip->identify(); - double offset = m_alignmentTool->getAlignmentOffset(id); - res.position -= offset; - - - res.dposition = sqrt(dpos*dpos + dpostht*dpostht); - - res.fstrip = 0; - res.lstrip = nstrip-1; - res.time = sfits[istrip_peak].time; - res.time_beforeT0Corr = sfits[istrip_peak].time_beforeT0Corr; - res.time_beforeBPCorr = sfits[istrip_peak].time_beforeBPCorr; - res.timeStatus = sfits[istrip_peak].timeStatus; - - - res.qleft = q1; - res.qpeak = q0; - res.qright = q2; - - // res.diff = dmap["scordiff"]; - // res.sig = dmap["scordiff"]/dmap["dscordiff"]; - - // cluster charge should be qsum over three strip... 3/21/2011 - res.charge = res.qleft+res.qpeak+res.qright; - res.charge_beforeBPCorr = sfits[istrip_peak].charge_beforeBPCorr - +sfits[istrip_peak-1].charge_beforeBPCorr - +sfits[istrip_peak+1].charge_beforeBPCorr; - - res.dataMap = dmap; - - ATH_MSG_VERBOSE ( " Position :: pos=" << res.position << " dpos:dtht=" << dpos << ":" << dpostht - << " ==>" << res.dposition << " at tanth=" << tantheta ); - - results.push_back(res); - return results; } -//int QratCscClusterFitter:: -//fit(const StripList&, const StripFitList& sfits, +// int QratCscClusterFitter:: +// fit(const StripList&, const StripFitList& sfits, // double& pos, double& dpos, Muon::CscClusterStatus& clustatus, // unsigned int& /*istrip*/, double& /*charge*/, double& /*time*/, DataMap* /*pdmap*/) const { return 0;} //********************************************************************** -double QratCscClusterFitter::getCorrectedError(const CscPrepData* pclu, double slope) const { - - // Cluster position. - Trk::ParamDefs icor = Trk::loc1; - Trk::ParamDefs ierr = Trk::loc1; - double pos = pclu->localPosition()[icor]; - double dpos = Amg::error(pclu->localCovariance(),ierr); - - Identifier idStrip0 = pclu->identify(); - int station = m_idHelperSvc->cscIdHelper().stationName(idStrip0) - 49; // 1=CSS, 2=CSL - // Calculate the angle of incidence. - double tantht = 0.0; - if ( station == 1 ) { - tantht = m_xtan_css_eta_offset + m_xtan_css_eta_slope*pos; - } else { - tantht = m_xtan_csl_eta_offset + m_xtan_csl_eta_slope*pos; - } - // Correct the error using this angle. - double old_dpostht = m_error_tantheta*std::abs(tantht); - - double new_dpostht = m_error_tantheta*std::abs(slope); - - double newError = sqrt(dpos*dpos - - old_dpostht*old_dpostht - + new_dpostht*new_dpostht); - - - ATH_MSG_VERBOSE ( " Position :: pos=" << pos - << " dpos:newdpos=" << dpos << " : " << newError - << " " << old_dpostht << " " << new_dpostht ); - - if (slope<-990) { - newError = sqrt(dpos*dpos - + old_dpostht*old_dpostht); - } - - return newError; -} - +double +QratCscClusterFitter::getCorrectedError(const CscPrepData* pclu, double slope) const +{ -//********************************************************************** + // Cluster position. + Trk::ParamDefs icor = Trk::loc1; + Trk::ParamDefs ierr = Trk::loc1; + double pos = pclu->localPosition()[icor]; + double dpos = Amg::error(pclu->localCovariance(), ierr); -Results QratCscClusterFitter::fit(const StripFitList& sfits) const { - Results results = fit(sfits, 0.0); - Results new_results; - for ( unsigned int iresult=0; iresult<results.size(); ++iresult ) { - Result res = results[iresult]; - if ( res.fitStatus ) { - new_results.push_back(res); - continue; - } - // Fetch the chamber type. - const CscStripPrepData* pstrip = sfits[0].strip; - Identifier idStrip0 = pstrip->identify(); - int station = m_idHelperSvc->cscIdHelper().stationName(idStrip0) - 49; // 1=CSS, 2=CSL + Identifier idStrip0 = pclu->identify(); + int station = m_idHelperSvc->cscIdHelper().stationName(idStrip0) - 49; // 1=CSS, 2=CSL // Calculate the angle of incidence. double tantht = 0.0; - double pos = res.position; - if ( station == 1 ) { - tantht = m_xtan_css_eta_offset + m_xtan_css_eta_slope*pos; + if (station == 1) { + tantht = m_xtan_css_eta_offset + m_xtan_css_eta_slope * pos; } else { - tantht = m_xtan_csl_eta_offset + m_xtan_csl_eta_slope*pos; + tantht = m_xtan_csl_eta_offset + m_xtan_csl_eta_slope * pos; } // Correct the error using this angle. - double dpostht = m_error_tantheta*std::abs(tantht); - double dpos = res.dposition; - - res.dposition = sqrt(dpos*dpos + dpostht*dpostht); - - // Return the updated result. - new_results.push_back(res); - } - - return new_results; + double old_dpostht = m_error_tantheta * std::abs(tantht); + + double new_dpostht = m_error_tantheta * std::abs(slope); + + double newError = sqrt(dpos * dpos - old_dpostht * old_dpostht + new_dpostht * new_dpostht); + + + ATH_MSG_VERBOSE(" Position :: pos=" << pos << " dpos:newdpos=" << dpos << " : " << newError << " " << old_dpostht + << " " << new_dpostht); + + if (slope < -990) { + newError = sqrt(dpos * dpos + old_dpostht * old_dpostht); + } + + return newError; +} + + +//********************************************************************** + +Results +QratCscClusterFitter::fit(const StripFitList& sfits) const +{ + Results results = fit(sfits, 0.0); + Results new_results; + for (unsigned int iresult = 0; iresult < results.size(); ++iresult) { + Result res = results[iresult]; + if (res.fitStatus) { + new_results.push_back(res); + continue; + } + // Fetch the chamber type. + const CscStripPrepData* pstrip = sfits[0].strip; + Identifier idStrip0 = pstrip->identify(); + int station = m_idHelperSvc->cscIdHelper().stationName(idStrip0) - 49; // 1=CSS, 2=CSL + // Calculate the angle of incidence. + double tantht = 0.0; + double pos = res.position; + if (station == 1) { + tantht = m_xtan_css_eta_offset + m_xtan_css_eta_slope * pos; + } else { + tantht = m_xtan_csl_eta_offset + m_xtan_csl_eta_slope * pos; + } + // Correct the error using this angle. + double dpostht = m_error_tantheta * std::abs(tantht); + double dpos = res.dposition; + + res.dposition = sqrt(dpos * dpos + dpostht * dpostht); + + // Return the updated result. + new_results.push_back(res); + } + + return new_results; } diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/QratCscClusterFitter.h b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/QratCscClusterFitter.h index ff962f4c1b07..14aaca0a6d18 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/QratCscClusterFitter.h +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/QratCscClusterFitter.h @@ -10,77 +10,82 @@ // // Tool to fit a CSC cluster using adjacent charge ratios. -#include "CscClusterization/ICscClusterFitter.h" #include "AthenaBaseComps/AthAlgTool.h" +#include "CscClusterization/ICscAlignmentTool.h" +#include "CscClusterization/ICscClusterFitter.h" #include "GaudiKernel/ServiceHandle.h" #include "GaudiKernel/ToolHandle.h" - -#include "MuonReadoutGeometry/MuonDetectorManager.h" #include "MuonIdHelpers/IMuonIdHelperSvc.h" #include "MuonPrepRawData/CscClusterStatus.h" -#include "CscClusterization/ICscAlignmentTool.h" +#include "MuonReadoutGeometry/MuonDetectorManager.h" namespace Muon { - class CscPrepData; +class CscPrepData; } class QratCscClusterFitter : virtual public ICscClusterFitter, public AthAlgTool { - -public: - QratCscClusterFitter(std::string, std::string, const IInterface*); - - ~QratCscClusterFitter()=default; - - StatusCode initialize(); + public: + QratCscClusterFitter(std::string, std::string, const IInterface*); + + ~QratCscClusterFitter() = default; + + StatusCode initialize(); + + // Inherited methods. + const DataNames& dataNames() const; + using ICscClusterFitter::fit; + Results fit(const StripFitList& sfits) const; + Results fit(const StripFitList& sfits, double dposdz) const; + double getCorrectedError(const Muon::CscPrepData* pclu, double slope) const; - // Inherited methods. - const DataNames& dataNames() const; - using ICscClusterFitter::fit; - Results fit(const StripFitList& sfits) const; - Results fit(const StripFitList& sfits, double dposdz) const; - double getCorrectedError(const Muon::CscPrepData* pclu, double slope) const; - -private: + private: + // Properties + std::vector<unsigned int> m_max_width; + std::string m_posopt_eta; + std::string m_posopt_phi; + std::string m_erropt_eta; + std::string m_erropt_phi; + double m_error_eta; + double m_error_phi; + double m_precisionErrorScaler; + double m_qrat_maxdiff; + double m_qrat_maxsig; + double m_error_tantheta; + double m_xtan_css_eta_offset; + double m_xtan_css_eta_slope; + double m_xtan_csl_eta_offset; + double m_xtan_csl_eta_slope; + double m_qratmin_css_eta; + double m_qratmin_csl_eta; + std::vector<double> m_qratcor_css_eta; + std::vector<double> m_qratcor_csl_eta; - // Properties - std::vector<unsigned int> m_max_width; - std::string m_posopt_eta; - std::string m_posopt_phi; - std::string m_erropt_eta; - std::string m_erropt_phi; - double m_error_eta; - double m_error_phi; - double m_precisionErrorScaler; - double m_qrat_maxdiff; - double m_qrat_maxsig; - double m_error_tantheta; - double m_xtan_css_eta_offset; - double m_xtan_css_eta_slope; - double m_xtan_csl_eta_offset; - double m_xtan_csl_eta_slope; - double m_qratmin_css_eta; - double m_qratmin_csl_eta; - std::vector<double> m_qratcor_css_eta; - std::vector<double> m_qratcor_csl_eta; - - double m_atanh_a_css_eta; // MS: atanh qrat parametrization - double m_atanh_b_css_eta; - double m_atanh_c_css_eta; - double m_atanh_x0_css_eta; - double m_atanh_a_csl_eta; - double m_atanh_b_csl_eta; - double m_atanh_c_csl_eta; - double m_atanh_x0_csl_eta; + double m_atanh_a_css_eta; // MS: atanh qrat parametrization + double m_atanh_b_css_eta; + double m_atanh_c_css_eta; + double m_atanh_x0_css_eta; + double m_atanh_a_csl_eta; + double m_atanh_b_csl_eta; + double m_atanh_c_csl_eta; + double m_atanh_x0_csl_eta; - double m_dposmin; // MS: minimum position error in mm + double m_dposmin; // MS: minimum position error in mm - /** retrieve MuonDetectorManager from the conditions store */ - SG::ReadCondHandleKey<MuonGM::MuonDetectorManager> m_DetectorManagerKey {this, "DetectorManagerKey", - "MuonDetectorManager", "Key of input MuonDetectorManager condition data"}; + /** retrieve MuonDetectorManager from the conditions store */ + SG::ReadCondHandleKey<MuonGM::MuonDetectorManager> m_DetectorManagerKey{ + this, + "DetectorManagerKey", + "MuonDetectorManager", + "Key of input MuonDetectorManager condition data", + }; - ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}; + ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc{ + this, + "MuonIdHelperSvc", + "Muon::MuonIdHelperSvc/MuonIdHelperSvc", + }; - ToolHandle<ICscAlignmentTool> m_alignmentTool; + ToolHandle<ICscAlignmentTool> m_alignmentTool; }; #endif diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/SimpleCscClusterFitter.cxx b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/SimpleCscClusterFitter.cxx index 65eec9561b4a..f07311045537 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/SimpleCscClusterFitter.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/SimpleCscClusterFitter.cxx @@ -4,335 +4,337 @@ #include "SimpleCscClusterFitter.h" +#include <iomanip> +#include <sstream> + #include "MuonPrepRawData/CscClusterStatus.h" #include "MuonPrepRawData/CscPrepData.h" #include "MuonPrepRawData/CscStripPrepData.h" #include "MuonReadoutGeometry/CscReadoutElement.h" -#include <sstream> -#include <iomanip> - using Muon::CscClusterStatus; using Muon::CscPrepData; using Muon::CscStripPrepData; using MuonGM::CscReadoutElement; typedef ICscClusterFitter::Result Result; -typedef std::vector<Result> Results; +typedef std::vector<Result> Results; enum CscStation { UNKNOWN_STATION, CSS, CSL }; enum CscPlane { CSS_R, CSL_R, CSS_PHI, CSL_PHI, UNKNOWN_PLANE }; -SimpleCscClusterFitter::SimpleCscClusterFitter(std::string type, std::string aname, const IInterface* parent) : - AthAlgTool(type, aname, parent), - m_alignmentTool("CscAlignmentTool/CscAlignmentTool", this) +SimpleCscClusterFitter::SimpleCscClusterFitter(std::string type, std::string aname, const IInterface* parent) + : AthAlgTool(type, aname, parent), m_alignmentTool("CscAlignmentTool/CscAlignmentTool", this) { - declareInterface<ICscClusterFitter>(this); - declareProperty("position_option", m_option = "MEAN", - "Cluster fitting option: MEAN, PEAK, CENTROID"); - declareProperty("intrinsic_cluster_width", m_intrinsic_cluster_width = 20.0, - "Intrinsic cluster width (mm)"); - declareProperty("use_peakthreshold", m_use_peakthreshold = false); - declareProperty("defaultErrorScaler_eta", m_defaultErrorScaler_eta = 1.0); - declareProperty("defaultErrorScaler_phi", m_defaultErrorScaler_phi = 1.0); - - declareProperty("CscAlignmentTool", m_alignmentTool ); + declareInterface<ICscClusterFitter>(this); + declareProperty("position_option", m_option = "MEAN", "Cluster fitting option: MEAN, PEAK, CENTROID"); + declareProperty("intrinsic_cluster_width", m_intrinsic_cluster_width = 20.0, "Intrinsic cluster width (mm)"); + declareProperty("use_peakthreshold", m_use_peakthreshold = false); + declareProperty("defaultErrorScaler_eta", m_defaultErrorScaler_eta = 1.0); + declareProperty("defaultErrorScaler_phi", m_defaultErrorScaler_phi = 1.0); + + declareProperty("CscAlignmentTool", m_alignmentTool); } //********************************************************************** -StatusCode SimpleCscClusterFitter::initialize() { - - ATH_MSG_VERBOSE ( "Initializing " << name() ); - - ATH_MSG_DEBUG ( "Properties for " << name() << ":" ); - ATH_MSG_DEBUG ( " Position option: " << m_option ); - ATH_MSG_DEBUG ( " Intrinsic width: " << m_intrinsic_cluster_width << " mm" ); - - ATH_CHECK(detStore()->retrieve(m_detMgr,"Muon")); - ATH_CHECK(m_idHelperSvc.retrieve()); - - if ( m_alignmentTool.retrieve().isFailure() ) { - ATH_MSG_WARNING ( name() << ": unable to retrieve cluster fitter " << m_alignmentTool ); - } else { - ATH_MSG_DEBUG ( name() << ": retrieved " << m_alignmentTool ); - } - // retrieve MuonDetectorManager from the conditions store - ATH_CHECK(m_DetectorManagerKey.initialize()); - return StatusCode::SUCCESS; +StatusCode +SimpleCscClusterFitter::initialize() +{ + + ATH_MSG_VERBOSE("Initializing " << name()); + + ATH_MSG_DEBUG("Properties for " << name() << ":"); + ATH_MSG_DEBUG(" Position option: " << m_option); + ATH_MSG_DEBUG(" Intrinsic width: " << m_intrinsic_cluster_width << " mm"); + + ATH_CHECK(detStore()->retrieve(m_detMgr, "Muon")); + ATH_CHECK(m_idHelperSvc.retrieve()); + + if (m_alignmentTool.retrieve().isFailure()) { + ATH_MSG_WARNING(name() << ": unable to retrieve cluster fitter " << m_alignmentTool); + } else { + ATH_MSG_DEBUG(name() << ": retrieved " << m_alignmentTool); + } + // retrieve MuonDetectorManager from the conditions store + ATH_CHECK(m_DetectorManagerKey.initialize()); + return StatusCode::SUCCESS; } //********************************************************************** -Results SimpleCscClusterFitter::fit(const StripFitList& sfits) const { +Results +SimpleCscClusterFitter::fit(const StripFitList& sfits) const +{ + + Results results; + Result res; - Results results; - Result res; - - // Check the input lists. - unsigned int nstrip = sfits.size(); - if ( nstrip == 0 ) { - ATH_MSG_WARNING ( "Strip list is empty." ); - res.fitStatus = 1; - results.push_back(res); - return results; - } - if ( sfits.size() != nstrip ) { - ATH_MSG_WARNING ( "Fit and strip lists have different sizes" ); - res.fitStatus = 2; - results.push_back(res); - return results; - } - - const CscStripPrepData* pstrip = sfits[0].strip; - if ( pstrip == 0 ) { - ATH_MSG_WARNING ( "Strip pointer is null." ); - res.fitStatus = 4; - results.push_back(res); - return results; - } - Identifier idStrip0 = pstrip->identify(); - - // retrieve MuonDetectorManager from the conditions store - SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey}; - const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr(); - if(MuonDetMgr==nullptr){ - ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object"); - return results; - } - const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(idStrip0); - - bool measphi = m_idHelperSvc->cscIdHelper().CscIdHelper::measuresPhi(idStrip0); - double pitch = pro->cathodeReadoutPitch(0, measphi); - int maxstrip = pro->maxNumberOfStrips(measphi); - int strip0 = m_idHelperSvc->cscIdHelper().strip(idStrip0) - 1; - - int zsec = m_idHelperSvc->cscIdHelper().stationEta(idStrip0); - int station = m_idHelperSvc->cscIdHelper().stationName(idStrip0) - 49; // 1=CSS, 2=CSL - int phisec = m_idHelperSvc->cscIdHelper().stationPhi(idStrip0); - - int sector = zsec*(2*phisec - station + 1); - int wlay = m_idHelperSvc->cscIdHelper().wireLayer(idStrip0); - - // In SimpleCscClusterFitter istrip_peak = strip0; - int peak_count = 0; // # peaks in the cluster - bool edge = strip0 == 0; // is cluster on the edge of the chamber? - int stripidx =0; // actual strip position [0-191] or [0-47] - int countstrip =0; // counting strip in for loop - double qsum=0; // charge sum of strips in cluster - double xsum=0; // stripidx sum in cluster - double qxsum=0; // position weighted (stripidx) charge sum - double qerravg=0; - // istrip starts from 0. - // stripidx is for actual strip position [0-191] or [0-47]. - // Out of for loop, stripidx will be the last strip of cluster. - unsigned int istrip_peak = 0; - double lastqpeak =0; - for ( unsigned int istrip =0; istrip<nstrip; ++istrip ) { - StripFit sfit = sfits[istrip]; - float qthis = sfit.charge; - float qlast = 0.0; - if ( istrip > 0 ) qlast = sfits[istrip-1].charge; - float qnext = 0.0; - if ( istrip < nstrip-1 ) qnext = sfits[istrip+1].charge; - stripidx = strip0+istrip; - qsum += qthis; - qerravg += sfit.dcharge; - xsum += stripidx; - qxsum += qthis*stripidx; - countstrip = istrip+1; - if ( countstrip==2 && qthis<qlast ) ++peak_count; - if ( countstrip>2 && qthis<qlast && qlast>=sfits[istrip-2].charge ) ++peak_count; - - bool ispeak = qthis > qlast && qthis > qnext; - // Special case: next strip has the same charge. - // Require the previous strip has less charge and the next following - // strip be absent or have less charge. - if ( ! ispeak ) { - if ( qthis == qnext ) { - ispeak = ( qthis > qlast ) && - ( istrip+2 == nstrip || sfits[istrip+2].charge < qthis ); - } + // Check the input lists. + unsigned int nstrip = sfits.size(); + if (nstrip == 0) { + ATH_MSG_WARNING("Strip list is empty."); + res.fitStatus = 1; + results.push_back(res); + return results; + } + if (sfits.size() != nstrip) { + ATH_MSG_WARNING("Fit and strip lists have different sizes"); + res.fitStatus = 2; + results.push_back(res); + return results; } - // Special case: first and second strips have the same charge. - // Require the third strip has less charge. - if ( ! ispeak ) { - if ( istrip == 1 ) { - if ( qthis == qlast ) { - ispeak = qthis > qnext; // bug found 10/13/07 + + const CscStripPrepData* pstrip = sfits[0].strip; + if (pstrip == 0) { + ATH_MSG_WARNING("Strip pointer is null."); + res.fitStatus = 4; + results.push_back(res); + return results; + } + Identifier idStrip0 = pstrip->identify(); + + // retrieve MuonDetectorManager from the conditions store + SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey}; + const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr(); + if (MuonDetMgr == nullptr) { + ATH_MSG_ERROR("Null pointer to the MuonDetectorManager conditions object"); + return results; + } + const CscReadoutElement* pro = MuonDetMgr->getCscReadoutElement(idStrip0); + + bool measphi = m_idHelperSvc->cscIdHelper().CscIdHelper::measuresPhi(idStrip0); + double pitch = pro->cathodeReadoutPitch(0, measphi); + int maxstrip = pro->maxNumberOfStrips(measphi); + int strip0 = m_idHelperSvc->cscIdHelper().strip(idStrip0) - 1; + + int zsec = m_idHelperSvc->cscIdHelper().stationEta(idStrip0); + int station = m_idHelperSvc->cscIdHelper().stationName(idStrip0) - 49; // 1=CSS, 2=CSL + int phisec = m_idHelperSvc->cscIdHelper().stationPhi(idStrip0); + + int sector = zsec * (2 * phisec - station + 1); + int wlay = m_idHelperSvc->cscIdHelper().wireLayer(idStrip0); + + // In SimpleCscClusterFitter istrip_peak = strip0; + int peak_count = 0; // # peaks in the cluster + bool edge = strip0 == 0; // is cluster on the edge of the chamber? + int stripidx = 0; // actual strip position [0-191] or [0-47] + int countstrip = 0; // counting strip in for loop + double qsum = 0; // charge sum of strips in cluster + double xsum = 0; // stripidx sum in cluster + double qxsum = 0; // position weighted (stripidx) charge sum + double qerravg = 0; + // istrip starts from 0. + // stripidx is for actual strip position [0-191] or [0-47]. + // Out of for loop, stripidx will be the last strip of cluster. + unsigned int istrip_peak = 0; + double lastqpeak = 0; + for (unsigned int istrip = 0; istrip < nstrip; ++istrip) { + StripFit sfit = sfits[istrip]; + float qthis = sfit.charge; + float qlast = 0.0; + if (istrip > 0) qlast = sfits[istrip - 1].charge; + float qnext = 0.0; + if (istrip < nstrip - 1) qnext = sfits[istrip + 1].charge; + stripidx = strip0 + istrip; + qsum += qthis; + qerravg += sfit.dcharge; + xsum += stripidx; + qxsum += qthis * stripidx; + countstrip = istrip + 1; + if (countstrip == 2 && qthis < qlast) ++peak_count; + if (countstrip > 2 && qthis < qlast && qlast >= sfits[istrip - 2].charge) ++peak_count; + + bool ispeak = qthis > qlast && qthis > qnext; + // Special case: next strip has the same charge. + // Require the previous strip has less charge and the next following + // strip be absent or have less charge. + if (!ispeak) { + if (qthis == qnext) { + ispeak = (qthis > qlast) && (istrip + 2 == nstrip || sfits[istrip + 2].charge < qthis); + } + } + // Special case: first and second strips have the same charge. + // Require the third strip has less charge. + if (!ispeak) { + if (istrip == 1) { + if (qthis == qlast) { + ispeak = qthis > qnext; // bug found 10/13/07 + } + } + } + // Record if peak. + if (ispeak && qthis > lastqpeak) { + istrip_peak = istrip; + lastqpeak = qthis; } - } } - // Record if peak. - if ( ispeak && qthis>lastqpeak ) { - istrip_peak = istrip; - lastqpeak = qthis; + if (stripidx == maxstrip - 1) edge = true; + // Update peak count and edge. + if (countstrip == 1) ++peak_count; + if (countstrip > 1 && sfits[nstrip - 1].charge >= sfits[nstrip - 2].charge) ++peak_count; + + + // Fix to avoid division-by-zero (W.L. 29 Jun 2012) + if (qsum <= 0) { + // ATH_MSG_WARNING("Charge sum is not positive."); + // ATH_MSG_WARNING("Charge sum : "<<qsum); + res.fitStatus = 0; + double savg = strip0 + istrip_peak; // peak position: this strip has Q>0 + res.position = pitch * (savg + 0.5 - 0.5 * maxstrip); + res.strip = istrip_peak; // relative to cluster start + double errorScaler = measphi ? m_defaultErrorScaler_phi : m_defaultErrorScaler_eta; + res.dposition = errorScaler * pitch / sqrt(12.0); + //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++added 13/06/2014 to avoid index out of range in + //CscThreshholdClusterBuilder.cxx + res.fstrip = 0; + res.lstrip = nstrip - 1; + res.time = sfits[istrip_peak].time; + res.timeStatus = sfits[istrip_peak].timeStatus; + res.qpeak = sfits[istrip_peak].charge; + + res.charge = res.qpeak; + res.charge_beforeBPCorr = sfits[res.strip].charge_beforeBPCorr; + + res.qleft = 0.; + res.qright = 0.; + + if (istrip_peak >= 1) { + res.qleft = sfits[istrip_peak - 1].charge; + res.charge += res.qleft; + res.charge_beforeBPCorr += sfits[istrip_peak - 1].charge_beforeBPCorr; + } + if (istrip_peak + 1 < nstrip) { + res.qright = sfits[istrip_peak + 1].charge; + res.charge += res.qright; + res.charge_beforeBPCorr += sfits[istrip_peak + 1].charge_beforeBPCorr; + } + res.time_beforeT0Corr = sfits[res.strip].time_beforeT0Corr; + res.time_beforeBPCorr = sfits[res.strip].time_beforeBPCorr; + //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + results.push_back(res); + return results; } - } - if ( stripidx == maxstrip-1 ) edge = true; - // Update peak count and edge. - if ( countstrip==1 ) ++peak_count; - if ( countstrip>1 && sfits[nstrip-1].charge>=sfits[nstrip-2].charge ) ++peak_count; - - - //Fix to avoid division-by-zero (W.L. 29 Jun 2012) - if (qsum<=0) { - //ATH_MSG_WARNING("Charge sum is not positive."); - //ATH_MSG_WARNING("Charge sum : "<<qsum); - res.fitStatus=0; - double savg = strip0+istrip_peak; // peak position: this strip has Q>0 - res.position = pitch*(savg + 0.5 - 0.5*maxstrip); - res.strip = istrip_peak; // relative to cluster start + + + // Calculate strip averages. + double strip_mean = xsum / nstrip; // Avg strip position + double strip_qmean = qxsum / qsum; // Avg strip position weighted by charge + qerravg = qerravg / nstrip; // for centroid error calculation.... + // Assign cluster status. + // Cluster is spoiled if it is on the edge or has multiple peaks. + res.fitStatus = 0; + res.clusterStatus = Muon::CscStatusSimple; + if (edge) + res.clusterStatus = Muon::CscStatusEdge; + else if (peak_count > 1) + res.clusterStatus = Muon::CscStatusMultiPeak; + + double savg = -99.; + if (m_option == "MEAN") { + savg = strip_mean; + } else if (m_option == "PEAK") { + savg = strip0 + istrip_peak; + } else if (m_option == "CENTROID") { + savg = strip_qmean; + } else { + ATH_MSG_WARNING("Invalid position option: " << m_option); + res.clusterStatus = Muon::CscStatusUndefined; + } + + // WP treats.... special centroid method.... + if (m_use_peakthreshold && nstrip > 2 && peak_count == 1) savg = strip_qmean; + + if (measphi) savg = strip_mean; + + // Assign cluster identifier and time using the center of the cluster. + // res.strip = (sfits.size()-1)/2; + // Assign cluster identifier and time using peak strip 2/24/2009 + res.strip = istrip_peak; + + // Assign position. + res.position = pitch * (savg + 0.5 - 0.5 * maxstrip); + + // internal alignment ... + Identifier id = sfits[res.strip].strip->identify(); + double offset = m_alignmentTool->getAlignmentOffset(id); + res.position -= offset; + + // Assign position error. + double wmeas = pitch * nstrip; + double weff = wmeas - m_intrinsic_cluster_width; + double weffmin = 0.5 * wmeas; + if (weff < weffmin) weff = weffmin; double errorScaler = measphi ? m_defaultErrorScaler_phi : m_defaultErrorScaler_eta; - res.dposition = errorScaler*pitch/sqrt(12.0); - //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++added 13/06/2014 to avoid index out of range in CscThreshholdClusterBuilder.cxx - res.fstrip = 0; - res.lstrip = nstrip-1; - res.time = sfits[istrip_peak].time; + res.dposition = errorScaler * weff / sqrt(12.0); // CENTROID doesn't make any effect on the case nstrip=1 + /* + if (nstrip>1) { + if ( m_option == "CENTROID" || ( m_use_peakthreshold && nstrip>2 && peak_count==1) ) { + double scale_centroid = qerravg/qsum; + double xxsum =0; + for ( unsigned int istrip =0; istrip<nstrip; ++istrip ) { + StripFit sfit = sfits[istrip]; + stripidx = strip0+istrip; + xxsum += (stripidx-strip_qmean)*(stripidx-strip_qmean); + } + + res.dposition = pitch*scale_centroid*sqrt(xxsum); + ATH_MSG_VERBOSE ("qerravg:qsum:scale_centroid:xxsum:res.dposition= " + << qerravg << ":" << qsum << ":" << scale_centroid << ":"<< xxsum << ":"<< res.dposition); + } + } + */ + ATH_MSG_VERBOSE(" Simple Fit Result " + << " nstr=" << nstrip << "[sector:wlay:measphi]= " << sector << ":" << wlay << ":" << measphi + << " strip0=" << strip0 << " istrip_peak=" << istrip_peak << " peaktime=" << sfits[istrip_peak].time + << " peakstatus=" << sfits[istrip_peak].status + << " peaktimeStatus=" << sfits[istrip_peak].timeStatus << " pos=" << res.position + << " dpos=" << res.dposition << " chg=" << qsum); + + // cluster charge should be qsum over three strip... 3/21/2011 + res.fstrip = 0; + res.lstrip = nstrip - 1; + res.time = sfits[istrip_peak].time; res.timeStatus = sfits[istrip_peak].timeStatus; - res.qpeak = sfits[istrip_peak].charge; + res.qpeak = sfits[istrip_peak].charge; - res.charge = res.qpeak; + res.charge = res.qpeak; res.charge_beforeBPCorr = sfits[res.strip].charge_beforeBPCorr; - - res.qleft = 0.; + + res.qleft = 0.; res.qright = 0.; - if (istrip_peak>=1) { - res.qleft= sfits[istrip_peak-1].charge; - res.charge += res.qleft; - res.charge_beforeBPCorr += sfits[istrip_peak-1].charge_beforeBPCorr; + if (istrip_peak >= 1) { + res.qleft = sfits[istrip_peak - 1].charge; + res.charge += res.qleft; + res.charge_beforeBPCorr += sfits[istrip_peak - 1].charge_beforeBPCorr; } - if (istrip_peak+1<nstrip) { - res.qright= sfits[istrip_peak+1].charge; - res.charge += res.qright; - res.charge_beforeBPCorr += sfits[istrip_peak+1].charge_beforeBPCorr; + if (istrip_peak + 1 < nstrip) { + res.qright = sfits[istrip_peak + 1].charge; + res.charge += res.qright; + res.charge_beforeBPCorr += sfits[istrip_peak + 1].charge_beforeBPCorr; } res.time_beforeT0Corr = sfits[res.strip].time_beforeT0Corr; res.time_beforeBPCorr = sfits[res.strip].time_beforeBPCorr; - //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + // res.charge = qsum; + results.push_back(res); return results; - } - - - // Calculate strip averages. - double strip_mean = xsum/nstrip; // Avg strip position - double strip_qmean = qxsum/qsum; // Avg strip position weighted by charge - qerravg = qerravg/nstrip; // for centroid error calculation.... - // Assign cluster status. - // Cluster is spoiled if it is on the edge or has multiple peaks. - res.fitStatus = 0; - res.clusterStatus = Muon::CscStatusSimple; - if ( edge ) res.clusterStatus = Muon::CscStatusEdge; - else if ( peak_count > 1 ) res.clusterStatus = Muon::CscStatusMultiPeak; - - double savg=-99.; - if ( m_option == "MEAN" ) { - savg = strip_mean; - } else if ( m_option == "PEAK" ) { - savg = strip0+istrip_peak; - } else if ( m_option == "CENTROID" ) { - savg = strip_qmean; - } else { - ATH_MSG_WARNING ( "Invalid position option: " << m_option ); - res.clusterStatus = Muon::CscStatusUndefined; - } - - //WP treats.... special centroid method.... - if (m_use_peakthreshold && nstrip>2 && peak_count==1) - savg = strip_qmean; - - if ( measphi ) savg = strip_mean; - - // Assign cluster identifier and time using the center of the cluster. - // res.strip = (sfits.size()-1)/2; - // Assign cluster identifier and time using peak strip 2/24/2009 - res.strip = istrip_peak; - - // Assign position. - res.position = pitch*(savg + 0.5 - 0.5*maxstrip); - - // internal alignment ... - Identifier id = sfits[res.strip].strip->identify(); - double offset = m_alignmentTool->getAlignmentOffset(id); - res.position -= offset; - - // Assign position error. - double wmeas = pitch*nstrip; - double weff = wmeas - m_intrinsic_cluster_width; - double weffmin = 0.5*wmeas; - if ( weff < weffmin ) weff = weffmin; - double errorScaler = measphi ? m_defaultErrorScaler_phi : m_defaultErrorScaler_eta; - res.dposition = errorScaler*weff/sqrt(12.0); // CENTROID doesn't make any effect on the case nstrip=1 - /* - if (nstrip>1) { - if ( m_option == "CENTROID" || ( m_use_peakthreshold && nstrip>2 && peak_count==1) ) { - double scale_centroid = qerravg/qsum; - double xxsum =0; - for ( unsigned int istrip =0; istrip<nstrip; ++istrip ) { - StripFit sfit = sfits[istrip]; - stripidx = strip0+istrip; - xxsum += (stripidx-strip_qmean)*(stripidx-strip_qmean); - } - - res.dposition = pitch*scale_centroid*sqrt(xxsum); - ATH_MSG_VERBOSE ("qerravg:qsum:scale_centroid:xxsum:res.dposition= " - << qerravg << ":" << qsum << ":" << scale_centroid << ":"<< xxsum << ":"<< res.dposition); - } - } - */ - ATH_MSG_VERBOSE ( " Simple Fit Result " << " nstr=" << nstrip - << "[sector:wlay:measphi]= " << sector << ":" <<wlay << ":" <<measphi - << " strip0=" << strip0 - << " istrip_peak=" << istrip_peak - << " peaktime=" << sfits[istrip_peak].time - << " peakstatus=" << sfits[istrip_peak].status - << " peaktimeStatus=" << sfits[istrip_peak].timeStatus - << " pos=" << res.position << " dpos=" << res.dposition - << " chg=" << qsum - ); - - // cluster charge should be qsum over three strip... 3/21/2011 - res.fstrip = 0; - res.lstrip = nstrip-1; - res.time = sfits[istrip_peak].time; - res.timeStatus = sfits[istrip_peak].timeStatus; - res.qpeak = sfits[istrip_peak].charge; - - res.charge = res.qpeak; - res.charge_beforeBPCorr = sfits[res.strip].charge_beforeBPCorr; - - res.qleft = 0.; - res.qright = 0.; - - if (istrip_peak>=1) { - res.qleft= sfits[istrip_peak-1].charge; - res.charge += res.qleft; - res.charge_beforeBPCorr += sfits[istrip_peak-1].charge_beforeBPCorr; - } - if (istrip_peak+1<nstrip) { - res.qright= sfits[istrip_peak+1].charge; - res.charge += res.qright; - res.charge_beforeBPCorr += sfits[istrip_peak+1].charge_beforeBPCorr; - } - res.time_beforeT0Corr = sfits[res.strip].time_beforeT0Corr; - res.time_beforeBPCorr = sfits[res.strip].time_beforeBPCorr; - - // res.charge = qsum; - - results.push_back(res); - return results; } //********************************************************************** -Results SimpleCscClusterFitter::fit(const StripFitList& sfits, double) const { - return fit(sfits); +Results +SimpleCscClusterFitter::fit(const StripFitList& sfits, double) const +{ + return fit(sfits); } //********************************************************************** -double SimpleCscClusterFitter::getCorrectedError(const CscPrepData* /*pclu*/, double /*slope*/) const { - return 0; +double +SimpleCscClusterFitter::getCorrectedError(const CscPrepData* /*pclu*/, double /*slope*/) const +{ + return 0; } diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/SimpleCscClusterFitter.h b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/SimpleCscClusterFitter.h index 7421986bb8b1..7585a5525794 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/SimpleCscClusterFitter.h +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/CscClusterization/src/SimpleCscClusterFitter.h @@ -10,52 +10,51 @@ // // Tool to select muons for physics analysis. -#include "CscClusterization/ICscClusterFitter.h" #include "AthenaBaseComps/AthAlgTool.h" +#include "CscClusterization/ICscAlignmentTool.h" +#include "CscClusterization/ICscClusterFitter.h" #include "GaudiKernel/ServiceHandle.h" #include "GaudiKernel/ToolHandle.h" - -#include "MuonReadoutGeometry/MuonDetectorManager.h" #include "MuonIdHelpers/IMuonIdHelperSvc.h" #include "MuonPrepRawData/CscClusterStatus.h" -#include "CscClusterization/ICscAlignmentTool.h" +#include "MuonReadoutGeometry/MuonDetectorManager.h" namespace Muon { - class CscPrepData; +class CscPrepData; } class SimpleCscClusterFitter : virtual public ICscClusterFitter, public AthAlgTool { - -public: - - SimpleCscClusterFitter(std::string, std::string, const IInterface*); - - ~SimpleCscClusterFitter()=default; - - StatusCode initialize(); - - // Inherited methods. - using ICscClusterFitter::fit; - Results fit(const StripFitList& sfits) const; - Results fit(const StripFitList& sfits, double dposdz) const; - double getCorrectedError(const Muon::CscPrepData* pclu, double slope) const; -private: - - // Properties - std::string m_option; // Fitting option: MEAN, PEAK, ... - double m_intrinsic_cluster_width; // Intrinsic widh for error calculation - bool m_use_peakthreshold; - double m_defaultErrorScaler_eta; - double m_defaultErrorScaler_phi; - - const MuonGM::MuonDetectorManager* m_detMgr; - - ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}; - - /** retrieve MuonDetectorManager from the conditions store */ - SG::ReadCondHandleKey<MuonGM::MuonDetectorManager> m_DetectorManagerKey {this, "DetectorManagerKey", - "MuonDetectorManager", "Key of input MuonDetectorManager condition data"}; - - ToolHandle<ICscAlignmentTool> m_alignmentTool; + + public: + SimpleCscClusterFitter(std::string, std::string, const IInterface*); + + ~SimpleCscClusterFitter() = default; + + StatusCode initialize(); + + // Inherited methods. + using ICscClusterFitter::fit; + Results fit(const StripFitList& sfits) const; + Results fit(const StripFitList& sfits, double dposdz) const; + double getCorrectedError(const Muon::CscPrepData* pclu, double slope) const; + + private: + // Properties + std::string m_option; // Fitting option: MEAN, PEAK, ... + double m_intrinsic_cluster_width; // Intrinsic widh for error calculation + bool m_use_peakthreshold; + double m_defaultErrorScaler_eta; + double m_defaultErrorScaler_phi; + + const MuonGM::MuonDetectorManager* m_detMgr; + + ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc{this, "MuonIdHelperSvc", + "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}; + + /** retrieve MuonDetectorManager from the conditions store */ + SG::ReadCondHandleKey<MuonGM::MuonDetectorManager> m_DetectorManagerKey{ + this, "DetectorManagerKey", "MuonDetectorManager", "Key of input MuonDetectorManager condition data"}; + + ToolHandle<ICscAlignmentTool> m_alignmentTool; }; #endif diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MuonClusterization/src/MuonClusterizationAlg.cxx b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MuonClusterization/src/MuonClusterizationAlg.cxx index a6403b5e64af..f5d4bb07b196 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MuonClusterization/src/MuonClusterizationAlg.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MuonClusterization/src/MuonClusterizationAlg.cxx @@ -8,48 +8,49 @@ using namespace Muon; -MuonClusterizationAlg::MuonClusterizationAlg(const std::string& name, ISvcLocator* pSvcLocator) : - AthAlgorithm(name,pSvcLocator), - m_clusterTool("Muon::MuonClusterizationTool/MuonClusterizationTool") +MuonClusterizationAlg::MuonClusterizationAlg(const std::string& name, ISvcLocator* pSvcLocator) + : AthAlgorithm(name, pSvcLocator), m_clusterTool("Muon::MuonClusterizationTool/MuonClusterizationTool") { - declareProperty("TgcPrepDataContainer", m_tgcPrdLocationInput = "TGC_Measurements"); - declareProperty("TgcPrepDataContainerOutput", m_tgcPrdLocationOutput = "TGC_Clusters"); - declareProperty("RpcPrepDataContainer", m_rpcPrdLocationInput = "RPC_Measurements"); - declareProperty("RpcPrepDataContainerOutput", m_rpcPrdLocationOutput = "RPC_Clusters"); - declareProperty("ClusterTool", m_clusterTool); + declareProperty("TgcPrepDataContainer", m_tgcPrdLocationInput = "TGC_Measurements"); + declareProperty("TgcPrepDataContainerOutput", m_tgcPrdLocationOutput = "TGC_Clusters"); + declareProperty("RpcPrepDataContainer", m_rpcPrdLocationInput = "RPC_Measurements"); + declareProperty("RpcPrepDataContainerOutput", m_rpcPrdLocationOutput = "RPC_Clusters"); + declareProperty("ClusterTool", m_clusterTool); } -StatusCode MuonClusterizationAlg::initialize() +StatusCode +MuonClusterizationAlg::initialize() { - ATH_CHECK(m_clusterTool.retrieve()); - return StatusCode::SUCCESS; + ATH_CHECK(m_clusterTool.retrieve()); + return StatusCode::SUCCESS; } -StatusCode MuonClusterizationAlg::execute() +StatusCode +MuonClusterizationAlg::execute() { - const TgcPrepDataContainer* tgcContainer = nullptr; - if (evtStore()->retrieve(tgcContainer,m_tgcPrdLocationInput).isFailure() ) { - ATH_MSG_WARNING("Could not find TgcPrepDataContainer at " << m_tgcPrdLocationInput); - return StatusCode::RECOVERABLE; - } - - const TgcPrepDataContainer* tgcContainerCluster = m_clusterTool->cluster(*tgcContainer); - if (evtStore()->record(tgcContainerCluster,m_tgcPrdLocationOutput).isFailure() ) { - ATH_MSG_WARNING("Could not record TgcPrepDataContainer at " << m_tgcPrdLocationOutput); - return StatusCode::RECOVERABLE; - } - - const RpcPrepDataContainer* rpcContainer = nullptr; - if (evtStore()->retrieve(rpcContainer,m_rpcPrdLocationInput).isFailure() ) { - ATH_MSG_WARNING("Could not find RpcPrepDataContainer at " << m_rpcPrdLocationInput); - return StatusCode::RECOVERABLE; - } - - const RpcPrepDataContainer* rpcContainerCluster = m_clusterTool->cluster(*rpcContainer); - if (evtStore()->record(rpcContainerCluster,m_rpcPrdLocationOutput).isFailure() ) { - ATH_MSG_WARNING("Could not record RpcPrepDataContainer at " << m_rpcPrdLocationOutput); - return StatusCode::RECOVERABLE; - } - - return StatusCode::SUCCESS; + const TgcPrepDataContainer* tgcContainer = nullptr; + if (evtStore()->retrieve(tgcContainer, m_tgcPrdLocationInput).isFailure()) { + ATH_MSG_WARNING("Could not find TgcPrepDataContainer at " << m_tgcPrdLocationInput); + return StatusCode::RECOVERABLE; + } + + const TgcPrepDataContainer* tgcContainerCluster = m_clusterTool->cluster(*tgcContainer); + if (evtStore()->record(tgcContainerCluster, m_tgcPrdLocationOutput).isFailure()) { + ATH_MSG_WARNING("Could not record TgcPrepDataContainer at " << m_tgcPrdLocationOutput); + return StatusCode::RECOVERABLE; + } + + const RpcPrepDataContainer* rpcContainer = nullptr; + if (evtStore()->retrieve(rpcContainer, m_rpcPrdLocationInput).isFailure()) { + ATH_MSG_WARNING("Could not find RpcPrepDataContainer at " << m_rpcPrdLocationInput); + return StatusCode::RECOVERABLE; + } + + const RpcPrepDataContainer* rpcContainerCluster = m_clusterTool->cluster(*rpcContainer); + if (evtStore()->record(rpcContainerCluster, m_rpcPrdLocationOutput).isFailure()) { + ATH_MSG_WARNING("Could not record RpcPrepDataContainer at " << m_rpcPrdLocationOutput); + return StatusCode::RECOVERABLE; + } + + return StatusCode::SUCCESS; } diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MuonClusterization/src/MuonClusterizationAlg.h b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MuonClusterization/src/MuonClusterizationAlg.h index 2694f57cf90d..b23e649d94cd 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MuonClusterization/src/MuonClusterizationAlg.h +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MuonClusterization/src/MuonClusterizationAlg.h @@ -5,32 +5,30 @@ #ifndef MUONCLUSTERIZATIONALG_H #define MUONCLUSTERIZATIONALG_H +#include <string> + #include "AthenaBaseComps/AthAlgorithm.h" #include "GaudiKernel/ToolHandle.h" #include "MuonClusterization/IMuonClusterizationTool.h" -#include <string> - -class MuonClusterizationAlg : public AthAlgorithm -{ - public: - MuonClusterizationAlg(const std::string& name, ISvcLocator* pSvcLocator); - - public: - virtual ~MuonClusterizationAlg()=default; +class MuonClusterizationAlg : public AthAlgorithm { + public: + MuonClusterizationAlg(const std::string& name, ISvcLocator* pSvcLocator); - virtual StatusCode initialize(); - virtual StatusCode execute(); + public: + virtual ~MuonClusterizationAlg() = default; - private: + virtual StatusCode initialize(); + virtual StatusCode execute(); - std::string m_tgcPrdLocationInput; //!< Location of input TgcPrepData - std::string m_tgcPrdLocationOutput; //!< Location of output TgcPrepData + private: + std::string m_tgcPrdLocationInput; //!< Location of input TgcPrepData + std::string m_tgcPrdLocationOutput; //!< Location of output TgcPrepData - std::string m_rpcPrdLocationInput; //!< Location of input RpcPrepData - std::string m_rpcPrdLocationOutput; //!< Location of output RpcPrepData + std::string m_rpcPrdLocationInput; //!< Location of input RpcPrepData + std::string m_rpcPrdLocationOutput; //!< Location of output RpcPrepData - ToolHandle<Muon::IMuonClusterizationTool> m_clusterTool; //!< clustering Tool + ToolHandle<Muon::IMuonClusterizationTool> m_clusterTool; //!< clustering Tool }; -#endif +#endif diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MuonTGMeasAssocAlg/MuonTGMeasAssocAlg/MuonTGMeasAssocAlg.h b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MuonTGMeasAssocAlg/MuonTGMeasAssocAlg/MuonTGMeasAssocAlg.h index a4f97d203734..7af26afb5d2e 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MuonTGMeasAssocAlg/MuonTGMeasAssocAlg/MuonTGMeasAssocAlg.h +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MuonTGMeasAssocAlg/MuonTGMeasAssocAlg/MuonTGMeasAssocAlg.h @@ -5,144 +5,145 @@ #ifndef MUONTGMEASASSOCALG_MUONTGMEASASSOCALG_H #define MUONTGMEASASSOCALG_MUONTGMEASASSOCALG_H +#include <fstream> + #include "AthenaBaseComps/AthAlgorithm.h" #include "GaudiKernel/ServiceHandle.h" #include "GaudiKernel/ToolHandle.h" - +#include "GeoPrimitives/GeoPrimitives.h" #include "MuonIdHelpers/IMuonIdHelperSvc.h" -#include "StoreGate/ReadCondHandleKey.h" -#include "TrkTrack/Track.h" -#include "TrkExInterfaces/IExtrapolator.h" -#include "TrkGeometry/TrackingGeometry.h" -#include "TrkSurfaces/CylinderSurface.h" -#include "TrkPrepRawData/PrepRawData.h" -#include "TrkSegment/SegmentCollection.h" -#include "MuonReadoutGeometry/MuonDetectorManager.h" +#include "MuonPrepRawData/CscPrepData.h" #include "MuonPrepRawData/MdtPrepData.h" #include "MuonPrepRawData/RpcPrepData.h" -#include "MuonPrepRawData/CscPrepData.h" #include "MuonPrepRawData/TgcPrepData.h" +#include "MuonReadoutGeometry/MuonDetectorManager.h" #include "MuonTGRecTools/IMuonTGMeasTool.h" #include "MuonTGRecTools/MuonTGHits.h" #include "MuonTGRecTools/MuonTGSegments.h" -#include "GeoPrimitives/GeoPrimitives.h" - -#include <fstream> +#include "StoreGate/ReadCondHandleKey.h" +#include "TrkExInterfaces/IExtrapolator.h" +#include "TrkGeometry/TrackingGeometry.h" +#include "TrkPrepRawData/PrepRawData.h" +#include "TrkSegment/SegmentCollection.h" +#include "TrkSurfaces/CylinderSurface.h" +#include "TrkTrack/Track.h" -namespace Muon{ - - /** @class MuonTGMeasAssocAlg - - associates hits/segments with active layers from the (muon) tracking geometry - - @author Sarka.Todorova@cern.ch - */ - -class MuonTGMeasAssocAlg : public AthAlgorithm { - -public: - - typedef Trk::Track Track; - typedef std::pair<const Trk::Layer*,std::vector<Identifier>*> PairOfLayerID; - typedef std::pair<const Trk::Layer*,std::vector<const Trk::PrepRawData*>*> PairOfLayerPrd; - typedef std::pair<const Trk::Layer*,std::vector<const Muon::MdtPrepData*>*> PairOfLayerMdtPrd; - typedef std::pair<const Trk::Layer*,std::vector<const Muon::RpcPrepData*>*> PairOfLayerRpcPrd; - typedef std::pair<const Trk::Layer*,std::vector<const Muon::CscPrepData*>*> PairOfLayerCscPrd; - typedef std::pair<const Trk::Layer*,std::vector<const Muon::TgcPrepData*>*> PairOfLayerTgcPrd; - - MuonTGMeasAssocAlg(const std::string &name,ISvcLocator *pSvcLocator); - - ~MuonTGMeasAssocAlg()=default; - - StatusCode initialize(); - StatusCode execute(); - - StatusCode retrieveMeasurements(const MuonGM::MuonDetectorManager* MuonDetMgr); - StatusCode storeMeasurements(); - StatusCode storeSegments(); - -private: - std::vector<PairOfLayerPrd*>* createMdtHitCollectionLayers(const MuonGM::MuonDetectorManager* MuonDetMgr) const; - std::vector<PairOfLayerPrd*>* createRpcHitCollectionLayers(const MuonGM::MuonDetectorManager* MuonDetMgr) const; - std::vector<PairOfLayerPrd*>* createCscHitCollectionLayers(const MuonGM::MuonDetectorManager* MuonDetMgr) const; - std::vector<PairOfLayerPrd*>* createTgcHitCollectionLayers(const MuonGM::MuonDetectorManager* MuonDetMgr) const; - StatusCode createStationHitCollection() const; - StatusCode createStationSegmentCollection(const MuonGM::MuonDetectorManager* MuonDetMgr) const; - void createStationMap(const Trk::TrackingVolume* vol, const MuonGM::MuonDetectorManager* MuonDetMgr) const; - void misAlignStations() const; - void reAlignStations() const; - const Trk::Layer* associatedLayer(int techn, Identifier id, const MuonGM::MuonDetectorManager* MuonDetMgr) const; - const Trk::Layer* associatedLayer(const Trk::TrackingVolume* trVol, Identifier id) const; - Identifier getStationId( Identifier id ) const; - - // --- job options - bool m_mdtIn; - bool m_rpcIn; - bool m_cscIn; - bool m_tgcIn; - bool m_segmentsIn; - bool m_writeTgHits; - bool m_writeTgSegments; - bool m_reAlign; - bool m_misAlign; - bool m_allowGeomAssoc; - - mutable const Trk::TrackingGeometry* m_trackingGeometry; - std::string m_trackingGeometryName; - - ToolHandle<Muon::IMuonTGMeasTool> m_muonTgTool; - - ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}; - - SG::ReadCondHandleKey<MuonGM::MuonDetectorManager> m_DetectorManagerKey {this, "DetectorManagerKey", - "MuonDetectorManager", - "Key of input MuonDetectorManager condition data"}; - - std::string m_inputSegmentCollectionMoore; - std::string m_inputSegmentCollectionMoMu; - std::string m_inputSegmentCollectionMBoy; - std::string m_inputMdtPrdCollection; - std::string m_inputRpcPrdCollection; - std::string m_inputTgcPrdCollection; - std::string m_inputCscPrdCollection; - - // -- algorithm members - ActiveStoreSvc* m_activeStore; - mutable std::vector<PairOfLayerPrd*>* m_mdtHits; - mutable std::vector<PairOfLayerPrd*>* m_rpcHits; - mutable std::vector<PairOfLayerPrd*>* m_cscHits; - mutable std::vector<PairOfLayerPrd*>* m_tgcHits; - mutable MuonTGHits *m_allHits; - mutable MuonTGSegments *m_allSegments; - ToolHandle<Trk::IExtrapolator> m_extrapolator; - mutable std::map<Identifier,std::pair<const MuonGM::MuonStation*,const Trk::DetachedTrackingVolume*> > m_stationMap; - mutable std::vector<std::pair<Identifier, Amg::Transform3D> > m_misAlignDiff; // vector holding required misalignment +namespace Muon { + +/** @class MuonTGMeasAssocAlg + + associates hits/segments with active layers from the (muon) tracking geometry + + @author Sarka.Todorova@cern.ch + */ + +class MuonTGMeasAssocAlg : public AthAlgorithm { + + public: + typedef Trk::Track Track; + typedef std::pair<const Trk::Layer*, std::vector<Identifier>*> PairOfLayerID; + typedef std::pair<const Trk::Layer*, std::vector<const Trk::PrepRawData*>*> PairOfLayerPrd; + typedef std::pair<const Trk::Layer*, std::vector<const Muon::MdtPrepData*>*> PairOfLayerMdtPrd; + typedef std::pair<const Trk::Layer*, std::vector<const Muon::RpcPrepData*>*> PairOfLayerRpcPrd; + typedef std::pair<const Trk::Layer*, std::vector<const Muon::CscPrepData*>*> PairOfLayerCscPrd; + typedef std::pair<const Trk::Layer*, std::vector<const Muon::TgcPrepData*>*> PairOfLayerTgcPrd; + + MuonTGMeasAssocAlg(const std::string& name, ISvcLocator* pSvcLocator); + + ~MuonTGMeasAssocAlg() = default; + + StatusCode initialize(); + StatusCode execute(); + + StatusCode retrieveMeasurements(const MuonGM::MuonDetectorManager* MuonDetMgr); + StatusCode storeMeasurements(); + StatusCode storeSegments(); + + private: + std::vector<PairOfLayerPrd*>* createMdtHitCollectionLayers(const MuonGM::MuonDetectorManager* MuonDetMgr) const; + std::vector<PairOfLayerPrd*>* createRpcHitCollectionLayers(const MuonGM::MuonDetectorManager* MuonDetMgr) const; + std::vector<PairOfLayerPrd*>* createCscHitCollectionLayers(const MuonGM::MuonDetectorManager* MuonDetMgr) const; + std::vector<PairOfLayerPrd*>* createTgcHitCollectionLayers(const MuonGM::MuonDetectorManager* MuonDetMgr) const; + StatusCode createStationHitCollection() const; + StatusCode createStationSegmentCollection(const MuonGM::MuonDetectorManager* MuonDetMgr) const; + void createStationMap(const Trk::TrackingVolume* vol, const MuonGM::MuonDetectorManager* MuonDetMgr) const; + void misAlignStations() const; + void reAlignStations() const; + const Trk::Layer* associatedLayer(int techn, Identifier id, const MuonGM::MuonDetectorManager* MuonDetMgr) const; + const Trk::Layer* associatedLayer(const Trk::TrackingVolume* trVol, Identifier id) const; + Identifier getStationId(Identifier id) const; + + // --- job options + bool m_mdtIn; + bool m_rpcIn; + bool m_cscIn; + bool m_tgcIn; + bool m_segmentsIn; + bool m_writeTgHits; + bool m_writeTgSegments; + bool m_reAlign; + bool m_misAlign; + bool m_allowGeomAssoc; + + mutable const Trk::TrackingGeometry* m_trackingGeometry; + std::string m_trackingGeometryName; + + ToolHandle<Muon::IMuonTGMeasTool> m_muonTgTool; + + ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc{this, "MuonIdHelperSvc", + "Muon::MuonIdHelperSvc/MuonIdHelperSvc"}; + + SG::ReadCondHandleKey<MuonGM::MuonDetectorManager> m_DetectorManagerKey{ + this, "DetectorManagerKey", "MuonDetectorManager", "Key of input MuonDetectorManager condition data"}; + + std::string m_inputSegmentCollectionMoore; + std::string m_inputSegmentCollectionMoMu; + std::string m_inputSegmentCollectionMBoy; + std::string m_inputMdtPrdCollection; + std::string m_inputRpcPrdCollection; + std::string m_inputTgcPrdCollection; + std::string m_inputCscPrdCollection; + + // -- algorithm members + ActiveStoreSvc* m_activeStore; + mutable std::vector<PairOfLayerPrd*>* m_mdtHits; + mutable std::vector<PairOfLayerPrd*>* m_rpcHits; + mutable std::vector<PairOfLayerPrd*>* m_cscHits; + mutable std::vector<PairOfLayerPrd*>* m_tgcHits; + mutable MuonTGHits* m_allHits; + mutable MuonTGSegments* m_allSegments; + ToolHandle<Trk::IExtrapolator> m_extrapolator; + mutable std::map<Identifier, std::pair<const MuonGM::MuonStation*, const Trk::DetachedTrackingVolume*> > + m_stationMap; + mutable std::vector<std::pair<Identifier, Amg::Transform3D> > + m_misAlignDiff; // vector holding required misalignment }; - inline StatusCode MuonTGMeasAssocAlg::retrieveMeasurements(const MuonGM::MuonDetectorManager* MuonDetMgr) { - // Get the messaging service, print where you are - ATH_MSG_DEBUG( "MuonTGMeasAssocAlg::retrieveMeasurements()" ); - // - //if (m_allHits) delete m_allHits; - if (m_mdtHits) delete m_mdtHits; - if (m_rpcHits) delete m_rpcHits; - if (m_cscHits) delete m_cscHits; - if (m_tgcHits) delete m_tgcHits; - - if (m_mdtIn) m_mdtHits = createMdtHitCollectionLayers(MuonDetMgr); - if (m_rpcIn) m_rpcHits = createRpcHitCollectionLayers(MuonDetMgr); - if (m_cscIn) m_cscHits = createCscHitCollectionLayers(MuonDetMgr); - if (m_tgcIn) m_tgcHits = createTgcHitCollectionLayers(MuonDetMgr); - ATH_CHECK( createStationHitCollection() ); - - ATH_MSG_DEBUG( "MuonTGMeasAssocAlg::collected hits from " << m_allHits->size() << " stations" ); - - if (m_allHits->size()) return StatusCode::SUCCESS; - - return StatusCode::FAILURE; - } - -} - -#endif //MUONTGMEASASSOCALG_MUONTGMEASASSOCALG_H +inline StatusCode +MuonTGMeasAssocAlg::retrieveMeasurements(const MuonGM::MuonDetectorManager* MuonDetMgr) +{ + // Get the messaging service, print where you are + ATH_MSG_DEBUG("MuonTGMeasAssocAlg::retrieveMeasurements()"); + // + // if (m_allHits) delete m_allHits; + if (m_mdtHits) delete m_mdtHits; + if (m_rpcHits) delete m_rpcHits; + if (m_cscHits) delete m_cscHits; + if (m_tgcHits) delete m_tgcHits; + + if (m_mdtIn) m_mdtHits = createMdtHitCollectionLayers(MuonDetMgr); + if (m_rpcIn) m_rpcHits = createRpcHitCollectionLayers(MuonDetMgr); + if (m_cscIn) m_cscHits = createCscHitCollectionLayers(MuonDetMgr); + if (m_tgcIn) m_tgcHits = createTgcHitCollectionLayers(MuonDetMgr); + ATH_CHECK(createStationHitCollection()); + + ATH_MSG_DEBUG("MuonTGMeasAssocAlg::collected hits from " << m_allHits->size() << " stations"); + + if (m_allHits->size()) return StatusCode::SUCCESS; + + return StatusCode::FAILURE; +} + +} // namespace Muon +#endif // MUONTGMEASASSOCALG_MUONTGMEASASSOCALG_H diff --git a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MuonTGMeasAssocAlg/src/MuonTGMeasAssocAlg.cxx b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MuonTGMeasAssocAlg/src/MuonTGMeasAssocAlg.cxx index 3e54c1cda5f2..133a0f63fe21 100644 --- a/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MuonTGMeasAssocAlg/src/MuonTGMeasAssocAlg.cxx +++ b/MuonSpectrometer/MuonReconstruction/MuonDataPrep/MuonTGMeasAssocAlg/src/MuonTGMeasAssocAlg.cxx @@ -4,1038 +4,1090 @@ #include "MuonTGMeasAssocAlg/MuonTGMeasAssocAlg.h" -#include "StoreGate/StoreGate.h" -#include "GaudiKernel/ListItem.h" -#include "StoreGate/StoreGateSvc.h" +#include <vector> + +#include "EventPrimitives/EventPrimitives.h" #include "GaudiKernel/IToolSvc.h" -#include "TrkParameters/TrackParameters.h" -#include "TrkEventPrimitives/ParamDefs.h" -#include "TrkEventPrimitives/LocalDirection.h" -#include "TrkMeasurementBase/MeasurementBase.h" -#include "TrkGeometry/Layer.h" -#include "TrkGeometry/TrackingVolume.h" -#include "TrkGeometry/TrackingGeometry.h" +#include "GaudiKernel/ListItem.h" +#include "GeoPrimitives/CLHEPtoEigenConverter.h" #include "MuonPrepRawData/MuonPrepDataContainer.h" +#include "MuonReadoutGeometry/CscReadoutElement.h" #include "MuonReadoutGeometry/MdtReadoutElement.h" +#include "MuonReadoutGeometry/MuonStation.h" #include "MuonReadoutGeometry/RpcReadoutElement.h" #include "MuonReadoutGeometry/TgcReadoutElement.h" -#include "MuonReadoutGeometry/CscReadoutElement.h" -#include "MuonReadoutGeometry/MuonStation.h" #include "MuonSegment/MuonSegment.h" -#include "EventPrimitives/EventPrimitives.h" -#include "GeoPrimitives/CLHEPtoEigenConverter.h" - -#include <vector> +#include "StoreGate/StoreGate.h" +#include "StoreGate/StoreGateSvc.h" +#include "TrkEventPrimitives/LocalDirection.h" +#include "TrkEventPrimitives/ParamDefs.h" +#include "TrkGeometry/Layer.h" +#include "TrkGeometry/TrackingGeometry.h" +#include "TrkGeometry/TrackingVolume.h" +#include "TrkMeasurementBase/MeasurementBase.h" +#include "TrkParameters/TrackParameters.h" // Constructor with parameters: -Muon::MuonTGMeasAssocAlg::MuonTGMeasAssocAlg(const std::string &name, ISvcLocator *pSvcLocator ) : - AthAlgorithm(name,pSvcLocator), - m_mdtIn(true), - m_rpcIn(true), - m_cscIn(true), - m_tgcIn(true), - m_segmentsIn(false), - m_writeTgHits(false), - m_writeTgSegments(false), - m_reAlign(false), - m_misAlign(false), - m_allowGeomAssoc(true), - m_trackingGeometry(0), - m_trackingGeometryName("AtlasTrackingGeometry"), - m_muonTgTool("Muon::MuonTGMeasurementTool/MuonTGMeasurementTool"), - m_inputSegmentCollectionMoore("MooreSegments"), - m_inputSegmentCollectionMoMu("MuonSegments_MoMu"), - m_inputSegmentCollectionMBoy("ConvertedMBoySegments"), - m_inputMdtPrdCollection("MDT_DriftCircles"), - m_inputRpcPrdCollection("RPC_Measurements"), - m_inputTgcPrdCollection("TGC_Measurements"), - m_inputCscPrdCollection("CSC_Clusters"), - m_activeStore(0), - m_mdtHits(0), - m_rpcHits(0), - m_cscHits(0), - m_tgcHits(0), - m_allHits(0), - m_allSegments(0), - m_extrapolator("Trk::Extrapolator/Extrapolator") +Muon::MuonTGMeasAssocAlg::MuonTGMeasAssocAlg(const std::string& name, ISvcLocator* pSvcLocator) + : AthAlgorithm(name, pSvcLocator), + m_mdtIn(true), + m_rpcIn(true), + m_cscIn(true), + m_tgcIn(true), + m_segmentsIn(false), + m_writeTgHits(false), + m_writeTgSegments(false), + m_reAlign(false), + m_misAlign(false), + m_allowGeomAssoc(true), + m_trackingGeometry(0), + m_trackingGeometryName("AtlasTrackingGeometry"), + m_muonTgTool("Muon::MuonTGMeasurementTool/MuonTGMeasurementTool"), + m_inputSegmentCollectionMoore("MooreSegments"), + m_inputSegmentCollectionMoMu("MuonSegments_MoMu"), + m_inputSegmentCollectionMBoy("ConvertedMBoySegments"), + m_inputMdtPrdCollection("MDT_DriftCircles"), + m_inputRpcPrdCollection("RPC_Measurements"), + m_inputTgcPrdCollection("TGC_Measurements"), + m_inputCscPrdCollection("CSC_Clusters"), + m_activeStore(0), + m_mdtHits(0), + m_rpcHits(0), + m_cscHits(0), + m_tgcHits(0), + m_allHits(0), + m_allSegments(0), + m_extrapolator("Trk::Extrapolator/Extrapolator") { - declareProperty("TrackingGeometry", m_trackingGeometryName); - declareProperty("Extrapolator", m_extrapolator); - declareProperty("ProcessMdtHits", m_mdtIn); - declareProperty("ProcessRpcHits", m_rpcIn); - declareProperty("ProcessCscHits", m_cscIn); - declareProperty("ProcessTgcHits", m_tgcIn); - declareProperty("ProcessSegments", m_segmentsIn); - declareProperty("WriteAssociatedHits", m_writeTgHits); - declareProperty("WriteAssociatedSegments", m_writeTgSegments); - declareProperty("InputSegmentCollection_Moore", m_inputSegmentCollectionMoore); - declareProperty("InputSegmentCollection_MoMu" , m_inputSegmentCollectionMoMu); - declareProperty("InputSegmentCollection_MBoy" , m_inputSegmentCollectionMBoy); - declareProperty("InputMdtPrdCollection", m_inputMdtPrdCollection); - declareProperty("InputRpcPrdCollection", m_inputRpcPrdCollection); - declareProperty("InputTgcPrdCollection", m_inputTgcPrdCollection); - declareProperty("InputCscPrdCollection", m_inputCscPrdCollection); - declareProperty("AlignMTG", m_reAlign); - declareProperty("MisAlignMTG", m_misAlign); - declareProperty("AllowGeometricalAssociation", m_allowGeomAssoc); + declareProperty("TrackingGeometry", m_trackingGeometryName); + declareProperty("Extrapolator", m_extrapolator); + declareProperty("ProcessMdtHits", m_mdtIn); + declareProperty("ProcessRpcHits", m_rpcIn); + declareProperty("ProcessCscHits", m_cscIn); + declareProperty("ProcessTgcHits", m_tgcIn); + declareProperty("ProcessSegments", m_segmentsIn); + declareProperty("WriteAssociatedHits", m_writeTgHits); + declareProperty("WriteAssociatedSegments", m_writeTgSegments); + declareProperty("InputSegmentCollection_Moore", m_inputSegmentCollectionMoore); + declareProperty("InputSegmentCollection_MoMu", m_inputSegmentCollectionMoMu); + declareProperty("InputSegmentCollection_MBoy", m_inputSegmentCollectionMBoy); + declareProperty("InputMdtPrdCollection", m_inputMdtPrdCollection); + declareProperty("InputRpcPrdCollection", m_inputRpcPrdCollection); + declareProperty("InputTgcPrdCollection", m_inputTgcPrdCollection); + declareProperty("InputCscPrdCollection", m_inputCscPrdCollection); + declareProperty("AlignMTG", m_reAlign); + declareProperty("MisAlignMTG", m_misAlign); + declareProperty("AllowGeometricalAssociation", m_allowGeomAssoc); } // Initialize method: -StatusCode Muon::MuonTGMeasAssocAlg::initialize() +StatusCode +Muon::MuonTGMeasAssocAlg::initialize() { - // Get the messaging service, print where you are - ATH_MSG_DEBUG("MuonTGMeasAssocAlg::initialize()"); - - ATH_CHECK(m_DetectorManagerKey.initialize()); - - // Get an Identifier helper object - ATH_CHECK(service("ActiveStoreSvc",m_activeStore)); - ATH_CHECK(m_idHelperSvc.retrieve()); - - // get muonTG tool - ATH_CHECK(m_muonTgTool.retrieve()); - // get extrapolator - ATH_CHECK(m_extrapolator.retrieve()); - - // initialize misalignment - if (m_misAlign) { - int station,eta,phi; - double x,y,z; - double rotX,rotY,rotZ; - std::ifstream misalign; - m_misAlignDiff.clear(); - misalign.open("MTGmisAlignment.txt",std::ios::in); - while (1) { - misalign >> station >> eta >> phi >> x >> y >> z >> rotX >> rotY >> rotZ; - if (!misalign.good()) break; - Identifier id(0); - if (station>=0) { - id = m_idHelperSvc->mdtIdHelper().elementID(station,eta,phi); - if (!m_idHelperSvc->mdtIdHelper().valid(id)) id = m_idHelperSvc->rpcIdHelper().elementID(station,eta,phi,1); - if (!m_idHelperSvc->rpcIdHelper().valid(id)) id = m_idHelperSvc->tgcIdHelper().elementID(station,eta,phi); - if (!m_idHelperSvc->tgcIdHelper().valid(id)) id = m_idHelperSvc->cscIdHelper().elementID(station,eta,phi); - } - Amg::Translation3D shift(x,y,z); - Amg::Transform3D transf = shift * Amg::RotationMatrix3D::Identity(); - transf *= Amg::AngleAxis3D(rotZ, Amg::Vector3D(0.,0.,1.)); - transf *= Amg::AngleAxis3D(rotY, Amg::Vector3D(0.,1.,0.)); - transf *= Amg::AngleAxis3D(rotX, Amg::Vector3D(1.,0.,0.)); - m_misAlignDiff.push_back(std::pair<Identifier,Amg::Transform3D>(id,transf)); + // Get the messaging service, print where you are + ATH_MSG_DEBUG("MuonTGMeasAssocAlg::initialize()"); + + ATH_CHECK(m_DetectorManagerKey.initialize()); + + // Get an Identifier helper object + ATH_CHECK(service("ActiveStoreSvc", m_activeStore)); + ATH_CHECK(m_idHelperSvc.retrieve()); + + // get muonTG tool + ATH_CHECK(m_muonTgTool.retrieve()); + // get extrapolator + ATH_CHECK(m_extrapolator.retrieve()); + + // initialize misalignment + if (m_misAlign) { + int station, eta, phi; + double x, y, z; + double rotX, rotY, rotZ; + std::ifstream misalign; + m_misAlignDiff.clear(); + misalign.open("MTGmisAlignment.txt", std::ios::in); + while (1) { + misalign >> station >> eta >> phi >> x >> y >> z >> rotX >> rotY >> rotZ; + if (!misalign.good()) break; + Identifier id(0); + if (station >= 0) { + id = m_idHelperSvc->mdtIdHelper().elementID(station, eta, phi); + if (!m_idHelperSvc->mdtIdHelper().valid(id)) + id = m_idHelperSvc->rpcIdHelper().elementID(station, eta, phi, 1); + if (!m_idHelperSvc->rpcIdHelper().valid(id)) + id = m_idHelperSvc->tgcIdHelper().elementID(station, eta, phi); + if (!m_idHelperSvc->tgcIdHelper().valid(id)) + id = m_idHelperSvc->cscIdHelper().elementID(station, eta, phi); + } + Amg::Translation3D shift(x, y, z); + Amg::Transform3D transf = shift * Amg::RotationMatrix3D::Identity(); + transf *= Amg::AngleAxis3D(rotZ, Amg::Vector3D(0., 0., 1.)); + transf *= Amg::AngleAxis3D(rotY, Amg::Vector3D(0., 1., 0.)); + transf *= Amg::AngleAxis3D(rotX, Amg::Vector3D(1., 0., 0.)); + m_misAlignDiff.push_back(std::pair<Identifier, Amg::Transform3D>(id, transf)); + } + misalign.close(); } - misalign.close(); - } - return StatusCode::SUCCESS; + return StatusCode::SUCCESS; } // Execute method: -StatusCode Muon::MuonTGMeasAssocAlg::execute() +StatusCode +Muon::MuonTGMeasAssocAlg::execute() { - // Get the messaging service, print where you are - ATH_MSG_INFO("MuonTGMeasAssocAlg::execute()"); - - SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey}; - const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr(); - if(MuonDetMgr==nullptr){ - ATH_MSG_ERROR("Null pointer to the read MuonDetectorManager conditions object"); - return StatusCode::FAILURE; - } - - StatusCode sc; - - if (!m_trackingGeometry) { - - ATH_CHECK(detStore()->retrieve(m_trackingGeometry, m_trackingGeometryName)); - ATH_MSG_DEBUG("tracking geometry Svc \""<<m_trackingGeometryName<<"\" booked "); - } - // create station map if not done already ; misalign stations if required - if (!m_stationMap.size()) { - const Trk::TrackingVolume* vol = m_trackingGeometry->highestTrackingVolume(); - ATH_MSG_INFO("creating station map "); - createStationMap(vol, MuonDetMgr); - ATH_MSG_INFO("station map created with "<<m_stationMap.size()<<" members "); - // pass the map to the MuonTGMeasurementTool - // if (m_muonTgTool) m_muonTgTool->getMuonStationMap(&m_stationMap); - // - if (m_misAlign) misAlignStations(); - } + // Get the messaging service, print where you are + ATH_MSG_INFO("MuonTGMeasAssocAlg::execute()"); + + SG::ReadCondHandle<MuonGM::MuonDetectorManager> DetectorManagerHandle{m_DetectorManagerKey}; + const MuonGM::MuonDetectorManager* MuonDetMgr = DetectorManagerHandle.cptr(); + if (MuonDetMgr == nullptr) { + ATH_MSG_ERROR("Null pointer to the read MuonDetectorManager conditions object"); + return StatusCode::FAILURE; + } + + StatusCode sc; + + if (!m_trackingGeometry) { + + ATH_CHECK(detStore()->retrieve(m_trackingGeometry, m_trackingGeometryName)); + ATH_MSG_DEBUG("tracking geometry Svc \"" << m_trackingGeometryName << "\" booked "); + } + // create station map if not done already ; misalign stations if required + if (!m_stationMap.size()) { + const Trk::TrackingVolume* vol = m_trackingGeometry->highestTrackingVolume(); + ATH_MSG_INFO("creating station map "); + createStationMap(vol, MuonDetMgr); + ATH_MSG_INFO("station map created with " << m_stationMap.size() << " members "); + // pass the map to the MuonTGMeasurementTool + // if (m_muonTgTool) m_muonTgTool->getMuonStationMap(&m_stationMap); + // + if (m_misAlign) misAlignStations(); + } - // realign - if (m_reAlign) reAlignStations(); + // realign + if (m_reAlign) reAlignStations(); - sc = retrieveMeasurements(MuonDetMgr); + sc = retrieveMeasurements(MuonDetMgr); - if ( !sc.isFailure() && m_writeTgHits ) sc = storeMeasurements(); + if (!sc.isFailure() && m_writeTgHits) sc = storeMeasurements(); - if ( m_segmentsIn ) { - sc = createStationSegmentCollection(MuonDetMgr); - if ( !sc.isFailure() && m_writeTgSegments ) sc = storeSegments(); - } + if (m_segmentsIn) { + sc = createStationSegmentCollection(MuonDetMgr); + if (!sc.isFailure() && m_writeTgSegments) sc = storeSegments(); + } - return StatusCode::SUCCESS; + return StatusCode::SUCCESS; } -StatusCode Muon::MuonTGMeasAssocAlg::storeMeasurements() { - // Get the messaging service, print where you are - ATH_MSG_DEBUG("MuonTGMeasAssocAlg::storeMeasurements()"); - // - StatusCode sc; - - if ( m_allHits ) { - std::string key = "MUON_TG_HITS"; - sc = evtStore()->record(m_allHits,key); - if (sc.isFailure()) { - ATH_MSG_ERROR("MuonTGMeasAssocAlg::storeMeasurements():recording of hit collection failed"); - } else { - ATH_MSG_INFO("MuonTGMeasAssocAlg:::storeMeasurements():MUON_TG_HITS recorded"); +StatusCode +Muon::MuonTGMeasAssocAlg::storeMeasurements() +{ + // Get the messaging service, print where you are + ATH_MSG_DEBUG("MuonTGMeasAssocAlg::storeMeasurements()"); + // + StatusCode sc; + + if (m_allHits) { + std::string key = "MUON_TG_HITS"; + sc = evtStore()->record(m_allHits, key); + if (sc.isFailure()) { + ATH_MSG_ERROR("MuonTGMeasAssocAlg::storeMeasurements():recording of hit collection failed"); + } else { + ATH_MSG_INFO("MuonTGMeasAssocAlg:::storeMeasurements():MUON_TG_HITS recorded"); + } } - } - - return StatusCode::SUCCESS; - } - -StatusCode Muon::MuonTGMeasAssocAlg::storeSegments() { - // Get the messaging service, print where you are - ATH_MSG_DEBUG("MuonTGMeasAssocAlg::storeSegments()"); - // - StatusCode sc; - - if ( m_allSegments ) { - std::string key = "MUON_TG_SEGMENTS"; - sc = evtStore()->record(m_allSegments,key); - if (sc.isFailure()) { - ATH_MSG_ERROR("MuonTGMeasAssocAlg::storeSegments():recording of segment collection failed"); - } else { - ATH_MSG_INFO("MuonTGMeasAssocAlg:::storeSegments():MUON_TG_SEGMENTS recorded"); + + return StatusCode::SUCCESS; +} + +StatusCode +Muon::MuonTGMeasAssocAlg::storeSegments() +{ + // Get the messaging service, print where you are + ATH_MSG_DEBUG("MuonTGMeasAssocAlg::storeSegments()"); + // + StatusCode sc; + + if (m_allSegments) { + std::string key = "MUON_TG_SEGMENTS"; + sc = evtStore()->record(m_allSegments, key); + if (sc.isFailure()) { + ATH_MSG_ERROR("MuonTGMeasAssocAlg::storeSegments():recording of segment collection failed"); + } else { + ATH_MSG_INFO("MuonTGMeasAssocAlg:::storeSegments():MUON_TG_SEGMENTS recorded"); + } } - } - return StatusCode::SUCCESS; - } + return StatusCode::SUCCESS; +} - StatusCode Muon::MuonTGMeasAssocAlg::createStationHitCollection() const +StatusCode +Muon::MuonTGMeasAssocAlg::createStationHitCollection() const { - // Get the messaging service, print where you are - ATH_MSG_DEBUG("MuonTGMeasAssocAlg::createStationHitCollection()" ); - - StatusCode sc; - - //Define the pair and the vector of pairs - m_allHits = new MuonTGHits; - - if (m_mdtIn && m_mdtHits) { - for (unsigned int il=0; il<m_mdtHits->size();il++) { - const Trk::DetachedTrackingVolume* station = (*m_mdtHits)[il]->first->enclosingDetachedTrackingVolume(); - if (station) { - bool found=false; - unsigned int ist = 0; - while ( !found && m_allHits->size()>0 && ist < m_allHits->size() ) { - if (station == (*m_allHits)[ist]->first ) { - (*m_allHits)[ist]->second->push_back((*m_mdtHits)[il]); - found = true; - } - ist++; - } - if (!found) { - std::vector<PairOfLayerPrd*>* layPrd= new std::vector<PairOfLayerPrd*>; - layPrd->push_back((*m_mdtHits)[il]); - m_allHits->push_back(new Muon::StationPrd(station,layPrd)); - } - } + // Get the messaging service, print where you are + ATH_MSG_DEBUG("MuonTGMeasAssocAlg::createStationHitCollection()"); + + StatusCode sc; + + // Define the pair and the vector of pairs + m_allHits = new MuonTGHits; + + if (m_mdtIn && m_mdtHits) { + for (unsigned int il = 0; il < m_mdtHits->size(); il++) { + const Trk::DetachedTrackingVolume* station = (*m_mdtHits)[il]->first->enclosingDetachedTrackingVolume(); + if (station) { + bool found = false; + unsigned int ist = 0; + while (!found && m_allHits->size() > 0 && ist < m_allHits->size()) { + if (station == (*m_allHits)[ist]->first) { + (*m_allHits)[ist]->second->push_back((*m_mdtHits)[il]); + found = true; + } + ist++; + } + if (!found) { + std::vector<PairOfLayerPrd*>* layPrd = new std::vector<PairOfLayerPrd*>; + layPrd->push_back((*m_mdtHits)[il]); + m_allHits->push_back(new Muon::StationPrd(station, layPrd)); + } + } + } } - } - - if (m_rpcIn && m_rpcHits) { - for (unsigned int il=0; il<m_rpcHits->size();il++) { - const Trk::DetachedTrackingVolume* station = (*m_rpcHits)[il]->first->enclosingDetachedTrackingVolume(); - if (station) { - bool found=false; - unsigned int ist = 0; - while ( !found && ist < m_allHits->size() ) { - if (station == (*m_allHits)[ist]->first ) { - (*m_allHits)[ist]->second->push_back((*m_rpcHits)[il]); - found = true; - } - ist++; - } - if (!found) { - std::vector<PairOfLayerPrd*>* layPrd=new std::vector<PairOfLayerPrd*>; - layPrd->push_back((*m_rpcHits)[il]); - m_allHits->push_back(new Muon::StationPrd(station,layPrd)); - } - } + + if (m_rpcIn && m_rpcHits) { + for (unsigned int il = 0; il < m_rpcHits->size(); il++) { + const Trk::DetachedTrackingVolume* station = (*m_rpcHits)[il]->first->enclosingDetachedTrackingVolume(); + if (station) { + bool found = false; + unsigned int ist = 0; + while (!found && ist < m_allHits->size()) { + if (station == (*m_allHits)[ist]->first) { + (*m_allHits)[ist]->second->push_back((*m_rpcHits)[il]); + found = true; + } + ist++; + } + if (!found) { + std::vector<PairOfLayerPrd*>* layPrd = new std::vector<PairOfLayerPrd*>; + layPrd->push_back((*m_rpcHits)[il]); + m_allHits->push_back(new Muon::StationPrd(station, layPrd)); + } + } + } } - } - - if (m_tgcIn && m_tgcHits) { - for (unsigned int il=0; il<m_tgcHits->size();il++) { - const Trk::DetachedTrackingVolume* station = (*m_tgcHits)[il]->first->enclosingDetachedTrackingVolume(); - if (station) { - bool found=false; - unsigned int ist = 0; - while ( !found && ist < m_allHits->size() ) { - if (station == (*m_allHits)[ist]->first ) { - (*m_allHits)[ist]->second->push_back((*m_tgcHits)[il]); - found = true; - } - ist++; + + if (m_tgcIn && m_tgcHits) { + for (unsigned int il = 0; il < m_tgcHits->size(); il++) { + const Trk::DetachedTrackingVolume* station = (*m_tgcHits)[il]->first->enclosingDetachedTrackingVolume(); + if (station) { + bool found = false; + unsigned int ist = 0; + while (!found && ist < m_allHits->size()) { + if (station == (*m_allHits)[ist]->first) { + (*m_allHits)[ist]->second->push_back((*m_tgcHits)[il]); + found = true; + } + ist++; + } + if (!found) { + std::vector<PairOfLayerPrd*>* layPrd = new std::vector<PairOfLayerPrd*>; + layPrd->push_back((*m_tgcHits)[il]); + m_allHits->push_back(new Muon::StationPrd(station, layPrd)); + } + } } - if (!found) { - std::vector<PairOfLayerPrd*>* layPrd=new std::vector<PairOfLayerPrd*>; - layPrd->push_back((*m_tgcHits)[il]); - m_allHits->push_back(new Muon::StationPrd(station,layPrd)); - } - } } - } - - if (m_cscIn && m_cscHits) { - for (unsigned int il=0; il<m_cscHits->size();il++) { - const Trk::DetachedTrackingVolume* station = (*m_cscHits)[il]->first->enclosingDetachedTrackingVolume(); - if (station) { - bool found=false; - unsigned int ist = 0; - while ( !found && ist < m_allHits->size() ) { - if (station == (*m_allHits)[ist]->first ) { - (*m_allHits)[ist]->second->push_back((*m_cscHits)[il]); - found = true; - } - ist++; - } - if (!found) { - std::vector<PairOfLayerPrd*>* layPrd=new std::vector<PairOfLayerPrd*>; - layPrd->push_back((*m_cscHits)[il]); - m_allHits->push_back(new Muon::StationPrd(station,layPrd)); - } - } + + if (m_cscIn && m_cscHits) { + for (unsigned int il = 0; il < m_cscHits->size(); il++) { + const Trk::DetachedTrackingVolume* station = (*m_cscHits)[il]->first->enclosingDetachedTrackingVolume(); + if (station) { + bool found = false; + unsigned int ist = 0; + while (!found && ist < m_allHits->size()) { + if (station == (*m_allHits)[ist]->first) { + (*m_allHits)[ist]->second->push_back((*m_cscHits)[il]); + found = true; + } + ist++; + } + if (!found) { + std::vector<PairOfLayerPrd*>* layPrd = new std::vector<PairOfLayerPrd*>; + layPrd->push_back((*m_cscHits)[il]); + m_allHits->push_back(new Muon::StationPrd(station, layPrd)); + } + } + } } - } - return StatusCode::SUCCESS; - + return StatusCode::SUCCESS; } - StatusCode Muon::MuonTGMeasAssocAlg::createStationSegmentCollection(const MuonGM::MuonDetectorManager* MuonDetMgr) const +StatusCode +Muon::MuonTGMeasAssocAlg::createStationSegmentCollection(const MuonGM::MuonDetectorManager* MuonDetMgr) const { - // Get the messaging service, print where you are - ATH_MSG_DEBUG("MuonTGMeasAssocAlg::createStationSegmentCollection()" ); - - StatusCode sc; - - //Define the pair and the vector of pairs - m_allSegments = 0; - - // retrieve input segments - std::vector<const Trk::SegmentCollection*> segmColls; - if (m_inputSegmentCollectionMoore != "") { - const Trk::SegmentCollection* mooreColl = 0; - sc = evtStore()->retrieve(mooreColl, m_inputSegmentCollectionMoore ); - if (!sc.isFailure()) { - ATH_MSG_INFO(" retrieved segment collection " << m_inputSegmentCollectionMoore ); - segmColls.push_back(mooreColl); - } else { - ATH_MSG_INFO(" failed to retrieve segment collection " << m_inputSegmentCollectionMoore ); - return sc; + // Get the messaging service, print where you are + ATH_MSG_DEBUG("MuonTGMeasAssocAlg::createStationSegmentCollection()"); + + StatusCode sc; + + // Define the pair and the vector of pairs + m_allSegments = 0; + + // retrieve input segments + std::vector<const Trk::SegmentCollection*> segmColls; + if (m_inputSegmentCollectionMoore != "") { + const Trk::SegmentCollection* mooreColl = 0; + sc = evtStore()->retrieve(mooreColl, m_inputSegmentCollectionMoore); + if (!sc.isFailure()) { + ATH_MSG_INFO(" retrieved segment collection " << m_inputSegmentCollectionMoore); + segmColls.push_back(mooreColl); + } else { + ATH_MSG_INFO(" failed to retrieve segment collection " << m_inputSegmentCollectionMoore); + return sc; + } } - } - if (m_inputSegmentCollectionMoMu != "") { - const Trk::SegmentCollection* momuColl = 0; - sc = evtStore()->retrieve(momuColl, m_inputSegmentCollectionMoMu ); - if (!sc.isFailure()) { - ATH_MSG_INFO(" retrieved segment collection " << m_inputSegmentCollectionMoMu ); - segmColls.push_back(momuColl); - } else { - ATH_MSG_INFO(" failed to retrieve segment collection " << m_inputSegmentCollectionMoMu ); - return sc; + if (m_inputSegmentCollectionMoMu != "") { + const Trk::SegmentCollection* momuColl = 0; + sc = evtStore()->retrieve(momuColl, m_inputSegmentCollectionMoMu); + if (!sc.isFailure()) { + ATH_MSG_INFO(" retrieved segment collection " << m_inputSegmentCollectionMoMu); + segmColls.push_back(momuColl); + } else { + ATH_MSG_INFO(" failed to retrieve segment collection " << m_inputSegmentCollectionMoMu); + return sc; + } } - } - if (m_inputSegmentCollectionMBoy != "") { - const Trk::SegmentCollection* mboyColl = 0; - sc = evtStore()->retrieve(mboyColl, m_inputSegmentCollectionMBoy ); - if (!sc.isFailure()) { - ATH_MSG_INFO(" retrieved segment collection " << m_inputSegmentCollectionMBoy ); - segmColls.push_back(mboyColl); - } else { - ATH_MSG_INFO(" failed to retrieve segment collection " << m_inputSegmentCollectionMBoy ); - return sc; + if (m_inputSegmentCollectionMBoy != "") { + const Trk::SegmentCollection* mboyColl = 0; + sc = evtStore()->retrieve(mboyColl, m_inputSegmentCollectionMBoy); + if (!sc.isFailure()) { + ATH_MSG_INFO(" retrieved segment collection " << m_inputSegmentCollectionMBoy); + segmColls.push_back(mboyColl); + } else { + ATH_MSG_INFO(" failed to retrieve segment collection " << m_inputSegmentCollectionMBoy); + return sc; + } + } + + if (!segmColls.size()) return StatusCode::FAILURE; + + m_allSegments = new MuonTGSegments; + + for (unsigned int ic = 0; ic < segmColls.size(); ic++) { + const Trk::SegmentCollection* segmColl = segmColls[ic]; + for (Trk::SegmentCollection::const_iterator iter = segmColl->begin(); iter != segmColl->end(); ++iter) { + const MuonSegment* segment = dynamic_cast<const MuonSegment*>(*iter); + // std::cout << "segment:" << segment << "," << segmColl->size() <<"," << segment->globalPosition()<< + // std::endl; + if (segment) { + // retrieve station + const Trk::DetachedTrackingVolume* detVol = 0; + const std::vector<const Trk::DetachedTrackingVolume*>* detVols = + m_trackingGeometry->lowestDetachedTrackingVolumes(segment->globalPosition()); + if (detVols) { + if (detVols->size() > 1) ATH_MSG_INFO("station overlaps ? "); + if (detVols->size()) detVol = detVols->front(); + if (!detVols->size()) { + ATH_MSG_ERROR("missing station?" << segment->globalPosition()); + std::vector<const Trk::RIO_OnTrack*> rots; + for (unsigned int irot = 0; irot < segment->numberOfContainedROTs(); irot++) + rots.push_back(segment->rioOnTrack(irot)); + if (rots.size() > 0) { + Identifier id = rots[0]->identify(); + Amg::Vector3D pos(0., 0., 0.); + if (m_idHelperSvc->isMdt(id)) { + const MuonGM::MdtReadoutElement* mdtROE = MuonDetMgr->getMdtReadoutElement(id); + pos = mdtROE->tubePos(id); + } else if (m_idHelperSvc->isRpc(id)) { + const MuonGM::RpcReadoutElement* rpcROE = MuonDetMgr->getRpcReadoutElement(id); + pos = rpcROE->stripPos(id); + } else if (m_idHelperSvc->isCsc(id)) { + const MuonGM::CscReadoutElement* cscROE = MuonDetMgr->getCscReadoutElement(id); + pos = cscROE->stripPos(id); + } else if (m_idHelperSvc->isTgc(id)) { + const MuonGM::TgcReadoutElement* tgcROE = MuonDetMgr->getTgcReadoutElement(id); + pos = tgcROE->channelPos(id); + } + const Trk::Layer* lay = m_trackingGeometry->associatedLayer(pos); + if (lay) detVol = lay->enclosingDetachedTrackingVolume(); + if (detVol) ATH_MSG_DEBUG(" enclosing detached volume retrieved:" << detVol->name()); + } + } + } + if (detVol) { + // extrapolate segment to station layer representation + // avoid propagation of error matrix for the moment + // const Trk::MeasuredAtaPlane + // segmPar(segment->globalPosition(),10000.*segment->globalDirection(),1., + // segment->associatedSurface(), new + //Trk::ErrorMatrix(segment->localErrorMatrix())); + const Trk::AtaPlane segmPar(segment->globalPosition(), 10000. * segment->globalDirection(), 1., + segment->associatedSurface()); + const Trk::TrackParameters* layPar = m_extrapolator->extrapolateDirectly( + segmPar, detVol->layerRepresentation()->surfaceRepresentation(), Trk::anyDirection, true, + Trk::muon); + // copy segment info + if (layPar) { + const Trk::PlaneSurface* plane = dynamic_cast<const Trk::PlaneSurface*>( + &(detVol->layerRepresentation()->surfaceRepresentation())); + // std::cout <<"error matrix, fit + // quality:"<<&(segment->localErrorMatrix())<<","<<segment->fitQuality()<<std::endl; const + // Trk::MeasuredAtaPlane* mLayPar = dynamic_cast<const Trk::MeasuredAtaPlane*> (layPar); const + // MuonSegment* assocSegm = new MuonSegment( layPar->localPosition(), new + //Trk::LocalDirection(layPar->momentum().unit(),detVol->layerRepresentation() + // ->surfaceRepresentation().transform().getRotation() + // ), + // &(mLayPar->localErrorMatrix()), new + //Trk::PlaneSurface(*plane), new std::vector<const Trk::RIO_OnTrack*>(segment->containedROTs()), + // new Trk::FitQuality( *(segment->fitQuality())) + //); + DataVector<const Trk::MeasurementBase>* meas = new DataVector<const Trk::MeasurementBase>; + for (unsigned int irot = 0; irot < segment->numberOfContainedROTs(); irot++) + meas->push_back(segment->rioOnTrack(irot)); + + Trk::LocalDirection dir; + plane->globalToLocalDirection(layPar->momentum(), dir); + const MuonSegment* assocSegm = new MuonSegment( + layPar->localPosition(), dir, segment->localCovariance(), new Trk::PlaneSurface(*plane), + meas, new Trk::FitQuality(*(segment->fitQuality())), segment->author()); + // association + if (assocSegm) { + bool found = false; + unsigned int ist = 0; + while (!found && ist < m_allSegments->size()) { + if (detVol == (*m_allSegments)[ist]->first) { + (*m_allSegments)[ist]->second->push_back(assocSegm); + found = true; + } + ist++; + } + if (!found) { + std::vector<const Trk::Segment*>* laySeg = new std::vector<const Trk::Segment*>; + laySeg->push_back(assocSegm); + StationSgs* assocPair = new StationSgs(detVol, laySeg); + m_allSegments->push_back(assocPair); + } + } + } + } + } + } } - } - - if (!segmColls.size()) return StatusCode::FAILURE; - - m_allSegments = new MuonTGSegments; - - for (unsigned int ic=0; ic<segmColls.size(); ic++) { - const Trk::SegmentCollection* segmColl = segmColls[ic]; - for (Trk::SegmentCollection::const_iterator iter = segmColl->begin(); iter!=segmColl->end(); ++iter) { - const MuonSegment* segment = dynamic_cast<const MuonSegment*> (*iter); - //std::cout << "segment:" << segment << "," << segmColl->size() <<"," << segment->globalPosition()<< std::endl; - if (segment) { - // retrieve station - const Trk::DetachedTrackingVolume* detVol = 0; - const std::vector<const Trk::DetachedTrackingVolume*>* - detVols = m_trackingGeometry->lowestDetachedTrackingVolumes(segment->globalPosition()); - if (detVols) { - if (detVols->size() > 1) ATH_MSG_INFO( "station overlaps ? " ); - if (detVols->size() ) detVol = detVols->front(); - if (!detVols->size() ) { - ATH_MSG_ERROR( "missing station?" << segment->globalPosition() ); - std::vector<const Trk::RIO_OnTrack*> rots; - for(unsigned int irot=0;irot<segment->numberOfContainedROTs();irot++) rots.push_back(segment->rioOnTrack(irot)); - if ( rots.size() > 0 ) { - Identifier id = rots[0]->identify(); - Amg::Vector3D pos(0., 0., 0.); - if (m_idHelperSvc->isMdt(id)) { - const MuonGM::MdtReadoutElement* mdtROE = MuonDetMgr->getMdtReadoutElement(id); - pos = mdtROE->tubePos(id); - } else if ( m_idHelperSvc->isRpc(id)) { - const MuonGM::RpcReadoutElement* rpcROE = MuonDetMgr->getRpcReadoutElement(id); - pos = rpcROE->stripPos(id); - } else if ( m_idHelperSvc->isCsc(id)) { - const MuonGM::CscReadoutElement* cscROE = MuonDetMgr->getCscReadoutElement(id); - pos = cscROE->stripPos(id); - } else if ( m_idHelperSvc->isTgc(id)) { - const MuonGM::TgcReadoutElement* tgcROE = MuonDetMgr->getTgcReadoutElement(id); - pos = tgcROE->channelPos(id); - } - const Trk::Layer* lay = m_trackingGeometry->associatedLayer(pos); - if (lay) detVol = lay->enclosingDetachedTrackingVolume(); - if (detVol) ATH_MSG_DEBUG(" enclosing detached volume retrieved:" << detVol->name() ); - } - } - } - if (detVol) { - // extrapolate segment to station layer representation - // avoid propagation of error matrix for the moment - //const Trk::MeasuredAtaPlane segmPar(segment->globalPosition(),10000.*segment->globalDirection(),1., - // segment->associatedSurface(), new Trk::ErrorMatrix(segment->localErrorMatrix())); - const Trk::AtaPlane segmPar(segment->globalPosition(),10000.*segment->globalDirection(),1., segment->associatedSurface()); - const Trk::TrackParameters* layPar = m_extrapolator->extrapolateDirectly(segmPar, - detVol->layerRepresentation()->surfaceRepresentation(), - Trk::anyDirection, true, Trk::muon); - // copy segment info - if (layPar) { - const Trk::PlaneSurface* plane = dynamic_cast<const Trk::PlaneSurface*> (&(detVol->layerRepresentation()->surfaceRepresentation())); - //std::cout <<"error matrix, fit quality:"<<&(segment->localErrorMatrix())<<","<<segment->fitQuality()<<std::endl; - //const Trk::MeasuredAtaPlane* mLayPar = dynamic_cast<const Trk::MeasuredAtaPlane*> (layPar); - //const MuonSegment* assocSegm = new MuonSegment( layPar->localPosition(), - // new Trk::LocalDirection(layPar->momentum().unit(),detVol->layerRepresentation() - // ->surfaceRepresentation().transform().getRotation() ), - // &(mLayPar->localErrorMatrix()), new Trk::PlaneSurface(*plane), - // new std::vector<const Trk::RIO_OnTrack*>(segment->containedROTs()), - // new Trk::FitQuality( *(segment->fitQuality())) ); - DataVector<const Trk::MeasurementBase>* meas= new DataVector<const Trk::MeasurementBase>; - for(unsigned int irot=0;irot<segment->numberOfContainedROTs();irot++) meas->push_back(segment->rioOnTrack(irot)); - - Trk::LocalDirection dir; - plane->globalToLocalDirection(layPar->momentum(),dir); - const MuonSegment* assocSegm = new MuonSegment( layPar->localPosition(), - dir, - segment->localCovariance(), new Trk::PlaneSurface(*plane), - meas, - new Trk::FitQuality( *(segment->fitQuality())), - segment->author() ); - // association - if (assocSegm) { - bool found=false; - unsigned int ist = 0; - while ( !found && ist < m_allSegments->size() ) { - if (detVol == (*m_allSegments)[ist]->first ) { - (*m_allSegments)[ist]->second->push_back(assocSegm); - found = true; - } - ist++; - } - if (!found) { - std::vector<const Trk::Segment*>* laySeg=new std::vector<const Trk::Segment*>; - laySeg->push_back(assocSegm); - StationSgs* assocPair = new StationSgs(detVol,laySeg); - m_allSegments->push_back(assocPair); - } - } - } - } - } - } - } - return StatusCode::SUCCESS; - + return StatusCode::SUCCESS; } -std::vector<std::pair<const Trk::Layer*,std::vector<const Trk::PrepRawData*>*>*>* +std::vector<std::pair<const Trk::Layer*, std::vector<const Trk::PrepRawData*>*>*>* Muon::MuonTGMeasAssocAlg::createMdtHitCollectionLayers(const MuonGM::MuonDetectorManager* MuonDetMgr) const { - // Get the messaging service, print where you are - ATH_MSG_DEBUG( "MuonTGMeasAssocAlg::createHitCollectionLayers()" ); - - StatusCode sc; - - //Define the pair and the vector of pairs - std::vector<PairOfLayerPrd*>* vec_alllayer = new std::vector<PairOfLayerPrd*>; - - int layerid=0; - - //Try to retrieve the MDT hit collection - const Muon::MdtPrepDataContainer* mdt_container; - StatusCode sc_read = evtStore()->retrieve(mdt_container, m_inputMdtPrdCollection); - if (sc_read.isFailure()) { - ATH_MSG_ERROR( " Cannot retrieve MDT PrepData Container " ); - delete vec_alllayer; - return NULL; - } - - const DataHandle<Muon::MdtPrepDataCollection> mdtCollection; - const DataHandle<Muon::MdtPrepDataCollection> lastColl; - - if (evtStore()->retrieve(mdtCollection,lastColl) ==StatusCode::SUCCESS) { - for ( ; mdtCollection != lastColl ; ++mdtCollection ) { - if (mdtCollection->size()>0) { - for (Muon::MdtPrepDataCollection::const_iterator mdtPrd = mdtCollection->begin(); - mdtPrd != mdtCollection->end(); ++mdtPrd) { - - Identifier dig_id = (*mdtPrd)->identify(); - - const Trk::Layer* layer = associatedLayer(0,dig_id,MuonDetMgr); - - if (!layer) { - ATH_MSG_ERROR( "MuonTGMeasAssocAlg::No layer associated with this MDT hit! (digit = " << dig_id << ")" ); - ATH_MSG_ERROR( "station name,eta,phi" << m_idHelperSvc->mdtIdHelper().stationName(dig_id) << "," - << m_idHelperSvc->mdtIdHelper().stationEta(dig_id) << "," - << m_idHelperSvc->mdtIdHelper().stationPhi(dig_id) ); - ATH_MSG_ERROR( "multilayer,layer,tube:" << m_idHelperSvc->mdtIdHelper().multilayer(dig_id) << "," << - m_idHelperSvc->mdtIdHelper().tubeLayer(dig_id) <<"," << - m_idHelperSvc->mdtIdHelper().tube(dig_id) ); - continue; - } - - layerid = layer->layerType(); - - //Check if the layer the hit is on already exists in the layer collection - bool stored = false; - std::vector<PairOfLayerPrd*>::const_iterator itr = vec_alllayer->begin(); - for (; itr != vec_alllayer->end(); ++itr) { - //Compare the pointers - if ((*itr)->first->layerType() == layerid) - { - if (stored) - ATH_MSG_WARNING( " Hit on two different layers! " ); - stored = true; - //Add the hit to the layer, order hits by tube number - std::vector<const Trk::PrepRawData*>::iterator piter = (*itr)->second->begin(); - while ( piter !=(*itr)->second->end() - && m_idHelperSvc->mdtIdHelper().tube(dig_id)> m_idHelperSvc->mdtIdHelper().tube((*piter)->identify()) ) piter++; - (*itr)->second->insert(piter,*mdtPrd); - } - } - - //If it didn't exist, add a new pair to the layer collection - if (!stored) { - //Create a vector with the ID - std::vector<const Trk::PrepRawData*>* prd = new std::vector<const Trk::PrepRawData*>; - prd->push_back(*mdtPrd); - - //Create a new pair of Layer and PRD vector - PairOfLayerPrd* pair_layerhits = new PairOfLayerPrd(layer,prd); - vec_alllayer->push_back(pair_layerhits); - } - } - } + // Get the messaging service, print where you are + ATH_MSG_DEBUG("MuonTGMeasAssocAlg::createHitCollectionLayers()"); + + StatusCode sc; + + // Define the pair and the vector of pairs + std::vector<PairOfLayerPrd*>* vec_alllayer = new std::vector<PairOfLayerPrd*>; + + int layerid = 0; + + // Try to retrieve the MDT hit collection + const Muon::MdtPrepDataContainer* mdt_container; + StatusCode sc_read = evtStore()->retrieve(mdt_container, m_inputMdtPrdCollection); + if (sc_read.isFailure()) { + ATH_MSG_ERROR(" Cannot retrieve MDT PrepData Container "); + delete vec_alllayer; + return NULL; + } + + const DataHandle<Muon::MdtPrepDataCollection> mdtCollection; + const DataHandle<Muon::MdtPrepDataCollection> lastColl; + + if (evtStore()->retrieve(mdtCollection, lastColl) == StatusCode::SUCCESS) { + for (; mdtCollection != lastColl; ++mdtCollection) { + if (mdtCollection->size() > 0) { + for (Muon::MdtPrepDataCollection::const_iterator mdtPrd = mdtCollection->begin(); + mdtPrd != mdtCollection->end(); ++mdtPrd) + { + + Identifier dig_id = (*mdtPrd)->identify(); + + const Trk::Layer* layer = associatedLayer(0, dig_id, MuonDetMgr); + + if (!layer) { + ATH_MSG_ERROR("MuonTGMeasAssocAlg::No layer associated with this MDT hit! (digit = " << dig_id + << ")"); + ATH_MSG_ERROR("station name,eta,phi" << m_idHelperSvc->mdtIdHelper().stationName(dig_id) << "," + << m_idHelperSvc->mdtIdHelper().stationEta(dig_id) << "," + << m_idHelperSvc->mdtIdHelper().stationPhi(dig_id)); + ATH_MSG_ERROR("multilayer,layer,tube:" << m_idHelperSvc->mdtIdHelper().multilayer(dig_id) << "," + << m_idHelperSvc->mdtIdHelper().tubeLayer(dig_id) << "," + << m_idHelperSvc->mdtIdHelper().tube(dig_id)); + continue; + } + + layerid = layer->layerType(); + + // Check if the layer the hit is on already exists in the layer collection + bool stored = false; + std::vector<PairOfLayerPrd*>::const_iterator itr = vec_alllayer->begin(); + for (; itr != vec_alllayer->end(); ++itr) { + // Compare the pointers + if ((*itr)->first->layerType() == layerid) { + if (stored) ATH_MSG_WARNING(" Hit on two different layers! "); + stored = true; + // Add the hit to the layer, order hits by tube number + std::vector<const Trk::PrepRawData*>::iterator piter = (*itr)->second->begin(); + while (piter != (*itr)->second->end() + && m_idHelperSvc->mdtIdHelper().tube(dig_id) + > m_idHelperSvc->mdtIdHelper().tube((*piter)->identify())) + piter++; + (*itr)->second->insert(piter, *mdtPrd); + } + } + + // If it didn't exist, add a new pair to the layer collection + if (!stored) { + // Create a vector with the ID + std::vector<const Trk::PrepRawData*>* prd = new std::vector<const Trk::PrepRawData*>; + prd->push_back(*mdtPrd); + + // Create a new pair of Layer and PRD vector + PairOfLayerPrd* pair_layerhits = new PairOfLayerPrd(layer, prd); + vec_alllayer->push_back(pair_layerhits); + } + } + } + } } - } - //Return the object - ATH_MSG_DEBUG( "MuonTGMeasAssocAlg::createMdtHitCollectionLayers() returns " << vec_alllayer->size() ); - return vec_alllayer; + // Return the object + ATH_MSG_DEBUG("MuonTGMeasAssocAlg::createMdtHitCollectionLayers() returns " << vec_alllayer->size()); + return vec_alllayer; } -std::vector<std::pair<const Trk::Layer*,std::vector<const Trk::PrepRawData*>*>*>* +std::vector<std::pair<const Trk::Layer*, std::vector<const Trk::PrepRawData*>*>*>* Muon::MuonTGMeasAssocAlg::createRpcHitCollectionLayers(const MuonGM::MuonDetectorManager* MuonDetMgr) const { - // Get the messaging service, print where you are - ATH_MSG_DEBUG( "MuonTGMeasAssocAlg::createRpcHitCollectionLayers()" ); - - StatusCode sc; - - //Define the pair and the vector of pairs - std::vector<PairOfLayerPrd*>* vec_alllayer = 0; - - //Try to retrieve the RPC hit collection - const Muon::RpcPrepDataContainer* rpc_container; - StatusCode sc_read = evtStore()->retrieve(rpc_container, m_inputRpcPrdCollection); - if (sc_read.isFailure()) { - ATH_MSG_ERROR( " Cannot retrieve RPC PrepData Container " ); - return vec_alllayer; - } - - const DataHandle<Muon::RpcPrepDataCollection> rpcCollection; - const DataHandle<Muon::RpcPrepDataCollection> lastColl; - - vec_alllayer = new std::vector<PairOfLayerPrd*>; - - int layerid; - - if (evtStore()->retrieve(rpcCollection,lastColl) ==StatusCode::SUCCESS) { - for ( ; rpcCollection != lastColl ; ++rpcCollection ) { - if (rpcCollection->size()>0) { - for (Muon::RpcPrepDataCollection::const_iterator rpcPrd = rpcCollection->begin(); - rpcPrd != rpcCollection->end(); ++rpcPrd) { - - Identifier dig_id = (*rpcPrd)->identify(); - - const Trk::Layer* layer = associatedLayer(1,dig_id,MuonDetMgr); - - if (!layer) { - ATH_MSG_ERROR( " No layer associated with this RPC hit! (digit = " << dig_id << ")" ); - ATH_MSG_ERROR( "station name,eta,phi" << m_idHelperSvc->rpcIdHelper().stationName(dig_id) << "," - << m_idHelperSvc->rpcIdHelper().stationEta(dig_id) << "," - << m_idHelperSvc->rpcIdHelper().stationPhi(dig_id) ); - ATH_MSG_ERROR( "doubletR,doubletZ,doubletPhi,gasGap:"<<m_idHelperSvc->rpcIdHelper().doubletR(dig_id)<<","<< - m_idHelperSvc->rpcIdHelper().doubletZ(dig_id)<<","<< - m_idHelperSvc->rpcIdHelper().doubletPhi(dig_id) << ","<< - m_idHelperSvc->rpcIdHelper().gasGap(dig_id)); - ATH_MSG_ERROR( "measuresPhi:"<<m_idHelperSvc->rpcIdHelper().measuresPhi(dig_id)); - continue; - } - - layerid = layer->layerType(); - - //Check if the layer the hit is on already exists in the layer collection and if the hit is a new hit - bool stored = false; - bool digstored = false; - std::vector<PairOfLayerPrd*>::const_iterator itr = vec_alllayer->begin(); - std::vector<const Trk::PrepRawData*>::const_iterator digitr; - for (; itr != vec_alllayer->end(); ++itr) { - - //Check for equivalent hits in the collection - for (digitr = (*itr)->second->begin(); digitr != (*itr)->second->end();++digitr) { - //Compare the found hit to the new hit - if ((*rpcPrd) == (*digitr)) { - stored = true; - digstored = true; - break; - } - } - //Stop the process if the digit is not unique - if (digstored) { - break; - } - - //Compare the pointers of the layers - if ((*itr)->first->layerType() == layerid) { - if (stored) - ATH_MSG_WARNING( " Hit on two different layers! " ); - stored = true; - //Add the hit to the layer - (*itr)->second->push_back(*rpcPrd); - } - } - - //If it didn't exist, add a new pair to the layer collection - if (!stored) { - //Create a vector with the ID - std::vector<const Trk::PrepRawData*>* vec_id = new std::vector<const Trk::PrepRawData*>; - vec_id->push_back(*rpcPrd); - - //Create a new pair of Layer and ID vector - PairOfLayerPrd* pair_layerhits = new PairOfLayerPrd(layer,vec_id); - vec_alllayer->push_back(pair_layerhits); - } - } - } + // Get the messaging service, print where you are + ATH_MSG_DEBUG("MuonTGMeasAssocAlg::createRpcHitCollectionLayers()"); + + StatusCode sc; + + // Define the pair and the vector of pairs + std::vector<PairOfLayerPrd*>* vec_alllayer = 0; + + // Try to retrieve the RPC hit collection + const Muon::RpcPrepDataContainer* rpc_container; + StatusCode sc_read = evtStore()->retrieve(rpc_container, m_inputRpcPrdCollection); + if (sc_read.isFailure()) { + ATH_MSG_ERROR(" Cannot retrieve RPC PrepData Container "); + return vec_alllayer; + } + + const DataHandle<Muon::RpcPrepDataCollection> rpcCollection; + const DataHandle<Muon::RpcPrepDataCollection> lastColl; + + vec_alllayer = new std::vector<PairOfLayerPrd*>; + + int layerid; + + if (evtStore()->retrieve(rpcCollection, lastColl) == StatusCode::SUCCESS) { + for (; rpcCollection != lastColl; ++rpcCollection) { + if (rpcCollection->size() > 0) { + for (Muon::RpcPrepDataCollection::const_iterator rpcPrd = rpcCollection->begin(); + rpcPrd != rpcCollection->end(); ++rpcPrd) + { + + Identifier dig_id = (*rpcPrd)->identify(); + + const Trk::Layer* layer = associatedLayer(1, dig_id, MuonDetMgr); + + if (!layer) { + ATH_MSG_ERROR(" No layer associated with this RPC hit! (digit = " << dig_id << ")"); + ATH_MSG_ERROR("station name,eta,phi" << m_idHelperSvc->rpcIdHelper().stationName(dig_id) << "," + << m_idHelperSvc->rpcIdHelper().stationEta(dig_id) << "," + << m_idHelperSvc->rpcIdHelper().stationPhi(dig_id)); + ATH_MSG_ERROR("doubletR,doubletZ,doubletPhi,gasGap:" + << m_idHelperSvc->rpcIdHelper().doubletR(dig_id) << "," + << m_idHelperSvc->rpcIdHelper().doubletZ(dig_id) << "," + << m_idHelperSvc->rpcIdHelper().doubletPhi(dig_id) << "," + << m_idHelperSvc->rpcIdHelper().gasGap(dig_id)); + ATH_MSG_ERROR("measuresPhi:" << m_idHelperSvc->rpcIdHelper().measuresPhi(dig_id)); + continue; + } + + layerid = layer->layerType(); + + // Check if the layer the hit is on already exists in the layer collection and if the hit is a new + // hit + bool stored = false; + bool digstored = false; + std::vector<PairOfLayerPrd*>::const_iterator itr = vec_alllayer->begin(); + std::vector<const Trk::PrepRawData*>::const_iterator digitr; + for (; itr != vec_alllayer->end(); ++itr) { + + // Check for equivalent hits in the collection + for (digitr = (*itr)->second->begin(); digitr != (*itr)->second->end(); ++digitr) { + // Compare the found hit to the new hit + if ((*rpcPrd) == (*digitr)) { + stored = true; + digstored = true; + break; + } + } + // Stop the process if the digit is not unique + if (digstored) { + break; + } + + // Compare the pointers of the layers + if ((*itr)->first->layerType() == layerid) { + if (stored) ATH_MSG_WARNING(" Hit on two different layers! "); + stored = true; + // Add the hit to the layer + (*itr)->second->push_back(*rpcPrd); + } + } + + // If it didn't exist, add a new pair to the layer collection + if (!stored) { + // Create a vector with the ID + std::vector<const Trk::PrepRawData*>* vec_id = new std::vector<const Trk::PrepRawData*>; + vec_id->push_back(*rpcPrd); + + // Create a new pair of Layer and ID vector + PairOfLayerPrd* pair_layerhits = new PairOfLayerPrd(layer, vec_id); + vec_alllayer->push_back(pair_layerhits); + } + } + } + } } - } - //Return the object - ATH_MSG_DEBUG( "MuonTGMeasAssocAlg::createRpcHitCollectionLayers() returns " << vec_alllayer->size() ); - return vec_alllayer; + // Return the object + ATH_MSG_DEBUG("MuonTGMeasAssocAlg::createRpcHitCollectionLayers() returns " << vec_alllayer->size()); + return vec_alllayer; } -std::vector<std::pair<const Trk::Layer*,std::vector<const Trk::PrepRawData*>*>*>* +std::vector<std::pair<const Trk::Layer*, std::vector<const Trk::PrepRawData*>*>*>* Muon::MuonTGMeasAssocAlg::createCscHitCollectionLayers(const MuonGM::MuonDetectorManager* MuonDetMgr) const { - // Get the messaging service, print where you are - ATH_MSG_DEBUG( "MuonTGMeasAssocAlg::createHitCollectionLayers()" ); - - StatusCode sc; + // Get the messaging service, print where you are + ATH_MSG_DEBUG("MuonTGMeasAssocAlg::createHitCollectionLayers()"); - //Define the pair and the vector of pairs - std::vector<PairOfLayerPrd*>* vec_alllayer = 0; + StatusCode sc; - int layerid; + // Define the pair and the vector of pairs + std::vector<PairOfLayerPrd*>* vec_alllayer = 0; - //Try to retrieve the CSC cluster collection - const DataHandle<CscPrepDataContainer> csc_container ; - StatusCode sc_read = evtStore()->retrieve(csc_container, m_inputCscPrdCollection); - if (sc_read.isFailure()) { - ATH_MSG_ERROR( " Cannot retrieve CSC Cluster Container " ); - return vec_alllayer; - } else { - vec_alllayer = new std::vector<PairOfLayerPrd*>; + int layerid; - for ( CscPrepDataContainer::const_iterator icol=csc_container->begin(); - icol != csc_container->end(); ++icol ) { - const CscPrepDataCollection* cscCollection = *icol; - for (CscPrepDataCollection::const_iterator cscPrd = cscCollection->begin(); - cscPrd != cscCollection->end(); ++cscPrd) { - - Identifier dig_id = (*cscPrd)->identify(); - - const Trk::Layer* layer = associatedLayer(3,dig_id,MuonDetMgr); - - if (!layer) { - ATH_MSG_ERROR( " No layer associated with this CSC hit! (digit = " << dig_id << ")" ); - ATH_MSG_ERROR( "station name,eta,phi" << m_idHelperSvc->cscIdHelper().stationName(dig_id) << "," - << m_idHelperSvc->cscIdHelper().stationEta(dig_id) << "," - << m_idHelperSvc->cscIdHelper().stationPhi(dig_id) ); - ATH_MSG_ERROR( "chamberLayer,wireLayer,measuresPhi:" << m_idHelperSvc->cscIdHelper().chamberLayer(dig_id)<<","<< - m_idHelperSvc->cscIdHelper().wireLayer(dig_id)<<","<< - m_idHelperSvc->cscIdHelper().measuresPhi(dig_id)); - continue; - } - - layerid = layer->layerType(); - - //Check if the layer the hit is on already exists in the layer collection and if the hit is a new hit - bool stored = false; - bool digstored = false; - std::vector<PairOfLayerPrd*>::const_iterator itr = vec_alllayer->begin(); - std::vector<const Trk::PrepRawData*>::const_iterator digitr; - for (; itr != vec_alllayer->end(); ++itr) { - - //Check for equivalent hits in the collection - for (digitr = (*itr)->second->begin(); digitr != (*itr)->second->end();++digitr) { - //Compare the found hit to the new hit - if ((*cscPrd) == (*digitr)) { - stored = true; - digstored = true; - break; - } - } - //Stop the process if the digit is not unique - if (digstored) { - break; - } - - //Compare the pointers of the layers - if ((*itr)->first->layerType() == layerid) { - if (stored) - ATH_MSG_WARNING( " Hit on two different layers! " ); - stored = true; - //Add the hit to the layer - (*itr)->second->push_back(*cscPrd); - } - } - - if (!stored) { - //Create a vector with the ID - std::vector<const Trk::PrepRawData*>* vec_id = new std::vector<const Trk::PrepRawData*>; - vec_id->push_back(*cscPrd); - - //Create a new pair of Layer and ID vector - PairOfLayerPrd* pair_layerhits = new PairOfLayerPrd(layer,vec_id); - vec_alllayer->push_back(pair_layerhits); - } - } + // Try to retrieve the CSC cluster collection + const DataHandle<CscPrepDataContainer> csc_container; + StatusCode sc_read = evtStore()->retrieve(csc_container, m_inputCscPrdCollection); + if (sc_read.isFailure()) { + ATH_MSG_ERROR(" Cannot retrieve CSC Cluster Container "); + return vec_alllayer; + } else { + vec_alllayer = new std::vector<PairOfLayerPrd*>; + + for (CscPrepDataContainer::const_iterator icol = csc_container->begin(); icol != csc_container->end(); ++icol) { + const CscPrepDataCollection* cscCollection = *icol; + for (CscPrepDataCollection::const_iterator cscPrd = cscCollection->begin(); cscPrd != cscCollection->end(); + ++cscPrd) { + + Identifier dig_id = (*cscPrd)->identify(); + + const Trk::Layer* layer = associatedLayer(3, dig_id, MuonDetMgr); + + if (!layer) { + ATH_MSG_ERROR(" No layer associated with this CSC hit! (digit = " << dig_id << ")"); + ATH_MSG_ERROR("station name,eta,phi" << m_idHelperSvc->cscIdHelper().stationName(dig_id) << "," + << m_idHelperSvc->cscIdHelper().stationEta(dig_id) << "," + << m_idHelperSvc->cscIdHelper().stationPhi(dig_id)); + ATH_MSG_ERROR("chamberLayer,wireLayer,measuresPhi:" + << m_idHelperSvc->cscIdHelper().chamberLayer(dig_id) << "," + << m_idHelperSvc->cscIdHelper().wireLayer(dig_id) << "," + << m_idHelperSvc->cscIdHelper().measuresPhi(dig_id)); + continue; + } + + layerid = layer->layerType(); + + // Check if the layer the hit is on already exists in the layer collection and if the hit is a new hit + bool stored = false; + bool digstored = false; + std::vector<PairOfLayerPrd*>::const_iterator itr = vec_alllayer->begin(); + std::vector<const Trk::PrepRawData*>::const_iterator digitr; + for (; itr != vec_alllayer->end(); ++itr) { + + // Check for equivalent hits in the collection + for (digitr = (*itr)->second->begin(); digitr != (*itr)->second->end(); ++digitr) { + // Compare the found hit to the new hit + if ((*cscPrd) == (*digitr)) { + stored = true; + digstored = true; + break; + } + } + // Stop the process if the digit is not unique + if (digstored) { + break; + } + + // Compare the pointers of the layers + if ((*itr)->first->layerType() == layerid) { + if (stored) ATH_MSG_WARNING(" Hit on two different layers! "); + stored = true; + // Add the hit to the layer + (*itr)->second->push_back(*cscPrd); + } + } + + if (!stored) { + // Create a vector with the ID + std::vector<const Trk::PrepRawData*>* vec_id = new std::vector<const Trk::PrepRawData*>; + vec_id->push_back(*cscPrd); + + // Create a new pair of Layer and ID vector + PairOfLayerPrd* pair_layerhits = new PairOfLayerPrd(layer, vec_id); + vec_alllayer->push_back(pair_layerhits); + } + } + } } - } - - ATH_MSG_DEBUG( "MuonTGMeasAssocAlg::createCscHitCollectionLayers() returns " << vec_alllayer->size() ); - return vec_alllayer; + + ATH_MSG_DEBUG("MuonTGMeasAssocAlg::createCscHitCollectionLayers() returns " << vec_alllayer->size()); + return vec_alllayer; } -std::vector<std::pair<const Trk::Layer*,std::vector<const Trk::PrepRawData*>*>*>* +std::vector<std::pair<const Trk::Layer*, std::vector<const Trk::PrepRawData*>*>*>* Muon::MuonTGMeasAssocAlg::createTgcHitCollectionLayers(const MuonGM::MuonDetectorManager* MuonDetMgr) const { - // Get the messaging service, print where you are - ATH_MSG_DEBUG( "MuonTGMeasAssocAlg::createHitCollectionLayers():TGC" ); - - StatusCode sc; - - //Define the pair and the vector of pairs - std::vector<PairOfLayerPrd*>* vec_alllayer = 0; - - //Try to retrieve the TGC hit collection - const Muon::TgcPrepDataContainer* tgc_container; - StatusCode sc_read = evtStore()->retrieve(tgc_container, m_inputTgcPrdCollection); - if (sc_read.isFailure()) { - ATH_MSG_ERROR( " Cannot retrieve TGC PrepData Container " ); - return vec_alllayer; - } - - const DataHandle<Muon::TgcPrepDataCollection> tgcCollection; - const DataHandle<Muon::TgcPrepDataCollection> lastColl; - - vec_alllayer = new std::vector<PairOfLayerPrd*>; - - int layerid; - - if (evtStore()->retrieve(tgcCollection,lastColl) ==StatusCode::SUCCESS) { - for ( ; tgcCollection != lastColl ; ++tgcCollection ) { - if (tgcCollection->size()>0) { - for (Muon::TgcPrepDataCollection::const_iterator tgcPrd = tgcCollection->begin(); - tgcPrd != tgcCollection->end(); ++tgcPrd) { - - Identifier dig_id = (*tgcPrd)->identify(); - - const Trk::Layer* layer = associatedLayer(2,dig_id,MuonDetMgr); - - if (!layer) { - ATH_MSG_ERROR( " No layer associated with this TGC hit! (digit = " << dig_id << ")" ); - ATH_MSG_ERROR( "station name,eta,phi" << m_idHelperSvc->tgcIdHelper().stationName(dig_id) << "," - << m_idHelperSvc->tgcIdHelper().stationEta(dig_id) << "," - << m_idHelperSvc->tgcIdHelper().stationPhi(dig_id) ); - ATH_MSG_ERROR( "gasGap,isStrip:" << m_idHelperSvc->tgcIdHelper().gasGap(dig_id)<<","<< - m_idHelperSvc->tgcIdHelper().isStrip(dig_id)); - continue; - } - - layerid = layer->layerType(); - - //Check if the layer the hit is on already exists in the layer collection and if the hit is a new hit - bool stored = false; - bool digstored = false; - std::vector<PairOfLayerPrd*>::const_iterator itr = vec_alllayer->begin(); - std::vector<const Trk::PrepRawData*>::const_iterator digitr; - for (; itr != vec_alllayer->end(); ++itr) { - - //Check for equivalent hits in the collection - for (digitr = (*itr)->second->begin(); digitr != (*itr)->second->end();++digitr) { - //Compare the found hit to the new hit - if ((*tgcPrd) == (*digitr)) { - stored = true; - digstored = true; - break; - } - } - //Stop the process if the digit is not unique - if (digstored) { - break; - } - - //Compare the pointers of the layers - if ((*itr)->first->layerType() == layerid) { - if (stored) - ATH_MSG_WARNING( " Hit on two different layers! " ); - stored = true; - //Add the hit to the layer - (*itr)->second->push_back(*tgcPrd); - } - } - - if (!stored) { - //Create a vector with the ID - std::vector<const Trk::PrepRawData*>* vec_id = new std::vector<const Trk::PrepRawData*>; - vec_id->push_back(*tgcPrd); - - //Create a new pair of Layer and ID vector - PairOfLayerPrd* pair_layerhits = new PairOfLayerPrd(layer,vec_id); - vec_alllayer->push_back(pair_layerhits); - } - } - } + // Get the messaging service, print where you are + ATH_MSG_DEBUG("MuonTGMeasAssocAlg::createHitCollectionLayers():TGC"); + + StatusCode sc; + + // Define the pair and the vector of pairs + std::vector<PairOfLayerPrd*>* vec_alllayer = 0; + + // Try to retrieve the TGC hit collection + const Muon::TgcPrepDataContainer* tgc_container; + StatusCode sc_read = evtStore()->retrieve(tgc_container, m_inputTgcPrdCollection); + if (sc_read.isFailure()) { + ATH_MSG_ERROR(" Cannot retrieve TGC PrepData Container "); + return vec_alllayer; + } + + const DataHandle<Muon::TgcPrepDataCollection> tgcCollection; + const DataHandle<Muon::TgcPrepDataCollection> lastColl; + + vec_alllayer = new std::vector<PairOfLayerPrd*>; + + int layerid; + + if (evtStore()->retrieve(tgcCollection, lastColl) == StatusCode::SUCCESS) { + for (; tgcCollection != lastColl; ++tgcCollection) { + if (tgcCollection->size() > 0) { + for (Muon::TgcPrepDataCollection::const_iterator tgcPrd = tgcCollection->begin(); + tgcPrd != tgcCollection->end(); ++tgcPrd) + { + + Identifier dig_id = (*tgcPrd)->identify(); + + const Trk::Layer* layer = associatedLayer(2, dig_id, MuonDetMgr); + + if (!layer) { + ATH_MSG_ERROR(" No layer associated with this TGC hit! (digit = " << dig_id << ")"); + ATH_MSG_ERROR("station name,eta,phi" << m_idHelperSvc->tgcIdHelper().stationName(dig_id) << "," + << m_idHelperSvc->tgcIdHelper().stationEta(dig_id) << "," + << m_idHelperSvc->tgcIdHelper().stationPhi(dig_id)); + ATH_MSG_ERROR("gasGap,isStrip:" << m_idHelperSvc->tgcIdHelper().gasGap(dig_id) << "," + << m_idHelperSvc->tgcIdHelper().isStrip(dig_id)); + continue; + } + + layerid = layer->layerType(); + + // Check if the layer the hit is on already exists in the layer collection and if the hit is a new + // hit + bool stored = false; + bool digstored = false; + std::vector<PairOfLayerPrd*>::const_iterator itr = vec_alllayer->begin(); + std::vector<const Trk::PrepRawData*>::const_iterator digitr; + for (; itr != vec_alllayer->end(); ++itr) { + + // Check for equivalent hits in the collection + for (digitr = (*itr)->second->begin(); digitr != (*itr)->second->end(); ++digitr) { + // Compare the found hit to the new hit + if ((*tgcPrd) == (*digitr)) { + stored = true; + digstored = true; + break; + } + } + // Stop the process if the digit is not unique + if (digstored) { + break; + } + + // Compare the pointers of the layers + if ((*itr)->first->layerType() == layerid) { + if (stored) ATH_MSG_WARNING(" Hit on two different layers! "); + stored = true; + // Add the hit to the layer + (*itr)->second->push_back(*tgcPrd); + } + } + + if (!stored) { + // Create a vector with the ID + std::vector<const Trk::PrepRawData*>* vec_id = new std::vector<const Trk::PrepRawData*>; + vec_id->push_back(*tgcPrd); + + // Create a new pair of Layer and ID vector + PairOfLayerPrd* pair_layerhits = new PairOfLayerPrd(layer, vec_id); + vec_alllayer->push_back(pair_layerhits); + } + } + } + } } - } - - ATH_MSG_DEBUG( "MuonTGMeasAssocAlg::createTgcHitCollectionLayers() returns " << vec_alllayer->size() ); - return vec_alllayer; + + ATH_MSG_DEBUG("MuonTGMeasAssocAlg::createTgcHitCollectionLayers() returns " << vec_alllayer->size()); + return vec_alllayer; } -void Muon::MuonTGMeasAssocAlg::createStationMap(const Trk::TrackingVolume* vol, const MuonGM::MuonDetectorManager* MuonDetMgr) const +void +Muon::MuonTGMeasAssocAlg::createStationMap(const Trk::TrackingVolume* vol, + const MuonGM::MuonDetectorManager* MuonDetMgr) const { - if (vol->confinedVolumes()) { - const std::vector<const Trk::TrackingVolume*> subVols = vol->confinedVolumes()->arrayObjects(); - std::vector<const Trk::TrackingVolume*>::const_iterator iter = subVols.begin(); - for (;iter!=subVols.end();iter++) createStationMap(*iter, MuonDetMgr); - } - - if (vol->confinedDetachedVolumes()) { - const std::vector<const Trk::DetachedTrackingVolume*>* detVols = vol->confinedDetachedVolumes(); - std::vector<const Trk::DetachedTrackingVolume*>::const_iterator dter = detVols->begin(); - for (;dter!=detVols->end();dter++) { - if ( (*dter)->layerRepresentation() && (*dter)->layerRepresentation()->layerType()>0 ) { - Identifier id((*dter)->layerRepresentation()->layerType()); - const MuonGM::MuonStation* mStation = 0; - if (m_idHelperSvc->isMdt(id)) mStation = MuonDetMgr->getMdtReadoutElement(id)->parentMuonStation(); - if (m_idHelperSvc->isRpc(id)) mStation = MuonDetMgr->getRpcReadoutElement(id)->parentMuonStation(); - if (m_idHelperSvc->isTgc(id)) { - if ( !MuonDetMgr->getTgcReadoutElement(id) ) { // tgc readout element not found, get any active layer to recover - const Trk::Layer* lay = associatedLayer((*dter)->trackingVolume(),Identifier(0)); - if (lay) mStation = MuonDetMgr->getTgcReadoutElement(Identifier(lay->layerType()))->parentMuonStation(); - } else { - mStation = MuonDetMgr->getTgcReadoutElement(id)->parentMuonStation(); - } + if (vol->confinedVolumes()) { + const std::vector<const Trk::TrackingVolume*> subVols = vol->confinedVolumes()->arrayObjects(); + std::vector<const Trk::TrackingVolume*>::const_iterator iter = subVols.begin(); + for (; iter != subVols.end(); iter++) createStationMap(*iter, MuonDetMgr); + } + + if (vol->confinedDetachedVolumes()) { + const std::vector<const Trk::DetachedTrackingVolume*>* detVols = vol->confinedDetachedVolumes(); + std::vector<const Trk::DetachedTrackingVolume*>::const_iterator dter = detVols->begin(); + for (; dter != detVols->end(); dter++) { + if ((*dter)->layerRepresentation() && (*dter)->layerRepresentation()->layerType() > 0) { + Identifier id((*dter)->layerRepresentation()->layerType()); + const MuonGM::MuonStation* mStation = 0; + if (m_idHelperSvc->isMdt(id)) mStation = MuonDetMgr->getMdtReadoutElement(id)->parentMuonStation(); + if (m_idHelperSvc->isRpc(id)) mStation = MuonDetMgr->getRpcReadoutElement(id)->parentMuonStation(); + if (m_idHelperSvc->isTgc(id)) { + if (!MuonDetMgr->getTgcReadoutElement(id)) + { // tgc readout element not found, get any active layer to recover + const Trk::Layer* lay = associatedLayer((*dter)->trackingVolume(), Identifier(0)); + if (lay) + mStation = + MuonDetMgr->getTgcReadoutElement(Identifier(lay->layerType()))->parentMuonStation(); + } else { + mStation = MuonDetMgr->getTgcReadoutElement(id)->parentMuonStation(); + } + } + if (m_idHelperSvc->isCsc(id)) { + if (!MuonDetMgr->getCscReadoutElement(id)) { + const Trk::Layer* lay = associatedLayer((*dter)->trackingVolume(), Identifier(0)); + if (lay) + mStation = + MuonDetMgr->getCscReadoutElement(Identifier(lay->layerType()))->parentMuonStation(); + } else + mStation = MuonDetMgr->getCscReadoutElement(id)->parentMuonStation(); + } + // coming across station repeatedly + if (mStation && !m_stationMap[id].second) + m_stationMap[id] = + std::pair<const MuonGM::MuonStation*, const Trk::DetachedTrackingVolume*>(mStation, *dter); + } } - if (m_idHelperSvc->isCsc(id)) { - if ( !MuonDetMgr->getCscReadoutElement(id) ) { - const Trk::Layer* lay = associatedLayer((*dter)->trackingVolume(),Identifier(0)); - if (lay) mStation = MuonDetMgr->getCscReadoutElement(Identifier(lay->layerType()))->parentMuonStation(); - } else mStation = MuonDetMgr->getCscReadoutElement(id)->parentMuonStation(); - } - // coming across station repeatedly - if (mStation && !m_stationMap[id].second ) - m_stationMap[id] = std::pair<const MuonGM::MuonStation*,const Trk::DetachedTrackingVolume*>(mStation,*dter); - } } - } } -void Muon::MuonTGMeasAssocAlg::misAlignStations() const +void +Muon::MuonTGMeasAssocAlg::misAlignStations() const { - std::map<Identifier,std::pair<const MuonGM::MuonStation*, const Trk::DetachedTrackingVolume*> >::iterator iter = m_stationMap.begin(); - - for ( ;iter!=m_stationMap.end();iter++) { - for (unsigned int mis = 0; mis<m_misAlignDiff.size(); mis++) { - Identifier sId( iter->first); - if ( sId == m_misAlignDiff[mis].first || !m_misAlignDiff[mis].first.get_identifier32().get_compact() ) { - iter->second.second->move(m_misAlignDiff[mis].second); - std::cout << "moving station :"<<iter->second.second->name() << " by " << m_misAlignDiff[mis].second.translation()<< std::endl; - break; - } + std::map<Identifier, std::pair<const MuonGM::MuonStation*, const Trk::DetachedTrackingVolume*> >::iterator iter = + m_stationMap.begin(); + + for (; iter != m_stationMap.end(); iter++) { + for (unsigned int mis = 0; mis < m_misAlignDiff.size(); mis++) { + Identifier sId(iter->first); + if (sId == m_misAlignDiff[mis].first || !m_misAlignDiff[mis].first.get_identifier32().get_compact()) { + iter->second.second->move(m_misAlignDiff[mis].second); + std::cout << "moving station :" << iter->second.second->name() << " by " + << m_misAlignDiff[mis].second.translation() << std::endl; + break; + } + } } - } } -void Muon::MuonTGMeasAssocAlg::reAlignStations() const +void +Muon::MuonTGMeasAssocAlg::reAlignStations() const { - std::map<Identifier,std::pair<const MuonGM::MuonStation*, const Trk::DetachedTrackingVolume*> >::iterator iter = m_stationMap.begin(); - - unsigned int moved = 0; - for ( ;iter!=m_stationMap.end();iter++) { - const Amg::Transform3D transfMS = iter->second.first->getGeoTransform()->getTransform(); - const Amg::Transform3D transfTV = iter->second.second->trackingVolume()->transform(); - if ( !transfMS.isApprox(transfTV, 1e-3) ) { - Amg::Transform3D shift = transfMS*transfTV.inverse(); - iter->second.second->move(shift); - moved++; + std::map<Identifier, std::pair<const MuonGM::MuonStation*, const Trk::DetachedTrackingVolume*> >::iterator iter = + m_stationMap.begin(); + + unsigned int moved = 0; + for (; iter != m_stationMap.end(); iter++) { + const Amg::Transform3D transfMS = iter->second.first->getGeoTransform()->getTransform(); + const Amg::Transform3D transfTV = iter->second.second->trackingVolume()->transform(); + if (!transfMS.isApprox(transfTV, 1e-3)) { + Amg::Transform3D shift = transfMS * transfTV.inverse(); + iter->second.second->move(shift); + moved++; + } } - } - ATH_MSG_DEBUG( moved << " stations realigned "); + ATH_MSG_DEBUG(moved << " stations realigned "); } -const Trk::Layer* Muon::MuonTGMeasAssocAlg::associatedLayer(int techn, Identifier id, const MuonGM::MuonDetectorManager* MuonDetMgr) const +const Trk::Layer* +Muon::MuonTGMeasAssocAlg::associatedLayer(int techn, Identifier id, const MuonGM::MuonDetectorManager* MuonDetMgr) const { - const Trk::Layer* layer = 0; - const MuonGM::MuonStation* mStation = 0; - if ( techn==0 ) mStation = MuonDetMgr->getMdtReadoutElement(id)->parentMuonStation(); - if ( techn==1 ) mStation = MuonDetMgr->getRpcReadoutElement(id)->parentMuonStation(); - if ( techn==2 ) mStation = MuonDetMgr->getTgcReadoutElement(id)->parentMuonStation(); - if ( techn==3 ) mStation = MuonDetMgr->getCscReadoutElement(id)->parentMuonStation(); - - if (!mStation ) ATH_MSG_ERROR( "no associated GM station found for hit id:"<< id << ","<< techn ); - if (!mStation ) return layer; - - //Identifier stId(m_muonTgTool->getStationId(id)); - Identifier stId = getStationId(id); - - const Trk::DetachedTrackingVolume* station = m_stationMap[stId].second; - if (!station) { - ATH_MSG_WARNING("no associated TG station found for hit id:"<< id << ","<< techn); - if (techn==2 && m_allowGeomAssoc) { - ATH_MSG_WARNING(m_idHelperSvc->tgcIdHelper().stationName(id)<<","<<m_idHelperSvc->tgcIdHelper().stationEta(id)<< ","<<m_idHelperSvc->tgcIdHelper().stationPhi(id)); - - //Get the TgcReadoutElement and the tube position from it - const MuonGM::TgcReadoutElement* tgcROE = MuonDetMgr->getTgcReadoutElement(id); - Amg::Vector3D pos = tgcROE->channelPos(id); - std::vector<const Trk::DetachedTrackingVolume*>* detVols = m_trackingGeometry->lowestDetachedTrackingVolumes(pos); - for (unsigned int i = 0;i<detVols->size();i++) { - Identifier sId((*detVols)[i]->layerRepresentation()->layerType()); - ATH_MSG_INFO("geom assoc with station:"<< (*detVols)[i]<<","<<(*detVols)[i]->name()<<","<<(*detVols)[i]->layerRepresentation()->layerType() <<":"<< m_idHelperSvc->tgcIdHelper().stationName(sId)<<","<<m_idHelperSvc->tgcIdHelper().stationEta(sId) - <<","<<m_idHelperSvc->tgcIdHelper().stationPhi(sId) ); - ATH_MSG_INFO("updating station map"); - m_stationMap[stId]=std::pair<const MuonGM::MuonStation*,const Trk::DetachedTrackingVolume*>(mStation,(*detVols)[i]); - } - station = m_stationMap[stId].second; - } - } - // associated layer - if (station) { - const Trk::Layer* lay = associatedLayer(station->trackingVolume(),id); - if (lay) return lay; - } - - return layer; + const Trk::Layer* layer = 0; + const MuonGM::MuonStation* mStation = 0; + if (techn == 0) mStation = MuonDetMgr->getMdtReadoutElement(id)->parentMuonStation(); + if (techn == 1) mStation = MuonDetMgr->getRpcReadoutElement(id)->parentMuonStation(); + if (techn == 2) mStation = MuonDetMgr->getTgcReadoutElement(id)->parentMuonStation(); + if (techn == 3) mStation = MuonDetMgr->getCscReadoutElement(id)->parentMuonStation(); + + if (!mStation) ATH_MSG_ERROR("no associated GM station found for hit id:" << id << "," << techn); + if (!mStation) return layer; + + // Identifier stId(m_muonTgTool->getStationId(id)); + Identifier stId = getStationId(id); + + const Trk::DetachedTrackingVolume* station = m_stationMap[stId].second; + if (!station) { + ATH_MSG_WARNING("no associated TG station found for hit id:" << id << "," << techn); + if (techn == 2 && m_allowGeomAssoc) { + ATH_MSG_WARNING(m_idHelperSvc->tgcIdHelper().stationName(id) + << "," << m_idHelperSvc->tgcIdHelper().stationEta(id) << "," + << m_idHelperSvc->tgcIdHelper().stationPhi(id)); + + // Get the TgcReadoutElement and the tube position from it + const MuonGM::TgcReadoutElement* tgcROE = MuonDetMgr->getTgcReadoutElement(id); + Amg::Vector3D pos = tgcROE->channelPos(id); + std::vector<const Trk::DetachedTrackingVolume*>* detVols = + m_trackingGeometry->lowestDetachedTrackingVolumes(pos); + for (unsigned int i = 0; i < detVols->size(); i++) { + Identifier sId((*detVols)[i]->layerRepresentation()->layerType()); + ATH_MSG_INFO("geom assoc with station:" << (*detVols)[i] << "," << (*detVols)[i]->name() << "," + << (*detVols)[i]->layerRepresentation()->layerType() << ":" + << m_idHelperSvc->tgcIdHelper().stationName(sId) << "," + << m_idHelperSvc->tgcIdHelper().stationEta(sId) << "," + << m_idHelperSvc->tgcIdHelper().stationPhi(sId)); + ATH_MSG_INFO("updating station map"); + m_stationMap[stId] = + std::pair<const MuonGM::MuonStation*, const Trk::DetachedTrackingVolume*>(mStation, (*detVols)[i]); + } + station = m_stationMap[stId].second; + } + } + // associated layer + if (station) { + const Trk::Layer* lay = associatedLayer(station->trackingVolume(), id); + if (lay) return lay; + } + + return layer; } -const Trk::Layer* Muon::MuonTGMeasAssocAlg::associatedLayer(const Trk::TrackingVolume* trVol, Identifier id) const +const Trk::Layer* +Muon::MuonTGMeasAssocAlg::associatedLayer(const Trk::TrackingVolume* trVol, Identifier id) const { - // finds associated layer using identifier match; station already found - - const Trk::Layer* layer = 0; - - if (trVol->confinedLayers()) { // MDT,TGC,CSC - std::vector<const Trk::Layer*> confLays = trVol->confinedLayers()->arrayObjects(); - std::vector<const Trk::Layer*>::iterator iLay = confLays.begin(); - for ( ; iLay!=confLays.end(); iLay++ ) { - Identifier idLay( (*iLay)->layerType() ); - if (!id.get_identifier32().get_compact() && idLay.get_identifier32().get_compact()) return (*iLay); - if (!idLay.get_identifier32().get_compact()) continue; - if ( m_idHelperSvc->isMdt(id) && - m_idHelperSvc->mdtIdHelper().multilayer(idLay)==m_idHelperSvc->mdtIdHelper().multilayer(id) && - m_idHelperSvc->mdtIdHelper().tubeLayer(idLay)==m_idHelperSvc->mdtIdHelper().tubeLayer(id) ) return (*iLay); - if ( m_idHelperSvc->isTgc(id) && - m_idHelperSvc->tgcIdHelper().gasGap(idLay)==m_idHelperSvc->tgcIdHelper().gasGap(id) ) return (*iLay); - if ( m_idHelperSvc->isCsc(id) && - m_idHelperSvc->cscIdHelper().chamberLayer(idLay)==m_idHelperSvc->cscIdHelper().chamberLayer(id) && - m_idHelperSvc->cscIdHelper().wireLayer(idLay)==m_idHelperSvc->cscIdHelper().wireLayer(id) ) return (*iLay); + // finds associated layer using identifier match; station already found + + const Trk::Layer* layer = 0; + + if (trVol->confinedLayers()) { // MDT,TGC,CSC + std::vector<const Trk::Layer*> confLays = trVol->confinedLayers()->arrayObjects(); + std::vector<const Trk::Layer*>::iterator iLay = confLays.begin(); + for (; iLay != confLays.end(); iLay++) { + Identifier idLay((*iLay)->layerType()); + if (!id.get_identifier32().get_compact() && idLay.get_identifier32().get_compact()) return (*iLay); + if (!idLay.get_identifier32().get_compact()) continue; + if (m_idHelperSvc->isMdt(id) + && m_idHelperSvc->mdtIdHelper().multilayer(idLay) == m_idHelperSvc->mdtIdHelper().multilayer(id) + && m_idHelperSvc->mdtIdHelper().tubeLayer(idLay) == m_idHelperSvc->mdtIdHelper().tubeLayer(id)) + return (*iLay); + if (m_idHelperSvc->isTgc(id) + && m_idHelperSvc->tgcIdHelper().gasGap(idLay) == m_idHelperSvc->tgcIdHelper().gasGap(id)) + return (*iLay); + if (m_idHelperSvc->isCsc(id) + && m_idHelperSvc->cscIdHelper().chamberLayer(idLay) == m_idHelperSvc->cscIdHelper().chamberLayer(id) + && m_idHelperSvc->cscIdHelper().wireLayer(idLay) == m_idHelperSvc->cscIdHelper().wireLayer(id)) + return (*iLay); + } + return layer; } - return layer; - } - - if (trVol->confinedArbitraryLayers()) { // RPC - const std::vector<const Trk::Layer*>* confLays = trVol->confinedArbitraryLayers(); - std::vector<const Trk::Layer*>::const_iterator iLay = confLays->begin(); - for ( ; iLay!=confLays->end(); iLay++ ) { - Identifier idLay( (*iLay)->layerType() ); - if (!id.get_identifier32().get_compact() && idLay.get_identifier32().get_compact()) return (*iLay); - if ( idLay.get_identifier32().get_compact()>0 && m_idHelperSvc->isRpc(id) && - m_idHelperSvc->rpcIdHelper().doubletR(idLay) == m_idHelperSvc->rpcIdHelper().doubletR(id) && - m_idHelperSvc->rpcIdHelper().doubletZ(idLay) == m_idHelperSvc->rpcIdHelper().doubletZ(id) && - m_idHelperSvc->rpcIdHelper().gasGap(idLay) == m_idHelperSvc->rpcIdHelper().gasGap(id) ) return (*iLay); + + if (trVol->confinedArbitraryLayers()) { // RPC + const std::vector<const Trk::Layer*>* confLays = trVol->confinedArbitraryLayers(); + std::vector<const Trk::Layer*>::const_iterator iLay = confLays->begin(); + for (; iLay != confLays->end(); iLay++) { + Identifier idLay((*iLay)->layerType()); + if (!id.get_identifier32().get_compact() && idLay.get_identifier32().get_compact()) return (*iLay); + if (idLay.get_identifier32().get_compact() > 0 && m_idHelperSvc->isRpc(id) + && m_idHelperSvc->rpcIdHelper().doubletR(idLay) == m_idHelperSvc->rpcIdHelper().doubletR(id) + && m_idHelperSvc->rpcIdHelper().doubletZ(idLay) == m_idHelperSvc->rpcIdHelper().doubletZ(id) + && m_idHelperSvc->rpcIdHelper().gasGap(idLay) == m_idHelperSvc->rpcIdHelper().gasGap(id)) + return (*iLay); + } + return layer; } - return layer; - } - - if (trVol->confinedVolumes()) { - std::vector<const Trk::TrackingVolume*> subVols=trVol->confinedVolumes()->arrayObjects(); - std::vector<const Trk::TrackingVolume*>::iterator iter=subVols.begin(); - for ( ; iter!=subVols.end(); iter++ ) { - const Trk::Layer* lay = associatedLayer((*iter),id); - if (lay) return lay; + + if (trVol->confinedVolumes()) { + std::vector<const Trk::TrackingVolume*> subVols = trVol->confinedVolumes()->arrayObjects(); + std::vector<const Trk::TrackingVolume*>::iterator iter = subVols.begin(); + for (; iter != subVols.end(); iter++) { + const Trk::Layer* lay = associatedLayer((*iter), id); + if (lay) return lay; + } } - } - return layer; + return layer; } -Identifier Muon::MuonTGMeasAssocAlg::getStationId( Identifier id ) const +Identifier +Muon::MuonTGMeasAssocAlg::getStationId(Identifier id) const { - Identifier stId(0); - if ( m_idHelperSvc->isMdt(id)) stId = m_idHelperSvc->mdtIdHelper().elementID(m_idHelperSvc->mdtIdHelper().stationName(id), - m_idHelperSvc->mdtIdHelper().stationEta(id), - m_idHelperSvc->mdtIdHelper().stationPhi(id)); - // BML station is an exception - if (m_idHelperSvc->isMdt(id) && m_idHelperSvc->mdtIdHelper().stationName(id)==2) - stId = m_idHelperSvc->rpcIdHelper().elementID(m_idHelperSvc->mdtIdHelper().stationName(id), - m_idHelperSvc->mdtIdHelper().stationEta(id), - m_idHelperSvc->mdtIdHelper().stationPhi(id),1); - - if ( m_idHelperSvc->isRpc(id)) stId = m_idHelperSvc->rpcIdHelper().elementID(m_idHelperSvc->rpcIdHelper().stationName(id), - m_idHelperSvc->rpcIdHelper().stationEta(id), - m_idHelperSvc->rpcIdHelper().stationPhi(id),1); - - // rpc not allways relevant - if ( m_idHelperSvc->isRpc(id) && m_stationMap.size() && !(m_stationMap)[stId].second ) { - stId = m_idHelperSvc->mdtIdHelper().elementID(m_idHelperSvc->mdtIdHelper().stationName(id), - m_idHelperSvc->mdtIdHelper().stationEta(id), - m_idHelperSvc->mdtIdHelper().stationPhi(id) ); - } - - if ( m_idHelperSvc->isTgc(id)) stId = m_idHelperSvc->tgcIdHelper().elementID(m_idHelperSvc->tgcIdHelper().stationName(id), - m_idHelperSvc->tgcIdHelper().stationEta(id), - m_idHelperSvc->tgcIdHelper().stationPhi(id)); - if ( m_idHelperSvc->isCsc(id)) stId = m_idHelperSvc->cscIdHelper().elementID(m_idHelperSvc->cscIdHelper().stationName(id), - m_idHelperSvc->cscIdHelper().stationEta(id), - m_idHelperSvc->cscIdHelper().stationPhi(id)); - - return stId; + Identifier stId(0); + if (m_idHelperSvc->isMdt(id)) + stId = m_idHelperSvc->mdtIdHelper().elementID(m_idHelperSvc->mdtIdHelper().stationName(id), + m_idHelperSvc->mdtIdHelper().stationEta(id), + m_idHelperSvc->mdtIdHelper().stationPhi(id)); + // BML station is an exception + if (m_idHelperSvc->isMdt(id) && m_idHelperSvc->mdtIdHelper().stationName(id) == 2) + stId = m_idHelperSvc->rpcIdHelper().elementID(m_idHelperSvc->mdtIdHelper().stationName(id), + m_idHelperSvc->mdtIdHelper().stationEta(id), + m_idHelperSvc->mdtIdHelper().stationPhi(id), 1); + + if (m_idHelperSvc->isRpc(id)) + stId = m_idHelperSvc->rpcIdHelper().elementID(m_idHelperSvc->rpcIdHelper().stationName(id), + m_idHelperSvc->rpcIdHelper().stationEta(id), + m_idHelperSvc->rpcIdHelper().stationPhi(id), 1); + + // rpc not allways relevant + if (m_idHelperSvc->isRpc(id) && m_stationMap.size() && !(m_stationMap)[stId].second) { + stId = m_idHelperSvc->mdtIdHelper().elementID(m_idHelperSvc->mdtIdHelper().stationName(id), + m_idHelperSvc->mdtIdHelper().stationEta(id), + m_idHelperSvc->mdtIdHelper().stationPhi(id)); + } + + if (m_idHelperSvc->isTgc(id)) + stId = m_idHelperSvc->tgcIdHelper().elementID(m_idHelperSvc->tgcIdHelper().stationName(id), + m_idHelperSvc->tgcIdHelper().stationEta(id), + m_idHelperSvc->tgcIdHelper().stationPhi(id)); + if (m_idHelperSvc->isCsc(id)) + stId = m_idHelperSvc->cscIdHelper().elementID(m_idHelperSvc->cscIdHelper().stationName(id), + m_idHelperSvc->cscIdHelper().stationEta(id), + m_idHelperSvc->cscIdHelper().stationPhi(id)); + + return stId; } -- GitLab