PandaRoot
softrig/PndSoftTriggerTask.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 #ifndef PndSoftTriggerTask_H
14 #define PndSoftTriggerTask_H 1
15 
16 #include "FairTask.h"
17 #include "FairRootManager.h"
18 
19 #include <map>
20 #include <vector>
21 #include <string>
22 #include "TLorentzVector.h"
23 #include "RhoCandList.h"
24 #include "TDatabasePDG.h"
25 #include "RhoVtxPoca.h"
26 
27 class TClonesArray;
28 class TObjectArray;
29 class TH1F;
30 class TH2F;
31 
35 class PndAnalysis;
36 class RhoCandList;
37 class RhoTuple;
38 class RhoCandidate;
39 class PndEventShape;
40 class TDatabasePDG;
41 class PndRhoTupleQA;
42 class PndSoftTriggerLine;
43 
44 class PndSoftTriggerTask : public FairTask {
45 
46  public:
47  // *** Default constructor
48  PndSoftTriggerTask(double pmom, int mode = 0, int runnum = 0, TString trigfilename = "");
49 
50  // *** Destructor
52 
53  // *** Virtual method Init
54  virtual InitStatus Init();
55 
56  // *** Virtual method Exec
57  virtual void Exec(Option_t *opt);
58 
59  virtual void Finish();
60 
61  // *** set default settings for fast and full sim
62  void SetFastSimDefaults();
63  void SetFullSimDefaults();
64 
65  // *** read selection configuration from file
66  void SetConfigurationFile(TString fname) { fCfgFileName = fname; }
67 
68  // switches between mass window only of full selection (selection defined in cfg file)
69  // 0: detailed selection turned off
70  // 1: exclusive mode (modes w/o detailed cut definitions are rejected)
71  // 2: open mode (modes w/o detailed cut definitions just have to fulfill their mass window criterion)
72  void ApplyFullSelection(int selmode = 1) { fApplyFullSelection = selmode; }
73 
74  // *** set max number of sigmas deviation for tag
75  void SetTagNSigMode(int mode, double nsig);
76  void SetTagNSigAll(double nsig);
77  void SetAuxNSig(double nsig) { fNsigAux = nsig; } // n sigma cut for KS, pi0, eta
78  void SetDstMDiffCut(double cut) { fDstMDiffCut = cut; } // cut on delta M(D*, D); default = 10. GeV/c^2
79 
80  // *** set selection parameters for QA tuple
81  void SetPi0QASelection(double min, double max)
82  {
83  fPi0QaMin = min;
84  fPi0QaMax = max;
85  }
86  void SetKs0QASelection(double min, double max)
87  {
88  fKs0QaMin = min;
89  fKs0QaMax = max;
90  }
91  void SetEtaQASelection(double min, double max)
92  {
93  fEtaQaMin = min;
94  fEtaQaMax = max;
95  }
96 
98 
99  // *** set mean and sigma for tagging algos
100  void SetPi0SignalParams(double mean, double sigma)
101  {
102  fPi0Mean = mean;
103  fPi0Sigma = sigma;
104  }
105  void SetKs0SignalParams(double mean, double sigma)
106  {
107  fKs0Mean = mean;
108  fKs0Sigma = sigma;
109  }
110  void SetEtaSignalParams(double mean, double sigma)
111  {
112  fEtaMean = mean;
113  fEtaSigma = sigma;
114  }
115 
117 
118  // *** pre selection of neutral and charged + PID cut
119  void SetGammaMinE(double min) { fGammaMinE = min; }
120  void SetTrackMinP(double min) { fTrackMinP = min; }
121  void SetInitialPidCut(double cut) { fIniPidCut = cut; }
122 
123  // *** modifiers for PID selection string
124  void SetPidAlgoAll(TString algo);
125 
126  void SetPidAlgoElectron(TString algo) { fAlgoElectron = algo; }
127  void SetPidAlgoMuon(TString algo) { fAlgoMuon = algo; }
128  void SetPidAlgoPion(TString algo) { fAlgoPion = algo; }
129  void SetPidAlgoKaon(TString algo) { fAlgoKaon = algo; }
130  void SetPidAlgoProton(TString algo) { fAlgoProton = algo; }
131 
132  // *** Switch Tagging methods
133  void SetTagAll(bool tag = true);
134  // mode code as in triggerlines configuration file
135  void SetTagMode(int mode, bool tag = true);
136 
137  // *** Enable/Disable QA output
138  void SetQAPi0(bool qa = true) { fQAPi0 = qa; }
139  void SetQAEta(bool qa = true) { fQAEta = qa; }
140  void SetQAKs0(bool qa = true) { fQAKs0 = qa; }
141  void SetQAMc(bool qa = true) { fQAMc = qa; }
142  void SetQAMctOnly(bool qa = true) { fQAMctOnly = qa; }
143 
144  void SetQAEvent(bool qa = true) { fQAEvent = qa; }
145 
146  void SetQAAll(bool qa = true);
147  // mode code as in triggerlines configuration file
148  void SetQAMode(int mode, bool qa = true);
149 
150  // passed to PndAnalysis: this also allows mct match, when some soft photons are missing in decay
151  void McMatchAllowPhotos(int maxn = 1, double thresh = 0.05)
152  {
153  fPhotosMax = maxn;
154  fPhotosThresh = thresh;
155  }
156 
157  void SetVerbose(int verb = 10) { fVerbose = verb; }
158 
159  protected:
160  private:
161  // *** List preparation methods
162  void FillGlobalLists();
163  bool ReadConfiguration();
164  bool ReadTriggerLines();
165 
166  // *** methods for full candidate selection
167  int DoCombinatorics(RhoCandList &l, PndSoftTriggerLine *tl); // do combinatorics for certain trigger line
168  void CombineList(RhoCandList &l, int mothpdg, int amothpdg, std::vector<int> &idx, std::vector<int> &aidx, bool cc = false);
169  int AntiPdg(int pdg); // gives pdg code of antiparticle if exists
170  double GetVarValue(RhoCandidate *c, int id); // fill single candidate variable with index id
171  void FillVarArray(RhoCandidate *c, int id, Bool_t tmva = false); // fill candidate variable array for selection
172  void FillEventShapeVarArray(); // fill event shape variable array for selection
173 
174  bool AcceptCandidate(int mode, RhoCandidate *c, RhoParticleSelectorBase *sel = nullptr); // accept candidate for full selection
175  bool AcceptDstCut(RhoCandidate *c); // accept the D* mass diff cut?
176  double GetPocaVtx(RhoCandidate *c, double &dist, double &ctau);
177  void GetAngles(RhoCandidate *c, double &oang, double &decang);
178 
179  // *** some helper functions
180  int SelectTruePid(RhoCandList &l);
181  int SelectPidProb(RhoCandList &l, int pididx, double cut);
182  int MultPidProb(RhoCandList &l, int pididx, double prob);
183  double DbMass(TString name)
184  {
185  if (fPdg->GetParticle(name))
186  return fPdg->GetParticle(name)->Mass();
187  else
188  return 0.;
189  }
190  int SplitString(TString s, TString delim, TString *toks, int maxtoks);
191  int DetermineRecoilMode(int &mode);
192  TLorentzVector BoostCms(TLorentzVector in);
193  int CodeVariable(TString v);
194 
195  // *** Created necessary composites
196  int CreateKs0Cands(RhoTuple *n);
197 
198  // *** General tagging method
199  int TagMode(PndSoftTriggerLine *tl, int &npre);
200 
201  // ----------------------------
202  // *** global vars
203  int fVerbose; // create verbose output
204  int fMode; // the signal or background mode code, to be set in the constructor
205  int fRecoilMode; // recoil mode code (0 = %, 1=gamma, 2=pi0, 3=eta, 4=2pi0, 5=2eta, 6=pi+pi-, 7=2pipi0, 8=K+K-, 9=K0 K0b)
206  int fRecoilCnt; // recoil counter (1*Ngamma + 10*Npi0 + 100*Npi+ + 1000*NK+ + 10000*NK0 + 100000*Neta)
207  int fEvtCount; // global event counter
208  int fRunNum; // run number
209  int fSigCount; // counter, unused for the time being
210  double fNsigTag; // max number of sigmas deviation of candidate to be tagged
211  double fNsigAux; // max number of sigmas deviation for auxilliary particle = pi0, K_S, eta
212  double fDstMDiffCut; // optional upper limit cut for D* -> DX decays on M(D*) - M(D) (explicit PDG codes 413, 423, 433)
213 
214  TString fCfgFileName; // file containing the detailed selection cuts
215  TString fTriggerFileName; // file containing the trigger setup
216  Int_t fPhotosMax; // passed over to PndAnalysis for MC match with photos on
217  Double_t fPhotosThresh; // passed over to PndAnalysis for MC match with photos on
218 
219  int fApplyFullSelection; // 0: detailed selection turned off
220  // 1: exclusive mode (modes w/o detailed cut definitions are rejected)
221  // 2: open mode (modes w/o detailed cut definitions just have to fulfill their mass window criterion)
222 
223  // *** initial pbar p system info
224  TLorentzVector fIniP4;
225  double fEcm;
226  double fPbarMom;
227  TVector3 fPrimVtx; // primary vertex estimate of all charged tracks by RhoVtxPoca
228  double fPrimVtxQa; // and primary vtx quality
229 
230  // ----------------------------
231  // *** flags for enable/disable QA ntuple output
232  bool fQAPi0; // QA tuple for pi0
233  bool fQAEta; // QA tuple for eta
234  bool fQAKs0; // QA tuple for KS
235  bool fQAEvent; // QA tuple for event (with tag info)
236  bool fQAMc; // QA tuple for MC lists
237  bool fQAMctOnly; // store QA info only for MCT
238 
239  // ----------------------------
240  // *** parameters for ntuple QA window
241  double fPi0QaMin; // min value for pi0 selection
242  double fPi0QaMax; // max value for pi0 selection
243 
244  double fEtaQaMin; // min value for eta(gg) selection
245  double fEtaQaMax; // max value for eta(gg) selection
246 
247  double fKs0QaMin; // min value for Ks selection
248  double fKs0QaMax; // max value for Ks selection
249 
250  // ----------------------------
251  // *** signal parameters for different channels
252  double fPi0Mean; // mean value for pi0 signal
253  double fPi0Sigma; // sigma value for pi0 signal
254 
255  double fEtaMean; // mean value for eta(gg) signal
256  double fEtaSigma; // sigma value for eta(gg) signal
257 
258  double fKs0Mean; // mean value for Ks signal
259  double fKs0Sigma; // sigma value for Ks signal
260 
261  // *** general cuts
262  double fGammaMinE; // minimum energy for gamma candidates
263  double fPi0MinE; // minimum energy for pi0 candidates
264  double fEtaMinE; // minimum energy for eta candidates
265  double fTrackMinP; // minimum momentum for charged candidates
266  double fIniPidCut; // Tightness of initial PID (cut on probability)
267 
268  // *** global mass selectors
269  RhoMassParticleSelector *fPi0Sel; // pi0 selector (g g)
270  RhoMassParticleSelector *fPi0PreSel; // pi0 pre selector
271 
272  RhoMassParticleSelector *fEtaSel; // eta selector (g g)
273  RhoMassParticleSelector *fEtaPreSel; // eta pre selector
274 
275  RhoMassParticleSelector *fKs0Sel; // Ks0 selector (pi pi)
276  RhoMassParticleSelector *fKs0PreSel; // Ks0 pre selector
277 
278  // *** global kin selectors
279  RhoMomentumParticleSelector *fMomentumSel; // cut for minimum p
280  RhoEnergyParticleSelector *fEnergySel; // cut for minimum E
281 
282  // *** pid algos
283  TString fAlgoElectron; // Pid algo definition string electrons
284  TString fAlgoMuon; // Pid algo definition string muons
285  TString fAlgoPion; // Pid algo definition string pions
286  TString fAlgoKaon; // Pid algo definition string kaons
287  TString fAlgoProton; // Pid algo definition string protons
288 
289  Int_t fPidMult_025[5]; // cache for the PID multiplicities with P>=0.25
290 
291  // *** declare NTuples
292  RhoTuple *ntp; // overall info
293  RhoTuple *nks0; // Ks0 QA
294  RhoTuple *npi0; // pi0 QA
295  RhoTuple *neta; // eta QA
296  RhoTuple *nmc; // MC QA
297 
298  // *** the PndAnalysis object
299  PndAnalysis *fAnalysis;
300 
301  // *** Pointer to event shape object
302  PndEventShape *fEventShape;
303 
304  // *** RhoTuple QA helper class
305  PndRhoTupleQA *fQA;
306 
307  // *** Poca vertexer
308  RhoVtxPoca *fPocaVertexer;
309 
310  // PDG database object
311  TDatabasePDG *fPdg;
312 
313  // *** global RhoCandLists
314  RhoCandList fMcTruth;
315  RhoCandList fAllCands;
316  RhoCandList fChargedCands;
317  RhoCandList fNeutralCands;
318  RhoCandList fGammaCands;
319 
320  RhoCandList fKs0Cands;
321  RhoCandList fPi0Cands;
322  RhoCandList fEtaCands;
323 
324  // *** index PID lists with ordering: e+ e- mu+ mu- pi+ pi- K+ K- p pb gam pi0 KS eta
325  RhoCandList fPidList[16];
326 
327  // *** Get parameter containers
328  virtual void SetParContainers();
329 
330  FairRootManager *fRootManager;
331  TClonesArray *fTcaOnlineFilterInfo;
332 
333  ClassDef(PndSoftTriggerTask, 1);
334 };
335 
336 #endif
void SetPidAlgoPion(TString algo)
void SetPi0QASelection(double min, double max)
void SetPidAlgoMuon(TString algo)
void SetTagAll(bool tag=true)
void SetConfigurationFile(TString fname)
void SetPidAlgoElectron(TString algo)
void SetKs0SignalParams(double mean, double sigma)
void SetPidAlgoKaon(TString algo)
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:37
void SetPi0SignalParams(double mean, double sigma)
__m128 v
Definition: P4_F32vec4.h:15
void SetTagNSigAll(double nsig)
void SetKs0QASelection(double min, double max)
void SetEtaSignalParams(double mean, double sigma)
void SetSignalParamsDefaults()
void SetQAMctOnly(bool qa=true)
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:36
virtual void Finish()
void SetEtaQASelection(double min, double max)
void SetTagMode(int mode, bool tag=true)
void SetQAMode(int mode, bool qa=true)
void SetPidAlgoAll(TString algo)
void SetQAAll(bool qa=true)
void SetQASelectionDefaults()
void SetTagNSigMode(int mode, double nsig)
virtual void Exec(Option_t *opt)
void SetPidAlgoProton(TString algo)
virtual InitStatus Init()
void McMatchAllowPhotos(int maxn=1, double thresh=0.05)
void ApplyFullSelection(int selmode=1)