CMS 3D CMS Logo

TrackingVerboseAction.cc

Go to the documentation of this file.
00001 
00002 // File: TrackingVerboseAction.cc
00003 // Creation: P.Arce  09/01
00004 // Modifications: porting to CMSSW by M. Stavrianakou 22/03/06
00005 // Description:
00007 
00008 #include "SimG4Core/TrackingVerbose/interface/TrackingVerboseAction.h"
00009 
00010 #include "SimG4Core/Notification/interface/BeginOfRun.h"
00011 #include "SimG4Core/Notification/interface/BeginOfEvent.h"
00012 #include "SimG4Core/Notification/interface/BeginOfTrack.h"
00013 #include "SimG4Core/Notification/interface/EndOfTrack.h"
00014 #include "SimG4Core/Notification/interface/TrackInformation.h"
00015 #include "SimG4Core/Application/interface/TrackingAction.h"
00016 
00017 #include "G4Track.hh"
00018 #include "G4Event.hh"
00019 #include "G4ios.hh"
00020 #include "G4TrackingManager.hh"
00021 #include "G4EventManager.hh"
00022 #include "G4VSteppingVerbose.hh"
00023 
00024 using std::cout;
00025 using std::endl;
00026 
00027 TrackingVerboseAction::TrackingVerboseAction(edm::ParameterSet const & p) :
00028   theTrackingManager(0), fVerbose(0) {
00029 
00030     fLarge = int(1E10);
00031     fDEBUG = p.getUntrackedParameter<bool>("DEBUG",false);
00032     fHighEtPhotons = p.getUntrackedParameter<bool>("CheckForHighEtPhotons",false);
00033 
00034     //----- Set which events are verbose
00035     fTVEventMin  = p.getUntrackedParameter<int>("EventMin",0);
00036     fTVEventMax  = p.getUntrackedParameter<int>("EventMax",fLarge);
00037     fTVEventStep = p.getUntrackedParameter<int>("EventStep",1);
00038 
00039     //----- Set which tracks of those events are verbose
00040     fTVTrackMin  = p.getUntrackedParameter<int>("TrackMin",0);
00041     fTVTrackMax  = p.getUntrackedParameter<int>("TrackMax",fLarge);
00042     fTVTrackStep = p.getUntrackedParameter<int>("TrackStep",1);
00043 
00044     //----- Set the verbosity level
00045     fVerboseLevel = p.getUntrackedParameter<int>("VerboseLevel",1);
00046 
00047     if (fDEBUG)
00048     cout << "TV: fTVTrackMin " << fTVTrackMin   << " fTVTrackMax "  <<  fTVTrackMax 
00049          <<  " fTVTrackStep "  << fTVTrackStep  << " fTVEventMin "  << fTVEventMin 
00050          << " fTVEventMax "    << fTVEventMax   << " fTVEventStep " << fTVEventStep 
00051          << " fVerboseLevel "  << fVerboseLevel << endl;
00052 
00053     //----- Set verbosity off to start
00054     fTrackingVerboseON = false;
00055     fTkVerbThisEventON = false;
00056 
00057     cout << " TrackingVerbose constructed " << endl;
00058 }
00059 
00060 TrackingVerboseAction::~TrackingVerboseAction() {}
00061 
00062 void TrackingVerboseAction::update(const BeginOfRun * run)
00063 {
00064     TrackingAction * ta = 
00065         dynamic_cast<TrackingAction*>(G4EventManager::GetEventManager()->GetUserTrackingAction());
00066     theTrackingManager = ta->getTrackManager();
00067     fVerbose = G4VSteppingVerbose::GetInstance();
00068     if (fDEBUG)
00069     cout << " TV: Get the Tracking Manager: " << theTrackingManager
00070          << " and the SteppingVerbose: " << fVerbose << endl;
00071 }
00072 
00073 void TrackingVerboseAction::update(const BeginOfEvent * evt)
00074 {
00075     if (evt==0) return;
00076     const G4Event * anEvent = (*evt)();
00077     if (anEvent==0) return;
00078 
00079     //----------- Set /tracking/verbose for this event 
00080     int eventNo = anEvent->GetEventID();
00081     if (fDEBUG) cout << "TV: trackID: NEW EVENT " << eventNo << endl;
00082 
00083     fTkVerbThisEventON = false;
00084     //----- Check if event is in the selected range
00085     if (eventNo >= fTVEventMin && eventNo <= fTVEventMax) 
00086     {
00087         if ((eventNo-fTVEventMin) % fTVEventStep == 0) fTkVerbThisEventON = true;
00088     }
00089 
00090     if (fDEBUG)
00091     cout << " TV: fTkVerbThisEventON " <<  fTkVerbThisEventON 
00092          << " fTrackingVerboseON " << fTrackingVerboseON 
00093          << " fTVEventMin " << fTVEventMin << " fTVEventMax " << fTVEventMax << endl;
00094     //----- check if verbosity has to be changed
00095     if ((fTkVerbThisEventON) && (!fTrackingVerboseON))
00096     {
00097         if (fTVTrackMin == 0 && fTVTrackMax == fLarge && fTVTrackStep != 1)
00098         {
00099             setTrackingVerbose(fVerboseLevel);
00100             fTrackingVerboseON = true;
00101             if (fDEBUG) cout << "TV: VERBOSEet1 " << eventNo << endl;
00102         }
00103     }
00104     else if ((!fTkVerbThisEventON) && (fTrackingVerboseON) ) 
00105     {
00106         setTrackingVerbose(0);
00107         fTrackingVerboseON = false;
00108         if (fDEBUG) cout << "TV: VERBOSEet0 " << eventNo << endl;
00109     }
00110 
00111 }
00112 
00113 void TrackingVerboseAction::update(const BeginOfTrack * trk)
00114 {
00115     const G4Track * aTrack = (*trk)();
00116 
00117     //----- High ET photon printout
00118     //---------- Set /tracking/verbose
00119     //----- track is verbose only if event is verbose
00120     double tkP = aTrack->GetMomentum().mag();
00121     double tkPx = aTrack->GetMomentum().x();
00122     double tkPy = aTrack->GetMomentum().y();
00123     double tkPz = aTrack->GetMomentum().z();
00124 
00125     double tvtx = aTrack->GetVertexPosition().x();
00126     double tvty = aTrack->GetVertexPosition().y();
00127     double tvtz = aTrack->GetVertexPosition().z();
00128 
00129     double g4t_phi=atan2(tkPy,tkPx);
00130 
00131     double drpart=sqrt(tkPx*tkPx + tkPy*tkPy);
00132 
00133     double mythetapart=acos(tkPz/sqrt(drpart*drpart+tkPz*tkPz));
00134 
00135     double g4t_eta=-log(tan(mythetapart/2.));
00136     G4int MytrackNo = aTrack->GetTrackID();
00137     
00138     if (fHighEtPhotons)
00139     {
00140         if (aTrack->GetDefinition()->GetParticleName() == "gamma" && aTrack->GetParentID() !=0)
00141         {
00142             if((tkPx*tkPx + tkPy*tkPy + tkPz*tkPz)>1000.0*1000.0 &&
00143                aTrack->GetCreatorProcess()->GetProcessName() == "LCapture")
00144             {
00145                 cout << "MY NEW GAMMA " << endl;
00146                 cout << "**********************************************************************"  << endl;
00147                 cout << "MY NEW TRACK ID = " << MytrackNo << "("
00148                      << aTrack->GetDefinition()->GetParticleName()
00149                      <<")"<< " PARENT ="<< aTrack->GetParentID() << endl;
00150                 cout << "Primary particle: " 
00151                      << aTrack->GetDynamicParticle()->GetPrimaryParticle() << endl;
00152                 cout << "Process type: " << aTrack->GetCreatorProcess()->GetProcessType()
00153                      << " Process name: " 
00154                      << aTrack->GetCreatorProcess()->GetProcessName() << endl;
00155                 cout << "ToT E = " << aTrack->GetTotalEnergy() 
00156                      << " KineE = " << aTrack->GetKineticEnergy()
00157                      << " Tot P = " << tkP << " Pt = " << sqrt(tkPx*tkPx + tkPy*tkPy) 
00158                      << " VTX=(" << tvtx << "," << tvty << "," << tvtz << ")" << endl;
00159                 if (aTrack->GetKineticEnergy() > 1.*GeV 
00160                     && aTrack->GetCreatorProcess()->GetProcessName() != "LCapture")
00161                 cout << " KineE > 1 GeV !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
00162                 const G4VTouchable* touchable=aTrack->GetTouchable();
00163                 if (touchable!=0 && touchable->GetVolume()!=0 
00164                     && touchable->GetVolume()->GetLogicalVolume()!=0)
00165                 {
00166                     G4Material* material=touchable->GetVolume()->GetLogicalVolume()->GetMaterial();
00167                     cout << "G4LCapture Gamma E(GeV) " 
00168                          << aTrack->GetTotalEnergy()/GeV << "  "
00169                          << material->GetName()<< " " 
00170                          << touchable->GetVolume()->GetName() << endl;
00171                     cout << "G4LCapture Gamma position(m): " 
00172                          << aTrack->GetPosition()/m << endl;
00173                     cout << "G4LCapture created Gamma direction " 
00174                          << aTrack->GetMomentumDirection() << endl;
00175                     cout << "G4LCapture gamma (eta,phi) = " 
00176                          << "(" << g4t_eta << "," << g4t_phi << ")" << endl;
00177                 }
00178                 aTrack->GetUserInformation()->Print();
00179                 cout << "**********************************************************************"  << endl;
00180             }
00181         }
00182 
00183         if (aTrack->GetDefinition()->GetParticleName() == "gamma")
00184         {
00185             const G4VProcess * proc = aTrack->GetCreatorProcess();
00186             double Tgamma = aTrack->GetKineticEnergy();
00187             std::string ProcName;
00188             const  std::string nullstr ("Null_prc");
00189             if (proc) ProcName = proc->GetProcessName();
00190             else ProcName = nullstr;
00191             if (Tgamma > 2.5*GeV ) //&& ProcName!="Decay" && ProcName!="eBrem")
00192             {
00193                 std::string volumeName("_Unknown_Vol_");
00194                 std::string materialName("_Unknown_Mat_");
00195                 G4Material * material = 0;
00196                 G4VPhysicalVolume * pvolume = 0;
00197                 G4LogicalVolume * lvolume = 0;
00198                 const G4VTouchable * touchable = aTrack->GetTouchable();
00199                 if (touchable) pvolume = touchable->GetVolume();
00200                 if (pvolume)
00201                 {
00202                     volumeName = pvolume->GetName();
00203                     lvolume = pvolume->GetLogicalVolume();
00204                 }
00205                 if (lvolume) material = lvolume->GetMaterial();
00206                 if (material) materialName = material->GetName();
00207                 cout << "**** ALL photons > 2.5 GeV ****" << endl;
00208                 cout << ProcName << "**** ALL photons: gamma E(GeV) "
00209                      << aTrack->GetTotalEnergy()/GeV << "  "
00210                      <<  materialName << " " << volumeName << endl;
00211                 cout << ProcName << "**** ALL photons: gamma position(m): " 
00212                      << aTrack->GetPosition()/m << endl;
00213                 cout << ProcName << "**** ALL photons: gamma direction " 
00214                      << aTrack->GetMomentumDirection() << endl;
00215                 cout << "**********************************************************************"  << endl;
00216             }
00217         }                                               
00218     }
00219     
00220     //---------- Set /tracking/verbose
00221     //----- track is verbose only if event is verbose
00222     if (fTkVerbThisEventON) 
00223     {
00224         bool trackingVerboseThisTrack = checkTrackingVerbose(aTrack);
00225     
00226         //----- Set the /tracking/verbose for this track 
00227         if ((trackingVerboseThisTrack) && (!fTrackingVerboseON) ) 
00228         {
00229             setTrackingVerbose(fVerboseLevel);
00230             fTrackingVerboseON = true;
00231             if (fDEBUG) cout << "TV: VERBOSEtt1 " << aTrack->GetTrackID()
00232                              << endl;
00233             printTrackInfo(aTrack);
00234         } 
00235         else if ((!trackingVerboseThisTrack) && ( fTrackingVerboseON )) 
00236         {
00237             setTrackingVerbose(0);
00238             fTrackingVerboseON = false;
00239             if (fDEBUG) cout << "TV: VERBOSEtt0 " << aTrack->GetTrackID()
00240                              << endl;
00241         }
00242     }
00243 }
00244 
00245 void TrackingVerboseAction::update(const EndOfTrack * trk)
00246 {
00247     const G4Track * aTrack = (*trk)();
00248     if (fTkVerbThisEventON) 
00249     {
00250         bool trackingVerboseThisTrack = checkTrackingVerbose(aTrack);
00251         if ((trackingVerboseThisTrack) && (fTrackingVerboseON ) &&
00252             (fTVTrackMax < fLarge || fTVTrackStep != 1))
00253         {
00254             setTrackingVerbose(0);
00255             fTrackingVerboseON = false;
00256             if (fDEBUG) cout << "TV: VERBOSEtt0 " << aTrack->GetTrackID()
00257                              << endl;
00258         }
00259     }
00260 }
00261 
00262 void TrackingVerboseAction::setTrackingVerbose(int verblev)
00263 {
00264     if (fDEBUG) cout << " setting verbose level " << verblev << endl;
00265     if (theTrackingManager!=0) theTrackingManager->SetVerboseLevel(verblev);
00266 }
00267  
00268 bool TrackingVerboseAction::checkTrackingVerbose(const G4Track* aTrack) 
00269 {
00270     int trackNo = aTrack->GetTrackID();    
00271     bool trackingVerboseThisTrack = false;
00272     //----- Check if track is in the selected range
00273     if (trackNo >= fTVTrackMin && trackNo <= fTVTrackMax) 
00274     {
00275         if ((trackNo-fTVTrackMin) % fTVTrackStep == 0) trackingVerboseThisTrack = true;
00276     }
00277     return trackingVerboseThisTrack;
00278 }
00279 
00280 void TrackingVerboseAction::printTrackInfo(const G4Track* aTrack)
00281 {
00282     cout << endl
00283          << "*******************************************************"
00284          << "**************************************************" << endl
00285          << "* G4Track Information: "
00286          << "  Particle = " << aTrack->GetDefinition()->GetParticleName()
00287          << ","
00288          << "   Track ID = " << aTrack->GetTrackID()
00289          << ","
00290          << "   Parent ID = " << aTrack->GetParentID() << endl
00291          << "*******************************************************"
00292          << "**************************************************"
00293          << endl << endl;
00294     if (fVerbose) fVerbose->TrackingStarted();
00295 }

Generated on Tue Jun 9 17:47:10 2009 for CMSSW by  doxygen 1.5.4