diff --git a/Alignment/CommonAlignmentProducer/python/ALCARECOTkAlCosmics0T_Output_cff.py b/Alignment/CommonAlignmentProducer/python/ALCARECOTkAlCosmics0T_Output_cff.py index 5c2b81e68b6a5..3ed7add1c59b7 100644 --- a/Alignment/CommonAlignmentProducer/python/ALCARECOTkAlCosmics0T_Output_cff.py +++ b/Alignment/CommonAlignmentProducer/python/ALCARECOTkAlCosmics0T_Output_cff.py @@ -6,14 +6,17 @@ OutALCARECOTkAlCosmics0T_noDrop = cms.PSet( SelectEvents = cms.untracked.PSet( SelectEvents = cms.vstring('pathALCARECOTkAlCosmicsCTF0T', - 'pathALCARECOTkAlCosmicsCosmicTF0T', - 'pathALCARECOTkAlCosmicsRegional0T') + 'pathALCARECOTkAlCosmicsCosmicTF0T', + 'pathALCARECOTkAlCosmicsRegional0T', + 'pathALCARECOTkAlCosmicsDuringCollisions0T' + ) ), outputCommands = cms.untracked.vstring( #'keep *_ALCARECOTkAlCosmics*0T_*_*', 'keep *_ALCARECOTkAlCosmicsCTF0T_*_*', 'keep *_ALCARECOTkAlCosmicsCosmicTF0T_*_*', 'keep *_ALCARECOTkAlCosmicsRegional0T_*_*', + 'keep *_ALCARECOTkAlCosmicsDuringCollisions0T_*_*', 'keep siStripDigis_DetIdCollection_*_*', 'keep L1AcceptBunchCrossings_*_*_*', 'keep L1GlobalTriggerReadoutRecord_gtDigis_*_*', diff --git a/Alignment/CommonAlignmentProducer/python/ALCARECOTkAlCosmics0T_cff.py b/Alignment/CommonAlignmentProducer/python/ALCARECOTkAlCosmics0T_cff.py index 9988df3909c63..2519602d28c7a 100644 --- a/Alignment/CommonAlignmentProducer/python/ALCARECOTkAlCosmics0T_cff.py +++ b/Alignment/CommonAlignmentProducer/python/ALCARECOTkAlCosmics0T_cff.py @@ -46,7 +46,14 @@ src = 'regionalCosmicTracks' ) +# AlCaReco for track based alignment using Cosmic muons reconstructed by Cosmics During Collisions Algorithm +# (same cuts) +ALCARECOTkAlCosmicsDuringCollisions0T = ALCARECOTkAlCosmicsCTF0T.clone( + src = 'cosmicDCTracks' + ) + #________________________________Sequences____________________________________ seqALCARECOTkAlCosmicsCTF0T = cms.Sequence(ALCARECOTkAlCosmicsCTF0T) seqALCARECOTkAlCosmicsCosmicTF0T = cms.Sequence(ALCARECOTkAlCosmicsCosmicTF0T) seqALCARECOTkAlCosmicsRegional0T = cms.Sequence(ALCARECOTkAlCosmicsRegional0T) +seqALCARECOTkAlCosmicsDuringCollisions0T = cms.Sequence(ALCARECOTkAlCosmicsDuringCollisions0T) diff --git a/Alignment/OfflineValidation/python/TkAlAllInOneTool/helperFunctions.py b/Alignment/OfflineValidation/python/TkAlAllInOneTool/helperFunctions.py index 6e0bea068dc08..1953c0d4c76c5 100644 --- a/Alignment/OfflineValidation/python/TkAlAllInOneTool/helperFunctions.py +++ b/Alignment/OfflineValidation/python/TkAlAllInOneTool/helperFunctions.py @@ -202,9 +202,12 @@ def getTagsMap(db): con = conddblib.connect(url = conddblib.make_url(db)) session = con.session() TAG = session.get_dbtype(conddblib.Tag) - q1 = session.query(TAG.object_type).order_by(TAG.name).all()[0] - q2 = session.query(TAG.name).order_by(TAG.name).all()[0] - dictionary = dict(zip(q1, q2)) + dictionary = {} + for i in range(0,len(session.query(TAG.object_type).order_by(TAG.name).all())): + q1 = session.query(TAG.object_type).order_by(TAG.name).all()[i][0] + q2 = session.query(TAG.name).order_by(TAG.name).all()[i][0] + dictionary[q1]=q2 + return dictionary def clean_name(s): diff --git a/Alignment/OfflineValidation/test/test_all.sh b/Alignment/OfflineValidation/test/test_all.sh index 7a70bc72962a6..ed9a27885be61 100755 --- a/Alignment/OfflineValidation/test/test_all.sh +++ b/Alignment/OfflineValidation/test/test_all.sh @@ -12,6 +12,7 @@ fi ## copy into local sqlite file the ideal alignment echo "COPYING locally Ideal Alignment ..." conddb --yes --db pro copy TrackerAlignment_Upgrade2017_design_v4 --destdb myfile.db +conddb --yes --db pro copy TrackerAlignmentErrorsExtended_Upgrade2017_design_v0 --destdb myfile.db echo "GENERATING all-in-one tool configuration ..." cat <> validation_config.ini @@ -29,6 +30,7 @@ style = 2001 title = express globaltag = 92X_dataRun2_Express_v2 condition TrackerAlignmentRcd = sqlite_file:myfile.db,TrackerAlignment_Upgrade2017_design_v4 +condition TrackerAlignmentErrorExtendedRcd = sqlite_file:myfile.db,TrackerAlignmentErrorsExtended_Upgrade2017_design_v0 color = 2 style = 2402 diff --git a/CondCore/SiPixelPlugins/interface/Phase1PixelMaps.h b/CondCore/SiPixelPlugins/interface/Phase1PixelMaps.h index 3c5835e6589a4..168049075babc 100644 --- a/CondCore/SiPixelPlugins/interface/Phase1PixelMaps.h +++ b/CondCore/SiPixelPlugins/interface/Phase1PixelMaps.h @@ -28,7 +28,7 @@ class Phase1PixelMaps { ~Phase1PixelMaps() {} //============================================================================ - void bookBarrelHistograms(const std::string& currentHistoName, const char* what) { + void bookBarrelHistograms(const std::string& currentHistoName, const char* what, const char* zaxis) { std::string histName; std::shared_ptr th2p; @@ -46,8 +46,8 @@ class Phase1PixelMaps { th2p->GetXaxis()->SetTitle("z [cm]"); th2p->GetYaxis()->SetTitle("ladder"); - //th2p->GetXaxis()->SetTitleOffset(0.09); - //th2p->GetYaxis()->SetTitleOffset(0.09); + th2p->GetZaxis()->SetTitle(zaxis); + th2p->GetZaxis()->CenterTitle(); th2p->SetStats(false); th2p->SetOption(m_option); pxbTh2PolyBarrel[currentHistoName].push_back(th2p); @@ -64,7 +64,7 @@ class Phase1PixelMaps { } //============================================================================ - void bookForwardHistograms(const std::string& currentHistoName, const char* what) { + void bookForwardHistograms(const std::string& currentHistoName, const char* what, const char* zaxis) { std::string histName; std::shared_ptr th2p; @@ -81,8 +81,8 @@ class Phase1PixelMaps { th2p->SetFloat(); th2p->GetXaxis()->SetTitle("x [cm]"); th2p->GetYaxis()->SetTitle("y [cm]"); - //th2p->GetXaxis()->SetTitleOffset(0.09); - //th2p->GetYaxis()->SetTitleOffset(0.09); + th2p->GetZaxis()->SetTitle(zaxis); + th2p->GetZaxis()->CenterTitle(); th2p->SetStats(false); th2p->SetOption(m_option); pxfTh2PolyForward[currentHistoName].push_back(th2p); @@ -208,6 +208,8 @@ class Phase1PixelMaps { SiPixelPI::makeNicePlotStyle(plot.get()); plot->GetXaxis()->SetTitleOffset(0.9); plot->GetYaxis()->SetTitleOffset(0.9); + plot->GetZaxis()->SetTitleOffset(1.2); + plot->GetZaxis()->SetTitleSize(0.05); } } @@ -216,10 +218,54 @@ class Phase1PixelMaps { SiPixelPI::makeNicePlotStyle(plot.get()); plot->GetXaxis()->SetTitleOffset(0.9); plot->GetYaxis()->SetTitleOffset(0.9); + plot->GetZaxis()->SetTitleOffset(1.2); + plot->GetZaxis()->SetTitleSize(0.05); } } } + //============================================================================ + void rescaleAllBarrel(const std::string& currentHistoName) { + std::vector maxima; + std::transform(pxbTh2PolyBarrel[currentHistoName].begin(), + pxbTh2PolyBarrel[currentHistoName].end(), + std::back_inserter(maxima), + [](std::shared_ptr thp) -> float { return thp->GetMaximum(); }); + std::vector minima; + std::transform(pxbTh2PolyBarrel[currentHistoName].begin(), + pxbTh2PolyBarrel[currentHistoName].end(), + std::back_inserter(minima), + [](std::shared_ptr thp) -> float { return thp->GetMinimum(); }); + + auto globalMax = *std::max_element(maxima.begin(), maxima.end()); + auto globalMin = *std::min_element(minima.begin(), minima.end()); + + for (auto& histo : pxbTh2PolyBarrel[currentHistoName]) { + histo->GetZaxis()->SetRangeUser(globalMin, globalMax); + } + } + + //============================================================================ + void rescaleAllForward(const std::string& currentHistoName) { + std::vector maxima; + std::transform(pxfTh2PolyForward[currentHistoName].begin(), + pxfTh2PolyForward[currentHistoName].end(), + std::back_inserter(maxima), + [](std::shared_ptr thp) -> float { return thp->GetMaximum(); }); + std::vector minima; + std::transform(pxfTh2PolyForward[currentHistoName].begin(), + pxfTh2PolyForward[currentHistoName].end(), + std::back_inserter(minima), + [](std::shared_ptr thp) -> float { return thp->GetMinimum(); }); + + auto globalMax = *std::max_element(maxima.begin(), maxima.end()); + auto globalMin = *std::min_element(minima.begin(), minima.end()); + + for (auto& histo : pxfTh2PolyForward[currentHistoName]) { + histo->GetZaxis()->SetRangeUser(globalMin, globalMax); + } + } + //============================================================================ void DrawBarrelMaps(const std::string& currentHistoName, TCanvas& canvas) { canvas.Divide(2, 2); @@ -229,7 +275,8 @@ class Phase1PixelMaps { canvas.cd(i)->SetRightMargin(0.02); pxbTh2PolyBarrel[currentHistoName].at(i - 1)->SetMarkerColor(kRed); } else { - SiPixelPI::adjustCanvasMargins(canvas.cd(i), 0.07, 0.12, 0.10, 0.14); + rescaleAllBarrel(currentHistoName); + SiPixelPI::adjustCanvasMargins(canvas.cd(i), 0.07, 0.12, 0.10, 0.18); } pxbTh2PolyBarrel[currentHistoName].at(i - 1)->Draw(); } @@ -244,7 +291,8 @@ class Phase1PixelMaps { canvas.cd(i)->SetRightMargin(0.02); pxfTh2PolyForward[currentHistoName].at(i - 1)->SetMarkerColor(kRed); } else { - SiPixelPI::adjustCanvasMargins(canvas.cd(i), 0.07, 0.12, 0.10, 0.16); + rescaleAllForward(currentHistoName); + SiPixelPI::adjustCanvasMargins(canvas.cd(i), 0.07, 0.12, 0.10, 0.18); } pxfTh2PolyForward[currentHistoName].at(i - 1)->Draw(); } diff --git a/CondCore/SiPixelPlugins/interface/PixelRegionContainers.h b/CondCore/SiPixelPlugins/interface/PixelRegionContainers.h index d80b88458b303..83215f55d5ad2 100644 --- a/CondCore/SiPixelPlugins/interface/PixelRegionContainers.h +++ b/CondCore/SiPixelPlugins/interface/PixelRegionContainers.h @@ -200,7 +200,7 @@ namespace PixelRegions { } //============================================================================ - void draw(TCanvas& canv, bool isBarrel, const char* option = "bar2", bool isComparison = false) { + void draw(TCanvas& canv, bool isBarrel, const char* option = "bar2", bool isPhase1Comparison = false) { if (isBarrel) { for (int j = 1; j <= 4; j++) { if (!m_isLog) { @@ -208,7 +208,7 @@ namespace PixelRegions { } else { canv.cd(j)->SetLogy(); } - if ((j == 4) && !m_isPhase1 && !isComparison) { + if ((j == 4) && !m_isPhase1 && !isPhase1Comparison) { m_theMap.at(PixelIDs[j - 1])->Draw("AXIS"); TLatex t2; t2.SetTextAlign(22); @@ -228,7 +228,7 @@ namespace PixelRegions { } else { canv.cd(j)->SetLogy(); } - if ((j % 6 == 5 || j % 6 == 0) && !m_isPhase1 && !isComparison) { + if ((j % 6 == 5 || j % 6 == 0) && !m_isPhase1 && !isPhase1Comparison) { m_theMap.at(PixelIDs[j + 3])->Draw("AXIS"); TLatex t2; t2.SetTextAlign(22); diff --git a/CondCore/SiPixelPlugins/interface/SiPixelGainCalibHelper.h b/CondCore/SiPixelPlugins/interface/SiPixelGainCalibHelper.h index f2cf840075a7c..a5d60e691d0dc 100644 --- a/CondCore/SiPixelPlugins/interface/SiPixelGainCalibHelper.h +++ b/CondCore/SiPixelPlugins/interface/SiPixelGainCalibHelper.h @@ -334,7 +334,7 @@ namespace gainCalibHelper { auto iov = tag.iovs.front(); // parse first if log - bool setLog(false); + bool setLog(true); auto paramValues = cond::payloadInspector::PlotBase::inputParamValues(); auto ip = paramValues.find("SetLog"); if (ip != paramValues.end()) { @@ -404,7 +404,7 @@ namespace gainCalibHelper { if (setLog) { myPlots.setLogScale(); } - myPlots.beautify(kBlue, 10); + myPlots.beautify(kBlue, -1); myPlots.draw(canvas, isBarrel, "HIST"); TLegend legend = TLegend(0.45, 0.88, 0.91, 0.92); @@ -418,7 +418,7 @@ namespace gainCalibHelper { unsigned int maxPads = isBarrel ? 4 : 12; for (unsigned int c = 1; c <= maxPads; c++) { canvas.cd(c); - SiPixelPI::adjustCanvasMargins(canvas.cd(c), 0.07, 0.12, 0.12, 0.05); + SiPixelPI::adjustCanvasMargins(canvas.cd(c), 0.06, 0.12, 0.12, 0.05); legend.Draw("same"); canvas.cd(c)->Update(); } @@ -453,12 +453,16 @@ namespace gainCalibHelper { /******************************************************************* 1d histograms comparison per region of SiPixelGainCalibration for Gains of 2 IOV ********************************************************************/ - template + template class SiPixelGainCalibrationValuesComparisonPerRegion - : public cond::payloadInspector::PlotImage { + : public cond::payloadInspector::PlotImage { public: SiPixelGainCalibrationValuesComparisonPerRegion() - : cond::payloadInspector::PlotImage( + : cond::payloadInspector::PlotImage( Form("SiPixelGainCalibration %s Values Per Region %i tag(s)", TypeName[myType], ntags)) { cond::payloadInspector::PlotBase::addInputParam("SetLog"); @@ -495,7 +499,7 @@ namespace gainCalibHelper { } // parse first if log - bool setLog(false); + bool setLog(true); auto paramValues = cond::payloadInspector::PlotBase::inputParamValues(); auto ip = paramValues.find("SetLog"); if (ip != paramValues.end()) { @@ -545,13 +549,15 @@ namespace gainCalibHelper { canvas.Divide(isBarrel ? 2 : 4, isBarrel ? 2 : 3); canvas.cd(); - const char* path_toTopologyXML = (l_detids.size() == SiPixelPI::phase0size) - ? "Geometry/TrackerCommonData/data/trackerParameters.xml" - : "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml"; + bool is_l_phase0 = (l_detids.size() == SiPixelPI::phase0size); + bool is_f_phase0 = (f_detids.size() == SiPixelPI::phase0size); + + const char* path_toTopologyXML = is_l_phase0 ? "Geometry/TrackerCommonData/data/trackerParameters.xml" + : "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml"; auto l_tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath(path_toTopologyXML).fullPath()); - auto l_myPlots = PixelRegions::PixelRegionContainers(&l_tTopo, (l_detids.size() == SiPixelPI::phase1size)); + auto l_myPlots = PixelRegions::PixelRegionContainers(&l_tTopo, !is_l_phase0); l_myPlots.bookAll( Form("Last SiPixel Gain Calibration %s - %s", (isForHLT_ ? "ForHLT" : "Offline"), TypeName[myType]), Form("per %s %s", (isForHLT_ ? "Column" : "Pixel"), TypeName[myType]), @@ -560,13 +566,12 @@ namespace gainCalibHelper { minimum, maximum); - path_toTopologyXML = (f_detids.size() == SiPixelPI::phase0size) - ? "Geometry/TrackerCommonData/data/trackerParameters.xml" - : "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml"; + path_toTopologyXML = is_f_phase0 ? "Geometry/TrackerCommonData/data/trackerParameters.xml" + : "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml"; auto f_tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath(path_toTopologyXML).fullPath()); - auto f_myPlots = PixelRegions::PixelRegionContainers(&f_tTopo, (f_detids.size() == SiPixelPI::phase1size)); + auto f_myPlots = PixelRegions::PixelRegionContainers(&f_tTopo, !is_f_phase0); f_myPlots.bookAll( Form("First SiPixel Gain Calibration %s - %s", (isForHLT_ ? "ForHLT" : "Offline"), TypeName[myType]), Form("per %s %s", (isForHLT_ ? "Column" : "Pixel"), TypeName[myType]), @@ -577,8 +582,8 @@ namespace gainCalibHelper { // fill the histograms for (const auto& pixelId : PixelRegions::PixelIDs) { - auto f_wantedDets = PixelRegions::attachedDets(pixelId, &f_tTopo, (f_detids.size() == SiPixelPI::phase1size)); - auto l_wantedDets = PixelRegions::attachedDets(pixelId, &l_tTopo, (l_detids.size() == SiPixelPI::phase1size)); + auto f_wantedDets = PixelRegions::attachedDets(pixelId, &f_tTopo, !is_f_phase0); + auto l_wantedDets = PixelRegions::attachedDets(pixelId, &l_tTopo, !is_l_phase0); gainCalibPI::fillTheHisto(first_payload, f_myPlots.getHistoFromMap(pixelId), myType, f_wantedDets); gainCalibPI::fillTheHisto(last_payload, l_myPlots.getHistoFromMap(pixelId), myType, l_wantedDets); } @@ -591,8 +596,8 @@ namespace gainCalibHelper { l_myPlots.beautify(kRed, -1); f_myPlots.beautify(kAzure, -1); - l_myPlots.draw(canvas, isBarrel, "HIST", true); - f_myPlots.draw(canvas, isBarrel, "HISTsames", true); + l_myPlots.draw(canvas, isBarrel, "HIST", (!is_f_phase0 || !is_l_phase0)); + f_myPlots.draw(canvas, isBarrel, "HISTsames", (!is_f_phase0 || !is_l_phase0)); // rescale the y-axis ranges in order to fit the canvas l_myPlots.rescaleMax(f_myPlots); @@ -857,7 +862,6 @@ namespace gainCalibHelper { hBPix->SetFillColor(kBlue); hBPix->SetMarkerStyle(20); hBPix->SetMarkerSize(1); - //hBPix->Draw("bar2"); hBPix->Draw("hist"); SiPixelPI::makeNicePlotStyle(hBPix.get()); @@ -869,7 +873,6 @@ namespace gainCalibHelper { hFPix->SetFillColor(kBlue); hFPix->SetMarkerStyle(20); hFPix->SetMarkerSize(1); - //hFPix->Draw("bar2"); hFPix->Draw("hist"); SiPixelPI::makeNicePlotStyle(hFPix.get()); @@ -1011,16 +1014,13 @@ namespace gainCalibHelper { hfirst->GetYaxis()->SetRangeUser(1., extrema.second * 10); hfirst->SetTitle(""); - //hfirst->SetFillColor(kRed); hfirst->SetLineColor(kRed); hfirst->SetBarWidth(0.95); - //hfirst->Draw("histbar"); hfirst->Draw("hist"); hlast->SetTitle(""); hlast->SetFillColorAlpha(kBlue, 0.20); hlast->SetBarWidth(0.95); - //hlast->Draw("histbarsame"); hlast->Draw("histsames"); SiPixelPI::makeNicePlotStyle(hfirst.get()); diff --git a/CondCore/SiPixelPlugins/interface/SiPixelPayloadInspectorHelper.h b/CondCore/SiPixelPlugins/interface/SiPixelPayloadInspectorHelper.h index 6fccd04684e94..a5567179deba0 100644 --- a/CondCore/SiPixelPlugins/interface/SiPixelPayloadInspectorHelper.h +++ b/CondCore/SiPixelPlugins/interface/SiPixelPayloadInspectorHelper.h @@ -804,14 +804,10 @@ namespace SiPixelPI { /*--------------------------------------------------------------------*/ { std::vector> rocsToMask; - - //int nblade_list[2] = {11, 17}; int nybins_list[2] = {92, 140}; - //int nblade = nblade_list[ring - 1]; int nybins = nybins_list[ring - 1]; int start_x = disk > 0 ? ((disk + 3) * 8) + 1 : ((3 - (std::abs(disk))) * 8) + 1; - //int start_y = blade > 0 ? ((blade+nblade)*4)-panel*2 : ((nblade-(std::abs(blade)))*4)-panel*2; int start_y = blade > 0 ? (nybins / 2) + (blade * 4) - (panel * 2) + 3 : ((nybins / 2) - (std::abs(blade) * 4) - panel * 2) + 3; @@ -839,14 +835,10 @@ namespace SiPixelPI { /*--------------------------------------------------------------------*/ { std::vector> rocsToMask; - - //int nblade_list[2] = {11, 17}; int nybins_list[2] = {92, 140}; - //int nblade = nblade_list[ring - 1]; int nybins = nybins_list[ring - 1]; int start_x = disk > 0 ? ((disk + 3) * 8) + 1 : ((3 - (std::abs(disk))) * 8) + 1; - //int start_y = blade > 0 ? ((blade+nblade)*4)-panel*2 : ((nblade-(std::abs(blade)))*4)-panel*2; int start_y = blade > 0 ? (nybins / 2) + (blade * 4) - (panel * 2) + 3 : ((nybins / 2) - (std::abs(blade) * 4) - panel * 2) + 3; diff --git a/CondCore/SiPixelPlugins/plugins/SiPixelGainCalibrationForHLT_PayloadInspector.cc b/CondCore/SiPixelPlugins/plugins/SiPixelGainCalibrationForHLT_PayloadInspector.cc index fd48d675aa07c..c8e9fd710e9b9 100644 --- a/CondCore/SiPixelPlugins/plugins/SiPixelGainCalibrationForHLT_PayloadInspector.cc +++ b/CondCore/SiPixelPlugins/plugins/SiPixelGainCalibrationForHLT_PayloadInspector.cc @@ -57,48 +57,56 @@ namespace { using SiPixelGainCalibForHLTGainComparisonBarrelSingleTag = gainCalibHelper::SiPixelGainCalibrationValuesComparisonPerRegion; using SiPixelGainCalibForHLTPedestalComparisonBarrelSingleTag = gainCalibHelper::SiPixelGainCalibrationValuesComparisonPerRegion; using SiPixelGainCalibForHLTGainComparisonBarrelTwoTags = gainCalibHelper::SiPixelGainCalibrationValuesComparisonPerRegion; using SiPixelGainCalibForHLTPedestalComparisonBarrelTwoTags = gainCalibHelper::SiPixelGainCalibrationValuesComparisonPerRegion; using SiPixelGainCalibForHLTGainComparisonEndcapSingleTag = gainCalibHelper::SiPixelGainCalibrationValuesComparisonPerRegion; using SiPixelGainCalibForHLTPedestalComparisonEndcapSingleTag = gainCalibHelper::SiPixelGainCalibrationValuesComparisonPerRegion; using SiPixelGainCalibForHLTGainComparisonEndcapTwoTags = gainCalibHelper::SiPixelGainCalibrationValuesComparisonPerRegion; using SiPixelGainCalibForHLTPedestalComparisonEndcapTwoTags = gainCalibHelper::SiPixelGainCalibrationValuesComparisonPerRegion; diff --git a/CondCore/SiPixelPlugins/plugins/SiPixelGainCalibrationOffline_PayloadInspector.cc b/CondCore/SiPixelPlugins/plugins/SiPixelGainCalibrationOffline_PayloadInspector.cc index bf84f66cfe4b3..525be85463a0e 100644 --- a/CondCore/SiPixelPlugins/plugins/SiPixelGainCalibrationOffline_PayloadInspector.cc +++ b/CondCore/SiPixelPlugins/plugins/SiPixelGainCalibrationOffline_PayloadInspector.cc @@ -57,48 +57,56 @@ namespace { using SiPixelGainCalibOfflineGainComparisonBarrelSingleTag = gainCalibHelper::SiPixelGainCalibrationValuesComparisonPerRegion; using SiPixelGainCalibOfflinePedestalComparisonBarrelSingleTag = gainCalibHelper::SiPixelGainCalibrationValuesComparisonPerRegion; using SiPixelGainCalibOfflineGainComparisonBarrelTwoTags = gainCalibHelper::SiPixelGainCalibrationValuesComparisonPerRegion; using SiPixelGainCalibOfflinePedestalComparisonBarrelTwoTags = gainCalibHelper::SiPixelGainCalibrationValuesComparisonPerRegion; using SiPixelGainCalibOfflineGainComparisonEndcapSingleTag = gainCalibHelper::SiPixelGainCalibrationValuesComparisonPerRegion; using SiPixelGainCalibOfflinePedestalComparisonEndcapSingleTag = gainCalibHelper::SiPixelGainCalibrationValuesComparisonPerRegion; using SiPixelGainCalibOfflineGainComparisonEndcapTwoTags = gainCalibHelper::SiPixelGainCalibrationValuesComparisonPerRegion; using SiPixelGainCalibOfflinePedestalComparisonEndcapTwoTags = gainCalibHelper::SiPixelGainCalibrationValuesComparisonPerRegion; diff --git a/CondCore/SiPixelPlugins/plugins/SiPixelLorentzAngle_PayloadInspector.cc b/CondCore/SiPixelPlugins/plugins/SiPixelLorentzAngle_PayloadInspector.cc index cab6fa6f2fe3c..6eef014179f0c 100644 --- a/CondCore/SiPixelPlugins/plugins/SiPixelLorentzAngle_PayloadInspector.cc +++ b/CondCore/SiPixelPlugins/plugins/SiPixelLorentzAngle_PayloadInspector.cc @@ -199,7 +199,7 @@ namespace { unsigned int maxPads = isBarrel ? 4 : 12; for (unsigned int c = 1; c <= maxPads; c++) { canvas.cd(c); - SiPixelPI::adjustCanvasMargins(canvas.cd(c), 0.07, 0.12, 0.12, 0.05); + SiPixelPI::adjustCanvasMargins(canvas.cd(c), 0.06, 0.12, 0.12, 0.05); legend.Draw("same"); canvas.cd(c)->Update(); } @@ -233,12 +233,12 @@ namespace { /************************************************ 1d histogram of SiPixelLorentzAngle of 2 IOV per region *************************************************/ - template + template class SiPixelLorentzAngleValuesComparisonPerRegion - : public cond::payloadInspector::PlotImage { + : public cond::payloadInspector::PlotImage { public: SiPixelLorentzAngleValuesComparisonPerRegion() - : cond::payloadInspector::PlotImage( + : cond::payloadInspector::PlotImage( Form("SiPixelLorentzAngle Values Comparisons per region %i tags(s)", ntags)) {} bool fill() override { @@ -287,16 +287,18 @@ namespace { canvas.Divide(isBarrel ? 2 : 4, isBarrel ? 2 : 3); canvas.cd(); + bool is_l_phase0 = (l_LAMap_.size() == SiPixelPI::phase0size); + bool is_f_phase0 = (f_LAMap_.size() == SiPixelPI::phase0size); + // deal with last IOV - const char *path_toTopologyXML = (l_LAMap_.size() == SiPixelPI::phase0size) - ? "Geometry/TrackerCommonData/data/trackerParameters.xml" - : "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml"; + const char *path_toTopologyXML = is_l_phase0 ? "Geometry/TrackerCommonData/data/trackerParameters.xml" + : "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml"; auto l_tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath(path_toTopologyXML).fullPath()); - auto l_myPlots = PixelRegions::PixelRegionContainers(&l_tTopo, (l_LAMap_.size() == SiPixelPI::phase1size)); + auto l_myPlots = PixelRegions::PixelRegionContainers(&l_tTopo, !is_l_phase0); l_myPlots.bookAll("SiPixel LA,last", "SiPixel LorentzAngle #mu_{H}(tan#theta_{L}/B) [1/T]", "#modules", @@ -304,25 +306,22 @@ namespace { min * 0.9, max * 1.1); - //canvas.Modified(); - for (const auto &element : l_LAMap_) { l_myPlots.fill(element.first, element.second); } l_myPlots.beautify(); - l_myPlots.draw(canvas, isBarrel, "bar2", true); + l_myPlots.draw(canvas, isBarrel, "bar2", (!is_f_phase0 || !is_l_phase0)); // deal with first IOV - path_toTopologyXML = (f_LAMap_.size() == SiPixelPI::phase0size) - ? "Geometry/TrackerCommonData/data/trackerParameters.xml" - : "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml"; + path_toTopologyXML = is_f_phase0 ? "Geometry/TrackerCommonData/data/trackerParameters.xml" + : "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml"; auto f_tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath(path_toTopologyXML).fullPath()); - auto f_myPlots = PixelRegions::PixelRegionContainers(&f_tTopo, (f_LAMap_.size() == SiPixelPI::phase1size)); + auto f_myPlots = PixelRegions::PixelRegionContainers(&f_tTopo, !is_f_phase0); f_myPlots.bookAll("SiPixel LA,first", "SiPixel LorentzAngle #mu_{H}(tan#theta_{L}/B) [1/T]", "#modules", @@ -330,14 +329,12 @@ namespace { min * 0.9, max * 1.1); - //canvas.Modified(); - for (const auto &element : f_LAMap_) { f_myPlots.fill(element.first, element.second); } f_myPlots.beautify(kAzure, kBlue); - f_myPlots.draw(canvas, isBarrel, "HISTsames", true); + f_myPlots.draw(canvas, isBarrel, "HISTsames", (!is_f_phase0 || !is_l_phase0)); // rescale the y-axis ranges in order to fit the canvas l_myPlots.rescaleMax(f_myPlots); @@ -396,11 +393,15 @@ namespace { } }; - using SiPixelLorentzAngleValuesBarrelCompareSingleTag = SiPixelLorentzAngleValuesComparisonPerRegion; - using SiPixelLorentzAngleValuesEndcapCompareSingleTag = SiPixelLorentzAngleValuesComparisonPerRegion; + using SiPixelLorentzAngleValuesBarrelCompareSingleTag = + SiPixelLorentzAngleValuesComparisonPerRegion; + using SiPixelLorentzAngleValuesEndcapCompareSingleTag = + SiPixelLorentzAngleValuesComparisonPerRegion; - using SiPixelLorentzAngleValuesBarrelCompareTwoTags = SiPixelLorentzAngleValuesComparisonPerRegion; - using SiPixelLorentzAngleValuesEndcapCompareTwoTags = SiPixelLorentzAngleValuesComparisonPerRegion; + using SiPixelLorentzAngleValuesBarrelCompareTwoTags = + SiPixelLorentzAngleValuesComparisonPerRegion; + using SiPixelLorentzAngleValuesEndcapCompareTwoTags = + SiPixelLorentzAngleValuesComparisonPerRegion; /************************************************ 1d histogram of SiPixelLorentzAngle of 1 IOV @@ -470,21 +471,11 @@ namespace { hfirst->SetBarWidth(0.95); hfirst->Draw("histbar"); - //hfirst->SetMarkerStyle(kFullCircle); - //hfirst->SetMarkerSize(1.5); - //hfirst->SetMarkerColor(kRed); - //hfirst->Draw("Psame"); - hlast->SetTitle(""); hlast->SetFillColorAlpha(kBlue, 0.20); hlast->SetBarWidth(0.95); hlast->Draw("histbarsame"); - //hlast->SetMarkerStyle(kOpenCircle); - //hlast->SetMarkerSize(1.5); - //hlast->SetMarkerColor(kBlue); - //hlast->Draw("Psame"); - SiPixelPI::makeNicePlotStyle(hfirst.get()); SiPixelPI::makeNicePlotStyle(hlast.get()); diff --git a/CondCore/SiPixelPlugins/plugins/SiPixelTemplateDBObject_PayloadInspector.cc b/CondCore/SiPixelPlugins/plugins/SiPixelTemplateDBObject_PayloadInspector.cc index 39167d56086ba..bdd7fbf27e1f8 100644 --- a/CondCore/SiPixelPlugins/plugins/SiPixelTemplateDBObject_PayloadInspector.cc +++ b/CondCore/SiPixelPlugins/plugins/SiPixelTemplateDBObject_PayloadInspector.cc @@ -227,7 +227,7 @@ namespace { "SiPixelTemplate assumed value of uH") {} bool fill() override { - gStyle->SetPalette(kBlackBody); + gStyle->SetPalette(kRainBow); TGaxis::SetMaxDigits(2); auto tag = PlotBase::getTag<0>(); @@ -268,10 +268,10 @@ namespace { Phase1PixelMaps theMaps("COLZ L"); if (myType == t_barrel) { - theMaps.bookBarrelHistograms("templateLABarrel", "#muH"); + theMaps.bookBarrelHistograms("templateLABarrel", "#muH", "#mu_{H} [1/T]"); theMaps.bookBarrelBins("templateLABarrel"); } else if (myType == t_forward) { - theMaps.bookForwardHistograms("templateLAForward", "#muH"); + theMaps.bookForwardHistograms("templateLAForward", "#muH", "#mu_{H} [1/T]"); theMaps.bookForwardBins("templateLAForward"); } @@ -344,11 +344,11 @@ namespace { // Book the TH2Poly Phase1PixelMaps theMaps("text"); if (myType == t_barrel) { - theMaps.bookBarrelHistograms("templateIDsBarrel", "IDs"); + theMaps.bookBarrelHistograms("templateIDsBarrel", "IDs", "template IDs"); // book the barrel bins of the TH2Poly theMaps.bookBarrelBins("templateIDsBarrel"); } else if (myType == t_forward) { - theMaps.bookForwardHistograms("templateIDsForward", "IDs"); + theMaps.bookForwardHistograms("templateIDsForward", "IDs", "template IDs"); // book the forward bins of the TH2Poly theMaps.bookForwardBins("templateIDsForward"); } diff --git a/CondCore/SiPixelPlugins/test/testSiPixelPayloadInspector.cpp b/CondCore/SiPixelPlugins/test/testSiPixelPayloadInspector.cpp index 241e50c2556c7..22a6a63d1bc31 100644 --- a/CondCore/SiPixelPlugins/test/testSiPixelPayloadInspector.cpp +++ b/CondCore/SiPixelPlugins/test/testSiPixelPayloadInspector.cpp @@ -5,6 +5,7 @@ #include "CondCore/SiPixelPlugins/plugins/SiPixelQuality_PayloadInspector.cc" #include "CondCore/SiPixelPlugins/plugins/SiPixelGainCalibrationOffline_PayloadInspector.cc" #include "CondCore/SiPixelPlugins/plugins/SiPixelTemplateDBObject_PayloadInspector.cc" +#include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/PluginManager/interface/PluginManager.h" #include "FWCore/PluginManager/interface/standard.h" #include "FWCore/PluginManager/interface/SharedLibrary.h" @@ -31,27 +32,27 @@ int main(int argc, char** argv) { cond::Time_t start = boost::lexical_cast(303790); cond::Time_t end = boost::lexical_cast(324245); - std::cout << "## Exercising Lorentz Angle plots " << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << "## Exercising Lorentz Angle plots " << std::endl; SiPixelLorentzAngleValues histo1; histo1.process(connectionString, PI::mk_input(tag, start, start)); - std::cout << histo1.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo1.data() << std::endl; SiPixelLorentzAngleValueComparisonSingleTag histo2; histo2.process(connectionString, PI::mk_input(tag, start, end)); - std::cout << histo2.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo2.data() << std::endl; SiPixelLorentzAngleByRegionComparisonSingleTag histo3; histo3.process(connectionString, PI::mk_input(tag, start, end)); - std::cout << histo3.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo3.data() << std::endl; SiPixelBPixLorentzAngleMap histo4; histo4.process(connectionString, PI::mk_input(tag, start, start)); - std::cout << histo4.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo4.data() << std::endl; SiPixelFPixLorentzAngleMap histo5; histo5.process(connectionString, PI::mk_input(tag, end, end)); - std::cout << histo5.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo5.data() << std::endl; // 2 tags comparisons @@ -60,11 +61,11 @@ int main(int argc, char** argv) { SiPixelLorentzAngleValueComparisonTwoTags histo6; histo6.process(connectionString, PI::mk_input(tag, start, start, tag2, start2, start2)); - std::cout << histo6.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo6.data() << std::endl; SiPixelLorentzAngleByRegionComparisonTwoTags histo7; histo7.process(connectionString, PI::mk_input(tag, start, start, tag2, start2, start2)); - std::cout << histo7.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo7.data() << std::endl; // SiPixelQuality @@ -72,15 +73,15 @@ int main(int argc, char** argv) { start = boost::lexical_cast(1); end = boost::lexical_cast(1); - std::cout << "## Exercising SiPixelQuality plots " << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << "## Exercising SiPixelQuality plots " << std::endl; SiPixelBPixQualityMap histo8; histo8.process(connectionString, PI::mk_input(tag, start, start)); - std::cout << histo8.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo8.data() << std::endl; SiPixelFPixQualityMap histo9; histo9.process(connectionString, PI::mk_input(tag, start, start)); - std::cout << histo9.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo9.data() << std::endl; // SiPixelGainCalibrationOffline @@ -88,37 +89,37 @@ int main(int argc, char** argv) { start = boost::lexical_cast(312203); end = boost::lexical_cast(312203); - std::cout << "## Exercising SiPixelGainCalibrationOffline plots " << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << "## Exercising SiPixelGainCalibrationOffline plots " << std::endl; SiPixelGainCalibrationOfflineGainsValues histo10; histo10.process(connectionString, PI::mk_input(tag, start, start)); - std::cout << histo10.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo10.data() << std::endl; SiPixelGainCalibrationOfflinePedestalsValues histo11; histo11.process(connectionString, PI::mk_input(tag, start, start)); - std::cout << histo11.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo11.data() << std::endl; SiPixelGainCalibrationOfflineGainsByPart histo12; histo12.process(connectionString, PI::mk_input(tag, start, start)); - std::cout << histo12.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo12.data() << std::endl; SiPixelGainCalibrationOfflinePedestalsByPart histo13; histo13.process(connectionString, PI::mk_input(tag, start, start)); - std::cout << histo13.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo13.data() << std::endl; end = boost::lexical_cast(326851); SiPixelGainCalibOfflinePedestalComparisonSingleTag histo14; histo14.process(connectionString, PI::mk_input(tag, start, end)); - std::cout << histo14.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo14.data() << std::endl; SiPixelGainCalibOfflineGainByRegionComparisonSingleTag histo15; histo15.process(connectionString, PI::mk_input(tag, start, end)); - std::cout << histo15.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo15.data() << std::endl; SiPixelGainCalibrationOfflineCorrelations histo16; histo16.process(connectionString, PI::mk_input(tag, end, end)); - std::cout << histo16.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo16.data() << std::endl; boost::python::dict inputs; inputs["SetLog"] = "True"; // sets to true, 1,True,Yes will work @@ -126,7 +127,7 @@ int main(int argc, char** argv) { SiPixelGainCalibrationOfflineGainsValuesBarrel histo17; histo17.setInputParamValues(inputs); histo17.process(connectionString, PI::mk_input(tag, end, end)); - std::cout << histo17.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo17.data() << std::endl; // SiPixelTemplates @@ -134,15 +135,15 @@ int main(int argc, char** argv) { start = boost::lexical_cast(326083); end = boost::lexical_cast(326083); - std::cout << "## Exercising SiPixelTemplates plots " << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << "## Exercising SiPixelTemplates plots " << std::endl; SiPixelTemplateIDsBPixMap histo18; histo18.process(connectionString, PI::mk_input(tag, end, end)); - std::cout << histo18.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo18.data() << std::endl; SiPixelTemplateLAFPixMap histo19; histo19.process(connectionString, PI::mk_input(tag, end, end)); - std::cout << histo19.data() << std::endl; + edm::LogPrint("testSiPixelPayloadInspector") << histo19.data() << std::endl; Py_Finalize(); } diff --git a/Configuration/StandardSequences/python/AlCaRecoStreams_cff.py b/Configuration/StandardSequences/python/AlCaRecoStreams_cff.py index 89fbabf913622..b9048810c9a5a 100644 --- a/Configuration/StandardSequences/python/AlCaRecoStreams_cff.py +++ b/Configuration/StandardSequences/python/AlCaRecoStreams_cff.py @@ -231,6 +231,7 @@ pathALCARECOTkAlCosmicsCTF0T = cms.Path(seqALCARECOTkAlCosmicsCTF0T*ALCARECOTkAlCosmicsCTF0TDQM) pathALCARECOTkAlCosmicsCosmicTF0T = cms.Path(seqALCARECOTkAlCosmicsCosmicTF0T*ALCARECOTkAlCosmicsCosmicTF0TDQM) pathALCARECOTkAlCosmicsRegional0T = cms.Path(seqALCARECOTkAlCosmicsRegional0T*ALCARECOTkAlCosmicsRegional0TDQM) +pathALCARECOTkAlCosmicsDuringCollisions0T = cms.Path(seqALCARECOTkAlCosmicsDuringCollisions0T*ALCARECOTkAlCosmicsInCollisions0TDQM) pathALCARECOTkAlCosmicsCTFHLT = cms.Path(seqALCARECOTkAlCosmicsCTFHLT*ALCARECOTkAlCosmicsCTFDQM) pathALCARECOTkAlCosmicsCosmicTFHLT = cms.Path(seqALCARECOTkAlCosmicsCosmicTFHLT*ALCARECOTkAlCosmicsCosmicTFDQM) pathALCARECOTkAlCosmicsRegionalHLT = cms.Path(seqALCARECOTkAlCosmicsRegionalHLT*ALCARECOTkAlCosmicsRegionalDQM) @@ -728,7 +729,7 @@ ALCARECOStreamTkAlCosmics0T = cms.FilteredStream( responsible = 'Andreas Mussgiller', name = 'TkAlCosmics0T', - paths = (pathALCARECOTkAlCosmicsCTF0T,pathALCARECOTkAlCosmicsCosmicTF0T,pathALCARECOTkAlCosmicsRegional0T), + paths = (pathALCARECOTkAlCosmicsCTF0T,pathALCARECOTkAlCosmicsCosmicTF0T,pathALCARECOTkAlCosmicsRegional0T,pathALCARECOTkAlCosmicsDuringCollisions0T), content = OutALCARECOTkAlCosmics0T.outputCommands, selectEvents = OutALCARECOTkAlCosmics0T.SelectEvents, dataTier = cms.untracked.string('ALCARECO') diff --git a/DQMOffline/Alignment/python/ALCARECOTkAlDQM_cff.py b/DQMOffline/Alignment/python/ALCARECOTkAlDQM_cff.py index fe49f2b1afb02..e7a1360fa1e42 100644 --- a/DQMOffline/Alignment/python/ALCARECOTkAlDQM_cff.py +++ b/DQMOffline/Alignment/python/ALCARECOTkAlDQM_cff.py @@ -675,6 +675,31 @@ #ALCARECOTkAlCosmicsRegional0TDQM = cms.Sequence( ALCARECOTkAlCosmicsRegional0TTrackingDQM + ALCARECOTkAlCosmicsRegional0TTkAlDQM +ALCARECOTkAlCosmicsRegional0THLTDQM) ALCARECOTkAlCosmicsRegional0TDQM = cms.Sequence( ALCARECOTkAlCosmicsRegional0TTrackingDQM + ALCARECOTkAlCosmicsRegional0TTkAlDQM ) +############################# +### TkAlCosmicsInCollisions0T ### +############################# +__selectionName = 'TkAlCosmicsInCollisions0T' +ALCARECOTkAlCosmicsInCollisions0TTrackingDQM = ALCARECOTkAlCosmicsCTF0TTrackingDQM.clone( +#names and desigantions + TrackProducer = 'ALCARECO'+__selectionName, + AlgoName = 'ALCARECO'+__selectionName, + BSFolderName = "AlCaReco/"+__selectionName+"/BeamSpot", +) +ALCARECOTkAlCosmicsInCollisions0TTkAlDQM = ALCARECOTkAlCosmicsCTF0TTkAlDQM.clone( +#names and desigantions + TrackProducer = 'ALCARECO'+__selectionName, + ReferenceTrackProducer = 'cosmictrackfinderP5', + AlgoName = 'ALCARECO'+__selectionName +) +from Alignment.CommonAlignmentProducer.ALCARECOTkAlCosmics0THLT_cff import ALCARECOTkAlCosmics0THLT +#ALCARECOTkAlCosmicsInCollisions0THLTDQM = hltMonBitSummary.clone( +# directory = "AlCaReco/"+__selectionName+"/HLTSummary", +# histLabel = __selectionName, +# HLTPaths = ["HLT_.*L1.*"], +# eventSetupPathsKey = ALCARECOTkAlCosmics0THLT.eventSetupPathsKey.value() +#) +#ALCARECOTkAlCosmicsInCollisions0TDQM = cms.Sequence( ALCARECOTkAlCosmicsInCollisions0TTrackingDQM + ALCARECOTkAlCosmicsInCollisions0TTkAlDQM +ALCARECOTkAlCosmicsInCollisions0THLTDQM) +ALCARECOTkAlCosmicsInCollisions0TDQM = cms.Sequence( ALCARECOTkAlCosmicsInCollisions0TTrackingDQM + ALCARECOTkAlCosmicsInCollisions0TTkAlDQM ) ########################################################################## ###### DQM modules for cosmic data taking with momentum measurement ###### diff --git a/DetectorDescription/Parser/test/run_testDoc.sh b/DetectorDescription/Parser/test/run_testDoc.sh index 09c6adccff1f1..42ffa53d74860 100755 --- a/DetectorDescription/Parser/test/run_testDoc.sh +++ b/DetectorDescription/Parser/test/run_testDoc.sh @@ -1,13 +1,19 @@ #!/bin/bash + test=testtestDoc function die { echo Failure $1: status $2 ; exit $2 ; } pushd ${LOCAL_TMP_DIR} - export mecpath=${PATH} export PATH=${LOCAL_TOP_DIR}/test/${SCRAM_ARCH}/:${PATH} cd ${LOCAL_TEST_DIR} -# cp ${LOCAL_TOP_DIR}/test/${SCRAM_ARCH}/testDoc . - echo ${test}testDoc ------------------------------------------------------------ - testDoc testConfiguration.xml|| die "testDoc" $? - export PATH=${mecpath} + echo ${test} testDoc ------------------------------------------------------------ + testDocProg=testDoc + for scriptDir in $CMSSW_BASE $CMSSW_RELEASE_BASE $CMSSW_FULL_RELEASE_BASE ; do + if [ -x $scriptDir/test/${SCRAM_ARCH}/testDoc ] ; then + testDocProg=$scriptDir/test/${SCRAM_ARCH}/testDoc + echo Found $testDocProg + break + fi + done + $testDocProg testConfiguration.xml || die "testDoc" $? popd exit 0 diff --git a/EventFilter/Utilities/src/EvFOutputModule.cc b/EventFilter/Utilities/src/EvFOutputModule.cc index e7be8123f4686..25e103bbbf0d2 100644 --- a/EventFilter/Utilities/src/EvFOutputModule.cc +++ b/EventFilter/Utilities/src/EvFOutputModule.cc @@ -140,7 +140,7 @@ namespace evf { edm::ParameterSetDescription desc; edm::StreamerOutputModuleCommon::fillDescription(desc); EvFOutputModuleType::fillDescription(desc); - desc.addUntracked("psetMap", {"psetMap"}) + desc.addUntracked("psetMap", {"hltPSetMap"}) ->setComment("Optionally allow the map of ParameterSets to be calculated externally."); descriptions.addDefault(desc); } diff --git a/Geometry/CMSCommonData/data/beampipe/2021/v1/beampipe.xml b/Geometry/CMSCommonData/data/beampipe/2021/v1/beampipe.xml index 2cb249237a617..27517206a0658 100644 --- a/Geometry/CMSCommonData/data/beampipe/2021/v1/beampipe.xml +++ b/Geometry/CMSCommonData/data/beampipe/2021/v1/beampipe.xml @@ -31,7 +31,7 @@ - + diff --git a/Geometry/CMSCommonData/data/cms/2021/v3/cms.xml b/Geometry/CMSCommonData/data/cms/2021/v3/cms.xml index e646067a3e262..1279899cbc593 100644 --- a/Geometry/CMSCommonData/data/cms/2021/v3/cms.xml +++ b/Geometry/CMSCommonData/data/cms/2021/v3/cms.xml @@ -87,7 +87,7 @@ - + diff --git a/HLTrigger/Configuration/python/HLT_2018_cff.py b/HLTrigger/Configuration/python/HLT_2018_cff.py index 1d28d1dcc7a7a..9cc0b997b9641 100644 --- a/HLTrigger/Configuration/python/HLT_2018_cff.py +++ b/HLTrigger/Configuration/python/HLT_2018_cff.py @@ -1,13 +1,13 @@ # hltGetConfiguration --cff --data /frozen/2018/111X/HLT --type 2018 -# /frozen/2018/111X/HLT/V11 (CMSSW_11_1_0_pre7) +# /frozen/2018/111X/HLT/V13 (CMSSW_11_1_0_pre8_HLT1) import FWCore.ParameterSet.Config as cms fragment = cms.ProcessFragment( "HLT" ) fragment.HLTConfigVersion = cms.PSet( - tableName = cms.string('/frozen/2018/111X/HLT/V11') + tableName = cms.string('/frozen/2018/111X/HLT/V13') ) fragment.transferSystem = cms.PSet( @@ -6280,11 +6280,12 @@ ClusterProbComputationFlag = cms.int32( 0 ), Alpha2Order = cms.bool( True ), appendToDataLabel = cms.string( "" ), - EdgeClusterErrorY = cms.double( 85.0 ), + lAWidthFPix = cms.double( 0.0 ), SmallPitch = cms.bool( False ), LoadTemplatesFromDB = cms.bool( True ), + NoTemplateErrorsWhenNoTrkAngles = cms.bool( False ), EdgeClusterErrorX = cms.double( 50.0 ), - lAWidthFPix = cms.double( 0.0 ), + EdgeClusterErrorY = cms.double( 85.0 ), lAOffset = cms.double( 0.0 ), ComponentName = cms.string( "hltESPPixelCPEGeneric" ), MagneticFieldRecord = cms.ESInputTag( "" ), @@ -6739,6 +6740,7 @@ fragment.hltGetRaw = cms.EDAnalyzer( "HLTGetRaw", RawDataCollection = cms.InputTag( "rawDataCollector" ) ) +fragment.hltPSetMap = cms.EDProducer( "ParameterSetBlobProducer" ) fragment.hltBoolFalse = cms.EDFilter( "HLTBool", result = cms.bool( False ) ) @@ -33340,6 +33342,7 @@ minMeff = cms.vdouble( 0.0 ) ) fragment.hltVerticesPF = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -33369,6 +33372,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltPFMuonMerging" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -48708,10 +48712,13 @@ minMht = cms.vdouble( 100.0 ) ) fragment.hltPFMETProducer = cms.EDProducer( "PFMETProducer", - globalThreshold = cms.double( 0.0 ), + src = cms.InputTag( "hltParticleFlow" ), + parameters = cms.PSet( ), + applyWeight = cms.bool( False ), calculateSignificance = cms.bool( False ), alias = cms.string( "hltPFMet" ), - src = cms.InputTag( "hltParticleFlow" ) + srcWeights = cms.InputTag( "" ), + globalThreshold = cms.double( 0.0 ) ) fragment.hltPFMET100 = cms.EDFilter( "HLT1PFMET", saveTags = cms.bool( True ), @@ -50313,6 +50320,7 @@ newQuality = cms.string( "confirmed" ) ) fragment.hltVerticesL3 = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -50342,6 +50350,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltMergedTracksForBTag" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -50662,10 +50671,13 @@ cut = cms.string( "particleId!=3" ) ) fragment.hltPFMETNoMuProducer = cms.EDProducer( "PFMETProducer", - globalThreshold = cms.double( 0.0 ), + src = cms.InputTag( "hltParticleFlowNoMu" ), + parameters = cms.PSet( ), + applyWeight = cms.bool( False ), calculateSignificance = cms.bool( False ), alias = cms.string( "pfMetNoMu" ), - src = cms.InputTag( "hltParticleFlowNoMu" ) + srcWeights = cms.InputTag( "" ), + globalThreshold = cms.double( 0.0 ) ) fragment.hltPFMETNoMu120 = cms.EDFilter( "HLT1PFMET", saveTags = cms.bool( True ), @@ -66693,10 +66705,13 @@ MaxMass = cms.double( -1.0 ) ) fragment.hltPFMETVBFProducer = cms.EDProducer( "PFMETProducer", - globalThreshold = cms.double( 0.0 ), + src = cms.InputTag( "hltParticleFlowNoMu" ), + parameters = cms.PSet( ), + applyWeight = cms.bool( False ), calculateSignificance = cms.bool( False ), alias = cms.string( "pfMet" ), - src = cms.InputTag( "hltParticleFlowNoMu" ) + srcWeights = cms.InputTag( "" ), + globalThreshold = cms.double( 0.0 ) ) fragment.hltPFMETVBF110 = cms.EDFilter( "HLT1PFMET", saveTags = cms.bool( True ), @@ -89010,7 +89025,7 @@ fragment.HLTBeginSequenceParking = cms.Sequence( fragment.hltTriggerType + fragment.hltEnableParking + fragment.HLTL1UnpackerSequence + fragment.HLTBeamSpot ) fragment.HLTPFScoutingPackingSequence = cms.Sequence( fragment.hltScoutingPFPacker + fragment.hltScoutingMuonPacker + fragment.hltScoutingEgammaPacker ) -fragment.HLTriggerFirstPath = cms.Path( fragment.hltGetConditions + fragment.hltGetRaw + fragment.hltBoolFalse ) +fragment.HLTriggerFirstPath = cms.Path( fragment.hltGetConditions + fragment.hltGetRaw + fragment.hltPSetMap + fragment.hltBoolFalse ) fragment.HLT_AK8PFJet360_TrimMass30_v18 = cms.Path( fragment.HLTBeginSequence + fragment.hltL1sSingleJet180 + fragment.hltPreAK8PFJet360TrimMass30 + fragment.HLTAK8CaloJetsSequence + fragment.hltAK8SingleCaloJet260 + fragment.HLTAK8PFJetsSequence + fragment.hltAK8PFJetsCorrectedMatchedToCaloJets260 + fragment.hltAK8SinglePFJet360 + fragment.hltAK8TrimModJets + fragment.hltAK8SinglePFJetTrimModMass30 + fragment.HLTEndSequence ) fragment.HLT_AK8PFJet380_TrimMass30_v11 = cms.Path( fragment.HLTBeginSequence + fragment.hltL1sSingleJet180 + fragment.hltPreAK8PFJet380TrimMass30 + fragment.HLTAK8CaloJetsSequence + fragment.hltAK8SingleCaloJet280 + fragment.HLTAK8PFJetsSequence + fragment.hltAK8PFJetsCorrectedMatchedToCaloJets280 + fragment.hltAK8SinglePFJet380 + fragment.hltAK8TrimModJets + fragment.hltAK8SinglePFJetTrimModMass30 + fragment.HLTEndSequence ) fragment.HLT_AK8PFJet400_TrimMass30_v12 = cms.Path( fragment.HLTBeginSequence + fragment.hltL1sSingleJet180 + fragment.hltPreAK8PFJet400TrimMass30 + fragment.HLTAK8CaloJetsSequence + fragment.hltAK8SingleCaloJet300 + fragment.HLTAK8PFJetsSequence + fragment.hltAK8PFJetsCorrectedMatchedToCaloJets300 + fragment.hltAK8SinglePFJet400 + fragment.hltAK8TrimModJets + fragment.hltAK8SinglePFJetTrimModMass30 + fragment.HLTEndSequence ) diff --git a/HLTrigger/Configuration/python/HLT_FULL_cff.py b/HLTrigger/Configuration/python/HLT_FULL_cff.py index 17b9538eb2956..81a348baa8850 100644 --- a/HLTrigger/Configuration/python/HLT_FULL_cff.py +++ b/HLTrigger/Configuration/python/HLT_FULL_cff.py @@ -1,13 +1,13 @@ # hltGetConfiguration --cff --data /dev/CMSSW_11_1_0/HLT --type FULL -# /dev/CMSSW_11_1_0/HLT/V17 (CMSSW_11_1_0_pre7) +# /dev/CMSSW_11_1_0/HLT/V20 (CMSSW_11_1_0_pre8_HLT1) import FWCore.ParameterSet.Config as cms fragment = cms.ProcessFragment( "HLT" ) fragment.HLTConfigVersion = cms.PSet( - tableName = cms.string('/dev/CMSSW_11_1_0/HLT/V17') + tableName = cms.string('/dev/CMSSW_11_1_0/HLT/V20') ) fragment.transferSystem = cms.PSet( @@ -7585,11 +7585,12 @@ ClusterProbComputationFlag = cms.int32( 0 ), Alpha2Order = cms.bool( True ), appendToDataLabel = cms.string( "" ), - EdgeClusterErrorY = cms.double( 85.0 ), + lAWidthFPix = cms.double( 0.0 ), SmallPitch = cms.bool( False ), LoadTemplatesFromDB = cms.bool( True ), + NoTemplateErrorsWhenNoTrkAngles = cms.bool( False ), EdgeClusterErrorX = cms.double( 50.0 ), - lAWidthFPix = cms.double( 0.0 ), + EdgeClusterErrorY = cms.double( 85.0 ), lAOffset = cms.double( 0.0 ), ComponentName = cms.string( "hltESPPixelCPEGeneric" ), MagneticFieldRecord = cms.ESInputTag( "" ), @@ -8044,6 +8045,7 @@ fragment.hltGetRaw = cms.EDAnalyzer( "HLTGetRaw", RawDataCollection = cms.InputTag( "rawDataCollector" ) ) +fragment.hltPSetMap = cms.EDProducer( "ParameterSetBlobProducer" ) fragment.hltBoolFalse = cms.EDFilter( "HLTBool", result = cms.bool( False ) ) @@ -9424,16 +9426,16 @@ maxNumberOfClusters = cms.int32( 40000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) fragment.hltSiPixelClustersCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -34569,6 +34571,7 @@ minMeff = cms.vdouble( 0.0 ) ) fragment.hltVerticesPF = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -34598,6 +34601,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltPFMuonMerging" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -36267,16 +36271,16 @@ maxNumberOfClusters = cms.int32( 20000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) fragment.hltSiPixelClustersRegL1TauSeededCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -41960,16 +41964,16 @@ maxNumberOfClusters = cms.int32( 20000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) fragment.hltSiPixelClustersRegForTauCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -50010,10 +50014,13 @@ minMht = cms.vdouble( 100.0 ) ) fragment.hltPFMETProducer = cms.EDProducer( "PFMETProducer", - globalThreshold = cms.double( 0.0 ), + src = cms.InputTag( "hltParticleFlow" ), + parameters = cms.PSet( ), + applyWeight = cms.bool( False ), calculateSignificance = cms.bool( False ), alias = cms.string( "hltPFMet" ), - src = cms.InputTag( "hltParticleFlow" ) + srcWeights = cms.InputTag( "" ), + globalThreshold = cms.double( 0.0 ) ) fragment.hltPFMET100 = cms.EDFilter( "HLT1PFMET", saveTags = cms.bool( True ), @@ -50395,16 +50402,16 @@ maxNumberOfClusters = cms.int32( 40000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) fragment.hltSiPixelClustersRegForBTagCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -51543,6 +51550,7 @@ newQuality = cms.string( "confirmed" ) ) fragment.hltVerticesL3 = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -51572,6 +51580,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltMergedTracksForBTag" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -51892,10 +51901,13 @@ cut = cms.string( "particleId!=3" ) ) fragment.hltPFMETNoMuProducer = cms.EDProducer( "PFMETProducer", - globalThreshold = cms.double( 0.0 ), + src = cms.InputTag( "hltParticleFlowNoMu" ), + parameters = cms.PSet( ), + applyWeight = cms.bool( False ), calculateSignificance = cms.bool( False ), alias = cms.string( "pfMetNoMu" ), - src = cms.InputTag( "hltParticleFlowNoMu" ) + srcWeights = cms.InputTag( "" ), + globalThreshold = cms.double( 0.0 ) ) fragment.hltPFMETNoMu120 = cms.EDFilter( "HLT1PFMET", saveTags = cms.bool( True ), @@ -68293,10 +68305,13 @@ MaxMass = cms.double( -1.0 ) ) fragment.hltPFMETVBFProducer = cms.EDProducer( "PFMETProducer", - globalThreshold = cms.double( 0.0 ), + src = cms.InputTag( "hltParticleFlowNoMu" ), + parameters = cms.PSet( ), + applyWeight = cms.bool( False ), calculateSignificance = cms.bool( False ), alias = cms.string( "pfMet" ), - src = cms.InputTag( "hltParticleFlowNoMu" ) + srcWeights = cms.InputTag( "" ), + globalThreshold = cms.double( 0.0 ) ) fragment.hltPFMETVBF110 = cms.EDFilter( "HLT1PFMET", saveTags = cms.bool( True ), @@ -82280,16 +82295,16 @@ maxNumberOfClusters = cms.int32( 40000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) fragment.hltSiPixelClustersCacheAfterSplitting = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -82481,6 +82496,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) fragment.hltPAIter0PrimaryVertices = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -82503,6 +82519,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltPAIter0CtfWithMaterialTracks" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -85022,6 +85039,7 @@ etMin = cms.double( 60.0 ) ) fragment.hltVerticesL3PFBjets = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -85051,6 +85069,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltPFMuonMerging" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -96513,16 +96532,16 @@ maxNumberOfClusters = cms.int32( 40000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) fragment.hltSiPixelClustersCacheForHighBeta = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -97955,16 +97974,16 @@ maxNumberOfClusters = cms.int32( -1 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "Offline" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) fragment.hltSiPixelClustersCachePPOnAA = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -100304,6 +100323,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) fragment.hltFullIter0PrimaryVerticesPreSplittingPPOnAA = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -100326,6 +100346,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPreSplittingPPOnAA" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -100636,6 +100657,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) fragment.hltFullIter0PrimaryVerticesPPOnAA = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -100658,6 +100680,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPPOnAA" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -102150,6 +102173,7 @@ correctors = cms.VInputTag( 'hltCsAK4PFCorrectorPPOnAA' ) ) fragment.hltVerticesPFPPOnAA = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -102179,6 +102203,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltPFMuonMergingPPOnAA" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -107394,6 +107419,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) fragment.hltFullIter0PrimaryVerticesPreSplittingPPOnAAForDmeson = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -107416,6 +107442,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPreSplittingPPOnAAForDmeson" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -107600,6 +107627,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) fragment.hltFullIter0PrimaryVerticesPPOnAAForDmeson = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -107622,6 +107650,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPPOnAAForDmeson" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -109843,6 +109872,7 @@ trackAlgoPriorityOrder = cms.string( "hltESPTrackAlgoPriorityOrder" ) ) fragment.hltFullOnlinePrimaryVerticesPPOnAAForDmeson = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -109872,6 +109902,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIterativeTrackingMergedPPOnAAForDmeson" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -110182,6 +110213,7 @@ trackAlgoPriorityOrder = cms.string( "hltESPTrackAlgoPriorityOrder" ) ) fragment.hltFullOnlinePrimaryVerticesPPOnAAForDmesonNoIter10 = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -110211,6 +110243,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIterativeTrackingMergedPPOnAAForDmesonNoIter10" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -113310,16 +113343,16 @@ maxNumberOfClusters = cms.int32( -1 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) fragment.hltHISiPixelClustersCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -113620,16 +113653,16 @@ maxNumberOfClusters = cms.int32( -1 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "Offline" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) fragment.hltSiPixelClustersCachePPOnAAForLowPt = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -113795,6 +113828,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) fragment.hltFullIter0PrimaryVerticesPreSplittingPPOnAAForLowPt = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -113817,6 +113851,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPreSplittingPPOnAAForLowPt" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -113999,6 +114034,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) fragment.hltFullIter0PrimaryVerticesPPOnAAForLowPt = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -114021,6 +114057,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPPOnAAForLowPt" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -116097,6 +116134,7 @@ trackAlgoPriorityOrder = cms.string( "hltESPTrackAlgoPriorityOrder" ) ) fragment.hltFullOnlinePrimaryVerticesPPOnAAForLowPt = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -116126,6 +116164,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIterativeTrackingMergedPPOnAAForLowPt" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -118989,6 +119028,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) fragment.hltFullIter0PrimaryVerticesPPOnAAForBTag = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -119011,6 +119051,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPPOnAAForBTag" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -119995,6 +120036,7 @@ trackAlgoPriorityOrder = cms.string( "hltESPTrackAlgoPriorityOrder" ) ) fragment.hltFullOnlinePrimaryVerticesPPOnAAForBTag = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -120024,6 +120066,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIterativeTrackingMergedPPOnAAForBTag" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -121958,7 +122001,7 @@ fragment.HLTHISinglePixelTrackNpix = cms.Sequence( fragment.HLTHIDoLocalPixelSequence + ~fragment.hltHIPixelCountFilterNpix + fragment.HLTHIRecoPixelTracksSequenceForTrackTrigger + fragment.hltHIPixelCandsForTrackTrigger + fragment.hltHIPixelFilter1 ) fragment.HLTPFScoutingPackingSequence = cms.Sequence( fragment.hltScoutingPFPacker + fragment.hltScoutingMuonPacker + fragment.hltScoutingEgammaPacker ) -fragment.HLTriggerFirstPath = cms.Path( fragment.hltGetConditions + fragment.hltGetRaw + fragment.hltBoolFalse ) +fragment.HLTriggerFirstPath = cms.Path( fragment.hltGetConditions + fragment.hltGetRaw + fragment.hltPSetMap + fragment.hltBoolFalse ) fragment.HLT_AK8PFJet360_TrimMass30_v18 = cms.Path( fragment.HLTBeginSequence + fragment.hltL1sSingleJet180 + fragment.hltPreAK8PFJet360TrimMass30 + fragment.HLTAK8CaloJetsSequence + fragment.hltAK8SingleCaloJet260 + fragment.HLTAK8PFJetsSequence + fragment.hltAK8PFJetsCorrectedMatchedToCaloJets260 + fragment.hltAK8SinglePFJet360 + fragment.hltAK8TrimModJets + fragment.hltAK8SinglePFJetTrimModMass30 + fragment.HLTEndSequence ) fragment.HLT_AK8PFJet380_TrimMass30_v11 = cms.Path( fragment.HLTBeginSequence + fragment.hltL1sSingleJet180 + fragment.hltPreAK8PFJet380TrimMass30 + fragment.HLTAK8CaloJetsSequence + fragment.hltAK8SingleCaloJet280 + fragment.HLTAK8PFJetsSequence + fragment.hltAK8PFJetsCorrectedMatchedToCaloJets280 + fragment.hltAK8SinglePFJet380 + fragment.hltAK8TrimModJets + fragment.hltAK8SinglePFJetTrimModMass30 + fragment.HLTEndSequence ) fragment.HLT_AK8PFJet400_TrimMass30_v12 = cms.Path( fragment.HLTBeginSequence + fragment.hltL1sSingleJet180 + fragment.hltPreAK8PFJet400TrimMass30 + fragment.HLTAK8CaloJetsSequence + fragment.hltAK8SingleCaloJet300 + fragment.HLTAK8PFJetsSequence + fragment.hltAK8PFJetsCorrectedMatchedToCaloJets300 + fragment.hltAK8SinglePFJet400 + fragment.hltAK8TrimModJets + fragment.hltAK8SinglePFJetTrimModMass30 + fragment.HLTEndSequence ) diff --git a/HLTrigger/Configuration/python/HLT_Fake1_cff.py b/HLTrigger/Configuration/python/HLT_Fake1_cff.py index 02e47840bd1b3..ace0bd8b198d5 100644 --- a/HLTrigger/Configuration/python/HLT_Fake1_cff.py +++ b/HLTrigger/Configuration/python/HLT_Fake1_cff.py @@ -1,13 +1,13 @@ # hltGetConfiguration --cff --data /dev/CMSSW_11_1_0/Fake1 --type Fake1 -# /dev/CMSSW_11_1_0/Fake1/V6 (CMSSW_11_1_0_pre7) +# /dev/CMSSW_11_1_0/Fake1/V7 (CMSSW_11_1_0_pre8_HLT1) import FWCore.ParameterSet.Config as cms fragment = cms.ProcessFragment( "HLT" ) fragment.HLTConfigVersion = cms.PSet( - tableName = cms.string('/dev/CMSSW_11_1_0/Fake1/V6') + tableName = cms.string('/dev/CMSSW_11_1_0/Fake1/V7') ) fragment.streams = cms.PSet( A = cms.vstring( 'InitialPD' ) ) diff --git a/HLTrigger/Configuration/python/HLT_Fake2_cff.py b/HLTrigger/Configuration/python/HLT_Fake2_cff.py index 9e4e53f867e04..9fe8c4e105ee3 100644 --- a/HLTrigger/Configuration/python/HLT_Fake2_cff.py +++ b/HLTrigger/Configuration/python/HLT_Fake2_cff.py @@ -1,13 +1,13 @@ # hltGetConfiguration --cff --data /dev/CMSSW_11_1_0/Fake2 --type Fake2 -# /dev/CMSSW_11_1_0/Fake2/V6 (CMSSW_11_1_0_pre7) +# /dev/CMSSW_11_1_0/Fake2/V7 (CMSSW_11_1_0_pre8_HLT1) import FWCore.ParameterSet.Config as cms fragment = cms.ProcessFragment( "HLT" ) fragment.HLTConfigVersion = cms.PSet( - tableName = cms.string('/dev/CMSSW_11_1_0/Fake2/V6') + tableName = cms.string('/dev/CMSSW_11_1_0/Fake2/V7') ) fragment.streams = cms.PSet( A = cms.vstring( 'InitialPD' ) ) diff --git a/HLTrigger/Configuration/python/HLT_Fake_cff.py b/HLTrigger/Configuration/python/HLT_Fake_cff.py index 6c96f1cfb8e1c..7c600e9d21ce4 100644 --- a/HLTrigger/Configuration/python/HLT_Fake_cff.py +++ b/HLTrigger/Configuration/python/HLT_Fake_cff.py @@ -1,13 +1,13 @@ # hltGetConfiguration --cff --data /dev/CMSSW_11_1_0/Fake --type Fake -# /dev/CMSSW_11_1_0/Fake/V6 (CMSSW_11_1_0_pre7) +# /dev/CMSSW_11_1_0/Fake/V7 (CMSSW_11_1_0_pre8_HLT1) import FWCore.ParameterSet.Config as cms fragment = cms.ProcessFragment( "HLT" ) fragment.HLTConfigVersion = cms.PSet( - tableName = cms.string('/dev/CMSSW_11_1_0/Fake/V6') + tableName = cms.string('/dev/CMSSW_11_1_0/Fake/V7') ) fragment.streams = cms.PSet( A = cms.vstring( 'InitialPD' ) ) diff --git a/HLTrigger/Configuration/python/HLT_GRun_cff.py b/HLTrigger/Configuration/python/HLT_GRun_cff.py index 5404fdd120892..b76441a5fb5e6 100644 --- a/HLTrigger/Configuration/python/HLT_GRun_cff.py +++ b/HLTrigger/Configuration/python/HLT_GRun_cff.py @@ -1,13 +1,13 @@ # hltGetConfiguration --cff --data /dev/CMSSW_11_1_0/GRun --type GRun -# /dev/CMSSW_11_1_0/GRun/V8 (CMSSW_11_1_0_pre7) +# /dev/CMSSW_11_1_0/GRun/V10 (CMSSW_11_1_0_pre8_HLT1) import FWCore.ParameterSet.Config as cms fragment = cms.ProcessFragment( "HLT" ) fragment.HLTConfigVersion = cms.PSet( - tableName = cms.string('/dev/CMSSW_11_1_0/GRun/V8') + tableName = cms.string('/dev/CMSSW_11_1_0/GRun/V10') ) fragment.transferSystem = cms.PSet( @@ -6268,11 +6268,12 @@ ClusterProbComputationFlag = cms.int32( 0 ), Alpha2Order = cms.bool( True ), appendToDataLabel = cms.string( "" ), - EdgeClusterErrorY = cms.double( 85.0 ), + lAWidthFPix = cms.double( 0.0 ), SmallPitch = cms.bool( False ), LoadTemplatesFromDB = cms.bool( True ), + NoTemplateErrorsWhenNoTrkAngles = cms.bool( False ), EdgeClusterErrorX = cms.double( 50.0 ), - lAWidthFPix = cms.double( 0.0 ), + EdgeClusterErrorY = cms.double( 85.0 ), lAOffset = cms.double( 0.0 ), ComponentName = cms.string( "hltESPPixelCPEGeneric" ), MagneticFieldRecord = cms.ESInputTag( "" ), @@ -6727,6 +6728,7 @@ fragment.hltGetRaw = cms.EDAnalyzer( "HLTGetRaw", RawDataCollection = cms.InputTag( "rawDataCollector" ) ) +fragment.hltPSetMap = cms.EDProducer( "ParameterSetBlobProducer" ) fragment.hltBoolFalse = cms.EDFilter( "HLTBool", result = cms.bool( False ) ) @@ -8107,16 +8109,16 @@ maxNumberOfClusters = cms.int32( 40000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) fragment.hltSiPixelClustersCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -33204,6 +33206,7 @@ minMeff = cms.vdouble( 0.0 ) ) fragment.hltVerticesPF = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -33233,6 +33236,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltPFMuonMerging" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -34878,16 +34882,16 @@ maxNumberOfClusters = cms.int32( 20000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) fragment.hltSiPixelClustersRegL1TauSeededCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -40571,16 +40575,16 @@ maxNumberOfClusters = cms.int32( 20000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) fragment.hltSiPixelClustersRegForTauCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -48237,10 +48241,13 @@ minMht = cms.vdouble( 100.0 ) ) fragment.hltPFMETProducer = cms.EDProducer( "PFMETProducer", - globalThreshold = cms.double( 0.0 ), + src = cms.InputTag( "hltParticleFlow" ), + parameters = cms.PSet( ), + applyWeight = cms.bool( False ), calculateSignificance = cms.bool( False ), alias = cms.string( "hltPFMet" ), - src = cms.InputTag( "hltParticleFlow" ) + srcWeights = cms.InputTag( "" ), + globalThreshold = cms.double( 0.0 ) ) fragment.hltPFMET100 = cms.EDFilter( "HLT1PFMET", saveTags = cms.bool( True ), @@ -48622,16 +48629,16 @@ maxNumberOfClusters = cms.int32( 40000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) fragment.hltSiPixelClustersRegForBTagCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -49770,6 +49777,7 @@ newQuality = cms.string( "confirmed" ) ) fragment.hltVerticesL3 = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -49799,6 +49807,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltMergedTracksForBTag" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -50119,10 +50128,13 @@ cut = cms.string( "particleId!=3" ) ) fragment.hltPFMETNoMuProducer = cms.EDProducer( "PFMETProducer", - globalThreshold = cms.double( 0.0 ), + src = cms.InputTag( "hltParticleFlowNoMu" ), + parameters = cms.PSet( ), + applyWeight = cms.bool( False ), calculateSignificance = cms.bool( False ), alias = cms.string( "pfMetNoMu" ), - src = cms.InputTag( "hltParticleFlowNoMu" ) + srcWeights = cms.InputTag( "" ), + globalThreshold = cms.double( 0.0 ) ) fragment.hltPFMETNoMu120 = cms.EDFilter( "HLT1PFMET", saveTags = cms.bool( True ), @@ -66017,10 +66029,13 @@ MaxMass = cms.double( -1.0 ) ) fragment.hltPFMETVBFProducer = cms.EDProducer( "PFMETProducer", - globalThreshold = cms.double( 0.0 ), + src = cms.InputTag( "hltParticleFlowNoMu" ), + parameters = cms.PSet( ), + applyWeight = cms.bool( False ), calculateSignificance = cms.bool( False ), alias = cms.string( "pfMet" ), - src = cms.InputTag( "hltParticleFlowNoMu" ) + srcWeights = cms.InputTag( "" ), + globalThreshold = cms.double( 0.0 ) ) fragment.hltPFMETVBF110 = cms.EDFilter( "HLT1PFMET", saveTags = cms.bool( True ), @@ -87829,7 +87844,7 @@ fragment.HLTBeginSequenceParking = cms.Sequence( fragment.hltTriggerType + fragment.hltEnableParking + fragment.HLTL1UnpackerSequence + fragment.HLTBeamSpot ) fragment.HLTPFScoutingPackingSequence = cms.Sequence( fragment.hltScoutingPFPacker + fragment.hltScoutingMuonPacker + fragment.hltScoutingEgammaPacker ) -fragment.HLTriggerFirstPath = cms.Path( fragment.hltGetConditions + fragment.hltGetRaw + fragment.hltBoolFalse ) +fragment.HLTriggerFirstPath = cms.Path( fragment.hltGetConditions + fragment.hltGetRaw + fragment.hltPSetMap + fragment.hltBoolFalse ) fragment.HLT_AK8PFJet360_TrimMass30_v18 = cms.Path( fragment.HLTBeginSequence + fragment.hltL1sSingleJet180 + fragment.hltPreAK8PFJet360TrimMass30 + fragment.HLTAK8CaloJetsSequence + fragment.hltAK8SingleCaloJet260 + fragment.HLTAK8PFJetsSequence + fragment.hltAK8PFJetsCorrectedMatchedToCaloJets260 + fragment.hltAK8SinglePFJet360 + fragment.hltAK8TrimModJets + fragment.hltAK8SinglePFJetTrimModMass30 + fragment.HLTEndSequence ) fragment.HLT_AK8PFJet380_TrimMass30_v11 = cms.Path( fragment.HLTBeginSequence + fragment.hltL1sSingleJet180 + fragment.hltPreAK8PFJet380TrimMass30 + fragment.HLTAK8CaloJetsSequence + fragment.hltAK8SingleCaloJet280 + fragment.HLTAK8PFJetsSequence + fragment.hltAK8PFJetsCorrectedMatchedToCaloJets280 + fragment.hltAK8SinglePFJet380 + fragment.hltAK8TrimModJets + fragment.hltAK8SinglePFJetTrimModMass30 + fragment.HLTEndSequence ) fragment.HLT_AK8PFJet400_TrimMass30_v12 = cms.Path( fragment.HLTBeginSequence + fragment.hltL1sSingleJet180 + fragment.hltPreAK8PFJet400TrimMass30 + fragment.HLTAK8CaloJetsSequence + fragment.hltAK8SingleCaloJet300 + fragment.HLTAK8PFJetsSequence + fragment.hltAK8PFJetsCorrectedMatchedToCaloJets300 + fragment.hltAK8SinglePFJet400 + fragment.hltAK8TrimModJets + fragment.hltAK8SinglePFJetTrimModMass30 + fragment.HLTEndSequence ) diff --git a/HLTrigger/Configuration/python/HLT_HIon_cff.py b/HLTrigger/Configuration/python/HLT_HIon_cff.py index 1a3225295d92b..7bf389f204f46 100644 --- a/HLTrigger/Configuration/python/HLT_HIon_cff.py +++ b/HLTrigger/Configuration/python/HLT_HIon_cff.py @@ -1,13 +1,13 @@ # hltGetConfiguration --cff --data /dev/CMSSW_11_1_0/HIon --type HIon -# /dev/CMSSW_11_1_0/HIon/V8 (CMSSW_11_1_0_pre7) +# /dev/CMSSW_11_1_0/HIon/V10 (CMSSW_11_1_0_pre8_HLT1) import FWCore.ParameterSet.Config as cms fragment = cms.ProcessFragment( "HLT" ) fragment.HLTConfigVersion = cms.PSet( - tableName = cms.string('/dev/CMSSW_11_1_0/HIon/V8') + tableName = cms.string('/dev/CMSSW_11_1_0/HIon/V10') ) fragment.transferSystem = cms.PSet( @@ -5393,11 +5393,12 @@ ClusterProbComputationFlag = cms.int32( 0 ), Alpha2Order = cms.bool( True ), appendToDataLabel = cms.string( "" ), - EdgeClusterErrorY = cms.double( 85.0 ), + lAWidthFPix = cms.double( 0.0 ), SmallPitch = cms.bool( False ), LoadTemplatesFromDB = cms.bool( True ), + NoTemplateErrorsWhenNoTrkAngles = cms.bool( False ), EdgeClusterErrorX = cms.double( 50.0 ), - lAWidthFPix = cms.double( 0.0 ), + EdgeClusterErrorY = cms.double( 85.0 ), lAOffset = cms.double( 0.0 ), ComponentName = cms.string( "hltESPPixelCPEGeneric" ), MagneticFieldRecord = cms.ESInputTag( "" ), @@ -5852,6 +5853,7 @@ fragment.hltGetRaw = cms.EDAnalyzer( "HLTGetRaw", RawDataCollection = cms.InputTag( "rawDataCollector" ) ) +fragment.hltPSetMap = cms.EDProducer( "ParameterSetBlobProducer" ) fragment.hltBoolFalse = cms.EDFilter( "HLTBool", result = cms.bool( False ) ) @@ -7819,16 +7821,16 @@ maxNumberOfClusters = cms.int32( -1 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "Offline" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) fragment.hltSiPixelClustersCachePPOnAA = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -10182,6 +10184,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) fragment.hltFullIter0PrimaryVerticesPreSplittingPPOnAA = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -10204,6 +10207,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPreSplittingPPOnAA" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -10525,6 +10529,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) fragment.hltFullIter0PrimaryVerticesPPOnAA = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -10547,6 +10552,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPPOnAA" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -12558,6 +12564,7 @@ correctors = cms.VInputTag( 'hltCsAK4PFCorrectorPPOnAA' ) ) fragment.hltVerticesPFPPOnAA = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -12587,6 +12594,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltPFMuonMergingPPOnAA" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -17874,6 +17882,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) fragment.hltFullIter0PrimaryVerticesPreSplittingPPOnAAForDmeson = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -17896,6 +17905,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPreSplittingPPOnAAForDmeson" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -18080,6 +18090,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) fragment.hltFullIter0PrimaryVerticesPPOnAAForDmeson = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -18102,6 +18113,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPPOnAAForDmeson" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -20323,6 +20335,7 @@ trackAlgoPriorityOrder = cms.string( "hltESPTrackAlgoPriorityOrder" ) ) fragment.hltFullOnlinePrimaryVerticesPPOnAAForDmeson = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -20352,6 +20365,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIterativeTrackingMergedPPOnAAForDmeson" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -20662,6 +20676,7 @@ trackAlgoPriorityOrder = cms.string( "hltESPTrackAlgoPriorityOrder" ) ) fragment.hltFullOnlinePrimaryVerticesPPOnAAForDmesonNoIter10 = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -20691,6 +20706,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIterativeTrackingMergedPPOnAAForDmesonNoIter10" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -23801,16 +23817,16 @@ maxNumberOfClusters = cms.int32( -1 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) fragment.hltHISiPixelClustersCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -24111,16 +24127,16 @@ maxNumberOfClusters = cms.int32( -1 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "Offline" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) fragment.hltSiPixelClustersCachePPOnAAForLowPt = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -24286,6 +24302,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) fragment.hltFullIter0PrimaryVerticesPreSplittingPPOnAAForLowPt = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -24308,6 +24325,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPreSplittingPPOnAAForLowPt" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -24490,6 +24508,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) fragment.hltFullIter0PrimaryVerticesPPOnAAForLowPt = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -24512,6 +24531,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPPOnAAForLowPt" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -26588,6 +26608,7 @@ trackAlgoPriorityOrder = cms.string( "hltESPTrackAlgoPriorityOrder" ) ) fragment.hltFullOnlinePrimaryVerticesPPOnAAForLowPt = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -26617,6 +26638,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIterativeTrackingMergedPPOnAAForLowPt" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -29502,6 +29524,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) fragment.hltFullIter0PrimaryVerticesPPOnAAForBTag = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -29524,6 +29547,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPPOnAAForBTag" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -30508,6 +30532,7 @@ trackAlgoPriorityOrder = cms.string( "hltESPTrackAlgoPriorityOrder" ) ) fragment.hltFullOnlinePrimaryVerticesPPOnAAForBTag = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -30537,6 +30562,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIterativeTrackingMergedPPOnAAForBTag" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -31703,7 +31729,7 @@ fragment.HLTBtagCSVv2SequenceL3ForHIBJet100 = cms.Sequence( fragment.HLTTrackReconstructionForBTagForHI + fragment.hltFullOnlinePrimaryVerticesPPOnAAForBTag + fragment.hltFastPixelBLifetimeL3AssociatorHIBJet100 + fragment.hltImpactParameterTagInfosHIBJet100 + fragment.hltInclusiveVertexFinderPPOnAA + fragment.hltInclusiveSecondaryVerticesPPOnAA + fragment.hltTrackVertexArbitratorPPOnAA + fragment.hltInclusiveMergedVerticesPPOnAA + fragment.hltInclusiveSecondaryVertexFinderTagInfosHIBJet100 + fragment.hltCombinedSecondaryVertexV2BJetTagsCaloBJet100 ) fragment.HLTHISinglePixelTrackNpix = cms.Sequence( fragment.HLTHIDoLocalPixelSequence + ~fragment.hltHIPixelCountFilterNpix + fragment.HLTHIRecoPixelTracksSequenceForTrackTrigger + fragment.hltHIPixelCandsForTrackTrigger + fragment.hltHIPixelFilter1 ) -fragment.HLTriggerFirstPath = cms.Path( fragment.hltGetConditions + fragment.hltGetRaw + fragment.hltBoolFalse ) +fragment.HLTriggerFirstPath = cms.Path( fragment.hltGetConditions + fragment.hltGetRaw + fragment.hltPSetMap + fragment.hltBoolFalse ) fragment.DST_Physics_v7 = cms.Path( fragment.HLTBeginSequence + fragment.hltPreDSTPhysics + fragment.HLTEndSequence ) fragment.HLT_EcalCalibration_v4 = cms.Path( fragment.HLTBeginSequenceCalibration + fragment.hltPreEcalCalibration + fragment.hltEcalCalibrationRaw + fragment.HLTEndSequence ) fragment.HLT_HcalCalibration_v5 = cms.Path( fragment.HLTBeginSequenceCalibration + fragment.hltPreHcalCalibration + fragment.hltHcalCalibTypeFilter + fragment.hltHcalCalibrationRaw + fragment.HLTEndSequence ) diff --git a/HLTrigger/Configuration/python/HLT_PIon_cff.py b/HLTrigger/Configuration/python/HLT_PIon_cff.py index f0959325797bc..419a6381826e7 100644 --- a/HLTrigger/Configuration/python/HLT_PIon_cff.py +++ b/HLTrigger/Configuration/python/HLT_PIon_cff.py @@ -1,13 +1,13 @@ # hltGetConfiguration --cff --data /dev/CMSSW_11_1_0/PIon --type PIon -# /dev/CMSSW_11_1_0/PIon/V8 (CMSSW_11_1_0_pre7) +# /dev/CMSSW_11_1_0/PIon/V10 (CMSSW_11_1_0_pre8_HLT1) import FWCore.ParameterSet.Config as cms fragment = cms.ProcessFragment( "HLT" ) fragment.HLTConfigVersion = cms.PSet( - tableName = cms.string('/dev/CMSSW_11_1_0/PIon/V8') + tableName = cms.string('/dev/CMSSW_11_1_0/PIon/V10') ) fragment.transferSystem = cms.PSet( @@ -4864,11 +4864,12 @@ ClusterProbComputationFlag = cms.int32( 0 ), Alpha2Order = cms.bool( True ), appendToDataLabel = cms.string( "" ), - EdgeClusterErrorY = cms.double( 85.0 ), + lAWidthFPix = cms.double( 0.0 ), SmallPitch = cms.bool( False ), LoadTemplatesFromDB = cms.bool( True ), + NoTemplateErrorsWhenNoTrkAngles = cms.bool( False ), EdgeClusterErrorX = cms.double( 50.0 ), - lAWidthFPix = cms.double( 0.0 ), + EdgeClusterErrorY = cms.double( 85.0 ), lAOffset = cms.double( 0.0 ), ComponentName = cms.string( "hltESPPixelCPEGeneric" ), MagneticFieldRecord = cms.ESInputTag( "" ), @@ -5323,6 +5324,7 @@ fragment.hltGetRaw = cms.EDAnalyzer( "HLTGetRaw", RawDataCollection = cms.InputTag( "rawDataCollector" ) ) +fragment.hltPSetMap = cms.EDProducer( "ParameterSetBlobProducer" ) fragment.hltBoolFalse = cms.EDFilter( "HLTBool", result = cms.bool( False ) ) @@ -5463,7 +5465,7 @@ fragment.HLTBeginSequenceRandom = cms.Sequence( fragment.hltRandomEventsFilter + fragment.hltGtStage2Digis ) fragment.HLTBeginSequence = cms.Sequence( fragment.hltTriggerType + fragment.HLTL1UnpackerSequence + fragment.HLTBeamSpot ) -fragment.HLTriggerFirstPath = cms.Path( fragment.hltGetConditions + fragment.hltGetRaw + fragment.hltBoolFalse ) +fragment.HLTriggerFirstPath = cms.Path( fragment.hltGetConditions + fragment.hltGetRaw + fragment.hltPSetMap + fragment.hltBoolFalse ) fragment.HLT_Physics_v7 = cms.Path( fragment.HLTBeginSequenceL1Fat + fragment.hltPrePhysics + fragment.HLTEndSequence ) fragment.HLT_Random_v3 = cms.Path( fragment.HLTBeginSequenceRandom + fragment.hltPreRandom + fragment.HLTEndSequence ) fragment.HLT_ZeroBias_v6 = cms.Path( fragment.HLTBeginSequence + fragment.hltL1sZeroBias + fragment.hltPreZeroBias + fragment.HLTEndSequence ) diff --git a/HLTrigger/Configuration/python/HLT_PRef_cff.py b/HLTrigger/Configuration/python/HLT_PRef_cff.py index f25b39fe4e09b..03b8ca57f0c5f 100644 --- a/HLTrigger/Configuration/python/HLT_PRef_cff.py +++ b/HLTrigger/Configuration/python/HLT_PRef_cff.py @@ -1,13 +1,13 @@ # hltGetConfiguration --cff --data /dev/CMSSW_11_1_0/PRef --type PRef -# /dev/CMSSW_11_1_0/PRef/V8 (CMSSW_11_1_0_pre7) +# /dev/CMSSW_11_1_0/PRef/V10 (CMSSW_11_1_0_pre8_HLT1) import FWCore.ParameterSet.Config as cms fragment = cms.ProcessFragment( "HLT" ) fragment.HLTConfigVersion = cms.PSet( - tableName = cms.string('/dev/CMSSW_11_1_0/PRef/V8') + tableName = cms.string('/dev/CMSSW_11_1_0/PRef/V10') ) fragment.transferSystem = cms.PSet( @@ -4942,11 +4942,12 @@ ClusterProbComputationFlag = cms.int32( 0 ), Alpha2Order = cms.bool( True ), appendToDataLabel = cms.string( "" ), - EdgeClusterErrorY = cms.double( 85.0 ), + lAWidthFPix = cms.double( 0.0 ), SmallPitch = cms.bool( False ), LoadTemplatesFromDB = cms.bool( True ), + NoTemplateErrorsWhenNoTrkAngles = cms.bool( False ), EdgeClusterErrorX = cms.double( 50.0 ), - lAWidthFPix = cms.double( 0.0 ), + EdgeClusterErrorY = cms.double( 85.0 ), lAOffset = cms.double( 0.0 ), ComponentName = cms.string( "hltESPPixelCPEGeneric" ), MagneticFieldRecord = cms.ESInputTag( "" ), @@ -5401,6 +5402,7 @@ fragment.hltGetRaw = cms.EDAnalyzer( "HLTGetRaw", RawDataCollection = cms.InputTag( "rawDataCollector" ) ) +fragment.hltPSetMap = cms.EDProducer( "ParameterSetBlobProducer" ) fragment.hltBoolFalse = cms.EDFilter( "HLTBool", result = cms.bool( False ) ) @@ -6548,16 +6550,16 @@ maxNumberOfClusters = cms.int32( 40000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) fragment.hltSiPixelClustersCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -9832,6 +9834,7 @@ newQuality = cms.string( "confirmed" ) ) fragment.hltVerticesPF = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -9861,6 +9864,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltPFMuonMerging" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -10846,7 +10850,7 @@ fragment.HLTDoFullUnpackingEgammaEcalSequence = cms.Sequence( fragment.hltEcalDigis + fragment.hltEcalPreshowerDigis + fragment.hltEcalUncalibRecHit + fragment.hltEcalDetIdToBeRecovered + fragment.hltEcalRecHit + fragment.hltEcalPreshowerRecHit ) fragment.HLTBeginSequenceCalibration = cms.Sequence( fragment.hltCalibrationEventsFilter + fragment.hltGtStage2Digis ) -fragment.HLTriggerFirstPath = cms.Path( fragment.hltGetConditions + fragment.hltGetRaw + fragment.hltBoolFalse ) +fragment.HLTriggerFirstPath = cms.Path( fragment.hltGetConditions + fragment.hltGetRaw + fragment.hltPSetMap + fragment.hltBoolFalse ) fragment.HLT_ZeroBias_Beamspot_v4 = cms.Path( fragment.HLTBeginSequence + fragment.hltL1sZeroBias + fragment.hltPreZeroBiasBeamspot + fragment.HLTTrackingForBeamSpot + fragment.hltVerticesPF + fragment.hltVerticesPFSelector + fragment.hltVerticesPFFilter + fragment.HLTEndSequence ) fragment.HLT_Physics_v7 = cms.Path( fragment.HLTBeginSequenceL1Fat + fragment.hltPrePhysics + fragment.HLTEndSequence ) fragment.DST_Physics_v7 = cms.Path( fragment.HLTBeginSequence + fragment.hltPreDSTPhysics + fragment.HLTEndSequence ) diff --git a/HLTrigger/Configuration/test/OnLine_HLT_2018.py b/HLTrigger/Configuration/test/OnLine_HLT_2018.py index 9214a4a6dbe50..0da1ebeee4060 100644 --- a/HLTrigger/Configuration/test/OnLine_HLT_2018.py +++ b/HLTrigger/Configuration/test/OnLine_HLT_2018.py @@ -1,13 +1,13 @@ # hltGetConfiguration --full --data /frozen/2018/111X/HLT --type 2018 --unprescale --process HLT2018 --globaltag auto:run2_hlt_2018 --input file:RelVal_Raw_2018_DATA.root -# /frozen/2018/111X/HLT/V11 (CMSSW_11_1_0_pre7) +# /frozen/2018/111X/HLT/V13 (CMSSW_11_1_0_pre8_HLT1) import FWCore.ParameterSet.Config as cms process = cms.Process( "HLT2018" ) process.HLTConfigVersion = cms.PSet( - tableName = cms.string('/frozen/2018/111X/HLT/V11') + tableName = cms.string('/frozen/2018/111X/HLT/V13') ) process.transferSystem = cms.PSet( @@ -6441,11 +6441,12 @@ ClusterProbComputationFlag = cms.int32( 0 ), Alpha2Order = cms.bool( True ), appendToDataLabel = cms.string( "" ), - EdgeClusterErrorY = cms.double( 85.0 ), + lAWidthFPix = cms.double( 0.0 ), SmallPitch = cms.bool( False ), LoadTemplatesFromDB = cms.bool( True ), + NoTemplateErrorsWhenNoTrkAngles = cms.bool( False ), EdgeClusterErrorX = cms.double( 50.0 ), - lAWidthFPix = cms.double( 0.0 ), + EdgeClusterErrorY = cms.double( 85.0 ), lAOffset = cms.double( 0.0 ), ComponentName = cms.string( "hltESPPixelCPEGeneric" ), MagneticFieldRecord = cms.ESInputTag( "" ), @@ -7042,6 +7043,7 @@ process.hltGetRaw = cms.EDAnalyzer( "HLTGetRaw", RawDataCollection = cms.InputTag( "rawDataCollector" ) ) +process.hltPSetMap = cms.EDProducer( "ParameterSetBlobProducer" ) process.hltBoolFalse = cms.EDFilter( "HLTBool", result = cms.bool( False ) ) @@ -33643,6 +33645,7 @@ minMeff = cms.vdouble( 0.0 ) ) process.hltVerticesPF = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -33672,6 +33675,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltPFMuonMerging" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -49011,10 +49015,13 @@ minMht = cms.vdouble( 100.0 ) ) process.hltPFMETProducer = cms.EDProducer( "PFMETProducer", - globalThreshold = cms.double( 0.0 ), + src = cms.InputTag( "hltParticleFlow" ), + parameters = cms.PSet( ), + applyWeight = cms.bool( False ), calculateSignificance = cms.bool( False ), alias = cms.string( "hltPFMet" ), - src = cms.InputTag( "hltParticleFlow" ) + srcWeights = cms.InputTag( "" ), + globalThreshold = cms.double( 0.0 ) ) process.hltPFMET100 = cms.EDFilter( "HLT1PFMET", saveTags = cms.bool( True ), @@ -50616,6 +50623,7 @@ newQuality = cms.string( "confirmed" ) ) process.hltVerticesL3 = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -50645,6 +50653,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltMergedTracksForBTag" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -50965,10 +50974,13 @@ cut = cms.string( "particleId!=3" ) ) process.hltPFMETNoMuProducer = cms.EDProducer( "PFMETProducer", - globalThreshold = cms.double( 0.0 ), + src = cms.InputTag( "hltParticleFlowNoMu" ), + parameters = cms.PSet( ), + applyWeight = cms.bool( False ), calculateSignificance = cms.bool( False ), alias = cms.string( "pfMetNoMu" ), - src = cms.InputTag( "hltParticleFlowNoMu" ) + srcWeights = cms.InputTag( "" ), + globalThreshold = cms.double( 0.0 ) ) process.hltPFMETNoMu120 = cms.EDFilter( "HLT1PFMET", saveTags = cms.bool( True ), @@ -66996,10 +67008,13 @@ MaxMass = cms.double( -1.0 ) ) process.hltPFMETVBFProducer = cms.EDProducer( "PFMETProducer", - globalThreshold = cms.double( 0.0 ), + src = cms.InputTag( "hltParticleFlowNoMu" ), + parameters = cms.PSet( ), + applyWeight = cms.bool( False ), calculateSignificance = cms.bool( False ), alias = cms.string( "pfMet" ), - src = cms.InputTag( "hltParticleFlowNoMu" ) + srcWeights = cms.InputTag( "" ), + globalThreshold = cms.double( 0.0 ) ) process.hltPFMETVBF110 = cms.EDFilter( "HLT1PFMET", saveTags = cms.bool( True ), @@ -92059,7 +92074,7 @@ process.HLTBeginSequenceParking = cms.Sequence( process.hltTriggerType + process.hltEnableParking + process.HLTL1UnpackerSequence + process.HLTBeamSpot ) process.HLTPFScoutingPackingSequence = cms.Sequence( process.hltScoutingPFPacker + process.hltScoutingMuonPacker + process.hltScoutingEgammaPacker ) -process.HLTriggerFirstPath = cms.Path( process.hltGetConditions + process.hltGetRaw + process.hltBoolFalse ) +process.HLTriggerFirstPath = cms.Path( process.hltGetConditions + process.hltGetRaw + process.hltPSetMap + process.hltBoolFalse ) process.HLT_AK8PFJet360_TrimMass30_v18 = cms.Path( process.HLTBeginSequence + process.hltL1sSingleJet180 + process.hltPreAK8PFJet360TrimMass30 + process.HLTAK8CaloJetsSequence + process.hltAK8SingleCaloJet260 + process.HLTAK8PFJetsSequence + process.hltAK8PFJetsCorrectedMatchedToCaloJets260 + process.hltAK8SinglePFJet360 + process.hltAK8TrimModJets + process.hltAK8SinglePFJetTrimModMass30 + process.HLTEndSequence ) process.HLT_AK8PFJet380_TrimMass30_v11 = cms.Path( process.HLTBeginSequence + process.hltL1sSingleJet180 + process.hltPreAK8PFJet380TrimMass30 + process.HLTAK8CaloJetsSequence + process.hltAK8SingleCaloJet280 + process.HLTAK8PFJetsSequence + process.hltAK8PFJetsCorrectedMatchedToCaloJets280 + process.hltAK8SinglePFJet380 + process.hltAK8TrimModJets + process.hltAK8SinglePFJetTrimModMass30 + process.HLTEndSequence ) process.HLT_AK8PFJet400_TrimMass30_v12 = cms.Path( process.HLTBeginSequence + process.hltL1sSingleJet180 + process.hltPreAK8PFJet400TrimMass30 + process.HLTAK8CaloJetsSequence + process.hltAK8SingleCaloJet300 + process.HLTAK8PFJetsSequence + process.hltAK8PFJetsCorrectedMatchedToCaloJets300 + process.hltAK8SinglePFJet400 + process.hltAK8TrimModJets + process.hltAK8SinglePFJetTrimModMass30 + process.HLTEndSequence ) @@ -92815,7 +92830,6 @@ # load the DQMStore and DQMRootOutputModule process.load( "DQMServices.Core.DQMStore_cfi" ) -process.DQMStore.enableMultiThread = True process.dqmOutput = cms.OutputModule("DQMRootOutputModule", fileName = cms.untracked.string("DQMIO.root") diff --git a/HLTrigger/Configuration/test/OnLine_HLT_FULL.py b/HLTrigger/Configuration/test/OnLine_HLT_FULL.py index ec6afc593acbc..98a861a57ca97 100644 --- a/HLTrigger/Configuration/test/OnLine_HLT_FULL.py +++ b/HLTrigger/Configuration/test/OnLine_HLT_FULL.py @@ -1,13 +1,13 @@ # hltGetConfiguration --full --data /dev/CMSSW_11_1_0/HLT --type FULL --unprescale --process HLTFULL --globaltag auto:run3_hlt_FULL --input file:RelVal_Raw_FULL_DATA.root -# /dev/CMSSW_11_1_0/HLT/V17 (CMSSW_11_1_0_pre7) +# /dev/CMSSW_11_1_0/HLT/V20 (CMSSW_11_1_0_pre8_HLT1) import FWCore.ParameterSet.Config as cms process = cms.Process( "HLTFULL" ) process.HLTConfigVersion = cms.PSet( - tableName = cms.string('/dev/CMSSW_11_1_0/HLT/V17') + tableName = cms.string('/dev/CMSSW_11_1_0/HLT/V20') ) process.transferSystem = cms.PSet( @@ -7746,11 +7746,12 @@ ClusterProbComputationFlag = cms.int32( 0 ), Alpha2Order = cms.bool( True ), appendToDataLabel = cms.string( "" ), - EdgeClusterErrorY = cms.double( 85.0 ), + lAWidthFPix = cms.double( 0.0 ), SmallPitch = cms.bool( False ), LoadTemplatesFromDB = cms.bool( True ), + NoTemplateErrorsWhenNoTrkAngles = cms.bool( False ), EdgeClusterErrorX = cms.double( 50.0 ), - lAWidthFPix = cms.double( 0.0 ), + EdgeClusterErrorY = cms.double( 85.0 ), lAOffset = cms.double( 0.0 ), ComponentName = cms.string( "hltESPPixelCPEGeneric" ), MagneticFieldRecord = cms.ESInputTag( "" ), @@ -8347,6 +8348,7 @@ process.hltGetRaw = cms.EDAnalyzer( "HLTGetRaw", RawDataCollection = cms.InputTag( "rawDataCollector" ) ) +process.hltPSetMap = cms.EDProducer( "ParameterSetBlobProducer" ) process.hltBoolFalse = cms.EDFilter( "HLTBool", result = cms.bool( False ) ) @@ -9727,16 +9729,16 @@ maxNumberOfClusters = cms.int32( 40000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) process.hltSiPixelClustersCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -34872,6 +34874,7 @@ minMeff = cms.vdouble( 0.0 ) ) process.hltVerticesPF = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -34901,6 +34904,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltPFMuonMerging" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -36570,16 +36574,16 @@ maxNumberOfClusters = cms.int32( 20000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) process.hltSiPixelClustersRegL1TauSeededCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -42263,16 +42267,16 @@ maxNumberOfClusters = cms.int32( 20000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) process.hltSiPixelClustersRegForTauCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -50313,10 +50317,13 @@ minMht = cms.vdouble( 100.0 ) ) process.hltPFMETProducer = cms.EDProducer( "PFMETProducer", - globalThreshold = cms.double( 0.0 ), + src = cms.InputTag( "hltParticleFlow" ), + parameters = cms.PSet( ), + applyWeight = cms.bool( False ), calculateSignificance = cms.bool( False ), alias = cms.string( "hltPFMet" ), - src = cms.InputTag( "hltParticleFlow" ) + srcWeights = cms.InputTag( "" ), + globalThreshold = cms.double( 0.0 ) ) process.hltPFMET100 = cms.EDFilter( "HLT1PFMET", saveTags = cms.bool( True ), @@ -50698,16 +50705,16 @@ maxNumberOfClusters = cms.int32( 40000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) process.hltSiPixelClustersRegForBTagCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -51846,6 +51853,7 @@ newQuality = cms.string( "confirmed" ) ) process.hltVerticesL3 = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -51875,6 +51883,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltMergedTracksForBTag" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -52195,10 +52204,13 @@ cut = cms.string( "particleId!=3" ) ) process.hltPFMETNoMuProducer = cms.EDProducer( "PFMETProducer", - globalThreshold = cms.double( 0.0 ), + src = cms.InputTag( "hltParticleFlowNoMu" ), + parameters = cms.PSet( ), + applyWeight = cms.bool( False ), calculateSignificance = cms.bool( False ), alias = cms.string( "pfMetNoMu" ), - src = cms.InputTag( "hltParticleFlowNoMu" ) + srcWeights = cms.InputTag( "" ), + globalThreshold = cms.double( 0.0 ) ) process.hltPFMETNoMu120 = cms.EDFilter( "HLT1PFMET", saveTags = cms.bool( True ), @@ -68596,10 +68608,13 @@ MaxMass = cms.double( -1.0 ) ) process.hltPFMETVBFProducer = cms.EDProducer( "PFMETProducer", - globalThreshold = cms.double( 0.0 ), + src = cms.InputTag( "hltParticleFlowNoMu" ), + parameters = cms.PSet( ), + applyWeight = cms.bool( False ), calculateSignificance = cms.bool( False ), alias = cms.string( "pfMet" ), - src = cms.InputTag( "hltParticleFlowNoMu" ) + srcWeights = cms.InputTag( "" ), + globalThreshold = cms.double( 0.0 ) ) process.hltPFMETVBF110 = cms.EDFilter( "HLT1PFMET", saveTags = cms.bool( True ), @@ -82583,16 +82598,16 @@ maxNumberOfClusters = cms.int32( 40000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) process.hltSiPixelClustersCacheAfterSplitting = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -82784,6 +82799,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) process.hltPAIter0PrimaryVertices = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -82806,6 +82822,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltPAIter0CtfWithMaterialTracks" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -85325,6 +85342,7 @@ etMin = cms.double( 60.0 ) ) process.hltVerticesL3PFBjets = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -85354,6 +85372,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltPFMuonMerging" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -96816,16 +96835,16 @@ maxNumberOfClusters = cms.int32( 40000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) process.hltSiPixelClustersCacheForHighBeta = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -98258,16 +98277,16 @@ maxNumberOfClusters = cms.int32( -1 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "Offline" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) process.hltSiPixelClustersCachePPOnAA = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -100607,6 +100626,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) process.hltFullIter0PrimaryVerticesPreSplittingPPOnAA = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -100629,6 +100649,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPreSplittingPPOnAA" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -100939,6 +100960,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) process.hltFullIter0PrimaryVerticesPPOnAA = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -100961,6 +100983,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPPOnAA" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -102453,6 +102476,7 @@ correctors = cms.VInputTag( 'hltCsAK4PFCorrectorPPOnAA' ) ) process.hltVerticesPFPPOnAA = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -102482,6 +102506,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltPFMuonMergingPPOnAA" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -107697,6 +107722,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) process.hltFullIter0PrimaryVerticesPreSplittingPPOnAAForDmeson = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -107719,6 +107745,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPreSplittingPPOnAAForDmeson" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -107903,6 +107930,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) process.hltFullIter0PrimaryVerticesPPOnAAForDmeson = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -107925,6 +107953,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPPOnAAForDmeson" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -110146,6 +110175,7 @@ trackAlgoPriorityOrder = cms.string( "hltESPTrackAlgoPriorityOrder" ) ) process.hltFullOnlinePrimaryVerticesPPOnAAForDmeson = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -110175,6 +110205,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIterativeTrackingMergedPPOnAAForDmeson" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -110485,6 +110516,7 @@ trackAlgoPriorityOrder = cms.string( "hltESPTrackAlgoPriorityOrder" ) ) process.hltFullOnlinePrimaryVerticesPPOnAAForDmesonNoIter10 = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -110514,6 +110546,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIterativeTrackingMergedPPOnAAForDmesonNoIter10" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -113613,16 +113646,16 @@ maxNumberOfClusters = cms.int32( -1 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) process.hltHISiPixelClustersCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -113923,16 +113956,16 @@ maxNumberOfClusters = cms.int32( -1 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "Offline" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) process.hltSiPixelClustersCachePPOnAAForLowPt = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -114098,6 +114131,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) process.hltFullIter0PrimaryVerticesPreSplittingPPOnAAForLowPt = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -114120,6 +114154,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPreSplittingPPOnAAForLowPt" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -114302,6 +114337,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) process.hltFullIter0PrimaryVerticesPPOnAAForLowPt = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -114324,6 +114360,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPPOnAAForLowPt" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -116400,6 +116437,7 @@ trackAlgoPriorityOrder = cms.string( "hltESPTrackAlgoPriorityOrder" ) ) process.hltFullOnlinePrimaryVerticesPPOnAAForLowPt = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -116429,6 +116467,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIterativeTrackingMergedPPOnAAForLowPt" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -119292,6 +119331,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) process.hltFullIter0PrimaryVerticesPPOnAAForBTag = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -119314,6 +119354,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPPOnAAForBTag" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -120298,6 +120339,7 @@ trackAlgoPriorityOrder = cms.string( "hltESPTrackAlgoPriorityOrder" ) ) process.hltFullOnlinePrimaryVerticesPPOnAAForBTag = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -120327,6 +120369,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIterativeTrackingMergedPPOnAAForBTag" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -128683,7 +128726,7 @@ process.HLTHISinglePixelTrackNpix = cms.Sequence( process.HLTHIDoLocalPixelSequence + ~process.hltHIPixelCountFilterNpix + process.HLTHIRecoPixelTracksSequenceForTrackTrigger + process.hltHIPixelCandsForTrackTrigger + process.hltHIPixelFilter1 ) process.HLTPFScoutingPackingSequence = cms.Sequence( process.hltScoutingPFPacker + process.hltScoutingMuonPacker + process.hltScoutingEgammaPacker ) -process.HLTriggerFirstPath = cms.Path( process.hltGetConditions + process.hltGetRaw + process.hltBoolFalse ) +process.HLTriggerFirstPath = cms.Path( process.hltGetConditions + process.hltGetRaw + process.hltPSetMap + process.hltBoolFalse ) process.HLT_AK8PFJet360_TrimMass30_v18 = cms.Path( process.HLTBeginSequence + process.hltL1sSingleJet180 + process.hltPreAK8PFJet360TrimMass30 + process.HLTAK8CaloJetsSequence + process.hltAK8SingleCaloJet260 + process.HLTAK8PFJetsSequence + process.hltAK8PFJetsCorrectedMatchedToCaloJets260 + process.hltAK8SinglePFJet360 + process.hltAK8TrimModJets + process.hltAK8SinglePFJetTrimModMass30 + process.HLTEndSequence ) process.HLT_AK8PFJet380_TrimMass30_v11 = cms.Path( process.HLTBeginSequence + process.hltL1sSingleJet180 + process.hltPreAK8PFJet380TrimMass30 + process.HLTAK8CaloJetsSequence + process.hltAK8SingleCaloJet280 + process.HLTAK8PFJetsSequence + process.hltAK8PFJetsCorrectedMatchedToCaloJets280 + process.hltAK8SinglePFJet380 + process.hltAK8TrimModJets + process.hltAK8SinglePFJetTrimModMass30 + process.HLTEndSequence ) process.HLT_AK8PFJet400_TrimMass30_v12 = cms.Path( process.HLTBeginSequence + process.hltL1sSingleJet180 + process.hltPreAK8PFJet400TrimMass30 + process.HLTAK8CaloJetsSequence + process.hltAK8SingleCaloJet300 + process.HLTAK8PFJetsSequence + process.hltAK8PFJetsCorrectedMatchedToCaloJets300 + process.hltAK8SinglePFJet400 + process.hltAK8TrimModJets + process.hltAK8SinglePFJetTrimModMass30 + process.HLTEndSequence ) @@ -130229,7 +130272,6 @@ # load the DQMStore and DQMRootOutputModule process.load( "DQMServices.Core.DQMStore_cfi" ) -process.DQMStore.enableMultiThread = True process.dqmOutput = cms.OutputModule("DQMRootOutputModule", fileName = cms.untracked.string("DQMIO.root") diff --git a/HLTrigger/Configuration/test/OnLine_HLT_Fake.py b/HLTrigger/Configuration/test/OnLine_HLT_Fake.py index eb656841f0c76..4d13fe70abfa4 100644 --- a/HLTrigger/Configuration/test/OnLine_HLT_Fake.py +++ b/HLTrigger/Configuration/test/OnLine_HLT_Fake.py @@ -1,13 +1,13 @@ # hltGetConfiguration --full --data /dev/CMSSW_11_1_0/Fake --type Fake --unprescale --process HLTFake --globaltag auto:run1_hlt_Fake --input file:RelVal_Raw_Fake_DATA.root -# /dev/CMSSW_11_1_0/Fake/V6 (CMSSW_11_1_0_pre7) +# /dev/CMSSW_11_1_0/Fake/V7 (CMSSW_11_1_0_pre8_HLT1) import FWCore.ParameterSet.Config as cms process = cms.Process( "HLTFake" ) process.HLTConfigVersion = cms.PSet( - tableName = cms.string('/dev/CMSSW_11_1_0/Fake/V6') + tableName = cms.string('/dev/CMSSW_11_1_0/Fake/V7') ) process.streams = cms.PSet( A = cms.vstring( 'InitialPD' ) ) @@ -371,7 +371,6 @@ # load the DQMStore and DQMRootOutputModule process.load( "DQMServices.Core.DQMStore_cfi" ) -process.DQMStore.enableMultiThread = True process.dqmOutput = cms.OutputModule("DQMRootOutputModule", fileName = cms.untracked.string("DQMIO.root") diff --git a/HLTrigger/Configuration/test/OnLine_HLT_Fake1.py b/HLTrigger/Configuration/test/OnLine_HLT_Fake1.py index 16ac8aa66b165..f0e2c12ec29cd 100644 --- a/HLTrigger/Configuration/test/OnLine_HLT_Fake1.py +++ b/HLTrigger/Configuration/test/OnLine_HLT_Fake1.py @@ -1,13 +1,13 @@ # hltGetConfiguration --full --data /dev/CMSSW_11_1_0/Fake1 --type Fake1 --unprescale --process HLTFake1 --globaltag auto:run2_hlt_Fake1 --input file:RelVal_Raw_Fake1_DATA.root -# /dev/CMSSW_11_1_0/Fake1/V6 (CMSSW_11_1_0_pre7) +# /dev/CMSSW_11_1_0/Fake1/V7 (CMSSW_11_1_0_pre8_HLT1) import FWCore.ParameterSet.Config as cms process = cms.Process( "HLTFake1" ) process.HLTConfigVersion = cms.PSet( - tableName = cms.string('/dev/CMSSW_11_1_0/Fake1/V6') + tableName = cms.string('/dev/CMSSW_11_1_0/Fake1/V7') ) process.streams = cms.PSet( A = cms.vstring( 'InitialPD' ) ) @@ -388,7 +388,6 @@ # load the DQMStore and DQMRootOutputModule process.load( "DQMServices.Core.DQMStore_cfi" ) -process.DQMStore.enableMultiThread = True process.dqmOutput = cms.OutputModule("DQMRootOutputModule", fileName = cms.untracked.string("DQMIO.root") diff --git a/HLTrigger/Configuration/test/OnLine_HLT_Fake2.py b/HLTrigger/Configuration/test/OnLine_HLT_Fake2.py index de525b4c25b84..3ba13c682cd13 100644 --- a/HLTrigger/Configuration/test/OnLine_HLT_Fake2.py +++ b/HLTrigger/Configuration/test/OnLine_HLT_Fake2.py @@ -1,13 +1,13 @@ # hltGetConfiguration --full --data /dev/CMSSW_11_1_0/Fake2 --type Fake2 --unprescale --process HLTFake2 --globaltag auto:run2_hlt_Fake2 --input file:RelVal_Raw_Fake2_DATA.root -# /dev/CMSSW_11_1_0/Fake2/V6 (CMSSW_11_1_0_pre7) +# /dev/CMSSW_11_1_0/Fake2/V7 (CMSSW_11_1_0_pre8_HLT1) import FWCore.ParameterSet.Config as cms process = cms.Process( "HLTFake2" ) process.HLTConfigVersion = cms.PSet( - tableName = cms.string('/dev/CMSSW_11_1_0/Fake2/V6') + tableName = cms.string('/dev/CMSSW_11_1_0/Fake2/V7') ) process.streams = cms.PSet( A = cms.vstring( 'InitialPD' ) ) @@ -395,7 +395,6 @@ # load the DQMStore and DQMRootOutputModule process.load( "DQMServices.Core.DQMStore_cfi" ) -process.DQMStore.enableMultiThread = True process.dqmOutput = cms.OutputModule("DQMRootOutputModule", fileName = cms.untracked.string("DQMIO.root") diff --git a/HLTrigger/Configuration/test/OnLine_HLT_GRun.py b/HLTrigger/Configuration/test/OnLine_HLT_GRun.py index bbf4d97579bfe..23944114d8b6e 100644 --- a/HLTrigger/Configuration/test/OnLine_HLT_GRun.py +++ b/HLTrigger/Configuration/test/OnLine_HLT_GRun.py @@ -1,13 +1,13 @@ # hltGetConfiguration --full --data /dev/CMSSW_11_1_0/GRun --type GRun --unprescale --process HLTGRun --globaltag auto:run3_hlt_GRun --input file:RelVal_Raw_GRun_DATA.root -# /dev/CMSSW_11_1_0/GRun/V8 (CMSSW_11_1_0_pre7) +# /dev/CMSSW_11_1_0/GRun/V10 (CMSSW_11_1_0_pre8_HLT1) import FWCore.ParameterSet.Config as cms process = cms.Process( "HLTGRun" ) process.HLTConfigVersion = cms.PSet( - tableName = cms.string('/dev/CMSSW_11_1_0/GRun/V8') + tableName = cms.string('/dev/CMSSW_11_1_0/GRun/V10') ) process.transferSystem = cms.PSet( @@ -6429,11 +6429,12 @@ ClusterProbComputationFlag = cms.int32( 0 ), Alpha2Order = cms.bool( True ), appendToDataLabel = cms.string( "" ), - EdgeClusterErrorY = cms.double( 85.0 ), + lAWidthFPix = cms.double( 0.0 ), SmallPitch = cms.bool( False ), LoadTemplatesFromDB = cms.bool( True ), + NoTemplateErrorsWhenNoTrkAngles = cms.bool( False ), EdgeClusterErrorX = cms.double( 50.0 ), - lAWidthFPix = cms.double( 0.0 ), + EdgeClusterErrorY = cms.double( 85.0 ), lAOffset = cms.double( 0.0 ), ComponentName = cms.string( "hltESPPixelCPEGeneric" ), MagneticFieldRecord = cms.ESInputTag( "" ), @@ -7030,6 +7031,7 @@ process.hltGetRaw = cms.EDAnalyzer( "HLTGetRaw", RawDataCollection = cms.InputTag( "rawDataCollector" ) ) +process.hltPSetMap = cms.EDProducer( "ParameterSetBlobProducer" ) process.hltBoolFalse = cms.EDFilter( "HLTBool", result = cms.bool( False ) ) @@ -8410,16 +8412,16 @@ maxNumberOfClusters = cms.int32( 40000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) process.hltSiPixelClustersCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -33507,6 +33509,7 @@ minMeff = cms.vdouble( 0.0 ) ) process.hltVerticesPF = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -33536,6 +33539,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltPFMuonMerging" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -35181,16 +35185,16 @@ maxNumberOfClusters = cms.int32( 20000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) process.hltSiPixelClustersRegL1TauSeededCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -40874,16 +40878,16 @@ maxNumberOfClusters = cms.int32( 20000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) process.hltSiPixelClustersRegForTauCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -48540,10 +48544,13 @@ minMht = cms.vdouble( 100.0 ) ) process.hltPFMETProducer = cms.EDProducer( "PFMETProducer", - globalThreshold = cms.double( 0.0 ), + src = cms.InputTag( "hltParticleFlow" ), + parameters = cms.PSet( ), + applyWeight = cms.bool( False ), calculateSignificance = cms.bool( False ), alias = cms.string( "hltPFMet" ), - src = cms.InputTag( "hltParticleFlow" ) + srcWeights = cms.InputTag( "" ), + globalThreshold = cms.double( 0.0 ) ) process.hltPFMET100 = cms.EDFilter( "HLT1PFMET", saveTags = cms.bool( True ), @@ -48925,16 +48932,16 @@ maxNumberOfClusters = cms.int32( 40000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) process.hltSiPixelClustersRegForBTagCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -50073,6 +50080,7 @@ newQuality = cms.string( "confirmed" ) ) process.hltVerticesL3 = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -50102,6 +50110,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltMergedTracksForBTag" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -50422,10 +50431,13 @@ cut = cms.string( "particleId!=3" ) ) process.hltPFMETNoMuProducer = cms.EDProducer( "PFMETProducer", - globalThreshold = cms.double( 0.0 ), + src = cms.InputTag( "hltParticleFlowNoMu" ), + parameters = cms.PSet( ), + applyWeight = cms.bool( False ), calculateSignificance = cms.bool( False ), alias = cms.string( "pfMetNoMu" ), - src = cms.InputTag( "hltParticleFlowNoMu" ) + srcWeights = cms.InputTag( "" ), + globalThreshold = cms.double( 0.0 ) ) process.hltPFMETNoMu120 = cms.EDFilter( "HLT1PFMET", saveTags = cms.bool( True ), @@ -66320,10 +66332,13 @@ MaxMass = cms.double( -1.0 ) ) process.hltPFMETVBFProducer = cms.EDProducer( "PFMETProducer", - globalThreshold = cms.double( 0.0 ), + src = cms.InputTag( "hltParticleFlowNoMu" ), + parameters = cms.PSet( ), + applyWeight = cms.bool( False ), calculateSignificance = cms.bool( False ), alias = cms.string( "pfMet" ), - src = cms.InputTag( "hltParticleFlowNoMu" ) + srcWeights = cms.InputTag( "" ), + globalThreshold = cms.double( 0.0 ) ) process.hltPFMETVBF110 = cms.EDFilter( "HLT1PFMET", saveTags = cms.bool( True ), @@ -90860,7 +90875,7 @@ process.HLTBeginSequenceParking = cms.Sequence( process.hltTriggerType + process.hltEnableParking + process.HLTL1UnpackerSequence + process.HLTBeamSpot ) process.HLTPFScoutingPackingSequence = cms.Sequence( process.hltScoutingPFPacker + process.hltScoutingMuonPacker + process.hltScoutingEgammaPacker ) -process.HLTriggerFirstPath = cms.Path( process.hltGetConditions + process.hltGetRaw + process.hltBoolFalse ) +process.HLTriggerFirstPath = cms.Path( process.hltGetConditions + process.hltGetRaw + process.hltPSetMap + process.hltBoolFalse ) process.HLT_AK8PFJet360_TrimMass30_v18 = cms.Path( process.HLTBeginSequence + process.hltL1sSingleJet180 + process.hltPreAK8PFJet360TrimMass30 + process.HLTAK8CaloJetsSequence + process.hltAK8SingleCaloJet260 + process.HLTAK8PFJetsSequence + process.hltAK8PFJetsCorrectedMatchedToCaloJets260 + process.hltAK8SinglePFJet360 + process.hltAK8TrimModJets + process.hltAK8SinglePFJetTrimModMass30 + process.HLTEndSequence ) process.HLT_AK8PFJet380_TrimMass30_v11 = cms.Path( process.HLTBeginSequence + process.hltL1sSingleJet180 + process.hltPreAK8PFJet380TrimMass30 + process.HLTAK8CaloJetsSequence + process.hltAK8SingleCaloJet280 + process.HLTAK8PFJetsSequence + process.hltAK8PFJetsCorrectedMatchedToCaloJets280 + process.hltAK8SinglePFJet380 + process.hltAK8TrimModJets + process.hltAK8SinglePFJetTrimModMass30 + process.HLTEndSequence ) process.HLT_AK8PFJet400_TrimMass30_v12 = cms.Path( process.HLTBeginSequence + process.hltL1sSingleJet180 + process.hltPreAK8PFJet400TrimMass30 + process.HLTAK8CaloJetsSequence + process.hltAK8SingleCaloJet300 + process.HLTAK8PFJetsSequence + process.hltAK8PFJetsCorrectedMatchedToCaloJets300 + process.hltAK8SinglePFJet400 + process.hltAK8TrimModJets + process.hltAK8SinglePFJetTrimModMass30 + process.HLTEndSequence ) @@ -91610,7 +91625,6 @@ # load the DQMStore and DQMRootOutputModule process.load( "DQMServices.Core.DQMStore_cfi" ) -process.DQMStore.enableMultiThread = True process.dqmOutput = cms.OutputModule("DQMRootOutputModule", fileName = cms.untracked.string("DQMIO.root") diff --git a/HLTrigger/Configuration/test/OnLine_HLT_HIon.py b/HLTrigger/Configuration/test/OnLine_HLT_HIon.py index 3f48f55eadcaf..a08ff455c5cba 100644 --- a/HLTrigger/Configuration/test/OnLine_HLT_HIon.py +++ b/HLTrigger/Configuration/test/OnLine_HLT_HIon.py @@ -1,13 +1,13 @@ # hltGetConfiguration --full --data /dev/CMSSW_11_1_0/HIon --type HIon --unprescale --process HLTHIon --globaltag auto:run3_hlt_HIon --input file:RelVal_Raw_HIon_DATA.root -# /dev/CMSSW_11_1_0/HIon/V8 (CMSSW_11_1_0_pre7) +# /dev/CMSSW_11_1_0/HIon/V10 (CMSSW_11_1_0_pre8_HLT1) import FWCore.ParameterSet.Config as cms process = cms.Process( "HLTHIon" ) process.HLTConfigVersion = cms.PSet( - tableName = cms.string('/dev/CMSSW_11_1_0/HIon/V8') + tableName = cms.string('/dev/CMSSW_11_1_0/HIon/V10') ) process.transferSystem = cms.PSet( @@ -5554,11 +5554,12 @@ ClusterProbComputationFlag = cms.int32( 0 ), Alpha2Order = cms.bool( True ), appendToDataLabel = cms.string( "" ), - EdgeClusterErrorY = cms.double( 85.0 ), + lAWidthFPix = cms.double( 0.0 ), SmallPitch = cms.bool( False ), LoadTemplatesFromDB = cms.bool( True ), + NoTemplateErrorsWhenNoTrkAngles = cms.bool( False ), EdgeClusterErrorX = cms.double( 50.0 ), - lAWidthFPix = cms.double( 0.0 ), + EdgeClusterErrorY = cms.double( 85.0 ), lAOffset = cms.double( 0.0 ), ComponentName = cms.string( "hltESPPixelCPEGeneric" ), MagneticFieldRecord = cms.ESInputTag( "" ), @@ -6155,6 +6156,7 @@ process.hltGetRaw = cms.EDAnalyzer( "HLTGetRaw", RawDataCollection = cms.InputTag( "rawDataRepacker" ) ) +process.hltPSetMap = cms.EDProducer( "ParameterSetBlobProducer" ) process.hltBoolFalse = cms.EDFilter( "HLTBool", result = cms.bool( False ) ) @@ -8122,16 +8124,16 @@ maxNumberOfClusters = cms.int32( -1 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "Offline" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) process.hltSiPixelClustersCachePPOnAA = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -10485,6 +10487,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) process.hltFullIter0PrimaryVerticesPreSplittingPPOnAA = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -10507,6 +10510,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPreSplittingPPOnAA" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -10828,6 +10832,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) process.hltFullIter0PrimaryVerticesPPOnAA = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -10850,6 +10855,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPPOnAA" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -12861,6 +12867,7 @@ correctors = cms.VInputTag( 'hltCsAK4PFCorrectorPPOnAA' ) ) process.hltVerticesPFPPOnAA = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -12890,6 +12897,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltPFMuonMergingPPOnAA" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -18177,6 +18185,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) process.hltFullIter0PrimaryVerticesPreSplittingPPOnAAForDmeson = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -18199,6 +18208,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPreSplittingPPOnAAForDmeson" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -18383,6 +18393,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) process.hltFullIter0PrimaryVerticesPPOnAAForDmeson = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -18405,6 +18416,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPPOnAAForDmeson" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -20626,6 +20638,7 @@ trackAlgoPriorityOrder = cms.string( "hltESPTrackAlgoPriorityOrder" ) ) process.hltFullOnlinePrimaryVerticesPPOnAAForDmeson = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -20655,6 +20668,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIterativeTrackingMergedPPOnAAForDmeson" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -20965,6 +20979,7 @@ trackAlgoPriorityOrder = cms.string( "hltESPTrackAlgoPriorityOrder" ) ) process.hltFullOnlinePrimaryVerticesPPOnAAForDmesonNoIter10 = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -20994,6 +21009,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIterativeTrackingMergedPPOnAAForDmesonNoIter10" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -24104,16 +24120,16 @@ maxNumberOfClusters = cms.int32( -1 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) process.hltHISiPixelClustersCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -24414,16 +24430,16 @@ maxNumberOfClusters = cms.int32( -1 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "Offline" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) process.hltSiPixelClustersCachePPOnAAForLowPt = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -24589,6 +24605,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) process.hltFullIter0PrimaryVerticesPreSplittingPPOnAAForLowPt = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -24611,6 +24628,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPreSplittingPPOnAAForLowPt" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -24793,6 +24811,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) process.hltFullIter0PrimaryVerticesPPOnAAForLowPt = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -24815,6 +24834,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPPOnAAForLowPt" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -26891,6 +26911,7 @@ trackAlgoPriorityOrder = cms.string( "hltESPTrackAlgoPriorityOrder" ) ) process.hltFullOnlinePrimaryVerticesPPOnAAForLowPt = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -26920,6 +26941,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIterativeTrackingMergedPPOnAAForLowPt" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -29805,6 +29827,7 @@ Propagator = cms.string( "hltESPRungeKuttaTrackerPropagator" ) ) process.hltFullIter0PrimaryVerticesPPOnAAForBTag = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -29827,6 +29850,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIter0CtfWithMaterialTracksPPOnAAForBTag" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -30811,6 +30835,7 @@ trackAlgoPriorityOrder = cms.string( "hltESPTrackAlgoPriorityOrder" ) ) process.hltFullOnlinePrimaryVerticesPPOnAAForBTag = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 2.5 ), label = cms.string( "" ), @@ -30840,6 +30865,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltFullIterativeTrackingMergedPPOnAAForBTag" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( algorithm = cms.string( "gap" ), TkGapClusParameters = cms.PSet( zSeparation = cms.double( 1.0 ) ) @@ -33594,7 +33620,7 @@ process.HLTBtagCSVv2SequenceL3ForHIBJet100 = cms.Sequence( process.HLTTrackReconstructionForBTagForHI + process.hltFullOnlinePrimaryVerticesPPOnAAForBTag + process.hltFastPixelBLifetimeL3AssociatorHIBJet100 + process.hltImpactParameterTagInfosHIBJet100 + process.hltInclusiveVertexFinderPPOnAA + process.hltInclusiveSecondaryVerticesPPOnAA + process.hltTrackVertexArbitratorPPOnAA + process.hltInclusiveMergedVerticesPPOnAA + process.hltInclusiveSecondaryVertexFinderTagInfosHIBJet100 + process.hltCombinedSecondaryVertexV2BJetTagsCaloBJet100 ) process.HLTHISinglePixelTrackNpix = cms.Sequence( process.HLTHIDoLocalPixelSequence + ~process.hltHIPixelCountFilterNpix + process.HLTHIRecoPixelTracksSequenceForTrackTrigger + process.hltHIPixelCandsForTrackTrigger + process.hltHIPixelFilter1 ) -process.HLTriggerFirstPath = cms.Path( process.hltGetConditions + process.hltGetRaw + process.hltBoolFalse ) +process.HLTriggerFirstPath = cms.Path( process.hltGetConditions + process.hltGetRaw + process.hltPSetMap + process.hltBoolFalse ) process.DST_Physics_v7 = cms.Path( process.HLTBeginSequence + process.hltPreDSTPhysics + process.HLTEndSequence ) process.HLT_EcalCalibration_v4 = cms.Path( process.HLTBeginSequenceCalibration + process.hltPreEcalCalibration + process.hltEcalCalibrationRaw + process.HLTEndSequence ) process.HLT_HcalCalibration_v5 = cms.Path( process.HLTBeginSequenceCalibration + process.hltPreHcalCalibration + process.hltHcalCalibTypeFilter + process.hltHcalCalibrationRaw + process.HLTEndSequence ) @@ -34120,7 +34146,6 @@ # load the DQMStore and DQMRootOutputModule process.load( "DQMServices.Core.DQMStore_cfi" ) -process.DQMStore.enableMultiThread = True process.dqmOutput = cms.OutputModule("DQMRootOutputModule", fileName = cms.untracked.string("DQMIO.root") diff --git a/HLTrigger/Configuration/test/OnLine_HLT_PIon.py b/HLTrigger/Configuration/test/OnLine_HLT_PIon.py index 70f8154110ff3..ab6155716f985 100644 --- a/HLTrigger/Configuration/test/OnLine_HLT_PIon.py +++ b/HLTrigger/Configuration/test/OnLine_HLT_PIon.py @@ -1,13 +1,13 @@ # hltGetConfiguration --full --data /dev/CMSSW_11_1_0/PIon --type PIon --unprescale --process HLTPIon --globaltag auto:run3_hlt_PIon --input file:RelVal_Raw_PIon_DATA.root -# /dev/CMSSW_11_1_0/PIon/V8 (CMSSW_11_1_0_pre7) +# /dev/CMSSW_11_1_0/PIon/V10 (CMSSW_11_1_0_pre8_HLT1) import FWCore.ParameterSet.Config as cms process = cms.Process( "HLTPIon" ) process.HLTConfigVersion = cms.PSet( - tableName = cms.string('/dev/CMSSW_11_1_0/PIon/V8') + tableName = cms.string('/dev/CMSSW_11_1_0/PIon/V10') ) process.transferSystem = cms.PSet( @@ -5025,11 +5025,12 @@ ClusterProbComputationFlag = cms.int32( 0 ), Alpha2Order = cms.bool( True ), appendToDataLabel = cms.string( "" ), - EdgeClusterErrorY = cms.double( 85.0 ), + lAWidthFPix = cms.double( 0.0 ), SmallPitch = cms.bool( False ), LoadTemplatesFromDB = cms.bool( True ), + NoTemplateErrorsWhenNoTrkAngles = cms.bool( False ), EdgeClusterErrorX = cms.double( 50.0 ), - lAWidthFPix = cms.double( 0.0 ), + EdgeClusterErrorY = cms.double( 85.0 ), lAOffset = cms.double( 0.0 ), ComponentName = cms.string( "hltESPPixelCPEGeneric" ), MagneticFieldRecord = cms.ESInputTag( "" ), @@ -5626,6 +5627,7 @@ process.hltGetRaw = cms.EDAnalyzer( "HLTGetRaw", RawDataCollection = cms.InputTag( "rawDataCollector" ) ) +process.hltPSetMap = cms.EDProducer( "ParameterSetBlobProducer" ) process.hltBoolFalse = cms.EDFilter( "HLTBool", result = cms.bool( False ) ) @@ -5843,7 +5845,7 @@ process.HLTBeginSequenceRandom = cms.Sequence( process.hltRandomEventsFilter + process.hltGtStage2Digis ) process.HLTBeginSequence = cms.Sequence( process.hltTriggerType + process.HLTL1UnpackerSequence + process.HLTBeamSpot ) -process.HLTriggerFirstPath = cms.Path( process.hltGetConditions + process.hltGetRaw + process.hltBoolFalse ) +process.HLTriggerFirstPath = cms.Path( process.hltGetConditions + process.hltGetRaw + process.hltPSetMap + process.hltBoolFalse ) process.HLT_Physics_v7 = cms.Path( process.HLTBeginSequenceL1Fat + process.hltPrePhysics + process.HLTEndSequence ) process.HLT_Random_v3 = cms.Path( process.HLTBeginSequenceRandom + process.hltPreRandom + process.HLTEndSequence ) process.HLT_ZeroBias_v6 = cms.Path( process.HLTBeginSequence + process.hltL1sZeroBias + process.hltPreZeroBias + process.HLTEndSequence ) @@ -5853,7 +5855,6 @@ # load the DQMStore and DQMRootOutputModule process.load( "DQMServices.Core.DQMStore_cfi" ) -process.DQMStore.enableMultiThread = True process.dqmOutput = cms.OutputModule("DQMRootOutputModule", fileName = cms.untracked.string("DQMIO.root") diff --git a/HLTrigger/Configuration/test/OnLine_HLT_PRef.py b/HLTrigger/Configuration/test/OnLine_HLT_PRef.py index a364435b9e4f5..31ad596c3ae8b 100644 --- a/HLTrigger/Configuration/test/OnLine_HLT_PRef.py +++ b/HLTrigger/Configuration/test/OnLine_HLT_PRef.py @@ -1,13 +1,13 @@ # hltGetConfiguration --full --data /dev/CMSSW_11_1_0/PRef --type PRef --unprescale --process HLTPRef --globaltag auto:run3_hlt_PRef --input file:RelVal_Raw_PRef_DATA.root -# /dev/CMSSW_11_1_0/PRef/V8 (CMSSW_11_1_0_pre7) +# /dev/CMSSW_11_1_0/PRef/V10 (CMSSW_11_1_0_pre8_HLT1) import FWCore.ParameterSet.Config as cms process = cms.Process( "HLTPRef" ) process.HLTConfigVersion = cms.PSet( - tableName = cms.string('/dev/CMSSW_11_1_0/PRef/V8') + tableName = cms.string('/dev/CMSSW_11_1_0/PRef/V10') ) process.transferSystem = cms.PSet( @@ -5103,11 +5103,12 @@ ClusterProbComputationFlag = cms.int32( 0 ), Alpha2Order = cms.bool( True ), appendToDataLabel = cms.string( "" ), - EdgeClusterErrorY = cms.double( 85.0 ), + lAWidthFPix = cms.double( 0.0 ), SmallPitch = cms.bool( False ), LoadTemplatesFromDB = cms.bool( True ), + NoTemplateErrorsWhenNoTrkAngles = cms.bool( False ), EdgeClusterErrorX = cms.double( 50.0 ), - lAWidthFPix = cms.double( 0.0 ), + EdgeClusterErrorY = cms.double( 85.0 ), lAOffset = cms.double( 0.0 ), ComponentName = cms.string( "hltESPPixelCPEGeneric" ), MagneticFieldRecord = cms.ESInputTag( "" ), @@ -5704,6 +5705,7 @@ process.hltGetRaw = cms.EDAnalyzer( "HLTGetRaw", RawDataCollection = cms.InputTag( "rawDataCollector" ) ) +process.hltPSetMap = cms.EDProducer( "ParameterSetBlobProducer" ) process.hltBoolFalse = cms.EDFilter( "HLTBool", result = cms.bool( False ) ) @@ -6851,16 +6853,16 @@ maxNumberOfClusters = cms.int32( 40000 ), ClusterThreshold_L1 = cms.int32( 2000 ), MissCalibrate = cms.bool( True ), - VCaltoElectronGain = cms.int32( 47 ), - VCaltoElectronGain_L1 = cms.int32( 50 ), - VCaltoElectronOffset = cms.int32( -60 ), + VCaltoElectronGain = cms.int32( 1 ), + VCaltoElectronGain_L1 = cms.int32( 1 ), + VCaltoElectronOffset = cms.int32( 0 ), SplitClusters = cms.bool( False ), payloadType = cms.string( "HLT" ), Phase2Calibration = cms.bool( False ), Phase2KinkADC = cms.int32( 8 ), ClusterMode = cms.string( "PixelThresholdClusterizer" ), SeedThreshold = cms.int32( 1000 ), - VCaltoElectronOffset_L1 = cms.int32( -670 ), + VCaltoElectronOffset_L1 = cms.int32( 0 ), ClusterThreshold = cms.int32( 4000 ) ) process.hltSiPixelClustersCache = cms.EDProducer( "SiPixelClusterShapeCacheProducer", @@ -10135,6 +10137,7 @@ newQuality = cms.string( "confirmed" ) ) process.hltVerticesPF = cms.EDProducer( "PrimaryVertexProducer", + TrackTimesLabel = cms.InputTag( "dummy_default" ), vertexCollections = cms.VPSet( cms.PSet( chi2cutoff = cms.double( 3.0 ), label = cms.string( "" ), @@ -10164,6 +10167,7 @@ ), beamSpotLabel = cms.InputTag( "hltOnlineBeamSpot" ), TrackLabel = cms.InputTag( "hltPFMuonMerging" ), + TrackTimeResosLabel = cms.InputTag( "dummy_default" ), TkClusParameters = cms.PSet( TkDAClusParameters = cms.PSet( zmerge = cms.double( 0.01 ), @@ -11697,7 +11701,7 @@ process.HLTDoFullUnpackingEgammaEcalSequence = cms.Sequence( process.hltEcalDigis + process.hltEcalPreshowerDigis + process.hltEcalUncalibRecHit + process.hltEcalDetIdToBeRecovered + process.hltEcalRecHit + process.hltEcalPreshowerRecHit ) process.HLTBeginSequenceCalibration = cms.Sequence( process.hltCalibrationEventsFilter + process.hltGtStage2Digis ) -process.HLTriggerFirstPath = cms.Path( process.hltGetConditions + process.hltGetRaw + process.hltBoolFalse ) +process.HLTriggerFirstPath = cms.Path( process.hltGetConditions + process.hltGetRaw + process.hltPSetMap + process.hltBoolFalse ) process.HLT_ZeroBias_Beamspot_v4 = cms.Path( process.HLTBeginSequence + process.hltL1sZeroBias + process.hltPreZeroBiasBeamspot + process.HLTTrackingForBeamSpot + process.hltVerticesPF + process.hltVerticesPFSelector + process.hltVerticesPFFilter + process.HLTEndSequence ) process.HLT_Physics_v7 = cms.Path( process.HLTBeginSequenceL1Fat + process.hltPrePhysics + process.HLTEndSequence ) process.DST_Physics_v7 = cms.Path( process.HLTBeginSequence + process.hltPreDSTPhysics + process.HLTEndSequence ) @@ -11742,7 +11746,6 @@ # load the DQMStore and DQMRootOutputModule process.load( "DQMServices.Core.DQMStore_cfi" ) -process.DQMStore.enableMultiThread = True process.dqmOutput = cms.OutputModule("DQMRootOutputModule", fileName = cms.untracked.string("DQMIO.root") diff --git a/IOPool/Streamer/plugins/ParameterSetBlobProducer.cc b/IOPool/Streamer/plugins/ParameterSetBlobProducer.cc index 796cc0e643cf1..46c555ada1f2b 100644 --- a/IOPool/Streamer/plugins/ParameterSetBlobProducer.cc +++ b/IOPool/Streamer/plugins/ParameterSetBlobProducer.cc @@ -15,7 +15,10 @@ class ParameterSetBlobProducer : public edm::global::EDProducer> const token_; diff --git a/IOPool/Streamer/src/StreamerOutputModuleBase.cc b/IOPool/Streamer/src/StreamerOutputModuleBase.cc index 52234aebd25d4..dee1806980504 100644 --- a/IOPool/Streamer/src/StreamerOutputModuleBase.cc +++ b/IOPool/Streamer/src/StreamerOutputModuleBase.cc @@ -68,7 +68,7 @@ namespace edm { void StreamerOutputModuleBase::fillDescription(ParameterSetDescription& desc) { StreamerOutputModuleCommon::fillDescription(desc); OutputModule::fillDescription(desc); - desc.addUntracked("psetMap", {"psetMap"}) + desc.addUntracked("psetMap", {"hltPSetMap"}) ->setComment("Optionally allow the map of ParameterSets to be calculated externally."); } } // namespace edm diff --git a/L1Trigger/TrackFindingTracklet/BuildFile.xml b/L1Trigger/TrackFindingTracklet/BuildFile.xml new file mode 100644 index 0000000000000..0d82ff22841b4 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/BuildFile.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h b/L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h new file mode 100644 index 0000000000000..f6367108d9ca4 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h @@ -0,0 +1,37 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_AllProjectionsMemory_h +#define L1Trigger_TrackFindingTracklet_interface_AllProjectionsMemory_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" + +#include +#include + +namespace trklet { + + class Settings; + class Tracklet; + + class AllProjectionsMemory : public MemoryBase { + public: + AllProjectionsMemory(std::string name, Settings const& settings, unsigned int iSector); + + ~AllProjectionsMemory() override = default; + + void addTracklet(Tracklet* tracklet) { tracklets_.push_back(tracklet); } + + unsigned int nTracklets() const { return tracklets_.size(); } + + const Tracklet* getTracklet(unsigned int i) const { return tracklets_[i]; } + + void clean() override { tracklets_.clear(); } + + void writeAP(bool first); + + private: + std::vector tracklets_; + + int layer_; + int disk_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h b/L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h new file mode 100644 index 0000000000000..c34601997b069 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h @@ -0,0 +1,37 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_AllStubsMemory_h +#define L1Trigger_TrackFindingTracklet_interface_AllStubsMemory_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" + +#include +#include +#include + +namespace trklet { + + class Settings; + class Stub; + class L1TStub; + + class AllStubsMemory : public MemoryBase { + public: + AllStubsMemory(std::string name, Settings const& settings, unsigned int iSector); + + ~AllStubsMemory() override = default; + + void addStub(const Stub* stub) { stubs_.push_back(stub); } + + unsigned int nStubs() const { return stubs_.size(); } + + const Stub* getStub(unsigned int i) const { return stubs_[i]; } + + void clean() override { stubs_.clear(); } + + void writeStubs(bool first); + + private: + std::vector stubs_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/Cabling.h b/L1Trigger/TrackFindingTracklet/interface/Cabling.h new file mode 100644 index 0000000000000..f835b0d446234 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/Cabling.h @@ -0,0 +1,39 @@ +// This class holds a list of stubs that are in a given layer and DCT region +#ifndef L1Trigger_TrackFindingTracklet_interface_Cabling_h +#define L1Trigger_TrackFindingTracklet_interface_Cabling_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/DTC.h" +#include "L1Trigger/TrackFindingTracklet/interface/DTCLink.h" + +#include +#include + +namespace trklet { + + class Settings; + + class Cabling { + public: + Cabling(std::string dtcconfig, std::string moduleconfig, Settings const& settings); + + ~Cabling() = default; + + const std::string& dtc(int layer, int ladder, int module) const; + + void addphi(const std::string& dtc, double phi, int layer, int module); + + void writephirange() const; + + std::vector DTCs() const; + + private: + Settings const& settings_; + std::vector links_; + std::map dtcranges_; + std::map dtcs_; + std::map > > modules_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h b/L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h new file mode 100644 index 0000000000000..96358051401c6 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h @@ -0,0 +1,38 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_CandidateMatchMemory_h +#define L1Trigger_TrackFindingTracklet_interface_CandidateMatchMemory_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" + +#include +#include +#include + +namespace trklet { + + class Settings; + class Stub; + class L1TStub; + class Tracklet; + + class CandidateMatchMemory : public MemoryBase { + public: + CandidateMatchMemory(std::string name, Settings const& settings, unsigned int iSector); + + ~CandidateMatchMemory() override = default; + + void addMatch(std::pair tracklet, const Stub* stub); + + unsigned int nMatches() const { return matches_.size(); } + + std::pair, const Stub*> getMatch(unsigned int i) { return matches_[i]; } + + void clean() override { matches_.clear(); } + + void writeCM(bool first); + + private: + std::vector, const Stub*> > matches_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h b/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h new file mode 100644 index 0000000000000..50ed9aeae58f9 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h @@ -0,0 +1,63 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_CircularBuffer_h +#define L1Trigger_TrackFindingTracklet_interface_CircularBuffer_h + +#include +#include + +namespace trklet { + + template + class CircularBuffer { + public: + CircularBuffer(unsigned int nbits) { + size_ = 1 << nbits; + buffer_.resize(size_); + reset(); + } + + ~CircularBuffer() = default; + + void reset() { + rptr_ = 0; + wptr_ = 0; + } + + //Full if writer ptr incremented is same as read ptr + bool full() const { return ((wptr_ + 1) % size_) == rptr_; } + + //Almost full if writer ptr incremented by 1 or 2 is same as read ptr + bool almostfull() const { return (((wptr_ + 1) % size_) == rptr_) || (((wptr_ + 2) % size_) == rptr_); } + + //Empty buffer is write ptr is same as read ptr + bool empty() const { return wptr_ == rptr_; } + + T read() { + assert(!empty()); + unsigned int oldrptr = rptr_; + rptr_ = (rptr_ + 1) % size_; + return buffer_[oldrptr]; + } + + T peek() const { + assert(!empty()); + return buffer_[rptr_]; + } + + void store(T element) { + assert(!full()); + buffer_[wptr_++] = element; + wptr_ = wptr_ % size_; + } + + private: + std::vector buffer_; + + //buffer size + unsigned int size_; + + //read and write poiters into buffer + unsigned int rptr_; + unsigned int wptr_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/CleanTrackMemory.h b/L1Trigger/TrackFindingTracklet/interface/CleanTrackMemory.h new file mode 100644 index 0000000000000..41e64bd302f12 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/CleanTrackMemory.h @@ -0,0 +1,34 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_CleanTrackMemory_h +#define L1Trigger_TrackFindingTracklet_interface_CleanTrackMemory_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" + +#include + +namespace trklet { + + class Settings; + class Tracklet; + + class CleanTrackMemory : public MemoryBase { + public: + CleanTrackMemory(std::string name, Settings const& settings, unsigned int iSector, double phimin, double phimax); + + ~CleanTrackMemory() override = default; + + void addTrack(Tracklet* tracklet) { tracks_.push_back(tracklet); } + + unsigned int nTracks() const { return tracks_.size(); } + + void clean() override { tracks_.clear(); } + + void writeCT(bool first); + + private: + double phimin_; + double phimax_; + std::vector tracks_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/DTC.h b/L1Trigger/TrackFindingTracklet/interface/DTC.h new file mode 100644 index 0000000000000..bbdf38c07636b --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/DTC.h @@ -0,0 +1,46 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_DTC_h +#define L1Trigger_TrackFindingTracklet_interface_DTC_h + +#include "L1Trigger/TrackFindingTracklet/interface/DTCLink.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +namespace trklet { + + class Stub; + class L1TStub; + + class DTC { + public: + DTC(std::string name = ""); + + ~DTC() = default; + + void setName(std::string name); + + void addSec(int sector); + + void addphi(double phi, unsigned int layerdisk); + + void addLink(double phimin, double phimax); + + int addStub(std::pair stub); + + unsigned int nLinks() const { return links_.size(); } + + const DTCLink& link(unsigned int i) const { return links_[i]; } + + void clean(); + + double min(unsigned int i) const { return phimin_[i]; } + double max(unsigned int i) const { return phimax_[i]; } + + private: + std::string name_; + std::vector links_; + std::vector sectors_; + + double phimin_[N_LAYER + N_DISK]; + double phimax_[N_LAYER + N_DISK]; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/DTCLink.h b/L1Trigger/TrackFindingTracklet/interface/DTCLink.h new file mode 100644 index 0000000000000..d9f7a0c24bcf5 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/DTCLink.h @@ -0,0 +1,34 @@ +// This class holds a list of stubs that are in a given layer and DCT region +#ifndef L1Trigger_TrackFindingTracklet_interface_DTCLink_h +#define L1Trigger_TrackFindingTracklet_interface_DTCLink_h + +#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" + +namespace trklet { + + class DTCLink { + public: + DTCLink(double phimin, double phimax); + + ~DTCLink() = default; + + void addStub(std::pair stub); + + bool inRange(double phi, bool overlaplayer); + + unsigned int nStubs() const { return stubs_.size(); } + + Stub* getFPGAStub(unsigned int i) const { return stubs_[i].first; } + L1TStub* getL1TStub(unsigned int i) const { return stubs_[i].second; } + std::pair getStub(unsigned int i) const { return stubs_[i]; } + + void clean() { stubs_.clear(); } + + private: + double phimin_; + double phimax_; + std::vector > stubs_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/DiskProjection.h b/L1Trigger/TrackFindingTracklet/interface/DiskProjection.h new file mode 100644 index 0000000000000..83784c5ea042b --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/DiskProjection.h @@ -0,0 +1,168 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_DiskProjection_h +#define L1Trigger_TrackFindingTracklet_interface_DiskProjection_h + +#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" + +#include + +namespace trklet { + + class Settings; + + class DiskProjection { + public: + DiskProjection() { valid_ = false; } + + ~DiskProjection() = default; + + void init(Settings const& settings, + int projdisk, + double zproj, + int iphiproj, + int irproj, + int iphider, + int irder, + double phiproj, + double rproj, + double phiprojder, + double rprojder, + double phiprojapprox, + double rprojapprox, + double phiprojderapprox, + double rprojderapprox); + + bool valid() const { return valid_; } + + int projdisk() const { + assert(valid_); + return projdisk_; + }; + + double zproj() const { + assert(valid_); + return zproj_; + }; + + const FPGAWord& fpgaphiproj() const { + assert(valid_); + return fpgaphiproj_; + }; + + const FPGAWord& fpgarproj() const { + assert(valid_); + return fpgarproj_; + }; + + const FPGAWord& fpgaphiprojder() const { + assert(valid_); + return fpgaphiprojder_; + }; + + const FPGAWord& fpgarprojder() const { + assert(valid_); + return fpgarprojder_; + }; + + const FPGAWord& fpgaphiprojvm() const { + assert(valid_); + return fpgaphiprojvm_; + }; + + const FPGAWord& fpgarprojvm() const { + assert(valid_); + return fpgarprojvm_; + }; + + double phiproj() const { + assert(valid_); + return phiproj_; + }; + + const FPGAWord& fpgarbin1projvm() const { + assert(valid_); + return fpgarbin1projvm_; + }; + + const FPGAWord& fpgarbin2projvm() const { + assert(valid_); + return fpgarbin2projvm_; + }; + + const FPGAWord& fpgafinervm() const { + assert(valid_); + return fpgafinervm_; + }; + + double rproj() const { + assert(valid_); + return rproj_; + }; + + double phiprojder() const { + assert(valid_); + return phiprojder_; + }; + + double rprojder() const { + assert(valid_); + return rprojder_; + }; + + double phiprojapprox() const { + assert(valid_); + return phiprojapprox_; + }; + + double rprojapprox() const { + assert(valid_); + return rprojapprox_; + }; + + double phiprojderapprox() const { + assert(valid_); + return phiprojderapprox_; + }; + + double rprojderapprox() const { + assert(valid_); + return rprojderapprox_; + }; + + void setBendIndex(int bendindex) { fpgabendindex_.set(bendindex, 5, true, __LINE__, __FILE__); } + + const FPGAWord& getBendIndex() const { return fpgabendindex_; } + + protected: + bool valid_; + + int projdisk_; + + double zproj_; + + FPGAWord fpgaphiproj_; + FPGAWord fpgarproj_; + FPGAWord fpgaphiprojder_; + FPGAWord fpgarprojder_; + + FPGAWord fpgaphiprojvm_; + FPGAWord fpgarprojvm_; + + FPGAWord fpgarbin1projvm_; + FPGAWord fpgarbin2projvm_; + FPGAWord fpgafinervm_; + + FPGAWord fpgabendindex_; + + double phiproj_; + double rproj_; + double phiprojder_; + double rprojder_; + + double phiprojapprox_; + double rprojapprox_; + double phiprojderapprox_; + double rprojderapprox_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/DiskResidual.h b/L1Trigger/TrackFindingTracklet/interface/DiskResidual.h new file mode 100644 index 0000000000000..546410e5a78b7 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/DiskResidual.h @@ -0,0 +1,112 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_DiskResidual_h +#define L1Trigger_TrackFindingTracklet_interface_DiskResidual_h + +#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" + +#include + +namespace trklet { + + class Settings; + class Stub; + + class DiskResidual { + public: + DiskResidual() { valid_ = false; } + + ~DiskResidual() = default; + + void init(Settings const& settings, + int disk, + int iphiresid, + int irresid, + int istubid, + double phiresid, + double rresid, + double phiresidapprox, + double rresidapprox, + double zstub, + double alpha, + FPGAWord ialpha, + const Stub* stubptr); + + bool valid() const { return valid_; } + + const FPGAWord& fpgaphiresid() const { + assert(valid_); + return fpgaphiresid_; + }; + + const FPGAWord& fpgarresid() const { + assert(valid_); + return fpgarresid_; + }; + + const FPGAWord& fpgastubid() const { + assert(valid_); + return fpgastubid_; + }; + + double phiresid() const { + assert(valid_); + return phiresid_; + }; + + double rresid() const { + assert(valid_); + return rresid_; + }; + + double phiresidapprox() const { + assert(valid_); + return phiresidapprox_; + }; + + double rresidapprox() const { + assert(valid_); + return rresidapprox_; + }; + + double zstub() const { + assert(valid_); + return zstub_; + }; + + double alpha() const { + assert(valid_); + return alpha_; + }; + + const FPGAWord& ialpha() const { + assert(valid_); + return ialpha_; + }; + + const Stub* stubptr() const { + assert(valid_); + return stubptr_; + }; + + protected: + bool valid_; + + int disk_; + + FPGAWord fpgaphiresid_; + FPGAWord fpgarresid_; + FPGAWord fpgastubid_; + + double phiresid_; + double rresid_; + + double phiresidapprox_; + double rresidapprox_; + + double zstub_; + double alpha_; + FPGAWord ialpha_; + const Stub* stubptr_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/FPGAWord.h b/L1Trigger/TrackFindingTracklet/interface/FPGAWord.h new file mode 100644 index 0000000000000..c67842fbe64c5 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/FPGAWord.h @@ -0,0 +1,37 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_FPGAWord_h +#define L1Trigger_TrackFindingTracklet_interface_FPGAWord_h + +#include +#include + +namespace trklet { + + class FPGAWord { + public: + FPGAWord(); + + FPGAWord(int value, int nbits, bool positive = true, int line = -1, const char* file = nullptr); + + ~FPGAWord() = default; + + void set(int value, int nbits, bool positive = true, int line = -1, const char* file = nullptr); + + std::string str() const; + + //return the nbits starting with the lsb. lsb=0 means the least significant bit + unsigned int bits(unsigned int lsb, unsigned int nbit) const; + + int value() const { return value_; } + int nbits() const { return nbits_; } + + bool atExtreme() const; + + bool operator==(const FPGAWord& other) const; + + private: + int value_{-1}; + int nbits_{-1}; + bool positive_{true}; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/FitTrack.h b/L1Trigger/TrackFindingTracklet/interface/FitTrack.h new file mode 100644 index 0000000000000..fb897ec1660bd --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/FitTrack.h @@ -0,0 +1,54 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_FitTrack_H +#define L1Trigger_TrackFindingTracklet_interface_FitTrack_H + +#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackFitMemory.h" + +#include + +namespace trklet { + + class Settings; + class Globals; + class Stub; + class L1TStub; + + class FitTrack : public ProcessBase { + public: + FitTrack(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + + ~FitTrack() override = default; + + void addOutput(MemoryBase* memory, std::string output) override; + + void addInput(MemoryBase* memory, std::string input) override; + + // used if USEHYBRID is not defined + void trackFitChisq(Tracklet* tracklet, std::vector&, std::vector>&); + + // used if USEHYBRID is defined + void trackFitKF(Tracklet* tracklet, + std::vector& trackstublist, + std::vector>& stubidslist); + + // used for propagating tracklet without fitting + void trackFitFake(Tracklet* tracklet, std::vector&, std::vector>&); + + std::vector orderedMatches(std::vector& fullmatch); + + void execute(); + + private: + std::vector seedtracklet_; + std::vector fullmatch1_; + std::vector fullmatch2_; + std::vector fullmatch3_; + std::vector fullmatch4_; + + TrackFitMemory* trackfit_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h b/L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h new file mode 100644 index 0000000000000..10215946939c5 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h @@ -0,0 +1,46 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_FullMatchMemory_h +#define L1Trigger_TrackFindingTracklet_interface_FullMatchMemory_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" + +#include +#include +#include + +namespace trklet { + + class Settings; + class Stub; + class L1TStub; + class Tracklet; + + class FullMatchMemory : public MemoryBase { + public: + FullMatchMemory(std::string name, Settings const& settings, unsigned int iSector); + + ~FullMatchMemory() override = default; + + void addMatch(Tracklet* tracklet, const Stub* stub); + + unsigned int nMatches() const { return matches_.size(); } + + Tracklet* getTracklet(unsigned int i) { return matches_[i].first; } + + std::pair getMatch(unsigned int i) { return matches_[i]; } + + void clean() override { matches_.clear(); } + + void writeMC(bool first); + + int layer() const { return layer_; } + int disk() const { return disk_; } + + private: + std::vector > matches_; + + int layer_; + int disk_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/Globals.h b/L1Trigger/TrackFindingTracklet/interface/Globals.h new file mode 100644 index 0000000000000..cbe4eb2b4c4c9 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/Globals.h @@ -0,0 +1,116 @@ +// Globals: holds "global" variables such as the IMATH_TrackletCalculators +#ifndef L1Trigger_TrackFindingTracklet_interface_Globals_h +#define L1Trigger_TrackFindingTracklet_interface_Globals_h + +#include +#include +#include +#include +#include +#include +#include + +#ifdef USEHYBRID +#include "L1Trigger/TrackFindingTMTT/interface/KFParamsComb.h" +#include "L1Trigger/TrackFindingTMTT/interface/Settings.h" +#endif + +namespace trklet { + + class TETableBase; + class TrackDerTable; + class ProjectionRouterBendTable; + class SLHCEvent; + class HistBase; + class Settings; + class VMRouterPhiCorrTable; + struct imathGlobals; + class IMATH_TrackletCalculator; + class IMATH_TrackletCalculatorDisk; + class IMATH_TrackletCalculatorOverlap; + + class Globals { + public: + Globals(Settings const& settings); + + ~Globals(); + + SLHCEvent*& event() { return theEvent_; } + + HistBase*& histograms() { return theHistBase_; } + + TrackDerTable*& trackDerTable() { return trackDerTable_; } + + VMRouterPhiCorrTable*& phiCorr(unsigned int layer) { return thePhiCorr_[layer]; } + + ProjectionRouterBendTable*& projectionRouterBendTable() { return projectionRouterBendTable_; } + + std::map >& ILindex() { return ILindex_; } + + std::map& layerdiskmap() { return layerdiskmap_; } + + IMATH_TrackletCalculator* ITC_L1L2() { return ITC_L1L2_.get(); } + IMATH_TrackletCalculator* ITC_L2L3() { return ITC_L2L3_.get(); } + IMATH_TrackletCalculator* ITC_L3L4() { return ITC_L3L4_.get(); } + IMATH_TrackletCalculator* ITC_L5L6() { return ITC_L5L6_.get(); } + + IMATH_TrackletCalculatorDisk* ITC_F1F2() { return ITC_F1F2_.get(); } + IMATH_TrackletCalculatorDisk* ITC_F3F4() { return ITC_F3F4_.get(); } + IMATH_TrackletCalculatorDisk* ITC_B1B2() { return ITC_B1B2_.get(); } + IMATH_TrackletCalculatorDisk* ITC_B3B4() { return ITC_B3B4_.get(); } + + IMATH_TrackletCalculatorOverlap* ITC_L1F1() { return ITC_L1F1_.get(); } + IMATH_TrackletCalculatorOverlap* ITC_L1B1() { return ITC_L1B1_.get(); } + IMATH_TrackletCalculatorOverlap* ITC_L2F1() { return ITC_L2F1_.get(); } + IMATH_TrackletCalculatorOverlap* ITC_L2B1() { return ITC_L2B1_.get(); } + + std::ofstream& ofstream(std::string fname); + +#ifdef USEHYBRID + std::unique_ptr& tmttSettings() { return tmttSettings_; } + std::unique_ptr& tmttKFParamsComb() { return tmttKFParamsComb_; } +#endif + + private: + std::unordered_map ofstreams_; + + std::unique_ptr imathGlobals_; + + // tracklet calculators + std::unique_ptr ITC_L1L2_; + std::unique_ptr ITC_L2L3_; + std::unique_ptr ITC_L3L4_; + std::unique_ptr ITC_L5L6_; + + std::unique_ptr ITC_F1F2_; + std::unique_ptr ITC_F3F4_; + std::unique_ptr ITC_B1B2_; + std::unique_ptr ITC_B3B4_; + + std::unique_ptr ITC_L1F1_; + std::unique_ptr ITC_L2F1_; + std::unique_ptr ITC_L1B1_; + std::unique_ptr ITC_L2B1_; + + SLHCEvent* theEvent_{nullptr}; + + HistBase* theHistBase_{nullptr}; + + TrackDerTable* trackDerTable_{nullptr}; + + ProjectionRouterBendTable* projectionRouterBendTable_{nullptr}; + +#ifdef USEHYBRID + std::unique_ptr tmttSettings_; + std::unique_ptr tmttKFParamsComb_; +#endif + + std::array thePhiCorr_{{nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}}; + + std::map > ILindex_; + + std::map layerdiskmap_; + }; +}; // namespace trklet + +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/HistBase.h b/L1Trigger/TrackFindingTracklet/interface/HistBase.h new file mode 100644 index 0000000000000..999d94a026da3 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/HistBase.h @@ -0,0 +1,54 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_HistBase_h +#define L1Trigger_TrackFindingTracklet_interface_HistBase_h + +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +#include +#include +#include +#include +#include +#include + +namespace trklet { + class Globals; + + class HistBase { + public: + HistBase() {} + + virtual ~HistBase() = default; + + virtual void open() {} + virtual void close() {} + + virtual void bookLayerResidual() {} + virtual void bookDiskResidual() {} + virtual void bookTrackletParams() {} + virtual void bookSeedEff() {} + + virtual void FillLayerResidual(int, int, double, double, double, double, bool) {} + + virtual void FillDiskResidual(int, int, double, double, double, double, bool) {} + + //arguments are + // int seedIndex + // int iSector + // double irinv, rinv + // double iphi0, phi0 + // double ieta, eta + // double iz0, z0 + // int tp + virtual void fillTrackletParams( + Settings const&, Globals*, int, int, double, double, double, double, double, double, double, double, int) {} + + //int seedIndex + //double etaTP + //bool eff + virtual void fillSeedEff(int, double, bool) {} + + private: + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/HybridFit.h b/L1Trigger/TrackFindingTracklet/interface/HybridFit.h new file mode 100644 index 0000000000000..5ca9437e8189e --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/HybridFit.h @@ -0,0 +1,45 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_HybridFit_h +#define L1Trigger_TrackFindingTracklet_interface_HybridFit_h + +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" + +#ifdef USEHYBRID +#include "DataFormats/L1TrackTrigger/interface/TTStub.h" +#include "DataFormats/L1TrackTrigger/interface/TTCluster.h" +#include "SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h" +#include "SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h" +#include "L1Trigger/TrackFindingTMTT/interface/L1track3D.h" +#include "L1Trigger/TrackFindingTMTT/interface/Stub.h" +#include "L1Trigger/TrackFindingTMTT/interface/KFParamsComb.h" +#include "L1Trigger/TrackFindingTMTT/interface/Settings.h" +#include "L1Trigger/TrackFindingTMTT/interface/L1fittedTrack.h" +#include "L1Trigger/TrackFindingTMTT/interface/KFTrackletTrack.h" +#endif + +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +#include + +namespace trklet { + + class Stub; + class L1TStub; + class Tracklet; + + class HybridFit { + public: + HybridFit(unsigned int iSector, Settings const& settings, Globals* globals); + + ~HybridFit() = default; + + void Fit(Tracklet* tracklet, std::vector& trackstublist); + + private: + unsigned int iSector_; + + Settings const& settings_; + Globals* globals_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h b/L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h new file mode 100644 index 0000000000000..4a14ef1740ec8 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h @@ -0,0 +1,476 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_IMATH_TrackletCalculator_h +#define L1Trigger_TrackFindingTracklet_interface_IMATH_TrackletCalculator_h + +#include "Settings.h" +#include "imath.h" + +// +// Constants used: +// dphisector +// rmaxL6 +// zmaxD5 +// rmaxdisk +// kr, kphi1, kz +// +// rmean[], zmean[] + +namespace trklet { + class Globals; + + class IMATH_TrackletCalculator { + public: + IMATH_TrackletCalculator(Settings const& settings, imathGlobals* globals, int i1, int i2) + : settings_(settings), globals_(globals) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "============================================="; + char s[1024]; + snprintf(s, 1024, "IMATH Tracklet Calculator %i %i dphisector = %f", i1, i2, settings_.dphisector()); + edm::LogVerbatim("Tracklet") << s; + snprintf(s, 1024, "rmaxL6 = %f, zmaxD5 = %f", settings_.rmax(5), settings_.zmax(4)); + edm::LogVerbatim("Tracklet") << s; + snprintf( + s, 1024, " stub Ks: kr, kphi1, kz = %g, %g, %g", settings_.kr(), settings_.kphi1(), settings_.kz()); + edm::LogVerbatim("Tracklet") << s; + snprintf(s, + 1024, + " tracklet Ks: krinvpars, kphi0pars, ktpars, kzpars = %g, %g, %g, %g", + settings_.kphi1() / settings_.kr() * pow(2, settings_.rinv_shift()), + settings_.kphi1() * pow(2, settings_.phi0_shift()), + settings_.kz() / settings_.kr() * pow(2, settings_.t_shift()), + settings_.kz() * pow(2, settings_.z0_shift())); + edm::LogVerbatim("Tracklet") << s; + snprintf(s, + 1024, + "layer proj Ks: kphiproj456, kphider, kzproj, kzder = %g, %g, %g, %g", + settings_.kphi1() * pow(2, settings_.SS_phiL_shift()), + settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderL_shift()), + settings_.kz() * pow(2, settings_.PS_zL_shift()), + settings_.kz() / settings_.kr() * pow(2, settings_.PS_zderL_shift())); + edm::LogVerbatim("Tracklet") << s; + snprintf(s, + 1024, + " disk proj Ks: kphiprojdisk, kphiprojderdisk, krprojdisk, krprojderdisk = %g, %g, %g, %g", + settings_.kphi1() * pow(2, settings_.SS_phiD_shift()), + settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderD_shift()), + settings_.kr() * pow(2, settings_.PS_rD_shift()), + settings_.kr() / settings_.kz() * pow(2, settings_.PS_rderD_shift())); + edm::LogVerbatim("Tracklet") << s; + edm::LogVerbatim("Tracklet") << "============================================="; + + snprintf(s, 1024, "initializing 1/dr LUT %f %f", settings_.rmean(i1 - 1), settings_.rmean(i2 - 1)); + edm::LogVerbatim("Tracklet") << s; + } + + drinv.initLUT(settings_.rmean(i2 - 1) - settings_.rmean(i1 - 1)); + r1mean.set_fval(settings_.rmean(i1 - 1)); + r2mean.set_fval(settings_.rmean(i2 - 1)); + r12mean.set_fval(settings_.rmean(i1 - 1) + settings_.rmean(i2 - 1)); + + if (i1 == 1) + z0_final.add_cut(&z0_final_L1_cut); + else + z0_final.add_cut(&z0_final_cut); + + valid_phiL_0.add_cut(&t_layer_cut); + valid_phiL_1.add_cut(&t_layer_cut); + valid_phiL_2.add_cut(&t_layer_cut); + valid_phiL_3.add_cut(&t_layer_cut); + + valid_der_phiL.add_cut(&t_layer_cut); + + valid_zL_0.add_cut(&t_layer_cut); + valid_zL_1.add_cut(&t_layer_cut); + valid_zL_2.add_cut(&t_layer_cut); + valid_zL_3.add_cut(&t_layer_cut); + + valid_der_zL.add_cut(&t_layer_cut); + + valid_phiD_0.add_cut(&t_disk_cut_left); + valid_phiD_1.add_cut(&t_disk_cut_left); + valid_phiD_2.add_cut(&t_disk_cut_left); + valid_phiD_3.add_cut(&t_disk_cut_left); + valid_phiD_4.add_cut(&t_disk_cut_left); + + valid_der_phiD.add_cut(&t_disk_cut_left); + + valid_rD_0.add_cut(&t_disk_cut_left); + valid_rD_1.add_cut(&t_disk_cut_left); + valid_rD_2.add_cut(&t_disk_cut_left); + valid_rD_3.add_cut(&t_disk_cut_left); + valid_rD_4.add_cut(&t_disk_cut_left); + + valid_der_rD.add_cut(&t_disk_cut_left); + + valid_phiD_0.add_cut(&t_disk_cut_right); + valid_phiD_1.add_cut(&t_disk_cut_right); + valid_phiD_2.add_cut(&t_disk_cut_right); + valid_phiD_3.add_cut(&t_disk_cut_right); + valid_phiD_4.add_cut(&t_disk_cut_right); + + valid_der_phiD.add_cut(&t_disk_cut_right); + + valid_rD_0.add_cut(&t_disk_cut_right); + valid_rD_1.add_cut(&t_disk_cut_right); + valid_rD_2.add_cut(&t_disk_cut_right); + valid_rD_3.add_cut(&t_disk_cut_right); + valid_rD_4.add_cut(&t_disk_cut_right); + + valid_der_rD.add_cut(&t_disk_cut_right); + } + + ~IMATH_TrackletCalculator() = default; + + Settings const& settings_; + + imathGlobals* globals_; + + //max values + const double dz_max = 50.; + const double delta0_max = 0.005; + const double a2_max = 3.; + const double a2a_max = 0.1; + const double x6a_max = 0.02; + const double x6m_max = 2.; + const double x8_max = 1.; + const double x13_max = 300.; + const double x22_max = 0.3; + const double x23_max = 200.; + const double t_max = 4.; + const double z0_max = 20.; + const double der_phiD_max = 0.002; + const double t_disk_min = 1; + const double t_disk_max = 4; + const double t_layer_max = 2.5; + + //constants + VarParam plus1{globals_, "plus1", 1., 10}; + VarParam plus2{globals_, "plus2", 2., 10}; + VarParam minus1{globals_, "minus1", -1., 10}; + + VarParam r1mean{globals_, "r1mean", "Kr", settings_.rmax(trklet::N_LAYER - 1), settings_.kr()}; + VarParam r2mean{globals_, "r2mean", "Kr", settings_.rmax(trklet::N_LAYER - 1), settings_.kr()}; + VarParam r12mean{globals_, "r12mean", "Kr", 2 * settings_.rmax(trklet::N_DISK - 1), settings_.kr()}; + + //inputs + VarDef r1{globals_, "r1", "Kr", settings_.drmax(), settings_.kr()}; + VarDef r2{globals_, "r2", "Kr", settings_.drmax(), settings_.kr()}; + VarDef z1{globals_, "z1", "Kz", settings_.zlength(), settings_.kz()}; + VarDef z2{globals_, "z2", "Kz", settings_.zlength(), settings_.kz()}; + + //0.75 below comes from phi range for coordinate can be larger than for sector + VarDef phi1{globals_, "phi1", "Kphi", settings_.dphisector() / 0.75, settings_.kphi1()}; + VarDef phi2{globals_, "phi2", "Kphi", settings_.dphisector() / 0.75, settings_.kphi1()}; + + VarDef rproj0{globals_, "rproj0", "Kr", settings_.rmax(trklet::N_LAYER - 1), settings_.kr()}; + VarDef rproj1{globals_, "rproj1", "Kr", settings_.rmax(trklet::N_LAYER - 1), settings_.kr()}; + VarDef rproj2{globals_, "rproj2", "Kr", settings_.rmax(trklet::N_LAYER - 1), settings_.kr()}; + VarDef rproj3{globals_, "rproj3", "Kr", settings_.rmax(trklet::N_LAYER - 1), settings_.kr()}; + + VarDef zproj0{globals_, "zproj0", "Kz", settings_.zmax(trklet::N_DISK - 1), settings_.kz()}; + VarDef zproj1{globals_, "zproj1", "Kz", settings_.zmax(trklet::N_DISK - 1), settings_.kz()}; + VarDef zproj2{globals_, "zproj2", "Kz", settings_.zmax(trklet::N_DISK - 1), settings_.kz()}; + VarDef zproj3{globals_, "zproj3", "Kz", settings_.zmax(trklet::N_DISK - 1), settings_.kz()}; + VarDef zproj4{globals_, "zproj4", "Kz", settings_.zmax(trklet::N_DISK - 1), settings_.kz()}; + + //calculations + + //tracklet + VarAdd r1abs{globals_, "r1abs", &r1, &r1mean, settings_.rmax(trklet::N_LAYER - 1)}; + VarAdd r2abs{globals_, "r2abs", &r2, &r2mean, settings_.rmax(trklet::N_LAYER - 1)}; + + VarSubtract dr{globals_, "dr", &r2, &r1}; + + //R LUT + VarInv drinv{globals_, "drinv", &dr, 0, 18, 24, 0, VarInv::mode::both}; + + VarSubtract dphi{globals_, "dphi", &phi2, &phi1, settings_.dphisector() / 4.}; + VarSubtract dz{globals_, "dz", &z2, &z1, dz_max}; + + VarMult delta0{globals_, "delta0", &dphi, &drinv, delta0_max}; + VarMult deltaZ{globals_, "deltaZ", &dz, &drinv}; + VarMult delta1{globals_, "delta1", &r1abs, &delta0}; + VarMult delta2{globals_, "delta2", &r2abs, &delta0}; + VarMult a2a{globals_, "a2a", &delta1, &delta2, a2a_max}; + VarNounits a2b{globals_, "a2b", &a2a}; + VarSubtract a2{globals_, "a2", &plus2, &a2b, a2_max}; + VarNeg a2n{globals_, "a2n", &a2}; + VarShift a{globals_, "a", &a2, 1}; + + VarAdd Rabs{globals_, "Rabs", &r1abs, &r2abs}; + VarTimesC R6{globals_, "R6", &Rabs, 1. / 6., 12}; + + VarMult x4{globals_, "x4", &R6, &delta0}; + VarMult x6a{globals_, "x6a", &delta2, &x4, 2 * x6a_max}; + VarNounits x6b{globals_, "x6b", &x6a}; + VarAdd x6m{globals_, "x6m", &minus1, &x6b, x6m_max}; + VarMult phi0a{globals_, "phi0a", &delta1, &x6m, settings_.dphisector()}; + + VarMult z0a{globals_, "z0a", &r1abs, &deltaZ, settings_.zlength()}; + VarMult z0b{globals_, "z0b", &z0a, &x6m, settings_.zlength()}; + + VarAdd phi0{globals_, "phi0", &phi1, &phi0a, 2 * settings_.dphisector()}; + VarMult rinv{globals_, "rinv", &a2n, &delta0, 2 * settings_.maxrinv()}; + VarMult t{globals_, "t", &a, &deltaZ, t_max}; + VarAdd z0{globals_, "z0", &z1, &z0b, 2 * z0_max}; + + VarAdjustK rinv_final{ + globals_, "rinv_final", &rinv, settings_.kphi1() / settings_.kr() * pow(2, settings_.rinv_shift())}; + VarAdjustK phi0_final{globals_, "phi0_final", &phi0, settings_.kphi1() * pow(2, settings_.phi0_shift())}; + VarAdjustKR t_final{globals_, "t_final", &t, settings_.kz() / settings_.kr() * pow(2, settings_.t_shift())}; + VarAdjustKR z0_final{globals_, "z0_final", &z0, settings_.kz() * pow(2, settings_.z0_shift())}; + + //projection to r + VarShift x2{globals_, "x2", &delta0, 1}; + + VarMult x1_0{globals_, "x1_0", &x2, &rproj0}; + VarMult x1_1{globals_, "x1_1", &x2, &rproj1}; + VarMult x1_2{globals_, "x1_2", &x2, &rproj2}; + VarMult x1_3{globals_, "x1_3", &x2, &rproj3}; + + VarMult x8_0{globals_, "x8_0", &x1_0, &a2n, x8_max}; + VarMult x8_1{globals_, "x8_1", &x1_1, &a2n, x8_max}; + VarMult x8_2{globals_, "x8_2", &x1_2, &a2n, x8_max}; + VarMult x8_3{globals_, "x8_3", &x1_3, &a2n, x8_max}; + + VarMult x12_0{globals_, "x12_0", &x8_0, &x8_0}; + VarMult x12_1{globals_, "x12_1", &x8_1, &x8_1}; + VarMult x12_2{globals_, "x12_2", &x8_2, &x8_2}; + VarMult x12_3{globals_, "x12_3", &x8_3, &x8_3}; + + VarNounits x12A_0{globals_, "x12A_0", &x12_0}; + VarNounits x12A_1{globals_, "x12A_1", &x12_1}; + VarNounits x12A_2{globals_, "x12A_2", &x12_2}; + VarNounits x12A_3{globals_, "x12A_3", &x12_3}; + + VarTimesC x20_0{globals_, "x20_0", &x12A_0, 1. / 6.}; + VarTimesC x20_1{globals_, "x20_1", &x12A_1, 1. / 6.}; + VarTimesC x20_2{globals_, "x20_2", &x12A_2, 1. / 6.}; + VarTimesC x20_3{globals_, "x20_3", &x12A_3, 1. / 6.}; + + VarAdd x10_0{globals_, "x10_0", &plus1, &x20_0}; + VarAdd x10_1{globals_, "x10_1", &plus1, &x20_1}; + VarAdd x10_2{globals_, "x10_2", &plus1, &x20_2}; + VarAdd x10_3{globals_, "x10_3", &plus1, &x20_3}; + + VarMult x22_0{globals_, "x22_0", &x8_0, &x10_0, 2 * x22_max}; + VarMult x22_1{globals_, "x22_1", &x8_1, &x10_1, 2 * x22_max}; + VarMult x22_2{globals_, "x22_2", &x8_2, &x10_2, 2 * x22_max}; + VarMult x22_3{globals_, "x22_3", &x8_3, &x10_3, 2 * x22_max}; + + VarSubtract phiL_0{globals_, "phiL_0", &phi0_final, &x22_0, -1, phi0_final.nbits() + 1}; + VarSubtract phiL_1{globals_, "phiL_1", &phi0_final, &x22_1, -1, phi0_final.nbits() + 1}; + VarSubtract phiL_2{globals_, "phiL_2", &phi0_final, &x22_2, -1, phi0_final.nbits() + 1}; + VarSubtract phiL_3{globals_, "phiL_3", &phi0_final, &x22_3, -1, phi0_final.nbits() + 1}; + + VarShift x3{globals_, "x3", &rinv, 1}; + VarNeg der_phiL{globals_, "der_phiL", &x3}; + + VarAdjustK phiL_0_final{globals_, "phiL_0_final", &phiL_0, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; + VarAdjustK phiL_1_final{globals_, "phiL_1_final", &phiL_1, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; + VarAdjustK phiL_2_final{globals_, "phiL_2_final", &phiL_2, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; + VarAdjustK phiL_3_final{globals_, "phiL_3_final", &phiL_3, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; + + VarAdjustK der_phiL_final{globals_, + "der_phiL_final", + &der_phiL, + settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderL_shift())}; + + VarMult x11_0{globals_, "x11_0", &rproj0, &t}; + VarMult x11_1{globals_, "x11_1", &rproj1, &t}; + VarMult x11_2{globals_, "x11_2", &rproj2, &t}; + VarMult x11_3{globals_, "x11_3", &rproj3, &t}; + + VarMult x23_0{globals_, "x23_0", &x11_0, &x10_0, 2 * x23_max}; + VarMult x23_1{globals_, "x23_1", &x11_1, &x10_1, 2 * x23_max}; + VarMult x23_2{globals_, "x23_2", &x11_2, &x10_2, 2 * x23_max}; + VarMult x23_3{globals_, "x23_3", &x11_3, &x10_3, 2 * x23_max}; + + VarAdd zL_0{globals_, "zL_0", &z0, &x23_0}; + VarAdd zL_1{globals_, "zL_1", &z0, &x23_1}; + VarAdd zL_2{globals_, "zL_2", &z0, &x23_2}; + VarAdd zL_3{globals_, "zL_3", &z0, &x23_3}; + + VarAdjustKR zL_0_final{globals_, "zL_0_final", &zL_0, settings_.kz() * pow(2, settings_.PS_zL_shift())}; + VarAdjustKR zL_1_final{globals_, "zL_1_final", &zL_1, settings_.kz() * pow(2, settings_.PS_zL_shift())}; + VarAdjustKR zL_2_final{globals_, "zL_2_final", &zL_2, settings_.kz() * pow(2, settings_.PS_zL_shift())}; + VarAdjustKR zL_3_final{globals_, "zL_3_final", &zL_3, settings_.kz() * pow(2, settings_.PS_zL_shift())}; + + VarAdjustK der_zL_final{ + globals_, "der_zL_final", &t_final, settings_.kz() / settings_.kr() * pow(2, settings_.PS_zderL_shift())}; + + //projection to z + // + VarInv invt{globals_, "invt", &t_final, 0., 18, 26, 1, VarInv::mode::both, 13}; + + VarMult x7{globals_, "x7", &x2, &a2}; + + VarSubtract x5_0{globals_, "x5_0", &zproj0, &z0}; + VarSubtract x5_1{globals_, "x5_1", &zproj1, &z0}; + VarSubtract x5_2{globals_, "x5_2", &zproj2, &z0}; + VarSubtract x5_3{globals_, "x5_3", &zproj3, &z0}; + VarSubtract x5_4{globals_, "x5_4", &zproj4, &z0}; + + VarMult x13_0{globals_, "x13_0", &x5_0, &invt, x13_max}; + VarMult x13_1{globals_, "x13_1", &x5_1, &invt, x13_max}; + VarMult x13_2{globals_, "x13_2", &x5_2, &invt, x13_max}; + VarMult x13_3{globals_, "x13_3", &x5_3, &invt, x13_max}; + VarMult x13_4{globals_, "x13_4", &x5_4, &invt, x13_max}; + + VarMult x25_0{globals_, "x25_0", &x13_0, &x7, 2 * settings_.dphisector()}; + VarMult x25_1{globals_, "x25_1", &x13_1, &x7, 2 * settings_.dphisector()}; + VarMult x25_2{globals_, "x25_2", &x13_2, &x7, 2 * settings_.dphisector()}; + VarMult x25_3{globals_, "x25_3", &x13_3, &x7, 2 * settings_.dphisector()}; + VarMult x25_4{globals_, "x25_4", &x13_4, &x7, 2 * settings_.dphisector()}; + + VarAdd phiD_0{globals_, "phiD_0", &phi0, &x25_0, 2 * settings_.dphisector()}; + VarAdd phiD_1{globals_, "phiD_1", &phi0, &x25_1, 2 * settings_.dphisector()}; + VarAdd phiD_2{globals_, "phiD_2", &phi0, &x25_2, 2 * settings_.dphisector()}; + VarAdd phiD_3{globals_, "phiD_3", &phi0, &x25_3, 2 * settings_.dphisector()}; + VarAdd phiD_4{globals_, "phiD_4", &phi0, &x25_4, 2 * settings_.dphisector()}; + + VarAdjustK phiD_0_final{globals_, "phiD_0_final", &phiD_0, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; + VarAdjustK phiD_1_final{globals_, "phiD_1_final", &phiD_1, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; + VarAdjustK phiD_2_final{globals_, "phiD_2_final", &phiD_2, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; + VarAdjustK phiD_3_final{globals_, "phiD_3_final", &phiD_3, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; + VarAdjustK phiD_4_final{globals_, "phiD_4_final", &phiD_4, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; + + VarMult der_phiD{globals_, "der_phiD", &x7, &invt, 4 * der_phiD_max}; + + VarAdjustK der_phiD_final{globals_, + "der_phiD_final", + &der_phiD, + settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderD_shift())}; + + VarMult x26_0{globals_, "x26_0", &x25_0, &x25_0}; + VarMult x26_1{globals_, "x26_1", &x25_1, &x25_1}; + VarMult x26_2{globals_, "x26_2", &x25_2, &x25_2}; + VarMult x26_3{globals_, "x26_3", &x25_3, &x25_3}; + VarMult x26_4{globals_, "x26_4", &x25_4, &x25_4}; + + VarNounits x26A_0{globals_, "x26A_0", &x26_0}; + VarNounits x26A_1{globals_, "x26A_1", &x26_1}; + VarNounits x26A_2{globals_, "x26A_2", &x26_2}; + VarNounits x26A_3{globals_, "x26A_3", &x26_3}; + VarNounits x26A_4{globals_, "x26A_4", &x26_4}; + + VarTimesC x9_0{globals_, "x9_0", &x26A_0, 1. / 6.}; + VarTimesC x9_1{globals_, "x9_1", &x26A_1, 1. / 6.}; + VarTimesC x9_2{globals_, "x9_2", &x26A_2, 1. / 6.}; + VarTimesC x9_3{globals_, "x9_3", &x26A_3, 1. / 6.}; + VarTimesC x9_4{globals_, "x9_4", &x26A_4, 1. / 6.}; + + VarSubtract x27m_0{globals_, "x27_0", &plus1, &x9_0}; + VarSubtract x27m_1{globals_, "x27_1", &plus1, &x9_1}; + VarSubtract x27m_2{globals_, "x27_2", &plus1, &x9_2}; + VarSubtract x27m_3{globals_, "x27_3", &plus1, &x9_3}; + VarSubtract x27m_4{globals_, "x27_4", &plus1, &x9_4}; + + VarMult rD_0{globals_, "rD_0", &x13_0, &x27m_0, 2 * settings_.rmaxdisk()}; + VarMult rD_1{globals_, "rD_1", &x13_1, &x27m_1, 2 * settings_.rmaxdisk()}; + VarMult rD_2{globals_, "rD_2", &x13_2, &x27m_2, 2 * settings_.rmaxdisk()}; + VarMult rD_3{globals_, "rD_3", &x13_3, &x27m_3, 2 * settings_.rmaxdisk()}; + VarMult rD_4{globals_, "rD_4", &x13_4, &x27m_4, 2 * settings_.rmaxdisk()}; + + VarAdjustK rD_0_final{globals_, "rD_0_final", &rD_0, settings_.kr() * pow(2, settings_.PS_rD_shift())}; + VarAdjustK rD_1_final{globals_, "rD_1_final", &rD_1, settings_.kr() * pow(2, settings_.PS_rD_shift())}; + VarAdjustK rD_2_final{globals_, "rD_2_final", &rD_2, settings_.kr() * pow(2, settings_.PS_rD_shift())}; + VarAdjustK rD_3_final{globals_, "rD_3_final", &rD_3, settings_.kr() * pow(2, settings_.PS_rD_shift())}; + VarAdjustK rD_4_final{globals_, "rD_4_final", &rD_4, settings_.kr() * pow(2, settings_.PS_rD_shift())}; + + VarAdjustK der_rD_final{ + globals_, "der_rD_final", &invt, settings_.kr() / settings_.kz() * pow(2, settings_.PS_rderD_shift())}; + + VarCut rinv_final_cut{globals_, &rinv_final, -settings_.rinvcut(), settings_.rinvcut()}; + // the following two are not associated with any variable yet; this is done + // in the constructor of this class since it depends on the layer + VarCut z0_final_L1_cut{globals_, -settings_.z0cut(), settings_.z0cut()}; + VarCut z0_final_cut{globals_, -1.5 * settings_.z0cut(), 1.5 * settings_.z0cut()}; + + VarCut r1abs_cut{globals_, &r1abs, -settings_.rmax(5), settings_.rmax(5)}; + VarCut r2abs_cut{globals_, &r2abs, -settings_.rmax(5), settings_.rmax(5)}; + VarCut dphi_cut{globals_, &dphi, -settings_.dphisector() / 4., settings_.dphisector() / 4.}; + VarCut dz_cut{globals_, &dz, -dz_max, dz_max}; + VarCut delta0_cut{globals_, &delta0, -delta0_max, delta0_max}; + VarCut a2a_cut{globals_, &a2a, -a2a_max, a2a_max}; + VarCut a2_cut{globals_, &a2, -a2_max, a2_max}; + VarCut x6a_cut{globals_, &x6a, -x6a_max, x6a_max}; + VarCut x6m_cut{globals_, &x6m, -x6m_max, x6m_max}; + VarCut phi0a_cut{globals_, &phi0a, -settings_.dphisector(), settings_.dphisector()}; + VarCut z0a_cut{globals_, &z0a, (-1) * settings_.zlength(), settings_.zlength()}; + VarCut phi0_cut{globals_, &phi0, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; + VarCut rinv_cut{globals_, &rinv, -settings_.maxrinv(), settings_.maxrinv()}; + VarCut t_cut{globals_, &t, -t_max, t_max}; + VarCut z0_cut{globals_, &z0, -z0_max, z0_max}; + VarCut x8_0_cut{globals_, &x8_0, -x8_max, x8_max}; + VarCut x8_1_cut{globals_, &x8_1, -x8_max, x8_max}; + VarCut x8_2_cut{globals_, &x8_2, -x8_max, x8_max}; + VarCut x8_3_cut{globals_, &x8_3, -x8_max, x8_max}; + VarCut x22_0_cut{globals_, &x22_0, -x22_max, x22_max}; + VarCut x22_1_cut{globals_, &x22_1, -x22_max, x22_max}; + VarCut x22_2_cut{globals_, &x22_2, -x22_max, x22_max}; + VarCut x22_3_cut{globals_, &x22_3, -x22_max, x22_max}; + VarCut x23_0_cut{globals_, &x23_0, -x23_max, x23_max}; + VarCut x23_1_cut{globals_, &x23_1, -x23_max, x23_max}; + VarCut x23_2_cut{globals_, &x23_2, -x23_max, x23_max}; + VarCut x23_3_cut{globals_, &x23_3, -x23_max, x23_max}; + VarCut x13_0_cut{globals_, &x13_0, -x13_max, x13_max}; + VarCut x13_1_cut{globals_, &x13_1, -x13_max, x13_max}; + VarCut x13_2_cut{globals_, &x13_2, -x13_max, x13_max}; + VarCut x13_3_cut{globals_, &x13_3, -x13_max, x13_max}; + VarCut x13_4_cut{globals_, &x13_4, -x13_max, x13_max}; + VarCut x25_0_cut{globals_, &x25_0, -settings_.dphisector(), settings_.dphisector()}; + VarCut x25_1_cut{globals_, &x25_1, -settings_.dphisector(), settings_.dphisector()}; + VarCut x25_2_cut{globals_, &x25_2, -settings_.dphisector(), settings_.dphisector()}; + VarCut x25_3_cut{globals_, &x25_3, -settings_.dphisector(), settings_.dphisector()}; + VarCut x25_4_cut{globals_, &x25_4, -settings_.dphisector(), settings_.dphisector()}; + VarCut phiD_0_cut{globals_, &phiD_0, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; + VarCut phiD_1_cut{globals_, &phiD_1, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; + VarCut phiD_2_cut{globals_, &phiD_2, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; + VarCut phiD_3_cut{globals_, &phiD_3, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; + VarCut phiD_4_cut{globals_, &phiD_4, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; + VarCut der_phiD_cut{globals_, &der_phiD, -der_phiD_max, der_phiD_max}; + VarCut rD_0_cut{globals_, &rD_0, -settings_.rmaxdisk(), settings_.rmaxdisk()}; + VarCut rD_1_cut{globals_, &rD_1, -settings_.rmaxdisk(), settings_.rmaxdisk()}; + VarCut rD_2_cut{globals_, &rD_2, -settings_.rmaxdisk(), settings_.rmaxdisk()}; + VarCut rD_3_cut{globals_, &rD_3, -settings_.rmaxdisk(), settings_.rmaxdisk()}; + VarCut rD_4_cut{globals_, &rD_4, -settings_.rmaxdisk(), settings_.rmaxdisk()}; + + VarCut t_disk_cut_left{globals_, &t, -t_disk_max, -t_disk_min}; + VarCut t_disk_cut_right{globals_, &t, t_disk_min, t_disk_max}; + VarCut t_layer_cut{globals_, &t, -t_layer_max, t_layer_max}; + + // the following flags are used to apply the cuts in TrackletCalculator + // and in the output Verilog + VarFlag valid_trackpar{globals_, "valid_trackpar", &rinv_final, &phi0_final, &t_final, &z0_final}; + + VarFlag valid_phiL_0{globals_, "valid_phiL_0", &phiL_0_final}; + VarFlag valid_phiL_1{globals_, "valid_phiL_1", &phiL_1_final}; + VarFlag valid_phiL_2{globals_, "valid_phiL_2", &phiL_2_final}; + VarFlag valid_phiL_3{globals_, "valid_phiL_3", &phiL_3_final}; + + VarFlag valid_zL_0{globals_, "valid_zL_0", &zL_0_final}; + VarFlag valid_zL_1{globals_, "valid_zL_1", &zL_1_final}; + VarFlag valid_zL_2{globals_, "valid_zL_2", &zL_2_final}; + VarFlag valid_zL_3{globals_, "valid_zL_3", &zL_3_final}; + + VarFlag valid_der_phiL{globals_, "valid_der_phiL", &der_phiL_final}; + VarFlag valid_der_zL{globals_, "valid_der_zL", &der_zL_final}; + + VarFlag valid_phiD_0{globals_, "valid_phiD_0", &phiD_0_final}; + VarFlag valid_phiD_1{globals_, "valid_phiD_1", &phiD_1_final}; + VarFlag valid_phiD_2{globals_, "valid_phiD_2", &phiD_2_final}; + VarFlag valid_phiD_3{globals_, "valid_phiD_3", &phiD_3_final}; + VarFlag valid_phiD_4{globals_, "valid_phiD_4", &phiD_4_final}; + + VarFlag valid_rD_0{globals_, "valid_rD_0", &rD_0_final}; + VarFlag valid_rD_1{globals_, "valid_rD_1", &rD_1_final}; + VarFlag valid_rD_2{globals_, "valid_rD_2", &rD_2_final}; + VarFlag valid_rD_3{globals_, "valid_rD_3", &rD_3_final}; + VarFlag valid_rD_4{globals_, "valid_rD_4", &rD_4_final}; + + VarFlag valid_der_phiD{globals_, "valid_der_phiD", &der_phiD_final}; + VarFlag valid_der_rD{globals_, "valid_der_rD", &der_rD_final}; + }; +}; // namespace trklet + +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorDisk.h b/L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorDisk.h new file mode 100644 index 0000000000000..351521be5ccea --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorDisk.h @@ -0,0 +1,406 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_IMATH_TrackletCalculatorDisk_h +#define L1Trigger_TrackFindingTracklet_interface_IMATH_TrackletCalculatorDisk_h + +#include "Settings.h" +#include "imath.h" + +// +// Constants used: +// dphisector +// rmaxL6 +// zmaxD5 +// rmaxdisk +// kr, kphi1, kz +// +// rmean[], zmean[] + +namespace trklet { + + class IMATH_TrackletCalculatorDisk { + public: + IMATH_TrackletCalculatorDisk(Settings const& settings, imathGlobals* globals, int i1, int i2) + : settings_(settings), globals_(globals) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "============================================="; + char s[1024]; + snprintf(s, 1024, "IMATH Tracklet Calculator for Disk %i %i dphisector = %f", i1, i2, settings_.dphisector()); + edm::LogVerbatim("Tracklet") << s; + snprintf(s, 1024, "rmaxL6 = %f, zmaxD5 = %f", settings_.rmax(5), settings_.zmax(4)); + edm::LogVerbatim("Tracklet") << s; + snprintf( + s, 1024, " stub Ks: kr, kphi1, kz = %g, %g, %g", settings_.kr(), settings_.kphi1(), settings_.kz()); + edm::LogVerbatim("Tracklet") << s; + snprintf(s, + 1024, + " tracklet Ks: krinvpars, kphi0pars, ktpars, kzpars = %g, %g, %g, %g", + settings_.kphi1() / settings_.kr() * pow(2, settings_.rinv_shift()), + settings_.kphi1() * pow(2, settings_.phi0_shift()), + settings_.kz() / settings_.kr() * pow(2, settings_.t_shift()), + settings_.kz() * pow(2, settings_.z0_shift())); + edm::LogVerbatim("Tracklet") << s; + snprintf(s, + 1024, + "layer proj Ks: kphiproj456, kphider, kzproj, kzder = %g, %g, %g, %g", + settings_.kphi1() * pow(2, settings_.SS_phiL_shift()), + settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderL_shift()), + settings_.kz() * pow(2, settings_.PS_zL_shift()), + settings_.kz() / settings_.kr() * pow(2, settings_.PS_zderL_shift())); + edm::LogVerbatim("Tracklet") << s; + snprintf(s, + 1024, + " disk proj Ks: kphiprojdisk, kphiprojderdisk, krprojdisk, krprojderdisk = %g, %g, %g, %g", + settings_.kphi1() * pow(2, settings_.SS_phiD_shift()), + settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderD_shift()), + settings_.kr() * pow(2, settings_.PS_rD_shift()), + settings_.kr() / settings_.kz() * pow(2, settings_.PS_rderD_shift())); + edm::LogVerbatim("Tracklet") << s; + edm::LogVerbatim("Tracklet") << "============================================="; + } + + z1mean.set_fval(settings_.zmean(abs(i1) - 1)); + z2mean.set_fval(settings_.zmean(abs(i2) - 1)); + + if (i2 < 0) { //t is negative + z1mean.set_fval(-settings_.zmean(abs(i1) - 1)); + z2mean.set_fval(-settings_.zmean(abs(i2) - 1)); + invt.set_mode(VarInv::mode::neg); + invt.initLUT(0.); + } + + valid_phiL_0.add_cut(&t_layer_cut); + valid_phiL_1.add_cut(&t_layer_cut); + valid_phiL_2.add_cut(&t_layer_cut); + + valid_der_phiL.add_cut(&t_layer_cut); + + valid_zL_0.add_cut(&t_layer_cut); + valid_zL_1.add_cut(&t_layer_cut); + valid_zL_2.add_cut(&t_layer_cut); + + valid_der_zL.add_cut(&t_layer_cut); + + valid_phiD_0.add_cut(&t_disk_cut_left); + valid_phiD_1.add_cut(&t_disk_cut_left); + valid_phiD_2.add_cut(&t_disk_cut_left); + + valid_der_phiD.add_cut(&t_disk_cut_left); + + valid_rD_0.add_cut(&t_disk_cut_left); + valid_rD_1.add_cut(&t_disk_cut_left); + valid_rD_2.add_cut(&t_disk_cut_left); + + valid_der_rD.add_cut(&t_disk_cut_left); + + valid_phiD_0.add_cut(&t_disk_cut_right); + valid_phiD_1.add_cut(&t_disk_cut_right); + valid_phiD_2.add_cut(&t_disk_cut_right); + + valid_der_phiD.add_cut(&t_disk_cut_right); + + valid_rD_0.add_cut(&t_disk_cut_right); + valid_rD_1.add_cut(&t_disk_cut_right); + valid_rD_2.add_cut(&t_disk_cut_right); + + valid_der_rD.add_cut(&t_disk_cut_right); + } + + ~IMATH_TrackletCalculatorDisk() = default; + + Settings const& settings_; + + imathGlobals* globals_; + + //max values + const double dz_max = 50.; + const double dr_max = 20.; + const double delta0_max = 0.005; + const double a2_max = 3.; + const double a2a_max = 0.1; + const double x6a_max = 0.02; + const double x6m_max = 2.; + const double x8_max = 1.; + const double x13_max = 300.; + const double x22_max = 0.3; + const double x23_max = 200.; + const double deltaZ_max = 8.; + const double der_phiD_max = 0.002; + const double t_max = 7.9; + const double t_disk_min = 1.; + const double t_disk_max = 7.9; + const double t_layer_max = 2.5; + const double z0_max = 20.; + const double z0a_max = 205.; + + //constants + VarParam plus2{globals_, "plus2", 2., 10}; + VarParam plus1{globals_, "plus1", 1., 10}; + VarParam minus1{globals_, "minus1", -1, 10}; + + VarParam z1mean{globals_, "z1mean", "Kz", settings_.zmax(trklet::N_DISK - 1), settings_.kz()}; + VarParam z2mean{globals_, "z2mean", "Kz", settings_.zmax(trklet::N_DISK - 1), settings_.kz()}; + + //inputs + VarDef r1{globals_, "r1", "Kr", settings_.rmax(trklet::N_LAYER - 1), settings_.kr()}; + VarDef r2{globals_, "r2", "Kr", settings_.rmax(trklet::N_LAYER - 1), settings_.kr()}; + VarDef z1{globals_, "z1", "Kz", settings_.dzmax(), settings_.kz()}; + VarDef z2{globals_, "z2", "Kz", settings_.dzmax(), settings_.kz()}; + + VarDef phi1{globals_, "phi1", "Kphi", settings_.dphisector() / 0.75, settings_.kphi1()}; + VarDef phi2{globals_, "phi2", "Kphi", settings_.dphisector() / 0.75, settings_.kphi1()}; + + VarDef rproj0{globals_, "rproj0", "Kr", settings_.rmax(trklet::N_LAYER - 1), settings_.kr()}; + VarDef rproj1{globals_, "rproj1", "Kr", settings_.rmax(trklet::N_LAYER - 1), settings_.kr()}; + VarDef rproj2{globals_, "rproj2", "Kr", settings_.rmax(trklet::N_LAYER - 1), settings_.kr()}; + + VarDef zproj0{globals_, "zproj0", "Kz", settings_.zmax(trklet::N_DISK - 1), settings_.kz()}; + VarDef zproj1{globals_, "zproj1", "Kz", settings_.zmax(trklet::N_DISK - 1), settings_.kz()}; + VarDef zproj2{globals_, "zproj2", "Kz", settings_.zmax(trklet::N_DISK - 1), settings_.kz()}; + + //calculations + + //tracklet + VarAdd z1abs{globals_, "z1abs", &z1, &z1mean, settings_.zmax(trklet::N_DISK - 1)}; + VarAdd z2abs{globals_, "z2abs", &z2, &z2mean, settings_.zmax(trklet::N_DISK - 1)}; + + VarSubtract dr{globals_, "dr", &r2, &r1, dr_max}; + + //R LUT + VarInv drinv{globals_, "drinv", &dr, 0, 18, 23, 0, VarInv::mode::pos}; + + VarSubtract dphi{globals_, "dphi", &phi2, &phi1, settings_.dphisector() / 4.}; + VarSubtract dz{globals_, "dz", &z2abs, &z1abs, dz_max}; + + VarMult delta0{globals_, "delta0", &dphi, &drinv, 4 * delta0_max}; + VarMult deltaZ{globals_, "deltaZ", &dz, &drinv, deltaZ_max}; + VarMult delta1{globals_, "delta1", &r1, &delta0}; + VarMult delta2{globals_, "delta2", &r2, &delta0}; + VarMult a2a{globals_, "a2a", &delta1, &delta2, 4 * a2a_max}; + VarNounits a2b{globals_, "a2b", &a2a}; + VarSubtract a2{globals_, "a2", &plus2, &a2b, 3.}; + VarNeg a2n{globals_, "a2n", &a2}; + VarShift a{globals_, "a", &a2, 1}; + + VarAdd Rabs{globals_, "Rabs", &r1, &r2}; + VarTimesC R6{globals_, "R6", &Rabs, 1. / 6., 12}; + + VarMult x4{globals_, "x4", &R6, &delta0}; + VarMult x6a{globals_, "x6a", &delta2, &x4, 8 * x6a_max}; + VarNounits x6b{globals_, "x6b", &x6a}; + VarAdd x6m{globals_, "x6m", &minus1, &x6b, 2.}; + VarMult phi0a{globals_, "phi0a", &delta1, &x6m, settings_.dphisector()}; + + VarMult z0a{globals_, "z0a", &r1, &deltaZ, 2 * settings_.zlength()}; + VarMult z0b{globals_, "z0b", &z0a, &x6m, 2 * settings_.zlength()}; + + VarAdd phi0{globals_, "phi0", &phi1, &phi0a, 2 * settings_.dphisector()}; + VarMult rinv{globals_, "rinv", &a2n, &delta0, 4 * settings_.maxrinv()}; + VarMult t{globals_, "t", &a, &deltaZ, 2 * t_max}; + VarAdd z0{globals_, "z0", &z1abs, &z0b, 2 * z0_max}; + + VarAdjustK rinv_final{ + globals_, "rinv_final", &rinv, settings_.kphi1() / settings_.kr() * pow(2, settings_.rinv_shift())}; + VarAdjustK phi0_final{globals_, "phi0_final", &phi0, settings_.kphi1() * pow(2, settings_.phi0_shift())}; + VarAdjustK t_final{globals_, "t_final", &t, settings_.kz() / settings_.kr() * pow(2, settings_.t_shift())}; + VarAdjustK z0_final{globals_, "z0_final", &z0, settings_.kz() * pow(2, settings_.z0_shift())}; + + //projection to r + VarShift x2{globals_, "x2", &delta0, 1}; + + VarMult x1_0{globals_, "x1_0", &x2, &rproj0}; + VarMult x1_1{globals_, "x1_1", &x2, &rproj1}; + VarMult x1_2{globals_, "x1_2", &x2, &rproj2}; + + VarMult x8_0{globals_, "x8_0", &x1_0, &a2n, x8_max}; + VarMult x8_1{globals_, "x8_1", &x1_1, &a2n, x8_max}; + VarMult x8_2{globals_, "x8_2", &x1_2, &a2n, x8_max}; + + VarMult x12_0{globals_, "x12_0", &x8_0, &x8_0}; + VarMult x12_1{globals_, "x12_1", &x8_1, &x8_1}; + VarMult x12_2{globals_, "x12_2", &x8_2, &x8_2}; + + VarNounits x12A_0{globals_, "x12A_0", &x12_0}; + VarNounits x12A_1{globals_, "x12A_1", &x12_1}; + VarNounits x12A_2{globals_, "x12A_2", &x12_2}; + + VarTimesC x20_0{globals_, "x20_0", &x12A_0, 1. / 6.}; + VarTimesC x20_1{globals_, "x20_1", &x12A_1, 1. / 6.}; + VarTimesC x20_2{globals_, "x20_2", &x12A_2, 1. / 6.}; + + VarAdd x10_0{globals_, "x10_0", &plus1, &x20_0}; + VarAdd x10_1{globals_, "x10_1", &plus1, &x20_1}; + VarAdd x10_2{globals_, "x10_2", &plus1, &x20_2}; + + VarMult x22_0{globals_, "x22_0", &x8_0, &x10_0, 2 * x22_max}; + VarMult x22_1{globals_, "x22_1", &x8_1, &x10_1, 2 * x22_max}; + VarMult x22_2{globals_, "x22_2", &x8_2, &x10_2, 2 * x22_max}; + + VarSubtract phiL_0{globals_, "phiL_0", &phi0_final, &x22_0, -1, phi0_final.nbits() + 1}; + VarSubtract phiL_1{globals_, "phiL_1", &phi0_final, &x22_1, -1, phi0_final.nbits() + 1}; + VarSubtract phiL_2{globals_, "phiL_2", &phi0_final, &x22_2, -1, phi0_final.nbits() + 1}; + + VarShift x3{globals_, "x3", &rinv, 1}; + VarNeg der_phiL{globals_, "der_phiL", &x3}; + + VarAdjustK phiL_0_final{globals_, "phiL_0_final", &phiL_0, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; + VarAdjustK phiL_1_final{globals_, "phiL_1_final", &phiL_1, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; + VarAdjustK phiL_2_final{globals_, "phiL_2_final", &phiL_2, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; + + VarAdjustK der_phiL_final{globals_, + "der_phiL_final", + &der_phiL, + settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderL_shift())}; + + VarMult x11_0{globals_, "x11_0", &rproj0, &t}; + VarMult x11_1{globals_, "x11_1", &rproj1, &t}; + VarMult x11_2{globals_, "x11_2", &rproj2, &t}; + + VarMult x23_0{globals_, "x23_0", &x11_0, &x10_0, 4 * x23_max}; + VarMult x23_1{globals_, "x23_1", &x11_1, &x10_1, 4 * x23_max}; + VarMult x23_2{globals_, "x23_2", &x11_2, &x10_2, 4 * x23_max}; + + VarAdd zL_0{globals_, "zL_0", &z0, &x23_0}; + VarAdd zL_1{globals_, "zL_1", &z0, &x23_1}; + VarAdd zL_2{globals_, "zL_2", &z0, &x23_2}; + + VarAdjustK zL_0_final{globals_, "zL_0_final", &zL_0, settings_.kz() * pow(2, settings_.PS_zL_shift())}; + VarAdjustK zL_1_final{globals_, "zL_1_final", &zL_1, settings_.kz() * pow(2, settings_.PS_zL_shift())}; + VarAdjustK zL_2_final{globals_, "zL_2_final", &zL_2, settings_.kz() * pow(2, settings_.PS_zL_shift())}; + + VarAdjustK der_zL_final{ + globals_, "der_zL_final", &t_final, settings_.kz() / settings_.kr() * pow(2, settings_.PS_zderL_shift())}; + + //projection to z + VarInv invt{globals_, "invt", &t_final, 0., 18, 26, 1, VarInv::mode::pos, 13}; + + VarMult x7{globals_, "x7", &x2, &a2}; + + VarSubtract x5_0{globals_, "x5_0", &zproj0, &z0}; + VarSubtract x5_1{globals_, "x5_1", &zproj1, &z0}; + VarSubtract x5_2{globals_, "x5_2", &zproj2, &z0}; + + VarMult x13_0{globals_, "x13_0", &x5_0, &invt, x13_max}; + VarMult x13_1{globals_, "x13_1", &x5_1, &invt, x13_max}; + VarMult x13_2{globals_, "x13_2", &x5_2, &invt, x13_max}; + + VarMult x25_0{globals_, "x25_0", &x13_0, &x7, settings_.dphisector()}; + VarMult x25_1{globals_, "x25_1", &x13_1, &x7, settings_.dphisector()}; + VarMult x25_2{globals_, "x25_2", &x13_2, &x7, settings_.dphisector()}; + + VarAdd phiD_0{globals_, "phiD_0", &phi0, &x25_0, 2 * settings_.dphisector()}; + VarAdd phiD_1{globals_, "phiD_1", &phi0, &x25_1, 2 * settings_.dphisector()}; + VarAdd phiD_2{globals_, "phiD_2", &phi0, &x25_2, 2 * settings_.dphisector()}; + + VarAdjustK phiD_0_final{globals_, "phiD_0_final", &phiD_0, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; + VarAdjustK phiD_1_final{globals_, "phiD_1_final", &phiD_1, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; + VarAdjustK phiD_2_final{globals_, "phiD_2_final", &phiD_2, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; + + VarMult der_phiD{globals_, "der_phiD", &x7, &invt, 2 * der_phiD_max}; + + VarAdjustK der_phiD_final{globals_, + "der_phiD_final", + &der_phiD, + settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderD_shift())}; + + VarMult x26_0{globals_, "x26_0", &x25_0, &x25_0}; + VarMult x26_1{globals_, "x26_1", &x25_1, &x25_1}; + VarMult x26_2{globals_, "x26_2", &x25_2, &x25_2}; + + VarNounits x26A_0{globals_, "x26A_0", &x26_0}; + VarNounits x26A_1{globals_, "x26A_1", &x26_1}; + VarNounits x26A_2{globals_, "x26A_2", &x26_2}; + + VarTimesC x9_0{globals_, "x9_0", &x26A_0, 1. / 6.}; + VarTimesC x9_1{globals_, "x9_1", &x26A_1, 1. / 6.}; + VarTimesC x9_2{globals_, "x9_2", &x26A_2, 1. / 6.}; + + VarSubtract x27_0{globals_, "x27_0", &plus1, &x9_0}; + VarSubtract x27_1{globals_, "x27_1", &plus1, &x9_1}; + VarSubtract x27_2{globals_, "x27_2", &plus1, &x9_2}; + + VarMult rD_0{globals_, "rD_0", &x13_0, &x27_0, settings_.rmaxdisk()}; + VarMult rD_1{globals_, "rD_1", &x13_1, &x27_1, settings_.rmaxdisk()}; + VarMult rD_2{globals_, "rD_2", &x13_2, &x27_2, settings_.rmaxdisk()}; + + VarAdjustK rD_0_final{globals_, "rD_0_final", &rD_0, settings_.kr() * pow(2, settings_.PS_rD_shift())}; + VarAdjustK rD_1_final{globals_, "rD_1_final", &rD_1, settings_.kr() * pow(2, settings_.PS_rD_shift())}; + VarAdjustK rD_2_final{globals_, "rD_2_final", &rD_2, settings_.kr() * pow(2, settings_.PS_rD_shift())}; + + VarAdjustK der_rD_final{ + globals_, "der_rD_final", &invt, settings_.kr() / settings_.kz() * pow(2, settings_.PS_rderD_shift())}; + + VarCut rinv_final_cut{globals_, &rinv_final, -settings_.rinvcut(), settings_.rinvcut()}; + VarCut z0_final_cut{globals_, &z0_final, -settings_.z0cut(), settings_.z0cut()}; + + VarCut z1abs_cut{globals_, &z1abs, -settings_.zmax(4), settings_.zmax(4)}; + VarCut z2abs_cut{globals_, &z2abs, -settings_.zmax(4), settings_.zmax(4)}; + VarCut dr_cut{globals_, &dr, -dr_max, dr_max}; + VarCut dphi_cut{globals_, &dphi, -settings_.dphisector() / 4., settings_.dphisector() / 4.}; + VarCut dz_cut{globals_, &dz, -dz_max, dz_max}; + VarCut delta0_cut{globals_, &delta0, -delta0_max, delta0_max}; + VarCut deltaZ_cut{globals_, &deltaZ, -deltaZ_max, deltaZ_max}; + VarCut a2a_cut{globals_, &a2a, -a2a_max, a2a_max}; + VarCut a2_cut{globals_, &a2, -a2_max, a2_max}; + VarCut x6a_cut{globals_, &x6a, -x6a_max, x6a_max}; + VarCut x6m_cut{globals_, &x6m, -x6m_max, x6m_max}; + VarCut phi0a_cut{globals_, &phi0a, -settings_.dphisector(), settings_.dphisector()}; + VarCut z0a_cut{globals_, &z0a, -z0a_max, z0a_max}; + VarCut phi0_cut{globals_, &phi0, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; + VarCut rinv_cut{globals_, &rinv, -settings_.maxrinv(), settings_.maxrinv()}; + VarCut t_cut{globals_, &t, -t_max, t_max}; + VarCut z0_cut{globals_, &z0, -z0_max, z0_max}; + VarCut x8_0_cut{globals_, &x8_0, -x8_max, x8_max}; + VarCut x8_1_cut{globals_, &x8_1, -x8_max, x8_max}; + VarCut x8_2_cut{globals_, &x8_2, -x8_max, x8_max}; + VarCut x22_0_cut{globals_, &x22_0, -x22_max, x22_max}; + VarCut x22_1_cut{globals_, &x22_1, -x22_max, x22_max}; + VarCut x22_2_cut{globals_, &x22_2, -x22_max, x22_max}; + VarCut x23_0_cut{globals_, &x23_0, -x23_max, x23_max}; + VarCut x23_1_cut{globals_, &x23_1, -x23_max, x23_max}; + VarCut x23_2_cut{globals_, &x23_2, -x23_max, x23_max}; + VarCut x13_0_cut{globals_, &x13_0, -x13_max, x13_max}; + VarCut x13_1_cut{globals_, &x13_1, -x13_max, x13_max}; + VarCut x13_2_cut{globals_, &x13_2, -x13_max, x13_max}; + VarCut x25_0_cut{globals_, &x25_0, -settings_.dphisector(), settings_.dphisector()}; + VarCut x25_1_cut{globals_, &x25_1, -settings_.dphisector(), settings_.dphisector()}; + VarCut x25_2_cut{globals_, &x25_2, -settings_.dphisector(), settings_.dphisector()}; + VarCut phiD_0_cut{globals_, &phiD_0, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; + VarCut phiD_1_cut{globals_, &phiD_1, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; + VarCut phiD_2_cut{globals_, &phiD_2, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; + VarCut der_phiD_cut{globals_, &der_phiD, -der_phiD_max, der_phiD_max}; + VarCut rD_0_cut{globals_, &rD_0, -settings_.rmaxdisk(), settings_.rmaxdisk()}; + VarCut rD_1_cut{globals_, &rD_1, -settings_.rmaxdisk(), settings_.rmaxdisk()}; + VarCut rD_2_cut{globals_, &rD_2, -settings_.rmaxdisk(), settings_.rmaxdisk()}; + + VarCut t_disk_cut_left{globals_, &t, -t_disk_max, -t_disk_min}; + VarCut t_disk_cut_right{globals_, &t, t_disk_min, t_disk_max}; + VarCut t_layer_cut{globals_, &t, -t_layer_max, t_layer_max}; + + // the following flags are used to apply the cuts in TrackletCalculator + // and in the output Verilog + VarFlag valid_trackpar{globals_, "valid_trackpar", &rinv_final, &phi0_final, &t_final, &z0_final}; + + VarFlag valid_phiL_0{globals_, "valid_phiL_0", &phiL_0_final}; + VarFlag valid_phiL_1{globals_, "valid_phiL_1", &phiL_1_final}; + VarFlag valid_phiL_2{globals_, "valid_phiL_2", &phiL_2_final}; + + VarFlag valid_zL_0{globals_, "valid_zL_0", &zL_0_final}; + VarFlag valid_zL_1{globals_, "valid_zL_1", &zL_1_final}; + VarFlag valid_zL_2{globals_, "valid_zL_2", &zL_2_final}; + + VarFlag valid_der_phiL{globals_, "valid_der_phiL", &der_phiL_final}; + VarFlag valid_der_zL{globals_, "valid_der_zL", &der_zL_final}; + + VarFlag valid_phiD_0{globals_, "valid_phiD_0", &phiD_0_final}; + VarFlag valid_phiD_1{globals_, "valid_phiD_1", &phiD_1_final}; + VarFlag valid_phiD_2{globals_, "valid_phiD_2", &phiD_2_final}; + + VarFlag valid_rD_0{globals_, "valid_rD_0", &rD_0_final}; + VarFlag valid_rD_1{globals_, "valid_rD_1", &rD_1_final}; + VarFlag valid_rD_2{globals_, "valid_rD_2", &rD_2_final}; + + VarFlag valid_der_phiD{globals_, "valid_der_phiD", &der_phiD_final}; + VarFlag valid_der_rD{globals_, "valid_der_rD", &der_rD_final}; + }; +}; // namespace trklet + +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorOverlap.h b/L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorOverlap.h new file mode 100644 index 0000000000000..835ada017311a --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorOverlap.h @@ -0,0 +1,429 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_IMATH_TrackletCalculatorOverlap_h +#define L1Trigger_TrackFindingTracklet_interface_IMATH_TrackletCalculatorOverlap_h + +#include "Settings.h" +#include "imath.h" + +// +// Constants used: +// dphisector +// rmaxL6 +// zmaxD5 +// rmaxdisk +// kr, kphi1, kz +// +// rmean[], zmean[] + +namespace trklet { + + class IMATH_TrackletCalculatorOverlap { + public: + IMATH_TrackletCalculatorOverlap(Settings const& settings, imathGlobals* globals, int i1, int i2) + : settings_(settings), globals_(globals) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "============================================="; + char s[1024]; + snprintf( + s, 1024, "IMATH Tracklet Calculator for Overlap %i %i dphisector = %f", i1, i2, settings_.dphisector()); + edm::LogVerbatim("Tracklet") << s; + snprintf(s, 1024, "rmaxL6 = %f, zmaxD5 = %f", settings_.rmax(5), settings_.zmax(4)); + edm::LogVerbatim("Tracklet") << s; + snprintf( + s, 1024, " stub Ks: kr, kphi1, kz = %g, %g, %g", settings_.kr(), settings_.kphi1(), settings_.kz()); + edm::LogVerbatim("Tracklet") << s; + snprintf(s, + 1024, + " tracklet Ks: krinvpars, kphi0pars, ktpars, kzpars = %g, %g, %g, %g", + settings_.kphi1() / settings_.kr() * pow(2, settings_.rinv_shift()), + settings_.kphi1() * pow(2, settings_.phi0_shift()), + settings_.kz() / settings_.kr() * pow(2, settings_.t_shift()), + settings_.kz() * pow(2, settings_.z0_shift())); + edm::LogVerbatim("Tracklet") << s; + snprintf(s, + 1024, + "layer proj Ks: kphiproj456, kphider, kzproj, kzder = %g, %g, %g, %g", + settings_.kphi1() * pow(2, settings_.SS_phiL_shift()), + settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderL_shift()), + settings_.kz() * pow(2, settings_.PS_zL_shift()), + settings_.kz() / settings_.kr() * pow(2, settings_.PS_zderL_shift())); + edm::LogVerbatim("Tracklet") << s; + snprintf(s, + 1024, + " disk proj Ks: kphiprojdisk, kphiprojderdisk, krprojdisk, krprojderdisk = %g, %g, %g, %g", + settings_.kphi1() * pow(2, settings_.SS_phiD_shift()), + settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderD_shift()), + settings_.kr() * pow(2, settings_.PS_rD_shift()), + settings_.kr() / settings_.kz() * pow(2, settings_.PS_rderD_shift())); + edm::LogVerbatim("Tracklet") << s; + edm::LogVerbatim("Tracklet") << "============================================="; + } + + r1mean.set_fval(settings_.rmean(i1 - 1)); + z2mean.set_fval(settings_.zmean(abs(i2) - 1)); + + if (i2 < 0) { //t is negative + z2mean.set_fval(-settings_.zmean(abs(i2) - 1)); + invt.set_mode(VarInv::mode::neg); + invt.initLUT(0.); + } + + valid_phiL_0.add_cut(&t_layer_cut); + valid_phiL_1.add_cut(&t_layer_cut); + valid_phiL_2.add_cut(&t_layer_cut); + + valid_der_phiL.add_cut(&t_layer_cut); + + valid_zL_0.add_cut(&t_layer_cut); + valid_zL_1.add_cut(&t_layer_cut); + valid_zL_2.add_cut(&t_layer_cut); + + valid_der_zL.add_cut(&t_layer_cut); + + valid_phiD_0.add_cut(&t_disk_cut_left); + valid_phiD_1.add_cut(&t_disk_cut_left); + valid_phiD_2.add_cut(&t_disk_cut_left); + valid_phiD_3.add_cut(&t_disk_cut_left); + + valid_der_phiD.add_cut(&t_disk_cut_left); + + valid_rD_0.add_cut(&t_disk_cut_left); + valid_rD_1.add_cut(&t_disk_cut_left); + valid_rD_2.add_cut(&t_disk_cut_left); + valid_rD_3.add_cut(&t_disk_cut_left); + + valid_der_rD.add_cut(&t_disk_cut_left); + + valid_phiD_0.add_cut(&t_disk_cut_right); + valid_phiD_1.add_cut(&t_disk_cut_right); + valid_phiD_2.add_cut(&t_disk_cut_right); + valid_phiD_3.add_cut(&t_disk_cut_right); + + valid_der_phiD.add_cut(&t_disk_cut_right); + + valid_rD_0.add_cut(&t_disk_cut_right); + valid_rD_1.add_cut(&t_disk_cut_right); + valid_rD_2.add_cut(&t_disk_cut_right); + valid_rD_3.add_cut(&t_disk_cut_right); + + valid_der_rD.add_cut(&t_disk_cut_right); + } + + ~IMATH_TrackletCalculatorOverlap() = default; + + Settings const& settings_; + + imathGlobals* globals_; + + //max values + const double dz_max = 50.; + const double dr_max = 40; + const double delta0_max = 0.005; + const double a2_max = 3.; + const double a2a_max = 0.1; + const double x6a_max = 0.02; + const double x6m_max = 2.; + const double x8_max = 1.; + const double x13_max = 300.; + const double x22_max = 0.3; + const double x23_max = 200.; + const double deltaZ_max = 8.; + const double der_phiD_max = 0.002; + const double t_max = 7.9; + const double t_disk_min = 1.; + const double t_disk_max = 7.9; + const double t_layer_max = 2.5; + const double z0_max = 20.; + + // constants + // + VarParam plus2{globals_, "plus2", 2., 10}; + VarParam plus1{globals_, "plus1", 1., 10}; + VarParam minus1{globals_, "minus1", -1, 10}; + // + // + VarParam r1mean{globals_, "r1mean", "Kr", settings_.rmax(trklet::N_LAYER - 1), settings_.kr()}; + VarParam z2mean{globals_, "z2mean", "Kz", settings_.zmax(trklet::N_DISK - 1), settings_.kz()}; + + //inputs + VarDef r1{globals_, "r1", "Kr", settings_.drmax(), settings_.kr()}; + VarDef r2{globals_, "r2", "Kr", settings_.rmax(trklet::N_LAYER - 1), settings_.kr()}; + VarDef z1{globals_, "z1", "Kz", settings_.zlength(), settings_.kz()}; + VarDef z2{globals_, "z2", "Kz", settings_.dzmax(), settings_.kz()}; + + VarDef phi1{globals_, "phi1", "Kphi", settings_.dphisector() / 0.75, settings_.kphi1()}; + VarDef phi2{globals_, "phi2", "Kphi", settings_.dphisector() / 0.75, settings_.kphi1()}; + + VarDef rproj0{globals_, "rproj0", "Kr", settings_.rmax(trklet::N_LAYER - 1), settings_.kr()}; + VarDef rproj1{globals_, "rproj1", "Kr", settings_.rmax(trklet::N_LAYER - 1), settings_.kr()}; + VarDef rproj2{globals_, "rproj2", "Kr", settings_.rmax(trklet::N_LAYER - 1), settings_.kr()}; + + VarDef zproj0{globals_, "zproj0", "Kz", settings_.zmax(trklet::N_DISK - 1), settings_.kz()}; + VarDef zproj1{globals_, "zproj1", "Kz", settings_.zmax(trklet::N_DISK - 1), settings_.kz()}; + VarDef zproj2{globals_, "zproj2", "Kz", settings_.zmax(trklet::N_DISK - 1), settings_.kz()}; + VarDef zproj3{globals_, "zproj3", "Kz", settings_.zmax(trklet::N_DISK - 1), settings_.kz()}; + + //calculations + + //tracklet + VarAdd r1abs{globals_, "r1abs", &r1, &r1mean, settings_.rmax(trklet::N_LAYER - 1)}; + VarAdd z2abs{globals_, "z2abs", &z2, &z2mean, settings_.zmax(trklet::N_DISK - 1)}; + + VarSubtract dr{globals_, "dr", &r2, &r1abs, dr_max}; + + //R LUT + VarInv drinv{globals_, "drinv", &dr, 0, 18, 23, 0, VarInv::mode::pos}; + + VarSubtract dphi{globals_, "dphi", &phi2, &phi1, settings_.dphisector() / 4.}; + VarSubtract dz{globals_, "dz", &z2abs, &z1, 2 * dz_max}; + + VarMult delta0{globals_, "delta0", &dphi, &drinv, 8 * delta0_max}; + VarMult deltaZ{globals_, "deltaZ", &dz, &drinv, deltaZ_max}; + VarMult delta1{globals_, "delta1", &r1abs, &delta0}; + VarMult delta2{globals_, "delta2", &r2, &delta0}; + VarMult a2a{globals_, "a2a", &delta1, &delta2, 32 * a2a_max}; + VarNounits a2b{globals_, "a2b", &a2a}; + VarSubtract a2{globals_, "a2", &plus2, &a2b, a2_max}; + VarNeg a2n{globals_, "a2n", &a2}; + VarShift a{globals_, "a", &a2, 1}; + + VarAdd Rabs{globals_, "Rabs", &r1abs, &r2}; + VarTimesC R6{globals_, "R6", &Rabs, 1. / 6., 12}; + + VarMult x4{globals_, "x4", &R6, &delta0}; + VarMult x6a{globals_, "x6a", &delta2, &x4, 32 * x6a_max}; + VarNounits x6b{globals_, "x6b", &x6a}; + VarAdd x6m{globals_, "x6m", &minus1, &x6b, x6m_max}; + VarMult phi0a{globals_, "phi0a", &delta1, &x6m, settings_.dphisector()}; + + VarMult z0a{globals_, "z0a", &r1abs, &deltaZ, 2 * settings_.zlength()}; + VarMult z0b{globals_, "z0b", &z0a, &x6m, 2 * settings_.zlength()}; + + VarAdd phi0{globals_, "phi0", &phi1, &phi0a, 2 * settings_.dphisector()}; + VarMult rinv{globals_, "rinv", &a2n, &delta0, 8 * settings_.maxrinv()}; + VarMult t{globals_, "t", &a, &deltaZ, t_max}; + VarAdd z0{globals_, "z0", &z1, &z0b, 16 * z0_max}; + + VarAdjustK rinv_final{ + globals_, "rinv_final", &rinv, settings_.kphi1() / settings_.kr() * pow(2, settings_.rinv_shift())}; + VarAdjustK phi0_final{globals_, "phi0_final", &phi0, settings_.kphi1() * pow(2, settings_.phi0_shift())}; + VarAdjustK t_final{globals_, "t_final", &t, settings_.kz() / settings_.kr() * pow(2, settings_.t_shift())}; + VarAdjustK z0_final{globals_, "z0_final", &z0, settings_.kz() * pow(2, settings_.z0_shift())}; + + //projection to r + VarShift x2{globals_, "x2", &delta0, 1}; + + VarMult x1_0{globals_, "x1_0", &x2, &rproj0}; + VarMult x1_1{globals_, "x1_1", &x2, &rproj1}; + VarMult x1_2{globals_, "x1_2", &x2, &rproj2}; + + VarMult x8_0{globals_, "x8_0", &x1_0, &a2n, 2 * x8_max}; + VarMult x8_1{globals_, "x8_1", &x1_1, &a2n, 2 * x8_max}; + VarMult x8_2{globals_, "x8_2", &x1_2, &a2n, 2 * x8_max}; + + VarMult x12_0{globals_, "x12_0", &x8_0, &x8_0}; + VarMult x12_1{globals_, "x12_1", &x8_1, &x8_1}; + VarMult x12_2{globals_, "x12_2", &x8_2, &x8_2}; + + VarNounits x12A_0{globals_, "x12A_0", &x12_0}; + VarNounits x12A_1{globals_, "x12A_1", &x12_1}; + VarNounits x12A_2{globals_, "x12A_2", &x12_2}; + + VarTimesC x20_0{globals_, "x20_0", &x12A_0, 1. / 6.}; + VarTimesC x20_1{globals_, "x20_1", &x12A_1, 1. / 6.}; + VarTimesC x20_2{globals_, "x20_2", &x12A_2, 1. / 6.}; + + VarAdd x10_0{globals_, "x10_0", &plus1, &x20_0}; + VarAdd x10_1{globals_, "x10_1", &plus1, &x20_1}; + VarAdd x10_2{globals_, "x10_2", &plus1, &x20_2}; + + VarMult x22_0{globals_, "x22_0", &x8_0, &x10_0, 4 * x22_max}; + VarMult x22_1{globals_, "x22_1", &x8_1, &x10_1, 4 * x22_max}; + VarMult x22_2{globals_, "x22_2", &x8_2, &x10_2, 4 * x22_max}; + + VarSubtract phiL_0{globals_, "phiL_0", &phi0_final, &x22_0, -1, phi0_final.nbits() + 1}; + VarSubtract phiL_1{globals_, "phiL_1", &phi0_final, &x22_1, -1, phi0_final.nbits() + 1}; + VarSubtract phiL_2{globals_, "phiL_2", &phi0_final, &x22_2, -1, phi0_final.nbits() + 1}; + + VarShift x3{globals_, "x3", &rinv, 1}; + VarNeg der_phiL{globals_, "der_phiL", &x3}; + + VarAdjustK phiL_0_final{globals_, "phiL_0_final", &phiL_0, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; + VarAdjustK phiL_1_final{globals_, "phiL_1_final", &phiL_1, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; + VarAdjustK phiL_2_final{globals_, "phiL_2_final", &phiL_2, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; + + VarAdjustK der_phiL_final{globals_, + "der_phiL_final", + &der_phiL, + settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderL_shift())}; + + VarMult x11_0{globals_, "x11_0", &rproj0, &t}; + VarMult x11_1{globals_, "x11_1", &rproj1, &t}; + VarMult x11_2{globals_, "x11_2", &rproj2, &t}; + + VarMult x23_0{globals_, "x23_0", &x11_0, &x10_0, 2 * x23_max}; + VarMult x23_1{globals_, "x23_1", &x11_1, &x10_1, 2 * x23_max}; + VarMult x23_2{globals_, "x23_2", &x11_2, &x10_2, 2 * x23_max}; + + VarAdd zL_0{globals_, "zL_0", &z0, &x23_0}; + VarAdd zL_1{globals_, "zL_1", &z0, &x23_1}; + VarAdd zL_2{globals_, "zL_2", &z0, &x23_2}; + + VarAdjustK zL_0_final{globals_, "zL_0_final", &zL_0, settings_.kz() * pow(2, settings_.PS_zL_shift())}; + VarAdjustK zL_1_final{globals_, "zL_1_final", &zL_1, settings_.kz() * pow(2, settings_.PS_zL_shift())}; + VarAdjustK zL_2_final{globals_, "zL_2_final", &zL_2, settings_.kz() * pow(2, settings_.PS_zL_shift())}; + + VarAdjustK der_zL_final{ + globals_, "der_zL_final", &t_final, settings_.kz() / settings_.kr() * pow(2, settings_.PS_zderL_shift())}; + + //projection to z + VarInv invt{globals_, "invt", &t_final, 0., 18, 26, 1, VarInv::mode::pos, 13}; + + VarMult x7{globals_, "x7", &x2, &a2}; + + VarSubtract x5_0{globals_, "x5_0", &zproj0, &z0}; + VarSubtract x5_1{globals_, "x5_1", &zproj1, &z0}; + VarSubtract x5_2{globals_, "x5_2", &zproj2, &z0}; + VarSubtract x5_3{globals_, "x5_3", &zproj3, &z0}; + + VarMult x13_0{globals_, "x13_0", &x5_0, &invt, x13_max}; + VarMult x13_1{globals_, "x13_1", &x5_1, &invt, x13_max}; + VarMult x13_2{globals_, "x13_2", &x5_2, &invt, x13_max}; + VarMult x13_3{globals_, "x13_3", &x5_3, &invt, x13_max}; + + VarMult x25_0{globals_, "x25_0", &x13_0, &x7, 4 * settings_.dphisector()}; + VarMult x25_1{globals_, "x25_1", &x13_1, &x7, 4 * settings_.dphisector()}; + VarMult x25_2{globals_, "x25_2", &x13_2, &x7, 4 * settings_.dphisector()}; + VarMult x25_3{globals_, "x25_3", &x13_3, &x7, 4 * settings_.dphisector()}; + + VarAdd phiD_0{globals_, "phiD_0", &phi0, &x25_0, 4 * settings_.dphisector()}; + VarAdd phiD_1{globals_, "phiD_1", &phi0, &x25_1, 4 * settings_.dphisector()}; + VarAdd phiD_2{globals_, "phiD_2", &phi0, &x25_2, 4 * settings_.dphisector()}; + VarAdd phiD_3{globals_, "phiD_3", &phi0, &x25_3, 4 * settings_.dphisector()}; + + VarAdjustK phiD_0_final{globals_, "phiD_0_final", &phiD_0, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; + VarAdjustK phiD_1_final{globals_, "phiD_1_final", &phiD_1, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; + VarAdjustK phiD_2_final{globals_, "phiD_2_final", &phiD_2, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; + VarAdjustK phiD_3_final{globals_, "phiD_3_final", &phiD_3, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; + + VarMult der_phiD{globals_, "der_phiD", &x7, &invt, 8 * der_phiD_max}; + + VarAdjustK der_phiD_final{globals_, + "der_phiD_final", + &der_phiD, + settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderD_shift())}; + + VarMult x26_0{globals_, "x26_0", &x25_0, &x25_0}; + VarMult x26_1{globals_, "x26_1", &x25_1, &x25_1}; + VarMult x26_2{globals_, "x26_2", &x25_2, &x25_2}; + VarMult x26_3{globals_, "x26_3", &x25_3, &x25_3}; + + VarNounits x26A_0{globals_, "x26A_0", &x26_0}; + VarNounits x26A_1{globals_, "x26A_1", &x26_1}; + VarNounits x26A_2{globals_, "x26A_2", &x26_2}; + VarNounits x26A_3{globals_, "x26A_3", &x26_3}; + + VarTimesC x9_0{globals_, "x9_0", &x26A_0, 1. / 6.}; + VarTimesC x9_1{globals_, "x9_1", &x26A_1, 1. / 6.}; + VarTimesC x9_2{globals_, "x9_2", &x26A_2, 1. / 6.}; + VarTimesC x9_3{globals_, "x9_3", &x26A_3, 1. / 6.}; + + VarSubtract x27m_0{globals_, "x27_0", &plus1, &x9_0}; + VarSubtract x27m_1{globals_, "x27_1", &plus1, &x9_1}; + VarSubtract x27m_2{globals_, "x27_2", &plus1, &x9_2}; + VarSubtract x27m_3{globals_, "x27_3", &plus1, &x9_3}; + + VarMult rD_0{globals_, "rD_0", &x13_0, &x27m_0, settings_.rmaxdisk()}; + VarMult rD_1{globals_, "rD_1", &x13_1, &x27m_1, settings_.rmaxdisk()}; + VarMult rD_2{globals_, "rD_2", &x13_2, &x27m_2, settings_.rmaxdisk()}; + VarMult rD_3{globals_, "rD_3", &x13_3, &x27m_3, settings_.rmaxdisk()}; + + VarAdjustK rD_0_final{globals_, "rD_0_final", &rD_0, settings_.kr() * pow(2, settings_.PS_rD_shift())}; + VarAdjustK rD_1_final{globals_, "rD_1_final", &rD_1, settings_.kr() * pow(2, settings_.PS_rD_shift())}; + VarAdjustK rD_2_final{globals_, "rD_2_final", &rD_2, settings_.kr() * pow(2, settings_.PS_rD_shift())}; + VarAdjustK rD_3_final{globals_, "rD_3_final", &rD_3, settings_.kr() * pow(2, settings_.PS_rD_shift())}; + + VarAdjustK der_rD_final{ + globals_, "der_rD_final", &invt, settings_.kr() / settings_.kz() * pow(2, settings_.PS_rderD_shift())}; + + VarCut t_final_cut{globals_, &t_final, -10, 10}; + VarCut rinv_final_cut{globals_, &rinv_final, -settings_.rinvcut(), settings_.rinvcut()}; + VarCut z0_final_cut{globals_, &z0_final, -settings_.z0cut(), settings_.z0cut()}; + + VarCut r1abs_cut{globals_, &r1abs, -settings_.rmax(5), settings_.rmax(5)}; + VarCut z2abs_cut{globals_, &z2abs, -settings_.zmax(4), settings_.zmax(4)}; + VarCut dr_cut{globals_, &dr, -dr_max, dr_max}; + VarCut dphi_cut{globals_, &dphi, -settings_.dphisector() / 4., settings_.dphisector() / 4.}; + VarCut dz_cut{globals_, &dz, -dz_max, dz_max}; + VarCut delta0_cut{globals_, &delta0, -delta0_max, delta0_max}; + VarCut deltaZ_cut{globals_, &deltaZ, -deltaZ_max, deltaZ_max}; + VarCut a2a_cut{globals_, &a2a, -a2a_max, a2a_max}; + VarCut a2_cut{globals_, &a2, -a2_max, a2_max}; + VarCut x6a_cut{globals_, &x6a, -x6a_max, x6a_max}; + VarCut x6m_cut{globals_, &x6m, -x6m_max, x6m_max}; + VarCut phi0a_cut{globals_, &phi0a, -settings_.dphisector(), settings_.dphisector()}; + VarCut z0a_cut{globals_, &z0a, -2 * settings_.zlength(), 2 * settings_.zlength()}; + VarCut phi0_cut{globals_, &phi0, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; + VarCut rinv_cut{globals_, &rinv, -settings_.maxrinv(), settings_.maxrinv()}; + VarCut t_cut{globals_, &t, -t_max, t_max}; + VarCut z0_cut{globals_, &z0, -z0_max, z0_max}; + VarCut x8_0_cut{globals_, &x8_0, -x8_max, x8_max}; + VarCut x8_1_cut{globals_, &x8_1, -x8_max, x8_max}; + VarCut x8_2_cut{globals_, &x8_2, -x8_max, x8_max}; + VarCut x22_0_cut{globals_, &x22_0, -x22_max, x22_max}; + VarCut x22_1_cut{globals_, &x22_1, -x22_max, x22_max}; + VarCut x22_2_cut{globals_, &x22_2, -x22_max, x22_max}; + VarCut x23_0_cut{globals_, &x23_0, -x23_max, x23_max}; + VarCut x23_1_cut{globals_, &x23_1, -x23_max, x23_max}; + VarCut x23_2_cut{globals_, &x23_2, -x23_max, x23_max}; + VarCut x13_0_cut{globals_, &x13_0, -x13_max, x13_max}; + VarCut x13_1_cut{globals_, &x13_1, -x13_max, x13_max}; + VarCut x13_2_cut{globals_, &x13_2, -x13_max, x13_max}; + VarCut x13_3_cut{globals_, &x13_3, -x13_max, x13_max}; + VarCut x25_0_cut{globals_, &x25_0, -settings_.dphisector(), settings_.dphisector()}; + VarCut x25_1_cut{globals_, &x25_1, -settings_.dphisector(), settings_.dphisector()}; + VarCut x25_2_cut{globals_, &x25_2, -settings_.dphisector(), settings_.dphisector()}; + VarCut x25_3_cut{globals_, &x25_3, -settings_.dphisector(), settings_.dphisector()}; + VarCut phiD_0_cut{globals_, &phiD_0, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; + VarCut phiD_1_cut{globals_, &phiD_1, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; + VarCut phiD_2_cut{globals_, &phiD_2, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; + VarCut phiD_3_cut{globals_, &phiD_3, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; + VarCut der_phiD_cut{globals_, &der_phiD, -der_phiD_max, der_phiD_max}; + VarCut rD_0_cut{globals_, &rD_0, -settings_.rmaxdisk(), settings_.rmaxdisk()}; + VarCut rD_1_cut{globals_, &rD_1, -settings_.rmaxdisk(), settings_.rmaxdisk()}; + VarCut rD_2_cut{globals_, &rD_2, -settings_.rmaxdisk(), settings_.rmaxdisk()}; + VarCut rD_3_cut{globals_, &rD_3, -settings_.rmaxdisk(), settings_.rmaxdisk()}; + + VarCut t_disk_cut_left{globals_, &t, -t_disk_max, -t_disk_min}; + VarCut t_disk_cut_right{globals_, &t, t_disk_min, t_disk_max}; + VarCut t_layer_cut{globals_, &t, -t_layer_max, t_layer_max}; + + // the following flags are used to apply the cuts in TrackletCalculator + // and in the output Verilog + VarFlag valid_trackpar{globals_, "valid_trackpar", &rinv_final, &phi0_final, &t_final, &z0_final}; + + VarFlag valid_phiL_0{globals_, "valid_phiL_0", &phiL_0_final}; + VarFlag valid_phiL_1{globals_, "valid_phiL_1", &phiL_1_final}; + VarFlag valid_phiL_2{globals_, "valid_phiL_2", &phiL_2_final}; + + VarFlag valid_zL_0{globals_, "valid_zL_0", &zL_0_final}; + VarFlag valid_zL_1{globals_, "valid_zL_1", &zL_1_final}; + VarFlag valid_zL_2{globals_, "valid_zL_2", &zL_2_final}; + + VarFlag valid_der_phiL{globals_, "valid_der_phiL", &der_phiL_final}; + VarFlag valid_der_zL{globals_, "valid_der_zL", &der_zL_final}; + + VarFlag valid_phiD_0{globals_, "valid_phiD_0", &phiD_0_final}; + VarFlag valid_phiD_1{globals_, "valid_phiD_1", &phiD_1_final}; + VarFlag valid_phiD_2{globals_, "valid_phiD_2", &phiD_2_final}; + VarFlag valid_phiD_3{globals_, "valid_phiD_3", &phiD_3_final}; + + VarFlag valid_rD_0{globals_, "valid_rD_0", &rD_0_final}; + VarFlag valid_rD_1{globals_, "valid_rD_1", &rD_1_final}; + VarFlag valid_rD_2{globals_, "valid_rD_2", &rD_2_final}; + VarFlag valid_rD_3{globals_, "valid_rD_3", &rD_3_final}; + + VarFlag valid_der_phiD{globals_, "valid_der_phiD", &der_phiD_final}; + VarFlag valid_der_rD{globals_, "valid_der_rD", &der_rD_final}; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h b/L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h new file mode 100644 index 0000000000000..02879946c8eb7 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h @@ -0,0 +1,41 @@ +// This class holds a list of stubs for an input link. +// This modules 'owns' the pointers to the stubs. All subsequent modules that handles stubs uses a pointer to the original stored here. +#ifndef L1Trigger_TrackFindingTracklet_interface_InputLinkMemory_h +#define L1Trigger_TrackFindingTracklet_interface_InputLinkMemory_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" + +#include + +namespace trklet { + + class Settings; + class Globals; + class Stub; + class L1TStub; + class VMRouterPhiCorrTable; + + class InputLinkMemory : public MemoryBase { + public: + InputLinkMemory(std::string name, Settings const& settings, unsigned int iSector, double, double); + + ~InputLinkMemory() override = default; + + bool addStub(Settings const& settings, Globals* globals, L1TStub& al1stub, Stub& stub, std::string dtc); + + unsigned int nStubs() const { return stubs_.size(); } + + Stub* getStub(unsigned int i) { return stubs_[i]; } + + void writeStubs(bool first); + + void clean() override; + + private: + std::vector stubs_; + int phiregion_; + unsigned int layerdisk_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/L1TStub.h b/L1Trigger/TrackFindingTracklet/interface/L1TStub.h new file mode 100644 index 0000000000000..2010d1eae1bb6 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/L1TStub.h @@ -0,0 +1,122 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_L1TStub_h +#define L1Trigger_TrackFindingTracklet_interface_L1TStub_h + +#include +#include +#include +#include +#include + +namespace trklet { + + class L1TStub { + public: + L1TStub(); + L1TStub(int eventid, + std::vector tps, + int iphi, + int iz, + int layer, + int ladder, + int module, + int strip, + double x, + double y, + double z, + double sigmax, + double sigmaz, + double pt, + double bend, + int isPSmodule, + int isFlipped); + + ~L1TStub() = default; + + void write(std::ofstream& out); + void write(std::ostream& out); + + double diphi(); + + double iphiouter(); + + double diz(); + + unsigned int layer() const { return layer_; } + int disk() const { + if (z_ < 0.0) { + return -module_; + } + return module_; + } + unsigned int ladder() const { return ladder_; } + unsigned int module() const { return module_; } + + double x() const { return x_; } + double y() const { return y_; } + double z() const { return z_; } + double r() const { return std::hypot(x_, y_); } + double pt() const { return pt_; } + double r2() const { return x_ * x_ + y_ * y_; } + double bend() const { return bend_; } + + double phi() const { return atan2(y_, x_); } + + unsigned int iphi() const { return iphi_; } + unsigned int iz() const { return iz_; } + + void setiphi(int iphi) { iphi_ = iphi; } + void setiz(int iz) { iz_ = iz; } + + double sigmax() const { return sigmax_; } + double sigmaz() const { return sigmaz_; } + + bool operator==(const L1TStub& other) const; + + void lorentzcor(double shift); + + int eventid() const { return eventid_; } + std::vector tps() const { return tps_; } + + void setAllStubIndex(unsigned int index) { allstubindex_ = index; } + + unsigned int allStubIndex() const { return allstubindex_; } + + unsigned int strip() const { return strip_; } + + double alpha(double pitch) const; + + //Scaled to go between -1 and +1 + double alphanorm() const; + + void setXY(double x, double y); + + unsigned int isPSmodule() const { return isPSmodule_; } + unsigned int isFlipped() const { return isFlipped_; } + + bool isTilted() const; + + bool tpmatch(int tp) const; + + private: + int eventid_; + std::vector tps_; + unsigned int iphi_; + unsigned int iz_; + unsigned int layer_; + unsigned int ladder_; + unsigned int module_; + unsigned int strip_; + double x_; + double y_; + double z_; + double sigmax_; + double sigmaz_; + double pt_; + double bend_; + unsigned int allstubindex_; + + unsigned int isPSmodule_; + unsigned int isFlipped_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/LayerProjection.h b/L1Trigger/TrackFindingTracklet/interface/LayerProjection.h new file mode 100644 index 0000000000000..1b55b4e0b5f8c --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/LayerProjection.h @@ -0,0 +1,162 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_LayerProjection_h +#define L1Trigger_TrackFindingTracklet_interface_LayerProjection_h + +#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" + +namespace trklet { + + class Settings; + + class LayerProjection { + public: + LayerProjection() { valid_ = false; } + + ~LayerProjection() = default; + + void init(Settings const& settings, + int projlayer, + double rproj, + int iphiproj, + int izproj, + int iphider, + int izder, + double phiproj, + double zproj, + double phiprojder, + double zprojder, + double phiprojapprox, + double zprojapprox, + double phiprojderapprox, + double zprojderapprox); + + bool valid() const { return valid_; } + + int projlayer() const { + assert(valid_); + return projlayer_; + }; + + double rproj() const { + assert(valid_); + return rproj_; + }; + + const FPGAWord& fpgaphiproj() const { + assert(valid_); + return fpgaphiproj_; + }; + + const FPGAWord& fpgazproj() const { + assert(valid_); + return fpgazproj_; + }; + + const FPGAWord& fpgaphiprojder() const { + assert(valid_); + return fpgaphiprojder_; + }; + + const FPGAWord& fpgazprojder() const { + assert(valid_); + return fpgazprojder_; + }; + + const FPGAWord& fpgaphiprojvm() const { + assert(valid_); + return fpgaphiprojvm_; + }; + + const FPGAWord& fpgazbin1projvm() const { + assert(valid_); + return fpgazbin1projvm_; + }; + + const FPGAWord& fpgazbin2projvm() const { + assert(valid_); + return fpgazbin2projvm_; + }; + + const FPGAWord& fpgafinezvm() const { + assert(valid_); + return fpgafinezvm_; + }; + + const FPGAWord& fpgazprojvm() const { + assert(valid_); + return fpgazprojvm_; + }; + + double phiproj() const { + assert(valid_); + return phiproj_; + }; + + double zproj() const { + assert(valid_); + return zproj_; + }; + + double phiprojder() const { + assert(valid_); + return phiprojder_; + }; + + double zprojder() const { + assert(valid_); + return zprojder_; + }; + + double phiprojapprox() const { + assert(valid_); + return phiprojapprox_; + }; + + double zprojapprox() const { + assert(valid_); + return zprojapprox_; + }; + + double phiprojderapprox() const { + assert(valid_); + return phiprojderapprox_; + }; + + double zprojderapprox() const { + assert(valid_); + return zprojderapprox_; + }; + + protected: + bool valid_; + + int projlayer_; + + double rproj_; + + FPGAWord fpgaphiproj_; + FPGAWord fpgazproj_; + FPGAWord fpgaphiprojder_; + FPGAWord fpgazprojder_; + + FPGAWord fpgaphiprojvm_; + FPGAWord fpgazprojvm_; + + FPGAWord fpgazbin1projvm_; + FPGAWord fpgazbin2projvm_; + FPGAWord fpgafinezvm_; + + double phiproj_; + double zproj_; + double phiprojder_; + double zprojder_; + + double zbin1_; + double zbin2_; + + double phiprojapprox_; + double zprojapprox_; + double phiprojderapprox_; + double zprojderapprox_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/LayerResidual.h b/L1Trigger/TrackFindingTracklet/interface/LayerResidual.h new file mode 100644 index 0000000000000..1c2cf303ae479 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/LayerResidual.h @@ -0,0 +1,98 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_LayerResidual_h +#define L1Trigger_TrackFindingTracklet_interface_LayerResidual_h + +#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" + +#include + +namespace trklet { + + class Settings; + class Stub; + + class LayerResidual { + public: + LayerResidual() { valid_ = false; } + + ~LayerResidual() = default; + + void init(Settings const& settings, + int layer, + int iphiresid, + int izresid, + int istubid, + double phiresid, + double zresid, + double phiresidapprox, + double zresidapprox, + double rstub, + const Stub* stubptr); + + bool valid() const { return valid_; } + + const FPGAWord& fpgaphiresid() const { + assert(valid_); + return fpgaphiresid_; + }; + + const FPGAWord& fpgazresid() const { + assert(valid_); + return fpgazresid_; + }; + + const FPGAWord& fpgastubid() const { + assert(valid_); + return fpgastubid_; + }; + + double phiresid() const { + assert(valid_); + return phiresid_; + }; + + double zresid() const { + assert(valid_); + return zresid_; + }; + + double phiresidapprox() const { + assert(valid_); + return phiresidapprox_; + }; + + double zresidapprox() const { + assert(valid_); + return zresidapprox_; + }; + + double rstub() const { + assert(valid_); + return rstub_; + } + + const Stub* stubptr() const { + assert(valid_); + return stubptr_; + } + + protected: + bool valid_; + + int layer_; + + FPGAWord fpgaphiresid_; + FPGAWord fpgazresid_; + FPGAWord fpgastubid_; + + double phiresid_; + double zresid_; + + double phiresidapprox_; + double zresidapprox_; + + double rstub_; + const Stub* stubptr_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h b/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h new file mode 100644 index 0000000000000..16d95f9d85f33 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h @@ -0,0 +1,63 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_MatchCalculator_h +#define L1Trigger_TrackFindingTracklet_interface_MatchCalculator_h + +#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +#include +#include + +namespace trklet { + + class Globals; + class Stub; + class L1TStub; + class Tracklet; + class AllStubsMemory; + class AllProjectionsMemory; + class CandidateMatchMemory; + class FullMatchMemory; + + class MatchCalculator : public ProcessBase { + public: + MatchCalculator(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + + ~MatchCalculator() override = default; + + void addOutput(MemoryBase* memory, std::string output) override; + void addInput(MemoryBase* memory, std::string input) override; + + void execute(); + + std::vector, const Stub*> > mergeMatches( + std::vector& candmatch); + + private: + unsigned int layerdisk_; + unsigned int phiregion_; + + int fact_; + int icorrshift_; + int icorzshift_; + int phi0shift_; + double phioffset_; + + unsigned int phimatchcut_[N_SEED]; + unsigned int zmatchcut_[N_SEED]; + unsigned int rphicutPS_[N_SEED]; + unsigned int rphicut2S_[N_SEED]; + unsigned int rcutPS_[N_SEED]; + unsigned int rcut2S_[N_SEED]; + + int ialphafactinner_[N_DSS_MOD * 2]; + int ialphafactouter_[N_DSS_MOD * 2]; + + AllStubsMemory* allstubs_; + AllProjectionsMemory* allprojs_; + + std::vector matches_; + std::vector fullMatches_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h b/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h new file mode 100644 index 0000000000000..2457be5a0c09a --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h @@ -0,0 +1,45 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_MatchEngine_h +#define L1Trigger_TrackFindingTracklet_interface_MatchEngine_h + +#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" +#include + +namespace trklet { + + class Settings; + class Globals; + class MemoryBase; + class VMStubsMEMemory; + class VMProjectionsMemory; + class CandidateMatchMemory; + + class MatchEngine : public ProcessBase { + public: + MatchEngine(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + + ~MatchEngine() override = default; + + void addOutput(MemoryBase* memory, std::string output) override; + void addInput(MemoryBase* memory, std::string input) override; + + void execute(); + + private: + VMStubsMEMemory* vmstubs_; + VMProjectionsMemory* vmprojs_; + + CandidateMatchMemory* candmatches_; + + int layer_; + int disk_; + + //used in the layers + std::vector table_; + + //used in the disks + std::vector tablePS_; + std::vector table2S_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h b/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h new file mode 100644 index 0000000000000..b8bd055564db7 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h @@ -0,0 +1,72 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_MatchEngineUnit_h +#define L1Trigger_TrackFindingTracklet_interface_MatchEngineUnit_h + +#include "L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h" +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" + +#include +#include + +namespace trklet { + + class Settings; + class Stub; + class L1TStub; + + class MatchEngineUnit { + public: + MatchEngineUnit(bool barrel, std::vector table, std::vector tablePS, std::vector table2S); + + ~MatchEngineUnit() = default; + + void init(VMStubsMEMemory* vmstubsmemory, + unsigned int slot, + int projrinv, + int projfinerz, + int projfinephi, + bool isPSseed, + Tracklet* proj); + + bool empty() const { return candmatches_.empty(); } + + std::pair read() { return candmatches_.read(); } + + std::pair peek() const { return candmatches_.peek(); } + + Tracklet* currentProj() const { return proj_; } + + bool idle() const { return idle_; } + + void step(); + + private: + VMStubsMEMemory* vmstubsmemory_; + + //unsigned int memory slot + unsigned int slot_; + unsigned int istub_; + + bool barrel_; + int projrinv_; + int projfinerz_; + int projfinephi_; + bool isPSseed_; + Tracklet* proj_; + + bool idle_; + + //used in the layers + std::vector table_; + + //used in the disks + std::vector tablePS_; + std::vector table2S_; + + //save the candidate matches + CircularBuffer > candmatches_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h b/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h new file mode 100644 index 0000000000000..1ecdaa08ac872 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h @@ -0,0 +1,93 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_MatchProcessor_h +#define L1Trigger_TrackFindingTracklet_interface_MatchProcessor_h + +#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h" +#include "L1Trigger/TrackFindingTracklet/interface/ProjectionTemp.h" +#include "L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h" +#include "L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" + +#include + +namespace trklet { + + class Settings; + class Globals; + class MemoryBase; + class Stub; + class L1TStub; + class Tracklet; + + class MatchProcessor : public ProcessBase { + public: + MatchProcessor(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + + ~MatchProcessor() override = default; + + void addOutput(MemoryBase* memory, std::string output) override; + void addInput(MemoryBase* memory, std::string input) override; + + void execute(); + + bool matchCalculator(Tracklet* tracklet, const Stub* fpgastub); + + private: + int layer_; + int disk_; + bool barrel_; + + unsigned int phiregion_; + + int nvm_; //VMs in sector + int nvmbits_; //# of bits for VMs in sector + int nvmbins_; //VMs in in phi region + + int fact_; + int icorrshift_; + int icorzshift_; + int phi0shift_; + + double phioffset_; + + unsigned int phimatchcut_[N_SEED]; + unsigned int zmatchcut_[N_SEED]; + + unsigned int rphicutPS_[N_SEED]; + unsigned int rphicut2S_[N_SEED]; + unsigned int rcutPS_[N_SEED]; + unsigned int rcut2S_[N_SEED]; + + double phifact_; + double rzfact_; + + int nrbits_; + int nphiderbits_; + + AllStubsMemory* allstubs_; + std::vector vmstubs_; + std::vector inputprojs_; + + int ialphafactinner_[N_DSS_MOD * 2]; + int ialphafactouter_[N_DSS_MOD * 2]; + + //Memory for the full matches + std::vector fullmatches_; + + //used in the layers + std::vector table_; + + //used in the disks + std::vector tablePS_; + std::vector table2S_; + + unsigned int nMatchEngines_; + std::vector matchengines_; + + CircularBuffer inputProjBuffer_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/MemoryBase.h b/L1Trigger/TrackFindingTracklet/interface/MemoryBase.h new file mode 100644 index 0000000000000..c2a5a009e5454 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/MemoryBase.h @@ -0,0 +1,51 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_MemoryBase_h +#define L1Trigger_TrackFindingTracklet_interface_MemoryBase_h + +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +#include +#include +#include +#include + +namespace trklet { + + class MemoryBase { + public: + MemoryBase(std::string name, Settings const& settings, unsigned int iSector); + + virtual ~MemoryBase() = default; + + std::string const& getName() const { return name_; } + std::string getLastPartOfName() const { return name_.substr(name_.find_last_of('_') + 1); } + + virtual void clean() = 0; + + //method sets the layer and disk based on the name. pos is the position in the memory name where the layer or disk is specified + void initLayerDisk(unsigned int pos, int& layer, int& disk); + + unsigned int initLayerDisk(unsigned int pos); + + // Based on memory name check if this memory is used for special seeding: + // overlap is layer-disk seeding + // extra is the L2L3 seeding + // extended is the seeding for displaced tracks + void initSpecialSeeding(unsigned int pos, bool& overlap, bool& extra, bool& extended); + + //Used for a hack below due to MAC OS case sensitiviy problem for files + void findAndReplaceAll(std::string& data, std::string toSearch, std::string replaceStr); + + void openFile(bool first, std::string filebase); + + protected: + std::string name_; + unsigned int iSector_; + + std::ofstream out_; + int bx_; + int event_; + + Settings const& settings_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/ProcessBase.h b/L1Trigger/TrackFindingTracklet/interface/ProcessBase.h new file mode 100644 index 0000000000000..7482d24b21768 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/ProcessBase.h @@ -0,0 +1,48 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_ProcessBase_h +#define L1Trigger_TrackFindingTracklet_interface_ProcessBase_h + +#include + +namespace trklet { + + class MemoryBase; + class Settings; + class Globals; + + class ProcessBase { + public: + ProcessBase(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + + virtual ~ProcessBase() = default; + + // Add wire from pin "output" or "input" this proc module to memory instance "memory". + virtual void addOutput(MemoryBase* memory, std::string output) = 0; + virtual void addInput(MemoryBase* memory, std::string input) = 0; + + std::string const& getName() const { return name_; } + + unsigned int nbits(unsigned int power); + + //method sets the layer and disk based on the name. pos is the position in the memory name where the layer or disk is specified + void initLayerDisk(unsigned int pos, int& layer, int& disk); + void initLayerDisk(unsigned int pos, int& layer, int& disk, int& layerdisk); + + unsigned int initLayerDisk(unsigned int pos); + + //This function processes the name of a TE module to determine the layerdisks and iseed + void initLayerDisksandISeed(unsigned int& layerdisk1, unsigned int& layerdisk2, unsigned int& iSeed); + + unsigned int getISeed(std::string name); + + protected: + std::string name_; + unsigned int iSector_; + + double phimin_; + double phimax_; + + Settings const& settings_; + Globals* globals_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h b/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h new file mode 100644 index 0000000000000..2559a22a96fbf --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h @@ -0,0 +1,40 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_ProjectionRouter_h +#define L1Trigger_TrackFindingTracklet_interface_ProjectionRouter_h + +#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/ProjectionRouterBendTable.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h" + +namespace trklet { + + class Settings; + class Globals; + class MemoryBase; + + class ProjectionRouter : public ProcessBase { + public: + ProjectionRouter(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + + ~ProjectionRouter() override = default; + + void addOutput(MemoryBase* memory, std::string output) override; + void addInput(MemoryBase* memory, std::string input) override; + + void execute(); + + private: + unsigned int layerdisk_; + + int nrbits_; + int nphiderbits_; + + std::vector inputproj_; + + AllProjectionsMemory* allproj_; + std::vector vmprojs_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/ProjectionRouterBendTable.h b/L1Trigger/TrackFindingTracklet/interface/ProjectionRouterBendTable.h new file mode 100644 index 0000000000000..0cd798d758d08 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/ProjectionRouterBendTable.h @@ -0,0 +1,31 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_ProjectionRouterBendTable_h +#define L1Trigger_TrackFindingTracklet_interface_ProjectionRouterBendTable_h + +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +#include +#include +#include +#include +#include + +namespace trklet { + + class Globals; + + class ProjectionRouterBendTable { + public: + ProjectionRouterBendTable() {} + + ~ProjectionRouterBendTable() = default; + + void init(Settings const& settings, Globals* globals, unsigned int nrbits, unsigned int nphiderbits); + + int bendLoookup(int diskindex, int bendindex); + + private: + std::vector bendtable_[N_DISK]; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/ProjectionTemp.h b/L1Trigger/TrackFindingTracklet/interface/ProjectionTemp.h new file mode 100644 index 0000000000000..65970995ce7da --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/ProjectionTemp.h @@ -0,0 +1,41 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_ProjectionTemp_h +#define L1Trigger_TrackFindingTracklet_interface_ProjectionTemp_h + +#include +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" + +namespace trklet { + + class ProjectionTemp { + public: + ProjectionTemp(Tracklet* proj, + unsigned int slot, + unsigned int projrinv, + int projfinerz, + unsigned int projfinephi, + unsigned int iphi, + bool isPSseed); + + ProjectionTemp(); + + ~ProjectionTemp() = default; + + Tracklet* proj() const { return proj_; } + unsigned int slot() const { return slot_; } + unsigned int projrinv() const { return projrinv_; } + int projfinerz() const { return projfinerz_; } + unsigned int projfinephi() const { return projfinephi_; } + unsigned int iphi() const { return iphi_; } + bool isPSseed() const { return isPSseed_; } + + private: + Tracklet* proj_; + unsigned int slot_; + unsigned int projrinv_; + unsigned int projfinerz_; + unsigned int projfinephi_; + unsigned int iphi_; + bool isPSseed_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/PurgeDuplicate.h b/L1Trigger/TrackFindingTracklet/interface/PurgeDuplicate.h new file mode 100644 index 0000000000000..833c41e30a7b4 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/PurgeDuplicate.h @@ -0,0 +1,44 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_PurgeDuplicate_h +#define L1Trigger_TrackFindingTracklet_interface_PurgeDuplicate_h + +#include "L1Trigger/TrackFindingTracklet/interface/TrackFitMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/CleanTrackMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" + +#include + +namespace trklet { + + class Settings; + class Globals; + class MemoryBase; + class Stub; + class L1TStub; + class Track; + class Tracklet; + + class PurgeDuplicate : public ProcessBase { + public: + PurgeDuplicate(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + + ~PurgeDuplicate() override = default; + + void addOutput(MemoryBase* memory, std::string output) override; + void addInput(MemoryBase* memory, std::string input) override; + + void execute(std::vector& outputtracks_); + + private: + double getPhiRes(Tracklet* curTracklet, const Stub* curStub); + + std::vector inputtracks_; + std::vector> inputstublists_; + std::vector>> inputstubidslists_; + std::vector>> mergedstubidslists_; + std::vector inputtrackfits_; + std::vector inputtracklets_; + std::vector outputtracklets_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h b/L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h new file mode 100644 index 0000000000000..0ef6024854059 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h @@ -0,0 +1,114 @@ +// This holds two classes: L1SimTrack (truth level simulated track), and SLHCEvent (support for maintaining standalone running) +#ifndef L1Trigger_TrackFindingTracklet_interface_SLHCEvent_h +#define L1Trigger_TrackFindingTracklet_interface_SLHCEvent_h + +#include +#include +#include +#include +#include +#include + +#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" + +namespace trklet { + + class L1SimTrack { + public: + L1SimTrack(); + L1SimTrack(int eventid, int trackid, int type, double pt, double eta, double phi, double vx, double vy, double vz); + ~L1SimTrack() = default; + + void write(std::ofstream& out); + void write(std::ostream& out); + + int eventid() const { return eventid_; } + int trackid() const { return trackid_; } + int type() const { return type_; } + double pt() const { return pt_; } + double eta() const { return eta_; } + double phi() const { return phi_; } + double vx() const { return vx_; } + double vy() const { return vy_; } + double vz() const { return vz_; } + double dxy() const { return -vx() * sin(phi()) + vy() * cos(phi()); } + double d0() const { return -dxy(); } + int charge() const { + if (type_ == 11 || type_ == 13 || type_ == -211 || type_ == -321 || type_ == -2212) + return -1; + return 1; + } + + private: + int eventid_; + int trackid_; + int type_; + double pt_; + double eta_; + double phi_; + double vx_; + double vy_; + double vz_; + }; + + class SLHCEvent { + public: + SLHCEvent() { + //empty constructor to be used with 'filler' functions + eventnum_ = 0; + } + SLHCEvent(std::istream& in); + ~SLHCEvent() = default; + + void setIPx(double x) { x_offset_ = x; } + void setIPy(double y) { y_offset_ = y; } + + void setEventNum(int eventnum) { eventnum_ = eventnum; } + + void addL1SimTrack( + int eventid, int trackid, int type, double pt, double eta, double phi, double vx, double vy, double vz); + + bool addStub(int layer, + int ladder, + int module, + int strip, + int eventid, + std::vector tps, + double pt, + double bend, + double x, + double y, + double z, + int isPSmodule, + int isFlipped); + + const L1TStub& lastStub() const { return stubs_.back(); } + + void write(std::ofstream& out); + void write(std::ostream& out); + + unsigned int layersHit(int tpid, int& nlayers, int& ndisks); + + int nstubs() const { return stubs_.size(); } + + const L1TStub& stub(int i) const { return stubs_[i]; } + + unsigned int nsimtracks() const { return simtracks_.size(); } + + const L1SimTrack& simtrack(int i) const { return simtracks_[i]; } + + int eventnum() const { return eventnum_; } + + int getSimtrackFromSimtrackid(int simtrackid, int eventid = 0) const; + + private: + int eventnum_; + std::vector simtracks_; + std::vector stubs_; + + double x_offset_{0.0}; + double y_offset_{0.0}; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/Sector.h b/L1Trigger/TrackFindingTracklet/interface/Sector.h new file mode 100644 index 0000000000000..5d25f2996afd0 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/Sector.h @@ -0,0 +1,170 @@ +//This class holds functional blocks of a sector +#ifndef L1Trigger_TrackFindingTracklet_interface_Sector_h +#define L1Trigger_TrackFindingTracklet_interface_Sector_h + +#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" +#include "L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h" + +#include +#include +#include +#include +#include +#include + +namespace trklet { + + class Settings; + class Globals; + class ProcessBase; + class MemoryBase; + class Tracklet; + class Track; + class Stub; + + //Memory modules + class InputLinkMemory; + class AllStubsMemory; + class VMStubsTEMemory; + class VMStubsMEMemory; + class StubPairsMemory; + class StubTripletsMemory; + class TrackletParametersMemory; + class TrackletProjectionsMemory; + class AllProjectionsMemory; + class VMProjectionsMemory; + class CandidateMatchMemory; + class FullMatchMemory; + class TrackFitMemory; + class CleanTrackMemory; + + //Processing modules + class VMRouter; + class TrackletEngine; + class TrackletEngineDisplaced; + class TripletEngine; + class TrackletCalculator; + class TrackletProcessor; + class TrackletCalculatorDisplaced; + class ProjectionRouter; + class MatchEngine; + class MatchCalculator; + class MatchProcessor; + class FitTrack; + class PurgeDuplicate; + + class Sector { + public: + Sector(unsigned int i, Settings const& settings, Globals* globals); + + ~Sector(); + + bool addStub(L1TStub stub, std::string dtc); //TODO - should be pointer or string + + // Creates all required memory modules based on wiring map (args: module type, module instance) + void addMem(std::string memType, std::string memName); + + // Creates all required processing modules based on wiring map (args: module type, module instance) + void addProc(std::string procType, std::string procName); + + //--- Create all required proc -> mem module connections, based on wiring map + //--- (args: memory instance & input/output proc modules it connects to in format procName.pinName) + void addWire(std::string mem, std::string procinfull, std::string procoutfull); + + ProcessBase* getProc(std::string procName); + MemoryBase* getMem(std::string memName); + + void writeInputStubs(bool first); + void writeVMSTE(bool first); + void writeVMSME(bool first); + void writeAS(bool first); + void writeSP(bool first); + void writeST(bool first); + void writeTPAR(bool first); + void writeTPROJ(bool first); + void writeAP(bool first); + void writeVMPROJ(bool first); + void writeCM(bool first); + void writeMC(bool first); + void writeTF(bool first); + void writeCT(bool first); + + void clean(); + + // execute the different tracklet processing modules + void executeVMR(); + void executeTE(); + void executeTED(); + void executeTRE(); + void executeTP(); + void executeTC(); + void executeTCD(); + void executePR(); + void executeME(); + void executeMC(); + void executeMP(); + void executeFT(); + void executePD(std::vector& tracks); + + std::vector getAllTracklets() const; + std::vector getStubs() const; + + std::unordered_set seedMatch(int itp) const; + + double phimin() const { return phimin_; } + double phimax() const { return phimax_; } + + template + void addMemToVec(std::vector& memvec, TV* mem, const std::string& memName) { + memvec.push_back(mem); + Memories_[memName].reset(mem); + MemoriesV_.push_back(mem); + } + + template + void addProcToVec(std::vector& procvec, TV* proc, const std::string& procName) { + procvec.push_back(proc); + Processes_[procName].reset(proc); + } + + private: + int isector_; + Settings const& settings_; + Globals* globals_; + double phimin_; + double phimax_; + + std::map > Memories_; + std::vector MemoriesV_; + std::vector IL_; + std::vector AS_; + std::vector VMSTE_; + std::vector VMSME_; + std::vector SP_; + std::vector ST_; + std::vector TPAR_; + std::vector TPROJ_; + std::vector AP_; + std::vector VMPROJ_; + std::vector CM_; + std::vector FM_; + std::vector TF_; + std::vector CT_; + + std::map > Processes_; + std::vector VMR_; + std::vector TE_; + std::vector TED_; + std::vector TRE_; + std::vector TP_; + std::vector TC_; + std::vector TCD_; + std::vector PR_; + std::vector ME_; + std::vector MC_; + std::vector MP_; + std::vector FT_; + std::vector PD_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/Settings.h b/L1Trigger/TrackFindingTracklet/interface/Settings.h new file mode 100644 index 0000000000000..3f211f3aedb72 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/Settings.h @@ -0,0 +1,710 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_Settings_h +#define L1Trigger_TrackFindingTracklet_interface_Settings_h + +#include +#include +#include +#include +#include +#include +#include + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +namespace trklet { + + constexpr unsigned int N_SECTOR = 9; // # of phi sectors for L1TK processing + + constexpr int N_LAYER = 6; // # of barrel layers assumed + constexpr int N_DISK = 5; // # of endcap disks assumed + constexpr unsigned int N_PSLAYER = 3; // # of barrel PS layers assumed + constexpr unsigned int N_SEED = 12; // # of tracklet+triplet seeds + + constexpr unsigned int N_DSS_MOD = 5; // # of rings with 2S modules per disk + + class Settings { + public: + Settings() { + //Comment out to run tracklet-only algorithm +#ifdef CMSSW_GIT_HASH +#define USEHYBRID +#endif + } + + ~Settings() = default; + + // processing & memory modules, wiring, etc. + std::string DTCLinkFile() const { return DTCLinkFile_; } + std::string const& moduleCablingFile() const { return moduleCablingFile_; } + std::string const& DTCLinkLayerDiskFile() const { return DTCLinkLayerDiskFile_; } + std::string const& fitPatternFile() const { return fitPatternFile_; } + std::string const& processingModulesFile() const { return processingModulesFile_; } + std::string const& memoryModulesFile() const { return memoryModulesFile_; } + std::string const& wiresFile() const { return wiresFile_; } + + void setDTCLinkFile(std::string DTCLinkFileName) { DTCLinkFile_ = DTCLinkFileName; } + void setModuleCablingFile(std::string moduleCablingFileName) { moduleCablingFile_ = moduleCablingFileName; } + void setDTCLinkLayerDiskFile(std::string DTCLinkLayerDiskFileName) { + DTCLinkLayerDiskFile_ = DTCLinkLayerDiskFileName; + } + void setFitPatternFile(std::string fitPatternFileName) { fitPatternFile_ = fitPatternFileName; } + void setProcessingModulesFile(std::string processingModulesFileName) { + processingModulesFile_ = processingModulesFileName; + } + void setMemoryModulesFile(std::string memoryModulesFileName) { memoryModulesFile_ = memoryModulesFileName; } + void setWiresFile(std::string wiresFileName) { wiresFile_ = wiresFileName; } + + unsigned int nzbitsstub(unsigned int layerdisk) const { return nzbitsstub_[layerdisk]; } + unsigned int nphibitsstub(unsigned int layerdisk) const { return nphibitsstub_[layerdisk]; } + unsigned int nrbitsstub(unsigned int layerdisk) const { return nrbitsstub_[layerdisk]; } + + unsigned int nrbitsprojderdisk() const { return nrbitsprojderdisk_; } + unsigned int nbitsphiprojderL123() const { return nbitsphiprojderL123_; } + unsigned int nbitsphiprojderL456() const { return nbitsphiprojderL456_; } + unsigned int nbitszprojderL123() const { return nbitszprojderL123_; } + unsigned int nbitszprojderL456() const { return nbitszprojderL456_; } + + bool useSeed(unsigned int iSeed) const { return useseeding_.find(iSeed) != useseeding_.end(); } + unsigned int nbitsvmte(unsigned int inner, unsigned int iSeed) const { return nbitsvmte_[inner][iSeed]; } + unsigned int nvmte(unsigned int inner, unsigned int iSeed) const { return (1 << nbitsvmte_[inner][iSeed]); } + + unsigned int nbitsvmme(unsigned int layerdisk) const { return nbitsvmme_[layerdisk]; } + unsigned int nvmme(unsigned int layerdisk) const { return (1 << nbitsvmme_[layerdisk]); } + + unsigned int nbitsallstubs(unsigned int layerdisk) const { return nbitsallstubs_[layerdisk]; } + unsigned int nallstubs(unsigned int layerdisk) const { return (1 << nbitsallstubs_[layerdisk]); } + + bool writeMonitorData(std::string module) const { + if (writeMonitorData_.find(module) == writeMonitorData_.end()) { + throw cms::Exception("BadConfig") << "Settings::writeMonitorData module = " << module << " not known"; + } + return writeMonitorData_.at(module); + } + + unsigned int maxStep(std::string module) const { + if (maxstep_.find(module) == maxstep_.end()) { + throw cms::Exception("BadConfig") + << __FILE__ << " " << __LINE__ << " maxStep module = " << module << " not known"; + } + return maxstep_.at(module) + maxstepoffset_; + } + + double zlength() const { return zlength_; } + double rmaxdisk() const { return rmaxdisk_; } + double rmindisk() const { return rmindisk_; } + + double drmax() const { return rmaxdisk_ / deltarzfract_; } + double dzmax() const { return zlength_ / deltarzfract_; } + + double half2SmoduleWidth() const { return half2SmoduleWidth_; } + + double bendcutte(unsigned int inner, unsigned int iSeed) const { return bendcutte_[inner][iSeed]; } + double bendcutme(unsigned int layerdisk) const { return bendcutme_[layerdisk]; } + double nfinephi(unsigned int inner, unsigned int iSeed) const { return nfinephi_[inner][iSeed]; } + double nphireg(unsigned int inner, unsigned int iSeed) const { return nphireg_[inner][iSeed]; } + double lutwidthtab(unsigned int inner, unsigned int iSeed) const { return lutwidthtab_[inner][iSeed]; } + double lutwidthtabextended(unsigned int inner, unsigned int iSeed) const { + return lutwidthtabextended_[inner][iSeed]; + } + + unsigned int projlayers(unsigned int iSeed, unsigned int i) const { return projlayers_[iSeed][i]; } + unsigned int projdisks(unsigned int iSeed, unsigned int i) const { return projdisks_[iSeed][i]; } + double rphimatchcut(unsigned int iSeed, unsigned int ilayer) const { return rphimatchcut_[ilayer][iSeed]; } + double zmatchcut(unsigned int iSeed, unsigned int ilayer) const { return zmatchcut_[ilayer][iSeed]; } + double rphicutPS(unsigned int iSeed, unsigned int idisk) const { return rphicutPS_[idisk][iSeed]; } + double rcutPS(unsigned int iSeed, unsigned int idisk) const { return rcutPS_[idisk][iSeed]; } + double rphicut2S(unsigned int iSeed, unsigned int idisk) const { return rphicut2S_[idisk][iSeed]; } + double rcut2S(unsigned int iSeed, unsigned int idisk) const { return rcut2S_[idisk][iSeed]; } + + double rmean(unsigned int iLayer) const { return irmean_[iLayer] * rmaxdisk_ / 4096; } + double rmax(unsigned int iLayer) const { return rmean(iLayer) + drmax(); } + double rmin(unsigned int iLayer) const { return rmean(iLayer) - drmax(); } + double zmean(unsigned int iDisk) const { return izmean_[iDisk] * zlength_ / 2048; } + double zmax(unsigned int iDisk) const { return zmean(iDisk) + dzmax(); } + double zmin(unsigned int iDisk) const { return zmean(iDisk) - dzmax(); } + + double rDSSinner(unsigned int iBin) const { + return rDSSinner_mod_[iBin / 2] + halfstrip_ * ((iBin % 2 == 0) ? -1 : 1); + } + double rDSSouter(unsigned int iBin) const { + return rDSSouter_mod_[iBin / 2] + halfstrip_ * ((iBin % 2 == 0) ? -1 : 1); + } + + unsigned int vmrlutzbits(unsigned int layerdisk) const { return vmrlutzbits_[layerdisk]; } + unsigned int vmrlutrbits(unsigned int layerdisk) const { return vmrlutrbits_[layerdisk]; } + + bool printDebugKF() const { return printDebugKF_; } + bool debugTracklet() const { return debugTracklet_; } + bool writetrace() const { return writetrace_; } + + bool warnNoMem() const { return warnNoMem_; } + bool warnNoDer() const { return warnNoDer_; } + + bool writeMem() const { return writeMem_; } + bool writeTable() const { return writeTable_; } + + bool writeVerilog() const { return writeVerilog_; } + bool writeHLS() const { return writeHLS_; } + bool writeInvTable() const { return writeInvTable_; } + bool writeHLSInvTable() const { return writeHLSInvTable_; } + + unsigned int writememsect() const { return writememsect_; } + + bool writeTripletTables() const { return writeTripletTables_; } + + bool writeoutReal() const { return writeoutReal_; } + + bool bookHistos() const { return bookHistos_; } + + double ptcut() const { return ptcut_; } + double rinvcut() const { return 0.01 * c_ * bfield_ / ptcut_; } //0.01 to convert to cm-1 + + double c() const { return c_; } + + double rinvmax() const { return 0.01 * c_ * bfield_ / ptmin_; } + + int alphashift() const { return alphashift_; } + int nbitsalpha() const { return nbitsalpha_; } + int alphaBitsTable() const { return alphaBitsTable_; } + int nrinvBitsTable() const { return nrinvBitsTable_; } + + unsigned int MEBinsBits() const { return MEBinsBits_; } + unsigned int MEBins() const { return 1u << MEBinsBits_; } + unsigned int MEBinsDisks() const { return MEBinsDisks_; } + + std::string geomext() const { return extended_ ? "hourglassExtended" : "hourglass"; } + + bool exactderivatives() const { return exactderivatives_; } + bool exactderivativesforfloating() const { return exactderivativesforfloating_; } + bool useapprox() const { return useapprox_; } + bool usephicritapprox() const { return usephicritapprox_; } + + unsigned int minIndStubs() const { return minIndStubs_; } + std::string removalType() const { return removalType_; } + std::string mergeComparison() const { return mergeComparison_; } + bool doKF() const { return doKF_; } + bool fakefit() const { return fakefit_; } + + // configurable + unsigned int nHelixPar() const { return nHelixPar_; } + void setNHelixPar(unsigned int nHelixPar) { nHelixPar_ = nHelixPar; } + + bool extended() const { return extended_; } + void setExtended(bool extended) { extended_ = extended; } + + double bfield() const { return bfield_; } + void setBfield(double bfield) { bfield_ = bfield; } + + unsigned int nStrips(bool isPSmodule) const { return isPSmodule ? nStrips_PS_ : nStrips_2S_; } + void setNStrips_PS(unsigned int nStrips_PS) { nStrips_PS_ = nStrips_PS; } + void setNStrips_2S(unsigned int nStrips_2S) { nStrips_2S_ = nStrips_2S; } + + double stripPitch(bool isPSmodule) const { return isPSmodule ? stripPitch_PS_ : stripPitch_2S_; } + void setStripPitch_PS(double stripPitch_PS) { stripPitch_PS_ = stripPitch_PS; } + void setStripPitch_2S(double stripPitch_2S) { stripPitch_2S_ = stripPitch_2S; } + + double stripLength(bool isPSmodule) const { return isPSmodule ? stripLength_PS_ : stripLength_2S_; } + void setStripLength_PS(double stripLength_PS) { stripLength_PS_ = stripLength_PS; } + void setStripLength_2S(double stripLength_2S) { stripLength_2S_ = stripLength_2S; } + + std::string skimfile() const { return skimfile_; } + void setSkimfile(std::string skimfile) { skimfile_ = skimfile; } + + double dphisectorHG() const { + return 2 * M_PI / N_SECTOR + + 2 * std::max(std::abs(asin(0.5 * rinvmax() * rmean(0)) - asin(0.5 * rinvmax() * rcrit_)), + std::abs(asin(0.5 * rinvmax() * rmean(5)) - asin(0.5 * rinvmax() * rcrit_))); + } + + double rcrit() const { return rcrit_; } + + double dphisector() const { return 2 * M_PI / N_SECTOR; } + + double phicritmin() const { return 0.5 * dphisectorHG() - M_PI / N_SECTOR; } + double phicritmax() const { return dphisectorHG() - 0.5 * dphisectorHG() + M_PI / N_SECTOR; } + + double phicritminmc() const { return phicritmin() - dphicritmc_; } + double phicritmaxmc() const { return phicritmax() + dphicritmc_; } + + double kphi() const { return dphisectorHG() / (1 << nphibitsstub(0)); } + double kphi1() const { return dphisectorHG() / (1 << nphibitsstub(5)); } + + double kz() const { return 2 * zlength_ / (1 << nzbitsstub_[0]); } + double kr() const { return rmaxdisk_ / (1 << nrbitsstub_[6]); } + + double maxrinv() const { return maxrinv_; } + double maxd0() const { return maxd0_; } + unsigned int nbitsd0() const { return nbitsd0_; } + + double kd0() const { return 2 * maxd0_ / (1 << nbitsd0_); } + + double rinvcutte() const { return 0.01 * c_ * bfield_ / ptcutte_; } //0.01 to convert to cm-1 + + double rmindiskvm() const { return rmindiskvm_; } + double rmaxdiskvm() const { return rmaxdiskvm_; } + + double rmaxdiskl1overlapvm() const { return rmaxdiskl1overlapvm_; } + double rmindiskl2overlapvm() const { return rmindiskl2overlapvm_; } + double rmindiskl3overlapvm() const { return rmindiskl3overlapvm_; } + + double rPS2S() const { return rPS2S_; } + + double z0cut() const { return z0cut_; } + + unsigned int NLONGVMBITS() const { return NLONGVMBITS_; } + unsigned int NLONGVMBINS() const { return (1 << NLONGVMBITS_); } + + unsigned int ntrackletmax() const { return ntrackletmax_; } + + //Bits used to store track parameter in tracklet + int nbitsrinv() const { return nbitsrinv_; } + int nbitsphi0() const { return nbitsphi0_; } + int nbitst() const { return nbitst_; } + int nbitsz0() const { return nbitsz0_; } + + //track and tracklet parameters + int rinv_shift() const { return rinv_shift_; } + int phi0_shift() const { return phi0_shift_; } + int t_shift() const { return t_shift_; } + int z0_shift() const { return z0_shift_; } + + //projections are coarsened from global to stub precision + + //projection to R parameters + int SS_phiL_shift() const { return SS_phiL_shift_; } + int PS_zL_shift() const { return PS_zL_shift_; } + + int SS_phiderL_shift() const { return SS_phiderL_shift_; } + int PS_zderL_shift() const { return PS_zderL_shift_; } + int SS_zderL_shift() const { return SS_zderL_shift_; } + + //projection to Z parameters + int SS_phiD_shift() const { return SS_phiD_shift_; } + int PS_rD_shift() const { return PS_rD_shift_; } + + int SS_phiderD_shift() const { return SS_phiderD_shift_; } + int PS_rderD_shift() const { return PS_rderD_shift_; } + + //numbers needed for matches & fit, unclear what they are. + int phi0bitshift() const { return phi0bitshift_; } + int phiderbitshift() const { return phiderbitshift_; } + int zderbitshift() const { return zderbitshift_; } + + int phiresidbits() const { return phiresidbits_; } + int zresidbits() const { return zresidbits_; } + int rresidbits() const { return rresidbits_; } + + //Trackfit + int fitrinvbitshift() const { return fitrinvbitshift_; } + int fitphi0bitshift() const { return fitphi0bitshift_; } + int fittbitshift() const { return fittbitshift_; } + int fitz0bitshift() const { return fitz0bitshift_; } + + //r correction bits + int rcorrbits() const { return rcorrbits_; } + + int chisqphifactbits() const { return chisqphifactbits_; } + int chisqzfactbits() const { return chisqzfactbits_; } + + //0.02 here is the maximum range in rinv values that can be represented + double krinvpars() const { + int shift = ceil(-log2(0.02 * rmaxdisk_ / ((1 << nbitsrinv_) * dphisectorHG()))); + return dphisectorHG() / rmaxdisk_ / (1 << shift); + } + double kphi0pars() const { return 2 * kphi1(); } + double ktpars() const { return maxt_ / (1 << nbitst_); } + double kz0pars() const { return kz(); } + double kd0pars() const { return kd0(); } + + double kphider() const { return krinvpars() / (1 << phiderbitshift_); } + double kzder() const { return ktpars() / (1 << zderbitshift_); } + + //This is a 'historical accident' and should be fixed so that we don't + //have the factor if 2 + double krprojshiftdisk() const { return 2 * kr(); } + + private: + std::string DTCLinkFile_; + std::string moduleCablingFile_; + std::string DTCLinkLayerDiskFile_; + std::string fitPatternFile_; + std::string processingModulesFile_; + std::string memoryModulesFile_; + std::string wiresFile_; + + double rcrit_{55.0}; // critical radius for the hourglass configuration + + double dphicritmc_{0.005}; + + //fraction of full r and z range that stubs can be located within layer/disk + double deltarzfract_{32.0}; + + double maxt_{32.0}; //range in t that we must cover + + std::array irmean_{{851, 1269, 1784, 2347, 2936, 3697}}; + std::array izmean_{{2239, 2645, 3163, 3782, 4523}}; + + std::array nzbitsstub_{{12, 12, 12, 8, 8, 8, 7, 7, 7, 7, 7}}; + std::array nphibitsstub_{{14, 14, 14, 17, 17, 17, 14, 14, 14, 14, 14}}; + std::array nrbitsstub_{{7, 7, 7, 7, 7, 7, 12, 12, 12, 12, 12}}; + + unsigned int nrbitsprojderdisk_{9}; + unsigned int nbitsphiprojderL123_{10}; + unsigned int nbitsphiprojderL456_{10}; + unsigned int nbitszprojderL123_{10}; + unsigned int nbitszprojderL456_{9}; + + std::set useseeding_{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + + std::array nbitsallstubs_{{3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}}; + std::array nbitsvmme_{{2, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2}}; + std::array, 3> nbitsvmte_{ + {{{2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 3, 2}}, // (3 = #stubs/triplet, only row 1+2 used for tracklet) + {{3, 2, 3, 3, 2, 2, 2, 2, 3, 3, 2, 2}}, + {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1}}}}; + + std::array, 2> bendcutte_{ + {{{1.25, 1.25, 1.25, 1.25, 1.25, 1.25, 1.25, 1.25}}, //inner (2 = #stubs/tracklet) + {{1.25, 1.25, 1.25, 1.25, 1.25, 1.25, 1.25, 1.25}}}}; //outer + + std::array bendcutme_{{2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 1.5, 1.5, 1.5, 1.5, 1.5}}; + + double rmindiskvm_{22.5}; + double rmaxdiskvm_{67.0}; + + double rmaxdiskl1overlapvm_{45.0}; + double rmindiskl2overlapvm_{40.0}; + double rmindiskl3overlapvm_{50.0}; + + double rPS2S_{60.0}; + + double z0cut_{15.0}; + + unsigned int NLONGVMBITS_{3}; + + double zlength_{120.0}; + double rmaxdisk_{120.0}; + double rmindisk_{20.0}; + + double half2SmoduleWidth_{4.57}; + + double maxrinv_{0.006}; + double maxd0_{10.0}; + + unsigned int nbitsd0_{13}; + + double ptmin_{2.0}; //minumim pt for tracks + + double ptcutte_{1.8}; //Minimum pt in TE + + unsigned int ntrackletmax_{127}; //maximum number of tracklets that can be stored + + //Bits used to store track parameter in tracklet + int nbitsrinv_{14}; + int nbitsphi0_{18}; + int nbitst_{14}; + int nbitsz0_{10}; + + //track and tracklet parameters + int rinv_shift_{-8}; // Krinv = 2^shift * Kphi/Kr + int phi0_shift_{1}; // Kphi0 = 2^shift * Kphi + int t_shift_{-10}; // Kt = 2^shift * Kz/Kr + int z0_shift_{0}; // Kz0 = 2^shift * kz + + //projections are coarsened from global to stub precision + + //projection to R parameters + int SS_phiL_shift_{0}; + int PS_zL_shift_{0}; // z projections have global precision in ITC + + int SS_phiderL_shift_{-5}; + int PS_zderL_shift_{-7}; // Kderz = 2^shift * Kz/Kr + int SS_zderL_shift_{-7}; + + //projection to Z parameters + int SS_phiD_shift_{3}; + int PS_rD_shift_{1}; // a bug?! coarser by a factor of two then stubs?? + + int SS_phiderD_shift_{-4}; + int PS_rderD_shift_{-6}; //Kderrdisk = 2^shift * Kr/Kz + + //numbers needed for matches & fit, unclear what they are. + int phi0bitshift_{1}; + int phiderbitshift_{7}; + int zderbitshift_{6}; + + int phiresidbits_{12}; + int zresidbits_{9}; + int rresidbits_{7}; + + //Trackfit + int fitrinvbitshift_{9}; //6 OK? + int fitphi0bitshift_{6}; //4 OK? + int fittbitshift_{10}; //4 OK? //lower number gives rounding problems + int fitz0bitshift_{8}; //6 OK? + + //r correction bits + int rcorrbits_{6}; + + int chisqphifactbits_{14}; + int chisqzfactbits_{14}; + + std::array vmrlutzbits_{ + {7, 7, 7, 7, 7, 7, 3, 3, 3, 3, 3}}; // zbits used by LUT in VMR + std::array vmrlutrbits_{ + {4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8}}; // rbits used by LUT in VMR + + std::array, 3> nfinephi_{ + {{{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}}, //inner (3 = #stubs/triplet, only row 1+2 used for tracklet) + {{3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}}, //outer + {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3}}}}; //outermost (triplets only) + + //These are the number of bits used for the VM regions in the TE by seedindex + std::array, 3> nphireg_{ + {{{5, 4, 4, 4, 4, 4, 4, 3, 4, 4, 5, 4}}, //inner + {{5, 4, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4}}, //outer + {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4}}}}; //outermost (triplets only) + + std::array, 3> lutwidthtab_{{{{10, 11, 11, 11, 11, 11, 11, 11, 0, 0, 11, 0}}, + {{6, 6, 6, 6, 10, 10, 10, 10, 0, 0, 6, 0}}, + {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6}}}}; + + std::array, 3> lutwidthtabextended_{ + {{{11, 11, 21, 21, 21, 21, 11, 11, 0, 0, 21, 0}}, + {{6, 6, 6, 6, 10, 10, 10, 10, 0, 0, 6, 0}}, + {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6}}}}; + + //projection layers by seed index. For each seeding index (row) the list of layers that we consider projections to + std::array, N_SEED> projlayers_{{{{3, 4, 5, 6}}, //0 L1L2 + {{1, 4, 5, 6}}, //1 L2L3 + {{1, 2, 5, 6}}, //2 L3L4 + {{1, 2, 3, 4}}, //3 L5L6 + {{1, 2}}, //4 D1D2 + {{1}}, //5 D3D4 + {{}}, //6 L1D1 + {{1}}, //7 L2D1 + {{1, 5, 6}}, //8 L2L3L4 + {{1, 2, 3}}, //9 L4L5L6 + {{1}}, //10 L2L3D1 + {{1}}}}; //11 D1D2L2 + + //projection disks by seed index. For each seeding index (row) the list of diks that we consider projections to + std::array, N_SEED> projdisks_{{{{1, 2, 3, 4}}, //0 L1L2 + {{1, 2, 3, 4}}, //1 L2L3 + {{1, 2}}, //2 L3L4 + {{}}, //3 L5L6 + {{3, 4, 5}}, //4 D1D2 + {{1, 2, 5}}, //5 D3D4 + {{2, 3, 4, 5}}, //6 L1D1 + {{2, 3, 4}}, //7 L2D1 + {{1, 2}}, //8 L2L3L4 + {{}}, //9 L4L5L6 + {{2, 3, 4}}, //10 L2L3D1 + {{3, 4}}}}; //11 D1D2L2 + + //rphi cuts for layers - the column is the seedindex + std::array, N_LAYER> rphimatchcut_{ + {{{0.0, 0.1, 0.07, 0.08, 0.07, 0.05, 0.0, 0.05, 0.08, 0.15, 0.125, 0.15}}, //Layer 1 + {{0.0, 0.0, 0.06, 0.08, 0.05, 0.0, 0.0, 0.0, 0.0, 0.1, 0.0, 0.0}}, //Layer 2 + {{0.1, 0.0, 0.0, 0.08, 0.0, 0.0, 0.0, 0.0, 0.0, 0.08, 0.0, 0.0}}, //Layer 3 + {{0.19, 0.19, 0.0, 0.05, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}}, //Layer 4 + {{0.4, 0.4, 0.08, 0.0, 0.0, 0.0, 0.0, 0.0, 0.08, 0.0, 0.0, 0.0}}, //Layer 5 + {{0.5, 0.0, 0.19, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.0, 0.0, 0.0}}}}; //Layer 6 + + //z cuts for layers - the column is the seedindex + std::array, N_LAYER> zmatchcut_{ + {{{0.0, 0.7, 5.5, 15.0, 1.5, 2.0, 0.0, 1.5, 1.0, 8.0, 1.0, 1.5}}, //Layer 1 + {{0.0, 0.0, 3.5, 15.0, 1.25, 0.0, 0.0, 0.0, 0.0, 7.0, 0.0, 0.0}}, //Layer 2 + {{0.7, 0.0, 0.0, 9.0, 0.0, 0.0, 0.0, 0.0, 0.0, 5.0, 0.0, 0.0}}, //Layer 3 + {{3.0, 3.0, 0.0, 7.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}}, //Layer 4 + {{3.0, 3.0, 8.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.5, 0.0, 0.0, 0.0}}, //Layer 5 + {{4.0, 0.0, 9.5, 0.0, 0.0, 0.0, 0.0, 0.0, 4.5, 0.0, 0.0, 0.0}}}}; //Layer 6 + + //rphi cuts for PS modules in disks - the column is the seedindex + std::array, N_DISK> rphicutPS_{ + {{{0.2, 0.2, 0.0, 0.0, 0.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}}, //disk 1 + {{0.2, 0.2, 0.0, 0.0, 0.0, 0.1, 0.1, 0.1, 0.0, 0.0, 0.15, 0.0}}, //disk 2 + {{0.25, 0.2, 0.0, 0.0, 0.15, 0.0, 0.2, 0.15, 0.0, 0.0, 0.0, 0.2}}, //disk 3 + {{0.5, 0.2, 0.0, 0.0, 0.2, 0.0, 0.3, 0.5, 0.0, 0.0, 0.0, 0.0}}, //disk 4 + {{0.0, 0.0, 0.0, 0.0, 0.25, 0.1, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0}}}}; //disk 5 + + //r cuts for PS modules in disks - the column is the seedindex + std::array, N_DISK> rcutPS_{ + {{{0.5, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}}, //disk 1 + {{0.5, 0.5, 0.0, 0.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 0.5, 0.0}}, //disk 2 + {{0.5, 0.5, 0.0, 0.0, 0.5, 0.0, 0.6, 0.8, 0.0, 0.0, 0.0, 0.4}}, //disk 3 + {{0.5, 0.5, 0.0, 0.0, 0.8, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0}}, //disk 4 + {{0.0, 0.0, 0.0, 0.0, 1.0, 0.5, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0}}}}; //disk 5 + + //rphi cuts for 2S modules in disks = the column is the seedindex + std::array, N_DISK> rphicut2S_{ + {{{0.5, 0.5, 0.8, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.0, 0.0, 0.0}}, //disk 1 + {{0.5, 0.5, 0.8, 0.0, 0.0, 0.0, 0.5, 0.15, 0.3, 0.0, 0.68, 0.0}}, //disk 2 + {{0.5, 0.5, 0.0, 0.0, 0.15, 0.0, 0.2, 0.25, 0.0, 0.0, 0.8, 0.1}}, //disk 3 + {{0.5, 0.5, 0.0, 0.0, 0.2, 0.0, 0.25, 0.5, 0.0, 0.0, 0.6, 0.4}}, //disk 4 + {{0.0, 0.0, 0.0, 0.0, 0.4, 0.2, 0.4, 0.0, 0.0, 0.0, 0.0, 0.8}}}}; //disk 5 + + //r cuts for 2S modules in disks -the column is the seedindex + std::array, N_DISK> rcut2S_{ + {{{3.8, 3.8, 3.8, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0}}, //disk 1 + {{3.8, 3.8, 3.8, 0.0, 0.0, 0.0, 3.8, 3.4, 3.0, 0.0, 3.0, 0.0}}, //disk 2 + {{3.6, 3.8, 0.0, 0.0, 3.6, 0.0, 3.6, 3.8, 0.0, 0.0, 3.8, 3.0}}, //disk 3 + {{3.6, 3.8, 0.0, 0.0, 3.6, 0.0, 3.5, 3.8, 0.0, 0.0, 3.0, 3.0}}, //disk 4 + {{0.0, 0.0, 0.0, 0.0, 3.6, 3.4, 3.7, 0.0, 0.0, 0.0, 0.0, 3.0}}}}; //disk 5 + + unsigned int maxstepoffset_{10000}; + + std::unordered_map maxstep_{{"Link", 108}, + {"MC", 108}, + {"ME", 108}, + {"MP", 108}, + {"PR", 108}, + {"TC", 108}, + {"TE", 108}, + {"TP", 108}, + {"TRE", 108}, + {"VMR", 108}}; + + std::unordered_map writeMonitorData_{{"IL", false}, + {"TE", false}, + {"CT", false}, + {"HitPattern", false}, + {"ChiSq", false}, + {"Seeds", false}, + {"FT", false}, + {"Residuals", false}, + {"MC", false}, + {"ME", false}, + {"AP", false}, + {"VMP", false}, + {"NMatches", false}, + {"TrackProjOcc", false}, + {"TC", false}, + {"Pars", false}, + {"TPars", false}, + {"TPD", false}, + {"TrackletPars", false}, + {"TED", false}, + {"TP", false}, + {"TRE", false}, + {"VMR", false}, + {"StubsLayer", false}, + {"StubsLayerSector", false}, + {"HitEff", false}, + {"MatchEff", false}, + {"Cabling", false}, + {"IFit", false}, + {"AS", false}}; + + std::array rDSSinner_mod_{{68.9391, 78.7750, 85.4550, 96.3150, 102.3160}}; + std::array rDSSouter_mod_{{66.4903, 76.7750, 84.4562, 94.9920, 102.3160}}; + + //we want the center of the two strip positions in a module, not just the center of a module + double halfstrip_{2.5}; + + // various printouts for debugging and warnings + bool printDebugKF_{false}; // if true print lots of debugging statements related to the KF fit + bool debugTracklet_{false}; //Print detailed debug information about tracklet tracking + bool writetrace_{false}; //Print out details about parsing configuration files + + bool warnNoMem_{false}; //If true will print out warnings about missing projection memories + bool warnNoDer_{false}; //If true will print out warnings about missing track fit derivatives + + bool writeMem_{false}; //If true will print out content of memories to files + bool writeTable_{false}; //IF true will print out content of LUTs to files + + // Write various lookup tables and autogenerated code (from iMath) + bool writeVerilog_{false}; //Write out auto-generated Verilog mudules used by TCs + bool writeHLS_{false}; //Write out auto-generated HLS mudules used by TCs + bool writeInvTable_{false}; //Write out tables of drinv and invt in tracklet calculator for Verilog module + bool writeHLSInvTable_{false}; //Write out tables of drinv and invt in tracklet calculator for HLS module + + unsigned int writememsect_{3}; //writemem only for this sector (note that the files will have _4 extension) + + bool writeTripletTables_{false}; //Train and write the TED and TRE tables. N.B.: the tables + //cannot be applied while they are being trained, i.e., + //this flag effectively turns off the cuts in + //TrackletEngineDisplaced and TripletEngine + + bool writeoutReal_{false}; + + //set to true/false to turn on/off histogram booking internal to the tracking (class "HistBase/HistImp", does nothing in central CMSSW) + bool bookHistos_{false}; + + // pt constants + double ptcut_{1.91}; //Minimum pt cut + + // Parameters for bit sizes + int alphashift_{12}; + int nbitsalpha_{4}; //bits used to store alpha + int alphaBitsTable_{2}; //For number of bits in track derivative table + int nrinvBitsTable_{3}; //number of bits for tabulating rinv dependence + + unsigned int MEBinsBits_{3}; + unsigned int MEBinsDisks_{8}; //on each side + + // Options for chisq fit + bool exactderivatives_{false}; + bool exactderivativesforfloating_{true}; //only for the floating point + bool useapprox_{true}; //use approximate postion based on integer representation for floating point + bool usephicritapprox_{false}; //use floating point approximate version of phicrit cut if true + + // Duplicate Removal + // "merge" (hybrid dup removal) + // "ichi" (pairwise, keep track with best ichisq), "nstub" (pairwise, keep track with more stubs) + // "grid" (TMTT-like removal), "" (no removal) + unsigned int minIndStubs_{3}; // not used with merge removal + +#ifdef USEHYBRID + std::string removalType_{"merge"}; + // "CompareBest" (recommended) Compares only the best stub in each track for each region (best = smallest phi residual) + // and will merge the two tracks if stubs are shared in three or more regions + // "CompareAll" Compares all stubs in a region, looking for matches, and will merge the two tracks if stubs are shared in three or more regions + std::string mergeComparison_{"CompareBest"}; + bool doKF_{true}; +#endif + +#ifndef USEHYBRID + bool doKF_{false}; + std::string removalType_{"ichi"}; + std::string mergeComparison_{""}; +#endif + + // if true, run a dummy fit, producing TTracks directly from output of tracklet pattern reco stage + bool fakefit_{false}; + + unsigned int nHelixPar_{4}; // 4 or 5 param helix fit + bool extended_{false}; // turn on displaced tracking + + std::string skimfile_{""}; //if not empty events will be written out in ascii format to this file + + double bfield_{3.8112}; //B-field in T + double c_{0.299792458}; //speed of light m/ns + + unsigned int nStrips_PS_{960}; + unsigned int nStrips_2S_{1016}; + + double stripPitch_PS_{0.01}; + double stripPitch_2S_{0.009}; + + double stripLength_PS_{0.1467}; + double stripLength_2S_{5.0250}; + }; + + constexpr unsigned int N_TILTED_RINGS = 12; // # of tilted rings per half-layer in TBPS layers + constexpr std::array N_MOD_PLANK = {{7, 11, 15}}; // # of modules/plank in TBPS + + constexpr unsigned int N_TRKLSEED = 7; // # of tracklet seeds + constexpr unsigned int N_PROJ = 4; // # of projections (beyond stubs from tracklet seed) + + // chi2 fitting + constexpr unsigned int N_FITPARAM = 4; // # of fit parameters for chi2 fit + constexpr unsigned int N_FITSTUB = 6; // max # of number of stubs used + + constexpr unsigned int N_TRACKDER_PTBIN = 4; + constexpr unsigned int N_TRACKDER_INDEX = 1000; + +} // namespace trklet + +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/Stub.h b/L1Trigger/TrackFindingTracklet/interface/Stub.h new file mode 100644 index 0000000000000..8b5536d270d84 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/Stub.h @@ -0,0 +1,92 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_Stub_h +#define L1Trigger_TrackFindingTracklet_interface_Stub_h + +#include +#include +#include +#include + +#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" +#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +namespace trklet { + + class Stub { + public: + Stub(Settings const& settings); + + Stub(L1TStub& stub, Settings const& settings, double phiminsec, double phimaxsec); + + ~Stub() = default; + + FPGAWord iphivmFineBins(int VMbits, int finebits) const; + + std::string str() const { + if (layer_.value() != -1) { + return r_.str() + "|" + z_.str() + "|" + phi_.str() + "|" + bend_.str(); + } else { + if (isPSmodule()) { + return r_.str() + "|" + z_.str() + "|" + phi_.str() + "|" + bend_.str(); + } else { + return "000" + r_.str() + "|" + z_.str() + "|" + phi_.str() + "|" + alphanew_.str() + "|" + bend_.str(); + } + } + } + + std::string strbare() const { return bend_.str() + r_.str() + z_.str() + phi_.str(); } + + unsigned int phiregionaddress() const; + std::string phiregionaddressstr() const; + + void setAllStubIndex(int nstub); //should migrate away from using this method + + void setPhiCorr(int phiCorr); + + const FPGAWord& bend() const { return bend_; } + + const FPGAWord& r() const { return r_; } + const FPGAWord& z() const { return z_; } + const FPGAWord& phi() const { return phi_; } + const FPGAWord& phicorr() const { return phicorr_; } + const FPGAWord& alphanew() const { return alphanew_; } + + const FPGAWord& stubindex() const { return stubindex_; } + const FPGAWord& layer() const { return layer_; } + const FPGAWord& disk() const { return disk_; } + unsigned int layerdisk() const; + + bool isBarrel() const { return layer_.value() != -1; } + bool isDisk() const { return disk_.value() != 0; } + + bool isPSmodule() const { return isBarrel() ? (layer_.value() < (int)N_PSLAYER) : (r_.value() > 10); } + + double rapprox() const; + double zapprox() const; + double phiapprox(double phimin, double) const; + + L1TStub* l1tstub() { return l1tstub_; } + const L1TStub* l1tstub() const { return l1tstub_; } + void setl1tstub(L1TStub* l1tstub) { l1tstub_ = l1tstub; } + + private: + FPGAWord layer_; + FPGAWord disk_; + FPGAWord r_; + FPGAWord z_; + FPGAWord phi_; + FPGAWord alphanew_; + + FPGAWord bend_; + + FPGAWord phicorr_; //Corrected for bend to nominal radius + + FPGAWord stubindex_; + + L1TStub* l1tstub_; + Settings const& settings_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h b/L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h new file mode 100644 index 0000000000000..cc219691a61ff --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h @@ -0,0 +1,52 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_StubPairsMemory_h +#define L1Trigger_TrackFindingTracklet_interface_StubPairsMemory_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMStubTE.h" + +#include + +namespace trklet { + + class Settings; + + class StubPairsMemory : public MemoryBase { + public: + StubPairsMemory(std::string name, Settings const& settings, unsigned int iSector); + + ~StubPairsMemory() override = default; + + void addStubPair(const VMStubTE& stub1, + const VMStubTE& stub2, + const unsigned index = 0, + const std::string& tedName = "") { + stubs_.emplace_back(stub1, stub2); + indices_.push_back(index); + tedNames_.push_back(tedName); + } + + unsigned int nStubPairs() const { return stubs_.size(); } + + const VMStubTE& getVMStub1(unsigned int i) const { return stubs_[i].first; } + const VMStubTE& getVMStub2(unsigned int i) const { return stubs_[i].second; } + + unsigned getIndex(const unsigned i) const { return indices_.at(i); } + const std::string& getTEDName(const unsigned i) const { return tedNames_.at(i); } + + void clean() override { + stubs_.clear(); + indices_.clear(); + tedNames_.clear(); + } + + void writeSP(bool first); + + private: + std::vector > stubs_; + + std::vector indices_; + std::vector tedNames_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/StubTripletsMemory.h b/L1Trigger/TrackFindingTracklet/interface/StubTripletsMemory.h new file mode 100644 index 0000000000000..ecb2163251a38 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/StubTripletsMemory.h @@ -0,0 +1,47 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_StubTripletsMemory_h +#define L1Trigger_TrackFindingTracklet_interface_StubTripletsMemory_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" + +#include + +namespace trklet { + + class Settings; + class Stub; + class L1TStub; + + class StubTripletsMemory : public MemoryBase { + public: + StubTripletsMemory(std::string name, Settings const& settings, unsigned int iSector); + + ~StubTripletsMemory() override = default; + + void addStubs(const Stub* stub1, const Stub* stub2, const Stub* stub3) { + stubs1_.push_back(stub1); + stubs2_.push_back(stub2); + stubs3_.push_back(stub3); + } + + unsigned int nStubTriplets() const { return stubs1_.size(); } + + const Stub* getFPGAStub1(unsigned int i) const { return stubs1_[i]; } + const Stub* getFPGAStub2(unsigned int i) const { return stubs2_[i]; } + const Stub* getFPGAStub3(unsigned int i) const { return stubs3_[i]; } + + void clean() override { + stubs1_.clear(); + stubs2_.clear(); + stubs3_.clear(); + } + + void writeST(bool first); + + private: + std::vector stubs1_; + std::vector stubs2_; + std::vector stubs3_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TETableBase.h b/L1Trigger/TrackFindingTracklet/interface/TETableBase.h new file mode 100644 index 0000000000000..754ac6345c4c4 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/TETableBase.h @@ -0,0 +1,33 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_TETableBase_h +#define L1Trigger_TrackFindingTracklet_interface_TETableBase_h + +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +#include +#include +#include +#include +#include + +namespace trklet { + + class Settings; + + class TETableBase { + public: + TETableBase(Settings const& settings); + + virtual ~TETableBase() = default; + + virtual void lookup(int, int) {} + + void writeVMTable(std::string name, bool positive = true); + + protected: + Settings const& settings_; + std::vector table_; + int nbits_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/Timer.h b/L1Trigger/TrackFindingTracklet/interface/Timer.h new file mode 100644 index 0000000000000..866fe655aec68 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/Timer.h @@ -0,0 +1,30 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_Timer_h +#define L1Trigger_TrackFindingTracklet_interface_Timer_h + +#include +#include + +namespace trklet { + + class Timer { + public: + Timer() {} + + ~Timer() = default; + + void start(); + void stop(); + unsigned int ntimes() const { return ntimes_; } + double avgtime() const { return ttot_ / ntimes_; } + double rms() const { return sqrt((ttot_ * ttot_ - ttotsq_)) / ntimes_; } + double tottime() const { return ttot_; } + + private: + unsigned int ntimes_{0}; + double ttot_{0.0}; + double ttotsq_{0.0}; + + std::chrono::high_resolution_clock::time_point tstart_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/Track.h b/L1Trigger/TrackFindingTracklet/interface/Track.h new file mode 100644 index 0000000000000..cbf27a81c3f63 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/Track.h @@ -0,0 +1,100 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_Track_h +#define L1Trigger_TrackFindingTracklet_interface_Track_h + +#include +#include +#include +#include +#include +#include + +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" +#include "L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackPars.h" + +namespace trklet { + + class Track { + public: + Track(TrackPars ipars, + int ichisqrphi, + int ichisqrz, + double chisqrphi, + double chisqrz, + int hitpattern, + std::map stubID, + const std::vector& l1stub, + int seed); + + ~Track() = default; + + void setDuplicate(bool flag) { duplicate_ = flag; } + void setSector(int nsec) { sector_ = nsec; } + void setStubIDpremerge(std::vector> stubIDpremerge) { stubIDpremerge_ = stubIDpremerge; } + void setStubIDprefit(std::vector> stubIDprefit) { stubIDprefit_ = stubIDprefit; } + + const TrackPars& pars() const { return ipars_; } + + int ichisq() const { return ichisqrphi_ + ichisqrz_; } + + const std::map& stubID() const { return stubID_; } + const std::vector& stubs() const { return l1stub_; } + + //These are not used? Should be removed? + const std::vector>& stubIDpremerge() const { return stubIDpremerge_; } + const std::vector>& stubIDprefit() const { return stubIDprefit_; } + + int hitpattern() const { return hitpattern_; } + int seed() const { return seed_; } + int duplicate() const { return duplicate_; } + int sector() const { return sector_; } + + double pt(Settings const& settings) const { + return (settings.c() * settings.bfield() * 0.01) / (ipars_.rinv() * settings.krinvpars()); + } + + double phi0(Settings const& settings) const; + + double eta(Settings const& settings) const { return asinh(ipars_.t() * settings.ktpars()); } + double tanL(Settings const& settings) const { return ipars_.t() * settings.ktpars(); } + double z0(Settings const& settings) const { return ipars_.z0() * settings.kz0pars(); } + double rinv(Settings const& settings) const { return ipars_.rinv() * settings.krinvpars(); } + double d0(Settings const& settings) const { return ipars_.d0() * settings.kd0pars(); } + double chisq() const { return chisqrphi_ + chisqrz_; } + + double chisqrphi() const { return chisqrphi_; } + double chisqrz() const { return chisqrz_; } + + int nPSstubs() const { + int npsstubs = 0; + for (auto istub : l1stub_) { + if (istub->layer() < N_PSLAYER) + npsstubs++; + } + return npsstubs; + } + + private: + TrackPars ipars_; + int ichisqrphi_; + int ichisqrz_; + + double chisqrphi_; + double chisqrz_; + + int hitpattern_; + + std::vector> stubIDpremerge_; + std::vector> stubIDprefit_; + std::map stubID_; + std::vector l1stub_; + + unsigned int nstubs_; + int seed_; + bool duplicate_; + int sector_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackDer.h b/L1Trigger/TrackFindingTracklet/interface/TrackDer.h new file mode 100644 index 0000000000000..d8ac1cae0eb91 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/TrackDer.h @@ -0,0 +1,120 @@ +// +// This class holdes the 'deriviatives' used in the linearized chi^2 fit. +// This is also referred to as the weight matrix which is used to weight +// the residuls when calculating the updated track parameters. +// +// +#ifndef L1Trigger_TrackFindingTracklet_interface_TrackDer_h +#define L1Trigger_TrackFindingTracklet_interface_TrackDer_h + +#include +#include +#include +#include +#include + +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +namespace trklet { + + class TrackDer { + public: + TrackDer(); + + ~TrackDer() = default; + + void setIndex(int layermask, int diskmask, int alphamask, int irinv); + + int layerMask() const { return layermask_; } + int diskMask() const { return diskmask_; } + int alphaMask() const { return alphamask_; } + int irinv() const { return irinv_; } + + void setirinvdphi(int i, int irinvdphi) { irinvdphi_[i] = irinvdphi; } + void setirinvdzordr(int i, int irinvdzordr) { irinvdzordr_[i] = irinvdzordr; } + void setiphi0dphi(int i, int iphi0dphi) { iphi0dphi_[i] = iphi0dphi; } + void setiphi0dzordr(int i, int iphi0dzordr) { iphi0dzordr_[i] = iphi0dzordr; } + void setitdphi(int i, int itdphi) { itdphi_[i] = itdphi; } + void setitdzordr(int i, int itdzordr) { itdzordr_[i] = itdzordr; } + void setiz0dphi(int i, int iz0dphi) { iz0dphi_[i] = iz0dphi; } + void setiz0dzordr(int i, int iz0dzordr) { iz0dzordr_[i] = iz0dzordr; } + + void setitdzcorr(int i, int j, int itdzcorr) { itdzcorr_[i][j] = itdzcorr; } + void setiz0dzcorr(int i, int j, int iz0dzcorr) { iz0dzcorr_[i][j] = iz0dzcorr; } + + void setrinvdphi(int i, double rinvdphi) { rinvdphi_[i] = rinvdphi; } + void setrinvdzordr(int i, double rinvdzordr) { rinvdzordr_[i] = rinvdzordr; } + void setphi0dphi(int i, double phi0dphi) { phi0dphi_[i] = phi0dphi; } + void setphi0dzordr(int i, double phi0dzordr) { phi0dzordr_[i] = phi0dzordr; } + void settdphi(int i, double tdphi) { tdphi_[i] = tdphi; } + void settdzordr(int i, double tdzordr) { tdzordr_[i] = tdzordr; } + void setz0dphi(int i, double z0dphi) { z0dphi_[i] = z0dphi; } + void setz0dzordr(int i, double z0dzordr) { z0dzordr_[i] = z0dzordr; } + + void settdzcorr(int i, int j, double tdzcorr) { tdzcorr_[i][j] = tdzcorr; } + void setz0dzcorr(int i, int j, double z0dzcorr) { z0dzcorr_[i][j] = z0dzcorr; } + + double rinvdphi(int i) const { return rinvdphi_[i]; } + double rinvdzordr(int i) const { return rinvdzordr_[i]; } + double phi0dphi(int i) const { return phi0dphi_[i]; } + double phi0dzordr(int i) const { return phi0dzordr_[i]; } + double tdphi(int i) const { return tdphi_[i]; } + double tdzordr(int i) const { return tdzordr_[i]; } + double z0dphi(int i) const { return z0dphi_[i]; } + double z0dzordr(int i) const { return z0dzordr_[i]; } + + double tdzcorr(int i, int j) const { return tdzcorr_[i][j]; } + double z0dzcorr(int i, int j) const { return z0dzcorr_[i][j]; } + + double irinvdphi(int i) const { return irinvdphi_[i]; } + double irinvdzordr(int i) const { return irinvdzordr_[i]; } + double iphi0dphi(int i) const { return iphi0dphi_[i]; } + double iphi0dzordr(int i) const { return iphi0dzordr_[i]; } + double itdphi(int i) const { return itdphi_[i]; } + double itdzordr(int i) const { return itdzordr_[i]; } + double iz0dphi(int i) const { return iz0dphi_[i]; } + double iz0dzordr(int i) const { return iz0dzordr_[i]; } + + int itdzcorr(int i, int j) const { return itdzcorr_[i][j]; } + int iz0dzcorr(int i, int j) const { return iz0dzcorr_[i][j]; } + + void settpar(double t) { t_ = t; } + double tpar() const { return t_; } + + void fill(int t, double MinvDt[N_FITPARAM][N_FITSTUB * 2], int iMinvDt[N_FITPARAM][N_FITSTUB * 2]) const; + + private: + int irinvdphi_[N_FITSTUB]; + int irinvdzordr_[N_FITSTUB]; + int iphi0dphi_[N_FITSTUB]; + int iphi0dzordr_[N_FITSTUB]; + int itdphi_[N_FITSTUB]; + int itdzordr_[N_FITSTUB]; + int iz0dphi_[N_FITSTUB]; + int iz0dzordr_[N_FITSTUB]; + + int itdzcorr_[N_PSLAYER][N_PSLAYER]; + int iz0dzcorr_[N_PSLAYER][N_PSLAYER]; + + double rinvdphi_[N_FITSTUB]; + double rinvdzordr_[N_FITSTUB]; + double phi0dphi_[N_FITSTUB]; + double phi0dzordr_[N_FITSTUB]; + double tdphi_[N_FITSTUB]; + double tdzordr_[N_FITSTUB]; + double z0dphi_[N_FITSTUB]; + double z0dzordr_[N_FITSTUB]; + + double tdzcorr_[N_PSLAYER][N_PSLAYER]; + double z0dzcorr_[N_PSLAYER][N_PSLAYER]; + + double t_; + + int layermask_; + int diskmask_; + int alphamask_; + int irinv_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackDerTable.h b/L1Trigger/TrackFindingTracklet/interface/TrackDerTable.h new file mode 100644 index 0000000000000..b88ce5e26ef38 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/TrackDerTable.h @@ -0,0 +1,86 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_TrackDerTable_h +#define L1Trigger_TrackFindingTracklet_interface_TrackDerTable_h + +#include +#include +#include +#include +#include +#include + +#include "L1Trigger/TrackFindingTracklet/interface/TrackDer.h" + +namespace trklet { + + class Settings; + class Globals; + + class TrackDerTable { + public: + TrackDerTable(Settings const& settings); + + ~TrackDerTable() = default; + + const TrackDer* getDerivatives(int index) const { return &derivatives_[index]; } + + const TrackDer* getDerivatives(unsigned int layermask, + unsigned int diskmask, + unsigned int alphaindex, + unsigned int rinvindex) const; + + int getIndex(unsigned int layermask, unsigned int diskmask) const; + + void addEntry(unsigned int layermask, unsigned int diskmask, int multiplicity, int nrinv); + + void readPatternFile(std::string fileName); + + int getEntries() const { return nextLayerDiskValue_; } + + void fillTable(); + + static void invert(double M[4][8], unsigned int n); + + static void invert(std::vector >& M, unsigned int n); + + static void calculateDerivatives(Settings const& settings, + unsigned int nlayers, + double r[N_LAYER], + unsigned int ndisks, + double z[N_DISK], + double alpha[N_DISK], + double t, + double rinv, + double D[N_FITPARAM][N_FITSTUB * 2], + int iD[N_FITPARAM][N_FITSTUB * 2], + double MinvDt[N_FITPARAM][N_FITSTUB * 2], + int iMinvDt[N_FITPARAM][N_FITSTUB * 2], + double sigma[N_FITSTUB * 2], + double kfactor[N_FITSTUB * 2]); + + static double tpar(Settings const& settings, int diskmask, int layermask); + + private: + Settings const& settings_; + + std::vector LayerMem_; + std::vector DiskMem_; + std::vector LayerDiskMem_; + + unsigned int LayerMemBits_; + unsigned int DiskMemBits_; + unsigned int LayerDiskMemBits_; + unsigned int alphaBits_; + + unsigned int Nlay_; + unsigned int Ndisk_; + + std::vector derivatives_; + + int nextLayerValue_; + int nextDiskValue_; + int nextLayerDiskValue_; + int lastMultiplicity_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackFitMemory.h b/L1Trigger/TrackFindingTracklet/interface/TrackFitMemory.h new file mode 100644 index 0000000000000..6775080971f1a --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/TrackFitMemory.h @@ -0,0 +1,50 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_TrackFitMemory_h +#define L1Trigger_TrackFindingTracklet_interface_TrackFitMemory_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" + +#include + +namespace trklet { + + class Settings; + class Stub; + class L1TStub; + class Tracklet; + + class TrackFitMemory : public MemoryBase { + public: + TrackFitMemory(std::string name, Settings const& settings, unsigned int iSector, double phimin, double phimax); + + ~TrackFitMemory() override = default; + + void addTrack(Tracklet* tracklet) { tracks_.push_back(tracklet); } + void addStubList(std::vector stublist) { stublists_.push_back(stublist); } + void addStubidsList(std::vector> stubidslist) { stubidslists_.push_back(stubidslist); } + + unsigned int nTracks() const { return tracks_.size(); } + unsigned int nStublists() const { return stublists_.size(); } + unsigned int nStubidslists() const { return stubidslists_.size(); } + + Tracklet* getTrack(unsigned int i) { return tracks_[i]; } + std::vector getStublist(unsigned int i) const { return stublists_[i]; } + std::vector> getStubidslist(unsigned int i) const { return stubidslists_[i]; } + + void clean() override { + tracks_.clear(); + stublists_.clear(); + stubidslists_.clear(); + } + + void writeTF(bool first); + + private: + double phimin_; + double phimax_; + std::vector tracks_; + std::vector> stublists_; + std::vector>> stubidslists_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackPars.h b/L1Trigger/TrackFindingTracklet/interface/TrackPars.h new file mode 100644 index 0000000000000..1a394e6dac8a1 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/TrackPars.h @@ -0,0 +1,50 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_TrackPars_h +#define L1Trigger_TrackFindingTracklet_interface_TrackPars_h + +namespace trklet { + + template + class TrackPars { + public: + TrackPars() = default; + + TrackPars(T rinv, T phi0, T d0, T t, T z0) { + rinv_ = rinv; + phi0_ = phi0; + d0_ = d0; + t_ = t; + z0_ = z0; + } + + ~TrackPars() = default; + + void init(T rinv, T phi0, T d0, T t, T z0) { + rinv_ = rinv; + phi0_ = phi0; + d0_ = d0; + t_ = t; + z0_ = z0; + } + + const T& rinv() const { return rinv_; } + const T& phi0() const { return phi0_; } + const T& d0() const { return d0_; } + const T& t() const { return t_; } + const T& z0() const { return z0_; } + + T& rinv() { return rinv_; } + T& phi0() { return phi0_; } + T& d0() { return d0_; } + T& t() { return t_; } + T& z0() { return z0_; } + + private: + T rinv_; + T phi0_; + T d0_; + T t_; + T z0_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/Tracklet.h b/L1Trigger/TrackFindingTracklet/interface/Tracklet.h new file mode 100644 index 0000000000000..41899ba349500 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/Tracklet.h @@ -0,0 +1,567 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_Tracklet_h +#define L1Trigger_TrackFindingTracklet_interface_Tracklet_h + +#include +#include +#include +#include +#include +#include + +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" +#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" +#include "L1Trigger/TrackFindingTracklet/interface/Track.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackPars.h" +#include "L1Trigger/TrackFindingTracklet/interface/LayerProjection.h" +#include "L1Trigger/TrackFindingTracklet/interface/DiskProjection.h" +#include "L1Trigger/TrackFindingTracklet/interface/LayerResidual.h" +#include "L1Trigger/TrackFindingTracklet/interface/DiskResidual.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" + +namespace trklet { + + class Settings; + class Stub; + class Track; + + class Tracklet { + public: + Tracklet(Settings const& settings, + const L1TStub* innerStub, + const L1TStub* middleStub, + const L1TStub* outerStub, + const Stub* innerFPGAStub, + const Stub* middleFPGAStub, + const Stub* outerFPGAStub, + double rinv, + double phi0, + double d0, + double z0, + double t, + double rinvapprox, + double phi0approx, + double d0approx, + double z0approx, + double tapprox, + int irinv, + int iphi0, + int id0, + int iz0, + int it, + LayerProjection layerprojs[N_PROJ], + DiskProjection diskprojs[N_PROJ], + bool disk, + bool overlap = false); + + ~Tracklet() = default; + + //Find tp corresponding to seed. + //Will require 'tight match' such that tp is part of each of the four clustes returns 0 if no tp matches + int tpseed(); + + bool stubtruthmatch(const L1TStub* stub); + + const L1TStub* innerStub() { return innerStub_; } + const Stub* innerFPGAStub() { return innerFPGAStub_; } + + const L1TStub* middleStub() { return middleStub_; } + const Stub* middleFPGAStub() { return middleFPGAStub_; } + + const L1TStub* outerStub() { return outerStub_; } + const Stub* outerFPGAStub() { return outerFPGAStub_; } + + std::string addressstr(); + + //Tracklet parameters print out + std::string trackletparstr(); + + std::string vmstrlayer(int layer, unsigned int allstubindex); + + std::string vmstrdisk(int disk, unsigned int allstubindex); + + std::string trackletprojstr(int layer) const; + std::string trackletprojstrD(int disk) const; + + std::string trackletprojstrlayer(int layer) const { return trackletprojstr(layer); } + std::string trackletprojstrdisk(int disk) const { return trackletprojstrD(disk); } + + bool validProj(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].valid(); + } + + const FPGAWord& fpgaphiprojder(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].fpgaphiprojder(); + } + + const FPGAWord& fpgazproj(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].fpgazproj(); + } + + const FPGAWord& fpgaphiproj(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].fpgaphiproj(); + } + + const FPGAWord& fpgazprojder(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].fpgazprojder(); + } + + int zbin1projvm(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].fpgazbin1projvm().value(); + } + + int zbin2projvm(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].fpgazbin2projvm().value(); + } + + int finezvm(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].fpgafinezvm().value(); + } + + int rbin1projvm(int disk) const { + assert(disk > 0 && disk <= N_DISK); + return diskproj_[disk - 1].fpgarbin1projvm().value(); + } + + int rbin2projvm(int disk) const { + assert(disk > 0 && disk <= N_DISK); + return diskproj_[disk - 1].fpgarbin2projvm().value(); + } + + int finervm(int disk) const { + assert(disk > 0 && disk <= N_DISK); + return diskproj_[disk - 1].fpgafinervm().value(); + } + + int phiprojvm(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].fpgaphiprojvm().value(); + } + + int zprojvm(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].fpgazprojvm().value(); + } + + double phiproj(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].phiproj(); + } + + double phiprojder(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].phiprojder(); + } + + double zproj(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].zproj(); + } + + double zprojder(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].zprojder(); + } + + double zprojapprox(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].zprojapprox(); + } + + double zprojderapprox(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].zprojderapprox(); + } + + double phiprojapprox(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].phiprojapprox(); + } + + double phiprojderapprox(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].phiprojderapprox(); + } + + double rproj(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerproj_[layer - 1].rproj(); + } + + double rstub(int layer) { + assert(layer > 0 && layer <= N_LAYER); + return layerresid_[layer - 1].rstub(); + } + + //Disks residuals + + bool validProjDisk(int disk) const { + assert(abs(disk) <= N_DISK); + return diskproj_[abs(disk) - 1].valid(); + } + + const FPGAWord& fpgaphiresiddisk(int disk) { + assert(abs(disk) <= N_DISK); + return diskresid_[abs(disk) - 1].fpgaphiresid(); + } + + const FPGAWord& fpgarresiddisk(int disk) { + assert(abs(disk) <= N_DISK); + return diskresid_[abs(disk) - 1].fpgarresid(); + } + + double phiresiddisk(int disk) { + assert(abs(disk) <= N_DISK); + return diskresid_[abs(disk) - 1].phiresid(); + } + + double rresiddisk(int disk) { + assert(abs(disk) <= N_DISK); + return diskresid_[abs(disk) - 1].rresid(); + } + + double phiresidapproxdisk(int disk) { + assert(abs(disk) <= N_DISK); + return diskresid_[abs(disk) - 1].phiresidapprox(); + } + + double rresidapproxdisk(int disk) { + assert(abs(disk) <= N_DISK); + return diskresid_[abs(disk) - 1].rresidapprox(); + } + + double zstubdisk(int disk) { + assert(abs(disk) <= N_DISK); + return diskresid_[abs(disk) - 1].zstub(); + } + + void setBendIndex(int bendIndex, int disk) { + assert(abs(disk) <= N_DISK); + diskproj_[abs(disk) - 1].setBendIndex(bendIndex); + } + + const FPGAWord& getBendIndex(int disk) const { + assert(abs(disk) <= N_DISK); + return diskproj_[abs(disk) - 1].getBendIndex(); + } + + double alphadisk(int disk) const { + assert(abs(disk) <= N_DISK); + return diskresid_[abs(disk) - 1].alpha(); + } + + const FPGAWord& ialphadisk(int disk) const { + assert(abs(disk) <= N_DISK); + return diskresid_[abs(disk) - 1].ialpha(); + } + + const FPGAWord& fpgaphiprojdisk(int disk) const { + assert(abs(disk) <= N_DISK); + return diskproj_[abs(disk) - 1].fpgaphiproj(); + } + + const FPGAWord& fpgaphiprojderdisk(int disk) const { + assert(abs(disk) <= N_DISK); + return diskproj_[abs(disk) - 1].fpgaphiprojder(); + } + + const FPGAWord& fpgarprojdisk(int disk) const { + assert(abs(disk) <= N_DISK); + return diskproj_[abs(disk) - 1].fpgarproj(); + } + + const FPGAWord& fpgarprojderdisk(int disk) const { + assert(abs(disk) <= N_DISK); + return diskproj_[abs(disk) - 1].fpgarprojder(); + } + + double phiprojapproxdisk(int disk) const { + assert(abs(disk) <= N_DISK); + return diskproj_[abs(disk) - 1].phiprojapprox(); + } + + double phiprojderapproxdisk(int disk) const { + assert(abs(disk) <= N_DISK); + return diskproj_[abs(disk) - 1].phiprojderapprox(); + } + + double rprojapproxdisk(int disk) const { + assert(abs(disk) <= N_DISK); + return diskproj_[abs(disk) - 1].rprojapprox(); + } + + double rprojderapproxdisk(int disk) const { + assert(abs(disk) <= N_DISK); + return diskproj_[abs(disk) - 1].rprojderapprox(); + } + + double phiprojdisk(int disk) const { + assert(abs(disk) <= N_DISK); + return diskproj_[abs(disk) - 1].phiproj(); + } + + double phiprojderdisk(int disk) const { + assert(abs(disk) <= N_DISK); + return diskproj_[abs(disk) - 1].phiprojder(); + } + + double rprojdisk(int disk) const { + assert(abs(disk) <= N_DISK); + return diskproj_[abs(disk) - 1].rproj(); + } + + double rprojderdisk(int disk) const { + assert(abs(disk) <= N_DISK); + return diskproj_[abs(disk) - 1].rprojder(); + } + + bool matchdisk(int disk) { + assert(abs(disk) <= N_DISK); + return diskresid_[abs(disk) - 1].valid(); + } + + void addMatch(int layer, + int ideltaphi, + int ideltaz, + double dphi, + double dz, + double dphiapprox, + double dzapprox, + int stubid, + double rstub, + const trklet::Stub* stubptr); + + void addMatchDisk(int disk, + int ideltaphi, + int ideltar, + double dphi, + double dr, + double dphiapprox, + double drapprox, + double alpha, + int stubid, + double zstub, + const trklet::Stub* stubptr); + + int nMatches(); + int nMatchesDisk(); + + bool match(int layer) { + assert(layer > 0 && layer <= N_LAYER); + return layerresid_[layer - 1].valid(); + } + + std::string fullmatchstr(int layer); + std::string fullmatchdiskstr(int disk); + + bool validResid(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerresid_[layer - 1].valid(); + } + + const trklet::Stub* stubptr(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerresid_[layer - 1].stubptr(); + } + + double phiresid(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerresid_[layer - 1].phiresid(); + } + + double phiresidapprox(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerresid_[layer - 1].phiresidapprox(); + } + + double zresid(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerresid_[layer - 1].zresid(); + } + + double zresidapprox(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerresid_[layer - 1].zresidapprox(); + } + + const FPGAWord& fpgaphiresid(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerresid_[layer - 1].fpgaphiresid(); + } + + const FPGAWord& fpgazresid(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + return layerresid_[layer - 1].fpgazresid(); + } + + std::vector getL1Stubs(); + + std::map getStubIDs(); + + double rinv() const { return trackpars_.rinv(); } + double phi0() const { return trackpars_.phi0(); } + double d0() const { return trackpars_.d0(); } + double t() const { return trackpars_.t(); } + double z0() const { return trackpars_.z0(); } + + double rinvapprox() const { return trackparsapprox_.rinv(); } + double phi0approx() const { return trackparsapprox_.phi0(); } + double d0approx() const { return trackparsapprox_.d0(); } + double tapprox() const { return trackparsapprox_.t(); } + double z0approx() const { return trackparsapprox_.z0(); } + + const FPGAWord& fpgarinv() const { return fpgapars_.rinv(); } + const FPGAWord& fpgaphi0() const { return fpgapars_.phi0(); } + const FPGAWord& fpgad0() const { return fpgapars_.d0(); } + const FPGAWord& fpgat() const { return fpgapars_.t(); } + const FPGAWord& fpgaz0() const { return fpgapars_.z0(); } + + double rinvfit() const { return fitpars_.rinv(); } + double phi0fit() const { return fitpars_.phi0(); } + double d0fit() const { return fitpars_.d0(); } + double tfit() const { return fitpars_.t(); } + double z0fit() const { return fitpars_.z0(); } + double chiSqfit() const { return chisqrphifit_ + chisqrzfit_; } + + double rinvfitexact() const { return fitparsexact_.rinv(); } + double phi0fitexact() const { return fitparsexact_.phi0(); } + double d0fitexact() const { return fitparsexact_.d0(); } + double tfitexact() const { return fitparsexact_.t(); } + double z0fitexact() const { return fitparsexact_.z0(); } + + const FPGAWord& irinvfit() const { return fpgafitpars_.rinv(); } + const FPGAWord& iphi0fit() const { return fpgafitpars_.phi0(); } + const FPGAWord& id0fit() const { return fpgafitpars_.d0(); } + const FPGAWord& itfit() const { return fpgafitpars_.t(); } + const FPGAWord& iz0fit() const { return fpgafitpars_.z0(); } + FPGAWord ichiSqfit() const { + return FPGAWord(ichisqrphifit_.value() + ichisqrzfit_.value(), ichisqrphifit_.nbits()); + } + + void setFitPars(double rinvfit, + double phi0fit, + double d0fit, + double tfit, + double z0fit, + double chisqrphifit, + double chisqrzfit, + double rinvfitexact, + double phi0fitexact, + double d0fitexact, + double tfitexact, + double z0fitexact, + double chisqrphifitexact, + double chisqrzfitexact, + int irinvfit, + int iphi0fit, + int id0fit, + int itfit, + int iz0fit, + int ichisqrphifit, + int ichisqrzfit, + int hitpattern, + const std::vector& l1stubs = std::vector()); + + std::string trackfitstr(); + + Track makeTrack(const std::vector& l1stubs); + + Track* getTrack() { + assert(fpgatrack_ != nullptr); + return fpgatrack_.get(); + } + + bool fit() const { return ichisqrphifit_.value() != -1; } + + int layer() const; + int disk() const; + int disk2() const; + + bool isBarrel() const { return barrel_; } + bool isOverlap() const { return overlap_; } + int isDisk() const { return disk_; } + + void setTrackletIndex(int index); + + int trackletIndex() const { return trackletIndex_; } + + void setTCIndex(int index) { TCIndex_ = index; } + + int TCIndex() const { return TCIndex_; } + + int TCID() const { return TCIndex_ * (1 << 7) + trackletIndex_; } + + int getISeed() const; + int getITC() const; + + unsigned int PSseed() const { return ((layer() == 1) || (layer() == 2) || (disk() != 0)) ? 1 : 0; } + + unsigned int seedIndex() const { return seedIndex_; } + + unsigned int calcSeedIndex() const; + + private: + unsigned int seedIndex_; + + // three types of tracklets + one triplet + bool barrel_; + bool disk_; + bool overlap_; + bool triplet_; + + const Stub* innerFPGAStub_; + const Stub* middleFPGAStub_; + const Stub* outerFPGAStub_; + + const L1TStub* innerStub_; + const L1TStub* middleStub_; + const L1TStub* outerStub_; + + int trackletIndex_; + int TCIndex_; + + //Tracklet track parameters + TrackPars fpgapars_; + + TrackPars trackpars_; + TrackPars trackparsapprox_; + + // the layer/disk ids that we project to (never project to >4 barrel layers) + int projlayer_[N_LAYER - 2]; + int projdisk_[N_DISK]; + + //Track parameters from track fit + TrackPars fpgafitpars_; + FPGAWord ichisqrphifit_; + FPGAWord ichisqrzfit_; + + TrackPars fitpars_; + double chisqrphifit_; + double chisqrzfit_; + + TrackPars fitparsexact_; + double chisqrphifitexact_; + double chisqrzfitexact_; + + int hitpattern_; + + std::unique_ptr fpgatrack_; + + LayerProjection layerproj_[N_LAYER]; + DiskProjection diskproj_[N_DISK]; + + LayerResidual layerresid_[N_LAYER]; + DiskResidual diskresid_[N_DISK]; + + Settings const& settings_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h new file mode 100644 index 0000000000000..cb1fb663b2978 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h @@ -0,0 +1,38 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_TrackletCalculator_h +#define L1Trigger_TrackFindingTracklet_interface_TrackletCalculator_h + +#include "L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h" + +#include +#include + +namespace trklet { + + class Settings; + class Globals; + class TrackletProjectionsMemory; + class MemoryBase; + class AllStubsMemory; + class StubPairsMemory; + + class TrackletCalculator : public TrackletCalculatorBase { + public: + TrackletCalculator(std::string name, Settings const& settings, Globals* globals, unsigned int iSector); + + ~TrackletCalculator() override = default; + + void addOutputProjection(TrackletProjectionsMemory*& outputProj, MemoryBase* memory); + void addOutput(MemoryBase* memory, std::string output) override; + void addInput(MemoryBase* memory, std::string input) override; + + void execute(); + + private: + int iTC_; + + std::vector innerallstubs_; + std::vector outerallstubs_; + std::vector stubpairs_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h new file mode 100644 index 0000000000000..46bc10760ac1c --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h @@ -0,0 +1,147 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_TrackletCalculatorBase_h +#define L1Trigger_TrackFindingTracklet_interface_TrackletCalculatorBase_h + +#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h" + +#include + +namespace trklet { + + class Settings; + class Globals; + class Stub; + class L1TStub; + class Tracklet; + + class TrackletCalculatorBase : public ProcessBase { + public: + TrackletCalculatorBase(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + + ~TrackletCalculatorBase() override = default; + + void exacttracklet(double r1, + double z1, + double phi1, + double r2, + double z2, + double phi2, + double, + double& rinv, + double& phi0, + double& t, + double& z0, + double phiproj[N_LAYER - 2], //=4 + double zproj[N_LAYER - 2], + double phider[N_LAYER - 2], + double zder[N_LAYER - 2], + double phiprojdisk[N_DISK], //=5 + double rprojdisk[N_DISK], + double phiderdisk[N_DISK], + double rderdisk[N_DISK]); + + void exacttrackletdisk(double r1, + double z1, + double phi1, + double r2, + double z2, + double phi2, + double, + double& rinv, + double& phi0, + double& t, + double& z0, + double phiprojLayer[N_PSLAYER], //=3 + double zprojLayer[N_PSLAYER], + double phiderLayer[N_PSLAYER], + double zderLayer[N_PSLAYER], + double phiproj[N_DISK - 2], //=3 + double rproj[N_DISK - 2], + double phider[N_DISK - 2], + double rder[N_DISK - 2]); + + void exacttrackletOverlap(double r1, + double z1, + double phi1, + double r2, + double z2, + double phi2, + double, + double& rinv, + double& phi0, + double& t, + double& z0, + double phiprojLayer[N_PSLAYER], //=3 + double zprojLayer[N_PSLAYER], + double phiderLayer[N_PSLAYER], + double zderLayer[N_PSLAYER], + double phiproj[N_DISK - 2], //=3 + double rproj[N_DISK - 2], + double phider[N_DISK - 2], + double rder[N_DISK - 2]); + + void exactproj(double rproj, + double rinv, + double phi0, + double t, + double z0, + double& phiproj, + double& zproj, + double& phider, + double& zder); + + void exactprojdisk(double zproj, + double rinv, + double phi0, + double t, + double z0, + double& phiproj, + double& rproj, + double& phider, + double& rder); + + void addDiskProj(Tracklet* tracklet, int disk); + bool addLayerProj(Tracklet* tracklet, int layer); + + void addProjection(int layer, int iphi, TrackletProjectionsMemory* trackletprojs, Tracklet* tracklet); + void addProjectionDisk(int disk, int iphi, TrackletProjectionsMemory* trackletprojs, Tracklet* tracklet); + + bool goodTrackPars(bool goodrinv, bool goodz0); + + bool inSector(int iphi0, int irinv, double phi0approx, double rinvapprox); + + bool barrelSeeding(const Stub* innerFPGAStub, + const L1TStub* innerStub, + const Stub* outerFPGAStub, + const L1TStub* outerStub); + bool diskSeeding(const Stub* innerFPGAStub, + const L1TStub* innerStub, + const Stub* outerFPGAStub, + const L1TStub* outerStub); + bool overlapSeeding(const Stub* innerFPGAStub, + const L1TStub* innerStub, + const Stub* outerFPGAStub, + const L1TStub* outerStub); + + protected: + unsigned int iSeed_; + unsigned int layerdisk1_; + unsigned int layerdisk2_; + + int TCIndex_; + + double phioffset_; + + int layer_; + int disk_; + + TrackletParametersMemory* trackletpars_; + + //First index is layer/disk second is phi region + std::vector > trackletprojlayers_; + std::vector > trackletprojdisks_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorDisplaced.h b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorDisplaced.h new file mode 100644 index 0000000000000..4d86e7a98310b --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorDisplaced.h @@ -0,0 +1,132 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_TrackletCalculatorDisplaced_h +#define L1Trigger_TrackFindingTracklet_interface_TrackletCalculatorDisplaced_h + +#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/StubTripletsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h" + +#include + +namespace trklet { + + class Settings; + class Globals; + class MemoryBase; + class Stub; + class L1TStub; + + class TrackletCalculatorDisplaced : public ProcessBase { + public: + TrackletCalculatorDisplaced(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + + ~TrackletCalculatorDisplaced() override = default; + + void addOutputProjection(TrackletProjectionsMemory*& outputProj, MemoryBase* memory); + + void addOutput(MemoryBase* memory, std::string output) override; + void addInput(MemoryBase* memory, std::string input) override; + + void execute(); + + void addDiskProj(Tracklet* tracklet, int disk); + bool addLayerProj(Tracklet* tracklet, int layer); + + void addProjection(int layer, int iphi, TrackletProjectionsMemory* trackletprojs, Tracklet* tracklet); + void addProjectionDisk(int disk, int iphi, TrackletProjectionsMemory* trackletprojs, Tracklet* tracklet); + + bool LLLSeeding(const Stub* innerFPGAStub, + const L1TStub* innerStub, + const Stub* middleFPGAStub, + const L1TStub* middleStub, + const Stub* outerFPGAStub, + const L1TStub* outerStub); + bool DDLSeeding(const Stub* innerFPGAStub, + const L1TStub* innerStub, + const Stub* middleFPGAStub, + const L1TStub* middleStub, + const Stub* outerFPGAStub, + const L1TStub* outerStub); + bool LLDSeeding(const Stub* innerFPGAStub, + const L1TStub* innerStub, + const Stub* middleFPGAStub, + const L1TStub* middleStub, + const Stub* outerFPGAStub, + const L1TStub* outerStub); + + void exactproj(double rproj, + double rinv, + double phi0, + double d0, + double t, + double z0, + double r0, + double& phiproj, + double& zproj, + double& phider, + double& zder); + + void exactprojdisk(double zproj, + double rinv, + double, + double, //phi0 and d0 are not used. + double t, + double z0, + double x0, + double y0, + double& phiproj, + double& rproj, + double& phider, + double& rder); + + void exacttracklet(double r1, + double z1, + double phi1, + double r2, + double z2, + double phi2, + double r3, + double z3, + double phi3, + int take3, + double& rinv, + double& phi0, + double& d0, + double& t, + double& z0, + double phiproj[N_LAYER - 2], + double zproj[N_LAYER - 2], + double phiprojdisk[N_DISK], + double rprojdisk[N_DISK], + double phider[N_LAYER - 2], + double zder[N_LAYER - 2], + double phiderdisk[N_DISK], + double rderdisk[N_DISK]); + + private: + int TCIndex_; + int layer_; + int disk_; + double rproj_[N_LAYER - 2]; + int lproj_[N_LAYER - 2]; + double zproj_[N_DISK - 2]; + int dproj_[N_DISK - 2]; + + std::vector toR_; + std::vector toZ_; + + std::vector innerallstubs_; + std::vector middleallstubs_; + std::vector outerallstubs_; + std::vector stubtriplets_; + + TrackletParametersMemory* trackletpars_; + + //First index is layer/disk second is phi region + std::vector > trackletprojlayers_; + std::vector > trackletprojdisks_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h b/L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h new file mode 100644 index 0000000000000..a6fd3f9492fe2 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h @@ -0,0 +1,55 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_TrackletEngine_h +#define L1Trigger_TrackFindingTracklet_interface_TrackletEngine_h + +#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" + +#include +#include + +namespace trklet { + + class Settings; + class Globals; + class MemoryBase; + class VMStubsTEMemory; + class StubPairsMemory; + + class TrackletEngine : public ProcessBase { + public: + TrackletEngine(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + + ~TrackletEngine() override = default; + + void addOutput(MemoryBase* memory, std::string output) override; + void addInput(MemoryBase* memory, std::string input) override; + + void execute(); + + void setVMPhiBin(); + + void writeTETable(); + + private: + //Which seed type and which layer/disk is used + unsigned int iSeed_; + unsigned int layerdisk1_; //inner seeding layer + unsigned int layerdisk2_; //outer seeding layer + + //The input vmstubs memories + VMStubsTEMemory* innervmstubs_; + VMStubsTEMemory* outervmstubs_; + + //The output stub pair memory + StubPairsMemory* stubpairs_; + + //The stub pt (bend) lookup table for the inner and outer stub + std::vector pttableinner_; + std::vector pttableouter_; + + //Number of phi bits used in the lookup table + unsigned int innerphibits_; + unsigned int outerphibits_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h b/L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h new file mode 100644 index 0000000000000..6affb50111dfb --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h @@ -0,0 +1,52 @@ +// TrackletEngineDisplaced: this class forms tracklets (pairs of stubs) w/o beamspot constraint for the displaced (extended) tracking. +// Triplet seeds are formed in the TripletEngine from these (=TrackletEngineDisplaced) + a third stub. +#ifndef L1Trigger_TrackFindingTracklet_interface_TrackletEngineDisplaced_h +#define L1Trigger_TrackFindingTracklet_interface_TrackletEngineDisplaced_h + +#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" + +#include +#include +#include + +namespace trklet { + + class Settings; + class Globals; + class MemoryBase; + class VMStubsTEMemory; + class StubPairsMemory; + + class TrackletEngineDisplaced : public ProcessBase { + public: + TrackletEngineDisplaced(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + + ~TrackletEngineDisplaced() override; + + void addOutput(MemoryBase* memory, std::string output) override; + void addInput(MemoryBase* memory, std::string input) override; + + void execute(); + + void readTables(); + + private: + int layer1_; + int layer2_; + int disk1_; + int disk2_; + + std::vector firstvmstubs_; + VMStubsTEMemory* secondvmstubs_; + + std::vector stubpairs_; + + std::vector > table_; + + int firstphibits_; + int secondphibits_; + + int iSeed_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h b/L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h new file mode 100644 index 0000000000000..854c7da49a3d6 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h @@ -0,0 +1,70 @@ +// TrackletEventProcessor: Class responsible for the main event processing for the tracklet algorithm +#ifndef L1Trigger_TrackFindingTracklet_interface_TrackletEventProcessor_h +#define L1Trigger_TrackFindingTracklet_interface_TrackletEventProcessor_h + +#include "L1Trigger/TrackFindingTracklet/interface/Timer.h" + +#include +#include +#include +#include + +namespace trklet { + + class Settings; + class SLHCEvent; + class Globals; + class Sector; + class HistBase; + class Track; + class Cabling; + + class TrackletEventProcessor { + public: + TrackletEventProcessor(); + + ~TrackletEventProcessor(); + + void init(const Settings* theSettings); + + void event(SLHCEvent& ev); + + void printSummary(); + + std::vector& tracks() { return tracks_; } + + private: + const Settings* settings_{nullptr}; + + std::unique_ptr globals_; + + std::vector > sectors_; + + HistBase* histbase_{}; + + int eventnum_ = {0}; + + std::unique_ptr cabling_; + + Timer cleanTimer_; + Timer addStubTimer_; + Timer VMRouterTimer_; + Timer TETimer_; + Timer TEDTimer_; + Timer TRETimer_; + Timer TCTimer_; + Timer TCDTimer_; + Timer PRTimer_; + Timer METimer_; + Timer MCTimer_; + Timer MPTimer_; + Timer FTTimer_; + Timer PDTimer_; + + std::vector tracks_; + + std::map > dtclayerdisk_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h b/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h new file mode 100644 index 0000000000000..088f937dcbc4c --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h @@ -0,0 +1,40 @@ +// TrackletParametersMemory: This class holds the tracklet parameters for selected stub pairs. +// This class owns the tracklets. Further modules only holds pointers. +#ifndef L1Trigger_TrackFindingTracklet_interface_TrackletParametersMemory_h +#define L1Trigger_TrackFindingTracklet_interface_TrackletParametersMemory_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" + +#include +#include + +namespace trklet { + + class Settings; + class Globals; + class Tracklet; + + class TrackletParametersMemory : public MemoryBase { + public: + TrackletParametersMemory(std::string name, Settings const &settings, unsigned int iSector); + + ~TrackletParametersMemory() override = default; + + void addTracklet(Tracklet *tracklet) { tracklets_.push_back(tracklet); } + + unsigned int nTracklets() const { return tracklets_.size(); } + + Tracklet *getTracklet(unsigned int i) { return tracklets_[i]; } + + void clean() override; + + void writeMatches(Globals *globals, int &matchesL1, int &matchesL3, int &matchesL5); + + void writeTPAR(bool first); + + private: + std::vector tracklets_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h b/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h new file mode 100644 index 0000000000000..b8cb5601cf8c0 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h @@ -0,0 +1,59 @@ +// TrackletProcessor: this class is an evolved version, performing the tasks of the TrackletEngine+TrackletCalculator. +// It will combine TEs that feed into a TC to a single module. +#ifndef L1Trigger_TrackFindingTracklet_interface_TrackletProcessor_h +#define L1Trigger_TrackFindingTracklet_interface_TrackletProcessor_h + +#include "L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" + +#include +#include + +namespace trklet { + + class Settings; + class Globals; + class MemoryBase; + + class TrackletProcessor : public TrackletCalculatorBase { + public: + TrackletProcessor(std::string name, Settings const& settings, Globals* globals, unsigned int iSector); + + ~TrackletProcessor() override = default; + + void addOutputProjection(TrackletProjectionsMemory*& outputProj, MemoryBase* memory); + + void addOutput(MemoryBase* memory, std::string output) override; + + void addInput(MemoryBase* memory, std::string input) override; + + void execute(); + + void setVMPhiBin(); + + void writeTETable(); + + private: + int iTC_; + + std::vector innervmstubs_; + std::vector outervmstubs_; + + std::vector innerallstubs_; + std::vector outerallstubs_; + + bool extra_; + + std::map > phitable_; + std::map > pttableinner_; + std::map > pttableouter_; + + int innerphibits_; + int outerphibits_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h b/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h new file mode 100644 index 0000000000000..3d376d3b98dcc --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h @@ -0,0 +1,42 @@ +// TrackletProjectionsMemory: this class holds the +#ifndef L1Trigger_TrackFindingTracklet_interface_TrackletProjectionsMemory_h +#define L1Trigger_TrackFindingTracklet_interface_TrackletProjectionsMemory_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" + +#include +#include + +namespace trklet { + + class Settings; + class Tracklet; + + class TrackletProjectionsMemory : public MemoryBase { + public: + TrackletProjectionsMemory(std::string name, Settings const& settings, unsigned int iSector); + + ~TrackletProjectionsMemory() override = default; + + void addProj(Tracklet* tracklet); + + unsigned int nTracklets() const { return tracklets_.size(); } + + Tracklet* getTracklet(unsigned int i) { return tracklets_[i]; } + + void clean() override; + + void writeTPROJ(bool first); + + int layer() const { return layer_; } + int disk() const { return disk_; } + + private: + std::vector tracklets_; + + int layer_; + int disk_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TripletEngine.h b/L1Trigger/TrackFindingTracklet/interface/TripletEngine.h new file mode 100644 index 0000000000000..1652262c1808a --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/TripletEngine.h @@ -0,0 +1,70 @@ +// TripletEngine: Adds third stub to stub pairs found by TrackletEngineDisplaced to form "triplet" seeds for the displaced (extended) tracking +#ifndef L1Trigger_TrackFindingTracklet_interface_TripletEngine_h +#define L1Trigger_TrackFindingTracklet_interface_TripletEngine_h + +#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/StubTripletsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h" + +#include +#include + +namespace trklet { + + class Settings; + class Globals; + + class TripletEngine : public ProcessBase { + public: + TripletEngine(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + + ~TripletEngine() override; + + void addOutput(MemoryBase* memory, std::string output) override; + void addInput(MemoryBase* memory, std::string input) override; + + void execute(); + + void readTables(); + void writeTables(); + + private: + int count_; + + int layer1_; + int layer2_; + int layer3_; + int disk1_; + int disk2_; + int disk3_; + int dct1_; + int dct2_; + int dct3_; + int phi1_; + int phi2_; + int phi3_; + int z1_; + int z2_; + int z3_; + int r1_; + int r2_; + int r3_; + + std::vector thirdvmstubs_; + std::vector stubpairs_; + + StubTripletsMemory* stubtriplets_; + + std::map > > tmpSPTable_; + std::map > > spTable_; + std::vector table_; + + int secondphibits_; + int thirdphibits_; + + int iSeed_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/Util.h b/L1Trigger/TrackFindingTracklet/interface/Util.h new file mode 100644 index 0000000000000..6d448d3109bff --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/Util.h @@ -0,0 +1,179 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_Util_h +#define L1Trigger_TrackFindingTracklet_interface_Util_h + +#include +#include +#include + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +namespace trklet { + + //Converts string in binary to hex (used in writing out memory content) + inline std::string hexFormat(const std::string& binary) { + std::string tmp = ""; + + unsigned int value = 0; + + for (unsigned int i = 0; i < binary.size(); i++) { + unsigned int slot = binary.size() - i - 1; + if (!(binary[slot] == '0' || binary[slot] == '1')) + continue; + value = value + (binary[slot] - '0'); + } + + std::stringstream ss; + ss << "0x" << std::hex << value; + + return ss.str(); + } + + //Should be optimized by layer - now first implementation to make sure it works OK + inline int bendencode(double bend, bool isPS) { + int ibend = 2.0 * bend; + + assert(std::abs(ibend - 2.0 * bend) < 0.1); + + if (isPS) { + if (ibend == 0 || ibend == 1) + return 0; + if (ibend == 2 || ibend == 3) + return 1; + if (ibend == 4 || ibend == 5) + return 2; + if (ibend >= 6) + return 3; + if (ibend == -1 || ibend == -2) + return 4; + if (ibend == -3 || ibend == -4) + return 5; + if (ibend == -5 || ibend == -6) + return 6; + if (ibend <= -7) + return 7; + + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ + << " Unknown bendencode for PS module for bend = " << bend + << " ibend = " << ibend; + } + + if (ibend == 0 || ibend == 1) + return 0; + if (ibend == 2 || ibend == 3) + return 1; + if (ibend == 4 || ibend == 5) + return 2; + if (ibend == 6 || ibend == 7) + return 3; + if (ibend == 8 || ibend == 9) + return 4; + if (ibend == 10 || ibend == 11) + return 5; + if (ibend == 12 || ibend == 13) + return 6; + if (ibend >= 14) + return 7; + if (ibend == -1 || ibend == -2) + return 8; + if (ibend == -3 || ibend == -4) + return 9; + if (ibend == -5 || ibend == -6) + return 10; + if (ibend == -7 || ibend == -8) + return 11; + if (ibend == -9 || ibend == -10) + return 12; + if (ibend == -11 || ibend == -12) + return 13; + if (ibend == -13 || ibend == -14) + return 14; + if (ibend <= -15) + return 15; + + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ + << " Unknown bendencode for 2S module for bend = " << bend + << " ibend = " << ibend; + } + + //Should be optimized by layer - now first implementation to make sure it works OK + inline double benddecode(int ibend, bool isPS) { + if (isPS) { + if (ibend == 0) + return 0.25; + if (ibend == 1) + return 1.25; + if (ibend == 2) + return 2.25; + if (ibend == 3) + return 3.25; + if (ibend == 4) + return -0.75; + if (ibend == 5) + return -1.75; + if (ibend == 6) + return -2.75; + if (ibend == 7) + return -3.75; + + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ + << " Unknown benddecode for PS module for ibend = " << ibend; + } + + if (ibend == 0) + return 0.25; + if (ibend == 1) + return 1.25; + if (ibend == 2) + return 2.25; + if (ibend == 3) + return 3.25; + if (ibend == 4) + return 4.25; + if (ibend == 5) + return 5.25; + if (ibend == 6) + return 6.25; + if (ibend == 7) + return 7.25; + if (ibend == 8) + return -0.75; + if (ibend == 9) + return -1.75; + if (ibend == 10) + return -2.75; + if (ibend == 11) + return -3.75; + if (ibend == 12) + return -4.75; + if (ibend == 13) + return -5.75; + if (ibend == 14) + return -6.75; + if (ibend == 15) + return -7.75; + + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ + << " Unknown benddecode for 2S module for ibend = " << ibend; + } + + inline double bend(double r, double rinv, double stripPitch) { + constexpr double dr = 0.18; + double delta = r * dr * 0.5 * rinv; + double bend = -delta / stripPitch; + return bend; + } + + inline double rinv(double phi1, double phi2, double r1, double r2) { + if (r2 <= r1) { //can not form tracklet + return 20.0; + } + + double dphi = phi2 - phi1; + double dr = r2 - r1; + + return 2.0 * sin(dphi) / dr / sqrt(1.0 + 2 * r1 * r2 * (1.0 - cos(dphi)) / (dr * dr)); + } + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h b/L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h new file mode 100644 index 0000000000000..1b3e37aba7184 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h @@ -0,0 +1,41 @@ +// VMProjectionsMemory: Class to hold a reduced format of the tracklet projections (from ProjectionRouter) +#ifndef L1Trigger_TrackFindingTracklet_interface_VMProjectionsMemory_h +#define L1Trigger_TrackFindingTracklet_interface_VMProjectionsMemory_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" + +#include + +namespace trklet { + + class Settings; + class Tracklet; + + class VMProjectionsMemory : public MemoryBase { + public: + VMProjectionsMemory(std::string name, Settings const& settings, unsigned int iSector); + + ~VMProjectionsMemory() override = default; + + void addTracklet(Tracklet* tracklet, unsigned int allprojindex); + + unsigned int nTracklets() const { return tracklets_.size(); } + + Tracklet* getTracklet(unsigned int i) { return tracklets_[i].first; } + int getAllProjIndex(unsigned int i) const { return tracklets_[i].second; } + + void writeVMPROJ(bool first); + + void clean() override { tracklets_.clear(); } + + int layer() const { return layer_; } + int disk() const { return disk_; } + + private: + int layer_; + int disk_; + std::vector > tracklets_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/VMRouter.h b/L1Trigger/TrackFindingTracklet/interface/VMRouter.h new file mode 100644 index 0000000000000..5e93482182cfe --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/VMRouter.h @@ -0,0 +1,73 @@ +// VMRouter: sorts input stubs into smaller units in phi (and possibly z), referred to as "Virtual Modules" (VMs) +#ifndef L1Trigger_TrackFindingTracklet_interface_VMRouter_h +#define L1Trigger_TrackFindingTracklet_interface_VMRouter_h + +#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h" + +#include +#include +#include + +namespace trklet { + + class Settings; + class Globals; + class MemoryBase; + class InputLinkMemory; + class AllStubsMemory; + class VMStubsMEMemory; + class VMStubsTEMemory; + + struct VMStubsTEPHI { + VMStubsTEPHI(unsigned int seednumber_, + unsigned int stubposition_, + std::vector > vmstubmem_) + : seednumber(seednumber_), stubposition(stubposition_), vmstubmem(vmstubmem_){}; + + unsigned int seednumber; //seed number [0,11] + unsigned int stubposition; //stub position in the seed + std::vector > + vmstubmem; // m_vmstubmem[iVM][n] is the VMStubsTEMemory for iVM and the nth copy + }; + + class VMRouter : public ProcessBase { + public: + VMRouter(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + + ~VMRouter() override = default; + + void addOutput(MemoryBase* memory, std::string output) override; + void addInput(MemoryBase* memory, std::string input) override; + + void execute(); + + private: + //0-5 are the layers and 6-10 are the disks + unsigned int layerdisk_; + + //overlapbits_ is the top bits of phicorr used to add or subtract one to see if stub should be added to + //two VMs. nextrabits_ is the number of bits beyond the bits for the phivm that is used by overlapbits_ + unsigned int overlapbits_; + unsigned int nextrabits_; + + int nbitszfinebintable_; + int nbitsrfinebintable_; + + VMRouterTable vmrtable_; + + //The input stub memories + std::vector stubinputs_; + + //The all stub memories + std::vector allstubs_; + + //The VM stubs memories used by the MEs + std::vector vmstubsMEPHI_; + + //The VM stubs memories used by the TEs (using structure defined above) + std::vector vmstubsTEPHI_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/VMRouterPhiCorrTable.h b/L1Trigger/TrackFindingTracklet/interface/VMRouterPhiCorrTable.h new file mode 100644 index 0000000000000..ec1907230e6b0 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/VMRouterPhiCorrTable.h @@ -0,0 +1,44 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_VMRouterPhiCorrTable_h +#define L1Trigger_TrackFindingTracklet_interface_VMRouterPhiCorrTable_h + +#include "L1Trigger/TrackFindingTracklet/interface/TETableBase.h" + +#include +#include +#include +#include +#include + +namespace trklet { + + class Settings; + + class VMRouterPhiCorrTable : public TETableBase { + public: + VMRouterPhiCorrTable(Settings const& settings); + + ~VMRouterPhiCorrTable() override = default; + + void init(int layer, int bendbits, int rbits); + + int getphiCorrValue(int ibend, int irbin) const; + + int lookupPhiCorr(int ibend, int rbin); + + private: + double rmean_; + double rmin_; + double rmax_; + + double dr_; + + int bendbits_; + int rbits_; + + int bendbins_; + int rbins_; + + int layer_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h b/L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h new file mode 100644 index 0000000000000..1f6e3a660c6e4 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h @@ -0,0 +1,60 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_VMRouterTable_h +#define L1Trigger_TrackFindingTracklet_interface_VMRouterTable_h + +#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" + +#include +#include +#include +#include +#include + +namespace trklet { + + class Settings; + + class VMRouterTable { + public: + VMRouterTable(Settings const& settings); + VMRouterTable(Settings const& settings, unsigned int layerdisk); + + ~VMRouterTable() = default; + + void init(unsigned int layerdisk); + + // negative return means that seed can not be formed + int getLookup(unsigned int layerdisk, double z, double r, int iseed = -1); + + int lookup(int zbin, int rbin); + int lookupdisk(int zbin, int rbin); + int lookupinner(int zbin, int rbin); + int lookupinneroverlap(int zbin, int rbin); + int lookupinnerThird(int zbin, int rbin); + + private: + Settings const& settings_; + + double rmin_; + double rmax_; + + double zmin_; + double zmax_; + + double dr_; + double dz_; + + int zbits_; + int rbits_; + + int zbins_; + int rbins_; + + //int layer_; + std::vector vmrtable_; //used for ME and outer TE + std::vector vmrtabletedisk_; //outer disk used by D1, D2, and D4 + std::vector vmrtableteinner_; //projection to next layer/disk + std::vector vmrtableteinneroverlap_; //projection to disk + std::vector vmrtableteinnerThird_; //projection to disk1 for extended - iseed=10 + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/VMStubME.h b/L1Trigger/TrackFindingTracklet/interface/VMStubME.h new file mode 100644 index 0000000000000..498c8e8819e05 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/VMStubME.h @@ -0,0 +1,46 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_VMStubME_h +#define L1Trigger_TrackFindingTracklet_interface_VMStubME_h + +#include +#include +#include +#include + +#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" + +namespace trklet { + + class VMStubME { + public: + VMStubME() {} + + VMStubME(const Stub* stub, FPGAWord finephi, FPGAWord finerz, FPGAWord bend, FPGAWord allstubindex); + + ~VMStubME() = default; + + const FPGAWord& finephi() const { return finephi_; } + const FPGAWord& finerz() const { return finerz_; } + + const FPGAWord& bend() const { return bend_; } + + const Stub* stub() const { return stub_; } + + bool isPSmodule() const { return stub_->isPSmodule(); } + + const FPGAWord& stubindex() const { return allStubIndex_; } + + //return binary string for memory printout + std::string str() const; + + private: + FPGAWord allStubIndex_; + FPGAWord finephi_; + FPGAWord finerz_; + FPGAWord bend_; + const Stub* stub_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/VMStubTE.h b/L1Trigger/TrackFindingTracklet/interface/VMStubTE.h new file mode 100644 index 0000000000000..e44c8361e0aee --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/VMStubTE.h @@ -0,0 +1,47 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_VMStubTE_h +#define L1Trigger_TrackFindingTracklet_interface_VMStubTE_h + +#include +#include +#include +#include +#include + +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" + +namespace trklet { + + class VMStubTE { + public: + VMStubTE() {} + + VMStubTE(const Stub* stub, FPGAWord finephi, FPGAWord bend, FPGAWord vmbits, FPGAWord allstubindex); + + ~VMStubTE() = default; + + const FPGAWord& finephi() const { return finephi_; } + + const FPGAWord& bend() const { return bend_; } + + const FPGAWord& vmbits() const { return vmbits_; } + + const Stub* stub() const { return stub_; } + + bool isPSmodule() const { return stub_->isPSmodule(); } + + const FPGAWord& stubindex() const { return allStubIndex_; } + + //return binary string for memory printout + std::string str() const; + + private: + FPGAWord finephi_; + FPGAWord finerz_; + FPGAWord bend_; + FPGAWord vmbits_; + FPGAWord allStubIndex_; + const Stub* stub_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h b/L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h new file mode 100644 index 0000000000000..2ed2c26aeb838 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h @@ -0,0 +1,54 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_VMStubsMEMemory_h +#define L1Trigger_TrackFindingTracklet_interface_VMStubsMEMemory_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMStubME.h" + +#include +#include + +namespace trklet { + + class Settings; + class Stub; + class L1TStub; + + class VMStubsMEMemory : public MemoryBase { + public: + VMStubsMEMemory(std::string name, Settings const& settings, unsigned int iSector); + + ~VMStubsMEMemory() override = default; + + void addStub(VMStubME stub, unsigned int bin) { binnedstubs_[bin].push_back(stub); } + + unsigned int nStubsBin(unsigned int bin) const { + assert(bin < binnedstubs_.size()); + return binnedstubs_[bin].size(); + } + + const VMStubME& getVMStubMEBin(unsigned int bin, unsigned int i) const { + assert(bin < binnedstubs_.size()); + assert(i < binnedstubs_[bin].size()); + return binnedstubs_[bin][i]; + } + + const Stub* getStubBin(unsigned int bin, unsigned int i) const { + assert(bin < binnedstubs_.size()); + assert(i < binnedstubs_[bin].size()); + return binnedstubs_[bin][i].stub(); + } + + void clean() override { + for (auto& binnedstub : binnedstubs_) { + binnedstub.clear(); + } + } + + void writeStubs(bool first); + + private: + std::vector > binnedstubs_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h b/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h new file mode 100644 index 0000000000000..f16a0a35a10c4 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h @@ -0,0 +1,72 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_VMStubsTEMemory_h +#define L1Trigger_TrackFindingTracklet_interface_VMStubsTEMemory_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMStubTE.h" + +#include +#include + +namespace trklet { + + class Settings; + class Stub; + class L1TStub; + + class VMStubsTEMemory : public MemoryBase { + public: + VMStubsTEMemory(std::string name, Settings const& settings, unsigned int iSector); + + ~VMStubsTEMemory() override = default; + + bool addVMStub(VMStubTE vmstub, int bin); + + bool addVMStub(VMStubTE vmstub); + + unsigned int nVMStubs() const { return stubsvm_.size(); } + + unsigned int nVMStubsBinned(unsigned int bin) const { return stubsbinnedvm_[bin].size(); } + + const VMStubTE& getVMStubTE(unsigned int i) const { return stubsvm_[i]; } + + const VMStubTE& getVMStubTEBinned(unsigned int bin, unsigned int i) const { return stubsbinnedvm_[bin][i]; } + + void clean() override; + + void writeStubs(bool first); + + int phibin() const { return phibin_; } + + void getPhiRange(double& phimin, double& phimax, unsigned int iSeed, unsigned int inner); + + void setother(VMStubsTEMemory* other) { other_ = other; } + + VMStubsTEMemory* other() { return other_; } + + void setbendtable(std::vector vmbendtable); + + bool passbend(unsigned int ibend) const { + assert(ibend < vmbendtable_.size()); + return vmbendtable_[ibend]; + } + + void writeVMBendTable(); + + private: + int layer_; + int disk_; + int phibin_; + VMStubsTEMemory* other_; + bool overlap_; + bool extra_; + bool extended_; // for the L2L3->D1 and D1D2->L2 + bool isinner_; // is inner layer/disk for TE purpose + + std::vector vmbendtable_; + + std::vector stubsvm_; + std::vector > stubsbinnedvm_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/imath.h b/L1Trigger/TrackFindingTracklet/interface/imath.h new file mode 100644 index 0000000000000..3db657cda0ed6 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/imath.h @@ -0,0 +1,1121 @@ +// // Integer representation of floating point arithmetic suitable for FPGA designs +// +// Author: Yuri Gershtein +// Date: March 2018 +// +// Functionality: +// +// *note* all integers are assumed to be signed +// +// all variables have units, stored in a map , with string a unit (i.e. "phi") and int the power +// "2" is always present in the map, and it's int pair is referred to as 'shift' +// units are properly combined / propagated through calculations +// adding/subtracting variables with different units throws an exception +// adding/subtracting variables with different shifts is allowed and is handled correctly +// +// calculate() method re-calculates the variable double and int values based on its operands +// returns false in case of overflows and/or mismatches between double and int calculations. +// +// the maximum and minimum values that the variable assumes are stored and updated each time calculate() is called +// if IMATH_ROOT is defined, all values are also stored in a histogram +// +// VarDef (string name, string units, double fmax, double K): +// define variable with bit value fval = K*ival, and maximum absolute value fmax. +// calculates nbins on its own +// one can assign value to it using set_ methods +// +// VarParam (string name, string units, double fval, int nbits): +// define a parameter. K is calculated based on the fval and nbits +// +// or (string name, std::string units, double fval, double K): +// define a parameer with bit value fval = K*ival. +// calculates nbins on its own +// +// VarAdd (string name, VarBase *p1, VarBase *p2, double range = -1, int nmax = 18): +// VarSubtract(string name, VarBase *p1, VarBase *p2, double range = -1, int nmax = 18): +// add/subtract variables. Bit length increases by 1, but capped at nmax +// if range>0 specified, bit length is decreased to drop unnecessary high bits +// +// VarMult (string name, VarBase *p1, VarBase *p2, double range = -1, int nmax = 18): +// multiplication. Bit length is a sum of the lengths of the operads, but capped at nmax +// if range>0 specified, bit length is decreased to drop unnecessary high bits or post-shift is reduced +// +// VarTimesC (string name, VarBase *p1, double cF, int ps = 17): +// multiplication by a constant. Bit length stays the same +// ps defines number of bits used to represent the constant +// +// VarDSPPostadd (string name, VarBase *p1, VarBase *p2, VarBase *p3, double range = -1, int nmax = 18): +// explicit instantiation of the 3-clock DSP postaddition: p1*p2+p3 +// range and nmax have the same meaning as for the VarMult. +// +// VarShift (string name, VarBase *p1, int shift): +// shifts the variable right by shift (equivalent to multiplication by pow(2, -shift)); +// Units stay the same, nbits are adjusted. +// +// VarShiftround (string name, VarBase *p1, int shift): +// shifts the variable right by shift, but doing rounding, i.e. +// (p>>(shift-1)+1)>>1; +// Units stay the same, nbits are adjusted. +// +// VarNeg (string name, VarBase *p1): +// multiplies the variable by -1 +// +// VarInv (string name, VarBase *p1, double offset, int nbits, int n, unsigned int shift, mode m, int nbaddr=-1): +// LUT-based inversion, f = 1./(offset + f1) and i = 2^n / (offsetI + i1) +// nbits is the width of the LUT (signed) +// m is from enum mode {pos, neg, both} and refers to possible sign values of f +// for pos and neg, the most significant bit of p1 (i.e. the sign bit) is ignored +// shift is a shift applied in i1<->address conversions (used to reduce size of LUT) +// nbaddr: if not specified, it is taken to be equal to p1->nbits() +// +// +// VarNounits (string name, VarBase *p1, int ps = 17): +// convert a number with units to a number - needed for trig function expansion (i.e. 1 - 0.5*phi^2) +// ps is a number of bits to represent the unit conversion constant +// +// VarAdjustK (string name, VarBase *p1, double Knew, double epsilon = 1e-5, bool do_assert = false, int nbits = -1) +// adjust variable shift so the K is as close to Knew as possible (needed for bit length adjustments) +// if do_assert is true, throw an exeption if Knew/Kold is not a power of two +// epsilon is a comparison precision, nbits forces the bit length (possibly discarding MSBs) +// +// VarAdjustKR (string name, VarBase *p1, double Knew, double epsilon = 1e-5, bool do_assert = false, int nbits = -1) +// - same as adjustK(), but with rounding, and therefore latency=1 +// +// bool calculate(int debug_level) runs through the entire formula tree recalculating both ineteger and floating point values +// returns true if everything is OK, false if obvious problems with the calculation exist, i.e +// - integer value does not fit into the alotted number of bins +// - integer value is more then 10% or more then 2 away from fval_/K_ +// debug_level: 0 - no warnings +// 1 - limited warning +// 2 - as 1, but also include explicit warnings when LUT was used out of its range +// 3 - maximum complaints level +// +// VarFlag (string name, VarBase *cut_var, VarBase *...) +// +// flag to apply cuts defined for any variable. When output as Verilog, the flag +// is true if and only if the following conditions are all true: +// 1) the cut defined by each VarCut pointer in the argument list must be passed +// by the associated variable +// 2) each VarBase pointer in the argument list that is not also a VarCut +// pointer must pass all of its associated cuts +// 3) all children of the variables in the argument list must pass all of their +// associated cuts +// The VarFlag::passes() method replicates the behavior of the output Verilog, +// returning true if and only if the above conditions are all true. The +// VarBase::local_passes() method can be used to query if a given variable passes +// its associated cuts, regardless of whether its children do. +// +#ifndef L1Trigger_TrackFindingTracklet_interface_imath_h +#define L1Trigger_TrackFindingTracklet_interface_imath_h + +//use root if uncommented +//#ifndef CMSSW_GIT_HASH +//#define IMATH_ROOT +//#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +#ifdef IMATH_ROOT +#include +#include +#include +#include +#endif + +//operation latencies for proper HDL pipelining +#define MULT_LATENCY 1 +#define LUT_LATENCY 2 +#define DSP_LATENCY 3 + +// Print out information on the pass/fail status of all variables. Warning: +// this outputs a lot of information for busy events! + +namespace trklet { + + struct imathGlobals { + bool printCutInfo_{false}; +#ifdef IMATH_ROOT + TFile *h_file_ = new TFile("imath.root", "RECREATE"); + bool use_root; +#endif + }; + + class VarCut; + class VarFlag; + + class VarBase { + public: + VarBase(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, VarBase *p3, int l) { + globals_ = globals; + p1_ = p1; + p2_ = p2; + p3_ = p3; + name_ = name; + latency_ = l; + int step1 = (p1) ? p1->step() + p1->latency() : 0; + int step2 = (p2) ? p2->step() + p2->latency() : 0; + step_ = std::max(step1, step2); + + cuts_.clear(); + cut_var_ = nullptr; + + pipe_counter_ = 0; + pipe_delays_.clear(); + + minval_ = std::numeric_limits::max(); + maxval_ = -std::numeric_limits::max(); + readytoprint_ = true; + readytoanalyze_ = true; + usedasinput_ = false; + Kmap_.clear(); + Kmap_["2"] = 0; // initially, zero shift +#ifdef IMATH_ROOT + h_ = 0; + h_nbins_ = 1024; + h_precision_ = 0.02; +#endif + } + virtual ~VarBase() { +#ifdef IMATH_ROOT + if (globals_->h_file_) { + globals_->h_file_->ls(); + globals_->h_file_->Close(); + globals_->h_file_ = 0; + } +#endif + } + + static struct Verilog { + } verilog; + static struct HLS { + } hls; + + std::string kstring() const; + std::string name() const { return name_; } + std::string op() const { return op_; } + VarBase *p1() const { return p1_; } + VarBase *p2() const { return p2_; } + VarBase *p3() const { return p3_; } + double fval() const { return fval_; } + long int ival() const { return ival_; } + + bool local_passes() const; + void passes(std::map > &passes, + const std::map > *const previous_passes = nullptr) const; + void print_cuts(std::map > &cut_strings, + const int step, + Verilog, + const std::map > *const previous_cut_strings = nullptr) const; + void print_cuts(std::map > &cut_strings, + const int step, + HLS, + const std::map > *const previous_cut_strings = nullptr) const; + void add_cut(VarCut *cut, const bool call_set_cut_var = true); + VarBase *cut_var(); + + double minval() const { return minval_; } + double maxval() const { return maxval_; } + void analyze(); +#ifdef IMATH_ROOT + TH2F *h() { return h_; } +#endif + void reset() { + minval_ = std::numeric_limits::max(); + maxval_ = -std::numeric_limits::max(); +#ifdef IMATH_ROOT + h_->Clear(); +#endif + } + + int nbits() const { return nbits_; } + std::map Kmap() const { return Kmap_; } + double range() const { return (1 << (nbits_ - 1)) * K_; } // everything is signed + double K() const { return K_; }; + int shift() const { return Kmap_.at("2"); } + + void makeready(); + int step() const { return step_; } + int latency() const { return latency_; } + void add_latency(unsigned int l) { latency_ += l; } //only call before using the variable in calculation! + bool calculate(int debug_level); + bool calculate() { return calculate(0); } + virtual void local_calculate() {} + virtual void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) { + fs << "// VarBase here. Soemthing is wrong!! " << l1 << ", " << l2 << ", " << l3 << "\n"; + } + virtual void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) { + fs << "// VarBase here. Soemthing is wrong!! " << l1 << ", " << l2 << ", " << l3 << "\n"; + } + void print_step(int step, std::ofstream &fs, Verilog); + void print_step(int step, std::ofstream &fs, HLS); + void print_all(std::ofstream &fs, Verilog); + void print_all(std::ofstream &fs, HLS); + void print_truncation(std::string &t, const std::string &o1, const int ps, Verilog) const; + void print_truncation(std::string &t, const std::string &o1, const int ps, HLS) const; + void inputs(std::vector *vd); //collect all inputs + + int pipe_counter() { return pipe_counter_; } + void pipe_increment() { pipe_counter_++; } + void add_delay(int i) { pipe_delays_.push_back(i); } + bool has_delay(int i); //returns true if already have this variable delayed. + static void verilog_print(std::vector v, std::ofstream &fs) { design_print(v, fs, verilog); } + static void hls_print(std::vector v, std::ofstream &fs) { design_print(v, fs, hls); } + static void design_print(std::vector v, std::ofstream &fs, Verilog); + static void design_print(std::vector v, std::ofstream &fs, HLS); + static std::string pipe_delay(VarBase *v, int nbits, int delay); + std::string pipe_delays(const int step); + static std::string pipe_delay_wire(VarBase *v, std::string name_delayed, int nbits, int delay); + +#ifdef IMATH_ROOT + static TTree *addToTree(imathGlobals *globals, VarBase *v, char *s = 0); + static TTree *addToTree(imathGlobals *globals, int *v, char *s); + static TTree *addToTree(imathGlobals *globals, double *v, char *s); + static void fillTree(imathGlobals *globals); + static void writeTree(imathGlobals *globals); +#endif + + void dump_msg(); + std::string dump(); + static std::string itos(int i); + + protected: + imathGlobals *globals_; + std::string name_; + VarBase *p1_; + VarBase *p2_; + VarBase *p3_; + std::string op_; // operation + int latency_; // number of clock cycles for the operation (for HDL output) + int step_; // step number in the calculation (for HDL output) + + double fval_; // exact calculation + long int ival_; // integer calculation + double val_; // integer calculation converted to double, ival_*K + + std::vector cuts_; + VarBase *cut_var_; + + int nbits_; + double K_; + std::map Kmap_; + + int pipe_counter_; + std::vector pipe_delays_; + + bool readytoanalyze_; + bool readytoprint_; + bool usedasinput_; + + double minval_; + double maxval_; +#ifdef IMATH_ROOT + void set_hist_pars(int n = 256, double p = 0.05) { + h_nbins_ = n; + h_precision_ = p; + } + int h_nbins_; + double h_precision_; + TH2F *h_; +#endif + }; + + class VarAdjustK : public VarBase { + public: + VarAdjustK(imathGlobals *globals, + std::string name, + VarBase *p1, + double Knew, + double epsilon = 1e-5, + bool do_assert = false, + int nbits = -1) + : VarBase(globals, name, p1, nullptr, nullptr, 0) { + op_ = "adjustK"; + K_ = p1->K(); + Kmap_ = p1->Kmap(); + + double r = Knew / K_; + + lr_ = (r > 1) ? log2(r) + epsilon : log2(r); + K_ = K_ * pow(2, lr_); + if (do_assert) + assert(std::abs(Knew / K_ - 1) < epsilon); + + if (nbits > 0) + nbits_ = nbits; + else + nbits_ = p1->nbits() - lr_; + + Kmap_["2"] = Kmap_["2"] + lr_; + } + + ~VarAdjustK() override = default; + + void adjust(double Knew, double epsilon = 1e-5, bool do_assert = false, int nbits = -1); + + void local_calculate() override; + void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; + void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; + + protected: + int lr_; + }; + + class VarAdjustKR : public VarBase { + public: + VarAdjustKR(imathGlobals *globals, + std::string name, + VarBase *p1, + double Knew, + double epsilon = 1e-5, + bool do_assert = false, + int nbits = -1) + : VarBase(globals, name, p1, nullptr, nullptr, 1) { + op_ = "adjustKR"; + K_ = p1->K(); + Kmap_ = p1->Kmap(); + + double r = Knew / K_; + + lr_ = (r > 1) ? log2(r) + epsilon : log2(r); + K_ = K_ * pow(2, lr_); + if (do_assert) + assert(std::abs(Knew / K_ - 1) < epsilon); + + if (nbits > 0) + nbits_ = nbits; + else + nbits_ = p1->nbits() - lr_; + + Kmap_["2"] = Kmap_["2"] + lr_; + } + + ~VarAdjustKR() override = default; + + void local_calculate() override; + void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; + void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; + + protected: + int lr_; + }; + + class VarParam : public VarBase { + public: + VarParam(imathGlobals *globals, std::string name, double fval, int nbits) + : VarBase(globals, name, nullptr, nullptr, nullptr, 0) { + op_ = "const"; + nbits_ = nbits; + int l = log2(std::abs(fval)) + 1.9999999 - nbits; + Kmap_["2"] = l; + K_ = pow(2, l); + fval_ = fval; + ival_ = fval / K_; + } + VarParam(imathGlobals *globals, std::string name, std::string units, double fval, double K) + : VarBase(globals, name, nullptr, nullptr, nullptr, 0) { + op_ = "const"; + K_ = K; + nbits_ = log2(fval / K) + 1.999999; //plus one to round up + if (!units.empty()) + Kmap_[units] = 1; + else { + //defining a constant, K should be a power of two + int l = log2(K); + if (std::abs(pow(2, l) / K - 1) > 1e-5) { + char slog[100]; + snprintf(slog, 100, "defining unitless constant, yet K is not a power of 2! %g, %g", K, pow(2, l)); + edm::LogVerbatim("Tracklet") << slog; + } + Kmap_["2"] = l; + } + } + + ~VarParam() override = default; + + void set_fval(double fval) { + fval_ = fval; + if (fval > 0) + ival_ = fval / K_ + 0.5; + else + ival_ = fval / K_ - 0.5; + val_ = ival_ * K_; + } + void set_ival(int ival) { + ival_ = ival; + fval_ = ival * K_; + val_ = fval_; + } + void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; + void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; + }; + + class VarDef : public VarBase { + public: + //construct from scratch + VarDef(imathGlobals *globals, std::string name, std::string units, double fmax, double K) + : VarBase(globals, name, nullptr, nullptr, nullptr, 1) { + op_ = "def"; + K_ = K; + nbits_ = log2(fmax / K) + 1.999999; //plus one to round up + if (!units.empty()) + Kmap_[units] = 1; + else { + //defining a constant, K should be a power of two + int l = log2(K); + if (std::abs(pow(2, l) / K - 1) > 1e-5) { + char slog[100]; + snprintf(slog, 100, "defining unitless constant, yet K is not a power of 2! %g, %g", K, pow(2, l)); + edm::LogVerbatim("Tracklet") << slog; + } + Kmap_["2"] = l; + } + } + //construct from abother variable (all provenance info is lost!) + VarDef(imathGlobals *globals, std::string name, VarBase *p) : VarBase(globals, name, nullptr, nullptr, nullptr, 1) { + op_ = "def"; + K_ = p->K(); + nbits_ = p->nbits(); + Kmap_ = p->Kmap(); + } + void set_fval(double fval) { + fval_ = fval; + if (fval > 0) + ival_ = fval / K_; + else + ival_ = fval / K_ - 1; + val_ = ival_ * K_; + } + void set_ival(int ival) { + ival_ = ival; + fval_ = ival * K_; + val_ = ival_ * K_; + } + ~VarDef() override = default; + void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; + void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; + }; + + class VarAdd : public VarBase { + public: + VarAdd(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, double range = -1, int nmax = 18) + : VarBase(globals, name, p1, p2, nullptr, 1) { + op_ = "add"; + + std::map map1 = p1->Kmap(); + std::map map2 = p2->Kmap(); + int s1 = map1["2"]; + int s2 = map2["2"]; + + //first check if the constants are all lined up + //go over the two maps subtracting the units + for (const auto &it : map2) { + if (map1.find(it.first) == map1.end()) + map1[it.first] = -it.second; + else + map1[it.first] = map1[it.first] - it.second; + } + + char slog[100]; + + //assert if different + for (const auto &it : map1) { + if (it.second != 0) { + if (it.first != "2") { + snprintf( + slog, 100, "VarAdd: bad units! %s^%i for variable %s", (it.first).c_str(), it.second, name_.c_str()); + edm::LogVerbatim("Tracklet") << slog; + p1->dump_msg(); + p2->dump_msg(); + throw cms::Exception("BadConfig") << "imath units are different!"; + } + } + } + + double ki1 = p1->K() / pow(2, s1); + double ki2 = p2->K() / pow(2, s2); + //those should be the same + if (std::abs(ki1 / ki2 - 1.) > 1e-6) { + snprintf(slog, 100, "VarAdd: bad constants! %f %f for variable %s", ki1, ki2, name_.c_str()); + edm::LogVerbatim("Tracklet") << slog; + p1->dump_msg(); + p2->dump_msg(); + throw cms::Exception("BadConfig") << "imath constants are different!"; + } + //everything checks out! + + Kmap_ = p1->Kmap(); + + int s0 = s1 < s2 ? s1 : s2; + shift1 = s1 - s0; + shift2 = s2 - s0; + + int n1 = p1->nbits() + shift1; + int n2 = p2->nbits() + shift2; + int n0 = 1 + (n1 > n2 ? n1 : n2); + + //before shifting, check the range + if (range > 0) { + n0 = log2(range / ki1 / pow(2, s0)) + 1e-9; + n0 = n0 + 2; + } + + if (n0 <= nmax) { //if it fits, we're done + ps_ = 0; + Kmap_["2"] = s0; + nbits_ = n0; + } else { + ps_ = n0 - nmax; + Kmap_["2"] = s0 + ps_; + nbits_ = nmax; + } + + K_ = ki1 * pow(2, Kmap_["2"]); + } + ~VarAdd() override = default; + void local_calculate() override; + void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; + void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; + + protected: + int ps_; + int shift1; + int shift2; + }; + + class VarSubtract : public VarBase { + public: + VarSubtract(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, double range = -1, int nmax = 18) + : VarBase(globals, name, p1, p2, nullptr, 1) { + op_ = "subtract"; + + std::map map1 = p1->Kmap(); + std::map map2 = p2->Kmap(); + int s1 = map1["2"]; + int s2 = map2["2"]; + + //first check if the constants are all lined up go over the two maps subtracting the units + for (const auto &it : map2) { + if (map1.find(it.first) == map1.end()) + map1[it.first] = -it.second; + else + map1[it.first] = map1[it.first] - it.second; + } + + char slog[100]; + + //assert if different + for (const auto &it : map1) { + if (it.second != 0) { + if (it.first != "2") { + snprintf( + slog, 100, "VarAdd: bad units! %s^%i for variable %s", (it.first).c_str(), it.second, name_.c_str()); + edm::LogVerbatim("Tracklet") << slog; + p1->dump_msg(); + p2->dump_msg(); + throw cms::Exception("BadConfig") << "imath units are different!"; + } + } + } + + double ki1 = p1->K() / pow(2, s1); + double ki2 = p2->K() / pow(2, s2); + //those should be the same + if (std::abs(ki1 / ki2 - 1.) > 1e-6) { + snprintf(slog, 100, "VarAdd: bad constants! %f %f for variable %s", ki1, ki2, name_.c_str()); + edm::LogVerbatim("Tracklet") << slog; + p1->dump_msg(); + p2->dump_msg(); + throw cms::Exception("BadConfig") << "imath constants are different!"; + } + //everything checks out! + + Kmap_ = p1->Kmap(); + + int s0 = s1 < s2 ? s1 : s2; + shift1 = s1 - s0; + shift2 = s2 - s0; + + int n1 = p1->nbits() + shift1; + int n2 = p2->nbits() + shift2; + int n0 = 1 + (n1 > n2 ? n1 : n2); + + //before shifting, check the range + if (range > 0) { + n0 = log2(range / ki1 / pow(2, s0)) + 1e-9; + n0 = n0 + 2; + } + + if (n0 <= nmax) { //if it fits, we're done + ps_ = 0; + Kmap_["2"] = s0; + nbits_ = n0; + } else { + ps_ = n0 - nmax; + Kmap_["2"] = s0 + ps_; + nbits_ = nmax; + } + + K_ = ki1 * pow(2, Kmap_["2"]); + } + + ~VarSubtract() override = default; + + void local_calculate() override; + void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; + void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; + + protected: + int ps_; + int shift1; + int shift2; + }; + + class VarNounits : public VarBase { + public: + VarNounits(imathGlobals *globals, std::string name, VarBase *p1, int ps = 17) + : VarBase(globals, name, p1, nullptr, nullptr, MULT_LATENCY) { + op_ = "nounits"; + ps_ = ps; + nbits_ = p1->nbits(); + + int s1 = p1->shift(); + double ki = p1->K() / pow(2, s1); + int m = log2(ki); + + K_ = pow(2, s1 + m); + Kmap_["2"] = s1 + m; + double c = ki * pow(2, -m); + cI_ = c * pow(2, ps_); + } + ~VarNounits() override = default; + + void local_calculate() override; + void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; + void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; + + protected: + int ps_; + int cI_; + }; + + class VarShiftround : public VarBase { + public: + VarShiftround(imathGlobals *globals, std::string name, VarBase *p1, int shift) + : VarBase(globals, name, p1, nullptr, nullptr, 1) { // latency is one because there is an addition + op_ = "shiftround"; + shift_ = shift; + + nbits_ = p1->nbits() - shift; + Kmap_ = p1->Kmap(); + K_ = p1->K(); + } + ~VarShiftround() override = default; + + void local_calculate() override; + void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; + void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; + + protected: + int shift_; + }; + + class VarShift : public VarBase { + public: + VarShift(imathGlobals *globals, std::string name, VarBase *p1, int shift) + : VarBase(globals, name, p1, nullptr, nullptr, 0) { + op_ = "shift"; + shift_ = shift; + + nbits_ = p1->nbits() - shift; + Kmap_ = p1->Kmap(); + K_ = p1->K(); + } + ~VarShift() override = default; + void local_calculate() override; + void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; + void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; + + protected: + int shift_; + }; + + class VarNeg : public VarBase { + public: + VarNeg(imathGlobals *globals, std::string name, VarBase *p1) : VarBase(globals, name, p1, nullptr, nullptr, 1) { + op_ = "neg"; + nbits_ = p1->nbits(); + Kmap_ = p1->Kmap(); + K_ = p1->K(); + } + ~VarNeg() override = default; + void local_calculate() override; + void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; + void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; + }; + + class VarTimesC : public VarBase { + public: + VarTimesC(imathGlobals *globals, std::string name, VarBase *p1, double cF, int ps = 17) + : VarBase(globals, name, p1, nullptr, nullptr, MULT_LATENCY) { + op_ = "timesC"; + cF_ = cF; + ps_ = ps; + + nbits_ = p1->nbits(); + Kmap_ = p1->Kmap(); + K_ = p1->K(); + + int s1 = Kmap_["2"]; + double l = log2(std::abs(cF)); + if (l > 0) + l += 0.999999; + int m = l; + + cI_ = cF * pow(2, ps - m); + K_ = K_ * pow(2, m); + Kmap_["2"] = s1 + m; + } + ~VarTimesC() override = default; + void local_calculate() override; + void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; + void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; + + protected: + int ps_; + int cI_; + double cF_; + }; + + class VarMult : public VarBase { + public: + VarMult(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, double range = -1, int nmax = 18) + : VarBase(globals, name, p1, p2, nullptr, MULT_LATENCY) { + op_ = "mult"; + + const std::map map1 = p1->Kmap(); + const std::map map2 = p2->Kmap(); + for (const auto &it : map1) { + if (Kmap_.find(it.first) == Kmap_.end()) + Kmap_[it.first] = it.second; + else + Kmap_[it.first] = Kmap_[it.first] + it.second; + } + for (const auto &it : map2) { + if (Kmap_.find(it.first) == Kmap_.end()) + Kmap_[it.first] = it.second; + else + Kmap_[it.first] = Kmap_[it.first] + it.second; + } + K_ = p1->K() * p2->K(); + int s0 = Kmap_["2"]; + + int n0 = p1->nbits() + p2->nbits(); + if (range > 0) { + n0 = log2(range / K_) + 1e-9; + n0 = n0 + 2; + } + if (n0 < nmax) { + ps_ = 0; + nbits_ = n0; + } else { + ps_ = n0 - nmax; + nbits_ = nmax; + Kmap_["2"] = s0 + ps_; + K_ = K_ * pow(2, ps_); + } + } + ~VarMult() override = default; + void local_calculate() override; + void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; + void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; + + protected: + int ps_; + }; + + class VarDSPPostadd : public VarBase { + public: + VarDSPPostadd( + imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, VarBase *p3, double range = -1, int nmax = 18) + : VarBase(globals, name, p1, p2, p3, DSP_LATENCY) { + op_ = "DSP_postadd"; + + //first, get constants for the p1*p2 + std::map map1 = p1->Kmap(); + std::map map2 = p2->Kmap(); + for (const auto &it : map2) { + if (map1.find(it.first) == map1.end()) + map1[it.first] = it.second; + else + map1[it.first] = map1[it.first] + it.second; + } + double k0 = p1->K() * p2->K(); + int s0 = map1["2"]; + + //now addition + std::map map3 = p3->Kmap(); + int s3 = map3["2"]; + + //first check if the constants are all lined up + //go over the two maps subtracting the units + for (const auto &it : map3) { + if (map1.find(it.first) == map1.end()) + map1[it.first] = -it.second; + else + map1[it.first] = map1[it.first] - it.second; + } + + char slog[100]; + + //assert if different + for (const auto &it : map1) { + if (it.second != 0) { + if (it.first != "2") { + snprintf(slog, + 100, + "VarDSPPostadd: bad units! %s^%i for variable %s", + (it.first).c_str(), + it.second, + name_.c_str()); + edm::LogVerbatim("Tracklet") << slog; + p1->dump_msg(); + p2->dump_msg(); + p3->dump_msg(); + throw cms::Exception("BadConfig") << "imath units are different!"; + } + } + } + + double ki1 = k0 / pow(2, s0); + double ki2 = p3->K() / pow(2, s3); + //those should be the same + if (std::abs(ki1 / ki2 - 1.) > 1e-6) { + snprintf(slog, 100, "VarDSPPostadd: bad constants! %f %f for variable %s", ki1, ki2, name_.c_str()); + edm::LogVerbatim("Tracklet") << slog; + p1->dump_msg(); + p2->dump_msg(); + p3->dump_msg(); + throw cms::Exception("BadConfig") << "imath constants are different!"; + } + //everything checks out! + + shift3_ = s3 - s0; + if (shift3_ < 0) { + throw cms::Exception("BadConfig") << "imath VarDSPPostadd: loosing precision on C in A*B+C: " << shift3_; + } + + Kmap_ = p3->Kmap(); + Kmap_["2"] = Kmap_["2"] - shift3_; + + int n12 = p1->nbits() + p2->nbits(); + int n3 = p3->nbits() + shift3_; + int n0 = 1 + (n12 > n3 ? n12 : n3); + + //before shifting, check the range + if (range > 0) { + n0 = log2(range / ki2 / pow(2, s3)) + 1e-9; + n0 = n0 + 2; + } + + if (n0 <= nmax) { //if it fits, we're done + ps_ = 0; + nbits_ = n0; + } else { + ps_ = n0 - nmax; + Kmap_["2"] = Kmap_["2"] + ps_; + nbits_ = nmax; + } + + K_ = ki2 * pow(2, Kmap_["2"]); + } + ~VarDSPPostadd() override = default; + + void local_calculate() override; + using VarBase::print; + void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; + + protected: + int ps_; + int shift3_; + }; + + class VarInv : public VarBase { + public: + enum mode { pos, neg, both }; + + VarInv(imathGlobals *globals, + std::string name, + VarBase *p1, + double offset, + int nbits, + int n, + unsigned int shift, + mode m, + int nbaddr = -1) + : VarBase(globals, name, p1, nullptr, nullptr, LUT_LATENCY) { + op_ = "inv"; + offset_ = offset; + nbits_ = nbits; + n_ = n; + shift_ = shift; + m_ = m; + if (nbaddr < 0) + nbaddr = p1->nbits(); + nbaddr_ = nbaddr - shift; + if (m_ != mode::both) + nbaddr_--; + Nelements_ = 1 << nbaddr_; + mask_ = Nelements_ - 1; + ashift_ = sizeof(int) * 8 - nbaddr_; + + const std::map map1 = p1->Kmap(); + for (const auto &it : map1) + Kmap_[it.first] = -it.second; + Kmap_["2"] = Kmap_["2"] - n; + K_ = pow(2, -n) / p1->K(); + + LUT = new int[Nelements_]; + double offsetI = lround(offset_ / p1_->K()); + for (int i = 0; i < Nelements_; ++i) { + int i1 = addr_to_ival(i); + LUT[i] = gen_inv(offsetI + i1); + } + } + ~VarInv() override { delete[] LUT; } + + void set_mode(mode m) { m_ = m; } + void initLUT(double offset); + double offset() { return offset_; } + double Ioffset() { return offset_ / p1_->K(); } + + void local_calculate() override; + void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; + void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; + void writeLUT(std::ofstream &fs) const { writeLUT(fs, verilog); } + void writeLUT(std::ofstream &fs, Verilog) const; + void writeLUT(std::ofstream &fs, HLS) const; + + int ival_to_addr(int ival) { return ((ival >> shift_) & mask_); } + int addr_to_ival(int addr) { + switch (m_) { + case mode::pos: + return addr << shift_; + case mode::neg: + return (addr - Nelements_) << shift_; + case mode::both: + return (addr << ashift_) >> (ashift_ - shift_); + } + assert(0); + } + int gen_inv(int i) { + unsigned int ms = sizeof(int) * 8 - nbits_; + int lut = 0; + if (i > 0) { + int i1 = i + (1 << shift_) - 1; + int lut1 = (lround((1 << n_) / i) << ms) >> ms; + int lut2 = (lround((1 << n_) / (i1)) << ms) >> ms; + lut = 0.5 * (lut1 + lut2); + } else if (i < -1) { + int i1 = i + (1 << shift_) - 1; + int i2 = i; + int lut1 = (lround((1 << n_) / i1) << ms) >> ms; + int lut2 = (lround((1 << n_) / i2) << ms) >> ms; + lut = 0.5 * (lut1 + lut2); + } + return lut; + } + + protected: + double offset_; + int n_; + mode m_; + unsigned int shift_; + unsigned int mask_; + unsigned int ashift_; + int Nelements_; + int nbaddr_; + + int *LUT; + }; + + class VarCut : public VarBase { + public: + VarCut(imathGlobals *globals, double lower_cut, double upper_cut) + : VarBase(globals, "", nullptr, nullptr, nullptr, 0), + lower_cut_(lower_cut), + upper_cut_(upper_cut), + parent_flag_(nullptr) { + op_ = "cut"; + } + + VarCut(imathGlobals *globals, VarBase *cut_var, double lower_cut, double upper_cut) + : VarCut(globals, lower_cut, upper_cut) { + set_cut_var(cut_var); + } + ~VarCut() override = default; + + double lower_cut() const { return lower_cut_; } + double upper_cut() const { return upper_cut_; } + + void local_passes(std::map > &passes, + const std::map > *const previous_passes = nullptr) const; + using VarBase::print; + void print(std::map > &cut_strings, + const int step, + Verilog, + const std::map > *const previous_cut_strings = nullptr) const; + void print(std::map > &cut_strings, + const int step, + HLS, + const std::map > *const previous_cut_strings = nullptr) const; + + void set_parent_flag(VarFlag *parent_flag, const bool call_add_cut); + VarFlag *parent_flag() { return parent_flag_; } + void set_cut_var(VarBase *cut_var, const bool call_add_cut = true); + + protected: + double lower_cut_; + double upper_cut_; + VarFlag *parent_flag_; + }; + + class VarFlag : public VarBase { + public: + template + VarFlag(imathGlobals *globals, std::string name, VarBase *cut, Args... args) + : VarBase(globals, name, nullptr, nullptr, nullptr, 0) { + op_ = "flag"; + nbits_ = 1; + add_cuts(cut, args...); + } + + template + void add_cuts(VarBase *cut, Args... args) { + add_cut(cut); + add_cuts(args...); + } + + void add_cuts(VarBase *cut) { add_cut(cut); } + + void add_cut(VarBase *cut, const bool call_set_parent_flag = true); + + void calculate_step(); + bool passes(); + void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; + void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/plugins/BuildFile.xml b/L1Trigger/TrackFindingTracklet/plugins/BuildFile.xml new file mode 100644 index 0000000000000..866e2d65ac4aa --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/plugins/BuildFile.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc b/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc new file mode 100644 index 0000000000000..70c554b5c80d7 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc @@ -0,0 +1,679 @@ +////////////////////////// +// Producer by Anders // +// and Emmanuele // +// july 2012 @ CU // +////////////////////////// + +//////////////////// +// FRAMEWORK HEADERS +#include "FWCore/PluginManager/interface/ModuleDef.h" +#include "FWCore/Framework/interface/MakerMacros.h" +// +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/ParameterSet/interface/FileInPath.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +// +#include "FWCore/Utilities/interface/InputTag.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" + +/////////////////////// +// DATA FORMATS HEADERS +#include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/Common/interface/Ref.h" +// +#include "DataFormats/DetId/interface/DetId.h" +#include "DataFormats/SiPixelDetId/interface/PXBDetId.h" +#include "DataFormats/SiPixelDetId/interface/PXFDetId.h" +#include "DataFormats/Common/interface/DetSetVector.h" +// +#include "L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h" +#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" + +#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h" +#include "SimDataFormats/TrackingHit/interface/PSimHit.h" +#include "SimDataFormats/Track/interface/SimTrack.h" +#include "SimDataFormats/Track/interface/SimTrackContainer.h" +#include "SimDataFormats/Vertex/interface/SimVertex.h" +#include "SimDataFormats/Vertex/interface/SimVertexContainer.h" +#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h" +#include "SimDataFormats/TrackingAnalysis/interface/TrackingVertex.h" +#include "SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h" +#include "SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h" +// +#include "DataFormats/Math/interface/LorentzVector.h" +#include "DataFormats/Math/interface/Vector3D.h" +// +#include "DataFormats/L1TrackTrigger/interface/TTCluster.h" +#include "DataFormats/L1TrackTrigger/interface/TTStub.h" +#include "DataFormats/L1TrackTrigger/interface/TTTrack.h" +#include "DataFormats/L1TrackTrigger/interface/TTTrack_TrackWord.h" +#include "DataFormats/L1TrackTrigger/interface/TTTypes.h" +// +#include "DataFormats/HepMCCandidate/interface/GenParticle.h" +#include "DataFormats/Candidate/interface/Candidate.h" +// +#include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementPoint.h" +#include "DataFormats/BeamSpot/interface/BeamSpot.h" +#include "DataFormats/SiPixelDetId/interface/PixelChannelIdentifier.h" +#include "TrackingTools/GeomPropagators/interface/HelixArbitraryPlaneCrossing.h" + +//////////////////////////// +// DETECTOR GEOMETRY HEADERS +#include "MagneticField/Engine/interface/MagneticField.h" +#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include "Geometry/CommonTopologies/interface/PixelGeomDetUnit.h" +#include "Geometry/CommonTopologies/interface/PixelGeomDetType.h" +#include "Geometry/TrackerGeometryBuilder/interface/PixelTopologyBuilder.h" +#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" +#include "Geometry/TrackerGeometryBuilder/interface/RectangularPixelTopology.h" +#include "Geometry/CommonDetUnit/interface/GeomDetType.h" +#include "Geometry/CommonDetUnit/interface/GeomDet.h" +// +#include "Geometry/Records/interface/StackedTrackerGeometryRecord.h" + +/////////////// +// Tracklet emulation +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Sector.h" +#include "L1Trigger/TrackFindingTracklet/interface/Cabling.h" +#include "L1Trigger/TrackFindingTracklet/interface/Track.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h" + +//////////////// +// PHYSICS TOOLS +#include "RecoTracker/TkSeedGenerator/interface/FastHelix.h" +#include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h" + +#include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementVector.h" +#include "DataFormats/GeometrySurface/interface/BoundPlane.h" + +#include "L1Trigger/TrackTrigger/interface/StubPtConsistency.h" + +////////////// +// STD HEADERS +#include +#include +#include +#include + +////////////// +// NAMESPACES +using namespace edm; +using namespace std; + +////////////////////////////// +// // +// CLASS DEFINITION // +// // +////////////////////////////// + +///////////////////////////////////// +// this class is needed to make a map +// between different types of stubs +struct L1TStubCompare { +public: + bool operator()(const trklet::L1TStub& x, const trklet::L1TStub& y) const { + if (x.x() != y.x()) + return (y.x() > x.x()); + else { + if (x.y() != y.y()) + return (y.y() > x.y()); + else + return (x.z() > y.z()); + } + } +}; + +class L1FPGATrackProducer : public edm::stream::EDProducer<> { +public: + /// Constructor/destructor + explicit L1FPGATrackProducer(const edm::ParameterSet& iConfig); + ~L1FPGATrackProducer() override; + +private: + int eventnum; + + /// Containers of parameters passed by python configuration file + edm::ParameterSet config; + + bool readMoreMcTruth_; + + /// File path for configuration files + edm::FileInPath fitPatternFile; + edm::FileInPath memoryModulesFile; + edm::FileInPath processingModulesFile; + edm::FileInPath wiresFile; + + edm::FileInPath DTCLinkFile; + edm::FileInPath moduleCablingFile; + + edm::FileInPath DTCLinkLayerDiskFile; + + string asciiEventOutName_; + std::ofstream asciiEventOut_; + + string geometryType_; + + // settings containing various constants for the tracklet processing + trklet::Settings settings; + + // event processor for the tracklet track finding + trklet::TrackletEventProcessor eventProcessor; + + unsigned int nHelixPar_; + bool extended_; + + std::map> dtclayerdisk; + + edm::ESHandle tTopoHandle; + edm::ESHandle tGeomHandle; + + edm::InputTag MCTruthClusterInputTag; + edm::InputTag MCTruthStubInputTag; + edm::InputTag TrackingParticleInputTag; + edm::InputTag TrackingVertexInputTag; + edm::InputTag ttStubSrc_; + edm::InputTag bsSrc_; + + const edm::EDGetTokenT>> ttStubToken_; + const edm::EDGetTokenT bsToken_; + + edm::EDGetTokenT> ttClusterMCTruthToken_; + edm::EDGetTokenT> ttStubMCTruthToken_; + edm::EDGetTokenT> TrackingParticleToken_; + edm::EDGetTokenT> TrackingVertexToken_; + + /// ///////////////// /// + /// MANDATORY METHODS /// + void beginRun(const edm::Run& run, const edm::EventSetup& iSetup) override; + void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override; +}; + +////////////// +// CONSTRUCTOR +L1FPGATrackProducer::L1FPGATrackProducer(edm::ParameterSet const& iConfig) + : config(iConfig), + readMoreMcTruth_(iConfig.getParameter("readMoreMcTruth")), + MCTruthClusterInputTag(readMoreMcTruth_ ? config.getParameter("MCTruthClusterInputTag") + : edm::InputTag()), + MCTruthStubInputTag(readMoreMcTruth_ ? config.getParameter("MCTruthStubInputTag") + : edm::InputTag()), + TrackingParticleInputTag(readMoreMcTruth_ ? iConfig.getParameter("TrackingParticleInputTag") + : edm::InputTag()), + TrackingVertexInputTag(readMoreMcTruth_ ? iConfig.getParameter("TrackingVertexInputTag") + : edm::InputTag()), + ttStubSrc_(config.getParameter("TTStubSource")), + bsSrc_(config.getParameter("BeamSpotSource")), + + ttStubToken_(consumes>>(ttStubSrc_)), + bsToken_(consumes(bsSrc_)) { + if (readMoreMcTruth_) { + ttClusterMCTruthToken_ = consumes>(MCTruthClusterInputTag); + ttStubMCTruthToken_ = consumes>(MCTruthStubInputTag); + TrackingParticleToken_ = consumes>(TrackingParticleInputTag); + TrackingVertexToken_ = consumes>(TrackingVertexInputTag); + } + + produces>>("Level1TTTracks").setBranchAlias("Level1TTTracks"); + + asciiEventOutName_ = iConfig.getUntrackedParameter("asciiFileName", ""); + + fitPatternFile = iConfig.getParameter("fitPatternFile"); + processingModulesFile = iConfig.getParameter("processingModulesFile"); + memoryModulesFile = iConfig.getParameter("memoryModulesFile"); + wiresFile = iConfig.getParameter("wiresFile"); + + DTCLinkFile = iConfig.getParameter("DTCLinkFile"); + moduleCablingFile = iConfig.getParameter("moduleCablingFile"); + + DTCLinkLayerDiskFile = iConfig.getParameter("DTCLinkLayerDiskFile"); + + extended_ = iConfig.getParameter("Extended"); + nHelixPar_ = iConfig.getParameter("Hnpar"); + + // -------------------------------------------------------------------------------- + // set options in Settings based on inputs from configuration files + // -------------------------------------------------------------------------------- + + settings.setExtended(extended_); + settings.setNHelixPar(nHelixPar_); + + settings.setDTCLinkFile(DTCLinkFile.fullPath()); + settings.setModuleCablingFile(moduleCablingFile.fullPath()); + settings.setDTCLinkLayerDiskFile(DTCLinkLayerDiskFile.fullPath()); + settings.setFitPatternFile(fitPatternFile.fullPath()); + settings.setProcessingModulesFile(processingModulesFile.fullPath()); + settings.setMemoryModulesFile(memoryModulesFile.fullPath()); + settings.setWiresFile(wiresFile.fullPath()); + + eventnum = 0; + if (not asciiEventOutName_.empty()) { + asciiEventOut_.open(asciiEventOutName_.c_str()); + } + + if (settings.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "cabling DTC links : " << DTCLinkFile.fullPath() + << "\n module cabling : " << moduleCablingFile.fullPath() + << "\n DTC link layer disk : " << DTCLinkLayerDiskFile.fullPath() + << "\n fit pattern : " << fitPatternFile.fullPath() + << "\n process modules : " << processingModulesFile.fullPath() + << "\n memory modules : " << memoryModulesFile.fullPath() + << "\n wires : " << wiresFile.fullPath(); + } +} + +///////////// +// DESTRUCTOR +L1FPGATrackProducer::~L1FPGATrackProducer() { + if (asciiEventOut_.is_open()) { + asciiEventOut_.close(); + } +} + +//////////// +// BEGIN JOB +void L1FPGATrackProducer::beginRun(const edm::Run& run, const edm::EventSetup& iSetup) { + //////////////////////// + // GET MAGNETIC FIELD // + edm::ESHandle magneticFieldHandle; + iSetup.get().get(magneticFieldHandle); + const MagneticField* theMagneticField = magneticFieldHandle.product(); + double mMagneticFieldStrength = theMagneticField->inTesla(GlobalPoint(0, 0, 0)).z(); + settings.setBfield(mMagneticFieldStrength); + + // initialize the tracklet event processing (this sets all the processing & memory modules, wiring, etc) + eventProcessor.init(&settings); +} + +////////// +// PRODUCE +void L1FPGATrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { + typedef std::map>, TTStub>, + L1TStubCompare> + stubMapType; + typedef edm::Ref>, TTCluster> + TTClusterRef; + + /// Prepare output + auto L1TkTracksForOutput = std::make_unique>>(); + + stubMapType stubMap; + + /// Geometry handles etc + edm::ESHandle geometryHandle; + + /// Set pointers to Stacked Modules + iSetup.get().get(geometryHandle); + + //////////// + // GET BS // + edm::Handle beamSpotHandle; + iEvent.getByToken(bsToken_, beamSpotHandle); + math::XYZPoint bsPosition = beamSpotHandle->position(); + + iSetup.get().get(tTopoHandle); + iSetup.get().get(tGeomHandle); + + eventnum++; + trklet::SLHCEvent ev; + ev.setEventNum(eventnum); + ev.setIPx(bsPosition.x()); + ev.setIPy(bsPosition.y()); + + // tracking particles + edm::Handle> TrackingParticleHandle; + edm::Handle> TrackingVertexHandle; + if (readMoreMcTruth_) + iEvent.getByToken(TrackingParticleToken_, TrackingParticleHandle); + if (readMoreMcTruth_) + iEvent.getByToken(TrackingVertexToken_, TrackingVertexHandle); + + // tracker topology + const TrackerTopology* const tTopo = tTopoHandle.product(); + const TrackerGeometry* const theTrackerGeom = tGeomHandle.product(); + + //////////////////////// + // GET THE PRIMITIVES // + edm::Handle>> Phase2TrackerDigiTTStubHandle; + iEvent.getByToken(ttStubToken_, Phase2TrackerDigiTTStubHandle); + + // must be defined for code to compile, even if it's not used unless readMoreMcTruth_ is true + map, int> translateTP; + + // MC truth association maps + edm::Handle> MCTruthTTClusterHandle; + edm::Handle> MCTruthTTStubHandle; + if (readMoreMcTruth_) { + iEvent.getByToken(ttClusterMCTruthToken_, MCTruthTTClusterHandle); + iEvent.getByToken(ttStubMCTruthToken_, MCTruthTTStubHandle); + + //////////////////////////////////////////////// + /// LOOP OVER TRACKING PARTICLES & GET SIMTRACKS + + int ntps = 1; //count from 1 ; 0 will mean invalid + + int this_tp = 0; + for (const auto& iterTP : *TrackingParticleHandle) { + edm::Ptr tp_ptr(TrackingParticleHandle, this_tp); + this_tp++; + + // only keep TPs producing a cluster + if (MCTruthTTClusterHandle->findTTClusterRefs(tp_ptr).empty()) + continue; + + if (iterTP.g4Tracks().empty()) { + continue; + } + + int sim_eventid = iterTP.g4Tracks().at(0).eventId().event(); + int sim_type = iterTP.pdgId(); + float sim_pt = iterTP.pt(); + float sim_eta = iterTP.eta(); + float sim_phi = iterTP.phi(); + + float vx = iterTP.vertex().x(); + float vy = iterTP.vertex().y(); + float vz = iterTP.vertex().z(); + + if (sim_pt < 1.0 || std::abs(vz) > 100.0 || hypot(vx, vy) > 50.0) + continue; + + ev.addL1SimTrack(sim_eventid, ntps, sim_type, sim_pt, sim_eta, sim_phi, vx, vy, vz); + + translateTP[tp_ptr] = ntps; + ntps++; + + } //end loop over TPs + + } // end if (readMoreMcTruth_) + + //////////////////////////////// + /// COLLECT STUB INFORMATION /// + //////////////////////////////// + + bool firstPS = true; + bool first2S = true; + + for (const auto& gd : theTrackerGeom->dets()) { + DetId detid = (*gd).geographicalId(); + if (detid.subdetId() != StripSubdetector::TOB && detid.subdetId() != StripSubdetector::TID) + continue; // only run on OT + if (!tTopo->isLower(detid)) + continue; // loop on the stacks: choose the lower arbitrarily + DetId stackDetid = tTopo->stack(detid); // Stub module detid + + if (Phase2TrackerDigiTTStubHandle->find(stackDetid) == Phase2TrackerDigiTTStubHandle->end()) + continue; + + // Get the DetSets of the Clusters + edmNew::DetSet> stubs = (*Phase2TrackerDigiTTStubHandle)[stackDetid]; + const GeomDetUnit* det0 = theTrackerGeom->idToDetUnit(detid); + const auto* theGeomDet = dynamic_cast(det0); + const PixelTopology* topol = dynamic_cast(&(theGeomDet->specificTopology())); + + bool isPSmodule = theTrackerGeom->getDetectorType(detid) == TrackerGeometry::ModuleType::Ph2PSP; + + // set constants that are common for all modules/stubs of a given type (PS vs 2S) + if (isPSmodule && firstPS) { + settings.setNStrips_PS(topol->nrows()); + settings.setStripPitch_PS(topol->pitch().first); + settings.setStripLength_PS(topol->pitch().second); + firstPS = false; + } + if (!isPSmodule && first2S) { + settings.setNStrips_2S(topol->nrows()); + settings.setStripPitch_2S(topol->pitch().first); + settings.setStripLength_2S(topol->pitch().second); + first2S = false; + } + + // loop over stubs + for (auto stubIter = stubs.begin(); stubIter != stubs.end(); ++stubIter) { + edm::Ref>, TTStub> tempStubPtr = + edmNew::makeRefTo(Phase2TrackerDigiTTStubHandle, stubIter); + + vector assocTPs; + + if (readMoreMcTruth_) { + for (unsigned int iClus = 0; iClus <= 1; iClus++) { // Loop over both clusters that make up stub. + + const TTClusterRef& ttClusterRef = tempStubPtr->clusterRef(iClus); + + // Now identify all TP's contributing to either cluster in stub. + vector> vecTpPtr = MCTruthTTClusterHandle->findTrackingParticlePtrs(ttClusterRef); + + for (const edm::Ptr& tpPtr : vecTpPtr) { + if (translateTP.find(tpPtr) != translateTP.end()) { + if (iClus == 0) { + assocTPs.push_back(translateTP.at(tpPtr)); + } else { + assocTPs.push_back(-translateTP.at(tpPtr)); + } + // N.B. Since not all tracking particles are stored in InputData::vTPs_, sometimes no match will be found. + } else { + assocTPs.push_back(0); + } + } + } + } // end if (readMoreMcTruth_) + + MeasurementPoint coords = tempStubPtr->clusterRef(0)->findAverageLocalCoordinatesCentered(); + LocalPoint clustlp = topol->localPosition(coords); + GlobalPoint posStub = theGeomDet->surface().toGlobal(clustlp); + + int eventID = -1; + + if (readMoreMcTruth_) { + edm::Ptr my_tp = MCTruthTTStubHandle->findTrackingParticlePtr(tempStubPtr); + } + + int layer = -999999; + int ladder = -999999; + int module = -999999; + + int strip = 460; + + if (detid.subdetId() == StripSubdetector::TOB) { + layer = static_cast(tTopo->layer(detid)); + module = static_cast(tTopo->module(detid)); + ladder = static_cast(tTopo->tobRod(detid)); + + // https://github.com/cms-sw/cmssw/tree/master/Geometry/TrackerNumberingBuilder + // tobSide = 1: ring- (tilted) + // tobSide = 2: ring+ (tilted) + // tobSide = 3: barrel (flat) + enum TypeBarrel { nonBarrel = 0, tiltedMinus = 1, tiltedPlus = 2, flat = 3 }; + const TypeBarrel type = static_cast(tTopo->tobSide(detid)); + + // modules in the flat part of barrel are mounted on planks, while modules in tilted part are on rings + // below, "module" is the module number in the z direction (from minus z to positive), + // while "ladder" is the module number in the phi direction + + if (layer > 0 && layer <= (int)trklet::N_PSLAYER) { + if (type == tiltedMinus) { + module = static_cast(tTopo->tobRod(detid)); + ladder = static_cast(tTopo->module(detid)); + } + if (type == tiltedPlus) { + module = + trklet::N_TILTED_RINGS + trklet::N_MOD_PLANK.at(layer - 1) + static_cast(tTopo->tobRod(detid)); + ladder = static_cast(tTopo->module(detid)); + } + if (type == flat) { + module = trklet::N_TILTED_RINGS + static_cast(tTopo->module(detid)); + } + } + } else if (detid.subdetId() == StripSubdetector::TID) { + layer = 1000 + static_cast(tTopo->tidRing(detid)); + ladder = static_cast(tTopo->module(detid)); + module = static_cast(tTopo->tidWheel(detid)); + } + + /// Get the Inner and Outer TTCluster + edm::Ref>, TTCluster> innerCluster = + tempStubPtr->clusterRef(0); + edm::Ref>, TTCluster> outerCluster = + tempStubPtr->clusterRef(1); + + std::vector irphi; + std::vector innerrows = innerCluster->getRows(); + irphi.reserve(innerrows.size()); + for (int innerrow : innerrows) { + irphi.push_back(innerrow); + } + std::vector outerrows = outerCluster->getRows(); + for (int outerrow : outerrows) { + irphi.push_back(outerrow); + } + + // ----------------------------------------------------- + // check module orientation, if flipped, need to store that information for track fit + // ----------------------------------------------------- + + const DetId innerDetId = innerCluster->getDetId(); + const GeomDetUnit* det_inner = theTrackerGeom->idToDetUnit(innerDetId); + const auto* theGeomDet_inner = dynamic_cast(det_inner); + const PixelTopology* topol_inner = dynamic_cast(&(theGeomDet_inner->specificTopology())); + + MeasurementPoint coords_inner = innerCluster->findAverageLocalCoordinatesCentered(); + LocalPoint clustlp_inner = topol_inner->localPosition(coords_inner); + GlobalPoint posStub_inner = theGeomDet_inner->surface().toGlobal(clustlp_inner); + + const DetId outerDetId = outerCluster->getDetId(); + const GeomDetUnit* det_outer = theTrackerGeom->idToDetUnit(outerDetId); + const auto* theGeomDet_outer = dynamic_cast(det_outer); + const PixelTopology* topol_outer = dynamic_cast(&(theGeomDet_outer->specificTopology())); + + MeasurementPoint coords_outer = outerCluster->findAverageLocalCoordinatesCentered(); + LocalPoint clustlp_outer = topol_outer->localPosition(coords_outer); + GlobalPoint posStub_outer = theGeomDet_outer->surface().toGlobal(clustlp_outer); + + bool isFlipped = !(posStub_outer.mag() < posStub_inner.mag()); + + // ----------------------------------------------------- + // correct sign for stubs in negative endcap + float stub_bend = tempStubPtr->bendFE(); + float stub_pt = -1; + if (layer > 999 && posStub.z() < 0.0) { + stub_bend = -stub_bend; + } + if (!irphi.empty()) { + strip = irphi[0]; + } + + //if module FE inefficiencies are calculated, a stub is thrown out if rawBend > 100 + if ((tempStubPtr->rawBend() < 100.) && (ev.addStub(layer, + ladder, + module, + strip, + eventID, + assocTPs, + stub_pt, + stub_bend, + posStub.x(), + posStub.y(), + posStub.z(), + isPSmodule, + isFlipped))) { + const trklet::L1TStub& lastStub = ev.lastStub(); + stubMap[lastStub] = tempStubPtr; + } + } + } + + ////////////////////////// + // NOW RUN THE L1 tracking + + if (!asciiEventOutName_.empty()) { + ev.write(asciiEventOut_); + } + + std::vector& tracks = eventProcessor.tracks(); + + trklet::L1SimTrack simtrk(0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + + // this performs the actual tracklet event processing + eventProcessor.event(ev); + + int ntracks = 0; + + for (auto track : tracks) { + if (track->duplicate()) + continue; + + ntracks++; + + // this is where we create the TTTrack object + double tmp_rinv = track->rinv(settings); + double tmp_phi = track->phi0(settings); + double tmp_tanL = track->tanL(settings); + double tmp_z0 = track->z0(settings); + double tmp_d0 = track->d0(settings); + double tmp_chi2rphi = track->chisqrphi(); + double tmp_chi2rz = track->chisqrz(); + unsigned int tmp_hit = track->hitpattern(); + + TTTrack aTrack(tmp_rinv, + tmp_phi, + tmp_tanL, + tmp_z0, + tmp_d0, + tmp_chi2rphi, + tmp_chi2rz, + 0, + 0, + 0, + tmp_hit, + settings.nHelixPar(), + settings.bfield()); + + unsigned int trksector = track->sector(); + unsigned int trkseed = (unsigned int)abs(track->seed()); + + aTrack.setPhiSector(trksector); + aTrack.setTrackSeedType(trkseed); + + const vector& stubptrs = track->stubs(); + vector stubs; + + stubs.reserve(stubptrs.size()); + for (auto stubptr : stubptrs) { + stubs.push_back(*stubptr); + } + + stubMapType::const_iterator it; + for (const auto& itstubs : stubs) { + it = stubMap.find(itstubs); + if (it != stubMap.end()) { + aTrack.addStubRef(it->second); + } else { + // could not find stub in stub map + } + } + + // pt consistency + aTrack.setStubPtConsistency( + StubPtConsistency::getConsistency(aTrack, theTrackerGeom, tTopo, settings.bfield(), settings.nHelixPar())); + + // set TTTrack word + aTrack.setTrackWordBits(); + + // test track word + //aTrack.testTrackWordBits(); + + L1TkTracksForOutput->push_back(aTrack); + } + + iEvent.put(std::move(L1TkTracksForOutput), "Level1TTTracks"); + +} /// End of produce() + +// /////////////////////////// +// // DEFINE THIS AS A PLUG-IN +DEFINE_FWK_MODULE(L1FPGATrackProducer); diff --git a/L1Trigger/TrackFindingTracklet/python/L1HybridEmulationTracks_cff.py b/L1Trigger/TrackFindingTracklet/python/L1HybridEmulationTracks_cff.py new file mode 100644 index 0000000000000..e977bd04faa73 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/python/L1HybridEmulationTracks_cff.py @@ -0,0 +1,26 @@ +import FWCore.ParameterSet.Config as cms + +from RecoVertex.BeamSpotProducer.BeamSpot_cfi import * + +from L1Trigger.TrackFindingTracklet.Tracklet_cfi import * + +from SimTracker.TrackTriggerAssociation.TrackTriggerAssociator_cff import * + +# prompt hybrid emulation +TTTrackAssociatorFromPixelDigis.TTTracks = cms.VInputTag(cms.InputTag("TTTracksFromTrackletEmulation", "Level1TTTracks") ) + +L1HybridTracks = cms.Sequence(offlineBeamSpot*TTTracksFromTrackletEmulation) +L1HybridTracksWithAssociators = cms.Sequence(offlineBeamSpot*TTTracksFromTrackletEmulation*TrackTriggerAssociatorTracks) + +# extended hybrid emulation +TTTrackAssociatorFromPixelDigisExtended = TTTrackAssociatorFromPixelDigis.clone( + TTTracks = cms.VInputTag(cms.InputTag("TTTracksFromExtendedTrackletEmulation", "Level1TTTracks") ) +) + +L1ExtendedHybridTracks = cms.Sequence(offlineBeamSpot*TTTracksFromExtendedTrackletEmulation) +L1ExtendedHybridTracksWithAssociators = cms.Sequence(offlineBeamSpot*TTTracksFromExtendedTrackletEmulation*TTTrackAssociatorFromPixelDigisExtended) + +# both (prompt + extended) hybrid emulation +L1PromptExtendedHybridTracks = cms.Sequence(offlineBeamSpot*TTTracksFromTrackletEmulation*TTTracksFromExtendedTrackletEmulation) +L1PromptExtendedHybridTracksWithAssociators = cms.Sequence(offlineBeamSpot*TTTracksFromTrackletEmulation*TrackTriggerAssociatorTracks*TTTracksFromExtendedTrackletEmulation*TTTrackAssociatorFromPixelDigisExtended) + diff --git a/L1Trigger/TrackFindingTracklet/python/Tracklet_cfi.py b/L1Trigger/TrackFindingTracklet/python/Tracklet_cfi.py new file mode 100644 index 0000000000000..516ae38c07922 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/python/Tracklet_cfi.py @@ -0,0 +1,31 @@ +import FWCore.ParameterSet.Config as cms + +TTTracksFromTrackletEmulation = cms.EDProducer("L1FPGATrackProducer", + TTStubSource = cms.InputTag("TTStubsFromPhase2TrackerDigis","StubAccepted"), + readMoreMcTruth = cms.bool(True), + MCTruthClusterInputTag = cms.InputTag("TTClusterAssociatorFromPixelDigis", "ClusterAccepted"), + MCTruthStubInputTag = cms.InputTag("TTStubAssociatorFromPixelDigis", "StubAccepted"), + TrackingParticleInputTag = cms.InputTag("mix", "MergedTrackTruth"), + TrackingVertexInputTag = cms.InputTag("mix", "MergedTrackTruth"), + BeamSpotSource = cms.InputTag("offlineBeamSpot"), + asciiFileName = cms.untracked.string(""), + # (if running on CRAB use "../../fitpattern.txt" etc instead) + Extended=cms.bool(False), + Hnpar=cms.uint32(4), + fitPatternFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/fitpattern.txt'), + memoryModulesFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/memorymodules_hourglass.dat'), + processingModulesFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/processingmodules_hourglass.dat'), + wiresFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/wires_hourglass.dat'), + DTCLinkFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/calcNumDTCLinks.txt'), + DTCLinkLayerDiskFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/dtclinklayerdisk.dat'), + moduleCablingFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/modules_T5v3_27SP_nonant_tracklet.dat') + ) + +TTTracksFromExtendedTrackletEmulation = TTTracksFromTrackletEmulation.clone( + Extended=cms.bool(True), + Hnpar=cms.uint32(5), + memoryModulesFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/memorymodules_hourglassExtended.dat'), + processingModulesFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/processingmodules_hourglassExtended.dat'), + wiresFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/wires_hourglassExtended.dat'), + ) + diff --git a/L1Trigger/TrackFindingTracklet/src/AllProjectionsMemory.cc b/L1Trigger/TrackFindingTracklet/src/AllProjectionsMemory.cc new file mode 100644 index 0000000000000..7f4af45f7cadf --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/AllProjectionsMemory.cc @@ -0,0 +1,44 @@ +#include "L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +using namespace trklet; +using namespace std; + +AllProjectionsMemory::AllProjectionsMemory(string name, Settings const& settings, unsigned int iSector) + : MemoryBase(name, settings, iSector) { + initLayerDisk(3, layer_, disk_); +} + +void AllProjectionsMemory::writeAP(bool first) { + std::ostringstream oss; + oss << "../data/MemPrints/TrackletProjections/AllProj_" << getName() << "_" << std::setfill('0') << std::setw(2) + << (iSector_ + 1) << ".dat"; + auto const& fname = oss.str(); + + if (first) { + bx_ = 0; + event_ = 1; + out_.open(fname.c_str()); + } else + out_.open(fname.c_str(), std::ofstream::app); + + out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; + + for (unsigned int j = 0; j < tracklets_.size(); j++) { + string proj = + (layer_ > 0) ? tracklets_[j]->trackletprojstrlayer(layer_) : tracklets_[j]->trackletprojstrdisk(disk_); + out_ << "0x"; + out_ << std::setfill('0') << std::setw(2); + out_ << hex << j << dec; + out_ << " " << proj << " " << trklet::hexFormat(proj) << endl; + } + out_.close(); + + bx_++; + event_++; + if (bx_ > 7) + bx_ = 0; +} diff --git a/L1Trigger/TrackFindingTracklet/src/AllStubsMemory.cc b/L1Trigger/TrackFindingTracklet/src/AllStubsMemory.cc new file mode 100644 index 0000000000000..9fab053a55905 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/AllStubsMemory.cc @@ -0,0 +1,23 @@ +#include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include + +using namespace std; +using namespace trklet; + +AllStubsMemory::AllStubsMemory(string name, Settings const& settings, unsigned int iSector) + : MemoryBase(name, settings, iSector) {} + +void AllStubsMemory::writeStubs(bool first) { + openFile(first, "../data/MemPrints/Stubs/AllStubs_"); + + for (unsigned int j = 0; j < stubs_.size(); j++) { + string stub = stubs_[j]->str(); + out_ << "0x"; + out_ << std::setfill('0') << std::setw(2); + out_ << hex << j << dec; + out_ << " " << stub << " " << hexFormat(stub) << endl; + } + out_.close(); +} diff --git a/L1Trigger/TrackFindingTracklet/src/Cabling.cc b/L1Trigger/TrackFindingTracklet/src/Cabling.cc new file mode 100644 index 0000000000000..c0b48b3e494ad --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/Cabling.cc @@ -0,0 +1,126 @@ +#include "L1Trigger/TrackFindingTracklet/interface/Cabling.h" +#include "L1Trigger/TrackFindingTracklet/interface/DTCLink.h" +#include "L1Trigger/TrackFindingTracklet/interface/DTC.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" +#include "DataFormats/Math/interface/deltaPhi.h" + +using namespace std; +using namespace trklet; + +Cabling::Cabling(string dtcconfig, string moduleconfig, Settings const& settings) : settings_(settings) { + ifstream indtc(dtcconfig.c_str()); + assert(indtc.good()); + + string dtc; + int isec; + + while (indtc.good()) { + indtc >> dtc >> isec; + + if (!indtc.good()) + continue; + + if (dtcs_.find(dtc) == dtcs_.end()) { + dtcs_[dtc].setName(dtc); + } + + dtcs_[dtc].addSec(isec); + + string dtcbase = dtc.substr(2, dtc.size() - 2); + if (dtc[0] == 'n') { + dtcbase = "neg_" + dtc.substr(6, dtc.size() - 6); + } + if (dtcranges_.find(dtcbase) == dtcranges_.end()) { + dtcranges_[dtcbase].setName(dtcbase); + } + } + + ifstream inmodules(moduleconfig.c_str()); + + int layer, ladder, module; + + while (inmodules.good()) { + inmodules >> layer >> ladder >> module >> dtc; + + // in the cabling module map, module# 300+ is flat part of barrel, 200-299 is tilted z-, 100-199 is tilted z+ + if (module > 300) { + if (layer > 0 && layer <= (int)N_PSLAYER) { + module = (module - 300) + N_TILTED_RINGS; + } else if (layer > (int)N_PSLAYER) { + module = (module - 300); + } + } + if (module > 200) { + module = (module - 200); + } + if ((module > 100) && (layer > 0 && layer <= (int)N_PSLAYER)) { + module = (module - 100) + N_TILTED_RINGS + N_MOD_PLANK.at(layer - 1); + } + if (!inmodules.good()) + break; + modules_[layer][ladder][module] = dtc; + } +} + +const string& Cabling::dtc(int layer, int ladder, int module) const { + auto it1 = modules_.find(layer); + assert(it1 != modules_.end()); + auto it2 = it1->second.find(ladder); + assert(it2 != it1->second.end()); + auto it3 = it2->second.find(module); + if (it3 == it2->second.end()) { + throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << "Could not find stub " << layer << " " + << ladder << " " << module; + } + return it3->second; +} + +void Cabling::addphi(const string& dtc, double phi, int layer, int module) { + unsigned int layerdisk = layer - 1; + + if (layer > 1000) + layerdisk = module + N_DISK; + + assert(layerdisk < N_LAYER + N_DISK); + + int isec = dtc[0] - '0'; + + string dtcbase = dtc.substr(2, dtc.size() - 2); + if (dtc[0] == 'n') { + dtcbase = "neg_" + dtc.substr(6, dtc.size() - 6); + isec = dtc[4] - '0'; + } + + double phisec = reco::reduceRange(phi - isec * settings_.dphisector()); + + assert(dtcranges_.find(dtcbase) != dtcranges_.end()); + + dtcranges_[dtcbase].addphi(phisec, layerdisk); +} + +void Cabling::writephirange() const { + ofstream out("dtcphirange.txt"); + + for (auto&& it : dtcranges_) { + for (unsigned int i = 0; i < N_LAYER + N_DISK; i++) { + double min = it.second.min(i); + double max = it.second.max(i); + if (min < max) { + out << it.first << " " << i + 1 << " " << min << " " << max << endl; + } + } + } +} + +std::vector Cabling::DTCs() const { + std::vector tmp; + + for (const auto& it : dtcs_) { + tmp.push_back(it.first); + } + + return tmp; +} diff --git a/L1Trigger/TrackFindingTracklet/src/CandidateMatchMemory.cc b/L1Trigger/TrackFindingTracklet/src/CandidateMatchMemory.cc new file mode 100644 index 0000000000000..6c535de1c93c2 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/CandidateMatchMemory.cc @@ -0,0 +1,63 @@ +#include "L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +using namespace std; +using namespace trklet; + +CandidateMatchMemory::CandidateMatchMemory(string name, Settings const& settings, unsigned int iSector) + : MemoryBase(name, settings, iSector) {} + +void CandidateMatchMemory::addMatch(std::pair tracklet, const Stub* stub) { + std::pair, const Stub*> tmp(tracklet, stub); + + //Check for consistency + for (auto& match : matches_) { + if (tracklet.first->TCID() < match.first.first->TCID()) { + throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " In " << getName() << " adding tracklet " + << tracklet.first << " with lower TCID : " << tracklet.first->TCID() + << " than earlier TCID " << match.first.first->TCID(); + } + } + matches_.push_back(tmp); +} + +void CandidateMatchMemory::writeCM(bool first) { + std::ostringstream oss; + oss << "../data/MemPrints/Matches/CandidateMatches_" << getName() << "_" << std::setfill('0') << std::setw(2) + << (iSector_ + 1) << ".dat"; + auto const& fname = oss.str(); + + if (first) { + bx_ = 0; + event_ = 1; + out_.open(fname.c_str()); + } else + out_.open(fname.c_str(), std::ofstream::app); + + out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; + + for (unsigned int j = 0; j < matches_.size(); j++) { + string stubid = matches_[j].second->stubindex().str(); // stub ID + int projindex = matches_[j].first.second; // Allproj index + FPGAWord tmp; + if (projindex >= (1 << 7)) { + projindex = (1 << 7) - 1; + } + tmp.set(projindex, 7, true, __LINE__, __FILE__); + out_ << "0x"; + out_ << std::setfill('0') << std::setw(2); + out_ << hex << j << dec; + out_ << " " << tmp.str() << "|" << stubid << " " << trklet::hexFormat(tmp.str() + stubid) << endl; + } + out_.close(); + + bx_++; + event_++; + if (bx_ > 7) + bx_ = 0; +} diff --git a/L1Trigger/TrackFindingTracklet/src/CleanTrackMemory.cc b/L1Trigger/TrackFindingTracklet/src/CleanTrackMemory.cc new file mode 100644 index 0000000000000..209c66431a5be --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/CleanTrackMemory.cc @@ -0,0 +1,68 @@ +#include "L1Trigger/TrackFindingTracklet/interface/CleanTrackMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" +#include "L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h" +#include + +using namespace std; +using namespace trklet; + +CleanTrackMemory::CleanTrackMemory( + string name, Settings const& settings, unsigned int iSector, double phimin, double phimax) + : MemoryBase(name, settings, iSector) { + phimin_ = phimin; + phimax_ = phimax; +} + +void CleanTrackMemory::writeCT(bool first) { + std::ostringstream oss; + oss << "../data/MemPrints/CleanTrack/CleanTrack_" << getName() << "_" << std::setfill('0') << std::setw(2) + << (iSector_ + 1) << ".dat"; + auto const& fname = oss.str(); + + if (first) { + bx_ = 0; + event_ = 1; + out_.open(fname.c_str()); + } else + out_.open(fname.c_str(), std::ofstream::app); + + out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; + + for (unsigned int j = 0; j < tracks_.size(); j++) { + out_ << "0x"; + out_ << std::setfill('0') << std::setw(2); + out_ << hex << j << dec << " "; + out_ << tracks_[j]->trackfitstr() << " " << trklet::hexFormat(tracks_[j]->trackfitstr()); + out_ << "\n"; + } + out_.close(); + + // -------------------------------------------------------------- + // print separately ALL cleaned tracks in single file + if (settings_.writeMonitorData("CT")) { + std::string fnameAll = "CleanTracksAll.dat"; + if (first && getName() == "CT_L1L2" && iSector_ == 0) + out_.open(fnameAll.c_str()); + else + out_.open(fnameAll.c_str(), std::ofstream::app); + + if (!tracks_.empty()) + out_ << "BX= " << (bitset<3>)bx_ << " event= " << event_ << " seed= " << getName() + << " phisector= " << iSector_ + 1 << endl; + + for (unsigned int j = 0; j < tracks_.size(); j++) { + if (j < 16) + out_ << "0"; + out_ << hex << j << dec << " "; + out_ << tracks_[j]->trackfitstr(); + out_ << "\n"; + } + out_.close(); + } + // -------------------------------------------------------------- + + bx_++; + event_++; + if (bx_ > 7) + bx_ = 0; +} diff --git a/L1Trigger/TrackFindingTracklet/src/DTC.cc b/L1Trigger/TrackFindingTracklet/src/DTC.cc new file mode 100644 index 0000000000000..6fb97d524565e --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/DTC.cc @@ -0,0 +1,52 @@ +#include "L1Trigger/TrackFindingTracklet/interface/DTC.h" +#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" + +#include "DataFormats/Math/interface/deltaPhi.h" + +using namespace std; +using namespace trklet; + +DTC::DTC(string name) { + name_ = name; + for (unsigned int i = 0; i < N_LAYER + N_DISK; i++) { + phimin_[i] = 10.0; + phimax_[i] = -10.0; + } +} + +void DTC::setName(string name) { name_ = name; } + +void DTC::addSec(int sector) { sectors_.push_back(sector); } + +void DTC::addphi(double phi, unsigned int layerdisk) { + assert(layerdisk < N_LAYER + N_DISK); + if (phi < phimin_[layerdisk]) + phimin_[layerdisk] = phi; + if (phi > phimax_[layerdisk]) + phimax_[layerdisk] = phi; +} + +void DTC::addLink(double phimin, double phimax) { + DTCLink link(phimin, phimax); + links_.push_back(link); +} + +int DTC::addStub(std::pair stub) { + double phi = reco::reduceRange(stub.second->phi()); + bool overlaplayer = ((stub.second->layer() + 1) % 2 == 0); + int added = 0; + for (auto& link : links_) { + if (link.inRange(phi, overlaplayer)) { + added++; + link.addStub(stub); + } + } + return added; +} + +void DTC::clean() { + for (auto& link : links_) { + link.clean(); + } +} diff --git a/L1Trigger/TrackFindingTracklet/src/DTCLink.cc b/L1Trigger/TrackFindingTracklet/src/DTCLink.cc new file mode 100644 index 0000000000000..8b5c59c671fd2 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/DTCLink.cc @@ -0,0 +1,29 @@ +#include "L1Trigger/TrackFindingTracklet/interface/DTCLink.h" + +using namespace std; +using namespace trklet; + +DTCLink::DTCLink(double phimin, double phimax) { + if (phimin > M_PI) { + phimin -= 2 * M_PI; + phimax -= 2 * M_PI; + } + assert(phimax > phimin); + phimin_ = phimin; + phimax_ = phimax; +} + +void DTCLink::addStub(std::pair stub) { stubs_.push_back(stub); } + +bool DTCLink::inRange(double phi, bool overlaplayer) { + double phimax = phimax_; + double phimin = phimin_; + if (overlaplayer) { + double dphi = phimax - phimin; + assert(dphi > 0.0); + assert(dphi < M_PI); + phimin -= dphi / 6.0; + phimax += dphi / 6.0; + } + return (phi < phimax && phi > phimin) || (phi + 2 * M_PI < phimax && phi + 2 * M_PI > phimin); +} diff --git a/L1Trigger/TrackFindingTracklet/src/DiskProjection.cc b/L1Trigger/TrackFindingTracklet/src/DiskProjection.cc new file mode 100644 index 0000000000000..4fa054be39805 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/DiskProjection.cc @@ -0,0 +1,94 @@ +#include "L1Trigger/TrackFindingTracklet/interface/DiskProjection.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +#include +#include + +using namespace std; +using namespace trklet; + +void DiskProjection::init(Settings const& settings, + int projdisk, + double zproj, + int iphiproj, + int irproj, + int iphider, + int irder, + double phiproj, + double rproj, + double phiprojder, + double rprojder, + double phiprojapprox, + double rprojapprox, + double phiprojderapprox, + double rprojderapprox) { + assert(abs(projdisk) >= 0); + assert(abs(projdisk) <= N_DISK); + + valid_ = true; + + zproj_ = zproj; + + projdisk_ = projdisk; + + assert(iphiproj >= 0); + + fpgaphiproj_.set(iphiproj, settings.nphibitsstub(0), true, __LINE__, __FILE__); + int iphivm = (iphiproj >> (settings.nphibitsstub(0) - 5)) & 0x7; + if ((abs(projdisk_) % 2) == 1) { + iphivm ^= 4; + } + fpgaphiprojvm_.set(iphivm, 3, true, __LINE__, __FILE__); + fpgarproj_.set(irproj, settings.nrbitsstub(6), false, __LINE__, __FILE__); + int irvm = irproj >> (13 - 7) & 0xf; + fpgarprojvm_.set(irvm, 4, true, __LINE__, __FILE__); + fpgaphiprojder_.set(iphider, settings.nbitsphiprojderL123(), false, __LINE__, __FILE__); + fpgarprojder_.set(irder, settings.nrbitsprojderdisk(), false, __LINE__, __FILE__); + + //TODO the -3 and +3 should be evaluated and efficiency for matching hits checked. + //This code should be migrated in the ProjectionRouter + int rbin1 = 8.0 * (irproj * settings.krprojshiftdisk() - 3 - settings.rmindiskvm()) / + (settings.rmaxdisk() - settings.rmindiskvm()); + int rbin2 = 8.0 * (irproj * settings.krprojshiftdisk() + 3 - settings.rmindiskvm()) / + (settings.rmaxdisk() - settings.rmindiskvm()); + + if (irproj * settings.krprojshiftdisk() < 20.0) { + edm::LogPrint("Tracklet") << " WARNING : irproj = " << irproj << " " << irproj * settings.krprojshiftdisk() << " " + << projdisk_; + } + + if (rbin1 < 0) + rbin1 = 0; + rbin2 = clamp(rbin2, 0, 7); + + assert(rbin1 <= rbin2); + assert(rbin2 - rbin1 <= 1); + + int finer = 64 * + ((irproj * settings.krprojshiftdisk() - settings.rmindiskvm()) - + rbin1 * (settings.rmaxdisk() - settings.rmindiskvm()) / 8.0) / + (settings.rmaxdisk() - settings.rmindiskvm()); + + finer = clamp(finer, 0, 15); + + int diff = rbin1 != rbin2; + if (irder < 0) + rbin1 += 8; + + fpgarbin1projvm_.set(rbin1, 4, true, __LINE__, __FILE__); // first r bin + fpgarbin2projvm_.set(diff, 1, true, __LINE__, __FILE__); // need to check adjacent r bin + + fpgafinervm_.set(finer, 4, true, __LINE__, __FILE__); // fine r postions starting at rbin1 + + phiproj_ = phiproj; + rproj_ = rproj; + phiprojder_ = phiprojder; + rprojder_ = rprojder; + + phiprojapprox_ = phiprojapprox; + rprojapprox_ = rprojapprox; + phiprojderapprox_ = phiprojderapprox; + rprojderapprox_ = rprojderapprox; +} diff --git a/L1Trigger/TrackFindingTracklet/src/DiskResidual.cc b/L1Trigger/TrackFindingTracklet/src/DiskResidual.cc new file mode 100644 index 0000000000000..99213f18b9848 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/DiskResidual.cc @@ -0,0 +1,47 @@ +#include "L1Trigger/TrackFindingTracklet/interface/DiskResidual.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +using namespace std; +using namespace trklet; + +void DiskResidual::init(Settings const& settings, + int disk, + int iphiresid, + int irresid, + int istubid, + double phiresid, + double rresid, + double phiresidapprox, + double rresidapprox, + double zstub, + double alpha, + FPGAWord ialpha, + const Stub* stubptr) { + assert(abs(disk) > 0); + assert(abs(disk) <= N_DISK); + + if (valid_ && (std::abs(iphiresid) > std::abs(fpgaphiresid_.value()))) + return; + + valid_ = true; + + disk_ = disk; + + fpgaphiresid_.set(iphiresid, settings.phiresidbits(), false, __LINE__, __FILE__); + fpgarresid_.set(irresid, settings.rresidbits(), false, __LINE__, __FILE__); + assert(istubid >= 0); + unsigned int nbitsstubid = 10; + fpgastubid_.set(istubid, nbitsstubid, true, __LINE__, __FILE__); + assert(!fpgaphiresid_.atExtreme()); + + phiresid_ = phiresid; + rresid_ = rresid; + + phiresidapprox_ = phiresidapprox; + rresidapprox_ = rresidapprox; + + zstub_ = zstub; + alpha_ = alpha; + ialpha_ = ialpha; + stubptr_ = stubptr; +} diff --git a/L1Trigger/TrackFindingTracklet/src/FPGAWord.cc b/L1Trigger/TrackFindingTracklet/src/FPGAWord.cc new file mode 100644 index 0000000000000..08109d4574224 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/FPGAWord.cc @@ -0,0 +1,88 @@ +#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +using namespace std; +using namespace trklet; + +FPGAWord::FPGAWord() {} + +FPGAWord::FPGAWord(int value, int nbits, bool positive, int line, const char* file) { + set(value, nbits, positive, line, file); +} + +void FPGAWord::set(int value, int nbits, bool positive, int line, const char* file) { + value_ = value; + nbits_ = nbits; + positive_ = positive; + if (positive) { + if (value < 0) { + edm::LogProblem("Tracklet") << "FPGAWord got negative value:" << value << " (" << file << ":" << line << ")"; + } + assert(value >= 0); + } + if (nbits >= 22) { + edm::LogPrint("Tracklet") << "FPGAWord got too many bits:" << nbits << " (" << file << ":" << line << ")"; + } + assert(nbits < 22); + if (nbits <= 0) { + edm::LogPrint("Tracklet") << "FPGAWord got too few bits:" << nbits << " (" << file << ":" << line << ")"; + } + assert(nbits > 0); + if (positive) { + if (value >= (1 << nbits)) { + if (file != nullptr) { + edm::LogProblem("Tracklet") << "value too large:" << value << " " << (1 << nbits) << " (" << file << ":" << line + << ")"; + } + } + assert(value < (1 << nbits)); + } else { + if (value > (1 << (nbits - 1))) { + edm::LogProblem("Tracklet") << "value too large:" << value << " " << (1 << (nbits - 1)) << " (" << file << ":" + << line << ")"; + } + assert(value <= (1 << (nbits - 1))); + if (value < -(1 << (nbits - 1))) { + edm::LogProblem("Tracklet") << "value too negative:" << value << " " << -(1 << (nbits - 1)) << " (" << file << ":" + << line << ")"; + } + assert(value >= -(1 << (nbits - 1))); + } +} + +std::string FPGAWord::str() const { + const int nbit = nbits_; + + if (!(nbit > 0 && nbit < 22)) + edm::LogVerbatim("Tracklet") << "nbit: " << nbit; + if (nbit == -1) + return "?"; + if (nbit == 0) + return "~"; + + int valtmp = value_; + string str = ""; + for (int i = 0; i < nbit; i++) { + str = ((valtmp & 1) ? "1" : "0") + str; + valtmp >>= 1; + } + + return str; +} + +unsigned int FPGAWord::bits(unsigned int lsb, unsigned int nbit) const { + assert(lsb + nbit <= (unsigned int)nbits()); + return (value_ >> lsb) & ((1 << nbit) - 1); +} + +bool FPGAWord::atExtreme() const { + if (positive_) { + return (value_ == 0) || (value_ == (1 << nbits_) - 1); + } + return ((value_ == (-(1 << (nbits_ - 1)))) || (value_ == ((1 << (nbits_ - 1)) - 1))); +} + +bool FPGAWord::operator==(const FPGAWord& other) const { + return (value_ == other.value_) && (nbits_ == other.nbits_) && (positive_ == other.positive_); +} diff --git a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc new file mode 100644 index 0000000000000..695abc9738835 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc @@ -0,0 +1,1024 @@ +#include "L1Trigger/TrackFindingTracklet/interface/FitTrack.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackDerTable.h" +#include "L1Trigger/TrackFindingTracklet/interface/HybridFit.h" +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +using namespace std; +using namespace trklet; + +FitTrack::FitTrack(string name, Settings const& settings, Globals* global, unsigned int iSector) + : ProcessBase(name, settings, global, iSector), trackfit_(nullptr) {} + +void FitTrack::addOutput(MemoryBase* memory, string output) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " + << output; + } + if (output == "trackout") { + TrackFitMemory* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + trackfit_ = tmp; + return; + } + + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " addOutput, output = " << output << " not known"; +} + +void FitTrack::addInput(MemoryBase* memory, string input) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " + << input; + } + if (input.substr(0, 4) == "tpar") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + seedtracklet_.push_back(tmp); + return; + } + if (input.substr(0, 10) == "fullmatch1") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + fullmatch1_.push_back(tmp); + return; + } + if (input.substr(0, 10) == "fullmatch2") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + fullmatch2_.push_back(tmp); + return; + } + if (input.substr(0, 10) == "fullmatch3") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + fullmatch3_.push_back(tmp); + return; + } + if (input.substr(0, 10) == "fullmatch4") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + fullmatch4_.push_back(tmp); + return; + } + + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " input = " << input << " not found"; +} + +#ifdef USEHYBRID +void FitTrack::trackFitKF(Tracklet* tracklet, + std::vector& trackstublist, + std::vector>& stubidslist) { + if (settings_.doKF()) { + // From full match lists, collect all the stubs associated with the tracklet seed + + // Get seed stubs first + trackstublist.emplace_back(tracklet->innerFPGAStub()); + if (tracklet->getISeed() >= (int)N_TRKLSEED + 1) + trackstublist.emplace_back(tracklet->middleFPGAStub()); + trackstublist.emplace_back(tracklet->outerFPGAStub()); + + // Now get ALL matches (can have multiple per layer) + for (const auto& i : fullmatch1_) { + for (unsigned int j = 0; j < i->nMatches(); j++) { + if (i->getTracklet(j)->TCID() == tracklet->TCID()) { + trackstublist.push_back(i->getMatch(j).second); + } + } + } + + for (const auto& i : fullmatch2_) { + for (unsigned int j = 0; j < i->nMatches(); j++) { + if (i->getTracklet(j)->TCID() == tracklet->TCID()) { + trackstublist.push_back(i->getMatch(j).second); + } + } + } + + for (const auto& i : fullmatch3_) { + for (unsigned int j = 0; j < i->nMatches(); j++) { + if (i->getTracklet(j)->TCID() == tracklet->TCID()) { + trackstublist.push_back(i->getMatch(j).second); + } + } + } + + for (const auto& i : fullmatch4_) { + for (unsigned int j = 0; j < i->nMatches(); j++) { + if (i->getTracklet(j)->TCID() == tracklet->TCID()) { + trackstublist.push_back(i->getMatch(j).second); + } + } + } + + // For merge removal, loop through the resulting list of stubs to calculate their stubids + if (settings_.removalType() == "merge") { + for (const auto& it : trackstublist) { + int layer = it->layer().value() + 1; // Assume layer (1-6) stub first + if (it->layer().value() < 0) { // if disk stub, though... + layer = it->disk().value() + 10 * it->disk().value() / abs(it->disk().value()); //disk = +/- 11-15 + } + stubidslist.push_back(std::make_pair(layer, it->phiregionaddress())); + } + + // And that's all we need! The rest is just for fitting (in PurgeDuplicate) + return; + } + + HybridFit hybridFitter(iSector_, settings_, globals_); + hybridFitter.Fit(tracklet, trackstublist); + return; + } +} +#endif + +void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std::vector>&) { + if (globals_->trackDerTable() == nullptr) { + TrackDerTable* derTablePtr = new TrackDerTable(settings_); + + derTablePtr->readPatternFile(settings_.fitPatternFile()); + derTablePtr->fillTable(); + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Number of entries in derivative table: " << derTablePtr->getEntries(); + } + assert(derTablePtr->getEntries() != 0); + + globals_->trackDerTable() = derTablePtr; + } + + const TrackDerTable& derTable = *globals_->trackDerTable(); + + //First step is to build list of layers and disks. + int layers[N_LAYER]; + double r[N_LAYER]; + unsigned int nlayers = 0; // layers with found stub-projections + int disks[N_DISK]; + double z[N_DISK]; + unsigned int ndisks = 0; // disks with found stub-projections + + // residuals for each stub + double phiresid[N_FITSTUB]; + double zresid[N_FITSTUB]; + double phiresidexact[N_FITSTUB]; + double zresidexact[N_FITSTUB]; + int iphiresid[N_FITSTUB]; + int izresid[N_FITSTUB]; + double alpha[N_FITSTUB]; + + for (unsigned int i = 0; i < N_FITSTUB; i++) { + iphiresid[i] = 0; + izresid[i] = 0; + alpha[i] = 0.0; + + phiresid[i] = 0.0; + zresid[i] = 0.0; + phiresidexact[i] = 0.0; + zresidexact[i] = 0.0; + } + + std::bitset lmatches; //layer matches + std::bitset dmatches; //disk matches (2 per disk to separate 2S from PS) + + int mult = 1; + + unsigned int layermask = 0; + unsigned int diskmask = 0; + unsigned int alphaindex = 0; + unsigned int power = 1; + + double t = tracklet->t(); + double rinv = tracklet->rinv(); + + if (tracklet->isBarrel()) { + for (unsigned int l = 1; l <= N_LAYER; l++) { + if (l == (unsigned int)tracklet->layer() || l == (unsigned int)tracklet->layer() + 1) { + lmatches.set(N_LAYER - l); + layermask |= (1 << (N_LAYER - l)); + layers[nlayers++] = l; + continue; + } + if (tracklet->match(l)) { + lmatches.set(N_LAYER - l); + layermask |= (1 << (N_LAYER - l)); + phiresid[nlayers] = tracklet->phiresidapprox(l); + zresid[nlayers] = tracklet->zresidapprox(l); + phiresidexact[nlayers] = tracklet->phiresid(l); + zresidexact[nlayers] = tracklet->zresid(l); + iphiresid[nlayers] = tracklet->fpgaphiresid(l).value(); + izresid[nlayers] = tracklet->fpgazresid(l).value(); + + layers[nlayers++] = l; + } + } + + for (unsigned int d = 1; d <= N_DISK; d++) { + if (layermask & (1 << (d - 1))) + continue; + + if (mult == 1 << (3 * settings_.alphaBitsTable())) + continue; + + if (ndisks + nlayers >= N_FITSTUB) + continue; + if (tracklet->matchdisk(d)) { + if (std::abs(tracklet->alphadisk(d)) < 1e-20) { + dmatches.set(2 * d - 1); + diskmask |= (1 << (2 * (N_DISK - d) + 1)); + } else { + int ialpha = tracklet->ialphadisk(d).value(); + int nalpha = tracklet->ialphadisk(d).nbits(); + nalpha = nalpha - settings_.alphaBitsTable(); + ialpha = (1 << (settings_.alphaBitsTable() - 1)) + (ialpha >> nalpha); + + alphaindex += ialpha * power; + power = power << settings_.alphaBitsTable(); + dmatches.set(2 * (N_DISK - d)); + diskmask |= (1 << (2 * (N_DISK - d))); + mult = mult << settings_.alphaBitsTable(); + } + alpha[ndisks] = tracklet->alphadisk(d); + phiresid[nlayers + ndisks] = tracklet->phiresidapproxdisk(d); + zresid[nlayers + ndisks] = tracklet->rresidapproxdisk(d); + phiresidexact[nlayers + ndisks] = tracklet->phiresiddisk(d); + zresidexact[nlayers + ndisks] = tracklet->rresiddisk(d); + iphiresid[nlayers + ndisks] = tracklet->fpgaphiresiddisk(d).value(); + izresid[nlayers + ndisks] = tracklet->fpgarresiddisk(d).value(); + + disks[ndisks++] = d; + } + } + + if (settings_.writeMonitorData("HitPattern")) { + if (mult <= 1 << (3 * settings_.alphaBitsTable())) { + globals_->ofstream("hitpattern.txt") + << lmatches.to_string() << " " << dmatches.to_string() << " " << mult << endl; + } + } + } + + if (tracklet->isDisk()) { + for (unsigned int l = 1; l <= 2; l++) { + if (tracklet->match(l)) { + lmatches.set(N_LAYER - l); + + layermask |= (1 << (N_LAYER - l)); + + phiresid[nlayers] = tracklet->phiresidapprox(l); + zresid[nlayers] = tracklet->zresidapprox(l); + phiresidexact[nlayers] = tracklet->phiresid(l); + zresidexact[nlayers] = tracklet->zresid(l); + iphiresid[nlayers] = tracklet->fpgaphiresid(l).value(); + izresid[nlayers] = tracklet->fpgazresid(l).value(); + + layers[nlayers++] = l; + } + } + + for (unsigned int d1 = 1; d1 <= N_DISK; d1++) { + int d = d1; + + // skip F/B5 if there's already a L2 match + if (d == 5 and layermask & (1 << 4)) + continue; + + if (tracklet->fpgat().value() < 0.0) + d = -d1; + if (d == tracklet->disk() || d == tracklet->disk2()) { + dmatches.set(2 * d1 - 1); + diskmask |= (1 << (2 * (N_DISK - d1) + 1)); + alpha[ndisks] = 0.0; + disks[ndisks++] = d; + continue; + } + + if (ndisks + nlayers >= N_FITSTUB) + continue; + if (tracklet->matchdisk(d)) { + if (std::abs(tracklet->alphadisk(d)) < 1e-20) { + dmatches.set(2 * d1 - 1); + diskmask |= (1 << (2 * (N_DISK - d1) + 1)); + } else { + int ialpha = tracklet->ialphadisk(d).value(); + int nalpha = tracklet->ialphadisk(d).nbits(); + nalpha = nalpha - settings_.alphaBitsTable(); + ialpha = (1 << (settings_.alphaBitsTable() - 1)) + (ialpha >> nalpha); + + alphaindex += ialpha * power; + power = power << settings_.alphaBitsTable(); + dmatches.set(2 * (N_DISK - d1)); + diskmask |= (1 << (2 * (N_DISK - d1))); + mult = mult << settings_.alphaBitsTable(); + } + + alpha[ndisks] = tracklet->alphadisk(d); + assert(std::abs(tracklet->phiresidapproxdisk(d)) < 0.2); + phiresid[nlayers + ndisks] = tracklet->phiresidapproxdisk(d); + zresid[nlayers + ndisks] = tracklet->rresidapproxdisk(d); + assert(std::abs(tracklet->phiresiddisk(d)) < 0.2); + phiresidexact[nlayers + ndisks] = tracklet->phiresiddisk(d); + zresidexact[nlayers + ndisks] = tracklet->rresiddisk(d); + iphiresid[nlayers + ndisks] = tracklet->fpgaphiresiddisk(d).value(); + izresid[nlayers + ndisks] = tracklet->fpgarresiddisk(d).value(); + + disks[ndisks++] = d; + } + } + } + + if (tracklet->isOverlap()) { + for (unsigned int l = 1; l <= 2; l++) { + if (l == (unsigned int)tracklet->layer()) { + lmatches.set(N_LAYER - l); + layermask |= (1 << (N_LAYER - l)); + layers[nlayers++] = l; + continue; + } + if (tracklet->match(l)) { + lmatches.set(N_LAYER - l); + layermask |= (1 << (N_LAYER - l)); + assert(std::abs(tracklet->phiresidapprox(l)) < 0.2); + phiresid[nlayers] = tracklet->phiresidapprox(l); + zresid[nlayers] = tracklet->zresidapprox(l); + assert(std::abs(tracklet->phiresid(l)) < 0.2); + phiresidexact[nlayers] = tracklet->phiresid(l); + zresidexact[nlayers] = tracklet->zresid(l); + iphiresid[nlayers] = tracklet->fpgaphiresid(l).value(); + izresid[nlayers] = tracklet->fpgazresid(l).value(); + + layers[nlayers++] = l; + } + } + + for (unsigned int d1 = 1; d1 <= N_DISK; d1++) { + if (mult == 1 << (3 * settings_.alphaBitsTable())) + continue; + int d = d1; + if (tracklet->fpgat().value() < 0.0) + d = -d1; + if (d == tracklet->disk()) { //All seeds in PS modules + disks[ndisks] = tracklet->disk(); + dmatches.set(2 * d1 - 1); + diskmask |= (1 << (2 * (N_DISK - d1) + 1)); + ndisks++; + continue; + } + + if (ndisks + nlayers >= N_FITSTUB) + continue; + if (tracklet->matchdisk(d)) { + if (std::abs(tracklet->alphadisk(d)) < 1e-20) { + dmatches.set(2 * (N_DISK - d1)); + diskmask |= (1 << (2 * (N_DISK - d1) + 1)); + FPGAWord tmp; + tmp.set(diskmask, 10); + } else { + int ialpha = tracklet->ialphadisk(d).value(); + int nalpha = tracklet->ialphadisk(d).nbits(); + nalpha = nalpha - settings_.alphaBitsTable(); + ialpha = (1 << (settings_.alphaBitsTable() - 1)) + (ialpha >> nalpha); + + alphaindex += ialpha * power; + power = power << settings_.alphaBitsTable(); + dmatches.set(2 * (N_DISK - d1)); + diskmask |= (1 << (2 * (N_DISK - d1))); + FPGAWord tmp; + tmp.set(diskmask, 10); + mult = mult << settings_.alphaBitsTable(); + } + + alpha[ndisks] = tracklet->alphadisk(d); + assert(std::abs(tracklet->phiresidapproxdisk(d)) < 0.2); + phiresid[nlayers + ndisks] = tracklet->phiresidapproxdisk(d); + zresid[nlayers + ndisks] = tracklet->rresidapproxdisk(d); + assert(std::abs(tracklet->phiresiddisk(d)) < 0.2); + phiresidexact[nlayers + ndisks] = tracklet->phiresiddisk(d); + zresidexact[nlayers + ndisks] = tracklet->rresiddisk(d); + iphiresid[nlayers + ndisks] = tracklet->fpgaphiresiddisk(d).value(); + izresid[nlayers + ndisks] = tracklet->fpgarresiddisk(d).value(); + + disks[ndisks++] = d; + } + } + } + + int rinvindex = + (1 << (settings_.nrinvBitsTable() - 1)) * rinv / settings_.rinvmax() + (1 << (settings_.nrinvBitsTable() - 1)); + if (rinvindex < 0) + rinvindex = 0; + if (rinvindex >= (1 << settings_.nrinvBitsTable())) + rinvindex = (1 << settings_.nrinvBitsTable()) - 1; + + const TrackDer* derivatives = derTable.getDerivatives(layermask, diskmask, alphaindex, rinvindex); + + if (derivatives == nullptr) { + if (settings_.warnNoDer()) { + FPGAWord tmpl, tmpd; + tmpl.set(layermask, 6); + tmpd.set(diskmask, 10); + edm::LogVerbatim("Tracklet") << "No derivative for layermask, diskmask : " << layermask << " " << tmpl.str() + << " " << diskmask << " " << tmpd.str() << " eta = " << asinh(t); + } + return; + } + + double ttabi = TrackDerTable::tpar(settings_, diskmask, layermask); + if (t < 0.0) + ttabi = -ttabi; + double ttab = ttabi; + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Doing trackfit in " << getName(); + } + + int sign = 1; + if (t < 0.0) + sign = -1; + + double rstub[6]; + + double realrstub[3]; + realrstub[0] = -1.0; + realrstub[1] = -1.0; + realrstub[2] = -1.0; + + for (unsigned i = 0; i < nlayers; i++) { + r[i] = settings_.rmean(layers[i] - 1); + if (layers[i] == tracklet->layer()) { + if (tracklet->isOverlap()) { + realrstub[i] = tracklet->outerStub()->r(); + } else { + realrstub[i] = tracklet->innerStub()->r(); + } + } + if (layers[i] == tracklet->layer() + 1) { + realrstub[i] = tracklet->outerStub()->r(); + } + if (tracklet->validResid(layers[i]) && layers[i] < 4) { + const Stub* stubptr = tracklet->stubptr(layers[i]); + realrstub[i] = stubptr->l1tstub()->r(); + assert(std::abs(realrstub[i] - r[i]) < 5.0); + } + rstub[i] = r[i]; + } + for (unsigned i = 0; i < ndisks; i++) { + z[i] = sign * settings_.zmean(abs(disks[i]) - 1); + rstub[i + nlayers] = z[i] / ttabi; + } + + double D[N_FITPARAM][N_FITSTUB * 2]; + double MinvDt[N_FITPARAM][N_FITSTUB * 2]; + int iD[N_FITPARAM][N_FITSTUB * 2]; + int iMinvDt[N_FITPARAM][N_FITSTUB * 2]; + double sigma[N_FITSTUB * 2]; + double kfactor[N_FITSTUB * 2]; + + unsigned int n = nlayers + ndisks; + + if (settings_.exactderivatives()) { + TrackDerTable::calculateDerivatives( + settings_, nlayers, r, ndisks, z, alpha, t, rinv, D, iD, MinvDt, iMinvDt, sigma, kfactor); + ttabi = t; + ttab = t; + } else { + if (settings_.exactderivativesforfloating()) { + TrackDerTable::calculateDerivatives( + settings_, nlayers, r, ndisks, z, alpha, t, rinv, D, iD, MinvDt, iMinvDt, sigma, kfactor); + + double MinvDtDummy[N_FITPARAM][N_FITSTUB * 2]; + derivatives->fill(tracklet->fpgat().value(), MinvDtDummy, iMinvDt); + ttab = t; + } else { + derivatives->fill(tracklet->fpgat().value(), MinvDt, iMinvDt); + } + } + + if (!settings_.exactderivatives()) { + for (unsigned int i = 0; i < nlayers; i++) { + if (r[i] > settings_.rPS2S()) + continue; + for (unsigned int ii = 0; ii < nlayers; ii++) { + if (r[ii] > settings_.rPS2S()) + continue; + + double tder = derivatives->tdzcorr(i, ii); + double zder = derivatives->z0dzcorr(i, ii); + + double dr = realrstub[i] - r[i]; + + MinvDt[2][2 * ii + 1] += dr * tder; + MinvDt[3][2 * ii + 1] += dr * zder; + + int itder = derivatives->itdzcorr(i, ii); + int izder = derivatives->iz0dzcorr(i, ii); + + int idr = dr / settings_.kr(); + + iMinvDt[2][2 * ii + 1] += ((idr * itder) >> settings_.rcorrbits()); + iMinvDt[3][2 * ii + 1] += ((idr * izder) >> settings_.rcorrbits()); + } + } + } + + double rinvseed = tracklet->rinvapprox(); + double phi0seed = tracklet->phi0approx(); + double tseed = tracklet->tapprox(); + double z0seed = tracklet->z0approx(); + + double rinvseedexact = tracklet->rinv(); + double phi0seedexact = tracklet->phi0(); + double tseedexact = tracklet->t(); + double z0seedexact = tracklet->z0(); + + double chisqseed = 0.0; + double chisqseedexact = 0.0; + + double delta[2 * N_FITSTUB]; + double deltaexact[2 * N_FITSTUB]; + int idelta[2 * N_FITSTUB]; + + for (unsigned int i = 0; i < 2 * N_FITSTUB; i++) { + delta[i] = 0.0; + deltaexact[i] = 0.0; + idelta[i] = 0; + } + + int j = 0; + + for (unsigned int i = 0; i < n; i++) { + if (i >= nlayers) { + iphiresid[i] *= (t / ttabi); + phiresid[i] *= (t / ttab); + phiresidexact[i] *= (t / ttab); + } + + idelta[j] = iphiresid[i]; + delta[j] = phiresid[i]; + if (std::abs(phiresid[i]) > 0.2) { + edm::LogWarning("Tracklet") << getName() << " WARNING too large phiresid: " << phiresid[i] << " " + << phiresidexact[i]; + } + assert(std::abs(phiresid[i]) < 1.0); + assert(std::abs(phiresidexact[i]) < 1.0); + deltaexact[j++] = phiresidexact[i]; + + idelta[j] = izresid[i]; + delta[j] = zresid[i]; + deltaexact[j++] = zresidexact[i]; + + chisqseed += (delta[j - 2] * delta[j - 2] + delta[j - 1] * delta[j - 1]); + chisqseedexact += (deltaexact[j - 2] * deltaexact[j - 2] + deltaexact[j - 1] * deltaexact[j - 1]); + } + assert(j <= 12); + + double drinv = 0.0; + double dphi0 = 0.0; + double dt = 0.0; + double dz0 = 0.0; + + double drinvexact = 0.0; + double dphi0exact = 0.0; + double dtexact = 0.0; + double dz0exact = 0.0; + + int idrinv = 0; + int idphi0 = 0; + int idt = 0; + int idz0 = 0; + + double drinv_cov = 0.0; + double dphi0_cov = 0.0; + double dt_cov = 0.0; + double dz0_cov = 0.0; + + double drinv_covexact = 0.0; + double dphi0_covexact = 0.0; + double dt_covexact = 0.0; + double dz0_covexact = 0.0; + + for (unsigned int j = 0; j < 2 * n; j++) { + drinv -= MinvDt[0][j] * delta[j]; + dphi0 -= MinvDt[1][j] * delta[j]; + dt -= MinvDt[2][j] * delta[j]; + dz0 -= MinvDt[3][j] * delta[j]; + + drinv_cov += D[0][j] * delta[j]; + dphi0_cov += D[1][j] * delta[j]; + dt_cov += D[2][j] * delta[j]; + dz0_cov += D[3][j] * delta[j]; + + drinvexact -= MinvDt[0][j] * deltaexact[j]; + dphi0exact -= MinvDt[1][j] * deltaexact[j]; + dtexact -= MinvDt[2][j] * deltaexact[j]; + dz0exact -= MinvDt[3][j] * deltaexact[j]; + + drinv_covexact += D[0][j] * deltaexact[j]; + dphi0_covexact += D[1][j] * deltaexact[j]; + dt_covexact += D[2][j] * deltaexact[j]; + dz0_covexact += D[3][j] * deltaexact[j]; + + idrinv += ((iMinvDt[0][j] * idelta[j])); + idphi0 += ((iMinvDt[1][j] * idelta[j])); + idt += ((iMinvDt[2][j] * idelta[j])); + idz0 += ((iMinvDt[3][j] * idelta[j])); + + if (false && j % 2 == 0) { + edm::LogVerbatim("Tracklet") << "DEBUG CHI2FIT " << j << " " << rinvseed << " + " << MinvDt[0][j] * delta[j] + << " " << MinvDt[0][j] << " " << delta[j] * rstub[j / 2] * 10000 << " \n" + << j << " " << tracklet->fpgarinv().value() * settings_.krinvpars() << " + " + << ((iMinvDt[0][j] * idelta[j])) * settings_.krinvpars() / 1024.0 << " " + << iMinvDt[0][j] * settings_.krinvpars() / settings_.kphi() / 1024.0 << " " + << idelta[j] * settings_.kphi() * rstub[j / 2] * 10000 << " " << idelta[j]; + } + } + + double deltaChisqexact = + drinvexact * drinv_covexact + dphi0exact * dphi0_covexact + dtexact * dt_covexact + dz0exact * dz0_covexact; + + int irinvseed = tracklet->fpgarinv().value(); + int iphi0seed = tracklet->fpgaphi0().value(); + + int itseed = tracklet->fpgat().value(); + int iz0seed = tracklet->fpgaz0().value(); + + int irinvfit = irinvseed + ((idrinv + (1 << settings_.fitrinvbitshift())) >> settings_.fitrinvbitshift()); + + int iphi0fit = iphi0seed + (idphi0 >> settings_.fitphi0bitshift()); + int itfit = itseed + (idt >> settings_.fittbitshift()); + + int iz0fit = iz0seed + (idz0 >> settings_.fitz0bitshift()); + + double rinvfit = rinvseed - drinv; + double phi0fit = phi0seed - dphi0; + + double tfit = tseed - dt; + double z0fit = z0seed - dz0; + + double rinvfitexact = rinvseedexact - drinvexact; + double phi0fitexact = phi0seedexact - dphi0exact; + + double tfitexact = tseedexact - dtexact; + double z0fitexact = z0seedexact - dz0exact; + + double chisqfitexact = chisqseedexact + deltaChisqexact; + + ////////////// NEW CHISQ ///////////////////// + bool NewChisqDebug = false; + double chisqfit = 0.0; + uint ichisqfit = 0; + + double phifactor; + double rzfactor; + double iphifactor; + double irzfactor; + int k = 0; // column index of D matrix + + if (NewChisqDebug) { + edm::LogVerbatim("Tracklet") << "OG chisq: \n" + << "drinv/cov = " << drinv << "/" << drinv_cov << " \n" + << "dphi0/cov = " << drinv << "/" << dphi0_cov << " \n" + << "dt/cov = " << drinv << "/" << dt_cov << " \n" + << "dz0/cov = " << drinv << "/" << dz0_cov << "\n"; + std::string myout = "D[0][k]= "; + for (unsigned int i = 0; i < 2 * n; i++) { + myout += std::to_string(D[0][i]); + myout += ", "; + } + edm::LogVerbatim("Tracklet") << myout; + } + + for (unsigned int i = 0; i < n; i++) { // loop over stubs + + phifactor = rstub[k / 2] * delta[k] / sigma[k] + D[0][k] * drinv + D[1][k] * dphi0 + D[2][k] * dt + D[3][k] * dz0; + iphifactor = kfactor[k] * rstub[k / 2] * idelta[k] * (1 << settings_.chisqphifactbits()) / sigma[k] - + iD[0][k] * idrinv - iD[1][k] * idphi0 - iD[2][k] * idt - iD[3][k] * idz0; + + if (NewChisqDebug) { + edm::LogVerbatim("Tracklet") << "delta[k]/sigma = " << delta[k] / sigma[k] << " delta[k] = " << delta[k] << "\n" + << "sum = " << phifactor - delta[k] / sigma[k] << " drinvterm = " << D[0][k] * drinv + << " dphi0term = " << D[1][k] * dphi0 << " dtterm = " << D[2][k] * dt + << " dz0term = " << D[3][k] * dz0 << "\n phifactor = " << phifactor; + } + + chisqfit += phifactor * phifactor; + ichisqfit += iphifactor * iphifactor / (1 << (2 * settings_.chisqphifactbits() - 4)); + + k++; + + rzfactor = delta[k] / sigma[k] + D[0][k] * drinv + D[1][k] * dphi0 + D[2][k] * dt + D[3][k] * dz0; + irzfactor = kfactor[k] * idelta[k] * (1 << settings_.chisqzfactbits()) / sigma[k] - iD[0][k] * idrinv - + iD[1][k] * idphi0 - iD[2][k] * idt - iD[3][k] * idz0; + + if (NewChisqDebug) { + edm::LogVerbatim("Tracklet") << "delta[k]/sigma = " << delta[k] / sigma[k] << " delta[k] = " << delta[k] << "\n" + << "sum = " << rzfactor - delta[k] / sigma[k] << " drinvterm = " << D[0][k] * drinv + << " dphi0term = " << D[1][k] * dphi0 << " dtterm = " << D[2][k] * dt + << " dz0term = " << D[3][k] * dz0 << "\n rzfactor = " << rzfactor; + } + + chisqfit += rzfactor * rzfactor; + ichisqfit += irzfactor * irzfactor / (1 << (2 * settings_.chisqzfactbits() - 4)); + + k++; + } + + if (settings_.writeMonitorData("ChiSq")) { + globals_->ofstream("chisq.txt") << asinh(itfit * settings_.ktpars()) << " " << chisqfit << " " << ichisqfit / 16.0 + << endl; + } + + // Chisquare per DOF capped out at 11 bits, so 15 is an educated guess + if (ichisqfit >= (1 << 15)) { + if (NewChisqDebug) { + edm::LogVerbatim("Tracklet") << "CHISQUARE (" << ichisqfit << ") LARGER THAN 11 BITS!"; + } + ichisqfit = (1 << 15) - 1; + } + + // Eliminate lower bits to fit in 8 bits + ichisqfit = ichisqfit >> 7; + // Probably redundant... enforce 8 bit cap + if (ichisqfit >= (1 << 8)) + ichisqfit = (1 << 8) - 1; + + double phicrit = phi0fit - asin(0.5 * settings_.rcrit() * rinvfit); + bool keep = (phicrit > settings_.phicritmin()) && (phicrit < settings_.phicritmax()); + + if (!keep) { + return; + } + + // NOTE: setFitPars in Tracklet.h now accepts chi2 r-phi and chi2 r-z values. This class only has access + // to the composite chi2. When setting fit parameters on a tracklet, this places all of the chi2 into the + // r-phi fit, and sets the r-z fit value to zero. + // + // This is also true for the call to setFitPars in trackFitFake. + tracklet->setFitPars(rinvfit, + phi0fit, + 0.0, + tfit, + z0fit, + chisqfit, + 0.0, + rinvfitexact, + phi0fitexact, + 0.0, + tfitexact, + z0fitexact, + chisqfitexact, + 0.0, + irinvfit, + iphi0fit, + 0, + itfit, + iz0fit, + ichisqfit, + 0, + 0); +} + +void FitTrack::trackFitFake(Tracklet* tracklet, std::vector&, std::vector>&) { + tracklet->setFitPars(tracklet->rinvapprox(), + tracklet->phi0approx(), + tracklet->d0approx(), + tracklet->tapprox(), + tracklet->z0approx(), + 0.0, + 0.0, + tracklet->rinv(), + tracklet->phi0(), + tracklet->d0(), + tracklet->t(), + tracklet->z0(), + 0.0, + 0.0, + tracklet->fpgarinv().value(), + tracklet->fpgaphi0().value(), + tracklet->fpgad0().value(), + tracklet->fpgat().value(), + tracklet->fpgaz0().value(), + 0, + 0, + 0); + return; +} + +std::vector FitTrack::orderedMatches(vector& fullmatch) { + std::vector tmp; + + std::vector indexArray; + for (auto& imatch : fullmatch) { + //check that we have correct order + if (imatch->nMatches() > 1) { + for (unsigned int j = 0; j < imatch->nMatches() - 1; j++) { + assert(imatch->getTracklet(j)->TCID() <= imatch->getTracklet(j + 1)->TCID()); + } + } + + if (settings_.debugTracklet() && imatch->nMatches() != 0) { + edm::LogVerbatim("Tracklet") << "orderedMatches: " << imatch->getName() << " " << imatch->nMatches(); + } + + indexArray.push_back(0); + } + + int bestIndex = -1; + do { + int bestTCID = (1 << 16); + bestIndex = -1; + for (unsigned int i = 0; i < fullmatch.size(); i++) { + if (indexArray[i] >= fullmatch[i]->nMatches()) { + //skip as we were at the end + continue; + } + int TCID = fullmatch[i]->getTracklet(indexArray[i])->TCID(); + if (TCID < bestTCID) { + bestTCID = TCID; + bestIndex = i; + } + } + if (bestIndex != -1) { + tmp.push_back(fullmatch[bestIndex]->getTracklet(indexArray[bestIndex])); + indexArray[bestIndex]++; + } + } while (bestIndex != -1); + + for (unsigned int i = 0; i < tmp.size(); i++) { + if (i > 0) { + //This allows for equal TCIDs. This means that we can e.g. have a track seeded in L1L2 that projects to both L3 and D4. + //The algorithm will pick up the first hit and drop the second. + if (tmp[i - 1]->TCID() > tmp[i]->TCID()) { + edm::LogVerbatim("Tracklet") << "Wrong TCID ordering in " << getName() << " : " << tmp[i - 1]->TCID() << " " + << tmp[i]->TCID(); + } + } + } + + return tmp; +} + +void FitTrack::execute() { + // merge + const std::vector& matches1 = orderedMatches(fullmatch1_); + const std::vector& matches2 = orderedMatches(fullmatch2_); + const std::vector& matches3 = orderedMatches(fullmatch3_); + const std::vector& matches4 = orderedMatches(fullmatch4_); + + if (settings_.debugTracklet() && (matches1.size() + matches2.size() + matches3.size() + matches4.size()) > 0) { + for (auto& imatch : fullmatch1_) { + edm::LogVerbatim("Tracklet") << imatch->getName() << " " << imatch->nMatches(); + } + edm::LogVerbatim("Tracklet") << getName() << "[" << iSector_ << "] matches : " << matches1.size() << " " + << matches2.size() << " " << matches3.size() << " " << matches4.size(); + } + + unsigned int indexArray[4]; + for (unsigned int i = 0; i < 4; i++) { + indexArray[i] = 0; + } + + int countAll = 0; + int countFit = 0; + + Tracklet* bestTracklet = nullptr; + do { + countAll++; + bestTracklet = nullptr; + + if (indexArray[0] < matches1.size()) { + if (bestTracklet == nullptr) { + bestTracklet = matches1[indexArray[0]]; + } else { + if (matches1[indexArray[0]]->TCID() < bestTracklet->TCID()) + bestTracklet = matches1[indexArray[0]]; + } + } + + if (indexArray[1] < matches2.size()) { + if (bestTracklet == nullptr) { + bestTracklet = matches2[indexArray[1]]; + } else { + if (matches2[indexArray[1]]->TCID() < bestTracklet->TCID()) + bestTracklet = matches2[indexArray[1]]; + } + } + + if (indexArray[2] < matches3.size()) { + if (bestTracklet == nullptr) { + bestTracklet = matches3[indexArray[2]]; + } else { + if (matches3[indexArray[2]]->TCID() < bestTracklet->TCID()) + bestTracklet = matches3[indexArray[2]]; + } + } + + if (indexArray[3] < matches4.size()) { + if (bestTracklet == nullptr) { + bestTracklet = matches4[indexArray[3]]; + } else { + if (matches4[indexArray[3]]->TCID() < bestTracklet->TCID()) + bestTracklet = matches4[indexArray[3]]; + } + } + + if (bestTracklet == nullptr) + break; + + //Counts total number of matched hits + int nMatches = 0; + + //Counts unique hits in each layer + int nMatchesUniq = 0; + bool match = false; + + if (indexArray[0] < matches1.size()) { + while (matches1[indexArray[0]] == bestTracklet && indexArray[0] < matches1.size()) { + indexArray[0]++; + nMatches++; + match = true; + } + } + + if (match) + nMatchesUniq++; + match = false; + + if (indexArray[1] < matches2.size()) { + while (matches2[indexArray[1]] == bestTracklet && indexArray[1] < matches2.size()) { + indexArray[1]++; + nMatches++; + match = true; + } + } + + if (match) + nMatchesUniq++; + match = false; + + if (indexArray[2] < matches3.size()) { + while (matches3[indexArray[2]] == bestTracklet && indexArray[2] < matches3.size()) { + indexArray[2]++; + nMatches++; + match = true; + } + } + + if (match) + nMatchesUniq++; + match = false; + + if (indexArray[3] < matches4.size()) { + while (matches4[indexArray[3]] == bestTracklet && indexArray[3] < matches4.size()) { + indexArray[3]++; + nMatches++; + match = true; + } + } + + if (match) + nMatchesUniq++; + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " : nMatches = " << nMatches << " " << asinh(bestTracklet->t()); + } + + std::vector trackstublist; + std::vector> stubidslist; + if ((bestTracklet->getISeed() >= 8 && nMatchesUniq >= 1) || + nMatchesUniq >= 2) { //For seeds index >=8 (triplet seeds), there are three stubs associated from start. + countFit++; + +#ifdef USEHYBRID + trackFitKF(bestTracklet, trackstublist, stubidslist); +#else + if (settings_.fakefit()) { + trackFitFake(bestTracklet, trackstublist, stubidslist); + } else { + trackFitChisq(bestTracklet, trackstublist, stubidslist); + } +#endif + + if (settings_.removalType() == "merge") { + trackfit_->addStubList(trackstublist); + trackfit_->addStubidsList(stubidslist); + trackfit_->addTrack(bestTracklet); + } else if (bestTracklet->fit()) { + assert(trackfit_ != nullptr); + if (settings_.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << bestTracklet->getISeed() + << endl; + fout.close(); + } + trackfit_->addTrack(bestTracklet); + } + } + + } while (bestTracklet != nullptr); + + if (settings_.writeMonitorData("FT")) { + globals_->ofstream("fittrack.txt") << getName() << " " << countAll << " " << countFit << endl; + } +} diff --git a/L1Trigger/TrackFindingTracklet/src/FullMatchMemory.cc b/L1Trigger/TrackFindingTracklet/src/FullMatchMemory.cc new file mode 100644 index 0000000000000..ab24308469642 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/FullMatchMemory.cc @@ -0,0 +1,71 @@ +#include "L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" +#include +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +using namespace std; +using namespace trklet; + +FullMatchMemory::FullMatchMemory(string name, Settings const& settings, unsigned int iSector) + : MemoryBase(name, settings, iSector) { + if (settings_.extended()) { + initLayerDisk(10, layer_, disk_); + } else { + initLayerDisk(8, layer_, disk_); + } +} + +void FullMatchMemory::addMatch(Tracklet* tracklet, const Stub* stub) { + if (!settings_.doKF()) { //When using KF we allow multiple matches + for (auto& match : matches_) { + if (match.first == tracklet) { //Better match, replace + match.second = stub; + return; + } + } + } + std::pair tmp(tracklet, stub); + //Check that we have the right TCID order + if (!matches_.empty()) { + if ((!settings_.doKF() && matches_[matches_.size() - 1].first->TCID() >= tracklet->TCID()) || + (settings_.doKF() && matches_[matches_.size() - 1].first->TCID() > tracklet->TCID())) { + edm::LogPrint("Tracklet") << "Wrong TCID ordering in " << getName() << " : " + << matches_[matches_.size() - 1].first->TCID() << " " << tracklet->TCID() << " " + << matches_[matches_.size() - 1].first->trackletIndex() << " " + << tracklet->trackletIndex(); + } + } + matches_.push_back(tmp); +} + +void FullMatchMemory::writeMC(bool first) { + std::ostringstream oss; + oss << "../data/MemPrints/Matches/FullMatches_" << getName() << "_" << std::setfill('0') << std::setw(2) + << (iSector_ + 1) << ".dat"; + auto const& fname = oss.str(); + + if (first) { + bx_ = 0; + event_ = 1; + out_.open(fname.c_str()); + } else + out_.open(fname.c_str(), std::ofstream::app); + + out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; + + for (unsigned int j = 0; j < matches_.size(); j++) { + string match = (layer_ > 0) ? matches_[j].first->fullmatchstr(layer_) : matches_[j].first->fullmatchdiskstr(disk_); + out_ << "0x"; + out_ << std::setfill('0') << std::setw(2); + out_ << hex << j << dec; + out_ << " " << match << " " << trklet::hexFormat(match) << endl; + } + out_.close(); + + bx_++; + event_++; + if (bx_ > 7) + bx_ = 0; +} diff --git a/L1Trigger/TrackFindingTracklet/src/Globals.cc b/L1Trigger/TrackFindingTracklet/src/Globals.cc new file mode 100644 index 0000000000000..da35939f46014 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/Globals.cc @@ -0,0 +1,51 @@ +// Globals: holds "global" variables such as the IMATH_TrackletCalculators +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/imath.h" +#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" +#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorDisk.h" +#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorOverlap.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMRouterPhiCorrTable.h" +#include "L1Trigger/TrackFindingTracklet/interface/HistBase.h" + +using namespace std; +using namespace trklet; + +Globals::Globals(Settings const& settings) { + imathGlobals* imathGlobs = new imathGlobals(); + + //takes owernship of globals pointer + imathGlobals_.reset(imathGlobs); + + // tracklet calculators + ITC_L1L2_ = make_unique(settings, imathGlobs, 1, 2); + ITC_L2L3_ = make_unique(settings, imathGlobs, 2, 3); + ITC_L3L4_ = make_unique(settings, imathGlobs, 3, 4); + ITC_L5L6_ = make_unique(settings, imathGlobs, 5, 6); + + ITC_F1F2_ = make_unique(settings, imathGlobs, 1, 2); + ITC_F3F4_ = make_unique(settings, imathGlobs, 3, 4); + ITC_B1B2_ = make_unique(settings, imathGlobs, -1, -2); + ITC_B3B4_ = make_unique(settings, imathGlobs, -3, -4); + + ITC_L1F1_ = make_unique(settings, imathGlobs, 1, 1); + ITC_L2F1_ = make_unique(settings, imathGlobs, 2, 1); + ITC_L1B1_ = make_unique(settings, imathGlobs, 1, -1); + ITC_L2B1_ = make_unique(settings, imathGlobs, 2, -1); +} + +Globals::~Globals() { + for (auto i : thePhiCorr_) { + delete i; + i = nullptr; + } +} + +std::ofstream& Globals::ofstream(std::string fname) { + if (ofstreams_.find(fname) != ofstreams_.end()) { + return *(ofstreams_[fname]); + } + std::ofstream* outptr = new std::ofstream(fname.c_str()); + ofstreams_[fname] = outptr; + return *outptr; +} diff --git a/L1Trigger/TrackFindingTracklet/src/HybridFit.cc b/L1Trigger/TrackFindingTracklet/src/HybridFit.cc new file mode 100644 index 0000000000000..2867bb70a0dbd --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/HybridFit.cc @@ -0,0 +1,251 @@ +#include "L1Trigger/TrackFindingTracklet/interface/HybridFit.h" +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" + +#ifdef USEHYBRID +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "DataFormats/Math/interface/deltaPhi.h" + +using namespace std; +using namespace trklet; + +HybridFit::HybridFit(unsigned int iSector, Settings const& settings, Globals* globals) : settings_(settings) { + iSector_ = iSector; + globals_ = globals; +} + +void HybridFit::Fit(Tracklet* tracklet, std::vector& trackstublist) { + if (settings_.fakefit()) { + tracklet->setFitPars(tracklet->rinvapprox(), + tracklet->phi0approx(), + tracklet->d0approx(), + tracklet->tapprox(), + tracklet->z0approx(), + 0., + 0., + tracklet->rinv(), + tracklet->phi0(), + tracklet->d0(), + tracklet->t(), + tracklet->z0(), + 0., + 0., + tracklet->fpgarinv().value(), + tracklet->fpgaphi0().value(), + tracklet->fpgad0().value(), + tracklet->fpgat().value(), + tracklet->fpgaz0().value(), + 0, + 0, + 0); + return; + } + + std::vector TMTTstubs; + std::map L1StubIndices; + unsigned int L1stubID = 0; + + if (globals_->tmttSettings() == nullptr) { + if (settings_.printDebugKF()) + edm::LogVerbatim("L1track") << "Creating TMTT::Settings in HybridFit::Fit"; + globals_->tmttSettings() = make_unique(); + globals_->tmttSettings()->setMagneticField(settings_.bfield()); + } + + const tmtt::Settings& TMTTsettings = *globals_->tmttSettings(); + + int kf_phi_sec = iSector_; + + for (unsigned int k = 0; k < trackstublist.size(); k++) { + const L1TStub* L1stubptr = trackstublist[k]->l1tstub(); + + double kfphi = L1stubptr->phi(); + double kfr = L1stubptr->r(); + double kfz = L1stubptr->z(); + double kfbend = L1stubptr->bend(); + bool psmodule = L1stubptr->isPSmodule(); + unsigned int iphi = L1stubptr->iphi(); + double alpha = L1stubptr->alpha(settings_.stripPitch(psmodule)); + bool isTilted = L1stubptr->isTilted(); + + bool isBarrel = trackstublist[k]->isBarrel(); + int kflayer; + + if (isBarrel) { // Barrel-specific + kflayer = L1stubptr->layer() + 1; + if (settings_.printDebugKF()) + edm::LogVerbatim("L1track") << "Will create layer stub with : "; + } else { // Disk-specific + kflayer = abs(L1stubptr->disk()); + if (kfz > 0) { + kflayer += 10; + } else { + kflayer += 20; + } + if (settings_.printDebugKF()) + edm::LogVerbatim("L1track") << "Will create disk stub with : "; + } + + float stripPitch = settings_.stripPitch(psmodule); + float stripLength = settings_.stripLength(psmodule); + unsigned int nStrips = settings_.nStrips(psmodule); + + if (settings_.printDebugKF()) { + edm::LogVerbatim("L1track") << kfphi << " " << kfr << " " << kfz << " " << kfbend << " " << kflayer << " " + << isBarrel << " " << psmodule << " " << isTilted << " \n" + << stripPitch << " " << stripLength << " " << nStrips; + } + + unsigned int uniqueStubIndex = 1000 * L1stubID + L1stubptr->allStubIndex(); + tmtt::Stub* TMTTstubptr = new tmtt::Stub(&TMTTsettings, + uniqueStubIndex, + kfphi, + kfr, + kfz, + kfbend, + iphi, + -alpha, + kflayer, + kf_phi_sec, + psmodule, + isBarrel, + isTilted, + stripPitch, + stripLength, + nStrips); + TMTTstubs.push_back(TMTTstubptr); + L1StubIndices[uniqueStubIndex] = L1stubptr; + L1stubID++; + } + + if (settings_.printDebugKF()) { + edm::LogVerbatim("L1track") << "Made TMTTstubs: trackstublist.size() = " << trackstublist.size(); + } + + double kfrinv = tracklet->rinvapprox(); + double kfphi0 = tracklet->phi0approx(); + double kfz0 = tracklet->z0approx(); + double kft = tracklet->tapprox(); + double kfd0 = tracklet->d0approx(); + + if (settings_.printDebugKF()) { + edm::LogVerbatim("L1track") << "tracklet phi0 = " << kfphi0 << "\n" + << "iSector = " << iSector_ << "\n" + << "dphisectorHG = " << settings_.dphisectorHG(); + } + + // KF wants global phi0, not phi0 measured with respect to lower edge of sector (Tracklet convention). + kfphi0 = reco::reduceRange(kfphi0 + iSector_ * settings_.dphisector() - 0.5 * settings_.dphisectorHG()); + + std::pair helixrphi(kfrinv / (0.01 * settings_.c() * settings_.bfield()), kfphi0); + std::pair helixrz(kfz0, kft); + + // KF HLS uses HT mbin (which is binned q/Pt) to allow for scattering. So estimate it from tracklet. + double chargeOverPt = helixrphi.first; + int mBin = std::floor(TMTTsettings.houghNbinsPt() / 2) + + std::floor((TMTTsettings.houghNbinsPt() / 2) * chargeOverPt / (1. / TMTTsettings.houghMinPt())); + mBin = max(min(mBin, int(TMTTsettings.houghNbinsPt() - 1)), 0); // protect precision issues. + std::pair celllocation(mBin, 1); + + // Get range in z of tracks covered by this sector at chosen radius from beam-line + const vector etaRegions = TMTTsettings.etaRegions(); + const float chosenRofZ = TMTTsettings.chosenRofZ(); + + float kfzRef = kfz0 + chosenRofZ * kft; + + unsigned int kf_eta_reg = 0; + for (unsigned int iEtaSec = 1; iEtaSec < etaRegions.size() - 1; iEtaSec++) { // Doesn't apply eta < 2.4 cut. + const float etaMax = etaRegions[iEtaSec]; + const float zRefMax = chosenRofZ / tan(2. * atan(exp(-etaMax))); + if (kfzRef > zRefMax) + kf_eta_reg = iEtaSec; + } + + tmtt::L1track3D l1track3d( + &TMTTsettings, TMTTstubs, celllocation, helixrphi, helixrz, kfd0, kf_phi_sec, kf_eta_reg, 1, false); + unsigned int seedType = tracklet->getISeed(); + unsigned int numPS = tracklet->PSseed(); // Function PSseed() is out of date! + l1track3d.setSeedLayerType(seedType); + l1track3d.setSeedPS(numPS); + + if (globals_->tmttKFParamsComb() == nullptr) { + if (settings_.printDebugKF()) + edm::LogVerbatim("L1track") << "Will make KFParamsComb for " << settings_.nHelixPar() << " param fit"; + globals_->tmttKFParamsComb() = make_unique(&TMTTsettings, settings_.nHelixPar(), "KFfitter"); + } + + tmtt::KFParamsComb& fitterKF = *globals_->tmttKFParamsComb(); + + // Call Kalman fit + tmtt::L1fittedTrack fittedTrk = fitterKF.fit(l1track3d); + + if (fittedTrk.accepted()) { + tmtt::KFTrackletTrack trk = fittedTrk.returnKFTrackletTrack(); + + if (settings_.printDebugKF()) + edm::LogVerbatim("L1track") << "Done with Kalman fit. Pars: pt = " << trk.pt() + << ", 1/2R = " << settings_.bfield() * 3 * trk.qOverPt() / 2000 + << ", phi0 = " << trk.phi0() << ", eta = " << trk.eta() << ", z0 = " << trk.z0() + << ", chi2 = " << trk.chi2() << ", accepted = " << trk.accepted(); + + // Tracklet wants phi0 with respect to lower edge of sector, not global phi0. + double phi0fit = reco::reduceRange(trk.phi0() - iSector_ * 2 * M_PI / N_SECTOR + 0.5 * settings_.dphisectorHG()); + + double rinvfit = 0.01 * settings_.c() * settings_.bfield() * trk.qOverPt(); + + int irinvfit = rinvfit / settings_.krinvpars(); + int iphi0fit = phi0fit / settings_.kphi0pars(); + int itanlfit = trk.tanLambda() / settings_.ktpars(); + int iz0fit = trk.z0() / settings_.kz0pars(); + int id0fit = trk.d0() / settings_.kd0pars(); + int ichi2rphifit = trk.chi2rphi() / 16; + int ichi2rzfit = trk.chi2rz() / 16; + + const vector& stubsFromFit = trk.stubs(); + vector l1stubsFromFit; + for (const tmtt::Stub* s : stubsFromFit) { + unsigned int IDf = s->index(); + const L1TStub* l1s = L1StubIndices.at(IDf); + l1stubsFromFit.push_back(l1s); + } + + if (settings_.printDebugKF()) { + edm::LogVerbatim("L1track") << "#stubs before/after KF fit = " << TMTTstubs.size() << "/" + << l1stubsFromFit.size(); + } + + tracklet->setFitPars(rinvfit, + phi0fit, + trk.d0(), + trk.tanLambda(), + trk.z0(), + trk.chi2rphi(), + trk.chi2rz(), + rinvfit, + phi0fit, + trk.d0(), + trk.tanLambda(), + trk.z0(), + trk.chi2rphi(), + trk.chi2rz(), + irinvfit, + iphi0fit, + id0fit, + itanlfit, + iz0fit, + ichi2rphifit, + ichi2rzfit, + trk.hitPattern(), + l1stubsFromFit); + } else { + if (settings_.printDebugKF()) { + edm::LogVerbatim("L1track") << "FitTrack:KF rejected track"; + } + } + + for (const tmtt::Stub* s : TMTTstubs) { + delete s; + } +} +#endif diff --git a/L1Trigger/TrackFindingTracklet/src/InputLinkMemory.cc b/L1Trigger/TrackFindingTracklet/src/InputLinkMemory.cc new file mode 100644 index 0000000000000..de31792a719ea --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/InputLinkMemory.cc @@ -0,0 +1,106 @@ +#include "L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMRouterPhiCorrTable.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" + +#include +#include +#include +#include + +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +using namespace trklet; +using namespace std; + +InputLinkMemory::InputLinkMemory(string name, Settings const& settings, unsigned int iSector, double, double) + : MemoryBase(name, settings, iSector) { + string subname = name.substr(5, 7); + phiregion_ = subname[3] - 'A'; + assert(phiregion_ >= 0 && phiregion_ < 8); + + layerdisk_ = initLayerDisk(3); +} + +bool InputLinkMemory::addStub( + Settings const& settings, Globals* globals, L1TStub& al1stub, Stub& stub, string dtc = "") { + if (layerdisk_ < N_LAYER && globals->phiCorr(layerdisk_) == nullptr) { + globals->phiCorr(layerdisk_) = new VMRouterPhiCorrTable(settings); + int nbits = 3; + if (layerdisk_ >= N_PSLAYER) + nbits = 4; + globals->phiCorr(layerdisk_)->init(layerdisk_ + 1, nbits, 3); + } + + unsigned int stublayerdisk = stub.layerdisk(); + assert(stublayerdisk < 11); + + if (stublayerdisk != layerdisk_) + return false; + + if (layerdisk_ < N_LAYER) { + FPGAWord r = stub.r(); + int bendbin = stub.bend().value(); + int rbin = (r.value() + (1 << (r.nbits() - 1))) >> (r.nbits() - 3); + const VMRouterPhiCorrTable& phiCorrTable = *globals->phiCorr(layerdisk_); + int iphicorr = phiCorrTable.getphiCorrValue(bendbin, rbin); + stub.setPhiCorr(iphicorr); + } + + FPGAWord iphi = stub.phicorr(); + unsigned int nallbits = settings_.nbitsallstubs(layerdisk_); + int phibin = iphi.bits(iphi.nbits() - nallbits, nallbits); + int iphivmRaw = iphi.bits(iphi.nbits() - 5, 5); + + if (phibin != phiregion_) + return false; + + if (getName().substr(10, dtc.size()) != dtc) + return false; + + string half = getName().substr(getName().size() - 3, 3); + if (half[1] != 'n') { + half = getName().substr(getName().size() - 1, 1); + } + + assert(half[0] == 'A' || half[0] == 'B'); + + if (half[0] == 'B' && iphivmRaw <= 15) + return false; + if (half[0] == 'A' && iphivmRaw > 15) + return false; + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Will add stub in " << getName() << " " + << "iphiwmRaw = " << iphivmRaw << " phi=" << al1stub.phi() << " z=" << al1stub.z() + << " r=" << al1stub.r(); + } + if (stubs_.size() < settings_.maxStep("Link")) { + Stub* stubptr = new Stub(stub); + stubptr->setl1tstub(new L1TStub(al1stub)); + + stubs_.emplace_back(stubptr); + } + return true; +} + +void InputLinkMemory::writeStubs(bool first) { + openFile(first, "../data/MemPrints/InputStubs/InputStubs_"); + + for (unsigned int j = 0; j < stubs_.size(); j++) { + string stub = stubs_[j]->str(); + out_ << std::setfill('0') << std::setw(2); + out_ << hex << j << dec; + out_ << " " << stub << " " << trklet::hexFormat(stub) << endl; + } + out_.close(); +} + +void InputLinkMemory::clean() { + for (auto& stub : stubs_) { + delete stub->l1tstub(); + delete stub; + } + stubs_.clear(); +} diff --git a/L1Trigger/TrackFindingTracklet/src/L1TStub.cc b/L1Trigger/TrackFindingTracklet/src/L1TStub.cc new file mode 100644 index 0000000000000..1ae8497e75396 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/L1TStub.cc @@ -0,0 +1,127 @@ +#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +using namespace std; +using namespace trklet; + +L1TStub::L1TStub() {} + +L1TStub::L1TStub(int eventid, + vector tps, + int iphi, + int iz, + int layer, + int ladder, + int module, + int strip, + double x, + double y, + double z, + double sigmax, + double sigmaz, + double pt, + double bend, + int isPSmodule, + int isFlipped) { + eventid_ = eventid; + tps_ = tps; + iphi_ = iphi; + iz_ = iz; + layer_ = layer; + ladder_ = ladder; + module_ = module; + strip_ = strip; + x_ = x; + y_ = y; + z_ = z; + sigmax_ = sigmax; + sigmaz_ = sigmaz; + pt_ = pt; + bend_ = bend; + isPSmodule_ = isPSmodule; + isFlipped_ = isFlipped; + + allstubindex_ = 999; +} + +void L1TStub::write(ofstream& out) { + out << "Stub: " << layer_ + 1 << "\t" << ladder_ << "\t" << module_ << "\t" << strip_ << "\t" << eventid_ << "\t" + << pt_ << "\t" << x_ << "\t" << y_ << "\t" << z_ << "\t" << bend_ << "\t" << isPSmodule_ << "\t" << isFlipped_ + << "\t" << tps_.size() << " \t"; + for (int itp : tps_) { + out << itp << " \t"; + } + out << endl; +} + +void L1TStub::write(ostream& out) { + out << "Stub: " << layer_ + 1 << "\t" << ladder_ << "\t" << module_ << "\t" << strip_ << "\t" << eventid_ << "\t" + << pt_ << "\t" << x_ << "\t" << y_ << "\t" << z_ << "\t" << bend_ << "\t" << isPSmodule_ << "\t" << isFlipped_ + << "\t" << tps_.size() << " \t"; + for (int itp : tps_) { + out << itp << " \t"; + } + out << endl; +} + +bool L1TStub::operator==(const L1TStub& other) const { + return (other.iphi() == iphi_ && other.iz() == iz_ && other.layer() == layer_ && other.ladder() == ladder_ && + other.module() == module_); +} + +void L1TStub::lorentzcor(double shift) { + double r = this->r(); + double phi = this->phi() - shift / r; + this->x_ = r * cos(phi); + this->y_ = r * sin(phi); +} + +double L1TStub::alpha(double pitch) const { + if (isPSmodule()) + return 0.0; + int flip = 1; + if (isFlipped()) + flip = -1; + if (z_ > 0.0) { + return ((int)strip_ - 509.5) * pitch * flip / r2(); + } + return -((int)strip_ - 509.5) * pitch * flip / r2(); +} + +double L1TStub::alphanorm() const { + if (isPSmodule()) + return 0.0; + int flip = 1; + if (isFlipped()) + flip = -1; + if (z_ > 0.0) { + return ((int)strip_ - 509.5) * flip / 510.0; + } + return -((int)strip_ - 509.5) * flip / 510.0; +} + +void L1TStub::setXY(double x, double y) { + x_ = x; + y_ = y; +} + +bool L1TStub::tpmatch(int tp) const { + for (int itp : tps_) { + if (tp == itp) + return true; + } + + return false; +} + +bool L1TStub::isTilted() const { + //here layer_ runs 0-5 for barrel, >1000 for disk + //disk modules and outer barrel modules are not tilted by construction + if (layer_ >= N_PSLAYER) + return false; + + assert(layer_ < N_PSLAYER); // safety for acccessing # modules/plank + if ((module_ <= N_TILTED_RINGS) || (module_ >= N_TILTED_RINGS + N_MOD_PLANK.at(layer_))) + return true; + return false; +} diff --git a/L1Trigger/TrackFindingTracklet/src/LayerProjection.cc b/L1Trigger/TrackFindingTracklet/src/LayerProjection.cc new file mode 100644 index 0000000000000..e6480bc930f7d --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/LayerProjection.cc @@ -0,0 +1,97 @@ +#include "L1Trigger/TrackFindingTracklet/interface/LayerProjection.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +using namespace std; +using namespace trklet; + +void LayerProjection::init(Settings const& settings, + int projlayer, + double rproj, + int iphiproj, + int izproj, + int iphider, + int izder, + double phiproj, + double zproj, + double phiprojder, + double zprojder, + double phiprojapprox, + double zprojapprox, + double phiprojderapprox, + double zprojderapprox) { + assert(projlayer > 0); + assert(projlayer <= N_LAYER); + + valid_ = true; + + rproj_ = rproj; + + projlayer_ = projlayer; + + assert(iphiproj >= 0); + + if (rproj < settings.rPS2S()) { + fpgaphiproj_.set(iphiproj, settings.nphibitsstub(0), true, __LINE__, __FILE__); + int iphivm = (iphiproj >> (settings.nphibitsstub(0) - 5)) & 0x7; + if ((projlayer_ % 2) == 1) { + iphivm ^= 4; + } + fpgaphiprojvm_.set(iphivm, 3, true, __LINE__, __FILE__); + fpgazproj_.set(izproj, settings.nzbitsstub(0), false, __LINE__, __FILE__); + int izvm = izproj >> (12 - 7) & 0xf; + fpgazprojvm_.set(izvm, 4, true, __LINE__, __FILE__); + fpgaphiprojder_.set(iphider, settings.nbitsphiprojderL123(), false, __LINE__, __FILE__); + fpgazprojder_.set(izder, settings.nbitszprojderL123(), false, __LINE__, __FILE__); + } else { + fpgaphiproj_.set(iphiproj, settings.nphibitsstub(5), true, __LINE__, __FILE__); + int iphivm = (iphiproj >> (settings.nphibitsstub(5) - 5)) & 0x7; + if ((projlayer_ % 2) == 1) { + iphivm ^= 4; + } + fpgaphiprojvm_.set(iphivm, 3, true, __LINE__, __FILE__); + fpgazproj_.set(izproj, settings.nzbitsstub(5), false, __LINE__, __FILE__); + int izvm = izproj >> (8 - 7) & 0xf; + fpgazprojvm_.set(izvm, 4, true, __LINE__, __FILE__); + fpgaphiprojder_.set(iphider, settings.nbitsphiprojderL456(), false, __LINE__, __FILE__); + fpgazprojder_.set(izder, settings.nbitszprojderL456(), false, __LINE__, __FILE__); + } + + ////Separate the vm projections into zbins + ////This determines the central bin: + ////int zbin=4+(zproj.value()>>(zproj.nbits()-3)); + ////But we need some range (particularly for L5L6 seed projecting to L1-L3): + unsigned int zbin1 = (1 << (settings.MEBinsBits() - 1)) + + (((fpgazproj_.value() >> (fpgazproj_.nbits() - settings.MEBinsBits() - 2)) - 2) >> 2); + unsigned int zbin2 = (1 << (settings.MEBinsBits() - 1)) + + (((fpgazproj_.value() >> (fpgazproj_.nbits() - settings.MEBinsBits() - 2)) + 2) >> 2); + if (zbin1 >= settings.MEBins()) + zbin1 = 0; //note that zbin1 is unsigned + if (zbin2 >= settings.MEBins()) + zbin2 = settings.MEBins() - 1; + assert(zbin1 <= zbin2); + assert(zbin2 - zbin1 <= 1); + fpgazbin1projvm_.set(zbin1, settings.MEBinsBits(), true, __LINE__, __FILE__); // first z bin + if (zbin1 == zbin2) + fpgazbin2projvm_.set(0, 1, true, __LINE__, __FILE__); // don't need to check adjacent z bin + else + fpgazbin2projvm_.set(1, 1, true, __LINE__, __FILE__); // do need to check next z bin + + //fine vm z bits. Use 4 bits for fine position. starting at zbin 1 + int finez = ((1 << (settings.MEBinsBits() + 2)) + + (fpgazproj_.value() >> (fpgazproj_.nbits() - (settings.MEBinsBits() + 3)))) - + (zbin1 << 3); + + fpgafinezvm_.set(finez, 4, true, __LINE__, __FILE__); // fine z postions starting at zbin1 + + phiproj_ = phiproj; + zproj_ = zproj; + phiprojder_ = phiprojder; + zprojder_ = zprojder; + + phiprojapprox_ = phiprojapprox; + zprojapprox_ = zprojapprox; + phiprojderapprox_ = phiprojderapprox; + zprojderapprox_ = zprojderapprox; +} diff --git a/L1Trigger/TrackFindingTracklet/src/LayerResidual.cc b/L1Trigger/TrackFindingTracklet/src/LayerResidual.cc new file mode 100644 index 0000000000000..b9483e5135881 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/LayerResidual.cc @@ -0,0 +1,42 @@ +#include "L1Trigger/TrackFindingTracklet/interface/LayerResidual.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +using namespace std; +using namespace trklet; + +void LayerResidual::init(Settings const& settings, + int layer, + int iphiresid, + int izresid, + int istubid, + double phiresid, + double zresid, + double phiresidapprox, + double zresidapprox, + double rstub, + const Stub* stubptr) { + assert(layer > 0); + assert(layer <= N_LAYER); + + if (valid_ && (std::abs(iphiresid) > std::abs(fpgaphiresid_.value()))) + return; + + valid_ = true; + + layer_ = layer; + + fpgaphiresid_.set(iphiresid, settings.phiresidbits(), false, __LINE__, __FILE__); + fpgazresid_.set(izresid, settings.zresidbits(), false, __LINE__, __FILE__); + int nbitsid = 10; + fpgastubid_.set(istubid, nbitsid, true, __LINE__, __FILE__); + assert(!fpgaphiresid_.atExtreme()); + + phiresid_ = phiresid; + zresid_ = zresid; + + phiresidapprox_ = phiresidapprox; + zresidapprox_ = zresidapprox; + + rstub_ = rstub; + stubptr_ = stubptr; +} diff --git a/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc b/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc new file mode 100644 index 0000000000000..7e43c32886922 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc @@ -0,0 +1,572 @@ +#include "L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" +#include "L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include "L1Trigger/TrackFindingTracklet/interface/HistBase.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" +#include "DataFormats/Math/interface/deltaPhi.h" + +using namespace std; +using namespace trklet; + +MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals* global, unsigned int iSector) + : ProcessBase(name, settings, global, iSector) { + phioffset_ = phimin_; + + phiregion_ = name[8] - 'A'; + layerdisk_ = initLayerDisk(3); + + fullMatches_.resize(12, nullptr); + + //TODO - need to sort out constants here + icorrshift_ = 7; + + if (layerdisk_ < N_PSLAYER) { + icorzshift_ = -1 - settings_.PS_zderL_shift(); + } else { + icorzshift_ = -1 - settings_.SS_zderL_shift(); + } + phi0shift_ = 3; + fact_ = 1; + if (layerdisk_ >= N_PSLAYER && layerdisk_ < N_LAYER) { + fact_ = (1 << (settings_.nzbitsstub(0) - settings_.nzbitsstub(5))); + icorrshift_ -= (10 - settings_.nrbitsstub(layerdisk_)); + icorzshift_ += (settings_.nzbitsstub(0) - settings_.nzbitsstub(5) + settings_.nrbitsstub(layerdisk_) - + settings_.nrbitsstub(0)); + phi0shift_ = 0; + } + + for (unsigned int iSeed = 0; iSeed < N_SEED; iSeed++) { + if (layerdisk_ < N_LAYER) { + phimatchcut_[iSeed] = + settings_.rphimatchcut(iSeed, layerdisk_) / (settings_.kphi1() * settings_.rmean(layerdisk_)); + zmatchcut_[iSeed] = settings_.zmatchcut(iSeed, layerdisk_) / settings_.kz(); + } else { + rphicutPS_[iSeed] = settings_.rphicutPS(iSeed, layerdisk_ - N_LAYER) / (settings_.kphi() * settings_.kr()); + rphicut2S_[iSeed] = settings_.rphicut2S(iSeed, layerdisk_ - N_LAYER) / (settings_.kphi() * settings_.kr()); + rcut2S_[iSeed] = settings_.rcut2S(iSeed, layerdisk_ - N_LAYER) / settings_.krprojshiftdisk(); + rcutPS_[iSeed] = settings_.rcutPS(iSeed, layerdisk_ - N_LAYER) / settings_.krprojshiftdisk(); + } + } + + if (iSector_ == 0 && layerdisk_ < N_LAYER && settings_.writeTable()) { + ofstream outphicut; + outphicut.open(getName() + "_phicut.tab"); + outphicut << "{" << endl; + for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { + if (seedindex != 0) + outphicut << "," << endl; + outphicut << phimatchcut_[seedindex]; + } + outphicut << endl << "};" << endl; + outphicut.close(); + + ofstream outzcut; + outzcut.open(getName() + "_zcut.tab"); + outzcut << "{" << endl; + for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { + if (seedindex != 0) + outzcut << "," << endl; + outzcut << zmatchcut_[seedindex]; + } + outzcut << endl << "};" << endl; + outzcut.close(); + } + + if (iSector_ == 0 && layerdisk_ >= N_LAYER && settings_.writeTable()) { + ofstream outphicut; + outphicut.open(getName() + "_PSphicut.tab"); + outphicut << "{" << endl; + for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { + if (seedindex != 0) + outphicut << "," << endl; + outphicut << rphicutPS_[seedindex]; + } + outphicut << endl << "};" << endl; + outphicut.close(); + + outphicut.open(getName() + "_2Sphicut.tab"); + outphicut << "{" << endl; + for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { + if (seedindex != 0) + outphicut << "," << endl; + outphicut << rphicut2S_[seedindex]; + } + outphicut << endl << "};" << endl; + outphicut.close(); + + ofstream outzcut; + outzcut.open(getName() + "_PSrcut.tab"); + outzcut << "{" << endl; + for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { + if (seedindex != 0) + outzcut << "," << endl; + outzcut << rcutPS_[seedindex]; + } + outzcut << endl << "};" << endl; + outzcut.close(); + + outzcut.open(getName() + "_2Srcut.tab"); + outzcut << "{" << endl; + for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { + if (seedindex != 0) + outzcut << "," << endl; + outzcut << rcut2S_[seedindex]; + } + outzcut << endl << "};" << endl; + outzcut.close(); + } + + for (unsigned int i = 0; i < N_DSS_MOD * 2; i++) { + ialphafactinner_[i] = (1 << settings_.alphashift()) * settings_.krprojshiftdisk() * settings_.half2SmoduleWidth() / + (1 << (settings_.nbitsalpha() - 1)) / (settings_.rDSSinner(i) * settings_.rDSSinner(i)) / + settings_.kphi(); + ialphafactouter_[i] = (1 << settings_.alphashift()) * settings_.krprojshiftdisk() * settings_.half2SmoduleWidth() / + (1 << (settings_.nbitsalpha() - 1)) / (settings_.rDSSouter(i) * settings_.rDSSouter(i)) / + settings_.kphi(); + } +} + +void MatchCalculator::addOutput(MemoryBase* memory, string output) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " + << output; + } + if (output.substr(0, 8) == "matchout") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + unsigned int iSeed = getISeed(memory->getName()); + fullMatches_[iSeed] = tmp; + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find output " << output; +} + +void MatchCalculator::addInput(MemoryBase* memory, string input) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " + << input; + } + if (input == "allstubin") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + allstubs_ = tmp; + return; + } + if (input == "allprojin") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + allprojs_ = tmp; + return; + } + if (input.substr(0, 5) == "match" && input.substr(input.size() - 2, 2) == "in") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + matches_.push_back(tmp); + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input " << input; +} + +void MatchCalculator::execute() { + unsigned int countall = 0; + unsigned int countsel = 0; + + Tracklet* oldTracklet = nullptr; + + std::vector, const Stub*> > mergedMatches = mergeMatches(matches_); + + for (unsigned int j = 0; j < mergedMatches.size(); j++) { + if (settings_.debugTracklet() && j == 0) { + edm::LogVerbatim("Tracklet") << getName() << " has " << mergedMatches.size() << " candidate matches"; + } + + countall++; + + const Stub* fpgastub = mergedMatches[j].second; + Tracklet* tracklet = mergedMatches[j].first.first; + const L1TStub* stub = fpgastub->l1tstub(); + + //check that the matches are orderd correctly + //allow equal here since we can have more than one cadidate match per tracklet projection + if (oldTracklet != nullptr) { + assert(oldTracklet->TCID() <= tracklet->TCID()); + } + oldTracklet = tracklet; + + if (layerdisk_ < N_LAYER) { + //Integer calculation + + int ir = fpgastub->r().value(); + int iphi = tracklet->fpgaphiproj(layerdisk_ + 1).value(); + int icorr = (ir * tracklet->fpgaphiprojder(layerdisk_ + 1).value()) >> icorrshift_; + iphi += icorr; + + int iz = tracklet->fpgazproj(layerdisk_ + 1).value(); + int izcor = (ir * tracklet->fpgazprojder(layerdisk_ + 1).value() + (1 << (icorzshift_ - 1))) >> icorzshift_; + iz += izcor; + + int ideltaz = fpgastub->z().value() - iz; + int ideltaphi = (fpgastub->phi().value() << phi0shift_) - (iphi << (settings_.phi0bitshift() - 1 + phi0shift_)); + + //Floating point calculations + + double phi = stub->phi() - phioffset_; + double r = stub->r(); + double z = stub->z(); + + if (settings_.useapprox()) { + double dphi = reco::reduceRange(phi - fpgastub->phiapprox(0.0, 0.0)); + assert(std::abs(dphi) < 0.001); + phi = fpgastub->phiapprox(0.0, 0.0); + z = fpgastub->zapprox(); + r = fpgastub->rapprox(); + } + + if (phi < 0) + phi += 2 * M_PI; + + double dr = r - tracklet->rproj(layerdisk_ + 1); + assert(std::abs(dr) < settings_.drmax()); + + double dphi = + reco::reduceRange(phi - (tracklet->phiproj(layerdisk_ + 1) + dr * tracklet->phiprojder(layerdisk_ + 1))); + + double dz = z - (tracklet->zproj(layerdisk_ + 1) + dr * tracklet->zprojder(layerdisk_ + 1)); + + double dphiapprox = reco::reduceRange( + phi - (tracklet->phiprojapprox(layerdisk_ + 1) + dr * tracklet->phiprojderapprox(layerdisk_ + 1))); + + double dzapprox = z - (tracklet->zprojapprox(layerdisk_ + 1) + dr * tracklet->zprojderapprox(layerdisk_ + 1)); + + int seedindex = tracklet->getISeed(); + + assert(phimatchcut_[seedindex] > 0); + assert(zmatchcut_[seedindex] > 0); + + if (settings_.bookHistos()) { + bool truthmatch = tracklet->stubtruthmatch(stub); + + HistBase* hists = globals_->histograms(); + hists->FillLayerResidual(layerdisk_ + 1, + seedindex, + dphiapprox * settings_.rmean(layerdisk_), + ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_), + ideltaz * fact_ * settings_.kz(), + dz, + truthmatch); + } + + if (std::abs(dphi) > 0.2 || std::abs(dphiapprox) > 0.2) { + edm::LogProblem("Tracklet") << "WARNING dphi and/or dphiapprox too large : " << dphi << " " << dphiapprox + << endl; + } + assert(std::abs(dphi) < 0.2); + assert(std::abs(dphiapprox) < 0.2); + + if (settings_.writeMonitorData("Residuals")) { + double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv()); + + globals_->ofstream("layerresiduals.txt") + << layerdisk_ + 1 << " " << seedindex << " " << pt << " " + << ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_) << " " + << dphiapprox * settings_.rmean(layerdisk_) << " " + << phimatchcut_[seedindex] * settings_.kphi1() * settings_.rmean(layerdisk_) << " " + << ideltaz * fact_ * settings_.kz() << " " << dz << " " << zmatchcut_[seedindex] * settings_.kz() << endl; + } + + bool imatch = (std::abs(ideltaphi) <= (int)phimatchcut_[seedindex]) && + (std::abs(ideltaz * fact_) <= (int)zmatchcut_[seedindex]); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " imatch = " << imatch << " ideltaphi cut " << ideltaphi << " " + << phimatchcut_[seedindex] << " ideltaz*fact cut " << ideltaz * fact_ << " " + << zmatchcut_[seedindex]; + } + + if (imatch) { + countsel++; + + tracklet->addMatch(layerdisk_ + 1, + ideltaphi, + ideltaz, + dphi, + dz, + dphiapprox, + dzapprox, + (phiregion_ << 7) + fpgastub->stubindex().value(), + stub->r(), + mergedMatches[j].second); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Accepted full match in layer " << getName() << " " << tracklet << " " + << iSector_; + } + + fullMatches_[seedindex]->addMatch(tracklet, mergedMatches[j].second); + } + } else { //disk matches + + //check that stubs and projections in same half of detector + assert(stub->z() * tracklet->t() > 0.0); + + int sign = (tracklet->t() > 0.0) ? 1 : -1; + int disk = sign * (layerdisk_ - (N_LAYER - 1)); + assert(disk != 0); + + //Perform integer calculations here + + int iz = fpgastub->z().value(); + int iphi = tracklet->fpgaphiprojdisk(disk).value(); + + //TODO - need to express interms of constants + int shifttmp = 6; + int iphicorr = (iz * tracklet->fpgaphiprojderdisk(disk).value()) >> shifttmp; + + iphi += iphicorr; + + int ir = tracklet->fpgarprojdisk(disk).value(); + + //TODO - need to express interms of constants + int shifttmp2 = 7; + int ircorr = (iz * tracklet->fpgarprojderdisk(disk).value()) >> shifttmp2; + + ir += ircorr; + + int ideltaphi = fpgastub->phi().value() * settings_.kphi() / settings_.kphi() - iphi; + + int irstub = fpgastub->r().value(); + int ialphafact = 0; + if (!stub->isPSmodule()) { + assert(irstub < (int)N_DSS_MOD * 2); + if (abs(disk) <= 2) { + ialphafact = ialphafactinner_[irstub]; + irstub = settings_.rDSSinner(irstub) / settings_.kr(); + } else { + ialphafact = ialphafactouter_[irstub]; + irstub = settings_.rDSSouter(irstub) / settings_.kr(); + } + } + + //TODO stub and projection r should not use different # bits... + int ideltar = (irstub >> 1) - ir; + + if (!stub->isPSmodule()) { + int ialphanew = fpgastub->alphanew().value(); + int iphialphacor = ((ideltar * ialphanew * ialphafact) >> settings_.alphashift()); + ideltaphi += iphialphacor; + } + + //Perform floating point calculations here + + double phi = stub->phi() - phioffset_; + double z = stub->z(); + double r = stub->r(); + + if (settings_.useapprox()) { + double dphi = reco::reduceRange(phi - fpgastub->phiapprox(0.0, 0.0)); + assert(std::abs(dphi) < 0.001); + phi = fpgastub->phiapprox(0.0, 0.0); + z = fpgastub->zapprox(); + r = fpgastub->rapprox(); + } + + if (phi < 0) + phi += 2 * M_PI; + + double dz = z - sign * settings_.zmean(layerdisk_ - N_LAYER); + + if (std::abs(dz) > settings_.dzmax()) { + throw cms::Exception("LogicError") + << __FILE__ << " " << __LINE__ << " " << name_ << "_" << iSector_ << " " << tracklet->getISeed() + << "\n stub " << stub->z() << " disk " << disk << " " << dz; + } + + double phiproj = tracklet->phiprojdisk(disk) + dz * tracklet->phiprojderdisk(disk); + + double rproj = tracklet->rprojdisk(disk) + dz * tracklet->rprojderdisk(disk); + + double deltar = r - rproj; + + double dr = stub->r() - rproj; + + double dphi = reco::reduceRange(phi - phiproj); + + double dphiapprox = + reco::reduceRange(phi - (tracklet->phiprojapproxdisk(disk) + dz * tracklet->phiprojderapproxdisk(disk))); + + double drapprox = stub->r() - (tracklet->rprojapproxdisk(disk) + dz * tracklet->rprojderapproxdisk(disk)); + + double drphi = dphi * stub->r(); + double drphiapprox = dphiapprox * stub->r(); + + if (!stub->isPSmodule()) { + double alphanorm = stub->alphanorm(); + dphi += dr * alphanorm * settings_.half2SmoduleWidth() / stub->r2(); + dphiapprox += drapprox * alphanorm * settings_.half2SmoduleWidth() / stub->r2(); + + drphi += dr * alphanorm * settings_.half2SmoduleWidth() / stub->r(); + drphiapprox += dr * alphanorm * settings_.half2SmoduleWidth() / stub->r(); + } + + int seedindex = tracklet->getISeed(); + + int idrphicut = rphicutPS_[seedindex]; + int idrcut = rcutPS_[seedindex]; + if (!stub->isPSmodule()) { + idrphicut = rphicut2S_[seedindex]; + idrcut = rcut2S_[seedindex]; + } + + double drphicut = idrphicut * settings_.kphi() * settings_.kr(); + double drcut = idrcut * settings_.krprojshiftdisk(); + + if (settings_.writeMonitorData("Residuals")) { + double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv()); + + globals_->ofstream("diskresiduals.txt") + << disk << " " << stub->isPSmodule() << " " << tracklet->layer() << " " << abs(tracklet->disk()) << " " + << pt << " " << ideltaphi * settings_.kphi() * stub->r() << " " << drphiapprox << " " << drphicut << " " + << ideltar * settings_.krprojshiftdisk() << " " << deltar << " " << drcut << " " << endl; + } + + bool match = (std::abs(drphi) < drphicut) && (std::abs(deltar) < drcut); + + bool imatch = (std::abs(ideltaphi * irstub) < idrphicut) && (std::abs(ideltar) < idrcut); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "imatch match disk: " << imatch << " " << match << " " << std::abs(ideltaphi) + << " " << drphicut / (settings_.kphi() * stub->r()) << " " << std::abs(ideltar) + << " " << drcut / settings_.krprojshiftdisk() << " r = " << stub->r(); + } + + if (imatch) { + countsel++; + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "MatchCalculator found match in disk " << getName(); + } + + if (std::abs(dphi) >= 0.25) { + edm::LogVerbatim("Tracklet") << "dphi " << dphi << " Seed / ISeed " << tracklet->getISeed(); + } + assert(std::abs(dphi) < 0.25); + assert(std::abs(dphiapprox) < 0.25); + + tracklet->addMatchDisk(disk, + ideltaphi, + ideltar, + drphi / stub->r(), + dr, + drphiapprox / stub->r(), + drapprox, + stub->alpha(settings_.stripPitch(stub->isPSmodule())), + (phiregion_ << 7) + fpgastub->stubindex().value(), + stub->z(), + fpgastub); + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Accepted full match in disk " << getName() << " " << tracklet << " " + << iSector_; + } + + fullMatches_[seedindex]->addMatch(tracklet, mergedMatches[j].second); + } + } + if (countall >= settings_.maxStep("MC")) + break; + } + + if (settings_.writeMonitorData("MC")) { + globals_->ofstream("matchcalculator.txt") << getName() << " " << countall << " " << countsel << endl; + } +} + +std::vector, const Stub*> > MatchCalculator::mergeMatches( + vector& candmatch) { + std::vector, const Stub*> > tmp; + + std::vector indexArray; + indexArray.reserve(candmatch.size()); + for (unsigned int i = 0; i < candmatch.size(); i++) { + indexArray.push_back(0); + } + + int bestIndex = -1; + do { + int bestSector = 100; + int bestTCID = (1 << 16); + bestIndex = -1; + for (unsigned int i = 0; i < candmatch.size(); i++) { + if (indexArray[i] >= candmatch[i]->nMatches()) { + // skip as we were at the end + continue; + } + int TCID = candmatch[i]->getMatch(indexArray[i]).first.first->TCID(); + int dSector = 0; + if (dSector > 2) + dSector -= N_SECTOR; + if (dSector < -2) + dSector += N_SECTOR; + assert(abs(dSector) < 2); + if (dSector == -1) + dSector = 2; + if (dSector < bestSector) { + bestSector = dSector; + bestTCID = TCID; + bestIndex = i; + } + if (dSector == bestSector) { + if (TCID < bestTCID) { + bestTCID = TCID; + bestIndex = i; + } + } + } + if (bestIndex != -1) { + tmp.push_back(candmatch[bestIndex]->getMatch(indexArray[bestIndex])); + indexArray[bestIndex]++; + } + } while (bestIndex != -1); + + if (layerdisk_ < N_LAYER) { + int lastTCID = -1; + bool error = false; + + //Allow equal TCIDs since we can have multiple candidate matches + for (unsigned int i = 1; i < tmp.size(); i++) { + if (lastTCID > tmp[i].first.first->TCID()) { + edm::LogProblem("Tracklet") << "Wrong TCID ordering for projections in " << getName() << " last " << lastTCID + << " " << tmp[i].first.first->TCID(); + error = true; + } else { + lastTCID = tmp[i].first.first->TCID(); + } + } + + if (error) { + for (unsigned int i = 1; i < tmp.size(); i++) { + edm::LogProblem("Tracklet") << "Wrong order for in " << getName() << " " << i << " " << tmp[i].first.first + << " " << tmp[i].first.first->TCID(); + } + } + } + + for (unsigned int i = 0; i < tmp.size(); i++) { + if (i > 0) { + //This allows for equal TCIDs. This means that we can e.g. have a track seeded + //in L1L2 that projects to both L3 and D4. The algorithm will pick up the first hit and + //drop the second + + assert(tmp[i - 1].first.first->TCID() <= tmp[i].first.first->TCID()); + } + } + + return tmp; +} diff --git a/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc b/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc new file mode 100644 index 0000000000000..417e43c24f8f7 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc @@ -0,0 +1,320 @@ +#include "L1Trigger/TrackFindingTracklet/interface/MatchEngine.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +using namespace std; +using namespace trklet; + +MatchEngine::MatchEngine(string name, Settings const& settings, Globals* global, unsigned int iSector) + : ProcessBase(name, settings, global, iSector) { + layer_ = 0; + disk_ = 0; + string subname = name.substr(3, 2); + if (subname.substr(0, 1) == "L") + layer_ = stoi(subname.substr(1, 1)); + else if (subname.substr(0, 1) == "D") + disk_ = stoi(subname.substr(1, 1)); + else + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " " << name << " subname = " << subname << " " + << layer_ << " " << disk_; + + if (layer_ > 0) { + unsigned int nbits = 3; + if (layer_ >= 4) + nbits = 4; + + for (unsigned int irinv = 0; irinv < 32; irinv++) { + double rinv = (irinv - 15.5) * (1 << (settings_.nbitsrinv() - 5)) * settings_.krinvpars(); + + double stripPitch = + (settings_.rmean(layer_ - 1) < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); + double projbend = bend(settings_.rmean(layer_ - 1), rinv, stripPitch); + for (unsigned int ibend = 0; ibend < (unsigned int)(1 << nbits); ibend++) { + double stubbend = benddecode(ibend, layer_ <= 3); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(layer_ - 1); + table_.push_back(pass); + } + } + + if (settings_.writeTable()) { + ofstream out; + char layer = '0' + layer_; + string fname = "METable_L"; + fname += layer; + fname += ".tab"; + out.open(fname.c_str()); + out << "{" << endl; + for (unsigned int i = 0; i < table_.size(); i++) { + if (i != 0) { + out << "," << endl; + } + out << table_[i]; + } + out << "};" << endl; + out.close(); + } + } + + if (disk_ > 0) { + for (unsigned int iprojbend = 0; iprojbend < 32; iprojbend++) { + double projbend = 0.5 * (iprojbend - 15.0); + for (unsigned int ibend = 0; ibend < 8; ibend++) { + double stubbend = benddecode(ibend, true); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(disk_ + 5); + tablePS_.push_back(pass); + } + for (unsigned int ibend = 0; ibend < 16; ibend++) { + double stubbend = benddecode(ibend, false); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(disk_ + 5); + table2S_.push_back(pass); + } + } + } +} + +void MatchEngine::addOutput(MemoryBase* memory, string output) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " + << output; + } + if (output == "matchout") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + candmatches_ = tmp; + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find output: " << output; +} + +void MatchEngine::addInput(MemoryBase* memory, string input) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " + << input; + } + if (input == "vmstubin") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + vmstubs_ = tmp; + return; + } + if (input == "vmprojin") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + vmprojs_ = tmp; + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input: " << input; +} + +void MatchEngine::execute() { + bool barrel = layer_ > 0; + + unsigned int countall = 0; + unsigned int countpass = 0; + + constexpr unsigned int kNBitsBuffer = 3; + + int writeindex = 0; + int readindex = 0; + std::pair projbuffer[1 << kNBitsBuffer]; //iproj zbin + + //The next projection to read, the number of projections and flag if we have more projections to read + int iproj = 0; + int nproj = vmprojs_->nTracklets(); + bool moreproj = iproj < nproj; + + //Projection that is read from the buffer and compared to stubs + int rzbin = 0; + int projfinerz = 0; + int projfinerzadj = 0; + + int projindex = 0; + int projrinv = 0; + bool isPSseed = false; + + //Number of stubs for current zbin and the stub being processed on this clock + int nstubs = 0; + int istub = 0; + + //Main processing loops starts here + for (unsigned int istep = 0; istep < settings_.maxStep("ME"); istep++) { + countall++; + + int writeindexplus = (writeindex + 1) % (1 << kNBitsBuffer); + int writeindexplusplus = (writeindex + 2) % (1 << kNBitsBuffer); + + //Determine if buffer is full - or near full as a projection + //can point to two z bins we might fill two slots in the buffer + bool bufferfull = (writeindexplus == readindex) || (writeindexplusplus == readindex); + + //Determin if buffer is empty + bool buffernotempty = (writeindex != readindex); + + //If we have more projections and the buffer is not full we read + //next projection and put in buffer if there are stubs in the + //memory the projection points to + + if ((!moreproj) && (!buffernotempty)) + break; + + if (moreproj && (!bufferfull)) { + Tracklet* proj = vmprojs_->getTracklet(iproj); + + int iprojtmp = iproj; + + iproj++; + moreproj = iproj < nproj; + + unsigned int rzfirst = barrel ? proj->zbin1projvm(layer_) : proj->rbin1projvm(disk_); + unsigned int rzlast = rzfirst; + bool second = (barrel ? proj->zbin2projvm(layer_) : proj->rbin2projvm(disk_)) == 1; + if (second) + rzlast += 1; + + //Check if there are stubs in the memory + int nstubfirst = vmstubs_->nStubsBin(rzfirst); + int nstublast = vmstubs_->nStubsBin(rzlast); + bool savefirst = nstubfirst != 0; + bool savelast = second && (nstublast != 0); + + int writeindextmp = writeindex; + int writeindextmpplus = (writeindex + 1) % (1 << kNBitsBuffer); + + if (savefirst && savelast) { + writeindex = writeindexplusplus; + } else if (savefirst || savelast) { + writeindex = writeindexplus; + } + + if (savefirst) { //TODO for HLS (make code logic simpler) + std::pair tmp(iprojtmp, rzfirst); + projbuffer[writeindextmp] = tmp; + } + if (savelast) { + std::pair tmp(iprojtmp, rzlast + 100); //TODO for HLS (fix flagging that this is second bin) + if (savefirst) { + projbuffer[writeindextmpplus] = tmp; + } else { + projbuffer[writeindextmp] = tmp; + } + } + } + + //If the buffer is not empty we have a projection that we need to process. + + if (buffernotempty) { + int istubtmp = istub; + + //New projection + if (istub == 0) { + projindex = projbuffer[readindex].first; + rzbin = projbuffer[readindex].second; + bool second = false; + if (rzbin >= 100) { + rzbin -= 100; + second = true; + } + + Tracklet* proj = vmprojs_->getTracklet(projindex); + + nstubs = vmstubs_->nStubsBin(rzbin); + + projfinerz = barrel ? proj->finezvm(layer_) : proj->finervm(disk_); + + projrinv = + barrel + ? (16 + (((-2) * proj->fpgaphiprojder(layer_).value()) >> (proj->fpgaphiprojder(layer_).nbits() - 4))) + : proj->getBendIndex(disk_).value(); + assert(projrinv >= 0); + if (settings_.extended() && projrinv == 32) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Extended tracking, projrinv:" << projrinv; + } + projrinv = 31; + } + assert(projrinv < 32); + + isPSseed = proj->PSseed() == 1; + + //Calculate fine z position + if (second) { + projfinerzadj = projfinerz - 8; + } else { + projfinerzadj = projfinerz; + } + if (nstubs == 1) { + istub = 0; + readindex = (readindex + 1) % (1 << kNBitsBuffer); + } else { + istub++; + } + } else { + //Check if last stub, if so, go to next buffer entry + if (istub + 1 >= nstubs) { + istub = 0; + readindex = (readindex + 1) % (1 << kNBitsBuffer); + } else { + istub++; + } + } + + //Read vmstub memory and extract data fields + const VMStubME& vmstub = vmstubs_->getVMStubMEBin(rzbin, istubtmp); + + bool isPSmodule = vmstub.isPSmodule(); + + int stubfinerz = vmstub.finerz().value(); + + int nbits = isPSmodule ? 3 : 4; + + //TODO - should use finephi information to reduce combinatorics + + unsigned int index = (projrinv << nbits) + vmstub.bend().value(); + + //Check if stub z position consistent + int idrz = stubfinerz - projfinerzadj; + bool pass; + + if (barrel) { + if (isPSseed) { + pass = idrz >= -2 && idrz <= 2; + } else { + pass = idrz >= -5 && idrz <= 5; + } + } else { + if (isPSmodule) { + pass = idrz >= -1 && idrz <= 1; + } else { + pass = idrz >= -5 && idrz <= 5; + } + } + + //Check if stub bend and proj rinv consistent + if (pass) { + if (barrel ? table_[index] : (isPSmodule ? tablePS_[index] : table2S_[index])) { + Tracklet* proj = vmprojs_->getTracklet(projindex); + std::pair tmp(proj, vmprojs_->getAllProjIndex(projindex)); + if (settings_.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << proj->getISeed() << endl; + fout.close(); + } + candmatches_->addMatch(tmp, vmstub.stub()); + countpass++; + } + } + } + } + + if (settings_.writeMonitorData("ME")) { + globals_->ofstream("matchengine.txt") << getName() << " " << countall << " " << countpass << endl; + } +} diff --git a/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc b/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc new file mode 100644 index 0000000000000..51f1042aa4d89 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc @@ -0,0 +1,82 @@ +#include "L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h" + +using namespace std; +using namespace trklet; + +MatchEngineUnit::MatchEngineUnit(bool barrel, vector table, vector tablePS, vector table2S) + : candmatches_(5) { + idle_ = true; + barrel_ = barrel; + table_ = table; + tablePS_ = tablePS; + table2S_ = table2S; + slot_ = 1; //This makes it idle until initialized +} + +void MatchEngineUnit::init(VMStubsMEMemory* vmstubsmemory, + unsigned int slot, + int projrinv, + int projfinerz, + int projfinephi, + bool isPSseed, + Tracklet* proj) { + vmstubsmemory_ = vmstubsmemory; + idle_ = false; + slot_ = slot; + istub_ = 0; + projrinv_ = projrinv; + projfinerz_ = projfinerz; + projfinephi_ = projfinephi; + isPSseed_ = isPSseed; + proj_ = proj; +} + +void MatchEngineUnit::step() { + if (idle() || candmatches_.almostfull()) + return; + + const VMStubME& vmstub = vmstubsmemory_->getVMStubMEBin(slot_, istub_); + + istub_++; + if (istub_ >= vmstubsmemory_->nStubsBin(slot_)) + idle_ = true; + + bool isPSmodule = vmstub.isPSmodule(); + int stubfinerz = vmstub.finerz().value(); + int stubfinephi = vmstub.finephi().value(); + + int deltaphi = stubfinephi - projfinephi_; + + bool dphicut = (abs(deltaphi) < 3) || (abs(deltaphi) > 5); //TODO - need better implementations + + if (!barrel_) + dphicut = true; + + int nbits = isPSmodule ? 3 : 4; + + unsigned int index = (projrinv_ << nbits) + vmstub.bend().value(); + + //Check if stub z position consistent + int idrz = stubfinerz - projfinerz_; + bool pass; + + if (barrel_) { + if (isPSseed_) { + pass = idrz >= -2 && idrz <= 2; + } else { + pass = idrz >= -5 && idrz <= 5; + } + } else { + if (isPSmodule) { + pass = idrz >= -1 && idrz <= 1; + } else { + pass = idrz >= -5 && idrz <= 5; + } + } + + //Check if stub bend and proj rinv consistent + if ((pass && dphicut) && (barrel_ ? table_[index] : (isPSmodule ? tablePS_[index] : table2S_[index]))) { + std::pair tmp(proj_, vmstub.stub()); + candmatches_.store(tmp); + } +} diff --git a/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc b/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc new file mode 100644 index 0000000000000..e09fb2bc7a01b --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc @@ -0,0 +1,656 @@ +#include "L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" +#include "L1Trigger/TrackFindingTracklet/interface/ProjectionRouterBendTable.h" +#include "L1Trigger/TrackFindingTracklet/interface/HistBase.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" +#include "DataFormats/Math/interface/deltaPhi.h" + +using namespace std; +using namespace trklet; + +MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* global, unsigned int iSector) + : ProcessBase(name, settings, global, iSector), fullmatches_(12), inputProjBuffer_(3) { + phioffset_ = phimin_; + + phiregion_ = name[8] - 'A'; + + initLayerDisk(3, layer_, disk_); + + //TODO should sort out constants here + icorrshift_ = 7; + + if (layer_ <= 3) { + icorzshift_ = -1 - settings_.PS_zderL_shift(); + } else { + icorzshift_ = -1 - settings_.SS_zderL_shift(); + } + phi0shift_ = 3; + fact_ = 1; + if (layer_ >= 4) { + fact_ = (1 << (settings_.nzbitsstub(0) - settings_.nzbitsstub(5))); + icorrshift_ -= (10 - settings_.nrbitsstub(layer_ - 1)); + icorzshift_ += (settings_.nzbitsstub(0) - settings_.nzbitsstub(5) + settings_.nrbitsstub(layer_ - 1) - + settings_.nrbitsstub(0)); + phi0shift_ = 0; + } + + nrbits_ = 5; + nphiderbits_ = 6; + + //to adjust globaly the phi and rz matching cuts + phifact_ = 1.0; + rzfact_ = 1.0; + + for (unsigned int iSeed = 0; iSeed < 12; iSeed++) { + if (layer_ > 0) { + phimatchcut_[iSeed] = + settings_.rphimatchcut(iSeed, layer_ - 1) / (settings_.kphi1() * settings_.rmean(layer_ - 1)); + zmatchcut_[iSeed] = settings_.zmatchcut(iSeed, layer_ - 1) / settings_.kz(); + } + if (disk_ != 0) { + rphicutPS_[iSeed] = settings_.rphicutPS(iSeed, abs(disk_) - 1) / (settings_.kphi() * settings_.kr()); + rphicut2S_[iSeed] = settings_.rphicut2S(iSeed, abs(disk_) - 1) / (settings_.kphi() * settings_.kr()); + rcut2S_[iSeed] = settings_.rcut2S(iSeed, abs(disk_) - 1) / settings_.krprojshiftdisk(); + rcutPS_[iSeed] = settings_.rcutPS(iSeed, abs(disk_) - 1) / settings_.krprojshiftdisk(); + } + } + + if (iSector_ == 0 && layer_ > 0 && settings_.writeTable()) { + ofstream outphicut; + outphicut.open(getName() + "_phicut.tab"); + outphicut << "{" << endl; + for (unsigned int seedindex = 0; seedindex < 12; seedindex++) { + if (seedindex != 0) + outphicut << "," << endl; + outphicut << phimatchcut_[seedindex]; + } + outphicut << endl << "};" << endl; + outphicut.close(); + + ofstream outzcut; + outzcut.open(getName() + "_zcut.tab"); + outzcut << "{" << endl; + for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { + if (seedindex != 0) + outzcut << "," << endl; + outzcut << zmatchcut_[seedindex]; + } + outzcut << endl << "};" << endl; + outzcut.close(); + } + + if (layer_ > 0) { + unsigned int nbits = 3; + if (layer_ >= 4) + nbits = 4; + + for (unsigned int irinv = 0; irinv < 32; irinv++) { + double rinv = (irinv - 15.5) * (1 << (settings_.nbitsrinv() - 5)) * settings_.krinvpars(); + double stripPitch = + (settings_.rmean(layer_ - 1) < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); + double projbend = bend(settings_.rmean(layer_ - 1), rinv, stripPitch); + for (unsigned int ibend = 0; ibend < (unsigned int)(1 << nbits); ibend++) { + double stubbend = benddecode(ibend, layer_ <= (int)N_PSLAYER); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(layer_ - 1); + table_.push_back(pass); + } + } + + if (settings_.writeTable()) { + ofstream out; + char layer = '0' + layer_; + string fname = "METable_L"; + fname += layer; + fname += ".tab"; + out.open(fname.c_str()); + out << "{" << endl; + for (unsigned int i = 0; i < table_.size(); i++) { + if (i != 0) { + out << "," << endl; + } + out << table_[i]; + } + out << "};" << endl; + out.close(); + } + } + + if (disk_ > 0) { + for (unsigned int iprojbend = 0; iprojbend < 32; iprojbend++) { + double projbend = 0.5 * (iprojbend - 15.0); + for (unsigned int ibend = 0; ibend < 8; ibend++) { + double stubbend = benddecode(ibend, true); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(disk_ + 5); + tablePS_.push_back(pass); + } + for (unsigned int ibend = 0; ibend < 16; ibend++) { + double stubbend = benddecode(ibend, false); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(disk_ + 5); + table2S_.push_back(pass); + } + } + } + + for (unsigned int i = 0; i < N_DSS_MOD * 2; i++) { + ialphafactinner_[i] = (1 << settings_.alphashift()) * settings_.krprojshiftdisk() * settings_.half2SmoduleWidth() / + (1 << (settings_.nbitsalpha() - 1)) / (settings_.rDSSinner(i) * settings_.rDSSinner(i)) / + settings_.kphi(); + ialphafactouter_[i] = (1 << settings_.alphashift()) * settings_.krprojshiftdisk() * settings_.half2SmoduleWidth() / + (1 << (settings_.nbitsalpha() - 1)) / (settings_.rDSSouter(i) * settings_.rDSSouter(i)) / + settings_.kphi(); + } + + barrel_ = layer_ > 0; + + nvm_ = barrel_ ? settings_.nvmme(layer_ - 1) * settings_.nallstubs(layer_ - 1) + : settings_.nvmme(disk_ + 5) * settings_.nallstubs(disk_ + 5); + nvmbins_ = barrel_ ? settings_.nvmme(layer_ - 1) : settings_.nvmme(disk_ + 5); + + if (nvm_ == 32) + nvmbits_ = 5; + if (nvm_ == 16) + nvmbits_ = 4; + assert(nvmbits_ != -1); + + nMatchEngines_ = 4; + for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { + MatchEngineUnit tmpME(barrel_, table_, tablePS_, table2S_); + matchengines_.push_back(tmpME); + } +} + +void MatchProcessor::addOutput(MemoryBase* memory, string output) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " + << output; + } + if (output.find("matchout") != std::string::npos) { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + unsigned int iSeed = getISeed(tmp->getName()); + assert(iSeed < fullmatches_.size()); + assert(fullmatches_[iSeed] == nullptr); + fullmatches_[iSeed] = tmp; + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find output: " << output; +} + +void MatchProcessor::addInput(MemoryBase* memory, string input) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " + << input; + } + if (input == "allstubin") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + allstubs_ = tmp; + return; + } + if (input == "vmstubin") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + vmstubs_.push_back(tmp); //to allow more than one stub in? vmstubs_=tmp; + return; + } + if (input == "projin") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + inputprojs_.push_back(tmp); + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input: " << input; +} + +void MatchProcessor::execute() { + if (globals_->projectionRouterBendTable() == nullptr) { // move to constructor?! + auto* bendTablePtr = new ProjectionRouterBendTable(); + bendTablePtr->init(settings_, globals_, nrbits_, nphiderbits_); + globals_->projectionRouterBendTable() = bendTablePtr; + } + + /* + The code is organized in three 'steps' corresponding to the PR, ME, and MC functions. The output from + the PR step is buffered in a 'circular' buffer, and similarly the ME output is put in a circular buffer. + + The implementation is done in steps, emulating what can be done in firmware. One each step we do: + + 1) A projection is read and if there is space it is insert into the inputProjBuffer_ + + 2) Process next match in the ME - if there is an idle ME the next projection is inserted + + 3) Readout match from ME and send to match calculator + + */ + + Tracklet* oldTracklet = nullptr; + + unsigned int countall = 0; + unsigned int countsel = 0; + + unsigned int iprojmem = 0; + unsigned int iproj = 0; + + inputProjBuffer_.reset(); + + for (unsigned int istep = 0; istep < settings_.maxStep("MP"); istep++) { + //Step 1 + //First step here checks if we have more input projections to put into + //the input puffer for projections + if (iprojmem < inputprojs_.size()) { + TrackletProjectionsMemory* projMem = inputprojs_[iprojmem]; + if (projMem->nTracklets() == 0) { + iprojmem++; + } else if (iproj < projMem->nTracklets()) { + if (!inputProjBuffer_.almostfull()) { + Tracklet* proj = projMem->getTracklet(iproj); + + FPGAWord fpgaphi = barrel_ ? proj->fpgaphiproj(layer_) : proj->fpgaphiprojdisk(disk_); + + int iphi = (fpgaphi.value() >> (fpgaphi.nbits() - nvmbits_)) & (nvmbins_ - 1); + + int projrinv = -1; + if (barrel_) { + projrinv = 16 + (proj->fpgarinv().value() >> (proj->fpgarinv().nbits() - 5)); + } else { + //The next lines looks up the predicted bend based on: + // 1 - r projections + // 2 - phi derivative + // 3 - the sign - i.e. if track is forward or backward + int rindex = (proj->fpgarprojdisk(disk_).value() >> (proj->fpgarprojdisk(disk_).nbits() - nrbits_)) & + ((1 << nrbits_) - 1); + + int phiderindex = + (proj->fpgaphiprojderdisk(disk_).value() >> (proj->fpgaphiprojderdisk(disk_).nbits() - nphiderbits_)) & + ((1 << nphiderbits_) - 1); + + int signindex = (proj->fpgarprojderdisk(disk_).value() < 0); + + int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex; + + projrinv = globals_->projectionRouterBendTable()->bendLoookup(abs(disk_) - 1, bendindex); + + proj->setBendIndex(projrinv, disk_); + } + assert(projrinv >= 0); + + unsigned int slot = barrel_ ? proj->zbin1projvm(layer_) : proj->rbin1projvm(disk_); + bool second = (barrel_ ? proj->zbin2projvm(layer_) : proj->rbin2projvm(disk_)) == 1; + + unsigned int projfinephi = fpgaphi.value() >> (fpgaphi.nbits() - (nvmbits_ + 3)) & 7; + int projfinerz = barrel_ ? proj->finezvm(layer_) : proj->finervm(disk_); + + bool isPSseed = proj->PSseed() == 1; + + VMStubsMEMemory* stubmem = vmstubs_[iphi]; + if (stubmem->nStubsBin(slot) != 0) { + ProjectionTemp tmpProj(proj, slot, projrinv, projfinerz, projfinephi, iphi, isPSseed); + inputProjBuffer_.store(tmpProj); + } + if (second && (stubmem->nStubsBin(slot + 1) != 0)) { + ProjectionTemp tmpProj(proj, slot + 1, projrinv, projfinerz - 8, projfinephi, iphi, isPSseed); + inputProjBuffer_.store(tmpProj); + } + iproj++; + if (iproj == projMem->nTracklets()) { + iproj = 0; + iprojmem++; + } + } + } + } + + //Step 2 + //Check if we have ME that can process projection + + bool addedProjection = false; + for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { + matchengines_[iME].step(); + //if match engine empty and we have queued projections add to match engine + if ((!addedProjection) && matchengines_[iME].idle() && (!inputProjBuffer_.empty())) { + ProjectionTemp tmpProj = inputProjBuffer_.read(); + VMStubsMEMemory* stubmem = vmstubs_[tmpProj.iphi()]; + + matchengines_[iME].init(stubmem, + tmpProj.slot(), + tmpProj.projrinv(), + tmpProj.projfinerz(), + tmpProj.projfinephi(), + tmpProj.isPSseed(), + tmpProj.proj()); + addedProjection = true; + } + } + + //Step 3 + //Check if we have candidate match to process + + unsigned int iMEbest = nMatchEngines_; + int bestTCID = -1; + bool bestInPipeline = false; + for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { + bool empty = matchengines_[iME].empty(); + if (empty && matchengines_[iME].idle()) + continue; + int currentTCID = empty ? matchengines_[iME].currentProj()->TCID() : matchengines_[iME].peek().first->TCID(); + if ((iMEbest == nMatchEngines_) || (currentTCID < bestTCID)) { + iMEbest = iME; + bestTCID = currentTCID; + bestInPipeline = empty; + } + } + + if (iMEbest != nMatchEngines_ && (!bestInPipeline)) { + std::pair candmatch = matchengines_[iMEbest].read(); + + const Stub* fpgastub = candmatch.second; + Tracklet* tracklet = candmatch.first; + + if (oldTracklet != nullptr) { + //allow equal here since we can have more than one cadidate match per tracklet projection + assert(oldTracklet->TCID() <= tracklet->TCID()); + } + oldTracklet = tracklet; + + bool match = matchCalculator(tracklet, fpgastub); + + countall++; + if (match) + countsel++; + ; + } + } + + if (settings_.writeMonitorData("MC")) { + globals_->ofstream("matchcalculator.txt") << getName() << " " << countall << " " << countsel << endl; + } +} + +bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { + const L1TStub* stub = fpgastub->l1tstub(); + + if (layer_ != 0) { + int ir = fpgastub->r().value(); + int iphi = tracklet->fpgaphiproj(layer_).value(); + int icorr = (ir * tracklet->fpgaphiprojder(layer_).value()) >> icorrshift_; + iphi += icorr; + + int iz = tracklet->fpgazproj(layer_).value(); + int izcor = (ir * tracklet->fpgazprojder(layer_).value() + (1 << (icorzshift_ - 1))) >> icorzshift_; + iz += izcor; + + int ideltaz = fpgastub->z().value() - iz; + int ideltaphi = (fpgastub->phi().value() << phi0shift_) - (iphi << (settings_.phi0bitshift() - 1 + phi0shift_)); + + //Floating point calculations + + double phi = stub->phi(); + double r = stub->r(); + double z = stub->z(); + + if (settings_.useapprox()) { + double dphi = reco::reduceRange(phi - fpgastub->phiapprox(phimin_, phimax_)); + assert(std::abs(dphi) < 0.001); + phi = fpgastub->phiapprox(phimin_, phimax_); + z = fpgastub->zapprox(); + r = fpgastub->rapprox(); + } + + if (phi < 0) + phi += 2 * M_PI; + phi -= phioffset_; + + double dr = r - tracklet->rproj(layer_); + assert(std::abs(dr) < settings_.drmax()); + + double dphi = reco::reduceRange(phi - (tracklet->phiproj(layer_) + dr * tracklet->phiprojder(layer_))); + + double dz = z - (tracklet->zproj(layer_) + dr * tracklet->zprojder(layer_)); + + double dphiapprox = + reco::reduceRange(phi - (tracklet->phiprojapprox(layer_) + dr * tracklet->phiprojderapprox(layer_))); + + double dzapprox = z - (tracklet->zprojapprox(layer_) + dr * tracklet->zprojderapprox(layer_)); + + int seedindex = tracklet->getISeed(); + + assert(phimatchcut_[seedindex] > 0); + assert(zmatchcut_[seedindex] > 0); + + if (settings_.bookHistos()) { + bool truthmatch = tracklet->stubtruthmatch(stub); + + HistBase* hists = globals_->histograms(); + hists->FillLayerResidual(layer_, + seedindex, + dphiapprox * settings_.rmean(layer_ - 1), + ideltaphi * settings_.kphi1() * settings_.rmean(layer_ - 1), + ideltaz * fact_ * settings_.kz(), + dz, + truthmatch); + } + + if (settings_.writeMonitorData("Residuals")) { + double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv()); + + globals_->ofstream("layerresiduals.txt") + << layer_ << " " << seedindex << " " << pt << " " + << ideltaphi * settings_.kphi1() * settings_.rmean(layer_ - 1) << " " + << dphiapprox * settings_.rmean(layer_ - 1) << " " + << phimatchcut_[seedindex] * settings_.kphi1() * settings_.rmean(layer_ - 1) << " " + << ideltaz * fact_ * settings_.kz() << " " << dz << " " << zmatchcut_[seedindex] * settings_.kz() << endl; + } + + bool imatch = (std::abs(ideltaphi) <= phifact_ * phimatchcut_[seedindex]) && + (std::abs(ideltaz * fact_) <= rzfact_ * zmatchcut_[seedindex]); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " imatch = " << imatch << " ideltaphi cut " << ideltaphi << " " + << phimatchcut_[seedindex] << " ideltaz*fact cut " << ideltaz * fact_ << " " + << zmatchcut_[seedindex]; + } + + if (std::abs(dphi) > 0.2 || std::abs(dphiapprox) > 0.2) { + edm::LogPrint("Tracklet") << "WARNING dphi and/or dphiapprox too large : " << dphi << " " << dphiapprox; + } + + assert(std::abs(dphi) < 0.2); + assert(std::abs(dphiapprox) < 0.2); + + if (imatch) { + tracklet->addMatch(layer_, + ideltaphi, + ideltaz, + dphi, + dz, + dphiapprox, + dzapprox, + (phiregion_ << 7) + fpgastub->stubindex().value(), + stub->r(), + fpgastub); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Accepted full match in layer " << getName() << " " << tracklet << " " + << iSector_; + } + + int iSeed = tracklet->getISeed(); + assert(fullmatches_[iSeed] != nullptr); + fullmatches_[iSeed]->addMatch(tracklet, fpgastub); + + return true; + } else { + return false; + } + } else { //disk matches + + //check that stubs and projections in same half of detector + assert(stub->z() * tracklet->t() > 0.0); + + int sign = (tracklet->t() > 0.0) ? 1 : -1; + int disk = sign * disk_; + assert(disk != 0); + + //Perform integer calculations here + + int iz = fpgastub->z().value(); + int iphi = tracklet->fpgaphiprojdisk(disk).value(); + + int shifttmp = 6; //TODO - express in terms of constants + assert(shifttmp >= 0); + int iphicorr = (iz * tracklet->fpgaphiprojderdisk(disk).value()) >> shifttmp; + + iphi += iphicorr; + + int ir = tracklet->fpgarprojdisk(disk).value(); + + int shifttmp2 = 7; //TODO - express in terms of constants + assert(shifttmp2 >= 0); + int ircorr = (iz * tracklet->fpgarprojderdisk(disk).value()) >> shifttmp2; + + ir += ircorr; + + int ideltaphi = fpgastub->phi().value() * settings_.kphi() / settings_.kphi() - iphi; + + int irstub = fpgastub->r().value(); + int ialphafact = 0; + if (!stub->isPSmodule()) { + assert(irstub < (int)N_DSS_MOD * 2); + if (disk_ <= 2) { + ialphafact = ialphafactinner_[irstub]; + irstub = settings_.rDSSinner(irstub) / settings_.kr(); + } else { + ialphafact = ialphafactouter_[irstub]; + irstub = settings_.rDSSouter(irstub) / settings_.kr(); + } + } + + int ideltar = (irstub * settings_.kr()) / settings_.krprojshiftdisk() - ir; + + if (!stub->isPSmodule()) { + int ialphanew = fpgastub->alphanew().value(); + int iphialphacor = ((ideltar * ialphanew * ialphafact) >> settings_.alphashift()); + ideltaphi += iphialphacor; + } + + //Perform floating point calculations here + + double phi = stub->phi(); + double z = stub->z(); + double r = stub->r(); + + if (settings_.useapprox()) { + double dphi = reco::reduceRange(phi - fpgastub->phiapprox(phimin_, phimax_)); + assert(std::abs(dphi) < 0.001); + phi = fpgastub->phiapprox(phimin_, phimax_); + z = fpgastub->zapprox(); + r = fpgastub->rapprox(); + } + + if (phi < 0) + phi += 2 * M_PI; + phi -= phioffset_; + + double dz = z - sign * settings_.zmean(disk_ - 1); + + if (std::abs(dz) > settings_.dzmax()) { + edm::LogProblem("Tracklet") << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " + << tracklet->getISeed(); + edm::LogProblem("Tracklet") << "stub " << stub->z() << " disk " << disk << " " << dz; + assert(std::abs(dz) < settings_.dzmax()); + } + + double phiproj = tracklet->phiprojdisk(disk) + dz * tracklet->phiprojderdisk(disk); + double rproj = tracklet->rprojdisk(disk) + dz * tracklet->rprojderdisk(disk); + double deltar = r - rproj; + + double dr = stub->r() - rproj; + double drapprox = stub->r() - (tracklet->rprojapproxdisk(disk) + dz * tracklet->rprojderapproxdisk(disk)); + + double dphi = reco::reduceRange(phi - phiproj); + double dphiapprox = + reco::reduceRange(phi - (tracklet->phiprojapproxdisk(disk) + dz * tracklet->phiprojderapproxdisk(disk))); + + double drphi = dphi * stub->r(); + double drphiapprox = dphiapprox * stub->r(); + + if (!stub->isPSmodule()) { + double alphanorm = stub->alphanorm(); + dphi += dr * alphanorm * settings_.half2SmoduleWidth() / stub->r2(); + ; + dphiapprox += drapprox * alphanorm * settings_.half2SmoduleWidth() / stub->r2(); + + drphi += dr * alphanorm * settings_.half2SmoduleWidth() / stub->r(); + drphiapprox += dr * alphanorm * settings_.half2SmoduleWidth() / stub->r(); + } + + int seedindex = tracklet->getISeed(); + + int idrphicut = rphicutPS_[seedindex]; + int idrcut = rcutPS_[seedindex]; + if (!stub->isPSmodule()) { + idrphicut = rphicut2S_[seedindex]; + idrcut = rcut2S_[seedindex]; + } + + double drphicut = idrphicut * settings_.kphi() * settings_.kr(); + double drcut = idrcut * settings_.krprojshiftdisk(); + + if (settings_.writeMonitorData("Residuals")) { + double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv()); + + globals_->ofstream("diskresiduals.txt") + << disk_ << " " << stub->isPSmodule() << " " << tracklet->layer() << " " << abs(tracklet->disk()) << " " << pt + << " " << ideltaphi * settings_.kphi() * stub->r() << " " << drphiapprox << " " << drphicut << " " + << ideltar * settings_.krprojshiftdisk() << " " << deltar << " " << drcut << " " << endl; + } + + bool match = (std::abs(drphi) < drphicut) && (std::abs(deltar) < drcut); + bool imatch = (std::abs(ideltaphi * irstub) < idrphicut) && (std::abs(ideltar) < idrcut); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "imatch match disk: " << imatch << " " << match << " " << std::abs(ideltaphi) + << " " << drphicut / (settings_.kphi() * stub->r()) << " " << std::abs(ideltar) + << " " << drcut / settings_.krprojshiftdisk() << " r = " << stub->r(); + } + + if (imatch) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "MatchCalculator found match in disk " << getName(); + } + + if (std::abs(dphi) >= 0.25) { + edm::LogPrint("Tracklet") << "dphi " << dphi << " ISeed " << tracklet->getISeed(); + } + assert(std::abs(dphi) < 0.25); + assert(std::abs(dphiapprox) < 0.25); + + tracklet->addMatchDisk(disk, + ideltaphi, + ideltar, + drphi / stub->r(), + dr, + drphiapprox / stub->r(), + drapprox, + stub->alpha(settings_.stripPitch(stub->isPSmodule())), + (phiregion_ << 7) + fpgastub->stubindex().value(), + stub->z(), + fpgastub); + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Accepted full match in disk " << getName() << " " << tracklet << " " + << iSector_; + } + + int iSeed = tracklet->getISeed(); + assert(fullmatches_[iSeed] != nullptr); + fullmatches_[iSeed]->addMatch(tracklet, fpgastub); + + return true; + } else { + return false; + } + } +} diff --git a/L1Trigger/TrackFindingTracklet/src/MemoryBase.cc b/L1Trigger/TrackFindingTracklet/src/MemoryBase.cc new file mode 100644 index 0000000000000..6f0c1452efe65 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/MemoryBase.cc @@ -0,0 +1,106 @@ +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +#include + +using namespace trklet; +using namespace std; + +MemoryBase::MemoryBase(string name, Settings const& settings, unsigned int iSector) : name_(name), settings_(settings) { + iSector_ = iSector; + bx_ = 0; + event_ = 0; +} + +void MemoryBase::initLayerDisk(unsigned int pos, int& layer, int& disk) { + string subname = name_.substr(pos, 2); + layer = 0; + disk = 0; + + if (subname.substr(0, 1) == "L") + layer = stoi(subname.substr(1, 1)); + else if (subname.substr(0, 1) == "D") + disk = stoi(subname.substr(1, 1)); + else + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " name = " << name_ << " subname = " << subname + << " " << layer << " " << disk; +} + +unsigned int MemoryBase::initLayerDisk(unsigned int pos) { + int layer, disk; + initLayerDisk(pos, layer, disk); + + if (disk > 0) + return N_DISK + disk; + return layer - 1; +} + +void MemoryBase::initSpecialSeeding(unsigned int pos, bool& overlap, bool& extra, bool& extended) { + overlap = false; + extra = false; + extended = false; + + char subname = name_[pos]; + + static const std::set overlapset = { + 'X', 'Y', 'W', 'Q', 'R', 'S', 'T', 'Z', 'x', 'y', 'w', 'q', 'r', 's', 't', 'z'}; + overlap = overlapset.find(subname) != overlapset.end(); + + static const std::set extraset = {'I', 'J', 'K', 'L'}; + extra = extraset.find(subname) != extraset.end(); + + static const std::set extendedset = { + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'x', 'y', 'z', 'w', 'q', 'r', 's', 't'}; + extended = extendedset.find(subname) != extendedset.end(); +} + +void MemoryBase::findAndReplaceAll(std::string& data, std::string toSearch, std::string replaceStr) { + // Get the first occurrence + size_t pos = data.find(toSearch); + + // Repeat till end is reached + while (pos != std::string::npos) { + // Replace this occurrence of Sub String + data.replace(pos, toSearch.size(), replaceStr); + // Get the next occurrence from the current position + pos = data.find(toSearch, pos + replaceStr.size()); + } +} + +void MemoryBase::openFile(bool first, std::string filebase) { + std::string fname = filebase; + fname += getName(); + + findAndReplaceAll(fname, "PHIa", "PHIaa"); + findAndReplaceAll(fname, "PHIb", "PHIbb"); + findAndReplaceAll(fname, "PHIc", "PHIcc"); + findAndReplaceAll(fname, "PHId", "PHIdd"); + + findAndReplaceAll(fname, "PHIx", "PHIxx"); + findAndReplaceAll(fname, "PHIy", "PHIyy"); + findAndReplaceAll(fname, "PHIz", "PHIzz"); + findAndReplaceAll(fname, "PHIw", "PHIww"); + + fname += "_"; + if (iSector_ + 1 < 10) + fname += "0"; + fname += std::to_string(iSector_ + 1); + fname += ".dat"; + + if (first) { + bx_ = 0; + event_ = 1; + out_.open(fname.c_str()); + } else { + out_.open(fname.c_str(), std::ofstream::app); + } + + out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; + + bx_++; + event_++; + if (bx_ > 7) + bx_ = 0; +} diff --git a/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc b/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc new file mode 100644 index 0000000000000..867b909d6c091 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc @@ -0,0 +1,148 @@ +#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +#include + +using namespace trklet; +using namespace std; + +ProcessBase::ProcessBase(string name, Settings const& settings, Globals* global, unsigned int iSector) + : name_(name), settings_(settings), globals_(global) { + iSector_ = iSector; + double dphi = 2 * M_PI / N_SECTOR; + double dphiHG = 0.5 * settings_.dphisectorHG() - M_PI / N_SECTOR; + phimin_ = iSector_ * dphi - dphiHG; + phimax_ = phimin_ + dphi + 2 * dphiHG; + phimin_ -= M_PI / N_SECTOR; + phimax_ -= M_PI / N_SECTOR; + if (phimin_ > M_PI) { + phimin_ -= 2 * M_PI; + phimax_ -= 2 * M_PI; + } +} + +unsigned int ProcessBase::nbits(unsigned int power) { + if (power == 2) + return 1; + if (power == 4) + return 2; + if (power == 8) + return 3; + if (power == 16) + return 4; + if (power == 32) + return 5; + + throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << "nbits: power = " << power; + return 0; +} + +void ProcessBase::initLayerDisk(unsigned int pos, int& layer, int& disk) { + string subname = name_.substr(pos, 2); + layer = 0; + disk = 0; + if (subname.substr(0, 1) == "L") + layer = stoi(subname.substr(1, 1)); + else if (subname.substr(0, 1) == "D") + disk = stoi(subname.substr(1, 1)); + else + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " " << name_ << " subname = " << subname << " " + << layer << " " << disk; +} + +void ProcessBase::initLayerDisk(unsigned int pos, int& layer, int& disk, int& layerdisk) { + initLayerDisk(pos, layer, disk); + + layerdisk = layer - 1; + if (disk > 0) + layerdisk = N_DISK + disk; +} + +unsigned int ProcessBase::initLayerDisk(unsigned int pos) { + int layer, disk; + initLayerDisk(pos, layer, disk); + + if (disk > 0) + return N_DISK + disk; + return layer - 1; +} + +void ProcessBase::initLayerDisksandISeed(unsigned int& layerdisk1, unsigned int& layerdisk2, unsigned int& iSeed) { + layerdisk1 = 99; + layerdisk2 = 99; + + if (name_.substr(0, 3) == "TE_") { + if (name_[3] == 'L') { + layerdisk1 = name_[4] - '1'; + } else if (name_[3] == 'D') { + layerdisk1 = 6 + name_[4] - '1'; + } + if (name_[11] == 'L') { + layerdisk2 = name_[12] - '1'; + } else if (name_[11] == 'D') { + layerdisk2 = 6 + name_[12] - '1'; + } else if (name_[12] == 'L') { + layerdisk2 = name_[13] - '1'; + } else if (name_[12] == 'D') { + layerdisk2 = 6 + name_[13] - '1'; + } + } + + if (name_.substr(0, 3) == "TC_") { + if (name_[3] == 'L') { + layerdisk1 = name_[4] - '1'; + } else if (name_[3] == 'D') { + layerdisk1 = 6 + name_[4] - '1'; + } + if (name_[5] == 'L') { + layerdisk2 = name_[6] - '1'; + } else if (name_[5] == 'D') { + layerdisk2 = 6 + name_[6] - '1'; + } + } + + if (layerdisk1 == 0 && layerdisk2 == 1) + iSeed = 0; + else if (layerdisk1 == 1 && layerdisk2 == 2) + iSeed = 1; + else if (layerdisk1 == 2 && layerdisk2 == 3) + iSeed = 2; + else if (layerdisk1 == 4 && layerdisk2 == 5) + iSeed = 3; + else if (layerdisk1 == 6 && layerdisk2 == 7) + iSeed = 4; + else if (layerdisk1 == 8 && layerdisk2 == 9) + iSeed = 5; + else if (layerdisk1 == 0 && layerdisk2 == 6) + iSeed = 6; + else if (layerdisk1 == 1 && layerdisk2 == 6) + iSeed = 7; + else { + throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " layerdisk1 " << layerdisk1 << " layerdisk2 " + << layerdisk2; + } +} + +unsigned int ProcessBase::getISeed(std::string name) { + std::size_t pos = name.find("_"); + std::string name1 = name.substr(pos + 1); + pos = name1.find("_"); + std::string name2 = name1.substr(0, pos); + + unordered_map seedmap = { + {"L1L2", 0}, {"L2L3", 1}, {"L3L4", 2}, {"L5L6", 3}, {"D1D2", 4}, {"D3D4", 5}, {"L1D1", 6}, + {"L2D1", 7}, {"L1L2XX", 0}, {"L2L3XX", 1}, {"L3L4XX", 2}, {"L5L6XX", 3}, {"D1D2XX", 4}, {"D3D4XX", 5}, + {"L1D1XX", 6}, {"L2D1XX", 7}, {"L3L4L2", 8}, {"L5L6L4", 9}, {"L2L3D1", 10}, {"D1D2L2", 11}}; + auto found = seedmap.find(name2); + if (found != seedmap.end()) + return found->second; + + throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " " << getName() << " name name1 name2 " << name + << " - " << name1 << " - " << name2; + return 0; +} diff --git a/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc b/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc new file mode 100644 index 0000000000000..06856031b1e1d --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc @@ -0,0 +1,148 @@ +#include "L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" +#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +using namespace std; +using namespace trklet; + +ProjectionRouter::ProjectionRouter(string name, Settings const& settings, Globals* global, unsigned int iSector) + : ProcessBase(name, settings, global, iSector) { + layerdisk_ = initLayerDisk(3); + + vmprojs_.resize(settings_.nvmme(layerdisk_), nullptr); + + nrbits_ = 5; + nphiderbits_ = 6; +} + +void ProjectionRouter::addOutput(MemoryBase* memory, string output) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " + << output; + } + if (output == "allprojout") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + allproj_ = tmp; + return; + } + + unsigned int nproj = settings_.nallstubs(layerdisk_); + unsigned int nprojvm = settings_.nvmme(layerdisk_); + + for (unsigned int iproj = 0; iproj < nproj; iproj++) { + for (unsigned int iprojvm = 0; iprojvm < nprojvm; iprojvm++) { + std::string name = "vmprojoutPHI"; + name += char(iproj + 'A'); + name += std::to_string(iproj * nprojvm + iprojvm + 1); + if (output == name) { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + vmprojs_[iprojvm] = tmp; + return; + } + } + } + + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find output: " << output; +} + +void ProjectionRouter::addInput(MemoryBase* memory, string input) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " + << input; + } + if (input.substr(0, 4) == "proj" && input.substr(input.size() - 2, 2) == "in") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + inputproj_.push_back(tmp); + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input: " << input; +} + +void ProjectionRouter::execute() { + if (globals_->projectionRouterBendTable() == nullptr) { + auto* bendTablePtr = new ProjectionRouterBendTable(); + bendTablePtr->init(settings_, globals_, nrbits_, nphiderbits_); + globals_->projectionRouterBendTable() = bendTablePtr; + } + + unsigned int allprojcount = 0; + + //These are just here to test that the order is correct. Does not affect the actual execution + + int lastTCID = -1; + + for (auto& iproj : inputproj_) { + for (unsigned int i = 0; i < iproj->nTracklets(); i++) { + if (allprojcount > settings_.maxStep("PR")) + continue; + + Tracklet* tracklet = iproj->getTracklet(i); + + FPGAWord fpgaphi; + + if (layerdisk_ < N_LAYER) { + fpgaphi = tracklet->fpgaphiproj(layerdisk_ + 1); + } else { + int disk = layerdisk_ - (N_LAYER - 1); + fpgaphi = tracklet->fpgaphiprojdisk(disk); + + //The next lines looks up the predicted bend based on: + // 1 - r projections + // 2 - phi derivative + // 3 - the sign - i.e. if track is forward or backward + int rindex = (tracklet->fpgarprojdisk(disk).value() >> (tracklet->fpgarprojdisk(disk).nbits() - nrbits_)) & + ((1 << nrbits_) - 1); + + int phiderindex = (tracklet->fpgaphiprojderdisk(disk).value() >> + (tracklet->fpgaphiprojderdisk(disk).nbits() - nphiderbits_)) & + ((1 << nphiderbits_) - 1); + + int signindex = (tracklet->fpgarprojderdisk(disk).value() < 0); + + int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex; + + int ibendproj = globals_->projectionRouterBendTable()->bendLoookup(disk - 1, bendindex); + + tracklet->setBendIndex(ibendproj, disk); + } + + unsigned int iphivm = + fpgaphi.bits(fpgaphi.nbits() - settings_.nbitsallstubs(layerdisk_) - settings_.nbitsvmme(layerdisk_), + settings_.nbitsvmme(layerdisk_)); + + //This block of code just checks that the configuration is consistent + if (lastTCID >= tracklet->TCID()) { + edm::LogPrint("Tracklet") << "Wrong TCID ordering for projections in " << getName(); + } else { + lastTCID = tracklet->TCID(); + } + + allproj_->addTracklet(tracklet); + + vmprojs_[iphivm]->addTracklet(tracklet, allprojcount); + + allprojcount++; + } + } + + if (settings_.writeMonitorData("AP")) { + globals_->ofstream("allprojections.txt") << getName() << " " << allproj_->nTracklets() << endl; + } + + if (settings_.writeMonitorData("VMP")) { + ofstream& out = globals_->ofstream("chisq.txt"); + for (unsigned int i = 0; i < 8; i++) { + if (vmprojs_[i] != nullptr) { + out << vmprojs_[i]->getName() << " " << vmprojs_[i]->nTracklets() << endl; + } + } + } +} diff --git a/L1Trigger/TrackFindingTracklet/src/ProjectionRouterBendTable.cc b/L1Trigger/TrackFindingTracklet/src/ProjectionRouterBendTable.cc new file mode 100644 index 0000000000000..6ddbcc3628cf2 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/ProjectionRouterBendTable.cc @@ -0,0 +1,54 @@ +#include "L1Trigger/TrackFindingTracklet/interface/ProjectionRouterBendTable.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" +#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" + +using namespace trklet; + +void ProjectionRouterBendTable::init(Settings const& settings, + Globals* globals, + unsigned int nrbits, + unsigned int nphiderbits) { + for (unsigned int idisk = 0; idisk < N_DISK; idisk++) { + unsigned int nsignbins = 2; + unsigned int nrbins = 1 << (nrbits); + unsigned int nphiderbins = 1 << (nphiderbits); + + for (unsigned int isignbin = 0; isignbin < nsignbins; isignbin++) { + for (unsigned int irbin = 0; irbin < nrbins; irbin++) { + int ir = irbin; + if (ir > (1 << (nrbits - 1))) + ir -= (1 << nrbits); + ir = ir << (settings.nrbitsstub(N_LAYER) - nrbits); + for (unsigned int iphiderbin = 0; iphiderbin < nphiderbins; iphiderbin++) { + int iphider = iphiderbin; + if (iphider > (1 << (nphiderbits - 1))) + iphider -= (1 << nphiderbits); + iphider = iphider << (settings.nbitsphiprojderL123() - nphiderbits); + + double rproj = ir * settings.krprojshiftdisk(); + double phider = iphider * globals->ITC_L1L2()->der_phiD_final.K(); + double t = settings.zmean(idisk) / rproj; + + if (isignbin) + t = -t; + + double rinv = -phider * (2.0 * t); + + double stripPitch = (rproj < settings.rcrit()) ? settings.stripPitch(true) : settings.stripPitch(false); + double bendproj = 0.5 * bend(rproj, rinv, stripPitch); + + int ibendproj = 2.0 * bendproj + 15.5; + if (ibendproj < 0) + ibendproj = 0; + if (ibendproj > 31) + ibendproj = 31; + + bendtable_[idisk].push_back(ibendproj); + } + } + } + } +} + +int ProjectionRouterBendTable::bendLoookup(int diskindex, int bendindex) { return bendtable_[diskindex][bendindex]; } diff --git a/L1Trigger/TrackFindingTracklet/src/ProjectionTemp.cc b/L1Trigger/TrackFindingTracklet/src/ProjectionTemp.cc new file mode 100644 index 0000000000000..5287ffacceb7b --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/ProjectionTemp.cc @@ -0,0 +1,30 @@ +#include "L1Trigger/TrackFindingTracklet/interface/ProjectionTemp.h" + +using namespace std; +using namespace trklet; + +ProjectionTemp::ProjectionTemp(Tracklet* proj, + unsigned int slot, + unsigned int projrinv, + int projfinerz, + unsigned int projfinephi, + unsigned int iphi, + bool isPSseed) { + proj_ = proj; + slot_ = slot; + projrinv_ = projrinv; + projfinerz_ = projfinerz; + projfinephi_ = projfinephi; + iphi_ = iphi; + isPSseed_ = isPSseed; +} + +ProjectionTemp::ProjectionTemp() { + proj_ = nullptr; + slot_ = 0; + projrinv_ = 0; + projfinerz_ = 0; + projfinephi_ = 0; + iphi_ = 0; + isPSseed_ = false; +} diff --git a/L1Trigger/TrackFindingTracklet/src/PurgeDuplicate.cc b/L1Trigger/TrackFindingTracklet/src/PurgeDuplicate.cc new file mode 100644 index 0000000000000..fb3e6042df594 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/PurgeDuplicate.cc @@ -0,0 +1,512 @@ +#include "L1Trigger/TrackFindingTracklet/interface/PurgeDuplicate.h" +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/CleanTrackMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include "L1Trigger/TrackFindingTracklet/interface/Track.h" + +#ifdef USEHYBRID +#include "DataFormats/L1TrackTrigger/interface/TTStub.h" +#include "L1Trigger/TrackFindingTMTT/interface/L1track3D.h" +#include "L1Trigger/TrackFindingTMTT/interface/KFParamsComb.h" +#include "L1Trigger/TrackFindingTracklet/interface/HybridFit.h" +#endif + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +#include +#include + +using namespace std; +using namespace trklet; + +PurgeDuplicate::PurgeDuplicate(std::string name, Settings const& settings, Globals* global, unsigned int iSector) + : ProcessBase(name, settings, global, iSector) {} + +void PurgeDuplicate::addOutput(MemoryBase* memory, std::string output) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " + << output; + } + unordered_set outputs = {"trackout", + "trackout1", + "trackout2", + "trackout3", + "trackout4", + "trackout5", + "trackout6", + "trackout7", + "trackout8", + "trackout9", + "trackout10", + "trackout11"}; + if (outputs.find(output) != outputs.end()) { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + outputtracklets_.push_back(tmp); + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find output: " << output; +} + +void PurgeDuplicate::addInput(MemoryBase* memory, std::string input) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " + << input; + } + unordered_set inputs = {"trackin", + "trackin1", + "trackin2", + "trackin3", + "trackin4", + "trackin5", + "trackin6", + "trackin7", + "trackin8", + "trackin9", + "trackin10", + "trackin11"}; + if (inputs.find(input) != inputs.end()) { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + inputtrackfits_.push_back(tmp); + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input: " << input; +} + +void PurgeDuplicate::execute(std::vector& outputtracks_) { + inputtracklets_.clear(); + inputtracks_.clear(); + + inputstubidslists_.clear(); + inputstublists_.clear(); + mergedstubidslists_.clear(); + + if (settings_.removalType() != "merge") { + for (auto& inputtrackfit : inputtrackfits_) { + if (inputtrackfit->nTracks() == 0) + continue; + for (unsigned int j = 0; j < inputtrackfit->nTracks(); j++) { + Track* aTrack = inputtrackfit->getTrack(j)->getTrack(); + aTrack->setSector(iSector_); + inputtracks_.push_back(aTrack); + } + } + if (inputtracks_.empty()) + return; + } + + unsigned int numTrk = inputtracks_.size(); + + //////////////////// + // Hybrid Removal // + //////////////////// +#ifdef USEHYBRID + + if (settings_.removalType() == "merge") { + std::vector> trackInfo; // Track seed & duplicate flag + // Vector to store the relative rank of the track candidate for merging, based on seed type + std::vector seedRank; + + // Get vectors from TrackFit and save them + // inputtracklets: Tracklet objects from the FitTrack (not actually fit yet) + // inputstublists: L1Stubs for that track + // inputstubidslists: Stub stubIDs for that 3rack + // mergedstubidslists: the same as inputstubidslists, but will be used during duplicate removal + for (unsigned int i = 0; i < inputtrackfits_.size(); i++) { + if (inputtrackfits_[i]->nStublists() == 0) + continue; + if (inputtrackfits_[i]->nStublists() != inputtrackfits_[i]->nTracks()) + throw "Number of stublists and tracks don't match up!"; + for (unsigned int j = 0; j < inputtrackfits_[i]->nStublists(); j++) { + Tracklet* aTrack = inputtrackfits_[i]->getTrack(j); + inputtracklets_.push_back(inputtrackfits_[i]->getTrack(j)); + + std::vector stublist = inputtrackfits_[i]->getStublist(j); + + inputstublists_.push_back(stublist); + + std::vector> stubidslist = inputtrackfits_[i]->getStubidslist(j); + inputstubidslists_.push_back(stubidslist); + mergedstubidslists_.push_back(stubidslist); + + // Encoding: L1L2=0, L2L3=1, L3L4=2, L5L6=3, D1D2=4, D3D4=5, L1D1=6, L2D1=7 + // Best Guess: L1L2 > L1D1 > L2L3 > L2D1 > D1D2 > L3L4 > L5L6 > D3D4 + // Best Rank: L1L2 > L3L4 > D3D4 > D1D2 > L2L3 > L2D1 > L5L6 > L1D1 + // Rank-Informed Guess: L1L2 > L3L4 > L1D1 > L2L3 > L2D1 > D1D2 > L5L6 > D3D4 + unsigned int curSeed = aTrack->seedIndex(); + if (curSeed == 0) { + seedRank.push_back(1); + } else if (curSeed == 2) { + seedRank.push_back(2); + } else if (curSeed == 5) { + seedRank.push_back(3); + } else if (curSeed == 4) { + seedRank.push_back(4); + } else if (curSeed == 1) { + seedRank.push_back(5); + } else if (curSeed == 7) { + seedRank.push_back(6); + } else if (curSeed == 3) { + seedRank.push_back(7); + } else if (curSeed == 6) { + seedRank.push_back(8); + } else if (settings_.extended()) { + seedRank.push_back(9); + } else { + throw cms::Exception("LogError") << __FILE__ << " " << __LINE__ << " Seed " << curSeed + << " not found in list, and settings->extended() not set."; + } + + if (stublist.size() != stubidslist.size()) + throw "Number of stubs and stubids don't match up!"; + + trackInfo.emplace_back(i, false); + } + } + + if (inputtracklets_.empty()) + return; + unsigned int numStublists = inputstublists_.size(); + + // Initialize all-false 2D array of tracks being duplicates to other tracks + bool dupMap[numStublists][numStublists]; // Ends up symmetric + for (unsigned int itrk = 0; itrk < numStublists; itrk++) { + for (unsigned int jtrk = 0; jtrk < numStublists; jtrk++) { + dupMap[itrk][jtrk] = false; + } + } + + // Find duplicates; Fill dupMap by looping over all pairs of "tracks" + // numStublists-1 since last track has no other to compare to + for (unsigned int itrk = 0; itrk < numStublists - 1; itrk++) { + for (unsigned int jtrk = itrk + 1; jtrk < numStublists; jtrk++) { + // Get primary track stubids + const std::vector>& stubsTrk1 = inputstubidslists_[itrk]; + + // Get and count secondary track stubids + const std::vector>& stubsTrk2 = inputstubidslists_[jtrk]; + + // Count number of Unique Regions (UR) that share stubs, and the number of UR that each track hits + unsigned int nShareUR = 0; + unsigned int nURStubTrk1 = 0; + unsigned int nURStubTrk2 = 0; + if (settings_.mergeComparison() == "CompareAll") { + bool URArray[16]; + for (auto& i : URArray) { + i = false; + }; + for (const auto& st1 : stubsTrk1) { + for (const auto& st2 : stubsTrk2) { + if (st1.first == st2.first && st1.second == st2.second) { + // Converts region encoded in st1->first to an index in the Unique Region (UR) array + int i = st1.first; + int reg = (i > 0 && i < 10) * (i - 1) + (i > 10) * (i - 5) - (i < 0) * i; + if (!URArray[reg]) { + nShareUR++; + URArray[reg] = true; + } + } + } + } + } else if (settings_.mergeComparison() == "CompareBest") { + std::vector fullStubslistsTrk1 = inputstublists_[itrk]; + std::vector fullStubslistsTrk2 = inputstublists_[jtrk]; + + // Arrays to store the index of the best stub in each region + int URStubidsTrk1[16]; + int URStubidsTrk2[16]; + for (int i = 0; i < 16; i++) { + URStubidsTrk1[i] = -1; + URStubidsTrk2[i] = -1; + } + // For each stub on the first track, find the stub with the best residual and store its index in the URStubidsTrk1 array + for (unsigned int stcount = 0; stcount < stubsTrk1.size(); stcount++) { + int i = stubsTrk1[stcount].first; + int reg = (i > 0 && i < 10) * (i - 1) + (i > 10) * (i - 5) - (i < 0) * i; + double nres = getPhiRes(inputtracklets_[itrk], fullStubslistsTrk1[stcount]); + double ores = 0; + if (URStubidsTrk1[reg] != -1) + ores = getPhiRes(inputtracklets_[itrk], fullStubslistsTrk1[URStubidsTrk1[reg]]); + if (URStubidsTrk1[reg] == -1 || nres < ores) { + URStubidsTrk1[reg] = stcount; + } + } + // For each stub on the second track, find the stub with the best residual and store its index in the URStubidsTrk1 array + for (unsigned int stcount = 0; stcount < stubsTrk2.size(); stcount++) { + int i = stubsTrk2[stcount].first; + int reg = (i > 0 && i < 10) * (i - 1) + (i > 10) * (i - 5) - (i < 0) * i; + double nres = getPhiRes(inputtracklets_[jtrk], fullStubslistsTrk2[stcount]); + double ores; + if (URStubidsTrk2[reg] != -1) + ores = getPhiRes(inputtracklets_[jtrk], fullStubslistsTrk2[URStubidsTrk2[reg]]); + if (URStubidsTrk2[reg] == -1 || nres < ores) { + URStubidsTrk2[reg] = stcount; + } + } + // For all 16 regions (6 layers and 10 disks), count the number of regions who's best stub on both tracks are the same + for (int i = 0; i < 16; i++) { + int t1i = URStubidsTrk1[i]; + int t2i = URStubidsTrk2[i]; + if (t1i != -1 && t2i != -1 && stubsTrk1[t1i].first == stubsTrk2[t2i].first && + stubsTrk1[t1i].second == stubsTrk2[t2i].second) + nShareUR++; + } + // Calculate the number of unique regions hit by each track, so that this number can be used in calculating the number of independent + // stubs on a track (not enabled/used by default) + for (int i = 0; i < 16; i++) { + if (URStubidsTrk1[i] != -1) + nURStubTrk1++; + if (URStubidsTrk2[i] != -1) + nURStubTrk2++; + } + } + + // Fill duplicate map + if (nShareUR >= settings_.minIndStubs()) { // For number of shared stub merge condition + dupMap[itrk][jtrk] = true; + dupMap[jtrk][itrk] = true; + } + } + } + + // Merge duplicate tracks + for (unsigned int itrk = 0; itrk < numStublists - 1; itrk++) { + for (unsigned int jtrk = itrk + 1; jtrk < numStublists; jtrk++) { + // Merge a track with its first duplicate found. + if (dupMap[itrk][jtrk]) { + // Set preferred track based on seed rank + int preftrk; + int rejetrk; + if (seedRank[itrk] < seedRank[jtrk]) { + preftrk = itrk; + rejetrk = jtrk; + } else { + preftrk = jtrk; + rejetrk = itrk; + } + + // Get a merged stub list + std::vector newStubList; + std::vector stubsTrk1 = inputstublists_[rejetrk]; + std::vector stubsTrk2 = inputstublists_[preftrk]; + newStubList = stubsTrk1; + for (unsigned int stub2it = 0; stub2it < stubsTrk2.size(); stub2it++) { + if (find(stubsTrk1.begin(), stubsTrk1.end(), stubsTrk2[stub2it]) == stubsTrk1.end()) { + newStubList.push_back(stubsTrk2[stub2it]); + } + } + // Overwrite stublist of preferred track with merged list + inputstublists_[preftrk] = newStubList; + + std::vector> newStubidsList; + std::vector> stubidsTrk1 = mergedstubidslists_[rejetrk]; + std::vector> stubidsTrk2 = mergedstubidslists_[preftrk]; + newStubidsList = stubidsTrk1; + for (unsigned int stub2it = 0; stub2it < stubidsTrk2.size(); stub2it++) { + if (find(stubidsTrk1.begin(), stubidsTrk1.end(), stubidsTrk2[stub2it]) == stubidsTrk1.end()) { + newStubidsList.push_back(stubidsTrk2[stub2it]); + } + } + // Overwrite stubidslist of preferred track with merged list + mergedstubidslists_[preftrk] = newStubidsList; + + // Mark that rejected track has been merged into another track + trackInfo[rejetrk].second = true; + } + } + } + + // Make the final track objects, fit with KF, and send to output + for (unsigned int itrk = 0; itrk < numStublists; itrk++) { + Tracklet* tracklet = inputtracklets_[itrk]; + std::vector trackstublist = inputstublists_[itrk]; + + HybridFit hybridFitter(iSector_, settings_, globals_); + hybridFitter.Fit(tracklet, trackstublist); + + // If the track was accepted (and thus fit), add to output + if (tracklet->fit()) { + // Add track to output if it wasn't merged into another + Track* outtrack = tracklet->getTrack(); + outtrack->setSector(iSector_); + if (trackInfo[itrk].second == true) + outtrack->setDuplicate(true); + else + outputtracklets_[trackInfo[itrk].first]->addTrack(tracklet); + + // Add all tracks to standalone root file output + outtrack->setStubIDpremerge(inputstubidslists_[itrk]); + outtrack->setStubIDprefit(mergedstubidslists_[itrk]); + outputtracks_.push_back(outtrack); + } + } + } +#endif + + ////////////////// + // Grid removal // + ////////////////// + if (settings_.removalType() == "grid") { + // Sort tracks by ichisq/DoF so that removal will keep the lower ichisq/DoF track + std::sort(inputtracks_.begin(), inputtracks_.end(), [](const Track* lhs, const Track* rhs) { + return lhs->ichisq() / lhs->stubID().size() < rhs->ichisq() / rhs->stubID().size(); + }); + bool grid[35][40] = {{false}}; + + for (unsigned int itrk = 0; itrk < numTrk; itrk++) { + if (inputtracks_[itrk]->duplicate()) + edm::LogPrint("Tracklet") << "WARNING: Track already tagged as duplicate!!"; + + double phiBin = (inputtracks_[itrk]->phi0(settings_) - 2 * M_PI / 27 * iSector_) / (2 * M_PI / 9 / 50) + 9; + phiBin = std::max(phiBin, 0.); + phiBin = std::min(phiBin, 34.); + + double ptBin = 1 / inputtracks_[itrk]->pt(settings_) * 40 + 20; + ptBin = std::max(ptBin, 0.); + ptBin = std::min(ptBin, 39.); + + if (grid[(int)phiBin][(int)ptBin]) + inputtracks_[itrk]->setDuplicate(true); + grid[(int)phiBin][(int)ptBin] = true; + + double phiTest = inputtracks_[itrk]->phi0(settings_) - 2 * M_PI / 27 * iSector_; + if (phiTest < -2 * M_PI / 27) + edm::LogVerbatim("Tracklet") << "track phi too small!"; + if (phiTest > 2 * 2 * M_PI / 27) + edm::LogVerbatim("Tracklet") << "track phi too big!"; + } + } // end grid removal + + ////////////////////////// + // ichi + nstub removal // + ////////////////////////// + if (settings_.removalType() == "ichi" || settings_.removalType() == "nstub") { + for (unsigned int itrk = 0; itrk < numTrk - 1; itrk++) { // numTrk-1 since last track has no other to compare to + + // If primary track is a duplicate, it cannot veto any...move on + if (inputtracks_[itrk]->duplicate() == 1) + continue; + + unsigned int nStubP = 0; + vector nStubS(numTrk); + vector nShare(numTrk); + // Get and count primary stubs + std::map stubsTrk1 = inputtracks_[itrk]->stubID(); + nStubP = stubsTrk1.size(); + + for (unsigned int jtrk = itrk + 1; jtrk < numTrk; jtrk++) { + // Skip duplicate tracks + if (inputtracks_[jtrk]->duplicate() == 1) + continue; + + // Get and count secondary stubs + std::map stubsTrk2 = inputtracks_[jtrk]->stubID(); + nStubS[jtrk] = stubsTrk2.size(); + + // Count shared stubs + for (auto& st : stubsTrk1) { + if (stubsTrk2.find(st.first) != stubsTrk2.end()) { + if (st.second == stubsTrk2[st.first]) + nShare[jtrk]++; + } + } + } + + // Tag duplicates + for (unsigned int jtrk = itrk + 1; jtrk < numTrk; jtrk++) { + // Skip duplicate tracks + if (inputtracks_[jtrk]->duplicate() == 1) + continue; + + // Chi2 duplicate removal + if (settings_.removalType() == "ichi") { + if ((nStubP - nShare[jtrk] < settings_.minIndStubs()) || + (nStubS[jtrk] - nShare[jtrk] < settings_.minIndStubs())) { + if ((int)inputtracks_[itrk]->ichisq() / (2 * inputtracks_[itrk]->stubID().size() - 4) > + (int)inputtracks_[jtrk]->ichisq() / (2 * inputtracks_[itrk]->stubID().size() - 4)) { + inputtracks_[itrk]->setDuplicate(true); + } else if ((int)inputtracks_[itrk]->ichisq() / (2 * inputtracks_[itrk]->stubID().size() - 4) <= + (int)inputtracks_[jtrk]->ichisq() / (2 * inputtracks_[itrk]->stubID().size() - 4)) { + inputtracks_[jtrk]->setDuplicate(true); + } else { + edm::LogVerbatim("Tracklet") << "Error: Didn't tag either track in duplicate pair."; + } + } + } // end ichi removal + + // nStub duplicate removal + if (settings_.removalType() == "nstub") { + if ((nStubP - nShare[jtrk] < settings_.minIndStubs()) && (nStubP < nStubS[jtrk])) { + inputtracks_[itrk]->setDuplicate(true); + } else if ((nStubS[jtrk] - nShare[jtrk] < settings_.minIndStubs()) && (nStubS[jtrk] <= nStubP)) { + inputtracks_[jtrk]->setDuplicate(true); + } else { + edm::LogVerbatim("Tracklet") << "Error: Didn't tag either track in duplicate pair."; + } + } // end nstub removal + + } // end tag duplicates + + } // end loop over primary track + + } // end ichi + nstub removal + + //Add tracks to output + if (settings_.removalType() != "merge") { + for (unsigned int i = 0; i < inputtrackfits_.size(); i++) { + for (unsigned int j = 0; j < inputtrackfits_[i]->nTracks(); j++) { + if (inputtrackfits_[i]->getTrack(j)->getTrack()->duplicate() == 0) { + if (settings_.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " + << inputtrackfits_[i]->getTrack(j)->getISeed() << endl; + fout.close(); + } + outputtracklets_[i]->addTrack(inputtrackfits_[i]->getTrack(j)); + } + //For root file: + outputtracks_.push_back(inputtrackfits_[i]->getTrack(j)->getTrack()); + } + } + } +} + +double PurgeDuplicate::getPhiRes(Tracklet* curTracklet, const Stub* curStub) { + double phiproj; + double stubphi; + double phires; + // Get phi position of stub + stubphi = curStub->l1tstub()->phi(); + // Get region that the stub is in (Layer 1->6, Disk 1->5) + int Layer = curStub->layer().value() + 1; + int Disk = curStub->disk().value(); + // Get phi projection of tracklet + int seedindex = curTracklet->seedIndex(); + // If this stub is a seed stub, set projection=phi, so that res=0 + if ((seedindex == 0 && (Layer == 1 || Layer == 2)) || (seedindex == 1 && (Layer == 2 || abs(Disk) == 0)) || + (seedindex == 2 && (Layer == 3 || Layer == 4)) || (seedindex == 3 && (Layer == 5 || Layer == 6)) || + (seedindex == 4 && (abs(Disk) == 1 || abs(Disk) == 2)) || + (seedindex == 5 && (abs(Disk) == 3 || abs(Disk) == 4)) || (seedindex == 6 && (Layer == 1 || abs(Disk) == 1)) || + (seedindex == 7 && (Layer == 2 || abs(Disk) == 1)) || + (seedindex == 8 && (Layer == 2 || Layer == 3 || Layer == 4)) || + (seedindex == 9 && (Layer == 4 || Layer == 5 || Layer == 6)) || + (seedindex == 10 && (Layer == 2 || Layer == 3 || abs(Disk) == 1)) || + (seedindex == 11 && (Layer == 2 || abs(Disk) == 1 || abs(Disk) == 2))) { + phiproj = stubphi; + // Otherwise, get projection of tracklet + } else if (Layer != 0) { + phiproj = curTracklet->phiproj(Layer); + } else if (Disk != 0) { + phiproj = curTracklet->phiprojdisk(Disk); + } else { + throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Layer: " << Layer << " -- Disk: " << Disk + << " Stub is not layer or disk in getPhiRes"; + } + // Calculate residual + phires = std::abs(stubphi - phiproj); + return phires; +} diff --git a/L1Trigger/TrackFindingTracklet/src/SLHCEvent.cc b/L1Trigger/TrackFindingTracklet/src/SLHCEvent.cc new file mode 100644 index 0000000000000..966bc40bca0e6 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/SLHCEvent.cc @@ -0,0 +1,293 @@ +#include "L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +using namespace std; +using namespace trklet; + +L1SimTrack::L1SimTrack() { + eventid_ = -1; + trackid_ = -1; +} + +L1SimTrack::L1SimTrack( + int eventid, int trackid, int type, double pt, double eta, double phi, double vx, double vy, double vz) { + eventid_ = eventid; + trackid_ = trackid; + type_ = type; + pt_ = pt; + eta_ = eta; + phi_ = phi; + vx_ = vx; + vy_ = vy; + vz_ = vz; +} + +void L1SimTrack::write(ofstream& out) { + if (pt_ > -2.0) { + out << "SimTrack: " << eventid_ << "\t" << trackid_ << "\t" << type_ << "\t" << pt_ << "\t" << eta_ << "\t" << phi_ + << "\t" << vx_ << "\t" << vy_ << "\t" << vz_ << "\t" << endl; + } +} + +void L1SimTrack::write(ostream& out) { + if (pt_ > -2) { + out << "SimTrack: " << eventid_ << "\t" << trackid_ << "\t" << type_ << "\t" << pt_ << "\t" << eta_ << "\t" << phi_ + << "\t" << vx_ << "\t" << vy_ << "\t" << vz_ << "\t" << endl; + } +} + +void SLHCEvent::addL1SimTrack( + int eventid, int trackid, int type, double pt, double eta, double phi, double vx, double vy, double vz) { + vx -= x_offset_; + vy -= y_offset_; + L1SimTrack simtrack(eventid, trackid, type, pt, eta, phi, vx, vy, vz); + simtracks_.push_back(simtrack); +} + +bool SLHCEvent::addStub(int layer, + int ladder, + int module, + int strip, + int eventid, + vector tps, + double pt, + double bend, + double x, + double y, + double z, + int isPSmodule, + int isFlipped) { + if (layer > 999 && layer < 1999 && z < 0.0) { + layer += 1000; + } + + layer--; + x -= x_offset_; + y -= y_offset_; + + L1TStub stub( + eventid, tps, -1, -1, layer, ladder, module, strip, x, y, z, -1.0, -1.0, pt, bend, isPSmodule, isFlipped); + + stubs_.push_back(stub); + return true; +} + +SLHCEvent::SLHCEvent(istream& in) { + string tmp; + in >> tmp; + while (tmp == "Map:") { + in >> tmp >> tmp >> tmp >> tmp >> tmp >> tmp >> tmp >> tmp; + in >> tmp >> tmp >> tmp >> tmp >> tmp >> tmp >> tmp >> tmp; + } + if (tmp == "EndMap") { + in >> tmp; + } + if (tmp != "Event:") { + edm::LogVerbatim("Tracklet") << "Expected to read 'Event:' but found:" << tmp; + if (tmp.empty()) { + edm::LogVerbatim("Tracklet") << "WARNING: fewer events to process than specified!"; + return; + } else { + edm::LogVerbatim("Tracklet") << "ERROR, aborting reading file"; + abort(); + } + } + in >> eventnum_; + + // read the SimTracks + in >> tmp; + while (tmp != "SimTrackEnd") { + if (!(tmp == "SimTrack:" || tmp == "SimTrackEnd")) { + edm::LogVerbatim("Tracklet") << "Expected to read 'SimTrack:' or 'SimTrackEnd' but found:" << tmp; + abort(); + } + int eventid; + int trackid; + int type; + string pt_str; + string eta_str; + string phi_str; + string vx_str; + string vy_str; + string vz_str; + double pt; + double eta; + double phi; + double vx; + double vy; + double vz; + in >> eventid >> trackid >> type >> pt_str >> eta_str >> phi_str >> vx_str >> vy_str >> vz_str; + pt = strtod(pt_str.c_str(), nullptr); + eta = strtod(eta_str.c_str(), nullptr); + phi = strtod(phi_str.c_str(), nullptr); + vx = strtod(vx_str.c_str(), nullptr); + vy = strtod(vy_str.c_str(), nullptr); + vz = strtod(vz_str.c_str(), nullptr); + vx -= x_offset_; + vy -= y_offset_; + L1SimTrack simtrack(eventid, trackid, type, pt, eta, phi, vx, vy, vz); + simtracks_.push_back(simtrack); + in >> tmp; + } + + int oldlayer = 0; + int oldladder = 0; + int oldmodule = 0; + int oldcbc = -1; + int count = 1; + double oldz = -1000.0; + + //read stubs + in >> tmp; + while (tmp != "StubEnd") { + if (!in.good()) { + edm::LogVerbatim("Tracklet") << "File not good"; + abort(); + }; + if (!(tmp == "Stub:" || tmp == "StubEnd")) { + edm::LogVerbatim("Tracklet") << "Expected to read 'Stub:' or 'StubEnd' but found:" << tmp; + abort(); + } + int layer; + int ladder; + int module; + int eventid; + vector tps; + int strip; + double pt; + double x; + double y; + double z; + double bend; + int isPSmodule; + int isFlipped; + + unsigned int ntps; + + in >> layer >> ladder >> module >> strip >> eventid >> pt >> x >> y >> z >> bend >> isPSmodule >> isFlipped >> ntps; + + for (unsigned int itps = 0; itps < ntps; itps++) { + int tp; + in >> tp; + tps.push_back(tp); + } + + if (layer > 999 && layer < 1999 && z < 0.0) { //negative disk + layer += 1000; + } + + int cbc = strip / 126; + if (layer > 3 && layer == oldlayer && ladder == oldladder && module == oldmodule && cbc == oldcbc && + std::abs(oldz - z) < 1.0) { + count++; + } else { + oldlayer = layer; + oldladder = ladder; + oldmodule = module; + oldcbc = cbc; + oldz = z; + count = 1; + } + + layer--; + x -= x_offset_; + y -= y_offset_; + + L1TStub stub( + eventid, tps, -1, -1, layer, ladder, module, strip, x, y, z, -1.0, -1.0, pt, bend, isPSmodule, isFlipped); + + in >> tmp; + + double t = std::abs(stub.z()) / stub.r(); + double eta = asinh(t); + + if (std::abs(eta) < 2.6 && count <= 100) { + stubs_.push_back(stub); + } + } +} + +void SLHCEvent::write(ofstream& out) { + out << "Event: " << eventnum_ << endl; + + for (auto& simtrack : simtracks_) { + simtrack.write(out); + } + out << "SimTrackEnd" << endl; + + for (auto& stub : stubs_) { + stub.write(out); + } + out << "StubEnd" << endl; +} + +void SLHCEvent::write(ostream& out) { + out << "Event: " << eventnum_ << endl; + + for (auto& simtrack : simtracks_) { + simtrack.write(out); + } + out << "SimTrackEnd" << endl; + + for (auto& stub : stubs_) { + stub.write(out); + } + out << "StubEnd" << endl; +} + +unsigned int SLHCEvent::layersHit(int tpid, int& nlayers, int& ndisks) { + int l1 = 0; + int l2 = 0; + int l3 = 0; + int l4 = 0; + int l5 = 0; + int l6 = 0; + + int d1 = 0; + int d2 = 0; + int d3 = 0; + int d4 = 0; + int d5 = 0; + + for (auto& stub : stubs_) { + if (stub.tpmatch(tpid)) { + if (stub.layer() == 0) + l1 = 1; + if (stub.layer() == 1) + l2 = 1; + if (stub.layer() == 2) + l3 = 1; + if (stub.layer() == 3) + l4 = 1; + if (stub.layer() == 4) + l5 = 1; + if (stub.layer() == 5) + l6 = 1; + + if (abs(stub.disk()) == 1) + d1 = 1; + if (abs(stub.disk()) == 2) + d2 = 1; + if (abs(stub.disk()) == 3) + d3 = 1; + if (abs(stub.disk()) == 4) + d4 = 1; + if (abs(stub.disk()) == 5) + d5 = 1; + } + } + + nlayers = l1 + l2 + l3 + l4 + l5 + l6; + ndisks = d1 + d2 + d3 + d4 + d5; + + return l1 + 2 * l2 + 4 * l3 + 8 * l4 + 16 * l5 + 32 * l6 + 64 * d1 + 128 * d2 + 256 * d3 + 512 * d4 + 1024 * d5; +} + +int SLHCEvent::getSimtrackFromSimtrackid(int simtrackid, int eventid) const { + for (unsigned int i = 0; i < simtracks_.size(); i++) { + if (simtracks_[i].trackid() == simtrackid && simtracks_[i].eventid() == eventid) + return i; + } + return -1; +} diff --git a/L1Trigger/TrackFindingTracklet/src/Sector.cc b/L1Trigger/TrackFindingTracklet/src/Sector.cc new file mode 100644 index 0000000000000..0c383ed147360 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/Sector.cc @@ -0,0 +1,430 @@ +#include "L1Trigger/TrackFindingTracklet/interface/Sector.h" +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" + +#include "L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/StubTripletsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackFitMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/CleanTrackMemory.h" + +#include "L1Trigger/TrackFindingTracklet/interface/VMRouter.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h" +#include "L1Trigger/TrackFindingTracklet/interface/TripletEngine.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorDisplaced.h" +#include "L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h" +#include "L1Trigger/TrackFindingTracklet/interface/MatchEngine.h" +#include "L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h" +#include "L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h" +#include "L1Trigger/TrackFindingTracklet/interface/FitTrack.h" +#include "L1Trigger/TrackFindingTracklet/interface/PurgeDuplicate.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" +#include "DataFormats/Math/interface/deltaPhi.h" + +using namespace std; +using namespace trklet; + +Sector::Sector(unsigned int i, Settings const& settings, Globals* globals) : settings_(settings), globals_(globals) { + isector_ = i; + double dphi = 2 * M_PI / N_SECTOR; + double dphiHG = 0.5 * settings_.dphisectorHG() - M_PI / N_SECTOR; + phimin_ = isector_ * dphi - dphiHG; + phimax_ = phimin_ + dphi + 2 * dphiHG; + phimin_ -= M_PI / N_SECTOR; + phimax_ -= M_PI / N_SECTOR; + phimin_ = reco::reduceRange(phimin_); + phimax_ = reco::reduceRange(phimax_); + if (phimin_ > phimax_) + phimin_ -= 2 * M_PI; +} + +Sector::~Sector() { + for (auto& mem : MemoriesV_) { + mem->clean(); + } +} + +bool Sector::addStub(L1TStub stub, string dtc) { + bool add = false; + + double phi = stub.phi(); + double dphi = 0.5 * settings_.dphisectorHG() - M_PI / N_SECTOR; + + std::map >& ILindex = globals_->ILindex(); + std::vector& tmp = ILindex[dtc]; + if (tmp.empty()) { + for (unsigned int i = 0; i < IL_.size(); i++) { + if (IL_[i]->getName().find("_" + dtc) != string::npos) { + tmp.push_back(i); + } + } + } + + if (((phi > phimin_ - dphi) && (phi < phimax_ + dphi)) || + ((phi > 2 * M_PI + phimin_ - dphi) && (phi < 2 * M_PI + phimax_ + dphi))) { + Stub fpgastub(stub, settings_, phimin_, phimax_); + std::vector& tmp = ILindex[dtc]; + assert(!tmp.empty()); + for (int i : tmp) { + if (IL_[i]->addStub(settings_, globals_, stub, fpgastub, dtc)) + add = true; + } + } + + return add; +} + +void Sector::addMem(string memType, string memName) { + if (memType == "InputLink:") { + addMemToVec(IL_, new InputLinkMemory(memName, settings_, isector_, phimin_, phimax_), memName); + } else if (memType == "AllStubs:") { + addMemToVec(AS_, new AllStubsMemory(memName, settings_, isector_), memName); + } else if (memType == "VMStubsTE:") { + addMemToVec(VMSTE_, new VMStubsTEMemory(memName, settings_, isector_), memName); + } else if (memType == "VMStubsME:") { + addMemToVec(VMSME_, new VMStubsMEMemory(memName, settings_, isector_), memName); + } else if (memType == "StubPairs:" || memType == "StubPairsDisplaced:") { + addMemToVec(SP_, new StubPairsMemory(memName, settings_, isector_), memName); + } else if (memType == "StubTriplets:") { + addMemToVec(ST_, new StubTripletsMemory(memName, settings_, isector_), memName); + } else if (memType == "TrackletParameters:") { + addMemToVec(TPAR_, new TrackletParametersMemory(memName, settings_, isector_), memName); + } else if (memType == "TrackletProjections:") { + addMemToVec(TPROJ_, new TrackletProjectionsMemory(memName, settings_, isector_), memName); + } else if (memType == "AllProj:") { + addMemToVec(AP_, new AllProjectionsMemory(memName, settings_, isector_), memName); + } else if (memType == "VMProjections:") { + addMemToVec(VMPROJ_, new VMProjectionsMemory(memName, settings_, isector_), memName); + } else if (memType == "CandidateMatch:") { + addMemToVec(CM_, new CandidateMatchMemory(memName, settings_, isector_), memName); + } else if (memType == "FullMatch:") { + addMemToVec(FM_, new FullMatchMemory(memName, settings_, isector_), memName); + } else if (memType == "TrackFit:") { + addMemToVec(TF_, new TrackFitMemory(memName, settings_, isector_, phimin_, phimax_), memName); + } else if (memType == "CleanTrack:") { + addMemToVec(CT_, new CleanTrackMemory(memName, settings_, isector_, phimin_, phimax_), memName); + } else { + edm::LogPrint("Tracklet") << "Don't know of memory type: " << memType; + exit(0); + } +} + +void Sector::addProc(string procType, string procName) { + if (procType == "VMRouter:") { + addProcToVec(VMR_, new VMRouter(procName, settings_, globals_, isector_), procName); + } else if (procType == "TrackletEngine:") { + addProcToVec(TE_, new TrackletEngine(procName, settings_, globals_, isector_), procName); + } else if (procType == "TrackletEngineDisplaced:") { + addProcToVec(TED_, new TrackletEngineDisplaced(procName, settings_, globals_, isector_), procName); + } else if (procType == "TripletEngine:") { + addProcToVec(TRE_, new TripletEngine(procName, settings_, globals_, isector_), procName); + } else if (procType == "TrackletCalculator:") { + addProcToVec(TC_, new TrackletCalculator(procName, settings_, globals_, isector_), procName); + } else if (procType == "TrackletProcessor:") { + addProcToVec(TP_, new TrackletProcessor(procName, settings_, globals_, isector_), procName); + } else if (procType == "TrackletCalculatorDisplaced:") { + addProcToVec(TCD_, new TrackletCalculatorDisplaced(procName, settings_, globals_, isector_), procName); + } else if (procType == "ProjectionRouter:") { + addProcToVec(PR_, new ProjectionRouter(procName, settings_, globals_, isector_), procName); + } else if (procType == "MatchEngine:") { + addProcToVec(ME_, new MatchEngine(procName, settings_, globals_, isector_), procName); + } else if (procType == "MatchCalculator:" || + procType == "DiskMatchCalculator:") { //TODO should not be used in configurations + addProcToVec(MC_, new MatchCalculator(procName, settings_, globals_, isector_), procName); + } else if (procType == "MatchProcessor:") { + addProcToVec(MP_, new MatchProcessor(procName, settings_, globals_, isector_), procName); + } else if (procType == "FitTrack:") { + addProcToVec(FT_, new FitTrack(procName, settings_, globals_, isector_), procName); + } else if (procType == "PurgeDuplicate:") { + addProcToVec(PD_, new PurgeDuplicate(procName, settings_, globals_, isector_), procName); + } else { + edm::LogPrint("Tracklet") << "Don't know of processing type: " << procType; + exit(0); + } +} + +void Sector::addWire(string mem, string procinfull, string procoutfull) { + stringstream ss1(procinfull); + string procin, output; + getline(ss1, procin, '.'); + getline(ss1, output); + + stringstream ss2(procoutfull); + string procout, input; + getline(ss2, procout, '.'); + getline(ss2, input); + + MemoryBase* memory = getMem(mem); + + if (!procin.empty()) { + ProcessBase* inProc = getProc(procin); + inProc->addOutput(memory, output); + } + + if (!procout.empty()) { + ProcessBase* outProc = getProc(procout); + outProc->addInput(memory, input); + } +} + +ProcessBase* Sector::getProc(string procName) { + auto it = Processes_.find(procName); + + if (it != Processes_.end()) { + return it->second.get(); + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find process : " << procName; + return nullptr; +} + +MemoryBase* Sector::getMem(string memName) { + auto it = Memories_.find(memName); + + if (it != Memories_.end()) { + return it->second.get(); + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find memory : " << memName; + return nullptr; +} + +void Sector::writeInputStubs(bool first) { + for (auto& i : IL_) { + i->writeStubs(first); + } +} + +void Sector::writeVMSTE(bool first) { + for (auto& i : VMSTE_) { + i->writeStubs(first); + } +} + +void Sector::writeVMSME(bool first) { + for (auto& i : VMSME_) { + i->writeStubs(first); + } +} + +void Sector::writeAS(bool first) { + for (auto& i : AS_) { + i->writeStubs(first); + } +} + +void Sector::writeSP(bool first) { + for (auto& i : SP_) { + i->writeSP(first); + } +} + +void Sector::writeST(bool first) { + for (auto& i : ST_) { + i->writeST(first); + } +} + +void Sector::writeTPAR(bool first) { + for (auto& i : TPAR_) { + i->writeTPAR(first); + } +} + +void Sector::writeTPROJ(bool first) { + for (auto& i : TPROJ_) { + i->writeTPROJ(first); + } +} + +void Sector::writeAP(bool first) { + for (auto& i : AP_) { + i->writeAP(first); + } +} + +void Sector::writeVMPROJ(bool first) { + for (auto& i : VMPROJ_) { + i->writeVMPROJ(first); + } +} + +void Sector::writeCM(bool first) { + for (auto& i : CM_) { + i->writeCM(first); + } +} + +void Sector::writeMC(bool first) { + for (auto& i : FM_) { + i->writeMC(first); + } +} + +void Sector::writeTF(bool first) { + for (auto& i : TF_) { + i->writeTF(first); + } +} + +void Sector::writeCT(bool first) { + for (auto& i : CT_) { + i->writeCT(first); + } +} + +void Sector::clean() { + if (settings_.writeMonitorData("NMatches")) { + int matchesL1 = 0; + int matchesL3 = 0; + int matchesL5 = 0; + for (auto& i : TPAR_) { + i->writeMatches(globals_, matchesL1, matchesL3, matchesL5); + } + globals_->ofstream("nmatchessector.txt") << matchesL1 << " " << matchesL3 << " " << matchesL5 << endl; + } + + for (auto& mem : MemoriesV_) { + mem->clean(); + } +} + +void Sector::executeVMR() { + if (settings_.writeMonitorData("IL")) { + ofstream& out = globals_->ofstream("inputlink.txt"); + for (auto& i : IL_) { + out << i->getName() << " " << i->nStubs() << endl; + } + } + for (auto& i : VMR_) { + i->execute(); + } +} + +void Sector::executeTE() { + for (auto& i : TE_) { + i->execute(); + } +} + +void Sector::executeTED() { + for (auto& i : TED_) { + i->execute(); + } +} + +void Sector::executeTRE() { + for (auto& i : TRE_) { + i->execute(); + } +} + +void Sector::executeTP() { + for (auto& i : TP_) { + i->execute(); + } +} + +void Sector::executeTC() { + for (auto& i : TC_) { + i->execute(); + } + + if (settings_.writeMonitorData("TrackProjOcc")) { + ofstream& out = globals_->ofstream("trackprojocc.txt"); + for (auto& i : TPROJ_) { + out << i->getName() << " " << i->nTracklets() << endl; + } + } +} + +void Sector::executeTCD() { + for (auto& i : TCD_) { + i->execute(); + } +} + +void Sector::executePR() { + for (auto& i : PR_) { + i->execute(); + } +} + +void Sector::executeME() { + for (auto& i : ME_) { + i->execute(); + } +} + +void Sector::executeMC() { + for (auto& i : MC_) { + i->execute(); + } +} + +void Sector::executeMP() { + for (auto& i : MP_) { + i->execute(); + } +} + +void Sector::executeFT() { + for (auto& i : FT_) { + i->execute(); + } +} + +void Sector::executePD(std::vector& tracks) { + for (auto& i : PD_) { + i->execute(tracks); + } +} + +std::vector Sector::getAllTracklets() const { + std::vector tmp; + for (auto tpar : TPAR_) { + for (unsigned int j = 0; j < tpar->nTracklets(); j++) { + tmp.push_back(tpar->getTracklet(j)); + } + } + return tmp; +} + +std::vector Sector::getStubs() const { + std::vector tmp; + + for (auto imem : IL_) { + for (unsigned int istub = 0; istub < imem->nStubs(); istub++) { + tmp.push_back(imem->getStub(istub)); + } + } + + return tmp; +} + +std::unordered_set Sector::seedMatch(int itp) const { + std::unordered_set tmpSeeds; + for (auto i : TPAR_) { + unsigned int nTracklet = i->nTracklets(); + for (unsigned int j = 0; j < nTracklet; j++) { + if (i->getTracklet(j)->tpseed() == itp) { + tmpSeeds.insert(i->getTracklet(j)->getISeed()); + } + } + } + return tmpSeeds; +} diff --git a/L1Trigger/TrackFindingTracklet/src/Stub.cc b/L1Trigger/TrackFindingTracklet/src/Stub.cc new file mode 100644 index 0000000000000..6fa8dc5b85753 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/Stub.cc @@ -0,0 +1,248 @@ +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" +#include "DataFormats/Math/interface/deltaPhi.h" + +#include + +using namespace std; +using namespace trklet; + +Stub::Stub(Settings const& settings) : settings_(settings) {} + +Stub::Stub(L1TStub& stub, Settings const& settings, double phiminsec, double phimaxsec) : settings_(settings) { + double r = stub.r(); + double z = stub.z(); + double sbend = stub.bend(); + + l1tstub_ = &stub; + + int bendbits = 4; + if (stub.isPSmodule()) + bendbits = 3; + + int ibend = bendencode(sbend, stub.isPSmodule()); + + bend_.set(ibend, bendbits, true, __LINE__, __FILE__); + + int layer = stub.layer() + 1; + + // hold the real values from L1Stub + double stubphi = stub.phi(); + + if (layer < 999) { + disk_.set(0, 4, false, __LINE__, __FILE__); + + assert(layer > 0 && layer <= N_LAYER); + double rmin = settings_.rmean(layer - 1) - settings_.drmax(); + double rmax = settings_.rmean(layer - 1) + settings_.drmax(); + + if (r < rmin || r > rmax) { + edm::LogProblem("Tracklet") << "Error r, rmin, rmeas, rmax :" << r << " " << rmin << " " << 0.5 * (rmin + rmax) + << " " << rmax; + } + + int irbits = settings_.nrbitsstub(layer - 1); + + int ir = lround((1 << irbits) * ((r - settings_.rmean(layer - 1)) / (rmax - rmin))); + + double zmin = -settings_.zlength(); + double zmax = settings_.zlength(); + + if (z < zmin || z > zmax) { + edm::LogProblem("Tracklet") << "Error z, zmin, zmax :" << z << " " << zmin << " " << zmax; + } + + int izbits = settings_.nzbitsstub(layer - 1); + + int iz = lround((1 << izbits) * z / (zmax - zmin)); + + if (z < zmin || z > zmax) { + edm::LogProblem("Tracklet") << "Error z, zmin, zmax :" << z << " " << zmin << " " << zmax; + } + + assert(phimaxsec - phiminsec > 0.0); + + if (stubphi < phiminsec - (phimaxsec - phiminsec) / 6.0) { + stubphi += 2 * M_PI; + } + assert((phimaxsec - phiminsec) > 0.0); + + int iphibits = settings_.nphibitsstub(layer - 1); + + double deltaphi = reco::reduceRange(stubphi - phiminsec); + + int iphi = (1 << iphibits) * deltaphi / (phimaxsec - phiminsec); + + layer_.set(layer - 1, 3, true, __LINE__, __FILE__); + r_.set(ir, irbits, false, __LINE__, __FILE__); + z_.set(iz, izbits, false, __LINE__, __FILE__); + phi_.set(iphi, iphibits, true, __LINE__, __FILE__); + + phicorr_.set(iphi, iphibits, true, __LINE__, __FILE__); + + } else { + // Here we handle the hits on disks. + + int disk = stub.module(); + assert(disk > 0 && disk <= N_DISK); + int sign = 1; + if (z < 0.0) + sign = -1; + + double zmin = sign * (settings_.zmean(disk - 1) - sign * settings_.dzmax()); + double zmax = sign * (settings_.zmean(disk - 1) + sign * settings_.dzmax()); + + if ((z > zmax) || (z < zmin)) { + edm::LogProblem("Tracklet") << "Error disk z, zmax, zmin: " << z << " " << zmax << " " << zmin; + } + + int iz = + (1 << settings.nzbitsstub(disk + N_DISK)) * ((z - sign * settings_.zmean(disk - 1)) / std::abs(zmax - zmin)); + + assert(phimaxsec - phiminsec > 0.0); + if (stubphi < phiminsec - (phimaxsec - phiminsec) / 6.0) { + stubphi += 2 * M_PI; + } + + assert(phimaxsec - phiminsec > 0.0); + if (stubphi < phiminsec - (phimaxsec - phiminsec) / 6.0) { + stubphi += 2 * M_PI; + } + + int iphibits = settings_.nphibitsstub(disk + 5); + + double deltaphi = reco::reduceRange(stubphi - phiminsec); + + int iphi = (1 << iphibits) * deltaphi / (phimaxsec - phiminsec); + + double rmin = 0; + double rmax = settings_.rmaxdisk(); + + if (r < rmin || r > rmax) { + edm::LogProblem("Tracklet") << "Error disk r, rmin, rmax :" << r << " " << rmin << " " << rmax; + } + + int ir = (1 << settings_.nrbitsstub(disk + 5)) * (r - rmin) / (rmax - rmin); + + int irSS = -1; + if (!stub.isPSmodule()) { + for (unsigned int i = 0; i < N_DSS_MOD * 2; ++i) { + if (disk <= 2) { + if (std::abs(r - settings_.rDSSinner(i)) < 0.2) { + irSS = i; + break; + } + } else { + if (std::abs(r - settings_.rDSSouter(i)) < 0.2) { + irSS = i; + break; + } + } + } + if (irSS < 0) { + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " didn't find rDSS value! r = " << r + << " Check that correct geometry is used!"; + } + } + if (irSS < 0) { + //PS modules + r_.set(ir, settings_.nrbitsstub(disk + N_DISK), true, __LINE__, __FILE__); + } else { + //SS modules + r_.set(irSS, 4, true, __LINE__, __FILE__); // in case of SS modules, store index, not r itself + } + + z_.set(iz, settings.nzbitsstub(disk + 5), false, __LINE__, __FILE__); + phi_.set(iphi, iphibits, true, __LINE__, __FILE__); + phicorr_.set(iphi, iphibits, true, __LINE__, __FILE__); + + disk_.set(sign * disk, 4, false, __LINE__, __FILE__); + + double alphanorm = stub.alphanorm(); + assert(std::abs(alphanorm) < 1.0); + int ialphanew = alphanorm * (1 << (settings.nbitsalpha() - 1)); + assert(ialphanew < (1 << (settings.nbitsalpha() - 1))); + assert(ialphanew >= -(1 << (settings.nbitsalpha() - 1))); + alphanew_.set(ialphanew, settings.nbitsalpha(), false, __LINE__, __FILE__); + } +} + +FPGAWord Stub::iphivmFineBins(int VMbits, int finebits) const { + unsigned int finephi = (phicorr_.value() >> (phicorr_.nbits() - VMbits - finebits)) & ((1 << finebits) - 1); + return FPGAWord(finephi, finebits, true, __LINE__, __FILE__); +} + +unsigned int Stub::phiregionaddress() const { + int iphi = (phicorr_.value() >> (phicorr_.nbits() - settings_.nbitsallstubs(layerdisk()))); + return (iphi << 7) + stubindex_.value(); +} + +std::string Stub::phiregionaddressstr() const { + int iphi = (phicorr_.value() >> (phicorr_.nbits() - settings_.nbitsallstubs(layerdisk()))); + FPGAWord phiregion(iphi, 3, true, __LINE__, __FILE__); + return phiregion.str() + stubindex_.str(); +} + +void Stub::setAllStubIndex(int nstub) { + if (nstub >= (1 << 7)) { + if (settings_.debugTracklet()) + edm::LogPrint("Tracklet") << "Warning too large stubindex!"; + nstub = (1 << 7) - 1; + } + + stubindex_.set(nstub, 7); +} + +void Stub::setPhiCorr(int phiCorr) { + int iphicorr = phi_.value() - phiCorr; + + if (iphicorr < 0) + iphicorr = 0; + if (iphicorr >= (1 << phi_.nbits())) + iphicorr = (1 << phi_.nbits()) - 1; + + phicorr_.set(iphicorr, phi_.nbits(), true, __LINE__, __FILE__); +} + +double Stub::rapprox() const { + if (disk_.value() == 0) { + int lr = 1 << (8 - settings_.nrbitsstub(layer_.value())); + return r_.value() * settings_.kr() * lr + settings_.rmean(layer_.value()); + } + return r_.value() * settings_.kr(); +} + +double Stub::zapprox() const { + if (disk_.value() == 0) { + int lz = 1; + if (layer_.value() >= 3) { + lz = 16; + } + return z_.value() * settings_.kz() * lz; + } + int sign = 1; + if (disk_.value() < 0) + sign = -1; + if (sign < 0) { + //Should understand why this is needed to get agreement with integer calculations + return (z_.value() + 1) * settings_.kz() + sign * settings_.zmean(abs(disk_.value()) - 1); + } else { + return z_.value() * settings_.kz() + sign * settings_.zmean(abs(disk_.value()) - 1); + } +} + +double Stub::phiapprox(double phimin, double) const { + int lphi = 1; + if (layer_.value() >= 3) { + lphi = 8; + } + return reco::reduceRange(phimin + phi_.value() * settings_.kphi() / lphi); +} + +unsigned int Stub::layerdisk() const { + if (layer_.value() == -1) + return 5 + abs(disk_.value()); + return layer_.value(); +} diff --git a/L1Trigger/TrackFindingTracklet/src/StubPairsMemory.cc b/L1Trigger/TrackFindingTracklet/src/StubPairsMemory.cc new file mode 100644 index 0000000000000..4f5e496ee1b94 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/StubPairsMemory.cc @@ -0,0 +1,40 @@ +#include "L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMStubTE.h" +#include + +using namespace std; +using namespace trklet; + +StubPairsMemory::StubPairsMemory(string name, Settings const& settings, unsigned int iSector) + : MemoryBase(name, settings, iSector) {} + +void StubPairsMemory::writeSP(bool first) { + std::ostringstream oss; + oss << "../data/MemPrints/StubPairs/StubPairs_" << getName() << "_" << std::setfill('0') << std::setw(2) + << (iSector_ + 1) << ".dat"; + auto const& fname = oss.str(); + + if (first) { + bx_ = 0; + event_ = 1; + out_.open(fname.c_str()); + } else + out_.open(fname.c_str(), std::ofstream::app); + + out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; + + for (unsigned int j = 0; j < stubs_.size(); j++) { + string stub1index = stubs_[j].first.stub()->stubindex().str(); + string stub2index = stubs_[j].second.stub()->stubindex().str(); + out_ << "0x"; + out_ << std::setfill('0') << std::setw(2); + out_ << hex << j << dec; + out_ << " " << stub1index << "|" << stub2index << " " << trklet::hexFormat(stub1index + stub2index) << endl; + } + out_.close(); + + bx_++; + event_++; + if (bx_ > 7) + bx_ = 0; +} diff --git a/L1Trigger/TrackFindingTracklet/src/StubTripletsMemory.cc b/L1Trigger/TrackFindingTracklet/src/StubTripletsMemory.cc new file mode 100644 index 0000000000000..e9a03d0546e9c --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/StubTripletsMemory.cc @@ -0,0 +1,41 @@ +#include "L1Trigger/TrackFindingTracklet/interface/StubTripletsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include + +using namespace std; +using namespace trklet; + +StubTripletsMemory::StubTripletsMemory(string name, Settings const& settings, unsigned int iSector) + : MemoryBase(name, settings, iSector) {} + +void StubTripletsMemory::writeST(bool first) { + std::ostringstream oss; + oss << "../data/MemPrints/StubPairs/StubTriplets_" << getName() << "_" << std::setfill('0') << std::setw(2) + << (iSector_ + 1) << ".dat"; + auto const& fname = oss.str(); + + if (first) { + bx_ = 0; + event_ = 1; + out_.open(fname.c_str()); + } else + out_.open(fname.c_str(), std::ofstream::app); + + out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; + + for (unsigned int j = 0; j < stubs1_.size(); j++) { + string stub1index = stubs1_[j]->stubindex().str(); + string stub2index = stubs2_[j]->stubindex().str(); + string stub3index = stubs3_[j]->stubindex().str(); + out_ << std::setfill('0') << std::setw(2); + out_ << hex << j << dec; + out_ << " " << stub1index << "|" << stub2index << "|" << stub3index << endl; + } + out_.close(); + + bx_++; + event_++; + if (bx_ > 7) + bx_ = 0; +} diff --git a/L1Trigger/TrackFindingTracklet/src/TETableBase.cc b/L1Trigger/TrackFindingTracklet/src/TETableBase.cc new file mode 100644 index 0000000000000..b28334bdf63ef --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/TETableBase.cc @@ -0,0 +1,30 @@ +#include "L1Trigger/TrackFindingTracklet/interface/TETableBase.h" + +using namespace std; +using namespace trklet; + +TETableBase::TETableBase(Settings const& settings) : settings_(settings) {} + +void TETableBase::writeVMTable(std::string name, bool positive) { + ofstream out; + out.open(name.c_str()); + out << "{" << endl; + for (unsigned int i = 0; i < table_.size(); i++) { + if (i != 0) { + out << "," << endl; + } + + assert(nbits_ > 0); + + int itable = table_[i]; + if (positive) { + if (table_[i] < 0) { + itable = (1 << nbits_) - 1; + } + } + + out << itable; + } + out << endl << "};" << endl; + out.close(); +} diff --git a/L1Trigger/TrackFindingTracklet/src/Timer.cc b/L1Trigger/TrackFindingTracklet/src/Timer.cc new file mode 100644 index 0000000000000..a9924c7fd21e9 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/Timer.cc @@ -0,0 +1,12 @@ +#include "L1Trigger/TrackFindingTracklet/interface/Timer.h" + +using namespace trklet; + +void Timer::start() { tstart_ = std::chrono::high_resolution_clock::now(); } +void Timer::stop() { + auto tstop = std::chrono::high_resolution_clock::now(); + double tmp = std::chrono::duration(tstop - tstart_).count(); + ttot_ += tmp; + ttotsq_ += tmp * tmp; + ntimes_++; +} diff --git a/L1Trigger/TrackFindingTracklet/src/Track.cc b/L1Trigger/TrackFindingTracklet/src/Track.cc new file mode 100644 index 0000000000000..51f3508189a27 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/Track.cc @@ -0,0 +1,52 @@ +#include "L1Trigger/TrackFindingTracklet/interface/Track.h" + +#include "DataFormats/Math/interface/deltaPhi.h" + +#include + +using namespace std; +using namespace trklet; + +Track::Track(TrackPars ipars, + int ichisqrphi, + int ichisqrz, + double chisqrphi, + double chisqrz, + int hitpattern, + std::map stubID, + const std::vector& l1stub, + int seed) { + ipars_ = ipars; + ichisqrphi_ = ichisqrphi; + ichisqrz_ = ichisqrz; + + chisqrphi_ = chisqrphi; + chisqrz_ = chisqrz; + + hitpattern_ = hitpattern; + + nstubs_ = std::max((int)l1stub.size(), (int)N_FITSTUB); + + stubID_ = stubID; + l1stub_ = l1stub; + + seed_ = seed; + duplicate_ = false; + sector_ = -1; +} + +double Track::phi0(Settings const& settings) const { + double dphi = 2 * M_PI / N_SECTOR; + double dphiHG = 0.5 * settings.dphisectorHG() - M_PI / N_SECTOR; + double phimin = sector_ * dphi - dphiHG; + double phimax = phimin + dphi + 2 * dphiHG; + phimin -= M_PI / N_SECTOR; + phimax -= M_PI / N_SECTOR; + phimin = reco::reduceRange(phimin); + phimax = reco::reduceRange(phimax); + if (phimin > phimax) + phimin -= 2 * M_PI; + double phioffset = phimin; + + return ipars_.phi0() * settings.kphi0pars() + phioffset; +} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackDer.cc b/L1Trigger/TrackFindingTracklet/src/TrackDer.cc new file mode 100644 index 0000000000000..2f8b02caba448 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/TrackDer.cc @@ -0,0 +1,88 @@ +#include "L1Trigger/TrackFindingTracklet/interface/TrackDer.h" + +using namespace std; +using namespace trklet; + +TrackDer::TrackDer() { + for (unsigned int i = 0; i < N_FITSTUB; i++) { + irinvdphi_[i] = 9999999; + irinvdzordr_[i] = 9999999; + iphi0dphi_[i] = 9999999; + iphi0dzordr_[i] = 9999999; + itdphi_[i] = 9999999; + itdzordr_[i] = 9999999; + iz0dphi_[i] = 9999999; + iz0dzordr_[i] = 9999999; + + rinvdphi_[i] = 0.0; + rinvdzordr_[i] = 0.0; + phi0dphi_[i] = 0.0; + phi0dzordr_[i] = 0.0; + tdphi_[i] = 0.0; + tdzordr_[i] = 0.0; + z0dphi_[i] = 0.0; + z0dzordr_[i] = 0.0; + } + + for (unsigned int i = 0; i < N_PSLAYER; i++) { + for (unsigned int j = 0; j < N_PSLAYER; j++) { + tdzcorr_[i][j] = 0.0; + z0dzcorr_[i][j] = 0.0; + } + } +} + +void TrackDer::setIndex(int layermask, int diskmask, int alphamask, int irinv) { + layermask_ = layermask; + diskmask_ = diskmask; + alphamask_ = alphamask; + irinv_ = irinv; +} + +void TrackDer::fill(int t, double MinvDt[N_FITPARAM][N_FITSTUB * 2], int iMinvDt[N_FITPARAM][N_FITSTUB * 2]) const { + unsigned int nlayer = 0; + if (layermask_ & 1) + nlayer++; + if (layermask_ & 2) + nlayer++; + if (layermask_ & 4) + nlayer++; + if (layermask_ & 8) + nlayer++; + if (layermask_ & 16) + nlayer++; + if (layermask_ & 32) + nlayer++; + int sign = 1; + if (t < 0) + sign = -1; + for (unsigned int i = 0; i < N_FITSTUB; i++) { + MinvDt[0][2 * i] = rinvdphi_[i]; + MinvDt[1][2 * i] = phi0dphi_[i]; + MinvDt[2][2 * i] = sign * tdphi_[i]; + MinvDt[3][2 * i] = sign * z0dphi_[i]; + MinvDt[0][2 * i + 1] = rinvdzordr_[i]; + MinvDt[1][2 * i + 1] = phi0dzordr_[i]; + MinvDt[2][2 * i + 1] = tdzordr_[i]; + MinvDt[3][2 * i + 1] = z0dzordr_[i]; + iMinvDt[0][2 * i] = irinvdphi_[i]; + iMinvDt[1][2 * i] = iphi0dphi_[i]; + iMinvDt[2][2 * i] = sign * itdphi_[i]; + iMinvDt[3][2 * i] = sign * iz0dphi_[i]; + iMinvDt[0][2 * i + 1] = irinvdzordr_[i]; + iMinvDt[1][2 * i + 1] = iphi0dzordr_[i]; + iMinvDt[2][2 * i + 1] = itdzordr_[i]; + iMinvDt[3][2 * i + 1] = iz0dzordr_[i]; + if (i < nlayer) { + MinvDt[0][2 * i + 1] *= sign; + MinvDt[1][2 * i + 1] *= sign; + iMinvDt[0][2 * i + 1] *= sign; + iMinvDt[1][2 * i + 1] *= sign; + } else { + MinvDt[2][2 * i + 1] *= sign; + MinvDt[3][2 * i + 1] *= sign; + iMinvDt[2][2 * i + 1] *= sign; + iMinvDt[3][2 * i + 1] *= sign; + } + } +} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackDerTable.cc b/L1Trigger/TrackFindingTracklet/src/TrackDerTable.cc new file mode 100644 index 0000000000000..a5d6668de19c1 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/TrackDerTable.cc @@ -0,0 +1,1048 @@ +#include "L1Trigger/TrackFindingTracklet/interface/TrackDerTable.h" +#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +using namespace std; +using namespace trklet; + +TrackDerTable::TrackDerTable(Settings const& settings) : settings_(settings) { + Nlay_ = N_LAYER; + Ndisk_ = N_DISK; + + LayerMemBits_ = 6; + DiskMemBits_ = 7; + LayerDiskMemBits_ = 18; + + alphaBits_ = settings_.alphaBitsTable(); + + nextLayerValue_ = 0; + nextDiskValue_ = 0; + nextLayerDiskValue_ = 0; + lastMultiplicity_ = (1 << (3 * alphaBits_)); + + for (int i = 0; i < (1 << Nlay_); i++) { + LayerMem_.push_back(-1); + } + + for (int i = 0; i < (1 << (2 * Ndisk_)); i++) { + DiskMem_.push_back(-1); + } + + for (int i = 0; i < (1 << (LayerMemBits_ + DiskMemBits_)); i++) { + LayerDiskMem_.push_back(-1); + } +} + +const TrackDer* TrackDerTable::getDerivatives(unsigned int layermask, + unsigned int diskmask, + unsigned int alphaindex, + unsigned int rinvindex) const { + int index = getIndex(layermask, diskmask); + if (index < 0) { + return nullptr; + } + return &derivatives_[index + alphaindex * (1 << settings_.nrinvBitsTable()) + rinvindex]; +} + +int TrackDerTable::getIndex(unsigned int layermask, unsigned int diskmask) const { + assert(layermask < LayerMem_.size()); + + assert(diskmask < DiskMem_.size()); + + int layercode = LayerMem_[layermask]; + int diskcode = DiskMem_[diskmask]; + + if (diskcode < 0 || layercode < 0) { + if (settings_.warnNoDer()) { + edm::LogPrint("Tracklet") << "layermask diskmask : " << layermask << " " << diskmask; + } + return -1; + } + + assert(layercode >= 0); + assert(layercode < (1 << LayerMemBits_)); + assert(diskcode >= 0); + assert(diskcode < (1 << DiskMemBits_)); + + int layerdiskaddress = layercode + (diskcode << LayerMemBits_); + + assert(layerdiskaddress >= 0); + assert(layerdiskaddress < (1 << (LayerMemBits_ + DiskMemBits_))); + + int address = LayerDiskMem_[layerdiskaddress]; + + if (address < 0) { + if (settings_.warnNoDer()) { + edm::LogVerbatim("Tracklet") << "layermask diskmask : " << layermask << " " << diskmask; + } + return -1; + } + + assert(address >= 0); + assert(address < (1 << LayerDiskMemBits_)); + + return address; +} + +void TrackDerTable::addEntry(unsigned int layermask, unsigned int diskmask, int multiplicity, int nrinv) { + assert(multiplicity <= (1 << (3 * alphaBits_))); + + assert(layermask < (unsigned int)(1 << Nlay_)); + + assert(diskmask < (unsigned int)(1 << (2 * Ndisk_))); + + if (LayerMem_[layermask] == -1) { + LayerMem_[layermask] = nextLayerValue_++; + } + if (DiskMem_[diskmask] == -1) { + DiskMem_[diskmask] = nextDiskValue_++; + } + + int layercode = LayerMem_[layermask]; + int diskcode = DiskMem_[diskmask]; + + assert(layercode >= 0); + assert(layercode < (1 << LayerMemBits_)); + assert(diskcode >= 0); + assert(diskcode < (1 << DiskMemBits_)); + + int layerdiskaddress = layercode + (diskcode << LayerMemBits_); + + assert(layerdiskaddress >= 0); + assert(layerdiskaddress < (1 << (LayerMemBits_ + DiskMemBits_))); + + int address = LayerDiskMem_[layerdiskaddress]; + + if (address != -1) { + edm::LogPrint("Tracklet") << "Duplicate entry: layermask=" << layermask << " diskmaks=" << diskmask; + } + + assert(address == -1); + + LayerDiskMem_[layerdiskaddress] = nextLayerDiskValue_; + + nextLayerDiskValue_ += multiplicity * nrinv; + + lastMultiplicity_ = multiplicity * nrinv; + + for (int i = 0; i < multiplicity; i++) { + for (int irinv = 0; irinv < nrinv; irinv++) { + TrackDer tmp; + tmp.setIndex(layermask, diskmask, i, irinv); + derivatives_.push_back(tmp); + } + } +} + +void TrackDerTable::readPatternFile(std::string fileName) { + ifstream in(fileName.c_str()); + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "reading fit pattern file " << fileName; + edm::LogVerbatim("Tracklet") << " flags (good/eof/fail/bad): " << in.good() << " " << in.eof() << " " << in.fail() + << " " << in.bad(); + } + + while (in.good()) { + std::string layerstr, diskstr; + int multiplicity; + + in >> layerstr >> diskstr >> multiplicity; + + //correct multiplicity if you dont want 3 bits of alpha. + if (alphaBits_ == 2) { + if (multiplicity == 8) + multiplicity = 4; + if (multiplicity == 64) + multiplicity = 16; + if (multiplicity == 512) + multiplicity = 64; + } + + if (alphaBits_ == 1) { + if (multiplicity == 8) + multiplicity = 2; + if (multiplicity == 64) + multiplicity = 4; + if (multiplicity == 512) + multiplicity = 8; + } + + if (!in.good()) + continue; + + char** tmpptr = nullptr; + + int layers = strtol(layerstr.c_str(), tmpptr, 2); + int disks = strtol(diskstr.c_str(), tmpptr, 2); + + addEntry(layers, disks, multiplicity, (1 << settings_.nrinvBitsTable())); + } +} + +void TrackDerTable::fillTable() { + int nentries = getEntries(); + + for (int i = 0; i < nentries; i++) { + TrackDer& der = derivatives_[i]; + int layermask = der.layerMask(); + int diskmask = der.diskMask(); + int alphamask = der.alphaMask(); + int irinv = der.irinv(); + + double rinv = (irinv - ((1 << (settings_.nrinvBitsTable() - 1)) - 0.5)) * settings_.rinvmax() / + (1 << (settings_.nrinvBitsTable() - 1)); + + bool print = false; + + if (print) { + edm::LogVerbatim("Tracklet") << "PRINT i " << i << " " << layermask << " " << diskmask << " " << alphamask << " " + << print; + } + + int nlayers = 0; + double r[N_LAYER]; + + for (unsigned l = 0; l < N_LAYER; l++) { + if (layermask & (1 << (N_LAYER - 1 - l))) { + r[nlayers] = settings_.rmean(l); + nlayers++; + } + } + + int ndisks = 0; + double z[N_DISK]; + double alpha[N_DISK]; + + double t = tpar(settings_, diskmask, layermask); + + for (unsigned d = 0; d < N_DISK; d++) { + if (diskmask & (3 << (2 * (N_DISK - 1 - d)))) { + z[ndisks] = settings_.zmean(d); + alpha[ndisks] = 0.0; + double r = settings_.zmean(d) / t; + double r2 = r * r; + if (diskmask & (1 << (2 * (N_DISK - 1 - d)))) { + if (alphaBits_ == 3) { + int ialpha = alphamask & 7; + alphamask = alphamask >> 3; + alpha[ndisks] = settings_.half2SmoduleWidth() * (ialpha - 3.5) / 4.0 / r2; + if (print) + edm::LogVerbatim("Tracklet") << "PRINT 3 alpha ialpha : " << alpha[ndisks] << " " << ialpha; + } + if (alphaBits_ == 2) { + int ialpha = alphamask & 3; + alphamask = alphamask >> 2; + alpha[ndisks] = settings_.half2SmoduleWidth() * (ialpha - 1.5) / 2.0 / r2; + } + if (alphaBits_ == 1) { + int ialpha = alphamask & 1; + alphamask = alphamask >> 1; + alpha[ndisks] = settings_.half2SmoduleWidth() * (ialpha - 0.5) / r2; + if (print) + edm::LogVerbatim("Tracklet") << "PRINT 1 alpha ialpha : " << alpha[ndisks] << " " << ialpha; + } + } + ndisks++; + } + } + + double D[N_FITPARAM][N_FITSTUB * 2]; + int iD[N_FITPARAM][N_FITSTUB * 2]; + double MinvDt[N_FITPARAM][N_FITSTUB * 2]; + double MinvDtDelta[N_FITPARAM][N_FITSTUB * 2]; + int iMinvDt[N_FITPARAM][N_FITSTUB * 2]; + double sigma[N_FITSTUB * 2]; + double kfactor[N_FITSTUB * 2]; + + if (print) { + edm::LogVerbatim("Tracklet") << "PRINT ndisks alpha[0] z[0] t: " << ndisks << " " << alpha[0] << " " << z[0] + << " " << t; + for (int iii = 0; iii < nlayers; iii++) { + edm::LogVerbatim("Tracklet") << "PRINT iii r: " << iii << " " << r[iii]; + } + } + + calculateDerivatives(settings_, nlayers, r, ndisks, z, alpha, t, rinv, D, iD, MinvDt, iMinvDt, sigma, kfactor); + + double delta = 0.1; + + for (int i = 0; i < nlayers; i++) { + if (r[i] > settings_.rPS2S()) + continue; + + r[i] += delta; + + calculateDerivatives( + settings_, nlayers, r, ndisks, z, alpha, t, rinv, D, iD, MinvDtDelta, iMinvDt, sigma, kfactor); + + for (int ii = 0; ii < nlayers; ii++) { + if (r[ii] > settings_.rPS2S()) + continue; + double tder = (MinvDtDelta[2][2 * ii + 1] - MinvDt[2][2 * ii + 1]) / delta; + int itder = (1 << (settings_.fittbitshift() + settings_.rcorrbits())) * tder * settings_.kr() * settings_.kz() / + settings_.ktpars(); + double zder = (MinvDtDelta[3][2 * ii + 1] - MinvDt[3][2 * ii + 1]) / delta; + int izder = (1 << (settings_.fitz0bitshift() + settings_.rcorrbits())) * zder * settings_.kr() * + settings_.kz() / settings_.kz0pars(); + der.settdzcorr(i, ii, tder); + der.setz0dzcorr(i, ii, zder); + der.setitdzcorr(i, ii, itder); + der.setiz0dzcorr(i, ii, izder); + } + + r[i] -= delta; + } + + if (print) { + edm::LogVerbatim("Tracklet") << "iMinvDt table build : " << iMinvDt[0][10] << " " << iMinvDt[1][10] << " " + << iMinvDt[2][10] << " " << iMinvDt[3][10] << " " << t << " " << nlayers << " " + << ndisks; + + std::string oss = "alpha :"; + for (int iii = 0; iii < ndisks; iii++) { + oss += " "; + oss += std::to_string(alpha[iii]); + } + edm::LogVerbatim("Tracklet") << oss; + oss = "z :"; + for (int iii = 0; iii < ndisks; iii++) { + oss += " "; + oss += std::to_string(z[iii]); + } + edm::LogVerbatim("Tracklet") << oss; + } + + if (print) { + edm::LogVerbatim("Tracklet") << "PRINT nlayers ndisks : " << nlayers << " " << ndisks; + } + + for (int j = 0; j < nlayers + ndisks; j++) { + der.settpar(t); + + //integer + assert(std::abs(iMinvDt[0][2 * j]) < (1 << 23)); + assert(std::abs(iMinvDt[0][2 * j + 1]) < (1 << 23)); + assert(std::abs(iMinvDt[1][2 * j]) < (1 << 23)); + assert(std::abs(iMinvDt[1][2 * j + 1]) < (1 << 23)); + assert(std::abs(iMinvDt[2][2 * j]) < (1 << 19)); + assert(std::abs(iMinvDt[2][2 * j + 1]) < (1 << 19)); + assert(std::abs(iMinvDt[3][2 * j]) < (1 << 19)); + assert(std::abs(iMinvDt[3][2 * j + 1]) < (1 << 19)); + + if (print) { + edm::LogVerbatim("Tracklet") << "PRINT i " << i << " " << j << " " << iMinvDt[1][2 * j] << " " + << std::abs(iMinvDt[1][2 * j]); + } + + der.setirinvdphi(j, iMinvDt[0][2 * j]); + der.setirinvdzordr(j, iMinvDt[0][2 * j + 1]); + der.setiphi0dphi(j, iMinvDt[1][2 * j]); + der.setiphi0dzordr(j, iMinvDt[1][2 * j + 1]); + der.setitdphi(j, iMinvDt[2][2 * j]); + der.setitdzordr(j, iMinvDt[2][2 * j + 1]); + der.setiz0dphi(j, iMinvDt[3][2 * j]); + der.setiz0dzordr(j, iMinvDt[3][2 * j + 1]); + //floating point + der.setrinvdphi(j, MinvDt[0][2 * j]); + der.setrinvdzordr(j, MinvDt[0][2 * j + 1]); + der.setphi0dphi(j, MinvDt[1][2 * j]); + der.setphi0dzordr(j, MinvDt[1][2 * j + 1]); + der.settdphi(j, MinvDt[2][2 * j]); + der.settdzordr(j, MinvDt[2][2 * j + 1]); + der.setz0dphi(j, MinvDt[3][2 * j]); + der.setz0dzordr(j, MinvDt[3][2 * j + 1]); + } + } + + if (settings_.writeTable()) { + ofstream outL("FitDerTableNew_LayerMem.txt"); + for (unsigned int i = 0; i < LayerMem_.size(); i++) { + FPGAWord tmp; + int tmp1 = LayerMem_[i]; + if (tmp1 < 0) + tmp1 = (1 << 6) - 1; + edm::LogVerbatim("Tracklet") << "i LayerMem_ : " << i << " " << tmp1; + tmp.set(tmp1, 6, true, __LINE__, __FILE__); + outL << tmp.str() << endl; + } + outL.close(); + + ofstream outD("FitDerTableNew_DiskMem.txt"); + for (int tmp1 : DiskMem_) { + if (tmp1 < 0) + tmp1 = (1 << 7) - 1; + FPGAWord tmp; + tmp.set(tmp1, 7, true, __LINE__, __FILE__); + outD << tmp.str() << endl; + } + outD.close(); + + ofstream outLD("FitDerTableNew_LayerDiskMem.txt"); + for (int tmp1 : LayerDiskMem_) { + if (tmp1 < 0) + tmp1 = (1 << 10) - 1; + FPGAWord tmp; + tmp.set(tmp1, 10, true, __LINE__, __FILE__); + outLD << tmp.str() << endl; + } + outLD.close(); + + unsigned int nderivatives = derivatives_.size(); + edm::LogVerbatim("Tracklet") << "nderivatives = " << nderivatives; + + const std::array seedings = {{"L1L2", "L3L4", "L5L6", "D1D2", "D3D4", "D1L1", "D1L2"}}; + const string prefix = "FitDerTableNew_"; + + // open files for derivative tables + ofstream outrinvdphi[N_TRKLSEED]; + for (unsigned int i = 0; i < N_TRKLSEED; ++i) { + const string fname = prefix + "Rinvdphi_" + seedings[i] + ".txt"; + outrinvdphi[i].open(fname.c_str()); + } + + ofstream outrinvdzordr[N_TRKLSEED]; + for (unsigned int i = 0; i < N_TRKLSEED; ++i) { + const string fname = prefix + "Rinvdzordr_" + seedings[i] + ".txt"; + outrinvdzordr[i].open(fname.c_str()); + } + + ofstream outphi0dphi[N_TRKLSEED]; + for (unsigned int i = 0; i < N_TRKLSEED; ++i) { + const string fname = prefix + "Phi0dphi_" + seedings[i] + ".txt"; + outphi0dphi[i].open(fname.c_str()); + } + + ofstream outphi0dzordr[N_TRKLSEED]; + for (unsigned int i = 0; i < N_TRKLSEED; ++i) { + const string fname = prefix + "Phi0dzordr_" + seedings[i] + ".txt"; + outphi0dzordr[i].open(fname.c_str()); + } + + ofstream outtdphi[N_TRKLSEED]; + for (unsigned int i = 0; i < N_TRKLSEED; ++i) { + const string fname = prefix + "Tdphi_" + seedings[i] + ".txt"; + outtdphi[i].open(fname.c_str()); + } + + ofstream outtdzordr[N_TRKLSEED]; + for (unsigned int i = 0; i < N_TRKLSEED; ++i) { + const string fname = prefix + "Tdzordr_" + seedings[i] + ".txt"; + outtdzordr[i].open(fname.c_str()); + } + + ofstream outz0dphi[N_TRKLSEED]; + for (unsigned int i = 0; i < N_TRKLSEED; ++i) { + const string fname = prefix + "Z0dphi_" + seedings[i] + ".txt"; + outz0dphi[i].open(fname.c_str()); + } + + ofstream outz0dzordr[N_TRKLSEED]; + for (unsigned int i = 0; i < N_TRKLSEED; ++i) { + string fname = prefix + "Z0dzordr_" + seedings[i] + ".txt"; + outz0dzordr[i].open(fname.c_str()); + } + + for (auto& der : derivatives_) { + unsigned int layerhits = der.layerMask(); // 6 bits layer hit pattern + unsigned int diskmask = der.diskMask(); // 10 bits disk hit pattern + unsigned int diskhits = 0; + if (diskmask & (3 << 8)) + diskhits += 16; + if (diskmask & (3 << 6)) + diskhits += 8; + if (diskmask & (3 << 4)) + diskhits += 4; + if (diskmask & (3 << 2)) + diskhits += 2; + if (diskmask & (3 << 0)) + diskhits += 1; + assert(diskhits < 32); // 5 bits + unsigned int hits = (layerhits << 5) + diskhits; // 11 bits hit pattern + assert(hits < 4096); + + // loop over all seedings + int i = 0; // seeding index + for (const string& seed : seedings) { + unsigned int iseed1 = 0; + unsigned int iseed2 = 0; + // check if the seeding is good for the current hit pattern + if (seed == "L1L2") { + iseed1 = 1; + iseed2 = 2; + } + if (seed == "L3L4") { + iseed1 = 3; + iseed2 = 4; + } + if (seed == "L5L6") { + iseed1 = 5; + iseed2 = 6; + } + if (seed == "D1D2") { + iseed1 = 7; + iseed2 = 8; + } + if (seed == "D3D4") { + iseed1 = 9; + iseed2 = 10; + } + if (seed == "D1L1") { + iseed1 = 7; + iseed2 = 1; + } + if (seed == "D1L2") { + iseed1 = 7; + iseed2 = 2; + } + + bool goodseed = (hits & (1 << (11 - iseed1))) and (hits & (1 << (11 - iseed2))); + + int itmprinvdphi[N_PROJ] = {9999999, 9999999, 9999999, 9999999}; + int itmprinvdzordr[N_PROJ] = {9999999, 9999999, 9999999, 9999999}; + int itmpphi0dphi[N_PROJ] = {9999999, 9999999, 9999999, 9999999}; + int itmpphi0dzordr[N_PROJ] = {9999999, 9999999, 9999999, 9999999}; + int itmptdphi[N_PROJ] = {9999999, 9999999, 9999999, 9999999}; + int itmptdzordr[N_PROJ] = {9999999, 9999999, 9999999, 9999999}; + int itmpz0dphi[N_PROJ] = {9999999, 9999999, 9999999, 9999999}; + int itmpz0dzordr[N_PROJ] = {9999999, 9999999, 9999999, 9999999}; + + // loop over bits in hit pattern + int ider = 0; + if (goodseed) { + for (unsigned int ihit = 1; ihit < N_FITSTUB * 2; ++ihit) { + // skip seeding layers + if (ihit == iseed1 or ihit == iseed2) { + ider++; + continue; + } + // skip if no hit + if (not(hits & (1 << (11 - ihit)))) + continue; + + int inputI = -1; + if (seed == "L1L2") { + if (ihit == 3 or ihit == 10) + inputI = 0; // L3 or D4 + if (ihit == 4 or ihit == 9) + inputI = 1; // L4 or D3 + if (ihit == 5 or ihit == 8) + inputI = 2; // L5 or D2 + if (ihit == 6 or ihit == 7) + inputI = 3; // L6 or D1 + } else if (seed == "L3L4") { + if (ihit == 1) + inputI = 0; // L1 + if (ihit == 2) + inputI = 1; // L2 + if (ihit == 5 or ihit == 8) + inputI = 2; // L5 or D2 + if (ihit == 6 or ihit == 7) + inputI = 3; // L6 or D1 + } else if (seed == "L5L6") { + if (ihit == 1) + inputI = 0; // L1 + if (ihit == 2) + inputI = 1; // L2 + if (ihit == 3) + inputI = 2; // L3 + if (ihit == 4) + inputI = 3; // L4 + } else if (seed == "D1D2") { + if (ihit == 1) + inputI = 0; // L1 + if (ihit == 9) + inputI = 1; // D3 + if (ihit == 10) + inputI = 2; // D4 + if (ihit == 2 or ihit == 11) + inputI = 3; // L2 or D5 + } else if (seed == "D3D4") { + if (ihit == 1) + inputI = 0; // L1 + if (ihit == 7) + inputI = 1; // D1 + if (ihit == 8) + inputI = 2; // D2 + if (ihit == 2 or ihit == 11) + inputI = 3; // L2 or D5 + } else if (seed == "D1L1" or "D1L2") { + if (ihit == 8) + inputI = 0; // D2 + if (ihit == 9) + inputI = 1; // D3 + if (ihit == 10) + inputI = 2; // D4 + if (ihit == 11) + inputI = 3; // D5 + } + if (inputI >= 0 and inputI < (int)N_PROJ) { + itmprinvdphi[inputI] = der.irinvdphi(ider); + itmprinvdzordr[inputI] = der.irinvdzordr(ider); + itmpphi0dphi[inputI] = der.iphi0dphi(ider); + itmpphi0dzordr[inputI] = der.iphi0dzordr(ider); + itmptdphi[inputI] = der.itdphi(ider); + itmptdzordr[inputI] = der.itdzordr(ider); + itmpz0dphi[inputI] = der.iz0dphi(ider); + itmpz0dzordr[inputI] = der.iz0dzordr(ider); + } + + ider++; + + } // for (unsigned int ihit = 1; ihit < 12; ++ihit) + } // if (goodseed) + + FPGAWord tmprinvdphi[N_PROJ]; + for (unsigned int j = 0; j < N_PROJ; ++j) { + if (itmprinvdphi[j] > (1 << 13)) + itmprinvdphi[j] = (1 << 13) - 1; + tmprinvdphi[j].set(itmprinvdphi[j], 14, false, __LINE__, __FILE__); + } + outrinvdphi[i] << tmprinvdphi[0].str() << tmprinvdphi[1].str() << tmprinvdphi[2].str() << tmprinvdphi[3].str() + << endl; + + FPGAWord tmprinvdzordr[N_PROJ]; + for (unsigned int j = 0; j < N_PROJ; ++j) { + if (itmprinvdzordr[j] > (1 << 15)) + itmprinvdzordr[j] = (1 << 15) - 1; + tmprinvdzordr[j].set(itmprinvdzordr[j], 16, false, __LINE__, __FILE__); + } + outrinvdzordr[i] << tmprinvdzordr[0].str() << tmprinvdzordr[1].str() << tmprinvdzordr[2].str() + << tmprinvdzordr[3].str() << endl; + + FPGAWord tmpphi0dphi[N_PROJ]; + for (unsigned int j = 0; j < N_PROJ; ++j) { + if (itmpphi0dphi[j] > (1 << 13)) + itmpphi0dphi[j] = (1 << 13) - 1; + tmpphi0dphi[j].set(itmpphi0dphi[j], 14, false, __LINE__, __FILE__); + } + outphi0dphi[i] << tmpphi0dphi[0].str() << tmpphi0dphi[1].str() << tmpphi0dphi[2].str() << tmpphi0dphi[3].str() + << endl; + + FPGAWord tmpphi0dzordr[N_PROJ]; + for (unsigned int j = 0; j < N_PROJ; ++j) { + if (itmpphi0dzordr[j] > (1 << 15)) + itmpphi0dzordr[j] = (1 << 15) - 1; + tmpphi0dzordr[j].set(itmpphi0dzordr[j], 16, false, __LINE__, __FILE__); + } + outphi0dzordr[i] << tmpphi0dzordr[0].str() << tmpphi0dzordr[1].str() << tmpphi0dzordr[2].str() + << tmpphi0dzordr[3].str() << endl; + + FPGAWord tmptdphi[N_PROJ]; + for (unsigned int j = 0; j < N_PROJ; ++j) { + if (itmptdphi[j] > (1 << 13)) + itmptdphi[j] = (1 << 13) - 1; + tmptdphi[j].set(itmptdphi[j], 14, false, __LINE__, __FILE__); + } + outtdphi[i] << tmptdphi[0].str() << tmptdphi[1].str() << tmptdphi[2].str() << tmptdphi[3].str() << endl; + + FPGAWord tmptdzordr[N_PROJ]; + for (unsigned int j = 0; j < N_PROJ; ++j) { + if (itmptdzordr[j] > (1 << 15)) + itmptdzordr[j] = (1 << 15) - 1; + tmptdzordr[j].set(itmptdzordr[j], 16, false, __LINE__, __FILE__); + } + outtdzordr[i] << tmptdzordr[0].str() << tmptdzordr[1].str() << tmptdzordr[2].str() << tmptdzordr[3].str() + << endl; + + FPGAWord tmpz0dphi[N_PROJ]; + for (unsigned int j = 0; j < N_PROJ; ++j) { + if (itmpz0dphi[j] > (1 << 13)) + itmpz0dphi[j] = (1 << 13) - 1; + tmpz0dphi[j].set(itmpz0dphi[j], 14, false, __LINE__, __FILE__); + } + outz0dphi[i] << tmpz0dphi[0].str() << tmpz0dphi[1].str() << tmpz0dphi[2].str() << tmpz0dphi[3].str() << endl; + + FPGAWord tmpz0dzordr[N_PROJ]; + for (unsigned int j = 0; j < N_PROJ; ++j) { + if (itmpz0dzordr[j] > (1 << 15)) + itmpz0dzordr[j] = (1 << 15) - 1; + tmpz0dzordr[j].set(itmpz0dzordr[j], 16, false, __LINE__, __FILE__); + } + outz0dzordr[i] << tmpz0dzordr[0].str() << tmpz0dzordr[1].str() << tmpz0dzordr[2].str() << tmpz0dzordr[3].str() + << endl; + + i++; + } // for (const string & seed : seedings) + + } // for (auto & der : derivatives_) + + // close files + for (unsigned int i = 0; i < N_TRKLSEED; ++i) { + outrinvdphi[i].close(); + outrinvdzordr[i].close(); + outphi0dphi[i].close(); + outphi0dzordr[i].close(); + outtdphi[i].close(); + outtdzordr[i].close(); + outz0dphi[i].close(); + outz0dzordr[i].close(); + } + + } // if (writeFitDerTable) +} + +void TrackDerTable::invert(double M[4][8], unsigned int n) { + assert(n <= 4); + + unsigned int i, j, k; + double ratio, a; + + for (i = 0; i < n; i++) { + for (j = n; j < 2 * n; j++) { + if (i == (j - n)) + M[i][j] = 1.0; + else + M[i][j] = 0.0; + } + } + + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (i != j) { + ratio = M[j][i] / M[i][i]; + for (k = 0; k < 2 * n; k++) { + M[j][k] -= ratio * M[i][k]; + } + } + } + } + + for (i = 0; i < n; i++) { + a = M[i][i]; + for (j = 0; j < 2 * n; j++) { + M[i][j] /= a; + } + } +} + +void TrackDerTable::invert(std::vector >& M, unsigned int n) { + assert(M.size() == n); + assert(M[0].size() == 2 * n); + + unsigned int i, j, k; + double ratio, a; + + for (i = 0; i < n; i++) { + for (j = n; j < 2 * n; j++) { + if (i == (j - n)) + M[i][j] = 1.0; + else + M[i][j] = 0.0; + } + } + + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + if (i != j) { + ratio = M[j][i] / M[i][i]; + for (k = 0; k < 2 * n; k++) { + M[j][k] -= ratio * M[i][k]; + } + } + } + } + + for (i = 0; i < n; i++) { + a = M[i][i]; + for (j = 0; j < 2 * n; j++) { + M[i][j] /= a; + } + } +} + +void TrackDerTable::calculateDerivatives(Settings const& settings, + unsigned int nlayers, + double r[N_LAYER], + unsigned int ndisks, + double z[N_DISK], + double alpha[N_DISK], + double t, + double rinv, + double D[N_FITPARAM][N_FITSTUB * 2], + int iD[N_FITPARAM][N_FITSTUB * 2], + double MinvDt[N_FITPARAM][N_FITSTUB * 2], + int iMinvDt[N_FITPARAM][N_FITSTUB * 2], + double sigma[N_FITSTUB * 2], + double kfactor[N_FITSTUB * 2]) { + double sigmax = settings.stripPitch(true) / sqrt(12.0); + double sigmaz = settings.stripLength(true) / sqrt(12.0); + double sigmaz2 = settings.stripLength(false) / sqrt(12.0); + + double sigmazpsbarrel = sigmaz; //This is a bit of a hack - these weights should be properly determined + if (std::abs(t) > 2.0) + sigmazpsbarrel = sigmaz * std::abs(t) / 2.0; + if (std::abs(t) > 3.8) + sigmazpsbarrel = sigmaz * std::abs(t); + + double sigmax2sdisk = settings.stripPitch(false) / sqrt(12.0); + double sigmaz2sdisk = settings.stripLength(false) / sqrt(12.0); + + double sigmaxpsdisk = settings.stripPitch(true) / sqrt(12.0); + double sigmazpsdisk = settings.stripLength(true) / sqrt(12.0); + + unsigned int n = nlayers + ndisks; + + assert(n <= N_FITSTUB); + + double rnew[N_FITSTUB]; + + int j = 0; + + //here we handle a barrel hit + for (unsigned int i = 0; i < nlayers; i++) { + double ri = r[i]; + + rnew[i] = ri; + + //first we have the phi position + D[0][j] = -0.5 * ri * ri / sqrt(1 - 0.25 * ri * ri * rinv * rinv) / sigmax; + D[1][j] = ri / sigmax; + D[2][j] = 0.0; + D[3][j] = 0.0; + sigma[j] = sigmax; + kfactor[j] = settings.kphi1(); + j++; + //second the z position + D[0][j] = 0.0; + D[1][j] = 0.0; + if (ri < settings.rPS2S()) { + D[2][j] = (2 / rinv) * asin(0.5 * ri * rinv) / sigmazpsbarrel; + D[3][j] = 1.0 / sigmazpsbarrel; + sigma[j] = sigmazpsbarrel; + kfactor[j] = settings.kz(); + } else { + D[2][j] = (2 / rinv) * asin(0.5 * ri * rinv) / sigmaz2; + D[3][j] = 1.0 / sigmaz2; + sigma[j] = sigmaz2; + kfactor[j] = settings.kz(); + } + + j++; + } + + for (unsigned int i = 0; i < ndisks; i++) { + double zi = z[i]; + + double z0 = 0.0; + + double rmultiplier = alpha[i] * zi / t; + + double phimultiplier = zi / t; + + double drdrinv = -2.0 * sin(0.5 * rinv * (zi - z0) / t) / (rinv * rinv) + + (zi - z0) * cos(0.5 * rinv * (zi - z0) / t) / (rinv * t); + double drdphi0 = 0; + double drdt = -(zi - z0) * cos(0.5 * rinv * (zi - z0) / t) / (t * t); + double drdz0 = -cos(0.5 * rinv * (zi - z0) / t) / t; + + double dphidrinv = -0.5 * (zi - z0) / t; + double dphidphi0 = 1.0; + double dphidt = 0.5 * rinv * (zi - z0) / (t * t); + double dphidz0 = 0.5 * rinv / t; + + double r = (zi - z0) / t; + + rnew[i + nlayers] = r; + + sigma[j] = sigmax2sdisk; + if (std::abs(alpha[i]) < 1e-10) { + sigma[j] = sigmaxpsdisk; + } + + D[0][j] = (phimultiplier * dphidrinv + rmultiplier * drdrinv) / sigma[j]; + D[1][j] = (phimultiplier * dphidphi0 + rmultiplier * drdphi0) / sigma[j]; + D[2][j] = (phimultiplier * dphidt + rmultiplier * drdt) / sigma[j]; + D[3][j] = (phimultiplier * dphidz0 + rmultiplier * drdz0) / sigma[j]; + kfactor[j] = settings.kphi(); + + j++; + + if (std::abs(alpha[i]) < 1e-10) { + D[0][j] = drdrinv / sigmazpsdisk; + D[1][j] = drdphi0 / sigmazpsdisk; + D[2][j] = drdt / sigmazpsdisk; + D[3][j] = drdz0 / sigmazpsdisk; + sigma[j] = sigmazpsdisk; + kfactor[j] = settings.kr(); + } else { + D[0][j] = drdrinv / sigmaz2sdisk; + D[1][j] = drdphi0 / sigmaz2sdisk; + D[2][j] = drdt / sigmaz2sdisk; + D[3][j] = drdz0 / sigmaz2sdisk; + sigma[j] = sigmaz2sdisk; + kfactor[j] = settings.kr(); + } + + j++; + } + + double M[4][8]; + + for (unsigned int i1 = 0; i1 < 4; i1++) { + for (unsigned int i2 = 0; i2 < 4; i2++) { + M[i1][i2] = 0.0; + for (unsigned int j = 0; j < 2 * n; j++) { + M[i1][i2] += D[i1][j] * D[i2][j]; + } + } + } + + invert(M, 4); + + for (unsigned int j = 0; j < N_FITSTUB * 2; j++) { + for (unsigned int i1 = 0; i1 < N_FITPARAM; i1++) { + MinvDt[i1][j] = 0.0; + iMinvDt[i1][j] = 0; + } + } + + for (unsigned int j = 0; j < 2 * n; j++) { + for (unsigned int i1 = 0; i1 < 4; i1++) { + for (unsigned int i2 = 0; i2 < 4; i2++) { + MinvDt[i1][j] += M[i1][i2 + 4] * D[i2][j]; + } + } + } + + for (unsigned int i = 0; i < n; i++) { + iD[0][2 * i] = + D[0][2 * i] * (1 << settings.chisqphifactbits()) * settings.krinvpars() / (1 << settings.fitrinvbitshift()); + iD[1][2 * i] = + D[1][2 * i] * (1 << settings.chisqphifactbits()) * settings.kphi0pars() / (1 << settings.fitphi0bitshift()); + iD[2][2 * i] = + D[2][2 * i] * (1 << settings.chisqphifactbits()) * settings.ktpars() / (1 << settings.fittbitshift()); + iD[3][2 * i] = + D[3][2 * i] * (1 << settings.chisqphifactbits()) * settings.kz0pars() / (1 << settings.fitz0bitshift()); + + iD[0][2 * i + 1] = + D[0][2 * i + 1] * (1 << settings.chisqzfactbits()) * settings.krinvpars() / (1 << settings.fitrinvbitshift()); + iD[1][2 * i + 1] = + D[1][2 * i + 1] * (1 << settings.chisqzfactbits()) * settings.kphi0pars() / (1 << settings.fitphi0bitshift()); + iD[2][2 * i + 1] = + D[2][2 * i + 1] * (1 << settings.chisqzfactbits()) * settings.ktpars() / (1 << settings.fittbitshift()); + iD[3][2 * i + 1] = + D[3][2 * i + 1] * (1 << settings.chisqzfactbits()) * settings.kz0pars() / (1 << settings.fitz0bitshift()); + + //First the barrel + if (i < nlayers) { + MinvDt[0][2 * i] *= rnew[i] / sigmax; + MinvDt[1][2 * i] *= rnew[i] / sigmax; + MinvDt[2][2 * i] *= rnew[i] / sigmax; + MinvDt[3][2 * i] *= rnew[i] / sigmax; + + iMinvDt[0][2 * i] = + (1 << settings.fitrinvbitshift()) * MinvDt[0][2 * i] * settings.kphi1() / settings.krinvpars(); + iMinvDt[1][2 * i] = + (1 << settings.fitphi0bitshift()) * MinvDt[1][2 * i] * settings.kphi1() / settings.kphi0pars(); + iMinvDt[2][2 * i] = (1 << settings.fittbitshift()) * MinvDt[2][2 * i] * settings.kphi1() / settings.ktpars(); + iMinvDt[3][2 * i] = (1 << settings.fitz0bitshift()) * MinvDt[3][2 * i] * settings.kphi1() / settings.kz0pars(); + + if (rnew[i] < settings.rPS2S()) { + MinvDt[0][2 * i + 1] /= sigmazpsbarrel; + MinvDt[1][2 * i + 1] /= sigmazpsbarrel; + MinvDt[2][2 * i + 1] /= sigmazpsbarrel; + MinvDt[3][2 * i + 1] /= sigmazpsbarrel; + + iMinvDt[0][2 * i + 1] = + (1 << settings.fitrinvbitshift()) * MinvDt[0][2 * i + 1] * settings.kz() / settings.krinvpars(); + iMinvDt[1][2 * i + 1] = + (1 << settings.fitphi0bitshift()) * MinvDt[1][2 * i + 1] * settings.kz() / settings.kphi0pars(); + iMinvDt[2][2 * i + 1] = + (1 << settings.fittbitshift()) * MinvDt[2][2 * i + 1] * settings.kz() / settings.ktpars(); + iMinvDt[3][2 * i + 1] = + (1 << settings.fitz0bitshift()) * MinvDt[3][2 * i + 1] * settings.kz() / settings.kz0pars(); + } else { + MinvDt[0][2 * i + 1] /= sigmaz2; + MinvDt[1][2 * i + 1] /= sigmaz2; + MinvDt[2][2 * i + 1] /= sigmaz2; + MinvDt[3][2 * i + 1] /= sigmaz2; + + int fact = (1 << (settings.nzbitsstub(0) - settings.nzbitsstub(5))); + + iMinvDt[0][2 * i + 1] = + (1 << settings.fitrinvbitshift()) * MinvDt[0][2 * i + 1] * fact * settings.kz() / settings.krinvpars(); + iMinvDt[1][2 * i + 1] = + (1 << settings.fitphi0bitshift()) * MinvDt[1][2 * i + 1] * fact * settings.kz() / settings.kphi0pars(); + iMinvDt[2][2 * i + 1] = + (1 << settings.fittbitshift()) * MinvDt[2][2 * i + 1] * fact * settings.kz() / settings.ktpars(); + iMinvDt[3][2 * i + 1] = + (1 << settings.fitz0bitshift()) * MinvDt[3][2 * i + 1] * fact * settings.kz() / settings.kz0pars(); + } + } + + //Secondly the disks + else { + double denom = (std::abs(alpha[i - nlayers]) < 1e-10) ? sigmaxpsdisk : sigmax2sdisk; + + MinvDt[0][2 * i] *= (rnew[i] / denom); + MinvDt[1][2 * i] *= (rnew[i] / denom); + MinvDt[2][2 * i] *= (rnew[i] / denom); + MinvDt[3][2 * i] *= (rnew[i] / denom); + + assert(MinvDt[0][2 * i] == MinvDt[0][2 * i]); + + iMinvDt[0][2 * i] = (1 << settings.fitrinvbitshift()) * MinvDt[0][2 * i] * settings.kphi() / settings.krinvpars(); + iMinvDt[1][2 * i] = (1 << settings.fitphi0bitshift()) * MinvDt[1][2 * i] * settings.kphi() / settings.kphi0pars(); + iMinvDt[2][2 * i] = (1 << settings.fittbitshift()) * MinvDt[2][2 * i] * settings.kphi() / settings.ktpars(); + iMinvDt[3][2 * i] = (1 << settings.fitz0bitshift()) * MinvDt[3][2 * i] * settings.kphi() / settings.kz(); + + denom = (std::abs(alpha[i - nlayers]) < 1e-10) ? sigmazpsdisk : sigmaz2sdisk; + + MinvDt[0][2 * i + 1] /= denom; + MinvDt[1][2 * i + 1] /= denom; + MinvDt[2][2 * i + 1] /= denom; + MinvDt[3][2 * i + 1] /= denom; + + iMinvDt[0][2 * i + 1] = + (1 << settings.fitrinvbitshift()) * MinvDt[0][2 * i + 1] * settings.krprojshiftdisk() / settings.krinvpars(); + iMinvDt[1][2 * i + 1] = + (1 << settings.fitphi0bitshift()) * MinvDt[1][2 * i + 1] * settings.krprojshiftdisk() / settings.kphi0pars(); + iMinvDt[2][2 * i + 1] = + (1 << settings.fittbitshift()) * MinvDt[2][2 * i + 1] * settings.krprojshiftdisk() / settings.ktpars(); + iMinvDt[3][2 * i + 1] = + (1 << settings.fitz0bitshift()) * MinvDt[3][2 * i + 1] * settings.krprojshiftdisk() / settings.kz(); + } + } +} + +double TrackDerTable::tpar(Settings const& settings, int diskmask, int layermask) { + if (diskmask == 0) + return 0.0; + + double tmax = 1000.0; + double tmin = 0.0; + + for (int d = 1; d <= (int)N_DISK; d++) { + if (diskmask & (1 << (2 * (5 - d) + 1))) { //PS hit + double dmax = settings.zmean(d - 1) / 22.0; + if (dmax > sinh(2.4)) + dmax = sinh(2.4); + double dmin = settings.zmean(d - 1) / 65.0; + if (dmax < tmax) + tmax = dmax; + if (dmin > tmin) + tmin = dmin; + } + + if (diskmask & (1 << (2 * (5 - d)))) { //2S hit + double dmax = settings.zmean(d - 1) / 65.0; + double dmin = settings.zmean(d - 1) / 105.0; + if (dmax < tmax) + tmax = dmax; + if (dmin > tmin) + tmin = dmin; + } + } + + for (int l = 1; l <= (int)N_LAYER; l++) { + if (layermask & (1 << (6 - l))) { + double lmax = settings.zlength() / settings.rmean(l - 1); + if (lmax < tmax) + tmax = lmax; + } + } + + return 0.5 * (tmax + tmin) * 1.07; +} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackFitMemory.cc b/L1Trigger/TrackFindingTracklet/src/TrackFitMemory.cc new file mode 100644 index 0000000000000..83f046180274d --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/TrackFitMemory.cc @@ -0,0 +1,43 @@ +#include "L1Trigger/TrackFindingTracklet/interface/TrackFitMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h" +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" +#include + +using namespace std; +using namespace trklet; + +TrackFitMemory::TrackFitMemory(string name, Settings const& settings, unsigned int iSector, double phimin, double phimax) + : MemoryBase(name, settings, iSector) { + phimin_ = phimin; + phimax_ = phimax; +} + +void TrackFitMemory::writeTF(bool first) { + std::ostringstream oss; + oss << "../data/MemPrints/FitTrack/TrackFit_" << getName() << "_" << std::setfill('0') << std::setw(2) + << (iSector_ + 1) << ".dat"; + auto const& fname = oss.str(); + + if (first) { + bx_ = 0; + event_ = 1; + out_.open(fname.c_str()); + } else + out_.open(fname.c_str(), std::ofstream::app); + + out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; + + for (unsigned int j = 0; j < tracks_.size(); j++) { + out_ << "0x"; + out_ << std::setfill('0') << std::setw(2); + out_ << hex << j << dec << " "; + out_ << tracks_[j]->trackfitstr() << " " << trklet::hexFormat(tracks_[j]->trackfitstr()); + out_ << "\n"; + } + out_.close(); + + bx_++; + event_++; + if (bx_ > 7) + bx_ = 0; +} diff --git a/L1Trigger/TrackFindingTracklet/src/Tracklet.cc b/L1Trigger/TrackFindingTracklet/src/Tracklet.cc new file mode 100644 index 0000000000000..92c6ced093dc2 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/Tracklet.cc @@ -0,0 +1,901 @@ +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include "L1Trigger/TrackFindingTracklet/interface/Track.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +#include + +using namespace std; +using namespace trklet; + +Tracklet::Tracklet(Settings const& settings, + const L1TStub* innerStub, + const L1TStub* middleStub, + const L1TStub* outerStub, + const Stub* innerFPGAStub, + const Stub* middleFPGAStub, + const Stub* outerFPGAStub, + double rinv, + double phi0, + double d0, + double z0, + double t, + double rinvapprox, + double phi0approx, + double d0approx, + double z0approx, + double tapprox, + int irinv, + int iphi0, + int id0, + int iz0, + int it, + LayerProjection layerprojs[N_PROJ], + DiskProjection diskprojs[N_PROJ], + bool disk, + bool overlap) + : settings_(settings) { + overlap_ = overlap; + disk_ = disk; + assert(!(disk && overlap)); + barrel_ = (!disk) && (!overlap); + triplet_ = false; + + trackletIndex_ = -1; + TCIndex_ = -1; + + assert(disk_ || barrel_ || overlap_); + + if (barrel_ && middleStub == nullptr) + assert(innerStub->layer() < N_LAYER); + + innerStub_ = innerStub; + middleStub_ = middleStub; + outerStub_ = outerStub; + innerFPGAStub_ = innerFPGAStub; + middleFPGAStub_ = middleFPGAStub; + outerFPGAStub_ = outerFPGAStub; + + trackpars_.init(rinv, phi0, d0, t, z0); + + trackparsapprox_.init(rinvapprox, phi0approx, d0approx, tapprox, z0approx); + + fpgapars_.rinv().set(irinv, settings_.nbitsrinv(), false, __LINE__, __FILE__); + fpgapars_.phi0().set(iphi0, settings_.nbitsphi0(), false, __LINE__, __FILE__); + fpgapars_.d0().set(id0, settings_.nbitsd0(), false, __LINE__, __FILE__); + fpgapars_.z0().set(iz0, settings_.nbitsz0(), false, __LINE__, __FILE__); + fpgapars_.t().set(it, settings_.nbitst(), false, __LINE__, __FILE__); + + fpgatrack_ = nullptr; + + if (innerStub_) + assert(innerStub_->layer() < N_LAYER || innerStub_->disk() < N_DISK); + if (middleStub_) + assert(middleStub_->layer() < N_LAYER || middleStub_->disk() < N_DISK); + if (outerStub_) + assert(outerStub_->layer() < N_LAYER || outerStub_->disk() < N_DISK); + + seedIndex_ = calcSeedIndex(); + + triplet_ = (seedIndex_ >= 8); + + //fill projection layers + for (unsigned int i = 0; i < N_LAYER - 2; i++) { + projlayer_[i] = settings.projlayers(seedIndex_, i); + } + + //fill projection disks + for (unsigned int i = 0; i < N_DISK; i++) { + projdisk_[i] = settings.projdisks(seedIndex_, i); + } + + //Handle projections to the layers + for (unsigned int i = 0; i < N_LAYER - 2; i++) { + if (projlayer_[i] == 0) + continue; + if (!layerprojs[i].valid()) + continue; + + layerproj_[projlayer_[i] - 1] = layerprojs[i]; + } + //Now handle projections to the disks + for (unsigned int i = 0; i < N_DISK; i++) { + if (projdisk_[i] == 0) + continue; + if (!diskprojs[i].valid()) + continue; + + diskproj_[projdisk_[i] - 1] = diskprojs[i]; + } + + ichisqrphifit_.set(-1, 8, false); + ichisqrzfit_.set(-1, 8, false); +} + +int Tracklet::tpseed() { + set tpset; + + set tpsetstubinner; + set tpsetstubouter; + + vector tps = innerStub_->tps(); + for (auto tp : tps) { + if (tp != 0) { + tpsetstubinner.insert(tp); + tpset.insert(abs(tp)); + } + } + + tps = outerStub_->tps(); + for (auto tp : tps) { + if (tp != 0) { + tpsetstubouter.insert(tp); + tpset.insert(abs(tp)); + } + } + + for (auto& tp : tpset) { + if (tpsetstubinner.find(tp) != tpsetstubinner.end() && tpsetstubinner.find(-tp) != tpsetstubinner.end() && + tpsetstubouter.find(tp) != tpsetstubouter.end() && tpsetstubouter.find(-tp) != tpsetstubouter.end()) { + return tp; + } + } + return 0; +} + +bool Tracklet::stubtruthmatch(const L1TStub* stub) { + set tpset; + set tpsetstub; + set tpsetstubinner; + set tpsetstubouter; + + vector tps = stub->tps(); + for (auto tp : tps) { + if (tp != 0) { + tpsetstub.insert(tp); + tpset.insert(abs(tp)); + } + } + tps = innerStub_->tps(); + for (auto tp : tps) { + if (tp != 0) { + tpsetstubinner.insert(tp); + tpset.insert(abs(tp)); + } + } + tps = outerStub_->tps(); + for (auto tp : tps) { + if (tp != 0) { + tpsetstubouter.insert(tp); + tpset.insert(abs(tp)); + } + } + + for (auto tp : tpset) { + if (tpsetstub.find(tp) != tpsetstub.end() && tpsetstub.find(-tp) != tpsetstub.end() && + tpsetstubinner.find(tp) != tpsetstubinner.end() && tpsetstubinner.find(-tp) != tpsetstubinner.end() && + tpsetstubouter.find(tp) != tpsetstubouter.end() && tpsetstubouter.find(-tp) != tpsetstubouter.end()) { + return true; + } + } + + return false; +} + +std::string Tracklet::addressstr() { + std::string str; + str = innerFPGAStub_->phiregionaddressstr() + "|"; + if (middleFPGAStub_) { + str += middleFPGAStub_->phiregionaddressstr() + "|"; + } + str += outerFPGAStub_->phiregionaddressstr(); + + return str; +} + +std::string Tracklet::trackletparstr() { + if (settings_.writeoutReal()) { + std::string oss = std::to_string(fpgapars_.rinv().value() * settings_.krinvpars()) + " " + + std::to_string(fpgapars_.phi0().value() * settings_.kphi0pars()) + " " + + std::to_string(fpgapars_.d0().value() * settings_.kd0pars()) + " " + + std::to_string(fpgapars_.z0().value() * settings_.kz()) + " " + + std::to_string(fpgapars_.t().value() * settings_.ktpars()); + return oss; + } else { + std::string str = innerFPGAStub_->stubindex().str() + "|"; + if (middleFPGAStub_) { + str += middleFPGAStub_->stubindex().str() + "|"; + } + str += outerFPGAStub_->stubindex().str() + "|" + fpgapars_.rinv().str() + "|" + fpgapars_.phi0().str() + "|" + + fpgapars_.d0().str() + "|" + fpgapars_.z0().str() + "|" + fpgapars_.t().str(); + return str; + } +} + +std::string Tracklet::vmstrlayer(int layer, unsigned int allstubindex) { + FPGAWord index; + if (allstubindex >= (1 << 7)) { + edm::LogPrint("Tracklet") << "Warning projection number too large!"; + index.set((1 << 7) - 1, 7, true, __LINE__, __FILE__); + } else { + index.set(allstubindex, 7, true, __LINE__, __FILE__); + } + + // This is a shortcut. + //int irinvvm=16+(fpgarinv().value()>>(fpgarinv().nbits()-5)); + // rinv is not directly available in the TrackletProjection. + // can be inferred from phi derivative: rinv = - phider * 2 + int tmp_irinv = layerproj_[layer - 1].fpgaphiprojder().value() * (-2); + int nbits_irinv = layerproj_[layer - 1].fpgaphiprojder().nbits() + 1; + + // irinv in VMProjection: + // top 5 bits of rinv and shifted to be positive + int irinvvm = 16 + (tmp_irinv >> (nbits_irinv - 5)); + + if (settings_.extended() && (irinvvm > 31)) { //TODO - displaced tracking should protect against this + edm::LogPrint("Tracklet") << "Warning irinvvm too large:" << irinvvm; + irinvvm = 31; + } + + assert(irinvvm >= 0); + assert(irinvvm < 32); + FPGAWord tmp; + tmp.set(irinvvm, 5, true, __LINE__, __FILE__); + std::string oss = index.str() + "|" + layerproj_[layer - 1].fpgazbin1projvm().str() + "|" + + layerproj_[layer - 1].fpgazbin2projvm().str() + "|" + layerproj_[layer - 1].fpgafinezvm().str() + + "|" + tmp.str() + "|" + std::to_string(PSseed()); + return oss; +} + +std::string Tracklet::vmstrdisk(int disk, unsigned int allstubindex) { + FPGAWord index; + if (allstubindex >= (1 << 7)) { + edm::LogPrint("Tracklet") << "Warning projection number too large!"; + index.set((1 << 7) - 1, 7, true, __LINE__, __FILE__); + } else { + index.set(allstubindex, 7, true, __LINE__, __FILE__); + } + std::string oss = index.str() + "|" + diskproj_[disk - 1].fpgarbin1projvm().str() + "|" + + diskproj_[disk - 1].fpgarbin2projvm().str() + "|" + diskproj_[disk - 1].fpgafinervm().str() + "|" + + diskproj_[disk - 1].getBendIndex().str(); + return oss; +} + +std::string Tracklet::trackletprojstr(int layer) const { + assert(layer > 0 && layer <= N_LAYER); + FPGAWord tmp; + if (trackletIndex_ < 0 || trackletIndex_ > (int)settings_.ntrackletmax()) { + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " trackletIndex_ = " << trackletIndex_; + } + tmp.set(trackletIndex_, 7, true, __LINE__, __FILE__); + FPGAWord tcid; + if (settings_.extended()) { + tcid.set(TCIndex_, 8, true, __LINE__, __FILE__); + } else { + tcid.set(TCIndex_, 7, true, __LINE__, __FILE__); + } + + std::string oss = tcid.str() + "|" + tmp.str() + "|" + layerproj_[layer - 1].fpgaphiproj().str() + "|" + + layerproj_[layer - 1].fpgazproj().str() + "|" + layerproj_[layer - 1].fpgaphiprojder().str() + "|" + + layerproj_[layer - 1].fpgazprojder().str(); + return oss; +} + +std::string Tracklet::trackletprojstrD(int disk) const { + assert(abs(disk) <= N_DISK); + FPGAWord tmp; + if (trackletIndex_ < 0 || trackletIndex_ > (int)settings_.ntrackletmax()) { + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " trackletIndex_ = " << trackletIndex_; + } + tmp.set(trackletIndex_, 7, true, __LINE__, __FILE__); + FPGAWord tcid; + if (settings_.extended()) { + tcid.set(TCIndex_, 8, true, __LINE__, __FILE__); + } else { + tcid.set(TCIndex_, 7, true, __LINE__, __FILE__); + } + std::string oss = tcid.str() + "|" + tmp.str() + "|" + diskproj_[abs(disk) - 1].fpgaphiproj().str() + "|" + + diskproj_[abs(disk) - 1].fpgarproj().str() + "|" + diskproj_[abs(disk) - 1].fpgaphiprojder().str() + + "|" + diskproj_[abs(disk) - 1].fpgarprojder().str(); + return oss; +} + +void Tracklet::addMatch(int layer, + int ideltaphi, + int ideltaz, + double dphi, + double dz, + double dphiapprox, + double dzapprox, + int stubid, + double rstub, + const trklet::Stub* stubptr) { + assert(layer > 0 && layer <= N_LAYER); + layerresid_[layer - 1].init( + settings_, layer, ideltaphi, ideltaz, stubid, dphi, dz, dphiapprox, dzapprox, rstub, stubptr); +} + +void Tracklet::addMatchDisk(int disk, + int ideltaphi, + int ideltar, + double dphi, + double dr, + double dphiapprox, + double drapprox, + double alpha, + int stubid, + double zstub, + const trklet::Stub* stubptr) { + assert(abs(disk) <= N_DISK); + diskresid_[abs(disk) - 1].init(settings_, + disk, + ideltaphi, + ideltar, + stubid, + dphi, + dr, + dphiapprox, + drapprox, + zstub, + alpha, + stubptr->alphanew(), + stubptr); +} + +int Tracklet::nMatches() { + int nmatches = 0; + + for (const auto& ilayerresid : layerresid_) { + if (ilayerresid.valid()) { + nmatches++; + } + } + + return nmatches; +} + +int Tracklet::nMatchesDisk() { + int nmatches = 0; + + for (const auto& idiskresid : diskresid_) { + if (idiskresid.valid()) { + nmatches++; + } + } + return nmatches; +} + +std::string Tracklet::fullmatchstr(int layer) { + assert(layer > 0 && layer <= N_LAYER); + + FPGAWord tmp; + if (trackletIndex_ < 0 || trackletIndex_ > (int)settings_.ntrackletmax()) { + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " trackletIndex_ = " << trackletIndex_; + } + tmp.set(trackletIndex_, 7, true, __LINE__, __FILE__); + FPGAWord tcid; + if (settings_.extended()) { + tcid.set(TCIndex_, 8, true, __LINE__, __FILE__); + } else { + tcid.set(TCIndex_, 7, true, __LINE__, __FILE__); + } + std::string oss = tcid.str() + "|" + tmp.str() + "|" + layerresid_[layer - 1].fpgastubid().str() + "|" + + layerresid_[layer - 1].fpgaphiresid().str() + "|" + layerresid_[layer - 1].fpgazresid().str(); + return oss; +} + +std::string Tracklet::fullmatchdiskstr(int disk) { + assert(disk > 0 && disk <= N_DISK); + + FPGAWord tmp; + if (trackletIndex_ < 0 || trackletIndex_ > (int)settings_.ntrackletmax()) { + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " trackletIndex_ = " << trackletIndex_; + } + tmp.set(trackletIndex_, 7, true, __LINE__, __FILE__); + FPGAWord tcid; + if (settings_.extended()) { + tcid.set(TCIndex_, 8, true, __LINE__, __FILE__); + } else { + tcid.set(TCIndex_, 7, true, __LINE__, __FILE__); + } + std::string oss = tcid.str() + "|" + tmp.str() + "|" + diskresid_[disk - 1].fpgastubid().str() + "|" + + diskresid_[disk - 1].fpgaphiresid().str() + "|" + diskresid_[disk - 1].fpgarresid().str(); + return oss; +} + +std::vector Tracklet::getL1Stubs() { + std::vector tmp; + + if (innerStub_) + tmp.push_back(innerStub_); + if (middleStub_) + tmp.push_back(middleStub_); + if (outerStub_) + tmp.push_back(outerStub_); + + for (const auto& ilayerresid : layerresid_) { + if (ilayerresid.valid()) + tmp.push_back(ilayerresid.stubptr()->l1tstub()); + } + + for (const auto& idiskresid : diskresid_) { + if (idiskresid.valid()) + tmp.push_back(idiskresid.stubptr()->l1tstub()); + } + + return tmp; +} + +std::map Tracklet::getStubIDs() { + std::map stubIDs; + + // For future reference, *resid_[i] uses i as the absolute stub index. (0-5 for barrel, 0-4 for disk) + // On the other hand, proj*_[i] uses i almost like *resid_[i], except the *seeding* layer indices are removed entirely. + // E.g. An L3L4 track has 0=L1, 1=L2, 2=L4, 3=L5 for the barrels (for proj*_[i]) + + if (innerFPGAStub_) + assert(innerFPGAStub_->stubindex().nbits() == 7); + if (middleFPGAStub_) + assert(middleFPGAStub_->stubindex().nbits() == 7); + if (outerFPGAStub_) + assert(outerFPGAStub_->stubindex().nbits() == 7); + + if (barrel_) { + for (int i = 0; i < N_LAYER; i++) { + //check barrel + if (layerresid_[i].valid()) { + // two extra bits to indicate if the matched stub is local or from neighbor + int location = 1; // local + location <<= layerresid_[i].fpgastubid().nbits(); + + stubIDs[1 + i] = layerresid_[i].fpgastubid().value() + location; + } + + //check disk + if (i >= N_DISK) + continue; //i=[0..4] for disks + if (diskresid_[i].valid()) { + if (i == 3 && layerresid_[0].valid() && innerFPGAStub_->layer().value() == 1) + continue; // Don't add D4 if track has L1 stub + // two extra bits to indicate if the matched stub is local or from neighbor + int location = 1; // local + location <<= diskresid_[i].fpgastubid().nbits(); + + if (itfit().value() < 0) { + stubIDs[-11 - i] = diskresid_[i].fpgastubid().value() + location; + } else { + stubIDs[11 + i] = diskresid_[i].fpgastubid().value() + location; + } + } + } + + //get stubs making up tracklet + if (innerFPGAStub_) + stubIDs[innerFPGAStub_->layer().value() + 1] = innerFPGAStub_->phiregionaddress() + (1 << 10); + if (middleFPGAStub_) + stubIDs[middleFPGAStub_->layer().value() + 1] = middleFPGAStub_->phiregionaddress() + (1 << 10); + if (outerFPGAStub_) + stubIDs[outerFPGAStub_->layer().value() + 1] = outerFPGAStub_->phiregionaddress() + (1 << 10); + + } else if (disk_) { + for (int i = 0; i < N_DISK; i++) { + //check barrel + if (layerresid_[i].valid()) { + // two extra bits to indicate if the matched stub is local or from neighbor + int location = 1; // local + location <<= layerresid_[i].fpgastubid().nbits(); + + stubIDs[1 + i] = layerresid_[i].fpgastubid().value() + location; + } + + //check disks + if (i == 4 && layerresid_[1].valid()) + continue; // Don't add D5 if track has L2 stub + if (diskresid_[i].valid()) { + // two extra bits to indicate if the matched stub is local or from neighbor + int location = 1; // local + location <<= diskresid_[i].fpgastubid().nbits(); + + if (innerStub_->disk() < 0) { + stubIDs[-11 - i] = diskresid_[i].fpgastubid().value() + location; + } else { + stubIDs[11 + i] = diskresid_[i].fpgastubid().value() + location; + } + } + } + + //get stubs making up tracklet + if (innerFPGAStub_->disk().value() < 0) { //negative side runs 6-10 + if (innerFPGAStub_) + stubIDs[innerFPGAStub_->disk().value() - 10] = innerFPGAStub_->phiregionaddress() + (1 << 10); + if (middleFPGAStub_) + stubIDs[middleFPGAStub_->disk().value() - 10] = middleFPGAStub_->phiregionaddress() + (1 << 10); + if (outerFPGAStub_) + stubIDs[outerFPGAStub_->disk().value() - 10] = outerFPGAStub_->phiregionaddress() + (1 << 10); + } else { // positive side runs 11-15] + if (innerFPGAStub_) + stubIDs[innerFPGAStub_->disk().value() + 10] = innerFPGAStub_->phiregionaddress() + (1 << 10); + if (middleFPGAStub_) + stubIDs[middleFPGAStub_->disk().value() + 10] = middleFPGAStub_->phiregionaddress() + (1 << 10); + if (outerFPGAStub_) + stubIDs[outerFPGAStub_->disk().value() + 10] = outerFPGAStub_->phiregionaddress() + (1 << 10); + } + + } else if (overlap_) { + for (int i = 0; i < N_DISK; i++) { + //check barrel + if (layerresid_[i].valid()) { + // two extra bits to indicate if the matched stub is local or from neighbor + int location = 1; // local + location <<= layerresid_[i].fpgastubid().nbits(); + + stubIDs[1 + i] = layerresid_[i].fpgastubid().value() + location; + } + + //check disks + if (diskresid_[i].valid()) { + // two extra bits to indicate if the matched stub is local or from neighbor + int location = 1; // local + location <<= diskresid_[i].fpgastubid().nbits(); + + if (innerStub_->disk() < 0) { // if negative overlap + if (innerFPGAStub_->layer().value() != 2 || !layerresid_[0].valid() || + i != 3) { // Don't add D4 if this is an L3L2 track with an L1 stub + stubIDs[-11 - i] = diskresid_[i].fpgastubid().value() + location; + } + } else { + if (innerFPGAStub_->layer().value() != 2 || !layerresid_[0].valid() || i != 3) { + stubIDs[11 + i] = diskresid_[i].fpgastubid().value() + location; + } + } + } + } + + //get stubs making up tracklet + + if (innerFPGAStub_->layer().value() == 2) { // L3L2 track + if (innerFPGAStub_) + stubIDs[innerFPGAStub_->layer().value() + 1] = innerFPGAStub_->phiregionaddress() + (1 << 10); + if (middleFPGAStub_) + stubIDs[middleFPGAStub_->layer().value() + 1] = middleFPGAStub_->phiregionaddress() + (1 << 10); + if (outerFPGAStub_) + stubIDs[outerFPGAStub_->layer().value() + 1] = outerFPGAStub_->phiregionaddress() + (1 << 10); + } else if (innerFPGAStub_->disk().value() < 0) { //negative side runs -11 - -15 + if (innerFPGAStub_) + stubIDs[innerFPGAStub_->disk().value() - 10] = innerFPGAStub_->phiregionaddress() + (1 << 10); + if (middleFPGAStub_) + stubIDs[middleFPGAStub_->layer().value() + 1] = middleFPGAStub_->phiregionaddress() + (1 << 10); + if (outerFPGAStub_) + stubIDs[outerFPGAStub_->layer().value() + 1] = outerFPGAStub_->phiregionaddress() + (1 << 10); + } else { // positive side runs 11-15] + if (innerFPGAStub_) + stubIDs[innerFPGAStub_->disk().value() + 10] = innerFPGAStub_->phiregionaddress() + (1 << 10); + if (middleFPGAStub_) + stubIDs[middleFPGAStub_->layer().value() + 1] = middleFPGAStub_->phiregionaddress() + (1 << 10); + if (outerFPGAStub_) + stubIDs[outerFPGAStub_->layer().value() + 1] = outerFPGAStub_->phiregionaddress() + (1 << 10); + } + } + + return stubIDs; +} + +void Tracklet::setFitPars(double rinvfit, + double phi0fit, + double d0fit, + double tfit, + double z0fit, + double chisqrphifit, + double chisqrzfit, + double rinvfitexact, + double phi0fitexact, + double d0fitexact, + double tfitexact, + double z0fitexact, + double chisqrphifitexact, + double chisqrzfitexact, + int irinvfit, + int iphi0fit, + int id0fit, + int itfit, + int iz0fit, + int ichisqrphifit, + int ichisqrzfit, + int hitpattern, + const vector& l1stubs) { + fitpars_.init(rinvfit, phi0fit, d0fit, tfit, z0fit); + chisqrphifit_ = chisqrphifit; + chisqrzfit_ = chisqrzfit; + + fitparsexact_.init(rinvfitexact, phi0fitexact, d0fitexact, tfitexact, z0fitexact); + chisqrphifitexact_ = chisqrphifitexact; + chisqrzfitexact_ = chisqrzfitexact; + + if (irinvfit > (1 << 14)) + irinvfit = (1 << 14); + if (irinvfit <= -(1 << 14)) + irinvfit = -(1 << 14) + 1; + fpgafitpars_.rinv().set(irinvfit, 15, false, __LINE__, __FILE__); + fpgafitpars_.phi0().set(iphi0fit, 19, false, __LINE__, __FILE__); + fpgafitpars_.d0().set(id0fit, 19, false, __LINE__, __FILE__); + fpgafitpars_.t().set(itfit, 14, false, __LINE__, __FILE__); + + if (iz0fit >= (1 << (settings_.nbitsz0() - 1))) { + iz0fit = (1 << (settings_.nbitsz0() - 1)) - 1; + } + + if (iz0fit <= -(1 << (settings_.nbitsz0() - 1))) { + iz0fit = 1 - (1 << (settings_.nbitsz0() - 1)); + } + + fpgafitpars_.z0().set(iz0fit, settings_.nbitsz0(), false, __LINE__, __FILE__); + ichisqrphifit_.set(ichisqrphifit, 8, true, __LINE__, __FILE__); + ichisqrzfit_.set(ichisqrzfit, 8, true, __LINE__, __FILE__); + + hitpattern_ = hitpattern; + + fpgatrack_.reset(new Track(makeTrack(l1stubs))); +} + +std::string Tracklet::trackfitstr() { + string stubid0 = "111111111"; + string stubid1 = "111111111"; + string stubid2 = "111111111"; + string stubid3 = "111111111"; + + if (isBarrel()) { + if (layer() == 1) { + if (layerresid_[2].valid()) { + stubid0 = layerresid_[2].fpgastubid().str(); + } + if (layerresid_[3].valid()) { + stubid1 = layerresid_[3].fpgastubid().str(); + } + if (layerresid_[4].valid()) { + stubid2 = layerresid_[4].fpgastubid().str(); + } + if (layerresid_[5].valid()) { + stubid3 = layerresid_[5].fpgastubid().str(); + } + if (diskresid_[0].valid()) { + stubid3 = diskresid_[0].fpgastubid().str(); + } + if (diskresid_[1].valid()) { + stubid2 = diskresid_[1].fpgastubid().str(); + } + if (diskresid_[2].valid()) { + stubid1 = diskresid_[2].fpgastubid().str(); + } + if (diskresid_[3].valid()) { + stubid0 = diskresid_[3].fpgastubid().str(); + } + } + + if (layer() == 3) { + if (layerresid_[0].valid()) { + stubid0 = layerresid_[0].fpgastubid().str(); + } + if (layerresid_[1].valid()) { + stubid1 = layerresid_[1].fpgastubid().str(); + } + if (layerresid_[4].valid()) { + stubid2 = layerresid_[4].fpgastubid().str(); + } + if (layerresid_[5].valid()) { + stubid3 = layerresid_[5].fpgastubid().str(); + } + if (diskresid_[0].valid()) { + stubid3 = diskresid_[0].fpgastubid().str(); + } + if (diskresid_[1].valid()) { + stubid2 = diskresid_[1].fpgastubid().str(); + } + } + + if (layer() == 5) { + if (layerresid_[0].valid()) { + stubid0 = layerresid_[0].fpgastubid().str(); + } + if (layerresid_[1].valid()) { + stubid1 = layerresid_[1].fpgastubid().str(); + } + if (layerresid_[2].valid()) { + stubid2 = layerresid_[2].fpgastubid().str(); + } + if (layerresid_[3].valid()) { + stubid3 = layerresid_[3].fpgastubid().str(); + } + } + } + + if (isDisk()) { + if (disk() == 1) { + if (layerresid_[0].valid()) { + stubid0 = layerresid_[0].fpgastubid().str(); + } + if (diskresid_[2].valid()) { + stubid1 = diskresid_[2].fpgastubid().str(); + } + if (diskresid_[3].valid()) { + stubid2 = diskresid_[3].fpgastubid().str(); + } + if (diskresid_[4].valid()) { + stubid3 = diskresid_[4].fpgastubid().str(); + } else if (layerresid_[1].valid()) { + stubid3 = layerresid_[1].fpgastubid().str(); + } + } + + if (disk() == 3) { + if (layerresid_[0].valid()) { + stubid0 = layerresid_[0].fpgastubid().str(); + } + if (diskresid_[0].valid()) { + stubid1 = diskresid_[0].fpgastubid().str(); + } + if (diskresid_[1].valid()) { + stubid2 = diskresid_[1].fpgastubid().str(); + } + if (diskresid_[4].valid()) { + stubid3 = diskresid_[4].fpgastubid().str(); + } else if (layerresid_[1].valid()) { + stubid3 = layerresid_[1].fpgastubid().str(); + } + } + } + + if (isOverlap()) { + if (layer() == 1) { + if (diskresid_[1].valid()) { + stubid0 = diskresid_[1].fpgastubid().str(); + } + if (diskresid_[2].valid()) { + stubid1 = diskresid_[2].fpgastubid().str(); + } + if (diskresid_[3].valid()) { + stubid2 = diskresid_[3].fpgastubid().str(); + } + if (diskresid_[4].valid()) { + stubid3 = diskresid_[4].fpgastubid().str(); + } + } + } + + std::string oss; + // real Q print out for fitted tracks + if (settings_.writeoutReal()) { + oss = std::to_string((fpgafitpars_.rinv().value()) * settings_.krinvpars()) + " " + + std::to_string((fpgafitpars_.phi0().value()) * settings_.kphi0pars()) + " " + + std::to_string((fpgafitpars_.d0().value()) * settings_.kd0pars()) + " " + + std::to_string((fpgafitpars_.t().value()) * settings_.ktpars()) + " " + + std::to_string((fpgafitpars_.z0().value()) * settings_.kz()) + " " + innerFPGAStub_->phiregionaddressstr() + + " "; + } + //Binary print out + if (!settings_.writeoutReal()) { + oss = fpgafitpars_.rinv().str() + "|" + fpgafitpars_.phi0().str() + "|" + fpgafitpars_.d0().str() + "|" + + fpgafitpars_.t().str() + "|" + fpgafitpars_.z0().str() + "|" + innerFPGAStub_->phiregionaddressstr() + "|"; + } + if (middleFPGAStub_) { + oss += middleFPGAStub_->phiregionaddressstr() + " "; + } + oss += outerFPGAStub_->phiregionaddressstr() + " " + stubid0 + "|" + stubid1 + "|" + stubid2 + "|" + stubid3; + + return oss; +} + +Track Tracklet::makeTrack(const vector& l1stubs) { + assert(fit()); + + TrackPars ipars(fpgafitpars_.rinv().value(), + fpgafitpars_.phi0().value(), + fpgafitpars_.d0().value(), + fpgafitpars_.t().value(), + fpgafitpars_.z0().value()); + + Track tmpTrack( + ipars, + ichisqrphifit_.value(), + ichisqrzfit_.value(), + chisqrphifit_, + chisqrzfit_, + hitpattern_, + getStubIDs(), + (l1stubs.empty()) ? getL1Stubs() : l1stubs, // If fitter produced no stub list, take it from original tracklet. + getISeed()); + + return tmpTrack; +} + +int Tracklet::layer() const { + int l1 = (innerFPGAStub_ && innerFPGAStub_->isBarrel()) ? innerStub_->layer() + 1 : 999, + l2 = (middleFPGAStub_ && middleFPGAStub_->isBarrel()) ? middleStub_->layer() + 1 : 999, + l3 = (outerFPGAStub_ && outerFPGAStub_->isBarrel()) ? outerStub_->layer() + 1 : 999, l = min(min(l1, l2), l3); + return (l < 999 ? l : 0); +} + +int Tracklet::disk() const { + int d1 = (innerFPGAStub_ && innerFPGAStub_->isDisk()) ? innerStub_->disk() : 999, + d2 = (middleFPGAStub_ && middleFPGAStub_->isDisk()) ? middleStub_->disk() : 999, + d3 = (outerFPGAStub_ && outerFPGAStub_->isDisk()) ? outerStub_->disk() : 999, d = 999; + if (abs(d1) < min(abs(d2), abs(d3))) + d = d1; + if (abs(d2) < min(abs(d1), abs(d3))) + d = d2; + if (abs(d3) < min(abs(d1), abs(d2))) + d = d3; + return (d < 999 ? d : 0); +} + +int Tracklet::disk2() const { + if (innerStub_->disk() > 0) { + return innerStub_->disk() + 1; + } + return innerStub_->disk() - 1; +} + +void Tracklet::setTrackletIndex(int index) { + trackletIndex_ = index; + assert(index < 128); +} + +int Tracklet::getISeed() const { + int iSeed = TCIndex_ >> 4; + assert(iSeed >= 0 && iSeed <= (int)N_SEED); + return iSeed; +} + +int Tracklet::getITC() const { + int iSeed = getISeed(), iTC = TCIndex_ - (iSeed << 4); + assert(iTC >= 0 && iTC <= 14); + return iTC; +} + +unsigned int Tracklet::calcSeedIndex() const { + int seedindex = -1; + int seedlayer = layer(); + int seeddisk = disk(); + + if (seedlayer == 1 && seeddisk == 0) + seedindex = 0; //L1L2 + if (seedlayer == 3 && seeddisk == 0) + seedindex = 2; //L3L4 + if (seedlayer == 5 && seeddisk == 0) + seedindex = 3; //L5L6 + if (seedlayer == 0 && abs(seeddisk) == 1) + seedindex = 4; //D1D2 + if (seedlayer == 0 && abs(seeddisk) == 3) + seedindex = 5; //D3D4 + if (seedlayer == 1 && abs(seeddisk) == 1) + seedindex = 6; //L1D1 + if (seedlayer == 2 && abs(seeddisk) == 1) + seedindex = 7; //L2D1 + if (seedlayer == 2 && abs(seeddisk) == 0) + seedindex = 1; //L2L3 + if (middleFPGAStub_ && seedlayer == 2 && seeddisk == 0) + seedindex = 8; // L3L4L2 + if (middleFPGAStub_ && seedlayer == 4 && seeddisk == 0) + seedindex = 9; // L5L6L4 + assert(innerFPGAStub_ != nullptr); + assert(outerFPGAStub_ != nullptr); + if (middleFPGAStub_ && seedlayer == 2 && abs(seeddisk) == 1) { + int l1 = (innerFPGAStub_ && innerFPGAStub_->isBarrel()) ? innerStub_->layer() + 1 : 999, + l2 = (middleFPGAStub_ && middleFPGAStub_->isBarrel()) ? middleStub_->layer() + 1 : 999, + l3 = (outerFPGAStub_ && outerFPGAStub_->isBarrel()) ? outerStub_->layer() + 1 : 999; + if (l1 + l2 + l3 < 1998) { // If two stubs are layer stubs + seedindex = 10; // L2L3D1 + } else { + seedindex = 11; // D1D2L2 + } + } + + if (seedindex < 0) { + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " seedlayer abs(seeddisk) : " << seedlayer + << " " << abs(seeddisk); + } + + return seedindex; +} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletCalculator.cc b/L1Trigger/TrackFindingTracklet/src/TrackletCalculator.cc new file mode 100644 index 0000000000000..c7946901b6e2a --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/TrackletCalculator.cc @@ -0,0 +1,192 @@ +#include "L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +using namespace std; +using namespace trklet; + +TrackletCalculator::TrackletCalculator(string name, Settings const& settings, Globals* globals, unsigned int iSector) + : TrackletCalculatorBase(name, settings, globals, iSector) { + phioffset_ = phimin_; + + for (unsigned int ilayer = 0; ilayer < N_LAYER; ilayer++) { + vector tmp(settings.nallstubs(ilayer), nullptr); + trackletprojlayers_.push_back(tmp); + } + + for (unsigned int idisk = 0; idisk < N_DISK; idisk++) { + vector tmp(settings.nallstubs(idisk + N_LAYER), nullptr); + trackletprojdisks_.push_back(tmp); + } + + initLayerDisksandISeed(layerdisk1_, layerdisk2_, iSeed_); + + // set TC index + iTC_ = name_[7] - 'A'; + + TCIndex_ = (iSeed_ << 4) + iTC_; + assert(TCIndex_ >= 0 && TCIndex_ <= (int)settings_.ntrackletmax()); + + if (settings_.usephicritapprox()) { + double phicritFactor = + 0.5 * settings_.rcrit() * globals_->ITC_L1L2()->rinv_final.K() / globals_->ITC_L1L2()->phi0_final.K(); + if (std::abs(phicritFactor - 2.) > 0.25) + edm::LogPrint("Tracklet") + << "TrackletCalculator::TrackletCalculator phicrit approximation may be invalid! Please check."; + } +} + +void TrackletCalculator::addOutputProjection(TrackletProjectionsMemory*& outputProj, MemoryBase* memory) { + outputProj = dynamic_cast(memory); + assert(outputProj != nullptr); +} + +void TrackletCalculator::addOutput(MemoryBase* memory, string output) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " + << output; + } + if (output == "trackpar") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + trackletpars_ = tmp; + return; + } + + if (output.substr(0, 7) == "projout") { + //output is on the form 'projoutL2PHIC' or 'projoutD3PHIB' + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + + unsigned int layerdisk = output[8] - '1'; //layer or disk counting from 0 + unsigned int phiregion = output[12] - 'A'; //phiregion counting from 0 + + if (output[7] == 'L') { + assert(layerdisk < N_LAYER); + assert(phiregion < trackletprojlayers_[layerdisk].size()); + //check that phiregion not already initialized + assert(trackletprojlayers_[layerdisk][phiregion] == nullptr); + trackletprojlayers_[layerdisk][phiregion] = tmp; + return; + } + + if (output[7] == 'D') { + assert(layerdisk < N_DISK); + assert(phiregion < trackletprojdisks_[layerdisk].size()); + //check that phiregion not already initialized + assert(trackletprojdisks_[layerdisk][phiregion] == nullptr); + trackletprojdisks_[layerdisk][phiregion] = tmp; + return; + } + } + + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output; +} + +void TrackletCalculator::addInput(MemoryBase* memory, string input) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " + << input; + } + if (input == "innerallstubin") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + innerallstubs_.push_back(tmp); + return; + } + if (input == "outerallstubin") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + outerallstubs_.push_back(tmp); + return; + } + if (input.substr(0, 8) == "stubpair") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + stubpairs_.push_back(tmp); + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find intput : " << input; +} + +void TrackletCalculator::execute() { + unsigned int countall = 0; + unsigned int countsel = 0; + + for (auto& stubpair : stubpairs_) { + if (trackletpars_->nTracklets() >= settings_.ntrackletmax()) { + edm::LogVerbatim("Tracklet") << "Will break on too many tracklets in " << getName(); + break; + } + for (unsigned int i = 0; i < stubpair->nStubPairs(); i++) { + countall++; + const Stub* innerFPGAStub = stubpair->getVMStub1(i).stub(); + const L1TStub* innerStub = innerFPGAStub->l1tstub(); + + const Stub* outerFPGAStub = stubpair->getVMStub2(i).stub(); + const L1TStub* outerStub = outerFPGAStub->l1tstub(); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "TrackletCalculator execute " << getName() << "[" << iSector_ << "]"; + } + + if (innerFPGAStub->isBarrel() && (getName() != "TC_D1L2A" && getName() != "TC_D1L2B")) { + if (outerFPGAStub->isDisk()) { + //overlap seeding + bool accept = overlapSeeding(outerFPGAStub, outerStub, innerFPGAStub, innerStub); + if (accept) + countsel++; + } else { + //barrel+barrel seeding + bool accept = barrelSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); + if (accept) + countsel++; + } + } else { + if (outerFPGAStub->isDisk()) { + //disk+disk seeding + bool accept = diskSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); + if (accept) + countsel++; + } else if (innerFPGAStub->isDisk()) { + //layer+disk seeding + bool accept = overlapSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); + if (accept) + countsel++; + } else { + throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " invalid seeding"; + } + } + + if (trackletpars_->nTracklets() >= settings_.ntrackletmax()) { + edm::LogVerbatim("Tracklet") << "Will break on number of tracklets in " << getName(); + break; + } + + if (countall >= settings_.maxStep("TC")) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Will break on MAXTC 1"; + break; + } + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "TrackletCalculator execute done"; + } + } + if (countall >= settings_.maxStep("TC")) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Will break on MAXTC 2"; + break; + } + } + + if (settings_.writeMonitorData("TC")) { + globals_->ofstream("trackletcalculator.txt") << getName() << " " << countall << " " << countsel << endl; + } +} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc new file mode 100644 index 0000000000000..3ad10166f4170 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc @@ -0,0 +1,1473 @@ +#include "L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/HistBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" +#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorDisk.h" +#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorOverlap.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" +#include "DataFormats/Math/interface/deltaPhi.h" + +using namespace std; +using namespace trklet; + +TrackletCalculatorBase::TrackletCalculatorBase(string name, + Settings const& settings, + Globals* global, + unsigned int iSector) + : ProcessBase(name, settings, global, iSector) {} + +void TrackletCalculatorBase::exacttracklet(double r1, + double z1, + double phi1, + double r2, + double z2, + double phi2, + double, + double& rinv, + double& phi0, + double& t, + double& z0, + double phiproj[N_LAYER - 2], + double zproj[N_LAYER - 2], + double phider[N_LAYER - 2], + double zder[N_LAYER - 2], + double phiprojdisk[N_DISK], + double rprojdisk[N_DISK], + double phiderdisk[N_DISK], + double rderdisk[N_DISK]) { + double deltaphi = reco::reduceRange(phi1 - phi2); + + double dist = sqrt(r2 * r2 + r1 * r1 - 2 * r1 * r2 * cos(deltaphi)); + + rinv = 2 * sin(deltaphi) / dist; + + double phi1tmp = phi1 - phimin_; + + phi0 = reco::reduceRange(phi1tmp + asin(0.5 * r1 * rinv)); + + double rhopsi1 = 2 * asin(0.5 * r1 * rinv) / rinv; + double rhopsi2 = 2 * asin(0.5 * r2 * rinv) / rinv; + + t = (z1 - z2) / (rhopsi1 - rhopsi2); + + z0 = z1 - t * rhopsi1; + + for (unsigned int i = 0; i < N_LAYER - 2; i++) { + exactproj(settings_.rmean(settings_.projlayers(iSeed_, i) - 1), + rinv, + phi0, + t, + z0, + phiproj[i], + zproj[i], + phider[i], + zder[i]); + } + + for (unsigned int i = 0; i < N_DISK; i++) { + exactprojdisk(settings_.zmean(i), rinv, phi0, t, z0, phiprojdisk[i], rprojdisk[i], phiderdisk[i], rderdisk[i]); + } +} + +void TrackletCalculatorBase::exacttrackletdisk(double r1, + double z1, + double phi1, + double r2, + double z2, + double phi2, + double, + double& rinv, + double& phi0, + double& t, + double& z0, + double phiprojLayer[N_PSLAYER], //=3 (project to PS barrel layers only) + double zprojLayer[N_PSLAYER], + double phiderLayer[N_PSLAYER], + double zderLayer[N_PSLAYER], + double phiproj[N_DISK - 2], //=3 (max project to 3 other disks) + double rproj[N_DISK - 2], + double phider[N_DISK - 2], + double rder[N_DISK - 2]) { + double deltaphi = reco::reduceRange(phi1 - phi2); + + double dist = sqrt(r2 * r2 + r1 * r1 - 2 * r1 * r2 * cos(deltaphi)); + + rinv = 2 * sin(deltaphi) / dist; + + double phi1tmp = phi1 - phimin_; + + phi0 = reco::reduceRange(phi1tmp + asin(0.5 * r1 * rinv)); + + double rhopsi1 = 2 * asin(0.5 * r1 * rinv) / rinv; + double rhopsi2 = 2 * asin(0.5 * r2 * rinv) / rinv; + + t = (z1 - z2) / (rhopsi1 - rhopsi2); + + z0 = z1 - t * rhopsi1; + + for (unsigned int i = 0; i < N_DISK - 2; i++) { + exactprojdisk(settings_.zmean(settings_.projdisks(iSeed_, i) - 1), + rinv, + phi0, + t, + z0, + phiproj[i], + rproj[i], + phider[i], + rder[i]); + } + + for (unsigned int i = 0; i < N_DISK - 2; i++) { + exactproj(settings_.rmean(i), rinv, phi0, t, z0, phiprojLayer[i], zprojLayer[i], phiderLayer[i], zderLayer[i]); + } +} + +void TrackletCalculatorBase::exacttrackletOverlap(double r1, + double z1, + double phi1, + double r2, + double z2, + double phi2, + double, + double& rinv, + double& phi0, + double& t, + double& z0, + double phiprojLayer[N_PSLAYER], + double zprojLayer[N_PSLAYER], + double phiderLayer[N_PSLAYER], + double zderLayer[N_PSLAYER], + double phiproj[N_DISK - 2], + double rproj[N_DISK - 2], + double phider[N_DISK - 2], + double rder[N_DISK - 2]) { + double deltaphi = reco::reduceRange(phi1 - phi2); + + double dist = sqrt(r2 * r2 + r1 * r1 - 2 * r1 * r2 * cos(deltaphi)); + + rinv = 2 * sin(deltaphi) / dist; + + if (r1 > r2) + rinv = -rinv; + + double phi1tmp = phi1 - phimin_; + + phi0 = reco::reduceRange(phi1tmp + asin(0.5 * r1 * rinv)); + + double rhopsi1 = 2 * asin(0.5 * r1 * rinv) / rinv; + double rhopsi2 = 2 * asin(0.5 * r2 * rinv) / rinv; + + t = (z1 - z2) / (rhopsi1 - rhopsi2); + + z0 = z1 - t * rhopsi1; + + for (int i = 0; i < 4; i++) { + exactprojdisk(settings_.zmean(i + 1), rinv, phi0, t, z0, phiproj[i], rproj[i], phider[i], rder[i]); + } + + for (int i = 0; i < 1; i++) { + exactproj(settings_.rmean(i), rinv, phi0, t, z0, phiprojLayer[i], zprojLayer[i], phiderLayer[i], zderLayer[i]); + } +} + +void TrackletCalculatorBase::exactproj(double rproj, + double rinv, + double phi0, + double t, + double z0, + double& phiproj, + double& zproj, + double& phider, + double& zder) { + phiproj = phi0 - asin(0.5 * rproj * rinv); + zproj = z0 + (2 * t / rinv) * asin(0.5 * rproj * rinv); + + phider = -0.5 * rinv / sqrt(1 - pow(0.5 * rproj * rinv, 2)); + zder = t / sqrt(1 - pow(0.5 * rproj * rinv, 2)); +} + +void TrackletCalculatorBase::exactprojdisk(double zproj, + double rinv, + double phi0, + double t, + double z0, + double& phiproj, + double& rproj, + double& phider, + double& rder) { + if (t < 0) + zproj = -zproj; + + double tmp = rinv * (zproj - z0) / (2.0 * t); + rproj = (2.0 / rinv) * sin(tmp); + phiproj = phi0 - tmp; + + phider = -rinv / (2 * t); + rder = cos(tmp) / t; +} + +void TrackletCalculatorBase::addDiskProj(Tracklet* tracklet, int disk) { + FPGAWord fpgar = tracklet->fpgarprojdisk(disk); + + if (fpgar.value() * settings_.krprojshiftdisk() < settings_.rmindiskvm()) + return; + if (fpgar.value() * settings_.krprojshiftdisk() > settings_.rmaxdisk()) + return; + + FPGAWord fpgaphi = tracklet->fpgaphiprojdisk(disk); + + int iphivmRaw = fpgaphi.value() >> (fpgaphi.nbits() - 5); + + int iphi = iphivmRaw / (32 / settings_.nallstubs(abs(disk) + N_DISK)); + + addProjectionDisk(disk, iphi, trackletprojdisks_[abs(disk) - 1][iphi], tracklet); +} + +bool TrackletCalculatorBase::addLayerProj(Tracklet* tracklet, int layer) { + assert(layer > 0); + + FPGAWord fpgaz = tracklet->fpgazproj(layer); + FPGAWord fpgaphi = tracklet->fpgaphiproj(layer); + + if (fpgaphi.atExtreme()) + edm::LogProblem("Tracklet") << "at extreme! " << fpgaphi.value(); + + assert(!fpgaphi.atExtreme()); + + if (fpgaz.atExtreme()) + return false; + + if (std::abs(fpgaz.value() * settings_.kz()) > settings_.zlength()) + return false; + + int iphivmRaw = fpgaphi.value() >> (fpgaphi.nbits() - 5); + int iphi = iphivmRaw / (32 / settings_.nallstubs(layer - 1)); + + addProjection(layer, iphi, trackletprojlayers_[layer - 1][iphi], tracklet); + + return true; +} + +void TrackletCalculatorBase::addProjection(int layer, + int iphi, + TrackletProjectionsMemory* trackletprojs, + Tracklet* tracklet) { + if (trackletprojs == nullptr) { + if (settings_.warnNoMem()) { + edm::LogVerbatim("Tracklet") << "No projection memory exists in " << getName() << " for layer = " << layer + << " iphi = " << iphi + 1; + } + return; + } + assert(trackletprojs != nullptr); + trackletprojs->addProj(tracklet); +} + +void TrackletCalculatorBase::addProjectionDisk(int disk, + int iphi, + TrackletProjectionsMemory* trackletprojs, + Tracklet* tracklet) { + if (iSeed_ == 2 && abs(disk) == 4) + return; //L3L4 projections to D3 are not used. Should be in configuration + if (trackletprojs == nullptr) { + if (iSeed_ == 2 && abs(disk) == 3) + return; //L3L4 projections to D3 are not used. + if (settings_.warnNoMem()) { + edm::LogVerbatim("Tracklet") << "No projection memory exists in " << getName() << " for disk = " << abs(disk) + << " iphi = " << iphi + 1; + } + return; + } + assert(trackletprojs != nullptr); + trackletprojs->addProj(tracklet); +} + +bool TrackletCalculatorBase::goodTrackPars(bool goodrinv, bool goodz0) { + bool success = true; + if (!goodrinv) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " TrackletCalculatorBase irinv too large"; + } + success = false; + } + if (!goodz0) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " TrackletCalculatorBase z0 cut to large"; + } + success = false; + } + return success; +} + +bool TrackletCalculatorBase::inSector(int iphi0, int irinv, double phi0approx, double rinvapprox) { + double phicritapprox = phi0approx - asin(0.5 * settings_.rcrit() * rinvapprox); + + int ifactor = 0.5 * settings_.rcrit() * settings_.krinvpars() / settings_.kphi0pars() * (1 << 8); + int iphicrit = iphi0 - (irinv >> 8) * ifactor; + + int iphicritmincut = settings_.phicritminmc() / globals_->ITC_L1L2()->phi0_final.K(); + int iphicritmaxcut = settings_.phicritmaxmc() / globals_->ITC_L1L2()->phi0_final.K(); + + bool keepapprox = (phicritapprox > settings_.phicritminmc()) && (phicritapprox < settings_.phicritmaxmc()), + keep = (iphicrit > iphicritmincut) && (iphicrit < iphicritmaxcut); + if (settings_.debugTracklet()) + if (keepapprox && !keep) + edm::LogVerbatim("Tracklet") << getName() + << " Tracklet kept with exact phicrit cut but not approximate, phicritapprox: " + << phicritapprox; + if (settings_.usephicritapprox()) { + return keepapprox; + } else { + return keep; + } + + return true; +} + +bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, + const L1TStub* innerStub, + const Stub* outerFPGAStub, + const L1TStub* outerStub) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "TrackletCalculator " << getName() + << " trying stub pair in layer (inner outer): " << innerFPGAStub->layer().value() + << " " << outerFPGAStub->layer().value(); + } + + assert(outerFPGAStub->isBarrel()); + assert(layerdisk1_ == (unsigned int)innerFPGAStub->layer().value()); + assert(layerdisk1_ < N_LAYER && layerdisk2_ < N_LAYER); + + double r1 = innerStub->r(); + double z1 = innerStub->z(); + double phi1 = innerStub->phi(); + + double r2 = outerStub->r(); + double z2 = outerStub->z(); + double phi2 = outerStub->phi(); + + double rinv, phi0, t, z0; + + double phiproj[N_LAYER - 2], zproj[N_LAYER - 2], phider[N_LAYER - 2], zder[N_LAYER - 2]; + double phiprojdisk[N_DISK], rprojdisk[N_DISK], phiderdisk[N_DISK], rderdisk[N_DISK]; + + exacttracklet(r1, + z1, + phi1, + r2, + z2, + phi2, + outerStub->sigmaz(), + rinv, + phi0, + t, + z0, + phiproj, + zproj, + phider, + zder, + phiprojdisk, + rprojdisk, + phiderdisk, + rderdisk); + + if (settings_.useapprox()) { + phi1 = innerFPGAStub->phiapprox(phimin_, phimax_); + z1 = innerFPGAStub->zapprox(); + r1 = innerFPGAStub->rapprox(); + + phi2 = outerFPGAStub->phiapprox(phimin_, phimax_); + z2 = outerFPGAStub->zapprox(); + r2 = outerFPGAStub->rapprox(); + } + + double rinvapprox, phi0approx, tapprox, z0approx; + double phiprojapprox[N_LAYER - 2], zprojapprox[N_LAYER - 2]; + double phiprojdiskapprox[N_DISK], rprojdiskapprox[N_DISK]; + + IMATH_TrackletCalculator* ITC; + if (iSeed_ == 0) + ITC = globals_->ITC_L1L2(); + else if (iSeed_ == 1) + ITC = globals_->ITC_L2L3(); + else if (iSeed_ == 2) + ITC = globals_->ITC_L3L4(); + else + ITC = globals_->ITC_L5L6(); + + ITC->r1.set_fval(r1 - settings_.rmean(layerdisk1_)); + ITC->r2.set_fval(r2 - settings_.rmean(layerdisk2_)); + ITC->z1.set_fval(z1); + ITC->z2.set_fval(z2); + double sphi1 = angle0to2pi::make0To2pi(phi1 - phioffset_); + double sphi2 = angle0to2pi::make0To2pi(phi2 - phioffset_); + + ITC->phi1.set_fval(sphi1); + ITC->phi2.set_fval(sphi2); + + ITC->rproj0.set_fval(settings_.rmean(settings_.projlayers(iSeed_, 0) - 1)); + ITC->rproj1.set_fval(settings_.rmean(settings_.projlayers(iSeed_, 1) - 1)); + ITC->rproj2.set_fval(settings_.rmean(settings_.projlayers(iSeed_, 2) - 1)); + ITC->rproj3.set_fval(settings_.rmean(settings_.projlayers(iSeed_, 3) - 1)); + + ITC->zproj0.set_fval(t > 0 ? settings_.zmean(0) : -settings_.zmean(0)); + ITC->zproj1.set_fval(t > 0 ? settings_.zmean(1) : -settings_.zmean(1)); + ITC->zproj2.set_fval(t > 0 ? settings_.zmean(2) : -settings_.zmean(2)); + ITC->zproj3.set_fval(t > 0 ? settings_.zmean(3) : -settings_.zmean(3)); + ITC->zproj4.set_fval(t > 0 ? settings_.zmean(4) : -settings_.zmean(4)); + + ITC->rinv_final.calculate(); + ITC->phi0_final.calculate(); + ITC->t_final.calculate(); + ITC->z0_final.calculate(); + + ITC->phiL_0_final.calculate(); + ITC->phiL_1_final.calculate(); + ITC->phiL_2_final.calculate(); + ITC->phiL_3_final.calculate(); + + ITC->zL_0_final.calculate(); + ITC->zL_1_final.calculate(); + ITC->zL_2_final.calculate(); + ITC->zL_3_final.calculate(); + + ITC->phiD_0_final.calculate(); + ITC->phiD_1_final.calculate(); + ITC->phiD_2_final.calculate(); + ITC->phiD_3_final.calculate(); + ITC->phiD_4_final.calculate(); + + ITC->rD_0_final.calculate(); + ITC->rD_1_final.calculate(); + ITC->rD_2_final.calculate(); + ITC->rD_3_final.calculate(); + ITC->rD_4_final.calculate(); + + ITC->der_phiL_final.calculate(); + ITC->der_zL_final.calculate(); + ITC->der_phiD_final.calculate(); + ITC->der_rD_final.calculate(); + + //store the approximate results + rinvapprox = ITC->rinv_final.fval(); + phi0approx = ITC->phi0_final.fval(); + tapprox = ITC->t_final.fval(); + z0approx = ITC->z0_final.fval(); + + phiprojapprox[0] = ITC->phiL_0_final.fval(); + phiprojapprox[1] = ITC->phiL_1_final.fval(); + phiprojapprox[2] = ITC->phiL_2_final.fval(); + phiprojapprox[3] = ITC->phiL_3_final.fval(); + + zprojapprox[0] = ITC->zL_0_final.fval(); + zprojapprox[1] = ITC->zL_1_final.fval(); + zprojapprox[2] = ITC->zL_2_final.fval(); + zprojapprox[3] = ITC->zL_3_final.fval(); + + phiprojdiskapprox[0] = ITC->phiD_0_final.fval(); + phiprojdiskapprox[1] = ITC->phiD_1_final.fval(); + phiprojdiskapprox[2] = ITC->phiD_2_final.fval(); + phiprojdiskapprox[3] = ITC->phiD_3_final.fval(); + phiprojdiskapprox[4] = ITC->phiD_4_final.fval(); + + rprojdiskapprox[0] = ITC->rD_0_final.fval(); + rprojdiskapprox[1] = ITC->rD_1_final.fval(); + rprojdiskapprox[2] = ITC->rD_2_final.fval(); + rprojdiskapprox[3] = ITC->rD_3_final.fval(); + rprojdiskapprox[4] = ITC->rD_4_final.fval(); + + //now binary + + int irinv, iphi0, it, iz0; + LayerProjection layerprojs[N_LAYER - 2]; + DiskProjection diskprojs[N_DISK]; + + int iphiproj[N_LAYER - 2], izproj[N_LAYER - 2]; + int iphiprojdisk[N_DISK], irprojdisk[N_DISK]; + + int ir1 = innerFPGAStub->r().value(); + int iphi1 = innerFPGAStub->phi().value(); + int iz1 = innerFPGAStub->z().value(); + + int ir2 = outerFPGAStub->r().value(); + int iphi2 = outerFPGAStub->phi().value(); + int iz2 = outerFPGAStub->z().value(); + + iphi1 <<= (settings_.nphibitsstub(5) - settings_.nphibitsstub(layerdisk1_)); + iphi2 <<= (settings_.nphibitsstub(5) - settings_.nphibitsstub(layerdisk2_)); + ir1 <<= (8 - settings_.nrbitsstub(layerdisk1_)); + ir2 <<= (8 - settings_.nrbitsstub(layerdisk2_)); + + iz1 <<= (settings_.nzbitsstub(0) - settings_.nzbitsstub(layerdisk1_)); + iz2 <<= (settings_.nzbitsstub(0) - settings_.nzbitsstub(layerdisk2_)); + + ITC->r1.set_ival(ir1); + ITC->r2.set_ival(ir2); + ITC->z1.set_ival(iz1); + ITC->z2.set_ival(iz2); + ITC->phi1.set_ival(iphi1); + ITC->phi2.set_ival(iphi2); + + ITC->rinv_final.calculate(); + ITC->phi0_final.calculate(); + ITC->t_final.calculate(); + ITC->z0_final.calculate(); + + ITC->phiL_0_final.calculate(); + ITC->phiL_1_final.calculate(); + ITC->phiL_2_final.calculate(); + ITC->phiL_3_final.calculate(); + + ITC->zL_0_final.calculate(); + ITC->zL_1_final.calculate(); + ITC->zL_2_final.calculate(); + ITC->zL_3_final.calculate(); + + ITC->phiD_0_final.calculate(); + ITC->phiD_1_final.calculate(); + ITC->phiD_2_final.calculate(); + ITC->phiD_3_final.calculate(); + ITC->phiD_4_final.calculate(); + + ITC->rD_0_final.calculate(); + ITC->rD_1_final.calculate(); + ITC->rD_2_final.calculate(); + ITC->rD_3_final.calculate(); + ITC->rD_4_final.calculate(); + + ITC->der_phiL_final.calculate(); + ITC->der_zL_final.calculate(); + ITC->der_phiD_final.calculate(); + ITC->der_rD_final.calculate(); + + //store the binary results + irinv = ITC->rinv_final.ival(); + iphi0 = ITC->phi0_final.ival(); + it = ITC->t_final.ival(); + iz0 = ITC->z0_final.ival(); + + iphiproj[0] = ITC->phiL_0_final.ival(); + iphiproj[1] = ITC->phiL_1_final.ival(); + iphiproj[2] = ITC->phiL_2_final.ival(); + iphiproj[3] = ITC->phiL_3_final.ival(); + + izproj[0] = ITC->zL_0_final.ival(); + izproj[1] = ITC->zL_1_final.ival(); + izproj[2] = ITC->zL_2_final.ival(); + izproj[3] = ITC->zL_3_final.ival(); + + if (!goodTrackPars(ITC->rinv_final.local_passes(), ITC->z0_final.local_passes())) + return false; + + if (!inSector(iphi0, irinv, phi0approx, rinvapprox)) + return false; + + for (unsigned int i = 0; i < N_LAYER - 2; ++i) { + //reject projection if z is out of range + if (izproj[i] < -(1 << (settings_.nzbitsstub(0) - 1))) + continue; + if (izproj[i] >= (1 << (settings_.nzbitsstub(0) - 1))) + continue; + + //reject projection if phi is out of range + if (iphiproj[i] >= (1 << settings_.nphibitsstub(5)) - 1) + continue; + if (iphiproj[i] <= 0) + continue; + + //Adjust bits for r and z projection depending on layer + if (settings_.projlayers(iSeed_, i) <= 3) { //TODO clean up logic + iphiproj[i] >>= (settings_.nphibitsstub(5) - settings_.nphibitsstub(settings_.projlayers(iSeed_, i) - 1)); + } else { + izproj[i] >>= (settings_.nzbitsstub(0) - settings_.nzbitsstub(5)); + } + + layerprojs[i].init(settings_, + settings_.projlayers(iSeed_, i), + settings_.rmean(settings_.projlayers(iSeed_, i) - 1), + iphiproj[i], + izproj[i], + ITC->der_phiL_final.ival(), + ITC->der_zL_final.ival(), + phiproj[i], + zproj[i], + phider[i], + zder[i], + phiprojapprox[i], + zprojapprox[i], + ITC->der_phiL_final.fval(), + ITC->der_zL_final.fval()); + } + + iphiprojdisk[0] = ITC->phiD_0_final.ival(); + iphiprojdisk[1] = ITC->phiD_1_final.ival(); + iphiprojdisk[2] = ITC->phiD_2_final.ival(); + iphiprojdisk[3] = ITC->phiD_3_final.ival(); + iphiprojdisk[4] = ITC->phiD_4_final.ival(); + + irprojdisk[0] = ITC->rD_0_final.ival(); + irprojdisk[1] = ITC->rD_1_final.ival(); + irprojdisk[2] = ITC->rD_2_final.ival(); + irprojdisk[3] = ITC->rD_3_final.ival(); + irprojdisk[4] = ITC->rD_4_final.ival(); + + if (std::abs(it * ITC->t_final.K()) > 1.0) { + for (unsigned int i = 0; i < N_DISK; ++i) { + if (iphiprojdisk[i] <= 0) + continue; + if (iphiprojdisk[i] >= (1 << settings_.nphibitsstub(0)) - 1) + continue; + + if (irprojdisk[i] < settings_.rmindisk() / ITC->rD_0_final.K() || + irprojdisk[i] > settings_.rmaxdisk() / ITC->rD_0_final.K()) + continue; + + diskprojs[i].init(settings_, + i + 1, + settings_.zmean(i), + iphiprojdisk[i], + irprojdisk[i], + ITC->der_phiD_final.ival(), + ITC->der_rD_final.ival(), + phiprojdisk[i], + rprojdisk[i], + phiderdisk[i], + rderdisk[i], + phiprojdiskapprox[i], + rprojdiskapprox[i], + ITC->der_phiD_final.fval(), + ITC->der_rD_final.fval()); + } + } + + if (settings_.writeMonitorData("TPars")) { + globals_->ofstream("trackletpars.txt") + << "Trackpars " << layerdisk1_ + 1 << " " << rinv << " " << rinvapprox << " " << ITC->rinv_final.fval() + << " " << phi0 << " " << phi0approx << " " << ITC->phi0_final.fval() << " " << t << " " << tapprox << " " + << ITC->t_final.fval() << " " << z0 << " " << z0approx << " " << ITC->z0_final.fval() << endl; + } + + Tracklet* tracklet = new Tracklet(settings_, + innerStub, + nullptr, + outerStub, + innerFPGAStub, + nullptr, + outerFPGAStub, + rinv, + phi0, + 0.0, + z0, + t, + rinvapprox, + phi0approx, + 0.0, + z0approx, + tapprox, + irinv, + iphi0, + 0, + iz0, + it, + layerprojs, + diskprojs, + false); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "TrackletCalculator " << getName() << " Found tracklet for seed = " << iSeed_ << " " + << iSector_ << " phi0 = " << phi0; + } + + tracklet->setTrackletIndex(trackletpars_->nTracklets()); + tracklet->setTCIndex(TCIndex_); + + if (settings_.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << tracklet->getISeed() << endl; + fout.close(); + } + trackletpars_->addTracklet(tracklet); + + if (settings_.bookHistos()) { + HistBase* hists = globals_->histograms(); + int tp = tracklet->tpseed(); + hists->fillTrackletParams(settings_, + globals_, + iSeed_, + iSector_, + rinvapprox, + irinv * ITC->rinv_final.K(), + phi0approx, + iphi0 * ITC->phi0_final.K(), + asinh(tapprox), + asinh(it * ITC->t_final.K()), + z0approx, + iz0 * ITC->z0_final.K(), + tp); + } + + bool addL3 = false; + bool addL4 = false; + bool addL5 = false; + bool addL6 = false; + for (unsigned int j = 0; j < N_LAYER - 2; j++) { + int lproj = settings_.projlayers(iSeed_, j); + bool added = false; + if (tracklet->validProj(lproj)) { + added = addLayerProj(tracklet, lproj); + if (added && lproj == 3) + addL3 = true; + if (added && lproj == 4) + addL4 = true; + if (added && lproj == 5) + addL5 = true; + if (added && lproj == 6) + addL6 = true; + } + } + + for (unsigned int j = 0; j < N_DISK - 1; j++) { //no projections to 5th disk!! + int disk = j + 1; + if (disk == 4 && addL3) + continue; + if (disk == 3 && addL4) + continue; + if (disk == 2 && addL5) + continue; + if (disk == 1 && addL6) + continue; + if (it < 0) + disk = -disk; + if (tracklet->validProjDisk(abs(disk))) { + addDiskProj(tracklet, disk); + } + } + + return true; +} + +bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, + const L1TStub* innerStub, + const Stub* outerFPGAStub, + const L1TStub* outerStub) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "TrackletCalculator::execute calculate disk seeds"; + } + + int sign = 1; + if (innerFPGAStub->disk().value() < 0) + sign = -1; + + int disk = innerFPGAStub->disk().value(); + assert(abs(disk) == 1 || abs(disk) == 3); + + assert(innerStub->isPSmodule()); + assert(outerStub->isPSmodule()); + + double r1 = innerStub->r(); + double z1 = innerStub->z(); + double phi1 = innerStub->phi(); + + double r2 = outerStub->r(); + double z2 = outerStub->z(); + double phi2 = outerStub->phi(); + + if (r2 < r1 + 2.0) { + return false; //Protection... Should be handled cleaner to avoid problem with floating point calculation + } + + double rinv, phi0, t, z0; + + double phiproj[N_PSLAYER], zproj[N_PSLAYER], phider[N_PSLAYER], zder[N_PSLAYER]; + double phiprojdisk[N_DISK - 2], rprojdisk[N_DISK - 2], phiderdisk[N_DISK - 2], rderdisk[N_DISK - 2]; + + exacttrackletdisk(r1, + z1, + phi1, + r2, + z2, + phi2, + outerStub->sigmaz(), + rinv, + phi0, + t, + z0, + phiproj, + zproj, + phider, + zder, + phiprojdisk, + rprojdisk, + phiderdisk, + rderdisk); + + //Truncates floating point positions to integer representation precision + if (settings_.useapprox()) { + phi1 = innerFPGAStub->phiapprox(phimin_, phimax_); + z1 = innerFPGAStub->zapprox(); + r1 = innerFPGAStub->rapprox(); + + phi2 = outerFPGAStub->phiapprox(phimin_, phimax_); + z2 = outerFPGAStub->zapprox(); + r2 = outerFPGAStub->rapprox(); + } + + double rinvapprox, phi0approx, tapprox, z0approx; + double phiprojapprox[N_PSLAYER], zprojapprox[N_PSLAYER]; + double phiprojdiskapprox[N_DISK - 2], rprojdiskapprox[N_DISK - 2]; + + IMATH_TrackletCalculatorDisk* ITC; + if (disk == 1) + ITC = globals_->ITC_F1F2(); + else if (disk == 3) + ITC = globals_->ITC_F3F4(); + else if (disk == -1) + ITC = globals_->ITC_B1B2(); + else + ITC = globals_->ITC_B3B4(); + + ITC->r1.set_fval(r1); + ITC->r2.set_fval(r2); + int signt = t > 0 ? 1 : -1; + ITC->z1.set_fval(z1 - signt * settings_.zmean(layerdisk1_ - N_LAYER)); + ITC->z2.set_fval(z2 - signt * settings_.zmean(layerdisk2_ - N_LAYER)); + double sphi1 = angle0to2pi::make0To2pi(phi1 - phioffset_); + double sphi2 = angle0to2pi::make0To2pi(phi2 - phioffset_); + ITC->phi1.set_fval(sphi1); + ITC->phi2.set_fval(sphi2); + + ITC->rproj0.set_fval(settings_.rmean(0)); + ITC->rproj1.set_fval(settings_.rmean(1)); + ITC->rproj2.set_fval(settings_.rmean(2)); + + ITC->zproj0.set_fval(signt * settings_.zmean(settings_.projdisks(iSeed_, 0) - 1)); + ITC->zproj1.set_fval(signt * settings_.zmean(settings_.projdisks(iSeed_, 1) - 1)); + ITC->zproj2.set_fval(signt * settings_.zmean(settings_.projdisks(iSeed_, 2) - 1)); + + ITC->rinv_final.calculate(); + ITC->phi0_final.calculate(); + ITC->t_final.calculate(); + ITC->z0_final.calculate(); + + ITC->phiL_0_final.calculate(); + ITC->phiL_1_final.calculate(); + ITC->phiL_2_final.calculate(); + + ITC->zL_0_final.calculate(); + ITC->zL_1_final.calculate(); + ITC->zL_2_final.calculate(); + + ITC->phiD_0_final.calculate(); + ITC->phiD_1_final.calculate(); + ITC->phiD_2_final.calculate(); + + ITC->rD_0_final.calculate(); + ITC->rD_1_final.calculate(); + ITC->rD_2_final.calculate(); + + ITC->der_phiL_final.calculate(); + ITC->der_zL_final.calculate(); + ITC->der_phiD_final.calculate(); + ITC->der_rD_final.calculate(); + + //store the approximate results + rinvapprox = ITC->rinv_final.fval(); + phi0approx = ITC->phi0_final.fval(); + tapprox = ITC->t_final.fval(); + z0approx = ITC->z0_final.fval(); + + phiprojapprox[0] = ITC->phiL_0_final.fval(); + phiprojapprox[1] = ITC->phiL_1_final.fval(); + phiprojapprox[2] = ITC->phiL_2_final.fval(); + + zprojapprox[0] = ITC->zL_0_final.fval(); + zprojapprox[1] = ITC->zL_1_final.fval(); + zprojapprox[2] = ITC->zL_2_final.fval(); + + phiprojdiskapprox[0] = ITC->phiD_0_final.fval(); + phiprojdiskapprox[1] = ITC->phiD_1_final.fval(); + phiprojdiskapprox[2] = ITC->phiD_2_final.fval(); + + rprojdiskapprox[0] = ITC->rD_0_final.fval(); + rprojdiskapprox[1] = ITC->rD_1_final.fval(); + rprojdiskapprox[2] = ITC->rD_2_final.fval(); + + //now binary + + int irinv, iphi0, it, iz0; + int iphiproj[N_PSLAYER], izproj[N_PSLAYER]; + + int iphiprojdisk[N_DISK - 2], irprojdisk[N_DISK - 2]; + + int ir1 = innerFPGAStub->r().value(); + int iphi1 = innerFPGAStub->phi().value(); + int iz1 = innerFPGAStub->z().value(); + + int ir2 = outerFPGAStub->r().value(); + int iphi2 = outerFPGAStub->phi().value(); + int iz2 = outerFPGAStub->z().value(); + + //To get same precission as for layers. + iphi1 <<= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); + iphi2 <<= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); + + ITC->r1.set_ival(ir1); + ITC->r2.set_ival(ir2); + ITC->z1.set_ival(iz1); + ITC->z2.set_ival(iz2); + ITC->phi1.set_ival(iphi1); + ITC->phi2.set_ival(iphi2); + + ITC->rinv_final.calculate(); + ITC->phi0_final.calculate(); + ITC->t_final.calculate(); + ITC->z0_final.calculate(); + + ITC->phiL_0_final.calculate(); + ITC->phiL_1_final.calculate(); + ITC->phiL_2_final.calculate(); + + ITC->zL_0_final.calculate(); + ITC->zL_1_final.calculate(); + ITC->zL_2_final.calculate(); + + ITC->phiD_0_final.calculate(); + ITC->phiD_1_final.calculate(); + ITC->phiD_2_final.calculate(); + + ITC->rD_0_final.calculate(); + ITC->rD_1_final.calculate(); + ITC->rD_2_final.calculate(); + + ITC->der_phiL_final.calculate(); + ITC->der_zL_final.calculate(); + ITC->der_phiD_final.calculate(); + ITC->der_rD_final.calculate(); + + //store the binary results + irinv = ITC->rinv_final.ival(); + iphi0 = ITC->phi0_final.ival(); + it = ITC->t_final.ival(); + iz0 = ITC->z0_final.ival(); + + iphiproj[0] = ITC->phiL_0_final.ival(); + iphiproj[1] = ITC->phiL_1_final.ival(); + iphiproj[2] = ITC->phiL_2_final.ival(); + + izproj[0] = ITC->zL_0_final.ival(); + izproj[1] = ITC->zL_1_final.ival(); + izproj[2] = ITC->zL_2_final.ival(); + + if (!goodTrackPars(ITC->rinv_final.local_passes(), ITC->z0_final.local_passes())) + return false; + + if (!inSector(iphi0, irinv, phi0approx, rinvapprox)) + return false; + + LayerProjection layerprojs[N_LAYER - 2]; + DiskProjection diskprojs[N_DISK - 2]; + + for (unsigned int i = 0; i < N_DISK - 2; ++i) { + //Check is outside z range + if (izproj[i] < -(1 << (settings_.nzbitsstub(0) - 1))) + continue; + if (izproj[i] >= (1 << (settings_.nzbitsstub(0) - 1))) + continue; + + //Check if outside phi range + if (iphiproj[i] >= (1 << settings_.nphibitsstub(5)) - 1) + continue; + if (iphiproj[i] <= 0) + continue; + + //shift bits - allways in PS modules for disk seeding + iphiproj[i] >>= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); + + layerprojs[i].init(settings_, + i + 1, + settings_.rmean(i), + iphiproj[i], + izproj[i], + ITC->der_phiL_final.ival(), + ITC->der_zL_final.ival(), + phiproj[i], + zproj[i], + phider[i], + zder[i], + phiprojapprox[i], + zprojapprox[i], + ITC->der_phiL_final.fval(), + ITC->der_zL_final.fval()); + } + + iphiprojdisk[0] = ITC->phiD_0_final.ival(); + iphiprojdisk[1] = ITC->phiD_1_final.ival(); + iphiprojdisk[2] = ITC->phiD_2_final.ival(); + + irprojdisk[0] = ITC->rD_0_final.ival(); + irprojdisk[1] = ITC->rD_1_final.ival(); + irprojdisk[2] = ITC->rD_2_final.ival(); + + for (unsigned int i = 0; i < N_DISK - 2; ++i) { + //check that phi projection in range + if (iphiprojdisk[i] <= 0) + continue; + if (iphiprojdisk[i] >= (1 << settings_.nphibitsstub(0)) - 1) + continue; + + //check that r projection in range + if (irprojdisk[i] <= 0 || irprojdisk[i] > settings_.rmaxdisk() / ITC->rD_0_final.K()) + continue; + + diskprojs[i].init(settings_, + i + 1, + settings_.zmean(settings_.projdisks(iSeed_, i) - 1), + iphiprojdisk[i], + irprojdisk[i], + ITC->der_phiD_final.ival(), + ITC->der_rD_final.ival(), + phiprojdisk[i], + rprojdisk[i], + phiderdisk[i], + rderdisk[i], + phiprojdiskapprox[i], + rprojdiskapprox[i], + ITC->der_phiD_final.fval(), + ITC->der_rD_final.fval()); + } + + if (settings_.writeMonitorData("TPars")) { + globals_->ofstream("trackletparsdisk.txt") + << "Trackpars " << layerdisk1_ - 5 << " " << rinv << " " << rinvapprox << " " + << ITC->rinv_final.fval() << " " << phi0 << " " << phi0approx << " " << ITC->phi0_final.fval() << " " << t + << " " << tapprox << " " << ITC->t_final.fval() << " " << z0 << " " << z0approx << " " << ITC->z0_final.fval() + << endl; + } + + Tracklet* tracklet = new Tracklet(settings_, + innerStub, + nullptr, + outerStub, + innerFPGAStub, + nullptr, + outerFPGAStub, + rinv, + phi0, + 0.0, + z0, + t, + rinvapprox, + phi0approx, + 0.0, + z0approx, + tapprox, + irinv, + iphi0, + 0, + iz0, + it, + layerprojs, + diskprojs, + true); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Found tracklet for seed = " << iSeed_ << " " << tracklet << " " << iSector_; + } + + tracklet->setTrackletIndex(trackletpars_->nTracklets()); + tracklet->setTCIndex(TCIndex_); + + if (settings_.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << tracklet->getISeed() << endl; + fout.close(); + } + trackletpars_->addTracklet(tracklet); + + if (tracklet->validProj(1)) { + addLayerProj(tracklet, 1); + } + + if (tracklet->validProj(2)) { + addLayerProj(tracklet, 2); + } + + for (unsigned int j = 0; j < N_DISK - 2; j++) { + if (tracklet->validProjDisk(sign * settings_.projdisks(iSeed_, j))) { + addDiskProj(tracklet, sign * settings_.projdisks(iSeed_, j)); + } + } + + return true; +} + +bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, + const L1TStub* innerStub, + const Stub* outerFPGAStub, + const L1TStub* outerStub) { + //Deal with overlap stubs here + assert(outerFPGAStub->isBarrel()); + + assert(innerFPGAStub->isDisk()); + + int disk = innerFPGAStub->disk().value(); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "trying to make overlap tracklet for seed = " << iSeed_ << " " << getName(); + } + + double r1 = innerStub->r(); + double z1 = innerStub->z(); + double phi1 = innerStub->phi(); + + double r2 = outerStub->r(); + double z2 = outerStub->z(); + double phi2 = outerStub->phi(); + + //Protection for wrong radii. Could be handled cleaner to avoid problem with floating point calculation and with overflows in the integer calculation. + if (r1 < r2 + 1.5) { + return false; + } + + double rinv, phi0, t, z0; + + double phiproj[N_PSLAYER], zproj[N_PSLAYER], phider[N_PSLAYER], zder[N_PSLAYER]; + double phiprojdisk[N_DISK - 1], rprojdisk[N_DISK - 1], phiderdisk[N_DISK - 1], rderdisk[N_DISK - 1]; + + exacttrackletOverlap(r1, + z1, + phi1, + r2, + z2, + phi2, + outerStub->sigmaz(), + rinv, + phi0, + t, + z0, + phiproj, + zproj, + phider, + zder, + phiprojdisk, + rprojdisk, + phiderdisk, + rderdisk); + + //Truncates floating point positions to integer representation precision + if (settings_.useapprox()) { + phi1 = innerFPGAStub->phiapprox(phimin_, phimax_); + z1 = innerFPGAStub->zapprox(); + r1 = innerFPGAStub->rapprox(); + + phi2 = outerFPGAStub->phiapprox(phimin_, phimax_); + z2 = outerFPGAStub->zapprox(); + r2 = outerFPGAStub->rapprox(); + } + + double rinvapprox, phi0approx, tapprox, z0approx; + double phiprojapprox[N_PSLAYER], zprojapprox[N_PSLAYER]; + double phiprojdiskapprox[N_DISK - 1], rprojdiskapprox[N_DISK - 1]; + + IMATH_TrackletCalculatorOverlap* ITC; + int ll = outerFPGAStub->layer().value() + 1; + if (ll == 1 && disk == 1) + ITC = globals_->ITC_L1F1(); + else if (ll == 2 && disk == 1) + ITC = globals_->ITC_L2F1(); + else if (ll == 1 && disk == -1) + ITC = globals_->ITC_L1B1(); + else if (ll == 2 && disk == -1) + ITC = globals_->ITC_L2B1(); + else + throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Invalid seeding!"; + + ITC->r1.set_fval(r2 - settings_.rmean(ll - 1)); + ITC->r2.set_fval(r1); + int signt = t > 0 ? 1 : -1; + ITC->z1.set_fval(z2); + ITC->z2.set_fval(z1 - signt * settings_.zmean(layerdisk2_ - N_LAYER)); + double sphi1 = angle0to2pi::make0To2pi(phi1 - phioffset_); + double sphi2 = angle0to2pi::make0To2pi(phi2 - phioffset_); + ITC->phi1.set_fval(sphi2); + ITC->phi2.set_fval(sphi1); + + ITC->rproj0.set_fval(settings_.rmean(0)); + ITC->rproj1.set_fval(settings_.rmean(1)); + ITC->rproj2.set_fval(settings_.rmean(2)); + + ITC->zproj0.set_fval(signt * settings_.zmean(1)); + ITC->zproj1.set_fval(signt * settings_.zmean(2)); + ITC->zproj2.set_fval(signt * settings_.zmean(3)); + ITC->zproj3.set_fval(signt * settings_.zmean(4)); + + ITC->rinv_final.calculate(); + ITC->phi0_final.calculate(); + ITC->t_final.calculate(); + ITC->z0_final.calculate(); + + ITC->phiL_0_final.calculate(); + ITC->phiL_1_final.calculate(); + ITC->phiL_2_final.calculate(); + + ITC->zL_0_final.calculate(); + ITC->zL_1_final.calculate(); + ITC->zL_2_final.calculate(); + + ITC->phiD_0_final.calculate(); + ITC->phiD_1_final.calculate(); + ITC->phiD_2_final.calculate(); + ITC->phiD_3_final.calculate(); + + ITC->rD_0_final.calculate(); + ITC->rD_1_final.calculate(); + ITC->rD_2_final.calculate(); + ITC->rD_3_final.calculate(); + + ITC->der_phiL_final.calculate(); + ITC->der_zL_final.calculate(); + ITC->der_phiD_final.calculate(); + ITC->der_rD_final.calculate(); + + //store the approximate results + rinvapprox = ITC->rinv_final.fval(); + phi0approx = ITC->phi0_final.fval(); + tapprox = ITC->t_final.fval(); + z0approx = ITC->z0_final.fval(); + + phiprojapprox[0] = ITC->phiL_0_final.fval(); + phiprojapprox[1] = ITC->phiL_1_final.fval(); + phiprojapprox[2] = ITC->phiL_2_final.fval(); + + zprojapprox[0] = ITC->zL_0_final.fval(); + zprojapprox[1] = ITC->zL_1_final.fval(); + zprojapprox[2] = ITC->zL_2_final.fval(); + + phiprojdiskapprox[0] = ITC->phiD_0_final.fval(); + phiprojdiskapprox[1] = ITC->phiD_1_final.fval(); + phiprojdiskapprox[2] = ITC->phiD_2_final.fval(); + phiprojdiskapprox[3] = ITC->phiD_3_final.fval(); + + rprojdiskapprox[0] = ITC->rD_0_final.fval(); + rprojdiskapprox[1] = ITC->rD_1_final.fval(); + rprojdiskapprox[2] = ITC->rD_2_final.fval(); + rprojdiskapprox[3] = ITC->rD_3_final.fval(); + + //now binary + + int irinv, iphi0, it, iz0; + int iphiproj[N_LAYER - 2], izproj[N_LAYER - 2]; + int iphiprojdisk[N_DISK], irprojdisk[N_DISK]; + + int ir2 = innerFPGAStub->r().value(); + int iphi2 = innerFPGAStub->phi().value(); + int iz2 = innerFPGAStub->z().value(); + + int ir1 = outerFPGAStub->r().value(); + int iphi1 = outerFPGAStub->phi().value(); + int iz1 = outerFPGAStub->z().value(); + + //To get global precission + ir1 <<= (8 - settings_.nrbitsstub(ll - 1)); + iphi1 <<= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); + iphi2 <<= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); + + ITC->r1.set_ival(ir1); + ITC->r2.set_ival(ir2); + ITC->z1.set_ival(iz1); + ITC->z2.set_ival(iz2); + ITC->phi1.set_ival(iphi1); + ITC->phi2.set_ival(iphi2); + + ITC->rinv_final.calculate(); + ITC->phi0_final.calculate(); + ITC->t_final.calculate(); + ITC->z0_final.calculate(); + + ITC->phiL_0_final.calculate(); + ITC->phiL_1_final.calculate(); + ITC->phiL_2_final.calculate(); + + ITC->zL_0_final.calculate(); + ITC->zL_1_final.calculate(); + ITC->zL_2_final.calculate(); + + ITC->phiD_0_final.calculate(); + ITC->phiD_1_final.calculate(); + ITC->phiD_2_final.calculate(); + ITC->phiD_3_final.calculate(); + + ITC->rD_0_final.calculate(); + ITC->rD_1_final.calculate(); + ITC->rD_2_final.calculate(); + ITC->rD_3_final.calculate(); + + ITC->der_phiL_final.calculate(); + ITC->der_zL_final.calculate(); + ITC->der_phiD_final.calculate(); + ITC->der_rD_final.calculate(); + + //store the binary results + irinv = ITC->rinv_final.ival(); + iphi0 = ITC->phi0_final.ival(); + it = ITC->t_final.ival(); + iz0 = ITC->z0_final.ival(); + + iphiproj[0] = ITC->phiL_0_final.ival(); + iphiproj[1] = ITC->phiL_1_final.ival(); + iphiproj[2] = ITC->phiL_2_final.ival(); + + izproj[0] = ITC->zL_0_final.ival(); + izproj[1] = ITC->zL_1_final.ival(); + izproj[2] = ITC->zL_2_final.ival(); + + iphiprojdisk[0] = ITC->phiD_0_final.ival(); + iphiprojdisk[1] = ITC->phiD_1_final.ival(); + iphiprojdisk[2] = ITC->phiD_2_final.ival(); + iphiprojdisk[3] = ITC->phiD_3_final.ival(); + + irprojdisk[0] = ITC->rD_0_final.ival(); + irprojdisk[1] = ITC->rD_1_final.ival(); + irprojdisk[2] = ITC->rD_2_final.ival(); + irprojdisk[3] = ITC->rD_3_final.ival(); + + if (!goodTrackPars(ITC->rinv_final.local_passes(), ITC->z0_final.local_passes())) + return false; + + if (!inSector(iphi0, irinv, phi0approx, rinvapprox)) + return false; + + LayerProjection layerprojs[N_LAYER - 2]; + DiskProjection diskprojs[N_DISK]; + + for (unsigned int i = 0; i < N_DISK - 2; ++i) { + //check that zproj is in range + if (izproj[i] < -(1 << (settings_.nzbitsstub(0) - 1))) + continue; + if (izproj[i] >= (1 << (settings_.nzbitsstub(0) - 1))) + continue; + + //check that phiproj is in range + if (iphiproj[i] >= (1 << settings_.nphibitsstub(5)) - 1) + continue; + if (iphiproj[i] <= 0) + continue; + + //adjust bits for PS modules (no 2S modules in overlap seeds) + iphiproj[i] >>= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); + + layerprojs[i].init(settings_, + i + 1, + settings_.rmean(i), + iphiproj[i], + izproj[i], + ITC->der_phiL_final.ival(), + ITC->der_zL_final.ival(), + phiproj[i], + zproj[i], + phider[i], + zder[i], + phiprojapprox[i], + zprojapprox[i], + ITC->der_phiL_final.fval(), + ITC->der_zL_final.fval()); + } + + for (int i = 0; i < 4; ++i) { + //check that phi projection in range + if (iphiprojdisk[i] <= 0) + continue; + if (iphiprojdisk[i] >= (1 << settings_.nphibitsstub(0)) - 1) + continue; + + //check that r projection in range + if (irprojdisk[i] <= 0 || irprojdisk[i] > settings_.rmaxdisk() / ITC->rD_0_final.K()) + continue; + + diskprojs[i].init(settings_, + i + 1, + settings_.zmean(i), + iphiprojdisk[i], + irprojdisk[i], + ITC->der_phiD_final.ival(), + ITC->der_rD_final.ival(), + phiprojdisk[i], + rprojdisk[i], + phiderdisk[i], + rderdisk[i], + phiprojdiskapprox[i], + rprojdiskapprox[i], + ITC->der_phiD_final.fval(), + ITC->der_rD_final.fval()); + } + + if (settings_.writeMonitorData("TPars")) { + globals_->ofstream("trackletparsoverlap.txt") + << "Trackpars " << layerdisk1_ - 5 << " " << rinv << " " << irinv << " " << ITC->rinv_final.fval() << " " + << phi0 << " " << iphi0 << " " << ITC->phi0_final.fval() << " " << t << " " << it << " " + << ITC->t_final.fval() << " " << z0 << " " << iz0 << " " << ITC->z0_final.fval() << endl; + } + + Tracklet* tracklet = new Tracklet(settings_, + innerStub, + nullptr, + outerStub, + innerFPGAStub, + nullptr, + outerFPGAStub, + rinv, + phi0, + 0.0, + z0, + t, + rinvapprox, + phi0approx, + 0.0, + z0approx, + tapprox, + irinv, + iphi0, + 0, + iz0, + it, + layerprojs, + diskprojs, + false, + true); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Found tracklet in overlap seed = " << iSeed_ << " " << tracklet << " " << iSector_; + } + + tracklet->setTrackletIndex(trackletpars_->nTracklets()); + tracklet->setTCIndex(TCIndex_); + + if (settings_.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << tracklet->getISeed() << endl; + fout.close(); + } + trackletpars_->addTracklet(tracklet); + + int layer = outerFPGAStub->layer().value() + 1; + + if (layer == 2) { + if (tracklet->validProj(1)) { + addLayerProj(tracklet, 1); + } + } + + for (unsigned int disk = 2; disk < 6; disk++) { + if (layer == 2 && disk == 5) + continue; + if (tracklet->validProjDisk(disk)) { + addDiskProj(tracklet, disk); + } + } + + return true; +} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc new file mode 100644 index 0000000000000..08932b5d42efc --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc @@ -0,0 +1,1526 @@ +#include "L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorDisplaced.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" +#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" +#include "DataFormats/Math/interface/deltaPhi.h" + +using namespace std; +using namespace trklet; + +constexpr double triplet_phioffset = 0.171; + +TrackletCalculatorDisplaced::TrackletCalculatorDisplaced(string name, + Settings const& settings, + Globals* global, + unsigned int iSector) + : ProcessBase(name, settings, global, iSector) { + for (unsigned int ilayer = 0; ilayer < N_LAYER; ilayer++) { + vector tmp(settings.nallstubs(ilayer), nullptr); + trackletprojlayers_.push_back(tmp); + } + + for (unsigned int idisk = 0; idisk < N_DISK; idisk++) { + vector tmp(settings.nallstubs(idisk + N_LAYER), nullptr); + trackletprojdisks_.push_back(tmp); + } + + layer_ = 0; + disk_ = 0; + + string name1 = name.substr(1); //this is to correct for "TCD" having one more letter then "TC" + if (name1[3] == 'L') + layer_ = name1[4] - '0'; + if (name1[3] == 'D') + disk_ = name1[4] - '0'; + + // set TC index + int iSeed = -1; + + int iTC = name1[9] - 'A'; + + if (name1.substr(3, 6) == "L3L4L2") + iSeed = 8; + else if (name1.substr(3, 6) == "L5L6L4") + iSeed = 9; + else if (name1.substr(3, 6) == "L2L3D1") + iSeed = 10; + else if (name1.substr(3, 6) == "D1D2L2") + iSeed = 11; + + assert(iSeed != -1); + + TCIndex_ = (iSeed << 4) + iTC; + assert(TCIndex_ >= 128 && TCIndex_ < 191); + + assert((layer_ != 0) || (disk_ != 0)); + + toR_.clear(); + toZ_.clear(); + + if (iSeed == 8 || iSeed == 9) { + if (layer_ == 3) { + rproj_[0] = settings_.rmean(0); + rproj_[1] = settings_.rmean(4); + rproj_[2] = settings_.rmean(5); + lproj_[0] = 1; + lproj_[1] = 5; + lproj_[2] = 6; + + dproj_[0] = 1; + dproj_[1] = 2; + dproj_[2] = 0; + toZ_.push_back(settings_.zmean(0)); + toZ_.push_back(settings_.zmean(1)); + } + if (layer_ == 5) { + rproj_[0] = settings_.rmean(0); + rproj_[1] = settings_.rmean(1); + rproj_[2] = settings_.rmean(2); + lproj_[0] = 1; + lproj_[1] = 2; + lproj_[2] = 3; + + dproj_[0] = 0; + dproj_[1] = 0; + dproj_[2] = 0; + } + for (unsigned int i = 0; i < N_LAYER - 3; ++i) + toR_.push_back(rproj_[i]); + } + + if (iSeed == 10 || iSeed == 11) { + if (layer_ == 2) { + rproj_[0] = settings_.rmean(0); + lproj_[0] = 1; + lproj_[1] = -1; + lproj_[2] = -1; + + zproj_[0] = settings_.zmean(1); + zproj_[1] = settings_.zmean(2); + zproj_[2] = settings_.zmean(3); + dproj_[0] = 2; + dproj_[1] = 3; + dproj_[2] = 4; + } + if (disk_ == 1) { + rproj_[0] = settings_.rmean(0); + lproj_[0] = 1; + lproj_[1] = -1; + lproj_[2] = -1; + + zproj_[0] = settings_.zmean(2); + zproj_[1] = settings_.zmean(3); + zproj_[2] = settings_.zmean(4); + dproj_[0] = 3; + dproj_[1] = 4; + dproj_[2] = 5; + } + toR_.push_back(settings_.rmean(0)); + for (unsigned int i = 0; i < N_DISK - 2; ++i) + toZ_.push_back(zproj_[i]); + } +} + +void TrackletCalculatorDisplaced::addOutputProjection(TrackletProjectionsMemory*& outputProj, MemoryBase* memory) { + outputProj = dynamic_cast(memory); + assert(outputProj != nullptr); +} + +void TrackletCalculatorDisplaced::addOutput(MemoryBase* memory, string output) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " + << output; + } + if (output == "trackpar") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + trackletpars_ = tmp; + return; + } + + if (output.substr(0, 7) == "projout") { + //output is on the form 'projoutL2PHIC' or 'projoutD3PHIB' + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + + unsigned int layerdisk = output[8] - '1'; //layer or disk counting from 0 + unsigned int phiregion = output[12] - 'A'; //phiregion counting from 0 + + if (output[7] == 'L') { + assert(layerdisk < N_LAYER); + assert(phiregion < trackletprojlayers_[layerdisk].size()); + //check that phiregion not already initialized + assert(trackletprojlayers_[layerdisk][phiregion] == nullptr); + trackletprojlayers_[layerdisk][phiregion] = tmp; + return; + } + + if (output[7] == 'D') { + assert(layerdisk < N_DISK); + assert(phiregion < trackletprojdisks_[layerdisk].size()); + //check that phiregion not already initialized + assert(trackletprojdisks_[layerdisk][phiregion] == nullptr); + trackletprojdisks_[layerdisk][phiregion] = tmp; + return; + } + } + + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output; +} + +void TrackletCalculatorDisplaced::addInput(MemoryBase* memory, string input) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " + << input; + } + if (input == "thirdallstubin") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + innerallstubs_.push_back(tmp); + return; + } + if (input == "firstallstubin") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + middleallstubs_.push_back(tmp); + return; + } + if (input == "secondallstubin") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + outerallstubs_.push_back(tmp); + return; + } + if (input.find("stubtriplet") == 0) { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + stubtriplets_.push_back(tmp); + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input; +} + +void TrackletCalculatorDisplaced::execute() { + unsigned int countall = 0; + unsigned int countsel = 0; + + for (auto& stubtriplet : stubtriplets_) { + if (trackletpars_->nTracklets() >= settings_.ntrackletmax()) { + edm::LogVerbatim("Tracklet") << "Will break on too many tracklets in " << getName(); + break; + } + for (unsigned int i = 0; i < stubtriplet->nStubTriplets(); i++) { + countall++; + + const Stub* innerFPGAStub = stubtriplet->getFPGAStub1(i); + const L1TStub* innerStub = innerFPGAStub->l1tstub(); + + const Stub* middleFPGAStub = stubtriplet->getFPGAStub2(i); + const L1TStub* middleStub = middleFPGAStub->l1tstub(); + + const Stub* outerFPGAStub = stubtriplet->getFPGAStub3(i); + const L1TStub* outerStub = outerFPGAStub->l1tstub(); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced execute " << getName() << "[" << iSector_ << "]"; + } + + if (innerFPGAStub->isBarrel() && middleFPGAStub->isBarrel() && outerFPGAStub->isBarrel()) { + //barrel+barrel seeding + bool accept = LLLSeeding(innerFPGAStub, innerStub, middleFPGAStub, middleStub, outerFPGAStub, outerStub); + if (accept) + countsel++; + } else if (innerFPGAStub->isDisk() && middleFPGAStub->isDisk() && outerFPGAStub->isDisk()) { + throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Invalid seeding!"; + } else { + //layer+disk seeding + if (innerFPGAStub->isBarrel() && middleFPGAStub->isDisk() && outerFPGAStub->isDisk()) { //D1D2L2 + bool accept = DDLSeeding(innerFPGAStub, innerStub, middleFPGAStub, middleStub, outerFPGAStub, outerStub); + if (accept) + countsel++; + } else if (innerFPGAStub->isDisk() && middleFPGAStub->isBarrel() && outerFPGAStub->isBarrel()) { //L2L3D1 + bool accept = LLDSeeding(innerFPGAStub, innerStub, middleFPGAStub, middleStub, outerFPGAStub, outerStub); + if (accept) + countsel++; + } else { + throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Invalid seeding!"; + } + } + + if (trackletpars_->nTracklets() >= settings_.ntrackletmax()) { + edm::LogVerbatim("Tracklet") << "Will break on number of tracklets in " << getName(); + break; + } + + if (countall >= settings_.maxStep("TC")) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Will break on MAXTC 1"; + break; + } + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced execute done"; + } + } + if (countall >= settings_.maxStep("TC")) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Will break on MAXTC 2"; + break; + } + } + + if (settings_.writeMonitorData("TPD")) { + globals_->ofstream("trackletcalculatordisplaced.txt") << getName() << " " << countall << " " << countsel << endl; + } +} + +void TrackletCalculatorDisplaced::addDiskProj(Tracklet* tracklet, int disk) { + FPGAWord fpgar = tracklet->fpgarprojdisk(disk); + + if (fpgar.value() * settings_.krprojshiftdisk() < settings_.rmindiskvm()) + return; + if (fpgar.value() * settings_.krprojshiftdisk() > settings_.rmaxdisk()) + return; + + FPGAWord fpgaphi = tracklet->fpgaphiprojdisk(disk); + + int iphivmRaw = fpgaphi.value() >> (fpgaphi.nbits() - 5); + int iphi = iphivmRaw / (32 / settings_.nallstubs(abs(disk) + N_DISK)); + + addProjectionDisk(disk, iphi, trackletprojdisks_[abs(disk) - 1][iphi], tracklet); +} + +bool TrackletCalculatorDisplaced::addLayerProj(Tracklet* tracklet, int layer) { + assert(layer > 0); + + FPGAWord fpgaz = tracklet->fpgazproj(layer); + FPGAWord fpgaphi = tracklet->fpgaphiproj(layer); + + if (fpgaphi.atExtreme()) + edm::LogProblem("Tracklet") << "at extreme! " << fpgaphi.value(); + + assert(!fpgaphi.atExtreme()); + + if (fpgaz.atExtreme()) + return false; + + if (std::abs(fpgaz.value() * settings_.kz()) > settings_.zlength()) + return false; + + int iphivmRaw = fpgaphi.value() >> (fpgaphi.nbits() - 5); + int iphi = iphivmRaw / (32 / settings_.nallstubs(layer - 1)); + + addProjection(layer, iphi, trackletprojlayers_[layer - 1][iphi], tracklet); + + return true; +} + +void TrackletCalculatorDisplaced::addProjection(int layer, + int iphi, + TrackletProjectionsMemory* trackletprojs, + Tracklet* tracklet) { + if (trackletprojs == nullptr) { + if (settings_.warnNoMem()) { + edm::LogVerbatim("Tracklet") << "No projection memory exists in " << getName() << " for layer = " << layer + << " iphi = " << iphi + 1; + } + return; + } + assert(trackletprojs != nullptr); + trackletprojs->addProj(tracklet); +} + +void TrackletCalculatorDisplaced::addProjectionDisk(int disk, + int iphi, + TrackletProjectionsMemory* trackletprojs, + Tracklet* tracklet) { + if (trackletprojs == nullptr) { + if (layer_ == 3 && abs(disk) == 3) + return; //L3L4 projections to D3 are not used. + if (settings_.warnNoMem()) { + edm::LogVerbatim("Tracklet") << "No projection memory exists in " << getName() << " for disk = " << abs(disk) + << " iphi = " << iphi + 1; + } + return; + } + assert(trackletprojs != nullptr); + trackletprojs->addProj(tracklet); +} + +bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, + const L1TStub* innerStub, + const Stub* middleFPGAStub, + const L1TStub* middleStub, + const Stub* outerFPGAStub, + const L1TStub* outerStub) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced " << getName() << " " << layer_ + << " trying stub triplet in layer (L L L): " << innerFPGAStub->layer().value() << " " + << middleFPGAStub->layer().value() << " " << outerFPGAStub->layer().value(); + } + + assert(outerFPGAStub->isBarrel()); + + double r1 = innerStub->r(); + double z1 = innerStub->z(); + double phi1 = innerStub->phi(); + + double r2 = middleStub->r(); + double z2 = middleStub->z(); + double phi2 = middleStub->phi(); + + double r3 = outerStub->r(); + double z3 = outerStub->z(); + double phi3 = outerStub->phi(); + + int take3 = 0; + if (layer_ == 5) + take3 = 1; + + double rinv, phi0, d0, t, z0; + + LayerProjection layerprojs[N_LAYER - 2]; + DiskProjection diskprojs[N_DISK]; + + double phiproj[N_LAYER - 2], zproj[N_LAYER - 2], phider[N_LAYER - 2], zder[N_LAYER - 2]; + double phiprojdisk[N_DISK], rprojdisk[N_DISK], phiderdisk[N_DISK], rderdisk[N_DISK]; + + exacttracklet(r1, + z1, + phi1, + r2, + z2, + phi2, + r3, + z3, + phi3, + take3, + rinv, + phi0, + d0, + t, + z0, + phiproj, + zproj, + phiprojdisk, + rprojdisk, + phider, + zder, + phiderdisk, + rderdisk); + + if (settings_.useapprox()) { + phi1 = innerFPGAStub->phiapprox(phimin_, phimax_); + z1 = innerFPGAStub->zapprox(); + r1 = innerFPGAStub->rapprox(); + + phi2 = outerFPGAStub->phiapprox(phimin_, phimax_); + z2 = outerFPGAStub->zapprox(); + r2 = outerFPGAStub->rapprox(); + } + + double rinvapprox, phi0approx, d0approx, tapprox, z0approx; + double phiprojapprox[N_LAYER - 2], zprojapprox[N_LAYER - 2], phiderapprox[N_LAYER - 2], zderapprox[N_LAYER - 2]; + double phiprojdiskapprox[N_DISK], rprojdiskapprox[N_DISK]; + double phiderdiskapprox[N_DISK], rderdiskapprox[N_DISK]; + + //TODO: implement the actual integer calculation + phi0 -= triplet_phioffset; + + //store the approcximate results + rinvapprox = rinv; + phi0approx = phi0; + d0approx = d0; + tapprox = t; + z0approx = z0; + + for (unsigned int i = 0; i < toR_.size(); ++i) { + phiproj[i] -= triplet_phioffset; + phiprojapprox[i] = phiproj[i]; + zprojapprox[i] = zproj[i]; + phiderapprox[i] = phider[i]; + zderapprox[i] = zder[i]; + } + + for (unsigned int i = 0; i < toZ_.size(); ++i) { + phiprojdisk[i] -= triplet_phioffset; + phiprojdiskapprox[i] = phiprojdisk[i]; + rprojdiskapprox[i] = rprojdisk[i]; + phiderdiskapprox[i] = phiderdisk[i]; + rderdiskapprox[i] = rderdisk[i]; + } + + //now binary + double krinv = settings_.kphi1() / settings_.kr() * pow(2, settings_.rinv_shift()), + kphi0 = settings_.kphi1() * pow(2, settings_.phi0_shift()), + kt = settings_.kz() / settings_.kr() * pow(2, settings_.t_shift()), + kz0 = settings_.kz() * pow(2, settings_.z0_shift()), + kphiproj = settings_.kphi1() * pow(2, settings_.SS_phiL_shift()), + kphider = settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderL_shift()), + kzproj = settings_.kz() * pow(2, settings_.PS_zL_shift()), + kzder = settings_.kz() / settings_.kr() * pow(2, settings_.PS_zderL_shift()), + kphiprojdisk = settings_.kphi1() * pow(2, settings_.SS_phiD_shift()), + kphiderdisk = settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderD_shift()), + krprojdisk = settings_.kr() * pow(2, settings_.PS_rD_shift()), + krderdisk = settings_.kr() / settings_.kz() * pow(2, settings_.PS_rderD_shift()); + + int irinv, iphi0, id0, it, iz0; + int iphiproj[N_LAYER - 2], izproj[N_LAYER - 2], iphider[N_LAYER - 2], izder[N_LAYER - 2]; + int iphiprojdisk[N_DISK], irprojdisk[N_DISK], iphiderdisk[N_DISK], irderdisk[N_DISK]; + + //store the binary results + irinv = rinvapprox / krinv; + iphi0 = phi0approx / kphi0; + id0 = d0approx / settings_.kd0(); + it = tapprox / kt; + iz0 = z0approx / kz0; + + bool success = true; + if (std::abs(rinvapprox) > settings_.rinvcut()) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "TrackletCalculator::LLL Seeding irinv too large: " << rinvapprox << "(" << irinv + << ")"; + success = false; + } + if (std::abs(z0approx) > 1.8 * settings_.z0cut()) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Failed tracklet z0 cut " << z0approx << " in layer " << layer_; + success = false; + } + if (std::abs(d0approx) > settings_.maxd0()) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Failed tracklet d0 cut " << d0approx; + success = false; + } + + if (!success) + return false; + + double phicritapprox = phi0approx - asin(0.5 * settings_.rcrit() * rinvapprox); + int phicrit = iphi0 - 2 * irinv; + + int iphicritmincut = settings_.phicritminmc() / globals_->ITC_L1L2()->phi0_final.K(); + int iphicritmaxcut = settings_.phicritmaxmc() / globals_->ITC_L1L2()->phi0_final.K(); + + bool keepapprox = (phicritapprox > settings_.phicritminmc()) && (phicritapprox < settings_.phicritmaxmc()), + keep = (phicrit > iphicritmincut) && (phicrit < iphicritmaxcut); + + if (settings_.debugTracklet()) + if (keep && !keepapprox) + edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced::LLLSeeding tracklet kept with exact phicrit cut " + "but not approximate, phicritapprox: " + << phicritapprox; + if (settings_.usephicritapprox()) { + if (!keepapprox) + return false; + } else { + if (!keep) + return false; + } + + for (unsigned int i = 0; i < toR_.size(); ++i) { + iphiproj[i] = phiprojapprox[i] / kphiproj; + izproj[i] = zprojapprox[i] / kzproj; + + iphider[i] = phiderapprox[i] / kphider; + izder[i] = zderapprox[i] / kzder; + + //check that z projection is in range + if (izproj[i] < -(1 << (settings_.nzbitsstub(0) - 1))) + continue; + if (izproj[i] >= (1 << (settings_.nzbitsstub(0) - 1))) + continue; + + //check that phi projection is in range + if (iphiproj[i] >= (1 << settings_.nphibitsstub(N_LAYER - 1)) - 1) + continue; + if (iphiproj[i] <= 0) + continue; + + //adjust number of bits for phi and z projection + if (rproj_[i] < settings_.rPS2S()) { + iphiproj[i] >>= (settings_.nphibitsstub(N_LAYER - 1) - settings_.nphibitsstub(0)); + if (iphiproj[i] >= (1 << settings_.nphibitsstub(0)) - 1) + iphiproj[i] = (1 << settings_.nphibitsstub(0)) - 2; //-2 not to hit atExtreme + } else { + izproj[i] >>= (settings_.nzbitsstub(0) - settings_.nzbitsstub(N_LAYER - 1)); + } + + if (rproj_[i] < settings_.rPS2S()) { + if (iphider[i] < -(1 << (settings_.nbitsphiprojderL123() - 1))) { + iphider[i] = -(1 << (settings_.nbitsphiprojderL123() - 1)); + } + if (iphider[i] >= (1 << (settings_.nbitsphiprojderL123() - 1))) { + iphider[i] = (1 << (settings_.nbitsphiprojderL123() - 1)) - 1; + } + } else { + if (iphider[i] < -(1 << (settings_.nbitsphiprojderL456() - 1))) { + iphider[i] = -(1 << (settings_.nbitsphiprojderL456() - 1)); + } + if (iphider[i] >= (1 << (settings_.nbitsphiprojderL456() - 1))) { + iphider[i] = (1 << (settings_.nbitsphiprojderL456() - 1)) - 1; + } + } + + layerprojs[i].init(settings_, + lproj_[i], + rproj_[i], + iphiproj[i], + izproj[i], + iphider[i], + izder[i], + phiproj[i], + zproj[i], + phider[i], + zder[i], + phiprojapprox[i], + zprojapprox[i], + phiderapprox[i], + zderapprox[i]); + } + + if (std::abs(it * kt) > 1.0) { + for (unsigned int i = 0; i < toZ_.size(); ++i) { + iphiprojdisk[i] = phiprojdiskapprox[i] / kphiprojdisk; + irprojdisk[i] = rprojdiskapprox[i] / krprojdisk; + + iphiderdisk[i] = phiderdiskapprox[i] / kphiderdisk; + irderdisk[i] = rderdiskapprox[i] / krderdisk; + + //check phi projection in range + if (iphiprojdisk[i] <= 0) + continue; + if (iphiprojdisk[i] >= (1 << settings_.nphibitsstub(0)) - 1) + continue; + + //check r projection in range + if (rprojdiskapprox[i] < settings_.rmindisk() || rprojdiskapprox[i] > settings_.rmaxdisk()) + continue; + + diskprojs[i].init(settings_, + i + 1, + rproj_[i], + iphiprojdisk[i], + irprojdisk[i], + iphiderdisk[i], + irderdisk[i], + phiprojdisk[i], + rprojdisk[i], + phiderdisk[i], + rderdisk[i], + phiprojdiskapprox[i], + rprojdiskapprox[i], + phiderdisk[i], + rderdisk[i]); + } + } + + if (settings_.writeMonitorData("TrackletPars")) { + globals_->ofstream("trackletpars.txt") + << "Trackpars " << layer_ << " " << rinv << " " << rinvapprox << " " << rinvapprox << " " << phi0 << " " + << phi0approx << " " << phi0approx << " " << t << " " << tapprox << " " << tapprox << " " << z0 << " " + << z0approx << " " << z0approx << endl; + } + + Tracklet* tracklet = new Tracklet(settings_, + innerStub, + middleStub, + outerStub, + innerFPGAStub, + middleFPGAStub, + outerFPGAStub, + rinv, + phi0, + d0, + z0, + t, + rinvapprox, + phi0approx, + d0approx, + z0approx, + tapprox, + irinv, + iphi0, + id0, + iz0, + it, + layerprojs, + diskprojs, + false); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced " << getName() + << " Found LLL tracklet in sector = " << iSector_ << " phi0 = " << phi0; + } + + tracklet->setTrackletIndex(trackletpars_->nTracklets()); + tracklet->setTCIndex(TCIndex_); + + if (settings_.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << tracklet->getISeed() << endl; + fout.close(); + } + trackletpars_->addTracklet(tracklet); + + bool addL5 = false; + bool addL6 = false; + for (unsigned int j = 0; j < toR_.size(); j++) { + bool added = false; + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "adding layer projection " << j << "/" << toR_.size() << " " << lproj_[j]; + if (tracklet->validProj(lproj_[j])) { + added = addLayerProj(tracklet, lproj_[j]); + if (added && lproj_[j] == 5) + addL5 = true; + if (added && lproj_[j] == 6) + addL6 = true; + } + } + + for (unsigned int j = 0; j < toZ_.size(); j++) { + int disk = dproj_[j]; + if (disk == 0) + continue; + if (disk == 2 && addL5) + continue; + if (disk == 1 && addL6) + continue; + if (it < 0) + disk = -disk; + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "adding disk projection " << j << "/" << toZ_.size() << " " << disk; + if (tracklet->validProjDisk(abs(disk))) { + addDiskProj(tracklet, disk); + } + } + + return true; +} + +bool TrackletCalculatorDisplaced::DDLSeeding(const Stub* innerFPGAStub, + const L1TStub* innerStub, + const Stub* middleFPGAStub, + const L1TStub* middleStub, + const Stub* outerFPGAStub, + const L1TStub* outerStub) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced " << getName() << " " << layer_ + << " trying stub triplet in (L2 D1 D2): " << innerFPGAStub->layer().value() << " " + << middleFPGAStub->disk().value() << " " << outerFPGAStub->disk().value(); + } + + int take3 = 1; //D1D2L2 + + double r1 = innerStub->r(); + double z1 = innerStub->z(); + double phi1 = innerStub->phi(); + + double r2 = middleStub->r(); + double z2 = middleStub->z(); + double phi2 = middleStub->phi(); + + double r3 = outerStub->r(); + double z3 = outerStub->z(); + double phi3 = outerStub->phi(); + + double rinv, phi0, d0, t, z0; + + double phiproj[N_LAYER - 2], zproj[N_LAYER - 2], phider[N_LAYER - 2], zder[N_LAYER - 2]; + double phiprojdisk[N_DISK], rprojdisk[N_DISK], phiderdisk[N_DISK], rderdisk[N_DISK]; + + exacttracklet(r1, + z1, + phi1, + r2, + z2, + phi2, + r3, + z3, + phi3, + take3, + rinv, + phi0, + d0, + t, + z0, + phiproj, + zproj, + phiprojdisk, + rprojdisk, + phider, + zder, + phiderdisk, + rderdisk); + + if (settings_.useapprox()) { + phi1 = innerFPGAStub->phiapprox(phimin_, phimax_); + z1 = innerFPGAStub->zapprox(); + r1 = innerFPGAStub->rapprox(); + + phi2 = outerFPGAStub->phiapprox(phimin_, phimax_); + z2 = outerFPGAStub->zapprox(); + r2 = outerFPGAStub->rapprox(); + } + + double rinvapprox, phi0approx, d0approx, tapprox, z0approx; + double phiprojapprox[N_LAYER - 2], zprojapprox[N_LAYER - 2], phiderapprox[N_LAYER - 2], zderapprox[N_LAYER - 2]; + double phiprojdiskapprox[N_DISK], rprojdiskapprox[N_DISK]; + double phiderdiskapprox[N_DISK], rderdiskapprox[N_DISK]; + + //TODO: implement the actual integer calculation + + phi0 -= triplet_phioffset; + + //store the approcximate results + rinvapprox = rinv; + phi0approx = phi0; + d0approx = d0; + tapprox = t; + z0approx = z0; + + for (unsigned int i = 0; i < toR_.size(); ++i) { + phiproj[i] -= triplet_phioffset; + phiprojapprox[i] = phiproj[i]; + zprojapprox[i] = zproj[i]; + phiderapprox[i] = phider[i]; + zderapprox[i] = zder[i]; + } + + for (unsigned int i = 0; i < toZ_.size(); ++i) { + phiprojdisk[i] -= triplet_phioffset; + phiprojdiskapprox[i] = phiprojdisk[i]; + rprojdiskapprox[i] = rprojdisk[i]; + phiderdiskapprox[i] = phiderdisk[i]; + rderdiskapprox[i] = rderdisk[i]; + } + + //now binary + double krinv = settings_.kphi1() / settings_.kr() * pow(2, settings_.rinv_shift()), + kphi0 = settings_.kphi1() * pow(2, settings_.phi0_shift()), + kt = settings_.kz() / settings_.kr() * pow(2, settings_.t_shift()), + kz0 = settings_.kz() * pow(2, settings_.z0_shift()), + kphiproj = settings_.kphi1() * pow(2, settings_.SS_phiL_shift()), + kphider = settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderL_shift()), + kzproj = settings_.kz() * pow(2, settings_.PS_zL_shift()), + kzder = settings_.kz() / settings_.kr() * pow(2, settings_.PS_zderL_shift()), + kphiprojdisk = settings_.kphi1() * pow(2, settings_.SS_phiD_shift()), + kphiderdisk = settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderD_shift()), + krprojdisk = settings_.kr() * pow(2, settings_.PS_rD_shift()), + krderdisk = settings_.kr() / settings_.kz() * pow(2, settings_.PS_rderD_shift()); + + int irinv, iphi0, id0, it, iz0; + int iphiproj[N_LAYER - 2], izproj[N_LAYER - 2], iphider[N_LAYER - 2], izder[N_LAYER - 2]; + int iphiprojdisk[N_DISK], irprojdisk[N_DISK], iphiderdisk[N_DISK], irderdisk[N_DISK]; + + //store the binary results + irinv = rinvapprox / krinv; + iphi0 = phi0approx / kphi0; + id0 = d0approx / settings_.kd0(); + it = tapprox / kt; + iz0 = z0approx / kz0; + + bool success = true; + if (std::abs(rinvapprox) > settings_.rinvcut()) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "TrackletCalculator::DDL Seeding irinv too large: " << rinvapprox << "(" << irinv + << ")"; + success = false; + } + if (std::abs(z0approx) > 1.8 * settings_.z0cut()) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Failed tracklet z0 cut " << z0approx; + success = false; + } + if (std::abs(d0approx) > settings_.maxd0()) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Failed tracklet d0 cut " << d0approx; + success = false; + } + + if (!success) + return false; + + double phicritapprox = phi0approx - asin(0.5 * settings_.rcrit() * rinvapprox); + int phicrit = iphi0 - 2 * irinv; + + int iphicritmincut = settings_.phicritminmc() / globals_->ITC_L1L2()->phi0_final.K(); + int iphicritmaxcut = settings_.phicritmaxmc() / globals_->ITC_L1L2()->phi0_final.K(); + + bool keepapprox = (phicritapprox > settings_.phicritminmc()) && (phicritapprox < settings_.phicritmaxmc()), + keep = (phicrit > iphicritmincut) && (phicrit < iphicritmaxcut); + + if (settings_.debugTracklet()) + if (keep && !keepapprox) + edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced::DDLSeeding tracklet kept with exact phicrit cut " + "but not approximate, phicritapprox: " + << phicritapprox; + if (settings_.usephicritapprox()) { + if (!keepapprox) + return false; + } else { + if (!keep) + return false; + } + + LayerProjection layerprojs[N_LAYER - 2]; + DiskProjection diskprojs[N_DISK]; + + for (unsigned int i = 0; i < toR_.size(); ++i) { + iphiproj[i] = phiprojapprox[i] / kphiproj; + izproj[i] = zprojapprox[i] / kzproj; + + iphider[i] = phiderapprox[i] / kphider; + izder[i] = zderapprox[i] / kzder; + + //check that z projection in range + if (izproj[i] < -(1 << (settings_.nzbitsstub(0) - 1))) + continue; + if (izproj[i] >= (1 << (settings_.nzbitsstub(0) - 1))) + continue; + + //check that phi projection in range + if (iphiproj[i] >= (1 << settings_.nphibitsstub(5)) - 1) + continue; + if (iphiproj[i] <= 0) + continue; + + if (rproj_[i] < settings_.rPS2S()) { + iphiproj[i] >>= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); + } else { + izproj[i] >>= (settings_.nzbitsstub(0) - settings_.nzbitsstub(5)); + } + + if (rproj_[i] < settings_.rPS2S()) { + if (iphider[i] < -(1 << (settings_.nbitsphiprojderL123() - 1))) + iphider[i] = -(1 << (settings_.nbitsphiprojderL123() - 1)); + if (iphider[i] >= (1 << (settings_.nbitsphiprojderL123() - 1))) + iphider[i] = (1 << (settings_.nbitsphiprojderL123() - 1)) - 1; + } else { + if (iphider[i] < -(1 << (settings_.nbitsphiprojderL456() - 1))) + iphider[i] = -(1 << (settings_.nbitsphiprojderL456() - 1)); + if (iphider[i] >= (1 << (settings_.nbitsphiprojderL456() - 1))) + iphider[i] = (1 << (settings_.nbitsphiprojderL456() - 1)) - 1; + } + + layerprojs[i].init(settings_, + lproj_[i], + rproj_[i], + iphiproj[i], + izproj[i], + iphider[i], + izder[i], + phiproj[i], + zproj[i], + phider[i], + zder[i], + phiprojapprox[i], + zprojapprox[i], + phiderapprox[i], + zderapprox[i]); + } + + if (std::abs(it * kt) > 1.0) { + for (unsigned int i = 0; i < toZ_.size(); ++i) { + iphiprojdisk[i] = phiprojdiskapprox[i] / kphiprojdisk; + irprojdisk[i] = rprojdiskapprox[i] / krprojdisk; + + iphiderdisk[i] = phiderdiskapprox[i] / kphiderdisk; + irderdisk[i] = rderdiskapprox[i] / krderdisk; + + if (iphiprojdisk[i] <= 0) + continue; + if (iphiprojdisk[i] >= (1 << settings_.nphibitsstub(0)) - 1) + continue; + + if (irprojdisk[i] < settings_.rmindisk() / krprojdisk || irprojdisk[i] > settings_.rmaxdisk() / krprojdisk) + continue; + + diskprojs[i].init(settings_, + i + 1, + rproj_[i], + iphiprojdisk[i], + irprojdisk[i], + iphiderdisk[i], + irderdisk[i], + phiprojdisk[i], + rprojdisk[i], + phiderdisk[i], + rderdisk[i], + phiprojdiskapprox[i], + rprojdiskapprox[i], + phiderdisk[i], + rderdisk[i]); + } + } + + if (settings_.writeMonitorData("TrackletPars")) { + globals_->ofstream("trackletpars.txt") + << "Trackpars " << layer_ << " " << rinv << " " << rinvapprox << " " << rinvapprox << " " << phi0 << " " + << phi0approx << " " << phi0approx << " " << t << " " << tapprox << " " << tapprox << " " << z0 << " " + << z0approx << " " << z0approx << endl; + } + + Tracklet* tracklet = new Tracklet(settings_, + innerStub, + middleStub, + outerStub, + innerFPGAStub, + middleFPGAStub, + outerFPGAStub, + rinv, + phi0, + d0, + z0, + t, + rinvapprox, + phi0approx, + d0approx, + z0approx, + tapprox, + irinv, + iphi0, + id0, + iz0, + it, + layerprojs, + diskprojs, + false); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced " << getName() + << " Found DDL tracklet in sector = " << iSector_ << " phi0 = " << phi0; + } + + tracklet->setTrackletIndex(trackletpars_->nTracklets()); + tracklet->setTCIndex(TCIndex_); + + if (settings_.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << tracklet->getISeed() << endl; + fout.close(); + } + trackletpars_->addTracklet(tracklet); + + for (unsigned int j = 0; j < toR_.size(); j++) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "adding layer projection " << j << "/" << toR_.size() << " " << lproj_[j] << " " + << tracklet->validProj(lproj_[j]); + if (tracklet->validProj(lproj_[j])) { + addLayerProj(tracklet, lproj_[j]); + } + } + + for (unsigned int j = 0; j < toZ_.size(); j++) { + int disk = dproj_[j]; + if (disk == 0) + continue; + if (it < 0) + disk = -disk; + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "adding disk projection " << j << "/" << toZ_.size() << " " << disk << " " + << tracklet->validProjDisk(abs(disk)); + if (tracklet->validProjDisk(abs(disk))) { + addDiskProj(tracklet, disk); + } + } + + return true; +} + +bool TrackletCalculatorDisplaced::LLDSeeding(const Stub* innerFPGAStub, + const L1TStub* innerStub, + const Stub* middleFPGAStub, + const L1TStub* middleStub, + const Stub* outerFPGAStub, + const L1TStub* outerStub) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced " << getName() << " " << layer_ + << " trying stub triplet in (L2L3D1): " << middleFPGAStub->layer().value() << " " + << outerFPGAStub->layer().value() << " " << innerFPGAStub->disk().value(); + } + + int take3 = 0; //L2L3D1 + + double r3 = innerStub->r(); + double z3 = innerStub->z(); + double phi3 = innerStub->phi(); + + double r1 = middleStub->r(); + double z1 = middleStub->z(); + double phi1 = middleStub->phi(); + + double r2 = outerStub->r(); + double z2 = outerStub->z(); + double phi2 = outerStub->phi(); + + double rinv, phi0, d0, t, z0; + + double phiproj[N_LAYER - 2], zproj[N_LAYER - 2], phider[N_LAYER - 2], zder[N_LAYER - 2]; + double phiprojdisk[N_DISK], rprojdisk[N_DISK], phiderdisk[N_DISK], rderdisk[N_DISK]; + + exacttracklet(r1, + z1, + phi1, + r2, + z2, + phi2, + r3, + z3, + phi3, + take3, + rinv, + phi0, + d0, + t, + z0, + phiproj, + zproj, + phiprojdisk, + rprojdisk, + phider, + zder, + phiderdisk, + rderdisk); + + if (settings_.useapprox()) { + phi1 = innerFPGAStub->phiapprox(phimin_, phimax_); + z1 = innerFPGAStub->zapprox(); + r1 = innerFPGAStub->rapprox(); + + phi2 = outerFPGAStub->phiapprox(phimin_, phimax_); + z2 = outerFPGAStub->zapprox(); + r2 = outerFPGAStub->rapprox(); + } + + double rinvapprox, phi0approx, d0approx, tapprox, z0approx; + double phiprojapprox[N_LAYER - 2], zprojapprox[N_LAYER - 2], phiderapprox[N_LAYER - 2], zderapprox[N_LAYER - 2]; + double phiprojdiskapprox[N_DISK], rprojdiskapprox[N_DISK]; + double phiderdiskapprox[N_DISK], rderdiskapprox[N_DISK]; + + //TODO: implement the actual integer calculation + + phi0 -= triplet_phioffset; + + //store the approcximate results + rinvapprox = rinv; + phi0approx = phi0; + d0approx = d0; + tapprox = t; + z0approx = z0; + + for (unsigned int i = 0; i < toR_.size(); ++i) { + phiproj[i] -= triplet_phioffset; + phiprojapprox[i] = phiproj[i]; + zprojapprox[i] = zproj[i]; + phiderapprox[i] = phider[i]; + zderapprox[i] = zder[i]; + } + + for (unsigned int i = 0; i < toZ_.size(); ++i) { + phiprojdisk[i] -= triplet_phioffset; + phiprojdiskapprox[i] = phiprojdisk[i]; + rprojdiskapprox[i] = rprojdisk[i]; + phiderdiskapprox[i] = phiderdisk[i]; + rderdiskapprox[i] = rderdisk[i]; + } + + //now binary + double krinv = settings_.kphi1() / settings_.kr() * pow(2, settings_.rinv_shift()), + kphi0 = settings_.kphi1() * pow(2, settings_.phi0_shift()), + kt = settings_.kz() / settings_.kr() * pow(2, settings_.t_shift()), + kz0 = settings_.kz() * pow(2, settings_.z0_shift()), + kphiproj = settings_.kphi1() * pow(2, settings_.SS_phiL_shift()), + kphider = settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderL_shift()), + kzproj = settings_.kz() * pow(2, settings_.PS_zL_shift()), + kzder = settings_.kz() / settings_.kr() * pow(2, settings_.PS_zderL_shift()), + kphiprojdisk = settings_.kphi1() * pow(2, settings_.SS_phiD_shift()), + kphiderdisk = settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderD_shift()), + krprojdisk = settings_.kr() * pow(2, settings_.PS_rD_shift()), + krderdisk = settings_.kr() / settings_.kz() * pow(2, settings_.PS_rderD_shift()); + + int irinv, iphi0, id0, it, iz0; + int iphiproj[N_LAYER - 2], izproj[N_LAYER - 2], iphider[N_LAYER - 2], izder[N_LAYER - 2]; + int iphiprojdisk[N_DISK], irprojdisk[N_DISK], iphiderdisk[N_DISK], irderdisk[N_DISK]; + + //store the binary results + irinv = rinvapprox / krinv; + iphi0 = phi0approx / kphi0; + id0 = d0approx / settings_.kd0(); + it = tapprox / kt; + iz0 = z0approx / kz0; + + bool success = true; + if (std::abs(rinvapprox) > settings_.rinvcut()) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "TrackletCalculator:: LLD Seeding irinv too large: " << rinvapprox << "(" << irinv + << ")"; + success = false; + } + if (std::abs(z0approx) > 1.8 * settings_.z0cut()) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Failed tracklet z0 cut " << z0approx; + success = false; + } + if (std::abs(d0approx) > settings_.maxd0()) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Failed tracklet d0 cut " << d0approx; + success = false; + } + + if (!success) + return false; + + double phicritapprox = phi0approx - asin(0.5 * settings_.rcrit() * rinvapprox); + int phicrit = iphi0 - 2 * irinv; + + int iphicritmincut = settings_.phicritminmc() / globals_->ITC_L1L2()->phi0_final.K(); + int iphicritmaxcut = settings_.phicritmaxmc() / globals_->ITC_L1L2()->phi0_final.K(); + + bool keepapprox = (phicritapprox > settings_.phicritminmc()) && (phicritapprox < settings_.phicritmaxmc()), + keep = (phicrit > iphicritmincut) && (phicrit < iphicritmaxcut); + + if (settings_.debugTracklet()) + if (keep && !keepapprox) + edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced::LLDSeeding tracklet kept with exact phicrit cut " + "but not approximate, phicritapprox: " + << phicritapprox; + if (settings_.usephicritapprox()) { + if (!keepapprox) + return false; + } else { + if (!keep) + return false; + } + + LayerProjection layerprojs[N_LAYER - 2]; + DiskProjection diskprojs[N_DISK]; + + for (unsigned int i = 0; i < toR_.size(); ++i) { + iphiproj[i] = phiprojapprox[i] / kphiproj; + izproj[i] = zprojapprox[i] / kzproj; + + iphider[i] = phiderapprox[i] / kphider; + izder[i] = zderapprox[i] / kzder; + + if (izproj[i] < -(1 << (settings_.nzbitsstub(0) - 1))) + continue; + if (izproj[i] >= (1 << (settings_.nzbitsstub(0) - 1))) + continue; + + //this is left from the original.... + if (iphiproj[i] >= (1 << settings_.nphibitsstub(5)) - 1) + continue; + if (iphiproj[i] <= 0) + continue; + + if (rproj_[i] < settings_.rPS2S()) { + iphiproj[i] >>= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); + } else { + izproj[i] >>= (settings_.nzbitsstub(0) - settings_.nzbitsstub(5)); + } + + if (rproj_[i] < settings_.rPS2S()) { + if (iphider[i] < -(1 << (settings_.nbitsphiprojderL123() - 1))) + iphider[i] = -(1 << (settings_.nbitsphiprojderL123() - 1)); + if (iphider[i] >= (1 << (settings_.nbitsphiprojderL123() - 1))) + iphider[i] = (1 << (settings_.nbitsphiprojderL123() - 1)) - 1; + } else { + if (iphider[i] < -(1 << (settings_.nbitsphiprojderL456() - 1))) + iphider[i] = -(1 << (settings_.nbitsphiprojderL456() - 1)); + if (iphider[i] >= (1 << (settings_.nbitsphiprojderL456() - 1))) + iphider[i] = (1 << (settings_.nbitsphiprojderL456() - 1)) - 1; + } + + layerprojs[i].init(settings_, + lproj_[i], + rproj_[i], + iphiproj[i], + izproj[i], + iphider[i], + izder[i], + phiproj[i], + zproj[i], + phider[i], + zder[i], + phiprojapprox[i], + zprojapprox[i], + phiderapprox[i], + zderapprox[i]); + } + + if (std::abs(it * kt) > 1.0) { + for (unsigned int i = 0; i < toZ_.size(); ++i) { + iphiprojdisk[i] = phiprojdiskapprox[i] / kphiprojdisk; + irprojdisk[i] = rprojdiskapprox[i] / krprojdisk; + + iphiderdisk[i] = phiderdiskapprox[i] / kphiderdisk; + irderdisk[i] = rderdiskapprox[i] / krderdisk; + + //Check phi range of projection + if (iphiprojdisk[i] <= 0) + continue; + if (iphiprojdisk[i] >= (1 << settings_.nphibitsstub(0)) - 1) + continue; + + //Check r range of projection + if (irprojdisk[i] < settings_.rmindisk() / krprojdisk || irprojdisk[i] > settings_.rmaxdisk() / krprojdisk) + continue; + + diskprojs[i].init(settings_, + i + 1, + rproj_[i], + iphiprojdisk[i], + irprojdisk[i], + iphiderdisk[i], + irderdisk[i], + phiprojdisk[i], + rprojdisk[i], + phiderdisk[i], + rderdisk[i], + phiprojdiskapprox[i], + rprojdiskapprox[i], + phiderdisk[i], + rderdisk[i]); + } + } + + if (settings_.writeMonitorData("TrackletPars")) { + globals_->ofstream("trackletpars.txt") + << "Trackpars " << layer_ << " " << rinv << " " << rinvapprox << " " << rinvapprox << " " << phi0 << " " + << phi0approx << " " << phi0approx << " " << t << " " << tapprox << " " << tapprox << " " << z0 << " " + << z0approx << " " << z0approx << endl; + } + + Tracklet* tracklet = new Tracklet(settings_, + innerStub, + middleStub, + outerStub, + innerFPGAStub, + middleFPGAStub, + outerFPGAStub, + rinv, + phi0, + d0, + z0, + t, + rinvapprox, + phi0approx, + d0approx, + z0approx, + tapprox, + irinv, + iphi0, + id0, + iz0, + it, + layerprojs, + diskprojs, + false); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced " << getName() + << " Found LLD tracklet in sector = " << iSector_ << " phi0 = " << phi0; + } + + tracklet->setTrackletIndex(trackletpars_->nTracklets()); + tracklet->setTCIndex(TCIndex_); + + if (settings_.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << tracklet->getISeed() << endl; + fout.close(); + } + trackletpars_->addTracklet(tracklet); + + for (unsigned int j = 0; j < toR_.size(); j++) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "adding layer projection " << j << "/" << toR_.size() << " " << lproj_[j]; + if (tracklet->validProj(lproj_[j])) { + addLayerProj(tracklet, lproj_[j]); + } + } + + for (unsigned int j = 0; j < toZ_.size(); j++) { + int disk = dproj_[j]; + if (disk == 0) + continue; + if (it < 0) + disk = -disk; + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "adding disk projection " << j << "/" << toZ_.size() << " " << disk; + if (tracklet->validProjDisk(abs(disk))) { + addDiskProj(tracklet, disk); + } + } + + return true; +} + +void TrackletCalculatorDisplaced::exactproj(double rproj, + double rinv, + double phi0, + double d0, + double t, + double z0, + double r0, + double& phiproj, + double& zproj, + double& phider, + double& zder) { + double rho = 1 / rinv; + if (rho < 0) { + r0 = -r0; + } + phiproj = phi0 - asin((rproj * rproj + r0 * r0 - rho * rho) / (2 * rproj * r0)); + double beta = acos((rho * rho + r0 * r0 - rproj * rproj) / (2 * r0 * rho)); + zproj = z0 + t * std::abs(rho * beta); + + //not exact, but close + phider = -0.5 * rinv / sqrt(1 - pow(0.5 * rproj * rinv, 2)) - d0 / (rproj * rproj); + zder = t / sqrt(1 - pow(0.5 * rproj * rinv, 2)); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "exact proj layer at " << rproj << " : " << phiproj << " " << zproj; + } +} + +void TrackletCalculatorDisplaced::exactprojdisk(double zproj, + double rinv, + double, + double, //phi0 and d0 are not used. + double t, + double z0, + double x0, + double y0, + double& phiproj, + double& rproj, + double& phider, + double& rder) { + //protect against t=0 + if (std::abs(t) < 0.1) + t = 0.1; + if (t < 0) + zproj = -zproj; + double rho = std::abs(1 / rinv); + double beta = (zproj - z0) / (t * rho); + double phiV = atan2(-y0, -x0); + double c = rinv > 0 ? -1 : 1; + + double x = x0 + rho * cos(phiV + c * beta); + double y = y0 + rho * sin(phiV + c * beta); + + phiproj = atan2(y, x); + + phiproj = reco::reduceRange(phiproj - phimin_ + (phimax_ - phimin_) / 6.0); + rproj = sqrt(x * x + y * y); + + phider = c / t / (x * x + y * y) * (rho + x0 * cos(phiV + c * beta) + y0 * sin(phiV + c * beta)); + rder = c / t / rproj * (y0 * cos(phiV + c * beta) - x0 * sin(phiV + c * beta)); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "exact proj disk at" << zproj << " : " << phiproj << " " << rproj; + } +} + +void TrackletCalculatorDisplaced::exacttracklet(double r1, + double z1, + double phi1, + double r2, + double z2, + double phi2, + double r3, + double z3, + double phi3, + int take3, + double& rinv, + double& phi0, + double& d0, + double& t, + double& z0, + double phiproj[N_DISK], + double zproj[N_DISK], + double phiprojdisk[N_DISK], + double rprojdisk[N_DISK], + double phider[N_DISK], + double zder[N_DISK], + double phiderdisk[N_DISK], + double rderdisk[N_DISK]) { + //two lines perpendicular to the 1->2 and 2->3 + double x1 = r1 * cos(phi1); + double x2 = r2 * cos(phi2); + double x3 = r3 * cos(phi3); + + double y1 = r1 * sin(phi1); + double y2 = r2 * sin(phi2); + double y3 = r3 * sin(phi3); + + double k1 = -(x2 - x1) / (y2 - y1); + double k2 = -(x3 - x2) / (y3 - y2); + double b1 = 0.5 * (y2 + y1) - 0.5 * (x1 + x2) * k1; + double b2 = 0.5 * (y3 + y2) - 0.5 * (x2 + x3) * k2; + //their intersection gives the center of the circle + double y0 = (b1 * k2 - b2 * k1) / (k2 - k1); + double x0 = (b1 - b2) / (k2 - k1); + //get the radius three ways: + double R1 = sqrt(pow(x1 - x0, 2) + pow(y1 - y0, 2)); + double R2 = sqrt(pow(x2 - x0, 2) + pow(y2 - y0, 2)); + double R3 = sqrt(pow(x3 - x0, 2) + pow(y3 - y0, 2)); + //check if the same + double eps1 = std::abs(R1 / R2 - 1); + double eps2 = std::abs(R3 / R2 - 1); + if (eps1 > 1e-10 || eps2 > 1e-10) + edm::LogVerbatim("Tracklet") << "&&&&&&&&&&&& bad circle! " << R1 << "\t" << R2 << "\t" << R3; + + //results + rinv = 1. / R1; + phi0 = 0.5 * M_PI + atan2(y0, x0); + + phi0 += -phimin_ + (phimax_ - phimin_) / 6.0; + d0 = -R1 + sqrt(x0 * x0 + y0 * y0); + //sign of rinv: + double dphi = reco::reduceRange(phi3 - atan2(y0, x0)); + if (dphi < 0) { + rinv = -rinv; + d0 = -d0; + phi0 = phi0 + M_PI; + } + phi0 = angle0to2pi::make0To2pi(phi0); + + //now in RZ: + //turning angle + double beta1 = reco::reduceRange(atan2(y1 - y0, x1 - x0) - atan2(-y0, -x0)); + double beta2 = reco::reduceRange(atan2(y2 - y0, x2 - x0) - atan2(-y0, -x0)); + double beta3 = reco::reduceRange(atan2(y3 - y0, x3 - x0) - atan2(-y0, -x0)); + + double t12 = (z2 - z1) / std::abs(beta2 - beta1) / R1; + double z12 = (z1 * beta2 - z2 * beta1) / (beta2 - beta1); + double t13 = (z3 - z1) / std::abs(beta3 - beta1) / R1; + double z13 = (z1 * beta3 - z3 * beta1) / (beta3 - beta1); + + if (take3 > 0) { + //take 13 (large lever arm) + t = t13; + z0 = z13; + } else { + //take 12 (pixel layers) + t = t12; + z0 = z12; + } + + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "exact tracklet: " << rinv << " " << phi0 << " " << d0 << " " << t << " " << z0; + + for (unsigned int i = 0; i < toR_.size(); i++) { + exactproj(toR_[i], rinv, phi0, d0, t, z0, sqrt(x0 * x0 + y0 * y0), phiproj[i], zproj[i], phider[i], zder[i]); + } + + for (unsigned int i = 0; i < toZ_.size(); i++) { + exactprojdisk(toZ_[i], rinv, phi0, d0, t, z0, x0, y0, phiprojdisk[i], rprojdisk[i], phiderdisk[i], rderdisk[i]); + } +} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc new file mode 100644 index 0000000000000..dbc5bb62835f3 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc @@ -0,0 +1,289 @@ +#include "L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h" +#include "L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +using namespace trklet; +using namespace std; + +TrackletEngine::TrackletEngine(string name, Settings const& settings, Globals* global, unsigned int iSector) + : ProcessBase(name, settings, global, iSector) { + stubpairs_ = nullptr; + innervmstubs_ = nullptr; + outervmstubs_ = nullptr; + + initLayerDisksandISeed(layerdisk1_, layerdisk2_, iSeed_); + + innerphibits_ = settings.nfinephi(0, iSeed_); + outerphibits_ = settings.nfinephi(1, iSeed_); +} + +void TrackletEngine::addOutput(MemoryBase* memory, string output) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " + << output; + } + if (output == "stubpairout") { + StubPairsMemory* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + stubpairs_ = tmp; + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output; +} + +void TrackletEngine::addInput(MemoryBase* memory, string input) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " + << input; + } + if (input == "innervmstubin") { + VMStubsTEMemory* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + innervmstubs_ = tmp; + setVMPhiBin(); + return; + } + if (input == "outervmstubin") { + VMStubsTEMemory* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + outervmstubs_ = tmp; + setVMPhiBin(); + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input; +} + +void TrackletEngine::execute() { + if (!settings_.useSeed(iSeed_)) + return; + + unsigned int countall = 0; + unsigned int countpass = 0; + + assert(innervmstubs_ != nullptr); + assert(outervmstubs_ != nullptr); + + for (unsigned int i = 0; i < innervmstubs_->nVMStubs(); i++) { + const VMStubTE& innervmstub = innervmstubs_->getVMStubTE(i); + FPGAWord lookupbits = innervmstub.vmbits(); + + unsigned int nbits = 7; + if (iSeed_ == 4 || iSeed_ == 5) + nbits = 6; + int rzdiffmax = lookupbits.bits(nbits, lookupbits.nbits() - nbits); + int rzbinfirst = lookupbits.bits(0, 3); + int start = lookupbits.bits(4, nbits - 4); + int next = lookupbits.bits(3, 1); + + if ((iSeed_ == 4 || iSeed_ == 5) && innervmstub.stub()->disk().value() < 0) { //TODO - need to store negative disk + start += 4; + } + int last = start + next; + + for (int ibin = start; ibin <= last; ibin++) { + for (unsigned int j = 0; j < outervmstubs_->nVMStubsBinned(ibin); j++) { + if (countall >= settings_.maxStep("TE")) + break; + countall++; + const VMStubTE& outervmstub = outervmstubs_->getVMStubTEBinned(ibin, j); + + int rzbin = outervmstub.vmbits().bits(0, 3); + + FPGAWord iphiinnerbin = innervmstub.finephi(); + FPGAWord iphiouterbin = outervmstub.finephi(); + + unsigned int index = (iphiinnerbin.value() << outerphibits_) + iphiouterbin.value(); + + if (iSeed_ >= 4) { //Also use r-position + int ir = ((ibin & 3) << 1) + (rzbin >> 2); + index = (index << 3) + ir; + } + + if (start != ibin) + rzbin += 8; + if ((rzbin < rzbinfirst) || (rzbin - rzbinfirst > rzdiffmax)) { + continue; + } + + FPGAWord innerbend = innervmstub.bend(); + FPGAWord outerbend = outervmstub.bend(); + + int ptinnerindex = (index << innerbend.nbits()) + innerbend.value(); + int ptouterindex = (index << outerbend.nbits()) + outerbend.value(); + + if (!(pttableinner_[ptinnerindex] && pttableouter_[ptouterindex])) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : " + << benddecode(innervmstub.bend().value(), innervmstub.isPSmodule()) << " " + << benddecode(outervmstub.bend().value(), outervmstub.isPSmodule()); + } + continue; + } + + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Adding stub pair in " << getName(); + + stubpairs_->addStubPair(innervmstub, outervmstub); + countpass++; + } + } + } + + if (settings_.writeMonitorData("TE")) { + globals_->ofstream("trackletengine.txt") << getName() << " " << countall << " " << countpass << endl; + } +} + +void TrackletEngine::setVMPhiBin() { + if (innervmstubs_ == nullptr || outervmstubs_ == nullptr) + return; + + innervmstubs_->setother(outervmstubs_); + outervmstubs_->setother(innervmstubs_); + + int outerrbits = 3; + if (iSeed_ < 4) { + outerrbits = 0; + } + + int outerrbins = (1 << outerrbits); + int innerphibins = (1 << innerphibits_); + int outerphibins = (1 << outerphibits_); + + double innerphimin, innerphimax; + innervmstubs_->getPhiRange(innerphimin, innerphimax, iSeed_, 0); + + double outerphimin, outerphimax; + outervmstubs_->getPhiRange(outerphimin, outerphimax, iSeed_, 1); + + double phiinner[2]; + double phiouter[2]; + double router[2]; + + unsigned int nbendbitsinner = 3; + unsigned int nbendbitsouter = 3; + if (iSeed_ == 2) { + nbendbitsouter = 4; + } + if (iSeed_ == 3) { + nbendbitsinner = 4; + nbendbitsouter = 4; + } + + std::vector vmbendinner((1 << nbendbitsinner), false); + std::vector vmbendouter((1 << nbendbitsouter), false); + + for (int iphiinnerbin = 0; iphiinnerbin < innerphibins; iphiinnerbin++) { + phiinner[0] = innerphimin + iphiinnerbin * (innerphimax - innerphimin) / innerphibins; + phiinner[1] = innerphimin + (iphiinnerbin + 1) * (innerphimax - innerphimin) / innerphibins; + for (int iphiouterbin = 0; iphiouterbin < outerphibins; iphiouterbin++) { + phiouter[0] = outerphimin + iphiouterbin * (outerphimax - outerphimin) / outerphibins; + phiouter[1] = outerphimin + (iphiouterbin + 1) * (outerphimax - outerphimin) / outerphibins; + for (int irouterbin = 0; irouterbin < outerrbins; irouterbin++) { + if (iSeed_ >= 4) { + router[0] = + settings_.rmindiskvm() + irouterbin * (settings_.rmaxdiskvm() - settings_.rmindiskvm()) / outerrbins; + router[1] = settings_.rmindiskvm() + + (irouterbin + 1) * (settings_.rmaxdiskvm() - settings_.rmindiskvm()) / outerrbins; + } else { + router[0] = settings_.rmean(layerdisk2_); + router[1] = settings_.rmean(layerdisk2_); + } + + double bendinnermin = 20.0; + double bendinnermax = -20.0; + double bendoutermin = 20.0; + double bendoutermax = -20.0; + double rinvmin = 1.0; + for (int i1 = 0; i1 < 2; i1++) { + for (int i2 = 0; i2 < 2; i2++) { + for (int i3 = 0; i3 < 2; i3++) { + double rinner = 0.0; + if (iSeed_ == 4 || iSeed_ == 5) { + rinner = router[i3] * settings_.zmean(layerdisk1_ - N_LAYER) / settings_.zmean(layerdisk2_ - N_LAYER); + } else { + rinner = settings_.rmean(layerdisk1_); + } + double rinv1 = rinv(phiinner[i1], phiouter[i2], rinner, router[i3]); + double pitchinner = + (rinner < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); + double pitchouter = + (router[i3] < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); + double abendinner = -bend(rinner, rinv1, pitchinner); + double abendouter = -bend(router[i3], rinv1, pitchouter); + if (abendinner < bendinnermin) + bendinnermin = abendinner; + if (abendinner > bendinnermax) + bendinnermax = abendinner; + if (abendouter < bendoutermin) + bendoutermin = abendouter; + if (abendouter > bendoutermax) + bendoutermax = abendouter; + if (std::abs(rinv1) < rinvmin) { + rinvmin = std::abs(rinv1); + } + } + } + } + + bool passptcut = rinvmin < settings_.rinvcutte(); + + for (int ibend = 0; ibend < (1 << nbendbitsinner); ibend++) { + double bend = benddecode(ibend, nbendbitsinner == 3); + + bool passinner = bend - bendinnermin > -settings_.bendcutte(0, iSeed_) && + bend - bendinnermax < settings_.bendcutte(0, iSeed_); + if (passinner) + vmbendinner[ibend] = true; + pttableinner_.push_back(passinner && passptcut); + } + + for (int ibend = 0; ibend < (1 << nbendbitsouter); ibend++) { + double bend = benddecode(ibend, nbendbitsouter == 3); + + bool passouter = bend - bendoutermin > -settings_.bendcutte(1, iSeed_) && + bend - bendoutermax < settings_.bendcutte(1, iSeed_); + if (passouter) + vmbendouter[ibend] = true; + pttableouter_.push_back(passouter && passptcut); + } + } + } + } + + innervmstubs_->setbendtable(vmbendinner); + outervmstubs_->setbendtable(vmbendouter); + + if (iSector_ == 0 && settings_.writeTable()) + writeTETable(); +} + +void TrackletEngine::writeTETable() { + ofstream outstubptinnercut; + outstubptinnercut.open(getName() + "_stubptinnercut.tab"); + outstubptinnercut << "{" << endl; + for (unsigned int i = 0; i < pttableinner_.size(); i++) { + if (i != 0) + outstubptinnercut << "," << endl; + outstubptinnercut << pttableinner_[i]; + } + outstubptinnercut << endl << "};" << endl; + outstubptinnercut.close(); + + ofstream outstubptoutercut; + outstubptoutercut.open(getName() + "_stubptoutercut.tab"); + outstubptoutercut << "{" << endl; + for (unsigned int i = 0; i < pttableouter_.size(); i++) { + if (i != 0) + outstubptoutercut << "," << endl; + outstubptoutercut << pttableouter_[i]; + } + outstubptoutercut << endl << "};" << endl; + outstubptoutercut.close(); +} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc new file mode 100644 index 0000000000000..c8b13f3c9e20a --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc @@ -0,0 +1,416 @@ +#include "L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +using namespace std; +using namespace trklet; + +TrackletEngineDisplaced::TrackletEngineDisplaced(string name, + Settings const& settings, + Globals* global, + unsigned int iSector) + : ProcessBase(name, settings, global, iSector) { + stubpairs_.clear(); + firstvmstubs_.clear(); + secondvmstubs_ = nullptr; + layer1_ = 0; + layer2_ = 0; + disk1_ = 0; + disk2_ = 0; + string name1 = name.substr(1); //this is to correct for "TED" having one more letter then "TE" + if (name1[3] == 'L') { + layer1_ = name1[4] - '0'; + } + if (name1[3] == 'D') { + disk1_ = name1[4] - '0'; + } + if (name1[11] == 'L') { + layer2_ = name1[12] - '0'; + } + if (name1[11] == 'D') { + disk2_ = name1[12] - '0'; + } + if (name1[12] == 'L') { + layer2_ = name1[13] - '0'; + } + if (name1[12] == 'D') { + disk2_ = name1[13] - '0'; + } + + iSeed_ = -1; + if (layer1_ == 3 && layer2_ == 4) + iSeed_ = 8; + if (layer1_ == 5 && layer2_ == 6) + iSeed_ = 9; + if (layer1_ == 2 && layer2_ == 3) + iSeed_ = 10; + if (disk1_ == 1 && disk2_ == 2) + iSeed_ = 11; + + firstphibits_ = settings_.nfinephi(0, iSeed_); + secondphibits_ = settings_.nfinephi(1, iSeed_); + + readTables(); +} + +TrackletEngineDisplaced::~TrackletEngineDisplaced() { table_.clear(); } + +void TrackletEngineDisplaced::addOutput(MemoryBase* memory, string output) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " + << output; + } + if (output == "stubpairout") { + StubPairsMemory* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + stubpairs_.push_back(tmp); + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output; +} + +void TrackletEngineDisplaced::addInput(MemoryBase* memory, string input) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " + << input; + } + if (input == "firstvmstubin") { + VMStubsTEMemory* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + firstvmstubs_.push_back(tmp); + return; + } + if (input == "secondvmstubin") { + VMStubsTEMemory* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + secondvmstubs_ = tmp; + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input; +} + +void TrackletEngineDisplaced::execute() { + if (!settings_.useSeed(iSeed_)) + return; + + unsigned int countall = 0; + unsigned int countpass = 0; + unsigned int nInnerStubs = 0; + + for (unsigned int iInnerMem = 0; iInnerMem < firstvmstubs_.size(); + nInnerStubs += firstvmstubs_.at(iInnerMem)->nVMStubs(), iInnerMem++) + ; + + assert(!firstvmstubs_.empty()); + assert(secondvmstubs_ != nullptr); + + for (auto& iInnerMem : firstvmstubs_) { + assert(iInnerMem->nVMStubs() == iInnerMem->nVMStubs()); + for (unsigned int i = 0; i < iInnerMem->nVMStubs(); i++) { + const VMStubTE& firstvmstub = iInnerMem->getVMStubTE(i); + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "In " << getName() << " have first stub"; + } + + if ((layer1_ == 3 && layer2_ == 4) || (layer1_ == 5 && layer2_ == 6)) { + int lookupbits = firstvmstub.vmbits().value() & 1023; + int zdiffmax = (lookupbits >> 7); + int newbin = (lookupbits & 127); + int bin = newbin / 8; + + int zbinfirst = newbin & 7; + + int start = (bin >> 1); + int last = start + (bin & 1); + + assert(last < 8); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Will look in zbins " << start << " to " << last; + } + for (int ibin = start; ibin <= last; ibin++) { + for (unsigned int j = 0; j < secondvmstubs_->nVMStubsBinned(ibin); j++) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "In " << getName() << " have second stub(1) " << ibin << " " << j; + } + + if (countall >= settings_.maxStep("TE")) + break; + countall++; + const VMStubTE& secondvmstub = secondvmstubs_->getVMStubTEBinned(ibin, j); + + int zbin = (secondvmstub.vmbits().value() & 7); + if (start != ibin) + zbin += 8; + if (zbin < zbinfirst || zbin - zbinfirst > zdiffmax) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Stubpair rejected because of wrong zbin"; + } + continue; + } + + assert(firstphibits_ != -1); + assert(secondphibits_ != -1); + + FPGAWord iphifirstbin = firstvmstub.finephi(); + FPGAWord iphisecondbin = secondvmstub.finephi(); + + unsigned int index = (iphifirstbin.value() << secondphibits_) + iphisecondbin.value(); + + FPGAWord firstbend = firstvmstub.bend(); + FPGAWord secondbend = secondvmstub.bend(); + + index = (index << firstbend.nbits()) + firstbend.value(); + index = (index << secondbend.nbits()) + secondbend.value(); + + if (index >= table_.size()) + table_.resize(index + 1); + + if (table_.at(index).empty()) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : " + << benddecode(firstvmstub.bend().value(), firstvmstub.isPSmodule()) << " " + << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule()); + } + if (!settings_.writeTripletTables()) + continue; + } + + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName(); + for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) { + if (settings_.writeTripletTables() || table_.at(index).count(stubpairs_.at(isp)->getName())) { + if (settings_.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout.close(); + } + stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName()); + } + } + + countpass++; + } + } + + } else if (layer1_ == 2 && layer2_ == 3) { + int lookupbits = firstvmstub.vmbits().value() & 1023; + int zdiffmax = (lookupbits >> 7); + int newbin = (lookupbits & 127); + int bin = newbin / 8; + + int zbinfirst = newbin & 7; + + int start = (bin >> 1); + int last = start + (bin & 1); + + assert(last < 8); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Will look in zbins " << start << " to " << last; + } + for (int ibin = start; ibin <= last; ibin++) { + for (unsigned int j = 0; j < secondvmstubs_->nVMStubsBinned(ibin); j++) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "In " << getName() << " have second stub(2) "; + } + + if (countall >= settings_.maxStep("TE")) + break; + countall++; + + const VMStubTE& secondvmstub = secondvmstubs_->getVMStubTEBinned(ibin, j); + + int zbin = (secondvmstub.vmbits().value() & 7); + if (start != ibin) + zbin += 8; + if (zbin < zbinfirst || zbin - zbinfirst > zdiffmax) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Stubpair rejected because of wrong zbin"; + } + continue; + } + + assert(firstphibits_ != -1); + assert(secondphibits_ != -1); + + FPGAWord iphifirstbin = firstvmstub.finephi(); + FPGAWord iphisecondbin = secondvmstub.finephi(); + + unsigned int index = (iphifirstbin.value() << secondphibits_) + iphisecondbin.value(); + + FPGAWord firstbend = firstvmstub.bend(); + FPGAWord secondbend = secondvmstub.bend(); + + index = (index << firstbend.nbits()) + firstbend.value(); + index = (index << secondbend.nbits()) + secondbend.value(); + + if (index >= table_.size()) + table_.resize(index + 1); + + if (table_.at(index).empty()) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : " + << benddecode(firstvmstub.bend().value(), firstvmstub.isPSmodule()) << " " + << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule()); + } + if (!settings_.writeTripletTables()) + continue; + } + + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName(); + for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) { + if (settings_.writeTripletTables() || table_.at(index).count(stubpairs_.at(isp)->getName())) { + if (settings_.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout.close(); + } + stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName()); + } + } + + countpass++; + } + } + + } else if (disk1_ == 1 && disk2_ == 2) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << getName() << "[" << iSector_ << "] Disk-disk pair"; + + int lookupbits = firstvmstub.vmbits().value() & 511; + bool negdisk = firstvmstub.stub()->disk().value() < 0; + int rdiffmax = (lookupbits >> 6); + int newbin = (lookupbits & 63); + int bin = newbin / 8; + + int rbinfirst = newbin & 7; + + int start = (bin >> 1); + if (negdisk) + start += 4; + int last = start + (bin & 1); + assert(last < 8); + for (int ibin = start; ibin <= last; ibin++) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " looking for matching stub in " << secondvmstubs_->getName() + << " in bin = " << ibin << " with " << secondvmstubs_->nVMStubsBinned(ibin) + << " stubs"; + } + for (unsigned int j = 0; j < secondvmstubs_->nVMStubsBinned(ibin); j++) { + if (countall >= settings_.maxStep("TE")) + break; + countall++; + + const VMStubTE& secondvmstub = secondvmstubs_->getVMStubTEBinned(ibin, j); + + int rbin = (secondvmstub.vmbits().value() & 7); + if (start != ibin) + rbin += 8; + if (rbin < rbinfirst) + continue; + if (rbin - rbinfirst > rdiffmax) + continue; + + unsigned int irsecondbin = secondvmstub.vmbits().value() >> 2; + + FPGAWord iphifirstbin = firstvmstub.finephi(); + FPGAWord iphisecondbin = secondvmstub.finephi(); + + unsigned int index = (irsecondbin << (secondphibits_ + firstphibits_)) + + (iphifirstbin.value() << secondphibits_) + iphisecondbin.value(); + + FPGAWord firstbend = firstvmstub.bend(); + FPGAWord secondbend = secondvmstub.bend(); + + index = (index << firstbend.nbits()) + firstbend.value(); + index = (index << secondbend.nbits()) + secondbend.value(); + + if (index >= table_.size()) + table_.resize(index + 1); + + if (table_.at(index).empty()) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : " + << benddecode(firstvmstub.bend().value(), firstvmstub.isPSmodule()) << " " + << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule()); + } + if (!settings_.writeTripletTables()) + continue; + } + + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Adding disk-disk pair in " << getName(); + + for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) { + if (settings_.writeTripletTables() || table_.at(index).count(stubpairs_.at(isp)->getName())) { + if (settings_.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout.close(); + } + stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName()); + } + } + countpass++; + } + } + } + } + } + if (countall > 5000) { + edm::LogVerbatim("Tracklet") << "In TrackletEngineDisplaced::execute : " << getName() << " " << nInnerStubs << " " + << secondvmstubs_->nVMStubs() << " " << countall << " " << countpass; + for (auto& iInnerMem : firstvmstubs_) { + for (unsigned int i = 0; i < iInnerMem->nVMStubs(); i++) { + const VMStubTE& firstvmstub = iInnerMem->getVMStubTE(i); + edm::LogVerbatim("Tracklet") << "In TrackletEngineDisplaced::execute first stub : " + << firstvmstub.stub()->l1tstub()->r() << " " + << firstvmstub.stub()->l1tstub()->phi() << " " + << firstvmstub.stub()->l1tstub()->r() * firstvmstub.stub()->l1tstub()->phi() << " " + << firstvmstub.stub()->l1tstub()->z(); + } + } + for (unsigned int i = 0; i < secondvmstubs_->nVMStubs(); i++) { + const VMStubTE& secondvmstub = secondvmstubs_->getVMStubTE(i); + edm::LogVerbatim("Tracklet") << "In TrackletEngineDisplaced::execute second stub : " + << secondvmstub.stub()->l1tstub()->r() << " " + << secondvmstub.stub()->l1tstub()->phi() << " " + << secondvmstub.stub()->l1tstub()->r() * secondvmstub.stub()->l1tstub()->phi() << " " + << secondvmstub.stub()->l1tstub()->z(); + } + } + + if (settings_.writeMonitorData("TED")) { + globals_->ofstream("trackletenginedisplaces.txt") << getName() << " " << countall << " " << countpass << endl; + } +} + +void TrackletEngineDisplaced::readTables() { + ifstream fin; + string tableName, line, word; + + tableName = "../data/table_TED/table_" + name_ + ".txt"; + + fin.open(tableName, ifstream::in); + if (!fin) { + throw cms::Exception("BadConfig") << "TripletEngine::readTables, file " << tableName << " not known"; + } + + while (getline(fin, line)) { + istringstream iss(line); + table_.resize(table_.size() + 1); + + while (iss >> word) + table_[table_.size() - 1].insert(word); + } + fin.close(); +} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc new file mode 100644 index 0000000000000..41a0f505cf378 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc @@ -0,0 +1,539 @@ +#include "L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h" +#include "L1Trigger/TrackFindingTracklet/interface/Sector.h" +#include "L1Trigger/TrackFindingTracklet/interface/HistBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/Track.h" +#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" +#include "L1Trigger/TrackFindingTracklet/interface/Cabling.h" + +#include "DataFormats/Math/interface/deltaPhi.h" + +#include + +using namespace trklet; +using namespace std; + +TrackletEventProcessor::TrackletEventProcessor() = default; + +TrackletEventProcessor::~TrackletEventProcessor() { + if (settings_->bookHistos()) { + histbase_->close(); + } +} + +void TrackletEventProcessor::init(const Settings* theSettings) { + settings_ = theSettings; + + globals_ = make_unique(*settings_); + + //Verify consistency + if (settings_->kphi0pars() != globals_->ITC_L1L2()->phi0_final.K()) { + throw cms::Exception("Inconsistency") << "phi0 conversion parameter inconsistency\n"; + } + + if (settings_->krinvpars() != globals_->ITC_L1L2()->rinv_final.K()) { + throw cms::Exception("Inconsistency") << "ring conversion parameter inconsistency\n"; + } + + if (settings_->ktpars() != globals_->ITC_L1L2()->t_final.K()) { + throw cms::Exception("Inconsistency") << "t conversion parameter inconsistency\n"; + } + + if (settings_->debugTracklet()) { + edm::LogVerbatim("Tracklet") << "========================================================= \n" + << "Conversion factors for global coordinates: \n" + << "z kz = " << settings_->kz() << "\n" + << "r kr = " << settings_->kr() << "\n" + << "phi kphi1 = " << settings_->kphi1() << "\n" + << "========================================================= \n" + << "Conversion factors for track(let) parameters: \n" + << "rinv krinvpars = " << settings_->krinvpars() << "\n" + << "phi0 kphi0pars = " << settings_->kphi0pars() << "\n" + << "d0 kd0pars = " << settings_->kd0pars() << "\n" + << "t ktpars = " << settings_->ktpars() << "\n" + << "z0 kz0pars = " << settings_->kz0pars() << "\n" + << "========================================================= \n" + << "phi0bitshift = " << settings_->phi0bitshift() << "\n" + << "d0bitshift = ??? \n" + << "========================================================="; + } + + //option to write out tables for HLS code, not used in production + /* + const Settings& settings = *settings_; + Globals* globals = globals_; + + if (settings_->writeVerilog() || settings_->writeHLS()) { +#include "../test/WriteInvTables.icc" +#include "../test/WriteDesign.icc" + } + */ + + if (settings_->bookHistos()) { + histbase_ = new HistBase; + histbase_->open(); + histbase_->bookLayerResidual(); + histbase_->bookDiskResidual(); + histbase_->bookTrackletParams(); + histbase_->bookSeedEff(); + + globals_->histograms() = histbase_; + } + + // create the sector processors (1 sector processor = 1 board) + sectors_.resize(N_SECTOR); + + for (unsigned int i = 0; i < N_SECTOR; i++) { + sectors_[i] = make_unique(i, *settings_, globals_.get()); + } + + // get the memory modules + if (settings_->debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Will read memory modules file"; + } + + ifstream inmem(settings_->memoryModulesFile().c_str()); + assert(inmem.good()); + + while (inmem.good()) { + string memType, memName, size; + inmem >> memType >> memName >> size; + if (!inmem.good()) + continue; + if (settings_->writetrace()) { + edm::LogVerbatim("Tracklet") << "Read memory: " << memType << " " << memName; + } + for (auto& sector : sectors_) { + sector->addMem(memType, memName); + } + } + + // get the processing modules + if (settings_->debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Will read processing modules file"; + } + + ifstream inproc(settings_->processingModulesFile().c_str()); + assert(inproc.good()); + + while (inproc.good()) { + string procType, procName; + inproc >> procType >> procName; + if (!inproc.good()) + continue; + if (settings_->writetrace()) { + edm::LogVerbatim("Tracklet") << "Read process: " << procType << " " << procName; + } + for (auto& sector : sectors_) { + sector->addProc(procType, procName); + } + } + + // get the wiring information + if (settings_->debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Will read wiring information"; + } + + ifstream inwire(settings_->wiresFile().c_str()); + assert(inwire.good()); + + while (inwire.good()) { + string line; + getline(inwire, line); + if (!inwire.good()) + continue; + if (settings_->writetrace()) { + edm::LogVerbatim("Tracklet") << "Line : " << line; + } + stringstream ss(line); + string mem, tmp1, procin, tmp2, procout; + ss >> mem >> tmp1 >> procin; + if (procin == "output=>") { + procin = ""; + ss >> procout; + } else { + ss >> tmp2 >> procout; + } + + for (auto& sector : sectors_) { + sector->addWire(mem, procin, procout); + } + } + + // get the DTC/cabling information + ifstream indtc(settings_->DTCLinkLayerDiskFile()); + assert(indtc.good()); + string dtc; + indtc >> dtc; + while (indtc.good()) { + vector tmp; + dtclayerdisk_[dtc] = tmp; + int layerdisk; + indtc >> layerdisk; + while (layerdisk > 0) { + dtclayerdisk_[dtc].push_back(layerdisk); + indtc >> layerdisk; + } + indtc >> dtc; + } + + cabling_ = make_unique(settings_->DTCLinkFile(), settings_->moduleCablingFile(), *settings_); +} + +void TrackletEventProcessor::event(SLHCEvent& ev) { + globals_->event() = &ev; + + tracks_.clear(); + + eventnum_++; + bool first = (eventnum_ == 1); + + cleanTimer_.start(); + for (unsigned int k = 0; k < N_SECTOR; k++) { + sectors_[k]->clean(); + } + cleanTimer_.stop(); + + addStubTimer_.start(); + + for (int j = 0; j < ev.nstubs(); j++) { + L1TStub stub = ev.stub(j); + + int layer = stub.layer() + 1; + int ladder = stub.ladder(); + int module = stub.module(); + + string dtc = cabling_->dtc(layer, ladder, module); + string dtcbase = dtc.substr(2, dtc.size() - 2); + if (dtc[0] == 'n') { + dtcbase = dtc.substr(0, 4) + dtc.substr(6, dtc.size() - 6); + } + + cabling_->addphi(dtc, stub.phi(), layer, module); + + double phi = angle0to2pi::make0To2pi(stub.phi() + 0.5 * settings_->dphisectorHG()); + + unsigned int isector = N_SECTOR * phi / (2 * M_PI); + + for (unsigned int k = 0; k < N_SECTOR; k++) { + int diff = k - isector; + if (diff > (int)N_SECTOR / 2) + diff -= (int)N_SECTOR; + if (diff < (-1) * (int)N_SECTOR / 2) + diff += (int)N_SECTOR; + if (abs(diff) > 1) + continue; + double phiminsect = + k * 2 * M_PI / N_SECTOR - 0.5 * (settings_->dphisectorHG() - 2 * M_PI / N_SECTOR) - M_PI / N_SECTOR; + double dphi = stub.phi() - phiminsect; + if (dphi > M_PI) + dphi -= 2 * M_PI; + while (dphi < 0.0) + dphi += 2 * M_PI; + if (dphi > settings_->dphisectorHG()) + continue; + bool add = sectors_[k]->addStub(stub, dtcbase); + + static std::map dtcstubs; + + if (settings_->writeMem()) { + vector dtcs = cabling_->DTCs(); + for (const auto& dtc : dtcs) { + string dtcbase = dtc.substr(2, dtc.size() - 2); + if (dtc[0] == 'n') { + dtcbase = dtc.substr(0, 4) + dtc.substr(6, dtc.size() - 6); + } + + string fname = "../data/MemPrints/InputStubs/Link_"; + fname += dtcbase; + if (dtcstubs.find(dtcbase + "A") != dtcstubs.end()) + continue; + fname += "_A.dat"; + ofstream* out = new ofstream; + out->open(fname.c_str()); + dtcstubs[dtcbase + "A"] = out; + + fname = "../data/MemPrints/InputStubs/Link_"; + fname += dtcbase; + if (dtcstubs.find(dtcbase + "B") != dtcstubs.end()) + continue; + fname += "_B.dat"; + out = new ofstream; + out->open(fname.c_str()); + dtcstubs[dtcbase + "B"] = out; + } + + static int oldevent = -1; + if (eventnum_ != oldevent) { + oldevent = eventnum_; + for (auto& dtcstub : dtcstubs) { + FPGAWord tmp; + tmp.set(eventnum_ % 8, 3); + (*(dtcstub.second)) << "BX " << tmp.str() << " Event : " << eventnum_ + 1 << endl; + } + } + } + + if (add && settings_->writeMem() && k == settings_->writememsect()) { + Stub fpgastub(stub, *settings_, sectors_[k]->phimin(), sectors_[k]->phimax()); + FPGAWord phi = fpgastub.phi(); + int topbit = phi.value() >> (phi.nbits() - 1); + std::vector tmp = dtclayerdisk_[dtcbase]; + int layerdisk = stub.layer() + 1; + if (layerdisk > 999) { + layerdisk = 10 + abs(stub.disk()); + } + int layerdiskcode = -1; + for (unsigned int i = 0; i < tmp.size(); i++) { + if (tmp[i] == layerdisk) + layerdiskcode = i; + } + if (layerdiskcode == -1) { + edm::LogVerbatim("Tracklet") << "dtcbase layerdisk layer disk : " << dtcbase << " " << layerdisk << " " + << stub.layer() + 1 << " " << stub.disk(); + } + assert(layerdiskcode >= 0); + assert(layerdiskcode < 4); + FPGAWord ldcode; + ldcode.set(layerdiskcode, 2); + string dataword = ldcode.str() + "|" + fpgastub.str(); + if (topbit == 0) { + (*dtcstubs[dtcbase + "A"]) << dataword << " " << trklet::hexFormat(dataword) << endl; + } else { + (*dtcstubs[dtcbase + "B"]) << dataword << " " << trklet::hexFormat(dataword) << endl; + } + } + } + } + + if (settings_->writeMem()) { + for (unsigned int k = 0; k < N_SECTOR; k++) { + if (k == settings_->writememsect()) + sectors_[k]->writeInputStubs(first); + } + } + + addStubTimer_.stop(); + + // ---------------------------------------------------------------------------------------- + // Now start the tracklet processing + + // VM router + VMRouterTimer_.start(); + for (unsigned int k = 0; k < N_SECTOR; k++) { + sectors_[k]->executeVMR(); + if (settings_->writeMem() && k == settings_->writememsect()) { + sectors_[k]->writeInputStubs(first); + sectors_[k]->writeVMSTE(first); + sectors_[k]->writeVMSME(first); + sectors_[k]->writeAS(first); + } + } + VMRouterTimer_.stop(); + + // tracklet engine + TETimer_.start(); + for (unsigned int k = 0; k < N_SECTOR; k++) { + sectors_[k]->executeTE(); + } + TETimer_.stop(); + + // tracklet engine displaced + TEDTimer_.start(); + for (unsigned int k = 0; k < N_SECTOR; k++) { + sectors_[k]->executeTED(); + } + TEDTimer_.stop(); + + // triplet engine + TRETimer_.start(); + for (unsigned int k = 0; k < N_SECTOR; k++) { + sectors_[k]->executeTRE(); + if (settings_->writeMem() && k == settings_->writememsect()) { + sectors_[k]->writeST(first); + } + } + TRETimer_.stop(); + + // tracklet processor (alternative implementation to TE+TC) + for (unsigned int k = 0; k < N_SECTOR; k++) { + sectors_[k]->executeTP(); + if (settings_->writeMem() && k == settings_->writememsect()) { + sectors_[k]->writeTPAR(first); + } + } + + for (unsigned int k = 0; k < N_SECTOR; k++) { + if (settings_->writeMem() && k == settings_->writememsect()) { + sectors_[k]->writeSP(first); + } + } + + // tracklet calculator + TCTimer_.start(); + for (unsigned int k = 0; k < N_SECTOR; k++) { + sectors_[k]->executeTC(); + if (settings_->writeMem() && k == settings_->writememsect()) { + sectors_[k]->writeTPAR(first); + } + } + TCTimer_.stop(); + + int nTP = globals_->event()->nsimtracks(); + for (int iTP = 0; iTP < nTP; iTP++) { + L1SimTrack simtrk = globals_->event()->simtrack(iTP); + if (simtrk.pt() < 2.0) + continue; + if (std::abs(simtrk.vz()) > 15.0) + continue; + if (hypot(simtrk.vx(), simtrk.vy()) > 0.1) + continue; + bool electron = (abs(simtrk.type()) == 11); + bool muon = (abs(simtrk.type()) == 13); + bool pion = (abs(simtrk.type()) == 211); + bool kaon = (abs(simtrk.type()) == 321); + bool proton = (abs(simtrk.type()) == 2212); + if (!(electron || muon || pion || kaon || proton)) + continue; + int nlayers = 0; + int ndisks = 0; + int simtrackid = simtrk.trackid(); + unsigned int hitmask = ev.layersHit(simtrackid, nlayers, ndisks); + if (nlayers + ndisks < 4) + continue; + + if (settings_->writeMonitorData("HitEff")) { + static ofstream outhit("hiteff.txt"); + outhit << simtrk.eta() << " " << (hitmask & 1) << " " << (hitmask & 2) << " " << (hitmask & 4) << " " + << (hitmask & 8) << " " << (hitmask & 16) << " " << (hitmask & 32) << " " << (hitmask & 64) << " " + << (hitmask & 128) << " " << (hitmask & 256) << " " << (hitmask & 512) << " " << (hitmask & 1024) << endl; + } + + std::unordered_set matchseed; + for (unsigned int k = 0; k < N_SECTOR; k++) { + std::unordered_set matchseedtmp = sectors_[k]->seedMatch(iTP); + matchseed.insert(matchseedtmp.begin(), matchseedtmp.end()); + } + if (settings_->bookHistos()) { + for (int iseed = 0; iseed < 8; iseed++) { + bool eff = matchseed.find(iseed) != matchseed.end(); + globals_->histograms()->fillSeedEff(iseed, simtrk.eta(), eff); + } + } + } + + // tracklet calculator displaced + TCDTimer_.start(); + for (unsigned int k = 0; k < N_SECTOR; k++) { + sectors_[k]->executeTCD(); + if (settings_->writeMem() && k == settings_->writememsect()) { + sectors_[k]->writeTPAR(first); + sectors_[k]->writeTPROJ(first); + } + } + TCDTimer_.stop(); + + // projection router + PRTimer_.start(); + for (unsigned int k = 0; k < N_SECTOR; k++) { + sectors_[k]->executePR(); + if (settings_->writeMem() && k == settings_->writememsect()) { + sectors_[k]->writeVMPROJ(first); + sectors_[k]->writeAP(first); + } + } + PRTimer_.stop(); + + // match engine + METimer_.start(); + for (unsigned int k = 0; k < N_SECTOR; k++) { + sectors_[k]->executeME(); + if (settings_->writeMem() && k == settings_->writememsect()) { + sectors_[k]->writeCM(first); + } + } + METimer_.stop(); + + // match calculator + MCTimer_.start(); + for (unsigned int k = 0; k < N_SECTOR; k++) { + sectors_[k]->executeMC(); + } + MCTimer_.stop(); + + // match processor (alternative to ME+MC) + MPTimer_.start(); + for (unsigned int k = 0; k < N_SECTOR; k++) { + sectors_[k]->executeMP(); + } + MPTimer_.stop(); + + for (unsigned int k = 0; k < N_SECTOR; k++) { + if (settings_->writeMem() && k == settings_->writememsect()) { + sectors_[k]->writeMC(first); + } + } + + // fit track + FTTimer_.start(); + for (unsigned int k = 0; k < N_SECTOR; k++) { + sectors_[k]->executeFT(); + if ((settings_->writeMem() || settings_->writeMonitorData("IFit")) && k == settings_->writememsect()) { + sectors_[k]->writeTF(first); + } + } + FTTimer_.stop(); + + // purge duplicate + PDTimer_.start(); + for (unsigned int k = 0; k < N_SECTOR; k++) { + sectors_[k]->executePD(tracks_); + if (((settings_->writeMem() || settings_->writeMonitorData("IFit")) && k == settings_->writememsect()) || + settings_->writeMonitorData("CT")) { + sectors_[k]->writeCT(first); + } + } + PDTimer_.stop(); +} + +void TrackletEventProcessor::printSummary() { + if (settings_->writeMonitorData("Cabling")) { + cabling_->writephirange(); + } + + if (settings_->bookHistos()) { + globals_->histograms()->close(); + } + + edm::LogVerbatim("Tracklet") + << "Process Times called Average time (ms) Total time (s) \n" + << "Cleaning " << setw(10) << cleanTimer_.ntimes() << setw(20) << setprecision(3) + << cleanTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << cleanTimer_.tottime() << "\n" + << "Add Stubs " << setw(10) << addStubTimer_.ntimes() << setw(20) << setprecision(3) + << addStubTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << addStubTimer_.tottime() << "\n" + << "VMRouter " << setw(10) << VMRouterTimer_.ntimes() << setw(20) << setprecision(3) + << VMRouterTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << VMRouterTimer_.tottime() << "\n" + << "TrackletEngine " << setw(10) << TETimer_.ntimes() << setw(20) << setprecision(3) + << TETimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << TETimer_.tottime() << "\n" + << "TrackletEngineDisplaced" << setw(10) << TEDTimer_.ntimes() << setw(20) << setprecision(3) + << TEDTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << TEDTimer_.tottime() << "\n" + << "TripletEngine " << setw(10) << TRETimer_.ntimes() << setw(20) << setprecision(3) + << TRETimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << TRETimer_.tottime() << "\n" + << "TrackletCalculator " << setw(10) << TCTimer_.ntimes() << setw(20) << setprecision(3) + << TCTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << TCTimer_.tottime() << "\n" + << "TrackletCalculatorDisplaced" << setw(10) << TCDTimer_.ntimes() << setw(20) << setprecision(3) + << TCDTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << TCDTimer_.tottime() << "\n" + << "ProjectionRouter " << setw(10) << PRTimer_.ntimes() << setw(20) << setprecision(3) + << PRTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << PRTimer_.tottime() << "\n" + << "MatchEngine " << setw(10) << METimer_.ntimes() << setw(20) << setprecision(3) + << METimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << METimer_.tottime() << "\n" + << "MatchCalculator " << setw(10) << MCTimer_.ntimes() << setw(20) << setprecision(3) + << MCTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << MCTimer_.tottime() << "\n" + << "MatchProcessor " << setw(10) << MPTimer_.ntimes() << setw(20) << setprecision(3) + << MPTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << MPTimer_.tottime() << "\n" + << "FitTrack " << setw(10) << FTTimer_.ntimes() << setw(20) << setprecision(3) + << FTTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << FTTimer_.tottime() << "\n" + << "PurgeDuplicate " << setw(10) << PDTimer_.ntimes() << setw(20) << setprecision(3) + << PDTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << PDTimer_.tottime(); +} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc b/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc new file mode 100644 index 0000000000000..ff2e3eea03c40 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc @@ -0,0 +1,64 @@ +#include "L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" +#include + +using namespace std; +using namespace trklet; + +TrackletParametersMemory::TrackletParametersMemory(string name, Settings const& settings, unsigned int iSector) + : MemoryBase(name, settings, iSector) {} + +void TrackletParametersMemory::clean() { + for (auto& tracklet : tracklets_) { + delete tracklet; + } + tracklets_.clear(); +} + +void TrackletParametersMemory::writeMatches(Globals* globals, int& matchesL1, int& matchesL3, int& matchesL5) { + ofstream& out = globals->ofstream("nmatches.txt"); + for (auto& tracklet : tracklets_) { + if ((tracklet->nMatches() + tracklet->nMatchesDisk()) > 0) { + if (tracklet->layer() == 1) + matchesL1++; + if (tracklet->layer() == 3) + matchesL3++; + if (tracklet->layer() == 5) + matchesL5++; + } + out << tracklet->layer() << " " << tracklet->disk() << " " << tracklet->nMatches() << " " + << tracklet->nMatchesDisk() << endl; + } +} + +void TrackletParametersMemory::writeTPAR(bool first) { + std::ostringstream oss; + oss << "../data/MemPrints/TrackletParameters/TrackletParameters_" << getName() << "_" << std::setfill('0') + << std::setw(2) << (iSector_ + 1) << ".dat"; + auto const& fname = oss.str(); + + if (first) { + bx_ = 0; + event_ = 1; + out_.open(fname.c_str()); + } else + out_.open(fname.c_str(), std::ofstream::app); + + out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; + + for (unsigned int j = 0; j < tracklets_.size(); j++) { + string tpar = tracklets_[j]->trackletparstr(); + out_ << "0x"; + out_ << std::setfill('0') << std::setw(2); + out_ << hex << j << dec; + out_ << " " << tpar << " " << trklet::hexFormat(tpar) << endl; + } + out_.close(); + + bx_++; + event_++; + if (bx_ > 7) + bx_ = 0; +} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc b/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc new file mode 100644 index 0000000000000..03f3d420637f4 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc @@ -0,0 +1,949 @@ +#include "L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" +#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" +#include "DataFormats/Math/interface/deltaPhi.h" + +using namespace std; +using namespace trklet; + +TrackletProcessor::TrackletProcessor(string name, Settings const& settings, Globals* globals, unsigned int iSector) + : TrackletCalculatorBase(name, settings, globals, iSector) { + double dphi = 2 * M_PI / N_SECTOR; + double dphiHG = 0.5 * settings_.dphisectorHG() - M_PI / N_SECTOR; + phimin_ = iSector_ * dphi - dphiHG; + phimax_ = phimin_ + dphi + 2 * dphiHG; + phimin_ -= M_PI / N_SECTOR; + phimax_ -= M_PI / N_SECTOR; + phimin_ = reco::reduceRange(phimin_); + phimax_ = reco::reduceRange(phimax_); + if (phimin_ > phimax_) + phimin_ -= 2 * M_PI; + phioffset_ = phimin_; + + for (unsigned int ilayer = 0; ilayer < N_LAYER; ilayer++) { + vector tmp(settings_.nallstubs(ilayer), nullptr); + trackletprojlayers_.push_back(tmp); + } + + for (unsigned int idisk = 0; idisk < N_DISK; idisk++) { + vector tmp(settings_.nallstubs(idisk + N_LAYER), nullptr); + trackletprojdisks_.push_back(tmp); + } + + layer_ = 0; + disk_ = 0; + + if (name_[3] == 'L') { + layer_ = name_[4] - '0'; + if (name_[5] == 'D') + disk_ = name_[6] - '0'; + } + if (name_[3] == 'D') + disk_ = name_[4] - '0'; + + extra_ = (layer_ == 2 && disk_ == 0); + + // set TC index + if (name_[7] == 'A') + iTC_ = 0; + else if (name_[7] == 'B') + iTC_ = 1; + else if (name_[7] == 'C') + iTC_ = 2; + else if (name_[7] == 'D') + iTC_ = 3; + else if (name_[7] == 'E') + iTC_ = 4; + else if (name_[7] == 'F') + iTC_ = 5; + else if (name_[7] == 'G') + iTC_ = 6; + else if (name_[7] == 'H') + iTC_ = 7; + else if (name_[7] == 'I') + iTC_ = 8; + else if (name_[7] == 'J') + iTC_ = 9; + else if (name_[7] == 'K') + iTC_ = 10; + else if (name_[7] == 'L') + iTC_ = 11; + else if (name_[7] == 'M') + iTC_ = 12; + else if (name_[7] == 'N') + iTC_ = 13; + else if (name_[7] == 'O') + iTC_ = 14; + + assert(iTC_ != -1); + + iSeed_ = 99; + if (name_.substr(3, 4) == "L1L2") + iSeed_ = 0; + else if (name_.substr(3, 4) == "L3L4") + iSeed_ = 2; + else if (name_.substr(3, 4) == "L5L6") + iSeed_ = 3; + else if (name_.substr(3, 4) == "D1D2") + iSeed_ = 4; + else if (name_.substr(3, 4) == "D3D4") + iSeed_ = 5; + else if (name_.substr(3, 4) == "D1L1") + iSeed_ = 6; + else if (name_.substr(3, 4) == "D1L2") + iSeed_ = 7; + else if (name_.substr(3, 4) == "L1D1") + iSeed_ = 6; + else if (name_.substr(3, 4) == "L2D1") + iSeed_ = 7; + else if (name_.substr(3, 4) == "L2L3") + iSeed_ = 1; + + assert(iSeed_ != 99); + + TCIndex_ = (iSeed_ << 4) + iTC_; + assert(TCIndex_ >= 0 && TCIndex_ <= (int)settings_.ntrackletmax()); + + assert((layer_ != 0) || (disk_ != 0)); + + if (settings_.usephicritapprox()) { + double phicritFactor = + 0.5 * settings_.rcrit() * globals_->ITC_L1L2()->rinv_final.K() / globals_->ITC_L1L2()->phi0_final.K(); + if (std::abs(phicritFactor - 2.) > 0.25) + edm::LogPrint("Tracklet") + << "TrackletProcessor::TrackletProcessor phicrit approximation may be invalid! Please check."; + } +} + +void TrackletProcessor::addOutputProjection(TrackletProjectionsMemory*& outputProj, MemoryBase* memory) { + outputProj = dynamic_cast(memory); + assert(outputProj != nullptr); +} + +void TrackletProcessor::addOutput(MemoryBase* memory, string output) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " + << output; + } + if (output == "trackpar") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + trackletpars_ = tmp; + return; + } + + if (output.substr(0, 7) == "projout") { + //output is on the form 'projoutL2PHIC' or 'projoutD3PHIB' + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + + unsigned int layerdisk = output[8] - '1'; //layer or disk counting from 0 + unsigned int phiregion = output[12] - 'A'; //phiregion counting from 0 + + if (output[7] == 'L') { + assert(layerdisk < N_LAYER); + assert(phiregion < trackletprojlayers_[layerdisk].size()); + //check that phiregion not already initialized + assert(trackletprojlayers_[layerdisk][phiregion] == nullptr); + trackletprojlayers_[layerdisk][phiregion] = tmp; + return; + } + + if (output[7] == 'D') { + assert(layerdisk < N_DISK); + assert(phiregion < trackletprojdisks_[layerdisk].size()); + //check that phiregion not already initialized + assert(trackletprojdisks_[layerdisk][phiregion] == nullptr); + trackletprojdisks_[layerdisk][phiregion] = tmp; + return; + } + } + + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output; +} + +void TrackletProcessor::addInput(MemoryBase* memory, string input) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " + << input; + } + + if (input == "innervmstubin") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + innervmstubs_.push_back(tmp); + setVMPhiBin(); + return; + } + if (input == "outervmstubin") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + outervmstubs_.push_back(tmp); + setVMPhiBin(); + return; + } + if (input == "innerallstubin") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + innerallstubs_.push_back(tmp); + return; + } + if (input == "outerallstubin") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + outerallstubs_.push_back(tmp); + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input; +} + +void TrackletProcessor::execute() { + unsigned int countall = 0; + unsigned int countsel = 0; + + unsigned int countteall = 0; + unsigned int counttepass = 0; + + StubPairsMemory stubpairs("tmp", settings_, iSector_); //dummy arguments for now + + bool print = false; + + assert(innervmstubs_.size() == outervmstubs_.size()); + + if (!settings_.useSeed(iSeed_)) + return; + + for (unsigned int ivmmem = 0; ivmmem < innervmstubs_.size(); ivmmem++) { + unsigned int innerphibin = innervmstubs_[ivmmem]->phibin(); + unsigned int outerphibin = outervmstubs_[ivmmem]->phibin(); + + unsigned phiindex = 32 * innerphibin + outerphibin; + + //overlap seeding + if (disk_ == 1 && (layer_ == 1 || layer_ == 2)) { + for (unsigned int i = 0; i < innervmstubs_[ivmmem]->nVMStubs(); i++) { + const VMStubTE& innervmstub = innervmstubs_[ivmmem]->getVMStubTE(i); + + int lookupbits = innervmstub.vmbits().value(); + + int rdiffmax = (lookupbits >> 7); + int newbin = (lookupbits & 127); + int bin = newbin / 8; + + int rbinfirst = newbin & 7; + + int start = (bin >> 1); + int last = start + (bin & 1); + + for (int ibin = start; ibin <= last; ibin++) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " looking for matching stub in bin " << ibin << " with " + << outervmstubs_[ivmmem]->nVMStubsBinned(ibin) << " stubs"; + } + for (unsigned int j = 0; j < outervmstubs_[ivmmem]->nVMStubsBinned(ibin); j++) { + countall++; + countteall++; + + const VMStubTE& outervmstub = outervmstubs_[ivmmem]->getVMStubTEBinned(ibin, j); + int rbin = (outervmstub.vmbits().value() & 7); + if (start != ibin) + rbin += 8; + if ((rbin < rbinfirst) || (rbin - rbinfirst > rdiffmax)) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") + << getName() << " layer-disk stub pair rejected because rbin cut : " << rbin << " " << rbinfirst + << " " << rdiffmax; + } + continue; + } + + int ir = ((start & 3) << 3) + rbinfirst; + + assert(innerphibits_ != -1); + assert(outerphibits_ != -1); + + FPGAWord iphiinnerbin = innervmstub.finephi(); + FPGAWord iphiouterbin = outervmstub.finephi(); + + assert(iphiouterbin == outervmstub.finephi()); + + unsigned int index = (((iphiinnerbin.value() << outerphibits_) + iphiouterbin.value()) << 5) + ir; + + assert(index < phitable_[phiindex].size()); + + if (!phitable_[phiindex][index]) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Stub pair rejected because of tracklet pt cut"; + } + continue; + } + + FPGAWord innerbend = innervmstub.bend(); + FPGAWord outerbend = outervmstub.bend(); + + int ptinnerindex = (index << innerbend.nbits()) + innerbend.value(); + int ptouterindex = (index << outerbend.nbits()) + outerbend.value(); + + if (!(pttableinner_[phiindex][ptinnerindex] && pttableouter_[phiindex][ptouterindex])) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : " + << benddecode(innervmstub.bend().value(), innervmstub.isPSmodule()) << " " + << benddecode(outervmstub.bend().value(), outervmstub.isPSmodule()); + } + continue; + } + + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Adding layer-disk pair in " << getName(); + if (settings_.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout.close(); + } + stubpairs.addStubPair( + innervmstub, outervmstub, 0, innervmstubs_[ivmmem]->getName() + " " + outervmstubs_[ivmmem]->getName()); + counttepass++; + countall++; + } + } + } + + } else { + for (unsigned int i = 0; i < innervmstubs_[ivmmem]->nVMStubs(); i++) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "In " << getName() << " have inner stub"; + } + + if ((layer_ == 1 && disk_ == 0) || (layer_ == 2 && disk_ == 0) || (layer_ == 3 && disk_ == 0) || + (layer_ == 5 && disk_ == 0)) { + const VMStubTE& innervmstub = innervmstubs_[ivmmem]->getVMStubTE(i); + + int lookupbits = (int)innervmstub.vmbits().value(); + int zdiffmax = (lookupbits >> 7); + int newbin = (lookupbits & 127); + int bin = newbin / 8; + + int zbinfirst = newbin & 7; + + int start = (bin >> 1); + int last = start + (bin & 1); + + if (print) { + edm::LogVerbatim("Tracklet") << "start last : " << start << " " << last; + } + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Will look in zbins " << start << " to " << last; + } + for (int ibin = start; ibin <= last; ibin++) { + for (unsigned int j = 0; j < outervmstubs_[ivmmem]->nVMStubsBinned(ibin); j++) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "In " << getName() << " have outer stub"; + } + + countteall++; + countall++; + + const VMStubTE& outervmstub = outervmstubs_[ivmmem]->getVMStubTEBinned(ibin, j); + + int zbin = (outervmstub.vmbits().value() & 7); + + if (start != ibin) + zbin += 8; + + if (zbin < zbinfirst || zbin - zbinfirst > zdiffmax) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Stubpair rejected because of wrong fine z"; + } + continue; + } + + if (print) { + edm::LogVerbatim("Tracklet") << "ibin j " << ibin << " " << j; + } + + assert(innerphibits_ != -1); + assert(outerphibits_ != -1); + + FPGAWord iphiinnerbin = innervmstub.finephi(); + FPGAWord iphiouterbin = outervmstub.finephi(); + + int index = (iphiinnerbin.value() << outerphibits_) + iphiouterbin.value(); + + assert(index < (int)phitable_[phiindex].size()); + + if (!phitable_[phiindex][index]) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Stub pair rejected because of tracklet pt cut"; + } + continue; + } + + FPGAWord innerbend = innervmstub.bend(); + FPGAWord outerbend = outervmstub.bend(); + + int ptinnerindex = (index << innerbend.nbits()) + innerbend.value(); + int ptouterindex = (index << outerbend.nbits()) + outerbend.value(); + + if (!(pttableinner_[phiindex][ptinnerindex] && pttableouter_[phiindex][ptouterindex])) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") + << "Stub pair rejected because of stub pt cut bends : " + << benddecode(innervmstub.bend().value(), innervmstub.isPSmodule()) << " " + << benddecode(outervmstub.bend().value(), outervmstub.isPSmodule()); + } + continue; + } + + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName(); + if (settings_.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout.close(); + } + stubpairs.addStubPair(innervmstub, + outervmstub, + 0, + innervmstubs_[ivmmem]->getName() + " " + outervmstubs_[ivmmem]->getName()); + counttepass++; + countall++; + } + } + + } else if ((disk_ == 1 && layer_ == 0) || (disk_ == 3 && layer_ == 0)) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << getName() << "[" << iSector_ << "] Disk-disk pair"; + + const VMStubTE& innervmstub = innervmstubs_[ivmmem]->getVMStubTE(i); + + int lookupbits = (int)innervmstub.vmbits().value(); + bool negdisk = innervmstub.stub()->disk().value() < 0; //TODO - need to store negative disk + int rdiffmax = (lookupbits >> 6); + int newbin = (lookupbits & 63); + int bin = newbin / 8; + + int rbinfirst = newbin & 7; + + int start = (bin >> 1); + if (negdisk) + start += 4; + int last = start + (bin & 1); + for (int ibin = start; ibin <= last; ibin++) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << getName() << " looking for matching stub in bin " << ibin << " with " + << outervmstubs_[ivmmem]->nVMStubsBinned(ibin) << " stubs"; + for (unsigned int j = 0; j < outervmstubs_[ivmmem]->nVMStubsBinned(ibin); j++) { + countall++; + countteall++; + + const VMStubTE& outervmstub = outervmstubs_[ivmmem]->getVMStubTEBinned(ibin, j); + + int vmbits = (int)outervmstub.vmbits().value(); + int rbin = (vmbits & 7); + if (start != ibin) + rbin += 8; + if (rbin < rbinfirst) + continue; + if (rbin - rbinfirst > rdiffmax) + continue; + + unsigned int irouterbin = vmbits >> 2; + + FPGAWord iphiinnerbin = innervmstub.finephi(); + FPGAWord iphiouterbin = outervmstub.finephi(); + + unsigned int index = (irouterbin << (outerphibits_ + innerphibits_)) + + (iphiinnerbin.value() << outerphibits_) + iphiouterbin.value(); + + assert(index < phitable_[phiindex].size()); + if (!phitable_[phiindex][index]) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "Stub pair rejected because of tracklet pt cut"; + } + continue; + } + + FPGAWord innerbend = innervmstub.bend(); + FPGAWord outerbend = outervmstub.bend(); + + unsigned int ptinnerindex = (index << innerbend.nbits()) + innerbend.value(); + unsigned int ptouterindex = (index << outerbend.nbits()) + outerbend.value(); + + assert(ptinnerindex < pttableinner_[phiindex].size()); + assert(ptouterindex < pttableouter_[phiindex].size()); + + if (!(pttableinner_[phiindex][ptinnerindex] && pttableouter_[phiindex][ptouterindex])) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") + << "Stub pair rejected because of stub pt cut bends : " + << benddecode(innervmstub.bend().value(), innervmstub.isPSmodule()) << " " + << benddecode(outervmstub.bend().value(), outervmstub.isPSmodule()) + << " pass : " << pttableinner_[phiindex][ptinnerindex] << " " + << pttableouter_[phiindex][ptouterindex]; + } + continue; + } + + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Adding disk-disk pair in " << getName(); + + if (settings_.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout.close(); + } + stubpairs.addStubPair(innervmstub, + outervmstub, + 0, + innervmstubs_[ivmmem]->getName() + " " + outervmstubs_[ivmmem]->getName()); + countall++; + counttepass++; + } + } + } + } + } + } + + if (settings_.writeMonitorData("TE")) { + globals_->ofstream("trackletprocessor.txt") << getName() << " " << countteall << " " << counttepass << endl; + } + + for (unsigned int i = 0; i < stubpairs.nStubPairs(); i++) { + if (trackletpars_->nTracklets() >= settings_.ntrackletmax()) { + edm::LogVerbatim("Tracklet") << "Will break on too many tracklets in " << getName(); + break; + } + countall++; + const Stub* innerFPGAStub = stubpairs.getVMStub1(i).stub(); + const L1TStub* innerStub = innerFPGAStub->l1tstub(); + + const Stub* outerFPGAStub = stubpairs.getVMStub2(i).stub(); + const L1TStub* outerStub = outerFPGAStub->l1tstub(); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "TrackletProcessor execute " << getName() << "[" << iSector_ << "]"; + } + + bool accept = false; + + if (innerFPGAStub->isBarrel() && (getName() != "TC_D1L2A" && getName() != "TC_D1L2B")) { + if (outerFPGAStub->isDisk()) { + //overlap seeding + accept = overlapSeeding(outerFPGAStub, outerStub, innerFPGAStub, innerStub); + } else { + //barrel+barrel seeding + accept = barrelSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); + } + } else { + if (outerFPGAStub->isDisk()) { + //disk+disk seeding + accept = diskSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); + } else if (innerFPGAStub->isDisk()) { + //layer+disk seeding + accept = overlapSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); + } else { + throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Invalid seeding!"; + } + } + + if (accept) + countsel++; + + if (settings_.writeMonitorData("TP")) { + globals_->ofstream("tc_seedpairs.txt") << stubpairs.getTEDName(i) << " " << accept << endl; + } + + if (trackletpars_->nTracklets() >= settings_.ntrackletmax()) { + edm::LogVerbatim("Tracklet") << "Will break on number of tracklets in " << getName(); + break; + } + + if (countall >= settings_.maxStep("TP")) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Will break on MAXTC 1"; + break; + } + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "TrackletProcessor execute done"; + } + } + if (countall >= settings_.maxStep("TP")) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Will break on MAXTC 2"; + //break; + } + + if (settings_.writeMonitorData("TP")) { + globals_->ofstream("trackletcalculator.txt") << getName() << " " << countall << " " << countsel << endl; + } +} + +void TrackletProcessor::setVMPhiBin() { + if (innervmstubs_.size() != outervmstubs_.size()) + return; + + for (unsigned int ivmmem = 0; ivmmem < innervmstubs_.size(); ivmmem++) { + unsigned int innerphibin = innervmstubs_[ivmmem]->phibin(); + unsigned int outerphibin = outervmstubs_[ivmmem]->phibin(); + + unsigned phiindex = 32 * innerphibin + outerphibin; + + if (phitable_.find(phiindex) != phitable_.end()) + continue; + + innervmstubs_[ivmmem]->setother(outervmstubs_[ivmmem]); + outervmstubs_[ivmmem]->setother(innervmstubs_[ivmmem]); + + if ((layer_ == 1 && disk_ == 0) || (layer_ == 2 && disk_ == 0) || (layer_ == 3 && disk_ == 0) || + (layer_ == 5 && disk_ == 0)) { + innerphibits_ = settings_.nfinephi(0, iSeed_); + outerphibits_ = settings_.nfinephi(1, iSeed_); + + int innerphibins = (1 << innerphibits_); + int outerphibins = (1 << outerphibits_); + + double innerphimin, innerphimax; + innervmstubs_[ivmmem]->getPhiRange(innerphimin, innerphimax, iSeed_, 0); + double rinner = settings_.rmean(layer_ - 1); + + double outerphimin, outerphimax; + outervmstubs_[ivmmem]->getPhiRange(outerphimin, outerphimax, iSeed_, 1); + double router = settings_.rmean(layer_); + + double phiinner[2]; + double phiouter[2]; + + std::vector vmbendinner; + std::vector vmbendouter; + unsigned int nbins1 = 8; + if (layer_ >= 4) + nbins1 = 16; + for (unsigned int i = 0; i < nbins1; i++) { + vmbendinner.push_back(false); + } + + unsigned int nbins2 = 8; + if (layer_ >= 3) + nbins2 = 16; + for (unsigned int i = 0; i < nbins2; i++) { + vmbendouter.push_back(false); + } + + for (int iphiinnerbin = 0; iphiinnerbin < innerphibins; iphiinnerbin++) { + phiinner[0] = innerphimin + iphiinnerbin * (innerphimax - innerphimin) / innerphibins; + phiinner[1] = innerphimin + (iphiinnerbin + 1) * (innerphimax - innerphimin) / innerphibins; + for (int iphiouterbin = 0; iphiouterbin < outerphibins; iphiouterbin++) { + phiouter[0] = outerphimin + iphiouterbin * (outerphimax - outerphimin) / outerphibins; + phiouter[1] = outerphimin + (iphiouterbin + 1) * (outerphimax - outerphimin) / outerphibins; + + double bendinnermin = 20.0; + double bendinnermax = -20.0; + double bendoutermin = 20.0; + double bendoutermax = -20.0; + double rinvmin = 1.0; + for (int i1 = 0; i1 < 2; i1++) { + for (int i2 = 0; i2 < 2; i2++) { + double rinv1 = rinv(phiinner[i1], phiouter[i2], rinner, router); + double pitchinner = + (rinner < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); + double pitchouter = + (router < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); + double abendinner = -bend(rinner, rinv1, pitchinner); + double abendouter = -bend(router, rinv1, pitchouter); + if (abendinner < bendinnermin) + bendinnermin = abendinner; + if (abendinner > bendinnermax) + bendinnermax = abendinner; + if (abendouter < bendoutermin) + bendoutermin = abendouter; + if (abendouter > bendoutermax) + bendoutermax = abendouter; + if (std::abs(rinv1) < rinvmin) { + rinvmin = std::abs(rinv1); + } + } + } + + phitable_[phiindex].push_back(rinvmin < settings_.rinvcutte()); + + int nbins1 = 8; + if (layer_ >= 4) + nbins1 = 16; + for (int ibend = 0; ibend < nbins1; ibend++) { + double bend = benddecode(ibend, layer_ <= 3); + + bool passinner = bend - bendinnermin > -settings_.bendcutte(0, iSeed_) && + bend - bendinnermax < settings_.bendcutte(0, iSeed_); + if (passinner) + vmbendinner[ibend] = true; + pttableinner_[phiindex].push_back(passinner); + } + + int nbins2 = 8; + if (layer_ >= 3) + nbins2 = 16; + for (int ibend = 0; ibend < nbins2; ibend++) { + double bend = benddecode(ibend, layer_ <= 2); + + bool passouter = bend - bendoutermin > -settings_.bendcutte(1, iSeed_) && + bend - bendoutermax < settings_.bendcutte(1, iSeed_); + if (passouter) + vmbendouter[ibend] = true; + pttableouter_[phiindex].push_back(passouter); + } + } + } + + innervmstubs_[ivmmem]->setbendtable(vmbendinner); + outervmstubs_[ivmmem]->setbendtable(vmbendouter); + + if (iSector_ == 0 && settings_.writeTable()) + writeTETable(); + } + + if ((disk_ == 1 && layer_ == 0) || (disk_ == 3 && layer_ == 0)) { + innerphibits_ = settings_.nfinephi(0, iSeed_); + outerphibits_ = settings_.nfinephi(0, iSeed_); + + int outerrbits = 3; + + int outerrbins = (1 << outerrbits); + int innerphibins = (1 << innerphibits_); + int outerphibins = (1 << outerphibits_); + + double innerphimin, innerphimax; + innervmstubs_[ivmmem]->getPhiRange(innerphimin, innerphimax, iSeed_, 0); + + double outerphimin, outerphimax; + outervmstubs_[ivmmem]->getPhiRange(outerphimin, outerphimax, iSeed_, 1); + + double phiinner[2]; + double phiouter[2]; + double router[2]; + + std::vector vmbendinner; + std::vector vmbendouter; + + for (unsigned int i = 0; i < 8; i++) { + vmbendinner.push_back(false); + vmbendouter.push_back(false); + } + + for (int irouterbin = 0; irouterbin < outerrbins; irouterbin++) { + router[0] = + settings_.rmindiskvm() + irouterbin * (settings_.rmaxdiskvm() - settings_.rmindiskvm()) / outerrbins; + router[1] = + settings_.rmindiskvm() + (irouterbin + 1) * (settings_.rmaxdiskvm() - settings_.rmindiskvm()) / outerrbins; + for (int iphiinnerbin = 0; iphiinnerbin < innerphibins; iphiinnerbin++) { + phiinner[0] = innerphimin + iphiinnerbin * (innerphimax - innerphimin) / innerphibins; + phiinner[1] = innerphimin + (iphiinnerbin + 1) * (innerphimax - innerphimin) / innerphibins; + for (int iphiouterbin = 0; iphiouterbin < outerphibins; iphiouterbin++) { + phiouter[0] = outerphimin + iphiouterbin * (outerphimax - outerphimin) / outerphibins; + phiouter[1] = outerphimin + (iphiouterbin + 1) * (outerphimax - outerphimin) / outerphibins; + + double bendinnermin = 20.0; + double bendinnermax = -20.0; + double bendoutermin = 20.0; + double bendoutermax = -20.0; + double rinvmin = 1.0; + double rinvmax = -1.0; + for (int i1 = 0; i1 < 2; i1++) { + for (int i2 = 0; i2 < 2; i2++) { + for (int i3 = 0; i3 < 2; i3++) { + double rinner = router[i3] * settings_.zmean(disk_ - 1) / settings_.zmean(disk_); + double rinv1 = rinv(phiinner[i1], phiouter[i2], rinner, router[i3]); + double pitchinner = + (rinner < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); + double pitchouter = + (router[i3] < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); + double abendinner = bend(rinner, rinv1, pitchinner); + double abendouter = bend(router[i3], rinv1, pitchouter); + if (abendinner < bendinnermin) + bendinnermin = abendinner; + if (abendinner > bendinnermax) + bendinnermax = abendinner; + if (abendouter < bendoutermin) + bendoutermin = abendouter; + if (abendouter > bendoutermax) + bendoutermax = abendouter; + if (std::abs(rinv1) < rinvmin) { + rinvmin = std::abs(rinv1); + } + if (std::abs(rinv1) > rinvmax) { + rinvmax = std::abs(rinv1); + } + } + } + } + + phitable_[phiindex].push_back(rinvmin < settings_.rinvcutte()); + + for (int ibend = 0; ibend < 8; ibend++) { + double bend = benddecode(ibend, true); + + bool passinner = bend - bendinnermin > -settings_.bendcutte(0, iSeed_) && + bend - bendinnermax < settings_.bendcutte(0, iSeed_); + if (passinner) + vmbendinner[ibend] = true; + pttableinner_[phiindex].push_back(passinner); + } + + for (int ibend = 0; ibend < 8; ibend++) { + double bend = benddecode(ibend, true); + + bool passouter = bend - bendoutermin > -settings_.bendcutte(1, iSeed_) && + bend - bendoutermax < settings_.bendcutte(1, iSeed_); + if (passouter) + vmbendouter[ibend] = true; + pttableouter_[phiindex].push_back(passouter); + } + } + } + } + + innervmstubs_[ivmmem]->setbendtable(vmbendinner); + outervmstubs_[ivmmem]->setbendtable(vmbendouter); + + if (iSector_ == 0 && settings_.writeTable()) + writeTETable(); + + } else if (disk_ == 1 && (layer_ == 1 || layer_ == 2)) { + innerphibits_ = settings_.nfinephi(0, iSeed_); + outerphibits_ = settings_.nfinephi(1, iSeed_); + unsigned int nrbits = 5; + + int innerphibins = (1 << innerphibits_); + int outerphibins = (1 << outerphibits_); + + double innerphimin, innerphimax; + innervmstubs_[ivmmem]->getPhiRange(innerphimin, innerphimax, iSeed_, 0); + + double outerphimin, outerphimax; + outervmstubs_[ivmmem]->getPhiRange(outerphimin, outerphimax, iSeed_, 1); + + double phiinner[2]; + double phiouter[2]; + double router[2]; + + std::vector vmbendinner; + std::vector vmbendouter; + + for (unsigned int i = 0; i < 8; i++) { + vmbendinner.push_back(false); + vmbendouter.push_back(false); + } + + double dr = (settings_.rmaxdiskvm() - settings_.rmindiskvm()) / (1 << nrbits); + + for (int iphiinnerbin = 0; iphiinnerbin < innerphibins; iphiinnerbin++) { + phiinner[0] = innerphimin + iphiinnerbin * (innerphimax - innerphimin) / innerphibins; + phiinner[1] = innerphimin + (iphiinnerbin + 1) * (innerphimax - innerphimin) / innerphibins; + for (int iphiouterbin = 0; iphiouterbin < outerphibins; iphiouterbin++) { + phiouter[0] = outerphimin + iphiouterbin * (outerphimax - outerphimin) / outerphibins; + phiouter[1] = outerphimin + (iphiouterbin + 1) * (outerphimax - outerphimin) / outerphibins; + for (int irbin = 0; irbin < (1 << nrbits); irbin++) { + router[0] = settings_.rmindiskvm() + dr * irbin; + router[1] = router[0] + dr; + double bendinnermin = 20.0; + double bendinnermax = -20.0; + double bendoutermin = 20.0; + double bendoutermax = -20.0; + double rinvmin = 1.0; + for (int i1 = 0; i1 < 2; i1++) { + for (int i2 = 0; i2 < 2; i2++) { + for (int i3 = 0; i3 < 2; i3++) { + double rinner = settings_.rmean(layer_ - 1); + double rinv1 = rinv(phiinner[i1], phiouter[i2], rinner, router[i3]); + double pitchinner = + (rinner < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); + double pitchouter = + (router[i3] < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); + double abendinner = bend(rinner, rinv1, pitchinner); + double abendouter = bend(router[i3], rinv1, pitchouter); + if (abendinner < bendinnermin) + bendinnermin = abendinner; + if (abendinner > bendinnermax) + bendinnermax = abendinner; + if (abendouter < bendoutermin) + bendoutermin = abendouter; + if (abendouter > bendoutermax) + bendoutermax = abendouter; + if (std::abs(rinv1) < rinvmin) { + rinvmin = std::abs(rinv1); + } + } + } + } + + phitable_[phiindex].push_back(rinvmin < settings_.rinvcutte()); + + for (int ibend = 0; ibend < 8; ibend++) { + double bend = benddecode(ibend, true); + + bool passinner = bend - bendinnermin > -settings_.bendcutte(0, iSeed_) && + bend - bendinnermax < settings_.bendcutte(0, iSeed_); + if (passinner) + vmbendinner[ibend] = true; + pttableinner_[phiindex].push_back(passinner); + } + + for (int ibend = 0; ibend < 8; ibend++) { + double bend = benddecode(ibend, true); + + bool passouter = bend - bendoutermin > -settings_.bendcutte(1, iSeed_) && + bend - bendoutermax < settings_.bendcutte(1, iSeed_); + if (passouter) + vmbendouter[ibend] = true; + pttableouter_[phiindex].push_back(passouter); + } + } + } + } + + innervmstubs_[ivmmem]->setbendtable(vmbendinner); + outervmstubs_[ivmmem]->setbendtable(vmbendouter); + + if (iSector_ == 0 && settings_.writeTable()) + writeTETable(); + } + } +} + +void TrackletProcessor::writeTETable() { + ofstream outptcut; + outptcut.open(getName() + "_ptcut.tab"); + outptcut << "{" << endl; + //for(unsigned int i=0;i +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +using namespace std; +using namespace trklet; + +TrackletProjectionsMemory::TrackletProjectionsMemory(string name, Settings const& settings, unsigned int iSector) + : MemoryBase(name, settings, iSector) { + if (settings_.extended()) { + initLayerDisk(14, layer_, disk_); + } else { + initLayerDisk(12, layer_, disk_); + } +} + +void TrackletProjectionsMemory::addProj(Tracklet* tracklet) { + if (layer_ != 0 && disk_ == 0) + assert(tracklet->validProj(layer_)); + if (layer_ == 0 && disk_ != 0) + assert(tracklet->validProjDisk(disk_)); + if (layer_ != 0 && disk_ != 0) + assert(tracklet->validProj(layer_) || tracklet->validProjDisk(disk_)); + + for (auto& itracklet : tracklets_) { + if (itracklet == tracklet) { + edm::LogPrint("Tracklet") << "Adding same tracklet " << tracklet << " twice in " << getName(); + } + assert(itracklet != tracklet); + } + + tracklets_.push_back(tracklet); +} + +void TrackletProjectionsMemory::clean() { tracklets_.clear(); } + +void TrackletProjectionsMemory::writeTPROJ(bool first) { + std::ostringstream oss; + oss << "../data/MemPrints/TrackletProjections/TrackletProjections_" << getName() << "_" << std::setfill('0') + << std::setw(2) << (iSector_ + 1) << ".dat"; + auto const& fname = oss.str(); + + if (first) { + bx_ = 0; + event_ = 1; + out_.open(fname.c_str()); + } else + out_.open(fname.c_str(), std::ofstream::app); + + out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; + + for (unsigned int j = 0; j < tracklets_.size(); j++) { + string proj = (layer_ > 0 && tracklets_[j]->validProj(layer_)) ? tracklets_[j]->trackletprojstrlayer(layer_) + : tracklets_[j]->trackletprojstrdisk(disk_); + out_ << "0x"; + out_ << std::setfill('0') << std::setw(2); + out_ << hex << j << dec; + out_ << " " << proj << " " << trklet::hexFormat(proj) << endl; + } + out_.close(); + + bx_++; + event_++; + if (bx_ > 7) + bx_ = 0; +} diff --git a/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc b/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc new file mode 100644 index 0000000000000..771dedf7474f2 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc @@ -0,0 +1,478 @@ +#include "L1Trigger/TrackFindingTracklet/interface/TripletEngine.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +#include + +using namespace std; +using namespace trklet; + +TripletEngine::TripletEngine(string name, Settings const &settings, Globals *global, unsigned int iSector) + : ProcessBase(name, settings, global, iSector) { + stubpairs_.clear(); + thirdvmstubs_.clear(); + layer1_ = 0; + layer2_ = 0; + layer3_ = 0; + disk1_ = 0; + disk2_ = 0; + disk3_ = 0; + dct1_ = 0; + dct2_ = 0; + dct3_ = 0; + phi1_ = 0; + phi2_ = 0; + phi3_ = 0; + z1_ = 0; + z2_ = 0; + z3_ = 0; + r1_ = 0; + r2_ = 0; + r3_ = 0; + + if (name_[4] == 'L') + layer1_ = name_[5] - '0'; + if (name_[4] == 'D') + disk1_ = name_[5] - '0'; + if (name_[7] == 'L') + layer2_ = name_[8] - '0'; + if (name_[7] == 'D') + disk2_ = name_[8] - '0'; + + if (layer1_ == 3 && layer2_ == 4) { + layer3_ = 2; + iSeed_ = 8; + } else if (layer1_ == 5 && layer2_ == 6) { + layer3_ = 4; + iSeed_ = 9; + } else if (layer1_ == 2 && layer2_ == 3) { + disk3_ = 1; + iSeed_ = 10; + } else if (disk1_ == 1 && disk2_ == 2) { + layer3_ = 2; + iSeed_ = 11; + } else + throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Invalid seeding!"; + + if ((layer2_ == 4 && layer3_ == 2) || (layer2_ == 6 && layer3_ == 4)) { + secondphibits_ = settings_.nfinephi(1, iSeed_); + thirdphibits_ = settings_.nfinephi(2, iSeed_); + } + if ((layer2_ == 3 && disk3_ == 1) || (disk2_ == 2 && layer3_ == 2)) { + secondphibits_ = settings_.nfinephi(1, iSeed_); + thirdphibits_ = settings_.nfinephi(2, iSeed_); + } + readTables(); +} + +TripletEngine::~TripletEngine() { + if (settings_.writeTripletTables()) + writeTables(); +} + +void TripletEngine::addOutput(MemoryBase *memory, string output) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " + << output; + } + if (output == "stubtripout") { + auto *tmp = dynamic_cast(memory); + assert(tmp != nullptr); + stubtriplets_ = tmp; + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output; +} + +void TripletEngine::addInput(MemoryBase *memory, string input) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " + << input; + } + if (input == "thirdvmstubin") { + auto *tmp = dynamic_cast(memory); + assert(tmp != nullptr); + thirdvmstubs_.push_back(tmp); + return; + } + if (input.substr(0, 8) == "stubpair") { + auto *tmp = dynamic_cast(memory); + assert(tmp != nullptr); + stubpairs_.push_back(tmp); + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input; +} + +void TripletEngine::execute() { + unsigned int countall = 0; + unsigned int countpass = 0; + unsigned int nThirdStubs = 0; + count_ = 0; + + for (unsigned int iThirdMem = 0; iThirdMem < thirdvmstubs_.size(); + nThirdStubs += thirdvmstubs_.at(iThirdMem)->nVMStubs(), iThirdMem++) + ; + + assert(!thirdvmstubs_.empty()); + assert(!stubpairs_.empty()); + + bool print = false && (getName().substr(0, 10) == "TRE_L2cL3c"); + + print = print && nThirdStubs > 0; + + int hacksum = 0; + if (print) { + edm::LogVerbatim("Tracklet") << "In TripletEngine::execute : " << getName() << " " << nThirdStubs << ":"; + for (unsigned int i = 0; i < thirdvmstubs_.size(); ++i) { + edm::LogVerbatim("Tracklet") << thirdvmstubs_.at(i)->getName() << " " << thirdvmstubs_.at(i)->nVMStubs(); + } + int s = 0; + std::string oss = ""; + for (unsigned int i = 0; i < stubpairs_.size(); ++i) { + oss += std::to_string(stubpairs_.at(i)->nStubPairs()); + oss += " "; + s += stubpairs_.at(i)->nStubPairs(); + } + hacksum += nThirdStubs * s; + edm::LogVerbatim("Tracklet") << oss; + for (unsigned int i = 0; i < stubpairs_.size(); ++i) { + edm::LogVerbatim("Tracklet") << " " << stubpairs_.at(i)->getName(); + } + } + + tmpSPTable_.clear(); + + for (unsigned int i = 0; i < stubpairs_.size(); ++i) { + for (unsigned int j = 0; j < stubpairs_.at(i)->nStubPairs(); ++j) { + if (print) + edm::LogVerbatim("Tracklet") << " ***** " << stubpairs_.at(i)->getName() << " " + << stubpairs_.at(i)->nStubPairs(); + + auto firstvmstub = stubpairs_.at(i)->getVMStub1(j); + auto secondvmstub = stubpairs_.at(i)->getVMStub2(j); + + if ((layer2_ == 4 && layer3_ == 2) || (layer2_ == 6 && layer3_ == 4)) { + int lookupbits = (int)((firstvmstub.vmbits().value() >> 10) & 1023); + int newbin = (lookupbits & 127); + int bin = newbin / 8; + + int start = (bin >> 1); + int last = start + (bin & 1); + + for (int ibin = start; ibin <= last; ibin++) { + for (unsigned int k = 0; k < thirdvmstubs_.size(); k++) { + string vmsteSuffix = thirdvmstubs_.at(k)->getLastPartOfName(); + vmsteSuffix = vmsteSuffix.substr(0, vmsteSuffix.find_last_of('n')); + if (stubpairs_.at(i)->getLastPartOfName() != vmsteSuffix) + continue; + for (unsigned int l = 0; l < thirdvmstubs_.at(k)->nVMStubsBinned(ibin); l++) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << "In " << getName() << " have third stub"; + } + + if (countall >= settings_.maxStep("TRE")) + break; + countall++; + + const VMStubTE &thirdvmstub = thirdvmstubs_.at(k)->getVMStubTEBinned(ibin, l); + + assert(secondphibits_ != -1); + assert(thirdphibits_ != -1); + + unsigned int nvmsecond = settings_.nallstubs(layer2_ - 1) * settings_.nvmte(1, iSeed_); + unsigned int nvmbitssecond = nbits(nvmsecond); + + FPGAWord iphisecondbin = secondvmstub.stub()->iphivmFineBins(nvmbitssecond, secondphibits_); + + //currently not using same number of bits as in the TED + //assert(iphisecondbin==(int)secondvmstub.finephi()); + FPGAWord iphithirdbin = thirdvmstub.finephi(); + + unsigned int index = (iphisecondbin.value() << thirdphibits_) + iphithirdbin.value(); + + FPGAWord secondbend = secondvmstub.bend(); + FPGAWord thirdbend = thirdvmstub.bend(); + + index = (index << secondbend.nbits()) + secondbend.value(); + index = (index << thirdbend.nbits()) + thirdbend.value(); + + if (index >= table_.size()) + table_.resize(index + 1, false); + + if (!table_[index]) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") + << "Stub pair rejected because of stub pt cut bends : " + << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule()) << " " + << benddecode(thirdvmstub.bend().value(), thirdvmstub.isPSmodule()); + } + if (!settings_.writeTripletTables()) + continue; + } + if (settings_.writeTripletTables()) + table_[index] = true; + + const unsigned spIndex = stubpairs_.at(i)->getIndex(j); + const string &tedName = stubpairs_.at(i)->getTEDName(j); + if (!tmpSPTable_.count(tedName)) + tmpSPTable_[tedName]; + if (spIndex >= tmpSPTable_.at(tedName).size()) + tmpSPTable_.at(tedName).resize(spIndex + 1); + tmpSPTable_.at(tedName).at(spIndex).push_back(stubpairs_.at(i)->getName()); + + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName(); + if (settings_.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout.close(); + } + stubtriplets_->addStubs(thirdvmstub.stub(), + (stubpairs_.at(i))->getVMStub1(j).stub(), + (stubpairs_.at(i))->getVMStub2(j).stub()); + + countpass++; + } + } + } + + } + + else if (disk2_ == 2 && layer3_ == 2) { + int lookupbits = (int)((firstvmstub.vmbits().value() >> 9) & 1023); + int newbin = (lookupbits & 127); + int bin = newbin / 8; + + int start = (bin >> 1); + int last = start + (bin & 1); + + if (firstvmstub.stub()->disk().value() < 0) { //TODO - negative disk should come from memory + start = settings_.NLONGVMBINS() - last - 1; + last = settings_.NLONGVMBINS() - start - 1; + } + + for (int ibin = start; ibin <= last; ibin++) { + for (unsigned int k = 0; k < thirdvmstubs_.size(); k++) { + string vmsteSuffix = thirdvmstubs_.at(k)->getLastPartOfName(); + vmsteSuffix = vmsteSuffix.substr(0, vmsteSuffix.find_last_of('n')); + if (stubpairs_.at(i)->getLastPartOfName() != vmsteSuffix) + continue; + for (unsigned int l = 0; l < thirdvmstubs_.at(k)->nVMStubsBinned(ibin); l++) { + if (countall >= settings_.maxStep("TRE")) + break; + countall++; + + const VMStubTE &thirdvmstub = thirdvmstubs_.at(k)->getVMStubTEBinned(ibin, l); + + assert(secondphibits_ != -1); + assert(thirdphibits_ != -1); + + FPGAWord iphisecondbin = secondvmstub.finephi(); + FPGAWord iphithirdbin = thirdvmstub.finephi(); + + unsigned int index = (iphisecondbin.value() << thirdphibits_) + iphithirdbin.value(); + + FPGAWord secondbend = secondvmstub.bend(); + FPGAWord thirdbend = thirdvmstub.bend(); + + index = (index << secondbend.nbits()) + secondbend.value(); + index = (index << thirdbend.nbits()) + thirdbend.value(); + + if (index >= table_.size()) + table_.resize(index + 1, false); + + if (!table_[index]) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") + << "Stub pair rejected because of stub pt cut bends : " + << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule()) << " " + << benddecode(thirdvmstub.bend().value(), thirdvmstub.isPSmodule()); + } + if (!settings_.writeTripletTables()) + continue; + } + if (settings_.writeTripletTables()) + table_[index] = true; + + const unsigned spIndex = stubpairs_.at(i)->getIndex(j); + const string &tedName = stubpairs_.at(i)->getTEDName(j); + if (!tmpSPTable_.count(tedName)) + tmpSPTable_[tedName]; + if (spIndex >= tmpSPTable_.at(tedName).size()) + tmpSPTable_.at(tedName).resize(spIndex + 1); + tmpSPTable_.at(tedName).at(spIndex).push_back(stubpairs_.at(i)->getName()); + + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Adding layer-disk pair in " << getName(); + if (settings_.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout.close(); + } + stubtriplets_->addStubs(thirdvmstub.stub(), + (stubpairs_.at(i))->getVMStub1(j).stub(), + (stubpairs_.at(i))->getVMStub2(j).stub()); + countpass++; + } + } + } + } + + else if (layer2_ == 3 && disk3_ == 1) { + int lookupbits = (int)((firstvmstub.vmbits().value() >> 10) & 1023); + + int newbin = (lookupbits & 127); + int bin = newbin / 8; + + int start = (bin >> 1); + int last = start + (bin & 1); + + for (int ibin = start; ibin <= last; ibin++) { + for (unsigned int k = 0; k < thirdvmstubs_.size(); k++) { + string vmsteSuffix = thirdvmstubs_.at(k)->getLastPartOfName(); + vmsteSuffix = vmsteSuffix.substr(0, vmsteSuffix.find_last_of('n')); + if (stubpairs_.at(i)->getLastPartOfName() != vmsteSuffix) + continue; + assert(thirdvmstubs_.at(k)->nVMStubsBinned(ibin) == thirdvmstubs_.at(k)->nVMStubsBinned(ibin)); + for (unsigned int l = 0; l < thirdvmstubs_.at(k)->nVMStubsBinned(ibin); l++) { + if (countall >= settings_.maxStep("TRE")) + break; + countall++; + + const VMStubTE &thirdvmstub = thirdvmstubs_.at(k)->getVMStubTEBinned(ibin, l); + + assert(secondphibits_ != -1); + assert(thirdphibits_ != -1); + + unsigned int nvmsecond; + + nvmsecond = settings_.nallstubs(layer2_ - 1) * settings_.nvmte(1, iSeed_); + unsigned int nvmbitssecond = nbits(nvmsecond); + + FPGAWord iphisecondbin = secondvmstub.stub()->iphivmFineBins(nvmbitssecond, secondphibits_); + + //currentlty not using same number of bits as in the TED + //assert(iphisecondbin==(int)secondvmstub.finephi()); + FPGAWord iphithirdbin = thirdvmstub.finephi(); + + unsigned int index = (iphisecondbin.value() << thirdphibits_) + iphithirdbin.value(); + + FPGAWord secondbend = secondvmstub.bend(); + FPGAWord thirdbend = thirdvmstub.bend(); + + index = (index << secondbend.nbits()) + secondbend.value(); + index = (index << thirdbend.nbits()) + thirdbend.value(); + + if (index >= table_.size()) + table_.resize(index + 1, false); + + if (!table_[index]) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") + << "Stub pair rejected because of stub pt cut bends : " + << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule()) << " " + << benddecode(thirdvmstub.bend().value(), thirdvmstub.isPSmodule()); + } + if (!settings_.writeTripletTables()) + continue; + } + if (settings_.writeTripletTables()) + table_[index] = true; + + const unsigned spIndex = stubpairs_.at(i)->getIndex(j); + const string &tedName = stubpairs_.at(i)->getTEDName(j); + if (!tmpSPTable_.count(tedName)) + tmpSPTable_[tedName]; + if (spIndex >= tmpSPTable_.at(tedName).size()) + tmpSPTable_.at(tedName).resize(spIndex + 1); + tmpSPTable_.at(tedName).at(spIndex).push_back(stubpairs_.at(i)->getName()); + + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Adding layer-disk pair in " << getName(); + if (settings_.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout.close(); + } + stubtriplets_->addStubs(thirdvmstub.stub(), + (stubpairs_.at(i))->getVMStub1(j).stub(), + (stubpairs_.at(i))->getVMStub2(j).stub()); + countpass++; + } + } + } + } + } + } + + for (const auto &tedName : tmpSPTable_) { + for (unsigned spIndex = 0; spIndex < tedName.second.size(); spIndex++) { + if (tedName.second.at(spIndex).empty()) + continue; + vector entry(tedName.second.at(spIndex)); + sort(entry.begin(), entry.end()); + entry.erase(unique(entry.begin(), entry.end()), entry.end()); + const string &spName = entry.at(0); + + if (!spTable_.count(tedName.first)) + spTable_[tedName.first]; + if (spIndex >= spTable_.at(tedName.first).size()) + spTable_.at(tedName.first).resize(spIndex + 1); + if (!spTable_.at(tedName.first).at(spIndex).count(spName)) + spTable_.at(tedName.first).at(spIndex)[spName] = 0; + spTable_.at(tedName.first).at(spIndex)[spName]++; + } + } + + if (settings_.writeMonitorData("TRE")) { + globals_->ofstream("tripletengine.txt") << getName() << " " << countall << " " << countpass << endl; + } +} + +void TripletEngine::readTables() { + ifstream fin; + string tableName, word; + unsigned num; + + tableName = "../data/table_TRE/table_" + name_ + ".txt"; + + fin.open(tableName, ifstream::in); + if (!fin) { + throw cms::Exception("BadConfig") << "TripletEngine::readTables, file " << tableName << " not known"; + } + while (!fin.eof()) { + fin >> word; + num = atoi(word.c_str()); + table_.push_back(num > 0 ? true : false); + } + fin.close(); +} + +void TripletEngine::writeTables() { + ofstream fout; + stringstream tableName; + + tableName << "table/table_" << name_ << "_" << iSector_ << ".txt"; + + fout.open(tableName.str(), ofstream::out); + for (const auto &entry : table_) + fout << entry << endl; + fout.close(); + + for (const auto &tedName : spTable_) { + tableName.str(""); + tableName << "table/table_" << tedName.first << "_" << name_ << "_" << iSector_ << ".txt"; + + fout.open(tableName.str(), ofstream::out); + for (const auto &entry : tedName.second) { + for (const auto &spName : entry) + fout << spName.first << ":" << spName.second << " "; + fout << endl; + } + fout.close(); + } +} diff --git a/L1Trigger/TrackFindingTracklet/src/VMProjectionsMemory.cc b/L1Trigger/TrackFindingTracklet/src/VMProjectionsMemory.cc new file mode 100644 index 0000000000000..ff4c8f2be7191 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/VMProjectionsMemory.cc @@ -0,0 +1,57 @@ +#include "L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" +#include +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +using namespace std; +using namespace trklet; + +VMProjectionsMemory::VMProjectionsMemory(string name, Settings const& settings, unsigned int iSector) + : MemoryBase(name, settings, iSector) { + initLayerDisk(7, layer_, disk_); +} + +void VMProjectionsMemory::addTracklet(Tracklet* tracklet, unsigned int allprojindex) { + std::pair tmp(tracklet, allprojindex); + //Check that order of TCID is correct + if (!tracklets_.empty()) { + assert(tracklets_[tracklets_.size() - 1].first->TCID() <= tracklet->TCID()); + } + tracklets_.push_back(tmp); +} + +void VMProjectionsMemory::writeVMPROJ(bool first) { + std::ostringstream oss; + oss << "../data/MemPrints/VMProjections/VMProjections_" << getName(); + //get rid of duplicates + auto const& tmp = oss.str(); + int len = tmp.size(); + if (tmp[len - 2] == 'n' && tmp[len - 1] > '1' && tmp[len - 1] <= '9') + return; + oss << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; + auto const& fname = oss.str(); + + if (first) { + bx_ = 0; + event_ = 1; + out_.open(fname.c_str()); + } else + out_.open(fname.c_str(), std::ofstream::app); + + out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; + + for (unsigned int j = 0; j < tracklets_.size(); j++) { + string vmproj = (layer_ > 0) ? tracklets_[j].first->vmstrlayer(layer_, tracklets_[j].second) + : tracklets_[j].first->vmstrdisk(disk_, tracklets_[j].second); + out_ << "0x"; + out_ << std::setfill('0') << std::setw(2); + out_ << hex << j << dec; + out_ << " " << vmproj << " " << trklet::hexFormat(vmproj) << endl; + } + out_.close(); + + bx_++; + event_++; + if (bx_ > 7) + bx_ = 0; +} diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouter.cc b/L1Trigger/TrackFindingTracklet/src/VMRouter.cc new file mode 100644 index 0000000000000..9b4170595c296 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/VMRouter.cc @@ -0,0 +1,332 @@ +#include "L1Trigger/TrackFindingTracklet/interface/VMRouter.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMStubTE.h" +#include "L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +using namespace std; +using namespace trklet; + +VMRouter::VMRouter(string name, Settings const& settings, Globals* global, unsigned int iSector) + : ProcessBase(name, settings, global, iSector), vmrtable_(settings) { + layerdisk_ = initLayerDisk(4); + + vmstubsMEPHI_.resize(settings_.nvmme(layerdisk_), nullptr); + + overlapbits_ = 7; + nextrabits_ = overlapbits_ - (settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmme(layerdisk_)); + + vmrtable_.init(layerdisk_); + + nbitszfinebintable_ = settings_.vmrlutzbits(layerdisk_); + nbitsrfinebintable_ = settings_.vmrlutrbits(layerdisk_); +} + +void VMRouter::addOutput(MemoryBase* memory, string output) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " + << output; + } + + if (output.substr(0, 10) == "allstubout") { + AllStubsMemory* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + allstubs_.push_back(tmp); + return; + } + + if (output.substr(0, 12) == "vmstuboutPHI") { + char seedtype = memory->getName().substr(11, 1)[0]; + unsigned int pos = 12; + int vmbin = memory->getName().substr(pos, 1)[0] - '0'; + pos++; + if (pos < memory->getName().size()) { + if (memory->getName().substr(pos, 1)[0] != 'n') { + vmbin = vmbin * 10 + memory->getName().substr(pos, 1)[0] - '0'; + pos++; + } + } + + int iseed = -1; + unsigned int inner = 1; + if (memory->getName().substr(3, 2) == "TE") { + VMStubsTEMemory* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + if (seedtype < 'I') { + if (layerdisk_ == 0 || layerdisk_ == 1) + iseed = 0; + if (layerdisk_ == 2 || layerdisk_ == 3) + iseed = 2; + if (layerdisk_ == 4 || layerdisk_ == 5) + iseed = 3; + if (layerdisk_ == 6 || layerdisk_ == 7) + iseed = 4; + if (layerdisk_ == 8 || layerdisk_ == 9) + iseed = 5; + if (layerdisk_ == 0 || layerdisk_ == 2 || layerdisk_ == 4 || layerdisk_ == 6 || layerdisk_ == 8) + inner = 0; + } else if (seedtype < 'M') { + if (layerdisk_ == 1 || layerdisk_ == 2) + iseed = 1; + if (layerdisk_ == 1) + inner = 0; + } else if (seedtype <= 'Z') { + if (layerdisk_ == 0 || layerdisk_ == 6) + iseed = 6; + if (layerdisk_ == 1 || layerdisk_ == 6) + iseed = 7; + if (layerdisk_ == 0 || layerdisk_ == 1) + inner = 0; + } else if (seedtype < 'o' && seedtype >= 'a') { + if (layerdisk_ == 1 || layerdisk_ == 2) + iseed = 10; + if (layerdisk_ == 1) + inner = 0; + } else if (seedtype > 'o' && seedtype <= 'z') { + if (layerdisk_ == 1) + iseed = 11; + if (layerdisk_ == 6) + iseed = 10; + inner = 2; + } else { + throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Invalid seeding!"; + } + assert(iseed != -1); + int seedindex = -1; + for (unsigned int k = 0; k < vmstubsTEPHI_.size(); k++) { + if (vmstubsTEPHI_[k].seednumber == (unsigned int)iseed) { + seedindex = k; + } + } + if (seedindex == -1) { + seedindex = vmstubsTEPHI_.size(); + vector avectmp; + vector > vectmp(settings_.nvmte(inner, iseed), avectmp); + VMStubsTEPHI atmp(iseed, inner, vectmp); + vmstubsTEPHI_.push_back(atmp); + } + vmstubsTEPHI_[seedindex].vmstubmem[(vmbin - 1) & (settings_.nvmte(inner, iseed) - 1)].push_back(tmp); + + } else if (memory->getName().substr(3, 2) == "ME") { + VMStubsMEMemory* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + vmstubsMEPHI_[(vmbin - 1) & (settings_.nvmme(layerdisk_) - 1)] = tmp; + } else { + throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " should never get here!"; + } + + return; + } + + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output; +} + +void VMRouter::addInput(MemoryBase* memory, string input) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " + << input; + } + if (input == "stubin") { + InputLinkMemory* tmp1 = dynamic_cast(memory); + assert(tmp1 != nullptr); + if (tmp1 != nullptr) { + stubinputs_.push_back(tmp1); + } + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input; +} + +void VMRouter::execute() { + unsigned int allStubCounter = 0; + + //Loop over the input stubs + for (auto& stubinput : stubinputs_) { + for (unsigned int i = 0; i < stubinput->nStubs(); i++) { + if (allStubCounter > settings_.maxStep("VMR")) + continue; + if (allStubCounter > 127) + continue; + Stub* stub = stubinput->getStub(i); + + //Note - below information is not part of the stub, but rather from which input memory we are reading + bool negdisk = (stub->disk().value() < 0); + + //use &127 to make sure we fit into the number of bits - + //though we should have protected against overflows above + FPGAWord allStubIndex(allStubCounter & 127, 7, true, __LINE__, __FILE__); + + //TODO - should not be needed - but need to migrate some other pieces of code before removing + stub->setAllStubIndex(allStubCounter); + //TODO - should not be needed - but need to migrate some other pieces of code before removing + stub->l1tstub()->setAllStubIndex(allStubCounter); + + allStubCounter++; + + //Fill allstubs memories - in HLS this is the same write to multiple memories + for (auto& allstub : allstubs_) { + allstub->addStub(stub); + } + + //Fill all the ME VM memories + + FPGAWord iphi = stub->phicorr(); + unsigned int ivm = + iphi.bits(iphi.nbits() - (settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmme(layerdisk_)), + settings_.nbitsvmme(layerdisk_)); + unsigned int extrabits = iphi.bits(iphi.nbits() - overlapbits_, nextrabits_); + + unsigned int ivmPlus = ivm; + + if (extrabits == ((1U << nextrabits_) - 1) && ivm != ((1U << settings_.nbitsvmme(layerdisk_)) - 1)) + ivmPlus++; + unsigned int ivmMinus = ivm; + if (extrabits == 0 && ivm != 0) + ivmMinus--; + + //Calculate the z and r position for the vmstub + + //Take the top nbitszfinebintable_ bits of the z coordinate + int indexz = (((1 << (stub->z().nbits() - 1)) + stub->z().value()) >> (stub->z().nbits() - nbitszfinebintable_)); + int indexr = -1; + if (layerdisk_ > (N_LAYER - 1)) { + if (negdisk) { + indexz = (1 << nbitszfinebintable_) - indexz; + } + indexr = stub->r().value(); + if (stub->isPSmodule()) { + indexr = stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_); + } + } else { + //Take the top nbitsfinebintable_ bits of the z coordinate. The & is to handle the negative z values. + indexr = (((1 << (stub->r().nbits() - 1)) + stub->r().value()) >> (stub->r().nbits() - nbitsrfinebintable_)); + } + + assert(indexz >= 0); + assert(indexr >= 0); + assert(indexz < (1 << nbitszfinebintable_)); + assert(indexr < (1 << nbitsrfinebintable_)); + + int melut = vmrtable_.lookup(indexz, indexr); + + assert(melut >= 0); + + int vmbin = melut >> 3; + if (negdisk) + vmbin += 8; + int rzfine = melut & 7; + + VMStubME vmstub( + stub, + stub->iphivmFineBins(iphi.nbits() - (settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmme(layerdisk_)), + settings_.nbitsvmme(layerdisk_)), + FPGAWord(rzfine, 3, true, __LINE__, __FILE__), + stub->bend(), + allStubIndex); + + assert(vmstubsMEPHI_[ivmPlus] != nullptr); + vmstubsMEPHI_[ivmPlus]->addStub(vmstub, vmbin); + + if (ivmMinus != ivmPlus) { + assert(vmstubsMEPHI_[ivmMinus] != nullptr); + vmstubsMEPHI_[ivmMinus]->addStub(vmstub, vmbin); + } + + //Fill the TE VM memories + + for (auto& ivmstubTEPHI : vmstubsTEPHI_) { + unsigned int iseed = ivmstubTEPHI.seednumber; + unsigned int inner = ivmstubTEPHI.stubposition; + if ((iseed == 4 || iseed == 5 || iseed == 6 || iseed == 7) && (!stub->isPSmodule())) + continue; + + unsigned int lutwidth = settings_.lutwidthtab(inner, iseed); + if (settings_.extended()) { + lutwidth = settings_.lutwidthtabextended(inner, iseed); + } + + int lutval = -999; + + if (inner > 0) { + if (layerdisk_ < N_LAYER) { + lutval = melut; + } else { + if (inner == 2 && iseed == 10) { + lutval = 0; + if (stub->r().value() < 10) { + lutval = 8 * (1 + (stub->r().value() >> 2)); + } else { + if (stub->r().value() < settings_.rmindiskl3overlapvm() / settings_.kr()) { + lutval = -1; + } + } + } else { + lutval = vmrtable_.lookupdisk(indexz, indexr); + } + } + if (lutval == -1) + continue; + } else { + if (iseed < 6 || iseed > 7) { + lutval = vmrtable_.lookupinner(indexz, indexr); + } else { + lutval = vmrtable_.lookupinneroverlap(indexz, indexr); + } + if (lutval == -1) + continue; + if (settings_.extended() && (iseed == 2 || iseed == 3 || iseed == 10 || iseed == 4)) { + int lutval2 = vmrtable_.lookupinnerThird(indexz, indexr); + if (lutval2 == -1) + continue; + lutval += (lutval2 << 10); + } + } + + assert(lutval >= 0); + + FPGAWord binlookup(lutval, lutwidth, true, __LINE__, __FILE__); + + if (binlookup.value() < 0) + continue; + + unsigned int ivmte = + iphi.bits(iphi.nbits() - (settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmte(inner, iseed)), + settings_.nbitsvmte(inner, iseed)); + + int bin = -1; + if (inner != 0) { + bin = binlookup.value() / 8; + unsigned int tmp = binlookup.value() & 7; //three bits in outer layers - this could be coded cleaner... + binlookup.set(tmp, 3, true, __LINE__, __FILE__); + } + + FPGAWord finephi = stub->iphivmFineBins(settings_.nphireg(inner, iseed), settings_.nfinephi(inner, iseed)); + + VMStubTE tmpstub(stub, finephi, stub->bend(), binlookup, allStubIndex); + + unsigned int nmem = ivmstubTEPHI.vmstubmem[ivmte].size(); + + assert(nmem > 0); + + for (unsigned int l = 0; l < nmem; l++) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " try adding stub to " + << ivmstubTEPHI.vmstubmem[ivmte][l]->getName() << " inner=" << inner + << " bin=" << bin; + } + if (inner == 0) { + ivmstubTEPHI.vmstubmem[ivmte][l]->addVMStub(tmpstub); + } else { + ivmstubTEPHI.vmstubmem[ivmte][l]->addVMStub(tmpstub, bin); + } + } + } + } + } +} diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouterPhiCorrTable.cc b/L1Trigger/TrackFindingTracklet/src/VMRouterPhiCorrTable.cc new file mode 100644 index 0000000000000..3ec4838e0adb0 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/VMRouterPhiCorrTable.cc @@ -0,0 +1,62 @@ +#include "L1Trigger/TrackFindingTracklet/interface/VMRouterPhiCorrTable.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" + +using namespace std; +using namespace trklet; + +VMRouterPhiCorrTable::VMRouterPhiCorrTable(Settings const& settings) : TETableBase(settings) { nbits_ = 14; } + +void VMRouterPhiCorrTable::init(int layer, int bendbits, int rbits) { + assert(bendbits == 3 || bendbits == 4); + + layer_ = layer; + bendbits_ = bendbits; + rbits_ = rbits; + + rbins_ = (1 << rbits); + rmin_ = settings_.rmean(layer - 1) - settings_.drmax(); + rmax_ = settings_.rmean(layer - 1) + settings_.drmax(); + dr_ = 2 * settings_.drmax() / rbins_; + + bendbins_ = (1 << bendbits); + + rmean_ = settings_.rmean(layer - 1); + + for (int ibend = 0; ibend < bendbins_; ibend++) { + for (int irbin = 0; irbin < rbins_; irbin++) { + int value = getphiCorrValue(ibend, irbin); + table_.push_back(value); + } + } + + if (settings_.writeTable()) { + writeVMTable("VMPhiCorrL" + std::to_string(layer_) + ".txt", false); + } +} + +int VMRouterPhiCorrTable::getphiCorrValue(int ibend, int irbin) const { + double bend = trklet::benddecode(ibend, layer_ <= (int)N_PSLAYER); + + //for the rbin - calculate the distance to the nominal layer radius + double Delta = (irbin + 0.5) * dr_ - settings_.drmax(); + + //calculate the phi correction - this is a somewhat approximate formula + double dphi = (Delta / 0.18) * (bend * settings_.stripPitch(false)) / rmean_; + + int idphi = 0; + + if (layer_ <= (int)N_PSLAYER) { + idphi = dphi / settings_.kphi(); + } else { + idphi = dphi / settings_.kphi1(); + } + + return idphi; +} + +int VMRouterPhiCorrTable::lookupPhiCorr(int ibend, int rbin) { + int index = ibend * rbins_ + rbin; + assert(index < (int)table_.size()); + return table_[index]; +} diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouterTable.cc b/L1Trigger/TrackFindingTracklet/src/VMRouterTable.cc new file mode 100644 index 0000000000000..15b46e7171514 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/VMRouterTable.cc @@ -0,0 +1,287 @@ +// VMRouterTable: Lookup table used by the VMRouter to route stubs and provide information about which VMStubs are needed by the TrackletEngine +#include "L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +#include + +using namespace std; +using namespace trklet; + +VMRouterTable::VMRouterTable(Settings const& settings) : settings_(settings) {} + +VMRouterTable::VMRouterTable(Settings const& settings, unsigned int layerdisk) : settings_(settings) { + init(layerdisk); +} + +void VMRouterTable::init(unsigned int layerdisk) { + zbits_ = settings_.vmrlutzbits(layerdisk); + rbits_ = settings_.vmrlutrbits(layerdisk); + + rbins_ = (1 << rbits_); + zbins_ = (1 << zbits_); + + if (layerdisk < N_LAYER) { + zmin_ = -settings_.zlength(); + zmax_ = settings_.zlength(); + rmin_ = settings_.rmean(layerdisk) - settings_.drmax(); + rmax_ = settings_.rmean(layerdisk) + settings_.drmax(); + } else { + rmin_ = 0; + rmax_ = settings_.rmaxdisk(); + zmin_ = settings_.zmean(layerdisk - N_LAYER) - settings_.dzmax(); + zmax_ = settings_.zmean(layerdisk - N_LAYER) + settings_.dzmax(); + } + + dr_ = (rmax_ - rmin_) / rbins_; + dz_ = (zmax_ - zmin_) / zbins_; + + int NBINS = settings_.NLONGVMBINS() * settings_.NLONGVMBINS(); + + for (int izbin = 0; izbin < zbins_; izbin++) { + for (int irbin = 0; irbin < rbins_; irbin++) { + double r = rmin_ + (irbin + 0.5) * dr_; + double z = zmin_ + (izbin + 0.5) * dz_; + + if (layerdisk > (N_LAYER - 1) && irbin < 10) //special case for the tabulated radii in 2S disks + r = (layerdisk <= 7) ? settings_.rDSSinner(irbin) : settings_.rDSSouter(irbin); + + int bin; + if (layerdisk < N_LAYER) { + double zproj = z * settings_.rmean(layerdisk) / r; + bin = NBINS * (zproj + settings_.zlength()) / (2 * settings_.zlength()); + } else { + double rproj = r * settings_.zmean(layerdisk - N_LAYER) / z; + bin = NBINS * (rproj - settings_.rmindiskvm()) / (settings_.rmaxdisk() - settings_.rmindiskvm()); + } + if (bin < 0) + bin = 0; + if (bin >= NBINS) + bin = NBINS - 1; + vmrtable_.push_back(bin); + + if (layerdisk >= N_LAYER) { + double rproj = r * settings_.zmean(layerdisk - N_LAYER) / z; + bin = 0.5 * NBINS * (rproj - settings_.rmindiskvm()) / (settings_.rmaxdiskvm() - settings_.rmindiskvm()); + if (bin < 0) + bin = 0; + if (bin >= NBINS / 2) + bin = NBINS / 2 - 1; + vmrtabletedisk_.push_back(bin); + } + + if (layerdisk == 0 || layerdisk == 2 || layerdisk == 4 || layerdisk == 6 || layerdisk == 8) { + vmrtableteinner_.push_back(getLookup(layerdisk + 1, z, r)); + } + + if (layerdisk == 1) { + vmrtableteinner_.push_back(getLookup(layerdisk + 1, z, r, 1)); + } + + if (layerdisk == 1) { //projection from L2 to D1 for L2L3D1 seeding + vmrtableteinnerThird_.push_back(getLookup(6, z, r, 10)); + } + + if (layerdisk == 4) { //projection from L5 to L4 for L5L6L4 seeding + vmrtableteinnerThird_.push_back(getLookup(3, z, r)); + } + + if (layerdisk == 2) { //projection from L3 to L5 for L3L4L2 seeding + vmrtableteinnerThird_.push_back(getLookup(1, z, r)); + } + + if (layerdisk == 6) { //projection from D1 to L2 for D1D2L2 seeding + vmrtableteinnerThird_.push_back(getLookup(1, z, r)); + } + + if (layerdisk == 0 || layerdisk == 1) { + vmrtableteinneroverlap_.push_back(getLookup(6, z, r, layerdisk + 6)); + } + } + } +} + +int VMRouterTable::getLookup(unsigned int layerdisk, double z, double r, int iseed) { + double z0cut = settings_.z0cut(); + + if (layerdisk < N_LAYER) { + if (iseed == 1 && std::abs(z) < 52.0) + return -1; + + double rmean = settings_.rmean(layerdisk); + + double rratio1 = rmean / (r + 0.5 * dr_); + double rratio2 = rmean / (r - 0.5 * dr_); + + double z1 = (z - 0.5 * dz_) * rratio1 + z0cut * (rratio1 - 1.0); + double z2 = (z + 0.5 * dz_) * rratio1 + z0cut * (rratio1 - 1.0); + double z3 = (z - 0.5 * dz_) * rratio2 + z0cut * (rratio2 - 1.0); + double z4 = (z + 0.5 * dz_) * rratio2 + z0cut * (rratio2 - 1.0); + double z5 = (z - 0.5 * dz_) * rratio1 - z0cut * (rratio1 - 1.0); + double z6 = (z + 0.5 * dz_) * rratio1 - z0cut * (rratio1 - 1.0); + double z7 = (z - 0.5 * dz_) * rratio2 - z0cut * (rratio2 - 1.0); + double z8 = (z + 0.5 * dz_) * rratio2 - z0cut * (rratio2 - 1.0); + + double zmin = std::min({z1, z2, z3, z4, z5, z6, z7, z8}); + double zmax = std::max({z1, z2, z3, z4, z5, z6, z7, z8}); + + int NBINS = settings_.NLONGVMBINS() * settings_.NLONGVMBINS(); + + int zbin1 = NBINS * (zmin + settings_.zlength()) / (2 * settings_.zlength()); + int zbin2 = NBINS * (zmax + settings_.zlength()) / (2 * settings_.zlength()); + + if (zbin1 >= NBINS) + return -1; + if (zbin2 < 0) + return -1; + + if (zbin2 >= NBINS) + zbin2 = NBINS - 1; + if (zbin1 < 0) + zbin1 = 0; + + // This is a 10 bit word: + // xxx|yyy|z|rrr + // xxx is the delta z window + // yyy is the z bin + // z is flag to look in next bin + // rrr first fine z bin + // NOTE : this encoding is not efficient z is one if xxx+rrr is greater than 8 + // and xxx is only 1,2, or 3 + // should also reject xxx=0 as this means projection is outside range + + int value = zbin1 / 8; + value *= 2; + if (zbin2 / 8 - zbin1 / 8 > 0) + value += 1; + value *= 8; + value += (zbin1 & 7); + assert(value / 8 < 15); + int deltaz = zbin2 - zbin1; + if (deltaz > 7) { + deltaz = 7; + } + assert(deltaz < 8); + value += (deltaz << 7); + + return value; + + } else { + if (std::abs(z) < 2.0 * z0cut) + return -1; + + double zmean = settings_.zmean(layerdisk - N_LAYER); + if (z < 0.0) + zmean = -zmean; + + double r1 = (r + 0.5 * dr_) * (zmean + z0cut) / (z + 0.5 * dz_ + z0cut); + double r2 = (r - 0.5 * dr_) * (zmean - z0cut) / (z + 0.5 * dz_ - z0cut); + double r3 = (r + 0.5 * dr_) * (zmean + z0cut) / (z - 0.5 * dz_ + z0cut); + double r4 = (r - 0.5 * dr_) * (zmean - z0cut) / (z - 0.5 * dz_ - z0cut); + double r5 = (r + 0.5 * dr_) * (zmean - z0cut) / (z + 0.5 * dz_ - z0cut); + double r6 = (r - 0.5 * dr_) * (zmean + z0cut) / (z + 0.5 * dz_ + z0cut); + double r7 = (r + 0.5 * dr_) * (zmean - z0cut) / (z - 0.5 * dz_ - z0cut); + double r8 = (r - 0.5 * dr_) * (zmean + z0cut) / (z - 0.5 * dz_ + z0cut); + + double rmin = std::min({r1, r2, r3, r4, r5, r6, r7, r8}); + double rmax = std::max({r1, r2, r3, r4, r5, r6, r7, r8}); + + int NBINS = settings_.NLONGVMBINS() * settings_.NLONGVMBINS() / 2; + + double rmindisk = settings_.rmindiskvm(); + double rmaxdisk = settings_.rmaxdiskvm(); + + if (iseed == 6) + rmaxdisk = settings_.rmaxdiskl1overlapvm(); + if (iseed == 7) + rmindisk = settings_.rmindiskl2overlapvm(); + if (iseed == 10) + rmaxdisk = settings_.rmaxdisk(); + + if (rmin > rmaxdisk) + return -1; + if (rmax > rmaxdisk) + rmax = rmaxdisk; + + if (rmax < rmindisk) + return -1; + if (rmin < rmindisk) + rmin = rmindisk; + + int rbin1 = NBINS * (rmin - settings_.rmindiskvm()) / (settings_.rmaxdiskvm() - settings_.rmindiskvm()); + int rbin2 = NBINS * (rmax - settings_.rmindiskvm()) / (settings_.rmaxdiskvm() - settings_.rmindiskvm()); + + if (iseed == 10) { + rbin1 = NBINS * (rmin - settings_.rmindiskvm()) / (settings_.rmaxdisk() - settings_.rmindiskvm()); + rbin2 = NBINS * (rmax - settings_.rmindiskvm()) / (settings_.rmaxdisk() - settings_.rmindiskvm()); + } + + if (rbin2 >= NBINS) + rbin2 = NBINS - 1; + if (rbin1 < 0) + rbin1 = 0; + + // This is a 9 bit word: + // xxx|yy|z|rrr + // xxx is the delta r window + // yy is the r bin yy is three bits for overlaps + // z is flag to look in next bin + // rrr fine r bin + // NOTE : this encoding is not efficient z is one if xxx+rrr is greater than 8 + // and xxx is only 1,2, or 3 + // should also reject xxx=0 as this means projection is outside range + + bool overlap = iseed == 6 || iseed == 7 || iseed == 10; + + int value = rbin1 / 8; + if (overlap) { + if (z < 0.0) + value += 4; + } + value *= 2; + if (rbin2 / 8 - rbin1 / 8 > 0) + value += 1; + value *= 8; + value += (rbin1 & 7); + assert(value / 8 < 15); + int deltar = rbin2 - rbin1; + if (deltar > 7) + deltar = 7; + if (overlap) { + value += (deltar << 7); + } else { + value += (deltar << 6); + } + + return value; + } +} + +int VMRouterTable::lookup(int zbin, int rbin) { + int index = zbin * rbins_ + rbin; + assert(index >= 0 && index < (int)vmrtable_.size()); + return vmrtable_[index]; +} + +int VMRouterTable::lookupdisk(int zbin, int rbin) { + int index = zbin * rbins_ + rbin; + assert(index >= 0 && index < (int)vmrtabletedisk_.size()); + return vmrtabletedisk_[index]; +} + +int VMRouterTable::lookupinner(int zbin, int rbin) { + int index = zbin * rbins_ + rbin; + assert(index >= 0 && index < (int)vmrtableteinner_.size()); + return vmrtableteinner_[index]; +} + +int VMRouterTable::lookupinneroverlap(int zbin, int rbin) { + int index = zbin * rbins_ + rbin; + assert(index >= 0 && index < (int)vmrtableteinneroverlap_.size()); + return vmrtableteinneroverlap_[index]; +} + +int VMRouterTable::lookupinnerThird(int zbin, int rbin) { + int index = zbin * rbins_ + rbin; + assert(index >= 0 && index < (int)vmrtableteinnerThird_.size()); + return vmrtableteinnerThird_[index]; +} diff --git a/L1Trigger/TrackFindingTracklet/src/VMStubME.cc b/L1Trigger/TrackFindingTracklet/src/VMStubME.cc new file mode 100644 index 0000000000000..d7e63bccc2002 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/VMStubME.cc @@ -0,0 +1,24 @@ +#include "L1Trigger/TrackFindingTracklet/interface/VMStubME.h" + +using namespace std; +using namespace trklet; + +VMStubME::VMStubME(const Stub* stub, FPGAWord finephi, FPGAWord finerz, FPGAWord bend, FPGAWord allstubindex) { + stub_ = stub; + finephi_ = finephi; + finerz_ = finerz; + bend_ = bend; + allStubIndex_ = allstubindex; +} + +std::string VMStubME::str() const { + string stub = allStubIndex_.str(); + stub += "|"; + stub += bend_.str(); + stub += "|"; + stub += finephi_.str(); + stub += "|"; + stub += finerz_.str(); + + return stub; +} diff --git a/L1Trigger/TrackFindingTracklet/src/VMStubTE.cc b/L1Trigger/TrackFindingTracklet/src/VMStubTE.cc new file mode 100644 index 0000000000000..a7eb85cb17408 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/VMStubTE.cc @@ -0,0 +1,24 @@ +#include "L1Trigger/TrackFindingTracklet/interface/VMStubTE.h" + +using namespace std; +using namespace trklet; + +VMStubTE::VMStubTE(const Stub* stub, FPGAWord finephi, FPGAWord bend, FPGAWord vmbits, FPGAWord allstubindex) { + stub_ = stub; + finephi_ = finephi; + bend_ = bend; + vmbits_ = vmbits; + allStubIndex_ = allstubindex; +} + +std::string VMStubTE::str() const { + string stub = allStubIndex_.str(); + stub += "|"; + stub += bend_.str(); + stub += "|"; + stub += finephi_.str(); + stub += "|"; + stub += vmbits_.str(); + + return stub; +} diff --git a/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc b/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc new file mode 100644 index 0000000000000..59418f445c5f5 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc @@ -0,0 +1,55 @@ +#include "L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include + +using namespace std; +using namespace trklet; + +VMStubsMEMemory::VMStubsMEMemory(string name, Settings const& settings, unsigned int iSector) + : MemoryBase(name, settings, iSector) { + unsigned int layerdisk = initLayerDisk(6); + if (layerdisk < N_LAYER) { + binnedstubs_.resize(settings_.NLONGVMBINS()); + } else { + //For disks we have NLONGVMBITS on each disk + binnedstubs_.resize(2 * settings_.NLONGVMBINS()); + } +} + +void VMStubsMEMemory::writeStubs(bool first) { + std::ostringstream oss; + oss << "../data/MemPrints/VMStubsME/VMStubs_" << getName(); + //get rid of duplicates + auto const& tmp = oss.str(); + int len = tmp.size(); + if (tmp[len - 2] == 'n' && tmp[len - 1] > '1' && tmp[len - 1] <= '9') + return; + oss << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; + auto const& fname = oss.str(); + + if (first) { + bx_ = 0; + event_ = 1; + out_.open(fname.c_str()); + } else + out_.open(fname.c_str(), std::ofstream::app); + + out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; + + for (unsigned int i = 0; i < binnedstubs_.size(); i++) { + for (unsigned int j = 0; j < binnedstubs_[i].size(); j++) { + string stub = binnedstubs_[i][j].stubindex().str(); + stub += "|" + binnedstubs_[i][j].bend().str(); + + FPGAWord finepos = binnedstubs_[i][j].finerz(); + stub += "|" + finepos.str(); + out_ << hex << i << " " << j << dec << " " << stub << " " << trklet::hexFormat(stub) << endl; + } + } + out_.close(); + + bx_++; + event_++; + if (bx_ > 7) + bx_ = 0; +} diff --git a/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc b/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc new file mode 100644 index 0000000000000..99e93be6e9c77 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc @@ -0,0 +1,267 @@ +#include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h" +#include +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +using namespace std; +using namespace trklet; + +VMStubsTEMemory::VMStubsTEMemory(string name, Settings const& settings, unsigned int iSector) + : MemoryBase(name, settings, iSector) { + //set the layer or disk that the memory is in + initLayerDisk(6, layer_, disk_); + + //Pointer to other VMStub memory for creating stub pairs + other_ = nullptr; + + //What type of seeding is this memory used for + initSpecialSeeding(11, overlap_, extra_, extended_); + + string subname = name.substr(12, 2); + phibin_ = subname[0] - '0'; + if (subname[1] != 'n') { + phibin_ = 10 * phibin_ + (subname[1] - '0'); + } + + //set the bins used in the bend tabele + unsigned int nbins = 8; + if (layer_ >= 4) + nbins = 16; + if (disk_ == 1 && extended_ && overlap_) + nbins = 16; + for (unsigned int i = 0; i < nbins; i++) { + vmbendtable_.push_back(true); + } + + isinner_ = (layer_ % 2 == 1 or disk_ % 2 == 1); + // special cases with overlap seeding + if (overlap_ and layer_ == 2) + isinner_ = true; + if (overlap_ and layer_ == 3) + isinner_ = false; + if (overlap_ and disk_ == 1) + isinner_ = false; + + if (extra_ and layer_ == 2) + isinner_ = true; + if (extra_ and layer_ == 3) + isinner_ = false; + // more special cases for triplets + if (!overlap_ and extended_ and layer_ == 2) + isinner_ = true; + if (!overlap_ and extended_ and layer_ == 3) + isinner_ = false; + if (overlap_ and extended_ and layer_ == 2) + isinner_ = false; + if (overlap_ and extended_ and disk_ == 1) + isinner_ = false; + + stubsbinnedvm_.resize(settings_.NLONGVMBINS()); +} + +bool VMStubsTEMemory::addVMStub(VMStubTE vmstub, int bin) { + //If the pt of the stub is consistent with the allowed pt of tracklets + //in that can be formed in this VM and the other VM used in the TE. + bool pass = passbend(vmstub.bend().value()); + + if (!pass) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << getName() << " Stub failed bend cut. bend = " + << benddecode(vmstub.bend().value(), vmstub.isPSmodule()); + return false; + } + + bool negdisk = vmstub.stub()->disk().value() < 0.0; + + if (overlap_) { + if (disk_ == 1) { + assert(bin < 4); + if (negdisk) + bin += 4; + stubsbinnedvm_[bin].push_back(vmstub); + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << getName() << " Stub in disk = " << disk_ << " in bin = " << bin; + } else if (layer_ == 2) { + stubsbinnedvm_[bin].push_back(vmstub); + } + } else { + if (vmstub.stub()->isBarrel()) { + if (!isinner_) { + stubsbinnedvm_[bin].push_back(vmstub); + } + + } else { + if (disk_ % 2 == 0) { + assert(bin < 4); + if (negdisk) + bin += 4; + stubsbinnedvm_[bin].push_back(vmstub); + } + } + } + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Adding stubs to " << getName(); + stubsvm_.push_back(vmstub); + return true; +} + +// TODO - should migrate away from using this method for any binned memory +bool VMStubsTEMemory::addVMStub(VMStubTE vmstub) { + FPGAWord binlookup = vmstub.vmbits(); + + assert(binlookup.value() >= 0); + int bin = (binlookup.value() / 8); + + //If the pt of the stub is consistent with the allowed pt of tracklets + //in that can be formed in this VM and the other VM used in the TE. + bool pass = passbend(vmstub.bend().value()); + + if (!pass) { + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << getName() << " Stub failed bend cut. bend = " + << benddecode(vmstub.bend().value(), vmstub.isPSmodule()); + return false; + } + + bool negdisk = vmstub.stub()->disk().value() < 0.0; + + if (!extended_) { + if (overlap_) { + if (disk_ == 1) { + assert(bin < 4); + if (negdisk) + bin += 4; + stubsbinnedvm_[bin].push_back(vmstub); + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " Stub with lookup = " << binlookup.value() + << " in disk = " << disk_ << " in bin = " << bin; + } + } + } else { + if (vmstub.stub()->isBarrel()) { + if (!isinner_) { + stubsbinnedvm_[bin].push_back(vmstub); + } + + } else { + if (disk_ % 2 == 0) { + assert(bin < 4); + if (negdisk) + bin += 4; + stubsbinnedvm_[bin].push_back(vmstub); + } + } + } + } else { //extended + if (!isinner_) { + if (layer_ > 0) { + stubsbinnedvm_[bin].push_back(vmstub); + } else { + if (overlap_) { + assert(disk_ == 1); // D1 from L2L3D1 + + //bin 0 is PS, 1 through 3 is 2S + if (vmstub.stub()->isPSmodule()) { + bin = 0; + } else { + bin = vmstub.stub()->r().value(); // 0 to 9 + bin = bin >> 2; // 0 to 2 + bin += 1; + } + } + assert(bin < 4); + if (negdisk) + bin += 4; + stubsbinnedvm_[bin].push_back(vmstub); + } + } + } + + if (settings_.debugTracklet()) + edm::LogVerbatim("Tracklet") << "Adding stubs to " << getName(); + stubsvm_.push_back(vmstub); + return true; +} + +void VMStubsTEMemory::clean() { + stubsvm_.clear(); + for (unsigned int i = 0; i < settings_.NLONGVMBINS(); i++) { + stubsbinnedvm_[i].clear(); + } +} + +void VMStubsTEMemory::writeStubs(bool first) { + openFile(first, "../data/MemPrints/VMStubsTE/VMStubs_"); + + if (isinner_) { // inner VM for TE purpose + for (unsigned int j = 0; j < stubsvm_.size(); j++) { + out_ << "0x"; + out_ << std::setfill('0') << std::setw(2); + out_ << hex << j << dec; + string stub = stubsvm_[j].str(); + out_ << " " << stub << " " << trklet::hexFormat(stub) << endl; + } + } else { // outer VM for TE purpose + for (unsigned int i = 0; i < settings_.NLONGVMBINS(); i++) { + for (unsigned int j = 0; j < stubsbinnedvm_[i].size(); j++) { + string stub = stubsbinnedvm_[i][j].str(); + out_ << hex << i << " " << j << dec << " " << stub << " " << trklet::hexFormat(stub) << endl; + } + } + } + + out_.close(); +} + +void VMStubsTEMemory::getPhiRange(double& phimin, double& phimax, unsigned int iSeed, unsigned int inner) { + int nvm = -1; + if (overlap_) { + if (layer_ > 0) { + nvm = settings_.nallstubs(layer_ - 1) * settings_.nvmte(inner, iSeed); + } + if (disk_ > 0) { + nvm = settings_.nallstubs(disk_ + N_DISK) * settings_.nvmte(inner, iSeed); + } + } else { + if (layer_ > 0) { + nvm = settings_.nallstubs(layer_ - 1) * settings_.nvmte(inner, iSeed); + if (extra_) { + nvm = settings_.nallstubs(layer_ - 1) * settings_.nvmte(inner, iSeed); + } + } + if (disk_ > 0) { + nvm = settings_.nallstubs(disk_ + N_DISK) * settings_.nvmte(inner, iSeed); + } + } + assert(nvm > 0); + assert(nvm <= 32); + double dphi = settings_.dphisectorHG() / nvm; + phimax = phibin() * dphi; + phimin = phimax - dphi; + + return; +} + +void VMStubsTEMemory::setbendtable(std::vector vmbendtable) { + assert(vmbendtable_.size() == vmbendtable.size()); + for (unsigned int i = 0; i < vmbendtable.size(); i++) { + vmbendtable_[i] = vmbendtable[i]; + } + + if (iSector_ == 0 && settings_.writeTable()) + writeVMBendTable(); +} + +void VMStubsTEMemory::writeVMBendTable() { + ofstream outvmbendcut; + outvmbendcut.open(getName() + "_vmbendcut.tab"); + outvmbendcut << "{" << endl; + unsigned int vmbendtableSize = vmbendtable_.size(); + assert(vmbendtableSize == 16 || vmbendtableSize == 8); + for (unsigned int i = 0; i < vmbendtableSize; i++) { + if (i != 0) + outvmbendcut << "," << endl; + outvmbendcut << vmbendtable_[i]; + } + outvmbendcut << endl << "};" << endl; + outvmbendcut.close(); +} diff --git a/L1Trigger/TrackFindingTracklet/src/imath.cc b/L1Trigger/TrackFindingTracklet/src/imath.cc new file mode 100644 index 0000000000000..a5498f6fa3959 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/imath.cc @@ -0,0 +1,439 @@ +// +// Integer representation of floating point arithmetic suitable for FPGA designs +// +// Author: Yuri Gershtein +// Date: March 2018 +// + +#include "L1Trigger/TrackFindingTracklet/interface/imath.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +#include + +using namespace trklet; + +std::string VarBase::itos(int i) { return std::to_string(i); } + +std::string VarBase::kstring() const { + char s[1024]; + std::string t = ""; + for (const auto &Kmap : Kmap_) { + sprintf(s, "^(%i)", Kmap.second); + std::string t0(s); + t = t + Kmap.first + t0; + } + return t; +} + +void VarBase::analyze() { + if (!readytoanalyze_) + return; + + double u = maxval_; + if (u < -minval_) + u = -minval_; + + int iu = log2(range() / u); + if (iu > 1) { + char slog[1024]; + sprintf(slog, + "analyzing %s: range %g is much larger then %g. suggest cutting by a factor of 2^%i", + name_.c_str(), + range(), + u, + iu); + edm::LogVerbatim("Tracklet") << slog; + } +#ifdef IMATH_ROOT + char slog[100]; + if (h_) { + double eff = h_->Integral() / h_->GetEntries(); + if (eff < 0.99) { + sprintf(slog, "analyzing %s: range is too small, contains %f", name_.c_str(), eff); + edm::LogVerbatim("Tracklet") << slog; + h_->Print(); + } + globals_->h_file_->cd(); + TCanvas *c = new TCanvas(); + c->cd(); + h_->Draw("colz"); + h_->Write(); + } else { + if (globals_->use_root) { + sprintf(slog, "analyzing %s: no histogram!\n", name_.c_str()); + edm::LogVerbatim("Tracklet") << slog; + } + } +#endif + + if (p1_) + p1_->analyze(); + if (p2_) + p2_->analyze(); + + readytoanalyze_ = false; +} + +std::string VarBase::dump() { + char s[1024]; + std::string u = kstring(); + sprintf( + s, + "Name = %s \t Op = %s \t nbits = %i \n ival = %li \t fval = %g \t K = %g Range = %f\n units = %s\n", + name_.c_str(), + op_.c_str(), + nbits_, + ival_, + fval_, + K_, + range(), + u.c_str()); + std::string t(s); + return t; +} + +void VarBase::dump_msg() { + char s[2048]; + std::string u = kstring(); + sprintf(s, + "Name = %s \t Op = %s \t nbits = %i \n ival = %li \t fval = %g \t K = %g Range = %f\n units = " + "%s\n step = %i, latency = %i\n", + name_.c_str(), + op_.c_str(), + nbits_, + ival_, + fval_, + K_, + range(), + u.c_str(), + step_, + latency_); + std::string t(s); + edm::LogVerbatim("Tracklet") << t; + if (p1_) + p1_->dump_msg(); + if (p2_) + p2_->dump_msg(); +} + +void VarAdjustK::adjust(double Knew, double epsilon, bool do_assert, int nbits) { + //WARNING!!! + //THIS METHID CAN BE USED ONLY FOR THE FINAL ANSWER + //THE CHANGE IN CONSTANT CAN NOT BE PROPAGATED UP THE CALCULATION TREE + + K_ = p1_->K(); + Kmap_ = p1_->Kmap(); + double r = Knew / K_; + + lr_ = (r > 1) ? log2(r) + epsilon : log2(r); + K_ = K_ * pow(2, lr_); + if (do_assert) + assert(std::abs(Knew / K_ - 1) < epsilon); + + if (nbits > 0) + nbits_ = nbits; + else + nbits_ = p1_->nbits() - lr_; + + Kmap_["2"] = Kmap_["2"] + lr_; +} + +void VarInv::initLUT(double offset) { + offset_ = offset; + double offsetI = lround(offset_ / p1_->K()); + for (int i = 0; i < Nelements_; ++i) { + int i1 = addr_to_ival(i); + LUT[i] = gen_inv(offsetI + i1); + } +} + +void VarBase::makeready() { + pipe_counter_ = 0; + pipe_delays_.clear(); + readytoprint_ = true; + readytoanalyze_ = true; + usedasinput_ = false; + if (p1_) + p1_->makeready(); + if (p2_) + p2_->makeready(); + if (p3_) + p3_->makeready(); +} + +bool VarBase::has_delay(int i) { + //dumb sequential search + for (int pipe_delay : pipe_delays_) + if (pipe_delay == i) + return true; + return false; +} + +std::string VarBase::pipe_delay(VarBase *v, int nbits, int delay) { + //have we been delayed by this much already? + if (v->has_delay(delay)) + return ""; + v->add_delay(delay); + std::string name = v->name(); + std::string name_delayed = name + "_delay" + itos(delay); + std::string out = "wire signed [" + itos(nbits - 1) + ":0] " + name_delayed + ";\n"; + out = out + pipe_delay_wire(v, name_delayed, nbits, delay); + return out; +} +std::string VarBase::pipe_delays(const int step) { + std::string out = ""; + if (p1_) + out += p1_->pipe_delays(step); + if (p2_) + out += p2_->pipe_delays(step); + if (p3_) + out += p3_->pipe_delays(step); + + int l = step - latency_ - step_; + return (out + pipe_delay(this, nbits(), l)); +} +std::string VarBase::pipe_delay_wire(VarBase *v, std::string name_delayed, int nbits, int delay) { + std::string name = v->name(); + std::string name_pipe = name + "_pipe" + itos(v->pipe_counter()); + v->pipe_increment(); + std::string out = "pipe_delay #(.STAGES(" + itos(delay) + "), .WIDTH(" + itos(nbits) + ")) " + name_pipe + + "(.clk(clk), .val_in(" + name + "), .val_out(" + name_delayed + "));\n"; + return out; +} + +void VarBase::inputs(std::vector *vd) { + if (op_ == "def" && !usedasinput_) { + usedasinput_ = true; + vd->push_back(this); + } else { + if (p1_) + p1_->inputs(vd); + if (p2_) + p2_->inputs(vd); + if (p3_) + p3_->inputs(vd); + } +} + +#ifdef IMATH_ROOT +TTree *VarBase::addToTree(imathGlobals *globals, VarBase *v, char *s) { + if (globals->h_file_ == 0) { + globals->h_file_ = new TFile("imath.root", "RECREATE"); + edm::LogVerbatim("Tracklet") << "recreating file imath.root"; + } + globals->h_file_->cd(); + TTree *tt = (TTree *)globals->h_file_->Get("tt"); + if (tt == 0) { + tt = new TTree("tt", ""); + edm::LogVerbatim("Tracklet") << "creating TTree tt"; + } + std::string si = v->name() + "_i"; + std::string sf = v->name() + "_f"; + std::string sv = v->name(); + if (s != 0) { + std::string prefix(s); + si = prefix + si; + sf = prefix + sf; + sv = prefix + sv; + } + if (!tt->GetBranchStatus(si.c_str())) { + tt->Branch(si.c_str(), (Long64_t *)&(v->ival_)); + tt->Branch(sf.c_str(), &(v->fval_)); + tt->Branch(sv.c_str(), &(v->val_)); + } + + if (v->p1_) + addToTree(globals, v->p1_, s); + if (v->p2_) + addToTree(globals, v->p2_, s); + if (v->p3_) + addToTree(globals, v->p3_, s); + + return tt; +} +TTree *VarBase::addToTree(imathGlobals *globals, double *v, char *s) { + if (globals->h_file_ == 0) { + globals->h_file_ = new TFile("imath.root", "RECREATE"); + edm::LogVerbatim("Tracklet") << "recreating file imath.root"; + } + globals->h_file_->cd(); + TTree *tt = (TTree *)globals->h_file_->Get("tt"); + if (tt == 0) { + tt = new TTree("tt", ""); + edm::LogVerbatim("Tracklet") << "creating TTree tt"; + } + tt->Branch(s, v); + return tt; +} +TTree *VarBase::addToTree(imathGlobals *globals, int *v, char *s) { + if (globals->h_file_ == 0) { + globals->h_file_ = new TFile("imath.root", "RECREATE"); + edm::LogVerbatim("Tracklet") << "recreating file imath.root"; + } + globals->h_file_->cd(); + TTree *tt = (TTree *)globals->h_file_->Get("tt"); + if (tt == 0) { + tt = new TTree("tt", ""); + edm::LogVerbatim("Tracklet") << "creating TTree tt"; + } + tt->Branch(s, v); + return tt; +} +void VarBase::fillTree(imathGlobals *globals) { + if (globals->h_file_ == 0) + return; + globals->h_file_->cd(); + TTree *tt = (TTree *)globals->h_file_->Get("tt"); + if (tt == 0) + return; + tt->Fill(); +} +void VarBase::writeTree(imathGlobals *globals) { + if (globals->h_file_ == 0) + return; + globals->h_file_->cd(); + TTree *tt = (TTree *)globals->h_file_->Get("tt"); + if (tt == 0) + return; + tt->Write(); +} + +#endif + +void VarCut::local_passes(std::map > &passes, + const std::map > *const previous_passes) const { + const int lower_cut = lower_cut_ / cut_var_->K(); + const int upper_cut = upper_cut_ / cut_var_->K(); + if (!previous_passes || (previous_passes && !previous_passes->count(cut_var_))) { + if (!passes.count(cut_var_)) + passes[cut_var_]; + passes.at(cut_var_).push_back(cut_var_->ival() > lower_cut && cut_var_->ival() < upper_cut); + } +} + +bool VarBase::local_passes() const { + bool passes = false; + for (const auto &cut : cuts_) { + const VarCut *const cast_cut = (VarCut *)cut; + const int lower_cut = cast_cut->lower_cut() / K_; + const int upper_cut = cast_cut->upper_cut() / K_; + passes = passes || (ival_ > lower_cut && ival_ < upper_cut); + if (globals_->printCutInfo_) { + edm::LogVerbatim("Tracklet") << " " << name_ << " " + << ((ival_ > lower_cut && ival_ < upper_cut) ? "PASSES" : "FAILS") + << " (required: " << lower_cut * K_ << " < " << ival_ * K_ << " < " << upper_cut * K_ + << ")"; + } + } + return passes; +} + +void VarBase::passes(std::map > &passes, + const std::map > *const previous_passes) const { + if (p1_) + p1_->passes(passes, previous_passes); + if (p2_) + p2_->passes(passes, previous_passes); + if (p3_) + p3_->passes(passes, previous_passes); + + for (const auto &cut : cuts_) { + const VarCut *const cast_cut = (VarCut *)cut; + const int lower_cut = cast_cut->lower_cut() / K_; + const int upper_cut = cast_cut->upper_cut() / K_; + if (!previous_passes || (previous_passes && !previous_passes->count(this))) { + if (!passes.count(this)) + passes[this]; + passes.at(this).push_back(ival_ > lower_cut && ival_ < upper_cut); + if (globals_->printCutInfo_) { + edm::LogVerbatim("Tracklet") << " " << name_ << " " + << ((ival_ > lower_cut && ival_ < upper_cut) ? "PASSES" : "FAILS") + << " (required: " << lower_cut * K_ << " < " << ival_ * K_ << " < " + << upper_cut * K_ << ")"; + } + } + } +} + +void VarBase::add_cut(VarCut *cut, const bool call_set_cut_var) { + cuts_.push_back(cut); + if (call_set_cut_var) + cut->set_cut_var(this, false); +} + +void VarCut::set_cut_var(VarBase *cut_var, const bool call_add_cut) { + cut_var_ = cut_var; + if (call_add_cut) + cut_var->add_cut(this, false); + if (parent_flag_) + parent_flag_->calculate_step(); +} + +void VarFlag::add_cut(VarBase *cut, const bool call_set_parent_flag) { + cuts_.push_back(cut); + if (cut->op() == "cut" && call_set_parent_flag) { + VarCut *const cast_cut = (VarCut *)cut; + cast_cut->set_parent_flag(this, false); + } + calculate_step(); +} + +void VarCut::set_parent_flag(VarFlag *parent_flag, const bool call_add_cut) { + parent_flag_ = parent_flag; + if (call_add_cut) + parent_flag->add_cut(this, false); +} + +VarBase *VarBase::cut_var() { + if (op_ == "cut") + return cut_var_; + else + return this; +} + +bool VarFlag::passes() { + if (globals_->printCutInfo_) { + edm::LogVerbatim("Tracklet") << "Checking if " << name_ << " passes..."; + } + + std::map > passes0, passes1; + for (const auto &cut : cuts_) { + if (cut->op() != "cut") + continue; + const VarCut *const cast_cut = (VarCut *)cut; + cast_cut->local_passes(passes0); + } + for (const auto &cut : cuts_) { + if (cut->op() != "cut") + cut->passes(passes1, &passes0); + else { + if (cut->cut_var()->p1()) + cut->cut_var()->p1()->passes(passes1, &passes0); + if (cut->cut_var()->p2()) + cut->cut_var()->p2()->passes(passes1, &passes0); + if (cut->cut_var()->p3()) + cut->cut_var()->p3()->passes(passes1, &passes0); + } + } + + bool passes = true; + for (const auto &cut_var : passes0) { + bool local_passes = false; + for (const auto &pass : cut_var.second) + local_passes = local_passes || pass; + passes = passes && local_passes; + } + for (const auto &cut_var : passes1) { + bool local_passes = false; + for (const auto &pass : cut_var.second) + local_passes = local_passes || pass; + passes = passes && local_passes; + } + + if (globals_->printCutInfo_) { + edm::LogVerbatim("Tracklet") << name_ << " " << (passes ? "PASSES" : "FAILS"); + } + + return passes; +} diff --git a/L1Trigger/TrackFindingTracklet/src/imath_HLS.cc b/L1Trigger/TrackFindingTracklet/src/imath_HLS.cc new file mode 100644 index 0000000000000..48cd864389a43 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/imath_HLS.cc @@ -0,0 +1,404 @@ +#include "L1Trigger/TrackFindingTracklet/interface/imath.h" + +using namespace trklet; + +void VarInv::writeLUT(std::ofstream& fs, HLS) const { + for (int i = 0; i < Nelements_ - 1; ++i) + fs << "0x" << std::hex << (LUT[i] & ((1 << nbits_) - 1)) << std::dec << ",\n"; + fs << "0x" << std::hex << (LUT[Nelements_ - 1] & ((1 << nbits_) - 1)) << std::dec << "\n"; +} + +void VarBase::print_truncation(std::string& t, const std::string& o1, const int ps, HLS) const { + if (ps > 0) { + t += "const ap_int<" + itos(nbits_ + ps) + "> " + name_ + "_tmp = " + o1 + ";\n"; + t += "const ap_int<" + itos(nbits_) + "> " + name_ + " = " + name_ + "_tmp >> " + itos(ps) + ";\n"; + } else + t += "const ap_int<" + itos(nbits_) + "> " + name_ + " = " + o1 + ";\n"; +} + +// +// print functions +// + +void VarCut::print(std::map >& cut_strings, + const int step, + HLS, + const std::map >* const previous_cut_strings) const { + assert(step > -1); + std::string name = cut_var_->name(); + + const int lower_cut = lower_cut_ / cut_var_->K(); + const int upper_cut = upper_cut_ / cut_var_->K(); + if (!previous_cut_strings || (previous_cut_strings && !previous_cut_strings->count(cut_var_))) { + if (!cut_strings.count(cut_var_)) + cut_strings[cut_var_]; + cut_strings.at(cut_var_).insert(name + " > " + itos(lower_cut) + " && " + name + " < " + itos(upper_cut)); + } +} + +void VarBase::print_cuts(std::map >& cut_strings, + const int step, + HLS, + const std::map >* const previous_cut_strings) const { + if (p1_) + p1_->print_cuts(cut_strings, step, hls, previous_cut_strings); + if (p2_) + p2_->print_cuts(cut_strings, step, hls, previous_cut_strings); + if (p3_) + p3_->print_cuts(cut_strings, step, hls, previous_cut_strings); + + std::string name = name_; + + for (const auto& cut : cuts_) { + const VarCut* const cast_cut = (VarCut*)cut; + const int lower_cut = cast_cut->lower_cut() / K_; + const int upper_cut = cast_cut->upper_cut() / K_; + if (!previous_cut_strings || (previous_cut_strings && !previous_cut_strings->count(this))) { + if (!cut_strings.count(this)) + cut_strings[this]; + cut_strings.at(this).insert(name + " > " + itos(lower_cut) + " && " + name + " < " + itos(upper_cut)); + } + } +} + +void VarAdjustK::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { + assert(p1_); + assert(l1 == 0); + assert(l2 == 0); + assert(l3 == 0); + + std::string shift = ""; + if (lr_ > 0) + shift = " >> " + itos(lr_); + else if (lr_ < 0) + shift = " << " + itos(-lr_); + + std::string n1 = p1_->name(); + + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n"; + fs << "const ap_int<" << nbits_ << "> " << name_ << " = " << n1 << shift << ";\n"; +} + +void VarAdjustKR::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { + assert(p1_); + assert(l1 == 0); + assert(l2 == 0); + assert(l3 == 0); + + std::string n1 = p1_->name(); + + std::string o1 = n1; + if (lr_ == 1) + o1 = "(" + o1 + "+1)>>1"; + if (lr_ > 1) + o1 = "( (" + o1 + ">>" + itos(lr_ - 1) + ")+1)>>1"; + if (lr_ < 0) + o1 = "ap_int<" + itos(nbits_) + ">(" + o1 + ")<<" + itos(-lr_); + + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n"; + fs << "const ap_int<" << nbits_ << "> " << name_ << " = " << o1 << ";\n"; +} + +void VarDef::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { + assert(l1 == 0); + assert(l2 == 0); + assert(l3 == 0); + + fs << "// units " << kstring() << "\t" << K_ << "\n"; + fs << "const ap_int<" << nbits_ << "> " << name_ << " = " << name_ << "_wire;\n"; +} + +void VarParam::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { + assert(l1 == 0); + assert(l2 == 0); + assert(l3 == 0); + + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n"; + fs << "static const ap_int<" << nbits_ << "> " << name_ << " = " << ival_ << ";\n"; +} + +void VarAdd::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { + assert(p1_); + assert(p2_); + assert(l1 == 0); + assert(l2 == 0); + assert(l3 == 0); + std::string o1 = p1_->name(); + if (shift1 > 0) { + o1 = "ap_int<" + itos(nbits_ + ps_) + ">(" + o1 + ")"; + o1 += "<<" + itos(shift1); + o1 = "(" + o1 + ")"; + } + + std::string o2 = p2_->name(); + if (shift2 > 0) { + o2 = "ap_int<" + itos(nbits_ + ps_) + ">(" + o2 + ")"; + o2 += "<<" + itos(shift2); + o2 = "(" + o2 + ")"; + } + + o1 = o1 + " + " + o2; + + std::string t = ""; + print_truncation(t, o1, ps_, hls); + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; +} + +void VarSubtract::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { + assert(p1_); + assert(p2_); + assert(l1 == 0); + assert(l2 == 0); + assert(l3 == 0); + std::string o1 = p1_->name(); + if (shift1 > 0) { + o1 = "ap_int<" + itos(nbits_ + ps_) + ">(" + o1 + ")"; + o1 += "<<" + itos(shift1); + o1 = "(" + o1 + ")"; + } + + std::string o2 = p2_->name(); + if (shift2 > 0) { + o2 = "ap_int<" + itos(nbits_ + ps_) + ">(" + o2 + ")"; + o2 += "<<" + itos(shift2); + o2 = "(" + o2 + ")"; + } + + o1 = o1 + " - " + o2; + + std::string t = ""; + print_truncation(t, o1, ps_, hls); + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; +} + +void VarNounits::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { + assert(p1_); + assert(l1 == 0); + assert(l2 == 0); + assert(l3 == 0); + std::string n1 = p1_->name(); + std::string o1 = "(" + n1 + " * " + itos(cI_) + ")"; + + std::string t = ""; + print_truncation(t, o1, ps_, hls); + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; +} + +void VarTimesC::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { + assert(p1_); + assert(l1 == 0); + assert(l2 == 0); + assert(l3 == 0); + std::string n1 = p1_->name(); + std::string o1 = "(" + n1 + " * " + itos(cI_) + ")"; + + std::string t = ""; + print_truncation(t, o1, ps_, hls); + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; +} + +void VarNeg::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { + assert(p1_); + assert(l1 == 0); + assert(l2 == 0); + assert(l3 == 0); + std::string n1 = p1_->name(); + + std::string t = "const ap_int<" + itos(nbits_) + "> " + name_ + " = -" + n1 + ";\n"; + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t << ";\n"; +} + +void VarShiftround::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { + assert(p1_); + assert(l1 == 0); + assert(l2 == 0); + assert(l3 == 0); + std::string n1 = p1_->name(); + std::string o1 = n1; + if (shift_ == 1) + o1 = "(" + o1 + "+1)>>1"; + if (shift_ > 1) + o1 = "( (" + o1 + ">>" + itos(shift_ - 1) + ")+1)>>1"; + if (shift_ < 0) + o1 = "ap_int<" + itos(nbits_) + ">(" + o1 + ")<<" + itos(-shift_); + + std::string t = "const ap_int<" + itos(nbits_) + "> " + name_ + " = " + o1 + ";\n"; + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t << ";\n"; +} + +void VarShift::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { + assert(p1_); + assert(l1 == 0); + assert(l2 == 0); + assert(l3 == 0); + std::string n1 = p1_->name(); + std::string o1 = n1; + if (shift_ > 0) + o1 = o1 + ">>" + itos(shift_); + if (shift_ < 0) + o1 = "ap_int<" + itos(nbits_) + ">(" + o1 + ")<<" + itos(-shift_); + + std::string t = "const ap_int<" + itos(nbits_) + "> " + name_ + " = " + o1 + ";\n"; + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t << ";\n"; +} + +void VarMult::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { + assert(l1 == 0); + assert(l2 == 0); + assert(l3 == 0); + assert(p1_); + std::string n1 = p1_->name(); + assert(p2_); + std::string n2 = p2_->name(); + std::string o1 = n1 + " * " + n2; + + std::string t = ""; + print_truncation(t, o1, ps_, hls); + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; +} + +void VarInv::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { + assert(p1_); + assert(l1 == 0); + assert(l2 == 0); + assert(l3 == 0); + + fs << "static const ap_int<" << itos(nbits_) << "> LUT_" << name_ << "[" << Nelements_ << "] = {\n"; + fs << "#include \"LUT_" << name_ << ".h\"\n"; + fs << "};\n"; + + std::string n1 = p1_->name(); + //first calculate address + std::string t1 = "addr_" + name_; + std::string t = "const ap_uint<" + itos(nbaddr_) + "> " + t1 + " = "; + if (shift_ > 0) + t = t + "(" + n1 + ">>" + itos(shift_) + ") & " + itos(mask_); + else + t = t + n1 + " & " + itos(mask_); + fs << t << "; // address for the LUT\n"; + + t = "const ap_int<" + itos(nbits_) + "> " + name_ + " = LUT_" + name_ + "[addr_" + name_ + "];\n"; + fs << t; +} + +void VarFlag::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { + assert(l1 == 0); + assert(l2 == 0); + assert(l3 == 0); + + fs << "const ap_int<1> " << name_ << " = ("; + std::map > cut_strings0, cut_strings1; + for (const auto& cut : cuts_) { + if (cut->op() != "cut") + continue; + const VarCut* const cast_cut = (VarCut*)cut; + cast_cut->print(cut_strings0, step_, hls); + } + for (const auto& cut : cuts_) { + if (cut->op() != "cut") + cut->print_cuts(cut_strings1, step_, hls, &cut_strings0); + else { + if (cut->cut_var()->p1()) + cut->cut_var()->p1()->print_cuts(cut_strings1, step_, hls, &cut_strings1); + if (cut->cut_var()->p2()) + cut->cut_var()->p2()->print_cuts(cut_strings1, step_, hls, &cut_strings1); + if (cut->cut_var()->p3()) + cut->cut_var()->p3()->print_cuts(cut_strings1, step_, hls, &cut_strings1); + } + } + + std::string separator = ""; + for (const auto& cut_var : cut_strings0) { + separator += "(("; + for (const auto& cut_string : cut_var.second) { + fs << separator << cut_string; + separator = ") || ("; + } + separator = ")) && "; + } + for (const auto& cut_var : cut_strings1) { + separator += "(("; + for (const auto& cut_string : cut_var.second) { + fs << separator << cut_string; + separator = ") || ("; + } + separator = ")) && "; + } + + fs << ")));"; +} + +void VarBase::print_step(int step, std::ofstream& fs, HLS) { + if (!readytoprint_) + return; + if (step > step_) + return; + if (p1_) + p1_->print_step(step, fs, hls); + if (p2_) + p2_->print_step(step, fs, hls); + if (p3_) + p3_->print_step(step, fs, hls); + if (step == step_) { + print(fs, hls, 0, 0, 0); + readytoprint_ = false; + } +} + +void VarBase::print_all(std::ofstream& fs, HLS) { + for (int i = 0; i <= step_; ++i) { + fs << "//\n// STEP " << i << "\n\n"; + print_step(i, fs, hls); + } +} + +void VarBase::design_print(std::vector v, std::ofstream& fs, HLS) { + //header of the module + + //inputs + std::vector vd; + vd.clear(); + int imax = v.size(); + for (int i = 0; i < imax; ++i) + (v[i])->inputs(&vd); + + //print header + fs << "#include \"ap_int.h\"\n\n"; + fs << "void XXX (\n"; + + imax = vd.size(); + for (int i = 0; i < imax; ++i) + fs << " const ap_int<" << (vd[i])->nbits() << "> " << (vd[i])->name() << "_wire,\n"; + fs << "\n"; + + imax = v.size() - 1; + for (int i = 0; i < imax; ++i) + fs << " ap_int<" << (v[i])->nbits() << "> * const " << (v[i])->name() << "_wire,\n"; + if (imax >= 0) + fs << " ap_int<" << (v[imax])->nbits() << "> * const " << (v[imax])->name() << "_wire\n"; + fs << ")\n{\n"; + fs << "#pragma HLS pipeline II=1\n"; + fs << "#pragma HLS latency max=25\n"; + + //body of the module + imax = v.size(); + for (int i = 0; i < imax; ++i) { + fs << "\n//\n"; + fs << "// calculating " << (v[i])->name() << "\n"; + fs << "//\n"; + (v[i])->print_all(fs, hls); + } + fs << "\n"; + + //trailer + fs << "\n"; + fs << "\n//\n"; + fs << "// wiring the outputs \n"; + fs << "//\n"; + for (int i = 0; i < imax; ++i) { + std::string n = v[i]->name() + "_wire"; + fs << "*" << n << " = " << (v[i])->name() << ";\n"; + } + + fs << "}\n"; +} diff --git a/L1Trigger/TrackFindingTracklet/src/imath_Verilog.cc b/L1Trigger/TrackFindingTracklet/src/imath_Verilog.cc new file mode 100644 index 0000000000000..e2e4d77463d4e --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/imath_Verilog.cc @@ -0,0 +1,534 @@ +#include "L1Trigger/TrackFindingTracklet/interface/imath.h" + +using namespace trklet; + +void VarInv::writeLUT(std::ofstream& fs, Verilog) const { + for (int i = 0; i < Nelements_; ++i) + fs << std::hex << (LUT[i] & ((1 << nbits_) - 1)) << std::dec << "\n"; +} + +void VarBase::print_truncation(std::string& t, const std::string& o1, const int ps, Verilog) const { + if (ps > 0) { + t += "wire signed [" + itos(nbits_ - 1) + ":0]" + name_ + ";\n"; + t += "reg signed [" + itos(nbits_ + ps - 1) + ":0]" + name_ + "_tmp;\n"; + t += "always @(posedge clk) " + name_ + "_tmp <= " + o1 + ";\n"; + t += "assign " + name_ + " = " + name_ + "_tmp[" + itos(nbits_ + ps - 1) + ":" + itos(ps) + "];\n"; + } else { + t += "reg signed [" + itos(nbits_ - 1) + ":0]" + name_ + ";\n"; + t += "always @(posedge clk) " + name_ + " <= " + o1 + ";\n"; + } +} + +// +// print functions +// + +void VarCut::print(std::map >& cut_strings, + const int step, + Verilog, + const std::map >* const previous_cut_strings) const { + int l = step - cut_var_->latency() - cut_var_->step(); + std::string name = cut_var_->name(); + if (l > 0) + name += "_delay" + itos(l); + + const int lower_cut = lower_cut_ / cut_var_->K(); + const int upper_cut = upper_cut_ / cut_var_->K(); + if (!previous_cut_strings || (previous_cut_strings && !previous_cut_strings->count(cut_var_))) { + if (!cut_strings.count(cut_var_)) + cut_strings[cut_var_]; + cut_strings.at(cut_var_).insert(name + " > " + itos(lower_cut) + " && " + name + " < " + itos(upper_cut)); + } +} + +void VarBase::print_cuts(std::map >& cut_strings, + const int step, + Verilog, + const std::map >* const previous_cut_strings) const { + if (p1_) + p1_->print_cuts(cut_strings, step, verilog, previous_cut_strings); + if (p2_) + p2_->print_cuts(cut_strings, step, verilog, previous_cut_strings); + if (p3_) + p3_->print_cuts(cut_strings, step, verilog, previous_cut_strings); + + int l = step - latency_ - step_; + std::string name = name_; + if (l > 0) + name += "_delay" + itos(l); + + for (const auto& cut : cuts_) { + const VarCut* const cast_cut = (VarCut*)cut; + const int lower_cut = cast_cut->lower_cut() / K_; + const int upper_cut = cast_cut->upper_cut() / K_; + if (!previous_cut_strings || (previous_cut_strings && !previous_cut_strings->count(this))) { + if (!cut_strings.count(this)) + cut_strings[this]; + cut_strings.at(this).insert(name + " > " + itos(lower_cut) + " && " + name + " < " + itos(upper_cut)); + } + } +} + +void VarAdjustK::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { + assert(p1_); + assert(l2 == 0); + assert(l3 == 0); + + std::string shift = ""; + if (lr_ > 0) + shift = " >>> " + itos(lr_); + else if (lr_ < 0) + shift = " << " + itos(-lr_); + + std::string n1 = p1_->name(); + if (l1 > 0) + n1 = n1 + "_delay" + itos(l1); + + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n"; + std::string t = "wire signed [" + itos(nbits_ - 1) + ":0]" + name_ + ";\n"; + t += "assign " + name_ + " = " + n1 + shift; + fs << t << "; \n"; +} + +void VarAdjustKR::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { + assert(p1_); + assert(l2 == 0); + assert(l3 == 0); + + std::string n1 = p1_->name(); + if (l1 > 0) + n1 = n1 + "_delay" + itos(l1); + + std::string o1 = n1; + if (lr_ == 1) + o1 = "(" + o1 + "+1)>>>1"; + if (lr_ > 1) + o1 = "( (" + o1 + ">>>" + itos(lr_ - 1) + ")+1)>>>1"; + if (lr_ < 0) + o1 = o1 + "<<" + itos(-lr_); + + std::string t = "reg signed [" + itos(nbits_ - 1) + ":0]" + name_ + ";\n"; + t += "always @(posedge clk) " + name_ + " <= " + o1; + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t << ";\n"; +} + +void VarDef::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { + assert(l1 == 0); + assert(l2 == 0); + assert(l3 == 0); + + std::string t = "reg signed [" + itos(nbits_ - 1) + ":0]" + name_ + ";\n"; + t = t + "always @(posedge clk) " + name_ + " <= " + name_ + "_wire;\n"; + fs << "// units " << kstring() << "\t" << K_ << "\n" << t; +} + +void VarParam::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { + assert(l1 == 0); + assert(l2 == 0); + assert(l3 == 0); + std::string t = "parameter " + name_ + " = "; + if (ival_ < 0) + t = t + "- " + itos(nbits_) + "\'sd" + itos(-ival_); + else + t = t + itos(nbits_) + "\'sd" + itos(ival_); + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t << ";\n"; +} + +void VarAdd::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { + assert(p1_); + assert(p2_); + assert(l3 == 0); + std::string o1 = p1_->name(); + if (l1 > 0) + o1 += "_delay" + itos(l1); + if (shift1 > 0) { + o1 += "<<" + itos(shift1); + o1 = "(" + o1 + ")"; + } + + std::string o2 = p2_->name(); + if (l2 > 0) + o2 += "_delay" + itos(l2); + if (shift2 > 0) { + o2 += "<<" + itos(shift2); + o2 = "(" + o2 + ")"; + } + + o1 = o1 + " + " + o2; + + std::string t = ""; + print_truncation(t, o1, ps_, verilog); + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; +} + +void VarSubtract::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { + assert(p1_); + assert(p2_); + assert(l3 == 0); + std::string o1 = p1_->name(); + if (l1 > 0) + o1 += "_delay" + itos(l1); + if (shift1 > 0) { + o1 += "<<" + itos(shift1); + o1 = "(" + o1 + ")"; + } + + std::string o2 = p2_->name(); + if (l2 > 0) + o2 += "_delay" + itos(l2); + if (shift2 > 0) { + o2 += "<<" + itos(shift2); + o2 = "(" + o2 + ")"; + } + + o1 = o1 + " - " + o2; + + std::string t = ""; + print_truncation(t, o1, ps_, verilog); + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; +} + +void VarNounits::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { + assert(p1_); + assert(l2 == 0); + assert(l3 == 0); + std::string n1 = p1_->name(); + if (l1 > 0) + n1 = n1 + "_delay" + itos(l1); + std::string o1 = "(" + n1 + " * " + itos(cI_) + ")"; + + std::string t = ""; + print_truncation(t, o1, ps_, verilog); + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; +} + +void VarTimesC::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { + assert(p1_); + assert(l2 == 0); + assert(l3 == 0); + std::string n1 = p1_->name(); + if (l1 > 0) + n1 = n1 + "_delay" + itos(l1); + std::string o1 = "(" + n1 + " * " + itos(cI_) + ")"; + + std::string t = ""; + print_truncation(t, o1, ps_, verilog); + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; +} + +void VarNeg::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { + assert(p1_); + assert(l2 == 0); + assert(l3 == 0); + std::string n1 = p1_->name(); + if (l1 > 0) + n1 = n1 + "_delay" + itos(l1); + + std::string t = "reg signed [" + itos(nbits_ - 1) + ":0]" + name_ + ";\n"; + t += "always @(posedge clk) " + name_ + " <= - " + n1; + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t << ";\n"; +} + +void VarShiftround::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { + assert(p1_); + assert(l2 == 0); + assert(l3 == 0); + std::string n1 = p1_->name(); + if (l1 > 0) + n1 = n1 + "_delay" + itos(l1); + std::string o1 = n1; + if (shift_ == 1) + o1 = "(" + o1 + "+1)>>>1"; + if (shift_ > 1) + o1 = "( (" + o1 + ">>>" + itos(shift_ - 1) + ")+1)>>>1"; + if (shift_ < 0) + o1 = o1 + "<<" + itos(-shift_); + + std::string t = "reg signed [" + itos(nbits_ - 1) + ":0]" + name_ + ";\n"; + t += "always @(posedge clk) " + name_ + " <= " + o1; + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t << ";\n"; +} + +void VarShift::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { + assert(p1_); + assert(l2 == 0); + assert(l3 == 0); + std::string n1 = p1_->name(); + if (l1 > 0) + n1 = n1 + "_delay" + itos(l1); + std::string o1 = n1; + if (shift_ > 0) + o1 = o1 + ">>>" + itos(shift_); + if (shift_ < 0) + o1 = o1 + "<<" + itos(-shift_); + + std::string t = "wire signed [" + itos(nbits_ - 1) + ":0]" + name_ + ";\n"; + t += "assign " + name_ + " = " + o1; + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t << ";\n"; +} + +void VarMult::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { + assert(l3 == 0); + assert(p1_); + std::string n1 = p1_->name(); + if (l1 > 0) + n1 = n1 + "_delay" + itos(l1); + assert(p2_); + std::string n2 = p2_->name(); + if (l2 > 0) + n2 = n2 + "_delay" + itos(l2); + std::string o1 = n1 + " * " + n2; + + std::string t = ""; + print_truncation(t, o1, ps_, verilog); + fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; +} + +void VarInv::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { + assert(p1_); + assert(l2 == 0); + assert(l3 == 0); + std::string n1 = p1_->name(); + if (l1 > 0) + n1 = n1 + "_delay" + itos(l1); + //first calculate address + std::string t1 = "addr_" + name_; + std::string t = "wire [" + itos(nbaddr_ - 1) + ":0] " + t1 + ";\n"; + t = t + "assign " + t1 + " = "; + if (shift_ > 0) + t = t + "(" + n1 + ">>>" + itos(shift_) + ") & " + itos(mask_); + else + t = t + n1 + " & " + itos(mask_); + fs << t << "; // address for the LUT\n"; + + t = "wire signed [" + itos(nbits_ - 1) + ":0] " + name_ + ";\n"; + fs << t; + + std::string t2 = "LUT_" + name_; + + fs << "Memory #( \n"; + fs << " .RAM_WIDTH(" << nbits_ << "), // Specify RAM data width \n"; + fs << " .RAM_DEPTH(" << Nelements_ << "), // Specify RAM depth (number of entries) \n"; + fs << " .RAM_PERFORMANCE(\"HIGH_PERFORMANCE\"), // \"HIGH_PERFORMANCE\" = 2 clks latency \n"; + fs << " .INIT_FILE() \n"; + fs << " ) " << t2 << " ( \n"; + fs << " .addra(" << itos(nbaddr_) << "\'b0), // Write address bus, width determined from RAM_DEPTH \n"; + fs << " .addrb(" << t1 << " ), // Read address bus, width determined from RAM_DEPTH \n"; + fs << " .dina(" << itos(nbits_) << "\'b0), // RAM input data, width determined from RAM_WIDTH \n"; + fs << " .clka(clk), // Write clock \n"; + fs << " .clkb(clk), // Read clock \n"; + fs << " .wea(1\'b0), // Write enable \n"; + fs << " .enb(1\'b1), // Read Enable, for additional power savings, disable when not in use \n"; + fs << " .rstb(reset), // Output reset (does not affect memory contents) \n"; + fs << " .regceb(1\'b1), // Output register enable \n"; + fs << " .doutb(" << name_ << ") // RAM output data, \n"; + fs << " ); \n"; +} + +void VarDSPPostadd::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { + assert(p1_); + assert(p2_); + assert(p3_); + std::string n1 = p1_->name(); + if (l1 > 0) + n1 = n1 + "_delay" + itos(l1); + std::string n2 = p2_->name(); + if (l2 > 0) + n2 = n2 + "_delay" + itos(l2); + std::string n3 = p3_->name(); + if (l3 > 0) + n3 = n3 + "_delay" + itos(l3); + + if (shift3_ > 0) + n3 = n3 + "<<" + itos(shift3_); + if (shift3_ < 0) + n3 = n3 + ">>>" + itos(-shift3_); + + std::string n4 = ""; + if (ps_ > 0) + n4 = ">>>" + itos(ps_); + + fs << name_ + " = DSP_postadd(" + n1 + ", " + n2 + ", " + n3 + ")" + n4 + ";"; +} + +void VarFlag::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { + assert(l1 == 0); + assert(l2 == 0); + assert(l3 == 0); + + fs << "wire " << name_ << ";" << std::endl; + fs << "assign " << name_ << " = ("; + std::map > cut_strings0, cut_strings1; + for (const auto& cut : cuts_) { + if (cut->op() != "cut") + continue; + const VarCut* const cast_cut = (VarCut*)cut; + cast_cut->print(cut_strings0, step_, verilog); + } + for (const auto& cut : cuts_) { + if (cut->op() != "cut") + cut->print_cuts(cut_strings1, step_, verilog, &cut_strings0); + else { + if (cut->cut_var()->p1()) + cut->cut_var()->p1()->print_cuts(cut_strings1, step_, verilog, &cut_strings1); + if (cut->cut_var()->p2()) + cut->cut_var()->p2()->print_cuts(cut_strings1, step_, verilog, &cut_strings1); + if (cut->cut_var()->p3()) + cut->cut_var()->p3()->print_cuts(cut_strings1, step_, verilog, &cut_strings1); + } + } + + std::string separator = ""; + for (const auto& cut_var : cut_strings0) { + separator += "(("; + for (const auto& cut_string : cut_var.second) { + fs << separator << cut_string; + separator = ") || ("; + } + separator = ")) && "; + } + for (const auto& cut_var : cut_strings1) { + separator += "(("; + for (const auto& cut_string : cut_var.second) { + fs << separator << cut_string; + separator = ") || ("; + } + separator = ")) && "; + } + + fs << ")));"; +} + +void VarBase::print_step(int step, std::ofstream& fs, Verilog) { + if (!readytoprint_) + return; + if (step > step_) + return; + int l1 = 0; + int l2 = 0; + int l3 = 0; + if (p1_) { + p1_->print_step(step, fs, verilog); + l1 = step_ - p1_->latency() - p1_->step(); + } + if (p2_) { + p2_->print_step(step, fs, verilog); + l2 = step_ - p2_->latency() - p2_->step(); + } + if (p3_) { + p3_->print_step(step, fs, verilog); + l3 = step_ - p3_->latency() - p3_->step(); + } + if (step == step_) { + if (l1 < 0 || l2 < 0 || l3 < 0 || (l1 > 0 && l2 > 0 && l3 > 0)) { + char slog[100]; + sprintf(slog, "%s::print_step(%i): something wrong with latencies! %i %i %i\n", name_.c_str(), step, l1, l2, l3); + edm::LogVerbatim("Tracklet") << slog; + dump_msg(); + assert(0); + } + if (l1 > 0) { + if (p1_->op() != "const") + fs << pipe_delay(p1_, p1_->nbits(), l1); + else + l1 = 0; + } + if (l2 > 0) { + if (p2_->op() != "const") + fs << pipe_delay(p2_, p2_->nbits(), l2); + else + l2 = 0; + } + if (l3 > 0) { + if (p3_->op() != "const") + fs << pipe_delay(p3_, p3_->nbits(), l3); + else + l3 = 0; + } + + if (op_ == "flag") { + for (const auto& cut : cuts_) + fs << cut->cut_var()->pipe_delays(step_); + } + + print(fs, verilog, l1, l2, l3); + readytoprint_ = false; + } +} + +void VarBase::print_all(std::ofstream& fs, Verilog) { + for (int i = 0; i <= step_; ++i) { + fs << "//\n// STEP " << i << "\n\n"; + print_step(i, fs, verilog); + } +} + +void VarBase::design_print(std::vector v, std::ofstream& fs, Verilog) { + //step at which all the outputs should be valid + int maxstep = 0; + + //header of the module + + //inputs + std::vector vd; + vd.clear(); + int imax = v.size(); + for (int i = 0; i < imax; ++i) { + (v[i])->inputs(&vd); + int step = v[i]->step() + v[i]->latency(); + if (step > maxstep) + maxstep = step; + } + + //print header + fs << "module \n"; + fs << "(\n"; + fs << " input clk,\n"; + fs << " input reset,\n\n"; + + imax = vd.size(); + for (int i = 0; i < imax; ++i) + fs << " input [" << (vd[i])->nbits() - 1 << ":0] " << (vd[i])->name() << "_wire,\n"; + fs << "\n"; + + imax = v.size() - 1; + for (int i = 0; i < imax; ++i) + if (v[i]->nbits() > 1) + fs << " output [" << (v[i])->nbits() - 1 << ":0] " << (v[i])->name() << "_wire,\n"; + else + fs << " output " << (v[i])->name() << "_wire,\n"; + if (imax >= 0) { + if (v[imax]->nbits() > 1) + fs << " output [" << (v[imax])->nbits() - 1 << ":0] " << (v[imax])->name() << "_wire\n"; + else + fs << " output " << (v[imax])->name() << "_wire\n"; + } + fs << ");\n\n"; + + //body of the module + imax = v.size(); + for (int i = 0; i < imax; ++i) { + fs << "\n//\n"; + fs << "// calculating " << (v[i])->name() << "\n"; + fs << "//\n"; + (v[i])->print_all(fs, verilog); + } + fs << "\n"; + + //trailer + fs << "\n"; + fs << "\n//\n"; + fs << "// wiring the outputs \n"; + fs << "// latency = " << maxstep << "\n"; + fs << "//\n"; + for (int i = 0; i < imax; ++i) { + std::string n = v[i]->name() + "_wire"; + int delay = maxstep - v[i]->step() - v[i]->latency(); + if (delay == 0) + fs << "assign " << n << " = " << (v[i])->name() << ";\n"; + else + fs << pipe_delay_wire(v[i], n, v[i]->nbits(), delay); + } + + fs << "endmodule\n"; +} diff --git a/L1Trigger/TrackFindingTracklet/src/imath_calculate.cc b/L1Trigger/TrackFindingTracklet/src/imath_calculate.cc new file mode 100644 index 0000000000000..0aa2f7b77c045 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/imath_calculate.cc @@ -0,0 +1,192 @@ +#include "L1Trigger/TrackFindingTracklet/interface/imath.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +using namespace trklet; + +bool VarBase::calculate(int debug_level) { + bool ok1 = true; + bool ok2 = true; + bool ok3 = true; + + if (p1_) + ok1 = p1_->calculate(debug_level); + if (p2_) + ok2 = p2_->calculate(debug_level); + if (p3_) + ok3 = p3_->calculate(debug_level); + + long int ival_prev = ival_; + local_calculate(); + + bool all_ok = ok1 && ok2 && ok3 && debug_level; + + if (fval_ > maxval_) + maxval_ = fval_; + if (fval_ < minval_) + minval_ = fval_; +#ifdef IMATH_ROOT + if (globals_->use_root) { + if (h_ == 0) { + globals_->h_file_->cd(); + std::string hname = "h_" + name_; + h_ = (TH2F *)globals_->h_file_->Get(hname.c_str()); + if (h_ == 0) { + h_precision_ = 0.5 * h_nbins_ * K_; + std::string st = name_ + ";fval;fval-ival*K"; + h_ = new TH2F(hname.c_str(), name_.c_str(), h_nbins_, -range(), range(), h_nbins_, -h_precision_, h_precision_); + if (debug_level == 3) + edm::LogVerbatim("Tracklet") << " booking histogram " << hname; + } + } + if (ival_ != ival_prev || op_ == "def" || op_ == "const") + h_->Fill(fval_, K_ * ival_ - fval_); + } +#endif + + bool todump = false; + int nmax = sizeof(long int) * 8; + int ns = nmax - nbits_; + long int itest = ival_; + itest = itest << ns; + itest = itest >> ns; + if (itest != ival_) { + if (debug_level == 3 || (ival_ != ival_prev && all_ok)) { + edm::LogVerbatim("Tracklet") << "imath: truncated value mismatch!! " << ival_ << " != " << itest; + todump = true; + } + all_ok = false; + } + + val_ = ival_ * K_; + float ftest = val_; + float tolerance = 0.1 * std::abs(fval_); + if (tolerance < 2 * K_) + tolerance = 2 * K_; + if (std::abs(ftest - fval_) > tolerance) { + if (debug_level == 3 || (ival_ != ival_prev && (all_ok && (op_ != "inv" || debug_level >= 2)))) { + edm::LogVerbatim("Tracklet") << "imath: **GROSS** value mismatch!! " << fval_ << " != " << ftest; + if (op_ == "inv") + edm::LogVerbatim("Tracklet") << p1_->dump() << "\n-----------------------------------"; + todump = true; + } + all_ok = false; + } + + if (todump) + edm::LogVerbatim("Tracklet") << dump(); + + return all_ok; +} + +void VarFlag::calculate_step() { + int max_step = 0; + for (const auto &cut : cuts_) { + if (!cut->cut_var()) + continue; + if (cut->cut_var()->latency() + cut->cut_var()->step() > max_step) + max_step = cut->cut_var()->latency() + cut->cut_var()->step(); + } + step_ = max_step; +} + +// +// local calculations +// + +void VarAdjustK::local_calculate() { + fval_ = p1_->fval(); + ival_ = p1_->ival(); + if (lr_ > 0) + ival_ = ival_ >> lr_; + else if (lr_ < 0) + ival_ = ival_ << (-lr_); +} + +void VarAdjustKR::local_calculate() { + fval_ = p1_->fval(); + ival_ = p1_->ival(); + if (lr_ > 0) + ival_ = ((ival_ >> (lr_ - 1)) + 1) >> 1; //rounding + else if (lr_ < 0) + ival_ = ival_ << (-lr_); +} + +void VarAdd::local_calculate() { + fval_ = p1_->fval() + p2_->fval(); + long int i1 = p1_->ival(); + long int i2 = p2_->ival(); + if (shift1 > 0) + i1 = i1 << shift1; + if (shift2 > 0) + i2 = i2 << shift2; + ival_ = i1 + i2; + if (ps_ > 0) + ival_ = ival_ >> ps_; +} + +void VarSubtract::local_calculate() { + fval_ = p1_->fval() - p2_->fval(); + long int i1 = p1_->ival(); + long int i2 = p2_->ival(); + if (shift1 > 0) + i1 = i1 << shift1; + if (shift2 > 0) + i2 = i2 << shift2; + ival_ = i1 - i2; + if (ps_ > 0) + ival_ = ival_ >> ps_; +} + +void VarNounits::local_calculate() { + fval_ = p1_->fval(); + ival_ = (p1_->ival() * cI_) >> ps_; +} + +void VarTimesC::local_calculate() { + fval_ = p1_->fval() * cF_; + ival_ = (p1_->ival() * cI_) >> ps_; +} + +void VarNeg::local_calculate() { + fval_ = -p1_->fval(); + ival_ = -p1_->ival(); +} + +void VarShift::local_calculate() { + fval_ = p1_->fval() * pow(2, -shift_); + ival_ = p1_->ival(); + if (shift_ > 0) + ival_ = ival_ >> shift_; + if (shift_ < 0) + ival_ = ival_ << (-shift_); +} + +void VarShiftround::local_calculate() { + fval_ = p1_->fval() * pow(2, -shift_); + ival_ = p1_->ival(); + if (shift_ > 0) + ival_ = ((ival_ >> (shift_ - 1)) + 1) >> 1; + if (shift_ < 0) + ival_ = ival_ << (-shift_); +} + +void VarMult::local_calculate() { + fval_ = p1_->fval() * p2_->fval(); + ival_ = (p1_->ival() * p2_->ival()) >> ps_; +} + +void VarDSPPostadd::local_calculate() { + fval_ = p1_->fval() * p2_->fval() + p3_->fval(); + ival_ = p3_->ival(); + if (shift3_ > 0) + ival_ = ival_ << shift3_; + if (shift3_ < 0) + ival_ = ival_ >> (-shift3_); + ival_ += p1_->ival() * p2_->ival(); + ival_ = ival_ >> ps_; +} + +void VarInv::local_calculate() { + fval_ = 1. / (offset_ + p1_->fval()); + ival_ = LUT[ival_to_addr(p1_->ival())]; +} diff --git a/L1Trigger/TrackFindingTracklet/test/BuildFile.xml b/L1Trigger/TrackFindingTracklet/test/BuildFile.xml new file mode 100644 index 0000000000000..8879ac8fd66db --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/test/BuildFile.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/L1Trigger/TrackFindingTracklet/test/HybridTracks_cfg.py b/L1Trigger/TrackFindingTracklet/test/HybridTracks_cfg.py new file mode 100644 index 0000000000000..7ef38f91d0194 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/test/HybridTracks_cfg.py @@ -0,0 +1,62 @@ +# define basic process +import FWCore.ParameterSet.Config as cms +import FWCore.Utilities.FileUtils as FileUtils +process = cms.Process("L1HybridTrack") + +# ---------------------------------------------------------------------------------- +# import standard configurations +process.load('Configuration.StandardSequences.Services_cff') +process.load('FWCore.MessageService.MessageLogger_cfi') +process.load('Configuration.EventContent.EventContent_cff') +process.load('Configuration.StandardSequences.MagneticField_cff') +process.load('Configuration.Geometry.GeometryExtended2026D49Reco_cff') +process.load('Configuration.Geometry.GeometryExtended2026D49_cff') + +process.load('Configuration.StandardSequences.EndOfProcess_cff') +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') + +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:upgradePLS3', '') + + +# ---------------------------------------------------------------------------------- +# input +process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(10)) +Source_Files = cms.untracked.vstring( + "/store/relval/CMSSW_11_0_0/RelValSingleMuFlatPt2To100/GEN-SIM-DIGI-RAW/110X_mcRun4_realistic_v2_2026D49noPU-v1/20000/F5E783E4-CF4A-4745-B4ED-6F1AA5E5C16F.root" +) +process.source = cms.Source("PoolSource", fileNames = Source_Files) + + +# ---------------------------------------------------------------------------------- +# L1 tracking => hybrid emulation +process.load("L1Trigger.TrackFindingTracklet.L1HybridEmulationTracks_cff") + +# prompt tracking only +process.TTTracksEmulation = cms.Path(process.L1HybridTracks) +process.TTTracksEmulationWithTruth = cms.Path(process.L1HybridTracksWithAssociators) + +# extended tracking only +#process.TTTracksEmulation = cms.Path(process.L1ExtendedHybridTracks) +#process.TTTracksEmulationWithTruth = cms.Path(process.L1ExtendedHybridTracksWithAssociators) + +# both prompt+extended hybrid tracking +#process.TTTracksEmulation = cms.Path(process.L1PromptExtendedHybridTracks) +#process.TTTracksEmulationWithTruth = cms.Path(process.L1PromptExtendedHybridTracksWithAssociators) + + +# ---------------------------------------------------------------------------------- +# output module +process.out = cms.OutputModule( "PoolOutputModule", + fileName = cms.untracked.string("L1Tracks.root"), + fastCloning = cms.untracked.bool( False ), + outputCommands = cms.untracked.vstring('drop *', + 'keep *_TTTrack*_Level1TTTracks_*', +) +) +process.FEVToutput_step = cms.EndPath(process.out) + + +#process.schedule = cms.Schedule(process.TTTracksEmulation,process.FEVToutput_step) +process.schedule = cms.Schedule(process.TTTracksEmulationWithTruth,process.FEVToutput_step) + diff --git a/L1Trigger/TrackFindingTracklet/test/INTERNAL/HistImp.cc b/L1Trigger/TrackFindingTracklet/test/INTERNAL/HistImp.cc new file mode 100644 index 0000000000000..c2ddd60745a4f --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/test/INTERNAL/HistImp.cc @@ -0,0 +1,280 @@ +#include "L1Trigger/TrackFindingTracklet/interface/HistImp.h" +#include "L1Trigger/TrackFindingTracklet/interface/slhcevent.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" + +using namespace std; +using namespace trklet; + +HistImp::HistImp() { + h_file_ = 0; + h_layerresid_phi_L3_L1L2_ = 0; + h_layerresid_phi_L3_L1L2_match_ = 0; + h_layerresid_phif_L3_L1L2_ = 0; + h_layerresid_phif_L3_L1L2_match_ = 0; + h_layerresid_z_L3_L1L2_ = 0; + h_layerresid_z_L3_L1L2_match_ = 0; + h_layerresid_zf_L3_L1L2_ = 0; + h_layerresid_zf_L3_L1L2_match_ = 0; + + h_diskresid_phi_D1_L1L2_ = 0; + h_diskresid_phi_D1_L1L2_match_ = 0; + h_diskresid_phif_D1_L1L2_ = 0; + h_diskresid_phif_D1_L1L2_match_ = 0; + h_diskresid_r_D1_L1L2_ = 0; + h_diskresid_r_D1_L1L2_match_ = 0; + h_diskresid_rf_D1_L1L2_ = 0; + h_diskresid_rf_D1_L1L2_match_ = 0; + + h_rinv_L1L2_ = 0; + h_irinv_L1L2_ = 0; + h_rinvres_L1L2_ = 0; + h_irinvres_L1L2_ = 0; +} + +void HistImp::open() { h_file_ = new TFile("fpgahist.root", "RECREATE"); } + +void HistImp::close() { + if (h_file_) { + h_file_->Write(); + h_file_->Close(); + h_file_ = 0; + } +} + +void HistImp::bookLayerResidual() { + TH1::AddDirectory(kTRUE); + + assert(h_file_ != 0); + h_file_->cd(); + + h_layerresid_phi_L3_L1L2_ = new TH1F("L3 phiresid L1L2", "L3 phiresid L1L2", 100, -0.5, 0.5); + h_layerresid_phi_L3_L1L2_match_ = new TH1F("L3 phiresid L1L2 Match", "L3 phiresid L1L2 Match", 100, -0.5, 0.5); + h_layerresid_phif_L3_L1L2_ = new TH1F("L3 phiresid float L1L2", "L3 phiresid float L1L2", 100, -0.5, 0.5); + h_layerresid_phif_L3_L1L2_match_ = + new TH1F("L3 phiresid float L1L2 Match", "L3 phiresid float L1L2 Match", 100, -0.5, 0.5); + + h_layerresid_z_L3_L1L2_ = new TH1F("L3 zresid L1L2", "L3 zresid L1L2", 100, -5.0, 5.0); + h_layerresid_z_L3_L1L2_match_ = new TH1F("L3 zresid L1L2 Match", "L3 zresid L1L2 Match", 100, -5.0, 5.0); + h_layerresid_zf_L3_L1L2_ = new TH1F("L3 zresid float L1L2", "L3 zresid float L1L2", 100, -5.0, 5.0); + h_layerresid_zf_L3_L1L2_match_ = new TH1F("L3 zresid float L1L2 Match", "L3 zresid float L1L2 Match", 100, -5.0, 5.0); +} + +void HistImp::bookDiskResidual() { + TH1::AddDirectory(kTRUE); + + assert(h_file_ != 0); + h_file_->cd(); + + h_diskresid_phi_D1_L1L2_ = new TH1F("D1 phiresid L1L2", "D1 phiresid L1L2", 100, -0.5, 0.5); + h_diskresid_phi_D1_L1L2_match_ = new TH1F("D1 phiresid L1L2 Match", "D1 phiresid L1L2 Match", 100, -0.5, 0.5); + h_diskresid_phif_D1_L1L2_ = new TH1F("D1 phiresid float L1L2", "D1 phiresid float L1L2", 100, -0.5, 0.5); + h_diskresid_phif_D1_L1L2_match_ = + new TH1F("D1 phiresid float L1L2 Match", "D1 phiresid float L1L2 Match", 100, -0.5, 0.5); + + h_diskresid_r_D1_L1L2_ = new TH1F("D1 rresid L1L2", "D1 rresid L1L2", 100, -5.0, 5.0); + h_diskresid_r_D1_L1L2_match_ = new TH1F("D1 rresid L1L2 Match", "D1 rresid L1L2 Match", 100, -5.0, 5.0); + h_diskresid_rf_D1_L1L2_ = new TH1F("D1 rresid float L1L2", "D1 rresid float L1L2", 100, -5.0, 5.0); + h_diskresid_rf_D1_L1L2_match_ = new TH1F("D1 rresid float L1L2 Match", "D1 rresid float L1L2 Match", 100, -5.0, 5.0); +} + +void HistImp::bookTrackletParams() { + TH1::AddDirectory(kTRUE); + + assert(h_file_ != 0); + h_file_->cd(); + + h_rinv_L1L2_ = new TH1F("Tracklet rinv in L1L2", "Tracklet rinv in L1L2", 140, -0.007, 0.007); + h_irinv_L1L2_ = new TH1F("Tracklet irinv in L1L2", "Tracklet irinv in L1L2", 140, -0.007, 0.007); + h_rinv_matched_L1L2_ = new TH1F("Tracklet rinv in matched L1L2", "Tracklet rinv in matched L1L2", 140, -0.007, 0.007); + h_irinv_matched_L1L2_ = + new TH1F("Tracklet irinv in matched L1L2", "Tracklet irinv in matched L1L2", 140, -0.007, 0.007); + h_rinvres_L1L2_ = new TH1F("Tracklet rinv res in L1L2", "Tracklet rinv res in L1L2", 100, -0.0005, 0.0005); + h_irinvres_L1L2_ = new TH1F("Tracklet irinv res in L1L2", "Tracklet irinv res in L1L2", 100, -0.0005, 0.0005); + + h_phi0_L1L2_ = new TH1F("Tracklet phi0 in L1L2", "Tracklet phi0 in L1L2", 100, 0.0, 1.0); + h_iphi0_L1L2_ = new TH1F("Tracklet iphi0 in L1L2", "Tracklet iphi0 in L1L2", 100, 0.0, 1.0); + h_phi0_matched_L1L2_ = new TH1F("Tracklet phi0 in matched L1L2", "Tracklet phi0 in matched L1L2", 100, 0.0, 1.0); + h_iphi0_matched_L1L2_ = new TH1F("Tracklet iphi0 in matched L1L2", "Tracklet iphi0 in matched L1L2", 100, 0.0, 1.0); + h_phi0global_L1L2_ = new TH1F("Tracklet phi0 global in L1L2", "Tracklet phi0 global in L1L2", 99, -M_PI, M_PI); + h_iphi0global_L1L2_ = new TH1F("Tracklet iphi0 global in L1L2", "Tracklet iphi0 global in L1L2", 99, -M_PI, M_PI); + h_phi0global_matched_L1L2_ = + new TH1F("Tracklet phi0 global in matched L1L2", "Tracklet phi0 global in matched L1L2", 99, -M_PI, M_PI); + h_iphi0global_matched_L1L2_ = + new TH1F("Tracklet iphi0 global in matched L1L2", "Tracklet iphi0 global in matched L1L2", 99, -M_PI, M_PI); + h_phi0res_L1L2_ = new TH1F("Tracklet phi0 res in L1L2", "Tracklet phi0 res in L1L2", 100, -0.5, 0.5); + h_iphi0res_L1L2_ = new TH1F("Tracklet iphi0 res in L1L2", "Tracklet iphi0 res in L1L2", 100, -0.5, 0.5); + + h_eta_L1L2_ = new TH1F("Tracklet eta in L1L2", "Tracklet eta in L1L2", 100, -2.5, 2.5); + h_ieta_L1L2_ = new TH1F("Tracklet ieta in L1L2", "Tracklet ieta in L1L2", 100, -2.5, 2.5); + h_eta_matched_L1L2_ = new TH1F("Tracklet eta in matched L1L2", "Tracklet eta in matched L1L2", 100, -2.5, 2.5); + h_ieta_matched_L1L2_ = new TH1F("Tracklet ieta in matched L1L2", "Tracklet ieta in matched L1L2", 100, -2.5, 2.5); + h_etares_L1L2_ = new TH1F("Tracklet eta res in L1L2", "Tracklet eta res in L1L2", 100, -0.05, 0.05); + h_ietares_L1L2_ = new TH1F("Tracklet ieta res in L1L2", "Tracklet ieta res in L1L2", 100, -0.05, 0.05); + + h_z0_L1L2_ = new TH1F("Tracklet z0 in L1L2", "Tracklet z0 in L1L2", 100, -25.0, 25.0); + h_iz0_L1L2_ = new TH1F("Tracklet iz0 in L1L2", "Tracklet iz0 in L1L2", 100, -25.0, 25.0); + h_z0_matched_L1L2_ = new TH1F("Tracklet z0 in matched L1L2", "Tracklet z0 in matched L1L2", 100, -25.0, 25.0); + h_iz0_matched_L1L2_ = new TH1F("Tracklet iz0 in matched L1L2", "Tracklet iz0 in matched L1L2", 100, -25.0, 25.0); + h_z0res_L1L2_ = new TH1F("Tracklet z0 res in L1L2", "Tracklet z0 res in L1L2", 100, -5.0, 5.0); + h_iz0res_L1L2_ = new TH1F("Tracklet iz0 res in L1L2", "Tracklet iz0 res in L1L2", 100, -5.0, 5.0); +} + +void HistImp::fillTrackletParams(const Settings* settings, + Globals* globals, + int seedIndex, + int iSector, + double rinv, + double irinv, + double phi0, + double iphi0, + double eta, + double ieta, + double z0, + double iz0, + int tp) { + if (seedIndex == 0) { + h_rinv_L1L2_->Fill(rinv); + h_irinv_L1L2_->Fill(irinv); + h_phi0_L1L2_->Fill(phi0); + h_iphi0_L1L2_->Fill(iphi0); + double phi0global = phi0 + iSector * 2 * M_PI / N_SECTOR; + if (phi0global > M_PI) + phi0global -= 2 * M_PI; + if (phi0global < -M_PI) + phi0global += 2 * M_PI; + double iphi0global = iphi0 + iSector * 2 * M_PI / N_SECTOR; + if (iphi0global > M_PI) + iphi0global -= 2 * M_PI; + if (iphi0global < -M_PI) + iphi0global += 2 * M_PI; + h_phi0global_L1L2_->Fill(phi0global); + h_iphi0global_L1L2_->Fill(iphi0global); + h_eta_L1L2_->Fill(eta); + h_ieta_L1L2_->Fill(ieta); + h_z0_L1L2_->Fill(z0); + h_iz0_L1L2_->Fill(iz0); + if (tp != 0) { + h_rinv_matched_L1L2_->Fill(rinv); + h_irinv_matched_L1L2_->Fill(irinv); + h_phi0_matched_L1L2_->Fill(phi0); + h_iphi0_matched_L1L2_->Fill(iphi0); + h_phi0global_matched_L1L2_->Fill(phi0global); + h_iphi0global_matched_L1L2_->Fill(iphi0global); + h_eta_matched_L1L2_->Fill(eta); + h_ieta_matched_L1L2_->Fill(ieta); + h_z0_matched_L1L2_->Fill(z0); + h_iz0_matched_L1L2_->Fill(iz0); + L1SimTrack simtrk = globals->event()->simtrack(tp - 1); + h_rinvres_L1L2_->Fill(rinv - (simtrk.charge() * 0.01 * 0.3 * 3.8 / simtrk.pt())); + h_irinvres_L1L2_->Fill(irinv - (simtrk.charge() * 0.01 * 0.3 * 3.8 / simtrk.pt())); + double simtrkphi0 = simtrk.phi(); + double dphiHG = 0.5 * settings->dphisectorHG() - M_PI / N_SECTOR; + double phimin = +dphiHG - M_PI / N_SECTOR; + double phioffset = phimin; + while (iphi0 - phioffset - simtrkphi0 > M_PI / N_SECTOR) + simtrkphi0 += 2 * M_PI / N_SECTOR; + while (iphi0 - phioffset - simtrkphi0 < -M_PI / N_SECTOR) + simtrkphi0 -= 2 * M_PI / N_SECTOR; + h_phi0res_L1L2_->Fill(phi0 - phioffset - simtrkphi0); + h_iphi0res_L1L2_->Fill(iphi0 - phioffset - simtrkphi0); + h_etares_L1L2_->Fill(eta - simtrk.eta()); + h_ietares_L1L2_->Fill(ieta - simtrk.eta()); + h_z0res_L1L2_->Fill(z0 - simtrk.vz()); + h_iz0res_L1L2_->Fill(iz0 - simtrk.vz()); + } + } + + return; +} + +void HistImp::FillLayerResidual( + int layer, int seed, double phiresid, double iphiresid, double zresid, double izresid, bool match) { + if (layer == 3) { + if (seed == 0) { + h_layerresid_phi_L3_L1L2_->Fill(iphiresid); + h_layerresid_phif_L3_L1L2_->Fill(phiresid); + h_layerresid_z_L3_L1L2_->Fill(izresid); + h_layerresid_zf_L3_L1L2_->Fill(zresid); + if (match) { + h_layerresid_phi_L3_L1L2_match_->Fill(iphiresid); + h_layerresid_phif_L3_L1L2_match_->Fill(phiresid); + h_layerresid_z_L3_L1L2_match_->Fill(izresid); + h_layerresid_zf_L3_L1L2_match_->Fill(zresid); + } + } + } + return; +} + +void HistImp::FillDiskResidual( + int disk, int seed, double phiresid, double iphiresid, double rresid, double irresid, bool match) { + if (disk == 1) { + if (seed == 0) { + h_diskresid_phi_D1_L1L2_->Fill(iphiresid); + h_diskresid_phif_D1_L1L2_->Fill(phiresid); + h_diskresid_r_D1_L1L2_->Fill(irresid); + h_diskresid_rf_D1_L1L2_->Fill(rresid); + if (match) { + h_diskresid_phi_D1_L1L2_match_->Fill(iphiresid); + h_diskresid_phif_D1_L1L2_match_->Fill(phiresid); + h_diskresid_r_D1_L1L2_match_->Fill(irresid); + h_diskresid_rf_D1_L1L2_match_->Fill(rresid); + } + } + } + + return; +} + +void HistImp::bookSeedEff() { + TH1::AddDirectory(kTRUE); + + assert(h_file_ != 0); + h_file_->cd(); + + h_eff_eta_L1L2seed_ = + new TEfficiency("Efficincy for L1L2 seeding vs eta", "Efficiency for L1L2 seeding vs eta", 50, -2.5, 2.5); + h_eff_eta_L2L3seed_ = + new TEfficiency("Efficincy for L2L3 seeding vs eta", "Efficiency for L2L3 seeding vs eta", 50, -2.5, 2.5); + h_eff_eta_L3L4seed_ = + new TEfficiency("Efficincy for L3L4 seeding vs eta", "Efficiency for L3L4 seeding vs eta", 50, -2.5, 2.5); + h_eff_eta_L5L6seed_ = + new TEfficiency("Efficincy for L5L6 seeding vs eta", "Efficiency for L5L6 seeding vs eta", 50, -2.5, 2.5); + h_eff_eta_D1D2seed_ = + new TEfficiency("Efficincy for D1D2 seeding vs eta", "Efficiency for D1D2 seeding vs eta", 50, -2.5, 2.5); + h_eff_eta_D3D4seed_ = + new TEfficiency("Efficincy for D3D4 seeding vs eta", "Efficiency for D3D4 seeding vs eta", 50, -2.5, 2.5); + h_eff_eta_D1L1seed_ = + new TEfficiency("Efficincy for D1L1 seeding vs eta", "Efficiency for D1L1 seeding vs eta", 50, -2.5, 2.5); + h_eff_eta_D1L2seed_ = + new TEfficiency("Efficincy for D1L2 seeding vs eta", "Efficiency for D1L2 seeding vs eta", 50, -2.5, 2.5); +} + +void HistImp::fillSeedEff(int seedIndex, double etaTP, bool eff) { + if (seedIndex == 0) { + h_eff_eta_L1L2seed_->Fill(eff, etaTP); + } + if (seedIndex == 1) { + h_eff_eta_L2L3seed_->Fill(eff, etaTP); + } + if (seedIndex == 2) { + h_eff_eta_L3L4seed_->Fill(eff, etaTP); + } + if (seedIndex == 3) { + h_eff_eta_L5L6seed_->Fill(eff, etaTP); + } + if (seedIndex == 4) { + h_eff_eta_D1D2seed_->Fill(eff, etaTP); + } + if (seedIndex == 5) { + h_eff_eta_D3D4seed_->Fill(eff, etaTP); + } + if (seedIndex == 6) { + h_eff_eta_D1L1seed_->Fill(eff, etaTP); + } + if (seedIndex == 7) { + h_eff_eta_D1L2seed_->Fill(eff, etaTP); + } + + return; +} diff --git a/L1Trigger/TrackFindingTracklet/test/INTERNAL/HistImp.h b/L1Trigger/TrackFindingTracklet/test/INTERNAL/HistImp.h new file mode 100644 index 0000000000000..25957724a05db --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/test/INTERNAL/HistImp.h @@ -0,0 +1,117 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_HistImp_h +#define L1Trigger_TrackFindingTracklet_interface_HistImp_h + +#include +#include +#include + +#include "L1Trigger/TrackFindingTracklet/interface/HistBase.h" + +namespace trklet { + + class Settings; + class Globals; + + class HistImp : public HistBase { + public: + HistImp(); + + ~HistImp() = default; + + void open() override; + void close() override; + + void bookLayerResidual() override; + void bookDiskResidual() override; + void bookTrackletParams() override; + void bookSeedEff() override; + + void fillTrackletParams(const Settings *settings, + Globals *globals, + int seedIndex, + int iSector, + double rinv, + double irinv, + double phi0, + double iphi0, + double eta, + double ieta, + double z0, + double iz0, + int tp) override; + + void FillLayerResidual( + int layer, int seed, double phiresid, double iphiresid, double zresid, double izresid, bool match) override; + + void FillDiskResidual( + int disk, int seed, double phiresid, double iphiresid, double rresid, double irresid, bool match) override; + + //Efficiency for finding seed + void fillSeedEff(int seedIndex, double etaTP, bool eff) override; + + private: + TFile *h_file_; + + //Layer residuales + TH1F *h_layerresid_phi_L3_L1L2_; + TH1F *h_layerresid_phi_L3_L1L2_match_; + TH1F *h_layerresid_phif_L3_L1L2_; + TH1F *h_layerresid_phif_L3_L1L2_match_; + TH1F *h_layerresid_z_L3_L1L2_; + TH1F *h_layerresid_z_L3_L1L2_match_; + TH1F *h_layerresid_zf_L3_L1L2_; + TH1F *h_layerresid_zf_L3_L1L2_match_; + + //Disk residuals + TH1F *h_diskresid_phi_D1_L1L2_; + TH1F *h_diskresid_phi_D1_L1L2_match_; + TH1F *h_diskresid_phif_D1_L1L2_; + TH1F *h_diskresid_phif_D1_L1L2_match_; + TH1F *h_diskresid_r_D1_L1L2_; + TH1F *h_diskresid_r_D1_L1L2_match_; + TH1F *h_diskresid_rf_D1_L1L2_; + TH1F *h_diskresid_rf_D1_L1L2_match_; + + //Tracklet parameters + TH1F *h_rinv_L1L2_; + TH1F *h_irinv_L1L2_; + TH1F *h_rinv_matched_L1L2_; + TH1F *h_irinv_matched_L1L2_; + TH1F *h_rinvres_L1L2_; + TH1F *h_irinvres_L1L2_; + TH1F *h_phi0_L1L2_; + TH1F *h_iphi0_L1L2_; + TH1F *h_phi0_matched_L1L2_; + TH1F *h_iphi0_matched_L1L2_; + TH1F *h_phi0global_L1L2_; + TH1F *h_iphi0global_L1L2_; + TH1F *h_phi0global_matched_L1L2_; + TH1F *h_iphi0global_matched_L1L2_; + TH1F *h_phi0res_L1L2_; + TH1F *h_iphi0res_L1L2_; + TH1F *h_eta_L1L2_; + TH1F *h_ieta_L1L2_; + TH1F *h_eta_matched_L1L2_; + TH1F *h_ieta_matched_L1L2_; + TH1F *h_etares_L1L2_; + TH1F *h_ietares_L1L2_; + TH1F *h_z0_L1L2_; + TH1F *h_iz0_L1L2_; + TH1F *h_z0_matched_L1L2_; + TH1F *h_iz0_matched_L1L2_; + TH1F *h_z0res_L1L2_; + TH1F *h_iz0res_L1L2_; + + //seeding efficiency + TEfficiency *h_eff_eta_L1L2seed_; + TEfficiency *h_eff_eta_L2L3seed_; + TEfficiency *h_eff_eta_L3L4seed_; + TEfficiency *h_eff_eta_L5L6seed_; + TEfficiency *h_eff_eta_D1D2seed_; + TEfficiency *h_eff_eta_D3D4seed_; + TEfficiency *h_eff_eta_D1L1seed_; + TEfficiency *h_eff_eta_D1L2seed_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc new file mode 100644 index 0000000000000..d86c90494b1e6 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker.cc @@ -0,0 +1,1492 @@ +////////////////////////////////////////////////////////////////////// +// // +// Analyzer for making mini-ntuple for L1 track performance plots // +// // +////////////////////////////////////////////////////////////////////// + +//////////////////// +// FRAMEWORK HEADERS +#include "FWCore/PluginManager/interface/ModuleDef.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/EDAnalyzer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/InputTag.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" + +/////////////////////// +// DATA FORMATS HEADERS +#include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/Common/interface/Ref.h" + +#include "DataFormats/L1TrackTrigger/interface/TTTypes.h" +#include "DataFormats/L1TrackTrigger/interface/TTCluster.h" +#include "DataFormats/L1TrackTrigger/interface/TTStub.h" +#include "DataFormats/L1TrackTrigger/interface/TTTrack.h" +#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h" +#include "SimDataFormats/TrackingAnalysis/interface/TrackingVertex.h" +#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h" +#include "SimDataFormats/TrackingHit/interface/PSimHit.h" +#include "SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h" +#include "SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h" +#include "SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h" +#include "Geometry/Records/interface/StackedTrackerGeometryRecord.h" + +#include "DataFormats/JetReco/interface/GenJetCollection.h" +#include "DataFormats/JetReco/interface/GenJet.h" + +//////////////////////////// +// DETECTOR GEOMETRY HEADERS +#include "MagneticField/Engine/interface/MagneticField.h" +#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" +#include "Geometry/TrackerGeometryBuilder/interface/RectangularPixelTopology.h" +#include "Geometry/CommonDetUnit/interface/GeomDetType.h" +#include "Geometry/CommonDetUnit/interface/GeomDet.h" + +#include "Geometry/CommonTopologies/interface/PixelGeomDetUnit.h" +#include "Geometry/CommonTopologies/interface/PixelGeomDetType.h" +#include "Geometry/TrackerGeometryBuilder/interface/PixelTopologyBuilder.h" +#include "Geometry/Records/interface/StackedTrackerGeometryRecord.h" + +//////////////// +// PHYSICS TOOLS +#include "CommonTools/UtilAlgos/interface/TFileService.h" + +/////////////// +// ROOT HEADERS +#include +#include +#include +#include +#include +#include +#include + +////////////// +// STD HEADERS +#include +#include +#include + +////////////// +// NAMESPACES +using namespace std; +using namespace edm; + +////////////////////////////// +// // +// CLASS DEFINITION // +// // +////////////////////////////// + +class L1TrackNtupleMaker : public edm::EDAnalyzer { +public: + // Constructor/destructor + explicit L1TrackNtupleMaker(const edm::ParameterSet& iConfig); + ~L1TrackNtupleMaker() override; + + // Mandatory methods + void beginJob() override; + void endJob() override; + void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override; + +protected: +private: + //----------------------------------------------------------------------------------------------- + // Containers of parameters passed by python configuration file + edm::ParameterSet config; + + int MyProcess; // 11/13/211 for single electrons/muons/pions, 6/15 for pions from ttbar/taus, 1 for inclusive + bool DebugMode; // lots of debug printout statements + bool SaveAllTracks; // store in ntuples not only truth-matched tracks but ALL tracks + bool SaveStubs; // option to save also stubs in the ntuples (makes them large...) + int L1Tk_nPar; // use 4 or 5 parameter track fit? + int TP_minNStub; // require TPs to have >= minNStub (defining efficiency denominator) (==0 means to only require >= 1 cluster) + int TP_minNStubLayer; // require TPs to have stubs in >= minNStubLayer layers/disks (defining efficiency denominator) + double TP_minPt; // save TPs with pt > minPt + double TP_maxEta; // save TPs with |eta| < maxEta + double TP_maxZ0; // save TPs with |z0| < maxZ0 + int L1Tk_minNStub; // require L1 tracks to have >= minNStub (this is mostly for tracklet purposes) + + bool TrackingInJets; // do tracking in jets? + + edm::InputTag L1TrackInputTag; // L1 track collection + edm::InputTag MCTruthTrackInputTag; // MC truth collection + edm::InputTag MCTruthClusterInputTag; + edm::InputTag L1StubInputTag; + edm::InputTag MCTruthStubInputTag; + edm::InputTag TrackingParticleInputTag; + edm::InputTag TrackingVertexInputTag; + edm::InputTag GenJetInputTag; + + edm::EDGetTokenT > > ttClusterToken_; + edm::EDGetTokenT > > ttStubToken_; + edm::EDGetTokenT > ttClusterMCTruthToken_; + edm::EDGetTokenT > ttStubMCTruthToken_; + + edm::EDGetTokenT > > ttTrackToken_; + edm::EDGetTokenT > ttTrackMCTruthToken_; + + edm::EDGetTokenT > TrackingParticleToken_; + edm::EDGetTokenT > TrackingVertexToken_; + + edm::EDGetTokenT > GenJetToken_; + + //----------------------------------------------------------------------------------------------- + // tree & branches for mini-ntuple + + bool available_; // ROOT file for histograms is open. + + TTree* eventTree; + + // all L1 tracks + std::vector* m_trk_pt; + std::vector* m_trk_eta; + std::vector* m_trk_phi; + std::vector* m_trk_d0; // (filled if L1Tk_nPar==5, else 999) + std::vector* m_trk_z0; + std::vector* m_trk_chi2; + std::vector* m_trk_chi2rphi; + std::vector* m_trk_chi2rz; + std::vector* m_trk_bendchi2; + std::vector* m_trk_nstub; + std::vector* m_trk_lhits; + std::vector* m_trk_dhits; + std::vector* m_trk_seed; + std::vector* m_trk_hitpattern; + std::vector* m_trk_phiSector; + std::vector* m_trk_genuine; + std::vector* m_trk_loose; + std::vector* m_trk_unknown; + std::vector* m_trk_combinatoric; + std::vector* m_trk_fake; //0 fake, 1 track from primary interaction, 2 secondary track + std::vector* m_trk_matchtp_pdgid; + std::vector* m_trk_matchtp_pt; + std::vector* m_trk_matchtp_eta; + std::vector* m_trk_matchtp_phi; + std::vector* m_trk_matchtp_z0; + std::vector* m_trk_matchtp_dxy; + std::vector* m_trk_injet; //is the track within dR<0.4 of a genjet with pt > 30 GeV? + std::vector* m_trk_injet_highpt; //is the track within dR<0.4 of a genjet with pt > 100 GeV? + std::vector* m_trk_injet_vhighpt; //is the track within dR<0.4 of a genjet with pt > 200 GeV? + + // all tracking particles + std::vector* m_tp_pt; + std::vector* m_tp_eta; + std::vector* m_tp_phi; + std::vector* m_tp_dxy; + std::vector* m_tp_d0; + std::vector* m_tp_z0; + std::vector* m_tp_d0_prod; + std::vector* m_tp_z0_prod; + std::vector* m_tp_pdgid; + std::vector* m_tp_nmatch; + std::vector* m_tp_nstub; + std::vector* m_tp_eventid; + std::vector* m_tp_charge; + std::vector* m_tp_injet; + std::vector* m_tp_injet_highpt; + std::vector* m_tp_injet_vhighpt; + + // *L1 track* properties if m_tp_nmatch > 0 + std::vector* m_matchtrk_pt; + std::vector* m_matchtrk_eta; + std::vector* m_matchtrk_phi; + std::vector* m_matchtrk_d0; //this variable is only filled if L1Tk_nPar==5 + std::vector* m_matchtrk_z0; + std::vector* m_matchtrk_chi2; + std::vector* m_matchtrk_chi2rphi; + std::vector* m_matchtrk_chi2rz; + std::vector* m_matchtrk_bendchi2; + std::vector* m_matchtrk_nstub; + std::vector* m_matchtrk_lhits; + std::vector* m_matchtrk_dhits; + std::vector* m_matchtrk_seed; + std::vector* m_matchtrk_hitpattern; + std::vector* m_matchtrk_injet; + std::vector* m_matchtrk_injet_highpt; + std::vector* m_matchtrk_injet_vhighpt; + + // ALL stubs + std::vector* m_allstub_x; + std::vector* m_allstub_y; + std::vector* m_allstub_z; + + std::vector* m_allstub_isBarrel; // stub is in barrel (1) or in disk (0) + std::vector* m_allstub_layer; + std::vector* m_allstub_isPSmodule; + + std::vector* m_allstub_trigDisplace; + std::vector* m_allstub_trigOffset; + std::vector* m_allstub_trigPos; + std::vector* m_allstub_trigBend; + + // stub associated with tracking particle ? + std::vector* m_allstub_matchTP_pdgid; // -999 if not matched + std::vector* m_allstub_matchTP_pt; // -999 if not matched + std::vector* m_allstub_matchTP_eta; // -999 if not matched + std::vector* m_allstub_matchTP_phi; // -999 if not matched + + std::vector* m_allstub_genuine; + + // track jet variables (for each gen jet, store the sum of pt of TPs / tracks inside jet cone) + std::vector* m_jet_eta; + std::vector* m_jet_phi; + std::vector* m_jet_pt; + std::vector* m_jet_tp_sumpt; + std::vector* m_jet_trk_sumpt; + std::vector* m_jet_matchtrk_sumpt; +}; + +////////////////////////////////// +// // +// CLASS IMPLEMENTATION // +// // +////////////////////////////////// + +////////////// +// CONSTRUCTOR +L1TrackNtupleMaker::L1TrackNtupleMaker(edm::ParameterSet const& iConfig) : config(iConfig) { + MyProcess = iConfig.getParameter("MyProcess"); + DebugMode = iConfig.getParameter("DebugMode"); + SaveAllTracks = iConfig.getParameter("SaveAllTracks"); + SaveStubs = iConfig.getParameter("SaveStubs"); + L1Tk_nPar = iConfig.getParameter("L1Tk_nPar"); + TP_minNStub = iConfig.getParameter("TP_minNStub"); + TP_minNStubLayer = iConfig.getParameter("TP_minNStubLayer"); + TP_minPt = iConfig.getParameter("TP_minPt"); + TP_maxEta = iConfig.getParameter("TP_maxEta"); + TP_maxZ0 = iConfig.getParameter("TP_maxZ0"); + L1TrackInputTag = iConfig.getParameter("L1TrackInputTag"); + MCTruthTrackInputTag = iConfig.getParameter("MCTruthTrackInputTag"); + L1Tk_minNStub = iConfig.getParameter("L1Tk_minNStub"); + + TrackingInJets = iConfig.getParameter("TrackingInJets"); + + L1StubInputTag = iConfig.getParameter("L1StubInputTag"); + MCTruthClusterInputTag = iConfig.getParameter("MCTruthClusterInputTag"); + MCTruthStubInputTag = iConfig.getParameter("MCTruthStubInputTag"); + TrackingParticleInputTag = iConfig.getParameter("TrackingParticleInputTag"); + TrackingVertexInputTag = iConfig.getParameter("TrackingVertexInputTag"); + GenJetInputTag = iConfig.getParameter("GenJetInputTag"); + + ttTrackToken_ = consumes > >(L1TrackInputTag); + ttTrackMCTruthToken_ = consumes >(MCTruthTrackInputTag); + ttStubToken_ = consumes > >(L1StubInputTag); + ttClusterMCTruthToken_ = consumes >(MCTruthClusterInputTag); + ttStubMCTruthToken_ = consumes >(MCTruthStubInputTag); + + TrackingParticleToken_ = consumes >(TrackingParticleInputTag); + TrackingVertexToken_ = consumes >(TrackingVertexInputTag); + GenJetToken_ = consumes >(GenJetInputTag); +} + +///////////// +// DESTRUCTOR +L1TrackNtupleMaker::~L1TrackNtupleMaker() {} + +////////// +// END JOB +void L1TrackNtupleMaker::endJob() { + // things to be done at the exit of the event Loop + edm::LogVerbatim("Tracklet") << "L1TrackNtupleMaker::endJob"; +} + +//////////// +// BEGIN JOB +void L1TrackNtupleMaker::beginJob() { + // things to be done before entering the event Loop + edm::LogVerbatim("Tracklet") << "L1TrackNtupleMaker::beginJob"; + + //----------------------------------------------------------------------------------------------- + // book histograms / make ntuple + edm::Service fs; + available_ = fs.isAvailable(); + if (not available_) + return; // No ROOT file open. + + // initilize + m_trk_pt = new std::vector; + m_trk_eta = new std::vector; + m_trk_phi = new std::vector; + m_trk_z0 = new std::vector; + m_trk_d0 = new std::vector; + m_trk_chi2 = new std::vector; + m_trk_chi2rphi = new std::vector; + m_trk_chi2rz = new std::vector; + m_trk_bendchi2 = new std::vector; + m_trk_nstub = new std::vector; + m_trk_lhits = new std::vector; + m_trk_dhits = new std::vector; + m_trk_seed = new std::vector; + m_trk_hitpattern = new std::vector; + m_trk_phiSector = new std::vector; + m_trk_genuine = new std::vector; + m_trk_loose = new std::vector; + m_trk_unknown = new std::vector; + m_trk_combinatoric = new std::vector; + m_trk_fake = new std::vector; + m_trk_matchtp_pdgid = new std::vector; + m_trk_matchtp_pt = new std::vector; + m_trk_matchtp_eta = new std::vector; + m_trk_matchtp_phi = new std::vector; + m_trk_matchtp_z0 = new std::vector; + m_trk_matchtp_dxy = new std::vector; + m_trk_injet = new std::vector; + m_trk_injet_highpt = new std::vector; + m_trk_injet_vhighpt = new std::vector; + + m_tp_pt = new std::vector; + m_tp_eta = new std::vector; + m_tp_phi = new std::vector; + m_tp_dxy = new std::vector; + m_tp_d0 = new std::vector; + m_tp_z0 = new std::vector; + m_tp_d0_prod = new std::vector; + m_tp_z0_prod = new std::vector; + m_tp_pdgid = new std::vector; + m_tp_nmatch = new std::vector; + m_tp_nstub = new std::vector; + m_tp_eventid = new std::vector; + m_tp_charge = new std::vector; + m_tp_injet = new std::vector; + m_tp_injet_highpt = new std::vector; + m_tp_injet_vhighpt = new std::vector; + + m_matchtrk_pt = new std::vector; + m_matchtrk_eta = new std::vector; + m_matchtrk_phi = new std::vector; + m_matchtrk_z0 = new std::vector; + m_matchtrk_d0 = new std::vector; + m_matchtrk_chi2 = new std::vector; + m_matchtrk_chi2rphi = new std::vector; + m_matchtrk_chi2rz = new std::vector; + m_matchtrk_bendchi2 = new std::vector; + m_matchtrk_nstub = new std::vector; + m_matchtrk_dhits = new std::vector; + m_matchtrk_lhits = new std::vector; + m_matchtrk_seed = new std::vector; + m_matchtrk_hitpattern = new std::vector; + m_matchtrk_injet = new std::vector; + m_matchtrk_injet_highpt = new std::vector; + m_matchtrk_injet_vhighpt = new std::vector; + + m_allstub_x = new std::vector; + m_allstub_y = new std::vector; + m_allstub_z = new std::vector; + + m_allstub_isBarrel = new std::vector; + m_allstub_layer = new std::vector; + m_allstub_isPSmodule = new std::vector; + m_allstub_trigDisplace = new std::vector; + m_allstub_trigOffset = new std::vector; + m_allstub_trigPos = new std::vector; + m_allstub_trigBend = new std::vector; + + m_allstub_matchTP_pdgid = new std::vector; + m_allstub_matchTP_pt = new std::vector; + m_allstub_matchTP_eta = new std::vector; + m_allstub_matchTP_phi = new std::vector; + + m_allstub_genuine = new std::vector; + + m_jet_eta = new std::vector; + m_jet_phi = new std::vector; + m_jet_pt = new std::vector; + m_jet_tp_sumpt = new std::vector; + m_jet_trk_sumpt = new std::vector; + m_jet_matchtrk_sumpt = new std::vector; + + // ntuple + eventTree = fs->make("eventTree", "Event tree"); + + if (SaveAllTracks) { + eventTree->Branch("trk_pt", &m_trk_pt); + eventTree->Branch("trk_eta", &m_trk_eta); + eventTree->Branch("trk_phi", &m_trk_phi); + eventTree->Branch("trk_d0", &m_trk_d0); + eventTree->Branch("trk_z0", &m_trk_z0); + eventTree->Branch("trk_chi2", &m_trk_chi2); + eventTree->Branch("trk_chi2rphi", &m_trk_chi2rphi); + eventTree->Branch("trk_chi2rz", &m_trk_chi2rz); + eventTree->Branch("trk_bendchi2", &m_trk_bendchi2); + eventTree->Branch("trk_nstub", &m_trk_nstub); + eventTree->Branch("trk_lhits", &m_trk_lhits); + eventTree->Branch("trk_dhits", &m_trk_dhits); + eventTree->Branch("trk_seed", &m_trk_seed); + eventTree->Branch("trk_hitpattern", &m_trk_hitpattern); + eventTree->Branch("trk_phiSector", &m_trk_phiSector); + eventTree->Branch("trk_genuine", &m_trk_genuine); + eventTree->Branch("trk_loose", &m_trk_loose); + eventTree->Branch("trk_unknown", &m_trk_unknown); + eventTree->Branch("trk_combinatoric", &m_trk_combinatoric); + eventTree->Branch("trk_fake", &m_trk_fake); + eventTree->Branch("trk_matchtp_pdgid", &m_trk_matchtp_pdgid); + eventTree->Branch("trk_matchtp_pt", &m_trk_matchtp_pt); + eventTree->Branch("trk_matchtp_eta", &m_trk_matchtp_eta); + eventTree->Branch("trk_matchtp_phi", &m_trk_matchtp_phi); + eventTree->Branch("trk_matchtp_z0", &m_trk_matchtp_z0); + eventTree->Branch("trk_matchtp_dxy", &m_trk_matchtp_dxy); + if (TrackingInJets) { + eventTree->Branch("trk_injet", &m_trk_injet); + eventTree->Branch("trk_injet_highpt", &m_trk_injet_highpt); + eventTree->Branch("trk_injet_vhighpt", &m_trk_injet_vhighpt); + } + } + + eventTree->Branch("tp_pt", &m_tp_pt); + eventTree->Branch("tp_eta", &m_tp_eta); + eventTree->Branch("tp_phi", &m_tp_phi); + eventTree->Branch("tp_dxy", &m_tp_dxy); + eventTree->Branch("tp_d0", &m_tp_d0); + eventTree->Branch("tp_z0", &m_tp_z0); + eventTree->Branch("tp_d0_prod", &m_tp_d0_prod); + eventTree->Branch("tp_z0_prod", &m_tp_z0_prod); + eventTree->Branch("tp_pdgid", &m_tp_pdgid); + eventTree->Branch("tp_nmatch", &m_tp_nmatch); + eventTree->Branch("tp_nstub", &m_tp_nstub); + eventTree->Branch("tp_eventid", &m_tp_eventid); + eventTree->Branch("tp_charge", &m_tp_charge); + if (TrackingInJets) { + eventTree->Branch("tp_injet", &m_tp_injet); + eventTree->Branch("tp_injet_highpt", &m_tp_injet_highpt); + eventTree->Branch("tp_injet_vhighpt", &m_tp_injet_vhighpt); + } + + eventTree->Branch("matchtrk_pt", &m_matchtrk_pt); + eventTree->Branch("matchtrk_eta", &m_matchtrk_eta); + eventTree->Branch("matchtrk_phi", &m_matchtrk_phi); + eventTree->Branch("matchtrk_z0", &m_matchtrk_z0); + eventTree->Branch("matchtrk_d0", &m_matchtrk_d0); + eventTree->Branch("matchtrk_chi2", &m_matchtrk_chi2); + eventTree->Branch("matchtrk_chi2rphi", &m_matchtrk_chi2rphi); + eventTree->Branch("matchtrk_chi2rz", &m_matchtrk_chi2rz); + eventTree->Branch("matchtrk_bendchi2", &m_matchtrk_bendchi2); + eventTree->Branch("matchtrk_nstub", &m_matchtrk_nstub); + eventTree->Branch("matchtrk_lhits", &m_matchtrk_lhits); + eventTree->Branch("matchtrk_dhits", &m_matchtrk_dhits); + eventTree->Branch("matchtrk_seed", &m_matchtrk_seed); + eventTree->Branch("matchtrk_hitpattern", &m_matchtrk_hitpattern); + if (TrackingInJets) { + eventTree->Branch("matchtrk_injet", &m_matchtrk_injet); + eventTree->Branch("matchtrk_injet_highpt", &m_matchtrk_injet_highpt); + eventTree->Branch("matchtrk_injet_vhighpt", &m_matchtrk_injet_vhighpt); + } + + if (SaveStubs) { + eventTree->Branch("allstub_x", &m_allstub_x); + eventTree->Branch("allstub_y", &m_allstub_y); + eventTree->Branch("allstub_z", &m_allstub_z); + + eventTree->Branch("allstub_isBarrel", &m_allstub_isBarrel); + eventTree->Branch("allstub_layer", &m_allstub_layer); + eventTree->Branch("allstub_isPSmodule", &m_allstub_isPSmodule); + + eventTree->Branch("allstub_trigDisplace", &m_allstub_trigDisplace); + eventTree->Branch("allstub_trigOffset", &m_allstub_trigOffset); + eventTree->Branch("allstub_trigPos", &m_allstub_trigPos); + eventTree->Branch("allstub_trigBend", &m_allstub_trigBend); + + eventTree->Branch("allstub_matchTP_pdgid", &m_allstub_matchTP_pdgid); + eventTree->Branch("allstub_matchTP_pt", &m_allstub_matchTP_pt); + eventTree->Branch("allstub_matchTP_eta", &m_allstub_matchTP_eta); + eventTree->Branch("allstub_matchTP_phi", &m_allstub_matchTP_phi); + + eventTree->Branch("allstub_genuine", &m_allstub_genuine); + } + + if (TrackingInJets) { + eventTree->Branch("jet_eta", &m_jet_eta); + eventTree->Branch("jet_phi", &m_jet_phi); + eventTree->Branch("jet_pt", &m_jet_pt); + eventTree->Branch("jet_tp_sumpt", &m_jet_tp_sumpt); + eventTree->Branch("jet_trk_sumpt", &m_jet_trk_sumpt); + eventTree->Branch("jet_matchtrk_sumpt", &m_jet_matchtrk_sumpt); + } +} + +////////// +// ANALYZE +void L1TrackNtupleMaker::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { + if (not available_) + return; // No ROOT file open. + + if (!(MyProcess == 13 || MyProcess == 11 || MyProcess == 211 || MyProcess == 6 || MyProcess == 15 || + MyProcess == 1)) { + edm::LogVerbatim("Tracklet") << "The specified MyProcess is invalid! Exiting..."; + return; + } + + if (!(L1Tk_nPar == 4 || L1Tk_nPar == 5)) { + edm::LogVerbatim("Tracklet") << "Invalid number of track parameters, specified L1Tk_nPar == " << L1Tk_nPar + << " but only 4/5 are valid options! Exiting..."; + return; + } + + // clear variables + if (SaveAllTracks) { + m_trk_pt->clear(); + m_trk_eta->clear(); + m_trk_phi->clear(); + m_trk_d0->clear(); + m_trk_z0->clear(); + m_trk_chi2->clear(); + m_trk_chi2rphi->clear(); + m_trk_chi2rz->clear(); + m_trk_bendchi2->clear(); + m_trk_nstub->clear(); + m_trk_lhits->clear(); + m_trk_dhits->clear(); + m_trk_seed->clear(); + m_trk_hitpattern->clear(); + m_trk_phiSector->clear(); + m_trk_genuine->clear(); + m_trk_loose->clear(); + m_trk_unknown->clear(); + m_trk_combinatoric->clear(); + m_trk_fake->clear(); + m_trk_matchtp_pdgid->clear(); + m_trk_matchtp_pt->clear(); + m_trk_matchtp_eta->clear(); + m_trk_matchtp_phi->clear(); + m_trk_matchtp_z0->clear(); + m_trk_matchtp_dxy->clear(); + m_trk_injet->clear(); + m_trk_injet_highpt->clear(); + m_trk_injet_vhighpt->clear(); + } + + m_tp_pt->clear(); + m_tp_eta->clear(); + m_tp_phi->clear(); + m_tp_dxy->clear(); + m_tp_d0->clear(); + m_tp_z0->clear(); + m_tp_d0_prod->clear(); + m_tp_z0_prod->clear(); + m_tp_pdgid->clear(); + m_tp_nmatch->clear(); + m_tp_nstub->clear(); + m_tp_eventid->clear(); + m_tp_charge->clear(); + m_tp_injet->clear(); + m_tp_injet_highpt->clear(); + m_tp_injet_vhighpt->clear(); + + m_matchtrk_pt->clear(); + m_matchtrk_eta->clear(); + m_matchtrk_phi->clear(); + m_matchtrk_z0->clear(); + m_matchtrk_d0->clear(); + m_matchtrk_chi2->clear(); + m_matchtrk_chi2rphi->clear(); + m_matchtrk_chi2rz->clear(); + m_matchtrk_bendchi2->clear(); + m_matchtrk_nstub->clear(); + m_matchtrk_lhits->clear(); + m_matchtrk_dhits->clear(); + m_matchtrk_seed->clear(); + m_matchtrk_hitpattern->clear(); + m_matchtrk_injet->clear(); + m_matchtrk_injet_highpt->clear(); + m_matchtrk_injet_vhighpt->clear(); + + if (SaveStubs) { + m_allstub_x->clear(); + m_allstub_y->clear(); + m_allstub_z->clear(); + + m_allstub_isBarrel->clear(); + m_allstub_layer->clear(); + m_allstub_isPSmodule->clear(); + + m_allstub_trigDisplace->clear(); + m_allstub_trigOffset->clear(); + m_allstub_trigPos->clear(); + m_allstub_trigBend->clear(); + + m_allstub_matchTP_pdgid->clear(); + m_allstub_matchTP_pt->clear(); + m_allstub_matchTP_eta->clear(); + m_allstub_matchTP_phi->clear(); + + m_allstub_genuine->clear(); + } + + m_jet_eta->clear(); + m_jet_phi->clear(); + m_jet_pt->clear(); + m_jet_tp_sumpt->clear(); + m_jet_trk_sumpt->clear(); + m_jet_matchtrk_sumpt->clear(); + + // ----------------------------------------------------------------------------------------------- + // retrieve various containers + // ----------------------------------------------------------------------------------------------- + + // L1 tracks + edm::Handle > > TTTrackHandle; + iEvent.getByToken(ttTrackToken_, TTTrackHandle); + + // L1 stubs + edm::Handle > > TTStubHandle; + if (SaveStubs) + iEvent.getByToken(ttStubToken_, TTStubHandle); + + // MC truth association maps + edm::Handle > MCTruthTTClusterHandle; + iEvent.getByToken(ttClusterMCTruthToken_, MCTruthTTClusterHandle); + edm::Handle > MCTruthTTStubHandle; + iEvent.getByToken(ttStubMCTruthToken_, MCTruthTTStubHandle); + edm::Handle > MCTruthTTTrackHandle; + iEvent.getByToken(ttTrackMCTruthToken_, MCTruthTTTrackHandle); + + // tracking particles + edm::Handle > TrackingParticleHandle; + edm::Handle > TrackingVertexHandle; + iEvent.getByToken(TrackingParticleToken_, TrackingParticleHandle); + iEvent.getByToken(TrackingVertexToken_, TrackingVertexHandle); + + // ----------------------------------------------------------------------------------------------- + // more for TTStubs + edm::ESHandle geometryHandle; + iSetup.get().get(geometryHandle); + + edm::ESHandle tTopoHandle; + iSetup.get().get(tTopoHandle); + + edm::ESHandle tGeomHandle; + iSetup.get().get(tGeomHandle); + + const TrackerTopology* const tTopo = tTopoHandle.product(); + const TrackerGeometry* const theTrackerGeom = tGeomHandle.product(); + + // ---------------------------------------------------------------------------------------------- + // loop over L1 stubs + // ---------------------------------------------------------------------------------------------- + + if (SaveStubs) { + for (auto gd = theTrackerGeom->dets().begin(); gd != theTrackerGeom->dets().end(); gd++) { + DetId detid = (*gd)->geographicalId(); + if (detid.subdetId() != StripSubdetector::TOB && detid.subdetId() != StripSubdetector::TID) + continue; + if (!tTopo->isLower(detid)) + continue; // loop on the stacks: choose the lower arbitrarily + DetId stackDetid = tTopo->stack(detid); // Stub module detid + + if (TTStubHandle->find(stackDetid) == TTStubHandle->end()) + continue; + + // Get the DetSets of the Clusters + edmNew::DetSet > stubs = (*TTStubHandle)[stackDetid]; + const GeomDetUnit* det0 = theTrackerGeom->idToDetUnit(detid); + const auto* theGeomDet = dynamic_cast(det0); + const PixelTopology* topol = dynamic_cast(&(theGeomDet->specificTopology())); + + // loop over stubs + for (auto stubIter = stubs.begin(); stubIter != stubs.end(); ++stubIter) { + edm::Ref >, TTStub > tempStubPtr = + edmNew::makeRefTo(TTStubHandle, stubIter); + + int isBarrel = 0; + int layer = -999999; + if (detid.subdetId() == StripSubdetector::TOB) { + isBarrel = 1; + layer = static_cast(tTopo->layer(detid)); + } else if (detid.subdetId() == StripSubdetector::TID) { + isBarrel = 0; + layer = static_cast(tTopo->layer(detid)); + } else { + edm::LogVerbatim("Tracklet") << "WARNING -- neither TOB or TID stub, shouldn't happen..."; + layer = -1; + } + + int isPSmodule = 0; + if (topol->nrows() == 960) + isPSmodule = 1; + + MeasurementPoint coords = tempStubPtr->clusterRef(0)->findAverageLocalCoordinatesCentered(); + LocalPoint clustlp = topol->localPosition(coords); + GlobalPoint posStub = theGeomDet->surface().toGlobal(clustlp); + + double tmp_stub_x = posStub.x(); + double tmp_stub_y = posStub.y(); + double tmp_stub_z = posStub.z(); + + float trigDisplace = tempStubPtr->rawBend(); + float trigOffset = tempStubPtr->bendOffset(); + float trigPos = tempStubPtr->innerClusterPosition(); + float trigBend = tempStubPtr->bendFE(); + + m_allstub_x->push_back(tmp_stub_x); + m_allstub_y->push_back(tmp_stub_y); + m_allstub_z->push_back(tmp_stub_z); + + m_allstub_isBarrel->push_back(isBarrel); + m_allstub_layer->push_back(layer); + m_allstub_isPSmodule->push_back(isPSmodule); + + m_allstub_trigDisplace->push_back(trigDisplace); + m_allstub_trigOffset->push_back(trigOffset); + m_allstub_trigPos->push_back(trigPos); + m_allstub_trigBend->push_back(trigBend); + + // matched to tracking particle? + edm::Ptr my_tp = MCTruthTTStubHandle->findTrackingParticlePtr(tempStubPtr); + + int myTP_pdgid = -999; + float myTP_pt = -999; + float myTP_eta = -999; + float myTP_phi = -999; + + if (my_tp.isNull() == false) { + int tmp_eventid = my_tp->eventId().event(); + + if (tmp_eventid > 0) + continue; // this means stub from pileup track + + myTP_pdgid = my_tp->pdgId(); + myTP_pt = my_tp->p4().pt(); + myTP_eta = my_tp->p4().eta(); + myTP_phi = my_tp->p4().phi(); + } + + m_allstub_matchTP_pdgid->push_back(myTP_pdgid); + m_allstub_matchTP_pt->push_back(myTP_pt); + m_allstub_matchTP_eta->push_back(myTP_eta); + m_allstub_matchTP_phi->push_back(myTP_phi); + + int tmp_stub_genuine = 0; + if (MCTruthTTStubHandle->isGenuine(tempStubPtr)) + tmp_stub_genuine = 1; + + m_allstub_genuine->push_back(tmp_stub_genuine); + } + } + } + + // ---------------------------------------------------------------------------------------------- + // tracking in jets + // ---------------------------------------------------------------------------------------------- + + std::vector v_jets; + std::vector v_jets_highpt; + std::vector v_jets_vhighpt; + + if (TrackingInJets) { + // gen jets + if (DebugMode) + edm::LogVerbatim("Tracklet") << "get genjets"; + edm::Handle > GenJetHandle; + iEvent.getByToken(GenJetToken_, GenJetHandle); + + if (GenJetHandle.isValid()) { + if (DebugMode) + edm::LogVerbatim("Tracklet") << "loop over genjets"; + std::vector::const_iterator iterGenJet; + for (iterGenJet = GenJetHandle->begin(); iterGenJet != GenJetHandle->end(); ++iterGenJet) { + reco::GenJet myJet = reco::GenJet(*iterGenJet); + + if (myJet.pt() < 30.0) + continue; + if (std::abs(myJet.eta()) > 2.5) + continue; + + if (DebugMode) + edm::LogVerbatim("Tracklet") << "genjet pt = " << myJet.pt() << ", eta = " << myJet.eta(); + + bool ishighpt = false; + bool isveryhighpt = false; + if (myJet.pt() > 100.0) + ishighpt = true; + if (myJet.pt() > 200.0) + isveryhighpt = true; + + const math::XYZTLorentzVector& jetP4 = myJet.p4(); + v_jets.push_back(jetP4); + if (ishighpt) + v_jets_highpt.push_back(1); + else + v_jets_highpt.push_back(0); + if (isveryhighpt) + v_jets_vhighpt.push_back(1); + else + v_jets_vhighpt.push_back(0); + + } // end loop over genjets + } // end isValid + + } // end TrackingInJets + + const int NJETS = 10; + float jets_tp_sumpt[NJETS] = {0}; //sum pt of TPs with dR<0.4 of jet + float jets_matchtrk_sumpt[NJETS] = {0}; //sum pt of tracks matched to TP with dR<0.4 of jet + float jets_trk_sumpt[NJETS] = {0}; //sum pt of all tracks with dR<0.4 of jet + + // ---------------------------------------------------------------------------------------------- + // loop over L1 tracks + // ---------------------------------------------------------------------------------------------- + + if (SaveAllTracks) { + if (DebugMode) { + edm::LogVerbatim("Tracklet") << "\n Loop over L1 tracks!"; + edm::LogVerbatim("Tracklet") << "\n Looking at " << L1Tk_nPar << "-parameter tracks!"; + } + + int this_l1track = 0; + std::vector >::const_iterator iterL1Track; + for (iterL1Track = TTTrackHandle->begin(); iterL1Track != TTTrackHandle->end(); iterL1Track++) { + edm::Ptr > l1track_ptr(TTTrackHandle, this_l1track); + this_l1track++; + + float tmp_trk_pt = iterL1Track->momentum().perp(); + float tmp_trk_eta = iterL1Track->momentum().eta(); + float tmp_trk_phi = iterL1Track->momentum().phi(); + float tmp_trk_z0 = iterL1Track->z0(); //cm + + float tmp_trk_d0 = -999; + if (L1Tk_nPar == 5) { + float tmp_trk_x0 = iterL1Track->POCA().x(); + float tmp_trk_y0 = iterL1Track->POCA().y(); + tmp_trk_d0 = -tmp_trk_x0 * sin(tmp_trk_phi) + tmp_trk_y0 * cos(tmp_trk_phi); + } + + float tmp_trk_chi2 = iterL1Track->chi2(); + float tmp_trk_chi2rphi = iterL1Track->chi2XY(); + float tmp_trk_chi2rz = iterL1Track->chi2Z(); + float tmp_trk_bendchi2 = iterL1Track->stubPtConsistency(); + + std::vector >, TTStub > > + stubRefs = iterL1Track->getStubRefs(); + int tmp_trk_nstub = (int)stubRefs.size(); + + int tmp_trk_seed = 0; + tmp_trk_seed = (int)iterL1Track->trackSeedType(); + + int tmp_trk_hitpattern = 0; + tmp_trk_hitpattern = (int)iterL1Track->hitPattern(); + + unsigned int tmp_trk_phiSector = iterL1Track->phiSector(); + + // ---------------------------------------------------------------------------------------------- + // loop over stubs on tracks + + //float tmp_trk_bend_chi2 = 0; + int tmp_trk_dhits = 0; + int tmp_trk_lhits = 0; + + if (true) { + // loop over stubs + for (int is = 0; is < tmp_trk_nstub; is++) { + //detID of stub + DetId detIdStub = theTrackerGeom->idToDet((stubRefs.at(is)->clusterRef(0))->getDetId())->geographicalId(); + + MeasurementPoint coords = stubRefs.at(is)->clusterRef(0)->findAverageLocalCoordinatesCentered(); + const GeomDet* theGeomDet = theTrackerGeom->idToDet(detIdStub); + Global3DPoint posStub = theGeomDet->surface().toGlobal(theGeomDet->topology().localPosition(coords)); + + double x = posStub.x(); + double y = posStub.y(); + double z = posStub.z(); + + int layer = -999999; + if (detIdStub.subdetId() == StripSubdetector::TOB) { + layer = static_cast(tTopo->layer(detIdStub)); + if (DebugMode) + edm::LogVerbatim("Tracklet") + << " stub in layer " << layer << " at position x y z = " << x << " " << y << " " << z; + tmp_trk_lhits += pow(10, layer - 1); + } else if (detIdStub.subdetId() == StripSubdetector::TID) { + layer = static_cast(tTopo->layer(detIdStub)); + if (DebugMode) + edm::LogVerbatim("Tracklet") + << " stub in disk " << layer << " at position x y z = " << x << " " << y << " " << z; + tmp_trk_dhits += pow(10, layer - 1); + } + + } //end loop over stubs + } + // ---------------------------------------------------------------------------------------------- + + int tmp_trk_genuine = 0; + int tmp_trk_loose = 0; + int tmp_trk_unknown = 0; + int tmp_trk_combinatoric = 0; + if (MCTruthTTTrackHandle->isLooselyGenuine(l1track_ptr)) + tmp_trk_loose = 1; + if (MCTruthTTTrackHandle->isGenuine(l1track_ptr)) + tmp_trk_genuine = 1; + if (MCTruthTTTrackHandle->isUnknown(l1track_ptr)) + tmp_trk_unknown = 1; + if (MCTruthTTTrackHandle->isCombinatoric(l1track_ptr)) + tmp_trk_combinatoric = 1; + + if (DebugMode) { + edm::LogVerbatim("Tracklet") << "L1 track," + << " pt: " << tmp_trk_pt << " eta: " << tmp_trk_eta << " phi: " << tmp_trk_phi + << " z0: " << tmp_trk_z0 << " chi2: " << tmp_trk_chi2 + << " chi2rphi: " << tmp_trk_chi2rphi << " chi2rz: " << tmp_trk_chi2rz + << " nstub: " << tmp_trk_nstub; + if (tmp_trk_genuine) + edm::LogVerbatim("Tracklet") << " (is genuine)"; + if (tmp_trk_unknown) + edm::LogVerbatim("Tracklet") << " (is unknown)"; + if (tmp_trk_combinatoric) + edm::LogVerbatim("Tracklet") << " (is combinatoric)"; + } + + m_trk_pt->push_back(tmp_trk_pt); + m_trk_eta->push_back(tmp_trk_eta); + m_trk_phi->push_back(tmp_trk_phi); + m_trk_z0->push_back(tmp_trk_z0); + if (L1Tk_nPar == 5) + m_trk_d0->push_back(tmp_trk_d0); + else + m_trk_d0->push_back(999.); + m_trk_chi2->push_back(tmp_trk_chi2); + m_trk_chi2rphi->push_back(tmp_trk_chi2rphi); + m_trk_chi2rz->push_back(tmp_trk_chi2rz); + m_trk_bendchi2->push_back(tmp_trk_bendchi2); + m_trk_nstub->push_back(tmp_trk_nstub); + m_trk_dhits->push_back(tmp_trk_dhits); + m_trk_lhits->push_back(tmp_trk_lhits); + m_trk_seed->push_back(tmp_trk_seed); + m_trk_hitpattern->push_back(tmp_trk_hitpattern); + m_trk_phiSector->push_back(tmp_trk_phiSector); + m_trk_genuine->push_back(tmp_trk_genuine); + m_trk_loose->push_back(tmp_trk_loose); + m_trk_unknown->push_back(tmp_trk_unknown); + m_trk_combinatoric->push_back(tmp_trk_combinatoric); + + // ---------------------------------------------------------------------------------------------- + // for studying the fake rate + // ---------------------------------------------------------------------------------------------- + + edm::Ptr my_tp = MCTruthTTTrackHandle->findTrackingParticlePtr(l1track_ptr); + + int myFake = 0; + + int myTP_pdgid = -999; + float myTP_pt = -999; + float myTP_eta = -999; + float myTP_phi = -999; + float myTP_z0 = -999; + float myTP_dxy = -999; + + if (my_tp.isNull()) + myFake = 0; + else { + int tmp_eventid = my_tp->eventId().event(); + + if (tmp_eventid > 0) + myFake = 2; + else + myFake = 1; + + myTP_pdgid = my_tp->pdgId(); + myTP_pt = my_tp->p4().pt(); + myTP_eta = my_tp->p4().eta(); + myTP_phi = my_tp->p4().phi(); + myTP_z0 = my_tp->vertex().z(); + + float myTP_x0 = my_tp->vertex().x(); + float myTP_y0 = my_tp->vertex().y(); + myTP_dxy = sqrt(myTP_x0 * myTP_x0 + myTP_y0 * myTP_y0); + + if (DebugMode) { + edm::LogVerbatim("Tracklet") << "TP matched to track has pt = " << my_tp->p4().pt() + << " eta = " << my_tp->momentum().eta() << " phi = " << my_tp->momentum().phi() + << " z0 = " << my_tp->vertex().z() << " pdgid = " << my_tp->pdgId() + << " dxy = " << myTP_dxy; + } + } + + m_trk_fake->push_back(myFake); + + m_trk_matchtp_pdgid->push_back(myTP_pdgid); + m_trk_matchtp_pt->push_back(myTP_pt); + m_trk_matchtp_eta->push_back(myTP_eta); + m_trk_matchtp_phi->push_back(myTP_phi); + m_trk_matchtp_z0->push_back(myTP_z0); + m_trk_matchtp_dxy->push_back(myTP_dxy); + + // ---------------------------------------------------------------------------------------------- + // for tracking in jets + // ---------------------------------------------------------------------------------------------- + + if (TrackingInJets) { + if (DebugMode) + edm::LogVerbatim("Tracklet") << "doing tracking in jets now"; + + int InJet = 0; + int InJetHighpt = 0; + int InJetVeryHighpt = 0; + + for (int ij = 0; ij < (int)v_jets.size(); ij++) { + float deta = tmp_trk_eta - (v_jets.at(ij)).eta(); + float dphi = tmp_trk_phi - (v_jets.at(ij)).phi(); + while (dphi > 3.14159) + dphi = std::abs(2 * 3.14159 - dphi); + float dR = sqrt(deta * deta + dphi * dphi); + + if (dR < 0.4) { + InJet = 1; + if (v_jets_highpt.at(ij) == 1) + InJetHighpt = 1; + if (v_jets_vhighpt.at(ij) == 1) + InJetVeryHighpt = 1; + if (ij < NJETS) + jets_trk_sumpt[ij] += tmp_trk_pt; + } + } + + m_trk_injet->push_back(InJet); + m_trk_injet_highpt->push_back(InJetHighpt); + m_trk_injet_vhighpt->push_back(InJetVeryHighpt); + + } //end tracking in jets + + } //end track loop + + } //end if SaveAllTracks + + // ---------------------------------------------------------------------------------------------- + // loop over tracking particles + // ---------------------------------------------------------------------------------------------- + + if (DebugMode) + edm::LogVerbatim("Tracklet") << "\n Loop over tracking particles!"; + + int this_tp = 0; + std::vector::const_iterator iterTP; + for (iterTP = TrackingParticleHandle->begin(); iterTP != TrackingParticleHandle->end(); ++iterTP) { + edm::Ptr tp_ptr(TrackingParticleHandle, this_tp); + this_tp++; + + int tmp_eventid = iterTP->eventId().event(); + if (MyProcess != 1 && tmp_eventid > 0) + continue; //only care about tracking particles from the primary interaction (except for MyProcess==1, i.e. looking at all TPs) + + float tmp_tp_pt = iterTP->pt(); + float tmp_tp_eta = iterTP->eta(); + float tmp_tp_phi = iterTP->phi(); + float tmp_tp_vz = iterTP->vz(); + float tmp_tp_vx = iterTP->vx(); + float tmp_tp_vy = iterTP->vy(); + int tmp_tp_pdgid = iterTP->pdgId(); + float tmp_tp_z0_prod = tmp_tp_vz; + float tmp_tp_d0_prod = tmp_tp_vx * sin(tmp_tp_phi) - tmp_tp_vy * cos(tmp_tp_phi); + + if (MyProcess == 13 && abs(tmp_tp_pdgid) != 13) + continue; + if (MyProcess == 11 && abs(tmp_tp_pdgid) != 11) + continue; + if ((MyProcess == 6 || MyProcess == 15 || MyProcess == 211) && abs(tmp_tp_pdgid) != 211) + continue; + + if (tmp_tp_pt < TP_minPt) + continue; + if (std::abs(tmp_tp_eta) > TP_maxEta) + continue; + + // ---------------------------------------------------------------------------------------------- + // get d0/z0 propagated back to the IP + + float tmp_tp_t = tan(2.0 * atan(1.0) - 2.0 * atan(exp(-tmp_tp_eta))); + + float delx = -tmp_tp_vx; + float dely = -tmp_tp_vy; + + float A = 0.01 * 0.5696; + float Kmagnitude = A / tmp_tp_pt; + + float tmp_tp_charge = tp_ptr->charge(); + float K = Kmagnitude * tmp_tp_charge; + float d = 0; + + float tmp_tp_x0p = delx - (d + 1. / (2. * K) * sin(tmp_tp_phi)); + float tmp_tp_y0p = dely + (d + 1. / (2. * K) * cos(tmp_tp_phi)); + float tmp_tp_rp = sqrt(tmp_tp_x0p * tmp_tp_x0p + tmp_tp_y0p * tmp_tp_y0p); + float tmp_tp_d0 = tmp_tp_charge * tmp_tp_rp - (1. / (2. * K)); + + tmp_tp_d0 = tmp_tp_d0 * (-1); //fix d0 sign + + static double pi = 4.0 * atan(1.0); + float delphi = tmp_tp_phi - atan2(-K * tmp_tp_x0p, K * tmp_tp_y0p); + if (delphi < -pi) + delphi += 2.0 * pi; + if (delphi > pi) + delphi -= 2.0 * pi; + float tmp_tp_z0 = tmp_tp_vz + tmp_tp_t * delphi / (2.0 * K); + // ---------------------------------------------------------------------------------------------- + + if (std::abs(tmp_tp_z0) > TP_maxZ0) + continue; + + // for pions in ttbar, only consider TPs coming from near the IP! + float dxy = sqrt(tmp_tp_vx * tmp_tp_vx + tmp_tp_vy * tmp_tp_vy); + float tmp_tp_dxy = dxy; + if (MyProcess == 6 && (dxy > 1.0)) + continue; + + if (DebugMode) + edm::LogVerbatim("Tracklet") << "Tracking particle, pt: " << tmp_tp_pt << " eta: " << tmp_tp_eta + << " phi: " << tmp_tp_phi << " z0: " << tmp_tp_z0 << " d0: " << tmp_tp_d0 + << " z_prod: " << tmp_tp_z0_prod << " d_prod: " << tmp_tp_d0_prod + << " pdgid: " << tmp_tp_pdgid << " eventID: " << iterTP->eventId().event() + << " ttclusters " << MCTruthTTClusterHandle->findTTClusterRefs(tp_ptr).size() + << " ttstubs " << MCTruthTTStubHandle->findTTStubRefs(tp_ptr).size() << " tttracks " + << MCTruthTTTrackHandle->findTTTrackPtrs(tp_ptr).size(); + + // ---------------------------------------------------------------------------------------------- + // only consider TPs associated with >= 1 cluster, or >= X stubs, or have stubs in >= X layers (configurable options) + + if (MCTruthTTClusterHandle->findTTClusterRefs(tp_ptr).empty()) { + if (DebugMode) + edm::LogVerbatim("Tracklet") << "No matching TTClusters for TP, continuing..."; + continue; + } + + std::vector >, TTStub > > + theStubRefs = MCTruthTTStubHandle->findTTStubRefs(tp_ptr); + int nStubTP = (int)theStubRefs.size(); + + // how many layers/disks have stubs? + int hasStubInLayer[11] = {0}; + for (auto& theStubRef : theStubRefs) { + DetId detid(theStubRef->getDetId()); + + int layer = -1; + if (detid.subdetId() == StripSubdetector::TOB) { + layer = static_cast(tTopo->layer(detid)) - 1; //fill in array as entries 0-5 + } else if (detid.subdetId() == StripSubdetector::TID) { + layer = static_cast(tTopo->layer(detid)) + 5; //fill in array as entries 6-10 + } + + //bool isPS = (theTrackerGeom->getDetectorType(detid)==TrackerGeometry::ModuleType::Ph2PSP); + + //treat genuine stubs separately (==2 is genuine, ==1 is not) + if (MCTruthTTStubHandle->findTrackingParticlePtr(theStubRef).isNull() && hasStubInLayer[layer] < 2) + hasStubInLayer[layer] = 1; + else + hasStubInLayer[layer] = 2; + } + + int nStubLayerTP = 0; + int nStubLayerTP_g = 0; + for (int isum : hasStubInLayer) { + if (isum >= 1) + nStubLayerTP += 1; + if (isum == 2) + nStubLayerTP_g += 1; + } + + if (DebugMode) + edm::LogVerbatim("Tracklet") << "TP is associated with " << nStubTP << " stubs, and has stubs in " << nStubLayerTP + << " different layers/disks, and has GENUINE stubs in " << nStubLayerTP_g + << " layers "; + + if (TP_minNStub > 0) { + if (DebugMode) + edm::LogVerbatim("Tracklet") << "Only consider TPs with >= " << TP_minNStub << " stubs"; + if (nStubTP < TP_minNStub) { + if (DebugMode) + edm::LogVerbatim("Tracklet") << "TP fails minimum nbr stubs requirement! Continuing..."; + continue; + } + } + if (TP_minNStubLayer > 0) { + if (DebugMode) + edm::LogVerbatim("Tracklet") << "Only consider TPs with stubs in >= " << TP_minNStubLayer << " layers/disks"; + if (nStubLayerTP < TP_minNStubLayer) { + if (DebugMode) + edm::LogVerbatim("Tracklet") << "TP fails stubs in minimum nbr of layers/disks requirement! Continuing..."; + continue; + } + } + + // ---------------------------------------------------------------------------------------------- + // look for L1 tracks matched to the tracking particle + + std::vector > > matchedTracks = + MCTruthTTTrackHandle->findTTTrackPtrs(tp_ptr); + + int nMatch = 0; + int i_track = -1; + float i_chi2dof = 99999; + + if (!matchedTracks.empty()) { + if (DebugMode && (matchedTracks.size() > 1)) + edm::LogVerbatim("Tracklet") << "TrackingParticle has more than one matched L1 track!"; + + // ---------------------------------------------------------------------------------------------- + // loop over matched L1 tracks + // here, "match" means tracks that can be associated to a TrackingParticle with at least one hit of at least one of its clusters + // https://twiki.cern.ch/twiki/bin/viewauth/CMS/SLHCTrackerTriggerSWTools#MC_truth_for_TTTrack + + for (int it = 0; it < (int)matchedTracks.size(); it++) { + bool tmp_trk_genuine = false; + bool tmp_trk_loosegenuine = false; + if (MCTruthTTTrackHandle->isGenuine(matchedTracks.at(it))) + tmp_trk_genuine = true; + if (MCTruthTTTrackHandle->isLooselyGenuine(matchedTracks.at(it))) + tmp_trk_loosegenuine = true; + if (!tmp_trk_loosegenuine) + continue; + + if (DebugMode) { + if (MCTruthTTTrackHandle->findTrackingParticlePtr(matchedTracks.at(it)).isNull()) { + edm::LogVerbatim("Tracklet") << "track matched to TP is NOT uniquely matched to a TP"; + } else { + edm::Ptr my_tp = MCTruthTTTrackHandle->findTrackingParticlePtr(matchedTracks.at(it)); + edm::LogVerbatim("Tracklet") << "TP matched to track matched to TP ... tp pt = " << my_tp->p4().pt() + << " eta = " << my_tp->momentum().eta() << " phi = " << my_tp->momentum().phi() + << " z0 = " << my_tp->vertex().z(); + } + edm::LogVerbatim("Tracklet") << " ... matched L1 track has pt = " << matchedTracks.at(it)->momentum().perp() + << " eta = " << matchedTracks.at(it)->momentum().eta() + << " phi = " << matchedTracks.at(it)->momentum().phi() + << " chi2 = " << matchedTracks.at(it)->chi2() + << " consistency = " << matchedTracks.at(it)->stubPtConsistency() + << " z0 = " << matchedTracks.at(it)->z0() + << " nstub = " << matchedTracks.at(it)->getStubRefs().size(); + if (tmp_trk_genuine) + edm::LogVerbatim("Tracklet") << " (genuine!) "; + if (tmp_trk_loosegenuine) + edm::LogVerbatim("Tracklet") << " (loose genuine!) "; + } + + // ---------------------------------------------------------------------------------------------- + // further require L1 track to be (loosely) genuine, that there is only one TP matched to the track + // + have >= L1Tk_minNStub stubs for it to be a valid match (only relevant is your track collection + // e.g. stores 3-stub tracks but at plot level you require >= 4 stubs (--> tracklet case) + + std::vector >, TTStub > > + stubRefs = matchedTracks.at(it)->getStubRefs(); + int tmp_trk_nstub = stubRefs.size(); + + if (tmp_trk_nstub < L1Tk_minNStub) + continue; + + /* + // PS stubs + int tmp_trk_nPSstub = 0; + for (int is=0; isidToDet( (stubRefs.at(is)->clusterRef(0))->getDetId() )->geographicalId(); + DetId stackDetid = tTopo->stack(detIdStub); + bool isPS = (theTrackerGeom->getDetectorType(stackDetid)==TrackerGeometry::ModuleType::Ph2PSP); + if (isPS) tmp_trk_nPSstub++; + } + */ + + float dmatch_pt = 999; + float dmatch_eta = 999; + float dmatch_phi = 999; + int match_id = 999; + + edm::Ptr my_tp = MCTruthTTTrackHandle->findTrackingParticlePtr(matchedTracks.at(it)); + dmatch_pt = std::abs(my_tp->p4().pt() - tmp_tp_pt); + dmatch_eta = std::abs(my_tp->p4().eta() - tmp_tp_eta); + dmatch_phi = std::abs(my_tp->p4().phi() - tmp_tp_phi); + match_id = my_tp->pdgId(); + + float tmp_trk_chi2dof = (matchedTracks.at(it)->chi2()) / (2 * tmp_trk_nstub - L1Tk_nPar); + + // ensure that track is uniquely matched to the TP we are looking at! + if (dmatch_pt < 0.1 && dmatch_eta < 0.1 && dmatch_phi < 0.1 && tmp_tp_pdgid == match_id && tmp_trk_genuine) { + nMatch++; + if (i_track < 0 || tmp_trk_chi2dof < i_chi2dof) { + i_track = it; + i_chi2dof = tmp_trk_chi2dof; + } + } + + } // end loop over matched L1 tracks + + } // end has at least 1 matched L1 track + // ---------------------------------------------------------------------------------------------- + + float tmp_matchtrk_pt = -999; + float tmp_matchtrk_eta = -999; + float tmp_matchtrk_phi = -999; + float tmp_matchtrk_z0 = -999; + float tmp_matchtrk_d0 = -999; + float tmp_matchtrk_chi2 = -999; + float tmp_matchtrk_chi2rphi = -999; + float tmp_matchtrk_chi2rz = -999; + float tmp_matchtrk_bendchi2 = -999; + int tmp_matchtrk_nstub = -999; + int tmp_matchtrk_dhits = -999; + int tmp_matchtrk_lhits = -999; + int tmp_matchtrk_seed = -999; + int tmp_matchtrk_hitpattern = -999; + + if (nMatch > 1 && DebugMode) + edm::LogVerbatim("Tracklet") << "WARNING *** 2 or more matches to genuine L1 tracks ***"; + + if (nMatch > 0) { + tmp_matchtrk_pt = matchedTracks.at(i_track)->momentum().perp(); + tmp_matchtrk_eta = matchedTracks.at(i_track)->momentum().eta(); + tmp_matchtrk_phi = matchedTracks.at(i_track)->momentum().phi(); + tmp_matchtrk_z0 = matchedTracks.at(i_track)->z0(); + + if (L1Tk_nPar == 5) { + float tmp_matchtrk_x0 = matchedTracks.at(i_track)->POCA().x(); + float tmp_matchtrk_y0 = matchedTracks.at(i_track)->POCA().y(); + tmp_matchtrk_d0 = -tmp_matchtrk_x0 * sin(tmp_matchtrk_phi) + tmp_matchtrk_y0 * cos(tmp_matchtrk_phi); + } + + tmp_matchtrk_chi2 = matchedTracks.at(i_track)->chi2(); + tmp_matchtrk_chi2rphi = matchedTracks.at(i_track)->chi2XY(); + tmp_matchtrk_chi2rz = matchedTracks.at(i_track)->chi2Z(); + tmp_matchtrk_bendchi2 = matchedTracks.at(i_track)->stubPtConsistency(); + tmp_matchtrk_nstub = (int)matchedTracks.at(i_track)->getStubRefs().size(); + tmp_matchtrk_seed = (int)matchedTracks.at(i_track)->trackSeedType(); + tmp_matchtrk_hitpattern = (int)matchedTracks.at(i_track)->hitPattern(); + + // ------------------------------------------------------------------------------------------ + + //float tmp_matchtrk_bend_chi2 = 0; + + tmp_matchtrk_dhits = 0; + tmp_matchtrk_lhits = 0; + + std::vector >, TTStub > > + stubRefs = matchedTracks.at(i_track)->getStubRefs(); + int tmp_nstub = stubRefs.size(); + + for (int is = 0; is < tmp_nstub; is++) { + DetId detIdStub = theTrackerGeom->idToDet((stubRefs.at(is)->clusterRef(0))->getDetId())->geographicalId(); + /* + MeasurementPoint coords = stubRefs.at(is)->clusterRef(0)->findAverageLocalCoordinatesCentered(); + const GeomDet* theGeomDet = theTrackerGeom->idToDet(detIdStub); + Global3DPoint posStub = theGeomDet->surface().toGlobal( theGeomDet->topology().localPosition(coords) ); + */ + + int layer = -999999; + if (detIdStub.subdetId() == StripSubdetector::TOB) { + layer = static_cast(tTopo->layer(detIdStub)); + tmp_matchtrk_lhits += pow(10, layer - 1); + } else if (detIdStub.subdetId() == StripSubdetector::TID) { + layer = static_cast(tTopo->layer(detIdStub)); + tmp_matchtrk_dhits += pow(10, layer - 1); + } + + // ------------------------------------------------------------------------------------------ + } + } + + m_tp_pt->push_back(tmp_tp_pt); + m_tp_eta->push_back(tmp_tp_eta); + m_tp_phi->push_back(tmp_tp_phi); + m_tp_dxy->push_back(tmp_tp_dxy); + m_tp_z0->push_back(tmp_tp_z0); + m_tp_d0->push_back(tmp_tp_d0); + m_tp_z0_prod->push_back(tmp_tp_z0_prod); + m_tp_d0_prod->push_back(tmp_tp_d0_prod); + m_tp_pdgid->push_back(tmp_tp_pdgid); + m_tp_nmatch->push_back(nMatch); + m_tp_nstub->push_back(nStubTP); + m_tp_eventid->push_back(tmp_eventid); + m_tp_charge->push_back(tmp_tp_charge); + + m_matchtrk_pt->push_back(tmp_matchtrk_pt); + m_matchtrk_eta->push_back(tmp_matchtrk_eta); + m_matchtrk_phi->push_back(tmp_matchtrk_phi); + m_matchtrk_z0->push_back(tmp_matchtrk_z0); + m_matchtrk_d0->push_back(tmp_matchtrk_d0); + m_matchtrk_chi2->push_back(tmp_matchtrk_chi2); + m_matchtrk_chi2rphi->push_back(tmp_matchtrk_chi2rphi); + m_matchtrk_chi2rz->push_back(tmp_matchtrk_chi2rz); + m_matchtrk_bendchi2->push_back(tmp_matchtrk_bendchi2); + m_matchtrk_nstub->push_back(tmp_matchtrk_nstub); + m_matchtrk_dhits->push_back(tmp_matchtrk_dhits); + m_matchtrk_lhits->push_back(tmp_matchtrk_lhits); + m_matchtrk_seed->push_back(tmp_matchtrk_seed); + m_matchtrk_hitpattern->push_back(tmp_matchtrk_hitpattern); + + // ---------------------------------------------------------------------------------------------- + // for tracking in jets + // ---------------------------------------------------------------------------------------------- + + if (TrackingInJets) { + if (DebugMode) + edm::LogVerbatim("Tracklet") << "check if TP/matched track is within jet"; + + int tp_InJet = 0; + int matchtrk_InJet = 0; + int tp_InJetHighpt = 0; + int matchtrk_InJetHighpt = 0; + int tp_InJetVeryHighpt = 0; + int matchtrk_InJetVeryHighpt = 0; + + for (int ij = 0; ij < (int)v_jets.size(); ij++) { + float deta = tmp_tp_eta - (v_jets.at(ij)).eta(); + float dphi = tmp_tp_phi - (v_jets.at(ij)).phi(); + while (dphi > 3.14159) + dphi = std::abs(2 * 3.14159 - dphi); + float dR = sqrt(deta * deta + dphi * dphi); + if (dR < 0.4) { + tp_InJet = 1; + if (v_jets_highpt.at(ij) == 1) + tp_InJetHighpt = 1; + if (v_jets_vhighpt.at(ij) == 1) + tp_InJetVeryHighpt = 1; + if (ij < NJETS) + jets_tp_sumpt[ij] += tmp_tp_pt; + } + + if (nMatch > 0) { + deta = tmp_matchtrk_eta - (v_jets.at(ij)).eta(); + dphi = tmp_matchtrk_phi - (v_jets.at(ij)).phi(); + while (dphi > 3.14159) + dphi = std::abs(2 * 3.14159 - dphi); + dR = sqrt(deta * deta + dphi * dphi); + if (dR < 0.4) { + matchtrk_InJet = 1; + if (v_jets_highpt.at(ij) == 1) + matchtrk_InJetHighpt = 1; + if (v_jets_vhighpt.at(ij) == 1) + matchtrk_InJetVeryHighpt = 1; + if (ij < NJETS) + jets_matchtrk_sumpt[ij] += tmp_matchtrk_pt; + } + } + } + + m_tp_injet->push_back(tp_InJet); + m_tp_injet_highpt->push_back(tp_InJetHighpt); + m_tp_injet_vhighpt->push_back(tp_InJetVeryHighpt); + m_matchtrk_injet->push_back(matchtrk_InJet); + m_matchtrk_injet_highpt->push_back(matchtrk_InJetHighpt); + m_matchtrk_injet_vhighpt->push_back(matchtrk_InJetVeryHighpt); + + } //end TrackingInJets + + } //end loop tracking particles + + if (TrackingInJets) { + for (int ij = 0; ij < (int)v_jets.size(); ij++) { + if (ij < NJETS) { + m_jet_eta->push_back((v_jets.at(ij)).eta()); + m_jet_phi->push_back((v_jets.at(ij)).phi()); + m_jet_pt->push_back((v_jets.at(ij)).pt()); + m_jet_tp_sumpt->push_back(jets_tp_sumpt[ij]); + m_jet_trk_sumpt->push_back(jets_trk_sumpt[ij]); + m_jet_matchtrk_sumpt->push_back(jets_matchtrk_sumpt[ij]); + } + } + } + + eventTree->Fill(); + +} // end of analyze() + +/////////////////////////// +// DEFINE THIS AS A PLUG-IN +DEFINE_FWK_MODULE(L1TrackNtupleMaker); diff --git a/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py new file mode 100644 index 0000000000000..9a4cb8cbec035 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py @@ -0,0 +1,202 @@ +############################################################ +# define basic process +############################################################ + +import FWCore.ParameterSet.Config as cms +import FWCore.Utilities.FileUtils as FileUtils +import os +process = cms.Process("L1TrackNtuple") + +############################################################ +# edit options here +############################################################ + +GEOMETRY = "D49" +L1TRKALGO = 'HYBRID' # L1 tracking algorithm: 'HYBRID' (baseline, 4par fit) or 'HYBRID_DISPLACED' (extended, 5par fit) + +WRITE_DATA = False + +############################################################ +# import standard configurations +############################################################ + +process.load('Configuration.StandardSequences.Services_cff') +process.load('Configuration.EventContent.EventContent_cff') +process.load('Configuration.StandardSequences.MagneticField_cff') + +process.load('FWCore.MessageService.MessageLogger_cfi') +process.MessageLogger.categories.append('Tracklet') +process.MessageLogger.categories.append('L1track') +process.MessageLogger.Tracklet = cms.untracked.PSet(limit = cms.untracked.int32(-1)) + +if GEOMETRY == "D49": + print "using geometry " + GEOMETRY + " (tilted)" + process.load('Configuration.Geometry.GeometryExtended2026D49Reco_cff') + process.load('Configuration.Geometry.GeometryExtended2026D49_cff') +else: + print "this is not a valid geometry!!!" + +process.load('Configuration.StandardSequences.EndOfProcess_cff') +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') + +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase2_realistic', '') + + +############################################################ +# input and output +############################################################ + +process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(10)) + +# Get list of MC datasets from repo, or specify yourself. + +def getTxtFile(txtFileName): + return FileUtils.loadListFromFile(os.environ['CMSSW_BASE']+'/src/'+txtFileName) + +if GEOMETRY == "D49": + inputMC = ["/store/relval/CMSSW_11_1_0_pre2/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200-v1/20000/F7BF4AED-51F1-9D47-B86D-6C3DDA134AB9.root"] + +else: + print "this is not a valid geometry!!!" + +process.source = cms.Source("PoolSource", fileNames = cms.untracked.vstring(*inputMC)) + +process.TFileService = cms.Service("TFileService", fileName = cms.string('TTbar_PU200_'+GEOMETRY+'.root'), closeFileFast = cms.untracked.bool(True)) +process.Timing = cms.Service("Timing", summaryOnly = cms.untracked.bool(True)) + + +############################################################ +# L1 tracking: remake stubs? +############################################################ + +#process.load('L1Trigger.TrackTrigger.TrackTrigger_cff') +#from L1Trigger.TrackTrigger.TTStubAlgorithmRegister_cfi import * +#process.load("SimTracker.TrackTriggerAssociation.TrackTriggerAssociator_cff") + +#from SimTracker.TrackTriggerAssociation.TTClusterAssociation_cfi import * +#TTClusterAssociatorFromPixelDigis.digiSimLinks = cms.InputTag("simSiPixelDigis","Tracker") + +#process.TTClusterStub = cms.Path(process.TrackTriggerClustersStubs) +#process.TTClusterStubTruth = cms.Path(process.TrackTriggerAssociatorClustersStubs) + +############################################################ +# L1 tracking +############################################################ + +process.load("L1Trigger.TrackFindingTracklet.L1HybridEmulationTracks_cff") + +# HYBRID: prompt tracking +if (L1TRKALGO == 'HYBRID'): + process.TTTracksEmulation = cms.Path(process.L1HybridTracks) + process.TTTracksEmulationWithTruth = cms.Path(process.L1HybridTracksWithAssociators) + NHELIXPAR = 4 + L1TRK_NAME = "TTTracksFromTrackletEmulation" + L1TRK_LABEL = "Level1TTTracks" + +# HYBRID: extended tracking +elif (L1TRKALGO == 'HYBRID_DISPLACED'): + process.TTTracksEmulation = cms.Path(process.L1ExtendedHybridTracks) + process.TTTracksEmulationWithTruth = cms.Path(process.L1ExtendedHybridTracksWithAssociators) + NHELIXPAR = 5 + L1TRK_NAME = "TTTracksFromExtendedTrackletEmulation" + L1TRK_LABEL = "Level1TTTracks" + +# LEGACY ALGORITHM (EXPERTS ONLY): TRACKLET +elif (L1TRKALGO == 'TRACKLET'): + print "\n WARNING - this is not a recommended algorithm! Please use HYBRID (HYBRID_DISPLACED)!" + print "\n To run the tracklet-only algorithm, please ensure you have commented out #define USEHYBRID in interface/Settings.h + recompiled! \n" + process.TTTracksEmulation = cms.Path(process.L1HybridTracks) + process.TTTracksEmulationWithTruth = cms.Path(process.L1HybridTracksWithAssociators) + NHELIXPAR = 4 + L1TRK_NAME = "TTTracksFromTrackletEmulation" + L1TRK_LABEL = "Level1TTTracks" + +# LEGACY ALGORITHM (EXPERTS ONLY): TMTT +elif (L1TRKALGO == 'TMTT'): + print "\n WARNING - this is not a recommended algorithm! Please use HYBRID (HYBRID_DISPLACED)! \n" + process.load("L1Trigger.TrackFindingTMTT.TMTrackProducer_Ultimate_cff") + L1TRK_PROC = process.TMTrackProducer + L1TRK_NAME = "TMTrackProducer" + L1TRK_LABEL = "TML1TracksKF4ParamsComb" + L1TRK_PROC.EnableMCtruth = cms.bool(False) # Reduce CPU use by disabling internal histos. + L1TRK_PROC.EnableHistos = cms.bool(False) + process.load("RecoVertex.BeamSpotProducer.BeamSpot_cfi") + process.load("SimTracker.TrackTriggerAssociation.TrackTriggerAssociator_cff") + process.TTTrackAssociatorFromPixelDigis.TTTracks = cms.VInputTag( cms.InputTag(L1TRK_NAME, L1TRK_LABEL) ) + process.TTTracksEmulation = cms.Path(process.offlineBeamSpot*L1TRK_PROC) + process.TTTracksEmulationWithTruth = cms.Path(process.offlineBeamSpot*L1TRK_PROC*process.TrackTriggerAssociatorTracks) + NHELIXPAR = 4 + +else: + print "ERROR: Unknown L1TRKALGO option" + exit(1) + +############################################################ +# Define the track ntuple process, MyProcess is the (unsigned) PDGID corresponding to the process which is run +# e.g. single electron/positron = 11 +# single pion+/pion- = 211 +# single muon+/muon- = 13 +# pions in jets = 6 +# taus = 15 +# all TPs = 1 +############################################################ + +process.L1TrackNtuple = cms.EDAnalyzer('L1TrackNtupleMaker', + MyProcess = cms.int32(1), + DebugMode = cms.bool(False), # printout lots of debug statements + SaveAllTracks = cms.bool(True), # save *all* L1 tracks, not just truth matched to primary particle + SaveStubs = cms.bool(False), # save some info for *all* stubs + L1Tk_nPar = cms.int32(NHELIXPAR), # use 4 or 5-parameter L1 tracking? + L1Tk_minNStub = cms.int32(4), # L1 tracks with >= 4 stubs + TP_minNStub = cms.int32(4), # require TP to have >= X number of stubs associated with it + TP_minNStubLayer = cms.int32(4), # require TP to have stubs in >= X layers/disks + TP_minPt = cms.double(2.0), # only save TPs with pt > X GeV + TP_maxEta = cms.double(2.5), # only save TPs with |eta| < X + TP_maxZ0 = cms.double(30.0), # only save TPs with |z0| < X cm + L1TrackInputTag = cms.InputTag(L1TRK_NAME, L1TRK_LABEL), # TTTrack input + MCTruthTrackInputTag = cms.InputTag("TTTrackAssociatorFromPixelDigis", L1TRK_LABEL), ## MCTruth input + # other input collections + L1StubInputTag = cms.InputTag("TTStubsFromPhase2TrackerDigis","StubAccepted"), + MCTruthClusterInputTag = cms.InputTag("TTClusterAssociatorFromPixelDigis", "ClusterAccepted"), + MCTruthStubInputTag = cms.InputTag("TTStubAssociatorFromPixelDigis", "StubAccepted"), + TrackingParticleInputTag = cms.InputTag("mix", "MergedTrackTruth"), + TrackingVertexInputTag = cms.InputTag("mix", "MergedTrackTruth"), + ## tracking in jets stuff (--> requires AK4 genjet collection present!) + TrackingInJets = cms.bool(False), + GenJetInputTag = cms.InputTag("ak4GenJets", ""), + ) + +process.ana = cms.Path(process.L1TrackNtuple) + +# use this if you want to re-run the stub making +# process.schedule = cms.Schedule(process.TTClusterStub,process.TTClusterStubTruth,process.TTTracksEmulationWithTruth,process.ana) + +# use this if cluster/stub associators not available +# process.schedule = cms.Schedule(process.TTClusterStubTruth,process.TTTracksEmulationWithTruth,process.ana) + +# use this to only run tracking + track associator +process.schedule = cms.Schedule(process.TTTracksEmulationWithTruth,process.ana) + + +############################################################ +# write output dataset? +############################################################ + +if (WRITE_DATA): + process.writeDataset = cms.OutputModule("PoolOutputModule", + splitLevel = cms.untracked.int32(0), + eventAutoFlushCompressedSize = cms.untracked.int32(5242880), + outputCommands = process.RAWSIMEventContent.outputCommands, + fileName = cms.untracked.string('output_dataset.root'), ## ADAPT IT ## + dataset = cms.untracked.PSet( + filterName = cms.untracked.string(''), + dataTier = cms.untracked.string('GEN-SIM') + ) + ) + process.writeDataset.outputCommands.append('keep *TTTrack*_*_*_*') + process.writeDataset.outputCommands.append('keep *TTStub*_*_*_*') + + process.pd = cms.EndPath(process.writeDataset) + process.schedule.append(process.pd) + diff --git a/L1Trigger/TrackFindingTracklet/test/L1TrackNtuplePlot.C b/L1Trigger/TrackFindingTracklet/test/L1TrackNtuplePlot.C new file mode 100644 index 0000000000000..b3ab4660b0bd4 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/test/L1TrackNtuplePlot.C @@ -0,0 +1,3747 @@ +// ---------------------------------------------------------------------------------------------------------------- +// Basic example ROOT script for making tracking performance plots using the ntuples produced by L1TrackNtupleMaker.cc +// +// e.g. in ROOT do: .L L1TrackNtuplePlot.C++, L1TrackNtuplePlot("TTbar_PU200_hybrid") +// +// By Louise Skinnari, June 2013 +// ---------------------------------------------------------------------------------------------------------------- + +#include "TROOT.h" +#include "TStyle.h" +#include "TLatex.h" +#include "TFile.h" +#include "TTree.h" +#include "TChain.h" +#include "TBranch.h" +#include "TLeaf.h" +#include "TCanvas.h" +#include "TLegend.h" +#include "TH1.h" +#include "TH2.h" +#include "TF1.h" +#include "TProfile.h" +#include "TProfile2D.h" +#include "TMath.h" +#include + +#include +#include +#include +#include + +using namespace std; + +void SetPlotStyle(); +void mySmallText(Double_t x, Double_t y, Color_t color, char* text); + +double getIntervalContainingFractionOfEntries(TH1* histogram, double interval, int minEntries = 5); +void makeResidualIntervalPlot( + TString type, TString dir, TString variable, TH1F* h_68, TH1F* h_90, TH1F* h_99, double minY, double maxY); + +// ---------------------------------------------------------------------------------------------------------------- +// Main script +// ---------------------------------------------------------------------------------------------------------------- + +void L1TrackNtuplePlot(TString type, + TString type_dir = "", + TString treeName = "", + int TP_select_injet = 0, + int TP_select_pdgid = 0, + int TP_select_eventid = 0, + bool useTightCuts = false, + bool useDeadRegion = false, + float TP_minPt = 2.0, + float TP_maxPt = 100.0, + float TP_maxEta = 2.4, + float TP_maxDxy = 1.0, + float TP_maxD0 = 1.0, + bool doDetailedPlots = false) { + // type: this is the name of the input file you want to process (minus ".root" extension) + // type_dir: this is the directory containing the input file you want to process. Note that this must end with a "/", as in "EventSets/" + // TP_select_pdgid: if non-zero, only select TPs with a given PDG ID + // TP_select_eventid: if zero, only look at TPs from primary interaction, else, include TPs from pileup + // TP_minPt: only look at TPs with pt > X GeV + // TP_maxPt: only look at TPs with pt < X GeV + // TP_maxEta: only look at TPs with |eta| < X + // doDetailedPlots: includes extra plots, such as performance vs d0. + + // TP_select_injet: only look at TPs that are within a jet with pt > 30 GeV (==1) or within a jet with pt > 100 GeV (==2), >200 GeV (==3) or all TPs (==0) + + //-- N.B. For standard displaced tracking plots, set TP_minPt=3.0, TP_maxEta=2.0, TP_maxDxy=10.0, + //-- TO_maxD0=10.0, doDetailedPlots=true. (Efficiency plots vs eta also usually made for d0 < 5). + + gROOT->SetBatch(); + gErrorIgnoreLevel = kWarning; + + SetPlotStyle(); + + // ---------------------------------------------------------------------------------------------------------------- + // define input options + + // these are the LOOSE cuts, baseline scenario for efficiency and rate plots ==> configure as appropriate + int L1Tk_minNstub = 4; + float L1Tk_maxChi2 = 999999; + float L1Tk_maxChi2dof = 999999.; + + // TIGHT cuts (separate plots / rates) ==> configure as appropriate + // this is currently set up as an either or for performance plots, to not duplicate a ton of code. + int L1Tk_TIGHT_minNstub = 4; + float L1Tk_TIGHT_maxChi2 = 999999; + float L1Tk_TIGHT_maxChi2dof = 999999.; + if (useTightCuts) { + L1Tk_minNstub = L1Tk_TIGHT_minNstub; + L1Tk_maxChi2 = L1Tk_TIGHT_maxChi2; + L1Tk_maxChi2dof = L1Tk_TIGHT_maxChi2dof; + } + + bool doGausFit = false; //do gaussian fit for resolution vs eta/pt plots + bool doLooseMatch = false; //looser MC truth matching + + // tracklet variables + int L1Tk_seed = 0; + + //some counters for integrated efficiencies + int n_all_eta2p5 = 0; + int n_all_eta1p75 = 0; + int n_all_eta1p0 = 0; + int n_match_eta2p5 = 0; + int n_match_eta1p75 = 0; + int n_match_eta1p0 = 0; + int n_all_ptg2 = 0; + int n_all_ptg8 = 0; + int n_all_pt2to8 = 0; + int n_all_ptg40 = 0; + int n_match_ptg2 = 0; + int n_match_ptg8 = 0; + int n_match_pt2to8 = 0; + int n_match_ptg40 = 0; + + // counters for total track rates + int ntrk_pt2 = 0; + int ntrk_pt3 = 0; + int ntrk_pt10 = 0; + int ntp_pt2 = 0; + int ntp_pt3 = 0; + int ntp_pt10 = 0; + + // ---------------------------------------------------------------------------------------------------------------- + // read ntuples + TChain* tree = new TChain("L1TrackNtuple" + treeName + "/eventTree"); + tree->Add(type_dir + type + ".root"); + + if (tree->GetEntries() == 0) { + cout << "File doesn't exist or is empty, returning..." + << endl; //cout's kept in this file as it is an example standalone plotting script, not running in central CMSSW + return; + } + + // ---------------------------------------------------------------------------------------------------------------- + // define leafs & branches + + // tracking particles + vector* tp_pt; + vector* tp_eta; + vector* tp_phi; + vector* tp_dxy; + vector* tp_z0; + vector* tp_d0; + vector* tp_pdgid; + vector* tp_nmatch; + vector* tp_nstub; + vector* tp_eventid; + vector* tp_injet; + vector* tp_injet_highpt; + vector* tp_injet_vhighpt; + + // *L1 track* properties, for tracking particles matched to a L1 track + vector* matchtrk_pt; + vector* matchtrk_eta; + vector* matchtrk_phi; + vector* matchtrk_d0; + vector* matchtrk_z0; + vector* matchtrk_chi2; + vector* matchtrk_chi2rphi; + vector* matchtrk_chi2rz; + vector* matchtrk_nstub; + vector* matchtrk_lhits; + vector* matchtrk_dhits; + vector* matchtrk_seed; + vector* matchtrk_hitpattern; + vector* matchtrk_injet; + vector* matchtrk_injet_highpt; + vector* matchtrk_injet_vhighpt; + + // all L1 tracks + vector* trk_pt; + vector* trk_eta; + vector* trk_phi; + vector* trk_chi2; + vector* trk_chi2rphi; + vector* trk_chi2rz; + vector* trk_nstub; + vector* trk_lhits; + vector* trk_dhits; + vector* trk_seed; + vector* trk_hitpattern; + vector* trk_phiSector; + vector* trk_injet; + vector* trk_injet_highpt; + vector* trk_injet_vhighpt; + vector* trk_fake; + vector* trk_genuine; + vector* trk_loose; + + TBranch* b_tp_pt; + TBranch* b_tp_eta; + TBranch* b_tp_phi; + TBranch* b_tp_dxy; + TBranch* b_tp_z0; + TBranch* b_tp_d0; + TBranch* b_tp_pdgid; + TBranch* b_tp_nmatch; + TBranch* b_tp_nstub; + TBranch* b_tp_eventid; + TBranch* b_tp_injet; + TBranch* b_tp_injet_highpt; + TBranch* b_tp_injet_vhighpt; + + TBranch* b_matchtrk_pt; + TBranch* b_matchtrk_eta; + TBranch* b_matchtrk_phi; + TBranch* b_matchtrk_d0; + TBranch* b_matchtrk_z0; + TBranch* b_matchtrk_chi2; + TBranch* b_matchtrk_chi2rphi; + TBranch* b_matchtrk_chi2rz; + TBranch* b_matchtrk_nstub; + TBranch* b_matchtrk_lhits; + TBranch* b_matchtrk_dhits; + TBranch* b_matchtrk_seed; + TBranch* b_matchtrk_hitpattern; + TBranch* b_matchtrk_injet; + TBranch* b_matchtrk_injet_highpt; + TBranch* b_matchtrk_injet_vhighpt; + + TBranch* b_trk_pt; + TBranch* b_trk_eta; + TBranch* b_trk_phi; + TBranch* b_trk_chi2; + TBranch* b_trk_chi2rphi; + TBranch* b_trk_chi2rz; + TBranch* b_trk_nstub; + TBranch* b_trk_lhits; + TBranch* b_trk_dhits; + TBranch* b_trk_phiSector; + TBranch* b_trk_seed; + TBranch* b_trk_hitpattern; + TBranch* b_trk_injet; + TBranch* b_trk_injet_highpt; + TBranch* b_trk_injet_vhighpt; + TBranch* b_trk_fake; + TBranch* b_trk_genuine; + TBranch* b_trk_loose; + + tp_pt = 0; + tp_eta = 0; + tp_phi = 0; + tp_dxy = 0; + tp_z0 = 0; + tp_d0 = 0; + tp_pdgid = 0; + tp_nmatch = 0; + tp_nstub = 0; + tp_eventid = 0; + tp_injet = 0; + tp_injet_highpt = 0; + tp_injet_vhighpt = 0; + + matchtrk_pt = 0; + matchtrk_eta = 0; + matchtrk_phi = 0; + matchtrk_d0 = 0; + matchtrk_z0 = 0; + matchtrk_chi2 = 0; + matchtrk_chi2rphi = 0; + matchtrk_chi2rz = 0; + matchtrk_nstub = 0; + matchtrk_lhits = 0; + matchtrk_dhits = 0; + matchtrk_seed = 0; + matchtrk_hitpattern = 0; + matchtrk_injet = 0; + matchtrk_injet_highpt = 0; + matchtrk_injet_vhighpt = 0; + + trk_pt = 0; + trk_eta = 0; + trk_phi = 0; + trk_chi2 = 0; + trk_chi2rphi = 0; + trk_chi2rz = 0; + trk_nstub = 0; + trk_lhits = 0; + trk_dhits = 0; + trk_phiSector = 0; + trk_seed = 0; + trk_hitpattern = 0; + trk_injet = 0; + trk_injet_highpt = 0; + trk_injet_vhighpt = 0; + trk_fake = 0; + trk_genuine = 0; + trk_loose = 0; + + tree->SetBranchAddress("tp_pt", &tp_pt, &b_tp_pt); + tree->SetBranchAddress("tp_eta", &tp_eta, &b_tp_eta); + tree->SetBranchAddress("tp_phi", &tp_phi, &b_tp_phi); + tree->SetBranchAddress("tp_dxy", &tp_dxy, &b_tp_dxy); + tree->SetBranchAddress("tp_z0", &tp_z0, &b_tp_z0); + tree->SetBranchAddress("tp_d0", &tp_d0, &b_tp_d0); + tree->SetBranchAddress("tp_pdgid", &tp_pdgid, &b_tp_pdgid); + if (doLooseMatch) + tree->SetBranchAddress("tp_nloosematch", &tp_nmatch, &b_tp_nmatch); + else + tree->SetBranchAddress("tp_nmatch", &tp_nmatch, &b_tp_nmatch); + tree->SetBranchAddress("tp_nstub", &tp_nstub, &b_tp_nstub); + tree->SetBranchAddress("tp_eventid", &tp_eventid, &b_tp_eventid); + if (TP_select_injet > 0) { + tree->SetBranchAddress("tp_injet", &tp_injet, &b_tp_injet); + tree->SetBranchAddress("tp_injet_highpt", &tp_injet_highpt, &b_tp_injet_highpt); + tree->SetBranchAddress("tp_injet_vhighpt", &tp_injet_vhighpt, &b_tp_injet_vhighpt); + } + + if (doLooseMatch) { + tree->SetBranchAddress("loosematchtrk_pt", &matchtrk_pt, &b_matchtrk_pt); + tree->SetBranchAddress("loosematchtrk_eta", &matchtrk_eta, &b_matchtrk_eta); + tree->SetBranchAddress("loosematchtrk_phi", &matchtrk_phi, &b_matchtrk_phi); + tree->SetBranchAddress("loosematchtrk_d0", &matchtrk_d0, &b_matchtrk_d0); + tree->SetBranchAddress("loosematchtrk_z0", &matchtrk_z0, &b_matchtrk_z0); + tree->SetBranchAddress("loosematchtrk_chi2", &matchtrk_chi2, &b_matchtrk_chi2); + tree->SetBranchAddress("loosematchtrk_chi2rphi", &matchtrk_chi2rphi, &b_matchtrk_chi2rphi); + tree->SetBranchAddress("loosematchtrk_chi2rz", &matchtrk_chi2rz, &b_matchtrk_chi2rz); + tree->SetBranchAddress("loosematchtrk_nstub", &matchtrk_nstub, &b_matchtrk_nstub); + tree->SetBranchAddress("loosematchtrk_seed", &matchtrk_seed, &b_matchtrk_seed); + tree->SetBranchAddress("loosematchtrk_hitpattern", &matchtrk_hitpattern, &b_matchtrk_hitpattern); + if (TP_select_injet > 0) { + tree->SetBranchAddress("loosematchtrk_injet", &matchtrk_injet, &b_matchtrk_injet); + tree->SetBranchAddress("loosematchtrk_injet_highpt", &matchtrk_injet_highpt, &b_matchtrk_injet_highpt); + tree->SetBranchAddress("loosematchtrk_injet_vhighpt", &matchtrk_injet_vhighpt, &b_matchtrk_injet_vhighpt); + } + } else { + tree->SetBranchAddress("matchtrk_pt", &matchtrk_pt, &b_matchtrk_pt); + tree->SetBranchAddress("matchtrk_eta", &matchtrk_eta, &b_matchtrk_eta); + tree->SetBranchAddress("matchtrk_phi", &matchtrk_phi, &b_matchtrk_phi); + tree->SetBranchAddress("matchtrk_d0", &matchtrk_d0, &b_matchtrk_d0); + tree->SetBranchAddress("matchtrk_z0", &matchtrk_z0, &b_matchtrk_z0); + tree->SetBranchAddress("matchtrk_chi2", &matchtrk_chi2, &b_matchtrk_chi2); + tree->SetBranchAddress("matchtrk_chi2rphi", &matchtrk_chi2rphi, &b_matchtrk_chi2rphi); + tree->SetBranchAddress("matchtrk_chi2rz", &matchtrk_chi2rz, &b_matchtrk_chi2rz); + tree->SetBranchAddress("matchtrk_nstub", &matchtrk_nstub, &b_matchtrk_nstub); + tree->SetBranchAddress("matchtrk_lhits", &matchtrk_lhits, &b_matchtrk_lhits); + tree->SetBranchAddress("matchtrk_dhits", &matchtrk_dhits, &b_matchtrk_dhits); + tree->SetBranchAddress("matchtrk_seed", &matchtrk_seed, &b_matchtrk_seed); + tree->SetBranchAddress("matchtrk_hitpattern", &matchtrk_hitpattern, &b_matchtrk_hitpattern); + if (TP_select_injet > 0) { + tree->SetBranchAddress("matchtrk_injet", &matchtrk_injet, &b_matchtrk_injet); + tree->SetBranchAddress("matchtrk_injet_highpt", &matchtrk_injet_highpt, &b_matchtrk_injet_highpt); + tree->SetBranchAddress("matchtrk_injet_vhighpt", &matchtrk_injet_vhighpt, &b_matchtrk_injet_vhighpt); + } + } + + tree->SetBranchAddress("trk_pt", &trk_pt, &b_trk_pt); + tree->SetBranchAddress("trk_eta", &trk_eta, &b_trk_eta); + tree->SetBranchAddress("trk_phi", &trk_phi, &b_trk_phi); + tree->SetBranchAddress("trk_chi2", &trk_chi2, &b_trk_chi2); + tree->SetBranchAddress("trk_chi2rphi", &trk_chi2rphi, &b_trk_chi2rphi); + tree->SetBranchAddress("trk_chi2rz", &trk_chi2rz, &b_trk_chi2rz); + tree->SetBranchAddress("trk_nstub", &trk_nstub, &b_trk_nstub); + tree->SetBranchAddress("trk_lhits", &trk_lhits, &b_trk_lhits); + tree->SetBranchAddress("trk_dhits", &trk_dhits, &b_trk_dhits); + tree->SetBranchAddress("trk_phiSector", &trk_phiSector, &b_trk_phiSector); + tree->SetBranchAddress("trk_seed", &trk_seed, &b_trk_seed); + tree->SetBranchAddress("trk_hitpattern", &trk_hitpattern, &b_trk_hitpattern); + tree->SetBranchAddress("trk_fake", &trk_fake, &b_trk_fake); + tree->SetBranchAddress("trk_genuine", &trk_genuine, &b_trk_genuine); + tree->SetBranchAddress("trk_loose", &trk_loose, &b_trk_loose); + if (TP_select_injet > 0) { + tree->SetBranchAddress("trk_injet", &trk_injet, &b_trk_injet); + tree->SetBranchAddress("trk_injet_highpt", &trk_injet_highpt, &b_trk_injet_highpt); + tree->SetBranchAddress("trk_injet_vhighpt", &trk_injet_vhighpt, &b_trk_injet_vhighpt); + } + + // ---------------------------------------------------------------------------------------------------------------- + // histograms + // ---------------------------------------------------------------------------------------------------------------- + + ///////////////////////////////////////////////// + // NOTATION: // + // 'C' - Central eta range, |eta|<0.8 // + // 'I' - Intermediate eta range, 0.8<|eta|<1.6 // + // 'F' - Forward eta range, |eta|>1.6 // + // // + // 'L' - Low pt range, pt<8 GeV // + // 'H' - High pt range, pt>8 GeV // + ///////////////////////////////////////////////// + + // ---------------------------------------------------------------------------------------------------------------- + // for efficiencies + + TH1F* h_tp_pt = new TH1F("tp_pt", ";Tracking particle p_{T} [GeV]; Tracking particles / 1.0 GeV", 100, 0, 100.0); + TH1F* h_tp_pt_L = new TH1F("tp_pt_L", ";Tracking particle p_{T} [GeV]; Tracking particles / 0.1 GeV", 80, 0, 8.0); + TH1F* h_tp_pt_LC = new TH1F("tp_pt_LC", ";Tracking particle p_{T} [GeV]; Tracking particles / 0.1 GeV", 80, 0, 8.0); + TH1F* h_tp_pt_H = new TH1F("tp_pt_H", ";Tracking particle p_{T} [GeV]; Tracking particles / 1.0 GeV", 92, 8.0, 100.0); + TH1F* h_tp_eta = new TH1F("tp_eta", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5); + TH1F* h_tp_eta_L = new TH1F("tp_eta_L", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5); + TH1F* h_tp_eta_H = new TH1F("tp_eta_H", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5); + TH1F* h_tp_eta_23 = new TH1F("tp_eta_23", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5); + TH1F* h_tp_eta_35 = new TH1F("tp_eta_35", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5); + TH1F* h_tp_eta_5 = new TH1F("tp_eta_5", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5); + + TH1F* h_match_tp_pt = + new TH1F("match_tp_pt", ";Tracking particle p_{T} [GeV]; Tracking particles / 1.0 GeV", 100, 0, 100.0); + TH1F* h_match_tp_pt_L = + new TH1F("match_tp_pt_L", ";Tracking particle p_{T} [GeV]; Tracking particles / 0.1 GeV", 80, 0, 8.0); + TH1F* h_match_tp_pt_LC = + new TH1F("match_tp_pt_LC", ";Tracking particle p_{T} [GeV]; Tracking particles / 0.1 GeV", 80, 0, 8.0); + TH1F* h_match_tp_pt_H = + new TH1F("match_tp_pt_H", ";Tracking particle p_{T} [GeV]; Tracking particles / 0.1 GeV", 92, 8.0, 100.0); + TH1F* h_match_tp_eta = new TH1F("match_tp_eta", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5); + TH1F* h_match_tp_eta_L = + new TH1F("match_tp_eta_L", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5); + TH1F* h_match_tp_eta_H = + new TH1F("match_tp_eta_H", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5); + TH1F* h_match_tp_eta_23 = + new TH1F("match_tp_eta_23", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5); + TH1F* h_match_tp_eta_35 = + new TH1F("match_tp_eta_35", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5); + TH1F* h_match_tp_eta_5 = + new TH1F("match_tp_eta_5", ";Tracking particle #eta; Tracking particles / 0.1", 50, -2.5, 2.5); + + // ---------------------------------------------------------------------------------------------------------------- + // Tracklet propogation efficiencies vs. eta for seeding layers + + int trackletEffEtaBins = 24; + double trackletEffMaxEta = 2.4; + int numLayers = 11; + TH2F* h_trk_tracklet_hits = new TH2F("trk_tracklet_hits", + ";Track |#eta|; Layer index (0-5 = L1-6, 6-10 = D1-5)", + trackletEffEtaBins, + 0, + trackletEffMaxEta, + 11, + 0, + 11); //used to create below hist + TH2F* h_trk_tracklet_eff = new TH2F("trk_tracklet_eff", + ";Track |#eta|; Layer index (0-5 = L1-6, 6-10 = D1-5)", + trackletEffEtaBins, + 0, + trackletEffMaxEta, + 11, + 0, + 11); + + // ---------------------------------------------------------------------------------------------------------------- + // resolution vs. pt histograms + + // ---------------------------------------------- + // for new versions of resolution vs pt/eta plots + unsigned int nBinsPtRes = 500; + double maxPtRes = 30.; + + unsigned int nBinsPtRelRes = 1000; + double maxPtRelRes = 10.; + + unsigned int nBinsEtaRes = 500; + double maxEtaRes = 0.1; + + unsigned int nBinsPhiRes = 500; + double maxPhiRes = 0.2; + + unsigned int nBinsZ0Res = 100; + double maxZ0Res = 4.0; + // ---------------------------------------------- + + const int nRANGE = 20; + TString ptrange[nRANGE] = {"0-5", "5-10", "10-15", "15-20", "20-25", "25-30", "30-35", "35-40", "40-45", "45-50", + "50-55", "55-60", "60-65", "65-70", "70-75", "75-80", "80-85", "85-90", "90-95", "95-100"}; + + const int nRANGE_L = 12; + TString ptrange_L[nRANGE] = { + "2-2.5", "2.5-3", "3-3.5", "3.5-4", "4-4.5", "4.5-5", "5-5.5", "5.5-6", "6-6.5", "6.5-7", "7-7.5", "7.5-8"}; + + TH1F* h_absResVsPt_pt[nRANGE]; + TH1F* h_absResVsPt_ptRel[nRANGE]; + TH1F* h_absResVsPt_z0[nRANGE]; + TH1F* h_absResVsPt_phi[nRANGE]; + TH1F* h_absResVsPt_eta[nRANGE]; + TH1F* h_absResVsPt_d0[nRANGE]; + + TH1F* h_absResVsPt_pt_L[nRANGE_L]; + TH1F* h_absResVsPt_ptRel_L[nRANGE_L]; + TH1F* h_absResVsPt_z0_L[nRANGE_L]; + TH1F* h_absResVsPt_phi_L[nRANGE_L]; + TH1F* h_absResVsPt_eta_L[nRANGE_L]; + TH1F* h_absResVsPt_d0_L[nRANGE_L]; + + for (int i = 0; i < nRANGE; i++) { + h_absResVsPt_pt[i] = new TH1F( + "absResVsPt_pt_" + ptrange[i], ";p_{T} residual (L1 - sim) [GeV]; L1 tracks / 0.1", nBinsPtRes, 0, maxPtRes); + h_absResVsPt_ptRel[i] = new TH1F("absResVsPt_ptRel_" + ptrange[i], + ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02", + nBinsPtRelRes, + 0, + maxPtRelRes); + h_absResVsPt_z0[i] = new TH1F( + "absResVsPt_z0_" + ptrange[i], ";z_{0} residual (L1 - sim) [GeV]; L1 tracks / 0.1", nBinsZ0Res, 0, maxZ0Res); + h_absResVsPt_phi[i] = new TH1F( + "absResVsPt_phi_" + ptrange[i], ";#phi residual (L1 - sim) [GeV]; L1 tracks / 0.1", nBinsPhiRes, 0, maxPhiRes); + h_absResVsPt_eta[i] = new TH1F( + "absResVsPt_eta_" + ptrange[i], ";#eta residual (L1 - sim) [GeV]; L1 tracks / 0.1", nBinsEtaRes, 0, maxEtaRes); + h_absResVsPt_d0[i] = + new TH1F("absResVsPt_d0_" + ptrange[i], ";d_{0}residual (L1 - sim) [GeV]; L1 tracks / 0.1", 100, 0, 0.02); + } + + for (int i = 0; i < nRANGE_L; i++) { + h_absResVsPt_pt_L[i] = new TH1F( + "absResVsPt_L_pt_" + ptrange_L[i], ";p_{T} residual (L1 - sim) [GeV]; L1 tracks / 0.1", nBinsPtRes, 0, maxPtRes); + h_absResVsPt_ptRel_L[i] = new TH1F("absResVsPt_L_ptRel_" + ptrange_L[i], + ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02", + nBinsPtRelRes, + 0, + maxPtRelRes); + h_absResVsPt_z0_L[i] = new TH1F( + "absResVsPt_L_z0_" + ptrange_L[i], ";z_{0} residual (L1 - sim) [GeV]; L1 tracks / 0.1", nBinsZ0Res, 0, maxZ0Res); + h_absResVsPt_phi_L[i] = new TH1F("absResVsPt_L_phi_" + ptrange_L[i], + ";#phi residual (L1 - sim) [GeV]; L1 tracks / 0.1", + nBinsPhiRes, + 0, + maxPhiRes); + h_absResVsPt_eta_L[i] = new TH1F("absResVsPt_L_eta_" + ptrange_L[i], + ";#eta residual (L1 - sim) [GeV]; L1 tracks / 0.1", + nBinsEtaRes, + 0, + maxEtaRes); + h_absResVsPt_d0_L[i] = + new TH1F("absResVsPt_L_d0_" + ptrange_L[i], ";d_{0}residual (L1 - sim) [GeV]; L1 tracks / 0.1", 100, 0, 0.02); + } + + // resolution vs. eta histograms + + const int nETARANGE = 24; + TString etarange[nETARANGE] = {"0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9", "1.0", "1.1", "1.2", + "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2.0", "2.1", "2.2", "2.3", "2.4"}; + /* + const int nETARANGE = 12; + TString etarange[nETARANGE] = {"0.2","0.4","0.6","0.8","1.0", + "1.2","1.4","1.6","1.8","2.0", + "2.2","2.4"}; + */ + + TH1F* h_absResVsEta_eta[nETARANGE]; + TH1F* h_absResVsEta_z0[nETARANGE]; + TH1F* h_absResVsEta_phi[nETARANGE]; + TH1F* h_absResVsEta_ptRel[nETARANGE]; + TH1F* h_absResVsEta_d0[nETARANGE]; + + TH1F* h_absResVsEta_eta_L[nETARANGE]; + TH1F* h_absResVsEta_z0_L[nETARANGE]; + TH1F* h_absResVsEta_phi_L[nETARANGE]; + TH1F* h_absResVsEta_ptRel_L[nETARANGE]; + TH1F* h_absResVsEta_d0_L[nETARANGE]; + + TH1F* h_absResVsEta_eta_H[nETARANGE]; + TH1F* h_absResVsEta_z0_H[nETARANGE]; + TH1F* h_absResVsEta_phi_H[nETARANGE]; + TH1F* h_absResVsEta_ptRel_H[nETARANGE]; + TH1F* h_absResVsEta_d0_H[nETARANGE]; + + for (int i = 0; i < nETARANGE; i++) { + h_absResVsEta_eta[i] = new TH1F( + "absResVsEta_eta_" + etarange[i], ";#eta residual (L1 - sim) [GeV]; L1 tracks / 0.1", nBinsEtaRes, 0, maxEtaRes); + h_absResVsEta_z0[i] = new TH1F( + "absResVsEta_z0_" + etarange[i], ";|z_{0} residual (L1 - sim)| [cm]; L1 tracks / 0.01", nBinsZ0Res, 0, maxZ0Res); + h_absResVsEta_phi[i] = new TH1F( + "absResVsEta_phi_" + etarange[i], ";#phi residual (L1 - sim) [GeV]; L1 tracks / 0.1", nBinsPhiRes, 0, maxPhiRes); + h_absResVsEta_ptRel[i] = new TH1F("absResVsEta_ptRel_" + etarange[i], + ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02", + nBinsPtRelRes, + 0, + maxPtRelRes); + h_absResVsEta_d0[i] = + new TH1F("absResVsEta_d0_" + etarange[i], ";d_{0}residual (L1 - sim) [GeV]; L1 tracks / 0.1", 100, 0, 0.02); + + h_absResVsEta_eta_L[i] = new TH1F("absResVsEta_eta_L_" + etarange[i], + ";#eta residual (L1 - sim) [GeV]; L1 tracks / 0.1", + nBinsEtaRes, + 0, + maxEtaRes); + h_absResVsEta_z0_L[i] = new TH1F("absResVsEta_z0_L_" + etarange[i], + ";|z_{0} residual (L1 - sim)| [cm]; L1 tracks / 0.01", + nBinsZ0Res, + 0, + maxZ0Res); + h_absResVsEta_phi_L[i] = new TH1F("absResVsEta_phi_L_" + etarange[i], + ";#phi residual (L1 - sim) [GeV]; L1 tracks / 0.1", + nBinsPhiRes, + 0, + maxPhiRes); + h_absResVsEta_ptRel_L[i] = new TH1F("absResVsEta_ptRel_L_" + etarange[i], + ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02", + nBinsPtRelRes, + 0, + maxPtRelRes); + h_absResVsEta_d0_L[i] = + new TH1F("absResVsEta_d0_L_" + etarange[i], ";d_{0}residual (L1 - sim) [GeV]; L1 tracks / 0.1", 100, 0, 0.02); + + h_absResVsEta_eta_H[i] = new TH1F("absResVsEta_eta_H_" + etarange[i], + ";#eta residual (L1 - sim) [GeV]; L1 tracks / 0.1", + nBinsEtaRes, + 0, + maxEtaRes); + h_absResVsEta_z0_H[i] = new TH1F("absResVsEta_z0_H_" + etarange[i], + ";|z_{0} residual (L1 - sim)| [cm]; L1 tracks / 0.01", + nBinsZ0Res, + 0, + maxZ0Res); + h_absResVsEta_phi_H[i] = new TH1F("absResVsEta_phi_H_" + etarange[i], + ";#phi residual (L1 - sim) [GeV]; L1 tracks / 0.1", + nBinsPhiRes, + 0, + maxPhiRes); + h_absResVsEta_ptRel_H[i] = new TH1F("absResVsEta_ptRel_H_" + etarange[i], + ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02", + nBinsPtRelRes, + 0, + maxPtRelRes); + h_absResVsEta_d0_H[i] = + new TH1F("absResVsEta_d0_H_" + etarange[i], ";d_{0}residual (L1 - sim) [GeV]; L1 tracks / 0.1", 100, 0, 0.02); + } + + // resolution vs phi + + const int nPHIRANGE = 32; + TString phirange[nPHIRANGE] = {"-3.0", "-2.8", "-2.6", "-2.4", "-2.2", "-2.0", "-1.8", "-1.6", "-1.4", "-1.2", "-1.0", + "-0.8", "-0.6", "-0.4", "-0.2", "0.0", "0.2", "0.4", "0.6", "0.8", "1.0", "1.2", + "1.4", "1.6", "1.8", "2.0", "2.2", "2.4", "2.6", "2.8", "3.0", "3.2"}; + + TH1F* h_absResVsPhi_pt[nPHIRANGE]; + TH1F* h_absResVsPhi_ptRel[nPHIRANGE]; + + for (int i = 0; i < nPHIRANGE; i++) { + h_absResVsPhi_pt[i] = new TH1F( + "absResVsPt_pt_" + phirange[i], ";p_{T} residual (L1 - sim) [GeV]; L1 tracks / 0.1", nBinsPtRes, 0, maxPtRes); + h_absResVsPhi_ptRel[i] = new TH1F("absResVsPt_ptRel_" + phirange[i], + ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02", + nBinsPtRelRes, + 0, + maxPtRelRes); + } + + // ---------------------------------------------------------------------------------------------------------------- + // chi2 histograms (last bin is an overflow bin) + + TH1F* h_trk_chi2 = new TH1F("trk_chi2", ";#chi^{2}; L1 tracks / 1.0", 100, 0, 100); + TH1F* h_trk_chi2_dof = new TH1F("trk_chi2_dof", ";#chi^{2} / D.O.F.; L1 tracks / 0.2", 100, 0, 20); + TH1F* h_match_trk_chi2 = new TH1F("match_trk_chi2", ";#chi^{2}; L1 tracks / 1.0", 100, 0, 100); + TH1F* h_match_trk_chi2_dof = new TH1F("match_trk_chi2_dof", ";#chi^{2} / D.O.F.; L1 tracks / 0.2", 100, 0, 20); + + TH1F* h_trk_chi2rphi = new TH1F("trk_chi2rphi", ";#chi^{2}_{r-#phi}; L1 tracks / 1.0", 100, 0, 100); + TH1F* h_trk_chi2rphi_dof = new TH1F("trk_chi2rphi_dof", ";#chi^{2}_{r-#phi} / D.O.F.; L1 tracks / 0.2", 100, 0, 20); + TH1F* h_match_trk_chi2rphi = new TH1F("match_trk_chi2rphi", ";#chi^{2}_{r-#phi}; L1 tracks / 1.0", 100, 0, 100); + TH1F* h_match_trk_chi2rphi_dof = + new TH1F("match_trk_chi2rphi_dof", ";#chi^{2}_{r-#phi} / D.O.F.; L1 tracks / 0.2", 100, 0, 20); + + TH1F* h_trk_chi2rz = new TH1F("trk_chi2rz", ";#chi^{2}_{r-z}; L1 tracks / 1.0", 100, 0, 100); + TH1F* h_trk_chi2rz_dof = new TH1F("trk_chi2rz_dof", ";#chi^{2}_{r-z} / D.O.F.; L1 tracks / 0.2", 100, 0, 20); + TH1F* h_match_trk_chi2rz = new TH1F("match_trk_chi2rz", ";#chi^{2}_{r-z}; L1 tracks / 1.0", 100, 0, 100); + TH1F* h_match_trk_chi2rz_dof = + new TH1F("match_trk_chi2rz_dof", ";#chi^{2}_{r-z} / D.O.F.; L1 tracks / 0.2", 100, 0, 20); + + // ---------------------------------------------------------------------------------------------------------------- + // total track rates + + TH1F* h_trk_all_vspt = new TH1F("trk_all_vspt", ";Track p_{T} [GeV]; ", 50, 0, 25); + TH1F* h_trk_loose_vspt = new TH1F("trk_loose_vspt", ";Track p_{T} [GeV]; ", 50, 0, 25); + TH1F* h_trk_genuine_vspt = new TH1F("trk_genuine_vspt", ";Track p_{T} [GeV]; ", 50, 0, 25); + TH1F* h_trk_notloose_vspt = new TH1F( + "trk_notloose_vspt", ";Track p_{T} [GeV]; ", 50, 0, 25); //(same as "fake" according to the trk_fake labeling) + TH1F* h_trk_notgenuine_vspt = new TH1F("trk_notgenuine_vspt", ";Track p_{T} [GeV]; ", 50, 0, 25); + TH1F* h_trk_duplicate_vspt = new TH1F("trk_duplicate_vspt", + ";Track p_{T} [GeV]; ", + 50, + 0, + 25); //where a TP is genuinely matched to more than one L1 track + TH1F* h_tp_vspt = new TH1F("tp_vspt", ";TP p_{T} [GeV]; ", 50, 0, 25); + + // ---------------------------------------------------------------------------------------------------------------- + + TH1F* h_tp_z0 = new TH1F("tp_z0", ";Tracking particle z_{0} [cm]; Tracking particles / 1.0 cm", 50, -25.0, 25.0); + TH1F* h_tp_z0_L = new TH1F("tp_z0_L", ";Tracking particle z_{0} [cm]; Tracking particles / 1.0 cm", 50, -25.0, 25.0); + TH1F* h_tp_z0_H = new TH1F("tp_z0_H", ";Tracking particle z_{0} [cm]; Tracking particles / 1.0 cm", 50, -25.0, 25.0); + + TH1F* h_match_tp_z0 = + new TH1F("match_tp_z0", ";Tracking particle z_{0} [cm]; Tracking particles / 1.0 cm", 50, -25.0, 25.0); + TH1F* h_match_tp_z0_L = + new TH1F("match_tp_z0_L", ";Tracking particle z_{0} [cm]; Tracking particles / 1.0 cm", 50, -25.0, 25.0); + TH1F* h_match_tp_z0_H = + new TH1F("match_tp_z0_H", ";Tracking particle z_{0} [cm]; Tracking particles / 1.0 cm", 50, -25.0, 25.0); + + // ---------------------------------------------------------------------------------------------------------------- + // + // ****************** additional histograms drawn if using 'detailed' option ****************** + // + // ---------------------------------------------------------------------------------------------------------------- + + const float maxD0plot = TP_maxD0; + + TH1F* h_tp_phi = new TH1F("tp_phi", ";Tracking particle #phi [rad]; Tracking particles / 0.1", 64, -3.2, 3.2); + TH1F* h_tp_d0 = + new TH1F("tp_d0", ";Tracking particle d_{0} [cm]; Tracking particles / 0.01 cm", 50, -maxD0plot, maxD0plot); + TH1F* h_tp_absd0 = + new TH1F("tp_absd0", ";Tracking particle |d_{0}| [cm]; Tracking particles / 0.04 cm", 50, 0, maxD0plot); + TH1F* h_tp_absd0_eta2 = + new TH1F("tp_absd0_eta2", ";Tracking particle |d_{0}| [cm]; Tracking particles / 0.04 cm", 50, 0, maxD0plot); + TH1F* h_tp_absd0_eta2_pt3 = + new TH1F("tp_absd0_eta2_pt3", ";Tracking particle |d_{0}| [cm]; Tracking particles / 0.04 cm", 50, 0, maxD0plot); + + TH1F* h_match_tp_phi = + new TH1F("match_tp_phi", ";Tracking particle #phi [rad]; Tracking particles / 0.1", 64, -3.2, 3.2); + TH1F* h_match_tp_d0 = + new TH1F("match_tp_d0", ";Tracking particle d_{0} [cm]; Tracking particles / 0.01 cm", 50, -maxD0plot, maxD0plot); + TH1F* h_match_tp_absd0 = + new TH1F("match_tp_absd0", ";Tracking particle d_{0} [cm]; Tracking particles / 0.04 cm", 50, 0, maxD0plot); + TH1F* h_match_tp_absd0_eta2 = + new TH1F("match_tp_absd0_eta2", ";Tracking particle d_{0} [cm]; Tracking particles / 0.04 cm", 50, 0, maxD0plot); + TH1F* h_match_tp_absd0_eta2_pt3 = new TH1F( + "match_tp_absd0_eta2_pt3", ";Tracking particle d_{0} [cm]; Tracking particles / 0.04 cm", 50, 0, maxD0plot); + + TH1F* h_match_trk_nstub = new TH1F("match_trk_nstub", ";Number of stubs; L1 tracks / 1.0", 15, 0, 15); + TH1F* h_match_trk_nstub_C = new TH1F("match_trk_nstub_C", ";Number of stubs; L1 tracks / 1.0", 15, 0, 15); + TH1F* h_match_trk_nstub_I = new TH1F("match_trk_nstub_I", ";Number of stubs; L1 tracks / 1.0", 15, 0, 15); + TH1F* h_match_trk_nstub_F = new TH1F("match_trk_nstub_F", ";Number of stubs; L1 tracks / 1.0", 15, 0, 15); + + // note that we are only making the below chi2 histograms using the joint chi2, not the separate chi2rphi and chi2rz + + // chi2 histograms + // note: last bin is an overflow bin + TH1F* h_match_trk_chi2_C_L = new TH1F("match_trk_chi2_C_L", ";#chi^{2}; L1 tracks / 1.0", 100, 0, 100); + TH1F* h_match_trk_chi2_I_L = new TH1F("match_trk_chi2_I_L", ";#chi^{2}; L1 tracks / 1.0", 100, 0, 100); + TH1F* h_match_trk_chi2_F_L = new TH1F("match_trk_chi2_F_L", ";#chi^{2}; L1 tracks / 1.0", 100, 0, 100); + TH1F* h_match_trk_chi2_C_H = new TH1F("match_trk_chi2_C_H", ";#chi^{2}; L1 tracks / 1.0", 100, 0, 100); + TH1F* h_match_trk_chi2_I_H = new TH1F("match_trk_chi2_I_H", ";#chi^{2}; L1 tracks / 1.0", 100, 0, 100); + TH1F* h_match_trk_chi2_F_H = new TH1F("match_trk_chi2_F_H", ";#chi^{2}; L1 tracks / 1.0", 100, 0, 100); + + // chi2/dof histograms + // note: lastbin is an overflow bin + TH1F* h_match_trk_chi2_dof_C_L = + new TH1F("match_trk_chi2_dof_C_L", ";#chi^{2} / D.O.F.; L1 tracks / 0.2", 100, 0, 20); + TH1F* h_match_trk_chi2_dof_I_L = + new TH1F("match_trk_chi2_dof_I_L", ";#chi^{2} / D.O.F.; L1 tracks / 0.2", 100, 0, 20); + TH1F* h_match_trk_chi2_dof_F_L = + new TH1F("match_trk_chi2_dof_F_L", ";#chi^{2} / D.O.F.; L1 tracks / 0.2", 100, 0, 20); + TH1F* h_match_trk_chi2_dof_C_H = + new TH1F("match_trk_chi2_dof_C_H", ";#chi^{2} / D.O.F.; L1 tracks / 0.2", 100, 0, 20); + TH1F* h_match_trk_chi2_dof_I_H = + new TH1F("match_trk_chi2_dof_I_H", ";#chi^{2} / D.O.F.; L1 tracks / 0.2", 100, 0, 20); + TH1F* h_match_trk_chi2_dof_F_H = + new TH1F("match_trk_chi2_dof_F_H", ";#chi^{2} / D.O.F.; L1 tracks / 0.2", 100, 0, 20); + + // ---------------------------------------------------------------------------------------------------------------- + // resolution histograms + TH1F* h_res_pt = new TH1F("res_pt", ";p_{T} residual (L1 - sim) [GeV]; L1 tracks / 0.05", 200, -5.0, 5.0); + TH1F* h_res_ptRel = new TH1F("res_ptRel", ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.01", 200, -1.0, 1.0); + TH1F* h_res_eta = new TH1F("res_eta", ";#eta residual (L1 - sim); L1 tracks / 0.0002", 100, -0.01, 0.01); + TH1F* h_res_phi = new TH1F("res_phi", ";#phi residual (L1 - sim) [rad]; L1 tracks / 0.0001", 100, -0.005, 0.005); + + TH1F* h_res_z0 = new TH1F("res_z0", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1.0, 1.0); + TH1F* h_res_z0_C = new TH1F("res_z0_C", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1.0, 1.0); + TH1F* h_res_z0_I = new TH1F("res_z0_I", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1.0, 1.0); + TH1F* h_res_z0_F = new TH1F("res_z0_F", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1.0, 1.0); + TH1F* h_res_z0_L = new TH1F("res_z0_L", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1.0, 1.0); + TH1F* h_res_z0_H = new TH1F("res_z0_H", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1.0, 1.0); + + TH1F* h_res_z0_C_L = + new TH1F("res_z0_C_L", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, (-1) * 1.0, 1.0); + TH1F* h_res_z0_I_L = + new TH1F("res_z0_I_L", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, (-1) * 1.0, 1.0); + TH1F* h_res_z0_F_L = + new TH1F("res_z0_F_L", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, (-1) * 1.0, 1.0); + TH1F* h_res_z0_C_H = + new TH1F("res_z0_C_H", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, (-1) * 1.0, 1.0); + TH1F* h_res_z0_I_H = + new TH1F("res_z0_I_H", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, (-1) * 1.0, 1.0); + TH1F* h_res_z0_F_H = + new TH1F("res_z0_F_H", ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, (-1) * 1.0, 1.0); + + TH1F* h_res_d0 = new TH1F("res_d0", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0002 cm", 200, -0.02, 0.02); + TH1F* h_res_d0_C = new TH1F("res_d0_C", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05); + TH1F* h_res_d0_I = new TH1F("res_d0_I", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05); + TH1F* h_res_d0_F = new TH1F("res_d0_F", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05); + TH1F* h_res_d0_L = new TH1F("res_d0_L", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05); + TH1F* h_res_d0_H = new TH1F("res_d0_H", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05); + + TH1F* h_res_d0_C_L = + new TH1F("res_d0_C_L", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05); + TH1F* h_res_d0_I_L = + new TH1F("res_d0_I_L", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05); + TH1F* h_res_d0_F_L = + new TH1F("res_d0_F_L", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05); + TH1F* h_res_d0_C_H = + new TH1F("res_d0_C_H", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05); + TH1F* h_res_d0_I_H = + new TH1F("res_d0_I_H", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05); + TH1F* h_res_d0_F_H = + new TH1F("res_d0_F_H", ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0001 cm", 200, -0.05, 0.05); + + // ---------------------------------------------------------------------------------------------------------------- + // more resolution vs pt + + TH1F* h_resVsPt_pt[nRANGE]; + TH1F* h_resVsPt_pt_C[nRANGE]; + TH1F* h_resVsPt_pt_I[nRANGE]; + TH1F* h_resVsPt_pt_F[nRANGE]; + + TH1F* h_resVsPt_ptRel[nRANGE]; + TH1F* h_resVsPt_ptRel_C[nRANGE]; + TH1F* h_resVsPt_ptRel_I[nRANGE]; + TH1F* h_resVsPt_ptRel_F[nRANGE]; + + TH1F* h_resVsPt_z0[nRANGE]; + TH1F* h_resVsPt_z0_C[nRANGE]; + TH1F* h_resVsPt_z0_I[nRANGE]; + TH1F* h_resVsPt_z0_F[nRANGE]; + + TH1F* h_resVsPt_phi[nRANGE]; + TH1F* h_resVsPt_phi_C[nRANGE]; + TH1F* h_resVsPt_phi_I[nRANGE]; + TH1F* h_resVsPt_phi_F[nRANGE]; + + TH1F* h_resVsPt_eta[nRANGE]; + TH1F* h_resVsPt_d0[nRANGE]; + + for (int i = 0; i < nRANGE; i++) { + h_resVsPt_pt[i] = + new TH1F("resVsPt_pt_" + ptrange[i], ";p_{T} residual (L1 - sim) [GeV]; L1 tracks / 0.1", 100, -5.0, 5.0); + h_resVsPt_pt_C[i] = + new TH1F("resVsPt_pt_C_" + ptrange[i], ";p_{T} residual (L1 - sim) [GeV]; L1 tracks / 0.1", 100, -5.0, 5.0); + h_resVsPt_pt_I[i] = + new TH1F("resVsPt_pt_I_" + ptrange[i], ";p_{T} residual (L1 - sim) [GeV]; L1 tracks / 0.1", 100, -5.0, 5.0); + h_resVsPt_pt_F[i] = + new TH1F("resVsPt_pt_F_" + ptrange[i], ";p_{T} residual (L1 - sim) [GeV]; L1 tracks / 0.1", 100, -5.0, 5.0); + + h_resVsPt_ptRel[i] = new TH1F( + "resVsPt_ptRel_" + ptrange[i], ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02", 300, -0.15, 0.15); + h_resVsPt_ptRel_C[i] = new TH1F( + "resVsPt_ptRel_c_" + ptrange[i], ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02", 300, -0.15, 0.15); + h_resVsPt_ptRel_I[i] = new TH1F( + "resVsPt_ptRel_I_" + ptrange[i], ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02", 300, -0.15, 0.15); + h_resVsPt_ptRel_F[i] = new TH1F( + "resVsPt_ptRel_F_" + ptrange[i], ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02", 300, -0.15, 0.15); + + h_resVsPt_z0[i] = + new TH1F("resVsPt_z0_" + ptrange[i], ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1, 1); + h_resVsPt_z0_C[i] = + new TH1F("resVsPt_z0_C_" + ptrange[i], ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1, 1); + h_resVsPt_z0_I[i] = + new TH1F("resVsPt_z0_I_" + ptrange[i], ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1, 1); + h_resVsPt_z0_F[i] = + new TH1F("resVsPt_z0_F_" + ptrange[i], ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.02", 100, -1, 1); + + h_resVsPt_phi[i] = new TH1F( + "resVsPt_phi_" + ptrange[i], ";#phi residual (L1 - sim) [rad]; L1 tracks / 0.0001", 100, -0.005, 0.005); + h_resVsPt_phi_C[i] = new TH1F( + "resVsPt_phi_C_" + ptrange[i], ";#phi residual (L1 - sim) [rad]; L1 tracks / 0.0001", 100, -0.005, 0.005); + h_resVsPt_phi_I[i] = new TH1F( + "resVsPt_phi_I_" + ptrange[i], ";#phi residual (L1 - sim) [rad]; L1 tracks / 0.0001", 100, -0.005, 0.005); + h_resVsPt_phi_F[i] = new TH1F( + "resVsPt_phi_F_" + ptrange[i], ";#phi residual (L1 - sim) [rad]; L1 tracks / 0.0001", 100, -0.005, 0.005); + + h_resVsPt_eta[i] = + new TH1F("resVsPt_eta_" + ptrange[i], ";#eta residual (L1 - sim); L1 tracks / 0.0002", 100, -0.01, 0.01); + + h_resVsPt_d0[i] = + new TH1F("resVsPt_d0_" + ptrange[i], ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.0004", 100, -0.02, 0.02); + } + + // ---------------------------------------------------------------------------------------------------------------- + // more resolution vs eta + + TH1F* h_resVsEta_eta[nETARANGE]; + TH1F* h_resVsEta_eta_L[nETARANGE]; + TH1F* h_resVsEta_eta_H[nETARANGE]; + + TH1F* h_resVsEta_z0[nETARANGE]; + TH1F* h_resVsEta_z0_L[nETARANGE]; + TH1F* h_resVsEta_z0_H[nETARANGE]; + + TH1F* h_resVsEta_phi[nETARANGE]; + TH1F* h_resVsEta_phi_L[nETARANGE]; + TH1F* h_resVsEta_phi_H[nETARANGE]; + + TH1F* h_resVsEta_ptRel[nETARANGE]; + TH1F* h_resVsEta_ptRel_L[nETARANGE]; + TH1F* h_resVsEta_ptRel_H[nETARANGE]; + + TH1F* h_resVsEta_d0[nETARANGE]; + TH1F* h_resVsEta_d0_L[nETARANGE]; + TH1F* h_resVsEta_d0_H[nETARANGE]; + + for (int i = 0; i < nETARANGE; i++) { + h_resVsEta_eta[i] = + new TH1F("resVsEta2_eta_" + etarange[i], ";#eta residual (L1 - sim); L1 tracks / 0.0002", 100, -0.01, 0.01); + h_resVsEta_eta_L[i] = + new TH1F("resVsEta2_eta_L_" + etarange[i], ";#eta residual (L1 - sim); L1 tracks / 0.0002", 100, -0.01, 0.01); + h_resVsEta_eta_H[i] = + new TH1F("resVsEta2_eta_H_" + etarange[i], ";#eta residual (L1 - sim); L1 tracks / 0.0002", 100, -0.01, 0.01); + + h_resVsEta_z0[i] = + new TH1F("resVsEta2_z0_" + etarange[i], ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.01", 100, -1, 1); + h_resVsEta_z0_L[i] = + new TH1F("resVsEta2_z0_L_" + etarange[i], ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.01", 100, -1, 1); + h_resVsEta_z0_H[i] = + new TH1F("resVsEta2_z0_H_" + etarange[i], ";z_{0} residual (L1 - sim) [cm]; L1 tracks / 0.01", 100, -1, 1); + + h_resVsEta_phi[i] = new TH1F( + "resVsEta2_phi_" + etarange[i], ";#phi residual (L1 - sim) [rad]; L1 tracks / 0.0001", 100, -0.005, 0.005); + h_resVsEta_phi_L[i] = new TH1F( + "resVsEta2_phi_L_" + etarange[i], ";#phi residual (L1 - sim) [rad]; L1 tracks / 0.0001", 100, -0.005, 0.005); + h_resVsEta_phi_H[i] = new TH1F( + "resVsEta2_phi_H_" + etarange[i], ";#phi residual (L1 - sim) [rad]; L1 tracks / 0.0001", 100, -0.005, 0.005); + + h_resVsEta_ptRel[i] = new TH1F( + "resVsEta2_ptRel_" + etarange[i], ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.01", 100, -0.5, 0.5); + h_resVsEta_ptRel_L[i] = new TH1F( + "resVsEta2_ptRel_L_" + etarange[i], ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02", 100, -0.1, 0.1); + h_resVsEta_ptRel_H[i] = new TH1F( + "resVsEta2_ptRel_H_" + etarange[i], ";p_{T} residual (L1 - sim) / p_{T}; L1 tracks / 0.02", 100, -0.25, 0.25); + + h_resVsEta_d0[i] = + new TH1F("resVsEta2_d0_" + etarange[i], ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.004", 100, -0.02, 0.02); + h_resVsEta_d0_L[i] = new TH1F( + "resVsEta2_d0_L_" + etarange[i], ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.004", 100, -0.02, 0.02); + h_resVsEta_d0_H[i] = new TH1F( + "resVsEta2_d0_H_" + etarange[i], ";d_{0} residual (L1 - sim) [cm]; L1 tracks / 0.004", 100, -0.02, 0.02); + } + // ---------------------------------------------------------------------------------------------------------------- + + // ---------------------------------------------------------------------------------------------------------------- + // additional ones for sum pt in jets + /* + TH1F* h_jet_tp_sumpt_vspt = new TH1F("jet_tp_sumpt_vspt", ";sum(TP p_{T}) [GeV]; Gen jets / 5.0 GeV", 20, 0, 200.0); + TH1F* h_jet_trk_sumpt_vspt = new TH1F("jet_trk_sumpt_vspt", ";sum(TP p_{T}) [GeV]; Gen jets / 5.0 GeV", 20, 0, 200.0); + TH1F* h_jet_matchtrk_sumpt_vspt = new TH1F("jet_matchtrk_sumpt_vspt", ";sum(TP p_{T}) [GeV]; Gen jets / 5.0 GeV", 20, 0, 200.0); + + TH1F* h_jet_tp_sumpt_vseta = new TH1F("jet_tp_sumpt_vseta", ";Gen jet #eta; Gen jets / 0.2", 24, -2.4, 2.4); + TH1F* h_jet_trk_sumpt_vseta = new TH1F("jet_trk_sumpt_vseta", ";Gen jet #eta; Gen jets / 0.2", 24, -2.4, 2.4); + TH1F* h_jet_matchtrk_sumpt_vseta = new TH1F("jet_matchtrk_sumpt_vseta", ";Gen jet #eta; Gen jets / 0.2", 24, -2.4, 2.4); + + h_jet_tp_sumpt_vseta->Sumw2(); + h_jet_tp_sumpt_vspt->Sumw2(); + h_jet_trk_sumpt_vseta->Sumw2(); + h_jet_trk_sumpt_vspt->Sumw2(); + h_jet_matchtrk_sumpt_vseta->Sumw2(); + h_jet_matchtrk_sumpt_vspt->Sumw2(); + */ + + // ---------------------------------------------------------------------------------------------------------------- + // number of tracks per event + + // all tracks + TH1F* h_ntrk_pt2 = new TH1F("ntrk_pt2", ";# tracks (p_{T} > 2 GeV) / event; Events", 400, 0, 400.0); + TH1F* h_ntrk_pt3 = new TH1F("ntrk_pt3", ";# tracks (p_{T} > 3 GeV) / event; Events", 300, 0, 300.0); + TH1F* h_ntrk_pt10 = new TH1F("ntrk_pt10", ";# tracks (p_{T} > 10 GeV) / event; Events", 100, 0, 100.0); + + // tracks flagged as genuine (this would include duplicates (?)) + TH1F* h_ntrk_genuine_pt2 = + new TH1F("ntrk_genuine_pt2", ";# genuine tracks (p_{T} > 2 GeV) / event; Events", 400, 0, 400.0); + TH1F* h_ntrk_genuine_pt3 = + new TH1F("ntrk_genuine_pt3", ";# genuine tracks (p_{T} > 3 GeV) / event; Events", 300, 0, 300.0); + TH1F* h_ntrk_genuine_pt10 = + new TH1F("ntrk_genuine_pt10", ";# genuine tracks (p_{T} > 10 GeV) / event; Events", 100, 0, 100.0); + + // Max N tracks from a sector per event + TH1F* h_ntrkPerSector_pt2 = + new TH1F("ntrkPerSector_pt2", ";Max. # tracks from a sector (p_{T} > 2 GeV) / event; Events", 50, 0, 100.0); + TH1F* h_ntrkPerSector_pt3 = + new TH1F("ntrkPerSector_pt3", ";Max. # tracks from a sector (p_{T} > 3 GeV) / event; Events", 50, 0, 100.0); + TH1F* h_ntrkPerSector_pt4 = + new TH1F("ntrkPerSector_pt4", ";Max. # tracks from a sector (p_{T} > 10 GeV) / event; Events", 50, 0, 100.0); + + // ---------------------------------------------------------------------------------------------------------------- + // * * * * * S T A R T O F A C T U A L R U N N I N G O N E V E N T S * * * * * + // ---------------------------------------------------------------------------------------------------------------- + + int nevt = tree->GetEntries(); + cout << "number of events = " << nevt << endl; + + // ---------------------------------------------------------------------------------------------------------------- + // event loop + for (int i = 0; i < nevt; i++) { + tree->GetEntry(i, 0); + + /* + // ---------------------------------------------------------------------------------------------------------------- + // sumpt in jets + if (TP_select_injet > 0) { + for (int ij=0; ij<(int)jet_tp_sumpt->size(); ij++) { + + float fraction = 0; + float fractionMatch = 0; + if (jet_tp_sumpt->at(ij) > 0) { + fraction = jet_trk_sumpt->at(ij)/jet_tp_sumpt->at(ij); + fractionMatch = jet_matchtrk_sumpt->at(ij)/jet_tp_sumpt->at(ij); + } + + h_jet_tp_sumpt_vspt->Fill(jet_tp_sumpt->at(ij),1.0); + h_jet_trk_sumpt_vspt->Fill(jet_tp_sumpt->at(ij),fraction); + h_jet_matchtrk_sumpt_vspt->Fill(jet_tp_sumpt->at(ij),fractionMatch); + + h_jet_tp_sumpt_vseta->Fill(jet_eta->at(ij),1.0); + h_jet_trk_sumpt_vseta->Fill(jet_eta->at(ij),fraction); + h_jet_matchtrk_sumpt_vseta->Fill(jet_eta->at(ij),fractionMatch); + } + } + */ + + // ---------------------------------------------------------------------------------------------------------------- + // track loop for total rates & fake rates. + + int ntrkevt_pt2 = 0; + int ntrkevt_pt3 = 0; + int ntrkevt_pt10 = 0; + + int ntrkevt_genuine_pt2 = 0; + int ntrkevt_genuine_pt3 = 0; + int ntrkevt_genuine_pt10 = 0; + + vector nTrksPerSector_pt2(9, 0); + vector nTrksPerSector_pt3(9, 0); + vector nTrksPerSector_pt4(9, 0); + + for (int it = 0; it < (int)trk_pt->size(); it++) { + // ---------------------------------------------------------------------------------------------------------------- + // track properties + + // fill all trk chi2 & chi2/dof histograms, including for chi2 r-phi and chi2 r-z + int ndof = 2 * trk_nstub->at(it) - 4; + float chi2 = trk_chi2->at(it); + float chi2dof = (float)chi2 / ndof; + float chi2rphi = trk_chi2rphi->at(it); + float chi2rphidof = (float)chi2rphi / ndof; + float chi2rz = trk_chi2rz->at(it); + float chi2rzdof = (float)chi2rz / ndof; + + // create overflow bins by restricting range of chi2 + int chi2Overflow = 100; + int chi2DOFOverflow = 20; //apprx chi2Overflow / avg. nstubs + double buffer = 0.1; + + if (chi2 > chi2Overflow) + chi2 = chi2Overflow - buffer; + if (chi2dof > chi2DOFOverflow) + chi2dof = chi2DOFOverflow - buffer; + if (chi2rphi > chi2Overflow) + chi2rphi = chi2Overflow - buffer; + if (chi2rphidof > chi2DOFOverflow) + chi2rphidof = chi2DOFOverflow - buffer; + if (chi2rz > chi2Overflow) + chi2rz = chi2Overflow - buffer; + if (chi2rzdof > chi2DOFOverflow) + chi2rzdof = chi2DOFOverflow - buffer; + + if (trk_pt->at(it) > TP_minPt) { //TRK pt > TP_minPt + + h_trk_chi2->Fill(chi2); + h_trk_chi2_dof->Fill(chi2dof); + + h_trk_chi2rphi->Fill(chi2rphi); + h_trk_chi2rphi_dof->Fill(chi2rphidof); + + h_trk_chi2rz->Fill(chi2rz); + h_trk_chi2rz_dof->Fill(chi2rzdof); + + } //end TRK pt > TP_minPt + + // ---------------------------------------------------------------------------------------------------------------- + // look at track rate and fake rate, etc. + + // only look at tracks in (ttbar) jets ? + if (TP_select_injet > 0) { + if (TP_select_injet == 1 && trk_injet->at(it) == 0) + continue; + if (TP_select_injet == 2 && trk_injet_highpt->at(it) == 0) + continue; + if (TP_select_injet == 3 && trk_injet_vhighpt->at(it) == 0) + continue; + } + + if (std::abs(trk_eta->at(it)) > TP_maxEta) + continue; + if (trk_pt->at(it) < TP_minPt) + continue; + + // Uncomment these cuts to see effect on rate & fake rate. + //int ndof = 2*trk_nstub->at(it)-4; + //if (trk_chi2->at(it) > L1Tk_maxChi2) continue; + //if (trk_chi2->at(it)/ndof > L1Tk_maxChi2dof) continue; + //if (trk_nstub->at(it) < L1Tk_minNstub) continue; + + // Tracklet & Hybrid have 9 sectors, but TMTT has 18 (with sectors 0 & 1 in nonant 0 etc). + // As don't know here with algo used, "% 9" added to prevent crash, but not correct for TMTT. + if (trk_pt->at(it) > 2.0) + ++nTrksPerSector_pt2.at(trk_phiSector->at(it) % 9); + if (trk_pt->at(it) > 3.0) + ++nTrksPerSector_pt3.at(trk_phiSector->at(it) % 9); + if (trk_pt->at(it) > 4.0) + ++nTrksPerSector_pt4.at(trk_phiSector->at(it) % 9); + + if (trk_pt->at(it) > 2.0) { + ntrk_pt2++; + ntrkevt_pt2++; + h_trk_all_vspt->Fill(trk_pt->at(it)); + if (trk_genuine->at(it) == 1) { + ntrkevt_genuine_pt2++; + h_trk_genuine_vspt->Fill(trk_pt->at(it)); + } else + h_trk_notgenuine_vspt->Fill(trk_pt->at(it)); + if (trk_loose->at(it) == 1) + h_trk_loose_vspt->Fill(trk_pt->at(it)); + else + h_trk_notloose_vspt->Fill(trk_pt->at(it)); + } + if (trk_pt->at(it) > 3.0) { + ntrk_pt3++; + ntrkevt_pt3++; + if (trk_genuine->at(it) == 1) + ntrkevt_genuine_pt3++; + } + if (trk_pt->at(it) > 10.0) { + ntrk_pt10++; + ntrkevt_pt10++; + if (trk_genuine->at(it) == 1) + ntrkevt_genuine_pt10++; + } + + // ---------------------------------------------------------------------------------------------------------------- + // Fill tracklet propogation efficiency histo + + // create an 11-bit long iterable from lhits and dhits + int num_layers = 6; + int num_discs = 5; + int lhits = trk_lhits->at(it); + int dhits = trk_dhits->at(it); + std::vector layers = {}; + for (int layer_index = 0; layer_index < num_layers + num_discs; layer_index++) { + if (layer_index < num_layers) { + layers.push_back(lhits % 10); + lhits /= 10; + } else { + layers.push_back(dhits % 10); + dhits /= 10; + } + } + + for (unsigned int layer = 0; layer < layers.size(); layer++) { + if (layers.at(layer)) { // if there was a hit at this layer... + h_trk_tracklet_hits->Fill(std::abs(trk_eta->at(it)), layer); // ...fill this bin with the layer of the track. + } + } + } + + h_ntrk_pt2->Fill(ntrkevt_pt2); + h_ntrk_pt3->Fill(ntrkevt_pt3); + h_ntrk_pt10->Fill(ntrkevt_pt10); + + h_ntrk_genuine_pt2->Fill(ntrkevt_genuine_pt2); + h_ntrk_genuine_pt3->Fill(ntrkevt_genuine_pt3); + h_ntrk_genuine_pt10->Fill(ntrkevt_genuine_pt10); + + h_ntrkPerSector_pt2->Fill(*std::max_element(nTrksPerSector_pt2.begin(), nTrksPerSector_pt2.end())); + h_ntrkPerSector_pt3->Fill(*std::max_element(nTrksPerSector_pt3.begin(), nTrksPerSector_pt3.end())); + h_ntrkPerSector_pt4->Fill(*std::max_element(nTrksPerSector_pt4.begin(), nTrksPerSector_pt4.end())); + + // ---------------------------------------------------------------------------------------------------------------- + // tracking particle loop + for (int it = 0; it < (int)tp_pt->size(); it++) { + // only look at TPs in (ttbar) jets ? + if (TP_select_injet > 0) { + if (TP_select_injet == 1 && tp_injet->at(it) == 0) + continue; + if (TP_select_injet == 2 && tp_injet_highpt->at(it) == 0) + continue; + if (TP_select_injet == 3 && tp_injet_vhighpt->at(it) == 0) + continue; + } + + // cut on PDG ID at plot stage? + if (TP_select_pdgid != 0) { + if (abs(tp_pdgid->at(it)) != abs(TP_select_pdgid)) + continue; + } + + // kinematic cuts + if (std::abs(tp_dxy->at(it)) > TP_maxDxy) + continue; + if (std::abs(tp_d0->at(it)) > TP_maxD0) + continue; + if (tp_pt->at(it) < 0.2) + continue; + if (tp_pt->at(it) > TP_maxPt) + continue; + if (std::abs(tp_eta->at(it)) > TP_maxEta) + continue; + + // total track rates + if (tp_pt->at(it) > TP_minPt) { + if (tp_pt->at(it) > 2.0) { + ntp_pt2++; + h_tp_vspt->Fill(tp_pt->at(it)); + // duplicate rate + if (tp_nmatch->at(it) > 1) { + for (int inm = 1; inm < tp_nmatch->at(it); inm++) + h_trk_duplicate_vspt->Fill(matchtrk_pt->at(it)); + } + } + if (tp_pt->at(it) > 3.0) + ntp_pt3++; + if (tp_pt->at(it) > 10.0) + ntp_pt10++; + } + + // cut on event ID (eventid=0 means the TP is from the primary interaction, so *not* selecting only eventid=0 means including stuff from pileup) + if (TP_select_eventid == 0 && tp_eventid->at(it) != 0) + continue; + + // look at failure scenarios? + if (useDeadRegion) { + if (tp_phi->at(it) < 0 || tp_phi->at(it) > 1) + continue; + } + + h_tp_pt->Fill(tp_pt->at(it)); + if (tp_pt->at(it) < 8.0) + h_tp_pt_L->Fill(tp_pt->at(it)); + else + h_tp_pt_H->Fill(tp_pt->at(it)); + if (tp_pt->at(it) < 8.0 && std::abs(tp_eta->at(it)) < 1.0) + h_tp_pt_LC->Fill(tp_pt->at(it)); + + if (tp_pt->at(it) > TP_minPt) { + if (std::abs(tp_eta->at(it)) < 1.0) + n_all_eta1p0++; + else if (std::abs(tp_eta->at(it)) < 1.75) + n_all_eta1p75++; + else + n_all_eta2p5++; + + if (std::abs(tp_pt->at(it)) > 2.0) + n_all_ptg2++; + if (std::abs(tp_pt->at(it)) > 2.0 && std::abs(tp_pt->at(it)) < 8.0) + n_all_pt2to8++; + if (std::abs(tp_pt->at(it)) > 8.0) + n_all_ptg8++; + if (std::abs(tp_pt->at(it)) > 40.0) + n_all_ptg40++; + + h_tp_eta->Fill(tp_eta->at(it)); + h_tp_phi->Fill(tp_phi->at(it)); + h_tp_z0->Fill(tp_z0->at(it)); + h_tp_d0->Fill(tp_d0->at(it)); + h_tp_absd0->Fill(std::abs(tp_d0->at(it))); + if (std::abs(tp_eta->at(it)) < 2.0) + h_tp_absd0_eta2->Fill(std::abs(tp_d0->at(it))); + if (std::abs(tp_eta->at(it)) < 2.0 && tp_pt->at(it) > 3.0) + h_tp_absd0_eta2_pt3->Fill(std::abs(tp_d0->at(it))); + + if (tp_pt->at(it) < 3.0) + h_tp_eta_23->Fill(tp_eta->at(it)); + else if (tp_pt->at(it) < 5.0) + h_tp_eta_35->Fill(tp_eta->at(it)); + else + h_tp_eta_5->Fill(tp_eta->at(it)); + + if (tp_pt->at(it) < 8.0) { + h_tp_eta_L->Fill(tp_eta->at(it)); + h_tp_z0_L->Fill(tp_z0->at(it)); + } else { + h_tp_eta_H->Fill(tp_eta->at(it)); + h_tp_z0_H->Fill(tp_z0->at(it)); + } + } + + // ---------------------------------------------------------------------------------------------------------------- + // was the tracking particle matched to a L1 track? + if (tp_nmatch->at(it) < 1) + continue; + + // ---------------------------------------------------------------------------------------------------------------- + // use only tracks with min X stubs + if (matchtrk_nstub->at(it) < L1Tk_minNstub) + continue; + + int thisseed = matchtrk_seed->at(it); + if (thisseed > 25) + thisseed = thisseed - 20; + if ((L1Tk_seed != 0) && (thisseed != L1Tk_seed)) + continue; + + // ---------------------------------------------------------------------------------------------------------------- + // fill matchtrk chi2 & chi2/dof histograms before making chi2 cut + + int ndof = 2 * matchtrk_nstub->at(it) - 4; + float chi2 = matchtrk_chi2->at(it); + float chi2dof = (float)chi2 / ndof; + float chi2rphi = matchtrk_chi2rphi->at(it); + float chi2rphidof = (float)chi2rphi / ndof; + float chi2rz = matchtrk_chi2rz->at(it); + float chi2rzdof = (float)chi2rz / ndof; + + // create overflow bins by restricting range of chi2 + int chi2Overflow = 100; + int chi2DOFOverflow = 20; //apprx chi2Overflow / avg. nstubs + double buffer = 0.1; + + if (chi2 > chi2Overflow) + chi2 = chi2Overflow - buffer; + if (chi2dof > chi2DOFOverflow) + chi2dof = chi2DOFOverflow - buffer; + if (chi2rphi > chi2Overflow) + chi2rphi = chi2Overflow - buffer; + if (chi2rphidof > chi2DOFOverflow) + chi2rphidof = chi2DOFOverflow - buffer; + if (chi2rz > chi2Overflow) + chi2rz = chi2Overflow - buffer; + if (chi2rzdof > chi2DOFOverflow) + chi2rzdof = chi2DOFOverflow - buffer; + + if (tp_pt->at(it) > TP_minPt) { //TP pt > TP_minPt + + h_match_trk_chi2->Fill(chi2); + h_match_trk_chi2_dof->Fill(chi2dof); + + h_match_trk_chi2rphi->Fill(chi2rphi); + h_match_trk_chi2rphi_dof->Fill(chi2rphidof); + + h_match_trk_chi2rz->Fill(chi2rz); + h_match_trk_chi2rz_dof->Fill(chi2rzdof); + + // central eta + if (std::abs(tp_eta->at(it)) < 0.8) { + if (tp_pt->at(it) < 8.0) { + h_match_trk_chi2_C_L->Fill(chi2); + h_match_trk_chi2_dof_C_L->Fill(chi2dof); + } else { + h_match_trk_chi2_C_H->Fill(chi2); + h_match_trk_chi2_dof_C_H->Fill(chi2dof); + } + } + // intermediate eta + else if (std::abs(tp_eta->at(it)) < 1.6 && std::abs(tp_eta->at(it)) >= 0.8) { + if (tp_pt->at(it) < 8.0) { + h_match_trk_chi2_I_L->Fill(chi2); + h_match_trk_chi2_dof_I_L->Fill(chi2dof); + } else { + h_match_trk_chi2_I_H->Fill(chi2); + h_match_trk_chi2_dof_I_H->Fill(chi2dof); + } + } + // forward eta + else if (std::abs(tp_eta->at(it)) >= 1.6) { + if (tp_pt->at(it) < 8.0) { + h_match_trk_chi2_F_L->Fill(chi2); + h_match_trk_chi2_dof_F_L->Fill(chi2dof); + } else { + h_match_trk_chi2_F_H->Fill(chi2); + h_match_trk_chi2_dof_F_H->Fill(chi2dof); + } + } + } //end TP pt > TP_minPt + + // ---------------------------------------------------------------------------------------------------------------- + // cut on chi2? + if (matchtrk_chi2->at(it) > L1Tk_maxChi2) + continue; + if (matchtrk_chi2->at(it) / ndof > L1Tk_maxChi2dof) + continue; + + // use tight quality cut selection? + /* + if (matchtrk_nstub->at(it)==4) { + if (std::abs(matchtrk_eta->at(it))<2.2 && matchtrk_consistency->at(it)>10) continue; + else if (std::abs(matchtrk_eta->at(it))>2.2 && chi2dof>5.0) continue; + } + if (matchtrk_pt->at(it)>10.0 && chi2dof>5.0) continue; + */ + + // ---------------------------------------------------------------------------------------------------------------- + // more plots + + // fill matched track histograms + h_match_tp_pt->Fill(tp_pt->at(it)); + if (tp_pt->at(it) < 8.0) + h_match_tp_pt_L->Fill(tp_pt->at(it)); + else + h_match_tp_pt_H->Fill(tp_pt->at(it)); + if (tp_pt->at(it) < 8.0 && std::abs(tp_eta->at(it)) < 1.0) + h_match_tp_pt_LC->Fill(tp_pt->at(it)); + + if (tp_pt->at(it) > TP_minPt) { + h_match_tp_eta->Fill(tp_eta->at(it)); + h_match_tp_phi->Fill(tp_phi->at(it)); + h_match_tp_z0->Fill(tp_z0->at(it)); + h_match_tp_d0->Fill(tp_d0->at(it)); + h_match_tp_absd0->Fill(std::abs(tp_d0->at(it))); + if (std::abs(tp_eta->at(it)) < 2.0) + h_match_tp_absd0_eta2->Fill(std::abs(tp_d0->at(it))); + if (std::abs(tp_eta->at(it)) < 2.0 && tp_pt->at(it) > 3.0) + h_match_tp_absd0_eta2_pt3->Fill(std::abs(tp_d0->at(it))); + + if (std::abs(tp_eta->at(it)) < 1.0) + n_match_eta1p0++; + else if (std::abs(tp_eta->at(it)) < 1.75) + n_match_eta1p75++; + else + n_match_eta2p5++; + + if (std::abs(tp_pt->at(it)) > 2.0) + n_match_ptg2++; + if (std::abs(tp_pt->at(it)) > 2.0 && std::abs(tp_pt->at(it)) < 8.0) + n_match_pt2to8++; + if (std::abs(tp_pt->at(it)) > 8.0) + n_match_ptg8++; + if (std::abs(tp_pt->at(it)) > 40.0) + n_match_ptg40++; + + if (tp_pt->at(it) < 3.0) + h_match_tp_eta_23->Fill(tp_eta->at(it)); + else if (tp_pt->at(it) < 5.0) + h_match_tp_eta_35->Fill(tp_eta->at(it)); + else + h_match_tp_eta_5->Fill(tp_eta->at(it)); + + if (tp_pt->at(it) < 8.0) { + h_match_tp_eta_L->Fill(tp_eta->at(it)); + h_match_tp_z0_L->Fill(tp_z0->at(it)); + } else { + h_match_tp_z0_H->Fill(tp_z0->at(it)); + h_match_tp_eta_H->Fill(tp_eta->at(it)); + } + } + + // for the following, only consider TPs with pt > TP_minPt + if (tp_pt->at(it) < TP_minPt) + continue; + + // fill nstub histograms + h_match_trk_nstub->Fill(matchtrk_nstub->at(it)); + if (std::abs(tp_eta->at(it)) < 0.8) + h_match_trk_nstub_C->Fill(matchtrk_nstub->at(it)); + else if (std::abs(tp_eta->at(it)) < 1.6 && std::abs(tp_eta->at(it)) >= 0.8) + h_match_trk_nstub_I->Fill(matchtrk_nstub->at(it)); + else if (std::abs(tp_eta->at(it)) >= 1.6) + h_match_trk_nstub_F->Fill(matchtrk_nstub->at(it)); + + // ---------------------------------------------------------------------------------------------------------------- + // fill resolution histograms + + h_res_pt->Fill(matchtrk_pt->at(it) - tp_pt->at(it)); + h_res_ptRel->Fill((matchtrk_pt->at(it) - tp_pt->at(it)) / tp_pt->at(it)); + h_res_eta->Fill(matchtrk_eta->at(it) - tp_eta->at(it)); + h_res_phi->Fill(matchtrk_phi->at(it) - tp_phi->at(it)); + h_res_z0->Fill(matchtrk_z0->at(it) - tp_z0->at(it)); + if (matchtrk_d0->at(it) < 999.) + h_res_d0->Fill(matchtrk_d0->at(it) - tp_d0->at(it)); + + if (std::abs(tp_eta->at(it)) < 0.8) + h_res_z0_C->Fill(matchtrk_z0->at(it) - tp_z0->at(it)); + else if (std::abs(tp_eta->at(it)) < 1.6 && std::abs(tp_eta->at(it)) >= 0.8) + h_res_z0_I->Fill(matchtrk_z0->at(it) - tp_z0->at(it)); + else if (std::abs(tp_eta->at(it)) >= 1.6) + h_res_z0_F->Fill(matchtrk_z0->at(it) - tp_z0->at(it)); + + if (tp_pt->at(it) < 8.0) { + h_res_z0_L->Fill(matchtrk_z0->at(it) - tp_z0->at(it)); + if (std::abs(tp_eta->at(it)) < 1.0) + h_res_z0_C_L->Fill(matchtrk_z0->at(it) - tp_z0->at(it)); + else + h_res_z0_F_L->Fill(matchtrk_z0->at(it) - tp_z0->at(it)); + } else { + h_res_z0_H->Fill(matchtrk_z0->at(it) - tp_z0->at(it)); + if (std::abs(tp_eta->at(it)) < 1.0) + h_res_z0_C_H->Fill(matchtrk_z0->at(it) - tp_z0->at(it)); + else + h_res_z0_F_H->Fill(matchtrk_z0->at(it) - tp_z0->at(it)); + } + + if (matchtrk_d0->at(it) < 999.) { + if (std::abs(tp_eta->at(it)) < 0.8) + h_res_d0_C->Fill(matchtrk_d0->at(it) - tp_d0->at(it)); + else if (std::abs(tp_eta->at(it)) < 1.6 && std::abs(tp_eta->at(it)) >= 0.8) + h_res_d0_I->Fill(matchtrk_d0->at(it) - tp_d0->at(it)); + else if (std::abs(tp_eta->at(it)) >= 1.6) + h_res_d0_F->Fill(matchtrk_d0->at(it) - tp_d0->at(it)); + + if (tp_pt->at(it) < 8.0) { + h_res_d0_L->Fill(matchtrk_d0->at(it) - tp_d0->at(it)); + if (std::abs(tp_eta->at(it)) < 1.0) + h_res_d0_C_L->Fill(matchtrk_d0->at(it) - tp_d0->at(it)); + else + h_res_d0_F_L->Fill(matchtrk_d0->at(it) - tp_d0->at(it)); + } else { + h_res_d0_H->Fill(matchtrk_d0->at(it) - tp_d0->at(it)); + if (std::abs(tp_eta->at(it)) < 1.0) + h_res_d0_C_H->Fill(matchtrk_d0->at(it) - tp_d0->at(it)); + else + h_res_d0_F_H->Fill(matchtrk_d0->at(it) - tp_d0->at(it)); + } + } + + // ---------------------------------------------------------------------------------------------------------------- + // fill resolution vs. pt histograms + for (int im = 0; im < nRANGE; im++) { + if ((tp_pt->at(it) > (float)im * 5.0) && (tp_pt->at(it) < (float)(im + 1) * 5.0)) { + h_resVsPt_pt[im]->Fill(matchtrk_pt->at(it) - tp_pt->at(it)); + h_resVsPt_ptRel[im]->Fill((matchtrk_pt->at(it) - tp_pt->at(it)) / tp_pt->at(it)); + h_resVsPt_eta[im]->Fill(matchtrk_eta->at(it) - tp_eta->at(it)); + h_resVsPt_phi[im]->Fill(matchtrk_phi->at(it) - tp_phi->at(it)); + h_resVsPt_z0[im]->Fill(matchtrk_z0->at(it) - tp_z0->at(it)); + + h_absResVsPt_pt[im]->Fill(std::abs(matchtrk_pt->at(it) - tp_pt->at(it))); + h_absResVsPt_ptRel[im]->Fill(std::abs((matchtrk_pt->at(it) - tp_pt->at(it))) / tp_pt->at(it)); + h_absResVsPt_z0[im]->Fill(std::abs(matchtrk_z0->at(it) - tp_z0->at(it))); + h_absResVsPt_phi[im]->Fill(std::abs(matchtrk_phi->at(it) - tp_phi->at(it))); + h_absResVsPt_eta[im]->Fill(std::abs(matchtrk_eta->at(it) - tp_eta->at(it))); + + if (std::abs(tp_eta->at(it)) < 0.8) { + h_resVsPt_pt_C[im]->Fill(matchtrk_pt->at(it) - tp_pt->at(it)); + h_resVsPt_ptRel_C[im]->Fill((matchtrk_pt->at(it) - tp_pt->at(it)) / tp_pt->at(it)); + h_resVsPt_z0_C[im]->Fill(matchtrk_z0->at(it) - tp_z0->at(it)); + h_resVsPt_phi_C[im]->Fill(matchtrk_phi->at(it) - tp_phi->at(it)); + } else if (std::abs(tp_eta->at(it)) < 1.6 && std::abs(tp_eta->at(it)) >= 0.8) { + h_resVsPt_pt_I[im]->Fill(matchtrk_pt->at(it) - tp_pt->at(it)); + h_resVsPt_ptRel_I[im]->Fill((matchtrk_pt->at(it) - tp_pt->at(it)) / tp_pt->at(it)); + h_resVsPt_z0_I[im]->Fill(matchtrk_z0->at(it) - tp_z0->at(it)); + h_resVsPt_phi_I[im]->Fill(matchtrk_phi->at(it) - tp_phi->at(it)); + } else if (std::abs(tp_eta->at(it)) >= 1.6) { + h_resVsPt_pt_F[im]->Fill(matchtrk_pt->at(it) - tp_pt->at(it)); + h_resVsPt_ptRel_F[im]->Fill((matchtrk_pt->at(it) - tp_pt->at(it)) / tp_pt->at(it)); + h_resVsPt_z0_F[im]->Fill(matchtrk_z0->at(it) - tp_z0->at(it)); + h_resVsPt_phi_F[im]->Fill(matchtrk_phi->at(it) - tp_phi->at(it)); + } + + if (matchtrk_d0->at(it) < 999) { + h_resVsPt_d0[im]->Fill(matchtrk_d0->at(it) - tp_d0->at(it)); + h_absResVsPt_d0[im]->Fill(std::abs(matchtrk_d0->at(it) - tp_d0->at(it))); + } + } + } + + for (int im = 4; im < nRANGE_L + 4; im++) { + if ((tp_pt->at(it) > (float)im * 0.5) && (tp_pt->at(it) <= (float)(im + 1) * 0.5)) { + h_absResVsPt_pt_L[im - 4]->Fill(std::abs(matchtrk_pt->at(it) - tp_pt->at(it))); + h_absResVsPt_ptRel_L[im - 4]->Fill(std::abs((matchtrk_pt->at(it) - tp_pt->at(it))) / tp_pt->at(it)); + h_absResVsPt_z0_L[im - 4]->Fill(std::abs(matchtrk_z0->at(it) - tp_z0->at(it))); + h_absResVsPt_phi_L[im - 4]->Fill(std::abs(matchtrk_phi->at(it) - tp_phi->at(it))); + h_absResVsPt_eta_L[im - 4]->Fill(std::abs(matchtrk_eta->at(it) - tp_eta->at(it))); + h_absResVsPt_d0_L[im - 4]->Fill(std::abs(matchtrk_d0->at(it) - tp_d0->at(it))); + } + } + + // ---------------------------------------------------------------------------------------------------------------- + // fill resolution vs. eta histograms + for (int im = 0; im < nETARANGE; im++) { + if ((std::abs(tp_eta->at(it)) > (float)im * 0.1) && (std::abs(tp_eta->at(it)) < (float)(im + 1) * 0.1)) { + h_resVsEta_ptRel[im]->Fill((matchtrk_pt->at(it) - tp_pt->at(it)) / tp_pt->at(it)); + h_resVsEta_eta[im]->Fill(matchtrk_eta->at(it) - tp_eta->at(it)); + h_resVsEta_phi[im]->Fill(matchtrk_phi->at(it) - tp_phi->at(it)); + h_resVsEta_z0[im]->Fill(matchtrk_z0->at(it) - tp_z0->at(it)); + + h_absResVsEta_ptRel[im]->Fill(std::abs((matchtrk_pt->at(it) - tp_pt->at(it))) / tp_pt->at(it)); + h_absResVsEta_eta[im]->Fill(std::abs(matchtrk_eta->at(it) - tp_eta->at(it))); + h_absResVsEta_phi[im]->Fill(std::abs(matchtrk_phi->at(it) - tp_phi->at(it))); + h_absResVsEta_z0[im]->Fill(std::abs(matchtrk_z0->at(it) - tp_z0->at(it))); + + if (tp_pt->at(it) < 8.0) { + h_resVsEta_ptRel_L[im]->Fill((matchtrk_pt->at(it) - tp_pt->at(it)) / tp_pt->at(it)); + h_resVsEta_eta_L[im]->Fill(matchtrk_eta->at(it) - tp_eta->at(it)); + h_resVsEta_z0_L[im]->Fill(matchtrk_z0->at(it) - tp_z0->at(it)); + h_resVsEta_phi_L[im]->Fill(matchtrk_phi->at(it) - tp_phi->at(it)); + + h_absResVsEta_ptRel_L[im]->Fill(std::abs((matchtrk_pt->at(it) - tp_pt->at(it))) / tp_pt->at(it)); + h_absResVsEta_eta_L[im]->Fill(std::abs(matchtrk_eta->at(it) - tp_eta->at(it))); + h_absResVsEta_phi_L[im]->Fill(std::abs(matchtrk_phi->at(it) - tp_phi->at(it))); + h_absResVsEta_z0_L[im]->Fill(std::abs(matchtrk_z0->at(it) - tp_z0->at(it))); + + if (matchtrk_d0->at(it) < 999) { + h_resVsEta_d0_L[im]->Fill(matchtrk_d0->at(it) - tp_d0->at(it)); + h_absResVsEta_d0_L[im]->Fill(std::abs(matchtrk_d0->at(it) - tp_d0->at(it))); + } + } else { + h_resVsEta_ptRel_H[im]->Fill((matchtrk_pt->at(it) - tp_pt->at(it)) / tp_pt->at(it)); + h_resVsEta_eta_H[im]->Fill(matchtrk_eta->at(it) - tp_eta->at(it)); + h_resVsEta_z0_H[im]->Fill(matchtrk_z0->at(it) - tp_z0->at(it)); + h_resVsEta_phi_H[im]->Fill(matchtrk_phi->at(it) - tp_phi->at(it)); + + h_absResVsEta_ptRel_H[im]->Fill(std::abs((matchtrk_pt->at(it) - tp_pt->at(it))) / tp_pt->at(it)); + h_absResVsEta_eta_H[im]->Fill(std::abs(matchtrk_eta->at(it) - tp_eta->at(it))); + h_absResVsEta_phi_H[im]->Fill(std::abs(matchtrk_phi->at(it) - tp_phi->at(it))); + h_absResVsEta_z0_H[im]->Fill(std::abs(matchtrk_z0->at(it) - tp_z0->at(it))); + + if (matchtrk_d0->at(it) < 999) { + h_resVsEta_d0_H[im]->Fill(matchtrk_d0->at(it) - tp_d0->at(it)); + h_absResVsEta_d0_H[im]->Fill(std::abs(matchtrk_d0->at(it) - tp_d0->at(it))); + } + } + + if (matchtrk_d0->at(it) < 999) { + h_resVsEta_d0[im]->Fill(matchtrk_d0->at(it) - tp_d0->at(it)); + h_absResVsEta_d0[im]->Fill(std::abs(matchtrk_d0->at(it) - tp_d0->at(it))); + } + } + } + + // ---------------------------------------------------------------------------------------------------------------- + // fill resolution vs. phi histograms + for (int im = 0; im < nPHIRANGE; im++) { + if ((tp_phi->at(it) > (float)im * 0.2 - 3.2) && (tp_phi->at(it) < (float)(im + 1) * 0.2 - 3.2)) { + h_absResVsPhi_pt[im]->Fill(std::abs(matchtrk_pt->at(it) - tp_pt->at(it))); + h_absResVsPhi_ptRel[im]->Fill(std::abs((matchtrk_pt->at(it) - tp_pt->at(it))) / tp_pt->at(it)); + } + } + + } // end of matched track loop + + } // end of event loop + // ---------------------------------------------------------------------------------------------------------------- + + // ---------------------------------------------------------------------------------------------------------------- + // Post-event-loop histogram normalization(s) + + // Normalize tracklet efficiency by each eta slice + double maxBinContents; + double etaRes = trackletEffMaxEta / trackletEffEtaBins; + for (double etaBin = 0; etaBin < trackletEffEtaBins; + etaBin++) { //loop through eta bin values (constants defined with relevant hist defs) + maxBinContents = 0; + std::vector binContents = {}; + for (int layer = 0; layer < numLayers; layer++) { + binContents.push_back(h_trk_tracklet_hits->GetBinContent(etaBin + 1, layer + 1)); + maxBinContents = std::max(maxBinContents, binContents.back()); + } + float binWeight; + for (int layer = 0; layer < numLayers; layer++) { + binWeight = (maxBinContents == 0) ? 0 : binContents.at(layer) / maxBinContents; + h_trk_tracklet_eff->Fill((etaBin + 0.5) * etaRes, layer, binWeight); + } + } + + // Adjust tracklet hits and efficiency histograms for aesthetics + + // ---------------------------------------------------------------------------------------------------------------- + // 2D plots + // ---------------------------------------------------------------------------------------------------------------- + + TH1F* h2_resVsPt_pt = new TH1F("resVsPt2_pt", ";Tracking particle p_{T} [GeV]; p_{T} resolution [GeV]", 20, 0, 100); + TH1F* h2_resVsPt_pt_C = + new TH1F("resVsPt2_pt_C", ";Tracking particle p_{T} [GeV]; p_{T} resolution [GeV]", 20, 0, 100); + TH1F* h2_resVsPt_pt_I = + new TH1F("resVsPt2_pt_I", ";Tracking particle p_{T} [GeV]; p_{T} resolution [GeV]", 20, 0, 100); + TH1F* h2_resVsPt_pt_F = + new TH1F("resVsPt2_pt_F", ";Tracking particle p_{T} [GeV]; p_{T} resolution [GeV]", 20, 0, 100); + + TH1F* h2_resVsPt_ptRel = + new TH1F("resVsPt2_ptRel", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", 20, 0, 100); + TH1F* h2_resVsPt_ptRel_C = + new TH1F("resVsPt2_ptRel_C", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", 20, 0, 100); + TH1F* h2_resVsPt_ptRel_I = + new TH1F("resVsPt2_ptRel_I", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", 20, 0, 100); + TH1F* h2_resVsPt_ptRel_F = + new TH1F("resVsPt2_ptRel_F", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", 20, 0, 100); + + TH1F* h2_mresVsPt_pt = + new TH1F("mresVsPt2_pt", ";Tracking particle p_{T} [GeV]; Mean(p_{T} residual) [GeV]", 20, 0, 100); + TH1F* h2_mresVsPt_pt_C = + new TH1F("mresVsPt2_pt_C", ";Tracking particle p_{T} [GeV]; Mean(p_{T} residual) [GeV]", 20, 0, 100); + TH1F* h2_mresVsPt_pt_I = + new TH1F("mresVsPt2_pt_I", ";Tracking particle p_{T} [GeV]; Mean(p_{T} residual) [GeV]", 20, 0, 100); + TH1F* h2_mresVsPt_pt_F = + new TH1F("mresVsPt2_pt_F", ";Tracking particle p_{T} [GeV]; Mean(p_{T} residual) [GeV]", 20, 0, 100); + + TH1F* h2_resVsPt_z0 = new TH1F("resVsPt2_z0", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", 20, 0, 100); + TH1F* h2_resVsPt_z0_C = + new TH1F("resVsPt2_z0_C", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", 20, 0, 100); + TH1F* h2_resVsPt_z0_I = + new TH1F("resVsPt2_z0_I", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", 20, 0, 100); + TH1F* h2_resVsPt_z0_F = + new TH1F("resVsPt2_z0_F", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", 20, 0, 100); + + TH1F* h2_resVsPt_phi = new TH1F("resVsPt2_phi", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", 20, 0, 100); + TH1F* h2_resVsPt_phi_C = + new TH1F("resVsPt2_phi_C", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", 20, 0, 100); + TH1F* h2_resVsPt_phi_I = + new TH1F("resVsPt2_phi_I", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", 20, 0, 100); + TH1F* h2_resVsPt_phi_F = + new TH1F("resVsPt2_phi_F", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", 20, 0, 100); + + TH1F* h2_resVsPt_eta = new TH1F("resVsPt2_eta", ";Tracking particle p_{T} [GeV]; #eta resolution", 20, 0, 100); + + TH1F* h2_resVsPt_d0 = new TH1F("resVsPt2_d0", ";Tracking particle p_{T} [GeV]; d_{0} resolution [cm]", 20, 0, 100); + + TH1F* h2_resVsPt_pt_68 = + new TH1F("resVsPt2_pt_68", ";Tracking particle p_{T} [GeV]; p_{T} resolution [GeV]", 20, 0, 100); + TH1F* h2_resVsPt_ptRel_68 = + new TH1F("resVsPt2_ptRel_68", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", 20, 0, 100); + TH1F* h2_resVsPt_z0_68 = + new TH1F("resVsPt2_z0_68", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", 20, 0, 100); + TH1F* h2_resVsPt_phi_68 = + new TH1F("resVsPt2_phi_68", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", 20, 0, 100); + TH1F* h2_resVsPt_eta_68 = new TH1F("resVsPt2_eta_68", ";Tracking particle p_{T} [GeV]; #eta resolution", 20, 0, 100); + TH1F* h2_resVsPt_d0_68 = + new TH1F("resVsPt2_d0_68", ";Tracking particle p_{T} [GeV]; d_{0} resolution [cm]", 20, 0, 100); + + TH1F* h2_resVsPt_pt_90 = + new TH1F("resVsPt2_pt_90", ";Tracking particle p_{T} [GeV]; p_{T} resolution [GeV]", 20, 0, 100); + TH1F* h2_resVsPt_ptRel_90 = + new TH1F("resVsPt2_ptRel_90", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", 20, 0, 100); + TH1F* h2_resVsPt_z0_90 = + new TH1F("resVsPt2_z0_90", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", 20, 0, 100); + TH1F* h2_resVsPt_phi_90 = + new TH1F("resVsPt2_phi_90", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", 20, 0, 100); + TH1F* h2_resVsPt_eta_90 = new TH1F("resVsPt2_eta_90", ";Tracking particle p_{T} [GeV]; #eta resolution", 20, 0, 100); + TH1F* h2_resVsPt_d0_90 = + new TH1F("resVsPt2_d0_90", ";Tracking particle p_{T} [GeV]; d_{0} resolution [cm]", 20, 0, 100); + + TH1F* h2_resVsPt_pt_99 = + new TH1F("resVsPt2_pt_99", ";Tracking particle p_{T} [GeV]; p_{T} resolution [GeV]", 20, 0, 100); + TH1F* h2_resVsPt_ptRel_99 = + new TH1F("resVsPt2_ptRel_99", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", 20, 0, 100); + TH1F* h2_resVsPt_z0_99 = + new TH1F("resVsPt2_z0_99", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", 20, 0, 100); + TH1F* h2_resVsPt_phi_99 = + new TH1F("resVsPt2_phi_99", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", 20, 0, 100); + TH1F* h2_resVsPt_eta_99 = new TH1F("resVsPt2_eta_99", ";Tracking particle p_{T} [GeV]; #eta resolution", 20, 0, 100); + TH1F* h2_resVsPt_d0_99 = + new TH1F("resVsPt2_d0_99", ";Tracking particle p_{T} [GeV]; d_{0} resolution [cm]", 20, 0, 100); + + TH1F* h2_resVsPt_pt_L_68 = + new TH1F("resVsPt2_pt_L_68", ";Tracking particle p_{T} [GeV]; p_{T} resolution [GeV]", nRANGE_L, 2, 8); + TH1F* h2_resVsPt_ptRel_L_68 = + new TH1F("resVsPt2_ptRel_L_68", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", nRANGE_L, 2, 8); + TH1F* h2_resVsPt_z0_L_68 = + new TH1F("resVsPt2_z0_L_68", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", nRANGE_L, 2, 8); + TH1F* h2_resVsPt_phi_L_68 = + new TH1F("resVsPt2_phi_L_68", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", nRANGE_L, 2, 8); + TH1F* h2_resVsPt_eta_L_68 = + new TH1F("resVsPt2_eta_L_68", ";Tracking particle p_{T} [GeV]; #eta resolution", nRANGE_L, 2, 8); + TH1F* h2_resVsPt_d0_L_68 = + new TH1F("resVsPt2_d0_L_68", ";Tracking particle p_{T} [GeV]; d_{0} resolution [cm]", nRANGE_L, 2, 8); + + TH1F* h2_resVsPt_pt_L_90 = + new TH1F("resVsPt2_pt_L_90", ";Tracking particle p_{T} [GeV]; p_{T} resolution [GeV]", nRANGE_L, 2, 8); + TH1F* h2_resVsPt_ptRel_L_90 = + new TH1F("resVsPt2_ptRel_L_90", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", nRANGE_L, 2, 8); + TH1F* h2_resVsPt_z0_L_90 = + new TH1F("resVsPt2_z0_L_90", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", nRANGE_L, 2, 8); + TH1F* h2_resVsPt_phi_L_90 = + new TH1F("resVsPt2_phi_L_90", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", nRANGE_L, 2, 8); + TH1F* h2_resVsPt_eta_L_90 = + new TH1F("resVsPt2_eta_L_90", ";Tracking particle p_{T} [GeV]; #eta resolution", nRANGE_L, 2, 8); + TH1F* h2_resVsPt_d0_L_90 = + new TH1F("resVsPt2_d0_L_90", ";Tracking particle p_{T} [GeV]; d_{0} resolution [cm]", nRANGE_L, 2, 8); + + TH1F* h2_resVsPt_pt_L_99 = + new TH1F("resVsPt2_pt_L_99", ";Tracking particle p_{T} [GeV]; p_{T} resolution [cm]", nRANGE_L, 2, 8); + TH1F* h2_resVsPt_ptRel_L_99 = + new TH1F("resVsPt2_ptRel_L_99", ";Tracking particle p_{T} [GeV]; p_{T} resolution / p_{T}", nRANGE_L, 2, 8); + TH1F* h2_resVsPt_z0_L_99 = + new TH1F("resVsPt2_z0_L_99", ";Tracking particle p_{T} [GeV]; z_{0} resolution [cm]", nRANGE_L, 2, 8); + TH1F* h2_resVsPt_phi_L_99 = + new TH1F("resVsPt2_phi_L_99", ";Tracking particle p_{T} [GeV]; #phi resolution [rad]", nRANGE_L, 2, 8); + TH1F* h2_resVsPt_eta_L_99 = + new TH1F("resVsPt2_eta_L_99", ";Tracking particle p_{T} [GeV]; #eta resolution", nRANGE_L, 2, 8); + TH1F* h2_resVsPt_d0_L_99 = + new TH1F("resVsPt2_d0_L_99", ";Tracking particle p_{T} [GeV]; d_{0} resolution [cm]", nRANGE_L, 2, 8); + + for (int i = 0; i < nRANGE; i++) { + // set bin content and error + h2_resVsPt_pt->SetBinContent(i + 1, h_resVsPt_pt[i]->GetRMS()); + h2_resVsPt_pt->SetBinError(i + 1, h_resVsPt_pt[i]->GetRMSError()); + h2_resVsPt_pt_C->SetBinContent(i + 1, h_resVsPt_pt_C[i]->GetRMS()); + h2_resVsPt_pt_C->SetBinError(i + 1, h_resVsPt_pt_C[i]->GetRMSError()); + h2_resVsPt_pt_I->SetBinContent(i + 1, h_resVsPt_pt_I[i]->GetRMS()); + h2_resVsPt_pt_I->SetBinError(i + 1, h_resVsPt_pt_I[i]->GetRMSError()); + h2_resVsPt_pt_F->SetBinContent(i + 1, h_resVsPt_pt_F[i]->GetRMS()); + h2_resVsPt_pt_F->SetBinError(i + 1, h_resVsPt_pt_F[i]->GetRMSError()); + + h2_resVsPt_ptRel->SetBinContent(i + 1, h_resVsPt_ptRel[i]->GetRMS()); + h2_resVsPt_ptRel->SetBinError(i + 1, h_resVsPt_ptRel[i]->GetRMSError()); + h2_resVsPt_ptRel_C->SetBinContent(i + 1, h_resVsPt_ptRel_C[i]->GetRMS()); + h2_resVsPt_ptRel_C->SetBinError(i + 1, h_resVsPt_ptRel_C[i]->GetRMSError()); + h2_resVsPt_ptRel_I->SetBinContent(i + 1, h_resVsPt_ptRel_I[i]->GetRMS()); + h2_resVsPt_ptRel_I->SetBinError(i + 1, h_resVsPt_ptRel_I[i]->GetRMSError()); + h2_resVsPt_ptRel_F->SetBinContent(i + 1, h_resVsPt_ptRel_F[i]->GetRMS()); + h2_resVsPt_ptRel_F->SetBinError(i + 1, h_resVsPt_ptRel_F[i]->GetRMSError()); + + h2_mresVsPt_pt->SetBinContent(i + 1, h_resVsPt_pt[i]->GetMean()); + h2_mresVsPt_pt->SetBinError(i + 1, h_resVsPt_pt[i]->GetMeanError()); + h2_mresVsPt_pt_C->SetBinContent(i + 1, h_resVsPt_pt_C[i]->GetMean()); + h2_mresVsPt_pt_C->SetBinError(i + 1, h_resVsPt_pt_C[i]->GetMeanError()); + h2_mresVsPt_pt_I->SetBinContent(i + 1, h_resVsPt_pt_I[i]->GetMean()); + h2_mresVsPt_pt_I->SetBinError(i + 1, h_resVsPt_pt_I[i]->GetMeanError()); + h2_mresVsPt_pt_F->SetBinContent(i + 1, h_resVsPt_pt_F[i]->GetMean()); + h2_mresVsPt_pt_F->SetBinError(i + 1, h_resVsPt_pt_F[i]->GetMeanError()); + + h2_resVsPt_z0->SetBinContent(i + 1, h_resVsPt_z0[i]->GetRMS()); + h2_resVsPt_z0->SetBinError(i + 1, h_resVsPt_z0[i]->GetRMSError()); + h2_resVsPt_z0_C->SetBinContent(i + 1, h_resVsPt_z0_C[i]->GetRMS()); + h2_resVsPt_z0_C->SetBinError(i + 1, h_resVsPt_z0_C[i]->GetRMSError()); + h2_resVsPt_z0_I->SetBinContent(i + 1, h_resVsPt_z0_I[i]->GetRMS()); + h2_resVsPt_z0_I->SetBinError(i + 1, h_resVsPt_z0_I[i]->GetRMSError()); + h2_resVsPt_z0_F->SetBinContent(i + 1, h_resVsPt_z0_F[i]->GetRMS()); + h2_resVsPt_z0_F->SetBinError(i + 1, h_resVsPt_z0_F[i]->GetRMSError()); + + h2_resVsPt_phi->SetBinContent(i + 1, h_resVsPt_phi[i]->GetRMS()); + h2_resVsPt_phi->SetBinError(i + 1, h_resVsPt_phi[i]->GetRMSError()); + h2_resVsPt_phi_C->SetBinContent(i + 1, h_resVsPt_phi_C[i]->GetRMS()); + h2_resVsPt_phi_C->SetBinError(i + 1, h_resVsPt_phi_C[i]->GetRMSError()); + h2_resVsPt_phi_I->SetBinContent(i + 1, h_resVsPt_phi_I[i]->GetRMS()); + h2_resVsPt_phi_I->SetBinError(i + 1, h_resVsPt_phi_I[i]->GetRMSError()); + h2_resVsPt_phi_F->SetBinContent(i + 1, h_resVsPt_phi_F[i]->GetRMS()); + h2_resVsPt_phi_F->SetBinError(i + 1, h_resVsPt_phi_F[i]->GetRMSError()); + + h2_resVsPt_eta->SetBinContent(i + 1, h_resVsPt_eta[i]->GetRMS()); + h2_resVsPt_eta->SetBinError(i + 1, h_resVsPt_eta[i]->GetRMSError()); + + h2_resVsPt_d0->SetBinContent(i + 1, h_resVsPt_d0[i]->GetRMS()); + h2_resVsPt_d0->SetBinError(i + 1, h_resVsPt_d0[i]->GetRMSError()); + + h2_resVsPt_pt_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_pt[i], 0.68)); + h2_resVsPt_pt_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_pt[i], 0.90)); + h2_resVsPt_pt_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_pt[i], 0.99)); + + h2_resVsPt_ptRel_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_ptRel[i], 0.68)); + h2_resVsPt_ptRel_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_ptRel[i], 0.90)); + h2_resVsPt_ptRel_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_ptRel[i], 0.99)); + + h2_resVsPt_eta_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_eta[i], 0.68)); + h2_resVsPt_eta_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_eta[i], 0.90)); + h2_resVsPt_eta_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_eta[i], 0.99)); + + h2_resVsPt_z0_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_z0[i], 0.68)); + h2_resVsPt_z0_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_z0[i], 0.90)); + h2_resVsPt_z0_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_z0[i], 0.99)); + + h2_resVsPt_phi_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_phi[i], 0.68)); + h2_resVsPt_phi_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_phi[i], 0.90)); + h2_resVsPt_phi_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_phi[i], 0.99)); + + h2_resVsPt_d0_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_d0[i], 0.68)); + h2_resVsPt_d0_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_d0[i], 0.90)); + h2_resVsPt_d0_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_d0[i], 0.99)); + } + + for (int i = 0; i < nRANGE_L; i++) { + h2_resVsPt_pt_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_pt_L[i], 0.68)); + h2_resVsPt_pt_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_pt_L[i], 0.90)); + h2_resVsPt_pt_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_pt_L[i], 0.99)); + + h2_resVsPt_ptRel_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_ptRel_L[i], 0.68)); + h2_resVsPt_ptRel_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_ptRel_L[i], 0.90)); + h2_resVsPt_ptRel_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_ptRel_L[i], 0.99)); + + h2_resVsPt_eta_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_eta_L[i], 0.68)); + h2_resVsPt_eta_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_eta_L[i], 0.90)); + h2_resVsPt_eta_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_eta_L[i], 0.99)); + + h2_resVsPt_z0_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_z0_L[i], 0.68)); + h2_resVsPt_z0_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_z0_L[i], 0.90)); + h2_resVsPt_z0_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_z0_L[i], 0.99)); + + h2_resVsPt_phi_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_phi_L[i], 0.68)); + h2_resVsPt_phi_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_phi_L[i], 0.90)); + h2_resVsPt_phi_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_phi_L[i], 0.99)); + + h2_resVsPt_d0_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_d0_L[i], 0.68)); + h2_resVsPt_d0_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_d0_L[i], 0.90)); + h2_resVsPt_d0_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPt_d0_L[i], 0.99)); + } + + // resolution vs. eta histograms + TH1F* h2_resVsEta_eta = new TH1F("resVsEta_eta", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_eta_L = new TH1F("resVsEta_eta_L", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_eta_H = new TH1F("resVsEta_eta_H", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, 2.4); + + TH1F* h2_resVsEta_z0 = new TH1F("resVsEta_z0", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_z0_L = + new TH1F("resVsEta_z0_L", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_z0_H = + new TH1F("resVsEta_z0_H", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, 2.4); + + TH1F* h2_resVsEta_phi = + new TH1F("resVsEta_phi", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_phi_L = + new TH1F("resVsEta_phi_L", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_phi_H = + new TH1F("resVsEta_phi_H", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, 2.4); + + TH1F* h2_resVsEta_ptRel = + new TH1F("resVsEta_ptRel", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_ptRel_L = + new TH1F("resVsEta_ptRel_L", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_ptRel_H = + new TH1F("resVsEta_ptRel_H", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, 2.4); + + TH1F* h2_resVsEta_d0 = new TH1F("resVsEta_d0", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_d0_L = + new TH1F("resVsEta_d0_L", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_d0_H = + new TH1F("resVsEta_d0_H", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, 2.4); + + // mean of residuals + TH1F* h2_mresVsEta_eta = + new TH1F("mresVsEta_eta", ";Tracking particle |#eta|; Mean(#eta residual)", nETARANGE, 0, 2.4); + TH1F* h2_mresVsEta_z0 = + new TH1F("mresVsEta_z0", ";Tracking particle |#eta|; Mean(z_{0} residual) [cm]", nETARANGE, 0, 2.4); + TH1F* h2_mresVsEta_phi = + new TH1F("mresVsEta_phi", ";Tracking particle |#eta|; Mean(phi residual) [rad]", nETARANGE, 0, 2.4); + TH1F* h2_mresVsEta_ptRel = + new TH1F("mresVsEta_ptRel", ";Tracking particle |#eta|; Mean(ptrel residual)", nETARANGE, 0, 2.4); + + // 68 / 90 / 99% residuals + TH1F* h2_resVsEta_eta_68 = + new TH1F("resVsEta_eta_68", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_eta_90 = + new TH1F("resVsEta_eta_90", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_eta_99 = + new TH1F("resVsEta_eta_99", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, 2.4); + + TH1F* h2_resVsEta_z0_68 = + new TH1F("resVsEta_z0_68", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_z0_90 = + new TH1F("resVsEta_z0_90", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_z0_99 = + new TH1F("resVsEta_z0_99", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, 2.4); + + TH1F* h2_resVsEta_phi_68 = + new TH1F("resVsEta_phi_68", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_phi_90 = + new TH1F("resVsEta_phi_90", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_phi_99 = + new TH1F("resVsEta_phi_99", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, 2.4); + + TH1F* h2_resVsEta_ptRel_68 = + new TH1F("resVsEta_ptRel_68", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_ptRel_90 = + new TH1F("resVsEta_ptRel_90", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_ptRel_99 = + new TH1F("resVsEta_ptRel_99", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, 2.4); + + TH1F* h2_resVsEta_d0_68 = + new TH1F("resVsEta_d0_68", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_d0_90 = + new TH1F("resVsEta_d0_90", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_d0_99 = + new TH1F("resVsEta_d0_99", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, 2.4); + + TH1F* h2_resVsEta_eta_L_68 = + new TH1F("resVsEta_eta_L_68", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_z0_L_68 = + new TH1F("resVsEta_z0_L_68", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_phi_L_68 = + new TH1F("resVsEta_phi_L_68", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_ptRel_L_68 = + new TH1F("resVsEta_ptRel_L_68", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_d0_L_68 = + new TH1F("resVsEta_d0_L_68", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, 2.4); + + TH1F* h2_resVsEta_eta_L_90 = + new TH1F("resVsEta_eta_L_90", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_z0_L_90 = + new TH1F("resVsEta_z0_L_90", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_phi_L_90 = + new TH1F("resVsEta_phi_L_90", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_ptRel_L_90 = + new TH1F("resVsEta_ptRel_L_90", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_d0_L_90 = + new TH1F("resVsEta_d0_L_90", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, 2.4); + + TH1F* h2_resVsEta_eta_L_99 = + new TH1F("resVsEta_eta_L_99", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_z0_L_99 = + new TH1F("resVsEta_z0_L_99", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_phi_L_99 = + new TH1F("resVsEta_phi_L_99", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_ptRel_L_99 = + new TH1F("resVsEta_ptRel_L_99", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_d0_L_99 = + new TH1F("resVsEta_d0_L_99", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, 2.4); + + TH1F* h2_resVsEta_eta_H_68 = + new TH1F("resVsEta_eta_H_68", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_z0_H_68 = + new TH1F("resVsEta_z0_H_68", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_phi_H_68 = + new TH1F("resVsEta_phi_H_68", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_ptRel_H_68 = + new TH1F("resVsEta_ptRel_H_68", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_d0_H_68 = + new TH1F("resVsEta_d0_H_68", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, 2.4); + + TH1F* h2_resVsEta_eta_H_90 = + new TH1F("resVsEta_eta_H_90", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_z0_H_90 = + new TH1F("resVsEta_z0_H_90", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_phi_H_90 = + new TH1F("resVsEta_phi_H_90", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_ptRel_H_90 = + new TH1F("resVsEta_ptRel_H_90", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_d0_H_90 = + new TH1F("resVsEta_d0_H_90", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, 2.4); + + TH1F* h2_resVsEta_eta_H_99 = + new TH1F("resVsEta_eta_H_99", ";Tracking particle |#eta|; #eta resolution", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_z0_H_99 = + new TH1F("resVsEta_z0_H_99", ";Tracking particle |#eta|; z_{0} resolution [cm]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_phi_H_99 = + new TH1F("resVsEta_phi_H_99", ";Tracking particle |#eta|; #phi resolution [rad]", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_ptRel_H_99 = + new TH1F("resVsEta_ptRel_H_99", ";Tracking particle |#eta|; p_{T} resolution / p_{T}", nETARANGE, 0, 2.4); + TH1F* h2_resVsEta_d0_H_99 = + new TH1F("resVsEta_d0_H_99", ";Tracking particle |#eta|; d_{0} resolution [cm]", nETARANGE, 0, 2.4); + + // resolution vs. eta histograms (gaussian fit) + TH1F* h3_resVsEta_eta_L = new TH1F("resVsEta_eta_L_gaus", ";|#eta|; #sigma(#eta)", nETARANGE, 0, 2.4); + TH1F* h3_resVsEta_eta_H = new TH1F("resVsEta_eta_H_gaus", ";|#eta|; #sigma(#eta)", nETARANGE, 0, 2.4); + + TH1F* h3_resVsEta_z0_L = new TH1F("resVsEta_z0_L_gaus", ";|#eta|; #sigma(z_{0}) [cm]", nETARANGE, 0, 2.4); + TH1F* h3_resVsEta_z0_H = new TH1F("resVsEta_z0_H_gaus", ";|#eta|; #sigma(z_{0}) [cm]", nETARANGE, 0, 2.4); + + TH1F* h3_resVsEta_phi_L = new TH1F("resVsEta_phi_L_gaus", ";|#eta|; #sigma(#phi) [rad]", nETARANGE, 0, 2.4); + TH1F* h3_resVsEta_phi_H = new TH1F("resVsEta_phi_H_gaus", ";|#eta|; #sigma(#phi) [rad]", nETARANGE, 0, 2.4); + + TH1F* h3_resVsEta_ptRel_L = new TH1F("resVsEta_ptRel_L_gaus", ";|#eta|; #sigma(p_{T}) / p_{T}", nETARANGE, 0, 2.4); + TH1F* h3_resVsEta_ptRel_H = new TH1F("resVsEta_ptRel_H_gaus", ";|#eta|; #sigma(p_{T}) / p_{T}", nETARANGE, 0, 2.4); + + TString fitdir = "FitResults/"; + + for (int i = 0; i < nETARANGE; i++) { + // set bin content and error + h2_resVsEta_eta->SetBinContent(i + 1, h_resVsEta_eta[i]->GetRMS()); + h2_resVsEta_eta->SetBinError(i + 1, h_resVsEta_eta[i]->GetRMSError()); + h2_resVsEta_eta_L->SetBinContent(i + 1, h_resVsEta_eta_L[i]->GetRMS()); + h2_resVsEta_eta_L->SetBinError(i + 1, h_resVsEta_eta_L[i]->GetRMSError()); + h2_resVsEta_eta_H->SetBinContent(i + 1, h_resVsEta_eta_H[i]->GetRMS()); + h2_resVsEta_eta_H->SetBinError(i + 1, h_resVsEta_eta_H[i]->GetRMSError()); + + h2_resVsEta_z0->SetBinContent(i + 1, h_resVsEta_z0[i]->GetRMS()); + h2_resVsEta_z0->SetBinError(i + 1, h_resVsEta_z0[i]->GetRMSError()); + h2_resVsEta_z0_L->SetBinContent(i + 1, h_resVsEta_z0_L[i]->GetRMS()); + h2_resVsEta_z0_L->SetBinError(i + 1, h_resVsEta_z0_L[i]->GetRMSError()); + h2_resVsEta_z0_H->SetBinContent(i + 1, h_resVsEta_z0_H[i]->GetRMS()); + h2_resVsEta_z0_H->SetBinError(i + 1, h_resVsEta_z0_H[i]->GetRMSError()); + + h2_resVsEta_phi->SetBinContent(i + 1, h_resVsEta_phi[i]->GetRMS()); + h2_resVsEta_phi->SetBinError(i + 1, h_resVsEta_phi[i]->GetRMSError()); + h2_resVsEta_phi_L->SetBinContent(i + 1, h_resVsEta_phi_L[i]->GetRMS()); + h2_resVsEta_phi_L->SetBinError(i + 1, h_resVsEta_phi_L[i]->GetRMSError()); + h2_resVsEta_phi_H->SetBinContent(i + 1, h_resVsEta_phi_H[i]->GetRMS()); + h2_resVsEta_phi_H->SetBinError(i + 1, h_resVsEta_phi_H[i]->GetRMSError()); + + h2_resVsEta_ptRel->SetBinContent(i + 1, h_resVsEta_ptRel[i]->GetRMS()); + h2_resVsEta_ptRel->SetBinError(i + 1, h_resVsEta_ptRel[i]->GetRMSError()); + h2_resVsEta_ptRel_L->SetBinContent(i + 1, h_resVsEta_ptRel_L[i]->GetRMS()); + h2_resVsEta_ptRel_L->SetBinError(i + 1, h_resVsEta_ptRel_L[i]->GetRMSError()); + h2_resVsEta_ptRel_H->SetBinContent(i + 1, h_resVsEta_ptRel_H[i]->GetRMS()); + h2_resVsEta_ptRel_H->SetBinError(i + 1, h_resVsEta_ptRel_H[i]->GetRMSError()); + + h2_mresVsEta_eta->SetBinContent(i + 1, h_resVsEta_eta[i]->GetMean()); + h2_mresVsEta_eta->SetBinError(i + 1, h_resVsEta_eta[i]->GetMeanError()); + h2_mresVsEta_z0->SetBinContent(i + 1, h_resVsEta_z0[i]->GetMean()); + h2_mresVsEta_z0->SetBinError(i + 1, h_resVsEta_z0[i]->GetMeanError()); + h2_mresVsEta_phi->SetBinContent(i + 1, h_resVsEta_phi[i]->GetMean()); + h2_mresVsEta_phi->SetBinError(i + 1, h_resVsEta_phi[i]->GetMeanError()); + h2_mresVsEta_ptRel->SetBinContent(i + 1, h_resVsEta_ptRel[i]->GetMean()); + h2_mresVsEta_ptRel->SetBinError(i + 1, h_resVsEta_ptRel[i]->GetMeanError()); + + h2_resVsEta_d0->SetBinContent(i + 1, h_resVsEta_d0[i]->GetRMS()); + h2_resVsEta_d0->SetBinError(i + 1, h_resVsEta_d0[i]->GetRMSError()); + h2_resVsEta_d0_L->SetBinContent(i + 1, h_resVsEta_d0_L[i]->GetRMS()); + h2_resVsEta_d0_L->SetBinError(i + 1, h_resVsEta_d0_L[i]->GetRMSError()); + h2_resVsEta_d0_H->SetBinContent(i + 1, h_resVsEta_d0_H[i]->GetRMS()); + h2_resVsEta_d0_H->SetBinError(i + 1, h_resVsEta_d0_H[i]->GetRMSError()); + + h2_resVsEta_eta_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_eta[i], 0.68)); + h2_resVsEta_eta_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_eta[i], 0.90)); + h2_resVsEta_eta_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_eta[i], 0.99)); + + h2_resVsEta_z0_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_z0[i], 0.68)); + h2_resVsEta_z0_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_z0[i], 0.90)); + h2_resVsEta_z0_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_z0[i], 0.99)); + + h2_resVsEta_phi_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_phi[i], 0.68)); + h2_resVsEta_phi_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_phi[i], 0.90)); + h2_resVsEta_phi_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_phi[i], 0.99)); + + h2_resVsEta_ptRel_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_ptRel[i], 0.68)); + h2_resVsEta_ptRel_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_ptRel[i], 0.90)); + h2_resVsEta_ptRel_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_ptRel[i], 0.99)); + + h2_resVsEta_d0_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_d0[i], 0.68)); + h2_resVsEta_d0_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_d0[i], 0.90)); + h2_resVsEta_d0_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_d0[i], 0.99)); + + h2_resVsEta_eta_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_eta_L[i], 0.68)); + h2_resVsEta_z0_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_z0_L[i], 0.68)); + h2_resVsEta_phi_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_phi_L[i], 0.68)); + h2_resVsEta_ptRel_L_68->SetBinContent(i + 1, + getIntervalContainingFractionOfEntries(h_absResVsEta_ptRel_L[i], 0.68)); + h2_resVsEta_d0_L_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_d0_L[i], 0.68)); + + h2_resVsEta_eta_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_eta_L[i], 0.90)); + h2_resVsEta_z0_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_z0_L[i], 0.90)); + h2_resVsEta_phi_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_phi_L[i], 0.90)); + h2_resVsEta_ptRel_L_90->SetBinContent(i + 1, + getIntervalContainingFractionOfEntries(h_absResVsEta_ptRel_L[i], 0.90)); + h2_resVsEta_d0_L_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_d0_L[i], 0.90)); + + h2_resVsEta_eta_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_eta_L[i], 0.99)); + h2_resVsEta_z0_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_z0_L[i], 0.99)); + h2_resVsEta_phi_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_phi_L[i], 0.99)); + h2_resVsEta_ptRel_L_99->SetBinContent(i + 1, + getIntervalContainingFractionOfEntries(h_absResVsEta_ptRel_L[i], 0.99)); + h2_resVsEta_d0_L_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_d0_L[i], 0.99)); + + h2_resVsEta_eta_H_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_eta_H[i], 0.68)); + h2_resVsEta_z0_H_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_z0_H[i], 0.68)); + h2_resVsEta_phi_H_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_phi_H[i], 0.68)); + h2_resVsEta_ptRel_H_68->SetBinContent(i + 1, + getIntervalContainingFractionOfEntries(h_absResVsEta_ptRel_H[i], 0.68)); + h2_resVsEta_d0_H_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_d0_H[i], 0.68)); + + h2_resVsEta_eta_H_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_eta_H[i], 0.90)); + h2_resVsEta_z0_H_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_z0_H[i], 0.90)); + h2_resVsEta_phi_H_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_phi_H[i], 0.90)); + h2_resVsEta_ptRel_H_90->SetBinContent(i + 1, + getIntervalContainingFractionOfEntries(h_absResVsEta_ptRel_H[i], 0.90)); + h2_resVsEta_d0_H_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_d0_H[i], 0.90)); + + h2_resVsEta_eta_H_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_eta_H[i], 0.99)); + h2_resVsEta_z0_H_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_z0_H[i], 0.99)); + h2_resVsEta_phi_H_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_phi_H[i], 0.99)); + h2_resVsEta_ptRel_H_99->SetBinContent(i + 1, + getIntervalContainingFractionOfEntries(h_absResVsEta_ptRel_H[i], 0.99)); + h2_resVsEta_d0_H_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsEta_d0_H[i], 0.99)); + + // --------------------------------------------------------------------------------------------------- + // gaussian fit instead + // --------------------------------------------------------------------------------------------------- + + if (doGausFit) { + TCanvas cfit; + char text[500]; + + float sigma = 0; + float esigma = 0; + TF1* fit; + + float rms = 0; + float erms = 0; + + fit = new TF1("fit", "gaus", -0.01, 0.01); + h_resVsEta_eta_L[i]->Fit("fit", "R"); + sigma = fit->GetParameter(2); + esigma = fit->GetParError(2); + rms = h_resVsEta_eta_L[i]->GetRMS(); + erms = h_resVsEta_eta_L[i]->GetRMSError(); + h3_resVsEta_eta_L->SetBinContent(i + 1, sigma); + h3_resVsEta_eta_L->SetBinError(i + 1, esigma); + h_resVsEta_eta_L[i]->Draw(); + sprintf(text, "RMS: %.4f +/- %.4f", rms, erms); + mySmallText(0.2, 0.86, 1, text); + sprintf(text, "Fit: %.4f +/- %.4f", sigma, esigma); + mySmallText(0.2, 0.8, 2, text); + sprintf(text, "p_{T} < 5 GeV"); + mySmallText(0.2, 0.7, 1, text); + cfit.SaveAs(fitdir + "resVsEta_eta_L_" + etarange[i] + ".pdf"); + delete fit; + + fit = new TF1("fit", "gaus", -0.01, 0.01); + h_resVsEta_eta_H[i]->Fit("fit", "R"); + sigma = fit->GetParameter(2); + esigma = fit->GetParError(2); + rms = h_resVsEta_eta_H[i]->GetRMS(); + erms = h_resVsEta_eta_H[i]->GetRMSError(); + h3_resVsEta_eta_H->SetBinContent(i + 1, sigma); + h3_resVsEta_eta_H->SetBinError(i + 1, esigma); + h_resVsEta_eta_H[i]->Draw(); + sprintf(text, "RMS: %.4f +/- %.4f", rms, erms); + mySmallText(0.2, 0.86, 1, text); + sprintf(text, "Fit: %.4f +/- %.4f", sigma, esigma); + mySmallText(0.2, 0.8, 2, text); + sprintf(text, "p_{T} > 15 GeV"); + mySmallText(0.2, 0.7, 1, text); + cfit.SaveAs(fitdir + "resVsEta_eta_H_" + etarange[i] + ".pdf"); + delete fit; + + fit = new TF1("fit", "gaus", -1, 1); + h_resVsEta_z0_L[i]->Fit("fit", "R"); + sigma = fit->GetParameter(2); + esigma = fit->GetParError(2); + rms = h_resVsEta_z0_L[i]->GetRMS(); + erms = h_resVsEta_z0_L[i]->GetRMSError(); + h3_resVsEta_z0_L->SetBinContent(i + 1, sigma); + h3_resVsEta_z0_L->SetBinError(i + 1, esigma); + h_resVsEta_z0_L[i]->Draw(); + sprintf(text, "RMS: %.4f +/- %.4f", rms, erms); + mySmallText(0.2, 0.86, 1, text); + sprintf(text, "Fit: %.4f +/- %.4f", sigma, esigma); + mySmallText(0.2, 0.8, 2, text); + sprintf(text, "p_{T} < 5 GeV"); + mySmallText(0.2, 0.7, 1, text); + cfit.SaveAs(fitdir + "resVsEta_z0_L_" + etarange[i] + ".pdf"); + delete fit; + + fit = new TF1("fit", "gaus", -1, 1); + h_resVsEta_z0_H[i]->Fit("fit", "R"); + sigma = fit->GetParameter(2); + esigma = fit->GetParError(2); + rms = h_resVsEta_z0_H[i]->GetRMS(); + erms = h_resVsEta_z0_H[i]->GetRMSError(); + h3_resVsEta_z0_H->SetBinContent(i + 1, sigma); + h3_resVsEta_z0_H->SetBinError(i + 1, esigma); + h_resVsEta_z0_H[i]->Draw(); + sprintf(text, "RMS: %.4f +/- %.4f", rms, erms); + mySmallText(0.2, 0.86, 1, text); + sprintf(text, "Fit: %.4f +/- %.4f", sigma, esigma); + mySmallText(0.2, 0.8, 2, text); + sprintf(text, "p_{T} > 15 GeV"); + mySmallText(0.2, 0.7, 1, text); + cfit.SaveAs(fitdir + "resVsEta_z0_H_" + etarange[i] + ".pdf"); + delete fit; + + fit = new TF1("fit", "gaus", -0.005, 0.005); + h_resVsEta_phi_L[i]->Fit("fit", "R"); + sigma = fit->GetParameter(2); + esigma = fit->GetParError(2); + rms = h_resVsEta_phi_L[i]->GetRMS(); + erms = h_resVsEta_phi_L[i]->GetRMSError(); + h3_resVsEta_phi_L->SetBinContent(i + 1, sigma); + h3_resVsEta_phi_L->SetBinError(i + 1, esigma); + h_resVsEta_phi_L[i]->Draw(); + sprintf(text, "RMS: %.4f +/- %.4f", rms, erms); + mySmallText(0.2, 0.86, 1, text); + sprintf(text, "Fit: %.4f +/- %.4f", sigma, esigma); + mySmallText(0.2, 0.8, 2, text); + sprintf(text, "p_{T} < 5 GeV"); + mySmallText(0.2, 0.7, 1, text); + cfit.SaveAs(fitdir + "resVsEta_phi_L_" + etarange[i] + ".pdf"); + delete fit; + + fit = new TF1("fit", "gaus", -0.005, 0.005); + h_resVsEta_phi_H[i]->Fit("fit", "R"); + sigma = fit->GetParameter(2); + esigma = fit->GetParError(2); + rms = h_resVsEta_phi_H[i]->GetRMS(); + erms = h_resVsEta_phi_H[i]->GetRMSError(); + h3_resVsEta_phi_H->SetBinContent(i + 1, sigma); + h3_resVsEta_phi_H->SetBinError(i + 1, esigma); + h_resVsEta_phi_H[i]->Draw(); + sprintf(text, "RMS: %.4f +/- %.4f", rms, erms); + mySmallText(0.2, 0.86, 1, text); + sprintf(text, "Fit: %.4f +/- %.4f", sigma, esigma); + mySmallText(0.2, 0.8, 2, text); + sprintf(text, "p_{T} > 15 GeV"); + mySmallText(0.2, 0.7, 1, text); + cfit.SaveAs(fitdir + "resVsEta_phi_H_" + etarange[i] + ".pdf"); + delete fit; + + fit = new TF1("fit", "gaus", -0.5, 0.5); + h_resVsEta_ptRel_L[i]->Fit("fit", "R"); + sigma = fit->GetParameter(2); + esigma = fit->GetParError(2); + rms = h_resVsEta_ptRel_L[i]->GetRMS(); + erms = h_resVsEta_ptRel_L[i]->GetRMSError(); + h3_resVsEta_ptRel_L->SetBinContent(i + 1, sigma); + h3_resVsEta_ptRel_L->SetBinError(i + 1, esigma); + h_resVsEta_ptRel_L[i]->Draw(); + sprintf(text, "RMS: %.4f +/- %.4f", rms, erms); + mySmallText(0.2, 0.86, 1, text); + sprintf(text, "Fit: %.4f +/- %.4f", sigma, esigma); + mySmallText(0.2, 0.8, 2, text); + sprintf(text, "p_{T} < 5 GeV"); + mySmallText(0.2, 0.7, 1, text); + cfit.SaveAs(fitdir + "resVsEta_ptRel_L_" + etarange[i] + ".pdf"); + delete fit; + + fit = new TF1("fit", "gaus", -0.5, 0.5); + h_resVsEta_ptRel_H[i]->Fit("fit", "R"); + sigma = fit->GetParameter(2); + esigma = fit->GetParError(2); + rms = h_resVsEta_ptRel_H[i]->GetRMS(); + erms = h_resVsEta_ptRel_H[i]->GetRMSError(); + h3_resVsEta_ptRel_H->SetBinContent(i + 1, sigma); + h3_resVsEta_ptRel_H->SetBinError(i + 1, esigma); + h_resVsEta_ptRel_H[i]->Draw(); + sprintf(text, "RMS: %.4f +/- %.4f", rms, erms); + mySmallText(0.2, 0.86, 1, text); + sprintf(text, "Fit: %.4f +/- %.4f", sigma, esigma); + mySmallText(0.2, 0.8, 2, text); + sprintf(text, "p_{T} > 15 GeV"); + mySmallText(0.2, 0.7, 1, text); + cfit.SaveAs(fitdir + "resVsEta_ptRel_H_" + etarange[i] + ".pdf"); + delete fit; + + } //end doGausFit + } + + TH1F* h2_resVsPhi_pt_68 = + new TH1F("resVsPhi2_pt_68", ";Tracking particle #phi; p_{T} resolution [GeV]", 32, -3.2, 3.2); + TH1F* h2_resVsPhi_pt_90 = + new TH1F("resVsPhi2_pt_90", ";Tracking particle #phi; p_{T} resolution [GeV]", 32, -3.2, 3.2); + TH1F* h2_resVsPhi_pt_99 = + new TH1F("resVsPhi2_pt_99", ";Tracking particle #phi; p_{T} resolution [GeV]", 32, -3.2, 3.2); + TH1F* h2_resVsPhi_ptRel_68 = + new TH1F("resVsPhi2_ptRel_68", ";Tracking particle #phi; p_{T} resolution / p_{T}", 32, -3.2, 3.2); + TH1F* h2_resVsPhi_ptRel_90 = + new TH1F("resVsPhi2_ptRel_90", ";Tracking particle #phi; p_{T} resolution / p_{T}", 32, -3.2, 3.2); + TH1F* h2_resVsPhi_ptRel_99 = + new TH1F("resVsPhi2_ptRel_99", ";Tracking particle #phi; p_{T} resolution / p_{T}", 32, -3.2, 3.2); + + for (int i = 0; i < nPHIRANGE; i++) { + h2_resVsPhi_pt_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPhi_pt[i], 0.68)); + h2_resVsPhi_pt_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPhi_pt[i], 0.90)); + h2_resVsPhi_pt_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPhi_pt[i], 0.99)); + + h2_resVsPhi_ptRel_68->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPhi_ptRel[i], 0.68)); + h2_resVsPhi_ptRel_90->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPhi_ptRel[i], 0.90)); + h2_resVsPhi_ptRel_99->SetBinContent(i + 1, getIntervalContainingFractionOfEntries(h_absResVsPhi_ptRel[i], 0.99)); + } + + // set minimum to zero + h2_resVsPt_pt->SetMinimum(0); + h2_resVsPt_pt_C->SetMinimum(0); + h2_resVsPt_pt_I->SetMinimum(0); + h2_resVsPt_pt_F->SetMinimum(0); + + h2_resVsPt_ptRel->SetMinimum(0); + h2_resVsPt_ptRel_C->SetMinimum(0); + h2_resVsPt_ptRel_I->SetMinimum(0); + h2_resVsPt_ptRel_F->SetMinimum(0); + + h2_resVsPt_z0->SetMinimum(0); + h2_resVsPt_z0_C->SetMinimum(0); + h2_resVsPt_z0_I->SetMinimum(0); + h2_resVsPt_z0_F->SetMinimum(0); + + h2_resVsPt_phi->SetMinimum(0); + h2_resVsPt_phi_C->SetMinimum(0); + h2_resVsPt_phi_I->SetMinimum(0); + h2_resVsPt_phi_F->SetMinimum(0); + + h2_resVsPt_eta->SetMinimum(0); + + h2_resVsEta_eta->SetMinimum(0); + h2_resVsEta_eta_L->SetMinimum(0); + h2_resVsEta_eta_H->SetMinimum(0); + + h2_resVsEta_z0->SetMinimum(0); + h2_resVsEta_z0_L->SetMinimum(0); + h2_resVsEta_z0_H->SetMinimum(0); + + h2_resVsEta_phi->SetMinimum(0); + h2_resVsEta_phi_L->SetMinimum(0); + h2_resVsEta_phi_H->SetMinimum(0); + + h2_resVsEta_ptRel->SetMinimum(0); + h2_resVsEta_ptRel_L->SetMinimum(0); + h2_resVsEta_ptRel_H->SetMinimum(0); + + h2_resVsPt_d0->SetMinimum(0); + h2_resVsEta_d0->SetMinimum(0); + h2_resVsEta_d0_L->SetMinimum(0); + h2_resVsEta_d0_H->SetMinimum(0); + + // ------------------------------------------------------------------------------------------- + // output file for histograms + // ------------------------------------------------------------------------------------------- + + if (TP_select_pdgid != 0) { + char pdgidtxt[500]; + sprintf(pdgidtxt, "_pdgid%i", TP_select_pdgid); + type = type + pdgidtxt; + } else if (TP_select_injet == 1) + type = type + "_injet"; + else if (TP_select_injet == 2) + type = type + "_injet_highpt"; + else if (TP_select_injet == 3) + type = type + "_injet_vhighpt"; + + if (TP_select_eventid != 0) + type = type + "_wpu"; + + if (useTightCuts) + type = type + "_tight"; + if (useDeadRegion) + type = type + "_dead"; + + if (L1Tk_seed != 0) { + char seedtxt[500]; + sprintf(seedtxt, "_seed%i", L1Tk_seed); + type = type + seedtxt; + } + + if (TP_minPt > 2.0) { + char pttxt[500]; + sprintf(pttxt, "_pt%.0f", TP_minPt); + type = type + pttxt; + } + + TFile* fout; + if (doLooseMatch) + fout = new TFile("output_looseMatch_" + type + treeName + ".root", "recreate"); + else + fout = new TFile(type_dir + "output_" + type + treeName + ".root", "recreate"); + + // ------------------------------------------------------------------------------------------- + // draw and save plots + // ------------------------------------------------------------------------------------------- + + char ctxt[500]; + TCanvas c; + + TString DIR = "TrkPlots/"; + + // plots overlaying 68, 90, 99% confidence levels] + + float max_eta_ptRel = 0.2; + float max_pt_ptRel = 0.2; + float max_pt_pt = 20; + float max_z0 = 2.0; + float max_phi = 0.01; + float max_eta = 0.03; + + if (type.Contains("El")) { + max_pt_ptRel = 1.0; + max_eta_ptRel = 1.0; + max_phi = 0.1; + } + + // makeResidualIntervalPlot will save the individual plots to the root file + makeResidualIntervalPlot( + type, DIR, "resVsPt_ptRel", h2_resVsPt_ptRel_68, h2_resVsPt_ptRel_90, h2_resVsPt_ptRel_99, 0, max_pt_ptRel); + makeResidualIntervalPlot(type, DIR, "resVsPt_pt", h2_resVsPt_pt_68, h2_resVsPt_pt_90, h2_resVsPt_pt_99, 0, max_pt_pt); + makeResidualIntervalPlot(type, DIR, "resVsPt_z0", h2_resVsPt_z0_68, h2_resVsPt_z0_90, h2_resVsPt_z0_99, 0, max_z0); + makeResidualIntervalPlot( + type, DIR, "resVsPt_phi", h2_resVsPt_phi_68, h2_resVsPt_phi_90, h2_resVsPt_phi_99, 0, max_phi); + makeResidualIntervalPlot( + type, DIR, "resVsPt_eta", h2_resVsPt_eta_68, h2_resVsPt_eta_90, h2_resVsPt_eta_99, 0, max_eta); + //makeResidualIntervalPlot( type, DIR, "resVsPt_d0", h2_resVsPt_d0_68, h2_resVsPt_d0_90, h2_resVsPt_d0_99, 0, 0.02 ); + + makeResidualIntervalPlot(type, + DIR, + "resVsPt_L_ptRel", + h2_resVsPt_ptRel_L_68, + h2_resVsPt_ptRel_L_90, + h2_resVsPt_ptRel_L_99, + 0, + max_pt_ptRel); + makeResidualIntervalPlot( + type, DIR, "resVsPt_L_pt", h2_resVsPt_pt_L_68, h2_resVsPt_pt_L_90, h2_resVsPt_pt_L_99, 0, max_pt_pt); + makeResidualIntervalPlot( + type, DIR, "resVsPt_L_z0", h2_resVsPt_z0_L_68, h2_resVsPt_z0_L_90, h2_resVsPt_z0_L_99, 0, max_z0); + makeResidualIntervalPlot( + type, DIR, "resVsPt_L_phi", h2_resVsPt_phi_L_68, h2_resVsPt_phi_L_90, h2_resVsPt_phi_L_99, 0, max_phi); + makeResidualIntervalPlot( + type, DIR, "resVsPt_L_eta", h2_resVsPt_eta_L_68, h2_resVsPt_eta_L_90, h2_resVsPt_eta_L_99, 0, max_eta); + //makeResidualIntervalPlot( type, DIR, "resVsPt_L_d0", h2_resVsPt_d0_L_68, h2_resVsPt_d0_L_90, h2_resVsPt_d0_L_99, 0, 0.02 ); + + makeResidualIntervalPlot( + type, DIR, "resVsEta_eta", h2_resVsEta_eta_68, h2_resVsEta_eta_90, h2_resVsEta_eta_99, 0, max_eta); + makeResidualIntervalPlot( + type, DIR, "resVsEta_z0", h2_resVsEta_z0_68, h2_resVsEta_z0_90, h2_resVsEta_z0_99, 0, max_z0); + makeResidualIntervalPlot( + type, DIR, "resVsEta_phi", h2_resVsEta_phi_68, h2_resVsEta_phi_90, h2_resVsEta_phi_99, 0, max_phi); + makeResidualIntervalPlot( + type, DIR, "resVsEta_ptRel", h2_resVsEta_ptRel_68, h2_resVsEta_ptRel_90, h2_resVsEta_ptRel_99, 0, max_eta_ptRel); + //makeResidualIntervalPlot( type, DIR, "resVsEta_d0", h2_resVsEta_d0_68, h2_resVsEta_d0_90, h2_resVsEta_d0_99, 0, 0.02 ); + + makeResidualIntervalPlot( + type, DIR, "resVsEta_L_eta", h2_resVsEta_eta_L_68, h2_resVsEta_eta_L_90, h2_resVsEta_eta_L_99, 0, max_eta); + makeResidualIntervalPlot( + type, DIR, "resVsEta_L_z0", h2_resVsEta_z0_L_68, h2_resVsEta_z0_L_90, h2_resVsEta_z0_L_99, 0, max_z0); + makeResidualIntervalPlot( + type, DIR, "resVsEta_L_phi", h2_resVsEta_phi_L_68, h2_resVsEta_phi_L_90, h2_resVsEta_phi_L_99, 0, max_phi); + makeResidualIntervalPlot(type, + DIR, + "resVsEta_L_ptRel", + h2_resVsEta_ptRel_L_68, + h2_resVsEta_ptRel_L_90, + h2_resVsEta_ptRel_L_99, + 0, + max_eta_ptRel); + //makeResidualIntervalPlot( type, DIR, "resVsEta_L_d0", h2_resVsEta_d0_L_68, h2_resVsEta_d0_L_90, h2_resVsEta_d0_L_99, 0, 0.02 ); + + makeResidualIntervalPlot( + type, DIR, "resVsEta_H_eta", h2_resVsEta_eta_H_68, h2_resVsEta_eta_H_90, h2_resVsEta_eta_H_99, 0, max_eta); + makeResidualIntervalPlot( + type, DIR, "resVsEta_H_z0", h2_resVsEta_z0_H_68, h2_resVsEta_z0_H_90, h2_resVsEta_z0_H_99, 0, max_z0); + makeResidualIntervalPlot( + type, DIR, "resVsEta_H_phi", h2_resVsEta_phi_H_68, h2_resVsEta_phi_H_90, h2_resVsEta_phi_H_99, 0, max_phi); + makeResidualIntervalPlot(type, + DIR, + "resVsEta_H_ptRel", + h2_resVsEta_ptRel_H_68, + h2_resVsEta_ptRel_H_90, + h2_resVsEta_ptRel_H_99, + 0, + max_eta_ptRel); + //makeResidualIntervalPlot( type, DIR, "resVsEta_H_d0", h2_resVsEta_d0_H_68, h2_resVsEta_d0_H_90, h2_resVsEta_d0_H_99, 0, 0.02 ); + + if (doDetailedPlots) { + makeResidualIntervalPlot( + type, DIR, "resVsPhi_ptRel", h2_resVsPhi_ptRel_68, h2_resVsPhi_ptRel_90, h2_resVsPhi_ptRel_99, 0, 0.5); + makeResidualIntervalPlot(type, DIR, "resVsPhi_pt", h2_resVsPhi_pt_68, h2_resVsPhi_pt_90, h2_resVsPhi_pt_99, 0, 20); + } + + // ---------------------------------------------------------------------------------------------------------- + // resoultion vs pt + // ---------------------------------------------------------------------------------------------------------- + + h2_resVsPt_pt_90->SetMinimum(0); + h2_resVsPt_pt_90->SetMarkerStyle(20); + h2_resVsPt_pt_90->Draw("p"); + c.SaveAs(DIR + type + "_resVsPt_pt_90.pdf"); + + h2_resVsPt_ptRel_90->SetMinimum(0); + h2_resVsPt_ptRel_90->SetMarkerStyle(20); + h2_resVsPt_ptRel_90->Draw("p"); + c.SaveAs(DIR + type + "_resVsPt_ptRel_90.pdf"); + + h2_resVsPt_z0_90->SetMinimum(0); + h2_resVsPt_z0_90->SetMarkerStyle(20); + h2_resVsPt_z0_90->Draw("p"); + c.SaveAs(DIR + type + "_resVsPt_z0_90.pdf"); + + h2_resVsPt_phi_90->SetMinimum(0); + h2_resVsPt_phi_90->SetMarkerStyle(20); + h2_resVsPt_phi_90->Draw("p"); + c.SaveAs(DIR + type + "_resVsPt_phi_90.pdf"); + + h2_resVsPt_eta_90->SetMinimum(0); + h2_resVsPt_eta_90->SetMarkerStyle(20); + h2_resVsPt_eta_90->Draw("p"); + c.SaveAs(DIR + type + "_resVsPt_eta_90.pdf"); + + /* + h2_resVsPt_phi_90->SetMinimum(0); + h2_resVsPt_d0_90->SetMarkerStyle(20); + h2_resVsPt_d0_90->Draw("p"); + c.SaveAs(DIR+type+"_resVsPt_d0_90.pdf"); + */ + + // Limit decimal places for doubles in normalized tracklet eff. graphs + gStyle->SetPaintTextFormat("4.2f"); + + h_trk_tracklet_eff->SetMinimum(0); + h_trk_tracklet_eff->Draw("col text"); + c.SaveAs(DIR + type + "_trk_tracklet_eff.pdf"); + + // Remove decimal places for ints in in tracklet hits graphs + gStyle->SetPaintTextFormat("4.0f"); + + h_trk_tracklet_hits->SetMinimum(0); + h_trk_tracklet_hits->Draw("col text"); + c.SaveAs(DIR + type + "_trk_tracklet_hits.pdf"); + + if (doDetailedPlots) { + h2_resVsPt_eta->Write(); + + h2_resVsPt_pt->Write(); + h2_resVsPt_pt_C->Write(); + h2_resVsPt_pt_I->Write(); + h2_resVsPt_pt_F->Write(); + + h2_resVsPt_ptRel->Write(); + h2_resVsPt_ptRel_C->Write(); + h2_resVsPt_ptRel_I->Write(); + h2_resVsPt_ptRel_F->Write(); + + h2_mresVsPt_pt->Write(); + h2_mresVsPt_pt_C->Write(); + h2_mresVsPt_pt_I->Write(); + h2_mresVsPt_pt_F->Write(); + + h2_resVsPt_d0->Write(); + + h2_resVsPt_z0_C->Write(); + h2_resVsPt_z0_I->Write(); + h2_resVsPt_z0_F->Write(); + + h2_resVsPt_phi->Write(); + h2_resVsPt_phi_C->Write(); + h2_resVsPt_phi_I->Write(); + h2_resVsPt_phi_F->Write(); + } + + // ---------------------------------------------------------------------------------------------------------- + // resolution vs eta + // ---------------------------------------------------------------------------------------------------------- + + h2_resVsEta_eta_90->SetMinimum(0); + h2_resVsEta_eta_90->SetMarkerStyle(20); + h2_resVsEta_eta_90->Draw("p"); + c.SaveAs(DIR + type + "_resVsEta_eta_90.pdf"); + + h2_resVsEta_eta_68->SetMinimum(0); + h2_resVsEta_eta_68->SetMarkerStyle(20); + h2_resVsEta_eta_68->Draw("p"); + c.SaveAs(DIR + type + "_resVsEta_eta_68.pdf"); + + if (doDetailedPlots) { + h2_resVsEta_eta_L_90->Draw("p"); + sprintf(ctxt, "p_{T} < 8 GeV"); + mySmallText(0.22, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_resVsEta_eta_L_90.pdf"); + + h2_resVsEta_eta_H_90->Draw("p"); + sprintf(ctxt, "p_{T} > 8 GeV"); + mySmallText(0.22, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_resVsEta_eta_H_90.pdf"); + } + + h2_resVsEta_z0_90->SetMinimum(0); + h2_resVsEta_z0_90->SetMarkerStyle(20); + h2_resVsEta_z0_90->Draw("p"); + c.SaveAs(DIR + type + "_resVsEta_z0_90.pdf"); + + h2_resVsEta_z0_68->SetMinimum(0); + h2_resVsEta_z0_68->SetMarkerStyle(20); + h2_resVsEta_z0_68->Draw("p"); + c.SaveAs(DIR + type + "_resVsEta_z0_68.pdf"); + + if (doDetailedPlots) { + h2_resVsEta_z0_L_90->Draw(); + sprintf(ctxt, "p_{T} < 8 GeV"); + mySmallText(0.22, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_resVsEta_z0_L_90.pdf"); + + h2_resVsEta_z0_H_90->Draw(); + sprintf(ctxt, "p_{T} > 8 GeV"); + mySmallText(0.22, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_resVsEta_z0_H_90.pdf"); + } + + /* + h2_resVsEta_d0_90->Draw(); + c.SaveAs(DIR+type+"_resVsEta_d0_90.pdf"); + + h2_resVsEta_d0_L_90->Draw(); + sprintf(ctxt,"p_{T} < 8 GeV"); + mySmallText(0.22,0.82,1,ctxt); + c.SaveAs(DIR+type+"_resVsEta_d0_L_90.pdf"); + + h2_resVsEta_d0_H_90->Draw(); + sprintf(ctxt,"p_{T} > 8 GeV"); + mySmallText(0.22,0.82,1,ctxt); + c.SaveAs(DIR+type+"_resVsEta_d0_H_90.pdf"); + */ + + h2_resVsEta_phi_90->SetMinimum(0); + h2_resVsEta_phi_90->SetMarkerStyle(20); + h2_resVsEta_phi_90->Draw("p"); + c.SaveAs(DIR + type + "_resVsEta_phi_90.pdf"); + + h2_resVsEta_phi_68->SetMinimum(0); + h2_resVsEta_phi_68->SetMarkerStyle(20); + h2_resVsEta_phi_68->Draw("p"); + c.SaveAs(DIR + type + "_resVsEta_phi_68.pdf"); + + if (doDetailedPlots) { + h2_resVsEta_phi_L_90->Draw(); + sprintf(ctxt, "p_{T} < 8 GeV"); + mySmallText(0.22, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_resVsEta_phi_L_90.pdf"); + + h2_resVsEta_phi_H_90->Draw(); + sprintf(ctxt, "p_{T} > 8 GeV"); + mySmallText(0.22, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_resVsEta_phi_H_90.pdf"); + } + + h2_resVsEta_ptRel_90->SetMinimum(0); + h2_resVsEta_ptRel_90->SetMarkerStyle(20); + h2_resVsEta_ptRel_90->Draw("p"); + c.SaveAs(DIR + type + "_resVsEta_ptRel_90.pdf"); + + h2_resVsEta_ptRel_68->SetMinimum(0); + h2_resVsEta_ptRel_68->SetMarkerStyle(20); + h2_resVsEta_ptRel_68->Draw("p"); + c.SaveAs(DIR + type + "_resVsEta_ptRel_68.pdf"); + + if (doDetailedPlots) { + h2_resVsEta_ptRel_L_90->Draw(); + sprintf(ctxt, "p_{T} < 8 GeV"); + mySmallText(0.22, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_resVsEta_ptRel_L_90.pdf"); + + h2_resVsEta_ptRel_H_90->Draw(); + sprintf(ctxt, "p_{T} > 8 GeV"); + mySmallText(0.22, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_resVsEta_ptRel_H_90.pdf"); + + h2_resVsEta_eta->Write(); + h2_resVsEta_eta_L->Write(); + h2_resVsEta_eta_H->Write(); + + h2_resVsEta_z0->Draw(); + c.SaveAs(DIR + type + "_resVsEta_z0_rms.pdf"); + h2_resVsEta_eta->Draw(); + c.SaveAs(DIR + type + "_resVsEta_eta_rms.pdf"); + h2_resVsEta_ptRel->Draw(); + c.SaveAs(DIR + type + "_resVsEta_ptRel_rms.pdf"); + h2_resVsEta_phi->Draw(); + c.SaveAs(DIR + type + "_resVsEta_phi_rms.pdf"); + + // check residuals + h2_mresVsEta_z0->Draw(); + h2_mresVsEta_z0->Write(); + c.SaveAs(DIR + type + "_mean-resVsEta_z0.pdf"); + + h2_mresVsEta_eta->Draw(); + h2_mresVsEta_eta->Write(); + c.SaveAs(DIR + type + "_mean-resVsEta_eta.pdf"); + + h2_mresVsEta_ptRel->Draw(); + h2_mresVsEta_ptRel->Write(); + c.SaveAs(DIR + type + "_mean-resVsEta_ptRel.pdf"); + + h2_mresVsEta_phi->Draw(); + h2_mresVsEta_phi->Write(); + c.SaveAs(DIR + type + "_mean-resVsEta_phi.pdf"); + + h2_resVsEta_z0->Write(); + h2_resVsEta_z0_L->Write(); + h2_resVsEta_z0_H->Write(); + + h2_resVsEta_d0->Write(); + h2_resVsEta_d0_L->Write(); + h2_resVsEta_d0_H->Write(); + + h2_resVsEta_phi->Write(); + h2_resVsEta_phi_L->Write(); + h2_resVsEta_phi_H->Write(); + + h2_resVsEta_ptRel->Write(); + h2_resVsEta_ptRel_L->Write(); + h2_resVsEta_ptRel_H->Write(); + } + + if (doGausFit) { + h3_resVsEta_eta_L->Write(); + h3_resVsEta_z0_L->Write(); + h3_resVsEta_phi_L->Write(); + h3_resVsEta_ptRel_L->Write(); + + h3_resVsEta_eta_H->Write(); + h3_resVsEta_z0_H->Write(); + h3_resVsEta_phi_H->Write(); + h3_resVsEta_ptRel_H->Write(); + } + + // resolution vs phi + if (doDetailedPlots) { + h2_resVsPhi_pt_90->SetMinimum(0); + h2_resVsPhi_pt_90->SetMarkerStyle(20); + h2_resVsPhi_pt_90->Draw("p"); + c.SaveAs(DIR + type + "_resVsPhi_pt_90.pdf"); + + h2_resVsPhi_ptRel_90->SetMinimum(0); + h2_resVsPhi_ptRel_90->SetMarkerStyle(20); + h2_resVsPhi_ptRel_90->Draw("p"); + c.SaveAs(DIR + type + "_resVsPhi_ptRel_90.pdf"); + } + + // ---------------------------------------------------------------------------------------------------------------- + // track quality plots + // ---------------------------------------------------------------------------------------------------------------- + + if (doDetailedPlots) { + h_match_trk_nstub->Write(); + h_match_trk_nstub_C->Write(); + h_match_trk_nstub_I->Write(); + h_match_trk_nstub_F->Write(); + } + + h_trk_chi2->Draw(); + sprintf(ctxt, "|eta| < 2.4"); + mySmallText(0.52, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_trk_chi2.pdf"); + + h_trk_chi2_dof->Draw(); + sprintf(ctxt, "|eta| < 2.4"); + mySmallText(0.52, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_trk_chi2_dof.pdf"); + + h_trk_chi2rphi->Draw(); + sprintf(ctxt, "|eta| < 2.4"); + mySmallText(0.52, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_trk_chi2rphi.pdf"); + + h_trk_chi2rphi_dof->Draw(); + sprintf(ctxt, "|eta| < 2.4"); + mySmallText(0.52, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_trk_chi2rphi_dof.pdf"); + + h_trk_chi2rz->Draw(); + sprintf(ctxt, "|eta| < 2.4"); + mySmallText(0.52, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_trk_chi2rz.pdf"); + + h_trk_chi2rz_dof->Draw(); + sprintf(ctxt, "|eta| < 2.4"); + mySmallText(0.52, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_trk_chi2rz_dof.pdf"); + + h_trk_chi2->Write(); + h_trk_chi2rphi->Write(); + h_trk_chi2rz->Write(); + h_match_trk_chi2->Write(); + h_match_trk_chi2rphi->Write(); + h_match_trk_chi2rz->Write(); + + if (doDetailedPlots) { + h_match_trk_chi2_C_L->Write(); + h_match_trk_chi2_I_L->Write(); + h_match_trk_chi2_F_L->Write(); + h_match_trk_chi2_C_H->Write(); + h_match_trk_chi2_I_H->Write(); + h_match_trk_chi2_F_H->Write(); + + h_match_trk_chi2_dof_C_L->Write(); + h_match_trk_chi2_dof_I_L->Write(); + h_match_trk_chi2_dof_F_L->Write(); + h_match_trk_chi2_dof_C_H->Write(); + h_match_trk_chi2_dof_I_H->Write(); + h_match_trk_chi2_dof_F_H->Write(); + } + + // ---------------------------------------------------------------------------------------------------------------- + // efficiency plots + // ---------------------------------------------------------------------------------------------------------------- + + // rebin pt/phi plots + h_tp_pt->Rebin(2); + h_match_tp_pt->Rebin(2); + h_tp_phi->Rebin(2); + h_match_tp_phi->Rebin(2); + + h_tp_pt_L->Rebin(2); + h_match_tp_pt_L->Rebin(2); + h_tp_pt_LC->Rebin(2); + h_match_tp_pt_LC->Rebin(2); + h_tp_pt_H->Rebin(2); + h_match_tp_pt_H->Rebin(2); + + h_tp_eta->Rebin(2); + h_match_tp_eta->Rebin(2); + h_tp_eta_L->Rebin(2); + h_match_tp_eta_L->Rebin(2); + h_tp_eta_H->Rebin(2); + h_match_tp_eta_H->Rebin(2); + + // calculate the effeciency + h_match_tp_pt->Sumw2(); + h_tp_pt->Sumw2(); + TH1F* h_eff_pt = (TH1F*)h_match_tp_pt->Clone(); + h_eff_pt->SetName("eff_pt"); + h_eff_pt->GetYaxis()->SetTitle("Efficiency"); + h_eff_pt->Divide(h_match_tp_pt, h_tp_pt, 1.0, 1.0, "B"); + + h_match_tp_pt_L->Sumw2(); + h_tp_pt_L->Sumw2(); + TH1F* h_eff_pt_L = (TH1F*)h_match_tp_pt_L->Clone(); + h_eff_pt_L->SetName("eff_pt_L"); + h_eff_pt_L->GetYaxis()->SetTitle("Efficiency"); + h_eff_pt_L->Divide(h_match_tp_pt_L, h_tp_pt_L, 1.0, 1.0, "B"); + + h_match_tp_pt_LC->Sumw2(); + h_tp_pt_LC->Sumw2(); + TH1F* h_eff_pt_LC = (TH1F*)h_match_tp_pt_LC->Clone(); + h_eff_pt_LC->SetName("eff_pt_LC"); + h_eff_pt_LC->GetYaxis()->SetTitle("Efficiency"); + h_eff_pt_LC->Divide(h_match_tp_pt_LC, h_tp_pt_LC, 1.0, 1.0, "B"); + + h_match_tp_pt_H->Sumw2(); + h_tp_pt_H->Sumw2(); + TH1F* h_eff_pt_H = (TH1F*)h_match_tp_pt_H->Clone(); + h_eff_pt_H->SetName("eff_pt_H"); + h_eff_pt_H->GetYaxis()->SetTitle("Efficiency"); + h_eff_pt_H->Divide(h_match_tp_pt_H, h_tp_pt_H, 1.0, 1.0, "B"); + + h_match_tp_eta->Sumw2(); + h_tp_eta->Sumw2(); + TH1F* h_eff_eta = (TH1F*)h_match_tp_eta->Clone(); + h_eff_eta->SetName("eff_eta"); + h_eff_eta->GetYaxis()->SetTitle("Efficiency"); + h_eff_eta->Divide(h_match_tp_eta, h_tp_eta, 1.0, 1.0, "B"); + + h_match_tp_eta_L->Sumw2(); + h_tp_eta_L->Sumw2(); + TH1F* h_eff_eta_L = (TH1F*)h_match_tp_eta_L->Clone(); + h_eff_eta_L->SetName("eff_eta_L"); + h_eff_eta_L->GetYaxis()->SetTitle("Efficiency"); + h_eff_eta_L->Divide(h_match_tp_eta_L, h_tp_eta_L, 1.0, 1.0, "B"); + + h_match_tp_eta_H->Sumw2(); + h_tp_eta_H->Sumw2(); + TH1F* h_eff_eta_H = (TH1F*)h_match_tp_eta_H->Clone(); + h_eff_eta_H->SetName("eff_eta_H"); + h_eff_eta_H->GetYaxis()->SetTitle("Efficiency"); + h_eff_eta_H->Divide(h_match_tp_eta_H, h_tp_eta_H, 1.0, 1.0, "B"); + + h_match_tp_eta_23->Sumw2(); + h_tp_eta_23->Sumw2(); + TH1F* h_eff_eta_23 = (TH1F*)h_match_tp_eta_23->Clone(); + h_eff_eta_23->SetName("eff_eta_23"); + h_eff_eta_23->GetYaxis()->SetTitle("Efficiency"); + h_eff_eta_23->Divide(h_match_tp_eta_23, h_tp_eta_23, 1.0, 1.0, "B"); + + h_match_tp_eta_35->Sumw2(); + h_tp_eta_35->Sumw2(); + TH1F* h_eff_eta_35 = (TH1F*)h_match_tp_eta_35->Clone(); + h_eff_eta_35->SetName("eff_eta_35"); + h_eff_eta_35->GetYaxis()->SetTitle("Efficiency"); + h_eff_eta_35->Divide(h_match_tp_eta_35, h_tp_eta_35, 1.0, 1.0, "B"); + + h_match_tp_eta_5->Sumw2(); + h_tp_eta_5->Sumw2(); + TH1F* h_eff_eta_5 = (TH1F*)h_match_tp_eta_5->Clone(); + h_eff_eta_5->SetName("eff_eta_5"); + h_eff_eta_5->GetYaxis()->SetTitle("Efficiency"); + h_eff_eta_5->Divide(h_match_tp_eta_5, h_tp_eta_5, 1.0, 1.0, "B"); + + h_match_tp_phi->Sumw2(); + h_tp_phi->Sumw2(); + TH1F* h_eff_phi = (TH1F*)h_match_tp_phi->Clone(); + h_eff_phi->SetName("eff_phi"); + h_eff_phi->GetYaxis()->SetTitle("Efficiency"); + h_eff_phi->Divide(h_match_tp_phi, h_tp_phi, 1.0, 1.0, "B"); + + h_match_tp_z0->Sumw2(); + h_tp_z0->Sumw2(); + TH1F* h_eff_z0 = (TH1F*)h_match_tp_z0->Clone(); + h_eff_z0->SetName("eff_z0"); + h_eff_z0->GetYaxis()->SetTitle("Efficiency"); + h_eff_z0->Divide(h_match_tp_z0, h_tp_z0, 1.0, 1.0, "B"); + + h_match_tp_z0_L->Sumw2(); + h_tp_z0_L->Sumw2(); + TH1F* h_eff_z0_L = (TH1F*)h_match_tp_z0_L->Clone(); + h_eff_z0_L->SetName("eff_z0_L"); + h_eff_z0_L->GetYaxis()->SetTitle("Efficiency"); + h_eff_z0_L->Divide(h_match_tp_z0_L, h_tp_z0_L, 1.0, 1.0, "B"); + + h_match_tp_z0_H->Sumw2(); + h_tp_z0_H->Sumw2(); + TH1F* h_eff_z0_H = (TH1F*)h_match_tp_z0_H->Clone(); + h_eff_z0_H->SetName("eff_z0_H"); + h_eff_z0_H->GetYaxis()->SetTitle("Efficiency"); + h_eff_z0_H->Divide(h_match_tp_z0_H, h_tp_z0_H, 1.0, 1.0, "B"); + + h_match_tp_d0->Sumw2(); + h_tp_d0->Sumw2(); + TH1F* h_eff_d0 = (TH1F*)h_match_tp_d0->Clone(); + h_eff_d0->SetName("eff_d0"); + h_eff_d0->GetYaxis()->SetTitle("Efficiency"); + h_eff_d0->Divide(h_match_tp_d0, h_tp_d0, 1.0, 1.0, "B"); + + h_match_tp_absd0->Sumw2(); + h_tp_absd0->Sumw2(); + TH1F* h_eff_absd0 = (TH1F*)h_match_tp_absd0->Clone(); + h_eff_absd0->SetName("eff_absd0"); + h_eff_absd0->GetYaxis()->SetTitle("Efficiency"); + h_eff_absd0->Divide(h_match_tp_absd0, h_tp_absd0, 1.0, 1.0, "B"); + + h_match_tp_absd0_eta2->Sumw2(); + h_tp_absd0_eta2->Sumw2(); + TH1F* h_eff_absd0_eta2 = (TH1F*)h_match_tp_absd0_eta2->Clone(); + h_eff_absd0_eta2->SetName("eff_absd0_eta2"); + h_eff_absd0_eta2->GetYaxis()->SetTitle("Efficiency"); + h_eff_absd0_eta2->Divide(h_match_tp_absd0_eta2, h_tp_absd0_eta2, 1.0, 1.0, "B"); + + h_match_tp_absd0_eta2_pt3->Sumw2(); + h_tp_absd0_eta2_pt3->Sumw2(); + TH1F* h_eff_absd0_eta2_pt3 = (TH1F*)h_match_tp_absd0_eta2_pt3->Clone(); + h_eff_absd0_eta2_pt3->SetName("eff_absd0_eta2_pt3"); + h_eff_absd0_eta2_pt3->GetYaxis()->SetTitle("Efficiency"); + h_eff_absd0_eta2_pt3->Divide(h_match_tp_absd0_eta2_pt3, h_tp_absd0_eta2_pt3, 1.0, 1.0, "B"); + + // set the axis range + h_eff_pt->SetAxisRange(0, 1.1, "Y"); + h_eff_pt_L->SetAxisRange(0, 1.1, "Y"); + h_eff_pt_LC->SetAxisRange(0, 1.1, "Y"); + h_eff_pt_H->SetAxisRange(0, 1.1, "Y"); + h_eff_eta->SetAxisRange(0, 1.1, "Y"); + h_eff_eta_L->SetAxisRange(0, 1.1, "Y"); + h_eff_eta_H->SetAxisRange(0, 1.1, "Y"); + h_eff_eta_23->SetAxisRange(0, 1.1, "Y"); + h_eff_eta_35->SetAxisRange(0, 1.1, "Y"); + h_eff_eta_5->SetAxisRange(0, 1.1, "Y"); + h_eff_phi->SetAxisRange(0, 1.1, "Y"); + h_eff_z0->SetAxisRange(0, 1.1, "Y"); + h_eff_z0_L->SetAxisRange(0, 1.1, "Y"); + h_eff_z0_H->SetAxisRange(0, 1.1, "Y"); + h_eff_d0->SetAxisRange(0, 1.1, "Y"); + h_eff_absd0->SetAxisRange(0, 1.1, "Y"); + h_eff_absd0_eta2->SetAxisRange(0, 1.1, "Y"); + h_eff_absd0_eta2_pt3->SetAxisRange(0, 1.1, "Y"); + + gPad->SetGridx(); + gPad->SetGridy(); + + // draw and save plots + h_eff_pt->Draw(); + h_eff_pt->Write(); + c.SaveAs(DIR + type + "_eff_pt.pdf"); + + if (type.Contains("Mu")) { + h_eff_pt->GetYaxis()->SetRangeUser(0.8, 1.01); // zoomed-in plot + c.SaveAs(DIR + type + "_eff_pt_zoom.pdf"); + } + + h_eff_pt_L->Draw(); + h_eff_pt_L->Write(); + sprintf(ctxt, "p_{T} < 8 GeV"); + mySmallText(0.45, 0.5, 1, ctxt); + c.SaveAs(DIR + type + "_eff_pt_L.pdf"); + + if (doDetailedPlots) { + h_eff_pt_LC->Draw(); + h_eff_pt_LC->Write(); + sprintf(ctxt, "p_{T} < 8 GeV, |#eta|<1.0"); + mySmallText(0.45, 0.5, 1, ctxt); + c.SaveAs(DIR + type + "_eff_pt_LC.pdf"); + } + h_eff_pt_H->Draw(); + h_eff_pt_H->Write(); + sprintf(ctxt, "p_{T} > 8 GeV"); + mySmallText(0.45, 0.5, 1, ctxt); + c.SaveAs(DIR + type + "_eff_pt_H.pdf"); + + h_eff_eta->Draw(); + h_eff_eta->Write(); + c.SaveAs(DIR + type + "_eff_eta.pdf"); + + if (type.Contains("Mu")) { + h_eff_eta->GetYaxis()->SetRangeUser(0.8, 1.01); // zoomed-in plot + c.SaveAs(DIR + type + "_eff_eta_zoom.pdf"); + } + + h_eff_eta_L->Draw(); + h_eff_eta_L->Write(); + sprintf(ctxt, "p_{T} < 8 GeV"); + mySmallText(0.45, 0.5, 1, ctxt); + c.SaveAs(DIR + type + "_eff_eta_L.pdf"); + + h_eff_eta_H->Draw(); + h_eff_eta_H->Write(); + sprintf(ctxt, "p_{T} > 8 GeV"); + mySmallText(0.45, 0.5, 1, ctxt); + c.SaveAs(DIR + type + "_eff_eta_H.pdf"); + + h_eff_eta_23->Write(); + h_eff_eta_35->Write(); + h_eff_eta_5->Write(); + + if (doDetailedPlots) { + h_eff_eta_23->Draw(); + sprintf(ctxt, "2 < p_{T} < 3 GeV"); + mySmallText(0.45, 0.5, 1, ctxt); + c.SaveAs(DIR + type + "_eff_eta_23.pdf"); + + h_eff_eta_35->Draw(); + sprintf(ctxt, "3 < p_{T} < 5 GeV"); + mySmallText(0.45, 0.5, 1, ctxt); + c.SaveAs(DIR + type + "_eff_eta_35.pdf"); + + h_eff_eta_5->Draw(); + sprintf(ctxt, "p_{T} > 5 GeV"); + mySmallText(0.45, 0.5, 1, ctxt); + c.SaveAs(DIR + type + "_eff_eta_5.pdf"); + + h_eff_z0->Draw(); + h_eff_z0->Write(); + c.SaveAs(DIR + type + "_eff_z0.pdf"); + + h_eff_z0_L->Write(); + h_eff_z0_H->Write(); + + h_eff_phi->Draw(); + h_eff_phi->Write(); + c.SaveAs(DIR + type + "_eff_phi.pdf"); + + if (type.Contains("Mu")) { + h_eff_phi->GetYaxis()->SetRangeUser(0.8, 1.01); // zoomed-in plot + c.SaveAs(DIR + type + "_eff_phi_zoom.pdf"); + } + } + + if (doDetailedPlots || TP_maxD0 > 1.0) { + h_eff_d0->Write(); + h_eff_absd0->Write(); + h_eff_absd0_eta2->Write(); + h_eff_absd0_eta2_pt3->Write(); + + h_eff_d0->Draw(); + c.SaveAs(DIR + type + "_eff_d0.pdf"); + + h_eff_absd0->Draw(); + c.SaveAs(DIR + type + "_eff_absd0.pdf"); + + h_eff_absd0_eta2->Draw(); + c.SaveAs(DIR + type + "_eff_absd0_eta2.pdf"); + + h_eff_absd0_eta2_pt3->Draw(); + c.SaveAs(DIR + type + "_eff_absd0_eta2_pt3.pdf"); + } + + gPad->SetGridx(0); + gPad->SetGridy(0); + + // ---------------------------------------------------------------------------------------------------------------- + // more resolution plots + // ---------------------------------------------------------------------------------------------------------------- + + float rms = 0; + + if (doDetailedPlots) { + // draw and save plots + h_res_pt->Draw(); + rms = h_res_pt->GetRMS(); + sprintf(ctxt, "RMS = %.4f", rms); + mySmallText(0.22, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_res_pt.pdf"); + + h_res_ptRel->Draw(); + rms = h_res_ptRel->GetRMS(); + sprintf(ctxt, "RMS = %.4f", rms); + mySmallText(0.22, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_res_ptRel.pdf"); + + h_res_eta->Draw(); + rms = h_res_eta->GetRMS(); + sprintf(ctxt, "RMS = %.3e", rms); + mySmallText(0.22, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_res_eta.pdf"); + + h_res_phi->Draw(); + rms = h_res_phi->GetRMS(); + sprintf(ctxt, "RMS = %.3e", rms); + mySmallText(0.22, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_res_phi.pdf"); + + h_res_z0->Draw(); + rms = h_res_z0->GetRMS(); + sprintf(ctxt, "RMS = %.4f", rms); + mySmallText(0.22, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_res_z0.pdf"); + + h_res_z0_C->Draw(); + rms = h_res_z0_C->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "|eta| < 0.8"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_z0_C.pdf"); + + h_res_z0_I->Draw(); + rms = h_res_z0_I->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "0.8 < |eta| < 1.6"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_z0_I.pdf"); + + h_res_z0_F->Draw(); + rms = h_res_z0_F->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "|eta| > 1.6"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_z0_F.pdf"); + + h_res_z0_C_L->Draw(); + h_res_z0_C_L->Write(); + rms = h_res_z0_C_L->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "|eta| < 0.8"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_z0_C_L.pdf"); + + h_res_z0_I_L->Draw(); + h_res_z0_I_L->Write(); + rms = h_res_z0_I_L->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "0.8 < |eta| < 1.6"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_z0_I_L.pdf"); + + h_res_z0_F_L->Draw(); + h_res_z0_F_L->Write(); + rms = h_res_z0_F_L->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "|eta| > 1.6"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_z0_F_L.pdf"); + + h_res_z0_C_H->Draw(); + h_res_z0_C_H->Write(); + rms = h_res_z0_C_H->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "|eta| < 0.8"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_z0_C_H.pdf"); + + h_res_z0_I_H->Draw(); + h_res_z0_I_H->Write(); + rms = h_res_z0_I_H->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "0.8 < |eta| < 1.6"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_z0_I_H.pdf"); + + h_res_z0_F_H->Draw(); + h_res_z0_F_H->Write(); + rms = h_res_z0_F_H->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "|eta| > 1.6"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_z0_F_H.pdf"); + + h_res_z0_L->Draw(); + h_res_z0_L->Write(); + rms = h_res_z0_L->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "p_{T} < 5 GeV"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_z0_L.pdf"); + + h_res_z0_H->Draw(); + h_res_z0_H->Write(); + rms = h_res_z0_H->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "p_{T} > 15 GeV"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_z0_H.pdf"); + + if (h_res_d0->GetEntries() > 0) { + h_res_d0->Draw(); + rms = h_res_d0->GetRMS(); + sprintf(ctxt, "RMS = %.4f", rms); + mySmallText(0.22, 0.82, 1, ctxt); + c.SaveAs(DIR + type + "_res_d0.pdf"); + + h_res_d0_C->Draw(); + h_res_d0_C->Write(); + rms = h_res_d0_C->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "|eta| < 0.8"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_d0_C.pdf"); + + h_res_d0_I->Draw(); + h_res_d0_I->Write(); + rms = h_res_d0_I->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "0.8 < |eta| < 1.6"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_d0_I.pdf"); + + h_res_d0_F->Draw(); + h_res_d0_F->Write(); + rms = h_res_d0_F->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "|eta| > 1.6"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_d0_F.pdf"); + + h_res_d0_C_L->Draw(); + h_res_d0_C_L->Write(); + rms = h_res_d0_C_L->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "|eta| < 0.8"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_d0_C_L.pdf"); + + h_res_d0_I_L->Draw(); + h_res_d0_I_L->Write(); + rms = h_res_d0_I_L->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "0.8 < |eta| < 1.6"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_d0_I_L.pdf"); + + h_res_d0_F_L->Draw(); + h_res_d0_F_L->Write(); + rms = h_res_d0_F_L->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "|eta| > 1.6"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_d0_F_L.pdf"); + + h_res_d0_C_H->Draw(); + h_res_d0_C_H->Write(); + rms = h_res_d0_C_H->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "|eta| < 0.8"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_d0_C_H.pdf"); + + h_res_d0_I_H->Draw(); + h_res_d0_I_H->Write(); + rms = h_res_d0_I_H->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "0.8 < |eta| < 1.6"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_d0_I_H.pdf"); + + h_res_d0_F_H->Draw(); + h_res_d0_F_H->Write(); + rms = h_res_d0_F_H->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "|eta| > 1.6"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_d0_F_H.pdf"); + + h_res_d0_L->Draw(); + h_res_d0_L->Write(); + rms = h_res_d0_L->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "p_{T} < 5 GeV"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_d0_L.pdf"); + + h_res_d0_H->Draw(); + h_res_d0_H->Write(); + rms = h_res_d0_H->GetRMS(); + sprintf(ctxt, "RMS = %.4f;", rms); + mySmallText(0.22, 0.82, 1, ctxt); + sprintf(ctxt, "p_{T} > 15 GeV"); + mySmallText(0.22, 0.76, 1, ctxt); + c.SaveAs(DIR + type + "_res_d0_H.pdf"); + } + } + + // --------------------------------------------------------------------------------------------------------- + // "fake rates" + + h_trk_all_vspt->Sumw2(); + h_trk_loose_vspt->Sumw2(); + h_trk_genuine_vspt->Sumw2(); + h_trk_notloose_vspt->Sumw2(); + h_trk_notgenuine_vspt->Sumw2(); + h_trk_duplicate_vspt->Sumw2(); + h_tp_vspt->Sumw2(); + + // fraction of not genuine tracks + TH1F* h_notgenuine_pt = (TH1F*)h_trk_notgenuine_vspt->Clone(); + h_notgenuine_pt->SetName("notgenuine_pt"); + h_notgenuine_pt->GetYaxis()->SetTitle("Not genuine fraction"); + h_notgenuine_pt->Divide(h_trk_notgenuine_vspt, h_trk_all_vspt, 1.0, 1.0, "B"); + + h_notgenuine_pt->Write(); + h_notgenuine_pt->Draw(); + c.SaveAs(DIR + type + "_notgenuine.pdf"); + + // fraction of not loosely genuine tracks + TH1F* h_notloose_pt = (TH1F*)h_trk_notloose_vspt->Clone(); + h_notloose_pt->SetName("notloose_pt"); + h_notloose_pt->GetYaxis()->SetTitle("Not loose fraction"); + h_notloose_pt->Divide(h_trk_notloose_vspt, h_trk_all_vspt, 1.0, 1.0, "B"); + + h_notloose_pt->Write(); + h_notloose_pt->Draw(); + c.SaveAs(DIR + type + "_notloose.pdf"); + + // fraction of DUPLICATE tracks (genuine and not matched) + TH1F* h_duplicatefrac_pt = (TH1F*)h_trk_duplicate_vspt->Clone(); + h_duplicatefrac_pt->SetName("duplicatefrac_pt"); + h_duplicatefrac_pt->GetYaxis()->SetTitle("Duplicate fraction"); + h_duplicatefrac_pt->Divide(h_trk_duplicate_vspt, h_trk_all_vspt, 1.0, 1.0, "B"); + + h_duplicatefrac_pt->Write(); + h_duplicatefrac_pt->Draw(); + c.SaveAs(DIR + type + "_duplicatefrac.pdf"); + + // --------------------------------------------------------------------------------------------------------- + // total track rates vs pt + + h_trk_all_vspt->Scale(1.0 / nevt); + h_trk_loose_vspt->Scale(1.0 / nevt); + h_trk_genuine_vspt->Scale(1.0 / nevt); + h_trk_notloose_vspt->Scale(1.0 / nevt); + h_trk_notgenuine_vspt->Scale(1.0 / nevt); + h_trk_duplicate_vspt->Scale(1.0 / nevt); + h_tp_vspt->Scale(1.0 / nevt); + + h_tp_vspt->GetYaxis()->SetTitle("Tracks / event"); + h_tp_vspt->GetXaxis()->SetTitle("Track p_{T} [GeV]"); + h_tp_vspt->SetLineColor(4); + h_tp_vspt->SetLineStyle(2); + + h_trk_notgenuine_vspt->SetLineColor(2); + h_trk_notgenuine_vspt->SetLineStyle(1); + + h_trk_duplicate_vspt->SetLineColor(8); + h_trk_duplicate_vspt->SetLineStyle(2); + + float max = h_tp_vspt->GetMaximum(); + if (h_trk_all_vspt->GetMaximum() > max) + max = h_trk_all_vspt->GetMaximum(); + h_tp_vspt->SetAxisRange(0.001, max * 1.5, "Y"); + + h_tp_vspt->Draw("hist"); + h_trk_all_vspt->Draw("same,hist"); + h_tp_vspt->Draw("same,hist"); + h_trk_notgenuine_vspt->Draw("same,hist"); + //h_trk_duplicate_vspt->Draw("same,hist"); + + h_trk_all_vspt->Write(); + h_trk_loose_vspt->Write(); + h_trk_genuine_vspt->Write(); + h_trk_notloose_vspt->Write(); + h_trk_notgenuine_vspt->Write(); + h_trk_duplicate_vspt->Write(); + h_tp_vspt->Write(); + + char txt[500]; + sprintf(txt, "# tracks/event = %.1f", h_trk_all_vspt->GetSum()); + mySmallText(0.5, 0.85, 1, txt); + char txt3[500]; + sprintf(txt3, "# TPs(stubs in #geq 4 layers)/"); + char txt2[500]; + sprintf(txt2, "event = %.1f", h_tp_vspt->GetSum()); + mySmallText(0.5, 0.79, 4, txt3); + mySmallText(0.5, 0.74, 4, txt2); + + sprintf(txt, "# !genuine tracks/event = %.1f", h_trk_notgenuine_vspt->GetSum()); + mySmallText(0.5, 0.69, 2, txt); + //sprintf(txt,"# duplicates/event = %.1f",h_trk_duplicate_vspt->GetSum()); + //mySmallText(0.5,0.64,8,txt); + + c.SaveAs(DIR + type + "_trackrate_vspt.pdf"); + + gPad->SetLogy(); + c.SaveAs(DIR + type + "_trackrate_vspt_log.pdf"); + gPad->SetLogy(0); + + // --------------------------------------------------------------------------------------------------------- + // sum track/ TP pt in jets + /* + if (TP_select_injet > 0) { + + TH1F* h_frac_sumpt_vspt = (TH1F*) h_jet_trk_sumpt_vspt->Clone(); + h_frac_sumpt_vspt->SetName("frac_sumpt_vspt"); + h_frac_sumpt_vspt->GetYaxis()->SetTitle("L1 sum(p_{T}) / TP sum(p_{T})"); + h_frac_sumpt_vspt->Divide(h_jet_trk_sumpt_vspt, h_jet_tp_sumpt_vspt, 1.0, 1.0, "B"); + + TH1F* h_frac_sumpt_vseta = (TH1F*) h_jet_trk_sumpt_vseta->Clone(); + h_frac_sumpt_vseta->SetName("frac_sumpt_vseta"); + h_frac_sumpt_vseta->GetYaxis()->SetTitle("L1 sum(p_{T}) / TP sum(p_{T})"); + h_frac_sumpt_vseta->Divide(h_jet_trk_sumpt_vseta, h_jet_tp_sumpt_vseta, 1.0, 1.0, "B"); + + + TH1F* h_matchfrac_sumpt_vspt = (TH1F*) h_jet_matchtrk_sumpt_vspt->Clone(); + h_matchfrac_sumpt_vspt->SetName("matchfrac_sumpt_vspt"); + h_matchfrac_sumpt_vspt->GetYaxis()->SetTitle("Matched L1 sum(p_{T}) / TP sum(p_{T})"); + h_matchfrac_sumpt_vspt->Divide(h_jet_matchtrk_sumpt_vspt, h_jet_tp_sumpt_vspt, 1.0, 1.0, "B"); + + TH1F* h_matchfrac_sumpt_vseta = (TH1F*) h_jet_matchtrk_sumpt_vseta->Clone(); + h_matchfrac_sumpt_vseta->SetName("matchfrac_sumpt_vseta"); + h_matchfrac_sumpt_vseta->GetYaxis()->SetTitle("Matched L1 sum(p_{T}) / TP sum(p_{T})"); + h_matchfrac_sumpt_vseta->Divide(h_jet_matchtrk_sumpt_vseta, h_jet_tp_sumpt_vseta, 1.0, 1.0, "B"); + + + h_frac_sumpt_vspt->Draw(); + c.SaveAs(DIR+type+"_sumpt_vspt.pdf"); + + h_frac_sumpt_vseta->Draw(); + c.SaveAs(DIR+type+"_sumpt_vseta.pdf"); + + h_matchfrac_sumpt_vspt->Draw(); + c.SaveAs(DIR+type+"_sumpt_match_vspt.pdf"); + + h_matchfrac_sumpt_vseta->Draw(); + c.SaveAs(DIR+type+"_sumpt_match_vseta.pdf"); + } + */ + + // nbr tracks per event + + h_ntrk_pt2->Write(); + h_ntrk_pt3->Write(); + h_ntrk_pt10->Write(); + + h_ntrkPerSector_pt2->Write(); + h_ntrkPerSector_pt3->Write(); + h_ntrkPerSector_pt4->Write(); + + h_ntrkPerSector_pt2->Scale(1.0 / nevt); + h_ntrkPerSector_pt3->Scale(1.0 / nevt); + h_ntrkPerSector_pt4->Scale(1.0 / nevt); + + h_ntrkPerSector_pt2->GetYaxis()->SetTitle("Fraction of events"); + h_ntrkPerSector_pt2->GetXaxis()->SetTitle("Max number of transmitted tracks per #phi sector"); + + h_ntrkPerSector_pt2->SetLineColor(4); + h_ntrkPerSector_pt3->SetLineColor(2); + h_ntrkPerSector_pt4->SetLineColor(8); + + max = h_ntrkPerSector_pt2->GetMaximum(); + h_ntrkPerSector_pt2->SetAxisRange(0.00001, max * 5, "Y"); + h_ntrkPerSector_pt2->SetAxisRange(0., 100, "X"); + + h_ntrkPerSector_pt2->Draw("hist"); + h_ntrkPerSector_pt3->Draw("same,hist"); + h_ntrkPerSector_pt4->Draw("same,hist"); + gPad->SetLogy(); + + TLegend* l = new TLegend(0.6, 0.55, 0.85, 0.85); + l->SetFillStyle(0); + l->SetBorderSize(0); + l->SetTextSize(0.04); + l->AddEntry(h_ntrkPerSector_pt2, "p_{T}^{track} > 2 GeV", "l"); + l->AddEntry(h_ntrkPerSector_pt3, "p_{T}^{track} > 3 GeV", "l"); + l->AddEntry(h_ntrkPerSector_pt4, "p_{T}^{track} > 4 GeV", "l"); + l->SetTextFont(42); + l->Draw(); + + c.SaveAs(DIR + type + "_trackRatePerPhiSector_log.pdf"); + gPad->SetLogy(0); + + h_ntrk_genuine_pt2->Write(); + h_ntrk_genuine_pt3->Write(); + h_ntrk_genuine_pt10->Write(); + + if (doDetailedPlots) { + h_ntrk_pt2->Draw(); + c.SaveAs(DIR + type + "_trackrate_pt2_perevt.pdf"); + + h_ntrk_pt3->Draw(); + c.SaveAs(DIR + type + "_trackrate_pt3_perevt.pdf"); + + h_ntrk_pt10->Draw(); + c.SaveAs(DIR + type + "_trackrate_pt10_perevt.pdf"); + } + + fout->Close(); + + // --------------------------------------------------------------------------------------------------------- + //some printouts + + float k = (float)n_match_eta1p0; + float N = (float)n_all_eta1p0; + if (std::abs(N) > 0) + cout << endl + << "efficiency for |eta| < 1.0 = " << k / N * 100.0 << " +- " << 1.0 / N * sqrt(k * (1.0 - k / N)) * 100.0 + << endl; + k = (float)n_match_eta1p75; + N = (float)n_all_eta1p75; + if (std::abs(N) > 0) + cout << "efficiency for 1.0 < |eta| < 1.75 = " << k / N * 100.0 << " +- " + << 1.0 / N * sqrt(k * (1.0 - k / N)) * 100.0 << endl; + k = (float)n_match_eta2p5; + N = (float)n_all_eta2p5; + if (std::abs(N) > 0) + cout << "efficiency for 1.75 < |eta| < " << std::min(TP_maxEta, 2.5f) << " = " << k / N * 100.0 << " +- " + << 1.0 / N * sqrt(k * (1.0 - k / N)) * 100.0 << endl; + N = (float)n_all_eta1p0 + n_all_eta1p75 + n_all_eta2p5; + k = (float)n_match_eta1p0 + n_match_eta1p75 + n_match_eta2p5; + if (std::abs(N) > 0) + cout << "combined efficiency for |eta| < " << std::min(TP_maxEta, 2.5f) << " = " << k / N * 100.0 << " +- " + << 1.0 / N * sqrt(k * (1.0 - k / N)) * 100.0 << " = " << k << "/" << N << endl + << endl; + + k = (float)n_match_ptg2; + N = (float)n_all_ptg2; + if (std::abs(N) > 0) + cout << "efficiency for pt > " << std::max(TP_minPt, 2.0f) << " = " << k / N * 100.0 << " +- " + << 1.0 / N * sqrt(k * (1.0 - k / N)) * 100.0 << endl; + k = (float)n_match_pt2to8; + N = (float)n_all_pt2to8; + if (std::abs(N) > 0) + cout << "efficiency for " << std::max(TP_minPt, 2.0f) << " < pt < 8.0 = " << k / N * 100.0 << " +- " + << 1.0 / N * sqrt(k * (1.0 - k / N)) * 100.0 << endl; + k = (float)n_match_ptg8; + N = (float)n_all_ptg8; + if (std::abs(N) > 0) + cout << "efficiency for pt > 8.0 = " << k / N * 100.0 << " +- " << 1.0 / N * sqrt(k * (1.0 - k / N)) * 100.0 + << endl; + k = (float)n_match_ptg40; + N = (float)n_all_ptg40; + if (std::abs(N) > 0) + cout << "efficiency for pt > 40.0 = " << k / N * 100.0 << " +- " << 1.0 / N * sqrt(k * (1.0 - k / N)) * 100.0 + << endl + << endl; + + // track rates + cout << "# TP/event (pt > " << std::max(TP_minPt, 2.0f) << ") = " << (float)ntp_pt2 / nevt << endl; + cout << "# TP/event (pt > 3.0) = " << (float)ntp_pt3 / nevt << endl; + cout << "# TP/event (pt > 10.0) = " << (float)ntp_pt10 / nevt << endl; + + cout << "# tracks/event (pt > " << std::max(TP_minPt, 2.0f) << ") = " << (float)ntrk_pt2 / nevt << endl; + cout << "# tracks/event (pt > 3.0) = " << (float)ntrk_pt3 / nevt << endl; + cout << "# tracks/event (pt > 10.0) = " << (float)ntrk_pt10 / nevt << endl; +} + +void SetPlotStyle() { + // from ATLAS plot style macro + + // use plain black on white colors + gStyle->SetFrameBorderMode(0); + gStyle->SetFrameFillColor(0); + gStyle->SetCanvasBorderMode(0); + gStyle->SetCanvasColor(0); + gStyle->SetPadBorderMode(0); + gStyle->SetPadColor(0); + gStyle->SetStatColor(0); + gStyle->SetHistLineColor(1); + + gStyle->SetPalette(1); + + // set the paper & margin sizes + gStyle->SetPaperSize(20, 26); + gStyle->SetPadTopMargin(0.05); + gStyle->SetPadRightMargin(0.05); + gStyle->SetPadBottomMargin(0.16); + gStyle->SetPadLeftMargin(0.16); + + // set title offsets (for axis label) + gStyle->SetTitleXOffset(1.4); + gStyle->SetTitleYOffset(1.4); + + // use large fonts + gStyle->SetTextFont(42); + gStyle->SetTextSize(0.05); + gStyle->SetLabelFont(42, "x"); + gStyle->SetTitleFont(42, "x"); + gStyle->SetLabelFont(42, "y"); + gStyle->SetTitleFont(42, "y"); + gStyle->SetLabelFont(42, "z"); + gStyle->SetTitleFont(42, "z"); + gStyle->SetLabelSize(0.05, "x"); + gStyle->SetTitleSize(0.05, "x"); + gStyle->SetLabelSize(0.05, "y"); + gStyle->SetTitleSize(0.05, "y"); + gStyle->SetLabelSize(0.05, "z"); + gStyle->SetTitleSize(0.05, "z"); + + // use bold lines and markers + gStyle->SetMarkerStyle(20); + gStyle->SetMarkerSize(1.2); + gStyle->SetHistLineWidth(2.); + gStyle->SetLineStyleString(2, "[12 12]"); + + // get rid of error bar caps + gStyle->SetEndErrorSize(0.); + + // do not display any of the standard histogram decorations + gStyle->SetOptTitle(0); + gStyle->SetOptStat(0); + gStyle->SetOptFit(0); + + // put tick marks on top and RHS of plots + gStyle->SetPadTickX(1); + gStyle->SetPadTickY(1); +} + +void mySmallText(Double_t x, Double_t y, Color_t color, char* text) { + Double_t tsize = 0.044; + TLatex l; + l.SetTextSize(tsize); + l.SetNDC(); + l.SetTextColor(color); + l.DrawLatex(x, y, text); +} + +double getIntervalContainingFractionOfEntries(TH1* absResidualHistogram, double quantileToCalculate, int minEntries) { + double totalIntegral = absResidualHistogram->Integral(0, absResidualHistogram->GetNbinsX() + 1); + double numEntries = absResidualHistogram->GetEntries(); + + // Check that the interval is not somewhere in the overflow bin + double maxAllowedEntriesInOverflow = totalIntegral * (1 - quantileToCalculate); + double nEntriesInOverflow = absResidualHistogram->GetBinContent(absResidualHistogram->GetNbinsX() + 1); + if (nEntriesInOverflow > maxAllowedEntriesInOverflow) { + // cout << "WARNING : Cannot compute range corresponding to interval, as it is in the overflow bin" << endl; + return absResidualHistogram->GetXaxis()->GetXmax() * 1.2; + } + + // Calculate quantile for given interval + double interval[1]; + double quantile[1] = {quantileToCalculate}; + if (totalIntegral > 0 && numEntries >= minEntries) { + absResidualHistogram->GetQuantiles(1, interval, quantile); + } else { + cout << "WARNING: histo " << absResidualHistogram->GetName() + << " empty or with too few entries, so can't calc quantiles." << endl; + interval[0] = 0.; + } + + return interval[0]; +} + +void makeResidualIntervalPlot( + TString type, TString dir, TString variable, TH1F* h_68, TH1F* h_90, TH1F* h_99, double minY, double maxY) { + TCanvas c; + + h_68->SetMinimum(minY); + h_90->SetMinimum(minY); + h_99->SetMinimum(minY); + + h_68->SetMaximum(maxY); + h_90->SetMaximum(maxY); + h_99->SetMaximum(maxY); + + h_68->SetMarkerStyle(20); + h_90->SetMarkerStyle(26); + h_99->SetMarkerStyle(24); + + h_68->Draw("P"); + h_68->Write(); + h_90->Draw("P same"); + h_90->Write(); + h_99->Draw("P same"); + h_99->Write(); + + TLegend* l = new TLegend(0.65, 0.65, 0.85, 0.85); + l->SetFillStyle(0); + l->SetBorderSize(0); + l->SetTextSize(0.04); + l->AddEntry(h_99, "99%", "p"); + l->AddEntry(h_90, "90%", "p"); + l->AddEntry(h_68, "68%", "p"); + l->SetTextFont(42); + l->Draw(); + + c.SaveAs(dir + type + "_" + variable + "_interval.pdf"); + + delete l; +} diff --git a/L1Trigger/TrackFindingTracklet/test/Makefile b/L1Trigger/TrackFindingTracklet/test/Makefile new file mode 100644 index 0000000000000..634405731eac9 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/test/Makefile @@ -0,0 +1,245 @@ +#common definitions go in here +CXX = g++ +CXXFLAGS = -O -Wall -fPIC -g -ansi -Wextra -Wno-deprecated -std=c++17 -I. -I../../.. +LD = g++ +LDFLAGS = -O +LIBDIR = $(WORKDIR) +AR = ar +ARFLAGS = cr + +OS := $(shell uname -s) +ifeq ($(OS),Darwin) + SOFLAGS = -dynamiclib +else + SOFLAGS = -shared +endif + +ifndef ROOTSYS +$(error *** Please set up Root) +endif + +ifeq ("$(wildcard lib)","") +$(shell mkdir lib) +endif + +# +# Add system headers here (hack around problem with makedepend +# if you added file remove the dummyIncl directory to rewrite files +# +ifeq ("$(wildcard dummyIncl)","") +$(shell mkdir dummyIncl) +$(shell mkdir dummyIncl/sys) +$(shell mkdir dummyIncl/ext) +$(shell touch dummyIncl/TBranch.h) +$(shell touch dummyIncl/TCanvas.h) +$(shell touch dummyIncl/TChain.h) +$(shell touch dummyIncl/TColor.h) +$(shell touch dummyIncl/TEfficiency.h) +$(shell touch dummyIncl/TFile.h) +$(shell touch dummyIncl/TH1D.h) +$(shell touch dummyIncl/TH1F.h) +$(shell touch dummyIncl/TH2F.h) +$(shell touch dummyIncl/TLatex.h) +$(shell touch dummyIncl/TLegend.h) +$(shell touch dummyIncl/TMath.h) +$(shell touch dummyIncl/TROOT.h) +$(shell touch dummyIncl/TStyle.h) +$(shell touch dummyIncl/TSystem.h) +$(shell touch dummyIncl/TTree.h) +$(shell touch dummyIncl/algorithm) +$(shell touch dummyIncl/array) +$(shell touch dummyIncl/bitset) +$(shell touch dummyIncl/cassert) +$(shell touch dummyIncl/chrono) +$(shell touch dummyIncl/cctype) +$(shell touch dummyIncl/cmath) +$(shell touch dummyIncl/ctime) +$(shell touch dummyIncl/cstdlib) +$(shell touch dummyIncl/cmath) +$(shell touch dummyIncl/exception) +$(shell touch dummyIncl/fstream) +$(shell touch dummyIncl/iomanip) +$(shell touch dummyIncl/iostream) +$(shell touch dummyIncl/limits) +$(shell touch dummyIncl/map) +$(shell touch dummyIncl/memory) +$(shell touch dummyIncl/set) +$(shell touch dummyIncl/sstream) +$(shell touch dummyIncl/string) +$(shell touch dummyIncl/vector) +$(shell touch dummyIncl/unordered_map) +$(shell touch dummyIncl/unordered_set) +$(shell touch dummyIncl/utility) +$(shell touch dummyIncl/algorithm) +$(shell touch dummyIncl/ext/hash_set) +$(shell touch dummyIncl/sys/time.h) +$(shell touch dummyIncl/ctime) +$(shell touch dummyIncl/chrono) +endif + +ifeq ("$(wildcard FWCore)","") +$(shell mkdir FWCore) +$(shell mkdir FWCore/MessageLogger) +$(shell mkdir FWCore/MessageLogger/interface) +$(shell mkdir FWCore/Utilities) +$(shell mkdir FWCore/Utilities/interface) +endif + +ifeq ("$(wildcard FWCore/Utilities/interface/Exception.h)","") +$(shell echo "#ifndef L1Trigger_TrackFindingTracklet_interface_Exception_h" > FWCore/Utilities/interface/Exception.h) +$(shell echo "#define L1Trigger_TrackFindingTracklet_interface_Exception_h" >> FWCore/Utilities/interface/Exception.h) +$(shell echo "#include" >> FWCore/Utilities/interface/Exception.h) +$(shell echo "namespace cms {" >> FWCore/Utilities/interface/Exception.h) +$(shell echo " class Exception{" >> FWCore/Utilities/interface/Exception.h) +$(shell echo " public:" >> FWCore/Utilities/interface/Exception.h) +$(shell echo " Exception(std::string type) { if(0) {std::cout<> FWCore/Utilities/interface/Exception.h) +$(shell echo " ~Exception() { std::cout << std::endl;}" >> FWCore/Utilities/interface/Exception.h) +$(shell echo " template Exception& operator<<(T const& t) {std::cout << t;return *this;}" >> FWCore/Utilities/interface/Exception.h) +$(shell echo " Exception& operator<<(std::ostream& (*f)(std::ostream&)) {std::cout << f;return *this;}" >> FWCore/Utilities/interface/Exception.h) +$(shell echo " Exception& operator<<(std::ios_base& (*f)(std::ios_base&)) {std::cout << f;return *this;}" >> FWCore/Utilities/interface/Exception.h) +$(shell echo " };" >> FWCore/Utilities/interface/Exception.h) +$(shell echo "};" >> FWCore/Utilities/interface/Exception.h) +$(shell echo "#endif" >> FWCore/Utilities/interface/Exception.h) +endif + +ifeq ("$(wildcard FWCore/MessageLogger/interface/MessageLogger.h)","") +$(shell echo "#ifndef L1Trigger_TrackFindingTracklet_interface_Logger_h" > FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo "#define L1Trigger_TrackFindingTracklet_interface_Logger_h" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo "#include" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo "namespace edm {" >> FWCore/MessageLogger/interface/MessageLogger.h) +# INFO statement +$(shell echo " class LogVerbatim{" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " public:" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " LogVerbatim(std::string type) { if(0) {std::cout<> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " ~LogVerbatim() { std::cout << std::endl;}" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " template LogVerbatim& operator<<(T const& t) {std::cout << t;return *this;}" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " LogVerbatim& operator<<(std::ostream& (*f)(std::ostream&)) {std::cout << f;return *this;}" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " LogVerbatim& operator<<(std::ios_base& (*f)(std::ios_base&)) {std::cout << f;return *this;}" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " };" >> FWCore/MessageLogger/interface/MessageLogger.h) +# WARNING statement +$(shell echo " class LogPrint{" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " public:" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " LogPrint(std::string type) { if(0) {std::cout<> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " ~LogPrint() { std::cout << std::endl;}" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " template LogPrint& operator<<(T const& t) {std::cout << t;return *this;}" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " LogPrint& operator<<(std::ostream& (*f)(std::ostream&)) {std::cout << f;return *this;}" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " LogPrint& operator<<(std::ios_base& (*f)(std::ios_base&)) {std::cout << f;return *this;}" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " };" >> FWCore/MessageLogger/interface/MessageLogger.h) +# another WARNING statement +$(shell echo " class LogWarning{" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " public:" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " LogWarning(std::string type) { if(0) {std::cout<> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " ~LogWarning() { std::cout << std::endl;}" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " template LogWarning& operator<<(T const& t) {std::cout << t;return *this;}" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " LogWarning& operator<<(std::ostream& (*f)(std::ostream&)) {std::cout << f;return *this;}" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " LogWarning& operator<<(std::ios_base& (*f)(std::ios_base&)) {std::cout << f;return *this;}" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " };" >> FWCore/MessageLogger/interface/MessageLogger.h) +# ERROR statement +$(shell echo " class LogProblem{" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " public:" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " LogProblem(std::string type) { if(0) {std::cout<> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " ~LogProblem() { std::cout << std::endl;}" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " template LogProblem& operator<<(T const& t) {std::cout << t;return *this;}" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " LogProblem& operator<<(std::ostream& (*f)(std::ostream&)) {std::cout << f;return *this;}" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " LogProblem& operator<<(std::ios_base& (*f)(std::ios_base&)) {std::cout << f;return *this;}" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo " };" >> FWCore/MessageLogger/interface/MessageLogger.h) +# +$(shell echo "};" >> FWCore/MessageLogger/interface/MessageLogger.h) +$(shell echo "#endif" >> FWCore/MessageLogger/interface/MessageLogger.h) +endif + +# reduceRange for standalone +ifeq ("$(wildcard DataFormats/Math/interface)","") +$(shell mkdir DataFormats) +$(shell mkdir DataFormats/Math) +$(shell mkdir DataFormats/Math/interface) +endif + +ifeq ("$(wildcard DataFormats/Math/interface/deltaPhi.h)","") +$(shell echo "#ifndef DataFormats_Math_interface_deltaPhi_h" > DataFormats/Math/interface/deltaPhi.h) +$(shell echo "#define DataFormats_Math_interface_deltaPhi_h" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo "namespace reco {" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " inline double reduceRange(double phi) { assert(std::abs(phi) < 100.0); " >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " while (phi < -M_PI) { phi += 2 * M_PI; }" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " while (phi > M_PI) { phi -= 2 * M_PI; }" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " return phi; } " >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo "};" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo "namespace angle0to2pi {" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " inline double make0To2pi(double phi) { assert(std::abs(phi) < 100.0); " >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " while (phi < 0.0) { phi += 2 * M_PI; }" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " while (phi > 2 * M_PI) { phi -= 2 * M_PI; }" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " return phi; } " >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo "};" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo "#endif" >> DataFormats/Math/interface/deltaPhi.h) +endif + +#find out about the installed ROOT +ROOTCONFIG := $(ROOTSYS)/bin/root-config +ROOTCFLAGS := $(shell $(ROOTCONFIG) --cflags) +ROOTLDFLAGS := $(shell $(ROOTCONFIG) --ldflags) $(shell $(ROOTCONFIG) --libs --nonew --glibs) + +#append to options +CXXFLAGS += $(ROOTCFLAGS) +LDFLAGS += $(ROOTLDFLAGS) +# Needed for ROOT-Tree +#LDFLAGS += -L./ FPGAEvent_cxx.so + +CXXFLAGS += -std=c++17 #fix, otherwise ROOT cflags overrule c++11 + +LIBS = -lHtml + + +ifneq ($(CMSSW_BASE),) + ROOTFIT_INCLUDE := $(shell cd $(CMSSW_BASE); scram tool info roofitcore | grep INCLUDE= | sed 's|INCLUDE=||') + ROOTFIT_LIBDIR := $(shell cd $(CMSSW_BASE); scram tool info roofitcore | grep LIBDIR= | sed 's|LIBDIR=||') + + CINTINCLUDES := -I$(ROOTFIT_INCLUDE) + CXXFLAGS += -I$(ROOTFIT_INCLUDE) + LDFLAGS += -L$(ROOTFIT_LIBDIR) +endif + + +DEPDIR = .deps + +MAKEDEPEND = makedepend -I../../.. -IdummyIncl -f- $< | sed 's/..\/src/lib/' > .deps/$*.d + +SRCS = $(wildcard ../src/*.cc) + +OBJS = $(SRCS:../src/%.cc=lib/%.o) + +default: fpga + +fpga: fpga.a fpga.o + $(LD) -o $@ fpga.o fpga.a $(LDFLAGS) $(LIBS) + +fpga.o: fpga.cc $(DEPDIR)/fpga.d | $(DEPDIR) + @$(MAKEDEPEND) + $(CXX) $(CXXFLAGS) -c fpga.cc -o $@ + +fpga.a:$(OBJS) + @$(AR) $(ARFLAGS) $@ $? + +lib/%.o:../src/%.cc $(DEPDIR)/%.d | $(DEPDIR) + @$(MAKEDEPEND) + time $(CXX) $(CXXFLAGS) -o $@ -c $< + +$(DEPDIR): ; @mkdir -p $@ + +%.d: ; + +DEPFILES := $(SRCS:../src/%.cc=$(DEPDIR)/%.d) +$(DEPFILES): +include $(wildcard $(DEPFILES)) +include $(wildcard $(DEPDIR)/fpga.d) + + +clean: + @rm -f *.o + @rm -f fpga + @rm -f fpga.a + @rm -rf DataFormats/ + @rm -rf FWCore/ + @rm -rf lib/ + @rm -rf dummyIncl/ + @rm -rf .deps/ + diff --git a/L1Trigger/TrackFindingTracklet/test/WriteDesign.icc b/L1Trigger/TrackFindingTracklet/test/WriteDesign.icc new file mode 100644 index 0000000000000..740265c09a856 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/test/WriteDesign.icc @@ -0,0 +1,648 @@ +std::map > v; + +//////////////////////////////////////////////////////////////////////////// +// L1L2 +//////////////////////////////////////////////////////////////////////////// +v["L1L2"]; + +v.at("L1L2").push_back(&globals->ITC_L1L2()->rinv_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->phi0_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->t_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->z0_final); + +v.at("L1L2").push_back(&globals->ITC_L1L2()->phiL_0_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->phiL_1_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->phiL_2_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->phiL_3_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->zL_0_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->zL_1_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->zL_2_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->zL_3_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->der_phiL_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->der_zL_final); + +v.at("L1L2").push_back(&globals->ITC_L1L2()->phiD_0_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->phiD_1_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->phiD_2_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->phiD_3_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->phiD_4_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->rD_0_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->rD_1_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->rD_2_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->rD_3_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->rD_4_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->der_phiD_final); +v.at("L1L2").push_back(&globals->ITC_L1L2()->der_rD_final); + +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_trackpar); + +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_phiL_0); +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_phiL_1); +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_phiL_2); +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_phiL_3); + +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_zL_0); +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_zL_1); +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_zL_2); +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_zL_3); + +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_der_phiL); +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_der_zL); + +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_phiD_0); +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_phiD_1); +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_phiD_2); +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_phiD_3); +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_phiD_4); + +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_rD_0); +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_rD_1); +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_rD_2); +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_rD_3); +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_rD_4); + +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_der_phiD); +v.at("L1L2").push_back(&globals->ITC_L1L2()->valid_der_rD); +//////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////// +// L3L4 +//////////////////////////////////////////////////////////////////////////// +v["L3L4"]; + +v.at("L3L4").push_back(&globals->ITC_L3L4()->rinv_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->phi0_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->t_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->z0_final); + +v.at("L3L4").push_back(&globals->ITC_L3L4()->phiL_0_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->phiL_1_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->phiL_2_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->phiL_3_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->zL_0_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->zL_1_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->zL_2_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->zL_3_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->der_phiL_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->der_zL_final); + +v.at("L3L4").push_back(&globals->ITC_L3L4()->phiD_0_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->phiD_1_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->phiD_2_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->phiD_3_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->phiD_4_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->rD_0_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->rD_1_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->rD_2_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->rD_3_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->rD_4_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->der_phiD_final); +v.at("L3L4").push_back(&globals->ITC_L3L4()->der_rD_final); + +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_trackpar); + +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_phiL_0); +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_phiL_1); +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_phiL_2); +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_phiL_3); + +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_zL_0); +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_zL_1); +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_zL_2); +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_zL_3); + +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_der_phiL); +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_der_zL); + +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_phiD_0); +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_phiD_1); +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_phiD_2); +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_phiD_3); +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_phiD_4); + +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_rD_0); +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_rD_1); +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_rD_2); +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_rD_3); +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_rD_4); + +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_der_phiD); +v.at("L3L4").push_back(&globals->ITC_L3L4()->valid_der_rD); +//////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////// +// L5L6 +//////////////////////////////////////////////////////////////////////////// +v["L5L6"]; + +v.at("L5L6").push_back(&globals->ITC_L5L6()->rinv_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->phi0_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->t_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->z0_final); + +v.at("L5L6").push_back(&globals->ITC_L5L6()->phiL_0_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->phiL_1_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->phiL_2_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->phiL_3_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->zL_0_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->zL_1_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->zL_2_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->zL_3_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->der_phiL_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->der_zL_final); + +v.at("L5L6").push_back(&globals->ITC_L5L6()->phiD_0_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->phiD_1_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->phiD_2_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->phiD_3_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->phiD_4_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->rD_0_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->rD_1_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->rD_2_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->rD_3_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->rD_4_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->der_phiD_final); +v.at("L5L6").push_back(&globals->ITC_L5L6()->der_rD_final); + +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_trackpar); + +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_phiL_0); +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_phiL_1); +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_phiL_2); +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_phiL_3); + +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_zL_0); +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_zL_1); +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_zL_2); +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_zL_3); + +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_der_phiL); +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_der_zL); + +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_phiD_0); +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_phiD_1); +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_phiD_2); +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_phiD_3); +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_phiD_4); + +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_rD_0); +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_rD_1); +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_rD_2); +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_rD_3); +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_rD_4); + +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_der_phiD); +v.at("L5L6").push_back(&globals->ITC_L5L6()->valid_der_rD); +//////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////// +// F1F2 +//////////////////////////////////////////////////////////////////////////// +v["F1F2"]; + +v.at("F1F2").push_back(&globals->ITC_F1F2()->rinv_final); +v.at("F1F2").push_back(&globals->ITC_F1F2()->phi0_final); +v.at("F1F2").push_back(&globals->ITC_F1F2()->t_final); +v.at("F1F2").push_back(&globals->ITC_F1F2()->z0_final); + +v.at("F1F2").push_back(&globals->ITC_F1F2()->phiL_0_final); +v.at("F1F2").push_back(&globals->ITC_F1F2()->phiL_1_final); +v.at("F1F2").push_back(&globals->ITC_F1F2()->phiL_2_final); +v.at("F1F2").push_back(&globals->ITC_F1F2()->zL_0_final); +v.at("F1F2").push_back(&globals->ITC_F1F2()->zL_1_final); +v.at("F1F2").push_back(&globals->ITC_F1F2()->zL_2_final); +v.at("F1F2").push_back(&globals->ITC_F1F2()->der_phiL_final); +v.at("F1F2").push_back(&globals->ITC_F1F2()->der_zL_final); + +v.at("F1F2").push_back(&globals->ITC_F1F2()->phiD_0_final); +v.at("F1F2").push_back(&globals->ITC_F1F2()->phiD_1_final); +v.at("F1F2").push_back(&globals->ITC_F1F2()->phiD_2_final); +v.at("F1F2").push_back(&globals->ITC_F1F2()->rD_0_final); +v.at("F1F2").push_back(&globals->ITC_F1F2()->rD_1_final); +v.at("F1F2").push_back(&globals->ITC_F1F2()->rD_2_final); +v.at("F1F2").push_back(&globals->ITC_F1F2()->der_phiD_final); +v.at("F1F2").push_back(&globals->ITC_F1F2()->der_rD_final); + +v.at("F1F2").push_back(&globals->ITC_F1F2()->valid_trackpar); + +v.at("F1F2").push_back(&globals->ITC_F1F2()->valid_phiL_0); +v.at("F1F2").push_back(&globals->ITC_F1F2()->valid_phiL_1); +v.at("F1F2").push_back(&globals->ITC_F1F2()->valid_phiL_2); + +v.at("F1F2").push_back(&globals->ITC_F1F2()->valid_zL_0); +v.at("F1F2").push_back(&globals->ITC_F1F2()->valid_zL_1); +v.at("F1F2").push_back(&globals->ITC_F1F2()->valid_zL_2); + +v.at("F1F2").push_back(&globals->ITC_F1F2()->valid_der_phiL); +v.at("F1F2").push_back(&globals->ITC_F1F2()->valid_der_zL); + +v.at("F1F2").push_back(&globals->ITC_F1F2()->valid_phiD_0); +v.at("F1F2").push_back(&globals->ITC_F1F2()->valid_phiD_1); +v.at("F1F2").push_back(&globals->ITC_F1F2()->valid_phiD_2); + +v.at("F1F2").push_back(&globals->ITC_F1F2()->valid_rD_0); +v.at("F1F2").push_back(&globals->ITC_F1F2()->valid_rD_1); +v.at("F1F2").push_back(&globals->ITC_F1F2()->valid_rD_2); + +v.at("F1F2").push_back(&globals->ITC_F1F2()->valid_der_phiD); +v.at("F1F2").push_back(&globals->ITC_F1F2()->valid_der_rD); +//////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////// +// B1B2 +//////////////////////////////////////////////////////////////////////////// +v["B1B2"]; + +v.at("B1B2").push_back(&globals->ITC_B1B2()->rinv_final); +v.at("B1B2").push_back(&globals->ITC_B1B2()->phi0_final); +v.at("B1B2").push_back(&globals->ITC_B1B2()->t_final); +v.at("B1B2").push_back(&globals->ITC_B1B2()->z0_final); + +v.at("B1B2").push_back(&globals->ITC_B1B2()->phiL_0_final); +v.at("B1B2").push_back(&globals->ITC_B1B2()->phiL_1_final); +v.at("B1B2").push_back(&globals->ITC_B1B2()->phiL_2_final); +v.at("B1B2").push_back(&globals->ITC_B1B2()->zL_0_final); +v.at("B1B2").push_back(&globals->ITC_B1B2()->zL_1_final); +v.at("B1B2").push_back(&globals->ITC_B1B2()->zL_2_final); +v.at("B1B2").push_back(&globals->ITC_B1B2()->der_phiL_final); +v.at("B1B2").push_back(&globals->ITC_B1B2()->der_zL_final); + +v.at("B1B2").push_back(&globals->ITC_B1B2()->phiD_0_final); +v.at("B1B2").push_back(&globals->ITC_B1B2()->phiD_1_final); +v.at("B1B2").push_back(&globals->ITC_B1B2()->phiD_2_final); +v.at("B1B2").push_back(&globals->ITC_B1B2()->rD_0_final); +v.at("B1B2").push_back(&globals->ITC_B1B2()->rD_1_final); +v.at("B1B2").push_back(&globals->ITC_B1B2()->rD_2_final); +v.at("B1B2").push_back(&globals->ITC_B1B2()->der_phiD_final); +v.at("B1B2").push_back(&globals->ITC_B1B2()->der_rD_final); + +v.at("B1B2").push_back(&globals->ITC_B1B2()->valid_trackpar); + +v.at("B1B2").push_back(&globals->ITC_B1B2()->valid_phiL_0); +v.at("B1B2").push_back(&globals->ITC_B1B2()->valid_phiL_1); +v.at("B1B2").push_back(&globals->ITC_B1B2()->valid_phiL_2); + +v.at("B1B2").push_back(&globals->ITC_B1B2()->valid_zL_0); +v.at("B1B2").push_back(&globals->ITC_B1B2()->valid_zL_1); +v.at("B1B2").push_back(&globals->ITC_B1B2()->valid_zL_2); + +v.at("B1B2").push_back(&globals->ITC_B1B2()->valid_der_phiL); +v.at("B1B2").push_back(&globals->ITC_B1B2()->valid_der_zL); + +v.at("B1B2").push_back(&globals->ITC_B1B2()->valid_phiD_0); +v.at("B1B2").push_back(&globals->ITC_B1B2()->valid_phiD_1); +v.at("B1B2").push_back(&globals->ITC_B1B2()->valid_phiD_2); + +v.at("B1B2").push_back(&globals->ITC_B1B2()->valid_rD_0); +v.at("B1B2").push_back(&globals->ITC_B1B2()->valid_rD_1); +v.at("B1B2").push_back(&globals->ITC_B1B2()->valid_rD_2); + +v.at("B1B2").push_back(&globals->ITC_B1B2()->valid_der_phiD); +v.at("B1B2").push_back(&globals->ITC_B1B2()->valid_der_rD); +//////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////// +// F3F4 +//////////////////////////////////////////////////////////////////////////// +v["F3F4"]; + +v.at("F3F4").push_back(&globals->ITC_F3F4()->rinv_final); +v.at("F3F4").push_back(&globals->ITC_F3F4()->phi0_final); +v.at("F3F4").push_back(&globals->ITC_F3F4()->t_final); +v.at("F3F4").push_back(&globals->ITC_F3F4()->z0_final); + +v.at("F3F4").push_back(&globals->ITC_F3F4()->phiL_0_final); +v.at("F3F4").push_back(&globals->ITC_F3F4()->phiL_1_final); +v.at("F3F4").push_back(&globals->ITC_F3F4()->phiL_2_final); +v.at("F3F4").push_back(&globals->ITC_F3F4()->zL_0_final); +v.at("F3F4").push_back(&globals->ITC_F3F4()->zL_1_final); +v.at("F3F4").push_back(&globals->ITC_F3F4()->zL_2_final); +v.at("F3F4").push_back(&globals->ITC_F3F4()->der_phiL_final); +v.at("F3F4").push_back(&globals->ITC_F3F4()->der_zL_final); + +v.at("F3F4").push_back(&globals->ITC_F3F4()->phiD_0_final); +v.at("F3F4").push_back(&globals->ITC_F3F4()->phiD_1_final); +v.at("F3F4").push_back(&globals->ITC_F3F4()->phiD_2_final); +v.at("F3F4").push_back(&globals->ITC_F3F4()->rD_0_final); +v.at("F3F4").push_back(&globals->ITC_F3F4()->rD_1_final); +v.at("F3F4").push_back(&globals->ITC_F3F4()->rD_2_final); +v.at("F3F4").push_back(&globals->ITC_F3F4()->der_phiD_final); +v.at("F3F4").push_back(&globals->ITC_F3F4()->der_rD_final); + +v.at("F3F4").push_back(&globals->ITC_F3F4()->valid_trackpar); + +v.at("F3F4").push_back(&globals->ITC_F3F4()->valid_phiL_0); +v.at("F3F4").push_back(&globals->ITC_F3F4()->valid_phiL_1); +v.at("F3F4").push_back(&globals->ITC_F3F4()->valid_phiL_2); + +v.at("F3F4").push_back(&globals->ITC_F3F4()->valid_zL_0); +v.at("F3F4").push_back(&globals->ITC_F3F4()->valid_zL_1); +v.at("F3F4").push_back(&globals->ITC_F3F4()->valid_zL_2); + +v.at("F3F4").push_back(&globals->ITC_F3F4()->valid_der_phiL); +v.at("F3F4").push_back(&globals->ITC_F3F4()->valid_der_zL); + +v.at("F3F4").push_back(&globals->ITC_F3F4()->valid_phiD_0); +v.at("F3F4").push_back(&globals->ITC_F3F4()->valid_phiD_1); +v.at("F3F4").push_back(&globals->ITC_F3F4()->valid_phiD_2); + +v.at("F3F4").push_back(&globals->ITC_F3F4()->valid_rD_0); +v.at("F3F4").push_back(&globals->ITC_F3F4()->valid_rD_1); +v.at("F3F4").push_back(&globals->ITC_F3F4()->valid_rD_2); + +v.at("F3F4").push_back(&globals->ITC_F3F4()->valid_der_phiD); +v.at("F3F4").push_back(&globals->ITC_F3F4()->valid_der_rD); +//////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////// +// B3B4 +//////////////////////////////////////////////////////////////////////////// +v["B3B4"]; + +v.at("B3B4").push_back(&globals->ITC_B3B4()->rinv_final); +v.at("B3B4").push_back(&globals->ITC_B3B4()->phi0_final); +v.at("B3B4").push_back(&globals->ITC_B3B4()->t_final); +v.at("B3B4").push_back(&globals->ITC_B3B4()->z0_final); + +v.at("B3B4").push_back(&globals->ITC_B3B4()->phiL_0_final); +v.at("B3B4").push_back(&globals->ITC_B3B4()->phiL_1_final); +v.at("B3B4").push_back(&globals->ITC_B3B4()->phiL_2_final); +v.at("B3B4").push_back(&globals->ITC_B3B4()->zL_0_final); +v.at("B3B4").push_back(&globals->ITC_B3B4()->zL_1_final); +v.at("B3B4").push_back(&globals->ITC_B3B4()->zL_2_final); +v.at("B3B4").push_back(&globals->ITC_B3B4()->der_phiL_final); +v.at("B3B4").push_back(&globals->ITC_B3B4()->der_zL_final); + +v.at("B3B4").push_back(&globals->ITC_B3B4()->phiD_0_final); +v.at("B3B4").push_back(&globals->ITC_B3B4()->phiD_1_final); +v.at("B3B4").push_back(&globals->ITC_B3B4()->phiD_2_final); +v.at("B3B4").push_back(&globals->ITC_B3B4()->rD_0_final); +v.at("B3B4").push_back(&globals->ITC_B3B4()->rD_1_final); +v.at("B3B4").push_back(&globals->ITC_B3B4()->rD_2_final); +v.at("B3B4").push_back(&globals->ITC_B3B4()->der_phiD_final); +v.at("B3B4").push_back(&globals->ITC_B3B4()->der_rD_final); + +v.at("B3B4").push_back(&globals->ITC_B3B4()->valid_trackpar); + +v.at("B3B4").push_back(&globals->ITC_B3B4()->valid_phiL_0); +v.at("B3B4").push_back(&globals->ITC_B3B4()->valid_phiL_1); +v.at("B3B4").push_back(&globals->ITC_B3B4()->valid_phiL_2); + +v.at("B3B4").push_back(&globals->ITC_B3B4()->valid_zL_0); +v.at("B3B4").push_back(&globals->ITC_B3B4()->valid_zL_1); +v.at("B3B4").push_back(&globals->ITC_B3B4()->valid_zL_2); + +v.at("B3B4").push_back(&globals->ITC_B3B4()->valid_der_phiL); +v.at("B3B4").push_back(&globals->ITC_B3B4()->valid_der_zL); + +v.at("B3B4").push_back(&globals->ITC_B3B4()->valid_phiD_0); +v.at("B3B4").push_back(&globals->ITC_B3B4()->valid_phiD_1); +v.at("B3B4").push_back(&globals->ITC_B3B4()->valid_phiD_2); + +v.at("B3B4").push_back(&globals->ITC_B3B4()->valid_rD_0); +v.at("B3B4").push_back(&globals->ITC_B3B4()->valid_rD_1); +v.at("B3B4").push_back(&globals->ITC_B3B4()->valid_rD_2); + +v.at("B3B4").push_back(&globals->ITC_B3B4()->valid_der_phiD); +v.at("B3B4").push_back(&globals->ITC_B3B4()->valid_der_rD); +//////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////// +// L1F1 +//////////////////////////////////////////////////////////////////////////// +v["L1F1"]; + +v.at("L1F1").push_back(&globals->ITC_L1F1()->rinv_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->phi0_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->t_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->z0_final); + +v.at("L1F1").push_back(&globals->ITC_L1F1()->phiL_0_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->phiL_1_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->phiL_2_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->zL_0_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->zL_1_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->zL_2_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->der_phiL_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->der_zL_final); + +v.at("L1F1").push_back(&globals->ITC_L1F1()->phiD_0_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->phiD_1_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->phiD_2_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->phiD_3_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->rD_0_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->rD_1_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->rD_2_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->rD_3_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->der_phiD_final); +v.at("L1F1").push_back(&globals->ITC_L1F1()->der_rD_final); + +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_trackpar); + +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_phiL_0); +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_phiL_1); +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_phiL_2); + +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_zL_0); +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_zL_1); +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_zL_2); + +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_der_phiL); +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_der_zL); + +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_phiD_0); +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_phiD_1); +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_phiD_2); +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_phiD_3); + +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_rD_0); +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_rD_1); +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_rD_2); +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_rD_3); + +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_der_phiD); +v.at("L1F1").push_back(&globals->ITC_L1F1()->valid_der_rD); +//////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////// +// L1B1 +//////////////////////////////////////////////////////////////////////////// +v["L1B1"]; + +v.at("L1B1").push_back(&globals->ITC_L1B1()->rinv_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->phi0_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->t_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->z0_final); + +v.at("L1B1").push_back(&globals->ITC_L1B1()->phiL_0_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->phiL_1_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->phiL_2_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->zL_0_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->zL_1_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->zL_2_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->der_phiL_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->der_zL_final); + +v.at("L1B1").push_back(&globals->ITC_L1B1()->phiD_0_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->phiD_1_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->phiD_2_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->phiD_3_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->rD_0_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->rD_1_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->rD_2_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->rD_3_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->der_phiD_final); +v.at("L1B1").push_back(&globals->ITC_L1B1()->der_rD_final); + +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_trackpar); + +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_phiL_0); +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_phiL_1); +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_phiL_2); + +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_zL_0); +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_zL_1); +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_zL_2); + +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_der_phiL); +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_der_zL); + +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_phiD_0); +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_phiD_1); +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_phiD_2); +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_phiD_3); + +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_rD_0); +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_rD_1); +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_rD_2); +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_rD_3); + +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_der_phiD); +v.at("L1B1").push_back(&globals->ITC_L1B1()->valid_der_rD); +//////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////// +// L2F1 +//////////////////////////////////////////////////////////////////////////// +v["L2F1"]; + +v.at("L2F1").push_back(&globals->ITC_L2F1()->rinv_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->phi0_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->t_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->z0_final); + +v.at("L2F1").push_back(&globals->ITC_L2F1()->phiL_0_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->phiL_1_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->phiL_2_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->zL_0_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->zL_1_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->zL_2_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->der_phiL_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->der_zL_final); + +v.at("L2F1").push_back(&globals->ITC_L2F1()->phiD_0_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->phiD_1_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->phiD_2_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->phiD_3_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->rD_0_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->rD_1_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->rD_2_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->rD_3_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->der_phiD_final); +v.at("L2F1").push_back(&globals->ITC_L2F1()->der_rD_final); + +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_trackpar); + +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_phiL_0); +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_phiL_1); +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_phiL_2); + +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_zL_0); +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_zL_1); +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_zL_2); + +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_der_phiL); +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_der_zL); + +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_phiD_0); +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_phiD_1); +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_phiD_2); +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_phiD_3); + +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_rD_0); +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_rD_1); +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_rD_2); +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_rD_3); + +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_der_phiD); +v.at("L2F1").push_back(&globals->ITC_L2F1()->valid_der_rD); +//////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////// +// L2B1 +//////////////////////////////////////////////////////////////////////////// +v["L2B1"]; + +v.at("L2B1").push_back(&globals->ITC_L2B1()->rinv_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->phi0_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->t_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->z0_final); + +v.at("L2B1").push_back(&globals->ITC_L2B1()->phiL_0_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->phiL_1_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->phiL_2_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->zL_0_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->zL_1_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->zL_2_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->der_phiL_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->der_zL_final); + +v.at("L2B1").push_back(&globals->ITC_L2B1()->phiD_0_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->phiD_1_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->phiD_2_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->phiD_3_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->rD_0_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->rD_1_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->rD_2_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->rD_3_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->der_phiD_final); +v.at("L2B1").push_back(&globals->ITC_L2B1()->der_rD_final); + +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_trackpar); + +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_phiL_0); +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_phiL_1); +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_phiL_2); + +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_zL_0); +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_zL_1); +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_zL_2); + +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_der_phiL); +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_der_zL); + +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_phiD_0); +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_phiD_1); +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_phiD_2); +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_phiD_3); + +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_rD_0); +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_rD_1); +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_rD_2); +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_rD_3); + +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_der_phiD); +v.at("L2B1").push_back(&globals->ITC_L2B1()->valid_der_rD); +//////////////////////////////////////////////////////////////////////////// + +for (const auto &calculator : v) { + const std::string &layer = calculator.first; + const std::vector v = calculator.second; + ofstream fv("TC_" + layer + (settings.writeVerilog() ? ".v" : ".cpp")); + + if (settings.writeVerilog()) + VarBase::design_print(v, fv, VarBase::verilog); + else + VarBase::design_print(v, fv, VarBase::hls); + fv.close(); +} diff --git a/L1Trigger/TrackFindingTracklet/test/WriteInvTables.icc b/L1Trigger/TrackFindingTracklet/test/WriteInvTables.icc new file mode 100644 index 0000000000000..6c1b3fcaf7ff4 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/test/WriteInvTables.icc @@ -0,0 +1,83 @@ +edm::LogVerbatim("Tracklet") << " Writing Inverse Tables"; + +ofstream finv; +void (*writeLUT)(const VarInv&, ofstream&) = NULL; +string extension = ""; +if (settings.writeInvTable()) { + writeLUT = [](const VarInv& x, ofstream& fs) -> void { return x.writeLUT(fs, VarBase::verilog); }; + extension = "h"; +} else { + writeLUT = [](const VarInv& x, ofstream& fs) -> void { return x.writeLUT(fs, VarBase::hls); }; + extension = "tab"; +} + +finv.open("TC_L1L2_drinv." + extension); +writeLUT(globals->ITC_L1L2()->drinv, finv); +finv.close(); +finv.open("TC_L1L2_invt." + extension); +writeLUT(globals->ITC_L1L2()->invt, finv); +finv.close(); +finv.open("TC_L3L4_drinv." + extension); +writeLUT(globals->ITC_L3L4()->drinv, finv); +finv.close(); +finv.open("TC_L3L4_invt." + extension); +writeLUT(globals->ITC_L3L4()->invt, finv); +finv.close(); +finv.open("TC_L5L6_drinv." + extension); +writeLUT(globals->ITC_L5L6()->drinv, finv); +finv.close(); +finv.open("TC_L5L6_invt." + extension); +writeLUT(globals->ITC_L5L6()->invt, finv); +finv.close(); + +finv.open("F1F2_drinv." + extension); +writeLUT(globals->ITC_F1F2()->drinv, finv); +finv.close(); +finv.open("F1F2_invt." + extension); +writeLUT(globals->ITC_F1F2()->invt, finv); +finv.close(); +finv.open("B1B2_drinv." + extension); +writeLUT(globals->ITC_B1B2()->drinv, finv); +finv.close(); +finv.open("B1B2_invt." + extension); +writeLUT(globals->ITC_B1B2()->invt, finv); +finv.close(); + +finv.open("F3F4_drinv." + extension); +writeLUT(globals->ITC_F3F4()->drinv, finv); +finv.close(); +finv.open("F3F4_invt." + extension); +writeLUT(globals->ITC_F3F4()->invt, finv); +finv.close(); +finv.open("B3B4_drinv." + extension); +writeLUT(globals->ITC_B3B4()->drinv, finv); +finv.close(); +finv.open("B3B4_invt." + extension); +writeLUT(globals->ITC_B3B4()->invt, finv); +finv.close(); + +finv.open("L1F1_drinv." + extension); +writeLUT(globals->ITC_L1F1()->drinv, finv); +finv.close(); +finv.open("L1F1_invt." + extension); +writeLUT(globals->ITC_L1F1()->invt, finv); +finv.close(); +finv.open("L1B1_drinv." + extension); +writeLUT(globals->ITC_L1B1()->drinv, finv); +finv.close(); +finv.open("L1B1_invt." + extension); +writeLUT(globals->ITC_L1B1()->invt, finv); +finv.close(); + +finv.open("L2F1_drinv." + extension); +writeLUT(globals->ITC_L2F1()->drinv, finv); +finv.close(); +finv.open("L2F1_invt." + extension); +writeLUT(globals->ITC_L2F1()->invt, finv); +finv.close(); +finv.open("L2B1_drinv." + extension); +writeLUT(globals->ITC_L2B1()->drinv, finv); +finv.close(); +finv.open("L2B1_invt." + extension); +writeLUT(globals->ITC_L2B1()->invt, finv); +finv.close(); diff --git a/L1Trigger/TrackFindingTracklet/test/fpga.cc b/L1Trigger/TrackFindingTracklet/test/fpga.cc new file mode 100644 index 0000000000000..4147fd6bd800f --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/test/fpga.cc @@ -0,0 +1,327 @@ +// ---------------------------------------------------------------- +// STANDALONE (non-CMSSW) producer for L1 tracking +// ---------------------------------------------------------------- +// ROOT includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "../interface/IMATH_TrackletCalculator.h" +#include "../interface/IMATH_TrackletCalculatorDisk.h" +#include "../interface/IMATH_TrackletCalculatorOverlap.h" + +#include "../interface/SLHCEvent.h" +#include "../interface/Track.h" +#include "../interface/Settings.h" +#include "../interface/TrackletEventProcessor.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "DataFormats/Math/interface/deltaPhi.h" + +#include +#include +#include + +//Uncomment if you want root output +//#define USEROOT + +// Include file to define ROOT-Tree +// -------------------------------- +#ifdef USEROOT +#include "FPGAEvent.h" +#endif +// -------------------------------- + +using namespace trklet; +using namespace std; + +int main(const int argc, const char **argv) { + trklet::Settings settings; + + // --------------------------------------------------------- + // these are options that are read from python configuration files for the CMSSW running, set manually for the standalone version + + settings.setDTCLinkFile("../data/calcNumDTCLinks.txt"); + settings.setModuleCablingFile("../data/modules_T5v3_27SP_nonant_tracklet.dat"); + settings.setDTCLinkLayerDiskFile("../data/dtclinklayerdisk.dat"); + settings.setFitPatternFile("../data/fitpattern.txt"); + settings.setProcessingModulesFile("../data/processingmodules_" + settings.geomext() + ".dat"); + settings.setMemoryModulesFile("../data/memorymodules_" + settings.geomext() + ".dat"); + settings.setWiresFile("../data/wires_" + settings.geomext() + ".dat"); + + edm::LogVerbatim("Tracklet") << "cabling DTC links : " << settings.DTCLinkFile(); + edm::LogVerbatim("Tracklet") << "module cabling : " << settings.moduleCablingFile(); + edm::LogVerbatim("Tracklet") << "DTC link layer disk : " << settings.DTCLinkLayerDiskFile(); + + edm::LogVerbatim("Tracklet") << "fit pattern : " << settings.fitPatternFile(); + edm::LogVerbatim("Tracklet") << "process modules : " << settings.processingModulesFile(); + edm::LogVerbatim("Tracklet") << "memory modules : " << settings.memoryModulesFile(); + edm::LogVerbatim("Tracklet") << "wires : " << settings.wiresFile(); + + // --------------------------------------------------------- + + TrackletEventProcessor eventProcessor; + eventProcessor.init(&settings); + + if (argc < 3) + edm::LogVerbatim("Tracklet") << "Need to specify the input ascii file and the number of events to run on!"; + + int nevents = atoi(argv[2]); + + ifstream infile; + istream *in = &cin; + if (strcmp(argv[1], "stdin")) { + infile.open(argv[1]); + in = &infile; + } + + ofstream outpars; + if (settings.writeMonitorData("Pars")) + outpars.open("trackpars.txt"); + + // --------------------------------------------------------- + // Open file to hold ROOT-Tree +#ifdef USEROOT + TFile *hfile = new TFile("myTest.root", "RECREATE", "Simple ROOT Ntuple"); + TTree *trackTree = new TTree("FPGAEvent", "L1Track Tree"); + FPGAEvent *fpgaEvent = new FPGAEvent; + fpgaEvent->reset(); + trackTree->Branch("Event", &fpgaEvent); +#endif + // --------------------------------------------------------- + + if (settings.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::out); + fout.close(); + } + + for (int eventnum = 0; eventnum < nevents && !in->eof(); eventnum++) { + SLHCEvent ev(*in); + + L1SimTrack simtrk; + + // ----------------------------------------------------------------- + // setup ROOT Tree and Add Monte Carlo tracks to the ROOT-Tree Event +#ifdef USEROOT + fpgaEvent->reset(); + fpgaEvent->nevt = eventnum; + for (int nst = 0; nst < ev.nsimtracks(); nst++) { + simtrk = ev.simtrack(nst); + FPGAEventMCTrack *mcTrack = new FPGAEventMCTrack( + simtrk.type(), simtrk.pt(), simtrk.eta(), simtrk.phi(), simtrk.vx(), simtrk.vy(), simtrk.vz()); + fpgaEvent->mcTracks.push_back(*mcTrack); + } +#endif + // ------------------------------------------------------------------ + + if (settings.writeMonitorData("Seeds")) { + ofstream fout("seeds.txt", ofstream::app); + fout << "======== Event " << eventnum << " ========" << endl; + for (unsigned nst = 0; nst < ev.nsimtracks(); nst++) { + const L1SimTrack &simtrk = ev.simtrack(nst); + fout << "SimTrk " << simtrk.pt() << " " << simtrk.eta() << " " << simtrk.phi() << " " << simtrk.d0() << " "; + + vector hitPattern; + for (int i = 0; i < ev.nstubs(); i++) { + const L1TStub &stub = ev.stub(i); + if (!stub.tpmatch(simtrk.trackid())) + continue; + if (stub.layer() < 999) { + switch (stub.layer()) { + case 0: + hitPattern.emplace_back("L1"); + break; + case 1: + hitPattern.emplace_back("L2"); + break; + case 2: + hitPattern.emplace_back("L3"); + break; + case 3: + hitPattern.emplace_back("L4"); + break; + case 4: + hitPattern.emplace_back("L5"); + break; + case 5: + hitPattern.emplace_back("L6"); + break; + default: + edm::LogVerbatim("Tracklet") << "Stub layer: " << stub.layer(); + assert(0); + } + } else { + string d = (stub.isPSmodule() ? "D" : "d"); + switch (abs(stub.disk())) { + case 1: + hitPattern.push_back(d + "1"); + break; + case 2: + hitPattern.push_back(d + "2"); + break; + case 3: + hitPattern.push_back(d + "3"); + break; + case 4: + hitPattern.push_back(d + "4"); + break; + case 5: + hitPattern.push_back(d + "5"); + break; + default: + edm::LogVerbatim("Tracklet") << "Stub disk: " << stub.disk(); + assert(0); + } + } + } + bool (*compare)(const string &, const string &) = [](const string &a, const string &b) -> bool { + if (a.at(0) == 'L' && b.at(0) == 'D') + return true; + else if (a.at(0) == 'D' && b.at(0) == 'L') + return false; + else + return a.at(1) < b.at(1); + }; + sort(hitPattern.begin(), hitPattern.end(), compare); + hitPattern.erase(unique(hitPattern.begin(), hitPattern.end()), hitPattern.end()); + for (const auto &stub : hitPattern) + fout << stub; + if (hitPattern.empty()) + fout << "XX"; + fout << endl; + } + fout.close(); + } + + edm::LogVerbatim("Tracklet") << "Process event: " << eventnum << " with " << ev.nstubs() << " stubs and " + << ev.nsimtracks() << " simtracks"; + + eventProcessor.event(ev); + + std::vector &tracks = eventProcessor.tracks(); + + // --------------------------------------------------------- + // Block for producing ROOT-Tree +#ifdef USEROOT +#include "FPGATree.icc" +#endif + // --------------------------------------------------------- + + if (settings.writeMonitorData("MatchEff")) { + static ofstream out("matcheff.txt"); + int nsim = 0; + for (unsigned int isimtrack = 0; isimtrack < ev.nsimtracks(); isimtrack++) { + L1SimTrack simtrack = ev.simtrack(isimtrack); + if (simtrack.pt() < 2.0) + continue; + if (fabs(simtrack.eta()) > 2.4) + continue; + if (fabs(simtrack.vz()) > 15.0) + continue; + if (hypot(simtrack.vx(), simtrack.vy()) > 0.1) + continue; + bool electron = (abs(simtrack.type()) == 11); + bool muon = (abs(simtrack.type()) == 13); + bool pion = (abs(simtrack.type()) == 211); + bool kaon = (abs(simtrack.type()) == 321); + bool proton = (abs(simtrack.type()) == 2212); + if (!(electron || muon || pion || kaon || proton)) + continue; + int nlayers = 0; + int ndisks = 0; + int simeventid = simtrack.eventid(); + int simtrackid = simtrack.trackid(); + ev.layersHit(simtrackid, nlayers, ndisks); + if (nlayers + ndisks < 4) + continue; + nsim++; + for (int seed = -1; seed < 8; seed++) { + bool eff = false; + bool effloose = false; + int itrackmatch = -1; + for (unsigned int itrack = 0; itrack < tracks.size(); itrack++) { + const std::vector &stubs = tracks[itrack]->stubs(); + if (seed == -1) { + if (tracks[itrack]->duplicate()) + continue; + } else { + if (seed != tracks[itrack]->seed()) + continue; + } + + unsigned int nmatch = 0; + for (auto stub : stubs) { + if (stub->tpmatch(simtrackid)) { + nmatch++; + } + } + + if (nmatch == stubs.size()) { + eff = true; + itrackmatch = itrack; + } + if (nmatch >= stubs.size() - 1) { + effloose = true; + if (!eff) + itrackmatch = itrack; + } + } + double dpt = -999; + double dphi = -999; + double deta = -999; + double dz0 = -999; + int q = 1; + if (simtrack.type() == 11 || simtrack.type() == 13 || simtrack.type() == -211 || simtrack.type() == -321 || + simtrack.type() == -2212) { + q = -1; + } + + if (itrackmatch >= 0) { + dpt = tracks[itrackmatch]->pt(settings) - q * simtrack.pt(); + dphi = tracks[itrackmatch]->phi0(settings) - simtrack.phi(); + if (dphi > M_PI) + dphi -= 2 * M_PI; + if (dphi < -M_PI) + dphi += 2 * M_PI; + deta = tracks[itrackmatch]->eta(settings) - simtrack.eta(); + dz0 = tracks[itrackmatch]->z0(settings) - simtrack.vz(); + } + + out << eventnum << " " << simeventid << " " << seed << " " << simtrackid << " " << simtrack.type() << " " + << simtrack.pt() << " " << simtrack.eta() << " " << simtrack.phi() << " " << simtrack.vx() << " " + << simtrack.vy() << " " << simtrack.vz() << " " << eff << " " << effloose << " " << dpt << " " << dphi + << " " << deta << " " << dz0 << endl; + } + } + } + + int ntrack = 0; + for (auto &track : tracks) { + if (settings.writeMonitorData("Pars")) { + outpars << track->duplicate() << " " << track->eta(settings) << " " << track->phi0(settings) << " " + << track->z0(settings) << " " << angle0to2pi::make0To2pi(track->phi0(settings)) / (2 * M_PI / N_SECTOR) + << " " << track->rinv(settings); + } + if (!track->duplicate()) { + ntrack++; + } + } + + edm::LogVerbatim("Tracklet") << "Number of found tracks : " << tracks.size() << " unique " << ntrack; + } + + eventProcessor.printSummary(); +} diff --git a/PhysicsTools/NanoAOD/python/nano_cff.py b/PhysicsTools/NanoAOD/python/nano_cff.py index 58c5a1f3e3845..dcfb273492b98 100644 --- a/PhysicsTools/NanoAOD/python/nano_cff.py +++ b/PhysicsTools/NanoAOD/python/nano_cff.py @@ -146,7 +146,7 @@ import RecoTauTag.RecoTau.tools.runTauIdMVA as tauIdConfig def nanoAOD_addTauIds(process): updatedTauName = "slimmedTausUpdated" - tauIdEmbedder = tauIdConfig.TauIDEmbedder(process, cms, debug = False, updatedTauName = updatedTauName, + tauIdEmbedder = tauIdConfig.TauIDEmbedder(process, debug = False, updatedTauName = updatedTauName, toKeep = [ "deepTau2017v2p1" ]) tauIdEmbedder.runTauID() process.patTauMVAIDsSeq.insert(process.patTauMVAIDsSeq.index(getattr(process, updatedTauName)), diff --git a/PhysicsTools/PatAlgos/python/producersLayer1/tauProducer_cfi.py b/PhysicsTools/PatAlgos/python/producersLayer1/tauProducer_cfi.py index 585e22b86a37e..a3ad88c7648ad 100644 --- a/PhysicsTools/PatAlgos/python/producersLayer1/tauProducer_cfi.py +++ b/PhysicsTools/PatAlgos/python/producersLayer1/tauProducer_cfi.py @@ -164,3 +164,4 @@ def containerID(pset, inputID, provCfgLabel, wps): ["againstElectronTightMVA6", "_Tight"], ["againstElectronVTightMVA6", "_VTight"] ]) +singleID(patTaus.tauIDSources, "hpsPFTauDiscriminationByDeadECALElectronRejection", "againstElectronDeadECAL") diff --git a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py index 3a13dd584b065..d4792ca7fe4dc 100644 --- a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py +++ b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py @@ -335,7 +335,7 @@ def miniAOD_customizeCommon(process): _noUpdatedTauName = 'slimmedTausNoDeepIDs' import RecoTauTag.RecoTau.tools.runTauIdMVA as tauIdConfig tauIdEmbedder = tauIdConfig.TauIDEmbedder( - process, cms, debug = False, + process, debug = False, updatedTauName = _updatedTauName, toKeep = ['deepTau2017v2p1'] ) diff --git a/PhysicsTools/PatAlgos/python/tools/tauTools.py b/PhysicsTools/PatAlgos/python/tools/tauTools.py index d63e5f1be200f..7beb431372102 100644 --- a/PhysicsTools/PatAlgos/python/tools/tauTools.py +++ b/PhysicsTools/PatAlgos/python/tools/tauTools.py @@ -154,6 +154,7 @@ def _switchToPFTau(process, ("againstElectronMediumMVA6", "DiscriminationByMVA6MediumElectronRejection"), ("againstElectronTightMVA6", "DiscriminationByMVA6TightElectronRejection"), ("againstElectronVTightMVA6", "DiscriminationByMVA6VTightElectronRejection"), + ("againstElectronDeadECAL", "DiscriminationByDeadECALElectronRejection"), ] # switch to PFTau collection produced for fixed dR = 0.07 signal cone size diff --git a/RecoJets/JetProducers/plugins/BoostedTauSeedsProducer.cc b/RecoJets/JetProducers/plugins/BoostedTauSeedsProducer.cc index 69503a88ab451..832c0ab5aac00 100644 --- a/RecoJets/JetProducers/plugins/BoostedTauSeedsProducer.cc +++ b/RecoJets/JetProducers/plugins/BoostedTauSeedsProducer.cc @@ -157,10 +157,7 @@ namespace { const reco::Jet& jet, const edm::Handle& pfCandidates, const JetToConstitMap::value_type& constitmap, - const reco::Jet::Constituents& jetConstituents, - double /*dRmatch*/, bool invert) { - //const double dRmatch2 = dRmatch*dRmatch; // comment out for now in case someone needs a dR-based search again auto const& collection_cand = (*pfCandidates); std::vector pfCandidates_exclJetConstituents; size_t numPFCandidates = pfCandidates->size(); @@ -256,10 +253,10 @@ void BoostedTauSeedsProducer::produce(edm::Event& evt, const edm::EventSetup& es edm::Ref subjetRef2(selectedSubjetRefProd, selectedSubjets->size() - 1); // find all PFCandidates that are not constituents of the **other** subjet - std::vector pfCandidatesNotInSubjet1 = getPFCandidates_exclJetConstituents( - *subjet1, pfCandidates, constitmap[2 * idx], subjetConstituents2, 1.e-4, false); - std::vector pfCandidatesNotInSubjet2 = getPFCandidates_exclJetConstituents( - *subjet2, pfCandidates, constitmap[2 * idx + 1], subjetConstituents1, 1.e-4, false); + std::vector pfCandidatesNotInSubjet1 = + getPFCandidates_exclJetConstituents(*subjet1, pfCandidates, constitmap[2 * idx + 1], false); + std::vector pfCandidatesNotInSubjet2 = + getPFCandidates_exclJetConstituents(*subjet2, pfCandidates, constitmap[2 * idx], false); if (verbosity_ >= 1) { std::cout << "#pfCandidatesNotInSubjet1 = " << pfCandidatesNotInSubjet1.size() << std::endl; std::cout << "#pfCandidatesNotInSubjet2 = " << pfCandidatesNotInSubjet2.size() << std::endl; diff --git a/RecoTauTag/Configuration/python/HPSPFTaus_cff.py b/RecoTauTag/Configuration/python/HPSPFTaus_cff.py index f5b5c66c46405..e4e48b362898d 100644 --- a/RecoTauTag/Configuration/python/HPSPFTaus_cff.py +++ b/RecoTauTag/Configuration/python/HPSPFTaus_cff.py @@ -13,7 +13,7 @@ from RecoTauTag.RecoTau.PFRecoTauDiscriminationByLeadingTrackFinding_cfi import * from RecoTauTag.RecoTau.PFRecoTauDiscriminationAgainstElectron_cfi import * from RecoTauTag.RecoTau.PFRecoTauDiscriminationAgainstElectronMVA6_cfi import * -from RecoTauTag.RecoTau.PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi import * +from RecoTauTag.RecoTau.pfRecoTauDiscriminationAgainstElectronDeadECAL_cfi import * from RecoTauTag.RecoTau.PFRecoTauDiscriminationAgainstMuon_cfi import * from RecoTauTag.RecoTau.pfRecoTauDiscriminationAgainstMuon2Container_cfi import * from RecoTauTag.RecoTau.PFRecoTauDiscriminationAgainstMuonMVA_cfi import * diff --git a/RecoTauTag/RecoTau/BuildFile.xml b/RecoTauTag/RecoTau/BuildFile.xml index 5a798e598d987..ee15b23a648ed 100644 --- a/RecoTauTag/RecoTau/BuildFile.xml +++ b/RecoTauTag/RecoTau/BuildFile.xml @@ -1,12 +1,17 @@ + + + + + diff --git a/RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h b/RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h new file mode 100644 index 0000000000000..d37bb1b73b5bd --- /dev/null +++ b/RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h @@ -0,0 +1,74 @@ +#ifndef RecoTauTag_RecoTau_AntiElectronDeadECAL_h +#define RecoTauTag_RecoTau_AntiElectronDeadECAL_h + +/** \class AntiElectronDeadECAL + * + * Flag tau candidates reconstructed near dead ECAL channels, + * in order to reduce e -> tau fakes not rejected by anti-e MVA discriminator + * + * The motivation for this flag is this presentation: + * https://indico.cern.ch/getFile.py/access?contribId=0&resId=0&materialId=slides&confId=177223 + * + * Code adapted from: + * RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc + * + * \authors Lauri Andreas Wendland, + * Christian Veelken + * + * + * + */ + +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Framework/interface/ESWatcher.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "RecoTauTag/RecoTau/interface/PositionAtECalEntranceComputer.h" + +#include +#include + +class EcalChannelStatusRcd; +class CaloGeometryRecord; +class IdealGeometryRecord; + +class AntiElectronDeadECAL { +public: + explicit AntiElectronDeadECAL(const edm::ParameterSet&); + ~AntiElectronDeadECAL(); + + void beginEvent(const edm::EventSetup&); + + bool operator()(const reco::Candidate* tau) const; + +private: + const unsigned minStatus_; + const double dR2_; + const bool extrapolateToECalEntrance_; + const int verbosity_; + + PositionAtECalEntranceComputer positionAtECalEntrance_; + + void updateBadTowers(const edm::EventSetup&); + + struct TowerInfo { + TowerInfo(uint32_t id, unsigned nBad, unsigned maxStatus, double eta, double phi) + : id_(id), nBad_(nBad), maxStatus_(maxStatus), eta_(eta), phi_(phi) {} + uint32_t id_; + unsigned nBad_; + unsigned maxStatus_; + double eta_; + double phi_; + }; + + std::vector badTowers_; + static const uint16_t statusMask_ = 0x1F; + + edm::ESWatcher channelStatusWatcher_; + edm::ESWatcher caloGeometryWatcher_; + edm::ESWatcher idealGeometryWatcher_; + + bool isFirstEvent_; +}; + +#endif // RecoTauTag_RecoTau_AntiElectronDeadECAL_h diff --git a/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h b/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h index 1283be084da1f..0a6473d62d6ad 100644 --- a/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h +++ b/RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h @@ -22,9 +22,8 @@ #include "CondFormats/EgammaObjects/interface/GBRForest.h" #include "DataFormats/PatCandidates/interface/Tau.h" #include "DataFormats/PatCandidates/interface/Electron.h" - -#include "CommonTools/BaseParticlePropagator/interface/BaseParticlePropagator.h" #include "DataFormats/PatCandidates/interface/PackedCandidate.h" +#include "RecoTauTag/RecoTau/interface/PositionAtECalEntranceComputer.h" #include "TMVA/Tools.h" #include "TMVA/Reader.h" @@ -125,7 +124,7 @@ class AntiElectronIDMVA6 { double MVAValue(const pat::Tau& theTau, const pat::Electron& theEle); // this function can be called for category 1 only !! double MVAValue(const pat::Tau& theTau); - // track extrapolation to ECAL entrance (used to re-calculate varibales that might not be available on miniAOD) + // track extrapolation to ECAL entrance (used to re-calculate variables that might not be available on miniAOD) bool atECalEntrance(const reco::Candidate* part, math::XYZPoint& pos); private: @@ -168,7 +167,8 @@ class AntiElectronIDMVA6 { std::vector inputFilesToDelete_; - double bField_; + PositionAtECalEntranceComputer positionAtECalEntrance_; + int verbosity_; }; diff --git a/RecoTauTag/RecoTau/interface/PositionAtECalEntranceComputer.h b/RecoTauTag/RecoTau/interface/PositionAtECalEntranceComputer.h new file mode 100644 index 0000000000000..0b167c2568549 --- /dev/null +++ b/RecoTauTag/RecoTau/interface/PositionAtECalEntranceComputer.h @@ -0,0 +1,33 @@ +#ifndef RecoTauTag_RecoTau_PositionAtECalEntranceComputer_h +#define RecoTauTag_RecoTau_PositionAtECalEntranceComputer_h + +/** \class PositionAtECalEntranceComputer + * + * Extrapolate particle (charged or neutral) to ECAL entrance, + * in order to compute the distance of the tau to ECAL cracks and/or dead ECAL channels + * + * \authors Fabio Colombo, + * Christian Veelken + * + * + * + */ + +#include "FWCore/Framework/interface/EventSetup.h" +#include "DataFormats/Candidate/interface/Candidate.h" + +class PositionAtECalEntranceComputer { +public: + PositionAtECalEntranceComputer(); + ~PositionAtECalEntranceComputer(); + + void beginEvent(const edm::EventSetup&); + + //To do: it seems to more practical to put this to the ES + reco::Candidate::Point operator()(const reco::Candidate* particle, bool& success) const; + +private: + double bField_z_; +}; + +#endif // RecoTauTag_RecoTau_PositionAtECalEntranceComputer_h diff --git a/RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h b/RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h index cdf527c5af624..521b2ac1f29f0 100644 --- a/RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h +++ b/RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h @@ -93,6 +93,10 @@ class TauDiscriminationProducerBase : public edm::stream::EDProducer<> { static void fillProducerDescriptions(edm::ParameterSetDescription& desc); + /// helper method to retrieve tau type name, e.g. to build correct cfi getter + //string (i.e. PFTau/PATTauProducer) + static std::string getTauTypeString(); + protected: //value given to taus that fail prediscriminants double prediscriminantFailValue_; @@ -125,13 +129,4 @@ typedef TauDiscriminationProducerBase PATTauDiscriminationProducerBase; -/// helper function retrieve the correct cfi getter string (ie PFTauProducer) -//for this tau type -template -std::string getProducerString() { - // this generic one shoudl never be called. - // these are specialized in TauDiscriminationProducerBase.cc - throw cms::Exception("TauDiscriminationProducerBase") - << "Unsupported TauType used. You must use either PFTau or PATTau."; -} #endif diff --git a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc b/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc deleted file mode 100644 index b7f7634c9c41d..0000000000000 --- a/RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstElectronDeadECAL.cc +++ /dev/null @@ -1,204 +0,0 @@ - -/** \class PFRecoTauDiscriminationAgainstElectronDeadECAL - * - * Flag tau candidates reconstructed near dead ECAL channels, - * in order to reduce e -> tau fakes not rejected by anti-e MVA discriminator - * - * The motivation for this flag is this presentation: - * https://indico.cern.ch/getFile.py/access?contribId=0&resId=0&materialId=slides&confId=177223 - * - * \authors Lauri Andreas Wendland, - * Christian Veelken - * - * - * - */ - -#include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h" -#include "FWCore/Framework/interface/ESHandle.h" -#include -#include - -#include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h" -#include "CondFormats/EcalObjects/interface/EcalChannelStatus.h" -#include "Geometry/Records/interface/CaloGeometryRecord.h" -#include "Geometry/CaloGeometry/interface/CaloGeometry.h" -#include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h" -#include "Geometry/Records/interface/IdealGeometryRecord.h" -#include "DataFormats/DetId/interface/DetId.h" -#include "DataFormats/EcalDetId/interface/EBDetId.h" -#include "DataFormats/EcalDetId/interface/EEDetId.h" -#include "DataFormats/Math/interface/deltaR.h" -#include "DataFormats/TauReco/interface/PFTauDiscriminator.h" - -#include - -using namespace reco; - -class PFRecoTauDiscriminationAgainstElectronDeadECAL : public PFTauDiscriminationProducerBase { -public: - explicit PFRecoTauDiscriminationAgainstElectronDeadECAL(const edm::ParameterSet& cfg) - : PFTauDiscriminationProducerBase(cfg), - moduleLabel_(cfg.getParameter("@module_label")), - isFirstEvent_(true) { - minStatus_ = cfg.getParameter("minStatus"); - dR_ = cfg.getParameter("dR"); - - verbosity_ = cfg.getParameter("verbosity"); - } - ~PFRecoTauDiscriminationAgainstElectronDeadECAL() override {} - - void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override { updateBadTowers(es); } - - double discriminate(const PFTauRef& pfTau) const override { - if (verbosity_) { - edm::LogPrint("PFTauAgainstEleDeadECAL") << ":"; - edm::LogPrint("PFTauAgainstEleDeadECAL") << " moduleLabel = " << moduleLabel_; - edm::LogPrint("PFTauAgainstEleDeadECAL") << "#badTowers = " << badTowers_.size(); - edm::LogPrint("PFTauAgainstEleDeadECAL") - << "tau: Pt = " << pfTau->pt() << ", eta = " << pfTau->eta() << ", phi = " << pfTau->phi(); - } - double discriminator = 1.; - for (std::vector::const_iterator badTower = badTowers_.begin(); badTower != badTowers_.end(); - ++badTower) { - if (deltaR(badTower->eta_, badTower->phi_, pfTau->eta(), pfTau->phi()) < dR_) { - if (verbosity_) { - edm::LogPrint("PFTauAgainstEleDeadECAL") - << " matches badTower: eta = " << badTower->eta_ << ", phi = " << badTower->phi_; - } - discriminator = 0.; - } - } - if (verbosity_) { - edm::LogPrint("PFTauAgainstEleDeadECAL") << "--> discriminator = " << discriminator; - } - return discriminator; - } - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - -private: - void updateBadTowers(const edm::EventSetup& es) { - // NOTE: modified version of SUSY CAF code - // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc - const uint32_t channelStatusId = es.get().cacheIdentifier(); - const uint32_t caloGeometryId = es.get().cacheIdentifier(); - const uint32_t idealGeometryId = es.get().cacheIdentifier(); - - if (!isFirstEvent_ && channelStatusId == channelStatusId_cache_ && caloGeometryId == caloGeometryId_cache_ && - idealGeometryId == idealGeometryId_cache_) - return; - - edm::ESHandle channelStatus; - es.get().get(channelStatus); - channelStatusId_cache_ = channelStatusId; - - edm::ESHandle caloGeometry; - es.get().get(caloGeometry); - caloGeometryId_cache_ = caloGeometryId; - - edm::ESHandle ttMap; - es.get().get(ttMap); - idealGeometryId_cache_ = idealGeometryId; - - std::map nBadCrystals, maxStatus; - std::map sumEta, sumPhi; - - loopXtals( - nBadCrystals, maxStatus, sumEta, sumPhi, channelStatus.product(), caloGeometry.product(), ttMap.product()); - loopXtals( - nBadCrystals, maxStatus, sumEta, sumPhi, channelStatus.product(), caloGeometry.product(), ttMap.product()); - - badTowers_.clear(); - for (std::map::const_iterator it = nBadCrystals.begin(); it != nBadCrystals.end(); ++it) { - uint32_t key = it->first; - badTowers_.push_back( - towerInfo(key, it->second, maxStatus[key], sumEta[key] / it->second, sumPhi[key] / it->second)); - } - - isFirstEvent_ = false; - } - - template - void loopXtals(std::map& nBadCrystals, - std::map& maxStatus, - std::map& sumEta, - std::map& sumPhi, - const EcalChannelStatus* channelStatus, - const CaloGeometry* caloGeometry, - const EcalTrigTowerConstituentsMap* ttMap) const { - // NOTE: modified version of SUSY CAF code - // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc - for (int i = 0; i < Id::kSizeForDenseIndexing; ++i) { - Id id = Id::unhashIndex(i); - if (id == Id(0)) - continue; - EcalChannelStatusMap::const_iterator it = channelStatus->getMap().find(id.rawId()); - unsigned status = (it == channelStatus->end()) ? 0 : (it->getStatusCode() & statusMask_); - if (status >= minStatus_) { - const GlobalPoint& point = caloGeometry->getPosition(id); - uint32_t key = ttMap->towerOf(id); - maxStatus[key] = TMath::Max(status, maxStatus[key]); - ++nBadCrystals[key]; - sumEta[key] += point.eta(); - sumPhi[key] += point.phi(); - } - } - } - - struct towerInfo { - towerInfo(uint32_t id, unsigned nBad, unsigned maxStatus, double eta, double phi) - : id_(id), nBad_(nBad), maxStatus_(maxStatus), eta_(eta), phi_(phi) {} - uint32_t id_; - unsigned nBad_; - unsigned maxStatus_; - double eta_; - double phi_; - }; - typedef ROOT::Math::LorentzVector > PolarLorentzVector; - - std::string moduleLabel_; - unsigned minStatus_; - double dR_; - - std::vector badTowers_; - static const uint16_t statusMask_ = 0x1F; - - uint32_t channelStatusId_cache_; - uint32_t caloGeometryId_cache_; - uint32_t idealGeometryId_cache_; - bool isFirstEvent_; - - int verbosity_; -}; - -void PFRecoTauDiscriminationAgainstElectronDeadECAL::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - // pfRecoTauDiscriminationAgainstElectronDeadECAL - edm::ParameterSetDescription desc; - desc.add("verbosity", 0); - { - edm::ParameterSetDescription pset_Prediscriminants; - pset_Prediscriminants.add("BooleanOperator", "and"); - { - edm::ParameterSetDescription psd1; - psd1.add("cut"); - psd1.add("Producer"); - pset_Prediscriminants.addOptional("leadTrack", psd1); - } - { - // encountered this at - // RecoTauTag/Configuration/python/HPSPFTaus_cff.py - edm::ParameterSetDescription psd1; - psd1.add("cut"); - psd1.add("Producer"); - pset_Prediscriminants.addOptional("decayMode", psd1); - } - desc.add("Prediscriminants", pset_Prediscriminants); - } - desc.add("dR", 0.08); - desc.add("PFTauProducer", edm::InputTag("pfTauProducer")); - desc.add("minStatus", 12); - descriptions.add("pfRecoTauDiscriminationAgainstElectronDeadECAL", desc); -} - -DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstElectronDeadECAL); diff --git a/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc new file mode 100644 index 0000000000000..578a232bb1d67 --- /dev/null +++ b/RecoTauTag/RecoTau/plugins/TauDiscriminationAgainstElectronDeadECAL.cc @@ -0,0 +1,87 @@ +/** \class TauDiscriminationAgainstElectronDeadECAL + * + * Template class for producing PFTau and PATTau discriminators which + * flag tau candidates reconstructed near dead ECAL channels, + * in order to reduce e -> tau fakes not rejected by anti-e MVA discriminator + * + * The motivation for this flag is this presentation: + * https://indico.cern.ch/getFile.py/access?contribId=0&resId=0&materialId=slides&confId=177223 + * + * \authors Lauri Andreas Wendland, + * Christian Veelken + * + * + * + */ +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h" +#include "RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h" + +template +class TauDiscriminationAgainstElectronDeadECAL : public TauDiscriminationProducerBase { +public: + typedef std::vector TauCollection; + typedef edm::Ref TauRef; + explicit TauDiscriminationAgainstElectronDeadECAL(const edm::ParameterSet& cfg) + : TauDiscriminationProducerBase::TauDiscriminationProducerBase(cfg), + moduleLabel_(cfg.getParameter("@module_label")), + verbosity_(cfg.getParameter("verbosity")), + antiElectronDeadECAL_(cfg) {} + ~TauDiscriminationAgainstElectronDeadECAL() override {} + + void beginEvent(const edm::Event& evt, const edm::EventSetup& es) override { antiElectronDeadECAL_.beginEvent(es); } + + double discriminate(const TauRef& tau) const override { + if (verbosity_) { + edm::LogPrint(this->getTauTypeString() + "AgainstEleDeadECAL") + << "<" + this->getTauTypeString() + "AgainstElectronDeadECAL::discriminate>:"; + edm::LogPrint(this->getTauTypeString() + "AgainstEleDeadECAL") << " moduleLabel = " << moduleLabel_; + edm::LogPrint(this->getTauTypeString() + "AgainstEleDeadECAL") + << " tau: Pt = " << tau->pt() << ", eta = " << tau->eta() << ", phi = " << tau->phi(); + } + double discriminator = 1.; + if (antiElectronDeadECAL_(tau.get())) { + discriminator = 0.; + } + if (verbosity_) { + edm::LogPrint(this->getTauTypeString() + "AgainstEleDeadECAL") << "--> discriminator = " << discriminator; + } + return discriminator; + } + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + std::string moduleLabel_; + int verbosity_; + + AntiElectronDeadECAL antiElectronDeadECAL_; +}; + +template +void TauDiscriminationAgainstElectronDeadECAL::fillDescriptions( + edm::ConfigurationDescriptions& descriptions) { + // {pfReco,pat}TauDiscriminationAgainstElectronDeadECAL + edm::ParameterSetDescription desc; + + desc.add("dR", 0.08); + desc.add("minStatus", 12); + desc.add("extrapolateToECalEntrance", true); + desc.add("verbosity", 0); + + TauDiscriminationProducerBase::fillProducerDescriptions( + desc); // inherited from the base-class + + descriptions.addWithDefaultLabel(desc); +} + +typedef TauDiscriminationAgainstElectronDeadECAL + PFRecoTauDiscriminationAgainstElectronDeadECAL; +typedef TauDiscriminationAgainstElectronDeadECAL + PATTauDiscriminationAgainstElectronDeadECAL; + +DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstElectronDeadECAL); +DEFINE_FWK_MODULE(PATTauDiscriminationAgainstElectronDeadECAL); diff --git a/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi.py b/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi.py deleted file mode 100644 index f891f28f305d2..0000000000000 --- a/RecoTauTag/RecoTau/python/PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi.py +++ /dev/null @@ -1,21 +0,0 @@ -import FWCore.ParameterSet.Config as cms -from RecoTauTag.RecoTau.TauDiscriminatorTools import requireLeadTrack - -pfRecoTauDiscriminationAgainstElectronDeadECAL = cms.EDProducer( - "PFRecoTauDiscriminationAgainstElectronDeadECAL", - - # tau collection to discriminate - PFTauProducer = cms.InputTag('pfTauProducer'), - - # Require leading pion ensures that: - # 1) these is at least one track above threshold (0.5 GeV) in the signal cone - # 2) a track OR a pi-zero in the signal cone has pT > 5 GeV - Prediscriminants = requireLeadTrack, - - # status flag indicating dead/masked ECAL crystals - minStatus = cms.uint32(12), - - # region around dead/masked ECAL crystals that is to be cut - dR = cms.double(0.08), - verbosity = cms.int32(0) -) diff --git a/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py b/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py index b2571e18a42ba..311ad4065215c 100644 --- a/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py +++ b/RecoTauTag/RecoTau/python/tools/runTauIdMVA.py @@ -1,4 +1,5 @@ from __future__ import print_function +import FWCore.ParameterSet.Config as cms from RecoTauTag.RecoTau.TauDiscriminatorTools import noPrediscriminants from RecoTauTag.RecoTau.PATTauDiscriminationByMVAIsolationRun2_cff import patDiscriminationByIsolationMVArun2v1raw, patDiscriminationByIsolationMVArun2v1 import os @@ -14,7 +15,7 @@ class TauIDEmbedder(object): "againstEle2018" ] - def __init__(self, process, cms, debug = False, + def __init__(self, process, debug = False, updatedTauName = "slimmedTausNewID", toKeep = ["deepTau2017v2p1"], tauIdDiscrMVA_trainings_run2_2017 = { 'tauIdMVAIsoDBoldDMwLT2017' : "tauIdMVAIsoDBoldDMwLT2017", }, @@ -34,7 +35,6 @@ def __init__(self, process, cms, debug = False, ): super(TauIDEmbedder, self).__init__() self.process = process - self.cms = cms self.debug = debug self.updatedTauName = updatedTauName self.process.load('RecoTauTag.Configuration.loadRecoTauTagMVAsFromPrepDB_cfi') @@ -90,8 +90,8 @@ def is_above_cmssw_version(klass, release=9, subversion=4, patch=0, debug = Fals if debug: print ("is_above_cmssw_version:", True) return True - def tauIDMVAinputs(module, wp): - return cms.PSet(inputTag = self.cms.InputTag(module), workingPointIndex = self.cms.int32(-1 if wp=="raw" else -2 if wp=="category" else getattr(self.process, module).workingPoints.index(wp))) + def tauIDMVAinputs(self, module, wp): + return cms.PSet(inputTag = cms.InputTag(module), workingPointIndex = cms.int32(-1 if wp=="raw" else -2 if wp=="category" else getattr(self.process, module).workingPoints.index(wp))) def loadMVA_WPs_run2_2017(self): if self.debug: print ("loadMVA_WPs_run2_2017: performed") @@ -99,34 +99,34 @@ def loadMVA_WPs_run2_2017(self): for training, gbrForestName in self.tauIdDiscrMVA_trainings_run2_2017.items(): self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append( - self.cms.PSet( - record = self.cms.string('GBRWrapperRcd'), - tag = self.cms.string("RecoTauTag_%s%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version)), - label = self.cms.untracked.string("RecoTauTag_%s%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version)) + cms.PSet( + record = cms.string('GBRWrapperRcd'), + tag = cms.string("RecoTauTag_%s%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version)), + label = cms.untracked.string("RecoTauTag_%s%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version)) ) ) for WP in self.tauIdDiscrMVA_WPs_run2_2017[training].keys(): self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append( - self.cms.PSet( - record = self.cms.string('PhysicsTGraphPayloadRcd'), - tag = self.cms.string("RecoTauTag_%s%s_WP%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version, WP)), - label = self.cms.untracked.string("RecoTauTag_%s%s_WP%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version, WP)) + cms.PSet( + record = cms.string('PhysicsTGraphPayloadRcd'), + tag = cms.string("RecoTauTag_%s%s_WP%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version, WP)), + label = cms.untracked.string("RecoTauTag_%s%s_WP%s" % (gbrForestName, self.tauIdDiscrMVA_2017_version, WP)) ) ) self.process.loadRecoTauTagMVAsFromPrepDB.toGet.append( - self.cms.PSet( - record = self.cms.string('PhysicsTFormulaPayloadRcd'), - tag = self.cms.string("RecoTauTag_%s%s_mvaOutput_normalization" % (gbrForestName, self.tauIdDiscrMVA_2017_version)), - label = self.cms.untracked.string("RecoTauTag_%s%s_mvaOutput_normalization" % (gbrForestName, self.tauIdDiscrMVA_2017_version)) + cms.PSet( + record = cms.string('PhysicsTFormulaPayloadRcd'), + tag = cms.string("RecoTauTag_%s%s_mvaOutput_normalization" % (gbrForestName, self.tauIdDiscrMVA_2017_version)), + label = cms.untracked.string("RecoTauTag_%s%s_mvaOutput_normalization" % (gbrForestName, self.tauIdDiscrMVA_2017_version)) ) ) def runTauID(self): - self.process.rerunMvaIsolationTask = self.cms.Task() - self.process.rerunMvaIsolationSequence = self.cms.Sequence() - tauIDSources = self.cms.PSet() + self.process.rerunMvaIsolationTask = cms.Task() + self.process.rerunMvaIsolationSequence = cms.Sequence() + tauIDSources = cms.PSet() # rerun the seq to obtain the 2017 nom training with 0.5 iso cone, old DM, ptph>1, trained on 2017MCv1 if "2017v1" in self.toKeep: @@ -151,25 +151,25 @@ def runTauID(self): self.loadMVA_WPs_run2_2017() self.process.rerunDiscriminationByIsolationOldDMMVArun2017v1raw = patDiscriminationByIsolationMVArun2v1raw.clone( - PATTauProducer = self.cms.InputTag('slimmedTaus'), + PATTauProducer = cms.InputTag('slimmedTaus'), Prediscriminants = noPrediscriminants, - loadMVAfromDB = self.cms.bool(True), - mvaName = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1"),#RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1 writeTauIdDiscrMVAs - mvaOpt = self.cms.string("DBoldDMwLTwGJ"), - verbosity = self.cms.int32(0) + loadMVAfromDB = cms.bool(True), + mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1"),#RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1 writeTauIdDiscrMVAs + mvaOpt = cms.string("DBoldDMwLTwGJ"), + verbosity = cms.int32(0) ) self.process.rerunDiscriminationByIsolationOldDMMVArun2017v1 = patDiscriminationByIsolationMVArun2v1.clone( - PATTauProducer = self.cms.InputTag('slimmedTaus'), + PATTauProducer = cms.InputTag('slimmedTaus'), Prediscriminants = noPrediscriminants, - toMultiplex = self.cms.InputTag('rerunDiscriminationByIsolationOldDMMVArun2017v1raw'), - loadMVAfromDB = self.cms.bool(True), - mvaOutput_normalization = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations - mapping = self.cms.VPSet( - self.cms.PSet( - category = self.cms.uint32(0), - cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1"), #writeTauIdDiscrWPs - variable = self.cms.string("pt"), + toMultiplex = cms.InputTag('rerunDiscriminationByIsolationOldDMMVArun2017v1raw'), + loadMVAfromDB = cms.bool(True), + mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations + mapping = cms.VPSet( + cms.PSet( + category = cms.uint32(0), + cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1"), #writeTauIdDiscrWPs + variable = cms.string("pt"), ) ), workingPoints = cms.vstring( @@ -183,21 +183,21 @@ def runTauID(self): ) ) - self.rerunIsolationOldDMMVArun2017v1Task = self.cms.Task( + self.rerunIsolationOldDMMVArun2017v1Task = cms.Task( self.process.rerunDiscriminationByIsolationOldDMMVArun2017v1raw, self.process.rerunDiscriminationByIsolationOldDMMVArun2017v1 ) self.process.rerunMvaIsolationTask.add(self.rerunIsolationOldDMMVArun2017v1Task) - self.process.rerunMvaIsolationSequence += self.cms.Sequence(self.rerunIsolationOldDMMVArun2017v1Task) + self.process.rerunMvaIsolationSequence += cms.Sequence(self.rerunIsolationOldDMMVArun2017v1Task) - tauIDSources.byIsolationMVArun2017v1DBoldDMwLTraw2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v1", "raw") - tauIDSources.byVVLooseIsolationMVArun2017v1DBoldDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v1", "_WPEff95") - tauIDSources.byVLooseIsolationMVArun2017v1DBoldDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v1", "_WPEff90") - tauIDSources.byLooseIsolationMVArun2017v1DBoldDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v1", "_WPEff80") - tauIDSources.byMediumIsolationMVArun2017v1DBoldDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v1", "_WPEff70") - tauIDSources.byTightIsolationMVArun2017v1DBoldDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v1", "_WPEff60") - tauIDSources.byVTightIsolationMVArun2017v1DBoldDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v1", "_WPEff50") - tauIDSources.byVVTightIsolationMVArun2017v1DBoldDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v1", "_WPEff40") + tauIDSources.byIsolationMVArun2017v1DBoldDMwLTraw2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v1", "raw") + tauIDSources.byVVLooseIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v1", "_WPEff95") + tauIDSources.byVLooseIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v1", "_WPEff90") + tauIDSources.byLooseIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v1", "_WPEff80") + tauIDSources.byMediumIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v1", "_WPEff70") + tauIDSources.byTightIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v1", "_WPEff60") + tauIDSources.byVTightIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v1", "_WPEff50") + tauIDSources.byVVTightIsolationMVArun2017v1DBoldDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v1", "_WPEff40") if "2017v2" in self.toKeep: @@ -222,25 +222,25 @@ def runTauID(self): self.loadMVA_WPs_run2_2017() self.process.rerunDiscriminationByIsolationOldDMMVArun2017v2raw = patDiscriminationByIsolationMVArun2v1raw.clone( - PATTauProducer = self.cms.InputTag('slimmedTaus'), + PATTauProducer = cms.InputTag('slimmedTaus'), Prediscriminants = noPrediscriminants, - loadMVAfromDB = self.cms.bool(True), - mvaName = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2"),#RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1 writeTauIdDiscrMVAs - mvaOpt = self.cms.string("DBoldDMwLTwGJ"), - verbosity = self.cms.int32(0) + loadMVAfromDB = cms.bool(True), + mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2"),#RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1 writeTauIdDiscrMVAs + mvaOpt = cms.string("DBoldDMwLTwGJ"), + verbosity = cms.int32(0) ) self.process.rerunDiscriminationByIsolationOldDMMVArun2017v2 = patDiscriminationByIsolationMVArun2v1.clone( - PATTauProducer = self.cms.InputTag('slimmedTaus'), + PATTauProducer = cms.InputTag('slimmedTaus'), Prediscriminants = noPrediscriminants, - toMultiplex = self.cms.InputTag('rerunDiscriminationByIsolationOldDMMVArun2017v2raw'), - loadMVAfromDB = self.cms.bool(True), - mvaOutput_normalization = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations - mapping = self.cms.VPSet( - self.cms.PSet( - category = self.cms.uint32(0), - cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2"), #writeTauIdDiscrWPs - variable = self.cms.string("pt"), + toMultiplex = cms.InputTag('rerunDiscriminationByIsolationOldDMMVArun2017v2raw'), + loadMVAfromDB = cms.bool(True), + mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations + mapping = cms.VPSet( + cms.PSet( + category = cms.uint32(0), + cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v2"), #writeTauIdDiscrWPs + variable = cms.string("pt"), ) ), workingPoints = cms.vstring( @@ -252,24 +252,24 @@ def runTauID(self): "_WPEff50", "_WPEff40" ), - verbosity = self.cms.int32(0) + verbosity = cms.int32(0) ) - self.rerunIsolationOldDMMVArun2017v2Task = self.cms.Task( + self.rerunIsolationOldDMMVArun2017v2Task = cms.Task( self.process.rerunDiscriminationByIsolationOldDMMVArun2017v2raw, self.process.rerunDiscriminationByIsolationOldDMMVArun2017v2 ) self.process.rerunMvaIsolationTask.add(self.rerunIsolationOldDMMVArun2017v2Task) - self.process.rerunMvaIsolationSequence += self.cms.Sequence(self.rerunIsolationOldDMMVArun2017v2Task) + self.process.rerunMvaIsolationSequence += cms.Sequence(self.rerunIsolationOldDMMVArun2017v2Task) - tauIDSources.byIsolationMVArun2017v2DBoldDMwLTraw2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v2", "raw") - tauIDSources.byVVLooseIsolationMVArun2017v2DBoldDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v2", "_WPEff95") - tauIDSources.byVLooseIsolationMVArun2017v2DBoldDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v2", "_WPEff90") - tauIDSources.byLooseIsolationMVArun2017v2DBoldDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v2", "_WPEff80") - tauIDSources.byMediumIsolationMVArun2017v2DBoldDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v2", "_WPEff70") - tauIDSources.byTightIsolationMVArun2017v2DBoldDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v2", "_WPEff60") - tauIDSources.byVTightIsolationMVArun2017v2DBoldDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v2", "_WPEff50") - tauIDSources.byVVTightIsolationMVArun2017v2DBoldDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v2", "_WPEff40") + tauIDSources.byIsolationMVArun2017v2DBoldDMwLTraw2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v2", "raw") + tauIDSources.byVVLooseIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v2", "_WPEff95") + tauIDSources.byVLooseIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v2", "_WPEff90") + tauIDSources.byLooseIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v2", "_WPEff80") + tauIDSources.byMediumIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v2", "_WPEff70") + tauIDSources.byTightIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v2", "_WPEff60") + tauIDSources.byVTightIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v2", "_WPEff50") + tauIDSources.byVVTightIsolationMVArun2017v2DBoldDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2017v2", "_WPEff40") if "newDM2017v2" in self.toKeep: self.tauIdDiscrMVA_2017_version = "v2" @@ -293,25 +293,25 @@ def runTauID(self): self.loadMVA_WPs_run2_2017() self.process.rerunDiscriminationByIsolationNewDMMVArun2017v2raw = patDiscriminationByIsolationMVArun2v1raw.clone( - PATTauProducer = self.cms.InputTag('slimmedTaus'), + PATTauProducer = cms.InputTag('slimmedTaus'), Prediscriminants = noPrediscriminants, - loadMVAfromDB = self.cms.bool(True), - mvaName = self.cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2"),#RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1 writeTauIdDiscrMVAs - mvaOpt = self.cms.string("DBnewDMwLTwGJ"), - verbosity = self.cms.int32(0) + loadMVAfromDB = cms.bool(True), + mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2"),#RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1 writeTauIdDiscrMVAs + mvaOpt = cms.string("DBnewDMwLTwGJ"), + verbosity = cms.int32(0) ) self.process.rerunDiscriminationByIsolationNewDMMVArun2017v2 = patDiscriminationByIsolationMVArun2v1.clone( - PATTauProducer = self.cms.InputTag('slimmedTaus'), + PATTauProducer = cms.InputTag('slimmedTaus'), Prediscriminants = noPrediscriminants, - toMultiplex = self.cms.InputTag('rerunDiscriminationByIsolationNewDMMVArun2017v2raw'), - loadMVAfromDB = self.cms.bool(True), - mvaOutput_normalization = self.cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations - mapping = self.cms.VPSet( - self.cms.PSet( - category = self.cms.uint32(0), - cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2"), #writeTauIdDiscrWPs - variable = self.cms.string("pt"), + toMultiplex = cms.InputTag('rerunDiscriminationByIsolationNewDMMVArun2017v2raw'), + loadMVAfromDB = cms.bool(True), + mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations + mapping = cms.VPSet( + cms.PSet( + category = cms.uint32(0), + cut = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2017v2"), #writeTauIdDiscrWPs + variable = cms.string("pt"), ) ), workingPoints = cms.vstring( @@ -323,24 +323,24 @@ def runTauID(self): "_WPEff50", "_WPEff40" ), - verbosity = self.cms.int32(0) + verbosity = cms.int32(0) ) - self.rerunIsolationNewDMMVArun2017v2Task = self.cms.Task( + self.rerunIsolationNewDMMVArun2017v2Task = cms.Task( self.process.rerunDiscriminationByIsolationNewDMMVArun2017v2raw, self.process.rerunDiscriminationByIsolationNewDMMVArun2017v2 ) self.process.rerunMvaIsolationTask.add(self.rerunIsolationNewDMMVArun2017v2Task) - self.process.rerunMvaIsolationSequence += self.cms.Sequence(self.rerunIsolationNewDMMVArun2017v2Task) + self.process.rerunMvaIsolationSequence += cms.Sequence(self.rerunIsolationNewDMMVArun2017v2Task) - tauIDSources.byIsolationMVArun2017v2DBnewDMwLTraw2017 = tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2017v2", "raw") - tauIDSources.byVVLooseIsolationMVArun2017v2DBnewDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2017v2", "_WPEff95") - tauIDSources.byVLooseIsolationMVArun2017v2DBnewDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2017v2", "_WPEff90") - tauIDSources.byLooseIsolationMVArun2017v2DBnewDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2017v2", "_WPEff80") - tauIDSources.byMediumIsolationMVArun2017v2DBnewDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2017v2", "_WPEff70") - tauIDSources.byTightIsolationMVArun2017v2DBnewDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2017v2", "_WPEff60") - tauIDSources.byVTightIsolationMVArun2017v2DBnewDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2017v2", "_WPEff50") - tauIDSources.byVVTightIsolationMVArun2017v2DBnewDMwLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2017v2", "_WPEff40") + tauIDSources.byIsolationMVArun2017v2DBnewDMwLTraw2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2017v2", "raw") + tauIDSources.byVVLooseIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2017v2", "_WPEff95") + tauIDSources.byVLooseIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2017v2", "_WPEff90") + tauIDSources.byLooseIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2017v2", "_WPEff80") + tauIDSources.byMediumIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2017v2", "_WPEff70") + tauIDSources.byTightIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2017v2", "_WPEff60") + tauIDSources.byVTightIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2017v2", "_WPEff50") + tauIDSources.byVVTightIsolationMVArun2017v2DBnewDMwLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2017v2", "_WPEff40") if "dR0p32017v2" in self.toKeep: self.tauIdDiscrMVA_2017_version = "v2" @@ -364,29 +364,29 @@ def runTauID(self): self.loadMVA_WPs_run2_2017() self.process.rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2raw = patDiscriminationByIsolationMVArun2v1raw.clone( - PATTauProducer = self.cms.InputTag('slimmedTaus'), + PATTauProducer = cms.InputTag('slimmedTaus'), Prediscriminants = noPrediscriminants, - loadMVAfromDB = self.cms.bool(True), - mvaName = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2"), - mvaOpt = self.cms.string("DBoldDMwLTwGJ"), - srcChargedIsoPtSum = self.cms.string('chargedIsoPtSumdR03'), - srcFootprintCorrection = self.cms.string('footprintCorrectiondR03'), - srcNeutralIsoPtSum = self.cms.string('neutralIsoPtSumdR03'), - srcPhotonPtSumOutsideSignalCone = self.cms.string('photonPtSumOutsideSignalConedR03'), - verbosity = self.cms.int32(0) + loadMVAfromDB = cms.bool(True), + mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2"), + mvaOpt = cms.string("DBoldDMwLTwGJ"), + srcChargedIsoPtSum = cms.string('chargedIsoPtSumdR03'), + srcFootprintCorrection = cms.string('footprintCorrectiondR03'), + srcNeutralIsoPtSum = cms.string('neutralIsoPtSumdR03'), + srcPhotonPtSumOutsideSignalCone = cms.string('photonPtSumOutsideSignalConedR03'), + verbosity = cms.int32(0) ) self.process.rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2= patDiscriminationByIsolationMVArun2v1.clone( - PATTauProducer = self.cms.InputTag('slimmedTaus'), + PATTauProducer = cms.InputTag('slimmedTaus'), Prediscriminants = noPrediscriminants, - toMultiplex = self.cms.InputTag('rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2raw'), - loadMVAfromDB = self.cms.bool(True), - mvaOutput_normalization = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations - mapping = self.cms.VPSet( - self.cms.PSet( - category = self.cms.uint32(0), - cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2"), #writeTauIdDiscrWPs - variable = self.cms.string("pt"), + toMultiplex = cms.InputTag('rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2raw'), + loadMVAfromDB = cms.bool(True), + mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations + mapping = cms.VPSet( + cms.PSet( + category = cms.uint32(0), + cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMdR0p3wLT2017v2"), #writeTauIdDiscrWPs + variable = cms.string("pt"), ) ), workingPoints = cms.vstring( @@ -398,47 +398,47 @@ def runTauID(self): "_WPEff50", "_WPEff40" ), - verbosity = self.cms.int32(0) + verbosity = cms.int32(0) ) - self.rerunIsolationOldDMdR0p3MVArun2017v2Task = self.cms.Task( + self.rerunIsolationOldDMdR0p3MVArun2017v2Task = cms.Task( self.process.rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2raw, self.process.rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2 ) self.process.rerunMvaIsolationTask.add(self.rerunIsolationOldDMdR0p3MVArun2017v2Task) - self.process.rerunMvaIsolationSequence += self.cms.Sequence(self.rerunIsolationOldDMdR0p3MVArun2017v2Task) + self.process.rerunMvaIsolationSequence += cms.Sequence(self.rerunIsolationOldDMdR0p3MVArun2017v2Task) - tauIDSources.byIsolationMVArun2017v2DBoldDMdR0p3wLTraw2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2", "raw") - tauIDSources.byVVLooseIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2", "_WPEff95") - tauIDSources.byVLooseIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2", "_WPEff90") - tauIDSources.byLooseIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2", "_WPEff80") - tauIDSources.byMediumIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2", "_WPEff70") - tauIDSources.byTightIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2", "_WPEff60") - tauIDSources.byVTightIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2", "_WPEff50") - tauIDSources.byVVTightIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2", "_WPEff40") + tauIDSources.byIsolationMVArun2017v2DBoldDMdR0p3wLTraw2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2", "raw") + tauIDSources.byVVLooseIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2", "_WPEff95") + tauIDSources.byVLooseIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2", "_WPEff90") + tauIDSources.byLooseIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2", "_WPEff80") + tauIDSources.byMediumIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2", "_WPEff70") + tauIDSources.byTightIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2", "_WPEff60") + tauIDSources.byVTightIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2", "_WPEff50") + tauIDSources.byVVTightIsolationMVArun2017v2DBoldDMdR0p3wLT2017 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMdR0p3MVArun2017v2", "_WPEff40") # 2016 training strategy(v2) - essentially the same as 2017 training strategy (v1), trained on 2016MC, old DM - currently not implemented in the tau sequence of any release # self.process.rerunDiscriminationByIsolationOldDMMVArun2v2raw = patDiscriminationByIsolationMVArun2v1raw.clone( - # PATTauProducer = self.cms.InputTag('slimmedTaus'), + # PATTauProducer = cms.InputTag('slimmedTaus'), # Prediscriminants = noPrediscriminants, - # loadMVAfromDB = self.cms.bool(True), - # mvaName = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v2"),#RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1 writeTauIdDiscrMVAs - # mvaOpt = self.cms.string("DBoldDMwLTwGJ"), - # verbosity = self.cms.int32(0) + # loadMVAfromDB = cms.bool(True), + # mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v2"),#RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1 writeTauIdDiscrMVAs + # mvaOpt = cms.string("DBoldDMwLTwGJ"), + # verbosity = cms.int32(0) # ) # # # self.process.rerunDiscriminationByIsolationOldDMMVArun2v2VLoose = patDiscriminationByIsolationMVArun2v1VLoose.clone( - # PATTauProducer = self.cms.InputTag('slimmedTaus'), + # PATTauProducer = cms.InputTag('slimmedTaus'), # Prediscriminants = noPrediscriminants, - # toMultiplex = self.cms.InputTag('rerunDiscriminationByIsolationOldDMMVArun2v2raw'), - # key = self.cms.InputTag('rerunDiscriminationByIsolationOldDMMVArun2v2raw:category'),#? - # loadMVAfromDB = self.cms.bool(True), - # mvaOutput_normalization = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations - # mapping = self.cms.VPSet( - # self.cms.PSet( - # category = self.cms.uint32(0), - # cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v2_WPEff90"), #writeTauIdDiscrWPs - # variable = self.cms.string("pt"), + # toMultiplex = cms.InputTag('rerunDiscriminationByIsolationOldDMMVArun2v2raw'), + # key = cms.InputTag('rerunDiscriminationByIsolationOldDMMVArun2v2raw:category'),#? + # loadMVAfromDB = cms.bool(True), + # mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v2_mvaOutput_normalization"), #writeTauIdDiscrMVAoutputNormalizations + # mapping = cms.VPSet( + # cms.PSet( + # category = cms.uint32(0), + # cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v2_WPEff90"), #writeTauIdDiscrWPs + # variable = cms.string("pt"), # ) # ) # ) @@ -446,25 +446,25 @@ def runTauID(self): # 2016 training strategy(v1), trained on 2016MC, old DM if "2016v1" in self.toKeep: self.process.rerunDiscriminationByIsolationOldDMMVArun2v1raw = patDiscriminationByIsolationMVArun2v1raw.clone( - PATTauProducer = self.cms.InputTag('slimmedTaus'), + PATTauProducer = cms.InputTag('slimmedTaus'), Prediscriminants = noPrediscriminants, - loadMVAfromDB = self.cms.bool(True), - mvaName = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1"), - mvaOpt = self.cms.string("DBoldDMwLT"), - verbosity = self.cms.int32(0) + loadMVAfromDB = cms.bool(True), + mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1"), + mvaOpt = cms.string("DBoldDMwLT"), + verbosity = cms.int32(0) ) self.process.rerunDiscriminationByIsolationOldDMMVArun2v1 = patDiscriminationByIsolationMVArun2v1.clone( - PATTauProducer = self.cms.InputTag('slimmedTaus'), + PATTauProducer = cms.InputTag('slimmedTaus'), Prediscriminants = noPrediscriminants, - toMultiplex = self.cms.InputTag('rerunDiscriminationByIsolationOldDMMVArun2v1raw'), - loadMVAfromDB = self.cms.bool(True), - mvaOutput_normalization = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1_mvaOutput_normalization"), - mapping = self.cms.VPSet( - self.cms.PSet( - category = self.cms.uint32(0), - cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1"), - variable = self.cms.string("pt"), + toMultiplex = cms.InputTag('rerunDiscriminationByIsolationOldDMMVArun2v1raw'), + loadMVAfromDB = cms.bool(True), + mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1_mvaOutput_normalization"), + mapping = cms.VPSet( + cms.PSet( + category = cms.uint32(0), + cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2016v1"), + variable = cms.string("pt"), ) ), workingPoints = cms.vstring( @@ -477,43 +477,43 @@ def runTauID(self): ) ) - self.rerunIsolationOldDMMVArun2016v1Task = self.cms.Task( + self.rerunIsolationOldDMMVArun2016v1Task = cms.Task( self.process.rerunDiscriminationByIsolationOldDMMVArun2v1raw, self.process.rerunDiscriminationByIsolationOldDMMVArun2v1 ) self.process.rerunMvaIsolationTask.add(self.rerunIsolationOldDMMVArun2016v1Task) - self.process.rerunMvaIsolationSequence += self.cms.Sequence(self.rerunIsolationOldDMMVArun2016v1Task) + self.process.rerunMvaIsolationSequence += cms.Sequence(self.rerunIsolationOldDMMVArun2016v1Task) - tauIDSources.byIsolationMVArun2v1DBoldDMwLTraw2016 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2v1", "raw") - tauIDSources.byVLooseIsolationMVArun2v1DBoldDMwLT2016 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2v1", "_WPEff90") - tauIDSources.byLooseIsolationMVArun2v1DBoldDMwLT2016 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2v1", "_WPEff80") - tauIDSources.byMediumIsolationMVArun2v1DBoldDMwLT2016 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2v1", "_WPEff70") - tauIDSources.byTightIsolationMVArun2v1DBoldDMwLT2016 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2v1", "_WPEff60") - tauIDSources.byVTightIsolationMVArun2v1DBoldDMwLT2016 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2v1", "_WPEff50") - tauIDSources.byVVTightIsolationMVArun2v1DBoldDMwLT2016 = tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2v1", "_WPEff40") + tauIDSources.byIsolationMVArun2v1DBoldDMwLTraw2016 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2v1", "raw") + tauIDSources.byVLooseIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2v1", "_WPEff90") + tauIDSources.byLooseIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2v1", "_WPEff80") + tauIDSources.byMediumIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2v1", "_WPEff70") + tauIDSources.byTightIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2v1", "_WPEff60") + tauIDSources.byVTightIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2v1", "_WPEff50") + tauIDSources.byVVTightIsolationMVArun2v1DBoldDMwLT2016 = self.tauIDMVAinputs("rerunDiscriminationByIsolationOldDMMVArun2v1", "_WPEff40") # 2016 training strategy(v1), trained on 2016MC, new DM if "newDM2016v1" in self.toKeep: self.process.rerunDiscriminationByIsolationNewDMMVArun2v1raw = patDiscriminationByIsolationMVArun2v1raw.clone( - PATTauProducer = self.cms.InputTag('slimmedTaus'), + PATTauProducer = cms.InputTag('slimmedTaus'), Prediscriminants = noPrediscriminants, - loadMVAfromDB = self.cms.bool(True), - mvaName = self.cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1"), - mvaOpt = self.cms.string("DBnewDMwLT"), - verbosity = self.cms.int32(0) + loadMVAfromDB = cms.bool(True), + mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1"), + mvaOpt = cms.string("DBnewDMwLT"), + verbosity = cms.int32(0) ) self.process.rerunDiscriminationByIsolationNewDMMVArun2v1 = patDiscriminationByIsolationMVArun2v1.clone( - PATTauProducer = self.cms.InputTag('slimmedTaus'), + PATTauProducer = cms.InputTag('slimmedTaus'), Prediscriminants = noPrediscriminants, - toMultiplex = self.cms.InputTag('rerunDiscriminationByIsolationNewDMMVArun2v1raw'), - loadMVAfromDB = self.cms.bool(True), - mvaOutput_normalization = self.cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1_mvaOutput_normalization"), - mapping = self.cms.VPSet( - self.cms.PSet( - category = self.cms.uint32(0), - cut = self.cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1_WPEff90"), - variable = self.cms.string("pt"), + toMultiplex = cms.InputTag('rerunDiscriminationByIsolationNewDMMVArun2v1raw'), + loadMVAfromDB = cms.bool(True), + mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1_mvaOutput_normalization"), + mapping = cms.VPSet( + cms.PSet( + category = cms.uint32(0), + cut = cms.string("RecoTauTag_tauIdMVAIsoDBnewDMwLT2016v1_WPEff90"), + variable = cms.string("pt"), ) ), workingPoints = cms.vstring( @@ -526,20 +526,20 @@ def runTauID(self): ) ) - self.rerunIsolationNewDMMVArun2016v1Task = self.cms.Task( + self.rerunIsolationNewDMMVArun2016v1Task = cms.Task( self.process.rerunDiscriminationByIsolationNewDMMVArun2v1raw, self.process.rerunDiscriminationByIsolationNewDMMVArun2v1 ) self.process.rerunMvaIsolationTask.add(self.rerunIsolationNewDMMVArun2016v1Task) - self.process.rerunMvaIsolationSequence += self.cms.Sequence(self.rerunIsolationNewDMMVArun2016v1Task) + self.process.rerunMvaIsolationSequence += cms.Sequence(self.rerunIsolationNewDMMVArun2016v1Task) - tauIDSources.byIsolationMVArun2v1DBnewDMwLTraw2016 = tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2v1", "raw") - tauIDSources.byVLooseIsolationMVArun2v1DBnewDMwLT2016 = tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2v1", "_WPEff90") - tauIDSources.byLooseIsolationMVArun2v1DBnewDMwLT2016 = tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2v1", "_WPEff80") - tauIDSources.byMediumIsolationMVArun2v1DBnewDMwLT2016 = tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2v1", "_WPEff70") - tauIDSources.byTightIsolationMVArun2v1DBnewDMwLT2016 = tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2v1", "_WPEff60") - tauIDSources.byVTightIsolationMVArun2v1DBnewDMwLT2016 = tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2v1", "_WPEff50") - tauIDSources.byVVTightIsolationMVArun2v1DBnewDMwLT2016 = tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2v1", "_WPEff40") + tauIDSources.byIsolationMVArun2v1DBnewDMwLTraw2016 = self.tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2v1", "raw") + tauIDSources.byVLooseIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2v1", "_WPEff90") + tauIDSources.byLooseIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2v1", "_WPEff80") + tauIDSources.byMediumIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2v1", "_WPEff70") + tauIDSources.byTightIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2v1", "_WPEff60") + tauIDSources.byVTightIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2v1", "_WPEff50") + tauIDSources.byVVTightIsolationMVArun2v1DBnewDMwLT2016 = self.tauIDMVAinputs("rerunDiscriminationByIsolationNewDMMVArun2v1", "_WPEff40") if "deepTau2017v1" in self.toKeep: if self.debug: print ("Adding DeepTau IDs") @@ -578,18 +578,18 @@ def runTauID(self): } } file_names = ['RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v1_20L1024N_quantized.pb'] - self.process.deepTau2017v1 = self.cms.EDProducer("DeepTauId", - electrons = self.cms.InputTag('slimmedElectrons'), - muons = self.cms.InputTag('slimmedMuons'), - taus = self.cms.InputTag('slimmedTaus'), - pfcands = self.cms.InputTag('packedPFCandidates'), - vertices = self.cms.InputTag('offlineSlimmedPrimaryVertices'), - rho = self.cms.InputTag('fixedGridRhoAll'), - graph_file = self.cms.vstring(file_names), - mem_mapped = self.cms.bool(False), - version = self.cms.uint32(self.getDeepTauVersion(file_names[0])[1]), - debug_level = self.cms.int32(0), - disable_dxy_pca = self.cms.bool(False) + self.process.deepTau2017v1 = cms.EDProducer("DeepTauId", + electrons = cms.InputTag('slimmedElectrons'), + muons = cms.InputTag('slimmedMuons'), + taus = cms.InputTag('slimmedTaus'), + pfcands = cms.InputTag('packedPFCandidates'), + vertices = cms.InputTag('offlineSlimmedPrimaryVertices'), + rho = cms.InputTag('fixedGridRhoAll'), + graph_file = cms.vstring(file_names), + mem_mapped = cms.bool(False), + version = cms.uint32(self.getDeepTauVersion(file_names[0])[1]), + debug_level = cms.int32(0), + disable_dxy_pca = cms.bool(False) ) self.processDeepProducer('deepTau2017v1', tauIDSources, workingPoints_) @@ -634,18 +634,18 @@ def runTauID(self): 'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_inner.pb', 'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_outer.pb', ] - self.process.deepTau2017v2 = self.cms.EDProducer("DeepTauId", - electrons = self.cms.InputTag('slimmedElectrons'), - muons = self.cms.InputTag('slimmedMuons'), - taus = self.cms.InputTag('slimmedTaus'), - pfcands = self.cms.InputTag('packedPFCandidates'), - vertices = self.cms.InputTag('offlineSlimmedPrimaryVertices'), - rho = self.cms.InputTag('fixedGridRhoAll'), - graph_file = self.cms.vstring(file_names), - mem_mapped = self.cms.bool(False), - version = self.cms.uint32(self.getDeepTauVersion(file_names[0])[1]), - debug_level = self.cms.int32(0), - disable_dxy_pca = self.cms.bool(False) + self.process.deepTau2017v2 = cms.EDProducer("DeepTauId", + electrons = cms.InputTag('slimmedElectrons'), + muons = cms.InputTag('slimmedMuons'), + taus = cms.InputTag('slimmedTaus'), + pfcands = cms.InputTag('packedPFCandidates'), + vertices = cms.InputTag('offlineSlimmedPrimaryVertices'), + rho = cms.InputTag('fixedGridRhoAll'), + graph_file = cms.vstring(file_names), + mem_mapped = cms.bool(False), + version = cms.uint32(self.getDeepTauVersion(file_names[0])[1]), + debug_level = cms.int32(0), + disable_dxy_pca = cms.bool(False) ) self.processDeepProducer('deepTau2017v2', tauIDSources, workingPoints_) @@ -690,18 +690,18 @@ def runTauID(self): 'inner:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_inner.pb', 'outer:RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6_outer.pb', ] - self.process.deepTau2017v2p1 = self.cms.EDProducer("DeepTauId", - electrons = self.cms.InputTag('slimmedElectrons'), - muons = self.cms.InputTag('slimmedMuons'), - taus = self.cms.InputTag('slimmedTaus'), - pfcands = self.cms.InputTag('packedPFCandidates'), - vertices = self.cms.InputTag('offlineSlimmedPrimaryVertices'), - rho = self.cms.InputTag('fixedGridRhoAll'), - graph_file = self.cms.vstring(file_names), - mem_mapped = self.cms.bool(False), - version = self.cms.uint32(self.getDeepTauVersion(file_names[0])[1]), - debug_level = self.cms.int32(0), - disable_dxy_pca = self.cms.bool(True) + self.process.deepTau2017v2p1 = cms.EDProducer("DeepTauId", + electrons = cms.InputTag('slimmedElectrons'), + muons = cms.InputTag('slimmedMuons'), + taus = cms.InputTag('slimmedTaus'), + pfcands = cms.InputTag('packedPFCandidates'), + vertices = cms.InputTag('offlineSlimmedPrimaryVertices'), + rho = cms.InputTag('fixedGridRhoAll'), + graph_file = cms.vstring(file_names), + mem_mapped = cms.bool(False), + version = cms.uint32(self.getDeepTauVersion(file_names[0])[1]), + debug_level = cms.int32(0), + disable_dxy_pca = cms.bool(True) ) self.processDeepProducer('deepTau2017v2p1', tauIDSources, workingPoints_) @@ -727,13 +727,13 @@ def runTauID(self): } } file_names = [ 'RecoTauTag/TrainingFiles/data/DPFTauId/DPFIsolation_2017v0_quantized.pb' ] - self.process.dpfTau2016v0 = self.cms.EDProducer("DPFIsolation", - pfcands = self.cms.InputTag('packedPFCandidates'), - taus = self.cms.InputTag('slimmedTaus'), - vertices = self.cms.InputTag('offlineSlimmedPrimaryVertices'), - graph_file = self.cms.vstring(file_names), - version = self.cms.uint32(self.getDpfTauVersion(file_names[0])), - mem_mapped = self.cms.bool(False) + self.process.dpfTau2016v0 = cms.EDProducer("DPFIsolation", + pfcands = cms.InputTag('packedPFCandidates'), + taus = cms.InputTag('slimmedTaus'), + vertices = cms.InputTag('offlineSlimmedPrimaryVertices'), + graph_file = cms.vstring(file_names), + version = cms.uint32(self.getDpfTauVersion(file_names[0])), + mem_mapped = cms.bool(False) ) self.processDeepProducer('dpfTau2016v0', tauIDSources, workingPoints_) @@ -752,13 +752,13 @@ def runTauID(self): } file_names = [ 'RecoTauTag/TrainingFiles/data/DPFTauId/DPFIsolation_2017v1_quantized.pb' ] - self.process.dpfTau2016v1 = self.cms.EDProducer("DPFIsolation", - pfcands = self.cms.InputTag('packedPFCandidates'), - taus = self.cms.InputTag('slimmedTaus'), - vertices = self.cms.InputTag('offlineSlimmedPrimaryVertices'), - graph_file = self.cms.vstring(file_names), - version = self.cms.uint32(self.getDpfTauVersion(file_names[0])), - mem_mapped = self.cms.bool(False) + self.process.dpfTau2016v1 = cms.EDProducer("DPFIsolation", + pfcands = cms.InputTag('packedPFCandidates'), + taus = cms.InputTag('slimmedTaus'), + vertices = cms.InputTag('offlineSlimmedPrimaryVertices'), + graph_file = cms.vstring(file_names), + version = cms.uint32(self.getDpfTauVersion(file_names[0])), + mem_mapped = cms.bool(False) ) self.processDeepProducer('dpfTau2016v1', tauIDSources, workingPoints_) @@ -773,7 +773,7 @@ def runTauID(self): from RecoTauTag.RecoTau.PATTauDiscriminationAgainstElectronMVA6_cfi import patTauDiscriminationAgainstElectronMVA6 self.process.patTauDiscriminationByElectronRejectionMVA62018Raw = patTauDiscriminationAgainstElectronMVA6.clone( Prediscriminants = noPrediscriminants, #already selected for MiniAOD - vetoEcalCracks = self.cms.bool(False), #keep taus in EB-EE cracks + vetoEcalCracks = cms.bool(False), #keep taus in EB-EE cracks mvaName_NoEleMatch_wGwoGSF_BL = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_BL', mvaName_NoEleMatch_wGwoGSF_EC = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_EC', mvaName_NoEleMatch_woGwoGSF_BL = 'RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_BL', @@ -785,50 +785,50 @@ def runTauID(self): ) ## WPs from RecoTauTag.RecoTau.PATTauDiscriminantCutMultiplexer_cfi import patTauDiscriminantCutMultiplexer - self.process.patTauDiscriminationByVLooseElectronRejectionMVA62018 = patTauDiscriminantCutMultiplexer.clone( + self.process.patTauDiscriminationByElectronRejectionMVA62018 = patTauDiscriminantCutMultiplexer.clone( PATTauProducer = self.process.patTauDiscriminationByElectronRejectionMVA62018Raw.PATTauProducer, Prediscriminants = self.process.patTauDiscriminationByElectronRejectionMVA62018Raw.Prediscriminants, - toMultiplex = self.cms.InputTag("patTauDiscriminationByElectronRejectionMVA62018Raw"), - mapping = self.cms.VPSet( - self.cms.PSet( - category = self.cms.uint32(0), - cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_BL'), - variable = self.cms.string('pt') + toMultiplex = cms.InputTag("patTauDiscriminationByElectronRejectionMVA62018Raw"), + mapping = cms.VPSet( + cms.PSet( + category = cms.uint32(0), + cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_BL'), + variable = cms.string('pt') ), - self.cms.PSet( - category = self.cms.uint32(2), - cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_BL'), - variable = self.cms.string('pt') + cms.PSet( + category = cms.uint32(2), + cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_BL'), + variable = cms.string('pt') ), - self.cms.PSet( - category = self.cms.uint32(5), - cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_woGwGSF_BL'), - variable = self.cms.string('pt') + cms.PSet( + category = cms.uint32(5), + cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_woGwGSF_BL'), + variable = cms.string('pt') ), - self.cms.PSet( - category = self.cms.uint32(7), - cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_wGwGSF_BL'), - variable = self.cms.string('pt') + cms.PSet( + category = cms.uint32(7), + cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_wGwGSF_BL'), + variable = cms.string('pt') ), - self.cms.PSet( - category = self.cms.uint32(8), - cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_EC'), - variable = self.cms.string('pt') + cms.PSet( + category = cms.uint32(8), + cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_woGwoGSF_EC'), + variable = cms.string('pt') ), - self.cms.PSet( - category = self.cms.uint32(10), - cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_EC'), - variable = self.cms.string('pt') + cms.PSet( + category = cms.uint32(10), + cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_NoEleMatch_wGwoGSF_EC'), + variable = cms.string('pt') ), - self.cms.PSet( - category = self.cms.uint32(13), - cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_woGwGSF_EC'), - variable = self.cms.string('pt') + cms.PSet( + category = cms.uint32(13), + cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_woGwGSF_EC'), + variable = cms.string('pt') ), - self.cms.PSet( - category = self.cms.uint32(15), - cut = self.cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_wGwGSF_EC'), - variable = self.cms.string('pt') + cms.PSet( + category = cms.uint32(15), + cut = cms.string('RecoTauTag_antiElectron'+antiElectronDiscrMVA6_version+'_gbr_wGwGSF_EC'), + variable = cms.string('pt') ) ), workingPoints = cms.vstring( @@ -840,24 +840,24 @@ def runTauID(self): ) ) ### Put all new anti-e discrminats to a sequence - self.process.patTauDiscriminationByElectronRejectionMVA62018Task = self.cms.Task( + self.process.patTauDiscriminationByElectronRejectionMVA62018Task = cms.Task( self.process.patTauDiscriminationByElectronRejectionMVA62018Raw, self.process.patTauDiscriminationByElectronRejectionMVA62018 ) - self.process.patTauDiscriminationByElectronRejectionMVA62018Seq = self.cms.Sequence(self.process.patTauDiscriminationByElectronRejectionMVA62018Task) + self.process.patTauDiscriminationByElectronRejectionMVA62018Seq = cms.Sequence(self.process.patTauDiscriminationByElectronRejectionMVA62018Task) self.process.rerunMvaIsolationTask.add(self.process.patTauDiscriminationByElectronRejectionMVA62018Task) self.process.rerunMvaIsolationSequence += self.process.patTauDiscriminationByElectronRejectionMVA62018Seq - _againstElectronTauIDSources = self.cms.PSet( - againstElectronMVA6Raw2018 = tauIDMVAinputs("patTauDiscriminationByElectronRejectionMVA62018", "raw"), - againstElectronMVA6category2018 = tauIDMVAinputs("patTauDiscriminationByElectronRejectionMVA62018", "category"), - againstElectronVLooseMVA62018 = tauIDMVAinputs("patTauDiscriminationByElectronRejectionMVA62018", "_WPeff98"), - againstElectronLooseMVA62018 = tauIDMVAinputs("patTauDiscriminationByElectronRejectionMVA62018", "_WPeff90"), - againstElectronMediumMVA62018 = tauIDMVAinputs("patTauDiscriminationByElectronRejectionMVA62018", "_WPeff80"), - againstElectronTightMVA62018 = tauIDMVAinputs("patTauDiscriminationByElectronRejectionMVA62018", "_WPeff70"), - againstElectronVTightMVA62018 = tauIDMVAinputs("patTauDiscriminationByElectronRejectionMVA62018", "_WPeff60") + _againstElectronTauIDSources = cms.PSet( + againstElectronMVA6Raw2018 = self.tauIDMVAinputs("patTauDiscriminationByElectronRejectionMVA62018", "raw"), + againstElectronMVA6category2018 = self.tauIDMVAinputs("patTauDiscriminationByElectronRejectionMVA62018", "category"), + againstElectronVLooseMVA62018 = self.tauIDMVAinputs("patTauDiscriminationByElectronRejectionMVA62018", "_WPeff98"), + againstElectronLooseMVA62018 = self.tauIDMVAinputs("patTauDiscriminationByElectronRejectionMVA62018", "_WPeff90"), + againstElectronMediumMVA62018 = self.tauIDMVAinputs("patTauDiscriminationByElectronRejectionMVA62018", "_WPeff80"), + againstElectronTightMVA62018 = self.tauIDMVAinputs("patTauDiscriminationByElectronRejectionMVA62018", "_WPeff70"), + againstElectronVTightMVA62018 = self.tauIDMVAinputs("patTauDiscriminationByElectronRejectionMVA62018", "_WPeff60") ) - _tauIDSourcesWithAgainistEle = self.cms.PSet( + _tauIDSourcesWithAgainistEle = cms.PSet( tauIDSources.clone(), _againstElectronTauIDSources ) @@ -866,13 +866,13 @@ def runTauID(self): ## if self.debug: print('Embedding new TauIDs into \"'+self.updatedTauName+'\"') if not hasattr(self.process, self.updatedTauName): - embedID = self.cms.EDProducer("PATTauIDEmbedder", - src = self.cms.InputTag('slimmedTaus'), + embedID = cms.EDProducer("PATTauIDEmbedder", + src = cms.InputTag('slimmedTaus'), tauIDSources = tauIDSources ) setattr(self.process, self.updatedTauName, embedID) else: #assume same type - tauIDSources = self.cms.PSet( + tauIDSources = cms.PSet( getattr(self.process, self.updatedTauName).tauIDSources, tauIDSources) getattr(self.process, self.updatedTauName).tauIDSources = tauIDSources @@ -881,16 +881,16 @@ def runTauID(self): def processDeepProducer(self, producer_name, tauIDSources, workingPoints_): for target,points in six.iteritems(workingPoints_): setattr(tauIDSources, 'by{}VS{}raw'.format(producer_name[0].upper()+producer_name[1:], target), - self.cms.PSet(inputTag = self.cms.InputTag(producer_name, 'VS{}'.format(target)), workingPointIndex = self.cms.int32(-1))) + cms.PSet(inputTag = cms.InputTag(producer_name, 'VS{}'.format(target)), workingPointIndex = cms.int32(-1))) cut_expressions = [] for index, (point,cut) in enumerate(six.iteritems(points)): cut_expressions.append(str(cut)) setattr(tauIDSources, 'by{}{}VS{}'.format(point, producer_name[0].upper()+producer_name[1:], target), - self.cms.PSet(inputTag = self.cms.InputTag(producer_name, 'VS{}'.format(target)), workingPointIndex = self.cms.int32(index))) + cms.PSet(inputTag = cms.InputTag(producer_name, 'VS{}'.format(target)), workingPointIndex = cms.int32(index))) - setattr(getattr(self.process, producer_name), 'VS{}WP'.format(target), self.cms.vstring(*cut_expressions)) + setattr(getattr(self.process, producer_name), 'VS{}WP'.format(target), cms.vstring(*cut_expressions)) def getDpfTauVersion(self, file_name): diff --git a/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc b/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc new file mode 100644 index 0000000000000..080c333fcf01b --- /dev/null +++ b/RecoTauTag/RecoTau/src/AntiElectronDeadECAL.cc @@ -0,0 +1,159 @@ +#include "RecoTauTag/RecoTau/interface/AntiElectronDeadECAL.h" + +#include "FWCore/Framework/interface/ESHandle.h" +#include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h" +#include "CondFormats/EcalObjects/interface/EcalChannelStatus.h" +#include "Geometry/Records/interface/CaloGeometryRecord.h" +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" +#include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h" +#include "Geometry/Records/interface/IdealGeometryRecord.h" +#include "DataFormats/TauReco/interface/PFTau.h" +#include "DataFormats/PatCandidates/interface/Tau.h" +#include "DataFormats/DetId/interface/DetId.h" +#include "DataFormats/EcalDetId/interface/EBDetId.h" +#include "DataFormats/EcalDetId/interface/EEDetId.h" +#include "DataFormats/Math/interface/deltaR.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +AntiElectronDeadECAL::AntiElectronDeadECAL(const edm::ParameterSet& cfg) + : minStatus_(cfg.getParameter("minStatus")), + dR2_(std::pow(cfg.getParameter("dR"), 2)), + extrapolateToECalEntrance_(cfg.getParameter("extrapolateToECalEntrance")), + verbosity_(cfg.getParameter("verbosity")), + isFirstEvent_(true) {} + +AntiElectronDeadECAL::~AntiElectronDeadECAL() {} + +void AntiElectronDeadECAL::beginEvent(const edm::EventSetup& es) { + updateBadTowers(es); + positionAtECalEntrance_.beginEvent(es); +} + +namespace { + template + void loopXtals(std::map& nBadCrystals, + std::map& maxStatus, + std::map& sumEta, + std::map& sumPhi, + const EcalChannelStatus* channelStatus, + const CaloGeometry* caloGeometry, + const EcalTrigTowerConstituentsMap* ttMap, + unsigned minStatus, + const uint16_t statusMask) { + // NOTE: modified version of SUSY CAF code + // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc + for (int i = 0; i < Id::kSizeForDenseIndexing; ++i) { + Id id = Id::unhashIndex(i); + if (id == Id(0)) + continue; + EcalChannelStatusMap::const_iterator it = channelStatus->getMap().find(id.rawId()); + unsigned status = (it == channelStatus->end()) ? 0 : (it->getStatusCode() & statusMask); + if (status >= minStatus) { + const GlobalPoint& point = caloGeometry->getPosition(id); + uint32_t key = ttMap->towerOf(id); + maxStatus[key] = std::max(status, maxStatus[key]); + ++nBadCrystals[key]; + sumEta[key] += point.eta(); + sumPhi[key] += point.phi(); + } + } + } +} // namespace + +void AntiElectronDeadECAL::updateBadTowers(const edm::EventSetup& es) { + // NOTE: modified version of SUSY CAF code + // UserCode/SusyCAF/plugins/SusyCAF_EcalDeadChannels.cc + + if (!isFirstEvent_ && !channelStatusWatcher_.check(es) && !caloGeometryWatcher_.check(es) && + !idealGeometryWatcher_.check(es)) + return; + + edm::ESHandle channelStatus; + es.get().get(channelStatus); + + edm::ESHandle caloGeometry; + es.get().get(caloGeometry); + + edm::ESHandle ttMap; + es.get().get(ttMap); + + std::map nBadCrystals, maxStatus; + std::map sumEta, sumPhi; + + loopXtals(nBadCrystals, + maxStatus, + sumEta, + sumPhi, + channelStatus.product(), + caloGeometry.product(), + ttMap.product(), + minStatus_, + statusMask_); + loopXtals(nBadCrystals, + maxStatus, + sumEta, + sumPhi, + channelStatus.product(), + caloGeometry.product(), + ttMap.product(), + minStatus_, + statusMask_); + + badTowers_.clear(); + for (auto it : nBadCrystals) { + uint32_t key = it.first; + badTowers_.push_back(TowerInfo(key, it.second, maxStatus[key], sumEta[key] / it.second, sumPhi[key] / it.second)); + } + + isFirstEvent_ = false; +} + +bool AntiElectronDeadECAL::operator()(const reco::Candidate* tau) const { + bool isNearBadTower = false; + double tau_eta = tau->eta(); + double tau_phi = tau->phi(); + const reco::Candidate* leadChargedHadron = nullptr; + if (extrapolateToECalEntrance_) { + const reco::PFTau* pfTau = dynamic_cast(tau); + if (pfTau != nullptr) { + leadChargedHadron = pfTau->leadChargedHadrCand().isNonnull() ? pfTau->leadChargedHadrCand().get() : nullptr; + } else { + const pat::Tau* patTau = dynamic_cast(tau); + if (patTau != nullptr) { + leadChargedHadron = patTau->leadChargedHadrCand().isNonnull() ? patTau->leadChargedHadrCand().get() : nullptr; + } + } + } + if (leadChargedHadron != nullptr) { + bool success = false; + reco::Candidate::Point positionAtECalEntrance = positionAtECalEntrance_(leadChargedHadron, success); + if (success) { + tau_eta = positionAtECalEntrance.eta(); + tau_phi = positionAtECalEntrance.phi(); + } + } + if (verbosity_) { + edm::LogPrint("TauAgainstEleDeadECAL") << ":"; + edm::LogPrint("TauAgainstEleDeadECAL") << " #badTowers = " << badTowers_.size(); + if (leadChargedHadron != nullptr) { + edm::LogPrint("TauAgainstEleDeadECAL") + << " leadChargedHadron (" << leadChargedHadron->pdgId() << "): Pt = " << leadChargedHadron->pt() + << ", eta at ECAL (vtx) = " << tau_eta << " (" << leadChargedHadron->eta() << ")" + << ", phi at ECAL (vtx) = " << tau_phi << " (" << leadChargedHadron->phi() << ")"; + } else { + edm::LogPrint("TauAgainstEleDeadECAL") + << " tau: Pt = " << tau->pt() << ", eta at vtx = " << tau_eta << ", phi at vtx = " << tau_phi; + } + } + for (auto const& badTower : badTowers_) { + if (deltaR2(badTower.eta_, badTower.phi_, tau_eta, tau_phi) < dR2_) { + if (verbosity_) { + edm::LogPrint("TauAgainstEleDeadECAL") + << " matches badTower: eta = " << badTower.eta_ << ", phi = " << badTower.phi_; + } + isNearBadTower = true; + break; + } + } + return isNearBadTower; +} diff --git a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc index c66ea912ccd94..547dc14e07090 100644 --- a/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc +++ b/RecoTauTag/RecoTau/src/AntiElectronIDMVA6.cc @@ -11,9 +11,6 @@ #include "CondFormats/DataRecord/interface/GBRWrapperRcd.h" #include "FWCore/Framework/interface/ESHandle.h" -#include "MagneticField/Engine/interface/MagneticField.h" -#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" - #include #include #include @@ -57,7 +54,6 @@ AntiElectronIDMVA6::AntiElectronIDMVA6(const edm::ParameterSet& cfg) Var_woGwGSF_Endcap_ = new Float_t[23]; Var_wGwGSF_Endcap_ = new Float_t[31]; - bField_ = 0; verbosity_ = 0; } @@ -134,10 +130,7 @@ void AntiElectronIDMVA6::beginEvent(const edm::Event& evt, const edm::EventSetup } isInitialized_ = true; } - - edm::ESHandle pSetup; - es.get().get(pSetup); - bField_ = pSetup->inTesla(GlobalPoint(0, 0, 0)).z(); + positionAtECalEntrance_.beginEvent(es); } double AntiElectronIDMVA6::MVAValue(Float_t TauPt, @@ -624,9 +617,11 @@ double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau, const reco::Gsf for (const auto& signalPFCand : signalPFCands) { reco::Candidate const* signalCand = signalPFCand.get(); float phi = thePFTau.phi(); - math::XYZPoint aPos; - if (atECalEntrance(signalCand, aPos)) + bool success = false; + reco::Candidate::Point aPos = positionAtECalEntrance_(signalCand, success); + if (success) { phi = aPos.Phi(); + } sumPhiTimesEnergy += phi * signalCand->energy(); sumEnergy += signalCand->energy(); } @@ -839,9 +834,11 @@ double AntiElectronIDMVA6::MVAValue(const reco::PFTau& thePFTau) { for (const auto& signalPFCand : signalPFCands) { reco::Candidate const* signalCand = signalPFCand.get(); float phi = thePFTau.phi(); - math::XYZPoint aPos; - if (atECalEntrance(signalCand, aPos) == true) + bool success = false; + reco::Candidate::Point aPos = positionAtECalEntrance_(signalCand, success); + if (success) { phi = aPos.Phi(); + } sumPhiTimesEnergy += phi * signalCand->energy(); sumEnergy += signalCand->energy(); } @@ -981,9 +978,11 @@ double AntiElectronIDMVA6::MVAValue(const pat::Tau& theTau, const pat::Electron& for (const auto& signalCandPtr : signalCands) { reco::Candidate const* signalCand = signalCandPtr.get(); float phi = theTau.phi(); - math::XYZPoint aPos; - if (atECalEntrance(signalCand, aPos) == true) + bool success = false; + reco::Candidate::Point aPos = positionAtECalEntrance_(signalCand, success); + if (success) { phi = aPos.Phi(); + } sumPhiTimesEnergy += phi * signalCand->energy(); sumEnergy += signalCand->energy(); } @@ -1172,9 +1171,11 @@ double AntiElectronIDMVA6::MVAValue(const pat::Tau& theTau) { for (const auto& signalCandPtr : signalCands) { reco::Candidate const* signalCand = signalCandPtr.get(); float phi = theTau.phi(); - math::XYZPoint aPos; - if (atECalEntrance(signalCand, aPos) == true) + bool success = false; + reco::Candidate::Point aPos = positionAtECalEntrance_(signalCand, success); + if (success) { phi = aPos.Phi(); + } sumPhiTimesEnergy += phi * signalCand->energy(); sumEnergy += signalCand->energy(); } @@ -1329,22 +1330,3 @@ double AntiElectronIDMVA6::dCrackEta(double eta) { return std::abs(retVal); } - -bool AntiElectronIDMVA6::atECalEntrance(const reco::Candidate* part, math::XYZPoint& pos) { - bool result = false; - BaseParticlePropagator theParticle = BaseParticlePropagator( - RawParticle(math::XYZTLorentzVector(part->px(), part->py(), part->pz(), part->energy()), - math::XYZTLorentzVector(part->vertex().x(), part->vertex().y(), part->vertex().z(), 0.), - part->charge()), - 0., - 0., - bField_); - theParticle.propagateToEcalEntrance(false); - if (theParticle.getSuccess() != 0) { - pos = math::XYZPoint(theParticle.particle().vertex()); - result = true; - } else { - result = false; - } - return result; -} diff --git a/RecoTauTag/RecoTau/src/PositionAtECalEntranceComputer.cc b/RecoTauTag/RecoTau/src/PositionAtECalEntranceComputer.cc new file mode 100644 index 0000000000000..aedab0dab18fb --- /dev/null +++ b/RecoTauTag/RecoTau/src/PositionAtECalEntranceComputer.cc @@ -0,0 +1,37 @@ +#include "RecoTauTag/RecoTau/interface/PositionAtECalEntranceComputer.h" + +#include "MagneticField/Engine/interface/MagneticField.h" +#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" +#include "CommonTools/BaseParticlePropagator/interface/BaseParticlePropagator.h" + +#include + +PositionAtECalEntranceComputer::PositionAtECalEntranceComputer() : bField_z_(-1.) {} + +PositionAtECalEntranceComputer::~PositionAtECalEntranceComputer() {} + +void PositionAtECalEntranceComputer::beginEvent(const edm::EventSetup& es) { + edm::ESHandle bField; + es.get().get(bField); + bField_z_ = bField->inTesla(GlobalPoint(0., 0., 0.)).z(); +} + +reco::Candidate::Point PositionAtECalEntranceComputer::operator()(const reco::Candidate* particle, bool& success) const { + assert(bField_z_ != -1.); + BaseParticlePropagator propagator = BaseParticlePropagator( + RawParticle(particle->p4(), + math::XYZTLorentzVector(particle->vertex().x(), particle->vertex().y(), particle->vertex().z(), 0.), + particle->charge()), + 0., + 0., + bField_z_); + propagator.propagateToEcalEntrance(false); + reco::Candidate::Point position; + if (propagator.getSuccess() != 0) { + position = propagator.particle().vertex().Vect(); + success = true; + } else { + success = false; + } + return position; +} diff --git a/RecoTauTag/RecoTau/src/TauDiscriminationProducerBase.cc b/RecoTauTag/RecoTau/src/TauDiscriminationProducerBase.cc index c114f0680f0d0..50d25e568e6cd 100644 --- a/RecoTauTag/RecoTau/src/TauDiscriminationProducerBase.cc +++ b/RecoTauTag/RecoTau/src/TauDiscriminationProducerBase.cc @@ -40,7 +40,7 @@ TauDiscriminationProducerBase("@module_label")) { // tau collection to discriminate - TauProducer_ = iConfig.getParameter(getProducerString()); + TauProducer_ = iConfig.getParameter(getTauTypeString() + "Producer"); Tau_token = consumes(TauProducer_); // prediscriminant operator @@ -172,7 +172,7 @@ template :: fillProducerDescriptions(edm::ParameterSetDescription& desc) { // helper function, it fills the description of the Producers parameter - desc.add(getProducerString(), edm::InputTag("fixme")); + desc.add(getTauTypeString() + "Producer", edm::InputTag("fixme")); { edm::ParameterSetDescription pset_prediscriminants; pset_prediscriminants.add("BooleanOperator", "AND"); @@ -191,14 +191,15 @@ void TauDiscriminationProducerBase -std::string getProducerString() { - return "PFTauProducer"; -} -template <> -std::string getProducerString() { - return "PATTauProducer"; +template +std::string +TauDiscriminationProducerBase::getTauTypeString() { + if (std::is_same::value) + return "PFTau"; + if (std::is_same::value) + return "PATTau"; + throw cms::Exception("TauDiscriminationProducerBase") + << "Unsupported TauType used. You must use either PFTau or PATTau."; } // compile our desired types and make available to linker diff --git a/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py b/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py index b8cdfd2c46190..9a555068fea5b 100644 --- a/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py +++ b/RecoTauTag/RecoTau/test/runDeepTauIDsOnMiniAOD.py @@ -8,7 +8,7 @@ # options.parseArguments() updatedTauName = "slimmedTausNewID" minimalOutput = True -eventsToProcess = 1 +eventsToProcess = 100 nThreads = 1 process = cms.Process('TauID') @@ -23,14 +23,14 @@ # Input source process.source = cms.Source('PoolSource', fileNames = cms.untracked.vstring( # File from dataset DY1JetsToLL_M-50_TuneCP5_13TeV-madgraphMLM-pythia8 - ' /store/mc/RunIIFall17MiniAODv2/TTToHadronic_TuneCP5_13TeV-powheg-pythia8/MINIAODSIM/PU2017_12Apr2018_94X_mc2017_realistic_v14-v1/40000/A256C80D-0943-E811-998E-7CD30AB0522C.root' + '/store/relval/CMSSW_10_5_0_pre1/RelValZTT_13/MINIAODSIM/PU25ns_103X_upgrade2018_realistic_v8-v1/20000/EA29017F-9967-3F41-BB8A-22C44A454235.root' )) process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(eventsToProcess) ) # Add new TauIDs import RecoTauTag.RecoTau.tools.runTauIdMVA as tauIdConfig -tauIdEmbedder = tauIdConfig.TauIDEmbedder(process, cms, debug = False, +tauIdEmbedder = tauIdConfig.TauIDEmbedder(process, debug = False, updatedTauName = updatedTauName, toKeep = [ "2017v2", "dR0p32017v2", "newDM2017v2", # "deepTau2017v1", diff --git a/RecoTauTag/RecoTau/test/runtests.sh b/RecoTauTag/RecoTau/test/runtests.sh index 8a0a2d274efe9..0dc7c497042eb 100755 --- a/RecoTauTag/RecoTau/test/runtests.sh +++ b/RecoTauTag/RecoTau/test/runtests.sh @@ -3,4 +3,4 @@ function die { echo $1: status $2 ; exit $2; } cmsRun ${LOCAL_TEST_DIR}/rerunTauRecoOnMiniAOD.py || die 'Failure using rerunTauRecoOnMiniAOD.py' $? - +cmsRun ${LOCAL_TEST_DIR}/runDeepTauIDsOnMiniAOD.py || die 'Failure using runDeepTauIDsOnMiniAOD.py' $? diff --git a/Utilities/DavixAdaptor/test/http.cpp b/Utilities/DavixAdaptor/test/http.cpp index 2845c704951b0..62648dcdbbb16 100644 --- a/Utilities/DavixAdaptor/test/http.cpp +++ b/Utilities/DavixAdaptor/test/http.cpp @@ -8,7 +8,7 @@ int main(int, char** /*argv*/) try { IOSize n; char buf[1024]; - auto s = StorageFactory::get()->open("http://home.web.cern.ch", IOFlags::OpenRead); + auto s = StorageFactory::get()->open("http://google.com", IOFlags::OpenRead); assert(s); while ((n = s->read(buf, sizeof(buf))))