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