00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #include <Validity/VldContext.h>
00014 #include <UgliGeometry/UgliGeomHandle.h>
00015 #include <RecoBase/CandStripHandle.h>
00016 #include <CandTrackSR/CandTrackSRHandle.h>
00017 #include <CandFitTrackSR/CandFitTrackSRHandle.h>
00018 #include <Plex/PlexPlaneId.h>
00019 #include "MessageService/MsgService.h"
00020 #include "Conventions/Detector.h"
00021
00022 #include "AnalysisNtuples/Module/ANtpRecoNtpManipulator.h"
00023 #include "StandardNtuple/NtpStRecord.h"
00024 #include "VertexFinder/Module/NtpVtxFinder.h"
00025
00026 CVSID("$Id: NtpVtxFinder.cxx,v 1.3 2007/11/11 04:58:36 rhatcher Exp $");
00027
00028
00029 NtpVtxFinder::NtpVtxFinder(int event, RecRecordImp<RecCandHeader> *srobj)
00030 {
00031 kUVPlanesBefore = 4;
00032 kUVPlanesAfter = 5;
00033 kNoiseCut = 2.0;
00034
00035 fTotalEnergy = 0;
00036
00037 fX = fY = fU = fV = fPlane = 0;
00038
00039 fEventNo = event;
00040 fSt = dynamic_cast<NtpStRecord *>(srobj);
00041 fSrObj = srobj;
00042 if(fSt)
00043 {
00044 int detType =
00045 fSt->GetHeader().GetVldContext().GetDetector();
00046
00047 if(detType == Detector::kFar)
00048 kNPlanes = 486;
00049
00050 if(detType == Detector::kNear)
00051 kNPlanes = 285;
00052 }
00053 }
00054
00055
00056 NtpVtxFinder::~NtpVtxFinder(){
00057 }
00058
00059
00060 Int_t NtpVtxFinder::FindVertex()
00061 {
00062 if(!fSt || !fSrObj) return -1;
00063
00064 ANtpRecoNtpManipulator ntpManipulator(fSt);
00065 ntpManipulator.SetPrimaryTrackCriteria(0,1,0);
00066
00067
00068 ANtpEventManipulator * ntpEventManipulator =
00069 ntpManipulator.GetEventManipulator();
00070
00071 ntpEventManipulator->SetEventInSnarl(fEventNo);
00072 fEvent = ntpEventManipulator->GetEvent();
00073 fTrack = ntpEventManipulator->GetPrimaryTrack();
00074
00075 Int_t retval = FindVtxPlane();
00076 if(retval < -1) return retval;
00077 FindVtxUV();
00078
00079 if(CheckTrackInfo()) {
00080 AcceptTrackInfo();
00081 MSG("VertexFinder",Msg::kDebug)<<"Taking trk vtx"<<endl;
00082 }else{
00083 MSG("VertexFinder",Msg::kDebug)<<"Rejected trk vtx"<<endl;
00084 }
00085
00086
00087 if(fPlane>0){
00088 fPlane--;
00089 }
00090
00091 if(fPlane >=0){
00092 VldContext vc=fSrObj->GetHeader().GetVldContext();
00093 UgliGeomHandle ugh(vc);
00094 PlexPlaneId plnid(vc.GetDetector(),fPlane,true);
00095 UgliSteelPlnHandle usph = ugh.GetSteelPlnHandle(plnid);
00096 fZ = usph.GetZ0();
00097
00098 fX = (sqrt(2.0)/2.0)*(fU - fV);
00099 fY = (sqrt(2.0)/2.0)*(fU + fV);
00100 }
00101 else return -1;
00102
00103 return 1;
00104 }
00105
00106
00107 Int_t NtpVtxFinder::FindVtxPlane()
00108 {
00109 if(!fSt) return -1;
00110 Int_t retval = 1;
00111
00112 fTotalEnergy = 0;
00113 Float_t trimEnergy = 0;
00114
00115 vector<Float_t> longEnergy(kNPlanes, 0);
00116
00117 for(int i=0;i<fEvent->nstrip;i++){
00118 Int_t index = SntpHelpers::GetStripIndex(i,fEvent);
00119 NtpSRStrip *strip = SntpHelpers::GetStrip(index,fSrObj);
00120
00121 Double_t charge = strip->ph0.pe+strip->ph1.pe;
00122
00123 if(charge > kNoiseCut){
00124 longEnergy[strip->plane] += charge;
00125 trimEnergy += charge;
00126 }
00127 fTotalEnergy += charge;
00128 }
00129
00130 MSG("VertexFinder",Msg::kDebug)
00131 <<"Total Energy in the event: "<<fTotalEnergy<<"\n"
00132 <<"Over Threshold Energy in the event: "<<trimEnergy<<endl;
00133
00134 if(trimEnergy < 40){
00135 MSG("VertexFinder",Msg::kDebug)
00136 <<"Returning due to insufficient energy"<<endl;
00137 return -5;
00138 }
00139
00140 VtxClusterList* vcl = new VtxClusterList(longEnergy, kNPlanes, kNoiseCut);
00141 fPlane = vcl->Process();
00142
00143 vcl->Clear();
00144 delete vcl;
00145
00146 return retval;
00147 }
00148
00149
00150 Int_t NtpVtxFinder::FindVtxUV()
00151 {
00152 Int_t retval = 1;
00153
00154 Int_t nbins = 200;
00155 Float_t start = -5.0;
00156 Float_t end = 5.0;
00157
00158 TH1F *tenestu = new TH1F("tenestu","TE (U view)", nbins, start, end);
00159 TH1F *tenestv = new TH1F("tenestv","TE (V view)", nbins, start, end);
00160 TH1F *tenestuAll = new TH1F("tenestu all","TE(U)", nbins, start, end);
00161 TH1F *tenestvAll = new TH1F("tenestv all","TE(V)", nbins, start, end);
00162 TH1F *tenestuBackup = new TH1F("tenestu backup","TE(U)", nbins, start, end);
00163 TH1F *tenestvBackup = new TH1F("tenestv backup","TE(V)", nbins, start, end);
00164
00165 bool inRange = false;
00166 Float_t delta = -1;
00167
00168 for(int i=0;i<fEvent->nstrip;i++){
00169 Int_t index = SntpHelpers::GetStripIndex(i,fEvent);
00170 NtpSRStrip *strip = SntpHelpers::GetStrip(index,fSrObj);
00171
00172 Double_t charge = strip->ph0.pe+strip->ph1.pe;
00173
00174 MSG("VertexFinder",Msg::kVerbose)<<"charge deposit:"
00175 <<charge<<" "<<strip->plane<<" "<<endl;
00176
00177 if(charge > kNoiseCut){
00178 delta = strip->plane-fPlane;
00179 inRange = false;
00180 if((delta <= 0 && fabs(delta) < kUVPlanesBefore) ||
00181 (delta >= 0 && fabs(delta) < kUVPlanesAfter)){
00182 inRange = true;
00183 }
00184
00185 if(strip->planeview==PlaneView::kU){
00186 tenestuAll->Fill(strip->tpos,charge);
00187 if(inRange) tenestu->Fill(strip->tpos,charge);
00188 }
00189 else if(strip->planeview==PlaneView::kV){
00190 tenestvAll->Fill(strip->tpos,charge);
00191 if(inRange) tenestv->Fill(strip->tpos,charge);
00192 }
00193 }
00194
00195 if(strip->planeview==PlaneView::kU){
00196 tenestuBackup->Fill(strip->tpos,charge);
00197 }
00198 else if(strip->planeview==PlaneView::kV){
00199 tenestvBackup->Fill(strip->tpos,charge);
00200 }
00201
00202 }
00203
00204
00205 fU = tenestu->GetMean();
00206 fV = tenestv->GetMean();
00207
00208 MSG("VertexFinder",Msg::kDebug)
00209 <<tenestu->GetMaximum()<<" "<<tenestuAll->GetMaximum()<<endl;
00210 if(tenestu->GetMaximum() < 2) fU = tenestuAll->GetMean();
00211 if(tenestv->GetMaximum() < 2) fV = tenestvAll->GetMean();
00212 if(tenestuAll->GetMaximum() < 2) fU = tenestuBackup->GetMean();
00213 if(tenestvAll->GetMaximum() < 2) fV = tenestvBackup->GetMean();
00214
00215 MSG("VertexFinder",Msg::kDebug)<<"plane guess "<<fPlane
00216 <<" U/V: "<<fU<<" "<<fV << endl;
00217
00218
00219 delete tenestu;
00220 delete tenestv;
00221 delete tenestuAll;
00222 delete tenestvAll;
00223 delete tenestuBackup;
00224 delete tenestvBackup;
00225
00226 return retval;
00227 }
00228
00229 Int_t NtpVtxFinder::CheckTrackInfo()
00230 {
00231 Int_t pass = 0;
00232 Int_t plane = 0;
00233 if(fTrack){
00234 pass = fTrack->fit.pass;
00235 Float_t nTrackPlane = static_cast<Float_t>(fTrack->plane.n);
00236 Float_t nTrackLike = static_cast<Float_t>(fTrack->plane.ntrklike);
00237 plane = TMath::Min(fTrack->plane.beg, fTrack->plane.end);
00238
00239 if(plane < 5 && nTrackPlane > 10) return 1;
00240
00241 if(pass==1){
00242 if(nTrackPlane>45) return 1;
00243
00244 Float_t ratio=0;
00245 if(nTrackPlane>0) ratio = nTrackLike/nTrackPlane;
00246
00247 if(nTrackPlane > 10 && ratio > 0.9)
00248 return 1;
00249
00250 }
00251 }
00252
00253 return 0;
00254 }
00255
00256 Int_t NtpVtxFinder::AcceptTrackInfo()
00257 {
00258 if(fTrack == 0) {
00259 MSG("VertexFinder",Msg::kError)<<"No track present, but trying to "
00260 <<"accept track info anyway - should NOT be possible"<<endl;
00261 }
00262
00263 Int_t plane = TMath::Min(fTrack->plane.beg, fTrack->plane.end);
00264 fU = fTrack->vtx.u;
00265 fV = fTrack->vtx.v;
00266 fPlane = plane;
00267
00268 return 1;
00269 }