Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/examples/advanced/underground_physics/src/DMXEventAction.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/advanced/underground_physics/src/DMXEventAction.cc (Version 11.3.0) and /examples/advanced/underground_physics/src/DMXEventAction.cc (Version 10.0.p3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //                                                 26 //
 27 // -------------------------------------------     27 // --------------------------------------------------------------
 28 //   GEANT 4 - Underground Dark Matter Detecto     28 //   GEANT 4 - Underground Dark Matter Detector Advanced Example
 29 //                                                 29 //
 30 //      For information related to this code c     30 //      For information related to this code contact: Alex Howard
 31 //      e-mail: alexander.howard@cern.ch           31 //      e-mail: alexander.howard@cern.ch
 32 // -------------------------------------------     32 // --------------------------------------------------------------
 33 // Comments                                        33 // Comments
 34 //                                                 34 //
 35 //                  Underground Advanced           35 //                  Underground Advanced
 36 //               by A. Howard and H. Araujo        36 //               by A. Howard and H. Araujo 
 37 //                    (27th November 2001)         37 //                    (27th November 2001)
 38 //                                                 38 //
 39 // History/Additions:                              39 // History/Additions:
 40 // 16 Jan 2002  Added analysis                     40 // 16 Jan 2002  Added analysis
 41 //                                                 41 //
 42 //                                                 42 //
 43 // EventAction program                             43 // EventAction program
 44 // -------------------------------------------     44 // --------------------------------------------------------------
 45                                                    45 
 46 #include "DMXEventAction.hh"                       46 #include "DMXEventAction.hh"
 47                                                    47 
 48 // pass parameters for messengers:                 48 // pass parameters for messengers:
 49 #include "DMXRunAction.hh"                         49 #include "DMXRunAction.hh"
 50 #include "DMXPrimaryGeneratorAction.hh"            50 #include "DMXPrimaryGeneratorAction.hh"
 51                                                    51 
 52 // note DMXPmtHit.hh and DMXScintHit.hh are in     52 // note DMXPmtHit.hh and DMXScintHit.hh are included in DMXEventAction.hh
 53                                                    53 
 54 #include "DMXEventActionMessenger.hh"              54 #include "DMXEventActionMessenger.hh"
                                                   >>  55 #include "DMXAnalysisManager.hh"
 55                                                    56 
 56 #include "G4AnalysisManager.hh"                <<  57 #include "G4SystemOfUnits.hh"
 57 #include "G4Event.hh"                              58 #include "G4Event.hh"
 58 #include "G4EventManager.hh"                       59 #include "G4EventManager.hh"
 59 #include "G4HCofThisEvent.hh"                      60 #include "G4HCofThisEvent.hh"
 60 #include "G4VHitsCollection.hh"                    61 #include "G4VHitsCollection.hh"
 61 #include "G4TrajectoryContainer.hh"                62 #include "G4TrajectoryContainer.hh"
 62 #include "G4Trajectory.hh"                         63 #include "G4Trajectory.hh"
 63 #include "G4VVisManager.hh"                        64 #include "G4VVisManager.hh"
 64 #include "G4SDManager.hh"                          65 #include "G4SDManager.hh"
 65 #include "G4UImanager.hh"                          66 #include "G4UImanager.hh"
 66 #include "G4UnitsTable.hh"                         67 #include "G4UnitsTable.hh"
 67 #include "G4RunManager.hh"                     <<  68 #include "G4ios.hh"
 68 #include "G4Threading.hh"                      << 
 69 #include <fstream>                                 69 #include <fstream>
 70 #include <iomanip>                                 70 #include <iomanip>
 71                                                    71 
 72 #include "G4SystemOfUnits.hh"                  << 
 73                                                    72 
 74 //....oooOO0OOooo........oooOO0OOooo........oo     73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 75 DMXEventAction::DMXEventAction()               <<  74 DMXEventAction::DMXEventAction(DMXRunAction* DMXRun,
 76   : runAct(0),genAction(0),hitsfile(0),pmtfile <<  75              DMXPrimaryGeneratorAction* DMXGenerator) 
                                                   >>  76   : runAct(DMXRun),genAction(DMXGenerator)
 77 {                                                  77 {
 78                                                    78 
 79   // create messenger                              79   // create messenger
 80   eventMessenger = new DMXEventActionMessenger     80   eventMessenger = new DMXEventActionMessenger(this);
 81                                                    81 
 82   // defaults for messenger                        82   // defaults for messenger
 83   drawColsFlag = "standard";                       83   drawColsFlag = "standard";
 84   drawTrksFlag = "all";                            84   drawTrksFlag = "all";
 85   drawHitsFlag = 1;                                85   drawHitsFlag = 1;
 86   savePmtFlag  = 0;                                86   savePmtFlag  = 0;
 87   saveHitsFlag = 1;                                87   saveHitsFlag = 1;
 88                                                    88   
 89   printModulo = 1;                                 89   printModulo = 1;
 90                                                    90 
 91   // hits collections                              91   // hits collections
 92   scintillatorCollID = -1;                         92   scintillatorCollID = -1;
 93   pmtCollID = -1;                                  93   pmtCollID = -1;
 94                                                    94 
 95   energy_pri=0;                                    95   energy_pri=0;
 96   seeds=NULL;                                      96   seeds=NULL;
 97                                                    97 
 98 }                                                  98 }
 99                                                    99 
100                                                   100 
101 //....oooOO0OOooo........oooOO0OOooo........oo    101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
102 DMXEventAction::~DMXEventAction() {               102 DMXEventAction::~DMXEventAction() {
103                                                   103 
104   if (hitsfile)                                << 
105     {                                          << 
106       hitsfile->close();                       << 
107       delete hitsfile;                         << 
108     }                                          << 
109   if (pmtfile)                                 << 
110     {                                          << 
111       pmtfile->close();                        << 
112       delete pmtfile;                          << 
113     }                                          << 
114   delete eventMessenger;                          104   delete eventMessenger;
115 }                                                 105 }
116                                                   106 
117                                                   107 
118 //....oooOO0OOooo........oooOO0OOooo........oo    108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
119 void DMXEventAction::BeginOfEventAction(const  << 109 void DMXEventAction::BeginOfEventAction(const G4Event* evt) {
120 {                                              << 
121                                                << 
122   //thread-local run action                    << 
123   if (!runAct)                                 << 
124     runAct =                                   << 
125       dynamic_cast<const DMXRunAction*>        << 
126       (G4RunManager::GetRunManager()->GetUserR << 
127                                                << 
128   if (!genAction)                              << 
129     genAction = dynamic_cast<const DMXPrimaryG << 
130       (G4RunManager::GetRunManager()->GetUserP << 
131                                                   110 
132                                                   111 
133   // grab seeds                                   112   // grab seeds
134   seeds = genAction->GetEventSeeds();             113   seeds = genAction->GetEventSeeds();
135                                                   114 
136   // grab energy of primary                       115   // grab energy of primary
137   energy_pri = genAction->GetEnergyPrimary();     116   energy_pri = genAction->GetEnergyPrimary();
138                                                   117 
139   event_id = evt->GetEventID();                   118   event_id = evt->GetEventID();
140                                                   119  
141   // print this information event by event (mo    120   // print this information event by event (modulo n)   
142   if (event_id%printModulo == 0)                  121   if (event_id%printModulo == 0)
143     {                                             122     {
144       G4cout << "\n---> Begin of event: " << e    123       G4cout << "\n---> Begin of event: " << event_id << G4endl;
145       G4cout << "\n     Primary Energy: " << G    124       G4cout << "\n     Primary Energy: " << G4BestUnit(energy_pri,"Energy") 
146        << G4endl;                                 125        << G4endl;
147       //      HepRandom::showEngineStatus();      126       //      HepRandom::showEngineStatus(); 
148     }                                             127     }
149                                                   128 
150                                                   129 
151   // get ID for scintillator hits collection      130   // get ID for scintillator hits collection
152   if (scintillatorCollID==-1) {                   131   if (scintillatorCollID==-1) {
153     G4SDManager *SDman = G4SDManager::GetSDMpo    132     G4SDManager *SDman = G4SDManager::GetSDMpointer();
154     scintillatorCollID = SDman->GetCollectionI    133     scintillatorCollID = SDman->GetCollectionID("scintillatorCollection");
155   }                                               134   }
156                                                   135 
157   // get ID for pmt hits collection               136   // get ID for pmt hits collection
158   if (pmtCollID==-1) {                            137   if (pmtCollID==-1) {
159     G4SDManager *SDman = G4SDManager::GetSDMpo    138     G4SDManager *SDman = G4SDManager::GetSDMpointer();
160     pmtCollID = SDman->GetCollectionID("pmtCol    139     pmtCollID = SDman->GetCollectionID("pmtCollection");
161   }                                               140   }
162                                                   141 
163 }                                                 142 }
164                                                   143 
165                                                   144 
166 //....oooOO0OOooo........oooOO0OOooo........oo    145 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
167 void DMXEventAction::EndOfEventAction(const G4    146 void DMXEventAction::EndOfEventAction(const G4Event* evt) {
168                                                   147 
169   // check that both hits collections have bee    148   // check that both hits collections have been defined
170   if(scintillatorCollID<0||pmtCollID<0) return    149   if(scintillatorCollID<0||pmtCollID<0) return;
171                                                   150 
172   G4AnalysisManager* man = G4AnalysisManager::    151   G4AnalysisManager* man = G4AnalysisManager::Instance();
173                                                   152 
174   // address hits collections                     153   // address hits collections
175   DMXScintHitsCollection* SHC = NULL;             154   DMXScintHitsCollection* SHC = NULL;
176   DMXPmtHitsCollection*   PHC = NULL;             155   DMXPmtHitsCollection*   PHC = NULL;
177   G4HCofThisEvent* HCE = evt->GetHCofThisEvent    156   G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
178   if(HCE) {                                       157   if(HCE) {
179     SHC = (DMXScintHitsCollection*)(HCE->GetHC    158     SHC = (DMXScintHitsCollection*)(HCE->GetHC(scintillatorCollID));
180     PHC = (DMXPmtHitsCollection*)(HCE->GetHC(p    159     PHC = (DMXPmtHitsCollection*)(HCE->GetHC(pmtCollID));
181   }                                               160   }
182                                                   161 
183   // event summary                                162   // event summary
184   totEnergy         = 0.;                         163   totEnergy         = 0.;
185   totEnergyGammas   = 0.;                         164   totEnergyGammas   = 0.;
186   totEnergyNeutrons = 0.;                         165   totEnergyNeutrons = 0.;
187   firstParticleE    = 0.;                         166   firstParticleE    = 0.;
188   particleEnergy    = 0.;                         167   particleEnergy    = 0.;
189   firstLXeHitTime   = 0.;                         168   firstLXeHitTime   = 0.;
190   aveTimePmtHits    = 0.;                         169   aveTimePmtHits    = 0.;
191                                                   170 
192   firstParticleName = "";                         171   firstParticleName = "";
193   particleName      = "";                         172   particleName      = "";
194                                                   173 
195                                                   174 
196   // particle flags                               175   // particle flags
197   gamma_ev          = false;                      176   gamma_ev          = false;
198   neutron_ev        = false;                      177   neutron_ev        = false;
199   positron_ev       = false;                      178   positron_ev       = false;
200   electron_ev       = false;                      179   electron_ev       = false;
201   proton_ev         = false;                      180   proton_ev         = false;
202   other_ev          = false;                      181   other_ev          = false;
203   start_gamma       = false;                      182   start_gamma       = false;
204   start_neutron     = false;                      183   start_neutron     = false;
205                                                   184 
206                                                   185 
207   // scintillator hits                            186   // scintillator hits
208   if(SHC) {                                       187   if(SHC) {
209     S_hits = SHC->entries();                      188     S_hits = SHC->entries();
210                                                   189     
211     for (G4int i=0; i<S_hits; i++) {              190     for (G4int i=0; i<S_hits; i++) {
212       if(i==0) {                                  191       if(i==0) {
213   firstParticleName = (*SHC)[0]->GetParticle()    192   firstParticleName = (*SHC)[0]->GetParticle();
214   firstLXeHitTime   = (*SHC)[0]->GetTime();       193   firstLXeHitTime   = (*SHC)[0]->GetTime();
215   firstParticleE = (*SHC)[0]->GetParticleEnerg    194   firstParticleE = (*SHC)[0]->GetParticleEnergy();
216   if (event_id%printModulo == 0 && S_hits > 0)    195   if (event_id%printModulo == 0 && S_hits > 0) {
217     G4cout << "     First hit in LXe: " << fir    196     G4cout << "     First hit in LXe: " << firstParticleName << G4endl;
218     G4cout << "     Number of hits in LXe: " <    197     G4cout << "     Number of hits in LXe: " << S_hits << G4endl; 
219   }                                               198   }
220       }                                           199       }
221       hitEnergy         = (*SHC)[i]->GetEdep()    200       hitEnergy         = (*SHC)[i]->GetEdep();
222       totEnergy        += hitEnergy;              201       totEnergy        += hitEnergy;
223                                                   202       
224       particleName      = (*SHC)[i]->GetPartic    203       particleName      = (*SHC)[i]->GetParticle();
225       particleEnergy    = (*SHC)[i]->GetPartic    204       particleEnergy    = (*SHC)[i]->GetParticleEnergy();
226                                                   205 
227       if(particleName == "gamma") {               206       if(particleName == "gamma") {
228   gamma_ev = true;                                207   gamma_ev = true;
229   start_gamma = true;                             208   start_gamma = true;
230   start_neutron = false;                          209   start_neutron = false;
231       }                                           210       }
232       else if(particleName == "neutron")          211       else if(particleName == "neutron") 
233   neutron_ev = true;                              212   neutron_ev = true;
234       else if(particleName == "e+")               213       else if(particleName == "e+") 
235   positron_ev = true;                             214   positron_ev = true;
236       else if(particleName == "e-")               215       else if(particleName == "e-") 
237   electron_ev = true;                             216   electron_ev = true;
238       else if(particleName == "proton")           217       else if(particleName == "proton") 
239   proton_ev = true;                               218   proton_ev = true;
240       else {                                      219       else {
241   other_ev = true;                                220   other_ev = true;
242   start_gamma = false;                            221   start_gamma = false;
243   start_neutron = true;                           222   start_neutron = true;
244       }                                           223       }
245                                                   224 
246       if(start_gamma && !start_neutron)           225       if(start_gamma && !start_neutron) 
247   totEnergyGammas += hitEnergy;                   226   totEnergyGammas += hitEnergy;
248       if(start_neutron && !start_gamma)           227       if(start_neutron && !start_gamma) 
249   totEnergyNeutrons += hitEnergy;                 228   totEnergyNeutrons += hitEnergy;
250     }                                             229     }
251                                                   230     
252     if (event_id%printModulo == 0)                231     if (event_id%printModulo == 0)
253       G4cout << "     Total energy in LXe: "      232       G4cout << "     Total energy in LXe: " 
254        << G4BestUnit(totEnergy,"Energy") << G4    233        << G4BestUnit(totEnergy,"Energy") << G4endl;  
255                                                   234     
256   }                                               235   }
257                                                   236   
258                                                   237   
259   // PMT hits                                     238   // PMT hits
260   if(PHC) {                                       239   if(PHC) {
261     P_hits = PHC->entries();                      240     P_hits = PHC->entries();
262                                                   241     
263     // average time of PMT hits                   242     // average time of PMT hits
264     for (G4int i=0; i<P_hits; i++) {              243     for (G4int i=0; i<P_hits; i++) {
265       G4double time = ( (*PHC)[i]->GetTime() -    244       G4double time = ( (*PHC)[i]->GetTime() - firstLXeHitTime );
266       aveTimePmtHits += time / (G4double)P_hit    245       aveTimePmtHits += time / (G4double)P_hits;
267       ////      if (event_id == 0) {              246       ////      if (event_id == 0) {
268       if(P_hits >= 0) {                           247       if(P_hits >= 0) {
269   man->FillH1(7,time);                            248   man->FillH1(7,time);
270       }                                           249       }
271     }                                             250     }
272                                                   251   
273     if (event_id%printModulo == 0 && P_hits >     252     if (event_id%printModulo == 0 && P_hits > 0) {
274       G4cout << "     Average light collection    253       G4cout << "     Average light collection time: "
275        << G4BestUnit(aveTimePmtHits,"Time") <<    254        << G4BestUnit(aveTimePmtHits,"Time") << G4endl;
276       G4cout << "     Number of PMT hits (phot    255       G4cout << "     Number of PMT hits (photoelectron equivalent): " 
277        << P_hits << G4endl;                       256        << P_hits << G4endl;     
278     }                                             257     }
279     // write out (x,y,z) of PMT hits              258     // write out (x,y,z) of PMT hits
280     if (savePmtFlag)                              259     if (savePmtFlag)
281       writePmtHitsToFile(PHC);                    260       writePmtHitsToFile(PHC);
282   }                                               261   }
283                                                   262   
284                                                   263 
285   // write out event summary                      264   // write out event summary
286   if(saveHitsFlag)                                265   if(saveHitsFlag) 
287     writeScintHitsToFile();                       266     writeScintHitsToFile();
288                                                   267   
289   // draw trajectories                            268   // draw trajectories
290   if(drawColsFlag=="standard" && drawTrksFlag!    269   if(drawColsFlag=="standard" && drawTrksFlag!="none")
291     drawTracks(evt);                              270     drawTracks(evt);
292                                                   271 
293   // hits in PMT                                  272   // hits in PMT
294   if(drawHitsFlag && PHC)                         273   if(drawHitsFlag && PHC) 
295     PHC->DrawAllHits();                           274     PHC->DrawAllHits();
296                                                   275 
297   // print this event by event (modulo n)         276   // print this event by event (modulo n)   
298   if (event_id%printModulo == 0)                  277   if (event_id%printModulo == 0) 
299     G4cout << "\n---> End of event: " << event    278     G4cout << "\n---> End of event: " << event_id << G4endl << G4endl;  
300                                                   279 
301 }                                                 280 }
302                                                   281 
303                                                   282 
304                                                   283 
305 //....oooOO0OOooo........oooOO0OOooo........oo    284 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
306 void DMXEventAction::writeScintHitsToFile()    << 285 void DMXEventAction::writeScintHitsToFile(void) {
307 {                                              << 
308                                                   286 
309   G4String filename="hits.out";                << 287   //  G4String filename="hits.out";
310   if (runAct)                                  << 288   G4String filename=runAct->GetsavehitsFile();
311     filename=runAct->GetsavehitsFile();        << 289   std::ofstream hitsfile(filename, std::ios::app);
312                                                << 290   if(!event_id) {
313                                                << 291     std::ofstream hitsfileInit(filename);
314                                                << 292     hitsfileInit <<"Evt     Eprim   Etot    LXe     LXeTime PMT     PMTTime Seed1           Seed2           First   Flags" 
315   //First time it is inkoved                   << 293        << G4endl;
316   if (!hitsfile)                               << 294     hitsfileInit <<"#       MeV     MeV     hits    ns      hits    ns                                      hit"
317     {                                          << 295        << G4endl
318       //check that we are in a worker: returns << 296        << G4endl;
319       //one file per thread is produced ending << 297   }
320       if (G4Threading::G4GetThreadId() >= 0)   << 
321   {                                            << 
322     std::stringstream sss;                     << 
323     sss << filename.c_str() << "." << G4Thread << 
324     filename = sss.str();                      << 
325     //G4cout << "Filename is: " << filename << << 
326   }                                            << 
327                                                << 
328       hitsfile = new std::ofstream;            << 
329       hitsfile->open(filename);                << 
330       (*hitsfile) <<"Evt     Eprim   Etot    L << 
331          << G4endl;                            << 
332       (*hitsfile) <<"#       MeV     MeV     h << 
333          << G4endl                             << 
334          << G4endl;                            << 
335     }                                          << 
336                                                   298 
337   if(S_hits) {                                    299   if(S_hits) {
338                                                   300 
339     if(hitsfile->is_open()) {                  << 301     if(hitsfile.is_open()) {
340                                                   302 
341                                                   303 
342       (*hitsfile) << std::setiosflags(std::ios << 304       hitsfile << std::setiosflags(std::ios::fixed)
343       << std::setprecision(4)                  << 305          << std::setprecision(4)
344       << std::setiosflags(std::ios::left)      << 306          << std::setiosflags(std::ios::left)
345       << std::setw(6)                          << 307          << std::setw(6)
346       << event_id << "\t"                      << 308          << event_id << "\t"
347       << energy_pri/MeV << "\t"                << 309          << energy_pri/MeV << "\t" 
348       << totEnergy/MeV << "\t"                 << 310          << totEnergy/MeV << "\t"
349       << S_hits  << "\t"                       << 311          << S_hits  << "\t"
350       << std::setiosflags(std::ios::scientific << 312          << std::setiosflags(std::ios::scientific) 
351       << std::setprecision(2)                  << 313          << std::setprecision(2)
352       << firstLXeHitTime/nanosecond << "\t"    << 314          << firstLXeHitTime/nanosecond << "\t"
353       << P_hits << "\t"                        << 315          << P_hits << "\t"
354       << std::setiosflags(std::ios::fixed)     << 316          << std::setiosflags(std::ios::fixed) 
355       << std::setprecision(4)                  << 317          << std::setprecision(4)
356       << aveTimePmtHits/nanosecond << "\t"     << 318          << aveTimePmtHits/nanosecond << "\t"
357       << *seeds     << "\t"                    << 319          << *seeds     << "\t"
358       << *(seeds+1) << "\t"                    << 320          << *(seeds+1) << "\t"
359       << firstParticleName << "\t"             << 321          << firstParticleName << "\t"
360       << (gamma_ev    ? "gamma " : "")         << 322          << (gamma_ev    ? "gamma " : "") 
361       << (neutron_ev  ? "neutron " : "")       << 323          << (neutron_ev  ? "neutron " : "") 
362       << (positron_ev ? "positron " : "")      << 324          << (positron_ev ? "positron " : "") 
363       << (electron_ev ? "electron " : "")      << 325          << (electron_ev ? "electron " : "") 
364       << (other_ev    ? "other " : "")         << 326          << (other_ev    ? "other " : "") 
365       << G4endl;                               << 327          << G4endl;
366                                                   328 
367       if (event_id%printModulo == 0)              329       if (event_id%printModulo == 0)
368   G4cout << "     Event summary in file " << f    330   G4cout << "     Event summary in file " << filename << G4endl;  
                                                   >> 331       hitsfile.close();
369     }                                             332     }
370                                                   333 
371     G4AnalysisManager* man = G4AnalysisManager    334     G4AnalysisManager* man = G4AnalysisManager::Instance();
372     G4int firstparticleIndex = 0;                 335     G4int firstparticleIndex = 0;
373     if(firstParticleName == "gamma") firstpart    336     if(firstParticleName == "gamma") firstparticleIndex = 1;
374     else if (firstParticleName == "neutron") f    337     else if (firstParticleName == "neutron") firstparticleIndex = 2;
375     else if(firstParticleName == "electron") f    338     else if(firstParticleName == "electron") firstparticleIndex = 3;
376     else if(firstParticleName == "positron") f    339     else if(firstParticleName == "positron") firstparticleIndex = 4;
377     else{                                         340     else{
378       firstparticleIndex = 5;                     341       firstparticleIndex = 5;
379       man->FillH1(3,totEnergy);                   342       man->FillH1(3,totEnergy);
380     }                                             343     }
381                                                   344 
382     man->FillH1(4,P_hits,10); //weight            345     man->FillH1(4,P_hits,10); //weight
383     man->FillH1(5,P_hits);                        346     man->FillH1(5,P_hits);
384                                                   347 
385     man->FillH1(1,energy_pri/keV);                348     man->FillH1(1,energy_pri/keV);
386     man->FillH1(2,totEnergy/keV);                 349     man->FillH1(2,totEnergy/keV);
387     man->FillH1(6,aveTimePmtHits/ns);             350     man->FillH1(6,aveTimePmtHits/ns);
388                                                   351 
389     long seed1 = *seeds;                          352     long seed1 = *seeds;
390     long seed2 = *(seeds+1);                      353     long seed2 = *(seeds+1);    
391                                                   354     
392     //Fill ntuple #2                              355     //Fill ntuple #2
393     man->FillNtupleDColumn(2,0,event_id);         356     man->FillNtupleDColumn(2,0,event_id);
394     man->FillNtupleDColumn(2,1,energy_pri/keV)    357     man->FillNtupleDColumn(2,1,energy_pri/keV);
395     man->FillNtupleDColumn(2,2,totEnergy);        358     man->FillNtupleDColumn(2,2,totEnergy);
396     man->FillNtupleDColumn(2,3,S_hits);           359     man->FillNtupleDColumn(2,3,S_hits);
397     man->FillNtupleDColumn(2,4,firstLXeHitTime    360     man->FillNtupleDColumn(2,4,firstLXeHitTime);
398     man->FillNtupleDColumn(2,5,P_hits);           361     man->FillNtupleDColumn(2,5,P_hits);
399     man->FillNtupleDColumn(2,6,aveTimePmtHits)    362     man->FillNtupleDColumn(2,6,aveTimePmtHits);
400     man->FillNtupleDColumn(2,7,firstparticleIn    363     man->FillNtupleDColumn(2,7,firstparticleIndex);
401     man->FillNtupleDColumn(2,8,firstParticleE)    364     man->FillNtupleDColumn(2,8,firstParticleE);
402     man->FillNtupleDColumn(2,9,gamma_ev);         365     man->FillNtupleDColumn(2,9,gamma_ev);
403     man->FillNtupleDColumn(2,10,neutron_ev);      366     man->FillNtupleDColumn(2,10,neutron_ev);
404     man->FillNtupleDColumn(2,11,positron_ev);     367     man->FillNtupleDColumn(2,11,positron_ev);
405     man->FillNtupleDColumn(2,12,electron_ev);     368     man->FillNtupleDColumn(2,12,electron_ev);
406     man->FillNtupleDColumn(2,13,other_ev);        369     man->FillNtupleDColumn(2,13,other_ev);
407     man->FillNtupleDColumn(2,14,seed1);           370     man->FillNtupleDColumn(2,14,seed1);
408     man->FillNtupleDColumn(2,15,seed2);           371     man->FillNtupleDColumn(2,15,seed2);
409     man->AddNtupleRow(2);                         372     man->AddNtupleRow(2);
410                                                   373     
411   }                                               374   }
412                                                   375 
413 }                                                 376 }
414                                                   377 
415                                                   378 
416 //....oooOO0OOooo........oooOO0OOooo........oo    379 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
417 void DMXEventAction::writePmtHitsToFile(const  << 380 void DMXEventAction::writePmtHitsToFile(const DMXPmtHitsCollection* hits) {
418 {                                              << 
419   G4String filename="pmt.out";                 << 
420   if (runAct)                                  << 
421     filename=runAct->GetsavepmtFile();         << 
422                                                << 
423                                                << 
424   //first time it is invoked: create it        << 
425   if (!pmtfile)                                << 
426     {                                          << 
427       //check that we are in a worker: returns << 
428       //one file per thread is produced ending << 
429       if (G4Threading::G4GetThreadId() >= 0)   << 
430   {                                            << 
431     std::stringstream sss;                     << 
432     sss << filename.c_str() << "." << G4Thread << 
433     filename = sss.str();                      << 
434     //G4cout << "Filename is: " << filename << << 
435   }                                            << 
436       pmtfile = new std::ofstream;             << 
437       pmtfile->open(filename);                 << 
438     }                                          << 
439                                                << 
440                                                   381 
                                                   >> 382   //  G4String filename="pmt.out";
                                                   >> 383   G4String filename=runAct->GetsavepmtFile();
                                                   >> 384   std::ofstream pmtfile(filename, std::ios::app);
441   G4double x; G4double y; G4double z;             385   G4double x; G4double y; G4double z;
442   G4AnalysisManager* man = G4AnalysisManager::    386   G4AnalysisManager* man = G4AnalysisManager::Instance();
443                                                   387 
444   if(pmtfile->is_open()) {                     << 388   if(pmtfile.is_open()) {
445     (*pmtfile) << "Hit#    X, mm   Y, mm   Z,  << 389     pmtfile << "Hit#    X, mm   Y, mm   Z, mm" << G4endl;       
446     (*pmtfile) << std::setiosflags(std::ios::f << 390     pmtfile << std::setiosflags(std::ios::fixed)
447          << std::setprecision(3)               << 391       << std::setprecision(3)
448          << std::setiosflags(std::ios::left)   << 392       << std::setiosflags(std::ios::left)
449          << std::setw(6);                      << 393       << std::setw(6);
450     for (G4int i=0; i<P_hits; i++)                394     for (G4int i=0; i<P_hits; i++)
451       {                                           395       {
452   x = ((*hits)[i]->GetPos()).x()/mm;              396   x = ((*hits)[i]->GetPos()).x()/mm;
453   y = ((*hits)[i]->GetPos()).y()/mm;              397   y = ((*hits)[i]->GetPos()).y()/mm;
454   z = ((*hits)[i]->GetPos()).z()/mm;              398   z = ((*hits)[i]->GetPos()).z()/mm;
455   (*pmtfile) << i << "\t"                      << 399   pmtfile << i << "\t"
456        << x << "\t"                            << 400     << x << "\t" 
457        << y << "\t"                            << 401     << y << "\t"
458        << z << G4endl;                         << 402     << z << G4endl;
459                                                   403   
460   man->FillH2(1,x/mm, y/mm);  // fill(x,y)        404   man->FillH2(1,x/mm, y/mm);  // fill(x,y)
461   if (event_id == 0 ) {                           405   if (event_id == 0 ) {
462     man->FillH2(2,x,y);                           406     man->FillH2(2,x,y);
463   }                                               407   }
464                                                   408 
465   //Fill ntuple #3                                409   //Fill ntuple #3
466   man->FillNtupleDColumn(3,0,event_id);           410   man->FillNtupleDColumn(3,0,event_id);
467   man->FillNtupleDColumn(3,1,(G4double) i);       411   man->FillNtupleDColumn(3,1,(G4double) i);
468   man->FillNtupleDColumn(3,2,x);                  412   man->FillNtupleDColumn(3,2,x);
469   man->FillNtupleDColumn(3,3,y);                  413   man->FillNtupleDColumn(3,3,y);
470   man->FillNtupleDColumn(3,4,z);                  414   man->FillNtupleDColumn(3,4,z);
471   man->AddNtupleRow(3);                           415   man->AddNtupleRow(3);
472                                                   416 
473       }                                           417       }
474     if (event_id%printModulo == 0 && P_hits >     418     if (event_id%printModulo == 0 && P_hits > 0) 
475       G4cout << "     " << P_hits << " PMT hit    419       G4cout << "     " << P_hits << " PMT hits in " << filename << G4endl;  
                                                   >> 420     pmtfile.close();
476   }                                               421   }
477                                                   422   
478 }                                                 423 }
479                                                   424 
480                                                   425 
481                                                   426 
482 //....oooOO0OOooo........oooOO0OOooo........oo    427 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
483 void DMXEventAction::drawTracks(const G4Event*    428 void DMXEventAction::drawTracks(const G4Event* evt) {
484                                                   429 
485   if(G4VVisManager::GetConcreteInstance()) {      430   if(G4VVisManager::GetConcreteInstance()) {
486     G4UImanager::GetUIpointer()->ApplyCommand(    431     G4UImanager::GetUIpointer()->ApplyCommand("/vis/scene/notifyHandlers");    
487     G4TrajectoryContainer* trajContainer = evt    432     G4TrajectoryContainer* trajContainer = evt->GetTrajectoryContainer();
488     G4int n_trajectories = 0;                     433     G4int n_trajectories = 0;
489                                                   434 
490     if(trajContainer) n_trajectories = trajCon    435     if(trajContainer) n_trajectories = trajContainer->entries();
491     for (G4int i=0; i<n_trajectories; i++) {      436     for (G4int i=0; i<n_trajectories; i++) {
492       G4Trajectory* trj = (G4Trajectory*)(*tra    437       G4Trajectory* trj = (G4Trajectory*)(*trajContainer)[i];
493       if (drawTrksFlag == "all")                  438       if (drawTrksFlag == "all") 
494   trj->DrawTrajectory();                          439   trj->DrawTrajectory();
495       else if ((drawTrksFlag == "charged") &&     440       else if ((drawTrksFlag == "charged") && (trj->GetCharge() != 0.))
496   trj->DrawTrajectory();                          441   trj->DrawTrajectory();
497       else if ((drawTrksFlag == "noscint")        442       else if ((drawTrksFlag == "noscint") 
498          && (trj->GetParticleName() != "optica    443          && (trj->GetParticleName() != "opticalphoton"))
499   trj->DrawTrajectory();                          444   trj->DrawTrajectory();
500     }                                             445     }
501                                                   446     
502     // G4UImanager::GetUIpointer()->ApplyComma    447     // G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");    
503   }                                               448   } 
504                                                   449 
505 }                                                 450 }
506                                                   451