]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MONITOR/monitorGDC.cxx
Use new naming conventions from QuadSet.
[u/mrichter/AliRoot.git] / MONITOR / monitorGDC.cxx
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 program performs local monitoring on a GDC by running the HLT code   //
21 //                                                                           //
22 // If an argument is given, this is taken as the name of a date file which   //
23 // is used instead of the local node.                                        //
24 // The program can be stopped by pressing CTRL-C.                            //
25 //                                                                           //
26 ///////////////////////////////////////////////////////////////////////////////
27
28 #include <TError.h>
29 #include <TSysEvtHandler.h>
30 #ifdef ALI_DATE
31 #include <TROOT.h>
32 #include <TSystem.h>
33 #include <TDatime.h>
34 #include "AliRawReaderDate.h"
35 #include "event.h"
36 #include "monitor.h"
37 #include <AliL3StandardIncludes.h>
38 #include <AliL3Transform.h>
39 #include <AliL3MemHandler.h>
40 #include <AliL3TrackArray.h>
41 #include <AliL3HoughMaxFinder.h>
42 #include <AliL3HoughBaseTransformer.h>
43 #include <AliL3Hough.h>
44 #include <AliL3Benchmark.h>
45 #include <AliKalmanTrack.h>
46 #include "AliITSgeom.h"
47 #include "AliMagF.h"
48 #include "AliMagFMaps.h"
49 #include <AliL3ITSclusterer.h>
50 #include <AliL3ITSVertexerZ.h>
51 #include <AliL3ITStracker.h>
52 #endif
53
54 //_____________________________________________________________________________
55 class AliGDCInterruptHandler : public TSignalHandler {
56 public:
57   AliGDCInterruptHandler();
58   Bool_t Notify() {fStop = kTRUE; return kTRUE;};
59   Bool_t Stop() const {return fStop;};
60 private:
61   Bool_t fStop;  // CTRL-C pressed
62 };
63
64 //_____________________________________________________________________________
65 AliGDCInterruptHandler::AliGDCInterruptHandler() : 
66   TSignalHandler(kSigInterrupt, kFALSE) 
67 {
68   fStop = kFALSE;
69 };
70
71
72 //_____________________________________________________________________________
73 #ifdef ALI_DATE
74 int main(int argc, char** argv)
75 {
76   // set ROOT in batch mode
77   gROOT->SetBatch();   
78
79   // open a log file
80   FILE* file = fopen("monitorGDC.log", "w");
81
82   TDatime time;
83
84   // get data from a file or online from this node
85   Int_t status = 0;
86   if (argc > 1) {
87     status = monitorSetDataSource(argv[1]);
88   } else {
89     status = monitorSetDataSource(":");
90   }
91   if (status) ::Fatal("monitorSetDataSource", monitorDecodeError(status));
92
93   // monitor only a sample of physics events
94   char* table[] = {"Physics event", "yes", NULL};
95   status = monitorDeclareTable(table);
96   if (status) ::Fatal("monitorDeclareTable", monitorDecodeError(status));
97
98   // declare this monitoring program to DATE
99   status = monitorDeclareMp("GDC physics monitoring");
100   if (status) ::Fatal("monitorDeclareMp", monitorDecodeError(status));
101
102   // initialize HLT transformations
103   if (!AliL3Transform::Init("./", kFALSE)) {
104     ::Fatal("AliL3Transform::Init", "HLT initialization failed");
105   }
106   AliESD *esd = new AliESD;
107   //  AliKalmanTrack::SetConvConst(
108   //     1000/0.299792458/AliL3Transform::GetSolenoidField()
109   //  );
110   AliITSgeom *geom = new AliITSgeom();
111   geom->ReadNewFile("$ALICE_ROOT/ITS/ITSgeometry_vPPRasymmFMD.det");
112   if (!geom) return 1;
113   Int_t sfield = 0;
114   switch ((Int_t)(AliL3Transform::GetSolenoidField()+0.5)) {
115   case 2:
116     sfield = AliMagFMaps::k2kG;
117     break;
118   case 4:
119     sfield = AliMagFMaps::k4kG;
120     break;
121   case 5:
122     sfield = AliMagFMaps::k5kG;
123     break;
124   default:
125     ::Fatal("AliL3Transform::GetSolenoidField", "Incorrect magnetic field");
126   }
127   AliMagF* field = new AliMagFMaps("Maps","Maps", 2, 1., 10., sfield);
128   AliTracker::SetFieldMap(field,kTRUE);
129
130   // Init PID
131   AliPID pid;
132
133   // create the signal handler
134   AliGDCInterruptHandler* handler = new AliGDCInterruptHandler;
135   gSystem->AddSignalHandler(handler);
136
137   // endless loop
138   void* ptr = NULL;
139   while (!handler->Stop()) {
140     // get the next event
141     status = monitorGetEventDynamic(&ptr);
142     if (status == (Int_t)MON_ERR_EOF) break;
143     if (status) ::Fatal("monitorGetEventDynamic", monitorDecodeError(status));
144
145     // if no new event
146     if (!ptr) {
147       gSystem->Sleep(1000);   // sleep for 1 second
148       continue;
149     }
150
151     AliRawReaderDate rawReader(ptr);
152     //    if ((rawReader.GetAttributes()[0] & 0x02) != 0) {
153
154     //      Int_t errorCode = rawReader.CheckData();
155     Int_t errorCode = 0;
156       if (errorCode && (errorCode != AliRawReader::kErrSize)) {
157         time.Set();
158         if (file) fprintf(file, "%s\n", time.AsString());
159         if (file) fprintf(file, "run: %d  event: %d %d\n", 
160                           rawReader.GetRunNumber(), 
161                           rawReader.GetEventId()[0], 
162                           rawReader.GetEventId()[1]);
163         fprintf(file, "ERROR: %d\n\n", errorCode);
164
165       } else {
166
167         AliL3Benchmark *fBenchmark = new AliL3Benchmark();
168         fBenchmark->Start("Overall timing");
169
170         // ITS clusterer and vertexer
171         fBenchmark->Start("ITS Clusterer");
172         AliL3ITSclusterer clusterer(geom);
173         AliRawReader *itsrawreader=new AliRawReaderDate(ptr);
174         TTree* treeClusters = new TTree("TreeL3ITSclusters"," "); //make a tree
175         clusterer.Digits2Clusters(itsrawreader,treeClusters);
176         fBenchmark->Stop("ITS Clusterer");
177         
178         AliL3ITSVertexerZ vertexer;
179         AliESDVertex *vertex = vertexer.FindVertexForCurrentEvent(geom,treeClusters);
180         Double_t vtxPos[3];
181         Double_t vtxErr[3]={0.005,0.005,0.010};
182         vertex->GetXYZ(vtxPos);
183         //      vertex->GetSigmaXYZ(vtxErr);
184         esd->SetVertex(vertex);
185
186         // TPC Hough reconstruction
187         Float_t ptmin = 0.1*AliL3Transform::GetSolenoidField();
188         Float_t zvertex = vtxPos[2];
189
190         // Run the Hough Transformer
191         fBenchmark->Start("Init");
192         AliL3Hough *hough1 = new AliL3Hough();
193
194         hough1->SetThreshold(4);
195         hough1->CalcTransformerParams(ptmin);
196         hough1->SetPeakThreshold(70,-1);
197         //      printf("Pointer is %x\n",ptr);
198         hough1->Init("./", kFALSE, 100, kFALSE,4,0,(Char_t*)ptr,zvertex);
199         hough1->SetAddHistograms();
200         fBenchmark->Stop("Init");
201
202         fBenchmark->Start("Init");
203         AliL3Hough *hough2 = new AliL3Hough();
204
205         hough2->SetThreshold(4);
206         hough2->CalcTransformerParams(ptmin);
207         hough2->SetPeakThreshold(70,-1);
208         //      printf("Pointer is %x\n",ptr);
209         hough2->Init("./", kFALSE, 100, kFALSE,4,0,(Char_t*)ptr,zvertex);
210         hough2->SetAddHistograms();
211         fBenchmark->Stop("Init");
212
213         Int_t nglobaltracks = 0;
214         /*
215         hough1->StartProcessInThread(0,17);
216         hough2->StartProcessInThread(18,35);
217
218         //      gSystem->Sleep(20000);
219         if(hough1->WaitForThreadFinish())
220           ::Fatal("AliL3Hough::WaitForThreadFinish"," Can not join the required thread! ");
221         if(hough2->WaitForThreadFinish())
222           ::Fatal("AliL3Hough::WaitForThreadFinish"," Can not join the required thread! ");
223
224         gSystem->MakeDirectory("hough1");
225         hough1->WriteTracks("./hough1");
226         gSystem->MakeDirectory("hough2");
227         hough2->WriteTracks("./hough2");
228         */
229
230         for(int slice=0; slice<=17; slice++)
231         {
232           //      cout<<"Processing slice "<<slice<<endl;
233           fBenchmark->Start("ReadData");
234           hough1->ReadData(slice,0);
235           fBenchmark->Stop("ReadData");
236           fBenchmark->Start("Transform");
237           hough1->Transform();
238           fBenchmark->Stop("Transform");
239           hough1->AddAllHistogramsRows();
240           hough1->FindTrackCandidatesRow();
241           fBenchmark->Start("AddTracks");
242           hough1->AddTracks();
243           fBenchmark->Stop("AddTracks");
244
245           //      AliL3TrackArray* tracks = (AliL3TrackArray*)hough1->GetTracks(0);
246           //      nglobaltracks += tracks->GetNTracks();
247         }
248         for(int slice=18; slice<=35; slice++)
249         {
250           //      cout<<"Processing slice "<<slice<<endl;
251           fBenchmark->Start("ReadData");
252           hough2->ReadData(slice,0);
253           fBenchmark->Stop("ReadData");
254           fBenchmark->Start("Transform");
255           hough2->Transform();
256           fBenchmark->Stop("Transform");
257           hough2->AddAllHistogramsRows();
258           hough2->FindTrackCandidatesRow();
259           fBenchmark->Start("AddTracks");
260           hough2->AddTracks();
261           fBenchmark->Stop("AddTracks");
262
263           //      AliL3TrackArray* tracks = (AliL3TrackArray*)hough2->GetTracks(0);
264           //      nglobaltracks += tracks->GetNTracks();
265         }
266
267         nglobaltracks += hough1->FillESD(esd);
268         nglobaltracks += hough2->FillESD(esd);
269
270         // ITS tracker
271         AliL3ITStracker itsTracker(geom);
272         itsTracker.SetVertex(vtxPos,vtxErr);
273
274         itsTracker.LoadClusters(treeClusters);
275         itsTracker.Clusters2Tracks(esd);
276         itsTracker.UnloadClusters();
277
278         fBenchmark->Stop("Overall timing");
279         time.Set();
280         if (file) fprintf(file, "%s\n", time.AsString());
281         if (file) fprintf(file, "run: %d  event: %d %d\n", 
282                           rawReader.GetRunNumber(), 
283                           rawReader.GetEventId()[0], 
284                           rawReader.GetEventId()[1]);
285         if (errorCode) fprintf(file, "ERROR: %d\n", errorCode);
286
287         if (file) fprintf(file, "Hough Transformer found %d tracks\n",nglobaltracks);
288
289         hough1->DoBench("hough1");
290         hough2->DoBench("hough2");
291         fBenchmark->Analyze("overall");
292         if (file) {
293           FILE* bench = fopen("hough1.dat", "r");
294           while (bench && !feof(bench)) {
295             char buffer[256];
296             if (!fgets(buffer, 256, bench)) break;
297             fprintf(file, "%s", buffer);
298           }
299           fclose(bench);
300         }
301         if (file) {
302           FILE* bench = fopen("hough2.dat", "r");
303           while (bench && !feof(bench)) {
304             char buffer[256];
305             if (!fgets(buffer, 256, bench)) break;
306             fprintf(file, "%s", buffer);
307           }
308           fclose(bench);
309         }
310         if (file) {
311           FILE* bench = fopen("overall.dat", "r");
312           while (bench && !feof(bench)) {
313             char buffer[256];
314             if (!fgets(buffer, 256, bench)) break;
315             fprintf(file, "%s", buffer);
316           }
317           fclose(bench);
318           fprintf(file, "\n\n");
319         }
320
321         delete hough1;
322         delete hough2;
323
324         esd->Reset();
325       }
326     //    }
327
328     /*
329     // read run, event, detector, DDL numbers and data size
330     AliRawReaderDate rawReader(ptr);
331     time.Set();
332     printf("\n%s\n", time.AsString());
333     printf("run: %d  event: %d %d\n", rawReader.GetRunNumber(), 
334            rawReader.GetEventId()[0], rawReader.GetEventId()[1]);
335     while (rawReader.ReadMiniHeader()) {
336       printf(" detector: %d   DDL: %d  size: %d\n", 
337              rawReader.GetDetectorID(), rawReader.GetDDLID(), 
338              rawReader.GetDataSize());
339     }
340
341     */
342
343     gSystem->Sleep(100);   // sleep for 0.1 second
344     free(ptr);
345
346     gSystem->ProcessEvents();
347     if (file) fflush(file);
348
349   }
350
351   gSystem->RemoveSignalHandler(handler);
352   if (file) fclose(file);
353
354   return 0;
355 }
356
357 #else
358 int main(int /*argc*/, char** /*argv*/)
359 {
360   ::Fatal("main", "this program was compiled without DATE");
361
362   return 1;
363 }
364 #endif