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

Gem online dqm #22500

Merged
merged 5 commits into from Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions DQM/GEM/BuildFile.xml
@@ -0,0 +1,3 @@
<export>
<lib name="1"/>
</export>
20 changes: 20 additions & 0 deletions DQM/GEM/plugins/BuildFile.xml
@@ -0,0 +1,20 @@
<library file="*.cc" name="DQMGEMPlugins">
<flags EDM_PLUGIN="1"/>

<use name="FWCore/Framework"/>
<use name="FWCore/ParameterSet"/>
<use name="FWCore/Utilities"/>

<use name="DQMServices/Core"/>

<use name="DataFormats/Common"/>
<use name="DataFormats/MuonDetId"/>
<use name="DataFormats/GEMDigi"/>
<use name="DataFormats/GEMRecHit"/>

<use name="Geometry/Records"/>
<use name="Geometry/CommonDetUnit"/>
<use name="Geometry/GEMGeometry"/>

<use name="DQM/GEM"/>
</library>
148 changes: 148 additions & 0 deletions DQM/GEM/plugins/GEMDQMHarvester.cc
@@ -0,0 +1,148 @@
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Framework/interface/ESHandle.h"

//DQM services
#include "DQMServices/Core/interface/DQMStore.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "DQMServices/Core/interface/MonitorElement.h"
#include "DQMServices/Core/interface/DQMEDHarvester.h"

#include <iostream>
#include <cstdlib>
#include <string>
#include <memory>
#include <vector>

#include "TString.h"
#include "Geometry/GEMGeometry/interface/GEMGeometry.h"
#include "Geometry/Records/interface/MuonGeometryRecord.h"

using namespace std;
using namespace edm;

class GEMDQMHarvester: public DQMEDHarvester
{
public:

GEMDQMHarvester(const edm::ParameterSet&);
~GEMDQMHarvester() override;

protected:
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override {}

void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, const edm::LuminosityBlock &, const edm::EventSetup &) override;


private:

void prova(DQMStore::IBooker &ibooker, edm::Run const &, edm::EventSetup const & iSetup);
std::string fName;
int verbosity;
DQMStore *dbe;
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove this pointer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was done. This moment we don't use harvester, so I removed all useless things.


const GEMGeometry* initGeometry(edm::EventSetup const & iSetup);
int findVFAT(float min_, float max_, float x_, int roll_);

const GEMGeometry* GEMGeometry_;

std::vector<GEMChamber> gemChambers;

int nCh;

std::unordered_map<UInt_t, MonitorElement*> Eff_Strips_vs_eta;

};

int GEMDQMHarvester::findVFAT(float min_, float max_, float x_, int roll_) {
float step = abs(max_-min_)/3.0;
if ( x_ < (min(min_,max_)+step) ) { return 8 - roll_;}
else if ( x_ < (min(min_,max_)+2.0*step) ) { return 16 - roll_;}
else { return 24 - roll_;}
}

const GEMGeometry* GEMDQMHarvester::initGeometry(edm::EventSetup const & iSetup) {
const GEMGeometry* GEMGeometry_ = nullptr;
try {
edm::ESHandle<GEMGeometry> hGeom;
iSetup.get<MuonGeometryRecord>().get(hGeom);
GEMGeometry_ = &*hGeom;
}
catch( edm::eventsetup::NoProxyException<GEMGeometry>& e) {
edm::LogError("MuonGEMBaseValidation") << "+++ Error : GEM geometry is unavailable on event loop. +++\n";
return nullptr;
}

return GEMGeometry_;
}


GEMDQMHarvester::GEMDQMHarvester(const edm::ParameterSet& ps)
{
// fName = ps.getUntrackedParameter<std::string>("Name");

//dbe_path_ = std::string("GEMDQM/");
//outputFile_ = ps.getUntrackedParameter<std::string>("outputFile", "myfile.root");
}

GEMDQMHarvester::~GEMDQMHarvester()
{

}

void GEMDQMHarvester::prova(DQMStore::IBooker &ibooker, edm::Run const &, edm::EventSetup const & iSetup)
{

GEMGeometry_ = initGeometry(iSetup);
if ( GEMGeometry_ == nullptr) return ;

const std::vector<const GEMSuperChamber*>& superChambers_ = GEMGeometry_->superChambers();
for (auto sch : superChambers_){
int n_lay = sch->nChambers();
for (int l=0;l<n_lay;l++){
gemChambers.push_back(*sch->chamber(l+1));
}
}
nCh = gemChambers.size();
ibooker.cd();
ibooker.setCurrentFolder("GEM/eff");
for (auto ch : gemChambers){
GEMDetId gid = ch.id();
string hName_eff = "Eff_Strip_Gemini_"+to_string(gid.superChamberId())+"_la_"+to_string(gid.layer());
string hTitle_eff = "Eff Strips Gemini ID : "+to_string(gid.superChamberId())+", layer : "+to_string(gid.layer());
Eff_Strips_vs_eta[ ch.id() ] = ibooker.book2D(hName_eff, hTitle_eff, 384, 1, 385, 8, 1,9);
//TH2F *hist_2 = Eff_Strips_vs_eta[ ch.id() ]->getTH2F();
//hist_2->SetMarkerStyle(20);
//hist_2->SetMarkerSize(0.5);
}

// MonitorElement* eta_1 = igetter.get("/GEM/testEta");
// MonitorElement* eta_2 = igetter.get("/GEM/testEta_2");
// MonitorElement* eff = igetter.get("/GEM/prova/eff");
//
// for(int i = 0; i < eta_1->getNbinsX(); i++){
// if(eta_2->getBinContent(i) == 0)
// eff->setBinContent(i, 0);
// else{
// double r = eta_1->getBinContent(i) / eta_2->getBinContent(i);
// eff->setBinContent(i, r);
// }
// }
}

void GEMDQMHarvester::dqmEndLuminosityBlock(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, const edm::LuminosityBlock &, const edm::EventSetup &)
{
}

//void GEMDQMHarvestor::dqmEndJob(DQMStore::IBooker & ibooker, DQMStore::IGetter &ig )
//{
//ig.setCurrentFolder(dbe_path_.c_str());

//}
DEFINE_FWK_MODULE(GEMDQMHarvester);
211 changes: 211 additions & 0 deletions DQM/GEM/plugins/GEMDQMSource.cc
@@ -0,0 +1,211 @@
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/PluginManager/interface/ModuleDef.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"


#include "DQMServices/Core/interface/DQMEDAnalyzer.h"
#include "DQMServices/Core/interface/DQMStore.h"
#include "DQMServices/Core/interface/MonitorElement.h"

#include "DataFormats/GEMRecHit/interface/GEMRecHit.h"
#include "DataFormats/GEMRecHit/interface/GEMRecHitCollection.h"
#include "DataFormats/GEMDigi/interface/GEMDigiCollection.h"

#include "Geometry/GEMGeometry/interface/GEMGeometry.h"
#include "Geometry/Records/interface/MuonGeometryRecord.h"

#include <string>

//----------------------------------------------------------------------------------------------------

class GEMDQMSource: public DQMEDAnalyzer
{
public:
GEMDQMSource(const edm::ParameterSet& cfg);
~GEMDQMSource() override;

protected:
void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override;
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
void analyze(edm::Event const& e, edm::EventSetup const& eSetup) override;
void beginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& eSetup) override;
void endLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& eSetup) override;
void endRun(edm::Run const& run, edm::EventSetup const& eSetup) override;

private:
unsigned int verbosity;

int nCh;

edm::EDGetToken tagRecHit;

const GEMGeometry* initGeometry(edm::EventSetup const & iSetup);
int findVFAT(float min_, float max_, float x_, int roll_);

const GEMGeometry* GEMGeometry_;

std::vector<GEMChamber> gemChambers;

std::unordered_map<UInt_t, MonitorElement*> recHitME;
std::unordered_map<UInt_t, MonitorElement*> VFAT_vs_ClusterSize;
std::unordered_map<UInt_t, MonitorElement*> StripsFired_vs_eta;
std::unordered_map<UInt_t, MonitorElement*> rh_vs_eta;

};

//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------

using namespace std;
using namespace edm;

int GEMDQMSource::findVFAT(float min_, float max_, float x_, int roll_) {
float step = abs(max_-min_)/3.0;
if ( x_ < (min(min_,max_)+step) ) { return 8 - roll_;}
else if ( x_ < (min(min_,max_)+2.0*step) ) { return 16 - roll_;}
else { return 24 - roll_;}
}

const GEMGeometry* GEMDQMSource::initGeometry(edm::EventSetup const & iSetup) {
const GEMGeometry* GEMGeometry_ = nullptr;
try {
edm::ESHandle<GEMGeometry> hGeom;
iSetup.get<MuonGeometryRecord>().get(hGeom);
GEMGeometry_ = &*hGeom;
}
catch( edm::eventsetup::NoProxyException<GEMGeometry>& e) {
edm::LogError("MuonGEMBaseValidation") << "+++ Error : GEM geometry is unavailable on event loop. +++\n";
return nullptr;
}

return GEMGeometry_;
}


//----------------------------------------------------------------------------------------------------
GEMDQMSource::GEMDQMSource(const edm::ParameterSet& cfg)
{

tagRecHit = consumes<GEMRecHitCollection>(cfg.getParameter<edm::InputTag>("recHitsInputLabel"));

}

//----------------------------------------------------------------------------------------------------

GEMDQMSource::~GEMDQMSource()
{
}

//----------------------------------------------------------------------------------------------------

void GEMDQMSource::dqmBeginRun(edm::Run const &, edm::EventSetup const &)
{
}

//----------------------------------------------------------------------------------------------------

void GEMDQMSource::bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &, edm::EventSetup const & iSetup)
{

GEMGeometry_ = initGeometry(iSetup);
if ( GEMGeometry_ == nullptr) return ;

const std::vector<const GEMSuperChamber*>& superChambers_ = GEMGeometry_->superChambers();
for (auto sch : superChambers_){
int n_lay = sch->nChambers();
for (int l=0;l<n_lay;l++){
gemChambers.push_back(*sch->chamber(l+1));
}
}
nCh = gemChambers.size();
ibooker.cd();
ibooker.setCurrentFolder("GEM/recHit");
for (auto ch : gemChambers){
GEMDetId gid = ch.id();
string hName = "recHit_Gemini_"+to_string(gid.chamber())+"_la_"+to_string(gid.layer());
string hTitle = "recHit Gemini chamber : "+to_string(gid.chamber())+", layer : "+to_string(gid.layer());
recHitME[ ch.id() ] = ibooker.book1D(hName, hTitle, 24,0,24);

string hName_2 = "VFAT_vs_ClusterSize_Gemini_"+to_string(gid.chamber())+"_la_"+to_string(gid.layer());
string hTitle_2 = "VFAT vs ClusterSize Gemini chamber : "+to_string(gid.chamber())+", layer : "+to_string(gid.layer());
VFAT_vs_ClusterSize[ ch.id() ] = ibooker.book2D(hName_2, hTitle_2, 9, 1, 10, 24, 0, 24);

string hName_fired = "StripFired_Gemini_"+to_string(gid.chamber())+"_la_"+to_string(gid.layer());
string hTitle_fired = "StripsFired Gemini chamber : "+to_string(gid.chamber())+", layer : "+to_string(gid.layer());
StripsFired_vs_eta[ ch.id() ] = ibooker.book2D(hName_fired, hTitle_fired, 384, 1, 385, 8, 1,9);

string hName_rh = "recHit_x_Gemini_"+to_string(gid.chamber())+"_la_"+to_string(gid.layer());
string hTitle_rh = "recHit local x Gemini chamber : "+to_string(gid.chamber())+", layer : "+to_string(gid.layer());
rh_vs_eta[ ch.id() ] = ibooker.book2D(hName_rh, hTitle_rh, 50, -25, 25, 8, 1,9);


}

}

//----------------------------------------------------------------------------------------------------

void GEMDQMSource::beginLuminosityBlock(edm::LuminosityBlock const& lumiSeg,
edm::EventSetup const& context)
{
}

//----------------------------------------------------------------------------------------------------

void GEMDQMSource::analyze(edm::Event const& event, edm::EventSetup const& eventSetup)
{
const GEMGeometry* GEMGeometry_ = initGeometry(eventSetup);
if ( GEMGeometry_ == nullptr) return;



////////////////
//// RecHit ////
////////////////
edm::Handle<GEMRecHitCollection> gemRecHits;
event.getByToken( this->tagRecHit, gemRecHits);
if (!gemRecHits.isValid()) {
edm::LogError("GEMDQMSource") << "GEM recHit is not valid.\n";
return ;
}
for (auto ch : gemChambers){
GEMDetId cId = ch.id();
for(auto roll : ch.etaPartitions()){
GEMDetId rId = roll->id();
const auto& recHitsRange = gemRecHits->get(rId);
auto gemRecHit = recHitsRange.first;
for ( auto hit = gemRecHit; hit != recHitsRange.second; ++hit ) {
int nVfat = findVFAT(1.0, 385.0, hit->firstClusterStrip()+0.5*hit->clusterSize(), rId.roll());
recHitME[ cId ]->Fill(nVfat);
rh_vs_eta[ cId ]->Fill(hit->localPosition().x(), rId.roll());
VFAT_vs_ClusterSize[ cId ]->Fill(hit->clusterSize(), nVfat);
for(int i = hit->firstClusterStrip(); i < (hit->firstClusterStrip() + hit->clusterSize()); i++){
StripsFired_vs_eta[ cId ]->Fill(i, rId.roll());
}
}
}
}


}

//----------------------------------------------------------------------------------------------------

void GEMDQMSource::endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& eSetup)
{
}

//----------------------------------------------------------------------------------------------------

void GEMDQMSource::endRun(edm::Run const& run, edm::EventSetup const& eSetup)
{
}

//----------------------------------------------------------------------------------------------------

DEFINE_FWK_MODULE(GEMDQMSource);