CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/SimG4CMS/Calo/interface/CaloSD.h

Go to the documentation of this file.
00001 #ifndef SimG4CMS_CaloSD_h
00002 #define SimG4CMS_CaloSD_h
00003 
00004 // File: CaloSD.h
00005 // Description: Stores hits of calorimetric type in appropriate container
00006 // Use in your sensitive detector builder:
00007 //    CaloSD* caloSD = new CaloSD(SDname, new CaloNumberingScheme());
00009 
00010 #include "SimG4CMS/Calo/interface/CaloG4Hit.h"
00011 #include "SimG4CMS/Calo/interface/CaloG4HitCollection.h"
00012 #include "SimG4CMS/Calo/interface/CaloMeanResponse.h"
00013 #include "SimG4Core/Notification/interface/Observer.h"
00014 #include "SimG4Core/Notification/interface/BeginOfRun.h"
00015 #include "SimG4Core/Notification/interface/BeginOfEvent.h"
00016 #include "SimG4Core/Notification/interface/BeginOfTrack.h"
00017 #include "SimG4Core/Notification/interface/EndOfTrack.h"
00018 #include "SimG4Core/Notification/interface/EndOfEvent.h"
00019 #include "SimG4Core/Notification/interface/TrackWithHistory.h"
00020 #include "SimG4Core/SensitiveDetector/interface/SensitiveCaloDetector.h"
00021 #include "SimG4Core/Application/interface/SimTrackManager.h"
00022 
00023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00024 
00025 // To be replaced by something else 
00026 /* #include "Utilities/Notification/interface/TimerProxy.h" */
00027  
00028 #include "G4VPhysicalVolume.hh"
00029 #include "G4Track.hh"
00030 #include "G4VGFlashSensitiveDetector.hh"
00031 
00032 #include <iostream>
00033 #include <fstream>
00034 #include <vector>
00035 #include <map>
00036 
00037 class G4Step;
00038 class G4HCofThisEvent;
00039 class CaloSlaveSD;
00040 class G4GFlashSpot;
00041 
00042 class CaloSD : public SensitiveCaloDetector, 
00043                public G4VGFlashSensitiveDetector,
00044                public Observer<const BeginOfRun *>,    
00045                public Observer<const BeginOfEvent *>,
00046                public Observer<const BeginOfTrack *>,
00047                public Observer<const EndOfTrack *>,
00048                public Observer<const EndOfEvent *> {
00049 
00050 public:    
00051   
00052   CaloSD(G4String  aSDname, const DDCompactView & cpv,
00053          SensitiveDetectorCatalog & clg, 
00054          edm::ParameterSet const & p, const SimTrackManager*,
00055          int tSlice=1, bool ignoreTkID=false);
00056   virtual ~CaloSD();
00057   virtual bool     ProcessHits(G4Step * step,G4TouchableHistory * tHistory);
00058   virtual bool     ProcessHits(G4GFlashSpot*aSpot,G4TouchableHistory*);
00059   virtual double   getEnergyDeposit(G4Step* step); 
00060   virtual uint32_t setDetUnitId(G4Step* step)=0;
00061   
00062   virtual void     Initialize(G4HCofThisEvent * HCE);
00063   virtual void     EndOfEvent(G4HCofThisEvent * eventHC);
00064   virtual void     clear();
00065   virtual void     DrawAll();
00066   virtual void     PrintAll();
00067 
00068   void             fillHits(edm::PCaloHitContainer&,std::string n);
00069 
00070 protected:
00071 
00072   virtual G4bool   getStepInfo(G4Step* aStep);
00073   G4ThreeVector    setToLocal(G4ThreeVector, const G4VTouchable*);
00074   G4bool           hitExists();
00075   G4bool           checkHit();
00076   CaloG4Hit*       createNewHit();
00077   void             updateHit(CaloG4Hit*);
00078   void             resetForNewPrimary(G4ThreeVector, double);
00079   double           getAttenuation(G4Step* aStep, double birk1, double birk2,
00080                                   double birk3);
00081 
00082   virtual void     update(const BeginOfRun *);
00083   virtual void     update(const BeginOfEvent *);
00084   virtual void     update(const BeginOfTrack * trk);
00085   virtual void     update(const EndOfTrack * trk);
00086   virtual void     update(const ::EndOfEvent *);
00087   virtual void     clearHits();
00088   virtual void     initRun();
00089   virtual bool     filterHit(CaloG4Hit*, double);
00090 
00091   virtual int      getTrackID(G4Track*);
00092   virtual uint16_t getDepth(G4Step*);   
00093   double           getResponseWt(G4Track*);
00094 
00095 private:
00096 
00097   void             storeHit(CaloG4Hit*);
00098   bool             saveHit(CaloG4Hit*);
00099   void             summarize();
00100   void             cleanHitCollection();
00101 
00102 protected:
00103   
00104   // Data relative to primary particle (the one which triggers a shower)
00105   // These data are common to all Hits of a given shower.
00106   // One shower is made of several hits which differ by the
00107   // unit ID (crystal/fibre/scintillator) and the Time slice ID.
00108 
00109   G4ThreeVector                   entrancePoint;
00110   G4ThreeVector                   entranceLocal;
00111   G4ThreeVector                   posGlobal;
00112   float                           incidentEnergy;
00113   int                             primIDSaved; //  ID of the last saved primary
00114 
00115   CaloHitID                       currentID, previousID; 
00116   G4Track*                        theTrack;
00117 
00118   G4StepPoint*                    preStepPoint; 
00119   float                           edepositEM, edepositHAD;
00120 
00121   double                          energyCut, tmaxHit, eminHit, eminHitD;
00122   int                             checkHits;
00123   bool                            useMap;
00124 
00125   const SimTrackManager*          m_trackManager;
00126   CaloG4Hit*                      currentHit;
00127 //  TimerProxy                    theHitTimer;
00128   bool                            runInit;
00129 
00130   bool                            corrTOFBeam, suppressHeavy;
00131   double                          correctT;
00132   double                          kmaxIon, kmaxNeutron, kmaxProton;
00133 
00134   G4int                           emPDG, epPDG, gammaPDG;
00135   bool                            forceSave;
00136 
00137 private:
00138 
00139   int                             timeSlice;
00140   bool                            ignoreTrackID;
00141   CaloSlaveSD*                    slave;
00142   int                             hcID;
00143   CaloG4HitCollection*            theHC; 
00144   std::map<CaloHitID,CaloG4Hit*>  hitMap;
00145 
00146   std::map<int,TrackWithHistory*> tkMap;
00147   CaloMeanResponse*               meanResponse;
00148 
00149   int                             primAncestor;
00150   int                             cleanIndex;
00151   std::vector<CaloG4Hit*>         reusehit;
00152   std::vector<CaloG4Hit*>         hitvec;
00153   std::vector<unsigned int>       selIndex;
00154   int                             totalHits;
00155 
00156 };
00157 
00158 #endif // SimG4CMS_CaloSD_h