]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON.cxx
In AliMUON:
[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 // Class AliMUON
20 // ------------------
21 // AliDetector class for MUON subsystem 
22 // providing simulation data management 
23 //-----------------------------------------------------------------------------
24
25 #include "AliMUON.h"
26
27 #include "AliMUONSDigitizerV2.h"
28 #include "AliMUONDigitizerV3.h"
29 #include "AliMUONDigitMaker.h"
30 #include "AliMUONCalibrationData.h"
31
32 #include "AliMUONDigitStoreV1.h"
33 #include "AliMUONVTriggerStore.h"
34 #include "AliMUONHitStoreV1.h"
35
36 #include "AliMUONChamberTrigger.h"
37 #include "AliMUONConstants.h"
38 #include "AliMUONGeometry.h"
39 #include "AliMUONGeometryTransformer.h"
40 #include "AliMUONGeometryBuilder.h"
41 #include "AliMUONVGeometryBuilder.h"    
42 #include "AliMUONCommonGeometryBuilder.h"
43 #include "AliMUONSt1GeometryBuilderV2.h"
44 #include "AliMUONSt2GeometryBuilderV2.h"
45 #include "AliMUONSlatGeometryBuilder.h"
46 #include "AliMUONTriggerGeometryBuilder.h"
47
48 #include "AliMUONRawWriter.h"
49
50 #include "AliLoader.h"
51 #include "AliCDBManager.h"
52 #include "AliRunDigitizer.h"
53 #include "AliMC.h"
54 #include "AliRun.h"
55 #include "AliRawDataHeaderSim.h"
56 #include "AliLog.h"
57
58 #include <TObjArray.h>
59
60 // Defaults parameters for Z positions of chambers
61 // taken from values for "stations" in AliMUON::AliMUON
62 //     const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
63 // and from array "dstation" in AliMUONv1::CreateGeometry
64 //          Float_t dstation[5]={20., 20., 20, 20., 20.};
65 //     for tracking chambers,
66 //          according to (Z1 = zch - dstation) and  (Z2 = zch + dstation)
67 //          for the first and second chambers in the station, respectively,
68 // and from "DTPLANES" in AliMUONv1::CreateGeometry
69 //           const Float_t DTPLANES = 15.;
70 //     for trigger chambers,
71 //          according to (Z1 = zch) and  (Z2 = zch + DTPLANES)
72 //          for the first and second chambers in the station, respectively
73
74 /// \cond CLASSIMP
75 ClassImp(AliMUON)  
76 /// \endcond
77
78 //__________________________________________________________________
79 AliMUON::AliMUON()
80   : AliDetector(),
81     fNCh(0),
82     fNTrackingCh(0),
83     fSplitLevel(0),
84     fChambers(0),
85     fGeometryBuilder(0),
86     fAccCut(kFALSE),
87     fAccMin(0.),
88     fAccMax(0.),   
89     fMaxStepGas(0.),
90     fMaxStepAlu(0.),
91     fMaxDestepGas(0.),
92     fMaxDestepAlu(0.),
93     fMaxIterPad(0),
94     fCurIterPad(0),
95     fIsMaxStep(kTRUE),
96     fTriggerScalerEvent(kFALSE),
97     fTriggerResponseV1(kFALSE),
98     fTriggerCoinc44(0),
99     fTriggerEffCells(0),
100     fDigitizerWithNoise(1),
101     fDigitizerNSigmas(4.0),
102     fIsTailEffect(kTRUE),
103     fRawWriter(0x0),
104     fDigitMaker(0x0),
105     fHitStore(0x0),
106     fDigitStoreConcreteClassName(),
107     fCalibrationData(0x0)
108 {
109 /// Default Constructor
110     
111     AliDebug(1,Form("default (empty) ctor this=%p",this));
112     fIshunt          = 0;
113 }
114
115 //__________________________________________________________________
116 AliMUON::AliMUON(const char *name, const char* title)
117   : AliDetector(name, title),
118     fNCh(AliMUONConstants::NCh()),
119     fNTrackingCh(AliMUONConstants::NTrackingCh()),
120     fSplitLevel(0),
121     fChambers(0),
122     fGeometryBuilder(0),
123     fAccCut(kFALSE),
124     fAccMin(0.),
125     fAccMax(0.),   
126     fMaxStepGas(0.1),
127     fMaxStepAlu(0.1),
128     fMaxDestepGas(-1), // Negatives values are ignored by geant3 CONS200 
129     fMaxDestepAlu(-1), // in the calculation of the tracking parameters
130     fMaxIterPad(0),
131     fCurIterPad(0),
132     fIsMaxStep(kTRUE),
133     fTriggerScalerEvent(kFALSE),
134     fTriggerResponseV1(kFALSE),
135     fTriggerCoinc44(0),
136     fTriggerEffCells(0),
137     fDigitizerWithNoise(1),
138     fDigitizerNSigmas(4.0),
139     fIsTailEffect(kTRUE),
140     fRawWriter(0x0),
141     fDigitMaker(new AliMUONDigitMaker),
142     fHitStore(0x0),
143     fDigitStoreConcreteClassName("AliMUONDigitStoreV2S"),
144     fCalibrationData()
145 {
146   /// Standard constructor  
147   
148   AliDebug(1,Form("ctor this=%p",this));
149   fIshunt =  0;
150   
151   //PH SetMarkerColor(kRed);//
152     
153   // Geometry builder
154   fGeometryBuilder = new AliMUONGeometryBuilder(this);
155   
156   // Common geometry definitions
157   fGeometryBuilder
158     ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
159   
160   // By default, add also all the needed geometry builders.
161   // If you want to change this from outside, please use ResetGeometryBuilder
162   // method, followed by AddGeometryBuilder ones.
163   
164   AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
165   AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
166   AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
167   AddGeometryBuilder(new AliMUONTriggerGeometryBuilder(this));
168   
169   //
170   // Creating List of Chambers
171     Int_t ch;
172     fChambers = new TObjArray(AliMUONConstants::NCh());
173     fChambers->SetOwner(kTRUE);
174     
175     // Loop over stations
176     for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
177       // Loop over 2 chambers in the station
178       for (Int_t stCH = 0; stCH < 2; stCH++) {
179         //
180         //    
181         //    Default Parameters for Muon Tracking Stations
182         ch = 2 * st + stCH;
183         if (ch < AliMUONConstants::NTrackingCh()) {
184           fChambers->AddAt(new AliMUONChamber(ch),ch);
185         } else {
186           fChambers->AddAt(new AliMUONChamberTrigger(ch, GetGeometryTransformer()),ch);
187         }
188       } // Chamber stCH (0, 1) in 
189     }     // Station st (0...)
190   
191   Int_t runnumber = AliCDBManager::Instance()->GetRun();
192   
193   fCalibrationData = new AliMUONCalibrationData(runnumber);
194 }
195
196 //____________________________________________________________________
197 AliMUON::~AliMUON()
198 {
199 /// Destructor
200
201   AliDebug(1,Form("dtor this=%p",this));
202   delete fChambers;
203   delete fGeometryBuilder;
204   delete fRawWriter;
205   delete fDigitMaker;
206   delete fHitStore;
207   delete fCalibrationData;
208 }
209
210 //_____________________________________________________________________________
211 void AliMUON::AddGeometryBuilder(AliMUONVGeometryBuilder* geomBuilder)
212 {
213 /// Add the geometry builder to the list
214
215   fGeometryBuilder->AddBuilder(geomBuilder);
216 }
217
218 //____________________________________________________________________
219 const AliMUONGeometry*  AliMUON::GetGeometry() const
220 {
221 /// Return geometry parametrisation
222
223   if ( !fGeometryBuilder) {
224     AliWarningStream() << "GeometryBuilder not defined." << std::endl;
225     return 0;
226   }
227   
228   return fGeometryBuilder->GetGeometry();
229 }   
230
231 //____________________________________________________________________
232 const AliMUONGeometryTransformer*  AliMUON::GetGeometryTransformer() const
233 {
234 /// Return geometry parametrisation
235
236   const AliMUONGeometry* kGeometry = GetGeometry();
237   
238   if ( !kGeometry) return 0;
239
240   return kGeometry->GetTransformer();
241 }   
242
243 //__________________________________________________________________
244 void 
245 AliMUON::MakeBranch(Option_t* opt)
246 {
247   /// Create branche(s) to hold MUON hits
248   AliDebug(1,"");
249   
250   TString sopt(opt);
251   if ( sopt != "H" ) return;
252     
253   if (!fHitStore)
254   {
255     fHitStore = new AliMUONHitStoreV1;
256     if ( gAlice->GetMCApp() )
257     {
258       if ( gAlice->GetMCApp()->GetHitLists() ) 
259       {
260         // AliStack::PurifyKine needs to be able to loop on our hits
261         // to remap the track numbers.
262         gAlice->GetMCApp()->AddHitList(fHitStore->Collection()); 
263       }  
264     }
265   }
266
267   TTree* treeH = fLoader->TreeH();
268   
269   if (!treeH)
270   {
271     AliFatal("No TreeH");
272   }
273   
274   fHitStore->Connect(*treeH);
275 }
276
277 //__________________________________________________________________
278 void  
279 AliMUON::SetTreeAddress()
280 {
281   /// Set Hits tree address  
282  
283 //  if ( gAlice->GetMCApp() && fHitStore )
284 //  {
285 //    TList* l = gAlice->GetMCApp()->GetHitLists();
286 //    if ( l )
287 //    {
288 //      TObject* o = l->First();
289 //      if (o!=fHitStore->HitCollection())
290 //      {
291 //        AliError(Form("Something is strange hitcollection=%x",fHitStore->HitCollection()));
292 //        l->Print();        
293 //      }
294 //    }  
295 //  }  
296 }
297
298 //_________________________________________________________________
299 void
300 AliMUON::ResetHits()
301 {
302   /// Reset hits
303   
304   AliDebug(1,"");
305   if (fHitStore) fHitStore->Clear();
306 }
307
308 //_________________________________________________________________
309 void AliMUON::SetChargeSlope(Int_t id, Float_t p1)
310 {
311 /// Set the inverse charge slope for chamber id
312
313     Int_t i=2*(id-1);    //PH    ((AliMUONChamber*) (*fChambers)[i])->SetSigmaIntegration(p1);
314     //PH    ((AliMUONChamber*) (*fChambers)[i+1])->SetSigmaIntegration(p1);
315     ((AliMUONChamber*) fChambers->At(i))->SetChargeSlope(p1);
316     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSlope(p1);
317 }
318 //__________________________________________________________________
319 void AliMUON::SetChargeSpread(Int_t id, Float_t p1, Float_t p2)
320 {
321 /// Set sigma of charge spread for chamber id
322
323     Int_t i=2*(id-1);
324     ((AliMUONChamber*) fChambers->At(i))->SetChargeSpread(p1,p2);
325     ((AliMUONChamber*) fChambers->At(i+1))->SetChargeSpread(p1,p2);
326 }
327 //___________________________________________________________________
328 void AliMUON::SetSigmaIntegration(Int_t id, Float_t p1)
329 {
330 /// Set integration limits for charge spread
331     Int_t i=2*(id-1);
332     ((AliMUONChamber*) fChambers->At(i))->SetSigmaIntegration(p1);
333     ((AliMUONChamber*) fChambers->At(i+1))->SetSigmaIntegration(p1);
334 }
335
336 //__________________________________________________________________
337 void AliMUON::SetMaxAdc(Int_t id, Int_t p1)
338 {
339 /// Set maximum number for ADCcounts (saturation)
340
341     Int_t i=2*(id-1);
342     ((AliMUONChamber*) fChambers->At(i))->SetMaxAdc(p1);
343     ((AliMUONChamber*) fChambers->At(i+1))->SetMaxAdc(p1);
344 }
345
346 //__________________________________________________________________
347 void AliMUON::SetMaxStepGas(Float_t p1)
348 {
349 /// Set stepsize in gas
350
351   fMaxStepGas=p1;
352 }
353 //__________________________________________________________________
354 void AliMUON::SetMaxStepAlu(Float_t p1)
355 {
356 /// Set step size in Alu
357
358     fMaxStepAlu=p1;
359 }
360 //__________________________________________________________________
361 void AliMUON::SetMaxDestepGas(Float_t p1)
362 {
363 /// Set maximum step size in Gas
364
365     fMaxDestepGas=p1;
366 }
367 //__________________________________________________________________
368 void AliMUON::SetMaxDestepAlu(Float_t p1)
369 {
370 /// Set maximum step size in Alu
371
372   fMaxDestepAlu=p1;
373 }
374
375 //____________________________________________________________________
376 Float_t  AliMUON::GetMaxStepGas() const
377 {
378 /// Return stepsize in gas
379   
380   return fMaxStepGas;
381 }  
382
383 //____________________________________________________________________
384 Float_t  AliMUON::GetMaxStepAlu() const
385 {
386 /// Return step size in Alu
387   
388   return fMaxStepAlu;
389 }
390   
391 //____________________________________________________________________
392 Float_t  AliMUON::GetMaxDestepGas() const
393 {
394 /// Return maximum step size in Gas
395   
396   return fMaxDestepGas;
397 }
398   
399 //____________________________________________________________________
400 Float_t  AliMUON::GetMaxDestepAlu() const
401 {
402 /// Return maximum step size in Gas
403   
404   return fMaxDestepAlu;
405 }
406
407 //____________________________________________________________________
408  void  AliMUON::SetAlign(Bool_t align)
409 {
410 /// Set option for alignement to geometry builder
411  
412    fGeometryBuilder->SetAlign(align);
413 }   
414
415 //____________________________________________________________________
416  void  AliMUON::SetAlign(const TString& fileName, Bool_t align)
417 {
418 /// Set option for alignement to geometry builder
419  
420    fGeometryBuilder->SetAlign(fileName, align);
421 }   
422
423 //____________________________________________________________________
424 void   AliMUON::SetResponseModel(Int_t id, const AliMUONResponse& response)
425 {
426 /// Set the response for chamber id
427     ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
428 }
429
430 //____________________________________________________________________
431 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
432 {
433 /// Return digitizer
434   
435   AliMUONDigitizerV3* digitizer = new AliMUONDigitizerV3(manager, fDigitizerWithNoise);
436   AliMUONDigitizerV3::SetNSigmas(fDigitizerNSigmas);
437   digitizer->SetCalibrationData(fCalibrationData);
438   return digitizer;
439 }
440
441 //_____________________________________________________________________
442 void AliMUON::SDigits2Digits()
443 {
444 /// Write TreeD here only 
445
446     char hname[30];
447     //    sprintf(hname,"TreeD%d",fLoader->GetHeader()->GetEvent());
448     fLoader->TreeD()->Write(hname,TObject::kOverwrite);
449     fLoader->TreeD()->Reset();
450 }
451
452 //_____________________________________________________________________
453 void AliMUON::Hits2SDigits()
454 {
455 /// Perform Hits2Digits using SDigitizerV2
456   
457   AliMUONSDigitizerV2 sdigitizer;
458   sdigitizer.ExecuteTask();
459 }
460
461 //_____________________________________________________________________
462 void AliMUON::Digits2Raw()
463 {
464 /// Convert digits of the current event to raw data
465
466   AliRawDataHeaderSim header;
467
468   if (!fRawWriter)
469   {
470     fRawWriter = new AliMUONRawWriter;
471     AliDebug(1,Form("Creating %s",fRawWriter->ClassName()));
472     if (fTriggerScalerEvent == kTRUE) 
473     {
474       fRawWriter->SetScalersNumbers();
475     }
476   }
477   
478   fLoader->LoadDigits("READ");
479   
480   TTree* treeD = fLoader->TreeD();
481   
482   if (!treeD)
483   {
484     AliError("Could not get TreeD");
485     return;
486   }
487   
488   AliMUONVTriggerStore*  triggerStore = AliMUONVTriggerStore::Create(*treeD);
489   AliMUONVDigitStore* digitStore = AliMUONVDigitStore::Create(*treeD);
490
491   triggerStore->Connect(*treeD,kFALSE);
492   digitStore->Connect(*treeD,kFALSE);
493   
494   treeD->GetEvent(0);
495   
496   fRawWriter->SetHeader(header);
497   if (!fRawWriter->Digits2Raw(digitStore,triggerStore))
498   {
499     AliError("pb writting raw data");
500   }
501   
502   delete triggerStore;
503   delete digitStore;
504   
505   fLoader->UnloadDigits();
506 }
507
508 //_____________________________________________________________________
509 Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
510 {
511 /// Convert  raw data to SDigit
512
513   fLoader->LoadDigits("READ");
514   if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
515
516   TTree* treeS = fLoader->TreeS();
517   
518   AliMUONVDigitStore* sDigitStore = new AliMUONDigitStoreV1;
519   sDigitStore->Connect(*treeS);
520   
521   fDigitMaker->Raw2Digits(rawReader,sDigitStore,0x0);
522
523   fLoader->WriteSDigits("OVERWRITE");
524
525   fLoader->UnloadSDigits();
526
527   delete sDigitStore;
528   
529   return kTRUE;
530 }
531
532 //_______________________________________________________________________
533 AliLoader* AliMUON::MakeLoader(const char* topfoldername)
534
535 /// Build standard getter (AliLoader type);
536 /// if detector wants to use castomized getter, it must overload this method
537  
538  AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
539          GetName(),topfoldername));
540  fLoader   = new AliLoader(GetName(),topfoldername);
541
542  return fLoader;
543 }
544
545 //________________________________________________________________________
546 void
547 AliMUON::ResetGeometryBuilder()
548 {
549 /// Only to be used by "experts" wanting to change the geometry builders
550 /// to be used. 
551 /// As the ctor of AliMUON now defines a default geometrybuilder, this
552 /// ResetGeometryBuilder() must be called prior to call the 
553 /// AddGeometryBuilder()
554
555   delete fGeometryBuilder;
556   fGeometryBuilder = new AliMUONGeometryBuilder(this);
557   fGeometryBuilder
558     ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
559 }
560
561 //____________________________________________________________________
562 Bool_t  AliMUON::GetTriggerResponseV1() const
563 {
564 ///
565 /// Returns fTriggerResponseV1
566 ///  
567     return fTriggerResponseV1;
568     
569 }  
570
571 //____________________________________________________________________
572 Int_t  AliMUON::GetTriggerCoinc44() const
573 {
574 ///
575 /// Returns fTriggerCoinc44
576 ///  
577     return fTriggerCoinc44;
578     
579 }
580
581 //____________________________________________________________________
582 Bool_t  AliMUON::GetTriggerEffCells() const
583 {
584 ///
585 /// Returns fTriggerEffCells
586 ///  
587     return fTriggerEffCells;
588     
589 }  
590
591 //____________________________________________________________________
592 Int_t  AliMUON::GetDigitizerWithNoise() const
593 {
594 ///
595 /// Returns fDigitizerWithNoise
596 ///  
597     return fDigitizerWithNoise;
598     
599 }  
600
601