00001 #include <algorithm>
00002
00003 #include "StandardNtuple/NtpStRecord.h"
00004 #include "CandNtupleSR/NtpSRRecord.h"
00005 #include "CandNtupleSR/NtpSREvent.h"
00006 #include "CandNtupleSR/NtpSRTrack.h"
00007 #include "CandNtupleSR/NtpSRStrip.h"
00008 #include "MessageService/MsgService.h"
00009 #include "NueAna/NueAnaTools/SntpHelpers.h"
00010 #include "NueAna/EventQualAna.h"
00011
00012 #include "DatabaseInterface/DbiResultPtr.h"
00013 #include "DcsUser/Dcs_Mag_Near.h"
00014 #include "Mad/fddataquality.h"
00015
00016 #include "DcsUser/CoilTools.h"
00017 #include "Conventions/Munits.h"
00018 #include "Conventions/Detector.h"
00019 #include "DataUtil/PlaneOutline.h"
00020 #include "DataUtil/DataQualDB.h"
00021
00022 #include "NueAna/NueAnaTools/NueConvention.h"
00023 #include "NtupleUtils/LISieve.h"
00024 #include "NueAna/NueStandard.h"
00025
00026 CVSID("$Id: EventQualAna.cxx,v 1.7 2009/07/30 16:30:17 pawloski Exp $");
00027
00028 EventQualAna::EventQualAna(NueRecord &nr):
00029 nr(nr)
00030 {}
00031
00032 EventQualAna::~EventQualAna()
00033 {
00034
00035 }
00036
00037 void EventQualAna::Analyze(int evtn, RecRecordImp<RecCandHeader> *srobj)
00038 {
00039 NtpStRecord *st = dynamic_cast<NtpStRecord*>(srobj);
00040
00041
00042 if(st == 0) return;
00043
00044 NtpSREventSummary *eventSummary = &(st->evthdr);
00045 NtpSRDmxStatus *dmxSummary = &(st->dmxstatus);
00046 NtpSRDetStatus *detStatus = &(st->detstatus);
00047 const RecCandHeader *header = &(st->GetHeader());
00048
00049 int det = header->GetVldContext().GetDetector();
00050 SimFlag::SimFlag_t s = header->GetVldContext().GetSimFlag();
00051 VldContext vld = header->GetVldContext();
00052
00053
00054 if(s == SimFlag::kMC && evtn == -10) return;
00055
00056 nr.eventq.triggerSource = header->GetTrigSrc();
00057 nr.eventq.spillType = header->GetRemoteSpillType();
00058
00059 nr.eventq.coilStatus = detStatus->coilstatus;
00060
00061 nr.eventq.liTime = eventSummary->litime;
00062 int isLI = 0;
00063 if(nr.eventq.liTime != -1) isLI = 1;
00064 else{ isLI = (int) LISieve::IsLI((*st)); }
00065
00066 nr.eventq.passLI = 1 - isLI;
00067
00068
00069 nr.eventq.coilQuality = 0;
00070 nr.eventq.coilDirection = 0;
00071
00072 if(s != SimFlag::kMC){
00073 nr.eventq.coilQuality = CoilTools::IsOK(vld);
00074 if(CoilTools::IsReverse(vld)) nr.eventq.coilDirection = -1;
00075 else nr.eventq.coilDirection = 1;
00076 }
00077
00078
00079
00080 int dmxStatus = 0;
00081 dmxStatus += (dmxSummary->nonphysicalfail);
00082 dmxStatus += ((dmxSummary->validplanesfail<<1));
00083 dmxStatus += ((dmxSummary->vertexplanefail<<2));
00084 nr.eventq.dmxstatus = dmxStatus;
00085
00086 nr.eventq.rcBoundary = 0;
00087 if(det == Detector::kFar)
00088 {
00089 nr.eventq.rcBoundary = FDRCBoundary(eventSummary);
00090 }
00091
00092 nr.eventq.passFarDetQuality = 1;
00093 if(s != SimFlag::kMC) nr.eventq.passFarDetQuality = DataUtil::IsGoodData(st);
00094 nr.eventq.passNearDetQuality = nr.eventq.passFarDetQuality;
00095
00096
00097
00098
00099
00100
00101
00102 if(evtn == -10) return;
00103
00104 nr.eventq.passCosmicCut = NueStandard::PassesCosmicCutFunction(&nr);
00105
00106 int lgst_evt_idx=-1;
00107 float big_ph=0.0;
00108 for(int i=0;i<eventSummary->nevent;i++){
00109 NtpSREvent *evtTemp = SntpHelpers::GetEvent(i,srobj);
00110 if(evtTemp == 0) continue;
00111 if(evtTemp->ph.mip > big_ph){
00112 big_ph=evtTemp->ph.mip;
00113 lgst_evt_idx=i;
00114 }
00115 }
00116
00117 nr.eventq.isLargestEvent = 0;
00118 if(lgst_evt_idx == evtn) nr.eventq.isLargestEvent = 1;
00119
00120 NtpSREvent *event = SntpHelpers::GetEvent(evtn,st);
00121
00122
00123 Int_t edgeActivityStrips = 0;
00124 Float_t edgeActivityPH = 0;
00125 Int_t oppEdgeStrips = 0;
00126 Float_t oppEdgePH = 0;
00127
00128 Double_t thisEvtTime = 99999.;
00129
00130 Int_t thisVtxPlane = 0;
00131 Float_t thisVtxZ = 0.0;
00132 thisVtxPlane = event->vtx.plane;
00133 thisVtxZ = event->vtx.z;
00134
00135 vector<Double_t> stpTimes;
00136
00137
00138 for(int i = 0; i < event->nstrip; i++){
00139 Int_t index = SntpHelpers::GetStripIndex(i,event);
00140 NtpSRStrip *strip = SntpHelpers::GetStrip(index,srobj);
00141 if(!strip) continue;
00142
00143 if (strip->plane >= thisVtxPlane
00144 && strip->plane < (thisVtxPlane+5)) {
00145 stpTimes.push_back(strip->time1);
00146 }
00147 }
00148
00149 sort(stpTimes.begin(), stpTimes.end());
00150
00151 if(stpTimes.size() > 0){
00152
00153 if (stpTimes.size()%2)
00154 thisEvtTime = *(stpTimes.begin()+stpTimes.size()/2);
00155 else
00156 thisEvtTime = ( *(stpTimes.begin()+stpTimes.size()/2)
00157 + *(stpTimes.begin()+stpTimes.size()/2-1) )/2.;
00158
00159 Double_t timeDiff = 99999.;
00160 int nevent = eventSummary->nevent;
00161 for(int i = 0; i < nevent; ++i){
00162 NtpSREvent *evtTemp = SntpHelpers::GetEvent(i,srobj);
00163 if(evtTemp == 0) continue;
00164
00165 if (i == evtn) continue;
00166
00167 int vtxPlane = evtTemp->vtx.plane;
00168 float vtxZ = evtTemp->vtx.z;
00169
00170 Double_t evtTime = 99999.;
00171 stpTimes.clear();
00172
00173
00174 for(Int_t j = 0; j < evtTemp->nstrip; ++j){
00175 Int_t index = SntpHelpers::GetStripIndex(j,evtTemp);
00176 NtpSRStrip *strip = SntpHelpers::GetStrip(index,st);
00177 if(!strip) continue;
00178 if (strip->plane >= vtxPlane && strip->plane < (vtxPlane+5)) {
00179 stpTimes.push_back(strip->time1);
00180 }
00181 }
00182
00183 sort(stpTimes.begin(), stpTimes.end());
00184 if (stpTimes.size()%2)
00185 evtTime = *(stpTimes.begin()+stpTimes.size()/2);
00186 else
00187 evtTime= ( *(stpTimes.begin()+stpTimes.size()/2)
00188 + *(stpTimes.begin()+stpTimes.size()/2-1) )/2.;
00189
00190 Double_t deltaT = evtTime - thisEvtTime;
00191 if( TMath::Abs(deltaT) < TMath::Abs(timeDiff)) {
00192 timeDiff = deltaT;
00193 nr.eventq.closeTimeDeltaZ = thisVtxZ - vtxZ;
00194 }
00195 }
00196
00197 nr.eventq.minTimeSeparation = timeDiff;
00198
00199
00200 Double_t activityTimeStart = thisEvtTime - 4e-8;
00201 Double_t activityTimeStop = thisEvtTime + 4e-8;
00202
00203
00204 for(unsigned int i = 0; i < eventSummary->nstrip; ++i){
00205 NtpSRStrip *strip = SntpHelpers::GetStrip(i,st);
00206 if(!strip) continue;
00207
00208
00209 if (strip->time1 > activityTimeStart
00210 && strip->time1 < activityTimeStop) {
00211
00212
00213 if (strip->plane%2==1 && (strip->tpos<-0.24)
00214 && strip->plane<121) {
00215 edgeActivityStrips++;
00216 edgeActivityPH += strip->ph1.sigcor;
00217 }
00218
00219 if (strip->plane%2==1 && (strip->tpos>2.27)
00220 && strip->plane<121) {
00221 oppEdgeStrips++;
00222 oppEdgePH += strip->ph1.sigcor;
00223 }
00224
00225 if (strip->plane%2==0 && (strip->tpos>0.24)
00226 && strip->plane<121) {
00227 edgeActivityStrips++;
00228 edgeActivityPH += strip->ph1.sigcor;
00229 }
00230
00231 if (strip->plane%2==0 && (strip->tpos<-2.27)
00232 && strip->plane<121) {
00233 oppEdgeStrips++;
00234 oppEdgePH += strip->ph1.sigcor;
00235 }
00236
00237 }
00238 }
00239 }
00240 nr.eventq.edgeActivityPH = edgeActivityPH;
00241 nr.eventq.edgeActivityStrips = edgeActivityStrips;
00242 nr.eventq.oppEdgePH = oppEdgePH;
00243 nr.eventq.oppEdgeStrips = oppEdgeStrips;
00244
00245
00246
00247
00248
00249 }
00250
00251
00252 Int_t EventQualAna::FDRCBoundary(NtpSREventSummary *eventSummary){
00253 Int_t litag=0;
00254 Int_t numshower=eventSummary->nshower;
00255 Float_t allph=eventSummary->ph.raw;
00256 Int_t plbeg=eventSummary->plane.beg;
00257 Int_t plend=eventSummary->plane.end;
00258
00259 if (numshower) {
00260 if (allph>1e6) litag+=10;
00261
00262 if (((plbeg==1 || plbeg==2) && (plend==63 || plend==64)) ||
00263 ((plbeg==65 || plbeg==66) && (plend==127 || plend==128)) ||
00264 ((plbeg==129 || plbeg==130) && (plend==191 || plend==192)) ||
00265 ((plbeg==193 || plbeg==194) && (plend==247 || plend==248))) litag++;
00266 if (((plbeg==250 || plbeg==251) && (plend==312 || plend==313)) ||
00267 ((plbeg==314 || plbeg==315) && (plend==376 || plend==377)) ||
00268 ((plbeg==378 || plbeg==379) && (plend==440 || plend==441)) ||
00269 ((plbeg==442 || plbeg==443) && (plend==484 || plend==485))) litag++;
00270 }
00271 return litag;
00272 }
00273
00274