Instead just bit-flag marking used clusters store ID's of ESDtracks for
[u/mrichter/AliRoot.git] / STEER / AliMultiplicity.cxx
CommitLineData
9e44b53d 1#include <string.h>
32e449be 2#include "AliMultiplicity.h"
d325d83f 3#include "AliLog.h"
32e449be 4
5ClassImp(AliMultiplicity)
6
7//______________________________________________________________________
fe12e09c 8AliMultiplicity::AliMultiplicity():
9 TObject(),
10 fNtracks(0),
cd888a89 11 fNsingle(0),
12 fLabels(0),
0939e22a 13 fLabelsL2(0),
34581d1e 14 fUsedClusS(0),
15 fUsedClusT(0),
fe12e09c 16 fTh(0),
17 fPhi(0),
fa9ed8e9 18 fDeltTh(0),
968e8539 19 fDeltPhi(0),
968e8539 20 fThsingle(0),
ff44c37c 21 fPhisingle(0),
d7c5c1e4 22 fLabelssingle(0),
adc4b00f 23 fFastOrFiredChips(1200),
ab37e14c 24 fClusterFiredChips(1200)
fe12e09c 25{
32e449be 26 // Default Constructor
ab37e14c 27 fFiredChips[0] = 0;
28 fFiredChips[1] = 0;
d325d83f 29 for(Int_t ilayer = 0; ilayer < 6; ilayer++)fITSClusters[ilayer] = 0;
32e449be 30}
31
32//______________________________________________________________________
d7c5c1e4 33AliMultiplicity::AliMultiplicity(Int_t ntr, Float_t *th, Float_t *ph, Float_t *dth, Float_t *dph, Int_t *labels, Int_t* labelsL2, Int_t ns, Float_t *ts, Float_t *ps, Int_t *labelss, Short_t nfcL1, Short_t nfcL2, const TBits & fFastOr):
fe12e09c 34 TObject(),
35 fNtracks(ntr),
cd888a89 36 fNsingle(ns),
37 fLabels(0),
0939e22a 38 fLabelsL2(0),
34581d1e 39 fUsedClusS(0),
40 fUsedClusT(0),
fe12e09c 41 fTh(0),
42 fPhi(0),
fa9ed8e9 43 fDeltTh(0),
968e8539 44 fDeltPhi(0),
968e8539 45 fThsingle(0),
ff44c37c 46 fPhisingle(0),
d7c5c1e4 47 fLabelssingle(0),
adc4b00f 48 fFastOrFiredChips(1200),
ab37e14c 49 fClusterFiredChips(1200)
fe12e09c 50{
32e449be 51// Standard constructor
32e449be 52 if(ntr>0){
59ea252e 53 fLabels = new Int_t[ntr];
0939e22a 54 fLabelsL2 = new Int_t[ntr];
cd888a89 55 fTh = new Double_t [ntr];
56 fPhi = new Double_t [ntr];
fa9ed8e9 57 fDeltTh = new Double_t [ntr];
cd888a89 58 fDeltPhi = new Double_t [ntr];
32e449be 59 for(Int_t i=0;i<fNtracks;i++){
fa9ed8e9 60 fTh[i]=th[i];
32e449be 61 fPhi[i]=ph[i];
fa9ed8e9 62 fDeltTh[i]=dth[i];
63 fDeltPhi[i]=dph[i];
59ea252e 64 fLabels[i] = labels[i];
0939e22a 65 fLabelsL2[i] = labelsL2[i];
32e449be 66 }
67 }
968e8539 68 if(ns>0){
cd888a89 69 fThsingle = new Double_t [ns];
70 fPhisingle = new Double_t [ns];
d7c5c1e4 71 fLabelssingle = new Int_t [ns];
968e8539 72 for(Int_t i=0;i<fNsingle;i++){
73 fThsingle[i]=ts[i];
74 fPhisingle[i]=ps[i];
d7c5c1e4 75 fLabelssingle[i]=labelss[i];
968e8539 76 }
77 }
ab37e14c 78 fFiredChips[0] = nfcL1;
79 fFiredChips[1] = nfcL2;
ff44c37c 80 fFastOrFiredChips = fFastOr;
d325d83f 81 for(Int_t ilayer = 0; ilayer < 6; ilayer++)fITSClusters[ilayer] = 0;
32e449be 82}
83
1f9831ab 84//______________________________________________________________________
85AliMultiplicity::AliMultiplicity(Int_t ntr, Int_t ns, Short_t nfcL1, Short_t nfcL2, const TBits & fFastOr) :
86 TObject(),
87 fNtracks(ntr),
88 fNsingle(ns),
89 fLabels(0),
90 fLabelsL2(0),
34581d1e 91 fUsedClusS(0),
92 fUsedClusT(0),
1f9831ab 93 fTh(0),
94 fPhi(0),
95 fDeltTh(0),
96 fDeltPhi(0),
97 fThsingle(0),
98 fPhisingle(0),
d7c5c1e4 99 fLabelssingle(0),
1f9831ab 100 fFastOrFiredChips(1200),
101 fClusterFiredChips(1200)
102{
103 // Standard constructor to create the arrays w/o filling
104 if(ntr>0){
105 fLabels = new Int_t[ntr];
106 fLabelsL2 = new Int_t[ntr];
107 fTh = new Double_t [ntr];
108 fPhi = new Double_t [ntr];
109 fDeltTh = new Double_t [ntr];
110 fDeltPhi = new Double_t [ntr];
34581d1e 111 fUsedClusT = new ULong64_t[ntr];
112
1f9831ab 113 for(Int_t i=fNtracks;i--;){
114 fTh[i]=fPhi[i]=fDeltTh[i]=fDeltPhi[i] = 0;
115 fLabels[i] = fLabelsL2[i] = 0;
116 }
117 }
118 if(ns>0){
119 fThsingle = new Double_t [ns];
120 fPhisingle = new Double_t [ns];
d7c5c1e4 121 fLabelssingle = new Int_t [ns];
34581d1e 122 fUsedClusS = new UInt_t[ns];
d7c5c1e4 123 for(Int_t i=fNsingle;i--;) fThsingle[i] = fPhisingle[i] = fLabelssingle[i] = 0;
1f9831ab 124 }
125 fFiredChips[0] = nfcL1;
126 fFiredChips[1] = nfcL2;
127 fFastOrFiredChips = fFastOr;
128 for(Int_t ilayer=6;ilayer--;) fITSClusters[ilayer] = 0;
129}
130
32e449be 131//______________________________________________________________________
fe12e09c 132AliMultiplicity::AliMultiplicity(const AliMultiplicity& m):
133 TObject(m),
134 fNtracks(m.fNtracks),
cd888a89 135 fNsingle(m.fNsingle),
136 fLabels(0),
0939e22a 137 fLabelsL2(0),
34581d1e 138 fUsedClusS(0),
139 fUsedClusT(0),
fe12e09c 140 fTh(0),
141 fPhi(0),
fa9ed8e9 142 fDeltTh(0),
968e8539 143 fDeltPhi(0),
968e8539 144 fThsingle(0),
ff44c37c 145 fPhisingle(0),
d7c5c1e4 146 fLabelssingle(0),
adc4b00f 147 fFastOrFiredChips(1200),
ab37e14c 148 fClusterFiredChips(1200)
fe12e09c 149{
32e449be 150 // copy constructor
32e449be 151 Duplicate(m);
32e449be 152}
153
154//______________________________________________________________________
155AliMultiplicity &AliMultiplicity::operator=(const AliMultiplicity& m){
156 // assignment operator
157 if(this == &m)return *this;
158 ((TObject *)this)->operator=(m);
159
316c6cd9 160 if(fTh)delete [] fTh;fTh = 0;
161 if(fPhi)delete [] fPhi;fPhi = 0;
fa9ed8e9 162 if(fDeltTh)delete [] fDeltTh;fDeltTh= 0;
316c6cd9 163 if(fDeltPhi)delete [] fDeltPhi;fDeltPhi = 0;
164 if(fLabels)delete [] fLabels;fLabels = 0;
0939e22a 165 if(fLabelsL2)delete [] fLabelsL2;fLabelsL2 = 0;
316c6cd9 166 if(fThsingle)delete [] fThsingle;fThsingle = 0;
167 if(fPhisingle)delete [] fPhisingle;fPhisingle = 0;
d7c5c1e4 168 if(fLabelssingle)delete [] fLabelssingle;fLabelssingle = 0;
34581d1e 169 if(fUsedClusS) delete[] fUsedClusS; fUsedClusS = 0;
170 if(fUsedClusT) delete[] fUsedClusT; fUsedClusT = 0;
171
32e449be 172 Duplicate(m);
173
174 return *this;
175}
176
732a24fe 177void AliMultiplicity::Copy(TObject &obj) const {
178
179 // this overwrites the virtual TOBject::Copy()
180 // to allow run time copying without casting
181 // in AliESDEvent
182
183 if(this==&obj)return;
184 AliMultiplicity *robj = dynamic_cast<AliMultiplicity*>(&obj);
185 if(!robj)return; // not an AliMultiplicity
186 *robj = *this;
187
188}
189
190
32e449be 191//______________________________________________________________________
192void AliMultiplicity::Duplicate(const AliMultiplicity& m){
193 // used by copy constructor and assignment operator
194 fNtracks = m.fNtracks;
195 if(fNtracks>0){
cd888a89 196 fTh = new Double_t[fNtracks];
197 fPhi = new Double_t[fNtracks];
fa9ed8e9 198 fDeltTh = new Double_t[fNtracks];
cd888a89 199 fDeltPhi = new Double_t[fNtracks];
59ea252e 200 fLabels = new Int_t[fNtracks];
0939e22a 201 fLabelsL2 = new Int_t[fNtracks];
34581d1e 202 if (m.fUsedClusT) fUsedClusT = new ULong64_t[fNtracks];
203 else fUsedClusT = 0;
32e449be 204 }
205 else {
206 fTh = 0;
207 fPhi = 0;
fa9ed8e9 208 fDeltTh = 0;
32e449be 209 fDeltPhi = 0;
59ea252e 210 fLabels = 0;
0939e22a 211 fLabelsL2 = 0;
32e449be 212 }
968e8539 213 fNsingle = m.fNsingle;
214 if(fNsingle>0){
cd888a89 215 fThsingle = new Double_t[fNsingle];
216 fPhisingle = new Double_t[fNsingle];
d7c5c1e4 217 fLabelssingle = new Int_t[fNsingle];
34581d1e 218 if (m.fUsedClusS) fUsedClusS = new UInt_t[fNsingle];
219 else fUsedClusS = 0;
968e8539 220 }
221 else {
222 fThsingle = 0;
223 fPhisingle = 0;
d7c5c1e4 224 fLabelssingle = 0;
968e8539 225 }
cd888a89 226 if(m.fTh)memcpy(fTh,m.fTh,fNtracks*sizeof(Double_t));
227 if(m.fPhi)memcpy(fPhi,m.fPhi,fNtracks*sizeof(Double_t));
fa9ed8e9 228 if(m.fDeltTh)memcpy(fDeltTh,m.fDeltTh,fNtracks*sizeof(Double_t));
cd888a89 229 if(m.fDeltPhi)memcpy(fDeltPhi,m.fDeltPhi,fNtracks*sizeof(Double_t));
230 if(m.fLabels)memcpy(fLabels,m.fLabels,fNtracks*sizeof(Int_t));
0939e22a 231 if(m.fLabelsL2)memcpy(fLabelsL2,m.fLabelsL2,fNtracks*sizeof(Int_t));
cd888a89 232 if(m.fThsingle)memcpy(fThsingle,m.fThsingle,fNsingle*sizeof(Double_t));
233 if(m.fPhisingle)memcpy(fPhisingle,m.fPhisingle,fNsingle*sizeof(Double_t));
d7c5c1e4 234 if(m.fLabelssingle)memcpy(fLabelssingle,m.fLabelssingle,fNsingle*sizeof(Int_t));
34581d1e 235 if(fUsedClusS) memcpy(fUsedClusS,m.fUsedClusS,fNsingle*sizeof(UInt_t));
236 if(fUsedClusT) memcpy(fUsedClusT,m.fUsedClusT,fNtracks*sizeof(ULong64_t));
ab37e14c 237 fFiredChips[0] = m.fFiredChips[0];
238 fFiredChips[1] = m.fFiredChips[1];
d325d83f 239 for(Int_t ilayer = 0; ilayer < 6; ilayer++){
240 fITSClusters[ilayer] = m.fITSClusters[ilayer];
241 }
d325d83f 242
ff44c37c 243 fFastOrFiredChips = m.fFastOrFiredChips;
ab37e14c 244 fClusterFiredChips = m.fClusterFiredChips;
32e449be 245}
246
247//______________________________________________________________________
248AliMultiplicity::~AliMultiplicity(){
249 // Destructor
316c6cd9 250 if(fTh)delete [] fTh;fTh = 0;
251 if(fPhi)delete [] fPhi;fPhi = 0;
fa9ed8e9 252 if(fDeltTh)delete [] fDeltTh;fDeltTh = 0;
316c6cd9 253 if(fDeltPhi)delete [] fDeltPhi;fDeltPhi = 0;
254 if(fLabels)delete [] fLabels;fLabels = 0;
0939e22a 255 if(fLabelsL2)delete [] fLabelsL2;fLabelsL2 = 0;
316c6cd9 256 if(fThsingle)delete [] fThsingle;fThsingle = 0;
257 if(fPhisingle)delete [] fPhisingle;fPhisingle = 0;
d7c5c1e4 258 if(fLabelssingle)delete [] fLabelssingle;fLabelssingle = 0;
34581d1e 259 if(fUsedClusS) delete[] fUsedClusS; fUsedClusS = 0;
260 if(fUsedClusT) delete[] fUsedClusT; fUsedClusT = 0;
32e449be 261}
56258350 262
1f9831ab 263//______________________________________________________________________
264void AliMultiplicity::Clear(Option_t*)
265{
266 // reset all
267 TObject::Clear();
268 if(fTh)delete [] fTh;fTh = 0;
269 if(fPhi)delete [] fPhi;fPhi = 0;
270 if(fDeltTh)delete [] fDeltTh;fDeltTh = 0;
271 if(fDeltPhi)delete [] fDeltPhi;fDeltPhi = 0;
272 if(fLabels)delete [] fLabels;fLabels = 0;
273 if(fLabelsL2)delete [] fLabelsL2;fLabelsL2 = 0;
274 if(fThsingle)delete [] fThsingle;fThsingle = 0;
275 if(fPhisingle)delete [] fPhisingle;fPhisingle = 0;
d7c5c1e4 276 if(fLabelssingle)delete [] fLabelssingle;fLabelssingle = 0;
34581d1e 277 if(fUsedClusS) delete[] fUsedClusS; fUsedClusS = 0;
278 if(fUsedClusT) delete[] fUsedClusT; fUsedClusT = 0;
1f9831ab 279 fNtracks = fNsingle = 0;
280 for (int i=6;i--;) fITSClusters[0] = 0;
281 fFiredChips[0] = fFiredChips[1] = 0;
282 fFastOrFiredChips.ResetAllBits(kTRUE);
283 fClusterFiredChips.ResetAllBits(kTRUE);
1f9831ab 284 //
285}
286
56258350 287//______________________________________________________________________
288void AliMultiplicity::SetLabel(Int_t i, Int_t layer, Int_t label)
289{
290 if(i>=0 && i<fNtracks) {
291 if (layer == 0) {
292 fLabels[i] = label;
293 return;
294 } else if (layer == 1) {
295 if (fLabelsL2) {
296 fLabelsL2[i] = label;
297 return;
298 }
299 }
300 }
301 Error("SetLabel","Invalid track number %d or layer %d",i,layer);
302}
d325d83f 303
d7c5c1e4 304//______________________________________________________________________
305void AliMultiplicity::SetLabelSingle(Int_t i, Int_t label)
306{
307 if(i>=0 && i<fNsingle) {
308 if (fLabelssingle) {
309 fLabelssingle[i] = label;
310 return;
311 }
312 }
313 Error("SetLabelSingle","Invalid single cluster number %d",i);
314}
315
d325d83f 316//______________________________________________________________________
317UInt_t AliMultiplicity::GetNumberOfITSClusters(Int_t layMin, Int_t layMax) const {
318
319 if(layMax < layMin) {
320 AliError("layer min > layer max");
321 return 0;
322 }
323 if(layMin < 0) {
324 AliError("layer min < 0");
325 return 0;
326 }
327 if(layMax < 0) {
328 AliError("layer max > 0");
329 return 0;
330 }
331
332 Int_t sum=0;
333 for (Int_t i=layMin; i<=layMax; i++) sum+=fITSClusters[i];
334 return sum;
335
336}
1f9831ab 337
338//______________________________________________________________________
34581d1e 339void AliMultiplicity::SetTrackletData(Int_t id, const Float_t* tlet, UInt_t trSPD1, UInt_t trSPD2)
1f9831ab 340{
341 // fill tracklet data
342 if (id>=fNtracks) {AliError(Form("Number of declared tracklets %d < %d",fNtracks,id)); return;}
343 fTh[id] = tlet[0];
344 fPhi[id] = tlet[1];
345 fDeltPhi[id] = tlet[2];
346 fDeltTh[id] = tlet[3];
347 fLabels[id] = Int_t(tlet[4]);
34581d1e 348 fLabelsL2[id] = Int_t(tlet[5]);
349 fUsedClusT[id] = (((ULong64_t)trSPD2)<<32) + trSPD1;
350 printf("(%d %d)(%d %d)\n",trSPD1&0xffff,trSPD1>>16, trSPD2&0xffff, trSPD2>>16);
1f9831ab 351 //
352}
353
354//______________________________________________________________________
34581d1e 355void AliMultiplicity::SetSingleClusterData(Int_t id, const Float_t* scl, UInt_t tr)
1f9831ab 356{
357 // fill single cluster data
358 if (id>=fNsingle) {AliError(Form("Number of declared singles %d < %d",fNsingle,id)); return;}
359 fThsingle[id] = scl[0];
360 fPhisingle[id] = scl[1];
d7c5c1e4 361 fLabelssingle[id] = scl[2];
34581d1e 362 fUsedClusS[id] = tr;
1f9831ab 363 //
364}
365
34581d1e 366//______________________________________________________________________
367Bool_t AliMultiplicity::FreeClustersTracklet(Int_t i, Int_t mode) const
368{
369 // return kTRUE if the tracklet was not used by the track (on any of layers) of type mode: 0=TPC/ITS or ITS_SA, 1=ITS_SA_Pure
370 if (!fUsedClusT || mode<0 || mode>1 || i<0 || i>fNtracks) return kFALSE;
371 const ULong64_t kMask0 = 0x0000ffff0000ffff;
372 const ULong64_t kMask1 = 0xffff0000ffff0000;
373 return (fUsedClusT[i]&(mode ? kMask1:kMask0)) == 0;
374}
375
376//______________________________________________________________________
377Bool_t AliMultiplicity::GetTrackletTrackIDs(Int_t i, Int_t mode, Int_t &spd1, Int_t &spd2) const
378{
379 // set spd1 and spd2 to ID's of the tracks using the clusters of the tracklet (-1 if not used)
380 // Mode: 0=TPC/ITS or ITS_SA, 1=ITS_SA_Pure tracks
381 // return false if the neither of clusters is used
382 //
383 // note: stored value: [(idSAPureSPD2+1)<<16+(idTPCITS/SA_SPD2+1)]<<32 + [(idSAPureSPD1+1)<<16+(idTPCITS/SA_SPD1+1)]
384 if (!fUsedClusT || mode<0 || mode>1 || i<0 || i>fNtracks) {spd1 = spd2 = -1; return kFALSE;}
385 spd1 = (fUsedClusT[i]&0xffffffff);
386 spd2 = (fUsedClusT[i]>>32);
387 if (mode) {
388 spd1 >>= 16;
389 spd2 >>= 16;
390 }
391 else {
392 spd1 &= 0xffff;
393 spd2 &= 0xffff;
394 }
395 spd1--; // we are storing id+1
396 spd2--;
397 return !(spd1<0&&spd2<0);
398}
399
400//______________________________________________________________________
401Bool_t AliMultiplicity::FreeSingleCluster(Int_t i, Int_t mode) const
402{
403 // return kTRUE if the cluster was not used by the track of type mode: 0=TPC/ITS or ITS_SA, 1=ITS_SA_Pure
404 if (!fUsedClusS || mode<0 || mode>1 || i<0 || i>fNsingle) return kFALSE;
405 const UInt_t kMask0 = 0x0000ffff;
406 const UInt_t kMask1 = 0xffff0000;
407 return (fUsedClusS[i]&(mode ? kMask1:kMask0)) == 0;
408}
409
410//______________________________________________________________________
411Bool_t AliMultiplicity::GetSingleClusterTrackID(Int_t i, Int_t mode, Int_t &tr) const
412{
413 // set tr to id of the track using the single clusters (-1 if not used)
414 // Mode: 0=TPC/ITS or ITS_SA, 1=ITS_SA_Pure tracks
415 // return false if the cluster is not used
416 //
417 // note: stored value: [(idSAPure+1)<<16+(idTPCITS/SA+1)]
418 if (!fUsedClusS || mode<0 || mode>1 || i<0 || i>fNsingle) {tr = -1; return kFALSE;}
419 tr = fUsedClusS[i];
420 if (mode) tr >>= 16;
421 else tr &= 0xffff;
422 return (--tr)>=0; // we are storing id+1
423}
424
1f9831ab 425//______________________________________________________________________
426void AliMultiplicity::CompactBits()
427{
428 // sqeeze bit contrainers to minimum
429 fFastOrFiredChips.Compact();
430 fClusterFiredChips.Compact();
1f9831ab 431}
432
433//______________________________________________________________________
434void AliMultiplicity::Print(Option_t *opt) const
435{
436 // print
437 printf("N.tracklets: %4d N.singles: %4d\n",fNtracks,fNsingle);
438 TString opts = opt; opts.ToLower();
34581d1e 439 int t0spd1=-1,t1spd1=-1,t0spd2=-1,t1spd2=-1;
440 //
1f9831ab 441 if (opts.Contains("t")) {
34581d1e 442 for (int i=0;i<fNtracks;i++) {
443 GetTrackletTrackIDs(i,0,t0spd1,t0spd2);
444 GetTrackletTrackIDs(i,1,t1spd1,t1spd2);
445 printf("T#%3d| Eta:%+5.2f Th:%+6.3f Phi:%+6.3f DTh:%+6.3f DPhi:%+6.3f L1:%4d L2:%4d U:L1[%5d/%5d] L2[%5d/%5d]\n",
446 i,GetEta(i),fTh[i],fPhi[i],fDeltTh[i],fDeltPhi[i],fLabels[i],fLabelsL2[i],t0spd1,t1spd1,t0spd2,t1spd2);
447 }
1f9831ab 448 }
449 if (opts.Contains("s")) {
34581d1e 450 for (int i=0;i<fNsingle;i++) {
451 GetSingleClusterTrackID(i,0,t0spd1);
452 GetSingleClusterTrackID(i,1,t1spd1);
453 printf("S#%3d| Th:%+6.3f Phi:%+6.3f L:%4d U:[%5d/%5d]\n",
454 i,fThsingle[i],fPhisingle[i],fLabelssingle[i], t0spd1,t1spd1);
455 }
1f9831ab 456 }
457 //
458}