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