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

Hf shower library update #16049

Merged
merged 2 commits into from
Sep 30, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SimG4CMS/Calo/interface/HFShowerLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class HFShowerLibrary {
TFile * hf;
TBranch *emBranch, *hadBranch;

bool verbose, applyFidCut, newForm;
bool verbose, applyFidCut, newForm, v3version;
int nMomBin, totEvents, evtPerBin;
float libVers, listVersion;
std::vector<double> pmom;
Expand Down
60 changes: 48 additions & 12 deletions SimG4CMS/Calo/src/HFShowerLibrary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ HFShowerLibrary::HFShowerLibrary(std::string & name, const DDCompactView & cpv,
nameBr = branchPre + hadName + branchPost;
hadBranch = event->GetBranch(nameBr.c_str());
if (verbose) hadBranch->Print();

v3version=false;
if ( emBranch->GetClassName() == std::string("vector<float>") ) {
v3version=true;
}


edm::LogInfo("HFShower") << "HFShowerLibrary:Branch " << emName
<< " has " << emBranch->GetEntries()
<< " entries and Branch " << hadName
Expand All @@ -118,9 +125,9 @@ HFShowerLibrary::HFShowerLibrary(std::string & name, const DDCompactView & cpv,
}

HFShowerLibrary::~HFShowerLibrary() {
if (hf) { hf->Close(); }
delete fibre;
delete photo;
if (hf) hf->Close();
if (fibre) delete fibre; fibre = 0;
if (photo) delete photo;
}

void HFShowerLibrary::initRun(G4ParticleTable * theParticleTable,
Expand Down Expand Up @@ -372,11 +379,14 @@ std::vector<HFShowerLibrary::Hit> HFShowerLibrary::fillHits(G4ThreeVector & hitP
if (nHit > npe && !onlyLong)
edm::LogWarning("HFShower") << "HFShowerLibrary: Hit buffer " << npe
<< " smaller than " << nHit << " Hits";
return hit;
return hit;

}

bool HFShowerLibrary::rInside(double r) {
return (r >= rMin && r <= rMax);

if (r >= rMin && r <= rMax) return true;
else return false;
}

void HFShowerLibrary::getRecord(int type, int record) {
Expand All @@ -386,19 +396,46 @@ void HFShowerLibrary::getRecord(int type, int record) {
photo->clear();
if (type > 0) {
if (newForm) {
hadBranch->SetAddress(&photo);
hadBranch->GetEntry(nrc+totEvents);
if ( !v3version ) {
hadBranch->SetAddress(&photo);
hadBranch->GetEntry(nrc+totEvents);
}
else{
std::vector<float> t;
std::vector<float> *tp=&t;
hadBranch->SetAddress(&tp);
hadBranch->GetEntry(nrc+totEvents);
unsigned int tSize=t.size()/5;
photo->reserve(tSize);
for ( unsigned int i=0; i<tSize; i++ ) {
photo->push_back( HFShowerPhoton( t[i], t[1*tSize+i], t[2*tSize+i], t[3*tSize+i], t[4*tSize+i] ) );
}
}
} else {
hadBranch->SetAddress(&photon);
hadBranch->GetEntry(nrc);
}
} else {
if (newForm) {
emBranch->SetAddress(&photo);
if (!v3version) {
emBranch->SetAddress(&photo);
emBranch->GetEntry(nrc);
}
else{
std::vector<float> t;
std::vector<float> *tp=&t;
emBranch->SetAddress(&tp);
emBranch->GetEntry(nrc);
unsigned int tSize=t.size()/5;
photo->reserve(tSize);
for ( unsigned int i=0; i<tSize; i++ ) {
photo->push_back( HFShowerPhoton( t[i], t[1*tSize+i], t[2*tSize+i], t[3*tSize+i], t[4*tSize+i] ) );
}
}
} else {
emBranch->SetAddress(&photon);
emBranch->GetEntry(nrc);
}
emBranch->GetEntry(nrc);
}
#ifdef DebugLog
int nPhoton = (newForm) ? photo->size() : photon.size();
Expand Down Expand Up @@ -436,9 +473,8 @@ void HFShowerLibrary::loadEventInfo(TBranch* branch) {
listVersion = 3.6;
pmom = {2,3,5,7,10,15,20,30,50,75,100,150,250,350,500,1000};
}
for (int i=0; i<nMomBin; i++) {
for (int i=0; i<nMomBin; i++)
pmom[i] *= GeV;
}
}

void HFShowerLibrary::interpolate(int type, double pin) {
Expand All @@ -448,7 +484,7 @@ void HFShowerLibrary::interpolate(int type, double pin) {
<< " GeV with " << nMomBin << " momentum bins and "
<< evtPerBin << " entries/bin -- total " << totEvents;
#endif
int irc[2] = {0, 0};
int irc[2]={0,0};
double w = 0.;
double r = G4UniformRand();

Expand Down
65 changes: 65 additions & 0 deletions SimG4CMS/Calo/test/convertHFShowerLibrary.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "TFile.h"
#include "TTree.h"
#include "TTreeReader.h"
#include "TTreeReaderArray.h"
#include <vector>

// takes "new" form of HF shower library and makes it a v3 version

void convertHFShowerLibrary() {
TFile *nF=new TFile("david.root","RECREATE","hiThere",1);
TTree *nT=new TTree("HFSimHits","HF simple tree");
std::vector<float> *parts=new std::vector<float>();
std::vector<float> *partsHad=new std::vector<float>();
nT->Branch("emParticles", &parts);
nT->GetBranch("emParticles")->SetBasketSize(1);
nT->Branch("hadParticles", &partsHad);
nT->GetBranch("hadParticles")->SetBasketSize(1);

TDirectory *target=gDirectory;
TFile *oF=TFile::Open("HFShowerLibrary_npmt_noatt_eta4_16en_v3_orig.root");
TTree *t=(TTree*)oF->Get("HFSimHits");
TTreeReader fReader(t);
TTreeReaderArray<Float_t> b1(fReader, "emParticles.position_.fCoordinates.fX");
TTreeReaderArray<Float_t> b2(fReader, "emParticles.position_.fCoordinates.fY");
TTreeReaderArray<Float_t> b3(fReader, "emParticles.position_.fCoordinates.fZ");
TTreeReaderArray<Float_t> b4(fReader, "emParticles.lambda_");
TTreeReaderArray<Float_t> b5(fReader, "emParticles.time_");

TTreeReaderArray<Float_t> h1(fReader, "hadParticles.position_.fCoordinates.fX");
TTreeReaderArray<Float_t> h2(fReader, "hadParticles.position_.fCoordinates.fY");
TTreeReaderArray<Float_t> h3(fReader, "hadParticles.position_.fCoordinates.fZ");
TTreeReaderArray<Float_t> h4(fReader, "hadParticles.lambda_");
TTreeReaderArray<Float_t> h5(fReader, "hadParticles.time_");


target->cd();
while ( fReader.Next() ) {
parts->clear();
unsigned int s=b1.GetSize();
parts->resize(5*s);
for ( unsigned int i=0; i<b1.GetSize(); i++) {
(*parts)[i]=(b1[i]);
(*parts)[i+1*s]=(b2[i]);
(*parts)[i+2*s]=(b3[i]);
(*parts)[i+3*s]=(b4[i]);
(*parts)[i+4*s]=(b5[i]);
}

partsHad->clear();
s=h1.GetSize();
partsHad->resize(5*s);
for ( unsigned int i=0; i<h1.GetSize(); i++) {
(*partsHad)[i]=(h1[i]);
(*partsHad)[i+1*s]=(h2[i]);
(*partsHad)[i+2*s]=(h3[i]);
(*partsHad)[i+3*s]=(h4[i]);
(*partsHad)[i+4*s]=(h5[i]);
}

nT->Fill();
}

nT->Write();
nF->Close();
}
2 changes: 1 addition & 1 deletion SimG4Core/Application/python/g4SimHits_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,4 @@
## Change the HFShowerLibrary file used for Run 2
##
from Configuration.Eras.Modifier_run2_common_cff import run2_common
run2_common.toModify( g4SimHits.HFShowerLibrary, FileName = 'SimG4CMS/Calo/data/HFShowerLibrary_npmt_noatt_eta4_16en_v3.root' )
run2_common.toModify( g4SimHits.HFShowerLibrary, FileName = 'SimG4CMS/Calo/data/HFShowerLibrary_npmt_noatt_eta4_16en_v4.root' )