| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

ValiNTuple.cc

Go to the documentation of this file.
00001 
00007 #include "ValiNTuple.h"
00008 
00009 #include "Event/SimHeader.h"
00010 #include "Event/SimHitHeader.h"
00011 #include "Event/SimHitCollection.h"
00012 #include "Event/SimPmtHit.h"
00013 #include "Event/SimHit.h"
00014 
00015 #include "Event/SimParticleHistory.h"
00016 
00017 #include "Event/SimTrack.h"
00018 #include "Event/SimVertex.h"
00019 
00020 #include "Conventions/Detectors.h"
00021 #include "Conventions/Site.h"
00022 #include "Conventions/DetectorId.h"
00023 
00024 #include "GaudiKernel/ITHistSvc.h"
00025 
00026 #include "TTree.h"
00027 
00028 #include <map>
00029 #include <string>
00030 using namespace std;
00031 
00032 typedef map<short int, pair<int,string> > detector_bins_t;
00033 static detector_bins_t detector_bins;
00034 
00035 typedef struct{
00036   double hitTime;
00037   int sensDetId;
00038   float weight;
00039   int ancestorPdg;
00040   double PosX;
00041   double PosY;
00042   double PosZ;  
00043   double wavelt;
00044 } hitStruct;
00045 
00046 ValiNTuple::ValiNTuple(const std::string& name, ISvcLocator* pSvcLocator)
00047     : GaudiAlgorithm(name,pSvcLocator)
00048     , m_hsvc(0)
00049     , m_outTree(0)
00050 {
00051     declareProperty("Location",m_location=DayaBay::SimHeaderLocation::Default,
00052                     "Location in the TES to get HepMCEvents");
00053     declareProperty("FilePath",m_filepath="/file1/sim/",
00054                     "File path with with to register TTree .");
00055 
00056     if (!detector_bins.size()) {
00057         DayaBay::Detector dets[] = {
00058             DayaBay::Detector(Site::kDayaBay,DetectorId::kAD1),
00059             DayaBay::Detector(Site::kDayaBay,DetectorId::kAD2),
00060             DayaBay::Detector(Site::kDayaBay,DetectorId::kOWS),
00061             DayaBay::Detector(Site::kDayaBay,DetectorId::kIWS),
00062             DayaBay::Detector(Site::kDayaBay,DetectorId::kRPC),
00063             DayaBay::Detector(Site::kLingAo,DetectorId::kAD1),
00064             DayaBay::Detector(Site::kLingAo,DetectorId::kAD2),
00065             DayaBay::Detector(Site::kLingAo,DetectorId::kOWS),
00066             DayaBay::Detector(Site::kLingAo,DetectorId::kIWS),
00067             DayaBay::Detector(Site::kLingAo,DetectorId::kRPC),
00068             DayaBay::Detector(Site::kFar,DetectorId::kAD1),
00069             DayaBay::Detector(Site::kFar,DetectorId::kAD2),
00070             DayaBay::Detector(Site::kFar,DetectorId::kAD3),
00071             DayaBay::Detector(Site::kFar,DetectorId::kAD4),
00072             DayaBay::Detector(Site::kFar,DetectorId::kOWS),
00073             DayaBay::Detector(Site::kFar,DetectorId::kIWS),
00074             DayaBay::Detector(Site::kFar,DetectorId::kRPC),
00075             DayaBay::Detector(),
00076         };
00077 
00078         detector_bins[0] = pair<int,string>(0,"unknown");
00079         for (int ind=0; dets[ind].site(); ++ind) {
00080             detector_bins[dets[ind].siteDetPackedData()] 
00081                 = pair<int,string>(ind+1,dets[ind].detName());
00082         }
00083     }    
00084 
00085     
00086 }
00087 ValiNTuple::~ValiNTuple()
00088 {
00089 }
00090 
00091 StatusCode ValiNTuple::initialize()
00092 {
00093     this->GaudiAlgorithm::initialize();
00094 
00095     // Get the histogram service
00096     if ( service("THistSvc", m_hsvc).isFailure()) {
00097         error() << " No THistSvc available." << endreq;
00098         return StatusCode::FAILURE;
00099     } 
00100 
00101     m_outTree = new TTree("nOutTree","Output from DetSim");
00102     string outstring= m_filepath+"nOutTree";
00103     if (m_hsvc->regTree(outstring,m_outTree).isFailure()) {
00104         error() << "Could not register " << m_filepath+"nOutTree" << endreq;
00105         delete m_outTree; m_outTree = 0;
00106         return StatusCode::FAILURE;
00107     }
00108 
00109     return StatusCode::SUCCESS;
00110 }
00111 
00112 StatusCode ValiNTuple::execute()
00113 {
00114 
00115   DayaBay::SimHeader* shead = get<DayaBay::SimHeader>(m_location);
00116 
00117   // Get hit info 
00118   const DayaBay::SimHitHeader* shith = shead->hits();
00119   const DayaBay::SimHitHeader::hc_map& hcmap = shith->hitCollection();
00120   DayaBay::SimHitHeader::hc_map::const_iterator it, done = hcmap.end();
00121 
00122   
00123   // Get Primary Track Info.
00124   const DayaBay::SimParticleHistory* shist = shead->particleHistory();
00125   const std::list<const DayaBay::SimTrack*>& priTrks = shist->primaryTracks();
00126   std::list<const DayaBay::SimTrack*>::const_iterator priIt, priEnd=priTrks.end();
00127 
00128   //Get UnObservable Statistics info
00129   const DayaBay::SimUnobservableStatisticsHeader* unobSt = shead->unobservableStatistics();
00130   const DayaBay::SimUnobservableStatisticsHeader::stat_map& statmap = unobSt->stats();
00131   DayaBay::SimUnobservableStatisticsHeader::stat_map::const_iterator st, stdone = statmap.end();
00132   
00133   
00134   //  if(statmap.size()){
00135   for (st=statmap.begin(); st != stdone; ++st) {
00136     
00137     info () << " stat first " << st->first << " stat second sum " << st->second.sum() <<endreq;
00138   }
00139   //  }
00140   
00141   
00142   int hitsize(0),hitInCont(0);
00143   double trkLengInOws(0),trkLengInIws(0);
00144   
00145   hitsize=hcmap.size();
00146   info () << " Hit size " << hitsize <<endreq;
00147 
00148   //  hitStruct* hitCol[hitsize];
00149 
00150   hitStruct singleHit;
00151 
00152   //**** hit information**
00153   m_outTree->Branch("hitTime",&singleHit.hitTime,"hitTime/D");
00154   m_outTree->Branch("hitDetID",&singleHit.sensDetId,"hitDetID/I");
00155   m_outTree->Branch("hitWt",&singleHit.weight,"hitWt/F");
00156   m_outTree->Branch("hitancPDG",&singleHit.ancestorPdg,"hitancPDG/I");
00157   m_outTree->Branch("hitpX",&singleHit.PosX,"hitpX/D");
00158   m_outTree->Branch("hitpY",&singleHit.PosY,"hitpY/D");
00159   m_outTree->Branch("hitpZ",&singleHit.PosZ,"hitpZ/D");
00160   m_outTree->Branch("hitWavl",&singleHit.wavelt,"hitWavl/D");
00161 
00162   //***  ***
00163   m_outTree->Branch("hitsize",&hitsize,"hitsize/I");
00164   m_outTree->Branch("hitInCont",&hitInCont,"hitInCont/I");
00165   m_outTree->Branch("trkLengInOws",&trkLengInOws,"trkLengInOws/D");
00166   m_outTree->Branch("trkLengInIws",&trkLengInIws,"trkLengInIws/D");
00167 
00168 
00169   info () << " 01010101010101010 " << endreq;
00170 
00171   //  m_outTree.Branch("hitCol", &hitCol,"hitCol[hitsize]/F");
00172   
00173   info () << " 000000000 " << endreq;
00174 
00175 
00176 
00177   // Iterate to get the hit informatioin.
00178   for (it=hcmap.begin(); it != done; ++it) {
00179     DayaBay::Detector det(it->first);
00180     pair<int,string> bin = detector_bins[det.siteDetPackedData()];
00181     
00182     info () << "Got hit collection from " << det.detName() 
00183             << " in bin " << bin.first << endreq;
00184     
00185     size_t siz = it->second->collection().size();
00186     info () << " #hits in this Det " << siz << endreq;
00187     
00188     //    const DayaBay::SimHitCollection::hit_container hitcont=it->second->collection();
00189     //    DayaBay::SimHitCollection::hit_container::const_iterator ithit;
00190 
00191     const std::vector<DayaBay::SimHit*>&  hitcont=it->second->collection();
00192     std::vector<DayaBay::SimHit*>::const_iterator ithit;
00193 
00194     hitInCont=siz;
00195     
00196     if(siz!=0){
00197       for(ithit=hitcont.begin(); ithit !=hitcont.end();++ithit) {
00198         singleHit.hitTime=(*ithit)->hitTime();
00199         //      info () << " Hit time "<< singleHit.hitTime << endreq;
00200         singleHit.sensDetId=(*ithit)->sensDetId();
00201         singleHit.weight=(*ithit)->weight();
00202         if((*ithit)->ancestor().track()){
00203           singleHit.ancestorPdg=(*ithit)->ancestor().track()->particle(); //particle PDG//generate error
00204         }
00205         singleHit.PosX=(*ithit)->localPos().x();
00206         singleHit.PosY=(*ithit)->localPos().y();
00207         singleHit.PosZ=(*ithit)->localPos().z();
00208         //      info () << " x: "<< singleHit.PosX <<singleHit.PosY << singleHit.PosZ << endreq;
00209         
00210         const DayaBay::SimPmtHit* pmthit = static_cast<const DayaBay::SimPmtHit*>(*ithit);
00211         
00212         //      info () << " 22222222 " << endreq;
00213         
00214         //      singleHit.wavelt=(*pmthit).wavelength();
00215         //      m_outTree->Fill();
00216       }
00217     }
00218     else m_outTree->Fill();
00219   }
00220 
00221 
00222 
00223   
00224   //  m_outTree->Write();
00225   return StatusCode::SUCCESS;
00226 }
00227 
00228 StatusCode ValiNTuple::finalize()
00229 {
00230 
00231     return this->GaudiAlgorithm::finalize();
00232 }
00233 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:56:26 2011 for DetSimValidation by doxygen 1.4.7