source: trunk/MagicSoft/Mars/manalysis/MTrigLvl2.cc@ 1772

Last change on this file since 1772 was 1746, checked in by moralejo, 22 years ago
*** empty log message ***
File size: 17.4 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Antonio Stamerra 1/2003 <mailto:antono.stamerra@pi.infn.it>
19! Author(s): Marcos Lopez 1/2003 <mailto:marcos@gae.ucm.es>
20!
21! Copyright: MAGIC Software Development, 2000-2003
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27// //
28// MTrigLvl2 //
29// Storage container for the 2nd level trigger selection parameters //
30// as part of the 2nd level trigger simulation //
31// //
32// (preliminary version) //
33// //
34// Basic L2T Selection Parameters: //
35// //
36// LutPseudoSize number of compact pixels in one LUT //
37// //
38/////////////////////////////////////////////////////////////////////////////
39
40#include "MTrigLvl2.h"
41
42#include "MGeomCamMagic.h"
43#include "MCamDisplay.h"
44
45#include "MMcTrig.hxx"
46
47#include <fstream.h>
48#include "MLog.h"
49
50#include <TCanvas.h>
51
52
53ClassImp(MTrigLvl2)
54
55
56//
57// Correspondence TABLE between pixel numbering in the trigger cells and
58// the standard spiral counting
59// (Note: Pixels start to count from 1 instead of 0)
60//
61static const Int_t pixels_in_cell[36][19] = {
62{26, 91, 66, 71, 76, 81, 86, 269, 224, 233, 242, 251, 260, 391, 336, 347, 358, 369, 380},
63{25, 61, 41, 45, 49, 53, 57, 215, 175, 183, 191, 199, 207, 325, 275, 285, 295, 305, 315},
64{24, 37, 22, 25, 28, 31, 34, 167, 132, 139, 146, 153, 160, 265, 220, 229, 238, 247, 256},
65{23, 19, 9, 11, 13, 15, 17, 125, 95, 101, 107, 113, 119, 211, 171, 179, 187, 195, 203},
66{27, 62, 67, 72, 77, 82, 87, 270, 225, 234, 243, 252, 261, 392, 337, 348, 359, 370, 381},
67{12, 38, 42, 46, 50, 54, 58, 216, 176, 184, 192, 200, 208, 326, 276, 286, 296, 306, 316},
68{11, 20, 23, 26, 29, 32, 35, 168, 133, 140, 147, 154, 161, 266, 221, 230, 239, 248, 257},
69{10, 8, 10, 12, 14, 16, 18, 126, 96, 102, 108, 114, 120, 212, 172, 180, 188, 196, 204},
70{22, 2, 3, 4, 5, 6, 7, 90, 65, 70, 75, 80, 85, 164, 129, 136, 143, 150, 157},
71{28, 93, 99, 105, 111, 117, 123, 271, 226, 235, 244, 253, 262, 393, 338, 349, 360, 371, 382},
72{13, 63, 68, 73, 78, 83, 88, 217, 177, 185, 193, 201, 209, 327, 277, 287, 297, 307, 317},
73{ 4, 39, 43, 47, 51, 55, 59, 169, 134, 141, 148, 155, 162, 267, 222, 231, 240, 249, 258},
74{ 3, 21, 24, 27, 30, 33, 36, 127, 97, 103, 109, 115, 121, 213, 173, 181, 189, 197, 205},
75{ 9, 9, 11, 13, 15, 17, 19, 91, 66, 71, 76, 81, 86, 165, 130, 137, 144, 151, 158},
76{21, 3, 4, 5, 6, 7, 2, 61, 41, 45, 49, 53, 57, 123, 93, 99, 105, 111, 117},
77{29, 130, 137, 144, 151, 158, 165, 218, 227, 236, 245, 254, 263, 394, 339, 350, 361, 372, 383},
78{14, 94, 100, 106, 112, 118, 124, 170, 178, 186, 194, 202, 210, 328, 278, 288, 298, 308, 318},
79{ 5, 64, 69, 74, 79, 84, 89, 128, 135, 142, 149, 156, 163, 268, 223, 232, 241, 250, 259},
80{ 1, 40, 44, 48, 52, 56, 60, 92, 98, 104, 110, 116, 122, 214, 174, 182, 190, 198, 206},
81{ 2, 22, 25, 28, 31, 34, 37, 62, 67, 72, 77, 82, 87, 166, 131, 138, 145, 152, 159},
82{ 8, 10, 12, 14, 16, 18, 8, 38, 42, 46, 50, 54, 58, 124, 94, 100, 106, 112, 118},
83{20, 11, 13, 15, 17, 19, 9, 20, 23, 26, 29, 32, 35, 88, 63, 68, 73, 78, 83},
84{30, 131, 138, 145, 152, 159, 166, 219, 228, 237, 246, 255, 264, 329, 279, 289, 299, 309, 319},
85{15, 95, 101, 107, 113, 119, 125, 171, 179, 187, 195, 203, 211, 269, 224, 233, 242, 251, 260},
86{ 6, 65, 70, 75, 80, 85, 90, 129, 136, 143, 150, 157, 164, 215, 175, 183, 191, 199, 207},
87{ 7, 41, 45, 49, 53, 57, 61, 93, 99, 105, 111, 117, 123, 167, 132, 139, 146, 153, 160},
88{19, 23, 26, 29, 32, 35, 20, 63, 68, 73, 78, 83, 88, 125, 95, 101, 107, 113, 119},
89{37, 24, 27, 30, 33, 36, 21, 39, 43, 47, 51, 55, 59, 89, 64, 69, 74, 79, 84},
90{31, 132, 139, 146, 153, 160, 167, 220, 229, 238, 247, 256, 265, 270, 225, 234, 243, 252, 261},
91{16, 96, 102, 108, 114, 120, 126, 172, 180, 188, 196, 204, 212, 216, 176, 184, 192, 200, 208},
92{17, 66, 71, 76, 81, 86, 91, 130, 137, 144, 151, 158, 165, 168, 133, 140, 147, 154, 161},
93{18, 42, 46, 50, 54, 58, 38, 94, 100, 106, 112, 118, 124, 126, 96, 102, 108, 114, 120},
94{36, 43, 47, 51, 55, 59, 39, 64, 69, 74, 79, 84, 89, 90, 65, 70, 75, 80, 85},
95{32, 133, 140, 147, 154, 161, 168, 221, 230, 239, 248, 257, 266, 217, 177, 185, 193, 201, 209},
96{33, 97, 103, 109, 115, 121, 127, 173, 181, 189, 197, 205, 213, 169, 134, 141, 148, 155, 162},
97{35, 68, 73, 78, 83, 88, 63, 95, 101, 107, 113, 119, 125, 91, 66, 71, 76, 81, 86}
98 };
99
100//
101// corrispondence between pixels in cell and lut (pix numbering starts from 1)
102//
103static const Int_t pixels_in_lut[3][12] = {
104{ 1, 2, 3, 4, 6, 7, 8, 9, 12, 13, 14, 15},
105{34, 29, 23, 16, 30, 24, 17, 10, 25, 18, 11, 5},
106{35, 31, 26, 20, 19, 32, 27, 21, 36, 33, 28, 22},
107 };
108
109// --------------------------------------------------------------------------
110//
111// Default constructor
112//
113MTrigLvl2::MTrigLvl2(const char *name, const char *title)
114{
115 fName = name ? name : ClassName();
116 fTitle = title;
117
118 *fLog << "created MTrigLvl2" << endl;
119
120 //
121 // Initialization of the fPixels array to zero
122 //
123 memset (fPixels,0,36*19);
124
125}
126
127// --------------------------------------------------------------------------
128//
129// Print functions for debugging and testing
130//
131//
132// Print out the pixel number of a given trigger cell
133//
134// Print a table with the status (pixel is fired or not after Lvl1) for all
135// the pixels in all the trigger cells
136//
137void MTrigLvl2::Print(Int_t cell) const
138{
139 if (cell >-1) {
140 for (int i=0;i<36;i++)
141 {
142 *fLog << pixels_in_cell[i][cell]-1 << endl;
143 }
144 }
145 else {
146 for(int i=0; i<36; i++){
147 for(int j=0; j<9; j++){
148 // *fLog.width(3);
149 *fLog << pixels_in_cell[i][j]-1 << ":" << fPixels[i][j] << "\t ";
150 }
151 *fLog << endl;
152 }
153 }
154}
155
156// --------------------------------------------------------------------------
157//
158// Take the information supplied by the Lvl1 (it reads from the object MMcTrig
159// i the status of all pixels after Lvl1) and pass it to the Lvl2 (fill the
160// array fPixels)
161//
162//
163void MTrigLvl2::SetLv1(MMcTrig *trig)
164{
165 if (!trig)
166 return;
167
168 fMcTrig = trig;
169
170 //fMcTrig->PrintPixelsFirstLevel();
171
172 for(int i=0; i<36; i++){
173 for(int j=0; j<19; j++){
174 int pixel = pixels_in_cell[i][j]-1;
175 fPixels[i][j] = (fMcTrig->IsPixelFired(pixel,0)) ? 1 : 0;
176 }
177 }
178}
179
180
181// --------------------------------------------------------------------------
182//
183// Set the trigger status ( pixel fired(=1) or not(=0) ) manually for a given
184// pixel of a given cell
185//
186//
187void MTrigLvl2::SetPixelFired(Int_t pixel, Int_t fired)
188{
189 for(int i=0; i<36; i++){
190 for(int j=0; j<19; j++){
191 if(pixels_in_cell[i][j]-1==pixel) fPixels[i][j]=fired;
192 }
193 }
194}
195
196
197// --------------------------------------------------------------------------
198//
199// Display the MAGIC Camera a draw the pixels corresponding to a given cell
200// (preliminary) <to be fixed>
201//
202void MTrigLvl2::DrawCell(Int_t cell)
203{
204
205 if(cell>18) return;
206
207 //
208 // Use MCamDisplay class variable for avoiding to create a MCamDisplay each
209 // time this function is called. Also, now all the hexagons are drawn in
210 // the same camera pad
211 //
212 if (!fGeomcam)
213 fGeomcam = new MGeomCamMagic;
214 if (!fCam)
215 {
216 fCam = new MCamDisplay(fGeomcam);
217 fCam->Draw();
218 fCam->DrawPixelNumbers();
219 }
220
221 //fCam->Draw();
222 fCam->Reset();
223
224 int color=0;
225
226 for(int i=0; i<36; i++){
227 color = (fPixels[i][cell]) ? 5 : 3;
228 fCam->SetPix( pixels_in_cell[i][cell]-1, color, 1, 5 );
229 }
230
231 //
232 // Update the display (paint the camera with the new colors)
233 //
234 gPad->Modified();
235 gPad->Update();
236}
237
238
239
240// --------------------------------------------------------------------------
241//
242// Display the MAGIC camera and draw all the pixel fired after Lvl1
243// (preliminary) <to be fixed>
244//
245//
246void MTrigLvl2::DrawLv1()
247{
248 //
249 // Use MCamDisplay class variable for avoiding to create a MCamDisplay each
250 // time this function is called. Also, now all the hexagons are drawn in
251 // the same camera pad
252 //
253 if (!fGeomcam)
254 fGeomcam = new MGeomCamMagic;
255 if (!fCam)
256 {
257 fCam = new MCamDisplay(fGeomcam);
258 fCam->Draw();
259 fCam->DrawPixelNumbers();
260 }
261
262 //fCam->Draw();
263 //fCam->Reset();
264
265 //
266 // Set the array of colors for each pixel (that will be painted after
267 // updating the dispaly)
268 //
269 int color=0;
270
271 for(int i=0; i<577; i++)
272 {
273 color = (fMcTrig->IsPixelFired(i,0)) ? 5 : 3;
274 fCam->SetPix( i, color, 1, 5 );
275 }
276
277 //
278 // Update the display (paint the camera with the new colors)
279 //
280 gPad->Modified();
281 gPad->Update();
282
283}
284
285// --------------------------------------------------------------------------
286//
287// For a given cell, just count how many pixels have been fired after Lvl1
288//
289Int_t MTrigLvl2::GetCellNumberFired(int cell)
290{
291 int size=0;
292
293 for(int i=0; i<36; i++){
294 size += fPixels[i][cell];
295 }
296
297 return size;
298
299}
300
301
302// --------------------------------------------------------------------------
303//
304// Find the cell which the bigger number of fired pixels
305//
306//
307Int_t MTrigLvl2::GetBiggerFiredCell()
308{
309 int size=-1;
310 int cell=-1;
311
312 for(int j=0; j<19; j++){
313 if (GetCellNumberFired(j) > size) {
314 size = GetCellNumberFired(j);
315 cell = j;
316 }
317 }
318
319 *fLog << "size " <<size <<" in cell " << cell << endl;
320
321 return cell;
322
323}
324
325// --------------------------------------------------------------------------
326//
327// Calculate the LutPseudoSize of one event, defined as the higher number
328// of compact pixel in the Luts of the trigger cells.
329// neighpix is the number of Next-Neighbors which defines the compact pixel
330// topology (it can be 2-NN or 3-NN)
331//
332//
333Int_t MTrigLvl2::GetLutPseudoSize(int neighpix)
334{
335 int size=0;
336 int cell=-1;
337 int lut=-1;
338
339 if (neighpix >3 || neighpix < 2) return(0);
340
341 for(int j=0; j<19; j++){
342 for(int i=0; i<3; i++){
343 if (GetLutCompactPixel(j,i,neighpix) > size) {
344 size = GetLutCompactPixel(j,i,neighpix);
345 cell = j;
346 lut = i;
347 }
348 }
349 }
350
351 *fLog <<"Max cell: " << cell+1 << " Max Lut: " << lut+1 << " PseudoSize: " << size <<endl;
352
353 fLutPseudoSize = size;
354
355 return fLutPseudoSize;
356}
357
358
359// --------------------------------------------------------------------------
360//
361// Identify compact pixels in one LUT and calculate the LutPseudoSize
362// (=number of compact pixels in one LUT)
363// neighpix is the number of Next-Neighbors which defines the compact pixel
364// topology (it can be 2NN or 3NN)
365//
366Int_t MTrigLvl2::GetLutCompactPixel(int cell, int lut, int neighpix)
367{
368 int size=0;
369 int lutpix, a[12];
370
371 if (neighpix >3 || neighpix < 2) return(0);
372
373 // LUT 1 and 2 are similar; LUT 3 differs
374
375 for(int j=0; j<12; j++){
376 lutpix = pixels_in_lut[lut][j]-1;
377 // *fLog << "j=" <<j<<" lutpix="<<lutpix<<" Cell="<<cell<<endl;
378 a[j] = fPixels[lutpix][cell];
379 }
380
381 //
382 // Look for compact pixels 2NN
383 //
384 if (neighpix==2){
385
386 // case Lut 1 and 2
387 if (lut == 0 || lut == 1){
388 if (a[0] && a[1] && a[4])
389 size ++;
390 if (a[1] && ((a[0] && a[4]) ||
391 (a[4] && a[5]) ||
392 (a[5] && a[2]) ))
393 size ++;
394 if (a[2] && ((a[1] && a[5]) ||
395 (a[5] && a[6]) ||
396 (a[6] && a[3]) ))
397 size ++;
398 if (a[3] && ((a[2] && a[6]) ||
399 (a[6] && a[7]) ))
400 size ++;
401 if (a[4] && ((a[0] && a[1]) ||
402 (a[1] && a[5]) ||
403 (a[5] && a[8]) ))
404 size ++;
405 if (a[5] && ((a[1] && a[2]) ||
406 (a[2] && a[6]) ||
407 (a[6] && a[9]) ||
408 (a[9] && a[8]) ||
409 (a[8] && a[4]) ||
410 (a[4] && a[1]) ))
411 size ++;
412 if (a[6] && ((a[2] && a[3]) ||
413 (a[3] && a[7]) ||
414 (a[7] && a[10]) ||
415 (a[10] && a[9]) ||
416 (a[9] && a[5]) ||
417 (a[5] && a[2]) ))
418 size ++;
419 if (a[7] && ((a[3] && a[6]) ||
420 (a[6] && a[10]) ||
421 (a[10] && a[11]) ))
422 size ++;
423 if (a[8] && ((a[4] && a[5]) ||
424 (a[5] && a[9]) ))
425 size ++;
426 if (a[9] && ((a[8] && a[5]) ||
427 (a[5] && a[6]) ||
428 (a[6] && a[10]) ))
429 size ++;
430 if (a[10] && ((a[9] && a[6]) ||
431 (a[6] && a[7]) ||
432 (a[7] && a[11]) ))
433 size ++;
434 if (a[11] && a[7] && a[10])
435 size ++;
436 }
437
438 // case Lut 3
439 if (lut==2) {
440 if (a[0] && a[1] && a[5])
441 size ++;
442 if (a[1] && ((a[0] && a[5]) ||
443 (a[5] && a[2]) ))
444 size ++;
445 if (a[2] && ((a[1] && a[5]) ||
446 (a[5] && a[6]) ||
447 (a[3] && a[4]) ||
448 (a[6] && a[3]) ))
449 size ++;
450 if (a[3] && ((a[2] && a[6]) ||
451 (a[6] && a[7]) ||
452 (a[2] && a[4]) ))
453 size ++;
454 if (a[4] && ((a[2] && a[3]) ))
455 size ++;
456 if (a[5] && ((a[1] && a[2]) ||
457 (a[2] && a[6]) ||
458 (a[6] && a[9]) ||
459 (a[9] && a[8]) ))
460 size ++;
461 if (a[6] && ((a[2] && a[3]) ||
462 (a[3] && a[7]) ||
463 (a[7] && a[10]) ||
464 (a[10] && a[9]) ||
465 (a[9] && a[5]) ||
466 (a[5] && a[2]) ))
467 size ++;
468 if (a[7] && ((a[3] && a[6]) ||
469 (a[6] && a[10]) ||
470 (a[10] && a[11]) ))
471 size ++;
472 if (a[8] && a[5] && a[9])
473 size ++;
474 if (a[9] && ((a[8] && a[5]) ||
475 (a[5] && a[6]) ||
476 (a[6] && a[10]) ))
477 size ++;
478 if (a[10] && ((a[9] && a[6]) ||
479 (a[6] && a[7]) ||
480 (a[7] && a[11]) ))
481 size ++;
482 if (a[11] && a[7] && a[10])
483 size ++;
484 }
485 }
486
487 //
488 // Look for compact pixels 3NN
489 //
490 if (neighpix==3){
491
492 // case Lut 1 and 2
493 if (lut == 0 || lut == 1){
494 if (a[0] && a[1] && a[4] && a[5]) // pix 0 is compact if there is a 4NN
495 size ++;
496 if (a[1] && ((a[0] && a[4] && a[5]) ||
497 (a[2] && a[4] && a[5]) ))
498 size ++;
499 if (a[2] && ((a[1] && a[5] && a[6]) ||
500 (a[5] && a[6] && a[3]) ))
501 size ++;
502 if (a[3] && (a[2] && a[6] && a[7] ))
503 size ++;
504 if (a[4] && ((a[0] && a[1] && a[5]) ||
505 (a[1] && a[5] && a[8]) ))
506 size ++;
507 if (a[5] && ((a[1] && a[2] && a[6]) ||
508 (a[2] && a[6] && a[9]) ||
509 (a[6] && a[9] && a[8]) ||
510 (a[9] && a[8] && a[4]) ||
511 (a[8] && a[4] && a[1]) ||
512 (a[4] && a[1] && a[2]) ))
513 size ++;
514 if (a[6] && ((a[2] && a[3] && a[7]) ||
515 (a[3] && a[7] && a[10]) ||
516 (a[7] && a[10] && a[9]) ||
517 (a[10] && a[9] && a[5]) ||
518 (a[9] && a[5] && a[2]) ||
519 (a[5] && a[2] && a[3]) ))
520 size ++;
521 if (a[7] && ((a[3] && a[6] && a[10]) ||
522 (a[6] && a[10] && a[11]) ))
523 size ++;
524 if (a[8] && (a[4] && a[5] && a[9] ))
525 size ++;
526 if (a[9] && ((a[8] && a[5] && a[6]) ||
527 (a[5] && a[6] && a[10]) ))
528 size ++;
529 if (a[10] && ((a[9] && a[6] && a[7]) ||
530 (a[6] && a[7] && a[11]) ))
531 size ++;
532 if (a[11] && a[7] && a[10] && a[6]) //pix 0 is compact if there is a 4NN
533 size ++;
534 }
535
536 // case Lut 3
537 if (lut==2) {
538 if (a[0] && a[1] && a[5] && a[8]) // pix 0 is compact if there is a 4NN
539 size ++;
540 if (a[1] && (a[0] && a[5] && a[2])) //pix 0 is compact if there is a 4NN
541 size ++;
542 if (a[2] && ((a[1] && a[5] && a[6]) ||
543 (a[3] && a[5] && a[6]) ||
544 (a[6] && a[3] && a[4]) ))
545 size ++;
546 if (a[3] && ((a[2] && a[4] && a[6]) ||
547 (a[2] && a[6] && a[7]) ))
548 size ++;
549 if (a[4] && (a[2] && a[3] && a[6] ))
550 size ++;
551 if (a[5] && ((a[1] && a[2] && a[6]) ||
552 (a[2] && a[6] && a[9]) ||
553 (a[6] && a[9] && a[8]) ))
554 size ++;
555 if (a[6] && ((a[2] && a[3] && a[7]) ||
556 (a[3] && a[7] && a[10]) ||
557 (a[7] && a[10] && a[9]) ||
558 (a[10] && a[9] && a[5]) ||
559 (a[9] && a[5] && a[2]) ||
560 (a[5] && a[2] && a[3]) ))
561 size ++;
562 if (a[7] && ((a[3] && a[6] && a[10]) ||
563 (a[6] && a[10] && a[11]) ))
564 size ++;
565 if (a[8] && a[5] && a[9] && a[6]) //pix 0 is compact if there is a 4NN
566 size ++;
567 if (a[9] && ((a[8] && a[5] && a[6]) ||
568 (a[5] && a[6] && a[10]) ))
569 size ++;
570 if (a[10] && ((a[9] && a[6] && a[7]) ||
571 (a[6] && a[7] && a[11]) ))
572 size ++;
573 if (a[11] && a[7] && a[10] && a[6]) //pix 0 is compact if there is a 4NN
574 size ++;
575 }
576 }
577
578
579 return size;
580}
581
582
Note: See TracBrowser for help on using the repository browser.