diff --git a/SimG4CMS/Calo/interface/HFShowerLibrary.h b/SimG4CMS/Calo/interface/HFShowerLibrary.h index db985ff681c83..4b6ee7205a5ab 100644 --- a/SimG4CMS/Calo/interface/HFShowerLibrary.h +++ b/SimG4CMS/Calo/interface/HFShowerLibrary.h @@ -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 pmom; diff --git a/SimG4CMS/Calo/src/HFShowerLibrary.cc b/SimG4CMS/Calo/src/HFShowerLibrary.cc index e217e7e6da010..0485fcb1140c4 100644 --- a/SimG4CMS/Calo/src/HFShowerLibrary.cc +++ b/SimG4CMS/Calo/src/HFShowerLibrary.cc @@ -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") ) { + v3version=true; + } + + edm::LogInfo("HFShower") << "HFShowerLibrary:Branch " << emName << " has " << emBranch->GetEntries() << " entries and Branch " << hadName @@ -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, @@ -372,11 +379,14 @@ std::vector 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) { @@ -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 t; + std::vector *tp=&t; + hadBranch->SetAddress(&tp); + hadBranch->GetEntry(nrc+totEvents); + unsigned int tSize=t.size()/5; + photo->reserve(tSize); + for ( unsigned int i=0; ipush_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 t; + std::vector *tp=&t; + emBranch->SetAddress(&tp); + emBranch->GetEntry(nrc); + unsigned int tSize=t.size()/5; + photo->reserve(tSize); + for ( unsigned int i=0; ipush_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(); @@ -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 + +// 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 *parts=new std::vector(); + std::vector *partsHad=new std::vector(); + 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 b1(fReader, "emParticles.position_.fCoordinates.fX"); + TTreeReaderArray b2(fReader, "emParticles.position_.fCoordinates.fY"); + TTreeReaderArray b3(fReader, "emParticles.position_.fCoordinates.fZ"); + TTreeReaderArray b4(fReader, "emParticles.lambda_"); + TTreeReaderArray b5(fReader, "emParticles.time_"); + + TTreeReaderArray h1(fReader, "hadParticles.position_.fCoordinates.fX"); + TTreeReaderArray h2(fReader, "hadParticles.position_.fCoordinates.fY"); + TTreeReaderArray h3(fReader, "hadParticles.position_.fCoordinates.fZ"); + TTreeReaderArray h4(fReader, "hadParticles.lambda_"); + TTreeReaderArray 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; iclear(); + s=h1.GetSize(); + partsHad->resize(5*s); + for ( unsigned int i=0; iFill(); + } + + nT->Write(); + nF->Close(); +} diff --git a/SimG4Core/Application/python/g4SimHits_cfi.py b/SimG4Core/Application/python/g4SimHits_cfi.py index d85fcff47c1d1..13914f05be488 100644 --- a/SimG4Core/Application/python/g4SimHits_cfi.py +++ b/SimG4Core/Application/python/g4SimHits_cfi.py @@ -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' )