CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

FFTJetPileupAnalyzer Class Reference

#include <RecoJets/JetAnalyzers/src/FFTJetPileupAnalyzer.cc>

Inheritance diagram for FFTJetPileupAnalyzer:
edm::EDAnalyzer

List of all members.

Public Member Functions

 FFTJetPileupAnalyzer (const edm::ParameterSet &)
 ~FFTJetPileupAnalyzer ()

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
void analyzePileup (const std::vector< PileupSummaryInfo > &pInfo)
virtual void beginJob ()
virtual void endJob ()
 FFTJetPileupAnalyzer (const FFTJetPileupAnalyzer &)
 FFTJetPileupAnalyzer ()
FFTJetPileupAnalyzeroperator= (const FFTJetPileupAnalyzer &)

Private Attributes

bool collectFastJetRho
bool collectGridDensity
bool collectGrids
bool collectHistos
bool collectOOTPileup
bool collectPileup
bool collectSummaries
bool collectVertexInfo
unsigned long counter
double crazyEnergyCut
edm::InputTag fastJetRhoLabel
edm::InputTag fastJetSigmaLabel
edm::InputTag gridLabel
edm::InputTag histoLabel
TNtuple * nt
std::vector< float > ntupleData
std::string ntupleName
std::string ntupleTitle
std::string pileupLabel
edm::InputTag srcPVs
edm::InputTag summaryLabel
int totalNpu
int totalNPV
bool verbosePileupInfo
double vertexNdofCut

Detailed Description

Description: collects the info produced by FFTJetPileupProcessor and FFTJetPileupEstimator

Implementation: [Notes on implementation]

Definition at line 51 of file FFTJetPileupAnalyzer.cc.


Constructor & Destructor Documentation

FFTJetPileupAnalyzer::FFTJetPileupAnalyzer ( const edm::ParameterSet ps) [explicit]
FFTJetPileupAnalyzer::~FFTJetPileupAnalyzer ( )

Definition at line 131 of file FFTJetPileupAnalyzer.cc.

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

Member Function Documentation

void FFTJetPileupAnalyzer::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
) [private, virtual]

Implements edm::EDAnalyzer.

Definition at line 252 of file FFTJetPileupAnalyzer.cc.

References analyzePileup(), collectFastJetRho, collectGridDensity, collectGrids, collectHistos, collectOOTPileup, collectPileup, collectSummaries, collectVertexInfo, filterCSVwithJSON::copy, counter, data, edm::EventID::event(), f, fastJetRhoLabel, fastJetSigmaLabel, edm::Event::getByLabel(), gridLabel, h, histoLabel, edm::EventBase::id(), LaserDQM_cfg::input, M_PI, nt, ntupleData, pileupLabel, edm::EventID::run(), cond::runnumber, srcPVs, edmLumisInFiles::summary, summaryLabel, totalNpu, totalNPV, and vertexNdofCut.

{
    ntupleData.clear();
    ntupleData.push_back(counter);
    totalNpu = -1;
    totalNPV = -1;

    const long runnumber = iEvent.id().run();
    const long eventnumber = iEvent.id().event();
    ntupleData.push_back(runnumber);
    ntupleData.push_back(eventnumber);

    // Get pileup information from the pile-up information module
    if (collectPileup || collectOOTPileup)
    {
        edm::Handle<std::vector<PileupSummaryInfo> > puInfo;
        if (iEvent.getByLabel(pileupLabel, puInfo))
            analyzePileup(*puInfo);
        else
        {
            if (collectPileup)
            {
                ntupleData.push_back(-1);
                ntupleData.push_back(-1);
                ntupleData.push_back(0.f);
                ntupleData.push_back(0.f);
            }
            if (collectOOTPileup)
                for (unsigned ibx = 0; ibx < 3; ++ibx)
                {
                    ntupleData.push_back(-1);
                    ntupleData.push_back(0.f);
                    ntupleData.push_back(0.f);
                }
        }
    }

    if (collectHistos)
    {
        edm::Handle<TH2D> input;
        iEvent.getByLabel(histoLabel, input);

        edm::Service<TFileService> fs;
        TH2D* copy = new TH2D(*input);

        std::ostringstream os;
        os << copy->GetName() << '_' << counter << '_'
           << totalNpu << '_' << runnumber << '_' << eventnumber;
        const std::string& newname(os.str());
        copy->SetNameTitle(newname.c_str(), newname.c_str());

        copy->SetDirectory(fs->getBareDirectory());
    }

    if (collectSummaries)
    {
        edm::Handle<reco::FFTJetPileupSummary> summary;
        iEvent.getByLabel(summaryLabel, summary);

        ntupleData.push_back(summary->uncalibratedQuantile());
        ntupleData.push_back(summary->pileupRho());
        ntupleData.push_back(summary->pileupRhoUncertainty());
        ntupleData.push_back(summary->uncertaintyCode());
    }

    if (collectFastJetRho)
    {
        edm::Handle<double> fjrho, fjsigma;
        iEvent.getByLabel(fastJetRhoLabel, fjrho);
        iEvent.getByLabel(fastJetSigmaLabel, fjsigma);

        ntupleData.push_back(*fjrho);
        ntupleData.push_back(*fjsigma);
    }

    if (collectGrids)
    {
        edm::Handle<reco::DiscretizedEnergyFlow> input;
        iEvent.getByLabel(gridLabel, input);

        // Make sure the input grid is reasonable
        const double* data = input->data();
        assert(data);
        assert(input->phiBin0Edge() == 0.0);
        const unsigned nEta = input->nEtaBins();
        const unsigned nPhi = input->nPhiBins();

        // Generate a name for the output histogram
        std::ostringstream os;
        os << "FFTJetGrid_" << counter << '_'
           << totalNpu << '_' << runnumber << '_' << eventnumber;
        const std::string& newname(os.str());

        // Make a histogram and copy the grid data into it
        edm::Service<TFileService> fs;
        TH2F* h = fs->make<TH2F>(newname.c_str(), newname.c_str(),
                                 nEta, input->etaMin(), input->etaMax(),
                                 nPhi, 0.0, 2.0*M_PI);
        h->GetXaxis()->SetTitle("Eta");
        h->GetYaxis()->SetTitle("Phi");
        h->GetZaxis()->SetTitle("Transverse Energy");

        for (unsigned ieta=0; ieta<nEta; ++ieta)
            for (unsigned iphi=0; iphi<nPhi; ++iphi)
                h->SetBinContent(ieta+1U, iphi+1U, data[ieta*nPhi + iphi]);
    }

    if (collectGridDensity)
    {
        edm::Handle<std::pair<double,double> > etSum;
        iEvent.getByLabel(histoLabel, etSum);

        ntupleData.push_back(etSum->first);
        ntupleData.push_back(etSum->second);
    }

    if (collectVertexInfo)
    {
        edm::Handle<reco::VertexCollection> pvCollection;
        iEvent.getByLabel(srcPVs, pvCollection);
        totalNPV = 0;
        if (!pvCollection->empty())
            for (reco::VertexCollection::const_iterator pv = pvCollection->begin();
                 pv != pvCollection->end(); ++pv)
            {
                const double ndof = pv->ndof();
                if (!pv->isFake() && ndof > vertexNdofCut)
                    ++totalNPV;
            }
        ntupleData.push_back(totalNPV);
    }

    assert(ntupleData.size() == static_cast<unsigned>(nt->GetNvar()));
    nt->Fill(&ntupleData[0]);

    ++counter;
}
void FFTJetPileupAnalyzer::analyzePileup ( const std::vector< PileupSummaryInfo > &  pInfo) [private]

Definition at line 139 of file FFTJetPileupAnalyzer.cc.

References collectOOTPileup, collectPileup, gather_cfg::cout, crazyEnergyCut, PileupSummaryInfo::getBunchCrossing(), PileupSummaryInfo::getPU_NumInteractions(), PileupSummaryInfo::getPU_sumpT_highpT(), PileupSummaryInfo::getPU_sumpT_lowpT(), ntupleData, totalNpu, and verbosePileupInfo.

Referenced by analyze().

{
    const unsigned nBx = info.size();
    if (collectPileup)
        ntupleData.push_back(static_cast<float>(nBx));

    double sumpt_Lo = 0.0, sumpt_Hi = 0.0;
    totalNpu = 0;

    int npu_by_Bx[3] = {0,};
    double sumpt_Lo_by_Bx[3] = {0.0,}, sumpt_Hi_by_Bx[3] = {0.0,};

    if (verbosePileupInfo)
        std::cout << "\n**** Pileup info begin" << std::endl;

    bool isCrazy = false;
    for (unsigned ibx = 0; ibx < nBx; ++ibx)
    {
        const PileupSummaryInfo& puInfo(info[ibx]);

        const int bx = puInfo.getBunchCrossing();
        const int npu = puInfo.getPU_NumInteractions();
        const std::vector<float>& lopt(puInfo.getPU_sumpT_lowpT());
        const std::vector<float>& hipt(puInfo.getPU_sumpT_highpT());
        const double losum = std::accumulate(lopt.begin(), lopt.end(), 0.0);
        const double hisum = std::accumulate(hipt.begin(), hipt.end(), 0.0);

        if (losum >= crazyEnergyCut)
            isCrazy = true;
        if (hisum >= crazyEnergyCut)
            isCrazy = true;

        totalNpu += npu;
        sumpt_Lo += losum;
        sumpt_Hi += hisum;

        const unsigned idx = bx < 0 ? 0U : (bx == 0 ? 1U : 2U);
        npu_by_Bx[idx] += npu;
        sumpt_Lo_by_Bx[idx] += losum;
        sumpt_Hi_by_Bx[idx] += hisum;

        if (verbosePileupInfo)
            std::cout << "ibx " << ibx << " bx " << bx
                      << " npu " << npu << " losum " << losum
                      << " hisum " << hisum
                      << std::endl;
    }

    if (verbosePileupInfo)
        std::cout << "**** Pileup info end\n" << std::endl;

    if (isCrazy)
    {
        totalNpu = -1;
        sumpt_Lo = 0.0;
        sumpt_Hi = 0.0;
        for (unsigned ibx = 0; ibx < 3; ++ibx)
        {
            npu_by_Bx[ibx] = -1;
            sumpt_Lo_by_Bx[ibx] = 0.0;
            sumpt_Hi_by_Bx[ibx] = 0.0;
        }
    }

    if (collectPileup)
    {
        ntupleData.push_back(totalNpu);
        ntupleData.push_back(sumpt_Lo);
        ntupleData.push_back(sumpt_Hi);
    }

    if (collectOOTPileup)
        for (unsigned ibx = 0; ibx < 3; ++ibx)
        {
            ntupleData.push_back(npu_by_Bx[ibx]);
            ntupleData.push_back(sumpt_Lo_by_Bx[ibx]);
            ntupleData.push_back(sumpt_Hi_by_Bx[ibx]);
        }
}
void FFTJetPileupAnalyzer::beginJob ( void  ) [private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 222 of file FFTJetPileupAnalyzer.cc.

References collectFastJetRho, collectGridDensity, collectOOTPileup, collectPileup, collectSummaries, collectVertexInfo, nt, ntupleData, ntupleName, and ntupleTitle.

{
    // Come up with the list of variables
    std::string vars = "cnt:run:event";
    if (collectPileup)
        vars += ":nbx:npu:sumptLowCut:sumptHiCut";
    if (collectOOTPileup)
    {
        vars += ":npu_negbx:sumptLowCut_negbx:sumptHiCut_negbx";
        vars += ":npu_0bx:sumptLowCut_0bx:sumptHiCut_0bx";
        vars += ":npu_posbx:sumptLowCut_posbx:sumptHiCut_posbx";
    }
    if (collectSummaries)
        vars += ":estimate:pileup:uncert:uncertCode";
    if (collectFastJetRho)
        vars += ":fjrho:fjsigma";
    if (collectGridDensity)
        vars += ":gridEtDensity:gridEtDensityMixed";
    if (collectVertexInfo)
        vars += ":nPV";

    // Book the ntuple
    edm::Service<TFileService> fs;
    nt = fs->make<TNtuple>(ntupleName.c_str(), ntupleTitle.c_str(),
                           vars.c_str());
    ntupleData.reserve(nt->GetNvar());
}
void FFTJetPileupAnalyzer::endJob ( void  ) [private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 393 of file FFTJetPileupAnalyzer.cc.

{
}
FFTJetPileupAnalyzer& FFTJetPileupAnalyzer::operator= ( const FFTJetPileupAnalyzer ) [private]

Member Data Documentation

Definition at line 81 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze(), and beginJob().

Definition at line 85 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze(), and beginJob().

Definition at line 84 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze().

Definition at line 79 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze().

Definition at line 83 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze(), analyzePileup(), and beginJob().

Definition at line 82 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze(), analyzePileup(), and beginJob().

Definition at line 80 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze(), and beginJob().

Definition at line 86 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze(), and beginJob().

unsigned long FFTJetPileupAnalyzer::counter [private]

Definition at line 96 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze().

Definition at line 90 of file FFTJetPileupAnalyzer.cc.

Referenced by analyzePileup().

Definition at line 72 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze().

Definition at line 73 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze().

Definition at line 74 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze().

Definition at line 70 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze().

TNtuple* FFTJetPileupAnalyzer::nt [private]

Definition at line 93 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze(), and beginJob().

std::vector<float> FFTJetPileupAnalyzer::ntupleData [private]

Definition at line 92 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze(), analyzePileup(), and beginJob().

std::string FFTJetPileupAnalyzer::ntupleName [private]

Definition at line 77 of file FFTJetPileupAnalyzer.cc.

Referenced by beginJob().

std::string FFTJetPileupAnalyzer::ntupleTitle [private]

Definition at line 78 of file FFTJetPileupAnalyzer.cc.

Referenced by beginJob().

std::string FFTJetPileupAnalyzer::pileupLabel [private]

Definition at line 76 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze().

Definition at line 75 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze().

Definition at line 71 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze().

Definition at line 94 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze(), and analyzePileup().

Definition at line 95 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze().

Definition at line 87 of file FFTJetPileupAnalyzer.cc.

Referenced by analyzePileup().

Definition at line 89 of file FFTJetPileupAnalyzer.cc.

Referenced by analyze().