- Adding hits pattern in trigger chambers in AliMUONTrack (Diego)
[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"
41#include "AliMUONData.h"
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//______________________________________________________________________________
74AliMUONTrackHitPattern::AliMUONTrackHitPattern(AliMUONData *data)
75 : TObject(),
76 fMUONData(data),
77 fTransformer(new AliMUONGeometryTransformer(kTRUE)),
78 fCrateManager(new AliMUONTriggerCrateStore())
79{
80 /// Default constructor
81
82 // Set magnetic field
83 const AliMagF* kField = AliTracker::GetFieldMap();
84 if (!kField) AliFatal("No field available");
85 AliMUONTrackExtrap::SetField(kField);
86
87 // Geometry transformer
88 fTransformer->ReadGeometryData("volpath.dat", "geometry.root");
89
90 // Crate manager to retrieve local boards
91 fCrateManager->ReadFromFile();
92
93 for(Int_t ch=0; ch<4; ch++){
94 fTriggerDigitsList[ch].Clear();
95 }
96}
97
98
99//______________________________________________________________________________
100AliMUONTrackHitPattern::~AliMUONTrackHitPattern(void)
101{
102/// Destructor
103 for(Int_t ch=0; ch<4; ch++){
104 fTriggerDigitsList[ch].Delete();
105 }
106 delete fCrateManager;
107}
108
109
110//______________________________________________________________________________
111void AliMUONTrackHitPattern::GetHitPattern(TClonesArray *recTracksPtr)
112{
113 //
114 /// Main method:
115 /// Loops on reco tracks, extrapolates them to trigger chambers
116 /// and searches for matching digits
117 //
118
119 const Int_t mask[2][4]={{0x80, 0x40, 0x20, 0x10},
120 {0x08, 0x04, 0x02, 0x01}};
121 Bool_t isMatch[2];
122 UShort_t pattern=0;
123 TriggerDigits();
124 Int_t nRecTracks = (Int_t)recTracksPtr->GetEntriesFast();
125 for(Int_t iTrack=0; iTrack<nRecTracks; iTrack++){
126 pattern = 0;
127 AliMUONTrack *muonTrack = (AliMUONTrack*) recTracksPtr->At(iTrack);
128 AliMUONTrackParam *trackParam = (AliMUONTrackParam*) ((muonTrack->GetTrackParamAtHit())->Last());
129 for(Int_t ch=0; ch<4; ch++){
130 AliMUONTrackExtrap::ExtrapToZCov(trackParam, AliMUONConstants::DefaultChamberZ(10+ch));
131 FindPadMatchingTrack(trackParam, isMatch, ch);
132 for(Int_t cath=0; cath<2; cath++){
133 if(isMatch[cath]) pattern |= mask[cath][ch];
134 }
135 }
136 muonTrack->SetHitsPatternInTrigCh(pattern);
137 }
138 return;
139}
140
141
142//______________________________________________________________________________
143void AliMUONTrackHitPattern::FindPadMatchingTrack(AliMUONTrackParam *trackParam,
144 Bool_t isMatch[2], Int_t iChamber)
145{
146 //
147 /// Given track position, searches for matching digits.
148 //
149
150 Float_t minMatchDist[2];
151
152 for(Int_t cath=0; cath<2; cath++){
153 isMatch[cath]=kFALSE;
154 minMatchDist[cath]=9999.;
155 }
156
157 Int_t ndigits = (Int_t)fTriggerDigitsList[iChamber].GetEntries();
158 AliMUONDigit * mDigit = 0x0;
159 for(Int_t idigit=0; idigit<ndigits; idigit++) { // digit loop
160 mDigit = (AliMUONDigit*)fTriggerDigitsList[iChamber].At(idigit);
161 Int_t currDetElemId = mDigit->DetElemId();
162
163 Int_t cathode = mDigit->Cathode();
164 Int_t ix = mDigit->PadX();
165 Int_t iy = mDigit->PadY();
166 Float_t xpad, ypad, zpad;
167 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()
168 ->GetMpSegmentation(currDetElemId,AliMp::GetCathodType(cathode));
169
170 AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy),kTRUE);
171 Float_t xlocal1 = pad.Position().X();
172 Float_t ylocal1 = pad.Position().Y();
173 Float_t dpx = pad.Dimensions().X();
174 Float_t dpy = pad.Dimensions().Y();
175 fTransformer->Local2Global(currDetElemId, xlocal1, ylocal1, 0, xpad, ypad, zpad);
176 Float_t matchDist = MinDistanceFromPad(xpad, ypad, zpad, dpx, dpy, trackParam);
177 if(matchDist>minMatchDist[cathode])continue;
178 isMatch[cathode] = kTRUE;
179 minMatchDist[cathode] = matchDist;
180 }
181
182 return;
183}
184
185
186//______________________________________________________________________________
187Float_t AliMUONTrackHitPattern::MinDistanceFromPad(Float_t xPad, Float_t yPad, Float_t zPad,
188 Float_t dpx, Float_t dpy, AliMUONTrackParam *trackParam)
189{
190 //
191 /// Decides if the digit belongs to the track.
192 //
193 Float_t xTrackAtPad = trackParam->GetNonBendingCoor();
194 Float_t yTrackAtPad = trackParam->GetBendingCoor();
195
196 Float_t sigmaX, sigmaY, sigmaMS;
197 GetPosUncertainty(trackParam, zPad, sigmaX, sigmaY, sigmaMS);
198
199 Float_t maxDistX = 3.*(sigmaX + sigmaMS); // in cm
200 Float_t maxDistY = 3.*(sigmaY + sigmaMS); // in cm
201
202 Float_t deltaX = TMath::Abs(xPad-xTrackAtPad)-dpx;
203 Float_t deltaY = TMath::Abs(yPad-yTrackAtPad)-dpy;
204
205 Float_t matchDist = 99999.;
206 if(deltaX<=maxDistX && deltaY<=maxDistY) matchDist = TMath::Max(deltaX, deltaY);
207 return matchDist;
208}
209
210
211//______________________________________________________________________________
212void AliMUONTrackHitPattern::GetPosUncertainty(AliMUONTrackParam *trackParam, Float_t zChamber,
213 Float_t &sigmaX, Float_t &sigmaY, Float_t &sigmaMS)
214{
215 //
216 /// Returns uncertainties on extrapolated position.
217 /// Takes into account Branson plane corrections in the iron wall.
218 //
219
220 const Float_t alpha = 0.1123; // GeV/c
221
222 // Find a better way to get such parameters ???
223 const Float_t kZFilterIn = 1471.; // From STRUCT/SHILConst2.h
224 const Float_t kZFilterOut = kZFilterIn + 120.; // From STRUCT/SHILConst2.h
225
226 const Float_t zBranson = - (kZFilterIn + (kZFilterOut - kZFilterIn)*2./3. ); // - sign because distance are positive
227 Float_t zDistFromWall = TMath::Abs(zChamber - zBranson);
228 Float_t zDistFromLastTrackCh = TMath::Abs(zChamber - AliMUONConstants::DefaultChamberZ(9));
229
230 TMatrixD *covParam = trackParam->GetCovariances();
231
232 sigmaX = (*covParam)(0,0);
233 sigmaY = (*covParam)(2,2);
234
235 // If covariance matrix is not extrapolated, use "reasonable" errors
236 // (To be removed as soon as covariance matrix is correctly propagated).
237 if (sigmaX==0.)sigmaX = 0.003 * zDistFromLastTrackCh;
238 if (sigmaY==0.)sigmaY = 0.004 * zDistFromLastTrackCh;
239
240 Float_t p = trackParam->P();
241 Float_t thetaMS = alpha/p;
242 sigmaMS = zDistFromWall * TMath::Tan(thetaMS);
243
244 return;
245}
246
247
248//____________________________________________________________________
249Bool_t AliMUONTrackHitPattern::TriggerDigits()
250{
251 //
252 /// make (S)Digit for trigger
253 //
254
255 Int_t nBoard;
256
257 TList digitList;
258
259 AliMUONDigitMaker* digitMaker = new AliMUONDigitMaker(); // should be put as member in class
260
261 AliMUONLocalTrigger *locTrg = 0x0;
262
263 fMUONData->SetTreeAddress("RC,TC");
264 fMUONData->GetTrigger();
265
266 TClonesArray *localTrigger = fMUONData->LocalTrigger();
267 Int_t nLocTrig = (Int_t) localTrigger->GetEntriesFast();
268
269 for(Int_t iLoc=0; iLoc<nLocTrig; iLoc++) {
270 locTrg = (AliMUONLocalTrigger*)localTrigger->UncheckedAt(iLoc);
271
272 TArrayS xyPattern[2];
273 xyPattern[0].Set(4);
274 xyPattern[1].Set(4);
275
276 xyPattern[0].AddAt(locTrg->GetX1Pattern(),0);
277 xyPattern[0].AddAt(locTrg->GetX2Pattern(),1);
278 xyPattern[0].AddAt(locTrg->GetX3Pattern(),2);
279 xyPattern[0].AddAt(locTrg->GetX4Pattern(),3);
280
281 xyPattern[1].AddAt(locTrg->GetY1Pattern(),0);
282 xyPattern[1].AddAt(locTrg->GetY2Pattern(),1);
283 xyPattern[1].AddAt(locTrg->GetY3Pattern(),2);
284 xyPattern[1].AddAt(locTrg->GetY4Pattern(),3);
285
286 digitList.Clear();
287 nBoard = locTrg->LoCircuit();
288 digitMaker->TriggerDigits(nBoard, xyPattern, digitList);
289
290
291 } // loop on localTriggers
292
293 for (Int_t iEntry = 0; iEntry < digitList.GetEntries(); ++iEntry) {
294 AliMUONDigit* digit = (AliMUONDigit*)digitList.At(iEntry);
295 Int_t detElemId = digit->DetElemId();
296 Int_t iChamber = detElemId/100 - 1; //FIXEME should be given by mapping
297 fTriggerDigitsList[iChamber].Add(digit);
298
299 }
300
301 return kTRUE;
302}