/[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.10 - (show annotations) (download)
Tue Jul 17 14:40:13 2007 UTC (17 years, 7 months ago) by mocchiut
Branch: MAIN
Changes since 1.9: +30 -3 lines
Added plugins loading feature

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 //
133 //
134 TString plugindir = (TString)gSystem->ExpandPathName("$FEV_PLUGIN");
135 if ( strcmp(plugindir,"$FEV_PLUGIN") ){
136 TString wdir = gSystem->WorkingDirectory();
137 printf("\n\n Plugin directory is %s \n",plugindir.Data());
138 printf(" Loading plugins: \n");
139 //
140 TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(plugindir),plugindir);
141 TList *temp = datadir->GetListOfFiles();
142 TIter next(temp);
143 TSystemFile *questo = 0;
144 Int_t npl = 0;
145 while ( (questo = (TSystemFile*) next()) ) {
146 TString name = questo->GetName();
147 if( name.EndsWith(".so") || name.EndsWith(".o") ){
148 npl++;
149 char *fullpath = gSystem->ConcatFileName(gSystem->DirName(plugindir),gSystem->BaseName(name));
150 gSystem->Load(fullpath);
151 printf(" %i -> %s plugin loaded \n",npl,name.Data());
152 delete fullpath;
153 };
154 }
155 delete temp;
156 delete datadir;
157 };
158 //
159 // book the canvas
160 //
161 TCanvas *figure = new TCanvas("PAMELA event viewer", "PAMELA event viewer",(int)winx,(int)winy);
162 //
163 // create the PAMELA detector
164 //
165 FEVdetector *pamela = new FEVdetector(filename,selfile,ctrlword,*figure);
166 //
167 // Pop up the GUI
168 //
169 PAMevcontrol *pamgui = 0;
170 //
171 pamgui = new PAMevcontrol(gClient->GetRoot(),400,800,pamela->var,pamela->level,*figure);
172 popup = true;
173 pamela->SetGUIPtr(*pamgui);
174 if ( outDir == "" ) outDir = startingdir;
175 //
176 TTree *otr0 = 0;
177 TTree *otr1 = 0;
178 TTree *otr2 = 0;
179 TTree *otr3 = 0;
180 TTree *otr4 = 0;
181 TTree *otr5 = 0;
182 TTree *otr6 = 0;
183 TTree *otr7 = 0;
184 TTree *otr8 = 0;
185 //
186 pamela->var.fl0 = false;
187 Int_t i = 0;
188 Int_t isOK = 0;
189 //
190 restart:
191 //
192 // set boolean variables
193 //
194 pamela->var.restart = false;
195 pamela->var.waitforever = false;
196 pamela->var.jumprog = true;
197 pamela->var.jumpen = false;
198 pamela->var.goon = false;
199 pamela->var.refresh = false;
200 pamela->var.alrforc = false;
201 //
202 // check if we have an input filename
203 //
204 if ( filename.Data() == "" || !strcmp(filename.Data(),"help") ){
205 pamela->var.waitforever = true;
206 };
207 //
208 // chek if we are forcing level0
209 //
210 if ( pamela->var.fl0 == true ){
211 FORCELEV = 0;
212 } else {
213 FORCELEV = -1;
214 };
215 //
216 // Define some variables
217 //
218 pamela->var.bw = 0;
219 pamela->var.xxvc = 0.20;
220 pamela->var.yxvc = 0.44;
221 pamela->var.xyvc = 0.815;
222 pamela->var.yyvc = 0.44;
223 pamela->var.sfx = 0.81/winrap;
224 pamela->var.sfy = 0.81;
225 pamela->var.nds4 = pamela->var.sfx;
226 pamela->var.xcat = 0.515;
227 pamela->var.ycat = 0.74;
228 pamela->var.tracknds4 = 1;
229 figure->Range(0.,0.,1.,1.);
230 gStyle->SetOptDate(0);
231 gStyle->SetOptStat(0);
232 gStyle->SetLabelSize(0);
233 gStyle->SetNdivisions(1,"X");
234 gStyle->SetNdivisions(1,"Y");
235 //
236 if ( i < 0 ){
237 i = -i;
238 } else {
239 i = 0;
240 };
241 isOK = 0;
242 //
243 // from here to refresh
244 //
245 refresh:
246 //
247 // reset pointers
248 //
249 TFile *headerFile = 0;
250 TChain *otr = 0;
251 TTree *L0 = 0;
252 //
253 // gROOT->Reset();
254 //
255 // set selection file variables
256 //
257 if ( pamela->var.refresh ){
258 if ( pamela->var.selex ){
259 // pamela->var.selex = true; //<<<<<<<<<<<<<<<<<<<<<<<<<<?????????????????????
260 selfile = pamela->var.thefilter.Data();
261 };
262 };
263 //
264 //
265 // if ( pamela->var.fl0 == true ) {
266 // FORCELEV = 0;
267 // } else {
268 // if ( pamela->var.refresh ) FORCELEV = -1; //<<<<<<<<<<<<<<<<<<<<<<<<<<?????????????????????
269 // };
270 //
271 // check the detectors to be shown
272 //
273 // if ( !pamela->var.refresh ) pamela->checkctrlword();
274 //pamela->checkctrlword();
275 //
276 // open a dialog if the program is launched without input filename
277 //
278 if ( firsttime ){
279 firsttime = false;
280 if ( filename == "" ) pamgui->DIALOG(0," Insert the filename and press load to start ");
281 };
282 //
283 // WAIT for an input filename
284 //
285 while( pamela->var.waitforever ) {
286 if ( !gROOT->GetListOfCanvases()->FindObject(figure) ) {
287 pamgui->Terminate();
288 };
289 gSystem->ProcessEvents();
290 gSystem->Sleep(10);
291 };
292 //
293 if ( pamela->var.restart ){
294 filename = pamela->var.thefilename.Data();
295 goto restart;
296 };
297 //
298 // check if we are forcing level0 data
299 //
300 if ( FORCELEV != -1 ) {
301 printf("\n WARNING: FORCING LEVEL%i DATA \n\n",FORCELEV);
302 if ( !pamela->var.alrforc ) {
303 pamgui->DIALOG(1," Forcing LEVEL0 data ");
304 pamela->var.alrforc = true;
305 };
306 };
307 //
308 // LOAD SELECTION FILE
309 //
310 if ( selfile == "" ){
311 //if ( !pamela->var.selex ) pamgui->DIALOG(0," Selection file unloaded ");
312 if ( pamela->var.selex ) pamgui->DIALOG(0," Selection file unloaded ");
313 pamela->var.selex = false;
314 } else {
315 //
316 // determine where to find the headers
317 //
318 gROOT->Reset();
319 stringstream paminc;
320 paminc.str("");
321 const char *testinc = pathtoinclude();
322 paminc << testinc;
323 //
324 stringstream carica;
325 //
326 // load the structure header
327 //
328 carica.str("");
329 carica << paminc.str().c_str() << "/feventvstruct.h";
330 gROOT->LoadMacro(carica.str().c_str());
331 // carica.str("");
332 // carica << paminc.str().c_str() << "/CaloNuclei.h";
333 // gROOT->LoadMacro(carica.str().c_str());
334 //
335 // load the selection macro
336 //
337 Int_t chkload = gROOT->LoadMacro(selfile);
338 //
339 pamela->var.selex = false;
340 //
341 if ( chkload ){
342 //
343 // not able to open the selection file
344 //
345 stringstream dialog;
346 dialog.str("");
347 dialog << pamela->var.thefilter.Data();
348 dialog << " : no such file!";
349 pamgui->DIALOG(2,dialog.str().c_str());
350 printf("\n\n ERROR! cannot read the selection file you give me as input! \n");
351 pamela->var.selex = false;
352 printf("\n WARNING! no selection file loaded! \n\n");
353 pamgui->DIALOG(1," No selection file loaded! ");
354 selfile = "";
355 //
356 // clear field in the GUI
357 //
358 pamgui->clearselfi();
359 } else {
360 //
361 // ok, selection file loaded
362 //
363 printf("\n\n Selection file loaded \n\n The first event will be shown anyway. \n\n");
364 //
365 if ( !pamela->var.selex ) pamgui->DIALOG(0," Selection file successfully loaded ");
366 //
367 pamela->var.selex = true;
368 };
369 };
370 //
371 // LOAD FILES
372 //
373 //
374 // if ( headerFile ) headerFile->Close();
375 // if ( otr ) otr->Delete();
376 // if ( L0 ) L0->Delete();
377
378 //
379 // check if user has given as input a correct path
380 //
381 ifstream myfile;
382 myfile.open(filename.Data());
383 if ( !myfile ){
384 if ( filename != "" ){
385 printf("ERROR: no such file, exiting...\n");
386 stringstream hfile;
387 hfile.str("");
388 hfile << filename.Data();
389 hfile << " : no such file! ";
390 pamgui->DIALOG(2,hfile.str().c_str());
391 };
392 pamela->var.waitforever = true;
393 goto refresh;
394 };
395 myfile.close();
396 //
397 // ok, open file and determine if it is a YODA or DARTHVADER file
398 //
399
400 headerFile=new TFile(filename.Data());
401 if ( FORCELEV == 0 ){
402 pamela->level.file = 0;
403 L0 = (TTree*)headerFile->Get("Physics");
404 if ( !L0 ){
405 printf("ERROR: no Physics tree...\n");
406 pamgui->DIALOG(2,"No Physics tree in this file");
407 pamela->var.waitforever = true;
408 goto refresh;
409 }
410 } else {
411 pamela->level.file = 2;
412 otr0 = (TTree*)headerFile->Get("Trigger");
413 otr1 = (TTree*)headerFile->Get("Calorimeter");
414 otr2 = (TTree*)headerFile->Get("Tracker");
415 otr3 = (TTree*)headerFile->Get("NeutronD");
416 otr4 = (TTree*)headerFile->Get("OrbitalInfo");
417 otr5 = (TTree*)headerFile->Get("S4");
418 otr6 = (TTree*)headerFile->Get("ToF");
419 otr7 = (TTree*)headerFile->Get("Run");
420 otr8 = (TTree*)headerFile->Get("Anticounter");
421 if ( !otr0 && !otr1 && !otr2 && !otr3 && !otr4 && !otr5 && !otr6 && !otr7 && !otr8 ){
422 L0 = (TTree*)headerFile->Get("Physics");
423 pamela->level.file = -1;
424 } else {
425 stringstream dddec;
426 dddec.str("");
427 dddec << " +ALL +RUN +CAL1 -TRKh -TRK1 ";
428 if ( !otr0 ){
429 dddec << " -TRG ";
430 pamela->var.TRG = 0;
431 otr0 = otr1;
432 };
433 if ( !otr1 ){
434 dddec << " -CAL ";
435 pamela->var.CALO = 0;
436 if ( !otr0 ) otr0 = otr2;
437 };
438 if ( !otr2 ){
439 dddec << " -TRK2 -TRK ";
440 pamela->var.TRK = 0;
441 if ( !otr0 ) otr0 = otr3;
442 };
443 if ( !otr3 ){
444 dddec << " -ND ";
445 pamela->var.ND = 0;
446 if ( !otr0 ) otr0 = otr4;
447 };
448 if ( !otr4 ){
449 dddec << " -ORB ";
450 pamela->var.ORB = 0;
451 if ( !otr0 ) otr0 = otr5;
452 };
453 if ( !otr5 ){
454 dddec << " -S4 ";
455 pamela->var.S4 = 0;
456 if ( !otr0 ) otr0 = otr6;
457 };
458 if ( !otr6 ){
459 dddec << " -TOF ";
460 pamela->var.TOF = 0;
461 if ( !otr0 ) otr0 = otr8;
462 };
463 if ( !otr7 ){
464 dddec << " -RUN ";
465 pamela->var.RUN = 0;
466 };
467 if ( !otr8 ){
468 dddec << " -AC ";
469 pamela->var.AC = 0;
470 };
471 pamela->SetDDEC(dddec.str().c_str());
472 };
473 if ( !otr0 && !otr1 && !otr2 && !otr3 && !otr4 && !otr5 && !otr6 && !otr7 && !otr8 && !L0 ){
474 pamela->level.file = -1;
475 printf("ERROR: nor Physics nor Run tree...\n");
476 pamgui->DIALOG(2,"Nor Physics nor Run tree in this file");
477 pamela->var.waitforever = true;
478 goto refresh;
479 };
480 };
481 headerFile->Close("R");
482 //
483 if ( pamela->level.file != 2 ){
484 printf(" This is a YODA (level0) file \n");
485 } else {
486 printf(" This is a DARTHVADER (level2) file \n");
487 };
488 //
489 // Disable on the GUI the buttons that cannot be used with this file
490 //
491 pamgui->CheckLevel();
492 //
493 // Load the file
494 //
495 if ( otr0 || L0 ){
496 otr = pamela->Load(filename.Data());
497 if ( !otr ){
498 pamela->level.file = -1;
499 printf("ERROR: problems opening file...\n");
500 pamgui->DIALOG(2,"Problems opening file");
501 pamela->var.waitforever = true;
502 goto refresh;
503 };
504 } else {
505 pamela->level.file = -1;
506 printf("ERROR: problems with TTree while opening file...\n");
507 pamgui->DIALOG(2,"Problems opening file");
508 pamela->var.waitforever = true;
509 goto refresh;
510 };
511 //
512 printf("\n");
513 //
514 // get the number of entries
515 //
516 if ( !otr ) printf(" AGH! \n");
517 //
518 Long64_t nevents = otr->GetEntries();
519 printf(" The file contains %i physics events \n",(int)nevents);
520 //
521 // check we have at least one event
522 //
523 if (nevents<=0) {
524 // headerFile->Close();
525 printf("The file is empty, exiting...\n");
526 pamgui->DIALOG(0," The file contains no physics data! ");
527 pamela->var.waitforever = true;
528 goto refresh;
529 }
530 //
531 // Check that given input are inside the boundary conditions
532 //
533 pamela->minevent = 0;
534 pamela->maxevent = nevents - 1;
535 //
536 // Determine the boundaries
537 //
538 pamela->GetWindow();
539 Int_t lastevno = pamela->lastevno;
540 Int_t firstevno = pamela->firstevno;
541 //
542 // display the first event (unless we are refreshing only the window)
543 //
544 if ( !pamela->var.refresh ) i = pamela->minevent;
545 pamela->var.refresh = false;
546 //
547 pamgui->RefreshButtons();
548 //
549 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
550 // MAIN LOOP STARTS HERE:
551 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
552 //
553 while ( 1 ){
554 //
555 // update progress bar
556 //
557 if ( popup ) pamgui->increment((float)(i+1)*100./(float)nevents);
558 //
559 // clear canvas and variables
560 //
561 pamela->ClearVariables();
562 //
563 // get entry i
564 //
565 pamela->GetEntry(i);
566 //
567 // call the filter to select events (if filter file is given)
568 //
569 isOK = pamela->SelectEvent();
570 //
571 // if the event is selected go on
572 //
573 if ( isOK ) {
574 //
575 // reset working variables
576 //
577 printf("\n\n\n\n\n\n\n\n\n\n");
578 pamela->SetEntry(i);
579 pamela->si = i;
580 pamela->var.doflag = 1;
581 pamela->var.i = i;
582 pamela->var.nevents = nevents;
583 pamela->var.lastevno = lastevno;
584 pamela->var.firstevno = firstevno;
585 //
586 printf("\n");
587 //
588 // disable "stop" button in the GUI
589 //
590 pamgui->StopSearching();
591 //
592 // make the canvas editable and clear it
593 //
594 figure->SetEditable(kTRUE);
595 figure->Clear();
596 figure->SetFillColor(10);
597 figure->cd();
598 //
599 // retrieve general info for the event (OBT, pkt_num, etc. etc.)
600 //
601 pamela->GetGeneralInfo();
602 //
603 // display the event
604 //
605 pamela->DisplayEvent();
606 //
607 // prepare the string for the figure filename
608 //
609 char *bw;
610 if ( pamela->var.bw ){
611 bw = "_bw";
612 } else {
613 bw = "";
614 };
615 TString filenm = pamela->var.thefilename;
616 const string fil = gSystem->BaseName(filenm.Data());
617 Int_t posiz = fil.find(".root");
618 TString file2;
619 if ( posiz == -1 ){
620 file2 = gSystem->BaseName(filename.Data());
621 } else {
622 Int_t posiz2 = 0;
623 stringcopy(file2,gSystem->BaseName(filename.Data()),posiz2,posiz);
624 };
625 const char *figrec = file2;
626 const char *outdir = outDir;
627 stringstream figsave;
628 figsave.str("");
629 figsave << outdir << "/";
630 figsave << figrec;
631 figsave << "_ev_";
632 figsave << (pamela->var.i+1);
633 figsave << bw;
634 pamela->var.svas=figsave.str().c_str();
635
636 // printf(" qua %s \n",figsave.str().c_str());
637 //
638 // upgrade the figure filename in the GUI
639 //
640 pamgui->upgrnamfi();
641 //
642 // WAIT for user input
643 //
644 pamela->var.jumpen = false;
645 while( !pamela->var.goon && !pamela->var.refresh && !pamela->var.restart ) {
646 if ( !gROOT->GetListOfCanvases()->FindObject(figure) ) {
647 pamgui->Terminate();
648 };
649 gSystem->ProcessEvents();
650 gSystem->Sleep(10);
651 };
652 //
653 // interpret user input
654 //
655 pamela->var.goon = false;
656 if ( pamela->var.refresh || pamela->var.restart ){
657 if ( pamela->GetL2() ) pamela->GetL2()->Reset();
658 if ( pamela->level.file != 2 ) pamela->GetChain()->Delete();
659 otr = NULL;
660 // if ( headerFile ) headerFile->Close("R");
661 if ( pamela->var.refresh ) goto refresh;
662 if ( pamela->var.restart ){
663 filename = pamela->var.thefilename.Data();
664 goto restart;
665 };
666 };
667 //
668 i = pamela->var.i;
669 if ( i != pamela->si ) pamela->OOBT = 1000000000;
670 if ( pamela->maxevent < i ) {
671 pamela->maxevent = nevents;
672 printf("WARNING: you have chosen an event number out of the starting range.\n Range extended to %i\n\n",pamela->maxevent);
673 };
674 //
675 };
676 //
677 // if the returned entry is -1 it means we must start again from the first event going forward (doflag=1)
678 //
679 if ( pamela->GetThisEntry() == -1 ){
680 pamela->var.doflag = 1;
681 i = pamela->minevent;
682 };
683 //
684 // doflag = 2 means "go backward" (check for lower boundary)
685 //
686 if ( pamela->var.doflag == 2 && i == 0 ) {
687 printf("\n WARNING: Cannot go backward! Going forward. \n");
688 pamela->var.doflag = 1;
689 };
690 if ( pamela->var.doflag == 2 && i>0 ) i--;
691 //
692 // doflag = 1 means go forward (the check on the upper boundary is made in FEVpamevcontrol)
693 //
694 if ( pamela->var.doflag == 1 ) i++;
695 //
696 // if in selection mode, print out a event progress bar in the text window:
697 //
698 if ( !pamela->var.selex || i == pamela->minevent ){
699 // do nothing
700 } else {
701 if ( (pamela->maxevent-pamela->minevent) != 0 ){
702 if((100*(i-pamela->minevent)/(pamela->maxevent-pamela->minevent))<10.){
703 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);
704 } else {
705 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);
706 };
707 };
708 };
709
710 };
711 //
712 // END OF THE MAIN LOOP AND OF THE MAIN PROGRAM
713 //
714 printf("\n");
715 printf(" ...done! \n\n");
716 return;
717 }

  ViewVC Help
Powered by ViewVC 1.1.23