]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Task for adding MC labels (if rawdata are produced) to the ESD muon tracks using...
authormartinez <martinez@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 9 Sep 2009 17:16:55 +0000 (17:16 +0000)
committermartinez <martinez@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 9 Sep 2009 17:16:55 +0000 (17:16 +0000)
PWG3/PWG3muondepLinkDef.h
PWG3/libPWG3muondep.pkg
PWG3/muondep/AddTaskESDMCLabelAddition.C [new file with mode: 0644]
PWG3/muondep/AliAnalysisTaskESDMCLabelAddition.cxx [new file with mode: 0644]
PWG3/muondep/AliAnalysisTaskESDMCLabelAddition.h [new file with mode: 0644]

index a69c65503b9c33c2aa4b48be56d0405d7a064f4f..bc4dc3a03d3e82cd10b04d701a41040dae5d18d5 100644 (file)
@@ -7,6 +7,7 @@
 #pragma link C++ class AliAnalysisTaskMuonTrackingEff+;
 #pragma link C++ class AliCheckMuonDetEltResponse+;
 #pragma link C++ class AliAnalysisTaskRecoCheck+;
+#pragma link C++ class AliAnalysisTaskESDMCLabelAddition+;
 #endif
 
 
index 361960d7a7ca99176d9de8e558b196497802b215..3ee15b2a7ea6782d81a336f4c916ad8724ee5ea0 100644 (file)
@@ -2,7 +2,8 @@
 
 SRCS:=  muondep/AliAnalysisTaskMuonTrackingEff.cxx \
          muondep/AliCheckMuonDetEltResponse.cxx \
-         muondep/AliAnalysisTaskRecoCheck.cxx
+         muondep/AliAnalysisTaskRecoCheck.cxx \
+         muondep/AliAnalysisTaskESDMCLabelAddition.cxx
 
 HDRS:= $(SRCS:.cxx=.h)
 
diff --git a/PWG3/muondep/AddTaskESDMCLabelAddition.C b/PWG3/muondep/AddTaskESDMCLabelAddition.C
new file mode 100644 (file)
index 0000000..e00b821
--- /dev/null
@@ -0,0 +1,40 @@
+AliAnalysisTaskESDMCLabelAddition *AddTaskESDMCLabelAddition(Bool_t useKineFilter=kTRUE)
+{
+// Creates a filter task and adds it to the analysis manager.
+// This file allows the creation of MC labels (based on the code of Philippe P.)
+
+   // Get the pointer to the existing analysis manager via the static access method.
+   //==============================================================================
+   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+   if (!mgr) {
+      ::Error("AddTaskESDMCLabelAddition", "No analysis manager to connect to.");
+      return NULL;
+   }   
+   
+   TString type = mgr->GetInputEventHandler()->GetDataType();
+   // Check if MC handler is connected in case kine filter requested
+   AliMCEventHandler *mcH = (AliMCEventHandler*)mgr->GetMCtruthEventHandler();
+   if (!mcH && useKineFilter) {
+      ::Error("AddTaskESDFilter", "No MC handler connected while kine filtering requested");
+      return NULL;
+   }   
+   
+   if (useKineFilter) {
+      AliAnalysisTaskMCParticleFilter *kinefilter = new AliAnalysisTaskMCParticleFilter("Particle Kine Filter");
+      mgr->AddTask(kinefilter);
+   }   
+
+
+   // Create the task, add it to the manager and configure it.
+   //===========================================================================   
+   // Barrel tracks filter
+   AliAnalysisTaskESDMCLabelAddition *ESDMCLabeltask = new AliAnalysisTaskESDMCLabelAddition("ESD MC Labels addition");
+   mgr->AddTask(ESDMCLabeltask);
+   
+   // Create ONLY the output containers for the data produced by the task.
+   // Get and connect other common input/output containers via the manager as below
+   //==============================================================================
+   mgr->ConnectInput  (ESDMCLabeltask,  0, mgr->GetCommonInputContainer());
+
+   return ESDMCLabeltask;
+}   
diff --git a/PWG3/muondep/AliAnalysisTaskESDMCLabelAddition.cxx b/PWG3/muondep/AliAnalysisTaskESDMCLabelAddition.cxx
new file mode 100644 (file)
index 0000000..b467f51
--- /dev/null
@@ -0,0 +1,237 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+// Add the muon tracks to the generic AOD track branch during the 
+// filtering of the ESD - R. Arnaldi 5/5/08
+
+#include <TChain.h>
+#include <TFile.h>
+#include <TParticle.h>
+
+#include "AliAnalysisTaskESDMCLabelAddition.h"
+#include "AliAnalysisManager.h"
+#include "AliESDEvent.h"
+#include "AliAODEvent.h"
+#include "AliESDInputHandler.h"
+#include "AliAODHandler.h"
+#include "AliAnalysisFilter.h"
+#include "AliESDtrack.h"
+#include "AliESDMuonTrack.h"
+#include "AliESDMuonCluster.h"
+#include "AliESDVertex.h"
+#include "AliMultiplicity.h"
+#include "AliLog.h"
+#include "AliStack.h"
+#include "AliMCEvent.h"
+#include "AliMCEventHandler.h"
+#include "AliAODMCParticle.h"
+
+#include "AliMUONRecoCheck.h"
+#include "AliMUONESDInterface.h"
+#include "AliMUONTrack.h"
+#include "AliMUONTrackParam.h"
+#include "AliMUONVTrackStore.h"
+#include "AliMUONVCluster.h"
+#include "AliMUONVClusterStore.h"
+
+ClassImp(AliAnalysisTaskESDMCLabelAddition)
+
+// sigma cut applied to match a reconstructed cluster with a trackref
+const Double_t AliAnalysisTaskESDMCLabelAddition::fgkSigmaCut = 10.;
+
+//----------------------------------------------------------------------
+AliAnalysisTaskESDMCLabelAddition::AliAnalysisTaskESDMCLabelAddition():
+  AliAnalysisTaskSE()
+{
+  // Default constructor
+}
+
+
+//----------------------------------------------------------------------
+AliAnalysisTaskESDMCLabelAddition::AliAnalysisTaskESDMCLabelAddition(const char* name):
+  AliAnalysisTaskSE(name)
+{
+  // Constructor
+}
+
+
+//----------------------------------------------------------------------
+void AliAnalysisTaskESDMCLabelAddition::UserCreateOutputObjects()
+{
+}
+
+
+//----------------------------------------------------------------------
+void AliAnalysisTaskESDMCLabelAddition::Init()
+{
+  if (fDebug > 1) AliInfo("Init() \n");
+}
+
+
+//----------------------------------------------------------------------
+void AliAnalysisTaskESDMCLabelAddition::UserExec(Option_t */*option*/)
+{
+  // Execute analysis for current event                                            
+  Long64_t ientry = Entry();
+  printf("MCLabel Addition: Analysing event # %5d\n", (Int_t) ientry);
+  
+  AddMCLabel();
+}
+
+
+//----------------------------------------------------------------------
+void AliAnalysisTaskESDMCLabelAddition::AddMCLabel() 
+{
+  // Load ESD event
+  AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
+  
+  // Load MC event 
+  AliMCEventHandler *mcH = 0;
+  if(MCEvent()) mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()); 
+  
+  // Get reference tracks
+  AliMUONRecoCheck rc(esd,mcH);
+  AliMUONVTrackStore* trackRefStore = rc.TrackRefs(-1);
+  
+  // Loop over reconstructed tracks
+  AliESDMuonTrack *esdTrack = 0x0;
+  Int_t nMuTracks = esd->GetNumberOfMuonTracks();
+  for (Int_t nMuTrack = 0; nMuTrack < nMuTracks; ++nMuTrack) {
+    
+    esdTrack = esd->GetMuonTrack(nMuTrack);
+    
+    // skip ghosts
+    if (!esdTrack->ContainTrackerData()) continue;
+    
+    // try to match the reconstructed track with a simulated one
+    AliMUONTrack* matchedTrackRef = MatchWithTrackRef(*esdTrack, *trackRefStore);
+    
+    if (matchedTrackRef) {
+      
+      // set the MC label
+      esdTrack->SetLabel(matchedTrackRef->GetUniqueID());
+       
+      // remove already matched trackRefs
+      trackRefStore->Remove(*matchedTrackRef);
+      
+    }
+    
+  }
+  
+}
+
+
+//----------------------------------------------------------------------
+void AliAnalysisTaskESDMCLabelAddition::Terminate(Option_t */*option*/)
+{
+  // Terminate analysis
+  //
+  if (fDebug > 1) printf("AnalysisESDfilter: Terminate() \n");
+}
+
+
+//----------------------------------------------------------------------
+AliMUONTrack* AliAnalysisTaskESDMCLabelAddition::ESDToMUON(AliESDMuonTrack &esdTrack)
+{
+  /// Convert an ESD track into a MUON track with dummy parameters (just to fill the clusters).
+  /// It is the responsability of the user to delete the track afterward
+  
+  AliMUONTrack *track = new AliMUONTrack();
+  
+  // ckeck whether the ESD track contains clusters
+  if(!esdTrack.ClustersStored()) return track;
+  
+  // track parameters at first cluster
+  AliMUONTrackParam param;
+  AliMUONESDInterface::GetParamAtFirstCluster(esdTrack, param);
+  AliMUONESDInterface::GetParamCov(esdTrack, param);
+  
+  // create empty cluster
+  AliMUONVClusterStore* cStore = AliMUONESDInterface::NewClusterStore();
+  AliMUONVCluster* cluster = cStore->CreateCluster(0,0,0);
+  
+  // loop over ESD clusters
+  AliESDMuonCluster *esdCluster = (AliESDMuonCluster*) esdTrack.GetClusters().First();
+  while (esdCluster) {
+    
+    // copy cluster information
+    AliMUONESDInterface::ESDToMUON(*esdCluster, *cluster);
+    
+    // only set the Z parameter to avoid error in the AddTrackParamAtCluster(...) method
+    param.SetZ(cluster->GetZ());
+    
+    // add common track parameters at current cluster
+    track->AddTrackParamAtCluster(param, *cluster, kTRUE);
+    
+    esdCluster = (AliESDMuonCluster*) esdTrack.GetClusters().After(esdCluster);
+  }
+  
+  // clean memory
+  delete cluster;
+  delete cStore;
+  
+  return track;
+  
+}
+
+
+//----------------------------------------------------------------------
+AliMUONTrack* AliAnalysisTaskESDMCLabelAddition::MatchWithTrackRef(AliESDMuonTrack &esdTrack,
+                                                                  AliMUONVTrackStore &trackRefStore)
+{
+  /// Return the trackRef matched with the reconstructed track and the fraction of matched clusters
+  
+  AliMUONTrack *matchedTrackRef = 0x0;
+  
+  // convert ESD track to MUON track
+  AliMUONTrack *track = ESDToMUON(esdTrack);
+  
+  // look for the corresponding simulated track if any
+  TIter next(trackRefStore.CreateIterator());
+  AliMUONTrack* trackRef;
+  while ( ( trackRef = static_cast<AliMUONTrack*>(next()) ) ) {
+    
+    // check compatibility
+    if (TrackMatched(*track, *trackRef)) {
+      matchedTrackRef = trackRef;
+      break;
+    }
+    
+  }
+  
+  // clean memory
+  delete track;
+  
+  return matchedTrackRef;
+  
+}
+
+
+//----------------------------------------------------------------------
+Bool_t AliAnalysisTaskESDMCLabelAddition::TrackMatched(AliMUONTrack &track, AliMUONTrack &trackRef)
+{
+  /// Try to match 2 tracks
+  
+  Bool_t compTrack[10];
+  Int_t nMatchClusters = track.CompatibleTrack(&trackRef, fgkSigmaCut, compTrack);
+  Double_t fractionOfMatchCluster = ((Double_t)nMatchClusters) / ((Double_t)track.GetNClusters());
+  
+  if ((compTrack[0] || compTrack[1] || compTrack[2] || compTrack[3]) && // at least 1 cluster matched in st 1 & 2
+      (compTrack[6] || compTrack[7] || compTrack[8] || compTrack[9]) && // at least 1 cluster matched in st 4 & 5
+      fractionOfMatchCluster > 0.5) return kTRUE;                       // more than 50% of clusters matched
+  else return kFALSE;
+  
+}
+
diff --git a/PWG3/muondep/AliAnalysisTaskESDMCLabelAddition.h b/PWG3/muondep/AliAnalysisTaskESDMCLabelAddition.h
new file mode 100644 (file)
index 0000000..958569d
--- /dev/null
@@ -0,0 +1,47 @@
+#ifndef ALIANALYSISTASKESDMCLABELADDITION_H
+#define ALIANALYSISTASKESDMCLABELADDITION_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+#include <TList.h> 
+#include "AliAnalysisTaskSE.h"
+
+class AliAnalysisFilter;
+class AliStack;
+class AliESDMuonTrack;
+class AliMUONTrack;
+class AliMUONVTrackStore;
+
+class AliAnalysisTaskESDMCLabelAddition : public AliAnalysisTaskSE
+{
+  
+  public:
+    AliAnalysisTaskESDMCLabelAddition();
+    AliAnalysisTaskESDMCLabelAddition(const char* name);
+    virtual ~AliAnalysisTaskESDMCLabelAddition() {;}
+    // Implementation of interface methods
+    virtual void UserCreateOutputObjects();
+    virtual void Init();
+    virtual void LocalInit() {Init();}
+    virtual void UserExec(Option_t *option);
+    virtual void Terminate(Option_t *option);
+    
+    
+  private:
+    
+    static const Double_t fgkSigmaCut; // sigma cut applied to match a reconstructed cluster with a trackref
+    
+    AliAnalysisTaskESDMCLabelAddition(const AliAnalysisTaskESDMCLabelAddition&);
+    AliAnalysisTaskESDMCLabelAddition& operator=(const AliAnalysisTaskESDMCLabelAddition&);
+    
+    void AddMCLabel();
+    AliMUONTrack* ESDToMUON(AliESDMuonTrack &esdTrack);
+    AliMUONTrack* MatchWithTrackRef(AliESDMuonTrack &esdTrack, AliMUONVTrackStore &trackRefStore);
+    Bool_t TrackMatched(AliMUONTrack &track, AliMUONTrack &trackRef);
+    
+    ClassDef(AliAnalysisTaskESDMCLabelAddition, 1); // Analysis task for standard ESD filtering
+    
+};
+
+#endif