X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=TRD%2FAliTRDclusterizer.cxx;h=4f493ba9ca17a0d878fb97edf0fa4a3f8489cf05;hb=de3b8fdc6314a404fefffc98aa75dab2e2c05bf9;hp=8c6b7ef8e8d359ce069ef6eebc9ab6d2739a8e70;hpb=a3c76cdc5a380432b4233697539c89802d6e9b6e;p=u%2Fmrichter%2FAliRoot.git diff --git a/TRD/AliTRDclusterizer.cxx b/TRD/AliTRDclusterizer.cxx index 8c6b7ef8e8d..4f493ba9ca1 100644 --- a/TRD/AliTRDclusterizer.cxx +++ b/TRD/AliTRDclusterizer.cxx @@ -13,55 +13,7 @@ * provided "as is" without express or implied warranty. * **************************************************************************/ -/* -$Log$ -Revision 1.6 2000/11/01 14:53:20 cblume -Merge with TRD-develop - - -Revision 1.1.4.5 2000/10/15 23:40:01 cblume -Remove AliTRDconst - -Revision 1.1.4.4 2000/10/06 16:49:46 cblume -Made Getters const - -Revision 1.1.4.3 2000/10/04 16:34:58 cblume -Replace include files by forward declarations - -Revision 1.1.4.2 2000/09/22 14:49:49 cblume -Adapted to tracking code - -Revision 1.5 2000/10/02 21:28:19 fca -Removal of useless dependecies via forward declarations - -Revision 1.4 2000/06/09 11:10:07 cblume -Compiler warnings and coding conventions, next round - -Revision 1.3 2000/06/08 18:32:58 cblume -Make code compliant to coding conventions - -Revision 1.2 2000/05/08 16:17:27 cblume -Merge TRD-develop - -Revision 1.1.4.1 2000/05/08 15:08:03 cblume -Remove the class AliTRDcluster - -Revision 1.4 2000/06/09 11:10:07 cblume -Compiler warnings and coding conventions, next round - -Revision 1.3 2000/06/08 18:32:58 cblume -Make code compliant to coding conventions - -Revision 1.2 2000/05/08 16:17:27 cblume -Merge TRD-develop - -Revision 1.1.4.1 2000/05/08 15:08:03 cblume -Remove the class AliTRDcluster - -Revision 1.1 2000/02/28 18:57:58 cblume -Add new TRD classes - -*/ +/* $Id$ */ /////////////////////////////////////////////////////////////////////////////// // // @@ -72,51 +24,57 @@ Add new TRD classes #include #include #include +#include + +#include "AliRunLoader.h" +#include "AliLoader.h" +#include "AliLog.h" -#include "AliRun.h" -#include "AliTRD.h" #include "AliTRDclusterizer.h" -#include "AliTRDrecPoint.h" +#include "AliTRDcluster.h" #include "AliTRDgeometry.h" +#include "AliTRDcalibDB.h" +#include "AliTRDCommonParam.h" ClassImp(AliTRDclusterizer) //_____________________________________________________________________________ -AliTRDclusterizer::AliTRDclusterizer():TNamed() +AliTRDclusterizer::AliTRDclusterizer() + :TNamed() + ,fRunLoader(NULL) + ,fClusterTree(NULL) + ,fRecPoints(NULL) { // // AliTRDclusterizer default constructor // - fInputFile = NULL; - fEvent = 0; - } //_____________________________________________________________________________ AliTRDclusterizer::AliTRDclusterizer(const Text_t* name, const Text_t* title) - :TNamed(name, title) + :TNamed(name,title) + ,fRunLoader(NULL) + ,fClusterTree(NULL) + ,fRecPoints(NULL) { // - // AliTRDclusterizer default constructor + // AliTRDclusterizer constructor // - fInputFile = NULL; - fEvent = 0; - - Init(); - } //_____________________________________________________________________________ AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c) + :TNamed(c) + ,fRunLoader(NULL) + ,fClusterTree(NULL) + ,fRecPoints(NULL) { // // AliTRDclusterizer copy constructor // - ((AliTRDclusterizer &) c).Copy(*this); - } //_____________________________________________________________________________ @@ -126,9 +84,9 @@ AliTRDclusterizer::~AliTRDclusterizer() // AliTRDclusterizer destructor // - if (fInputFile) { - fInputFile->Close(); - delete fInputFile; + if (fRecPoints) { + fRecPoints->Delete(); + delete fRecPoints; } } @@ -140,142 +98,229 @@ AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c) // Assignment operator // - if (this != &c) ((AliTRDclusterizer &) c).Copy(*this); + if (this != &c) { + ((AliTRDclusterizer &) c).Copy(*this); + } return *this; } //_____________________________________________________________________________ -void AliTRDclusterizer::Copy(TObject &c) +void AliTRDclusterizer::Copy(TObject &c) const { // // Copy function // - ((AliTRDclusterizer &) c).fInputFile = NULL; - ((AliTRDclusterizer &) c).fEvent = 0; + ((AliTRDclusterizer &) c).fClusterTree = NULL; + ((AliTRDclusterizer &) c).fRecPoints = NULL; } //_____________________________________________________________________________ -void AliTRDclusterizer::Init() +Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent) { // - // Initializes the cluster finder + // 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) { + AliError(Form("Can not open session for file %s.",name)); + return kFALSE; + } + + OpenInput(nEvent); + OpenOutput(); + + return kTRUE; + } //_____________________________________________________________________________ -Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent) +Bool_t AliTRDclusterizer::OpenOutput() { // - // Opens a ROOT-file with TRD-hits and reads in the digits-tree + // Open the output file // - // 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); - } + TObjArray *ioArray = 0; - // 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("Could not find AliRun object.\n"); - return kFALSE; - } - } + AliLoader* loader = fRunLoader->GetLoader("TRDLoader"); + loader->MakeTree("R"); - fEvent = nEvent; + 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::OpenOutput(TTree *clusterTree) +{ + // + // Connect the output tree + // - // Create a tree for the reconstructed points - TTree *recPointTree = new TTree("ClusterTree","Tree with clusters and rec. points"); TObjArray *ioArray = 0; - recPointTree->Branch("TRDrecPoints","TObjArray",&ioArray,32000,0); -// TObjArray *iopointer = 0; -// recPointTree->Branch("Clusters","TObjArray",&iopointer,32000,0); + + fClusterTree = clusterTree; + fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0); return kTRUE; } //_____________________________________________________________________________ -Bool_t AliTRDclusterizer::WriteClusters(Int_t det) +Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent) { // - // Fills TRDrecPoints branch in TRDrecPoints## tree with rec. points - // found in detector = det. For det=-1 writes the tree. - // For det=-2 recreates the tree. + // Opens a ROOT-file with TRD-hits and reads in the digits-tree // - Char_t treeName[14]; - sprintf(treeName,"TRDrecPoints%d", fEvent); + // Import the Trees for the event nEvent in the file + fRunLoader->GetEvent(nEvent); + + return kTRUE; - if (det == -2) { - fInputFile->Delete(treeName); - TTree *tree = new TTree(treeName,"Tree with TRD rec. points"); - tree->Write(); - return kTRUE; - } +} - //TTree *tree = (TTree *) fInputFile->Get(treeName); - TTree *tree = (TTree *) fInputFile->Get("ClusterTree"); - TBranch *branch = tree->GetBranch("TRDrecPoints"); +//_____________________________________________________________________________ +Bool_t AliTRDclusterizer::WriteClusters(Int_t det) +{ + // + // Fills TRDcluster branch in the tree with the clusters + // found in detector = det. For det=-1 writes the tree. + // - if(!branch) { + if ((det < -1) || + (det >= AliTRDgeometry::Ndet())) { + AliError(Form("Unexpected detector index %d.\n",det)); + return kFALSE; + } + + TBranch *branch = fClusterTree->GetBranch("TRDcluster"); + if (!branch) { TObjArray *ioArray = 0; - branch = tree->Branch("TRDrecPoints","TObjArray",&ioArray,32000,0); + branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0); } - if ((det >= 0) && (det < AliTRDgeometry::Ndet())) { + if ((det >= 0) && + (det < AliTRDgeometry::Ndet())) { - AliTRD *TRD = (AliTRD*) gAlice->GetDetector("TRD"); - Int_t nRecPoints = TRD->RecPoints()->GetEntriesFast(); - TObjArray *fDetRecPoints = new TObjArray(400); + Int_t nRecPoints = RecPoints()->GetEntriesFast(); + TObjArray *detRecPoints = new TObjArray(400); - for (Int_t i=0; iRecPoints()->UncheckedAt(i); - if(det == p->GetDetector()) fDetRecPoints->AddLast(p); - else printf("attempt to write a RecPoint with unexpected detector index"); + for (Int_t i = 0; i < nRecPoints; i++) { + AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i); + if (det == c->GetDetector()) { + detRecPoints->AddLast(c); + } + else { + AliError("Attempt to write a cluster with unexpected detector index\n"); + } } - branch->SetAddress(&fDetRecPoints); - tree->Fill(); + branch->SetAddress(&detRecPoints); + fClusterTree->Fill(); + + delete detRecPoints; + return kTRUE; + } if (det == -1) { - printf("\rAliTRDclusterizer::WriteClusters -- "); - printf("Writing the cluster tree %-18s for event %d.\n" - ,tree->GetName(),fEvent); + AliInfo(Form("Writing the cluster tree %s for event %d." + ,fClusterTree->GetName(),fRunLoader->GetEventNumber())); + + if (fRecPoints) { + + branch->SetAddress(&fRecPoints); + + AliLoader *loader = fRunLoader->GetLoader("TRDLoader"); + loader->WriteRecPoints("OVERWRITE"); + + } + else { + + AliError("Cluster tree does not exist. Cannot write clusters.\n"); + return kFALSE; + + } - tree->Write(); return kTRUE; + } - - printf("\rAliTRDclusterizer::WriteClusters -- "); - printf("Unexpected detector index %d.\n", det); + + AliError(Form("Unexpected detector index %d.\n",det)); + return kFALSE; + +} + +//_____________________________________________________________________________ +Double_t AliTRDclusterizer::CalcXposFromTimebin(Float_t timebin, Int_t idet + , Int_t col, Int_t row) +{ + // + // Calculates the local x position in the detector from the timebin, + // depends on the drift velocity and t0 + // + + AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); + if (!calibration) { + AliError("Cannot find calibration object"); + return -1; + } + AliTRDCommonParam *parCom = AliTRDCommonParam::Instance(); + if (!parCom) { + AliError("Could not get common parameters\n"); + return kFALSE; + } + + Float_t vdrift = calibration->GetVdrift(idet,col,row); + Float_t t0 = calibration->GetT0(idet,col,row); + Float_t samplingFrequency = parCom->GetSamplingFrequency(); + + timebin -= t0; + + return timebin / samplingFrequency * vdrift; + +} + +//_____________________________________________________________________________ +void AliTRDclusterizer::ResetRecPoints() +{ + // + // Resets the list of rec points + // + + if (fRecPoints) { + fRecPoints->Delete(); + } } +//_____________________________________________________________________________ +TObjArray *AliTRDclusterizer::RecPoints() +{ + // + // Returns the list of rec points + // + if (!fRecPoints) { + fRecPoints = new TObjArray(400); + } + + return fRecPoints; +}