//STL and C includes #include #include #include //ROOT headers #include #include #include #include #include #include #include #include #include //TestChamber includes #include "TCcluster.h" #include "TCalign.h" #include "TCtrack.h" #include "TCevent.h" #include "ConfigFile.h" #include "TCfast2Dhough.h" static bool controlC=false; static int controlCs=0; using std::cout; using std::endl; void signalHandler2(int signal) { if (signal==SIGINT) { cout<<"CTRL + C pressed saving and exiting, press again to abort"<abort" << std::endl; throw; } int main(int argc,char **argv){ using namespace std; signal(SIGINT, signalHandler2); if(!(argc==2)){ cerr<<"Wrong number of arguments, "<SetStyle("Plain"); //reading configFile TCanvas * c=NULL; string infilePath; string outFilePath; string alignmentFilePath; string histFilePath; string mode; ConfigFile cf( argv[1] ); bool hough = true; bool maxAmp=false; bool disp=false; int houghThreshold; int houghDepth; bool debug =false; if(!(cf.readInto(infilePath , "inFile") )) failedConf("infile"); if(!(cf.readInto(outFilePath , "outFile") )) failedConf("alignmentFile"); if(!(cf.readInto(alignmentFilePath , "alignmentFile") )) failedConf("alignmentFile"); if(!(cf.readInto(histFilePath , "histFile") )) failedConf("histFile"); if(!(cf.readInto(mode , "mode") )) failedConf("mode"); if(mode=="hough"){ hough=true; maxAmp=false; disp=false; if(!(cf.readInto(houghThreshold , "houghThreshold") )) failedConf("houghThreshold"); if(!(cf.readInto(houghDepth , "houghDepth") )) failedConf("houghDepth"); }else if(mode=="maxAmp"){ hough=false; maxAmp=true; disp=false; houghDepth=0; houghThreshold=0; }else if(mode=="eventDisp"){ hough=true; maxAmp=false; disp=true; if(!(cf.readInto(houghThreshold , "houghThreshold") )) failedConf("houghThreshold"); if(!(cf.readInto(houghDepth , "houghDepth") )) failedConf("houghDepth"); }else{ std::cerr << "Unknown mode " << mode << " from conf file ->abort" << std::endl; throw; } if(!(cf.readInto(debug , "debug") )) debug=false; TFile::Open(infilePath.c_str()); TTree *inTree = (TTree*)gROOT->FindObject("at_cl"); TCevent *inEvent = new TCevent(); TCevent *outEvent = new TCevent(); TBranch *branchEvent=inTree->GetBranch("event"); branchEvent->SetAddress(&inEvent); int nEvents=inTree->GetEntries(); /* outTree wil contain events with clusters, and track candidates. */ TFile* outFile = new TFile(outFilePath.c_str(),"RECREATE"); TTree* eventTreeOut = new TTree("at_pr","testBench analysis tree"); eventTreeOut->Branch("event","TCevent",&outEvent,32000,99); int totClusters=0; TVector3 x(1,0,0); TVector3 y(0,1,0); TVector3 z(0,0,1); TCfast2DHough* houghXZ = new TCfast2DHough(-x,z,true); TCfast2DHough* houghYZ = new TCfast2DHough(y,z,true); cout<<"thresholds "<setThreshold(houghThreshold); houghXZ->setDepth(houghDepth); houghYZ->setThreshold(houghThreshold); houghYZ->setDepth(houghDepth); TCalign* a = TCalign::getInstance(alignmentFilePath); a->clear(); a->read(alignmentFilePath); int nTracks2=0; for(int i_ev=0;i_evGetEntry(i_ev); if(controlC){ cout<<"jumping out of for loop"<getEventNumber()<<" n clusters "<clear(); // cout<getEventNumber()<setEventNumber(inEvent->getEventNumber()); TGraph* x_event =new TGraph(); TGraph* y_event =new TGraph(); TGraph* x_SelEvent =new TGraph(); TGraph* y_SelEvent =new TGraph(); vector y_clusters; vector x_clusters; int x_count=0; int y_count=0; //cout<<"nr cluster"<nClusters()< outClusters; vector outTracks; if(disp){ // cout<<"nclusters "<nClusters()<<" tracks "<nClusters();++iCl) { TCcluster cl=inEvent->getCluster(iCl); outClusters.push_back(cl); int detID=cl.getId(); if(detID%2==0){ y_clusters.push_back(cl); y_event->SetPoint(y_count, cl.posXYZ().z(), cl.posXYZ().y()); y_count++; // if(disp) // cout<<"z "<SetPoint(x_count, cl.posXYZ().z(), cl.posXYZ().x()); x_count++; // if(disp) // cout<<"z "<maxAmpGM1x){ maxAmpGM1x=cl.getAmp(); maxPosGM1x=iCl; } break; case 2: if(cl.getAmp()>maxAmpGM1y){ maxAmpGM1y=cl.getAmp(); maxPosGM1y=iCl; } break; case 3: if(cl.getAmp()>maxAmpSI1x){ maxAmpSI1x=cl.getAmp(); maxPosSI1x=iCl; } break; case 4: if(cl.getAmp()>maxAmpSI1y){ maxAmpSI1y=cl.getAmp(); maxPosSI1y=iCl; } break; case 5: if(cl.getAmp()>maxAmpSI2x){ maxAmpSI2x=cl.getAmp(); maxPosSI2x=iCl; } break; case 6: if(cl.getAmp()>maxAmpSI2y){ maxAmpSI2y=cl.getAmp(); maxPosSI2y=iCl; } break; case 7: if(cl.getAmp()>maxAmpGM2x){ maxAmpGM2x=cl.getAmp(); maxPosGM2x=iCl; } break; case 8: if(cl.getAmp()>maxAmpGM2y){ maxAmpGM2y=cl.getAmp(); maxPosGM2y=iCl; } break; default: break; } } } if(maxAmp){ int xmax=0; int ymax=0; vector clTrack; if(maxPosGM1x>-1){ inEvent->getCluster(maxPosGM1x).setFit(); clTrack.push_back(inEvent->getCluster(maxPosGM1x)); ++totClusters; ++xmax; } if(maxPosGM1y>-1){ inEvent->getCluster(maxPosGM1y).setFit(); clTrack.push_back(inEvent->getCluster(maxPosGM1y)); ++totClusters; ++ymax; } if(maxPosSI1x>-1){ inEvent->getCluster(maxPosSI1x).setFit(); clTrack.push_back(inEvent->getCluster(maxPosSI1x)); ++totClusters; ++xmax; } if(maxPosSI1y>-1){ inEvent->getCluster(maxPosSI1y).setFit(); clTrack.push_back(inEvent->getCluster(maxPosSI1y)); ++totClusters; ++ymax; } if(maxPosSI2x>-1){ inEvent->getCluster(maxPosSI2x).setFit(); clTrack.push_back(inEvent->getCluster(maxPosSI2x)); ++totClusters; ++xmax; } if(maxPosSI2y>-1){ inEvent->getCluster(maxPosSI2y).setFit(); clTrack.push_back(inEvent->getCluster(maxPosSI2y)); ++totClusters; ++ymax; } if(maxPosGM2x>-1){ inEvent->getCluster(maxPosGM2x).setFit(); clTrack.push_back(inEvent->getCluster(maxPosGM2x)); ++totClusters; ++xmax; } if(maxPosGM2y>-1){ inEvent->getCluster(maxPosGM2y).setFit(); clTrack.push_back(inEvent->getCluster(maxPosGM2y)); ++totClusters; ++ymax; } if(xmax>3&&ymax>3){ outTracks.push_back(new TCtrack()); for(unsigned int i=0;iaddClusters(clTrack); //cout<nClFit()<1&&y_clusters.size()>1){ if(disp){ // cout<<"hough"<clear(); houghYZ->clear(); */ vector clTrack; if(disp||debug){ houghXZ->setDebug(true); houghYZ->setDebug(true); }else{ houghXZ->setDebug(false); houghYZ->setDebug(false); } if(disp||debug){ // cout<make(x_clusters); if(disp||debug){ // cout<make(y_clusters); int yDet=0; int xDet=0; int n1 =0; int n2 =0; int n3 =0; int n4 =0; int n5 =0; int n6 =0; int n7 =0; int n8 =0; if(disp){ // cout<<"before hough selection"<getNmax()>0&&houghYZ->getNmax()>0&&houghXZ->getMaxVote()>2&&houghYZ->getMaxVote()>2){ int x_n=0; int y_n=0; for(unsigned int i=0;ihot(i)){ double ztmp=0; double xtmp=0; x_clusters.at(i).setFit(); x_SelEvent->SetPoint(x_n, x_clusters.at(i).posXYZ().z(), x_clusters.at(i).posXYZ().x()); if(disp){ x_SelEvent->GetPoint(x_n, ztmp, xtmp); // cout<hot(i)){ double ztmp=0; double ytmp=0; y_clusters.at(i).setFit(); y_SelEvent->SetPoint(y_n, y_clusters.at(i).posXYZ().z(), y_clusters.at(i).posXYZ().y()); if(disp){ y_SelEvent->GetPoint(y_n, ztmp, ytmp); // cout<GetN()<GetN()<addClusters(clTrack); bool a1 =false; bool a2 =false; bool a3 =false; bool a4 =false; bool a5 =false; bool a6 =false; bool a7 =false; bool a8 =false; //cout<nCl();j++){ int id = outTracks.back()->getCl(j).getId(); if(!outTracks.back()->getCl(j).getFit()){ continue; } if(!a1&&id==1){ xDet++; //cout<<" a1 "; a1=true; } if(!a2&&id==2){ yDet++; a2=true; //cout<<" a2 "; } if(!a3&&id==3){ xDet++; a3=true; //cout<<" a3 "; } if(!a4&&id==4){ yDet++; a4=true; //cout<<" a4 "; } if(!a5&&id==5){ xDet++; a5=true; //cout<<" a5 "; } if(!a6&&id==6){ yDet++; a6=true; //cout<<" a6 "; } if(!a7&&id==7){ xDet++; a7=true; //cout<<" a7 "; } if(!a8&&id==8){ yDet++; a8=true; //cout<<" a8 "; } if(id==1){ n1++; } if(id==2){ n2++; } if(id==3){ n3++; } if(id==4){ n4++; } if(id==5){ n5++; } if(id==6){ n6++; } if(id==7){ n7++; } if(id==8){ n8++; } } //cout<1||n2>1||n3>1||n4>1||n5>1||n6>1||n7>1||n8>1){ //cout<<"outTrack deleted"<GetN()<GetN()<draw(false ); houghYZ->draw(false,800); if(c!=NULL){ delete c; } c = new TCanvas("Event display","Event Display",1280,1,960,480); x_event->SetMarkerSize(2); y_event->SetMarkerSize(2); c->Divide(2,1); (c->cd(1))->Clear(); if(x_SelEvent->GetN()>0){ x_SelEvent->SetMarkerColor(3); x_SelEvent->SetMarkerSize(1); // cout<<"drawing selected x clusters "<GetN()<Draw("AP*"); x_SelEvent->Draw("*SAME"); for(int bla=0;blaGetN();++bla){ double ztmp=0; double xtmp=0; x_SelEvent->GetPoint(bla, ztmp, xtmp); // cout<Draw("AP*"); } (c->cd(2))->Clear(); if(y_SelEvent->GetN()>0){ y_SelEvent->SetMarkerColor(3); y_SelEvent->SetMarkerSize(1); y_event->Draw("AP*"); y_SelEvent->Draw("*SAME"); // cout<<"drawing selected y clusters "<GetN()<GetN();++bla){ double ztmp=0; double ytmp=0; y_SelEvent->GetPoint(bla, ztmp, ytmp); //cout<Draw("AP*"); } x_event->GetXaxis()->SetTitle("z (cm)"); x_event->GetYaxis()->SetTitle("x (cm)"); y_event->GetXaxis()->SetTitle("z (cm)"); y_event->GetYaxis()->SetTitle("y (cm)"); gApplication->SetReturnFromRun(kTRUE); gSystem->Run(); gROOT->Reset(); } for(unsigned int i = 0; iaddTrack(outTracks.at(i)); nTracks2++; } if(outTracks.size()>0&&!disp){ if(maxAmp){ outEvent->addClusters(outClusters); eventTreeOut->Fill(); }else{ outEvent->addClusters(outClusters); eventTreeOut->Fill(); } } delete x_event; delete y_event; delete x_SelEvent; delete y_SelEvent; }//end event loop if(!disp){ eventTreeOut->Write(); } outFile->Close(); }