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"
91 m_varLabels[
"crtDiff"] =
"1/p_{T}(+) - 1/p_{T}(-) [GeV^{-1}]";
95 m_varRanges[
"phi"] = std::make_pair(-Gaudi::Units::pi,Gaudi::Units::pi);
96 m_varRanges[
"phiAll"] = std::make_pair(-Gaudi::Units::pi,Gaudi::Units::pi);
97 m_varRanges[
"phiPos"] = std::make_pair(-Gaudi::Units::pi,Gaudi::Units::pi);
98 m_varRanges[
"phiNeg"] = std::make_pair(-Gaudi::Units::pi,Gaudi::Units::pi);
107 m_varRanges[
"crtDiff"] = std::make_pair(-0.15,0.15);
113 m_varRanges[
"phiDiff"] = std::make_pair(0.,Gaudi::Units::pi);
115 m_varRanges[
"crtDiff"] = std::make_pair(-0.03,0.03);
129 return StatusCode::SUCCESS;
154 m_chi2 =
new TH1F(
"chi2",
"chi2",100,0.,10.);
158 m_stat =
new TH1F(
"statistics",
"Statistics",nCuts, 0.,
double(nCuts));
159 TString binLabels[] ={
"MuonIdTrk",
"TrkIsoPt40/Pt<.2",
"CombMuon",
"MCPgoodTrk",
"MuPtOK",
"eta<2.5",
"OppChargePair",
"InvMassOK"};
160 for(
int ilabel=0;ilabel<nCuts;ilabel++){
161 m_stat->GetXaxis()->SetBinLabel(ilabel+1,binLabels[ilabel]);
166 for (
const std::string& reg :
m_regions) {
170 m_varRanges[
"etaAll"] = std::make_pair(-1.05,1.05);
171 m_varRanges[
"etaPos"] = std::make_pair(-1.05,1.05);
172 m_varRanges[
"etaNeg"] = std::make_pair(-1.05,1.05);
173 }
else if (reg ==
"EAEA") {
177 }
else if (reg ==
"ECEC") {
178 m_varRanges[
"etaAll"] = std::make_pair(-2.5,-1.05);
179 m_varRanges[
"etaPos"] = std::make_pair(-2.5,-1.05);
180 m_varRanges[
"etaNeg"] = std::make_pair(-2.5,-1.05);
189 TString htitle = hname +
"; Invmass[GeV/c^{2}]";
195 hname =
m_resonName +
"_2DinvmassVS" + varM +
"_" + reg;
196 htitle = hname +
";" +
m_varLabels[varM] +
";Invmass[GeV/c^{2}]";
200 hname =
m_resonName +
"_invmassVS" + varM +
"_" + reg;
201 htitle = hname +
";" +
m_varLabels[varM] +
";Invmass[GeV/c^{2}]";
210 hname =
m_resonName +
"_2DinvmassVS" + varW +
"_" + reg;
211 htitle = hname +
";" +
m_varLabels[varW] +
";Invmass[GeV/c^{2}]";
216 hname =
m_resonName +
"_widthVS" + varW +
"_" + reg;
217 htitle = hname +
";" +
m_varLabels[varW] +
";Width[GeV/c^{2}]";
227 if (varD ==
"eta" || varD ==
"etaAll" || varD ==
"etaPos" || varD ==
"etaNeg" ){
229 }
else if (varD ==
"pt" || varD ==
"ptAll" || varD ==
"ptPos" || varD ==
"ptNeg" ){
231 }
else if (varD ==
"phi" || varD ==
"phiAll" || varD ==
"phiPos" || varD ==
"phiNeg" ){
241 return StatusCode::SUCCESS;
253 return StatusCode::FAILURE;
254 }
else ATH_MSG_DEBUG(
"Muon container successfully retrieved.");
260 for(
const auto* muon : *muons ) {
262 const xAOD::TrackParticle *idTrk = muon->trackParticle(xAOD::Muon::InnerDetectorTrackParticle);
263 if (!idTrk)
continue;
264 m_stat->Fill(
"MuonIdTrk",1);
265 double idTrkPt(0),ptSum(0);
268 return StatusCode::FAILURE;
271 idTrkPt = idTrk->
pt();
275 m_stat->Fill(
"TrkIsoPt40/Pt<.2",1);
276 if (!muon->trackParticle(xAOD::Muon::CombinedTrackParticle))
continue;
277 m_stat->Fill(
"CombMuon",1);
280 m_stat->Fill(
"MCPgoodTrk",1);
282 if (idTrkPt <
m_ptCut*1000)
continue;
285 double idTrkEta = idTrk->
eta();
286 if (std::abs(idTrkEta)>2.5)
continue;
287 m_stat->Fill(
"eta<2.5",1);
293 int nMuons = goodMuons.size();
298 for (; mu1!=muEnd;++mu1){
299 const xAOD::TrackParticle *id1 = (*mu1)->trackParticle(xAOD::Muon::InnerDetectorTrackParticle);
301 for (; mu2!=muEnd; ++mu2){
304 double q1 = id1->
charge();
305 double q2 =
id2->charge();
306 if (q1*q2>0)
continue;
307 m_stat->Fill(
"OppChargePair",1);
317 if (invmass<m_minInvmass || invmass>
m_maxInvmass)
continue;
318 m_stat->Fill(
"InvMassOK",1);
322 double etaPos = idPos->
eta();
324 double etaNeg = idNeg->
eta();
327 double phiPos = idPos->
phi();
329 double phiNeg = idNeg->
phi();
332 double ptPos = idPos->
pt()/Gaudi::Units::GeV;
334 double ptNeg = idNeg->
pt()/Gaudi::Units::GeV;
339 double phiDiff = std::abs(phiPos - phiNeg);
340 if (phiDiff>Gaudi::Units::pi) phiDiff = 2*(Gaudi::Units::pi) - phiDiff;
346 std::string region =
"";
347 if ((std::abs(etaPos)<1.05 || std::abs(etaPos)==1.05) && (std::abs(etaNeg)<1.05 || std::abs(etaNeg)==1.05)) region=
"BB";
348 else if ((etaPos>1.05 && etaPos<2.5) && (etaNeg>1.05 && etaNeg<2.5)) region=
"EAEA";
349 else if ((etaPos<-1.05 && etaPos>-2.5) && (etaNeg<-1.05 && etaNeg>-2.5)) region=
"ECEC";
353 bool fillReg =
false;
357 if (!fillAll && !fillReg)
continue;
361 if (fillAll)
m_invmass[
"All"]->Fill(invmass);
362 if (fillReg)
m_invmass[region]->Fill(invmass);
366 std::map<std::string, TH2F*>* allVars =
nullptr;
373 for (
const std::pair<const std::string, TH2F*>& p : *allVars) {
374 if (p.first!=
"etaAll" && p.first!=
"phiAll" && p.first!=
"ptAll"){
377 }
else if (p.first==
"etaAll"){
386 }
else if (p.first==
"phiAll"){
395 }
else if (p.first==
"ptAll"){
410 if (varD!=
"etaAll" && varD!=
"phiAll" && varD!=
"ptAll"){
413 }
else if (varD==
"etaAll"){
415 m_xDistr[
"All"][
"etaAll"]->Fill(etaPos);
416 m_xDistr[
"All"][
"etaAll"]->Fill(etaNeg);
419 m_xDistr[region][
"etaAll"]->Fill(etaPos);
420 m_xDistr[region][
"etaAll"]->Fill(etaNeg);
422 }
else if (varD==
"phiAll"){
424 m_xDistr[
"All"][
"phiAll"]->Fill(phiPos);
425 m_xDistr[
"All"][
"phiAll"]->Fill(phiNeg);
428 m_xDistr[region][
"phiAll"]->Fill(phiPos);
429 m_xDistr[region][
"phiAll"]->Fill(phiNeg);
431 }
else if (varD==
"ptAll"){
433 m_xDistr[
"All"][
"ptAll"]->Fill(ptPos);
434 m_xDistr[
"All"][
"ptAll"]->Fill(ptNeg);
437 m_xDistr[region][
"ptAll"]->Fill(ptPos);
438 m_xDistr[region][
"ptAll"]->Fill(ptNeg);
447 return StatusCode::SUCCESS;
456 for (
const std::string& reg :
m_regions) {
457 for (
const std::pair<const std::string, TH2F*>& p :
m_2DinvmassVSx[reg]) {
459 std::vector<TH1F*> hout;
477 return StatusCode::SUCCESS;
483 TString hname = hin->GetName();
485 TCanvas* ctemp =
new TCanvas(
"ctemp",
"ctemp",500,500);
487 hin->SetMarkerSize(1.2);
490 int nbins=hin->GetNbinsX();
491 for (
int i=0; i<nbins;i++){
492 std::ostringstream o; o<<i;
493 TString projName = hname + o.str();
494 TH1D* htemp = (TH1D*) (hin->ProjectionY(projName,i+1,i+1)->Clone());
495 htemp->SetTitle(projName);
497 if (htemp->GetEntries()>50){
498 double mean = 999., meanErr = 999., sigma = 999., sigmaErr = 999.,
chi2=0;
500 mean = htemp->GetMean();
501 sigma= htemp->GetRMS();
502 TF1* fn =
new TF1(
"fn",
"gaus",
mean-2*sigma,
mean+2*sigma);
503 fn->SetParameters(
float(htemp->GetEntries())/10.,
mean,sigma);
504 htemp->Fit(
"fn",
"RMLQN");
505 mean = fn->GetParameter(1);
506 sigma= fn->GetParameter(2);
507 fn->SetRange(
mean-1.2*sigma,
mean+1.2*sigma);
508 fn->SetParameters(
float(htemp->GetEntries())/10.,
mean,sigma);
511 htemp->Fit(
"fn",
"RML");
512 ctemp->Print(psName);
513 }
else htemp->Fit(
"fn",
"RMLQN");
514 double frange = 2.4*sigma;
515 double hrange = htemp->GetXaxis()->GetXmax()-htemp->GetXaxis()->GetXmin();
516 double ndf = frange/hrange*(htemp->GetNbinsX()) - 3;
517 chi2 = (fn->GetChisquare())/ndf;
519 mean = fn->GetParameter(1);
520 meanErr = fn->GetParError(1);
521 sigma = fn->GetParameter(2);
522 sigmaErr = fn->GetParError(2);
526 RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL);
527 RooRealVar m(
"mass",
"dimuon invariant mass", 91.2, 71., 111.,
"GeV");
528 RooDataHist *
data =
nullptr;
529 data =
new RooDataHist(
"data",
"data", m, htemp);
530 RooRealVar bwm0(
"bw_#mu",
"bw_#mu", 91.2, 85.2, 97.2) ;
531 RooRealVar bwsg(
"bw_#sigma",
"bw_#sigma", 2.4952) ;
532 RooBreitWigner bw(
"bw",
"bw", m, bwm0, bwsg);
534 RooRealVar cbm0(
"cb_#mu",
"cb_#mu", 0 ) ;
535 RooRealVar cbsg(
"cb_#sigma",
"cb_#sigma", 3., 1., 10.) ;
536 RooRealVar cbal(
"cb_#alpha",
"cb_#alpha", 2.0) ;
537 RooRealVar cbn(
"cb_n",
"cb_n", 1., 0.05, 3.) ;
538 RooCBShape cb(
"cb",
"cb", m, cbm0, cbsg, cbal, cbn);
541 RooFFTConvPdf bxc(
"bxc",
"BW (X) CB", m, bw, cb) ;
542 bxc.fitTo(*
data, RooFit::PrintLevel(-1), RooFit::PrintEvalErrors(-1));
543 RooPlot* frame = m.frame();
544 data->plotOn(frame, RooFit::MarkerSize(0.9));
545 bxc.paramOn(frame, RooFit::Format(
"NELU", RooFit::AutoPrecision(2)), RooFit::Layout(0.1,0.4,0.9));
546 bxc.plotOn (frame, RooFit::LineColor(kBlue));
549 ctemp->Print(psName);
551 mean = bwm0.getVal();
552 meanErr = bwm0.getError();
553 sigma = cbsg.getVal();
554 sigmaErr = cbsg.getError();
555 chi2 = frame->chiSquare();
561 hout.at(0)->SetBinContent(i+1,
mean);
562 hout.at(0)->SetBinError(i+1,meanErr);
563 hout.at(1)->SetBinContent(i+1,sigma);
564 hout.at(1)->SetBinError(i+1,sigmaErr);
566 hout.at(0)->SetBinContent(i+1,
mean);
567 hout.at(0)->SetBinError(i+1,meanErr);
569 hout.at(0)->SetBinContent(i+1,sigma);
570 hout.at(0)->SetBinError(i+1,sigmaErr);
578 if (hout.size()==2) hout.at(1)->Sumw2();
586 StatusCode
sc = mon.regHist(histo);
587 if (
sc.isFailure() ) {
606 if (nBLhits>0 || !(eBLhits)) countPass+=1;
607 if ((nhitsPIX+nPIXDS)>1) countPass+=1;
608 if ((nhitsSCT+nSCTDS)>5) countPass+=1;
609 if ((nPIXH+nSCTH)<3) countPass+=1;
612 int n = nTRTout + nTRThits;
613 if (std::abs(idTrk->
eta())<1.9){
614 if (n>5 && nTRTout<(0.9*n)) countPass+=1;
617 if (nTRTout<(0.9*n)) countPass+=1;
622 ATH_MSG_WARNING(
"Trying to check trackquality but no xAOD::TrackParticle available!");
629 TLorentzVector particle1,particle2,v;
630 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)));
632 v=particle1+particle2;
633 double invmass = v.Mag()/Gaudi::Units::GeV;
639 double px = id1->
p4().Px()+
id2->p4().Px();
640 double py = id1->
p4().Py()+
id2->p4().Py();
641 transmom=sqrt(px*px+py*py);
642 return transmom/Gaudi::Units::GeV;
647 double px=id1->
p4().Px()+
id2->p4().Px();
648 double py = id1->
p4().Py()+
id2->p4().Py();
649 double pz = id1->
p4().Pz()+
id2->p4().Pz();
650 double p=sqrt(px*px+py*py+pz*pz);
651 eta=0.5*log((p+pz)/(p-pz));
656 double px=id1->
p4().Px()+
id2->p4().Px();
657 double py = id1->
p4().Py()+
id2->p4().Py();
658 double p=sqrt(px*px+py*py);
659 double phi=acos(px/p);
665 double qoverpt1=id1->
charge()/id1->
pt();
666 double qoverpt2=
id2->charge()/
id2->pt();
668 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.
constexpr int pow(int base, int exp) noexcept
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
std::vector< std::string > m_varsVSwidth
virtual StatusCode fillHistograms()
An inheriting class should either override this function or fillHists().
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].