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