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