8 #include "CLHEP/Random/RandFlat.h"
9 #include "CLHEP/Random/RandGaussZiggurat.h"
20 const IInterface*
p ) :
23 declareInterface<INSWCalibSmearingTool>(
this);
31 if ( !(m_idHelperSvc->hasMM() || m_idHelperSvc->hasSTGC() ) ) {
32 ATH_MSG_ERROR(
"MM or STGC not part of initialized detector layout");
33 return StatusCode::FAILURE;
37 if (m_readEfficiencyFromFile || m_readGainFractionFromFile) {
41 return StatusCode::SUCCESS;
55 if (!getIdFields(
id,etaSector,phiSector,
gasGap)) {
57 return StatusCode::SUCCESS;
61 float efficiencyCut = 0.0;
62 if ( !(m_readEfficiencyFromFile || m_readGainFractionFromFile) ) {
63 efficiencyCut = m_clusterEfficiency.value()[
gasGap-1];
68 if ( !getPCBIdentifier(
id, pcb_id) ) {
69 ATH_MSG_ERROR(
"Could not convert the id " << m_idHelperSvc->toString(
id) <<
" to a PCB identifier" );
70 return StatusCode::FAILURE;
74 std::map<Identifier,float>::const_iterator
it = m_hvMap.find(pcb_id);
75 if (
it != m_hvMap.end() ) {
76 double hv =
it->second;
77 efficiencyCut = getMMEfficiencyFromHV(hv);
80 ATH_MSG_WARNING(
"PCB Id not found in the HV map " << m_idHelperSvc->toString(pcb_id));
82 return StatusCode::SUCCESS;
87 if ( CLHEP::RandFlat::shoot(rndmEngine, 0. , 1.) > efficiencyCut ) {
91 return StatusCode::SUCCESS;
108 if (!getIdFields(
id,etaSector,phiSector,
gasGap)) {
110 return StatusCode::SUCCESS;
115 float efficiencyCut = 0.0;
116 if ( !(m_readEfficiencyFromFile || m_readGainFractionFromFile) ) {
117 efficiencyCut = m_clusterEfficiency.value()[
gasGap-1];
122 if ( !getPCBIdentifier(
id, pcb_id) ) {
123 ATH_MSG_ERROR(
"Could not convert the id " << m_idHelperSvc->toString(
id) <<
" to a PCB identifier" );
124 return StatusCode::FAILURE;
127 std::map<Identifier,float>::const_iterator
it = m_hvMap.find(pcb_id);
128 if (
it != m_hvMap.end() ) {
129 double hv =
it->second;
130 efficiencyCut = getMMEfficiencyFromHV(hv);
133 ATH_MSG_WARNING(
"PCB Id not found in the HV map " << m_idHelperSvc->toString(pcb_id));
135 return StatusCode::SUCCESS;
139 if ( m_phiSectors.value()[phiSector-1] && m_etaSectors.value()[etaSector-1] ) {
141 double chargeSmear = m_chargeSmear.value()[
gasGap-1];
142 charge =
charge + CLHEP::RandGaussZiggurat::shoot(rndmEngine,0.0, chargeSmear);
146 if ( CLHEP::RandFlat::shoot(rndmEngine, 0. , 1.) > efficiencyCut ) {
151 return StatusCode::SUCCESS;
160 if ( m_idHelperSvc->issTgc(
id) ) {
162 return StatusCode::FAILURE;
169 if (!getIdFields(
id,etaSector,phiSector,
gasGap)) {
171 return StatusCode::SUCCESS;
174 if ( m_phiSectors.value()[phiSector-1] && m_etaSectors.value()[etaSector-1] ) {
177 double timeSmear = m_timeSmear.value()[
gasGap-1];
178 double chargeSmear = m_chargeSmear.value()[
gasGap-1];
180 time = time + CLHEP::RandGaussZiggurat::shoot(rndmEngine,0.0, timeSmear);
181 charge =
charge + CLHEP::RandGaussZiggurat::shoot(rndmEngine,0.0, chargeSmear);
185 if ( CLHEP::RandFlat::shoot(rndmEngine, 0. , 1.) > m_channelEfficiency.value()[
gasGap-1] ) {
190 return StatusCode::SUCCESS;
202 if (!getIdFields(
id,etaSector,phiSector,
gasGap)) {
204 return StatusCode::SUCCESS;
209 if(!m_readGainFractionFromFile) {
210 if ( m_phiSectors.value()[phiSector-1] && m_etaSectors.value()[etaSector-1] ) {
211 gainFraction = m_gainFraction.value()[
gasGap-1];
215 float hv = getHighVoltage(
id);
217 return StatusCode::FAILURE;
219 else if(hv == -1.0) {
223 gainFraction=getMMGainFractionFromHV(hv);
224 ATH_MSG_DEBUG(
"Got gain fraction: "<< gainFraction <<
" for id " << m_idHelperSvc->toString(
id));
227 return StatusCode::SUCCESS;
242 etaSector < 0 ? etaSector = etaSector + 3 : etaSector = etaSector + 2;
245 int multilayer =
m_idHelperSvc->stgcIdHelper().multilayer(
id);
250 etaSector < 0 ? etaSector = etaSector + 4 : etaSector = etaSector + 3;
258 if ( phiSector < 1 || phiSector> (
int)
m_phiSectors.value().size()
261 ATH_MSG_WARNING(
"Wrong phi, eta sector, or gasGap number: " << phiSector <<
" "
281 std::map<Identifier,float>::const_iterator
it =
m_hvMap.find(pcbId);
298 double eff = 1.0/(1+
exp(-0.0551*(hv-510.54)));
309 return std::exp(-8.87971 + 0.0224561 * hv) /
std::exp(-8.87971 + 0.0224561 * 570);
325 pcb_strip = pcb_strip * 1024 + 512;
350 std::string fileNamesA[16] = {
"A01.txt",
"A02.txt",
"A03.txt",
"A04.txt",
351 "A05.txt",
"A06.txt",
"A07.txt",
"A08.txt",
352 "A09.txt",
"A10.txt",
"A11.txt",
"A12.txt",
353 "A13.txt",
"A14.txt",
"A15.txt",
"A16.txt" };
360 if ( !
file.is_open() ) {
371 bool isLM,isSM,isIP,isHO;
374 std::string layerId[4] = {
"L1",
"L2",
"L3",
"L4"};
389 std::string secName = fileNamesA[
ifile].substr(0,2);
391 if ( secName.substr(0,1)==
"A" )
side = +1;
392 else if ( secName.substr(0,1)==
"C" )
side = -1;
395 return StatusCode::FAILURE;
397 int phiSec = std::stoi(fileNamesA[
ifile].substr(1,2));
398 stationPhi = (phiSec-1)/2+1;
400 size_t fLM =
line.find(
"LM");
401 size_t fSM =
line.find(
"SM");
402 isLM = (fLM!=std::string::npos);
403 isSM = (fSM!=std::string::npos);
406 if ( isLM || isSM ) {
408 stationEta =
side*std::stoi(
line.substr(fSM+2,1));
411 stationEta =
side*std::stoi(
line.substr(fLM+2,1));
415 if (stationEta==1) endPCB=5;
416 else if (stationEta==2) endPCB=3;
423 std::size_t fIP =
line.find(
"IP");
424 isIP = (fIP!=std::string::npos);
425 std::size_t fHO =
line.find(
"HO");
426 isHO = (fHO!=std::string::npos);
427 if ( !isIP && !isHO ) {
429 return StatusCode::FAILURE;
431 else if ( isIP && isHO ) {
432 ATH_MSG_ERROR(
"ERROR multilayer id duplicated (IP and HO) ");
433 return StatusCode::FAILURE;
445 for (
int ilayer = 1; ilayer <= 4; ilayer++) {
446 for (
int ipcb = 1; ipcb <= endPCB; ipcb++) {
450 std::istringstream elem(
line);
451 std::vector<std::string> elements;
454 std::string subs_elem;
456 if (!subs_elem.empty()) elements.push_back(subs_elem);
459 gasGap = std::stoi(elements[0]);
460 int readed_pcb = std::stoi(elements[1]);
461 if (
gasGap != ilayer || readed_pcb != ipcb) {
463 return StatusCode::FAILURE;
466 HVval=std::stoi(elements[4]);
468 ATH_MSG_DEBUG(
"PCB done, stationName, stationEta, stationPhi, ml, layer, pcb, hv: "
469 <<
stationName<<
" " << stationEta <<
" " << stationPhi <<
" " << multilayer <<
" "
470 << ilayer <<
" " << ipcb <<
" " << HVval );
472 int chanNum = (ipcb-1)*1024+512;
476 float hv = (
float)HVval;
477 m_hvMap.insert(std::pair<Identifier,float>(pcbId,hv));
488 return StatusCode::SUCCESS;