6 #include <calobase/RawTower.h>
7 #include <calobase/RawTowerContainer.h>
8 #include <calobase/RawTowerGeom.h>
9 #include <calobase/RawTowerGeomContainer.h>
11 #include <calobase/TowerInfo.h>
12 #include <calobase/TowerInfoContainer.h>
31 #include <TLorentzVector.h>
52 , _backgroundName(
"TestTowerBackground")
57 _UE.resize(3, std::vector<float>(1, 0));
69 std::cout <<
"DetermineTowerBackground::process_event: entering with do_flow = " <<
_do_flow <<
", seed type = " <<
_seed_type <<
", ";
72 else if (_seed_type == 1)
75 std::cout <<
" UNDEFINED seed behavior! " << std::endl;
91 towerinfosEM3 = findNode::getClass<TowerInfoContainer>(topNode,
"TOWERINFO_CALIB_CEMC_RETOWER");
92 towerinfosIH3 = findNode::getClass<TowerInfoContainer>(topNode,
"TOWERINFO_CALIB_HCALIN");
93 towerinfosOH3 = findNode::getClass<TowerInfoContainer>(topNode,
"TOWERINFO_CALIB_HCALOUT");
97 towersEM3 = findNode::getClass<RawTowerContainer>(topNode,
"TOWER_CALIB_CEMC_RETOWER");
98 towersIH3 = findNode::getClass<RawTowerContainer>(topNode,
"TOWER_CALIB_HCALIN");
99 towersOH3 = findNode::getClass<RawTowerContainer>(topNode,
"TOWER_CALIB_HCALOUT");
103 std::cout <<
"DetermineTowerBackground::process_event: " << towersEM3->
size() <<
" TOWER_CALIB_CEMC_RETOWER towers" << std::endl;
104 std::cout <<
"DetermineTowerBackground::process_event: " << towersIH3->size() <<
" TOWER_CALIB_HCALIN towers" << std::endl;
105 std::cout <<
"DetermineTowerBackground::process_event: " << towersOH3->size() <<
" TOWER_CALIB_HCALOUT towers" << std::endl;
110 RawTowerGeomContainer *geomIH = findNode::getClass<RawTowerGeomContainer>(topNode,
"TOWERGEOM_HCALIN");
111 RawTowerGeomContainer *geomOH = findNode::getClass<RawTowerGeomContainer>(topNode,
"TOWERGEOM_HCALOUT");
119 reco2_jets = findNode::getClass<JetContainer>(topNode,
"AntiKt_TowerInfo_HIRecoSeedsRaw_r02");
123 reco2_jets = findNode::getClass<JetContainer>(topNode,
"AntiKt_Tower_HIRecoSeedsRaw_r02");
126 std::cout <<
"DetermineTowerBackground::process_event: examining possible seeds (1st iteration) ... " << std::endl;
130 for (
auto this_jet : *reco2_jets) {
132 float this_pt = this_jet->get_pt();
133 float this_phi = this_jet->get_phi();
134 float this_eta = this_jet->get_eta();
136 if (this_jet->get_pt() < 5)
146 std::cout <<
"DetermineTowerBackground::process_event: possible seed jet with pt / eta / phi = " << this_pt <<
" / " << this_eta <<
" / " << this_phi <<
", examining constituents..." << std::endl;
148 std::map<int, double> constituent_ETsum;
150 for (
const auto&
comp : this_jet->get_comp_vec())
163 if (
comp.first == 5 ||
comp.first == 26)
174 else if (
comp.first == 7 ||
comp.first == 27)
181 tower_geom = geomOH->get_tower_geometry(key);
185 else if (
comp.first == 13 ||
comp.first == 28)
209 else if (
comp.first == 7)
212 tower_geom = geomOH->get_tower_geometry(tower->
get_key());
218 else if (
comp.first == 13)
228 if(comp_T == -10 || comp_T == -11)
231 std::cout <<
"DetermineTowerBackground::process_event: --> --> Skipping constituent in layer " <<
comp.first <<
" at ieta / iphi = " << comp_ieta <<
" / " << comp_iphi <<
"due to masking" << std::endl;
234 int comp_ikey = 1000 * comp_ieta + comp_iphi;
237 std::cout <<
"DetermineTowerBackground::process_event: --> --> constituent in layer " <<
comp.first <<
" at ieta / iphi = " << comp_ieta <<
" / " << comp_iphi <<
", filling map with key = " << comp_ikey <<
" and ET = " << comp_ET << std::endl;
239 constituent_ETsum[comp_ikey] += comp_ET;
242 std::cout <<
"DetermineTowerBackground::process_event: --> --> ET sum map at key = " << comp_ikey <<
" now has ET = " << constituent_ETsum[comp_ikey] << std::endl;
246 float constituent_max_ET = 0;
247 float constituent_sum_ET = 0;
248 int nconstituents = 0;
251 std::cout <<
"DetermineTowerBackground::process_event: --> now iterating over map..." << std::endl;
252 for (std::map<int, double>::iterator map_iter = constituent_ETsum.begin(); map_iter != constituent_ETsum.end(); ++map_iter)
255 std::cout <<
"DetermineTowerBackground::process_event: --> --> map has key # " << map_iter->first <<
" and ET = " << map_iter->second << std::endl;
257 constituent_sum_ET += map_iter->second;
258 if (map_iter->second > constituent_max_ET) constituent_max_ET = map_iter->second;
261 float mean_constituent_ET = constituent_sum_ET / nconstituents;
262 float seed_D = constituent_max_ET / mean_constituent_ET;
268 std::cout <<
"DetermineTowerBackground::process_event: --> jet has < ET > = " << constituent_sum_ET <<
" / " << nconstituents <<
" = " << mean_constituent_ET <<
", max-ET = " << constituent_max_ET <<
", and D = " << seed_D << std::endl;
279 std::cout <<
"DetermineTowerBackground::process_event: --> adding seed at eta / phi = " << this_eta <<
" / " << this_phi <<
" ( R=0.2 jet with pt = " << this_pt <<
", D = " << seed_D <<
" ) " << std::endl;
287 std::cout <<
"DetermineTowerBackground::process_event: --> discarding potential seed at eta / phi = " << this_eta <<
" / " << this_phi <<
" ( R=0.2 jet with pt = " << this_pt <<
", D = " << seed_D <<
" ) " << std::endl;
301 reco2_jets = findNode::getClass<JetContainer>(topNode,
"AntiKt_TowerInfo_HIRecoSeedsSub_r02");
305 reco2_jets = findNode::getClass<JetContainer>(topNode,
"AntiKt_Tower_HIRecoSeedsSub_r02");
308 std::cout <<
"DetermineTowerBackground::process_event: examining possible seeds (2nd iteration) ... " << std::endl;
312 for (
auto this_jet : *reco2_jets)
314 float this_pt = this_jet->get_pt();
315 float this_phi = this_jet->get_phi();
316 float this_eta = this_jet->get_eta();
333 std::cout <<
"DetermineTowerBackground::process_event: --> adding seed at eta / phi = " << this_eta <<
" / " << this_phi <<
" ( R=0.2 jet with pt = " << this_pt <<
" ) " << std::endl;
364 std::cout <<
"DetermineTowerBackground::process_event: setting number of towers in eta / phi: " <<
_HCAL_NETA <<
" / " <<
_HCAL_NPHI << std::endl;
393 if (!towerinfosEM3 || !towerinfosIH3 || !towerinfosOH3)
395 std::cout <<
PHWHERE <<
"missing tower info object, doing nothing" << std::endl;
398 unsigned int nchannels_em = towerinfosEM3->
size();
406 _EMCAL_E[this_etabin][this_phibin] += this_E;
407 _EMCAL_T[this_etabin][this_phibin] = this_T;
411 unsigned int nchannels_ih = towerinfosIH3->
size();
419 _IHCAL_E[this_etabin][this_phibin] += this_E;
420 _IHCAL_T[this_etabin][this_phibin] += this_T;
424 unsigned int nchannels_oh = towerinfosOH3->
size();
432 _OHCAL_E[this_etabin][this_phibin] += this_E;
433 _OHCAL_T[this_etabin][this_phibin] += this_T;
446 float this_eta = tower_geom->
get_eta();
447 float this_phi = tower_geom->
get_phi();
448 int this_etabin = geomIH->
get_etabin(this_eta);
449 int this_phibin = geomIH->
get_phibin(this_phi);
452 _EMCAL_E[this_etabin][this_phibin] += this_E;
456 std::cout <<
"DetermineTowerBackground::process_event: EMCal tower eta ( bin ) / phi ( bin ) / E = " << std::setprecision(6) << this_eta <<
" ( " << this_etabin <<
" ) / " << this_phi <<
" ( " << this_phibin <<
" ) / " << this_E << std::endl;
467 float this_eta = tower_geom->
get_eta();
468 float this_phi = tower_geom->
get_phi();
469 int this_etabin = geomIH->
get_etabin(this_eta);
470 int this_phibin = geomIH->
get_phibin(this_phi);
473 _IHCAL_E[this_etabin][this_phibin] += this_E;
477 std::cout <<
"DetermineTowerBackground::process_event: IHCal tower at eta ( bin ) / phi ( bin ) / E = " << std::setprecision(6) << this_eta <<
" ( " << this_etabin <<
" ) / " << this_phi <<
" ( " << this_phibin <<
" ) / " << this_E << std::endl;
488 float this_eta = tower_geom->
get_eta();
489 float this_phi = tower_geom->
get_phi();
490 int this_etabin = geomOH->get_etabin(this_eta);
491 int this_phibin = geomOH->get_phibin(this_phi);
494 _OHCAL_E[this_etabin][this_phibin] += this_E;
498 std::cout <<
"DetermineTowerBackground::process_event: OHCal tower at eta ( bin ) / phi ( bin ) / E = " << std::setprecision(6) << this_eta <<
" ( " << this_etabin <<
" ) / " << this_phi <<
" ( " << this_phibin <<
" ) / " << this_E << std::endl;
512 std::cout <<
"DetermineTowerBackground::process_event: flow not enabled, setting Psi2 = " <<
_Psi2 <<
" ( " <<
_Psi2 / M_PI <<
" * pi ) , v2 = " <<
_v2 << std::endl;
519 int nStripsAvailableForFlow = 0;
520 int nStripsUnavailableForFlow = 0;
527 for (
int eta = 0;
eta < local_max_eta;
eta++)
529 bool isAnyTowerExcluded =
false;
531 for (
int phi = 0;
phi < local_max_phi;
phi++)
536 bool isExcluded =
false;
540 if(my_T == -10 || my_T == -11) isExcluded =
true;
541 for (
unsigned int iseed = 0; iseed <
_seed_eta.size(); iseed++)
543 float deta = this_eta -
_seed_eta[iseed];
545 if (dphi > M_PI) dphi -= 2 * M_PI;
546 if (dphi < -M_PI) dphi += 2 * M_PI;
547 float dR = sqrt(pow(deta, 2) + pow(dphi, 2));
554 std::cout <<
" setting excluded mark for tower with E / eta / phi = " << my_E <<
" / " << this_eta <<
" / " << this_phi <<
" from seed at eta / phi = " << _seed_eta[iseed] <<
" / " << _seed_phi[iseed] << std::endl;
562 isAnyTowerExcluded =
true;
566 if (!isAnyTowerExcluded)
569 std::cout <<
" strip at layer " <<
layer <<
", eta " <<
eta <<
" has no excluded towers and can be used for flow determination " << std::endl;
570 nStripsAvailableForFlow++;
572 for (
int phi = 0;
phi < local_max_phi;
phi++)
586 std::cout <<
" strip at layer " <<
layer <<
", eta " <<
eta <<
" DOES have excluded towers and CANNOT be used for flow determination " << std::endl;
587 nStripsUnavailableForFlow++;
600 std::cout <<
"DetermineTowerBackground::process_event: # of strips (summed over layers) available / unavailable for flow determination: " << nStripsAvailableForFlow <<
" / " << nStripsUnavailableForFlow << std::endl;
602 if (nStripsAvailableForFlow > 0)
613 _Psi2 = atan2(Q_y, Q_x) / 2.0;
621 std::cout <<
"DetermineTowerBackground::process_event: FATAL , G4TruthInfo does not exist , cannot extract truth flow with do_flow = " <<
_do_flow << std::endl;
627 float Hijing_Qx = 0, Hijing_Qy = 0;
638 float truth_pt = t.Pt();
639 if (truth_pt < 0.4)
continue;
640 float truth_eta = t.Eta();
641 if (fabs(truth_eta) > 1.1)
continue;
642 float truth_phi = t.Phi();
643 int truth_pid = g4particle->
get_pid();
646 std::cout <<
"DetermineTowerBackground::process_event: determining truth flow, using particle w/ pt / eta / phi " << truth_pt <<
" / " << truth_eta <<
" / " << truth_phi <<
" , embed / PID = " << truthinfo->
isEmbeded(g4particle->
get_track_id()) <<
" / " << truth_pid << std::endl;
648 Hijing_Qx += truth_pt * cos(2 * truth_phi);
649 Hijing_Qy += truth_pt * sin(2 * truth_phi);
652 _Psi2 = atan2(Hijing_Qy, Hijing_Qx) / 2.0;
655 std::cout <<
"DetermineTowerBackground::process_event: flow extracted from Hijing truth particles, setting Psi2 = " <<
_Psi2 <<
" ( " <<
_Psi2 / M_PI <<
" * pi ) " << std::endl;
659 double sum_cos2dphi = 0;
665 _v2 = sum_cos2dphi /
E;
675 std::cout <<
"DetermineTowerBackground::process_event: no full strips available for flow modulation, setting v2 and Psi = 0" << std::endl;
680 std::cout <<
"DetermineTowerBackground::process_event: unnormalized Q vector (Qx, Qy) = ( " << Q_x <<
", " << Q_y <<
" ) with Sum E_i = " << E << std::endl;
681 std::cout <<
"DetermineTowerBackground::process_event: Psi2 = " <<
_Psi2 <<
" ( " <<
_Psi2 / M_PI <<
" * pi " << (
_do_flow == 2 ?
"from Hijing " :
"") <<
") , v2 = " <<
_v2 <<
" ( using " <<
_nStrips <<
" ) " << std::endl;
694 for (
int eta = 0;
eta < local_max_eta;
eta++)
699 for (
int phi = 0;
phi < local_max_phi;
phi++)
704 bool isExcluded =
false;
709 if(my_T == -10 || my_T == -11)
712 if (
Verbosity() > 10) std::cout <<
" tower in layer " <<
layer <<
" at eta / phi = " << this_eta <<
" / " << this_phi <<
" with E = " << my_E <<
" excluded due to masking" << std::endl;
714 for (
unsigned int iseed = 0; iseed <
_seed_eta.size(); iseed++)
716 float deta = this_eta -
_seed_eta[iseed];
718 if (dphi > M_PI) dphi -= 2 * M_PI;
719 if (dphi < -M_PI) dphi += 2 * M_PI;
720 float dR = sqrt(pow(deta, 2) + pow(dphi, 2));
724 if (
Verbosity() > 10) std::cout <<
" setting excluded mark from seed at eta / phi = " << _seed_eta[iseed] <<
" / " << _seed_phi[iseed] << std::endl;
738 if (
Verbosity() > 10) std::cout <<
" tower at eta / phi = " << this_eta <<
" / " << this_phi <<
" with E = " << total_E <<
" excluded due to seed " << std::endl;
743 std::pair<float, float> phibounds = geomIH->
get_phibounds(0);
745 float deta = etabounds.second - etabounds.first;
746 float dphi = phibounds.second - phibounds.first;
747 float total_area = total_tower * deta *
dphi;
753 std::cout <<
"DetermineTowerBackground::process_event: at layer / eta index ( eta range ) = " <<
layer <<
" / " <<
eta <<
" ( " << etabounds.first <<
" - " << etabounds.second <<
" ) , total E / total Ntower / total area = " << total_E <<
" / " << total_tower <<
" / " << total_area <<
" , UE per tower = " << total_E / total_tower << std::endl;
762 std::cout <<
"DetermineTowerBackground::process_event: summary UE in layer " <<
layer <<
" : ";
764 std::cout << std::endl;
772 if (
Verbosity() > 0) std::cout <<
"DetermineTowerBackground::process_event: exiting" << std::endl;
785 std::cout <<
PHWHERE <<
"DST Node missing, doing nothing." << std::endl;
799 if (!towerbackground)
817 if (!towerbackground)
819 std::cout <<
" ERROR -- can't find TowerBackground node after it should have been created" << std::endl;