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