]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONClusterReconstructor.cxx
Runloader is updated when moving to next file (quick fix).
[u/mrichter/AliRoot.git] / MUON / AliMUONClusterReconstructor.cxx
index f3224d6e205b8830baac6e7f445781c0cce5f4ba..7c6109228705f7aa1d5aee0ac9245c892ba08845 100644 (file)
 
 /* $Id$ */
 
-////////////////////////////////////
-//
-// MUON event reconstructor in ALICE
-//
-// This class contains as data:
-// * the parameters for the event reconstruction
-// * a pointer to the array of hits to be reconstructed (the event)
-// * a pointer to the array of segments made with these hits inside each station
-// * a pointer to the array of reconstructed tracks
-//
-// It contains as methods, among others:
-// * MakeEventToBeReconstructed to build the array of hits to be reconstructed
-// * MakeSegments to build the segments
-// * MakeTracks to build the tracks
-//
-////////////////////////////////////
-
-#include <Riostream.h> // for cout
-#include <stdlib.h> // for exit()
-
-#include <TTree.h>
-
-#include "AliMUON.h"
+// -----------------------------------
+// Class AliMUONClusterReconstructor
+// ----------------------------------
+// MUON cluster reconstructor for MUON
+// Should implement a virtual class ClusterFinder to choose between VS and AZ method
+
+#include <Riostream.h>
 #include "AliMUONClusterReconstructor.h"
+#include "AliRunLoader.h"
+#include "AliLoader.h"
+
 #include "AliMUONDigit.h"
 #include "AliMUONConstants.h"
 #include "AliMUONData.h"
 #include "AliMUONClusterFinderVS.h"
-#include "AliMUONClusterFinderAZ.h"
 #include "AliMUONClusterInput.h"
 #include "AliMUONRawCluster.h"
-#include "AliRun.h" // for gAlice
-#include "AliConfig.h"
-#include "AliRunLoader.h"
-#include "AliLoader.h"
-
-static const Int_t kDefaultPrintLevel = 0;
+#include "AliMUONVClusterFinder.h"
+#include "AliMUONCluster.h"
+#include "AliMpDEManager.h"
+#include "AliMpSegmentation.h"
+#include "AliMpCathodType.h"
+#include "AliMUONGeometryTransformer.h"
+#include "AliLog.h"
 
+/// \cond CLASSIMP
 ClassImp(AliMUONClusterReconstructor) // Class implementation in ROOT context
-
+/// \endcond
 //__________________________________________________________________________
-AliMUONClusterReconstructor::AliMUONClusterReconstructor(AliLoader* loader)
+AliMUONClusterReconstructor::AliMUONClusterReconstructor(AliMUONData* data,
+                                                         AliMUONVClusterFinder* clusterFinder,
+                                                         const AliMUONGeometryTransformer* transformer)
+: TObject(),
+  fClusterFinder(clusterFinder),
+  fMUONData(data),
+  fRecModel(new AliMUONClusterFinderVS()),
+  fDigitsCath0(new TClonesArray("AliMUONDigit",1000)),
+  fDigitsCath1(new TClonesArray("AliMUONDigit",1000)),
+  fTransformer(transformer)
 {
-  // Default Constructor
-  fDebug           = 0;
-  fNCh             = 0;
-  fNTrackingCh     = 0;
-  fChambers        = 0;
-  fMUONData        = 0;
-  fChambers = new TObjArray(AliMUONConstants::NCh());
+/// Standard Constructor
 
-  fPrintLevel = kDefaultPrintLevel;
+  fDigitsCath0->SetOwner(kTRUE); 
+  fDigitsCath1->SetOwner(kTRUE);
+  if (!transformer && clusterFinder)
+  {
+    AliFatal("I require a geometry transformer, otherwise I cannot compute "
+             "global coordinates of the clusters !");    
+  }
+}
 
-  // initialize loader's
-  fLoader = loader;
+//__________________________________________________________________________
+AliMUONClusterReconstructor::~AliMUONClusterReconstructor(void)
+{
+/// Destructor
 
-  // initialize container
-  fMUONData  = new AliMUONData(fLoader,"MUON","MUON");
+  delete fRecModel;
+  delete fDigitsCath0;
+  delete fDigitsCath1;
+}
 
-  // Loading AliRun master
-  AliRunLoader* runloader = fLoader->GetRunLoader();
-  if (runloader->GetAliRun() == 0x0) runloader->LoadgAlice();
-  gAlice = runloader->GetAliRun();
+//______________________________________________________________________________
+void
+AliMUONClusterReconstructor::ClusterizeOneDEV2(Int_t detElemId)
+{
+/// Clusterize one detection element, and let fMUONData know about
+/// the results.
 
-  // getting MUON
-  fMUON = (AliMUON*) gAlice->GetDetector("MUON");
+  AliDebug(1,Form("DE %d",detElemId));
+  const AliMpVSegmentation* seg[2] = 
+  { AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0),
+    AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath1)
+  };
+  
+  
+  TClonesArray* digits[2] = { fDigitsCath0, fDigitsCath1 };
+  
+  Bool_t ok = fClusterFinder->Prepare(seg,digits);
+  if ( !ok )
+  {
+    AliWarning(Form("No hit pad for DE %d ?",detElemId));
+  }
+  
+  AliMUONCluster* cluster;
+  
+  Int_t chamber = detElemId/100 - 1;
+  
+  while ( ( cluster = fClusterFinder->NextCluster() ) )
+  {
+//    StdoutToAliDebug(1,cout << "From AliMUONClusterReconstructor::ClusterizeOneDEV2 : cluster->Print():" << endl;
+//                     cluster->Print(););
+    
+    // Converts cluster objects into ones suitable for output
+    //
+    AliMUONRawCluster rawCluster;
+    
+    rawCluster.SetDetElemId(detElemId);
+    
+    for ( Int_t cathode = 0; cathode < 2; ++cathode )
+    {
+      rawCluster.SetMultiplicity(cathode,cluster->Multiplicity(cathode));
+      rawCluster.SetCharge(cathode,cluster->Charge()); // both cathode get the total cluster charge
+      Double_t xg, yg, zg;
+      
+      fTransformer->Local2Global(detElemId, 
+                                 cluster->Position().X(), cluster->Position().Y(), 
+                                 0, xg, yg, zg);
+      
+      if ( cathode == 0 )
+      {
+        AliDebug(1,Form("Adding RawCluster detElemId %4d mult %2d charge %e (xl,yl,zl)=(%e,%e,%e) (xg,yg,zg)=(%e,%e,%e)",
+                        detElemId,cluster->Multiplicity(),cluster->Charge(),
+                        cluster->Position().X(),cluster->Position().Y(),0.0,
+                        xg,yg,zg));
+      }
+      rawCluster.SetX(cathode,xg);
+      rawCluster.SetY(cathode,yg);
+      rawCluster.SetZ(cathode,zg);      
+    }
+    fMUONData->AddRawCluster(chamber,rawCluster);
+  }
+}
 
-  return; 
+//______________________________________________________________________________
+void
+AliMUONClusterReconstructor::ClusterizeOneDE(Int_t detElemId)
+{
+/// Clusterize one detection element, and let fMUONData know about
+/// the results.
+  
+  if ( fDigitsCath0->GetEntriesFast() || fDigitsCath1->GetEntriesFast() )
+  {
+    if ( fClusterFinder )
+    {
+      ClusterizeOneDEV2(detElemId);
+    }
+    else
+    {
+      Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
+      AliMUONClusterInput::Instance()->SetDigits(iChamber, detElemId,
+                                                 fDigitsCath0,fDigitsCath1);
+      AliDebug(3,Form("ClusterizeOneDE iChamber=%d DE=%d",iChamber,detElemId));
+//      StdoutToAliDebug(3,cout << "DigitsCath0=" << endl;
+//                       fDigitsCath0->Print();
+//                       cout << "DigitsCath1=" << endl;
+//                       fDigitsCath1->Print(););
+      fRecModel->FindRawClusters();
+      
+      // copy results into the output container
+      TClonesArray* tmp = fRecModel->GetRawClusters();
+      for (Int_t id = 0; id < tmp->GetEntriesFast(); ++id) 
+      {
+        AliMUONRawCluster* pClus = (AliMUONRawCluster*) tmp->At(id);
+        fMUONData->AddRawCluster(iChamber, *pClus);
+      }        
+    }
+    // Reset the arrays
+    fDigitsCath0->Clear("C");
+    fDigitsCath1->Clear("C");
+  }
 }
+
 //____________________________________________________________________
-void AliMUONClusterReconstructor::SetReconstructionModel(Int_t id, AliMUONClusterFinderVS *reconst)
+void AliMUONClusterReconstructor::Digits2Clusters(Int_t chBeg)
 {
-  // take infos chambers from AliMUON
-  AliMUONChamber* pCh = 0;
-  pCh = &(fMUON->Chamber(id));
-
-  fChambers->AddAt(pCh, id);
+/// Clusterize all the tracking chamber digits.
+///
+/// For each chamber, we loop *once* on that chamber digits, and store them
+/// in 2 temporary arrays (one pair of arrays per detection element, 
+/// one array per cathode). Once a pair of arrays is full (i.e. all the digits
+/// of that detection element have been stored), we clusterize this DE, and
+/// move to the next one.
+  
+  if (!fRecModel && !fClusterFinder)
+  {
+    AliWarning("No reco model defined. Nothing to do...");
+    return;
+  }
+  
+  Int_t iChamber(-1);
+  Int_t currentDE(-1);
+  
+  // Loop on chambers 
+  for ( iChamber = chBeg; iChamber < AliMUONConstants::NTrackingCh(); ++iChamber ) 
+  {
+    TClonesArray* muonDigits = fMUONData->Digits(iChamber); 
+    
+    Int_t ndig = muonDigits->GetEntriesFast();
+    if (!ndig) continue;
+    
+    muonDigits->Sort(); // the sort *must* be per DE (at least), otherwise
+                        // the following logic with currentDE will fail.
+    
+    currentDE = -1; // initialize the DE counter (that is used to track 
+                    // when we change of DE in the following loop over
+                    // all digits) to an invalid value.
 
-  // Set ClusterFinder for chamber id
-  ((AliMUONChamber*) fChambers->At(id))->SetReconstructionModel(reconst);
+    for ( Int_t k = 0; k < ndig; ++k ) 
+    {
+      AliMUONDigit* digit = (AliMUONDigit*) muonDigits->UncheckedAt(k);
+      if ( ! digit->Signal() > 0 ) continue; // skip void digits.
+      
+      if ( digit->DetElemId() != currentDE )
+      {
+        AliDebug(3,Form("Switching DE from %d to %d",currentDE,digit->DetElemId()));
+        // we get to a new DE, so clusterize the previous one before
+        // moving on.
+        ClusterizeOneDE(currentDE);
+        currentDE = digit->DetElemId();
+      }
+      
+      // Add the digit to the array with the right cathode number.
+      if (digit->Cathode() == 0)
+      {
+        new((*fDigitsCath0)[fDigitsCath0->GetLast()+1]) AliMUONDigit(*digit);
+      }
+      else 
+      {
+        new((*fDigitsCath1)[fDigitsCath1->GetLast()+1]) AliMUONDigit(*digit);
+      }
+    } // end of loop on chamber digits
+    
+    // As the above logic is based on detecting a change in DE number,
+    // the last DE of each chamber has not been clusterized, so we do 
+    // it here.
+    ClusterizeOneDE(currentDE);
+  } // end of loop over chambers
 }
+
 //_______________________________________________________________________
-AliMUONClusterReconstructor::AliMUONClusterReconstructor (const AliMUONClusterReconstructor& Reconstructor):TObject(Reconstructor)
-{
-  // Dummy copy constructor
-}
+void 
+AliMUONClusterReconstructor::SetRecoModel(AliMUONClusterFinderVS* rec)
+{ 
+/// Set reconstruction model
 
-AliMUONClusterReconstructor & AliMUONClusterReconstructor::operator=(const AliMUONClusterReconstructor& /*Reconstructor*/)
-{
-  // Dummy assignment operator
-    return *this;
-}
+  delete fRecModel; 
+  fRecModel = rec;
+} 
 
-//__________________________________________________________________________
-AliMUONClusterReconstructor::~AliMUONClusterReconstructor(void)
-{
-  if (fChambers){
-    fChambers->Clear(); // Sets pointers to 0 sinche it is not the owner
-    delete fChambers;
-  } 
-  if (fMUONData)
-    delete fMUONData;
-
-  return;
-}
-//____________________________________________________________________
-void AliMUONClusterReconstructor::Digits2Clusters()
+//_______________________________________________________________________
+void AliMUONClusterReconstructor::Trigger2Trigger() 
 {
-//
-//  Perform cluster finding
-//
-    TClonesArray *dig1, *dig2;
-    Int_t ndig, k;
-    dig1 = new TClonesArray("AliMUONDigit",1000);
-    dig2 = new TClonesArray("AliMUONDigit",1000);
-    AliMUONDigit *digit;
-// Loop on chambers and on cathode planes
-//
-//    fMUONData->ResetRawClusters();        
-    TClonesArray * muonDigits;
-
-    for (Int_t ich = 0; ich < 10; ich++) {
-       AliMUONChamber* iChamber = (AliMUONChamber*) fChambers->At(ich);
-       AliMUONClusterFinderVS* rec = iChamber->ReconstructionModel();
-       //AliMUONClusterFinderAZ* rec = (AliMUONClusterFinderAZ*)iChamber->ReconstructionModel();
-
-       fMUONData->ResetDigits();
-       fMUONData->GetCathode(0);
-       //TClonesArray *
-       muonDigits = fMUONData->Digits(ich); 
-       ndig=muonDigits->GetEntriesFast();
-       if(fDebug)
-         printf("1 Found %d digits in %p chamber %d\n", ndig, muonDigits,ich);
-       TClonesArray &lhits1 = *dig1;
-       Int_t n = 0;
-       for (k = 0; k < ndig; k++) {
-           digit = (AliMUONDigit*) muonDigits->UncheckedAt(k);
-           if (rec->TestTrack(digit->Track(0)))
-             new(lhits1[n++]) AliMUONDigit(*digit);
-       }
-       fMUONData->ResetDigits();
-       fMUONData->GetCathode(1);
-       muonDigits =  fMUONData->Digits(ich);  
-       ndig=muonDigits->GetEntriesFast();
-       if(fDebug)
-         printf("\n 2 Found %d digits in %p %d", ndig, muonDigits, ich);
-       TClonesArray &lhits2 = *dig2;
-       n=0;
-       
-       for (k=0; k<ndig; k++) {
-           digit= (AliMUONDigit*) muonDigits->UncheckedAt(k);
-           if (rec->TestTrack(digit->Track(0)))
-             new(lhits2[n++]) AliMUONDigit(*digit);
-       }
-
-       if (rec) {       
-           AliMUONClusterInput::Instance()->SetDigits(ich, dig1, dig2);
-           rec->FindRawClusters();
-       }
-       // copy into the container
-       TClonesArray* tmp = rec->GetRawClusters();
-       for (Int_t id = 0; id < tmp->GetEntriesFast(); id++) {
-         AliMUONRawCluster* pClus = (AliMUONRawCluster*) tmp->At(id);
-         fMUONData->AddRawCluster(ich, *pClus);
-       }
-       dig1->Delete();
-       dig2->Delete();
-    } // for ich
-    delete dig1;
-    delete dig2;
+/// Copy trigger from TreeD to TreeR
+
+  fMUONData->SetTreeAddress("GLT");
+  fMUONData->GetTriggerD();
 }