00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #include "VertexFinder.h"
00014 #include <Validity/VldContext.h>
00015 #include <UgliGeometry/UgliGeomHandle.h>
00016 #include <RecoBase/CandStripHandle.h>
00017 #include <CandTrackSR/CandTrackSRHandle.h>
00018 #include <CandFitTrackSR/CandFitTrackSRHandle.h>
00019 #include <Plex/PlexPlaneId.h>
00020 #include "MessageService/MsgService.h"
00021 #include "Conventions/Detector.h"
00022 #include <cmath>
00023
00024 ClassImp(VertexFinder)
00025 CVSID("$Id: VertexFinder.cxx,v 1.13 2008/09/02 22:28:49 boehm Exp $");
00026
00027
00028 VertexFinder::VertexFinder(CandEventHandle * ceh, const VldContext * vldptr)
00029 {
00030 kUVPlanesBefore = 4;
00031 kUVPlanesAfter = 5;
00032 kNoiseCut = 2.0;
00033
00034 fTotalEnergy = 0;
00035
00036 fCeh=ceh;
00037 fVld = vldptr;
00038 fX = fY = fU = fV = fPlane = 0;
00039 kNPlanes = 0;
00040
00041
00042 if(vldptr->GetDetector() == Detector::kFar)
00043 kNPlanes = 486;
00044
00045 if(vldptr->GetDetector() == Detector::kNear)
00046 kNPlanes = 285;
00047
00048 if(vldptr->GetDetector() == Detector::kCalDet)
00049 kNPlanes = 64;
00050
00051 if(kNPlanes == 0){
00052 MSG("VertexFinder",Msg::kError)
00053 <<"Detector Type is "<<vldptr->GetDetector()
00054 <<": VertexFinder only designed for work in Near or Far Det"<<endl;
00055 }
00056 }
00057
00058
00059 VertexFinder::~VertexFinder(){
00060 }
00061
00062
00063 Int_t VertexFinder::FindVertex()
00064 {
00065 if(!fCeh || kNPlanes == 0) return -1;
00066
00067 Int_t retval = FindVtxPlane();
00068 if(retval < 0) return retval;
00069 FindVtxUV();
00070
00071 if(CheckTrackInfo()) {
00072 AcceptTrackInfo();
00073 MSG("VertexFinder",Msg::kDebug)<<"Taking trk vtx"<<endl;
00074 }else{
00075 MSG("VertexFinder",Msg::kDebug)<<"Rejected trk vtx"<<endl;
00076 }
00077
00078
00079 if(fPlane>0){
00080 fPlane--;
00081 }
00082
00083 if(fPlane >=0){
00084 UgliGeomHandle ugh(*fVld);
00085 PlexPlaneId plnid(fVld->GetDetector(),fPlane,true);
00086 UgliSteelPlnHandle usph = ugh.GetSteelPlnHandle(plnid);
00087 fZ = usph.GetZ0();
00088
00089 fX = (sqrt(2.0)/2.0)*(fU - fV);
00090 fY = (sqrt(2.0)/2.0)*(fU + fV);
00091 }
00092 else return -1;
00093
00094 return 1;
00095 }
00096
00097
00098 Int_t VertexFinder::FindVtxPlane()
00099 {
00100 if(!fCeh) return -1;
00101 Int_t retval = 1;
00102
00103 fTotalEnergy = 0;
00104 Float_t trimEnergy = 0;
00105
00106 vector<Float_t> longEnergy(kNPlanes, 0);
00107 TIter stripItr(fCeh->GetDaughterIterator());
00108 while (CandStripHandle *strip =
00109 dynamic_cast<CandStripHandle*> (stripItr())) {
00110 Double_t charge = strip->GetCharge(CalDigitType::kPE);
00111 if(charge > kNoiseCut){
00112 longEnergy[strip->GetPlane()] += charge;
00113 trimEnergy += charge;
00114 }
00115 fTotalEnergy += charge;
00116 }
00117
00118 if(trimEnergy == 0){
00119 MSG("VertexFinder",Msg::kError)
00120 <<"Zero Energy event, I declare that bad"<<endl;
00121 return -5;
00122 }
00123
00124 VtxClusterList* vcl = new VtxClusterList(longEnergy, kNPlanes, kNoiseCut);
00125 fPlane = vcl->Process();
00126
00127 vcl->Clear();
00128 delete vcl;
00129
00130 return retval;
00131 }
00132
00133
00134 Int_t VertexFinder::FindVtxUV()
00135 {
00136 Int_t retval = 1;
00137
00138 Int_t nbins = 200;
00139 Float_t start = -5.0;
00140 Float_t end = 5.0;
00141
00142 TH1F *tenestu = new TH1F("tenestu","TE (U view)", nbins, start, end);
00143 TH1F *tenestv = new TH1F("tenestv","TE (V view)", nbins, start, end);
00144 TH1F *tenestuAll = new TH1F("tenestu all","TE(U)", nbins, start, end);
00145 TH1F *tenestvAll = new TH1F("tenestv all","TE(V)", nbins, start, end);
00146 TH1F *tenestuBackup = new TH1F("tenestu backup","TE(U)", nbins, start, end);
00147 TH1F *tenestvBackup = new TH1F("tenestv backup","TE(V)", nbins, start, end);
00148
00149 bool inRange = false;
00150 Float_t delta = -1;
00151
00152 TIter stripItr(fCeh->GetDaughterIterator());
00153
00154 stripItr.Reset();
00155 while (CandStripHandle *strip = dynamic_cast<CandStripHandle*>
00156 (stripItr())) {
00157 Double_t charge = strip->GetCharge(CalDigitType::kPE);
00158 MSG("VertexFinder",Msg::kDebug)<<"charge deposit:"
00159 <<charge<<" "<<strip->GetPlane()<<" "<<endl;
00160
00161 if(charge > kNoiseCut){
00162 delta = strip->GetPlane()-fPlane;
00163 inRange = false;
00164 if((delta <= 0 && fabs(delta) < kUVPlanesBefore) ||
00165 (delta >= 0 && fabs(delta) < kUVPlanesAfter)){
00166 inRange = true;
00167 }
00168
00169 if(strip->GetPlaneView()==PlaneView::kU){
00170 tenestuAll->Fill(strip->GetTPos(),charge);
00171 if(inRange) tenestu->Fill(strip->GetTPos(),charge);
00172 }
00173 else if(strip->GetPlaneView()==PlaneView::kV){
00174 tenestvAll->Fill(strip->GetTPos(),charge);
00175 if(inRange) tenestv->Fill(strip->GetTPos(),charge);
00176 }
00177 }
00178
00179 if(strip->GetPlaneView()==PlaneView::kU){
00180 tenestuBackup->Fill(strip->GetTPos(),charge);
00181 }
00182 else if(strip->GetPlaneView()==PlaneView::kV){
00183 tenestvBackup->Fill(strip->GetTPos(),charge);
00184 }
00185
00186 }
00187
00188
00189 fU = tenestu->GetMean();
00190 fV = tenestv->GetMean();
00191
00192 MSG("VertexFinder",Msg::kDebug)
00193 <<tenestu->GetMaximum()<<" "<<tenestuAll->GetMaximum()<<endl;
00194 if(tenestu->GetMaximum() < 2) fU = tenestuAll->GetMean();
00195 if(tenestv->GetMaximum() < 2) fV = tenestvAll->GetMean();
00196 if(tenestuAll->GetMaximum() < 2) fU = tenestuBackup->GetMean();
00197 if(tenestvAll->GetMaximum() < 2) fV = tenestvBackup->GetMean();
00198
00199 MSG("VertexFinder",Msg::kDebug)<<"plane guess "<<fPlane
00200 <<" U/V: "<<fU<<" "<<fV << endl;
00201
00202
00203 delete tenestu;
00204 delete tenestv;
00205 delete tenestuAll;
00206 delete tenestvAll;
00207 delete tenestuBackup;
00208 delete tenestvBackup;
00209
00210 return retval;
00211 }
00212
00213 Int_t VertexFinder::CheckTrackInfo()
00214 {
00215 CandTrackHandle * track = fCeh->GetPrimaryTrack();
00216 CandFitTrackHandle *fittrack = 0;
00217
00218 Int_t pass = 0;
00219 Int_t plane = 0;
00220 if(track){
00221 if (track->InheritsFrom("CandFitTrackHandle")) {
00222 fittrack = dynamic_cast<CandFitTrackHandle*>(track);
00223 pass = fittrack->GetPass();
00224 }
00225
00226 Float_t nTrackPlane = static_cast<Float_t>(track->GetNPlane());
00227 Float_t nTrackLike = static_cast<Float_t>(track->GetNTrackPlane());
00228 plane = TMath::Min(track->GetBegPlane(), track->GetEndPlane());
00229
00230 if(plane < 5 && nTrackPlane > 10) return 1;
00231
00232 if(pass==1){
00233 if(track->GetNPlane()>45) return 1;
00234
00235 Float_t ratio=0;
00236 if(nTrackPlane>0) ratio = nTrackLike/nTrackPlane;
00237
00238 if(track->GetNPlane() > 10 && ratio > 0.92)
00239 return 1;
00240
00241 }
00242 }
00243
00244 return 0;
00245 }
00246
00247 Int_t VertexFinder::AcceptTrackInfo()
00248 {
00249 CandTrackHandle * track = fCeh->GetPrimaryTrack();
00250 if(track == 0) {
00251 MSG("VertexFinder",Msg::kError)<<"No track present, but trying to "
00252 <<"accept track info anyway - should NOT be possible"<<endl;
00253 }
00254
00255 Int_t plane = TMath::Min(track->GetBegPlane(), track->GetEndPlane());
00256 fU = track->GetVtxU();
00257 fV = track->GetVtxV();
00258 fPlane = plane;
00259
00260 return 1;
00261 }