ATLAS Offline Software
LArPhysCaliTDiffAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
8 #include <fstream>
9 
10 LArPhysCaliTDiffAlg::LArPhysCaliTDiffAlg(const std::string & name, ISvcLocator * pSvcLocator) :
11  LArCond2NtupleBase(name,pSvcLocator) {
12 
13  declareProperty("InputContainer",m_inputContainer="LArPhysCaliTdiffIn");
14  declareProperty("OutputContainer",m_outputContainer="LArPhysCaliTdiff");
15  declareProperty("FileName",m_fileName);
16  declareProperty("PerFebMGCorr",m_perFebMG=false);
17 }
18 
20 
21 
23 
24  m_ntTitle="TimeDiffs";
25  m_ntpath=std::string("/NTUPLES/FILE1/TIMEDIFF");
27 }
28 
30 
31 
32  NTuple::Item<float> ntold, ntnew, ntoffset, ntcorr;
33  NTuple::Item<long> ntgain;
34 
35  CHECK(m_nt->addItem("gain",ntgain,0,3));
36  CHECK(m_nt->addItem("PCDiffOld",ntold,-200,200));
37  CHECK(m_nt->addItem("PCDiffNew",ntnew,-200,200));
38  if(!m_perFebMG) CHECK(m_nt->addItem("offset",ntoffset,0,200));
39  CHECK(m_nt->addItem("correction",ntcorr,0,200));
40 
41 
42  const LArOnlineID* onlineID=nullptr;
43  CHECK(detStore()->retrieve(onlineID));
44 
45  std::vector<std::map<HWIdentifier,float> > offsetMap;
46  if(m_perFebMG) offsetMap.resize(2); else offsetMap.resize(3);
47  std::ifstream rein(m_fileName.c_str(),std::ifstream::in);
48  if (!rein.good()) {
49  ATH_MSG_ERROR( "Failed to open file " << m_fileName );
50  return StatusCode::SUCCESS;
51  }
52 
53 
54  while (rein.good()) {
55  unsigned gain,chidint;
56  float offset;
57  if(m_perFebMG) {
58  rein >> std::hex>>chidint >>std::dec>> offset;
59  const HWIdentifier fid(chidint);
60  offsetMap[1][fid]=offset;
61  //std::cout <<std::hex<< fid <<std::dec<< " " << offset << std::endl;
62  } else {
63  rein >> chidint >> gain >> offset;
64  const HWIdentifier fid(chidint);
65  offsetMap[gain][fid]=offset;
66  }
67  }
68 
69  rein.close();
70 
71  const LArPhysCaliTdiffComplete* oldCont=nullptr;
73 
76  CHECK(newCont->initialize());
77  StatusCode sc=detStore()->record(newCont,m_outputContainer);
78  if(sc!=StatusCode::SUCCESS) {
79  ATH_MSG_ERROR( "Failed to register container with key " << m_outputContainer << " to StoreGate" );
80  }
81 
82  for (int gain=0;gain<3;++gain) {
83  ATH_MSG_INFO( "Working on gain " << gain );
86  for (;it!=it_e;++it) {
87  const HWIdentifier chid=it.channelId();
88  const HWIdentifier fid=onlineID->feb_Id(chid);
89  const LArPhysCaliTdiffP& td=*it;
90  if (td.isEmpty()) {
91  ATH_MSG_DEBUG("Channel " << onlineID->channel_name(chid) << " has no data");
92  continue;
93  }
94  float timediff=td.m_Tdiff;
95  ntold=timediff;
96  if(m_perFebMG && gain != 1) {// do nothing if we are only correcting MG per FEB
97  newCont->set(chid,gain,timediff);
98  continue;
99  }
100  if(!m_perFebMG) {
101  ntoffset=offsetMap[gain][fid];
102  int refGain=0;
103  if (onlineID->isHECchannel(chid)) refGain=1;
104 
105  if (gain>refGain) {
106  ntcorr=offsetMap[gain][fid]-offsetMap[refGain][fid];
107  const float correction=offsetMap[gain][fid]-offsetMap[refGain][fid];
109  } else ntcorr=-999;
110  } else {
111  ntcorr=offsetMap[gain][fid];
112  const float correction=offsetMap[gain][fid];
114  }
115 
116  newCont->set(chid,gain,timediff);
117  ntnew=timediff;
118  fillFromIdentifier(chid);
119  ntgain=gain;
120  ATH_MSG_DEBUG("Gain " << gain << " Ch:" << onlineID->channel_name(chid) << ":" << td.m_Tdiff << " -> " << timediff);
121 
122 
123  sc=ntupleSvc()->writeRecord(m_nt);
124  if (sc!=StatusCode::SUCCESS) {
125  ATH_MSG_ERROR( "writeRecord failed" );
126  return StatusCode::FAILURE;
127  }
128 
129  }//end loop over all channels
130  std::cout<<"2"<<std::endl;
131  }//end loop over gains
132 
133 
134  return StatusCode::SUCCESS;
135 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArPhysCaliTDiffAlg::LArPhysCaliTDiffAlg
LArPhysCaliTDiffAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArPhysCaliTDiffAlg.cxx:10
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArConditionsContainerBase::ExtendedSubDetGrouping
@ ExtendedSubDetGrouping
Definition: LArConditionsContainerBase.h:50
LArConditionsContainerDB::iteratorT
Declaration of const iterator.
Definition: LArConditionsContainerDB.h:72
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
skel.it
it
Definition: skel.GENtoEVGEN.py:407
HWIdentifier
Definition: HWIdentifier.h:13
LArCond2NtupleBase::initialize
StatusCode initialize()
Definition: LArCond2NtupleBase.cxx:33
LArPhysCaliTDiffAlg::~LArPhysCaliTDiffAlg
virtual ~LArPhysCaliTDiffAlg()
LArCond2NtupleBase
Definition: LArCond2NtupleBase.h:32
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
tools.zlumi_mc_cf.correction
def correction(mu, runmode, campaign, run=None)
Definition: zlumi_mc_cf.py:4
LArPhysCaliTdiffP
Definition: LArPhysCaliTdiffP.h:11
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LArPhysCaliTDiffAlg::m_outputContainer
std::string m_outputContainer
Definition: LArPhysCaliTDiffAlg.h:28
LArConditionsContainer::end
ConstConditionsMapIterator end(unsigned int gain) const
end of all channels for this gain
LArPhysCaliTDiffAlg::m_inputContainer
std::string m_inputContainer
Definition: LArPhysCaliTDiffAlg.h:27
LArPhysCaliTdiffComplete
This class implements the ILArPhysCaliTdiff interface ` *.
Definition: LArPhysCaliTdiffComplete.h:22
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition: AthCommonDataStore.h:145
LArCond2NtupleBase::m_ntpath
std::string m_ntpath
Definition: LArCond2NtupleBase.h:65
LArCond2NtupleBase::m_nt
NTuple::Tuple * m_nt
Definition: LArCond2NtupleBase.h:68
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
LArOnlineID_Base::feb_Id
HWIdentifier feb_Id(int barrel_ec, int pos_neg, int feedthrough, int slot) const
Create feb_Id from fields.
Definition: LArOnlineID_Base.cxx:1479
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
LArCond2NtupleBase::m_ntTitle
std::string m_ntTitle
Definition: LArCond2NtupleBase.h:65
LArPhysCaliTdiffP::m_Tdiff
float m_Tdiff
Definition: LArPhysCaliTdiffP.h:17
LArOnlineID
Definition: LArOnlineID.h:20
LArPhysCaliTDiffAlg::m_perFebMG
bool m_perFebMG
Definition: LArPhysCaliTDiffAlg.h:31
LArCond2NtupleBase::fillFromIdentifier
bool fillFromIdentifier(const HWIdentifier &id)
Definition: LArCond2NtupleBase.cxx:288
LArPhysCaliTdiffP::isEmpty
bool isEmpty() const
Definition: LArPhysCaliTdiffP.h:17
LArConditionsContainer::initialize
virtual StatusCode initialize()
Initialization done after creation or read back - derived classes may augment the functionality.
LArPhysCaliTDiffAlg::m_fileName
std::string m_fileName
Definition: LArPhysCaliTDiffAlg.h:29
LArPhysCaliTDiffAlg::initialize
StatusCode initialize()
Definition: LArPhysCaliTDiffAlg.cxx:22
LArPhysCaliTDiffAlg.h
LArConditionsContainer::begin
ConstConditionsMapIterator begin(unsigned int gain) const
get iterator for all channels for a gain
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
LArPhysCaliTdiffComplete.h
LArPhysCaliTDiffAlg::execute
StatusCode execute()
Definition: LArPhysCaliTDiffAlg.cxx:29
LArOnlineID::isHECchannel
bool isHECchannel(const HWIdentifier id) const override final
Definition: LArOnlineID.cxx:720
LArOnlineID_Base::channel_name
std::string channel_name(const HWIdentifier id) const
Return a string corresponding to a feedthrough name given an identifier.
Definition: LArOnlineID_Base.cxx:221
python.LArCalib_HVCorrConfig.timediff
timediff
Definition: LArCalib_HVCorrConfig.py:95
ntupleSvc
INTupleSvc * ntupleSvc()
Definition: ServiceAccessor.h:14
LArPhysCaliTdiffComplete::set
void set(const HWIdentifier &CellID, int gain, float tdiff)
Definition: LArPhysCaliTdiffComplete.cxx:27