Class Reference for E1039 Core & Analysis Software
AnaModule.cxx
Go to the documentation of this file.
1 #include <iomanip>
2 #include <TFile.h>
3 #include <TTree.h>
4 
6 #include <phool/getClass.h>
10 
11 
12 #include "AnaModule.h"
13 
14 AnaModule::AnaModule(const std::string& name): SubsysReco(name), p_geomSvc(GeomSvc::instance())
15 {}
16 
18 {}
19 
21 {
23 }
24 
26 {
27  int ret = GetNodes(topNode);
28  if(ret != Fun4AllReturnCodes::EVENT_OK) return ret;
29 
30  eventID = 0;
31  MakeTree();
33 }
34 
36 {
37  int nTracklets = trackletVec->size();
38  for(int i = 0; i < nTracklets; ++i)
39  {
40  Tracklet* tracklet = trackletVec->at(i);
41  nHits = tracklet->getNHits();
42  chisq = tracklet->getChisq();
43 
44  //very loose cuts here
45  if(nHits < 9) continue;
46  if(chisq > 20.) continue;
47 
48  for(auto it = detectorIDs.begin(); it != detectorIDs.end(); ++it)
49  {
50  detectorID = *it;
51  double z_exp = p_geomSvc->getPlanePosition(detectorID);
52  x_exp = tracklet->getExpPositionX(z_exp);
53  y_exp = tracklet->getExpPositionY(z_exp);
54  if(!p_geomSvc->isInPlane(detectorID, x_exp, y_exp)) continue;
55 
56  elementID_exp = p_geomSvc->getExpElementID(detectorID, tracklet->getExpPositionW(detectorID));
57  if(elementID_exp < 1 || elementID_exp > p_geomSvc->getPlaneNElements(detectorID)) continue;
58 
59  SQHit* hit = findHit(detectorID, elementID_exp);
60  elementID_closest = hit == nullptr ? -1 : hit->get_element_id();
61 
62  saveTree->Fill();
63  }
64  }
65 
66  ++eventID;
68 }
69 
71 {
72  saveFile->cd();
73  saveTree->Write();
74  saveFile->Close();
75 
77 }
78 
79 int AnaModule::GetNodes(PHCompositeNode* topNode)
80 {
81  hitVector = findNode::getClass<SQHitVector>(topNode, "SQHitVector");
82  trackletVec = findNode::getClass<TrackletVector>(topNode, "TrackletVector");
83  if(!hitVector || !trackletVec)
84  {
86  }
87 
89 }
90 
91 void AnaModule::MakeTree()
92 {
93  saveFile = new TFile(saveName, "RECREATE");
94 
95  saveTree = new TTree("save", "Efficiency tree Created by AnaModule");
96  saveTree->Branch("eventID", &eventID, "eventID/I");
97  saveTree->Branch("detectorID", &detectorID, "detectorID/I");
98  saveTree->Branch("elementID_exp", &elementID_exp, "elementID_exp/I");
99  saveTree->Branch("elementID_closest", &elementID_closest, "elementID_closest/I");
100  saveTree->Branch("x_exp", &x_exp, "x_exp/D");
101  saveTree->Branch("y_exp", &y_exp, "y_exp/D");
102  saveTree->Branch("nHits", &nHits, "nHits/I");
103  saveTree->Branch("chisq", &chisq, "chisq/D");
104 }
105 
106 void AnaModule::registerDetector(TString name)
107 {
108  detectorIDs.insert(p_geomSvc->getDetectorID(name.Data()));
109 }
110 
111 SQHit* AnaModule::findHit(int detID, int eleID)
112 {
113  int delta = 999;
114  SQHit* hit = nullptr;
115  for(SQHitVector::Iter it = hitVector->begin(); it != hitVector->end(); ++it)
116  {
117  if((*it)->get_detector_id() != detID) continue;
118  int delta_temp = abs(eleID - (*it)->get_element_id());
119  if(delta > delta_temp)
120  {
121  delta = delta_temp;
122  hit = (*it);
123  }
124  }
125 
126  return hit;
127 }
AnaModule()
Definition: AnaModule.h:15
void registerDetector(TString name)
Definition: AnaModule.cxx:106
int End(PHCompositeNode *topNode)
Called at the end of all processing.
Definition: AnaModule.cxx:70
int Init(PHCompositeNode *topNode)
Definition: AnaModule.cxx:20
int InitRun(PHCompositeNode *topNode)
Definition: AnaModule.cxx:25
int process_event(PHCompositeNode *topNode)
Definition: AnaModule.cxx:35
virtual ~AnaModule()
Definition: AnaModule.cxx:17
User interface class about the geometry of detector planes.
Definition: GeomSvc.h:164
int getDetectorID(const std::string &detectorName) const
Get the plane position.
Definition: GeomSvc.h:219
double getPlanePosition(int detectorID) const
Definition: GeomSvc.h:235
int getPlaneNElements(int detectorID) const
Definition: GeomSvc.h:260
int getExpElementID(int detectorID, double pos_exp)
Definition: GeomSvc.cxx:677
bool isInPlane(int detectorID, double x, double y)
See if a point is in a plane.
Definition: GeomSvc.cxx:622
virtual ConstIter end() const =0
virtual ConstIter begin() const =0
std::vector< SQHit * >::iterator Iter
Definition: SQHitVector.h:38
An SQ interface class to hold one detector hit.
Definition: SQHit.h:20
virtual short get_element_id() const
Return the element ID of this hit.
Definition: SQHit.h:45
const Tracklet * at(const size_t index) const
size_t size() const
Definition: FastTracklet.h:265
double getExpPositionY(double z) const
int getNHits() const
Definition: FastTracklet.h:145
double getExpPositionX(double z) const
double getChisq() const
Definition: FastTracklet.h:157
double getExpPositionW(int detectorID) const