* provided "as is" without express or implied warranty. *
**************************************************************************/
-/*
-$Log$
-*/
+/* $Id$ */
///////////////////////////////////////////////////////////////////////////////
// //
// //
///////////////////////////////////////////////////////////////////////////////
+#include <TROOT.h>
+#include <TTree.h>
+#include <TFile.h>
+
#include "AliRun.h"
+#include "AliRunLoader.h"
+#include "AliLoader.h"
-#include "AliTRD.h"
#include "AliTRDclusterizer.h"
+#include "AliTRDcluster.h"
+#include "AliTRDrecPoint.h"
+#include "AliTRDgeometry.h"
+#include "AliTRDparameter.h"
ClassImp(AliTRDclusterizer)
// AliTRDclusterizer default constructor
//
- fInputFile = NULL;
- fEvent = 0;
+ fClusterTree = NULL;
+ fRecPoints = 0;
+ fVerbose = 0;
+ fPar = 0;
}
// AliTRDclusterizer default constructor
//
- fInputFile = NULL;
- fEvent = 0;
+ fClusterTree = NULL;
+ fRecPoints = 0;
+ fVerbose = 0;
+ fPar = 0;
+
+}
+
+//_____________________________________________________________________________
+AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c):TNamed(c)
+{
+ //
+ // AliTRDclusterizer copy constructor
+ //
- Init();
+ ((AliTRDclusterizer &) c).Copy(*this);
}
//_____________________________________________________________________________
AliTRDclusterizer::~AliTRDclusterizer()
{
+ //
+ // AliTRDclusterizer destructor
+ //
- if (fInputFile) {
- fInputFile->Close();
- delete fInputFile;
+ if (fRecPoints) {
+ fRecPoints->Delete();
+ delete fRecPoints;
}
+}
+
+//_____________________________________________________________________________
+AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
+{
+ //
+ // Assignment operator
+ //
+
+ if (this != &c) ((AliTRDclusterizer &) c).Copy(*this);
+ return *this;
}
//_____________________________________________________________________________
-void AliTRDclusterizer::Init()
+void AliTRDclusterizer::Copy(TObject &c)
{
//
- // Initializes the cluster finder
+ // Copy function
//
+ ((AliTRDclusterizer &) c).fClusterTree = NULL;
+ ((AliTRDclusterizer &) c).fRecPoints = NULL;
+ ((AliTRDclusterizer &) c).fVerbose = fVerbose;
+ ((AliTRDclusterizer &) c).fPar = 0;
+
}
//_____________________________________________________________________________
Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
{
//
- // Opens a ROOT-file with TRD-hits and reads in the digits-tree
+ // Opens the AliROOT file. Output and input are in the same file
//
+ TString evfoldname = AliConfig::GetDefaultEventFolderName();
+ fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
+ if (!fRunLoader)
+ fRunLoader = AliRunLoader::Open(name);
+ if (!fRunLoader)
+ {
+ Error("Open","Can not open session for file %s.",name);
+ return kFALSE;
+ }
+
+ OpenInput(nEvent);
+ OpenOutput();
+ return kTRUE;
+}
- // Connect the AliRoot file containing Geometry, Kine, and Hits
- fInputFile = (TFile*) gROOT->GetListOfFiles()->FindObject(name);
- if (!fInputFile) {
- printf("AliTRDclusterizer::Open -- ");
- printf("Open the ALIROOT-file %s.\n",name);
- fInputFile = new TFile(name,"UPDATE");
- }
- else {
- printf("AliTRDclusterizer::Open -- ");
- printf("%s is already open.\n",name);
- }
- // Get AliRun object from file or create it if not on file
- //if (!gAlice) {
- gAlice = (AliRun*) fInputFile->Get("gAlice");
- if (gAlice) {
- printf("AliTRDclusterizer::Open -- ");
- printf("AliRun object found on file.\n");
- }
- else {
- printf("AliTRDclusterizer::Open -- ");
- printf("Could not find AliRun object.\n");
- return kFALSE;
- }
- //}
+//_____________________________________________________________________________
+Bool_t AliTRDclusterizer::OpenOutput()
+{
+ //
+ // Open the output file
+ //
- fEvent = nEvent;
+ TObjArray *ioArray = 0;
+
+ AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
+ loader->MakeTree("R");
+ fClusterTree = loader->TreeR();
+ fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
- // Import the Trees for the event nEvent in the file
- Int_t nparticles = gAlice->GetEvent(fEvent);
- if (nparticles <= 0) {
- printf("AliTRDclusterizer::Open -- ");
- printf("No entries in the trees for event %d.\n",fEvent);
- return kFALSE;
- }
return kTRUE;
}
//_____________________________________________________________________________
-Bool_t AliTRDclusterizer::WriteCluster()
+Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
{
//
- // Writes out the TRD-cluster
+ // Opens a ROOT-file with TRD-hits and reads in the digits-tree
//
- // Write the new tree into the input file (use overwrite option)
- Char_t treeName[7];
- sprintf(treeName,"TreeR%d",fEvent);
- printf("AliTRDclusterizer::WriteCluster -- ");
- printf("Write the cluster tree %s for event %d.\n"
- ,treeName,fEvent);
- gAlice->TreeR()->Write(treeName,2);
+ // Connect the AliRoot file containing Geometry, Kine, and Hits
+ if (fRunLoader->GetAliRun() == 0x0) fRunLoader->LoadgAlice();
+ gAlice = fRunLoader->GetAliRun();
+
+ if (!(gAlice)) {
+ fRunLoader->LoadgAlice();
+ gAlice = fRunLoader->GetAliRun();
+ if (!(gAlice)) {
+ printf("AliTRDclusterizer::OpenInput -- ");
+ printf("Could not find AliRun object.\n");
+ return kFALSE;
+ }
+ }
+ // Import the Trees for the event nEvent in the file
+ fRunLoader->GetEvent(nEvent);
+
return kTRUE;
}
-ClassImp(AliTRDcluster)
-
//_____________________________________________________________________________
-AliTRDcluster::AliTRDcluster(Int_t *tracks, Int_t *cluster, Float_t energy, Float_t* position)
- :TObject()
+Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
{
//
- // Create a TRD cluster
+ // Fills TRDcluster branch in the tree with the clusters
+ // found in detector = det. For det=-1 writes the tree.
//
- fDetector = cluster[0];
+ if ((det < -1) || (det >= AliTRDgeometry::Ndet())) {
+ printf("AliTRDclusterizer::WriteClusters -- ");
+ printf("Unexpected detector index %d.\n",det);
+ return kFALSE;
+ }
+
+
+ TBranch *branch = fClusterTree->GetBranch("TRDcluster");
+ if (!branch) {
+ TObjArray *ioArray = 0;
+ branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
+ }
+
+ if ((det >= 0) && (det < AliTRDgeometry::Ndet())) {
+
+ Int_t nRecPoints = RecPoints()->GetEntriesFast();
+ TObjArray *detRecPoints = new TObjArray(400);
- fTimeSlice = cluster[1];
- fEnergy = energy;
+ for (Int_t i = 0; i < nRecPoints; i++) {
+ AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
+ if (det == c->GetDetector()) {
+ detRecPoints->AddLast(c);
+ }
+ else {
+ printf("AliTRDclusterizer::WriteClusters --");
+ printf("Attempt to write a cluster with unexpected detector index\n");
+ }
+ }
+
+ branch->SetAddress(&detRecPoints);
+ fClusterTree->Fill();
+
+ delete detRecPoints;
+
+ return kTRUE;
- fX = position[0];
- fY = position[1];
- fZ = position[2];
+ }
+
+ if (det == -1) {
+
+ Info("WriteClusters","Writing the cluster tree %s for event %d."
+ ,fClusterTree->GetName(),fRunLoader->GetEventNumber());
+ /*
+ fClusterTree->Write();
+ AliTRDgeometry *geo = fTRD->GetGeometry();
+ geo->SetName("TRDgeometry");
+ geo->Write();
+ fPar->Write();
+ */
+ AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
+ loader->WriteRecPoints("OVERWRITE");
+
+ return kTRUE;
+
+ }
+ /*
+ AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
+ loader->WriteDigits("OVERWRITE");
+ */
+ printf("AliTRDclusterizer::WriteClusters -- ");
+ printf("Unexpected detector index %d.\n",det);
+
+ return kFALSE;
+
+}
+
+
+//_____________________________________________________________________________
+void AliTRDclusterizer::AddCluster(Float_t *pos, Int_t det, Float_t amp
+ , Int_t *tracks, Float_t *sig, Int_t iType)
+{
+ //
+ // Add a cluster for the TRD
+ //
- fTracks[0] = tracks[0];
- fTracks[1] = tracks[1];
- fTracks[2] = tracks[2];
+ AliTRDcluster *c = new AliTRDcluster();
+
+ c->SetDetector(det);
+ c->AddTrackIndex(tracks);
+ c->SetQ(amp);
+ c->SetY(pos[0]);
+ c->SetZ(pos[1]);
+ c->SetSigmaY2(sig[0]);
+ c->SetSigmaZ2(sig[1]);
+ c->SetLocalTimeBin(((Int_t) pos[2]));
+
+ switch (iType) {
+ case 0:
+ c->Set2pad();
+ break;
+ case 1:
+ c->Set3pad();
+ break;
+ case 2:
+ c->Set4pad();
+ break;
+ case 3:
+ c->Set5pad();
+ break;
+ case 4:
+ c->SetLarge();
+ break;
+ };
+
+ RecPoints()->Add(c);
}