20 #include "CLHEP/Units/SystemOfUnits.h"
24 using namespace std::string_literals;
34 const std::string&
name,
40 m_MinClusterEnergyToDeal(200.0*
MeV),
41 m_MinLookupBinNentry(40),
42 m_MinCellEnergyToDeal(0.0),
43 m_MaxChangeInCellWeight(30.0),
44 m_useHadProbability(false),
48 declareInterface<IClusterCellWeightTool>(
this);
87 msg() << (*it2) <<
" ";
93 std::vector<int > *vtmp=
nullptr;
94 if((*it).first ==
"AREA_DMFIT") {
96 }
else if((*it).first ==
"AREA_DMLOOKUP") {
98 }
else if((*it).first ==
"AREA_DMSMPW") {
101 msg(MSG::WARNING) <<
"Unkown dead material area type '" << (*it).first <<
"'" << std::endl;
107 vtmp->push_back(
int(
id));
109 ATH_MSG_WARNING(
"Dimension '" << (*it2) <<
"' is invalid and will be excluded." );
120 return StatusCode::SUCCESS;
133 float wrong_dm_energy = 0.0;
134 float dm_total = 0.0;
137 double weightMom (1);
138 if (!theCluster->
retrieveMoment(CaloCluster::DM_WEIGHT,weightMom)) {
145 double eWeighted = theCluster->
e();
165 set_zero_moments(theCluster);
167 return StatusCode::SUCCESS;
173 ATH_MSG_ERROR(
"Cannot retrieve EM_PROBABILITY cluster moment, "
174 <<
" cluster energy " << theCluster->
e() <<
" remains the same." );
175 return StatusCode::FAILURE;
179 }
else if ( pi0Prob > 1 ) {
186 double center_lambda = 0;
188 ATH_MSG_ERROR(
"Cannot retrieve CENTER_LAMBDA cluster moment, "
189 <<
" cluster energy " << theCluster->
e() <<
" remains the same." );
190 return StatusCode::FAILURE;
198 return StatusCode::FAILURE;
201 ATH_MSG_DEBUG(
"Cluster is selected for local DM calibration."
202 <<
" Old cluster energy:" << theCluster->
e()
206 std::vector<Area> areas;
207 std::vector<Cell>
cells;
209 float cls_unweighted_energy = 0;
211 smp_energy, cls_unweighted_energy,
data);
212 if ( !
sc.isSuccess() ) {
214 set_zero_moments(theCluster);
220 float cls_initial_energy = theCluster->
e();
221 float cls_side = (theCluster->
eta()<0?-1.0:1.0);
222 float cls_eta = fabs(theCluster->
eta());
223 float cls_phi = theCluster->
phi();
224 float log10ener = 0.0;
225 if(cls_unweighted_energy > 0.0) {
226 log10ener = log10(cls_unweighted_energy);
229 if(center_lambda > 0.0) {
230 log10lambda = log10(center_lambda);
231 if(log10lambda >=4.0) log10lambda = 3.9999;
235 #ifdef DEBUG_DMTHINGS
236 std::cout <<
" cls_initial_energy: " << cls_initial_energy <<
" cls_eta: " << cls_eta << std::endl;
237 std::cout <<
" log10ener: " << log10ener <<
" log10lambda: " << log10lambda << std::endl;
239 std::cout <<
" i_smp: " << i_smp <<
" smp_energy: " << smp_energy[i_smp] << std::endl;
243 std::vector<float > vars;
252 size_t n_dm =
data->getSizeAreaSet();
255 for(
int i_mix=0; i_mix<2; i_mix++){
256 float mixWeight = (i_mix==0?(1-pi0Prob):pi0Prob);
257 if(mixWeight == 0)
continue;
262 for(
size_t i_dm=0; i_dm < n_dm; i_dm++){
263 if(areas[i_dm].eprep <= 0.0)
continue;
267 if(log10ener > emax) log10ener = emax - 0.0001;
271 if( !
pars )
continue;
293 const int nSmp=
pars->size()-1;
295 double ecalonew = 0.0;
296 double ecaloold = 0.0;
297 for(
int i_smp=0; i_smp<nSmp; i_smp++){
298 ecaloold += smp_energy[i_smp];
299 ecalonew += smp_energy[i_smp] * (*pars)[i_smp];
301 ecalonew += (*pars)[nSmp];
302 edm = ecalonew - ecaloold;
319 std::cout <<
"CaloLCDeadMaterialTool -> Error! Unknown correction type " <<
area->getType()
320 <<
" with number of parameters " <<
area->getNpars() << std::endl;
322 wrong_dm_energy += areas[i_dm].edm_wrong;
324 #ifdef DEBUG_DMTHINGS
325 std::cout <<
" result> edm: " << edm <<
" edm_wrong:" << edm_wrong << std::endl;
327 edm -= areas[i_dm].edm_wrong;
329 areas[i_dm].erec = areas[i_dm].erec + edm*mixWeight;
340 #ifdef DEBUG_DMTHINGS
341 std::cout <<
"wc> calculation of weights" << std::endl;
347 theCluster->
setE(cls_initial_energy + dm_total - wrong_dm_energy);
352 float sub_ener_old = 0.0;
353 for(
size_t i_c = 0; i_c <
cells.size(); i_c++)
357 sub_ener_old +=
cell.weight*
cell.energy;
359 if(sub_ener_old > 0.0) {
360 float corr = (sub_ener_old + dm_total)/sub_ener_old;
361 for(
size_t i_c = 0; i_c <
cells.size(); i_c++)
364 cells[i_c].weight *= corr;
372 for (
size_t cell_index = 0; cell_index <
cells.size(); ++cell_index)
376 float we =
cell.weight *
cell.energy;
378 areas[
cell.dm].sub_ener_old += we;
384 for(
size_t i_dm=0; i_dm < areas.size(); i_dm++) {
385 Area& dma = areas[i_dm];
387 if (i_dm >= n_dm || dma.
eprep <= 0)
403 for (
size_t cell_index = 0; cell_index <
cells.size(); ++cell_index)
409 cell.weight *= gblfac;
420 for (;itrCell!=itrCellEnd; ++itrCell) {
422 const float old_weight = itrCell.weight();
423 float new_weight =
cells[cell_index].weight;
427 new_weight = old_weight;
429 #ifdef DEBUG_DMTHINGS
430 std::cout <<
" cells> " << cell_index <<
" ener: " <<
cells[cell_index].energy <<
" old_w: " << old_weight <<
" new_w:" << new_weight << std::endl;
431 if( new_weight > 100) std::cout <<
"DeadMaterialCorrectionTool2 -> Panic! Too large weight" << std::endl;
441 <<
" (contains wrongly estimated DM energy: " << wrong_dm_energy <<
")"
442 <<
" calculated DM energy (to be added):" << dm_total
443 <<
" new cluster energy:" << theCluster->
e());
464 x = (
double)(dm_total+wrong_dm_energy);
467 for(
size_t i_dm=0; i_dm < areas.size(); i_dm++) {
468 Area& dma = areas[i_dm];
485 if ( eWeighted > 0 || eWeighted < 0 ) {
486 weightMom *= theCluster->
e()/eWeighted;
488 theCluster->
insertMoment(CaloCluster::DM_WEIGHT,weightMom);
490 return StatusCode::SUCCESS;
500 theCluster->
insertMoment(CaloCluster::ENG_RECO_EMB0, 0.0);
501 theCluster->
insertMoment(CaloCluster::ENG_RECO_EME0, 0.0);
502 theCluster->
insertMoment(CaloCluster::ENG_RECO_TILEG3, 0.0);
503 theCluster->
insertMoment(CaloCluster::ENG_RECO_DEAD_TOT, 0.0);
504 for(
size_t i_dm=0; i_dm < DeadMaterialCorrectionTool2::sDM; i_dm++) {
523 std::vector<Area>& areas,
524 std::vector<Cell>&
cells,
528 areas.resize(
data->getSizeAreaSet());
529 cells.reserve (theCluster->size());
535 CaloCluster::const_cell_iterator itrCell = theCluster->
cell_begin();
536 CaloCluster::const_cell_iterator itrCellEnd = theCluster->
cell_end();
537 cls_unweighted_energy = 0;
538 for (;itrCell!=itrCellEnd; ++itrCell) {
540 const CaloCell* thisCell = *itrCell;
546 float weight = itrCell.weight();
547 cls_unweighted_energy +=
energy;
554 smp_energy[nsmp] +=
energy;
626 areas[
sDM_FCAL].eprep = cls_unweighted_energy;
630 return StatusCode::SUCCESS;