]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONSimpleClusterServer.cxx
Propagate the modification of the unit of the calibrated charge (fC) to the QA histograms
[u/mrichter/AliRoot.git] / MUON / AliMUONSimpleClusterServer.cxx
index 401b57ed6b25a1f5c02f6a8c5574f9f18803df27..943a0f5140ebeeae273edc78a11829166dfbb904 100644 (file)
@@ -28,6 +28,7 @@
 #include "AliMUONVClusterFinder.h"
 #include "AliMUONVClusterStore.h"
 #include "AliMUONVDigitStore.h"
+#include "AliMUONRecoParam.h"
 #include "AliMpArea.h"
 #include "AliMpDEIterator.h"
 #include "AliMpDEManager.h"
@@ -56,19 +57,20 @@ namespace
   TString AsString(const AliMpArea& area)
   {
     return Form("(X,Y)=(%7.3f,%7.3f) (DX,DY)=(%7.3f,%7.3f)",
-                area.Position().X(),
-                area.Position().Y(),
-                area.Dimensions().Y(),
-                area.Dimensions().Y());
+                area.GetPositionX(),
+                area.GetPositionY(),
+                area.GetDimensionX(),  /// TBCL was Y !!!
+                area.GetDimensionY());
   }
 }
 
 //_____________________________________________________________________________
 AliMUONSimpleClusterServer::AliMUONSimpleClusterServer(AliMUONVClusterFinder* clusterFinder,
                                                        const AliMUONGeometryTransformer& transformer)
-: AliMUONVClusterServer(), 
+: AliMUONVClusterServer(),
+  fDigitStore(0x0),
   fClusterFinder(clusterFinder),
-  fTransformer(transformer),
+  fkTransformer(transformer),
   fPads(),
   fTriggerTrackStore(0x0),
   fBypass(0x0)
@@ -76,8 +78,8 @@ AliMUONSimpleClusterServer::AliMUONSimpleClusterServer(AliMUONVClusterFinder* cl
     /// Ctor
     /// Note that we take ownership of the clusterFinder
     
-    fPads[0] = new AliMpExMap(true);
-    fPads[1] = new AliMpExMap(true);
+    fPads[0] = new AliMpExMap;
+    fPads[1] = new AliMpExMap;
     
 }
 
@@ -95,7 +97,8 @@ AliMUONSimpleClusterServer::~AliMUONSimpleClusterServer()
 Int_t 
 AliMUONSimpleClusterServer::Clusterize(Int_t chamberId,
                                        AliMUONVClusterStore& clusterStore,
-                                       const AliMpArea& area)
+                                       const AliMpArea& area,
+                                       const AliMUONRecoParam* recoParam)
 {
   /// Area is in absolute coordinate. If not valid, means clusterize all
   /// the chamber.
@@ -110,6 +113,11 @@ AliMUONSimpleClusterServer::Clusterize(Int_t chamberId,
     return fBypass->GenerateClusters(chamberId,clusterStore);
   }
   
+  if (!recoParam) {
+    AliError("Reconstruction parameters are missing: unable to clusterize");
+    return 0;
+  }
+  
   AliMpDEIterator it;
   
   it.First(chamberId);
@@ -143,12 +151,12 @@ AliMUONSimpleClusterServer::Clusterize(Int_t chamberId,
       
       if ( ok ) 
       {      
-        if ( fClusterFinder->NeedSegmentation() )
-        {
-          const AliMpVSegmentation* seg[2] = 
+       const AliMpVSegmentation* seg[2] = 
         { AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0),
           AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath1)
         };
+        if ( fClusterFinder->NeedSegmentation() )
+        {
           fClusterFinder->Prepare(detElemId,pads,deArea,seg);
         }
         else
@@ -167,7 +175,7 @@ AliMUONSimpleClusterServer::Clusterize(Int_t chamberId,
         {      
           // add new cluster to the store with information to build its ID
           // increment the number of clusters into the store
-          AliMUONVCluster* rawCluster = clusterStore.Add(AliMpDEManager::GetChamberId(detElemId), detElemId, fNCluster++);
+          AliMUONVCluster* rawCluster = clusterStore.Add(chamberId, detElemId, fNCluster++);
           
           ++nofAddedClusters;
           
@@ -190,15 +198,22 @@ AliMUONSimpleClusterServer::Clusterize(Int_t chamberId,
           rawCluster->SetChi2(cluster->Chi2());
           
           Double_t xg, yg, zg;
-          fTransformer.Local2Global(detElemId, 
+          fkTransformer.Local2Global(detElemId, 
                                     cluster->Position().X(), cluster->Position().Y(), 
                                     0, xg, yg, zg);
           rawCluster->SetXYZ(xg, yg, zg);
+          rawCluster->SetErrXY(recoParam->GetDefaultNonBendingReso(chamberId),recoParam->GetDefaultBendingReso(chamberId));
+          
+          // Set MC label
+          if (fDigitStore && fDigitStore->HasMCInformation()) 
+          {
+            rawCluster->SetMCLabel(FindMCLabel(*cluster, detElemId, seg));
+          }
           
-          AliDebug(1,Form("Adding RawCluster detElemId %4d mult %2d charge %e (xl,yl,zl)=(%e,%e,%e) (xg,yg,zg)=(%e,%e,%e)",
+          AliDebug(1,Form("Adding RawCluster detElemId %4d mult %2d charge %e (xl,yl,zl)=(%e,%e,%e) (xg,yg,zg)=(%e,%e,%e) label %d",
                           detElemId,rawCluster->GetNDigits(),rawCluster->GetCharge(),
                           cluster->Position().X(),cluster->Position().Y(),0.0,
-                          xg,yg,zg));
+                          xg,yg,zg,rawCluster->GetMCLabel()));
         }
       }
     }
@@ -206,7 +221,7 @@ AliMUONSimpleClusterServer::Clusterize(Int_t chamberId,
   }
   
   AliDebug(1,Form("chamberId = %2d NofClusters after = %d",chamberId,fNCluster));
-
+  
   return nofAddedClusters;
 }
 
@@ -222,11 +237,11 @@ AliMUONSimpleClusterServer::Global2Local(Int_t detElemId, const AliMpArea& globa
   
   Double_t zg = AliMUONConstants::DefaultChamberZ(AliMpDEManager::GetChamberId(detElemId));
   
-  fTransformer.Global2Local(detElemId,
-                             globalArea.Position().X(),globalArea.Position().Y(),zg,
+  fkTransformer.Global2Local(detElemId,
+                             globalArea.GetPositionX(),globalArea.GetPositionY(),zg,
                              xl,yl,zl);
   
-  localArea = AliMpArea(TVector2(xl,yl), globalArea.Dimensions());
+  localArea = AliMpArea(xl,yl, globalArea.GetDimensionX(), globalArea.GetDimensionY());
 }
 
 //_____________________________________________________________________________
@@ -241,7 +256,7 @@ AliMUONSimpleClusterServer::Overlap(Int_t detElemId,
   
   Bool_t overlap(kFALSE);
   
-  AliMpArea* globalDEArea = fTransformer.GetDEArea(detElemId);
+  AliMpArea* globalDEArea = fkTransformer.GetDEArea(detElemId);
   
   if (!globalDEArea) return kFALSE;
   
@@ -285,16 +300,18 @@ AliMUONSimpleClusterServer::UseTriggerTrackStore(AliMUONVTriggerTrackStore* trac
   /// Tells us to use trigger track store, and thus to bypass St45 clusters
   fTriggerTrackStore = trackStore; // not owner
   delete fBypass;
-  fBypass = new AliMUONTriggerTrackToTrackerClusters(fTransformer,fTriggerTrackStore);
+  fBypass = new AliMUONTriggerTrackToTrackerClusters(fkTransformer,fTriggerTrackStore);
   return kTRUE;
 }
 
 //_____________________________________________________________________________
 void 
-AliMUONSimpleClusterServer::UseDigits(TIter& next)
+AliMUONSimpleClusterServer::UseDigits(TIter& next, AliMUONVDigitStore* digitStore)
 {
   /// Convert digitStore into two arrays of AliMUONPads
-
+  
+  fDigitStore = digitStore;
+  
   fPads[0]->Clear();
   fPads[1]->Clear();
   
@@ -308,7 +325,7 @@ AliMUONSimpleClusterServer::UseDigits(TIter& next)
     Int_t detElemId = d->DetElemId();
     const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
       GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
-    AliMpPad pad = seg->PadByIndices(AliMpIntPair(ix,iy));
+    AliMpPad pad = seg->PadByIndices(ix,iy);
     
     TClonesArray* padArray = PadArray(detElemId,cathode);
     if (!padArray)
@@ -318,8 +335,8 @@ AliMUONSimpleClusterServer::UseDigits(TIter& next)
     }
     
     AliMUONPad mpad(detElemId,cathode,
-                    ix,iy,pad.Position().X(),pad.Position().Y(),
-                    pad.Dimensions().X(),pad.Dimensions().Y(),
+                    ix,iy,pad.GetPositionX(),pad.GetPositionY(),
+                    pad.GetDimensionX(),pad.GetDimensionY(),
                     d->Charge());
     if ( d->IsSaturated() ) mpad.SetSaturated(kTRUE);
     mpad.SetUniqueID(d->GetUniqueID());
@@ -327,6 +344,76 @@ AliMUONSimpleClusterServer::UseDigits(TIter& next)
   }
 }
 
+//_____________________________________________________________________________
+Int_t
+AliMUONSimpleClusterServer::FindMCLabel(const AliMUONCluster& cluster, Int_t detElemId, const AliMpVSegmentation* seg[2]) const
+{
+  /// Find the label of the most contributing MC track (-1 in case of failure)
+  /// The data member fDigitStore must be set
+  
+  // --- get the digit (if any) located at the cluster position on both cathods ---
+  Int_t nTracks[2] = {0, 0};
+  AliMUONVDigit* digit[2] = {0x0, 0x0};
+  for (Int_t iCath = 0; iCath < 2; iCath++) {
+    AliMpPad pad 
+      = seg[AliMp::GetCathodType(iCath)]->PadByPosition(cluster.Position().X(), cluster.Position().Y(),kFALSE);
+    if (pad.IsValid()) {
+      digit[iCath] = fDigitStore->FindObject(detElemId, pad.GetManuId(), pad.GetManuChannel(), iCath);
+      if (digit[iCath]) nTracks[iCath] = digit[iCath]->Ntracks();
+    }
+  }
+  
+  if (nTracks[0] + nTracks[1] == 0) return -1;
+  
+  // --- build the list of contributing tracks and of the associated charge ---
+  Int_t* trackId = new Int_t[nTracks[0] + nTracks[1]];
+  Float_t* trackCharge = new Float_t[nTracks[0] + nTracks[1]];
+  Int_t nTracksTot = 0;
+  
+  // fill with contributing tracks on first cathod
+  for (Int_t iTrack1 = 0; iTrack1 < nTracks[0]; iTrack1++) {
+    trackId[iTrack1] = digit[0]->Track(iTrack1);
+    trackCharge[iTrack1] = digit[0]->TrackCharge(iTrack1);
+  }
+  nTracksTot = nTracks[0];
+  
+  // complement with contributing tracks on second cathod
+  for (Int_t iTrack2 = 0; iTrack2 < nTracks[1]; iTrack2++) {
+    Int_t trackId2 = digit[1]->Track(iTrack2);
+    // check if track exist
+    Bool_t trackExist = kFALSE;
+    for (Int_t iTrack1 = 0; iTrack1 < nTracks[0]; iTrack1++) {
+      if (trackId2 == trackId[iTrack1]) {
+       // complement existing track
+       trackCharge[iTrack1] += digit[1]->TrackCharge(iTrack2);
+       trackExist = kTRUE;
+       break;
+      }
+    }
+    // add the new track
+    if (!trackExist) {
+      trackId[nTracksTot] = trackId2;
+      trackCharge[nTracksTot] = digit[1]->TrackCharge(iTrack2);
+      nTracksTot++;
+    }
+  }
+  
+  // --- Find the most contributing track ---
+  Int_t mainTrackId = -1;
+  Float_t maxCharge = 0.;
+  for (Int_t iTrack = 0; iTrack < nTracksTot; iTrack++) {
+    if (trackCharge[iTrack] > maxCharge) {
+      mainTrackId = trackId[iTrack];
+      maxCharge = trackCharge[iTrack];
+    }
+  }
+  
+  delete[] trackId;
+  delete[] trackCharge;
+  
+  return mainTrackId;
+}
+
 //_____________________________________________________________________________
 void 
 AliMUONSimpleClusterServer::Print(Option_t*) const