Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the photon kinematics for the EMCal clusters QA type plots #3175

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions offline/QA/Jet/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ pkginclude_HEADERS = \
TrksInJetQAJetManager.h \
RhosinEvent.h \
JetSeedCount.h \
JetKinematicCheck.h
JetKinematicCheck.h \
photonjetskinematics.h

libjetqa_la_SOURCES = \
ConstituentsinJets.cc\
Expand All @@ -47,7 +48,8 @@ libjetqa_la_SOURCES = \
TrksInJetQAJetManager.cc \
RhosinEvent.cc \
JetSeedCount.cc \
JetKinematicCheck.cc
JetKinematicCheck.cc \
photonjetskinematics.cc

libjetqa_la_LIBADD = \
-L$(libdir) \
Expand Down
220 changes: 220 additions & 0 deletions offline/QA/Jet/photonjetskinematics.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
//____________________________________________________________________________..

#include "photonjetskinematics.h"
#include <fun4all/PHTFileServer.h>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to add include the hist manager here!

Suggested change
// Fun4all includes
#include <fun4all/Fun4AllHistoManager.h>

// Fun4all includes

#include <fun4all/Fun4AllHistoManager.h>

#include <fun4all/Fun4AllReturnCodes.h>

#include <phool/PHCompositeNode.h>

#include <TFile.h>
#include <phool/getClass.h>
#include "TH1.h"
#include "TMath.h"
//#include <jetbase/JetContainer.h>


// Tower includes
#include <calobase/RawCluster.h>
#include <calobase/RawClusterContainer.h>
#include <calobase/RawClusterUtility.h>
#include <calobase/RawTower.h>
#include <calobase/RawTowerContainer.h>
#include <calobase/RawTowerGeom.h>
#include <calobase/RawTowerGeomContainer.h>
#include <calobase/TowerInfo.h>
#include <calobase/TowerInfoContainer.h>
#include <calobase/TowerInfoDefs.h>

// Cluster includes
#include <calobase/RawCluster.h>
#include <calobase/RawClusterContainer.h>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we'll need to include the QA hist manager!

Suggested change
// QA includes
#include <qautils/QAHistManagerDef.h>

// QA includes
#include <qautils/QAHistManagerDef.h>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll also need a few standard headers as well...

Suggested change
// c++ includes
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

// c++ includes
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
//____________________________________________________________________________..

photonjetskinematics::photonjetskinematics(const std::string &m_modulename, const std::string &m_inputnode) :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies! I should've been more clear: the m_ is for variables that are class members (e.g. the ones starting at line 75 of the .h file), and then the arguments here usually aren't prefixed by anything😅

SubsysReco(m_modulename)
, modulename(m_modulename)
, inputnode(m_inputnode)
, histtag("AllTrig")
, trgToSelect(JetQADefs::GL1::MBDNSJet1)
, doTrgSelect(false)
Comment on lines +48 to +53
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we'll need to initialize manager, so something like so:

Suggested change
SubsysReco(m_modulename)
, modulename(m_modulename)
, inputnode(m_inputnode)
, histtag("AllTrig")
, trgToSelect(JetQADefs::GL1::MBDNSJet1)
, doTrgSelect(false)
SubsysReco(m_modulename)
, modulename(m_modulename)
, inputnode(m_inputnode)
, histtag("AllTrig")
, trgToSelect(JetQADefs::GL1::MBDNSJet1)
, doTrgSelect(false)
, manager(nullptr)

{
if (Verbosity() > 1) std::cout << "photonjetskinematics::photonjetskinematics(const std::string &name, const std::string&outputfilename) Calling ctor" << std::endl;
}
//____________________________________________________________________________..
photonjetskinematics::~photonjetskinematics()
{
std::cout << "photonjetskinematics::~photonjetskinematics() Calling dtor" << std::endl;
}

//____________________________________________________________________________..
int photonjetskinematics::Init(PHCompositeNode* /*topNode*/)
{
if (Verbosity() > 1) std::cout << "photonjetskinematics::Init(PHCompositeNode *topNode) Initializing" << std::endl;
manager = QAHistManagerDef::getHistoManager();
if (!manager)
{
std::cerr << PHWHERE << "PANIC: couldn't grab histogram manager!" << std::endl;
assert(manager);
}

// make sure module name is lower case
std::string smallModuleName = modulename;
std::transform(
smallModuleName.begin(),
smallModuleName.end(),
smallModuleName.begin(),
::tolower);
// construct histogram names
std::vector<std::string> vecHistNames = {
"emcal_cluster_chi2",
"emcal_cluster_energy",
"emcal_cluster_eta_phi",
"emcal_cluster_eta",
"emcal_cluster_phi"};

for (auto& histName : vecHistNames)
{
histName.insert(0, "h_" + smallModuleName + "_");
if (!histtag.empty())
{
histName.append("_" + histtag);
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following suggestion is for making sure the histogram names conform to the same pattern that most of the other modules follow: h_<module name>_<what it is>_<additional tags>. The first chunk just makes sure that the module name is all lower-case, and the second chunk systematically makes sure each histogram has the same prefix and suffix.

Suggested change
// make sure module name is lower case
std::string smallModuleName = modulename;
std::transform(
smallModuleName.begin(),
smallModuleName.end(),
smallModuleName.begin(),
::tolower);
// construct histogram names
std::vector<std::string> vecHistNames = {
"emcal_cluster_chi2",
"emcal_cluster_energy",
"emcal_cluster_eta_phi",
"emcal_cluster_eta",
"emcal_cluster_phi"};
for (auto& histName : vecHistName)
{
histName.insert(0, "h_" + smallModuleName + "_");
if (!histtag.empty())
{
histName.append("_" + histtag);
}
}

//initializing histograms

h_emcal_cluster_chi2 = new TH1D(vecHistNames[0].data(), "h_emcal_cluster_chi2", 30, 0, 150);
h_emcal_cluster_chi2->GetXaxis()->SetTitle("#chi^{2}");

h_emcal_cluster_energy = new TH1D(vecHistNames[1].data(), "h_emcal_cluster_energy", 100, 0, 10);
h_emcal_cluster_energy->GetXaxis()->SetTitle("E_{T} [GeV]");

h_emcal_cluster_eta_phi = new TH2F(vecHistNames[2].data(), "h_emcal_cluster_eta_phi", 140, -1.2, 1.2, 64, -M_PI, M_PI);
h_emcal_cluster_eta_phi->GetXaxis()->SetTitle("#eta");
h_emcal_cluster_eta_phi->GetYaxis()->SetTitle("#Phi");
h_emcal_cluster_eta_phi->SetOption("COLZ");

h_emcal_cluster_eta = new TH1D(vecHistNames[3].data(), "Eta Distribution", 140, -1.2, 1.2);
h_emcal_cluster_eta->GetXaxis()->SetTitle("#eta");

h_emcal_cluster_phi = new TH1D(vecHistNames[4].data(), "Phi Distribution", 64, -M_PI, M_PI);
h_emcal_cluster_phi->GetXaxis()->SetTitle("#phi");

return Fun4AllReturnCodes::EVENT_OK;

}

//____________________________________________________________________________..
int photonjetskinematics::InitRun(PHCompositeNode* /*topNode*/)
{

if (Verbosity() > 1) std::cout << "photonjetskinematics::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << std::endl;
return Fun4AllReturnCodes::EVENT_OK;
}

//____________________________________________________________________________..
int photonjetskinematics::process_event(PHCompositeNode *topNode)
{

RawClusterContainer* clusterContainer = findNode::getClass<RawClusterContainer>(topNode, inputnode);
if (!clusterContainer)
{
std::cout << PHWHERE << "funkyCaloStuff::process_event - Fatal Error - CLUSTER_CEMC node is missing. " << std::endl;
return 0;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to add a chunk of code here to filter out events which don't have the trigger we're interested in if we're applying a trigger selection.

Suggested change
// if needed, check if trigger fired
if (doTrgSelect)
{
bool hasTrigger = JetQADefs::DidTriggerFire(trgToSelect, topNode);
if (!hasTrigger)
{
return Fun4AllCodes::EVENT_OK;
}
}

// if needed, check if trigger fired
if (doTrgSelect)
{
bool hasTrigger = JetQADefs::DidTriggerFire(trgToSelect, topNode);
if (!hasTrigger)
{
return Fun4AllReturnCodes::EVENT_OK;
}
}

RawClusterContainer::ConstIterator clusterIter;
RawClusterContainer::ConstRange clusterEnd = clusterContainer->getClusters();

for (clusterIter = clusterEnd.first; clusterIter != clusterEnd.second; clusterIter++)
{
RawCluster* recoCluster = clusterIter->second;
CLHEP::Hep3Vector vertex(0, 0, 0);
CLHEP::Hep3Vector E_vec_cluster = RawClusterUtility::GetECoreVec(*recoCluster, vertex);

float clusE = E_vec_cluster.mag();
float clus_eta = E_vec_cluster.pseudoRapidity();
float clus_phi = E_vec_cluster.phi();
float clus_chisq = recoCluster->get_chi2();

//Filling Histograms, only taking into account E vec cluster, not reco cluster

h_emcal_cluster_chi2->Fill(clus_chisq);
h_emcal_cluster_energy->Fill(clusE);
h_emcal_cluster_eta_phi->Fill(clus_eta, clus_phi);
h_emcal_cluster_eta->Fill(clus_eta); // 1D eta plot
h_emcal_cluster_phi->Fill(clus_phi); // 1D phi plot
}

// std::cout << "photonjetskinematics::process_event(PHCompositeNode *topNode) Processing Event" << std::endl;
return Fun4AllReturnCodes::EVENT_OK;
}

//____________________________________________________________________________..
int photonjetskinematics::ResetEvent(PHCompositeNode* /*topNode*/)
{
// std::cout << "photonjetskinematics::ResetEvent(PHCompositeNode *topNode) Resetting internal structures, prepare for next event" << std::endl;
return Fun4AllReturnCodes::EVENT_OK;
}

//____________________________________________________________________________..
int photonjetskinematics::EndRun(const int runnumber)
{
if (Verbosity() > 1) std::cout << "photonjetskinematics::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
return Fun4AllReturnCodes::EVENT_OK;
}

//____________________________________________________________________________..
int photonjetskinematics::End(PHCompositeNode* /*topNode*/)
{
// Commenting out the following line because Jenkins keeps failing the build test :(
// if (Verbosity() > 1) std::cout << "photonjetskinematics::End - Output to " << outfilename << std::endl;

//Outputting the histograms
manager->registerHisto(h_emcal_cluster_eta_phi);
manager->registerHisto(h_emcal_cluster_energy);
manager->registerHisto(h_emcal_cluster_chi2);
manager->registerHisto(h_emcal_cluster_eta);
manager->registerHisto(h_emcal_cluster_phi);

if (Verbosity() > 1) std::cout << "photonjetskinematics::End(PHCompositeNode *topNode) This is the End..." << std::endl;
return Fun4AllReturnCodes::EVENT_OK;

}

//____________________________________________________________________________..
int photonjetskinematics::Reset(PHCompositeNode* /*topNode*/)
{
if (Verbosity() > 1) std::cout << "photonjetskinematics::Reset(PHCompositeNode *topNode) being Reset" << std::endl;
return Fun4AllReturnCodes::EVENT_OK;
}

//____________________________________________________________________________..
void photonjetskinematics::Print(const std::string &what) const
{
if (Verbosity() > 1) std::cout << "photonjetskinematics::Print(const std::string &what) const Printing info for " << what << std::endl;
}
94 changes: 94 additions & 0 deletions offline/QA/Jet/photonjetskinematics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Tell emacs that this is a C++ source
// -*- C++ -*-.
#ifndef PHOTONJETSKINEMATICS_H
#define PHOTONJETSKINEMATICS_H

#include <fun4all/SubsysReco.h>

#include <string>
#include <TFile.h>
#include <TH1.h>
#include <TH2D.h>
#include "JetQADefs.h"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need this for the trigger indices.

Suggested change
#include "JetQADefs.h"

class Fun4AllHistoManager;
class PHCompositeNode;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to do a forward declaration for the hist manager...

Suggested change
class PHCompositeNode;
class Fun4AllHistoManager;
class PHCompositeNode;

class TH1;
class TH2;
class TH3;

class photonjetskinematics : public SubsysReco
{
public:


photonjetskinematics(const std::string &modulename = "photonjetskinematics", const std::string &inputnode = "CLUSTERINFO_CEMC");
~photonjetskinematics() override;

/** Called during initialization.
Typically this is where you can book histograms, and e.g.
register them to Fun4AllServer (so they can be output to file
using Fun4AllServer::dumpHistos() method).
*/
int Init(PHCompositeNode *topNode) override;

/** Called for first event when run number is known.
Typically this is where you may want to fetch data from
database, because you know the run number. A place
to book histograms which have to know the run number.
*/
int InitRun(PHCompositeNode *topNode) override;

/** Called for each event.
This is where you do the real work.
*/
int process_event(PHCompositeNode *topNode) override;

/// Clean up internals after each event.
int ResetEvent(PHCompositeNode *topNode) override;

/// Called at the end of each run.
int EndRun(const int runnumber) override;

/// Called at the end of all processing.
int End(PHCompositeNode *topNode) override;

/// Reset
int Reset(PHCompositeNode * /*topNode*/) override;

void Print(const std::string &what = "ALL") const override;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just in case we want to check this as a function of trigger type (e.g. Photon5), we'll need some way to set which trigger to select.

Suggested change
/// specifies a trigger to select
void SetTrgToSelect(const uitn32_t trig = JetQADefs::GL1::MBDNSPhoton1)
{
doTrgSelect = true;
trgToSelect = trig;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want to be able to add additional tags to histogram names to label things (e.g. if we're selecting a particular trigger), so we'll need to add a setter.

Suggested change
/// set histogram tag
void SetHistTag(const std::string& tag)
{
histtag = tag;
}

/// specifies a trigger to select
void SetTrgToSelect(const uint32_t trig = JetQADefs::GL1::MBDNSPhoton1)
{
doTrgSelect = true;
trgToSelect = trig;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want to add a few members here for bookkeeping:

  • 1st is that we'll need to keep the module name on hand for making histogram names: this will help us keep track of what histograms are coming from which modules!
  • 2nd is that we might need to change the input node.
  • 3rd is that we might need to add a tag to a histogram.
  • And then we'll need to know if we're selecting triggers (doTrgSelect) and, if we are, which one (trgToSelect).
Suggested change
std::string modulename;
std::string inputnode;
std::string histtag;
uint32_t trgToSelect;
bool doTrgSelect;

/// set histogram tag
void SetHistTag(const std::string& tag)
{
histtag = tag;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need the hist manager to collect the output histograms...

Suggested change
// hist manager
Fun4AllHistoManager* manager;

private:
// std::string outfilename;
// TFile *outfile;
// hist manager

Fun4AllHistoManager* manager;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So (hopefully 🤞) this is the last issue: manager not being initialized in the constructor is throwing a warning on Jenkins... I'll add a comment where this needs to be added.

std::string modulename;
std::string inputnode;
std::string histtag;
uint32_t trgToSelect;
bool doTrgSelect;

///Output histograms
TH1 *h_emcal_cluster_chi2 = nullptr;
TH1 *h_emcal_cluster_energy = nullptr;
TH2 *h_emcal_cluster_eta_phi = nullptr;
TH1 *h_emcal_cluster_eta = nullptr; // <-- Declare eta histogram
TH1 *h_emcal_cluster_phi = nullptr; // <-- Declare phi histogram
};

#endif // PHOTONJETSKINEMATICS_H