]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUON.cxx
Coding rule violations fixed.
[u/mrichter/AliRoot.git] / MUON / AliMUON.cxx
index e40232118eef7060134b0dc8de466957fabfdcf4..3cf30d3cd866acbb6d6484ce3f66925168cb4cbc 100644 (file)
 
 /* $Id$ */
 
-// ------------------
+//-----------------------------------------------------------------------------
 // Class AliMUON
 // ------------------
 // AliDetector class for MUON subsystem 
 // providing simulation data management 
+//-----------------------------------------------------------------------------
 
 #include "Riostream.h"
 
 
 //#include "AliHeader.h"
 #include "AliLoader.h"
+#include "AliCDBManager.h"
 #include "AliRunDigitizer.h"
 #include "AliMC.h"
-#include "AliRun.h"    
+#include "AliRun.h"
+#include "AliRawDataHeaderSim.h"
 #include "AliMUON.h"
 #include "AliMUONChamberTrigger.h"
 #include "AliMUONConstants.h"
 #include "AliMUONHit.h"        
-#include "AliMUONRawCluster.h"
 #include "AliMUONGeometry.h"
 #include "AliMUONGeometryTransformer.h"
 #include "AliMUONGeometryBuilder.h"
 #include "AliMUONCommonGeometryBuilder.h"
 #include "AliMUONVGeometryBuilder.h"   
-#include "AliMUONGeometrySegmentation.h"
 #include "AliMUONRawWriter.h"
-#include "AliMUONSegmentation.h"
 #include "AliLog.h"
 
 #include "AliMUONSDigitizerV2.h"
 #include "AliMUONDigitizerV3.h"
 #include "AliMUONDigitMaker.h"
+#include "AliMUONCalibrationData.h"
 
 #include "AliMUONSt1GeometryBuilderV2.h"
 #include "AliMUONSt2GeometryBuilderV2.h"
 #include "AliMUONSlatGeometryBuilder.h"
 #include "AliMUONTriggerGeometryBuilder.h"
 
+#include "AliMUONDigitStoreV1.h"
+#include "AliMUONVTriggerStore.h"
+#include "AliMUONHitStoreV1.h"
+
 // Defaults parameters for Z positions of chambers
 // taken from values for "stations" in AliMUON::AliMUON
 //     const Float_t zch[7]={528, 690., 975., 1249., 1449., 1610, 1710.};
@@ -98,11 +103,9 @@ AliMUON::AliMUON()
   : AliDetector(),
     fNCh(0),
     fNTrackingCh(0),
-    fMUONData(0),
     fSplitLevel(0),
     fChambers(0),
     fGeometryBuilder(0),
-    fSegmentation(0),
     fAccCut(kFALSE),
     fAccMin(0.),
     fAccMax(0.),   
@@ -116,10 +119,13 @@ AliMUON::AliMUON()
     fTriggerResponseV1(kFALSE),
     fTriggerCoinc44(0),
     fTriggerEffCells(0),
-    fDigitizerWithNoise(kTRUE),
+    fDigitizerWithNoise(1),
+    fIsTailEffect(kTRUE),
     fRawWriter(0x0),
-    fDigitMaker(0x0)
-
+    fDigitMaker(0x0),
+    fHitStore(0x0),
+    fDigitStoreConcreteClassName(),
+    fCalibrationData(0x0)
 {
 /// Default Constructor
     
@@ -132,11 +138,9 @@ AliMUON::AliMUON(const char *name, const char* title)
   : AliDetector(name, title),
     fNCh(AliMUONConstants::NCh()),
     fNTrackingCh(AliMUONConstants::NTrackingCh()),
-    fMUONData(0),
     fSplitLevel(0),
     fChambers(0),
     fGeometryBuilder(0),
-    fSegmentation(0),
     fAccCut(kFALSE),
     fAccMin(0.),
     fAccMax(0.),   
@@ -150,15 +154,20 @@ AliMUON::AliMUON(const char *name, const char* title)
     fTriggerResponseV1(kFALSE),
     fTriggerCoinc44(0),
     fTriggerEffCells(0),
-    fDigitizerWithNoise(kTRUE),
+    fDigitizerWithNoise(1),
+    fIsTailEffect(kTRUE),
     fRawWriter(0x0),
-    fDigitMaker(new AliMUONDigitMaker(kFALSE)) 
+    fDigitMaker(new AliMUONDigitMaker),
+    fHitStore(0x0),
+    fDigitStoreConcreteClassName("AliMUONDigitStoreV2S"),
+    fCalibrationData()
+
 {
-/// Standard constructor  
+  /// Standard constructor  
   
   AliDebug(1,Form("ctor this=%p",this));
   fIshunt =  0;
-
+  
   //PH SetMarkerColor(kRed);//
     
   // Geometry builder
@@ -167,11 +176,11 @@ AliMUON::AliMUON(const char *name, const char* title)
   // Common geometry definitions
   fGeometryBuilder
     ->AddBuilder(new AliMUONCommonGeometryBuilder(this));
-
+  
   // By default, add also all the needed geometry builders.
   // If you want to change this from outside, please use ResetGeometryBuilder
   // method, followed by AddGeometryBuilder ones.
-
+  
   AddGeometryBuilder(new AliMUONSt1GeometryBuilderV2(this));
   AddGeometryBuilder(new AliMUONSt2GeometryBuilderV2(this));
   AddGeometryBuilder(new AliMUONSlatGeometryBuilder(this));
@@ -181,7 +190,8 @@ AliMUON::AliMUON(const char *name, const char* title)
   // Creating List of Chambers
     Int_t ch;
     fChambers = new TObjArray(AliMUONConstants::NCh());
-
+    fChambers->SetOwner(kTRUE);
+    
     // Loop over stations
     for (Int_t st = 0; st < AliMUONConstants::NCh() / 2; st++) {
       // Loop over 2 chambers in the station
@@ -197,7 +207,10 @@ AliMUON::AliMUON(const char *name, const char* title)
        }
       } // Chamber stCH (0, 1) in 
     }     // Station st (0...)
-
+  
+  Int_t runnumber = AliCDBManager::Instance()->GetRun();
+  
+  fCalibrationData = new AliMUONCalibrationData(runnumber);
 }
 
 //____________________________________________________________________
@@ -206,18 +219,12 @@ AliMUON::~AliMUON()
 /// Destructor
 
   AliDebug(1,Form("dtor this=%p",this));
-  fIshunt  = 0;
-
-  if (fChambers){
-    fChambers->Delete();
-    delete fChambers;
-  }
-  
-  delete fMUONData;
+  delete fChambers;
   delete fGeometryBuilder;
-  delete fSegmentation;
   delete fRawWriter;
   delete fDigitMaker;
+  delete fHitStore;
+  delete fCalibrationData;
 }
 
 //_____________________________________________________________________________
@@ -266,22 +273,68 @@ const AliMUONGeometryTransformer*  AliMUON::GetGeometryTransformer() const
 }   
 
 //__________________________________________________________________
-void  AliMUON::SetTreeAddress()
+void 
+AliMUON::MakeBranch(Option_t* opt)
 {
-/// Set Hits tree address
-
-  GetMUONData()->SetLoader(fLoader); 
-  //  GetMUONData()->MakeBranch("D,S,RC");
-  //  GetMUONData()->SetTreeAddress("H,D,S,RC");
-  GetMUONData()->SetTreeAddress("H");
-  if (fHits !=  GetMUONData()->Hits())  {
+  /// Create branche(s) to hold MUON hits
+  AliDebug(1,"");
+  
+  TString sopt(opt);
+  if ( sopt != "H" ) return;
+    
+  if (!fHitStore)
+  {
+    fHitStore = new AliMUONHitStoreV1;
     if ( gAlice->GetMCApp() )
-      if ( gAlice->GetMCApp()->GetHitLists() ) {
-       fHits = GetMUONData()->Hits();
-       gAlice->GetMCApp()->AddHitList(fHits); // For purifyKine, only necessary when Hit list is created in AliMUONData
+    {
+      if ( gAlice->GetMCApp()->GetHitLists() ) 
+      {
+        // AliStack::PurifyKine needs to be able to loop on our hits
+        // to remap the track numbers.
+        gAlice->GetMCApp()->AddHitList(fHitStore->Collection()); 
       }  
+    }
+  }
+
+  TTree* treeH = fLoader->TreeH();
+  
+  if (!treeH)
+  {
+    AliFatal("No TreeH");
   }
-  fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector    
+  
+  fHitStore->Connect(*treeH);
+}
+
+//__________________________________________________________________
+void  
+AliMUON::SetTreeAddress()
+{
+  /// Set Hits tree address  
+//  if ( gAlice->GetMCApp() && fHitStore )
+//  {
+//    TList* l = gAlice->GetMCApp()->GetHitLists();
+//    if ( l )
+//    {
+//      TObject* o = l->First();
+//      if (o!=fHitStore->HitCollection())
+//      {
+//        AliError(Form("Something is strange hitcollection=%x",fHitStore->HitCollection()));
+//        l->Print();        
+//      }
+//    }  
+//  }  
+}
+
+//_________________________________________________________________
+void
+AliMUON::ResetHits()
+{
+  /// Reset hits
+  
+  AliDebug(1,"");
+  if (fHitStore) fHitStore->Clear();
 }
 
 //_________________________________________________________________
@@ -400,7 +453,7 @@ Float_t  AliMUON::GetMaxDestepAlu() const
 }   
 
 //____________________________________________________________________
-void   AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
+void   AliMUON::SetResponseModel(Int_t id, const AliMUONResponse& response)
 {
 /// Set the response for chamber id
     ((AliMUONChamber*) fChambers->At(id))->SetResponseModel(response);
@@ -411,7 +464,9 @@ AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
 {
 /// Return digitizer
   
-  return new AliMUONDigitizerV3(manager, fDigitizerWithNoise);
+  AliMUONDigitizerV3* digitizer = new AliMUONDigitizerV3(manager, fDigitizerWithNoise);
+  digitizer->SetCalibrationData(fCalibrationData);
+  return digitizer;
 }
 
 //_____________________________________________________________________
@@ -430,8 +485,8 @@ void AliMUON::Hits2SDigits()
 {
 /// Perform Hits2Digits using SDigitizerV2
   
-  TTask* sdigitizer = new AliMUONSDigitizerV2;
-  sdigitizer->ExecuteTask();
+  AliMUONSDigitizerV2 sdigitizer;
+  sdigitizer.ExecuteTask();
 }
 
 //_____________________________________________________________________
@@ -439,41 +494,70 @@ void AliMUON::Digits2Raw()
 {
 /// Convert digits of the current event to raw data
 
+  AliRawDataHeaderSim header;
+
   if (!fRawWriter)
   {
-    fRawWriter = new AliMUONRawWriter(fMUONData);
+    fRawWriter = new AliMUONRawWriter;
+    AliDebug(1,Form("Creating %s",fRawWriter->ClassName()));
     if (fTriggerScalerEvent == kTRUE) 
     {
       fRawWriter->SetScalersNumbers();
     }
   }
   
-  if (!fRawWriter->Digits2Raw()) 
+  fLoader->LoadDigits("READ");
+  
+  TTree* treeD = fLoader->TreeD();
+  
+  if (!treeD)
+  {
+    AliError("Could not get TreeD");
+    return;
+  }
+  
+  AliMUONVTriggerStore*  triggerStore = AliMUONVTriggerStore::Create(*treeD);
+  AliMUONVDigitStore* digitStore = AliMUONVDigitStore::Create(*treeD);
+
+  triggerStore->Connect(*treeD,kFALSE);
+  digitStore->Connect(*treeD,kFALSE);
+  
+  treeD->GetEvent(0);
+  
+  fRawWriter->SetHeader(header);
+  if (!fRawWriter->Digits2Raw(digitStore,triggerStore))
   {
     AliError("pb writting raw data");
   }
+  
+  delete triggerStore;
+  delete digitStore;
+  
+  fLoader->UnloadDigits();
 }
 
 //_____________________________________________________________________
 Bool_t AliMUON::Raw2SDigits(AliRawReader* rawReader)
 {
 /// Convert  raw data to SDigit
-/// Only for tracking for the moment (ChF) 
 
-  //fLoader->LoadDigits("READ");
+  fLoader->LoadDigits("READ");
   if (!fLoader->TreeS()) fLoader->MakeSDigitsContainer();
 
-  fMUONData->MakeBranch("S");
-  fMUONData->SetTreeAddress("S");
-  fDigitMaker->Raw2Digits(rawReader);
-  fMUONData->Fill("S");
+  TTree* treeS = fLoader->TreeS();
+  
+  AliMUONVDigitStore* sDigitStore = new AliMUONDigitStoreV1;
+  sDigitStore->Connect(*treeS);
+  
+  fDigitMaker->Raw2Digits(rawReader,sDigitStore,0x0);
 
   fLoader->WriteSDigits("OVERWRITE");
-  fMUONData->ResetSDigits();
+
   fLoader->UnloadSDigits();
 
+  delete sDigitStore;
+  
   return kTRUE;
-
 }
 
 //_______________________________________________________________________
@@ -485,33 +569,9 @@ AliLoader* AliMUON::MakeLoader(const char* topfoldername)
  AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
          GetName(),topfoldername));
  fLoader   = new AliLoader(GetName(),topfoldername);
- fMUONData = new AliMUONData(fLoader,GetName(),GetName()); 
- fMUONData->SetSplitLevel(fSplitLevel);
-
- fDigitMaker->SetMUONData(fMUONData);
 
  return fLoader;
 }
-//_______________________________________________________________________
-
-AliMUONRawCluster *AliMUON::RawCluster(Int_t ichamber, Int_t icathod, Int_t icluster)
-{
-/// Return rawcluster (icluster) for chamber ichamber and cathode icathod
-/// Obsolete ??
-
-    TClonesArray *muonRawCluster  = GetMUONData()->RawClusters(ichamber);
-    ResetRawClusters();
-    TTree *treeR = fLoader->TreeR();
-    Int_t nent=(Int_t)treeR->GetEntries();
-    treeR->GetEvent(nent-2+icathod-1);
-    //treeR->GetEvent(icathod);
-    //Int_t nrawcl = (Int_t)muonRawCluster->GetEntriesFast();
-
-    AliMUONRawCluster * mRaw = (AliMUONRawCluster*)muonRawCluster->UncheckedAt(icluster);
-    //printf("RawCluster _ nent nrawcl icluster mRaw %d %d %d%p\n",nent,nrawcl,icluster,mRaw);
-    
-    return  mRaw;
-}
 
 //________________________________________________________________________
 void
@@ -560,7 +620,7 @@ Bool_t  AliMUON::GetTriggerEffCells() const
 }  
 
 //____________________________________________________________________
-Bool_t  AliMUON::GetDigitizerWithNoise() const
+Int_t  AliMUON::GetDigitizerWithNoise() const
 {
 ///
 /// Returns fDigitizerWithNoise
@@ -569,3 +629,55 @@ Bool_t  AliMUON::GetDigitizerWithNoise() const
     
 }  
 
+//____________________________________________________________________
+Bool_t AliMUON::UsingFastTrackerDecoder() const
+{
+/// Checks to see if we are using the fast decoder for tracker DDL streams.
+
+  if ( ! fDigitMaker ) {
+    AliError("Digit maker is not instantiated.");
+    return kFALSE;
+  }
+  
+  return fDigitMaker->UsingFastTrackerDecoder();
+}
+
+//____________________________________________________________________
+Bool_t AliMUON::UsingFastTriggerDecoder() const
+{
+/// Checks to see if we are using the fast decoder for trigger DDL streams.
+
+  if ( ! fDigitMaker ) {
+    AliError("Digit maker is not instantiated.");
+    return kFALSE;
+  }
+  
+  return fDigitMaker->UsingFastTriggerDecoder();
+}
+
+//____________________________________________________________________
+void AliMUON::SetFastTrackerDecoder(Bool_t useFastDecoder)
+{
+/// Set fast raw data decoder 
+
+  if ( ! fDigitMaker ) {
+    AliError("Digit maker is not instantiated.");
+    return;
+  }
+
+  fDigitMaker->SetFastTrackerDecoder(useFastDecoder);
+}
+
+//____________________________________________________________________
+void AliMUON::SetFastTriggerDecoder(Bool_t useFastDecoder)
+{
+/// Set fast raw data decoder 
+
+  if ( ! fDigitMaker ) {
+    AliError("Digit maker is not instantiated.");
+    return;
+  }
+
+  fDigitMaker->SetFastTriggerDecoder(useFastDecoder);
+}
+