00001
00002
00003
00004
00005
00006
00007
00009 #include "AnalysisNtuples/Module/VHS.h"
00010 #include "AnalysisNtuples/Module/VHSevent.h"
00011
00012 #include "MinosObjectMap/MomNavigator.h"
00013 #include "StandardNtuple/NtpStRecord.h"
00014 #include "CandNtupleSR/NtpSRRecord.h"
00015 #include "MCNtuple/NtpMCRecord.h"
00016 #include "TruthHelperNtuple/NtpTHRecord.h"
00017 #include "CandNtupleSR/NtpSREvent.h"
00018 #include "CandNtupleSR/NtpSRStrip.h"
00019 #include "Conventions/PlaneView.h"
00020 #include "MCNtuple/NtpMCStdHep.h"
00021 #include "MCNtuple/NtpMCTruth.h"
00022 #include "TruthHelperNtuple/NtpTHEvent.h"
00023
00024 #include "TBenchmark.h"
00025 #include "TButton.h"
00026 #include "TCanvas.h"
00027 #include "TClonesArray.h"
00028 #include "TDirectory.h"
00029 #include "TFile.h"
00030 #include "TH2D.h"
00031 #include "TList.h"
00032 #include "TMath.h"
00033 #include "TPaveStats.h"
00034 #include "TPaveText.h"
00035 #include "TSystem.h"
00036 #include "TTree.h"
00037
00038 #include "Riostream.h"
00039 #include <fstream>
00040 #include <iomanip>
00041 #include <sstream>
00042
00043
00044
00045 bool VHS::DrawEvent( int nEntry, const char* treeName,
00046 int nPlanes, int nStrips )
00047 {
00048
00049
00050 TTree* theTree = (TTree*)gROOT->FindObject(treeName);
00051
00052 if (!theTree) return false;
00053 const int kNumEntries = theTree->GetEntriesFast();
00054
00055 if ( nEntry > kNumEntries ) return false;
00056
00057 TCanvas* evtDisp = 0;
00058
00059 if ( !gROOT->FindObject("VHSEvtDisp") ) {
00060 evtDisp = new TCanvas("VHSEvtDisp","VHS Event Display",0,0,800,600);
00061 evtDisp->Divide(2,2);
00062 evtDisp->GetPad(1)->SetPad(0.00,0.5,0.33,1.0);
00063 evtDisp->GetPad(2)->SetPad(0.33,0.5,1.00,1.0);
00064 evtDisp->GetPad(3)->SetPad(0.00,0.0,0.33,0.5);
00065 evtDisp->GetPad(4)->SetPad(0.33,0.0,1.00,0.5);
00066
00067 } else {
00068 evtDisp = (TCanvas*)gROOT->FindObject("VHSEvtDisp");
00069 evtDisp->cd(1);
00070 }
00071 evtDisp->SetEditable(kTRUE);
00072
00073 std::string nextCom = (nEntry+1 < kNumEntries)?
00074 std::string("VHS::DrawEvent(") + VHS::ToString(nEntry+1) + std::string(",\"") +
00075 std::string(theTree->GetName()) + "\"," + VHS::ToString(nPlanes) + std::string(",") +
00076 VHS::ToString(nStrips) + std::string(");") :
00077 std::string("VHS::DrawEvent(") + VHS::ToString(kNumEntries-1) + std::string(",\"") +
00078 std::string(theTree->GetName()) + "\"," + VHS::ToString(nPlanes) + std::string(",") +
00079 VHS::ToString(nStrips) + std::string(");");
00080
00081 std::string prevCom = (nEntry > 0)?
00082 std::string("VHS::DrawEvent(") + VHS::ToString(nEntry-1) + std::string(",\"") +
00083 std::string(theTree->GetName()) + "\"," + VHS::ToString(nPlanes) + std::string(",") +
00084 VHS::ToString(nStrips) + std::string(");") :
00085 std::string("VHS::DrawEvent(0,\"") +
00086 std::string(theTree->GetName()) + "\"," + VHS::ToString(nPlanes) + std::string(",") +
00087 VHS::ToString(nStrips) + std::string(");");
00088
00089
00090 evtDisp->cd(3);
00091 evtDisp->GetPad(3)->GetListOfPrimitives()->Delete();
00092 evtDisp->GetPad(3)->Range(0,0,1,1);
00093
00094
00095 TButton* butNext =
00096 new TButton("Next Event",nextCom.c_str(),0.20,0.60,0.80,0.80);
00097 butNext->SetTextSize(0.3);
00098
00099
00100 TButton* butPrev =
00101 new TButton("Prev Event",prevCom.c_str(),0.20,0.40,0.80,0.60);
00102 butPrev->SetTextSize(0.3);
00103
00104
00105 TButton* butQuit = new TButton("Quit",".q",0.20,0.20,0.80,0.40);
00106 butQuit->SetTextSize(0.3);
00107
00108 butNext->Draw();
00109 butPrev->Draw();
00110 butQuit->Draw();
00111
00112
00113 VHSevent* evt = new VHSevent();
00114 theTree->SetBranchAddress("VHSevent",&evt);
00115 theTree->GetEntry(nEntry);
00116
00117
00118 TH2D* uzImage = (TH2D*)gROOT->FindObject("UZImage");
00119 TH2D* vzImage = (TH2D*)gROOT->FindObject("VZImage");
00120
00121 if ( uzImage ) { delete uzImage; uzImage = 0; }
00122 if ( vzImage ) { delete vzImage; vzImage = 0; }
00123
00124 VHS::ToTH2D( VHS::FullVec( evt->stp, evt->ind, nPlanes, nStrips ),
00125 nPlanes, nStrips, "ZImage", "Z",
00126 uzImage, vzImage);
00127
00128 evtDisp->cd(2);
00129 uzImage->SetXTitle("Plane");
00130 uzImage->SetYTitle("Strip");
00131 uzImage->SetStats(kFALSE);
00132 uzImage->Draw("COLZ");
00133
00134
00135 evtDisp->cd(4);
00136 vzImage->SetXTitle("Plane");
00137 vzImage->SetYTitle("Strip");
00138 vzImage->SetStats(kFALSE);
00139 vzImage->Draw("COLZ");
00140
00141
00142 evtDisp->cd(1);
00143 evtDisp->GetPad(1)->GetListOfPrimitives()->Delete();
00144
00145 bool MC = evt->MC;
00146 double MCenu = evt->MCenu;
00147 int MCiaction = evt->MCiaction;
00148 int MCinu = TMath::Abs(evt->MCinu);
00149
00150
00151 double dNC = evt->dNC;
00152 double dCCe = evt->dCCe;
00153 double dCCmu = evt->dCCmu;
00154 double dCCtau = evt->dCCtau;
00155
00156 double pNC = evt->pNC;
00157 double pCCe = evt->pCCe;
00158 double pCCmu = evt->pCCmu;
00159 double pCCtau = evt->pCCtau;
00160
00161 double GeV = evt->GeV;
00162 double Sigcor = evt->Sigcor;
00163
00164 int NumPln = evt->NumPln;
00165
00166 VHS::evtType evtt = VHS::GetEvtType( MCinu, MCiaction );
00167
00168
00169 TPaveText* ptL = new TPaveText(0.02,0.02,0.5,0.45,"brNDC");
00170 ptL->SetLineWidth(2);
00171 ptL->SetBorderSize(1);
00172 ptL->SetTextSize(0.05);
00173 ptL->SetTextAlign(12);
00174
00175 std::string li1L = std::string("dCCe = ") + VHS::ToString(dCCe,7,5);
00176 std::string li2L = std::string("dCC#mu = ") + VHS::ToString(dCCmu,7,5);
00177 std::string li3L = std::string("dCC#tau = ") + VHS::ToString(dCCtau,7,5);
00178 std::string li4L = std::string("dNC = ") + VHS::ToString(dNC,7,5);
00179 ptL->AddText(li1L.c_str());
00180 ptL->AddText(li2L.c_str());
00181 ptL->AddText(li3L.c_str());
00182 ptL->AddText(li4L.c_str());
00183 ptL->Draw();
00184
00185 TPaveText* ptR = new TPaveText(0.5,0.02,0.98,0.45,"brNDC");
00186 ptR->SetLineWidth(2);
00187 ptR->SetBorderSize(1);
00188 ptR->SetTextSize(0.05);
00189 ptR->SetTextAlign(12);
00190
00191 std::string li1R = std::string("pCCe = ") + VHS::ToString(pCCe,7,5);
00192 std::string li2R = std::string("pCC#mu = ") + VHS::ToString(pCCmu,7,5);
00193 std::string li3R = std::string("pCC#tau = ") + VHS::ToString(pCCtau,7,5);
00194 std::string li4R = std::string("pNC = ") + VHS::ToString(pNC,7,5);
00195 ptR->AddText(li1R.c_str());
00196 ptR->AddText(li2R.c_str());
00197 ptR->AddText(li3R.c_str());
00198 ptR->AddText(li4R.c_str());
00199 ptR->Draw();
00200
00201 TPaveText* pt = new TPaveText(0.02,0.45,0.98,0.98,"brNDC");
00202 pt->SetLineWidth(2);
00203 pt->SetBorderSize(1);
00204 pt->SetTextSize(0.05);
00205 pt->SetTextAlign(12);
00206
00207 std::string li1 =
00208 std::string("Event #") + VHS::ToString(nEntry+1) +
00209 std::string(" of ") + VHS::ToString(kNumEntries);
00210 std::string li2 = std::string("");
00211 if (evtt == vhsNC ) li2 = "NC event ";
00212 if (evtt == vhsCCe ) li2 = "e CCevent ";
00213 if (evtt == vhsCCmu ) li2 = "#mu CC event ";
00214 if (evtt == vhsCCtau) li2 = "#tau CC event ";
00215 li2 += (MC)?
00216 std::string("(") + VHS::ToString(NumPln) + std::string(" total planes)") :
00217 VHS::ToString(NumPln) + std::string(" total planes") ;
00218 std::string li3 = std::string("E_{vis} = ") + VHS::ToString(GeV,7,5) +
00219 std::string(" GeV (") + VHS::ToString(Sigcor,7,7) + std::string(" pe)");
00220 std::string li4 = (MC)?
00221 std::string("E_{#nu} = ") +
00222 VHS::ToString(MCenu,7,5) +
00223 std::string(" GeV") :
00224 "";
00225 std::string li5 = "";
00226 if ( dNC < dCCmu )
00227 li5 = std::string("Determined: NC event");
00228 if ( dCCmu < dNC )
00229 li5 = std::string("Determined: #mu CC event");
00230
00231
00232
00233
00234
00235
00236
00237
00238 li5 += std::string(" (distance) ");
00239 pt->AddText(li1.c_str());
00240 pt->AddText(li2.c_str());
00241 pt->AddText(li3.c_str());
00242 if (MC) pt->AddText(li4.c_str());
00243 if ( (MC) ){
00244 if ((evtt == vhsNC &&
00245 dNC > dCCmu ) ||
00246 (evtt == vhsCCmu &&
00247 dCCmu > dNC ) )
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 pt->AddText(li5.c_str())->SetTextColor(2);
00258 else
00259 pt->AddText(li5.c_str());
00260 } else {
00261 pt->AddText(li5.c_str());
00262 }
00263
00264 std::string li6 = "";
00265 if ( pNC > pCCmu )
00266 li6 = std::string("Determined: NC event");
00267 if ( pCCmu > pNC )
00268 li6 = std::string("Determined: #mu CC event");
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 li6 += std::string(" (loglikelihood) ");
00280 if ( (MC) ) {
00281 if ((evtt == vhsNC &&
00282 pNC < pCCmu ) ||
00283 (evtt == vhsCCmu &&
00284 pCCmu < pNC ) )
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294 pt->AddText(li6.c_str())->SetTextColor(2);
00295 else
00296 pt->AddText(li6.c_str());
00297 } else {
00298 pt->AddText(li6.c_str());
00299 }
00300
00301 pt->Draw();
00302
00303 delete evt; evt = 0;
00304
00305 evtDisp->cd(3);
00306
00307 evtDisp->SetEditable(kFALSE);
00308
00309 return true;
00310
00311 }
00312
00313
00314
00315 void VHS::FillDiscriminants(NtpSREvent* evt,
00316 TClonesArray* stp,
00317 std::vector<double> avgNC,
00318 std::vector<double> avgCCe,
00319 std::vector<double> avgCCmu,
00320 std::vector<double> avgCCtau,
00321 std::vector<double> varNC,
00322 std::vector<double> varCCe,
00323 std::vector<double> varCCmu,
00324 std::vector<double> varCCtau,
00325 std::vector<double> pNC,
00326 std::vector<double> pCCe,
00327 std::vector<double> pCCmu,
00328 std::vector<double> pCCtau,
00329 const int nPlanes,
00330 const int nStrips,
00331 const bool bUnit,
00332 VHSevent*& vhsevt)
00333 {
00334
00335
00336 std::vector<double> image;
00337 std::vector<int> index;
00338 std::vector<double> theta;
00339 VHS::GetImage(evt->stp, evt->nstrip,
00340 stp, nPlanes, nStrips, image, index, theta);
00341
00342 vhsevt->stp = image;
00343 vhsevt->ind = index;
00344
00345 vhsevt->MOIThetaU = theta[0];
00346 vhsevt->MOIThetaV = theta[1];
00347
00348
00349 vhsevt->MinPlnU = evt->plane.begu;
00350 vhsevt->MinPlnV = evt->plane.begv;
00351
00352
00353 std::vector<double> fullImg = FullVec(image,index,nPlanes,nStrips);
00354
00355 vhsevt->pNC =
00356 VHS::GetLL(fullImg, pNC , avgNC , varNC );
00357 vhsevt->pCCe =
00358 VHS::GetLL(fullImg, pCCe , avgCCe , varCCe );
00359 vhsevt->pCCmu =
00360 VHS::GetLL(fullImg, pCCmu , avgCCmu , varCCmu );
00361 vhsevt->pCCtau =
00362 VHS::GetLL(fullImg, pCCtau, avgCCtau, varCCtau);
00363
00364
00365 if (bUnit) {
00366 VHS::UnitVector(fullImg );
00367 VHS::UnitVector(avgNC );
00368 VHS::UnitVector(avgCCe );
00369 VHS::UnitVector(avgCCmu );
00370 VHS::UnitVector(avgCCtau);
00371 }
00372
00373 vhsevt->dNC = VHS::GetDistance( fullImg, avgNC );
00374 vhsevt->dCCe = VHS::GetDistance( fullImg, avgCCe );
00375 vhsevt->dCCmu = VHS::GetDistance( fullImg, avgCCmu );
00376 vhsevt->dCCtau = VHS::GetDistance( fullImg, avgCCtau );
00377
00378 }
00379
00380
00381
00382 std::vector<double> VHS::FindMedian(std::vector< std::vector<double> > pt,
00383 std::vector< double > avg,
00384 bool bUnit,
00385 bool bVerbose )
00386 {
00387 const unsigned int nDim = avg.size();
00388 const unsigned int nPts = pt.size();
00389 const double kEpsilon = 1.e-6;
00390 const double kDelta = 1.e-4;
00391
00392 if (bUnit) {
00393 VHS::UnitVector(avg);
00394 for (unsigned int i = 0; i < nPts; i++)
00395 VHS::UnitVector(pt[i]);
00396 }
00397
00398
00399 vector<double> median = avg;
00400 vector<double> lastMedian(nDim, 0.);
00401 double dDist = 999.;
00402 double lastAvgD = 0.;
00403 double avgD = 0.;
00404
00405
00406 for (unsigned int i = 0; i < nPts; i++) {
00407 double dPt = VHS::GetDistance(median, pt[i]);
00408 avgD += dPt/nPts;
00409 }
00410 if (bVerbose)
00411 cout << "-- Iteration 0 : dItr = N/A : avgDist = " << avgD << " del(N/A)" << endl;
00412
00413
00414 double dItr = 999.;
00415 int nItr = 0;
00416 while( dItr > kDelta ) {
00417 lastMedian = median;
00418 for (unsigned int j = 0; j < nDim; j++) median[j] = 0.;
00419 lastAvgD = avgD;
00420 avgD = 0.;
00421
00422
00423 double norm = 0.;
00424 for (unsigned int i = 0; i < nPts; i++) {
00425 double dPt = VHS::GetDistance(lastMedian, pt[i]);
00426
00427 if (!bUnit) norm += (dPt > kEpsilon)? 1./dPt : 1./kEpsilon;
00428
00429 for (unsigned int j = 0; j < nDim; j++)
00430 median[j] += (dPt > kEpsilon)?
00431 pt[i][j]/dPt : pt[i][j]/TMath::Abs(kEpsilon) ;
00432 }
00433
00434 if (bUnit) VHS::UnitVector(median);
00435 else for (unsigned int j = 0; j < nDim; j++) median[j] *= 1./norm;
00436
00437 dItr = VHS::GetDistance( lastMedian, median );
00438
00439 for (unsigned int i = 0; i < nPts; i++) {
00440 double dPt = VHS::GetDistance(median, pt[i]);
00441 avgD += dPt/nPts;
00442 }
00443
00444 dDist = lastAvgD-avgD;
00445 nItr++;
00446 if (bVerbose)
00447 cout << "-- Iteration " << nItr << " : dItr = " << dItr
00448 << " : avgDist = " << avgD << " del(" << dDist
00449 << ")" << endl;
00450 }
00451 if (bVerbose) {
00452 double dMedAvg = VHS::GetDistance( median, avg );
00453 cout << "|median-average| = " << dMedAvg << endl;
00454 }
00455
00456 return median;
00457
00458 }
00459
00460
00461
00462 std::vector<double> VHS::FullVec(std::vector<double> image,
00463 std::vector<int> index,
00464 int nPlanes,
00465 int nStrips)
00466 {
00467 std::vector<double> full( 2*nPlanes*nStrips, 0.);
00468
00469 for (unsigned int i = 0; i < index.size(); i++)
00470 full[ index[i] ] = image[i];
00471
00472 return full;
00473
00474 }
00475
00476
00477
00478 double VHS::GetDistance(std::vector<double> vec0, std::vector<double> vec1)
00479 {
00480
00481
00482
00483 if (vec0.size() != vec1.size()) return -1.;
00484
00485 double dist = 0.;
00486
00487 for (unsigned int i = 0; i < vec0.size(); i++)
00488 dist += TMath::Power( vec0[i]-vec1[i], 2. );
00489
00490 return TMath::Sqrt( dist );
00491
00492 }
00493
00494
00495
00496 VHS::evtType VHS::GetEvtType( int inu, int iaction )
00497 {
00498 if ( iaction == 0 ) return vhsNC;
00499
00500 if ( iaction == 1 && TMath::Abs(inu) == 12 ) return vhsCCe;
00501
00502 if ( iaction == 1 && TMath::Abs(inu) == 14 ) return vhsCCmu;
00503
00504 if ( iaction == 1 && TMath::Abs(inu) == 16 ) return vhsCCtau;
00505
00506 return vhsUnknown;
00507
00508 }
00509
00510
00511
00512 void VHS::GetImage(int* index,
00513 int nstp,
00514 TClonesArray* stp,
00515 int nPlanes,
00516 int nStrips,
00517 std::vector<double>& image,
00518 std::vector<int>& vecInd,
00519 std::vector<double>& theta)
00520 {
00521
00522
00523
00524
00525
00526 image.clear();
00527 vecInd.clear();
00528 theta.clear();
00529 theta = std::vector<double>(2,-999.);
00530
00531
00532 std::vector< std::vector<int> > uvindex(2);
00533 VHS::SeparateViews(index,nstp,stp,uvindex[0],uvindex[1]);
00534
00535 const int kOffsetInd = nPlanes*nStrips;
00536
00537 for (unsigned int uv = 0; uv <= 1 ; uv++) {
00538 std::vector<int> ind = uvindex[uv];
00539
00540
00541 std::vector<int> centerPix(2,0);
00542 VHS::GetThetaAxis(stp, uvindex[uv], theta[uv], centerPix);
00543
00544
00545 int minPln = 999;
00546 for (unsigned int j = 0; j < ind.size(); j++) {
00547 NtpSRStrip* stpEntry = dynamic_cast<NtpSRStrip*>(stp->At(ind[j]));
00548 if (stpEntry) {
00549 int plane = stpEntry->plane;
00550 int strip = stpEntry->strip;
00551 VHS::RotatePixel(plane,strip,centerPix[0],centerPix[1],theta[uv]);
00552 if (plane < minPln) minPln = plane;
00553 }
00554 }
00555
00556
00557 int endPln = minPln + 2*nPlanes;
00558
00559
00560 double stpXph = 0.;
00561 double totSigcor = 0.;
00562 for (unsigned int j = 0; j < ind.size(); j++) {
00563 NtpSRStrip* stpEntry = dynamic_cast<NtpSRStrip*>(stp->At(ind[j]));
00564 if (stpEntry) {
00565 int plane = stpEntry->plane;
00566 int strip = stpEntry->strip;
00567 VHS::RotatePixel(plane,strip,centerPix[0],centerPix[1],theta[uv]);
00568 if (plane >= minPln && plane < endPln) {
00569 double sigcor = stpEntry->ph0.sigcor + stpEntry->ph1.sigcor;
00570
00571 stpXph += plane*sigcor;
00572 totSigcor += sigcor;
00573 }
00574 }
00575 }
00576
00577
00578
00579 const int avgPln = TMath::FloorNint(stpXph/totSigcor);
00580 minPln = avgPln - TMath::FloorNint(0.25*2.*nPlanes);
00581 endPln = minPln + 2*nPlanes;
00582
00583
00584 stpXph = 0.;
00585 totSigcor = 0.;
00586 for (unsigned int j = 0; j < ind.size(); j++) {
00587 NtpSRStrip* stpEntry = dynamic_cast<NtpSRStrip*>(stp->At(ind[j]));
00588 if (stpEntry) {
00589 int plane = stpEntry->plane;
00590 int strip = stpEntry->strip;
00591 VHS::RotatePixel(plane,strip,centerPix[0],centerPix[1],theta[uv]);
00592 if (plane >= minPln && plane < endPln) {
00593 double sigcor = stpEntry->ph0.sigcor + stpEntry->ph1.sigcor;
00594
00595 stpXph += strip*sigcor;
00596 totSigcor += sigcor;
00597 }
00598 }
00599 }
00600
00601
00602 const int avgStp = TMath::FloorNint(stpXph/totSigcor);
00603 const int minStp = avgStp - nStrips/2;
00604
00605
00606 for (unsigned int i = 0; i < ind.size(); i++) {
00607 NtpSRStrip* stpEntry = dynamic_cast<NtpSRStrip*>(stp->At(ind[i]));
00608 if (stpEntry) {
00609 int plane = stpEntry->plane;
00610 int strip = stpEntry->strip;
00611 VHS::RotatePixel(plane,strip,centerPix[0],centerPix[1],theta[uv]);
00612 double sigcor = stpEntry->ph0.sigcor + stpEntry->ph1.sigcor;
00613
00614 int iPln = (plane - minPln)/2;
00615 int iStp = (strip - minStp);
00616 int iVec = VecIndex(iPln,iStp,nPlanes);
00617
00618 if (iPln >= 0 && iPln < nPlanes &&
00619 iStp >= 0 && iStp < nStrips ) {
00620 image.push_back(sigcor);
00621 if (uv == 0)
00622 vecInd.push_back(iVec);
00623 else
00624 vecInd.push_back(iVec+kOffsetInd);
00625 }
00626 }
00627 }
00628 }
00629
00630 return;
00631
00632 }
00633
00634
00635
00636 double VHS::GetLL(std::vector<double> fullImage,
00637 std::vector<double> pHit,
00638 std::vector<double> avg,
00639 std::vector<double> var)
00640 {
00641
00642
00643
00644
00645
00646 double ll = 0.;
00647 const double kCutoff = 1.e-10;
00648 const double kLnCutoff = TMath::Log10(kCutoff);
00649
00650 for (unsigned int i = 0; i < fullImage.size(); i++) {
00651 double x = fullImage[i];
00652 double mean = avg[i];
00653 double sigma = TMath::Sqrt( var[i] );
00654
00655 if ( x < kCutoff || pHit[i] < kCutoff )
00656 ll += TMath::Log10(1.-pHit[i]);
00657 else {
00658 ll += TMath::Log10(pHit[i]);
00659 ll += (TMath::Gaus(x,mean,sigma,true) > kCutoff)?
00660 TMath::Log10(TMath::Gaus(x,mean,sigma,true)) : kLnCutoff;
00661 ll -= (TMath::Gaus(mean,mean,sigma,true) > kCutoff)?
00662 TMath::Log10(TMath::Gaus(mean,mean,sigma,true)) : kLnCutoff;
00663 }
00664 }
00665
00666 return ll;
00667
00668 }
00669
00670
00671
00672 int VHS::GetPlane(int vecInd, int nPlanes)
00673 {
00674
00675 return (nPlanes != 0)? vecInd % nPlanes : -1;
00676 }
00677
00678
00679
00680 int VHS::GetStrip(int vecInd, int nPlanes)
00681 {
00682
00683 return (nPlanes != 0)? vecInd / nPlanes : -1;
00684 }
00685
00686
00687
00688 void VHS::GetThetaAxis(TClonesArray* stp,
00689 std::vector<int> index,
00690 double& theta,
00691 std::vector<int>& center)
00692 {
00693 const unsigned int kNhits = index.size();
00694
00695
00696
00697 double stpXph = 0.;
00698 double plnXph = 0.;
00699 double totSigcor = 0.;
00700 int minPln = 999;
00701 int minPlnStp = 999;
00702 for (unsigned int j = 0; j < kNhits; j++) {
00703 NtpSRStrip* stpEntry = dynamic_cast<NtpSRStrip*>(stp->At(index[j]));
00704 if (stpEntry) {
00705 int plane = stpEntry->plane;
00706 int strip = stpEntry->strip;
00707 double sigcor = stpEntry->ph0.sigcor + stpEntry->ph1.sigcor;
00708
00709 plnXph += plane*sigcor;
00710 stpXph += strip*sigcor;
00711 totSigcor += sigcor;
00712
00713 if (plane < minPln) {
00714 minPln = plane;
00715 minPlnStp = strip;
00716 }
00717 }
00718 }
00719
00720 center[0] = (int)TMath::Floor(plnXph/totSigcor);
00721 center[1] = (int)TMath::Floor(stpXph/totSigcor);
00722
00723 double relPln = plnXph/totSigcor - 1.*minPln;
00724 double relStp = stpXph/totSigcor - 1.*minPlnStp;
00725
00726 theta = (TMath::Abs(relPln) > 1.e-10)?
00727 TMath::ATan( relStp/relPln ) : 0.;
00728
00729 return;
00730 }
00731
00732
00733
00734 std::vector<std::string> VHS::ParseNmList(const char* cstr)
00735 {
00736
00737
00738 std::string strList = cstr;
00739
00740 std::vector<std::string> strVec;
00741
00742 int len = strList.length();
00743
00744 unsigned int lastLoc = 0;
00745 unsigned int loc = strList.find(" ",lastLoc);
00746 while (lastLoc != std::string::npos) {
00747 int subLen = (loc != std::string::npos)? loc-lastLoc : len-lastLoc;
00748 std::string sub = strList.substr(lastLoc, subLen);
00749 if (sub.length() > 0) strVec.push_back(sub);
00750 lastLoc = (loc != std::string::npos)? loc+1 : loc;
00751 loc = strList.find(" ",lastLoc);
00752 }
00753
00754 return strVec;
00755 }
00756
00757
00758
00759 void VHS::ReadFile(TFile* inFile,
00760 std::vector<double>& avgNC,
00761 std::vector<double>& avgCCe,
00762 std::vector<double>& avgCCmu,
00763 std::vector<double>& avgCCtau,
00764 std::vector<double>& varNC,
00765 std::vector<double>& varCCe,
00766 std::vector<double>& varCCmu,
00767 std::vector<double>& varCCtau,
00768 std::vector<double>& pNChit,
00769 std::vector<double>& pCCehit,
00770 std::vector<double>& pCCmuhit,
00771 std::vector<double>& pCCtauhit,
00772 const int nPlanes)
00773 {
00774
00775
00776
00777
00778
00779
00780
00781
00782 inFile->cd();
00783
00784
00785 const std::string UpNCName = "UpNCHit";
00786 const std::string VpNCName = "VpNCHit";
00787 TH2D* UpNCHist = (TH2D*)inFile->Get(UpNCName.c_str());
00788 TH2D* VpNCHist = (TH2D*)inFile->Get(VpNCName.c_str());
00789 std::vector<double> UpNChit = VHS::ToVector( UpNCHist, nPlanes);
00790 std::vector<double> VpNChit = VHS::ToVector( VpNCHist, nPlanes);
00791 pNChit.clear();
00792 for (unsigned int i = 0; i < UpNChit.size(); i++)
00793 pNChit.push_back(UpNChit[i]);
00794 for (unsigned int i = 0; i < VpNChit.size(); i++)
00795 pNChit.push_back(VpNChit[i]);
00796
00797
00798 const std::string UpCCeName = "UpCCeHit";
00799 const std::string VpCCeName = "VpCCeHit";
00800 TH2D* UpCCeHist = (TH2D*)inFile->Get(UpCCeName.c_str());
00801 TH2D* VpCCeHist = (TH2D*)inFile->Get(VpCCeName.c_str());
00802 std::vector<double> UpCCehit = VHS::ToVector( UpCCeHist, nPlanes);
00803 std::vector<double> VpCCehit = VHS::ToVector( VpCCeHist, nPlanes);
00804 pCCehit.clear();
00805 for (unsigned int i = 0; i < UpCCehit.size(); i++)
00806 pCCehit.push_back(UpCCehit[i]);
00807 for (unsigned int i = 0; i < VpCCehit.size(); i++)
00808 pCCehit.push_back(VpCCehit[i]);
00809
00810
00811 const std::string UpCCmuName = "UpCCmuHit";
00812 const std::string VpCCmuName = "VpCCmuHit";
00813 TH2D* UpCCmuHist = (TH2D*)inFile->Get(UpCCmuName.c_str());
00814 TH2D* VpCCmuHist = (TH2D*)inFile->Get(VpCCmuName.c_str());
00815 std::vector<double> UpCCmuhit = VHS::ToVector( UpCCmuHist, nPlanes);
00816 std::vector<double> VpCCmuhit = VHS::ToVector( VpCCmuHist, nPlanes);
00817 pCCmuhit.clear();
00818 for (unsigned int i = 0; i < UpCCmuhit.size(); i++)
00819 pCCmuhit.push_back(UpCCmuhit[i]);
00820 for (unsigned int i = 0; i < VpCCmuhit.size(); i++)
00821 pCCmuhit.push_back(VpCCmuhit[i]);
00822
00823
00824 const std::string UpCCtauName = "UpCCtauHit";
00825 const std::string VpCCtauName = "VpCCtauHit";
00826 TH2D* UpCCtauHist = (TH2D*)inFile->Get(UpCCtauName.c_str());
00827 TH2D* VpCCtauHist = (TH2D*)inFile->Get(VpCCtauName.c_str());
00828 std::vector<double> UpCCtauhit = VHS::ToVector( UpCCtauHist, nPlanes);
00829 std::vector<double> VpCCtauhit = VHS::ToVector( VpCCtauHist, nPlanes);
00830 pCCtauhit.clear();
00831 for (unsigned int i = 0; i < UpCCtauhit.size(); i++)
00832 pCCtauhit.push_back(UpCCtauhit[i]);
00833 for (unsigned int i = 0; i < VpCCtauhit.size(); i++)
00834 pCCtauhit.push_back(VpCCtauhit[i]);
00835
00836
00837 const std::string UavgNCName = "UAvgNCImg";
00838 const std::string VavgNCName = "VAvgNCImg";
00839 TH2D* UavgNCHist = (TH2D*)inFile->Get(UavgNCName.c_str());
00840 TH2D* VavgNCHist = (TH2D*)inFile->Get(VavgNCName.c_str());
00841 std::vector<double> UavgNC = VHS::ToVector( UavgNCHist, nPlanes);
00842 std::vector<double> VavgNC = VHS::ToVector( VavgNCHist, nPlanes);
00843 avgNC.clear();
00844 for (unsigned int i = 0; i < UavgNC.size(); i++)
00845 avgNC.push_back(UavgNC[i]);
00846 for (unsigned int i = 0; i < VavgNC.size(); i++)
00847 avgNC.push_back(VavgNC[i]);
00848
00849
00850 const std::string UavgCCeName = "UAvgCCeImg";
00851 const std::string VavgCCeName = "VAvgCCeImg";
00852 TH2D* UavgCCeHist = (TH2D*)inFile->Get(UavgCCeName.c_str());
00853 TH2D* VavgCCeHist = (TH2D*)inFile->Get(VavgCCeName.c_str());
00854 std::vector<double> UavgCCe = VHS::ToVector( UavgCCeHist, nPlanes);
00855 std::vector<double> VavgCCe = VHS::ToVector( VavgCCeHist, nPlanes);
00856 avgCCe.clear();
00857 for (unsigned int i = 0; i < UavgCCe.size(); i++)
00858 avgCCe.push_back(UavgCCe[i]);
00859 for (unsigned int i = 0; i < VavgCCe.size(); i++)
00860 avgCCe.push_back(VavgCCe[i]);
00861
00862
00863 const std::string UavgCCmuName = "UAvgCCmuImg";
00864 const std::string VavgCCmuName = "VAvgCCmuImg";
00865 TH2D* UavgCCmuHist = (TH2D*)inFile->Get(UavgCCmuName.c_str());
00866 TH2D* VavgCCmuHist = (TH2D*)inFile->Get(VavgCCmuName.c_str());
00867 std::vector<double> UavgCCmu = VHS::ToVector( UavgCCmuHist, nPlanes);
00868 std::vector<double> VavgCCmu = VHS::ToVector( VavgCCmuHist, nPlanes);
00869 avgCCmu.clear();
00870 for (unsigned int i = 0; i < UavgCCmu.size(); i++)
00871 avgCCmu.push_back(UavgCCmu[i]);
00872 for (unsigned int i = 0; i < VavgCCmu.size(); i++)
00873 avgCCmu.push_back(VavgCCmu[i]);
00874
00875
00876 const std::string UavgCCtauName = "UAvgCCtauImg";
00877 const std::string VavgCCtauName = "VAvgCCtauImg";
00878 TH2D* UavgCCtauHist = (TH2D*)inFile->Get(UavgCCtauName.c_str());
00879 TH2D* VavgCCtauHist = (TH2D*)inFile->Get(VavgCCtauName.c_str());
00880 std::vector<double> UavgCCtau = VHS::ToVector( UavgCCtauHist, nPlanes);
00881 std::vector<double> VavgCCtau = VHS::ToVector( VavgCCtauHist, nPlanes);
00882 avgCCtau.clear();
00883 for (unsigned int i = 0; i < UavgCCtau.size(); i++)
00884 avgCCtau.push_back(UavgCCtau[i]);
00885 for (unsigned int i = 0; i < VavgCCtau.size(); i++)
00886 avgCCtau.push_back(VavgCCtau[i]);
00887
00888
00889 const std::string UNCVarName = "UNCVar";
00890 const std::string VNCVarName = "VNCVar";
00891 TH2D* UNCVarHist = (TH2D*)inFile->Get(UNCVarName.c_str());
00892 TH2D* VNCVarHist = (TH2D*)inFile->Get(VNCVarName.c_str());
00893 std::vector<double> UNCVar = VHS::ToVector( UNCVarHist, nPlanes);
00894 std::vector<double> VNCVar = VHS::ToVector( VNCVarHist, nPlanes);
00895 varNC.clear();
00896 for (unsigned int i = 0; i < UNCVar.size(); i++)
00897 varNC.push_back(UNCVar[i]);
00898 for (unsigned int i = 0; i < VpNChit.size(); i++)
00899 varNC.push_back(VNCVar[i]);
00900
00901
00902 const std::string UCCeVarName = "UCCeVar";
00903 const std::string VCCeVarName = "VCCeVar";
00904 TH2D* UCCeVarHist = (TH2D*)inFile->Get(UCCeVarName.c_str());
00905 TH2D* VCCeVarHist = (TH2D*)inFile->Get(VCCeVarName.c_str());
00906 std::vector<double> UCCeVar = VHS::ToVector( UCCeVarHist, nPlanes);
00907 std::vector<double> VCCeVar = VHS::ToVector( VCCeVarHist, nPlanes);
00908 varCCe.clear();
00909 for (unsigned int i = 0; i < UCCeVar.size(); i++)
00910 varCCe.push_back(UCCeVar[i]);
00911 for (unsigned int i = 0; i < VpCCehit.size(); i++)
00912 varCCe.push_back(VCCeVar[i]);
00913
00914
00915 const std::string UCCmuVarName = "UCCmuVar";
00916 const std::string VCCmuVarName = "VCCmuVar";
00917 TH2D* UCCmuVarHist = (TH2D*)inFile->Get(UCCmuVarName.c_str());
00918 TH2D* VCCmuVarHist = (TH2D*)inFile->Get(VCCmuVarName.c_str());
00919 std::vector<double> UCCmuVar = VHS::ToVector( UCCmuVarHist, nPlanes);
00920 std::vector<double> VCCmuVar = VHS::ToVector( VCCmuVarHist, nPlanes);
00921 varCCmu.clear();
00922 for (unsigned int i = 0; i < UCCmuVar.size(); i++)
00923 varCCmu.push_back(UCCmuVar[i]);
00924 for (unsigned int i = 0; i < VpCCmuhit.size(); i++)
00925 varCCmu.push_back(VCCmuVar[i]);
00926
00927
00928 const std::string UCCtauVarName = "UCCtauVar";
00929 const std::string VCCtauVarName = "VCCtauVar";
00930 TH2D* UCCtauVarHist = (TH2D*)inFile->Get(UCCtauVarName.c_str());
00931 TH2D* VCCtauVarHist = (TH2D*)inFile->Get(VCCtauVarName.c_str());
00932 std::vector<double> UCCtauVar = VHS::ToVector( UCCtauVarHist, nPlanes);
00933 std::vector<double> VCCtauVar = VHS::ToVector( VCCtauVarHist, nPlanes);
00934 varCCtau.clear();
00935 for (unsigned int i = 0; i < UCCtauVar.size(); i++)
00936 varCCtau.push_back(UCCtauVar[i]);
00937 for (unsigned int i = 0; i < VpCCtauhit.size(); i++)
00938 varCCtau.push_back(VCCtauVar[i]);
00939
00940 inFile->Close();
00941
00942 return;
00943
00944 }
00945
00946
00947
00948 void VHS::RotatePixel(int& plane, int& strip,
00949 const int avgPlane, const int avgStrip,
00950 const double theta )
00951 {
00952
00953
00954
00955 if ( TMath::Abs(theta) < 1.e-10 ) return;
00956
00957 const double cosTheta = TMath::Cos(-theta);
00958 const double sinTheta = TMath::Sin(-theta);
00959
00960 double newPlnD = cosTheta*(plane-avgPlane) + sinTheta*(strip-avgStrip);
00961 double newStpD = cosTheta*(strip-avgStrip) - sinTheta*(plane-avgPlane);
00962
00963 if (newStpD-TMath::Floor(newStpD) < 0.5) newStpD = TMath::Floor(newStpD);
00964 else newStpD = TMath::Ceil(newStpD);
00965
00966 if (newPlnD-TMath::Floor(newPlnD) < 0.5) newPlnD = TMath::Floor(newPlnD);
00967 else newPlnD = TMath::Ceil(newPlnD);
00968
00969 strip = avgStrip + (int)newStpD;
00970 plane = avgPlane + (int)newPlnD;
00971
00972 return;
00973
00974 }
00975
00976
00977
00978 void VHS::SeparateViews(int* index, int nstp, TClonesArray* stp,
00979 std::vector<int>& ustp, std::vector<int>& vstp)
00980 {
00981
00982
00983 for (int i = 0; i < nstp; i++) {
00984 int ind = index[i];
00985 NtpSRStrip* strip = dynamic_cast<NtpSRStrip*>(stp->At(ind));
00986 if (strip) {
00987 unsigned int pv = strip->planeview;
00988 if (pv == PlaneView::kU) ustp.push_back(ind);
00989 if (pv == PlaneView::kV) vstp.push_back(ind);
00990 }
00991 }
00992 return;
00993 }
00994
00995
00996
00997 std::vector< VHSevent* > VHS::Skim(NtpStRecord* ntpst,
00998 std::vector<double> avgNC,
00999 std::vector<double> avgCCe,
01000 std::vector<double> avgCCmu,
01001 std::vector<double> avgCCtau,
01002 std::vector<double> varNC,
01003 std::vector<double> varCCe,
01004 std::vector<double> varCCmu,
01005 std::vector<double> varCCtau,
01006 std::vector<double> pNC,
01007 std::vector<double> pCCe,
01008 std::vector<double> pCCmu,
01009 std::vector<double> pCCtau,
01010 const int nPlanes,
01011 const int nStrips,
01012 const bool bUnit)
01013 {
01014
01015
01016
01017
01018
01019
01020
01021
01022 vector< VHSevent* > vhslist;
01023
01024
01025 if ( !ntpst ) return vhslist;
01026
01027 const NtpSREventSummary& evthdr = ntpst->evthdr;
01028 TClonesArray* evt = ntpst->evt;
01029 TClonesArray* stp = ntpst->stp;
01030 TClonesArray* mc = ntpst->mc;
01031 TClonesArray* thevt = ntpst->thevt;
01032
01033
01034 if (evt && stp) {
01035 const unsigned int nEvt = evthdr.nevent;
01036
01037 for (unsigned int i = 0; i < nEvt; i++){
01038 NtpSREvent* evtEntry = dynamic_cast<NtpSREvent*>( evt->At(i) );
01039 if ( !evtEntry ) continue;
01040
01041
01042 VHSevent* vhsevt = new VHSevent( ntpst->GetHeader() ) ;
01043 vhsevt->SetName("VHSevent");
01044 vhsevt->SetTitle("VHS Event");
01045
01046
01047 vhsevt->GeV = evtEntry->ph.gev;
01048 vhsevt->NumPln = evtEntry->plane.end - evtEntry->plane.beg;
01049 vhsevt->NumStp = evtEntry->nstrip;
01050 vhsevt->Sigcor = evtEntry->ph.sigcor;
01051
01052 VHS::evtType evtt = vhsUnknown;
01053
01054
01055 if ( mc && thevt ) {
01056 NtpTHEvent* thevtEntry = dynamic_cast<NtpTHEvent*>(thevt->At(i));
01057 NtpMCTruth* mcEntry = (thevtEntry)?
01058 dynamic_cast<NtpMCTruth*>( mc->At( (thevtEntry->neumc) ) ) : 0;
01059 if (mcEntry) {
01060 vhsevt->MCenu = mcEntry->p4neu[3];
01061 vhsevt->MCinu = mcEntry->inu;
01062 vhsevt->MCiaction = mcEntry->iaction;
01063 vhsevt->MCrescode = mcEntry->iresonance;
01064 vhsevt->MCQsq = mcEntry->q2;
01065 vhsevt->MCWsq = mcEntry->w2;
01066 vhsevt->MCx = mcEntry->x;
01067 vhsevt->MCy = mcEntry->y;
01068
01069 evtt = VHS::GetEvtType(mcEntry->inu, mcEntry->iaction);
01070 }
01071 }
01072 vhsevt->MC = (evtt != vhsUnknown);
01073
01074 VHS::FillDiscriminants(evtEntry, stp,
01075 avgNC, avgCCe, avgCCmu, avgCCtau,
01076 varNC, varCCe, varCCmu, varCCtau,
01077 pNC, pCCe, pCCmu, pCCtau,
01078 nPlanes, nStrips, bUnit, vhsevt );
01079
01080 vhslist.push_back( vhsevt );
01081
01082 }
01083 }
01084
01085 return vhslist;
01086 }
01087
01088
01089
01090 std::vector<double> VHS::SubtractVec(std::vector<double> image0,
01091 std::vector<double> image1)
01092 {
01093
01094
01095 std::vector<double> subt(image0.size(), 0.);
01096
01097 if (image0.size() != image1.size() ) return subt;
01098
01099 for (unsigned int i = 0; i < image0.size(); i++)
01100 subt[i] = image0[i] - image1[i];
01101
01102 return subt;
01103
01104 }
01105
01106
01107
01108 template<class T>
01109 std::string VHS::ToString(const T& thing, int w, int p)
01110 {
01111
01112 std::ostringstream os;
01113 os << std::setw(w) << std::setprecision(p) << thing;
01114 return os.str();
01115
01116 }
01117
01118
01119
01120 void VHS::ToTH2D(std::vector<double> vec,
01121 int nPlanes, int nStrips,
01122 std::string name, std::string title,
01123 TH2D*& Uview, TH2D*& Vview )
01124 {
01125
01126
01127 std::string Uname = "U" + name;
01128 std::string Utitle = "U" + title;
01129
01130 std::string Vname = "V" + name;
01131 std::string Vtitle = "V" + title;
01132
01133
01134
01135
01136 Uview = new TH2D(Uname.c_str(), Utitle.c_str(),
01137 nPlanes, 0, nPlanes,
01138 nStrips, 0, nStrips);
01139 Vview = new TH2D(Vname.c_str(), Vtitle.c_str(),
01140 nPlanes, 0, nPlanes,
01141 nStrips, 0, nStrips);
01142 const unsigned int kOffset = nPlanes*nStrips;
01143 for (unsigned int i = 0; i < vec.size(); i++){
01144 if ( i < kOffset )
01145 Uview->SetBinContent( VHS::GetPlane(i,nPlanes)+1,
01146 VHS::GetStrip(i,nPlanes)+1,
01147 vec[i] );
01148 else
01149 Vview->SetBinContent( VHS::GetPlane(i-kOffset,nPlanes)+1,
01150 VHS::GetStrip(i-kOffset,nPlanes)+1,
01151 vec[i] );
01152 }
01153
01154 return;
01155
01156 }
01157
01158
01159
01160 std::vector<double> VHS::ToVector(TH2D* hist, int nPlanes)
01161 {
01162
01163
01164 const int nPln = hist->GetNbinsX();
01165 const int nStp = hist->GetNbinsY();
01166 const int nBins = nPln*nStp;
01167
01168 std::vector<double> vec(nBins,0.);
01169
01170 if (nPln != nPlanes) return vec;
01171
01172 for (int ipln = 0; ipln < nPln; ipln++)
01173 for (int istp = 0; istp < nStp; istp++)
01174 vec[VecIndex(ipln,istp,nPlanes)] =
01175 hist->GetBinContent(ipln+1, istp+1);
01176
01177 return vec;
01178
01179 }
01180
01181
01182
01183 int VHS::Train(NtpStRecord* ntpst,
01184 std::vector<double>& avgNC,
01185 std::vector<double>& avgCCe,
01186 std::vector<double>& avgCCmu,
01187 std::vector<double>& avgCCtau,
01188 std::vector<double>& varNC,
01189 std::vector<double>& varCCe,
01190 std::vector<double>& varCCmu,
01191 std::vector<double>& varCCtau,
01192 std::vector<int>& numNC,
01193 std::vector<int>& numCCe,
01194 std::vector<int>& numCCmu,
01195 std::vector<int>& numCCtau,
01196 int& NCevts,
01197 int& eCCevts,
01198 int& muCCevts,
01199 int& tauCCevts,
01200 const int maxTrain,
01201 const int nPlanes,
01202 const int nStrips,
01203 const int cutPlanes,
01204 const double eRecoMax,
01205 const double eTrueMax)
01206 {
01207
01208
01209
01210
01211
01212
01213
01214 int nEvtUsed = 0;
01215
01216
01217 if ( !ntpst ) return nEvtUsed;
01218
01219 const NtpSREventSummary& evthdr = ntpst->evthdr;
01220 TClonesArray* evt = ntpst->evt;
01221 TClonesArray* stp = ntpst->stp;
01222 TClonesArray* mc = ntpst->mc;
01223 TClonesArray* thevt = ntpst->thevt;
01224
01225
01226 if (evt && stp && mc && thevt) {
01227 const unsigned int nEvt = evthdr.nevent;
01228
01229 for (unsigned int i = 0; i < nEvt; i++){
01230 NtpSREvent* evtEntry = dynamic_cast<NtpSREvent*>( evt->At(i) );
01231 if ( !evtEntry ) continue;
01232
01233 NtpTHEvent* thevtEntry = dynamic_cast<NtpTHEvent*>(thevt->At(i));
01234 NtpMCTruth* mcEntry = (thevtEntry)?
01235 dynamic_cast<NtpMCTruth*>( mc->At( (thevtEntry->neumc) ) ) : 0;
01236 if ( !mcEntry ) continue;
01237
01238 const double eReco = evtEntry->ph.gev;
01239 const double eTrue = mcEntry->p4neu[3];
01240
01241 if (eReco < eRecoMax || eTrue < eTrueMax ) continue;
01242
01243 VHS::evtType evtt = VHS::GetEvtType(mcEntry->inu, mcEntry->iaction);
01244
01245 if ( evtt == vhsUnknown ) continue;
01246
01247 if (evtEntry->plane.end - evtEntry->plane.beg > cutPlanes) continue;
01248
01249 if ( ( evtt == vhsNC && NCevts >= maxTrain ) ||
01250 ( evtt == vhsCCe && eCCevts >= maxTrain ) ||
01251 ( evtt == vhsCCmu && muCCevts >= maxTrain ) ||
01252 ( evtt == vhsCCtau && tauCCevts >= maxTrain ) )
01253 continue;
01254
01255
01256 std::vector<double> image;
01257 std::vector<int> index;
01258 std::vector<double> theta;
01259 VHS::GetImage(evtEntry->stp, evtEntry->nstrip,
01260 stp, nPlanes, nStrips, image, index, theta);
01261
01262
01263 switch (evtt) {
01264 case vhsNC :
01265 for (unsigned int ind = 0; ind < image.size(); ind++) {
01266 int ii = index[ind];
01267 double xi = image[ind];
01268 int ni = numNC[ii];
01269
01270 avgNC[ii] = (avgNC[ii]*ni + xi )/(ni+1);
01271 varNC[ii] = (varNC[ii]*ni + xi*xi)/(ni+1);
01272 numNC[ii]++;
01273 }
01274 NCevts++;
01275
01276 break;
01277 case vhsCCe :
01278 for (unsigned int ind = 0; ind < image.size(); ind++) {
01279 int ii = index[ind];
01280 double xi = image[ind];
01281 int ni = numCCe[ii];
01282
01283 avgCCe[ii] = (avgCCe[ii]*ni + xi )/(ni+1);
01284 varCCe[ii] = (varCCe[ii]*ni + xi*xi)/(ni + 1);
01285 numCCe[ii]++;
01286 }
01287 eCCevts++;
01288
01289 break;
01290 case vhsCCmu :
01291 for (unsigned int ind = 0; ind < image.size(); ind++) {
01292 int ii = index[ind];
01293 double xi = image[ind];
01294 int ni = numCCmu[ii];
01295
01296 avgCCmu[ii] = (avgCCmu[ii]*ni + xi )/(ni+1);
01297 varCCmu[ii] = (varCCmu[ii]*ni + xi*xi)/(ni+1);
01298 numCCmu[ii]++;
01299 }
01300 muCCevts++;
01301
01302 break;
01303 case vhsCCtau :
01304 for (unsigned int ind = 0; ind < image.size(); ind++) {
01305 int ii = index[ind];
01306 double xi = image[ind];
01307 int ni = numCCtau[ii];
01308
01309 avgCCtau[ii] = (avgCCtau[ii]*ni + xi )/(ni+1);
01310 varCCtau[ii] = (varCCtau[ii]*ni + xi*xi)/(ni+1);
01311 numCCtau[ii]++;
01312 }
01313 tauCCevts++;
01314
01315 break;
01316 case vhsUnknown :
01317 continue;
01318 }
01319
01320 nEvtUsed++;
01321
01322 }
01323 }
01324
01325 return nEvtUsed;
01326
01327 }
01328
01329
01330
01331 void VHS::TrainPost(TFile* outFile,
01332 std::vector<double>& avgNC,
01333 std::vector<double>& avgCCe,
01334 std::vector<double>& avgCCmu,
01335 std::vector<double>& avgCCtau,
01336 std::vector<double>& varNC,
01337 std::vector<double>& varCCe,
01338 std::vector<double>& varCCmu,
01339 std::vector<double>& varCCtau,
01340 std::vector<int>& numNC,
01341 std::vector<int>& numCCe,
01342 std::vector<int>& numCCmu,
01343 std::vector<int>& numCCtau,
01344 int NCevts,
01345 int eCCevts,
01346 int muCCevts,
01347 int tauCCevts,
01348 const int nPlanes,
01349 const int nStrips)
01350 {
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361 const unsigned int kImgSz = avgNC.size();
01362
01363
01364 std::vector<double> pNChit (kImgSz, 0.0);
01365 std::vector<double> pCCehit (kImgSz, 0.0);
01366 std::vector<double> pCCmuhit (kImgSz, 0.0);
01367 std::vector<double> pCCtauhit(kImgSz, 0.0);
01368
01369 for (unsigned int pix = 0; pix < kImgSz; pix++) {
01370 pNChit[pix] = (NCevts > 0)?
01371 (double)numNC[pix] / (double)NCevts : 0.;
01372 pCCehit[pix] = (eCCevts > 0)?
01373 (double)numCCe[pix] / (double)eCCevts : 0.;
01374 pCCmuhit[pix] = (muCCevts > 0)?
01375 (double)numCCmu[pix] / (double)muCCevts : 0.;
01376 pCCtauhit[pix] = (tauCCevts > 0)?
01377 (double)numCCtau[pix] / (double)tauCCevts : 0.;
01378 }
01379
01380
01381 for (unsigned int ii = 0; ii < kImgSz; ii++) {
01382 varNC[ii] -= avgNC[ii] * avgNC[ii];
01383 varCCe[ii] -= avgCCe[ii] * avgCCe[ii];
01384 varCCmu[ii] -= avgCCmu[ii] * avgCCmu[ii];
01385 varCCtau[ii] -= avgCCtau[ii] * avgCCtau[ii];
01386
01387 }
01388
01389 VHS::WriteFile( outFile,
01390 avgNC, avgCCe, avgCCmu, avgCCtau,
01391 varNC, varCCe, varCCmu, varCCtau,
01392 pNChit, pCCehit, pCCmuhit, pCCtauhit,
01393 nPlanes, nStrips);
01394
01395 return;
01396
01397 }
01398
01399
01400
01401 void VHS::UnitVector(std::vector<double>& vec)
01402 {
01403 double len = 0.;
01404
01405 for (unsigned int i = 0; i < vec.size(); i++)
01406 len += TMath::Power( vec[i], 2. );
01407
01408 len = TMath::Sqrt( len );
01409
01410 if (len <= 0.) return;
01411
01412 for (unsigned int i = 0; i < vec.size(); i++)
01413 vec[i] = vec[i] / len ;
01414
01415 return;
01416
01417 }
01418
01419
01420
01421 int VHS::VecIndex(int ipln, int istp, int nPlanes)
01422 {
01423
01424
01425 return (ipln + nPlanes * istp);
01426
01427 }
01428
01429
01430
01431 void VHS::WriteFile(TFile* outFile,
01432 std::vector<double>& avgNC,
01433 std::vector<double>& avgCCe,
01434 std::vector<double>& avgCCmu,
01435 std::vector<double>& avgCCtau,
01436 std::vector<double>& varNC,
01437 std::vector<double>& varCCe,
01438 std::vector<double>& varCCmu,
01439 std::vector<double>& varCCtau,
01440 std::vector<double>& pNChit,
01441 std::vector<double>& pCCehit,
01442 std::vector<double>& pCCmuhit,
01443 std::vector<double>& pCCtauhit,
01444 const int nPlanes,
01445 const int nStrips)
01446 {
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457 outFile->cd();
01458
01459 const std::string imgXTitle = "Plane";
01460 const std::string imgYTitle = "Strip";
01461
01462
01463 const std::string pNCTitle = "NC Hit Probabilities";
01464 const std::string pNCName = "pNCHit";
01465 TH2D* UpNCHist; TH2D* VpNCHist;
01466 VHS::ToTH2D( pNChit,
01467 nPlanes, nStrips,
01468 pNCName.c_str(),
01469 pNCTitle.c_str(),
01470 UpNCHist, VpNCHist);
01471 UpNCHist->SetXTitle( imgXTitle.c_str() );
01472 UpNCHist->SetYTitle( imgYTitle.c_str() );
01473 UpNCHist->Write();
01474 VpNCHist->SetXTitle( imgXTitle.c_str() );
01475 VpNCHist->SetYTitle( imgYTitle.c_str() );
01476 VpNCHist->Write();
01477
01478
01479 const std::string pCCeTitle = "CCe Hit Probabilities";
01480 const std::string pCCeName = "pCCeHit";
01481 TH2D* UpCCeHist; TH2D* VpCCeHist;
01482 VHS::ToTH2D( pCCehit,
01483 nPlanes, nStrips,
01484 pCCeName.c_str(),
01485 pCCeTitle.c_str(),
01486 UpCCeHist, VpCCeHist);
01487 UpCCeHist->SetXTitle( imgXTitle.c_str() );
01488 UpCCeHist->SetYTitle( imgYTitle.c_str() );
01489 UpCCeHist->Write();
01490 VpCCeHist->SetXTitle( imgXTitle.c_str() );
01491 VpCCeHist->SetYTitle( imgYTitle.c_str() );
01492 VpCCeHist->Write();
01493
01494
01495 const std::string pCCmuTitle = "CC#mu Hit Probabilities";
01496 const std::string pCCmuName = "pCCmuHit";
01497 TH2D* UpCCmuHist; TH2D* VpCCmuHist;
01498 VHS::ToTH2D( pCCmuhit,
01499 nPlanes, nStrips,
01500 pCCmuName.c_str(),
01501 pCCmuTitle.c_str(),
01502 UpCCmuHist, VpCCmuHist);
01503 UpCCmuHist->SetXTitle( imgXTitle.c_str() );
01504 UpCCmuHist->SetYTitle( imgYTitle.c_str() );
01505 UpCCmuHist->Write();
01506 VpCCmuHist->SetXTitle( imgXTitle.c_str() );
01507 VpCCmuHist->SetYTitle( imgYTitle.c_str() );
01508 VpCCmuHist->Write();
01509
01510
01511 const std::string pCCtauTitle = "CC#tau Hit Probabilities";
01512 const std::string pCCtauName = "pCCtauHit";
01513 TH2D* UpCCtauHist; TH2D* VpCCtauHist;
01514 VHS::ToTH2D( pCCtauhit,
01515 nPlanes, nStrips,
01516 pCCtauName.c_str(),
01517 pCCtauTitle.c_str(),
01518 UpCCtauHist, VpCCtauHist);
01519 UpCCtauHist->SetXTitle( imgXTitle.c_str() );
01520 UpCCtauHist->SetYTitle( imgYTitle.c_str() );
01521 UpCCtauHist->Write();
01522 VpCCtauHist->SetXTitle( imgXTitle.c_str() );
01523 VpCCtauHist->SetYTitle( imgYTitle.c_str() );
01524 VpCCtauHist->Write();
01525
01526
01527 const std::string avgNCTitle = "Average NC Image";
01528 const std::string avgNCName = "AvgNCImg";
01529 TH2D* UavgNCHist; TH2D* VavgNCHist;
01530 VHS::ToTH2D( avgNC,
01531 nPlanes, nStrips,
01532 avgNCName.c_str(),
01533 avgNCTitle.c_str(),
01534 UavgNCHist, VavgNCHist);
01535 UavgNCHist->SetXTitle( imgXTitle.c_str() );
01536 UavgNCHist->SetYTitle( imgYTitle.c_str() );
01537 UavgNCHist->Write();
01538 VavgNCHist->SetXTitle( imgXTitle.c_str() );
01539 VavgNCHist->SetYTitle( imgYTitle.c_str() );
01540 VavgNCHist->Write();
01541
01542
01543 const std::string avgCCeTitle = "Average CCe Image";
01544 const std::string avgCCeName = "AvgCCeImg";
01545 TH2D* UavgCCeHist; TH2D* VavgCCeHist;
01546 VHS::ToTH2D( avgCCe,
01547 nPlanes, nStrips,
01548 avgCCeName.c_str(),
01549 avgCCeTitle.c_str(),
01550 UavgCCeHist, VavgCCeHist);
01551 UavgCCeHist->SetXTitle( imgXTitle.c_str() );
01552 UavgCCeHist->SetYTitle( imgYTitle.c_str() );
01553 UavgCCeHist->Write();
01554 VavgCCeHist->SetXTitle( imgXTitle.c_str() );
01555 VavgCCeHist->SetYTitle( imgYTitle.c_str() );
01556 VavgCCeHist->Write();
01557
01558
01559 const std::string avgCCmuTitle = "Average CC#mu Image";
01560 const std::string avgCCmuName = "AvgCCmuImg";
01561 TH2D* UavgCCmuHist; TH2D* VavgCCmuHist;
01562 VHS::ToTH2D( avgCCmu,
01563 nPlanes, nStrips,
01564 avgCCmuName.c_str(),
01565 avgCCmuTitle.c_str(),
01566 UavgCCmuHist, VavgCCmuHist);
01567 UavgCCmuHist->SetXTitle( imgXTitle.c_str() );
01568 UavgCCmuHist->SetYTitle( imgYTitle.c_str() );
01569 UavgCCmuHist->Write();
01570 VavgCCmuHist->SetXTitle( imgXTitle.c_str() );
01571 VavgCCmuHist->SetYTitle( imgYTitle.c_str() );
01572 VavgCCmuHist->Write();
01573
01574
01575 const std::string avgCCtauTitle = "Average CC#tau Image";
01576 const std::string avgCCtauName = "AvgCCtauImg";
01577 TH2D* UavgCCtauHist; TH2D* VavgCCtauHist;
01578 VHS::ToTH2D( avgCCtau,
01579 nPlanes, nStrips,
01580 avgCCtauName.c_str(),
01581 avgCCtauTitle.c_str(),
01582 UavgCCtauHist, VavgCCtauHist);
01583 UavgCCtauHist->SetXTitle( imgXTitle.c_str() );
01584 UavgCCtauHist->SetYTitle( imgYTitle.c_str() );
01585 UavgCCtauHist->Write();
01586 VavgCCtauHist->SetXTitle( imgXTitle.c_str() );
01587 VavgCCtauHist->SetYTitle( imgYTitle.c_str() );
01588 VavgCCtauHist->Write();
01589
01590
01591 const std::string varNCTitle = "NC Variance";
01592 const std::string varNCName = "NCVar";
01593 TH2D* UvarNCHist; TH2D* VvarNCHist;
01594 VHS::ToTH2D( varNC,
01595 nPlanes, nStrips,
01596 varNCName.c_str(),
01597 varNCTitle.c_str(),
01598 UvarNCHist, VvarNCHist);
01599 UvarNCHist->SetXTitle( imgXTitle.c_str() );
01600 UvarNCHist->SetYTitle( imgYTitle.c_str() );
01601 UvarNCHist->Write();
01602 VvarNCHist->SetXTitle( imgXTitle.c_str() );
01603 VvarNCHist->SetYTitle( imgYTitle.c_str() );
01604 VvarNCHist->Write();
01605
01606
01607 const std::string varCCeTitle = "CCe Variance";
01608 const std::string varCCeName = "CCeVar";
01609 TH2D* UvarCCeHist; TH2D* VvarCCeHist;
01610 VHS::ToTH2D( varCCe,
01611 nPlanes, nStrips,
01612 varCCeName.c_str(),
01613 varCCeTitle.c_str(),
01614 UvarCCeHist, VvarCCeHist);
01615 UvarCCeHist->SetXTitle( imgXTitle.c_str() );
01616 UvarCCeHist->SetYTitle( imgYTitle.c_str() );
01617 UvarCCeHist->Write();
01618 VvarCCeHist->SetXTitle( imgXTitle.c_str() );
01619 VvarCCeHist->SetYTitle( imgYTitle.c_str() );
01620 VvarCCeHist->Write();
01621
01622
01623 const std::string varCCmuTitle = "CCmu Variance";
01624 const std::string varCCmuName = "CCmuVar";
01625 TH2D* UvarCCmuHist; TH2D* VvarCCmuHist;
01626 VHS::ToTH2D( varCCmu,
01627 nPlanes, nStrips,
01628 varCCmuName.c_str(),
01629 varCCmuTitle.c_str(),
01630 UvarCCmuHist, VvarCCmuHist);
01631 UvarCCmuHist->SetXTitle( imgXTitle.c_str() );
01632 UvarCCmuHist->SetYTitle( imgYTitle.c_str() );
01633 UvarCCmuHist->Write();
01634 VvarCCmuHist->SetXTitle( imgXTitle.c_str() );
01635 VvarCCmuHist->SetYTitle( imgYTitle.c_str() );
01636 VvarCCmuHist->Write();
01637
01638
01639 const std::string varCCtauTitle = "CCtau Variance";
01640 const std::string varCCtauName = "CCtauVar";
01641 TH2D* UvarCCtauHist; TH2D* VvarCCtauHist;
01642 VHS::ToTH2D( varCCtau,
01643 nPlanes, nStrips,
01644 varCCtauName.c_str(),
01645 varCCtauTitle.c_str(),
01646 UvarCCtauHist, VvarCCtauHist);
01647 UvarCCtauHist->SetXTitle( imgXTitle.c_str() );
01648 UvarCCtauHist->SetYTitle( imgYTitle.c_str() );
01649 UvarCCtauHist->Write();
01650 VvarCCtauHist->SetXTitle( imgXTitle.c_str() );
01651 VvarCCtauHist->SetYTitle( imgYTitle.c_str() );
01652 VvarCCtauHist->Write();
01653
01654 return;
01655
01656 }
01657
01658
01659