All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRTTrueHitRecoAlg.cc
Go to the documentation of this file.
1 #ifndef ICARUS_CRTTRUEHITRECOALG_CC
2 #define ICARUS_CRTTRUEHITRECOALG_CC
3 
5 #include "larcore/CoreUtils/ServiceUtil.h" // lar::providerFrom()
6 
7 using namespace icarus::crt;
8 
9 //----------------------------------------------------------------------
11  this->reconfigure(config);
12 
13  fGeometryService = lar::providerFrom<geo::Geometry>();
14  fCrtutils = new CRTCommonUtils();
15 }
16 
17 //---------------------------------------------------------------------
19  fGeometryService = lar::providerFrom<geo::Geometry>();
20  fCrtutils = new CRTCommonUtils();
21 }
22 
23 
25 
26 //---------------------------------------------------------------------
29  fEDepMin = config.EDepMin();
32  return;
33 }
34 
35 
36 //------------------------------------------------------------------------------
37 vector<pair<sbn::crt::CRTHit,vector<sim::AuxDetIDE>>> CRTTrueHitRecoAlg::CreateCRTHits(
38  vector<art::Ptr<sim::AuxDetSimChannel>> adscList)
39 {
40  vector<pair<CRTHit,vector<sim::AuxDetIDE>>> hitCol;
41  map<int,map<int,tagger>> trackTaggers; //trackID -> (moduleID -> tagger )
42 
43  //fill taggers
44  //loop over AuxDetSimChannels
45  for(auto const& adsc : adscList) {
46 
47  const int adID = adsc->AuxDetID();
48  const int layerID = fCrtutils->GetLayerID(adsc);
49  const char type = fCrtutils->GetAuxDetType(adID);
50  const string region = fCrtutils->GetAuxDetRegion(adID);
51  const int adsID = adsc->AuxDetSensitiveID();
52 
53  //loop over AuxDetIDEs
54  for(auto const& ide : adsc->AuxDetIDEs()) {
55 
56  //FIX ME: for now, ignoring negative IDs, impliment fRollupUnusedIds
57  if(/*ide.trackID>-1 &&*/ ide.energyDeposited*1000 < fEDepMin)
58  continue;
59  if(!fRollupUnusedIds && ide.trackID<0)
60  continue;
61  tagger& tag = (trackTaggers[ide.trackID])[adID];
62  tag.type = type;
63  tag.region = region;
64  tag.layerID.insert(layerID);
65  tag.stripLayer[adsID] = layerID;
66  tag.stripIDE[adsID] = ide;
67  }//AuxDetIDEs
68  }//AuxDetSimChannels
69 
70  int nmisscd=0, nmisspair=0;
71 
72  //apply logic to form hits
73  //loop over trackIDs
74  for (auto const& trk : trackTaggers) {
75 
76  map <int,tagger> mTaggers; //MINOS module ID -> tagger
77  // loop over taggers: modID->strip hit info
78  for (auto const& tag : trk.second) {
79 
80  vector<sim::AuxDetIDE> vide; //IDEs in hit
81  //XYZTVector
82  TLorentzVector rHit(0.,0.,0.,0.); //average hit position
83  vector<uint8_t> feb_id = {(fCrtutils->ADToMac( tag.first)).first};
84  map<uint8_t,vector< pair<int,float> > > pesmap;
85  float peshit = 0.;
86  double xerr=0., yerr=0., zerr = 0.;
87 
88  // if c or d type module
89  if (tag.second.type=='c' || tag.second.type=='d') {
90 
91  // if "X-Y" coincidence
92  if (tag.second.layerID.size()>1) {
93 
94  // loop over module strips map: stripID->pos 4-vec
95  for (auto const& ide : tag.second.stripIDE) {
96  rHit += fCrtutils->AvgIDEPoint(ide.second);
97  vide.push_back(ide.second);
98  peshit+=ide.second.energyDeposited*1000;
99  pesmap[feb_id[0]].push_back(std::make_pair(ide.first,ide.second.energyDeposited*1000));
100  }
101 
102  rHit*=1.0/tag.second.stripIDE.size();
103  rHit.SetT(rHit.T()+fGlobalT0Offset);
104 
105  //hit position RMS
106  for ( auto const& ide : tag.second.stripIDE) {
107  //XYZTVector
108  TLorentzVector point = fCrtutils->AvgIDEPoint(ide.second);
109  xerr += pow(point.X()-rHit.X(),2);
110  yerr += pow(point.Y()-rHit.Y(),2);
111  zerr += pow(point.Z()-rHit.Z(),2);
112  }
113  xerr = sqrt(xerr/(tag.second.stripIDE.size()-1));
114  yerr = sqrt(yerr/(tag.second.stripIDE.size()-1));
115  zerr = sqrt(zerr/(tag.second.stripIDE.size()-1));
116 
117  } //if coincidence
118  else{
119  nmisscd++;
120  continue;
121  }
122 
123  hitCol.push_back(std::make_pair(
124  FillCrtHit(feb_id, pesmap, peshit, rHit.T(), rHit.T(), 0, rHit.X(), xerr,
125  rHit.Y(), yerr, rHit.Z(), zerr, tag.second.region),
126  vide) );
127 
128  }//if c or d type
129 
130  if ( tag.second.type=='m' ) {
131  mTaggers[tag.first] = tag.second;
132  }
133 
134  } //loop over taggers
135 
136  set <int> mPairs; //keep track of used auxdetIDs
137  for (auto const& tag : mTaggers) {
138 
139  if (mPairs.find(tag.first) != mPairs.end()) continue; //don't double count
140 
141  vector<sim::AuxDetIDE> vide; //IDEs in hit
142  //XYZTVector
143  TLorentzVector rHit(0.,0.,0.,0.); //average hit position
144  auto macpair = fCrtutils->ADToMac(tag.first);
145  uint8_t mac1 = macpair.first;
146  uint8_t mac11 = macpair.second;
147  vector<uint8_t> feb_id = {mac1};
148  if(mac1!=mac11) feb_id.push_back(mac11);
149  map<uint8_t,vector< pair<int,float> > > pesmap;
150  float peshit = 0.;
151  bool pairFound = false;
152  double xerr=0., yerr=0., zerr = 0.;
153  set<int> layers;
154  layers.insert(*(tag.second.layerID.begin()));
155  mPairs.insert(tag.first);
156 
157  for (auto const& ide : tag.second.stripIDE) {
158  rHit += fCrtutils->AvgIDEPoint(ide.second);
159  vide.push_back(ide.second);
160  peshit+=ide.second.energyDeposited*1000;
161  pesmap[mac1].push_back(std::make_pair(ide.first,ide.second.energyDeposited*1000));
162  }
163 
164  //inner loop over mTaggers (try to find a coincidence match)
165  for (auto const& tag2 : mTaggers) {
166  if ( tag.first == tag2.first ) continue; //not the same module
167  if ( mPairs.find(tag2.first) != mPairs.end()) continue; //not aleady counted
168  if ( tag.second.region != tag2.second.region ) continue; //modules in same region
169 
170  layers.insert(*(tag2.second.layerID.begin()));
171 
172  //mark module as counted
173  mPairs.insert(tag2.first);
174 
175  //mac5's for 2nd module in pair
176  macpair = fCrtutils->ADToMac(tag2.first);
177  uint8_t mac2 = macpair.first;
178  uint8_t mac22 = macpair.second;
179  feb_id.push_back(mac2);
180  if(mac2!=mac22) feb_id.push_back(mac22);
181 
182  // loop over module strips map: stripID->pos 4-vec
183  for (auto const& ide : tag2.second.stripIDE) {
184  rHit += fCrtutils->AvgIDEPoint(ide.second);
185  vide.push_back(ide.second);
186  peshit+=ide.second.energyDeposited*1000;
187  pesmap[mac2].push_back(std::make_pair(ide.first,ide.second.energyDeposited*1000));
188  }//for xyzt in second tagger (module)
189 
190  if(layers.size()==2)
191  pairFound = true;
192  }//inner loop over taggers
193 
194  if (pairFound) {
195 
196  rHit*=1.0/vide.size();
197  rHit.SetT(rHit.T()+fGlobalT0Offset);
198 
199  //hit position RMS
200  for ( auto const& ide : vide) {
201  //XYZTVector
202  TLorentzVector point = fCrtutils->AvgIDEPoint(ide);
203  xerr += pow(point.X()-rHit.X(),2);
204  yerr += pow(point.Y()-rHit.Y(),2);
205  zerr += pow(point.Z()-rHit.Z(),2);
206  }
207 
208  xerr = sqrt(xerr/(vide.size()-1));
209  yerr = sqrt(yerr/(vide.size()-1));
210  zerr = sqrt(zerr/(vide.size()-1));
211 
212  hitCol.push_back(std::make_pair(
213  FillCrtHit(feb_id, pesmap, peshit, rHit.T(), rHit.T(), 0, rHit.X(), xerr,
214  rHit.Y(), yerr, rHit.Z(), zerr, tag.second.region),
215  vide) );
216 
217  }
218  else nmisspair++;
219 
220  } // outer loop over minos taggers
221  } //loop over trackTaggers
222 
223  std::cout << "CRTTrueHitRecoAlg: nmisscd=" << nmisscd << ", nmissm=" << nmisspair << std::endl;
224 
225  return hitCol;
226 }
227 
228 //--------------------------------------------------------------------------------------------
229 // Function to make filling a CRTHit a bit faster
230 sbn::crt::CRTHit CRTTrueHitRecoAlg::FillCrtHit(vector<uint8_t> tfeb_id, map<uint8_t,vector<pair<int,float>>> tpesmap,
231  float peshit, double time0, double time1, int plane,
232  double x, double ex, double y, double ey, double z, double ez, string tagger){
233  CRTHit crtHit;
234  crtHit.feb_id = tfeb_id;
235  crtHit.pesmap = tpesmap;
236  crtHit.peshit = peshit;
237  crtHit.ts0_s_corr = time0*1e-9;
238  crtHit.ts0_ns = time0;
239  crtHit.ts0_ns_corr = time0;
240  crtHit.ts1_ns = time1;
241  crtHit.ts0_s = time0 * 1e-9;
242  crtHit.plane = plane;
243  crtHit.x_pos = x;
244  crtHit.x_err = ex;
245  crtHit.y_pos = y;
246  crtHit.y_err = ey;
247  crtHit.z_pos = z;
248  crtHit.z_err = ez;
249  crtHit.tagger = tagger;
250 
251  return crtHit;
252 
253 } //FillCrtHit()
254 
255 #endif
float z_err
position uncertainty in z-direction (cm).
Definition: CRTHit.hh:43
process_name opflash particleana ie ie ie z
float x_err
position uncertainty in x-direction (cm).
Definition: CRTHit.hh:39
std::map< uint8_t, std::vector< std::pair< int, float > > > pesmap
Saves signal hit information (FEB, local-channel and PE) .
Definition: CRTHit.hh:26
map< int, int > stripLayer
Utilities related to art service access.
std::vector< uint8_t > feb_id
FEB address.
Definition: CRTHit.hh:25
double ts1_ns
Timestamp T1 ([signal time w.r.t. Trigger time]), in UTC absolute time scale in nanoseconds from the ...
Definition: CRTHit.hh:34
process_name opflash particleana ie x
int plane
Name of the CRT wall (in the form of numbers).
Definition: CRTHit.hh:36
float peshit
Total photo-electron (PE) in a crt hit.
Definition: CRTHit.hh:27
void reconfigure(const Config &config)
float y_err
position uncertainty in y-direction (cm).
Definition: CRTHit.hh:41
vector< pair< CRTHit, vector< sim::AuxDetIDE > > > CreateCRTHits(vector< art::Ptr< sim::AuxDetSimChannel >> adscList)
string region
double ts0_ns_corr
[Honestly, not sure at this point, it was there since long time (BB)]
Definition: CRTHit.hh:33
double ts0_s_corr
[Honestly, not sure at this point, it was there since long time (BB)]
Definition: CRTHit.hh:30
uint64_t ts0_s
Second-only part of timestamp T0.
Definition: CRTHit.hh:29
float z_pos
position in z-direction (cm).
Definition: CRTHit.hh:42
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
double ts0_ns
Timestamp T0 (from White Rabbit), in UTC absolute time scale in nanoseconds from the Epoch...
Definition: CRTHit.hh:32
CRTHit FillCrtHit(vector< uint8_t > tfeb_id, map< uint8_t, vector< pair< int, float >>> tpesmap, float peshit, double time0, double time1, int plane, double x, double ex, double y, double ey, double z, double ez, std::string tagger)
geo::GeometryCore const * fGeometryService
process_name opflash particleana ie ie y
map< int, sim::AuxDetIDE > stripIDE
std::set< int > layerID
float y_pos
position in y-direction (cm).
Definition: CRTHit.hh:40
float x_pos
position in x-direction (cm).
Definition: CRTHit.hh:38
do i e
process_name crt
std::string tagger
Name of the CRT wall (in the form of strings).
Definition: CRTHit.hh:45
CRTTrueHitRecoAlg(const Config &config)
BEGIN_PROLOG could also be cout