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/AtmosShower.h"
00012 #include "AtNuEvent/AtmosShieldPlank.h"
00013 #include "MessageService/MsgService.h"
00014
00015 #include "AtNuUtils/UtilMisc.h"
00016 #include "AtNuUtils/VetoShower.h"
00017
00018 CVSID("$Id: VetoShower.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 PlankToShw::PlankToShw() {
00025 Plane = 0;
00026 Section = 0;
00027 PlankPE = 0.;
00028 DZ = 0.;
00029 DSteel = 0.;
00030 }
00031
00032 PlankToShw::PlankToShw(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 VetoShower::~VetoShower() {
00042
00043
00044
00045
00046 delete InTimePlanks;
00047 }
00048
00049 VetoShower::VetoShower() {
00050 InTimePlanks = new TClonesArray("PlankToShw");
00051 Zero();
00052 }
00053
00054 VetoShower::VetoShower(const AtmosEvent *event) {
00055 InTimePlanks = new TClonesArray("PlankToShw");
00056 Zero();
00057 Fill(event);
00058 }
00059
00060 VetoShower::VetoShower(const AtmosShower *shower,
00061 const TClonesArray *ShieldPlankList) {
00062 InTimePlanks = new TClonesArray("PlankToShw");
00063 Zero();
00064 Fill(shower, ShieldPlankList);
00065 }
00066
00067 void VetoShower::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 VetoShower::Fill(const AtmosEvent *event) {
00083
00084 const AtmosShower* shower =
00085 dynamic_cast<const AtmosShower*>(event->ShowerList->At(0));
00086 if(!shower) return;
00087
00088 if(event->NShieldPlanks == 0) return;
00089 if(!(event->ShieldPlankList)) return;
00090
00091 Fill(shower, event->ShieldPlankList);
00092 }
00093
00094 void VetoShower::Fill(const AtmosShower *shower,
00095 const TClonesArray *ShieldPlankList) {
00096 assert(shower);
00097 assert(ShieldPlankList);
00098 Zero();
00099
00100
00101
00102
00103
00104
00105 const double VtxX = shower->VtxX;
00106 const double VtxY = shower->VtxY;
00107 const double VtxZ = shower->VtxZ;
00108 const double VtxTime = shower->VtxTime;
00109
00110
00111 int vtx_section(0);
00112 if (VtxZ>0.0 && VtxZ<15) {
00113 if(VtxZ<8.5) vtx_section|=1;
00114 if(VtxZ>6.9) vtx_section|=2;
00115 }
00116 else if (VtxZ>15.5 && VtxZ<31.0) {
00117 if(VtxZ<23.9) vtx_section|=4;
00118 if(VtxZ>21.8) vtx_section|=8;
00119 }
00120
00121 const int nplanks = (int)(ShieldPlankList->GetEntries());
00122 double DTime[2] = {0., 0.};
00123 for (int iplnk=0; iplnk<nplanks; iplnk++) {
00124 const AtmosShieldPlank* plank =
00125 dynamic_cast<const AtmosShieldPlank*>
00126 (ShieldPlankList->At(iplnk));
00127 assert(plank);
00128
00129
00130 for (unsigned int iend=0; iend<2; iend++) {
00131 DTime[iend] = plank->Tcal[iend];
00132 DTime[iend] -= plank->WlsPigtail[iend]*WlsFibreN/TMath::C();
00133 DTime[iend] -= plank->ClearFibre[iend]*ClearFibreN/TMath::C();
00134 DTime[iend] -= TMath::Abs(VtxZ-plank->Z[iend])*WlsFibreN/TMath::C();
00135 }
00136
00137
00138 if ((plank->QPE[0]>0 && TMath::Abs(DTime[0]-VtxTime)<TimeWin) ||
00139 (plank->QPE[1]>0 && TMath::Abs(DTime[1]-VtxTime)<TimeWin)) {
00140 SectionQInTime[plank->Section-1] += plank->QPE[0]+plank->QPE[1];
00141
00142 if ((1<<(plank->Section-1)&(vtx_section))) {
00143 VetoQCorrSS += plank->QPE[0]+plank->QPE[1];
00144 }
00145
00146
00147
00148
00149 bool ShwUnderPlank(false);
00150 if(plank->Z[0] < plank->Z[1])
00151 ShwUnderPlank =
00152 (plank->Z[0] < VtxZ && VtxZ < plank->Z[1]);
00153 else
00154 ShwUnderPlank =
00155 (plank->Z[1] < VtxZ && VtxZ < plank->Z[0]);
00156
00157 double DZ(0.);
00158 if(!ShwUnderPlank) DZ = TMath::Min(TMath::Abs(plank->Z[0]-VtxZ),
00159 TMath::Abs(plank->Z[1]-VtxZ));
00160
00161
00162 double SteelToPlank(0.);
00163 double RP(0.);
00164 if (!ShwUnderPlank) {
00165 RP = TMath::Sqrt((DZ*DZ) +
00166 ((plank->X-VtxX)*(plank->X-VtxX)) +
00167 ((plank->X-VtxX)*(plank->X-VtxX)) );
00168 double ShwVtx[3] = {VtxX, VtxY, VtxZ};
00169 double ShwCos[3];
00170 ShwCos[0] = (plank->X-VtxX) / RP;
00171 ShwCos[1] = (plank->Y-VtxY) / RP;
00172 ShwCos[2] = (DZ) / RP;
00173 double DetVtx[3];
00174 int Side = UtilMisc::DetectorWall(ShwVtx, ShwCos, DetVtx);
00175 if (Side==9 || Side==10) {
00176 MSG("VetoShower",Msg::kDebug) << "Cross on SM Gap" << endl;
00177 }
00178 SteelToPlank = TMath::Abs((ShwVtx[2]-DetVtx[2])/ShwCos[2]);
00179 SteelToPlank = SteelToPlank * 2.54 / 5.99;
00180 }
00181
00182 new((*InTimePlanks)[NInTimePlanks++]) PlankToShw(plank, DZ, SteelToPlank);
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 }
00198 else {
00199 SectionQOutTime[plank->Section-1] += plank->QPE[0]+plank->QPE[1];
00200 }
00201 }
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 }