CMS 3D CMS Logo

CaloTruthAccumulator.h
Go to the documentation of this file.
1 #ifndef CaloAnalysis_CaloTruthAccumulator_h
2 #define CaloAnalysis_CaloTruthAccumulator_h
3 
5 #include <memory> // required for std::auto_ptr
9 
10 #include <unordered_map>
15 
16 typedef unsigned Index_t;
17 typedef int Barcode_t;
18 typedef std::pair<Index_t,Index_t> IndexPair_t;
19 typedef std::pair<IndexPair_t,float> SimHitInfo_t;
20 typedef std::pair<Barcode_t,Index_t> BarcodeIndexPair_t;
21 typedef std::pair<Barcode_t,Barcode_t> BarcodePair_t;
22 typedef std::pair<DetId,float> SimHitInfoPerRecoDetId_t;
23 typedef std::vector<SimHitInfoPerRecoDetId_t> SimHitInfoPerSimTrack_t;
24 
25 
26 // typedef uint32_t RecoDetId_t;
27 
28 // Forward declarations
29 namespace edm {
30  class ParameterSet;
31  class ConsumesCollector;
32  namespace stream {
33  class EDProducerBase;
34  }
35  class Event;
36  class EventSetup;
37  class StreamID;
38 }
40 class PCaloHit;
41 class SimTrack;
42 class SimVertex;
43 
45  public:
47  private:
48  void initializeEvent( const edm::Event& event, const edm::EventSetup& setup ) override;
49  void accumulate( const edm::Event& event, const edm::EventSetup& setup ) override;
50  void accumulate( const PileUpEventPrincipal& event, const edm::EventSetup& setup, edm::StreamID const& ) override;
51  void finalizeEvent( edm::Event& event, const edm::EventSetup& setup ) override;
52  void beginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) override;
53 
55  template<class T> void accumulateEvent( const T& event, const edm::EventSetup& setup, const edm::Handle< edm::HepMCProduct >& hepMCproduct );
56 
58  template<class T> void fillSimHits( std::vector<std::pair<DetId,const PCaloHit*> > & returnValue, const T& event, const edm::EventSetup& setup );
59 
60  std::vector<Barcode_t> descendantTrackBarcodes( Barcode_t barcode );
61  std::unique_ptr<SimHitInfoPerSimTrack_t> attachedSimHitInfo( Barcode_t st, const std::vector<std::pair<DetId,const PCaloHit*> > & hits,
62  bool includeOwn = true, bool includeOther = false, bool markUsed = false);
63  std::unique_ptr<SimHitInfoPerSimTrack_t> descendantOnlySimHitInfo( Barcode_t st, const std::vector<std::pair<DetId,const PCaloHit*> > & hits, bool markUsed = false);
64  std::unique_ptr<SimHitInfoPerSimTrack_t> allAttachedSimHitInfo( Barcode_t st, const std::vector<std::pair<DetId,const PCaloHit*> > & hits, bool markUsed = false);
65 
66  SimClusterCollection descendantSimClusters( Barcode_t barcode, const std::vector<std::pair<DetId,const PCaloHit*> > & hits );
68  void setConsideredBarcode( Barcode_t barcode ) { m_simTracksConsideredForSimClusters.insert( barcode ); }
69  bool consideredBarcode( Barcode_t barcode ) {
70  // return (std::find(m_simTracksConsideredForSimClusters.begin(), m_simTracksConsideredForSimClusters.end(), barcode) != m_simTracksConsideredForSimClusters.end());
71  return m_simTracksConsideredForSimClusters.count( barcode );
72  }
73 
75 
76  struct calo_particles {
77  std::vector<uint32_t> sc_start_;
78  std::vector<uint32_t> sc_stop_;
79 
80  void swap(calo_particles& oth) {
81  sc_start_.swap(oth.sc_start_);
82  sc_stop_.swap(oth.sc_stop_);
83  }
84 
85  void clear() {
86  sc_start_.clear();
87  sc_stop_.clear();
88  }
89  };
90 
92  double caloStartZ;
93 
94  std::unordered_map<Index_t,float> m_detIdToTotalSimEnergy; // keep track of cell normalizations
95  std::unordered_map<Barcode_t,Index_t> m_genParticleBarcodeToIndex;
96  std::unordered_map<Barcode_t,Index_t> m_simTrackBarcodeToIndex;
97  std::unordered_map<Barcode_t,Index_t> m_genBarcodeToSimTrackIndex;
98  std::unordered_map<Barcode_t,Index_t> m_simVertexBarcodeToIndex;
99  std::unordered_multimap<Index_t,Index_t> m_detIdToCluster;
100  std::unordered_multimap<Barcode_t,Index_t> m_simHitBarcodeToIndex;
101  std::unordered_multimap<Barcode_t,Barcode_t> m_simVertexBarcodeToSimTrackBarcode;
102  std::unordered_map<Barcode_t,Barcode_t> m_simTrackBarcodeToSimVertexParentBarcode;
103  std::unordered_multimap<Barcode_t,Index_t> m_simTrackToSimVertex;
104  std::unordered_multimap<Barcode_t,Index_t> m_simVertexToSimTrackParent;
105  // std::unordered_multimap<RecoDetId_t,SimHitInfo_t> m_recoDetIdToSimHits;
106 
107  std::vector<Barcode_t> m_simVertexBarcodes;
108 
109  // const double volumeRadius_;
110  // const double volumeZ_;
112  // const double vertexDistanceCut_;
113  // const bool ignoreTracksOutsideVolume_;
114 
117  const unsigned int maximumPreviousBunchCrossing_;
122  // const bool createUnmergedCollection_;
123  // const bool createMergedCollection_;
125  // const bool createInitialVertexCollection_;
127  // const bool addAncestors_;
128 
133 
134  std::vector<edm::InputTag> collectionTags_;
138 
139  const double minEnergy_, maxPseudoRapidity_;
140 
146 
148 
156  // bool allowDifferentProcessTypeForDifferentDetectors_;
157  public:
158  // These always go hand in hand, and I need to pass them around in the internal
159  // functions, so I might as well package them up in a struct.
161  {
162  std::unique_ptr<SimClusterCollection> pSimClusters;
163  std::unique_ptr<CaloParticleCollection> pCaloParticles;
164  // std::auto_ptr<TrackingVertexCollection> pTrackingVertices;
165  // TrackingParticleRefProd refTrackingParticles;
166  // TrackingVertexRefProd refTrackingVertexes;
167  };
168  private:
169  const HGCalTopology* hgtopo_[2];
170  const HGCalDDDConstants* hgddd_[2];
173 };
174 
175 #endif // end of "#ifndef CaloAnalysis_CaloTruthAccumulator_h"
std::pair< Index_t, Index_t > IndexPair_t
void setConsideredBarcode(Barcode_t barcode)
std::pair< Barcode_t, Barcode_t > BarcodePair_t
calo_particles m_caloParticles
std::unordered_multimap< Index_t, Index_t > m_detIdToCluster
edm::Handle< std::vector< SimVertex > > hSimVertices
std::unordered_multimap< Barcode_t, Index_t > m_simTrackToSimVertex
std::unordered_multimap< Barcode_t, Index_t > m_simHitBarcodeToIndex
const unsigned int maximumSubsequentBunchCrossing_
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
std::unordered_map< Barcode_t, Index_t > m_genParticleBarcodeToIndex
std::unordered_map< Barcode_t, Index_t > m_genBarcodeToSimTrackIndex
std::vector< edm::InputTag > collectionTags_
Definition: config.py:1
bool signalOnly_
Uses the same config as selector_, but can be used to drop out early since selector_ requires the Tra...
OutputCollections output_
std::pair< Barcode_t, Index_t > BarcodeIndexPair_t
edm::InputTag hepMCproductLabel_
Needed to add HepMC::GenVertex to SimVertex.
const std::string messageCategory_
The message category used to send messages to MessageLogger.
const edm::InputTag simVertexLabel_
bool consideredBarcode(Barcode_t barcode)
std::unordered_map< Barcode_t, Barcode_t > m_simTrackBarcodeToSimVertexParentBarcode
std::vector< Barcode_t > m_simVertexBarcodes
const edm::InputTag simTrackLabel_
If bremsstrahlung merging, whether to also add the unmerged collection to the event or not...
std::unordered_map< Barcode_t, Index_t > m_simTrackBarcodeToIndex
edm::Handle< std::vector< SimTrack > > hSimTracks
std::unordered_map< Barcode_t, Index_t > m_simVertexBarcodeToIndex
std::unique_ptr< CaloParticleCollection > pCaloParticles
unsigned Index_t
const HcalDDDRecConstants * hcddd_
std::vector< SimHitInfoPerRecoDetId_t > SimHitInfoPerSimTrack_t
int Barcode_t
std::set< Barcode_t > m_simTracksConsideredForSimClusters
HLT enums.
std::pair< DetId, float > SimHitInfoPerRecoDetId_t
std::unique_ptr< SimClusterCollection > pSimClusters
When counting hits, allows hits in different detectors to have a different process type...
std::unordered_multimap< Barcode_t, Index_t > m_simVertexToSimTrackParent
std::vector< SimCluster > SimClusterCollection
Definition: SimClusterFwd.h:8
std::unordered_map< Index_t, float > m_detIdToTotalSimEnergy
long double T
std::unordered_multimap< Barcode_t, Barcode_t > m_simVertexBarcodeToSimTrackBarcode
Definition: event.py:1
const unsigned int maximumPreviousBunchCrossing_
maximum distance for HepMC::GenVertex to be added to SimVertex
std::pair< IndexPair_t, float > SimHitInfo_t
bool chargedOnly_
Uses the same config as selector_, but can be used to drop out early since selector_ requires the Tra...