ATLAS Offline Software
egDetailContainerCnv_p2.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // egDetailContainerCnv_p2.cxx
8 // Implementation file for class egDetailContainerCnv_p2
10 
11 
13 
14 // egammaEventTPCnv includes
16 
17 #include "egammaEvent/EMShower.h"
19 #include "egammaEvent/EMConvert.h"
20 #include "egammaEvent/EMBremFit.h"
21 #include "egammaEvent/EMTrackFit.h"
23 
24 #include <cfloat>
25 
26 #ifdef MSG_DEBUG
27 #undef MSG_DEBUG
28 #endif
29 #define MSG_DEBUG(log, x) \
30  do { if (log.level()<=MSG::DEBUG) { log << MSG::DEBUG << x << endmsg; } } while (0)
31 
32 
34  egDetailContainer *trans,
35  MsgStream &msg )
36 {
37  trans->clear();
38  egDetailContainer_p2::const_iterator it = pers->begin();
39 
40  for( ; it != pers->end(); ++it ){
41 
42  const std::vector<float>& egParams = it->m_egDetailFloatParams;
43  const std::vector<unsigned int>& egEnum = it->m_egDetailEnumParams;
44  // if you crash here, then there is a data corruption...
45  assert( egEnum.size() == egParams.size() );
46 
47  if ( it->m_className == "EMShower" ) {
48 
49  EMShower *tmpEMShower = new EMShower();
50  for ( unsigned int i=0; i< egEnum.size(); i++ ) {
51  if ( tmpEMShower->hasParameter( (egammaParameters::ParamDef) egEnum[i]) ) {
52  tmpEMShower->set_parameter((egammaParameters::ParamDef) egEnum[i],egParams[i]);
53  }
54  else {
55  msg << MSG::ERROR << "Read unknown parameter for " << it->m_className
56  << " Index " << egEnum[i] << endmsg;
57  continue;
58  }
59  }
60  trans->push_back(tmpEMShower);
61 
62  }
63  else if ( it->m_className == "EMTrackMatch" ) {
64 
65  EMTrackMatch *tmpEMTrackMatch = new EMTrackMatch();
66  for ( unsigned int i=0; i< egEnum.size(); i++ ) {
68  static_cast<egammaParameters::ParamDef> (egEnum[i]);
69  if (key == egammaParameters::EoverP) continue;
72  if ( tmpEMTrackMatch->hasParameter( key ) ) {
73  tmpEMTrackMatch->set_parameter(key, egParams[i]);
74  }
75  else {
76  msg << MSG::ERROR << "Read unknown parameter for "
77  << it->m_className << " Index " << key << endmsg;
78  continue;
79  }
80  }
81  trans->push_back(tmpEMTrackMatch);
82 
83  }
84  else if ( it->m_className == "EMConvert" ) {
85 
86  EMConvert *tmpEMConvert = new EMConvert();
87  for ( unsigned int i=0; i< egEnum.size(); i++ ) {
88  if ( tmpEMConvert->hasParameter( (egammaParameters::ParamDef) egEnum[i]) ) {
89  tmpEMConvert->set_parameter((egammaParameters::ParamDef) egEnum[i],egParams[i]);
90  }
91  else {
92  msg << MSG::ERROR << "Read unknown parameter for " << it->m_className
93  << " Index " << egEnum[i] << endmsg;
94  continue;
95  }
96  }
97  trans->push_back(tmpEMConvert);
98 
99  }
100  else if ( it->m_className == "EMBremFit" ) {
101 
102  EMBremFit *tmpEMBremFit = new EMBremFit();
103  for ( unsigned int i=0; i< egEnum.size(); i++ ) {
104  if ( tmpEMBremFit->hasParameter( (egammaParameters::ParamDef) egEnum[i]) ) {
105  tmpEMBremFit->set_parameter((egammaParameters::ParamDef) egEnum[i],egParams[i]);
106  }
107  else {
108  msg << MSG::ERROR << "Read unknown parameter for " << it->m_className
109  << " Index " << egEnum[i] << endmsg;
110  continue;
111  }
112  }
113  trans->push_back(tmpEMBremFit);
114  }
115  else if ( it->m_className == "EMTrackFit" ) {
116 
117  EMTrackFit *tmpEMTrackFit = new EMTrackFit();
118  for ( unsigned int i=0; i< egEnum.size(); i++ ) {
119  if ( tmpEMTrackFit->hasParameter( (egammaParameters::ParamDef) egEnum[i]) ) {
120  tmpEMTrackFit->set_parameter((egammaParameters::ParamDef) egEnum[i],egParams[i]);
121  }
122  else {
123  msg << MSG::ERROR << "Read unknown parameter for " << it->m_className
124  << " Index " << egEnum[i] << endmsg;
125  continue;
126  }
127  }
128  trans->push_back(tmpEMTrackFit);
129 
130  }
131  else if ( it->m_className == "EMErrorDetail" ) {
132 
133  EMErrorDetail *tmpEMErrorDetail = new EMErrorDetail();
134  for ( unsigned int i=0; i< egEnum.size(); i++ ) {
135  if ( tmpEMErrorDetail->hasParameter( (egammaParameters::ParamDef) egEnum[i]) ) {
136  tmpEMErrorDetail->set_parameter((egammaParameters::ParamDef) egEnum[i],egParams[i]);
137  }
138  else {
139  msg << MSG::ERROR << "Read unknown parameter for " << it->m_className
140  << " Index " << egEnum[i] << endmsg;
141  continue;
142  }
143  }
144  trans->push_back(tmpEMErrorDetail);
145 
146  }
147  else {
148  msg << MSG::ERROR << "Read unknown egDetail type: " << it->m_className << endmsg;
149  continue;
150  }
151  // trans = (dynamic_cast<EMShower*>(trans));
152 
153  }
154 
155  MSG_DEBUG(msg, "finished egDetailContainer perstoTrans");
156 }
157 
159  egDetailContainer_p2 *pers,
160  MsgStream &msg )
161 {
163  for( ; it != trans->end(); ++it ){
164 
166  std::vector<float>& egParam = detail.m_egDetailFloatParams;
167  std::vector<unsigned int>& egEnum = detail.m_egDetailEnumParams;
168 
169  unsigned int nbOfEgammaParams = (int) egammaParameters::lastEgammaParam;
170  // first we need to cast
171  const EMShower *tmpEMShower = dynamic_cast<const EMShower*> (*it);
172  const EMTrackMatch *tmpEMTrackMatch = dynamic_cast<const EMTrackMatch*> (*it);
173  const EMConvert *tmpEMConvert = dynamic_cast<const EMConvert*> (*it);
174  const EMBremFit *tmpEMBremFit = dynamic_cast<const EMBremFit*> (*it);
175  const EMTrackFit *tmpEMTrackFit = dynamic_cast<const EMTrackFit*> (*it);
176  const EMErrorDetail *tmpEMErrorDetail = dynamic_cast<const EMErrorDetail*> (*it);
177  if ( !tmpEMShower &&
178  !tmpEMTrackMatch &&
179  !tmpEMConvert &&
180  !tmpEMBremFit &&
181  !tmpEMTrackFit &&
182  !tmpEMErrorDetail ) {
183  msg << MSG::ERROR << "Unknown egDetail type will not write its data" << endmsg;
184  continue;
185  }
186 
187  double tmpParam;
188  if ( tmpEMShower ) {
189  MSG_DEBUG(msg, "decoded detail as " << tmpEMShower->className());
190  detail.m_className = tmpEMShower->className();
191  for ( unsigned int i=0; i<nbOfEgammaParams; i++ ) {
192  tmpParam = tmpEMShower->parameter( (egammaParameters::ParamDef)i);
193  if ( tmpParam != egammaParameters::EgParamUndefined ) {
194  if (tmpParam > FLT_MAX) tmpParam = FLT_MAX;
195  if (tmpParam < - FLT_MAX) tmpParam = - FLT_MAX;
196  egEnum.push_back(i);
197  egParam.push_back(tmpParam);
198  }
199  }
200  }
201  else if ( tmpEMTrackMatch ) {
202  MSG_DEBUG(msg, "decoded detail as " << tmpEMTrackMatch->className());
203  detail.m_className = tmpEMTrackMatch->className();
204  for ( unsigned int i=0; i<nbOfEgammaParams; i++ ) {
205  tmpParam = tmpEMTrackMatch->parameter( (egammaParameters::ParamDef)i);
206  if ( tmpParam != egammaParameters::EgParamUndefined ) {
207  if (tmpParam > FLT_MAX) tmpParam = FLT_MAX;
208  if (tmpParam < - FLT_MAX) tmpParam = - FLT_MAX;
209  egEnum.push_back(i);
210  egParam.push_back(tmpParam);
211  }
212  }
213  }
214  else if ( tmpEMConvert ) {
215  MSG_DEBUG(msg, "decoded detail as " << tmpEMConvert->className());
216  detail.m_className = tmpEMConvert->className();
217  for ( unsigned int i=0; i<nbOfEgammaParams; i++ ) {
218  tmpParam = tmpEMConvert->parameter( (egammaParameters::ParamDef)i);
219  if ( tmpParam != egammaParameters::EgParamUndefined ) {
220  if (tmpParam > FLT_MAX) tmpParam = FLT_MAX;
221  if (tmpParam < - FLT_MAX) tmpParam = - FLT_MAX;
222  egEnum.push_back(i);
223  egParam.push_back(tmpParam);
224  }
225  }
226  }
227  else if ( tmpEMBremFit ) {
228  MSG_DEBUG(msg, "decoded detail as " << tmpEMBremFit->className());
229  detail.m_className = tmpEMBremFit->className();
230  for ( unsigned int i=0; i<nbOfEgammaParams; i++ ) {
231  tmpParam = tmpEMBremFit->parameter( (egammaParameters::ParamDef)i);
232  if ( tmpParam != egammaParameters::EgParamUndefined ) {
233  if (tmpParam > FLT_MAX) tmpParam = FLT_MAX;
234  if (tmpParam < - FLT_MAX) tmpParam = - FLT_MAX;
235  egEnum.push_back(i);
236  egParam.push_back(tmpParam);
237  }
238  }
239  }
240  else if ( tmpEMTrackFit ) {
241  MSG_DEBUG(msg, "decoded detail as " << tmpEMTrackFit->className());
242  detail.m_className = tmpEMTrackFit->className();
243  for ( unsigned int i=0; i<nbOfEgammaParams; i++ ) {
244  tmpParam = tmpEMTrackFit->parameter( (egammaParameters::ParamDef)i);
245  if ( tmpParam != egammaParameters::EgParamUndefined ) {
246  if (tmpParam > FLT_MAX) tmpParam = FLT_MAX;
247  if (tmpParam < - FLT_MAX) tmpParam = - FLT_MAX;
248  egEnum.push_back(i);
249  egParam.push_back(tmpParam);
250  }
251  }
252  }
253  else if ( tmpEMErrorDetail ) {
254  MSG_DEBUG(msg, "decoded detail as " << tmpEMErrorDetail->className());
255  detail.m_className = tmpEMErrorDetail->className();
256  for ( unsigned int i=0; i<nbOfEgammaParams; i++ ) {
257  tmpParam = tmpEMErrorDetail->parameter( (egammaParameters::ParamDef)i);
258  if ( tmpParam != egammaParameters::EgParamUndefined ) {
259  if (tmpParam > FLT_MAX) tmpParam = FLT_MAX;
260  if (tmpParam < - FLT_MAX) tmpParam = - FLT_MAX;
261  egEnum.push_back(i);
262  egParam.push_back(tmpParam);
263  }
264  }
265  }
266 
267  pers->push_back( detail );
268  }
269 
270 }
EMConvert
Definition: EMConvert.h:35
EMTrackMatch
Definition: EMTrackMatch.h:20
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
EMBremFit::set_parameter
void set_parameter(egammaParameters::ParamDef, double, bool overwrite=false)
general set method for parameters
Definition: EMBremFit.cxx:66
EMTrackMatch::parameter
virtual double parameter(egammaParameters::ParamDef) const override
Definition: EMTrackMatch.cxx:109
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
skel.it
it
Definition: skel.GENtoEVGEN.py:396
EMConvert::hasParameter
virtual bool hasParameter(egammaParameters::ParamDef) const
Definition: EMConvert.cxx:65
egammaParameters::ParamDef
ParamDef
Definition: egammaParamDefs.h:99
egDetailContainer.h
EMTrackMatch::hasParameter
virtual bool hasParameter(egammaParameters::ParamDef) const override
Definition: EMTrackMatch.cxx:445
detail
Definition: extract_histogram_tag.cxx:14
EMErrorDetail::hasParameter
virtual bool hasParameter(egammaParameters::ParamDef) const
EMConvert::parameter
virtual double parameter(egammaParameters::ParamDef) const
general parameter retrieval
Definition: EMConvert.cxx:161
egammaParameters::EgParamUndefined
const double EgParamUndefined
Definition: egammaParamDefs.h:78
EMErrorDetail::set_parameter
void set_parameter(egammaParameters::ParamDef, double, bool overwrite=false)
general set method for parameters
Definition: EMErrorDetail.cxx:98
EMBremFit::hasParameter
virtual bool hasParameter(egammaParameters::ParamDef) const
Definition: EMBremFit.cxx:201
EMShower::parameter
virtual double parameter(egammaParameters::ParamDef) const
Definition: EMShower.cxx:71
EMTrackFit::hasParameter
virtual bool hasParameter(egammaParameters::ParamDef) const
EMTrackFit
Definition: EMTrackFit.h:35
EMShower
Definition: EMShower.h:24
egDetailContainerCnv_p2::transToPers
virtual void transToPers(const egDetailContainer *transObj, egDetailContainer_p2 *persObj, MsgStream &msg)
Definition: egDetailContainerCnv_p2.cxx:158
EMErrorDetail::parameter
virtual double parameter(egammaParameters::ParamDef) const
Definition: EMErrorDetail.cxx:52
lumiFormat.i
int i
Definition: lumiFormat.py:85
egDetailContainer_p2
Definition: egDetailContainer_p2.h:21
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EMTrackFit.h
EMErrorDetail.h
EMErrorDetail
Definition: EMErrorDetail.h:30
EMTrackMatch::set_parameter
void set_parameter(egammaParameters::ParamDef, double, bool overwrite=false)
Definition: EMTrackMatch.cxx:132
EMShower::className
virtual const std::string & className() const
Definition: EMShower.cxx:65
DataVector::clear
void clear()
Erase all the elements in the collection.
egammaParameters::lastEgammaParam
@ lastEgammaParam
Definition: egammaParamDefs.h:809
EMTrackFit::className
virtual const std::string & className() const
Definition: EMTrackFit.cxx:47
EMTrackFit::parameter
virtual double parameter(egammaParameters::ParamDef) const
Definition: EMTrackFit.cxx:53
MSG_DEBUG
#define MSG_DEBUG(log, x)
Definition: egDetailContainerCnv_p2.cxx:29
egDetail_p2
Definition: egDetail_p2.h:22
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
EMShower.h
EMTrackFit::set_parameter
void set_parameter(egammaParameters::ParamDef, double, bool overwrite=false)
general set method for parameters
Definition: EMTrackFit.cxx:76
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
EMBremFit
Definition: EMBremFit.h:27
egammaParameters::EtaCorrMag
@ EtaCorrMag
eta of the track extrapolated to the first sampling (NB : should be equivalent to etaSampling1
Definition: egammaParamDefs.h:197
EMErrorDetail::className
virtual const std::string & className() const
Definition: EMErrorDetail.cxx:29
EMTrackMatch::className
virtual const std::string & className() const override
interface methods
Definition: EMTrackMatch.cxx:102
EMShower::set_parameter
void set_parameter(egammaParameters::ParamDef, double, bool overwrite=false)
Definition: EMShower.cxx:90
EMShower::hasParameter
virtual bool hasParameter(egammaParameters::ParamDef) const
Definition: EMShower.cxx:227
EMBremFit::parameter
virtual double parameter(egammaParameters::ParamDef) const
Definition: EMBremFit.cxx:45
egDetailContainerCnv_p2::persToTrans
virtual void persToTrans(const egDetailContainer_p2 *persObj, egDetailContainer *transObj, MsgStream &msg)
Definition: egDetailContainerCnv_p2.cxx:33
EMBremFit::className
virtual const std::string & className() const
Definition: EMBremFit.cxx:40
egammaParameters::etaSampling1
@ etaSampling1
eta position at sampling 1 for track extrapolated from the last hit.
Definition: egammaParamDefs.h:599
egammaParameters::EoverP
@ EoverP
ratio of the cluster energy and the track momentum
Definition: egammaParamDefs.h:199
EMConvert::className
virtual const std::string & className() const
Definition: EMConvert.cxx:155
EMTrackMatch.h
egDetailContainer
Definition: egDetailContainer.h:18
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
EMConvert.h
EMConvert::set_parameter
void set_parameter(egammaParameters::ParamDef, double, bool overwrite=false)
general parameter setting
Definition: EMConvert.cxx:222
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
egDetailContainerCnv_p2.h
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
EMBremFit.h