]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON.cxx
include RICH in tracking
[u/mrichter/AliRoot.git] / MUON / AliMUON.cxx
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  **************************************************************************/
15
16 /* $Id$ */
17
18
19 ///////////////////////////////////////////////
20 //  Manager and hits classes for set:MUON     //
21 ////////////////////////////////////////////////
22
23 #include "Riostream.h"
24
25 #include <AliPDG.h>
26 #include <TBRIK.h>
27 #include <TCanvas.h>
28 #include <TDirectory.h>
29 #include <TFile.h>
30 #include <TGeometry.h>
31 #include <TMinuit.h>
32 #include <TNode.h> 
33 #include <TNtuple.h>
34 #include <TObjArray.h>
35 #include <TObject.h>
36 #include <TObjectTable.h>
37 #include <TPad.h>
38 #include <TParticle.h>
39 #include <TROOT.h>
40 #include <TRandom.h> 
41 #include <TRotMatrix.h>
42 #include <TTUBE.h>
43 #include <TTUBE.h>
44 #include <TTree.h> 
45 #include <TVector.h>
46 #include <TVirtualMC.h>
47
48 //#include "AliHeader.h"
49 #include "AliLoader.h"
50 #include "AliRunDigitizer.h"
51 #include "AliMC.h"
52 #include "AliRun.h"     
53 #include "AliMUON.h"
54 #include "AliMUONChamberTrigger.h"
55 #include "AliMUONConstants.h"
56 #include "AliMUONHit.h"
57 #include "AliMUONMerger.h"      
58 #include "AliMUONPadHit.h"
59 #include "AliMUONRawCluster.h"
60 #include "AliMUONTransientDigit.h"
61 #include "AliMUONTriggerCircuit.h"
62 #include "AliMUONGeometryBuilder.h"
63 #include "AliMUONVGeometryBuilder.h"    
64 #include "AliMUONDigitizerv2.h"
65 #include "AliMUONSDigitizerv1.h"
66 #include "AliMUONRawData.h"
67
68 // Defaults parameters for Z positions of chambers
69 // taken from values for "stations" in AliMUON::AliMUON
70 //     const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
71 // and from array "dstation" in AliMUONv1::CreateGeometry
72 //          Float_t dstation[5]={20., 20., 20, 20., 20.};
73 //     for tracking chambers,
74 //          according to (Z1 = zch - dstation) and  (Z2 = zch + dstation)
75 //          for the first and second chambers in the station, respectively,
76 // and from "DTPLANES" in AliMUONv1::CreateGeometry
77 //           const Float_t DTPLANES = 15.;
78 //     for trigger chambers,
79 //          according to (Z1 = zch) and  (Z2 = zch + DTPLANES)
80 //          for the first and second chambers in the station, respectively
81
82 ClassImp(AliMUON)
83
84 //__________________________________________________________________
85 AliMUON::AliMUON()
86   : AliDetector(),
87     fNCh(0),
88     fNTrackingCh(0),
89     fMUONData(0),
90     fSplitLevel(0),
91     fChambers(0),
92     fTriggerCircuits(0),
93     fGeometryBuilder(0),
94     fAccCut(kFALSE),
95     fAccMin(0.),
96     fAccMax(0.),   
97     fMaxStepGas(0.),
98     fMaxStepAlu(0.),
99     fMaxDestepGas(0.),
100     fMaxDestepAlu(0.),
101     fMaxIterPad(0),
102     fCurIterPad(0),
103     fMerger(0)
104 {
105 // Default Constructor
106 //
107     fIshunt          = 0;
108 }
109
110 //__________________________________________________________________
111 AliMUON::AliMUON(const char *name, const char *title)
112   : AliDetector(name,title),
113     fNCh(AliMUONConstants::NCh()),
114     fNTrackingCh(AliMUONConstants::NTrackingCh()),
115     fMUONData(0),
116     fSplitLevel(0),
117     fChambers(0),
118     fTriggerCircuits(0),
119     fGeometryBuilder(0),
120     fAccCut(kFALSE),
121     fAccMin(0.),
122     fAccMax(0.),   
123     fMaxStepGas(0.1),
124     fMaxStepAlu(0.1),
125     fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200 
126     fMaxDestepAlu(-1), // in the calculation of the tracking parameters
127     fMaxIterPad(0),
128     fCurIterPad(0),
129     fMerger(0)
130 {
131
132   fIshunt =  0;
133
134   SetMarkerColor(kRed);//
135 //
136 // Creating List of Chambers
137     Int_t ch;
138     fChambers = new TObjArray(AliMUONConstants::NCh());
139
140     // Loop over stations
141     for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
142       // Loop over 2 chambers in the station
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);
154         //chamber->SetGid(0);
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 
164     }     // Station st (0...)
165     
166     // cp new design of AliMUONTriggerDecision
167     fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
168     for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
169       fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);          
170     }
171     
172     // Geometry builder
173     fGeometryBuilder = new AliMUONGeometryBuilder(this);
174 }
175
176 //____________________________________________________________________
177 AliMUON::AliMUON(const AliMUON& rMUON)
178  : AliDetector(rMUON)
179 {
180 // Protected copy constructor
181
182   Fatal("AliMUONMergerModule", "Not implemented.");
183 }
184
185 //____________________________________________________________________
186 AliMUON::~AliMUON()
187 {
188 // Destructor
189   if(fDebug) printf("%s: Calling AliMUON destructor !!!\n",ClassName());
190   fIshunt  = 0;
191   if (fMerger) delete fMerger;
192
193   if (fChambers){
194     fChambers->Delete();
195     delete fChambers;
196   }
197   if (fTriggerCircuits){
198     fTriggerCircuits->Delete();
199     delete fTriggerCircuits;
200   }
201   delete fMUONData;
202   delete fGeometryBuilder;
203 }
204
205 //________________________________________________________________________
206 AliMUON& AliMUON::operator = (const AliMUON& rhs)
207 {
208 // Protected assignement operator
209
210   if (this == &rhs) return *this;
211
212   Fatal("operator=", "Not implemented.");
213     
214   return *this;  
215 }
216
217 //_____________________________________________________________________________
218 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
219 {
220 // Adds the geometry builder to the list
221 // ---
222
223   fGeometryBuilder->AddBuilder(geomBuilder);
224 }
225
226 //____________________________________________________________________
227 void AliMUON::BuildGeometry()
228 {
229 // Geometry for event display
230
231    for (Int_t i=0; i<7; i++) {
232      for (Int_t j=0; j<2; j++) {
233        Int_t id=2*i+j+1;
234        this->Chamber(id-1).SegmentationModel(1)->Draw("eventdisplay");
235      }
236    }
237 }
238
239 //__________________________________________________________________
240 void  AliMUON::SetTreeAddress()
241 {
242   GetMUONData()->SetLoader(fLoader); 
243   //  GetMUONData()->MakeBranch("D,S,RC");
244   //  GetMUONData()->SetTreeAddress("H,D,S,RC");
245   GetMUONData()->SetTreeAddress("H");
246   if (fHits !=  GetMUONData()->Hits())  {
247     if ( gAlice->GetMCApp() )
248       if ( gAlice->GetMCApp()->GetHitLists() ) {
249         fHits = GetMUONData()->Hits();
250         gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
251       }  
252   }
253   fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector    
254 }
255
256 //____________________________________________________________________
257 void AliMUON::SetPadSize(Int_t id, Int_t isec, Float_t p1, Float_t p2)
258 {
259 // Set the pad size for chamber id and cathode isec
260     Int_t i=2*(id-1);
261     ((AliMUONChamber*) fChambers->At(i))  ->SetPadSize(isec,p1,p2);
262     ((AliMUONChamber*) fChambers->At(i+1))->SetPadSize(isec,p1,p2);
263 }
264
265 //___________________________________________
266 void 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"
270     for (Int_t ch = 0; ch < AliMUONConstants::NCh(); ch++)
271         ((AliMUONChamber*) fChambers->At(ch))->SetZ(Z[ch]);
272     return;
273 }
274 //_________________________________________________________________
275 void AliMUON::SetChambersZToDefault()
276 {
277   // Set Z values for all chambers (tracking and trigger)
278   // to default values
279   SetChambersZ(AliMUONConstants::DefaultChamberZ());
280   return;
281 }
282 //_________________________________________________________________
283 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
284 {
285 // Set the inverse charge slope for chamber id
286     Int_t i=2*(id-1);    //PH    ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
287     //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
288     ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
289     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
290 }
291 //__________________________________________________________________
292 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
293 {
294 // Set sigma of charge spread for chamber id
295     Int_t i=2*(id-1);
296     ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
297     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
298 }
299 //___________________________________________________________________
300 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
301 {
302 // Set integration limits for charge spread
303     Int_t i=2*(id-1);
304     ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
305     ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
306 }
307
308 //__________________________________________________________________
309 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
310 {
311 // Set maximum number for ADCcounts (saturation)
312     Int_t i=2*(id-1);
313     ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
314     ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
315 }
316
317 //__________________________________________________________________
318 void AliMUON::SetMaxStepGas(Float_t p1)
319 {
320 // Set stepsize in gas
321   fMaxStepGas=p1;
322 }
323 //__________________________________________________________________
324 void AliMUON::SetMaxStepAlu(Float_t p1)
325 {
326 // Set step size in Alu
327     fMaxStepAlu=p1;
328 }
329 //__________________________________________________________________
330 void AliMUON::SetMaxDestepGas(Float_t p1)
331 {
332 // Set maximum step size in Gas
333     fMaxDestepGas=p1;
334 }
335 //__________________________________________________________________
336 void AliMUON::SetMaxDestepAlu(Float_t p1)
337 {
338 // Set maximum step size in Alu
339   fMaxDestepAlu=p1;
340 }
341
342 //___________________________________________________________________
343 void AliMUON::SetAcceptance(Bool_t acc, Float_t angmin, Float_t angmax)
344 {
345 // Set acceptance cuts 
346   fAccCut=acc;
347   fAccMin=angmin*TMath::Pi()/180;
348   fAccMax=angmax*TMath::Pi()/180;
349   Int_t ch;
350   if (acc) {
351     for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
352       // Loop over 2 chambers in the station
353       for (Int_t stCH = 0; stCH < 2; stCH++) {
354         ch = 2 * st + stCH;
355         //         Set chamber inner and outer radius according to acceptance cuts
356         Chamber(ch).SetRInner(TMath::Abs(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMin)));
357         Chamber(ch).SetROuter(TMath::Abs(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMax)));
358       } // chamber loop
359     } // station loop
360   }
361 }
362
363 //____________________________________________________________________
364 Float_t  AliMUON::GetMaxStepGas() const
365 {
366 // Return stepsize in gas
367   
368   return fMaxStepGas;
369 }  
370
371 //____________________________________________________________________
372 Float_t  AliMUON::GetMaxStepAlu() const
373 {
374 // Return step size in Alu
375   
376   return fMaxStepAlu;
377 }
378   
379 //____________________________________________________________________
380 Float_t  AliMUON::GetMaxDestepGas() const
381 {
382 // Return maximum step size in Gas
383   
384   return fMaxDestepGas;
385 }
386   
387 //____________________________________________________________________
388 Float_t  AliMUON::GetMaxDestepAlu() const
389 {
390 // Return maximum step size in Gas
391   
392   return fMaxDestepAlu;
393 }
394
395 //____________________________________________________________________
396 void   AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliSegmentation *segmentation)
397 {
398 // Set the segmentation for chamber id cathode isec
399     ((AliMUONChamber*) fChambers->At(id))->SetSegmentationModel(isec, segmentation);
400
401 }
402 //____________________________________________________________________
403 void   AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
404 {
405 // Set the response for chamber id
406     ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
407 }
408 //____________________________________________________________________
409 void   AliMUON::SetNsec(Int_t id, Int_t nsec)
410 {
411 // Set number of segmented cathods for chamber id
412     ((AliMUONChamber*) fChambers->At(id))->SetNsec(nsec);
413 }
414 //____________________________________________________________________
415 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
416 {
417   return new AliMUONDigitizerv2(manager);
418 }
419 //_____________________________________________________________________
420 void AliMUON::SDigits2Digits()
421 {
422
423 // write TreeD here 
424
425     if (!fMerger) {
426       if (gAlice->GetDebug()>0) {
427         cerr<<"AliMUON::SDigits2Digits: create default AliMUONMerger "<<endl;
428         cerr<<" no merging, just digitization of 1 event will be done"<<endl;
429       }
430       fMerger = new AliMUONMerger();
431     }
432     fMerger->Init();
433     fMerger->Digitise();
434     char hname[30];
435     //    sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
436     fLoader->TreeD()->Write(hname,TObject::kOverwrite);
437     fLoader->TreeD()->Reset();
438 }
439
440 //_____________________________________________________________________
441 void AliMUON::Hits2SDigits()
442 {
443   // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
444   AliRunLoader* runLoader = fLoader->GetRunLoader();
445   AliRunDigitizer   * manager = new AliRunDigitizer(1,1);
446   manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
447   AliMUONDigitizer * dMUON   = new AliMUONSDigitizerv1(manager);
448   fLoader->LoadHits("READ");
449   for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
450     runLoader->GetEvent(iEvent);
451     dMUON->Exec("");
452   }
453   fLoader->UnloadHits();
454 }
455 //_____________________________________________________________________
456 void AliMUON::Digits2Raw()
457 {
458   // convert digits of the current event to raw data
459   AliMUONRawData* rawData;
460
461   rawData = new AliMUONRawData(fLoader);
462   if (!rawData->WriteRawData()) Info("MUON","pb writting raw data");
463   delete rawData;
464   return;
465 }
466 //_______________________________________________________________________
467 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
468
469 //builds standard getter (AliLoader type)
470 //if detector wants to use castomized getter, it must overload this method
471
472  if (GetDebug())
473    Info("MakeLoader",
474         "Creating standard getter for detector %s. Top folder is %s.",
475          GetName(),topfoldername);
476  fLoader   = new AliLoader(GetName(),topfoldername);
477  fMUONData = new AliMUONData(fLoader,GetName(),GetName()); 
478  fMUONData->SetSplitLevel(fSplitLevel);
479  return fLoader;
480 }
481 //_______________________________________________________________________
482 AliMUONPadHit* AliMUON::FirstPad(AliMUONHit*  hit, TClonesArray *clusters) 
483 {
484 // to be removed
485     // Initialise the pad iterator
486     // Return the address of the first padhit for hit
487     TClonesArray *theClusters = clusters;
488     Int_t nclust = theClusters->GetEntriesFast();
489     if (nclust && hit->PHlast() > 0) {
490         fMaxIterPad=hit->PHlast();
491         fCurIterPad=hit->PHfirst();
492         return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
493     } else {
494         return 0;
495     }
496 }
497 //_______________________________________________________________________
498 AliMUONPadHit* AliMUON::NextPad(TClonesArray *clusters) 
499 {
500   // To be removed
501 // Get next pad (in iterator) 
502 //
503     fCurIterPad++;
504     if (fCurIterPad <= fMaxIterPad) {
505         return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
506     } else {
507         return 0;
508     }
509 }
510 //_______________________________________________________________________
511
512 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
513 {
514 //
515 //  Return rawcluster (icluster) for chamber ichamber and cathode icathod
516 //  Obsolete ??
517     TClonesArray *muonRawCluster  = GetMUONData()->RawClusters(ichamber);
518     ResetRawClusters();
519     TTree *treeR = fLoader->TreeR();
520     Int_t nent=(Int_t)treeR->GetEntries();
521     treeR->GetEvent(nent-2+icathod-1);
522     //treeR->GetEvent(icathod);
523     //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
524
525     AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
526     //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
527     
528     return  mRaw;
529 }
530 //________________________________________________________________________
531 void   AliMUON::SetMerger(AliMUONMerger* merger)
532 {
533 // Set pointer to merger 
534     fMerger = merger;
535 }
536 //________________________________________________________________________
537 AliMUONMerger*  AliMUON::Merger()
538 {
539 // Return pointer to merger
540     return fMerger;
541 }
542 /* PH Commented out waiting for correct implementation
543 //________________________________________________________________________
544 void AliMUON::RemapTrackHitIDs(Int_t* map)
545 {
546 // Remaps the track numbers in the hits arrays, so that they correspond
547 // to the entry indices in the Kine tree.
548 // The correspondance is not direct. To get the real index into the Kine tree
549 // compute the particle index as follows:
550 //
551 //   num_primaries = AliStack::GetNprimary();
552 //   num_tracks = AliStack::GetNtracks();
553 //   track = AliMUONHit::Track()
554 //
555 //   if (track < num_primaries)
556 //       particleindex = track + num_tracks - num_primaries;
557 //   else
558 //       particleindex = track - num_primaries;
559         
560         // Remap the track numbers based on the specified map.
561         AliMUONData* data = GetMUONData();
562         TClonesArray* hits = data->Hits();
563         for (Int_t i = 0; i < hits->GetEntriesFast(); i++)
564         {
565                 AliMUONHit* hit = static_cast<AliMUONHit*>( hits->At(i) );
566                 hit->SetTrack( map[hit->Track()] );
567         };
568 };
569 */