11 #include "StEventTypes.h"
12 #include "StThreeVectorF.hh"
15 #include "StTrackGeometry.h"
16 #include "StDcaGeometry.h"
17 #include "StTpcDedxPidAlgorithm.h"
18 #include "StDedxPidTraits.h"
19 #include "StTrackPidTraits.h"
21 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
22 #include "StMuDSTMaker/COMMON/StMuDst.h"
23 #include "StMuDSTMaker/COMMON/StMuEvent.h"
24 #include "StMuDSTMaker/COMMON/StMuTrack.h"
25 #include "StMuDSTMaker/COMMON/StMuMtdHit.h"
26 #include "StMuDSTMaker/COMMON/StMuMtdPidTraits.h"
29 #include "StMtdEvtFilterMaker.h"
30 #include "tables/St_trgOfflineFilter_Table.h"
31 #include "tables/St_mtdEventFilterCuts_Table.h"
32 #include "tables/St_MtdTrackFilterTag_Table.h"
34 #include "tables/St_HighPtTag_Table.h"
45 mIsJpsiEvent = kFALSE;
47 mIsDiMuonOnly = kFALSE;
54 mMinFitHitsFraction = 0.52;
59 nMinMuonCandidates = 2;
63 mhNMuonCandidates = NULL;
67 StMtdEvtFilterMaker::~StMtdEvtFilterMaker()
73 Int_t StMtdEvtFilterMaker::Init()
75 SetFlavor(
"MtdEvtFilter",
"trgOfflineFilter");
84 Int_t StMtdEvtFilterMaker::InitRun(
const Int_t runNumber)
86 LOG_INFO <<
"Retrieving trigger ID from database ..." << endm;
88 mOtherTrigIDs.clear();
90 St_trgOfflineFilter* flaggedTrgs =
91 static_cast<St_trgOfflineFilter *
>(GetDataBase(
"Calibrations/trg/trgOfflineFilter"));
94 LOG_ERROR <<
"Could not find Calibrations/trg/trgOfflineFilter in database" << endm;
98 trgOfflineFilter_st* flaggedTrg = flaggedTrgs->GetTable();
99 for (
long j = 0; j < flaggedTrgs->GetNRows(); j++, flaggedTrg++)
101 int trigid = flaggedTrg->trigid;
102 if(trigid==0)
continue;
103 else if (trigid<1e9) mTriggerIDs.push_back(trigid);
104 else mOtherTrigIDs.push_back(trigid-1e9);
109 for(
unsigned int i=0; i<mTriggerIDs.size(); i++){
110 LOG_INFO <<
"Di-muon trigger ID: " << mTriggerIDs[i] << endm; }
112 for(
unsigned int i=0; i<mOtherTrigIDs.size(); i++){
113 LOG_INFO <<
"Other MTD trigger ID: " << mOtherTrigIDs[i] << endm; }
116 LOG_INFO <<
"Retrieving event filtering cuts from database ..." << endm;
118 St_mtdEventFilterCuts *mtdEventFilterCuts =
119 static_cast<St_mtdEventFilterCuts*
>(GetDataBase(
"Calibrations/mtd/mtdEventFilterCuts"));
120 if(!mtdEventFilterCuts)
122 LOG_ERROR <<
"No mtdEventFilterCuts table found in database" << endm;
125 mtdEventFilterCuts_st *table =
static_cast<mtdEventFilterCuts_st*
>(mtdEventFilterCuts->GetTable());
127 mMinTrkPtAll = table->minTrkPtAll;
128 mMinTrkPtLead = table->minTrkPtLead;
129 mMinNHitsFit = (int)table->minNHitsFit;
130 mMinNHitsDedx = (
int)table->minNHitsDedx;
131 mMinFitHitsFraction = table->minFitHitsFrac;
132 mMaxDca = table->maxDca;
133 mMinNsigmaPi = table->minNsigmaPi;
134 mMaxNsigmaPi = table->maxNsigmaPi;
135 mMaxDeltaZ = table->maxDeltaZ;
136 nMinMuonCandidates = (int)table->minNMuons;
139 LOG_INFO <<
"minTrkPtAll = " << mMinTrkPtAll << endm;
140 LOG_INFO <<
"minTrkPtLead = " << mMinTrkPtLead << endm;
141 LOG_INFO <<
"minNHitsFit = " << mMinNHitsFit << endm;
142 LOG_INFO <<
"minNHitsDedx = " << mMinNHitsDedx << endm;
143 LOG_INFO <<
"minFitHitsFrac = " << mMinFitHitsFraction << endm;
144 LOG_INFO <<
"maxDca = " << mMaxDca << endm;
145 LOG_INFO <<
"minNsigmaPi = " << mMinNsigmaPi << endm;
146 LOG_INFO <<
"maxNsigmaPi = " << mMaxNsigmaPi << endm;
147 LOG_INFO <<
"maxDeltaZ = " << mMaxDeltaZ << endm;
148 LOG_INFO <<
"minNMuons = " << nMinMuonCandidates << endm;
159 mIsJpsiEvent = kFALSE;
161 mIsDiMuonOnly = kFALSE;
167 mStEvent = (
StEvent*) GetInputDS(
"StEvent");
170 LOG_DEBUG <<
"Running on StEvent ..." << endm;
171 iret = processStEvent();
178 mMuDst = muDstMaker->
muDst();
179 iret = processMuDst();
183 LOG_ERROR <<
"No muDST is available ... "<< endm;
188 MtdTrackFilterTag_st tagTable;
189 StMaker* maskMk = GetMakerInheritsFrom(
"StMtdTrackingMaskMaker");
190 tagTable.tpcSectors = (maskMk ? maskMk->UAttr(
"TpcSectorsByMtd") : ~0U);
193 St_MtdTrackFilterTag*
MtdTrackFilterTag =
new St_MtdTrackFilterTag(
"MtdTrackFilterTag",1);
194 MtdTrackFilterTag->AddAt(&tagTable,0);
199 LOG_INFO <<
"Is event rejected: " << tagTable.isRejectEvent << endm;
200 LOG_INFO <<
"Should event be rejected: " << tagTable.shouldHaveRejectEvent << endm;
214 return (mIsDiMuonOnly && !mIsJpsiEvent);
227 if(!mIsDiMuonOnly && !mIsJpsiEvent)
return 1;
234 void StMtdEvtFilterMaker::checkTriggerIDs(
const vector<unsigned int> triggers)
241 for(
unsigned int i=0; !mIsDiMuon && i<triggers.size(); i++)
243 for(
unsigned int j=0; !mIsDiMuon && j<mTriggerIDs.size(); j++)
245 mIsDiMuon = ((int)triggers[i]==mTriggerIDs[j]);
249 mIsDiMuonOnly = mIsDiMuon;
250 for(
unsigned int i=0; mIsDiMuonOnly && i<triggers.size(); i++)
252 for(
unsigned int j=0; mIsDiMuonOnly && j<mOtherTrigIDs.size(); j++)
254 mIsDiMuonOnly = !((int)triggers[i]==mOtherTrigIDs[j]);
260 Int_t StMtdEvtFilterMaker::processMuDst()
262 mhEventStat->Fill(0.5);
265 vector<unsigned int> triggers = mMuDst->
event()->triggerIdCollection().nominal().triggerIds();
266 checkTriggerIDs(triggers);
267 if(!mIsDiMuon)
return kStOK;
268 mhEventStat->Fill(1.5);
271 int nNodes = mMuDst->numberOfGlobalTracks();
272 LOG_DEBUG <<
"# of global tracks " << nNodes << endm;
274 int nMuonCandidates = 0;
277 for(
int i=0; i<nNodes; i++)
280 if(!isValidTrack(gTrack))
continue;
284 double pt = gTrack->
pt();
285 if(pt_max<pt) pt_max = pt;
288 mhNMuonCandidates->Fill(nMuonCandidates);
289 if(nMuonCandidates>=nMinMuonCandidates && pt_max>mMinTrkPtLead)
291 mIsJpsiEvent = kTRUE;
292 mhEventStat->Fill(2.5);
299 Int_t StMtdEvtFilterMaker::processStEvent()
301 mhEventStat->Fill(0.5);
304 vector<unsigned int> triggers = mStEvent->triggerIdCollection()->nominal()->triggerIds();
305 checkTriggerIDs(triggers);
306 if(!mIsDiMuon)
return kStOK;
307 mhEventStat->Fill(1.5);
310 StSPtrVecTrackNode& nodes = mStEvent->trackNodes();
311 int nNodes = nodes.size();
312 LOG_DEBUG <<
"# of global tracks " << nNodes << endm;
314 int nMuonCandidates = 0;
316 for(
int i=0; i<nNodes; i++)
318 StTrack *gTrack = nodes[i]->track(global);
320 if(!isValidTrack(gTrack))
continue;
324 double pt = gTrack->geometry()->momentum().perp();
325 if(pt_max<pt) pt_max = pt;
328 mhNMuonCandidates->Fill(nMuonCandidates);
329 if(nMuonCandidates>=nMinMuonCandidates && pt_max>mMinTrkPtLead)
331 mIsJpsiEvent = kTRUE;
332 mhEventStat->Fill(2.5);
344 if(!track)
return kFALSE;
346 Float_t pt = mom.perp();
347 int nHitsFit = track->fitTraits().numberOfFitPoints(kTpcId);
348 int nHitsPoss = track->numberOfPossiblePoints(kTpcId);
352 if(pd && pidAlgorithm.traits())
353 nHitsDedx = pidAlgorithm.traits()->numberOfPoints();
355 if(pt < mMinTrkPtAll)
return kFALSE;
356 if(nHitsFit<mMinNHitsFit)
return kFALSE;
357 if(nHitsDedx<mMinNHitsDedx)
return kFALSE;
358 if(nHitsFit/(1.0*nHitsPoss)<mMinFitHitsFraction)
return kFALSE;
365 if(!pvtx)
return kFALSE;
368 if(!trDcaGeom)
return kFALSE;
370 double dca = dcahh.
distance(vtxPos,kFALSE);
371 if(dca>mMaxDca)
return kFALSE;
378 bool StMtdEvtFilterMaker::isValidTrack(
StMuTrack *track)
384 if(!track)
return kFALSE;
386 double pt = mom.perp();
387 int nHitsFit = track->
nHitsFit(kTpcId);
392 if(pt < mMinTrkPtAll)
return kFALSE;
393 if(nHitsFit<mMinNHitsFit)
return kFALSE;
394 if(nHitDedx<mMinNHitsDedx)
return kFALSE;
395 if(dca>mMaxDca)
return kFALSE;
396 if(nHitsFit/(1.0*nHitPoss)<mMinFitHitsFraction)
return kFALSE;
407 if(!track)
return kFALSE;
412 double nSigmaPi = -999.;
415 if(pd && pidAlgorithm.traits())
417 static StPionPlus* Pion = StPionPlus::instance();
418 nSigmaPi = pidAlgorithm.numberOfSigma(Pion);
420 if(nSigmaPi<mMinNsigmaPi || nSigmaPi>mMaxNsigmaPi)
return kFALSE;
425 StSPtrVecTrackPidTraits& traits = track->pidTraits();
426 for(
unsigned int it=0; it<traits.size(); it++)
428 if (traits[it]->detector() == kMtdId)
434 if(!mtdpid)
return kFALSE;
437 double dz = mtdpid->deltaZ();
438 if(dz > mMaxDeltaZ)
return kFALSE;
451 if(!track)
return kFALSE;
457 if(nSigmaPi<mMinNsigmaPi || nSigmaPi>mMaxNsigmaPi)
return kFALSE;
462 if(!hit)
return kFALSE;
466 double dz = mtdPid.deltaZ();
467 if(dz > mMaxDeltaZ)
return kFALSE;
474 void StMtdEvtFilterMaker::bookHistos()
476 mhEventStat =
new TH1F(
"hEventStat",
"Event statistics",5,0,5);
477 mhEventStat->GetXaxis()->SetBinLabel(1,
"All events");
478 mhEventStat->GetXaxis()->SetBinLabel(2,
"Good trigger");
479 mhEventStat->GetXaxis()->SetBinLabel(3,
"Accepted");
481 mhNMuonCandidates =
new TH1F(
"hNMuonCandidates",
"Number of muon candidates per event;N",10,0,10);
485 AddHist(mhEventStat);
486 AddHist(mhNMuonCandidates);
static TObjArray * globalTracks()
returns pointer to the global tracks list
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
Double_t pt() const
Returns pT at point of dca to primary vertex.
UShort_t nHitsDedx() const
Return number of hits used for dEdx.
This class is used to check number of muon candidates in each event. It runs both on StEvent and MuDs...
double distance(const StThreeVector< double > &p, bool scanPeriods=true) const
minimal distance between point and helix
bool isMuonCandidate(StTrack *track)
UShort_t nHitsFit() const
Return total number of hits used in fit.
Double_t nSigmaPion() const
Returns Craig's distance to the calculated dE/dx band for pions in units of sigma.
UShort_t nHitsPoss() const
Return number of possible hits on track.
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
const StThreeVectorF & momentum() const
Returns 3-momentum at dca to primary vertex.
int shouldHaveRejectEvent()
StThreeVectorF dcaGlobal(Int_t vtx_id=-1) const
Returns 3D distance of closest approach to primary vertex of associated global track.