don't sort clusters after local reco, do this in AliITSUTrackerGlo
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUTrackCond.cxx
CommitLineData
3c18eefd 1#include "AliITSUTrackCond.h"
2#include "AliITSUAux.h"
3#include "AliLog.h"
ee54014a 4#include <TMath.h>
3c18eefd 5
6using namespace AliITSUAux;
ee54014a 7using namespace TMath;
8
c03e4f8a 9Char_t AliITSUTrackCond::fgkClSharing = 0;
ee54014a 10Int_t AliITSUTrackCond::fgkMaxBranches = 50;
11Int_t AliITSUTrackCond::fgkMaxCandidates = 500;
12Float_t AliITSUTrackCond::fgkMaxTr2ClChi2 = 50.;
08419930 13Float_t AliITSUTrackCond::fgkMaxChi2GloNrm = 50.;
ee54014a 14Float_t AliITSUTrackCond::fgkMissPenalty = 2.;
9cdcba2c 15Float_t AliITSUTrackCond::fgkMaxMatchChi2 = 15.;
16Float_t AliITSUTrackCond::fgkMaxITSSAChi2 = 15;
3c18eefd 17//______________________________________________________________
18AliITSUTrackCond::AliITSUTrackCond(int nLayers)
ee54014a 19 :fInitDone(kFALSE)
d99994b2 20 ,fActiveLrInner(0)
21 ,fActiveLrOuter(0)
097e4cdf 22 ,fAllowLayers(0)
ee54014a 23 ,fNLayers(0)
6cb10ec2 24 ,fMaxClus(0)
9cdcba2c 25 ,fMaxITSTPCMatchChi2(fgkMaxMatchChi2)
c03e4f8a 26 ,fClSharing(0)
38997c3c 27 ,fMaxBranches(0)
28 ,fMaxCandidates(0)
5e3587be 29 ,fMaxITSSAChi2(0)
ee54014a 30 ,fMaxTr2ClChi2(0)
08419930 31 ,fMaxChi2GloNrm(0)
ee54014a 32 ,fMissPenalty(0)
33 ,fNSigmaRoadY(0)
34 ,fNSigmaRoadZ(0)
3c18eefd 35 ,fNConditions(0)
36 ,fConditions(0)
37 ,fAuxData(0)
38{
39 // def c-tor
38997c3c 40 if (nLayers) SetNLayers(nLayers);
3c18eefd 41}
42
43//______________________________________________________________
44AliITSUTrackCond::AliITSUTrackCond(const AliITSUTrackCond& src)
ee54014a 45 :TObject(src)
46 ,fInitDone(src.fInitDone)
d99994b2 47 ,fActiveLrInner(src.fActiveLrInner)
48 ,fActiveLrOuter(src.fActiveLrOuter)
097e4cdf 49 ,fAllowLayers(src.fAllowLayers)
ee54014a 50 ,fNLayers(0)
6cb10ec2 51 ,fMaxClus(0)
9cdcba2c 52 ,fMaxITSTPCMatchChi2(src.fMaxITSTPCMatchChi2)
c03e4f8a 53 ,fClSharing(0)
38997c3c 54 ,fMaxBranches(0)
55 ,fMaxCandidates(0)
5e3587be 56 ,fMaxITSSAChi2(0)
ee54014a 57 ,fMaxTr2ClChi2(0)
08419930 58 ,fMaxChi2GloNrm(0)
ee54014a 59 ,fMissPenalty(0)
60 ,fNSigmaRoadY(0)
61 ,fNSigmaRoadZ(0)
3c18eefd 62 ,fNConditions(src.fNConditions)
63 ,fConditions(src.fConditions)
64 ,fAuxData(src.fAuxData)
65{
66 // copy c-tor
ee54014a 67 SetNLayers(src.fNLayers);
6cb10ec2 68 fMaxClus = src.fMaxClus;
ee54014a 69 for (int i=fNLayers;i--;) {
70 SetMaxBranches(i,src.GetMaxBranches(i));
71 SetMaxCandidates(i,src.GetMaxCandidates(i));
72 SetMaxTr2ClChi2(i,src.GetMaxTr2ClChi2(i));
08419930 73 SetMaxChi2GloNrm(i,src.GetMaxChi2GloNrm(i));
ee54014a 74 SetMissPenalty(i,src.GetMissPenalty(i));
75 SetNSigmaRoadY(i,src.GetNSigmaRoadY(i));
76 SetNSigmaRoadZ(i,src.GetNSigmaRoadZ(i));
c03e4f8a 77 SetClSharing(i,src.GetClSharing(i));
38997c3c 78 }
6cb10ec2 79 //
80 for (int i=fMaxClus;i--;) SetMaxITSSAChi2(1+i,src.GetMaxITSSAChi2(1+i));
81 //
3c18eefd 82}
83
84//______________________________________________________________
85AliITSUTrackCond& AliITSUTrackCond::operator=(const AliITSUTrackCond& src)
86{
87 // copy op.
88 if (this!=&src) {
ee54014a 89 fInitDone = src.fInitDone;
d99994b2 90 fActiveLrInner = src.fActiveLrInner;
91 fActiveLrOuter = src.fActiveLrOuter;
92 //
097e4cdf 93 fAllowLayers = src.fAllowLayers;
3c18eefd 94 fNConditions = src.fNConditions;
95 fConditions = src.fConditions;
9cdcba2c 96 fMaxITSTPCMatchChi2 = src.fMaxITSTPCMatchChi2;
ee54014a 97 //
98 SetNLayers(src.fNLayers);
99 //
100 for (int i=fNLayers;i--;) {
101 SetMaxBranches(i,src.GetMaxBranches(i));
102 SetMaxCandidates(i,src.GetMaxCandidates(i));
103 SetMaxTr2ClChi2(i,src.GetMaxTr2ClChi2(i));
08419930 104 SetMaxChi2GloNrm(i,src.GetMaxChi2GloNrm(i));
ee54014a 105 SetMissPenalty(i,src.GetMissPenalty(i));
106 SetNSigmaRoadY(i,src.GetNSigmaRoadY(i));
107 SetNSigmaRoadZ(i,src.GetNSigmaRoadZ(i));
c03e4f8a 108 SetClSharing(i,src.GetClSharing(i));
38997c3c 109 }
6cb10ec2 110 for (int i=fMaxClus;i--;) SetMaxITSSAChi2(1+i,src.GetMaxITSSAChi2(1+i));
111 //
3c18eefd 112 fAuxData = src.fAuxData;
113 }
114 return *this;
115}
116
117//______________________________________________________________
38997c3c 118void AliITSUTrackCond::SetNLayers(int nLayers)
119{
120 // set number of layers
ee54014a 121 fInitDone = kFALSE;
122 if (fNLayers) {
9a2806bf 123 delete[] fClSharing;
124 delete[] fMaxBranches;
125 delete[] fMaxCandidates;
126 delete[] fMaxTr2ClChi2;
08419930 127 delete[] fMaxChi2GloNrm;
9a2806bf 128 delete[] fMissPenalty;
129 delete[] fNSigmaRoadY;
130 delete[] fNSigmaRoadZ;
5e3587be 131 delete[] fMaxITSSAChi2;
ee54014a 132 }
38997c3c 133 fNLayers = nLayers;
6cb10ec2 134 fMaxClus = 2*fNLayers;
097e4cdf 135 fAllowLayers = 0;
ee54014a 136 //
38997c3c 137 if (fNLayers>0) {
d99994b2 138 fActiveLrInner = 0;
139 fActiveLrOuter = fNLayers-1;
c03e4f8a 140 fClSharing = new Char_t[fNLayers];
141 fMaxBranches = new Short_t[fNLayers];
38997c3c 142 fMaxCandidates = new Short_t[fNLayers];
ee54014a 143 fMaxTr2ClChi2 = new Float_t[fNLayers];
08419930 144 fMaxChi2GloNrm = new Float_t[fNLayers];
ee54014a 145 fMissPenalty = new Float_t[fNLayers];
146 fNSigmaRoadY = new Float_t[fNLayers];
147 fNSigmaRoadZ = new Float_t[fNLayers];
6cb10ec2 148 fMaxITSSAChi2 = new Float_t[fMaxClus];
38997c3c 149 for (int i=fNLayers;i--;) {
097e4cdf 150 fAllowLayers |= 0x1<<i;
c03e4f8a 151 SetClSharing(i,fgkClSharing);
ee54014a 152 SetMaxBranches(i,fgkMaxBranches);
153 SetMaxCandidates(i,fgkMaxCandidates);
154 SetMaxTr2ClChi2(i,fgkMaxTr2ClChi2);
08419930 155 SetMaxChi2GloNrm(i,fgkMaxChi2GloNrm);
ee54014a 156 SetMissPenalty(i,fgkMissPenalty);
157 SetNSigmaRoadY(i,-1); // force recalculation
158 SetNSigmaRoadZ(i,-1); // force recalculation
38997c3c 159 }
6cb10ec2 160 for (int i=fMaxClus;i--;) SetMaxITSSAChi2(1+i,fgkMaxITSSAChi2);
38997c3c 161 }
ee54014a 162 else {
c03e4f8a 163 fClSharing = 0;
ee54014a 164 fMaxBranches = 0;
165 fMaxCandidates = 0;
166 fMaxTr2ClChi2 = 0;
08419930 167 fMaxChi2GloNrm = 0;
ee54014a 168 fMissPenalty = 0;
169 fNSigmaRoadY = 0;
170 fNSigmaRoadZ = 0;
171 }
172 //
38997c3c 173}
174
175//______________________________________________________________
70f61d86 176void AliITSUTrackCond::AddGroupPattern(UShort_t patt,Int_t minCl)
3c18eefd 177{
70f61d86 178 // add new group pattern to last condition: the track should have at least minCl clusters at layers given by patt
3c18eefd 179 if (fNConditions<1) AliFatal("Can be called only after AddCondition");
70f61d86 180 if (minCl>int(AliITSUAux::kMaxLayers)) AliFatal(Form("Requested Nlayers=%d exceeds max alowed %d",minCl,AliITSUAux::kMaxLayers));
181 if (minCl<1) AliFatal(Form("Requested Nlayers=%d for pattern %x",minCl,patt));
3c18eefd 182 int ind = fConditions.GetSize();
183 fConditions.Set(ind+1);
70f61d86 184 fConditions[ind] = (patt&AliITSUAux::kMaxLrMask) | (minCl<<kShiftNcl);
3c18eefd 185 fAuxData[(fNConditions-1)*kNAuxSz + kNGroups]++;
186}
187
188//______________________________________________________________
189void AliITSUTrackCond::AddNewCondition(Int_t minClusters)
190{
191 // add new track condition
192 fAuxData.Set( (1+fNConditions)*kNAuxSz );
193 fAuxData[fNConditions*kNAuxSz+kCondStart] = fConditions.GetSize();
194 fAuxData[fNConditions*kNAuxSz+kNGroups] = 0;
195 fAuxData[fNConditions*kNAuxSz+kMinClus] = minClusters;
196 fNConditions++;
197 //
198}
199
200//______________________________________________________________
c8d1f258 201Bool_t AliITSUTrackCond::CheckPattern(UShort_t patt) const
3c18eefd 202{
203 // check if the pattern matches to some condition
204 Short_t *arrAux = (Short_t*)fAuxData.GetArray();
70f61d86 205 UInt_t *arrGrp = (UInt_t*)fConditions.GetArray();
c8d1f258 206 int ncl = NumberOfBitsSet(patt);
3c18eefd 207 int cntCond = 0;
208 for (int ic=0;ic<fNConditions;ic++) {
209 if (arrAux[cntCond+kMinClus]>ncl) {cntCond+=kNAuxSz; continue;} // check number of clusters
210 int grAddr = arrAux[cntCond+kCondStart]; // 1st group pattern address in the condition
211 Bool_t ok = kTRUE;
212 // if every group of the condition does not match, check next contition
70f61d86 213 for (int ig=arrAux[cntCond+kNGroups];ig--;) {
214 UInt_t pattReq = arrGrp[grAddr++];
215 UShort_t actLr = (pattReq&AliITSUAux::kMaxLrMask)&patt; // patter of active layers satisfying to mask
aab41398 216 if (!actLr || NumberOfBitsSet(actLr)<int(pattReq>>kShiftNcl)) {ok = kFALSE; break;}
70f61d86 217 }
3c18eefd 218 if (ok) return kTRUE;
219 cntCond += kNAuxSz;
220 }
221 return kFALSE;
222}
223
224//______________________________________________________________
225void AliITSUTrackCond::Print(Option_t*) const
226{
227 // print conditions
228 int nc = GetNConditions();
229 Short_t *arrAux = (Short_t*)fAuxData.GetArray();
70f61d86 230 UInt_t *arrGrp = (UInt_t*)fConditions.GetArray();
3c18eefd 231 int cntCond = 0;
232 printf("Conditions set ID=%d : %d entries\n",GetID(),nc);
233 for (int i=0;i<nc;i++) {
234 printf("#%2d: MinCl:%2d | %d groups :",i,arrAux[cntCond+kMinClus],arrAux[cntCond+kNGroups]);
235 int grAddr = arrAux[cntCond+kCondStart];
236 for (int ig=arrAux[cntCond+kNGroups];ig--;) {
70f61d86 237 UInt_t patt = arrGrp[grAddr];
3c18eefd 238 printf("{");
70f61d86 239 PrintBits(patt, fNLayers);
240 printf("|%d}",patt>>kShiftNcl);
241 grAddr++;
3c18eefd 242 }
243 printf("\n");
244 cntCond += kNAuxSz;
245 }
097e4cdf 246 if (fAllowLayers) {
247 printf("Allowed Layers: ");
248 for (int i=0;i<fNLayers;i++) if (!IsLayerExcluded(i)) printf(" %d",i); printf("\n");
d99994b2 249 }
08419930 250 printf("Cuts:\t%6s\t%6s\t%4s\t%8s\t%8s\t%8s\t%8s\t%8s\n", "MaxBrn","MaxCnd","ClSh","Chi2Cl","Chi2Glo","Mis.Pen.","NSig.Y","NSig.Z");
ee54014a 251 for (int i=0;i<fNLayers;i++) {
08419930 252 printf("Lr%2d:\t%6d\t%6d\t%4d\t%8.1f\t%8.2f\t%8.2f\t%8.2f\t%8.2f\n",i,
253 fMaxBranches[i],fMaxCandidates[i],fClSharing[i],fMaxTr2ClChi2[i],fMaxChi2GloNrm[i],fMissPenalty[i],fNSigmaRoadY[i],fNSigmaRoadZ[i]);
ee54014a 254 }
255 //
9cdcba2c 256 printf("ITS/TPC matching MaxChi2: %.3f\n",fMaxITSTPCMatchChi2);
5e3587be 257 printf("ITS_SA BWD fit MaxChi2 vs Ncl :");
6cb10ec2 258 for (int i=1;i<=fMaxClus;i++) if (GetMaxITSSAChi2(i)>1e-6) printf("\t%d: %.2f",i,GetMaxITSSAChi2(i)); printf("\n");
9cdcba2c 259 //
ee54014a 260}
261
262//______________________________________________________________
263void AliITSUTrackCond::Init()
264{
265 // finalize and check consistency
266 if (fInitDone) return;
267 //
d99994b2 268 fActiveLrInner = -1;
ee54014a 269 for (int ilr=0;ilr<fNLayers;ilr++) {
270 if (IsLayerExcluded(ilr)) continue;
d99994b2 271 if (fActiveLrInner<0) fActiveLrInner = ilr;
272 fActiveLrOuter = ilr;
08419930 273 float nsig = Sqrt(2*GetMaxTr2ClChi2(ilr));
ee54014a 274 if (GetNSigmaRoadY(ilr)<0) SetNSigmaRoadY(ilr,nsig);
275 if (GetNSigmaRoadZ(ilr)<0) SetNSigmaRoadZ(ilr,nsig);
276 //
277 }
6cb10ec2 278 for (int i=fMaxClus;i--;) if (GetMaxITSSAChi2(1+1)<1e-6) SetMaxITSSAChi2(1+i,fgkMaxMatchChi2);
70cb7fe4 279 if (fMaxITSTPCMatchChi2<1e-6) SetMaxITSTPCMatchChi2(fgkMaxMatchChi2);
ee54014a 280 //
281 fInitDone = kTRUE;
3c18eefd 282}