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