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>
320 template <
typename T>
322 std::vector<MuScleFitMuon>
muons;
323 typename std::vector<T>::const_iterator
track;
340 Double_t hitsTk =
track->innerTrack()->hitPattern().numberOfValidTrackerHits();
341 Double_t hitsMuon =
track->innerTrack()->hitPattern().numberOfValidMuonHits();
342 Double_t ptError =
track->innerTrack()->ptError();
345 std::cout <<
"[MuScleFit::fillMuonCollection]" << std::endl;
356 template <
typename T>
381 std::cout <<
"[MuScleFit]: Constructor" << std::endl;
383 if ((theMuonType_ < -4 || theMuonType_ > 5) &&
theMuonType_ < 10) {
384 std::cout <<
"[MuScleFit]: Unknown muon type! Aborting." << std::endl;
408 fastLoop =
pset.getUntrackedParameter<
bool>(
"FastLoop",
true);
418 int biasType =
pset.getParameter<
int>(
"BiasType");
422 int smearType =
pset.getParameter<
int>(
"SmearType");
428 int resolFitType =
pset.getParameter<
int>(
"ResolFitType");
432 int scaleType =
pset.getParameter<
int>(
"ScaleFitType");
443 pset.getUntrackedParameter<std::vector<double> >(
"parResolStep", std::vector<double>());
448 pset.getUntrackedParameter<std::vector<double> >(
"parScaleStep", std::vector<double>());
479 triggerPath_ =
pset.getUntrackedParameter<std::vector<std::string> >(
"TriggerPath");
492 PATmuons_ =
pset.getUntrackedParameter<
bool>(
"PATmuons",
false);
525 std::cout <<
"[MuScleFit-Constructor]: Generating random values for smearing" << std::endl;
526 TF1
G(
"G",
"[0]*exp(-0.5*pow(x,2))", -5., 5.);
528 G.SetParameter(0, norm);
529 for (
int i = 0;
i < 10000;
i++) {
530 for (
int j = 0;
j < 7;
j++) {
590 pset.getParameter<std::vector<double> >(
"LeftWindowBorder"),
591 pset.getParameter<std::vector<double> >(
"RightWindowBorder"),
602 pset.getUntrackedParameter<
bool>(
"NormalizeLikelihoodByEventNumber",
true);
604 std::cout <<
"End of MuScleFit constructor" << std::endl;
621 std::cout <<
"[MuScleFit]: Destructor" << std::endl;
627 std::cout <<
"Saving muon pairs to root tree" << std::endl;
632 std::vector<MuonPair>::const_iterator it =
muonPairs_.begin();
633 std::cout <<
"[MuScleFit::~MuScleFit] (Destructor)" << std::endl;
635 std::cout <<
" Debugging pairs that are going to be written to file" << std::endl;
636 std::cout <<
" muon1 = " << it->mu1 << std::endl;
637 std::cout <<
" muon2 = " << it->mu2 << std::endl;
660 std::cout <<
"[MuScleFit]: beginOfJob" << std::endl;
667 std::cout <<
"[MuScleFit]: beginOfJob" << std::endl;
672 std::stringstream
ss;
682 std::cout <<
"[MuScleFit]: Root file created" << std::endl;
684 std::cout <<
"creating plotter" << std::endl;
693 std::cout <<
"[MuScleFit]: endOfJob" << std::endl;
700 std::cout <<
"[MuScleFit]: Starting loop # " << iLoop << std::endl;
726 unsigned int iFastLoop = 1;
741 std::cout <<
"Starting fast loop number " << iFastLoop << std::endl;
751 if (
iev % 50000 == 0) {
752 std::cout <<
"Fast looping on event number " <<
iev << std::endl;
757 std::cout <<
"End of fast loop number " << iFastLoop <<
". Ran on " <<
iev <<
" events" << std::endl;
778 std::cout <<
"Ending loop # " << iLoop << std::endl;
788 TDirectory* likelihoodDir =
theFiles_[iLoop]->mkdir(
"likelihood");
806 bool isFired =
false;
813 std::cout <<
"Trigger " << isFired << std::endl;
825 for (
unsigned int ipath = 0; ipath <
triggerPath_.size(); ipath++) {
826 if (hltName.find(
triggerPath_[ipath]) != std::string::npos) {
827 unsigned int triggerIndex(
hltConfig.triggerIndex(hltName));
830 if (triggerIndex < triggerResults->
size()) {
846 CALLGRIND_START_INSTRUMENTATION;
850 std::cout <<
"[MuScleFit-duringLoop]: loopCounter = " <<
loopCounter <<
" Run: " <<
event.id().run()
851 <<
" Event: " <<
event.id().event() << std::endl;
862 std::cout <<
"Reading from edm event" << std::endl;
872 CALLGRIND_STOP_INSTRUMENTATION;
873 CALLGRIND_DUMP_STATS;
881 std::vector<MuScleFitMuon>
muons;
886 std::cout <<
"[MuScleFit::selectMuons] Debugging muons collections after call to muonSelector_->selectMuons" 889 for (std::vector<MuScleFitMuon>::const_iterator it =
muons.begin(); it <
muons.end(); ++it) {
890 std::cout <<
" - muon n. " << iMu <<
" = " << (*it) << std::endl;
901 std::cout << std::setprecision(9) <<
"Pt after findbestrecores: " << (recMuFromBestRes.first).Pt() <<
" " 902 << (recMuFromBestRes.second).Pt() << std::endl;
906 recMu1 = recMuFromBestRes.first.p4();
907 recMu2 = recMuFromBestRes.second.p4();
929 Int_t the_numPUvtx(0);
930 Float_t the_TrueNumInteractions(0);
936 std::vector<PileupSummaryInfo>::const_iterator PVI;
937 for (PVI = puInfo->begin(); PVI != puInfo->end(); ++PVI) {
938 int BX = PVI->getBunchCrossing();
940 the_TrueNumInteractions = PVI->getTrueNumInteractions();
941 the_numPUvtx = PVI->getPU_NumInteractions();
948 std::vector<reco::Vertex>::const_iterator itv;
954 if (fabs(itv->z()) > 50.0)
956 if (fabs(itv->position().rho()) > 2.0)
964 double the_genEvtweight = 1.;
966 the_genEvtweight = genEvtInfo->
weight();
973 event.run(),
event.id().event(), the_genEvtweight, the_numPUvtx, the_TrueNumInteractions, the_NVtx)));
981 std::cout <<
"Reading muon pairs from Root Tree in " << treeFileName << std::endl;
983 std::vector<std::pair<unsigned int, unsigned long long> > evtRun;
996 std::vector<std::pair<unsigned int, unsigned long long> >::iterator evtRunIt = evtRun.begin();
998 std::vector<std::pair<MuScleFitMuon, MuScleFitMuon> >::iterator genIt;
1005 double pt1 = it->first.pt();
1007 double pt2 = it->second.pt();
1009 double eta1 = it->first.eta();
1011 double eta2 = it->second.eta();
1014 bool dontPass =
false;
1015 bool eta1InFirstRange;
1016 bool eta2InFirstRange;
1017 bool eta1InSecondRange;
1018 bool eta2InSecondRange;
1020 int ch1 = it->first.charge();
1021 int ch2 = it->second.charge();
1034 ((eta1InFirstRange && eta2InSecondRange && ch1 >= ch2) ||
1035 (eta1InSecondRange && eta2InFirstRange && ch1 < ch2))))
1046 (((eta1InFirstRange && !eta2InFirstRange) && (eta2InSecondRange && !eta1InSecondRange) && ch1 >= ch2) ||
1047 ((eta2InFirstRange && !eta1InFirstRange) && (eta1InSecondRange && !eta2InSecondRange) && ch1 < ch2))))
1081 (*evtRunIt).first, (*evtRunIt).second, 0, 0, 0, 0))
1126 <<
" Pt2 = " <<
recMu2.Pt() << std::endl;
1138 <<
" Pt2 = " <<
recMu2.Pt() << std::endl;
1153 mapHisto_[
"hRecBestResAllEvents"]->Fill(bestRecRes, +1, 1.);
1175 mapHisto_[
"hRecBestResVSRes"]->Fill(bestRecRes, bestRecRes, +1,
weight);
1177 std::vector<double>* parval;
1178 std::vector<double> initpar;
1218 mapHisto_[
"hFunctionResolCotgTheta"]->Fill(
1224 mapHisto_[
"hFunctionResolCotgTheta"]->Fill(
1232 std::cout <<
"mass = " << bestRecRes.mass() << std::endl;
1238 std::vector<double> initpar;
1258 bestRecRes.Rapidity(),
1270 bestRecRes.Rapidity(),
1278 std::cout <<
"inside weight: mass = " << bestRecRes.mass() <<
", prob = " <<
prob << std::endl;
1281 std::cout <<
"inside prob: mass = " << bestRecRes.mass() <<
", prob = " <<
prob << std::endl;
1290 if (recoMass != 0) {
1294 mapHisto_[
"hFunctionResolMassVSMu"]->Fill(
recMu1, massResol / recoMass, -1);
1295 mapHisto_[
"hFunctionResolMassVSMu"]->Fill(
recMu2, massResol / recoMass, +1);
1317 double diffMass = (recoMass - genMass) / genMass;
1325 if (diffMass == diffMass) {
1327 mapHisto_[
"hDeltaMassOverGenMassVsPt"]->Fill(
pt1, diffMass);
1328 mapHisto_[
"hDeltaMassOverGenMassVsPt"]->Fill(
pt2, diffMass);
1329 mapHisto_[
"hDeltaMassOverGenMassVsEta"]->Fill(
eta1, diffMass);
1330 mapHisto_[
"hDeltaMassOverGenMassVsEta"]->Fill(
eta2, diffMass);
1335 std::cout <<
"Error, there is a nan: recoMass = " << recoMass <<
", genMass = " << genMass << std::endl;
1346 std::cout <<
"mass = " << bestRecRes.mass() <<
", prob = " <<
prob << std::endl;
1349 mapHisto_[
"hMassProbVsRes"]->Fill(bestRecRes, bestRecRes, +1,
prob);
1352 mapHisto_[
"hMassProbVsRes_fine"]->Fill(bestRecRes, bestRecRes, +1,
prob);
1363 std::cout <<
"[MuScleFit]: filling the pair" << std::endl;
1377 ((recMu.Eta() - genMu.Eta()) * (recMu.Eta() - genMu.Eta())));
1381 std::cout <<
"Reco muon " << recMu <<
" with eta " << recMu.Eta() <<
" and phi " << recMu.Phi() << std::endl
1382 <<
" DOES NOT MATCH with generated muon from resonance: " << std::endl
1383 << genMu <<
" with eta " << genMu.Eta() <<
" and phi " << genMu.Phi() << std::endl;
1393 mapHisto_[
"hResolPt" +
name]->Fill(recMu, (-genMu.Pt() + recMu.Pt()) / genMu.Pt(),
charge);
1396 recMu, (-
cos(genMu.Theta()) /
sin(genMu.Theta()) +
cos(recMu.Theta()) /
sin(recMu.Theta())),
charge);
1401 if ((genMu.Pt() != 0) && (recMu.Pt() != 0)) {
1402 mapHisto_[
"hPtRecoVsPt" + inputName]->Fill(genMu.Pt(), recMu.Pt());
1427 std::cout <<
"[MuScleFit-Constructor]: wrong size of resolution fits selector = " 1429 std::cout <<
"it must have as many values as the number of loops, which is = " <<
maxLoopNumber << std::endl;
1435 std::cout <<
"it must have as many values as the number of loops, which is = " <<
maxLoopNumber << std::endl;
1439 std::cout <<
"[MuScleFit-Constructor]: wrong size of cross section fits selector = " 1441 std::cout <<
"it must have as many values as the number of loops, which is = " <<
maxLoopNumber << std::endl;
1445 std::cout <<
"[MuScleFit-Constructor]: wrong size of background fits selector = " 1447 std::cout <<
"it must have as many values as the number of loops, which is = " <<
maxLoopNumber << std::endl;
1473 std::cout <<
"[MuScleFit-Constructor]: Wrong bias type or number of parameters: aborting!" << std::endl;
1486 std::cout <<
"[MuScleFit-Constructor]: Wrong smear type or number of parameters: aborting!" << std::endl;
1493 std::cout <<
"[MuScleFit-Constructor]: Mismatch in number of parameters for Resol: aborting!" << std::endl;
1498 std::cout <<
"[MuScleFit-Constructor]: Mismatch in number of parameters for Scale: aborting!" << std::endl;
1503 std::cout <<
"[MuScleFit-Constructor]: Mismatch in number of parameters for Bgr: aborting!" << std::endl;
1508 std::cout <<
"[MuScleFit-Constructor]: Mismatch in number of parameters for Bgr: aborting!" << std::endl;
1515 std::cout <<
"[MuScleFit-Constructor]: resfind must have 6 elements (1 Z, 3 Y, 2 Psi): aborting!" << std::endl;
1528 iTrack->found() > 11 && gTrack->chi2() / gTrack->ndof() < 20.0 &&
q.numberOfValidMuonHits() > 0 &&
1529 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);
1540 iTrack->found() > 11 && iTrack->chi2() / iTrack->ndof() < 4.0 && aMuon->
muonID(
"TrackerMuonArbitrated") &&
1541 aMuon->
muonID(
"TMLastStationAngTight") &&
p.pixelLayersWithMeasurement() > 1 &&
1542 fabs(iTrack->dxy()) < 3.0 &&
1543 fabs(iTrack->dz()) < 15.0);
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::vector< std::pair< lorentzVector, lorentzVector > > simPair
static std::vector< int > doScaleFit
static std::vector< int > doResolFit
static std::vector< double > parBias
void selectMuons(const edm::Event &event)
static std::vector< int > parCrossSectionOrder
std::vector< GenMuonPair > genMuonPairs_
Stores the genMuon pairs and the motherId prior to the creation of the internal tree.
static smearFunctionBase * smearFunction
static std::vector< int > parScaleOrder
edm::InputTag theMuonLabel_
static std::vector< int > doCrossSectionFit
static void minimizeLikelihood()
static double maxMuonEtaSecondRange_
std::vector< MuScleFitMuon > fillMuonCollection(const std::vector< T > &tracks)
static std::vector< int > parBgrOrder
bool selGlobalMuon(const pat::Muon *aMuon)
Function for onia selections.
static unsigned int loopCounter
static double deltaPhiMaxCut_
static std::vector< double > parResolMax
static std::vector< std::pair< MuScleFitMuon, MuScleFitMuon > > SavedPairMuScleFitMuons
static std::vector< std::pair< MuScleFitMuon, MuScleFitMuon > > genMuscleFitPair
static bool startWithSimplex_
std::string triggerResultsProcess_
static std::vector< int > doBackgroundFit
static std::vector< double > parResol
static bool debugMassResol_
virtual void duringFastLoop()
Sin< T >::type sin(const T &t)
static BackgroundHandler * backgroundHandler
static double x[7][10000]
static double massWindowHalfWidth[3][6]
#define DEFINE_FWK_LOOPER(type)
std::map< std::string, Histograms * > mapHisto_
The map of histograms.
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)
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 scaleFunctionBase< std::vector< double > > * biasFunction
bool selTrackerMuon(const pat::Muon *aMuon)
void startingNewLoop(unsigned int iLoop) override
static std::vector< int > parBgrFix
static std::vector< double > parResolMin
static bool minimumShapePlots_
edm::InputTag simTracksCollection_
static int MuonTypeForCheckMassWindow
static double minMuonEtaFirstRange_
static double massProb(const double &mass, const double &rapidity, const int ires, const double &massResol)
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 struct MuScleFitUtils::massResolComponentsStruct massResolComponents
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
std::vector< std::string > triggerPath_
static std::vector< int > parScaleFix
static bool computeMinosErrors_
MuScleFitMuon recMuScleMu1
reco::Particle::LorentzVector lorentzVector
static scaleFunctionBase< std::vector< double > > * scaleFunctionForVec
static std::vector< std::vector< double > > parvalue
resolutionFunctionBase< double * > * resolutionFunctionService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier.
U second(std::pair< T, U > const &p)
void writeTree(const TString &fileName, const std::vector< MuonPair > *savedPair, const int muonType=0, const std::vector< GenMuonPair > *genPair=nullptr, const bool saveAll=false)
int theCompressionSettings_
static std::pair< MuScleFitMuon, MuScleFitMuon > findBestRecoRes(const std::vector< MuScleFitMuon > &muons)
static std::vector< std::pair< lorentzVector, lorentzVector > > genPair
std::string outputRootTreeFileName_
std::string theGenInfoRootFileName_
resolutionFunctionBase< std::vector< double > > * resolutionFunctionVecService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier when receiving a std::...
static double massResolution(const lorentzVector &mu1, const lorentzVector &mu2)
reco::Particle::LorentzVector recMu2
static std::vector< double > parScaleMin
std::vector< double > vec1
reco::Particle::LorentzVector recMu1
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
static lorentzVector applyBias(const lorentzVector &muon, const int charge)
static std::vector< double > parBgr
unsigned int maxLoopNumber
MuonServiceProxy * theService
std::string genParticlesName_
Cos< T >::type cos(const T &t)
edm::EDGetTokenT< std::vector< PileupSummaryInfo > > puInfoToken_
scaleFunctionBase< double * > * scaleFunctionService(const int identifier)
Service to build the scale functor corresponding to the passed identifier.
void clearHistoMap()
Clean the histograms map.
MuScleFitMuon recMuScleMu2
static double computeWeight(const double &mass, const int iev, const bool doUseBkgrWindow=false)
static std::vector< double > parScaleStep
static std::vector< std::pair< lorentzVector, lorentzVector > > SavedPair
MuScleFit(const edm::ParameterSet &pset)
static std::string const triggerResults
static lorentzVector applyScale(const lorentzVector &muon, const std::vector< double > &parval, const int charge)
static std::vector< int > parResolFix
static std::vector< double > parSmear
void beginOfJobInConstructor()
smearFunctionBase * smearFunctionService(const int identifier)
Service to build the smearing functor corresponding to the passed identifier.
edm::EDGetTokenT< GenEventInfoProduct > genEvtInfoToken_
static std::vector< int > parResolOrder
edm::EDLooper::Status duringLoop(const edm::Event &event, const edm::EventSetup &eventSetup) override
static std::vector< double > parScaleMax
scaleFunctionBase< std::vector< double > > * scaleFunctionVecService(const int identifier)
Service to build the scale functor corresponding to the passed identifier when receiving a std::vecto...
void writeHistoMap(const unsigned int iLoop)
Save the histograms map to file.
static std::vector< double > parScale
static double oldNormalization_
void applySmearing(reco::Particle::LorentzVector &mu)
Apply the smearing if needed using the function in MuScleFitUtils.
std::string theRootFileName_
void fillTreeGen(const std::vector< std::pair< reco::Particle::LorentzVector, reco::Particle::LorentzVector > > &genPairs)
static double deltaPhiMinCut_
std::string triggerResultsLabel_
static bool rapidityBinsForZ_
MuScleFitPlotter * plotter
void fillHistoMap(TFile *outputFile, unsigned int iLoop)
Create the histograms map.
std::vector< TFile * > theFiles_
The files were the histograms are saved.
double minResMass_hwindow[6]
reco::TrackRef globalTrack() const override
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) ...
static bool separateRanges_
static double minMuonEtaSecondRange_
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
static std::vector< double > parCrossSection
static lorentzVector applySmearing(const lorentzVector &muon)
static bool normalizeLikelihoodByEventNumber_
std::string inputRootTreeFileName_
bool checkDeltaR(reco::Particle::LorentzVector &genMu, reco::Particle::LorentzVector &recMu)
Check if two lorentzVector are near in deltaR.
int maxEventsFromRootTree_
double maxResMass_hwindow[6]
std::vector< MuonPair > muonPairs_
Used to store the muon pairs plus run and event number prior to the creation of the internal tree...
static double deltaPhi(const double &phi1, const double &phi2)
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
static scaleFunctionBase< double * > * scaleFunction
static bool useProbsFile_
static std::vector< int > resfind
void readProbabilityDistributionsFromFile()
Read probability distributions from a local root file.
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 int counter_resprob
static resolutionFunctionBase< std::vector< double > > * resolutionFunctionForVec
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Analysis-level muon class.
static double maxMuonEtaFirstRange_
std::unique_ptr< MuScleFitMuonSelector > muonSelector_
void applyBias(reco::Particle::LorentzVector &mu, const int charge)
Apply the bias if needed using the function in MuScleFitUtils.
static CrossSectionHandler * crossSectionHandler
edm::EDLooper::Status endOfLoop(const edm::EventSetup &eventSetup, unsigned int iLoop) override
static std::vector< double > parResolStep
static std::vector< int > parCrossSectionFix
static resolutionFunctionBase< double * > * resolutionFunction
void addParameters(std::vector< double > &initpar)
Inputs the vars in a vector.
bool muonID(const std::string &name) const
virtual void endOfFastLoop(const unsigned int iLoop)