File indexing completed on 2025-08-06 08:13:10
0001
0002 #include "Emcal_Tower_Masking.h"
0003
0004 #include <calobase/TowerInfo.h>
0005 #include <calobase/TowerInfoContainer.h>
0006 #include <calobase/TowerInfoContainerv1.h>
0007
0008 #include <caloreco/CaloWaveformProcessing.h> // for CaloWaveformProcessing
0009 #include <globalvertex/GlobalVertex.h>
0010 #include <globalvertex/GlobalVertexv1.h>
0011 #include <globalvertex/GlobalVertexMap.h>
0012 #include <globalvertex/GlobalVertexMapv1.h>
0013 #include <fun4all/Fun4AllReturnCodes.h>
0014 #include <fun4all/SubsysReco.h> // for SubsysReco
0015
0016 #include <phool/PHCompositeNode.h>
0017 #include <phool/PHIODataNode.h> // for PHIODataNode
0018 #include <phool/PHNode.h> // for PHNode
0019 #include <phool/PHNodeIterator.h> // for PHNodeIterator
0020 #include <phool/PHObject.h> // for PHObject
0021 #include <phool/getClass.h>
0022
0023 #include <Event/Event.h>
0024 #include <Event/packet.h>
0025
0026 #include <iostream> // for operator<<, endl, basic...
0027 #include <memory> // for allocator_traits<>::val...
0028 #include <vector> // for vector
0029 #include <fun4all/Fun4AllReturnCodes.h>
0030
0031 #include <phool/PHCompositeNode.h>
0032
0033
0034 Emcal_Tower_Masking::Emcal_Tower_Masking(const std::string &name):
0035 SubsysReco(name)
0036 {
0037 }
0038
0039
0040 Emcal_Tower_Masking::~Emcal_Tower_Masking()
0041 {
0042 }
0043
0044
0045 int Emcal_Tower_Masking::Init(PHCompositeNode *topNode)
0046 {
0047
0048 return Fun4AllReturnCodes::EVENT_OK;
0049 }
0050
0051
0052 int Emcal_Tower_Masking::InitRun(PHCompositeNode *topNode)
0053 {
0054 CreateNodeTree(topNode);
0055 topNode->print();
0056 return Fun4AllReturnCodes::EVENT_OK;
0057 }
0058
0059
0060 int Emcal_Tower_Masking::process_event(PHCompositeNode *topNode)
0061 {
0062 float emcalescale = 1.0;
0063
0064 TowerInfoContainer* emcaltowers = findNode::getClass<TowerInfoContainerv1>(topNode, "TOWERS_CEMC");
0065 if (!emcaltowers)
0066 {
0067 std::cout
0068 << "MyJetAnalysis::process_event - Error can not find DST TOWERS_CEMC node "
0069 << std::endl;
0070 exit(-1);
0071 }
0072 TowerInfoContainer* calib_emcaltowers = findNode::getClass<TowerInfoContainerv1>(topNode, "TOWERINFO_CALIB_CEMC");
0073 if (!calib_emcaltowers)
0074 {
0075 std::cout
0076 << "MyJetAnalysis::process_event - Error can not find DST TOWERINFO_CALIB_CEMC node "
0077 << std::endl;
0078 exit(-1);
0079 }
0080
0081
0082 GlobalVertexMap *vertexmap = findNode::getClass<GlobalVertexMap>(topNode, "GlobalVertexMap");
0083 GlobalVertex *vertex = new GlobalVertexv1(GlobalVertex::VTXTYPE::SVTX);
0084 vertex->set_id(vertexmap->size());
0085 for (unsigned int i = 0; i < 3; ++i)
0086 {
0087 vertex->set_position(i, 0);
0088 for (unsigned int j = i; j < 3; ++j)
0089 {
0090 vertex->set_error(i, j, 0);
0091 }
0092 }
0093 vertexmap->insert(vertex);
0094
0095
0096 {
0097 unsigned int nchannels = emcaltowers->size();
0098 for (unsigned int channel = 0; channel < nchannels;channel++)
0099 {
0100 TowerInfo* tower = emcaltowers->get_tower_at_channel(channel);
0101 TowerInfo* calib_tower = calib_emcaltowers->get_tower_at_channel(channel);
0102 unsigned int channelkey = emcaltowers->encode_key(channel);
0103 unsigned int ieta = emcaltowers->getTowerEtaBin(channelkey);
0104 unsigned int iphi = emcaltowers->getTowerPhiBin(channelkey);
0105 int n_masked_packets = packetmasklist.size();
0106 bool maskpacket = false;
0107 if (n_masked_packets > 0 )
0108 {
0109 for (int i = 0; i < n_masked_packets;i++)
0110 {
0111 if (channel >= 192*(packetmasklist.at(i)-1) && channel < 192*packetmasklist.at(i))
0112 {
0113 maskpacket = true;
0114 }
0115 }
0116 }
0117 if (maskpacket == true)
0118 {
0119 calib_tower->set_energy(0);
0120 calib_tower->set_time(0);
0121 }
0122 else
0123 {
0124 calib_tower->set_energy(tower->get_energy() * emcalescale);
0125 calib_tower->set_time(tower->get_time());
0126 }
0127 int nbads = etamasklist.size();
0128 if(nbads > 0 )
0129 {
0130 for(int q =0 ; q < nbads;q++)
0131 {
0132 if (ieta == etamasklist.at(q) && iphi == phimasklist.at(q))
0133 {
0134 calib_tower->set_energy(0);
0135 calib_tower->set_time(0);
0136 }
0137 }
0138 }
0139
0140 }
0141 }
0142
0143
0144 return Fun4AllReturnCodes::EVENT_OK;
0145 }
0146
0147
0148 int Emcal_Tower_Masking::ResetEvent(PHCompositeNode *topNode)
0149 {
0150
0151 return Fun4AllReturnCodes::EVENT_OK;
0152 }
0153
0154
0155 int Emcal_Tower_Masking::EndRun(const int runnumber)
0156 {
0157 return Fun4AllReturnCodes::EVENT_OK;
0158 }
0159
0160
0161 int Emcal_Tower_Masking::End(PHCompositeNode *topNode)
0162 {
0163 return Fun4AllReturnCodes::EVENT_OK;
0164 }
0165
0166
0167 int Emcal_Tower_Masking::Reset(PHCompositeNode *topNode)
0168 {
0169 return Fun4AllReturnCodes::EVENT_OK;
0170 }
0171
0172
0173 void Emcal_Tower_Masking::Print(const std::string &what) const
0174 {
0175 std::cout << "Emcal_Tower_Masking::Print(const std::string &what) const Printing info for " << what << std::endl;
0176 }
0177
0178 void Emcal_Tower_Masking::CreateNodeTree(PHCompositeNode *topNode)
0179 {
0180 PHNodeIterator nodeItr(topNode);
0181
0182 PHCompositeNode *dst_node = dynamic_cast<PHCompositeNode *>(
0183 nodeItr.findFirst("PHCompositeNode", "DST"));
0184 if (!dst_node)
0185 {
0186 std::cout << "PHComposite node created: DST" << std::endl;
0187 dst_node = new PHCompositeNode("DST");
0188 topNode->addNode(dst_node);
0189 }
0190 PHNodeIterator dstItr(dst_node);
0191
0192 PHCompositeNode *CEMCNode = dynamic_cast<PHCompositeNode *>(dstItr.findFirst("PHCompositeNode", "CEMC"));
0193 if (!CEMCNode)
0194 {
0195 std::cout << " no CEMC Node? " << std::endl;
0196 CEMCNode = new PHCompositeNode("CEMC");
0197 }
0198 TowerInfoContainer* m_CEMC_calib_container = new TowerInfoContainerv1(TowerInfoContainer::DETECTOR::EMCAL);
0199 PHIODataNode<PHObject> *emcal_towerNode = new PHIODataNode<PHObject>(m_CEMC_calib_container, "TOWERINFO_CALIB_CEMC", "PHObject");
0200 CEMCNode->addNode(emcal_towerNode);
0201
0202
0203
0204 PHCompositeNode *globalNode = dynamic_cast<PHCompositeNode *>(dstItr.findFirst("PHCompositeNode", "GLOBAL"));
0205 if (!globalNode)
0206 {
0207 globalNode = new PHCompositeNode("GLOBAL");
0208 dst_node->addNode(globalNode);
0209 }
0210
0211
0212 GlobalVertexMap *vertexes = findNode::getClass<GlobalVertexMap>(topNode, "GlobalVertexMap");
0213 if (!vertexes)
0214 {
0215 vertexes = new GlobalVertexMapv1();
0216 PHIODataNode<PHObject> *VertexMapNode = new PHIODataNode<PHObject>(vertexes, "GlobalVertexMap", "PHObject");
0217 globalNode->addNode(VertexMapNode);
0218 }
0219
0220 }