Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:28

0001 #include "Fireworks/Calo/interface/FWCaloDataHistProxyBuilder.h"
0002 #include "Fireworks/Core/interface/fw3dlego_xbins.h"
0003 #include "Fireworks/Calo/interface/FWHistSliceSelector.h"
0004 
0005 #include "Fireworks/Core/interface/FWEventItem.h"
0006 #include "Fireworks/Core/interface/FWModelChangeManager.h"
0007 
0008 #include "Rtypes.h"
0009 #include "TEveCaloData.h"
0010 #include "TMath.h"
0011 #include "TEveCalo.h"
0012 #include "TH2F.h"
0013 
0014 FWCaloDataHistProxyBuilder::FWCaloDataHistProxyBuilder() : m_hist(nullptr), m_sliceSelector(nullptr) {}
0015 FWCaloDataHistProxyBuilder::~FWCaloDataHistProxyBuilder() {}
0016 
0017 namespace {
0018   double wrapPi(double val) {
0019     using namespace TMath;
0020 
0021     if (val < -Pi()) {
0022       return val += TwoPi();
0023     }
0024     if (val > Pi()) {
0025       return val -= TwoPi();
0026     }
0027     return val;
0028   }
0029 }  // namespace
0030 
0031 void FWCaloDataHistProxyBuilder::setCaloData(const fireworks::Context&) { m_caloData = context().getCaloData(); }
0032 
0033 void FWCaloDataHistProxyBuilder::itemBeingDestroyed(const FWEventItem* iItem) {
0034   if (nullptr != m_hist) {
0035     m_hist->Reset();
0036   }
0037   FWCaloDataProxyBuilderBase::itemBeingDestroyed(iItem);
0038 }
0039 
0040 bool FWCaloDataHistProxyBuilder::assertCaloDataSlice() {
0041   if (m_hist == nullptr) {
0042     // add new slice
0043     Bool_t status = TH1::AddDirectoryStatus();
0044     TH1::AddDirectory(kFALSE);  //Keeps histogram from going into memory
0045     m_hist = new TH2F("caloHist", "caloHist", fw3dlego::xbins_n - 1, fw3dlego::xbins, 72, -M_PI, M_PI);
0046     TH1::AddDirectory(status);
0047     TEveCaloDataHist* ch = static_cast<TEveCaloDataHist*>(m_caloData);
0048     m_sliceIndex = ch->AddHistogram(m_hist);
0049 
0050     m_caloData->RefSliceInfo(m_sliceIndex)
0051         .Setup(item()->name().c_str(),
0052                0.,
0053                item()->defaultDisplayProperties().color(),
0054                item()->defaultDisplayProperties().transparency());
0055 
0056     // add new selector
0057     FWFromTEveCaloDataSelector* sel = nullptr;
0058     if (m_caloData->GetUserData()) {
0059       FWFromEveSelectorBase* base = reinterpret_cast<FWFromEveSelectorBase*>(m_caloData->GetUserData());
0060       assert(nullptr != base);
0061       sel = dynamic_cast<FWFromTEveCaloDataSelector*>(base);
0062       assert(nullptr != sel);
0063     } else {
0064       sel = new FWFromTEveCaloDataSelector(m_caloData);
0065       //make sure it is accessible via the base class
0066       m_caloData->SetUserData(static_cast<FWFromEveSelectorBase*>(sel));
0067     }
0068     m_sliceSelector = instantiateSliceSelector();
0069     sel->addSliceSelector(m_sliceIndex, m_sliceSelector);
0070 
0071     return true;
0072   }
0073   return false;
0074 }
0075 
0076 void FWCaloDataHistProxyBuilder::addEntryToTEveCaloData(float eta, float phi, float Et, bool isSelected) {
0077   using namespace TMath;
0078   static float d = 2.5 * Pi() / 180;
0079   //    printf("comapre %f, %f \n", fw3dlego::xbins[80],  fw3dlego::xbins[61] );
0080 
0081   if (m_sliceSelector->aggregatePhiCells()) {
0082     if (Abs(eta) > fw3dlego::xbins[80]) {
0083       m_hist->Fill(eta, wrapPi(phi - 3 * d), Et * 0.25);
0084       m_hist->Fill(eta, wrapPi(phi - d), Et * 0.25);
0085       m_hist->Fill(eta, wrapPi(phi + d), Et * 0.25);
0086       m_hist->Fill(eta, wrapPi(phi + 3 * d), Et * 0.25);
0087     } else if (Abs(eta) > fw3dlego::xbins[61]) {
0088       m_hist->Fill(eta, wrapPi(phi - d), Et * 0.5);
0089       m_hist->Fill(eta, wrapPi(phi + d), Et * 0.5);
0090     } else {
0091       m_hist->Fill(eta, phi, Et);
0092     }
0093   } else {
0094     m_hist->Fill(eta, phi, Et);
0095   }
0096 
0097   TEveCaloData::vCellId_t& selected = m_caloData->GetCellsSelected();
0098   if (isSelected) {
0099     //NOTE: I tried calling TEveCalo::GetCellList but it always returned 0, probably because of threshold issues
0100     // but looking at the TEveCaloHist::GetCellList code the CellId_t is just the histograms bin # and the slice
0101     // printf("applyChangesToAllModels ...check selected \n");
0102 
0103     if (m_sliceSelector->aggregatePhiCells()) {
0104       if (Abs(eta) > fw3dlego::xbins[80]) {
0105         selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(eta, wrapPi(phi - 3 * d)), m_sliceIndex));
0106         selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(eta, wrapPi(phi - d)), m_sliceIndex));
0107         selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(eta, wrapPi(phi + d)), m_sliceIndex));
0108         selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(eta, wrapPi(phi + 3 * d)), m_sliceIndex));
0109       }
0110       if (Abs(eta) > fw3dlego::xbins[60]) {
0111         selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(eta, wrapPi(phi - d)), m_sliceIndex));
0112         selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(eta, wrapPi(phi + d)), m_sliceIndex));
0113       } else {
0114         selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(eta, phi), m_sliceIndex));
0115       }
0116     } else {
0117       selected.push_back(TEveCaloData::CellId_t(m_hist->FindBin(eta, phi), m_sliceIndex));
0118     }
0119   }
0120 }