Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DCDCHit_factory.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DCDCHit_factory.cc
4 // Created: Tue Aug 6 11:29:56 EDT 2013
5 // Creator: davidl (on Darwin harriet.jlab.org 11.4.2 i386)
6 //
7 
8 
9 #include <iostream>
10 #include <iomanip>
11 #include <cmath>
12 #include <CDC/DCDCHit.h>
13 
14 #include "DCDCHit_factory.h"
15 
16 static double DIGI_THRESHOLD = -1.0e8;
17 
18 //------------------
19 // init
20 //------------------
21 jerror_t DCDCHit_factory::init(void)
22 {
23 
24  LowTCut = -10000.;
25  HighTCut = 10000.;
26 
27  Disable_CDC_TimingCuts = 0; // this can be changed by a parameter in brun()
28  // Note: That has to be done in brun() because the parameters are read from ccdb at every call to brun()
29  gPARMS->SetDefaultParameter("CDCHit:Disable_TimingCuts", Disable_CDC_TimingCuts,
30  "Disable CDC timing Cuts if this variable is not zero!");
31 
32 
33  gPARMS->SetDefaultParameter("CDC:DIGI_THRESHOLD",DIGI_THRESHOLD,
34  "Do not convert CDC digitized hits into DCDCHit objects"
35  " that would have q less than this");
36 
38 
39  gPARMS->SetDefaultParameter("CDCHit:RemoveCorrelationHits", RemoveCorrelationHits,
40  "Remove hits correlated in time with saturation hits!");
41 
42  CorrelationHitsCut = 1.5;
43  gPARMS->SetDefaultParameter("CDCHit:CorrelationHitsCut", CorrelationHitsCut,
44  "Cut in units of 8ns bins to remove correlated hits with Saturation hits!");
45 
46  CorrelatedHitPeak = 3.5;
47  gPARMS->SetDefaultParameter("CDCHit:CorrelatedHitPeak", CorrelatedHitPeak,
48  "Location of peak time around which we cut correlated times in units of 8ns bins");
49 
50  // Setting this flag makes it so that JANA does not delete the objects in _data.
51  // This factory will manage this memory.
52  SetFactoryFlag(NOT_OBJECT_OWNER);
53 
54  return NOERROR;
55 }
56 
57 //------------------
58 // brun
59 //------------------
60 jerror_t DCDCHit_factory::brun(jana::JEventLoop *eventLoop, int32_t runnumber)
61 {
62 
63  /// Read in calibration constants
64 
65  vector<double> cdc_timing_cuts;
66 
67  if (eventLoop->GetCalib("/CDC/timing_cut", cdc_timing_cuts)){
68  LowTCut = -60.;
69  HighTCut = 900.;
70  jout << "Error loading /CDC/timing_cut ! set defaul values -60. and 900." << endl;
71  } else {
72  LowTCut = cdc_timing_cuts[0];
73  HighTCut = cdc_timing_cuts[1];
74  //jout<<"CDC Timing Cuts: "<<LowTCut<<" ... "<<HighTCut<<endl;
75  }
76 
77  gPARMS->SetDefaultParameter("CDCHit:LowTCut", LowTCut,"Minimum acceptable CDC hit time (ns)");
78  gPARMS->SetDefaultParameter("CDCHit:HighTCut", HighTCut, "Maximum acceptable CDC hit time (ns)");
79 
80  //jout<<LowTCut<<" / "<<HighTCut<<endl;
81 
83 
84  LowTCut = -10000.;
85  HighTCut = 10000.;
86  jout << "Disable CDC Hit Timing Cuts!" << endl;
87 
88  }
89 
90  eventLoop->Get(ttab);
91 
92  return NOERROR;
93 }
94 
95 //------------------
96 // evnt
97 //------------------
98 jerror_t DCDCHit_factory::evnt(JEventLoop *loop, uint64_t eventnumber)
99 {
100 
101  // Clear _data vector
102  _data.clear();
103 
104  vector<const DCDCHit*> hits;
105  loop->Get(hits, "Calib");
106 
107 
108  vector<cdchit_info_t> hit_info_vec;
109 
110  // loop over hits and find roc/slot/con numbers
111  for (unsigned int k=0 ;k<hits.size(); k++){
112  const DCDCHit *hit = hits[k];
113  vector <const Df125CDCPulse*> pulse;
114  hit->Get(pulse);
115 
116  cdchit_info_t hit_info;
117  if(pulse.size()==0) {
118  // for hits without lower-level hit info, e.g. HDDM data, we have to use the translation table
119  // to figure out which DAQ channels his hit corresponds to
120  try {
121  DTranslationTable::DChannelInfo channel_info;
122  channel_info.det_sys = DTranslationTable::CDC;
123  channel_info.cdc.ring = hit->ring;
124  channel_info.cdc.straw = hit->straw;
125  DTranslationTable::csc_t daq_index = ttab[0]->GetDAQIndex(channel_info);
126 
127  hit_info.rocid = daq_index.rocid;
128  hit_info.slot = daq_index.slot;
129  hit_info.connector = daq_index.channel / 24;
130  } catch(...) {
131  cout << "Cannot find Translation Table data for hit on ring " << hit->ring
132  << " straw " << hit->straw << ", skipping this info ..." << endl;
133  continue;
134  }
135  } else {
136  hit_info.rocid = pulse[0]->rocid;
137  hit_info.slot = pulse[0]->slot;
138  hit_info.connector = pulse[0]->channel / 24;
139  }
140 
141  hit_info.time = hit->t;
142  hit_info.max = 0;
143 
144  if (hit->QF > 1) {
145  hit_info.max = 1;
146  }
147 
148  hit_info_vec.push_back(hit_info);
149  }
150 
151 
152  vector<bool> Mark4Removal(hit_info_vec.size(), false);
153 
154  if (RemoveCorrelationHits && (hit_info_vec.size()>0) ) {
155 
156  for (unsigned int k=0 ;k<hit_info_vec.size()-1; k++){
157 
158  if (hit_info_vec[k].max){
159 
160  for (unsigned int n=k+1 ;n<hit_info_vec.size(); n++){
161 
162  //if (n==k)
163  // continue;
164 
165  //if ((RocID[k] == RocID[n]) && (Slot[k] == Slot[n]) && (Connector[k] == Connector[n]) ){
166  if(hit_info_vec[k] == hit_info_vec[n]) {
167  double dt = (hit_info_vec[k].time - hit_info_vec[n].time)/8.; // units of samples (8ns)
168  if ( std::fabs(dt+CorrelatedHitPeak)<CorrelationHitsCut) {
169  Mark4Removal[n] = true;
170  //cout<<"remove "<<hits[n]->ring<<" "<<hits[n]->straw<<endl;
171  }
172 
173  }
174 
175  }
176  }
177  }
178 
179  }
180 
181 
182  for (int k=0 ;k<(int) hits.size(); k++){
183  const DCDCHit *hit = hits[k];
184 
185  // remove hits with small charge: not really used
186  if (hit->q < DIGI_THRESHOLD) {
187  continue;
188  }
189 
190  // remove hits with amplitudes 0 or less
191  if ( hit->amp <= 0 ) {
192  continue;
193  }
194 
195  // remove hits with failed timing alorithm
196  if ( (hit->QF & 0x1) != 0 ) {
197  continue;
198  }
199 
200  // remove hits ouside of the timing cut
201  if ( (hit->t < LowTCut) || (hit->t > HighTCut) ){
202  continue;
203  }
204 
205  // removed hits correclated with Saturation hit on same connector/reamp/HV-board
206  // this vector should not be filled if we are running over HDDM data
207  if (Mark4Removal.size() > 0 && Mark4Removal[k]){
208  continue;
209  }
210 
211  _data.push_back( const_cast<DCDCHit*>(hit) );
212 
213  }
214 
215  return NOERROR;
216 }
217 
218 //------------------
219 // erun
220 //------------------
221 jerror_t DCDCHit_factory::erun(void)
222 {
223  return NOERROR;
224 }
225 
226 //------------------
227 // fini
228 //------------------
229 jerror_t DCDCHit_factory::fini(void)
230 {
231  return NOERROR;
232 }
float amp
Definition: DCDCHit.h:21
float t
Definition: DCDCHit.h:22
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
int ring
Definition: DCDCHit.h:18
jerror_t fini(void)
Called after last event of last event source has been processed.
static double DIGI_THRESHOLD
jerror_t init(void)
Called once at program start.
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
vector< const DTranslationTable * > ttab
float q
Definition: DCDCHit.h:20
double CorrelationHitsCut
int straw
Definition: DCDCHit.h:19
int QF
Definition: DCDCHit.h:24
double CorrelatedHitPeak