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