]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/MUONRefit.C
Fixes for object target dependencies
[u/mrichter/AliRoot.git] / MUON / MUONRefit.C
index 69d299d5c7169e5e4123d6771cce7ce273c1a566..3db97280060f6440d8cad50fb6d82698cc58ec83 100644 (file)
@@ -49,6 +49,7 @@
 #endif
 
 const Int_t printLevel = 1;
+const Bool_t reconstructFromDigits = kTRUE; // kFALSE = reconstruct from clusters
 
 TTree* GetESDTree(TFile *esdFile);
 
@@ -66,14 +67,19 @@ void MUONRefit(Int_t nevents = -1, const char* esdFileNameIn = "AliESDs.root", c
   TFile* esdFile = TFile::Open(esdFileNameIn);
   TTree* esdTree = GetESDTree(esdFile);
   
+  // connect ESD event to the ESD tree
+  AliESDEvent* esd = new AliESDEvent();
+  esd->ReadFromTree(esdTree);
+  
   // create the ESD output file and tree
   TFile* newESDFile = TFile::Open(esdFileNameOut, "RECREATE");
   newESDFile->SetCompressionLevel(2);
-  TTree* newESDTree = esdTree->CloneTree(0);
   
-  // connect ESD event to the ESD tree
-  AliESDEvent* esd = new AliESDEvent();
-  esd->ReadFromTree(esdTree);
+  // connect ESD event to the ESD tree (recreate track branch for backward compatibility)
+  esdTree->SetBranchStatus("*MuonTracks*",0);
+  TTree* newESDTree = esdTree->CloneTree(0);
+  esdTree->SetBranchStatus("*MuonTracks*",1);
+  esd->WriteToTree(newESDTree);
   
   // get run number
   if (esdTree->GetEvent(0) <= 0) {
@@ -131,16 +137,31 @@ void MUONRefit(Int_t nevents = -1, const char* esdFileNameIn = "AliESDs.root", c
     // load the current event
     esdInterface.LoadEvent(*esd, kFALSE);
     
-    // loop over digit to modify their charge
-    AliMUONVDigit *digit;
-    TIter next(esdInterface.CreateDigitIterator());
-    while ((digit = static_cast<AliMUONVDigit*>(next()))) {
-      digit->SetCharge(digit->ADC());
-      digit->Calibrated(kFALSE);
-    }
+    // remove digits and clusters from ESD
+    esd->FindListObject("MuonClusters")->Clear("C");
+    esd->FindListObject("MuonPads")->Clear("C");
     
-    // refit the tracks from digits
-    AliMUONVTrackStore* newTrackStore = refitter.ReconstructFromDigits();
+    AliMUONVTrackStore* newTrackStore = 0x0;
+    if (reconstructFromDigits) {
+      
+      // loop over digits to modify their charge
+      AliMUONVDigit *digit;
+      TIter next(esdInterface.CreateDigitIterator());
+      while ((digit = static_cast<AliMUONVDigit*>(next()))) {
+        digit->SetCharge(digit->ADC());
+        digit->Calibrated(kFALSE);
+      }
+      
+      // refit the tracks from digits
+      refitter.SetFirstClusterIndex(0);
+      newTrackStore = refitter.ReconstructFromDigits();
+      
+    } else {
+      
+      // refit the tracks from clusters
+      newTrackStore = refitter.ReconstructFromClusters();
+      
+    }
     
     //----------------------------------------------//
     // ------ fill new ESD and print results ------ //
@@ -162,12 +183,19 @@ void MUONRefit(Int_t nevents = -1, const char* esdFileNameIn = "AliESDs.root", c
       AliMUONTrack* newTrack = (AliMUONTrack*) newTrackStore->FindObject(esdTrack->GetUniqueID());
       
       // replace the content of the current ESD track or remove it if the refitting has failed
-      if (newTrack) {
+      if (newTrack && (!recoParam->ImproveTracks() || newTrack->IsImproved())) {
+       
+       // fill the track info
        Double_t vertex[3] = {esdTrack->GetNonBendingCoor(), esdTrack->GetBendingCoor(), esdTrack->GetZ()};
-       AliMUONESDInterface::MUONToESD(*newTrack, *esdTrack, vertex, esdInterface.GetDigits());
-      } else {
-       esdTracks->Remove(esdTrack);
-      }
+       AliMUONESDInterface::MUONToESD(*newTrack, *esdTrack, vertex);
+       
+       // add the clusters (and the digits if previously there)
+       for (Int_t i = 0; i < newTrack->GetNClusters(); i++) {
+         AliMUONTrackParam *param = static_cast<AliMUONTrackParam*>(newTrack->GetTrackParamAtCluster()->UncheckedAt(i));
+         AliMUONESDInterface::MUONToESD(*(param->GetClusterPtr()), *esd, esdInterface.GetDigits());
+       }
+       
+      } else esdTracks->Remove(esdTrack);
       
       // print initial and re-fitted track parameters at first cluster if any
       if (printLevel>0) {