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

FillShortVar.cxx

Go to the documentation of this file.
00001 // C/C++
00002 #include <cmath>
00003 #include <iostream>
00004 #include <numeric>
00005 #include <sstream>
00006 // MINOS
00007 #include "Registry/Registry.h"
00008 #include "Calibrator/Calibrator.h"
00009 #include "Plex/PlexStripEndId.h"
00010 #include "Registry/Registry.h"
00011 #include "UgliGeometry/UgliGeomHandle.h"
00012 #include "Validity/VldContext.h"
00013 
00014 // Local
00015 #include "PhysicsNtuple/Default.h"
00016 #include "PhysicsNtuple/Factory.h"
00017 // Local
00018 #include "FillShortVar.h"
00019 
00020 REGISTER_ANP_OBJECT(AlgSnarl,FillShortVar) 
00021 
00022 using namespace std;
00023 //---------------------------------------------------------------------------------------
00024 Anp::FillShortVar::FillShortVar()
00025   :fMinNPlane(4),
00026    fMaxNPlane(20),
00027    fEndNPlane(5),
00028    fKeyBase(14600),
00029    fTimeWindow(2.0*(18.83 + 0.1)*1.0e-9),
00030    fStripWindow(4),
00031    fMinStripADC(200.0),
00032    fMinStripMIP(0.3),
00033    fFillEvent(false),
00034    fDebug(false),
00035    fErase(false),
00036    fqeltrack(false),
00037    ftruelowE(-10),
00038    frecolowE(-10),
00039    fselectsign(0),
00040    fNTrackAll(0),
00041    fNTrackAdd(0)
00042 {
00043 }
00044 
00045 //------------------------------------------------------------------------------------------
00046 Anp::FillShortVar::~FillShortVar()
00047 {
00048 }
00049 //------------------------------------------------------------------------------------------
00050 bool Anp::FillShortVar::Run(Record &record)
00051 { 
00052   map<short,const DataMap> track_dmap;
00053   DataMap dmap1, dmap2,dmap3;
00054   DataMap  dmap;
00055   TrackIterator itrack = record.TrackBegIterator(); 
00056  
00057   //
00058   // Iterate over tracks       
00059   //
00060   while(itrack != record.TrackEndIterator())
00061   { 
00062     if(IsGoodTrack(itrack,record))
00063     {
00064       dmap.clear();
00065       if(FillShortVar::Study(*itrack, record,dmap1,"SIGCOR"))FillShortVar::Fill(dmap,dmap1,0);
00066       if(FillShortVar::Study(*itrack, record,dmap2,"SIGMAP"))FillShortVar::Fill(dmap,dmap2,100);
00067       if(FillShortVar::Study(*itrack, record,dmap3,"MIP"))   FillShortVar::Fill(dmap,dmap3,200);
00068       
00069       if(dmap.size()>0)
00070         {
00071           for(DataMap::const_iterator dit = dmap.begin(); dit!=dmap.end(); dit++)         
00072             itrack->Add(dit->first+fKeyBase,dit->second);       
00073           
00074           if(!track_dmap.insert(map<short, const DataMap>::value_type(itrack -> TrackIndex(), dmap)).second)
00075           {
00076               cerr << "FillShortVar::Run - duplicate track index " << itrack -> TrackIndex() << endl;
00077           }
00078           
00079           ++fNTrackAdd;
00080         }
00081       itrack++;
00082     }
00083     else{
00084       if(fDebug) cout<<" FillShortVar:: Run - This track is bad"<<endl;
00085       if(fErase) itrack = record.Erase(itrack);
00086       else ++itrack;
00087     }
00088     ++fNTrackAll;        
00089   }
00090    //
00091    // Delete events that do not match tracks
00092    //
00093 
00094   if(!fErase  && (!fFillEvent || track_dmap.empty()))  return true;
00095 
00096    for ( EventIterator ievent = record.EventBegIterator(); ievent !=record.EventEnd();)
00097    {     
00098      const TrackVec tvec = Anp::GetTrack(*ievent, record);
00099      if(fErase &&ievent->GetNTracks()>0 &&(tvec.size()==0||(int)tvec.size()!=ievent->GetNTracks() ))
00100        {
00101          ievent=record.Erase(ievent);
00102          continue;
00103        }
00104 
00105        if(fFillEvent) 
00106        {
00107          TrackIter titer =Anp::LongestTrack(*ievent,record);
00108          map<short, const DataMap>::const_iterator dit = track_dmap.find(titer -> TrackIndex());
00109 
00110          if(dit == track_dmap.end())
00111            {
00112              cerr << "FillShortVar::Run - failed to find track index " << titer -> TrackIndex() << endl;
00113              ievent++;
00114              continue;
00115            }
00116          const DataMap &dmap = dit -> second;
00117 
00118          for(DataMap::const_iterator it = dmap.begin(); it != dmap.end(); ++it)ievent -> Add(it -> first+fKeyBase, it -> second);
00119 
00120        }
00121        ievent++;
00122    }   
00123    return true;
00124 }
00125 
00126 //-----------------------------------------------------------------------------
00127 void Anp::FillShortVar::Config(const Registry &reg)
00128 {
00129    //
00130    // Configure self
00131    //
00132 
00133    reg.Get("FillShortVarMinNPlane",  fMinNPlane);
00134    reg.Get("FillShortVarMaxNPlane",  fMaxNPlane);
00135    reg.Get("FillShortVarEndNPlane",  fEndNPlane);
00136    reg.Get("FillShortVarKeyBase",    fKeyBase);
00137 
00138    reg.Get("FillShortVarMinStripAdc", fMinStripADC);
00139    reg.Get("FillShortVarMinStripMip", fMinStripMIP);
00140    reg.Get("FillShortVarTimeWindow", fTimeWindow);
00141 
00142    //
00143    // Read bool and string variables
00144    //
00145                                                                                           
00146    Anp::Read(reg, "FillShortVarEvent",    fFillEvent);
00147    Anp::Read(reg, "FillShortVarDebug",    fDebug);
00148    Anp::Read(reg, "FillShortVarErase",    fErase);
00149    Anp::Read(reg, "FillShortVarQELTrack", fqeltrack);
00150 
00151    // Extra Configurations
00152    reg.Get( "FillShortVarLowTrueE", ftruelowE);
00153    reg.Get( "FillShortVarLowRecoE", frecolowE);
00154    reg.Get( "FillShortVarSelectSign", fselectsign);
00155    if(reg.KeyExists("PrintConfig"))
00156    {
00157       cout << "FillShortVar::Config" << endl
00158            << "   MinNPlane = " << fMinNPlane << endl
00159            << "   MaxNPlane = " << fMaxNPlane << endl
00160            << "   EndNPlane = " << fEndNPlane << endl
00161            << "   KeyBase = " << fKeyBase << endl
00162            << "   MinStripADC = " << fMinStripADC << endl
00163            << "   MinStripMIP = " << fMinStripMIP<< endl
00164            << "   SelectSign = " << fselectsign<< endl
00165            << "   TimeWindow = " << fTimeWindow << endl
00166            << "   Debug = " << fDebug << endl
00167            << "   Erase = " << fErase << endl
00168            << "   QELTrack  ="<< fqeltrack << endl
00169            << "   trueE Upper Limit  ="<< ftruelowE << endl
00170            << "   RecoE Upper Limit  ="<< frecolowE << endl;
00171 
00172    }
00173 }
00174 //-----------------------------------------------------------------------------
00175 void Anp::FillShortVar::End(const DataBlock &)
00176 {
00177       cout << "   NTrackAll = " << fNTrackAll << endl
00178            << "   NTrackAdd = " << fNTrackAdd << endl;
00179 }
00180 //-----------------------------------------------------------------------------
00181 bool Anp::FillShortVar::Study(Track &track, const Record &record, DataMap &dmap,string StripMin)
00182 {  
00183   if(fDebug) cout<<" FillShortVar::Study - START! with StripChargeCut "<<StripMin<<endl;
00184   //
00185   // check total number of planes in track given by track container
00186   //  
00187   double last_plane=-1; double first_plane=-1; double sum_ph=0.0;   double sum_strip =0.0;
00188   double trk_ph = 0.0;  double now_ph =0.0;    double now_oph=0.0;  double last_ph=0.0;
00189   double l_ph = 0.0;    int l_ph_plane =0;     int count_plane = 0;
00190   int Ibase=20;
00191   int Sbase=30;
00192 
00193   double minStripPH=FillShortVar::GetStripChargeCut(StripMin);
00194   if(minStripPH<0) return false;
00195    
00196   if((track.GetBasic().NPlaneScint() < fMinNPlane)||
00197      (track.GetBasic().NPlaneScint() > fMaxNPlane && fMaxNPlane >0)||
00198      (track.GetBasic().NPlaneScint() < fEndNPlane))
00199     {
00200       return false;
00201     }
00202   
00203   dmap[0]=minStripPH;         
00204   
00205   //==================== Get Track Map===================
00206    PlaneMap track_map; 
00207    std::map<int,float> o_mean;
00208    if(!GetTrackMap(track,record,track_map,o_mean,StripMin))
00209    {
00210      return false;
00211    }
00212    //===check number of planes in track with PH cut======   
00213    const int nplane = static_cast<int>(track_map.size());
00214    if((nplane < fMinNPlane) ||
00215       (nplane > fMaxNPlane && fMaxNPlane>0)||
00216       (nplane < fEndNPlane))
00217    {
00218      return false;
00219    }
00220    //===Run through track map and find Analysis variables=
00221    for(PlaneMap::reverse_iterator pit = track_map.rbegin(); pit != track_map.rend(); ++pit)
00222    {
00223      ++count_plane;
00224       const unsigned short plane = pit -> first;
00225       if(last_plane ==-1) last_plane= plane;
00226       if(plane< last_plane) first_plane = plane;
00227       now_ph=0.0;
00228    
00229       vector<StripIter> &tvec = pit -> second;
00230       for(vector<StripIter>::iterator it = tvec.begin(); it!=tvec.end(); it++)
00231       {
00232         now_ph+= TrackStripEnergy((*it),track.TrackIndex(),StripMin);   
00233       }
00234 
00235       vector<StripIter>  ovec = Get(track, plane, record,o_mean,StripMin);
00236 
00237       for(vector<StripIter>::iterator oit = ovec.begin(); oit!=ovec.end(); oit++)
00238       {       
00239         double wpos =GetWPos((*oit)->GetPlane(),o_mean);
00240         double ovec_sc= OtherStripEnergy(*oit,GetVldc(record.GetHeader()),wpos,StripMin);
00241         if(ovec_sc> minStripPH) now_oph +=ovec_sc;              
00242       }
00243 
00244       // If you are at the end of the track
00245       if(count_plane>fEndNPlane) break;
00246       
00247       sum_ph+=(now_ph + now_oph);
00248       trk_ph+=now_ph;      
00249       sum_strip +=tvec.size();            
00250       last_ph=now_ph;      
00251       dmap[count_plane] =sum_ph;
00252       dmap[count_plane+10]= trk_ph;      
00253             
00254       if(now_ph+now_oph>l_ph)
00255       { 
00256         l_ph=now_ph + now_oph;
00257         l_ph_plane=count_plane;
00258       }           
00259    }
00260    
00261    dmap[Ibase+1]  = trk_ph/sum_ph;
00262    dmap[Ibase+2]  = sum_ph/sum_strip;
00263    dmap[Ibase+3]  = l_ph_plane;
00264    dmap[Ibase+4]  = l_ph;
00265 
00266 
00267    //==== Get track scatter quantities===============
00268    // Straggling
00269    // Straightness
00270 
00271    float pearu=0.0;    float pearv=0.0;
00272    float pearmodu=0.0; float pearmodv=0.0;
00273    
00274    
00275    if( FillShortVar::GetScatter(track_map, pearu,pearmodu, 1)&&
00276        FillShortVar::GetScatter(track_map, pearv,pearmodv, 2))
00277      {
00278        if(pearu>1.00) pearu=1.0;
00279        if(pearv>1.00) pearv=1.0;
00280        if(pearmodu>1.00) pearmodu=1.0;
00281        if(pearmodv>1.00) pearmodv=1.0;
00282        
00283        float scatu_1 = 0.01/(1.010-pearmodu);
00284        float scatv_1 = 0.01/(1.010-pearmodv);
00285        float scatu_2 = 0.01/(1.010-pearu);
00286        float scatv_2 = 0.01/(1.010-pearv);
00287        if(scatu_1>1.0 || scatv_1>1.0 ||scatu_2>1.0 || scatv_2>1.0){
00288          cerr<<"FillShortVar::Study - scattering variables greater than 1.0"<<endl;
00289        }
00290        dmap[Sbase+3]  = scatu_1;     
00291        dmap[Sbase+5]  = scatu_2;   
00292        dmap[Sbase+4]  = scatv_1;
00293        dmap[Sbase+6]  = scatv_2;
00294 
00295         dmap[Sbase+7]  = track.QP();
00296        if(pearmodu >0 || pearmodv>0)dmap[Sbase+8]  = 2*(pearmodu*pearmodv)/(pearmodu*pearmodu+pearmodv*pearmodv);
00297        else dmap[Sbase+8]  = 0.5;
00298        dmap[Sbase+9]  = track.QP()/track.ErrorQP();
00299      }
00300    return true;
00301 }
00302 
00303 //-----------------------------------------------------------------------------
00304 std::vector<Anp::StripIter> Anp::FillShortVar::Get(const Track &track,  const unsigned short plane, 
00305                                                    const Record &record, std::map<int,float> other_map,string StripMin) const
00306 {
00307   //
00308   // Collect all non-track strips in a given plane within window after some given cuts   
00309   //  
00310   vector<StripIter> svec;
00311   int min_strip=-1;  int max_strip=-1;
00312 
00313   double minStripPH = FillShortVar::GetStripChargeCut(StripMin);
00314   if(minStripPH<0)  return svec;
00315   
00316    for(StripIter istrip = record.StripBeg(); istrip != record.StripEnd(); ++istrip)
00317    {
00318      if(istrip -> GetPlane() != plane)  continue;
00319      
00320      if(istrip -> MatchTrk(track.TrackIndex()))
00321      {
00322        if(min_strip<0 || min_strip > istrip->GetStrip()) min_strip = istrip->GetStrip();
00323        if(max_strip<0 || max_strip < istrip->GetStrip()) max_strip = istrip->GetStrip();
00324        continue;
00325      }
00326      if(fTimeWindow > 0.0)
00327      {
00328        if(istrip->Time() < track.GetBasic().MinTime() - fTimeWindow ||
00329           istrip->Time() > track.GetBasic().MaxTime() + fTimeWindow)
00330          continue;     
00331      }
00332       svec.push_back(istrip);
00333    }
00334    std::vector<Anp::StripIter>::iterator si = svec.begin() ;
00335    while(si!=svec.end()){
00336      if((*si)->GetStrip() > max_strip+fStripWindow || (*si)->GetStrip()< min_strip-fStripWindow)  si=svec.erase(si);
00337      else si++;
00338    }
00339    return svec;
00340 }
00341 //-------------------------------------------------------------------------
00342 bool Anp::FillShortVar::GetTrackMap(Track& track, const Record& record,PlaneMap& track_map, 
00343                                     std::map<int,float>& other_map,string StripMin) const
00344 {
00345   //
00346   // collect all track strips in a plane and insert plane, vector into the 'plane map'
00347   //  find the average position of all track (and near?) strips
00348   //
00349   double minStrip= GetStripChargeCut(StripMin);
00350   int  Uview=0;
00351   int  Vview=0;
00352   PlaneMap o_map;
00353   for(StripIter istrip = record.StripBeg(); istrip != record.StripEnd(); ++istrip)
00354   {
00355 
00356     // seperate strips in record not from track
00357     bool istrack = istrip -> MatchTrk(track.TrackIndex());       
00358     if(!istrack) continue;
00359     // Ignore  non calorimeter strips/events
00360     if(record.GetHeader().IsNear() && istrip -> GetPlane() > 120 && istrack) return false;     
00361     
00362     if(TrackStripEnergy(istrip,track.TrackIndex(),StripMin)>minStrip){  
00363       vector<StripIter> &svec = track_map[istrip -> GetPlane()]; 
00364       svec.push_back(istrip);                                           
00365       if(istrip->IsUview()) Uview++;
00366       if(istrip->IsVview()) Vview++;
00367     }          
00368   }
00369                                                                                                                         
00370   for(PlaneMap::iterator track_it =track_map.begin(); track_it!=track_map.end(); track_it++)   
00371     {
00372       float strip_mean =0.0;
00373       const std::vector<StripIter>  tsvec = track_it->second;
00374       for(std::vector<StripIter>::const_iterator it = tsvec.begin(); it!= tsvec.end(); it++){
00375         strip_mean += (*it) -> TPos();  
00376       }
00377       strip_mean /=(float) tsvec.size();
00378       other_map [track_it->first]= strip_mean;
00379     }
00380 
00381   if(Uview<=0 || Vview<=0){
00382     if(fDebug) cout<<" No track hits in  view  (hits in U, hits in V) = ("<<Uview<<","<<Vview<<")"<<endl;
00383     return false;
00384   }
00385 
00386   return true;
00387 }
00388 //-------------------------------------------------------------------------
00389 bool Anp::FillShortVar::GetScatter(PlaneMap track_map, float& pear,
00390                                    float& dpear, int keyview) const 
00391 {
00392 
00393   double TPos_mean =0.0000;  double ZPos_mean =0.0000;   double TPos2_mean =0.0000;  double ZPos2_mean =0.000000;
00394   double TPosZPos_mean =0.0000;
00395 
00396   int count=0; 
00397 
00398   for(PlaneMap::iterator pit = track_map.begin(); pit != track_map.end(); ++pit){
00399    vector<StripIter> &vec = pit->second;
00400     if((vec[0]->IsUview() &&!(keyview==1)) ||(vec[0]->IsVview() &&!(keyview==2))) continue; 
00401 
00402     for(vector<StripIter>::iterator ivec = vec.begin(); ivec!=vec.end() ; ivec++)
00403     {
00404       double tpos=(double)((*ivec))->TPos();                             
00405       double zpos=(double)((*ivec))->ZPos();
00406       TPos_mean  +=tpos;
00407       ZPos_mean  +=zpos;
00408       TPos2_mean +=pow(tpos,2);
00409       ZPos2_mean +=pow(zpos,2);
00410       TPosZPos_mean +=tpos*zpos;
00411       count++;
00412     }
00413   }
00414   if(count <=0){
00415     cerr<<"count is = "<<count<<endl;
00416     return false;
00417   }
00418 
00419   TPos2_mean/=count;
00420   ZPos2_mean/=count;
00421   TPos_mean/=count;
00422   ZPos_mean/=count;
00423   TPosZPos_mean/=count;
00424 
00425   if(TPos2_mean <pow(TPos_mean,2.0) || ZPos2_mean < pow(ZPos_mean,2.0))
00426     {
00427       cerr<<"FillShortVar::GetScatter count is zero or TPos,ZPos wrong "<<count<<" "<<endl;
00428       cerr<<"TPOS \t"<<TPos2_mean<<" "<<pow(TPos_mean,2)<<" "<<TPos2_mean-pow(TPos_mean,2)<<endl;
00429       cerr<<"ZPOS \t"<<ZPos2_mean<<" "<<pow(ZPos_mean,2)<<" "<<ZPos2_mean-pow(ZPos_mean,2)<<endl;
00430       return false;
00431     }
00432 
00433   if(count<3) {
00434     pear=1.0;
00435     dpear=1.0;
00436     return true;
00437   }
00438 
00439   double sdev_t=0.0;  double sdev_z=0.0;
00440   sdev_t = sqrt(TPos2_mean - pow(TPos_mean,2));
00441   sdev_z = sqrt(ZPos2_mean - pow(ZPos_mean,2));
00442 
00443   if(sdev_t*sdev_z>0){
00444     pear = abs(TPosZPos_mean - (TPos_mean*ZPos_mean))/(sdev_t*sdev_z);
00445   }
00446   else pear =0;
00447   if(pear>1.05){
00448     cerr<<"FillShortVar::GetScatter - something went terribly wrong "<<count<<" "<<pear<<endl;
00449     cerr<<"tpos:  "<<TPos_mean<<endl;
00450     cerr<<"tpos2: "<<TPos2_mean<<endl;
00451     cerr<<"zpos:  "<<ZPos_mean<<endl;
00452     cerr<<"zpos2: "<<ZPos2_mean<<endl;
00453     cerr<<"tzpos: "<<TPosZPos_mean<<endl;
00454     cerr<<"sdevt: "<<sdev_t<<endl;
00455     cerr<<"sdevz: "<<sdev_z<<endl;
00456     cerr<<"numer: "<< abs(TPosZPos_mean - (TPos_mean*ZPos_mean))<<endl;
00457     cerr<<"denom: "<<(sdev_t*sdev_z)<<endl;
00458     pear=1.0;
00459     dpear=1.0;
00460     return false;
00461   }
00462 
00463   if(sdev_t>0 && sdev_z>0) dpear  = sqrt(pow(2*pear*sdev_t*sdev_z,2) + pow((sdev_t*sdev_t)-(sdev_z*sdev_z),2))/(sdev_t*sdev_t+sdev_z*sdev_z);
00464   else dpear=0;
00465 
00466   return true;
00467 }
00468 
00469                                                                                                           
00470 float Anp::FillShortVar::GetWPos(const short plane, std::map< int,float> pmap) const
00471 {
00472   //
00473   // Find transverse hit position using nearby planes
00474   //
00475   std::map<short, float> fmap;
00476   for(std::map<int,float>::iterator pit = pmap.begin(); pit != pmap.end(); ++pit)
00477     {     
00478       const short diff = plane - pit -> first;
00479       // easiest solution: return tpos in the previous plane      
00480       if(diff == -1)
00481         {         
00482           return  pit->second;
00483         }
00484 
00485       // skip strips in same plane view
00486       if(std::abs(diff) % 2 == 0)
00487         {
00488           continue;
00489         }
00490 
00491       if(!fmap.insert(map<short, float>::value_type(diff,pit->second)).second)
00492         {
00493           cerr << "FillShortVar::GetWPos - duplicate plane difference" << endl;
00494         }
00495     }
00496 
00497   if(fmap.empty())
00498     {
00499       cerr << "FillShortVar::GetWPos - no planes in orthogonal view. " << endl;
00500       return -100.0;
00501     }
00502 
00503   map<short, float>::iterator dit_pos = fmap.begin();
00504   map<short, float>::iterator dit_neg = fmap.begin();
00505   for(map<short, float>::iterator dit = fmap.begin(); dit != fmap.end(); ++dit)
00506     {
00507       const short diff = dit -> first;
00508       if(diff < 0)
00509         {
00510           if(abs(dit_neg -> first) > abs(diff))
00511             {
00512               dit_neg = dit;
00513             }
00514         }
00515       if(diff > 0)
00516         {
00517           if(abs(dit_pos -> first) > abs(diff))
00518             {
00519               dit_pos = dit;
00520             }
00521         }
00522     }
00523 
00524   double return_value = 0.5*(dit_pos -> second + dit_neg -> second);
00525   return return_value;
00526 }
00527 
00528 float Anp::FillShortVar::TrackStripEnergy(Anp::StripIter si, short index,string StripMin) const
00529 {
00530   if(StripMin.find("SIGCOR")!=string::npos && si->SigCor()>0) return si->SigCor();
00531   Strip::TrackInfoIter info_it = si->GetInfo(index);
00532 
00533   if(info_it == si-> InfoEndIter())
00534   {
00535     cout<<" FillShortVar::TrackStripEnergy -  Can't find info for track index  "<<index<<endl;
00536     return 0;
00537   }
00538 
00539   const Strip::TrackInfo &info = info_it -> second;
00540   double strip_charge = -1.0;
00541 
00542   if(StripMin.find("SIGMAP")  !=string::npos)strip_charge =(info.sigmap_east+info.sigmap_west);
00543   else if(StripMin.find("MIP")!=string::npos)strip_charge =(info.mip_east   +info.mip_west   );
00544   else cerr<<"FillShortVar::TrackStripEnergy - unable to find unit "<<StripMin<<endl;
00545   if(strip_charge >0) return strip_charge;
00546   
00547   cerr<<" bad strip charge "<<strip_charge<<" for "<<StripMin<<endl;
00548   return 0;
00549 }
00550 
00551 //-----------------------------------------------------------                                                                
00552 float Anp::FillShortVar::OtherStripEnergy(StripIter sp, const VldContext &vldc,
00553                                           const float lpos, string StripMin) const
00554 {
00555   // This is stolen from rustem's FillMuonID code.
00556   // Calibrate strip pulse height from sigcor to sigmap or from sigmap to mip 
00557   
00558   //
00559   // RETURN SIGCOR
00560   //
00561   if(StripMin.find("SIGCOR")!=string::npos) return sp->SigCor();
00562 
00563   const Strip& strip = *sp;
00564   float upos = -1.0, vpos = -1.0;
00565   if(strip.IsUview())
00566     {
00567       upos = strip.TPos();
00568       vpos = lpos;
00569     }
00570   else
00571     {
00572       upos = lpos;
00573       vpos = strip.TPos();
00574     }
00575 
00576   UgliGeomHandle ugh(vldc);
00577   if(!ugh.IsValid())
00578     {
00579       cerr << "FillMuonId::Get - invalid UgliGeomHandle: " << vldc << endl;
00580       return 0.0;
00581     }
00582 
00583   const PlexStripEndId seid(strip.GetEncoded());
00584   const UgliStripHandle ush = ugh.GetStripHandle(seid);
00585 
00586   if(!ush.IsValid())
00587     {
00588       cerr << "FillMuonId::Get - invalid UgliStripHandle: " << seid << endl;
00589       return 0.0;
00590     }
00591 
00592   const TVector3 guvz(upos, vpos, strip.ZPos());
00593   const TVector3 lxyz = ush.GlobalToLocal(guvz, false);
00594   Calibrator &calibrator = Calibrator::Instance();
00595   calibrator.ReInitialise(vldc);
00596  float sigmap = 0.0, sigmap_east = -1.0, sigmap_west = -1.0;
00597  if(vldc.GetDetector() == Detector::kNear)
00598    {
00599      if(fDebug) cout<<"FillShortVar::OtherStripEnergy  -near detector "<<lxyz.x()<<" "<<strip.SigCor()<<" "<<seid<<endl;
00600      sigmap = calibrator.GetAttenCorrected(strip.SigCor(), lxyz.x(), seid);
00601      if(fDebug) cout<<" here !"<<endl;
00602      sigmap = calibrator.GetAttenCorrectedTpos(strip.SigCor(), lpos, seid);
00603      if(fDebug) cout<<" after calibrator "<<endl;
00604    }
00605  else if(vldc.GetDetector() == Detector::kFar)
00606    {
00607      PlexStripEndId seid_far(seid);
00608      if(strip.SigCorEast() > 0.0)
00609        {
00610          seid_far.SetEnd(StripEnd::kEast);
00611          sigmap_east = calibrator.GetAttenCorrected(strip.SigCorEast(), lxyz.x(), seid_far);
00612          sigmap += sigmap_west;
00613        }
00614 
00615      if(strip.SigCorWest() > 0.0)
00616        {
00617          seid_far.SetEnd(StripEnd::kWest);
00618          sigmap_east = calibrator.GetAttenCorrected(strip.SigCorWest(), lxyz.x(), seid_far);
00619          sigmap += sigmap_east;
00620        }
00621    }
00622  else
00623    {
00624      cerr << "FillMuonId::Get - unknown detector" << endl;
00625      return 0.0;
00626    }
00627 
00628  //
00629  // Just want sigmap pulse height  
00630  //
00631  //
00632  // RETURN SIGMAP
00633  //
00634  if(StripMin.find("SIGMAP")!=string::npos){
00635    if(fDebug) cout<<" FillShortVar::OtherStripEnergy - return SIGMAP "<<sigmap<<endl;
00636    return sigmap;
00637  }
00638  if(StripMin.find("MIP")!=string::npos){
00639       float mip = 0.0;
00640      if(vldc.GetDetector() == Detector::kNear)
00641        {
00642      mip = Calibrator::Instance().GetMIP(sigmap, seid);
00643        }
00644      else if(vldc.GetDetector() == Detector::kFar)
00645        {
00646          PlexStripEndId seid_far(seid);
00647          
00648          if(sigmap_east > 0.0)
00649            {
00650              seid_far.SetEnd(StripEnd::kEast);
00651              mip += Calibrator::Instance().GetMIP(sigmap_east, seid_far);
00652            }
00653          if(sigmap_west > 0.0)
00654            {
00655              seid_far.SetEnd(StripEnd::kWest);
00656              mip = Calibrator::Instance().GetMIP(sigmap_west, seid_far);
00657            }
00658        } 
00659      //
00660      // RETURN MIP
00661      //
00662      if(fDebug) cout<<" FillShortVar::OtherStripEnergy - return MIP "<<mip<<endl;
00663      return mip;
00664    }
00665    
00666    cerr<<" FillShortVar::OtherStripEnergy - Invalid type "<<StripMin<<endl;   
00667    return 0;
00668 }
00669 
00670 //-----------------------------------------------------------------------------------------
00671 float Anp::FillShortVar::GetStripChargeCut(string StripMin) const 
00672 {
00673   //
00674   // Given a string, find the corresponding minimum (MIP, SIGMAP or SIGCOR) in ADC or MIP
00675   //
00676   double minStripPH=-1.0;
00677   if(StripMin.find("MIP")!=string::npos){
00678     minStripPH = fMinStripMIP;
00679   }
00680   else if(StripMin.find("SIGMAP")!=string::npos){
00681     minStripPH= fMinStripADC;
00682   }
00683   else if(StripMin.find("SIGCOR")!=string::npos){
00684     minStripPH= fMinStripADC;
00685   }
00686   else {
00687     cerr<<" FillShortVar::GetStripChargeCut - Invalid Strip Charge Unit "<<StripMin<<endl;
00688   }
00689 
00690   return minStripPH;
00691 }
00692 //---------------------------------------------------------------------------- 
00693 void Anp::FillShortVar::Fill(DataMap& dmapout, DataMap dmapin, int base){
00694   for(DataMap::iterator dmapit= dmapin.begin(); dmapit!=dmapin.end(); dmapit++){
00695     if(!dmapout.insert(DataMap::value_type(dmapit->first+ base, dmapit->second)).second){
00696       cerr<<" The value of "<<dmapit->first+base<<", "<< dmapit->first<<" + "<<base<<" = "<<dmapit->second
00697           <<" has been taken already by  "<<dmapout[dmapit->first]<<endl;
00698     }
00699   }
00700 }
00701 //------------------------------------------------------------------------------
00702 std::vector<Anp::StripIter> Anp::FillShortVar::FirstPassOtherStrip(const std::vector<StripIter> instrip,const std::vector<StripIter> track_strip, double minT, double maxT) const
00703 {
00704   // Do I really need this function?
00705   // Rustem uses (in FillMuonID) the track strips to find the orthogonal strip location for the 'other' strips (to get sigmaps)
00706   // keep but don't need
00707   std::vector<StripIter> ret_strip;
00708 
00709   double min_strip=-1;  double max_strip=-1;
00710   for( std::vector<StripIter>::const_iterator istrip = track_strip.begin(); istrip!=track_strip.end(); istrip++)
00711   {
00712     if(min_strip<0 || min_strip > (*istrip)->GetStrip()) min_strip = (*istrip)->GetStrip();
00713     if(max_strip<0 || max_strip < (*istrip)->GetStrip()) max_strip = (*istrip)->GetStrip();
00714     //add trck strips too
00715     ret_strip.push_back(*istrip);
00716   }
00717 
00718 
00719   for( std::vector<StripIter>::const_iterator oiter = instrip.begin(); oiter!=instrip.end();oiter++){
00720     // Decent SigCor
00721     if((*oiter)->SigCor()<fMinStripADC){
00722       continue;
00723     }
00724     // Within Time Window
00725     if(fTimeWindow > 0.0)
00726       {
00727         if((*oiter)->Time() < minT - fTimeWindow || (*oiter)->Time() > maxT + fTimeWindow)
00728          {
00729            continue;
00730          }
00731       }
00732     // Within Strip Window
00733     if((*oiter)->GetStrip() > max_strip+fStripWindow || (*oiter)->GetStrip()< min_strip-fStripWindow){
00734       continue;
00735     }
00736 
00737     ret_strip.push_back(*oiter);
00738   }
00739   return ret_strip;
00740 }
00741 //--------------------------------------------------------------------------
00742                                                                                                 
00743 bool Anp::FillShortVar::IsGoodTrack(TrackIter itrack, Record& record) {
00744   //
00745   // Returns whether a track is 'good' or not (study)
00746   //
00747   bool goodtrack=true;
00748   EventIter itevent= record.FindEvent(*itrack);
00749 
00750   if(     (ftruelowE>=0)   && ftruelowE<record.FindTruth(*itevent)->Energy())           goodtrack= false;
00751   else if((frecolowE>=0)   && (itevent!=record.EventEnd())&&frecolowE<itevent->Gev())   goodtrack= false;
00752   else if((fqeltrack)      && (itevent!=record.EventEnd())&&!(itevent->GetNTracks()==1))goodtrack= false;
00753   else if((fselectsign!=0) && itrack->QP()/fselectsign<0)                               goodtrack= false;
00754   else if((fMaxNPlane>0)   && itrack->GetBasic().NPlaneScint()>fMaxNPlane)              goodtrack= false;
00755 
00756   return goodtrack;
00757 }
00758 
00759 //----------------------------------------------------------------------------   
00760 
00761 const VldContext Anp::FillShortVar::GetVldc(const Header &header) const
00762 {
00763   // 
00764   // This is stolen from Rustem's FillMuonID code  
00765   //
00766   const VldTimeStamp time(header.Sec(), header.NSec());
00767   if(header.IsData())
00768     {
00769       if(header.IsNear())
00770         {
00771           return VldContext(Detector::kNear, SimFlag::kData, time);
00772         }
00773       else if(header.IsFar())
00774         {
00775           return VldContext(Detector::kFar, SimFlag::kData, time);
00776         }
00777     }
00778   else
00779     {
00780       if(header.IsNear())
00781         {
00782           return VldContext(Detector::kNear, SimFlag::kMC, time);
00783         }
00784       else if(header.IsFar())
00785         {
00786           return VldContext(Detector::kFar, SimFlag::kMC, time);
00787         }
00788     }
00789   return VldContext(Detector::kUnknown, SimFlag::kUnknown, time);
00790 }

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