From 0cea3354d4853d2c0be42bdacd544cb5613f1d09 Mon Sep 17 00:00:00 2001 From: mmusich Date: Mon, 5 Feb 2024 16:26:30 +0100 Subject: [PATCH] miscellaneous updates to improve validation of phase-2 alcareco samples --- .../OfflineValidation/macros/loopAndPlot.C | 21 ++- .../OfflineValidation/plugins/DMRChecker.cc | 73 ++++---- .../plugins/DiMuonVertexValidation.cc | 86 +++++---- .../plugins/GeneralPurposeTrackAnalyzer.cc | 10 +- .../TkAlAllInOneTool/defaultInputFiles_cff.py | 2 + .../OfflineValidation/test/inspectData_cfg.py | 171 ++++++++++++++++-- .../testingScripts/test_unitMiscellanea.sh | 5 +- 7 files changed, 272 insertions(+), 96 deletions(-) diff --git a/Alignment/OfflineValidation/macros/loopAndPlot.C b/Alignment/OfflineValidation/macros/loopAndPlot.C index cc14f9f843ada..093582435b54d 100644 --- a/Alignment/OfflineValidation/macros/loopAndPlot.C +++ b/Alignment/OfflineValidation/macros/loopAndPlot.C @@ -32,12 +32,12 @@ void MakeNiceProfile(TProfile *prof); //void MakeNicePlotStyle(TH1 *hist); void plot2Histograms(TH1 *h1, TH1 *h2, const TString &label1, const TString &label2); void plot2Profiles(TProfile *h1, TProfile *h2, const TString &label1, const TString &label2); -void recurseOverKeys(TDirectory *target1, const std::vector &labels); +void recurseOverKeys(TDirectory *target1, const std::vector &labels, bool isNorm); void recurseOverKeys(TDirectory *target1, const TString &label1, const TString &label2); -void plotHistograms(std::vector histos, const std::vector &labels); +void plotHistograms(std::vector histos, const std::vector &labels, bool isNormalized = false); /************************************************/ -void loopAndPlot(TString namesandlabels) +void loopAndPlot(TString namesandlabels, bool doNormalize = false) /************************************************/ { std::vector labels; @@ -56,7 +56,7 @@ void loopAndPlot(TString namesandlabels) } } - recurseOverKeys(sourceFiles[0], labels); + recurseOverKeys(sourceFiles[0], labels, doNormalize); for (const auto &file : sourceFiles) { file->Close(); @@ -64,7 +64,7 @@ void loopAndPlot(TString namesandlabels) } /************************************************/ -void recurseOverKeys(TDirectory *target1, const std::vector &labels) +void recurseOverKeys(TDirectory *target1, const std::vector &labels, bool isNorm) /************************************************/ { // Figure out where we are @@ -107,7 +107,7 @@ void recurseOverKeys(TDirectory *target1, const std::vector &labels) //outputFilename=histName; //plot2Histograms(htemp1, htemp2, outputFolder+path+"/"+outputFilename+"."+imageType); - plotHistograms(histos, labels); + plotHistograms(histos, labels, isNorm); } else if (obj->IsA()->InheritsFrom("TDirectory")) { // it's a subdirectory @@ -122,14 +122,14 @@ void recurseOverKeys(TDirectory *target1, const std::vector &labels) if ((TString(obj->GetName())).Contains("Residuals")) continue; - recurseOverKeys((TDirectory *)obj, labels); + recurseOverKeys((TDirectory *)obj, labels, isNorm); } // end of IF a TDriectory } } /************************************************/ -void plotHistograms(std::vector histos, const std::vector &labels) { +void plotHistograms(std::vector histos, const std::vector &labels, bool isNormalized) { /************************************************/ TGaxis::SetMaxDigits(3); @@ -143,6 +143,11 @@ void plotHistograms(std::vector histos, const std::vector &label for (const auto &histo : histos) { MakeNicePlotStyle(histo); + if (isNormalized) { + Double_t scale = 1. / histo->Integral(); + histo->Scale(scale); + } + histo->SetLineColor(def_colors[index]); histo->SetMarkerColor(def_colors[index]); histo->SetMarkerStyle(20); diff --git a/Alignment/OfflineValidation/plugins/DMRChecker.cc b/Alignment/OfflineValidation/plugins/DMRChecker.cc index 48dac30ea14e2..0bc402c14a808 100644 --- a/Alignment/OfflineValidation/plugins/DMRChecker.cc +++ b/Alignment/OfflineValidation/plugins/DMRChecker.cc @@ -154,10 +154,16 @@ class DMRChecker : public edm::one::EDAnalyzer()), magFieldToken_(esConsumes()), topoToken_(esConsumes()), - latencyToken_(esConsumes()), - isCosmics_(pset.getParameter("isCosmics")) { + isCosmics_(pset.getParameter("isCosmics")), + doLatencyAnalysis_(pset.getParameter("doLatencyAnalysis")) { usesResource(TFileService::kSharedResource); + if (doLatencyAnalysis_) { + latencyToken_ = esConsumes(); + } else { + latencyToken_ = edm::ESGetToken(); + } + TkTag_ = pset.getParameter("TkTag"); theTrackCollectionToken_ = consumes(TkTag_); @@ -231,7 +237,8 @@ class DMRChecker : public edm::one::EDAnalyzer runInfoToken_; const edm::ESGetToken magFieldToken_; const edm::ESGetToken topoToken_; - const edm::ESGetToken latencyToken_; + // not const + edm::ESGetToken latencyToken_; const MagneticField *magneticField_; const TrackerGeometry *trackerGeometry_; @@ -463,12 +470,12 @@ class DMRChecker : public edm::one::EDAnalyzer trackCollection = event.getHandle(theTrackCollectionToken_); - if (firstEvent_) { - if (trackerGeometry_->isThere(GeomDetEnumerators::P2PXB) || - trackerGeometry_->isThere(GeomDetEnumerators::P2PXEC)) { - phase_ = SiPixelPI::phase::two; - } else if (trackerGeometry_->isThere(GeomDetEnumerators::P1PXB) || - trackerGeometry_->isThere(GeomDetEnumerators::P1PXEC)) { - phase_ = SiPixelPI::phase::one; - } else { - phase_ = SiPixelPI::phase::zero; - } - firstEvent_ = false; - } - GlobalPoint zeroPoint(0, 0, 0); if (DEBUG) edm::LogVerbatim("DMRChecker") << "event #" << ievt << " Event ID = " << event.id() @@ -589,7 +583,8 @@ class DMRChecker : public edm::one::EDAnalyzerisValid() && (subid > PixelSubdetector::PixelEndcap)) { - tmap->fill(detid_db, 1); + if (phase_ != SiPixelPI::phase::two) + tmap->fill(detid_db, 1); //LocalPoint lp = (*iHit)->localPosition(); //LocalError le = (*iHit)->localPositionError(); @@ -1105,20 +1100,38 @@ class DMRChecker : public edm::one::EDAnalyzersingleReadOutMode() == 1) { - mode = 1; // peak mode - } else if (apvlat->singleReadOutMode() == 0) { - mode = -1; // deco mode + // set geometry and topology + trackerGeometry_ = &setup.getData(geomToken_); + if (trackerGeometry_->isThere(GeomDetEnumerators::P2PXB) || trackerGeometry_->isThere(GeomDetEnumerators::P2PXEC)) { + phase_ = SiPixelPI::phase::two; + } else if (trackerGeometry_->isThere(GeomDetEnumerators::P1PXB) || + trackerGeometry_->isThere(GeomDetEnumerators::P1PXEC)) { + phase_ = SiPixelPI::phase::one; + } else { + phase_ = SiPixelPI::phase::zero; + } + + trackerTopology_ = &setup.getData(topoToken_); + + // if it's a phase-2 geometry there are no phase-1 conditions + if (phase_ == SiPixelPI::phase::two) { + mode = 0; + } else { + if (doLatencyAnalysis_) { + //SiStrip Latency + const SiStripLatency *apvlat = &setup.getData(latencyToken_); + if (apvlat->singleReadOutMode() == 1) { + mode = 1; // peak mode + } else if (apvlat->singleReadOutMode() == 0) { + mode = -1; // deco mode + } + } else { + mode = 0.; + } } conditionsMap_[run.run()].first = mode; conditionsMap_[run.run()].second = B_; - - // set geometry and topology - trackerGeometry_ = &setup.getData(geomToken_); - trackerTopology_ = &setup.getData(topoToken_); } //************************************************************* @@ -1378,11 +1391,8 @@ class DMRChecker : public edm::one::EDAnalyzer("h2_kappa_vs_phi", "#kappa vs. #phi;#phi_{Track};#kappa", 100, -M_PI, M_PI, 100, .0, .05)); vTrack2DHistos_.push_back(book("h2_kappa_vs_eta", "#kappa vs. #eta;#eta_{Track};#kappa", 100, -etaMax_, etaMax_, 100, .0, .05)); vTrack2DHistos_.push_back(book("h2_normchi2_vs_kappa", "#kappa vs. #chi^{2}/ndof;#chi^{2}/ndof;#kappa", 100, 0., 10, 100, -.03, .03)); - // clang-format on - firstEvent_ = true; - // create the full maps fullPixelmapXDMR->createTrackerBaseMap(); fullPixelmapYDMR->createTrackerBaseMap(); @@ -2102,6 +2112,7 @@ void DMRChecker::fillDescriptions(edm::ConfigurationDescriptions &descriptions) desc.add("BeamSpotTag", edm::InputTag("offlineBeamSpot")); desc.add("VerticesTag", edm::InputTag("offlinePrimaryVertices")); desc.add("isCosmics", false); + desc.add("doLatencyAnalysis", true); descriptions.addWithDefaultLabel(desc); } diff --git a/Alignment/OfflineValidation/plugins/DiMuonVertexValidation.cc b/Alignment/OfflineValidation/plugins/DiMuonVertexValidation.cc index f292f249adf3a..5af46dc1759ee 100644 --- a/Alignment/OfflineValidation/plugins/DiMuonVertexValidation.cc +++ b/Alignment/OfflineValidation/plugins/DiMuonVertexValidation.cc @@ -79,18 +79,17 @@ class DiMuonVertexValidation : public edm::one::EDAnalyzer pTthresholds_; - float maxSVdist_; + const float maxSVdist_; // plot configurations - - edm::ParameterSet CosPhiConfiguration_; - edm::ParameterSet CosPhi3DConfiguration_; - edm::ParameterSet VtxProbConfiguration_; - edm::ParameterSet VtxDistConfiguration_; - edm::ParameterSet VtxDist3DConfiguration_; - edm::ParameterSet VtxDistSigConfiguration_; - edm::ParameterSet VtxDist3DSigConfiguration_; - edm::ParameterSet DiMuMassConfiguration_; + const edm::ParameterSet CosPhiConfiguration_; + const edm::ParameterSet CosPhi3DConfiguration_; + const edm::ParameterSet VtxProbConfiguration_; + const edm::ParameterSet VtxDistConfiguration_; + const edm::ParameterSet VtxDist3DConfiguration_; + const edm::ParameterSet VtxDistSigConfiguration_; + const edm::ParameterSet VtxDist3DSigConfiguration_; + const edm::ParameterSet DiMuMassConfiguration_; // control plots @@ -127,13 +126,14 @@ class DiMuonVertexValidation : public edm::one::EDAnalyzer ttbESToken_; - edm::EDGetTokenT tracksToken_; //used to select what tracks to read from configuration file - edm::EDGetTokenT vertexToken_; //used to select what vertices to read from configuration file + //used to select what tracks to read from configuration file + edm::EDGetTokenT tracksToken_; + //used to select what vertices to read from configuration file + const edm::EDGetTokenT vertexToken_; // either on or the other! - edm::EDGetTokenT muonsToken_; //used to select what tracks to read from configuration file - edm::EDGetTokenT - alcaRecoToken_; //used to select what muon tracks to read from configuration file + edm::EDGetTokenT muonsToken_; // used to select tracks to read from configuration file + edm::EDGetTokenT alcaRecoToken_; //used to select muon tracks to read from configuration file }; // @@ -350,7 +350,7 @@ void DiMuonVertexValidation::analyze(const edm::Event& iEvent, const edm::EventS // fill the VtxProb plots VtxProbPlots.fillPlots(SVProb, tktk_p4); - math::XYZPoint MainVertex(0, 0, 0); + math::XYZPoint mainVtxPos(0, 0, 0); const reco::Vertex* theClosestVertex = nullptr; // get collection of reconstructed vertices from event edm::Handle vertexHandle = iEvent.getHandle(vertexToken_); @@ -362,35 +362,35 @@ void DiMuonVertexValidation::analyze(const edm::Event& iEvent, const edm::EventS return; } - reco::Vertex TheMainVertex; + reco::Vertex theMainVertex; if (!useClosestVertex_ || theClosestVertex == nullptr) { // if the closest vertex is not available, or explicitly not chosen - TheMainVertex = vertexHandle.product()->front(); + theMainVertex = vertexHandle.product()->front(); } else { - TheMainVertex = *theClosestVertex; + theMainVertex = *theClosestVertex; } - MainVertex.SetXYZ(TheMainVertex.position().x(), TheMainVertex.position().y(), TheMainVertex.position().z()); + mainVtxPos.SetXYZ(theMainVertex.position().x(), theMainVertex.position().y(), theMainVertex.position().z()); const math::XYZPoint myVertex( aTransientVertex.position().x(), aTransientVertex.position().y(), aTransientVertex.position().z()); const math::XYZPoint deltaVtx( - MainVertex.x() - myVertex.x(), MainVertex.y() - myVertex.y(), MainVertex.z() - myVertex.z()); + mainVtxPos.x() - myVertex.x(), mainVtxPos.y() - myVertex.y(), mainVtxPos.z() - myVertex.z()); #ifdef EDM_ML_DEBUG edm::LogVerbatim("DiMuonVertexValidation") << "mm vertex position:" << aTransientVertex.position().x() << "," << aTransientVertex.position().y() << "," << aTransientVertex.position().z(); - edm::LogVerbatim("DiMuonVertexValidation") << "main vertex position:" << TheMainVertex.position().x() << "," - << TheMainVertex.position().y() << "," << TheMainVertex.position().z(); + edm::LogVerbatim("DiMuonVertexValidation") << "main vertex position:" << theMainVertex.position().x() << "," + << theMainVertex.position().y() << "," << theMainVertex.position().z(); #endif - if (TheMainVertex.isValid()) { + if (theMainVertex.isValid()) { // Z Vertex distance in the xy plane VertexDistanceXY vertTool; - double distance = vertTool.distance(aTransientVertex, TheMainVertex).value(); - double dist_err = vertTool.distance(aTransientVertex, TheMainVertex).error(); + double distance = vertTool.distance(aTransientVertex, theMainVertex).value(); + double dist_err = vertTool.distance(aTransientVertex, theMainVertex).error(); hSVDist_->Fill(distance * cmToum); hSVDistSig_->Fill(distance / dist_err); @@ -404,8 +404,8 @@ void DiMuonVertexValidation::analyze(const edm::Event& iEvent, const edm::EventS // Z Vertex distance in 3D VertexDistance3D vertTool3D; - double distance3D = vertTool3D.distance(aTransientVertex, TheMainVertex).value(); - double dist3D_err = vertTool3D.distance(aTransientVertex, TheMainVertex).error(); + double distance3D = vertTool3D.distance(aTransientVertex, theMainVertex).value(); + double dist3D_err = vertTool3D.distance(aTransientVertex, theMainVertex).error(); hSVDist3D_->Fill(distance3D * cmToum); hSVDist3DSig_->Fill(distance3D / dist3D_err); @@ -459,14 +459,32 @@ void DiMuonVertexValidation::beginJob() { TH1F::SetDefaultSumw2(kTRUE); hSVProb_ = fs->make("VtxProb", ";#mu^{+}#mu^{-} vertex probability;N(#mu#mu pairs)", 100, 0., 1.); - hSVDist_ = fs->make("VtxDist", ";PV-#mu^{+}#mu^{-} vertex xy distance [#mum];N(#mu#mu pairs)", 100, 0., 300.); - hSVDistSig_ = fs->make("VtxDistSig", ";PV-#mu^{+}#mu^{-} vertex xy distance signficance;N(#mu#mu pairs)", 100, 0., 5.); + auto extractRangeValues = [](const edm::ParameterSet& PSetConfiguration_) -> std::pair { + double min = PSetConfiguration_.getParameter("ymin"); + double max = PSetConfiguration_.getParameter("ymax"); + return {min, max}; + }; + + // take the range from the 2D histograms + const auto& svDistRng = extractRangeValues(VtxDistConfiguration_); + hSVDist_ = fs->make("VtxDist", ";PV-#mu^{+}#mu^{-} vertex xy distance [#mum];N(#mu#mu pairs)", 100, svDistRng.first, svDistRng.second); + + // take the range from the 2D histograms + const auto& svDistSigRng = extractRangeValues(VtxDistSigConfiguration_); + hSVDistSig_ = fs->make("VtxDistSig", ";PV-#mu^{+}#mu^{-} vertex xy distance signficance;N(#mu#mu pairs)", 100, svDistSigRng.first, svDistRng.second); + + // take the range from the 2D histograms + const auto& svDist3DRng = extractRangeValues(VtxDist3DConfiguration_); + hSVDist3D_ = fs->make("VtxDist3D", ";PV-#mu^{+}#mu^{-} vertex 3D distance [#mum];N(#mu#mu pairs)", 100, svDist3DRng.first, svDist3DRng.second); - hSVDist3D_ = fs->make("VtxDist3D", ";PV-#mu^{+}#mu^{-} vertex 3D distance [#mum];N(#mu#mu pairs)", 100, 0., 300.); - hSVDist3DSig_ = fs->make("VtxDist3DSig", ";PV-#mu^{+}#mu^{-} vertex 3D distance signficance;N(#mu#mu pairs)", 100, 0., 5.); + // take the range from the 2D histograms + const auto& svDist3DSigRng = extractRangeValues(VtxDist3DSigConfiguration_); + hSVDist3DSig_ = fs->make("VtxDist3DSig", ";PV-#mu^{+}#mu^{-} vertex 3D distance signficance;N(#mu#mu pairs)", 100, svDist3DSigRng.first, svDist3DSigRng.second); - hInvMass_ = fs->make("InvMass", ";M(#mu#mu) [GeV];N(#mu#mu pairs)", 70., 50., 120.); - hTrackInvMass_ = fs->make("TkTkInvMass", ";M(tk,tk) [GeV];N(tk tk pairs)", 70., 50., 120.); + // take the range from the 2D histograms + const auto& massRng = extractRangeValues(DiMuMassConfiguration_); + hInvMass_ = fs->make("InvMass", ";M(#mu#mu) [GeV];N(#mu#mu pairs)", 70., massRng.first, massRng.second); + hTrackInvMass_ = fs->make("TkTkInvMass", ";M(tk,tk) [GeV];N(tk tk pairs)", 70., massRng.first, massRng.second); hCosPhi_ = fs->make("CosPhi", ";cos(#phi_{xy});N(#mu#mu pairs)", 50, -1., 1.); hCosPhi3D_ = fs->make("CosPhi3D", ";cos(#phi_{3D});N(#mu#mu pairs)", 50, -1., 1.); diff --git a/Alignment/OfflineValidation/plugins/GeneralPurposeTrackAnalyzer.cc b/Alignment/OfflineValidation/plugins/GeneralPurposeTrackAnalyzer.cc index 080f8c39542e1..73f043c4cdd48 100644 --- a/Alignment/OfflineValidation/plugins/GeneralPurposeTrackAnalyzer.cc +++ b/Alignment/OfflineValidation/plugins/GeneralPurposeTrackAnalyzer.cc @@ -869,7 +869,7 @@ class GeneralPurposeTrackAnalyzer : public edm::one::EDAnalyzer("h_Eta", "Track pseudorapidity; track #eta;tracks", 100, -etaMax_, etaMax_); hPhi = book("h_Phi", "Track azimuth; track #phi;tracks", 100, -M_PI, M_PI); - hPhiBarrel = book("h_PhiBarrel", "hPhiBarrel (0<|#eta|<0.8);track #Phi;tracks", 100, -M_PI, M_PI); + hPhiBarrel = book("h_PhiBarrel", "hPhiBarrel (0<|#eta|<0.8);track #phi;tracks", 100, -M_PI, M_PI); hPhiOverlapPlus = book("h_PhiOverlapPlus", "hPhiOverlapPlus (0.8<#eta<1.4);track #phi;tracks", 100, -M_PI, M_PI); hPhiOverlapMinus = @@ -880,7 +880,7 @@ class GeneralPurposeTrackAnalyzer : public edm::one::EDAnalyzer("h_BSx0", "x-coordinate of reco beamspot;x^{BS}_{0};n_{events}", 100, -0.1, 0.1); h_BSy0 = book("h_BSy0", "y-coordinate of reco beamspot;y^{BS}_{0};n_{events}", 100, -0.1, 0.1); h_BSz0 = book("h_BSz0", "z-coordinate of reco beamspot;z^{BS}_{0};n_{events}", 100, -1., 1.); - h_Beamsigmaz = book("h_Beamsigmaz", "z-coordinate beam width;#sigma_{Z}^{beam};n_{events}", 100, 0., 1.); + h_Beamsigmaz = book("h_Beamsigmaz", "z-coordinate beam width;#sigma_{Z}^{beam};n_{events}", 100, 0., 7.); h_BeamWidthX = book("h_BeamWidthX", "x-coordinate beam width;#sigma_{X}^{beam};n_{events}", 100, 0., 0.01); h_BeamWidthY = book("h_BeamWidthY", "y-coordinate beam width;#sigma_{Y}^{beam};n_{events}", 100, 0., 0.01); h_BSdxdz = book("h_BSdxdz", "BeamSpot dxdz;beamspot dx/dz;n_{events}", 100, -0.0003, 0.0003); @@ -1126,6 +1126,12 @@ class GeneralPurposeTrackAnalyzer : public edm::one::EDAnalyzerGetXaxis()->SetBinLabel((the_r - theRuns_.front()) + 1, std::to_string(the_r).c_str()); } + static const int kappadiffindex = this->index(vTrackHistos_, "h_diff_curvature"); + vTrackHistos_[kappadiffindex]->Add(vTrackHistos_[this->index(vTrackHistos_, "h_curvature_neg")], + vTrackHistos_[this->index(vTrackHistos_, "h_curvature_pos")], + -1, + 1); + if (phase_ < SiPixelPI::phase::two) { if (phase_ == SiPixelPI::phase::zero) { pmap->save(true, 0, 0, "PixelHitMap.pdf", 600, 800); diff --git a/Alignment/OfflineValidation/python/TkAlAllInOneTool/defaultInputFiles_cff.py b/Alignment/OfflineValidation/python/TkAlAllInOneTool/defaultInputFiles_cff.py index 498441f5ac464..69a5e48f18e19 100644 --- a/Alignment/OfflineValidation/python/TkAlAllInOneTool/defaultInputFiles_cff.py +++ b/Alignment/OfflineValidation/python/TkAlAllInOneTool/defaultInputFiles_cff.py @@ -18,6 +18,8 @@ '/store/relval/CMSSW_12_5_3/RelValMinBias_14TeV/ALCARECO/TkAlMinBias-125X_mcRun4_realistic_v5_2026D88PU-v1/2590000/27b7ab93-1d2b-4f4a-a98e-68386c314b5e.root', ) +filesDefaultMC_DoubleMuonPUPhase_string = '/store/mc/Phase2Fall22DRMiniAOD/DYJetsToMuMu_M-50_TuneCP5_14TeV-madgraphMLM-pythia8/ALCARECO/TkAlZMuMu-PU200ALCA_TkAlPU200_125X_mcRun4_realistic_v5-v1/60000/9382696c-70fd-4b37-8a0f-24bd02aeda5f.root' + filesDefaultMC_MinBiasPUPhase2RECO = cms.untracked.vstring( '/store/relval/CMSSW_12_5_3/RelValMinBias_14TeV/GEN-SIM-RECO/125X_mcRun4_realistic_v5_2026D88PU-v1/2590000/22e22ae6-a353-4f2e-815e-cc5efee37af9.root', ) diff --git a/Alignment/OfflineValidation/test/inspectData_cfg.py b/Alignment/OfflineValidation/test/inspectData_cfg.py index f1a71b0422f44..261e89d7f4b48 100644 --- a/Alignment/OfflineValidation/test/inspectData_cfg.py +++ b/Alignment/OfflineValidation/test/inspectData_cfg.py @@ -1,6 +1,8 @@ +import math import glob +import importlib import FWCore.ParameterSet.Config as cms -from Alignment.OfflineValidation.TkAlAllInOneTool.defaultInputFiles_cff import filesDefaultData_Comissioning2022_Cosmics_string +from Alignment.OfflineValidation.TkAlAllInOneTool.defaultInputFiles_cff import filesDefaultData_Comissioning2022_Cosmics_string,filesDefaultMC_DoubleMuonPUPhase_string ################################################################### # Setup 'standard' options @@ -31,6 +33,18 @@ VarParsing.VarParsing.varType.bool, # string, int, or float "is it a unit test?") +options.register('isDiMuonData', + False, # default value + VarParsing.VarParsing.multiplicity.singleton, # singleton or list + VarParsing.VarParsing.varType.bool, # string, int, or float + "is it running on DiMuon data?") + +options.register('isCosmics', + False, # default value + VarParsing.VarParsing.multiplicity.singleton, # singleton or list + VarParsing.VarParsing.varType.bool, # string, int, or float + "is it running on cosmics data?") + options.register('inputData', "/eos/cms/store/express/Commissioning2022/ExpressCosmics/FEVT/Express-v1/000/350/010/00000/*", VarParsing.VarParsing.multiplicity.singleton, # singleton or list @@ -43,9 +57,33 @@ VarParsing.VarParsing.varType.int, # string, int, or float "num. events to run") +options.register('Detector', + '2023', + VarParsing.VarParsing.multiplicity.singleton, # singleton or list + VarParsing.VarParsing.varType.string, # string, int, or float + "Detector to run upon") + options.parseArguments() -process = cms.Process("AlCaRECOAnalysis") + +from Configuration.PyReleaseValidation.upgradeWorkflowComponents import upgradeProperties +ConditionsInfo = {} +if 'D' in options.Detector: + ConditionsInfo = upgradeProperties[2026][options.Detector] # so if the default changes, change wf only here +else: + ConditionsInfo = upgradeProperties[2017][options.Detector] + +era_value = ConditionsInfo['Era'] +era_module_name = f'Configuration.Eras.Era_{era_value}_cff' +config_name = f'{era_value}' +era_module = importlib.import_module(era_module_name) +era_config = getattr(era_module, config_name, None) + +if era_config is not None: + # Use the configurations from the imported module in the process setup + process = cms.Process("AlCaRECOAnalysis", era_config) +else: + print(f"Error: Could not find configuration {config_name} in module {era_module_name}.") ################################################################### # Message logger service @@ -71,7 +109,12 @@ ################################################################### process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff") process.load("Configuration.StandardSequences.Services_cff") -process.load("Configuration.StandardSequences.GeometryRecoDB_cff") +if 'D' in options.Detector: + geom = options.Detector # Replace with your actual dynamic part + process.load(f'Configuration.Geometry.GeometryExtended{geom}Reco_cff') +else: + process.load("Configuration.StandardSequences.GeometryRecoDB_cff") + process.load('Configuration.StandardSequences.MagneticField_cff') #process.load("Configuration.StandardSequences.MagneticField_0T_cff") process.load("CondCore.CondDB.CondDB_cfi") @@ -81,7 +124,7 @@ #################################################################### process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") from Configuration.AlCa.GlobalTag import GlobalTag -process.GlobalTag = GlobalTag(process.GlobalTag,options.globalTag, '') +process.GlobalTag = GlobalTag(process.GlobalTag,options.globalTag if (options.globalTag != '') else ConditionsInfo['GT'], '') ################################################################### # Source @@ -91,11 +134,19 @@ the_files=[] if(options.unitTest): ## fixed input for the unit test - readFiles.extend([filesDefaultData_Comissioning2022_Cosmics_string]) + if('D' in options.Detector) : + # it's for phase-2 + readFiles.extend([filesDefaultMC_DoubleMuonPUPhase_string]) + else: + # it's for phase-1 + readFiles.extend([filesDefaultData_Comissioning2022_Cosmics_string]) else: file_list = glob.glob(options.inputData) for f in file_list: - the_files.append(f.replace("/eos/cms","")) + if '/eos/cms' in f: + the_files.append(f.replace("/eos/cms","")) + else: + the_files.append(f.replace("./","file:")) print(the_files) readFiles.extend(the_files) @@ -135,13 +186,21 @@ ################################################################### process.load("RecoTracker.TrackProducer.TrackRefitters_cff") import RecoTracker.TrackProducer.TrackRefitters_cff -process.TrackRefitter1 = process.TrackRefitterP5.clone( - src = options.trackCollection, #'AliMomConstraint', - TrajectoryInEvent = True, - TTRHBuilder = "WithAngleAndTemplate", #"WithTrackAngle" - NavigationSchool = "", - #constraint = 'momentum', ### SPECIFIC FOR CRUZET - #srcConstr='AliMomConstraint' ### SPECIFIC FOR CRUZET$works only with tag V02-10-02 TrackingTools/PatternTools / or CMSSW >=31X +if options.isCosmics: + process.TrackRefitter1 = process.TrackRefitterP5.clone( + src = options.trackCollection, #'AliMomConstraint', + TrajectoryInEvent = True, + TTRHBuilder = "WithAngleAndTemplate", #"WithTrackAngle" + NavigationSchool = "", + #constraint = 'momentum', ### SPECIFIC FOR CRUZET + #srcConstr='AliMomConstraint' ### SPECIFIC FOR CRUZET$works only with tag V02-10-02 TrackingTools/PatternTools / or CMSSW >=31X + ) +else: + process.TrackRefitter1 = RecoTracker.TrackProducer.TrackRefitter_cfi.TrackRefitter.clone( + src = options.trackCollection, #'AliMomConstraint', + TrajectoryInEvent = True, + TTRHBuilder = "WithAngleAndTemplate", #"WithTrackAngle" + NavigationSchool = "", ) ################################################################### @@ -161,11 +220,12 @@ ################################################################### process.myanalysis = cms.EDAnalyzer("GeneralPurposeTrackAnalyzer", TkTag = cms.InputTag('TrackRefitter1'), - isCosmics = cms.bool(True)) + #TkTag = cms.InputTag(options.trackCollection), + isCosmics = cms.bool(options.isCosmics)) process.fastdmr = cms.EDAnalyzer("DMRChecker", TkTag = cms.InputTag('TrackRefitter1'), - isCosmics = cms.bool(True)) + isCosmics = cms.bool(options.isCosmics)) ################################################################### # Output name @@ -173,17 +233,88 @@ process.TFileService = cms.Service("TFileService", fileName = cms.string(options.outFileName)) + +################################################################### +# TransientTrack from https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideTransientTracks +################################################################### +process.load("TrackingTools.TransientTrack.TransientTrackBuilder_cfi") +process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorOpposite_cfi') +process.load('TrackPropagation.SteppingHelixPropagator.SteppingHelixPropagatorAlong_cfi') +process.load('TrackingTools.TrackAssociator.DetIdAssociatorESProducer_cff') + +process.DiMuonVertexValidation = cms.EDAnalyzer("DiMuonVertexValidation", + useReco = cms.bool(False), + muonTracks = cms.InputTag('TrackRefitter1'), + tracks = cms.InputTag(''), + vertices = cms.InputTag('offlinePrimaryVertices')) + +from Alignment.OfflineValidation.diMuonValidation_cfi import diMuonValidation as _diMuonValidation +process.DiMuonMassValidation = _diMuonValidation.clone( + #TkTag = 'refittedMuons', + TkTag = 'TrackRefitter1', + # mu mu mass + Pair_mass_min = 80., + Pair_mass_max = 120., + Pair_mass_nbins = 80, + Pair_etaminpos = -2.4, + Pair_etamaxpos = 2.4, + Pair_etaminneg = -2.4, + Pair_etamaxneg = 2.4, + # cosTheta CS + Variable_CosThetaCS_xmin = -1., + Variable_CosThetaCS_xmax = 1., + Variable_CosThetaCS_nbins = 20, + # DeltaEta + Variable_DeltaEta_xmin = -4.8, + Variable_DeltaEta_xmax = 4.8, + Variable_DeltaEta_nbins = 20, + # EtaMinus + Variable_EtaMinus_xmin = -2.4, + Variable_EtaMinus_xmax = 2.4, + Variable_EtaMinus_nbins = 12, + # EtaPlus + Variable_EtaPlus_xmin = -2.4, + Variable_EtaPlus_xmax = 2.4, + Variable_EtaPlus_nbins = 12, + # Phi CS + Variable_PhiCS_xmin = -math.pi/2., + Variable_PhiCS_xmax = math.pi/2., + Variable_PhiCS_nbins = 20, + # Phi Minus + Variable_PhiMinus_xmin = -math.pi, + Variable_PhiMinus_xmax = math.pi, + Variable_PhiMinus_nbins = 16, + # Phi Plus + Variable_PhiPlus_xmin = -math.pi, + Variable_PhiPlus_xmax = math.pi, + Variable_PhiPlus_nbins = 16, + # mu mu pT + Variable_PairPt_xmin = 0., + Variable_PairPt_xmax = 100., + Variable_PairPt_nbins = 100) + ################################################################### # Path ################################################################### process.p1 = cms.Path(process.offlineBeamSpot #*process.AliMomConstraint # for 0T - *process.TrackRefitter1 - *process.myanalysis - *process.fastdmr) + * process.TrackRefitter1 + * process.myanalysis + * process.fastdmr) ################################################################### -# preprend the filter +# append di muon analysis ################################################################### -if(options.unitTest): +if(options.isDiMuonData): + process.p1.insert(5,process.DiMuonVertexValidation) + process.p1.insert(6,process.DiMuonMassValidation) + +################################################################### +# preprend the filter for unit tests +################################################################### +if(options.unitTest and not options.isDiMuonData): process.p1.insert(0, process.preAnaSeq) + + + + diff --git a/Alignment/OfflineValidation/test/testingScripts/test_unitMiscellanea.sh b/Alignment/OfflineValidation/test/testingScripts/test_unitMiscellanea.sh index 1a4735bac6287..1f339a3bb3779 100755 --- a/Alignment/OfflineValidation/test/testingScripts/test_unitMiscellanea.sh +++ b/Alignment/OfflineValidation/test/testingScripts/test_unitMiscellanea.sh @@ -2,7 +2,10 @@ function die { echo $1: status $2 ; exit $2; } echo "TESTING inspect ALCARECO data ..." -cmsRun ${CMSSW_BASE}/src/Alignment/OfflineValidation/test/inspectData_cfg.py unitTest=True trackCollection=ALCARECOTkAlCosmicsCTF0T || die "Failure running inspectData_cfg.py" $? +cmsRun ${CMSSW_BASE}/src/Alignment/OfflineValidation/test/inspectData_cfg.py unitTest=True isCosmics=True trackCollection=ALCARECOTkAlCosmicsCTF0T || die "Failure running inspectData_cfg.py" $? + +echo "TESTING inspect Phase2 ALCARECO data ..." +cmsRun ${CMSSW_BASE}/src/Alignment/OfflineValidation/test/inspectData_cfg.py unitTest=True isCosmics=False globalTag='' trackCollection=ALCARECOTkAlZMuMu isDiMuonData=True Detector='2026D98' || die "Failure running inspectData_cfg.py on Phase-2 input" $? echo "TESTING G4e refitter ..." cmsRun ${CMSSW_BASE}/src/Alignment/OfflineValidation/test/testG4Refitter_cfg.py maxEvents=10 || die "Failure running testG4Refitter_cfg.py" $?