CMS 3D CMS Logo

FWCaloClusterProxyBuilder.cc
Go to the documentation of this file.
7 
8 #include "TEveBoxSet.h"
9 #include "TEveStraightLineSet.h"
10 
11 class FWCaloClusterProxyBuilder : public FWHeatmapProxyBuilderTemplate<reco::CaloCluster> {
12 public:
14  ~FWCaloClusterProxyBuilder(void) override {}
15 
17 
18 private:
21  long layer;
23  bool heatmap;
24  bool z_plus;
25  bool z_minus;
27 
28  FWCaloClusterProxyBuilder(const FWCaloClusterProxyBuilder &) = delete; // stop default
29  const FWCaloClusterProxyBuilder &operator=(const FWCaloClusterProxyBuilder &) = delete; // stop default
30 
31  void setItem(const FWEventItem *iItem) override;
32 
33  void build(const FWEventItem *iItem, TEveElementList *product, const FWViewContext *vc) override;
34  void build(const reco::CaloCluster &iData,
35  unsigned int iIndex,
36  TEveElement &oItemHolder,
37  const FWViewContext *) override;
38 };
39 
42  if (iItem) {
43  iItem->getConfig()->assertParam("Cluster(0)/RecHit(1)", false);
44  iItem->getConfig()->assertParam("EnableTimeFilter", false);
45  iItem->getConfig()->assertParam("TimeLowerBound(ns)", 0.01, 0.0, 75.0);
46  iItem->getConfig()->assertParam("TimeUpperBound(ns)", 0.01, 0.0, 75.0);
47  }
48 }
49 
50 void FWCaloClusterProxyBuilder::build(const FWEventItem *iItem, TEveElementList *product, const FWViewContext *vc) {
51  iItem->getEvent()->getByLabel(edm::InputTag("hgcalLayerClusters", "timeLayerCluster"), TimeValueMapHandle);
53  timeLowerBound = std::min(item()->getConfig()->value<double>("TimeLowerBound(ns)"),
54  item()->getConfig()->value<double>("TimeUpperBound(ns)"));
55  timeUpperBound = std::max(item()->getConfig()->value<double>("TimeLowerBound(ns)"),
56  item()->getConfig()->value<double>("TimeUpperBound(ns)"));
57  } else {
58  std::cerr << "Warning: couldn't locate 'timeLayerCluster' ValueMap in root file." << std::endl;
59  }
60 
61  layer = item()->getConfig()->value<long>("Layer");
62  saturation_energy = item()->getConfig()->value<double>("EnergyCutOff");
63  heatmap = item()->getConfig()->value<bool>("Heatmap");
64  z_plus = item()->getConfig()->value<bool>("Z+");
65  z_minus = item()->getConfig()->value<bool>("Z-");
66  enableTimeFilter = item()->getConfig()->value<bool>("EnableTimeFilter");
67 
68  FWHeatmapProxyBuilderTemplate::build(iItem, product, vc);
69 }
70 
72  unsigned int iIndex,
73  TEveElement &oItemHolder,
74  const FWViewContext *) {
76  const float time = TimeValueMapHandle->get(iIndex);
77  if (time < timeLowerBound || time > timeUpperBound)
78  return;
79  }
80 
81  std::vector<std::pair<DetId, float>> clusterDetIds = iData.hitsAndFractions();
82 
83  bool h_hex(false);
84  TEveBoxSet *hex_boxset = new TEveBoxSet();
85  if (!heatmap)
86  hex_boxset->UseSingleColor();
87  hex_boxset->SetPickable(true);
88  hex_boxset->Reset(TEveBoxSet::kBT_Hex, true, 64);
89  hex_boxset->SetAntiFlick(true);
90 
91  bool h_box(false);
92  TEveBoxSet *boxset = new TEveBoxSet();
93  if (!heatmap)
94  boxset->UseSingleColor();
95  boxset->SetPickable(true);
96  boxset->Reset(TEveBoxSet::kBT_FreeBox, true, 64);
97  boxset->SetAntiFlick(true);
98 
99  for (std::vector<std::pair<DetId, float>>::iterator it = clusterDetIds.begin(), itEnd = clusterDetIds.end();
100  it != itEnd;
101  ++it) {
102  const uint8_t type = ((it->first >> 28) & 0xF);
103 
104  const float *corners = item()->getGeom()->getCorners(it->first);
105  if (corners == nullptr)
106  continue;
107 
108  // HGCal
109  if (iData.algo() == 8 || (type >= 8 && type <= 10)) {
110  if (heatmap && hitmap.find(it->first) == hitmap.end())
111  continue;
112 
113  const bool z = (it->first >> 25) & 0x1;
114 
115  // discard everything thats not at the side that we are intersted in
116  if (((z_plus & z_minus) != 1) && (((z_plus | z_minus) == 0) || !(z == z_minus || z == !z_plus)))
117  continue;
118 
119  const float *parameters = item()->getGeom()->getParameters(it->first);
120  const float *shapes = item()->getGeom()->getShapePars(it->first);
121 
122  if (parameters == nullptr || shapes == nullptr)
123  continue;
124 
125  const int total_points = parameters[0];
126  const bool isScintillator = (total_points == 4);
127 
128  uint8_t ll = layer;
129  if (layer > 0) {
130  if (layer > 28) {
131  if (type == 8) {
132  continue;
133  }
134  ll -= 28;
135  } else {
136  if (type != 8) {
137  continue;
138  }
139  }
140 
141  if (ll != ((it->first >> (isScintillator ? 17 : 20)) & 0x1F))
142  continue;
143  }
144 
145  // seed
146  if (iData.seed().rawId() == it->first.rawId()) {
147  TEveStraightLineSet *marker = new TEveStraightLineSet;
148  marker->SetLineWidth(1);
149 
150  // center of RecHit
151  const float center[3] = {corners[total_points * 3 + 0],
152  corners[total_points * 3 + 1],
153  corners[total_points * 3 + 2] + shapes[3] * 0.5f};
154 
155  // draw 3D cross
156  const float crossScale = 1.0f + fmin(iData.energy(), 5.0f);
157  marker->AddLine(center[0] - crossScale, center[1], center[2], center[0] + crossScale, center[1], center[2]);
158  marker->AddLine(center[0], center[1] - crossScale, center[2], center[0], center[1] + crossScale, center[2]);
159  marker->AddLine(center[0], center[1], center[2] - crossScale, center[0], center[1], center[2] + crossScale);
160 
161  oItemHolder.AddElement(marker);
162  }
163 
164  const float energy = fmin(
165  (item()->getConfig()->value<bool>("Cluster(0)/RecHit(1)") ? hitmap[it->first]->energy() : iData.energy()) /
167  1.0f);
168  const uint8_t colorFactor = gradient_steps * energy;
169 
170  // Scintillator
171  if (isScintillator) {
172  const int total_vertices = 3 * total_points;
173 
174  std::vector<float> pnts(24);
175  for (int i = 0; i < total_points; ++i) {
176  pnts[i * 3 + 0] = corners[i * 3];
177  pnts[i * 3 + 1] = corners[i * 3 + 1];
178  pnts[i * 3 + 2] = corners[i * 3 + 2];
179 
180  pnts[(i * 3 + 0) + total_vertices] = corners[i * 3];
181  pnts[(i * 3 + 1) + total_vertices] = corners[i * 3 + 1];
182  pnts[(i * 3 + 2) + total_vertices] = corners[i * 3 + 2] + shapes[3];
183  }
184  boxset->AddBox(&pnts[0]);
185  if (heatmap) {
186  energy ? boxset->DigitColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor])
187  : boxset->DigitColor(64, 64, 64);
188  }
189 
190  h_box = true;
191  }
192  // Silicon
193  else {
194  constexpr int offset = 9;
195 
196  float centerX = (corners[6] + corners[6 + offset]) / 2;
197  float centerY = (corners[7] + corners[7 + offset]) / 2;
198  float radius = fabs(corners[6] - corners[6 + offset]) / 2;
199  hex_boxset->AddHex(TEveVector(centerX, centerY, corners[2]), radius, 90.0, shapes[3]);
200  if (heatmap) {
201  energy ? hex_boxset->DigitColor(gradient[0][colorFactor], gradient[1][colorFactor], gradient[2][colorFactor])
202  : hex_boxset->DigitColor(64, 64, 64);
203  }
204 
205  h_hex = true;
206  }
207  }
208  // Not HGCal
209  else {
210  h_box = true;
211 
212  std::vector<float> pnts(24);
213  fireworks::energyTower3DCorners(corners, (*it).second, pnts);
214  boxset->AddBox(&pnts[0]);
215  }
216  }
217 
218  if (h_hex) {
219  hex_boxset->RefitPlex();
220 
221  hex_boxset->CSCTakeAnyParentAsMaster();
222  if (!heatmap) {
223  hex_boxset->CSCApplyMainColorToMatchingChildren();
224  hex_boxset->CSCApplyMainTransparencyToMatchingChildren();
225  hex_boxset->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
226  hex_boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
227  }
228  oItemHolder.AddElement(hex_boxset);
229  }
230 
231  if (h_box) {
232  boxset->RefitPlex();
233 
234  boxset->CSCTakeAnyParentAsMaster();
235  if (!heatmap) {
236  boxset->CSCApplyMainColorToMatchingChildren();
237  boxset->CSCApplyMainTransparencyToMatchingChildren();
238  boxset->SetMainColor(item()->modelInfo(iIndex).displayProperties().color());
239  boxset->SetMainTransparency(item()->defaultDisplayProperties().transparency());
240  }
241  oItemHolder.AddElement(boxset);
242  }
243 }
244 
FWCaloClusterProxyBuilder::timeUpperBound
double timeUpperBound
Definition: FWCaloClusterProxyBuilder.cc:20
FWCaloClusterProxyBuilder::timeLowerBound
double timeLowerBound
Definition: FWCaloClusterProxyBuilder.cc:20
mps_fire.i
i
Definition: mps_fire.py:355
FWHeatmapProxyBuilderTemplate::setItem
void setItem(const FWEventItem *iItem) override
Definition: FWHeatmapProxyBuilderTemplate.h:82
FWGeometry::getCorners
const float * getCorners(unsigned int id) const
Definition: FWGeometry.cc:464
edm::EventBase::getByLabel
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:92
FWEventItem::getConfig
FWProxyBuilderConfiguration * getConfig() const
Definition: FWEventItem.h:150
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
FWHeatmapProxyBuilderTemplate< reco::CaloCluster >::gradient_steps
static constexpr uint8_t gradient_steps
Definition: FWHeatmapProxyBuilderTemplate.h:49
FWHeatmapProxyBuilderTemplate< reco::CaloCluster >::hitmap
std::map< DetId, const HGCRecHit * > hitmap
Definition: FWHeatmapProxyBuilderTemplate.h:47
min
T min(T a, T b)
Definition: MathUtil.h:58
REGISTER_FWPROXYBUILDER
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
Definition: FWProxyBuilderFactory.h:33
FWCaloClusterProxyBuilder::saturation_energy
double saturation_energy
Definition: FWCaloClusterProxyBuilder.cc:22
FWCaloClusterProxyBuilder::~FWCaloClusterProxyBuilder
~FWCaloClusterProxyBuilder(void) override
Definition: FWCaloClusterProxyBuilder.cc:14
REGISTER_PROXYBUILDER_METHODS
#define REGISTER_PROXYBUILDER_METHODS()
Definition: register_dataproxybuilder_macro.h:28
FWGeometry::getShapePars
const float * getShapePars(unsigned int id) const
Definition: FWGeometry.cc:486
BuilderUtils.h
FWCaloClusterProxyBuilder::z_minus
bool z_minus
Definition: FWCaloClusterProxyBuilder.cc:25
edm::Handle
Definition: AssociativeIterator.h:50
FWCaloClusterProxyBuilder::layer
long layer
Definition: FWCaloClusterProxyBuilder.cc:21
parameters
parameters
Definition: BeamSpot_PayloadInspector.cc:14
FWGeometry::getParameters
const float * getParameters(unsigned int id) const
Definition: FWGeometry.cc:475
FWProxyBuilderBase::layer
int layer() const
Definition: FWProxyBuilderBase.cc:414
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
reco::CaloCluster
Definition: CaloCluster.h:31
DDAxes::z
fireworks::energyTower3DCorners
void energyTower3DCorners(const float *corners, float scale, std::vector< float > &, bool reflect=false)
Definition: BuilderUtils.cc:286
CaloClusterFwd.h
FWCaloClusterProxyBuilder
Definition: FWCaloClusterProxyBuilder.cc:11
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
FWProxyBuilderConfiguration::assertParam
FWGenericParameter< T > * assertParam(const std::string &name, T def)
Definition: FWProxyBuilderConfiguration.cc:83
FWEventItem::getEvent
const edm::EventBase * getEvent() const
Definition: FWEventItem.h:131
FWHeatmapProxyBuilderTemplate< reco::CaloCluster >::gradient
static constexpr uint8_t gradient[3][gradient_steps]
Definition: FWHeatmapProxyBuilderTemplate.h:50
FWGeometry.h
FWCaloClusterProxyBuilder::heatmap
bool heatmap
Definition: FWCaloClusterProxyBuilder.cc:23
reco::CaloCluster::hitsAndFractions
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:210
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
FWCaloClusterProxyBuilder::enableTimeFilter
bool enableTimeFilter
Definition: FWCaloClusterProxyBuilder.cc:26
beam_dqm_sourceclient-live_cfg.cerr
cerr
Definition: beam_dqm_sourceclient-live_cfg.py:17
FWCaloClusterProxyBuilder::operator=
const FWCaloClusterProxyBuilder & operator=(const FWCaloClusterProxyBuilder &)=delete
FWProxyBuilderBase::build
void build()
Definition: FWProxyBuilderBase.cc:110
reco::CaloCluster::seed
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:219
FWEventItem.h
FWViewContext
Definition: FWViewContext.h:32
ValueMap.h
FWCaloClusterProxyBuilder::setItem
void setItem(const FWEventItem *iItem) override
Definition: FWCaloClusterProxyBuilder.cc:40
FWEventItem::getGeom
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:548
FWProxyBuilderBase::item
const FWEventItem * item() const
Definition: FWProxyBuilderBase.h:64
edm::ValueMap::get
const_reference_type get(ProductID id, size_t idx) const
Definition: ValueMap.h:144
FWHeatmapProxyBuilderTemplate
Definition: FWHeatmapProxyBuilderTemplate.h:34
FWEventItem
Definition: FWEventItem.h:56
type
type
Definition: HCALResponse.h:21
FWViewType::kISpyBit
Definition: FWViewType.h:54
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
FWProxyBuilderConfiguration::value
T value(const std::string &name)
Definition: FWProxyBuilderConfiguration.cc:123
reco::CaloCluster::algo
AlgoId algo() const
algorithm identifier
Definition: CaloCluster.h:190
CosmicsPD_Skims.radius
radius
Definition: CosmicsPD_Skims.py:135
FWCaloClusterProxyBuilder::TimeValueMapHandle
edm::Handle< edm::ValueMap< float > > TimeValueMapHandle
Definition: FWCaloClusterProxyBuilder.cc:19
FWHeatmapProxyBuilderTemplate.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
ntuplemaker.time
time
Definition: ntuplemaker.py:310
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
FWCaloClusterProxyBuilder::FWCaloClusterProxyBuilder
FWCaloClusterProxyBuilder(void)
Definition: FWCaloClusterProxyBuilder.cc:13
reco::CaloCluster::energy
double energy() const
cluster energy
Definition: CaloCluster.h:149
FWCaloClusterProxyBuilder::z_plus
bool z_plus
Definition: FWCaloClusterProxyBuilder.cc:24
edm::InputTag
Definition: InputTag.h:15