ATO-91 Update in TPC-QA trending: MIPattach now part of dEdx descision in status...
[u/mrichter/AliRoot.git] / PWGPP / TPC / macros / qaConfig.C
1
2 Int_t qaConfig(TTree* tree, TString* returnStrings)
3 {
4   Float_t entryFrac=0.8, nsigmaOutlier=6., nsigmaWarning=3., epsilon=1.0e-6;
5   
6   //
7   // specify all variables for which the status aliases shall be defined.
8   // only for these variables the lines in the trending plots can be computed and plotted.
9   //
10   TString sTrendVars="meanTPCncl;meanTPCnclF;meanMIP;resolutionMIP;MIPattachSlopeA;MIPattachSlopeC;";
11   sTrendVars+=";meanMIPele;resolutionMIPele;electroMIPSeparation;meanVertX;meanVertY;meanVertZ;meanMultPos;meanMultNeg;";
12   sTrendVars+=";tpcItsMatchA;tpcItsMatchC;tpcItsMatchHighPtA;tpcItsMatchHighPtC;lambdaPull;ptPull;yPull;zPull;";
13   sTrendVars+=";tpcConstrainPhiA;tpcConstrainPhiC;deltaPt;";
14   sTrendVars+=";offsetdRA;offsetdZA;offsetdRC;offsetdZC;dcarAP0;dcarAP1;dcarCP0;dcarCP1;";
15   sTrendVars+=";dcar_posA_0;dcar_posA_1;dcar_posA_2;dcaz_posA_0;dcaz_posA_1;dcaz_posA_2;";
16   sTrendVars+=";dcar_posC_0;dcar_posC_1;dcar_posC_2;dcaz_posC_0;dcaz_posC_1;dcaz_posC_2;";
17   sTrendVars+=";dcar_negA_0;dcar_negA_1;dcar_negA_2;dcaz_negA_0;dcaz_negA_1;dcaz_negA_2;";
18   sTrendVars+=";dcar_negC_0;dcar_negC_1;dcar_negC_2;dcaz_negC_0;dcaz_negC_1;dcaz_negC_2;";
19   
20   //
21   // combined variables
22   // name them '..._combN' with N being the number of combined variables!
23   //
24   tree->SetAlias("meanMult_comb2"         , "((meanMultPos+meanMultNeg)/2.)");
25   tree->SetAlias("tpcItsMatch_comb4"      , "((tpcItsMatchA+tpcItsMatchC+tpcItsMatchHighPtA+tpcItsMatchHighPtC)/4)"); // mean of all 4.
26   tree->SetAlias("itsTpcPulls_comb4"      , "(TMath::Sqrt(lambdaPull**2+ptPull**2+yPull**2+zPull**2))");
27   tree->SetAlias("tpcConstrainPhi_comb2"  , "(TMath::Sqrt(tpcConstrainPhiA**2+tpcConstrainPhiC**2))"); // sqrt of quadr. sum ok because it's a bias.
28   tree->SetAlias("offsetd_comb4"          , "(TMath::Sqrt(offsetdRA**2+offsetdZA**2+offsetdRC**2+offsetdZC**2))");
29   tree->SetAlias("dcarFitpar_comb4"       , "((dcarAP0+dcarAP1+dcarCP0+dcarCP1)/4)"); // mean of 4.
30   tree->SetAlias("dcar0_comb4"            , "(TMath::Sqrt(dcar_posA_0**2+dcar_posC_0**2+dcar_negA_0**2+dcar_negC_0**2))");
31   tree->SetAlias("dcar1_comb4"            , "(TMath::Sqrt(dcar_posA_1**2+dcar_posC_1**2+dcar_negA_1**2+dcar_negC_1**2))");
32   tree->SetAlias("dcar2_comb4"            , "(TMath::Sqrt(dcar_posA_2**2+dcar_posC_2**2+dcar_negA_2**2+dcar_negC_2**2))");
33   tree->SetAlias("dcaz0_comb4"            , "(TMath::Sqrt(dcaz_posA_0**2+dcaz_posC_0**2+dcaz_negA_0**2+dcaz_negC_0**2))");
34   tree->SetAlias("dcaz1_comb4"            , "(TMath::Sqrt(dcaz_posA_1**2+dcaz_posC_1**2+dcaz_negA_1**2+dcaz_negC_1**2))");
35   tree->SetAlias("dcaz2_comb4"            , "(TMath::Sqrt(dcaz_posA_2**2+dcaz_posC_2**2+dcaz_negA_2**2+dcaz_negC_2**2))");
36   tree->SetAlias("MIPattachSlope_comb2"   , "((MIPattachSlopeA+MIPattachSlopeC*(-1))/2)");
37   
38   //
39   // add all combined variables to sTrendVars!
40   // only then the statistics aliases will be computed for them as well.
41   //
42   sTrendVars+=";meanMult_comb2;tpcItsMatch_comb4;itsTpcPulls_comb4;tpcConstrainPhi_comb2;";
43   sTrendVars+=";offsetd_comb4;dcarFitpar_comb4;dcar0_comb4;dcar1_comb4;dcar2_comb4;dcaz0_comb4;dcaz1_comb4;dcaz2_comb4;";
44   sTrendVars+=";MIPattachSlope_comb2;";
45   
46   //
47   // specify criterion to mark runs with enough statistics.
48   // these runs are the basis for the computation of the outlier criteria.
49   // -> robust mean and rms are computed from given entry fraction (EF) of these runs!
50   //
51   tree->SetAlias("statisticOK", "(meanTPCncl>0)");
52   
53   //
54   // creation of aliases for Outliers, Warnings, PhysicsAcceptable ...
55   // upper and lower limits needed separately to retrieve the numerical values for the line positions.
56   // for that reason the aliases are expected to be computable expressions.
57   //
58   TObjArray* oaTrendVars = sTrendVars.Tokenize(",;");
59   for (Int_t vari=0; vari<oaTrendVars->GetEntriesFast(); vari++)
60   {
61     TString sVar( oaTrendVars->At(vari)->GetName() );
62     
63     // outliers, warnings and robust mean are set for all variables identically.
64     TStatToolkit::SetStatusAlias(tree, sVar.Data(),    "statisticOK", Form("varname_OutlierMin:(MeanEF-%f*RMSEF-%f):%f", nsigmaOutlier, epsilon, entryFrac));
65     TStatToolkit::SetStatusAlias(tree, sVar.Data(),    "statisticOK", Form("varname_OutlierMax:(MeanEF+%f*RMSEF+%f):%f", nsigmaOutlier, epsilon, entryFrac));
66     TStatToolkit::SetStatusAlias(tree, sVar.Data(),    "statisticOK", Form("varname_WarningMin:(MeanEF-%f*RMSEF-%f):%f", nsigmaWarning, epsilon, entryFrac));
67     TStatToolkit::SetStatusAlias(tree, sVar.Data(),    "statisticOK", Form("varname_WarningMax:(MeanEF+%f*RMSEF+%f):%f", nsigmaWarning, epsilon, entryFrac));
68     TStatToolkit::SetStatusAlias(tree, sVar.Data(),    "statisticOK", Form("varname_RobustMean:(MeanEF+0):%f", entryFrac));
69     
70     // physics acceptable should be set for each type of variable individually.
71     // some sets of variables are already set here, the rest should be set appropriately after the loop!
72     Float_t combfac=1.;
73     if (sVar.Contains("_comb")) {
74       TString last = sVar(sVar.Last('b')+1, sVar.Length());
75       combfac = TMath::Sqrt( atoi(last.Data()) );
76     }
77     if (sVar.Contains("dca")) {
78       TStatToolkit::SetStatusAlias(tree, sVar.Data(),    "statisticOK", Form("varname_PhysAccMin:(MeanEF-%f+0)", 0.2*combfac)); // 2 mm around mean
79       TStatToolkit::SetStatusAlias(tree, sVar.Data(),    "statisticOK", Form("varname_PhysAccMax:(MeanEF+%f+0)", 0.2*combfac)); // 2 mm around mean
80     }
81     else if (sVar.Contains("Pull")) {
82       TStatToolkit::SetStatusAlias(tree, sVar.Data(),    "statisticOK", Form("varname_PhysAccMin:(MeanEF-%f+0)", 1.0*combfac)); // check them!
83       TStatToolkit::SetStatusAlias(tree, sVar.Data(),    "statisticOK", Form("varname_PhysAccMin:(MeanEF-%f+0)", 1.0*combfac));
84       TStatToolkit::SetStatusAlias(tree, sVar.Data(),    "statisticOK", Form("varname_PhysAccMax:(MeanEF+%f+0)", 1.0*combfac));
85     }
86     else { // other variables set to +- 5% of the mean as default to avoid crashes:
87       TStatToolkit::SetStatusAlias(tree, sVar.Data(),    "statisticOK", Form("varname_PhysAccMin:(MeanEF-%f*MeanEF):%f", 0.05*combfac, entryFrac));
88       TStatToolkit::SetStatusAlias(tree, sVar.Data(),    "statisticOK", Form("varname_PhysAccMax:(MeanEF+%f*MeanEF):%f", 0.05*combfac, entryFrac));
89     }
90     
91   }
92   
93   //
94   // all aliases can just be overwritten here...
95   // PhysAcc should be set to relative or absolute values appropriately!
96   //
97   TStatToolkit::SetStatusAlias(tree, "meanTPCncl",    "statisticOK", Form("varname_PhysAccMin:(MeanEF-%f*MeanEF):%f", 0.05, entryFrac));
98   TStatToolkit::SetStatusAlias(tree, "meanTPCncl",    "statisticOK", Form("varname_PhysAccMax:(MeanEF+%f*MeanEF):%f", 0.05, entryFrac));
99   TStatToolkit::SetStatusAlias(tree, "meanMIP",       "statisticOK", Form("varname_PhysAccMin:(MeanEF-%f*MeanEF):%f", 0.01, entryFrac));
100   TStatToolkit::SetStatusAlias(tree, "meanMIP",       "statisticOK", Form("varname_PhysAccMax:(MeanEF+%f*MeanEF):%f", 0.01, entryFrac));
101   TStatToolkit::SetStatusAlias(tree, "resolutionMIP", "statisticOK", Form("varname_PhysAccMin:(MeanEF-%f*MeanEF):%f", 0.10, entryFrac));
102   TStatToolkit::SetStatusAlias(tree, "resolutionMIP", "statisticOK", Form("varname_PhysAccMax:(MeanEF+%f*MeanEF):%f", 0.10, entryFrac));
103   TStatToolkit::SetStatusAlias(tree, "MIPattachSlopeA",  "statisticOK", Form("varname_PhysAccMin:(MeanEF-%f*MeanEF):%f", 0.005, entryFrac)); // p0 + p1 * tan(theta) // showing p1
104   TStatToolkit::SetStatusAlias(tree, "MIPattachSlopeA",  "statisticOK", Form("varname_PhysAccMax:(MeanEF+%f*MeanEF):%f", 0.005, entryFrac));
105   TStatToolkit::SetStatusAlias(tree, "MIPattachSlopeC",  "statisticOK", Form("varname_PhysAccMin:(MeanEF-%f*MeanEF):%f", 0.005, entryFrac));
106   TStatToolkit::SetStatusAlias(tree, "MIPattachSlopeC",  "statisticOK", Form("varname_PhysAccMax:(MeanEF+%f*MeanEF):%f", 0.005, entryFrac));
107   TStatToolkit::SetStatusAlias(tree, "meanMIPele",       "statisticOK", Form("varname_PhysAccMin:(MeanEF-%f*MeanEF):%f", 0.01, entryFrac));
108   TStatToolkit::SetStatusAlias(tree, "meanMIPele",       "statisticOK", Form("varname_PhysAccMax:(MeanEF+%f*MeanEF):%f", 0.01, entryFrac));
109   TStatToolkit::SetStatusAlias(tree, "resolutionMIPele", "statisticOK", Form("varname_PhysAccMin:(MeanEF-%f*MeanEF):%f", 0.10, entryFrac));
110   TStatToolkit::SetStatusAlias(tree, "resolutionMIPele", "statisticOK", Form("varname_PhysAccMax:(MeanEF+%f*MeanEF):%f", 0.10, entryFrac));
111   TStatToolkit::SetStatusAlias(tree, "meanVertZ",     "statisticOK", Form("varname_PhysAccMin:(%f+0)",-1.0 ));
112   TStatToolkit::SetStatusAlias(tree, "meanVertZ",     "statisticOK", Form("varname_PhysAccMax:(%f+0)", 1.0 ));
113 //  TStatToolkit::SetStatusAlias(tree, "tpcItsMatchA",  "statisticOK", Form("varname_PhysAccMin:(%f+0)", 0.7 )); // TODO: set to +-3% after multiplicity correction (see wiki)
114 //  TStatToolkit::SetStatusAlias(tree, "tpcItsMatchA",  "statisticOK", Form("varname_PhysAccMax:(%f+0)", 1.0 ));
115 //  TStatToolkit::SetStatusAlias(tree, "tpcItsMatchC",  "statisticOK", Form("varname_PhysAccMin:(%f+0)", 0.7 ));
116 //  TStatToolkit::SetStatusAlias(tree, "tpcItsMatchC",  "statisticOK", Form("varname_PhysAccMax:(%f+0)", 1.0 ));
117   
118   //
119   // now the actual criteria for each variable are set automatically.
120   //
121   for (Int_t vari=0; vari<oaTrendVars->GetEntriesFast(); vari++)
122   {
123     TString sVar( oaTrendVars->At(vari)->GetName() );
124     TStatToolkit::SetStatusAlias(tree, sVar.Data(),    "", Form("varname_Outlier:(varname>varname_OutlierMax||varname<varname_OutlierMin)"));
125     TStatToolkit::SetStatusAlias(tree, sVar.Data(),    "", Form("varname_Warning:(varname>varname_WarningMax||varname<varname_WarningMin)"));
126     TStatToolkit::SetStatusAlias(tree, sVar.Data(),    "", Form("varname_PhysAcc:(varname>varname_PhysAccMin&&varname<varname_PhysAccMax)"));
127   }
128   
129   //
130   // COMBINED CRITERIA
131   //
132   // Adding new subcriteria to the following combined criteria may change the descision based on the individual ones.
133   // e.g.: Assume a meanMIP warning that was vetoed by a meanMIP physacc before. It will not be vetoed anymore, if the physacc of MIPattach is very small.
134   //
135   
136   // combined MIP quality
137   tree->SetAlias("MIPquality_Outlier", "(meanMIP_Outlier||resolutionMIP_Outlier||MIPattachSlopeA_Outlier||MIPattachSlopeC_Outlier)");
138   tree->SetAlias("MIPquality_Warning", "(meanMIP_Warning||resolutionMIP_Warning||MIPattachSlopeA_Warning||MIPattachSlopeC_Warning)");
139   tree->SetAlias("MIPquality_PhysAcc", "(meanMIP_PhysAcc&&resolutionMIP_PhysAcc&&MIPattachSlopeA_PhysAcc&&MIPattachSlopeC_PhysAcc)");
140   
141   // combined matching efficiency
142   tree->SetAlias("tpcItsMatch_Outlier", "(tpcItsMatchA_Outlier||tpcItsMatchC_Outlier||tpcItsMatchHighPtA_Outlier||tpcItsMatchHighPtC_Outlier)");
143   tree->SetAlias("tpcItsMatch_Warning", "(tpcItsMatchA_Warning||tpcItsMatchC_Warning||tpcItsMatchHighPtA_Warning||tpcItsMatchHighPtC_Warning)");
144   tree->SetAlias("tpcItsMatch_PhysAcc", "(tpcItsMatchA_PhysAcc&&tpcItsMatchC_PhysAcc&&tpcItsMatchHighPtA_PhysAcc&&tpcItsMatchHighPtC_PhysAcc)");
145   
146   // combined matching quality (lambdaPull ptPull yPull zPull)
147   tree->SetAlias("itsTpcPulls_Outlier", "(lambdaPull_Outlier||ptPull_Outlier||yPull_Outlier||zPull_Outlier)");
148   tree->SetAlias("itsTpcPulls_Warning", "(lambdaPull_Warning||ptPull_Warning||yPull_Warning||zPull_Warning)");
149   tree->SetAlias("itsTpcPulls_PhysAcc", "(lambdaPull_PhysAcc&&ptPull_PhysAcc&&yPull_PhysAcc&&zPull_PhysAcc)");
150   
151   // combined DCA R and Z
152   tree->SetAlias("dcar0_Outlier", "(dcar_posA_0_Outlier||dcar_posC_0_Outlier||dcar_negA_0_Outlier||dcar_negC_0_Outlier)");
153   tree->SetAlias("dcar1_Outlier", "(dcar_posA_1_Outlier||dcar_posC_1_Outlier||dcar_negA_1_Outlier||dcar_negC_1_Outlier)");
154   tree->SetAlias("dcar2_Outlier", "(dcar_posA_2_Outlier||dcar_posC_2_Outlier||dcar_negA_2_Outlier||dcar_negC_2_Outlier)");
155   tree->SetAlias("dcar_Outlier" , "(dcar0_Outlier||dcar1_Outlier||dcar2_Outlier)");
156   tree->SetAlias("dcaz0_Outlier", "(dcaz_posA_0_Outlier||dcaz_posC_0_Outlier||dcaz_negA_0_Outlier||dcaz_negC_0_Outlier)");
157   tree->SetAlias("dcaz1_Outlier", "(dcaz_posA_1_Outlier||dcaz_posC_1_Outlier||dcaz_negA_1_Outlier||dcaz_negC_1_Outlier)");
158   tree->SetAlias("dcaz2_Outlier", "(dcaz_posA_2_Outlier||dcaz_posC_2_Outlier||dcaz_negA_2_Outlier||dcaz_negC_2_Outlier)");
159   tree->SetAlias("dcaz_Outlier" , "(dcaz0_Outlier||dcaz1_Outlier||dcaz2_Outlier)");
160   
161   tree->SetAlias("dcar0_Warning", "(dcar_posA_0_Warning||dcar_posC_0_Warning||dcar_negA_0_Warning||dcar_negC_0_Warning)");
162   tree->SetAlias("dcar1_Warning", "(dcar_posA_1_Warning||dcar_posC_1_Warning||dcar_negA_1_Warning||dcar_negC_1_Warning)");
163   tree->SetAlias("dcar2_Warning", "(dcar_posA_2_Warning||dcar_posC_2_Warning||dcar_negA_2_Warning||dcar_negC_2_Warning)");
164   tree->SetAlias("dcar_Warning" , "(dcar0_Warning||dcar1_Warning||dcar2_Warning)");
165   tree->SetAlias("dcaz0_Warning", "(dcaz_posA_0_Warning||dcaz_posC_0_Warning||dcaz_negA_0_Warning||dcaz_negC_0_Warning)");
166   tree->SetAlias("dcaz1_Warning", "(dcaz_posA_1_Warning||dcaz_posC_1_Warning||dcaz_negA_1_Warning||dcaz_negC_1_Warning)");
167   tree->SetAlias("dcaz2_Warning", "(dcaz_posA_2_Warning||dcaz_posC_2_Warning||dcaz_negA_2_Warning||dcaz_negC_2_Warning)");
168   tree->SetAlias("dcaz_Warning" , "(dcaz0_Warning||dcaz1_Warning||dcaz2_Warning)");
169   
170   tree->SetAlias("dcar0_PhysAcc", "(dcar_posA_0_PhysAcc&&dcar_posC_0_PhysAcc&&dcar_negA_0_PhysAcc&&dcar_negC_0_PhysAcc)");
171   tree->SetAlias("dcar1_PhysAcc", "(dcar_posA_1_PhysAcc&&dcar_posC_1_PhysAcc&&dcar_negA_1_PhysAcc&&dcar_negC_1_PhysAcc)");
172   tree->SetAlias("dcar2_PhysAcc", "(dcar_posA_2_PhysAcc&&dcar_posC_2_PhysAcc&&dcar_negA_2_PhysAcc&&dcar_negC_2_PhysAcc)");
173   tree->SetAlias("dcar_PhysAcc" , "(dcar0_PhysAcc&&dcar1_PhysAcc&&dcar2_PhysAcc)");
174   tree->SetAlias("dcaz0_PhysAcc", "(dcaz_posA_0_PhysAcc&&dcaz_posC_0_PhysAcc&&dcaz_negA_0_PhysAcc&&dcaz_negC_0_PhysAcc)");
175   tree->SetAlias("dcaz1_PhysAcc", "(dcaz_posA_1_PhysAcc&&dcaz_posC_1_PhysAcc&&dcaz_negA_1_PhysAcc&&dcaz_negC_1_PhysAcc)");
176   tree->SetAlias("dcaz2_PhysAcc", "(dcaz_posA_2_PhysAcc&&dcaz_posC_2_PhysAcc&&dcaz_negA_2_PhysAcc&&dcaz_negC_2_PhysAcc)");
177   tree->SetAlias("dcaz_PhysAcc" , "(dcaz0_PhysAcc&&dcaz1_PhysAcc&&dcaz2_PhysAcc)");
178   
179   
180   //
181   // specify the variables which shall be included in the status bar.
182   // give them meaningful names for the y axis of the status bar!
183   //
184   TString sStatusbarVars ("MIPquality;dcaz;dcar;tpcItsMatch;itsTpcPulls;meanTPCncl;global");
185   TString sStatusbarNames("dE/dx (MIP);v_drift (DCAZ);space p.(DCAR);TPC-ITS m.eff.;ITS-TPC m.qual.;mean TPC Ncl;global result");
186   
187   //
188   // global descision is made automatically from the other entries in the status bar.
189   //
190   TString sVarsNoGlobal = sStatusbarVars;
191   sVarsNoGlobal.Remove(sVarsNoGlobal.Last(';'), sVarsNoGlobal.Length()); // remove last item (';global')
192   // global PhysAcc
193   TString sGlobalCriterion = sVarsNoGlobal;
194   sGlobalCriterion.ReplaceAll(";","_PhysAcc&&"); sGlobalCriterion.Append("_PhysAcc");
195   cout << "global PhysAcc:  " << sGlobalCriterion.Data() << endl;
196   tree->SetAlias("global_PhysAcc" , sGlobalCriterion.Data());
197   // global Outlier
198   sGlobalCriterion="";
199   TObjArray* oaVarsNoGlobal = sVarsNoGlobal.Tokenize(";");
200   for (Int_t vari=0; vari<oaVarsNoGlobal->GetEntriesFast(); vari++)
201   {
202     TString sVar( oaVarsNoGlobal->At(vari)->GetName() );
203     sGlobalCriterion+=Form("(%s_Outlier&&!%s_PhysAcc)", sVar.Data(), sVar.Data());
204     if (vari<oaVarsNoGlobal->GetEntriesFast()-1) sGlobalCriterion+="||";
205   }
206   cout << "global Outlier:  " << sGlobalCriterion.Data() << endl;
207   tree->SetAlias("global_Outlier" , sGlobalCriterion.Data());
208   // global Warning
209   sGlobalCriterion.ReplaceAll("_Outlier","_Warning");
210   cout << "global Warning:  " << sGlobalCriterion.Data() << endl;
211   tree->SetAlias("global_Warning" , sGlobalCriterion.Data());
212   
213   //
214   // set Boolean criteria to be checked for the markers in the status bar:
215   // separate them by colon ":"   (1) = true --> first marker always plotted
216   //
217   TString sCriteria("(1):(statisticOK):(varname_Warning):(varname_Outlier):(varname_PhysAcc)"); // or to just show vetos: (varname_PhysAcc&&varname_Warning)
218   
219   returnStrings[0] = sStatusbarVars;
220   returnStrings[1] = sStatusbarNames;
221   returnStrings[2] = sCriteria;
222   
223   return 1;
224 }