Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

FracVarAna.cxx

Go to the documentation of this file.
00001 #include "StandardNtuple/NtpStRecord.h"
00002 #include "CandNtupleSR/NtpSRRecord.h"
00003 #include "CandNtupleSR/NtpSREvent.h"
00004 #include "CandNtupleSR/NtpSRTrack.h"
00005 #include "CandNtupleSR/NtpSRShower.h"
00006 #include "CandNtupleSR/NtpSRStrip.h"
00007 #include "NueAna/NueAnaTools/SntpHelpers.h"
00008 #include "VertexFinder/NtpVtxFinder/NtpVtxFinder.h"
00009 #include "FracVarAna.h"
00010 #include "NueAna/mlpANN.h"
00011 #include "MessageService/MsgService.h"
00012 #include "TPad.h"
00013 #include "TLatex.h"
00014 #include "TNtuple.h"
00015 #include "TFile.h"
00016 #include "TMath.h"
00017 #include <cassert>
00018 #include <vector>
00019 #include <algorithm>
00020 #include <iostream>
00021 #include <fstream>
00022 
00023 using namespace std;
00024 
00025 CVSID("$Id: FracVarAna.cxx,v 1.31 2007/11/11 04:15:06 rhatcher Exp $");
00026 
00027 TMultiLayerPerceptron* FracVarAna::fneuralNet = 0;
00028 
00029 static Int_t WeightedFit
00030 (const Int_t n, const Double_t *x, const Double_t *y, const Double_t *w,
00031  Double_t *parm)
00032 {
00033   Double_t sumx=0.;
00034   Double_t sumx2=0.;
00035   Double_t sumy=0.;
00036   Double_t sumy2=0.;
00037   Double_t sumxy=0.;
00038   Double_t sumw=0.;
00039   Double_t eparm[2];
00040 
00041   parm[0]  = 0.;
00042   parm[1]  = 0.;
00043   eparm[0] = 0.;
00044   eparm[1] = 0.;
00045 
00046   for (Int_t i=0; i<n; i++) {
00047     sumx += x[i]*w[i];
00048     sumx2 += x[i]*x[i]*w[i];
00049     sumy += y[i]*w[i]; 
00050     sumy2 += y[i]*y[i]*w[i];
00051     sumxy += x[i]*y[i]*w[i];
00052     sumw += w[i];
00053   }
00054   
00055   if (sumx2*sumw-sumx*sumx==0.) return 1;
00056   if (sumx2-sumx*sumx/sumw==0.) return 1;
00057   
00058   parm[0] = (sumy*sumx2-sumx*sumxy)/(sumx2*sumw-sumx*sumx);
00059   parm[1] = (sumxy-sumx*sumy/sumw)/(sumx2-sumx*sumx/sumw);
00060   
00061   eparm[0] = sumx2*(sumx2*sumw-sumx*sumx);
00062   eparm[1] = (sumx2-sumx*sumx/sumw);
00063   
00064   if (eparm[0]<0. || eparm[1]<0.) return 1;
00065   
00066   eparm[0] = sqrt(eparm[0])/(sumx2*sumw-sumx*sumx);
00067   eparm[1] = sqrt(eparm[1])/(sumx2-sumx*sumx/sumw);
00068   
00069   return 0;
00070 
00071 }
00072 
00073 const Float_t STP_WIDTH = 0.0412; //should be the same for the near and far detectors
00074 
00075 
00076 FracVarAna::FracVarAna(FracVar &fv):
00077   fFracVar(fv),
00078   fDisplay(0)
00079 {
00080   display = new TNtuple("display","display","tpos:z:ph:uv:core");
00081   static bool first = true;
00082                                                                                 
00083   if(first){
00084     char *srt_dir = getenv("SRT_PRIVATE_CONTEXT");
00085     char annfile[10000];
00086     sprintf(annfile,"%s/NueAna/data/fvann032007.root",srt_dir);
00087     ifstream Test(annfile);
00088     if (!Test){
00089       srt_dir = getenv("SRT_PUBLIC_CONTEXT");
00090       sprintf(annfile,"%s/NueAna/data/fvann032007.root",srt_dir);
00091       ifstream Test_again(annfile);
00092       if (!Test_again){
00093         cout<<"Couldn't find ANN object for FracVarAna, blame Tingjun"<<endl;
00094         exit(0);
00095       }
00096     }
00097                                                                                 
00098     static TFile *f = TFile::Open(annfile);
00099     fneuralNet = (TMultiLayerPerceptron*) f->Get("mlp");
00100     cout<<"Reading FracVar ann from : "<<annfile<<endl;
00101     first = false;
00102   }
00103                                                                                 
00104   if (!fneuralNet) {
00105     cout<<"Couldn't find ANN object for FracVarAna, blame Tingjun"<<endl;
00106     exit(0);
00107   }
00108   
00109 }
00110 
00111 FracVarAna::~FracVarAna()
00112 {
00113   if(display){
00114     delete display;
00115     display=0;
00116   }
00117 
00118 }
00119 
00120 void FracVarAna::Analyze(int evtn,  RecRecordImp<RecCandHeader> *srobj)
00121 {
00122   if(srobj==0){
00123     return;
00124   }
00125 
00126   if(((dynamic_cast<NtpStRecord *>(srobj))==0)&&
00127      ((dynamic_cast<NtpSRRecord *>(srobj))==0)){
00128     return;
00129   }
00130 
00131   fFracVar.Reset();
00132   if (fDisplay) display->Reset();
00133 
00134   fFracVar.passcuts = 1;
00135   NtpSREvent *event = SntpHelpers::GetEvent(evtn,srobj);
00136   
00137   if ((event->ph.sigcor+event->ph.sigcor)<2e4)  fFracVar.passcuts = 0;
00138   if ((event->ph.sigcor+event->ph.sigcor)>1e5)  fFracVar.passcuts = 0;
00139 
00140   Int_t ntrks = event->ntrack;
00141   for (int itrk = 0; itrk<ntrks; itrk++){
00142     NtpSRTrack *track = SntpHelpers::GetTrack(itrk,srobj);
00143     if (track->plane.n>13) fFracVar.passcuts = 0;
00144   }
00145 
00146   Int_t nshws = event->nshower;
00147   if (nshws){//we should have at lease one shower in the event for the rest of the analysis
00148 
00149     if (fDisplay){
00150       for (int istp = 0; istp<event->nstrip; istp++){
00151         Int_t index = event->stp[istp];
00152         NtpSRStrip*strip = SntpHelpers::GetStrip(index,srobj);
00153         if(!strip) continue;
00154 //        if(!evtstp0mip){
00155 //          MSG("FracVarAna",Msg::kError)<<"No mip strip information"<<endl;
00156 //          continue;
00157 //        }
00158 
00159         float x1 = strip->tpos;
00160         float x2 = strip->z;
00161         float x3 = (strip->ph0.sigcor+strip->ph1.sigcor)/sigcormeu;
00162                    //evtstp0mip[index] + evtstp1mip[index];;
00163         int x4 = int(strip->planeview);
00164         display->Fill(x1,x2,x3,x4,0);
00165       }
00166     }
00167 
00168 //    //find the primary shower, now only require the maximum ph
00169 //    Int_t pshw = 0; //primary shower index in the shower array
00170 //    Float_t maxshwph = 0;
00171 //    for (int ishw = 0; ishw<nshws; ishw++){
00172 //      Int_t shwindex = event->shw[ishw];
00173 //      NtpSRShower *shower = SntpHelpers::GetShower(shwindex,srobj);
00174 //      if (shower->ph.sigcor>maxshwph){
00175 //      pshw = shwindex;
00176 //      maxshwph = shower->ph.sigcor;
00177 //      }
00178 //    }
00179 
00180     //Get the shower close to the track vertex or the biggest shower if
00181     //there is no track. Pull out from Mad.
00182     int track_index   = -1;
00183     int shower_index  = -1;
00184     if(ReleaseType::IsBirch(release)){
00185       if (LoadLargestTrackFromEvent(event,srobj,track_index)){
00186         if(!LoadShowerAtTrackVertex(event,srobj,track_index,shower_index)){
00187           LoadLargestShowerFromEvent(event,srobj,shower_index);
00188         }
00189       }
00190       else LoadLargestShowerFromEvent(event,srobj,shower_index);
00191     }
00192     else {//cedar ...
00193       if (ntrks) track_index = event->trk[0];
00194       //not using event->primshw, the concern is the 2GeV cut off
00195       if (nshws) shower_index = event->shw[0];
00196     }
00197     if (shower_index == -1) return; //no decent shower was found
00198 
00199     NtpSRShower *shower = SntpHelpers::GetShower(shower_index,srobj);
00200     if (!shower) return;     //no decent shower was found
00201     if (shower->plane.n<5) fFracVar.passcuts = 0;
00202     if (shower->plane.n>15) fFracVar.passcuts = 0;
00203     //get rid of cosmics
00204     if (shower->plane.beg>shower->plane.end) return;
00205     //get rid of events with shw.ph>evt.ph
00206 //    if (shower->ph.mip>event->ph.mip){
00207 //      MAXMSG("FracVarAna",Msg::kWarning,5)
00208 //      <<"shower ph("<<shower->ph.mip<<"mip)>event ph("<<event->ph.mip<<"mip)"<<endl;
00209 //      return;
00210 //    }
00211       
00212     float vtx_ph = 0;
00213     //Int_t shwnstp = shower->nstrip;
00214     Float_t plane[14];
00215     for (int i = 0; i<14; i++){
00216       plane[i] = 0;
00217     }
00218 
00219     vector<Float_t> stpph;
00220     vector<Float_t> stpph2; //for sorting purpose
00221     vector<Float_t>::iterator p;
00222     vector<Int_t> stppl;
00223     vector<Int_t> stpstp;
00224     vector<Float_t> stpt;
00225     vector<Float_t> stpz;
00226     vector<Int_t> planev;
00227 
00228     Float_t total_ph = event->ph.sigcor;
00229     Int_t vtxpl = shower->vtx.plane;
00230 //    if(ReleaseType::IsCedar(release)){
00231 //      NtpVtxFinder vtxf;
00232 //      NtpStRecord *st = dynamic_cast<NtpStRecord *>(srobj);
00233 //      vtxf.SetTargetEvent(evtn, st);
00234 //      if(vtxf.FindVertex() > 0){
00235 //      vtxpl = vtxf.VtxPlane();
00236 //      }
00237 //    }
00238     for (Int_t istp = 0; istp<shower->nstrip; istp++){
00239       Int_t index = shower->stp[istp];
00240       NtpSRStrip *strip = SntpHelpers::GetStrip(index,srobj);
00241       if(!strip) continue;
00242       float charge = strip->ph0.sigcor+strip->ph1.sigcor;
00243       // shower->stpph1mip[istp] + shower->stpph0mip[istp];
00244       if (abs(strip->plane-vtxpl)<3){
00245         vtx_ph+=charge;
00246       }
00247       stpph.push_back(charge);
00248       stpph2.push_back(charge);
00249       stppl.push_back(strip->plane);
00250       stpstp.push_back(strip->strip);
00251       stpt.push_back(strip->tpos);
00252       stpz.push_back(strip->z);
00253       planev.push_back(int(strip->planeview));
00254     }
00255 
00256     Float_t maxph = 0;
00257 
00258     Float_t maxph1 = -1;
00259     Float_t maxph2 = -1;
00260     int maxpl1 = -1;
00261     int maxpl2 = -1;
00262 
00263     for(unsigned int istp=0; istp<stpph.size(); istp++){//Loop over all strips
00264       if (stppl[istp]>=vtxpl-2&&stppl[istp]<vtxpl+12)
00265         plane[stppl[istp]-vtxpl+2] += stpph[istp];//fill plane energy information
00266       if (stpph[istp]>maxph){
00267         maxph = stpph[istp];
00268         fFracVar.shw_max = stppl[istp] - vtxpl;
00269       }
00270       if (stpph[istp]>maxph1){
00271         maxph1 = stpph[istp];
00272         maxpl1 = stppl[istp];
00273       }
00274       else if (stpph[istp]>maxph2){
00275         maxph2 = stpph[istp];
00276         maxpl2 = stppl[istp];
00277       }
00278     }
00279     if (maxpl1!=-1&&maxpl2!=-1) fFracVar.dis2stp = abs(maxpl1-maxpl2);
00280     if (fFracVar.shw_max>100) fFracVar.shw_max = -2;
00281     //I don't understand why this is happening. This should be a temporary solution.
00282     if (fFracVar.shw_max<-100) fFracVar.shw_max = -2;
00283 
00284     if (fFracVar.shw_max<0){
00285       MAXMSG("FracVarAna",Msg::kWarning,5)
00286         <<"fFracVar.shw_max<0"<<endl;
00287       fFracVar.shw_max = 0;
00288     }
00289 
00290     sort(stpph2.begin(), stpph2.end());
00291     
00292     Float_t sum_1_plane = 0,sum_2_planes = 0,sum_3_planes = 0;
00293     Float_t sum_4_planes = 0,sum_5_planes = 0,sum_6_planes = 0;
00294     Float_t sum_2_counts = 0, sum_4_counts = 0, sum_6_counts = 0;
00295     Float_t sum_8_counts = 0, sum_10_counts = 0, sum_12_counts = 0;
00296 
00297     //calculate fFracVar.fract_1_plane ...
00298     
00299     if (total_ph>0.){
00300       for (Int_t i = 0; i<14; i++){
00301         if (i<14){
00302           sum_1_plane = plane[i];
00303           if (sum_1_plane/total_ph > fFracVar.fract_1_plane) {
00304             fFracVar.fract_1_plane = sum_1_plane/total_ph;
00305           }
00306         }
00307         if (i<13){
00308           sum_2_planes = plane[i]+plane[i+1];
00309           if (sum_2_planes/total_ph > fFracVar.fract_2_planes) 
00310             fFracVar.fract_2_planes = sum_2_planes/total_ph;
00311         }
00312         if (i<12){
00313           sum_3_planes = plane[i]+plane[i+1]+plane[i+2];
00314           if (sum_3_planes/total_ph > fFracVar.fract_3_planes) 
00315             fFracVar.fract_3_planes = sum_3_planes/total_ph;
00316         }
00317         if (i<11){
00318           sum_4_planes = plane[i]+plane[i+1]+plane[i+2]+plane[i+3];
00319           if (sum_4_planes/total_ph > fFracVar.fract_4_planes) 
00320             fFracVar.fract_4_planes = sum_4_planes/total_ph;
00321         }
00322         if (i<10) {
00323           sum_5_planes = plane[i]+plane[i+1]+plane[i+2]+plane[i+3]+plane[i+4];
00324           if (sum_5_planes/total_ph > fFracVar.fract_5_planes) 
00325             fFracVar.fract_5_planes = sum_5_planes/total_ph;
00326         }
00327         if (i<9) {
00328           sum_6_planes = plane[i]+plane[i+1]+plane[i+2]+plane[i+3]+plane[i+4]+plane[i+5];
00329           if (sum_6_planes/total_ph > fFracVar.fract_6_planes) 
00330             fFracVar.fract_6_planes = sum_6_planes/total_ph;
00331         }
00332       }
00333     }//if(total_ph>0)
00334     
00335     p = stpph2.end();
00336     while (p!=stpph2.begin()&&p>stpph2.end()-12){
00337       p--;
00338       if (p>=stpph2.end()-2) sum_2_counts += *p;
00339       if (p>=stpph2.end()-4) sum_4_counts += *p;
00340       if (p>=stpph2.end()-6) sum_6_counts += *p;
00341       if (p>=stpph2.end()-8) sum_8_counts += *p;
00342       if (p>=stpph2.end()-10) sum_10_counts += *p;
00343       if (p>=stpph2.end()-12) sum_12_counts += *p;
00344       
00345       //cout<<*p<<endl;
00346     }
00347     
00348     if (total_ph>0) {
00349       fFracVar.fract_2_counters = sum_2_counts/total_ph;
00350       fFracVar.fract_4_counters = sum_4_counts/total_ph;
00351       fFracVar.fract_6_counters = sum_6_counts/total_ph;
00352       fFracVar.fract_8_counters = sum_8_counts/total_ph;
00353       fFracVar.fract_10_counters = sum_10_counts/total_ph;
00354       fFracVar.fract_12_counters = sum_12_counts/total_ph;
00355     }
00356 
00357     vector<Double_t> upos;
00358     vector<Double_t> zupos;
00359     vector<Double_t> vpos;
00360     vector<Double_t> zvpos;
00361     vector<Double_t> ucharge;
00362     vector<Double_t> vcharge;
00363     vector<Int_t> ustrip;
00364     vector<Int_t> uplane;
00365     vector<Int_t> vstrip;
00366     vector<Int_t> vplane;
00367     
00368     vector<Double_t> ufit;
00369     vector<Double_t> zufit;
00370     vector<Double_t> vfit;
00371     vector<Double_t> zvfit;
00372     vector<Double_t> ufitcharge;
00373     vector<Double_t> vfitcharge;
00374 
00375     vector<Int_t> ifitu;
00376     vector<Int_t> ifitv;
00377     
00378     vector<Double_t> ushwstrip;
00379     vector<Double_t> ushwplane;
00380     vector<Double_t> vshwstrip;
00381     vector<Double_t> vshwplane;
00382     vector<Int_t> shwplane;
00383     
00384     Double_t total_charge = 0.;
00385     
00386     Float_t toler1 = 3*0.0412;
00387     Float_t toler2 = 1.5*0.0412;
00388     
00389     Double_t thr1 = 0.05; //threshold to determine shw_beg and shw_end
00390     
00391     Int_t begplane = shower->plane.beg;
00392     Int_t endplane = shower->plane.end;
00393 
00394     if (begplane>endplane) {
00395       MAXMSG("FracVarAna",Msg::kWarning,5)
00396         <<"shower->plane.beg= "<<begplane
00397         <<"shower->plane.end= "<<endplane<<endl;
00398       return;
00399     }
00400     vector<Double_t> planeph(endplane-begplane+1);
00401     for (int i = 0; i<endplane-begplane+1; i++){
00402       planeph[i] = 0;
00403     }
00404     
00405     for (unsigned int i = 0; i<stpph.size(); i++){
00406       if (planev[i] == 2){//u view
00407         upos.push_back(stpt[i]);
00408         zupos.push_back(stpz[i]);
00409         ustrip.push_back(stpstp[i]);
00410         uplane.push_back(stppl[i]);
00411         ucharge.push_back(stpph[i]);
00412         ifitu.push_back(0);
00413       }
00414       
00415       if (planev[i] == 3){//v view
00416         vpos.push_back(stpt[i]);
00417         zvpos.push_back(stpz[i]);
00418         vstrip.push_back(stpstp[i]);
00419         vplane.push_back(stppl[i]);
00420         vcharge.push_back(stpph[i]);
00421         ifitv.push_back(0);
00422       }
00423       
00424       if (stppl[i]>=begplane&&stppl[i]<=endplane){
00425         planeph[stppl[i]-begplane] += stpph[i];
00426       }
00427       
00428       total_charge += stpph[i];
00429       
00430     }
00431     
00432     //find shower range
00433     Int_t shw_beg = 485;
00434     Int_t shw_end = 1;
00435     
00436     for (Int_t ipl = 0; ipl<endplane-begplane+1; ipl++){
00437       if (planeph[ipl]>total_charge*thr1/2 && ipl+begplane<shw_beg
00438           && ipl<endplane-begplane && planeph[ipl+1]>total_charge*thr1)
00439         shw_beg = ipl + begplane;
00440       if (planeph[ipl]>total_charge*thr1/2&&ipl+begplane>shw_end)
00441         shw_end = ipl + begplane;
00442     }
00443     
00444     if (shw_beg == 485) shw_beg = begplane;
00445     if (shw_end == 1) shw_end = endplane;
00446     //cout<<begplane<<" "<<endplane<<endl;
00447     //cout<<shw_beg<<" "<<shw_end<<endl;
00448     
00449     for (unsigned int i = 0; i<ifitu.size(); i++){
00450       if (uplane[i]>=shw_beg&&uplane[i]<=shw_end){
00451         ufit.push_back(upos[i]);
00452         zufit.push_back(zupos[i]);
00453         ufitcharge.push_back(ucharge[i]);
00454       }
00455     }
00456     
00457     for (unsigned int i = 0; i<ifitv.size(); i++){
00458       if (vplane[i]>=shw_beg&&vplane[i]<=shw_end){
00459         vfit.push_back(vpos[i]);
00460         zvfit.push_back(zvpos[i]);
00461         vfitcharge.push_back(vcharge[i]);
00462       }
00463     }
00464     
00465     //perform weighted fit of u, v vs z positions
00466     Double_t uparm[2];
00467     Double_t vparm[2];
00468     Int_t fituok = 0;
00469     Int_t fitvok = 0;
00470     
00471     if (ufit.size()) {
00472       fituok = WeightedFit(ufit.size(),&zufit[0],&ufit[0],&ufitcharge[0],&uparm[0]);
00473       //cout<<"u "<<fituok<<" "<<uparm[0]<<" "<<uparm[1]<<endl;
00474     }
00475     if (vfit.size()) {
00476       fitvok = WeightedFit(vfit.size(),&zvfit[0],&vfit[0],&vfitcharge[0],&vparm[0]);
00477       //cout<<"v "<<fitvok<<" "<<vparm[0]<<" "<<vparm[1]<<endl;
00478     }
00479     
00480     ufit.clear();
00481     zufit.clear();
00482     ufitcharge.clear();
00483     vfit.clear();
00484     zvfit.clear();
00485     vfitcharge.clear();
00486     
00487     for (unsigned int i = 0; i<ifitu.size(); i++){
00488         if (!fituok&&TMath::Abs((upos[i]-(uparm[0]+zupos[i]*uparm[1]))*cos(atan(uparm[1])))<toler1&&uplane[i]>=shw_beg&&uplane[i]<=shw_end){
00489         ifitu[i] = 1;
00490         ushwstrip.push_back(ustrip[i]+0.5);
00491         ushwplane.push_back(uplane[i]+0.5);
00492         ufit.push_back(upos[i]);
00493         zufit.push_back(zupos[i]);
00494         ufitcharge.push_back(ucharge[i]);
00495       }
00496     }
00497     
00498     for (unsigned int i = 0; i<ifitv.size(); i++){
00499         if (!fitvok&&TMath::Abs((vpos[i]-(vparm[0]+zvpos[i]*vparm[1]))*cos(atan(vparm[1])))<toler1&&vplane[i]>=shw_beg&&vplane[i]<=shw_end){
00500         ifitv[i] = 1;
00501         vshwstrip.push_back(vstrip[i]+0.5);
00502         vshwplane.push_back(vplane[i]+0.5);
00503         vfit.push_back(vpos[i]);
00504         zvfit.push_back(zvpos[i]);
00505         vfitcharge.push_back(vcharge[i]);
00506       }
00507     }
00508     
00509     for(int itr = 0; itr<2; itr++){
00510       
00511       if (ufit.size()) {
00512         fituok = WeightedFit(ufit.size(),&zufit[0],&ufit[0],&ufitcharge[0],&uparm[0]);
00513         //cout<<"u "<<fituok<<" "<<uparm[0]<<" "<<uparm[1]<<endl;
00514       }
00515       if (vfit.size()) {
00516         fitvok = WeightedFit(vfit.size(),&zvfit[0],&vfit[0],&vfitcharge[0],&vparm[0]);
00517         //cout<<"v "<<fitvok<<" "<<vparm[0]<<" "<<vparm[1]<<endl;
00518       }
00519       
00520       ushwstrip.clear();
00521       ushwplane.clear();
00522       vshwstrip.clear();
00523       vshwplane.clear();
00524       ufit.clear();
00525       zufit.clear();
00526       ufitcharge.clear();
00527       vfit.clear();
00528       zvfit.clear();
00529       vfitcharge.clear();
00530       
00531       
00532       for (unsigned int i = 0; i<ifitu.size(); i++){
00533         ifitu[i] = 0;
00534           if (!fituok&&TMath::Abs((upos[i]-(uparm[0]+zupos[i]*uparm[1]))*cos(atan(uparm[1])))<toler2&&uplane[i]>=shw_beg&&uplane[i]<=shw_end){
00535           ifitu[i] = 1;
00536           ushwstrip.push_back(ustrip[i]+0.5);
00537           ushwplane.push_back(uplane[i]+0.5);
00538           ufit.push_back(upos[i]);
00539           zufit.push_back(zupos[i]);
00540           ufitcharge.push_back(ucharge[i]);
00541           if (itr==1) {
00542             shwplane.push_back(uplane[i]);
00543             display->Fill(upos[i],zupos[i],100000,2,1);
00544           }
00545         }
00546       }
00547       
00548       for (unsigned int i = 0; i<ifitv.size(); i++){
00549         ifitv[i] = 0;
00550           if (!fitvok&&TMath::Abs((vpos[i]-(vparm[0]+zvpos[i]*vparm[1]))*cos(atan(vparm[1])))<toler2&&vplane[i]>=shw_beg&&vplane[i]<=shw_end){
00551           ifitv[i] = 1;
00552           vshwstrip.push_back(vstrip[i]+0.5);
00553           vshwplane.push_back(vplane[i]+0.5);
00554           vfit.push_back(vpos[i]);
00555           zvfit.push_back(zvpos[i]);
00556           vfitcharge.push_back(vcharge[i]);
00557           if (itr==1) {
00558             shwplane.push_back(vplane[i]);
00559             display->Fill(vpos[i],zvpos[i],100000,3,1);
00560           }
00561         }
00562       }
00563     }
00564     
00565     Double_t shwcoreph = 0;
00566     fFracVar.shw_nstp = 0;
00567     for (unsigned int i = 0; i<ufitcharge.size(); i++){
00568       shwcoreph += ufitcharge[i];
00569       fFracVar.shw_nstp ++;
00570     }
00571     for (unsigned int i = 0; i<vfitcharge.size(); i++){
00572       shwcoreph += vfitcharge[i];
00573       fFracVar.shw_nstp ++;
00574     }
00575     if (total_ph) {
00576       fFracVar.fract_road = shwcoreph/total_ph;
00577       fFracVar.vtxph = vtx_ph/total_ph;
00578     }
00579     Int_t shw_begpl = 1000;
00580     Int_t shw_endpl = 0;
00581     for (unsigned int i = 0; i<shwplane.size(); i++){
00582       if (shw_begpl>shwplane[i]) shw_begpl = shwplane[i];
00583       if (shw_endpl<shwplane[i]) shw_endpl = shwplane[i];
00584    }
00585     if (shw_endpl>=shw_begpl) fFracVar.shw_npl = shw_endpl - shw_begpl + 1;
00586 
00587     double slope = -1;
00588     if (!fituok&&!fitvok&&TMath::Abs(uparm[1])<100&&TMath::Abs(vparm[1])<100){
00589       slope = sqrt(pow(uparm[1],2)+pow(vparm[1],2));
00590     }
00591     fFracVar.shw_slp = slope;
00592     //calculate ANN pid
00593     mlpANN ann;
00594     Double_t params[14];
00595     params[0] = fFracVar.fract_1_plane;
00596     params[1] = fFracVar.fract_2_planes;
00597     params[2] = fFracVar.fract_3_planes;
00598     params[3] = fFracVar.fract_4_planes;
00599     params[4] = fFracVar.fract_5_planes;
00600     params[5] = fFracVar.fract_6_planes;
00601     params[6] = fFracVar.fract_2_counters;
00602     params[7] = fFracVar.fract_4_counters;
00603     params[8] = fFracVar.fract_6_counters;
00604     params[9] = fFracVar.fract_8_counters;
00605     params[10] = fFracVar.fract_10_counters;
00606     params[11] = fFracVar.fract_12_counters;
00607     params[12] = fFracVar.fract_road;
00608     params[13] = fFracVar.shw_max;
00609     
00610     fFracVar.pid = ann.value(0,params[0],params[1],params[2],params[3],params[4],params[5],params[6],params[7],params[8],params[9],params[10],params[11],params[12],params[13]);
00611     fFracVar.pid1 = fneuralNet->Evaluate(0,params);
00612     
00613   }//if (nshws)
00614   else {
00615     fFracVar.passcuts = 0;
00616   }
00617 }
00618 
00619 
00620 //......................................................................
00621 
00622 bool FracVarAna::LoadLargestTrackFromEvent(NtpSREvent* event,
00623                                       RecRecordImp<RecCandHeader>* record,
00624                                       int& trkidx)
00625 {
00626   bool status = false;
00627   float longest_trk = 0;
00628   for (int i=0; i<event->ntrack; i++){
00629     NtpSRTrack *track = SntpHelpers::GetTrack(event->trk[i],record);
00630     if (!track) continue;
00631     int trklen = abs(track->plane.end-track->plane.beg)+1;
00632     if (trklen>longest_trk){
00633       trkidx = event->trk[i];
00634       longest_trk = trklen;
00635     }
00636   }
00637   if (longest_trk>0){
00638     status = true;
00639   }
00640   return status;
00641 }
00642 
00643 //.....................................................................
00644 
00645 bool FracVarAna::LoadShowerAtTrackVertex(NtpSREvent* event,
00646                                     RecRecordImp<RecCandHeader>* record,
00647                                     int  trkidx,
00648                                     int& shwidx)
00649 {
00650   bool status = false;
00651   NtpSRTrack *track = SntpHelpers::GetTrack(trkidx,record);
00652   if (!track) return false;
00653   float closest_ph = 0.;
00654   float closest_vtx = 1000.;
00655   const float close_enough = 7*0.06; //about 1 interaction length
00656   for (int i=0; i<event->nshower; i++){
00657     NtpSRShower *shower = SntpHelpers::GetShower(event->shw[i],record);
00658     if (!shower) continue;
00659     float vtx_sep = TMath::Abs(shower->vtx.z-track->vtx.z);
00660 
00661     //if this is the closest shower
00662     if (vtx_sep<closest_vtx){
00663       shwidx = event->shw[i];
00664       closest_vtx = vtx_sep;
00665       if (shower->shwph.linCCgev>0) closest_ph = shower->shwph.linCCgev;
00666       else closest_ph = shower->ph.gev;
00667     }
00668     // if this isn't the closest shower but it's within close_enough m of the
00669     // track vertex and has a larger pulseheight
00670     else if(vtx_sep<close_enough && shower->ph.gev>closest_ph){
00671       shwidx = event->shw[i];
00672       closest_vtx = vtx_sep;
00673 
00674       if (shower->shwph.linCCgev>0) closest_ph = shower->shwph.linCCgev;
00675       else closest_ph = shower->ph.gev;
00676     }
00677   }
00678   if (closest_vtx<close_enough){
00679     status = true;
00680   }
00681   else shwidx = -1;
00682   return status;
00683 }
00684 
00685 //.........................................................................
00686 
00687 bool FracVarAna::LoadLargestShowerFromEvent(NtpSREvent* event,
00688                                        RecRecordImp<RecCandHeader>* record,
00689                                        int& shwidx)
00690 {
00691   bool status = false;
00692   float largest_ph = 0;
00693   for (int i=0; i<event->nshower; i++){
00694     NtpSRShower *shower = SntpHelpers::GetShower(event->shw[i],record);
00695     if (!shower) continue;
00696     if (shower->ph.gev>largest_ph){
00697       shwidx = event->shw[i];
00698       largest_ph = shower->ph.gev;
00699     }
00700   }
00701   if (largest_ph>0){
00702     status = true;
00703   }
00704   return status;
00705 }
00706 
00707 //........................................................................
00708 
00709 void FracVarAna::Draw(TPad *pad){
00710   pad->cd(1);
00711   //TLatex *t1 = new TLatex(0.5,0.5,Form("%.3f",fFracVar.fract_road));
00712   //t1->Draw();
00713   display->Draw("tpos:z","ph*(uv==2&&!core)","colz");
00714   display->Draw("tpos:z","ph*(uv==2&&core)","box same");
00715   pad->cd(2);
00716   display->Draw("tpos:z","ph*(uv==3&&!core)","colz");
00717   display->Draw("tpos:z","ph*(uv==3&&core)","box same");
00718   pad->Modified();
00719 }
00720 
00721 void FracVarAna::Print(TPad */*pad*/){
00722 }
00723                           

Generated on Mon Jun 16 14:57:14 2008 for loon by  doxygen 1.3.9.1