DrawSector is now static to be used from macro, warning in ClusterFinder is also...
[u/mrichter/AliRoot.git] / MUON / AliMUON.cxx
CommitLineData
4c039060 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 **************************************************************************/
4c039060 15
88cb7938 16/* $Id$ */
17
a9e2aefa 18
19///////////////////////////////////////////////
fe4da5cc 20// Manager and hits classes for set:MUON //
21////////////////////////////////////////////////
22
88cb7938 23#include "Riostream.h"
24
25#include <AliPDG.h>
a897a37a 26#include <TBRIK.h>
88cb7938 27#include <TCanvas.h>
28#include <TDirectory.h>
29#include <TFile.h>
94de3818 30#include <TGeometry.h>
88cb7938 31#include <TMinuit.h>
fe4da5cc 32#include <TNode.h>
88cb7938 33#include <TNtuple.h>
fe4da5cc 34#include <TObjArray.h>
88cb7938 35#include <TObject.h>
36#include <TObjectTable.h>
37#include <TPad.h>
a897a37a 38#include <TParticle.h>
39#include <TROOT.h>
88cb7938 40#include <TRandom.h>
41#include <TRotMatrix.h>
42#include <TTUBE.h>
a9e2aefa 43#include <TTUBE.h>
88cb7938 44#include <TTree.h>
45#include <TVector.h>
46#include <TVirtualMC.h>
fe4da5cc 47
88cb7938 48#include "AliConst.h"
49#include "AliHeader.h"
50#include "AliHitMap.h"
51#include "AliLoader.h"
aa43efee 52#include "AliESD.h"
53#include "AliESDMuonTrack.h"
3fa6cfdd 54#include "AliMUONLoader.h"
fe4da5cc 55#include "AliMUON.h"
aa43efee 56#include "AliMUONTriggerTrack.h"
57#include "AliMUONEventReconstructor.h"
58#include "AliMUONTrack.h"
59#include "AliMUONTrackParam.h"
88cb7938 60#include "AliMUONChamberTrigger.h"
61#include "AliMUONClusterFinderVS.h"
62#include "AliMUONClusterInput.h"
63#include "AliMUONConstants.h"
64#include "AliMUONDigit.h"
65#include "AliMUONGlobalTrigger.h"
a9e2aefa 66#include "AliMUONHit.h"
88cb7938 67#include "AliMUONHitMapA1.h"
68#include "AliMUONLocalTrigger.h"
69#include "AliMUONMerger.h"
a9e2aefa 70#include "AliMUONPadHit.h"
a9e2aefa 71#include "AliMUONRawCluster.h"
88cb7938 72#include "AliMUONTransientDigit.h"
ecfa008b 73#include "AliMUONTriggerCircuit.h"
a9e2aefa 74#include "AliMUONTriggerDecision.h"
d1cd2474 75#include "AliMUONVGeometryBuilder.h"
88cb7938 76#include "AliRun.h"
85a5290f 77#include "AliMUONDigitizerv1.h"
88cb7938 78
a9e2aefa 79
80// Defaults parameters for Z positions of chambers
81// taken from values for "stations" in AliMUON::AliMUON
82// const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
83// and from array "dstation" in AliMUONv1::CreateGeometry
84// Float_t dstation[5]={20., 20., 20, 20., 20.};
85// for tracking chambers,
86// according to (Z1 = zch - dstation) and (Z2 = zch + dstation)
87// for the first and second chambers in the station, respectively,
88// and from "DTPLANES" in AliMUONv1::CreateGeometry
89// const Float_t DTPLANES = 15.;
90// for trigger chambers,
91// according to (Z1 = zch) and (Z2 = zch + DTPLANES)
92// for the first and second chambers in the station, respectively
fe4da5cc 93
fe4da5cc 94ClassImp(AliMUON)
ce3f5e87 95//__________________________________________________________________
fe4da5cc 96AliMUON::AliMUON()
97{
de05461e 98// Default Constructor
99//
1bd28025 100 fNCh = 0;
101 fNTrackingCh = 0;
1bd26093 102 fIshunt = 0;
1bd28025 103 fChambers = 0;
d1cd2474 104 fGeometryBuilders = 0;
ce3f5e87 105 fTriggerCircuits = 0;
1bd26093 106 fAccMin = 0.;
107 fAccMax = 0.;
108 fAccCut = kFALSE;
1cae9436 109 fMerger = 0;
edf34242 110 fFileName = 0;
aecb8bcd 111 fMUONData = 0;
d652f85c 112 fSplitLevel = 0;
fe4da5cc 113}
ce3f5e87 114//__________________________________________________________________
fe4da5cc 115AliMUON::AliMUON(const char *name, const char *title)
ce3f5e87 116 : AliDetector(name,title)
fe4da5cc 117{
118//Begin_Html
119/*
a897a37a 120<img src="gif/alimuon.gif">
fe4da5cc 121*/
122//End_Html
ce3f5e87 123 fMUONData = 0x0;
d652f85c 124 fSplitLevel= 0;
ce3f5e87 125 fIshunt = 0;
f665c1ea 126
ce3f5e87 127 fNCh = AliMUONConstants::NCh();
128 fNTrackingCh = AliMUONConstants::NTrackingCh();
a897a37a 129
ce3f5e87 130 SetMarkerColor(kRed);//
a9e2aefa 131//
ce3f5e87 132// Creating List of Chambers
a9e2aefa 133 Int_t ch;
f665c1ea 134 fChambers = new TObjArray(AliMUONConstants::NCh());
d1cd2474 135 fGeometryBuilders = new TObjArray(AliMUONConstants::NCh());
136
a9e2aefa 137 // Loop over stations
f665c1ea 138 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
a9e2aefa 139 // Loop over 2 chambers in the station
ce3f5e87 140 for (Int_t stCH = 0; stCH < 2; stCH++) {
141 //
142 //
143 // Default Parameters for Muon Tracking Stations
144 ch = 2 * st + stCH;
145 if (ch < AliMUONConstants::NTrackingCh()) {
146 fChambers->AddAt(new AliMUONChamber(ch),ch);
147 } else {
148 fChambers->AddAt(new AliMUONChamberTrigger(ch),ch);
149 }
150 AliMUONChamber* chamber = (AliMUONChamber*) fChambers->At(ch);
d1cd2474 151 //chamber->SetGid(0);
ce3f5e87 152 // Default values for Z of chambers
153 chamber->SetZ(AliMUONConstants::DefaultChamberZ(ch));
154 //
155 chamber->InitGeo(AliMUONConstants::DefaultChamberZ(ch));
156 // Set chamber inner and outer radius to default
157 chamber->SetRInner(AliMUONConstants::Dmin(st)/2);
158 chamber->SetROuter(AliMUONConstants::Dmax(st)/2);
159 //
160 } // Chamber stCH (0, 1) in
a9e2aefa 161 } // Station st (0...)
ce3f5e87 162
1391e633 163 // Negatives values are ignored by geant3 CONS200 in the calculation of the tracking parameters
164 fMaxStepGas=0.1;
165 fMaxStepAlu=0.1;
a9e2aefa 166 fMaxDestepGas=-1;
167 fMaxDestepAlu=-1;
ce3f5e87 168
169 fMaxIterPad = 0;
170 fCurIterPad = 0;
171
172 fAccMin = 0.;
173 fAccMax = 0.;
174 fAccCut = kFALSE;
175
176 // cp new design of AliMUONTriggerDecision
177 fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
178 for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
179 fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);
180 }
181 fMerger = 0;
fe4da5cc 182}
ce3f5e87 183//____________________________________________________________________
50e97f19 184AliMUON::AliMUON(const AliMUON& rMUON):AliDetector(rMUON)
a9e2aefa 185{
186// Dummy copy constructor
187 ;
188
189}
ce3f5e87 190//____________________________________________________________________
fe4da5cc 191AliMUON::~AliMUON()
192{
de05461e 193// Destructor
ce3f5e87 194 if(fDebug) printf("%s: Calling AliMUON destructor !!!\n",ClassName());
195 fIshunt = 0;
196 if (fMerger) delete fMerger;
d1cd2474 197
198 if (fGeometryBuilders){
199 fGeometryBuilders->Delete();
200 delete fGeometryBuilders;
201 }
202}
203//_____________________________________________________________________________
204void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
205{
206// Adds the geometry builder to the list
207// ---
208
209 fGeometryBuilders->Add(geomBuilder);
a897a37a 210}
ce3f5e87 211//____________________________________________________________________
fe4da5cc 212void AliMUON::BuildGeometry()
213{
de05461e 214// Geometry for event display
5fd73042 215 for (Int_t i=0; i<7; i++) {
216 for (Int_t j=0; j<2; j++) {
217 Int_t id=2*i+j+1;
218 this->Chamber(id-1).SegmentationModel(1)->Draw("eventdisplay");
a897a37a 219 }
5fd73042 220 }
fe4da5cc 221}
ce3f5e87 222//___________________________________________________________________
fe4da5cc 223Int_t AliMUON::DistancetoPrimitive(Int_t , Int_t )
224{
ce3f5e87 225 return 9999;
fe4da5cc 226}
ce3f5e87 227//__________________________________________________________________
228void AliMUON::SetTreeAddress()
a897a37a 229{
ce3f5e87 230 GetMUONData()->SetLoader(fLoader);
231 GetMUONData()->SetTreeAddress("H,D,RC");
d652f85c 232 fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector
a9e2aefa 233}
234
ce3f5e87 235//____________________________________________________________________
a9e2aefa 236void AliMUON::SetPadSize(Int_t id, Int_t isec, Float_t p1, Float_t p2)
237{
de05461e 238// Set the pad size for chamber id and cathode isec
a9e2aefa 239 Int_t i=2*(id-1);
2682e810 240 ((AliMUONChamber*) fChambers->At(i)) ->SetPadSize(isec,p1,p2);
241 ((AliMUONChamber*) fChambers->At(i+1))->SetPadSize(isec,p1,p2);
a897a37a 242}
243
fe4da5cc 244//___________________________________________
a9e2aefa 245void AliMUON::SetChambersZ(const Float_t *Z)
246{
247 // Set Z values for all chambers (tracking and trigger)
248 // from the array pointed to by "Z"
f665c1ea 249 for (Int_t ch = 0; ch < AliMUONConstants::NCh(); ch++)
2682e810 250 ((AliMUONChamber*) fChambers->At(ch))->SetZ(Z[ch]);
f665c1ea 251 return;
a9e2aefa 252}
ce3f5e87 253//_________________________________________________________________
a9e2aefa 254void AliMUON::SetChambersZToDefault()
fe4da5cc 255{
a9e2aefa 256 // Set Z values for all chambers (tracking and trigger)
257 // to default values
f665c1ea 258 SetChambersZ(AliMUONConstants::DefaultChamberZ());
a9e2aefa 259 return;
fe4da5cc 260}
ce3f5e87 261//_________________________________________________________________
a897a37a 262void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
fe4da5cc 263{
de05461e 264// Set the inverse charge slope for chamber id
ce3f5e87 265 Int_t i=2*(id-1); //PH ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
266 //PH ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
2682e810 267 ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
268 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
fe4da5cc 269}
ce3f5e87 270//__________________________________________________________________
a897a37a 271void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
fe4da5cc 272{
de05461e 273// Set sigma of charge spread for chamber id
fe4da5cc 274 Int_t i=2*(id-1);
2682e810 275 ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
276 ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
fe4da5cc 277}
ce3f5e87 278//___________________________________________________________________
a897a37a 279void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
fe4da5cc 280{
de05461e 281// Set integration limits for charge spread
fe4da5cc 282 Int_t i=2*(id-1);
2682e810 283 ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
284 ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
fe4da5cc 285}
286
ce3f5e87 287//__________________________________________________________________
d09fafb0 288void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
fe4da5cc 289{
de05461e 290// Set maximum number for ADCcounts (saturation)
fe4da5cc 291 Int_t i=2*(id-1);
2682e810 292 ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
293 ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
fe4da5cc 294}
ce3f5e87 295//__________________________________________________________________
a897a37a 296void AliMUON::SetMaxStepGas(Float_t p1)
fe4da5cc 297{
de05461e 298// Set stepsize in gas
ce3f5e87 299 fMaxStepGas=p1;
fe4da5cc 300}
ce3f5e87 301//__________________________________________________________________
a897a37a 302void AliMUON::SetMaxStepAlu(Float_t p1)
fe4da5cc 303{
de05461e 304// Set step size in Alu
fe4da5cc 305 fMaxStepAlu=p1;
306}
ce3f5e87 307//__________________________________________________________________
a897a37a 308void AliMUON::SetMaxDestepGas(Float_t p1)
fe4da5cc 309{
de05461e 310// Set maximum step size in Gas
fe4da5cc 311 fMaxDestepGas=p1;
312}
ce3f5e87 313//__________________________________________________________________
a897a37a 314void AliMUON::SetMaxDestepAlu(Float_t p1)
fe4da5cc 315{
de05461e 316// Set maximum step size in Alu
ce3f5e87 317 fMaxDestepAlu=p1;
fe4da5cc 318}
ce3f5e87 319//___________________________________________________________________
5c1f55c5 320void AliMUON::SetAcceptance(Bool_t acc, Float_t angmin, Float_t angmax)
fe4da5cc 321{
de05461e 322// Set acceptance cuts
ce3f5e87 323 fAccCut=acc;
324 fAccMin=angmin*TMath::Pi()/180;
325 fAccMax=angmax*TMath::Pi()/180;
326 Int_t ch;
327 if (acc) {
328 for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
329 // Loop over 2 chambers in the station
330 for (Int_t stCH = 0; stCH < 2; stCH++) {
331 ch = 2 * st + stCH;
332 // Set chamber inner and outer radius according to acceptance cuts
b13a15bc 333 Chamber(ch).SetRInner(TMath::Abs(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMin)));
334 Chamber(ch).SetROuter(TMath::Abs(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMax)));
ce3f5e87 335 } // chamber loop
336 } // station loop
337 }
fe4da5cc 338}
d1cd2474 339
340//____________________________________________________________________
341Float_t AliMUON::GetMaxStepGas() const
342{
343// Return stepsize in gas
344
345 return fMaxStepGas;
346}
347
348//____________________________________________________________________
349Float_t AliMUON::GetMaxStepAlu() const
350{
351// Return step size in Alu
352
353 return fMaxStepAlu;
354}
355
356//____________________________________________________________________
357Float_t AliMUON::GetMaxDestepGas() const
358{
359// Return maximum step size in Gas
360
361 return fMaxDestepGas;
362}
363
364//____________________________________________________________________
365Float_t AliMUON::GetMaxDestepAlu() const
366{
367// Return maximum step size in Gas
368
369 return fMaxDestepAlu;
370}
371
ce3f5e87 372//____________________________________________________________________
a30a000f 373void AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliSegmentation *segmentation)
fe4da5cc 374{
de05461e 375// Set the segmentation for chamber id cathode isec
2682e810 376 ((AliMUONChamber*) fChambers->At(id))->SetSegmentationModel(isec, segmentation);
fe4da5cc 377
378}
ce3f5e87 379//____________________________________________________________________
a9e2aefa 380void AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
fe4da5cc 381{
de05461e 382// Set the response for chamber id
2682e810 383 ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
fe4da5cc 384}
ce3f5e87 385//____________________________________________________________________
30aaba74 386void AliMUON::SetReconstructionModel(Int_t id, AliMUONClusterFinderVS *reconst)
a897a37a 387{
de05461e 388// Set ClusterFinder for chamber id
2682e810 389 ((AliMUONChamber*) fChambers->At(id))->SetReconstructionModel(reconst);
a897a37a 390}
ce3f5e87 391//____________________________________________________________________
fe4da5cc 392void AliMUON::SetNsec(Int_t id, Int_t nsec)
393{
de05461e 394// Set number of segmented cathods for chamber id
2682e810 395 ((AliMUONChamber*) fChambers->At(id))->SetNsec(nsec);
fe4da5cc 396}
85a5290f 397//____________________________________________________________________
c92eb8ad 398AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
85a5290f 399{
400 return new AliMUONDigitizerv1(manager);
401}
ce3f5e87 402//_____________________________________________________________________
2ab0c725 403void AliMUON::SDigits2Digits()
404{
d963c261 405
406// write TreeD here
407
408 if (!fMerger) {
409 if (gAlice->GetDebug()>0) {
410 cerr<<"AliMUON::SDigits2Digits: create default AliMUONMerger "<<endl;
411 cerr<<" no merging, just digitization of 1 event will be done"<<endl;
412 }
413 fMerger = new AliMUONMerger();
2ab0c725 414 }
d963c261 415 fMerger->Init();
416 fMerger->Digitise();
417 char hname[30];
88cb7938 418 // sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
419 fLoader->TreeD()->Write(hname,TObject::kOverwrite);
420 fLoader->TreeD()->Reset();
2ab0c725 421}
a9e2aefa 422
ce3f5e87 423//_______________________________________________________________________
3fa6cfdd 424AliLoader* AliMUON::MakeLoader(const char* topfoldername)
425{
426//builds standard getter (AliLoader type)
427//if detector wants to use castomized getter, it must overload this method
428
429 if (GetDebug())
430 Info("MakeLoader",
431 "Creating standard getter for detector %s. Top folder is %s.",
432 GetName(),topfoldername);
433
128843d9 434 fLoader = new AliLoader(GetName(),topfoldername);
ce3f5e87 435 fMUONData = new AliMUONData(fLoader,GetName(),GetName());
d652f85c 436 fMUONData->SetSplitLevel(fSplitLevel);
3fa6cfdd 437 return fLoader;
438}
a897a37a 439
ce3f5e87 440//_______________________________________________________________________
a9e2aefa 441void AliMUON::Trigger(Int_t nev){
442// call the Trigger Algorithm and fill TreeR
443
444 Int_t singlePlus[3] = {0,0,0};
445 Int_t singleMinus[3] = {0,0,0};
446 Int_t singleUndef[3] = {0,0,0};
447 Int_t pairUnlike[3] = {0,0,0};
448 Int_t pairLike[3] = {0,0,0};
ce3f5e87 449
a9e2aefa 450 ResetTrigger();
a9e2aefa 451 AliMUONTriggerDecision* decision= new AliMUONTriggerDecision(1);
452 decision->Trigger();
453 decision->GetGlobalTrigger(singlePlus, singleMinus, singleUndef,
454 pairUnlike, pairLike);
ce3f5e87 455
456 // add a local trigger in the list
457 GetMUONData()->AddGlobalTrigger(singlePlus, singleMinus, singleUndef, pairUnlike, pairLike);
9ae15266 458 Int_t i;
a9e2aefa 459
f665c1ea 460 for (Int_t icirc=0; icirc<AliMUONConstants::NTriggerCircuit(); icirc++) {
ce3f5e87 461 if(decision->GetITrigger(icirc)==1) {
462 Int_t localtr[7]={0,0,0,0,0,0,0};
463 Int_t loLpt[2]={0,0}; Int_t loHpt[2]={0,0}; Int_t loApt[2]={0,0};
464 decision->GetLutOutput(icirc, loLpt, loHpt, loApt);
465 localtr[0] = icirc;
466 localtr[1] = decision->GetStripX11(icirc);
467 localtr[2] = decision->GetDev(icirc);
468 localtr[3] = decision->GetStripY11(icirc);
469 for (i=0; i<2; i++) { // convert the Lut output in 1 digit
470 localtr[4] = localtr[4]+Int_t(loLpt[i]*TMath::Power(2,i));
471 localtr[5] = localtr[5]+Int_t(loHpt[i]*TMath::Power(2,i));
472 localtr[6] = localtr[6]+Int_t(loApt[i]*TMath::Power(2,i));
a897a37a 473 }
ce3f5e87 474 GetMUONData()->AddLocalTrigger(localtr); // add a local trigger in the list
475 }
a9e2aefa 476 }
ce3f5e87 477
a9e2aefa 478 delete decision;
bf17dbfd 479
ba9436c6 480 // fLoader->TreeR()->Fill();
1a1cdff8 481 GetMUONData()->Fill("GLT"); //Filling Global and Local Trigger GLT
ce3f5e87 482 // char hname[30];
483 // sprintf(hname,"TreeR%d",nev);
484 // fLoader->TreeR()->Write(hname,TObject::kOverwrite);
bf17dbfd 485 // fLoader->TreeR()->Reset();
88cb7938 486 fLoader->WriteRecPoints("OVERWRITE");
88cb7938 487
a9e2aefa 488 printf("\n End of trigger for event %d", nev);
a897a37a 489}
a897a37a 490
ce3f5e87 491//____________________________________________________________________
fe311ef1 492void AliMUON::Digits2Reco()
493{
494 FindClusters();
e365e1ee 495 Int_t nev = gAlice->GetHeader()->GetEvent();
1a1cdff8 496 GetMUONData()->Fill("RC"); //Filling Reconstructed Cluster
88cb7938 497 fLoader->WriteRecPoints("OVERWRITE");
ce3f5e87 498 GetMUONData()->ResetRawClusters();
1a1cdff8 499 Info("Digits2Reco","End of cluster finding for event %d", nev);
fe311ef1 500}
ce3f5e87 501//____________________________________________________________________
fe311ef1 502void AliMUON::FindClusters()
a9e2aefa 503{
de05461e 504//
505// Perform cluster finding
506//
a9e2aefa 507 TClonesArray *dig1, *dig2;
508 Int_t ndig, k;
509 dig1 = new TClonesArray("AliMUONDigit",1000);
510 dig2 = new TClonesArray("AliMUONDigit",1000);
511 AliMUONDigit *digit;
a9e2aefa 512// Loop on chambers and on cathode planes
a897a37a 513//
fe311ef1 514 ResetRawClusters();
88cb7938 515 TClonesArray * muonDigits;
516
1bd28025 517 for (Int_t ich = 0; ich < 10; ich++) {
2682e810 518 //PH AliMUONChamber* iChamber = (AliMUONChamber*) (*fChambers)[ich];
519 AliMUONChamber* iChamber = (AliMUONChamber*) fChambers->At(ich);
fe311ef1 520 AliMUONClusterFinderVS* rec = iChamber->ReconstructionModel();
521
88cb7938 522 ResetDigits();
1a1cdff8 523 GetMUONData()->GetCathode(0);
88cb7938 524 //TClonesArray *
1a1cdff8 525 muonDigits = GetMUONData()->Digits(ich);
a9e2aefa 526 ndig=muonDigits->GetEntriesFast();
88cb7938 527 printf("\n 1 Found %d digits in %p chamber %d", ndig, muonDigits,ich);
a9e2aefa 528 TClonesArray &lhits1 = *dig1;
1bd28025 529 Int_t n = 0;
530 for (k = 0; k < ndig; k++) {
531 digit = (AliMUONDigit*) muonDigits->UncheckedAt(k);
532 if (rec->TestTrack(digit->Track(0)))
a9e2aefa 533 new(lhits1[n++]) AliMUONDigit(*digit);
534 }
1a1cdff8 535 GetMUONData()->ResetDigits();
536 GetMUONData()->GetCathode(1);
537 muonDigits = GetMUONData()->Digits(ich);
a9e2aefa 538 ndig=muonDigits->GetEntriesFast();
539 printf("\n 2 Found %d digits in %p %d", ndig, muonDigits, ich);
540 TClonesArray &lhits2 = *dig2;
541 n=0;
542
543 for (k=0; k<ndig; k++) {
544 digit= (AliMUONDigit*) muonDigits->UncheckedAt(k);
1bd28025 545 if (rec->TestTrack(digit->Track(0)))
a9e2aefa 546 new(lhits2[n++]) AliMUONDigit(*digit);
a897a37a 547 }
a897a37a 548
9825400f 549 if (rec) {
550 AliMUONClusterInput::Instance()->SetDigits(ich, dig1, dig2);
a9e2aefa 551 rec->FindRawClusters();
552 }
553 dig1->Delete();
554 dig2->Delete();
555 } // for ich
a9e2aefa 556 delete dig1;
557 delete dig2;
a897a37a 558}
ce3f5e87 559//______________________________________________________________________
2ab0c725 560#ifdef never
ce3f5e87 561void AliMUON::Streamer(TBuffer &R__b)_
fe4da5cc 562{
563 // Stream an object of class AliMUON.
a30a000f 564 AliMUONChamber *iChamber;
a9e2aefa 565 AliMUONTriggerCircuit *iTriggerCircuit;
a30a000f 566 AliSegmentation *segmentation;
567 AliMUONResponse *response;
568 TClonesArray *digitsaddress;
569 TClonesArray *rawcladdress;
9ae15266 570 Int_t i;
9ae15266 571 if (R__b.IsReading()) {
572 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
573 AliDetector::Streamer(R__b);
574 R__b >> fNPadHits;
575 R__b >> fPadHits; // diff
576 R__b >> fNLocalTrigger;
577 R__b >> fLocalTrigger;
578 R__b >> fNGlobalTrigger;
579 R__b >> fGlobalTrigger;
580 R__b >> fDchambers;
581 R__b >> fRawClusters;
582 R__b.ReadArray(fNdch);
583 R__b.ReadArray(fNrawch);
584 R__b >> fAccCut;
585 R__b >> fAccMin;
586 R__b >> fAccMax;
587 R__b >> fChambers;
588 R__b >> fTriggerCircuits;
f665c1ea 589 for (i =0; i<AliMUONConstants::NTriggerCircuit(); i++) {
9ae15266 590 iTriggerCircuit=(AliMUONTriggerCircuit*) (*fTriggerCircuits)[i];
591 iTriggerCircuit->Streamer(R__b);
fe4da5cc 592 }
9ae15266 593// Stream chamber related information
f665c1ea 594 for (i =0; i<AliMUONConstants::NCh(); i++) {
9ae15266 595 iChamber=(AliMUONChamber*) (*fChambers)[i];
596 iChamber->Streamer(R__b);
597 if (iChamber->Nsec()==1) {
598 segmentation=iChamber->SegmentationModel(1);
599 if (segmentation)
600 segmentation->Streamer(R__b);
601 } else {
602 segmentation=iChamber->SegmentationModel(1);
603 if (segmentation)
604 segmentation->Streamer(R__b);
605 if (segmentation)
606 segmentation=iChamber->SegmentationModel(2);
607 segmentation->Streamer(R__b);
608 }
609 response=iChamber->ResponseModel();
610 if (response)
611 response->Streamer(R__b);
612 digitsaddress=(TClonesArray*) (*fDchambers)[i];
613 digitsaddress->Streamer(R__b);
f665c1ea 614 if (i < AliMUONConstants::NTrackingCh()) {
9ae15266 615 rawcladdress=(TClonesArray*) (*fRawClusters)[i];
616 rawcladdress->Streamer(R__b);
617 }
a9e2aefa 618 }
9ae15266 619
620 } else {
621 R__b.WriteVersion(AliMUON::IsA());
622 AliDetector::Streamer(R__b);
623 R__b << fNPadHits;
624 R__b << fPadHits; // diff
625 R__b << fNLocalTrigger;
626 R__b << fLocalTrigger;
627 R__b << fNGlobalTrigger;
628 R__b << fGlobalTrigger;
629 R__b << fDchambers;
630 R__b << fRawClusters;
f665c1ea 631 R__b.WriteArray(fNdch, AliMUONConstants::NCh());
632 R__b.WriteArray(fNrawch, AliMUONConstants::NTrackingCh());
9ae15266 633
634 R__b << fAccCut;
635 R__b << fAccMin;
636 R__b << fAccMax;
637
638 R__b << fChambers;
639 R__b << fTriggerCircuits;
f665c1ea 640 for (i =0; i<AliMUONConstants::NTriggerCircuit(); i++) {
9ae15266 641 iTriggerCircuit=(AliMUONTriggerCircuit*) (*fTriggerCircuits)[i];
642 iTriggerCircuit->Streamer(R__b);
fe4da5cc 643 }
f665c1ea 644 for (i =0; i<AliMUONConstants::NCh(); i++) {
9ae15266 645 iChamber=(AliMUONChamber*) (*fChambers)[i];
646 iChamber->Streamer(R__b);
647 if (iChamber->Nsec()==1) {
648 segmentation=iChamber->SegmentationModel(1);
649 if (segmentation)
650 segmentation->Streamer(R__b);
651 } else {
652 segmentation=iChamber->SegmentationModel(1);
653 if (segmentation)
654 segmentation->Streamer(R__b);
655 segmentation=iChamber->SegmentationModel(2);
656 if (segmentation)
657 segmentation->Streamer(R__b);
658 }
659 response=iChamber->ResponseModel();
660 if (response)
661 response->Streamer(R__b);
662 digitsaddress=(TClonesArray*) (*fDchambers)[i];
663 digitsaddress->Streamer(R__b);
f665c1ea 664 if (i < AliMUONConstants::NTrackingCh()) {
9ae15266 665 rawcladdress=(TClonesArray*) (*fRawClusters)[i];
666 rawcladdress->Streamer(R__b);
667 }
a9e2aefa 668 }
fe4da5cc 669 }
fe4da5cc 670}
2ab0c725 671#endif
ce3f5e87 672//_______________________________________________________________________
a9e2aefa 673AliMUONPadHit* AliMUON::FirstPad(AliMUONHit* hit, TClonesArray *clusters)
fe4da5cc 674{
5a35ac13 675// to be removed
fe4da5cc 676 // Initialise the pad iterator
677 // Return the address of the first padhit for hit
a897a37a 678 TClonesArray *theClusters = clusters;
fe4da5cc 679 Int_t nclust = theClusters->GetEntriesFast();
1bd28025 680 if (nclust && hit->PHlast() > 0) {
681 AliMUON::fMaxIterPad=hit->PHlast();
682 AliMUON::fCurIterPad=hit->PHfirst();
a9e2aefa 683 return (AliMUONPadHit*) clusters->UncheckedAt(AliMUON::fCurIterPad-1);
fe4da5cc 684 } else {
685 return 0;
686 }
687}
ce3f5e87 688//_______________________________________________________________________
a9e2aefa 689AliMUONPadHit* AliMUON::NextPad(TClonesArray *clusters)
fe4da5cc 690{
5a35ac13 691 // To be removed
de05461e 692// Get next pad (in iterator)
693//
a9e2aefa 694 AliMUON::fCurIterPad++;
695 if (AliMUON::fCurIterPad <= AliMUON::fMaxIterPad) {
696 return (AliMUONPadHit*) clusters->UncheckedAt(AliMUON::fCurIterPad-1);
fe4da5cc 697 } else {
698 return 0;
699 }
700}
ce3f5e87 701//_______________________________________________________________________
a897a37a 702
703AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
704{
de05461e 705//
706// Return rawcluster (icluster) for chamber ichamber and cathode icathod
707// Obsolete ??
ce3f5e87 708 TClonesArray *muonRawCluster = GetMUONData()->RawClusters(ichamber);
a897a37a 709 ResetRawClusters();
88cb7938 710 TTree *treeR = fLoader->TreeR();
a9e2aefa 711 Int_t nent=(Int_t)treeR->GetEntries();
712 treeR->GetEvent(nent-2+icathod-1);
713 //treeR->GetEvent(icathod);
714 //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
a897a37a 715
a9e2aefa 716 AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
a897a37a 717 //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
718
719 return mRaw;
720}
ce3f5e87 721//________________________________________________________________________
1cae9436 722void AliMUON::SetMerger(AliMUONMerger* merger)
723{
724// Set pointer to merger
725 fMerger = merger;
726}
ce3f5e87 727//________________________________________________________________________
1cae9436 728AliMUONMerger* AliMUON::Merger()
729{
730// Return pointer to merger
731 return fMerger;
732}
ce3f5e87 733//________________________________________________________________________
50e97f19 734AliMUON& AliMUON::operator = (const AliMUON& /*rhs*/)
a897a37a 735{
a9e2aefa 736// copy operator
737// dummy version
738 return *this;
a897a37a 739}
aa43efee 740//________________________________________________________________________
741void AliMUON::Reconstruct() const
742{
743// reconstruct clusters
744
9a22765d 745// AliLoader* loader = GetLoader();
746 AliRunLoader* runLoader = fLoader->GetRunLoader();
aa43efee 747 Int_t nEvents = runLoader->GetNumberOfEvents();
748
749 for (Int_t i = 0; i < 10; i++) {
750 AliMUONClusterFinderVS *RecModel = new AliMUONClusterFinderVS();
751 RecModel->SetGhostChi2Cut(10);
752 const_cast<AliMUON*>(this)->SetReconstructionModel(i,RecModel);
753 }
754
755 AliMUONEventReconstructor* reco = new AliMUONEventReconstructor();
756
9a22765d 757 fLoader->LoadRecPoints("RECREATE");
758 fLoader->LoadTracks("RECREATE");
759 fLoader->LoadDigits("READ");
aa43efee 760
761
762 // Loop over events
763 for(Int_t ievent = 0; ievent < nEvents; ievent++) {
764 printf("event %d\n",ievent);
765 runLoader->GetEvent(ievent);
766
767 //---------------------------- digit2Reco & Trigger ---------------------
9a22765d 768 if (!fLoader->TreeR()) fLoader->MakeRecPointsContainer();
aa43efee 769
770 // tracking branch
771 fMUONData->MakeBranch("RC");
772 fMUONData->SetTreeAddress("D,RC");
773 const_cast<AliMUON*>(this)->Digits2Reco();
774
775 // trigger branch
776 fMUONData->MakeBranch("GLT");
777 fMUONData->SetTreeAddress("D,GLT");
778 const_cast<AliMUON*>(this)->Trigger(ievent);
779
780 //---------------------------- Track & TriggerTrack ---------------------
9a22765d 781 if (!fLoader->TreeT()) fLoader->MakeTracksContainer();
aa43efee 782
783 fMUONData->MakeBranch("RT"); //track
784 fMUONData->SetTreeAddress("RT");
785 reco->EventReconstruct();
786 for(Int_t i=0; i<reco->GetNRecTracks(); i++) {
787 AliMUONTrack * track = (AliMUONTrack*) reco->GetRecTracksPtr()->At(i);
788 fMUONData->AddRecTrack(*track);
789 }
790 fMUONData->Fill("RT");
791
792 fMUONData->MakeBranch("RL"); //trigger track
793 fMUONData->SetTreeAddress("RL");
794 reco->EventReconstructTrigger();
795 for(Int_t i=0; i<reco->GetNRecTriggerTracks(); i++) {
796 AliMUONTriggerTrack * triggertrack = (AliMUONTriggerTrack*) reco->GetRecTriggerTracksPtr()->At(i);
797 fMUONData->AddRecTriggerTrack(*triggertrack);
798 }
799 fMUONData->Fill("RL");
800
9a22765d 801 fLoader->WriteTracks("OVERWRITE");
aa43efee 802
803 //--------------------------- Resetting branches -----------------------
804 fMUONData->ResetDigits();
805 fMUONData->ResetRawClusters();
806 fMUONData->ResetTrigger();
807 fMUONData->ResetRecTracks();
808 fMUONData->ResetRecTriggerTracks();
809 }
9a22765d 810 fLoader->UnloadDigits();
811 fLoader->UnloadRecPoints();
812 fLoader->UnloadTracks();
813 //delete reco;
aa43efee 814}
815//________________________________________________________________________
816void AliMUON::FillESD(AliESD* event) const
817{
818
819 TClonesArray * recTracksArray;
820
bdfa9e49 821 //YS AliLoader* loader = GetLoader();
822 AliRunLoader* runLoader = fLoader->GetRunLoader(); //YS loader->GetRunLoader();
823 fLoader->LoadTracks("READ"); //YS
aa43efee 824
825
826 // declaration
827 Int_t ievent;
828 Int_t ntrackhits;
829 Double_t fitfmin;
830 Int_t nrectracks;
831
832 Double_t bendingSlope, nonBendingSlope, fInverseBendingMomentum;
833 Double_t fXRec, fYRec, fZRec;
834
835 Float_t x11, y11, thetaX,thetaY ;
836
bdfa9e49 837 //YS Int_t nEvents = runLoader->GetNumberOfEvents();
aa43efee 838
839 // setting pointer for tracks, triggertracks& trackparam at vertex
840 AliMUONTrack * rectrack;
841 AliMUONTriggerTrack * rectriggertrack;
842 AliMUONTrackParam *trackParam;
bdfa9e49 843
844 ievent = runLoader->GetEventNumber() ; //YS
845 //YS for (ievent = 0; ievent < nEvents; ievent++) {
aa43efee 846 runLoader->GetEvent(ievent);
847
848 // setting ESD MUON class
849 AliESDMuonTrack* ESDTrack = new AliESDMuonTrack() ;
850
851 // -------------------- tracks-------------
852 fMUONData->SetTreeAddress("RT");
853 fMUONData->GetRecTracks();
854 recTracksArray = fMUONData->RecTracks();
855
856 nrectracks = (Int_t) recTracksArray->GetEntriesFast(); //
857
858 // printf(">>> Event %d Number of Recconstructed tracks %d \n",ievent, nrectracks);
859
860 // read track infos
861 for (Int_t irectracks = 0; irectracks < nrectracks; irectracks++) {
862
863 rectrack = (AliMUONTrack*) recTracksArray->At(irectracks);
864
865 trackParam = rectrack->GetTrackParamAtVertex();
866
867 bendingSlope = trackParam->GetBendingSlope();
868 nonBendingSlope = trackParam->GetNonBendingSlope();
869 fInverseBendingMomentum = trackParam->GetInverseBendingMomentum();
870 fXRec = trackParam->GetNonBendingCoor();
871 fYRec = trackParam->GetBendingCoor();
872 fZRec = trackParam->GetZ();
873
874 ntrackhits = rectrack->GetNTrackHits();
875 fitfmin = rectrack->GetFitFMin();
876
877 // setting data member of ESD MUON
878 ESDTrack->SetInverseBendingMomentum(fInverseBendingMomentum);
879 ESDTrack->SetThetaX(TMath::ATan(nonBendingSlope));
880 ESDTrack->SetThetaY(TMath::ATan(bendingSlope));
881 ESDTrack->SetZ(fZRec);
882 ESDTrack->SetBendingCoor(fYRec);
883 ESDTrack->SetNonBendingCoor(fXRec);
884 ESDTrack->SetChi2(fitfmin);
885 ESDTrack->SetNHit(ntrackhits);
886 }
887
888 // // -------------------- trigger tracks-------------
889 fMUONData->SetTreeAddress("RL");
890 fMUONData->GetRecTriggerTracks();
891 recTracksArray = fMUONData->RecTriggerTracks();
892
bdfa9e49 893 Int_t ntrectracks = (Int_t) recTracksArray->GetEntriesFast(); //YS
aa43efee 894
895 // printf(">>> Event %d Number of Recconstructed tracks %d \n",ievent, nrectracks);
896
897 // read trigger track infos
bdfa9e49 898 for (Int_t irectracks = 0; irectracks < ntrectracks; irectracks++) {
aa43efee 899
900 rectriggertrack = (AliMUONTriggerTrack*) recTracksArray->At(irectracks);
901
902 x11 = rectriggertrack->GetY11();
903 y11 = rectriggertrack->GetY11();
904 thetaX = rectriggertrack->GetThetax();
905 thetaY = rectriggertrack->GetThetay();
906
907 // setting data member of ESD MUON trigger
908 ESDTrack->SetThetaX11(thetaX);
909 ESDTrack->SetThetaY11(thetaY);
910 ESDTrack->SetX11(x11);
911 ESDTrack->SetY11(y11);
912 }
913
914 // storing ESD MUON Track into ESD Event & reset muondata
bdfa9e49 915 if (ntrectracks+ntrectracks != 0) //YS
916 event->AddMuonTrack(ESDTrack);
aa43efee 917 fMUONData->ResetRecTracks();
918 fMUONData->ResetRecTriggerTracks();
919
bdfa9e49 920 //YS } // end loop on event
921 fLoader->UnloadTracks(); //YS
aa43efee 922}
a897a37a 923