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

MiniMaker.cxx

Go to the documentation of this file.
00001 #include "MiniMaker.h"
00002 #include "NueAna/NueStandard.h"
00003 #include "NueAna/NueMiniAna.h"
00004 #include "NueAna/NueMini.h"
00005 
00006 MiniMaker::MiniMaker(){ 
00007   outSet = false;
00008   fReweight = false;
00009   fBaseline = 735;
00010   fDeltaMSquare = 0.0027;
00011   fUe3Square = 0.025;
00012   fTheta23 = TMath::Pi()/4;
00013 
00014   fOverWritePOT = false;
00015 }
00016 
00017 void MiniMaker::AddFiles(string infiles)
00018 {
00019    files.push_back(infiles);
00020 }
00021 
00022 void MiniMaker::SetOutputFile(string file)
00023 {
00024    outSet = true;
00025    outFile = file;
00026 }   
00027 
00028 void MiniMaker::Config(Registry &r)
00029 {
00030   fCuts.Config(r);
00031 }
00032 
00033 void MiniMaker::SetDeltaMSquare(double dm2) { fDeltaMSquare = dm2; fReweight = true;}
00034 void MiniMaker::SetUe3Square(double dUe32) { fUe3Square = dUe32; fReweight = true;}
00035 void MiniMaker::SetTheta23(double t23) { fTheta23 = t23; fReweight = true;}
00036 void MiniMaker::SetBaseline(double bl) { fBaseline = bl; fReweight = true;}
00037 
00038 void MiniMaker::RunMiniMaker()
00039 {
00040   NueRecord *nr = new NueRecord();
00041   NuePOT *np = new NuePOT();
00042   NuePOT *total = new NuePOT();
00043 
00044   TChain *chain = new TChain("ana_nue");
00045   chain->SetBranchAddress("NueRecord",&nr);
00046                                                                         
00047   TChain *pchain = new TChain("pottree");
00048   pchain->SetBranchAddress("NuePOT", &np);
00049  
00050   for(unsigned int i = 0; i < files.size(); i++)
00051   {
00052       chain->Add(files[i].c_str());
00053       pchain->Add(files[i].c_str());
00054   }
00055   
00056   if(!outSet){
00057      string file;
00058                                                                         
00059      if(pchain->GetEntries() > 0){
00060         pchain->GetEntry(0);
00061         total->beamtype = np->beamtype;
00062         file = pchain->GetFile()->GetName();
00063      }
00064      string minifile = file.substr(file.find_last_of("/")+1, file.find_last_of(".root")-file.find_last_of("/") - 5);
00065      minifile += "-Mini.root";
00066   
00067      outFile = minifile;
00068   }
00069   if(outFile == "-Mini.root"){
00070      cout<<"No input file found"<<endl; 
00071      return;
00072   }
00073                                                                          
00074   cout<<"Setting output to "<<outFile<<endl;
00075 
00076   // And now the actual looping
00077                                                                                 
00078   TFile *save = new TFile(outFile.c_str(),"RECREATE");
00079   save->SetCompressionLevel(9);
00080   save->cd();
00081   TTree *tree = new TTree("NueMini","NueMini");
00082   TTree::SetBranchStyle(1);
00083 
00084   if(chain->GetEntries() > 0) chain->GetEvent(0);
00085   Detector::Detector_t det = nr->GetHeader().GetVldContext().GetDetector();
00086   ReleaseType::Release_t rel = nr->GetHeader().GetRelease();
00087   BeamType::BeamType_t beam = nr->GetHeader().GetBeamType();
00088                                                                                 
00089   NueMiniAna nma;
00090                                                                                 
00091   NueMini* nm = new NueMini(beam, det, rel);
00092 
00093   TBranch* br = tree->Branch("NueMini","NueMini", &nm );
00094   br->SetAutoDelete(kFALSE);
00095                                                                         
00096   Int_t n = chain->GetEntries();
00097   int count = 0;
00098 
00099   bool isMC = false;
00100   double TotPOT = 0.0;
00101 
00102   for(int i=0;i<n;i++){
00103     if(i%10000==0) cout << 100*float(i)/float(n)
00104                        << "% done" << endl;
00105     chain->GetEvent(i);
00106 
00107     if(i == 0){
00108       SimFlag::SimFlag_t sim = nr->GetHeader().GetVldContext().GetSimFlag();
00109       isMC = (sim == SimFlag::kMC);
00110     }       
00111 
00112     if(NueStandard::PassesDataQuality(nr)) {
00113        if(nr->GetHeader().GetEventNo() == 0 ||
00114              nr->GetHeader().GetEvents() == 0){
00115           TotPOT += nr->bmon.bI;
00116           if(nr->bmon.bI < 0 && !isMC) cout<<"Unexpected behavior"<<endl;
00117        }
00118     }
00119 
00120     if(EvaluateCuts(nr)){
00121        if(fReweight && nr->mctrue.nuFlavor > -10)
00122        {
00123           int nuFlavor = nr->mctrue.nuFlavor;
00124           int  nonOsc = nr->mctrue.nonOscNuFlavor;
00125           float energy = nr->mctrue.nuEnergy;
00126                                                                                 
00127           Float_t newWeight = NueConvention::Oscillate(nuFlavor, nonOsc, energy,                                735, fDeltaMSquare, fTheta23, fUe3Square);
00128                                                                                 
00129           nr->mctrue.Ue3Squared = fUe3Square;
00130           nr->mctrue.DeltamSquared23 = fDeltaMSquare;
00131           nr->mctrue.Theta23  = fTheta23;
00132           nr->mctrue.fOscProb = newWeight;
00133        }
00134        nma.FillMini(nr, nm);
00135 
00136        tree->Fill();
00137        count++;
00138     }
00139 #ifdef DEBUG_OUTPUT
00140     else{
00141       float x = nr->srevent.vtxX;
00142       float y = nr->srevent.vtxY;
00143       float r = TMath::Sqrt(x*x+y*y);
00144 
00145       cout<<"rejecting event"<<x<<"  "<<y<<"  "<<r<<"  "
00146           <<nr->srevent.vtxZ<<"  "
00147           <<NueStandard::PassesSelection(nr, Selection::kDataQual)
00148           <<"  "<<NueStandard::PassesSelection(nr, Selection::kFid)<<endl;
00149 
00150     }
00151 #endif
00152   }
00153   cout<<count<<" of "<<n<<" entries were passed"<<endl;
00154                                                                         
00155   TTree *ptree = new TTree("pottree","pottree");
00156   TBranch* br2 = ptree->Branch("NuePOT","NuePOT", &total );
00157   br2->SetAutoDelete(kFALSE);
00158                                                                         
00159   for(int i = 0; i < pchain->GetEntries(); i++)
00160   {
00161      pchain->GetEntry(i);
00162                                                                         
00163      if(total->beamtype != np->beamtype)
00164         cerr<<"You are merging files of different beamtyp - BAD"<<endl;
00165                                                                         
00166      total->nruns +=  np->nruns;
00167      total->nsnarls +=  np->nsnarls;
00168      total->pot += np->pot;
00169   }
00170 
00171   if(fOverWritePOT && !isMC) total->pot = TotPOT;
00172 
00173   ptree->Fill();
00174                                                                         
00175   save->cd();
00176   tree->Write();
00177   ptree->Write();
00178   
00179   cout<<"Compression level of output file "<<save->GetCompressionLevel()<<"\n";
00180   
00181   cout<<"Trimming completed with "<<total->pot<<"x10^12 POT"<<endl;
00182 }
00183 
00184 void MiniMaker::SetCuts(string type, int level)
00185 {
00186    cutSet = type;
00187    cutLevel = level;   
00188 }
00189 
00190 bool MiniMaker::EvaluateCuts(NueRecord *nr)
00191 {
00192    NueConvention::NueEnergyCorrection(nr);  
00193 
00194    if(cutSet == "Fiducial") 
00195      return NueStandard::PassesSelection(nr, Selection::kFid);
00196 
00197    if(cutSet == "Standard"){
00198       bool ret;
00199       switch(cutLevel){
00200         case 0: return NueStandard::PassesSelection(nr, Selection::kDataQual);
00201         case 1: return NueStandard::PassesSelection(nr, Selection::kFid);
00202         case 2: 
00203              ret = NueStandard::PassesSelection(nr, Selection::kFid);
00204              ret = ret &&  NueStandard::PassesNonHEPreSelection(nr);
00205              return ret;
00206         case 3: return NueStandard::PassesSelection(nr, Selection::kPre);
00207       }
00208    }
00209    if(cutSet == "MRE" || cutSet == "MRCC"){
00210       bool dq = NueStandard::PassesSelection(nr, Selection::kDataQual);
00211       bool mrefid = NueStandard::PassesMREFiducial(nr);
00212       bool mrepre = NueStandard::PassesMREPreSelection(nr) && mrefid && dq;
00213       bool ret;
00214       switch(cutLevel){
00215         case 0: return mrefid && dq;
00216         case 1: return mrepre;
00217         case 2: 
00218           return NueStandard::PassesSelection(nr, Selection::kFid) && mrepre;
00219         case 3:
00220              ret = NueStandard::PassesSelection(nr, Selection::kFid);
00221              ret = ret &&  NueStandard::PassesNonHEPreSelection(nr);
00222              return ret && mrepre;
00223         case 4: 
00224          return NueStandard::PassesSelection(nr, Selection::kPre) && mrepre;
00225       }
00226    }
00227    if(cutSet == "Presel")
00228       return NueStandard::PassesSelection(nr, Selection::kPre);
00229 
00230    if(cutSet == "PreselNoHE")
00231       return  NueStandard::PassesNonHEPreSelection(nr);
00232 
00233    if(cutSet == "Systematic")
00234       return NueStandard::PassesSysPreSelection(nr);
00235 
00236    if(cutSet == "CC")
00237       return NueStandard::PassesSelection(nr, Selection::kCC);
00238 
00239 
00240   cout<<"Invalid Cut Level for "<<cutSet<<": "<<cutLevel<<endl;
00241   return false;
00242 }

Generated on Mon Feb 15 11:07:00 2010 for loon by  doxygen 1.3.9.1