115 #include <CLHEP/Vector/LorentzVector.h>
145 #include "HepPDT/defs.h"
146 #include "HepPDT/TableBuilder.hh"
147 #include "HepPDT/ParticleDataTable.hh"
149 #include "HepMC/GenParticle.h"
150 #include "HepMC/GenEvent.h"
166 #include "valgrind/callgrind.h"
307 std::vector<reco::LeafCandidate>
muons;
308 typename std::vector<T>::const_iterator track;
309 for( track = tracks.begin(); track != tracks.end(); ++track ) {
318 <<
": initial value Pt = " << mu.Pt() << std::endl;
326 muons.push_back (
muon);
338 tracks.push_back(*(muon->globalTrack()));
340 tracks.push_back(*(muon->outerTrack()));
342 tracks.push_back(*(muon->innerTrack()));
344 else if(
theMuonType_ == 10 && !(muon->isStandAloneMuon()) )
345 tracks.push_back(*(muon->innerTrack()));
347 tracks.push_back(*(muon->innerTrack()));
349 tracks.push_back(*(muon->innerTrack()));
362 if ((theMuonType_<-4 || theMuonType_>5) &&
theMuonType_<10) {
363 std::cout <<
"[MuScleFit]: Unknown muon type! Aborting." << std::endl;
407 int resolFitType = pset.
getParameter<
int>(
"ResolFitType");
488 if (MuScleFitUtils::SmearType>0) {
489 std::cout <<
"[MuScleFit-Constructor]: Generating random values for smearing" << std::endl;
490 TF1 G(
"G",
"[0]*exp(-0.5*pow(x,2))", -5., 5.);
492 G.SetParameter (0,norm);
493 for (
int i=0;
i<10000;
i++) {
494 for (
int j=0;
j<7;
j++) {
516 MuScleFitUtils::rapidityBinsForZ_ =
false;
541 MuScleFitUtils::resfind,
542 MuScleFitUtils::speedup, genParticlesName_,
543 compareToSimTracks_, simTracksCollection_,
544 MuScleFitUtils::sherpa_,
debug_));
547 pset.
getParameter<std::vector<double> >(
"LeftWindowBorder"),
548 pset.
getParameter<std::vector<double> >(
"RightWindowBorder"),
580 std::cout <<
"Saving muon pairs to root tree" << std::endl;
614 std::stringstream ss;
617 theFiles_.push_back (
new TFile(rootFileName.c_str(),
"RECREATE"));
619 if (
debug_>0)
std::cout <<
"[MuScleFit]: Root file created" << std::endl;
621 std::cout <<
"creating plotter" << std::endl;
636 if (
debug_>0)
std::cout <<
"[MuScleFit]: Starting loop # " << iLoop << std::endl;
663 unsigned int iFastLoop = 1;
680 std::cout <<
"Starting fast loop number " << iFastLoop << std::endl;
690 if(
iev%50000 == 0 ) {
691 std::cout <<
"Fast looping on event number " <<
iev << std::endl;
696 std::cout <<
"End of fast loop number " << iFastLoop <<
". Ran on " <<
iev <<
" events" << std::endl;
718 std::cout <<
"Ending loop # " << iLoop << std::endl;
728 TDirectory * likelihoodDir =
theFiles_[iLoop]->mkdir(
"likelihood");
749 bool isFired =
false;
754 isFired =triggerResults->accept();
756 std::cout<<
"Trigger "<<isFired<<std::endl;
766 for (
unsigned i=0;
i<triggerNames.
size();
i++) {
770 for (
unsigned int ipath=0; ipath<
triggerPath_.size(); ipath++ ) {
771 if ( hltName.find(
triggerPath_[ipath]) != std::string::npos ) {
772 unsigned int triggerIndex( hltConfig.
triggerIndex(hltName) );
775 if (triggerIndex < triggerResults->
size()) {
776 isFired = triggerResults->accept(triggerIndex);
790 CALLGRIND_START_INSTRUMENTATION;
795 <<
" Run: " <<
event.id().run() <<
" Event: " <<
event.id().event() << std::endl;
816 CALLGRIND_STOP_INSTRUMENTATION;
817 CALLGRIND_DUMP_STATS;
826 std::vector<reco::LeafCandidate>
muons;
832 std::pair<reco::Particle::LorentzVector, reco::Particle::LorentzVector> recMuFromBestRes =
837 std::cout <<std::setprecision(9)<<
"Pt after findbestrecores: " << (recMuFromBestRes.first).
Pt() <<
" "
838 << (recMuFromBestRes.second).
Pt() << std::endl;
842 recMu1 = recMuFromBestRes.first;
843 recMu2 = recMuFromBestRes.second;
859 event.
run(),
event.id().event()));
868 std::cout <<
"Reading muon pairs from Root Tree in " << treeFileName << std::endl;
870 std::vector<std::pair<int, int> > evtRun;
878 std::vector<std::pair<int, int> >::iterator evtRunIt = evtRun.begin();
880 std::vector<std::pair<lorentzVector,lorentzVector> >::iterator genIt;
887 double pt1 = it->first.pt();
889 double pt2 = it->second.pt();
891 double eta1 = it->first.eta();
893 double eta2 = it->second.eta();
896 bool dontPass =
false;
897 bool eta1InFirstRange;
898 bool eta2InFirstRange;
899 bool eta1InSecondRange;
900 bool eta2InSecondRange;
911 eta1InFirstRange && eta2InSecondRange ) ) {
924 ( ((eta1InFirstRange && !eta2InFirstRange) && (eta2InSecondRange && !eta1InSecondRange)) ||
925 ((eta2InFirstRange && !eta1InFirstRange) && (eta1InSecondRange && !eta2InSecondRange)) )) ) {
948 evtRunIt->second, evtRunIt->first));
975 if(
debug_>0 )
std::cout <<
"About to start lik par correction and histo filling; ResFound is "
988 <<
recMu1.Pt() <<
" Pt2 = " <<
recMu2.Pt() << std::endl;
1000 <<
recMu1.Pt() <<
" Pt2 = " <<
recMu2.Pt() << std::endl;
1014 mapHisto_[
"hRecBestRes"]->Fill(bestRecRes,+1, weight);
1015 mapHisto_[
"hRecBestResAllEvents"]->Fill(bestRecRes,+1, 1.);
1037 mapHisto_[
"hRecBestResVSRes"]->Fill (bestRecRes, bestRecRes, +1, weight);
1044 std::vector<double> * parval;
1045 std::vector<double> initpar;
1093 if(
debug_ > 0 )
std::cout <<
"mass = " << bestRecRes.mass() << std::endl;
1099 std::vector<double> initpar;
1127 if(
debug_ > 0 )
std::cout <<
"inside weight: mass = " << bestRecRes.mass() <<
", prob = " << prob << std::endl;
1129 if(
debug_ > 0 )
std::cout <<
"inside prob: mass = " << bestRecRes.mass() <<
", prob = " << prob << std::endl;
1138 if( recoMass != 0 ) {
1142 mapHisto_[
"hFunctionResolMassVSMu"]->Fill(
recMu1, massResol/recoMass, -1);
1143 mapHisto_[
"hFunctionResolMassVSMu"]->Fill(
recMu2, massResol/recoMass, +1);
1158 if( genMass != 0 ) {
1161 double diffMass = (recoMass - genMass)/genMass;
1164 double pt1 =
recMu1.pt();
1165 double eta1 =
recMu1.eta();
1166 double pt2 =
recMu2.pt();
1167 double eta2 =
recMu2.eta();
1169 if( diffMass == diffMass ) {
1171 mapHisto_[
"hDeltaMassOverGenMassVsPt"]->Fill(pt1, diffMass);
1172 mapHisto_[
"hDeltaMassOverGenMassVsPt"]->Fill(pt2, diffMass);
1173 mapHisto_[
"hDeltaMassOverGenMassVsEta"]->Fill(eta1, diffMass);
1174 mapHisto_[
"hDeltaMassOverGenMassVsEta"]->Fill(eta2, diffMass);
1176 mapHisto_[
"hMassResolutionVsPtEta"]->Fill(pt1, eta1, diffMass, diffMass);
1177 mapHisto_[
"hMassResolutionVsPtEta"]->Fill(pt2, eta2, diffMass, diffMass);
1180 std::cout <<
"Error, there is a nan: recoMass = " << recoMass <<
", genMass = " << genMass << std::endl;
1190 if(
debug_ > 0 )
std::cout <<
"mass = " << bestRecRes.mass() <<
", prob = " << prob << std::endl;
1193 mapHisto_[
"hMassProbVsRes"]->Fill(bestRecRes, bestRecRes, +1, prob);
1196 mapHisto_[
"hMassProbVsRes_fine"]->Fill(bestRecRes, bestRecRes, +1, prob);
1206 if (
debug_>0)
std::cout <<
"[MuScleFit]: filling the pair" << std::endl;
1219 ((recMu.Eta()-genMu.Eta()) * (recMu.Eta()-genMu.Eta())));
1223 std::cout<<
"Reco muon "<<recMu<<
" with eta "<<recMu.Eta()<<
" and phi "<<recMu.Phi()<<std::endl
1224 <<
" DOES NOT MATCH with generated muon from resonance: "<<std::endl
1225 <<genMu<<
" with eta "<<genMu.Eta()<<
" and phi "<<genMu.Phi()<<std::endl;
1235 mapHisto_[
"hResolTheta"+
name]->Fill(recMu, (-genMu.Theta()+recMu.Theta()), charge);
1238 mapHisto_[
"hResolEta"+
name]->Fill(recMu, (-genMu.Eta()+recMu.Eta()),charge);
1242 if( (genMu.Pt() != 0) && (recMu.Pt() != 0) ) {
1243 mapHisto_[
"hPtRecoVsPt"+inputName]->Fill(genMu.Pt(), recMu.Pt());
1252 <<
": after smearing Pt = " << mu.Pt() << std::endl;
1261 <<
": after bias Pt = " << mu.Pt() << std::endl;
1272 std::cout <<
"it must have as many values as the number of loops, which is = " <<
maxLoopNumber << std::endl;
1277 std::cout <<
"it must have as many values as the number of loops, which is = " <<
maxLoopNumber << std::endl;
1282 std::cout <<
"it must have as many values as the number of loops, which is = " <<
maxLoopNumber << std::endl;
1287 std::cout <<
"it must have as many values as the number of loops, which is = " <<
maxLoopNumber << std::endl;
1306 MuScleFitUtils::BiasType<0 || MuScleFitUtils::BiasType>13) {
1307 std::cout <<
"[MuScleFit-Constructor]: Wrong bias type or number of parameters: aborting!" << std::endl;
1319 MuScleFitUtils::SmearType<0 || MuScleFitUtils::SmearType>7) {
1320 std::cout <<
"[MuScleFit-Constructor]: Wrong smear type or number of parameters: aborting!" << std::endl;
1327 std::cout <<
"[MuScleFit-Constructor]: Mismatch in number of parameters for Resol: aborting!" << std::endl;
1332 std::cout <<
"[MuScleFit-Constructor]: Mismatch in number of parameters for Scale: aborting!" << std::endl;
1337 std::cout <<
"[MuScleFit-Constructor]: Mismatch in number of parameters for Bgr: aborting!" << std::endl;
1342 std::cout <<
"[MuScleFit-Constructor]: Mismatch in number of parameters for Bgr: aborting!" << std::endl;
1349 std::cout <<
"[MuScleFit-Constructor]: resfind must have 6 elements (1 Z, 3 Y, 2 Psi): aborting!" << std::endl;
1363 iTrack->found() > 11 &&
1364 gTrack->chi2()/gTrack->ndof() < 20.0 &&
1366 iTrack->chi2()/iTrack->ndof() < 4.0 &&
1367 aMuon->
muonID(
"TrackerMuonArbitrated") &&
1368 aMuon->
muonID(
"TMLastStationAngTight") &&
1370 fabs(iTrack->dxy()) < 3.0 &&
1371 fabs(iTrack->dz()) < 15.0 );
1381 iTrack->found() > 11 &&
1382 iTrack->chi2()/iTrack->ndof() < 4.0 &&
1383 aMuon->
muonID(
"TrackerMuonArbitrated") &&
1384 aMuon->
muonID(
"TMLastStationAngTight") &&
1386 fabs(iTrack->dxy()) < 3.0 &&
1387 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
void readTree(const int maxEvents, const TString &fileName, MuonPairVector *savedPair, const int muonType, std::vector< std::pair< int, int > > *evtRun, MuonPairVector *genPair=0)
static std::vector< int > doResolFit
T getParameter(std::string const &) const
scaleFunctionBase< double * > * scaleFunctionService(const int identifier)
Service to build the scale functor corresponding to the passed identifier.
T getUntrackedParameter(std::string const &, T const &) const
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.
reco::TrackRef innerTrack() const
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
static smearFunctionBase * smearFunction
static std::vector< int > parScaleOrder
edm::InputTag theMuonLabel_
static std::vector< int > doCrossSectionFit
double maxResMass_hwindow[6]
static void minimizeLikelihood()
static double maxMuonEtaSecondRange_
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
bool muonID(const std::string &name) const
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]
int pixelLayersWithMeasurement() const
static double massWindowHalfWidth[3][6]
#define DEFINE_FWK_LOOPER(type)
Run const & getRun() const
std::map< std::string, Histograms * > mapHisto_
The map of histograms.
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)
virtual void startingNewLoop(unsigned int iLoop) override
Strings::size_type size() const
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
Strings const & triggerNames() const
std::vector< reco::LeafCandidate > fillMuonCollection(const std::vector< T > &tracks)
std::vector< std::string > triggerPath_
static std::vector< int > parScaleFix
static bool computeMinosErrors_
reco::Particle::LorentzVector lorentzVector
static scaleFunctionBase< std::vector< double > > * scaleFunctionForVec
static std::vector< std::vector< double > > parvalue
unsigned int triggerIndex(const std::string &triggerName) const
slot position of trigger path in trigger table (0 to size-1)
MuonServiceProxy * theService
U second(std::pair< T, U > const &p)
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
double minResMass_hwindow[6]
static std::vector< double > parScaleMin
reco::Particle::LorentzVector recMu1
static lorentzVector applyBias(const lorentzVector &muon, const int charge)
static std::vector< double > parBgr
unsigned int maxLoopNumber
std::string genParticlesName_
Cos< T >::type cos(const T &t)
void clearHistoMap()
Clean the histograms map.
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
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
static std::vector< double > parSmear
void beginOfJobInConstructor()
smearFunctionBase * smearFunctionService(const int identifier)
Service to build the smearing functor corresponding to the passed identifier.
reco::TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) ...
static std::vector< int > parResolOrder
virtual void endOfJob() override
virtual edm::EDLooper::Status duringLoop(const edm::Event &event, const edm::EventSetup &eventSetup) override
double deltaR(double eta1, double eta2, double phi1, double phi2)
void writeTree(const TString &fileName, const std::vector< MuonPair > *savedPair, const int muonType=0, const std::vector< GenMuonPair > *genPair=0, const bool saveAll=false)
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 const & triggerName(unsigned int index) const
std::string theRootFileName_
void fillTreeGen(const std::vector< std::pair< reco::Particle::LorentzVector, reco::Particle::LorentzVector > > &genPairs)
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d'tor
static double deltaPhiMinCut_
std::string triggerResultsLabel_
static bool rapidityBinsForZ_
void fillHistoMap(TFile *outputFile, unsigned int iLoop)
Create the histograms map.
std::vector< TFile * > theFiles_
The files were the histograms are saved.
static bool separateRanges_
static double minMuonEtaSecondRange_
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.
std::auto_ptr< MuScleFitMuonSelector > muonSelector_
resolutionFunctionBase< double * > * resolutionFunctionService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier.
int maxEventsFromRootTree_
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)
static scaleFunctionBase< double * > * scaleFunction
int numberOfValidMuonHits() const
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_
tuple size
Write out results.
static std::pair< lorentzVector, lorentzVector > findBestRecoRes(const std::vector< reco::LeafCandidate > &muons)
Power< A, B >::type pow(const A &a, const B &b)
void applyBias(reco::Particle::LorentzVector &mu, const int charge)
Apply the bias if needed using the function in MuScleFitUtils.
static CrossSectionHandler * crossSectionHandler
virtual edm::EDLooper::Status endOfLoop(const edm::EventSetup &eventSetup, unsigned int iLoop) override
MuScleFitPlotter * plotter
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.
virtual void endOfFastLoop(const unsigned int iLoop)