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