Skip to content

Commit 75a6c3d

Browse files
committed
improve SiStripHitEffFromCalibTree and SiStripHitResolFromCalibTree
1 parent 1234e95 commit 75a6c3d

File tree

5 files changed

+136
-20
lines changed

5 files changed

+136
-20
lines changed

CalibTracker/SiStripHitEfficiency/plugins/SiStripHitEffFromCalibTree.cc

Lines changed: 96 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#include "TString.h"
7777
#include "TStyle.h"
7878
#include "TTree.h"
79+
#include "TKey.h"
7980

8081
// custom made printout
8182
#define LOGPRINT edm::LogPrint("SiStripHitEffFromCalibTree")
@@ -94,7 +95,7 @@ struct hit {
9495
class SiStripHitEffFromCalibTree : public ConditionDBWriter<SiStripBadStrip> {
9596
public:
9697
explicit SiStripHitEffFromCalibTree(const edm::ParameterSet&);
97-
~SiStripHitEffFromCalibTree() override = default;
98+
~SiStripHitEffFromCalibTree() override;
9899

99100
private:
100101
// overridden from ConditionDBWriter
@@ -168,16 +169,16 @@ class SiStripHitEffFromCalibTree : public ConditionDBWriter<SiStripBadStrip> {
168169
// for using events after number of tracks cut
169170
map<pair<unsigned int, unsigned int>, bool> event_used;
170171

171-
vector<hit> hits[23];
172+
vector<hit> hits[::k_END_OF_LAYERS];
172173
vector<TH2F*> HotColdMaps;
173-
map<unsigned int, pair<unsigned int, unsigned int> > modCounter[23];
174+
map<unsigned int, pair<unsigned int, unsigned int> > modCounter[::k_END_OF_LAYERS];
174175
TrackerMap* tkmap;
175176
TrackerMap* tkmapbad;
176177
TrackerMap* tkmapeff;
177178
TrackerMap* tkmapnum;
178179
TrackerMap* tkmapden;
179-
long layerfound[23];
180-
long layertotal[23];
180+
long layerfound[::k_END_OF_LAYERS];
181+
long layertotal[::k_END_OF_LAYERS];
181182
map<unsigned int, vector<int> > layerfound_perBx;
182183
map<unsigned int, vector<int> > layertotal_perBx;
183184
vector<TH1F*> layerfound_vsLumi;
@@ -188,10 +189,10 @@ class SiStripHitEffFromCalibTree : public ConditionDBWriter<SiStripBadStrip> {
188189
vector<TH1F*> layertotal_vsCM;
189190
vector<TH1F*> layerfound_vsBX;
190191
vector<TH1F*> layertotal_vsBX;
191-
int goodlayertotal[35];
192-
int goodlayerfound[35];
193-
int alllayertotal[35];
194-
int alllayerfound[35];
192+
int goodlayertotal[::k_END_OF_LAYS_AND_RINGS];
193+
int goodlayerfound[::k_END_OF_LAYS_AND_RINGS];
194+
int alllayertotal[::k_END_OF_LAYS_AND_RINGS];
195+
int alllayerfound[::k_END_OF_LAYS_AND_RINGS];
195196
map<unsigned int, double> BadModules;
196197
};
197198

@@ -229,6 +230,83 @@ SiStripHitEffFromCalibTree::SiStripHitEffFromCalibTree(const edm::ParameterSet&
229230
nTEClayers = 7; // number of rings
230231

231232
quality_ = new SiStripQuality(detInfo_);
233+
234+
layerfound_vsLumi.reserve(::k_END_OF_LAYERS);
235+
layertotal_vsLumi.reserve(::k_END_OF_LAYERS);
236+
layerfound_vsPU.reserve(::k_END_OF_LAYERS);
237+
layertotal_vsPU.reserve(::k_END_OF_LAYERS);
238+
layerfound_vsCM.reserve(::k_END_OF_LAYERS);
239+
layertotal_vsCM.reserve(::k_END_OF_LAYERS);
240+
layerfound_vsBX.reserve(::k_END_OF_LAYERS);
241+
layertotal_vsBX.reserve(::k_END_OF_LAYERS);
242+
}
243+
244+
namespace utils {
245+
246+
void Recursion(TFile* f1, TDirectory* target) {
247+
TString path((char*)strstr(target->GetPath(), ":"));
248+
path.Remove(0, 2);
249+
f1->cd(path);
250+
TDirectory* temp = gDirectory;
251+
std::cout << "Checking initial Get Keys Here: " << temp->GetPath() << std::endl;
252+
253+
TIter next(temp->GetListOfKeys());
254+
TKey* key;
255+
while ((key = (TKey*)next())) {
256+
printf("key: %s points to an object of class: %s \n", key->GetName(), key->GetClassName());
257+
258+
TObject* obj = key->ReadObj();
259+
if (obj->IsA()->InheritsFrom(TDirectory::Class())) {
260+
std::cout << "Found subdirectory " << obj->GetName() << std::endl;
261+
TDirectory* subdir = (TDirectory*)obj;
262+
std::cout << subdir->GetPath() << std::endl;
263+
Recursion(f1, subdir);
264+
} else if (obj->IsA()->InheritsFrom(TTree::Class())) {
265+
std::cout << "object found" << std::endl;
266+
delete obj;
267+
} else {
268+
std::cout << "no new directory:" << std::endl;
269+
}
270+
}
271+
}
272+
} // namespace utils
273+
274+
SiStripHitEffFromCalibTree::~SiStripHitEffFromCalibTree() {
275+
if (quality_)
276+
delete quality_;
277+
if (tkmap)
278+
delete tkmap;
279+
if (tkmapbad)
280+
delete tkmapbad;
281+
if (tkmapeff)
282+
delete tkmapeff;
283+
if (tkmapnum)
284+
delete tkmapnum;
285+
if (tkmapden)
286+
delete tkmapden;
287+
288+
if (fs) {
289+
auto& tFile = fs->file();
290+
//tFile.Print(); // Print information about the file
291+
edm::LogPrint("") << __PRETTY_FUNCTION__ << " File Name: " << tFile.GetName() << std::endl;
292+
edm::LogPrint("") << __PRETTY_FUNCTION__ << " File Title: " << tFile.GetTitle() << std::endl;
293+
edm::LogPrint("") << __PRETTY_FUNCTION__ << " File Option: " << tFile.GetOption() << std::endl;
294+
edm::LogPrint("") << __PRETTY_FUNCTION__ << " File Writable: " << tFile.IsWritable() << std::endl;
295+
edm::LogPrint("") << __PRETTY_FUNCTION__ << " File IsZombie: " << tFile.IsZombie() << std::endl;
296+
edm::LogPrint("") << __PRETTY_FUNCTION__ << " File has inconsistent hash: " << tFile.HasInconsistentHash()
297+
<< std::endl;
298+
299+
bool debug{false};
300+
301+
if (!tFile.IsZombie() && tFile.IsWritable() && debug) {
302+
// Delete all objects in the file recursively
303+
utils::Recursion(&tFile, &tFile);
304+
edm::LogPrint("") << __PRETTY_FUNCTION__ << "done deleting" << std::endl;
305+
// Write and close the file
306+
tFile.Write(); // Ensure all objects are written
307+
tFile.Close();
308+
}
309+
}
232310
}
233311

234312
void SiStripHitEffFromCalibTree::algoAnalyze(const edm::Event& e, const edm::EventSetup& c) {
@@ -272,15 +350,15 @@ void SiStripHitEffFromCalibTree::algoAnalyze(const edm::Event& e, const edm::Eve
272350
instLumiHisto_cutOnTracks = fs->make<TH1F>("instLumi_cutOnTracks", "inst. lumi.", 250, 0, 25000);
273351
PUHisto_cutOnTracks = fs->make<TH1F>("PU_cutOnTracks", "PU", 300, 0, 300);
274352

275-
for (int l = 0; l < 35; l++) {
353+
for (int l = 0; l < ::k_END_OF_LAYS_AND_RINGS; l++) {
276354
goodlayertotal[l] = 0;
277355
goodlayerfound[l] = 0;
278356
alllayertotal[l] = 0;
279357
alllayerfound[l] = 0;
280358
}
281359

282-
TH1F* resolutionPlots[23];
283-
for (Long_t ilayer = 0; ilayer < 23; ilayer++) {
360+
TH1F* resolutionPlots[::k_END_OF_LAYERS];
361+
for (Long_t ilayer = 0; ilayer < ::k_END_OF_LAYERS; ilayer++) {
284362
std::string lyrName = ::layerName(ilayer, showRings_, nTEClayers);
285363

286364
resolutionPlots[ilayer] = fs->make<TH1F>(Form("resol_layer_%i", (int)(ilayer)), lyrName.c_str(), 125, -125, 125);
@@ -548,7 +626,7 @@ void SiStripHitEffFromCalibTree::algoAnalyze(const edm::Event& e, const edm::Eve
548626
}
549627
}
550628

551-
if (!badquality && layer < 23) {
629+
if (!badquality && layer < ::k_END_OF_LAYERS) {
552630
if (resxsig != 1000.0)
553631
resolutionPlots[layer]->Fill(stripTrajMid - stripCluster);
554632
else
@@ -610,8 +688,8 @@ void SiStripHitEffFromCalibTree::algoAnalyze(const edm::Event& e, const edm::Eve
610688
}
611689

612690
if (layerfound_perBx.find(bx) == layerfound_perBx.end()) {
613-
layerfound_perBx[bx] = vector<int>(23, 0);
614-
layertotal_perBx[bx] = vector<int>(23, 0);
691+
layerfound_perBx[bx] = vector<int>(::k_END_OF_LAYERS, 0);
692+
layertotal_perBx[bx] = vector<int>(::k_END_OF_LAYERS, 0);
615693
}
616694
if (!badflag)
617695
layerfound_perBx[bx][layer]++;
@@ -685,6 +763,9 @@ void SiStripHitEffFromCalibTree::algoAnalyze(const edm::Event& e, const edm::Eve
685763
}
686764
//At this point, both of our maps are loaded with the correct information
687765
}
766+
// once we're done close the bloody file
767+
CalibTreeFile->Close();
768+
delete CalibTreeFile;
688769
} // go to next CalibTreeFile
689770

690771
makeHotColdMaps();

CalibTracker/SiStripHitEfficiency/test/testHitEffWorker.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,13 @@
9090
## END OLD HITEFF
9191

9292
## TODO double-check in main CalibTree config if hiteff also takes refitted tracks
93-
process.allPath = cms.Path(process.MeasurementTrackerEvent*process.offlineBeamSpot*process.refitTracks
94-
*process.anEff*process.shallowEventRun*process.eventInfo
95-
*process.hiteff)
93+
process.allPath = cms.Path(process.MeasurementTrackerEvent*
94+
process.offlineBeamSpot*
95+
process.refitTracks*
96+
process.anEff*
97+
process.shallowEventRun*
98+
process.eventInfo*
99+
process.hiteff)
96100

97101
# save the DQM plots in the DQMIO format
98102
process.dqmOutput = cms.OutputModule("DQMRootOutputModule",

CalibTracker/SiStripHitEfficiency/test/test_SiStripHitEfficiency.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22
function die { echo $1: status $2; exit $2; }
33

4+
#export MALLOC_CONF=junk:true
5+
46
if [ "${SCRAM_TEST_NAME}" != "" ] ; then
57
mkdir ${SCRAM_TEST_NAME}
68
cd ${SCRAM_TEST_NAME}

CalibTracker/SiStripHitResolution/plugins/SiStripHitResolFromCalibTree.cc

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct hit {
7373
class SiStripHitResolFromCalibTree : public ConditionDBWriter<SiStripBadStrip> {
7474
public:
7575
explicit SiStripHitResolFromCalibTree(const edm::ParameterSet&);
76-
~SiStripHitResolFromCalibTree() override = default;
76+
~SiStripHitResolFromCalibTree() override;
7777

7878
private:
7979
void algoBeginJob(const edm::EventSetup&) override;
@@ -199,6 +199,30 @@ SiStripHitResolFromCalibTree::SiStripHitResolFromCalibTree(const edm::ParameterS
199199
nTEClayers_ = 7; // number of rings
200200

201201
quality_ = new SiStripQuality(detInfo_);
202+
203+
layerfound_vsLumi.reserve(::k_END_OF_LAYS_AND_RINGS);
204+
layertotal_vsLumi.reserve(::k_END_OF_LAYS_AND_RINGS);
205+
layerfound_vsPU.reserve(::k_END_OF_LAYS_AND_RINGS);
206+
layertotal_vsPU.reserve(::k_END_OF_LAYS_AND_RINGS);
207+
layerfound_vsCM.reserve(::k_END_OF_LAYS_AND_RINGS);
208+
layertotal_vsCM.reserve(::k_END_OF_LAYS_AND_RINGS);
209+
layerfound_vsBX.reserve(::k_END_OF_LAYS_AND_RINGS);
210+
layertotal_vsBX.reserve(::k_END_OF_LAYS_AND_RINGS);
211+
}
212+
213+
SiStripHitResolFromCalibTree::~SiStripHitResolFromCalibTree() {
214+
if (quality_)
215+
delete quality_;
216+
if (tkmap)
217+
delete tkmap;
218+
if (tkmapbad)
219+
delete tkmapbad;
220+
if (tkmapeff)
221+
delete tkmapeff;
222+
if (tkmapnum)
223+
delete tkmapnum;
224+
if (tkmapden)
225+
delete tkmapden;
202226
}
203227

204228
void SiStripHitResolFromCalibTree::algoBeginJob(const edm::EventSetup&) {}
@@ -334,7 +358,7 @@ void SiStripHitResolFromCalibTree::algoAnalyze(const edm::Event& e, const edm::E
334358
//Open the ROOT Calib Tree
335359
for (unsigned int ifile = 0; ifile < calibTreeFileNames_.size(); ifile++) {
336360
edm::LogInfo("SiStripHitResolFromCalibTree") << "Loading file: " << calibTreeFileNames_[ifile] << endl;
337-
TFile* CalibTreeFile = TFile::Open(calibTreeFileNames_[ifile].c_str(), "READ");
361+
TFile* CalibTreeFile = TFile::Open(calibTreeFileNames_[ifile].c_str(), "READ+CACHEREAD");
338362

339363
// Get event infos
340364
bool foundEventInfos = false;
@@ -709,6 +733,9 @@ void SiStripHitResolFromCalibTree::algoAnalyze(const edm::Event& e, const edm::E
709733
}
710734
//At this point, both of our maps are loaded with the correct information
711735
}
736+
// once we're done close the bloody file
737+
CalibTreeFile->Close();
738+
delete CalibTreeFile;
712739
} // go to next CalibTreeFile
713740

714741
makeHotColdMaps(fs);

CalibTracker/SiStripHitResolution/test/test_SiStripHitResolution.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22
function die { echo $1: status $2; exit $2; }
33

4+
#export MALLOC_CONF=junk:true
5+
46
if [ "${SCRAM_TEST_NAME}" != "" ] ; then
57
mkdir ${SCRAM_TEST_NAME}
68
cd ${SCRAM_TEST_NAME}

0 commit comments

Comments
 (0)