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