6 #include <TSQLServer.h>
7 #include <TSQLResult.h>
32 std::vector<int> H2X_trigger = p_geomSvc->
getDetectorIDs(
"H2[TB]");
33 std::vector<int> H3X_trigger = p_geomSvc->
getDetectorIDs(
"H3[TB]");
34 std::vector<int> H4X_trigger = p_geomSvc->
getDetectorIDs(
"H4[TB]");
36 detectorIDs_trigger.insert(detectorIDs_trigger.end(), H2X_trigger.begin(), H2X_trigger.end());
37 detectorIDs_trigger.insert(detectorIDs_trigger.end(), H3X_trigger.begin(), H3X_trigger.end());
38 detectorIDs_trigger.insert(detectorIDs_trigger.end(), H4X_trigger.begin(), H4X_trigger.end());
56 int H1TID = p_geomSvc->getDetectorID(
"H1T");
57 int H2TID = p_geomSvc->getDetectorID(
"H2T");
58 int H3TID = p_geomSvc->getDetectorID(
"H3T");
59 int H4TID = p_geomSvc->getDetectorID(
"H4T");
60 int H1BID = p_geomSvc->getDetectorID(
"H1B");
61 int H2BID = p_geomSvc->getDetectorID(
"H2B");
62 int H3BID = p_geomSvc->getDetectorID(
"H3B");
63 int H4BID = p_geomSvc->getDetectorID(
"H4B");
65 std::string roadsPT = rc->
get_CharFlag(
"TRIGGER_REPO") +
"/firmware/roads/L1/" + rc->
get_CharFlag(
"TRIGGER_L1") +
"/roads_plus_top.txt";
66 std::string roadsPB = rc->
get_CharFlag(
"TRIGGER_REPO") +
"/firmware/roads/L1/" + rc->
get_CharFlag(
"TRIGGER_L1") +
"/roads_plus_bottom.txt";
67 std::string roadsMT = rc->
get_CharFlag(
"TRIGGER_REPO") +
"/firmware/roads/L1/" + rc->
get_CharFlag(
"TRIGGER_L1") +
"/roads_minus_top.txt";
68 std::string roadsMB = rc->
get_CharFlag(
"TRIGGER_REPO") +
"/firmware/roads/L1/" + rc->
get_CharFlag(
"TRIGGER_L1") +
"/roads_minus_bottom.txt";
70 std::string fileNames[4] = {roadsPT, roadsPB, roadsMT, roadsMB};
74 for(
int i = 0; i < 4; ++i)
76 fstream fin(fileNames[i].c_str(), ios::in);
78 while(fin.getline(buffer, 300))
80 istringstream stringBuf(buffer);
86 stringBuf >> roadID >> elementIDs[0] >> elementIDs[1] >> elementIDs[2] >> elementIDs[3] >> charge >> groupID;
109 road_new.
roadID = pRoads++;
110 roads_enabled[0].insert(map<int, TriggerRoad>::value_type(road_new.
getRoadID(), road_new));
114 road_new.
roadID = mRoads++;
115 roads_enabled[1].insert(map<int, TriggerRoad>::value_type(road_new.
getRoadID(), road_new));
121 std::cout <<
"TriggerAnalyzer: " << roads_enabled[0].size() <<
" positive roads and " << roads_enabled[1].size() <<
" negative roads are activated." << std::endl;
122 return roads_enabled[0].size() > 0 && roads_enabled[1].size();
130 TFile dataFile(fileName.c_str(),
"READ");
131 TTree* p_dataTree = (TTree*)dataFile.Get(
"single_p");
132 TTree* m_dataTree = (TTree*)dataFile.Get(
"single_m");
134 p_dataTree->SetBranchAddress(
"road", &road);
135 m_dataTree->SetBranchAddress(
"road", &road);
138 for(
int i = 0; i < p_dataTree->GetEntries(); i++)
140 p_dataTree->GetEntry(i);
141 if(road->
isValid()) roads[0].insert(std::map<int, TriggerRoad>::value_type(road->
getRoadID(), *road));
146 for(
int i = 0; i < m_dataTree->GetEntries(); i++)
148 m_dataTree->GetEntry(i);
149 if(road->
isValid()) roads[1].insert(std::map<int, TriggerRoad>::value_type(road->
getRoadID(), *road));
203 for(
int i = 1; i <= 7; i++)
205 for(
int j = 1; j <= 7; j++)
211 triggers.push_back(std::make_pair(i, j));
214 triggers.push_back(std::make_pair(-i, j));
215 triggers.push_back(std::make_pair(i, -j));
224 bool pRoadFound = roads_enabled[0].find(p_road.
getRoadID()) != roads_enabled[0].end();
225 bool mRoadFound = roads_enabled[1].find(m_road.
getRoadID()) != roads_enabled[1].end();
227 return pRoadFound && mRoadFound;
236 std::set<int> vertex;
240 for(
int i = 0; i < nHits; i++)
243 int uniqueID = detectorIDs[i]*100 + elementIDs[i];
244 if(detectorName.find(
"H1T") != std::string::npos || detectorName.find(
"H1B") != std::string::npos)
246 HX[0].insert(uniqueID);
248 else if(detectorName.find(
"H2T") != std::string::npos || detectorName.find(
"H2B") != std::string::npos)
250 HX[1].insert(uniqueID);
252 else if(detectorName.find(
"H3T") != std::string::npos || detectorName.find(
"H3B") != std::string::npos)
254 HX[2].insert(uniqueID);
256 else if(detectorName.find(
"H4T") != std::string::npos || detectorName.find(
"H4B") != std::string::npos)
258 HX[3].insert(uniqueID);
262 for(
int i = 0; i < 4; i++)
264 if(HX[i].empty())
return false;
267 data.push_back(vertex);
268 data.push_back(HX[0]);
269 data.push_back(HX[1]);
270 data.push_back(HX[2]);
271 data.push_back(HX[3]);
279 int detectorIDs[10000];
280 int elementIDs[10000];
284 for(std::vector<Hit>::iterator iter = rawEvent->
getAllHits().begin(); iter != rawEvent->
getAllHits().end(); ++iter)
287 if(!iter->isInTime())
continue;
289 detectorIDs[nHits] = iter->detectorID;
290 elementIDs[nHits] = iter->elementID;
300 if(!iter->isInTime())
continue;
302 detectorIDs[nHits] = iter->detectorID;
303 elementIDs[nHits] = iter->elementID;
309 return acceptEvent(nHits, detectorIDs, elementIDs);
315 roads_found[0].clear();
316 roads_found[1].clear();
323 if(!
buildData(nHits, detectorIDs, elementIDs))
return false;
326 for(
int i = 0; i < 2; i++)
329 search(root[i], data, 0, i);
333 std::set<int> groupIDs[2];
334 for(
int i = 0; i < 2; i++)
336 for(std::list<TriggerRoad>::iterator iter = roads_found[i].begin(); iter != roads_found[i].end(); )
338 if(roads_enabled[i].find(iter->getRoadID()) == roads_enabled[i].end())
340 iter = roads_found[i].erase(iter);
345 *iter = roads_enabled[i][iter->getRoadID()];
346 iter->groupID > 0 ? ++nRoads[i][0] : ++nRoads[i][1];
350 groupIDs[i].insert(abs(iter->groupID));
353 groupIDs[i].insert(iter->groupID);
359 if(groupIDs[0].empty() || groupIDs[1].empty())
return false;
362 for(std::set<int>::iterator p_groupID = groupIDs[0].begin(); p_groupID != groupIDs[0].end(); ++p_groupID)
364 for(std::set<int>::iterator m_groupID = groupIDs[1].begin(); m_groupID != groupIDs[1].end(); ++m_groupID)
366 std::list<Trigger>::iterator trigger = std::find(triggers.begin(), triggers.end(), std::make_pair(*p_groupID, *m_groupID));
367 if(trigger != triggers.end())
return true;
376 roads_temp.push_back(root->
uniqueID);
381 if(roads_enabled[charge].find(road_found.
getRoadID()) != roads_enabled[charge].end()) roads_found[charge].push_back(road_found);
382 roads_temp.pop_back();
387 for(std::list<SQTNode*>::iterator iter = root->
children.begin(); iter != root->
children.end(); ++iter)
389 if(data[level+1].find((*iter)->uniqueID) == data[level+1].end())
continue;
390 search(*iter, data, level+1, charge);
392 roads_temp.pop_back();
397 if(root ==
nullptr)
return;
399 roads_temp.push_back(root->
uniqueID);
403 roads_temp.pop_back();
408 for(std::list<SQTNode*>::iterator iter = root->
children.begin(); iter != root->
children.end(); ++iter)
412 roads_temp.pop_back();
417 if(root ==
nullptr)
return;
424 for(std::list<SQTNode*>::iterator iter = root->
children.begin(); iter != root->
children.end(); ++iter)
433 for(
int i = 0; i < 2; i++)
436 for(std::map<int, TriggerRoad>::iterator iter = roads_enabled[i].begin(); iter != roads_enabled[i].end(); ++iter)
438 if(!iter->second.isEnabled())
continue;
441 parentNode[0] = root[i];
442 for(
int j = 0; j < 4; j++)
444 int uniqueID = iter->second.getDetectorID(j)*100 + iter->second.getElementID(j);
445 bool isNewNode =
true;
446 for(std::list<SQTNode*>::iterator jter = parentNode[j]->children.begin(); jter != parentNode[j]->
children.end(); ++jter)
448 if(uniqueID == (*jter)->uniqueID)
450 parentNode[j+1] = *jter;
460 parentNode[j]->
add(node_new);
462 parentNode[j+1] = node_new;
471 std::cout <<
"Found one road: " << std::endl;
472 for(std::list<int>::iterator iter = roads_temp.begin(); iter != roads_temp.end(); ++iter)
474 std::cout << *iter <<
" --> ";
476 std::cout << std::endl;
481 for(
unsigned int i = 0; i < data.size(); i++)
483 std::cout << i <<
": ";
484 for(std::set<int>::iterator iter = data[i].begin(); iter != data[i].end(); ++iter)
486 std::cout << *iter <<
" ";
488 std::cout << std::endl;
497 fstream fout_road[2][2];
498 fout_road[0][0].open(
"roads_plus_top.txt", ios::out);
499 fout_road[0][1].open(
"roads_plus_bottom.txt", ios::out);
500 fout_road[1][0].open(
"roads_minus_top.txt", ios::out);
501 fout_road[1][1].open(
"roads_minus_bottom.txt", ios::out);
505 for(
int i = 0; i < 2; i++)
507 for(std::map<int, TriggerRoad>::iterator iter = roads_enabled[i].begin(); iter != roads_enabled[i].end(); ++iter)
509 if(!iter->second.isEnabled())
continue;
511 int tb = iter->second.getTB() > 0 ? 0 : 1;
512 fout_road[i][tb] << iter->second << endl;
516 fout_road[0][0].close();
517 fout_road[0][1].close();
518 fout_road[1][0].close();
519 fout_road[1][1].close();
523 fout_pair.open(
"road_pairs.txt", ios::out);
525 for(std::list<Trigger>::iterator iter = triggers.begin(); iter != triggers.end(); ++iter)
527 fout_pair << iter->first <<
" " << iter->second << endl;
539 for(
int i = 0; i < 2; ++i)
541 for(std::list<TriggerRoad>::iterator iter = roads_found[i].begin(); iter != roads_found[i].end(); ++iter)
543 for(
int j = 0; j < 4; ++j)
546 h.
index = 10000 + hitlist.size();
555 hitlist.push_back(h);
std::vector< std::set< int > > DataMatrix
static GeomSvc * instance()
singlton instance
void getMeasurement(int detectorID, int elementID, double &measurement, double &dmeasurement)
Convert the detectorID and elementID to the actual hit position.
std::string getDetectorName(const int &detectorID) const
std::vector< int > getDetectorIDs(std::string pattern)
Definition of hit structure.
void setTriggerMask(bool f=true)
void setInTime(bool f=true)
virtual const std::string get_CharFlag(const std::string &flag) const
std::list< SQTNode * > children
std::vector< Hit > & getTriggerHits()
void setTriggerEmu(bool flag)
void setNRoads(Short_t nRoads[])
std::vector< Hit > & getAllHits()
void search(SQTNode *root, DataMatrix &data, int level, int charge)
bool buildData(int nHits, int detectorIDs[], int elementIDs[])
void printData(DataMatrix &data)
void printTree(SQTNode *root)
void trimEvent(SRawEvent *rawEvent, std::list< Hit > &hitlist, bool USE_TRIGGER_HIT, bool USE_HIT)
void clearTree(SQTNode *root)
bool acceptEvent(TriggerRoad &p_road, TriggerRoad &m_road)
void addElement(int detectorID, int elementID)
static recoConsts * instance()