File indexing completed on 2024-05-22 04:02:32
0001
0002 #include <memory>
0003 #include <cmath>
0004 #include <fmt/printf.h>
0005
0006
0007 #include "Alignment/OfflineValidation/interface/DiLeptonVertexHelpers.h"
0008 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0009 #include "DataFormats/Candidate/interface/Particle.h"
0010 #include "DataFormats/TrackReco/interface/Track.h"
0011 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0012 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
0013 #include "FWCore/Framework/interface/Event.h"
0014 #include "FWCore/Framework/interface/Frameworkfwd.h"
0015 #include "FWCore/Framework/interface/MakerMacros.h"
0016 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 #include "FWCore/ServiceRegistry/interface/Service.h"
0019 #include "FWCore/Utilities/interface/InputTag.h"
0020 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0021 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0022 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0023
0024
0025 #include "TH1D.h"
0026 #include "TH2D.h"
0027 #include "TH3D.h"
0028
0029 namespace DiMuonValid {
0030 using LV = reco::Particle::LorentzVector;
0031 }
0032
0033
0034
0035 class DiMuonValidation : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0036 public:
0037 explicit DiMuonValidation(const edm::ParameterSet& pset)
0038 : eBeam_(pset.getParameter<double>("eBeam")),
0039 compressionSettings_(pset.getUntrackedParameter<int>("compressionSettings", -1)),
0040 TkTag_(pset.getParameter<std::string>("TkTag")),
0041 pair_mass_min_(pset.getParameter<double>("Pair_mass_min")),
0042 pair_mass_max_(pset.getParameter<double>("Pair_mass_max")),
0043 pair_mass_nbins_(pset.getParameter<int>("Pair_mass_nbins")),
0044 pair_etaminpos_(pset.getParameter<double>("Pair_etaminpos")),
0045 pair_etamaxpos_(pset.getParameter<double>("Pair_etamaxpos")),
0046 pair_etaminneg_(pset.getParameter<double>("Pair_etaminneg")),
0047 pair_etamaxneg_(pset.getParameter<double>("Pair_etamaxneg")),
0048 variable_CosThetaCS_xmin_(pset.getParameter<double>("Variable_CosThetaCS_xmin")),
0049 variable_CosThetaCS_xmax_(pset.getParameter<double>("Variable_CosThetaCS_xmax")),
0050 variable_CosThetaCS_nbins_(pset.getParameter<int>("Variable_CosThetaCS_nbins")),
0051 variable_DeltaEta_xmin_(pset.getParameter<double>("Variable_DeltaEta_xmin")),
0052 variable_DeltaEta_xmax_(pset.getParameter<double>("Variable_DeltaEta_xmax")),
0053 variable_DeltaEta_nbins_(pset.getParameter<int>("Variable_DeltaEta_nbins")),
0054 variable_EtaMinus_xmin_(pset.getParameter<double>("Variable_EtaMinus_xmin")),
0055 variable_EtaMinus_xmax_(pset.getParameter<double>("Variable_EtaMinus_xmax")),
0056 variable_EtaMinus_nbins_(pset.getParameter<int>("Variable_EtaMinus_nbins")),
0057 variable_EtaPlus_xmin_(pset.getParameter<double>("Variable_EtaPlus_xmin")),
0058 variable_EtaPlus_xmax_(pset.getParameter<double>("Variable_EtaPlus_xmax")),
0059 variable_EtaPlus_nbins_(pset.getParameter<int>("Variable_EtaPlus_nbins")),
0060 variable_PhiCS_xmin_(pset.getParameter<double>("Variable_PhiCS_xmin")),
0061 variable_PhiCS_xmax_(pset.getParameter<double>("Variable_PhiCS_xmax")),
0062 variable_PhiCS_nbins_(pset.getParameter<int>("Variable_PhiCS_nbins")),
0063 variable_PhiMinus_xmin_(pset.getParameter<double>("Variable_PhiMinus_xmin")),
0064 variable_PhiMinus_xmax_(pset.getParameter<double>("Variable_PhiMinus_xmax")),
0065 variable_PhiMinus_nbins_(pset.getParameter<int>("Variable_PhiMinus_nbins")),
0066 variable_PhiPlus_xmin_(pset.getParameter<double>("Variable_PhiPlus_xmin")),
0067 variable_PhiPlus_xmax_(pset.getParameter<double>("Variable_PhiPlus_xmax")),
0068 variable_PhiPlus_nbins_(pset.getParameter<int>("Variable_PhiPlus_nbins")),
0069 variable_PairPt_xmin_(pset.getParameter<double>("Variable_PairPt_xmin")),
0070 variable_PairPt_xmax_(pset.getParameter<double>("Variable_PairPt_xmax")),
0071 variable_PairPt_nbins_(pset.getParameter<int>("Variable_PairPt_nbins")) {
0072 usesResource(TFileService::kSharedResource);
0073 theTrackCollectionToken_ = consumes<reco::TrackCollection>(TkTag_);
0074
0075 variables_min_[Variable::CosThetaCS] = variable_CosThetaCS_xmin_;
0076 variables_min_[Variable::DeltaEta] = variable_DeltaEta_xmin_;
0077 variables_min_[Variable::EtaMinus] = variable_EtaMinus_xmin_;
0078 variables_min_[Variable::EtaPlus] = variable_EtaPlus_xmin_;
0079 variables_min_[Variable::PhiCS] = variable_PhiCS_xmin_;
0080 variables_min_[Variable::PhiMinus] = variable_PhiMinus_xmin_;
0081 variables_min_[Variable::PhiPlus] = variable_PhiPlus_xmin_;
0082 variables_min_[Variable::Pt] = variable_PairPt_xmin_;
0083
0084 variables_max_[Variable::CosThetaCS] = variable_CosThetaCS_xmax_;
0085 variables_max_[Variable::DeltaEta] = variable_DeltaEta_xmax_;
0086 variables_max_[Variable::EtaMinus] = variable_EtaMinus_xmax_;
0087 variables_max_[Variable::EtaPlus] = variable_EtaPlus_xmax_;
0088 variables_max_[Variable::PhiCS] = variable_PhiCS_xmax_;
0089 variables_max_[Variable::PhiMinus] = variable_PhiMinus_xmax_;
0090 variables_max_[Variable::PhiPlus] = variable_PhiPlus_xmax_;
0091 variables_max_[Variable::Pt] = variable_PairPt_xmax_;
0092
0093 variables_bins_number_[Variable::CosThetaCS] = variable_CosThetaCS_nbins_;
0094 variables_bins_number_[Variable::DeltaEta] = variable_DeltaEta_nbins_;
0095 variables_bins_number_[Variable::EtaMinus] = variable_EtaMinus_nbins_;
0096 variables_bins_number_[Variable::EtaPlus] = variable_EtaPlus_nbins_;
0097 variables_bins_number_[Variable::PhiCS] = variable_PhiCS_nbins_;
0098 variables_bins_number_[Variable::PhiMinus] = variable_PhiMinus_nbins_;
0099 variables_bins_number_[Variable::PhiPlus] = variable_PhiPlus_nbins_;
0100 variables_bins_number_[Variable::Pt] = variable_PairPt_nbins_;
0101 }
0102
0103 ~DiMuonValidation() override = default;
0104
0105 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0106
0107
0108 enum Variable {
0109 CosThetaCS = 0,
0110 DeltaEta = 1,
0111 EtaMinus = 2,
0112 EtaPlus = 3,
0113 PhiCS = 4,
0114 PhiMinus = 5,
0115 PhiPlus = 6,
0116 Pt = 7,
0117 VarNumber = 8
0118 };
0119
0120 static constexpr double mu_mass2_ = 0.105658 * 0.105658;
0121
0122 private:
0123 void beginJob() override;
0124 void analyze(const edm::Event&, const edm::EventSetup&) override;
0125
0126
0127 float eBeam_;
0128 int compressionSettings_;
0129 std::string TkTag_;
0130
0131 double pair_mass_min_;
0132 double pair_mass_max_;
0133 int pair_mass_nbins_;
0134 double pair_etaminpos_;
0135 double pair_etamaxpos_;
0136 double pair_etaminneg_;
0137 double pair_etamaxneg_;
0138
0139 double variable_CosThetaCS_xmin_;
0140 double variable_CosThetaCS_xmax_;
0141 int variable_CosThetaCS_nbins_;
0142
0143 double variable_DeltaEta_xmin_;
0144 double variable_DeltaEta_xmax_;
0145 int variable_DeltaEta_nbins_;
0146
0147 double variable_EtaMinus_xmin_;
0148 double variable_EtaMinus_xmax_;
0149 int variable_EtaMinus_nbins_;
0150
0151 double variable_EtaPlus_xmin_;
0152 double variable_EtaPlus_xmax_;
0153 int variable_EtaPlus_nbins_;
0154
0155 double variable_PhiCS_xmin_;
0156 double variable_PhiCS_xmax_;
0157 int variable_PhiCS_nbins_;
0158
0159 double variable_PhiMinus_xmin_;
0160 double variable_PhiMinus_xmax_;
0161 int variable_PhiMinus_nbins_;
0162
0163 double variable_PhiPlus_xmin_;
0164 double variable_PhiPlus_xmax_;
0165 int variable_PhiPlus_nbins_;
0166
0167 double variable_PairPt_xmin_;
0168 double variable_PairPt_xmax_;
0169 int variable_PairPt_nbins_;
0170
0171 edm::EDGetTokenT<reco::TrackCollection> theTrackCollectionToken_;
0172
0173 TH1F* th1f_mass;
0174 TH2D* th2d_mass_variables_[Variable::VarNumber];
0175 TH3D* th3d_mass_vs_eta_phi_plus_;
0176 TH3D* th3d_mass_vs_eta_phi_minus_;
0177
0178 std::string variables_name_[Variable::VarNumber] = {
0179 "CosThetaCS", "DeltaEta", "EtaMinus", "EtaPlus", "PhiCS", "PhiMinus", "PhiPlus", "Pt"};
0180
0181 std::string variables_title_[Variable::VarNumber] = {"Cos#theta_{CS}",
0182 "#Delta#eta(#mu^{-},#mu^{+})",
0183 "#mu^{-} #eta",
0184 "#mu^{+} #eta",
0185 "#phi_{CS} [rad]",
0186 "#mu^{-} #phi [rad]",
0187 "#mu^{+} #phi [rad]",
0188 "p_{T} [GeV]"};
0189
0190 int variables_bins_number_[Variable::VarNumber];
0191 double variables_min_[Variable::VarNumber];
0192 double variables_max_[Variable::VarNumber];
0193
0194 DiLeptonHelp::PlotsVsDiLeptonRegion InvMassInEtaBins = DiLeptonHelp::PlotsVsDiLeptonRegion(1.5);
0195 DiLeptonHelp::PlotsVsDiLeptonRegion InvMassVsPhiPlusInEtaBins = DiLeptonHelp::PlotsVsDiLeptonRegion(1.5);
0196 DiLeptonHelp::PlotsVsDiLeptonRegion InvMassVsPhiMinusInEtaBins = DiLeptonHelp::PlotsVsDiLeptonRegion(1.5);
0197 DiLeptonHelp::PlotsVsDiLeptonRegion InvMassVsCosThetaCSInEtaBins = DiLeptonHelp::PlotsVsDiLeptonRegion(1.5);
0198 };
0199
0200
0201
0202
0203
0204
0205 void DiMuonValidation::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0206 using namespace edm;
0207
0208 const reco::TrackCollection& tC = iEvent.get(theTrackCollectionToken_);
0209
0210 DiMuonValid::LV LV_mother(0., 0., 0., 0.);
0211 for (reco::TrackCollection::const_iterator track1 = tC.begin(); track1 != tC.end(); track1++) {
0212 DiMuonValid::LV LV_track1(track1->px(),
0213 track1->py(),
0214 track1->pz(),
0215 sqrt((track1->p() * track1->p()) + mu_mass2_));
0216
0217 for (reco::TrackCollection::const_iterator track2 = track1 + 1; track2 != tC.end(); track2++) {
0218 if (track1->charge() == track2->charge()) {
0219 continue;
0220 }
0221
0222 DiMuonValid::LV LV_track2(
0223 track2->px(), track2->py(), track2->pz(), sqrt((track2->p() * track2->p()) + mu_mass2_));
0224
0225 LV_mother = LV_track1 + LV_track2;
0226 double mother_mass = LV_mother.M();
0227 th1f_mass->Fill(mother_mass);
0228 double mother_pt = LV_mother.Pt();
0229
0230 int charge1 = track1->charge();
0231 double etaMu1 = track1->eta();
0232 double phiMu1 = track1->phi();
0233 double ptMu1 = track1->pt();
0234
0235 int charge2 = track2->charge();
0236 double etaMu2 = track2->eta();
0237 double phiMu2 = track2->phi();
0238 double ptMu2 = track2->pt();
0239
0240 if (charge1 < 0) {
0241 std::swap(charge1, charge2);
0242 std::swap(etaMu1, etaMu2);
0243 std::swap(phiMu1, phiMu2);
0244 std::swap(ptMu1, ptMu2);
0245 }
0246
0247 const auto& tplus = track1->charge() > 0 ? track1 : track2;
0248 const auto& tminus = track1->charge() < 0 ? track1 : track2;
0249 TLorentzVector p4_tplus(tplus->px(), tplus->py(), tplus->pz(), sqrt((tplus->p() * tplus->p()) + mu_mass2_));
0250 TLorentzVector p4_tminus(tminus->px(), tminus->py(), tminus->pz(), sqrt((tminus->p() * tminus->p()) + mu_mass2_));
0251 std::pair<TLorentzVector, TLorentzVector> tktk_p4 = std::make_pair(p4_tplus, p4_tminus);
0252 InvMassInEtaBins.fillTH1Plots(mother_mass, tktk_p4);
0253 InvMassVsPhiPlusInEtaBins.fillTH2Plots(mother_mass, phiMu1, tktk_p4);
0254 InvMassVsPhiMinusInEtaBins.fillTH2Plots(mother_mass, phiMu2, tktk_p4);
0255
0256
0257 if (etaMu1 < pair_etaminpos_ || etaMu1 > pair_etamaxpos_ || etaMu2 < pair_etaminneg_ ||
0258 etaMu2 > pair_etamaxneg_) {
0259 continue;
0260 }
0261
0262 double delta_eta = etaMu1 - etaMu2;
0263
0264 double muplus = 1.0 / sqrt(2.0) * (LV_track1.E() + LV_track1.Z());
0265 double muminus = 1.0 / sqrt(2.0) * (LV_track1.E() - LV_track1.Z());
0266 double mubarplus = 1.0 / sqrt(2.0) * (LV_track2.E() + LV_track2.Z());
0267 double mubarminus = 1.0 / sqrt(2.0) * (LV_track2.E() - LV_track2.Z());
0268
0269 double costhetaCS = 2.0 / LV_mother.mag() / sqrt(pow(LV_mother.mag(), 2) + pow(LV_mother.Pt(), 2)) *
0270 (muplus * mubarminus - muminus * mubarplus);
0271
0272 InvMassVsCosThetaCSInEtaBins.fillTH2Plots(mother_mass, costhetaCS, tktk_p4);
0273
0274 DiMuonValid::LV Pbeam(0., 0., eBeam_, eBeam_);
0275 auto R = Pbeam.Vect().Cross(LV_mother.Vect());
0276 auto Runit = R.Unit();
0277 auto Qt = LV_mother.Vect();
0278 Qt.SetZ(0);
0279 auto Qtunit = Qt.Unit();
0280 DiMuonValid::LV D(LV_track1 - LV_track2);
0281 auto Dt = D.Vect();
0282 Dt.SetZ(0);
0283 double tanphi =
0284 sqrt(pow(LV_mother.mag(), 2) + pow(LV_mother.Pt(), 2)) / LV_mother.mag() * Dt.Dot(Runit) / Dt.Dot(Qtunit);
0285 double phiCS = atan(tanphi);
0286
0287 if (mother_mass > pair_mass_min_ && mother_mass < pair_mass_max_) {
0288 th2d_mass_variables_[Variable::CosThetaCS]->Fill(mother_mass, costhetaCS, 1);
0289 th2d_mass_variables_[Variable::DeltaEta]->Fill(mother_mass, delta_eta, 1);
0290 th2d_mass_variables_[Variable::EtaMinus]->Fill(mother_mass, etaMu2, 1);
0291 th2d_mass_variables_[Variable::EtaPlus]->Fill(mother_mass, etaMu1, 1);
0292 th2d_mass_variables_[Variable::PhiCS]->Fill(mother_mass, phiCS, 1);
0293 th2d_mass_variables_[Variable::PhiMinus]->Fill(mother_mass, phiMu2, 1);
0294 th2d_mass_variables_[Variable::PhiPlus]->Fill(mother_mass, phiMu1, 1);
0295 th2d_mass_variables_[Variable::Pt]->Fill(mother_mass, mother_pt, 1);
0296
0297 th3d_mass_vs_eta_phi_plus_->Fill(mother_mass, etaMu1, phiMu1);
0298 th3d_mass_vs_eta_phi_minus_->Fill(mother_mass, etaMu2, phiMu2);
0299 }
0300 }
0301 }
0302 }
0303
0304
0305 void DiMuonValidation::beginJob() {
0306 edm::Service<TFileService> fs;
0307 if (compressionSettings_ > 0) {
0308 fs->file().SetCompressionSettings(compressionSettings_);
0309 }
0310
0311 th1f_mass = fs->make<TH1F>("hMass", "mass;m_{#mu#mu} [GeV];events", 200, 0., 200.);
0312
0313 for (int i = 0; i < Variable::VarNumber; i++) {
0314 std::string th2d_name = fmt::sprintf("th2d_mass_%s", variables_name_[i].c_str());
0315 th2d_mass_variables_[i] =
0316 fs->make<TH2D>(th2d_name.c_str(),
0317 fmt::format("{};M_{{#mu^{{-}}#mu^{{+}}}} [GeV];{}", th2d_name, variables_title_[i]).c_str(),
0318 pair_mass_nbins_,
0319 pair_mass_min_,
0320 pair_mass_max_,
0321 variables_bins_number_[i],
0322 variables_min_[i],
0323 variables_max_[i]);
0324 }
0325
0326
0327 th3d_mass_vs_eta_phi_plus_ =
0328 fs->make<TH3D>("th3d_mass_vs_eta_phi_plus",
0329 "th3d_mass_vs_eta_phi_plus;M_{#mu^{-}#mu^{+}} [GeV];#mu^{+} #eta;#mu^{+} #phi [rad]",
0330 pair_mass_nbins_,
0331 pair_mass_min_,
0332 pair_mass_max_,
0333 variables_bins_number_[Variable::EtaPlus],
0334 variables_min_[Variable::EtaPlus],
0335 variables_max_[Variable::EtaPlus],
0336 variables_bins_number_[Variable::PhiPlus],
0337 variables_min_[Variable::PhiPlus],
0338 variables_max_[Variable::PhiPlus]);
0339
0340
0341 th3d_mass_vs_eta_phi_minus_ =
0342 fs->make<TH3D>("th3d_mass_vs_eta_phi_minus",
0343 "th3d_mass_vs_eta_phi_minus;M_{#mu^{-}#mu^{+}} [GeV];#mu^{-} #eta;#mu^{-} #phi [rad]",
0344 pair_mass_nbins_,
0345 pair_mass_min_,
0346 pair_mass_max_,
0347 variables_bins_number_[Variable::EtaMinus],
0348 variables_min_[Variable::EtaMinus],
0349 variables_max_[Variable::EtaMinus],
0350 variables_bins_number_[Variable::PhiMinus],
0351 variables_min_[Variable::PhiMinus],
0352 variables_max_[Variable::PhiMinus]);
0353
0354
0355 TFileDirectory dirResMassEta = fs->mkdir("TkTkMassInEtaBins");
0356 InvMassInEtaBins.bookSet(dirResMassEta, th1f_mass);
0357
0358
0359 TFileDirectory dirResMassVsCosThetaCSInEta = fs->mkdir("TkTkMassVsCosThetaCSInEtaBins");
0360 InvMassVsCosThetaCSInEtaBins.bookSet(dirResMassVsCosThetaCSInEta, th2d_mass_variables_[Variable::CosThetaCS]);
0361
0362
0363 TFileDirectory dirResMassVsPhiMinusInEta = fs->mkdir("TkTkMassVsPhiMinusInEtaBins");
0364 InvMassVsPhiMinusInEtaBins.bookSet(dirResMassVsPhiMinusInEta, th2d_mass_variables_[Variable::PhiMinus]);
0365
0366
0367 TFileDirectory dirResMassVsPhiPlusInEta = fs->mkdir("TkTkMassVsPhiPlusInEtaBins");
0368 InvMassVsPhiPlusInEtaBins.bookSet(dirResMassVsPhiPlusInEta, th2d_mass_variables_[Variable::PhiPlus]);
0369 }
0370
0371
0372 void DiMuonValidation::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0373 edm::ParameterSetDescription desc;
0374 desc.setComment("Validates alignment payloads by evaluating bias in Z->mm mass distributions");
0375 desc.addUntracked<int>("compressionSettings", -1);
0376
0377 desc.add<double>("eBeam", 3500.)->setComment("beam energy in GeV");
0378 desc.add<std::string>("TkTag", "ALCARECOTkAlZMuMu");
0379
0380 desc.add<double>("Pair_mass_min", 60.);
0381 desc.add<double>("Pair_mass_max", 120.);
0382 desc.add<int>("Pair_mass_nbins", 120);
0383 desc.add<double>("Pair_etaminpos", -2.4);
0384 desc.add<double>("Pair_etamaxpos", 2.4);
0385 desc.add<double>("Pair_etaminneg", -2.4);
0386 desc.add<double>("Pair_etamaxneg", 2.4);
0387
0388 desc.add<double>("Variable_CosThetaCS_xmin", -1.);
0389 desc.add<double>("Variable_CosThetaCS_xmax", 1.);
0390 desc.add<int>("Variable_CosThetaCS_nbins", 20);
0391
0392 desc.add<double>("Variable_DeltaEta_xmin", -4.8);
0393 desc.add<double>("Variable_DeltaEta_xmax", 4.8);
0394 desc.add<int>("Variable_DeltaEta_nbins", 20);
0395
0396 desc.add<double>("Variable_EtaMinus_xmin", -2.4);
0397 desc.add<double>("Variable_EtaMinus_xmax", 2.4);
0398 desc.add<int>("Variable_EtaMinus_nbins", 12);
0399
0400 desc.add<double>("Variable_EtaPlus_xmin", -2.4);
0401 desc.add<double>("Variable_EtaPlus_xmax", 2.4);
0402 desc.add<int>("Variable_EtaPlus_nbins", 12);
0403
0404 desc.add<double>("Variable_PhiCS_xmin", -M_PI / 2);
0405 desc.add<double>("Variable_PhiCS_xmax", M_PI / 2);
0406 desc.add<int>("Variable_PhiCS_nbins", 20);
0407
0408 desc.add<double>("Variable_PhiMinus_xmin", -M_PI);
0409 desc.add<double>("Variable_PhiMinus_xmax", M_PI);
0410 desc.add<int>("Variable_PhiMinus_nbins", 16);
0411
0412 desc.add<double>("Variable_PhiPlus_xmin", -M_PI);
0413 desc.add<double>("Variable_PhiPlus_xmax", M_PI);
0414 desc.add<int>("Variable_PhiPlus_nbins", 16);
0415
0416 desc.add<double>("Variable_PairPt_xmin", 0.);
0417 desc.add<double>("Variable_PairPt_xmax", 100.);
0418 desc.add<int>("Variable_PairPt_nbins", 100);
0419
0420 descriptions.addWithDefaultLabel(desc);
0421 }
0422
0423
0424 DEFINE_FWK_MODULE(DiMuonValidation);