CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/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   G4ThreeVector    setToGlobal(G4ThreeVector, const G4VTouchable*);
00075   G4bool           hitExists();
00076   G4bool           checkHit();
00077   CaloG4Hit*       createNewHit();
00078   void             updateHit(CaloG4Hit*);
00079   void             resetForNewPrimary(G4ThreeVector, double);
00080   double           getAttenuation(G4Step* aStep, double birk1, double birk2,
00081                                   double birk3);
00082 
00083   virtual void     update(const BeginOfRun *);
00084   virtual void     update(const BeginOfEvent *);
00085   virtual void     update(const BeginOfTrack * trk);
00086   virtual void     update(const EndOfTrack * trk);
00087   virtual void     update(const ::EndOfEvent *);
00088   virtual void     clearHits();
00089   virtual void     initRun();
00090   virtual bool     filterHit(CaloG4Hit*, double);
00091 
00092   virtual int      getTrackID(G4Track*);
00093   virtual uint16_t getDepth(G4Step*);   
00094   double           getResponseWt(G4Track*);
00095   int              getNumberOfHits();
00096 
00097 private:
00098 
00099   void             storeHit(CaloG4Hit*);
00100   bool             saveHit(CaloG4Hit*);
00101   void             summarize();
00102   void             cleanHitCollection();
00103 
00104 protected:
00105   
00106   // Data relative to primary particle (the one which triggers a shower)
00107   // These data are common to all Hits of a given shower.
00108   // One shower is made of several hits which differ by the
00109   // unit ID (crystal/fibre/scintillator) and the Time slice ID.
00110 
00111   G4ThreeVector                   entrancePoint;
00112   G4ThreeVector                   entranceLocal;
00113   G4ThreeVector                   posGlobal;
00114   float                           incidentEnergy;
00115   int                             primIDSaved; //  ID of the last saved primary
00116 
00117   CaloHitID                       currentID, previousID; 
00118   G4Track*                        theTrack;
00119 
00120   G4StepPoint*                    preStepPoint; 
00121   float                           edepositEM, edepositHAD;
00122 
00123   double                          energyCut, tmaxHit, eminHit, eminHitD;
00124   int                             checkHits;
00125   bool                            useMap;
00126 
00127   const SimTrackManager*          m_trackManager;
00128   CaloG4Hit*                      currentHit;
00129 //  TimerProxy                    theHitTimer;
00130   bool                            runInit;
00131 
00132   bool                            corrTOFBeam, suppressHeavy;
00133   double                          correctT;
00134   double                          kmaxIon, kmaxNeutron, kmaxProton;
00135 
00136   G4int                           emPDG, epPDG, gammaPDG;
00137   bool                            forceSave;
00138 
00139 private:
00140 
00141   int                             timeSlice;
00142   bool                            ignoreTrackID;
00143   CaloSlaveSD*                    slave;
00144   int                             hcID;
00145   CaloG4HitCollection*            theHC; 
00146   std::map<CaloHitID,CaloG4Hit*>  hitMap;
00147 
00148   std::map<int,TrackWithHistory*> tkMap;
00149   CaloMeanResponse*               meanResponse;
00150 
00151   int                             primAncestor;
00152   int                             cleanIndex;
00153   std::vector<CaloG4Hit*>         reusehit;
00154   std::vector<CaloG4Hit*>         hitvec;
00155   std::vector<unsigned int>       selIndex;
00156   int                             totalHits;
00157 
00158 };
00159 
00160 #endif // SimG4CMS_CaloSD_h