]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliTrackMapper.cxx
AliTPCTransform.h - removing warning visible in
[u/mrichter/AliRoot.git] / STEER / AliTrackMapper.cxx
index 1ab5fa62c13c342eb999c4afa5c3e497e84264d6..b166349aa05a3f428ba076ef8a21f4323583cf55 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.3  2002/10/14 14:57:33  hristov
-Merging the VirtualMC branch to the main development branch (HEAD)
-
-Revision 1.2.2.1  2002/10/14 09:45:57  hristov
-Updating VirtualMC to v3-09-02
-
-Revision 1.2  2002/10/01 08:47:04  jchudoba
-Change loop order to run faster.
-
-Revision 1.1  2002/09/17 08:37:12  jchudoba
-Classes to create and store tracks maps - correcpondence between track label and entry number in the TreeH
-
-*/
+/* $Id$ */
 
 ////////////////////////////////////////////////////////////////////////
 //
@@ -41,135 +27,165 @@ Classes to create and store tracks maps - correcpondence between track label and
 
 #include <Riostream.h>
 
-#include "TTree.h"
-#include "TROOT.h"
+#include "TError.h"
 #include "TFile.h"
-#include "TBenchmark.h"
 #include "TStopwatch.h"
+#include "TTree.h"
 
+#include "AliLog.h"
 #include "AliDetector.h"
-#include "AliTrackMapper.h"
-#include "AliTrackMap.h"
-#include "AliRun.h"
 #include "AliHit.h"
+#include "AliLoader.h"
+#include "AliRun.h"
+#include "AliRunLoader.h"
+#include "AliTrackMap.h"
+#include "AliTrackMapper.h"
 
 ClassImp(AliTrackMapper)
 
-////////////////////////////////////////////////////////////////////////
+//_______________________________________________________________________
+AliTrackMapper::AliTrackMapper(): 
+  fDEBUG(0)
+{
+  //
+  // Default ctor
+  //
+}
+
+
+//_______________________________________________________________________
 void AliTrackMapper::CreateMap(Int_t nEvents, Int_t firstEventNr,
-                           const char* fnMap, const char* fnHits)
+                               const char* fnMap, const char* fnHits)
 {
-//
-// method to create a track map for a given number of events starting 
-// from event firstEventNr. This method just opens and closes files and
-// loops over events, the creation of map is delegated to 
-// CreateMap(Int_t eventNr, TFile* fileMap) method
-//
+  //
+  // method to create a track map for a given number of events starting 
+  // from event firstEventNr. This method just opens and closes files and
+  // loops over events, the creation of map is delegated to 
+  // CreateMap(Int_t eventNr, TFile* fileMap) method
+  //
   TStopwatch timer;
   timer.Start();
   
   TFile *fileMap=TFile::Open(fnMap,"new");
-  if (!fileMap->IsOpen()) {cerr<<"Can't open output file "<<fnMap<<"!\n"; return;}
-
-  TFile *fileHits=TFile::Open(fnHits);
-  if (!fileHits->IsOpen()) {cerr<<"Can't open input file "<<fnHits<<"!\n"; return;}
-  if (!(gAlice=(AliRun*)fileHits->Get("gAlice"))) {
-    cerr<<"gAlice have not been found on galice.root !\n";
+  if (!fileMap->IsOpen()) {AliErrorClass(Form("Can't open output file %s!", fnMap)); return;}
+
+  AliRunLoader* rl = AliRunLoader::Open(fnHits);
+  if (rl == 0x0) {AliErrorClass(Form("Can't open input file %s!\n", fnHits)); return;}
+  if (rl->LoadgAlice())
+    {
+      AliErrorClass("Error occured while loading AliRun");
+      return;
+    }
+    
+  if (!(gAlice=rl->GetAliRun())) {
+    AliErrorClass("gAlice have not been found on session !");
     return;
   }
-
+  
+  rl->LoadKinematics();
+  
   for (Int_t eventNr = firstEventNr; eventNr < firstEventNr+nEvents;
        eventNr++) {
-    CreateMap(eventNr,fileMap);
+    CreateMap(eventNr,fileMap,rl);
   } // end loop over events
-
-  delete gAlice;
-  gAlice = 0;
-  fileHits->Close();
-  delete fileHits;
+  
+  delete rl;
   fileMap->Close();
   delete fileMap;
   timer.Stop();
   if (fDEBUG > 0) timer.Print();
 }
 
-////////////////////////////////////////////////////////////////////////
-Int_t  AliTrackMapper::CreateMap(Int_t eventNr, TFile* fileMap) {
-//
-// create an AliTrackMap for a given event
-// correct gAlice must be already present in memory
-//
+//_______________________________________________________________________
+Int_t  AliTrackMapper::CreateMap(Int_t eventNr, TFile* fileMap,AliRunLoader* rl) 
+{
+  //
+  // create an AliTrackMap for a given event
+  // correct gAlice must be already present in memory
+  //
 
-  Int_t nGenPrimPlusSecParticles = gAlice->GetEvent(eventNr);
-  if (fDEBUG > 1) cout<<"nGenPrimPlusSecParticles = "<<nGenPrimPlusSecParticles<<endl;
-  if (nGenPrimPlusSecParticles < 1) {
-    cerr<<"No primary particles found in event "<<eventNr<<endl;
-    return -1;
-  }
+  rl->GetEvent(eventNr);
 
-  TTree *treeK = gAlice->TreeK();
+  TTree *treeK = rl->TreeK();
   if (!treeK) {
-    cerr<<"Error: Event "<<eventNr<<", treeK not found."<<endl;
+    AliErrorClass(Form("Event %d, treeK not found.", eventNr));
     return -1;
   }
   Int_t nAllParticles = static_cast<Int_t>(treeK->GetEntries());
   Int_t *trackMap = new Int_t[nAllParticles];
   for (Int_t i = 0; i<nAllParticles; i++) {trackMap[i] = kNoEntry;}
 
-  TTree *treeH = gAlice->TreeH();
-  if (!treeH) {
-    cerr<<"Error: Event "<<eventNr<<", treeH not found."<<endl;
-    return -1;
-  }
-  Int_t treeHEntries = static_cast<Int_t>(treeH->GetEntries());
-  if (fDEBUG > 1) cout<<"treeHEntries "<<treeHEntries<<endl;
-
 
   TObjArray *modules = gAlice->Detectors();
   if (!modules) {
-    cerr<<"TObjArray with modules not found."<<endl;
+    AliErrorClass("TObjArray with modules not found.");
     return -1;
   }
   Int_t nModules = static_cast<Int_t>(modules->GetEntries());
   AliHit* hit;
-  for (Int_t treeHIndex = 0; treeHIndex < treeHEntries; treeHIndex++) {
-    gAlice->ResetHits();
-    treeH->GetEvent(treeHIndex);
-    for (Int_t iModule = 0; iModule < nModules; iModule++) {
-      AliDetector * detector = dynamic_cast<AliDetector*>(modules->At(iModule));
-      if (!detector) continue;
-// process only detectors with shunt = 0
+  for (Int_t iModule = 0; iModule < nModules; iModule++) 
+   {
+    AliDetector * detector = dynamic_cast<AliDetector*>(modules->At(iModule));
+    if (!detector) continue;
+    AliLoader* loader = detector->GetLoader();
+    if (loader == 0x0)
+     {
+       AliWarningClass(Form("Can not get loader from detector %s.",
+                      detector->GetName()));
+       continue;
+     }
+    Int_t retval = loader->LoadHits();
+    if (retval) {
+      AliErrorClass(Form("Event %d: error occured while loading hits for %s",
+                        eventNr,detector->GetName()));
+      return -1;
+     }
+    
+    TTree *treeH = loader->TreeH();
+    if (!treeH) {
+      AliErrorClass(Form("Event %d: Can not get TreeH for %s",
+                        eventNr,detector->GetName()));
+      return -1;
+     }
+    Int_t treeHEntries = static_cast<Int_t>(treeH->GetEntries());
+    AliDebugClass(2, Form("treeHEntries %d", treeHEntries));
+     
+    detector->ResetHits();
+    
+    for (Int_t treeHIndex = 0; treeHIndex < treeHEntries; treeHIndex++)  
+     { // process only detectors with shunt = 0
+      treeH->GetEvent(treeHIndex);
       if (detector->GetIshunt()) continue; 
 
-      hit=(AliHit*)detector->FirstHit(-1);
+      hit=dynamic_cast<AliHit*>(detector->FirstHit(-1));
       Int_t lastLabel=-1, label;
-      for( ; hit; hit=(AliHit*)detector->NextHit() ) {
-       label=hit->Track();     
-       if (lastLabel != label) {
-         if (label < 0 || label >= nAllParticles) {
-           cerr<<"Error: label out of range. ";
-           cerr<<"Event "<<eventNr<<" treeHIndex "<<treeHIndex<<" label = "<<label<<endl;
-           return -2;
-         }
-         if (trackMap[label] >=0 && trackMap[label] != treeHIndex) {
-           cerr<<"Error: different treeHIndex for label "<<label
-               <<" indeces: "<<trackMap[label]<<" != "<<treeHIndex;
-           cerr<<" event "<<eventNr<<" detector "<<detector->GetName()<<endl;
-           return -3;
-         }
-         trackMap[label] = treeHIndex;
-         if (fDEBUG > 2) cout<<"treeHIndex, label = "<<treeHIndex<<" "<<label<<endl;
-         lastLabel = label;
-       }
+      for( ; hit; hit=dynamic_cast<AliHit*>(detector->NextHit()) ) {
+       label=hit->Track();       
+       if (lastLabel != label) {
+         if (label < 0 || label >= nAllParticles) {
+           AliErrorClass(Form("label out of range. Event %d treeHIndex %d label = %d",
+                             eventNr, treeHIndex, label));
+           return -2;
+         }
+         if (trackMap[label] >=0 && trackMap[label] != treeHIndex) {
+           AliErrorClass(Form("different treeHIndex for label %d indeces: %d != %d event %d detector %s",
+                             label, trackMap[label], treeHIndex, eventNr, detector->GetName()));
+           return -3;
+         }
+         trackMap[label] = treeHIndex;
+         AliDebugClass(3, Form("treeHIndex, label = %d %d", treeHIndex, label));
+         lastLabel = label;
+       }
       }
-    }
-  }
+    }//loop over hits in module
+    loader->UnloadHits();
+  }//loop over modules
 
-  if (fDEBUG > 2) {
+  ToAliDebugClass(3,
     for (Int_t i = 0; i < nAllParticles; i++) {
       cout<<eventNr<<"\t"<<i<<"\t"<<trackMap[i]<<endl;
     }
-  }
+  )
   fileMap->cd();
   AliTrackMap* trackMapObject = new AliTrackMap(nAllParticles, trackMap);
   trackMapObject->SetEventNr(eventNr);
@@ -180,37 +196,37 @@ Int_t  AliTrackMapper::CreateMap(Int_t eventNr, TFile* fileMap) {
   return 0;
 }
   
-////////////////////////////////////////////////////////////////////////
+//_______________________________________________________________________
 AliTrackMap* AliTrackMapper::LoadTrackMap(Int_t eventNr, const char* fnMap, TFile* &fileMap) {
-//
-// read an AliTrackMap object for the given event eventNr from 
-// the file fileMap
-//
+  //
+  // read an AliTrackMap object for the given event eventNr from 
+  // the file fileMap
+  //
   fileMap=TFile::Open(fnMap);
-  if (!fileMap->IsOpen()) {cerr<<"Can't open file "<<fnMap<<" with map!\n"; return 0;}
+  if (!fileMap->IsOpen()) {AliErrorClass(Form("Can't open file %s with map!", fnMap)); return 0;}
   char mapName[20];
   sprintf(mapName,"AliTrackMap_%5.5d",eventNr);
-  AliTrackMap* trackMapObject = (AliTrackMap*)fileMap->Get(mapName);
+  AliTrackMap* trackMapObject = dynamic_cast<AliTrackMap*>(fileMap->Get(mapName));
   if (!trackMapObject) {
-    cerr<<"Error: map named "<<mapName<<" not found."<<endl;
+    AliErrorClass(Form("map named %s not found.", mapName));
     return 0;
   }
   return trackMapObject;
 }
-////////////////////////////////////////////////////////////////////////
+
+//_______________________________________________________________________
 void AliTrackMapper::CheckTrackMap(Int_t eventNr, const char* fnMap) {
-//
-// 
-//
+  //
+  // 
+  //
   TFile *fileMap;
   AliTrackMap* trackMapObject = LoadTrackMap(eventNr, fnMap, fileMap);
   if (!trackMapObject) return;
-
+  
   trackMapObject->PrintValues();
-
+  
   delete trackMapObject;
   fileMap->Close();
   delete fileMap;
 }
-////////////////////////////////////////////////////////////////////////