AtNuShieldNtuple Class Reference

#include <AtNuShieldNtuple.h>

List of all members.

Public Member Functions

 AtNuShieldNtuple ()
 AtNuShieldNtuple (const char *filename)
 ~AtNuShieldNtuple ()
void Reset ()
void Finish ()
int Loud ()
void Loud (int i)
bool FillEvent (const AtmosEvent *event)

Private Member Functions

void OpenFile (const char *filename)
void CloseFile ()

Private Attributes

int fLoud
TFile * fNtupleFile
TTree * fNtupleTree
ShieldEventfShieldEvent
ShieldGeomfShGeom
VldContextfVldContext

Detailed Description

Definition at line 60 of file AtNuShieldNtuple.h.


Constructor & Destructor Documentation

AtNuShieldNtuple::AtNuShieldNtuple (  ) 

Definition at line 76 of file AtNuShieldNtuple.cxx.

References fLoud, OpenFile(), and Reset().

00076                                    :
00077   fNtupleFile(0), fNtupleTree(0), fShieldEvent(0), fShGeom(0), fVldContext(0)
00078 {
00079   fLoud = 0;
00080   Reset();
00081 
00082   OpenFile("ShieldNtuple.root");
00083 }

AtNuShieldNtuple::AtNuShieldNtuple ( const char *  filename  ) 

Definition at line 85 of file AtNuShieldNtuple.cxx.

References fLoud, OpenFile(), and Reset().

00085                                                        :
00086   fNtupleFile(0), fNtupleTree(0), fShieldEvent(0), fShGeom(0), fVldContext(0)
00087 {
00088   fLoud = 0;
00089   Reset();
00090 
00091   OpenFile(filename);
00092 }

AtNuShieldNtuple::~AtNuShieldNtuple (  ) 

Definition at line 99 of file AtNuShieldNtuple.cxx.

References fLoud.

00100 {
00101   if(fLoud>=2) cout << "AtNuShieldNtuple::~AtNuShieldNtuple" << endl;
00102 }


Member Function Documentation

void AtNuShieldNtuple::CloseFile (  )  [private]

Definition at line 115 of file AtNuShieldNtuple.cxx.

References fNtupleFile, and fNtupleTree.

Referenced by Finish().

00116 {
00117   TDirectory* tmpd = gDirectory;
00118   fNtupleFile->cd();
00119   fNtupleTree->Write();
00120   fNtupleFile->Close();
00121   gDirectory = tmpd;
00122 }

bool AtNuShieldNtuple::FillEvent ( const AtmosEvent event  ) 

Definition at line 124 of file AtNuShieldNtuple.cxx.

References C, AtmosShieldPlank::ClearFibre, MuELoss::e, fClearFibreN, fLoud, fNtupleTree, fShieldEvent, fVldContext, fWlsFibreN, SimFlag::kData, Detector::kFar, ShieldEvent::MapPMTPE, ShieldEvent::MaxNPlanks100nsWin, ShieldEvent::MeanNPlanks100nsWin, ShieldEvent::MeanPlankEndPE, ShieldEvent::MeanPlankEndTime, ShieldEvent::MeanQPlankEndTime, AtmosEvent::NanoSec, ShieldEvent::NanoSec, AtmosShieldPlank::Plane, AtmosShieldPlank::QPE, ShieldEvent::Reset(), ShieldEvent::RMSPlankEndPE, ShieldEvent::RMSPlankEndTime, ShieldEvent::RMSQPlankEndTime, ShieldEvent::Run, AtmosShieldPlank::Section, ShieldEvent::ShieldDigits, ShieldEvent::ShieldPE, ShieldEvent::ShieldPlanks, UtilShield::ShieldPMTId(), ShieldEvent::ShieldTimeSpread, ShieldEvent::Snarl, ShieldEvent::SubRun, AtmosShieldPlank::Tcal, ShieldEvent::UnixTime, AtmosEvent::UnixTime, and AtmosShieldPlank::WlsPigtail.

00125 {
00126   assert(event);
00127 
00128   if(fLoud>=3) cout << "AtNuShieldNtuple::FillEvent" << endl;
00129 
00130   fShieldEvent->Reset();
00131 
00132   fShieldEvent->UnixTime = event->UnixTime;
00133   fShieldEvent->NanoSec = event->NanoSec;
00134 
00135   fShieldEvent->Run = event->Run;
00136   fShieldEvent->SubRun = event->SubRun;
00137   fShieldEvent->Snarl = event->Snarl;
00138 
00139   VldTimeStamp vtime(event->UnixTime, event->NanoSec);
00140   fVldContext = new VldContext(Detector::kFar, SimFlag::kData, vtime);
00141 
00142   double MinPlankTime[5] = {1.0, 1.0, 1.0, 1.0, 1.0};
00143   double MaxPlankTime[5] = {-1.0, -1.0, -1.0, -1.0, -1.0};
00144   std::vector<double> vPlankDTime;
00145 
00146   for (int iplk=0; iplk<event->ShieldPlankList->GetLast()+1; iplk++) {
00147     const AtmosShieldPlank *plank = dynamic_cast<const AtmosShieldPlank*>
00148       (event->ShieldPlankList->At(iplk));
00149 
00150     //Such a plank shouldn't be written to file, but skip in case
00151     if(plank->QPE[0] == 0 && plank->QPE[1] == 0) continue;
00152 
00153     fShieldEvent->ShieldPlanks[0]++;
00154     fShieldEvent->ShieldPlanks[plank->Section]++;
00155 
00156     fShieldEvent->ShieldPE[0] += plank->QPE[0] + plank->QPE[1];
00157     fShieldEvent->ShieldPE[plank->Section] += plank->QPE[0] + plank->QPE[1];
00158 
00159     for (unsigned int iend=0; iend<2; iend++) {
00160       if(plank->QPE[iend] == 0) continue;
00161 
00162       fShieldEvent->ShieldDigits[0]++;
00163       fShieldEvent->ShieldDigits[plank->Section]++;
00164 
00165       double PlankEndPE = plank->QPE[iend];
00166       fShieldEvent->MeanPlankEndPE[0] += PlankEndPE;
00167       fShieldEvent->MeanPlankEndPE[plank->Section] += PlankEndPE;
00168       fShieldEvent->RMSPlankEndPE[0] += PlankEndPE*PlankEndPE;
00169       fShieldEvent->RMSPlankEndPE[plank->Section] += PlankEndPE*PlankEndPE;
00170 
00171       double DTime = plank->Tcal[iend];
00172       DTime -= plank->WlsPigtail[iend]*fWlsFibreN/TMath::C();
00173       DTime -= plank->ClearFibre[iend]*fClearFibreN/TMath::C();
00174 
00175       vPlankDTime.push_back(DTime);
00176 
00177       fShieldEvent->MeanPlankEndTime[0] += DTime;
00178       fShieldEvent->MeanPlankEndTime[plank->Section] += DTime;
00179       fShieldEvent->RMSPlankEndTime[0] += DTime*DTime;
00180       fShieldEvent->RMSPlankEndTime[plank->Section] += DTime*DTime;
00181 
00182       fShieldEvent->MeanQPlankEndTime[0] += PlankEndPE*DTime;
00183       fShieldEvent->MeanQPlankEndTime[plank->Section] += PlankEndPE*DTime;
00184       fShieldEvent->RMSQPlankEndTime[0] += PlankEndPE*DTime*DTime;
00185       fShieldEvent->RMSQPlankEndTime[plank->Section] += PlankEndPE*DTime*DTime;
00186 
00187       if(DTime < MinPlankTime[0]) MinPlankTime[0] = DTime;
00188       if(DTime < MinPlankTime[plank->Section])
00189         MinPlankTime[plank->Section] = DTime;
00190 
00191       if(DTime > MaxPlankTime[0]) MaxPlankTime[0] = DTime;
00192       if(DTime > MaxPlankTime[plank->Section])
00193         MaxPlankTime[plank->Section] = DTime;
00194 
00195       short PMTId = UtilShield::ShieldPMTId(plank->Plane);
00196       PMTId += iend<<5;
00197 
00198       fShieldEvent->MapPMTPE[PMTId] += PlankEndPE;
00199     }
00200   }
00201 
00202   for (int isect=0;isect<=4; isect++) {
00203 
00204     fShieldEvent->ShieldTimeSpread[isect] = 
00205       MaxPlankTime[isect] - MinPlankTime[isect];
00206 
00207     if (fShieldEvent->ShieldDigits[isect]>0) {
00208       fShieldEvent->MeanPlankEndPE[isect] /=
00209         fShieldEvent->ShieldDigits[isect];
00210 
00211       fShieldEvent->MeanPlankEndTime[isect] /=
00212         fShieldEvent->ShieldDigits[isect];
00213 
00214       if (fShieldEvent->ShieldDigits[isect]>1) {
00215         fShieldEvent->RMSPlankEndPE[isect] =
00216           ((fShieldEvent->RMSPlankEndPE[isect] / 
00217             fShieldEvent->ShieldDigits[isect]) -
00218            (fShieldEvent->MeanPlankEndPE[isect] *
00219             fShieldEvent->MeanPlankEndPE[isect]));
00220         if(fShieldEvent->RMSPlankEndPE[isect] <= 0.0)
00221           fShieldEvent->RMSPlankEndPE[isect] = 0.0;
00222         else fShieldEvent->RMSPlankEndPE[isect] =
00223           sqrt(fShieldEvent->RMSPlankEndPE[isect]);
00224 
00225         fShieldEvent->RMSPlankEndTime[isect] =
00226           ((fShieldEvent->RMSPlankEndTime[isect]/
00227             fShieldEvent->ShieldDigits[isect]) -
00228            (fShieldEvent->MeanPlankEndTime[isect] *
00229             fShieldEvent->MeanPlankEndTime[isect]));
00230         if(fShieldEvent->RMSPlankEndTime[isect] <= 0.0)
00231           fShieldEvent->RMSPlankEndTime[isect] = 0.0;
00232         else fShieldEvent->RMSPlankEndTime[isect] =
00233           sqrt(fShieldEvent->RMSPlankEndTime[isect]);
00234       }
00235     }
00236 
00237     if (fShieldEvent->ShieldPE[isect]>0) {
00238       fShieldEvent->MeanQPlankEndTime[isect] /=
00239         fShieldEvent->ShieldPE[isect];
00240       if (fShieldEvent->ShieldPE[isect]>1) {
00241         fShieldEvent->RMSQPlankEndTime[isect] =
00242           ((fShieldEvent->RMSQPlankEndTime[isect] /
00243             fShieldEvent->ShieldPE[isect]) -
00244            (fShieldEvent->MeanQPlankEndTime[isect] *
00245             fShieldEvent->MeanQPlankEndTime[isect]));
00246         if(fShieldEvent->RMSQPlankEndTime[isect] <= 0.0)
00247           fShieldEvent->RMSQPlankEndTime[isect] = 0.0;
00248         else fShieldEvent->RMSQPlankEndTime[isect] =
00249           sqrt(fShieldEvent->RMSQPlankEndTime[isect]);
00250       }
00251     }
00252   }
00253 
00254   int MaxNPlanks100nsWin = 0;
00255   double MeanNPlanks100nsWin(0.0), N100nsWindows(0.0);
00256   std::sort(vPlankDTime.begin(), vPlankDTime.end());
00257   for (unsigned int idt=0; idt<vPlankDTime.size(); idt++) {
00258     double PlankTimeWin = vPlankDTime[idt]+100e-9;
00259     int NPlanks100nsWin = 1;//Count the first plank
00260     unsigned int jdt;
00261     for (jdt=idt+1; jdt<vPlankDTime.size(); jdt++) {
00262       if(vPlankDTime[jdt] < PlankTimeWin) NPlanks100nsWin++;
00263       else break;
00264     }
00265     N100nsWindows += 1.0;
00266     MeanNPlanks100nsWin += NPlanks100nsWin;
00267     if(NPlanks100nsWin>MaxNPlanks100nsWin) MaxNPlanks100nsWin=NPlanks100nsWin;
00268 
00269     //break if the inner loop hit the end of the vector
00270     if(jdt == vPlankDTime.size()) break;
00271 
00272     if(NPlanks100nsWin == 1 && (idt+1) < vPlankDTime.size()) {
00273       N100nsWindows += ((vPlankDTime[idt+1]-vPlankDTime[idt])/100e-9) - 1.0;
00274     }
00275   }
00276 
00277 
00278   fShieldEvent->MaxNPlanks100nsWin[0] = MaxNPlanks100nsWin;
00279   if (N100nsWindows>0.0) {
00280     fShieldEvent->MeanNPlanks100nsWin[0] = MeanNPlanks100nsWin/N100nsWindows;
00281   }
00282 
00283   /*
00284   //Alternate method to measure the MeanPlankEnds in a 100nsWindow
00285   int iWindow = 1;
00286   double T0 = *(vPlankDTime.begin());
00287   double TF = *(vPlankDTime.rbegin());
00288   MeanNPlanks100nsWin = 0.0;
00289   N100nsWindows = 0.0;
00290   while ((T0+iWindow*100e-9) < TF) {
00291     N100nsWindows += 1.0;
00292     int NPlanks100nsWin = 
00293     std::count_if(vPlankDTime.begin(), vPlankDTime.end(),
00294       __gnu_cxx::compose2(std::logical_and<bool>(),
00295         std::bind2nd(std::greater_equal<double>(), T0+iWindow*100e-9),
00296         std::bind2nd(std::less_equal<double>(), T0+(iWindow+1)*100e-9)));
00297 
00298     MeanNPlanks100nsWin += NPlanks100nsWin;
00299 
00300     iWindow++;
00301   }
00302   */
00303 
00304   fNtupleTree->Fill();
00305   return true;
00306 }

void AtNuShieldNtuple::Finish (  ) 

Definition at line 308 of file AtNuShieldNtuple.cxx.

References CloseFile(), and fLoud.

00309 {
00310   if(fLoud>1) cout << "AtNuShieldNtuple::Finish" << endl;
00311 
00312   CloseFile();
00313 }

void AtNuShieldNtuple::Loud ( int  i  )  [inline]

Definition at line 71 of file AtNuShieldNtuple.h.

References fLoud.

00071 {fLoud=i;}

int AtNuShieldNtuple::Loud (  )  [inline]

Definition at line 70 of file AtNuShieldNtuple.h.

References fLoud.

00070 {return fLoud;}

void AtNuShieldNtuple::OpenFile ( const char *  filename  )  [private]

Definition at line 104 of file AtNuShieldNtuple.cxx.

References fNtupleFile, fNtupleTree, and fShieldEvent.

Referenced by AtNuShieldNtuple().

00105 {
00106   TDirectory* tmpd = gDirectory;
00107   fNtupleFile = new TFile(filename, "RECREATE");
00108   fNtupleTree = new TTree("ntuple", "shield analysis ntuple");
00109   fNtupleTree->SetDirectory(fNtupleFile);
00110   fShieldEvent = new ShieldEvent();
00111   fNtupleTree->Branch("evt", "ShieldEvent", &fShieldEvent);
00112   gDirectory = tmpd;
00113 }

void AtNuShieldNtuple::Reset (  ) 

Definition at line 94 of file AtNuShieldNtuple.cxx.

References fLoud.

Referenced by AtNuShieldNtuple().

00095 {
00096   if(fLoud>=2) cout << "AtNuShieldNtuple::Reset" << endl;
00097 }


Member Data Documentation

int AtNuShieldNtuple::fLoud [private]

Definition at line 80 of file AtNuShieldNtuple.h.

Referenced by AtNuShieldNtuple(), FillEvent(), Finish(), Loud(), Reset(), and ~AtNuShieldNtuple().

Definition at line 82 of file AtNuShieldNtuple.h.

Referenced by CloseFile(), and OpenFile().

Definition at line 83 of file AtNuShieldNtuple.h.

Referenced by CloseFile(), FillEvent(), and OpenFile().

Definition at line 86 of file AtNuShieldNtuple.h.

Definition at line 84 of file AtNuShieldNtuple.h.

Referenced by FillEvent(), and OpenFile().

Definition at line 87 of file AtNuShieldNtuple.h.

Referenced by FillEvent().


The documentation for this class was generated from the following files:

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1