]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONRawCluster.cxx
add protection in case TreeD (digits) is not available
[u/mrichter/AliRoot.git] / MUON / AliMUONRawCluster.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //-----------------------------------------------------------------------------
19 // Class AliMUONRawCluster
20 // -------------------------
21 // Class for the MUON RecPoint
22 // It contains the properties of the physics cluters found in the tracking chambers
23 // RawCluster contains also the information from the both cathode of the chambers.
24 //-----------------------------------------------------------------------------
25
26
27 #include "Riostream.h"
28
29 #include <TArrayF.h>
30 #include <TString.h>
31
32 #include "AliMUONRawCluster.h"
33
34 using std::endl;
35 using std::cout;
36 using std::setw;
37 /// \cond CLASSIMP
38 ClassImp(AliMUONRawCluster)
39 /// \endcond
40
41
42 //____________________________________________________
43 AliMUONRawCluster::AliMUONRawCluster() 
44   : AliMUONVCluster(),
45     fClusterType(0),
46     fGhost(0),
47     fDetElemId(0)   
48 {
49 /// Constructor
50     fTracks[0]=fTracks[1]=fTracks[2]=-1; 
51     for (int j=0;j<2;j++) {
52         fQ[j]=0;
53         fX[j]=0;
54         fY[j]=0;
55       fZ[j]=0;
56         fMultiplicity[j]=0;
57         fPeakSignal[j]=-1;
58         fChi2[j]=-1;
59         
60         for (int k=0;k<50;k++) {
61             fIndexMap[k][j]=-1;
62             fOffsetMap[k][j]=0;
63             fContMap[k][j]=0;
64             fPhysicsMap[k]=-1;
65         }
66     }
67     fNcluster[0]=fNcluster[1]=-1;
68     fErrXY[0] = FLT_MAX;
69     fErrXY[1] = FLT_MAX;
70 }
71
72 //____________________________________________________
73 AliMUONRawCluster::~AliMUONRawCluster() 
74 {
75 /// Destructor
76 }
77
78 //____________________________________________________
79 void AliMUONRawCluster::SetDigitsId(Int_t nDigits, const UInt_t *digitsId)
80 {
81   /// Set the array of digit Id
82   /// if digitsId is not given the array is filled with id=0
83   
84   fMultiplicity[0] = (nDigits < 50) ? nDigits : 50;
85   
86   if (fMultiplicity[0] == 0) return;
87   if (digitsId == 0)
88     for (Int_t i=0; i<fMultiplicity[0]; i++) fIndexMap[i][0] = 0;
89   else
90     for (Int_t i=0; i<fMultiplicity[0]; i++) fIndexMap[i][0] = (Int_t) digitsId[i];
91 }
92
93 //____________________________________________________
94 Int_t AliMUONRawCluster::Compare(const TObject *obj) const
95 {
96 /// Compare
97
98   /*
99          AliMUONRawCluster *raw=(AliMUONRawCluster *)obj;
100          Float_t r=GetRadius();
101          Float_t ro=raw->GetRadius();
102          if (r>ro) return 1;
103          else if (r<ro) return -1;
104          else return 0;
105   */
106   /*
107          AliMUONRawCluster *raw=(AliMUONRawCluster *)obj;
108          Float_t y=fY[0];
109          Float_t yo=raw->fY[0];
110          if (y>yo) return 1;
111          else if (y<yo) return -1;
112          else return 0;
113    */
114   
115   const AliMUONRawCluster* raw = static_cast<const AliMUONRawCluster*>(obj);
116   if ( GetCharge() > raw->GetCharge() ) 
117   {
118     return 1;
119   }
120   else if ( GetCharge() < raw->GetCharge() ) 
121   {
122     return -1;
123   }
124   return 0;
125 }
126
127 //____________________________________________________
128 Int_t AliMUONRawCluster::BinarySearch(Float_t y, TArrayF coord, Int_t from, Int_t upto)
129 {
130 /// Find object using a binary search. Array must first have been sorted.
131 /// Search can be limited by setting upto to desired index.
132
133    Int_t low=from, high=upto-1, half;
134    while(high-low>1) {
135         half=(high+low)/2;
136         if(y>coord[half]) low=half;
137         else high=half;
138    }
139    return low;
140 }
141 //____________________________________________________
142 void AliMUONRawCluster::SortMin(Int_t *idx,Float_t *xdarray,Float_t *xarray,Float_t *yarray,Float_t *qarray, Int_t ntr)
143 {
144 /// Get the 3 closest points(cog) one can find on the second cathode 
145 /// starting from a given cog on first cathode
146   
147   //
148   //  Loop over deltax, only 3 times
149   //
150   
151     Float_t xmin;
152     Int_t jmin;
153     Int_t id[3] = {-2,-2,-2};
154     Float_t jx[3] = {0.,0.,0.};
155     Float_t jy[3] = {0.,0.,0.};
156     Float_t jq[3] = {0.,0.,0.};
157     Int_t jid[3] = {-2,-2,-2};
158     Int_t i,j,imax;
159   
160     if (ntr<3) imax=ntr;
161     else imax=3;
162     for(i=0;i<imax;i++){
163         xmin=1001.;
164         jmin=0;
165     
166         for(j=0;j<ntr;j++){
167             if ((i == 1 && j == id[i-1]) 
168                   ||(i == 2 && (j == id[i-1] || j == id[i-2]))) continue;
169            if (TMath::Abs(xdarray[j]) < xmin) {
170               xmin = TMath::Abs(xdarray[j]);
171               jmin=j;
172            }       
173         } // j
174         if (xmin != 1001.) {    
175            id[i]=jmin;
176            jx[i]=xarray[jmin]; 
177            jy[i]=yarray[jmin]; 
178            jq[i]=qarray[jmin]; 
179            jid[i]=idx[jmin];
180         } 
181     
182     }  // i
183   
184     for (i=0;i<3;i++){
185         if (jid[i] == -2) {
186             xarray[i]=1001.;
187             yarray[i]=1001.;
188             qarray[i]=1001.;
189             idx[i]=-1;
190         } else {
191             xarray[i]=jx[i];
192             yarray[i]=jy[i];
193             qarray[i]=jq[i];
194             idx[i]=jid[i];
195         }
196     }
197
198 }
199
200 //____________________________________________________
201 Int_t AliMUONRawCluster::PhysicsContribution() const
202 {
203 /// Evaluate physics contribution to cluster
204   Int_t iPhys=0;
205   Int_t iBg=0;
206   Int_t iMixed=0;
207   for (Int_t i=0; i<fMultiplicity[0]; i++) {
208     if (fPhysicsMap[i]==2) iPhys++;
209     if (fPhysicsMap[i]==1) iMixed++;
210     if (fPhysicsMap[i]==0) iBg++;
211   }
212   if (iMixed==0 && iBg==0) {
213     return 2;
214   } else if ((iPhys != 0 && iBg !=0) || iMixed != 0) {
215     return 1;
216   } else {
217     return 0;
218   }
219 }
220
221 //____________________________________________________
222 void AliMUONRawCluster::Print(Option_t* opt) const
223 {
224   ///
225   /// Printing Raw Cluster (Rec Point) information 
226   /// "full" option for printing all the information about the raw cluster
227   ///
228   TString sopt(opt);
229   sopt.ToUpper();
230  
231   cout << Form("<AliMUONRawCluster>: DetEle=%4d (x,y,z)=(%7.4f,%7.4f,%7.4f) cm"
232                " Chi2=%7.2f Q=%7.2f",
233                GetDetElemId(),GetX(),GetY(),GetZ(),GetChi2(),
234                GetCharge());
235                
236   if ( sopt.Contains("FULL") )
237   {
238     cout << ", Hit=" << setw(4)  << GetTrack(0) <<
239     ", Track1=" <<  setw(4)  << GetTrack(1) <<
240     ", Track2=" <<  setw(4)  << GetTrack(2);
241   }
242   cout << endl;
243 }
244
245 //____________________________________________________
246 void AliMUONRawCluster::DumpIndex(void)
247 {
248 /// Dumping IdexMap of the cluster
249     printf ("-----\n");
250     for (Int_t icat=0;icat<2;icat++) {
251         printf ("Mult %d\n",fMultiplicity[icat]);
252         for (Int_t idig=0;idig<fMultiplicity[icat];idig++){
253             printf("Index %d",fIndexMap[idig][icat]);
254         }
255         printf("\n");
256     }
257 }
258 //____________________________________________________
259 Int_t AliMUONRawCluster::AddCharge(Int_t i, Float_t Q)
260 {
261 /// Adding Q to the fQ value
262   if (i==0 || i==1) {
263     fQ[i]+=Q;
264     return 1;
265   }
266   else  return 0;
267 }
268 //____________________________________________________
269 Int_t AliMUONRawCluster::AddX(Int_t i, Float_t X)
270 {
271 /// Adding X to the fX value
272   if (i==0 || i==1) {
273     fX[i]+=X;
274     return 1;
275   }
276   else  return 0;
277 }
278 //____________________________________________________
279 Int_t AliMUONRawCluster::AddY(Int_t i, Float_t Y)
280 {
281 /// Adding Y to the fY value 
282   if (i==0 || i==1) {
283     fY[i]+=Y;
284     return 1;
285   }
286   else return 0;
287 }
288 //____________________________________________________
289 Int_t AliMUONRawCluster::AddZ(Int_t i, Float_t Z)
290 {
291 /// Adding Z to the fZ value
292   if (i==0 || i==1) {
293     fZ[i]+=Z;
294     return 1;
295   }
296   else return 0;
297 }
298 //____________________________________________________
299 Float_t AliMUONRawCluster::GetCharge(Int_t i) const
300 {
301 /// Getting the charge of the cluster
302   if (i==0 || i==1) return fQ[i];
303   else  return 99999;
304 }
305 //____________________________________________________
306 Float_t AliMUONRawCluster::GetX(Int_t i)  const
307 {
308 /// Getting X value of the cluster
309   if (i==0 || i==1) return fX[i];
310   else  return 99999.;
311 }
312 //____________________________________________________
313 Float_t AliMUONRawCluster::GetY(Int_t i) const 
314 {
315 /// Getting Y value of the cluster
316   if (i==0 || i==1) return fY[i];
317   else  return 99999.;
318 }
319 //____________________________________________________
320 Float_t AliMUONRawCluster::GetZ(Int_t i) const 
321 {
322 /// Getting Z value of the cluster
323   if (i==0 || i==1) return fZ[i];
324   else  return 99999.;
325 }
326 //____________________________________________________
327 Int_t AliMUONRawCluster::GetTrack(Int_t i) const 
328 {
329 /// Getting track i contributing to the cluster
330   if (i==0 || i==1 || i==2) return fTracks[i];
331   else  return 99999;
332 }
333 //____________________________________________________
334 Float_t AliMUONRawCluster::GetPeakSignal(Int_t i) const 
335 {
336 /// Getting cluster peaksignal
337   if (i==0 || i==1 ) return fPeakSignal[i];
338   else  return 99999;
339 }
340 //____________________________________________________
341 Int_t AliMUONRawCluster::GetMultiplicity(Int_t i) const 
342 {
343 /// Getting cluster multiplicity
344   if (i==0 || i==1 ) return fMultiplicity[i];
345   else  return 99999;
346 }
347 //____________________________________________________
348 Int_t AliMUONRawCluster::GetClusterType() const 
349 {
350 /// Getting Cluster Type
351   return fClusterType;
352 }
353 //____________________________________________________
354 Int_t AliMUONRawCluster::GetGhost() const 
355 {
356 /// Getting Ghost
357   return fGhost;
358 }
359 //____________________________________________________
360 Int_t AliMUONRawCluster::GetNcluster(Int_t i) const 
361 {
362 /// Getting number of clusters
363   if (i==0 || i==1 ) return fNcluster[i];
364   else  return 99999;
365 }
366 //____________________________________________________
367 Float_t AliMUONRawCluster::GetChi2(Int_t i) const 
368 {
369 /// Getting chi2 value of the cluster
370   if (i==0 || i==1) return fChi2[i];
371   else  return 99999.;
372 }
373 //____________________________________________________
374 Int_t AliMUONRawCluster::SetCharge(Int_t i, Float_t Q)
375 {
376 /// Setting Charge of the cluster
377   if (i==0 || i==1) {
378     fQ[i]=Q;
379     return 1;
380   }
381   else  return 0;
382 }
383 //____________________________________________________
384 Int_t AliMUONRawCluster::SetX(Int_t i, Float_t X)
385 {
386 /// Setting X value of the cluster
387   if (i==0 || i==1) {
388     fX[i]=X;
389     return 1;
390   }
391   else  return 0;
392 }
393 //____________________________________________________
394 Int_t AliMUONRawCluster::SetY(Int_t i, Float_t Y)
395 {
396 /// Setting Y value of the cluster
397   if (i==0 || i==1) {
398     fY[i]=Y;
399     return 1;
400   }
401   else return 0;
402 }
403 //____________________________________________________
404 Int_t AliMUONRawCluster::SetZ(Int_t i, Float_t Z)
405 {
406 /// Setting Z value of the cluste
407   if (i==0 || i==1) {
408     fZ[i]=Z;
409     return 1;
410   }
411   else return 0;
412 }
413 //____________________________________________________
414 Int_t AliMUONRawCluster::SetTrack(Int_t i, Int_t track)
415 {
416 /// Setting tracks contributing to the cluster
417   if (i==0 || i==1 || i==2) {
418     fTracks[i]=track;
419     return 1;
420   }
421   else return 0;
422 }
423 //____________________________________________________
424 Int_t AliMUONRawCluster::SetPeakSignal(Int_t i, Float_t peaksignal)
425 {
426 /// Setting PeakSignal of the cluster
427   if (i==0 || i==1 ) {
428     fPeakSignal[i]=peaksignal;
429     return 1;
430   }
431   else return 0;
432 }
433 //____________________________________________________
434 Int_t AliMUONRawCluster::SetMultiplicity(Int_t i, Int_t mul)
435 {
436 /// Setting multiplicity of the cluster
437   if (i==0 || i==1 ) {
438     fMultiplicity[i]=mul;
439     return 1;
440   }
441   else return 0;
442 }
443 //____________________________________________________
444 Int_t AliMUONRawCluster::SetClusterType(Int_t type)
445 {
446 /// Setting the cluster type
447   fClusterType=type;
448   return 1;
449 }
450 //____________________________________________________
451 Int_t AliMUONRawCluster::SetGhost(Int_t ghost)
452 {
453 /// Setting the ghost
454   fGhost=ghost;
455   return 1;
456 }
457 //____________________________________________________
458 Int_t AliMUONRawCluster::SetNcluster(Int_t i, Int_t ncluster)
459 {
460 /// Setting number the cluster
461   if (i==0 || i==1 ) {
462     fNcluster[i]=ncluster;
463     return 1;
464   }
465   else return 0;
466 }
467 //____________________________________________________
468 Int_t AliMUONRawCluster::SetChi2(Int_t i, Float_t chi2)
469 {
470 /// Setting chi2 of the cluster
471   if (i==0 || i==1) {
472     fChi2[i]=chi2;
473     return 1;
474   }
475   else return 0;
476 }
477
478