]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliMultiplicity.cxx
Fixed storing size of singles -> track reference
[u/mrichter/AliRoot.git] / STEER / AliMultiplicity.cxx
1 #include <string.h>
2 #include "AliMultiplicity.h"
3 #include "AliLog.h"
4
5 ClassImp(AliMultiplicity)
6
7 //______________________________________________________________________
8 AliMultiplicity::AliMultiplicity():
9   TObject(),
10   fNtracks(0),
11   fNsingle(0),
12   fLabels(0),
13   fLabelsL2(0),
14   fUsedClusS(0),
15   fUsedClusT(0),
16   fTh(0),
17   fPhi(0),
18   fDeltTh(0),
19   fDeltPhi(0),
20   fThsingle(0),
21   fPhisingle(0),
22   fLabelssingle(0),
23   fFastOrFiredChips(1200),
24   fClusterFiredChips(1200)
25 {
26   // Default Constructor
27   fFiredChips[0] = 0;
28   fFiredChips[1] = 0;
29   for(Int_t ilayer = 0; ilayer < 6; ilayer++)fITSClusters[ilayer] = 0;
30 }
31
32 //______________________________________________________________________
33 AliMultiplicity::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):
34   TObject(),
35   fNtracks(ntr),
36   fNsingle(ns),
37   fLabels(0),
38   fLabelsL2(0),
39   fUsedClusS(0),
40   fUsedClusT(0),
41   fTh(0),
42   fPhi(0),
43   fDeltTh(0),
44   fDeltPhi(0),
45   fThsingle(0),
46   fPhisingle(0),
47   fLabelssingle(0),
48   fFastOrFiredChips(1200),
49   fClusterFiredChips(1200)
50 {
51 // Standard constructor
52   if(ntr>0){
53     fLabels = new Int_t[ntr];
54     fLabelsL2 = new Int_t[ntr];
55     fTh = new Double_t [ntr];
56     fPhi = new Double_t [ntr];
57     fDeltTh = new Double_t [ntr];
58     fDeltPhi = new Double_t [ntr];
59     for(Int_t i=0;i<fNtracks;i++){
60       fTh[i]=th[i];
61       fPhi[i]=ph[i];
62       fDeltTh[i]=dth[i];
63       fDeltPhi[i]=dph[i];
64       fLabels[i] = labels[i];
65       fLabelsL2[i] = labelsL2[i];
66     }
67   }
68   if(ns>0){
69     fThsingle = new Double_t [ns];
70     fPhisingle = new Double_t [ns];
71     fLabelssingle = new Int_t [ns];
72     for(Int_t i=0;i<fNsingle;i++){
73       fThsingle[i]=ts[i];
74       fPhisingle[i]=ps[i];
75       fLabelssingle[i]=labelss[i];
76     }
77   }
78   fFiredChips[0] = nfcL1;
79   fFiredChips[1] = nfcL2;
80   fFastOrFiredChips = fFastOr;
81   for(Int_t ilayer = 0; ilayer < 6; ilayer++)fITSClusters[ilayer] = 0;
82 }
83
84 //______________________________________________________________________
85 AliMultiplicity::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),
91   fUsedClusS(0),
92   fUsedClusT(0),
93   fTh(0),
94   fPhi(0),
95   fDeltTh(0),
96   fDeltPhi(0),
97   fThsingle(0),
98   fPhisingle(0),
99   fLabelssingle(0),
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];
111     fUsedClusT = new ULong64_t[ntr];
112
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];
121     fLabelssingle = new Int_t [ns];
122     fUsedClusS = new UInt_t[ns];
123     for(Int_t i=fNsingle;i--;) fThsingle[i] = fPhisingle[i] = fLabelssingle[i] = 0;
124   }
125   fFiredChips[0] = nfcL1;
126   fFiredChips[1] = nfcL2;
127   fFastOrFiredChips = fFastOr;
128   for(Int_t ilayer=6;ilayer--;) fITSClusters[ilayer] = 0;
129 }
130
131 //______________________________________________________________________
132 AliMultiplicity::AliMultiplicity(const AliMultiplicity& m):
133   TObject(m),
134   fNtracks(m.fNtracks),
135   fNsingle(m.fNsingle),
136   fLabels(0),
137   fLabelsL2(0),
138   fUsedClusS(0),
139   fUsedClusT(0),
140   fTh(0),
141   fPhi(0),
142   fDeltTh(0),
143   fDeltPhi(0),
144   fThsingle(0),
145   fPhisingle(0),
146   fLabelssingle(0),
147   fFastOrFiredChips(1200),
148   fClusterFiredChips(1200)
149 {
150   // copy constructor
151   Duplicate(m);
152 }
153
154 //______________________________________________________________________
155 AliMultiplicity &AliMultiplicity::operator=(const AliMultiplicity& m){
156   // assignment operator
157   if(this == &m)return *this;
158   ((TObject *)this)->operator=(m);
159
160   if(fTh)delete [] fTh;fTh = 0;
161   if(fPhi)delete [] fPhi;fPhi = 0; 
162   if(fDeltTh)delete [] fDeltTh;fDeltTh= 0; 
163   if(fDeltPhi)delete [] fDeltPhi;fDeltPhi = 0; 
164   if(fLabels)delete [] fLabels;fLabels = 0;
165   if(fLabelsL2)delete [] fLabelsL2;fLabelsL2 = 0;
166   if(fThsingle)delete [] fThsingle;fThsingle = 0;
167   if(fPhisingle)delete [] fPhisingle;fPhisingle = 0;
168   if(fLabelssingle)delete [] fLabelssingle;fLabelssingle = 0;
169   if(fUsedClusS) delete[] fUsedClusS; fUsedClusS = 0;
170   if(fUsedClusT) delete[] fUsedClusT; fUsedClusT = 0;
171
172   Duplicate(m);
173
174   return *this;
175 }
176
177 void 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
191 //______________________________________________________________________
192 void AliMultiplicity::Duplicate(const AliMultiplicity& m){
193   // used by copy constructor and assignment operator
194   fNtracks = m.fNtracks;
195   if(fNtracks>0){
196     fTh = new Double_t[fNtracks];
197     fPhi = new Double_t[fNtracks];
198     fDeltTh = new Double_t[fNtracks];
199     fDeltPhi = new Double_t[fNtracks];
200     fLabels = new Int_t[fNtracks];
201     fLabelsL2 = new Int_t[fNtracks];
202     if (m.fUsedClusT) fUsedClusT = new ULong64_t[fNtracks];
203     else fUsedClusT = 0;
204   }
205   else {
206     fTh = 0;
207     fPhi = 0;
208     fDeltTh = 0;
209     fDeltPhi = 0;
210     fLabels = 0;
211     fLabelsL2 = 0;
212   }
213   fNsingle = m.fNsingle;
214   if(fNsingle>0){
215     fThsingle = new Double_t[fNsingle];
216     fPhisingle = new Double_t[fNsingle];
217     fLabelssingle = new Int_t[fNsingle];
218     if (m.fUsedClusS) fUsedClusS = new UInt_t[fNsingle];
219     else fUsedClusS = 0;
220   }
221   else {
222     fThsingle = 0;
223     fPhisingle = 0;
224     fLabelssingle = 0;
225   }
226   if(m.fTh)memcpy(fTh,m.fTh,fNtracks*sizeof(Double_t));
227   if(m.fPhi)memcpy(fPhi,m.fPhi,fNtracks*sizeof(Double_t));
228   if(m.fDeltTh)memcpy(fDeltTh,m.fDeltTh,fNtracks*sizeof(Double_t));
229   if(m.fDeltPhi)memcpy(fDeltPhi,m.fDeltPhi,fNtracks*sizeof(Double_t));
230   if(m.fLabels)memcpy(fLabels,m.fLabels,fNtracks*sizeof(Int_t));
231   if(m.fLabelsL2)memcpy(fLabelsL2,m.fLabelsL2,fNtracks*sizeof(Int_t));
232   if(m.fThsingle)memcpy(fThsingle,m.fThsingle,fNsingle*sizeof(Double_t));
233   if(m.fPhisingle)memcpy(fPhisingle,m.fPhisingle,fNsingle*sizeof(Double_t));
234   if(m.fLabelssingle)memcpy(fLabelssingle,m.fLabelssingle,fNsingle*sizeof(Int_t));
235   if(fUsedClusS) memcpy(fUsedClusS,m.fUsedClusS,fNsingle*sizeof(UInt_t));
236   if(fUsedClusT) memcpy(fUsedClusT,m.fUsedClusT,fNtracks*sizeof(ULong64_t));
237   fFiredChips[0] = m.fFiredChips[0];
238   fFiredChips[1] = m.fFiredChips[1];
239   for(Int_t ilayer = 0; ilayer < 6; ilayer++){
240     fITSClusters[ilayer] = m.fITSClusters[ilayer];
241   }
242   
243   fFastOrFiredChips = m.fFastOrFiredChips;
244   fClusterFiredChips = m.fClusterFiredChips;
245 }
246
247 //______________________________________________________________________
248 AliMultiplicity::~AliMultiplicity(){
249   // Destructor
250   if(fTh)delete [] fTh;fTh = 0;
251   if(fPhi)delete [] fPhi;fPhi = 0; 
252   if(fDeltTh)delete [] fDeltTh;fDeltTh = 0; 
253   if(fDeltPhi)delete [] fDeltPhi;fDeltPhi = 0; 
254   if(fLabels)delete [] fLabels;fLabels = 0;
255   if(fLabelsL2)delete [] fLabelsL2;fLabelsL2 = 0;
256   if(fThsingle)delete [] fThsingle;fThsingle = 0;
257   if(fPhisingle)delete [] fPhisingle;fPhisingle = 0;
258   if(fLabelssingle)delete [] fLabelssingle;fLabelssingle = 0;
259   if(fUsedClusS) delete[] fUsedClusS; fUsedClusS = 0;
260   if(fUsedClusT) delete[] fUsedClusT; fUsedClusT = 0;
261 }
262
263 //______________________________________________________________________
264 void 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;
276   if(fLabelssingle)delete [] fLabelssingle;fLabelssingle = 0;
277   if(fUsedClusS) delete[] fUsedClusS; fUsedClusS = 0;
278   if(fUsedClusT) delete[] fUsedClusT; fUsedClusT = 0;
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);
284   //
285 }
286
287 //______________________________________________________________________
288 void 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 }
303
304 //______________________________________________________________________
305 void 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
316 //______________________________________________________________________
317 UInt_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 }
337
338 //______________________________________________________________________
339 void AliMultiplicity::SetTrackletData(Int_t id, const Float_t* tlet, UInt_t trSPD1, UInt_t trSPD2)
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]);
348   fLabelsL2[id] = Int_t(tlet[5]);
349   fUsedClusT[id] = (((ULong64_t)trSPD2)<<32) + trSPD1;
350   //
351 }
352
353 //______________________________________________________________________
354 void AliMultiplicity::SetSingleClusterData(Int_t id, const Float_t* scl, UInt_t tr)
355 {
356   // fill single cluster data
357   if (id>=fNsingle) {AliError(Form("Number of declared singles %d < %d",fNsingle,id)); return;}
358   fThsingle[id]  = scl[0];
359   fPhisingle[id] = scl[1];
360   fLabelssingle[id] = Int_t(scl[2]); 
361   fUsedClusS[id] = tr;
362   //
363 }
364
365 //______________________________________________________________________
366 Bool_t AliMultiplicity::FreeClustersTracklet(Int_t i, Int_t mode) const
367 {
368   // 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
369   if (!fUsedClusT || mode<0 || mode>1 || i<0 || i>fNtracks) return kFALSE;
370   const ULong64_t kMask0 = 0x0000ffff0000ffffLL;
371   const ULong64_t kMask1 = 0xffff0000ffff0000LL;
372   return (fUsedClusT[i]&(mode ? kMask1:kMask0)) == 0;
373 }
374
375 //______________________________________________________________________
376 Bool_t AliMultiplicity::GetTrackletTrackIDs(Int_t i, Int_t mode, Int_t &spd1, Int_t &spd2) const
377 {
378   // set spd1 and spd2 to ID's of the tracks using the clusters of the tracklet (-1 if not used)
379   // Mode: 0=TPC/ITS or ITS_SA, 1=ITS_SA_Pure tracks
380   // return false if the neither of clusters is used
381   //
382   // note: stored value:  [(idSAPureSPD2+1)<<16+(idTPCITS/SA_SPD2+1)]<<32 +  [(idSAPureSPD1+1)<<16+(idTPCITS/SA_SPD1+1)]
383   if (!fUsedClusT || mode<0 || mode>1 || i<0 || i>fNtracks) {spd1 = spd2 = -1; return kFALSE;}
384   //
385   spd1 = (fUsedClusT[i]&0xffffffffLL);
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 //______________________________________________________________________
401 Bool_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 //______________________________________________________________________
411 Bool_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
425 //______________________________________________________________________
426 void AliMultiplicity::CompactBits()
427 {
428   // sqeeze bit contrainers to minimum
429   fFastOrFiredChips.Compact();
430   fClusterFiredChips.Compact();
431 }
432
433 //______________________________________________________________________
434 void 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();
439   int t0spd1=-1,t1spd1=-1,t0spd2=-1,t1spd2=-1;
440   //
441   if (opts.Contains("t")) {
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     }
448   }
449   if (opts.Contains("s")) {
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     }
456   }
457   //
458 }