Class Reference for E1039 Core & Analysis Software
AnaEmbeddedData.cc
Go to the documentation of this file.
1 #include <iomanip>
2 #include <TFile.h>
3 #include <TTree.h>
4 #include <geom_svc/GeomSvc.h>
5 //#include <interface_main/SQRun.h>
11 #include <ktracker/SRecEvent.h>
13 #include <phool/getClass.h>
14 #include <UtilAna/UtilSQHit.h>
15 #include <UtilAna/UtilDimuon.h>
16 #include "AnaEmbeddedData.h"
17 using namespace std;
18 
19 AnaEmbeddedData::AnaEmbeddedData(const std::string name)
20  : SubsysReco(name)
21  , m_run_id(0)
22  , m_rs_id(0)
23 {
24  ;
25 }
26 
28 {
30 }
31 
33 {
35  m_rs_id = rc->get_IntFlag("ROADSET_ID");
36  if (m_rs_id != 0) {
37  int ret = m_rs.LoadConfig(m_rs_id);
38  if (ret != 0) {
39  cout << "!!WARNING!! OnlMonTrigEP::InitRunOnlMon(): roadset.LoadConfig returned " << ret << ".\n";
40  }
41  }
42  cout <<"Roadset " << m_rs_id << endl;
43 
44  mi_evt = findNode::getClass<SQEvent >(topNode, "SQEvent");
45  mi_vec_hit = findNode::getClass<SQHitVector >(topNode, "SQHitVector");
46  if (!mi_evt || !mi_vec_hit) {
47  cout << PHWHERE << ": Cannot find SQEvent and/or SQHitVector." << endl;
49  }
50 
51  mi_evt_emb = findNode::getClass<SQEvent >(topNode, "SQEventEmb");
52  mi_evt_mc = findNode::getClass<SQMCEvent >(topNode, "SQMCEvent");
53  mi_evt_mc_emb = findNode::getClass<SQMCEvent >(topNode, "SQMCEventEmb");
54  mi_vec_trk = findNode::getClass<SQTrackVector >(topNode, "SQTruthTrackVector");
55  mi_vec_dim = findNode::getClass<SQDimuonVector>(topNode, "SQTruthDimuonVector");
56  mi_vec_trk_rec = findNode::getClass<SQTrackVector >(topNode, "SQRecTrackVector");
57  mi_vec_dim_rec = findNode::getClass<SQDimuonVector>(topNode, "SQRecDimuonVector_PM");
58 
59  if (!mi_evt_emb ) cout << "No SQEventEmb node." << endl;
60  if (!mi_evt_mc ) cout << "No SQMCEvent node." << endl;
61  if (!mi_evt_mc_emb) cout << "No SQMCEventEmb node." << endl;
62  if (!mi_vec_trk ) cout << "No SQTruthTrackVector node." << endl;
63  if (!mi_vec_dim ) cout << "No SQTruthDimuonVector node." << endl;
64  if (!mi_vec_trk_rec) cout << "No SRecTrackVector node." << endl;
65  if (!mi_vec_dim_rec) cout << "No SRecDimuonVector_PM node." << endl;
66 
67  mo_file = new TFile("ana_tree.root", "RECREATE");
68  mo_tree = new TTree("tree", "Created by AnaEmbeddedData");
69  mo_tree->Branch("evt" , &mo_evt);
70  mo_tree->Branch("occ" , &mo_occ);
71  mo_tree->Branch("trk_true", &mo_trk_true);
72  mo_tree->Branch("trk_reco", &mo_trk_reco);
73  mo_tree->Branch("dim_true", &mo_dim_true);
74  mo_tree->Branch("dim_reco", &mo_dim_reco);
75 
77 }
78 
80 {
84  mo_evt.job_id = mi_evt->get_spill_id(); // Ppill ID in simulation means job ID
85  mo_evt.event_id = mi_evt->get_event_id();
86  mo_evt.trig_bits = mi_evt->get_trigger();
87  mo_evt.rfp01 = mi_evt->get_qie_rf_intensity(+1);
88  mo_evt.rfp00 = mi_evt->get_qie_rf_intensity( 0);
89  mo_evt.rfm01 = mi_evt->get_qie_rf_intensity(-1);
90 
91  if (mi_evt_mc) {
92  mo_evt.weight = mi_evt_mc->get_weight();
93  }
94  mo_evt.rec_stat = 0; // No rec status info in SQRecTrackVector/SQRecDimuonVector??
95 
99  mo_occ.D1 = mo_occ.D2 = mo_occ.D3p = mo_occ.D3m = 0;
100  for (SQHitVector::ConstIter it = mi_vec_hit->begin(); it != mi_vec_hit->end(); it++) {
101  SQHit* hit = *it;
102  int det_id = hit->get_detector_id();
103  if ( 0 < det_id && det_id <= 6) mo_occ.D1++;
104  else if (12 < det_id && det_id <= 18) mo_occ.D2++;
105  else if (18 < det_id && det_id <= 24) mo_occ.D3p++;
106  else if (24 < det_id && det_id <= 30) mo_occ.D3m++;
107  }
108 
109  map<int, int> list_cnt; // [det ID] -> hit count
110  for (SQHitVector::ConstIter it = mi_vec_hit->begin(); it != mi_vec_hit->end(); it++) {
111  const SQHit* hit = *it;
112  //if (! hit->is_in_time()) continue;
113  int det_id = hit->get_detector_id();
114  list_cnt[det_id]++;
115  }
116 
117  GeomSvc* geom = GeomSvc::instance();
118  mo_evt.n_h1x = list_cnt[geom->getDetectorID("H1T")] + list_cnt[geom->getDetectorID("H1B")];
119  mo_evt.n_h2x = list_cnt[geom->getDetectorID("H2T")] + list_cnt[geom->getDetectorID("H2B")];
120  mo_evt.n_h3x = list_cnt[geom->getDetectorID("H3T")] + list_cnt[geom->getDetectorID("H3B")];
121  mo_evt.n_h4x = list_cnt[geom->getDetectorID("H4T")] + list_cnt[geom->getDetectorID("H4B")];
122  mo_evt.n_d1 = list_cnt[geom->getDetectorID("D0X")];
123  mo_evt.n_d2 = list_cnt[geom->getDetectorID("D2X")];
124  mo_evt.n_d3 = list_cnt[geom->getDetectorID("D3pX")] + list_cnt[geom->getDetectorID("D3mX")];
125 
129  if (mi_vec_trk) {
130  mo_trk_true.clear();
131  for (unsigned int ii = 0; ii < mi_vec_trk->size(); ii++) {
132  SQTrack* trk = mi_vec_trk->at(ii);
133  TrackData td;
134  td.charge = trk->get_charge();
135  td.mom_vtx = trk->get_mom_vtx();
136  mo_trk_true.push_back(td);
137  }
138  }
139  if (mi_vec_dim) {
140  mo_dim_true.clear();
141  for (unsigned int ii = 0; ii < mi_vec_dim->size(); ii++) {
142  SQDimuon* dim = mi_vec_dim->at(ii);
143  DimuonData dd;
144  dd.pos = dim->get_pos();
145  dd.mom = dim->get_mom();
146  dd.mom_pos = dim->get_mom_pos();
147  dd.mom_neg = dim->get_mom_neg();
148  UtilDimuon::CalcVar(dim, dd.mass, dd.pT, dd.x1, dd.x2, dd.xF);
150  mo_dim_true.push_back(dd);
151  }
152  }
153 
157  if (mi_vec_trk_rec) {
158  mo_trk_reco.clear();
159  for (int ii = 0; ii < mi_vec_trk_rec->size(); ii++) {
160  SRecTrack* trk = dynamic_cast<SRecTrack*>(mi_vec_trk_rec->at(ii));
161  TrackData td;
162  td.charge = trk->getCharge();
163  td.road_id = trk->getTriggerRoad();
164  td.n_hits = trk->getNHits();
165  td.chi2 = trk->get_chisq();
166  td.pos_vtx = trk->get_pos_vtx();
167  td.mom_vtx = trk->getMomentumVertex();
168  mo_trk_reco.push_back(td);
169  }
170  }
171  if (mi_vec_dim_rec) {
172  mo_dim_reco.clear();
173  for (int ii = 0; ii < mi_vec_dim_rec->size(); ii++) {
174  SRecDimuon* dim = dynamic_cast<SRecDimuon*>(mi_vec_dim_rec->at(ii));
175  int trk_id_pos = dim->get_track_id_pos();
176  int trk_id_neg = dim->get_track_id_neg();
177  SRecTrack* trk_pos = dynamic_cast<SRecTrack*>(mi_vec_trk_rec->at(trk_id_pos));
178  SRecTrack* trk_neg = dynamic_cast<SRecTrack*>(mi_vec_trk_rec->at(trk_id_neg));
179  int road_pos = trk_pos->getTriggerRoad();
180  int road_neg = trk_neg->getTriggerRoad();
181 
182  DimuonData dd;
183  dd.road_pos = road_pos;
184  dd.road_neg = road_neg;
185  if (m_rs_id != 0) {
186  dd.pos_top = m_rs.PosTop()->FindRoad(road_pos);
187  dd.pos_bot = m_rs.PosBot()->FindRoad(road_pos);
188  dd.neg_top = m_rs.NegTop()->FindRoad(road_neg);
189  dd.neg_bot = m_rs.NegBot()->FindRoad(road_neg);
190  }
191  dd.pos = dim->get_pos();
192  dd.mom_pos = dim->p_pos_target; // Using the momentum optimized for target position.
193  dd.mom_neg = dim->p_neg_target; // Using the momentum optimized for target position.
194  dd.mom = dim->p_pos_target + dim->p_neg_target;
195  UtilDimuon::CalcVar(dd.mom_pos, dd.mom_neg, dd.mass, dd.pT, dd.x1, dd.x2, dd.xF);
196  UtilDimuon::Lab2CollinsSoper(dd.mom_pos.Vect(), dd.mom_neg.Vect(), dd.costh_cs, dd.phi_cs);
197  mo_dim_reco.push_back(dd);
198  }
199  }
200 
201  mo_tree->Fill();
203 }
204 
206 {
207  mo_file->cd();
208  mo_file->Write();
209  mo_file->Close();
211 }
212 
214 
226 void AnaEmbeddedData::DivideHitVector(const SQHitVector* vec_in, std::map<int, SQHitVector*>& vec_sep, const bool in_time)
227 {
228  SQHitVector* vec0 = vec_in->Clone();
229  vec0->clear();
230  for (SQHitVector::ConstIter it = mi_vec_hit->begin(); it != mi_vec_hit->end(); it++) {
231  const SQHit* hit = *it;
232  if (in_time && ! hit->is_in_time()) continue;
233  int det_id = hit->get_detector_id();
234  SQHitVector* hv = vec_sep[det_id];
235  if (hv == 0) vec_sep[det_id] = hv = vec0->Clone();
236  hv->push_back(hit);
237  }
238  delete vec0;
239 }
int Init(PHCompositeNode *topNode)
AnaEmbeddedData(const std::string name="AnaEmbeddedData")
int End(PHCompositeNode *topNode)
Called at the end of all processing.
int process_event(PHCompositeNode *topNode)
int InitRun(PHCompositeNode *topNode)
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
static GeomSvc * instance()
singlton instance
Definition: GeomSvc.cxx:212
virtual int get_IntFlag(const std::string &name) const
Definition: PHFlag.cc:117
virtual const SQDimuon * at(const size_t id) const =0
virtual size_t size() const =0
An SQ interface class to hold one true or reconstructed dimuon.
Definition: SQDimuon.h:8
virtual TLorentzVector get_mom_neg() const =0
Return the momentum of the negative track at vertex.
virtual TLorentzVector get_mom_pos() const =0
Return the momentum of the positive track at vertex.
virtual TLorentzVector get_mom() const =0
Return the dimuon momentum at vertex.
virtual TVector3 get_pos() const =0
Return the dimuon position at vertex.
virtual int get_qie_rf_intensity(const short i) const =0
Return the i-th QIE RF intensity, where i=-16...+16.
virtual bool get_trigger(const SQEvent::TriggerMask i) const =0
Return the trigger bit (fired or not) of the selected trigger channel.
virtual int get_spill_id() const =0
Return the spill ID.
virtual int get_event_id() const =0
Return the event ID, which is unique per run.
An SQ interface class to hold a list of SQHit objects.
Definition: SQHitVector.h:32
virtual SQHitVector * Clone() const =0
std::vector< SQHit * >::const_iterator ConstIter
Definition: SQHitVector.h:37
virtual ConstIter end() const =0
virtual ConstIter begin() const =0
virtual void push_back(const SQHit *hit)=0
virtual void clear()=0
An SQ interface class to hold one detector hit.
Definition: SQHit.h:20
virtual bool is_in_time() const
Return 'true' if this hit is in the time window.
Definition: SQHit.h:90
virtual short get_detector_id() const
Return the detector ID of this hit.
Definition: SQHit.h:42
virtual double get_weight() const =0
Return the event weight.
virtual const SQTrack * at(const size_t id) const =0
virtual size_t size() const =0
An SQ interface class to hold one true or reconstructed track.
Definition: SQTrack.h:8
virtual int get_charge() const =0
Return the charge, i.e. +1 or -1.
virtual TLorentzVector get_mom_vtx() const =0
Return the track momentum at vertex.
TLorentzVector p_neg_target
Definition: SRecEvent.h:370
virtual TVector3 get_pos() const
Return the dimuon position at vertex.
Definition: SRecEvent.h:326
TLorentzVector p_pos_target
Track momentum projections at different location.
Definition: SRecEvent.h:369
virtual int get_track_id_neg() const
Return the track ID of the negative track.
Definition: SRecEvent.h:323
virtual int get_track_id_pos() const
Return the track ID of the positive track.
Definition: SRecEvent.h:320
Int_t getNHits() const
Definition: SRecEvent.h:102
Int_t getCharge() const
Gets.
Definition: SRecEvent.h:101
TLorentzVector getMomentumVertex()
Get the vertex info.
Definition: SRecEvent.cxx:340
Int_t getTriggerRoad()
Definition: SRecEvent.h:222
virtual double get_chisq() const
Definition: SRecEvent.h:84
virtual TVector3 get_pos_vtx() const
Return the track position at vertex.
Definition: SRecEvent.h:66
TrigRoad * FindRoad(const int road_id)
Definition: TrigRoads.cc:24
int LoadConfig(const std::string dir)
Definition: TrigRoadset.cc:23
TrigRoads * NegBot()
Definition: TrigRoadset.h:55
TrigRoads * NegTop()
Definition: TrigRoadset.h:54
TrigRoads * PosTop()
Definition: TrigRoadset.h:52
TrigRoads * PosBot()
Definition: TrigRoadset.h:53
static recoConsts * instance()
Definition: recoConsts.cc:7
void CalcVar(const SQDimuon *dim, double &mass, double &pT, double &x1, double &x2, double &xF)
Calculate the key kinematic variables of dimuon.
Definition: UtilDimuon.cc:70
void Lab2CollinsSoper(const SQDimuon *dim, double &costh, double &phi)
Convert the momenta of muon pair from Lab frame to Collins-Soper frame.
Definition: UtilDimuon.cc:125
#define PHWHERE
Definition: phool.h:23
TLorentzVector mom_pos
Definition: TreeData.h:37
TLorentzVector mom
Definition: TreeData.h:36
double costh_cs
Definition: TreeData.h:70
bool neg_bot
Definition: TreeData.h:60
bool pos_top
Definition: TreeData.h:57
double x1
Definition: TreeData.h:41
double phi_cs
Definition: TreeData.h:71
TLorentzVector mom_neg
Definition: TreeData.h:38
bool pos_bot
Definition: TreeData.h:58
double x2
Definition: TreeData.h:42
double mass
Definition: TreeData.h:39
double xF
Definition: TreeData.h:43
double pT
Definition: TreeData.h:40
bool neg_top
Definition: TreeData.h:59
TVector3 pos
Definition: TreeData.h:35
int road_pos
Definition: TreeData.h:55
int road_neg
Definition: TreeData.h:56
double weight
Definition: TreeData.h:10
int n_h3x
Definition: TreeData.h:16
int trig_bits
Definition: TreeData.h:11
int n_d2
Definition: TreeData.h:19
int rec_stat
Definition: TreeData.h:12
int n_d1
Definition: TreeData.h:18
int event_id
Definition: TreeData.h:10
int n_h2x
Definition: TreeData.h:15
int rfp00
Definition: TreeData.h:10
int n_h1x
Definition: TreeData.h:14
int n_d3
Definition: TreeData.h:20
int n_h4x
Definition: TreeData.h:17
int rfp01
Definition: TreeData.h:9
int rfm01
Definition: TreeData.h:11
int job_id
Definition: TreeData.h:6
int D2
Definition: TreeData.h:30
int D3m
Definition: TreeData.h:32
int D1
Definition: TreeData.h:29
int D3p
Definition: TreeData.h:31
int n_hits
Definition: TreeData.h:43
int road_id
Definition: TreeData.h:42
TVector3 pos_vtx
Definition: TreeData.h:24
double chi2
Definition: TreeData.h:44
int charge
Definition: TreeData.h:23
TLorentzVector mom_vtx
Definition: TreeData.h:25