Skip to content

Commit a2780ef

Browse files
author
Sunanda
committed
Code check
1 parent 44dc539 commit a2780ef

File tree

2 files changed

+65
-54
lines changed

2 files changed

+65
-54
lines changed

Calibration/HcalCalibAlgos/macros/CalibFitPlots.C

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -568,30 +568,30 @@ results fitOneGauss(TH1D* hist, bool fitTwice, bool debug) {
568568
return results(value, error, width, werror);
569569
}
570570

571-
double DoubleSidedCrystalballFunction(double *x, double *par) {
572-
double alpha_l = par[0];
573-
double alpha_h = par[1];
574-
double n_l = par[2];
575-
double n_h = par[3];
576-
double mean = par[4];
577-
double sigma = par[5];
578-
double N = par[6];
579-
float t = (x[0]-mean)/sigma;
571+
double DoubleSidedCrystalballFunction(double* x, double* par) {
572+
double alpha_l = par[0];
573+
double alpha_h = par[1];
574+
double n_l = par[2];
575+
double n_h = par[3];
576+
double mean = par[4];
577+
double sigma = par[5];
578+
double N = par[6];
579+
float t = (x[0] - mean) / sigma;
580580
double result;
581-
double fact1TLessMinosAlphaL = alpha_l/n_l;
582-
double fact2TLessMinosAlphaL = (n_l/alpha_l) - alpha_l -t;
583-
double fact1THihgerAlphaH = alpha_h/n_h;
581+
double fact1TLessMinosAlphaL = alpha_l / n_l;
582+
double fact2TLessMinosAlphaL = (n_l / alpha_l) - alpha_l - t;
583+
double fact1THihgerAlphaH = alpha_h / n_h;
584584
// double fact2THigherAlphaH = (n_h/alpha_h) - alpha_h + t;
585-
585+
586586
if (-alpha_l <= t && alpha_h >= t) {
587587
result = exp(-0.5 * t * t);
588588
} else if (t < -alpha_l) {
589-
result = exp(-0.5 * alpha_l * alpha_l) * pow(fact1TLessMinosAlphaL * fact2TLessMinosAlphaL, -n_l);
589+
result = exp(-0.5 * alpha_l * alpha_l) * pow(fact1TLessMinosAlphaL * fact2TLessMinosAlphaL, -n_l);
590590
} else if (t > alpha_h) {
591-
result = exp(-0.5 * alpha_l * alpha_l) * pow(fact1THihgerAlphaH * fact1THihgerAlphaH, -n_h);
591+
result = exp(-0.5 * alpha_l * alpha_l) * pow(fact1THihgerAlphaH * fact1THihgerAlphaH, -n_h);
592592
}
593593
return N * result;
594-
}
594+
}
595595

596596
results fitDoubleSidedCrystalball(TH1D* hist, bool /* fitTwice */, bool debug) {
597597
double rms;
@@ -619,17 +619,18 @@ results fitDoubleSidedCrystalball(TH1D* hist, bool /* fitTwice */, bool debug) {
619619
if (LowEdge < 0.5)
620620
LowEdge = 0.5;
621621
diff = Fit1->Value(1) - LowEdge;
622-
HighEdge = (diff > fitrangeFactor1 * rms) ? (Fit1->Value(1) + fitrangeFactor1 * Fit1->Value(2)) : (Fit1->Value(1) + 1.5 * diff);
622+
HighEdge = (diff > fitrangeFactor1 * rms) ? (Fit1->Value(1) + fitrangeFactor1 * Fit1->Value(2))
623+
: (Fit1->Value(1) + 1.5 * diff);
623624
if (HighEdge > 5.0)
624625
HighEdge = 5.0;
625626
if (debug)
626627
std::cout << " Range for second Fit " << LowEdge << ":" << HighEdge << std::endl;
627628
TObject* ob2 = gROOT->FindObject("fitDSCB");
628629
if (ob2 != nullptr)
629630
ob2->Delete();
630-
TF1 *fitDSCB = new TF1("fitDSCB", DoubleSidedCrystalballFunction, LowEdge, HighEdge, 7);
631+
TF1* fitDSCB = new TF1("fitDSCB", DoubleSidedCrystalballFunction, LowEdge, HighEdge, 7);
631632
fitDSCB->SetParameters(1, 2, 2, 1, value, width, hist->Integral(LowEdge, HighEdge));
632-
fitDSCB->SetParNames ("alpha_{low}","alpha_{high}","n_{low}", "n_{high}", "mean", "sigma", "Norm");
633+
fitDSCB->SetParNames("alpha_{low}", "alpha_{high}", "n_{low}", "n_{high}", "mean", "sigma", "Norm");
633634
TFitResultPtr Fit = hist->Fit(fitDSCB, option.c_str(), "", LowEdge, HighEdge);
634635
value = Fit->Value(4);
635636
error = Fit->FitResult::Error(4);
@@ -770,7 +771,8 @@ void FitHistStandard(std::string infile,
770771
}
771772
if (hist->GetEntries() > 4) {
772773
bool flag = (j == 0) ? true : false;
773-
results meaner = (((type / 10) % 10) == 0) ? fitOneGauss(hist, flag, debug) : fitDoubleSidedCrystalball(hist, flag, debug);
774+
results meaner = (((type / 10) % 10) == 0) ? fitOneGauss(hist, flag, debug)
775+
: fitDoubleSidedCrystalball(hist, flag, debug);
774776
value = meaner.mean;
775777
error = meaner.errmean;
776778
width = meaner.width;
@@ -889,7 +891,8 @@ void FitHistExtended(const char* infile,
889891
}
890892
if (hist0->GetEntries() > 10) {
891893
double rms;
892-
results meaner0 = (((type / 10) % 10) == 0) ? fitOneGauss(hist0, true, debug) : fitDoubleSidedCrystalball(hist0, true, debug);
894+
results meaner0 =
895+
(((type / 10) % 10) == 0) ? fitOneGauss(hist0, true, debug) : fitDoubleSidedCrystalball(hist0, true, debug);
893896
std::pair<double, double> meaner1 = GetMean(hist0, 0.2, 2.0, rms);
894897
std::pair<double, double> meaner2 = GetWidth(hist0, 0.2, 2.0);
895898
if (debug) {
@@ -931,15 +934,17 @@ void FitHistExtended(const char* infile,
931934
if (j == 0) {
932935
sprintf(name, "%sOne", hist1->GetName());
933936
TH1D* hist2 = (TH1D*)hist1->Clone(name);
934-
fitOneGauss(hist2, true, debug);
937+
fitOneGauss(hist2, true, debug);
935938
hists.push_back(hist2);
936-
results meaner = (((type / 10) % 10) == 0) ? fitOneGauss(hist, true, debug) : fitDoubleSidedCrystalball(hist, true, debug);
939+
results meaner = (((type / 10) % 10) == 0) ? fitOneGauss(hist, true, debug)
940+
: fitDoubleSidedCrystalball(hist, true, debug);
937941
value = meaner.mean;
938942
error = meaner.errmean;
939943
width = meaner.width;
940944
werror = meaner.errwidth;
941945
} else {
942-
results meaner = (((type / 10) % 10) == 0) ? fitOneGauss(hist, true, debug) : fitDoubleSidedCrystalball(hist, true, debug);
946+
results meaner = (((type / 10) % 10) == 0) ? fitOneGauss(hist, true, debug)
947+
: fitDoubleSidedCrystalball(hist, true, debug);
943948
value = meaner.mean;
944949
error = meaner.errmean;
945950
width = meaner.width;
@@ -1010,7 +1015,8 @@ void FitHistExtended(const char* infile,
10101015
if (total > 4) {
10111016
sprintf(name, "%sOne", hist1->GetName());
10121017
TH1D* hist2 = (TH1D*)hist1->Clone(name);
1013-
results meanerr = (((type / 10) % 10) == 0) ? fitOneGauss(hist2, true, debug) : fitDoubleSidedCrystalball(hist2, true, debug);
1018+
results meanerr = (((type / 10) % 10) == 0) ? fitOneGauss(hist2, true, debug)
1019+
: fitDoubleSidedCrystalball(hist2, true, debug);
10141020
value = meanerr.mean;
10151021
error = meanerr.errmean;
10161022
width = meanerr.width;
@@ -1027,7 +1033,8 @@ void FitHistExtended(const char* infile,
10271033
hists.push_back(hist3);
10281034
}
10291035
// results meaner0 = fitTwoGauss(hist, debug);
1030-
results meaner0 = (((type / 10) % 10) == 0) ? fitOneGauss(hist, true, debug) : fitDoubleSidedCrystalball(hist, true, debug);
1036+
results meaner0 = (((type / 10) % 10) == 0) ? fitOneGauss(hist, true, debug)
1037+
: fitDoubleSidedCrystalball(hist, true, debug);
10311038
value = meaner0.mean;
10321039
error = meaner0.errmean;
10331040
double rms;
@@ -1071,7 +1078,7 @@ void FitHistExtended2(const char* infile,
10711078
const char* outfile,
10721079
std::string prefix,
10731080
int numb = 50,
1074-
int type = 0,
1081+
int type = 0,
10751082
bool append = true,
10761083
int iname = 3,
10771084
bool debug = false) {
@@ -1143,15 +1150,17 @@ void FitHistExtended2(const char* infile,
11431150
if (j == 0) {
11441151
sprintf(name, "%sOne", hist1->GetName());
11451152
TH1D* hist2 = (TH1D*)hist1->Clone(name);
1146-
fitOneGauss(hist2, true, debug);
1153+
fitOneGauss(hist2, true, debug);
11471154
hists.push_back(hist2);
1148-
results meaner = (((type / 10) % 10) == 0) ? fitOneGauss(hist, true, debug) : fitDoubleSidedCrystalball(hist, true, debug);
1155+
results meaner = (((type / 10) % 10) == 0) ? fitOneGauss(hist, true, debug)
1156+
: fitDoubleSidedCrystalball(hist, true, debug);
11491157
value = meaner.mean;
11501158
error = meaner.errmean;
11511159
width = meaner.width;
11521160
werror = meaner.errwidth;
11531161
} else {
1154-
results meaner = (((type / 10) % 10) == 0) ? fitOneGauss(hist, true, debug) : fitDoubleSidedCrystalball(hist, true, debug);
1162+
results meaner = (((type / 10) % 10) == 0) ? fitOneGauss(hist, true, debug)
1163+
: fitDoubleSidedCrystalball(hist, true, debug);
11551164
value = meaner.mean;
11561165
error = meaner.errmean;
11571166
width = meaner.width;
@@ -1227,7 +1236,8 @@ void FitHistExtended2(const char* infile,
12271236
if (total > 4) {
12281237
sprintf(name, "%sOne", hist1->GetName());
12291238
TH1D* hist2 = (TH1D*)hist1->Clone(name);
1230-
results meanerr = (((type / 10) % 10) == 0) ? fitOneGauss(hist2, true, debug) : fitDoubleSidedCrystalball(hist2, true, debug);
1239+
results meanerr = (((type / 10) % 10) == 0) ? fitOneGauss(hist2, true, debug)
1240+
: fitDoubleSidedCrystalball(hist2, true, debug);
12311241
value = meanerr.mean;
12321242
error = meanerr.errmean;
12331243
width = meanerr.width;
@@ -1237,7 +1247,8 @@ void FitHistExtended2(const char* infile,
12371247
std::cout << hist2->GetName() << " MPV " << value << " +- " << error << " Width " << width << " +- "
12381248
<< werror << " W/M " << wbyv << " +- " << wverr << std::endl;
12391249
hists.push_back(hist2);
1240-
results meaner0 = (((type / 10) % 10) == 0) ? fitOneGauss(hist, true, debug) : fitDoubleSidedCrystalball(hist, true, debug);
1250+
results meaner0 = (((type / 10) % 10) == 0) ? fitOneGauss(hist, true, debug)
1251+
: fitDoubleSidedCrystalball(hist, true, debug);
12411252
value = meaner0.mean;
12421253
error = meaner0.errmean;
12431254
double rms;

Calibration/HcalCalibAlgos/macros/CalibPlotProperties.C

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//
2727
// This will plot two superimposed histograms from the two files
2828
// with the possibility of normalizing and save the canvases
29-
//
29+
//
3030
// .L CalibPlotProperties.C+g
3131
// CalibSplit c1(fname, dirname, outFileName, pmin, pmax, runMin, runMax,
3232
// debug);
@@ -1126,14 +1126,14 @@ void CalibPlotProperties::Loop(Long64_t nentries) {
11261126
h_mom[je2]->Fill(pmom, t_EventWeight);
11271127
h_eEcal[je1]->Fill(t_eMipDR, t_EventWeight);
11281128
h_eEcal[je2]->Fill(t_eMipDR, t_EventWeight);
1129-
if (final) {
1130-
h_eHcalX[je1]->Fill(eHcal, t_EventWeight);
1131-
h_eHcalX[je2]->Fill(eHcal, t_EventWeight);
1132-
h_momX[je1]->Fill(pmom, t_EventWeight);
1133-
h_momX[je2]->Fill(pmom, t_EventWeight);
1134-
h_eEcalX[je1]->Fill(t_eMipDR, t_EventWeight);
1135-
h_eEcalX[je2]->Fill(t_eMipDR, t_EventWeight);
1136-
}
1129+
if (final) {
1130+
h_eHcalX[je1]->Fill(eHcal, t_EventWeight);
1131+
h_eHcalX[je2]->Fill(eHcal, t_EventWeight);
1132+
h_momX[je1]->Fill(pmom, t_EventWeight);
1133+
h_momX[je2]->Fill(pmom, t_EventWeight);
1134+
h_eEcalX[je1]->Fill(t_eMipDR, t_EventWeight);
1135+
h_eEcalX[je2]->Fill(t_eMipDR, t_EventWeight);
1136+
}
11371137
}
11381138
}
11391139
}
@@ -1172,15 +1172,15 @@ void CalibPlotProperties::Loop(Long64_t nentries) {
11721172
eb += ener;
11731173
bv[depth - 1] += ener;
11741174
h_bvlist2[depth - 1]->Fill(ener, weight);
1175-
if (final)
1176-
h_bvlist2X[depth - 1]->Fill(ener, weight);
1175+
if (final)
1176+
h_bvlist2X[depth - 1]->Fill(ener, weight);
11771177
++bnrec[depth - 1];
11781178
} else if (subdet == 2) {
11791179
ee += ener;
11801180
ev[depth - 1] += ener;
11811181
h_evlist2[depth - 1]->Fill(ener, weight);
1182-
if (final)
1183-
h_evlist2X[depth - 1]->Fill(ener, weight);
1182+
if (final)
1183+
h_evlist2X[depth - 1]->Fill(ener, weight);
11841184
++enrec[depth - 1];
11851185
}
11861186
}
@@ -1195,17 +1195,17 @@ void CalibPlotProperties::Loop(Long64_t nentries) {
11951195
if (barrel) {
11961196
h_bvlist[i]->Fill(bv[i], weight);
11971197
h_bvlist3[i]->Fill((bnrec[i] + 0.001), weight);
1198-
if (final) {
1199-
h_bvlistX[i]->Fill(bv[i], weight);
1200-
h_bvlist3X[i]->Fill((bnrec[i] + 0.001), weight);
1201-
}
1198+
if (final) {
1199+
h_bvlistX[i]->Fill(bv[i], weight);
1200+
h_bvlist3X[i]->Fill((bnrec[i] + 0.001), weight);
1201+
}
12021202
} else {
12031203
h_evlist[i]->Fill(ev[i], weight);
12041204
h_evlist3[i]->Fill((enrec[i] + 0.001), weight);
1205-
if (final) {
1206-
h_evlistX[i]->Fill(ev[i], weight);
1207-
h_evlist3X[i]->Fill((enrec[i] + 0.001), weight);
1208-
}
1205+
if (final) {
1206+
h_evlistX[i]->Fill(ev[i], weight);
1207+
h_evlist3X[i]->Fill((enrec[i] + 0.001), weight);
1208+
}
12091209
}
12101210
}
12111211
}
@@ -1989,7 +1989,7 @@ void PlotHist(const char *hisFileName,
19891989
hist->GetXaxis()->SetTitle(title);
19901990
PlotThisHist(hist, text, isRealData, save);
19911991
}
1992-
1992+
19931993
sprintf(name, "b_edepthX%d", i);
19941994
hist = (TH1D *)(file->FindObjectAny(name));
19951995
if (hist != nullptr) {

0 commit comments

Comments
 (0)