]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONClusterReconstructor.cxx
- Added handling of tracks and file mask (used when merging different files).
[u/mrichter/AliRoot.git] / MUON / AliMUONClusterReconstructor.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 //
20 // MUON cluster reconstructor for MUON
21 //
22 // Should implement a virtual class ClusterFinder to chose between VS and AZ method
23 ////////////////////////////////////
24
25 #include "AliMUONClusterReconstructor.h"
26 #include "AliRun.h" // for gAlice
27 #include "AliRunLoader.h"
28 #include "AliLoader.h"
29
30 #include "AliMUON.h"
31 #include "AliMUONDigit.h"
32 #include "AliMUONConstants.h"
33 #include "AliMUONData.h"
34 #include "AliMUONClusterFinderVS.h"
35 #include "AliMUONClusterInput.h"
36 #include "AliMUONRawCluster.h"
37 #include "AliLog.h"
38
39 ClassImp(AliMUONClusterReconstructor) // Class implementation in ROOT context
40  
41 //__________________________________________________________________________
42 AliMUONClusterReconstructor::AliMUONClusterReconstructor(AliMUONData* data)
43 : TObject(),
44   fMUONData(data),
45   fRecModel(new AliMUONClusterFinderVS()),
46   fDigitsCath0(new TClonesArray("AliMUONDigit",1000)),
47   fDigitsCath1(new TClonesArray("AliMUONDigit",1000))
48 {
49   // Standard Constructor
50
51   fDigitsCath0->SetOwner(kTRUE); 
52   fDigitsCath1->SetOwner(kTRUE);
53 }
54
55 //_______________________________________________________________________
56 AliMUONClusterReconstructor::AliMUONClusterReconstructor (const AliMUONClusterReconstructor& rhs)
57   : TObject(rhs)
58 {
59 // Protected copy constructor
60
61   AliFatal("Not implemented.");
62 }
63
64 //_______________________________________________________________________
65 AliMUONClusterReconstructor & 
66 AliMUONClusterReconstructor::operator=(const AliMUONClusterReconstructor& rhs)
67 {
68 // Protected assignement operator
69
70   if (this == &rhs) return *this;
71
72   AliFatal("Not implemented.");
73     
74   return *this;  
75 }
76
77 //__________________________________________________________________________
78 AliMUONClusterReconstructor::~AliMUONClusterReconstructor(void)
79 {
80   delete fRecModel;
81   delete fDigitsCath0;
82   delete fDigitsCath1;
83 }
84
85 //______________________________________________________________________________
86 void
87 AliMUONClusterReconstructor::CheckSize(TClonesArray& a)
88 {
89   // 
90   // Check if one can adds a new element, or if a is already full.
91   // If full, it is resized.
92   //
93   if ( a.GetLast()+1 >= a.GetSize() )
94   {
95     AliInfo(Form("Increasing array size from %d to %d",
96                  a.GetSize(),a.GetSize()*2));
97     a.Expand(a.GetSize()*2);
98   }
99 }
100
101 //______________________________________________________________________________
102 void
103 AliMUONClusterReconstructor::ClusterizeOneDE(Int_t detElemId)
104 {
105   //
106   // Clusterize one detection element, and let fMUONData know about
107   // the results.
108   // 
109   
110   if ( fDigitsCath0->GetEntriesFast() || fDigitsCath1->GetEntriesFast() )
111   {
112     Int_t iChamber = detElemId/100 - 1;
113     AliMUONClusterInput::Instance()->SetDigits(iChamber, detElemId,
114                                                fDigitsCath0,fDigitsCath1);
115     AliDebug(3,Form("ClusterizeOneDE iChamber=%d DE=%d",iChamber,detElemId));
116     StdoutToAliDebug(3,cout << "DigitsCath0=" << endl;
117                      fDigitsCath0->Print();
118                      cout << "DigitsCath1=" << endl;
119                      fDigitsCath1->Print(););
120     fRecModel->FindRawClusters();
121     
122     // copy results into the output container
123     TClonesArray* tmp = fRecModel->GetRawClusters();
124     for (Int_t id = 0; id < tmp->GetEntriesFast(); ++id) 
125     {
126       AliMUONRawCluster* pClus = (AliMUONRawCluster*) tmp->At(id);
127       fMUONData->AddRawCluster(iChamber, *pClus);
128     }        
129     
130     // Reset the arrays
131     fDigitsCath0->Clear("C");
132     fDigitsCath1->Clear("C");
133   }
134 }
135
136 //____________________________________________________________________
137 void AliMUONClusterReconstructor::Digits2Clusters(Int_t chBeg)
138 {
139   //
140   // Clusterize all the tracking chamber digits.
141   //
142   // For each chamber, we loop *once* on that chamber digits, and store them
143   // in 2 temporary arrays (one pair of arrays per detection element, 
144   // one array per cathode). Once a pair of arrays is full (i.e. all the digits
145   // of that detection element have been stored), we clusterize this DE, and
146   // move to the next one.
147   //
148   
149   if (!fRecModel)
150   {
151     AliWarning("No reco model defined. Nothing to do...");
152     return;
153   }
154   
155   Int_t iChamber(-1);
156   Int_t currentDE(-1);
157   
158   // Loop on chambers 
159   for ( iChamber = chBeg; iChamber < AliMUONConstants::NTrackingCh(); ++iChamber ) 
160   {
161     TClonesArray* muonDigits = fMUONData->Digits(iChamber); 
162     
163     Int_t ndig = muonDigits->GetEntriesFast();
164     if (!ndig) continue;
165     
166     muonDigits->Sort(); // the sort *must* be per DE (at least), otherwise
167                         // the following logic with currentDE will fail.
168     
169     currentDE = -1; // initialize the DE counter (that is used to track 
170                     // when we change of DE in the following loop over
171                     // all digits) to an invalid value.
172
173     for ( Int_t k = 0; k < ndig; ++k ) 
174     {
175       AliMUONDigit* digit = (AliMUONDigit*) muonDigits->UncheckedAt(k);
176       if ( ! digit->Signal() > 0 ) continue; // skip void digits.
177       
178       if ( digit->DetElemId() != currentDE )
179       {
180         AliDebug(3,Form("Switching DE from %d to %d",currentDE,digit->DetElemId()));
181         // we get to a new DE, so clusterize the previous one before
182         // moving on.
183         ClusterizeOneDE(currentDE);
184         currentDE = digit->DetElemId();
185       }
186       
187       // Add the digit to the array with the right cathode number.
188       if (digit->Cathode() == 0)
189       {
190         CheckSize(*fDigitsCath0);
191         new((*fDigitsCath0)[fDigitsCath0->GetLast()+1]) AliMUONDigit(*digit);
192       }
193       else 
194       {
195         CheckSize(*fDigitsCath1);
196         new((*fDigitsCath1)[fDigitsCath1->GetLast()+1]) AliMUONDigit(*digit);
197       }
198     } // end of loop on chamber digits
199     
200     // As the above logic is based on detecting a change in DE number,
201     // the last DE of each chamber has not been clusterized, so we do 
202     // it here.
203     ClusterizeOneDE(currentDE);
204   } // end of loop over chambers
205 }
206
207 //_______________________________________________________________________
208 void 
209 AliMUONClusterReconstructor::SetRecoModel(AliMUONClusterFinderVS* rec)
210
211   delete fRecModel; 
212   fRecModel = rec;
213
214
215 //_______________________________________________________________________
216 void AliMUONClusterReconstructor::Trigger2Trigger() 
217 {
218 // copy trigger from TreeD to TreeR
219
220   fMUONData->SetTreeAddress("GLT");
221   fMUONData->GetTriggerD();
222 }