27 #include <boost/format.hpp> 56 edm::SimTrackContainer::const_iterator
parentSimTrack(edm::SimTrackContainer::const_iterator thisTrkItr);
57 bool validSimTrack(
unsigned int simTkId, edm::SimTrackContainer::const_iterator thisTrkItr);
102 edm::LogVerbatim(
"HitParentTest") <<
"Module Label: " << g4Label <<
" Hits: " << hitLabEB <<
", " << hitLabEE
103 <<
", " << hitLabES <<
", " <<
hitLabHC;
112 for (
unsigned int i = 0;
i < 2; ++
i) {
118 std::string dets[7] = {
"EB",
"EE",
"ES",
"HB",
"HE",
"HO",
"HF"};
119 for (
unsigned int i = 0;
i < 7; ++
i) {
136 descriptions.
add(
"HitParentTest", desc);
142 edm::LogVerbatim(
"HitParentTest") <<
"TFileService unavailable: no histograms";
147 for (
unsigned int i = 0;
i < 7; ++
i) {
148 sprintf(name,
"HitType%d",
i);
149 sprintf(title,
"Hit types for %s",
detector[
i].c_str());
151 hitType[
i]->GetXaxis()->SetTitle(title);
152 hitType[
i]->GetYaxis()->SetTitle(
"Hits");
153 sprintf(name,
"RhoVertex%d",
i);
154 sprintf(title,
"#rho of the vertex for %s Hits",
detector[
i].c_str());
156 hitRho[
i]->GetXaxis()->SetTitle(title);
157 hitRho[
i]->GetYaxis()->SetTitle(
"Hits");
158 sprintf(name,
"ZVertex%d",
i);
159 sprintf(title,
"z of the vertex for %s Hits",
detector[
i].c_str());
161 hitZ[
i]->GetXaxis()->SetTitle(title);
162 hitZ[
i]->GetYaxis()->SetTitle(
"Hits");
193 <<
" valid[EE]: " << caloHitEE.
isValid() <<
" valid[ES]: " << caloHitES.
isValid()
194 <<
" valid[HC]: " << caloHitHC.
isValid();
216 : particle_type_count(_particle_type_count) {}
218 bool operator()(
int pid1,
int pid2)
const {
return particle_type_count.at(pid1) > particle_type_count.at(pid2); }
222 edm::LogVerbatim(
"HitParentTest") <<
"HitParentTest::Total number of APD hits seen: " 226 <<
" Total = " << total_num_apd_hits_seen[
depth];
228 <<
" number of APD hits with zero geant track id: " 230 <<
"number of APD hits for which the parent simtrack was not found " 232 <<
"number of APD hits for which no generator particle was " 236 for (
unsigned int det = 0; det < 7; ++det) {
239 <<
"number of hits with zero geant track id: " <<
noParent[det] <<
"\n" 240 <<
"number of hits for which the parent simtrack was not found in " 241 <<
"the simtrack collection: " <<
noSimTrack[det] <<
"\n" 242 <<
"number of hits for which no generator particle was found: " 247 std::vector<int> sorted_pids;
249 sorted_pids.push_back(it->first);
255 edm::LogVerbatim(
"HitParentTest") <<
"HitParentTest::Frequency particle types through the APD " 256 <<
"(pid/frequency):";
257 for (
unsigned i = 0;
i < sorted_pids.size(); ++
i) {
258 int pid = sorted_pids[
i];
265 for (std::vector<PCaloHit>::const_iterator hit_it = hits.begin(); hit_it != hits.end(); ++hit_it) {
269 int subdet = id_.
subdet();
272 else if (subdet == static_cast<int>(
HcalOuter))
280 int hit_geant_track_id = hit_it->geantTrackId();
282 if (hit_geant_track_id <= 0) {
289 for (edm::SimTrackContainer::const_iterator simTrkItr =
SimTk->begin(); simTrkItr !=
SimTk->end() && !
found;
291 if (hit_geant_track_id == (
int)(simTrkItr->trackId())) {
297 <<
"[" <<
detector[
type] <<
"] Match = " << match <<
" hit_geant_track_id=" << hit_geant_track_id
298 <<
" particle id=" << simTrkItr->type();
306 int pid = simTrkItr->type();
309 edm::SimTrackContainer::const_iterator oldest_parent_track =
parentSimTrack(simTrkItr);
312 <<
"[" <<
detector[
type] <<
"] Hit pid = " << pid <<
" hit track id = " << hit_geant_track_id
313 <<
" Oldest Parent's Vertex: " << oldest_parent_vertex <<
" rho = " << oldest_parent_vertex.Rho()
314 <<
" Oldest Parent's pid: " << oldest_parent_track->type()
315 <<
" Oldest Parent's track id: " << oldest_parent_track->trackId()
316 <<
"\nHit vertex index: " << simTrkItr->vertIndex() <<
" (tot #vertices: " <<
SimVtx->size() <<
")" 317 <<
"\nHit vertex parent track: " << (*SimVtx)[simTrkItr->vertIndex()].parentIndex()
320 hitRho[
id]->Fill(oldest_parent_vertex.Rho());
321 hitZ[
id]->Fill(oldest_parent_vertex.Z());
335 for (std::vector<PCaloHit>::const_iterator hit_it = hits.begin(); hit_it != hits.end(); ++hit_it) {
336 if (hit_it->depth() ==
depth) {
340 int hit_geant_track_id = hit_it->geantTrackId();
342 if (hit_geant_track_id <= 0) {
347 for (edm::SimTrackContainer::const_iterator simTrkItr =
SimTk->begin(); simTrkItr !=
SimTk->end() && !
found;
349 if (hit_geant_track_id == (
int)(simTrkItr->trackId())) {
354 <<
"APDHIT Match = " << match <<
" hit_geant_track_id = " << hit_geant_track_id
355 <<
" particle id=" << simTrkItr->type();
362 int apd_pid = simTrkItr->type();
375 edm::SimTrackContainer::const_iterator oldest_parent_track =
parentSimTrack(simTrkItr);
378 <<
"APD hit pid = " << apd_pid <<
" APD hit track id = " << hit_geant_track_id
379 <<
" depth = " << hit_it->depth() <<
" OLDEST PARENT'S VERTEX: " << oldest_parent_vertex
380 <<
" rho = " << oldest_parent_vertex.Rho() <<
" OLDEST PARENT'S PID: " << oldest_parent_track->type()
381 <<
" OLDEST PARENT'S track id: " << oldest_parent_track->trackId() <<
"\n" 382 <<
"APD hit vertex index: " << simTrkItr->vertIndex() <<
" (tot #vertices: " <<
SimVtx->size() <<
")" 384 <<
"APD hit vertex parent track: " << (*SimVtx)[simTrkItr->vertIndex()].parentIndex()
398 for (edm::SimTrackContainer::const_iterator simTrkItr =
SimTk->begin(); simTrkItr !=
SimTk->end(); ++simTrkItr) {
399 if ((
int)(simTrkItr->trackId()) ==
id)
407 10000, 10000, 10000, 10000);
409 edm::SimTrackContainer::const_iterator oldest_parent_track =
parentSimTrack(track);
411 int vertex_index = oldest_parent_track->vertIndex();
414 if (vertex_index < 0 || vertex_index >= (
int)(
SimVtx->size()))
415 return invalid_vertex;
417 return (*
SimVtx)[vertex_index].position();
421 edm::SimTrackContainer::const_iterator itr =
SimTk->end();
423 int vertIndex = thisTrkItr->vertIndex();
424 int type = thisTrkItr->type();
426 edm::LogVerbatim(
"HitParentTest") <<
"SimTrackParent:: " << thisTrkItr->trackId() <<
" Vertex " << vertIndex
427 <<
" Type " << type <<
" Charge " <<
charge;
431 else if (vertIndex >= (
int)
SimVtx->size())
434 edm::SimVertexContainer::const_iterator simVtxItr =
SimVtx->begin();
435 for (
int iv = 0; iv < vertIndex; iv++)
437 int parent = simVtxItr->parentIndex();
439 if (parent < 0 && simVtxItr != SimVtx->
begin()) {
441 for (simVtxItr =
SimVtx->begin(); simVtxItr !=
SimVtx->end(); ++simVtxItr) {
442 if (simVtxItr->parentIndex() > 0) {
444 double dist = pos2.P();
446 parent = simVtxItr->parentIndex();
452 for (edm::SimTrackContainer::const_iterator simTrkItr =
SimTk->begin(); simTrkItr !=
SimTk->end(); simTrkItr++) {
453 if ((
int)simTrkItr->trackId() == parent && simTrkItr != thisTrkItr)
461 edm::LogVerbatim(
"HitParentTest") <<
"Inside validSimTrack: trackId " << thisTrkItr->trackId() <<
" vtxIndex " 462 << thisTrkItr->vertIndex() <<
" to be matched to " << simTkId;
465 if (thisTrkItr->trackId() == simTkId)
469 int vertIndex = thisTrkItr->vertIndex();
470 if (vertIndex == -1 || vertIndex >= (
int)
SimVtx->size())
472 edm::SimVertexContainer::const_iterator simVtxItr =
SimVtx->begin();
473 for (
int iv = 0; iv < vertIndex; iv++)
475 int parent = simVtxItr->parentIndex();
476 edm::LogVerbatim(
"HitParentTest") <<
"validSimTrack:: parent index " << parent <<
" ";
477 if (parent < 0 && simVtxItr != SimVtx->
begin()) {
479 for (simVtxItr =
SimVtx->begin(); simVtxItr !=
SimVtx->end(); ++simVtxItr) {
480 if (simVtxItr->parentIndex() > 0) {
482 double dist = pos2.P();
484 parent = simVtxItr->parentIndex();
491 for (edm::SimTrackContainer::const_iterator simTrkItr =
SimTk->begin(); simTrkItr !=
SimTk->end(); simTrkItr++) {
492 if ((
int)simTrkItr->trackId() == parent && simTrkItr != thisTrkItr)
static const std::string kSharedResource
EventNumber_t event() const
edm::EDGetTokenT< edm::SimTrackContainer > tok_tk_
T getUntrackedParameter(std::string const &, T const &) const
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
HcalSubdetector subdet() const
get the subdetector
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
edm::EDGetTokenT< edm::SimVertexContainer > tok_vtx_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
unsigned int noGenParticle[7]
bool operator()(int pid1, int pid2) const
unsigned int num_apd_hits_no_simtrack[2]
const std::map< int, unsigned > & particle_type_count
edm::SimTrackContainer::const_iterator parentSimTrack(edm::SimTrackContainer::const_iterator thisTrkItr)
unsigned int noSimTrack[7]
T * make(const Args &...args) const
make new ROOT object
edm::Handle< edm::SimVertexContainer > SimVtx
unsigned int num_apd_hits_no_gen_particle[2]
void analyze(const edm::Event &e, const edm::EventSetup &c) override
#define DEFINE_FWK_MODULE(type)
edm::EDGetTokenT< edm::PCaloHitContainer > tok_ee_
edm::Handle< edm::SimTrackContainer > SimTk
void endRun(edm::Run const &, edm::EventSetup const &) override
std::map< int, unsigned > particle_type_count
HitParentTest(const edm::ParameterSet &ps)
edm::EDGetTokenT< edm::PCaloHitContainer > tok_eb_
bool validSimTrack(unsigned int simTkId, edm::SimTrackContainer::const_iterator thisTrkItr)
unsigned int num_apd_hits_no_parent[2]
math::XYZTLorentzVectorD getOldestParentVertex(edm::SimTrackContainer::const_iterator track)
HitParentTestComparison(const std::map< int, unsigned > &_particle_type_count)
edm::EDGetTokenT< edm::PCaloHitContainer > tok_hc_
void beginRun(edm::Run const &, edm::EventSetup const &) override
void analyzeHits(const std::vector< PCaloHit > &, int type)
bool simTrackPresent(int id)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
unsigned int total_num_apd_hits_seen[2]
void analyzeAPDHits(const std::vector< PCaloHit > &, int depth)
unsigned int totalHits[7]
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
edm::EDGetTokenT< edm::PCaloHitContainer > tok_es_
~HitParentTest() override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)