1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ////////////////////////////////////////////////////////////////////////
22 // create an AliTrackMap - a relation between track label and
23 // it's index in TreeH. Check all branches with hits.
24 // Output is in the root file.
26 ////////////////////////////////////////////////////////////////////////
28 #include <Riostream.h>
32 #include "TStopwatch.h"
35 #include "AliDetector.h"
37 #include "AliLoader.h"
39 #include "AliRunLoader.h"
40 #include "AliTrackMap.h"
41 #include "AliTrackMapper.h"
43 ClassImp(AliTrackMapper)
45 //_______________________________________________________________________
46 AliTrackMapper::AliTrackMapper():
55 //_______________________________________________________________________
56 void AliTrackMapper::CreateMap(Int_t nEvents, Int_t firstEventNr,
57 const char* fnMap, const char* fnHits)
60 // method to create a track map for a given number of events starting
61 // from event firstEventNr. This method just opens and closes files and
62 // loops over events, the creation of map is delegated to
63 // CreateMap(Int_t eventNr, TFile* fileMap) method
68 TFile *fileMap=TFile::Open(fnMap,"new");
69 if (!fileMap->IsOpen()) {cerr<<"Can't open output file "<<fnMap<<"!\n"; return;}
71 AliRunLoader* rl = AliRunLoader::Open(fnHits);
72 if (rl == 0x0) {cerr<<"Can't open input file "<<fnHits<<"!\n"; return;}
75 ::Error("AliTrackMapper::CreateMap","Error occured while loading AliRun");
79 if (!(gAlice=rl->GetAliRun())) {
80 cerr<<"gAlice have not been found on session !\n";
86 for (Int_t eventNr = firstEventNr; eventNr < firstEventNr+nEvents;
88 CreateMap(eventNr,fileMap,rl);
89 } // end loop over events
95 if (fDEBUG > 0) timer.Print();
98 //_______________________________________________________________________
99 Int_t AliTrackMapper::CreateMap(Int_t eventNr, TFile* fileMap,AliRunLoader* rl)
102 // create an AliTrackMap for a given event
103 // correct gAlice must be already present in memory
106 rl->GetEvent(eventNr);
108 TTree *treeK = rl->TreeK();
110 cerr<<"Error: Event "<<eventNr<<", treeK not found."<<endl;
113 Int_t nAllParticles = static_cast<Int_t>(treeK->GetEntries());
114 Int_t *trackMap = new Int_t[nAllParticles];
115 for (Int_t i = 0; i<nAllParticles; i++) {trackMap[i] = kNoEntry;}
118 TObjArray *modules = gAlice->Detectors();
120 cerr<<"TObjArray with modules not found."<<endl;
123 Int_t nModules = static_cast<Int_t>(modules->GetEntries());
125 for (Int_t iModule = 0; iModule < nModules; iModule++)
127 AliDetector * detector = dynamic_cast<AliDetector*>(modules->At(iModule));
128 if (!detector) continue;
129 AliLoader* loader = detector->GetLoader();
132 ::Warning("AliTrackMapper::CreateMap",
133 "Can not get loader from detector %s.",detector->GetName());
136 Int_t retval = loader->LoadHits();
138 ::Error("AliTrackMapper::CreateMap",
139 "Event %d: error occured while loading hits for %s",
140 eventNr,detector->GetName());
144 TTree *treeH = loader->TreeH();
146 ::Error("AliTrackMapper::CreateMap","Event %d: Can not get TreeH for %s",
147 eventNr,detector->GetName());
150 Int_t treeHEntries = static_cast<Int_t>(treeH->GetEntries());
151 if (fDEBUG > 1) cout<<"treeHEntries "<<treeHEntries<<endl;
153 detector->ResetHits();
155 for (Int_t treeHIndex = 0; treeHIndex < treeHEntries; treeHIndex++)
156 { // process only detectors with shunt = 0
157 treeH->GetEvent(treeHIndex);
158 if (detector->GetIshunt()) continue;
160 hit=dynamic_cast<AliHit*>(detector->FirstHit(-1));
161 Int_t lastLabel=-1, label;
162 for( ; hit; hit=dynamic_cast<AliHit*>(detector->NextHit()) ) {
164 if (lastLabel != label) {
165 if (label < 0 || label >= nAllParticles) {
166 cerr<<"Error: label out of range. ";
167 cerr<<"Event "<<eventNr<<" treeHIndex "<<treeHIndex<<" label = "<<label<<endl;
170 if (trackMap[label] >=0 && trackMap[label] != treeHIndex) {
171 cerr<<"Error: different treeHIndex for label "<<label
172 <<" indeces: "<<trackMap[label]<<" != "<<treeHIndex;
173 cerr<<" event "<<eventNr<<" detector "<<detector->GetName()<<endl;
176 trackMap[label] = treeHIndex;
177 if (fDEBUG > 2) cout<<"treeHIndex, label = "<<treeHIndex<<" "<<label<<endl;
181 }//loop over hits in module
182 loader->UnloadHits();
186 for (Int_t i = 0; i < nAllParticles; i++) {
187 cout<<eventNr<<"\t"<<i<<"\t"<<trackMap[i]<<endl;
191 AliTrackMap* trackMapObject = new AliTrackMap(nAllParticles, trackMap);
192 trackMapObject->SetEventNr(eventNr);
193 trackMapObject->Write();
194 delete trackMapObject;
200 //_______________________________________________________________________
201 AliTrackMap* AliTrackMapper::LoadTrackMap(Int_t eventNr, const char* fnMap, TFile* &fileMap) {
203 // read an AliTrackMap object for the given event eventNr from
206 fileMap=TFile::Open(fnMap);
207 if (!fileMap->IsOpen()) {cerr<<"Can't open file "<<fnMap<<" with map!\n"; return 0;}
209 sprintf(mapName,"AliTrackMap_%5.5d",eventNr);
210 AliTrackMap* trackMapObject = dynamic_cast<AliTrackMap*>(fileMap->Get(mapName));
211 if (!trackMapObject) {
212 cerr<<"Error: map named "<<mapName<<" not found."<<endl;
215 return trackMapObject;
218 //_______________________________________________________________________
219 void AliTrackMapper::CheckTrackMap(Int_t eventNr, const char* fnMap) {
224 AliTrackMap* trackMapObject = LoadTrackMap(eventNr, fnMap, fileMap);
225 if (!trackMapObject) return;
227 trackMapObject->PrintValues();
229 delete trackMapObject;