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