int bag(vector< vector< map<int,float> > > & tests, vector<float> & weight){ vector< map<int,float> > aa(USER_NUM); for(int k = 0; k < tests.size(); ++k){ for(int u = 0; u < tests[k].size(); ++u){ if(tests[k][u].empty()) continue; for(map<int,float>::iterator j = tests[k][u].begin(); j != tests[k][u].end(); ++j){ int item = j->first; if(aa[u].find(item) == aa[u].end()) aa[u][item] = 0; aa[u][item] += (float)(j->second) * weight[k]; } } } ofstream out("result-train.txt"); for(int i = 0; i < aa.size(); ++i){ if(aa[i].empty()) continue; vector< pair<int,float> > reco(aa[i].begin(), aa[i].end()); sort(reco.begin(), reco.end(), GreaterSecond<int,float>); //if(reco.size() > 20) reco.erase(reco.begin() + 20, reco.end()); //postProcessByLanguage(i, reco); out << i << ":" << reco[0].first; for(int k = 1; k < reco.size() && k < 20; ++k) out << "," << reco[k].first; out << endl; } out.close(); return score(aa); }
Int_t writeReco(Int_t event1=0, Int_t event2=-1 , TTree* tree=0 , const char* dbname="rundb-May2015.dat" , const char* tv_calib_fname="TVcalib.txt" , const char* wet_calib_fname="wet5calibExp.txt" , OutputFiles* outputFiles=0 , bool debug=false ) { bool do_wepl = true; if (!tv_calib_fname || !tv_calib_fname[0]) do_wepl = false; if (!wet_calib_fname || !wet_calib_fname[0]) do_wepl = false; if (!do_wepl) { cout<< "There are no TV-correction and/or WET calibration file provided. Nothing to do" <<endl; return 0; } if (!tree) tree = (TTree*) gDirectory->Get("t"); // DataFormat tree if (!tree) { cout<< "Could not find tree t" <<endl; return 0; } const PCTEvent* pCTEvent = 0; tree->SetBranchAddress("event", &pCTEvent); RecoEvent* recoEvent = new RecoEvent(); RunHeader* runHeader = new RunHeader(*((RunHeader*) tree->GetUserInfo()->First())); // use copy constructor cout<< "runHeader->GetRun() = " << runHeader->GetRun() <<endl; time_t start_time = runHeader->GetTime(); cout<< "run start time: " << std::ctime(&start_time); cout<< "program version is " << runHeader->GetVersion() <<endl; if (runHeader->GetTimeTag()) cout<< "event time tag was written out" <<endl; else cout<< "event time tag was not written out" <<endl; cout<< "runHeader->GetAngle() = " << runHeader->GetAngle() <<endl; cout<<endl; // // read the database // Geometry* geometry = new Geometry(runHeader->GetRun(), dbname); // // use geometry to fill up outputFiles data and to get u-positions of the layers // outputFiles->run = runHeader->GetRun(); //--from-rundb-- outputFiles->angle = geometry->angle_; outputFiles->angle = runHeader->GetAngle(); // take angle from the RunHeader instead of rundb // // open temporary output files. The angle will be embedded into the file name // outputFiles->open(); Double_t uv[4]; Double_t ut[4]; for (int ilayer=0; ilayer<4; ++ilayer) { uv[ilayer] = geometry->uv_[ilayer]; ut[ilayer] = geometry->ut_[ilayer]; if (debug) cout<< "uv[" << ilayer << "] = " << uv[ilayer] << " ut[" << ilayer << "] = " << ut[ilayer] <<endl; } PCTSensors* pCTSensors = new PCTSensors(geometry); //-- Geant4 setup //-- Double_t RbeamSpot = 10.; // Geant4 //-- BeamSpot beamSpotIn(0,0,-3500, RbeamSpot); // Geant4 //-- BeamSpot beamSpotOut(0,0,-3500, RbeamSpot); // Geant4 // Double_t RbeamSpot = 0.5*(14.16 + 17.08); // Sep2014 beam test // BeamSpot beamSpotIn(35.52,-1.07,-3500, RbeamSpot); // Sep2014 beam test // BeamSpot beamSpotOut(13.76,-6.96,-3500, 140.); // Sep2014 beam test Double_t RbeamSpot = 10.; // May2015 beam test BeamSpot beamSpotIn(-10.5,9.7,-2100, RbeamSpot); // May2015 beam test BeamSpot beamSpotOut(-5.0,13.0,-2100, RbeamSpot); // May2015 beam test // // WEPL reconstruction // // ADC Pedestals // Double_t ped[5] = {9.645, -20.484, -201.987, 62.966, -7.747}; // Celeste data // Jul2014-- Double_t ped[5] = {121.3, -71.5, -1137, 346.2, -49.}; // New pedestals (x6, reduced data) // Double_t ped[5] = {431,-130,-20,224,60}; // Sept. 2014 pedestals (x6, reduced data) Double_t ped[5] = {549,92,204,575,385}; // New pedestals, May 2015 (x6, reduced data) // Prepare stuff for TV correction and convertion ADC->energy(MeV) Double_t ucal = 216.9 + 40; // approx position for the calorimeter entrance Float_t par[5]; Float_t adc; Float_t Estage[5]; CalF* f2cal[5]; // Calibration functions for 5 stages if (do_wepl) { // open TV-correction parameters file std::ifstream TVcalfile(tv_calib_fname); if (!TVcalfile) { cout<< "Could not open TV-correction file " << tv_calib_fname <<endl; return 0; } for (int i=0; i<5; ++i) { // read fit parameters: TVcalfile >> par[0] >> par[1] >> par[2] >> par[3] >> par[4] ; f2cal[i]=new CalF(i,par); // initialize t-v calibration function } TVcalfile.close(); } // Prepare stuff for WEPL calibration Float_t wepl_par[45]; Float_t Wet; if (do_wepl) { // open text file with WEPL calibration data (parameters of 9 pol4 curves) std::ifstream WEPLcalfile(wet_calib_fname); if (!WEPLcalfile) { cout<< "Could not find file " << wet_calib_fname <<endl; return 0; } for (int i=0; i<45; ++i) WEPLcalfile >> wepl_par[i]; WEPLcalfile.close(); } Wepl* WEPL = 0; if (do_wepl) { WEPL = new Wepl(wepl_par); // initialize WEPL calibr. WEPL->SetEthresholds(1,.99,1,1,1); // Set all stage thresholds to 1 MeV } //----------------- end of WEPL reconstruction stuff ----------------- Int_t nevents_with_tracks = 0; if (event2 < event1) event2 = tree->GetEntries()-1; cout<< "event1 = " << event1 << " event2 = " << event2 <<endl; EventOutput eventOutput; // // event loop over DataFormat tree // for (int ientry=event1; ientry<=event2; ++ientry) { if (tree->LoadTree(ientry) < 0) { cout<< "Could not load event " << ientry <<endl; break; } tree->GetEntry(ientry); if (false || (ientry < 10) || (ientry < 10000 && ientry%1000 == 0) || (ientry%100000 == 0) ) cout<< "---> processing entry " << ientry <<endl; //-- recoEvent->clear(); // probably we don't need it, the recoEvent->Extract(reco) will do the job Reco reco(geometry, pCTSensors, &beamSpotIn, &beamSpotOut, pCTEvent, ientry, debug); reco.Tracking(); if (debug) cout<< "call recoEvent->Extract(reco)" <<endl; recoEvent->Extract(reco); if (recoEvent->track->GetLast()+1 > 0) ++nevents_with_tracks; recoEvent->wepl = -2000; if (do_wepl) { // // calculate WEPL and assign to the recoEvent->wepl // if (debug) cout<< "calculate WEPL: recoEvent->track->GetLast()+1 = " << recoEvent->track->GetLast()+1 <<endl; if (recoEvent->track->GetLast()+1 > 0) { const SuperTrack* superTrack = (const SuperTrack*) recoEvent->track->At(0); // take the first reconstructed track // // angle cut // if (superTrack->angle > 0.070) continue; for (int ical=0; ical<5; ++ical) { adc = recoEvent->a[ical]; adc = adc - ped[ical]; // if (adc < 100) adc = 0; // Apply TV correction and convert ADC channel to E in MeV if (debug) cout<< "Apply TV correction and convert ADC channel to E in MeV" <<endl; Estage[ical]=f2cal[ical]->CalTVf(superTrack->T(ucal),superTrack->V(ucal),adc); } // Get Wet=WEPL from Estage if (debug) cout<< "Get Wet=WEPL from Estage" <<endl; Wet=WEPL->EtoWEPL(Estage); if (debug) cout<< "Wet = " << Wet <<endl; //-- if(Wet>999. || Wet<-999.) continue; //--new-- recoEvent->SetWEPL(Wet); if (debug) cout<< "assign Wet to recoEvent->wepl" <<endl; if(Wet>-999. && Wet<999.) recoEvent->wepl = Wet; if (debug) cout<< " done" <<endl; // // writeReco stuff // ++outputFiles->nevents; eventOutput.good = kTRUE; for (int ilayer=0; ilayer<4; ++ilayer) { eventOutput.u[ilayer] = ut[ilayer]; eventOutput.v[ilayer] = superTrack->V(ut[ilayer]); eventOutput.t[ilayer] = superTrack->T(ut[ilayer]); } eventOutput.wepl = Wet; for (int ilayer=0; ilayer<4; ilayer++) outputFiles->tfile[ilayer]->write((const char*) &eventOutput.t[ilayer], sizeof(Float_t)); for (int ilayer=0; ilayer<4; ilayer++) outputFiles->vfile[ilayer]->write((const char*) &eventOutput.v[ilayer], sizeof(Float_t)); for (int ilayer=0; ilayer<4; ilayer++) outputFiles->ufile[ilayer]->write((const char*) &eventOutput.u[ilayer], sizeof(Float_t)); outputFiles->wfile->write((const char*) &eventOutput.wepl, sizeof(Float_t)); } } } cout<< "Wrote " << outputFiles->nevents << " events into temporary files" <<endl; return outputFiles->nevents; }
static gboolean _frame_handler(GstElement *img, GstBuffer *buffer, gpointer data) { static gboolean inited = FALSE; static gboolean sended = FALSE; if (!inited) { g_timer_start(recognition_info.timer); inited = TRUE; } if (frame == NULL) frame = cvCreateImageHeader(cvSize(640, 480), IPL_DEPTH_8U, 3); switch (recognition_info.reco_state) { case NOT_START_RECOGNIZING: g_debug("[%s] not start recognizing", __func__); if (copy_buffer != NULL) gst_buffer_unref(copy_buffer); if (pure_buffer != NULL) gst_buffer_unref(pure_buffer); copy_buffer = gst_buffer_copy((buffer)); pure_buffer = gst_buffer_copy((buffer)); frame->imageData = (char*)GST_BUFFER_DATA(copy_buffer); if (recognition_info.detect_is_enabled) { detect(frame); } else { g_timer_start(recognition_info.timer); } recognition_info.source_data = (guchar*)(frame->imageData); recognition_info.length = GST_BUFFER_SIZE(copy_buffer); recognition_info.has_data = TRUE; break; case START_RECOGNIZING: g_debug("[%s] start recognizing", __func__); recognition_info.source_data = (guchar*)GST_BUFFER_DATA(pure_buffer); recognition_info.length = GST_BUFFER_SIZE(pure_buffer); GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(recognition_info.source_data, GDK_COLORSPACE_RGB, // color space FALSE, // has alpha 8, // bits per sample CAMERA_WIDTH, // width CAMERA_HEIGHT, // height 3*CAMERA_WIDTH, // row stride NULL, // destroy function NULL // destroy function data ); GError* error = NULL; gdk_pixbuf_save(pixbuf, "/tmp/deepin_user_face.png", "png", &error, NULL); if (error != NULL) { g_debug("[%s] %s", __func__, error->message); g_error_free(error); } g_object_unref(pixbuf); recognition_info.has_data = TRUE; js_post_signal("start-animation"); recognition_info.reco_state = RECOGNIZING; sended = FALSE; reco(); break; case RECOGNIZED: g_debug("[%s] recognized", __func__); if (!sended) { g_timeout_add(ANIMATION_TIME, recognized_handler, NULL); sended = TRUE; } break; case NOT_RECOGNIZED: g_debug("[%s] not recognized", __func__); if (!sended) { g_timeout_add(ANIMATION_TIME, not_recognize_handler, NULL); sended = TRUE; } break; case RECOGNIZE_FINISH: g_debug("[%s] recognizing finish", __func__); if (copy_buffer != NULL) gst_buffer_unref(copy_buffer); copy_buffer = gst_buffer_copy((buffer)); recognition_info.source_data = (guchar*)GST_BUFFER_DATA(copy_buffer); recognition_info.length = GST_BUFFER_SIZE(pure_buffer); recognition_info.has_data = TRUE; } return TRUE; }