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