Fixing coding convention violation and adding Clear method (Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackHitPattern.cxx
CommitLineData
7771752e 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////////////////////////////////////
17///
18/// \class AliMUONTrackHitPattern
19///
20/// This class propagates tracks to trigger chambers
21/// searching for fired strips.
22///
23/// To each track, a hit pattern for trigger chambers is set.
24/// The hit pattern is a UShort_t with 8 bits used:
25///
26/// 1 1 0 1 1 1 0 1
27/// | | |
28/// ----------- ------------
29/// chamber: 11 12 13 14 | 11 12 13 14
30/// cathode: bending | non-bending
31///
32/// The main method is:
33/// * GetHitPattern
34///
35/// \author Diego Stocco
36///
37////////////////////////////////////
38
39
40#include "AliMUONTrackHitPattern.h"
803eec57 41#include "AliMUONRecData.h"
7771752e 42#include "AliMUONTrack.h"
43#include "AliMUONTrackParam.h"
44#include "AliMUONTrackExtrap.h"
45#include "AliMUONConstants.h"
46#include "AliMUONGeometryTransformer.h"
47#include "AliMUONDigit.h"
48#include "AliMUONLocalTrigger.h"
49#include "AliMUONTriggerCrateStore.h"
50#include "AliMUONLocalTriggerBoard.h"
51#include "AliMUONTriggerCircuit.h"
52#include "AliMUONDigitMaker.h"
53
54#include "AliMpPad.h"
55#include "AliMpVSegmentation.h"
56#include "AliMpSegmentation.h"
57
58#include "AliLog.h"
59#include "AliTracker.h"
60#include "AliMagF.h"
61
62#include <Riostream.h>
63#include <TClonesArray.h>
64#include <TMath.h>
65#include <TMatrixD.h>
66#include <TArrayS.h>
67
68/// \cond CLASSIMP
69ClassImp(AliMUONTrackHitPattern) // Class implementation in ROOT context
70/// \endcond
71
72
73//______________________________________________________________________________
803eec57 74AliMUONTrackHitPattern::AliMUONTrackHitPattern(AliMUONRecData *data)
7771752e 75 : TObject(),
76 fMUONData(data),
77 fTransformer(new AliMUONGeometryTransformer(kTRUE)),
a721d89c 78 fCrateManager(new AliMUONTriggerCrateStore()),
79 fDigitMaker(new AliMUONDigitMaker())
7771752e 80{
81 /// Default constructor
82
83 // Set magnetic field
84 const AliMagF* kField = AliTracker::GetFieldMap();
85 if (!kField) AliFatal("No field available");
86 AliMUONTrackExtrap::SetField(kField);
87
88 // Geometry transformer
89 fTransformer->ReadGeometryData("volpath.dat", "geometry.root");
90
91 // Crate manager to retrieve local boards
92 fCrateManager->ReadFromFile();
93
a721d89c 94 // set to digit maker
95 fDigitMaker->SetCrateManager(fCrateManager);
96
7771752e 97 for(Int_t ch=0; ch<4; ch++){
98 fTriggerDigitsList[ch].Clear();
99 }
100}
101
102
103//______________________________________________________________________________
104AliMUONTrackHitPattern::~AliMUONTrackHitPattern(void)
105{
106/// Destructor
107 for(Int_t ch=0; ch<4; ch++){
108 fTriggerDigitsList[ch].Delete();
109 }
110 delete fCrateManager;
111}
112
113
114//______________________________________________________________________________
115void AliMUONTrackHitPattern::GetHitPattern(TClonesArray *recTracksPtr)
116{
117 //
118 /// Main method:
119 /// Loops on reco tracks, extrapolates them to trigger chambers
120 /// and searches for matching digits
121 //
122
7dc68cf4 123 const Int_t kMask[2][4]={{0x80, 0x40, 0x20, 0x10},
7771752e 124 {0x08, 0x04, 0x02, 0x01}};
125 Bool_t isMatch[2];
126 UShort_t pattern=0;
127 TriggerDigits();
128 Int_t nRecTracks = (Int_t)recTracksPtr->GetEntriesFast();
129 for(Int_t iTrack=0; iTrack<nRecTracks; iTrack++){
130 pattern = 0;
131 AliMUONTrack *muonTrack = (AliMUONTrack*) recTracksPtr->At(iTrack);
132 AliMUONTrackParam *trackParam = (AliMUONTrackParam*) ((muonTrack->GetTrackParamAtHit())->Last());
133 for(Int_t ch=0; ch<4; ch++){
134 AliMUONTrackExtrap::ExtrapToZCov(trackParam, AliMUONConstants::DefaultChamberZ(10+ch));
135 FindPadMatchingTrack(trackParam, isMatch, ch);
136 for(Int_t cath=0; cath<2; cath++){
7dc68cf4 137 if(isMatch[cath]) pattern |= kMask[cath][ch];
7771752e 138 }
139 }
140 muonTrack->SetHitsPatternInTrigCh(pattern);
141 }
142 return;
143}
144
145
146//______________________________________________________________________________
147void AliMUONTrackHitPattern::FindPadMatchingTrack(AliMUONTrackParam *trackParam,
148 Bool_t isMatch[2], Int_t iChamber)
149{
150 //
151 /// Given track position, searches for matching digits.
152 //
153
154 Float_t minMatchDist[2];
155
156 for(Int_t cath=0; cath<2; cath++){
157 isMatch[cath]=kFALSE;
158 minMatchDist[cath]=9999.;
159 }
160
161 Int_t ndigits = (Int_t)fTriggerDigitsList[iChamber].GetEntries();
162 AliMUONDigit * mDigit = 0x0;
163 for(Int_t idigit=0; idigit<ndigits; idigit++) { // digit loop
164 mDigit = (AliMUONDigit*)fTriggerDigitsList[iChamber].At(idigit);
165 Int_t currDetElemId = mDigit->DetElemId();
166
167 Int_t cathode = mDigit->Cathode();
168 Int_t ix = mDigit->PadX();
169 Int_t iy = mDigit->PadY();
170 Float_t xpad, ypad, zpad;
171 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()
172 ->GetMpSegmentation(currDetElemId,AliMp::GetCathodType(cathode));
173
174 AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy),kTRUE);
175 Float_t xlocal1 = pad.Position().X();
176 Float_t ylocal1 = pad.Position().Y();
177 Float_t dpx = pad.Dimensions().X();
178 Float_t dpy = pad.Dimensions().Y();
179 fTransformer->Local2Global(currDetElemId, xlocal1, ylocal1, 0, xpad, ypad, zpad);
180 Float_t matchDist = MinDistanceFromPad(xpad, ypad, zpad, dpx, dpy, trackParam);
181 if(matchDist>minMatchDist[cathode])continue;
182 isMatch[cathode] = kTRUE;
183 minMatchDist[cathode] = matchDist;
184 }
185
186 return;
187}
188
189
190//______________________________________________________________________________
191Float_t AliMUONTrackHitPattern::MinDistanceFromPad(Float_t xPad, Float_t yPad, Float_t zPad,
192 Float_t dpx, Float_t dpy, AliMUONTrackParam *trackParam)
193{
194 //
195 /// Decides if the digit belongs to the track.
196 //
197 Float_t xTrackAtPad = trackParam->GetNonBendingCoor();
198 Float_t yTrackAtPad = trackParam->GetBendingCoor();
199
200 Float_t sigmaX, sigmaY, sigmaMS;
201 GetPosUncertainty(trackParam, zPad, sigmaX, sigmaY, sigmaMS);
202
203 Float_t maxDistX = 3.*(sigmaX + sigmaMS); // in cm
204 Float_t maxDistY = 3.*(sigmaY + sigmaMS); // in cm
205
206 Float_t deltaX = TMath::Abs(xPad-xTrackAtPad)-dpx;
207 Float_t deltaY = TMath::Abs(yPad-yTrackAtPad)-dpy;
208
209 Float_t matchDist = 99999.;
210 if(deltaX<=maxDistX && deltaY<=maxDistY) matchDist = TMath::Max(deltaX, deltaY);
211 return matchDist;
212}
213
214
215//______________________________________________________________________________
216void AliMUONTrackHitPattern::GetPosUncertainty(AliMUONTrackParam *trackParam, Float_t zChamber,
217 Float_t &sigmaX, Float_t &sigmaY, Float_t &sigmaMS)
218{
219 //
220 /// Returns uncertainties on extrapolated position.
221 /// Takes into account Branson plane corrections in the iron wall.
222 //
223
7dc68cf4 224 const Float_t kAlpha = 0.1123; // GeV/c
7771752e 225
226 // Find a better way to get such parameters ???
227 const Float_t kZFilterIn = 1471.; // From STRUCT/SHILConst2.h
228 const Float_t kZFilterOut = kZFilterIn + 120.; // From STRUCT/SHILConst2.h
229
7dc68cf4 230 const Float_t kZBranson = - (kZFilterIn + (kZFilterOut - kZFilterIn)*2./3. ); // - sign because distance are positive
231 Float_t zDistFromWall = TMath::Abs(zChamber - kZBranson);
7771752e 232 Float_t zDistFromLastTrackCh = TMath::Abs(zChamber - AliMUONConstants::DefaultChamberZ(9));
233
234 TMatrixD *covParam = trackParam->GetCovariances();
235
236 sigmaX = (*covParam)(0,0);
237 sigmaY = (*covParam)(2,2);
238
239 // If covariance matrix is not extrapolated, use "reasonable" errors
240 // (To be removed as soon as covariance matrix is correctly propagated).
241 if (sigmaX==0.)sigmaX = 0.003 * zDistFromLastTrackCh;
242 if (sigmaY==0.)sigmaY = 0.004 * zDistFromLastTrackCh;
243
244 Float_t p = trackParam->P();
7dc68cf4 245 Float_t thetaMS = kAlpha/p;
7771752e 246 sigmaMS = zDistFromWall * TMath::Tan(thetaMS);
247
248 return;
249}
250
251
252//____________________________________________________________________
253Bool_t AliMUONTrackHitPattern::TriggerDigits()
254{
255 //
256 /// make (S)Digit for trigger
257 //
258
6650909c 259 for(Int_t ch=0; ch<4; ++ch) fTriggerDigitsList[ch].Clear();
a721d89c 260
7771752e 261 Int_t nBoard;
262
263 TList digitList;
264
a721d89c 265 digitList.Clear();
7771752e 266
267 AliMUONLocalTrigger *locTrg = 0x0;
268
269 fMUONData->SetTreeAddress("RC,TC");
270 fMUONData->GetTrigger();
271
272 TClonesArray *localTrigger = fMUONData->LocalTrigger();
273 Int_t nLocTrig = (Int_t) localTrigger->GetEntriesFast();
274
275 for(Int_t iLoc=0; iLoc<nLocTrig; iLoc++) {
276 locTrg = (AliMUONLocalTrigger*)localTrigger->UncheckedAt(iLoc);
277
278 TArrayS xyPattern[2];
279 xyPattern[0].Set(4);
280 xyPattern[1].Set(4);
281
282 xyPattern[0].AddAt(locTrg->GetX1Pattern(),0);
283 xyPattern[0].AddAt(locTrg->GetX2Pattern(),1);
284 xyPattern[0].AddAt(locTrg->GetX3Pattern(),2);
285 xyPattern[0].AddAt(locTrg->GetX4Pattern(),3);
286
287 xyPattern[1].AddAt(locTrg->GetY1Pattern(),0);
288 xyPattern[1].AddAt(locTrg->GetY2Pattern(),1);
289 xyPattern[1].AddAt(locTrg->GetY3Pattern(),2);
290 xyPattern[1].AddAt(locTrg->GetY4Pattern(),3);
291
a721d89c 292 for(Int_t cath=0; cath<2; cath++){
293 for(Int_t ch=0; ch<4; ch++){
294 if(xyPattern[cath][ch]==0) continue;
295 }
296 }
297
7771752e 298 nBoard = locTrg->LoCircuit();
a721d89c 299 fDigitMaker->TriggerDigits(nBoard, xyPattern, digitList);
7771752e 300
301
302 } // loop on localTriggers
303
304 for (Int_t iEntry = 0; iEntry < digitList.GetEntries(); ++iEntry) {
305 AliMUONDigit* digit = (AliMUONDigit*)digitList.At(iEntry);
306 Int_t detElemId = digit->DetElemId();
a721d89c 307 Int_t iChamber = detElemId/100 - 11; //FIXEME should be given by mapping
7771752e 308 fTriggerDigitsList[iChamber].Add(digit);
309
310 }
311
312 return kTRUE;
313}