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