1 #include "TEveBoxSet.h"
3 #include "TEveTrackPropagator.h"
4 #include "TEveCompound.h"
5 #include "TEveStraightLineSet.h"
6 #include "TEveProjectionBases.h"
24 const std::string cname(
"particleFlowRecHitHCALUpgrade");
26 void addLineToLineSet(TEveStraightLineSet*
ls,
const float*
p,
int i1,
int i2) {
29 ls->AddLine(p[i1], p[i1 + 1], p[i1 + 2], p[i2], p[i2 + 1], p[i2 + 2]);
32 void addBoxAsLines(TEveStraightLineSet* lineset,
const float* p) {
33 for (
int l = 0;
l < 5;
l += 4) {
34 addLineToLineSet(lineset, p, 0 +
l, 1 +
l);
35 addLineToLineSet(lineset, p, 1 +
l, 2 +
l);
36 addLineToLineSet(lineset, p, 2 +
l, 3 +
l);
37 addLineToLineSet(lineset, p, 3 +
l, 0 +
l);
39 for (
int l = 0;
l < 4; ++
l)
40 addLineToLineSet(lineset, p, 0 +
l, 4 +
l);
43 void editLineInLineSet(TEveChunkManager::iterator& li,
const float* p,
int i1,
int i2) {
44 TEveStraightLineSet::Line_t&
line = *(TEveStraightLineSet::Line_t*)li();
47 for (
int i = 0;
i < 3; ++
i) {
48 line.fV1[0 +
i] = p[i1 +
i];
49 line.fV2[0 +
i] = p[i2 +
i];
55 void editBoxInLineSet(TEveChunkManager::iterator& li,
const float* p) {
56 for (
int i = 0;
i < 5;
i += 4) {
57 editLineInLineSet(li, p, 0 +
i, 1 +
i);
59 editLineInLineSet(li, p, 1 +
i, 2 +
i);
60 editLineInLineSet(li, p, 2 +
i, 3 +
i);
61 editLineInLineSet(li, p, 3 +
i, 0 +
i);
63 for (
int i = 0;
i < 4; ++
i)
64 editLineInLineSet(li, p, 0 +
i, 4 +
i);
70 TEveElementList* product,
74 iItem->
get(candidates);
75 if (candidates ==
nullptr)
80 for (reco::PFCandidateCollection::const_iterator it = candidates->begin(), itEnd = candidates->end(); it != itEnd;
92 t.fP = TEveVector(cand.
px(), cand.
py(), cand.
pz());
95 TEveTrack* trk =
new TEveTrack(&t,
context().getTrackPropagator());
122 <<
": Failed to access collection with name " << cname <<
"." << std::endl;
126 <<
": Failed to access collection with name " << cname <<
"." << std::endl;
132 const float* corners,
float scale,
bool plotEt, std::vector<float>& scaledCorners,
const reco::PFRecHit*) {
133 static TEveVector vtmp;
134 vtmp.Set(0.
f, 0.
f, 0.
f);
135 for (
unsigned int i = 0;
i < 24;
i += 3) {
136 vtmp[0] += corners[
i];
137 vtmp[1] += corners[
i + 1];
138 vtmp[2] += corners[
i + 2];
143 scale *= vtmp.Perp() / vtmp.Mag();
147 for (
unsigned int i = 0;
i < 24;
i += 3) {
148 scaledCorners[
i] = vtmp[0] + (corners[
i] - vtmp[0]) * scale;
149 scaledCorners[
i + 1] = vtmp[1] + (corners[
i + 1] - vtmp[1]) * scale;
150 scaledCorners[
i + 2] = vtmp[2] + (corners[
i + 2] - vtmp[2]) * scale;
157 if (it->detId() == candIdx) {
168 std::vector<float> scaledCorners(24);
171 for (TEveElement::List_i
i = parent->BeginChildren();
i != parent->EndChildren(); ++
i) {
172 if ((*i)->NumChildren() > 1) {
173 TEveElement::List_i xx = (*i)->BeginChildren();
175 TEveBoxSet* boxset =
dynamic_cast<TEveBoxSet*
>(*xx);
177 TEveStraightLineSet* lineset =
dynamic_cast<TEveStraightLineSet*
>(*xx);
178 TEveChunkManager::iterator li(lineset->GetLinePlex());
181 TEveChunkManager* plex = boxset->GetPlex();
183 for (
int atomIdx = 0; atomIdx < plex->Size(); ++atomIdx) {
184 TEveBoxSet::BFreeBox_t* atom = (TEveBoxSet::BFreeBox_t*)boxset->GetPlex()->Atom(atomIdx);
188 memcpy(atom->fVertices, &scaledCorners[0],
sizeof(atom->fVertices));
190 editBoxInLineSet(li, &scaledCorners[0]);
193 for (TEveProjectable::ProjList_i p = lineset->BeginProjecteds(); p != lineset->EndProjecteds(); ++
p) {
194 TEveStraightLineSetProjected* projLineSet = (TEveStraightLineSetProjected*)(*p);
195 projLineSet->UpdateProjection();
203 TString boxset_tooltip_callback(TEveDigitSet* ds, Int_t idx) {
204 void* ud = ds->GetUserData(idx);
209 return TString::Format(
"RecHit %d energy '%f'", idx, hit->
energy());
222 TEveBoxSet* boxset =
nullptr;
223 TEveStraightLineSet* lineset =
nullptr;
225 for (
unsigned elIdx = 0; elIdx < eleInBlocks.size(); elIdx++) {
231 unsigned indexInBlock = eleInBlocks[elIdx].second;
239 if (myBlock->elements()[indexInBlock].type() == 5)
240 ieHCAL = indexInBlock;
242 std::vector<float> scaledCorners(24);
247 if (myCluster.get()) {
248 const std::vector<std::pair<DetId, float> >& hitsandfracs = myCluster->hitsAndFractions();
251 boxset =
new TEveBoxSet();
252 boxset->Reset(TEveBoxSet::kBT_FreeBox,
true, hitsandfracs.size());
253 boxset->SetAntiFlick(
true);
254 boxset->SetAlwaysSecSelect(
true);
255 boxset->SetPickable(
true);
256 boxset->SetTooltipCBFoo(boxset_tooltip_callback);
260 lineset =
new TEveStraightLineSet();
263 bool hitsFound =
false;
264 for (
int ihandf = 0, lastIdx = (
int)(hitsandfracs.size()); ihandf < lastIdx; ihandf++) {
265 unsigned int hitDetId = hitsandfracs[ihandf].first;
270 boxset->AddBox(&scaledCorners[0]);
272 boxset->DigitColor(holder->GetMainColor());
273 boxset->DigitUserData((
void*)hit);
274 addBoxAsLines(lineset, &scaledCorners[0]);
287 "Can't find matching hits with for HCAL block %d in %s collection. Number of hits %d.\n",
290 (int)hitsandfracs.size());
310 "PFCandidatesWithHits",
const fireworks::Context & context() const
float getScaleFactor3D() const
const FWDisplayProperties & defaultDisplayProperties() const
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
double pz() const final
z coordinate of momentum vector
static const int kAllRPZBits
unsigned detId() const
rechit detId
const std::string & name() const
void setupAddElement(TEveElement *el, TEveElement *parent, bool set_color=true) const
void get(const T *&oData) const
FWViewEnergyScale * getEnergyScale() const
key_type key() const
Accessor for product key.
ProductID id() const
Accessor for product ID.
const FWEventItem * item() const
static const int kAll3DBits
std::vector< ElementInBlock > ElementsInBlocks
double px() const final
x coordinate of momentum vector
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
void scaleProduct(TEveElementList *parent, FWViewType::EType type, const FWViewContext *vc) override
T const * get() const
Returns C++ pointer to the item.
float energy() const
rechit energy
double py() const final
y coordinate of momentum vector
const edm::EventBase * getEvent() const
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
const float * getCorners(unsigned int id) const
void viewContextBoxScale(const float *corners, float scale, bool plotEt, std::vector< float > &scaledCorners, const reco::PFRecHit *)
const reco::PFRecHitCollection * m_collectionHCAL
const Point & vertex() const override
vertex position (overwritten by PF...)
const reco::PFRecHit * getHitForDetId(unsigned detId)
void setTrackTypePF(const reco::PFCandidate &pfCand, TAttLine *track)
Particle reconstructed by the particle flow algorithm.
bool getByLabel(InputTag const &, Handle< T > &) const
TEveCompound * createCompound(bool set_color=true, bool propagate_color_to_all_children=false) const
void initPFRecHitsCollections()
void addHitsForCandidate(const reco::PFCandidate &c, TEveElement *holder, const FWViewContext *vc)
const ElementsInBlocks & elementsInBlocks() const
FWGeometry * getGeom() const
const FWGeometry * getGeom() const
int charge() const final
electric charge