6#include "GaudiKernel/PhysicalConstants.h"
20#include "RooRealVar.h"
21#include "RooDataHist.h"
23#include "RooBreitWigner.h"
24#include "RooCBShape.h"
25#include "RooFFTConvPdf.h"
26#include "RooGlobalFunc.h"
27#include "RooArgList.h"
28#include "RooFitResult.h"
89 m_varLabels[
"crtDiff"] =
"1/p_{T}(+) - 1/p_{T}(-) [GeV^{-1}]";
93 m_varRanges[
"phi"] = std::make_pair(-Gaudi::Units::pi,Gaudi::Units::pi);
94 m_varRanges[
"phiAll"] = std::make_pair(-Gaudi::Units::pi,Gaudi::Units::pi);
95 m_varRanges[
"phiPos"] = std::make_pair(-Gaudi::Units::pi,Gaudi::Units::pi);
96 m_varRanges[
"phiNeg"] = std::make_pair(-Gaudi::Units::pi,Gaudi::Units::pi);
105 m_varRanges[
"crtDiff"] = std::make_pair(-0.15,0.15);
111 m_varRanges[
"phiDiff"] = std::make_pair(0.,Gaudi::Units::pi);
113 m_varRanges[
"crtDiff"] = std::make_pair(-0.03,0.03);
127 return StatusCode::SUCCESS;
152 m_chi2 =
new TH1F(
"chi2",
"chi2",100,0.,10.);
156 m_stat =
new TH1F(
"statistics",
"Statistics",nCuts, 0.,
double(nCuts));
157 static const std::string binLabels[] ={
"MuonIdTrk",
"TrkIsoPt40/Pt<.2",
"CombMuon",
"MCPgoodTrk",
"MuPtOK",
"eta<2.5",
"OppChargePair",
"InvMassOK"};
158 for(
int ilabel=0;ilabel<nCuts;ilabel++){
159 m_stat->GetXaxis()->SetBinLabel(ilabel+1,binLabels[ilabel].c_str());
164 for (
const std::string& reg :
m_regions) {
168 m_varRanges[
"etaAll"] = std::make_pair(-1.05,1.05);
169 m_varRanges[
"etaPos"] = std::make_pair(-1.05,1.05);
170 m_varRanges[
"etaNeg"] = std::make_pair(-1.05,1.05);
171 }
else if (reg ==
"EAEA") {
175 }
else if (reg ==
"ECEC") {
176 m_varRanges[
"etaAll"] = std::make_pair(-2.5,-1.05);
177 m_varRanges[
"etaPos"] = std::make_pair(-2.5,-1.05);
178 m_varRanges[
"etaNeg"] = std::make_pair(-2.5,-1.05);
186 std::string hname =
m_resonName +
"_invmass_" + reg;
187 std::string htitle = hname +
"; Invmass[GeV/c^{2}]";
193 hname =
m_resonName +
"_2DinvmassVS" + varM +
"_" + reg;
194 htitle = hname +
";" +
m_varLabels[varM] +
";Invmass[GeV/c^{2}]";
198 hname =
m_resonName +
"_invmassVS" + varM +
"_" + reg;
199 htitle = hname +
";" +
m_varLabels[varM] +
";Invmass[GeV/c^{2}]";
208 hname =
m_resonName +
"_2DinvmassVS" + varW +
"_" + reg;
209 htitle = hname +
";" +
m_varLabels[varW] +
";Invmass[GeV/c^{2}]";
214 hname =
m_resonName +
"_widthVS" + varW +
"_" + reg;
215 htitle = hname +
";" +
m_varLabels[varW] +
";Width[GeV/c^{2}]";
225 if (varD ==
"eta" || varD ==
"etaAll" || varD ==
"etaPos" || varD ==
"etaNeg" ){
227 }
else if (varD ==
"pt" || varD ==
"ptAll" || varD ==
"ptPos" || varD ==
"ptNeg" ){
229 }
else if (varD ==
"phi" || varD ==
"phiAll" || varD ==
"phiPos" || varD ==
"phiNeg" ){
239 return StatusCode::SUCCESS;
251 return StatusCode::FAILURE;
252 }
else ATH_MSG_DEBUG(
"Muon container successfully retrieved.");
258 for(
const auto* muon : *muons ) {
259 const xAOD::TrackParticle *idTrk = muon->trackParticle(xAOD::Muon::TrackParticleType::InnerDetectorTrackParticle);
260 if (!idTrk)
continue;
261 m_stat->Fill(
"MuonIdTrk",1);
262 double idTrkPt(0),ptSum(0);
265 return StatusCode::FAILURE;
268 idTrkPt = idTrk->
pt();
272 m_stat->Fill(
"TrkIsoPt40/Pt<.2",1);
273 if (!muon->trackParticle(xAOD::Muon::TrackParticleType::CombinedTrackParticle))
continue;
274 m_stat->Fill(
"CombMuon",1);
277 m_stat->Fill(
"MCPgoodTrk",1);
279 if (idTrkPt <
m_ptCut*1000)
continue;
282 double idTrkEta = idTrk->
eta();
283 if (std::abs(idTrkEta)>2.5)
continue;
284 m_stat->Fill(
"eta<2.5",1);
290 int nMuons = goodMuons.size();
295 for (; mu1!=muEnd;++mu1){
296 const xAOD::TrackParticle *id1 = (*mu1)->trackParticle(xAOD::Muon::TrackParticleType::InnerDetectorTrackParticle);
298 for (; mu2!=muEnd; ++mu2){
299 const xAOD::TrackParticle *id2 = (*mu2)->trackParticle(xAOD::Muon::TrackParticleType::InnerDetectorTrackParticle);
301 double q1 = id1->
charge();
302 double q2 = id2->
charge();
303 if (q1*q2>0)
continue;
304 m_stat->Fill(
"OppChargePair",1);
313 double invmass =
getInvmass(id1,id2,muonMass);
314 if (invmass<m_minInvmass || invmass>
m_maxInvmass)
continue;
315 m_stat->Fill(
"InvMassOK",1);
319 double etaPos = idPos->
eta();
321 double etaNeg = idNeg->
eta();
324 double phiPos = idPos->
phi();
326 double phiNeg = idNeg->
phi();
329 double ptPos = idPos->
pt()/Gaudi::Units::GeV;
331 double ptNeg = idNeg->
pt()/Gaudi::Units::GeV;
336 double phiDiff = std::abs(phiPos - phiNeg);
337 if (phiDiff>Gaudi::Units::pi) phiDiff = 2*(Gaudi::Units::pi) - phiDiff;
343 std::string region =
"";
344 if ((std::abs(etaPos)<1.05 || std::abs(etaPos)==1.05) && (std::abs(etaNeg)<1.05 || std::abs(etaNeg)==1.05)) region=
"BB";
345 else if ((etaPos>1.05 && etaPos<2.5) && (etaNeg>1.05 && etaNeg<2.5)) region=
"EAEA";
346 else if ((etaPos<-1.05 && etaPos>-2.5) && (etaNeg<-1.05 && etaNeg>-2.5)) region=
"ECEC";
350 bool fillReg =
false;
354 if (!fillAll && !fillReg)
continue;
358 if (fillAll)
m_invmass[
"All"]->Fill(invmass);
359 if (fillReg)
m_invmass[region]->Fill(invmass);
363 std::map<std::string, TH2F*>* allVars =
nullptr;
370 for (
const std::pair<const std::string, TH2F*>& p : *allVars) {
371 if (p.first!=
"etaAll" && p.first!=
"phiAll" && p.first!=
"ptAll"){
374 }
else if (p.first==
"etaAll"){
383 }
else if (p.first==
"phiAll"){
392 }
else if (p.first==
"ptAll"){
407 if (varD!=
"etaAll" && varD!=
"phiAll" && varD!=
"ptAll"){
410 }
else if (varD==
"etaAll"){
412 m_xDistr[
"All"][
"etaAll"]->Fill(etaPos);
413 m_xDistr[
"All"][
"etaAll"]->Fill(etaNeg);
416 m_xDistr[region][
"etaAll"]->Fill(etaPos);
417 m_xDistr[region][
"etaAll"]->Fill(etaNeg);
419 }
else if (varD==
"phiAll"){
421 m_xDistr[
"All"][
"phiAll"]->Fill(phiPos);
422 m_xDistr[
"All"][
"phiAll"]->Fill(phiNeg);
425 m_xDistr[region][
"phiAll"]->Fill(phiPos);
426 m_xDistr[region][
"phiAll"]->Fill(phiNeg);
428 }
else if (varD==
"ptAll"){
430 m_xDistr[
"All"][
"ptAll"]->Fill(ptPos);
431 m_xDistr[
"All"][
"ptAll"]->Fill(ptNeg);
434 m_xDistr[region][
"ptAll"]->Fill(ptPos);
435 m_xDistr[region][
"ptAll"]->Fill(ptNeg);
444 return StatusCode::SUCCESS;
453 for (
const std::string& reg :
m_regions) {
454 for (
const std::pair<const std::string, TH2F*>& p :
m_2DinvmassVSx[reg]) {
456 std::vector<TH1F*> hout;
474 return StatusCode::SUCCESS;
480 std::string hname = hin->GetName();
482 TCanvas* ctemp =
new TCanvas(
"ctemp",
"ctemp",500,500);
484 hin->SetMarkerSize(1.2);
487 int nbins=hin->GetNbinsX();
488 for (
int i=0; i<nbins;i++){
489 std::ostringstream o; o<<i;
490 std::string projName = hname + o.str();
491 TH1D* htemp = (TH1D*) (hin->ProjectionY(projName.c_str(),i+1,i+1)->Clone());
492 htemp->SetTitle(projName.c_str());
494 if (htemp->GetEntries()>50){
495 double mean = 999., meanErr = 999., sigma = 999., sigmaErr = 999.,
chi2=0;
497 mean = htemp->GetMean();
498 sigma= htemp->GetRMS();
499 TF1* fn =
new TF1(
"fn",
"gaus",
mean-2*sigma,
mean+2*sigma);
500 fn->SetParameters(
float(htemp->GetEntries())/10.,
mean,sigma);
501 htemp->Fit(
"fn",
"RMLQN");
502 mean = fn->GetParameter(1);
503 sigma= fn->GetParameter(2);
504 fn->SetRange(
mean-1.2*sigma,
mean+1.2*sigma);
505 fn->SetParameters(
float(htemp->GetEntries())/10.,
mean,sigma);
508 htemp->Fit(
"fn",
"RML");
509 ctemp->Print(psName.c_str());
510 }
else htemp->Fit(
"fn",
"RMLQN");
511 double frange = 2.4*sigma;
512 double hrange = htemp->GetXaxis()->GetXmax()-htemp->GetXaxis()->GetXmin();
513 double ndf = frange/hrange*(htemp->GetNbinsX()) - 3;
514 chi2 = (fn->GetChisquare())/ndf;
516 mean = fn->GetParameter(1);
517 meanErr = fn->GetParError(1);
518 sigma = fn->GetParameter(2);
519 sigmaErr = fn->GetParError(2);
523 RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL);
524 RooRealVar m(
"mass",
"dimuon invariant mass", 91.2, 71., 111.,
"GeV");
525 RooDataHist *
data =
nullptr;
526 data =
new RooDataHist(
"data",
"data", m, htemp);
527 RooRealVar bwm0(
"bw_#mu",
"bw_#mu", 91.2, 85.2, 97.2) ;
528 RooRealVar bwsg(
"bw_#sigma",
"bw_#sigma", 2.4952) ;
529 RooBreitWigner bw(
"bw",
"bw", m, bwm0, bwsg);
531 RooRealVar cbm0(
"cb_#mu",
"cb_#mu", 0 ) ;
532 RooRealVar cbsg(
"cb_#sigma",
"cb_#sigma", 3., 1., 10.) ;
533 RooRealVar cbal(
"cb_#alpha",
"cb_#alpha", 2.0) ;
534 RooRealVar cbn(
"cb_n",
"cb_n", 1., 0.05, 3.) ;
535 RooCBShape cb(
"cb",
"cb", m, cbm0, cbsg, cbal, cbn);
538 RooFFTConvPdf bxc(
"bxc",
"BW (X) CB", m, bw, cb) ;
539 bxc.fitTo(*
data, RooFit::PrintLevel(-1), RooFit::PrintEvalErrors(-1));
540 RooPlot* frame = m.frame();
541 data->plotOn(frame, RooFit::MarkerSize(0.9));
542 bxc.paramOn(frame, RooFit::Format(
"NELU", RooFit::AutoPrecision(2)), RooFit::Layout(0.1,0.4,0.9));
543 bxc.plotOn (frame, RooFit::LineColor(kBlue));
546 ctemp->Print(psName.c_str());
548 mean = bwm0.getVal();
549 meanErr = bwm0.getError();
550 sigma = cbsg.getVal();
551 sigmaErr = cbsg.getError();
552 chi2 = frame->chiSquare();
558 hout.at(0)->SetBinContent(i+1,
mean);
559 hout.at(0)->SetBinError(i+1,meanErr);
560 hout.at(1)->SetBinContent(i+1,sigma);
561 hout.at(1)->SetBinError(i+1,sigmaErr);
563 hout.at(0)->SetBinContent(i+1,
mean);
564 hout.at(0)->SetBinError(i+1,meanErr);
566 hout.at(0)->SetBinContent(i+1,sigma);
567 hout.at(0)->SetBinError(i+1,sigmaErr);
575 if (hout.size()==2) hout.at(1)->Sumw2();
583 StatusCode
sc = mon.regHist(histo);
584 if (
sc.isFailure() ) {
603 if (nBLhits>0 || !(eBLhits)) countPass+=1;
604 if ((nhitsPIX+nPIXDS)>1) countPass+=1;
605 if ((nhitsSCT+nSCTDS)>5) countPass+=1;
606 if ((nPIXH+nSCTH)<3) countPass+=1;
609 int n = nTRTout + nTRThits;
610 if (std::abs(idTrk->
eta())<1.9){
611 if (n>5 && nTRTout<(0.9*n)) countPass+=1;
614 if (nTRTout<(0.9*n)) countPass+=1;
619 ATH_MSG_WARNING(
"Trying to check trackquality but no xAOD::TrackParticle available!");
626 TLorentzVector particle1,particle2,v;
627 particle1.SetPtEtaPhiE(id1->
pt(),id1->
eta(),id1->
phi(),sqrt(pow(Mass,2)+pow(id1->
p4().Px(),2)+pow(id1->
p4().Py(),2)+pow(id1->
p4().Pz(),2)));
628 particle2.SetPtEtaPhiE(id2->
pt(),id2->
eta(),id2->
phi(),sqrt(pow(Mass,2)+pow(id2->
p4().Px(),2)+pow(id2->
p4().Py(),2)+pow(id2->
p4().Pz(),2)));
629 v=particle1+particle2;
630 double invmass = v.Mag()/Gaudi::Units::GeV;
636 double px = id1->
p4().Px()+id2->
p4().Px();
637 double py = id1->
p4().Py()+id2->
p4().Py();
638 transmom=sqrt(px*px+py*py);
639 return transmom/Gaudi::Units::GeV;
644 double px=id1->
p4().Px()+id2->
p4().Px();
645 double py = id1->
p4().Py()+id2->
p4().Py();
646 double pz = id1->
p4().Pz()+id2->
p4().Pz();
647 double p=sqrt(px*px+py*py+pz*pz);
648 eta=0.5*log((p+pz)/(p-pz));
653 double px=id1->
p4().Px()+id2->
p4().Px();
654 double py = id1->
p4().Py()+id2->
p4().Py();
655 double p=sqrt(px*px+py*py);
656 double phi=acos(px/p);
662 double qoverpt1=id1->
charge()/id1->
pt();
663 double qoverpt2=id2->
charge()/id2->
pt();
665 asym=std::abs(qoverpt1)-std::abs(qoverpt2);
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
DataVector adapter that acts like it holds const pointers.
char data[hepevt_bytes_allocation_ATLAS]
A number of constexpr particle constants to avoid hardcoding them directly in various places.
Define macros for attributes used to control the static checker.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
static Environment_t environment()
Returns the running environment of the monitoring application to help ManagedMonitorToolBase objects ...
static DataType_t dataType()
Returns the data type that the monitoring application is running over to help ManagedMonitorToolBase ...
DataVector adapter that acts like it holds const pointers.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
iterator begin() noexcept
Return an iterator pointing at the beginning of the collection.
iterator end() noexcept
Return an iterator pointing past the end of the collection.
DataModel_detail::const_iterator< DataVector > const_iterator
std::map< std::string, std::map< std::string, TH2F * > > m_2DinvmassVSx
std::map< std::string, std::pair< double, double > > m_varRanges
std::map< std::string, double > m_varValues
std::map< std::string, std::map< std::string, TH1F * > > m_xDistr
std::map< std::string, std::map< std::string, TH1F * > > m_invmassVSx
void iterativeGausFit(TH2F *hin, const std::vector< TH1F * > &hout, int mode)
virtual StatusCode bookHistograms()
An inheriting class should either override this function or bookHists().
std::map< std::string, std::map< std::string, TH1F * > > m_widthVSx
virtual StatusCode initialize()
bool trackQuality(const xAOD::TrackParticle *idTrk)
std::map< std::string, TH1F * > m_invmass
double getCrtDiff(const xAOD::TrackParticle *id1, const xAOD::TrackParticle *id2) const
std::string m_triggerChainName
virtual StatusCode fillHistograms(const EventContext &ctx)
An inheriting class should either override this function or fillHists().
std::vector< std::string > m_varsVSwidth
virtual StatusCode procHistograms()
An inheriting class should either override this function or finalHists().
std::vector< std::string > m_regions
void RegisterHisto(MonGroup &mon, T *histo)
double getEta(const xAOD::TrackParticle *id1, const xAOD::TrackParticle *id2) const
double getPhi(const xAOD::TrackParticle *id1, const xAOD::TrackParticle *id2) const
SG::ReadHandleKey< xAOD::MuonContainer > m_muonCollection
DiMuMon(const std::string &type, const std::string &name, const IInterface *parent)
double getPt(const xAOD::TrackParticle *id1, const xAOD::TrackParticle *id2) const
double getInvmass(const xAOD::TrackParticle *track1, const xAOD::TrackParticle *track2, double Mass) const
std::vector< std::string > m_varsDistr
std::map< std::string, std::string > m_varLabels
std::vector< std::string > m_varsVSmean
virtual bool isValid() override final
Can the handle be successfully dereferenced?
virtual FourMom_t p4() const override final
The full 4-momentum of the particle.
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .).
bool summaryValue(uint8_t &value, const SummaryType &information) const
Accessor for TrackSummary values.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
float charge() const
Returns the charge.
double chi2(TH1 *h0, TH1 *h1)
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
std::string find(const std::string &s)
return a remapped string
constexpr double muonMassInMeV
the mass of the muon (in MeV)
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
TrackParticle_v1 TrackParticle
Reference the current persistent version:
@ expectInnermostPixelLayerHit
Do we expect a 0th-layer barrel hit for this track?
@ numberOfPixelHoles
number of pixel layers on track with absence of hits [unit8_t].
@ numberOfTRTHits
number of TRT hits [unit8_t].
@ numberOfSCTDeadSensors
number of dead SCT sensors crossed [unit8_t].
@ numberOfSCTHits
number of hits in SCT [unit8_t].
@ numberOfInnermostPixelLayerHits
these are the hits in the 0th pixel barrel layer
@ numberOfPixelHits
these are the pixel hits, including the b-layer [unit8_t].
@ numberOfTRTOutliers
number of TRT outliers [unit8_t].
@ numberOfPixelDeadSensors
number of dead pixel sensors crossed [unit8_t].
@ numberOfSCTHoles
number of SCT holes [unit8_t].