CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes
CaloTruthCellsProducer Class Reference
Inheritance diagram for CaloTruthCellsProducer:
edm::stream::EDProducer<>

Public Member Functions

 CaloTruthCellsProducer (edm::ParameterSet const &)
 
 ~CaloTruthCellsProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Types

typedef edm::AssociationMap< edm::OneToMany< CaloParticleCollection, l1t::HGCalTriggerCellBxCollection > > CaloToCellsMap
 

Private Member Functions

std::unordered_map< uint32_t, double > makeHitMap (edm::Event const &, edm::EventSetup const &, HGCalTriggerGeometryBase const &) const
 
void produce (edm::Event &, edm::EventSetup const &) override
 

Private Attributes

edm::EDGetTokenT< CaloParticleCollectioncaloParticlesToken_
 
HGCalClusteringDummyImpl dummyClustering_
 
bool makeCellsCollection_
 
HGCalShowerShape showerShape_
 
edm::EDGetTokenT< std::vector< PCaloHit > > simHitsTokenEE_
 
edm::EDGetTokenT< std::vector< PCaloHit > > simHitsTokenHEback_
 
edm::EDGetTokenT< std::vector< PCaloHit > > simHitsTokenHEfront_
 
edm::EDGetTokenT< l1t::HGCalTriggerCellBxCollectiontriggerCellsToken_
 
HGCalTriggerTools triggerTools_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Definition at line 26 of file CaloTruthCellsProducer.cc.

Member Typedef Documentation

◆ CaloToCellsMap

Definition at line 40 of file CaloTruthCellsProducer.cc.

Constructor & Destructor Documentation

◆ CaloTruthCellsProducer()

CaloTruthCellsProducer::CaloTruthCellsProducer ( edm::ParameterSet const &  config)
explicit

Definition at line 55 of file CaloTruthCellsProducer.cc.

56  : makeCellsCollection_(config.getParameter<bool>("makeCellsCollection")),
57  caloParticlesToken_(consumes<CaloParticleCollection>(config.getParameter<edm::InputTag>("caloParticles"))),
59  consumes<l1t::HGCalTriggerCellBxCollection>(config.getParameter<edm::InputTag>("triggerCells"))),
60  simHitsTokenEE_(consumes<std::vector<PCaloHit>>(config.getParameter<edm::InputTag>("simHitsEE"))),
61  simHitsTokenHEfront_(consumes<std::vector<PCaloHit>>(config.getParameter<edm::InputTag>("simHitsHEfront"))),
62  simHitsTokenHEback_(consumes<std::vector<PCaloHit>>(config.getParameter<edm::InputTag>("simHitsHEback"))),
63  dummyClustering_(config.getParameterSet("dummyClustering")) {
64  produces<CaloToCellsMap>();
65  produces<l1t::HGCalClusterBxCollection>();
66  produces<l1t::HGCalMulticlusterBxCollection>();
68  produces<l1t::HGCalTriggerCellBxCollection>();
69 }

References makeCellsCollection_.

◆ ~CaloTruthCellsProducer()

CaloTruthCellsProducer::~CaloTruthCellsProducer ( )
override

Definition at line 71 of file CaloTruthCellsProducer.cc.

71 {}

Member Function Documentation

◆ fillDescriptions()

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

Definition at line 271 of file CaloTruthCellsProducer.cc.

271  {
272  //The following says we do not know what parameters are allowed so do no validation
273  // Please change this to state exactly what you do use, even if it is no parameters
275  desc.setUnknown();
276  descriptions.addDefault(desc);
277 }

References edm::ConfigurationDescriptions::addDefault(), and submitPVResolutionJobs::desc.

◆ makeHitMap()

std::unordered_map< uint32_t, double > CaloTruthCellsProducer::makeHitMap ( edm::Event const &  event,
edm::EventSetup const &  setup,
HGCalTriggerGeometryBase const &  geometry 
) const
private

Definition at line 234 of file CaloTruthCellsProducer.cc.

235  {
236  std::unordered_map<uint32_t, double> hitMap; // cellId -> sim energy
237 
238  typedef std::function<DetId(DetId const&)> DetIdMapper;
239  typedef std::pair<edm::EDGetTokenT<std::vector<PCaloHit>> const*, DetIdMapper> SimHitSpec;
240 
241  SimHitSpec specs[3] = {{&simHitsTokenEE_,
242  [this, &geometry](DetId const& simId) -> DetId {
243  return this->triggerTools_.simToReco(simId, geometry.eeTopology());
244  }},
246  [this, &geometry](DetId const& simId) -> DetId {
247  return this->triggerTools_.simToReco(simId, geometry.fhTopology());
248  }},
249  {&simHitsTokenHEback_, nullptr}};
250  if (geometry.isV9Geometry())
251  specs[2].second = [this, &geometry](DetId const& simId) -> DetId {
252  return this->triggerTools_.simToReco(simId, geometry.hscTopology());
253  };
254  else
255  specs[2].second = [this, &geometry](DetId const& simId) -> DetId {
256  return this->triggerTools_.simToReco(simId, geometry.bhTopology());
257  };
258 
259  for (auto const& tt : specs) {
261  event.getByToken(*tt.first, handle);
262  auto const& simhits(*handle);
263 
264  for (auto const& simhit : simhits)
265  hitMap.emplace(tt.second(simhit.id()), simhit.energy());
266  }
267 
268  return hitMap;
269 }

References HiBiasedCentrality_cfi::function, geometry, patZpeak::handle, edm::second(), HLTBitAnalyser_cfi::simhits, simHitsTokenEE_, simHitsTokenHEback_, simHitsTokenHEfront_, HGCalTriggerTools::simToReco(), HistogramManager_cfi::specs, triggerTools_, and groupFilesInBlocks::tt.

Referenced by produce().

◆ produce()

void CaloTruthCellsProducer::produce ( edm::Event event,
edm::EventSetup const &  setup 
)
overrideprivate

Definition at line 73 of file CaloTruthCellsProducer.cc.

73  {
74  edm::Handle<CaloParticleCollection> caloParticlesHandle;
75  event.getByToken(caloParticlesToken_, caloParticlesHandle);
76  auto const& caloParticles(*caloParticlesHandle);
77 
79  event.getByToken(triggerCellsToken_, triggerCellsHandle);
80  auto const& triggerCells(*triggerCellsHandle);
81 
85 
87  setup.get<CaloGeometryRecord>().get(geometryHandle);
88  auto const& geometry(*geometryHandle);
89 
90  std::unordered_map<uint32_t, CaloParticleRef> tcToCalo;
91 
92  std::unordered_map<uint32_t, double> hitToEnergy(makeHitMap(event, setup, geometry)); // cellId -> sim energy
93  std::unordered_map<uint32_t, std::pair<double, double>>
94  tcToEnergies; // tcId -> {total sim energy, fractioned sim energy}
95 
96  for (auto const& he : hitToEnergy) {
97  DetId hitId(he.first);
98  // this line will throw if (for whatever reason) hitId is not mapped to a trigger cell id
99  uint32_t tcId(geometry.getTriggerCellFromCell(hitId));
100  tcToEnergies[tcId].first += he.second;
101  }
102 
103  // used later to order multiclusters
104  std::map<int, CaloParticleRef> orderedCaloRefs;
105 
106  for (unsigned iP(0); iP != caloParticles.size(); ++iP) {
107  auto const& caloParticle(caloParticles.at(iP));
108  if (caloParticle.g4Tracks().at(0).eventId().event() != 0) // pileup
109  continue;
110 
111  CaloParticleRef ref(caloParticlesHandle, iP);
112 
113  SimClusterRefVector const& simClusters(caloParticle.simClusters());
114  for (auto const& simCluster : simClusters) {
115  for (auto const& hAndF : simCluster->hits_and_fractions()) {
116  DetId hitId(hAndF.first);
117  uint32_t tcId;
118  try {
119  tcId = geometry.getTriggerCellFromCell(hitId);
120  } catch (cms::Exception const& ex) {
121  edm::LogError("CaloTruthCellsProducer") << ex.what();
122  continue;
123  }
124 
125  tcToCalo.emplace(tcId, ref);
126  tcToEnergies[tcId].second += hitToEnergy[hAndF.first] * hAndF.second;
127  }
128  }
129 
130  // ordered by the gen particle index
131  int genIndex(caloParticle.g4Tracks().at(0).genpartIndex() - 1);
132  orderedCaloRefs[genIndex] = ref;
133  }
134 
135  auto outMap(std::make_unique<CaloToCellsMap>(caloParticlesHandle, triggerCellsHandle));
136  std::unique_ptr<l1t::HGCalTriggerCellBxCollection> outCollection;
138  outCollection = std::make_unique<l1t::HGCalTriggerCellBxCollection>();
139 
140  typedef edm::Ptr<l1t::HGCalTriggerCell> TriggerCellPtr;
141  typedef edm::Ptr<l1t::HGCalCluster> ClusterPtr;
142 
143  // ClusteringDummyImpl only considers BX 0, so we dump all cells to one vector
144  std::vector<TriggerCellPtr> triggerCellPtrs;
145 
146  // loop through all bunch crossings
147  for (int bx(triggerCells.getFirstBX()); bx <= triggerCells.getLastBX(); ++bx) {
148  for (auto cItr(triggerCells.begin(bx)); cItr != triggerCells.end(bx); ++cItr) {
149  auto const& cell(*cItr);
150 
151  auto mapElem(tcToCalo.find(cell.detId()));
152  if (mapElem == tcToCalo.end())
153  continue;
154 
155  outMap->insert(mapElem->second,
156  edm::Ref<l1t::HGCalTriggerCellBxCollection>(triggerCellsHandle, triggerCells.key(cItr)));
157 
158  if (makeCellsCollection_) {
159  auto const& simEnergies(tcToEnergies.at(cell.detId()));
160  if (simEnergies.first > 0.) {
161  double eFraction(simEnergies.second / simEnergies.first);
162 
163  outCollection->push_back(bx, cell);
164  auto& newCell((*outCollection)[outCollection->size() - 1]);
165 
166  newCell.setMipPt(cell.mipPt() * eFraction);
167  newCell.setP4(cell.p4() * eFraction);
168  }
169  }
170 
171  triggerCellPtrs.emplace_back(triggerCellsHandle, triggerCells.key(cItr));
172  }
173  }
174 
175  event.put(std::move(outMap));
177  event.put(std::move(outCollection));
178 
179  auto outClusters(std::make_unique<l1t::HGCalClusterBxCollection>());
180 
181  auto sortCellPtrs(
182  [](TriggerCellPtr const& lhs, TriggerCellPtr const& rhs) -> bool { return lhs->mipPt() > rhs->mipPt(); });
183 
184  std::sort(triggerCellPtrs.begin(), triggerCellPtrs.end(), sortCellPtrs);
185  dummyClustering_.clusterizeDummy(triggerCellPtrs, *outClusters);
186 
187  std::unordered_map<unsigned, std::vector<unsigned>> caloToClusterIndices;
188  for (unsigned iC(0); iC != outClusters->size(); ++iC) {
189  auto const& cluster((*outClusters)[iC]);
190  // cluster detId and cell detId are identical
191  auto caloRef(tcToCalo.at(cluster.detId()));
192  caloToClusterIndices[caloRef.key()].push_back(iC);
193  }
194 
195  auto clustersHandle(event.put(std::move(outClusters)));
196 
197  auto outMulticlusters(std::make_unique<l1t::HGCalMulticlusterBxCollection>());
198 
199  for (auto const& ocr : orderedCaloRefs) {
200  auto const& ref(ocr.second);
201 
202  if (ref.isNull()) // shouldn't happen
203  continue;
204 
205  auto const& caloParticle(*ref);
206 
207  l1t::HGCalMulticluster multicluster;
208 
209  for (unsigned iC : caloToClusterIndices[ref.key()]) {
210  ClusterPtr clPtr(clustersHandle, iC);
211  multicluster.addConstituent(clPtr, true, 1.);
212  }
213 
214  // Set the gen particle index as the DetId
215  multicluster.setDetId(caloParticle.g4Tracks().at(0).genpartIndex() - 1);
216 
217  auto const& centre(multicluster.centre());
218  math::PtEtaPhiMLorentzVector multiclusterP4(multicluster.sumPt(), centre.eta(), centre.phi(), 0.);
219  multicluster.setP4(multiclusterP4);
220 
221  showerShape_.fillShapes(multicluster, geometry);
222 
223  // not setting the quality flag
224  // multicluster.setHwQual(id_->decision(multicluster));
225  // fill H/E
226  multicluster.saveHOverE();
227 
228  outMulticlusters->push_back(0, multicluster);
229  }
230 
231  event.put(std::move(outMulticlusters));
232 }

References l1t::HGCalClusterT< C >::addConstituent(), l1GtPatternGenerator_cfi::bx, caloTruthCellsProducer_cfi::caloParticles, caloParticlesToken_, l1t::HGCalClusterT< C >::centre(), HGCalClusteringDummyImpl::clusterizeDummy(), dummyClustering_, HGCalClusteringDummyImpl::eventSetup(), HGCalShowerShape::eventSetup(), HGCalTriggerTools::eventSetup(), HGCalShowerShape::fillShapes(), geometry, get, hcalSimParameters_cfi::he, makeCellsCollection_, makeHitMap(), eostools::move(), l1t::HGCalMulticluster::saveHOverE(), l1t::HGCalClusterT< C >::setDetId(), reco::LeafCandidate::setP4(), singleTopDQM_cfi::setup, showerShape_, l1t::HGCalClusterT< C >::sumPt(), caloTruthCellsProducer_cfi::triggerCells, triggerCellsToken_, triggerTools_, and cms::Exception::what().

Member Data Documentation

◆ caloParticlesToken_

edm::EDGetTokenT<CaloParticleCollection> CaloTruthCellsProducer::caloParticlesToken_
private

Definition at line 43 of file CaloTruthCellsProducer.cc.

Referenced by produce().

◆ dummyClustering_

HGCalClusteringDummyImpl CaloTruthCellsProducer::dummyClustering_
private

Definition at line 49 of file CaloTruthCellsProducer.cc.

Referenced by produce().

◆ makeCellsCollection_

bool CaloTruthCellsProducer::makeCellsCollection_
private

Definition at line 42 of file CaloTruthCellsProducer.cc.

Referenced by CaloTruthCellsProducer(), and produce().

◆ showerShape_

HGCalShowerShape CaloTruthCellsProducer::showerShape_
private

Definition at line 50 of file CaloTruthCellsProducer.cc.

Referenced by produce().

◆ simHitsTokenEE_

edm::EDGetTokenT<std::vector<PCaloHit> > CaloTruthCellsProducer::simHitsTokenEE_
private

Definition at line 45 of file CaloTruthCellsProducer.cc.

Referenced by makeHitMap().

◆ simHitsTokenHEback_

edm::EDGetTokenT<std::vector<PCaloHit> > CaloTruthCellsProducer::simHitsTokenHEback_
private

Definition at line 47 of file CaloTruthCellsProducer.cc.

Referenced by makeHitMap().

◆ simHitsTokenHEfront_

edm::EDGetTokenT<std::vector<PCaloHit> > CaloTruthCellsProducer::simHitsTokenHEfront_
private

Definition at line 46 of file CaloTruthCellsProducer.cc.

Referenced by makeHitMap().

◆ triggerCellsToken_

edm::EDGetTokenT<l1t::HGCalTriggerCellBxCollection> CaloTruthCellsProducer::triggerCellsToken_
private

Definition at line 44 of file CaloTruthCellsProducer.cc.

Referenced by produce().

◆ triggerTools_

HGCalTriggerTools CaloTruthCellsProducer::triggerTools_
private

Definition at line 52 of file CaloTruthCellsProducer.cc.

Referenced by makeHitMap(), and produce().

CaloTruthCellsProducer::makeCellsCollection_
bool makeCellsCollection_
Definition: CaloTruthCellsProducer.cc:42
l1t::HGCalClusterT::setDetId
void setDetId(uint32_t id)
Definition: HGCalClusterT.h:94
HGCalShowerShape::fillShapes
void fillShapes(l1t::HGCalMulticluster &, const HGCalTriggerGeometryBase &) const
Definition: HGCalShowerShape.cc:515
geometry
ESHandle< TrackerGeometry > geometry
Definition: TkLasBeamFitter.cc:200
HGCalTriggerTools::eventSetup
void eventSetup(const edm::EventSetup &)
Definition: HGCalTriggerTools.cc:35
CaloTruthCellsProducer::simHitsTokenHEfront_
edm::EDGetTokenT< std::vector< PCaloHit > > simHitsTokenHEfront_
Definition: CaloTruthCellsProducer.cc:46
l1t::HGCalMulticluster::saveHOverE
void saveHOverE()
Definition: HGCalMulticluster.h:31
groupFilesInBlocks.tt
int tt
Definition: groupFilesInBlocks.py:144
l1t::HGCalClusterT::sumPt
double sumPt() const
Definition: HGCalClusterT.h:96
patZpeak.handle
handle
Definition: patZpeak.py:23
CaloTruthCellsProducer::caloParticlesToken_
edm::EDGetTokenT< CaloParticleCollection > caloParticlesToken_
Definition: CaloTruthCellsProducer.cc:43
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
geometry
Definition: geometry.py:1
HistogramManager_cfi.specs
specs
Definition: HistogramManager_cfi.py:80
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
CaloTruthCellsProducer::showerShape_
HGCalShowerShape showerShape_
Definition: CaloTruthCellsProducer.cc:50
edm::RefVector< SimClusterCollection >
cms::Exception::what
char const * what() const noexcept override
Definition: Exception.cc:103
edm::Handle
Definition: AssociativeIterator.h:50
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
edm::Ref
Definition: AssociativeIterator.h:58
CaloTruthCellsProducer::triggerTools_
HGCalTriggerTools triggerTools_
Definition: CaloTruthCellsProducer.cc:52
config
Definition: config.py:1
DetId
Definition: DetId.h:17
l1t::HGCalMulticluster
Definition: HGCalMulticluster.h:13
HGCalClusteringDummyImpl::eventSetup
void eventSetup(const edm::EventSetup &es)
Definition: HGCalClusteringDummyImpl.h:17
caloTruthCellsProducer_cfi.caloParticles
caloParticles
Definition: caloTruthCellsProducer_cfi.py:6
edm::ESHandle< HGCalTriggerGeometryBase >
HGCalClusteringDummyImpl::clusterizeDummy
void clusterizeDummy(const std::vector< edm::Ptr< l1t::HGCalTriggerCell >> &triggerCellsPtrs, l1t::HGCalClusterBxCollection &clusters)
Definition: HGCalClusteringDummyImpl.cc:16
CaloTruthCellsProducer::dummyClustering_
HGCalClusteringDummyImpl dummyClustering_
Definition: CaloTruthCellsProducer.cc:49
HLTBitAnalyser_cfi.simhits
simhits
SIM objects.
Definition: HLTBitAnalyser_cfi.py:21
l1t::HGCalClusterT::centre
const GlobalPoint & centre() const
Definition: HGCalClusterT.h:101
HGCalShowerShape::eventSetup
void eventSetup(const edm::EventSetup &es)
Definition: HGCalShowerShape.h:21
CaloTruthCellsProducer::simHitsTokenEE_
edm::EDGetTokenT< std::vector< PCaloHit > > simHitsTokenEE_
Definition: CaloTruthCellsProducer.cc:45
l1t::HGCalClusterT::addConstituent
void addConstituent(const edm::Ptr< C > &c, bool updateCentre=true, float fraction=1.)
Definition: HGCalClusterT.h:55
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
HGCalTriggerTools::simToReco
DetId simToReco(const DetId &, const HGCalTopology &) const
Definition: HGCalTriggerTools.cc:346
get
#define get
edm::Ptr
Definition: AssociationVector.h:31
reco::LeafCandidate::setP4
void setP4(const LorentzVector &p4) final
set 4-momentum
Definition: LeafCandidate.h:158
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
hcalSimParameters_cfi.he
he
Definition: hcalSimParameters_cfi.py:79
CaloTruthCellsProducer::makeHitMap
std::unordered_map< uint32_t, double > makeHitMap(edm::Event const &, edm::EventSetup const &, HGCalTriggerGeometryBase const &) const
Definition: CaloTruthCellsProducer.cc:234
HiBiasedCentrality_cfi.function
function
Definition: HiBiasedCentrality_cfi.py:4
math::PtEtaPhiMLorentzVector
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
cms::Exception
Definition: Exception.h:70
event
Definition: event.py:1
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
CaloTruthCellsProducer::triggerCellsToken_
edm::EDGetTokenT< l1t::HGCalTriggerCellBxCollection > triggerCellsToken_
Definition: CaloTruthCellsProducer.cc:44
edm::InputTag
Definition: InputTag.h:15
caloTruthCellsProducer_cfi.triggerCells
triggerCells
Definition: caloTruthCellsProducer_cfi.py:7
CaloTruthCellsProducer::simHitsTokenHEback_
edm::EDGetTokenT< std::vector< PCaloHit > > simHitsTokenHEback_
Definition: CaloTruthCellsProducer.cc:47