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