]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MONITOR/AliMonitorProcess.cxx
Use correct alien file name (C.Cheshkov)
[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>
1899848d 64#endif
04fa961a 65
66ClassImp(AliMonitorProcess)
67
68
c4bd737c 69const Int_t AliMonitorProcess::fgkPort = 9327;
04fa961a 70
71
72//_____________________________________________________________________________
807ee5a3 73AliMonitorProcess::AliMonitorProcess(
74#if ROOT_VERSION_CODE <= 199169 // 3.10/01
75 const char* /*alienHost*/,
76#else
77 const char* alienHost,
78#endif
79 const char* alienDir,
04fa961a 80 const char* fileNameGalice)
81{
82// initialize the monitoring process and the monitor histograms
83
807ee5a3 84#if ROOT_VERSION_CODE <= 199169 // 3.10/01
04fa961a 85 fGrid = TGrid::Connect("alien", gSystem->Getenv("USER"));
807ee5a3 86#else
87 fGrid = TGrid::Connect(alienHost, gSystem->Getenv("USER"));
88#endif
04fa961a 89 if (!fGrid || fGrid->IsZombie() || !fGrid->IsConnected()) {
90 delete fGrid;
91 Fatal("AliMonitorProcess", "could not connect to alien");
92 }
807ee5a3 93#if ROOT_VERSION_CODE <= 199169 // 3.10/01
04fa961a 94 fGrid->cd(alienDir);
807ee5a3 95#else
96 fAlienDir = alienDir;
97#endif
04fa961a 98 fLogicalFileName = "";
99 fFileName = "";
100
101 fRunLoader = AliRunLoader::Open(fileNameGalice);
102 if (!fRunLoader) Fatal("AliMonitorProcess",
103 "could not get run loader from file %s",
104 fileNameGalice);
105
106 fRunLoader->CdGAFile();
107 fTPCParam = AliTPC::LoadTPCParam(gFile);
108 if (!fTPCParam) Fatal("AliMonitorProcess", "could not load TPC parameters");
109
110 fRunLoader->LoadgAlice();
111 gAlice = fRunLoader->GetAliRun();
112 if (!gAlice) Fatal("AliMonitorProcess", "no gAlice object found");
c4bd737c 113 AliITS* its = (AliITS*) gAlice->GetModule("ITS");
114 if (!its) Fatal("AliMonitorProcess", "no ITS detector found");
115 fITSgeom = its->GetITSgeom();
04fa961a 116 if (!fITSgeom) Fatal("AliMonitorProcess", "could not load ITS geometry");
117
1899848d 118#ifdef ALI_HLT
119// Init TPC parameters for HLT
120 Bool_t isinit=AliL3Transform::Init(const_cast<char*>(fileNameGalice),kTRUE);
121 if(!isinit){
122 cerr << "Could not create transform settings, please check log for error messages!" << endl;
123 return;
124 }
125#endif
126
04fa961a 127 fRunNumber = 0;
128 fSubRunNumber = 0;
129 fNEvents = 0;
130 fNEventsMin = 2;
131 fWriteHistoList = kFALSE;
132
133 fTopFolder = new TFolder("Monitor", "monitor histograms");
134 fTopFolder->SetOwner(kTRUE);
135
136 fMonitors.Add(new AliMonitorTPC(fTPCParam));
137 fMonitors.Add(new AliMonitorITS(fITSgeom));
138 fMonitors.Add(new AliMonitorV0s);
97d6eb66 139#ifdef ALI_HLT
140 fMonitors.Add(new AliMonitorHLT(fTPCParam));
c6ba6205 141 fMonitors.Add(new AliMonitorHLTHough(fTPCParam));
97d6eb66 142#endif
04fa961a 143
144 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
145 ((AliMonitor*) fMonitors[iMonitor])->CreateHistos(fTopFolder);
146 }
147
148 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
149 while (TFolder* folder = (TFolder*) iFolder->Next()) folder->SetOwner(kTRUE);
150 delete iFolder;
151
152 fFile = TFile::Open("monitor_tree.root", "RECREATE");
153 if (!fFile || !fFile->IsOpen()) {
154 Fatal("AliMonitorProcess", "could not open file for tree");
155 }
156 fTree = new TTree("MonitorTree", "tree for monitoring");
157 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
158 ((AliMonitor*) fMonitors[iMonitor])->CreateBranches(fTree);
159 }
160 gROOT->cd();
161
c4bd737c 162 fServerSocket = new TServerSocket(fgkPort, kTRUE);
04fa961a 163 fServerSocket->SetOption(kNoBlock, 1);
164 fDisplaySocket = NULL;
165 CheckForConnections();
97d6eb66 166#ifdef ALI_HLT
167 fHLT = NULL;
168#endif
04fa961a 169
1899848d 170 SetStatus(kStopped);
04fa961a 171 fStopping = kFALSE;
172}
173
c4bd737c 174//_____________________________________________________________________________
175AliMonitorProcess::AliMonitorProcess(const AliMonitorProcess& process) :
176 TObject(process)
177{
178 Fatal("AliMonitorProcess", "copy constructor not implemented");
179}
180
181//_____________________________________________________________________________
182AliMonitorProcess& AliMonitorProcess::operator = (const AliMonitorProcess&
183 /*process*/)
184{
185 Fatal("operator =", "assignment operator not implemented");
186 return *this;
187}
188
04fa961a 189//_____________________________________________________________________________
190AliMonitorProcess::~AliMonitorProcess()
191{
192// clean up
193
194 fMonitors.Delete();
195 delete fTopFolder;
196 delete fRunLoader;
197
198 delete fServerSocket;
199 fSockets.Delete();
200 delete fDisplaySocket;
201
807ee5a3 202#if ROOT_VERSION_CODE <= 199169 // 3.10/01
04fa961a 203 fGrid->Close();
807ee5a3 204#endif
04fa961a 205 delete fGrid;
206
207 fFile->Close();
208 delete fFile;
209 gSystem->Unlink("monitor_tree.root");
97d6eb66 210
211#ifdef ALI_HLT
212 delete fHLT;
4a69f9c7 213 delete fHLTHough;
97d6eb66 214#endif
04fa961a 215}
216
217
218//_____________________________________________________________________________
219const char* AliMonitorProcess::GetRevision()
220{
221 return "$Revision$";
222}
223
224
1899848d 225//_____________________________________________________________________________
226void AliMonitorProcess::SetStatus(EStatus status)
227{
c4bd737c 228// set the current status and process system events
229
1899848d 230 fStatus = status;
231 gSystem->ProcessEvents();
232}
233
234
04fa961a 235//_____________________________________________________________________________
236void AliMonitorProcess::Run()
237{
238// run the monitor process:
239// check for a raw data file, process the raw data file and delete it
240
241 fStopping = kFALSE;
242
243 while (!fStopping) {
1899848d 244 SetStatus(kWaiting);
04fa961a 245 while (!CheckForNewFile()) {
246 CheckForConnections();
1899848d 247 SetStatus(kWaiting);
04fa961a 248 if (fStopping) break;
249 gSystem->Sleep(10);
250 }
251 if (fStopping) break;
252
253 ProcessFile();
254 }
255
256 WriteHistos();
257
258 fStopping = kFALSE;
1899848d 259 SetStatus(kStopped);
04fa961a 260}
261
262
263//_____________________________________________________________________________
264void AliMonitorProcess::Stop()
265{
266// set the fStopping flag to terminate the monitor process after the current
267// event was processed
268
1899848d 269 if (GetStatus() != kStopped) fStopping = kTRUE;
04fa961a 270}
271
272
273//_____________________________________________________________________________
274void AliMonitorProcess::ProcessFile(const char* fileName)
275{
276// create a file with monitor histograms for a single file
277
1899848d 278 if (GetStatus() != kStopped) {
04fa961a 279 Error("ProcessFile", "ProcessFile can not be called"
280 " while the monitor process is running");
281 return;
282 }
283
284 fFileName = fileName;
285 Int_t nEventMin = fNEventsMin;
286 fNEventsMin = 1;
287 ProcessFile();
288 WriteHistos();
289 fNEventsMin = nEventMin;
1899848d 290 SetStatus(kStopped);
04fa961a 291}
292
293
294//_____________________________________________________________________________
295Bool_t AliMonitorProcess::CheckForNewFile()
296{
297// check whether a new file was registered in alien
298
807ee5a3 299#if ROOT_VERSION_CODE <= 199169 // 3.10/01
04fa961a 300 TGridResult* result = fGrid->Ls();
807ee5a3 301#else
302 Grid_ResultHandle_t handle = fGrid->OpenDir(fAlienDir);
303 if (!handle) {
304 Error("CheckForNewFile", "could not open alien directory %s",
305 fAlienDir.Data());
306 return kFALSE;
307 }
308 TGridResult* result = fGrid->CreateGridResult(handle);
309#endif
04fa961a 310 Long_t maxDate = -1;
311 Long_t maxTime = -1;
312 TString fileName;
313
807ee5a3 314#if ROOT_VERSION_CODE <= 199169 // 3.10/01
04fa961a 315 while (const char* entry = result->Next()) {
807ee5a3 316#else
317 while (Grid_Result_t* resultEntry = result->Next()) {
318 const char* entry = resultEntry->name.c_str();
319#endif
04fa961a 320 // entry = host_date_time.root
321 TString entryCopy(entry);
322 char* p = const_cast<char*>(entryCopy.Data());
6ad9b9d5 323 if (!strtok(p, "_") || !p) continue; // host name
97d6eb66 324 char* dateStr = strtok(NULL, "_");
04fa961a 325 if (!dateStr || !p) continue;
97d6eb66 326 char* timeStr = strtok(NULL, ".");
04fa961a 327 if (!timeStr || !p) continue;
328 Long_t date = atoi(dateStr);
329 Long_t time = atoi(timeStr);
330
331 if ((date > maxDate) || ((date == maxDate) && (time > maxTime))) {
332 maxDate = date;
333 maxTime = time;
334 fileName = entry;
335 }
336 }
337
807ee5a3 338 delete result;
04fa961a 339 if (maxDate < 0) return kFALSE; // no files found
340 if (fLogicalFileName.CompareTo(fileName) == 0) return kFALSE; // no new file
341
342 fLogicalFileName = fileName;
807ee5a3 343#if ROOT_VERSION_CODE <= 199169 // 3.10/01
344 result = fGrid->GetPhysicalFileNames(fLogicalFileName.Data());
345 fFileName = result->Next();
346#else
347 handle = fGrid->GetPhysicalFileNames(fLogicalFileName.Data());
348 if (!handle) {
349 Error("CheckForNewFile", "could not get physical file names for %s",
350 fLogicalFileName.Data());
351 return kFALSE;
352 }
353 result = fGrid->CreateGridResult(handle);
354 Grid_Result_t* resultEntry = result->Next();
355 if (!resultEntry) {
356 Error("CheckForNewFile", "could not get physical file names for %s",
357 fLogicalFileName.Data());
358 return kFALSE;
359 }
389567d6 360 fFileName = resultEntry->name2.c_str();
807ee5a3 361#endif
362 delete result;
1899848d 363
04fa961a 364 return kTRUE;
365}
366
367//_____________________________________________________________________________
368Bool_t AliMonitorProcess::ProcessFile()
369{
370// loop over all events in the raw data file, run the reconstruction
371// and fill the monitor histograms
372
373 Int_t nEvents = GetNumberOfEvents(fFileName);
374 if (nEvents <= 0) return kFALSE;
375 Info("ProcessFile", "found %d event(s) in file %s",
376 nEvents, fFileName.Data());
97d6eb66 377#ifdef ALI_HLT
378 CreateHLT(fFileName);
c6ba6205 379 CreateHLTHough(fFileName);
97d6eb66 380#endif
04fa961a 381
382 // loop over the events
383 for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
1899848d 384 SetStatus(kReading);
04fa961a 385 fRunLoader->SetEventNumber(0);
386 AliRawReaderRoot rawReader(fFileName, iEvent);
387 if (fStopping) break;
388 if (rawReader.GetRunNumber() != fRunNumber) {
389 WriteHistos();
390 StartNewRun();
391 fRunNumber = rawReader.GetRunNumber();
392 fEventNumber[0] = rawReader.GetEventId()[0];
393 fEventNumber[1] = rawReader.GetEventId()[1];
394 fSubRunNumber = 0;
395 if (fStopping) break;
396 }
397
398 if (!ReconstructTPC(&rawReader)) return kFALSE;
399 if (fStopping) break;
400 if (!ReconstructITS(&rawReader)) return kFALSE;
401 if (fStopping) break;
402 if (!ReconstructV0s()) return kFALSE;
403 if (fStopping) break;
97d6eb66 404 if (!ReconstructHLT(iEvent)) return kFALSE;
405 if (fStopping) break;
c6ba6205 406 if (!ReconstructHLTHough(iEvent)) return kFALSE;
407 if (fStopping) break;
04fa961a 408
409 if (fDisplaySocket) fDisplaySocket->Send("new event");
410
411 Info("ProcessFile", "filling histograms...");
1899848d 412 SetStatus(kFilling);
04fa961a 413 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
414 ((AliMonitor*) fMonitors[iMonitor])->FillHistos(fRunLoader, &rawReader);
415 if (fStopping) break;
416 }
417 if (fStopping) break;
418
419 Info("ProcessFile", "updating histograms...");
1899848d 420 SetStatus(kUpdating);
04fa961a 421 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
422 while (TFolder* folder = (TFolder*) iFolder->Next()) {
423 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
424 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
425 histo->Update();
426 }
427 delete iHisto;
428 }
429 delete iFolder;
430 if (fStopping) break;
431
432 Info("ProcessFile", "filling the tree...");
433 fTree->Fill();
434
435 Info("ProcessFile", "broadcasting histograms...");
436 CheckForConnections();
437 BroadcastHistos();
438
439 fNEvents++;
440 if (fStopping) break;
441 }
442
97d6eb66 443#ifdef ALI_HLT
444 delete fHLT;
445 fHLT = NULL;
446#endif
447
04fa961a 448 return kTRUE;
449}
450
451//_____________________________________________________________________________
452void AliMonitorProcess::Reset()
453{
454// write the current histograms to a file and reset them
455
456 if (fSubRunNumber == 0) fSubRunNumber++;
457 WriteHistos();
458 StartNewRun();
459 fSubRunNumber++;
460}
461
462
463//_____________________________________________________________________________
c4bd737c 464UInt_t AliMonitorProcess::GetEventPeriodNumber() const
04fa961a 465{
466// get the period number from the event id
467
468 return (fEventNumber[1] >> 4);
469}
470
471//_____________________________________________________________________________
c4bd737c 472UInt_t AliMonitorProcess::GetEventOrbitNumber() const
04fa961a 473{
474// get the orbit number from the event id
475
476 return ((fEventNumber[1] & 0x000F) << 20) + (fEventNumber[0] >> 12);
477}
478
479//_____________________________________________________________________________
c4bd737c 480UInt_t AliMonitorProcess::GetEventBunchNumber() const
04fa961a 481{
482// get the bunch number from the event id
483
484 return (fEventNumber[0] % 0x0FFF);
485}
486
487//_____________________________________________________________________________
c4bd737c 488Int_t AliMonitorProcess::GetNumberOfEvents(const char* fileName) const
04fa961a 489{
490// determine the number of events in the given raw data file
491
492 Int_t nEvents = -1;
493
494 TFile* file = TFile::Open(fileName);
495 if (!file || !file->IsOpen()) {
496 Error("GetNumberOfEvents", "could not open file %s", fileName);
497 if (file) delete file;
498 return -1;
499 }
500
501 TTree* tree = (TTree*) file->Get("RAW");
502 if (!tree) {
503 Error("GetNumberOfEvents", "could not find tree with raw data");
504 } else {
505 nEvents = (Int_t) tree->GetEntries();
506 }
507 file->Close();
508 delete file;
509
510 return nEvents;
511}
512
513//_____________________________________________________________________________
514Bool_t AliMonitorProcess::ReconstructTPC(AliRawReader* rawReader)
515{
516// find TPC clusters and tracks
517
1899848d 518 SetStatus(kRecTPC);
04fa961a 519
520 AliLoader* tpcLoader = fRunLoader->GetLoader("TPCLoader");
521 if (!tpcLoader) {
522 Error("ReconstructTPC", "no TPC loader found");
523 return kFALSE;
524 }
525 gSystem->Unlink("TPC.RecPoints.root");
526 gSystem->Unlink("TPC.Tracks.root");
527
528 // cluster finder
529 Info("ReconstructTPC", "reconstructing clusters...");
530 tpcLoader->LoadRecPoints("recreate");
531 AliTPCclustererMI clusterer(fTPCParam);
532 tpcLoader->MakeRecPointsContainer();
533 clusterer.SetOutput(tpcLoader->TreeR());
534 clusterer.Digits2Clusters(rawReader);
535 tpcLoader->WriteRecPoints("OVERWRITE");
536
537 // track finder
538 Info("ReconstructTPC", "reconstructing tracks...");
539 tpcLoader->LoadTracks("recreate");
540 {
541 AliTPCtrackerMI tracker(fTPCParam);
542 tracker.Clusters2Tracks();
543 }
544
545 tpcLoader->UnloadRecPoints();
546 tpcLoader->UnloadTracks();
547 return kTRUE;
548}
549
550//_____________________________________________________________________________
551Bool_t AliMonitorProcess::ReconstructITS(AliRawReader* rawReader)
552{
553// find ITS clusters and tracks
554
1899848d 555 SetStatus(kRecITS);
04fa961a 556
557 AliLoader* itsLoader = fRunLoader->GetLoader("ITSLoader");
558 if (!itsLoader) {
559 Error("ReconstructITS", "no ITS loader found");
560 return kFALSE;
561 }
562 AliLoader* tpcLoader = fRunLoader->GetLoader("TPCLoader");
563 if (!tpcLoader) {
564 Error("ReconstructITS", "no TPC loader found");
565 return kFALSE;
566 }
567 gSystem->Unlink("ITS.RecPoints.root");
568 gSystem->Unlink("ITS.Tracks.root");
569
570 // cluster finder
571 Info("ReconstructITS", "reconstructing clusters...");
572 itsLoader->LoadRecPoints("recreate");
573 AliITSclustererV2 clusterer(fITSgeom);
574 itsLoader->MakeRecPointsContainer();
575 clusterer.Digits2Clusters(rawReader);
576
577 // track finder
578 Info("ReconstructITS", "reconstructing tracks...");
579 itsLoader->LoadTracks("recreate");
580 itsLoader->MakeTracksContainer();
581 tpcLoader->LoadTracks();
582 AliITStrackerV2 tracker(fITSgeom);
583 tracker.LoadClusters(itsLoader->TreeR());
584 tracker.Clusters2Tracks(tpcLoader->TreeT(), itsLoader->TreeT());
585 tracker.UnloadClusters();
586 itsLoader->WriteTracks("OVERWRITE");
587
588 itsLoader->UnloadRecPoints();
589 itsLoader->UnloadTracks();
590 tpcLoader->UnloadTracks();
591 return kTRUE;
592}
593
594//_____________________________________________________________________________
595Bool_t AliMonitorProcess::ReconstructV0s()
596{
597// find V0s
598
1899848d 599 SetStatus(kRecV0s);
04fa961a 600
601 AliITSLoader* itsLoader = (AliITSLoader*) fRunLoader->GetLoader("ITSLoader");
602 if (!itsLoader) {
603 Error("ReconstructV0", "no ITS loader found");
604 return kFALSE;
605 }
606 gSystem->Unlink("ITS.V0s.root");
607
608 // V0 finder
609 Info("ReconstructV0s", "reconstructing V0s...");
610 itsLoader->LoadTracks("read");
611 itsLoader->LoadV0s("recreate");
612 AliV0vertexer vertexer;
613 TTree* tracks = itsLoader->TreeT();
614 if (!tracks) {
615 Error("ReconstructV0s", "no ITS tracks tree found");
616 return kFALSE;
617 }
618 if (!itsLoader->TreeV0()) itsLoader->MakeTree("V0");
619 TTree* v0s = itsLoader->TreeV0();
620 vertexer.Tracks2V0vertices(tracks, v0s);
621 itsLoader->WriteV0s("OVERWRITE");
622
623 itsLoader->UnloadTracks();
624 itsLoader->UnloadV0s();
625 return kTRUE;
626}
627
97d6eb66 628//_____________________________________________________________________________
629#ifdef ALI_HLT
630void AliMonitorProcess::CreateHLT(const char* fileName)
631{
1899848d 632
97d6eb66 633// create the HLT (Level3) object
634
635 if (fHLT) delete fHLT;
636
637 char name[256];
638 strcpy(name, fileName);
639 fHLT = new AliLevel3(name);
640 fHLT->Init("./", AliLevel3::kRaw, 1);
641
524a85e8 642 fHLT->SetClusterFinderParam(-1, -1, kTRUE);
97d6eb66 643
c4bd737c 644 Int_t phiSegments = 50;
645 Int_t etaSegments = 100;
97d6eb66 646 Int_t trackletlength = 3;
524a85e8 647 Int_t tracklength = 20;//40 or 5
97d6eb66 648 Int_t rowscopetracklet = 2;
524a85e8 649 Int_t rowscopetrack = 10;
c4bd737c 650 Double_t minPtFit = 0;
524a85e8 651 Double_t maxangle = 0.1745;
97d6eb66 652 Double_t goodDist = 5;
524a85e8 653 Double_t maxphi = 0.1;
654 Double_t maxeta = 0.1;
1899848d 655 Double_t hitChi2Cut = 15;//100 or 15
656 Double_t goodHitChi2 = 5;//20 or 5
657 Double_t trackChi2Cut = 10;//50 or 10
c4bd737c 658 fHLT->SetTrackerParam(phiSegments, etaSegments,
97d6eb66 659 trackletlength, tracklength,
660 rowscopetracklet, rowscopetrack,
c4bd737c 661 minPtFit, maxangle, goodDist, hitChi2Cut,
97d6eb66 662 goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kTRUE);
663
664 fHLT->WriteFiles("./hlt/");
665}
c6ba6205 666
667//_____________________________________________________________________________
668void AliMonitorProcess::CreateHLTHough(const char* fileName)
669{
670
671// create the HLT Hough transform (L3Hough) object
672
673 if (fHLTHough) delete fHLTHough;
674
675 char name[256];
676 strcpy(name, fileName);
677
678 fHLTHough = new AliL3Hough();
4a69f9c7 679 fHLTHough->SetThreshold(4);
680 fHLTHough->SetTransformerParams(140,150,0.2,-1);
681 fHLTHough->SetPeakThreshold(6000,-1);
682 fHLTHough->Init("./", kFALSE, 50, kFALSE,0,name);
c6ba6205 683 fHLTHough->SetAddHistograms();
4a69f9c7 684 // fHLTHough->GetMaxFinder()->SetThreshold(14000);
c6ba6205 685
686}
97d6eb66 687#endif
688
689//_____________________________________________________________________________
54a41755 690Bool_t AliMonitorProcess::ReconstructHLT(
691#ifdef ALI_HLT
692 Int_t iEvent
693#else
9abb4463 694 Int_t /* iEvent */
54a41755 695#endif
696)
97d6eb66 697{
698// run the HLT cluster and track finder
699
1899848d 700 SetStatus(kRecHLT);
97d6eb66 701
702#ifndef ALI_HLT
703 Warning("ReconstructHLT", "the code was compiled without HLT support");
704 return kTRUE;
705
706#else
707 gSystem->Exec("rm -rf hlt");
708 gSystem->MakeDirectory("hlt");
709 if (!fHLT) return kFALSE;
710
711 fHLT->ProcessEvent(0, 35, iEvent);
712
713 // remove the event number from the file names
714 char command[256];
715 sprintf(command, "rename points_%d points hlt/*.raw", iEvent);
716 gSystem->Exec(command);
717 sprintf(command, "rename tracks_tr_%d tracks_tr hlt/*.raw", iEvent);
718 gSystem->Exec(command);
719 sprintf(command, "rename tracks_gl_%d tracks_gl hlt/*.raw", iEvent);
720 gSystem->Exec(command);
721 sprintf(command, "rename tracks_%d tracks hlt/*.raw", iEvent);
722 gSystem->Exec(command);
723 return kTRUE;
724#endif
725}
726
c6ba6205 727//_____________________________________________________________________________
728Bool_t AliMonitorProcess::ReconstructHLTHough(
729#ifdef ALI_HLT
730 Int_t iEvent
731#else
732 Int_t /* iEvent */
733#endif
734)
735{
736// run the HLT Hough transformer
737
738 SetStatus(kRecHLT);
739
740#ifndef ALI_HLT
741 Warning("ReconstructHLTHough", "the code was compiled without HLT support");
742 return kTRUE;
743
744#else
4a69f9c7 745 gSystem->Exec("rm -rf hlt/hough");
746 gSystem->MakeDirectory("hlt/hough");
747 gSystem->Exec("rm -rf hlt/fitter");
748 gSystem->MakeDirectory("hlt/fitter");
c6ba6205 749 if (!fHLTHough) return kFALSE;
750
751 // fHLTHough->Process(0, 35);
752 // Loop over TPC sectors and process the data
753 for(Int_t i=0; i<=35; i++)
754 {
755 fHLTHough->ReadData(i,iEvent);
756 fHLTHough->Transform();
757 // if(fHLTHough->fAddHistograms)
758 fHLTHough->AddAllHistograms();
759 fHLTHough->FindTrackCandidates();
4a69f9c7 760 fHLTHough->AddTracks();
c6ba6205 761 }
4a69f9c7 762 fHLTHough->WriteTracks("./hlt/hough");
763
764 // Run cluster fitter
765 AliL3ClusterFitter *fitter = new AliL3ClusterFitter("./hlt");
766
767 // Set debug flag for the cluster fitter
768 // fitter->Debug();
769
770 // Setting fitter parameters
771 fitter->SetInnerWidthFactor(1,1.5);
772 fitter->SetOuterWidthFactor(1,1.5);
773 fitter->SetNmaxOverlaps(5);
774
775 //fitter->SetChiSqMax(5,kFALSE); //isolated clusters
776 fitter->SetChiSqMax(5,kTRUE); //overlapping clusters
777
778 Int_t rowrange[2] = {0,AliL3Transform::GetNRows()-1};
779
780 // Takes input from global hough tracks produced by HT
781 fitter->LoadSeeds(rowrange,kFALSE,iEvent);
782
783 for(Int_t islice = 0; islice <= 35; islice++)
784 {
785 for(Int_t ipatch = 0; ipatch < AliL3Transform::GetNPatches(); ipatch++)
786 {
787 fitter->Init(islice,ipatch);
788
789 // Read digits
790 AliL3DigitRowData *digits = fHLTHough->GetTransformer(ipatch)->GetDataPointer();
791 fitter->SetInputData(digits);
792 fitter->FindClusters();
793 fitter->WriteClusters();
794 }
795 }
796
797 // Refit of the clusters
798 AliL3Vertex vertex;
799 //The seeds are the input tracks from circle HT
800 AliL3TrackArray *tracks = fitter->GetSeeds();
801 AliL3Fitter *ft = new AliL3Fitter(&vertex,1);
802
803 // Temporary solution !
804 // sprintf(command, "rename _5.raw _-1.raw hlt/fitter/points*.raw", iEvent);
805 // gSystem->Exec(command);
806
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;
812 if(track->GetNHits() < 40) continue;
813 ft->SortTrackClusters(track);
814 ft->FitHelix(track);
815 ft->UpdateTrack(track);
816 }
817 delete ft;
818
819 //Write the final tracks
820 fitter->WriteTracks(5);
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}