]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Classes to create and store tracks maps - correcpondence between track label and...
authorjchudoba <jchudoba@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 17 Sep 2002 08:37:12 +0000 (08:37 +0000)
committerjchudoba <jchudoba@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 17 Sep 2002 08:37:12 +0000 (08:37 +0000)
STEER/AliTrackMap.cxx [new file with mode: 0644]
STEER/AliTrackMap.h [new file with mode: 0644]
STEER/AliTrackMapper.cxx [new file with mode: 0644]
STEER/AliTrackMapper.h [new file with mode: 0644]

diff --git a/STEER/AliTrackMap.cxx b/STEER/AliTrackMap.cxx
new file mode 100644 (file)
index 0000000..26998b6
--- /dev/null
@@ -0,0 +1,113 @@
+/**************************************************************************
+ * 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.                  *
+ **************************************************************************/
+
+/*
+$Log$
+*/
+
+////////////////////////////////////////////////////////////////////////
+//
+// AliTrackMap.cxx
+// description: 
+//   contains a relation between track label and it's index
+//   in a TreeH.
+//   The main method is At, it takes a particle label as an argument
+//   and returns the correponding entry in TreeH (many particles
+//   are usually stored in 1 TreeH entry, one has to check particle
+//   labels for each hit). 'At' returns:
+//       kNoEntry = -1 if the particle has no entry in TreeH
+//       kOutOfBounds = -2 if the particle label is out of bounds
+//                  
+//  Author: Jiri Chudoba (CERN), 2002
+//
+////////////////////////////////////////////////////////////////////////
+
+#include <iostream.h>
+
+#include "TTree.h"
+#include "TROOT.h"
+
+#include "AliTrackMap.h"
+
+#include "AliRun.h"
+
+ClassImp(AliTrackMap)
+
+////////////////////////////////////////////////////////////////////////
+AliTrackMap::AliTrackMap()
+{
+//
+// default ctor
+//
+  fArray=0; 
+  fSize = 0;
+}
+////////////////////////////////////////////////////////////////////////
+AliTrackMap::AliTrackMap(Int_t size, Int_t *array) : 
+  TNamed("AliTrackMap", "AliTrackMap")
+{
+//
+// ctor
+//
+
+  fSize = size;
+  fArray = new Int_t[fSize];
+  for (Int_t i = 0; i < fSize; i++) fArray[i] = array[i];
+}
+////////////////////////////////////////////////////////////////////////
+AliTrackMap::~AliTrackMap()
+{
+//
+// dtor
+//
+
+  delete [] fArray;
+}
+
+////////////////////////////////////////////////////////////////////////
+Int_t AliTrackMap::At(Int_t label)
+{
+//
+// returns entry number in the TreeH corresponding to particle with 
+// label label
+//
+  if (label < 0 || label >= fSize) {
+    cerr<<"AliTrackMap::At: label "<<label<<" out of range, fSize = "<<fSize<<endl;
+    return kOutOfBounds;
+  }
+  return fArray[label];
+}
+////////////////////////////////////////////////////////////////////////
+void AliTrackMap::SetEventNr(Int_t eventNr) 
+{
+//
+// map is identified by it's name, event number is part of it
+//
+  char name[20];
+  sprintf(name,"AliTrackMap_%5.5d",eventNr);
+  SetName(name);  
+}
+////////////////////////////////////////////////////////////////////////
+void AliTrackMap::PrintValues() 
+{
+//
+// method for debugging
+//
+  cout<<this->GetName()<<" contains these values: "<<endl;
+  for (Int_t i = 0; i < fSize; i++) {
+    cout<<i<<"\t"<<fArray[i]<<"\n";
+  }
+}
+////////////////////////////////////////////////////////////////////////
diff --git a/STEER/AliTrackMap.h b/STEER/AliTrackMap.h
new file mode 100644 (file)
index 0000000..6f30b78
--- /dev/null
@@ -0,0 +1,48 @@
+#ifndef ALITRACKMAP_H
+#define ALITRACKMAP_H
+/* Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+////////////////////////////////////////////////////////////////////////
+//
+// AliTrackMap.h
+// description:
+//   contains a relation between track label and it's index
+//   in a TreeH.
+//   See http://AliSoft.cern.ch/people/chudoba/classes/AliTrackMap.html
+//                  
+//  Author: Jiri Chudoba (CERN), 2002
+//
+////////////////////////////////////////////////////////////////////////
+
+#include "TNamed.h"
+
+typedef enum { kOutOfBounds = -2, kNoEntry} MapConsts_t;
+
+class AliTrackMap: public TNamed {
+
+public:
+  AliTrackMap();
+  AliTrackMap(Int_t size, Int_t *array);
+  ~AliTrackMap();
+  Int_t At(Int_t label);
+  Int_t Size(){return fSize;}
+  void SetEventNr(Int_t eventNr);
+  void PrintValues();
+
+private:
+  Int_t fSize;             // size of the array
+
+  Int_t *fArray;           //[fSize] actual map
+
+  ClassDef(AliTrackMap,1)  // connection between track label and TreeH indeces
+};
+
+#endif // ALITRACKMAP_H
+
+
+
+
+
diff --git a/STEER/AliTrackMapper.cxx b/STEER/AliTrackMapper.cxx
new file mode 100644 (file)
index 0000000..17ee681
--- /dev/null
@@ -0,0 +1,205 @@
+/**************************************************************************
+ * 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.                  *
+ **************************************************************************/
+
+/*
+$Log$
+*/
+
+////////////////////////////////////////////////////////////////////////
+//
+// AliTrackMapper.cxx
+// description: 
+//        create an AliTrackMap - a relation between track label and 
+//        it's index in TreeH. Check all branches with hits.
+//        Output is in the root file.
+//
+////////////////////////////////////////////////////////////////////////
+
+#include <iostream.h>
+
+#include "TTree.h"
+#include "TROOT.h"
+#include "TFile.h"
+#include "TBenchmark.h"
+#include "TStopwatch.h"
+
+#include "AliDetector.h"
+#include "AliTrackMapper.h"
+#include "AliTrackMap.h"
+#include "AliRun.h"
+#include "AliHit.h"
+
+ClassImp(AliTrackMapper)
+
+////////////////////////////////////////////////////////////////////////
+void AliTrackMapper::CreateMap(Int_t nEvents, Int_t firstEventNr,
+                           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
+//
+  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";
+    return;
+  }
+
+  for (Int_t eventNr = firstEventNr; eventNr < firstEventNr+nEvents;
+       eventNr++) {
+    CreateMap(eventNr,fileMap);
+  } // end loop over events
+
+  delete gAlice;
+  gAlice = 0;
+  fileHits->Close();
+  delete fileHits;
+  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 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;
+  }
+
+  TTree *treeK = gAlice->TreeK();
+  if (!treeK) {
+    cerr<<"Error: Event "<<eventNr<<", treeK not found."<<endl;
+    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;
+    return -1;
+  }
+  Int_t nModules = static_cast<Int_t>(modules->GetEntries());
+  for (Int_t iModule = 0; iModule < nModules; iModule++) {
+//  for (Int_t iModule = nModules-1; iModule >= 0; iModule--) {
+    AliDetector * detector = dynamic_cast<AliDetector*>(modules->At(iModule));
+    if (!detector) continue;
+// process only detectors with shunt = 0
+    if (detector->GetIshunt()) continue; 
+    if (fDEBUG > 0) cerr<<"Processing detector "<<detector->GetName()<<endl;
+
+    AliHit* hit;
+    for (Int_t treeHIndex = 0; treeHIndex < treeHEntries; treeHIndex++) {
+      detector->ResetHits();
+      treeH->GetEvent(treeHIndex);
+      hit=(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;
+       }
+      }
+    }
+  }
+
+  if (fDEBUG > 0) {
+    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);
+  trackMapObject->Write();
+  delete trackMapObject;
+
+  delete [] trackMap;
+  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
+//
+  fileMap=TFile::Open(fnMap);
+  if (!fileMap->IsOpen()) {cerr<<"Can't open file "<<fnMap<<" with map!\n"; return 0;}
+  char mapName[20];
+  sprintf(mapName,"AliTrackMap_%5.5d",eventNr);
+  AliTrackMap* trackMapObject = (AliTrackMap*)fileMap->Get(mapName);
+  if (!trackMapObject) {
+    cerr<<"Error: map named "<<mapName<<" not found."<<endl;
+    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;
+}
+////////////////////////////////////////////////////////////////////////
+
diff --git a/STEER/AliTrackMapper.h b/STEER/AliTrackMapper.h
new file mode 100644 (file)
index 0000000..ddec808
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef ALITRACKMAPPER_H
+#define ALITRACKMAPPER_H
+/* Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+////////////////////////////////////////////////////////////////////////
+//
+// description:
+//   create a relation between track label and it's index
+//   in TreeH. Check all branches with hits.
+//   Output is in the root file.
+//   See http://AliSoft.cern.ch/people/chudoba/classes/AliTrackMap.html
+//                  
+//  Author: Jiri Chudoba (CERN), 2002
+//
+////////////////////////////////////////////////////////////////////////
+
+// --- ROOT system ---
+
+#include "TString.h"
+#include "TFile.h"
+
+// --- AliRoot header files ---
+
+class AliTrackMap;
+
+class AliTrackMapper {
+
+public:
+  AliTrackMapper(){fDEBUG=0;}
+  virtual ~AliTrackMapper(){;}
+  void CreateMap(Int_t nEvents, Int_t firstEventNr,
+           const char* fnMap = "trackMap.root",
+           const char* fnHits   ="rfio:galice.root");
+  Int_t CreateMap(Int_t eventNr, TFile* fileMap);
+  void SetDebug(Int_t level) {fDEBUG = level;}
+  void CheckTrackMap(Int_t eventNr, const char* fnMap = "trackMap.root");
+  AliTrackMap* LoadTrackMap(Int_t eventNr, const char* fnMap, TFile* &fileMap);
+
+    
+private:
+
+  Int_t fDEBUG;
+  
+  ClassDef(AliTrackMapper,0)  // methods to create AliTrackMap
+};
+
+#endif // ALITRACKMAPPER_H
+
+
+
+
+