CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Types

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

Private Member Functions

void beginRun (const edm::Run &, const edm::EventSetup &) override
 
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
< CaloParticleCollection
caloParticlesToken_
 
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::HGCalTriggerCellBxCollection
triggerCellsToken_
 
edm::ESHandle
< HGCalTriggerGeometryBase
triggerGeomHandle_
 
edm::ESGetToken
< HGCalTriggerGeometryBase,
CaloGeometryRecord
triggerGeomToken_
 
HGCalTriggerTools triggerTools_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T...>
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T...>
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Definition at line 26 of file CaloTruthCellsProducer.cc.

Member Typedef Documentation

Definition at line 41 of file CaloTruthCellsProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 58 of file CaloTruthCellsProducer.cc.

References makeCellsCollection_.

59  : makeCellsCollection_(config.getParameter<bool>("makeCellsCollection")),
60  caloParticlesToken_(consumes<CaloParticleCollection>(config.getParameter<edm::InputTag>("caloParticles"))),
62  consumes<l1t::HGCalTriggerCellBxCollection>(config.getParameter<edm::InputTag>("triggerCells"))),
63  simHitsTokenEE_(consumes<std::vector<PCaloHit>>(config.getParameter<edm::InputTag>("simHitsEE"))),
64  simHitsTokenHEfront_(consumes<std::vector<PCaloHit>>(config.getParameter<edm::InputTag>("simHitsHEfront"))),
65  simHitsTokenHEback_(consumes<std::vector<PCaloHit>>(config.getParameter<edm::InputTag>("simHitsHEback"))),
66  triggerGeomToken_(esConsumes<HGCalTriggerGeometryBase, CaloGeometryRecord, edm::Transition::BeginRun>()),
67  dummyClustering_(config.getParameterSet("dummyClustering")) {
68  produces<CaloToCellsMap>();
69  produces<l1t::HGCalClusterBxCollection>();
70  produces<l1t::HGCalMulticlusterBxCollection>();
72  produces<l1t::HGCalTriggerCellBxCollection>();
73 }
HGCalClusteringDummyImpl dummyClustering_
edm::EDGetTokenT< std::vector< PCaloHit > > simHitsTokenEE_
edm::ESGetToken< HGCalTriggerGeometryBase, CaloGeometryRecord > triggerGeomToken_
edm::EDGetTokenT< l1t::HGCalTriggerCellBxCollection > triggerCellsToken_
edm::EDGetTokenT< CaloParticleCollection > caloParticlesToken_
edm::EDGetTokenT< std::vector< PCaloHit > > simHitsTokenHEback_
edm::EDGetTokenT< std::vector< PCaloHit > > simHitsTokenHEfront_
tuple config
parse the configuration file
CaloTruthCellsProducer::~CaloTruthCellsProducer ( )
override

Definition at line 75 of file CaloTruthCellsProducer.cc.

75 {}

Member Function Documentation

void CaloTruthCellsProducer::beginRun ( const edm::Run ,
const edm::EventSetup es 
)
overrideprivate

Definition at line 77 of file CaloTruthCellsProducer.cc.

References edm::EventSetup::getHandle(), triggerGeomHandle_, and triggerGeomToken_.

77  {
79 }
edm::ESGetToken< HGCalTriggerGeometryBase, CaloGeometryRecord > triggerGeomToken_
edm::ESHandle< HGCalTriggerGeometryBase > triggerGeomHandle_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
void CaloTruthCellsProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 271 of file CaloTruthCellsProducer.cc.

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

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 }
void addDefault(ParameterSetDescription const &psetDescription)
std::unordered_map< uint32_t, double > CaloTruthCellsProducer::makeHitMap ( edm::Event const &  event,
edm::EventSetup const &  setup,
HGCalTriggerGeometryBase const &  geometry 
) const
private

Definition at line 240 of file CaloTruthCellsProducer.cc.

References HGCalTriggerGeometryBase::eeTopology(), HGCalTriggerGeometryBase::fhTopology(), relativeConstraints::geometry, patZpeak::handle, HGCalTriggerGeometryBase::hscTopology(), simHitsTokenEE_, simHitsTokenHEback_, simHitsTokenHEfront_, HGCalTriggerTools::simToReco(), triggerTools_, and groupFilesInBlocks::tt.

Referenced by produce().

241  {
242  std::unordered_map<uint32_t, double> hitMap; // cellId -> sim energy
243 
244  typedef std::function<DetId(DetId const&)> DetIdMapper;
245  typedef std::pair<edm::EDGetTokenT<std::vector<PCaloHit>> const*, DetIdMapper> SimHitSpec;
246 
247  SimHitSpec specs[3] = {{&simHitsTokenEE_,
248  [this, &geometry](DetId const& simId) -> DetId {
249  return this->triggerTools_.simToReco(simId, geometry.eeTopology());
250  }},
252  [this, &geometry](DetId const& simId) -> DetId {
253  return this->triggerTools_.simToReco(simId, geometry.fhTopology());
254  }},
255  {&simHitsTokenHEback_, [this, &geometry](DetId const& simId) -> DetId {
256  return this->triggerTools_.simToReco(simId, geometry.hscTopology());
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 }
edm::EDGetTokenT< std::vector< PCaloHit > > simHitsTokenEE_
tuple handle
Definition: patZpeak.py:23
edm::EDGetTokenT< std::vector< PCaloHit > > simHitsTokenHEback_
Definition: DetId.h:17
edm::EDGetTokenT< std::vector< PCaloHit > > simHitsTokenHEfront_
DetId simToReco(const DetId &, const HGCalTopology &) const
void CaloTruthCellsProducer::produce ( edm::Event event,
edm::EventSetup const &  setup 
)
overrideprivate

Definition at line 81 of file CaloTruthCellsProducer.cc.

References l1t::HGCalClusterT< C >::addConstituent(), makePileupJSON::bx, caloTruthProducer_cfi::caloParticles, caloParticlesToken_, l1t::HGCalClusterT< C >::centre(), HGCalClusteringDummyImpl::clusterizeDummy(), dummyClustering_, HGCalShowerShape::fillShapes(), relativeConstraints::geometry, hcalSimParameters_cfi::he, makeCellsCollection_, makeHitMap(), eostools::move(), edm::ESHandle< class >::product(), edm::Event::put(), l1t::HGCalMulticluster::saveHOverE(), l1t::HGCalClusterT< C >::setDetId(), HGCalClusteringDummyImpl::setGeometry(), HGCalShowerShape::setGeometry(), HGCalTriggerTools::setGeometry(), reco::LeafCandidate::setP4(), showerShape_, l1t::HGCalClusterT< C >::sumPt(), triggerCellsToken_, triggerGeomHandle_, triggerTools_, and cms::Exception::what().

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

Member Data Documentation

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

Definition at line 44 of file CaloTruthCellsProducer.cc.

Referenced by produce().

HGCalClusteringDummyImpl CaloTruthCellsProducer::dummyClustering_
private

Definition at line 52 of file CaloTruthCellsProducer.cc.

Referenced by produce().

bool CaloTruthCellsProducer::makeCellsCollection_
private

Definition at line 43 of file CaloTruthCellsProducer.cc.

Referenced by CaloTruthCellsProducer(), and produce().

HGCalShowerShape CaloTruthCellsProducer::showerShape_
private

Definition at line 53 of file CaloTruthCellsProducer.cc.

Referenced by produce().

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

Definition at line 46 of file CaloTruthCellsProducer.cc.

Referenced by makeHitMap().

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

Definition at line 48 of file CaloTruthCellsProducer.cc.

Referenced by makeHitMap().

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

Definition at line 47 of file CaloTruthCellsProducer.cc.

Referenced by makeHitMap().

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

Definition at line 45 of file CaloTruthCellsProducer.cc.

Referenced by produce().

edm::ESHandle<HGCalTriggerGeometryBase> CaloTruthCellsProducer::triggerGeomHandle_
private

Definition at line 50 of file CaloTruthCellsProducer.cc.

Referenced by beginRun(), and produce().

edm::ESGetToken<HGCalTriggerGeometryBase, CaloGeometryRecord> CaloTruthCellsProducer::triggerGeomToken_
private

Definition at line 49 of file CaloTruthCellsProducer.cc.

Referenced by beginRun().

HGCalTriggerTools CaloTruthCellsProducer::triggerTools_
private

Definition at line 55 of file CaloTruthCellsProducer.cc.

Referenced by makeHitMap(), and produce().