91 :
simTracks_(iConfig.getParameter<
edm::InputTag>(
"simTracks")),
135 std::vector<int> sorted_tracks_idx(
tracks.size());
136 iota(
begin(sorted_tracks_idx),
end(sorted_tracks_idx), 0);
137 sort(
begin(sorted_tracks_idx),
138 end(sorted_tracks_idx),
140 return tracks[
i].momentum().eta() <
tracks[j].momentum().eta();
145 std::vector<int> sorted_genParticles_idx(
genParticles.size());
146 iota(
begin(sorted_genParticles_idx),
end(sorted_genParticles_idx), 0);
147 sort(
begin(sorted_genParticles_idx),
153 std::vector<int> sorted_vertices_idx(
vertices.size());
154 iota(
begin(sorted_vertices_idx),
end(sorted_vertices_idx), 0);
155 sort(
begin(sorted_vertices_idx),
156 end(sorted_vertices_idx), [&
vertices](
int i,
int j){
161 auto const & trackingpart = *trackingParticlesH.
product();
162 std::vector<int> sorted_tp_idx(trackingpart.size());
163 iota(
begin(sorted_tp_idx),
end(sorted_tp_idx), 0);
164 sort(
begin(sorted_tp_idx),
165 end(sorted_tp_idx), [&trackingpart] (
int i,
int j){
166 return trackingpart[
i].eta() < trackingpart[j].eta();
170 auto const & calopart = *caloParticlesH.
product();
171 std::vector<int> sorted_cp_idx(calopart.size());
172 iota(
begin(sorted_cp_idx),
173 end(sorted_cp_idx), 0);
174 sort(
begin(sorted_cp_idx),
175 end(sorted_cp_idx), [&calopart](
int i,
int j){
176 return calopart[
i].eta() < calopart[j].eta();});
179 auto const & simclusters = *simClustersH.
product();
180 std::vector<int> sorted_simcl_idx(simclusters.size());
181 iota(
begin(sorted_simcl_idx),
182 end(sorted_simcl_idx), 0);
183 sort(
begin(sorted_simcl_idx),
184 end(sorted_simcl_idx), [&simclusters](
int i,
int j){
185 return simclusters[
i].eta() < simclusters[j].eta();});
188 std::map<int, float> detIdToTotalSimEnergy;
189 fillSimHits(detIdToTotalSimEnergy, iEvent, iSetup);
193 std::map<int, int> trackid_to_track_index;
194 std::cout <<
"Printing SimTracks information" << std::endl;
195 std::cout <<
"IDX\tTrackId\tPDGID\tMOMENTUM(x,y,z,E)\tVertexIdx\tGenPartIdx" << std::endl;
196 for (
auto i : sorted_tracks_idx) {
198 std::cout << idx <<
"\t" <<
t.trackId() <<
"\t" <<
t << std::endl;
199 trackid_to_track_index[
t.trackId()] =
idx;
203 std::cout <<
"Printing GenParticles information" << std::endl;
204 std::cout <<
"IDX\tPDGID\tMOMENTUM(x,y,z)\tVertex(x,y,z)" << std::endl;
205 for (
auto i : sorted_genParticles_idx) {
208 <<
"\t" <<
gp.pdgId()
209 <<
"\t" <<
gp.momentum()
210 <<
"\t" <<
gp.vertex() << std::endl;
213 std::cout <<
"Printing SimVertex information" << std::endl;
214 std::cout <<
"IDX\tPOSITION(x,y,z)\tPARENT_INDEX\tVERTEX_ID" << std::endl;
215 for (
auto i : sorted_vertices_idx) {
219 std::cout <<
"Printing TrackingParticles information" << std::endl;
220 for (
auto i : sorted_tp_idx) {
221 auto const & tp = trackingpart[
i];
222 std::cout << i <<
"\t" << tp << std::endl;
225 std::cout <<
"Printing CaloParticles information" << std::endl;
227 for (
auto i : sorted_cp_idx) {
228 auto const &
cp = calopart[
i];
232 <<
"\tIdx: " <<
cp.
g4Tracks()[0].trackId() << std::endl;
233 double total_sim_energy = 0.;
234 double total_cp_energy = 0.;
238 std::vector<int> sorted_sc_idx(simcs.size());
239 iota(
begin(sorted_sc_idx),
end(sorted_sc_idx), 0);
240 sort(
begin(sorted_sc_idx),
242 [&simcs] (
int i,
int j) {
243 return simcs[
i]->momentum().eta() < simcs[j]->momentum().eta();
245 for (
auto i : sorted_sc_idx) {
251 total_sim_energy += detIdToTotalSimEnergy[
cl.first]*
cl.second;
255 std::cout <<
"--> Overall SC energy (sum using sim energies): " << total_sim_energy << std::endl;
256 std::cout <<
"--> Overall SC energy (sum using CaloP energies): " << total_cp_energy << std::endl;
260 std::cout <<
"Printing SimClusters information" << std::endl;
261 for (
auto i : sorted_simcl_idx) {
262 auto const & simcl = simclusters[
i];
264 <<
"\tType: " << simcl.pdgId()
265 <<
"\tEnergy: " << simcl.energy()
266 <<
"\tKey: " << i << std::endl;
267 double total_sim_energy = 0.;
268 std::cout <<
"--> Overall simclusters's size: " << simcl.numberOfRecHits() << std::endl;
269 for (
auto const &
cl : simcl.hits_and_fractions()) {
270 total_sim_energy += detIdToTotalSimEnergy[
cl.first]*
cl.second;
273 std::cout <<
"--> Overall SimCluster energy (sum using sim energies): " << total_sim_energy << std::endl;
287 std::map<int, float> & detIdToTotalSimEnergy,
305 for (
unsigned i = 0;
i < 2; ++
i) {
315 const bool isHcal = ( collectionTag.instance().find(
"HcalHits") != std::string::npos );
317 for (
auto const&
simHit : *hSimHits) {
319 const uint32_t simId =
simHit.id();
324 int subdet, layer, cell, sec, subsec, zp;
327 std::pair<int, int> recoLayerCell = ddd->
simToReco(cell, layer, sec,
328 hgtopo[subdet-3]->detectorType());
329 cell = recoLayerCell.first;
330 layer = recoLayerCell.second;
332 if (layer == -1 ||
simHit.geantTrackId() == 0)
continue;
336 if (
DetId(0) ==
id)
continue;
338 detIdToTotalSimEnergy[
id.rawId()] +=
simHit.energy();
353 desc.
add<std::vector<edm::InputTag> >(
"collectionTags",
357 descriptions.
add(
"caloParticleDebugger", desc);
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
const HcalDDDRecConstants * dddConstants() const
HcalSubdetector subdet() const
get the subdetector
std::vector< std::pair< uint32_t, float > > hits_and_fractions() const
Returns list of rechit IDs and fractions for this SimCluster.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
edm::EDGetTokenT< std::vector< TrackingParticle > > trackingParticlesToken_
#define DEFINE_FWK_MODULE(type)
const std::vector< SimTrack > & g4Tracks() const
edm::InputTag simClusters_
edm::EDGetTokenT< std::vector< SimCluster > > simClustersToken_
const HcalTopology & topology() const
CaloParticleDebugger(const edm::ParameterSet &)
std::pair< int, int > simToReco(int cell, int layer, int mod, bool half) const
std::vector< edm::EDGetTokenT< std::vector< PCaloHit > > > collectionTagsToken_
edm::InputTag genParticles_
const SimClusterRefVector & simClusters() const
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
const HGCalTopology & topology() const
float energy() const
Energy. Note this is taken from the first SimTrack only.
Abs< T >::type abs(const T &t)
edm::EDGetTokenT< std::vector< SimTrack > > simTracksToken_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::EDGetTokenT< std::vector< CaloParticle > > caloParticlesToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
math::XYZVectorF momentum() const
spatial momentum vector
T const * product() const
const HGCalDDDConstants & dddConstants() const
void fillSimHits(std::map< int, float > &, const edm::Event &, const edm::EventSetup &)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
int pdgId() const
PDG ID.
edm::EDGetTokenT< std::vector< reco::GenParticle > > genParticlesToken_
void analyze(const edm::Event &, const edm::EventSetup &) override
size_type size() const
Size of the RefVector.
DetId relabel(const uint32_t testId) const
edm::InputTag trackingParticles_
edm::InputTag caloParticles_
edm::InputTag simVertices_
static void unpackHexagonIndex(const uint32_t &idx, int &subdet, int &z, int &lay, int &wafer, int &celltyp, int &cell)
std::vector< edm::InputTag > collectionTags_
~CaloParticleDebugger() override
edm::EDGetTokenT< std::vector< SimVertex > > simVerticesToken_