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

bsunanda:Run2-sim04 Adding a dumping analyzer to diagnose if o/p is created using TestNumbering or not for HCAL #17800

Merged
merged 2 commits into from Mar 9, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 1 addition & 7 deletions SimG4CMS/Calo/test/BuildFile.xml
Expand Up @@ -14,11 +14,5 @@
<use name="root"/>
<use name="clhep"/>
<flags EDM_PLUGIN="1"/>
<library file="CaloSimHitStudy.cc" name="testCaloSimHits">
</library>
<library file="HOSimHitStudy.cc" name="testCaloHOSimHits">
</library>
<library file="HFPMTHitAnalyzer.cc" name="testCaloHFPMTHitAnalyzer">
</library>
<library file="HitParentTest.cc" name="testCaloHitParentTest">
<library file="*.cc" name="testCaloSimHits">
</library>
125 changes: 125 additions & 0 deletions SimG4CMS/Calo/test/HcalSimHitDump.cc
@@ -0,0 +1,125 @@
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "DataFormats/HcalDetId/interface/HcalDetId.h"
#include "DataFormats/HcalDetId/interface/HcalTestNumbering.h"
#include "SimDataFormats/CaloHit/interface/PCaloHit.h"
#include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
#include "SimG4CMS/Calo/interface/CaloHitID.h"
#include "SimDataFormats/TrackingHit/interface/PSimHit.h"
#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"

#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"

#include <memory>
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <string>

class HcalSimHitDump: public edm::EDAnalyzer{
public:

HcalSimHitDump(const edm::ParameterSet& ps);
~HcalSimHitDump() {}

protected:

void beginJob () {}
void endJob () {}
void analyze (const edm::Event& e, const edm::EventSetup& c);

void analyzeHits (std::vector<PCaloHit> &);

private:

std::string g4Label_, hitLab_;
edm::EDGetTokenT<edm::PCaloHitContainer> toks_calo_;
int nevt_, maxEvent_;
};


HcalSimHitDump::HcalSimHitDump(const edm::ParameterSet& ps) : nevt_(0) {

g4Label_ = ps.getUntrackedParameter<std::string>("ModuleLabel","g4SimHits");
hitLab_ = ps.getUntrackedParameter<std::string>("HCCollection","HcalHits");
maxEvent_ = ps.getUntrackedParameter<int>("MaxEvent", 10);

// register for data access
toks_calo_ = consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_,hitLab_));

edm::LogInfo("HitStudy") << "Module Label: " << g4Label_ << " Hits: "
<< hitLab_ << " MzEvent " << maxEvent_;
}

void HcalSimHitDump::analyze(const edm::Event& e, const edm::EventSetup& ) {

++nevt_;
edm::LogInfo("HitStudy") << "Serial # " << nevt_ << " Run # "
<< e.id().run() << " Event # " << e.id().event();

if (nevt_ <= maxEvent_) {
std::vector<PCaloHit> hcHits;
edm::Handle<edm::PCaloHitContainer> hitsCalo;
e.getByToken(toks_calo_,hitsCalo);
if (hitsCalo.isValid()) {
edm::LogInfo("HitStudy") << "HcalValidation: get valid hist for Hcal";
std::vector<PCaloHit> caloHits;
caloHits.insert(caloHits.end(),hitsCalo->begin(),hitsCalo->end());
edm::LogInfo("HitStudy") << "HcalValidation: Hit buffer "
<< caloHits.size();
analyzeHits (caloHits);
}
}
}

void HcalSimHitDump::analyzeHits (std::vector<PCaloHit>& hits) {

bool testN(false);
for (unsigned int k=1; k<hits.size(); ++k) {
int det = (((hits[k].id())>>28)&0xF);
if (det != 4) {testN = true; break;}
}
edm::LogInfo("HitStudy") << "Hit ID uses numbering scheme " << testN
<< " (0 normal; 1 test)";

//Now the dump
for (unsigned int i=0; i<hits.size(); i++) {
double edep = hits[i].energy();
double time = hits[i].time();
unsigned int id_ = hits[i].id();
if (testN) {
int det, z, depth, eta, phi, lay;
HcalTestNumbering::unpackHcalIndex(id_, det, z, depth, eta, phi, lay);
std::string sub("HX");
if (det == 1) sub = "HB";
else if (det == 2) sub = "HE";
else if (det == 3) sub = "HO";
else if (det == 4) sub = "HF";
else if (det == 5) sub = "HT";
int side = (z==0) ? (-1) : (1);
edm::LogVerbatim("HitStudy") << "[" << i << "] (" << sub << " "
<< side*eta << "," << phi << "," << depth
<< "," << lay << ") E " << edep << " T "
<< time;
} else {
edm::LogVerbatim("HitStudy") << "[" << i << "] " << HcalDetId(id_)
<< " E " << edep << " T " << time;
}
}
}

//define this as a plug-in
DEFINE_FWK_MODULE(HcalSimHitDump);

50 changes: 50 additions & 0 deletions SimG4CMS/Calo/test/python/runHcalSimHitDump_cfg.py
@@ -0,0 +1,50 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("Sim")
process.load("SimG4CMS.Calo.PythiaMinBias_cfi")
process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi")
process.load("Configuration.Geometry.GeometryExtended2017Reco_cff")
process.load("Configuration.StandardSequences.MagneticField_cff")
process.load("Configuration.EventContent.EventContent_cff")
process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
from Configuration.AlCa.autoCond import autoCond
process.GlobalTag.globaltag = autoCond['phase1_2017_design']

process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring(
'root://xrootd.unl.edu//store/mc/Phys14DR/DYToMuMu_M-50_Tune4C_13TeV-pythia8/GEN-SIM-RECO/PU20bx25_tsg_castor_PHYS14_25_V1-v1/10000/184C1AC9-A775-E411-9196-002590200824.root'
# 'file:/afs/cern.ch/user/a/amkalsi/public/ForSunandaDa/024A536E-48EE-E611-843A-001E67E71C95.root'
)
)

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(200)
)

process.MessageLogger = cms.Service("MessageLogger",
destinations = cms.untracked.vstring('cout'),
categories = cms.untracked.vstring('HitStudy'),
cout = cms.untracked.PSet(
default = cms.untracked.PSet(
limit = cms.untracked.int32(0)
),
HitStudy = cms.untracked.PSet(
limit = cms.untracked.int32(-1)
),
)
)

process.load("IOMC.RandomEngine.IOMC_cff")
process.RandomNumberGeneratorService.generator.initialSeed = 456789
process.RandomNumberGeneratorService.g4SimHits.initialSeed = 9876
process.RandomNumberGeneratorService.VtxSmeared.initialSeed = 123456789
process.rndmStore = cms.EDProducer("RandomEngineStateProducer")

process.analyze = cms.EDAnalyzer("HcalSimHitDump",
ModuleLabel = cms.untracked.string('g4SimHits'),
HCCollection = cms.untracked.string('HcalHits'),
MaxEvent = cms.untracked.int32(20)
)

process.schedule = cms.Path(process.analyze)