Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DEventProcessor_dirc_tree.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DEventProcessor_dirc_tree.cc
4 //
5 
7 
8 // Routine used to create our DEventProcessor
9 
10 extern "C"
11 {
12  void InitPlugin(JApplication *locApplication)
13  {
14  InitJANAPlugin(locApplication);
15  locApplication->AddProcessor(new DEventProcessor_dirc_tree()); //register this plugin
16  locApplication->AddFactoryGenerator(new DFactoryGenerator_dirc_tree()); //register the factory generator
17  }
18 } // "C"
19 
20 //------------------
21 // init
22 //------------------
24 {
25  // This is called once at program startup. If you are creating
26  // and filling historgrams in this plugin, you should lock the
27  // ROOT mutex like this:
28  //
29  // japp->RootWriteLock();
30  // ... create historgrams or trees ...
31  // japp->RootUnLock();
32  //
33 
34  japp->RootWriteLock(); //ACQUIRE ROOT LOCK!!
35 
36  string locOutputFileName = "hd_root.root";
37  if(gPARMS->Exists("OUTPUT_FILENAME"))
38  gPARMS->GetParameter("OUTPUT_FILENAME", locOutputFileName);
39 
40  //go to file
41  TFile* locFile = (TFile*)gROOT->FindObject(locOutputFileName.c_str());
42  if(locFile != NULL)
43  locFile->cd("");
44  else
45  gDirectory->Cd("/");
46 
47  TObject* locTree = gDirectory->Get("dirc");
48  if(locTree == NULL)
49  fTree = new TTree("dirc", "dirc tree");
50  else
51  fTree = static_cast<TTree*>(locTree);
52 
53  fcEvent = new TClonesArray("DrcEvent");
54  fTree->Branch("DrcEvent",&fcEvent,256000,2);
55 
56  japp->RootUnLock(); //RELEASE ROOT LOCK!!
57 
58  return NOERROR;
59 }
60 
61 //------------------
62 // brun
63 //------------------
64 jerror_t DEventProcessor_dirc_tree::brun(jana::JEventLoop* locEventLoop, int locRunNumber)
65 {
66  // This is called whenever the run number changes
67 
68  return NOERROR;
69 }
70 
71 //------------------
72 // evnt
73 //------------------
74 jerror_t DEventProcessor_dirc_tree::evnt(jana::JEventLoop* loop, uint64_t locEventNumber)
75 {
76  // get DIRC geometry
77  vector<const DDIRCGeometry*> locDIRCGeometryVec;
78  loop->Get(locDIRCGeometryVec);
79  auto locDIRCGeometry = locDIRCGeometryVec[0];
80 
81  // get PID algos
82  const DParticleID* locParticleID = NULL;
83  loop->GetSingle(locParticleID);
84 
85  vector<const DAnalysisResults*> locAnalysisResultsVector;
86  loop->Get(locAnalysisResultsVector);
87 
88  vector<const DTrackTimeBased*> locTimeBasedTracks;
89  loop->Get(locTimeBasedTracks);
90 
91  vector<const DDIRCPmtHit*> locDIRCPmtHits;
92  loop->Get(locDIRCPmtHits);
93 
94  const DDetectorMatches* locDetectorMatches = NULL;
95  loop->GetSingle(locDetectorMatches);
96  DDetectorMatches locDetectorMatch = (DDetectorMatches)locDetectorMatches[0];
97 
98  japp->RootWriteLock();
99 
100  TClonesArray& cevt = *fcEvent;
101  cevt.Clear();
102 
103  for (size_t loc_i = 0; loc_i < locAnalysisResultsVector.size(); loc_i++){
104  deque<const DParticleCombo*> locPassedParticleCombos;
105  locAnalysisResultsVector[loc_i]->Get_PassedParticleCombos(locPassedParticleCombos);
106  const DReaction* locReaction = locAnalysisResultsVector[loc_i]->Get_Reaction();
107  std::vector<double> previousInv;
108 
109  // loop over combos
110  for(size_t icombo = 0; icombo < locPassedParticleCombos.size(); ++icombo){
111  double chisq = locPassedParticleCombos[icombo]->Get_KinFitResults()->Get_ChiSq();
112  DLorentzVector locMissingP4 = fAnalysisUtilities->Calc_MissingP4(locReaction, locPassedParticleCombos[icombo], false);
113  DLorentzVector locInvP4;
114  auto locParticleComboStep = locPassedParticleCombos[icombo]->Get_ParticleComboStep(0);
115 
116  int numIt=0;
117  for(size_t parti=0; parti<locParticleComboStep->Get_NumFinalParticles(); parti++){
118  auto locParticle = locParticleComboStep->Get_FinalParticle(parti); // Get_FinalParticle_Measured(parti);
119 
120  // we expect only rho or phi events: g,p->pi+,pi-,p g,p->K+,K-,p
121  if(locParticle->PID() == PiPlus || locParticle->PID() == PiMinus || locParticle->PID() == KPlus || locParticle->PID() == KMinus){
122  locInvP4 += locParticle->lorentzMomentum();
123  numIt++;
124  if(numIt==2){
125  double tm = locInvP4.M();
126  // do not store doubles
127  if(std::find_if(previousInv.begin(), previousInv.end(), [&tm](double m){return fabs(m-tm)<0.000000001;}) != previousInv.end()) { continue; }
128  previousInv.push_back(tm);
129  }
130  }
131 
132  // get track
133  auto locChargedTrack = static_cast<const DChargedTrack*>(locParticleComboStep->Get_FinalParticle_SourceObject(parti));
134  auto locChargedTrackHypothesis = locChargedTrack->Get_Hypothesis(locParticle->PID());
135  auto locTrackTimeBased = locChargedTrackHypothesis->Get_TrackTimeBased();
136 
137  // require well reconstructed tracks for initial studies
138  int locDCHits = locTrackTimeBased->Ndof + 5;
139  double locTheta = locTrackTimeBased->momentum().Theta()*180/TMath::Pi();
140  double locP = locTrackTimeBased->momentum().Mag();
141  if(locDCHits < 10 || locTheta < 1.0 || locTheta > 12.0 || locP > 12.0) continue;
142 
143  // require has good match to TOF hit for cleaner sample
144  shared_ptr<const DTOFHitMatchParams> locTOFHitMatchParams;
145  bool foundTOF = locParticleID->Get_BestTOFMatchParams(locTrackTimeBased, locDetectorMatches, locTOFHitMatchParams);
146  if(!foundTOF || locTOFHitMatchParams->Get_DistanceToTrack() > 20.0) continue;
147  double toftrackdist = locTOFHitMatchParams->Get_DistanceToTrack();
148  Particle_t locPID = locTrackTimeBased->PID();
149 
150  // get DIRC match parameters (contains LUT information)
151  shared_ptr<const DDIRCMatchParams> locDIRCMatchParams;
152  bool foundDIRC = locParticleID->Get_DIRCMatchParams(locTrackTimeBased, locDetectorMatches, locDIRCMatchParams);
153 
154  if(foundDIRC){
155  DVector3 posInBar = locDIRCMatchParams->dExtrapolatedPos;
156  DVector3 momInBar = locDIRCMatchParams->dExtrapolatedMom;
157  double locExtrapolatedTime = locDIRCMatchParams->dExtrapolatedTime;
158  int locBar = dDIRCGeometry->GetBar(posInBar.Y());
159 
160  fEvent = new DrcEvent();
161  fEvent->SetType(2);
162  fEvent->SetMomentum(TVector3(momInBar.X(),momInBar.Y(),momInBar.Z()));
163  fEvent->SetPdg(PDGtype(locPID));
164  fEvent->SetTime(locExtrapolatedTime);
165  fEvent->SetParent(0);
166  fEvent->SetId(locBar);// bar id where the particle hit the detector
167  fEvent->SetPosition(TVector3(posInBar.X(), posInBar.Y(), posInBar.Z()));
168  fEvent->SetDcHits(locDCHits);
169  fEvent->SetTofTrackDist(toftrackdist);
170  fEvent->SetInvMass(locInvP4.M());
171  fEvent->SetMissMass(locMissingP4.M2());
172  fEvent->SetChiSq(chisq);
173 
174  DrcHit hit;
175  for(const auto dhit : locDIRCPmtHits){
176  int ch=dhit->ch;
177  int pmt=ch/64;
178  int pix=ch%64;
179 
180  hit.SetChannel(ch);
181  hit.SetPmtId(pmt);
182  hit.SetPixelId(pix);
183  hit.SetLeadTime(dhit->t);
184  hit.SetTotTime(dhit->tot);
185  fEvent->AddHit(hit);
186  }
187 
188  if(fEvent->GetHitSize()>0) new (cevt[ cevt.GetEntriesFast()]) DrcEvent(*fEvent);
189  }
190  }
191  }
192  }
193 
194  if(cevt.GetEntriesFast()>0) fTree->Fill();
195  japp->RootUnLock();
196 
197  return NOERROR;
198 }
199 
200 //------------------
201 // erun
202 //------------------
204 {
205  // This is called whenever the run number changes, before it is
206  // changed to give you a chance to clean up before processing
207  // events from the next run number.
208  return NOERROR;
209 }
210 
211 //------------------
212 // fini
213 //------------------
215 {
216  // Called before program exit after event processing is finished.
217  return NOERROR;
218 }
219 
const DDIRCGeometry * dDIRCGeometry
void SetTime(Double_t val)
void SetPixelId(Int_t val)
jerror_t evnt(jana::JEventLoop *locEventLoop, uint64_t locEventNumber)
Called every event.
void SetMissMass(Double_t val)
TVector3 DVector3
Definition: DVector3.h:14
void SetId(Int_t val)
void SetLeadTime(Double_t val)
const DTrackTimeBased * Get_TrackTimeBased(void) const
void SetType(Int_t val)
jerror_t init(void)
Called once at program start.
bool Get_DIRCMatchParams(const DTrackingData *locTrack, const DDetectorMatches *locDetectorMatches, shared_ptr< const DDIRCMatchParams > &locBestMatchParams) const
TLorentzVector DLorentzVector
void SetChiSq(Double_t val)
static int PDGtype(Particle_t p)
void SetPmtId(Int_t val)
const DChargedTrackHypothesis * Get_Hypothesis(Particle_t locPID) const
Definition: DChargedTrack.h:59
void AddHit(DrcHit hit)
JApplication * japp
void SetParent(Int_t val)
bool Get_BestTOFMatchParams(const DTrackingData *locTrack, const DDetectorMatches *locDetectorMatches, shared_ptr< const DTOFHitMatchParams > &locBestMatchParams) const
const DAnalysisUtilities * fAnalysisUtilities
InitPlugin_t InitPlugin
void SetDcHits(Int_t val)
DLorentzVector Calc_MissingP4(const DReaction *locReaction, const DParticleCombo *locParticleCombo, bool locUseKinFitDataFlag) const
void SetTofTrackDist(Double_t val)
void SetMomentum(TVector3 val)
void SetChannel(Int_t val)
int Ndof
Number of degrees of freedom in the fit.
jerror_t erun(void)
Called every time run number changes, provided brun has been called.
jerror_t fini(void)
Called after last event of last event source has been processed.
void SetInvMass(Double_t val)
void SetPosition(TVector3 val)
jerror_t brun(jana::JEventLoop *locEventLoop, int locRunNumber)
Called every time a new run number is detected.
void SetTotTime(Double_t val)
void SetPdg(Int_t val)
Int_t GetHitSize() const
int GetBar(float y) const
Particle_t
Definition: particleType.h:12