Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

AlToolBox.cpp

Go to the documentation of this file.
00001 
00002 //
00003 // Implementation of the Tool Box.
00004 //
00005 // Author :  C. Delaere
00006 //
00008 
00009 #include "AlToolBox.h"
00010 #include "AlephCollection.h"
00011 #include "fortran_def.h"
00012 #include "AlBjet.h"
00013 #include "AlEflw.h"
00014 #include "AlTrack.h"
00015 #include "AlphaBanks.h"
00016 #include "AlJet.h"
00017 
00018 pair<AlephCollection<AlBjet>,vector<float> > AlToolBox::TagBjets(AlphaBanks* banks )
00019 {
00020         int Error =0;
00021         int NumberOfJets =0;
00022         int NumberOfTracks =0;
00023         float Xjets[40] ={0};
00024         float Yjets[40] ={0};
00025         float Zjets[40] ={0};
00026         float Ejets[40] ={0};
00027         int TracksUsed[400] ={0};
00028         float TracksProba[400] ={0};
00029         int EflwsInJets[400] ={0};
00030         int JetsOfEflws[400] ={0};
00031         float JetProba[40] ={0};
00032         float HemiProba[2] ={0};
00033         float EventProba =0;
00034         F_QIPBTAG(Error,NumberOfJets,NumberOfTracks,Xjets,Yjets,Zjets,Ejets,TracksUsed,
00035                         TracksProba,EflwsInJets,JetsOfEflws,JetProba,HemiProba,EventProba);
00036         pair<AlephCollection<AlBjet>,vector<float> > output;
00037         AlephCollection<AlBjet> thejets;
00038         vector<float> values(banks->TrackPV().size()+1);
00039         if(Error==0)
00040         {
00041                 values[values.size()-1] = EventProba;
00042                 for(int i=0;i<NumberOfTracks;i++)
00043                 {
00044                         if (TracksUsed[i]<=(int)values.size())
00045                                 values[TracksUsed[i]-1] = TracksProba[i];
00046                         else    values.push_back(TracksProba[i]);
00047                 }
00048                 for(int i=0;i<NumberOfJets;i++)
00049                 {
00050                         AlBjet myBjet;
00051                         myBjet.setA4V(Xjets[i],Yjets[i],Zjets[i],Ejets[i]);
00052                         myBjet.setBprobability(JetProba[i]);
00053                         myBjet.setScheme(1);
00054                         myBjet.setMetric(0);
00055                         thejets.push_back(myBjet);
00056                 }
00057                 for(unsigned int i=0;i<banks->EflwPV().size();i++)
00058                         if (JetsOfEflws[i]!=0) 
00059                                 thejets[JetsOfEflws[i]-1].addObject(banks->EflwPV()[EflwsInJets[i]]);
00060         }
00061         output.first=thejets;
00062         output.second=values;
00063         return output;
00064 }
00065 AlephCollection<AlBjet> AlToolBox::ComputeBprobability(AlephCollection<AlJet*>* thejets, AlphaBanks* banks,bool negprob=false)
00066 {
00067         // call QIPBTAG to get tracks probabilities
00068         pair<AlephCollection<AlBjet>,vector<float> > qipbtags = TagBjets( banks );
00069         // computes log factorials
00070         float logfac[401] = {0};
00071         for(int i=1;i<=400;i++) logfac[i] = logfac[i-1] + log(i);
00072         // some initialisations and declarations
00073         float sumjet[thejets->size()];
00074         int   ntrk_jet[thejets->size()];
00075         for (unsigned int i=0;i<thejets->size();i++) sumjet[i]=ntrk_jet[i]=0;
00076         // computes de probabilities products
00077         AlephCollection<AlTrack*> allthetracks = banks->TrackPV();
00078         AlephCollection<AlEflw*>  alltheeflws  = banks->EflwPV();
00079         int indexofthetrack = 0;
00080         for( AlephCollection<AlTrack*>::iterator itrack = allthetracks.begin(); itrack<allthetracks.end();itrack++,indexofthetrack++)
00081         {
00082                 AlEflw* theasseflw = (*itrack)->getEflw();
00083                 int ijet = 0;
00084                 for(AlephCollection<AlJet*>::iterator jet = thejets->begin(); jet<thejets->end();jet++,ijet++)
00085                 {
00086                         vector<AlObject*>  thejeteflws = (*jet)->getObjects();
00087                         for(vector<AlObject*>::iterator ieflw = thejeteflws.begin(); ieflw<thejeteflws.end();ieflw++)
00088                                 if (((AlEflw*)(*ieflw))==theasseflw)
00089                                 {
00090                                         float thetrack = qipbtags.second[indexofthetrack];      
00091                                         if ((negprob)&&(thetrack!=0))
00092                                         {
00093                                                 sumjet[ijet] += ((thetrack>0) ? log(thetrack/2) : log(1+thetrack/2));
00094                                                 ntrk_jet[ijet]++;
00095                                         }
00096                                         else if (thetrack>0)
00097                                         {
00098                                                 sumjet[ijet] += log(thetrack);
00099                                                 ntrk_jet[ijet]++;
00100                                         }
00101                                 }
00102                 }
00103         }
00104         // normalize the probability product for the number of measurements made
00105         int ijet=0;
00106         float loginvlog;
00107         float proba = 0;
00108         AlephCollection<AlBjet> result;
00109         for(AlephCollection<AlJet*>::iterator jet = thejets->begin(); jet<thejets->end();jet++,ijet++)
00110         {
00111                 if(sumjet[ijet]<0)
00112                 {
00113                         if((ntrk_jet[ijet]-1)>=1)
00114                                 loginvlog = log(-sumjet[ijet]);
00115                         for(int i=1;i<ntrk_jet[ijet];i++)
00116                                 proba += exp(i*loginvlog-logfac[i]);
00117                         float logproba = log(proba) + sumjet[ijet];
00118                         proba = exp((logproba>-50) ? logproba : -50) ;
00119                         proba = ((proba<1) ? proba : 1) ;
00120                 }
00121                 else
00122                         proba = 1;
00123                 result.push_back(AlBjet(**jet,proba));
00124         }
00125         // done
00126         return result;
00127 }

Generated at Wed Jun 18 17:19:11 2003 for ALPHA++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001