]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliMultiplicity.cxx
Typo fixed, and removing unused variable.
[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     if(m.fTh)memcpy(fTh,m.fTh,fNtracks*sizeof(Double_t));
205     if(m.fPhi)memcpy(fPhi,m.fPhi,fNtracks*sizeof(Double_t));
206     if(m.fDeltTh)memcpy(fDeltTh,m.fDeltTh,fNtracks*sizeof(Double_t));
207     if(m.fDeltPhi)memcpy(fDeltPhi,m.fDeltPhi,fNtracks*sizeof(Double_t));
208     if(m.fLabels)memcpy(fLabels,m.fLabels,fNtracks*sizeof(Int_t));
209     if(m.fLabelsL2)memcpy(fLabelsL2,m.fLabelsL2,fNtracks*sizeof(Int_t));
210     if(fUsedClusT) memcpy(fUsedClusT,m.fUsedClusT,fNtracks*sizeof(ULong64_t));
211   }
212   else {
213     fTh = 0;
214     fPhi = 0;
215     fDeltTh = 0;
216     fDeltPhi = 0;
217     fLabels = 0;
218     fLabelsL2 = 0;
219   }
220   fNsingle = m.fNsingle;
221   if(fNsingle>0){
222     fThsingle = new Double_t[fNsingle];
223     fPhisingle = new Double_t[fNsingle];
224     fLabelssingle = new Int_t[fNsingle];
225     if (m.fUsedClusS) fUsedClusS = new UInt_t[fNsingle];
226     else fUsedClusS = 0;
227     if(m.fThsingle)memcpy(fThsingle,m.fThsingle,fNsingle*sizeof(Double_t));
228     if(m.fPhisingle)memcpy(fPhisingle,m.fPhisingle,fNsingle*sizeof(Double_t));
229     if(m.fLabelssingle)memcpy(fLabelssingle,m.fLabelssingle,fNsingle*sizeof(Int_t));
230     if(fUsedClusS) memcpy(fUsedClusS,m.fUsedClusS,fNsingle*sizeof(UInt_t));
231   }
232   else {
233     fThsingle = 0;
234     fPhisingle = 0;
235     fLabelssingle = 0;
236   }
237
238   fFiredChips[0] = m.fFiredChips[0];
239   fFiredChips[1] = m.fFiredChips[1];
240   for(Int_t ilayer = 0; ilayer < 6; ilayer++){
241     fITSClusters[ilayer] = m.fITSClusters[ilayer];
242   }
243   
244   fFastOrFiredChips = m.fFastOrFiredChips;
245   fClusterFiredChips = m.fClusterFiredChips;
246 }
247
248 //______________________________________________________________________
249 AliMultiplicity::~AliMultiplicity(){
250   // Destructor
251   if(fTh)delete [] fTh;fTh = 0;
252   if(fPhi)delete [] fPhi;fPhi = 0; 
253   if(fDeltTh)delete [] fDeltTh;fDeltTh = 0; 
254   if(fDeltPhi)delete [] fDeltPhi;fDeltPhi = 0; 
255   if(fLabels)delete [] fLabels;fLabels = 0;
256   if(fLabelsL2)delete [] fLabelsL2;fLabelsL2 = 0;
257   if(fThsingle)delete [] fThsingle;fThsingle = 0;
258   if(fPhisingle)delete [] fPhisingle;fPhisingle = 0;
259   if(fLabelssingle)delete [] fLabelssingle;fLabelssingle = 0;
260   if(fUsedClusS) delete[] fUsedClusS; fUsedClusS = 0;
261   if(fUsedClusT) delete[] fUsedClusT; fUsedClusT = 0;
262 }
263
264 //______________________________________________________________________
265 void AliMultiplicity::Clear(Option_t*)
266 {
267   // reset all
268   TObject::Clear();
269   if(fTh)delete [] fTh;fTh = 0;
270   if(fPhi)delete [] fPhi;fPhi = 0; 
271   if(fDeltTh)delete [] fDeltTh;fDeltTh = 0; 
272   if(fDeltPhi)delete [] fDeltPhi;fDeltPhi = 0; 
273   if(fLabels)delete [] fLabels;fLabels = 0;
274   if(fLabelsL2)delete [] fLabelsL2;fLabelsL2 = 0;
275   if(fThsingle)delete [] fThsingle;fThsingle = 0;
276   if(fPhisingle)delete [] fPhisingle;fPhisingle = 0;
277   if(fLabelssingle)delete [] fLabelssingle;fLabelssingle = 0;
278   if(fUsedClusS) delete[] fUsedClusS; fUsedClusS = 0;
279   if(fUsedClusT) delete[] fUsedClusT; fUsedClusT = 0;
280   fNtracks = fNsingle = 0;
281   for (int i=6;i--;) fITSClusters[0] = 0;
282   fFiredChips[0] = fFiredChips[1] = 0;
283   fFastOrFiredChips.ResetAllBits(kTRUE);
284   fClusterFiredChips.ResetAllBits(kTRUE);
285   //
286 }
287
288 //______________________________________________________________________
289 void AliMultiplicity::SetLabel(Int_t i, Int_t layer, Int_t label)
290 {
291     if(i>=0 && i<fNtracks) {
292         if (layer == 0) {
293             fLabels[i] = label;
294             return;
295         } else if (layer == 1) {
296             if (fLabelsL2) {
297                 fLabelsL2[i] = label;
298                 return;
299             }
300         }
301     }
302     Error("SetLabel","Invalid track number %d or layer %d",i,layer);
303 }
304
305 //______________________________________________________________________
306 void AliMultiplicity::SetLabelSingle(Int_t i, Int_t label) 
307 {
308     if(i>=0 && i<fNsingle) {
309       if (fLabelssingle) {
310         fLabelssingle[i] = label;
311         return;
312       }
313     }
314     Error("SetLabelSingle","Invalid single cluster number %d",i);
315 }
316
317 //______________________________________________________________________
318 UInt_t AliMultiplicity::GetNumberOfITSClusters(Int_t layMin, Int_t layMax) const {
319
320   if(layMax < layMin) {
321     AliError("layer min > layer max");
322     return 0;
323   }
324   if(layMin < 0) {
325     AliError("layer min < 0");
326     return 0;
327   }
328   if(layMax < 0) {
329     AliError("layer max > 0");
330     return 0;
331   }
332
333   Int_t sum=0; 
334   for (Int_t i=layMin; i<=layMax; i++) sum+=fITSClusters[i]; 
335   return sum; 
336
337 }
338
339 //______________________________________________________________________
340 void AliMultiplicity::SetTrackletData(Int_t id, const Float_t* tlet, UInt_t trSPD1, UInt_t trSPD2)
341 {
342   // fill tracklet data
343   if (id>=fNtracks) {AliError(Form("Number of declared tracklets %d < %d",fNtracks,id)); return;}
344   fTh[id]      = tlet[0];
345   fPhi[id]     = tlet[1];
346   fDeltPhi[id] = tlet[2];
347   fDeltTh[id]  = tlet[3];
348   fLabels[id]   = Int_t(tlet[4]);
349   fLabelsL2[id] = Int_t(tlet[5]);
350   fUsedClusT[id] = (((ULong64_t)trSPD2)<<32) + trSPD1;
351   //
352 }
353
354 //______________________________________________________________________
355 void AliMultiplicity::SetSingleClusterData(Int_t id, const Float_t* scl, UInt_t tr)
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];
361   fLabelssingle[id] = Int_t(scl[2]); 
362   fUsedClusS[id] = tr;
363   //
364 }
365
366 //______________________________________________________________________
367 Bool_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 = 0x0000ffff0000ffffLL;
372   const ULong64_t kMask1 = 0xffff0000ffff0000LL;
373   return (fUsedClusT[i]&(mode ? kMask1:kMask0)) == 0;
374 }
375
376 //______________________________________________________________________
377 Bool_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   //
386   spd1 = (fUsedClusT[i]&0xffffffffLL);
387   spd2 = (fUsedClusT[i]>>32);
388   if (mode) {
389     spd1 >>= 16;
390     spd2 >>= 16;
391   }
392   else {
393     spd1 &= 0xffff;
394     spd2 &= 0xffff;
395   }
396   spd1--; // we are storing id+1
397   spd2--;
398   return !(spd1<0&&spd2<0);
399 }
400
401 //______________________________________________________________________
402 Bool_t AliMultiplicity::FreeSingleCluster(Int_t i, Int_t mode) const
403 {
404   // return kTRUE if the cluster was not used by the track of type mode: 0=TPC/ITS or ITS_SA, 1=ITS_SA_Pure
405   if (!fUsedClusS || mode<0 || mode>1 || i<0 || i>fNsingle) return kFALSE;
406   const UInt_t kMask0 = 0x0000ffff;
407   const UInt_t kMask1 = 0xffff0000;
408   return (fUsedClusS[i]&(mode ? kMask1:kMask0)) == 0;
409 }
410
411 //______________________________________________________________________
412 Bool_t AliMultiplicity::GetSingleClusterTrackID(Int_t i, Int_t mode, Int_t &tr) const
413 {
414   // set tr to id of the track using the single clusters  (-1 if not used)
415   // Mode: 0=TPC/ITS or ITS_SA, 1=ITS_SA_Pure tracks
416   // return false if the cluster is not used
417   //
418   // note: stored value:  [(idSAPure+1)<<16+(idTPCITS/SA+1)]
419   if (!fUsedClusS || mode<0 || mode>1 || i<0 || i>fNsingle) {tr = -1; return kFALSE;}
420   tr = fUsedClusS[i];
421   if (mode) tr >>= 16;
422   else      tr &= 0xffff;
423   return (--tr)>=0; // we are storing id+1
424 }
425
426 //______________________________________________________________________
427 void AliMultiplicity::CompactBits()
428 {
429   // sqeeze bit contrainers to minimum
430   fFastOrFiredChips.Compact();
431   fClusterFiredChips.Compact();
432 }
433
434 //______________________________________________________________________
435 void AliMultiplicity::Print(Option_t *opt) const
436 {
437   // print
438   printf("N.tracklets: %4d N.singles: %4d\n",fNtracks,fNsingle);
439   TString opts = opt; opts.ToLower();
440   int t0spd1=-1,t1spd1=-1,t0spd2=-1,t1spd2=-1;
441   //
442   if (opts.Contains("t")) {
443     for (int i=0;i<fNtracks;i++) {
444       GetTrackletTrackIDs(i,0,t0spd1,t0spd2);
445       GetTrackletTrackIDs(i,1,t1spd1,t1spd2);
446       printf("T#%3d| Eta:%+5.2f Th:%+6.3f Phi:%+6.3f DTh:%+6.3f DPhi:%+6.3f L1:%6d L2:%6d U:L1[%5d/%5d] L2[%5d/%5d]\n",
447              i,GetEta(i),fTh[i],fPhi[i],fDeltTh[i],fDeltPhi[i],fLabels[i],fLabelsL2[i],t0spd1,t1spd1,t0spd2,t1spd2);
448     }
449   }
450   if (opts.Contains("s")) {
451     for (int i=0;i<fNsingle;i++) {
452       GetSingleClusterTrackID(i,0,t0spd1);
453       GetSingleClusterTrackID(i,1,t1spd1);
454       printf("S#%3d| Th:%+6.3f Phi:%+6.3f L:%6d U:[%5d/%5d]\n",
455              i,fThsingle[i],fPhisingle[i],fLabelssingle[i], t0spd1,t1spd1);
456     }
457   }
458   //
459 }