|
|
Go to the documentation of this file.
114 #include <CLHEP/Vector/LorentzVector.h>
148 #include "HepPDT/defs.h"
149 #include "HepPDT/TableBuilder.hh"
150 #include "HepPDT/ParticleDataTable.hh"
152 #include "HepMC/GenParticle.h"
153 #include "HepMC/GenEvent.h"
172 #include "valgrind/callgrind.h"
214 template <
typename T>
232 template <
typename T>
315 template <
typename T>
317 std::vector<MuScleFitMuon>
muons;
318 typename std::vector<T>::const_iterator
track;
335 Double_t hitsTk =
track->innerTrack()->hitPattern().numberOfValidTrackerHits();
336 Double_t hitsMuon =
track->innerTrack()->hitPattern().numberOfValidMuonHits();
337 Double_t ptError =
track->innerTrack()->ptError();
340 std::cout <<
"[MuScleFit::fillMuonCollection]" << std::endl;
351 template <
typename T>
376 std::cout <<
"[MuScleFit]: Constructor" << std::endl;
378 if ((theMuonType_ < -4 || theMuonType_ > 5) &&
theMuonType_ < 10) {
379 std::cout <<
"[MuScleFit]: Unknown muon type! Aborting." << std::endl;
403 fastLoop =
pset.getUntrackedParameter<
bool>(
"FastLoop",
true);
413 int biasType =
pset.getParameter<
int>(
"BiasType");
417 int smearType =
pset.getParameter<
int>(
"SmearType");
423 int resolFitType =
pset.getParameter<
int>(
"ResolFitType");
427 int scaleType =
pset.getParameter<
int>(
"ScaleFitType");
438 pset.getUntrackedParameter<std::vector<double> >(
"parResolStep", std::vector<double>());
443 pset.getUntrackedParameter<std::vector<double> >(
"parScaleStep", std::vector<double>());
470 triggerPath_ =
pset.getUntrackedParameter<std::vector<std::string> >(
"TriggerPath");
478 PATmuons_ =
pset.getUntrackedParameter<
bool>(
"PATmuons",
false);
511 std::cout <<
"[MuScleFit-Constructor]: Generating random values for smearing" << std::endl;
512 TF1
G(
"G",
"[0]*exp(-0.5*pow(x,2))", -5., 5.);
514 G.SetParameter(0, norm);
515 for (
int i = 0;
i < 10000;
i++) {
516 for (
int j = 0;
j < 7;
j++) {
574 pset.getParameter<std::vector<double> >(
"LeftWindowBorder"),
575 pset.getParameter<std::vector<double> >(
"RightWindowBorder"),
586 pset.getUntrackedParameter<
bool>(
"NormalizeLikelihoodByEventNumber",
true);
588 std::cout <<
"End of MuScleFit constructor" << std::endl;
605 std::cout <<
"[MuScleFit]: Destructor" << std::endl;
611 std::cout <<
"Saving muon pairs to root tree" << std::endl;
616 std::vector<MuonPair>::const_iterator it =
muonPairs_.begin();
617 std::cout <<
"[MuScleFit::~MuScleFit] (Destructor)" << std::endl;
619 std::cout <<
" Debugging pairs that are going to be written to file" << std::endl;
620 std::cout <<
" muon1 = " << it->mu1 << std::endl;
621 std::cout <<
" muon2 = " << it->mu2 << std::endl;
644 std::cout <<
"[MuScleFit]: beginOfJob" << std::endl;
651 std::cout <<
"[MuScleFit]: beginOfJob" << std::endl;
656 std::stringstream
ss;
666 std::cout <<
"[MuScleFit]: Root file created" << std::endl;
668 std::cout <<
"creating plotter" << std::endl;
677 std::cout <<
"[MuScleFit]: endOfJob" << std::endl;
684 std::cout <<
"[MuScleFit]: Starting loop # " << iLoop << std::endl;
710 unsigned int iFastLoop = 1;
725 std::cout <<
"Starting fast loop number " << iFastLoop << std::endl;
735 if (
iev % 50000 == 0) {
736 std::cout <<
"Fast looping on event number " <<
iev << std::endl;
741 std::cout <<
"End of fast loop number " << iFastLoop <<
". Ran on " <<
iev <<
" events" << std::endl;
762 std::cout <<
"Ending loop # " << iLoop << std::endl;
772 TDirectory* likelihoodDir =
theFiles_[iLoop]->mkdir(
"likelihood");
792 bool isFired =
false;
799 std::cout <<
"Trigger " << isFired << std::endl;
811 for (
unsigned int ipath = 0; ipath <
triggerPath_.size(); ipath++) {
812 if (hltName.find(
triggerPath_[ipath]) != std::string::npos) {
813 unsigned int triggerIndex(
hltConfig.triggerIndex(hltName));
816 if (triggerIndex < triggerResults->
size()) {
832 CALLGRIND_START_INSTRUMENTATION;
836 std::cout <<
"[MuScleFit-duringLoop]: loopCounter = " <<
loopCounter <<
" Run: " <<
event.id().run()
837 <<
" Event: " <<
event.id().event() << std::endl;
848 std::cout <<
"Reading from edm event" << std::endl;
858 CALLGRIND_STOP_INSTRUMENTATION;
859 CALLGRIND_DUMP_STATS;
867 std::vector<MuScleFitMuon>
muons;
872 std::cout <<
"[MuScleFit::selectMuons] Debugging muons collections after call to muonSelector_->selectMuons"
875 for (std::vector<MuScleFitMuon>::const_iterator it =
muons.begin(); it <
muons.end(); ++it) {
876 std::cout <<
" - muon n. " << iMu <<
" = " << (*it) << std::endl;
887 std::cout << std::setprecision(9) <<
"Pt after findbestrecores: " << (recMuFromBestRes.first).Pt() <<
" "
888 << (recMuFromBestRes.second).Pt() << std::endl;
892 recMu1 = recMuFromBestRes.first.p4();
893 recMu2 = recMuFromBestRes.second.p4();
915 Int_t the_numPUvtx(0);
916 Float_t the_TrueNumInteractions(0);
923 std::vector<PileupSummaryInfo>::const_iterator PVI;
924 for (PVI = puInfo->begin(); PVI != puInfo->end(); ++PVI) {
925 int BX = PVI->getBunchCrossing();
927 the_TrueNumInteractions = PVI->getTrueNumInteractions();
928 the_numPUvtx = PVI->getPU_NumInteractions();
936 std::vector<reco::Vertex>::const_iterator itv;
942 if (fabs(itv->z()) > 50.0)
944 if (fabs(itv->position().rho()) > 2.0)
952 event.getByLabel(
"generator", genEvtInfo);
953 double the_genEvtweight = 1.;
955 the_genEvtweight = genEvtInfo->
weight();
962 event.run(),
event.id().event(), the_genEvtweight, the_numPUvtx, the_TrueNumInteractions, the_NVtx)));
970 std::cout <<
"Reading muon pairs from Root Tree in " << treeFileName << std::endl;
972 std::vector<std::pair<unsigned int, unsigned long long> > evtRun;
985 std::vector<std::pair<unsigned int, unsigned long long> >::iterator evtRunIt = evtRun.begin();
987 std::vector<std::pair<MuScleFitMuon, MuScleFitMuon> >::iterator genIt;
994 double pt1 = it->first.pt();
996 double pt2 = it->second.pt();
998 double eta1 = it->first.eta();
1000 double eta2 = it->second.eta();
1003 bool dontPass =
false;
1004 bool eta1InFirstRange;
1005 bool eta2InFirstRange;
1006 bool eta1InSecondRange;
1007 bool eta2InSecondRange;
1009 int ch1 = it->first.charge();
1010 int ch2 = it->second.charge();
1023 ((eta1InFirstRange && eta2InSecondRange && ch1 >= ch2) ||
1024 (eta1InSecondRange && eta2InFirstRange && ch1 < ch2))))
1035 (((eta1InFirstRange && !eta2InFirstRange) && (eta2InSecondRange && !eta1InSecondRange) && ch1 >= ch2) ||
1036 ((eta2InFirstRange && !eta1InFirstRange) && (eta1InSecondRange && !eta2InSecondRange) && ch1 < ch2))))
1070 (*evtRunIt).first, (*evtRunIt).second, 0, 0, 0, 0))
1115 <<
" Pt2 = " <<
recMu2.Pt() << std::endl;
1127 <<
" Pt2 = " <<
recMu2.Pt() << std::endl;
1142 mapHisto_[
"hRecBestResAllEvents"]->Fill(bestRecRes, +1, 1.);
1164 mapHisto_[
"hRecBestResVSRes"]->Fill(bestRecRes, bestRecRes, +1,
weight);
1166 std::vector<double>* parval;
1167 std::vector<double> initpar;
1207 mapHisto_[
"hFunctionResolCotgTheta"]->Fill(
1213 mapHisto_[
"hFunctionResolCotgTheta"]->Fill(
1221 std::cout <<
"mass = " << bestRecRes.mass() << std::endl;
1227 std::vector<double> initpar;
1247 bestRecRes.Rapidity(),
1259 bestRecRes.Rapidity(),
1267 std::cout <<
"inside weight: mass = " << bestRecRes.mass() <<
", prob = " <<
prob << std::endl;
1270 std::cout <<
"inside prob: mass = " << bestRecRes.mass() <<
", prob = " <<
prob << std::endl;
1279 if (recoMass != 0) {
1283 mapHisto_[
"hFunctionResolMassVSMu"]->Fill(
recMu1, massResol / recoMass, -1);
1284 mapHisto_[
"hFunctionResolMassVSMu"]->Fill(
recMu2, massResol / recoMass, +1);
1306 double diffMass = (recoMass - genMass) / genMass;
1314 if (diffMass == diffMass) {
1316 mapHisto_[
"hDeltaMassOverGenMassVsPt"]->Fill(
pt1, diffMass);
1317 mapHisto_[
"hDeltaMassOverGenMassVsPt"]->Fill(
pt2, diffMass);
1318 mapHisto_[
"hDeltaMassOverGenMassVsEta"]->Fill(
eta1, diffMass);
1319 mapHisto_[
"hDeltaMassOverGenMassVsEta"]->Fill(
eta2, diffMass);
1324 std::cout <<
"Error, there is a nan: recoMass = " << recoMass <<
", genMass = " << genMass << std::endl;
1335 std::cout <<
"mass = " << bestRecRes.mass() <<
", prob = " <<
prob << std::endl;
1338 mapHisto_[
"hMassProbVsRes"]->Fill(bestRecRes, bestRecRes, +1,
prob);
1341 mapHisto_[
"hMassProbVsRes_fine"]->Fill(bestRecRes, bestRecRes, +1,
prob);
1352 std::cout <<
"[MuScleFit]: filling the pair" << std::endl;
1366 ((recMu.Eta() - genMu.Eta()) * (recMu.Eta() - genMu.Eta())));
1370 std::cout <<
"Reco muon " << recMu <<
" with eta " << recMu.Eta() <<
" and phi " << recMu.Phi() << std::endl
1371 <<
" DOES NOT MATCH with generated muon from resonance: " << std::endl
1372 << genMu <<
" with eta " << genMu.Eta() <<
" and phi " << genMu.Phi() << std::endl;
1382 mapHisto_[
"hResolPt" +
name]->Fill(recMu, (-genMu.Pt() + recMu.Pt()) / genMu.Pt(),
charge);
1385 recMu, (-
cos(genMu.Theta()) /
sin(genMu.Theta()) +
cos(recMu.Theta()) /
sin(recMu.Theta())),
charge);
1390 if ((genMu.Pt() != 0) && (recMu.Pt() != 0)) {
1391 mapHisto_[
"hPtRecoVsPt" + inputName]->Fill(genMu.Pt(), recMu.Pt());
1416 std::cout <<
"[MuScleFit-Constructor]: wrong size of resolution fits selector = "
1418 std::cout <<
"it must have as many values as the number of loops, which is = " <<
maxLoopNumber << std::endl;
1424 std::cout <<
"it must have as many values as the number of loops, which is = " <<
maxLoopNumber << std::endl;
1428 std::cout <<
"[MuScleFit-Constructor]: wrong size of cross section fits selector = "
1430 std::cout <<
"it must have as many values as the number of loops, which is = " <<
maxLoopNumber << std::endl;
1434 std::cout <<
"[MuScleFit-Constructor]: wrong size of background fits selector = "
1436 std::cout <<
"it must have as many values as the number of loops, which is = " <<
maxLoopNumber << std::endl;
1462 std::cout <<
"[MuScleFit-Constructor]: Wrong bias type or number of parameters: aborting!" << std::endl;
1475 std::cout <<
"[MuScleFit-Constructor]: Wrong smear type or number of parameters: aborting!" << std::endl;
1482 std::cout <<
"[MuScleFit-Constructor]: Mismatch in number of parameters for Resol: aborting!" << std::endl;
1487 std::cout <<
"[MuScleFit-Constructor]: Mismatch in number of parameters for Scale: aborting!" << std::endl;
1492 std::cout <<
"[MuScleFit-Constructor]: Mismatch in number of parameters for Bgr: aborting!" << std::endl;
1497 std::cout <<
"[MuScleFit-Constructor]: Mismatch in number of parameters for Bgr: aborting!" << std::endl;
1504 std::cout <<
"[MuScleFit-Constructor]: resfind must have 6 elements (1 Z, 3 Y, 2 Psi): aborting!" << std::endl;
1517 iTrack->found() > 11 && gTrack->chi2() / gTrack->ndof() < 20.0 &&
q.numberOfValidMuonHits() > 0 &&
1518 iTrack->chi2() / iTrack->ndof() < 4.0 && aMuon->
muonID(
"TrackerMuonArbitrated") &&
1519 aMuon->
muonID(
"TMLastStationAngTight") &&
p.pixelLayersWithMeasurement() > 1 &&
1520 fabs(iTrack->dxy()) < 3.0 &&
1521 fabs(iTrack->dz()) < 15.0);
1529 iTrack->found() > 11 && iTrack->chi2() / iTrack->ndof() < 4.0 && aMuon->
muonID(
"TrackerMuonArbitrated") &&
1530 aMuon->
muonID(
"TMLastStationAngTight") &&
p.pixelLayersWithMeasurement() > 1 &&
1531 fabs(iTrack->dxy()) < 3.0 &&
1532 fabs(iTrack->dz()) < 15.0);
void takeSelectedMuonType(const T &muon, std::vector< reco::Track > &tracks)
Template method used to fill the track collection starting from reco::muons or pat::muons.
static double x[7][10000]
static std::vector< double > parSmear
static std::vector< int > parScaleFix
std::vector< MuonPair > muonPairs_
Used to store the muon pairs plus run and event number prior to the creation of the internal tree.
bool selTrackerMuon(const pat::Muon *aMuon)
static double deltaPhiNoFabs(const double &phi1, const double &phi2)
Without fabs at the end, used to have a symmetric distribution for the resolution fits and variance c...
static std::pair< MuScleFitMuon, MuScleFitMuon > findBestRecoRes(const std::vector< MuScleFitMuon > &muons)
static smearFunctionBase * smearFunction
static std::vector< double > parResolMin
void fillComparisonHistograms(const reco::Particle::LorentzVector &genMu, const reco::Particle::LorentzVector &recoMu, const std::string &inputName, const int charge)
Fill the reco vs gen and reco vs sim comparison histograms.
static std::vector< std::vector< double > > parvalue
static bool separateRanges_
std::vector< GenMuonPair > genMuonPairs_
Stores the genMuon pairs and the motherId prior to the creation of the internal tree.
static std::vector< int > parScaleOrder
std::vector< double > vec1
static double maxMuonEtaFirstRange_
static double computeWeight(const double &mass, const int iev, const bool doUseBkgrWindow=false)
static double deltaPhi(const double &phi1, const double &phi2)
edm::EDLooper::Status duringLoop(const edm::Event &event, const edm::EventSetup &eventSetup) override
void fillTreeRec(const std::vector< std::pair< reco::Particle::LorentzVector, reco::Particle::LorentzVector > > &savedPairs)
Used when running on the root tree containing preselected muon pairs.
static std::vector< int > parBgrFix
static double deltaPhiMaxCut_
static bool computeMinosErrors_
static CrossSectionHandler * crossSectionHandler
static const std::string triggerResults
static int MuonTypeForCheckMassWindow
U second(std::pair< T, U > const &p)
resolutionFunctionBase< double * > * resolutionFunctionService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier.
static std::vector< int > parResolOrder
static std::vector< int > parCrossSectionOrder
static lorentzVector applyScale(const lorentzVector &muon, const std::vector< double > &parval, const int charge)
Analysis-level muon class.
static struct MuScleFitUtils::massResolComponentsStruct massResolComponents
#define DEFINE_FWK_LOOPER(type)
void selectMuons(const edm::Event &event)
static bool useProbsFile_
void readProbabilityDistributionsFromFile()
Read probability distributions from a local root file.
static std::vector< int > resfind
int maxEventsFromRootTree_
static std::vector< std::pair< lorentzVector, lorentzVector > > genPair
math::XYZTLorentzVector LorentzVector
Lorentz vector.
reco::Particle::LorentzVector recMu2
static bool rapidityBinsForZ_
edm::EDLooper::Status endOfLoop(const edm::EventSetup &eventSetup, unsigned int iLoop) override
static lorentzVector applySmearing(const lorentzVector &muon)
Sin< T >::type sin(const T &t)
resolutionFunctionBase< std::vector< double > > * resolutionFunctionVecService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier when receiving a std::...
void addParameters(std::vector< double > &initpar)
Inputs the vars in a vector.
static bool minimumShapePlots_
static std::vector< int > doCrossSectionFit
MuScleFitMuon recMuScleMu1
std::vector< TFile * > theFiles_
The files were the histograms are saved.
Cos< T >::type cos(const T &t)
edm::InputTag simTracksCollection_
static std::vector< double > parResol
static bool normalizeLikelihoodByEventNumber_
static std::vector< double > parCrossSection
static bool debugMassResol_
static std::vector< double > parResolMax
void fillTreeGen(const std::vector< std::pair< reco::Particle::LorentzVector, reco::Particle::LorentzVector > > &genPairs)
reco::Particle::LorentzVector recMu1
static double deltaPhiMinCut_
static scaleFunctionBase< double * > * scaleFunction
static double massResolution(const lorentzVector &mu1, const lorentzVector &mu2)
static bool startWithSimplex_
void startingNewLoop(unsigned int iLoop) override
static double minMuonEtaSecondRange_
void applySmearing(reco::Particle::LorentzVector &mu)
Apply the smearing if needed using the function in MuScleFitUtils.
edm::InputTag theMuonLabel_
unsigned int maxLoopNumber
double maxResMass_hwindow[6]
static std::vector< double > parScale
static resolutionFunctionBase< std::vector< double > > * resolutionFunctionForVec
std::string theRootFileName_
void writeTree(const TString &fileName, const std::vector< MuonPair > *savedPair, const int muonType=0, const std::vector< GenMuonPair > *genPair=nullptr, const bool saveAll=false)
scaleFunctionBase< std::vector< double > > * scaleFunctionVecService(const int identifier)
Service to build the scale functor corresponding to the passed identifier when receiving a std::vecto...
static double minMuonEtaFirstRange_
void beginOfJobInConstructor()
std::string triggerResultsLabel_
static std::vector< std::pair< MuScleFitMuon, MuScleFitMuon > > SavedPairMuScleFitMuons
static double massWindowHalfWidth[3][6]
MuonServiceProxy * theService
static std::vector< double > parScaleMax
double minResMass_hwindow[6]
reco::Particle::LorentzVector lorentzVector
const uint32_t *__restrict__ const HitContainer *__restrict__ TkSoA *__restrict__ tracks
void fillHistoMap(TFile *outputFile, unsigned int iLoop)
Create the histograms map.
static std::vector< std::pair< lorentzVector, lorentzVector > > SavedPair
std::unique_ptr< MuScleFitMuonSelector > muonSelector_
std::string outputRootTreeFileName_
std::vector< MuScleFitMuon > fillMuonCollection(const std::vector< T > &tracks)
static scaleFunctionBase< std::vector< double > > * biasFunction
MuScleFitMuon recMuScleMu2
static std::vector< int > parResolFix
bool selGlobalMuon(const pat::Muon *aMuon)
Function for onia selections.
std::string theGenInfoRootFileName_
static std::vector< double > parBgr
std::string triggerResultsProcess_
void clearHistoMap()
Clean the histograms map.
static std::vector< int > parBgrOrder
static std::vector< std::pair< MuScleFitMuon, MuScleFitMuon > > genMuscleFitPair
reco::TrackRef globalTrack() const override
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon)
int theCompressionSettings_
std::string genParticlesName_
static double oldNormalization_
static std::vector< double > parBias
static scaleFunctionBase< std::vector< double > > * scaleFunctionForVec
static lorentzVector applyBias(const lorentzVector &muon, const int charge)
smearFunctionBase * smearFunctionService(const int identifier)
Service to build the smearing functor corresponding to the passed identifier.
void applyBias(reco::Particle::LorentzVector &mu, const int charge)
Apply the bias if needed using the function in MuScleFitUtils.
static std::vector< int > parCrossSectionFix
static std::vector< int > doBackgroundFit
static int counter_resprob
static std::vector< double > parScaleMin
bool muonID(const std::string &name) const
scaleFunctionBase< double * > * scaleFunctionService(const int identifier)
Service to build the scale functor corresponding to the passed identifier.
static std::vector< int > doScaleFit
void readTree(const int maxEvents, const TString &fileName, MuonPairVector *savedPair, const int muonType, std::vector< std::pair< unsigned int, unsigned long long > > *evtRun, MuonPairVector *genPair=nullptr)
static std::vector< double > parScaleStep
virtual void endOfFastLoop(const unsigned int iLoop)
Power< A, B >::type pow(const A &a, const B &b)
MuScleFitPlotter * plotter
static unsigned int loopCounter
std::map< std::string, Histograms * > mapHisto_
The map of histograms.
std::string inputRootTreeFileName_
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon)
bool checkDeltaR(reco::Particle::LorentzVector &genMu, reco::Particle::LorentzVector &recMu)
Check if two lorentzVector are near in deltaR.
static std::vector< double > parResolStep
static resolutionFunctionBase< double * > * resolutionFunction
virtual void duringFastLoop()
static std::vector< std::pair< lorentzVector, lorentzVector > > simPair
static BackgroundHandler * backgroundHandler
static void minimizeLikelihood()
static double maxMuonEtaSecondRange_
MuScleFit(const edm::ParameterSet &pset)
static std::vector< int > doResolFit
void writeHistoMap(const unsigned int iLoop)
Save the histograms map to file.
std::vector< std::string > triggerPath_
static double massProb(const double &mass, const double &rapidity, const int ires, const double &massResol)