otsdaq  v1_01_03
 All Classes Namespaces Functions
MonicelliEventAnalyzer.cpp
1 #include "otsdaq-core/MonicelliInterface/MonicelliEventAnalyzer.h"
2 #include "otsdaq-core/MonicelliInterface/MonicelliFileReader.h"
3 #include "otsdaq-core/MonicelliInterface/Visual3DEvent.h"
4 
5 #include "otsdaq-core/MonicelliInterface/Event.h"
6 #include "otsdaq-core/MonicelliInterface/Geometry.h"
7 #include "otsdaq-core/MonicelliInterface/Detector.h"
8 
9 using namespace ots;
10 
11 //========================================================================================================================
12 MonicelliEventAnalyzer::MonicelliEventAnalyzer(void)
13 {}
14 
15 //========================================================================================================================
16 MonicelliEventAnalyzer::~MonicelliEventAnalyzer(void)
17 {}
18 
19 //========================================================================================================================
20 void MonicelliEventAnalyzer::load(std::string fileName)
21 {
22  theVisualEvents_.clear();
23  if(!theReader_.openEventsFile(fileName)) return;
24  if(!theReader_.openGeoFile(fileName.replace(fileName.find('.')+1,4,"geo"))) return;
25 
26  theMonicelliEvent_ = theReader_.getEventPointer () ;
27  theMonicelliHeader_ = theReader_.getEventHeaderPointer() ;
28  theMonicelliGeometry_ = theReader_.getGeometryPointer () ;
29 
30  unsigned int numberOfEvents = theReader_.getNumberOfEvents() ;
31  std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "Number of events: " << numberOfEvents << std::endl;
32  theVisualEvents_.resize(numberOfEvents);
33  for(unsigned int event=0; event<numberOfEvents && event<1000; event++)
34  //for(unsigned int event=0; event<10; event++)
35  {
36  theReader_.readEvent(event) ;
37  this->analyzeEvent(event) ;
38  }
39  theReader_.closeGeoFile();
40  theReader_.closeEventsFile();
41  std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "Done!" << std::endl;
42 }
43 
44 //========================================================================================================================
45 const Visual3DEvents& MonicelliEventAnalyzer::getEvents(void)
46 {
47  return theVisualEvents_;
48 }
49 
50 //========================================================================================================================
51 void MonicelliEventAnalyzer::analyzeEvent(unsigned int event)
52 {
53  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "Event: " << event << std::endl;
54 
55  monicelli::Event::clustersMapDef & clusters = theMonicelliEvent_->getClusters () ;
56  monicelli::Event::fittedTracksDef & fittedTracks = theMonicelliEvent_->getFittedTracks () ;
57  //monicelli::Event::chi2VectorDef & chi2 = theMonicelliEvent_->getFittedTracksChi2() ;
58  //monicelli::Event::fittedTracksCovarianceDef & fittedTrackCovariance = theMonicelliEvent_->getFittedTracksCovariance();
59  //monicelli::Event::trackCandidatesDef & trackPoints = theMonicelliEvent_->getTrackCandidates () ;
60 
61  if( fittedTracks.size() == 0 ) return;
62 
63  for(unsigned int tr=0; tr<fittedTracks.size(); tr++)
64  {
65  ROOT::Math::SVector<double,4> tParameters = fittedTracks[tr] ;
66  VisualTrack tmpVisualTrack;
67  tmpVisualTrack.slopeX = tParameters[0];
68  tmpVisualTrack.interceptX = tParameters[1]*10;
69  tmpVisualTrack.slopeY = tParameters[2];
70  tmpVisualTrack.interceptY = tParameters[3]*10;
71  //chi2[tr] ;
72  theVisualEvents_[event].addTrack(tmpVisualTrack);
73  }
74 
75  for(monicelli::Event::clustersMapDef::iterator itClusters=clusters.begin(); itClusters != clusters.end(); itClusters++)
76  for(monicelli::Event::aClusterMapDef::iterator itClusterMap=itClusters->second.begin(); itClusterMap != itClusters->second.end(); itClusterMap++)
77  {
78  VisualHit tmpVisualHit;
79  tmpVisualHit.x = itClusterMap->second["x"];
80  tmpVisualHit.y = itClusterMap->second["y"];
81  tmpVisualHit.z = 0;
82  tmpVisualHit.charge = itClusterMap->second["charge"];
83  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "Local X: " << tmpVisualHit.x << " Y: " << tmpVisualHit.y << " Z: " << tmpVisualHit.z << std::endl;
84  monicelli::Detector* detector = theMonicelliGeometry_->getDetector(itClusters->first);
85  detector->fromLocalToGlobal(&(tmpVisualHit.x),&(tmpVisualHit.y),&(tmpVisualHit.z));
86  theVisualEvents_[event].addHit(tmpVisualHit*10);//To become um
87  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "Global X: " << tmpVisualHit.x << " Y: " << tmpVisualHit.y << " Z: " << tmpVisualHit.z << std::endl;
88  }
89 }