]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONClusterReconstructor.cxx
Inserting TMath.h where required by the new version of ROOT
[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 // Class AliMUONClusterReconstructor
20 // ----------------------------------
21 // MUON cluster reconstructor for MUON
22 // Should implement a virtual class ClusterFinder to choose between VS and AZ method
23
24 #include <Riostream.h>
25 #include "AliMUONClusterReconstructor.h"
26 #include "AliRunLoader.h"
27 #include "AliLoader.h"
28
29 #include "AliMUONDigit.h"
30 #include "AliMUONConstants.h"
31 #include "AliMUONData.h"
32 #include "AliMUONClusterFinderVS.h"
33 #include "AliMUONClusterInput.h"
34 #include "AliMUONRawCluster.h"
35 #include "AliMUONVClusterFinder.h"
36 #include "AliMUONCluster.h"
37 #include "AliMpDEManager.h"
38 #include "AliMpSegmentation.h"
39 #include "AliMUONGeometryTransformer.h"
40 #include "AliLog.h"
41
42 /// \cond CLASSIMP
43 ClassImp(AliMUONClusterReconstructor) // Class implementation in ROOT context
44 /// \endcond
45  
46 //__________________________________________________________________________
47 AliMUONClusterReconstructor::AliMUONClusterReconstructor(AliMUONData* data,
48                                                          AliMUONVClusterFinder* clusterFinder,
49                                                          const AliMUONGeometryTransformer* transformer)
50 : TObject(),
51   fClusterFinder(clusterFinder),
52   fMUONData(data),
53   fRecModel(new AliMUONClusterFinderVS()),
54   fDigitsCath0(new TClonesArray("AliMUONDigit",1000)),
55   fDigitsCath1(new TClonesArray("AliMUONDigit",1000)),
56   fTransformer(transformer)
57 {
58 /// Standard Constructor
59
60   fDigitsCath0->SetOwner(kTRUE); 
61   fDigitsCath1->SetOwner(kTRUE);
62   if (!transformer && clusterFinder)
63   {
64     AliFatal("I require a geometry transformer, otherwise I cannot compute "
65              "global coordinates of the clusters !");    
66   }
67 }
68
69 //__________________________________________________________________________
70 AliMUONClusterReconstructor::~AliMUONClusterReconstructor(void)
71 {
72 /// Destructor
73
74   delete fRecModel;
75   delete fDigitsCath0;
76   delete fDigitsCath1;
77 }
78
79 //______________________________________________________________________________
80 void
81 AliMUONClusterReconstructor::ClusterizeOneDEV2(Int_t detElemId)
82 {
83   AliDebug(1,Form("DE %d",detElemId));
84   const AliMpVSegmentation* seg[2] = 
85   { AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,0),
86     AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,1)
87   };
88   
89   
90   TClonesArray* digits[2] = { fDigitsCath0, fDigitsCath1 };
91   
92   Bool_t ok = fClusterFinder->Prepare(seg,digits);
93   if ( !ok )
94   {
95     AliWarning(Form("No hit pad for DE %d ?",detElemId));
96   }
97   
98   AliMUONCluster* cluster;
99   
100   Int_t chamber = detElemId/100 - 1;
101   
102   while ( ( cluster = fClusterFinder->NextCluster() ) )
103   {
104     StdoutToAliDebug(1,cout << "From AliMUONClusterReconstructor::ClusterizeOneDEV2 : cluster->Print():" << endl;
105                      cluster->Print(););
106     
107     // Converts cluster objects into ones suitable for output
108     //
109     AliMUONRawCluster rawCluster;
110     
111     rawCluster.SetDetElemId(detElemId);
112     
113     for ( Int_t cathode = 0; cathode < 2; ++cathode )
114     {
115       rawCluster.SetMultiplicity(cathode,cluster->Multiplicity(cathode));
116       rawCluster.SetCharge(cathode,cluster->Charge()); // both cathode get the total cluster charge
117       Double_t xg, yg, zg;
118       
119       fTransformer->Local2Global(detElemId, 
120                                  cluster->Position().X(), cluster->Position().Y(), 
121                                  0, xg, yg, zg);
122       
123       if ( cathode == 0 )
124       {
125         AliDebug(1,Form("Adding RawCluster detElemId %4d mult %2d charge %e (xl,yl,zl)=(%e,%e,%e) (xg,yg,zg)=(%e,%e,%e)",
126                         detElemId,cluster->Multiplicity(),cluster->Charge(),
127                         cluster->Position().X(),cluster->Position().Y(),0.0,
128                         xg,yg,zg));
129       }
130       rawCluster.SetX(cathode,xg);
131       rawCluster.SetY(cathode,yg);
132       rawCluster.SetZ(cathode,zg);      
133     }
134     fMUONData->AddRawCluster(chamber,rawCluster);
135     delete cluster;
136   }
137 }
138
139 //______________________________________________________________________________
140 void
141 AliMUONClusterReconstructor::ClusterizeOneDE(Int_t detElemId)
142 {
143 /// Clusterize one detection element, and let fMUONData know about
144 /// the results.
145   
146   if ( fDigitsCath0->GetEntriesFast() || fDigitsCath1->GetEntriesFast() )
147   {
148     if ( fClusterFinder )
149     {
150       ClusterizeOneDEV2(detElemId);
151     }
152     else
153     {
154       Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
155       AliMUONClusterInput::Instance()->SetDigits(iChamber, detElemId,
156                                                  fDigitsCath0,fDigitsCath1);
157       AliDebug(3,Form("ClusterizeOneDE iChamber=%d DE=%d",iChamber,detElemId));
158       StdoutToAliDebug(3,cout << "DigitsCath0=" << endl;
159                        fDigitsCath0->Print();
160                        cout << "DigitsCath1=" << endl;
161                        fDigitsCath1->Print(););
162       fRecModel->FindRawClusters();
163       
164       // copy results into the output container
165       TClonesArray* tmp = fRecModel->GetRawClusters();
166       for (Int_t id = 0; id < tmp->GetEntriesFast(); ++id) 
167       {
168         AliMUONRawCluster* pClus = (AliMUONRawCluster*) tmp->At(id);
169         fMUONData->AddRawCluster(iChamber, *pClus);
170       }        
171     }
172     // Reset the arrays
173     fDigitsCath0->Clear("C");
174     fDigitsCath1->Clear("C");
175   }
176 }
177
178 //____________________________________________________________________
179 void AliMUONClusterReconstructor::Digits2Clusters(Int_t chBeg)
180 {
181 /// Clusterize all the tracking chamber digits.
182 ///
183 /// For each chamber, we loop *once* on that chamber digits, and store them
184 /// in 2 temporary arrays (one pair of arrays per detection element, 
185 /// one array per cathode). Once a pair of arrays is full (i.e. all the digits
186 /// of that detection element have been stored), we clusterize this DE, and
187 /// move to the next one.
188   
189   if (!fRecModel && !fClusterFinder)
190   {
191     AliWarning("No reco model defined. Nothing to do...");
192     return;
193   }
194   
195   Int_t iChamber(-1);
196   Int_t currentDE(-1);
197   
198   // Loop on chambers 
199   for ( iChamber = chBeg; iChamber < AliMUONConstants::NTrackingCh(); ++iChamber ) 
200   {
201     TClonesArray* muonDigits = fMUONData->Digits(iChamber); 
202     
203     Int_t ndig = muonDigits->GetEntriesFast();
204     if (!ndig) continue;
205     
206     muonDigits->Sort(); // the sort *must* be per DE (at least), otherwise
207                         // the following logic with currentDE will fail.
208     
209     currentDE = -1; // initialize the DE counter (that is used to track 
210                     // when we change of DE in the following loop over
211                     // all digits) to an invalid value.
212
213     for ( Int_t k = 0; k < ndig; ++k ) 
214     {
215       AliMUONDigit* digit = (AliMUONDigit*) muonDigits->UncheckedAt(k);
216       if ( ! digit->Signal() > 0 ) continue; // skip void digits.
217       
218       if ( digit->DetElemId() != currentDE )
219       {
220         AliDebug(3,Form("Switching DE from %d to %d",currentDE,digit->DetElemId()));
221         // we get to a new DE, so clusterize the previous one before
222         // moving on.
223         ClusterizeOneDE(currentDE);
224         currentDE = digit->DetElemId();
225       }
226       
227       // Add the digit to the array with the right cathode number.
228       if (digit->Cathode() == 0)
229       {
230         new((*fDigitsCath0)[fDigitsCath0->GetLast()+1]) AliMUONDigit(*digit);
231       }
232       else 
233       {
234         new((*fDigitsCath1)[fDigitsCath1->GetLast()+1]) AliMUONDigit(*digit);
235       }
236     } // end of loop on chamber digits
237     
238     // As the above logic is based on detecting a change in DE number,
239     // the last DE of each chamber has not been clusterized, so we do 
240     // it here.
241     ClusterizeOneDE(currentDE);
242   } // end of loop over chambers
243 }
244
245 //_______________________________________________________________________
246 void 
247 AliMUONClusterReconstructor::SetRecoModel(AliMUONClusterFinderVS* rec)
248
249 /// Set reconstruction model
250
251   delete fRecModel; 
252   fRecModel = rec;
253
254
255 //_______________________________________________________________________
256 void AliMUONClusterReconstructor::Trigger2Trigger() 
257 {
258 /// Copy trigger from TreeD to TreeR
259
260   fMUONData->SetTreeAddress("GLT");
261   fMUONData->GetTriggerD();
262 }