]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MONITOR/AliMonitorProcess.cxx
Corrected index
[u/mrichter/AliRoot.git] / MONITOR / AliMonitorProcess.cxx
CommitLineData
04fa961a 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// This is the class for perfoming the monitoring process. //
21// It checks if a raw data file exists, loops over the events in the raw //
22// data file, reconstructs TPC and ITS clusters and tracks, fills the //
23// monitor histograms and sends the updated histograms to the clients. //
24// Then the raw data file is deleted and it waits for a new file. //
25// //
26///////////////////////////////////////////////////////////////////////////////
27
28
29#include "AliMonitorProcess.h"
30#include "AliMonitorTPC.h"
31#include "AliMonitorITS.h"
32#include "AliMonitorV0s.h"
97d6eb66 33#include "AliMonitorHLT.h"
c6ba6205 34#include "AliMonitorHLTHough.h"
04fa961a 35#include "AliRawReaderRoot.h"
36#include "AliLoader.h"
37#include "AliRun.h"
38#include "AliTPC.h"
39#include "AliTPCclustererMI.h"
40#include "AliTPCtrackerMI.h"
41#include "AliITS.h"
42#include "AliITSclustererV2.h"
43#include "AliITStrackerV2.h"
44#include "AliITSLoader.h"
45#include "AliV0vertexer.h"
c4bd737c 46#include <TGrid.h>
04fa961a 47#include <TSocket.h>
c4bd737c 48#include <TServerSocket.h>
04fa961a 49#include <TMessage.h>
50#include <TGridResult.h>
51#include <TROOT.h>
1899848d 52#ifdef ALI_HLT
c4bd737c 53#include <AliLevel3.h>
1899848d 54#include <AliL3Transform.h>
4a69f9c7 55#include <AliL3Track.h>
56#include <AliL3TrackArray.h>
c6ba6205 57#include <AliL3StandardIncludes.h>
58#include <AliL3HoughMaxFinder.h>
4a69f9c7 59#include <AliL3HoughBaseTransformer.h>
c6ba6205 60#include <AliL3Hough.h>
4a69f9c7 61#include <AliL3ClusterFitter.h>
62#include <AliL3Vertex.h>
63#include <AliL3Fitter.h>
8aad0cd3 64#include <AliL3DDLDataFileHandler.h>
1899848d 65#endif
04fa961a 66
67ClassImp(AliMonitorProcess)
68
69
c4bd737c 70const Int_t AliMonitorProcess::fgkPort = 9327;
04fa961a 71
72
73//_____________________________________________________________________________
807ee5a3 74AliMonitorProcess::AliMonitorProcess(
75#if ROOT_VERSION_CODE <= 199169 // 3.10/01
76 const char* /*alienHost*/,
77#else
78 const char* alienHost,
79#endif
80 const char* alienDir,
04fa961a 81 const char* fileNameGalice)
82{
83// initialize the monitoring process and the monitor histograms
84
807ee5a3 85#if ROOT_VERSION_CODE <= 199169 // 3.10/01
04fa961a 86 fGrid = TGrid::Connect("alien", gSystem->Getenv("USER"));
807ee5a3 87#else
88 fGrid = TGrid::Connect(alienHost, gSystem->Getenv("USER"));
89#endif
04fa961a 90 if (!fGrid || fGrid->IsZombie() || !fGrid->IsConnected()) {
91 delete fGrid;
92 Fatal("AliMonitorProcess", "could not connect to alien");
93 }
807ee5a3 94#if ROOT_VERSION_CODE <= 199169 // 3.10/01
04fa961a 95 fGrid->cd(alienDir);
807ee5a3 96#else
97 fAlienDir = alienDir;
98#endif
04fa961a 99 fLogicalFileName = "";
100 fFileName = "";
101
102 fRunLoader = AliRunLoader::Open(fileNameGalice);
103 if (!fRunLoader) Fatal("AliMonitorProcess",
104 "could not get run loader from file %s",
105 fileNameGalice);
106
107 fRunLoader->CdGAFile();
108 fTPCParam = AliTPC::LoadTPCParam(gFile);
109 if (!fTPCParam) Fatal("AliMonitorProcess", "could not load TPC parameters");
110
111 fRunLoader->LoadgAlice();
112 gAlice = fRunLoader->GetAliRun();
113 if (!gAlice) Fatal("AliMonitorProcess", "no gAlice object found");
c4bd737c 114 AliITS* its = (AliITS*) gAlice->GetModule("ITS");
115 if (!its) Fatal("AliMonitorProcess", "no ITS detector found");
116 fITSgeom = its->GetITSgeom();
04fa961a 117 if (!fITSgeom) Fatal("AliMonitorProcess", "could not load ITS geometry");
118
1899848d 119#ifdef ALI_HLT
120// Init TPC parameters for HLT
121 Bool_t isinit=AliL3Transform::Init(const_cast<char*>(fileNameGalice),kTRUE);
122 if(!isinit){
123 cerr << "Could not create transform settings, please check log for error messages!" << endl;
124 return;
125 }
126#endif
127
04fa961a 128 fRunNumber = 0;
129 fSubRunNumber = 0;
130 fNEvents = 0;
131 fNEventsMin = 2;
132 fWriteHistoList = kFALSE;
133
134 fTopFolder = new TFolder("Monitor", "monitor histograms");
135 fTopFolder->SetOwner(kTRUE);
136
137 fMonitors.Add(new AliMonitorTPC(fTPCParam));
138 fMonitors.Add(new AliMonitorITS(fITSgeom));
139 fMonitors.Add(new AliMonitorV0s);
97d6eb66 140#ifdef ALI_HLT
141 fMonitors.Add(new AliMonitorHLT(fTPCParam));
c6ba6205 142 fMonitors.Add(new AliMonitorHLTHough(fTPCParam));
97d6eb66 143#endif
04fa961a 144
145 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
146 ((AliMonitor*) fMonitors[iMonitor])->CreateHistos(fTopFolder);
147 }
148
149 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
150 while (TFolder* folder = (TFolder*) iFolder->Next()) folder->SetOwner(kTRUE);
151 delete iFolder;
152
153 fFile = TFile::Open("monitor_tree.root", "RECREATE");
154 if (!fFile || !fFile->IsOpen()) {
155 Fatal("AliMonitorProcess", "could not open file for tree");
156 }
157 fTree = new TTree("MonitorTree", "tree for monitoring");
158 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
159 ((AliMonitor*) fMonitors[iMonitor])->CreateBranches(fTree);
160 }
161 gROOT->cd();
162
c4bd737c 163 fServerSocket = new TServerSocket(fgkPort, kTRUE);
04fa961a 164 fServerSocket->SetOption(kNoBlock, 1);
165 fDisplaySocket = NULL;
166 CheckForConnections();
97d6eb66 167#ifdef ALI_HLT
168 fHLT = NULL;
169#endif
04fa961a 170
1899848d 171 SetStatus(kStopped);
04fa961a 172 fStopping = kFALSE;
173}
174
c4bd737c 175//_____________________________________________________________________________
176AliMonitorProcess::AliMonitorProcess(const AliMonitorProcess& process) :
177 TObject(process)
178{
179 Fatal("AliMonitorProcess", "copy constructor not implemented");
180}
181
182//_____________________________________________________________________________
183AliMonitorProcess& AliMonitorProcess::operator = (const AliMonitorProcess&
184 /*process*/)
185{
186 Fatal("operator =", "assignment operator not implemented");
187 return *this;
188}
189
04fa961a 190//_____________________________________________________________________________
191AliMonitorProcess::~AliMonitorProcess()
192{
193// clean up
194
195 fMonitors.Delete();
196 delete fTopFolder;
197 delete fRunLoader;
198
199 delete fServerSocket;
200 fSockets.Delete();
201 delete fDisplaySocket;
202
807ee5a3 203#if ROOT_VERSION_CODE <= 199169 // 3.10/01
04fa961a 204 fGrid->Close();
807ee5a3 205#endif
04fa961a 206 delete fGrid;
207
208 fFile->Close();
209 delete fFile;
210 gSystem->Unlink("monitor_tree.root");
97d6eb66 211
212#ifdef ALI_HLT
213 delete fHLT;
4a69f9c7 214 delete fHLTHough;
97d6eb66 215#endif
04fa961a 216}
217
218
219//_____________________________________________________________________________
220const char* AliMonitorProcess::GetRevision()
221{
222 return "$Revision$";
223}
224
225
1899848d 226//_____________________________________________________________________________
227void AliMonitorProcess::SetStatus(EStatus status)
228{
c4bd737c 229// set the current status and process system events
230
1899848d 231 fStatus = status;
232 gSystem->ProcessEvents();
233}
234
235
04fa961a 236//_____________________________________________________________________________
237void AliMonitorProcess::Run()
238{
239// run the monitor process:
240// check for a raw data file, process the raw data file and delete it
241
242 fStopping = kFALSE;
243
244 while (!fStopping) {
1899848d 245 SetStatus(kWaiting);
04fa961a 246 while (!CheckForNewFile()) {
247 CheckForConnections();
1899848d 248 SetStatus(kWaiting);
04fa961a 249 if (fStopping) break;
250 gSystem->Sleep(10);
251 }
252 if (fStopping) break;
253
254 ProcessFile();
255 }
256
257 WriteHistos();
258
259 fStopping = kFALSE;
1899848d 260 SetStatus(kStopped);
04fa961a 261}
262
263
264//_____________________________________________________________________________
265void AliMonitorProcess::Stop()
266{
267// set the fStopping flag to terminate the monitor process after the current
268// event was processed
269
1899848d 270 if (GetStatus() != kStopped) fStopping = kTRUE;
04fa961a 271}
272
273
274//_____________________________________________________________________________
275void AliMonitorProcess::ProcessFile(const char* fileName)
276{
277// create a file with monitor histograms for a single file
278
1899848d 279 if (GetStatus() != kStopped) {
04fa961a 280 Error("ProcessFile", "ProcessFile can not be called"
281 " while the monitor process is running");
282 return;
283 }
284
285 fFileName = fileName;
286 Int_t nEventMin = fNEventsMin;
287 fNEventsMin = 1;
288 ProcessFile();
289 WriteHistos();
290 fNEventsMin = nEventMin;
1899848d 291 SetStatus(kStopped);
04fa961a 292}
293
294
295//_____________________________________________________________________________
296Bool_t AliMonitorProcess::CheckForNewFile()
297{
298// check whether a new file was registered in alien
299
807ee5a3 300#if ROOT_VERSION_CODE <= 199169 // 3.10/01
04fa961a 301 TGridResult* result = fGrid->Ls();
807ee5a3 302#else
303 Grid_ResultHandle_t handle = fGrid->OpenDir(fAlienDir);
304 if (!handle) {
305 Error("CheckForNewFile", "could not open alien directory %s",
306 fAlienDir.Data());
307 return kFALSE;
308 }
309 TGridResult* result = fGrid->CreateGridResult(handle);
310#endif
04fa961a 311 Long_t maxDate = -1;
312 Long_t maxTime = -1;
313 TString fileName;
314
807ee5a3 315#if ROOT_VERSION_CODE <= 199169 // 3.10/01
04fa961a 316 while (const char* entry = result->Next()) {
807ee5a3 317#else
318 while (Grid_Result_t* resultEntry = result->Next()) {
319 const char* entry = resultEntry->name.c_str();
320#endif
04fa961a 321 // entry = host_date_time.root
322 TString entryCopy(entry);
323 char* p = const_cast<char*>(entryCopy.Data());
6ad9b9d5 324 if (!strtok(p, "_") || !p) continue; // host name
97d6eb66 325 char* dateStr = strtok(NULL, "_");
04fa961a 326 if (!dateStr || !p) continue;
97d6eb66 327 char* timeStr = strtok(NULL, ".");
04fa961a 328 if (!timeStr || !p) continue;
329 Long_t date = atoi(dateStr);
330 Long_t time = atoi(timeStr);
331
332 if ((date > maxDate) || ((date == maxDate) && (time > maxTime))) {
333 maxDate = date;
334 maxTime = time;
335 fileName = entry;
336 }
337 }
338
807ee5a3 339 delete result;
04fa961a 340 if (maxDate < 0) return kFALSE; // no files found
341 if (fLogicalFileName.CompareTo(fileName) == 0) return kFALSE; // no new file
342
343 fLogicalFileName = fileName;
807ee5a3 344#if ROOT_VERSION_CODE <= 199169 // 3.10/01
345 result = fGrid->GetPhysicalFileNames(fLogicalFileName.Data());
346 fFileName = result->Next();
347#else
348 handle = fGrid->GetPhysicalFileNames(fLogicalFileName.Data());
349 if (!handle) {
350 Error("CheckForNewFile", "could not get physical file names for %s",
351 fLogicalFileName.Data());
352 return kFALSE;
353 }
354 result = fGrid->CreateGridResult(handle);
355 Grid_Result_t* resultEntry = result->Next();
356 if (!resultEntry) {
357 Error("CheckForNewFile", "could not get physical file names for %s",
358 fLogicalFileName.Data());
359 return kFALSE;
360 }
389567d6 361 fFileName = resultEntry->name2.c_str();
807ee5a3 362#endif
363 delete result;
1899848d 364
04fa961a 365 return kTRUE;
366}
367
368//_____________________________________________________________________________
369Bool_t AliMonitorProcess::ProcessFile()
370{
371// loop over all events in the raw data file, run the reconstruction
372// and fill the monitor histograms
373
374 Int_t nEvents = GetNumberOfEvents(fFileName);
375 if (nEvents <= 0) return kFALSE;
376 Info("ProcessFile", "found %d event(s) in file %s",
377 nEvents, fFileName.Data());
97d6eb66 378#ifdef ALI_HLT
379 CreateHLT(fFileName);
c6ba6205 380 CreateHLTHough(fFileName);
97d6eb66 381#endif
04fa961a 382
383 // loop over the events
384 for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
1899848d 385 SetStatus(kReading);
04fa961a 386 fRunLoader->SetEventNumber(0);
387 AliRawReaderRoot rawReader(fFileName, iEvent);
388 if (fStopping) break;
389 if (rawReader.GetRunNumber() != fRunNumber) {
390 WriteHistos();
391 StartNewRun();
392 fRunNumber = rawReader.GetRunNumber();
393 fEventNumber[0] = rawReader.GetEventId()[0];
394 fEventNumber[1] = rawReader.GetEventId()[1];
395 fSubRunNumber = 0;
396 if (fStopping) break;
397 }
398
399 if (!ReconstructTPC(&rawReader)) return kFALSE;
400 if (fStopping) break;
401 if (!ReconstructITS(&rawReader)) return kFALSE;
402 if (fStopping) break;
403 if (!ReconstructV0s()) return kFALSE;
404 if (fStopping) break;
97d6eb66 405 if (!ReconstructHLT(iEvent)) return kFALSE;
406 if (fStopping) break;
c6ba6205 407 if (!ReconstructHLTHough(iEvent)) return kFALSE;
408 if (fStopping) break;
04fa961a 409
410 if (fDisplaySocket) fDisplaySocket->Send("new event");
411
412 Info("ProcessFile", "filling histograms...");
1899848d 413 SetStatus(kFilling);
04fa961a 414 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
415 ((AliMonitor*) fMonitors[iMonitor])->FillHistos(fRunLoader, &rawReader);
416 if (fStopping) break;
417 }
418 if (fStopping) break;
419
420 Info("ProcessFile", "updating histograms...");
1899848d 421 SetStatus(kUpdating);
04fa961a 422 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
423 while (TFolder* folder = (TFolder*) iFolder->Next()) {
424 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
425 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
426 histo->Update();
427 }
428 delete iHisto;
429 }
430 delete iFolder;
431 if (fStopping) break;
432
433 Info("ProcessFile", "filling the tree...");
434 fTree->Fill();
435
436 Info("ProcessFile", "broadcasting histograms...");
437 CheckForConnections();
438 BroadcastHistos();
439
440 fNEvents++;
441 if (fStopping) break;
442 }
443
97d6eb66 444#ifdef ALI_HLT
445 delete fHLT;
446 fHLT = NULL;
447#endif
448
04fa961a 449 return kTRUE;
450}
451
452//_____________________________________________________________________________
453void AliMonitorProcess::Reset()
454{
455// write the current histograms to a file and reset them
456
457 if (fSubRunNumber == 0) fSubRunNumber++;
458 WriteHistos();
459 StartNewRun();
460 fSubRunNumber++;
461}
462
463
464//_____________________________________________________________________________
c4bd737c 465UInt_t AliMonitorProcess::GetEventPeriodNumber() const
04fa961a 466{
467// get the period number from the event id
468
469 return (fEventNumber[1] >> 4);
470}
471
472//_____________________________________________________________________________
c4bd737c 473UInt_t AliMonitorProcess::GetEventOrbitNumber() const
04fa961a 474{
475// get the orbit number from the event id
476
477 return ((fEventNumber[1] & 0x000F) << 20) + (fEventNumber[0] >> 12);
478}
479
480//_____________________________________________________________________________
c4bd737c 481UInt_t AliMonitorProcess::GetEventBunchNumber() const
04fa961a 482{
483// get the bunch number from the event id
484
485 return (fEventNumber[0] % 0x0FFF);
486}
487
488//_____________________________________________________________________________
c4bd737c 489Int_t AliMonitorProcess::GetNumberOfEvents(const char* fileName) const
04fa961a 490{
491// determine the number of events in the given raw data file
492
493 Int_t nEvents = -1;
494
495 TFile* file = TFile::Open(fileName);
496 if (!file || !file->IsOpen()) {
497 Error("GetNumberOfEvents", "could not open file %s", fileName);
498 if (file) delete file;
499 return -1;
500 }
501
502 TTree* tree = (TTree*) file->Get("RAW");
503 if (!tree) {
504 Error("GetNumberOfEvents", "could not find tree with raw data");
505 } else {
506 nEvents = (Int_t) tree->GetEntries();
507 }
508 file->Close();
509 delete file;
510
511 return nEvents;
512}
513
514//_____________________________________________________________________________
515Bool_t AliMonitorProcess::ReconstructTPC(AliRawReader* rawReader)
516{
517// find TPC clusters and tracks
518
1899848d 519 SetStatus(kRecTPC);
04fa961a 520
521 AliLoader* tpcLoader = fRunLoader->GetLoader("TPCLoader");
522 if (!tpcLoader) {
523 Error("ReconstructTPC", "no TPC loader found");
524 return kFALSE;
525 }
526 gSystem->Unlink("TPC.RecPoints.root");
527 gSystem->Unlink("TPC.Tracks.root");
528
529 // cluster finder
530 Info("ReconstructTPC", "reconstructing clusters...");
531 tpcLoader->LoadRecPoints("recreate");
532 AliTPCclustererMI clusterer(fTPCParam);
533 tpcLoader->MakeRecPointsContainer();
534 clusterer.SetOutput(tpcLoader->TreeR());
535 clusterer.Digits2Clusters(rawReader);
536 tpcLoader->WriteRecPoints("OVERWRITE");
537
538 // track finder
539 Info("ReconstructTPC", "reconstructing tracks...");
540 tpcLoader->LoadTracks("recreate");
541 {
542 AliTPCtrackerMI tracker(fTPCParam);
543 tracker.Clusters2Tracks();
544 }
545
546 tpcLoader->UnloadRecPoints();
547 tpcLoader->UnloadTracks();
548 return kTRUE;
549}
550
551//_____________________________________________________________________________
552Bool_t AliMonitorProcess::ReconstructITS(AliRawReader* rawReader)
553{
554// find ITS clusters and tracks
555
1899848d 556 SetStatus(kRecITS);
04fa961a 557
558 AliLoader* itsLoader = fRunLoader->GetLoader("ITSLoader");
559 if (!itsLoader) {
560 Error("ReconstructITS", "no ITS loader found");
561 return kFALSE;
562 }
563 AliLoader* tpcLoader = fRunLoader->GetLoader("TPCLoader");
564 if (!tpcLoader) {
565 Error("ReconstructITS", "no TPC loader found");
566 return kFALSE;
567 }
568 gSystem->Unlink("ITS.RecPoints.root");
569 gSystem->Unlink("ITS.Tracks.root");
570
571 // cluster finder
572 Info("ReconstructITS", "reconstructing clusters...");
573 itsLoader->LoadRecPoints("recreate");
574 AliITSclustererV2 clusterer(fITSgeom);
575 itsLoader->MakeRecPointsContainer();
576 clusterer.Digits2Clusters(rawReader);
577
578 // track finder
579 Info("ReconstructITS", "reconstructing tracks...");
580 itsLoader->LoadTracks("recreate");
581 itsLoader->MakeTracksContainer();
582 tpcLoader->LoadTracks();
583 AliITStrackerV2 tracker(fITSgeom);
584 tracker.LoadClusters(itsLoader->TreeR());
585 tracker.Clusters2Tracks(tpcLoader->TreeT(), itsLoader->TreeT());
586 tracker.UnloadClusters();
587 itsLoader->WriteTracks("OVERWRITE");
588
589 itsLoader->UnloadRecPoints();
590 itsLoader->UnloadTracks();
591 tpcLoader->UnloadTracks();
592 return kTRUE;
593}
594
595//_____________________________________________________________________________
596Bool_t AliMonitorProcess::ReconstructV0s()
597{
598// find V0s
599
1899848d 600 SetStatus(kRecV0s);
04fa961a 601
602 AliITSLoader* itsLoader = (AliITSLoader*) fRunLoader->GetLoader("ITSLoader");
603 if (!itsLoader) {
604 Error("ReconstructV0", "no ITS loader found");
605 return kFALSE;
606 }
607 gSystem->Unlink("ITS.V0s.root");
608
609 // V0 finder
610 Info("ReconstructV0s", "reconstructing V0s...");
611 itsLoader->LoadTracks("read");
612 itsLoader->LoadV0s("recreate");
613 AliV0vertexer vertexer;
614 TTree* tracks = itsLoader->TreeT();
615 if (!tracks) {
616 Error("ReconstructV0s", "no ITS tracks tree found");
617 return kFALSE;
618 }
619 if (!itsLoader->TreeV0()) itsLoader->MakeTree("V0");
620 TTree* v0s = itsLoader->TreeV0();
621 vertexer.Tracks2V0vertices(tracks, v0s);
622 itsLoader->WriteV0s("OVERWRITE");
623
624 itsLoader->UnloadTracks();
625 itsLoader->UnloadV0s();
626 return kTRUE;
627}
628
97d6eb66 629//_____________________________________________________________________________
630#ifdef ALI_HLT
631void AliMonitorProcess::CreateHLT(const char* fileName)
632{
1899848d 633
97d6eb66 634// create the HLT (Level3) object
635
636 if (fHLT) delete fHLT;
637
638 char name[256];
639 strcpy(name, fileName);
640 fHLT = new AliLevel3(name);
641 fHLT->Init("./", AliLevel3::kRaw, 1);
642
524a85e8 643 fHLT->SetClusterFinderParam(-1, -1, kTRUE);
97d6eb66 644
c4bd737c 645 Int_t phiSegments = 50;
646 Int_t etaSegments = 100;
97d6eb66 647 Int_t trackletlength = 3;
524a85e8 648 Int_t tracklength = 20;//40 or 5
97d6eb66 649 Int_t rowscopetracklet = 2;
524a85e8 650 Int_t rowscopetrack = 10;
c4bd737c 651 Double_t minPtFit = 0;
524a85e8 652 Double_t maxangle = 0.1745;
97d6eb66 653 Double_t goodDist = 5;
524a85e8 654 Double_t maxphi = 0.1;
655 Double_t maxeta = 0.1;
1899848d 656 Double_t hitChi2Cut = 15;//100 or 15
657 Double_t goodHitChi2 = 5;//20 or 5
658 Double_t trackChi2Cut = 10;//50 or 10
c4bd737c 659 fHLT->SetTrackerParam(phiSegments, etaSegments,
97d6eb66 660 trackletlength, tracklength,
661 rowscopetracklet, rowscopetrack,
c4bd737c 662 minPtFit, maxangle, goodDist, hitChi2Cut,
97d6eb66 663 goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kTRUE);
664
665 fHLT->WriteFiles("./hlt/");
666}
c6ba6205 667
668//_____________________________________________________________________________
669void AliMonitorProcess::CreateHLTHough(const char* fileName)
670{
671
672// create the HLT Hough transform (L3Hough) object
673
674 if (fHLTHough) delete fHLTHough;
675
676 char name[256];
677 strcpy(name, fileName);
678
679 fHLTHough = new AliL3Hough();
4a69f9c7 680 fHLTHough->SetThreshold(4);
8aad0cd3 681 fHLTHough->SetTransformerParams(140,150,0.5,-1);
682 fHLTHough->SetPeakThreshold(9000,-1);// or 6000
4a69f9c7 683 fHLTHough->Init("./", kFALSE, 50, kFALSE,0,name);
c6ba6205 684 fHLTHough->SetAddHistograms();
4a69f9c7 685 // fHLTHough->GetMaxFinder()->SetThreshold(14000);
c6ba6205 686
687}
97d6eb66 688#endif
689
690//_____________________________________________________________________________
54a41755 691Bool_t AliMonitorProcess::ReconstructHLT(
692#ifdef ALI_HLT
693 Int_t iEvent
694#else
9abb4463 695 Int_t /* iEvent */
54a41755 696#endif
697)
97d6eb66 698{
699// run the HLT cluster and track finder
700
1899848d 701 SetStatus(kRecHLT);
97d6eb66 702
703#ifndef ALI_HLT
704 Warning("ReconstructHLT", "the code was compiled without HLT support");
705 return kTRUE;
706
707#else
708 gSystem->Exec("rm -rf hlt");
709 gSystem->MakeDirectory("hlt");
710 if (!fHLT) return kFALSE;
711
712 fHLT->ProcessEvent(0, 35, iEvent);
713
714 // remove the event number from the file names
715 char command[256];
716 sprintf(command, "rename points_%d points hlt/*.raw", iEvent);
717 gSystem->Exec(command);
718 sprintf(command, "rename tracks_tr_%d tracks_tr hlt/*.raw", iEvent);
719 gSystem->Exec(command);
720 sprintf(command, "rename tracks_gl_%d tracks_gl hlt/*.raw", iEvent);
721 gSystem->Exec(command);
722 sprintf(command, "rename tracks_%d tracks hlt/*.raw", iEvent);
723 gSystem->Exec(command);
724 return kTRUE;
725#endif
726}
727
c6ba6205 728//_____________________________________________________________________________
729Bool_t AliMonitorProcess::ReconstructHLTHough(
730#ifdef ALI_HLT
731 Int_t iEvent
732#else
733 Int_t /* iEvent */
734#endif
735)
736{
737// run the HLT Hough transformer
738
739 SetStatus(kRecHLT);
740
741#ifndef ALI_HLT
742 Warning("ReconstructHLTHough", "the code was compiled without HLT support");
743 return kTRUE;
744
745#else
4a69f9c7 746 gSystem->Exec("rm -rf hlt/hough");
747 gSystem->MakeDirectory("hlt/hough");
748 gSystem->Exec("rm -rf hlt/fitter");
749 gSystem->MakeDirectory("hlt/fitter");
c6ba6205 750 if (!fHLTHough) return kFALSE;
751
752 // fHLTHough->Process(0, 35);
753 // Loop over TPC sectors and process the data
754 for(Int_t i=0; i<=35; i++)
755 {
756 fHLTHough->ReadData(i,iEvent);
757 fHLTHough->Transform();
758 // if(fHLTHough->fAddHistograms)
759 fHLTHough->AddAllHistograms();
760 fHLTHough->FindTrackCandidates();
4a69f9c7 761 fHLTHough->AddTracks();
c6ba6205 762 }
4a69f9c7 763 fHLTHough->WriteTracks("./hlt/hough");
764
765 // Run cluster fitter
766 AliL3ClusterFitter *fitter = new AliL3ClusterFitter("./hlt");
767
768 // Set debug flag for the cluster fitter
769 // fitter->Debug();
770
771 // Setting fitter parameters
772 fitter->SetInnerWidthFactor(1,1.5);
773 fitter->SetOuterWidthFactor(1,1.5);
774 fitter->SetNmaxOverlaps(5);
775
776 //fitter->SetChiSqMax(5,kFALSE); //isolated clusters
777 fitter->SetChiSqMax(5,kTRUE); //overlapping clusters
778
779 Int_t rowrange[2] = {0,AliL3Transform::GetNRows()-1};
780
781 // Takes input from global hough tracks produced by HT
782 fitter->LoadSeeds(rowrange,kFALSE,iEvent);
783
8aad0cd3 784 UInt_t ndigits;
785
4a69f9c7 786 for(Int_t islice = 0; islice <= 35; islice++)
787 {
788 for(Int_t ipatch = 0; ipatch < AliL3Transform::GetNPatches(); ipatch++)
789 {
4a69f9c7 790 // Read digits
8aad0cd3 791 fHLTHough->GetMemHandler(ipatch)->Init(islice,ipatch);
792 AliL3DigitRowData *digits = (AliL3DigitRowData *)fHLTHough->GetMemHandler(ipatch)->AliAltroDigits2Memory(ndigits,iEvent);
793
794 fitter->Init(islice,ipatch);
4a69f9c7 795 fitter->SetInputData(digits);
796 fitter->FindClusters();
797 fitter->WriteClusters();
798 }
799 }
800
801 // Refit of the clusters
802 AliL3Vertex vertex;
803 //The seeds are the input tracks from circle HT
804 AliL3TrackArray *tracks = fitter->GetSeeds();
805 AliL3Fitter *ft = new AliL3Fitter(&vertex,1);
806
4a69f9c7 807 ft->LoadClusters("./hlt/fitter/",iEvent,kFALSE);
808 for(Int_t i=0; i<tracks->GetNTracks(); i++)
809 {
810 AliL3Track *track = tracks->GetCheckedTrack(i);
811 if(!track) continue;
8aad0cd3 812 if(track->GetNHits() < 20) continue;
4a69f9c7 813 ft->SortTrackClusters(track);
814 ft->FitHelix(track);
815 ft->UpdateTrack(track);
816 }
817 delete ft;
818
819 //Write the final tracks
8aad0cd3 820 fitter->WriteTracks(20);
4a69f9c7 821
822 delete fitter;
29504bd3 823
824 // remove the event number from the file names
825 char command[256];
4a69f9c7 826 sprintf(command, "rename tracks_%d tracks hlt/hough/*.raw", iEvent);
827 gSystem->Exec(command);
828 sprintf(command, "rename tracks_%d tracks hlt/fitter/*.raw", iEvent);
829 gSystem->Exec(command);
830 sprintf(command, "rename points_%d points hlt/fitter/*.raw", iEvent);
29504bd3 831 gSystem->Exec(command);
c6ba6205 832 return kTRUE;
833#endif
834}
04fa961a 835
836//_____________________________________________________________________________
837Bool_t AliMonitorProcess::WriteHistos()
838{
839// write the monitor tree and the monitor histograms to the file
840// "monitor_<run number>[_<sub_run_number>].root"
841// if at least fNEventsMin events were monitored
842
1899848d 843 SetStatus(kWriting);
04fa961a 844
845 // rename tree file and create a new one
846 fFile->cd();
847 fTree->Write();
848 fFile->Close();
849 delete fFile;
850
851 char fileName[256];
852 sprintf(fileName, "monitor_tree_%d.root", fRunNumber);
853 if (fSubRunNumber > 0) {
854 sprintf(fileName, "monitor_tree_%d_%d.root", fRunNumber, fSubRunNumber);
855 }
856 if (fNEvents < fNEventsMin) {
857 gSystem->Unlink("monitor_tree.root");
858 } else {
859 gSystem->Rename("monitor_tree.root", fileName);
860 }
861
862 fFile = TFile::Open("monitor_tree.root", "RECREATE");
863 if (!fFile || !fFile->IsOpen()) {
864 Fatal("WriteHistos", "could not open file for tree");
865 }
866 fTree = new TTree("MonitorTree", "tree for monitoring");
867 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
868 ((AliMonitor*) fMonitors[iMonitor])->CreateBranches(fTree);
869 }
870 gROOT->cd();
871
872 // write the histograms
873 if (fNEvents < fNEventsMin) return kTRUE;
874
875 if (!fWriteHistoList) {
876 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
877 while (TFolder* folder = (TFolder*) iFolder->Next()) {
878 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
879 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
880 histo->ResetList();
881 }
882 delete iHisto;
883 }
884 delete iFolder;
885 }
886
887 Bool_t result = kTRUE;
888 sprintf(fileName, "monitor_%d.root", fRunNumber);
889 if (fSubRunNumber > 0) {
890 sprintf(fileName, "monitor_%d_%d.root", fRunNumber, fSubRunNumber);
891 }
892 TFile* file = TFile::Open(fileName, "recreate");
893 if (!file || !file->IsOpen()) {
894 Error("WriteHistos", "could not open file %s", fileName);
895 result = kFALSE;
896 } else {
897 fTopFolder->Write();
898 file->Close();
899 }
900 if (file) delete file;
901
902 return result;
903}
904
905//_____________________________________________________________________________
906void AliMonitorProcess::StartNewRun()
907{
908// reset the histograms for a new run
909
1899848d 910 SetStatus(kResetting);
04fa961a 911 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
912 while (TFolder* folder = (TFolder*) iFolder->Next()) {
913 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
914 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
915 histo->Reset();
916 }
917 delete iHisto;
918 }
919 delete iFolder;
920
921 fNEvents = 0;
922}
923
924
925//_____________________________________________________________________________
926void AliMonitorProcess::CheckForConnections()
927{
928// check if new clients want to connect and add them to the list of sockets
929
930 TMessage message(kMESS_OBJECT);
931 message.WriteObject(fTopFolder);
1899848d 932 SetStatus(kConnecting);
04fa961a 933
934 TSocket* socket;
935 while ((socket = fServerSocket->Accept()) != (TSocket*)-1) {
54a41755 936 socket->SetOption(kNoBlock, 1);
04fa961a 937 char socketType[256];
938 if (!socket->Recv(socketType, 255)) continue;
939 if (strcmp(socketType, "client") == 0) {
940 if ((fNEvents == 0) || (socket->Send(message) >= 0)) {
941 fSockets.Add(socket);
942 TInetAddress adr = socket->GetInetAddress();
943 Info("CheckForConnections", "new client:\n %s (%s), port %d\n",
944 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
945 }
946 } else if (strcmp(socketType, "display") == 0) {
947 if (fDisplaySocket) {
948 fDisplaySocket->Close();
949 delete fDisplaySocket;
950 }
951 fDisplaySocket = socket;
952 fDisplaySocket->SetOption(kNoBlock, 1);
953 TInetAddress adr = socket->GetInetAddress();
954 Info("CheckForConnections", "new display:\n %s (%s), port %d\n",
955 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
956 }
957 }
958
959 for (Int_t iSocket = 0; iSocket < fSockets.GetEntriesFast(); iSocket++) {
960 socket = (TSocket*) fSockets[iSocket];
961 if (!socket) continue;
1899848d 962 // remove finished client
963 char str[256];
964 if (socket->Recv(str, 255)) {
965 TString socketMessage(str);
966 if(socketMessage.CompareTo("Finished") == 0) {
967 TInetAddress adr = socket->GetInetAddress();
968 Info("CheckForConnections",
969 "disconnect finished client:\n %s (%s), port %d\n",
970 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
971 delete fSockets.RemoveAt(iSocket);
972 continue;
973 }
974 }
04fa961a 975 if (!socket->IsValid()) {
976 // remove invalid sockets from the list
977 TInetAddress adr = socket->GetInetAddress();
978 Info("BroadcastHistos", "disconnect client:\n %s (%s), port %d\n",
979 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
980 delete fSockets.RemoveAt(iSocket);
981 }
982 }
983 fSockets.Compress();
984}
985
986//_____________________________________________________________________________
987void AliMonitorProcess::BroadcastHistos()
988{
989// send the monitor histograms to the clients
990
1899848d 991 SetStatus(kBroadcasting);
04fa961a 992 TMessage message(kMESS_OBJECT);
993 message.WriteObject(fTopFolder);
994
995 for (Int_t iSocket = 0; iSocket < fSockets.GetEntriesFast(); iSocket++) {
996 TSocket* socket = (TSocket*) fSockets[iSocket];
997 if (!socket) continue;
54a41755 998 socket->SetOption(kNoBlock, 0);
04fa961a 999 if (!socket->IsValid() || (socket->Send(message) < 0)) {
1000 // remove the socket from the list if there was an error
1001 TInetAddress adr = socket->GetInetAddress();
1002 Info("BroadcastHistos", "disconnect client:\n %s (%s), port %d\n",
1003 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1004 delete fSockets.RemoveAt(iSocket);
54a41755 1005 } else {
1006 socket->SetOption(kNoBlock, 1);
04fa961a 1007 }
1008 }
1009 fSockets.Compress();
1010}