/[PAMELA software]/eventviewer/flight/src/FEventViewerCore.cpp
ViewVC logotype

Contents of /eventviewer/flight/src/FEventViewerCore.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations) (download)
Tue Apr 17 16:05:22 2007 UTC (17 years, 10 months ago) by mocchiut
Branch: MAIN
CVS Tags: v2r01
Changes since 1.8: +6 -5 lines
Strange bug (lead to crash) which appears using ROOT >= 5.14 fixed

1 //-------------------------------------------------------------------------------------------------------------------------------------------------------
2 //
3 // FEventViewer.c version 1.03 (2006-04-04)
4 //
5 // Shows PAMELA events - Emiliano Mocchiutti
6 //
7 //-------------------------------------------------------------------------------------------------------------------------------------------------------
8 //
9 //
10 // Standard use:
11 //
12 // bash> EventViewer
13 //
14 // For further informations use:
15 //
16 // EventViewer --help
17 //
18 // or
19 //
20 // EventViewer --version
21 //
22 //-------------------------------------------------------------------------------------------------------------------------------------------------------
23 //
24 // Changelog:
25 //
26 // 1.02 - 1.03 (2006-04-04): Make it possible to select events with the calorimeter also when generating level1 from level0.
27 //
28 // 1.01 - 1.02 (2006-03-22): Read calorimeter ADC2MIP flight conversion file. Do not install FEventviewer.cxx!
29 //
30 // 1.00 - 1.01 (2006-03-09): Flight version, read unique YODA file. Many capabilities disabled at the moment (reads only LEVEL0 data).
31 //
32 // 0.00 - 1.00 (2006-03-09): Clone of EventViewer.c v9r01.
33 //
34 #include <math.h>
35 #include <stdio.h>
36 //
37 #include <iostream>
38 #include <iomanip>
39 #include <fstream>
40 #if (__GNUC__ == 3) && (__GNUC_MINOR__ == 2)
41 char* operator+( std::streampos&, char* );
42 #endif
43 //
44 #include <TObjectTable.h>
45 #include <TGClient.h>
46 #include <TGButton.h>
47 #include <TGComboBox.h>
48 #include <TGLabel.h>
49 #include <TGTextEntry.h>
50 #include <TGFrame.h>
51 #include <TGButtonGroup.h>
52 #include <TGProgressBar.h>
53 #include <TGMsgBox.h>
54 #include <TGComboBox.h>
55 //
56 #include <TTree.h>
57 #include <TClassEdit.h>
58 #include <TObject.h>
59 #include <TList.h>
60 #include <TSystem.h>
61 #include <TSystemDirectory.h>
62 #include <TString.h>
63 #include <TFile.h>
64 #include <TClass.h>
65 #include <TCanvas.h>
66 #include <TH1.h>
67 #include <TH1F.h>
68 #include <TH2D.h>
69 #include <TLatex.h>
70 #include <TPad.h>
71 #include <TPaveLabel.h>
72 #include <TLine.h>
73 #include <TPolyLine.h>
74 #include <TChain.h>
75 #include <TApplication.h>
76 #include <TVirtualX.h>
77 #include <TGClient.h>
78 #include <TGWindow.h>
79 #include <TEllipse.h>
80 #include <TArrow.h>
81 #include <TStyle.h>
82 //
83 #include <PamelaRun.h>
84 #include <physics/trigger/TriggerEvent.h>
85 extern void stringcopy(TString&, const TString&, Int_t, Int_t);
86 extern void stringappend(TString&, const TString&);
87 #include <FEVpathtoc.h>
88 //
89 #include <FEVpamevcontrol.h>
90 #include <FEVdetector.h>
91 #include <FEventViewer.h>
92 #include <feventvstruct.h>
93 //
94 using namespace std;
95 //
96 Bool_t existfile(TString filename){
97 ifstream myfile;
98 myfile.open(filename.Data());
99 if ( !myfile ){
100 return(false);
101 };
102 myfile.close();
103 return(true);
104 }
105
106 //
107 // MAIN ROUTINE
108 //
109 void ShowEvent(TString filename="help", TString selfile="", TString outDir = ""){
110 Int_t ctrlword = 509;
111 Int_t FORCELEV = -1;
112 TString startingdir = gSystem->WorkingDirectory();
113 //
114 TApplication app("app",0,0);
115 //
116 Bool_t firsttime = true;
117 //
118 Bool_t popup = false;
119 //
120 gROOT->GetListOfCanvases()->Delete();
121 gDirectory->GetList()->Delete();
122 //
123 // here windows dimension (based on the computer screen size) and position and dimension of figures
124 //
125 Int_t xw, yw;
126 UInt_t ww, hw;
127 gVirtualX->GetWindowSize(gClient->GetRoot()->GetId(),xw,yw,ww,hw);
128 Float_t winx = (float)ww*0.80;
129 Float_t winy = (float)hw*0.80; // 95
130 Float_t winrap = winx/winy;
131 //
132 // book the canvas
133 //
134 TCanvas *figure = new TCanvas("PAMELA event viewer", "PAMELA event viewer",(int)winx,(int)winy);
135 //
136 // create the PAMELA detector
137 //
138 FEVdetector *pamela = new FEVdetector(filename,selfile,ctrlword,*figure);
139 //
140 // Pop up the GUI
141 //
142 PAMevcontrol *pamgui = 0;
143 //
144 pamgui = new PAMevcontrol(gClient->GetRoot(),400,800,pamela->var,pamela->level,*figure);
145 popup = true;
146 pamela->SetGUIPtr(*pamgui);
147 if ( outDir == "" ) outDir = startingdir;
148 //
149 TTree *otr0 = 0;
150 TTree *otr1 = 0;
151 TTree *otr2 = 0;
152 TTree *otr3 = 0;
153 TTree *otr4 = 0;
154 TTree *otr5 = 0;
155 TTree *otr6 = 0;
156 TTree *otr7 = 0;
157 TTree *otr8 = 0;
158 //
159 pamela->var.fl0 = false;
160 Int_t i = 0;
161 Int_t isOK = 0;
162 //
163 restart:
164 //
165 // set boolean variables
166 //
167 pamela->var.restart = false;
168 pamela->var.waitforever = false;
169 pamela->var.jumprog = true;
170 pamela->var.jumpen = false;
171 pamela->var.goon = false;
172 pamela->var.refresh = false;
173 pamela->var.alrforc = false;
174 //
175 // check if we have an input filename
176 //
177 if ( filename.Data() == "" || !strcmp(filename.Data(),"help") ){
178 pamela->var.waitforever = true;
179 };
180 //
181 // chek if we are forcing level0
182 //
183 if ( pamela->var.fl0 == true ){
184 FORCELEV = 0;
185 } else {
186 FORCELEV = -1;
187 };
188 //
189 // Define some variables
190 //
191 pamela->var.bw = 0;
192 pamela->var.xxvc = 0.20;
193 pamela->var.yxvc = 0.44;
194 pamela->var.xyvc = 0.815;
195 pamela->var.yyvc = 0.44;
196 pamela->var.sfx = 0.81/winrap;
197 pamela->var.sfy = 0.81;
198 pamela->var.nds4 = pamela->var.sfx;
199 pamela->var.xcat = 0.515;
200 pamela->var.ycat = 0.74;
201 pamela->var.tracknds4 = 1;
202 figure->Range(0.,0.,1.,1.);
203 gStyle->SetOptDate(0);
204 gStyle->SetOptStat(0);
205 gStyle->SetLabelSize(0);
206 gStyle->SetNdivisions(1,"X");
207 gStyle->SetNdivisions(1,"Y");
208 //
209 if ( i < 0 ){
210 i = -i;
211 } else {
212 i = 0;
213 };
214 isOK = 0;
215 //
216 // from here to refresh
217 //
218 refresh:
219 //
220 // reset pointers
221 //
222 TFile *headerFile = 0;
223 TChain *otr = 0;
224 TTree *L0 = 0;
225 //
226 // gROOT->Reset();
227 //
228 // set selection file variables
229 //
230 if ( pamela->var.refresh ){
231 if ( pamela->var.selex ){
232 // pamela->var.selex = true; //<<<<<<<<<<<<<<<<<<<<<<<<<<?????????????????????
233 selfile = pamela->var.thefilter.Data();
234 };
235 };
236 //
237 //
238 // if ( pamela->var.fl0 == true ) {
239 // FORCELEV = 0;
240 // } else {
241 // if ( pamela->var.refresh ) FORCELEV = -1; //<<<<<<<<<<<<<<<<<<<<<<<<<<?????????????????????
242 // };
243 //
244 // check the detectors to be shown
245 //
246 // if ( !pamela->var.refresh ) pamela->checkctrlword();
247 //pamela->checkctrlword();
248 //
249 // open a dialog if the program is launched without input filename
250 //
251 if ( firsttime ){
252 firsttime = false;
253 if ( filename == "" ) pamgui->DIALOG(0," Insert the filename and press load to start ");
254 };
255 //
256 // WAIT for an input filename
257 //
258 while( pamela->var.waitforever ) {
259 if ( !gROOT->GetListOfCanvases()->FindObject(figure) ) {
260 pamgui->Terminate();
261 };
262 gSystem->ProcessEvents();
263 gSystem->Sleep(10);
264 };
265 //
266 if ( pamela->var.restart ){
267 filename = pamela->var.thefilename.Data();
268 goto restart;
269 };
270 //
271 // check if we are forcing level0 data
272 //
273 if ( FORCELEV != -1 ) {
274 printf("\n WARNING: FORCING LEVEL%i DATA \n\n",FORCELEV);
275 if ( !pamela->var.alrforc ) {
276 pamgui->DIALOG(1," Forcing LEVEL0 data ");
277 pamela->var.alrforc = true;
278 };
279 };
280 //
281 // LOAD SELECTION FILE
282 //
283 if ( selfile == "" ){
284 //if ( !pamela->var.selex ) pamgui->DIALOG(0," Selection file unloaded ");
285 if ( pamela->var.selex ) pamgui->DIALOG(0," Selection file unloaded ");
286 pamela->var.selex = false;
287 } else {
288 //
289 // determine where to find the headers
290 //
291 gROOT->Reset();
292 stringstream paminc;
293 paminc.str("");
294 const char *testinc = pathtoinclude();
295 paminc << testinc;
296 //
297 stringstream carica;
298 //
299 // load the structure header
300 //
301 carica.str("");
302 carica << paminc.str().c_str() << "/feventvstruct.h";
303 gROOT->LoadMacro(carica.str().c_str());
304 // carica.str("");
305 // carica << paminc.str().c_str() << "/CaloNuclei.h";
306 // gROOT->LoadMacro(carica.str().c_str());
307 //
308 // load the selection macro
309 //
310 Int_t chkload = gROOT->LoadMacro(selfile);
311 //
312 pamela->var.selex = false;
313 //
314 if ( chkload ){
315 //
316 // not able to open the selection file
317 //
318 stringstream dialog;
319 dialog.str("");
320 dialog << pamela->var.thefilter.Data();
321 dialog << " : no such file!";
322 pamgui->DIALOG(2,dialog.str().c_str());
323 printf("\n\n ERROR! cannot read the selection file you give me as input! \n");
324 pamela->var.selex = false;
325 printf("\n WARNING! no selection file loaded! \n\n");
326 pamgui->DIALOG(1," No selection file loaded! ");
327 selfile = "";
328 //
329 // clear field in the GUI
330 //
331 pamgui->clearselfi();
332 } else {
333 //
334 // ok, selection file loaded
335 //
336 printf("\n\n Selection file loaded \n\n The first event will be shown anyway. \n\n");
337 //
338 if ( !pamela->var.selex ) pamgui->DIALOG(0," Selection file successfully loaded ");
339 //
340 pamela->var.selex = true;
341 };
342 };
343 //
344 // LOAD FILES
345 //
346 //
347 // if ( headerFile ) headerFile->Close();
348 // if ( otr ) otr->Delete();
349 // if ( L0 ) L0->Delete();
350
351 //
352 // check if user has given as input a correct path
353 //
354 ifstream myfile;
355 myfile.open(filename.Data());
356 if ( !myfile ){
357 if ( filename != "" ){
358 printf("ERROR: no such file, exiting...\n");
359 stringstream hfile;
360 hfile.str("");
361 hfile << filename.Data();
362 hfile << " : no such file! ";
363 pamgui->DIALOG(2,hfile.str().c_str());
364 };
365 pamela->var.waitforever = true;
366 goto refresh;
367 };
368 myfile.close();
369 //
370 // ok, open file and determine if it is a YODA or DARTHVADER file
371 //
372
373 headerFile=new TFile(filename.Data());
374 if ( FORCELEV == 0 ){
375 pamela->level.file = 0;
376 L0 = (TTree*)headerFile->Get("Physics");
377 if ( !L0 ){
378 printf("ERROR: no Physics tree...\n");
379 pamgui->DIALOG(2,"No Physics tree in this file");
380 pamela->var.waitforever = true;
381 goto refresh;
382 }
383 } else {
384 pamela->level.file = 2;
385 otr0 = (TTree*)headerFile->Get("Trigger");
386 otr1 = (TTree*)headerFile->Get("Calorimeter");
387 otr2 = (TTree*)headerFile->Get("Tracker");
388 otr3 = (TTree*)headerFile->Get("NeutronD");
389 otr4 = (TTree*)headerFile->Get("OrbitalInfo");
390 otr5 = (TTree*)headerFile->Get("S4");
391 otr6 = (TTree*)headerFile->Get("ToF");
392 otr7 = (TTree*)headerFile->Get("Run");
393 otr8 = (TTree*)headerFile->Get("Anticounter");
394 if ( !otr0 && !otr1 && !otr2 && !otr3 && !otr4 && !otr5 && !otr6 && !otr7 && !otr8 ){
395 L0 = (TTree*)headerFile->Get("Physics");
396 pamela->level.file = -1;
397 } else {
398 stringstream dddec;
399 dddec.str("");
400 dddec << " +ALL +RUN +CAL1 -TRKh -TRK1 ";
401 if ( !otr0 ){
402 dddec << " -TRG ";
403 pamela->var.TRG = 0;
404 otr0 = otr1;
405 };
406 if ( !otr1 ){
407 dddec << " -CAL ";
408 pamela->var.CALO = 0;
409 if ( !otr0 ) otr0 = otr2;
410 };
411 if ( !otr2 ){
412 dddec << " -TRK2 -TRK ";
413 pamela->var.TRK = 0;
414 if ( !otr0 ) otr0 = otr3;
415 };
416 if ( !otr3 ){
417 dddec << " -ND ";
418 pamela->var.ND = 0;
419 if ( !otr0 ) otr0 = otr4;
420 };
421 if ( !otr4 ){
422 dddec << " -ORB ";
423 pamela->var.ORB = 0;
424 if ( !otr0 ) otr0 = otr5;
425 };
426 if ( !otr5 ){
427 dddec << " -S4 ";
428 pamela->var.S4 = 0;
429 if ( !otr0 ) otr0 = otr6;
430 };
431 if ( !otr6 ){
432 dddec << " -TOF ";
433 pamela->var.TOF = 0;
434 if ( !otr0 ) otr0 = otr8;
435 };
436 if ( !otr7 ){
437 dddec << " -RUN ";
438 pamela->var.RUN = 0;
439 };
440 if ( !otr8 ){
441 dddec << " -AC ";
442 pamela->var.AC = 0;
443 };
444 pamela->SetDDEC(dddec.str().c_str());
445 };
446 if ( !otr0 && !otr1 && !otr2 && !otr3 && !otr4 && !otr5 && !otr6 && !otr7 && !otr8 && !L0 ){
447 pamela->level.file = -1;
448 printf("ERROR: nor Physics nor Run tree...\n");
449 pamgui->DIALOG(2,"Nor Physics nor Run tree in this file");
450 pamela->var.waitforever = true;
451 goto refresh;
452 };
453 };
454 headerFile->Close("R");
455 //
456 if ( pamela->level.file != 2 ){
457 printf(" This is a YODA (level0) file \n");
458 } else {
459 printf(" This is a DARTHVADER (level2) file \n");
460 };
461 //
462 // Disable on the GUI the buttons that cannot be used with this file
463 //
464 pamgui->CheckLevel();
465 //
466 // Load the file
467 //
468 if ( otr0 || L0 ){
469 otr = pamela->Load(filename.Data());
470 if ( !otr ){
471 pamela->level.file = -1;
472 printf("ERROR: problems opening file...\n");
473 pamgui->DIALOG(2,"Problems opening file");
474 pamela->var.waitforever = true;
475 goto refresh;
476 };
477 } else {
478 pamela->level.file = -1;
479 printf("ERROR: problems with TTree while opening file...\n");
480 pamgui->DIALOG(2,"Problems opening file");
481 pamela->var.waitforever = true;
482 goto refresh;
483 };
484 //
485 printf("\n");
486 //
487 // get the number of entries
488 //
489 if ( !otr ) printf(" AGH! \n");
490 //
491 Long64_t nevents = otr->GetEntries();
492 printf(" The file contains %i physics events \n",(int)nevents);
493 //
494 // check we have at least one event
495 //
496 if (nevents<=0) {
497 // headerFile->Close();
498 printf("The file is empty, exiting...\n");
499 pamgui->DIALOG(0," The file contains no physics data! ");
500 pamela->var.waitforever = true;
501 goto refresh;
502 }
503 //
504 // Check that given input are inside the boundary conditions
505 //
506 pamela->minevent = 0;
507 pamela->maxevent = nevents - 1;
508 //
509 // Determine the boundaries
510 //
511 pamela->GetWindow();
512 Int_t lastevno = pamela->lastevno;
513 Int_t firstevno = pamela->firstevno;
514 //
515 // display the first event (unless we are refreshing only the window)
516 //
517 if ( !pamela->var.refresh ) i = pamela->minevent;
518 pamela->var.refresh = false;
519 //
520 pamgui->RefreshButtons();
521 //
522 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
523 // MAIN LOOP STARTS HERE:
524 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
525 //
526 while ( 1 ){
527 //
528 // update progress bar
529 //
530 if ( popup ) pamgui->increment((float)(i+1)*100./(float)nevents);
531 //
532 // clear canvas and variables
533 //
534 pamela->ClearVariables();
535 //
536 // get entry i
537 //
538 pamela->GetEntry(i);
539 //
540 // call the filter to select events (if filter file is given)
541 //
542 isOK = pamela->SelectEvent();
543 //
544 // if the event is selected go on
545 //
546 if ( isOK ) {
547 //
548 // reset working variables
549 //
550 printf("\n\n\n\n\n\n\n\n\n\n");
551 pamela->SetEntry(i);
552 pamela->si = i;
553 pamela->var.doflag = 1;
554 pamela->var.i = i;
555 pamela->var.nevents = nevents;
556 pamela->var.lastevno = lastevno;
557 pamela->var.firstevno = firstevno;
558 //
559 printf("\n");
560 //
561 // disable "stop" button in the GUI
562 //
563 pamgui->StopSearching();
564 //
565 // make the canvas editable and clear it
566 //
567 figure->SetEditable(kTRUE);
568 figure->Clear();
569 figure->SetFillColor(10);
570 figure->cd();
571 //
572 // retrieve general info for the event (OBT, pkt_num, etc. etc.)
573 //
574 pamela->GetGeneralInfo();
575 //
576 // display the event
577 //
578 pamela->DisplayEvent();
579 //
580 // prepare the string for the figure filename
581 //
582 char *bw;
583 if ( pamela->var.bw ){
584 bw = "_bw";
585 } else {
586 bw = "";
587 };
588 TString filenm = pamela->var.thefilename;
589 const string fil = gSystem->BaseName(filenm.Data());
590 Int_t posiz = fil.find(".root");
591 TString file2;
592 if ( posiz == -1 ){
593 file2 = gSystem->BaseName(filename.Data());
594 } else {
595 Int_t posiz2 = 0;
596 stringcopy(file2,gSystem->BaseName(filename.Data()),posiz2,posiz);
597 };
598 const char *figrec = file2;
599 const char *outdir = outDir;
600 stringstream figsave;
601 figsave.str("");
602 figsave << outdir << "/";
603 figsave << figrec;
604 figsave << "_ev_";
605 figsave << (pamela->var.i+1);
606 figsave << bw;
607 pamela->var.svas=figsave.str().c_str();
608
609 // printf(" qua %s \n",figsave.str().c_str());
610 //
611 // upgrade the figure filename in the GUI
612 //
613 pamgui->upgrnamfi();
614 //
615 // WAIT for user input
616 //
617 pamela->var.jumpen = false;
618 while( !pamela->var.goon && !pamela->var.refresh && !pamela->var.restart ) {
619 if ( !gROOT->GetListOfCanvases()->FindObject(figure) ) {
620 pamgui->Terminate();
621 };
622 gSystem->ProcessEvents();
623 gSystem->Sleep(10);
624 };
625 //
626 // interpret user input
627 //
628 pamela->var.goon = false;
629 if ( pamela->var.refresh || pamela->var.restart ){
630 if ( pamela->GetL2() ) pamela->GetL2()->Reset();
631 if ( pamela->level.file != 2 ) pamela->GetChain()->Delete();
632 otr = NULL;
633 // if ( headerFile ) headerFile->Close("R");
634 if ( pamela->var.refresh ) goto refresh;
635 if ( pamela->var.restart ){
636 filename = pamela->var.thefilename.Data();
637 goto restart;
638 };
639 };
640 //
641 i = pamela->var.i;
642 if ( i != pamela->si ) pamela->OOBT = 1000000000;
643 if ( pamela->maxevent < i ) {
644 pamela->maxevent = nevents;
645 printf("WARNING: you have chosen an event number out of the starting range.\n Range extended to %i\n\n",pamela->maxevent);
646 };
647 //
648 };
649 //
650 // if the returned entry is -1 it means we must start again from the first event going forward (doflag=1)
651 //
652 if ( pamela->GetThisEntry() == -1 ){
653 pamela->var.doflag = 1;
654 i = pamela->minevent;
655 };
656 //
657 // doflag = 2 means "go backward" (check for lower boundary)
658 //
659 if ( pamela->var.doflag == 2 && i == 0 ) {
660 printf("\n WARNING: Cannot go backward! Going forward. \n");
661 pamela->var.doflag = 1;
662 };
663 if ( pamela->var.doflag == 2 && i>0 ) i--;
664 //
665 // doflag = 1 means go forward (the check on the upper boundary is made in FEVpamevcontrol)
666 //
667 if ( pamela->var.doflag == 1 ) i++;
668 //
669 // if in selection mode, print out a event progress bar in the text window:
670 //
671 if ( !pamela->var.selex || i == pamela->minevent ){
672 // do nothing
673 } else {
674 if ( (pamela->maxevent-pamela->minevent) != 0 ){
675 if((100*(i-pamela->minevent)/(pamela->maxevent-pamela->minevent))<10.){
676 printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8);
677 } else {
678 printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8);
679 };
680 };
681 };
682
683 };
684 //
685 // END OF THE MAIN LOOP AND OF THE MAIN PROGRAM
686 //
687 printf("\n");
688 printf(" ...done! \n\n");
689 return;
690 }

  ViewVC Help
Powered by ViewVC 1.1.23