* provided "as is" without express or implied warranty. *
**************************************************************************/
-/* $Header$ */
+/* $Id$ */
////////////////////////////////////////////////////////////////////////
//
#include <Riostream.h>
-#include "TTree.h"
+#include "TError.h"
#include "TFile.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)
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=dynamic_cast<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();
}
//_______________________________________________________________________
-Int_t AliTrackMapper::CreateMap(Int_t eventNr, TFile* fileMap) const
+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;
- }
- TTree *treeK = gAlice->TreeK();
+ rl->GetEvent(eventNr);
+
+ 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=dynamic_cast<AliHit*>(detector->FirstHit(-1));
Int_t lastLabel=-1, label;
for( ; hit; hit=dynamic_cast<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;
- }
+ 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);
// 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 = 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;