Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MadDpID Class Reference

#include <MadDpID.h>

List of all members.

Public Member Functions

 MadDpID ()
 ~MadDpID ()
Float_t CalcPID (MadQuantities *mb, Int_t event, Int_t method)
Float_t CalcPID (const NtpSRTrack *ntpTrack, const NtpSREvent *ntpEvent, const NtpSREventSummary *eventSummary, Detector::Detector_t det, Int_t method)
Float_t CalcPID (Float_t var1, Float_t var2, Float_t var3)
bool ReadPDFs (const char *name)
bool ChoosePDFs (const Detector::Detector_t &det, const BeamType::BeamType_t &beam, std::string recover="", std::string mcver="")
void InitPDFs (const Detector::Detector_t &det)
bool FillPDFs (MadQuantities *mb, Int_t event, Int_t method, Float_t weight=1)
void WritePDFs (const char *name)
void SetPHCorrection (double p=1.0)

Private Member Functions

void ResetPDFs ()
void CheckBinning (const Detector::Detector_t &det)
bool CalcVars (MadQuantities *mb, Int_t event, Int_t method, Float_t &var1, Float_t &var2, Float_t &var3)
bool CalcVars (const NtpSRTrack *ntpTrack, const NtpSREvent *ntpEvent, const NtpSREventSummary *eventSummary, Detector::Detector_t det, Int_t method, Float_t &var1, Float_t &var2, Float_t &var3)

Private Attributes

double ph_correction
Detector::Detector_t cache_det
BeamType::BeamType_t cache_beam
std::vector< TH1 * > fLikeliHist


Constructor & Destructor Documentation

MadDpID::MadDpID  ) 
 

Definition at line 92 of file MadDpID.cxx.

References fLikeliHist.

00092                  : 
00093   ph_correction(1.0),cache_det(Detector::kUnknown), cache_beam(BeamType::kUnknown), fLikeliHist(6){
00094   for (unsigned int i=0; i<6; i++) fLikeliHist[i]=0;
00095 }

MadDpID::~MadDpID  ) 
 

Definition at line 97 of file MadDpID.cxx.

References fLikeliHist.

00097                   {
00098   for (unsigned int i=0; i<fLikeliHist.size(); i++){
00099     if(fLikeliHist[i]) {
00100       // check that histogram really isn't in a directory
00101       // before deleting
00102       if(fLikeliHist[i]->GetDirectory()!=0){
00103         delete fLikeliHist[i];      
00104         fLikeliHist[i]=0;
00105       }
00106     }
00107   }
00108 }


Member Function Documentation

Float_t MadDpID::CalcPID Float_t  var1,
Float_t  var2,
Float_t  var3
 

Definition at line 195 of file MadDpID.cxx.

References fLikeliHist.

00196 {
00197   assert(fLikeliHist[0]); // essentially make sure file was read
00198 
00199   Float_t ProbNC = 1.;
00200   Float_t ProbCC = 1.;
00201   Float_t PidCC = 0.;
00202 
00203   Float_t prob1=fLikeliHist[0]->GetBinContent(fLikeliHist[0]->FindBin(var1));
00204   Float_t prob2=fLikeliHist[2]->GetBinContent(fLikeliHist[2]->FindBin(var2));
00205   Float_t prob3=fLikeliHist[4]->GetBinContent(fLikeliHist[4]->FindBin(var3));
00206 
00207   if (prob1==0) {prob1=0.0001;}
00208   if (prob2==0) {prob2=0.0001;}
00209   if (prob3==0) {prob3=0.0001;}
00210  
00211   ProbCC=prob1*prob2*prob3;
00212 
00213   prob1=fLikeliHist[1]->GetBinContent(fLikeliHist[1]->FindBin(var1));
00214   prob2=fLikeliHist[3]->GetBinContent(fLikeliHist[3]->FindBin(var2));
00215   prob3=fLikeliHist[5]->GetBinContent(fLikeliHist[5]->FindBin(var3));
00216  
00217   if (prob1==0) {prob1=0.0001;}
00218   if (prob2==0) {prob2=0.0001;}
00219   if (prob3==0) {prob3=0.0001;}
00220  
00221   ProbNC=prob1*prob2*prob3;
00222 
00223   PidCC=-(sqrt(-TMath::Log(ProbCC))-sqrt(-TMath::Log(ProbNC)));
00224 
00225   return PidCC;
00226 }

Float_t MadDpID::CalcPID const NtpSRTrack ntpTrack,
const NtpSREvent ntpEvent,
const NtpSREventSummary eventSummary,
Detector::Detector_t  det,
Int_t  method
 

Definition at line 183 of file MadDpID.cxx.

References CalcPID(), CalcVars(), and det.

00186 {
00187   Float_t var1, var2, var3;
00188   
00189   if(!CalcVars(ntpTrack,ntpEvent,eventSummary,det,method,var1,var2,var3) )
00190         return -10;
00191                                                                                 
00192   return CalcPID(var1, var2, var3);
00193 }

Float_t MadDpID::CalcPID MadQuantities mb,
Int_t  event,
Int_t  method
 

Definition at line 172 of file MadDpID.cxx.

References CalcVars().

Referenced by MNtpModule::Ana(), MuonRemovalInfoAna::Analyze(), ANtpAnalysisInfoAna::Analyze(), AnalysisInfoAna::Analyze(), CalcPID(), NuAnalysis::ChargeSignCut(), MadTVAnalysis::CreatePAN(), MadTestAnalysis::CreatePAN(), MadMKAnalysis::CreatePAN(), NuAnalysis::Efficiencies(), NuAnalysis::EnergySpect(), NuPIDInterface::GetDpID(), and NuAnalysis::N_1().

00173 {
00174   // calculate a PID or return -10 in case the calculation of variables
00175   // encounters an error. The -10 maintains historical convention
00176   
00177   Float_t var1,var2,var3;
00178   if(!CalcVars(mb,event,method,var1,var2,var3) ) return -10;
00179 
00180   return CalcPID(var1, var2, var3);
00181 }

bool MadDpID::CalcVars const NtpSRTrack ntpTrack,
const NtpSREvent ntpEvent,
const NtpSREventSummary eventSummary,
Detector::Detector_t  det,
Int_t  method,
Float_t &  var1,
Float_t &  var2,
Float_t &  var3
[private]
 

Definition at line 110 of file MadDpID.cxx.

References NtpSRPlane::beg, det, NtpSRPlane::end, NtpSRPlane::n, NtpSREvent::ph, NtpSRTrack::ph, ph_correction, NtpSRTrack::plane, NtpSREvent::plane, NtpSREventSummary::plane, and NtpSRPulseHeight::sigcor.

00113 {
00114   if(method != 0) return false;
00115                                                                                 
00116   var1=var2=var3=0.0;
00117   if(ntpEvent==0 || ntpTrack==0) return false;
00118   if(eventSummary == 0) return false;                                                                              
00119   // basic checks on quality of event
00120 //  if(! ntpTrack->fit.pass) return false;
00121 
00122   //Calculate the Variables
00123 /*
00124   if(! MadDpAnalysis::InFidVol(ntpHeader->GetVldContext().GetDetector(),
00125                                ntpEvent->vtx.x, ntpEvent->vtx.y,
00126                                ntpEvent->vtx.z) ) return false;
00127   */
00128   // compute variables
00129 
00130   var1=eventSummary->plane.n;
00131   if(det == Detector::kNear){
00132     var1=ntpEvent->plane.end-ntpEvent->plane.beg+1;
00133   }
00134 
00135   Float_t phtrack=ntpTrack->ph.sigcor*ph_correction;
00136   Float_t phevent=ntpEvent->ph.sigcor*ph_correction;
00137                                                                                 
00138   if (phevent>0) {var2=phtrack/phevent;}
00139                                                                                 
00140   if (ntpTrack->plane.n!=0) var3 = float(ntpTrack->ph.sigcor*ph_correction)
00141                               /float(ntpTrack->plane.n);
00142   return true;
00143 }

bool MadDpID::CalcVars MadQuantities mb,
Int_t  event,
Int_t  method,
Float_t &  var1,
Float_t &  var2,
Float_t &  var3
[private]
 

Definition at line 145 of file MadDpID.cxx.

References VldContext::GetDetector(), MadBase::GetEvent(), MadBase::GetEventSummary(), MadBase::GetHeader(), MadBase::GetLargestTrackFromEvent(), and RecHeader::GetVldContext().

Referenced by CalcPID(), and FillPDFs().

00147 {
00148   // calculate the variables used to construct the PID
00149   //
00150   // this routine should be used in PID calculation *and* to fill PDFs
00151   //
00152   // checks that the event passes certain criteria before doing the calc  
00153   // returns false in case of error, or if the event doesn't satisfy
00154   // 
00155 
00156   if(method!=0) return false;
00157   
00158   var1=var2=var3=0.0;
00159 
00160   const RecCandHeader* ntpHeader = mb->GetHeader();
00161   const NtpSREvent* ntpEvent=mb->GetEvent(event);
00162   Int_t track = -1;
00163   const NtpSRTrack* ntpTrack=mb->GetLargestTrackFromEvent(event,track);
00164   if(track==-1) return false;
00165 
00166   return CalcVars(ntpTrack, ntpEvent, mb->GetEventSummary(), 
00167                   ntpHeader->GetVldContext().GetDetector(), method, 
00168                   var1, var2, var3);
00169 }

void MadDpID::CheckBinning const Detector::Detector_t det  )  [private]
 

Definition at line 373 of file MadDpID.cxx.

References det, and fLikeliHist.

Referenced by FillPDFs().

00373                                                        {
00374   // duplicate a funny little bit of code, which rebins
00375   // one of the pdfs in reaction to the detector type
00376   TH1* evlength_cc = fLikeliHist[0];
00377   TH1* evlength_nc = fLikeliHist[1];
00378   assert(evlength_cc);
00379   assert(evlength_nc);
00380 
00381   if(det==Detector::kFar){
00382     if (evlength_cc->GetNbinsX()==60) {
00383       evlength_cc->SetBins(50,0,500);
00384       evlength_nc->SetBins(50,0,500);
00385     }
00386   }
00387   else if(det==Detector::kNear){
00388     if (evlength_cc->GetBinLowEdge(50)>200) {
00389         evlength_cc->SetBins(60,0,300);
00390         evlength_nc->SetBins(60,0,300);
00391     }
00392   }
00393   
00394 }

bool MadDpID::ChoosePDFs const Detector::Detector_t det,
const BeamType::BeamType_t beam,
std::string  recover = "",
std::string  mcver = ""
 

Definition at line 403 of file MadDpID.cxx.

References BeamType::AsString(), base, cache_beam, cache_det, det, and ReadPDFs().

Referenced by MNtpModule::Ana(), MuonRemovalInfoAna::Analyze(), ANtpAnalysisInfoAna::Analyze(), AnalysisInfoAna::Analyze(), NuAnalysis::ChargeSignCut(), MadTVAnalysis::CreatePAN(), MadMKAnalysis::CreatePAN(), NuAnalysis::Efficiencies(), NuAnalysis::EnergySpect(), NuPIDInterface::InitialiseDpID(), NuAnalysis::N_1(), and NuAnalysis::NuMuBarAppearance().

00406 {
00407   // check to see if we already have this file
00408   if(det==cache_det && beam==cache_beam){
00409     // no action is needed 
00410     return true;
00411   }
00412   if(det==Detector::kUnknown || beam==BeamType::kUnknown){
00413     return false;
00414   }
00415   std::string priv="";
00416   std::string pub="";
00417 
00418   std::string base="";
00419 
00420   priv=getenv("SRT_PRIVATE_CONTEXT");
00421   pub = getenv("SRT_PUBLIC_CONTEXT");
00422  
00423   if(priv == "" && pub == ""){
00424     std::cerr<<"No SRT_PUBLIC_CONTEXT set"<<std::endl;
00425     assert(false);
00426   }
00427 
00428   
00429   priv += "/Mad/data/";
00430   pub += "/Mad/data/";
00431 
00432   struct stat ss;
00433   if(stat(priv.c_str(), &ss) == -1) {
00434    std::cout<<"Data not present in SRT_PRIVATE_CONTEXT trying SRT_PUBLIC"<<std::endl;
00435    if(stat(pub.c_str(), &ss) == -1) {
00436      std::cout<<"Data not present in SRT_PUBLIC - doesn't seem to exist"<<std::endl;
00437       assert(false);
00438    }else{ base = pub; }
00439   }else { base = priv; }
00440 
00441   base+="dp_pdf_";
00442 
00443   if((recover==""||recover.find("birch")<recover.size()||
00444      recover.find("Birch")<recover.size()||
00445      recover.find("BIRCH")<recover.size()||
00446      recover.find("R1.18")<recover.size())&&
00447      (mcver==""||mcver.find("carrot")<mcver.size()||
00448       mcver.find("Carrot")<mcver.size()||
00449       mcver.find("CARROT")<mcver.size())){
00450     if(det==Detector::kNear){
00451       base+="near";
00452     }
00453     else if(det==Detector::kFar){
00454       base+="far";
00455     }
00456     //  else return false;
00457     
00458     if(beam==BeamType::kLE || beam==BeamType::k010){
00459       base+="_le";
00460     }
00461     else if(beam==BeamType::kME){
00462       base+="_me";
00463     }
00464     else if(beam==BeamType::kHE){
00465       base+="_he";
00466     }
00467   }
00468   else if((mcver.find("daikon")<mcver.size()||
00469           mcver.find("Daikon")<mcver.size()||
00470           mcver.find("DAIKON")<mcver.size())&&
00471           (recover.find("cedar")<recover.size()||
00472            recover.find("Cedar")<recover.size()||
00473            recover.find("CEDAR")<recover.size()||
00474            recover.find("1.24")<recover.size())){
00475     BeamType::BeamType_t tmpbeam = beam;
00476     switch(beam){
00477     case BeamType::kL010z170i: tmpbeam = BeamType::kL010z185i; break;
00478     case BeamType::kL010z200i: tmpbeam = BeamType::kL010z185i; break;
00479       //forcing le to go to le010
00480     case BeamType::kL000z200i: tmpbeam = BeamType::kL010z185i; break;
00481     case BeamType::kL010z185i_lowintensity: 
00482       tmpbeam = BeamType::kL010z185i; break;
00483       //for birch, we used le010 pdfs for the horn off running,
00484       //but, I think we should use the he since the
00485       //mean neutrino energy in the horn off running is 
00486       //higher than le, more like he.
00487     case BeamType::kL010z000i: tmpbeam = BeamType::kL250z200i; break;
00488     default: tmpbeam = beam; break;
00489     }
00490     if(det==Detector::kNear){
00491       base+="near";
00492       base+=("_"+(string)BeamType::AsString(tmpbeam));
00493     }
00494     else if(det==Detector::kFar){
00495       base+="far";
00496       if(tmpbeam==BeamType::kL250z200i){
00497         base+="_phe";
00498       }
00499       else{
00500         base+="_le";
00501       }
00502     }
00503 
00504     base+="_cedar_daikon";
00505   }
00506 
00507   //  else return false;
00508   
00509   base+=".root";
00510   if(stat(base.c_str(),&ss) == -1) {
00511     std::cerr<<"The file '"<<base<<"' doesn't seem to exist"<<std::endl;
00512     //    assert(false);
00513     return false;
00514   }
00515   cout<<"Reading pdfs from "<<base<<endl;
00516   //  assert(ReadPDFs(base.c_str()));
00517   if(ReadPDFs(base.c_str())){
00518   // set these so we don't have to reread each event
00519     cache_det=det;
00520     cache_beam=beam;    
00521     return true;
00522   }
00523   else {
00524     return false;
00525   }
00526 }

bool MadDpID::FillPDFs MadQuantities mb,
Int_t  event,
Int_t  method,
Float_t  weight = 1
 

Definition at line 331 of file MadDpID.cxx.

References CalcVars(), CheckBinning(), MadQuantities::Flavour(), fLikeliHist, VldContext::GetDetector(), MadBase::GetHeader(), MadBase::GetTruthForReco(), RecHeader::GetVldContext(), and MadQuantities::IAction().

00332                                       {
00333   
00334   // fill PDFs for this event
00335   // the code checks truth information to determine
00336   // if the event is numu-CC or NC
00337   
00338 
00339   assert(fLikeliHist[0]);// assure histograms are there
00340 
00341   Float_t var1,var2,var3;
00342   if(!CalcVars(mb,event,method,var1,var2,var3) ) return false;
00343   
00344   Int_t mcevent=-1;
00345   const NtpMCTruth* ntpTruth = mb->GetTruthForReco(event,mcevent);
00346   if(mcevent == -1  || ntpTruth==0) return false;
00347 
00348   // check binning of histograms, possibly rebin 
00349   // not in love with this bit of the code!
00350   const RecCandHeader* header = mb->GetHeader();
00351   assert(header); // something deeply wrong
00352   CheckBinning(header->GetVldContext().GetDetector());
00353   
00354   //
00355   Int_t cc_nc = mb->IAction(mcevent);
00356   Int_t flavour = mb->Flavour(mcevent);
00357   
00358   if(flavour==2 && cc_nc==1){
00359     fLikeliHist[0]->Fill(var1,weight);
00360     fLikeliHist[2]->Fill(var2,weight);
00361     fLikeliHist[4]->Fill(var3,weight);
00362   }
00363   else if(cc_nc==0) {
00364     fLikeliHist[1]->Fill(var1,weight);
00365     fLikeliHist[3]->Fill(var2,weight);
00366     fLikeliHist[5]->Fill(var3,weight);
00367   }
00368   
00369   return true;
00370 }

void MadDpID::InitPDFs const Detector::Detector_t det  ) 
 

Definition at line 278 of file MadDpID.cxx.

References det, and fLikeliHist.

00278                                                    {
00279   // create pdf histograms and assign to fLikeliHist array
00280 
00281   int nbins=60;
00282   float low=0; 
00283   float high=300;
00284   if(det==Detector::kFar){ nbins=50; low=0; high=500;}
00285   
00286   TH1F *evlength_nc = new TH1F("Event length - nc",
00287                                "Event length - nc",
00288                                nbins,low,high);
00289   evlength_nc->SetXTitle("Event length (planes)");
00290   TH1F *evlength_cc = new TH1F("Event length - cc",
00291                                "Event length - cc",
00292                                nbins,low,high);
00293   evlength_cc->SetXTitle("Event length (planes)");
00294 
00295 
00296   TH1F *phfrac_nc = new TH1F("Track ph frac - nc",
00297                                "Track ph frac - nc",
00298                                50,0,1);
00299   phfrac_nc->SetXTitle("pulse height fraction");
00300 
00301 
00302   TH1F *phfrac_cc = new TH1F("Track ph frac - cc",
00303                                "Track ph frac - cc",
00304                                50,0,1);
00305   phfrac_cc->SetXTitle("pulse height fraction");
00306 
00307 
00308   TH1F *phplane_nc = new TH1F("ph per plane (nc)",
00309                               "ph per plane (nc)",
00310                                50,0,5000);
00311   phplane_nc->SetXTitle("pulse height per plane");
00312   TH1F *phplane_cc = new TH1F("ph per plane (cc)",
00313                               "ph per plane (cc)",
00314                                50,0,5000);
00315   phplane_cc->SetXTitle("pulse height per plane");
00316 
00317 
00318   fLikeliHist[0] = evlength_cc;
00319   fLikeliHist[1] = evlength_nc;
00320   
00321   fLikeliHist[2] = phfrac_cc;
00322   fLikeliHist[3] = phfrac_nc;
00323   
00324   fLikeliHist[4] = phplane_cc;
00325   fLikeliHist[5] = phplane_nc;
00326 
00327   for (unsigned int i=0; i<fLikeliHist.size(); i++) fLikeliHist[i]->SetDirectory(0);
00328   
00329 }

bool MadDpID::ReadPDFs const char *  name  ) 
 

Definition at line 228 of file MadDpID.cxx.

References fLikeliHist, and gSystem().

Referenced by ChoosePDFs().

00228                                       {
00229   
00230 
00231   // check if this file or directory exists
00232   Long_t id,size,flags,modtime;
00233   if(gSystem->GetPathInfo(name,&id,&size,&flags,&modtime) == 1) {
00234     return false;
00235   }
00236   // check that it is a file and not a directory
00237   if(flags>1) return false;
00238   
00239 
00240   TDirectory* sd = gDirectory;
00241   TFile fLikeliFile(name,"READ");
00242   bool found=true;
00243   if(fLikeliFile.IsOpen() && !fLikeliFile.IsZombie()) { //if file is found
00244     
00245     fLikeliFile.cd();
00246     
00247     fLikeliHist[0]=dynamic_cast<TH1*>( fLikeliFile.Get("Event length - cc"));
00248     fLikeliHist[1]=dynamic_cast<TH1*>( fLikeliFile.Get("Event length - nc"));
00249     fLikeliHist[2]=dynamic_cast<TH1*>( fLikeliFile.Get("Track ph frac - cc"));
00250     fLikeliHist[3]=dynamic_cast<TH1*>( fLikeliFile.Get("Track ph frac - nc"));
00251     fLikeliHist[4]=dynamic_cast<TH1*>( fLikeliFile.Get("ph per plane (cc)"));
00252     fLikeliHist[5]=dynamic_cast<TH1*>( fLikeliFile.Get("ph per plane (nc)"));
00253     
00254     for (unsigned int i=0;i<fLikeliHist.size();i++){
00255       assert(fLikeliHist[i]);
00256       fLikeliHist[i]->SetDirectory(0); // histogram owned by this object
00257       float integ = fLikeliHist[i]->Integral(); 
00258       fLikeliHist[i]->Scale(1./integ);
00259     }
00260     std::cout<<"Read MadDpID pdfs from : "<<name<<std::endl;
00261   }
00262   else found=false;
00263   if(sd) sd->cd();
00264   return found;
00265 }

void MadDpID::ResetPDFs  )  [private]
 

Definition at line 396 of file MadDpID.cxx.

References fLikeliHist.

00396                        {
00397   for (unsigned int i=0; i<fLikeliHist.size(); i++){
00398     TH1* h = fLikeliHist[i];
00399     delete h; fLikeliHist[i]=0;
00400   }
00401 }

void MadDpID::SetPHCorrection double  p = 1.0  )  [inline]
 

Definition at line 92 of file MadDpID.h.

Referenced by MuonRemovalInfoAna::Analyze(), ANtpAnalysisInfoAna::Analyze(), AnalysisInfoAna::Analyze(), MadTVAnalysis::CreatePAN(), and MadMKAnalysis::CreatePAN().

00092 {ph_correction=p;}

void MadDpID::WritePDFs const char *  name  ) 
 

Definition at line 267 of file MadDpID.cxx.

References fLikeliHist.

00267                                        {
00268   // write histograms to a file but retain ownership with this object
00269   TDirectory* sd = gDirectory;
00270   TFile f(name,"recreate");
00271   for (unsigned int i=0; i<fLikeliHist.size(); i++){
00272     fLikeliHist[i]->Write();
00273   }
00274   if(sd) sd->cd();
00275 }


Member Data Documentation

BeamType::BeamType_t MadDpID::cache_beam [private]
 

Definition at line 107 of file MadDpID.h.

Referenced by ChoosePDFs().

Detector::Detector_t MadDpID::cache_det [private]
 

Definition at line 106 of file MadDpID.h.

Referenced by ChoosePDFs().

std::vector<TH1*> MadDpID::fLikeliHist [private]
 

Definition at line 109 of file MadDpID.h.

Referenced by CalcPID(), CheckBinning(), FillPDFs(), InitPDFs(), MadDpID(), ReadPDFs(), ResetPDFs(), WritePDFs(), and ~MadDpID().

double MadDpID::ph_correction [private]
 

Definition at line 104 of file MadDpID.h.

Referenced by CalcVars().


The documentation for this class was generated from the following files:
Generated on Mon Feb 15 11:09:27 2010 for loon by  doxygen 1.3.9.1