]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MONITOR/AliMonitorProcess.cxx
Fixed a memory leakage in the reading of digits for the HLT cluster fitter
[u/mrichter/AliRoot.git] / MONITOR / AliMonitorProcess.cxx
index 25d5222ff1133a9946319fa2e5373dd97a9bd66e..1bc5f0c24a38d016bbf5deb4824883e56cce79bc 100644 (file)
@@ -31,6 +31,7 @@
 #include "AliMonitorITS.h"
 #include "AliMonitorV0s.h"
 #include "AliMonitorHLT.h"
+#include "AliMonitorHLTHough.h"
 #include "AliRawReaderRoot.h"
 #include "AliLoader.h"
 #include "AliRun.h"
 #include "AliITStrackerV2.h"
 #include "AliITSLoader.h"
 #include "AliV0vertexer.h"
-#include <TSystem.h>
+#include <TGrid.h>
 #include <TSocket.h>
+#include <TServerSocket.h>
 #include <TMessage.h>
 #include <TGridResult.h>
 #include <TROOT.h>
 #ifdef ALI_HLT
+#include <AliLevel3.h>
 #include <AliL3Transform.h>
+#include <AliL3Track.h>
+#include <AliL3TrackArray.h>
+#include <AliL3StandardIncludes.h>
+#include <AliL3HoughMaxFinder.h>
+#include <AliL3HoughBaseTransformer.h>
+#include <AliL3Hough.h>
+#include <AliL3ClusterFitter.h>
+#include <AliL3Vertex.h>
+#include <AliL3Fitter.h>
+#include <AliL3DDLDataFileHandler.h>
 #endif
 
 ClassImp(AliMonitorProcess) 
 
 
-const Int_t AliMonitorProcess::kgPort = 9327;
+const Int_t AliMonitorProcess::fgkPort = 9327;
 
 
 //_____________________________________________________________________________
-AliMonitorProcess::AliMonitorProcess(const char* alienDir,
+AliMonitorProcess::AliMonitorProcess(
+#if ROOT_VERSION_CODE <= 199169   // 3.10/01
+                                    const char* /*alienHost*/,
+#else
+                                    const char* alienHost,
+#endif
+                                    const char* alienDir,
                                     const char* fileNameGalice)
 {
 // initialize the monitoring process and the monitor histograms
 
+#if ROOT_VERSION_CODE <= 199169   // 3.10/01
   fGrid = TGrid::Connect("alien", gSystem->Getenv("USER"));
+#else
+  fGrid = TGrid::Connect(alienHost, gSystem->Getenv("USER"));
+#endif
   if (!fGrid || fGrid->IsZombie() || !fGrid->IsConnected()) {
     delete fGrid;
     Fatal("AliMonitorProcess", "could not connect to alien");
   }
+#if ROOT_VERSION_CODE <= 199169   // 3.10/01
   fGrid->cd(alienDir);
+#else
+  fAlienDir = alienDir;
+#endif
   fLogicalFileName = "";
   fFileName = "";
 
@@ -84,9 +111,9 @@ AliMonitorProcess::AliMonitorProcess(const char* alienDir,
   fRunLoader->LoadgAlice();
   gAlice = fRunLoader->GetAliRun();
   if (!gAlice) Fatal("AliMonitorProcess", "no gAlice object found");
-  AliITS* ITS = (AliITS*) gAlice->GetModule("ITS");
-  if (!ITS) Fatal("AliMonitorProcess", "no ITS detector found");
-  fITSgeom = ITS->GetITSgeom();
+  AliITS* its = (AliITS*) gAlice->GetModule("ITS");
+  if (!its) Fatal("AliMonitorProcess", "no ITS detector found");
+  fITSgeom = its->GetITSgeom();
   if (!fITSgeom) Fatal("AliMonitorProcess", "could not load ITS geometry");
 
 #ifdef ALI_HLT
@@ -101,7 +128,7 @@ AliMonitorProcess::AliMonitorProcess(const char* alienDir,
   fRunNumber = 0;
   fSubRunNumber = 0;
   fNEvents = 0;
-  fNEventsMin = 2;
+  fNEventsMin = 1;
   fWriteHistoList = kFALSE;
 
   fTopFolder = new TFolder("Monitor", "monitor histograms");
@@ -112,6 +139,7 @@ AliMonitorProcess::AliMonitorProcess(const char* alienDir,
   fMonitors.Add(new AliMonitorV0s);
 #ifdef ALI_HLT
   fMonitors.Add(new AliMonitorHLT(fTPCParam));
+  fMonitors.Add(new AliMonitorHLTHough(fTPCParam));
 #endif
 
   for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
@@ -132,7 +160,7 @@ AliMonitorProcess::AliMonitorProcess(const char* alienDir,
   }
   gROOT->cd();
 
-  fServerSocket = new TServerSocket(kgPort, kTRUE);
+  fServerSocket = new TServerSocket(fgkPort, kTRUE);
   fServerSocket->SetOption(kNoBlock, 1);
   fDisplaySocket = NULL;
   CheckForConnections();
@@ -144,6 +172,21 @@ AliMonitorProcess::AliMonitorProcess(const char* alienDir,
   fStopping = kFALSE;
 }
 
+//_____________________________________________________________________________
+AliMonitorProcess::AliMonitorProcess(const AliMonitorProcess& process) :
+  TObject(process)
+{
+  Fatal("AliMonitorProcess", "copy constructor not implemented");
+}
+
+//_____________________________________________________________________________
+AliMonitorProcess& AliMonitorProcess::operator = (const AliMonitorProcess& 
+                                                 /*process*/)
+{
+  Fatal("operator =", "assignment operator not implemented");
+  return *this;
+}
+
 //_____________________________________________________________________________
 AliMonitorProcess::~AliMonitorProcess()
 {
@@ -157,7 +200,9 @@ AliMonitorProcess::~AliMonitorProcess()
   fSockets.Delete();
   delete fDisplaySocket;
 
+#if ROOT_VERSION_CODE <= 199169   // 3.10/01
   fGrid->Close();
+#endif
   delete fGrid;
 
   fFile->Close();
@@ -166,6 +211,7 @@ AliMonitorProcess::~AliMonitorProcess()
 
 #ifdef ALI_HLT
   delete fHLT;
+  delete fHLTHough;
 #endif
 }
 
@@ -180,6 +226,8 @@ const char* AliMonitorProcess::GetRevision()
 //_____________________________________________________________________________
 void AliMonitorProcess::SetStatus(EStatus status)
 {
+// set the current status and process system events
+
   fStatus = status;
   gSystem->ProcessEvents();
 }
@@ -249,12 +297,27 @@ Bool_t AliMonitorProcess::CheckForNewFile()
 {
 // check whether a new file was registered in alien
 
+#if ROOT_VERSION_CODE <= 199169   // 3.10/01
   TGridResult* result = fGrid->Ls();
+#else
+  Grid_ResultHandle_t handle = fGrid->OpenDir(fAlienDir);
+  if (!handle) {
+    Error("CheckForNewFile", "could not open alien directory %s", 
+         fAlienDir.Data());
+    return kFALSE;
+  }
+  TGridResult* result = fGrid->CreateGridResult(handle);
+#endif
   Long_t maxDate = -1;
   Long_t maxTime = -1;
   TString fileName;
 
+#if ROOT_VERSION_CODE <= 199169   // 3.10/01
   while (const char* entry = result->Next()) {
+#else
+  while (Grid_Result_t* resultEntry = result->Next()) {
+    const char* entry = resultEntry->name.c_str();
+#endif
     // entry = host_date_time.root
     TString entryCopy(entry);
     char* p = const_cast<char*>(entryCopy.Data());
@@ -273,12 +336,34 @@ Bool_t AliMonitorProcess::CheckForNewFile()
     }
   }
 
+  delete result;
   if (maxDate < 0) return kFALSE;  // no files found
   if (fLogicalFileName.CompareTo(fileName) == 0) return kFALSE;  // no new file
 
   fLogicalFileName = fileName;
-  TGridResult* result2 = fGrid->GetPhysicalFileNames(fLogicalFileName.Data());
-  fFileName = result2->Next();
+#if ROOT_VERSION_CODE <= 199169   // 3.10/01
+  result = fGrid->GetPhysicalFileNames(fLogicalFileName.Data());
+  fFileName = result->Next();
+#else
+  fileName = fAlienDir + "/" + fLogicalFileName;
+  handle = fGrid->GetPhysicalFileNames(fileName.Data());
+  if (!handle) {
+    Error("CheckForNewFile", "could not get physical file names for %s", 
+         fileName.Data());
+    return kFALSE;
+  }
+  result = fGrid->CreateGridResult(handle);
+  result->Reset();
+  Grid_Result_t* resultEntry = result->Next();
+  if (!resultEntry) {
+    Error("CheckForNewFile", "could not get physical file names for %s", 
+         fileName.Data());
+    return kFALSE;
+  }
+  fFileName = resultEntry->name2.c_str();
+  fFileName.ReplaceAll("castor:/", "rfio:/");
+#endif
+  delete result;
 
   return kTRUE;
 }
@@ -295,6 +380,7 @@ Bool_t AliMonitorProcess::ProcessFile()
        nEvents, fFileName.Data());
 #ifdef ALI_HLT
   CreateHLT(fFileName);
+  CreateHLTHough(fFileName);
 #endif
 
   // loop over the events
@@ -313,6 +399,10 @@ Bool_t AliMonitorProcess::ProcessFile()
       if (fStopping) break;
     }
 
+    // monitor only central physics events
+    if (rawReader.GetType() != 7) continue;
+    if ((rawReader.GetAttributes()[0] & 0x02) == 0) continue;
+
     if (!ReconstructTPC(&rawReader)) return kFALSE;
     if (fStopping) break;
     if (!ReconstructITS(&rawReader)) return kFALSE;
@@ -321,6 +411,8 @@ Bool_t AliMonitorProcess::ProcessFile()
     if (fStopping) break;
     if (!ReconstructHLT(iEvent)) return kFALSE;
     if (fStopping) break;
+    if (!ReconstructHLTHough(iEvent)) return kFALSE;
+    if (fStopping) break;
 
     if (fDisplaySocket) fDisplaySocket->Send("new event");
 
@@ -377,7 +469,7 @@ void AliMonitorProcess::Reset()
 
 
 //_____________________________________________________________________________
-UInt_t AliMonitorProcess::GetEventPeriodNumber()
+UInt_t AliMonitorProcess::GetEventPeriodNumber() const
 {
 // get the period number from the event id
 
@@ -385,7 +477,7 @@ UInt_t AliMonitorProcess::GetEventPeriodNumber()
 }
 
 //_____________________________________________________________________________
-UInt_t AliMonitorProcess::GetEventOrbitNumber()
+UInt_t AliMonitorProcess::GetEventOrbitNumber() const
 {
 // get the orbit number from the event id
 
@@ -393,7 +485,7 @@ UInt_t AliMonitorProcess::GetEventOrbitNumber()
 }
 
 //_____________________________________________________________________________
-UInt_t AliMonitorProcess::GetEventBunchNumber()
+UInt_t AliMonitorProcess::GetEventBunchNumber() const
 {
 // get the bunch number from the event id
 
@@ -401,7 +493,7 @@ UInt_t AliMonitorProcess::GetEventBunchNumber()
 }
 
 //_____________________________________________________________________________
-Int_t AliMonitorProcess::GetNumberOfEvents(const char* fileName)
+Int_t AliMonitorProcess::GetNumberOfEvents(const char* fileName) const
 {
 // determine the number of events in the given raw data file
 
@@ -555,30 +647,51 @@ void AliMonitorProcess::CreateHLT(const char* fileName)
   fHLT = new AliLevel3(name);
   fHLT->Init("./", AliLevel3::kRaw, 1);
 
-  fHLT->SetClusterFinderParam(0, 0, kTRUE);
+  fHLT->SetClusterFinderParam(-1, -1, kTRUE);
   
-  Int_t phi_segments = 50;
-  Int_t eta_segments = 100;
+  Int_t phiSegments = 50;
+  Int_t etaSegments = 100;
   Int_t trackletlength = 3;
-  Int_t tracklength = 40;//40 or 5
+  Int_t tracklength = 20;//40 or 5
   Int_t rowscopetracklet = 2;
-  Int_t rowscopetrack = 2;
-  Double_t min_pt_fit = 0;
-  Double_t maxangle = 1.31;
+  Int_t rowscopetrack = 10;
+  Double_t minPtFit = 0;
+  Double_t maxangle = 0.1745;
   Double_t goodDist = 5;
-  Double_t maxphi = 100;
-  Double_t maxeta = 100;
+  Double_t maxphi = 0.1;
+  Double_t maxeta = 0.1;
   Double_t hitChi2Cut = 15;//100 or 15
   Double_t goodHitChi2 = 5;//20 or 5
   Double_t trackChi2Cut = 10;//50 or 10
-  fHLT->SetTrackerParam(phi_segments, eta_segments, 
+  fHLT->SetTrackerParam(phiSegments, etaSegments, 
                        trackletlength, tracklength,
                        rowscopetracklet, rowscopetrack,
-                       min_pt_fit, maxangle, goodDist, hitChi2Cut,
+                       minPtFit, maxangle, goodDist, hitChi2Cut,
                        goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kTRUE);
   
   fHLT->WriteFiles("./hlt/");  
 }
+
+//_____________________________________________________________________________
+void AliMonitorProcess::CreateHLTHough(const char* fileName)
+{
+
+// create the HLT Hough transform (L3Hough) object
+
+  if (fHLTHough) delete fHLTHough;
+
+  char name[256];
+  strcpy(name, fileName);
+
+  fHLTHough = new AliL3Hough();
+  fHLTHough->SetThreshold(4);
+  fHLTHough->SetTransformerParams(140,150,0.5,-1);
+  fHLTHough->SetPeakThreshold(9000,-1);// or 6000
+  fHLTHough->Init("./", kFALSE, 50, kFALSE,0,name);
+  fHLTHough->SetAddHistograms();
+  //  fHLTHough->GetMaxFinder()->SetThreshold(14000);
+
+}
 #endif
 
 //_____________________________________________________________________________
@@ -619,6 +732,114 @@ Bool_t AliMonitorProcess::ReconstructHLT(
 #endif
 }
 
+//_____________________________________________________________________________
+Bool_t AliMonitorProcess::ReconstructHLTHough(
+#ifdef ALI_HLT
+  Int_t iEvent
+#else
+  Int_t /* iEvent */
+#endif
+)
+{
+// run the HLT Hough transformer
+
+  SetStatus(kRecHLT);
+
+#ifndef ALI_HLT
+  Warning("ReconstructHLTHough", "the code was compiled without HLT support");
+  return kTRUE;
+
+#else
+  gSystem->Exec("rm -rf hlt/hough");
+  gSystem->MakeDirectory("hlt/hough");
+  gSystem->Exec("rm -rf hlt/fitter");
+  gSystem->MakeDirectory("hlt/fitter");
+  if (!fHLTHough) return kFALSE;
+
+  //  fHLTHough->Process(0, 35);
+  // Loop over TPC sectors and process the data
+  for(Int_t i=0; i<=35; i++)
+    {
+      fHLTHough->ReadData(i,iEvent);
+      fHLTHough->Transform();
+      //      if(fHLTHough->fAddHistograms)
+      fHLTHough->AddAllHistograms();
+      fHLTHough->FindTrackCandidates();
+      fHLTHough->AddTracks();
+    }
+  fHLTHough->WriteTracks("./hlt/hough");
+
+  // Run cluster fitter
+  AliL3ClusterFitter *fitter = new AliL3ClusterFitter("./hlt");
+
+  // Set debug flag for the cluster fitter
+  //  fitter->Debug();
+
+  // Setting fitter parameters
+  fitter->SetInnerWidthFactor(1,1.5);
+  fitter->SetOuterWidthFactor(1,1.5);
+  fitter->SetNmaxOverlaps(5);
+  
+  //fitter->SetChiSqMax(5,kFALSE); //isolated clusters
+  fitter->SetChiSqMax(5,kTRUE);  //overlapping clusters
+
+  Int_t rowrange[2] = {0,AliL3Transform::GetNRows()-1};
+
+  // Takes input from global hough tracks produced by HT
+  fitter->LoadSeeds(rowrange,kFALSE,iEvent);
+
+  UInt_t ndigits;
+
+  for(Int_t islice = 0; islice <= 35; islice++)
+    {
+      for(Int_t ipatch = 0; ipatch < AliL3Transform::GetNPatches(); ipatch++)
+       {
+         // Read digits
+         fHLTHough->GetMemHandler(ipatch)->Free();
+         fHLTHough->GetMemHandler(ipatch)->Init(islice,ipatch);
+         AliL3DigitRowData *digits = (AliL3DigitRowData *)fHLTHough->GetMemHandler(ipatch)->AliAltroDigits2Memory(ndigits,iEvent);
+
+         fitter->Init(islice,ipatch);
+         fitter->SetInputData(digits);
+         fitter->FindClusters();
+         fitter->WriteClusters();
+       }
+    }
+
+  // Refit of the clusters
+  AliL3Vertex vertex;
+  //The seeds are the input tracks from circle HT
+  AliL3TrackArray *tracks = fitter->GetSeeds();
+  AliL3Fitter *ft = new AliL3Fitter(&vertex,1);
+
+  ft->LoadClusters("./hlt/fitter/",iEvent,kFALSE);
+  for(Int_t i=0; i<tracks->GetNTracks(); i++)
+    {
+      AliL3Track *track = tracks->GetCheckedTrack(i);
+      if(!track) continue;
+      if(track->GetNHits() < 20) continue;
+      ft->SortTrackClusters(track);
+      ft->FitHelix(track);
+      ft->UpdateTrack(track);
+    }
+  delete ft;
+        
+  //Write the final tracks
+  fitter->WriteTracks(20);
+
+  delete fitter;
+
+  // remove the event number from the file names
+  char command[256];
+  sprintf(command, "rename tracks_%d tracks hlt/hough/*.raw", iEvent);
+  gSystem->Exec(command);
+  sprintf(command, "rename tracks_%d tracks hlt/fitter/*.raw", iEvent);
+  gSystem->Exec(command);
+  sprintf(command, "rename points_%d points hlt/fitter/*.raw", iEvent);
+  gSystem->Exec(command);
+  return kTRUE;
+#endif
+}
 
 //_____________________________________________________________________________
 Bool_t AliMonitorProcess::WriteHistos()