Skip to content

Commit 648ddf4

Browse files
author
Sunanda
committed
Add the new ways to introduce PF cuts frm a file derivd from DB
1 parent 1a09f40 commit 648ddf4

File tree

6 files changed

+421
-57
lines changed

6 files changed

+421
-57
lines changed

Calibration/HcalCalibAlgos/macros/CalibCorr.C

Lines changed: 92 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -238,28 +238,6 @@ int truncateDepth(int ieta, int depth, int truncateFlag) {
238238
return d;
239239
}
240240

241-
double threshold(int subdet, int depth, int form) {
242-
double cutHE[4][7] = {{0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2},
243-
{0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2},
244-
{0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2},
245-
{0.2, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3}};
246-
double cutHB[4][4] = {{0.1, 0.2, 0.3, 0.3}, {0.25, 0.25, 0.3, 0.3}, {0.4, 0.3, 0.3, 0.3}, {0.6, 0.4, 0.4, 0.5}};
247-
double thr(0);
248-
if (form > 0) {
249-
if (subdet == 2)
250-
thr = cutHE[form - 1][depth - 1];
251-
else
252-
thr = cutHB[form - 1][depth - 1];
253-
}
254-
return thr;
255-
}
256-
257-
double threshold(unsigned int detId, int form) {
258-
int subdet = ((detId >> 25) & (0x7));
259-
int depth = ((detId & 0x1000000) == 0) ? ((detId >> 14) & 0x1F) : ((detId >> 20) & 0xF);
260-
return threshold(subdet, depth, form);
261-
}
262-
263241
double puFactor(int type, int ieta, double pmom, double eHcal, double ediff, bool debug = false) {
264242
double fac(1.0);
265243
if (debug)
@@ -568,6 +546,98 @@ std::vector<std::string> splitString(const std::string& fLine) {
568546
return result;
569547
}
570548

549+
class CalibThreshold {
550+
public:
551+
CalibThreshold(int form);
552+
~CalibThreshold() {}
553+
554+
double threshold(unsigned int detId);
555+
private:
556+
double threshold(int subdet, int ieta, int depth);
557+
bool fileThreshold(const char* fname);
558+
559+
int form_;
560+
std::map<std::pair<int, int>, double> thresh_;
561+
bool ok_;
562+
};
563+
564+
CalibThreshold::CalibThreshold(int form) : form_(form) {
565+
if (form_ == 5)
566+
ok_ = fileThreshold("PFCuts362975.txt");
567+
else if ((form_ < 1) || (form_ > 5))
568+
ok_ = false;
569+
else
570+
ok_ = true;
571+
std::cout << "CalibThreshold initialized with flag " << ok_ << " for form " << form_ << std::endl;
572+
}
573+
574+
bool CalibThreshold::fileThreshold(const char* fname) {
575+
bool ok(false);
576+
if (std::string(fname) != "") {
577+
std::ifstream fInput(fname);
578+
if (!fInput.good()) {
579+
std::cout << "Cannot open file " << fname << std::endl;
580+
} else {
581+
char buffer[1024];
582+
unsigned int all(0), good(0), bad(0);
583+
while (fInput.getline(buffer, 1024)) {
584+
++all;
585+
if (buffer[0] == '#')
586+
continue; //ignore comment
587+
std::vector<std::string> items = splitString(std::string(buffer));
588+
if (items.size() != 7) {
589+
++bad;
590+
std::cout << "Ignore line: " << buffer << std::endl;
591+
} else {
592+
++good;
593+
int ieta = std::atoi(items[0].c_str());
594+
int depth = std::atoi(items[2].c_str());
595+
double thr = std::atof(items[4].c_str());
596+
thresh_[std::pair<int, int>(ieta, depth)] = thr;
597+
}
598+
}
599+
fInput.close();
600+
std::cout << "Reads " << all << " entries from " << fname << " with " << good << " Good and " << bad << " bad records" << std::endl;
601+
if (good > 0)
602+
ok = true;
603+
}
604+
}
605+
return ok;
606+
}
607+
608+
double CalibThreshold::threshold(int subdet, int ieta, int depth) {
609+
double cutHE[4][7] = {{0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2},
610+
{0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2},
611+
{0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2},
612+
{0.2, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3}};
613+
double cutHB[4][4] = {{0.1, 0.2, 0.3, 0.3},
614+
{0.25, 0.25, 0.3, 0.3},
615+
{0.4, 0.3, 0.3, 0.3},
616+
{0.6, 0.4, 0.4, 0.5}};
617+
618+
double thr(0);
619+
if (ok_) {
620+
if ((form_ > 0) && (form_ <= 4)) {
621+
if (subdet == 2)
622+
thr = cutHE[form_ - 1][depth - 1];
623+
else
624+
thr = cutHB[form_ - 1][depth - 1];
625+
} else {
626+
std::map<std::pair<int, int>, double>::const_iterator itr =
627+
thresh_.find(std::pair<int, int>(ieta, depth));
628+
if (itr != thresh_.end())
629+
thr = itr->second;
630+
}
631+
}
632+
return thr;
633+
}
634+
635+
double CalibThreshold::threshold(unsigned int detId) {
636+
int subdet, zside, ieta, iphi, depth;
637+
unpackDetId(detId, subdet, zside, ieta, iphi, depth);
638+
return threshold(subdet, (zside * ieta), depth);
639+
}
640+
571641
class CalibCorrFactor {
572642
public:
573643
CalibCorrFactor(const char* infile, int useScale, double scale, bool etamax, bool marina, bool debug);

Calibration/HcalCalibAlgos/macros/CalibFitPlots.C

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@
265265
#include "CalibCorr.C"
266266

267267
const double fitrangeFactor = 1.5;
268+
const double fitrangeFactor1 = 1.2;
268269

269270
struct cfactors {
270271
int ieta, depth;
@@ -445,7 +446,7 @@ results fitTwoGauss(TH1D* hist, bool debug) {
445446
std::pair<double, double> mrms = GetMean(hist, 0.2, 2.0, rms);
446447
double mean = mrms.first;
447448
double LowEdge = mean - fitrangeFactor * rms;
448-
double HighEdge = mean + fitrangeFactor * rms;
449+
double HighEdge = mean + fitrangeFactor1 * rms;
449450
if (LowEdge < 0.15)
450451
LowEdge = 0.15;
451452
std::string option = (hist->GetEntries() > 100) ? "QRS" : "QRWLS";
@@ -482,7 +483,7 @@ results fitTwoGauss(TH1D* hist, bool debug) {
482483
highValue[5] = 100. * startvalues[5];
483484
//fitrange[0] = mean - 2.0*rms; fitrange[1] = mean + 2.0*rms;
484485
fitrange[0] = Fit->Value(1) - fitrangeFactor * Fit->Value(2);
485-
fitrange[1] = Fit->Value(1) + fitrangeFactor * Fit->Value(2);
486+
fitrange[1] = Fit->Value(1) + fitrangeFactor1 * Fit->Value(2);
486487
TFitResultPtr Fitfun = functionFit(hist, fitrange, startvalues, lowValue, highValue);
487488
double wt1 = (Fitfun->Value(0)) * (Fitfun->Value(2));
488489
double value1 = Fitfun->Value(1);
@@ -514,7 +515,8 @@ results fitOneGauss(TH1D* hist, bool fitTwice, bool debug) {
514515
std::pair<double, double> mrms = GetMean(hist, 0.2, 2.0, rms);
515516
double mean = mrms.first;
516517
double LowEdge = ((mean - fitrangeFactor * rms) < 0.5) ? 0.5 : (mean - fitrangeFactor * rms);
517-
double HighEdge = (mean + fitrangeFactor * rms);
518+
double diff = mean - LowEdge;
519+
double HighEdge = (diff > fitrangeFactor1 * rms) ? (mean + fitrangeFactor1 * rms) : (mean + diff);
518520
if (debug)
519521
std::cout << hist->GetName() << " Mean " << mean << " RMS " << rms << " Range " << LowEdge << ":" << HighEdge
520522
<< "\n";
@@ -531,9 +533,10 @@ results fitOneGauss(TH1D* hist, bool fitTwice, bool debug) {
531533
double werror = Fit1->FitResult::Error(2);
532534
if (fitTwice) {
533535
LowEdge = Fit1->Value(1) - fitrangeFactor * Fit1->Value(2);
534-
HighEdge = Fit1->Value(1) + fitrangeFactor * Fit1->Value(2);
535536
if (LowEdge < 0.5)
536537
LowEdge = 0.5;
538+
diff = Fit1->Value(1) - LowEdge;
539+
HighEdge = (diff > fitrangeFactor1 * rms) ? (Fit1->Value(1) + fitrangeFactor1 * Fit1->Value(2)) : (Fit1->Value(1) + diff);
537540
if (HighEdge > 5.0)
538541
HighEdge = 5.0;
539542
if (debug)
@@ -2220,6 +2223,7 @@ void PlotHistCorrFactor(char* infile,
22202223
int nbin = etamax - etamin + 1;
22212224
std::vector<TH1D*> hists;
22222225
std::vector<int> entries;
2226+
std::vector<int> depths;
22232227
char name[100];
22242228
double dy(0);
22252229
int fits(0);
@@ -2254,17 +2258,20 @@ void PlotHistCorrFactor(char* infile,
22542258
TF1* func = new TF1(name, "pol0", etamin, etamax);
22552259
h->Fit(func, "+QWLR", "");
22562260
}
2257-
h->SetLineColor(colors[j]);
2258-
h->SetMarkerColor(colors[j]);
2259-
h->SetMarkerStyle(mtype[j]);
2260-
h->GetXaxis()->SetTitle("i#eta");
2261-
h->GetYaxis()->SetTitle("Correction Factor");
2262-
h->GetYaxis()->SetLabelOffset(0.005);
2263-
h->GetYaxis()->SetTitleOffset(1.20);
2264-
h->GetYaxis()->SetRangeUser(0.0, 2.0);
2265-
hists.push_back(h);
2266-
entries.push_back(nent);
2267-
dy += 0.025;
2261+
if (nent > 0) {
2262+
h->SetLineColor(colors[j]);
2263+
h->SetMarkerColor(colors[j]);
2264+
h->SetMarkerStyle(mtype[j]);
2265+
h->GetXaxis()->SetTitle("i#eta");
2266+
h->GetYaxis()->SetTitle("Correction Factor");
2267+
h->GetYaxis()->SetLabelOffset(0.005);
2268+
h->GetYaxis()->SetTitleOffset(1.20);
2269+
h->GetYaxis()->SetRangeUser(0.0, 2.5);
2270+
hists.push_back(h);
2271+
entries.push_back(nent);
2272+
depths.push_back(j + 1);
2273+
dy += 0.025;
2274+
}
22682275
}
22692276
sprintf(name, "c_%sCorrFactor", prefixF.c_str());
22702277
TCanvas* pad = new TCanvas(name, name, 700, 500);
@@ -2292,7 +2299,7 @@ void PlotHistCorrFactor(char* infile,
22922299
st1->SetX2NDC(0.90);
22932300
yh -= dy;
22942301
}
2295-
sprintf(name, "Depth %d (%s)", k + 1, text.c_str());
2302+
sprintf(name, "Depth %d (%s)", depths[k], text.c_str());
22962303
legend->AddEntry(hists[k], name, "lp");
22972304
}
22982305
legend->Draw("same");
@@ -2493,7 +2500,7 @@ void PlotHistCorrAsymmetry(
24932500
std::vector<int> entries;
24942501
char name[100];
24952502
double dy(0);
2496-
int maxd = (depth < 0) ? maxdepth : 1;
2503+
int maxd = (depth <= 0) ? maxdepth : 1;
24972504
for (int j = 0; j < maxd; ++j) {
24982505
int dep = (depth <= 0) ? (j + 1) : depth;
24992506
sprintf(name, "hd%d", dep);
@@ -4330,7 +4337,7 @@ void PlotMeanError(const std::string infilest, int reg = 3, bool resol = false,
43304337
} else {
43314338
ok = true;
43324339
fInput >> nEner >> nType >> nPts;
4333-
int nmax = nEner * nType;
4340+
const int nmax = nEner * nType;
43344341
int type, elow, ehigh;
43354342
double v1[4], e1[4], v2[4], e2[4];
43364343
for (int n = 0; n < nmax; ++n) {
@@ -4406,7 +4413,7 @@ void PlotMeanError(const std::string infilest, int reg = 3, bool resol = false,
44064413
legend->SetFillColor(kWhite);
44074414
std::string nameg[ntypmx] = {"MAHI", "M0", "M2"};
44084415
for (int n = 0; n < nType; ++n) {
4409-
unsigned int nmax0 = energy[n].size();
4416+
const unsigned int nmax0 = energy[n].size();
44104417
double mom[nmax0], dmom[nmax0], mean[nmax0], dmean[nmax0];
44114418
for (unsigned int k = 0; k < nmax0; ++k) {
44124419
mom[k] = energy[n][k];

Calibration/HcalCalibAlgos/macros/CalibMonitor.C

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ private:
314314
CalibCorr *cFactor_;
315315
CalibSelectRBX *cSelect_;
316316
CalibDuplicate *cDuplicate_;
317+
CalibThreshold *cThr_;
317318
const std::string fname_, dirnm_, prefix_, outFileName_;
318319
const int corrPU_, flag_, numb_;
319320
const bool isRealData_, useGen_;
@@ -370,6 +371,7 @@ CalibMonitor::CalibMonitor(const char *fname,
370371
cFactor_(nullptr),
371372
cSelect_(nullptr),
372373
cDuplicate_(nullptr),
374+
cThr_(nullptr),
373375
fname_(std::string(fname)),
374376
dirnm_(std::string(dirnm)),
375377
prefix_(prefix),
@@ -440,6 +442,8 @@ CalibMonitor::CalibMonitor(const char *fname,
440442
}
441443
if (std::string(rbxFile) != "")
442444
cSelect_ = new CalibSelectRBX(rbxFile, false);
445+
if (thrForm_ > 0)
446+
cThr_ = new CalibThreshold(thrForm_);
443447
}
444448
}
445449

@@ -1150,7 +1154,7 @@ void CalibMonitor::Loop(Long64_t nmax, bool debug) {
11501154
eHcal = 0;
11511155
for (unsigned int k = 0; k < t_HitEnergies->size(); ++k) {
11521156
// Apply thresholds if necessary
1153-
bool okcell = (thrForm_ == 0) || ((*t_HitEnergies)[k] > threshold((*t_DetIds)[k], thrForm_));
1157+
bool okcell = (thrForm_ == 0) || ((*t_HitEnergies)[k] > (cThr_->threshold((*t_DetIds)[k])));
11541158
// The masks are defined in DataFormats/HcalDetId/interface/HcalDetId.h
11551159
if (okcell) {
11561160
double cfac(1.0);
@@ -1572,7 +1576,7 @@ bool CalibMonitor::selectPhi(bool debug) {
15721576
// The masks are defined in DataFormats/HcalDetId/interface/HcalDetId.h
15731577
for (unsigned int k = 0; k < t_HitEnergies->size(); ++k) {
15741578
// Apply thresholds if necessary
1575-
bool okcell = (thrForm_ == 0) || ((*t_HitEnergies)[k] > threshold((*t_DetIds)[k], thrForm_));
1579+
bool okcell = (thrForm_ == 0) || ((*t_HitEnergies)[k] > (cThr_->threshold((*t_DetIds)[k])));
15761580
if (okcell) {
15771581
int iphi = ((*t_DetIds)[k]) & (0x3FF);
15781582
int zside = ((*t_DetIds)[k] & 0x80000) ? (1) : (-1);
@@ -1760,7 +1764,7 @@ void CalibMonitor::correctEnergy(double &eHcal, const Long64_t &entry) {
17601764
// The masks are defined in DataFormats/HcalDetId/interface/HcalDetId.h
17611765
for (unsigned int idet = 0; idet < (*t_DetIds1).size(); idet++) {
17621766
// Apply thresholds if necessary
1763-
bool okcell = (thrForm_ == 0) || ((*t_HitEnergies1)[idet] > threshold((*t_DetIds1)[idet], thrForm_));
1767+
bool okcell = (thrForm_ == 0) || ((*t_HitEnergies1)[idet] > (cThr_->threshold((*t_DetIds1)[idet])));
17641768
if (okcell) {
17651769
unsigned int id = truncateId((*t_DetIds1)[idet], truncateFlag_, false);
17661770
double cfac = corrFactor_->getCorr(id);
@@ -1779,7 +1783,7 @@ void CalibMonitor::correctEnergy(double &eHcal, const Long64_t &entry) {
17791783
}
17801784
for (unsigned int idet = 0; idet < (*t_DetIds3).size(); idet++) {
17811785
// Apply thresholds if necessary
1782-
bool okcell = (thrForm_ == 0) || ((*t_HitEnergies3)[idet] > threshold((*t_DetIds3)[idet], thrForm_));
1786+
bool okcell = (thrForm_ == 0) || ((*t_HitEnergies3)[idet] > (cThr_->threshold((*t_DetIds3)[idet])));
17831787
if (okcell) {
17841788
unsigned int id = truncateId((*t_DetIds3)[idet], truncateFlag_, false);
17851789
double cfac = corrFactor_->getCorr(id);

Calibration/HcalCalibAlgos/macros/CalibPlotProperties.C

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ private:
329329
CalibCorr *cFactor_;
330330
CalibSelectRBX *cSelect_;
331331
CalibDuplicate *cDuplicate_;
332+
CalibThreshold *cThr_;
332333
const std::string fname_, dirnm_, prefix_, outFileName_;
333334
const int corrPU_, flag_;
334335
const bool isRealData_, useGen_;
@@ -387,6 +388,7 @@ CalibPlotProperties::CalibPlotProperties(const char *fname,
387388
cFactor_(nullptr),
388389
cSelect_(nullptr),
389390
cDuplicate_(nullptr),
391+
cThr_(nullptr),
390392
fname_(fname),
391393
dirnm_(dirnm),
392394
prefix_(prefix),
@@ -452,6 +454,8 @@ CalibPlotProperties::CalibPlotProperties(const char *fname,
452454
cDuplicate_ = new CalibDuplicate(dupFileName, duplicate_, false);
453455
if (std::string(rbxFile) != "")
454456
cSelect_ = new CalibSelectRBX(rbxFile, false);
457+
if (thrForm_ > 0)
458+
cThr_ = new CalibThreshold(thrForm_);
455459
}
456460
}
457461

@@ -923,7 +927,7 @@ void CalibPlotProperties::Loop(Long64_t nentries) {
923927
eHcal = 0;
924928
for (unsigned int k = 0; k < t_HitEnergies->size(); ++k) {
925929
// Apply thresholds if necessary
926-
bool okcell = (thrForm_ == 0) || ((*t_HitEnergies)[k] > threshold((*t_DetIds)[k], thrForm_));
930+
bool okcell = (thrForm_ == 0) || ((*t_HitEnergies)[k] > (cThr_->threshold((*t_DetIds)[k])));
927931
if (okcell) {
928932
// The masks are defined in DataFormats/HcalDetId/interface/HcalDetId.h
929933
unsigned int id = truncateId((*t_DetIds)[k], truncateFlag_, false);
@@ -1024,7 +1028,7 @@ void CalibPlotProperties::Loop(Long64_t nentries) {
10241028
double eb(0), ee(0);
10251029
for (unsigned int k = 0; k < t_HitEnergies->size(); ++k) {
10261030
// Apply thresholds if necessary
1027-
bool okcell = (thrForm_ == 0) || ((*t_HitEnergies)[k] > threshold((*t_DetIds)[k], thrForm_));
1031+
bool okcell = (thrForm_ == 0) || ((*t_HitEnergies)[k] > (cThr_->threshold((*t_DetIds)[k])));
10281032
if (okcell) {
10291033
unsigned int id = truncateId((*t_DetIds)[k], truncateFlag_, false);
10301034
double cfac = corrFactor_->getCorr(id);
@@ -1110,7 +1114,7 @@ bool CalibPlotProperties::selectPhi(bool debug) {
11101114
// The masks are defined in DataFormats/HcalDetId/interface/HcalDetId.h
11111115
for (unsigned int k = 0; k < t_HitEnergies->size(); ++k) {
11121116
// Apply thresholds if necessary
1113-
bool okcell = (thrForm_ == 0) || ((*t_HitEnergies)[k] > threshold((*t_DetIds)[k], thrForm_));
1117+
bool okcell = (thrForm_ == 0) || ((*t_HitEnergies)[k] > (cThr_->threshold((*t_DetIds)[k])));
11141118
if (okcell) {
11151119
int iphi = ((*t_DetIds)[k]) & (0x3FF);
11161120
int zside = ((*t_DetIds)[k] & 0x80000) ? (1) : (-1);
@@ -1258,7 +1262,7 @@ void CalibPlotProperties::correctEnergy(double &eHcal) {
12581262
// The masks are defined in DataFormats/HcalDetId/interface/HcalDetId.h
12591263
for (unsigned int idet = 0; idet < (*t_DetIds1).size(); idet++) {
12601264
// Apply thresholds if necessary
1261-
bool okcell = (thrForm_ == 0) || ((*t_HitEnergies1)[idet] > threshold((*t_DetIds1)[idet], thrForm_));
1265+
bool okcell = (thrForm_ == 0) || ((*t_HitEnergies1)[idet] > (cThr_->threshold((*t_DetIds1)[idet])));
12621266
if (okcell) {
12631267
unsigned int id = truncateId((*t_DetIds1)[idet], truncateFlag_, false);
12641268
double cfac = corrFactor_->getCorr(id);
@@ -1277,7 +1281,7 @@ void CalibPlotProperties::correctEnergy(double &eHcal) {
12771281
}
12781282
for (unsigned int idet = 0; idet < (*t_DetIds3).size(); idet++) {
12791283
// Apply thresholds if necessary
1280-
bool okcell = (thrForm_ == 0) || ((*t_HitEnergies3)[idet] > threshold((*t_DetIds3)[idet], thrForm_));
1284+
bool okcell = (thrForm_ == 0) || ((*t_HitEnergies3)[idet] > (cThr_->threshold((*t_DetIds3)[idet])));
12811285
if (okcell) {
12821286
unsigned int id = truncateId((*t_DetIds3)[idet], truncateFlag_, false);
12831287
double cfac = corrFactor_->getCorr(id);

0 commit comments

Comments
 (0)