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

PIDEval.cxx

Go to the documentation of this file.
00001 #include "NueAna/ParticlePID/PIDEval.h"
00002 
00003 #include "TTree.h"
00004 #include "TFile.h"
00005 #include "TDirectory.h"
00006 #include "TROOT.h"
00007 
00008 #include "MessageService/MsgService.h"
00009 #include "MinosObjectMap/MomNavigator.h"
00010 #include "JobControl/JobCModuleRegistry.h" // For JOBMODULE macro
00011 #include "Conventions/Detector.h"
00012 
00013 #include "TTree.h"
00014 
00015 
00016 
00017 JOBMODULE(PIDEval, "PIDEval",
00018           "does the pid eval for ParticleFinder");
00019 CVSID("$Id: PIDEval.cxx,v 1.8 2009/08/14 19:16:30 scavan Exp $");
00020 
00021 
00022 TMultiLayerPerceptron * PIDEval::mlp1=0;
00023 TMultiLayerPerceptron * PIDEval::mlp2=0;
00024 TMultiLayerPerceptron * PIDEval::mlp3=0;
00025 TMultiLayerPerceptron * PIDEval::mlp4=0;
00026 TMultiLayerPerceptron * PIDEval::mlp5=0;
00027 TMultiLayerPerceptron * PIDEval::mlp6=0;
00028 
00029 int PIDEval::first=1;
00030 
00031 PIDEval::PIDEval()
00032 {
00033         if(mlp1==0 && first) //only try once...
00034     {
00035                 LoadMLP();
00036                 first=0;
00037     }
00038     
00039         infile="";
00040         outfile="";
00041         cnt=0;
00042         total=1;
00043         
00044         
00045         //osc
00046 
00047 /*      fBaseLine = 735;
00048         fDeltaMS12= 8.0;
00049         fTh12= 0.816;
00050         fTh23=3.141592/4.0;
00051         fDensity=2.75;
00052         SetOscParamBase(0.00243, TMath::ASin(TMath::Sqrt(0.15))/2.0, 0, 1);     
00053   */               
00054   
00055 }
00056 
00057 PIDEval::~PIDEval()
00058 {}
00059 
00060 void PIDEval::LoadMLP()
00061 {
00062   TFile *mlpfile0 = TFile::Open("/minos/scratch/nue/Releases/Griffin/Data/ParticlePID/finalMLPs/MLP_13inp_20:9.root");
00063   if (mlpfile0==0)
00064     {
00065       printf("Error in PIDEval::LoadMLP() 1-- Bad file name\n");
00066     }
00067   if(mlpfile0)mlp1 = (TMultiLayerPerceptron*) mlpfile0->Get("MLP");
00068   if (mlp1==0)
00069     {
00070       printf("Error in PIDEval::LoadMLP() 1-- File does not contain mlp\n");
00071     }else{
00072                 printf("loaded ParticlePID from %s\n",mlpfile0->GetName());
00073                 mlp1=(TMultiLayerPerceptron*)mlp1->Clone();
00074                 mlpfile0->Close();
00075         }
00076 
00077         TFile *mlpfile1 = TFile::Open("/minos/scratch/nue/Releases/Griffin/Data/ParticlePID/finalMLPs/MLP_13inp_25:10.root");
00078   if (mlpfile1==0)
00079     {
00080       printf("Error in PIDEval::LoadMLP() 2-- Bad file name\n");
00081       
00082     }
00083   if(mlpfile1)mlp2 = (TMultiLayerPerceptron*) mlpfile1->Get("MLP");
00084   if (mlp2==0)
00085     {
00086       printf("Error in PIDEval::LoadMLP() 2-- File does not contain mlp\n");
00087     }else{
00088                 printf("loaded ParticlePID from %s\n",mlpfile1->GetName());
00089                 mlp2=(TMultiLayerPerceptron*)mlp2->Clone();
00090                 mlpfile1->Close();
00091         }
00092   
00093   
00094         TFile *mlpfile2 = TFile::Open("/minos/scratch/nue/Releases/Griffin/Data/ParticlePID/finalMLPs/MLP_14inp_16:9.root");
00095   if (mlpfile2==0)
00096     {
00097       printf("Error in PIDEval::LoadMLP() 3-- Bad file name\n");
00098       
00099     }
00100   if(mlpfile2)mlp3 = (TMultiLayerPerceptron*) mlpfile2->Get("MLP");
00101   if (mlp3==0)
00102     {
00103       printf("Error in PIDEval::LoadMLP() 3-- File does not contain mlp\n");
00104     }else{
00105                 printf("loaded ParticlePID from %s\n",mlpfile2->GetName());
00106                 mlp3=(TMultiLayerPerceptron*)mlp3->Clone();
00107                 mlpfile2->Close();
00108         }  
00109   
00110   
00111   
00112   
00113         TFile *mlpfile3 = TFile::Open("/minos/scratch/nue/Releases/Griffin/Data/ParticlePID/finalMLPs/MLP_14inp_18:11.root");
00114 
00115   if (mlpfile3==0)
00116     {
00117       printf("Error in PIDEval::LoadMLP() 4-- Bad file name\n");
00118       
00119     }
00120   if(mlpfile3)mlp4 = (TMultiLayerPerceptron*) mlpfile3->Get("MLP");
00121   if (mlp4==0)
00122     {
00123       printf("Error in PIDEval::LoadMLP() 4-- File does not contain mlp\n");
00124     }else{
00125                 printf("loaded ParticlePID from %s\n",mlpfile3->GetName());
00126                 mlp4=(TMultiLayerPerceptron*)mlp4->Clone();
00127                 mlpfile3->Close();
00128         }    
00129   
00130  
00131   
00132         TFile *mlpfile4 = TFile::Open("/minos/scratch/nue/Releases/Griffin/Data/ParticlePID/finalMLPs/MLP_14inp_18:6.root");
00133 
00134   if (mlpfile4==0)
00135     {
00136       printf("Error in PIDEval::LoadMLP() 5-- Bad file name\n");
00137       
00138     }
00139   if(mlpfile4)mlp5 = (TMultiLayerPerceptron*) mlpfile4->Get("MLP");
00140   if (mlp5==0)
00141     {
00142       printf("Error in PIDEval::LoadMLP() 5-- File does not contain mlp\n");
00143     }else{
00144                 printf("loaded ParticlePID from %s\n",mlpfile4->GetName());
00145                 mlp5=(TMultiLayerPerceptron*)mlp5->Clone();
00146                 mlpfile4->Close();
00147         }  
00148         
00149         
00150  
00151   
00152         TFile *mlpfile5 = TFile::Open("/minos/scratch/nue/Releases/Griffin/Data/ParticlePID/finalMLPs/MLP_14inp_23:6.root");
00153 
00154   if (mlpfile5==0)
00155     {
00156       printf("Error in PIDEval::LoadMLP() 6-- Bad file name\n");
00157       
00158     }
00159   if(mlpfile5)mlp6 = (TMultiLayerPerceptron*) mlpfile5->Get("MLP");
00160   if (mlp6==0)
00161     {
00162       printf("Error in PIDEval::LoadMLP() 6-- File does not contain mlp\n");
00163     }else{
00164                 printf("loaded ParticlePID from %s\n",mlpfile5->GetName());
00165                 mlp6=(TMultiLayerPerceptron*)mlp6->Clone();
00166                 mlpfile5->Close();
00167         }         
00168 
00169 
00170     if(! (mlp1 || mlp2 || mlp3 || mlp4 || mlp5 || mlp6) )
00171     {           
00172         printf("ParticlePID files are missing! directory must have moved\nexiting...\n");
00173         exit(1);
00174     }
00175 
00176 
00177   
00178   
00179 }
00180 
00181 void PIDEval::ana(Particles * particles, Event * event, NueRecord* /*nr*/)
00182 {
00183 
00184         if(cnt%10000==0)printf("%d ... \n",cnt);//%2.2f%%\n",cnt,100.*((double)cnt)/((double)total));
00185         cnt++;
00186 
00187 
00188 
00189         event->pidA=-1;
00190         event->pidB=-1;
00191         event->pidC=-1;
00192         event->pidD=-1;
00193         event->pidE=-1; 
00194         event->pidF=-1;
00195 
00196 
00197 
00198         //double reco_frac=particles->prim_vise/event->visenergy;
00199         //double length_z = event->max_z - event->min_z;        
00200     
00201     double largest_frac=particles->totvise ? 
00202         particles->largest_particle_e/particles->totvise : 1;
00203     double prim_ae0=particles->prim_par_e0 ? 
00204         particles->prim_par_a/particles->prim_par_e0 : 0;
00205         double largest_cmp_chisqndf = particles->largest_particle_cmp_ndf ?
00206                 particles->largest_particle_cmp_chisq / 
00207                         particles->largest_particle_cmp_ndf : 0;
00208         
00209         
00210 
00211         //check ranges
00212         if(particles->longest_s_particle_s<0 || 
00213                 particles->longest_s_particle_s>6)return;
00214         //removing restriction on longest_z since it is not in the nn
00215         //if(particles->longest_z<0 || 
00216         //      particles->longest_z>6)return;
00217         if(particles->ntot<0 || 
00218                 particles->ntot>50)return;
00219         //removing restriction on rms_r since it is not in the nn
00220         //if(particles->rms_r<0 || 
00221         //      particles->rms_r>100)return;
00222         if(particles->prim_par_e0<0 || 
00223                 particles->prim_par_e0>40e3)return;
00224         //changing max on prim_par_chisq from 1000 to 10000 for flexibility
00225         if(particles->prim_par_chisq<0 || 
00226                 particles->prim_par_chisq>10000)return;
00227         if(particles->largest_particle_peakdiff<-200 || 
00228                 particles->largest_particle_peakdiff>200)return;                
00230 
00231     
00232     
00233 
00234         double pars[30];//30? Pick numer based on appropriate neural network.
00235         
00236         int z=0;
00237         
00238     if(mlp1 || mlp2)
00239     {
00240 
00241                 z=0;
00242                 
00243 
00244                 pars[z++]=particles->longest_s_particle_s;
00245                 pars[z++]=particles->mol_rad_r;
00246                 pars[z++]=particles->emfrac;
00247                 pars[z++]=particles->ntot;
00248                 pars[z++]=particles->weighted_phi;
00249                 pars[z++]=largest_frac;
00250                 pars[z++]=particles->prim_par_b;
00251                 pars[z++]=particles->prim_par_e0;
00252                 pars[z++]=particles->prim_par_chisq;
00253                 pars[z++]=largest_cmp_chisqndf;
00254                 pars[z++]=particles->prim_par_a;
00255                 pars[z++]=event->nclusters;
00256                 pars[z++]=prim_ae0;
00257 
00258                 for(int i=z;i<30;i++)pars[i]=0;
00259         
00260  
00261                 event->pidA = mlp1 ? mlp1->Evaluate(0, pars) : -1;
00262 
00263                 event->pidB = mlp2 ? mlp2->Evaluate(0, pars) : -1;
00264  
00265         }
00266         
00267         
00268 
00269 
00270         
00271     if(mlp3 || mlp4 || mlp5 || mlp6)
00272     {
00273 
00274                 z=0;
00275                 
00276 
00277                 pars[z++]=particles->longest_s_particle_s;
00278                 pars[z++]=particles->mol_rad_r;
00279                 pars[z++]=particles->emfrac;
00280                 pars[z++]=particles->ntot;
00281                 pars[z++]=particles->weighted_phi;
00282                 pars[z++]=largest_frac;
00283                 pars[z++]=particles->prim_par_b;
00284                 pars[z++]=particles->prim_par_e0;
00285                 pars[z++]=particles->prim_par_chisq;
00286                 pars[z++]=particles->largest_particle_peakdiff;
00287                 pars[z++]=largest_cmp_chisqndf;
00288                 pars[z++]=particles->prim_par_a;
00289                 pars[z++]=event->nclusters;
00290                 pars[z++]=prim_ae0;
00291 
00292                 for(int i=z;i<30;i++)pars[i]=0;
00293         
00294  
00295                 event->pidC = mlp3 ? mlp3->Evaluate(0, pars) : -1;
00296 
00297                 event->pidD = mlp4 ? mlp4->Evaluate(0, pars) : -1;
00298 
00299                 event->pidE = mlp5 ? mlp5->Evaluate(0, pars) : -1;
00300 
00301                 event->pidF = mlp6 ? mlp6->Evaluate(0, pars) : -1;
00302                  
00303         }
00304         
00305          
00306     
00307     
00308 
00309 }
00310 
00311 
00312 
00313 
00314 //......................................................................
00315 
00316 void PIDEval::BeginJob()
00317 {
00321 
00322 /*      TFile *f = TFile::Open(infile.c_str());
00323         if(!f)return;
00324         TTree * pt = (TTree*)f->Get("PA");
00325         if(pt)
00326         {
00327                 total=pt->GetEntries();
00328                 printf("%d total PRecords\n",total);
00329         }
00330         f->Close();
00331 */
00332 
00333 }
00334 
00335 //......................................................................
00336 
00337 void PIDEval::EndJob()
00338 {
00342 
00343 
00344         //copy pot tree?
00345 /*      if(infile!="" && outfile!="")
00346         {
00347                 //copy the pot tree
00348 
00349                 TDirectory *savedir = gDirectory;
00350         
00351                 TFile *fpf = dynamic_cast<TFile *>(gROOT->GetListOfFiles()->FindObject(outfile.c_str()));
00352                 if(fpf){
00353 
00354                         TFile *f = TFile::Open(infile.c_str());
00355                         TTree * pt = (TTree*)f->Get("pottree");
00356                         fpf->cd();
00357                         if(pt)
00358                                 pt->CloneTree()->Write("pottree");
00359                         else
00360                                 printf("NO POTTREE FOUND...!\n");
00361                         savedir->cd();
00362                 }
00363         
00364         }
00365 */
00366 
00367 
00368   if(kPOTTreeName=="")return; //don't want to copy pottree...
00369   
00370 
00371    printf("PIDEval copying POTtree from input file\n");  
00372    TFile *fpf = dynamic_cast<TFile *>(gROOT->GetListOfFiles()->FindObject(kPOTTreeName.c_str()));
00373    if(fpf){
00374         printf("got outfile\n");
00375    }
00376 
00377 
00378    TFile *fpi = dynamic_cast<TFile *>(gROOT->GetListOfFiles()->FindObject(kPOTTreeNameIn.c_str()));
00379    if(fpi){
00380         printf("got infile\n");
00381         TTree *pt = (TTree*)fpi->Get("pottree");
00382         if(pt)
00383         {
00384                 printf("got pottree\n");
00385                 fpf->cd();
00386                 pt->CloneTree()->Write();
00387         }
00388    }
00389 
00390 
00391 
00392 
00393 }
00394 
00395 //......................................................................
00396 
00397 JobCResult PIDEval::Reco(MomNavigator* mom)
00398 {
00402 
00403 
00404         std::vector<TObject* > hft =( mom->GetFragmentList("PRecord"));
00405 
00406         for(unsigned int s =0;s<hft.size();s++)
00407         {
00408                 PRecord *n=0;
00409                 n=dynamic_cast<PRecord *>(hft[s]);
00410                 ana(&(n->particles),&(n->event),0);
00411                 
00412                 //recalc_oscprob(n);
00413                 //adjRecoE(n);
00414         }
00415 
00416         if(hft.size()<1) //no PRecords.. so look for nuerecords...
00417         {
00418                 std::vector<TObject* > nrv =( mom->GetFragmentList("NueRecord"));
00419                 NueRecord * nr =0;
00420                 for(unsigned int s=0;s<nrv.size();s++)
00421                 {
00422                         nr = dynamic_cast<NueRecord *>(nrv[s]);         
00423                         PRecord *n=&nr->precord;
00424                         if(n)ana(&(n->particles),&(n->event),nr);
00425                         n=&nr->precordMRCC;
00426                         if(n)ana(&(n->particles),&(n->event),nr);
00427                         
00428         //              recalc_oscprob(nr);
00429                 }
00430         }
00431 
00432         return JobCResult::kPassed; // kNoDecision, kFailed, etc.
00433 }
00434 
00435 //......................................................................
00436 
00437 const Registry& PIDEval::DefaultConfig() const
00438 {
00442 
00443   static Registry r; // Default configuration for module
00444 
00445   // Set name of config
00446   std::string name = this->GetName();
00447   name += ".config.default";
00448   r.SetName(name.c_str());
00449   r.Set("InFileName",""); //don't set when used with a real reco chain
00450   r.Set("OutFileName","");
00451   // Set values in configuration
00452 
00453   r.Set("POTTreeName","");
00454   r.Set("POTTreeNameIn","");
00455 
00456 
00457 
00458 
00459 
00460 
00461   r.UnLockValues();
00462   r.LockValues();
00463 
00464 
00465   return r;
00466 }
00467 
00468 //......................................................................
00469 
00470 void PIDEval::Config(const Registry& r)
00471 {
00475   
00476  
00477     const char* tmps;
00478     if(r.Get("InFileName",tmps)){infile=tmps;}
00479     if(r.Get("OutFileName",tmps)){outfile=tmps;}  
00480 
00481 
00482     if(r.Get("POTTreeName",tmps))kPOTTreeName=tmps;
00483     if(r.Get("POTTreeNameIn",tmps))kPOTTreeNameIn=tmps;
00484 
00485 }
00486 
00487 //......................................................................
00488 
00489 void PIDEval::Reset()
00490 {
00494 }
00495 
00497 
00498 /*
00499 void PIDEval::adjRecoE(PRecord * p)
00500 {
00501         if(p->GetHeader().GetVldContext().GetDetector()==Detector::kNear)
00502         {
00503         
00504                 p->event.visenergy=p->event.visenergy*0.03799819+0.4803261;
00505                 p->particles.totvise=p->particles.totvise*0.03958938+0.4161953;
00506         
00507         }else if(p->GetHeader().GetVldContext().GetDetector()==Detector::kFar)
00508         {
00509                 p->event.visenergy=p->event.visenergy*0.0387301+0.489987;
00510                 p->particles.totvise=p->particles.totvise*0.03379042+0.5866994;
00511         
00512         }
00513         
00514 
00515 }
00516 */
00517 
00518 /*
00519 void PIDEval::recalc_oscprob(NueRecord * p)
00520 {
00521         if(p->GetHeader().GetVldContext().GetDetector()==Detector::kNear)
00522         {
00523 //              p->mctrue.fOscProb=1.;
00524                 return;
00525         }
00526 
00527 
00528         
00529         double newoscprob =  fOscCalc.Oscillate(p->mctrue.nuFlavor, p->mctrue.nonOscNuFlavor, p->mctrue.nuEnergy);
00530         
00531 //      if(p->mctrue.fNueClass==0)newoscprob/=3.; //adjust for equal file types
00532         
00533 //      printf("%f %f\n",p->mctrue.oscprob,newoscprob);
00534         p->mctrue.fOscProb = newoscprob;
00535         
00536         / *
00537         p->mctrue.osc_L=fBaseLine;
00538         p->mctrue.osc_dm2=fDeltaMS12;
00539         p->mctrue.osc_sinth23=fTh12;
00540         p->mctrue.osc_sin2th13=fTh23;
00541 * /
00542 }
00543 */
00544 /*
00545 void PIDEval::SetOscParamBase( float dm2, float ss13,
00546                                     float delta, int hierarchy){
00547 
00548   Double_t dm2_12 = fDeltaMS12*1e-5; //best fit SNO
00549   Double_t dm2_23 = dm2;
00550                                                                                 
00551   Double_t par[9] = {0};
00552   par[OscPar::kL] = fBaseLine;
00553   par[OscPar::kTh23] = fTh23;
00554   par[OscPar::kTh12] = fTh12;
00555   par[OscPar::kTh13] = ss13; // TMath::ASin(TMath::Sqrt(ss2th13))/2.;
00556   par[OscPar::kDeltaM23] = hierarchy*dm2_23;
00557   par[OscPar::kDeltaM12] = dm2_12;
00558   par[OscPar::kDensity] = fDensity; //standard rock density
00559   par[OscPar::kDelta] = delta;
00560   par[OscPar::kNuAntiNu] = 1;
00561                                                                                 
00562 //  std::cout<<"About to call "<<dm2<<"  "<<ss13<<"  "<<delta<<std::endl;
00563   fOscCalc.SetOscParam(par);
00564 }
00565 */

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