00001 #include <cassert>
00002 #include <math.h>
00003 #include <vector>
00004 #include <iostream>
00005
00006 #include "TString.h"
00007 #include "TFile.h"
00008 #include "TMath.h"
00009
00010 #include "AtNuEvent/AtmosEvent.h"
00011 #include "AtNuEvent/AtmosTrack.h"
00012 #include "AtNuEvent/AtmosShieldPlank.h"
00013 #include "MessageService/MsgService.h"
00014
00015 #include "AtNuUtils/UtilMisc.h"
00016 #include "AtNuUtils/VetoTrack.h"
00017
00018 CVSID("$Id: VetoTrack.cxx,v 1.4 2007/01/15 19:52:00 rhatcher Exp $");
00019
00020 const double WlsFibreN = 1.43;
00021 const double ClearFibreN = 1.6;
00022 const double TimeWin = 100e-9;
00023
00024 PlankToTrk::PlankToTrk() {
00025 Plane = 0;
00026 Section = 0;
00027 PlankPE = 0.;
00028 DZ = 0.;
00029 DSteel = 0.;
00030 }
00031
00032 PlankToTrk::PlankToTrk(const AtmosShieldPlank *plank, float dz,
00033 float dsteel) {
00034 Plane = plank->Plane;
00035 Section = plank->Section;
00036 PlankPE = plank->QPE[0] + plank->QPE[1];
00037 DZ = dz;
00038 DSteel = dsteel;
00039 }
00040
00041 VetoTrack::~VetoTrack() {
00042
00043
00044
00045
00046 delete InTimePlanks;
00047 }
00048
00049 VetoTrack::VetoTrack() {
00050 InTimePlanks = new TClonesArray("PlankToTrk");
00051 Zero();
00052 }
00053
00054 VetoTrack::VetoTrack(const AtmosEvent *event) {
00055 InTimePlanks = new TClonesArray("PlankToTrk");
00056 Zero();
00057 Fill(event);
00058 }
00059
00060 VetoTrack::VetoTrack(const AtmosTrack *track,
00061 const TClonesArray *ShieldPlankList) {
00062 InTimePlanks = new TClonesArray("PlankToTrk");
00063 Zero();
00064 Fill(track, ShieldPlankList);
00065 }
00066
00067 void VetoTrack::Zero() {
00068 memset(SectionQInTime, 0, 4*sizeof(double));
00069 memset(SectionQOutTime, 0, 4*sizeof(double));
00070
00071 VetoQCorrSS = 0;
00072
00073
00074
00075 for (int i=0; i<1+InTimePlanks->GetLast(); i++){
00076 InTimePlanks->At(i)->Clear();
00077 }
00078 InTimePlanks->Delete();
00079 NInTimePlanks = 0;
00080 }
00081
00082 void VetoTrack::Fill(const AtmosEvent *event) {
00083
00084 const AtmosTrack* track =
00085 dynamic_cast<const AtmosTrack*>(event->TrackList->At(0));
00086 if(!track) return;
00087
00088 if(event->NShieldPlanks == 0) return;
00089 if(!(event->ShieldPlankList)) return;
00090
00091 Fill(track, event->ShieldPlankList);
00092 }
00093
00094 void VetoTrack::Fill(const AtmosTrack *track,
00095 const TClonesArray *ShieldPlankList) {
00096 assert(track);
00097 assert(ShieldPlankList);
00098
00099
00100 const double VtxX = track->VtxX;
00101 const double VtxY = track->VtxY;
00102 const double VtxZ = track->VtxZ;
00103 const double VtxTime = track->VtxTime;
00104
00105
00106 int vtx_section(0);
00107 if (VtxZ>0.0 && VtxZ<15) {
00108 if(VtxZ<8.5) vtx_section|=1;
00109 if(VtxZ>6.9) vtx_section|=2;
00110 }
00111 else if (VtxZ>15.5 && VtxZ<31.0) {
00112 if(VtxZ<23.9) vtx_section|=4;
00113 if(VtxZ>21.8) vtx_section|=8;
00114 }
00115
00116 const int nplanks = (int)(ShieldPlankList->GetEntries());
00117 double DTime[2] = {0., 0.};
00118 for (int iplnk = 0; iplnk< nplanks; ++iplnk) {
00119 const AtmosShieldPlank* plank =
00120 dynamic_cast<const AtmosShieldPlank*>
00121 (ShieldPlankList->At(iplnk));
00122 assert(plank);
00123
00124
00125 for (unsigned int iend=0; iend<2; iend++) {
00126 DTime[iend] = plank->Tcal[iend];
00127 DTime[iend] -= plank->WlsPigtail[iend]*WlsFibreN/TMath::C();
00128 DTime[iend] -= plank->ClearFibre[iend]*ClearFibreN/TMath::C();
00129 DTime[iend] -= TMath::Abs(VtxZ-plank->Z[iend])*WlsFibreN/TMath::C();
00130 }
00131
00132
00133 if ((plank->QPE[0]>0 && TMath::Abs(DTime[0]-VtxTime)<TimeWin) ||
00134 (plank->QPE[1]>0 && TMath::Abs(DTime[1]-VtxTime)<TimeWin)) {
00135
00136 if ((1<<(plank->Section-1)&(vtx_section))) {
00137 VetoQCorrSS += plank->QPE[0]+plank->QPE[1];
00138 }
00139
00140 bool TrkUnderPlank(false);
00141 if(plank->Z[0] < plank->Z[1])
00142 TrkUnderPlank =
00143 (plank->Z[0] < VtxZ && VtxZ < plank->Z[1]);
00144 else
00145 TrkUnderPlank =
00146 (plank->Z[1] < VtxZ && VtxZ < plank->Z[0]);
00147
00148 double DZ(0.);
00149 if(!TrkUnderPlank) DZ = TMath::Min(TMath::Abs(plank->Z[0]-VtxZ),
00150 TMath::Abs(plank->Z[1]-VtxZ));
00151
00152
00153 double SteelToPlank(0.);
00154 double RP(0.);
00155 if (!TrkUnderPlank) {
00156 RP = TMath::Sqrt((DZ*DZ) +
00157 ((plank->X-VtxX)*(plank->X-VtxX)) +
00158 ((plank->X-VtxX)*(plank->X-VtxX)) );
00159 double TrkVtx[3] = {VtxX, VtxY, VtxZ};
00160 double TrkCos[3];
00161 TrkCos[0] = (plank->X-VtxX) / RP;
00162 TrkCos[1] = (plank->Y-VtxY) / RP;
00163 TrkCos[2] = (DZ) / RP;
00164 double DetVtx[3];
00165 int Side = UtilMisc::DetectorWall(TrkVtx, TrkCos, DetVtx);
00166 if (Side==9 || Side==10) {
00167 MSG("VetoTrack",Msg::kDebug) << "Cross on SM Gap" << endl;
00168 }
00169 SteelToPlank = TMath::Abs((TrkVtx[2]-DetVtx[2])/TrkCos[2]);
00170 SteelToPlank = SteelToPlank * 2.54 / 5.99;
00171 }
00172
00173 new((*InTimePlanks)[NInTimePlanks++]) PlankToTrk(plank, DZ, SteelToPlank);
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 }
00189 }
00190 }