forked from osschar/OssTests
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFWTracksterLayersProxyBuilder.cc
More file actions
276 lines (240 loc) · 11.7 KB
/
Copy pathFWTracksterLayersProxyBuilder.cc
File metadata and controls
276 lines (240 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#include "FireworksWeb/Core/interface/FWProxyBuilderFactory.h"
#include "FireworksWeb/Calo/interface/FWHeatmapProxyBuilderTemplate.h"
#include "ROOT/REvePointSet.hxx"
#include "ROOT/REveViewContext.hxx"
#include "ROOT/REveStraightLineSet.hxx"
#include "ROOT/REveGeoShape.hxx"
#include "TGeoTube.h"
#include "FireworksWeb/Core/interface/FWGeometry.h"
#include "FireworksWeb/Core/interface/fwLog.h"
#include "FireworksWeb/Core/interface/Context.h"
#include "FireworksWeb/Core/interface/BuilderUtils.h"
#include "FireworksWeb/Core/interface/fwLog.h"
#include "DataFormats/HGCalReco/interface/Trackster.h"
#include "DataFormats/CaloRecHit/interface/CaloCluster.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/ForwardDetId/interface/HGCScintillatorDetId.h"
#include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
#include "DataFormats/FWLite/interface/Event.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
using namespace ROOT::Experimental;
class FWTracksterLayersProxyBuilder : public FWHeatmapProxyBuilderTemplate<ticl::Trackster>
{
public:
REGISTER_FWPB_METHODS();
using FWHeatmapProxyBuilderTemplate::SetCollection;
void SetCollection(REveDataCollection* c) override {
auto item = dynamic_cast<FWWebEventItem *>(c);
item->getConfig()->assertParam("EnablePositionLines", false);
item->getConfig()->assertParam("EnableEdges", false);
item->getConfig()->assertParam("EnableTimeFilter", false);
item->getConfig()->assertParam("TimeLowerBound(ns)", 0.01, 0.0, 75.0);
item->getConfig()->assertParam("TimeUpperBound(ns)", 0.01, 0.0, 75.0);
item->getConfig()->assertParam("DisplayMode", 0L, 0L, 4L);
item->getConfig()->assertParam("ProportionalityFactor", 1.0, 0.0, 1.0);
FWHeatmapProxyBuilderTemplate::SetCollection(c);
}
using FWHeatmapProxyBuilderTemplate<ticl::Trackster>::Build;
void Build() override;
using FWHeatmapProxyBuilderTemplate<ticl::Trackster>::BuildItem;
virtual void BuildItem(const ticl::Trackster &iData, int idx, ROOT::Experimental::REveElement *iItemHolder, const ROOT::Experimental::REveViewContext *context) override;
private:
edm::Handle<edm::ValueMap<std::pair<float, float>>> TimeValueMapHandle_;
edm::Handle<std::vector<reco::CaloCluster>> layerClustersHandle_;
double timeLowerBound_, timeUpperBound_;
long layer_;
double saturation_energy_;
bool heatmap_;
bool z_plus_;
bool z_minus_;
bool enableTimeFilter_;
bool enablePositionLines_;
bool enableEdges_;
long displayMode_;
double proportionalityFactor_;
};
//------------------------------------------------------------
void FWTracksterLayersProxyBuilder::Build() {
auto fwitem = dynamic_cast<FWWebEventItem*>(Collection());
auto event = fireworks::Context::getInstance()->getCurrentEvent();
event->getByLabel(edm::InputTag("hgcalLayerClusters", "timeLayerCluster"), TimeValueMapHandle_);
event->getByLabel(edm::InputTag("hgcalLayerClusters"), layerClustersHandle_);
if (TimeValueMapHandle_.isValid()) {
timeLowerBound_ = fwitem->getConfig()->value<double>("TimeLowerBound(ns)");
timeUpperBound_ = fwitem->getConfig()->value<double>("TimeUpperBound(ns)");
if (timeLowerBound_ > timeUpperBound_) {
edm::LogWarning("InvalidParameters")
<< "lower time bound is larger than upper time bound. Maybe opposite is desired?";
}
} else {
event->getByLabel(edm::InputTag("hgcalMergeLayerClusters", "timeLayerCluster"), TimeValueMapHandle_);
edm::LogWarning("DataNotFound|InvalidData")
<< __FILE__ << ":" << __LINE__
<< " couldn't locate 'hgcalLayerClusters:timeLayerCluster' ValueMap in input file. Trying to access "
"'hgcalMergeLayerClusters:timeLayerClusters' ValueMap";
if (!TimeValueMapHandle_.isValid()) {
edm::LogWarning("DataNotFound|InvalidData")
<< __FILE__ << ":" << __LINE__
<< " couldn't locate 'hgcalMergeLayerClusters:timeLayerCluster' ValueMap in input file.";
}
}
if (!layerClustersHandle_.isValid()) {
event->getByLabel(edm::InputTag("hgcalMergeLayerClusters"), layerClustersHandle_);
edm::LogWarning("DataNotFound|InvalidData")
<< __FILE__ << ":" << __LINE__
<< " couldn't locate 'hgcalLayerClusters' collection "
"in input file. Trying to access 'hgcalMergeLayerClusters' collection.";
if (!layerClustersHandle_.isValid()) {
edm::LogWarning("DataNotFound|InvalidData")
<< __FILE__ << ":" << __LINE__ << " couldn't locate 'hgcalMergeLayerClusters' collection in input file.";
}
}
layer_ = fwitem->getConfig()->value<long>("Layer");
saturation_energy_ = fwitem->getConfig()->value<double>("EnergyCutOff");
heatmap_ = fwitem->getConfig()->value<bool>("Heatmap");
z_plus_ = fwitem->getConfig()->value<bool>("Z+");
z_minus_ = fwitem->getConfig()->value<bool>("Z-");
enableTimeFilter_ = fwitem->getConfig()->value<bool>("EnableTimeFilter");
enablePositionLines_ = fwitem->getConfig()->value<bool>("EnablePositionLines");
enableEdges_ = fwitem->getConfig()->value<bool>("EnableEdges");
displayMode_ = fwitem->getConfig()->value<long>("DisplayMode");
proportionalityFactor_ = fwitem->getConfig()->value<double>("ProportionalityFactor");
FWHeatmapProxyBuilderTemplate::Build();
}
//------------------------------------------------------------
void FWTracksterLayersProxyBuilder::BuildItem(const ticl::Trackster &iData,
int idx, ROOT::Experimental::REveElement *oItemHolder,
const ROOT::Experimental::REveViewContext *context)
{
if (enableTimeFilter_ && TimeValueMapHandle_.isValid()) {
const float time = TimeValueMapHandle_->get(idx).first;
if (time < timeLowerBound_ || time > timeUpperBound_)
return;
}
auto geom = fireworks::Context::getInstance()->getGeom();
const ticl::Trackster &trackster = iData;
const size_t N = trackster.vertices().size();
const std::vector<reco::CaloCluster> &layerClusters = *layerClustersHandle_;
REveStraightLineSet *position_marker = nullptr;
if (enablePositionLines_) {
position_marker = new REveStraightLineSet;
position_marker->SetLineWidth(2);
position_marker->SetLineColor(kWhite);
}
for (size_t i = 0; i < N; ++i) {
const reco::CaloCluster layerCluster = layerClusters[trackster.vertices(i)];
const math::XYZPoint &position = layerCluster.position();
const size_t nHits = layerCluster.size();
const double energy = layerCluster.energy();
float radius = 0;
auto detIdOnLayer = layerCluster.seed();
const auto *parameters = geom->getParameters(detIdOnLayer);
const int layer = parameters[1];
const int zside = parameters[2];
bool isSilicon = parameters[3];
const int total_points = parameters[0];
if (isSilicon && total_points == 4) {
fwLog(fwlog::kDebug) << "FWTracksterHitsProxyBuilder::BuildItem isSilicon "<< isSilicon << " N points " << total_points << "\n";
isSilicon = false;
}
auto const z_selection_is_on = z_plus_ ^ z_minus_;
auto const z_plus_selection_ok = z_plus_ && (zside == 1);
auto const z_minus_selection_ok = z_minus_ && (zside == -1);
if (!z_minus_ && !z_plus_)
continue;
if (z_selection_is_on && !(z_plus_selection_ok || z_minus_selection_ok))
continue;
if (layer_ > 0 && (layer != layer_))
continue;
if (displayMode_ == 0) {
radius = sqrt(nHits);
} else if (displayMode_ == 1) {
radius = nHits;
} else if (displayMode_ == 2) {
radius = energy;
} else if (displayMode_ == 3) {
radius = energy / nHits;
} else if (displayMode_ == 4) {
float area = 0;
if (!isSilicon) {
const bool isFine = (HGCScintillatorDetId(layerCluster.seed()).type() == 0);
float dphi = (isFine) ? 1.0 * M_PI / 180. : 1.25 * M_PI / 180.;
int ir = HGCScintillatorDetId(layerCluster.seed()).iradiusAbs();
float dr = (isFine) ? (0.0484 * static_cast<float>(ir) + 2.1) : (0.075 * static_cast<float>(ir) + 2.0);
float r = (isFine) ? (0.0239 * static_cast<float>(pow(ir, 2)) + 2.02 * static_cast<float>(ir) + 119.6)
: (0.0367 * static_cast<float>(pow(ir, 2)) + 1.7 * static_cast<float>(ir) + 90.7);
area = r * dr * dphi;
} else {
const bool isFine = (HGCSiliconDetId(layerCluster.seed()).type() == 0);
float side = (isFine) ? 0.465 : 0.698;
area = pow(side, 2) * 3 * sqrt(3) / 2;
}
radius = sqrt(nHits * area) / M_PI;
}
auto *eveCircle = new REveGeoShape("Circle");
auto tube = new TGeoTube(0., proportionalityFactor_ * radius, 0.1);
eveCircle->SetShape(tube);
eveCircle->InitMainTrans();
eveCircle->RefMainTrans().Move3PF(position.x(), position.y(), position.z());
SetupAddElement(eveCircle, oItemHolder);
// Apply heatmap color coding **after** the call to setupAddElement, that will internally setup the color.
if (heatmap_) {
const float normalized_energy = fmin(energy / saturation_energy_, 1.0f);
const uint8_t colorFactor = FWHGCAL_GRADIENT_STEPS * normalized_energy;
eveCircle->SetFillColor(
TColor::GetColor(fwhgcal::gradient[0][colorFactor], fwhgcal::gradient[1][colorFactor], fwhgcal::gradient[2][colorFactor]));
} else {
Color_t itemColor = Collection()->GetDataItem(idx)->GetMainColor();
eveCircle->SetMainColor(itemColor);
eveCircle->SetMainTransparency(Collection()->GetMainTransparency());
}
// seed and cluster position
const float crossScale = 1.0f + fmin(energy, 5.0f);
if (enablePositionLines_) {
auto const &pos = layerCluster.position();
const float position_crossScale = crossScale * 0.5;
position_marker->AddLine(
pos.x() - position_crossScale, pos.y(), pos.z(), pos.x() + position_crossScale, pos.y(), pos.z());
position_marker->AddLine(
pos.x(), pos.y() - position_crossScale, pos.z(), pos.x(), pos.y() + position_crossScale, pos.z());
}
}
if (enablePositionLines_)
oItemHolder->AddElement(position_marker);
if (enableEdges_) {
auto &edges = trackster.edges();
REveStraightLineSet *adjacent_marker = new REveStraightLineSet;
adjacent_marker->SetLineWidth(2);
adjacent_marker->SetLineColor(kYellow);
REveStraightLineSet *non_adjacent_marker = new REveStraightLineSet;
non_adjacent_marker->SetLineWidth(2);
non_adjacent_marker->SetLineColor(kRed);
for (auto edge : edges) {
auto doublet = std::make_pair(layerClusters[edge[0]], layerClusters[edge[1]]);
int layerIn = geom->getParameters(doublet.first.seed())[1];
int layerOut = geom->getParameters(doublet.second.seed())[1];
const bool isAdjacent = std::abs(layerOut - layerIn) == 1;
// draw 3D cross
if (layer_ == 0 || fabs(layerIn - layer_) == 0 || fabs(layerOut - layer_) == 0) {
if (isAdjacent)
adjacent_marker->AddLine(doublet.first.x(),
doublet.first.y(),
doublet.first.z(),
doublet.second.x(),
doublet.second.y(),
doublet.second.z());
else
non_adjacent_marker->AddLine(doublet.first.x(),
doublet.first.y(),
doublet.first.z(),
doublet.second.x(),
doublet.second.y(),
doublet.second.z());
}
}
SetupAddElement(adjacent_marker, oItemHolder);
SetupAddElement(non_adjacent_marker, oItemHolder);
}
}
REGISTER_FW2PROXYBUILDER(FWTracksterLayersProxyBuilder, ticl::Trackster, "Trackster layers");