]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON.cxx
Obsolete material removed.
[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 #include "AliMUONRawData.h"
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
136   fIshunt =  0;
137
138   SetMarkerColor(kRed);//
139 //
140 // Creating List of Chambers
141     Int_t ch;
142     fChambers = new TObjArray(AliMUONConstants::NCh());
143     fGeometryBuilders = new TObjArray(AliMUONConstants::NCh());
144
145     // Loop over stations
146     for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
147       // Loop over 2 chambers in the station
148       for (Int_t stCH = 0; stCH < 2; stCH++) {
149         //
150         //    
151         //    Default Parameters for Muon Tracking Stations
152         ch = 2 * st + stCH;
153         if (ch < AliMUONConstants::NTrackingCh()) {
154           fChambers->AddAt(new AliMUONChamber(ch),ch);
155         } else {
156           fChambers->AddAt(new AliMUONChamberTrigger(ch),ch);
157         }
158         AliMUONChamber* chamber = (AliMUONChamber*) fChambers->At(ch);
159         //chamber->SetGid(0);
160         // Default values for Z of chambers
161         chamber->SetZ(AliMUONConstants::DefaultChamberZ(ch));
162         //
163         chamber->InitGeo(AliMUONConstants::DefaultChamberZ(ch));
164         //          Set chamber inner and outer radius to default
165         chamber->SetRInner(AliMUONConstants::Dmin(st)/2);
166         chamber->SetROuter(AliMUONConstants::Dmax(st)/2);
167         //
168       } // Chamber stCH (0, 1) in 
169     }     // Station st (0...)
170     
171     // cp new design of AliMUONTriggerDecision
172     fTriggerCircuits = new TObjArray(AliMUONConstants::NTriggerCircuit());
173     for (Int_t circ=0; circ<AliMUONConstants::NTriggerCircuit(); circ++) {
174       fTriggerCircuits->AddAt(new AliMUONTriggerCircuit(),circ);          
175     }
176 }
177
178 //____________________________________________________________________
179 AliMUON::AliMUON(const AliMUON& rMUON)
180  : AliDetector(rMUON)
181 {
182 // Protected copy constructor
183
184   Fatal("AliMUONMergerModule", "Not implemented.");
185 }
186
187 //____________________________________________________________________
188 AliMUON::~AliMUON()
189 {
190 // Destructor
191   if(fDebug) printf("%s: Calling AliMUON destructor !!!\n",ClassName());
192   fIshunt  = 0;
193   if (fMerger) delete fMerger;
194
195   if (fGeometryBuilders){
196     fGeometryBuilders->Delete();
197     delete fGeometryBuilders;
198   }
199   if (fChambers){
200     fChambers->Delete();
201     delete fChambers;
202   }
203   if (fTriggerCircuits){
204     fTriggerCircuits->Delete();
205     delete fTriggerCircuits;
206   }
207   delete fMUONData;
208 }
209
210 //________________________________________________________________________
211 AliMUON& AliMUON::operator = (const AliMUON& rhs)
212 {
213 // Protected assignement operator
214
215   if (this == &rhs) return *this;
216
217   Fatal("operator=", "Not implemented.");
218     
219   return *this;  
220 }
221
222 //_____________________________________________________________________________
223 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
224 {
225 // Adds the geometry builder to the list
226 // ---
227
228   fGeometryBuilders->Add(geomBuilder);
229 }
230
231 //____________________________________________________________________
232 void AliMUON::BuildGeometry()
233 {
234 // Geometry for event display
235
236    for (Int_t i=0; i<7; i++) {
237      for (Int_t j=0; j<2; j++) {
238        Int_t id=2*i+j+1;
239        this->Chamber(id-1).SegmentationModel(1)->Draw("eventdisplay");
240      }
241    }
242 }
243
244 //__________________________________________________________________
245 void  AliMUON::SetTreeAddress()
246 {
247   GetMUONData()->SetLoader(fLoader); 
248   //  GetMUONData()->MakeBranch("D,S,RC");
249   //  GetMUONData()->SetTreeAddress("H,D,S,RC");
250   GetMUONData()->SetTreeAddress("H");
251   if (fHits !=  GetMUONData()->Hits())  {
252     if ( gAlice->GetMCApp() )
253       if ( gAlice->GetMCApp()->GetHitLists() ) {
254         fHits = GetMUONData()->Hits();
255         gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
256       }  
257   }
258   fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector    
259 }
260
261 //____________________________________________________________________
262 void AliMUON::SetPadSize(Int_t id, Int_t isec, Float_t p1, Float_t p2)
263 {
264 // Set the pad size for chamber id and cathode isec
265     Int_t i=2*(id-1);
266     ((AliMUONChamber*) fChambers->At(i))  ->SetPadSize(isec,p1,p2);
267     ((AliMUONChamber*) fChambers->At(i+1))->SetPadSize(isec,p1,p2);
268 }
269
270 //___________________________________________
271 void AliMUON::SetChambersZ(const Float_t *Z)
272 {
273   // Set Z values for all chambers (tracking and trigger)
274   // from the array pointed to by "Z"
275     for (Int_t ch = 0; ch < AliMUONConstants::NCh(); ch++)
276         ((AliMUONChamber*) fChambers->At(ch))->SetZ(Z[ch]);
277     return;
278 }
279 //_________________________________________________________________
280 void AliMUON::SetChambersZToDefault()
281 {
282   // Set Z values for all chambers (tracking and trigger)
283   // to default values
284   SetChambersZ(AliMUONConstants::DefaultChamberZ());
285   return;
286 }
287 //_________________________________________________________________
288 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
289 {
290 // Set the inverse charge slope for chamber id
291     Int_t i=2*(id-1);    //PH    ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
292     //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
293     ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
294     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
295 }
296 //__________________________________________________________________
297 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
298 {
299 // Set sigma of charge spread for chamber id
300     Int_t i=2*(id-1);
301     ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
302     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
303 }
304 //___________________________________________________________________
305 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
306 {
307 // Set integration limits for charge spread
308     Int_t i=2*(id-1);
309     ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
310     ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
311 }
312
313 //__________________________________________________________________
314 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
315 {
316 // Set maximum number for ADCcounts (saturation)
317     Int_t i=2*(id-1);
318     ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
319     ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
320 }
321 //__________________________________________________________________
322 void AliMUON::SetMaxStepGas(Float_t p1)
323 {
324 // Set stepsize in gas
325   fMaxStepGas=p1;
326 }
327 //__________________________________________________________________
328 void AliMUON::SetMaxStepAlu(Float_t p1)
329 {
330 // Set step size in Alu
331     fMaxStepAlu=p1;
332 }
333 //__________________________________________________________________
334 void AliMUON::SetMaxDestepGas(Float_t p1)
335 {
336 // Set maximum step size in Gas
337     fMaxDestepGas=p1;
338 }
339 //__________________________________________________________________
340 void AliMUON::SetMaxDestepAlu(Float_t p1)
341 {
342 // Set maximum step size in Alu
343   fMaxDestepAlu=p1;
344 }
345 //___________________________________________________________________
346 void AliMUON::SetAcceptance(Bool_t acc, Float_t angmin, Float_t angmax)
347 {
348 // Set acceptance cuts 
349   fAccCut=acc;
350   fAccMin=angmin*TMath::Pi()/180;
351   fAccMax=angmax*TMath::Pi()/180;
352   Int_t ch;
353   if (acc) {
354     for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
355       // Loop over 2 chambers in the station
356       for (Int_t stCH = 0; stCH < 2; stCH++) {
357         ch = 2 * st + stCH;
358         //         Set chamber inner and outer radius according to acceptance cuts
359         Chamber(ch).SetRInner(TMath::Abs(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMin)));
360         Chamber(ch).SetROuter(TMath::Abs(AliMUONConstants::DefaultChamberZ(ch)*TMath::Tan(fAccMax)));
361       } // chamber loop
362     } // station loop
363   }
364 }
365
366 //____________________________________________________________________
367 Float_t  AliMUON::GetMaxStepGas() const
368 {
369 // Return stepsize in gas
370   
371   return fMaxStepGas;
372 }  
373
374 //____________________________________________________________________
375 Float_t  AliMUON::GetMaxStepAlu() const
376 {
377 // Return step size in Alu
378   
379   return fMaxStepAlu;
380 }
381   
382 //____________________________________________________________________
383 Float_t  AliMUON::GetMaxDestepGas() const
384 {
385 // Return maximum step size in Gas
386   
387   return fMaxDestepGas;
388 }
389   
390 //____________________________________________________________________
391 Float_t  AliMUON::GetMaxDestepAlu() const
392 {
393 // Return maximum step size in Gas
394   
395   return fMaxDestepAlu;
396 }
397 //____________________________________________________________________
398 void   AliMUON::SetSegmentationModel(Int_t id, Int_t isec, AliSegmentation *segmentation)
399 {
400 // Set the segmentation for chamber id cathode isec
401     ((AliMUONChamber*) fChambers->At(id))->SetSegmentationModel(isec, segmentation);
402
403 }
404 //____________________________________________________________________
405 void   AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
406 {
407 // Set the response for chamber id
408     ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
409 }
410 //____________________________________________________________________
411 void   AliMUON::SetNsec(Int_t id, Int_t nsec)
412 {
413 // Set number of segmented cathods for chamber id
414     ((AliMUONChamber*) fChambers->At(id))->SetNsec(nsec);
415 }
416 //____________________________________________________________________
417 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
418 {
419   return new AliMUONDigitizerv2(manager);
420 }
421 //_____________________________________________________________________
422 void AliMUON::SDigits2Digits()
423 {
424
425 // write TreeD here 
426
427     if (!fMerger) {
428       if (gAlice->GetDebug()>0) {
429         cerr<<"AliMUON::SDigits2Digits: create default AliMUONMerger "<<endl;
430         cerr<<" no merging, just digitization of 1 event will be done"<<endl;
431       }
432       fMerger = new AliMUONMerger();
433     }
434     fMerger->Init();
435     fMerger->Digitise();
436     char hname[30];
437     //    sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
438     fLoader->TreeD()->Write(hname,TObject::kOverwrite);
439     fLoader->TreeD()->Reset();
440 }
441
442 //_____________________________________________________________________
443 void AliMUON::Hits2SDigits()
444 {
445   // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
446   AliRunLoader* runLoader = fLoader->GetRunLoader();
447   AliRunDigitizer   * manager = new AliRunDigitizer(1,1);
448   manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
449   AliMUONDigitizer * dMUON   = new AliMUONSDigitizerv1(manager);
450   fLoader->LoadHits("READ");
451   for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
452     runLoader->GetEvent(iEvent);
453     dMUON->Exec("");
454   }
455   fLoader->UnloadHits();
456 }
457 //_____________________________________________________________________
458 void AliMUON::Digits2Raw()
459 {
460   // convert digits of the current event to raw data
461   AliMUONRawData* rawData;
462
463   rawData = new AliMUONRawData(fLoader);
464   if (!rawData->WriteRawData()) Info("MUON","pb writting raw data");
465   delete rawData;
466   return;
467 }
468 //_______________________________________________________________________
469 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
470
471 //builds standard getter (AliLoader type)
472 //if detector wants to use castomized getter, it must overload this method
473
474  if (GetDebug())
475    Info("MakeLoader",
476         "Creating standard getter for detector %s. Top folder is %s.",
477          GetName(),topfoldername);
478  fLoader   = new AliLoader(GetName(),topfoldername);
479  fMUONData = new AliMUONData(fLoader,GetName(),GetName()); 
480  fMUONData->SetSplitLevel(fSplitLevel);
481  return fLoader;
482 }
483 //_______________________________________________________________________
484 AliMUONPadHit* AliMUON::FirstPad(AliMUONHit*  hit, TClonesArray *clusters) 
485 {
486 // to be removed
487     // Initialise the pad iterator
488     // Return the address of the first padhit for hit
489     TClonesArray *theClusters = clusters;
490     Int_t nclust = theClusters->GetEntriesFast();
491     if (nclust && hit->PHlast() > 0) {
492         fMaxIterPad=hit->PHlast();
493         fCurIterPad=hit->PHfirst();
494         return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
495     } else {
496         return 0;
497     }
498 }
499 //_______________________________________________________________________
500 AliMUONPadHit* AliMUON::NextPad(TClonesArray *clusters) 
501 {
502   // To be removed
503 // Get next pad (in iterator) 
504 //
505     fCurIterPad++;
506     if (fCurIterPad <= fMaxIterPad) {
507         return (AliMUONPadHit*) clusters->UncheckedAt(fCurIterPad-1);
508     } else {
509         return 0;
510     }
511 }
512 //_______________________________________________________________________
513
514 AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
515 {
516 //
517 //  Return rawcluster (icluster) for chamber ichamber and cathode icathod
518 //  Obsolete ??
519     TClonesArray *muonRawCluster  = GetMUONData()->RawClusters(ichamber);
520     ResetRawClusters();
521     TTree *treeR = fLoader->TreeR();
522     Int_t nent=(Int_t)treeR->GetEntries();
523     treeR->GetEvent(nent-2+icathod-1);
524     //treeR->GetEvent(icathod);
525     //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
526
527     AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
528     //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
529     
530     return  mRaw;
531 }
532 //________________________________________________________________________
533 void   AliMUON::SetMerger(AliMUONMerger* merger)
534 {
535 // Set pointer to merger 
536     fMerger = merger;
537 }
538 //________________________________________________________________________
539 AliMUONMerger*  AliMUON::Merger()
540 {
541 // Return pointer to merger
542     return fMerger;
543 }
544 /* PH Commented out waiting for correct implementation
545 //________________________________________________________________________
546 void AliMUON::RemapTrackHitIDs(Int_t* map)
547 {
548 // Remaps the track numbers in the hits arrays, so that they correspond
549 // to the entry indices in the Kine tree.
550 // The correspondance is not direct. To get the real index into the Kine tree
551 // compute the particle index as follows:
552 //
553 //   num_primaries = AliStack::GetNprimary();
554 //   num_tracks = AliStack::GetNtracks();
555 //   track = AliMUONHit::Track()
556 //
557 //   if (track < num_primaries)
558 //       particleindex = track + num_tracks - num_primaries;
559 //   else
560 //       particleindex = track - num_primaries;
561         
562         // Remap the track numbers based on the specified map.
563         AliMUONData* data = GetMUONData();
564         TClonesArray* hits = data->Hits();
565         for (Int_t i = 0; i < hits->GetEntriesFast(); i++)
566         {
567                 AliMUONHit* hit = static_cast<AliMUONHit*>( hits->At(i) );
568                 hit->SetTrack( map[hit->Track()] );
569         };
570 };
571 */