]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTrackHitPattern.cxx
Updated list of MUON libraries
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackHitPattern.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 ////////////////////////////////////
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 "AliMUONRecData.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
69 ClassImp(AliMUONTrackHitPattern) // Class implementation in ROOT context
70 /// \endcond
71
72
73 //______________________________________________________________________________
74 AliMUONTrackHitPattern::AliMUONTrackHitPattern(AliMUONRecData *data)
75     : TObject(),
76       fMUONData(data),
77       fTransformer(new AliMUONGeometryTransformer(kTRUE)),
78       fCrateManager(new AliMUONTriggerCrateStore()),
79       fDigitMaker(new AliMUONDigitMaker())
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
94     // set to digit maker
95     fDigitMaker->SetCrateManager(fCrateManager);
96
97     for(Int_t ch=0; ch<4; ch++){
98         fTriggerDigitsList[ch].Clear();
99     }
100 }
101
102
103 //______________________________________________________________________________
104 AliMUONTrackHitPattern::~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 //______________________________________________________________________________
115 void 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     
123     const Int_t kMask[2][4]={{0x80, 0x40, 0x20, 0x10},
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++){
137                 if(isMatch[cath]) pattern |= kMask[cath][ch];
138             }
139         }
140         muonTrack->SetHitsPatternInTrigCh(pattern);
141     }
142     return;
143 }
144
145
146 //______________________________________________________________________________
147 void 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 //______________________________________________________________________________
191 Float_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 //______________________________________________________________________________
216 void 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
224     const Float_t kAlpha = 0.1123; // GeV/c
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     
230     const Float_t kZBranson = - (kZFilterIn + (kZFilterOut - kZFilterIn)*2./3. ); // - sign because distance are positive
231     Float_t zDistFromWall = TMath::Abs(zChamber - kZBranson);
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();
245     Float_t thetaMS = kAlpha/p;
246     sigmaMS = zDistFromWall * TMath::Tan(thetaMS);
247
248     return;
249 }
250
251
252 //____________________________________________________________________
253 Bool_t AliMUONTrackHitPattern::TriggerDigits()
254 {
255     //
256     /// make (S)Digit for trigger
257     //
258
259
260     Int_t nBoard;
261
262     TList digitList;
263
264     digitList.Clear();
265
266     AliMUONLocalTrigger *locTrg = 0x0;
267
268     fMUONData->SetTreeAddress("RC,TC");
269     fMUONData->GetTrigger();
270
271     TClonesArray *localTrigger = fMUONData->LocalTrigger();
272     Int_t nLocTrig = (Int_t) localTrigger->GetEntriesFast();
273
274     for(Int_t iLoc=0; iLoc<nLocTrig; iLoc++) {
275       locTrg = (AliMUONLocalTrigger*)localTrigger->UncheckedAt(iLoc);
276
277       TArrayS xyPattern[2];
278       xyPattern[0].Set(4);
279       xyPattern[1].Set(4);
280
281       xyPattern[0].AddAt(locTrg->GetX1Pattern(),0);
282       xyPattern[0].AddAt(locTrg->GetX2Pattern(),1);
283       xyPattern[0].AddAt(locTrg->GetX3Pattern(),2);
284       xyPattern[0].AddAt(locTrg->GetX4Pattern(),3);
285
286       xyPattern[1].AddAt(locTrg->GetY1Pattern(),0);
287       xyPattern[1].AddAt(locTrg->GetY2Pattern(),1);
288       xyPattern[1].AddAt(locTrg->GetY3Pattern(),2);
289       xyPattern[1].AddAt(locTrg->GetY4Pattern(),3);
290
291       for(Int_t cath=0; cath<2; cath++){
292           for(Int_t ch=0; ch<4; ch++){
293               if(xyPattern[cath][ch]==0) continue;
294           }
295       }
296
297       nBoard    = locTrg->LoCircuit();
298       fDigitMaker->TriggerDigits(nBoard, xyPattern, digitList);
299
300
301     } // loop on localTriggers
302
303     for (Int_t iEntry = 0; iEntry < digitList.GetEntries(); ++iEntry) {
304       AliMUONDigit* digit = (AliMUONDigit*)digitList.At(iEntry);
305       Int_t detElemId = digit->DetElemId();
306       Int_t iChamber  = detElemId/100 - 11; //FIXEME should be given by mapping
307       fTriggerDigitsList[iChamber].Add(digit);
308
309     }
310
311     return kTRUE;
312 }