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>
16 
17 typedef unsigned Index_t;
18 typedef int Barcode_t;
19 typedef std::pair<Index_t,Index_t> IndexPair_t;
20 typedef std::pair<IndexPair_t,float> SimHitInfo_t;
21 typedef std::pair<Barcode_t,Index_t> BarcodeIndexPair_t;
22 typedef std::pair<Barcode_t,Barcode_t> BarcodePair_t;
23 typedef std::pair<DetId,float> SimHitInfoPerRecoDetId_t;
24 typedef std::vector<SimHitInfoPerRecoDetId_t> SimHitInfoPerSimTrack_t;
25 
26 
27 // typedef uint32_t RecoDetId_t;
28 
29 // Forward declarations
30 namespace edm {
31  class ParameterSet;
32  class ConsumesCollector;
33  class ProducerBase;
34  class Event;
35  class EventSetup;
36  class StreamID;
37 }
39 class PCaloHit;
40 class SimTrack;
41 class SimVertex;
42 
44  public:
46  private:
47  void initializeEvent( const edm::Event& event, const edm::EventSetup& setup ) override;
48  void accumulate( const edm::Event& event, const edm::EventSetup& setup ) override;
49  void accumulate( const PileUpEventPrincipal& event, const edm::EventSetup& setup, edm::StreamID const& ) override;
50  void finalizeEvent( edm::Event& event, const edm::EventSetup& setup ) override;
51  void beginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& setup) override;
52 
54  template<class T> void accumulateEvent( const T& event, const edm::EventSetup& setup, const edm::Handle< edm::HepMCProduct >& hepMCproduct );
55 
57  template<class T> void fillSimHits( std::vector<std::pair<DetId,const PCaloHit*> > & returnValue, const T& event, const edm::EventSetup& setup );
58 
59  std::vector<Barcode_t> descendantTrackBarcodes( Barcode_t barcode );
60  std::unique_ptr<SimHitInfoPerSimTrack_t> attachedSimHitInfo( Barcode_t st, const std::vector<std::pair<DetId,const PCaloHit*> > & hits,
61  bool includeOwn = true, bool includeOther = false, bool markUsed = false);
62  std::unique_ptr<SimHitInfoPerSimTrack_t> descendantOnlySimHitInfo( Barcode_t st, const std::vector<std::pair<DetId,const PCaloHit*> > & hits, bool markUsed = false);
63  std::unique_ptr<SimHitInfoPerSimTrack_t> allAttachedSimHitInfo( Barcode_t st, const std::vector<std::pair<DetId,const PCaloHit*> > & hits, bool markUsed = false);
64 
65  SimClusterCollection descendantSimClusters( Barcode_t barcode, const std::vector<std::pair<DetId,const PCaloHit*> > & hits );
67  void setConsideredBarcode( Barcode_t barcode ) { m_simTracksConsideredForSimClusters.insert( barcode ); }
68  bool consideredBarcode( Barcode_t barcode ) {
69  // return (std::find(m_simTracksConsideredForSimClusters.begin(), m_simTracksConsideredForSimClusters.end(), barcode) != m_simTracksConsideredForSimClusters.end());
70  return m_simTracksConsideredForSimClusters.count( barcode );
71  }
72 
74 
75  struct calo_particles {
76  std::vector<uint32_t> sc_start_;
77  std::vector<uint32_t> sc_stop_;
78 
79  void swap(calo_particles& oth) {
80  sc_start_.swap(oth.sc_start_);
81  sc_stop_.swap(oth.sc_stop_);
82  }
83 
84  void clear() {
85  sc_start_.clear();
86  sc_stop_.clear();
87  }
88  };
89 
91  double caloStartZ;
92 
93  std::unordered_map<Index_t,float> m_detIdToTotalSimEnergy; // keep track of cell normalizations
94  std::unordered_map<Barcode_t,Index_t> m_genParticleBarcodeToIndex;
95  std::unordered_map<Barcode_t,Index_t> m_simTrackBarcodeToIndex;
96  std::unordered_map<Barcode_t,Index_t> m_genBarcodeToSimTrackIndex;
97  std::unordered_map<Barcode_t,Index_t> m_simVertexBarcodeToIndex;
98  std::unordered_multimap<Index_t,Index_t> m_detIdToCluster;
99  std::unordered_multimap<Barcode_t,Index_t> m_simHitBarcodeToIndex;
100  std::unordered_multimap<Barcode_t,Barcode_t> m_simVertexBarcodeToSimTrackBarcode;
101  std::unordered_map<Barcode_t,Barcode_t> m_simTrackBarcodeToSimVertexParentBarcode;
102  std::unordered_multimap<Barcode_t,Index_t> m_simTrackToSimVertex;
103  std::unordered_multimap<Barcode_t,Index_t> m_simVertexToSimTrackParent;
104  // std::unordered_multimap<RecoDetId_t,SimHitInfo_t> m_recoDetIdToSimHits;
105 
106  std::vector<Barcode_t> m_simVertexBarcodes;
107 
108  // const double volumeRadius_;
109  // const double volumeZ_;
111  // const double vertexDistanceCut_;
112  // const bool ignoreTracksOutsideVolume_;
113 
116  const unsigned int maximumPreviousBunchCrossing_;
121  // const bool createUnmergedCollection_;
122  // const bool createMergedCollection_;
124  // const bool createInitialVertexCollection_;
126  // const bool addAncestors_;
127 
132 
133  std::vector<edm::InputTag> collectionTags_;
137 
138  const double minEnergy_, maxPseudoRapidity_;
139 
145 
147 
155  // bool allowDifferentProcessTypeForDifferentDetectors_;
156  public:
157  // These always go hand in hand, and I need to pass them around in the internal
158  // functions, so I might as well package them up in a struct.
160  {
161  std::unique_ptr<SimClusterCollection> pSimClusters;
162  std::unique_ptr<CaloParticleCollection> pCaloParticles;
163  // std::auto_ptr<TrackingVertexCollection> pTrackingVertices;
164  // TrackingParticleRefProd refTrackingParticles;
165  // TrackingVertexRefProd refTrackingVertexes;
166  };
167  private:
168  const HGCalTopology* hgtopo_[2];
169  const HGCalDDDConstants* hgddd_[2];
172 };
173 
174 #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...