CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
HitParentTest Class Reference
Inheritance diagram for HitParentTest:
edm::one::EDAnalyzer< edm::one::WatchRuns, edm::one::SharedResources > edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

 HitParentTest (const edm::ParameterSet &ps)
 
 ~HitParentTest () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::WatchRuns, edm::one::SharedResources >
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Protected Member Functions

void analyze (const edm::Event &e, const edm::EventSetup &c) override
 
void beginJob () override
 
void beginRun (edm::Run const &, edm::EventSetup const &) override
 
void endJob () override
 
void endRun (edm::Run const &, edm::EventSetup const &) override
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
void resetItemsToGetFrom (BranchType iType)
 

Private Member Functions

void analyzeAPDHits (const std::vector< PCaloHit > &, const edm::Handle< edm::SimTrackContainer > &, const edm::Handle< edm::SimVertexContainer > &, int depth)
 
void analyzeHits (const std::vector< PCaloHit > &, const edm::Handle< edm::SimTrackContainer > &, const edm::Handle< edm::SimVertexContainer > &, int type)
 
math::XYZTLorentzVectorD getOldestParentVertex (const edm::Handle< edm::SimTrackContainer > &, const edm::Handle< edm::SimVertexContainer > &, edm::SimTrackContainer::const_iterator track)
 
edm::SimTrackContainer::const_iterator parentSimTrack (const edm::Handle< edm::SimTrackContainer > &, const edm::Handle< edm::SimVertexContainer > &, edm::SimTrackContainer::const_iterator thisTrkItr)
 
bool simTrackPresent (const edm::Handle< edm::SimTrackContainer > &, int id)
 
bool validSimTrack (const edm::Handle< edm::SimTrackContainer > &, const edm::Handle< edm::SimVertexContainer > &, unsigned int simTkId, edm::SimTrackContainer::const_iterator thisTrkItr)
 

Private Attributes

std::string detector [7]
 
const std::string g4Label_
 
bool histos
 
const std::string hitLabEB_
 
const std::string hitLabEE_
 
const std::string hitLabES_
 
const std::string hitLabHC_
 
TH1F * hitRho [7]
 
TH1F * hitType [7]
 
TH1F * hitZ [7]
 
unsigned int noGenParticle [7]
 
unsigned int noParent [7]
 
unsigned int noSimTrack [7]
 
unsigned int num_apd_hits_no_gen_particle [2]
 
unsigned int num_apd_hits_no_parent [2]
 
unsigned int num_apd_hits_no_simtrack [2]
 
std::map< int, unsigned > particle_type_count
 
const std::string sourceLabel
 
const edm::EDGetTokenT< edm::PCaloHitContainertok_eb_
 
const edm::EDGetTokenT< edm::PCaloHitContainertok_ee_
 
const edm::EDGetTokenT< edm::PCaloHitContainertok_es_
 
const edm::EDGetTokenT< edm::PCaloHitContainertok_hc_
 
const edm::EDGetTokenT< edm::SimTrackContainertok_tk_
 
const edm::EDGetTokenT< edm::SimVertexContainertok_vtx_
 
unsigned int total_num_apd_hits_seen [2]
 
unsigned int totalHits [7]
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 

Detailed Description

Definition at line 31 of file HitParentTest.cc.

Constructor & Destructor Documentation

◆ HitParentTest()

HitParentTest::HitParentTest ( const edm::ParameterSet ps)

Definition at line 98 of file HitParentTest.cc.

References detector, g4Label_, hitLabEB_, hitLabEE_, hitLabES_, hitLabHC_, mps_fire::i, TFileService::kSharedResource, noGenParticle, noParent, noSimTrack, num_apd_hits_no_gen_particle, num_apd_hits_no_parent, num_apd_hits_no_simtrack, AlCaHLTBitMon_QueryRunRegistry::string, total_num_apd_hits_seen, and totalHits.

99  : sourceLabel(ps.getUntrackedParameter<std::string>("SourceLabel", "VtxSmeared")),
100  g4Label_(ps.getUntrackedParameter<std::string>("ModuleLabel", "g4SimHits")),
101  hitLabEB_(ps.getUntrackedParameter<std::string>("EBCollection", "EcalHitsEB")),
102  hitLabEE_(ps.getUntrackedParameter<std::string>("EECollection", "EcalHitsEE")),
103  hitLabES_(ps.getUntrackedParameter<std::string>("ESCollection", "EcalHitsES")),
104  hitLabHC_(ps.getUntrackedParameter<std::string>("HCCollection", "HcalHits")),
105  tok_eb_(consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, hitLabEB_))),
106  tok_ee_(consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, hitLabEE_))),
107  tok_es_(consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, hitLabES_))),
108  tok_hc_(consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, hitLabHC_))),
109  tok_tk_(consumes<edm::SimTrackContainer>(edm::InputTag(g4Label_))),
110  tok_vtx_(consumes<edm::SimVertexContainer>(edm::InputTag(g4Label_))) {
111  usesResource(TFileService::kSharedResource);
112 
113  edm::LogVerbatim("HitParentTest") << "Module Label: " << g4Label_ << " Hits: " << hitLabEB_ << ", " << hitLabEE_
114  << ", " << hitLabES_ << ", " << hitLabHC_;
115 
116  for (unsigned int i = 0; i < 2; ++i) {
121  }
122  std::string dets[7] = {"EB", "EE", "ES", "HB", "HE", "HO", "HF"};
123  for (unsigned int i = 0; i < 7; ++i) {
124  detector[i] = dets[i];
125  totalHits[i] = 0;
126  noParent[i] = 0;
127  noSimTrack[i] = 0;
128  noGenParticle[i] = 0;
129  }
130 }
static const std::string kSharedResource
Definition: TFileService.h:76
Log< level::Info, true > LogVerbatim
unsigned int noGenParticle[7]
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_eb_
unsigned int num_apd_hits_no_simtrack[2]
unsigned int noSimTrack[7]
std::string detector[7]
unsigned int noParent[7]
const std::string hitLabES_
T getUntrackedParameter(std::string const &, T const &) const
unsigned int num_apd_hits_no_gen_particle[2]
const std::string sourceLabel
const std::string hitLabEE_
const edm::EDGetTokenT< edm::SimVertexContainer > tok_vtx_
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_hc_
unsigned int num_apd_hits_no_parent[2]
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_es_
const edm::EDGetTokenT< edm::SimTrackContainer > tok_tk_
const std::string g4Label_
unsigned int total_num_apd_hits_seen[2]
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_ee_
unsigned int totalHits[7]
const std::string hitLabHC_
const std::string hitLabEB_

◆ ~HitParentTest()

HitParentTest::~HitParentTest ( )
inlineoverride

Definition at line 34 of file HitParentTest.cc.

34 {}

Member Function Documentation

◆ analyze()

void HitParentTest::analyze ( const edm::Event e,
const edm::EventSetup c 
)
overrideprotectedvirtual

Implements edm::one::EDAnalyzerBase.

Definition at line 171 of file HitParentTest.cc.

References analyzeAPDHits(), analyzeHits(), hcalRecHitTable_cff::depth, MillePedeFileConverter_cfg::e, edm::HandleBase::isValid(), tok_eb_, tok_ee_, tok_es_, tok_hc_, tok_tk_, and tok_vtx_.

171  {
172  edm::LogVerbatim("HitParentTest") << "HitParentTes::Run = " << e.id().run() << " Event = " << e.id().event();
173 
174  // get PCaloHits for ecal barrel
175  const edm::Handle<edm::PCaloHitContainer>& caloHitEB = e.getHandle(tok_eb_);
176 
177  // get PCaloHits for ecal endcap
178  const edm::Handle<edm::PCaloHitContainer>& caloHitEE = e.getHandle(tok_ee_);
179 
180  // get PCaloHits for preshower
181  const edm::Handle<edm::PCaloHitContainer>& caloHitES = e.getHandle(tok_es_);
182 
183  // get PCaloHits for hcal
184  const edm::Handle<edm::PCaloHitContainer>& caloHitHC = e.getHandle(tok_hc_);
185 
186  // get sim tracks
187  const edm::Handle<edm::SimTrackContainer>& simTk = e.getHandle(tok_tk_);
188 
189  // get sim vertices
190  const edm::Handle<edm::SimVertexContainer>& simVtx = e.getHandle(tok_vtx_);
191 
192  edm::LogVerbatim("HitParentTest") << "HitParentTest: hits valid[EB]: " << caloHitEB.isValid()
193  << " valid[EE]: " << caloHitEE.isValid() << " valid[ES]: " << caloHitES.isValid()
194  << " valid[HC]: " << caloHitHC.isValid();
195 
196  if (caloHitEB.isValid()) {
197  for (int depth = 1; depth <= 2; ++depth)
198  analyzeAPDHits(*caloHitEB, simTk, simVtx, depth);
199  analyzeHits(*caloHitEB, simTk, simVtx, 0);
200  }
201  if (caloHitEE.isValid())
202  analyzeHits(*caloHitEE, simTk, simVtx, 1);
203  if (caloHitES.isValid())
204  analyzeHits(*caloHitES, simTk, simVtx, 2);
205  if (caloHitHC.isValid())
206  analyzeHits(*caloHitHC, simTk, simVtx, 3);
207 }
Log< level::Info, true > LogVerbatim
void analyzeHits(const std::vector< PCaloHit > &, const edm::Handle< edm::SimTrackContainer > &, const edm::Handle< edm::SimVertexContainer > &, int type)
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_eb_
const edm::EDGetTokenT< edm::SimVertexContainer > tok_vtx_
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_hc_
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_es_
const edm::EDGetTokenT< edm::SimTrackContainer > tok_tk_
bool isValid() const
Definition: HandleBase.h:70
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_ee_
void analyzeAPDHits(const std::vector< PCaloHit > &, const edm::Handle< edm::SimTrackContainer > &, const edm::Handle< edm::SimVertexContainer > &, int depth)

◆ analyzeAPDHits()

void HitParentTest::analyzeAPDHits ( const std::vector< PCaloHit > &  hits,
const edm::Handle< edm::SimTrackContainer > &  simTk,
const edm::Handle< edm::SimVertexContainer > &  simVtx,
int  depth 
)
private

Definition at line 337 of file HitParentTest.cc.

References hcalRecHitTable_cff::depth, newFWLiteAna::found, getOldestParentVertex(), hfClusterShapes_cfi::hits, match(), num_apd_hits_no_gen_particle, num_apd_hits_no_parent, num_apd_hits_no_simtrack, parentSimTrack(), particle_type_count, simTrackPresent(), total_num_apd_hits_seen, and validSimTrack().

Referenced by analyze().

340  {
341  for (std::vector<PCaloHit>::const_iterator hit_it = hits.begin(); hit_it != hits.end(); ++hit_it) {
342  if (hit_it->depth() == depth) {
344 
345  // get the geant track id
346  int hit_geant_track_id = hit_it->geantTrackId();
347 
348  if (hit_geant_track_id <= 0) {
350  } else {
351  bool found = false;
352  // check whether this id is actually there in the list of simtracks
353  for (edm::SimTrackContainer::const_iterator simTrkItr = simTk->begin(); simTrkItr != simTk->end() && !found;
354  ++simTrkItr) {
355  if (hit_geant_track_id == (int)(simTrkItr->trackId())) {
356  found = true;
357  bool match = validSimTrack(simTk, simVtx, hit_geant_track_id, simTrkItr);
358 
359  edm::LogVerbatim("HitParentTest")
360  << "APDHIT Match = " << match << " hit_geant_track_id = " << hit_geant_track_id
361  << " particle id=" << simTrkItr->type();
362 
363  if (!match) {
364  edm::LogVerbatim("HitParentTest") << "NO MATCH FOUND !";
366  }
367 
368  int apd_pid = simTrkItr->type();
369  std::map<int, unsigned>::iterator count_it = particle_type_count.find(apd_pid);
370  if (count_it == particle_type_count.end())
371  // first occurence of this particle pid
372  particle_type_count[apd_pid] = 1;
373  else
374  ++count_it->second;
375 
376  //--------------------
377  // check where the oldest parent has its vertex. Should be close to the
378  // beam pipe...
379  math::XYZTLorentzVectorD oldest_parent_vertex = getOldestParentVertex(simTk, simVtx, simTrkItr);
380 
381  edm::SimTrackContainer::const_iterator oldest_parent_track = parentSimTrack(simTk, simVtx, simTrkItr);
382 
383  edm::LogVerbatim("HitParentTest")
384  << "APD hit pid = " << apd_pid << " APD hit track id = " << hit_geant_track_id
385  << " depth = " << hit_it->depth() << " OLDEST PARENT'S VERTEX: " << oldest_parent_vertex
386  << " rho = " << oldest_parent_vertex.Rho() << " OLDEST PARENT'S PID: " << oldest_parent_track->type()
387  << " OLDEST PARENT'S track id: " << oldest_parent_track->trackId() << "\n"
388  << "APD hit vertex index: " << simTrkItr->vertIndex() << " (tot #vertices: " << simVtx->size() << ")"
389  << "\n"
390  << "APD hit vertex parent track: " << (*simVtx)[simTrkItr->vertIndex()].parentIndex()
391  << " present=" << simTrackPresent(simTk, (*simVtx)[simTrkItr->vertIndex()].parentIndex());
392 
393  } // a match was found
394  } // geant track id found in simtracks
395 
396  if (!found)
398  } // hits with a valid SimTrack Id
399  } // right depth index
400  } // loop over all calohits (of the given depth)
401 }
Log< level::Info, true > LogVerbatim
bool simTrackPresent(const edm::Handle< edm::SimTrackContainer > &, int id)
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
edm::SimTrackContainer::const_iterator parentSimTrack(const edm::Handle< edm::SimTrackContainer > &, const edm::Handle< edm::SimVertexContainer > &, edm::SimTrackContainer::const_iterator thisTrkItr)
bool validSimTrack(const edm::Handle< edm::SimTrackContainer > &, const edm::Handle< edm::SimVertexContainer > &, unsigned int simTkId, edm::SimTrackContainer::const_iterator thisTrkItr)
unsigned int num_apd_hits_no_simtrack[2]
unsigned int num_apd_hits_no_gen_particle[2]
std::map< int, unsigned > particle_type_count
unsigned int num_apd_hits_no_parent[2]
unsigned int total_num_apd_hits_seen[2]
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
math::XYZTLorentzVectorD getOldestParentVertex(const edm::Handle< edm::SimTrackContainer > &, const edm::Handle< edm::SimVertexContainer > &, edm::SimTrackContainer::const_iterator track)

◆ analyzeHits()

void HitParentTest::analyzeHits ( const std::vector< PCaloHit > &  hits,
const edm::Handle< edm::SimTrackContainer > &  simTk,
const edm::Handle< edm::SimVertexContainer > &  simVtx,
int  type 
)
private

performs some checks on hits

Definition at line 264 of file HitParentTest.cc.

References detector, RemoveAddSevLevel::flag, newFWLiteAna::found, getOldestParentVertex(), HcalEndcap, HcalForward, HcalOuter, histos, hitRho, hfClusterShapes_cfi::hits, hitType, hitZ, l1ctLayer2EG_cff::id, match(), noGenParticle, noParent, noSimTrack, parentSimTrack(), simTrackPresent(), HcalDetId::subdet(), totalHits, and validSimTrack().

Referenced by analyze().

267  {
268  for (std::vector<PCaloHit>::const_iterator hit_it = hits.begin(); hit_it != hits.end(); ++hit_it) {
269  int id(type), flag(0);
270  if (type == 3) {
271  HcalDetId id_ = HcalDetId(hit_it->id());
272  int subdet = id_.subdet();
273  if (subdet == static_cast<int>(HcalEndcap))
274  id = type + 1;
275  else if (subdet == static_cast<int>(HcalOuter))
276  id = type + 2;
277  else if (subdet == static_cast<int>(HcalForward))
278  id = type + 3;
279  }
280  ++totalHits[id];
281 
282  // get the geant track id
283  int hit_geant_track_id = hit_it->geantTrackId();
284 
285  if (hit_geant_track_id <= 0) {
286  ++noParent[id];
287  flag = 1;
288  } else {
289  bool found = false;
290  flag = 2;
291  // check whether this id is actually there in the list of simtracks
292  for (edm::SimTrackContainer::const_iterator simTrkItr = simTk->begin(); simTrkItr != simTk->end() && !found;
293  ++simTrkItr) {
294  if (hit_geant_track_id == (int)(simTrkItr->trackId())) {
295  found = true;
296  flag = 3;
297  bool match = validSimTrack(simTk, simVtx, hit_geant_track_id, simTrkItr);
298 
299  edm::LogVerbatim("HitParentTest")
300  << "[" << detector[type] << "] Match = " << match << " hit_geant_track_id=" << hit_geant_track_id
301  << " particle id=" << simTrkItr->type();
302 
303  if (!match) {
304  edm::LogVerbatim("HitParentTest") << "NO MATCH FOUND !";
305  ++noGenParticle[id];
306  }
307 
308  // beam pipe...
309  int pid = simTrkItr->type();
310  math::XYZTLorentzVectorD oldest_parent_vertex = getOldestParentVertex(simTk, simVtx, simTrkItr);
311 
312  edm::SimTrackContainer::const_iterator oldest_parent_track = parentSimTrack(simTk, simVtx, simTrkItr);
313 
314  edm::LogVerbatim("HitParentTest")
315  << "[" << detector[type] << "] Hit pid = " << pid << " hit track id = " << hit_geant_track_id
316  << " Oldest Parent's Vertex: " << oldest_parent_vertex << " rho = " << oldest_parent_vertex.Rho()
317  << " Oldest Parent's pid: " << oldest_parent_track->type()
318  << " Oldest Parent's track id: " << oldest_parent_track->trackId()
319  << "\nHit vertex index: " << simTrkItr->vertIndex() << " (tot #vertices: " << simVtx->size() << ")"
320  << "\nHit vertex parent track: " << (*simVtx)[simTrkItr->vertIndex()].parentIndex()
321  << " present=" << simTrackPresent(simTk, (*simVtx)[simTrkItr->vertIndex()].parentIndex());
322  if (histos) {
323  hitRho[id]->Fill(oldest_parent_vertex.Rho());
324  hitZ[id]->Fill(oldest_parent_vertex.Z());
325  }
326  } // a match was found
327  } // geant track id found in simtracks
328 
329  if (!found)
330  ++noSimTrack[id];
331  } // hits with a valid SimTrack Id
332  if (histos)
333  hitType[id]->Fill((double)(flag));
334  } // loop over all calohits (of the given depth)
335 }
Log< level::Info, true > LogVerbatim
bool simTrackPresent(const edm::Handle< edm::SimTrackContainer > &, int id)
TH1F * hitRho[7]
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
edm::SimTrackContainer::const_iterator parentSimTrack(const edm::Handle< edm::SimTrackContainer > &, const edm::Handle< edm::SimVertexContainer > &, edm::SimTrackContainer::const_iterator thisTrkItr)
unsigned int noGenParticle[7]
bool validSimTrack(const edm::Handle< edm::SimTrackContainer > &, const edm::Handle< edm::SimVertexContainer > &, unsigned int simTkId, edm::SimTrackContainer::const_iterator thisTrkItr)
unsigned int noSimTrack[7]
std::string detector[7]
unsigned int noParent[7]
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
TH1F * hitZ[7]
TH1F * hitType[7]
unsigned int totalHits[7]
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
math::XYZTLorentzVectorD getOldestParentVertex(const edm::Handle< edm::SimTrackContainer > &, const edm::Handle< edm::SimVertexContainer > &, edm::SimTrackContainer::const_iterator track)

◆ beginJob()

void HitParentTest::beginJob ( void  )
overrideprotectedvirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 143 of file HitParentTest.cc.

References detector, histos, hitRho, hitType, hitZ, mps_fire::i, Skims_PA_cff::name, compare::tfile, and runGCPTkAlMap::title.

143  {
145  if (!tfile.isAvailable()) {
146  edm::LogVerbatim("HitParentTest") << "TFileService unavailable: no histograms";
147  histos = false;
148  } else {
149  char name[20], title[100];
150  histos = true;
151  for (unsigned int i = 0; i < 7; ++i) {
152  sprintf(name, "HitType%d", i);
153  sprintf(title, "Hit types for %s", detector[i].c_str());
154  hitType[i] = tfile->make<TH1F>(name, title, 10, 0., 10.);
155  hitType[i]->GetXaxis()->SetTitle(title);
156  hitType[i]->GetYaxis()->SetTitle("Hits");
157  sprintf(name, "RhoVertex%d", i);
158  sprintf(title, "#rho of the vertex for %s Hits", detector[i].c_str());
159  hitRho[i] = tfile->make<TH1F>(name, title, 10000, 0., 100.);
160  hitRho[i]->GetXaxis()->SetTitle(title);
161  hitRho[i]->GetYaxis()->SetTitle("Hits");
162  sprintf(name, "ZVertex%d", i);
163  sprintf(title, "z of the vertex for %s Hits", detector[i].c_str());
164  hitZ[i] = tfile->make<TH1F>(name, title, 2000, -100., 100.);
165  hitZ[i]->GetXaxis()->SetTitle(title);
166  hitZ[i]->GetYaxis()->SetTitle("Hits");
167  }
168  }
169 }
Log< level::Info, true > LogVerbatim
TH1F * hitRho[7]
std::string detector[7]
TH1F * hitZ[7]
Definition: tfile.py:1
TH1F * hitType[7]

◆ beginRun()

void HitParentTest::beginRun ( edm::Run const &  ,
edm::EventSetup const &   
)
inlineoverrideprotected

Definition at line 39 of file HitParentTest.cc.

39 {}

◆ endJob()

void HitParentTest::endJob ( void  )
overrideprotectedvirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 221 of file HitParentTest.cc.

References hcalRecHitTable_cff::depth, detector, mps_fire::i, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, noGenParticle, noParent, noSimTrack, num_apd_hits_no_gen_particle, num_apd_hits_no_parent, num_apd_hits_no_simtrack, particle_type_count, jetUpdater_cfi::sort, total_num_apd_hits_seen, and totalHits.

221  {
222  edm::LogVerbatim("HitParentTest") << "HitParentTest::Total number of APD hits seen: "
224  for (unsigned int depth = 0; depth < 2; ++depth) {
225  edm::LogVerbatim("HitParentTest") << "APD Hits in depth = " << depth + 1
226  << " Total = " << total_num_apd_hits_seen[depth];
227  edm::LogVerbatim("HitParentTest") << "summary of errors:\n"
228  << " number of APD hits with zero geant track id: "
229  << num_apd_hits_no_parent[depth] << "\n"
230  << "number of APD hits for which the parent simtrack was not found "
231  << "in the simtrack collection: " << num_apd_hits_no_simtrack[depth] << "\n"
232  << "number of APD hits for which no generator particle was "
233  << "found: " << num_apd_hits_no_gen_particle[depth] << "\n";
234  }
235 
236  for (unsigned int det = 0; det < 7; ++det) {
237  edm::LogVerbatim("HitParentTest") << "Total number of hits seen in " << detector[det] << ": " << totalHits[det];
238  edm::LogVerbatim("HitParentTest") << "summary of errors:\n"
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: "
243  << noGenParticle[det] << "\n";
244  }
245 
246  // sort in decreasing order of occurence
247  std::vector<int> sorted_pids;
248  for (std::map<int, unsigned>::const_iterator it = particle_type_count.begin(); it != particle_type_count.end(); ++it)
249  sorted_pids.push_back(it->first);
250 
251  // now sort the pids
252 
253  std::sort(sorted_pids.begin(), sorted_pids.end(), HitParentTestComparison(particle_type_count));
254 
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];
259  edm::LogVerbatim("HitParentTest") << " pid " << std::setw(6) << pid << ": count " << std::setw(6)
260  << particle_type_count[pid];
261  }
262 }
Log< level::Info, true > LogVerbatim
unsigned int noGenParticle[7]
unsigned int num_apd_hits_no_simtrack[2]
unsigned int noSimTrack[7]
std::string detector[7]
unsigned int noParent[7]
unsigned int num_apd_hits_no_gen_particle[2]
std::map< int, unsigned > particle_type_count
unsigned int num_apd_hits_no_parent[2]
unsigned int total_num_apd_hits_seen[2]
unsigned int totalHits[7]

◆ endRun()

void HitParentTest::endRun ( edm::Run const &  ,
edm::EventSetup const &   
)
inlineoverrideprotected

Definition at line 41 of file HitParentTest.cc.

41 {}

◆ fillDescriptions()

void HitParentTest::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 132 of file HitParentTest.cc.

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, and AlCaHLTBitMon_QueryRunRegistry::string.

132  {
134  desc.addUntracked<std::string>("SourceLabel", "generatorSmeared");
135  desc.addUntracked<std::string>("ModuleLabel", "g4SimHits");
136  desc.addUntracked<std::string>("EBCollection", "EcalHitsEB");
137  desc.addUntracked<std::string>("EECollection", "EcalHitsEE");
138  desc.addUntracked<std::string>("ESCollection", "EcalHitsES");
139  desc.addUntracked<std::string>("HCCollection", "HcalHits");
140  descriptions.add("HitParentTest", desc);
141 }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ getOldestParentVertex()

math::XYZTLorentzVectorD HitParentTest::getOldestParentVertex ( const edm::Handle< edm::SimTrackContainer > &  simTk,
const edm::Handle< edm::SimVertexContainer > &  simVtx,
edm::SimTrackContainer::const_iterator  track 
)
private

Definition at line 411 of file HitParentTest.cc.

References parentSimTrack(), and HLT_2023v12_cff::track.

Referenced by analyzeAPDHits(), and analyzeHits().

413  {
414  static const math::XYZTLorentzVectorD invalid_vertex(
415  10000, 10000, 10000, 10000); // default value if no valid vertex found
416 
417  edm::SimTrackContainer::const_iterator oldest_parent_track = parentSimTrack(simTk, simVtx, track);
418 
419  int vertex_index = oldest_parent_track->vertIndex();
420 
421  // sanity checks
422  if (vertex_index < 0 || vertex_index >= (int)(simVtx->size()))
423  return invalid_vertex;
424 
425  return (*simVtx)[vertex_index].position();
426 }
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
edm::SimTrackContainer::const_iterator parentSimTrack(const edm::Handle< edm::SimTrackContainer > &, const edm::Handle< edm::SimVertexContainer > &, edm::SimTrackContainer::const_iterator thisTrkItr)

◆ parentSimTrack()

edm::SimTrackContainer::const_iterator HitParentTest::parentSimTrack ( const edm::Handle< edm::SimTrackContainer > &  simTk,
const edm::Handle< edm::SimVertexContainer > &  simVtx,
edm::SimTrackContainer::const_iterator  thisTrkItr 
)
private

Definition at line 428 of file HitParentTest.cc.

References ALCARECOTkAlJpsiMuMu_cff::charge, createfilelist::int, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::iv, and class-composition::parent.

Referenced by analyzeAPDHits(), analyzeHits(), and getOldestParentVertex().

430  {
431  edm::SimTrackContainer::const_iterator itr = simTk->end();
432 
433  int vertIndex = thisTrkItr->vertIndex();
434  int type = thisTrkItr->type();
435  int charge = (int)thisTrkItr->charge();
436  edm::LogVerbatim("HitParentTest") << "SimTrackParent:: " << thisTrkItr->trackId() << " Vertex " << vertIndex
437  << " Type " << type << " Charge " << charge;
438 
439  if (vertIndex == -1)
440  return thisTrkItr;
441  else if (vertIndex >= (int)simVtx->size())
442  return itr;
443 
444  edm::SimVertexContainer::const_iterator simVtxItr = simVtx->begin();
445  for (int iv = 0; iv < vertIndex; iv++)
446  simVtxItr++;
447  int parent = simVtxItr->parentIndex();
448 
449  if (parent < 0 && simVtxItr != simVtx->begin()) {
450  const math::XYZTLorentzVectorD pos1 = simVtxItr->position();
451  for (simVtxItr = simVtx->begin(); simVtxItr != simVtx->end(); ++simVtxItr) {
452  if (simVtxItr->parentIndex() > 0) {
453  const math::XYZTLorentzVectorD pos2 = pos1 - simVtxItr->position();
454  double dist = pos2.P();
455  if (dist < 0.001) {
456  parent = simVtxItr->parentIndex();
457  break;
458  }
459  }
460  }
461  }
462  for (edm::SimTrackContainer::const_iterator simTrkItr = simTk->begin(); simTrkItr != simTk->end(); simTrkItr++) {
463  if ((int)simTrkItr->trackId() == parent && simTrkItr != thisTrkItr)
464  return parentSimTrack(simTk, simVtx, simTrkItr);
465  }
466 
467  return thisTrkItr;
468 }
Log< level::Info, true > LogVerbatim
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
edm::SimTrackContainer::const_iterator parentSimTrack(const edm::Handle< edm::SimTrackContainer > &, const edm::Handle< edm::SimVertexContainer > &, edm::SimTrackContainer::const_iterator thisTrkItr)

◆ simTrackPresent()

bool HitParentTest::simTrackPresent ( const edm::Handle< edm::SimTrackContainer > &  simTk,
int  id 
)
private

Definition at line 403 of file HitParentTest.cc.

Referenced by analyzeAPDHits(), and analyzeHits().

403  {
404  for (edm::SimTrackContainer::const_iterator simTrkItr = simTk->begin(); simTrkItr != simTk->end(); ++simTrkItr) {
405  if ((int)(simTrkItr->trackId()) == id)
406  return true;
407  }
408  return false;
409 }

◆ validSimTrack()

bool HitParentTest::validSimTrack ( const edm::Handle< edm::SimTrackContainer > &  simTk,
const edm::Handle< edm::SimVertexContainer > &  simVtx,
unsigned int  simTkId,
edm::SimTrackContainer::const_iterator  thisTrkItr 
)
private

Definition at line 470 of file HitParentTest.cc.

References ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::iv, and class-composition::parent.

Referenced by analyzeAPDHits(), and analyzeHits().

473  {
474  edm::LogVerbatim("HitParentTest") << "Inside validSimTrack: trackId " << thisTrkItr->trackId() << " vtxIndex "
475  << thisTrkItr->vertIndex() << " to be matched to " << simTkId;
476 
477  //This track originates from simTkId
478  if (thisTrkItr->trackId() == simTkId)
479  return true;
480 
481  //Otherwise trace back the history using SimTracks and SimVertices
482  int vertIndex = thisTrkItr->vertIndex();
483  if (vertIndex == -1 || vertIndex >= (int)simVtx->size())
484  return false;
485  edm::SimVertexContainer::const_iterator simVtxItr = simVtx->begin();
486  for (int iv = 0; iv < vertIndex; iv++)
487  simVtxItr++;
488  int parent = simVtxItr->parentIndex();
489  edm::LogVerbatim("HitParentTest") << "validSimTrack:: parent index " << parent << " ";
490  if (parent < 0 && simVtxItr != simVtx->begin()) {
491  const math::XYZTLorentzVectorD pos1 = simVtxItr->position();
492  for (simVtxItr = simVtx->begin(); simVtxItr != simVtx->end(); ++simVtxItr) {
493  if (simVtxItr->parentIndex() > 0) {
494  const math::XYZTLorentzVectorD pos2 = pos1 - simVtxItr->position();
495  double dist = pos2.P();
496  if (dist < 0.001) {
497  parent = simVtxItr->parentIndex();
498  break;
499  }
500  }
501  }
502  }
503  edm::LogVerbatim("HitParentTest") << "HitParentTes::final index " << parent;
504  for (edm::SimTrackContainer::const_iterator simTrkItr = simTk->begin(); simTrkItr != simTk->end(); simTrkItr++) {
505  if ((int)simTrkItr->trackId() == parent && simTrkItr != thisTrkItr)
506  return validSimTrack(simTk, simVtx, simTkId, simTrkItr);
507  }
508 
509  return false;
510 }
Log< level::Info, true > LogVerbatim
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
bool validSimTrack(const edm::Handle< edm::SimTrackContainer > &, const edm::Handle< edm::SimVertexContainer > &, unsigned int simTkId, edm::SimTrackContainer::const_iterator thisTrkItr)

Member Data Documentation

◆ detector

std::string HitParentTest::detector[7]
private

Definition at line 91 of file HitParentTest.cc.

Referenced by analyzeHits(), beginJob(), endJob(), and HitParentTest().

◆ g4Label_

const std::string HitParentTest::g4Label_
private

Definition at line 68 of file HitParentTest.cc.

Referenced by HitParentTest().

◆ histos

bool HitParentTest::histos
private

Definition at line 92 of file HitParentTest.cc.

Referenced by analyzeHits(), and beginJob().

◆ hitLabEB_

const std::string HitParentTest::hitLabEB_
private

Definition at line 68 of file HitParentTest.cc.

Referenced by HitParentTest().

◆ hitLabEE_

const std::string HitParentTest::hitLabEE_
private

Definition at line 68 of file HitParentTest.cc.

Referenced by HitParentTest().

◆ hitLabES_

const std::string HitParentTest::hitLabES_
private

Definition at line 68 of file HitParentTest.cc.

Referenced by HitParentTest().

◆ hitLabHC_

const std::string HitParentTest::hitLabHC_
private

Definition at line 68 of file HitParentTest.cc.

Referenced by HitParentTest().

◆ hitRho

TH1F * HitParentTest::hitRho[7]
private

Definition at line 95 of file HitParentTest.cc.

Referenced by analyzeHits(), and beginJob().

◆ hitType

TH1F* HitParentTest::hitType[7]
private

Definition at line 95 of file HitParentTest.cc.

Referenced by ntupleDataFormat._RecoHitAdaptor::_hits(), analyzeHits(), and beginJob().

◆ hitZ

TH1F * HitParentTest::hitZ[7]
private

Definition at line 95 of file HitParentTest.cc.

Referenced by analyzeHits(), and beginJob().

◆ noGenParticle

unsigned int HitParentTest::noGenParticle[7]
private

Definition at line 94 of file HitParentTest.cc.

Referenced by analyzeHits(), endJob(), and HitParentTest().

◆ noParent

unsigned int HitParentTest::noParent[7]
private

Definition at line 93 of file HitParentTest.cc.

Referenced by analyzeHits(), endJob(), and HitParentTest().

◆ noSimTrack

unsigned int HitParentTest::noSimTrack[7]
private

Definition at line 94 of file HitParentTest.cc.

Referenced by analyzeHits(), endJob(), and HitParentTest().

◆ num_apd_hits_no_gen_particle

unsigned int HitParentTest::num_apd_hits_no_gen_particle[2]
private

number of APD hits for which no generator particle was found

Definition at line 85 of file HitParentTest.cc.

Referenced by analyzeAPDHits(), endJob(), and HitParentTest().

◆ num_apd_hits_no_parent

unsigned int HitParentTest::num_apd_hits_no_parent[2]
private

Definition at line 78 of file HitParentTest.cc.

Referenced by analyzeAPDHits(), endJob(), and HitParentTest().

◆ num_apd_hits_no_simtrack

unsigned int HitParentTest::num_apd_hits_no_simtrack[2]
private

number of apd hits for which the parent sim track id was not found in the simtrack collection.

Definition at line 82 of file HitParentTest.cc.

Referenced by analyzeAPDHits(), endJob(), and HitParentTest().

◆ particle_type_count

std::map<int, unsigned> HitParentTest::particle_type_count
private

'histogram' of types of particles going through the APD. Maps from numeric particle code to the number of occurences.

Definition at line 89 of file HitParentTest.cc.

Referenced by analyzeAPDHits(), and endJob().

◆ sourceLabel

const std::string HitParentTest::sourceLabel
private

Definition at line 68 of file HitParentTest.cc.

◆ tok_eb_

const edm::EDGetTokenT<edm::PCaloHitContainer> HitParentTest::tok_eb_
private

Definition at line 69 of file HitParentTest.cc.

Referenced by analyze().

◆ tok_ee_

const edm::EDGetTokenT<edm::PCaloHitContainer> HitParentTest::tok_ee_
private

Definition at line 70 of file HitParentTest.cc.

Referenced by analyze().

◆ tok_es_

const edm::EDGetTokenT<edm::PCaloHitContainer> HitParentTest::tok_es_
private

Definition at line 71 of file HitParentTest.cc.

Referenced by analyze().

◆ tok_hc_

const edm::EDGetTokenT<edm::PCaloHitContainer> HitParentTest::tok_hc_
private

Definition at line 72 of file HitParentTest.cc.

Referenced by analyze().

◆ tok_tk_

const edm::EDGetTokenT<edm::SimTrackContainer> HitParentTest::tok_tk_
private

Definition at line 73 of file HitParentTest.cc.

Referenced by analyze().

◆ tok_vtx_

const edm::EDGetTokenT<edm::SimVertexContainer> HitParentTest::tok_vtx_
private

Definition at line 74 of file HitParentTest.cc.

Referenced by analyze().

◆ total_num_apd_hits_seen

unsigned int HitParentTest::total_num_apd_hits_seen[2]
private

error and other counters

Definition at line 77 of file HitParentTest.cc.

Referenced by analyzeAPDHits(), endJob(), and HitParentTest().

◆ totalHits

unsigned int HitParentTest::totalHits[7]
private

Definition at line 93 of file HitParentTest.cc.

Referenced by analyzeHits(), endJob(), and HitParentTest().