CMS 3D CMS Logo

EcalBarrelClusterFastTimer.cc
Go to the documentation of this file.
1 // This producer eats standard PF ECAL clusters
2 // finds the corresponding fast-timing det IDs and attempts to
3 // assign a reasonable time guess
4 
7 
11 
13 
19 
22 
27 
28 #include <random>
29 #include <memory>
30 
32 #include "CLHEP/Units/SystemOfUnits.h"
34 
36 public:
39 
40  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
41 
42 private:
43  // inputs
46  // options
47  std::vector<std::unique_ptr<const ResolutionModel>> _resolutions;
48  const float minFraction_, minEnergy_;
49  const unsigned ecalDepth_;
50  // functions
51  std::pair<float, DetId> getTimeForECALPFCluster(const EcalRecHitCollection&, const reco::PFCluster&) const;
52  float correctTimeToVertex(const float intime,
53  const DetId& timeDet,
54  const reco::Vertex& vtx,
55  const CaloSubdetectorGeometry* ecalGeom) const;
56 };
57 
59 
60 namespace {
61  const std::string resolution("Resolution");
62 
63  constexpr float cm_per_ns = 29.9792458;
64 
65  template <typename T>
66  void writeValueMap(edm::Event& iEvent,
67  const edm::Handle<std::vector<reco::PFCluster>>& handle,
68  const std::vector<T>& values,
69  const std::string& label) {
70  auto valMap = std::make_unique<edm::ValueMap<T>>();
71  typename edm::ValueMap<T>::Filler filler(*valMap);
72  filler.insert(handle, values.begin(), values.end());
73  filler.fill();
74  iEvent.put(std::move(valMap), label);
75  }
76 } // namespace
77 
79  : ebTimeHitsToken_(consumes<EcalRecHitCollection>(conf.getParameter<edm::InputTag>("ebTimeHits"))),
80  ebClustersToken_(consumes<std::vector<reco::PFCluster>>(conf.getParameter<edm::InputTag>("ebClusters"))),
81  minFraction_(conf.getParameter<double>("minFractionToConsider")),
82  minEnergy_(conf.getParameter<double>("minEnergyToConsider")),
83  ecalDepth_(conf.getParameter<double>("ecalDepth")) {
84  // setup resolution models
85  const std::vector<edm::ParameterSet>& resos = conf.getParameterSetVector("resolutionModels");
86  for (const auto& reso : resos) {
87  const std::string& name = reso.getParameter<std::string>("modelName");
88  _resolutions.emplace_back(ResolutionModelFactory::get()->create(name, reso));
89 
90  // times and time resolutions for general tracks
91  produces<edm::ValueMap<float>>(name);
92  produces<edm::ValueMap<float>>(name + resolution);
93  }
94 }
95 
99 
100  evt.getByToken(ebClustersToken_, clustersH);
101  evt.getByToken(ebTimeHitsToken_, timehitsH);
102 
103  const auto& clusters = *clustersH;
104  const auto& timehits = *timehitsH;
105 
106  // get event-based seed for RNG
107  unsigned int runNum_uint = static_cast<unsigned int>(evt.id().run());
108  unsigned int lumiNum_uint = static_cast<unsigned int>(evt.id().luminosityBlock());
109  unsigned int evNum_uint = static_cast<unsigned int>(evt.id().event());
110  std::uint32_t seed = (lumiNum_uint << 10) + (runNum_uint << 20) + evNum_uint;
111  std::mt19937 rng(seed);
112 
113  std::vector<std::pair<float, DetId>> times; // perfect times keyed to cluster index
114  times.reserve(clusters.size());
115 
116  for (const auto& cluster : clusters) {
117  times.push_back(getTimeForECALPFCluster(timehits, cluster));
118  }
119 
120  for (const auto& reso : _resolutions) {
121  const std::string& name = reso->name();
122  std::vector<float> resolutions;
123  std::vector<float> smeared_times;
124  resolutions.reserve(clusters.size());
125  smeared_times.reserve(clusters.size());
126 
127  // smear once then correct to multiple vertices
128  for (unsigned i = 0; i < clusters.size(); ++i) {
129  const float theresolution = reso->getTimeResolution(clusters[i]);
130  std::normal_distribution<float> gausTime(times[i].first, theresolution);
131 
132  smeared_times.emplace_back(gausTime(rng));
133  resolutions.push_back(theresolution);
134  }
135 
136  writeValueMap(evt, clustersH, smeared_times, name);
137  writeValueMap(evt, clustersH, resolutions, name + resolution);
138  }
139 }
140 
142  const reco::PFCluster& cluster) const {
143  const auto& rhfs = cluster.recHitFractions();
144  unsigned best_hit = 0;
145  float best_energy = -1.f;
146  for (const auto& rhf : rhfs) {
147  const auto& hitref = rhf.recHitRef();
148  const unsigned detid = hitref->detId();
149  const auto fraction = rhf.fraction();
150  const auto energy = hitref->energy();
152  continue;
153  auto timehit = timehits.find(detid);
154  float e_hit = rhf.fraction() * hitref->energy();
155  if (e_hit > best_energy && timehit->isTimeValid()) {
156  best_energy = e_hit;
157  best_hit = detid;
158  }
159  }
160 
161  float best_time_guess = std::numeric_limits<float>::max();
162  if (best_energy > 0.) {
163  best_time_guess = timehits.find(best_hit)->time();
164  }
165 
166  //std::cout << "EcalBarrelFastTimer: " << best_time_guess << ' ' << best_energy << ' ' << best_hit << std::endl;
167 
168  return std::make_pair(best_time_guess, DetId(best_hit));
169 }
170 
172  const DetId& timeDet,
173  const reco::Vertex& vtx,
174  const CaloSubdetectorGeometry* ecalGeom) const {
175  if (timeDet.rawId() == 0)
176  return -999.;
177  // correct the cluster time from 0,0,0 to the primary vertex given
178  auto cellGeometry = ecalGeom->getGeometry(timeDet);
179  if (nullptr == cellGeometry) {
180  throw cms::Exception("BadECALBarrelCell")
181  << std::hex << timeDet.rawId() << std::dec << " is not a valid ECAL Barrel DetId!";
182  }
183  //depth in mm in the middle of the layer position;
184  GlobalPoint layerPos = cellGeometry->getPosition(ecalDepth_ + 0.5);
185  const math::XYZPoint layerPos_cm(layerPos.x(), layerPos.y(), layerPos.z());
186  const math::XYZVector to_center = layerPos_cm - math::XYZPoint(0., 0., 0.);
187  const math::XYZVector to_vtx = layerPos_cm - vtx.position();
188 
189  /*
190  std::cout << intime << ' ' << to_center.r()/cm_per_ns << ' ' << to_vtx.r()/cm_per_ns
191  << ' ' << intime + to_center.r()/cm_per_ns - to_vtx.r()/cm_per_ns << std::endl;
192  */
193 
194  return intime + to_center.r() / cm_per_ns - to_vtx.r() / cm_per_ns;
195 }
EcalBarrelClusterFastTimer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: EcalBarrelClusterFastTimer.cc:96
edm::StreamID
Definition: StreamID.h:30
mps_fire.i
i
Definition: mps_fire.py:355
EcalBarrelClusterFastTimer::minEnergy_
const float minEnergy_
Definition: EcalBarrelClusterFastTimer.cc:48
MessageLogger.h
ESHandle.h
ResolutionModel.h
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
patZpeak.handle
handle
Definition: patZpeak.py:23
edm::EDGetTokenT
Definition: EDGetToken.h:33
EcalBarrelClusterFastTimer::ebClustersToken_
edm::EDGetTokenT< std::vector< reco::PFCluster > > ebClustersToken_
Definition: EcalBarrelClusterFastTimer.cc:45
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::PFCluster::recHitFractions
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
Definition: PFCluster.h:69
edm::SortedCollection< EcalRecHit >
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
edm::EventID::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:39
edm::Handle
Definition: AssociativeIterator.h:50
dqmdumpme.first
first
Definition: dqmdumpme.py:55
EcalRecHitCollections.h
EcalBarrelClusterFastTimer::minFraction_
const float minFraction_
Definition: EcalBarrelClusterFastTimer.cc:48
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
DetId
Definition: DetId.h:17
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
TruncatedPyramid.h
PFCluster.h
L1TObjectsTimingClient_cff.resolution
resolution
Definition: L1TObjectsTimingClient_cff.py:52
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
EcalBarrelClusterFastTimer
Definition: EcalBarrelClusterFastTimer.cc:35
Point3DBase< float, GlobalTag >
edm::EventID::run
RunNumber_t run() const
Definition: EventID.h:38
edm::global::EDProducer
Definition: EDProducer.h:32
CaloGeometryRecord.h
badGlobalMuonTaggersAOD_cff.vtx
vtx
Definition: badGlobalMuonTaggersAOD_cff.py:5
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
EcalSubdetector.h
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
EcalBarrelClusterFastTimer::ebTimeHitsToken_
edm::EDGetTokenT< EcalRecHitCollection > ebTimeHitsToken_
Definition: EcalBarrelClusterFastTimer.cc:44
CaloSubdetectorGeometry.h
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Event.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
EcalBarrelClusterFastTimer::_resolutions
std::vector< std::unique_ptr< const ResolutionModel > > _resolutions
Definition: EcalBarrelClusterFastTimer.cc:47
math::XYZVector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
edm::EventID::event
EventNumber_t event() const
Definition: EventID.h:40
iEvent
int iEvent
Definition: GenABIO.cc:224
CaloSubdetectorGeometry::getGeometry
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
Definition: CaloSubdetectorGeometry.cc:36
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
ValueMap.h
VertexFwd.h
EcalBarrelClusterFastTimer::ecalDepth_
const unsigned ecalDepth_
Definition: EcalBarrelClusterFastTimer.cc:49
electronProducer_cfi.resolutions
resolutions
Definition: electronProducer_cfi.py:80
edm::SortedCollection::find
iterator find(key_type k)
Definition: SortedCollection.h:240
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
isFinite.h
Frameworkfwd.h
EcalBarrelClusterFastTimer::getTimeForECALPFCluster
std::pair< float, DetId > getTimeForECALPFCluster(const EcalRecHitCollection &, const reco::PFCluster &) const
Definition: EcalBarrelClusterFastTimer.cc:141
Exception
Definition: hltDiff.cc:246
CaloGeometry.h
edm::EventBase::id
edm::EventID id() const
Definition: EventBase.h:59
reco::PFCluster
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:46
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
CaloSubdetectorGeometry
Definition: CaloSubdetectorGeometry.h:22
EcalBarrelClusterFastTimer::EcalBarrelClusterFastTimer
EcalBarrelClusterFastTimer(const edm::ParameterSet &)
Definition: EcalBarrelClusterFastTimer.cc:78
edm::ParameterSet::getParameterSetVector
VParameterSet const & getParameterSetVector(std::string const &name) const
Definition: ParameterSet.cc:2153
edm::helper::Filler
Definition: ValueMap.h:22
View.h
EDProducer.h
edm::Event
Definition: Event.h:73
EcalBarrelClusterFastTimer::correctTimeToVertex
float correctTimeToVertex(const float intime, const DetId &timeDet, const reco::Vertex &vtx, const CaloSubdetectorGeometry *ecalGeom) const
Definition: EcalBarrelClusterFastTimer.cc:171
HLT_2018_cff.fraction
fraction
Definition: HLT_2018_cff.py:51317
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
label
const char * label
Definition: PFTauDecayModeTools.cc:11
reco::Vertex
Definition: Vertex.h:35
SurveyInfoScenario_cff.seed
seed
Definition: SurveyInfoScenario_cff.py:295
EcalBarrelClusterFastTimer::~EcalBarrelClusterFastTimer
~EcalBarrelClusterFastTimer() override
Definition: EcalBarrelClusterFastTimer.cc:38