Skip to content

Commit

Permalink
Merge branch 'master' into 106X_autoCondMC
Browse files Browse the repository at this point in the history
  • Loading branch information
tocheng committed Apr 11, 2019
2 parents 7fd727d + eaed370 commit 98c17f1
Show file tree
Hide file tree
Showing 203 changed files with 2,939 additions and 1,345 deletions.
@@ -1,5 +1,5 @@
import FWCore.ParameterSet.Config as cms

import six
process = cms.Process("CALIB")

####################################################
Expand Down Expand Up @@ -53,7 +53,7 @@ def getFileInPath(rfile):
#print(detDict)

APVsToKill = []
for det,napv in detDict.iteritems():
for det,napv in six.iteritems(detDict):
APVsToKill.append(
cms.PSet(
DetId = cms.uint32(int(det)),
Expand Down
104 changes: 61 additions & 43 deletions Calibration/HcalCalibAlgos/macros/CalibCorr.C
Expand Up @@ -64,9 +64,12 @@ unsigned int truncateId(unsigned int detId, int truncateFlag, bool debug=false){
return id;
}

double puFactor(int type, int ieta, double pmom, double eHcal, double ediff) {
double puFactor(int type, int ieta, double pmom, double eHcal, double ediff,
bool debug=false) {

double fac(1.0);
if (debug) std::cout << "Input Type " << type << " ieta " << ieta
<< " pmon " << pmom << " E " << eHcal << ":" << ediff;
if (type <=2) {
double frac = (type == 1) ? 0.02 : 0.03;
if (pmom > 0 && ediff > frac*pmom) {
Expand All @@ -87,50 +90,65 @@ double puFactor(int type, int ieta, double pmom, double eHcal, double ediff) {
}
}
fac = (1.0+a1*(eHcal/pmom)*(ediff/pmom)*(1+a2*(ediff/pmom)));
} else {
int jeta = std::abs(ieta);
double d2p = (ediff/pmom);
const double DELTA_CUT = 0.03;
const int PU_IETA_3 = 25;
if (type == 3) { // 16pu
const double CONST_COR_COEF[4] = { 0.971, 1.008, 0.985, 1.086 };
const double LINEAR_COR_COEF[4] = { 0, -0.359, -0.251, -0.535 };
const double SQUARE_COR_COEF[4] = { 0, 0, 0.048, 0.143 };
const int PU_IETA_1 = 9;
const int PU_IETA_2 = 16;
unsigned icor = (unsigned(jeta >= PU_IETA_1) +
unsigned(jeta >= PU_IETA_2) +
unsigned(jeta >= PU_IETA_3));
if (d2p > DELTA_CUT) fac = (CONST_COR_COEF[icor] +
LINEAR_COR_COEF[icor]*d2p +
SQUARE_COR_COEF[icor]*d2p*d2p);
} else if (type == 4) { // 17pu
const double CONST_COR_COEF[4] = { 0.974, 1.023, 0.989, 1.077 };
const double LINEAR_COR_COEF[4] = { 0, -0.524, -0.268, -0.584 };
const double SQUARE_COR_COEF[4] = { 0, 0, 0.053, 0.170 };
const int PU_IETA_1 = 9;
const int PU_IETA_2 = 18;
unsigned icor = (unsigned(jeta >= PU_IETA_1) +
unsigned(jeta >= PU_IETA_2) +
unsigned(jeta >= PU_IETA_3));
if (d2p > DELTA_CUT) fac = (CONST_COR_COEF[icor] +
LINEAR_COR_COEF[icor]*d2p +
SQUARE_COR_COEF[icor]*d2p*d2p);
} else { // 18pu
const double CONST_COR_COEF[4] = { 0.973, 0.998, 0.992, 0.965 };
const double LINEAR_COR_COEF[4] = { 0, -0.318, -0.261, -0.406 };
const double SQUARE_COR_COEF[4] = { 0, 0, 0.047, 0.089 };
const int PU_IETA_1 = 7;
const int PU_IETA_2 = 16;
unsigned icor = (unsigned(jeta >= PU_IETA_1) +
unsigned(jeta >= PU_IETA_2) +
unsigned(jeta >= PU_IETA_3));
if (d2p > DELTA_CUT) fac = (CONST_COR_COEF[icor] +
LINEAR_COR_COEF[icor]*d2p +
SQUARE_COR_COEF[icor]*d2p*d2p);
}
if (debug) std::cout << " coeff " << a1 << ":" << a2 << " Fac " << fac;
}
} else {
int jeta = std::abs(ieta);
double d2p = (ediff/pmom);
const double DELTA_CUT = 0.03;
const int PU_IETA_3 = 25;
if (type == 3) { // 16pu
const double CONST_COR_COEF[4] = { 0.971, 1.008, 0.985, 1.086 };
const double LINEAR_COR_COEF[4] = { 0, -0.359, -0.251, -0.535 };
const double SQUARE_COR_COEF[4] = { 0, 0, 0.048, 0.143 };
const int PU_IETA_1 = 9;
const int PU_IETA_2 = 16;
unsigned icor = (unsigned(jeta >= PU_IETA_1) +
unsigned(jeta >= PU_IETA_2) +
unsigned(jeta >= PU_IETA_3));
if (d2p > DELTA_CUT) fac = (CONST_COR_COEF[icor] +
LINEAR_COR_COEF[icor]*d2p +
SQUARE_COR_COEF[icor]*d2p*d2p);
if (debug) std::cout << " d2p " << d2p << ":" << DELTA_CUT << " coeff "
<< icor << ":" << CONST_COR_COEF[icor] << ":"
<< LINEAR_COR_COEF[icor] << ":"
<< SQUARE_COR_COEF[icor] << " Fac " << fac;
} else if (type == 4) { // 17pu
const double CONST_COR_COEF[4] = { 0.974, 1.023, 0.989, 1.077 };
const double LINEAR_COR_COEF[4] = { 0, -0.524, -0.268, -0.584 };
const double SQUARE_COR_COEF[4] = { 0, 0, 0.053, 0.170 };
const int PU_IETA_1 = 9;
const int PU_IETA_2 = 18;
unsigned icor = (unsigned(jeta >= PU_IETA_1) +
unsigned(jeta >= PU_IETA_2) +
unsigned(jeta >= PU_IETA_3));
if (d2p > DELTA_CUT) fac = (CONST_COR_COEF[icor] +
LINEAR_COR_COEF[icor]*d2p +
SQUARE_COR_COEF[icor]*d2p*d2p);
if (debug) std::cout << " d2p " << d2p << ":" << DELTA_CUT << " coeff "
<< icor << ":" << CONST_COR_COEF[icor] << ":"
<< LINEAR_COR_COEF[icor] << ":"
<< SQUARE_COR_COEF[icor] << " Fac " << fac;
} else { // 18pu
const double CONST_COR_COEF[4] = { 0.973, 0.998, 0.992, 0.965 };
const double LINEAR_COR_COEF[4] = { 0, -0.318, -0.261, -0.406 };
const double SQUARE_COR_COEF[4] = { 0, 0, 0.047, 0.089 };
const int PU_IETA_1 = 7;
const int PU_IETA_2 = 16;
unsigned icor = (unsigned(jeta >= PU_IETA_1) +
unsigned(jeta >= PU_IETA_2) +
unsigned(jeta >= PU_IETA_3));
if (d2p > DELTA_CUT) fac = (CONST_COR_COEF[icor] +
LINEAR_COR_COEF[icor]*d2p +
SQUARE_COR_COEF[icor]*d2p*d2p);
if (debug) std::cout << " d2p " << d2p << ":" << DELTA_CUT << " coeff "
<< icor << ":" << CONST_COR_COEF[icor] << ":"
<< LINEAR_COR_COEF[icor] << ":"
<< SQUARE_COR_COEF[icor] << " Fac " << fac;
}
}
if (fac < 0 || fac > 1) fac = 0;
if (debug) std::cout << " Final factor " << fac << std::endl;
return fac;
}

Expand Down
19 changes: 17 additions & 2 deletions Calibration/HcalCalibAlgos/macros/CalibFitPlots.C
Expand Up @@ -759,7 +759,7 @@ void FitHistExtended(const char* infile, const char* outfile,std::string prefix,
if (total > 4) {
sprintf (name, "%sOne", hist1->GetName());
TH1D* hist2 = (TH1D*)hist1->Clone(name);
results meanerr = fitOneGauss(hist2,false,debug);
results meanerr = fitOneGauss(hist2,true,debug);
value = meanerr.mean; error = meanerr.errmean;
width = meanerr.width; werror= meanerr.errwidth;
double wbyv = width/value;
Expand Down Expand Up @@ -1002,8 +1002,23 @@ void PlotHist(const char* infile, std::string prefix, std::string text,
double xmin = hist->GetBinLowEdge(1);
int nbin = hist->GetNbinsX();
double xmax = hist->GetBinLowEdge(nbin)+hist->GetBinWidth(nbin);
double mean(0), rms(0), total(0);
int kount(0);
for (int k=2; k<nbin; ++k) {
double x = hist->GetBinContent(k);
double w = hist->GetBinError(k);
mean += (x*w);
rms += (x*x*w);
total += w;
++kount;
}
mean /= total;
rms /= total;
double error = sqrt(rms-mean*mean)/total;
line = new TLine(xmin,p0,xmax,p0); //etamin,1.0,etamax,1.0);
std::cout << xmin << ":" << xmax << ":" << p0 << std::endl;
std::cout << xmin << ":" << xmax << ":" << p0 << " Mean " << nbin
<< ":" << kount << ":" << total <<":" << mean << ":" << rms
<< ":" << error << std::endl;
line->SetLineWidth(2);
line->SetLineStyle(2);
line->Draw("same");
Expand Down
33 changes: 26 additions & 7 deletions Calibration/HcalCalibAlgos/macros/CalibMonitor.C
Expand Up @@ -798,6 +798,7 @@ void CalibMonitor::Loop() {
std::vector<int> kounts(kp1,0);
std::vector<int> kount50(20,0);
for (Long64_t jentry=0; jentry<nentries;jentry++) {
//for (Long64_t jentry=0; jentry<200;jentry++) {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
Expand Down Expand Up @@ -1100,9 +1101,11 @@ bool CalibMonitor::goodTrack(double& eHcal, double &cuti, bool debug) {
}
correctEnergy(eHcal);
select = ((t_qltyFlag) && (t_selectTk) && (t_hmaxNearP < cut) &&
(t_eMipDR < 1.0));
(t_eMipDR < 1.0) && (eHcal > 0.001));
if (debug) {
std::cout << " output " << eHcal << ":" << cut << ":" << select<< std::endl;
std::cout << " output " << select << " Based on " << t_qltyFlag << ":"
<< t_selectTk << ":" << t_hmaxNearP << ":" << cut << ":"
<< t_eMipDR << ":" << eHcal << std::endl;
}
return select;
}
Expand Down Expand Up @@ -1263,7 +1266,7 @@ void CalibMonitor::savePlot(const std::string& theName, bool append, bool all) {
}

void CalibMonitor::correctEnergy(double& eHcal) {

bool debug(false);
double pmom = (useGen_ && (t_gentrackP>0)) ? t_gentrackP : t_p;
if ((corrPU_ < 0) && (pmom > 0)) {
double ediff = (t_eHcal30-t_eHcal10);
Expand All @@ -1286,7 +1289,13 @@ void CalibMonitor::correctEnergy(double& eHcal) {
}
ediff = (Etot3-Etot1);
}
double fac = puFactor(-corrPU_,t_ieta,pmom,eHcal,ediff);
double fac = puFactor(-corrPU_,t_ieta,pmom,eHcal,ediff,false);
if (debug) {
double fac1 = puFactor(-corrPU_,t_ieta,pmom,eHcal,ediff,true);
double fac2 = puFactor(2,t_ieta,pmom,eHcal,ediff,true);
std::cout << "PU Factor for " << -corrPU_ << " = " << fac1 << "; for 2 = "
<< fac2 << std::endl;
}
eHcal *= fac;
} else if (corrPU_ > 0) {
eHcal = puFactorRho(corrPU_,t_ieta,t_rhoh,eHcal);
Expand Down Expand Up @@ -2485,15 +2494,25 @@ void CalibPlotProperties::Loop() {

if (plotHists_) {
h_nvtx->Fill(t_nVtx);
if ((std::fabs(rat-1)<0.15) && (kp == kp50) &&
bool bad(false);
for (unsigned int k=0; k<t_HitEnergies->size(); ++k) {
unsigned int id = truncateId((*t_DetIds)[k],truncateFlag_,false);
double cfac = corrFactor_->getCorr(id);
if (cFactor_ != 0)
cfac *= cFactor_->getCorr(t_Run,(*t_DetIds)[k]);
double ener = cfac*(*t_HitEnergies)[k];
if (corrPU_) correctEnergy(ener);
if (ener < 0.001) bad = true;
}
if ((!bad) && (std::fabs(rat-1)<0.15) && (kp == kp50) &&
((std::abs(t_ieta) < 15) || (std::abs(t_ieta) > 17))) {
float weight = (dataMC_ ? t_EventWeight :
t_EventWeight*puweight(t_nVtx));
h_etaE->Fill(t_ieta,eHcal,weight);
sel += weight;
std::vector<float> bv(7,0.0f), ev(7,0.0f);
std::vector<int> bnrec(7,0), enrec(7,0);
double eb(0), ee(0);
double eb(0), ee(0);
for (unsigned int k=0; k<t_HitEnergies->size(); ++k) {
unsigned int id = truncateId((*t_DetIds)[k],truncateFlag_,false);
double cfac = corrFactor_->getCorr(id);
Expand Down Expand Up @@ -2559,7 +2578,7 @@ bool CalibPlotProperties::goodTrack(double& eHcal, double &cuti, bool debug) {
}
correctEnergy(eHcal);
select = ((t_qltyFlag) && (t_selectTk) && (t_hmaxNearP < cut) &&
(t_eMipDR < 100.0));
(t_eMipDR < 100.0) && (eHcal > 0.001));
if (debug) {
std::cout << " output " << eHcal << ":" << cut << ":" << select<< std::endl;
}
Expand Down

0 comments on commit 98c17f1

Please sign in to comment.