00001 #include "StandardNtuple/NtpStRecord.h"
00002 #include "CandNtupleSR/NtpSRRecord.h"
00003 #include "CandNtupleSR/NtpSREvent.h"
00004 #include "CandNtupleSR/NtpSRShower.h"
00005 #include "CandNtupleSR/NtpSRTrack.h"
00006 #include "CandNtupleSR/NtpSRStrip.h"
00007 #include "MessageService/MsgService.h"
00008 #include "NueAna/NueAnaTools/SntpHelpers.h"
00009 #include "NueAna/ANtpShowerInfoAna.h"
00010 #include "AnalysisNtuples/Module/ANtpRecoNtpManipulator.h"
00011 #include "AnalysisNtuples/ANtpDefaultValue.h"
00012 #include "AtNuOutput/MOISolution.h"
00013 #include "DataUtil/EnergyCorrections.h"
00014 #include <cmath>
00015
00016
00017 using namespace EnergyCorrections;
00018
00019 ANtpShowerInfoAna::ANtpShowerInfoAna(ANtpShowerInfoNue &ansi):
00020 fANtpShowerInfo(ansi)
00021 {}
00022
00023 ANtpShowerInfoAna::~ANtpShowerInfoAna()
00024 {
00025 }
00026
00027
00028 void ANtpShowerInfoAna::Analyze(int evtn, RecRecordImp<RecCandHeader> *srobj)
00029 {
00030 if(srobj==0){
00031 return;
00032 }
00033 if(((dynamic_cast<NtpStRecord *>(srobj))==0)&&
00034 ((dynamic_cast<NtpSRRecord *>(srobj))==0)){
00035 return;
00036 }
00037
00038 NtpSREvent *event = 0;
00039 NtpSRShower *shower = 0;
00040 NtpSRTrack *track = 0;
00041 Detector::Detector_t det;
00042
00043
00044 bool foundst=false;
00045 NtpStRecord *st=dynamic_cast<NtpStRecord *>(srobj);
00046 fInfoFiller = new ANtpInfoObjectFiller();
00047
00048 SimFlag::SimFlag_t s = SimFlag::kUnknown;
00049
00050 if(ReleaseType::IsDogwood(release))
00051 SetCorrectionVersion(EnergyCorrections::kDogwood);
00052 if(ReleaseType::IsCedar(release))
00053 SetCorrectionVersion(EnergyCorrections::kCedar);
00054 if(ReleaseType::IsBirch(release))
00055 SetCorrectionVersion(EnergyCorrections::kBirch);
00056
00057 if(st!=0){
00058 foundst=true;
00059
00060 ANtpRecoNtpManipulator ntpManipulator(st);
00061 fInfoFiller->SetStripArray(ntpManipulator.GetStripArray());
00062
00063 event = SntpHelpers::GetEvent(evtn, st);
00064 track = SntpHelpers::GetPrimaryTrack(evtn, st);
00065 shower = SntpHelpers::GetPrimaryShower(evtn, st);
00066
00067 det = st->GetHeader().GetVldContext().GetDetector();
00068 s = st->GetHeader().GetVldContext().GetSimFlag();
00069 }
00070
00071
00072 if(!foundst){
00073 NtpSRRecord *sr=dynamic_cast<NtpSRRecord *>(srobj);
00074
00075 ANtpRecoNtpManipulator ntpManipulator(sr);
00076 fInfoFiller->SetStripArray(ntpManipulator.GetStripArray());
00077
00078
00079
00080 ntpManipulator.SetPrimaryShowerCriteria(0,1);
00081
00082
00083 ANtpEventManipulator * ntpEventManipulator =
00084 ntpManipulator.GetEventManipulator();
00085
00086 ntpEventManipulator->SetEventInSnarl(evtn);
00087 event=ntpEventManipulator->GetEvent();
00088 shower = ntpEventManipulator->GetPrimaryShower();
00089 }
00090
00091
00092 if(shower) {
00093
00094 fInfoFiller->FillShowerInformation(shower, &fANtpShowerInfo);
00095
00096 FillNueShowerInformation(shower, event, &fANtpShowerInfo,st);
00097 VldContext vc = st->GetHeader().GetVldContext();
00098
00099 fANtpShowerInfo.phCCGeV = RecoShwEnergyNew(shower, 0, vc);
00100 fANtpShowerInfo.phNCGeV = shower->shwph.linNCgev;
00101
00102 FillGapInformation(event, shower, track, st);
00103
00104 }
00105
00106 if(fInfoFiller){
00107 delete fInfoFiller;
00108 fInfoFiller=0;
00109 }
00110
00111
00112 }
00113
00114
00115 void ANtpShowerInfoAna::FillNueShowerInformation(NtpSRShower *ntpShower, NtpSREvent *ntpEvent, ANtpShowerInfoNue *showerInfoNue, RecRecordImp<RecCandHeader> *srobj)
00116 {
00117
00118 if(ntpEvent->nstrip){
00119 showerInfoNue->stripRatio=static_cast<Float_t>(ntpShower->nstrip)/static_cast<Float_t>(ntpEvent->nstrip);
00120 }
00121 if(ntpEvent->plane.n){
00122 showerInfoNue->planeRatio=static_cast<Float_t>(ntpShower->plane.n)/static_cast<Float_t>(ntpEvent->plane.n);
00123 }
00124 if(ntpEvent->ph.mip){
00125 showerInfoNue->pulseHeightRatio=ntpShower->ph.mip/ntpEvent->ph.mip;
00126 }
00127
00128 showerInfoNue->phMeu = ntpShower->ph.mip;
00129 showerInfoNue->phMip = ntpShower->ph.mip;
00130 showerInfoNue->phNueGeV = showerInfoNue->phMip/MeuPerGeV;
00131
00132
00133 vector<double> UStripsU, UStripsZ, UStripsE;
00134 vector<double> VStripsU, VStripsZ, VStripsE;
00135 for(int i=0;i<ntpShower->nstrip;i++){
00136 NtpSRStrip *strip = SntpHelpers::GetStrip(ntpShower->stp[i],srobj);
00137 float energy = ntpShower->stpph1mip[i] + ntpShower->stpph0mip[i];
00138
00139 if(!strip) continue;
00140 if(strip->planeview==2){
00141 UStripsU.push_back(strip->tpos);
00142 UStripsZ.push_back(strip->z);
00143 UStripsE.push_back(energy);
00144 }
00145 else if(strip->planeview==3){
00146 VStripsU.push_back(strip->tpos);
00147 VStripsZ.push_back(strip->z);
00148 VStripsE.push_back(energy);
00149 }
00150 }
00151
00152 MOISolution MOIUZ(UStripsU,UStripsZ,UStripsE);
00153 showerInfoNue->EValUZ0 = MOIUZ.EigenValues[0];
00154 showerInfoNue->EValUZ1 = MOIUZ.EigenValues[1];
00155 showerInfoNue->EVecUZ0[0] = MOIUZ.EigenVectors[0][0];
00156 showerInfoNue->EVecUZ1[0] = MOIUZ.EigenVectors[1][0];
00157 showerInfoNue->EVecUZ0[1] = MOIUZ.EigenVectors[0][1];
00158 showerInfoNue->EVecUZ1[1] = MOIUZ.EigenVectors[1][1];
00159
00160 MOISolution MOIVZ(VStripsU,VStripsZ,VStripsE);
00161 showerInfoNue->EValVZ0 = MOIVZ.EigenValues[0];
00162 showerInfoNue->EValVZ1 = MOIVZ.EigenValues[1];
00163 showerInfoNue->EVecVZ0[0] = MOIVZ.EigenVectors[0][0];
00164 showerInfoNue->EVecVZ1[0] = MOIVZ.EigenVectors[1][0];
00165 showerInfoNue->EVecVZ0[1] = MOIVZ.EigenVectors[0][1];
00166 showerInfoNue->EVecVZ1[1] = MOIVZ.EigenVectors[1][1];
00167
00168 return;
00169 }
00170
00171
00172
00173 Float_t ANtpShowerInfoAna::RecoShwEnergy(NtpSRShower * ntpShower, Int_t opt, Int_t det){
00174
00175 Float_t shower_ene=0;
00176 Float_t shwEtemp = GetShwEnergy(ntpShower, opt);
00177 CandShowerHandle::EShowerType type = GetShwHandleType(opt);
00178
00179 if(det==1){
00180 if(opt==-1 || opt == 4) shower_ene = shwEtemp;
00181 else{
00182 shower_ene = CorrectShowerEnergyNear(shwEtemp, type);
00183 }
00184 return shower_ene;
00185 }
00186 if(det==2){
00187 if(opt==-1 || opt == 4) shower_ene = shwEtemp;
00188 else{
00189 shower_ene = CorrectShowerEnergyFar(shwEtemp, type);
00190 }
00191 return shower_ene;
00192 }
00193 return 0;
00194 }
00195
00196 Float_t ANtpShowerInfoAna::GetShwEnergy(NtpSRShower* ntpShower, Int_t opt)
00197 {
00198 Float_t shower_ene = 0.0;
00199 if(opt==-1) shower_ene = ntpShower->ph.gev;
00200 if(opt==0) shower_ene = ntpShower->shwph.linCCgev;
00201 if(opt==1) shower_ene = ntpShower->shwph.wtCCgev;
00202 if(opt==2) shower_ene = ntpShower->shwph.linNCgev;
00203 if(opt==3) shower_ene = ntpShower->shwph.wtNCgev;
00204 if(opt==4) shower_ene = ntpShower->shwph.EMgev;
00205
00206 return shower_ene;
00207 }
00208
00209 CandShowerHandle::EShowerType ANtpShowerInfoAna::GetShwHandleType(Int_t opt)
00210 {
00211 CandShowerHandle::EShowerType type = CandShowerHandle::kCC;
00212 if(opt==0) type = CandShowerHandle::kCC;
00213 if(opt==1) type = CandShowerHandle::kWtCC;
00214 if(opt==2) type = CandShowerHandle::kNC;
00215 if(opt==3) type = CandShowerHandle::kWtCC;
00216
00217 return type;
00218 }
00219
00220
00221 Float_t ANtpShowerInfoAna::RecoShwEnergy(Float_t linearCCGeV, SimFlag::SimFlag_t s, const Detector::Detector_t& det, int mode){
00222
00223 Float_t result = 0;
00224
00225 Bool_t ok = !ANtpDefVal::IsDefault(linearCCGeV);
00226 bool isdata = (s == SimFlag::kData);
00227 if(!ok) return 0;
00228
00229
00230
00231
00232 result = linearCCGeV;
00233 if(result> 0.0 )
00234 {
00235 result = CorrectShowerEnergy(result,det,CandShowerHandle::kCC,mode,isdata);
00236 }
00237 return result;
00238
00239 }
00240
00241
00242 Float_t ANtpShowerInfoAna::RecoShwEnergyNew(NtpSRShower * ntpShower,
00243 Int_t opt, VldContext cx)
00244 {
00245 EnergyCorrections::WhichCorrection_t corrver = EnergyCorrections::kDefault;
00246 Float_t shower_ene=0;
00247
00248 if(opt==-1) shower_ene = ntpShower->ph.gev;
00249 if(opt==0) shower_ene = FullyCorrectShowerEnergy(ntpShower->shwph.linCCgev,CandShowerHandle::kCC,cx,release,corrver);
00250 if(opt==1) shower_ene = FullyCorrectShowerEnergy(ntpShower->shwph.wtCCgev,CandShowerHandle::kWtCC,cx,release,corrver);
00251 if(opt==2) shower_ene = FullyCorrectShowerEnergy(ntpShower->shwph.linNCgev,CandShowerHandle::kNC,cx,release,corrver);
00252 if(opt==3) shower_ene = FullyCorrectShowerEnergy(ntpShower->shwph.wtNCgev,CandShowerHandle::kWtNC,cx,release,corrver);
00253 if(opt==4) shower_ene = ntpShower->shwph.EMgev;
00254 return shower_ene;
00255
00256 return 0;
00257 }
00258
00259 void ANtpShowerInfoAna::FillGapInformation(NtpSREvent* , NtpSRShower *shw, NtpSRTrack* trk, NtpStRecord * st)
00260 {
00261 float planes[500];
00262 int dir[500];
00263
00264 for(int i = 0; i < 500; i++){
00265 planes[i] = dir[i] = 0;
00266 }
00267
00268 Detector::Detector_t det = st->GetHeader().GetVldContext().GetDetector();
00269
00270 for(int i = 0; i < 500; i++){
00271 if(i < 250 || det == Detector::kNear){
00272 if(i%2 == 0) dir[i] = PlaneView::kU;
00273 else dir[i] = PlaneView::kV;
00274 }else{
00275 if(i%2 == 0) dir[i] = PlaneView::kV;
00276 else dir[i] = PlaneView::kU;
00277 }
00278 }
00279 int shwendplane = shw->plane.end;
00280
00281 if(trk == 0) return;
00282 if(trk->plane.end <= shwendplane){
00283 fANtpShowerInfo.longestTrackGapU = 0;
00284 fANtpShowerInfo.longestTrackGapV = 0;
00285 fANtpShowerInfo.gapPlanesU = 0;
00286 fANtpShowerInfo.gapPlanesV = 0;
00287 fANtpShowerInfo.longestTrackGap = 0;
00288 fANtpShowerInfo.gapPlanes = 0;
00289 return;
00290 }
00291
00292 for(int i=0; i<trk->nstrip; i++){
00293 Int_t index = SntpHelpers::GetStripIndex(i,trk);
00294 NtpSRStrip *ntpStrip = SntpHelpers::GetStrip(index,st);
00295 if(ntpStrip==0) continue;
00296 if(ntpStrip->plane < shwendplane) continue;
00297 float charge = ntpStrip->ph0.sigcor + ntpStrip->ph1.sigcor;
00298 planes[ntpStrip->plane] = charge;
00299 }
00300
00301 int ucount = 0;
00302 int vcount = 0;
00303 int count = 0;
00304
00305 int longestU = 0;
00306 int longestV = 0;
00307 int longest = 0;
00308
00309 int totalU = 0;
00310 int totalV = 0;
00311
00312 bool start = true;
00313
00314 for(int i = shwendplane - 1; i < trk->plane.end + 1; i++)
00315 {
00316 if(planes[i] == 0 && start) continue;
00317
00318 if(planes[i] == 0){
00319 if(dir[i] == PlaneView::kU && !start) ucount++;
00320 if(dir[i] == PlaneView::kV && !start) vcount++;
00321 if(!start) count++;
00322 continue;
00323 }
00324
00325 if(planes[i] > 0){
00326 start = false;
00327
00328 if(dir[i] == PlaneView::kU){
00329 if(ucount > longestU) longestU = ucount;
00330 totalU += ucount;
00331 if(count > longest) longest = count;
00332 ucount = count = 0;
00333 }
00334 if(dir[i] == PlaneView::kV){
00335 if(ucount > longestV) longestV = vcount;
00336 totalV += vcount;
00337 if(count > longest) longest = count;
00338 vcount = count = 0;
00339 }
00340 }
00341 }
00342
00343 fANtpShowerInfo.longestTrackGapU = longestU;
00344 fANtpShowerInfo.longestTrackGapV = longestV;
00345 fANtpShowerInfo.gapPlanesU = totalU;
00346 fANtpShowerInfo.gapPlanesV = totalV;
00347 fANtpShowerInfo.longestTrackGap = longest;
00348 fANtpShowerInfo.gapPlanes = totalU + totalV;
00349 }