14 #define LogInfo(message) std::cout << "DEBUG: " << __FILE__ << " " << __LINE__ << " " << __FUNCTION__ << " ::: " << message << std::endl
24 int PatternDBUtil::verbosity = 0;
25 bool PatternDBUtil::_loose_mode =
false;
26 int PatternDBUtil::_RESOLUTION1_ = 2;
27 int PatternDBUtil::_RESOLUTION2_ = 2;
28 int PatternDBUtil::_RESOLUTION3_ = 2;
30 std::map<unsigned int, unsigned int> PatternDBUtil::_detid_view = {
70 TFile *feval = TFile::Open(
"PatternDBUtilEval.root",
"recreate");
71 TTree *Teval =
new TTree(
"T",
"PatternDBUtilEval");
76 float acc_prob_23 = 0;
77 float acc_prob_123 = 0;
79 Teval->Branch(
"ntrack", &ntrack,
"ntrack/I");
80 Teval->Branch(
"acc_prob_1", &acc_prob_1,
"acc_prob_1/F");
81 Teval->Branch(
"acc_prob_2", &acc_prob_2,
"acc_prob_2/F");
82 Teval->Branch(
"acc_prob_3", &acc_prob_3,
"acc_prob_3/F");
83 Teval->Branch(
"acc_prob_23", &acc_prob_23,
"acc_prob_23/F");
84 Teval->Branch(
"acc_prob_123", &acc_prob_123,
"acc_prob_123/F");
91 const int interval = 1000;
95 LogInfo(
"PatternDBUtil::BuildPatternDB from " << fin);
98 TFile *f_in = TFile::Open(fin.c_str(),
"read");
104 TTree *T = (TTree*) f_in->Get(
"T");
106 LogInfo(
"TTree T not found in " << fin);
112 int elmid [1000][55];
114 T->SetBranchAddress(
"n_tracks", &n_particles);
115 T->SetBranchAddress(
"gelmid", &elmid);
116 T->SetBranchAddress(
"gndc", &gndc);
133 for(
int ientry=0;ientry<T->GetEntries();++ientry) {
136 for(
int ipar=0; ipar<n_particles; ++ipar) {
138 if(!(gndc[ipar]>17))
continue;
141 unsigned int D1U = elmid[ipar][1];
142 unsigned int D1Up = elmid[ipar][2];
143 unsigned int D1X = elmid[ipar][3];
144 unsigned int D1Xp = elmid[ipar][4];
145 unsigned int D1V = elmid[ipar][5];
146 unsigned int D1Vp = elmid[ipar][6];
148 unsigned int D1V = elmid[ipar][7];
149 unsigned int D1Vp = elmid[ipar][8];
150 unsigned int D1X = elmid[ipar][9];
151 unsigned int D1Xp = elmid[ipar][10];
152 unsigned int D1U = elmid[ipar][11];
153 unsigned int D1Up = elmid[ipar][12];
155 unsigned int D2V = elmid[ipar][13];
156 unsigned int D2Vp = elmid[ipar][14];
157 unsigned int D2Xp = elmid[ipar][15];
158 unsigned int D2X = elmid[ipar][16];
159 unsigned int D2U = elmid[ipar][17];
160 unsigned int D2Up = elmid[ipar][18];
162 unsigned int D3pVp = elmid[ipar][19];
163 unsigned int D3pV = elmid[ipar][20];
164 unsigned int D3pXp = elmid[ipar][21];
165 unsigned int D3pX = elmid[ipar][22];
166 unsigned int D3pUp = elmid[ipar][23];
167 unsigned int D3pU = elmid[ipar][24];
169 unsigned int D3mVp = elmid[ipar][25];
170 unsigned int D3mV = elmid[ipar][26];
171 unsigned int D3mXp = elmid[ipar][27];
172 unsigned int D3mX = elmid[ipar][28];
173 unsigned int D3mUp = elmid[ipar][29];
174 unsigned int D3mU = elmid[ipar][30];
178 auto size_1 = db.
St1.size();
179 auto size_2 = db.
St2.size();
180 auto size_3 = db.
St3.size();
181 auto size_23 = db.
St23.size();
182 auto size_123 = db.
St123.size();
212 if(db.
St1.size()>size_1) ++nacc_1;
213 if(db.
St2.size()>size_2) ++nacc_2;
214 if(db.
St3.size()>size_3) ++nacc_3;
215 if(db.
St23.size()>size_23) ++nacc_23;
216 if(db.
St123.size()>size_123) ++nacc_123;
218 if(ntrack>0 and ntrack%interval==0) {
219 acc_prob_1 = 1.*nacc_1/interval;
220 acc_prob_2 = 1.*nacc_2/interval;
221 acc_prob_3 = 1.*nacc_3/interval;
222 acc_prob_23 = 1.*nacc_23/interval;
223 acc_prob_123 = 1.*nacc_123/interval;
246 LogInfo(
"PatternDBUtil::BuildPatternDB from " << fin);
279 TFile *f_out = TFile::Open(fout.c_str(),
"recreate");
281 TTree *T_out_St1 =
new TTree(
"St1",
"St1");
283 T_out_St1->Branch(
"key",&b_St1);
284 for(
auto key : db.
St1) {
289 TTree *T_out_St2 =
new TTree(
"St2",
"St2");
291 T_out_St2->Branch(
"key",&b_St2);
292 for(
auto key : db.
St2) {
297 TTree *T_out_St3 =
new TTree(
"St3",
"St3");
299 T_out_St3->Branch(
"key",&b_St3);
300 for(
auto key : db.
St3) {
305 TTree *T_out_St23 =
new TTree(
"St23",
"St23");
307 T_out_St23->Branch(
"key",&b_St23);
308 for(
auto key : db.
St23) {
313 TTree *T_out_St123 =
new TTree(
"St123",
"St123");
315 T_out_St123->Branch(
"key",&b_St123);
316 for(
auto key : db.
St123) {
326 T_out_St123->Write();
339 LogInfo(
"PatternDBUtil::BuildPatternDB from " << fin);
342 TFile *f_in = TFile::Open(fin.c_str(),
"read");
350 TTree *St1 = (TTree*) f_in->Get(
"St1");
353 St1->SetBranchAddress(
"key", &key);
354 for(
int ientry=0;ientry<St1->GetEntries();++ientry) {
355 St1->GetEntry(ientry);
356 db->
St1.insert(db->
St1.end(), *key);
361 TTree *St2 = (TTree*) f_in->Get(
"St2");
364 St2->SetBranchAddress(
"key", &key);
365 for(
int ientry=0;ientry<St2->GetEntries();++ientry) {
366 St2->GetEntry(ientry);
367 db->
St2.insert(db->
St2.end(), *key);
372 TTree *St3 = (TTree*) f_in->Get(
"St3");
375 St3->SetBranchAddress(
"key", &key);
376 for(
int ientry=0;ientry<St3->GetEntries();++ientry) {
377 St3->GetEntry(ientry);
378 db->
St3.insert(db->
St3.end(), *key);
383 TTree *St23 = (TTree*) f_in->Get(
"St23");
386 St23->SetBranchAddress(
"key", &key);
387 for(
int ientry=0;ientry<St23->GetEntries();++ientry) {
388 St23->GetEntry(ientry);
394 TTree *St123 = (TTree*) f_in->Get(
"St123");
397 St123->SetBranchAddress(
"key", &key);
398 for(
int ientry=0;ientry<St123->GetEntries();++ientry) {
399 St123->GetEntry(ientry);
406 LogInfo(
"PatternDBUtil::LoadPatternDB from " << fin);
408 else LogInfo(
"PatternDB NOT found!!");
416 const unsigned int X,
const unsigned int Xp,
417 const unsigned int U,
const unsigned int Up,
418 const unsigned int V,
const unsigned int Vp) {
423 X > 255 or Xp > 255 or
424 U > 255 or Up > 255 or
440 if(x == 0 and u == 0 and v == 0) {
445 return TrackletKey(ST, x/_RESOLUTION1_, u/_RESOLUTION1_, v/_RESOLUTION1_);
447 return TrackletKey(ST, x/_RESOLUTION2_, u/_RESOLUTION2_, v/_RESOLUTION2_);
449 return TrackletKey(ST, x/_RESOLUTION3_, u/_RESOLUTION3_, v/_RESOLUTION3_);
458 std::vector<unsigned int> elmids;
461 for (
auto ptr_hit = tracklet.
hits.begin();
462 ptr_hit != tracklet.
hits.end(); ++ptr_hit) {
463 auto hit = &ptr_hit->hit;
464 if (hit->index < 0)
continue;
465 unsigned int det_id = hit->detectorID;
466 if(station==
PatternDB::DC1 and !(det_id>=1 and det_id<=12))
continue;
467 if(station==
PatternDB::DC2 and !(det_id>=13 and det_id<=18))
continue;
468 if(station==
PatternDB::DC3p and !(det_id>=19 and det_id<=24))
continue;
469 if(station==
PatternDB::DC3m and !(det_id>=25 and det_id<=30))
continue;
471 elmids[_detid_view[det_id]] = hit->elementID;
486 const std::vector< std::pair<unsigned int, unsigned int> >& det_elem_pairs,
490 std::vector<unsigned int> elmids;
493 for (
auto pair : det_elem_pairs) {
494 unsigned int det_id = pair.first;
495 if(station==
PatternDB::DC1 and !(det_id>=1 and det_id<=12))
continue;
496 if(station==
PatternDB::DC2 and !(det_id>=13 and det_id<=18))
continue;
497 if(station==
PatternDB::DC3p and !(det_id>=19 and det_id<=24))
continue;
498 if(station==
PatternDB::DC3m and !(det_id>=25 and det_id<=30))
continue;
500 elmids[_detid_view[det_id]] = pair.second;
static TrackletKey EncodeTrackletKey(PatternDB::STATION, const unsigned int X, const unsigned int Xp, const unsigned int U, const unsigned int Up, const unsigned int V, const unsigned int Vp)
static int BuildPatternDB(const std::string &fin, const std::string &fout, PatternDB &db)
static PatternDB * LoadPatternDB(const std::string &fin)
static TrackletKey GetTrackletKey(const Tracklet tracklet, const PatternDB::STATION station)
PatternDB interface objects.
std::set< TrackletKey > St2
static const TrackletKey ERR_KEY
std::set< GlobTrackKey > St123
std::set< PartTrackKey > St23
std::set< TrackletKey > St1
std::set< TrackletKey > St3
std::list< SignedHit > hits