// file phat.C Overall event loop for MDC1, multiple tasks merged // DMcL 9/16/98 Add date/time stamp, correct final interactive loop // MDB 9/16/98 Allow a different number of events for SPC // DMcL 9/13/98 Some additions for track finding // DMcL 9/12/98 merged in interactive debugs/improvements since 9/05/98; // sequence rearranged, & edited comments to clarify. // MB/AT 9/10/98 MDC1 version: Add tree output. // MDB 9/08/98 MDC1 version: Add default VTX. Start from Raw data. // DMcL 9/05/98 version 2 // DMcL 8/27/98 version 1 // // Usage: phat phat.C (& simbatch = 0) for interactive use with gui; // phat -b -q phat.C for batch. // // What it is: A combination of the functionality of macros provided by // phat program developers (RV -> mul, JK -> sensor monitors, // PD/LR -> vertex, KW -> spectr. tracks); in interactive // mode, added buttons & dialog boxes for ease of use. // >>>> As of 9/10/98 no dialog boxes; text "workaround". // // Structure: At a minimum, one can run this script in batch mode which // will use the (editable) defaults below, on one "processor", // i.e. one of macros Vtx.C, Mul.C, Onl.C, Spc.C. You may // also need include files such as Mul.h for global variables. // Out.C is needed for output files. For interactive use, // needs phatic.C, phatset.C and dialogs.C or equivalents. // // Comments: This is and will remain a CINT script for ease in editing // and understanding; this is fast enough at the event loop // level. phat.C calls other macros which may or may not // become compiled classes, as well as compiled phat & root. // Some object and variable names are assumed "standard" by // the macros and are so labeled below. // ///////////////////////////////////////////////////////////////////////////// // INITIALIZATION ///////////////////////////////////////////////////////////////////////////// // General phat.C initialization: { gROOT->Reset("a"); // Load include files, if needed, for user macro global variables // You will have to select which lines go into the .h file and which // go into the initialization phase of the .C files below; note that // in the latter, quantities defined in the initialization phase will // not be in scope for the event loop, although changes in global // variables in initialization will be seen in the event loop. #include "Mul.h" //#include "Onl.h" #include "Spc.h" //************************************************************************* // Some important variables to edit, or set by interactive GUI if coded: Int_t simbatch = 0; //Set this to 1 to simulate batch, but with displays Int_t datype = 1; // Data type 1 = raw, 2 for cv0_10events.apx.root Int_t ReportLevel = 1; // Verbosity of comments; 3 = highest Int_t ReportFreq = 1; // every ReportFreq events Char_t *HitArrayName = "HitArraysfromRawData";// For datype = 1 // Char_t *HitArrayName = "MCHitArrays"; // For datype = 2 // Number of events, runs etc.: // (Edit or set via GUI) Int_t nEvents = 10000; Int_t nSpc = 100; // Max. number of events to run Spc on Int_t nRuns = 10000; // Flags to turn on or off the individual analysis processes. // These may be changed by interactive phatic.C, or for batch use // may be edited temporarily for the particular application. Int_t doVtx = 0; // Convention: 0 =do not process, 1 = process Int_t doOnl = 0; // the corresponding data type. These may be Int_t doMul = 0; // set to 1 by clicking buttons on the GUI. Int_t doSpc = 0; Int_t doOut = 0; // Write output if not zero Int_t flVtx = 1; // Event loop processing flag: 0 = process only, Int_t flOnl = 0; // otherwise process & display. The integer value Int_t flMul = 1; // may be used to select types of displays. (Also Int_t flSpc = 1; // controls final displays.) Int_t flOut = 1; // available for use to control output routine // Integer code for display type may be replaced by e.g. string later? // If in batch, process only, regardless of the state of fl*** above. //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>End of the usual user editables // Load the user macros. // The macro name list may be changed by editing phat.C, phatic.C // and phatset.C; this is easy enough that symbolic names aren't needed. // At least "dummy" routines are recommended to avoid error messages here. gROOT->LoadMacro("Vtx.C"); gROOT->LoadMacro("Mul.C"); gROOT->LoadMacro("Onl.C"); gROOT->LoadMacro("Spc.C"); gROOT->LoadMacro("Out.C"); printf("Loaded user macros\n"); if(!gROOT->IsBatch() && (simbatch == 0)) { // Macro to define dialog boxes and their parameters (from root // tutorials); see its comments for the methods thus enabled. // gROOT->LoadMacro("dialogs.C"); // Must be in macro search path! // the interactive control macros (set flags etc.): gROOT->LoadMacro("phatic.C"); gROOT->LoadMacro("phatset.C"); } // Analysis phase flags: const Int_t kNull = 0; // can use to "comment out" parts of user macro const Int_t kIni1 = 1; // initialization (only one stage now) const Int_t kRun1 = 11; // first event loop execution const Int_t kRun2 = 13; // second; for actions dep. on kRun1 const Int_t kRun3 = 15; // third, likewise. (Can add 4th etc. later) const Int_t kDis1 = 12; // displays after first stage execution const Int_t kDis2 = 14; // displays after second stage execution const Int_t kDis3 = 16; // displays after third stage execution const Int_t kDisf = 18; // displays in final execution after ev. loop const Int_t kFin1 = 101; // after run processing stage 1 (all for now) const Int_t kFinf = 201; // final run processing, after displays // These are compared to "phase" flag in user macros to generate the // proper analysis sequence. See phatic.html (RH button) for details. // Loop control flags (irrelevant if in batch mode) Int_t doGo = 0; // Leave 100 ms loop before event loop Int_t doStop = 0; // End the event loop by user request Int_t doPause = 0; // while != 0, 100 ms delay loop within event loop // allowing interactive manipulation of last event Int_t doDisp = 1; // Toggle set by any button choice, cleared after // first display in pause, set at pause exit. // default file names (in environment variables as per discussion 8/25/98) // phatic.C allows interactive change of InFile, OuFile: Char_t *InFile = "$INPUT0"; printf("Default input file set to $INPUT0, expanded name = %s\n", gSystem->ExpandPathName(InFile)); Char_t *OuFile = "$OUTPUT0"; printf("Default output file set to $OUTPUT0, expanded name = %s\n", gSystem->ExpandPathName(OuFile)); Char_t *TemplFile = "$TEMPLATES"; printf("Default template file set to $TEMPLATES, expanded name = %s\n", gSystem->ExpandPathName(TemplFile)); Char_t *ActIn = "$ACTUAL_INPUT0"; printf("MDC1 HPSS input file name = %s\n", gSystem->ExpandPathName(ActIn)); Char_t *ActOut = "$ACTUAL_OUTPUT0"; printf("MDC1 HPSS output file name = %s\n", gSystem->ExpandPathName(ActOut)); // Declarations of objects; note that user routines (Mul.C etc.) // must use these names to reference these objects instantiated by phat.C. TPhDetector *det; TPhDST *data = NULL; // Either raw or dst format TPhEvent *ev = NULL; TPhVertex *v1 = NULL; Int_t iev = 0; // We need the event loop counter to be global // Create the detector. ReadLatestGeometry depends on the existence // of Detector.root in $PhatHome/init/test/. Macros assume object "det". if ((det = TPhDetector::GetInstance()) == NULL) { det = TPhDetector::ReadLatestGeometry(); } if(!det) { printf("FATAL.. maybe no $PHATHOME/init/test/Detector.root?") gSystem->Abort(); } // Execute phase 1 of the interactive macro phatic.C, brings up GUI // to alter from defaults. if(!gROOT->IsBatch() && (simbatch == 0)) { phatic(1); // Panel of initialization buttons // Now enter a loop while the buttons are pushed & dialog boxes // are filled; exit when "GO" is pushed. // This loop times out after 10 minutes for (Int_t i = 0; i < 6000; i++) { gSystem->ProcessEvents(); // new method in ROOT 2.10! if(doGo == 1) break; // Continue on if "GO" button is pushed gSystem->Sleep(100); // 1/10 second delay } printf("Exit setup loop\n"); } //end IsBatch // Any alterations by the initialization GUI are now in effect. // // Open input data file. Macros assume object "data". data = new TPhDST(InFile); // This is used for both raw and dst input if(!data) { printf("FATAL.. InFile, expanded name = %s, can't open!\n", gSystem->ExpandPathName(InFile)); gSystem->Abort(); } printf("Input data file opened, expanded name = %s\n", gSystem->ExpandPathName(InFile)); // The output file, if wanted, is opened by the Out.C macro. The default // name is set above, and may have been changed by the GUI. // Initialize analysis modules: if(doVtx >= 1) Vtx(kIni1); if(doMul >= 1) Mul(kIni1); if(doOnl >= 1) Onl(kIni1); if(doSpc >= 1) Spc(kIni1); if(doOut >= 1) Out(kIni1); printf("End of initialization, start event processing at\n"); gSystem->Exec("date"); ////////////////////////////////////////////////////////////////////////// // EVENT LOOP ////////////////////////////////////////////////////////////////////////// if(!gROOT->IsBatch() && (simbatch == 0)) phatic(2); // 2nd panel for event loop flags. // This continues to be active during the event loop and allows // asynchronous setting of flags for the event loop to read. // Loop over all events for (iev = 0; iev < nEvents; iev++) { if(doStop >> 0) break; // STOP button was pressed. The effect will // nevertheless usually appear to be delayed by one event. ev = data->GetNextEvent(); if (!ev) break; //EOF if(iev%ReportFreq==0 && ReportLevel >=1 && iev) printf("Event# %d\n",iev); det->ClearHits(); det->SetEvent(ev); // changed MDB edit to allow raw/dst choice for use after reconstruction: if(datype == 1) det->MakeHitArrays("MCRawHitFECn0s", HitArrayName); det->FillWithEventHitArrays(HitArrayName); if(ReportLevel >= 3) printf("Hit arrays into detector\n"); // Step through (for now) three phases e.g. vertex first, then multiplicity, // then through everything else. Use phase e.g kRun2 to control sequence. if(doVtx >= 1) { // find vertex (or set to 0) Vtx(kRun1); if(v1 && (ReportLevel >= 3) ) { printf("Vertex at %f %f %f\n",v1->GetX(),v1->GetY(),v1->GetZ()); } } else { v1 = new TPhVertex("MainVertex"); ev->AddObject(v1); v1->SetX(0.0); // MDB... default the vertex to 0 if v1->SetY(0.0); // there is no vertex finder called by phat.C v1->SetZ(0.0); } if(doMul >= 1) Mul(kRun1); // multiplicity analysis if(doOnl >= 1) Onl(kRun1); // online monitoring if(doSpc >= 1 && iev < nSpc) Spc(kRun1); // spectrometer tracking if(doOut >= 1) Out(kRun1); // DST output if(doVtx >= 1) Vtx(kRun2); // more vertex processing if wanted if(doMul >= 1) Mul(kRun2); // second stage processing if wanted if(doOnl >= 1) Onl(kRun2); if(doSpc >= 1 && iev < nSpc) Spc(kRun2); if(doOut >= 1) Out(kRun2); if(doVtx >= 1) Vtx(kRun3); // third stage processing if(doMul >= 1) Mul(kRun3); if(doOnl >= 1) Onl(kRun3); if(doSpc >= 1 && iev < nSpc) Spc(kRun3); if(doOut >= 1) Out(kRun3); // EVENT LOOP DISPLAYS // Execute the following at least once if interactive; loops if paused. // For now we assume only one display phase, at the end of event analysis. // (If simbatch = 1, we still get displays to follow the progress.) if(!gROOT->IsBatch()) { do { if(doStop >> 0) break; // STOP button was pressed during PAUSE if(simbatch == 0) gSystem->ProcessEvents(); if(doDisp == 1) { // We assume for now only one phase (kDis3) of displays. if(doVtx >= 1 && flVtx != 0) Vtx(kDis3,flVtx); if(doMul >= 1 && flMul != 0) Mul(kDis3,flMul); if(doOnl >= 1 && flOnl != 0) Onl(kDis3,flOnl); if(doSpc >= 1 && flSpc != 0 && iev < nSpc) Spc(kDis3,flSpc); if(doOut >= 1 && flOut != 0) Out(kDis3,flOut); doDisp = 0; // Turn off, comes back on if button push } if(doPause != 0) gSystem->Sleep(100); // Don't tie up CPU! } while (doPause != 0); doDisp = 1; // Turn the displays back on after pause } //end !IsBatch if (ReportLevel >= 2) printf("Delete event\n"); delete ev; } //end event loop printf("End of event loop at\n"); gSystem->Exec("date"); /////////////////////////////////////////////////////////////////////////// // FINAL ACTIONS /////////////////////////////////////////////////////////////////////////// // End of run, store histograms etc.; for batch use, exit or clean up & // return to initialization but for interactive use allow user plots, // possible output of histograms, etc. // Run final actions before interactive displays: if(doVtx >= 1) Vtx(kFin1,flVtx); // vertex if(doMul >= 1) Mul(kFin1,flMul); // multiplicity if(doOnl >= 1) Onl(kFin1,flOnl); // online monitoring if(doSpc >= 1) Spc(kFin1,flSpc); // spectrometer tracking if(doOut >= 1) Out(kFin1,flSpc); // write output DST printf("After Fin1 final actions \n"); // END OF RUN DISPLAYS // Interactive display loop: if(!gROOT->IsBatch()) { if (simbatch == 0) phatic(3); // Panel for final stage // Now enter a loop while the buttons are pushed & dialog boxes // are filled; exit when "EXIT" is pushed. // This loop times out after 10 minutes for (Int_t i = 0; i < 6000; i++) { if(doGo == 10) break; // Continue on if "EXIT" button is pushed, // the button-selected options will execute. if(simbatch == 0) gSystem->ProcessEvents(); if(doDisp == 1) { // We assume for now only one phase (kDisf) of displays. if(doVtx >= 1 && flVtx != 0) Vtx(kDisf,flVtx); if(doMul >= 1 && flMul != 0) Mul(kDisf,flMul); if(doOnl >= 1 && flOnl != 0) Onl(kDisf,flOnl); if(doSpc >= 1 && flSpc != 0) Spc(kDisf,flSpc); doDisp = 0; // Turn off, comes back on if button push } if(simbatch !=0) break; // Avoid looping in simulated batch gSystem->Sleep(100); // Don't tie up CPU! } } printf("Before Finf final actions \n"); // Run final actions after interactive displays: if(doVtx >= 1) Vtx(kFinf,flVtx); // vertex final actions if(doMul >= 1) Mul(kFinf,flMul); // multiplicity if(doOnl >= 1) Onl(kFinf,flOnl); // online monitoring if(doSpc >= 1) Spc(kFinf,flSpc); // spectrometer tracking if(doOut >= 1) Out(kFinf); // write output #2 (if wanted) printf("MDC1 HPSS input file name = %s\n", gSystem->ExpandPathName(ActIn)); printf("MDC1 HPSS output file name = %s\n", gSystem->ExpandPathName(ActOut)); printf("RUN COMPLETED at\n"); gSystem->Exec("date"); if(!gROOT->IsBatch()) gSystem->Abort(); // Redundant with -q in batch. // Remove the above if you want ROOT to continue. } // End of phat.C //////////////////////////////////////////////////////////////////////////// // SETUP NOTES ///////////////////////////////////////////////////////////////////////////// // 1) Define as environment variables $INPUT0, $OUTPUT0, $TEMPLATE e.g. // setenv INPUT0 $PHATHOME/data/cv0_002.raw.root // setenv OUTPUT0 $PHATHOME/data/output.root // setenv TEMPLATES $PHATHOME/data/templates.root // The first two setenv will also be done by the MDC scripts. // For analysis only, one or both of the last two may not be needed. // // 2) To be able to use the right hand HELP button, // setenv PHATHELP $BROWSER\ $PHATHOME/phatloop/html/phatic.html // // 3) Requires ROOT v. 2.10 or higher // // 4) Macros must be local or in the macro search path (see .rootrc) // and have the names you see here to run this example of phat.C // // 5) For setting constants for batch operation in the top section // of phat.C, see phatic.html in the directory defined above i.e. HELP // /////////////////////////////////////////////////////////////////////////////