]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDetElement.cxx
track matching macros from Alberto
[u/mrichter/AliRoot.git] / MUON / AliMUONDetElement.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 AliMUONDetElement
20 // --------------------------
21 // Detection element object containing information for combined 
22 // cluster / track finder in MUON arm 
23 // Author: Alexander Zinchenko, JINR Dubna
24  
25
26 #include <TObjArray.h>
27 #include <TClonesArray.h>
28 #include "AliMUONDetElement.h"
29 #include "AliMUON.h"
30 #include "AliMUONSegmentation.h"
31 #include "AliMUONDigit.h"
32 #include "AliMUONHitMapA1.h"
33 #include "AliMUONRawCluster.h"
34 #include "AliMUONHitForRec.h"
35 #include "AliMUONClusterInput.h"
36 #include "AliMUONClusterFinderAZ.h"
37 #include "AliRun.h"
38 #include "AliLog.h"
39
40 ClassImp(AliMUONDetElement) // Class implementation in ROOT context
41
42 //_________________________________________________________________________
43 AliMUONDetElement::AliMUONDetElement()
44   : TObject(),
45     fidDE(0),
46     fIndex(0),
47     fChamber(0),
48     fZ(0.),
49     fNHitsForRec(0),
50     fRawClus(0x0),
51     fHitsForRec(0x0),
52     fRecModel(0x0)
53 {
54 /// Default constructor
55   for (Int_t i = 0; i < 2; i++) {
56     fHitMap[i] = NULL;
57     fDigits[i] = NULL;
58     fSeg[i] = NULL;
59   }
60
61
62 //_________________________________________________________________________
63 AliMUONDetElement::AliMUONDetElement(Int_t idDE, AliMUONDigit *dig, AliMUONClusterFinderAZ *recModel) 
64   : TObject(),
65     fidDE(idDE),
66     fIndex(0),
67     fChamber(idDE / 100 - 1),
68     fZ(0.),
69     fNHitsForRec(0),
70     fRawClus(0x0),
71     fHitsForRec(0x0),
72     fRecModel(recModel)
73 {
74 /// Constructor
75   fDigits[0] = new TObjArray(10);
76   fDigits[1] = new TObjArray(10);
77   fRawClus = new TObjArray(10);
78   fHitsForRec = new TClonesArray("AliMUONHitForRec",10);
79   AliMUON *pMUON = (AliMUON*) gAlice->GetModule("MUON");
80   AliMUONSegmentation *pSegmentation = pMUON->GetSegmentation();
81   fSeg[0] = pSegmentation->GetModuleSegmentation(fChamber, 0);
82   fSeg[1] = pSegmentation->GetModuleSegmentation(fChamber, 1);
83   Float_t x, y, z;
84   fSeg[dig->Cathode()]->GetPadC(fidDE, dig->PadX(), dig->PadY(), x, y, z);
85   fZ = z;
86   AddDigit(dig);
87 }
88
89 //_________________________________________________________________________
90 AliMUONDetElement::~AliMUONDetElement()
91 {
92 /// Destructor
93   for (Int_t i = 0; i < 2; i++) {
94     delete fHitMap[i]; fHitMap[i] = NULL; 
95     delete fDigits[i]; fDigits[i] = NULL; 
96   }
97   if (fRawClus) { fRawClus->Delete(); delete fRawClus; fRawClus = 0; }
98   //if (fRawClus) { delete fRawClus; fRawClus = 0; }
99   delete fHitsForRec; fHitsForRec = 0;
100 }
101
102 //_________________________________________________________________________
103 Int_t AliMUONDetElement::Compare(const TObject* detElem) const
104 {
105 /// "Compare" function to sort in Z (towards interaction point)
106 /// Returns -1 (0, +1) if charge of current pixel
107 /// is greater than (equal to, less than) charge of pixel
108   if (fZ > ((AliMUONDetElement*)detElem)->Z()) return(+1);
109   else if (fZ == ((AliMUONDetElement*)detElem)->Z()) return( 0);
110   else return(-1);
111 }
112
113 //_________________________________________________________________________
114 void AliMUONDetElement::Fill(AliMUONData */*data*/)
115 {
116 /// Fill hit maps
117   fLeft[0] = fDigits[0]->GetEntriesFast();
118   fLeft[1] = fDigits[1]->GetEntriesFast();
119
120   Int_t  npx0  = fSeg[0]->Npx(fidDE)+1;
121   Int_t  npy0  = fSeg[0]->Npy(fidDE)+1;
122   fHitMap[0] = new AliMUONHitMapA1(npx0, npy0, fDigits[0]);
123   fHitMap[0]->FillHits();
124
125   Int_t  npx1  = fSeg[1]->Npx(fidDE)+1;
126   Int_t  npy1  = fSeg[1]->Npy(fidDE)+1;
127   fHitMap[1] = new AliMUONHitMapA1(npx1, npy1, fDigits[1]);
128   fHitMap[1]->FillHits();
129
130   // The part below is just for debugging (fill rec. points already found)
131   /*
132   fLeft[0] = fLeft[1] = 0;
133   TClonesArray *rawClus = data->RawClusters(fChamber);
134   cout << rawClus << " " << rawClus->GetEntriesFast() << endl;
135   for (Int_t i = 0; i < rawClus->GetEntriesFast(); i++) {
136     AliMUONRawCluster *recP = (AliMUONRawCluster*) rawClus->UncheckedAt(i);
137     cout << fChamber << " " << recP->GetZ(0) << " " << recP->GetZ(1) << " " << fZ << endl;
138     if (TMath::Abs(recP->GetZ(0)-fZ) > 0.5) continue;
139     if (!Inside(recP->GetX(0), recP->GetY(0), recP->GetZ(0))) continue;
140     AddHitForRec(recP); // add hit for rec.
141     rawClus->RemoveAt(i); // remove
142   }
143   cout << fHitsForRec->GetEntriesFast() << endl;
144   rawClus->Compress();
145   */
146 }
147
148 //_________________________________________________________________________
149 void AliMUONDetElement::AddDigit(AliMUONDigit *dig)
150 {
151 /// Add digit
152
153   fDigits[dig->Cathode()]->Add(dig);
154 }
155
156 //_________________________________________________________________________
157 Bool_t AliMUONDetElement::Inside(Double_t x, Double_t y, Double_t z) const
158 {
159 /// Check if point is inside detection element
160
161   Int_t ix, iy;
162   for (Int_t i = 0; i < 2; i++) {
163     if (!fSeg[i]) continue;
164     fSeg[i]->GetPadI(fidDE, x, y, z, ix, iy);
165     //cout << x << " " << y << " " << z << " " << fChamber << " " << ix << " " << iy << " " << fSeg[i]->Npx(fidDE) << " " << fSeg[i]->Npy(fidDE) /*<< " " << fSeg[i]->GetPadI(fidDE, x, y, z, ix, iy)*/ << endl; 
166     if (ix > 0 && iy > 0 && ix <= fSeg[i]->Npx(fidDE) && iy <= fSeg[i]->Npy(fidDE)) return kTRUE;
167   }
168   // Check for edge effect (extrapolated track "right outside" det. elem. boundaries (+- 1cm in X and Y)
169   for (Int_t i = 0; i < 2; i++) {
170     if (!fSeg[i]) continue;
171     for (Int_t idx = -1; idx < 2; idx++) {
172       Double_t x1 = x + 1. * idx;
173       for (Int_t idy = -1; idy < 2; idy++) {
174         if (idx == 0 && idy == 0) continue;
175         Double_t y1 = y + 1. * idy;
176         fSeg[i]->GetPadI(fidDE, x1, y1, z, ix, iy);
177         //cout << x1 << " " << y1 << " " << z << " " << fChamber << " " << ix << " " << iy << " " << fSeg[i]->Npx(fidDE) << " " << fSeg[i]->Npy(fidDE) /*<< " " << fSeg[i]->GetPadI(fidDE, x, y, z, ix, iy)*/ << endl; 
178         if (ix > 0 && iy > 0 && ix <= fSeg[i]->Npx(fidDE) && iy <= fSeg[i]->Npy(fidDE)) return kTRUE;
179       }
180     }
181   }
182   return kFALSE;
183 }
184
185 //_________________________________________________________________________
186 void AliMUONDetElement::ClusterReco(Double_t xTrack, Double_t yTrack)
187 {
188 /// Run cluster reconstruction around point (x,y)
189
190   if (fLeft[0] == 0 && fLeft[1] == 0) return; // all digits have been used 
191   Float_t dx, dy;
192   dx = dy = 5; // 5 cm for now 
193   AliMUONClusterInput::Instance()->SetDigits(fChamber, fidDE, 
194              (TClonesArray*)fDigits[0], (TClonesArray*)fDigits[1]);
195
196   // Mark used pads
197   for (Int_t cath = 0; cath < 2; cath++) {
198     if (fDigits[cath]->GetEntriesFast() == 0) continue; // empty cathode
199     for (Int_t i = 0; i < fDigits[cath]->GetEntriesFast(); i++) {
200       if (fLeft[cath] == 0) { fRecModel->SetUsed(cath,i); continue; }
201       AliMUONDigit *dig = (AliMUONDigit*) fDigits[cath]->UncheckedAt(i);
202       //cout << i << " " << dig->PadX() << " " << dig->PadY() << " " << fHitMap[cath]->TestHit(dig->PadX(), dig->PadY()) << endl;
203       if (fHitMap[cath]->TestHit(dig->PadX(), dig->PadY()) == kUsed) fRecModel->SetUsed(cath,i);
204       else fRecModel->SetUnused(cath,i);
205     }
206   }
207
208   fRecModel->ResetRawClusters();
209
210   for (Int_t cath = 0; cath < 2; cath++) {
211     if (fDigits[cath]->GetEntriesFast() == 0) continue; // empty cathode
212     // Loop over pads
213     for (fSeg[cath]->FirstPad(fidDE, xTrack, yTrack, fZ, dx, dy);
214          fSeg[cath]->MorePads(fidDE);
215          fSeg[cath]->NextPad(fidDE)) {
216       if (fLeft[cath] == 0) break;
217       //cout << cath << " " << fSeg[cath]->Ix() << " " << fSeg[cath]->Iy() << " " << fSeg[cath]->DetElemId() << " " << fHitMap[cath]->TestHit(fSeg[cath]->Ix(), fSeg[cath]->Iy()) << endl;
218       if (fHitMap[cath]->TestHit(fSeg[cath]->Ix(), fSeg[cath]->Iy()) == kEmpty ||
219           fHitMap[cath]->TestHit(fSeg[cath]->Ix(), fSeg[cath]->Iy()) == kUsed) continue;
220
221       // Set starting pad
222       for (Int_t j = 0; j < fDigits[cath]->GetEntriesFast(); j++) {
223         AliMUONDigit *dig = (AliMUONDigit*) fDigits[cath]->UncheckedAt(j);
224         if (dig->PadX() != fSeg[cath]->Ix() || dig->PadY() != fSeg[cath]->Iy()) continue;
225         //cout << fidDE << " " << j << " " << fSeg[cath]->Ix() << " " << fSeg[cath]->Iy() << endl;
226         fRecModel->SetStart(cath, j);
227         break;
228       }
229
230       fRecModel->FindRawClusters();
231       Int_t nClusEnd = fRecModel->GetRawClusters()->GetEntriesFast();
232       //cout << " ***nclus: " << nClusEnd << endl;
233       for (Int_t i = 0; i < nClusEnd; i++) {
234         AliMUONRawCluster *clus = (AliMUONRawCluster*) fRecModel->GetRawClusters()->UncheckedAt(i);
235         AddHitForRec(clus); // add hit for rec.
236         //cout << clus->GetX(0) << " " << clus->GetY(0) << endl;
237       }
238       // Mark used pads
239       for (Int_t cath1 = 0; cath1 < 2; cath1++) {
240         for (Int_t j = 0; j < fDigits[cath1]->GetEntriesFast(); j++) {
241           if (fLeft[cath1] == 0) break;
242           AliMUONDigit *dig = (AliMUONDigit*) fDigits[cath1]->UncheckedAt(j);
243           Float_t x, y, z;
244           fSeg[cath1]->GetPadC(fidDE,dig->PadX(),dig->PadY(),x,y,z);
245           //cout << "clus " << cath1 << " " << fLeft[cath1] << " " << dig->PadX() << " " << dig->PadY() << " " << x << " " << y << " " << z << " " << fRecModel->GetUsed(cath1,j) << endl;
246           if (!fRecModel->GetUsed(cath1,j)) continue;
247           if (fHitMap[cath1]->TestHit(dig->PadX(), dig->PadY()) == kUsed) continue;
248           fHitMap[cath1]->FlagHit(dig->PadX(), dig->PadY());
249           AliDebug(10,Form(" %d %d %d %d \n", cath1, fidDE, dig->PadX(), dig->PadY()));
250           fLeft[cath1]--;
251         }
252       }
253     } // for (fSeg[cath]->FirstPad(...
254   } // for (Int_t cath = 0;
255 }
256
257 //_________________________________________________________________________
258 void AliMUONDetElement::AddHitForRec(AliMUONRawCluster *clus)
259 {
260 /// Make HitForRec from raw cluster (rec. point)
261
262   fRawClus->Add(new AliMUONRawCluster(*clus));
263   AliMUONHitForRec *hitForRec = 
264     new ((*fHitsForRec)[fNHitsForRec++]) AliMUONHitForRec(clus);
265
266   // more information into HitForRec
267   //  resolution: info should be already in raw cluster and taken from it ????
268   hitForRec->SetBendingReso2(-1); //fBendingResolution * fBendingResolution);
269   hitForRec->SetNonBendingReso2(-1); //fNonBendingResolution * fNonBendingResolution);
270   //  original raw cluster
271   hitForRec->SetChamberNumber(fChamber);
272   hitForRec->SetZ(clus->GetZ(0));
273   //hitForRec->SetHitNumber(-(fIndex+1)*100000-fNHitsForRec+1);
274   hitForRec->SetHitNumber(-(fIndex+1)*100000-fRawClus->GetEntriesFast()+1);
275   //delete clus; // for now
276 }
277
278 /*
279 //_________________________________________________________________________
280 Int_t AliMUONDetElement::GetMapElem(AliMUONDigit *digit)
281 {
282   Int_t cath = digit->Cathode();
283   return 0;
284
285 }
286
287 //_________________________________________________________________________
288 void AliMUONDetElement::SetMapElem(const AliMUONDigit *digit, Int_t flag)
289 {
290   Int_t cath = digit->Cathode();
291 }
292 */