]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON.cxx
New class to make V2 clusters starting from digits or hits (fast simulation). Origin...
[u/mrichter/AliRoot.git] / MUON / AliMUON.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 $Log$
17 Revision 1.58  2002/10/21 09:01:33  alibrary
18 Getting rid of unused variable
19
20 Revision 1.57  2002/10/14 14:57:29  hristov
21 Merging the VirtualMC branch to the main development branch (HEAD)
22
23 Revision 1.56.6.2  2002/07/24 10:07:20  alibrary
24 Updating VirtualMC
25
26 Revision 1.56.6.1  2002/06/10 15:10:14  hristov
27 Merged with v3-08-02
28
29 Revision 1.56  2001/11/22 11:26:28  jchudoba
30 Proper deletion of arrays, deletion of unused variables (thanks to Rene Brun)
31
32 Revision 1.55  2001/09/07 08:38:30  hristov
33 Pointers initialised to 0 in the default constructors
34
35 Revision 1.54  2001/08/30 09:52:12  hristov
36 The operator[] is replaced by At() or AddAt() in case of TObjArray.
37
38 Revision 1.53  2001/07/20 10:03:13  morsch
39 Changes needed to work with Root 3.01 (substitute lhs [] operator). (Jiri Chudoba)
40
41 Revision 1.52  2001/06/14 13:49:22  hristov
42 Write a TreeD in SDigits2Digits method (needed to be compatible with alirun script)
43
44 Revision 1.51  2001/05/31 10:19:52  morsch
45 Fix for new AliRun::RunReco().
46
47 Revision 1.50  2001/05/16 14:57:17  alibrary
48 New files for folders and Stack
49
50 Revision 1.49  2001/03/12 17:45:48  hristov
51 Changes needed on Sun with CC 5.0
52
53 Revision 1.48  2001/03/06 00:01:36  morsch
54 Add  Digits2Reco() and FindClusters()
55 Adapt call of cluster finder to new STEER.
56
57 Revision 1.47  2001/03/05 08:38:36  morsch
58 Digitization related methods moved to AliMUONMerger.
59
60 Revision 1.46  2001/01/26 21:34:59  morsch
61 Use access functions for AliMUONHit, AliMUONDigit and AliMUONPadHit data members.
62
63 Revision 1.45  2001/01/26 20:00:49  hristov
64 Major upgrade of AliRoot code
65
66 Revision 1.44  2001/01/25 17:39:09  morsch
67 Pass size of fNdch and fNrawch to CINT.
68
69 Revision 1.43  2001/01/23 18:58:19  hristov
70 Initialisation of some pointers
71
72 Revision 1.42  2001/01/17 20:53:40  hristov
73 Destructors corrected to avoid memory leaks
74
75 Revision 1.41  2000/12/21 22:12:40  morsch
76 Clean-up of coding rule violations,
77
78 Revision 1.40  2000/11/29 20:32:26  gosset
79 Digitize:
80 1. correction for array index out of bounds
81 2. one printout commented
82
83 Revision 1.39  2000/11/12 17:17:03  pcrochet
84 BuildGeometry of AliMUON for trigger chambers delegated to AliMUONSegmentationTriggerX (same strategy as for tracking chambers)
85
86 Revision 1.38  2000/11/06 09:20:43  morsch
87 AliMUON delegates part of BuildGeometry() to AliMUONSegmentation using the
88 Draw() method. This avoids code and parameter replication.
89
90 Revision 1.37  2000/10/26 09:53:37  pcrochet
91 put back trigger chambers in the display (there was a problem in buildgeometry)
92
93 Revision 1.36  2000/10/25 19:51:18  morsch
94 Correct x-position of chambers.
95
96 Revision 1.35  2000/10/24 19:46:21  morsch
97 BuildGeometry updated for slats in station 3-4.
98
99 Revision 1.34  2000/10/18 11:42:06  morsch
100 - AliMUONRawCluster contains z-position.
101 - Some clean-up of useless print statements during initialisations.
102
103 Revision 1.33  2000/10/09 14:01:57  morsch
104 Unused variables removed.
105
106 Revision 1.32  2000/10/06 09:08:10  morsch
107 Built geometry includes slat geometry for event display.
108
109 Revision 1.31  2000/10/02 21:28:08  fca
110 Removal of useless dependecies via forward declarations
111
112 Revision 1.30  2000/10/02 16:58:29  egangler
113 Cleaning of the code :
114 -> coding conventions
115 -> void Streamers
116 -> some useless includes removed or replaced by "class" statement
117
118 Revision 1.29  2000/07/28 13:49:38  morsch
119 SetAcceptance defines inner and outer chamber radii according to angular acceptance.
120 Can be used for simple acceptance studies.
121
122 Revision 1.28  2000/07/22 16:43:15  morsch
123 Same comment as before, but now done correctly I hope (sorry it's Saturday evening)
124
125 Revision 1.27  2000/07/22 16:36:50  morsch
126 Change order of indices in creation (new) of xhit and yhit
127
128 Revision 1.26  2000/07/03 11:54:57  morsch
129 AliMUONSegmentation and AliMUONHitMap have been replaced by AliSegmentation and AliHitMap in STEER
130 The methods GetPadIxy and GetPadXxy of AliMUONSegmentation have changed name to GetPadI and GetPadC.
131
132 Revision 1.25  2000/06/29 12:34:09  morsch
133 AliMUONSegmentation class has been made independent of AliMUONChamber. This makes
134 it usable with any other geometry class. The link to the object to which it belongs is
135 established via an index. This assumes that there exists a global geometry manager
136 from which the pointer to the parent object can be obtained (in our case gAlice).
137
138 Revision 1.24  2000/06/28 15:16:35  morsch
139 (1) Client code adapted to new method signatures in AliMUONSegmentation (see comments there)
140 to allow development of slat-muon chamber simulation and reconstruction code in the MUON
141 framework. The changes should have no side effects (mostly dummy arguments).
142 (2) Hit disintegration uses 3-dim hit coordinates to allow simulation
143 of chambers with overlapping modules (MakePadHits, Disintegration).
144
145 Revision 1.23  2000/06/28 12:19:17  morsch
146 More consequent seperation of global input data services (AliMUONClusterInput singleton) and the
147 cluster and hit reconstruction algorithms in AliMUONClusterFindRawinderVS.
148 AliMUONClusterFinderVS becomes the base class for clustering and hit reconstruction.
149 It requires two cathode planes. Small modifications in the code will make it usable for
150 one cathode plane and, hence, more general (for test beam data).
151 AliMUONClusterFinder is now obsolete.
152
153 Revision 1.22  2000/06/28 08:06:10  morsch
154 Avoid global variables in AliMUONClusterFinderVS by seperating the input data for the fit from the
155 algorithmic part of the class. Input data resides inside the AliMUONClusterInput singleton.
156 It also naturally takes care of the TMinuit instance.
157
158 Revision 1.21  2000/06/27 08:54:41  morsch
159 Problems with on constant array sizes (in hitMap, nmuon, xhit, yhit) corrected.
160
161 Revision 1.20  2000/06/26 14:02:38  morsch
162 Add class AliMUONConstants with MUON specific constants using static memeber data and access methods.
163
164 Revision 1.19  2000/06/22 13:40:51  morsch
165 scope problem on HP, "i" declared once
166 pow changed to TMath::Power (PH, AM)
167
168 Revision 1.18  2000/06/15 07:58:48  morsch
169 Code from MUON-dev joined
170
171 Revision 1.14.4.17  2000/06/14 14:36:46  morsch
172 - add TriggerCircuit (PC)
173 - add GlobalTrigger and LocalTrigger and specific methods (PC)
174
175 Revision 1.14.4.16  2000/06/09 21:20:28  morsch
176 Most coding rule violations corrected
177
178 Revision 1.14.4.15  2000/05/02 09:54:32  morsch
179 RULE RN17 violations corrected
180
181 Revision 1.14.4.12  2000/04/26 12:25:02  morsch
182 Code revised by P. Crochet:
183 - Z position of TriggerChamber changed according to A.Tournaire Priv.Comm.
184 - ToF included in the method MakePadHits
185 - inner radius of flange between beam shielding and trigger corrected
186 - Trigger global volume updated (according to the new geometry)
187
188 Revision 1.14.4.11  2000/04/19 19:42:08  morsch
189 Some changes of variable names curing viols and methods concerning
190 correlated clusters removed.
191
192 Revision 1.14.4.10  2000/03/22 16:44:07  gosset
193 Memory leak suppressed in function Digitise:
194 p_adr->Delete() instead of Clear (I.Chevrot and A.Baldisseri)
195
196 Revision 1.14.4.9  2000/03/20 18:15:25  morsch
197 Positions of trigger chambers corrected (P.C.)
198
199 Revision 1.14.4.8  2000/02/21 15:38:01  morsch
200 Call to AddHitList introduced to make this version compatible with head.
201
202 Revision 1.14.4.7  2000/02/20 07:45:53  morsch
203 Bugs in Trigger part of BuildGeomemetry corrected (P.C)
204
205 Revision 1.14.4.6  2000/02/17 14:28:54  morsch
206 Trigger included into initialization and digitization
207
208 Revision 1.14.4.5  2000/02/15 10:02:58  morsch
209 Log messages of previous revisions added
210
211 Revision 1.14.4.2  2000/02/04 10:57:34  gosset
212 Z position of the chambers:
213 it was the Z position of the stations;
214 it is now really the Z position of the chambers.
215    !!!! WARNING: THE CALLS TO "AliMUONChamber::SetZPOS"
216    !!!!                   AND "AliMUONChamber::ZPosition"
217    !!!! HAVE TO BE CHANGED TO "AliMUONChamber::"SetZ"
218    !!!!                   AND "AliMUONChamber::Z"
219
220 Revision 1.14.4.3  2000/02/04 16:19:04  gosset
221 Correction for mis-spelling of NCH 
222
223 Revision 1.14.4.4  2000/02/15 09:43:38  morsch
224 Log message added
225
226 */
227
228
229 ///////////////////////////////////////////////
230 //  Manager and hits classes for set:MUON     //
231 ////////////////////////////////////////////////
232
233 #include <TTUBE.h>
234 #include <TBRIK.h>
235 #include <TRotMatrix.h>
236 #include <TGeometry.h>
237 #include <TNode.h> 
238 #include <TTree.h> 
239 #include <TRandom.h> 
240 #include <TObject.h>
241 #include <TVector.h>
242 #include <TObjArray.h>
243 #include <TMinuit.h>
244 #include <TParticle.h>
245 #include <TROOT.h>
246 #include <TFile.h>
247 #include <TNtuple.h>
248 #include <TCanvas.h>
249 #include <TPad.h>
250 #include <TDirectory.h>
251 #include <TObjectTable.h>
252 #include <AliPDG.h>
253 #include <TTUBE.h>
254
255 #include "AliMUON.h"
256 #include "AliMUONHit.h"
257 #include "AliMUONPadHit.h"
258 #include "AliMUONDigit.h"
259 #include "AliMUONTransientDigit.h"
260 #include "AliMUONRawCluster.h"
261 #include "AliMUONLocalTrigger.h"
262 #include "AliMUONGlobalTrigger.h"
263 #include "AliMUONTriggerCircuit.h"
264 #include "AliHitMap.h"
265 #include "AliMUONHitMapA1.h"
266 #include "AliMUONChamberTrigger.h"
267 #include "AliMUONConstants.h"
268 #include "AliMUONClusterFinderVS.h"
269 #include "AliMUONTriggerDecision.h"
270 #include "AliRun.h"
271 #include "AliHeader.h"
272 #include "AliMUONClusterInput.h"
273 #include "AliMUONMerger.h"      
274 #include "Riostream.h"
275 #include "AliConst.h" 
276
277 // Defaults parameters for Z positions of chambers
278 // taken from values for "stations" in AliMUON::AliMUON
279 //     const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
280 // and from array "dstation" in AliMUONv1::CreateGeometry
281 //          Float_t dstation[5]={20., 20., 20, 20., 20.};
282 //     for tracking chambers,
283 //          according to (Z1 = zch - dstation) and  (Z2 = zch + dstation)
284 //          for the first and second chambers in the station, respectively,
285 // and from "DTPLANES" in AliMUONv1::CreateGeometry
286 //           const Float_t DTPLANES = 15.;
287 //     for trigger chambers,
288 //          according to (Z1 = zch) and  (Z2 = zch + DTPLANES)
289 //          for the first and second chambers in the station, respectively
290
291 ClassImp(AliMUON)
292 //___________________________________________
293 AliMUON::AliMUON()
294 {
295 // Default Constructor
296 //
297     fNCh             = 0;
298     fNTrackingCh     = 0;
299     fIshunt          = 0;
300     fPadHits         = 0;
301     fNPadHits        = 0;
302     fChambers        = 0;
303     fDchambers       = 0;
304     fTriggerCircuits = 0;  
305     fNdch            = 0;
306     fRawClusters     = 0;
307     fNrawch          = 0;
308     fGlobalTrigger   = 0;
309     fNLocalTrigger   = 0;
310     fLocalTrigger    = 0;
311     fNLocalTrigger   = 0;
312     fAccMin          = 0.;
313     fAccMax          = 0.;   
314     fAccCut          = kFALSE;
315     fMerger          = 0;
316     fFileName        = 0;
317 }
318  
319 //___________________________________________
320 AliMUON::AliMUON(const char *name, const char *title)
321        : AliDetector(name,title)
322 {
323 //Begin_Html
324 /*
325 <img src="gif/alimuon.gif">
326 */
327 //End_Html
328
329    fHits     = new TClonesArray("AliMUONHit",1000);
330    gAlice->AddHitList(fHits);
331    fPadHits = new TClonesArray("AliMUONPadHit",10000);
332    fNPadHits  =  0;
333    fIshunt     =  0;
334
335    fNCh             = AliMUONConstants::NCh(); 
336    fNTrackingCh     = AliMUONConstants::NTrackingCh();
337    fNdch            = new Int_t[fNCh];
338
339    fDchambers = new TObjArray(AliMUONConstants::NCh());
340
341    Int_t i;
342    
343    for (i=0; i<AliMUONConstants::NCh() ;i++) {
344        fDchambers->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
345        fNdch[i]=0;
346    }
347
348    fNrawch      = new Int_t[fNTrackingCh];
349
350    fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
351
352    for (i=0; i<AliMUONConstants::NTrackingCh();i++) {
353        fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i); 
354        fNrawch[i]=0;
355    }
356
357    fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);    
358    fNGlobalTrigger = 0;
359    fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);    
360    fNLocalTrigger = 0;
361
362    SetMarkerColor(kRed);
363 //
364 //
365 //
366 //
367
368     Int_t ch;
369
370     fChambers = new TObjArray(AliMUONConstants::NCh());
371
372     // Loop over stations
373     for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
374       // Loop over 2 chambers in the station
375         for (Int_t stCH = 0; stCH < 2; stCH++) {
376 //
377 //    
378 //    Default Parameters for Muon Tracking Stations
379
380
381             ch = 2 * st + stCH;
382 //
383             if (ch < AliMUONConstants::NTrackingCh()) {
384               fChambers->AddAt(new AliMUONChamber(ch),ch);
385             } else {
386               fChambers->AddAt(new AliMUONChamberTrigger(ch),ch);
387             }
388             
389         //PH        AliMUONChamber* chamber = (AliMUONChamber*) (*fChambers)[ch];
390             AliMUONChamber* chamber = (AliMUONChamber*) fChambers->At(ch);
391             
392             chamber->SetGid(0);
393             // Default values for Z of chambers
394             chamber->SetZ(AliMUONConstants::DefaultChamberZ(ch));
395 //
396             chamber->InitGeo(AliMUONConstants::DefaultChamberZ(ch));
397 //          Set chamber inner and outer radius to default
398             chamber->SetRInner(AliMUONConstants::Dmin(st)/2);
399             chamber->SetROuter(AliMUONConstants::Dmax(st)/2);
400 //
401         } // Chamber stCH (0, 1) in 
402     }     // Station st (0...)
403 //    fChambers->SetLast(AliMUONConstants::NCh());
404     fMaxStepGas=0.01; 
405     fMaxStepAlu=0.1; 
406     fMaxDestepGas=-1;
407     fMaxDestepAlu=-1;
408 //
409    fMaxIterPad   = 0;
410    fCurIterPad   = 0;
411 //
412    fAccMin          = 0.;
413    fAccMax          = 0.;   
414    fAccCut          = kFALSE;
415
416    // cp new design of AliMUONTriggerDecision
417    fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
418    for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
419      fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);     
420
421    }
422      fMerger = 0;
423 }
424  
425 //___________________________________________
426 AliMUON::AliMUON(const AliMUON& rMUON)
427 {
428 // Dummy copy constructor
429     ;
430     
431 }
432
433 AliMUON::~AliMUON()
434 {
435 // Destructor
436     if(fDebug) printf("%s: Calling AliMUON destructor !!!\n",ClassName());
437     
438     fIshunt  = 0;
439  
440     // Delete TObjArrays
441  
442     if (fChambers){
443       fChambers->Delete();
444       delete fChambers;
445     }
446  
447     if (fTriggerCircuits){
448       fTriggerCircuits->Delete();
449       delete fTriggerCircuits;
450     }
451  
452     if (fDchambers){
453       fDchambers->Delete();
454       delete fDchambers;
455     }
456  
457     if (fRawClusters){
458       fRawClusters->Delete();
459       delete fRawClusters;
460     }
461
462     if (fNrawch) delete [] fNrawch;
463  
464     // Delete TClonesArrays
465  
466     if (fPadHits){
467       fPadHits->Delete();
468       delete fPadHits;
469     }
470  
471     if (fGlobalTrigger){
472       fGlobalTrigger->Delete();
473       delete fGlobalTrigger;
474     }
475     fNGlobalTrigger = 0;
476     
477     if (fLocalTrigger){
478       fLocalTrigger->Delete();
479       delete fLocalTrigger;
480     }
481     fNLocalTrigger = 0;
482
483     if (fHits) {
484       fHits->Delete();
485       delete fHits;
486     }
487
488     if (fMerger) delete fMerger;
489     if (fNdch) delete [] fNdch;
490
491 }
492  
493 //___________________________________________
494 void AliMUON::AddHit(Int_t track, Int_t *vol, Float_t *hits)
495 {
496   TClonesArray &lhits = *fHits;
497   new(lhits[fNhits++]) AliMUONHit(fIshunt,track,vol,hits);
498 }
499 //___________________________________________
500 void AliMUON::AddPadHit(Int_t *clhits)
501 {
502    TClonesArray &lclusters = *fPadHits;
503    new(lclusters[fNPadHits++]) AliMUONPadHit(clhits);
504 }
505 //_____________________________________________________________________________
506 void AliMUON::AddDigits(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digits)
507 {
508     //
509     // Add a MUON digit to the list
510     //
511
512   //PH    TClonesArray &ldigits = *((TClonesArray*)(*fDchambers)[id]);
513     TClonesArray &ldigits = *((TClonesArray*)fDchambers->At(id));
514     new(ldigits[fNdch[id]++]) AliMUONDigit(tracks,charges,digits);
515 }
516
517 //_____________________________________________________________________________
518 void AliMUON::AddRawCluster(Int_t id, const AliMUONRawCluster& c)
519 {
520     //
521     // Add a MUON digit to the list
522     //
523
524   //PH    TClonesArray &lrawcl = *((TClonesArray*)(*fRawClusters)[id]);
525     TClonesArray &lrawcl = *((TClonesArray*)fRawClusters->At(id));
526     new(lrawcl[fNrawch[id]++]) AliMUONRawCluster(c);
527 }
528
529 //___________________________________________
530 void AliMUON::AddGlobalTrigger(Int_t *singlePlus, Int_t *singleMinus,
531                                Int_t *singleUndef,
532                                Int_t *pairUnlike, Int_t *pairLike)
533 {
534 // add a MUON Global Trigger to the list (only one GlobalTrigger per event !)
535   TClonesArray &globalTrigger = *fGlobalTrigger;
536   new(globalTrigger[fNGlobalTrigger++]) 
537     AliMUONGlobalTrigger(singlePlus, singleMinus,  singleUndef, pairUnlike, 
538                          pairLike);
539 }
540 //___________________________________________
541 void AliMUON::AddLocalTrigger(Int_t *localtr)
542 {
543 // add a MUON Local Trigger to the list
544   TClonesArray &localTrigger = *fLocalTrigger;
545   new(localTrigger[fNLocalTrigger++]) AliMUONLocalTrigger(localtr);
546 }
547
548 //___________________________________________
549 void AliMUON::BuildGeometry()
550 {
551 // Geometry for event display
552   for (Int_t i=0; i<7; i++) {
553     for (Int_t j=0; j<2; j++) {
554       Int_t id=2*i+j+1;
555       this->Chamber(id-1).SegmentationModel(1)->Draw("eventdisplay");
556     }
557   }
558 }
559
560 //___________________________________________
561 Int_t AliMUON::DistancetoPrimitive(Int_t , Int_t )
562 {
563    return 9999;
564 }
565
566 //___________________________________________
567 void AliMUON::MakeBranch(Option_t* option, const char *file)
568 {
569     //
570     // Create Tree branches for the MUON.
571     //
572     const Int_t kBufferSize = 4000;
573     char branchname[30];
574     sprintf(branchname,"%sCluster",GetName());
575     
576     AliDetector::MakeBranch(option,file);
577     
578     const char *cD = strstr(option,"D");
579     const char *cR = strstr(option,"R");
580     const char *cH = strstr(option,"H");
581
582     if (fPadHits   && gAlice->TreeH() && cH) {
583       MakeBranchInTree(gAlice->TreeH(), 
584                        branchname, &fPadHits, kBufferSize, file);
585     }
586     
587     if (cD) {
588       //
589       // one branch for digits per chamber
590       // 
591       Int_t i;
592     
593       for (i=0; i<AliMUONConstants::NCh() ;i++) {
594             sprintf(branchname,"%sDigits%d",GetName(),i+1);     
595             if (fDchambers   && gAlice->TreeD()) {
596             MakeBranchInTree(gAlice->TreeD(), 
597                              branchname, &((*fDchambers)[i]), kBufferSize, file);
598               printf("Making Branch %s for digits in chamber %d\n",branchname,i+1);
599         }
600           }     
601     }
602     
603     if (cR) {
604       //     
605       // one branch for raw clusters per chamber
606       //  
607       printf("Make Branch - TreeR address %p\n",gAlice->TreeR());
608       
609       Int_t i;
610
611       for (i=0; i<AliMUONConstants::NTrackingCh() ;i++) {
612             sprintf(branchname,"%sRawClusters%d",GetName(),i+1);        
613             if (fRawClusters   && gAlice->TreeR()) {
614               MakeBranchInTree(gAlice->TreeR(), 
615                                branchname, &((*fRawClusters)[i]), kBufferSize, file);
616               printf("Making Branch %s for raw clusters in chamber %d\n",branchname,i+1);
617             }   
618       }
619       //
620       // one branch for global trigger
621       //
622       sprintf(branchname,"%sGlobalTrigger",GetName());
623       if (fGlobalTrigger && gAlice->TreeR()) {  
624           MakeBranchInTree(gAlice->TreeR(), 
625                            branchname, &fGlobalTrigger, kBufferSize, file);
626             printf("Making Branch %s for Global Trigger\n",branchname);
627       }
628       //
629       // one branch for local trigger
630       //  
631       sprintf(branchname,"%sLocalTrigger",GetName());
632       if (fLocalTrigger && gAlice->TreeR()) {  
633           MakeBranchInTree(gAlice->TreeR(), 
634                            branchname, &fLocalTrigger, kBufferSize, file);
635             printf("Making Branch %s for Local Trigger\n",branchname);
636       }
637    }
638 }
639
640 //___________________________________________
641 void AliMUON::SetTreeAddress()
642 {
643   // Set branch address for the Hits and Digits Tree.
644   char branchname[30];
645   AliDetector::SetTreeAddress();
646
647   TBranch *branch;
648   TTree *treeH = gAlice->TreeH();
649   TTree *treeD = gAlice->TreeD();
650   TTree *treeR = gAlice->TreeR();
651
652   if (treeH) {
653     if (fPadHits) {
654       branch = treeH->GetBranch("MUONCluster");
655       if (branch) branch->SetAddress(&fPadHits);
656     }
657   }
658
659   if (treeD) {
660       for (int i=0; i<AliMUONConstants::NCh(); i++) {
661           sprintf(branchname,"%sDigits%d",GetName(),i+1);
662           if (fDchambers) {
663               branch = treeD->GetBranch(branchname);
664               if (branch) branch->SetAddress(&((*fDchambers)[i]));
665           }
666       }
667   }
668
669   // printf("SetTreeAddress --- treeR address  %p \n",treeR);
670
671   if (treeR) {
672       for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
673           sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
674           if (fRawClusters) {
675               branch = treeR->GetBranch(branchname);
676               if (branch) branch->SetAddress(&((*fRawClusters)[i]));
677           }
678       }
679
680       if (fLocalTrigger) {
681         branch = treeR->GetBranch("MUONLocalTrigger");
682         if (branch) branch->SetAddress(&fLocalTrigger);
683       }
684       if (fGlobalTrigger) {
685         branch = treeR->GetBranch("MUONGlobalTrigger");
686         if (branch) branch->SetAddress(&fGlobalTrigger);
687       }
688   }
689 }
690 //___________________________________________
691 void AliMUON::ResetHits()
692 {
693   // Reset number of clusters and the cluster array for this detector
694   AliDetector::ResetHits();
695   fNPadHits = 0;
696   if (fPadHits) fPadHits->Clear();
697 }
698
699 //____________________________________________
700 void AliMUON::ResetDigits()
701 {
702     //
703     // Reset number of digits and the digits array for this detector
704     //
705     for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
706       //PH      if ((*fDchambers)[i])    ((TClonesArray*)(*fDchambers)[i])->Clear();
707         if ((*fDchambers)[i])    ((TClonesArray*)fDchambers->At(i))->Clear();
708         if (fNdch)  fNdch[i]=0;
709     }
710 }
711 //____________________________________________
712 void AliMUON::ResetRawClusters()
713 {
714     //
715     // Reset number of raw clusters and the raw clust array for this detector
716     //
717     for ( int i=0;i<AliMUONConstants::NTrackingCh();i++ ) {
718       //PH      if ((*fRawClusters)[i])    ((TClonesArray*)(*fRawClusters)[i])->Clear();
719         if ((*fRawClusters)[i])    ((TClonesArray*)fRawClusters->At(i))->Clear();
720         if (fNrawch)  fNrawch[i]=0;
721     }
722 }
723
724 //____________________________________________
725 void AliMUON::ResetTrigger()
726 {
727   //  Reset Local and Global Trigger 
728   fNGlobalTrigger = 0;
729   if (fGlobalTrigger) fGlobalTrigger->Clear();
730   fNLocalTrigger = 0;
731   if (fLocalTrigger) fLocalTrigger->Clear();
732 }
733
734 //____________________________________________
735 void AliMUON::SetPadSize(Int_t id, Int_t isec, Float_t p1, Float_t p2)
736 {
737 // Set the pad size for chamber id and cathode isec
738     Int_t i=2*(id-1);
739     //PH    ((AliMUONChamber*) (*fChambers)[i])  ->SetPadSize(isec,p1,p2);
740     //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetPadSize(isec,p1,p2);
741     ((AliMUONChamber*) fChambers->At(i))  ->SetPadSize(isec,p1,p2);
742     ((AliMUONChamber*) fChambers->At(i+1))->SetPadSize(isec,p1,p2);
743 }
744
745 //___________________________________________
746 void AliMUON::SetChambersZ(const Float_t *Z)
747 {
748   // Set Z values for all chambers (tracking and trigger)
749   // from the array pointed to by "Z"
750     for (Int_t ch = 0; ch < AliMUONConstants::NCh(); ch++)
751       //PH      ((AliMUONChamber*) ((*fChambers)[ch]))->SetZ(Z[ch]);
752         ((AliMUONChamber*) fChambers->At(ch))->SetZ(Z[ch]);
753     return;
754 }
755
756 //___________________________________________
757 void AliMUON::SetChambersZToDefault()
758 {
759   // Set Z values for all chambers (tracking and trigger)
760   // to default values
761   SetChambersZ(AliMUONConstants::DefaultChamberZ());
762   return;
763 }
764
765 //___________________________________________
766 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
767 {
768 // Set the inverse charge slope for chamber id
769     Int_t i=2*(id-1);
770     //PH    ((AliMUONChamber*) (*fChambers)[i])->SetChargeSlope(p1);
771     //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetChargeSlope(p1);
772     ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
773     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
774 }
775
776 //___________________________________________
777 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
778 {
779 // Set sigma of charge spread for chamber id
780     Int_t i=2*(id-1);
781     //PH    ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
782     //PH    ((AliMUONChamber*) fChambers->Ati+1])->SetChargeSpread(p1,p2);
783     ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
784     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
785 }
786
787 //___________________________________________
788 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
789 {
790 // Set integration limits for charge spread
791     Int_t i=2*(id-1);
792     //PH    ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
793     //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
794     ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
795     ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
796 }
797
798 //___________________________________________
799 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
800 {
801 // Set maximum number for ADCcounts (saturation)
802     Int_t i=2*(id-1);
803     //PH    ((AliMUONChamber*) (*fChambers)[i])->SetMaxAdc(p1);
804     //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetMaxAdc(p1);
805     ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
806     ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
807 }
808
809 //___________________________________________
810 void AliMUON::SetMaxStepGas(Float_t p1)
811 {
812 // Set stepsize in gas
813      fMaxStepGas=p1;
814 }
815
816 //___________________________________________
817 void AliMUON::SetMaxStepAlu(Float_t p1)
818 {
819 // Set step size in Alu
820     fMaxStepAlu=p1;
821 }
822
823 //___________________________________________
824 void AliMUON::SetMaxDestepGas(Float_t p1)
825 {
826 // Set maximum step size in Gas
827     fMaxDestepGas=p1;
828 }
829
830 //___________________________________________
831 void AliMUON::SetMaxDestepAlu(Float_t p1)
832 {
833 // Set maximum step size in Alu
834     fMaxDestepAlu=p1;
835 }
836 //___________________________________________
837 void AliMUON::SetAcceptance(Bool_t acc, Float_t angmin, Float_t angmax)
838 {
839 // Set acceptance cuts 
840    fAccCut=acc;
841    fAccMin=angmin*TMath::Pi()/180;
842    fAccMax=angmax*TMath::Pi()/180;
843    Int_t ch;
844    if (acc) {
845        for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
846            // Loop over 2 chambers in the station
847            for (Int_t stCH = 0; stCH < 2; stCH++) {
848                ch = 2 * st + stCH;
849 //         Set chamber inner and outer radius according to acceptance cuts
850                Chamber(ch).SetRInner(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMin));
851                Chamber(ch).SetROuter(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMax));
852            } // chamber loop
853        } // station loop
854    }
855 }
856 //___________________________________________
857 void   AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliSegmentation *segmentation)
858 {
859 // Set the segmentation for chamber id cathode isec
860   //PH    ((AliMUONChamber*) (*fChambers)[id])->SetSegmentationModel(isec, segmentation);
861     ((AliMUONChamber*) fChambers->At(id))->SetSegmentationModel(isec, segmentation);
862
863 }
864 //___________________________________________
865 void   AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
866 {
867 // Set the response for chamber id
868   //PH    ((AliMUONChamber*) (*fChambers)[id])->SetResponseModel(response);
869     ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
870 }
871
872 void   AliMUON::SetReconstructionModel(Int_t id, AliMUONClusterFinderVS *reconst)
873 {
874 // Set ClusterFinder for chamber id
875   //PH    ((AliMUONChamber*) (*fChambers)[id])->SetReconstructionModel(reconst);
876     ((AliMUONChamber*) fChambers->At(id))->SetReconstructionModel(reconst);
877 }
878
879 void   AliMUON::SetNsec(Int_t id, Int_t nsec)
880 {
881 // Set number of segmented cathods for chamber id
882   //PH    ((AliMUONChamber*) (*fChambers)[id])->SetNsec(nsec);
883     ((AliMUONChamber*) fChambers->At(id))->SetNsec(nsec);
884 }
885
886 //___________________________________________
887 void AliMUON::SDigits2Digits()
888 {
889
890 // write TreeD here 
891
892     if (!fMerger) {
893       if (gAlice->GetDebug()>0) {
894         cerr<<"AliMUON::SDigits2Digits: create default AliMUONMerger "<<endl;
895         cerr<<" no merging, just digitization of 1 event will be done"<<endl;
896       }
897       fMerger = new AliMUONMerger();
898     }
899     fMerger->Init();
900     fMerger->Digitise();
901     char hname[30];
902     sprintf(hname,"TreeD%d",gAlice->GetHeader()->GetEvent());
903     gAlice->TreeD()->Write(hname,TObject::kOverwrite);
904     gAlice->TreeD()->Reset();
905 }
906
907 //___________________________________________
908 void AliMUON::MakePadHits(Float_t xhit,Float_t yhit, Float_t zhit,
909                           Float_t eloss, Float_t tof,  Int_t idvol)
910 {
911 //
912 //  Calls the charge disintegration method of the current chamber and adds
913 //  the simulated cluster to the root treee 
914 //
915     Int_t clhits[7];
916     Float_t newclust[6][500];
917     Int_t nnew;
918     
919     
920 //
921 //  Integrated pulse height on chamber
922
923     
924     clhits[0]=fNhits+1;
925 //
926 //
927 //    if (idvol == 6) printf("\n ->Disintegration %f %f %f", xhit, yhit, eloss );
928     
929
930     //PH    ((AliMUONChamber*) (*fChambers)[idvol])
931     ((AliMUONChamber*) fChambers->At(idvol))
932         ->DisIntegration(eloss, tof, xhit, yhit, zhit, nnew, newclust);
933     Int_t ic=0;
934 //    if (idvol == 6) printf("\n nnew  %d \n", nnew);
935 //
936 //  Add new clusters
937     for (Int_t i=0; i<nnew; i++) {
938         if (Int_t(newclust[3][i]) > 0) {
939             ic++;
940 // Cathode plane
941             clhits[1] = Int_t(newclust[5][i]);
942 //  Cluster Charge
943             clhits[2] = Int_t(newclust[0][i]);
944 //  Pad: ix
945             clhits[3] = Int_t(newclust[1][i]);
946 //  Pad: iy 
947             clhits[4] = Int_t(newclust[2][i]);
948 //  Pad: charge
949             clhits[5] = Int_t(newclust[3][i]);
950 //  Pad: chamber sector
951             clhits[6] = Int_t(newclust[4][i]);
952             
953             AddPadHit(clhits);
954         }
955     }
956 }
957
958 //___________________________________________
959 void AliMUON::Trigger(Int_t nev){
960 // call the Trigger Algorithm and fill TreeR
961
962   Int_t singlePlus[3]  = {0,0,0}; 
963   Int_t singleMinus[3] = {0,0,0}; 
964   Int_t singleUndef[3] = {0,0,0};
965   Int_t pairUnlike[3]  = {0,0,0}; 
966   Int_t pairLike[3]    = {0,0,0};
967
968   ResetTrigger();
969   AliMUONTriggerDecision* decision= new AliMUONTriggerDecision(1);
970   decision->Trigger();   
971   decision->GetGlobalTrigger(singlePlus, singleMinus, singleUndef,
972                              pairUnlike, pairLike);
973 // add a local trigger in the list 
974   AddGlobalTrigger(singlePlus, singleMinus, singleUndef, pairUnlike, pairLike);
975   Int_t i;
976   
977   for (Int_t icirc=0; icirc<AliMUONConstants::NTriggerCircuit(); icirc++) { 
978       if(decision->GetITrigger(icirc)==1) {
979           Int_t localtr[7]={0,0,0,0,0,0,0};      
980           Int_t loLpt[2]={0,0}; Int_t loHpt[2]={0,0}; Int_t loApt[2]={0,0};
981           decision->GetLutOutput(icirc, loLpt, loHpt, loApt);
982           localtr[0] = icirc;
983           localtr[1] = decision->GetStripX11(icirc);
984           localtr[2] = decision->GetDev(icirc);
985           localtr[3] = decision->GetStripY11(icirc);
986           for (i=0; i<2; i++) {    // convert the Lut output in 1 digit 
987               localtr[4] = localtr[4]+Int_t(loLpt[i]*TMath::Power(2,i));
988               localtr[5] = localtr[5]+Int_t(loHpt[i]*TMath::Power(2,i));
989               localtr[6] = localtr[6]+Int_t(loApt[i]*TMath::Power(2,i));
990           }
991           AddLocalTrigger(localtr);  // add a local trigger in the list
992       }
993   }
994   delete decision;
995
996   gAlice->TreeR()->Fill();
997   ResetTrigger();
998   char hname[30];
999   sprintf(hname,"TreeR%d",nev);
1000   gAlice->TreeR()->Write(hname,TObject::kOverwrite);
1001   gAlice->TreeR()->Reset();
1002   printf("\n End of trigger for event %d", nev);
1003 }
1004
1005
1006 //____________________________________________
1007 void AliMUON::Digits2Reco()
1008 {
1009   FindClusters();
1010   Int_t nev = gAlice->GetHeader()->GetEvent();
1011   gAlice->TreeR()->Fill();
1012   char hname[30];
1013   sprintf(hname,"TreeR%d", nev);
1014   gAlice->TreeR()->Write(hname);
1015   gAlice->TreeR()->Reset();
1016   ResetRawClusters();        
1017   printf("\n End of cluster finding for event %d", nev);
1018 }
1019
1020 void AliMUON::FindClusters()
1021 {
1022 //
1023 //  Perform cluster finding
1024 //
1025     TClonesArray *dig1, *dig2;
1026     Int_t ndig, k;
1027     dig1 = new TClonesArray("AliMUONDigit",1000);
1028     dig2 = new TClonesArray("AliMUONDigit",1000);
1029     AliMUONDigit *digit;
1030 //
1031 // Loop on chambers and on cathode planes
1032 //
1033     ResetRawClusters();        
1034     for (Int_t ich = 0; ich < 10; ich++) {
1035       //PH      AliMUONChamber* iChamber = (AliMUONChamber*) (*fChambers)[ich];
1036         AliMUONChamber* iChamber = (AliMUONChamber*) fChambers->At(ich);
1037         AliMUONClusterFinderVS* rec = iChamber->ReconstructionModel();
1038     
1039         gAlice->ResetDigits();
1040         gAlice->TreeD()->GetEvent(0);
1041         TClonesArray *muonDigits = this->DigitsAddress(ich);
1042         ndig=muonDigits->GetEntriesFast();
1043         printf("\n 1 Found %d digits in %p %d", ndig, muonDigits,ich);
1044         TClonesArray &lhits1 = *dig1;
1045         Int_t n = 0;
1046         for (k = 0; k < ndig; k++) {
1047             digit = (AliMUONDigit*) muonDigits->UncheckedAt(k);
1048             if (rec->TestTrack(digit->Track(0)))
1049                 new(lhits1[n++]) AliMUONDigit(*digit);
1050         }
1051         gAlice->ResetDigits();
1052         gAlice->TreeD()->GetEvent(1);
1053         muonDigits  = this->DigitsAddress(ich);
1054         ndig=muonDigits->GetEntriesFast();
1055         printf("\n 2 Found %d digits in %p %d", ndig, muonDigits, ich);
1056         TClonesArray &lhits2 = *dig2;
1057         n=0;
1058         
1059         for (k=0; k<ndig; k++) {
1060             digit= (AliMUONDigit*) muonDigits->UncheckedAt(k);
1061             if (rec->TestTrack(digit->Track(0)))
1062             new(lhits2[n++]) AliMUONDigit(*digit);
1063         }
1064
1065         if (rec) {       
1066             AliMUONClusterInput::Instance()->SetDigits(ich, dig1, dig2);
1067             rec->FindRawClusters();
1068         }
1069         dig1->Delete();
1070         dig2->Delete();
1071     } // for ich
1072     delete dig1;
1073     delete dig2;
1074 }
1075  
1076 #ifdef never
1077 void AliMUON::Streamer(TBuffer &R__b)
1078 {
1079    // Stream an object of class AliMUON.
1080       AliMUONChamber        *iChamber;
1081       AliMUONTriggerCircuit *iTriggerCircuit;
1082       AliSegmentation       *segmentation;
1083       AliMUONResponse       *response;
1084       TClonesArray          *digitsaddress;
1085       TClonesArray          *rawcladdress;
1086       Int_t i;
1087       if (R__b.IsReading()) {
1088           Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1089           AliDetector::Streamer(R__b);
1090           R__b >> fNPadHits;
1091           R__b >> fPadHits; // diff
1092           R__b >> fNLocalTrigger;       
1093           R__b >> fLocalTrigger;       
1094           R__b >> fNGlobalTrigger;       
1095           R__b >> fGlobalTrigger;   
1096           R__b >> fDchambers;
1097           R__b >> fRawClusters;
1098           R__b.ReadArray(fNdch);
1099           R__b.ReadArray(fNrawch);
1100           R__b >> fAccCut;
1101           R__b >> fAccMin;
1102           R__b >> fAccMax; 
1103           R__b >> fChambers;
1104           R__b >> fTriggerCircuits;
1105           for (i =0; i<AliMUONConstants::NTriggerCircuit(); i++) {
1106               iTriggerCircuit=(AliMUONTriggerCircuit*) (*fTriggerCircuits)[i];
1107               iTriggerCircuit->Streamer(R__b);
1108           }
1109 // Stream chamber related information
1110           for (i =0; i<AliMUONConstants::NCh(); i++) {
1111               iChamber=(AliMUONChamber*) (*fChambers)[i];
1112               iChamber->Streamer(R__b);
1113               if (iChamber->Nsec()==1) {
1114                   segmentation=iChamber->SegmentationModel(1);
1115                   if (segmentation)
1116                       segmentation->Streamer(R__b);
1117               } else {
1118                   segmentation=iChamber->SegmentationModel(1);
1119                   if (segmentation)
1120                       segmentation->Streamer(R__b);
1121                   if (segmentation)
1122                       segmentation=iChamber->SegmentationModel(2);
1123                   segmentation->Streamer(R__b);
1124               }
1125               response=iChamber->ResponseModel();
1126               if (response)
1127                   response->Streamer(R__b);       
1128               digitsaddress=(TClonesArray*) (*fDchambers)[i];
1129               digitsaddress->Streamer(R__b);
1130               if (i < AliMUONConstants::NTrackingCh()) {
1131                   rawcladdress=(TClonesArray*) (*fRawClusters)[i];
1132                   rawcladdress->Streamer(R__b);
1133               }
1134           }
1135           
1136       } else {
1137           R__b.WriteVersion(AliMUON::IsA());
1138           AliDetector::Streamer(R__b);
1139           R__b << fNPadHits;
1140           R__b << fPadHits; // diff
1141           R__b << fNLocalTrigger;       
1142           R__b << fLocalTrigger;       
1143           R__b << fNGlobalTrigger;       
1144           R__b << fGlobalTrigger; 
1145           R__b << fDchambers;
1146           R__b << fRawClusters;
1147           R__b.WriteArray(fNdch, AliMUONConstants::NCh());
1148           R__b.WriteArray(fNrawch, AliMUONConstants::NTrackingCh());
1149           
1150           R__b << fAccCut;
1151           R__b << fAccMin;
1152           R__b << fAccMax; 
1153           
1154           R__b << fChambers;
1155           R__b << fTriggerCircuits;
1156           for (i =0; i<AliMUONConstants::NTriggerCircuit(); i++) {
1157               iTriggerCircuit=(AliMUONTriggerCircuit*) (*fTriggerCircuits)[i];
1158               iTriggerCircuit->Streamer(R__b);
1159           }
1160           for (i =0; i<AliMUONConstants::NCh(); i++) {
1161               iChamber=(AliMUONChamber*) (*fChambers)[i];
1162               iChamber->Streamer(R__b);
1163               if (iChamber->Nsec()==1) {
1164                   segmentation=iChamber->SegmentationModel(1);
1165                   if (segmentation)
1166                       segmentation->Streamer(R__b);
1167               } else {
1168                   segmentation=iChamber->SegmentationModel(1);
1169                   if (segmentation)
1170                       segmentation->Streamer(R__b);
1171                   segmentation=iChamber->SegmentationModel(2);
1172                   if (segmentation)
1173                       segmentation->Streamer(R__b);
1174               }
1175               response=iChamber->ResponseModel();
1176               if (response)
1177                   response->Streamer(R__b);
1178               digitsaddress=(TClonesArray*) (*fDchambers)[i];
1179               digitsaddress->Streamer(R__b);
1180               if (i < AliMUONConstants::NTrackingCh()) {
1181                   rawcladdress=(TClonesArray*) (*fRawClusters)[i];
1182                   rawcladdress->Streamer(R__b);
1183               }
1184           }
1185       }
1186 }
1187 #endif
1188
1189 AliMUONPadHit* AliMUON::FirstPad(AliMUONHit*  hit, TClonesArray *clusters) 
1190 {
1191 //
1192     // Initialise the pad iterator
1193     // Return the address of the first padhit for hit
1194     TClonesArray *theClusters = clusters;
1195     Int_t nclust = theClusters->GetEntriesFast();
1196     if (nclust && hit->PHlast() > 0) {
1197         AliMUON::fMaxIterPad=hit->PHlast();
1198         AliMUON::fCurIterPad=hit->PHfirst();
1199         return (AliMUONPadHit*) clusters->UncheckedAt(AliMUON::fCurIterPad-1);
1200     } else {
1201         return 0;
1202     }
1203 }
1204
1205 AliMUONPadHit* AliMUON::NextPad(TClonesArray *clusters) 
1206 {
1207 // Get next pad (in iterator) 
1208 //
1209     AliMUON::fCurIterPad++;
1210     if (AliMUON::fCurIterPad <= AliMUON::fMaxIterPad) {
1211         return (AliMUONPadHit*) clusters->UncheckedAt(AliMUON::fCurIterPad-1);
1212     } else {
1213         return 0;
1214     }
1215 }
1216
1217
1218 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
1219 {
1220 //
1221 //  Return rawcluster (icluster) for chamber ichamber and cathode icathod
1222 //  Obsolete ??
1223     TClonesArray *muonRawCluster  = RawClustAddress(ichamber);
1224     ResetRawClusters();
1225     TTree *treeR = gAlice->TreeR();
1226     Int_t nent=(Int_t)treeR->GetEntries();
1227     treeR->GetEvent(nent-2+icathod-1);
1228     //treeR->GetEvent(icathod);
1229     //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
1230
1231     AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
1232     //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
1233     
1234     return  mRaw;
1235 }
1236  
1237 void   AliMUON::SetMerger(AliMUONMerger* merger)
1238 {
1239 // Set pointer to merger 
1240     fMerger = merger;
1241 }
1242
1243 AliMUONMerger*  AliMUON::Merger()
1244 {
1245 // Return pointer to merger
1246     return fMerger;
1247 }
1248
1249
1250
1251 AliMUON& AliMUON::operator = (const AliMUON& rhs)
1252 {
1253 // copy operator
1254 // dummy version
1255     return *this;
1256 }
1257
1258 ////////////////////////////////////////////////////////////////////////
1259 void AliMUON::MakeBranchInTreeD(TTree *treeD, const char *file)
1260 {
1261     //
1262     // Create TreeD branches for the MUON.
1263     //
1264
1265   const Int_t kBufferSize = 4000;
1266   char branchname[30];
1267     
1268   //
1269   // one branch for digits per chamber
1270   // 
1271   for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
1272     sprintf(branchname,"%sDigits%d",GetName(),i+1);     
1273     if (fDchambers && treeD) {
1274       MakeBranchInTree(treeD, 
1275                        branchname, &((*fDchambers)[i]), kBufferSize, file);
1276 //      printf("Making Branch %s for digits in chamber %d\n",branchname,i+1);
1277     }
1278   }
1279 }
1280
1281 //___________________________________________
1282