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

  ViewVC Help
Powered by ViewVC 1.1.23