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

MadNsID.cxx

Go to the documentation of this file.
00001 
00002 //
00003 // MadNsID
00004 //
00005 // A class to calculate Niki Saoulidou's ANN based CC PID
00006 //
00007 // Created:  N. Saoulidou --Analysis first presented early 2004, Code implementation in May-2005
00008 //
00009 // Converted to this format: M. Kordosky, 12 August 2005
00010 //
00011 // $Author: niki $ 
00012 //
00013 // $Revision: 1.22 $
00014 // 
00015 // $Name:  $
00016 //
00017 // $Id: MadNsID.cxx,v 1.22 2007/04/25 15:48:53 niki Exp $
00018 //
00019 // $Log: MadNsID.cxx,v $
00020 // Revision 1.22  2007/04/25 15:48:53  niki
00021 // changes for new 7 var ANN without total pulse height in input variables
00022 //
00023 // Revision 1.21  2007/03/19 23:50:45  niki
00024 // New Cedar Daikon ANN Weight files and new 7-Input variable ANN
00025 //
00026 // Revision 1.20  2007/03/15 19:44:54  niki
00027 // Small changes in order to be able to call methods from NCUtils
00028 //
00029 // Revision 1.19  2007/03/14 16:17:58  niki
00030 // Fixed a the beam type definition for LE010
00031 //
00032 // Revision 1.18  2007/02/17 00:32:13  niki
00033 // UPdated ann weights files
00034 //
00035 // Revision 1.17  2007/02/13 01:09:10  niki
00036 // Reading Cedar/Carrot weights for ANN separation
00037 //
00038 // Revision 1.16  2007/02/09 21:33:57  niki
00039 // Josh pointed out "unprotected" occurences of strip index = -! (Thanks
00040 // Josh!) All such occurences are now protected against.
00041 //
00042 // Revision 1.15  2007/02/01 22:01:19  rhatcher
00043 // Changes to ROOT headers means we need an explicit #include "TClonesArray.h"
00044 //
00045 // Revision 1.14  2007/01/30 03:17:21  rhatcher
00046 // No longer user BeamType "class" found in MCReweight, but rather the
00047 // BeamType "namespace" found in Conventions package.
00048 // Also covert to using "Detector::" rather than "DetectorType::", though
00049 // for now they are synonyms.
00050 //
00051 // Revision 1.13  2007/01/29 23:05:13  boehm
00052 // Adjusting how the data files are loaded into the two PIDs.  Now the code looks first in the SRT_PRIVATE_CONTEXT and then checks the SRT_PUBLIC_CONTEXT.  This further detachs the CC-pids from the Mad Framework.
00053 //
00054 // Revision 1.12  2006/10/16 19:53:30  kordosky
00055 // cope with CEDAR strip indices set to -1. allow user to force beam type (useful for 150cm data). Open files with TFile::Open() to allow natural dcache access. IMPORTANT: Big change to pans. Tacking on a spill marker, looks like event=-1 with no muon or shower energy, pass and is_fid set to fail. Beam variables and nevent are correct for these entries. Modification intended to ease POT counting
00056 //
00057 // Revision 1.11  2006/05/08 21:27:44  boehm
00058 // Primary change is the addition of functions to calculate the PID's from NtpSt objects.  Both PIDs may now be generated without relying on the rest of the Mad infrastructure.  Mad based code though should not be changed.
00059 //
00060 // Also removed the if(!ntpTrack.fit.pass) return;  from MadDpID.cxx as it does not reflect the current state of the CC analysis. This was removed in the branched version but remained in the development version.
00061 //
00062 // Revision 1.10  2006/02/13 00:34:22  niki
00063 // update my ANN weight files to version 18_2
00064 //
00065 // Revision 1.9  2005/12/14 23:19:58  niki
00066 //  Fix a bug (ntrklike was zero for a given track(?) and I was dividing by
00067 // it).
00068 //
00069 //  Thanks to David P. and Mike K. for catching this!
00070 //
00071 // Revision 1.8  2005/12/12 15:34:32  niki
00072 //  Revised the ANN weight files in order to reflect training with R1_18
00073 //  Addded a few comments to explain the use of priors, fiducials e.t.c
00074 //
00075 // Revision 1.7  2005/10/07 11:19:12  kordosky
00076 // deal with BeamMonSpill::StatusBits.beam_type==0 without asserting. Clearly, it can be zero!
00077 //
00078 // Revision 1.6  2005/10/06 18:40:52  kordosky
00079 // random additions
00080 //
00081 // Revision 1.5  2005/10/06 15:03:26  kordosky
00082 // various improvements, pids finally integrated into pan construction routine, still not fully debugged though
00083 //
00084 // Revision 1.4  2005/09/14 13:32:45  kordosky
00085 // DpID and NsID classes now fully working and validated with MadTestAnalysis by comparing nannpid vs. annpid and npid0 vs. pid0.  pdf files and weights stored in data subdirectory. FD pdfs needed for DpID.
00086 //
00087 //
00089 
00090 
00091 #include <fstream>
00092 #include <iostream>
00093 #include <sys/types.h>
00094 #include <sys/stat.h>
00095 #include <unistd.h>
00096 
00097 #include "TClonesArray.h"
00098 #include "TSystem.h"
00099 
00100 #include "Mad/MadNsID.h"
00101 #include "Mad/MadQuantities.h"
00102 
00103 MadNsID::MadNsID() : weights_read(false), weight_fname("") {
00104   cache_det=Detector::kUnknown;
00105   cache_beam=BeamType::kUnknown;
00106   cache_fid = -1;
00107   cache_prior = -1;
00108 
00109 }
00110 
00111 bool MadNsID::ReadWeights(const char* file){
00112   // read a text file containing the ANN weights
00113   // returns true if file was correctly read
00114   // returns false otherwise
00115   weights_read = false;
00116 
00117   std::ifstream weightfile(file);
00118   if(!weightfile){ 
00119     std::cout<<"MadNsID::ReadWeights(), cannot read: "<<file<<std::endl;
00120     return false;
00121   }
00122   std::cout<<"Reading MadNsID weights from: "<<file<<std::endl;
00123   
00124   Int_t all  = inneuron*hidneuron+hidneuron+hidneuron+1;
00125   Int_t all1 = inneuron*hidneuron+hidneuron;
00126   Int_t n1  =0;
00127   Int_t nw1 =0;
00128   Int_t no  =0;
00129   Int_t nwo =0;
00130 
00131   // read weights
00132   for(Int_t k=0;k<all;k++){  
00133     Double_t var;
00134     weightfile >> var ;
00135     if(!weightfile.good()){
00136       std::cerr<<"MadNsID::ReadWeights() bad input, k="<<k<<std::endl;
00137       weightfile.close();
00138       return false;
00139     }
00140     if(k<all1){
00141       if(k%(inneuron+1)==0){
00142         nw1=0;
00143         constant1[n1]=var;        
00144         n1=n1+1;           
00145       }
00146       else {
00147         weight1[nw1][n1-1]=var;    
00148         nw1=nw1+1;         
00149       }
00150     }
00151     else if(k>=all1){
00152       if((k-all1)%(hidneuron+1)==0){
00153         nwo=0;
00154         constanto[no]=var;        
00155         no=no+1;          
00156       }
00157       else {
00158         weighto[nwo]=var;          
00159         nwo=nwo+1;         
00160       }
00161     }          
00162   }
00163   
00164   weightfile.close();  
00165   weights_read=true;
00166   return true;
00167 
00168 }
00169 
00170 
00171 Double_t MadNsID::CalcPID(const AnnInputBlock& anninput, 
00172                           const Detector::Detector_t& det){
00173   // calculate the ANN PID based on the information in the input block
00174   // code does a little detector specific stuff...
00175   if(!weights_read) assert( ReadWeights(weight_fname.c_str()) );
00176 
00177   Double_t rin[hidneuron];
00178   Double_t out[hidneuron];
00179   for(Int_t i=0; i<hidneuron; i++){rin[i]=0; out[i]=0;}
00180   
00181   
00182   if(det==Detector::kFar){  
00183   
00184       out[0]  =  (anninput.aTrkphperpl*anninput.aTotrk*anninput.aTrkpass)/2000.;
00185       out[1]  =  (anninput.aPhperpl/10000.); 
00186    // out[1]  =  (anninput.aTotph/50000.); 
00187       out[2]  =  (anninput.aTotlen/40);
00188       out[3]  =  (anninput.aPh3/(anninput.aTotph+1.));
00189       out[4]  =  (anninput.aPh6/(anninput.aTotph+1.));
00190       out[5]  =  (anninput.aPhlast/(anninput.aTotph+1.));
00191       out[6]  =  ((anninput.aTrkplu-anninput.aShwplu)+20.)/40.;
00192  /*     
00193     out[0]  =  anninput.aTrkphperpl/2000.;
00194     out[1]  =  anninput.aTotrk*anninput.aTrkpass;
00195     out[2]  = (anninput.aTotstp/100.);
00196     out[3]  = (anninput.aTotph/50000.);   
00197     out[4]  = (anninput.aTotlen/40);
00198     out[5]  = (anninput.aPhperpl/5000.);        
00199     out[6]  = (anninput.aPhperstp/1000.);
00200     out[10] = ((anninput.aTrkplv-anninput.aShwplv)+20.)/40.;
00201     out[11] = ((anninput.aTrkplu-anninput.aShwplu)+20.)/40.;
00202   */
00203   }
00204   else if(det==Detector::kNear){
00205        out[0]  =  (anninput.aTrkphperpl*anninput.aTotrk*anninput.aTrkpass)/5000.;
00206        out[1]  =  (anninput.aPhperpl/10000.); 
00207      //out[1]  =  (anninput.aTotph/100000.); 
00208        out[2]  =  (anninput.aTotlen/40);
00209        out[3]  =  (anninput.aPh3/(anninput.aTotph+1.));
00210        out[4]  =  (anninput.aPh6/(anninput.aTotph+1.));
00211        out[5]  =  (anninput.aPhlast/(anninput.aTotph+1.));
00212        out[6]  =  ((anninput.aTrkplu-anninput.aShwplu)+10.)/20.;
00213 /*       
00214     out[0]  = anninput.aTrkphperpl/5000.;
00215     out[1]  = anninput.aTotrk*anninput.aTrkpass;
00216     out[2]  = (anninput.aTotstp/100.);
00217     out[3]  = (anninput.aTotph/100000.);   
00218     out[4]  = (anninput.aTotlen/40);
00219     out[5]  = (anninput.aPhperpl/10000.);       
00220     out[6]  = (anninput.aPhperstp/2000.);  
00221     out[10] = ((anninput.aTrkplv-anninput.aShwplv)+10.)/20.;
00222     out[11] = ((anninput.aTrkplu-anninput.aShwplu)+10.)/20.;
00223   */
00224   }
00225  // out[7]  = (anninput.aPh3/(anninput.aTotph+1.));
00226  // out[8]  = (anninput.aPh6/(anninput.aTotph+1.));
00227  //  out[9]  = (anninput.aPhlast/(anninput.aTotph+1.));
00228  // out[12] = (anninput.aShwphperdig/800.);
00229 
00230 
00231      
00232   // first layer         
00233   for(Int_t i=0;i<hidneuron;i++){
00234     rin[i]=constant1[i];
00235     for(Int_t j=0;j<inneuron;j++){
00236       rin[i]=rin[i]+weight1[j][i]*out[j];
00237     }
00238   }
00239   // output                     
00240   for(Int_t i=0;i<hidneuron;i++){        
00241     out[i]=Sigmoid(rin[i]);      
00242   }             
00243 
00244   Double_t prob =constanto[0];  
00245   for(Int_t i=0;i<hidneuron;i++) prob=prob+weighto[i]*out[i];
00246   
00247   
00248   if(anninput.aTotlen>50) prob=0.;
00249 
00250   return prob;
00251 
00252 }
00253 
00254 bool MadNsID::CalcVars(MadQuantities* mq, Int_t event, 
00255                        AnnInputBlock& anninput){
00256 
00257   // calculates ann input variables for this event and records them in
00258   // anninput.  returns false in case of problems, true otherwise
00259   
00260 
00261   // Initialize
00262   anninput.aTotrk       =0.;
00263   anninput.aTotstp      =0.;
00264   anninput.aTotph       =0.;
00265   anninput.aTotlen      =0.;
00266   anninput.aPhperpl     =0.;
00267   anninput.aPhperstp    =0.;
00268   
00269   
00270   anninput.aTrkpass     =0.;
00271   anninput.aTrkph       =0.;
00272   anninput.aTrklen      =0.;
00273   anninput.aTrkphperpl  =0.;
00274   anninput.aTrkphper    =0.;
00275   anninput.aTrkplu      =0.;
00276   anninput.aTrkplv      =0.;
00277   anninput.aTrkstp      =0.;
00278  
00279   anninput.aShwph       =0.;
00280   anninput.aShwstp      =0.;
00281   anninput.aShwdig      =0.;
00282   anninput.aShwpl       =0.;
00283   anninput.aShwphper    =0.;
00284   anninput.aShwphperpl  =0.;
00285   anninput.aShwphperdig =0.;
00286   anninput.aShwphperstp =0.;
00287   anninput.aShwplu      =0.;
00288   anninput.aShwplv      =0.;
00289   anninput.aPh3         =0.;
00290   anninput.aPh6         =0.;
00291   anninput.aPhlast      =0.;
00292   anninput.aPhcommon    =0.;
00293 //  
00294   
00295 // Calculate variables needed for ANN (and a few more)
00296   
00297   const NtpSREvent* ntpEvent = mq->GetEvent(event) ;  
00298   if(!ntpEvent) return false; // perhaps ought to assert here?
00299   int track_index   = -1;
00300   const NtpSRTrack* ntpTrack   = mq->GetLargestTrackFromEvent(event,track_index);
00301   int shower_index  = -1;
00302   const NtpSRShower* ntpShower = mq->GetLargestShowerFromEvent(event,shower_index);
00303  
00304   anninput.aTotrk       =ntpEvent->ntrack;
00305   anninput.aTotstp      =ntpEvent->nstrip;
00306   anninput.aTotph       =ntpEvent->ph.sigcor;
00307   anninput.aTotlen      =ntpEvent->plane.end-ntpEvent->plane.beg+1; // prepei na to alla3w
00308   anninput.aPhperpl     =ntpEvent->ph.sigcor/ntpEvent->plane.n;
00309   anninput.aPhperstp    =ntpEvent->ph.sigcor/ntpEvent->nstrip;
00310   
00311   if(track_index!=-1) {
00312     anninput.aTrkpass     =ntpTrack->fit.pass;
00313     anninput.aTrkph       =ntpTrack->ph.sigcor;
00314     anninput.aTrklen      =ntpTrack->plane.ntrklike;
00315     if(ntpTrack->plane.ntrklike>0) anninput.aTrkphperpl  =ntpTrack->ph.sigcor/ntpTrack->plane.ntrklike;
00316     if(ntpEvent->ph.sigcor>0)      anninput.aTrkphper    =ntpTrack->ph.sigcor/ntpEvent->ph.sigcor;
00317     anninput.aTrkplu      =ntpTrack->plane.nu;
00318     anninput.aTrkplv      =ntpTrack->plane.nv;
00319     anninput.aTrkstp      =ntpTrack->nstrip;
00320   }
00321   if(shower_index!=-1) {
00322     anninput.aShwph       =ntpShower->ph.sigcor;
00323     anninput.aShwstp      =ntpShower->nstrip;
00324     anninput.aShwdig      =ntpShower->ndigit;
00325     anninput.aShwpl       =ntpShower->plane.n;
00326     anninput.aShwphper    =ntpShower->ph.sigcor/ntpEvent->ph.sigcor;
00327     anninput.aShwphperpl  =ntpShower->ph.sigcor/ntpShower->plane.n;
00328     anninput.aShwphperdig =ntpShower->ph.sigcor/ntpShower->ndigit;
00329     anninput.aShwphperstp =ntpShower->ph.sigcor/ntpShower->nstrip;
00330     anninput.aShwplu      =ntpShower->plane.nu;
00331     anninput.aShwplv      =ntpShower->plane.nv; 
00332   }
00333 
00334   Int_t ssind,ssplind;
00335   Double_t ssphtot;
00336   Bool_t foundshw,foundtrk;
00337   Int_t planes=ntpEvent->plane.beg;
00338   
00339   Double_t ph3,ph6,phlast,phcommon,phnowere,hitcommon,hitnowere;
00340   ph3=0.;ph6=0.;phlast=0.;phcommon=0.;phnowere=0.;hitcommon=0.;hitnowere=0.;
00341   // loop over strips to compute ph3 ph6 phlast phcommon
00342   for(Int_t evss=0;evss<ntpEvent->nstrip;evss++){ 
00343     Int_t stp_index=((ntpEvent->stp)[evss]);
00344 
00345     if(stp_index!=-1){
00346  
00347     const NtpSRStrip* ntpStrip =  mq->GetStrip(stp_index);      
00348     if(!ntpStrip) continue;
00349     ssind   =ntpStrip->strip;
00350     ssplind =ntpStrip->plane;
00351     ssphtot =ntpStrip->ph1.sigcor+ntpStrip->ph0.sigcor; 
00352     
00353     foundshw=false;
00354     foundtrk=false;
00355     
00356     Double_t phstrips=0;
00357     Double_t phstript=0;       
00358     // shower strips
00359     Int_t sshwind,sshwplind;
00360     Double_t sshwphtot;
00361     
00362     if(shower_index!=-1) {
00363       for(Int_t jj=0;jj<ntpShower->nstrip;jj++){
00364         Int_t stp_indexs=((ntpShower->stp)[jj]);
00365         
00366        if(stp_indexs!=-1){
00367 
00368         ntpStrip = mq->GetStrip(stp_indexs);
00369         if(!foundshw){
00370           sshwind=ntpStrip->strip;
00371           sshwplind=ntpStrip->plane;
00372           sshwphtot=ntpStrip->ph1.sigcor+ntpStrip->ph0.sigcor;             
00373           if(sshwind==ssind && sshwplind==ssplind) {
00374             foundshw=true;
00375             phstrips=sshwphtot;
00376           }
00377         }
00378        }
00379       }
00380     }      
00381     // tracks strips
00382     Int_t strkind,strkplind;
00383     Double_t strkphtot;
00384     if(track_index!=-1) {
00385       for(Int_t jj=0;jj<ntpTrack->nstrip;jj++){
00386         Int_t stp_indext=((ntpTrack->stp)[jj]);
00387 
00388         if(stp_indext!=-1){
00389 
00390         ntpStrip = mq->GetStrip(stp_indext);
00391 
00392         if(!foundtrk){
00393           strkind  =ntpStrip->strip;
00394           strkplind=ntpStrip->plane;
00395           strkphtot=ntpStrip->ph1.sigcor+ntpStrip->ph0.sigcor;   
00396           if(strkind==ssind && strkplind==ssplind) {
00397             foundtrk=true;
00398             phstript=strkphtot;
00399           }
00400         }
00401 
00402        }
00403       }
00404     }
00405        
00406     if(foundshw && foundtrk) {
00407       hitcommon=hitcommon+1;
00408       phcommon=phcommon+phstrips+phstript;
00409     }  
00410     if(!foundshw && ! foundtrk) {
00411       hitnowere=hitnowere+1; 
00412       phnowere=phnowere+ssphtot; 
00413     }            
00414     if(ssplind>=planes && ssplind<=(planes+3)){
00415       ph3=ph3+ssphtot;
00416     }
00417     else if(ssplind>(planes+3) && ssplind<=(planes+6)){
00418       ph6=ph6+ssphtot; 
00419     }
00420     else {
00421       phlast=phlast+ssphtot;
00422     }     
00423 
00424    } // end of if stp_index != -1
00425 
00426   } // end of looping over event strips....    
00427 
00428 //
00429   anninput.aPh3       =ph3;
00430   anninput.aPh6       =ph6;
00431   anninput.aPhlast    =phlast;
00432   anninput.aPhcommon  =phcommon; 
00433   
00434   return true;
00435 
00436 
00437 }
00438 
00439 bool MadNsID::CalcVars(NtpSREvent* ntpEvent, NtpSRTrack *ntpTrack,
00440                        NtpSRShower *ntpShower, NtpStRecord* st,
00441                         AnnInputBlock& anninput)
00442 {                                                                            
00443                                                                                 
00444   // calculates ann input variables for this event and records them in
00445   // anninput.  returns false in case of problems, true otherwise
00446                                                                                 
00447   // Initialize
00448   anninput.aTotrk       =0.;
00449   anninput.aTotstp      =0.;
00450   anninput.aTotph       =0.;
00451   anninput.aTotlen      =0.;
00452   anninput.aPhperpl     =0.;
00453   anninput.aPhperstp    =0.;
00454                                                                                 
00455   anninput.aTrkpass     =0.;
00456   anninput.aTrkph       =0.;
00457   anninput.aTrklen      =0.;
00458   anninput.aTrkphperpl  =0.;
00459   anninput.aTrkphper    =0.;
00460   anninput.aTrkplu      =0.;
00461   anninput.aTrkplv      =0.;
00462   anninput.aTrkstp      =0.;
00463                                                                                 
00464   anninput.aShwph       =0.;
00465   anninput.aShwstp      =0.;
00466   anninput.aShwdig      =0.;
00467   anninput.aShwpl       =0.;
00468   anninput.aShwphper    =0.;
00469   anninput.aShwphperpl  =0.;
00470   anninput.aShwphperdig =0.;
00471   anninput.aShwphperstp =0.;
00472   anninput.aShwplu      =0.;
00473   anninput.aShwplv      =0.;
00474   
00475   anninput.aPh3         =0.;
00476   anninput.aPh6         =0.;
00477   anninput.aPhlast      =0.;
00478   anninput.aPhcommon    =0.;
00479 
00480   // Calculate variables needed for ANN (and a few more)
00481                                                                                 
00482   if(!ntpEvent) return false; // perhaps ought to assert here?
00483                                                                                 
00484   anninput.aTotrk       =ntpEvent->ntrack;
00485   anninput.aTotstp      =ntpEvent->nstrip;
00486   anninput.aTotph       =ntpEvent->ph.sigcor;
00487   anninput.aTotlen      =ntpEvent->plane.end-ntpEvent->plane.beg+1; // prepei na to alla3w
00488   anninput.aPhperpl     =ntpEvent->ph.sigcor/ntpEvent->plane.n;
00489   anninput.aPhperstp    =ntpEvent->ph.sigcor/ntpEvent->nstrip;
00490                                                                                 
00491   if(ntpTrack != 0) {
00492     anninput.aTrkpass     =ntpTrack->fit.pass;
00493     anninput.aTrkph       =ntpTrack->ph.sigcor;
00494     anninput.aTrklen      =ntpTrack->plane.ntrklike;
00495     if(ntpTrack->plane.ntrklike>0) anninput.aTrkphperpl  =ntpTrack->ph.sigcor/ntpTrack->plane.ntrklike;
00496     if(ntpEvent->ph.sigcor>0)      anninput.aTrkphper    =ntpTrack->ph.sigcor/ntpEvent->ph.sigcor;
00497     anninput.aTrkplu      =ntpTrack->plane.nu;
00498     anninput.aTrkplv      =ntpTrack->plane.nv;
00499     anninput.aTrkstp      =ntpTrack->nstrip;
00500   }
00501   if(ntpShower != 0) {
00502     anninput.aShwph       =ntpShower->ph.sigcor;
00503     anninput.aShwstp      =ntpShower->nstrip;
00504     anninput.aShwdig      =ntpShower->ndigit;
00505     anninput.aShwpl       =ntpShower->plane.n;
00506     anninput.aShwphper    =ntpShower->ph.sigcor/ntpEvent->ph.sigcor;
00507     anninput.aShwphperpl  =ntpShower->ph.sigcor/ntpShower->plane.n;
00508     anninput.aShwphperdig =ntpShower->ph.sigcor/ntpShower->ndigit;
00509     anninput.aShwphperstp =ntpShower->ph.sigcor/ntpShower->nstrip;
00510     anninput.aShwplu      =ntpShower->plane.nu;
00511     anninput.aShwplv      =ntpShower->plane.nv;
00512   }
00513                                                                                 
00514   Int_t ssind,ssplind;
00515   Double_t ssphtot;
00516   Bool_t foundshw,foundtrk;
00517   Int_t planes =ntpEvent->plane.beg;
00518   Double_t ph3,ph6,phlast,phcommon,phnowere,hitcommon,hitnowere;
00519   ph3=0.;ph6=0.;phlast=0.;phcommon=0.;phnowere=0.;hitcommon=0.;hitnowere=0.;
00520   // loop over strips to compute ph3 ph6 phlast phcommon
00521                                                                                 
00522   for(Int_t i = 0; i < ntpEvent->nstrip;i++)
00523   {
00524     Int_t stp_index=((ntpEvent->stp)[i]);
00525 
00526     if(stp_index!=-1){
00527 
00528     NtpSRStrip* ntpStrip = dynamic_cast<NtpSRStrip *>((*st->stp)[stp_index]);
00529 
00530                                                                                 
00531     ssind   = ntpStrip->strip;
00532     ssplind = ntpStrip->plane;
00533     ssphtot = ntpStrip->ph1.sigcor+ntpStrip->ph0.sigcor;
00534                                                                                 
00535     foundshw=false;
00536     foundtrk=false;
00537                                                                                 
00538     Double_t phstrips=0;
00539     Double_t phstript=0;
00540     // shower strips
00541     Int_t sshwind,sshwplind;
00542     Double_t sshwphtot;
00543                                                                                 
00544     if(ntpShower != 0) {
00545       for(Int_t jj=0;jj<ntpShower->nstrip;jj++){
00546         Int_t stp_indexs=((ntpShower->stp)[jj]);
00547        
00548         if(stp_indexs!=-1){
00549 
00550         ntpStrip = dynamic_cast<NtpSRStrip *>((*st->stp)[stp_indexs]);
00551 
00552         if(!foundshw){
00553           sshwind=ntpStrip->strip;
00554           sshwplind=ntpStrip->plane;
00555           sshwphtot=ntpStrip->ph1.sigcor+ntpStrip->ph0.sigcor;
00556           if(sshwind==ssind && sshwplind==ssplind) {
00557             foundshw=true;
00558             phstrips=sshwphtot;
00559           }
00560         }
00561        }
00562       }
00563     }
00564     // tracks strips
00565     Int_t strkind,strkplind;
00566     Double_t strkphtot;
00567     if(ntpTrack != 0) {
00568       for(Int_t jj=0;jj<ntpTrack->nstrip;jj++){
00569         Int_t stp_indext=((ntpTrack->stp)[jj]);
00570        
00571         if(stp_indext!=-1){
00572 
00573          ntpStrip = dynamic_cast<NtpSRStrip *>((*st->stp)[stp_indext]);
00574 
00575         if(!foundtrk){                                                                                
00576           strkind=ntpStrip->strip;
00577           strkplind=ntpStrip->plane;
00578           strkphtot=ntpStrip->ph1.sigcor+ntpStrip->ph0.sigcor;
00579           if(strkind==ssind && strkplind==ssplind) {
00580             foundtrk=true;
00581             phstript=strkphtot;
00582           }
00583         }
00584        }
00585       }
00586     }
00587                                                                                 
00588     if(foundshw && foundtrk) {
00589       hitcommon=hitcommon+1;
00590       phcommon=phcommon+phstrips+phstript;
00591     }
00592     if(!foundshw && ! foundtrk) {
00593       hitnowere=hitnowere+1;
00594       phnowere=phnowere+ssphtot;
00595     }
00596     if(ssplind>=planes && ssplind<=(planes+3)){
00597       ph3=ph3+ssphtot;
00598     }
00599     else if(ssplind>(planes+3) && ssplind<=(planes+6)){
00600       ph6=ph6+ssphtot;
00601     }
00602     else {
00603       phlast=phlast+ssphtot;
00604     }
00605    } // end of if strip index !=-1
00606   } // end of looping over event strips....
00607 //
00608   anninput.aPh3       =ph3;
00609   anninput.aPh6       =ph6;
00610   anninput.aPhlast    =phlast;
00611   anninput.aPhcommon  =phcommon;
00612                                                                                 
00613   return true;
00614 }
00615 
00616 std::string MadNsID::GetWeightFileName(const Detector::Detector_t& det,
00617                                        const BeamType::BeamType_t& beam, 
00618                                        Int_t fid, Int_t prior)
00619 {
00620   // M. Kordosky Sept 09, 2005
00621   //
00622   // Choose a file of ANN weights according to the detector, beam, 
00623   // fiducial volue and prior 
00624   // 
00625   //
00626   // N Saoulidou December 12 2005
00627   // DET IS THE DETECTOR 1 = NEAR 2 = FAR
00628   // TAR IS THE ENERGY   1 = LE 2 = PME 3 = PHE
00629   // FID IS THE FIDUCIAL REGION FOR FAR , 2 = DAVIDS  1 = MINE (MORE STRICT)
00630   // PRIOR IS THE FAR TRAINED METHOD    , 1 = NO OSCILLATIONS , 
00631   //                                      2 = DM2 0.0025 SINTHETA2 = 0.95
00632   //                                      3 = DM2 0.002 SINTHETA2 = 0.95
00633                                                                                                                          
00634 
00635   //
00636   std::string priv="";
00637   std::string pub="";
00638                                                                                 
00639   std::string base="";
00640                                                                                 
00641   priv=getenv("SRT_PRIVATE_CONTEXT");
00642   pub = getenv("SRT_PUBLIC_CONTEXT");
00643                                                                                 
00644   if(priv == "" && pub == ""){
00645     std::cerr<<"No SRT_PUBLIC_CONTEXT set"<<std::endl;
00646     assert(false);
00647   }
00648                                                                                 
00649   priv += "/Mad/data/";
00650   pub  += "/Mad/data/";
00651                                                                                 
00652   struct stat ss;
00653   if(stat(priv.c_str(), &ss) == -1) {
00654    std::cout<<"Data not present in SRT_PRIVATE_CONTEXT trying SRT_PUBLIC"<<std::endl;
00655    if(stat(pub.c_str(), &ss) == -1) {
00656      std::cout<<"Data not present in SRT_PUBLIC - doesn't seem to exist"<<std::endl;
00657       assert(false);
00658    }else{ base = pub; }
00659   }else { base = priv; }
00660   
00661   if(det==Detector::kFar){  
00662     if(prior==1){ 
00663       if(fid==1) base+="weights_farle_cedar_daikon7v2.dat";    
00664       if(fid==2) base+="weights_farle_cedar_daikon7v2.dat";      
00665     }
00666     if(prior==2){ 
00667       if(fid==1) base+="weights_farle_cedar_daikon7v2.dat";    
00668       if(fid==2) base+="weights_farle_cedar_daikon7v2.dat";
00669     }
00670     if(prior==3){ 
00671       if(fid==1) base+="weights_farle_cedar_daikon7v2.dat";    
00672       if(fid==2) base+="weights_farle_cedar_daikon7v2.dat";
00673     }
00674   }
00675   else if(det==Detector::kNear){
00676     if(beam==BeamType::kL010z185i || beam==BeamType::kL000z200i || beam==BeamType::kL010z170i || beam==BeamType::kL010z200i)  base+="weights_nearle_cedar_daikon7v2.dat";    
00677     if(beam==BeamType::k100)  base+="weights_nearpme_cedar_daikon7v2.dat";    
00678     if(beam==BeamType::k250)  base+="weights_nearphe_cedar_daikon7v2.dat";    
00679   }
00680 
00681   if(stat(base.c_str(),&ss) == -1) {
00682     std::cerr<<"The file '"<<base<<"' doesn't seem to exist"<<std::endl;
00683     assert(false);
00684   }
00685 
00686   return base;
00687 }
00688 
00689 bool MadNsID::ChooseWeightFile(const Detector::Detector_t& det,
00690                                const BeamType::BeamType_t& beam, 
00691                                Int_t fid, Int_t prior){
00692   // look for the proper weight file
00693   // return true if we already have read it
00694   // or if we haven't read it but can find it
00695   if(det==cache_det && beam==cache_beam && 
00696      prior==cache_prior && fid==cache_fid){
00697     // no action needed
00698     return true;
00699   }
00700   
00701   weight_fname = GetWeightFileName(det,beam,fid,prior);
00702   // check if this file or directory exists
00703   Long_t id,size,flags,modtime;
00704   if(gSystem->GetPathInfo(weight_fname.c_str(),&id,&size,&flags,&modtime) == 1) {
00705     return false;
00706   }
00707   // check that it is a file and not a directory
00708   if(flags>1) return false;
00709   else {
00710     cache_det=det; cache_beam=beam; cache_prior=prior; cache_fid=fid;
00711     weights_read=false;
00712     return true;
00713   }
00714 }
00715 
00716 void MadNsID::SetWeightFile(const char* file){
00717   weight_fname = file;
00718 }
00719 
00720 bool MadNsID::GetPID(MadQuantities* mq, Int_t event, 
00721                      const Detector::Detector_t & det, Double_t& pid){
00722   AnnInputBlock ib;
00723   bool result=true;
00724   result = CalcVars(mq, event, ib);
00725   if(result) pid = CalcPID(ib,det);
00726   return result;
00727 }
00728 
00729 bool MadNsID::GetPID(NtpSREvent* ntpEvent, NtpSRTrack *ntpTrack,
00730                      NtpSRShower *ntpShower, NtpStRecord* st,
00731                      const Detector::Detector_t& det, Double_t& pid)
00732 {
00733   AnnInputBlock ib;
00734   bool result=true;
00735   result = CalcVars(ntpEvent, ntpTrack, ntpShower, st, ib);
00736   if(result) pid = CalcPID(ib,det);
00737   return result;
00738 }
00739 
00740 bool MadNsID::CompareAnnBlocks(MadQuantities* mq, Int_t event, const AnnInputBlock& ext){
00741   AnnInputBlock ib;
00742   CalcVars(mq, event, ib);
00743   if( !(ib==ext) ){
00744     std::cout<<"AnnInputBlocks disagree!!!"<<std::endl;
00745     std::cout<<"Event: "<<event<<std::endl;
00746     std::cout<<"This block: "<<std::endl;
00747     std::cout<<ib<<std::endl;
00748     std::cout<<"Other block: "<<std::endl;
00749     std::cout<<ext<<std::endl;
00750     return false;
00751   }
00752   else return true;
00753 }

Generated on Mon Feb 15 11:06:55 2010 for loon by  doxygen 1.3.9.1