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 <ifstream>
9 #include <fstream>
10 
11 LArPhysCaliTDiffAlg::LArPhysCaliTDiffAlg(const std::string & name, ISvcLocator * pSvcLocator) :
12  LArCond2NtupleBase(name,pSvcLocator) {
13 
14  declareProperty("InputContainer",m_inputContainer="LArPhysCaliTdiffIn");
15  declareProperty("OutputContainer",m_outputContainer="LArPhysCaliTdiff");
16  declareProperty("FileName",m_fileName);
17  declareProperty("PerFebMGCorr",m_perFebMG=false);
18 }
19 
21 
22 
24 
25  m_ntTitle="TimeDiffs";
26  m_ntpath=std::string("/NTUPLES/FILE1/TIMEDIFF");
28 }
29 
31 
32 
33  NTuple::Item<float> ntold, ntnew, ntoffset, ntcorr;
34  NTuple::Item<long> ntgain;
35 
36  CHECK(m_nt->addItem("gain",ntgain,0,3));
37  CHECK(m_nt->addItem("PCDiffOld",ntold,-200,200));
38  CHECK(m_nt->addItem("PCDiffNew",ntnew,-200,200));
39  if(!m_perFebMG) CHECK(m_nt->addItem("offset",ntoffset,0,200));
40  CHECK(m_nt->addItem("correction",ntcorr,0,200));
41 
42 
43  const LArOnlineID* onlineID=nullptr;
44  CHECK(detStore()->retrieve(onlineID));
45 
46  std::vector<std::map<HWIdentifier,float> > offsetMap;
47  if(m_perFebMG) offsetMap.resize(2); else offsetMap.resize(3);
48  std::ifstream rein(m_fileName.c_str(),std::ifstream::in);
49  if (!rein.good()) {
50  ATH_MSG_ERROR( "Failed to open file " << m_fileName );
51  return StatusCode::SUCCESS;
52  }
53 
54 
55  while (rein.good()) {
56  unsigned gain,chidint;
57  float offset;
58  if(m_perFebMG) {
59  rein >> std::hex>>chidint >>std::dec>> offset;
60  const HWIdentifier fid(chidint);
61  offsetMap[1][fid]=offset;
62  //std::cout <<std::hex<< fid <<std::dec<< " " << offset << std::endl;
63  } else {
64  rein >> chidint >> gain >> offset;
65  const HWIdentifier fid(chidint);
66  offsetMap[gain][fid]=offset;
67  }
68  }
69 
70  rein.close();
71 
72  const LArPhysCaliTdiffComplete* oldCont=nullptr;
74 
77  CHECK(newCont->initialize());
78  StatusCode sc=detStore()->record(newCont,m_outputContainer);
79  if(sc!=StatusCode::SUCCESS) {
80  ATH_MSG_ERROR( "Failed to register container with key " << m_outputContainer << " to StoreGate" );
81  }
82 
83  for (int gain=0;gain<3;++gain) {
84  ATH_MSG_INFO( "Working on gain " << gain );
87  for (;it!=it_e;++it) {
88  const HWIdentifier chid=it.channelId();
89  const HWIdentifier fid=onlineID->feb_Id(chid);
90  const LArPhysCaliTdiffP& td=*it;
91  if (td.isEmpty()) {
92  ATH_MSG_DEBUG("Channel " << onlineID->channel_name(chid) << " has no data");
93  continue;
94  }
95  float timediff=td.m_Tdiff;
96  ntold=timediff;
97  if(m_perFebMG && gain != 1) {// do nothing if we are only correcting MG per FEB
98  newCont->set(chid,gain,timediff);
99  continue;
100  }
101  if(!m_perFebMG) {
102  ntoffset=offsetMap[gain][fid];
103  int refGain=0;
104  if (onlineID->isHECchannel(chid)) refGain=1;
105 
106  if (gain>refGain) {
107  ntcorr=offsetMap[gain][fid]-offsetMap[refGain][fid];
108  const float correction=offsetMap[gain][fid]-offsetMap[refGain][fid];
110  } else ntcorr=-999;
111  } else {
112  ntcorr=offsetMap[gain][fid];
113  const float correction=offsetMap[gain][fid];
115  }
116 
117  newCont->set(chid,gain,timediff);
118  ntnew=timediff;
119  fillFromIdentifier(chid);
120  ntgain=gain;
121  ATH_MSG_DEBUG("Gain " << gain << " Ch:" << onlineID->channel_name(chid) << ":" << td.m_Tdiff << " -> " << timediff);
122 
123 
124  sc=ntupleSvc()->writeRecord(m_nt);
125  if (sc!=StatusCode::SUCCESS) {
126  ATH_MSG_ERROR( "writeRecord failed" );
127  return StatusCode::FAILURE;
128  }
129 
130  }//end loop over all channels
131  std::cout<<"2"<<std::endl;
132  }//end loop over gains
133 
134 
135  return StatusCode::SUCCESS;
136 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArPhysCaliTDiffAlg::LArPhysCaliTDiffAlg
LArPhysCaliTDiffAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArPhysCaliTDiffAlg.cxx:11
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArConditionsContainerBase::ExtendedSubDetGrouping
@ ExtendedSubDetGrouping
Definition: LArConditionsContainerBase.h:50
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArConditionsContainerDB::iteratorT
Declaration of const iterator.
Definition: LArConditionsContainerDB.h:72
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
skel.it
it
Definition: skel.GENtoEVGEN.py:423
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
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:1483
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
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:23
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:30
LArOnlineID::isHECchannel
bool isHECchannel(const HWIdentifier id) const override final
Definition: LArOnlineID.cxx:734
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:218
python.LArCalib_HVCorrConfig.timediff
timediff
Definition: LArCalib_HVCorrConfig.py:81
ntupleSvc
INTupleSvc * ntupleSvc()
Definition: ServiceAccessor.h:14
LArPhysCaliTdiffComplete::set
void set(const HWIdentifier &CellID, int gain, float tdiff)
Definition: LArPhysCaliTdiffComplete.cxx:27