]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONEventRecoCombi.cxx
- Class description on 5 lines (Coding conventions)
[u/mrichter/AliRoot.git] / MUON / AliMUONEventRecoCombi.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 /* $Id$ */
17
18 // -------------------------------------
19 // Class AliMUONEventRecoCombi
20 // -------------------------------------
21 // Steering class for the combined cluster / track reconstructor
22 // Author: Alexander Zinchenko, JINR Dubna
23
24 #include "AliMUONEventRecoCombi.h"
25
26 #include "AliMUONData.h"
27 #include "AliMUONDetElement.h"
28 #include "AliMUONDigit.h"
29 #include "AliMUONHitForRec.h"
30 #include "AliMUONRawCluster.h"
31 #include "AliMUONTrackK.h"
32 #include "AliMUONTrackReconstructor.h"
33 #include "AliMUONConstants.h"
34
35 #include "AliLoader.h"
36
37 #include <Riostream.h>
38 #include <TClonesArray.h>
39 #include <TArrayS.h>
40 #include <TArrayD.h>
41 #include "AliLog.h"
42
43 AliMUONEventRecoCombi* AliMUONEventRecoCombi::fgRecoCombi = 0; 
44
45 ClassImp(AliMUONEventRecoCombi)
46
47 //_________________________________________________________________________
48 AliMUONEventRecoCombi::AliMUONEventRecoCombi() : TObject()
49 {
50   // Ctor
51
52   fDetElems = new TClonesArray("AliMUONDetElement", 20);
53   fZ = new TArrayD(20);
54   fNZ = 0;
55   fDEvsZ = NULL;
56 }
57
58 //_________________________________________________________________________
59 AliMUONEventRecoCombi* AliMUONEventRecoCombi::Instance()
60 {
61 // return pointer to the singleton instance
62
63   if (fgRecoCombi == 0) {
64     fgRecoCombi = new AliMUONEventRecoCombi();
65   }
66   //fDetElems = new TClonesArray("AliMUONDetElement", 20);
67   //fZ = new TArrayD(20);
68   //fNZ = 0;
69   return fgRecoCombi;
70 }
71
72 //_________________________________________________________________________
73 AliMUONEventRecoCombi::~AliMUONEventRecoCombi()
74 {
75   // Destructor
76   delete fDetElems;
77   delete fZ;
78   delete [] fDEvsZ;
79 }
80
81 //_________________________________________________________________________
82 AliMUONEventRecoCombi::AliMUONEventRecoCombi (const AliMUONEventRecoCombi& rhs)
83   : TObject(rhs)
84 {
85   // Protected copy constructor
86   AliFatal("Not implemented.");
87 }
88
89 //_________________________________________________________________________
90 AliMUONEventRecoCombi & AliMUONEventRecoCombi::operator = (const AliMUONEventRecoCombi& rhs)
91 {
92   // Protected assignment operator
93
94   // check assignement to self
95   if (this == &rhs) return *this;
96
97   AliFatal("Not implemented.");
98
99   return *this;
100 }
101
102 //_________________________________________________________________________
103 void AliMUONEventRecoCombi::FillEvent(AliMUONData *data, AliMUONClusterFinderAZ *recModel)
104 {
105   // Fill event information
106
107   // Clear previous event
108   fDetElems->Delete();
109   for (Int_t i = 0; i < fNZ; i++) delete [] fDEvsZ[i];
110   delete [] fDEvsZ; fDEvsZ = NULL;
111   fNZ = -1;
112
113   Int_t nDetElem = 0;
114   for (Int_t ich = 0; ich < 6; ich++) {
115     // loop over chambers 0-5
116     TClonesArray *digs = data->Digits(ich);
117     //cout << ich << " " << digs << " " << digs->GetEntriesFast() << endl;
118     Int_t idDE = -1;
119     for (Int_t i = 0; i < digs->GetEntriesFast(); i++) {
120       AliMUONDigit *dig = (AliMUONDigit*) digs->UncheckedAt(i);
121       if (dig->DetElemId() != idDE) {
122         idDE = dig->DetElemId();
123         new ((*fDetElems)[nDetElem++]) AliMUONDetElement(idDE, dig, recModel);
124       }
125       else ((AliMUONDetElement*)fDetElems->UncheckedAt(nDetElem-1))->AddDigit(dig);
126     }
127   }
128
129   // Sort according to Z
130   fDetElems->Sort();
131   //cout << nDetElem << endl;
132   // Fill det. elems. position index in the container
133   for (Int_t i = 0; i < nDetElem; i++) 
134     ((AliMUONDetElement*)fDetElems->UncheckedAt(i))->SetIndex(i);
135
136   // Find groups of det. elements with the same Z
137   Double_t z0 = -99999;
138   TArrayS *nPerZ = new TArrayS(20);
139   for (Int_t i = 0; i < nDetElem; i++) {
140     AliMUONDetElement *detElem = (AliMUONDetElement*) fDetElems->UncheckedAt(i);
141     detElem->Fill(data);
142     //cout << i << " " << detElem->Z() << endl;
143     if (detElem->Z() - z0 < 0.5) { 
144       // the same Z
145       (*nPerZ)[fNZ]++;
146     } else {
147       if (fZ->GetSize() <= fNZ) fZ->Set(fZ->GetSize()+10);
148       if (nPerZ->GetSize() <= fNZ) nPerZ->Set(nPerZ->GetSize()+10);
149       (*fZ)[++fNZ] = detElem->Z();
150       z0 = detElem->Z();
151       (*nPerZ)[fNZ]++;
152     }
153   }
154   fNZ++;
155   /*
156   cout << fNZ << endl;
157   for (Int_t i = 0; i < 7; i++) {
158     cout << i << " " << data->RawClusters(i)->GetEntriesFast() << endl;
159   }
160   */
161
162   // Build list of DE locations vs Z
163   fDEvsZ = new Int_t* [fNZ];
164   Int_t iPos = 0;
165   for (Int_t i = 0; i < fNZ; i++) {
166     Int_t *idPerZ = new Int_t[(*nPerZ)[i]+1]; 
167     for (Int_t j = 1; j < (*nPerZ)[i]+1; j++) idPerZ[j] = iPos++;
168     idPerZ[0] = (*nPerZ)[i]; // number of DE's as first element of array
169     fDEvsZ[i] = idPerZ;
170     //cout << (*nPerZ)[i] << " ";
171   }
172   //cout << endl;
173   delete nPerZ;
174
175   // Fill rec. point container for stations 4 and 5
176   //cout << data->TreeR() << endl;
177   //data->MakeBranch("RC");
178   data->SetTreeAddress("RCC");
179   for (Int_t ch = 6; ch < 10; ch++) {
180     TClonesArray *raw = data->RawClusters(ch);
181     //cout << raw->GetEntriesFast() << " " << data->RawClusters(ch) << endl;
182     for (Int_t i = 0; i < raw->GetEntriesFast(); i++) {
183       AliMUONRawCluster *clus = (AliMUONRawCluster*) raw->UncheckedAt(i);
184       data->AddRawCluster(ch, *clus);
185     }
186   }
187   //data->SetTreeAddress("RC");
188 }
189
190 //_________________________________________________________________________
191 void AliMUONEventRecoCombi::FillRecP(AliMUONData *dataCluster, AliMUONTrackReconstructor *recoTrack) const
192 {
193   // Fill rec. points used for tracking from det. elems
194
195   TClonesArray *tracks = recoTrack->GetRecTracksPtr();
196   for (Int_t i = 0; i < recoTrack->GetNRecTracks(); i++) {
197     AliMUONTrackK *track = (AliMUONTrackK*) tracks->UncheckedAt(i);
198     TObjArray *hits = track->GetTrackHits();
199     for (Int_t j = 0; j < track->GetNTrackHits(); j++) {
200       AliMUONHitForRec *hit = (AliMUONHitForRec*) hits->UncheckedAt(j);
201       if (hit->GetHitNumber() >= 0) continue;
202       // Combined cluster / track finder
203       Int_t index = -hit->GetHitNumber() / 100000;
204       Int_t iPos = -hit->GetHitNumber() - index * 100000;
205       AliMUONRawCluster *clus = (AliMUONRawCluster*) DetElem(index-1)->RawClusters()->UncheckedAt(iPos);
206       //cout << j << " " << iPos << " " << clus << " " << index << " " << DetElem(index-1)->Chamber() << endl; 
207       dataCluster->AddRawCluster(DetElem(index-1)->Chamber(), *clus);
208     }
209   }
210   /*
211   for (Int_t ch = 0; ch < 10; ch++) {
212     TClonesArray *raw = dataCluster->RawClusters(ch);
213     cout << ch << " " << raw->GetEntriesFast() << endl;
214   }
215   */
216   // Reset raw cluster tree
217   /*
218   char branchname[30];
219   TBranch * branch = 0x0;
220   if ( dataCluster->TreeR()) {
221     if ( dataCluster->IsTriggerBranchesInTree() ) {
222       // Branch per branch filling
223       for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
224         sprintf(branchname,"%sRawClusters%d",dataCluster->GetName(),i+1);
225         branch = dataCluster->TreeR()->GetBranch(branchname);
226         //branch->Fill();
227         //branch->Reset();
228         //branch->Clear();
229         branch->Delete();
230       }
231     }
232     //else  TreeR()->Fill();
233     else  dataCluster->TreeR()->Reset();
234   }
235   */
236 }
237
238 //_________________________________________________________________________
239 Int_t AliMUONEventRecoCombi::IZfromHit(AliMUONHitForRec *hit) const
240 {
241   // Get Iz of det. elem. from the hit
242
243   Int_t index = -hit->GetHitNumber() / 100000 - 1, iz0 = -1;
244   for (Int_t iz = 0; iz < fNZ; iz++) {
245     Int_t *pDEatZ = DEatZ(iz);
246     Int_t nDetElem = pDEatZ[-1];
247     for (Int_t j = 0; j < nDetElem; j++) {
248       if (pDEatZ[j] != index) continue;
249       iz0 = iz;
250       break;
251     }
252     if (iz0 >= 0) break;
253   }
254   return iz0;
255 }