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

MSTCalcAna.cxx

Go to the documentation of this file.
00001 #include "TH1F.h"
00002 #include "TF1.h"
00003 #include "TProfile2D.h"
00004 #include "TClonesArray.h"
00005 #include "StandardNtuple/NtpStRecord.h"
00006 #include "Conventions/PlaneView.h"
00007 #include "CandNtupleSR/NtpSRRecord.h"
00008 #include "CandNtupleSR/NtpSREvent.h"
00009 #include "CandNtupleSR/NtpSRTrack.h"
00010 #include "CandNtupleSR/NtpSRStrip.h"
00011 #include "MessageService/MsgService.h"
00012 #include "CalDetDST/UberRecord.h"
00013 #include "CalDetDST/UberHit.h"
00014 #include "NueAna/NueAnaTools/SntpHelpers.h"
00015 #include "NueAna/NueAnaTools/DCGraph.h"
00016 #include "NueAna/NueAnaTools/DCVertex.h"
00017 #include "NueAna/NueAnaTools/DCHit.h"
00018 #include "NueAna/MSTCalcAna.h"
00019 #include "NueAna/MSTCalc.h"
00020 #include "AnalysisNtuples/ANtpDefaultValue.h"
00021 
00022 TH1* eth=0;
00023 TH1* bth=0;
00024 
00025 CVSID("$Id: MSTCalcAna.cxx,v 1.13 2009/06/30 20:52:49 vahle Exp $");
00026 
00027 Double_t AFit(Double_t *x, Double_t *par){ 
00028    if(eth==0){
00029       return 0.;
00030    }
00031    if(bth==0){
00032       return 0.;
00033    }
00034    double xo = (*x);
00035    int sbin = eth->FindBin(xo,0.,0.);
00036    int bbin = bth->FindBin(xo,0.,0.);
00037    double sig = 1.*eth->GetBinContent(sbin);
00038    double back = 1.*bth->GetBinContent(bbin);
00039    return par[0]*sig+(1-par[0])*back;
00040 //   return par[0]*sig+par[1]*back;
00041 }
00042 
00043 MSTCalcAna::MSTCalcAna(MSTCalc &mst):
00044   fMSTCalc(mst),
00045   minsig(0.),
00046   maxmetric(0.),
00047   minfarsigcor(0.),
00048   maxmetriclowz(0.),
00049   even(),
00050   odd(),
00051   etemplate(0),
00052   btemplate(0),
00053   emtemplate(0),
00054   bmtemplate(0)
00055 {}
00056 
00057 MSTCalcAna::~MSTCalcAna()
00058 {
00059    for(unsigned int i=0;i<even.size();i++){
00060       if(even[i]!=0){
00061          delete even[i];
00062          even[i]=0;
00063       }
00064    }
00065    for(unsigned int i=0;i<odd.size();i++){
00066       if(odd[i]!=0){
00067          delete odd[i];
00068          odd[i]=0;
00069       }
00070    }
00071 }
00072 
00073 //void MSTCalcAna::Analyze(int evtn, NtpSRRecord *srobj, 
00074 //                       NtpMCRecord */*mc*/, NtpTHRecord */*th*/)
00075 void MSTCalcAna::Analyze(int evtn, RecRecordImp<RecCandHeader> *srobj)
00076 {
00077   set<DCHit> evenhitset;
00078   set<DCHit> oddhitset;
00079   Reset();
00080   FillHitSets(evtn,srobj,evenhitset,oddhitset);
00081   FindAllGraphs(evenhitset,oddhitset);
00082   ComputeGraphQuantities();
00083   //  cout<<"done with ana"<<endl;
00084 }
00085 
00086 void MSTCalcAna::Analyze(UberRecord *ur)
00087 {
00088   set<DCHit> evenhitset;
00089   set<DCHit> oddhitset;
00090   Reset();
00091   FillHitSets(ur,evenhitset,oddhitset);
00092   FindAllGraphs(evenhitset,oddhitset);
00093   ComputeGraphQuantities();
00094 }
00095 
00096 
00097 void MSTCalcAna::ComputeGraphQuantities()
00098 {
00099   //  cout<<"In computegraph"<<endl;
00100   //compute quantities
00101   fMSTCalc.enmsg=even.size();
00102   fMSTCalc.onmsg=odd.size();
00103 
00104   fMSTCalc.esmtot = 0.0;
00105   fMSTCalc.ewtot  = 0.0;
00106   fMSTCalc.enntot = 0;
00107   fMSTCalc.osmtot = 0.0;
00108   fMSTCalc.owtot  = 0.0;
00109   fMSTCalc.onntot = 0;
00110     
00111   const int NYBINS = etemplate->GetNbinsY()+1;
00112 
00113   TH1F ew("ew","ew",NYBINS-1,etemplate->GetYaxis()->GetXbins()->GetArray());
00114   TH1F ow("ow","ow",NYBINS-1,etemplate->GetYaxis()->GetXbins()->GetArray());
00115   
00116   const int NYMBINS = emtemplate->GetNbinsY()+1;
00117   TH1F em("em","em",NYMBINS-1,emtemplate->GetYaxis()->GetXbins()->GetArray());
00118   TH1F om("om","om",NYMBINS-1,emtemplate->GetYaxis()->GetXbins()->GetArray());
00119   
00120   for(unsigned int i=0;i<even.size();i++){
00121     if(even[i]==0){
00122       continue;
00123     }
00124     fMSTCalc.esmtot+=even[i]->GetSummedZ();
00125     fMSTCalc.ewtot+=even[i]->GetSummedMetric();
00126     fMSTCalc.enntot+=even[i]->GetNVerts();
00127   }
00128   for(unsigned int i=0;i<odd.size();i++){
00129     if(odd[i]==0){
00130       continue;
00131     }
00132     fMSTCalc.osmtot+=odd[i]->GetSummedZ();
00133     fMSTCalc.owtot+=odd[i]->GetSummedMetric();
00134     fMSTCalc.onntot+=odd[i]->GetNVerts();
00135   }
00136   
00137   DCGraph<DCHit> *me = GetMaxGraph(0);
00138   if(me!=0){
00139     fMSTCalc.esm1=me->GetSummedZ();
00140     fMSTCalc.ew1=me->GetSummedMetric();
00141     fMSTCalc.enn1=me->GetNVerts();                  
00142       vector<float> eweights = me->GetAllWeights();
00143       int NW=eweights.size();
00144       for(int i=0;i<NW;i++){
00145          if(NW<2880){
00146            fMSTCalc.eallw1[i] = eweights[i];
00147          }
00148          if(eweights[i]!=0){
00149             ew.Fill(eweights[i]);
00150          }
00151       }
00152 
00153       int nabove=0;
00154       float aveph=fMSTCalc.esm1/fMSTCalc.enn1;
00155       vector<float> emips = me->GetAllZ();
00156       int NM=emips.size();
00157       for(int i=0;i<NM;i++){
00158          if(NM<2880){
00159            fMSTCalc.eallm1[i] = emips[i];
00160          }
00161          em.Fill(emips[i]);
00162          if(emips[i]>aveph){
00163             nabove++;
00164          }
00165       }
00166       
00167       if(nabove>0){
00168          DCGraph<DCHit> *emax4 = me->GraphMaxHits(nabove);
00169          fMSTCalc.e4w = emax4->GetSummedMetric();
00170          fMSTCalc.e4sm = emax4->GetSummedZ();
00171          fMSTCalc.e4nn = emax4->GetNVerts();
00172          delete emax4;
00173       }
00174       else{
00175         fMSTCalc.e4w = ANtpDefVal::kFloat;
00176         fMSTCalc.e4sm = ANtpDefVal::kFloat;
00177         fMSTCalc.e4nn = 0;
00178       }  
00179   }
00180   GraphLoop(me,0);
00181   
00182 
00183   DCGraph<DCHit> *mo = GetMaxGraph(1);
00184   if(mo!=0){
00185     fMSTCalc.osm1=mo->GetSummedZ();
00186     fMSTCalc.ow1=mo->GetSummedMetric();
00187     fMSTCalc.onn1=mo->GetNVerts();                  
00188     vector<float> oweights = mo->GetAllWeights();
00189      int NW=oweights.size();
00190      for(int i=0;i<NW;i++){
00191        if(NW<2880){
00192          fMSTCalc.oallw1[i] = oweights[i];
00193        }
00194        if(oweights[i]!=0){
00195          ow.Fill(oweights[i]);
00196        }
00197      }
00198 
00199      int nabove=0;
00200      float aveph=fMSTCalc.osm1/fMSTCalc.onn1;
00201      vector<float> omips = mo->GetAllZ();
00202      int NM=omips.size();
00203      for(int i=0;i<NM;i++){
00204        if(NM<2880){
00205          fMSTCalc.oallm1[i] = omips[i];
00206        }
00207        om.Fill(omips[i]);
00208        if(omips[i]>aveph){
00209          nabove++;
00210        }
00211      }
00212      
00213      if(nabove>0){
00214        DCGraph<DCHit> *omax4 = mo->GraphMaxHits(nabove);
00215        fMSTCalc.o4w = omax4->GetSummedMetric();
00216        fMSTCalc.o4sm = omax4->GetSummedZ();
00217        fMSTCalc.o4nn = omax4->GetNVerts();
00218        delete omax4;
00219      }
00220      else{
00221        fMSTCalc.o4w=ANtpDefVal::kFloat;
00222        fMSTCalc.o4sm=ANtpDefVal::kFloat;
00223        fMSTCalc.o4nn=ANtpDefVal::kInt;
00224      }
00225   }
00226   GraphLoop(mo,1);
00227   
00228   if(etemplate==0||btemplate==0){
00229     MSG("MSTCalcAna",Msg::kError)<<"Template Histograms are not available"
00230                                  <<" can not calculate likelihoods"
00231                                  <<" or alphas"<<endl;
00232     fMSTCalc.eeprob=ANtpDefVal::kFloat;
00233      fMSTCalc.oeprob=ANtpDefVal::kFloat;
00234      fMSTCalc.ealpha=ANtpDefVal::kFloat;
00235      fMSTCalc.oalpha=ANtpDefVal::kFloat;
00236      fMSTCalc.ebeta=ANtpDefVal::kFloat;
00237      fMSTCalc.obeta=ANtpDefVal::kFloat;
00238      ew.Reset();
00239      ow.Reset();
00240      em.Reset();
00241      om.Reset();
00242 
00243      return;
00244    }
00245 
00246    TH1F *esigt = (TH1F *)FindProjection(etemplate,
00247                                         fMSTCalc.enn1,"esigt");
00248    TH1F *osigt = (TH1F *)FindProjection(etemplate,
00249                                         fMSTCalc.onn1,"osigt");
00250    TH1F *ebgt = (TH1F *)FindProjection(btemplate,
00251                                        fMSTCalc.enn1,"ebgt");
00252    TH1F *obgt = (TH1F *)FindProjection(btemplate,
00253                                        fMSTCalc.onn1,"obgt");
00254 
00255    int endof, ondof;
00256    fMSTCalc.eeprob = ComputeLLike(&ew,esigt,endof);
00257    fMSTCalc.oeprob = ComputeLLike(&ow,osigt,ondof);
00258 
00259 
00260    FindLikeAlpha(&ew,esigt,ebgt,fMSTCalc.ealpha,fMSTCalc.ebeta);
00261    FindLikeAlpha(&ow,osigt,obgt,fMSTCalc.oalpha,fMSTCalc.obeta);
00262 
00263    esigt->Reset();
00264    osigt->Reset();
00265    ebgt->Reset();
00266    obgt->Reset();
00267    
00268    ew.Reset();
00269    ow.Reset();
00270    em.Reset();
00271    om.Reset();
00272    //   cout<<"done with compute graph"<<endl;
00273 }
00274 
00275 void MSTCalcAna::FindAllGraphs(set<DCHit> &evenhitset, 
00276                                set<DCHit> &oddhitset)
00277 {
00278   //  cout<<"In findalagraphs"<<endl;
00279   DCGraph<DCHit> geven;
00280   DCGraph<DCHit> godd;
00281    set<DCHit>::reverse_iterator eit=evenhitset.rbegin();
00282    while(eit!=evenhitset.rend()){
00283      DCHit th=*eit;
00284      geven.AddVertex(&th);
00285      eit++;
00286    }
00287    
00288    set<DCHit>::reverse_iterator oit=oddhitset.rbegin();
00289    while(oit!=oddhitset.rend()){
00290       DCHit th=*oit;
00291       godd.AddVertex(&th);
00292       oit++;
00293    }
00294 
00295   if(geven.GetNVerts()!=0){
00296     even=geven.FindAllMinSpan(maxmetric,minfarsigcor,maxmetriclowz);
00297   }
00298   if(godd.GetNVerts()!=0){
00299     odd=godd.FindAllMinSpan(maxmetric,minfarsigcor,maxmetriclowz);
00300   }
00301   //  cout<<"done with findallgraphs"<<endl;
00302 }
00303 
00304 
00305 //void MSTCalcAna::FillHitSets(int evtn, NtpSRRecord *srobj, 
00306 //     set<DCHit> &evenhitset, set<DCHit> &oddhitset)
00307 void MSTCalcAna::FillHitSets(int evtn, RecRecordImp<RecCandHeader> *srobj, 
00308                              set<DCHit> &evenhitset, set<DCHit> &oddhitset)
00309 {
00310 
00311   //  cout<<"In fill hitsets"<<endl;
00312   if(srobj==0){
00313     return;
00314   }
00315   if(((dynamic_cast<NtpStRecord *>(srobj))==0)&&
00316      ((dynamic_cast<NtpSRRecord *>(srobj))==0)){
00317     return;
00318   }
00319 
00320 
00321   NtpSREvent *event = SntpHelpers::GetEvent(evtn,srobj);
00322   if(!event){
00323     MSG("MSTCalcAna",Msg::kError)<<"Couldn't get event "<<evtn
00324                                  <<" from Snarl "
00325                                  <<srobj->GetHeader().GetSnarl()
00326                                  <<endl;
00327     return;
00328   }
00329   
00330   //  cout<<"gotevent"<<endl;
00331   
00332   int nstrips=event->nstrip;
00333   //  cout<<"nstrips "<<nstrips<<endl;
00334   for(int i=0;i<nstrips;i++){
00335     Int_t index = SntpHelpers::GetStripIndex(i,event);
00336     NtpSRStrip *s = SntpHelpers::GetStrip(index,srobj);
00337     if(!s){
00338       continue;
00339     }
00340     if(!evtstp0mip){
00341        MSG("MSTCalcAna",Msg::kError)<<"No mip strip information"<<endl;
00342        continue;
00343     }
00344 
00345 
00346     float energy = evtstp0mip[index] + evtstp1mip[index];
00347     
00348     if(energy<minsig){
00349       continue;
00350     }
00351     
00352     double time = (evtstp0mip[index]*s->time0+
00353                    evtstp1mip[index]*s->time1);
00354     if(energy!=0){
00355       time/=(energy);
00356     }
00357     else{
00358       time=0.;
00359     }
00360     DCHit h(s->z*100.,s->tpos*100., energy,time);
00361     h.SetData("zpos","tpos","pulseheight");
00362     
00363     if(s->planeview==PlaneView::kU){
00364       evenhitset.insert(h);
00365     }
00366     else if(s->planeview==PlaneView::kV){
00367       oddhitset.insert(h);
00368     }
00369     else{
00370     }
00371   }
00372   //  cout<<"done fil hitsets"<<endl;
00373 }
00374 
00375 
00376 void MSTCalcAna::FillHitSets(UberRecord *ur,
00377                              set<DCHit> &evenhitset, 
00378                              set<DCHit> &oddhitset)
00379 {
00380 
00381   const TClonesArray *hits = ur->GetHitList();
00382   for(int i=0;i<ur->nhitstrips;i++){
00383     UberHit *uh=static_cast<UberHit *>((*hits)[i]);
00384     if(uh->GetPosMIP()+uh->GetNegMIP()<minsig){
00385       continue;
00386     }
00387     DCHit h(uh);
00388     h.SetData("zpos","tpos","pulseheight");
00389     
00390     if(uh->GetPlane()%2==0){
00391       evenhitset.insert(h);
00392     }
00393     else{
00394       oddhitset.insert(h);
00395     }
00396   }
00397 }
00398 
00399 void MSTCalcAna::Reset()
00400 {
00401    for(unsigned int i=0;i<even.size();i++){
00402       if(even[i]!=0){
00403          delete even[i];
00404          even[i]=0;
00405       }
00406    }
00407    for(unsigned int i=0;i<odd.size();i++){
00408       if(odd[i]!=0){
00409          delete odd[i];
00410          odd[i]=0;
00411       }
00412    }
00413    even.clear();
00414    odd.clear();
00415 
00416    fMSTCalc.Reset();
00417 }
00418 
00419 
00420 void MSTCalcAna::DrawMaxGraph(int view)
00421 {
00422    float maxmip=0.;
00423    int index=0;
00424    vector<DCGraph<DCHit> *> *g;
00425    if(view==0){
00426       g=&even;
00427    }
00428    else{
00429       g=&odd;
00430    }
00431    for(unsigned int i=0;i<g->size();i++){
00432       if((*g)[i]->GetSummedZ()>maxmip){
00433          maxmip=(*g)[i]->GetSummedZ();
00434          index=i;
00435       }
00436    }
00437    if(g->size()>0){
00438       (*g)[index]->Draw();
00439    }
00440 }
00441 
00442 DCGraph<DCHit> *MSTCalcAna::GetMaxGraph(int view)
00443 {
00444   //  cout<<"in getmaxgraph "<<view<<endl;
00445    float maxmip=0.;
00446    int index=0;
00447    vector<DCGraph<DCHit> *> *g;
00448    if(view==0){
00449       g=&even;
00450    }
00451    else{
00452       g=&odd;
00453    }
00454    if(g->size()==0){
00455       return 0;
00456    }
00457    for(unsigned int i=0;i<g->size();i++){
00458       if((*g)[i]->GetSummedZ()>maxmip){
00459          maxmip=(*g)[i]->GetSummedZ();
00460          index=i;
00461       }
00462    }
00463    return (*g)[index];
00464 }
00465 
00466 void MSTCalcAna::Print() const
00467 {
00468   fMSTCalc.Print();
00469 }
00470 
00471 TH1D *MSTCalcAna::FindProjection(TProfile2D *tmplt, int n, const char* name)
00472 {
00473 //   string n2d=(string)(name)+"_2d";
00474 //   TH2D *proj2d = tmplt->ProjectionXY(n2d.c_str(),"E");
00475    int bin = tmplt->GetXaxis()->FindFixBin(n);
00476    TH1D *proj = tmplt->ProjectionY(name,bin,bin,"E,goff");
00477 //   delete proj2d;
00478 //   proj->Sumw2();
00479    return proj;
00480 }
00481 
00482 double MSTCalcAna::ComputeChi2(TH1 *h1, TH1 *h2, 
00483                               double &chi2, int &ndof)
00484 {
00485    chi2=0.;
00486    double NENTH1=h1->Integral();
00487    double NENTH2=h2->Integral();
00488 
00489    ndof = 0;
00490    if(NENTH2==0||NENTH1==0){
00491       chi2=-1.;
00492       ndof=0;
00493       return -1.;
00494    }
00495    
00496 //   double weight1 = sqrt(NENTH2/NENTH1);
00497 //   double weight2 = sqrt(NENTH1/NENTH2);
00498 
00499 
00500    double weight1 = 1.;
00501    double weight2 = 1.;
00502    for(int i=1;i<=h1->GetNbinsX();i++){
00503       double h1bc=h1->GetBinContent(i);
00504       double h2bc=h2->GetBinContent(i);
00505       double eh1bc=h1->GetBinError(i);
00506       double eh2bc=h2->GetBinError(i);
00507       
00508       double num = pow((weight1*h1bc-weight2*h2bc),2);
00509       double denom = eh1bc*eh1bc+eh2bc*eh2bc;
00510 
00511       if(denom!=0){
00512          chi2+=num/denom;
00513          ndof++;
00514       }
00515    }
00516    ndof--; //one constraint, number of entries must be equal to n
00517    Double_t prob = TMath::Prob(chi2/2.,Int_t(ndof/2.));
00518 
00519    return prob;
00520 }
00521 
00522 double MSTCalcAna::ComputeLLike(TH1 *data, TH1 *tmpl, int &ndof)
00523 {
00524 
00525    if(data==0){
00526       return ANtpDefVal::kFloat;
00527    }
00528    if(tmpl==0){
00529       return ANtpDefVal::kFloat;
00530    }
00531    if(data->Integral()<2){
00532       return ANtpDefVal::kFloat;
00533    }
00534    if(data->GetNbinsX()!=tmpl->GetNbinsX()){
00535      MSG("MSTCalcAna",Msg::kError)<<"Data bins "
00536                                   <<data->GetNbinsX()<<endl
00537                                   <<"Template bins "
00538                                   <<tmpl->GetNbinsX()<<endl
00539                                   <<"Can not do likelihood"<<endl;
00540      return ANtpDefVal::kFloat;
00541    }
00542    
00543    ndof=0;
00544    double llike=0.;
00545 
00546    for(int i=1;i<=tmpl->GetNbinsX();i++){
00547       float x = data->GetBinContent(i);
00548       float mu = tmpl->GetBinContent(i);
00549       double l=0.;
00550       if(x>0&&mu>0){
00551          l=x*(TMath::Log(mu)-TMath::Log(x)+1)-mu;
00552       }
00553       else if(x==0&&mu!=0){
00554          l=-mu;
00555       }
00556       else if(x!=0&&mu==0){
00557          l=0.;
00558       }
00559       else{
00560          l=0.;
00561       }
00562          
00563       if(x!=0){
00564          ndof+=(int)(x);
00565       }
00566       llike+=l;    
00567 
00568    }
00569 
00570    double chi2 = -2*llike;
00571    return chi2;
00572 }
00573 
00574 float MSTCalcAna::FindAlpha(TH1 *data, TH1 *ehist,TH1 *bhist)
00575 {
00576 
00577    if(data==0){      
00578       MSG("MSTCalcAna",Msg::kError)<<"data==0"<<endl;
00579       return ANtpDefVal::kFloat;
00580    }
00581    if(ehist==0){
00582       MSG("MSTCalcAna",Msg::kError)<<"ehist==0"<<endl;
00583       return ANtpDefVal::kFloat;
00584    }
00585    if(bhist==0){
00586       MSG("MSTCalcAna",Msg::kError)<<"bhist==0"<<endl;
00587       return ANtpDefVal::kFloat;
00588    }
00589 
00590    double num=0.;
00591    double denom=0.;
00592    double error=0.;
00593    float ea=0.;
00594    if(data->GetNbinsX()==ehist->GetNbinsX()&&
00595       data->GetNbinsX()==bhist->GetNbinsX()){
00596       for(int i=1;i<=data->GetNbinsX();i++){
00597          double n=1.*data->GetBinContent(i);
00598          double c=1.*ehist->GetBinContent(i);
00599          double d=1.*bhist->GetBinContent(i);
00600          double en=1.*data->GetBinError(i);
00601          double ec=1.*ehist->GetBinError(i);
00602          double ed=1.*bhist->GetBinError(i);
00603 
00604          error = en*en+ec*ec+ed*ed;
00605          if(error!=0){
00606             num+=(d-n)*(d-c)/error;
00607             denom+=(d-c)*(d-c)/error;
00608          }
00609       }
00610       if(denom>1.e-10){
00611          ea=num/denom;
00612       }
00613       else{
00614          ea=ANtpDefVal::kFloat;
00615       }
00616    }
00617    return ea;
00618 
00619 }
00620 
00621 
00622 void MSTCalcAna::FindLikeAlpha(TH1 *data, TH1 *ehist,TH1 *bhist, 
00623                               double &alpha, double &beta)
00624 {
00625 
00626    if(data==0){      
00627       MSG("MSTCalcAna",Msg::kError)<<"data==0"<<endl;
00628       alpha=ANtpDefVal::kFloat;
00629       beta=ANtpDefVal::kFloat;
00630       return;
00631    }
00632    if(ehist==0){
00633       MSG("MSTCalcAna",Msg::kError)<<"ehist==0"<<endl;
00634       alpha=ANtpDefVal::kFloat;
00635       beta=ANtpDefVal::kFloat;
00636       return;
00637    }
00638    if(bhist==0){
00639       MSG("MSTCalcAna",Msg::kError)<<"bhist==0"<<endl;
00640       alpha=ANtpDefVal::kFloat;
00641       beta=ANtpDefVal::kFloat;
00642       return;
00643    }
00644 
00645    if(data->GetNbinsX()!=ehist->GetNbinsX()){
00646       MSG("MSTCalcAna",Msg::kError)<<"Data bins: "
00647                                    <<data->GetNbinsX()<<endl
00648                                    <<"etemplate bins: "
00649                                    <<ehist->GetNbinsX()<<endl
00650                                    <<"Cant do like alpha"<<endl;
00651       alpha=ANtpDefVal::kFloat;
00652       beta=ANtpDefVal::kFloat;
00653       return;
00654    }
00655    if(data->GetNbinsX()!=bhist->GetNbinsX()){
00656       MSG("MSTCalcAna",Msg::kError)<<"Data bins: "
00657                                    <<data->GetNbinsX()<<endl
00658                                    <<"btemplate bins: "
00659                                    <<bhist->GetNbinsX()<<endl
00660                                    <<"Cant do like alpha"<<endl;
00661       alpha=ANtpDefVal::kFloat;
00662       beta=ANtpDefVal::kFloat;
00663       return;
00664    }
00665    eth=ehist;
00666    bth=bhist;
00667 
00668    TF1 *histfit = new TF1("histfit",AFit,0,100,1);
00669    histfit->SetParName(0,"alpha");
00670    histfit->SetParameter(0,0.9);
00671    histfit->SetParLimits(0,0.,1.);
00672 
00673    data->Fit(histfit,"RLQNO");
00674 //   data->Fit(histfit,"RIL");
00675    
00676    alpha = histfit->GetParameter(0);
00677    beta = histfit->GetParError(0);
00678       
00679    if(histfit!=0){
00680      delete histfit;
00681      histfit=0;
00682    }
00683    return;
00684 }
00685 
00686 void MSTCalcAna::GraphLoop(DCGraph<DCHit> *g, int view)
00687 {
00688   //  cout<<"in graph loop "<<view<<endl;
00689   if(g==0){
00690     return;
00691   }
00692 
00693   float mipsum=0;
00694   float b1mipsum=0;
00695   float b25mipsum=0;
00696   int nbranch=0;
00697   DCVertex<DCHit> *v = g->GetFirst();
00698   while(v!=0){
00699     DCEdge<DCHit> *e = v->GetFirstEdge();
00700     float vx1,vy1,vz1;
00701     v->GetData()->GetData(vx1,vy1,vz1);
00702     int nedge=0;
00703     while(e!=0){
00704       float vx2=0,vy2=0,vz2=0;
00705       e->GetEnd()->GetData()->GetData(vx2,vy2,vz2);
00706       if(e->GetMetric()<5){
00707         b1mipsum+=vz1+vz2;
00708       }
00709       if(e->GetMetric()>25){
00710         b25mipsum+=vz1+vz2;
00711       }
00712       mipsum+=vz1+vz2;
00713       nedge++;
00714       e=e->GetNext();
00715     }
00716     if(nedge>1){ nbranch++; }
00717     v=v->GetNextVertex();
00718   }
00719 
00720 
00721   if(view==0){
00722     if(mipsum>0){
00723       fMSTCalc.eb1=b1mipsum/mipsum;
00724       fMSTCalc.eb25=b25mipsum/mipsum;
00725     }
00726     fMSTCalc.enbranch=nbranch;
00727   }
00728   else if(view==1){
00729     if(mipsum>0){
00730       fMSTCalc.ob1=b1mipsum/mipsum;
00731       fMSTCalc.ob25=b25mipsum/mipsum;
00732     }
00733     fMSTCalc.onbranch=nbranch;
00734   }
00735   //  cout<<"done with graph loop"<<endl;
00736 }

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