File indexing completed on 2025-08-05 08:11:12
0001 #include "EliminateBackground.h"
0002 #include <calobase/RawTowerGeomContainer.h>
0003 #include <calobase/RawTowerGeom.h>
0004
0005 #include "TMath.h"
0006 #include <calobase/TowerInfo.h>
0007 #include <calobase/TowerInfoDefs.h>
0008 #include <phool/PHCompositeNode.h>
0009 #include <phool/PHIODataNode.h>
0010 #include <phool/PHNode.h>
0011 #include <phool/PHNodeIterator.h>
0012 #include <phool/PHObject.h>
0013 #include <phool/getClass.h>
0014 #include <phool/phool.h>
0015
0016 #include <TH1.h>
0017 #include <TH2.h>
0018
0019 #include <calobase/TowerInfoContainer.h>
0020
0021 #include <fun4all/Fun4AllReturnCodes.h>
0022
0023
0024 EliminateBackground::EliminateBackground(const std::string& name)
0025 : SubsysReco(name)
0026 {
0027
0028 }
0029
0030 EliminateBackground::~EliminateBackground()
0031 {
0032
0033 }
0034
0035 int EliminateBackground::InitRun(PHCompositeNode*)
0036 {
0037 hcal_phi_consec = new TH1F("hcal_phi_consec", "", 64, -0.5, 63.5);
0038 hcal_phi = new TH1F("hcal_phi", "", 64, -0.5, 63.5);
0039 hcal = new TH2F("hcal", "", 24, -0.5, 23.5, 64, -0.5, 63.5);
0040 return 0;
0041
0042 }
0043 int EliminateBackground::Init(PHCompositeNode* )
0044 {
0045
0046 return Fun4AllReturnCodes::EVENT_OK;
0047 }
0048
0049 int EliminateBackground::process_event(PHCompositeNode* topNode)
0050 {
0051
0052 TowerInfoContainer *hcalout_towers = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_HCALOUT");
0053
0054 hcal_phi->Reset();
0055 hcal_phi_consec->Reset();
0056 hcal->Reset();
0057 int size = hcalout_towers->size();
0058
0059 for (int channel = 0; channel < size;channel++)
0060 {
0061 TowerInfo *tower = hcalout_towers->get_tower_at_channel(channel);
0062 float energy = tower->get_energy();
0063 unsigned int towerkey = hcalout_towers->encode_key(channel);
0064 int ieta = hcalout_towers->getTowerEtaBin(towerkey);
0065 int iphi = hcalout_towers->getTowerPhiBin(towerkey);
0066 short good = (tower->get_isGood() ? 1:0);
0067 if (!good) continue;
0068 if (energy > HCAL_TOWER_ENERGY_CUT)
0069 {
0070 hcal->Fill(ieta, iphi, energy);
0071 hcal_phi->Fill(iphi);
0072 }
0073 }
0074 for (int iphi = 0 ; iphi < 64; iphi++)
0075 {
0076 int maxlength = 0;
0077 int length = 0;
0078 for (int ieta = 0 ; ieta < 24; ieta++)
0079 {
0080 int bin = hcal->GetBin(ieta+1, iphi+1);
0081 if (hcal->GetBinContent(bin) > CONSECUTIVE_ENERGY_CUT)
0082 {
0083 length++;
0084 }
0085 else
0086 {
0087 maxlength = length;
0088 length = 0;
0089 }
0090 }
0091 if (maxlength < length) maxlength = length;
0092 hcal_phi_consec->Fill(iphi, maxlength);
0093 }
0094
0095 int bmax = hcal_phi_consec->GetMaximumBin();
0096
0097 if (hcal_phi_consec->GetBinContent(bmax) > CONSECUTIVE_COUNT_CUT)
0098 {
0099 if (hcal_proj->GetMaximumBin() != bmax) return Fun4AllReturnCodes::EVENT_OK;
0100 if (Verbosity()) std::cout << "EVENT ELIMINATED" << std::endl;
0101 return Fun4AllReturnCodes::ABORTEVENT;
0102 }
0103 if (hcal_phi->GetBinContent(bmax) > COUNT_CUT)
0104 {
0105 if (hcal_proj->GetMaximumBin() != bmax) return Fun4AllReturnCodes::EVENT_OK;
0106 if (Verbosity()) std::cout << "EVENT ELIMINATED" << std::endl;
0107 return Fun4AllReturnCodes::ABORTEVENT;
0108 }
0109
0110 int binup = (bmax == 64 ? 1 : bmax + 1);
0111 int bindown = (bmax == 1 ? 64 : bmax - 1);
0112
0113 bool nextdoor_consec = (hcal_phi_consec->GetBinContent(binup) < 2 && hcal_phi_consec->GetBinContent(bindown) < 2);
0114 bool nextdoor_total = (hcal_phi->GetBinContent(binup) < 2 && hcal_phi->GetBinContent(bindown) < 2);
0115
0116 bool bad = (hcal_phi_consec->GetBinContent(bmax) > 4 && nextdoor_total && nextdoor_consec);
0117
0118 if (bad)
0119 {
0120 if (hcal_proj->GetMaximumBin() != bmax) return Fun4AllReturnCodes::EVENT_OK;
0121 trash->setIsTrash(true);
0122 if (!m_keep) return Fun4AllReturnCodes::ABORTEVENT;
0123 }
0124
0125 return Fun4AllReturnCodes::EVENT_OK;
0126 }
0127
0128 int EliminateBackground::End(PHCompositeNode* )
0129 {
0130 return Fun4AllReturnCodes::EVENT_OK;
0131 }