File indexing completed on 2026-05-23 08:12:15
0001 #include "analysisHelper.h"
0002 #include "RooUnfoldResponse.h"
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 void fillResponse(int jetSample = 20, int seg = 0, const char* outDir = ".",
0046 Mode mode = Mode::kFull, float towCut = 0.25)
0047 {
0048 const bool halfClosure = (mode == Mode::kHalf);
0049 const bool vtxOnly = (mode == Mode::kVtx);
0050
0051 std::string outName = std::format(
0052 "{}/Jet{}/response_Jet{}_seg{:06d}_to_{:06d}-{}.root",
0053 outDir, jetSample, jetSample, seg, seg + 24, ModeLabel(mode));
0054
0055 std::cout << "making file " << outName << std::endl;
0056 std::cout.flush();
0057
0058 TFile* fOut = new TFile(outName.c_str(), "RECREATE");
0059
0060 std::cout << "made file " << outName << std::endl;
0061 std::cout.flush();
0062
0063
0064
0065
0066
0067 TH1D* hVtxMC = new TH1D("hVtxMC",
0068 "MC vtx_z (xsec weighted);v_{z} (cm);weighted events",
0069 nVtxBins, vtxZMin, vtxZMax);
0070 hVtxMC->Sumw2();
0071
0072 if (vtxOnly)
0073 {
0074
0075
0076
0077 TFile* simFile = new TFile(SimFilePath(jetSample, seg).c_str(), "READ");
0078 if (!simFile || simFile->IsZombie()) {
0079 std::cerr << "Cannot open sim file\n";
0080 fOut->Close(); return;
0081 }
0082
0083 TTree* T = (TTree*)simFile->Get("T");
0084 if (!T) { simFile->Close(); fOut->Close(); return; }
0085
0086 EventInfo* eventInfo = nullptr;
0087 std::vector<JetInfo>* truthJets = nullptr;
0088 T->SetBranchAddress("EventInfo", &eventInfo);
0089 T->SetBranchAddress("TruthJetInfo_r04", &truthJets);
0090
0091 long nEvents = T->GetEntries();
0092 for (long ev = 0; ev < nEvents; ++ev) {
0093 std::cout << "kVtx: working on event " << ev << std::endl;
0094 T->GetEntry(ev);
0095
0096 double vtx_z = eventInfo->get_z_vtx();
0097 if (std::abs(vtx_z) > 10.0) continue;
0098
0099
0100 double maxTruthPT = -1;
0101 for (auto& j : *truthJets)
0102 if (j.pt() > maxTruthPT) maxTruthPT = j.pt();
0103 if (maxTruthPT < get_jet_pTLow(jetSample) ||
0104 maxTruthPT > get_jet_pTHigh(jetSample)) continue;
0105
0106 double evtWeight = eventInfo->get_cross_section();
0107 hVtxMC->Fill(vtx_z, evtWeight);
0108 }
0109
0110 simFile->Close(); delete simFile;
0111
0112 fOut->cd();
0113 hVtxMC->Write();
0114 fOut->Close();
0115 std::cout << "Written (vtxOnly): " << outName << "\n";
0116 return;
0117 }
0118
0119
0120 TH1D* hJetPt_truth_matched = new TH1D("hJetPt_truth_matched", "", nTrueFlat(), 0, nTrueFlat());
0121 TH1D* hJetPt_truth = new TH1D("hJetPt_truth", "", nTrueFlat(), 0, nTrueFlat());
0122 TH1D* hJetPt_reco_matched = new TH1D("hJetPt_reco_matched", "", nRecoFlat(), 0, nRecoFlat());
0123 TH1D* hJetPt_reco = new TH1D("hJetPt_reco", "", nRecoFlat(), 0, nRecoFlat());
0124 TH1D* hJetPt_meas = new TH1D("hJetPt_meas", "", nRecoFlat(), 0, nRecoFlat());
0125 TH1D* hJetPt_truth_meas = new TH1D("hJetPt_truth_meas", "", nTrueFlat(), 0, nTrueFlat());
0126 hJetPt_truth_matched->Sumw2(); hJetPt_truth ->Sumw2();
0127 hJetPt_reco_matched ->Sumw2(); hJetPt_reco ->Sumw2();
0128 hJetPt_meas ->Sumw2(); hJetPt_truth_meas ->Sumw2();
0129
0130 std::cout << "made jet hists" << std::endl;
0131 std::cout.flush();
0132
0133 RooUnfoldResponse* respJetPt = nullptr;
0134 {
0135
0136
0137 respJetPt = new RooUnfoldResponse(nRecoFlat(), 0, nRecoFlat(), nTrueFlat(), 0, nTrueFlat());
0138 }
0139
0140 std::cout << "made jet response matrix" << std::endl;
0141 std::cout.flush();
0142
0143
0144
0145
0146
0147
0148
0149
0150 std::vector<RooUnfoldResponse*> respWEEC3D(nDphi, nullptr);
0151 for (int k = 0; k < nDphi; ++k)
0152 {
0153
0154
0155 respWEEC3D[k] = new RooUnfoldResponse(nRecoFlat3D(), 0, nRecoFlat3D(), nTrueFlat3D(), 0, nTrueFlat3D());
0156 }
0157
0158 std::cout << "made 3D response matrices" << std::endl;
0159 std::cout.flush();
0160
0161
0162
0163
0164
0165 std::vector<TH1D*> hWEEC3D_truth(nDphi, nullptr);
0166 std::vector<TH1D*> hWEEC3D_misses(nDphi, nullptr);
0167 for (int k = 0; k < nDphi; ++k) {
0168 hWEEC3D_truth[k] = new TH1D(
0169 std::format("hWEEC3D_truth_{}", k).c_str(),
0170 std::format("Truth wEEC 3D k{};flat(iL,iS,iPw);pairs", k).c_str(),
0171 nTrueFlat3D(), 0, nTrueFlat3D());
0172 hWEEC3D_truth[k]->Sumw2();
0173
0174 hWEEC3D_misses[k] = new TH1D(
0175 std::format("hWEEC3D_misses_{}", k).c_str(),
0176 std::format("Misses wEEC 3D k{};flat(iL,iS,iPw);pairs", k).c_str(),
0177 nTrueFlat3D(), 0, nTrueFlat3D());
0178 hWEEC3D_misses[k]->Sumw2();
0179 }
0180
0181 std::cout << "made 3D truth hists" << std::endl;
0182 std::cout.flush();
0183
0184
0185
0186
0187
0188
0189
0190
0191 std::vector<TH1D*> hWEEC3D_pwNum(nDphi, nullptr);
0192 std::vector<TH1D*> hWEEC3D_pwDen(nDphi, nullptr);
0193 for (int k = 0; k < nDphi; ++k) {
0194 hWEEC3D_pwNum[k] = new TH1D(
0195 std::format("hWEEC3D_pwNum_{}", k).c_str(),
0196 std::format("PW num k{};flat(iL,iS,iPw);sum(w*evtW)", k).c_str(),
0197 nTrueFlat3D(), 0, nTrueFlat3D());
0198 hWEEC3D_pwDen[k] = new TH1D(
0199 std::format("hWEEC3D_pwDen_{}", k).c_str(),
0200 std::format("PW den k{};flat(iL,iS,iPw);sum(evtW)", k).c_str(),
0201 nTrueFlat3D(), 0, nTrueFlat3D());
0202 hWEEC3D_pwNum[k]->Sumw2();
0203 hWEEC3D_pwDen[k]->Sumw2();
0204 }
0205
0206
0207 std::vector<TH1D*> hWEEC3D_meas(nDphi, nullptr);
0208 std::vector<TH1D*> hWEEC3D_fakes(nDphi, nullptr);
0209 std::vector<TH1D*> hWEEC3D_meas_truth(nDphi, nullptr);
0210 for (int k = 0; k < nDphi; ++k) {
0211 hWEEC3D_meas[k] = new TH1D(
0212 std::format("hWEEC3D_meas_{}", k).c_str(),
0213 std::format("Meas wEEC 3D k{};flat(iL,iS,iPw);pairs", k).c_str(),
0214 nRecoFlat3D(), 0, nRecoFlat3D());
0215 hWEEC3D_meas[k]->Sumw2();
0216
0217 hWEEC3D_fakes[k] = new TH1D(
0218 std::format("hWEEC3D_fakes_{}", k).c_str(),
0219 std::format("Fakes wEEC 3D k{};flat(iL,iS,iPw);pairs", k).c_str(),
0220 nRecoFlat3D(), 0, nRecoFlat3D());
0221 hWEEC3D_fakes[k]->Sumw2();
0222
0223 hWEEC3D_meas_truth[k] = new TH1D(
0224 std::format("hWEEC3D_meas_truth_{}", k).c_str(),
0225 std::format("Truth Meas Half wEEC 3D k{};flat(iL,iS,iPw);pairs", k).c_str(),
0226 nTrueFlat3D(), 0, nTrueFlat3D());
0227 hWEEC3D_meas_truth[k]->Sumw2();
0228 }
0229
0230 std::cout << "made 3D meas hists" << std::endl;
0231 std::cout.flush();
0232
0233
0234
0235
0236
0237
0238
0239 std::vector<TH2D*> hWEEC3D_counts(nDphi, nullptr);
0240 for (int k = 0; k < nDphi; ++k) {
0241 hWEEC3D_counts[k] = new TH2D(
0242 std::format("hWEEC3D_counts_{}", k).c_str(),
0243 std::format("Counts wEEC 3D k{};reco flat3D;truth flat3D", k).c_str(),
0244 nRecoFlat3D(), 0, nRecoFlat3D(),
0245 nTrueFlat3D(), 0, nTrueFlat3D());
0246
0247 }
0248
0249 std::cout << "made 3D counts hists" << std::endl;
0250 std::cout.flush();
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264 TH1D* hWEEC_particle = new TH1D("hWEEC_particle",
0265 "Particle-level wEEC;#Delta#phi;wEEC", nDphi, dPhiBins.data());
0266 TH1D* hWEEC_truthTower = new TH1D("hWEEC_truthTower",
0267 "Truth-tower wEEC;#Delta#phi;wEEC", nDphi, dPhiBins.data());
0268 hWEEC_particle ->Sumw2();
0269 hWEEC_truthTower->Sumw2();
0270
0271 TFile* simFile = new TFile(SimFilePath(jetSample, seg).c_str(), "READ");
0272 if (!simFile || simFile->IsZombie()) {
0273 std::cerr << "Cannot open " << SimFilePath(jetSample, seg) << "\n";
0274 if (simFile) delete simFile; return;
0275 }
0276 TTree* T = (TTree*)simFile->Get("T");
0277 if (!T) { simFile->Close(); delete simFile; return; }
0278
0279 TRandom3 rng(jetSample * 100000 + seg);
0280
0281
0282 EventInfo* eventInfo = nullptr;
0283 std::vector<JetInfo>* recoJets = nullptr;
0284 std::vector<JetInfo>* truthJets = nullptr;
0285 std::vector<Tower>* towers = nullptr;
0286 std::vector<Tower>* particles = nullptr;
0287
0288 T->SetBranchAddress("EventInfo", &eventInfo);
0289 T->SetBranchAddress("JetInfo_r04", &recoJets);
0290 T->SetBranchAddress("TruthJetInfo_r04", &truthJets);
0291 T->SetBranchAddress("TowerInfo", &towers);
0292 T->SetBranchAddress("TruthParticles", &particles);
0293
0294
0295 long nEvents = T->GetEntries();
0296 long nGood = 0, nGoodReco = 0, nGoodTruth = 0, nMatched = 0;
0297 for (long ev = 0; ev < nEvents; ++ev)
0298 {
0299 T->GetEntry(ev);
0300
0301 const bool isEven = (rng.Rndm() < 0.5);
0302 const bool fillResp = !halfClosure || isEven;
0303 const bool fillMeas = !halfClosure || !isEven;
0304
0305 double vtx_z = eventInfo->get_z_vtx();
0306
0307 std::cout << std::format("Working on event {:5d}: vtx_z={:.2f}\n", ev, vtx_z);
0308 std::cout.flush();
0309
0310 if (std::abs(vtx_z) > 10.0) continue;
0311
0312 double evtWeight = eventInfo->get_cross_section();
0313
0314
0315
0316
0317
0318 if (mode == Mode::kData)
0319 evtWeight *= GetVtxWeight(vtx_z);
0320
0321 double maxTruthPT = -1;
0322 for (auto& j : *truthJets)
0323 if (j.pt() > maxTruthPT) maxTruthPT = j.pt();
0324 if (maxTruthPT < get_jet_pTLow(jetSample) ||
0325 maxTruthPT > get_jet_pTHigh(jetSample)) continue;
0326
0327 bool rValid = eventInfo->is_dijet_event(2)
0328 && eventInfo->get_lead_pT(2) >= recoLeadMin
0329 && eventInfo->get_sublead_pT(2) >= recoSublMin;
0330 bool tValid = eventInfo->is_dijetTruth_event(2)
0331 && eventInfo->get_leadTruth_pT(2) >= trueLeadMin
0332 && eventInfo->get_subleadTruth_pT(2) >= trueSublMin;
0333
0334 if(!rValid && !tValid) continue;
0335
0336
0337
0338
0339 hVtxMC->Fill(vtx_z, eventInfo->get_cross_section());
0340
0341 double rLeadPT = rValid ? eventInfo->get_lead_pT(2) : -1;
0342 double rSublPT = rValid ? eventInfo->get_sublead_pT(2) : -1;
0343 double tLeadPT = tValid ? eventInfo->get_leadTruth_pT(2) : -1;
0344 double tSublPT = tValid ? eventInfo->get_subleadTruth_pT(2) : -1;
0345
0346 int iLreco = rValid ? FindBin(rLeadPT, recoLeadPtBins) : -1;
0347 int iSreco = rValid ? FindBin(rSublPT, recoSublPtBins) : -1;
0348 int iLtrue = tValid ? FindBin(tLeadPT, trueLeadPtBins) : -1;
0349 int iStrue = tValid ? FindBin(tSublPT, trueSublPtBins) : -1;
0350
0351 bool recoInRange = rValid && iLreco >= 0 && iSreco >= 0;
0352 bool trueInRange = tValid && iLtrue >= 0 && iStrue >= 0;
0353
0354 bool geoMatch = false;
0355 if (rValid && tValid)
0356 geoMatch = GetGeoMatch(*recoJets, *truthJets,
0357 rLeadPT, rSublPT, tLeadPT, tSublPT);
0358
0359
0360 double recoMap[24][64] = {};
0361 if (recoInRange) {
0362 shiftEtaEdges(vtx_z);
0363 for (auto& tow : *towers) {
0364 if (tow.get_calo() < 1 || tow.get_calo() > 3) continue;
0365 fastjet::PseudoJet tj(tow.px(), tow.py(), tow.pz(), tow.e());
0366 int etaBin = getEtaBin(tj.pseudorapidity(), vtx_z);
0367 int phiBin = getPhiBin(tj.phi());
0368 if (etaBin >= 0 && phiBin >= 0)
0369 recoMap[etaBin][phiBin] += tow.e();
0370 }
0371 }
0372
0373
0374
0375
0376
0377 double truthMap[24][64] = {};
0378 if (trueInRange) {
0379 for (auto& part : *particles) {
0380 if(part.get_calo() != 4) continue;
0381
0382 fastjet::PseudoJet pj(part.px(), part.py(), part.pz(), part.e());
0383 int etaBin = getEtaBin(pj.pseudorapidity(), 0.0);
0384 int phiBin = getPhiBin(pj.phi());
0385 if (etaBin >= 0 && phiBin >= 0)
0386 truthMap[etaBin][phiBin] += part.e();
0387 }
0388 }
0389
0390
0391 if (fillResp) {
0392 if (recoInRange && trueInRange && geoMatch) {
0393 double rFlat = RecoFlatBinCenter(RecoFlatIndex(iLreco, iSreco));
0394 double tFlat = TrueFlatBinCenter(TrueFlatIndex(iLtrue, iStrue));
0395 respJetPt->Fill(rFlat, tFlat, evtWeight);
0396 hJetPt_reco_matched ->Fill(rFlat, evtWeight);
0397 hJetPt_reco ->Fill(rFlat, evtWeight);
0398 hJetPt_truth_matched->Fill(tFlat, evtWeight);
0399 hJetPt_truth ->Fill(tFlat, evtWeight);
0400 } else {
0401 if (recoInRange) {
0402 double rFlat = RecoFlatBinCenter(RecoFlatIndex(iLreco, iSreco));
0403 respJetPt->Fake(rFlat, evtWeight);
0404 hJetPt_reco->Fill(rFlat, evtWeight);
0405 }
0406 if (trueInRange) {
0407 double tFlat = TrueFlatBinCenter(TrueFlatIndex(iLtrue, iStrue));
0408 respJetPt->Miss(tFlat, evtWeight);
0409 hJetPt_truth->Fill(tFlat, evtWeight);
0410 }
0411 }
0412 }
0413 if (fillMeas && recoInRange) {
0414 hJetPt_meas->Fill(RecoFlatBinCenter(RecoFlatIndex(iLreco, iSreco)), evtWeight);
0415 if (halfClosure && trueInRange)
0416 hJetPt_truth_meas->Fill(TrueFlatBinCenter(TrueFlatIndex(iLtrue, iStrue)), evtWeight);
0417 }
0418
0419
0420
0421
0422
0423
0424
0425
0426
0427 const bool isMatched = recoInRange && trueInRange && geoMatch;
0428 const bool isFake = recoInRange && !isMatched;
0429 const bool isMiss = trueInRange && !isMatched;
0430
0431 ++nGood;
0432 if (recoInRange) ++nGoodReco;
0433 if (trueInRange) ++nGoodTruth;
0434 if (isMatched) ++nMatched;
0435
0436 std::cout << std::format(
0437 "ev {:5d}: reco={} truth={} match={} | "
0438 "good={} goodReco={} goodTruth={} matched={}\n",
0439 ev, (int)recoInRange, (int)trueInRange, (int)isMatched,
0440 nGood, nGoodReco, nGoodTruth, nMatched);
0441 std::cout.flush();
0442
0443
0444
0445
0446
0447 if (fillResp && trueInRange)
0448 {
0449 const double tPTmean2 = 0.25*(tLeadPT+tSublPT)*(tLeadPT+tSublPT);
0450
0451
0452
0453
0454
0455 struct PInfo { double pT, phi; };
0456 std::vector<PInfo> plist;
0457 plist.reserve(particles->size());
0458 for (auto& part : *particles) {
0459 if (part.get_calo() != 4) continue;
0460 fastjet::PseudoJet pj(part.px(), part.py(), part.pz(), part.e());
0461 double eta = pj.pseudorapidity();
0462
0463 if (std::abs(eta) > 1.1) continue;
0464 double phi = pj.phi();
0465 double pT = part.e() / std::cosh(eta);
0466 if (pT <= 0) continue;
0467 plist.push_back({pT, phi});
0468 }
0469 for (int i = 0; i < (int)plist.size(); ++i)
0470 for (int j = i+1; j < (int)plist.size(); ++j) {
0471 double dphi = DeltaPhi(plist[i].phi, plist[j].phi);
0472 double pairW = plist[i].pT * plist[j].pT / tPTmean2;
0473 if (pairW < pairWeightMin || pairW > pairWeightMax) continue;
0474 hWEEC_particle->Fill(dphi, evtWeight * pairW);
0475 }
0476
0477
0478
0479 for (int i = 0; i < 24*64; ++i) {
0480 const int ei = i/64, pi = i%64;
0481 double phi_i = getPhiCenter(pi);
0482 const double tpT_i = truthMap[ei][pi] / cosh(getEtaCenter(ei, 0.0));
0483 if (tpT_i <= towCut || tpT_i >= 80) continue;
0484
0485 for (int j = i+1; j < 24*64; ++j) {
0486 const int ej = j/64, pj = j%64;
0487 double phi_j = getPhiCenter(pj);
0488 const double tpT_j = truthMap[ej][pj] / cosh(getEtaCenter(ej, 0.0));
0489 if (tpT_j <= towCut || tpT_j >= 80) continue;
0490
0491 double dphi = DeltaPhi(phi_i, phi_j);
0492 double pairW = tpT_i * tpT_j / tPTmean2;
0493 if (pairW < pairWeightMin || pairW > pairWeightMax) continue;
0494 hWEEC_truthTower->Fill(dphi, evtWeight * pairW);
0495 }
0496 }
0497 }
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507 if (isMatched)
0508 {
0509 const double rPTmean2 = 0.25*(rLeadPT+rSublPT)*(rLeadPT+rSublPT);
0510 const double tPTmean2 = 0.25*(tLeadPT+tSublPT)*(tLeadPT+tSublPT);
0511
0512 for (int i = 0; i < 24*64; ++i) {
0513 const int ei = i/64, pi = i%64;
0514 const double rE_i = recoMap[ei][pi];
0515 const double tE_i = truthMap[ei][pi];
0516
0517 double phi_i = getPhiCenter(pi);
0518 const double rpT_i = rE_i/cosh(getEtaCenter(ei, vtx_z));
0519 const double tpT_i = tE_i/cosh(getEtaCenter(ei, 0.0));
0520
0521 const bool rOk_i = (rpT_i > towCut && rpT_i < 80);
0522 const bool tOk_i = (tpT_i > towCut && tpT_i < 80);
0523 if (!rOk_i && !tOk_i) continue;
0524
0525 for (int j = i+1; j < 24*64; ++j) {
0526 const int ej = j/64, pj = j%64;
0527 const double rE_j = recoMap[ej][pj];
0528 const double tE_j = truthMap[ej][pj];
0529
0530 double phi_j = getPhiCenter(pj);
0531 const double rpT_j = rE_j/cosh(getEtaCenter(ej, vtx_z));
0532 const double tpT_j = tE_j/cosh(getEtaCenter(ej, 0.0));
0533
0534 const bool rOk_j = (rpT_j > towCut && rpT_j < 80);
0535 const bool tOk_j = (tpT_j > towCut && tpT_j < 80);
0536 if (!rOk_j && !tOk_j) continue;
0537
0538 const double dphi = DeltaPhi(phi_i, phi_j);
0539 const int iDphi = FindBin(dphi, dPhiBins);
0540 if (iDphi < 0) continue;
0541
0542 const bool hasReco = rOk_i && rOk_j;
0543 const bool hasTruth = tOk_i && tOk_j;
0544
0545 if (hasReco && hasTruth) {
0546 const double rPairW = rpT_i*rpT_j/rPTmean2;
0547 const double tPairW = tpT_i*tpT_j/tPTmean2;
0548 if (rPairW >= pairWeightMin && rPairW <= pairWeightMax &&
0549 tPairW >= pairWeightMin && tPairW <= pairWeightMax) {
0550 const int rIPw = FindBin(rPairW, pairWeightBins);
0551 const int tIPw = FindBin(tPairW, pairWeightBins);
0552 if (rIPw >= 0 && tIPw >= 0) {
0553 const double rF3Dcen = RecoFlat3DBinCenter(RecoFlat3DIndex(iLreco,iSreco,rIPw));
0554 const double tF3Dcen = TrueFlat3DBinCenter(TrueFlat3DIndex(iLtrue,iStrue,tIPw));
0555 if (fillResp) {
0556 respWEEC3D[iDphi]->Fill(rF3Dcen, tF3Dcen, evtWeight);
0557 hWEEC3D_counts[iDphi]->Fill(rF3Dcen, tF3Dcen);
0558 hWEEC3D_truth[iDphi]->Fill(tF3Dcen, evtWeight);
0559 hWEEC3D_pwNum[iDphi]->Fill(tF3Dcen, evtWeight * tPairW);
0560 hWEEC3D_pwDen[iDphi]->Fill(tF3Dcen, evtWeight);
0561 }
0562 if (fillMeas) {
0563 hWEEC3D_meas[iDphi]->Fill(rF3Dcen, evtWeight);
0564 hWEEC3D_meas_truth[iDphi]->Fill(tF3Dcen, evtWeight);
0565 }
0566 }
0567 }
0568 } else if (hasReco) {
0569 const double rPairW = rpT_i*rpT_j/rPTmean2;
0570 if (rPairW >= pairWeightMin && rPairW <= pairWeightMax) {
0571 const int rIPw = FindBin(rPairW, pairWeightBins);
0572 if (rIPw >= 0) {
0573 const double rF3Dcen = RecoFlat3DBinCenter(RecoFlat3DIndex(iLreco,iSreco,rIPw));
0574 if (fillResp) {
0575 respWEEC3D[iDphi]->Fake(rF3Dcen, evtWeight);
0576 hWEEC3D_fakes[iDphi]->Fill(rF3Dcen, evtWeight);
0577 }
0578 if (fillMeas) hWEEC3D_meas[iDphi]->Fill(rF3Dcen, evtWeight);
0579 }
0580 }
0581 } else {
0582 const double tPairW = tpT_i*tpT_j/tPTmean2;
0583 if (tPairW >= pairWeightMin && tPairW <= pairWeightMax) {
0584 const int tIPw = FindBin(tPairW, pairWeightBins);
0585 if (tIPw >= 0) {
0586 const double tF3Dcen = TrueFlat3DBinCenter(TrueFlat3DIndex(iLtrue,iStrue,tIPw));
0587 if (fillResp) {
0588 respWEEC3D[iDphi]->Miss(tF3Dcen, evtWeight);
0589 hWEEC3D_truth[iDphi]->Fill(tF3Dcen, evtWeight);
0590 hWEEC3D_pwNum[iDphi]->Fill(tF3Dcen, evtWeight * tPairW);
0591 hWEEC3D_pwDen[iDphi]->Fill(tF3Dcen, evtWeight);
0592 hWEEC3D_misses[iDphi]->Fill(tF3Dcen, evtWeight);
0593 }
0594 if (fillMeas) {
0595 hWEEC3D_meas_truth[iDphi]->Fill(tF3Dcen, evtWeight);
0596 }
0597 }
0598 }
0599 }
0600 }
0601 }
0602 }
0603
0604
0605
0606
0607 if (isFake)
0608 {
0609 const double rPTmean2 = 0.25*(rLeadPT+rSublPT)*(rLeadPT+rSublPT);
0610
0611 for (int i = 0; i < 24*64; ++i) {
0612 const int ei = i/64, pi = i%64;
0613 double phi_i = getPhiCenter(pi);
0614 const double rpT_i = recoMap[ei][pi]/cosh(getEtaCenter(ei, vtx_z));
0615 if (rpT_i <= towCut || rpT_i >= 80) continue;
0616
0617 for (int j = i+1; j < 24*64; ++j) {
0618 const int ej = j/64, pj = j%64;
0619 double phi_j = getPhiCenter(pj);
0620 const double rpT_j = recoMap[ej][pj]/cosh(getEtaCenter(ej, vtx_z));
0621 if (rpT_j <= towCut || rpT_j >= 80) continue;
0622
0623 const double dphi = DeltaPhi(phi_i, phi_j);
0624 const double rPairW = rpT_i*rpT_j/rPTmean2;
0625 if (rPairW < pairWeightMin || rPairW > pairWeightMax) continue;
0626
0627 const int iDphi = FindBin(dphi, dPhiBins);
0628 const int rIPw = FindBin(rPairW, pairWeightBins);
0629 if (iDphi < 0 || rIPw < 0) continue;
0630
0631 const double rF3Dcen = RecoFlat3DBinCenter(RecoFlat3DIndex(iLreco,iSreco,rIPw));
0632 if (fillResp) {
0633 respWEEC3D[iDphi]->Fake(rF3Dcen, evtWeight);
0634 hWEEC3D_fakes[iDphi]->Fill(rF3Dcen, evtWeight);
0635 }
0636 if (fillMeas) hWEEC3D_meas[iDphi]->Fill(rF3Dcen, evtWeight);
0637 }
0638 }
0639 }
0640
0641
0642
0643
0644 if (isMiss)
0645 {
0646 const double tPTmean2 = 0.25*(tLeadPT+tSublPT)*(tLeadPT+tSublPT);
0647
0648 for (int i = 0; i < 24*64; ++i) {
0649 const int ei = i/64, pi = i%64;
0650 double phi_i = getPhiCenter(pi);
0651 const double tpT_i = truthMap[ei][pi]/cosh(getEtaCenter(ei, 0.0));
0652 if (tpT_i <= towCut || tpT_i >= 80) continue;
0653
0654 for (int j = i+1; j < 24*64; ++j) {
0655 const int ej = j/64, pj = j%64;
0656 double phi_j = getPhiCenter(pj);
0657 const double tpT_j = truthMap[ej][pj]/cosh(getEtaCenter(ej, 0.0));
0658 if (tpT_j <= towCut || tpT_j >= 80) continue;
0659
0660 const double dphi = DeltaPhi(phi_i, phi_j);
0661 const double tPairW = tpT_i*tpT_j/tPTmean2;
0662 if (tPairW < pairWeightMin || tPairW > pairWeightMax) continue;
0663
0664 const int iDphi = FindBin(dphi, dPhiBins);
0665 const int tIPw = FindBin(tPairW, pairWeightBins);
0666 if (iDphi < 0 || tIPw < 0) continue;
0667
0668 const double tF3Dcen = TrueFlat3DBinCenter(TrueFlat3DIndex(iLtrue,iStrue,tIPw));
0669 if (fillResp) {
0670 respWEEC3D[iDphi]->Miss(tF3Dcen, evtWeight);
0671 hWEEC3D_truth[iDphi]->Fill(tF3Dcen, evtWeight);
0672 hWEEC3D_pwNum[iDphi]->Fill(tF3Dcen, evtWeight * tPairW);
0673 hWEEC3D_pwDen[iDphi]->Fill(tF3Dcen, evtWeight);
0674 hWEEC3D_misses[iDphi]->Fill(tF3Dcen, evtWeight);
0675 }
0676 if (fillMeas) {
0677 hWEEC3D_meas_truth[iDphi]->Fill(tF3Dcen, evtWeight);
0678 }
0679 }
0680 }
0681 }
0682
0683
0684
0685
0686
0687
0688
0689
0690
0691
0692
0693
0694
0695
0696
0697
0698
0699
0700
0701
0702
0703
0704
0705
0706
0707
0708
0709
0710
0711
0712
0713
0714
0715
0716
0717
0718
0719
0720
0721
0722
0723
0724
0725
0726
0727
0728
0729
0730
0731
0732
0733
0734
0735
0736
0737
0738
0739
0740
0741
0742
0743
0744
0745
0746
0747
0748
0749
0750
0751
0752
0753
0754
0755
0756
0757
0758
0759 }
0760
0761 simFile->Close(); delete simFile;
0762
0763
0764 std::cout << "writing file " << outName << std::endl;
0765 std::cout.flush();
0766
0767 fOut->cd();
0768
0769 respJetPt->Write("response_jet_pT");
0770 hJetPt_truth_matched->Write();
0771 hJetPt_truth ->Write();
0772 hJetPt_reco_matched ->Write();
0773 hJetPt_reco ->Write();
0774 hJetPt_meas ->Write();
0775 if (halfClosure) hJetPt_truth_meas->Write();
0776
0777 std::cout << "done writing jet plots" << std::endl;
0778
0779 for (int k = 0; k < nDphi; ++k)
0780 respWEEC3D[k]->Write(std::format("response_wEEC3D_{}", k).c_str());
0781
0782 std::cout << "done writing response matrices" << std::endl;
0783
0784 for (int k = 0; k < nDphi; ++k)
0785 hWEEC3D_truth[k]->Write();
0786
0787 std::cout << "done writing truth plots" << std::endl;
0788
0789 for (int k = 0; k < nDphi; ++k) {
0790 hWEEC3D_pwNum[k]->Write();
0791 hWEEC3D_pwDen[k]->Write();
0792 }
0793
0794 std::cout << "done writing pair weight mean hists" << std::endl;
0795
0796 for (int k = 0; k < nDphi; ++k)
0797 hWEEC3D_meas[k]->Write();
0798
0799 std::cout << "done writing meas plots" << std::endl;
0800
0801 if (halfClosure) {
0802 for (int k = 0; k < nDphi; ++k)
0803 hWEEC3D_meas_truth[k]->Write();
0804 std::cout << "done writing meas truth plots" << std::endl;
0805 }
0806
0807 for (int k = 0; k < nDphi; ++k)
0808 hWEEC3D_counts[k]->Write();
0809
0810 for (int k = 0; k < nDphi; ++k)
0811 hWEEC3D_misses[k]->Write();
0812
0813 for (int k = 0; k < nDphi; ++k)
0814 hWEEC3D_fakes[k]->Write();
0815
0816 std::cout << "done writing counts hists" << std::endl;
0817
0818 hVtxMC->Write();
0819
0820 std::cout << "done writing vtx hist" << std::endl;
0821
0822 hWEEC_particle ->Write();
0823 hWEEC_truthTower->Write();
0824
0825 std::cout << "done writing cross-check wEEC hists" << std::endl;
0826
0827 fOut->Close();
0828 std::cout << "Written: " << outName << "\n";
0829 }