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