1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include <TObjArray.h>
19 #include <TClonesArray.h>
20 #include "AliMUONDetElement.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"
33 ClassImp(AliMUONDetElement) // Class implementation in ROOT context
34 FILE *lun = 0x0; //fopen("hitmap.dat","w");
36 //_________________________________________________________________________
37 AliMUONDetElement::AliMUONDetElement()
40 // Default constructor
41 for (Int_t i = 0; i < 2; i++) {
46 fRawClus = fHitsForRec = NULL;
50 //_________________________________________________________________________
51 AliMUONDetElement::AliMUONDetElement(Int_t idDE, AliMUONDigit *dig, AliMUONClusterFinderAZ *recModel)
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);
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);
68 fSeg[dig->Cathode()]->GetPadC(fidDE, dig->PadX(), dig->PadY(), x, y, z);
73 //_________________________________________________________________________
74 AliMUONDetElement::~AliMUONDetElement()
77 for (Int_t i = 0; i < 2; i++) {
78 delete fHitMap[i]; fHitMap[i] = NULL;
79 delete fDigits[i]; fDigits[i] = NULL;
81 if (fRawClus) { fRawClus->Delete(); delete fRawClus; fRawClus = 0; }
82 //if (fRawClus) { delete fRawClus; fRawClus = 0; }
83 delete fHitsForRec; fHitsForRec = 0;
86 //_________________________________________________________________________
87 AliMUONDetElement::AliMUONDetElement (const AliMUONDetElement& rhs)
92 AliFatal("Not implemented.");
95 //________________________________________________________________________
96 AliMUONDetElement & AliMUONDetElement::operator = (const AliMUONDetElement& rhs)
98 // Assignement operator
100 if (this == &rhs) return *this;
101 AliFatal( "Not implemented.");
105 //_________________________________________________________________________
106 Int_t AliMUONDetElement::Compare(const TObject* detElem) const
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);
116 //_________________________________________________________________________
117 void AliMUONDetElement::Fill(AliMUONData */*data*/)
120 fLeft[0] = fDigits[0]->GetEntriesFast();
121 fLeft[1] = fDigits[1]->GetEntriesFast();
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();
128 // The part below is just for debugging (fill rec. points already found)
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
141 cout << fHitsForRec->GetEntriesFast() << endl;
146 //_________________________________________________________________________
147 void AliMUONDetElement::AddDigit(AliMUONDigit *dig)
151 fDigits[dig->Cathode()]->Add(dig);
154 //_________________________________________________________________________
155 Bool_t AliMUONDetElement::Inside(Double_t x, Double_t y, Double_t z) const
157 // Check if point is inside detection element
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;
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;
183 //_________________________________________________________________________
184 void AliMUONDetElement::ClusterReco(Double_t xTrack, Double_t yTrack)
186 // Run cluster reconstruction around point (x,y)
188 if (fLeft[0] == 0 && fLeft[1] == 0) return; // all digits have been used
190 dx = dy = 5; // 5 cm for now
191 AliMUONClusterInput::Instance()->SetDigits(fChamber, fidDE,
192 (TClonesArray*)fDigits[0], (TClonesArray*)fDigits[1]);
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);
206 fRecModel->ResetRawClusters();
208 for (Int_t cath = 0; cath < 2; cath++) {
209 if (fDigits[cath]->GetEntriesFast() == 0) continue; // empty cathode
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;
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);
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;
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);
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());
251 } // for (fSeg[cath]->FirstPad(...
252 } // for (Int_t cath = 0;
255 //_________________________________________________________________________
256 void AliMUONDetElement::AddHitForRec(AliMUONRawCluster *clus)
258 // Make HitForRec from raw cluster (rec. point)
260 fRawClus->Add(new AliMUONRawCluster(*clus));
261 AliMUONHitForRec *hitForRec =
262 new ((*fHitsForRec)[fNHitsForRec++]) AliMUONHitForRec(clus);
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
277 //_________________________________________________________________________
278 Int_t AliMUONDetElement::GetMapElem(AliMUONDigit *digit)
280 Int_t cath = digit->Cathode();
285 //_________________________________________________________________________
286 void AliMUONDetElement::SetMapElem(const AliMUONDigit *digit, Int_t flag)
288 Int_t cath = digit->Cathode();