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

FilterPID.cxx

Go to the documentation of this file.
00001 
00002 // $Id: FilterPID.cxx,v 1.1 2006/09/18 21:41:22 boehm Exp $
00003 //
00004 // FILL_IN: [Document your code!!]
00005 //
00006 // vahle@hep.ucl.ac.uk
00008 #include "TH1F.h"
00009 #include "TFile.h"
00010 #include "NueAna/FilterPID.h"
00011 #include "NueAna/NueRecord.h"
00012 #include "NueAna/NuePID.h"
00013 #include "MessageService/MsgService.h"
00014 #include "MinosObjectMap/MomNavigator.h"
00015 #include "MessageService/MsgService.h"
00016 #include "JobControl/JobCModuleRegistry.h" // For JOBMODULE macro
00017 #include "HistMan/HistMan.h"
00018 JOBMODULE(FilterPID, "FilterPID",
00019           "Reads ana_nue ntuple and pid ntuple, writes out only those events that pass pid");
00020 CVSID("$Id:");
00021 //......................................................................
00022 
00023 FilterPID::FilterPID()
00024  {}
00025 
00026 //......................................................................
00027 
00028 FilterPID::~FilterPID()
00029 {}
00030 
00031 //......................................................................
00032 
00033 JobCResult FilterPID::Reco(MomNavigator* mom)
00034 {
00035    //get all NueRecords from mom 
00036    //may have more than one per go since mom reads in a snarl's worth of data
00037    //so, this is a little more complicated than just asking for a NueRecord
00038    MSG("FilterPID",Msg::kDebug)<<"***********IN ANA*****************"<<endl;
00039    
00040    TObject *obj=0;
00041    TIter objiter = mom->FragmentIter();
00042    vector<NueRecord *> vr;
00043    vector<NuePID *> vpid;
00044    while((obj=objiter.Next())){
00045       const char *cn=obj->ClassName();
00046       MSG("FilterPID",Msg::kDebug)<<"Found a "<<cn<<endl;
00047       if(strcmp(cn,"NueRecord")==0){
00048          NueRecord *nr = dynamic_cast<NueRecord *>(obj);
00049          MSG("FilterPID",Msg::kDebug)<<"Found a NueRecord in MOM"
00050                                        <<" Snarl "<<nr->GetHeader().GetSnarl()
00051                                        <<" Event "<<nr->GetHeader().GetEventNo()<<endl;
00052          vr.push_back(nr);
00053       }
00054       else if(strcmp(cn,"NuePID")==0){
00055          NuePID *npid  = dynamic_cast<NuePID *>(obj);
00056          MSG("FilterPID",Msg::kDebug)<<"Found a NuePID in MOM"
00057                                        <<" Snarl "<<npid->GetHeader().GetSnarl()
00058                                        <<" Event "<<npid->GetHeader().GetEventNo()<<endl;
00059          vpid.push_back(npid);
00060       }
00061       else{
00062          continue;
00063       }
00064    }
00065 
00066    
00067    //so, mom will match up snarls for us,
00068    //but, we have to match up events for ourselves.
00069    for(unsigned int i=0;i<vr.size();i++){
00070       int event = vr[i]->GetHeader().GetEventNo();
00071       bool foundmatch=false;
00072       for(unsigned int j=0;j<vpid.size();j++){
00073          if(vpid[j]->GetHeader().GetEventNo()==event){
00074             int pass = vpid[j]->IsNue;
00075             MSG("FilterPID",Msg::kDebug)<<"Found match!"<<endl
00076                                         <<" Record snarl: "
00077                                         <<vr[i]->GetHeader().GetSnarl()
00078                                         <<" event: "
00079                                         <<vr[i]->GetHeader().GetEventNo()<<endl
00080                                         <<" PID snarl: "
00081                                         <<vpid[j]->GetHeader().GetSnarl()
00082                                         <<" event: "
00083                                         <<vpid[j]->GetHeader().GetEventNo()<<endl;
00084             MSG("FilterPID",Msg::kDebug)<<"pass "<<pass<<" j "<<j
00085                                         <<" "<<vpid[j]->IsNue<<endl;
00086             if(pass==1){
00087               MSG("FilterPID",Msg::kDebug)<<"Gave to mom"<<endl;
00088               NueRecord *passnr = new NueRecord(*(vr[i]));
00089               //              NueHeader passh(vr[i]->GetHeader().GetVldContext());
00090               //              NueRecord *passnr = new NueRecord(passh);
00091               //              cout<<"passnr "<<passnr<<" vr[i] "<<vr[i]<<endl;
00092               //              passnr->Print();
00093               passnr->SetName("NueRecord_filt");
00094               mom->AdoptFragment(passnr);
00095               //              mom->Print();
00096             }
00097 
00098          }
00099          //delete pid from vector so we don't loop over it next time
00100          vector<NuePID *>::iterator vi(&(vpid[j]));
00101          vpid.erase(vi);
00102          foundmatch=true;
00103          break;
00104       }
00105       if(!foundmatch){
00106          MSG("FilterPID",Msg::kError)<<"Could not find PID match for"
00107                                        <<" Snarl "<<vr[i]->GetHeader().GetSnarl()
00108                                        <<" Event "<<vr[i]->GetHeader().GetEventNo()<<endl;
00109       }
00110    }
00111 
00112    MSG("FilterPID",Msg::kDebug)<<"**********************************"<<endl;
00113 
00114    return JobCResult::kPassed; // kNoDecision, kFailed, etc.
00115 }
00116 

Generated on Mon Jun 16 14:57:11 2008 for loon by  doxygen 1.3.9.1