]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON.cxx
The operator[] is replaced by At() or AddAt() in case of TObjArray.
[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.53  2001/07/20 10:03:13  morsch
18 Changes needed to work with Root 3.01 (substitute lhs [] operator). (Jiri Chudoba)
19
20 Revision 1.52  2001/06/14 13:49:22  hristov
21 Write a TreeD in SDigits2Digits method (needed to be compatible with alirun script)
22
23 Revision 1.51  2001/05/31 10:19:52  morsch
24 Fix for new AliRun::RunReco().
25
26 Revision 1.50  2001/05/16 14:57:17  alibrary
27 New files for folders and Stack
28
29 Revision 1.49  2001/03/12 17:45:48  hristov
30 Changes needed on Sun with CC 5.0
31
32 Revision 1.48  2001/03/06 00:01:36  morsch
33 Add  Digits2Reco() and FindClusters()
34 Adapt call of cluster finder to new STEER.
35
36 Revision 1.47  2001/03/05 08:38:36  morsch
37 Digitization related methods moved to AliMUONMerger.
38
39 Revision 1.46  2001/01/26 21:34:59  morsch
40 Use access functions for AliMUONHit, AliMUONDigit and AliMUONPadHit data members.
41
42 Revision 1.45  2001/01/26 20:00:49  hristov
43 Major upgrade of AliRoot code
44
45 Revision 1.44  2001/01/25 17:39:09  morsch
46 Pass size of fNdch and fNrawch to CINT.
47
48 Revision 1.43  2001/01/23 18:58:19  hristov
49 Initialisation of some pointers
50
51 Revision 1.42  2001/01/17 20:53:40  hristov
52 Destructors corrected to avoid memory leaks
53
54 Revision 1.41  2000/12/21 22:12:40  morsch
55 Clean-up of coding rule violations,
56
57 Revision 1.40  2000/11/29 20:32:26  gosset
58 Digitize:
59 1. correction for array index out of bounds
60 2. one printout commented
61
62 Revision 1.39  2000/11/12 17:17:03  pcrochet
63 BuildGeometry of AliMUON for trigger chambers delegated to AliMUONSegmentationTriggerX (same strategy as for tracking chambers)
64
65 Revision 1.38  2000/11/06 09:20:43  morsch
66 AliMUON delegates part of BuildGeometry() to AliMUONSegmentation using the
67 Draw() method. This avoids code and parameter replication.
68
69 Revision 1.37  2000/10/26 09:53:37  pcrochet
70 put back trigger chambers in the display (there was a problem in buildgeometry)
71
72 Revision 1.36  2000/10/25 19:51:18  morsch
73 Correct x-position of chambers.
74
75 Revision 1.35  2000/10/24 19:46:21  morsch
76 BuildGeometry updated for slats in station 3-4.
77
78 Revision 1.34  2000/10/18 11:42:06  morsch
79 - AliMUONRawCluster contains z-position.
80 - Some clean-up of useless print statements during initialisations.
81
82 Revision 1.33  2000/10/09 14:01:57  morsch
83 Unused variables removed.
84
85 Revision 1.32  2000/10/06 09:08:10  morsch
86 Built geometry includes slat geometry for event display.
87
88 Revision 1.31  2000/10/02 21:28:08  fca
89 Removal of useless dependecies via forward declarations
90
91 Revision 1.30  2000/10/02 16:58:29  egangler
92 Cleaning of the code :
93 -> coding conventions
94 -> void Streamers
95 -> some useless includes removed or replaced by "class" statement
96
97 Revision 1.29  2000/07/28 13:49:38  morsch
98 SetAcceptance defines inner and outer chamber radii according to angular acceptance.
99 Can be used for simple acceptance studies.
100
101 Revision 1.28  2000/07/22 16:43:15  morsch
102 Same comment as before, but now done correctly I hope (sorry it's Saturday evening)
103
104 Revision 1.27  2000/07/22 16:36:50  morsch
105 Change order of indices in creation (new) of xhit and yhit
106
107 Revision 1.26  2000/07/03 11:54:57  morsch
108 AliMUONSegmentation and AliMUONHitMap have been replaced by AliSegmentation and AliHitMap in STEER
109 The methods GetPadIxy and GetPadXxy of AliMUONSegmentation have changed name to GetPadI and GetPadC.
110
111 Revision 1.25  2000/06/29 12:34:09  morsch
112 AliMUONSegmentation class has been made independent of AliMUONChamber. This makes
113 it usable with any other geometry class. The link to the object to which it belongs is
114 established via an index. This assumes that there exists a global geometry manager
115 from which the pointer to the parent object can be obtained (in our case gAlice).
116
117 Revision 1.24  2000/06/28 15:16:35  morsch
118 (1) Client code adapted to new method signatures in AliMUONSegmentation (see comments there)
119 to allow development of slat-muon chamber simulation and reconstruction code in the MUON
120 framework. The changes should have no side effects (mostly dummy arguments).
121 (2) Hit disintegration uses 3-dim hit coordinates to allow simulation
122 of chambers with overlapping modules (MakePadHits, Disintegration).
123
124 Revision 1.23  2000/06/28 12:19:17  morsch
125 More consequent seperation of global input data services (AliMUONClusterInput singleton) and the
126 cluster and hit reconstruction algorithms in AliMUONClusterFindRawinderVS.
127 AliMUONClusterFinderVS becomes the base class for clustering and hit reconstruction.
128 It requires two cathode planes. Small modifications in the code will make it usable for
129 one cathode plane and, hence, more general (for test beam data).
130 AliMUONClusterFinder is now obsolete.
131
132 Revision 1.22  2000/06/28 08:06:10  morsch
133 Avoid global variables in AliMUONClusterFinderVS by seperating the input data for the fit from the
134 algorithmic part of the class. Input data resides inside the AliMUONClusterInput singleton.
135 It also naturally takes care of the TMinuit instance.
136
137 Revision 1.21  2000/06/27 08:54:41  morsch
138 Problems with on constant array sizes (in hitMap, nmuon, xhit, yhit) corrected.
139
140 Revision 1.20  2000/06/26 14:02:38  morsch
141 Add class AliMUONConstants with MUON specific constants using static memeber data and access methods.
142
143 Revision 1.19  2000/06/22 13:40:51  morsch
144 scope problem on HP, "i" declared once
145 pow changed to TMath::Power (PH, AM)
146
147 Revision 1.18  2000/06/15 07:58:48  morsch
148 Code from MUON-dev joined
149
150 Revision 1.14.4.17  2000/06/14 14:36:46  morsch
151 - add TriggerCircuit (PC)
152 - add GlobalTrigger and LocalTrigger and specific methods (PC)
153
154 Revision 1.14.4.16  2000/06/09 21:20:28  morsch
155 Most coding rule violations corrected
156
157 Revision 1.14.4.15  2000/05/02 09:54:32  morsch
158 RULE RN17 violations corrected
159
160 Revision 1.14.4.12  2000/04/26 12:25:02  morsch
161 Code revised by P. Crochet:
162 - Z position of TriggerChamber changed according to A.Tournaire Priv.Comm.
163 - ToF included in the method MakePadHits
164 - inner radius of flange between beam shielding and trigger corrected
165 - Trigger global volume updated (according to the new geometry)
166
167 Revision 1.14.4.11  2000/04/19 19:42:08  morsch
168 Some changes of variable names curing viols and methods concerning
169 correlated clusters removed.
170
171 Revision 1.14.4.10  2000/03/22 16:44:07  gosset
172 Memory leak suppressed in function Digitise:
173 p_adr->Delete() instead of Clear (I.Chevrot and A.Baldisseri)
174
175 Revision 1.14.4.9  2000/03/20 18:15:25  morsch
176 Positions of trigger chambers corrected (P.C.)
177
178 Revision 1.14.4.8  2000/02/21 15:38:01  morsch
179 Call to AddHitList introduced to make this version compatible with head.
180
181 Revision 1.14.4.7  2000/02/20 07:45:53  morsch
182 Bugs in Trigger part of BuildGeomemetry corrected (P.C)
183
184 Revision 1.14.4.6  2000/02/17 14:28:54  morsch
185 Trigger included into initialization and digitization
186
187 Revision 1.14.4.5  2000/02/15 10:02:58  morsch
188 Log messages of previous revisions added
189
190 Revision 1.14.4.2  2000/02/04 10:57:34  gosset
191 Z position of the chambers:
192 it was the Z position of the stations;
193 it is now really the Z position of the chambers.
194    !!!! WARNING: THE CALLS TO "AliMUONChamber::SetZPOS"
195    !!!!                   AND "AliMUONChamber::ZPosition"
196    !!!! HAVE TO BE CHANGED TO "AliMUONChamber::"SetZ"
197    !!!!                   AND "AliMUONChamber::Z"
198
199 Revision 1.14.4.3  2000/02/04 16:19:04  gosset
200 Correction for mis-spelling of NCH 
201
202 Revision 1.14.4.4  2000/02/15 09:43:38  morsch
203 Log message added
204
205 */
206
207
208 ///////////////////////////////////////////////
209 //  Manager and hits classes for set:MUON     //
210 ////////////////////////////////////////////////
211
212 #include <TTUBE.h>
213 #include <TBRIK.h>
214 #include <TRotMatrix.h>
215 #include <TGeometry.h>
216 #include <TNode.h> 
217 #include <TTree.h> 
218 #include <TRandom.h> 
219 #include <TObject.h>
220 #include <TVector.h>
221 #include <TObjArray.h>
222 #include <TMinuit.h>
223 #include <TParticle.h>
224 #include <TROOT.h>
225 #include <TFile.h>
226 #include <TNtuple.h>
227 #include <TCanvas.h>
228 #include <TPad.h>
229 #include <TDirectory.h>
230 #include <TObjectTable.h>
231 #include <AliPDG.h>
232 #include <TTUBE.h>
233
234 #include "AliMUON.h"
235 #include "AliMUONHit.h"
236 #include "AliMUONPadHit.h"
237 #include "AliMUONDigit.h"
238 #include "AliMUONTransientDigit.h"
239 #include "AliMUONRawCluster.h"
240 #include "AliMUONLocalTrigger.h"
241 #include "AliMUONGlobalTrigger.h"
242 #include "AliMUONTriggerCircuit.h"
243 #include "AliHitMap.h"
244 #include "AliMUONHitMapA1.h"
245 #include "AliMUONChamberTrigger.h"
246 #include "AliMUONConstants.h"
247 #include "AliMUONClusterFinderVS.h"
248 #include "AliMUONTriggerDecision.h"
249 #include "AliRun.h"
250 #include "AliHeader.h"
251 #include "AliMC.h"
252 #include "AliMUONClusterInput.h"
253 #include "AliMUONMerger.h"      
254 #include "iostream.h"
255 #include "AliCallf77.h" 
256 #include "AliConst.h" 
257
258 // Defaults parameters for Z positions of chambers
259 // taken from values for "stations" in AliMUON::AliMUON
260 //     const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
261 // and from array "dstation" in AliMUONv1::CreateGeometry
262 //          Float_t dstation[5]={20., 20., 20, 20., 20.};
263 //     for tracking chambers,
264 //          according to (Z1 = zch - dstation) and  (Z2 = zch + dstation)
265 //          for the first and second chambers in the station, respectively,
266 // and from "DTPLANES" in AliMUONv1::CreateGeometry
267 //           const Float_t DTPLANES = 15.;
268 //     for trigger chambers,
269 //          according to (Z1 = zch) and  (Z2 = zch + DTPLANES)
270 //          for the first and second chambers in the station, respectively
271
272 ClassImp(AliMUON)
273 //___________________________________________
274 AliMUON::AliMUON()
275 {
276 // Default Constructor
277 //
278     fNCh             = 0;
279     fNTrackingCh     = 0;
280     fIshunt          = 0;
281     fHits            = 0;
282     fPadHits         = 0;
283     fNPadHits        = 0;
284     fChambers        = 0;
285     fDchambers       = 0;
286     fTriggerCircuits = 0;  
287     fNdch            = 0;
288     fRawClusters     = 0;
289     fNrawch          = 0;
290     fGlobalTrigger   = 0;
291     fNLocalTrigger   = 0;
292     fLocalTrigger    = 0;
293     fNLocalTrigger   = 0;
294     fAccMin          = 0.;
295     fAccMax          = 0.;   
296     fAccCut          = kFALSE;
297     fMerger          = 0;
298 }
299  
300 //___________________________________________
301 AliMUON::AliMUON(const char *name, const char *title)
302        : AliDetector(name,title)
303 {
304 //Begin_Html
305 /*
306 <img src="gif/alimuon.gif">
307 */
308 //End_Html
309
310    fHits     = new TClonesArray("AliMUONHit",1000);
311    gAlice->AddHitList(fHits);
312    fPadHits = new TClonesArray("AliMUONPadHit",10000);
313    fNPadHits  =  0;
314    fIshunt     =  0;
315
316    fNCh             = AliMUONConstants::NCh(); 
317    fNTrackingCh     = AliMUONConstants::NTrackingCh();
318    fNdch            = new Int_t[fNCh];
319
320    fDchambers = new TObjArray(AliMUONConstants::NCh());
321
322    Int_t i;
323    
324    for (i=0; i<AliMUONConstants::NCh() ;i++) {
325        fDchambers->AddAt(new TClonesArray("AliMUONDigit",10000),i); 
326        fNdch[i]=0;
327    }
328
329    fNrawch      = new Int_t[fNTrackingCh];
330
331    fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
332
333    for (i=0; i<AliMUONConstants::NTrackingCh();i++) {
334        fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i); 
335        fNrawch[i]=0;
336    }
337
338    fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);    
339    fNGlobalTrigger = 0;
340    fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);    
341    fNLocalTrigger = 0;
342
343    SetMarkerColor(kRed);
344 //
345 //
346 //
347 //
348
349     Int_t ch;
350
351     fChambers = new TObjArray(AliMUONConstants::NCh());
352
353     // Loop over stations
354     for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
355       // Loop over 2 chambers in the station
356         for (Int_t stCH = 0; stCH < 2; stCH++) {
357 //
358 //    
359 //    Default Parameters for Muon Tracking Stations
360
361
362             ch = 2 * st + stCH;
363 //
364             if (ch < AliMUONConstants::NTrackingCh()) {
365               fChambers->AddAt(new AliMUONChamber(ch),ch);
366             } else {
367               fChambers->AddAt(new AliMUONChamberTrigger(ch),ch);
368             }
369             
370         //PH        AliMUONChamber* chamber = (AliMUONChamber*) (*fChambers)[ch];
371             AliMUONChamber* chamber = (AliMUONChamber*) fChambers->At(ch);
372             
373             chamber->SetGid(0);
374             // Default values for Z of chambers
375             chamber->SetZ(AliMUONConstants::DefaultChamberZ(ch));
376 //
377             chamber->InitGeo(AliMUONConstants::DefaultChamberZ(ch));
378 //          Set chamber inner and outer radius to default
379             chamber->SetRInner(AliMUONConstants::Dmin(st)/2);
380             chamber->SetROuter(AliMUONConstants::Dmax(st)/2);
381 //
382         } // Chamber stCH (0, 1) in 
383     }     // Station st (0...)
384 //    fChambers->SetLast(AliMUONConstants::NCh());
385     fMaxStepGas=0.01; 
386     fMaxStepAlu=0.1; 
387     fMaxDestepGas=-1;
388     fMaxDestepAlu=-1;
389 //
390    fMaxIterPad   = 0;
391    fCurIterPad   = 0;
392 //
393    fAccMin          = 0.;
394    fAccMax          = 0.;   
395    fAccCut          = kFALSE;
396
397    // cp new design of AliMUONTriggerDecision
398    fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
399    for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
400      fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);     
401
402    }
403      fMerger = 0;
404 }
405  
406 //___________________________________________
407 AliMUON::AliMUON(const AliMUON& rMUON)
408 {
409 // Dummy copy constructor
410     ;
411     
412 }
413
414 AliMUON::~AliMUON()
415 {
416 // Destructor
417     if(fDebug) printf("%s: Calling AliMUON destructor !!!\n",ClassName());
418     
419     Int_t i;
420     fIshunt  = 0;
421  
422     // Delete TObjArrays
423  
424     if (fChambers){
425       fChambers->Delete();
426       delete fChambers;
427     }
428  
429     if (fTriggerCircuits){
430       fTriggerCircuits->Delete();
431       delete fTriggerCircuits;
432     }
433  
434     if (fDchambers){
435       fDchambers->Delete();
436       delete fDchambers;
437     }
438  
439     if (fRawClusters){
440       fRawClusters->Delete();
441       delete fRawClusters;
442     }
443     for (i=0;i<AliMUONConstants::NTrackingCh();i++) {
444       fNrawch[i]=0;
445     }
446  
447     // Delete TClonesArrays
448  
449     if (fPadHits){
450       fPadHits->Delete();
451       delete fPadHits;
452     }
453  
454     if (fGlobalTrigger){
455       fGlobalTrigger->Delete();
456       delete fGlobalTrigger;
457     }
458     fNGlobalTrigger = 0;
459     
460     if (fLocalTrigger){
461       fLocalTrigger->Delete();
462       delete fLocalTrigger;
463     }
464     fNLocalTrigger = 0;
465
466     if (fHits2){
467       fHits2->Delete();
468       delete fHits2;
469     }
470
471     if (fPadHits2){
472       fPadHits2->Delete();
473       delete fPadHits2;
474     }
475
476     if (fHits) {
477       fHits->Delete();
478       delete fHits;
479     }
480
481     // Delete hits tree for background event
482
483     if (fTrH1) {
484       fTrH1->Delete();
485       delete fTrH1;
486     }
487
488     if (fMerger) delete fMerger;
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