]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/DecodeRecoCocktail.C
Updated misalignment macros and AliITSMisalignMaker class (R. Grosso)
[u/mrichter/AliRoot.git] / MUON / DecodeRecoCocktail.C
index 0b9f095cdd628e5bee324386b49fb995e8886cc1..be8f88c39ce17daab2d6cd85134224e84b3f0c3e 100644 (file)
 
 /* $Id$ */
 
-// A. De Falco, H. Woehri, INFN Cagliari, July 2006
-// This macro reads the generation/reconstruction files in the 
-// input directory (dirname), 
-// builds a tree that contains, for each event, an array of muons and dimuons
-// (TClonesArrays of AliMUONTrackLight and AliMUONPairLight objects) 
-// and writes the tree in an output file (outFileName) 
-// Note that if the path for the output file is not explicitly specified, 
-// it will be written in the directory containing the generation/reconstruction
+/// \ingroup macros
+/// \file DecodeRecoCocktail.C
+/// \brief add brief description
+///
+/// \author A. De Falco, H. Woehri, INFN Cagliari, July 2006
+///
+/// This macro reads the generation/reconstruction files in the 
+/// input directories (recodir and simdir), 
+/// builds a tree that contains, for each event, an array of muons and dimuons
+/// (TClonesArrays of AliMUONTrackLight and AliMUONPairLight objects) 
+/// and writes the tree in an output file (outFileName) 
+/// Note that if the path for the output file is not explicitly specified, 
+/// it will be written in the directory containing the generation/reconstruction
+/// 27-Nov-2006: modified by in order to loop on files
+///
+/// 13 Nov 2007:
+/// Updated this macro to work with new version of AliMUONRecoCheck. Also, we are
+/// now fetching reconstructed track data from ESD and not the track tree, because
+/// the AliMUONTrack objects for reconstructed tracks are no longer stored on disk.
+///  - Artur Szostak <artursz@iafrica.com>
 
-#include <iostream>
+#if !defined(__CINT__) || defined(__MAKECINT__)
+#include <Riostream.h>
 #include <TClonesArray.h>
 #include <TFile.h>
 #include <TTree.h>
 #include <TLorentzVector.h>
 #include <TParticle.h>
 #include <TSystem.h>
-#include <AliMUONRecoCheck.h>
-#include <AliMUONTrack.h>
-#include <AliMUONTrackParam.h>
-#include <AliRunLoader.h>
+#include <TGeoManager.h>
+#include "AliMUONRecoCheck.h"
+#include "AliMUONTrack.h"
+#include "AliMUONTrackParam.h"
 #include "AliMUONTrackLight.h"
 #include "AliMUONPairLight.h"
+#include "AliMUONVTrackStore.h"
+#include "AliMUONTrackExtrap.h"
+#include "AliESDEvent.h"
+#include "AliESDVertex.h"
+#include "AliMCEventHandler.h"
+#include "AliMCEvent.h"
+/*TODO: need to update this with changes made to ITS
+#include "AliITSVertexerPPZ.h"
+#include "AliITSLoader.h"
+*/
+#include "AliTracker.h"
+#include "AliMagFMaps.h"
+#endif
 
-void DecodeRecoCocktail(char* dirname=".", char* outFileName = "MuonLight.root"){ 
-  const char *startingDir = gSystem->pwd(); 
-  gSystem->cd(dirname); 
-  TFile *fout = new TFile(outFileName,"recreate"); 
 
-  AliMUONRecoCheck *rc = new AliMUONRecoCheck("galice.root");
-  AliRunLoader *runLoader = rc->GetRunLoader();
-  
+void DecodeRecoCocktail(
+    char* recodir=".",          // The directory containing galice.root for reconstructed data.
+    char* simdir="generated/",  // The directory containing galice.root for simulated data.
+    char* outFileName = "MuonLight.root", // The output filename containing AliMUONTrackLight and AliMUONPairLight objects.
+    char* geoFilename = "geometry.root"  // The filename containing the geometry.
+  )
+{
+/// \param recodir      The directory containing galice.root for reconstructed data.
+/// \param simdir       The directory containing galice.root for simulated data.
+/// \param outFileName  The output filename containing AliMUONTrackLight and AliMUONPairLight objects.
+/// \param geoFilename  The filename containing the geometry.
+
+  char startingDir[200]; 
+  sprintf (startingDir,"%s",gSystem->pwd()); 
+  gSystem->cd(recodir); 
+
   TClonesArray *muonArray   = new TClonesArray("AliMUONTrackLight",10); 
   TClonesArray *dimuonArray = new TClonesArray("AliMUONPairLight",10); 
   TTree *treeOut = new TTree("tree","tree"); 
 
+  TFile *fout = new TFile(outFileName,"recreate"); 
   fout->cd(); 
+
   treeOut->Branch("muons",&muonArray); 
   treeOut->Branch("dimuons",&dimuonArray); 
   
-  runLoader->LoadKinematics("READ");;
-  Int_t nev = runLoader->GetNumberOfEvents(); 
+  // Import TGeo geometry (needed by AliMUONTrackExtrap::ExtrapToVertex)
+  if (!gGeoManager) {
+    TGeoManager::Import(geoFilename);
+    if (!gGeoManager) {
+      Error("MUONmass_ESD", "getting geometry from file %s failed", geoFilename);
+      return;
+    }
+  }
+  
+  // set  mag field 
+  // waiting for mag field in CDB 
+  printf("Loading field map...\n");
+  AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
+  AliTracker::SetFieldMap(field, kFALSE);
+  // set the magnetic field for track extrapolations
+  AliMUONTrackExtrap::SetField(AliTracker::GetFieldMap());
+
+  AliMUONRecoCheck *rc = new AliMUONRecoCheck("AliESDs.root", simdir);
+  Int_t nev = rc->NumberOfEvents();
+  
+  /*TODO: need to update this with changes made to ITS
+  AliITSLoader* ITSloader =  (AliITSLoader*) runLoaderSim->GetLoader("ITSLoader");
+  AliITSVertexerPPZ *dovert = 0; 
+  if (ITSloader) { 
+    dovert = new AliITSVertexerPPZ("default",0,0);
+    // dovert->SetDebug(0);
+    dovert->SetDiffPhiMax(0.05);
+    dovert->SetWindow(3.);
+  }
+  AliESDVertex *vert = 0;
+  */
   
   TLorentzVector v; 
   for(Int_t ievent = 0; ievent < nev; ievent++){ // loop over events 
-    printf ("Event %d of %d\n",ievent,nev);
+    
+    /*TODO: need to update this with changes made to ITS
+    runLoaderSim->GetHeader();
+    if (ITSloader) { 
+      vert = dovert->FindVertexForCurrentEvent(ievent);
+    }
+    */
+    
+    //printf ("Event %d of %d\n",ievent,nev);
     muonArray->Clear();     // clean muon and dimuon arrays 
     dimuonArray->Clear(); 
-    runLoader->GetEvent(ievent);
-    rc->ResetTracks();
-    rc->MakeTrackRef(); // make reconstructable tracks
     
-    TClonesArray * trackRecoArray = rc->GetTrackReco();
-    TClonesArray * trackRefArray = rc->GetMuonTrackRef();
-    Int_t nTrackReco = trackRecoArray->GetEntriesFast();
-    Int_t nreftracks = 0; 
-    for (Int_t itrRec = 0; itrRec<nTrackReco; itrRec++) { 
+    AliMUONVTrackStore* recoTracks = rc->ReconstructedTracks(ievent);  // Use tracks from actual reconstruction, but this does not work anymore.
+    //AliMUONVTrackStore* trackRefs = rc->ReconstructibleTracks(ievent);  // Only use reconstructible reference tracks.
+    AliMUONVTrackStore* trackRefs = rc->TrackRefs(ievent);
+    AliStack* pstack = (const_cast<AliMCEventHandler*>(rc->GetMCEventHandler()))->MCEvent()->Stack();
+    
+    TIter next(recoTracks->CreateIterator());
+    AliMUONTrack* trackReco = NULL;
+    
+    Int_t nTrackReco = recoTracks->GetSize();
+    Int_t nTracksESD = rc->GetESDEvent()->GetNumberOfMuonTracks();
+    if (nTrackReco != nTracksESD) printf ("Tracks in recoTracks (%d) and in ESD (%d) do not match!\n", nTrackReco, nTracksESD);
+    Int_t nreftracks = 0;
+    Int_t itrRec = 0;
+    while ( (trackReco = static_cast<AliMUONTrack*>(next())) != NULL )
+    {
       // assign parameters concerning the reconstructed tracks
-      AliMUONTrack *trackReco = (AliMUONTrack *)trackRecoArray->At(itrRec);
-      AliMUONTrackLight *muLight = new AliMUONTrackLight(); 
-      AliMUONTrackParam *trPar = trackReco->GetTrackParamAtVertex(); 
-      muLight->SetCharge(Int_t(TMath::Sign(1.,trPar->GetInverseBendingMomentum())));
-      muLight->SetPxPyPz(trPar->Px(),trPar->Py(), trPar->Pz()); 
-      muLight->SetTriggered(trackReco->GetMatchTrigger()); 
-      Double_t xyz[3] = { trPar->GetNonBendingCoor(), 
-                         trPar->GetBendingCoor(), 
-                         trPar->GetZ()};
-      muLight->SetVertex(xyz); 
-      // find the reference track and store further information
-      TParticle *part = muLight->FindRefTrack(trackReco,trackRefArray,runLoader); 
+      AliMUONTrackLight muLight;
+      
+      muLight.FillFromESD(rc->GetESDEvent()->GetMuonTrack(itrRec));
+      // muLight.FillFromAliMUONTrack(trackReco);
+      
+      // find the reference track and store further information        
+      TParticle *part = muLight.FindRefTrack(trackReco, trackRefs, pstack);
       if (part) { 
        v.SetPxPyPzE(part->Px(), part->Py(), part->Pz(), part->Energy());
-       muLight->SetPGen(v); 
-       muLight->FillMuonHistory(runLoader, part);
-       muLight->PrintInfo("A");
+       muLight.SetPGen(v); 
+       muLight.FillMuonHistory(pstack, part);
+       //        muLight.PrintInfo("A");
        //store the referenced track in the muonArray:
        TClonesArray &muons = *muonArray;
-       new (muons[nreftracks++]) AliMUONTrackLight(*muLight);
-      }
-    }
+       new (muons[nreftracks++]) AliMUONTrackLight(muLight);
+      } 
+      
+      itrRec++;
+    }  // end reco track
     
     // now loop over muon pairs to build dimuons
     Int_t nmuons = muonArray->GetEntriesFast(); 
@@ -103,27 +182,24 @@ void DecodeRecoCocktail(char* dirname=".", char* outFileName = "MuonLight.root")
       AliMUONTrackLight* mu1 = (AliMUONTrackLight*) muonArray->At(itrRec1); 
       for(Int_t itrRec2 = itrRec1+1; itrRec2 < nmuons; itrRec2++){
        AliMUONTrackLight* mu2 = (AliMUONTrackLight*) muonArray->At(itrRec2); 
-       AliMUONPairLight *dimuLight = new AliMUONPairLight(); 
-       dimuLight->SetMuons(*mu1, *mu2);
-       //      if(dimuLight->GetCreationProcess() == 2){
-       //        printf ("#dimuon = %d (%d, %d) \n", ndimuons, itrRec1, itrRec2);
-       // dimuLight->PrintInfo("A");
-       //      }
-       //store the referenced track in the dimuonArray:
+       AliMUONPairLight dimuLight;
+       dimuLight.SetMuons(*mu1, *mu2);
        TClonesArray &dimuons = *dimuonArray;
-       new (dimuons[ndimuons++]) AliMUONPairLight(*dimuLight);
+       new (dimuons[ndimuons++]) AliMUONPairLight(dimuLight);
       }
     }
-    Int_t ndimu2 = dimuonArray->GetEntriesFast(); 
-    //     printf ("dimuonArray has %d entries\n",ndimu2); 
-    //    dimuonArray->Dump(); 
-    //     printf ("filling tree\n"); 
-    //     // fill the tree
-    treeOut->Fill(); 
-    //     printf ("done\n"); 
     
-  }
+    treeOut->Fill(); 
+  } 
+  
   fout->cd(); 
   treeOut->Write(); 
   gSystem->cd(startingDir); 
+  fout->Close();
+  delete muonArray;
+  delete dimuonArray;
+  delete treeOut; 
+  delete fout;
+  delete rc;
 }
+