20 #include "CLHEP/Units/SystemOfUnits.h"
33 const std::string&
name,
39 m_MinClusterEnergyToDeal(200.0*
MeV),
40 m_MinLookupBinNentry(40),
41 m_MinCellEnergyToDeal(0.0),
42 m_MaxChangeInCellWeight(30.0),
43 m_useHadProbability(false),
47 declareInterface<IClusterCellWeightTool>(
this);
59 std::vector<std::string > vstr;
62 vstr[1] =
"DIMD_ENER";
66 vstr[1] =
"DIMD_ENER";
67 vstr[2] =
"DIMD_LAMBDA";
71 vstr[1] =
"DIMD_LAMBDA";
93 msg(MSG::INFO) <<
"Interpolation is ON, dimensions: ";
95 msg(MSG::INFO) <<
" " << (*it).first <<
" (";
97 msg() << (*it2) <<
" ";
103 std::vector<int > *vtmp=
nullptr;
104 if((*it).first ==
"AREA_DMFIT") {
106 }
else if((*it).first ==
"AREA_DMLOOKUP") {
108 }
else if((*it).first ==
"AREA_DMSMPW") {
111 msg(MSG::WARNING) <<
"Unkown dead material area type '" << (*it).first <<
"'" << std::endl;
117 vtmp->push_back(
int(
id));
119 ATH_MSG_WARNING(
"Dimension '" << (*it2) <<
"' is invalid and will be excluded." );
130 return StatusCode::SUCCESS;
143 float wrong_dm_energy = 0.0;
144 float dm_total = 0.0;
147 double weightMom (1);
148 if (!theCluster->
retrieveMoment(CaloCluster::DM_WEIGHT,weightMom)) {
155 double eWeighted = theCluster->
e();
175 set_zero_moments(theCluster);
177 return StatusCode::SUCCESS;
183 ATH_MSG_ERROR(
"Cannot retrieve EM_PROBABILITY cluster moment, "
184 <<
" cluster energy " << theCluster->
e() <<
" remains the same." );
185 return StatusCode::FAILURE;
189 }
else if ( pi0Prob > 1 ) {
196 double center_lambda = 0;
198 ATH_MSG_ERROR(
"Cannot retrieve CENTER_LAMBDA cluster moment, "
199 <<
" cluster energy " << theCluster->
e() <<
" remains the same." );
200 return StatusCode::FAILURE;
208 return StatusCode::FAILURE;
211 ATH_MSG_DEBUG(
"Cluster is selected for local DM calibration."
212 <<
" Old cluster energy:" << theCluster->
e()
216 std::vector<Area> areas;
217 std::vector<Cell>
cells;
219 float cls_unweighted_energy = 0;
221 smp_energy, cls_unweighted_energy,
data);
222 if ( !
sc.isSuccess() ) {
224 set_zero_moments(theCluster);
230 float cls_initial_energy = theCluster->
e();
231 float cls_side = (theCluster->
eta()<0?-1.0:1.0);
232 float cls_eta = fabs(theCluster->
eta());
233 float cls_phi = theCluster->
phi();
234 float log10ener = 0.0;
235 if(cls_unweighted_energy > 0.0) {
236 log10ener = log10(cls_unweighted_energy);
239 if(center_lambda > 0.0) {
240 log10lambda = log10(center_lambda);
241 if(log10lambda >=4.0) log10lambda = 3.9999;
245 #ifdef DEBUG_DMTHINGS
246 std::cout <<
" cls_initial_energy: " << cls_initial_energy <<
" cls_eta: " << cls_eta << std::endl;
247 std::cout <<
" log10ener: " << log10ener <<
" log10lambda: " << log10lambda << std::endl;
249 std::cout <<
" i_smp: " << i_smp <<
" smp_energy: " << smp_energy[i_smp] << std::endl;
253 std::vector<float > vars;
262 size_t n_dm =
data->getSizeAreaSet();
265 for(
int i_mix=0; i_mix<2; i_mix++){
266 float mixWeight = (i_mix==0?(1-pi0Prob):pi0Prob);
267 if(mixWeight == 0)
continue;
272 for(
size_t i_dm=0; i_dm < n_dm; i_dm++){
273 if(areas[i_dm].eprep <= 0.0)
continue;
277 if(log10ener > emax) log10ener = emax - 0.0001;
281 if( !
pars )
continue;
303 const int nSmp=
pars->size()-1;
305 double ecalonew = 0.0;
306 double ecaloold = 0.0;
307 for(
int i_smp=0; i_smp<nSmp; i_smp++){
308 ecaloold += smp_energy[i_smp];
309 ecalonew += smp_energy[i_smp] * (*pars)[i_smp];
311 ecalonew += (*pars)[nSmp];
312 edm = ecalonew - ecaloold;
329 std::cout <<
"CaloLCDeadMaterialTool -> Error! Unknown correction type " <<
area->getType()
330 <<
" with number of parameters " <<
area->getNpars() << std::endl;
332 wrong_dm_energy += areas[i_dm].edm_wrong;
334 #ifdef DEBUG_DMTHINGS
335 std::cout <<
" result> edm: " << edm <<
" edm_wrong:" << edm_wrong << std::endl;
337 edm -= areas[i_dm].edm_wrong;
339 areas[i_dm].erec = areas[i_dm].erec + edm*mixWeight;
350 #ifdef DEBUG_DMTHINGS
351 std::cout <<
"wc> calculation of weights" << std::endl;
357 theCluster->
setE(cls_initial_energy + dm_total - wrong_dm_energy);
362 float sub_ener_old = 0.0;
363 for(
size_t i_c = 0; i_c <
cells.size(); i_c++)
367 sub_ener_old +=
cell.weight*
cell.energy;
369 if(sub_ener_old > 0.0) {
370 float corr = (sub_ener_old + dm_total)/sub_ener_old;
371 for(
size_t i_c = 0; i_c <
cells.size(); i_c++)
374 cells[i_c].weight *= corr;
382 for (
size_t cell_index = 0; cell_index <
cells.size(); ++cell_index)
386 float we =
cell.weight *
cell.energy;
388 areas[
cell.dm].sub_ener_old += we;
394 for(
size_t i_dm=0; i_dm < areas.size(); i_dm++) {
395 Area& dma = areas[i_dm];
397 if (i_dm >= n_dm || dma.
eprep <= 0)
413 for (
size_t cell_index = 0; cell_index <
cells.size(); ++cell_index)
419 cell.weight *= gblfac;
430 for (;itrCell!=itrCellEnd; ++itrCell) {
432 const float old_weight = itrCell.weight();
433 float new_weight =
cells[cell_index].weight;
437 new_weight = old_weight;
439 #ifdef DEBUG_DMTHINGS
440 std::cout <<
" cells> " << cell_index <<
" ener: " <<
cells[cell_index].energy <<
" old_w: " << old_weight <<
" new_w:" << new_weight << std::endl;
441 if( new_weight > 100) std::cout <<
"DeadMaterialCorrectionTool2 -> Panic! Too large weight" << std::endl;
451 <<
" (contains wrongly estimated DM energy: " << wrong_dm_energy <<
")"
452 <<
" calculated DM energy (to be added):" << dm_total
453 <<
" new cluster energy:" << theCluster->
e());
474 x = (
double)(dm_total+wrong_dm_energy);
477 for(
size_t i_dm=0; i_dm < areas.size(); i_dm++) {
478 Area& dma = areas[i_dm];
495 if ( eWeighted > 0 || eWeighted < 0 ) {
496 weightMom *= theCluster->
e()/eWeighted;
498 theCluster->
insertMoment(CaloCluster::DM_WEIGHT,weightMom);
500 return StatusCode::SUCCESS;
510 theCluster->
insertMoment(CaloCluster::ENG_RECO_EMB0, 0.0);
511 theCluster->
insertMoment(CaloCluster::ENG_RECO_EME0, 0.0);
512 theCluster->
insertMoment(CaloCluster::ENG_RECO_TILEG3, 0.0);
513 theCluster->
insertMoment(CaloCluster::ENG_RECO_DEAD_TOT, 0.0);
514 for(
size_t i_dm=0; i_dm < DeadMaterialCorrectionTool2::sDM; i_dm++) {
533 std::vector<Area>& areas,
534 std::vector<Cell>&
cells,
538 areas.resize(
data->getSizeAreaSet());
539 cells.reserve (theCluster->size());
545 CaloCluster::const_cell_iterator itrCell = theCluster->
cell_begin();
546 CaloCluster::const_cell_iterator itrCellEnd = theCluster->
cell_end();
547 cls_unweighted_energy = 0;
548 for (;itrCell!=itrCellEnd; ++itrCell) {
550 const CaloCell* thisCell = *itrCell;
556 float weight = itrCell.weight();
557 cls_unweighted_energy +=
energy;
564 smp_energy[nsmp] +=
energy;
636 areas[
sDM_FCAL].eprep = cls_unweighted_energy;
640 return StatusCode::SUCCESS;