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>
33 #include "TBenchmark.h"
34 #include "TStopwatch.h"
36 #include "AliDetector.h"
37 #include "AliTrackMapper.h"
38 #include "AliTrackMap.h"
42 ClassImp(AliTrackMapper)
44 //_______________________________________________________________________
45 AliTrackMapper::AliTrackMapper():
54 //_______________________________________________________________________
55 void AliTrackMapper::CreateMap(Int_t nEvents, Int_t firstEventNr,
56 const char* fnMap, const char* fnHits)
59 // method to create a track map for a given number of events starting
60 // from event firstEventNr. This method just opens and closes files and
61 // loops over events, the creation of map is delegated to
62 // CreateMap(Int_t eventNr, TFile* fileMap) method
67 TFile *fileMap=TFile::Open(fnMap,"new");
68 if (!fileMap->IsOpen()) {cerr<<"Can't open output file "<<fnMap<<"!\n"; return;}
70 TFile *fileHits=TFile::Open(fnHits);
71 if (!fileHits->IsOpen()) {cerr<<"Can't open input file "<<fnHits<<"!\n"; return;}
72 if (!(gAlice=dynamic_cast<AliRun*>(fileHits->Get("gAlice")))) {
73 cerr<<"gAlice have not been found on galice.root !\n";
77 for (Int_t eventNr = firstEventNr; eventNr < firstEventNr+nEvents;
79 CreateMap(eventNr,fileMap);
80 } // end loop over events
89 if (fDEBUG > 0) timer.Print();
92 //_______________________________________________________________________
93 Int_t AliTrackMapper::CreateMap(Int_t eventNr, TFile* fileMap)
96 // create an AliTrackMap for a given event
97 // correct gAlice must be already present in memory
99 Int_t nGenPrimPlusSecParticles = gAlice->GetEvent(eventNr);
100 if (fDEBUG > 1) cout<<"nGenPrimPlusSecParticles = "<<nGenPrimPlusSecParticles<<endl;
101 if (nGenPrimPlusSecParticles < 1) {
102 cerr<<"No primary particles found in event "<<eventNr<<endl;
106 TTree *treeK = gAlice->TreeK();
108 cerr<<"Error: Event "<<eventNr<<", treeK not found."<<endl;
111 Int_t nAllParticles = static_cast<Int_t>(treeK->GetEntries());
112 Int_t *trackMap = new Int_t[nAllParticles];
113 for (Int_t i = 0; i<nAllParticles; i++) {trackMap[i] = kNoEntry;}
115 TTree *treeH = gAlice->TreeH();
117 cerr<<"Error: Event "<<eventNr<<", treeH not found."<<endl;
120 Int_t treeHEntries = static_cast<Int_t>(treeH->GetEntries());
121 if (fDEBUG > 1) cout<<"treeHEntries "<<treeHEntries<<endl;
123 TObjArray *modules = gAlice->Detectors();
125 cerr<<"TObjArray with modules not found."<<endl;
128 Int_t nModules = static_cast<Int_t>(modules->GetEntries());
130 for (Int_t treeHIndex = 0; treeHIndex < treeHEntries; treeHIndex++) {
132 treeH->GetEvent(treeHIndex);
133 for (Int_t iModule = 0; iModule < nModules; iModule++) {
134 AliDetector * detector = dynamic_cast<AliDetector*>(modules->At(iModule));
135 if (!detector) continue;
136 // process only detectors with shunt = 0
137 if (detector->GetIshunt()) continue;
139 hit=dynamic_cast<AliHit*>(detector->FirstHit(-1));
140 Int_t lastLabel=-1, label;
141 for( ; hit; hit=dynamic_cast<AliHit*>(detector->NextHit()) ) {
143 if (lastLabel != label) {
144 if (label < 0 || label >= nAllParticles) {
145 cerr<<"Error: label out of range. ";
146 cerr<<"Event "<<eventNr<<" treeHIndex "<<treeHIndex<<" label = "<<label<<endl;
149 if (trackMap[label] >=0 && trackMap[label] != treeHIndex) {
150 cerr<<"Error: different treeHIndex for label "<<label
151 <<" indeces: "<<trackMap[label]<<" != "<<treeHIndex;
152 cerr<<" event "<<eventNr<<" detector "<<detector->GetName()<<endl;
155 trackMap[label] = treeHIndex;
156 if (fDEBUG > 2) cout<<"treeHIndex, label = "<<treeHIndex<<" "<<label<<endl;
164 for (Int_t i = 0; i < nAllParticles; i++) {
165 cout<<eventNr<<"\t"<<i<<"\t"<<trackMap[i]<<endl;
169 AliTrackMap* trackMapObject = new AliTrackMap(nAllParticles, trackMap);
170 trackMapObject->SetEventNr(eventNr);
171 trackMapObject->Write();
172 delete trackMapObject;
178 //_______________________________________________________________________
179 AliTrackMap* AliTrackMapper::LoadTrackMap(Int_t eventNr, const char* fnMap, TFile* &fileMap) {
181 // read an AliTrackMap object for the given event eventNr from
184 fileMap=TFile::Open(fnMap);
185 if (!fileMap->IsOpen()) {cerr<<"Can't open file "<<fnMap<<" with map!\n"; return 0;}
187 sprintf(mapName,"AliTrackMap_%5.5d",eventNr);
188 AliTrackMap* trackMapObject = dynamic_cast<AliTrackMap*>(fileMap->Get(mapName));
189 if (!trackMapObject) {
190 cerr<<"Error: map named "<<mapName<<" not found."<<endl;
193 return trackMapObject;
196 //_______________________________________________________________________
197 void AliTrackMapper::CheckTrackMap(Int_t eventNr, const char* fnMap) {
202 AliTrackMap* trackMapObject = LoadTrackMap(eventNr, fnMap, fileMap);
203 if (!trackMapObject) return;
205 trackMapObject->PrintValues();
207 delete trackMapObject;