CMS 3D CMS Logo

FWPFCandidateWithHitsProxyBuilder.cc
Go to the documentation of this file.
1 #include "TEveBoxSet.h"
2 #include "TEveTrack.h"
3 #include "TEveTrackPropagator.h"
4 #include "TEveCompound.h"
5 #include "TEveStraightLineSet.h"
6 #include "TEveProjectionBases.h"
7 
15 
20 
22 
23 namespace {
24  const std::string cname("particleFlowRecHitHCALUpgrade");
25 
26  void addLineToLineSet(TEveStraightLineSet* ls, const float* p, int i1, int i2) {
27  i1 *= 3;
28  i2 *= 3;
29  ls->AddLine(p[i1], p[i1 + 1], p[i1 + 2], p[i2], p[i2 + 1], p[i2 + 2]);
30  }
31 
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);
38  }
39  for (int l = 0; l < 4; ++l)
40  addLineToLineSet(lineset, p, 0 + l, 4 + l);
41  }
42 
43  void editLineInLineSet(TEveChunkManager::iterator& li, const float* p, int i1, int i2) {
44  TEveStraightLineSet::Line_t& line = *(TEveStraightLineSet::Line_t*)li();
45  i1 *= 3;
46  i2 *= 3;
47  for (int i = 0; i < 3; ++i) {
48  line.fV1[0 + i] = p[i1 + i];
49  line.fV2[0 + i] = p[i2 + i];
50  }
51 
52  li.next();
53  }
54 
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);
58 
59  editLineInLineSet(li, p, 1 + i, 2 + i);
60  editLineInLineSet(li, p, 2 + i, 3 + i);
61  editLineInLineSet(li, p, 3 + i, 0 + i);
62  }
63  for (int i = 0; i < 4; ++i)
64  editLineInLineSet(li, p, 0 + i, 4 + i);
65  }
66 } // namespace
67 
68 //______________________________________________________________________________
70  TEveElementList* product,
71  const FWViewContext* vc) {
72  // init PFCandiate collection
73  reco::PFCandidateCollection const* candidates = nullptr;
74  iItem->get(candidates);
75  if (candidates == nullptr)
76  return;
77 
78  Int_t idx = 0;
80  for (reco::PFCandidateCollection::const_iterator it = candidates->begin(), itEnd = candidates->end(); it != itEnd;
81  ++it, ++idx) {
82  TEveCompound* comp = createCompound();
83  setupAddElement(comp, product);
84  // printf("products size %d/%d \n", (int)iItem->size(), product->NumChildren());
85 
86  const reco::PFCandidate& cand = *it;
87 
88  // track
89  {
90  TEveRecTrack t;
91  t.fBeta = 1.;
92  t.fP = TEveVector(cand.px(), cand.py(), cand.pz());
93  t.fV = TEveVector(cand.vertex().x(), cand.vertex().y(), cand.vertex().z());
94  t.fSign = cand.charge();
95  TEveTrack* trk = new TEveTrack(&t, context().getTrackPropagator());
96  trk->MakeTrack();
98  setupAddElement(trk, comp);
99  }
100  // hits
101  {
102  comp->SetMainColor(iItem->defaultDisplayProperties().color());
104  }
105  }
106 }
107 
108 //______________________________________________________________________________
110  // ref hcal collections
112 
113  m_collectionHCAL = nullptr;
114  try {
115  // edm::InputTag tag("particleFlowRecHitHCAL");
116  edm::InputTag tag(cname);
117  item()->getEvent()->getByLabel(tag, handle_hits);
118  if (handle_hits.isValid()) {
119  m_collectionHCAL = &*handle_hits;
120  } else {
121  fwLog(fwlog::kError) << "FWPFCandidateWithHitsProxyBuilder, item " << item()->name()
122  << ": Failed to access collection with name " << cname << "." << std::endl;
123  }
124  } catch (...) {
125  fwLog(fwlog::kError) << "FWPFCandidateWithHitsProxyBuilder, item " << item()->name()
126  << ": Failed to access collection with name " << cname << "." << std::endl;
127  }
128 }
129 
130 //______________________________________________________________________________
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];
139  }
140  vtmp *= 1.f / 8.f;
141 
142  if (plotEt) {
143  scale *= vtmp.Perp() / vtmp.Mag();
144  }
145 
146  // Coordinates for a scaled version of the original box
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;
151  }
152 }
153 
154 //______________________________________________________________________________
156  for (reco::PFRecHitCollection::const_iterator it = m_collectionHCAL->begin(); it != m_collectionHCAL->end(); ++it) {
157  if (it->detId() == candIdx) {
158  return &(*it);
159  }
160  }
161  return nullptr;
162 }
163 
164 //______________________________________________________________________________
167  const FWViewContext* vc) {
168  std::vector<float> scaledCorners(24);
169 
170  float scale = vc->getEnergyScale()->getScaleFactor3D() / 50;
171  for (TEveElement::List_i i = parent->BeginChildren(); i != parent->EndChildren(); ++i) {
172  if ((*i)->NumChildren() > 1) {
173  TEveElement::List_i xx = (*i)->BeginChildren();
174  ++xx;
175  TEveBoxSet* boxset = dynamic_cast<TEveBoxSet*>(*xx);
176  ++xx;
177  TEveStraightLineSet* lineset = dynamic_cast<TEveStraightLineSet*>(*xx);
178  TEveChunkManager::iterator li(lineset->GetLinePlex());
179  li.next();
180 
181  TEveChunkManager* plex = boxset->GetPlex();
182  if (plex->N()) {
183  for (int atomIdx = 0; atomIdx < plex->Size(); ++atomIdx) {
184  TEveBoxSet::BFreeBox_t* atom = (TEveBoxSet::BFreeBox_t*)boxset->GetPlex()->Atom(atomIdx);
185  reco::PFRecHit* hit = (reco::PFRecHit*)boxset->GetUserData(atomIdx);
186  const float* corners = item()->getGeom()->getCorners(hit->detId());
187  viewContextBoxScale(corners, hit->energy() * scale, vc->getEnergyScale()->getPlotEt(), scaledCorners, hit);
188  memcpy(atom->fVertices, &scaledCorners[0], sizeof(atom->fVertices));
189 
190  editBoxInLineSet(li, &scaledCorners[0]);
191  }
192 
193  for (TEveProjectable::ProjList_i p = lineset->BeginProjecteds(); p != lineset->EndProjecteds(); ++p) {
194  TEveStraightLineSetProjected* projLineSet = (TEveStraightLineSetProjected*)(*p);
195  projLineSet->UpdateProjection();
196  }
197  }
198  }
199  }
200 }
201 //______________________________________________________________________________
202 namespace {
203  TString boxset_tooltip_callback(TEveDigitSet* ds, Int_t idx) {
204  void* ud = ds->GetUserData(idx);
205  if (ud) {
207  // printf("idx %d %p hit data %p\n", idx, (void*)hit, ud);
208  if (hit)
209  return TString::Format("RecHit %d energy '%f'", idx, hit->energy());
210  else
211  return "ERROR";
212  }
213  return "NULL";
214  }
215 } // namespace
216 //______________________________________________________________________________
218  TEveElement* holder,
219  const FWViewContext* vc) {
220  reco::PFCandidate::ElementsInBlocks eleInBlocks = cand.elementsInBlocks();
221 
222  TEveBoxSet* boxset = nullptr;
223  TEveStraightLineSet* lineset = nullptr;
224 
225  for (unsigned elIdx = 0; elIdx < eleInBlocks.size(); elIdx++) {
226  // unsigned ieTrack = 0;
227  // unsigned ieECAL = 0;
228  unsigned ieHCAL = 0;
229 
230  reco::PFBlockRef blockRef = eleInBlocks[elIdx].first;
231  unsigned indexInBlock = eleInBlocks[elIdx].second;
232  edm::Ptr<reco::PFBlock> myBlock(blockRef.id(), blockRef.get(), blockRef.key());
233  /*
234  if (myBlock->elements()[indexInBlock].type() == 1)
235  ieTrack = indexInBlock;
236  if (myBlock->elements()[indexInBlock].type() == 4)
237  ieECAL = indexInBlock;
238  */
239  if (myBlock->elements()[indexInBlock].type() == 5)
240  ieHCAL = indexInBlock;
241 
242  std::vector<float> scaledCorners(24);
243  float scale = vc->getEnergyScale()->getScaleFactor3D() / 50;
244  if (ieHCAL && m_collectionHCAL) {
245  reco::PFClusterRef hcalclusterRef = myBlock->elements()[ieHCAL].clusterRef();
246  edm::Ptr<reco::PFCluster> myCluster(hcalclusterRef.id(), hcalclusterRef.get(), hcalclusterRef.key());
247  if (myCluster.get()) {
248  const std::vector<std::pair<DetId, float> >& hitsandfracs = myCluster->hitsAndFractions();
249 
250  if (!boxset) {
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);
257  }
258 
259  if (!lineset) {
260  lineset = new TEveStraightLineSet();
261  }
262 
263  bool hitsFound = false;
264  for (int ihandf = 0, lastIdx = (int)(hitsandfracs.size()); ihandf < lastIdx; ihandf++) {
265  unsigned int hitDetId = hitsandfracs[ihandf].first;
266  const float* corners = context().getGeom()->getCorners(hitDetId);
267  const reco::PFRecHit* hit = getHitForDetId(hitDetId);
268  if (hit) {
269  viewContextBoxScale(corners, hit->energy() * scale, vc->getEnergyScale()->getPlotEt(), scaledCorners, hit);
270  boxset->AddBox(&scaledCorners[0]);
271  // setup last box
272  boxset->DigitColor(holder->GetMainColor());
273  boxset->DigitUserData((void*)hit);
274  addBoxAsLines(lineset, &scaledCorners[0]);
275  hitsFound = true;
276  }
277  /*
278  // AMT: don't add lines if hit is not found becuse of unconsistency of scaling.
279  else
280  {
281  addBoxAsLines(lineset, corners);
282  }
283  */
284  }
285  if (!hitsFound)
286  fwLog(fwlog::kWarning) << Form(
287  "Can't find matching hits with for HCAL block %d in %s collection. Number of hits %d.\n",
288  elIdx,
289  cname.c_str(),
290  (int)hitsandfracs.size());
291 
292  } else {
293  fwLog(fwlog::kInfo) << "empty cluster \n";
294  }
295  }
296  } // endloop cand.elementsInBlocks();
297 
298  if (boxset) {
299  boxset->RefitPlex();
300  setupAddElement(boxset, holder);
301  }
302 
303  if (lineset) {
304  setupAddElement(lineset, holder);
305  }
306 }
307 
310  "PFCandidatesWithHits",
eostools.ls
def ls(path, rec=False)
Definition: eostools.py:349
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
fwLog
#define fwLog(_level_)
Definition: fwLog.h:45
mps_fire.i
i
Definition: mps_fire.py:428
Handle.h
FWGeometry::getCorners
const float * getCorners(unsigned int id) const
Definition: FWGeometry.cc:467
L1EGammaCrystalsEmulatorProducer_cfi.scale
scale
Definition: L1EGammaCrystalsEmulatorProducer_cfi.py:10
FWPFCandidateWithHitsProxyBuilder::initPFRecHitsCollections
void initPFRecHitsCollections()
Definition: FWPFCandidateWithHitsProxyBuilder.cc:109
FWViewType::EType
EType
Definition: FWViewType.h:31
edm::EventBase::getByLabel
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:92
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
PFCandidate.h
FWViewType::kAllRPZBits
static const int kAllRPZBits
Definition: FWViewType.h:67
REGISTER_FWPROXYBUILDER
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
Definition: FWProxyBuilderFactory.h:33
FWEventItem::get
void get(const T *&oData) const
Definition: FWEventItem.h:78
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
FWPFCandidateWithHitsProxyBuilder::viewContextBoxScale
void viewContextBoxScale(const float *corners, float scale, bool plotEt, std::vector< float > &scaledCorners, const reco::PFRecHit *)
Definition: FWPFCandidateWithHitsProxyBuilder.cc:131
edm::Ref::get
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
FWViewEnergyScale::getPlotEt
bool getPlotEt() const
Definition: FWViewEnergyScale.h:47
FWPFCandidateWithHitsProxyBuilder.h
BuilderUtils.h
FWDisplayProperties::color
Color_t color() const
Definition: FWDisplayProperties.h:47
edm::Handle< reco::PFRecHitCollection >
FWProxyBuilderBase::createCompound
TEveCompound * createCompound(bool set_color=true, bool propagate_color_to_all_children=false) const
Definition: FWProxyBuilderBase.cc:374
fireworks::setTrackTypePF
void setTrackTypePF(const reco::PFCandidate &pfCand, TAttLine *track)
Definition: setTrackTypePF.cc:16
AlCaHLTBitMon_QueryRunRegistry.comp
comp
Definition: AlCaHLTBitMon_QueryRunRegistry.py:249
edm::Ref< PFBlockCollection >
FWViewType::kAll3DBits
static const int kAll3DBits
Definition: FWViewType.h:68
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
FWEventItem::defaultDisplayProperties
const FWDisplayProperties & defaultDisplayProperties() const
Definition: FWEventItem.cc:403
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
FWPFCandidateWithHitsProxyBuilder
Definition: FWPFCandidateWithHitsProxyBuilder.h:11
PFCluster.h
reco::PFCandidate::ElementsInBlocks
std::vector< ElementInBlock > ElementsInBlocks
Definition: PFCandidate.h:379
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FWEventItem::getEvent
const edm::EventBase * getEvent() const
Definition: FWEventItem.h:131
FWPFCandidateWithHitsProxyBuilder::m_collectionHCAL
const reco::PFRecHitCollection * m_collectionHCAL
Definition: FWPFCandidateWithHitsProxyBuilder.h:34
FWGeometry.h
reco::CaloCluster::hitsAndFractions
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:210
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
fireworks::Context::getGeom
FWGeometry * getGeom() const
Definition: Context.h:72
cand
Definition: decayParser.h:32
createfilelist.int
int
Definition: createfilelist.py:10
setTrackTypePF.h
FWProxyBuilderBase::setupAddElement
void setupAddElement(TEveElement *el, TEveElement *parent, bool set_color=true) const
Definition: FWProxyBuilderBase.cc:350
fwlog::kWarning
Definition: fwLog.h:35
fwLog.h
FWProxyBuilderBase::build
void build()
Definition: FWProxyBuilderBase.cc:110
FWEventItem.h
FWViewContext
Definition: FWViewContext.h:32
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
edm::Ptr
Definition: AssociationVector.h:31
PFBlock.h
FWEventItem::getGeom
const FWGeometry * getGeom() const
Definition: FWEventItem.cc:548
FWProxyBuilderBase::item
const FWEventItem * item() const
Definition: FWProxyBuilderBase.h:64
FWViewEnergyScale::getScaleFactor3D
float getScaleFactor3D() const
Definition: FWViewEnergyScale.h:44
fwlog::kInfo
Definition: fwLog.h:35
edm::Ref::id
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
FWEventItem
Definition: FWEventItem.h:56
HLT_FULL_cff.candidates
candidates
Definition: HLT_FULL_cff.py:54996
FWPFCandidateWithHitsProxyBuilder::scaleProduct
void scaleProduct(TEveElementList *parent, FWViewType::EType type, const FWViewContext *vc) override
Definition: FWPFCandidateWithHitsProxyBuilder.cc:165
reco::PFCandidateCollection
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
Definition: PFCandidateFwd.h:12
FWProxyBuilderBase::context
const fireworks::Context & context() const
Definition: FWProxyBuilderBase.cc:412
reco::PFRecHit
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:31
fwlog::kError
Definition: fwLog.h:35
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
edm::Ref::key
key_type key() const
Accessor for product key.
Definition: Ref.h:250
FWEventItem::name
const std::string & name() const
Definition: FWEventItem.cc:435
FWViewEnergyScale.h
FWPFCandidateWithHitsProxyBuilder::getHitForDetId
const reco::PFRecHit * getHitForDetId(unsigned detId)
Definition: FWPFCandidateWithHitsProxyBuilder.cc:155
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
mps_splice.line
line
Definition: mps_splice.py:76
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
FWViewContext::getEnergyScale
FWViewEnergyScale * getEnergyScale() const
Definition: FWViewContext.cc:25
class-composition.parent
parent
Definition: class-composition.py:88
edm::InputTag
Definition: InputTag.h:15
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
FWPFCandidateWithHitsProxyBuilder::addHitsForCandidate
void addHitsForCandidate(const reco::PFCandidate &c, TEveElement *holder, const FWViewContext *vc)
Definition: FWPFCandidateWithHitsProxyBuilder.cc:217
hit
Definition: SiStripHitEffFromCalibTree.cc:88
PFCandidateFwd.h