35 unsigned short wireID;
36 unsigned short layerID;
41 efftree->SetBranchAddress(
"wireID", &wireID);
42 efftree->SetBranchAddress(
"layerID", &layerID);
43 efftree->SetBranchAddress(
"z", &z);
44 efftree->SetBranchAddress(
"isFound", &isFound);
49 std::vector<long long> wireCounts;
52 unsigned short layerNo = wireLayer.getICLayer();
54 wireCounts.resize(wireCounts.size() + nwidbins, 0);
57 const Long64_t nEntries = efftree->GetEntries();
59 for (Long64_t i = 0; i < nEntries; i++) {
64 unsigned int totalCountsForActiveWires = 0;
65 unsigned int activeWireCount = 0;
67 for (
auto count : wireCounts) {
69 totalCountsForActiveWires += count;
74 double averageOccupancy =
75 (activeWireCount > 0) ? (1.0 * totalCountsForActiveWires / activeWireCount) : 0.0;
79 B2INFO(
"Will run the calibration for this run with enough hits per wire: " << averageOccupancy);
81 B2WARNING(
"Not enough hits per wire in this run: " << averageOccupancy);
87 unsigned short wireID;
88 unsigned short layerID;
93 efftree->SetBranchAddress(
"wireID", &wireID);
94 efftree->SetBranchAddress(
"layerID", &layerID);
95 efftree->SetBranchAddress(
"z", &z);
96 efftree->SetBranchAddress(
"isFound", &isFound);
102 unsigned short layerNo = wireLayer.getICLayer();
104 unsigned short nzbins = 30 - layerNo / 7;
107 double widbins[2] = { -0.5, (double)cdcgeo.
nWiresInLayer(layerNo) - 0.5};
108 double zbins[2] = {wireLayer.getBackwardZ(), wireLayer.getForwardZ()};
110 TEfficiency* effInLayer =
new TEfficiency(
111 Form(
"effLayer_%d", layerNo),
112 Form(
"Hit efficiency of L%d ; z (cm) ; IWire ", layerNo),
113 nzbins, zbins[0], zbins[1], nwidbins, widbins[0], widbins[1]);
118 const Long64_t nEntries = efftree->GetEntries();
120 for (Long64_t i = 0; i < nEntries; i++) {
121 efftree->GetEntry(i);
123 if (layerID < m_efficiencyList->GetEntries()) {
124 TEfficiency* efficiencyInLayer =
127 efficiencyInLayer->Fill(isFound, z, wireID);
131 TFile* outputCollection =
new TFile(
"LayerEfficiencies.root",
"RECREATE");
133 outputCollection->Close();
134 delete outputCollection;
142 unsigned short layerNo = wireLayer.getICLayer();
146 auto passed = (TH2F*)efficiencyInLayer->GetPassedHistogram();
147 auto total = (TH2F*)efficiencyInLayer->GetTotalHistogram();
150 if (!total->GetEntries())
continue;
153 double minFitRange = wireLayer.getBackwardZ() + 30;
154 double maxFitRange = wireLayer.getForwardZ() - 30;
155 TF1* constantFunction =
new TF1(
"constantFunction",
"pol0", minFitRange, maxFitRange);
158 auto passedProjectedX = passed->ProjectionX(
"projectionx1");
159 auto totalProjectedX = total->ProjectionX(
"projectionx2");
160 TEfficiency* efficiencyProjectedX =
new TEfficiency(*passedProjectedX, *totalProjectedX);
162 unsigned short minFitBin = passedProjectedX->FindBin(minFitRange) + 1;
163 unsigned short maxFitBin = passedProjectedX->FindBin(maxFitRange) - 1;
166 auto passedProjectedY = passed->ProjectionY(
"projectiony1", minFitBin, maxFitBin);
167 auto totalProjectedY = total->ProjectionY(
"projectiony2", minFitBin, maxFitBin);
168 TEfficiency* efficiencyProjectedY =
new TEfficiency(*passedProjectedY, *totalProjectedY);
171 float totalAverage = 0;
172 int nonZeroWires = 0;
173 for (
int i = 1; i <= passedProjectedY->GetNbinsX(); ++i) {
174 float efficiencyAtBin = efficiencyProjectedY->GetEfficiency(i);
175 if (efficiencyAtBin > 0.2) {
176 totalAverage += efficiencyAtBin;
181 if (nonZeroWires > 0) totalAverage /= nonZeroWires;
182 else totalAverage = 0;
184 TGraphAsymmErrors* graphEfficiencyProjected = efficiencyProjectedX->CreateGraph();
187 for (
int i = 1; i <= passed->GetNbinsY(); ++i) {
190 auto singleWirePassed = passed->ProjectionX(
"single wire projection passed", i, i);
191 auto singleWireTotal = total->ProjectionX(
"single wire projection total", i, i);
194 if (!singleWirePassed->Integral(minFitBin, maxFitBin)) {
195 double wireID = passed->GetYaxis()->GetBinCenter(i);
197 if (wireID < 0 || wireID >= maxWires) {
198 B2ERROR(
"Invalid wireID: " << wireID <<
" for LayerID: " << layerNo
199 <<
". Max wires: " << maxWires);
206 TEfficiency* singleWireEfficiency =
new TEfficiency(*singleWirePassed, *singleWireTotal);
207 TGraphAsymmErrors* graphSingleWireEfficiency = singleWireEfficiency->CreateGraph();
210 TFitResultPtr singleWireFitResults = graphSingleWireEfficiency->Fit(constantFunction,
"SQR");
211 double singleWireEfficiencyFromFit = (singleWireFitResults.Get())->Value(0);
212 double singleWireUpErrorFromFit = (singleWireFitResults.Get())->UpperError(0);
215 float p_value =
chiTest(graphSingleWireEfficiency, graphEfficiencyProjected, minFitRange, maxFitRange);
217 bool averageCondition = (0.95 * totalAverage) > (singleWireEfficiencyFromFit + 3 * singleWireUpErrorFromFit);
218 bool pvalueCondition = p_value < 0.01;
219 bool generalCondition = singleWireEfficiencyFromFit < 0.4;
220 if (generalCondition || (averageCondition && pvalueCondition)) {
221 double wireID = passed->GetYaxis()->GetBinCenter(i);
222 m_badWireList->setWire(layerNo, round(wireID), singleWireEfficiencyFromFit);
232 unsigned short ndof = 0;
234 int numOfEntries1 = graph1->GetN();
235 int numOfEntries2 = graph2->GetN();
238 for (
int index1 = 0; index1 < numOfEntries1; ++index1) {
240 if (graph1->GetX()[index1] < minValue)
continue;
241 if (graph1->GetX()[index1] > maxValue)
continue;
242 for (
int index2 = 0; index2 < numOfEntries2; ++index2) {
243 if (std::abs(graph1->GetX()[index1] - graph2->GetX()[index2]) < 1e-6) {
245 double chiNumerator = std::pow(graph1->GetY()[index1] - graph2->GetY()[index2], 2);
246 double err1 = 0.5 * (graph1->GetErrorYhigh(index1) + graph1->GetErrorYlow(index1));
247 double err2 = 0.5 * (graph2->GetErrorYhigh(index2) + graph2->GetErrorYlow(index2));
248 double chiDenominator = err1 * err1 + err2 * err2;
250 chi += chiNumerator / chiDenominator;
256 return TMath::Prob(chi, ndof);