22 #include <fmt/printf.h> 23 #include <boost/range/adaptor/indexed.hpp> 69 using fitParams = std::pair<Measurement1D, Measurement1D>;
92 template <std::
size_t SIZE>
95 unsigned int theNOfBins,
271 : compressionSettings_(iConfig.getUntrackedParameter<
int>(
"compressionSettings", -1)),
272 storeNtuple_(iConfig.getParameter<
bool>(
"storeNtuple")),
273 intLumi_(iConfig.getUntrackedParameter<double>(
"intLumi", 0.)),
274 debug_(iConfig.getUntrackedParameter<
bool>(
"Debug",
false)),
275 pvsTag_(iConfig.getParameter<
edm::
InputTag>(
"vtxCollection")),
277 tracksTag_(iConfig.getParameter<
edm::
InputTag>(
"trackCollection")),
280 transientTrackBuilderToken_(
283 minVtxNdf_(iConfig.getUntrackedParameter<double>(
"minVertexNdf")),
284 minVtxWgt_(iConfig.getUntrackedParameter<double>(
"minVertexMeanWeight")),
285 runControl_(iConfig.getUntrackedParameter<
bool>(
"runControl",
false)),
287 sumpTStartScale_(iConfig.getUntrackedParameter<double>(
"sumpTStartScale", 1.)),
288 sumpTEndScale_(iConfig.getUntrackedParameter<double>(
"sumpTEndScale", 1
e3)),
289 nVisTrackBins_(iConfig.getUntrackedParameter<double>(
"nTrackBins", 120.)),
290 nVisVtxBins_(iConfig.getUntrackedParameter<double>(
"nVtxBins", 60.)) {
293 std::vector<unsigned int> defaultRuns;
294 defaultRuns.push_back(0);
313 for (
const auto& pTbin :
mypT_bins_ | boost::adaptors::indexed(1)) {
314 if (pTbin.index() != 1) {
317 toOutput += fmt::sprintf(
"%.2f", pTbin.value());
318 if (pTbin.index() !=
nPtBins_ + 1) {
322 edm::LogVerbatim(
"SplitVertexResolution") <<
"sum(pT) bins = [" << toOutput <<
"] \n";
325 for (
const auto& tkbin :
myNTrack_bins_ | boost::adaptors::indexed(1)) {
326 if (tkbin.index() != 1) {
329 toOutput += fmt::sprintf(
"%.1f", tkbin.value());
334 edm::LogVerbatim(
"SplitVertexResolution") <<
"n. track bins = [" << toOutput <<
"] \n";
337 for (
const auto& vtxbin :
myNVtx_bins_ | boost::adaptors::indexed(1)) {
338 if (vtxbin.index() != 1) {
341 toOutput += fmt::sprintf(
"%.1f", vtxbin.value());
346 edm::LogVerbatim(
"SplitVertexResolution") <<
"n. vertices bins = [" << toOutput <<
"] \n";
362 bool passesRunControl =
false;
371 passesRunControl =
true;
375 if (!passesRunControl)
404 int nOfflineVtx = pvtx.size();
411 for (
int itrig = 0; itrig != ntrigs; ++itrig) {
422 int noFakecounter = 0;
425 for (
auto pvIt = pvtx.cbegin(); pvIt != pvtx.cend(); ++pvIt) {
440 if (trki->isNonnull()) {
457 ntrks % 2 == 0 ? even_ntrks = ntrks : even_ntrks = ntrks - 1;
460 for (
uint tracksIt = 0; tracksIt < even_ntrks; tracksIt = tracksIt + 2) {
463 auto dis = std::uniform_int_distribution<>(0, 1);
466 groupOne.push_back(firstTrk);
467 groupTwo.push_back(secondTrk);
469 groupOne.push_back(secondTrk);
470 groupTwo.push_back(firstTrk);
474 if (!(groupOne.size() >= 2 && groupTwo.size() >= 2))
481 float sumPt = 0, sumPt1 = 0, sumPt2 = 0, avgSumPt = 0;
484 std::vector<reco::TransientTrack> groupOne_ttks;
485 groupOne_ttks.clear();
486 for (
auto itrk = groupOne.cbegin(); itrk != groupOne.cend(); itrk++) {
488 groupOne_ttks.push_back(tmpTransientTrack);
489 sumPt1 += itrk->pt();
500 std::vector<reco::TransientTrack> groupTwo_ttks;
501 groupTwo_ttks.clear();
502 for (
auto itrk = groupTwo.cbegin(); itrk != groupTwo.cend(); itrk++) {
504 groupTwo_ttks.push_back(tmpTransientTrack);
505 sumPt2 += itrk->pt();
510 avgSumPt = (sumPt1 + sumPt2) / 2.;
536 int half_trks = twoPV.
nTracks();
538 const double invSqrt2 = 1. /
std::sqrt(2.);
540 double deltaX = (twoPV.
x() - onePV.
x());
541 double deltaY = (twoPV.
y() - onePV.
y());
542 double deltaZ = (twoPV.
z() - onePV.
z());
544 double resX = deltaX * invSqrt2;
545 double resY = deltaY * invSqrt2;
546 double resZ =
deltaZ * invSqrt2;
566 for (
int ipTBin = 0; ipTBin <
nPtBins_; ipTBin++) {
570 if (avgSumPt >= pTF && avgSumPt < pTL) {
583 for (
int inTrackBin = 0; inTrackBin <
nTrackBins_; inTrackBin++) {
586 if (ntrks >= nTrackF && ntrks < nTrackL) {
600 for (
int inVtxBin = 0; inVtxBin <
nVtxBins_; inVtxBin++) {
603 if (nOfflineVtx >= nVtxF && nOfflineVtx < nVtxL) {
683 unsigned int RunNumber_ =
run.run();
689 const time_t start_time = times.first / 1.0e+6;
691 << RunNumber_ <<
" has start time: " << times.first <<
" - " << times.second << std::endl;
693 <<
"human readable time: " << std::asctime(std::gmtime(&start_time)) << std::endl;
711 h_profileBinnings = BinningFeatures.
make<TH1F>(
"h_profileBinnings",
"profile binnings", 4, -0.5, 3.5);
728 EventFeatures.
make<TH1F>(
"h_lumiFromConfig",
"luminosity from config;;luminosity of present run", 1, -0.5, 0.5);
732 "run number from config;;run number (from configuration)",
744 edm::LogError(
"SplitVertexResolution") <<
" Warning - the vector of pT bins is not ordered " << std::endl;
748 edm::LogError(
"SplitVertexResolution") <<
" Warning -the vector of n. tracks bins is not ordered " << std::endl;
752 edm::LogError(
"SplitVertexResolution") <<
" Warning -the vector of n. vertices bins is not ordered " << std::endl;
812 h_runNumber =
outfile_->
make<TH1F>(
"h_runNumber",
"run number;run number;n_{events}", 100000, 250000., 350000.);
817 outfile_->
make<TH1I>(
"h_nRealVertices",
"n. of non-fake vertices;n. vertices; events", 100, 0, 100);
819 outfile_->
make<TH1I>(
"h_nSelectedVertices",
"n. of selected vertices vertices;n. vertices; events", 100, 0, 100);
822 "h_diffX",
"x-coordinate vertex resolution;vertex resolution (x) [#mum];vertices", 100, -300, 300.);
824 "h_diffY",
"y-coordinate vertex resolution;vertex resolution (y) [#mum];vertices", 100, -300, 300.);
826 "h_diffZ",
"z-coordinate vertex resolution;vertex resolution (z) [#mum];vertices", 100, -500, 500.);
829 "h_OrigVertexErrX",
"x-coordinate vertex error;vertex error (x) [#mum];vertices", 300, 0., 300.);
831 "h_OrigVertexErrY",
"y-coordinate vertex error;vertex error (y) [#mum];vertices", 300, 0., 300.);
833 "h_OrigVertexErrZ",
"z-coordinate vertex error;vertex error (z) [#mum];vertices", 500, 0., 500.);
836 "h_errX",
"x-coordinate vertex resolution error;vertex resoltuion error (x) [#mum];vertices", 300, 0., 300.);
838 "h_errY",
"y-coordinate vertex resolution error;vertex resolution error (y) [#mum];vertices", 300, 0., 300.);
840 "h_errZ",
"z-coordinate vertex resolution error;vertex resolution error (z) [#mum];vertices", 500, 0., 500.);
842 h_pullX =
outfile_->
make<TH1F>(
"h_pullX",
"x-coordinate vertex pull;vertex pull (x);vertices", 500, -10, 10.);
843 h_pullY =
outfile_->
make<TH1F>(
"h_pullY",
"y-coordinate vertex pull;vertex pull (y);vertices", 500, -10, 10.);
844 h_pullZ =
outfile_->
make<TH1F>(
"h_pullZ",
"z-coordinate vertex pull;vertex pull (z);vertices", 500, -10, 10.);
847 "number of tracks in vertex;vertex multeplicity;vertices",
855 "h_avgSumPt",
"#LT #Sigma p_{T} #GT;#LT #sum p_{T} #GT [GeV];vertices",
mypT_bins_.size() - 1,
mypT_bins_.data());
858 "#Sigma p_{T} sub-vertex 1;#sum p_{T} sub-vertex 1 [GeV];subvertices",
862 "#Sigma p_{T} sub-vertex 2;#sum p_{T} sub-vertex 2 [GeV];subvertices",
866 h_wTrks1 =
outfile_->
make<TH1F>(
"h_wTrks1",
"weight of track for sub-vertex 1;track weight;subvertices", 500, 0., 1.);
867 h_wTrks2 =
outfile_->
make<TH1F>(
"h_wTrks2",
"weithg of track for sub-vertex 2;track weight;subvertices", 500, 0., 1.);
870 "h_minWTrks1",
"minimum weight of track for sub-vertex 1;minimum track weight;subvertices", 500, 0., 1.);
872 "h_minWTrks2",
"minimum weithg of track for sub-vertex 2;minimum track weight;subvertices", 500, 0., 1.);
876 "#chi^{2} probability for sub-vertex 1;Prob(#chi^{2},ndof) for sub-vertex 1;subvertices",
882 "#chi^{2} probability for sub-vertex 2;Prob(#chi^{2},ndof) for sub-vertex 2;subvertices",
890 "x-resolution vs #Sigma p_{T};#sum p_{T} [GeV]; x vertex resolution [#mum]",
894 "y-resolution vs #Sigma p_{T};#sum p_{T} [GeV]; y vertex resolution [#mum]",
898 "z-resolution vs #Sigma p_{T};#sum p_{T} [GeV]; z vertex resolution [#mum]",
903 "x-resolution vs n_{tracks};n_{tracks}; x vertex resolution [#mum]",
907 "y-resolution vs n_{tracks};n_{tracks}; y vertex resolution [#mum]",
911 "z-resolution vs n_{tracks};n_{tracks}; z vertex resolution [#mum]",
916 "x-resolution vs n_{vertices};n_{vertices}; x vertex resolution [#mum]",
920 "y-resolution vs n_{vertices};n_{vertices}; y vertex resolution [#mum]",
924 "z-resolution vs n_{vertices};n_{vertices}; z vertex resolution [#mum]",
931 "x-pull vs #Sigma p_{T};#sum p_{T} [GeV]; x vertex pull",
935 "y-pull vs #Sigma p_{T};#sum p_{T} [GeV]; y vertex pull",
939 "z-pull vs #Sigma p_{T};#sum p_{T} [GeV]; z vertex pull",
944 "x-pull vs n_{tracks};n_{tracks}; x vertex pull",
948 "y-pull vs n_{tracks};n_{tracks}; y vertex pull",
952 "z-pull vs n_{tracks};n_{tracks}; z vertex pull",
957 "x-pull vs n_{vertices};n_{vertices}; x vertex pull",
961 "y-pull vs n_{vertices};n_{vertices}; y vertex pull",
965 "z-pull vs n_{vertices};n_{vertices}; z vertex pull",
977 unsigned int theNOfBins,
980 TH1F::SetDefaultSumw2(kTRUE);
985 if (resType.Contains(
"pull")) {
990 std::vector<TH1F*>
h;
991 h.reserve(theNOfBins);
993 const char* auxResType = (resType.ReplaceAll(
"_",
"")).Data();
995 for (
unsigned int i = 0;
i < theNOfBins;
i++) {
996 TH1F* htemp =
dir.make<TH1F>(Form(
"histo_%s_%s_plot%i", resType.Data(),
varType.Data(),
i),
997 Form(
"%s vs %s - bin %i;%s;vertices", auxResType,
varType.Data(),
i, auxResType),
1009 edm::LogVerbatim(
"SplitVertexResolution") <<
"*******************************" << std::endl;
1012 edm::LogVerbatim(
"SplitVertexResolution") <<
"*******************************" << std::endl;
1015 edm::LogVerbatim(
"SplitVertexResolution") <<
"firing triggers: " << nFiringTriggers << std::endl;
1016 edm::LogVerbatim(
"SplitVertexResolution") <<
"*******************************" << std::endl;
1019 "tksByTrigger",
"tracks by HLT path;;% of # traks", nFiringTriggers, -0.5, nFiringTriggers - 0.5);
1021 "evtsByTrigger",
"events by HLT path;;% of # events", nFiringTriggers, -0.5, nFiringTriggers - 0.5);
1027 double trkpercent = ((it->second).
second) * 100. / double(
itrks);
1028 double evtpercent = ((it->second).
first) * 100. / double(
ievt);
1031 <<
"HLT path: " << std::setw(60) << std::left << it->first <<
" | events firing: " << std::right << std::setw(8)
1032 << (it->second).
first <<
" (" << std::setw(8) <<
std::fixed << std::setprecision(4) << evtpercent <<
"%)" 1033 <<
" | tracks collected: " << std::setw(8) << (it->second).
second <<
" (" << std::setw(8) <<
std::fixed 1034 << std::setprecision(4) << trkpercent <<
"%)";
1049 unsigned int count = 1;
1094 "Validates alignment payloads by evaluating the resulting Primary Vertex Resolution via vertex splitting method");
1096 desc.addUntracked<
int>(
"compressionSettings", -1);
1097 desc.add<
bool>(
"storeNtuple",
false);
1098 desc.addUntracked<
double>(
"intLumi", 0.);
1099 desc.addUntracked<
bool>(
"Debug",
false);
1102 desc.addUntracked<
double>(
"minVertexNdf", 10);
1103 desc.addUntracked<
double>(
"minVertexMeanWeight", 0.5);
1104 desc.addUntracked<
bool>(
"runControl",
false);
1105 desc.addUntracked<std::vector<unsigned int>>(
"runControlNumber", {});
1106 desc.addUntracked<
double>(
"sumpTStartScale", 1.);
1107 desc.addUntracked<
double>(
"sumpTEndScale", 1
e3);
1108 desc.addUntracked<
double>(
"nTrackBins", 120.);
1109 desc.addUntracked<
double>(
"nVtxBins", 60.);
1120 <<
"start time: " <<
runInfo.m_start_time_str <<
" - stop time: " <<
runInfo.m_stop_time_str << std::endl;
1122 return std::make_pair(
runInfo.m_start_time_ll,
runInfo.m_stop_time_ll);
1129 for (
auto iterator =
h.begin(); iterator !=
h.end(); iterator++) {
1135 float mean_ = myFit.first.value();
1136 float meanErr_ = myFit.first.error();
1137 trendPlot->SetBinContent(
bin, mean_);
1138 trendPlot->SetBinError(
bin, meanErr_);
1142 float width_ = myFit.second.value();
1143 float widthErr_ = myFit.second.error();
1144 trendPlot->SetBinContent(
bin, width_);
1145 trendPlot->SetBinError(
bin, widthErr_);
1151 trendPlot->SetBinContent(
bin, median_);
1152 trendPlot->SetBinError(
bin, medianErr_);
1158 trendPlot->SetBinContent(
bin, mad_);
1159 trendPlot->SetBinError(
bin, madErr_);
1164 <<
"fillTrendPlotByIndex() " << fitPar_ <<
" unknown estimator!" << std::endl;
1174 if (
hist->GetEntries() < 10) {
1175 LogDebug(
"SplitVertexResolution") <<
"hist name: " <<
hist->GetName() <<
" has less than 10 entries" << std::endl;
1179 float maxHist =
hist->GetXaxis()->GetXmax();
1180 float minHist =
hist->GetXaxis()->GetXmin();
1182 float sigma =
hist->GetRMS();
1187 sigma = -minHist + maxHist;
1189 <<
"FitPVResiduals::fitResiduals(): histogram" <<
hist->GetName() <<
" mean or sigma are NaN!!" << std::endl;
1192 TF1
func(
"tmp",
"gaus",
mean - 2. * sigma,
mean + 2. * sigma);
1193 if (0 ==
hist->Fit(&
func,
"QNR")) {
1195 sigma =
func.GetParameter(2);
1202 if (0 ==
hist->Fit(&
func,
"Q0LR")) {
1203 if (
hist->GetFunction(
func.GetName())) {
1204 hist->GetFunction(
func.GetName())->ResetBit(TF1::kNotDraw);
1210 float res_mean =
func.GetParameter(1);
1211 float res_width =
func.GetParameter(2);
1213 float res_mean_err =
func.GetParError(1);
1214 float res_width_err =
func.GetParError(2);
1228 float sigma =
hist->GetRMS();
1230 TF1
func(
"tmp",
"gaus",
mean - 1.5 * sigma,
mean + 1.5 * sigma);
1231 if (0 ==
hist->Fit(&
func,
"QNR")) {
1233 sigma =
func.GetParameter(2);
1238 if (0 ==
hist->Fit(&
func,
"Q0LR")) {
1239 if (
hist->GetFunction(
func.GetName())) {
1240 hist->GetFunction(
func.GetName())->ResetBit(TF1::kNotDraw);
1245 float res_mean =
func.GetParameter(1);
1246 float res_width =
func.GetParameter(2);
1248 float res_mean_err =
func.GetParError(1);
1249 float res_width_err =
func.GetParError(2);
1259 template <std::
size_t SIZE>
1265 if (std::is_sorted(
bins.begin(),
bins.end())) {
1268 for (
const auto&
bin :
bins) {
1269 edm::LogInfo(
"SplitVertexResolution") <<
"bin: " <<
i <<
" : " <<
bin << std::endl;
1272 edm::LogInfo(
"SplitVertexResolution") <<
"--------------------------------" << std::endl;
static const std::string kSharedResource
Log< level::Info, true > LogVerbatim
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Measurement1D getMedian(TH1F *histo)
float totalChiSquared() const
const double nVisVtxBins_
std::vector< TH1F * > h_resolZ_Nvtx_
std::vector< TH1F * > h_pullY_sumPt_
std::pair< long long, long long > getRunTime(const edm::EventSetup &iSetup) const
void beginRun(edm::Run const &iEvent, edm::EventSetup const &) override
SplitVertexResolution(const edm::ParameterSet &)
double z() const
z coordinate
const float sumpTEndScale_
std::vector< TH1F * > h_pullZ_sumPt_
std::vector< TH1F * > h_resolX_sumPt_
void endRun(edm::Run const &, edm::EventSetup const &) override
constexpr bool isNotFinite(T x)
std::vector< float > generateBins(int n, float start, float range)
edm::EDGetTokenT< reco::VertexCollection > pvsToken_
std::vector< Track > TrackCollection
collection of Tracks
std::string to_string(const V &value)
std::vector< Vertex > VertexCollection
collection of Vertex objects
statmode::fitParams fitResiduals_v0(TH1 *hist)
Log< level::Error, false > LogError
double zError() const
error on z
CachingVertex< 5 > vertex(const std::vector< reco::TransientTrack > &) const override
std::vector< Vertex > VertexCollection
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
float degreesOfFreedom() const
Measurement1D getMAD(TH1F *histo)
double xError() const
error on x
std::vector< TH1F * > h_pullY_Ntracks_
trackRef_iterator tracks_end() const
last iterator over tracks
edm::ESGetToken< RunInfo, RunInfoRcd > runInfoToken_
std::pair< Measurement1D, Measurement1D > fitParams
size_t tracksSize() const
number of tracks
T getUntrackedParameter(std::string const &, T const &) const
reco::TransientTrack build(const reco::Track *p) const
U second(std::pair< T, U > const &p)
TH1F * p_resolX_vsNtracks
T * make(const Args &...args) const
make new ROOT object
edm::InputTag triggerResultsTag_
std::array< float, nPtBins_+1 > mypT_bins_
static constexpr double cmToUm
void fillTrendPlotByIndex(TH1F *trendPlot, std::vector< TH1F *> &h, PVValHelper::estimator fitPar_)
std::vector< pvCand > pvs
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
unsigned int nTracks(float minWeight=0.5) const
Returns the number of tracks in the vertex with weight above minWeight.
std::vector< reco::TransientTrack > const & originalTracks() const
trackRef_iterator tracks_begin() const
first iterator over tracks
static const int nVtxBins_
#define DEFINE_FWK_MODULE(type)
bool getData(T &iHolder) const
double x() const
x coordinate
static const int nPtBins_
std::array< float, nVtxBins_+1 > myNVtx_bins_
std::vector< TH1F * > h_resolX_Nvtx_
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
double y() const
y coordinate
edm::Service< TFileService > outfile_
const int compressionSettings_
std::map< std::string, std::pair< int, int > > triggerMap_
Log< level::Info, false > LogInfo
~SplitVertexResolution() override
TH1I * h_nNonFakeVertices
static bool mysorter(reco::Track i, reco::Track j)
std::array< float, nTrackBins_+1 > myNTrack_bins_
std::map< unsigned int, std::pair< long long, long long > > runNumbersTimesLog_
std::vector< TH1F * > h_pullY_Nvtx_
std::vector< TH1F * > h_resolZ_Ntracks_
auto const & tracks
cannot be loose
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
TH1I * h_nOfflineVertices
std::vector< TH1F * > h_pullX_Nvtx_
virtual void beginEvent() final
int luminosityBlockNumber
static const int nTrackBins_
statmode::fitParams fitResiduals(TH1 *hist, bool singleTime=false)
std::string const & triggerName(unsigned int index) const
std::vector< TH1F * > h_pullZ_Nvtx_
std::vector< TH1F * > bookResidualsHistogram(TFileDirectory dir, unsigned int theNOfBins, TString resType, TString varType)
std::vector< TH1F * > h_resolY_Nvtx_
const float sumpTStartScale_
double yError() const
error on y
static std::atomic< unsigned int > counter
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transientTrackBuilderToken_
std::vector< TH1F * > h_pullX_sumPt_
float trackWeight(const reco::TransientTrack &track) const
T * make(const Args &...args) const
make new ROOT object
Log< level::Warning, false > LogWarning
std::vector< TH1F * > h_pullX_Ntracks_
bool checkBinOrdering(std::array< float, SIZE > &bins)
void fillByIndex(std::vector< TH1F *> &h, unsigned int index, double x, std::string tag="")
TH1F * p_resolY_vsNtracks
edm::EDGetTokenT< reco::TrackCollection > tracksToken_
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
std::vector< TH1F * > h_pullZ_Ntracks_
std::vector< TH1F * > h_resolY_sumPt_
std::vector< unsigned int > runControlNumbers_
std::vector< TH1F * > h_resolX_Ntracks_
void analyze(const edm::Event &, const edm::EventSetup &) override
TH1F * p_resolZ_vsNtracks
std::vector< TH1F * > h_resolY_Ntracks_
Power< A, B >::type pow(const A &a, const B &b)
const double nVisTrackBins_
std::vector< TH1F * > h_resolZ_sumPt_
TFile & file() const
return opened TFile