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