hpstr
The Heavy Photon Search Toolkit for Reconstruction (hpstr) provides an interface to physics data from the HPS experiment saved in the LCIO format and converts it into an ROOT based format.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ECalDataProcessor.cxx
Go to the documentation of this file.
1
7#include "ECalDataProcessor.h"
8#include "Event.h"
9
10ECalDataProcessor::ECalDataProcessor(const std::string& name, Process& process)
11 : Processor(name, process) {
12 }
13
16
18
19 std::cout << "Configuring ECalDataProcessor" << std::endl;
20 try
21 {
22 debug_ = parameters.getInteger("debug", debug_);
23 hitCollLcio_ = parameters.getString("hitCollLcio", hitCollLcio_);
24 hitCollRoot_ = parameters.getString("hitCollRoot", hitCollRoot_);
25 clusCollLcio_ = parameters.getString("clusCollLcio", clusCollLcio_);
26 clusCollRoot_ = parameters.getString("clusCollRoot", clusCollRoot_);
27 }
28 catch (std::runtime_error& error)
29 {
30 std::cout << error.what() << std::endl;
31 }
32}
33
35 if (!hitCollRoot_.empty())
36 tree->Branch(hitCollRoot_.c_str(), &cal_hits_);
37 tree->Branch(clusCollRoot_.c_str(), &clusters_);
38}
39
41
42 if(debug_ > 0) std::cout << "[ECalDataProcessor] Running Process" << std::endl;
43 for(int i = 0; i < cal_hits_.size(); i++) delete cal_hits_.at(i);
44 cal_hits_.clear();
45 for(int i = 0; i < clusters_.size(); i++) delete clusters_.at(i);
46 clusters_.clear();
47 // Attempt to retrieve the collection "TimeCorrEcalHits" from the event. If
48 // the collection doesn't exist, handle the DataNotAvailableCollection and
49 // attempt to retrieve the collection "EcalCalHits". If that collection
50 // doesn't exist, the DST maker will fail.
51
52 //dynamic cast
53 Event* event = static_cast<Event*> (ievent);
54 EVENT::LCCollection* hits{nullptr};
55 try {
56 hits = static_cast<EVENT::LCCollection*>(event->getLCCollection(hitCollLcio_.c_str()));
57 } catch (EVENT::DataNotAvailableException e) {
58 std::cout << e.what() << std::endl;
59 }
60
61 // A calorimeter hit
62 IMPL::CalorimeterHitImpl* lc_hit{nullptr};
63
64 // Get the collection of Ecal hits from the event.
65 std::map< std::pair<int,int>, CalHit*> hit_map;
66
67 // Loop through all of the hits and add them to event.
68 for (int ihit=0; ihit < hits->getNumberOfElements(); ++ihit) {
69
70 // Get the ith hit from the LC Event.
71 IMPL::CalorimeterHitImpl* lc_hit
72 = static_cast<IMPL::CalorimeterHitImpl*>(hits->getElementAt(ihit));
73
74 // Get the unique cell id of this hit. Combine it with the integer time,
75 // since a crystal can be hit more than once.
76 int id0 = lc_hit->getCellID0();
77
78 // 0.1 ns resolution is sufficient to distinguish any 2 hits on the same crystal.
79 int id1 = static_cast<int>(10.0*lc_hit->getTime());
80
81 CalHit* cal_hit = new CalHit();
82
83 // Store the hit in the map for easy access later.
84 hit_map[ std::make_pair(id0,id1) ] = cal_hit;
85
86 // Set the energy of the Ecal hit
87 cal_hit->setEnergy(lc_hit->getEnergy());
88
89 // Set the hit time of the Ecal hit
90 cal_hit->setTime(lc_hit->getTime());
91
92 // Set the indices of the crystal
93 int index_x = this->getIdentifierFieldValue("ix", lc_hit);
94 int index_y = this->getIdentifierFieldValue("iy", lc_hit);
95
96 cal_hit->setCrystalIndices(index_x, index_y);
97 cal_hits_.push_back(cal_hit);
98
99 }
100
101 // Get the collection of Ecal clusters from the event
102 EVENT::LCCollection* clusters{nullptr};
103 try
104 {
105 clusters = static_cast<EVENT::LCCollection*>(event->getLCCollection(clusCollLcio_.c_str()));
106 }
107 catch (EVENT::DataNotAvailableException e)
108 {
109 std::cout << e.what() << std::endl;
110 }
111
112 // Loop over all clusters and fill the event
113 for(int icluster = 0; icluster < clusters->getNumberOfElements(); ++icluster) {
114
115 // Get an Ecal cluster from the LCIO collection
116 IMPL::ClusterImpl* lc_cluster = static_cast<IMPL::ClusterImpl*>(clusters->getElementAt(icluster));
117
118 // Add a cluster to the event
119 CalCluster* cluster = new CalCluster();
120
121 // Set the cluster position
122 cluster->setPosition(lc_cluster->getPosition());
123
124 // Set the cluster energy
125 cluster->setEnergy(lc_cluster->getEnergy());
126
127 // Get the ecal hits used to create the cluster
128 EVENT::CalorimeterHitVec lc_hits = lc_cluster->getCalorimeterHits();
129
130 // Loop over all of the Ecal hits and add them to the Ecal cluster. The
131 // seed hit is set to be the hit with the highest energy. The cluster time
132 // is set to be the hit time of the seed hit.
133 double senergy = 0;
134 double stime = 0;
135 CalHit* seed_hit{nullptr};
136 for(int ihit = 0; ihit < (int) lc_hits.size(); ++ihit) {
137
138 // Get an Ecal hit
139 lc_hit = static_cast<IMPL::CalorimeterHitImpl*>(lc_hits[ihit]);
140
141 int id0=lc_hit->getCellID0();
142 int id1=(int)(10.0*lc_hit->getTime());
143
144 if (hit_map.find(std::make_pair(id0,id1)) == hit_map.end()) {
145 throw std::runtime_error("[ EcalDataProcessor ]: Hit not found in map, but is in the cluster.");
146 } else {
147 // Get the hit and add it to the cluster
148 CalHit* cal_hit = hit_map[std::make_pair(id0,id1)];
149 cluster->addHit(cal_hit);
150
151 if (senergy < lc_hit->getEnergy()) {
152 senergy = lc_hit->getEnergy();
153 seed_hit = cal_hit;
154 stime = cal_hit->getTime();
155 }
156 }
157 }
158
159 // Set the time of the cluster
160 cluster->setTime(stime);
161
162 // Set the cluster seed.
163 cluster->setSeed(seed_hit);
164 clusters_.push_back(cluster);
165 }
166
167 if(debug_ > 0) std::cout << "[ECalDataProcessor] End of process" << std::endl;
168 return true;
169}
170
173
174UTIL::BitFieldValue ECalDataProcessor::getIdentifierFieldValue(std::string field, EVENT::CalorimeterHit* hit){
175
176 UTIL::BitField64 decoder(encoder_string_);
177 long64 value = long64( hit->getCellID0() & 0xffffffff ) | ( long64( hit->getCellID1() ) << 32 ) ;
178 decoder.setValue(value);
179
180 return decoder[field];
181}
182
Processor used to convert ECal LCIO data to ROOT.
long long long64
Class defining methods used to access event information and data collections.
#define DECLARE_PROCESSOR(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Definition Processor.h:139
void setPosition(const float *position)
void setEnergy(const double energy)
Definition CalCluster.h:70
void setSeed(TObject *seed_hit)
Definition CalCluster.h:90
void setTime(const double time)
Definition CalCluster.h:80
void addHit(TObject *hit)
void setCrystalIndices(int index_x_, int index_y_)
Definition CalHit.cxx:23
void setEnergy(const double energy)
Definition CalHit.h:33
void setTime(const double time)
Definition CalHit.h:43
double getTime() const
Definition CalHit.h:46
Insert description here. more details.
UTIL::BitFieldValue getIdentifierFieldValue(std::string field, EVENT::CalorimeterHit *hit)
Method to unpack field value from a calorimeter hit ID.
int debug_
Debug Level.
std::string clusCollRoot_
description
const std::string encoder_string_
virtual void configure(const ParameterSet &parameters)
Callback for the Processor to configure itself from the given set of parameters.
virtual void finalize()
Callback for the Processor to take any necessary action when the processing of events finishes.
std::vector< CalCluster * > clusters_
virtual void initialize(TTree *tree)
Callback for the Processor to take any necessary action when the processing of events starts.
std::string hitCollRoot_
description
std::string clusCollLcio_
description
std::string hitCollLcio_
description
std::vector< CalHit * > cal_hits_
ECalDataProcessor(const std::string &name, Process &process)
Class constructor.
Definition Event.h:35
Definition IEvent.h:7
description
Base class for all event processing components.
Definition Processor.h:34
virtual bool process()
Process the histograms and generate analysis output.
Definition Processor.h:95