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"
36 #include "AliDetector.h"
38 #include "AliLoader.h"
40 #include "AliRunLoader.h"
41 #include "AliTrackMap.h"
42 #include "AliTrackMapper.h"
44 ClassImp(AliTrackMapper)
46 //_______________________________________________________________________
47 AliTrackMapper::AliTrackMapper():
56 //_______________________________________________________________________
57 void AliTrackMapper::CreateMap(Int_t nEvents, Int_t firstEventNr,
58 const char* fnMap, const char* fnHits)
61 // method to create a track map for a given number of events starting
62 // from event firstEventNr. This method just opens and closes files and
63 // loops over events, the creation of map is delegated to
64 // CreateMap(Int_t eventNr, TFile* fileMap) method
69 TFile *fileMap=TFile::Open(fnMap,"new");
70 if (!fileMap->IsOpen()) {AliErrorClass(Form("Can't open output file %s!", fnMap)); return;}
72 AliRunLoader* rl = AliRunLoader::Open(fnHits);
73 if (rl == 0x0) {AliErrorClass(Form("Can't open input file %s!\n", fnHits)); return;}
76 AliErrorClass("Error occured while loading AliRun");
80 if (!(gAlice=rl->GetAliRun())) {
81 AliErrorClass("gAlice have not been found on session !");
87 for (Int_t eventNr = firstEventNr; eventNr < firstEventNr+nEvents;
89 CreateMap(eventNr,fileMap,rl);
90 } // end loop over events
96 if (fDEBUG > 0) timer.Print();
99 //_______________________________________________________________________
100 Int_t AliTrackMapper::CreateMap(Int_t eventNr, TFile* fileMap,AliRunLoader* rl)
103 // create an AliTrackMap for a given event
104 // correct gAlice must be already present in memory
107 rl->GetEvent(eventNr);
109 TTree *treeK = rl->TreeK();
111 AliErrorClass(Form("Event %d, treeK not found.", eventNr));
114 Int_t nAllParticles = static_cast<Int_t>(treeK->GetEntries());
115 Int_t *trackMap = new Int_t[nAllParticles];
116 for (Int_t i = 0; i<nAllParticles; i++) {trackMap[i] = kNoEntry;}
119 TObjArray *modules = gAlice->Detectors();
121 AliErrorClass("TObjArray with modules not found.");
124 Int_t nModules = static_cast<Int_t>(modules->GetEntries());
126 for (Int_t iModule = 0; iModule < nModules; iModule++)
128 AliDetector * detector = dynamic_cast<AliDetector*>(modules->At(iModule));
129 if (!detector) continue;
130 AliLoader* loader = detector->GetLoader();
133 AliWarningClass(Form("Can not get loader from detector %s.",
134 detector->GetName()));
137 Int_t retval = loader->LoadHits();
139 AliErrorClass(Form("Event %d: error occured while loading hits for %s",
140 eventNr,detector->GetName()));
144 TTree *treeH = loader->TreeH();
146 AliErrorClass(Form("Event %d: Can not get TreeH for %s",
147 eventNr,detector->GetName()));
150 Int_t treeHEntries = static_cast<Int_t>(treeH->GetEntries());
151 AliDebugClass(2, Form("treeHEntries %d", treeHEntries));
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 AliErrorClass(Form("label out of range. Event %d treeHIndex %d label = %d",
167 eventNr, treeHIndex, label));
170 if (trackMap[label] >=0 && trackMap[label] != treeHIndex) {
171 AliErrorClass(Form("different treeHIndex for label %d indeces: %d != %d event %d detector %s",
172 label, trackMap[label], treeHIndex, eventNr, detector->GetName()));
175 trackMap[label] = treeHIndex;
176 AliDebugClass(3, Form("treeHIndex, label = %d %d", treeHIndex, label));
180 }//loop over hits in module
181 loader->UnloadHits();
185 for (Int_t i = 0; i < nAllParticles; i++) {
186 cout<<eventNr<<"\t"<<i<<"\t"<<trackMap[i]<<endl;
190 AliTrackMap* trackMapObject = new AliTrackMap(nAllParticles, trackMap);
191 trackMapObject->SetEventNr(eventNr);
192 trackMapObject->Write();
193 delete trackMapObject;
199 //_______________________________________________________________________
200 AliTrackMap* AliTrackMapper::LoadTrackMap(Int_t eventNr, const char* fnMap, TFile* &fileMap) {
202 // read an AliTrackMap object for the given event eventNr from
205 fileMap=TFile::Open(fnMap);
206 if (!fileMap->IsOpen()) {AliErrorClass(Form("Can't open file %s with map!", fnMap)); return 0;}
208 sprintf(mapName,"AliTrackMap_%5.5d",eventNr);
209 AliTrackMap* trackMapObject = dynamic_cast<AliTrackMap*>(fileMap->Get(mapName));
210 if (!trackMapObject) {
211 AliErrorClass(Form("map named %s not found.", mapName));
214 return trackMapObject;
217 //_______________________________________________________________________
218 void AliTrackMapper::CheckTrackMap(Int_t eventNr, const char* fnMap) {
223 AliTrackMap* trackMapObject = LoadTrackMap(eventNr, fnMap, fileMap);
224 if (!trackMapObject) return;
226 trackMapObject->PrintValues();
228 delete trackMapObject;