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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download)
Thu Mar 15 14:02:33 2007 UTC (17 years, 8 months ago) by mocchiut
Branch: MAIN
Changes since 1.3: +24 -20 lines
Code updated from TTree to TChain, OBT level2 bug fixed

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

  ViewVC Help
Powered by ViewVC 1.1.23