]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUON.cxx
Update of HP decoders:
[u/mrichter/AliRoot.git] / MUON / AliMUON.cxx
index 817eb656fa571514e2094d6cf4fe268cce7ba309..a6765b48194c4be02f5d4dd1318eb2362a9d2004 100644 (file)
 
 /* $Id$ */
 
-// ------------------
+//-----------------------------------------------------------------------------
 // Class AliMUON
 // ------------------
 // AliDetector class for MUON subsystem 
 // providing simulation data management 
+//-----------------------------------------------------------------------------
 
 #include "Riostream.h"
 
 #include "AliLoader.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 "AliMUONTransientDigit.h"
 #include "AliMUONGeometry.h"
 #include "AliMUONGeometryTransformer.h"
 #include "AliMUONGeometryBuilder.h"
 #include "AliMUONCommonGeometryBuilder.h"
 #include "AliMUONVGeometryBuilder.h"   
-#include "AliMUONGeometrySegmentation.h"
-#include "AliMUONDigitizerv2.h"
-#include "AliMUONSDigitizerv1.h"
 #include "AliMUONRawWriter.h"
-#include "AliMUONSegmentation.h"
 #include "AliLog.h"
 
 #include "AliMUONSDigitizerV2.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.};
@@ -101,11 +101,9 @@ AliMUON::AliMUON()
   : AliDetector(),
     fNCh(0),
     fNTrackingCh(0),
-    fMUONData(0),
     fSplitLevel(0),
     fChambers(0),
     fGeometryBuilder(0),
-    fSegmentation(0),
     fAccCut(kFALSE),
     fAccMin(0.),
     fAccMax(0.),   
@@ -119,11 +117,12 @@ AliMUON::AliMUON()
     fTriggerResponseV1(kFALSE),
     fTriggerCoinc44(0),
     fTriggerEffCells(0),
-    fSDigitizerType(""),
-    fDigitizerType(""),
+    fDigitizerWithNoise(1),
+    fIsTailEffect(kTRUE),
     fRawWriter(0x0),
-    fDigitMaker(0x0)
-
+    fDigitMaker(0x0),
+    fHitStore(0x0),
+  fDigitStoreConcreteClassName()
 {
 /// Default Constructor
     
@@ -132,17 +131,13 @@ AliMUON::AliMUON()
 }
 
 //__________________________________________________________________
-AliMUON::AliMUON(const char *name, const char *title,
-                 const char* sDigitizerClassName,
-                 const char* digitizerClassName)
-  : AliDetector(name,title),
+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.),   
@@ -156,17 +151,19 @@ AliMUON::AliMUON(const char *name, const char *title,
     fTriggerResponseV1(kFALSE),
     fTriggerCoinc44(0),
     fTriggerEffCells(0),
-    fSDigitizerType(sDigitizerClassName),
-    fDigitizerType(digitizerClassName),
+    fDigitizerWithNoise(1),
+    fIsTailEffect(kTRUE),
     fRawWriter(0x0),
-    fDigitMaker(new AliMUONDigitMaker(kFALSE)) 
+    fDigitMaker(new AliMUONDigitMaker),
+    fHitStore(0x0),
+  fDigitStoreConcreteClassName("AliMUONDigitStoreV2S")
 {
 /// Standard constructor  
   
   AliDebug(1,Form("ctor this=%p",this));
   fIshunt =  0;
 
-  SetMarkerColor(kRed);//
+  //PH SetMarkerColor(kRed);//
     
   // Geometry builder
   fGeometryBuilder = new AliMUONGeometryBuilder(this);
@@ -188,7 +185,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
@@ -213,18 +211,11 @@ 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;
 }
 
 //_____________________________________________________________________________
@@ -273,22 +264,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()); 
       }  
+    }
   }
-  fHits = GetMUONData()->Hits(); // Added by Ivana to use the methods FisrtHit, NextHit of AliDetector    
+
+  TTree* treeH = fLoader->TreeH();
+  
+  if (!treeH)
+  {
+    AliFatal("No TreeH");
+  }
+  
+  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();
 }
 
 //_________________________________________________________________
@@ -407,7 +444,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);
@@ -416,33 +453,9 @@ void   AliMUON::SetResponseModel(Int_t id, AliMUONResponse *response)
 //____________________________________________________________________
 AliDigitizer* AliMUON::CreateDigitizer(AliRunDigitizer* manager) const
 {
-/// FIXME: the selection of the class should be done through a factory
-/// mechanism. (see also Hits2SDigits()).
+/// Return digitizer
   
-  AliDebug(1, Form("Digitizer used : %s",fDigitizerType.Data()));
-  
-  if ( fDigitizerType == "digitizer:default" ) // NewDigitizerNewTrigger
-  {
-      return new AliMUONDigitizerV3(manager,kTRUE);
-  } 
-  else if ( fDigitizerType == "digitizer:NewDigitizerWONoiseNewTrigger" ) 
-  {                                     
-      return new AliMUONDigitizerV3(manager,kFALSE);
-  }
-  else
-  {
-    AliFatal(Form("Unknown digitizer type : %s",fDigitizerType.Data()));
-  }
-  return 0x0;
-}
-
-//_____________________________________________________________________
-TString
-AliMUON::SDigitizerType() const
-{
-/// Return digitizer type
-
-  return fSDigitizerType;
+  return new AliMUONDigitizerV3(manager, fDigitizerWithNoise);
 }
 
 //_____________________________________________________________________
@@ -459,43 +472,10 @@ void AliMUON::SDigits2Digits()
 //_____________________________________________________________________
 void AliMUON::Hits2SDigits()
 {
-/// FIXME: the selection of the sdigitizer should be done through a
-/// factory mechanism.
+/// Perform Hits2Digits using SDigitizerV2
   
-  AliDebug(1, Form("SDigitizer used : %s",fSDigitizerType.Data()));
-
-  if ( fSDigitizerType == "sdigitizer:default" )
-  {
-    // Adaption of AliMUONSDigitizerv1 to be excuted by the AliSimulation framework
-    AliRunLoader* runLoader = fLoader->GetRunLoader();
-    AliRunDigitizer   * manager = new AliRunDigitizer(1,1);
-    manager->SetInputStream(0,runLoader->GetFileName(),AliConfig::GetDefaultEventFolderName());
-    AliMUONDigitizer * dMUON   = new AliMUONSDigitizerv1(manager);
-    fLoader->LoadHits("READ");
-    for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
-      runLoader->GetEvent(iEvent);
-      dMUON->Exec("");
-    }
-    fLoader->UnloadHits();
-  }
-  else if ( fSDigitizerType == "sdigitizer:AliMUONSDigitizerV2" )
-  {
-    TTask* sdigitizer = new AliMUONSDigitizerV2;
-    sdigitizer->ExecuteTask();
-  }
-  else
-  {
-    AliFatal(Form("Unknown sdigitizer classname : %s",fSDigitizerType.Data()));
-  }
-}
-
-//_____________________________________________________________________
-TString
-AliMUON::DigitizerType() const
-{
-/// Return digitizer type
-
-  return fDigitizerType;
+  AliMUONSDigitizerV2 sdigitizer;
+  sdigitizer.ExecuteTask();
 }
 
 //_____________________________________________________________________
@@ -503,19 +483,46 @@ 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();
 }
 
 //_____________________________________________________________________
@@ -524,20 +531,23 @@ 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;
-
 }
 
 //_______________________________________________________________________
@@ -549,33 +559,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
@@ -623,3 +609,65 @@ Bool_t  AliMUON::GetTriggerEffCells() const
     
 }  
 
+//____________________________________________________________________
+Int_t  AliMUON::GetDigitizerWithNoise() const
+{
+///
+/// Returns fDigitizerWithNoise
+///  
+    return fDigitizerWithNoise;
+    
+}  
+
+//____________________________________________________________________
+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);
+}
+