6#include "GaudiKernel/PhysicalConstants.h"
18#include "RooRealVar.h"
19#include "RooDataHist.h"
21#include "RooBreitWigner.h"
22#include "RooCBShape.h"
23#include "RooFFTConvPdf.h"
24#include "RooGlobalFunc.h"
25#include "RooArgList.h"
26#include "RooFitResult.h"
86 m_varLabels[
"crtDiff"] =
"1/p_{T}(+) - 1/p_{T}(-) [GeV^{-1}]";
90 m_varRanges[
"phi"] = std::make_pair(-Gaudi::Units::pi,Gaudi::Units::pi);
91 m_varRanges[
"phiAll"] = std::make_pair(-Gaudi::Units::pi,Gaudi::Units::pi);
92 m_varRanges[
"phiPos"] = std::make_pair(-Gaudi::Units::pi,Gaudi::Units::pi);
93 m_varRanges[
"phiNeg"] = std::make_pair(-Gaudi::Units::pi,Gaudi::Units::pi);
102 m_varRanges[
"crtDiff"] = std::make_pair(-0.15,0.15);
108 m_varRanges[
"phiDiff"] = std::make_pair(0.,Gaudi::Units::pi);
110 m_varRanges[
"crtDiff"] = std::make_pair(-0.03,0.03);
124 return StatusCode::SUCCESS;
149 m_chi2 =
new TH1F(
"chi2",
"chi2",100,0.,10.);
153 m_stat =
new TH1F(
"statistics",
"Statistics",nCuts, 0.,
double(nCuts));
154 static const std::string binLabels[] ={
"MuonIdTrk",
"TrkIsoPt40/Pt<.2",
"CombMuon",
"MCPgoodTrk",
"MuPtOK",
"eta<2.5",
"OppChargePair",
"InvMassOK"};
155 for(
int ilabel=0;ilabel<nCuts;ilabel++){
156 m_stat->GetXaxis()->SetBinLabel(ilabel+1,binLabels[ilabel].c_str());
161 for (
const std::string& reg :
m_regions) {
165 m_varRanges[
"etaAll"] = std::make_pair(-1.05,1.05);
166 m_varRanges[
"etaPos"] = std::make_pair(-1.05,1.05);
167 m_varRanges[
"etaNeg"] = std::make_pair(-1.05,1.05);
168 }
else if (reg ==
"EAEA") {
172 }
else if (reg ==
"ECEC") {
173 m_varRanges[
"etaAll"] = std::make_pair(-2.5,-1.05);
174 m_varRanges[
"etaPos"] = std::make_pair(-2.5,-1.05);
175 m_varRanges[
"etaNeg"] = std::make_pair(-2.5,-1.05);
183 std::string hname =
m_resonName +
"_invmass_" + reg;
184 std::string htitle = hname +
"; Invmass[GeV/c^{2}]";
190 hname =
m_resonName +
"_2DinvmassVS" + varM +
"_" + reg;
191 htitle = hname +
";" +
m_varLabels[varM] +
";Invmass[GeV/c^{2}]";
195 hname =
m_resonName +
"_invmassVS" + varM +
"_" + reg;
196 htitle = hname +
";" +
m_varLabels[varM] +
";Invmass[GeV/c^{2}]";
205 hname =
m_resonName +
"_2DinvmassVS" + varW +
"_" + reg;
206 htitle = hname +
";" +
m_varLabels[varW] +
";Invmass[GeV/c^{2}]";
211 hname =
m_resonName +
"_widthVS" + varW +
"_" + reg;
212 htitle = hname +
";" +
m_varLabels[varW] +
";Width[GeV/c^{2}]";
222 if (varD ==
"eta" || varD ==
"etaAll" || varD ==
"etaPos" || varD ==
"etaNeg" ){
224 }
else if (varD ==
"pt" || varD ==
"ptAll" || varD ==
"ptPos" || varD ==
"ptNeg" ){
226 }
else if (varD ==
"phi" || varD ==
"phiAll" || varD ==
"phiPos" || varD ==
"phiNeg" ){
236 return StatusCode::SUCCESS;
248 return StatusCode::FAILURE;
249 }
else ATH_MSG_DEBUG(
"Muon container successfully retrieved.");
255 for(
const auto* muon : *muons ) {
256 const xAOD::TrackParticle *idTrk = muon->trackParticle(xAOD::Muon::TrackParticleType::InnerDetectorTrackParticle);
257 if (!idTrk)
continue;
258 m_stat->Fill(
"MuonIdTrk",1);
259 double idTrkPt(0),ptSum(0);
262 return StatusCode::FAILURE;
265 idTrkPt = idTrk->
pt();
269 m_stat->Fill(
"TrkIsoPt40/Pt<.2",1);
270 if (!muon->trackParticle(xAOD::Muon::TrackParticleType::CombinedTrackParticle))
continue;
271 m_stat->Fill(
"CombMuon",1);
274 m_stat->Fill(
"MCPgoodTrk",1);
276 if (idTrkPt <
m_ptCut*1000)
continue;
279 double idTrkEta = idTrk->
eta();
280 if (std::abs(idTrkEta)>2.5)
continue;
281 m_stat->Fill(
"eta<2.5",1);
287 int nMuons = goodMuons.size();
292 for (; mu1!=muEnd;++mu1){
293 const xAOD::TrackParticle *id1 = (*mu1)->trackParticle(xAOD::Muon::TrackParticleType::InnerDetectorTrackParticle);
295 for (; mu2!=muEnd; ++mu2){
296 const xAOD::TrackParticle *id2 = (*mu2)->trackParticle(xAOD::Muon::TrackParticleType::InnerDetectorTrackParticle);
298 double q1 = id1->
charge();
299 double q2 = id2->
charge();
300 if (q1*q2>0)
continue;
301 m_stat->Fill(
"OppChargePair",1);
310 double invmass =
getInvmass(id1,id2,muonMass);
311 if (invmass<m_minInvmass || invmass>
m_maxInvmass)
continue;
312 m_stat->Fill(
"InvMassOK",1);
316 double etaPos = idPos->
eta();
318 double etaNeg = idNeg->
eta();
321 double phiPos = idPos->
phi();
323 double phiNeg = idNeg->
phi();
326 double ptPos = idPos->
pt()/Gaudi::Units::GeV;
328 double ptNeg = idNeg->
pt()/Gaudi::Units::GeV;
333 double phiDiff = std::abs(phiPos - phiNeg);
334 if (phiDiff>Gaudi::Units::pi) phiDiff = 2*(Gaudi::Units::pi) - phiDiff;
340 std::string region{};
341 if ((std::abs(etaPos)<1.05 || std::abs(etaPos)==1.05) && (std::abs(etaNeg)<1.05 || std::abs(etaNeg)==1.05)) region=
"BB";
342 else if ((etaPos>1.05 && etaPos<2.5) && (etaNeg>1.05 && etaNeg<2.5)) region=
"EAEA";
343 else if ((etaPos<-1.05 && etaPos>-2.5) && (etaNeg<-1.05 && etaNeg>-2.5)) region=
"ECEC";
347 bool fillReg =
false;
348 if (!region.empty()){
351 if (!fillAll && !fillReg)
continue;
355 if (fillAll)
m_invmass[
"All"]->Fill(invmass);
356 if (fillReg)
m_invmass[region]->Fill(invmass);
360 std::map<std::string, TH2F*>* allVars =
nullptr;
367 for (
const std::pair<const std::string, TH2F*>& p : *allVars) {
368 if (p.first!=
"etaAll" && p.first!=
"phiAll" && p.first!=
"ptAll"){
371 }
else if (p.first==
"etaAll"){
380 }
else if (p.first==
"phiAll"){
389 }
else if (p.first==
"ptAll"){
404 if (varD!=
"etaAll" && varD!=
"phiAll" && varD!=
"ptAll"){
407 }
else if (varD==
"etaAll"){
409 m_xDistr[
"All"][
"etaAll"]->Fill(etaPos);
410 m_xDistr[
"All"][
"etaAll"]->Fill(etaNeg);
413 m_xDistr[region][
"etaAll"]->Fill(etaPos);
414 m_xDistr[region][
"etaAll"]->Fill(etaNeg);
416 }
else if (varD==
"phiAll"){
418 m_xDistr[
"All"][
"phiAll"]->Fill(phiPos);
419 m_xDistr[
"All"][
"phiAll"]->Fill(phiNeg);
422 m_xDistr[region][
"phiAll"]->Fill(phiPos);
423 m_xDistr[region][
"phiAll"]->Fill(phiNeg);
425 }
else if (varD==
"ptAll"){
427 m_xDistr[
"All"][
"ptAll"]->Fill(ptPos);
428 m_xDistr[
"All"][
"ptAll"]->Fill(ptNeg);
431 m_xDistr[region][
"ptAll"]->Fill(ptPos);
432 m_xDistr[region][
"ptAll"]->Fill(ptNeg);
441 return StatusCode::SUCCESS;
450 for (
const std::string& reg :
m_regions) {
451 for (
const std::pair<const std::string, TH2F*>& p :
m_2DinvmassVSx[reg]) {
453 std::vector<TH1F*> hout;
471 return StatusCode::SUCCESS;
477 std::string hname = hin->GetName();
479 TCanvas* ctemp =
new TCanvas(
"ctemp",
"ctemp",500,500);
481 hin->SetMarkerSize(1.2);
484 int nbins=hin->GetNbinsX();
485 for (
int i=0; i<nbins;i++){
486 std::ostringstream o; o<<i;
487 std::string projName = hname + o.str();
488 TH1D* htemp = (TH1D*) (hin->ProjectionY(projName.c_str(),i+1,i+1)->Clone());
489 htemp->SetTitle(projName.c_str());
491 if (htemp->GetEntries()>50){
492 double mean = 999., meanErr = 999., sigma = 999., sigmaErr = 999.,
chi2=0;
494 mean = htemp->GetMean();
495 sigma= htemp->GetRMS();
496 TF1* fn =
new TF1(
"fn",
"gaus",
mean-2*sigma,
mean+2*sigma);
497 fn->SetParameters(
float(htemp->GetEntries())/10.,
mean,sigma);
498 htemp->Fit(
"fn",
"RMLQN");
499 mean = fn->GetParameter(1);
500 sigma= fn->GetParameter(2);
501 fn->SetRange(
mean-1.2*sigma,
mean+1.2*sigma);
502 fn->SetParameters(
float(htemp->GetEntries())/10.,
mean,sigma);
505 htemp->Fit(
"fn",
"RML");
506 ctemp->Print(psName.c_str());
507 }
else htemp->Fit(
"fn",
"RMLQN");
508 double frange = 2.4*sigma;
509 double hrange = htemp->GetXaxis()->GetXmax()-htemp->GetXaxis()->GetXmin();
510 double ndf = frange/hrange*(htemp->GetNbinsX()) - 3;
511 chi2 = (fn->GetChisquare())/ndf;
513 mean = fn->GetParameter(1);
514 meanErr = fn->GetParError(1);
515 sigma = fn->GetParameter(2);
516 sigmaErr = fn->GetParError(2);
520 RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL);
521 RooRealVar m(
"mass",
"dimuon invariant mass", 91.2, 71., 111.,
"GeV");
522 RooDataHist *data =
nullptr;
523 data =
new RooDataHist(
"data",
"data", m, htemp);
524 RooRealVar bwm0(
"bw_#mu",
"bw_#mu", 91.2, 85.2, 97.2) ;
525 RooRealVar bwsg(
"bw_#sigma",
"bw_#sigma", 2.4952) ;
526 RooBreitWigner bw(
"bw",
"bw", m, bwm0, bwsg);
528 RooRealVar cbm0(
"cb_#mu",
"cb_#mu", 0 ) ;
529 RooRealVar cbsg(
"cb_#sigma",
"cb_#sigma", 3., 1., 10.) ;
530 RooRealVar cbal(
"cb_#alpha",
"cb_#alpha", 2.0) ;
531 RooRealVar cbn(
"cb_n",
"cb_n", 1., 0.05, 3.) ;
532 RooCBShape cb(
"cb",
"cb", m, cbm0, cbsg, cbal, cbn);
535 RooFFTConvPdf bxc(
"bxc",
"BW (X) CB", m, bw, cb) ;
536 [[maybe_unused]]
auto owningPtr = bxc.fitTo(*data, RooFit::PrintLevel(-1), RooFit::PrintEvalErrors(-1));
537 RooPlot* frame = m.frame();
538 data->plotOn(frame, RooFit::MarkerSize(0.9));
539 bxc.paramOn(frame, RooFit::Format(
"NELU", RooFit::AutoPrecision(2)), RooFit::Layout(0.1,0.4,0.9));
540 bxc.plotOn (frame, RooFit::LineColor(kBlue));
543 ctemp->Print(psName.c_str());
545 mean = bwm0.getVal();
546 meanErr = bwm0.getError();
547 sigma = cbsg.getVal();
548 sigmaErr = cbsg.getError();
549 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.
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)
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
std::map< std::string, TH1F *, std::less<> > m_invmass
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].