CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

FWPFCandidateWithHitsProxyBuilder Class Reference

#include <FWPFCandidateWithHitsProxyBuilder.h>

Inheritance diagram for FWPFCandidateWithHitsProxyBuilder:
FWProxyBuilderBase

List of all members.

Public Member Functions

virtual void build (const FWEventItem *iItem, TEveElementList *product, const FWViewContext *)
 FWPFCandidateWithHitsProxyBuilder ()
virtual bool havePerViewProduct (FWViewType::EType) const
 REGISTER_PROXYBUILDER_METHODS ()
virtual void scaleProduct (TEveElementList *parent, FWViewType::EType type, const FWViewContext *vc)
virtual void setItem (const FWEventItem *iItem)
virtual ~FWPFCandidateWithHitsProxyBuilder ()

Private Member Functions

void addHitsForCandidate (const reco::PFCandidate &c, TEveElement *holder, const FWViewContext *vc)
 FWPFCandidateWithHitsProxyBuilder (const FWPFCandidateWithHitsProxyBuilder &)
const reco::PFRecHitgetHitForDetId (unsigned detId)
void initPFRecHitsCollections ()
const
FWPFCandidateWithHitsProxyBuilder
operator= (const FWPFCandidateWithHitsProxyBuilder &)
void viewContextBoxScale (const float *corners, float scale, bool plotEt, std::vector< float > &scaledCorners, const reco::PFRecHit *)

Private Attributes

const reco::PFRecHitCollectionm_collectionHCAL

Detailed Description

Definition at line 12 of file FWPFCandidateWithHitsProxyBuilder.h.


Constructor & Destructor Documentation

FWPFCandidateWithHitsProxyBuilder::FWPFCandidateWithHitsProxyBuilder ( ) [inline]

Definition at line 15 of file FWPFCandidateWithHitsProxyBuilder.h.

{}
virtual FWPFCandidateWithHitsProxyBuilder::~FWPFCandidateWithHitsProxyBuilder ( ) [inline, virtual]

Definition at line 16 of file FWPFCandidateWithHitsProxyBuilder.h.

{}
FWPFCandidateWithHitsProxyBuilder::FWPFCandidateWithHitsProxyBuilder ( const FWPFCandidateWithHitsProxyBuilder ) [private]

Member Function Documentation

void FWPFCandidateWithHitsProxyBuilder::addHitsForCandidate ( const reco::PFCandidate c,
TEveElement *  holder,
const FWViewContext vc 
) [private]

Definition at line 262 of file FWPFCandidateWithHitsProxyBuilder.cc.

References FWProxyBuilderBase::context(), reco::PFCandidate::elementsInBlocks(), reco::PFRecHit::energy(), fwLog, edm::Ref< C, T, F >::get(), FWGeometry::getCorners(), FWViewContext::getEnergyScale(), fireworks::Context::getGeom(), getHitForDetId(), FWViewEnergyScale::getPlotEt(), FWViewEnergyScale::getScaleFactor3D(), edm::Ref< C, T, F >::id(), edm::Ref< C, T, F >::key(), fwlog::kInfo, fwlog::kWarning, m_collectionHCAL, pileupReCalc_HLTpaths::scale, FWProxyBuilderBase::setupAddElement(), and viewContextBoxScale().

Referenced by build().

{ 
   reco::PFCandidate::ElementsInBlocks eleInBlocks = cand.elementsInBlocks();

   TEveBoxSet* boxset = 0;
   TEveStraightLineSet* lineset = 0;

   for(unsigned elIdx=0; elIdx<eleInBlocks.size(); elIdx++)
   {
      // unsigned ieTrack = 0;
      // unsigned ieECAL = 0;
      unsigned ieHCAL = 0;

      reco::PFBlockRef blockRef = eleInBlocks[elIdx].first;
      unsigned indexInBlock = eleInBlocks[elIdx].second;
      edm::Ptr<reco::PFBlock> myBlock(blockRef.id(),blockRef.get(), blockRef.key());
      /*
        if (myBlock->elements()[indexInBlock].type() == 1)
        ieTrack = indexInBlock;
        if (myBlock->elements()[indexInBlock].type() == 4)
        ieECAL = indexInBlock;
      */
      if (myBlock->elements()[indexInBlock].type() == 5)
         ieHCAL = indexInBlock;
   
 
      std::vector<float> scaledCorners(24);
      float scale = vc->getEnergyScale()->getScaleFactor3D()/50;
      if (ieHCAL &&  m_collectionHCAL) {
         reco::PFClusterRef hcalclusterRef=myBlock->elements()[ieHCAL].clusterRef();
         edm::Ptr<reco::PFCluster> myCluster(hcalclusterRef.id(),hcalclusterRef.get(), hcalclusterRef.key());
         if (myCluster.get())
         {
            const std::vector< std::pair<DetId, float> > & hitsandfracs = myCluster->hitsAndFractions();

            if (!boxset)
            {
               boxset = new TEveBoxSet();
               boxset->Reset(TEveBoxSet::kBT_FreeBox, true, hitsandfracs.size());
               boxset->SetAntiFlick(true);
               boxset->SetAlwaysSecSelect(1);
               boxset->SetPickable(1);
               boxset->SetTooltipCBFoo(boxset_tooltip_callback);
            }

            if (!lineset)
            {
               lineset = new TEveStraightLineSet();
            }

            bool hitsFound = false;
            for ( int ihandf=0, lastIdx=(int)(hitsandfracs.size()); ihandf<lastIdx; ihandf++) 
            {
               unsigned int hitDetId = hitsandfracs[ihandf].first;
               const float* corners = context().getGeom()->getCorners(hitDetId);
               const reco::PFRecHit* hit = getHitForDetId(hitDetId);
               if (hit)
               {
                  viewContextBoxScale( corners, hit->energy()*scale, vc->getEnergyScale()->getPlotEt(), scaledCorners, hit);
                  boxset->AddBox( &scaledCorners[0]);
                  // setup last box
                  boxset->DigitColor(holder->GetMainColor());
                  boxset->DigitUserData((void*)hit);
                  addBoxAsLines(lineset, &scaledCorners[0]);
                  hitsFound = true;
               }
               /*
               // AMT: don't add lines if hit is not found becuse of unconsistency of scaling.
               else
               {
                  addBoxAsLines(lineset, corners);
               }
               */
            }
            if (!hitsFound)
               fwLog(fwlog::kWarning) << Form("Can't find matching hits with for HCAL block %d in RecHit collection. Number of hits %d.\n", elIdx, (int)hitsandfracs.size());


         }
         else
         {
            fwLog(fwlog::kInfo) << "empty cluster \n";
         }
      }
   } // endloop cand.elementsInBlocks();


   if (boxset) {
      boxset->RefitPlex();
      setupAddElement(boxset, holder);
   }

   if (lineset) {
      setupAddElement(lineset, holder);
   }
}
void FWPFCandidateWithHitsProxyBuilder::build ( const FWEventItem iItem,
TEveElementList *  product,
const FWViewContext vc 
) [virtual]

Reimplemented from FWProxyBuilderBase.

Definition at line 94 of file FWPFCandidateWithHitsProxyBuilder.cc.

References addHitsForCandidate(), reco::LeafCandidate::charge(), FWDisplayProperties::color(), AlCaHLTBitMon_QueryRunRegistry::comp, FWProxyBuilderBase::context(), FWProxyBuilderBase::createCompound(), FWEventItem::defaultDisplayProperties(), FWEventItem::get(), customizeTrackingMonitorSeedNumber::idx, initPFRecHitsCollections(), reco::LeafCandidate::px(), reco::LeafCandidate::py(), reco::LeafCandidate::pz(), fireworks::setTrackTypePF(), FWProxyBuilderBase::setupAddElement(), lumiQTWidget::t, and reco::PFCandidate::vertex().

{
   // init PFCandiate collection
   reco::PFCandidateCollection const * candidates = 0;
   iItem->get( candidates );
   if( candidates == 0 ) return;

   Int_t idx = 0;
   initPFRecHitsCollections();
   for( reco::PFCandidateCollection::const_iterator it = candidates->begin(), itEnd = candidates->end(); it != itEnd; ++it, ++idx)
   {  
      TEveCompound* comp = createCompound();
      setupAddElement( comp, product );
      // printf("products size %d/%d \n", (int)iItem->size(), product->NumChildren());

      const reco::PFCandidate& cand = *it;
      
      // track
      {
         TEveRecTrack t;
         t.fBeta = 1.;
         t.fP = TEveVector( cand.px(), cand.py(), cand.pz() );
         t.fV = TEveVector( cand.vertex().x(), cand.vertex().y(), cand.vertex().z() );
         t.fSign = cand.charge();
         TEveTrack* trk = new TEveTrack(&t, context().getTrackPropagator() );
         trk->MakeTrack();
         fireworks::setTrackTypePF( cand, trk );
         setupAddElement( trk, comp);
      }
      // hits
      {
         comp->SetMainColor(iItem->defaultDisplayProperties().color());
         addHitsForCandidate(cand, comp, vc);
      }

   }
}
const reco::PFRecHit * FWPFCandidateWithHitsProxyBuilder::getHitForDetId ( unsigned  detId) [private]

Definition at line 189 of file FWPFCandidateWithHitsProxyBuilder.cc.

References m_collectionHCAL.

Referenced by addHitsForCandidate().

{

   for (reco::PFRecHitCollection::const_iterator it = m_collectionHCAL->begin(); it != m_collectionHCAL->end(); ++it)
   {

      if ( it->detId() == candIdx)
      {
         return  &(*it);
      }
   }
   return 0;
}
virtual bool FWPFCandidateWithHitsProxyBuilder::havePerViewProduct ( FWViewType::EType  ) const [inline, virtual]

Reimplemented from FWProxyBuilderBase.

Definition at line 20 of file FWPFCandidateWithHitsProxyBuilder.h.

{ return true; }
void FWPFCandidateWithHitsProxyBuilder::initPFRecHitsCollections ( ) [private]

Definition at line 133 of file FWPFCandidateWithHitsProxyBuilder.cc.

References fwLog, edm::EventBase::getByLabel(), FWEventItem::getConfig(), FWEventItem::getEvent(), edm::HandleBase::isValid(), FWProxyBuilderBase::item(), fwlog::kError, fwlog::kInfo, m_collectionHCAL, FWEventItem::name(), AlCaHLTBitMon_QueryRunRegistry::string, GlobalPosition_Frontier_DevDB_cff::tag, and FWProxyBuilderConfiguration::value().

Referenced by build().

{  
   // ref hcal collections
   edm::Handle<reco::PFRecHitCollection> handle_hits;


   m_collectionHCAL =0;
   try
   {
      std::string scc = item()->getConfig()->value<std::string>(kRecHitCollectionName);
      edm::InputTag tag(scc);
      item()->getEvent()->getByLabel(tag, handle_hits);
      if (handle_hits.isValid())
      {
         m_collectionHCAL = &*handle_hits;
         fwLog(fwlog::kInfo) <<"FWPFCandidateWithHitsProxyBuilder, item " << item()->name() <<": Accessed collection with name " << scc << "." << std::endl;
      }
      else
      {
         fwLog(fwlog::kError) <<"FWPFCandidateWithHitsProxyBuilder, item " << item()->name() <<": Failed to access collection with name " << scc << "." << std::endl;
      }
   }
   catch (...)
   {
      fwLog(fwlog::kError) <<"FWPFCandidateWithHitsProxyBuilder, item " << item()->name() <<": Failed to access rechit collection \n";
   }
}
const FWPFCandidateWithHitsProxyBuilder& FWPFCandidateWithHitsProxyBuilder::operator= ( const FWPFCandidateWithHitsProxyBuilder ) [private]
FWPFCandidateWithHitsProxyBuilder::REGISTER_PROXYBUILDER_METHODS ( )
void FWPFCandidateWithHitsProxyBuilder::scaleProduct ( TEveElementList *  parent,
FWViewType::EType  type,
const FWViewContext vc 
) [virtual]

Reimplemented from FWProxyBuilderBase.

Definition at line 204 of file FWPFCandidateWithHitsProxyBuilder.cc.

References reco::PFRecHit::detId(), reco::PFRecHit::energy(), FWGeometry::getCorners(), FWViewContext::getEnergyScale(), FWEventItem::getGeom(), FWViewEnergyScale::getPlotEt(), FWViewEnergyScale::getScaleFactor3D(), i, FWProxyBuilderBase::item(), AlCaHLTBitMon_ParallelJobs::p, pileupReCalc_HLTpaths::scale, and viewContextBoxScale().

{
   std::vector<float> scaledCorners(24);

   float scale = vc->getEnergyScale()->getScaleFactor3D()/50;
   for (TEveElement::List_i i=parent->BeginChildren(); i!=parent->EndChildren(); ++i)
   {
      if ((*i)->NumChildren() > 1)
      {
         TEveElement::List_i xx =  (*i)->BeginChildren(); ++xx;
         TEveBoxSet* boxset = dynamic_cast<TEveBoxSet*>(*xx);
         ++xx;
         TEveStraightLineSet* lineset = dynamic_cast<TEveStraightLineSet*>(*xx);
         TEveChunkManager::iterator li(lineset->GetLinePlex());
         li.next();


         TEveChunkManager* plex = boxset->GetPlex();
         if (plex->N())
         {
            for (int atomIdx=0; atomIdx < plex->Size(); ++atomIdx)
            {
              
               TEveBoxSet::BFreeBox_t* atom = (TEveBoxSet::BFreeBox_t*)boxset->GetPlex()->Atom(atomIdx);
               reco::PFRecHit* hit = (reco::PFRecHit*)boxset->GetUserData(atomIdx);
               const float* corners = item()->getGeom()->getCorners(hit->detId());
               viewContextBoxScale(corners, hit->energy()*scale, vc->getEnergyScale()->getPlotEt(), scaledCorners, hit);
               memcpy(atom->fVertices, &scaledCorners[0], sizeof(atom->fVertices));

               editBoxInLineSet(li, &scaledCorners[0]);
            }

            for (TEveProjectable::ProjList_i p = lineset->BeginProjecteds(); p != lineset->EndProjecteds(); ++p)
            {
               TEveStraightLineSetProjected* projLineSet = (TEveStraightLineSetProjected*)(*p);
               projLineSet->UpdateProjection();
            }
         }
      }
   }
}  
void FWPFCandidateWithHitsProxyBuilder::setItem ( const FWEventItem iItem) [virtual]

Reimplemented from FWProxyBuilderBase.

Definition at line 82 of file FWPFCandidateWithHitsProxyBuilder.cc.

References FWProxyBuilderConfiguration::assertParam(), FWEventItem::getConfig(), and AlCaHLTBitMon_QueryRunRegistry::string.

{

   FWProxyBuilderBase::setItem(iItem);
   if (iItem) {
      std::string defn =  "particleFlowRecHitHCAL";
      iItem->getConfig()->assertParam(kRecHitCollectionName, defn);
   }
}
void FWPFCandidateWithHitsProxyBuilder::viewContextBoxScale ( const float *  corners,
float  scale,
bool  plotEt,
std::vector< float > &  scaledCorners,
const reco::PFRecHit  
) [private]

Definition at line 162 of file FWPFCandidateWithHitsProxyBuilder.cc.

References f, and i.

Referenced by addHitsForCandidate(), and scaleProduct().

{
   static TEveVector vtmp;
   vtmp.Set(0.f, 0.f, 0.f);
   for( unsigned int i = 0; i < 24; i += 3 )
   {     
      vtmp[0] += corners[i];
      vtmp[1] += corners[i + 1];
      vtmp[2] += corners[i + 2];
   }
   vtmp *= 1.f/8.f;

   if (plotEt)
   {
      scale *= vtmp.Perp()/vtmp.Mag();
   }

   // Coordinates for a scaled version of the original box
   for( unsigned int i = 0; i < 24; i += 3 )
   {    
      scaledCorners[i] = vtmp[0] + ( corners[i] - vtmp[0] ) * scale;
      scaledCorners[i + 1] = vtmp[1] + ( corners[i + 1] - vtmp[1] ) * scale;
      scaledCorners[i + 2] = vtmp[2] + ( corners[i + 2] - vtmp[2] ) * scale;
   }
}

Member Data Documentation