Anp::FillShortVar Class Reference

#include <FillShortVar.h>

Inheritance diagram for Anp::FillShortVar:
Anp::AlgSnarl Anp::Base

List of all members.

Public Member Functions

 FillShortVar ()
virtual ~FillShortVar ()
bool Run (Record &record)
void Config (const Registry &reg)
void End (const DataBlock &)

Private Types

typedef StripLinkStripLinkIter
typedef std::map< short, float > DataMap
typedef std::map< unsigned
short, std::vector
< Anp::StripIter > > 
PlaneMap
typedef std::map< unsigned
short, std::vector
< StripLinkIter > > 
PlaneMapList

Private Member Functions

bool Study (Track &track, const Record &record, DataMap &dmap, string StripMin)
void Fill (DataMap &dmapout, DataMap dmapin, int base)
bool GetTrackMap (Track &track, const Record &record, PlaneMap &track_map, std::map< int, float > &other_map, string StripMin) const
std::vector< Anp::StripIterGet (const Track &track, unsigned short plane, const Record &record, std::map< int, float > other_map, string StripMin) const
bool GetScatter (PlaneMap track_map, float &pear, float &dpear, int keyval) const
double BVD_BestLine (PlaneMap &map) const
double GetProbability (StripLink *cur, StripLink *cmp) const
float GetWPos (const short plane, std::map< int, float > pmap) const
const VldContext GetVldc (const Header &header) const
float TrackStripEnergy (StripIter si, short index, string StripMin) const
float OtherStripEnergy (StripIter sp, const VldContext &vldc, const float lpos, string StripMin) const
bool IsGoodTrack (TrackIter itrack, Record &record)
float GetStripChargeCut (string StripMin) const
std::vector< Anp::StripIterFirstPassOtherStrip (const std::vector< StripIter > instrip, const std::vector< StripIter > track_strip, double minT, double maxT) const

Private Attributes

int fMinNPlane
int fMaxNPlane
int fEndNPlane
int fKeyBase
double fTimeWindow
int fStripWindow
double fMinStripADC
double fMinStripMIP
bool fFillEvent
bool fDebug
bool fErase
bool fqeltrack
double ftruelowE
double frecolowE
int fselectsign
int fNTrackAll
int fNTrackAdd

Detailed Description

Definition at line 22 of file FillShortVar.h.


Member Typedef Documentation

typedef std::map<short,float> Anp::FillShortVar::DataMap [private]

Definition at line 38 of file FillShortVar.h.

typedef std::map<unsigned short, std::vector<Anp::StripIter> > Anp::FillShortVar::PlaneMap [private]

Definition at line 39 of file FillShortVar.h.

typedef std::map<unsigned short, std::vector<StripLinkIter> > Anp::FillShortVar::PlaneMapList [private]

Definition at line 40 of file FillShortVar.h.

Definition at line 37 of file FillShortVar.h.


Constructor & Destructor Documentation

Anp::FillShortVar::FillShortVar (  ) 

Definition at line 24 of file FillShortVar.cxx.

00025   :fMinNPlane(4),
00026    fMaxNPlane(20),
00027    fEndNPlane(5),
00028    fKeyBase(14700),
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 }

Anp::FillShortVar::~FillShortVar (  )  [virtual]

Definition at line 46 of file FillShortVar.cxx.

00047 {
00048 }


Member Function Documentation

double Anp::FillShortVar::BVD_BestLine ( PlaneMap map  )  const [private]
void Anp::FillShortVar::Config ( const Registry reg  )  [virtual]

Reimplemented from Anp::AlgSnarl.

Definition at line 136 of file FillShortVar.cxx.

References fDebug, fEndNPlane, fErase, fFillEvent, fKeyBase, fMaxNPlane, fMinNPlane, fMinStripADC, fMinStripMIP, fqeltrack, frecolowE, fselectsign, fTimeWindow, ftruelowE, Registry::Get(), Registry::KeyExists(), and Anp::Read().

00137 {
00138    //
00139    // Configure self
00140    //
00141 
00142    reg.Get("FillShortVarMinNPlane",  fMinNPlane);
00143    reg.Get("FillShortVarMaxNPlane",  fMaxNPlane);
00144    reg.Get("FillShortVarEndNPlane",  fEndNPlane);
00145    reg.Get("FillShortVarKeyBase",    fKeyBase);
00146 
00147    reg.Get("FillShortVarMinStripAdc", fMinStripADC);
00148    reg.Get("FillShortVarMinStripMip", fMinStripMIP);
00149    reg.Get("FillShortVarTimeWindow", fTimeWindow);
00150 
00151    //
00152    // Read bool and string variables
00153    //
00154                                                                                           
00155    Anp::Read(reg, "FillShortVarEvent",    fFillEvent);
00156    Anp::Read(reg, "FillShortVarDebug",    fDebug);
00157    Anp::Read(reg, "FillShortVarErase",    fErase);
00158    Anp::Read(reg, "FillShortVarQELTrack", fqeltrack);
00159 
00160    // Extra Configurations
00161    reg.Get( "FillShortVarLowTrueE", ftruelowE);
00162    reg.Get( "FillShortVarLowRecoE", frecolowE);
00163    reg.Get( "FillShortVarSelectSign", fselectsign);
00164    if(reg.KeyExists("PrintConfig"))
00165    {
00166       cout << "FillShortVar::Config" << endl
00167            << "   MinNPlane = " << fMinNPlane << endl
00168            << "   MaxNPlane = " << fMaxNPlane << endl
00169            << "   EndNPlane = " << fEndNPlane << endl
00170            << "   KeyBase = " << fKeyBase << endl
00171            << "   MinStripADC = " << fMinStripADC << endl
00172            << "   MinStripMIP = " << fMinStripMIP<< endl
00173            << "   SelectSign = " << fselectsign<< endl
00174            << "   TimeWindow = " << fTimeWindow << endl       
00175            << "   Debug = " << fDebug << endl
00176            << "   Erase = " << fErase << endl
00177            << "   QELTrack  ="<< fqeltrack << endl
00178            << "   trueE Upper Limit  ="<< ftruelowE << endl
00179            << "   RecoE Upper Limit  ="<< frecolowE << endl
00180            << "   FillEvent ="<<  fFillEvent<<endl;
00181 
00182 
00183    }
00184 }

void Anp::FillShortVar::End ( const DataBlock  )  [virtual]

Reimplemented from Anp::AlgSnarl.

Definition at line 186 of file FillShortVar.cxx.

References fNTrackAdd, and fNTrackAll.

00187 {
00188       cout << "   NTrackAll = " << fNTrackAll << endl
00189            << "   NTrackAdd = " << fNTrackAdd << endl;
00190 }

void Anp::FillShortVar::Fill ( DataMap dmapout,
DataMap  dmapin,
int  base 
) [private]

Definition at line 702 of file FillShortVar.cxx.

Referenced by Run().

00702                                                                     {
00703   for(DataMap::iterator dmapit= dmapin.begin(); dmapit!=dmapin.end(); dmapit++){
00704     if(!dmapout.insert(DataMap::value_type(dmapit->first+ base, dmapit->second)).second){
00705       cerr<<" The value of "<<dmapit->first+base<<", "<< dmapit->first<<" + "<<base<<" = "<<dmapit->second
00706           <<" has been taken already by  "<<dmapout[dmapit->first]<<endl;
00707     }
00708   }
00709 }

std::vector< Anp::StripIter > Anp::FillShortVar::FirstPassOtherStrip ( const std::vector< StripIter instrip,
const std::vector< StripIter track_strip,
double  minT,
double  maxT 
) const [private]

Definition at line 711 of file FillShortVar.cxx.

References fMinStripADC, fStripWindow, and fTimeWindow.

00712 {
00713   // Do I really need this function?
00714   // Rustem uses (in FillMuonID) the track strips to find the orthogonal strip location for the 'other' strips (to get sigmaps)
00715   // keep but don't need
00716   std::vector<StripIter> ret_strip;
00717 
00718   double min_strip=-1;  double max_strip=-1;
00719   for( std::vector<StripIter>::const_iterator istrip = track_strip.begin(); istrip!=track_strip.end(); istrip++)
00720   {
00721     if(min_strip<0 || min_strip > (*istrip)->GetStrip()) min_strip = (*istrip)->GetStrip();
00722     if(max_strip<0 || max_strip < (*istrip)->GetStrip()) max_strip = (*istrip)->GetStrip();
00723     //add trck strips too
00724     ret_strip.push_back(*istrip);
00725   }
00726 
00727   for( std::vector<StripIter>::const_iterator oiter = instrip.begin(); oiter!=instrip.end();oiter++){
00728     // Decent SigCor
00729     if((*oiter)->SigCor()<fMinStripADC){
00730       continue;
00731     }
00732     // Within Time Window
00733     if(fTimeWindow > 0.0)
00734       {
00735         if((*oiter)->Time() < minT - fTimeWindow || (*oiter)->Time() > maxT + fTimeWindow)
00736          {
00737            continue;
00738          }
00739       }
00740     // Within Strip Window
00741     if((*oiter)->GetStrip() > max_strip+fStripWindow || (*oiter)->GetStrip()< min_strip-fStripWindow){
00742       continue;
00743     }
00744 
00745     ret_strip.push_back(*oiter);
00746   }
00747   return ret_strip;
00748 }

std::vector< Anp::StripIter > Anp::FillShortVar::Get ( const Track track,
unsigned short  plane,
const Record record,
std::map< int, float >  other_map,
string  StripMin 
) const [private]

Definition at line 320 of file FillShortVar.cxx.

References fStripWindow, fTimeWindow, Anp::Track::GetBasic(), VHS::GetPlane(), Anp::GetStrip(), GetStripChargeCut(), Anp::Basic::MaxTime(), Anp::Basic::MinTime(), Anp::Record::StripBeg(), Anp::Record::StripEnd(), and Anp::Track::TrackIndex().

Referenced by Study().

00322 {
00323   //
00324   // Collect all non-track strips in a given plane within window after some given cuts   
00325   //  
00326   vector<StripIter> svec;
00327   int min_strip=-1;  int max_strip=-1;
00328 
00329   double minStripPH = FillShortVar::GetStripChargeCut(StripMin);
00330   if(minStripPH<0)  return svec;
00331   
00332    for(StripIter istrip = record.StripBeg(); istrip != record.StripEnd(); ++istrip)
00333    {
00334      if(istrip -> GetPlane() != plane)  continue;
00335      
00336      if(istrip -> MatchTrk(track.TrackIndex()))
00337      {
00338        if(min_strip<0 || min_strip > istrip->GetStrip()) min_strip = istrip->GetStrip();
00339        if(max_strip<0 || max_strip < istrip->GetStrip()) max_strip = istrip->GetStrip();
00340        continue;
00341      }
00342      if(fTimeWindow > 0.0)
00343      {
00344        if(istrip->Time() < track.GetBasic().MinTime() - fTimeWindow ||
00345           istrip->Time() > track.GetBasic().MaxTime() + fTimeWindow)
00346          continue;     
00347      }
00348       svec.push_back(istrip);
00349    }
00350    std::vector<Anp::StripIter>::iterator si = svec.begin() ;
00351    while(si!=svec.end()){
00352      if((*si)->GetStrip() > max_strip+fStripWindow || (*si)->GetStrip()< min_strip-fStripWindow)  si=svec.erase(si);
00353      else si++;
00354    }
00355    return svec;
00356 }

double Anp::FillShortVar::GetProbability ( StripLink cur,
StripLink cmp 
) const [private]
bool Anp::FillShortVar::GetScatter ( PlaneMap  track_map,
float &  pear,
float &  dpear,
int  keyval 
) const [private]

Definition at line 405 of file FillShortVar.cxx.

References count.

Referenced by Study().

00407 {
00408 
00409   double TPos_mean =0.0000;  double ZPos_mean =0.0000;   double TPos2_mean =0.0000;  double ZPos2_mean =0.000000;
00410   double TPosZPos_mean =0.0000;
00411   int count=0; 
00412 
00413   for(PlaneMap::iterator pit = track_map.begin(); pit != track_map.end(); ++pit)
00414   {
00415     vector<StripIter> &vec = pit->second;
00416     if((vec[0]->IsUview() &&!(keyview==1)) ||(vec[0]->IsVview() &&!(keyview==2))) continue; 
00417 
00418     for(vector<StripIter>::iterator ivec = vec.begin(); ivec!=vec.end() ; ivec++)
00419     {
00420       double tpos=(double)((*ivec))->TPos();                             
00421       double zpos=(double)((*ivec))->ZPos();
00422       TPos_mean  +=tpos;
00423       ZPos_mean  +=zpos;
00424       TPos2_mean +=pow(tpos,2);
00425       ZPos2_mean +=pow(zpos,2);
00426       TPosZPos_mean +=tpos*zpos;
00427  
00428       count++;
00429     }
00430   }
00431   if(count<3) return false; // return true ? as was before  must have pear=dpear= some value
00432   
00433   TPos2_mean/=count;
00434   ZPos2_mean/=count;
00435   TPos_mean/=count;
00436   ZPos_mean/=count;
00437   TPosZPos_mean/=count;
00438 
00439   if(TPos2_mean <pow(TPos_mean,2.0) || ZPos2_mean < pow(ZPos_mean,2.0))
00440     {
00441       cerr<<"FillShortVar::GetScatter count is zero or TPos,ZPos wrong "<<count<<" "<<endl;
00442       cerr<<"TPOS \t"<<TPos2_mean<<" "<<pow(TPos_mean,2)<<" "<<TPos2_mean-pow(TPos_mean,2)<<endl;
00443       cerr<<"ZPOS \t"<<ZPos2_mean<<" "<<pow(ZPos_mean,2)<<" "<<ZPos2_mean-pow(ZPos_mean,2)<<endl;
00444       return false;
00445     }
00446 
00447   double sdev_t=0.0;  double sdev_z=0.0;
00448   sdev_t = sqrt(TPos2_mean - pow(TPos_mean,2));
00449   sdev_z = sqrt(ZPos2_mean - pow(ZPos_mean,2));
00450 
00451   if(sdev_t*sdev_z>0){
00452     pear = abs(TPosZPos_mean - (TPos_mean*ZPos_mean))/(sdev_t*sdev_z);
00453   }
00454   else pear =0;
00455   if(pear>1.05){
00456     cerr<<"FillShortVar::GetScatter - something went terribly wrong "<<count<<" "<<pear<<endl;
00457     cerr<<"tpos:  "<<TPos_mean<<endl;
00458     cerr<<"tpos2: "<<TPos2_mean<<endl;
00459     cerr<<"zpos:  "<<ZPos_mean<<endl;
00460     cerr<<"zpos2: "<<ZPos2_mean<<endl;
00461     cerr<<"tzpos: "<<TPosZPos_mean<<endl;
00462     cerr<<"sdevt: "<<sdev_t<<endl;
00463     cerr<<"sdevz: "<<sdev_z<<endl;
00464     cerr<<"numer: "<< abs(TPosZPos_mean - (TPos_mean*ZPos_mean))<<endl;
00465     cerr<<"denom: "<<(sdev_t*sdev_z)<<endl;
00466     pear=1.0;
00467     dpear=1.0;
00468     return false;
00469   }
00470 
00471   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);
00472   else dpear=0;
00473   
00474   return true;
00475 }

float Anp::FillShortVar::GetStripChargeCut ( string  StripMin  )  const [private]

Definition at line 680 of file FillShortVar.cxx.

References fMinStripADC, and fMinStripMIP.

Referenced by Get(), GetTrackMap(), and Study().

00681 {
00682   //
00683   // Given a string, find the corresponding minimum (MIP, SIGMAP or SIGCOR) in ADC or MIP
00684   //
00685   double minStripPH=-1.0;
00686   if(StripMin.find("MIP")!=string::npos){
00687     minStripPH = fMinStripMIP;
00688   }
00689   else if(StripMin.find("SIGMAP")!=string::npos){
00690     minStripPH= fMinStripADC;
00691   }
00692   else if(StripMin.find("SIGCOR")!=string::npos){
00693     minStripPH= fMinStripADC;
00694   }
00695   else {
00696     cerr<<" FillShortVar::GetStripChargeCut - Invalid Strip Charge Unit "<<StripMin<<endl;
00697   }
00698 
00699   return minStripPH;
00700 }

bool Anp::FillShortVar::GetTrackMap ( Track track,
const Record record,
PlaneMap track_map,
std::map< int, float > &  other_map,
string  StripMin 
) const [private]

Definition at line 358 of file FillShortVar.cxx.

References fDebug, Anp::Record::GetHeader(), VHS::GetPlane(), GetStripChargeCut(), Anp::Header::IsNear(), it, Anp::Record::StripBeg(), Anp::Record::StripEnd(), Anp::Track::TrackIndex(), and TrackStripEnergy().

Referenced by Study().

00360 {
00361   //
00362   // collect all track strips in a plane and insert plane, vector into the 'plane map'
00363   //  find the average position of all track (and near?) strips
00364   //
00365   double minStrip= GetStripChargeCut(StripMin);
00366   int  Uview=0;
00367   int  Vview=0;
00368   PlaneMap o_map;
00369   for(StripIter istrip = record.StripBeg(); istrip != record.StripEnd(); ++istrip)
00370   {
00371 
00372     // seperate strips in record not from track
00373     bool istrack = istrip -> MatchTrk(track.TrackIndex());       
00374     if(!istrack) continue;
00375     // Ignore  non calorimeter strips/events
00376     if(record.GetHeader().IsNear() && istrip -> GetPlane() > 120 && istrack) return false;     
00377     
00378     if(TrackStripEnergy(istrip,track.TrackIndex(),StripMin)>minStrip){  
00379       vector<StripIter> &svec = track_map[istrip -> GetPlane()]; 
00380       svec.push_back(istrip);                                           
00381       if(istrip->IsUview()) Uview++;
00382       if(istrip->IsVview()) Vview++;
00383     }          
00384   }
00385                                                                                                                         
00386   for(PlaneMap::iterator track_it =track_map.begin(); track_it!=track_map.end(); track_it++)   
00387     {
00388       float strip_mean =0.0;
00389       const std::vector<StripIter>  tsvec = track_it->second;
00390       for(std::vector<StripIter>::const_iterator it = tsvec.begin(); it!= tsvec.end(); it++){
00391         strip_mean += (*it) -> TPos();  
00392       }
00393       strip_mean /=(float) tsvec.size();
00394       other_map [track_it->first]= strip_mean;
00395     }
00396 
00397   if(Uview<=0 || Vview<=0){
00398     if(fDebug) cout<<" No track hits in  view  (hits in U, hits in V) = ("<<Uview<<","<<Vview<<")"<<endl;
00399     return false;
00400   }
00401 
00402   return true;
00403 }

const VldContext Anp::FillShortVar::GetVldc ( const Header header  )  const [private]

Definition at line 769 of file FillShortVar.cxx.

References Anp::Header::IsData(), Anp::Header::IsFar(), Anp::Header::IsNear(), SimFlag::kData, Detector::kFar, SimFlag::kMC, Detector::kNear, SimFlag::kUnknown, Detector::kUnknown, Anp::Header::NSec(), and Anp::Header::Sec().

Referenced by Study().

00770 {
00771   // 
00772   // This is stolen from Rustem's FillMuonID code  
00773   //
00774   const VldTimeStamp time(header.Sec(), header.NSec());
00775   if(header.IsData())
00776     {
00777       if(header.IsNear())
00778         {
00779           return VldContext(Detector::kNear, SimFlag::kData, time);
00780         }
00781       else if(header.IsFar())
00782         {
00783           return VldContext(Detector::kFar, SimFlag::kData, time);
00784         }
00785     }
00786   else
00787     {
00788       if(header.IsNear())
00789         {
00790           return VldContext(Detector::kNear, SimFlag::kMC, time);
00791         }
00792       else if(header.IsFar())
00793         {
00794           return VldContext(Detector::kFar, SimFlag::kMC, time);
00795         }
00796     }
00797   return VldContext(Detector::kUnknown, SimFlag::kUnknown, time);
00798 }

float Anp::FillShortVar::GetWPos ( const short  plane,
std::map< int, float >  pmap 
) const [private]

Definition at line 478 of file FillShortVar.cxx.

References Munits::second.

Referenced by Study().

00479 {
00480   //
00481   // Find transverse hit position using nearby planes
00482   //
00483   std::map<short, float> fmap;
00484   for(std::map<int,float>::iterator pit = pmap.begin(); pit != pmap.end(); ++pit)
00485     {     
00486       const short diff = plane - pit -> first;
00487       // easiest solution: return tpos in the previous plane      
00488       if(diff == -1)
00489         {         
00490           return  pit->second;
00491         }
00492 
00493       // skip strips in same plane view
00494       if( int(std::abs(diff)) % 2 == 0)
00495         {
00496           continue;
00497         }
00498 
00499       if(!fmap.insert(map<short, float>::value_type(diff,pit->second)).second)
00500         {
00501           cerr << "FillShortVar::GetWPos - duplicate plane difference" << endl;
00502         }
00503     }
00504 
00505   if(fmap.empty())
00506     {
00507       cerr << "FillShortVar::GetWPos - no planes in orthogonal view. " << endl;
00508       return -100.0;
00509     }
00510 
00511   map<short, float>::iterator dit_pos = fmap.begin();
00512   map<short, float>::iterator dit_neg = fmap.begin();
00513   for(map<short, float>::iterator dit = fmap.begin(); dit != fmap.end(); ++dit)
00514     {
00515       const short diff = dit -> first;
00516       if(diff < 0)
00517         {
00518           if(abs(dit_neg -> first) > abs(diff))
00519             {
00520               dit_neg = dit;
00521             }
00522         }
00523       if(diff > 0)
00524         {
00525           if(abs(dit_pos -> first) > abs(diff))
00526             {
00527               dit_pos = dit;
00528             }
00529         }
00530     }
00531 
00532   double return_value = 0.5*(dit_pos -> second + dit_neg -> second);
00533   return return_value;
00534 }

bool Anp::FillShortVar::IsGoodTrack ( TrackIter  itrack,
Record record 
) [private]

Definition at line 751 of file FillShortVar.cxx.

References Anp::Record::EventEnd(), Anp::Record::FindEvent(), Anp::Record::FindTruth(), fMaxNPlane, fqeltrack, frecolowE, fselectsign, and ftruelowE.

Referenced by Run().

00751                                                                   {
00752   //
00753   // Returns whether a track is 'good' or not (study)
00754   //
00755   bool goodtrack=true;
00756   EventIter itevent= record.FindEvent(*itrack);
00757 
00758   if(     (ftruelowE>=0)   && ftruelowE<record.FindTruth(*itevent)->Energy())           goodtrack= false;
00759   else if((frecolowE>=0)   && (itevent!=record.EventEnd())&&frecolowE<itevent->Gev())   goodtrack= false;
00760   else if((fqeltrack)      && (itevent!=record.EventEnd())&&!(itevent->GetNTracks()==1))goodtrack= false;
00761   else if((fselectsign!=0) && itrack->QP()/fselectsign<0)                               goodtrack= false;
00762   else if((fMaxNPlane>0)   && itrack->GetBasic().NPlaneScint()>fMaxNPlane)              goodtrack= false;
00763 
00764   return goodtrack;
00765 }

float Anp::FillShortVar::OtherStripEnergy ( StripIter  sp,
const VldContext vldc,
const float  lpos,
string  StripMin 
) const [private]

Definition at line 561 of file FillShortVar.cxx.

References fDebug, Calibrator::GetAttenCorrected(), Calibrator::GetAttenCorrectedTpos(), VldContext::GetDetector(), Anp::Strip::GetEncoded(), Calibrator::GetMIP(), UgliGeomHandle::GetStripHandle(), UgliStripHandle::GlobalToLocal(), Calibrator::Instance(), Anp::Strip::IsUview(), UgliGeomHandle::IsValid(), StripEnd::kEast, Detector::kFar, Detector::kNear, StripEnd::kWest, Calibrator::ReInitialise(), PlexStripEndId::SetEnd(), Anp::Strip::SigCor(), Anp::Strip::SigCorEast(), Anp::Strip::SigCorWest(), Anp::Strip::TPos(), and Anp::Strip::ZPos().

Referenced by Study().

00563 {
00564   // This is stolen from rustem's FillMuonID code.
00565   // Calibrate strip pulse height from sigcor to sigmap or from sigmap to mip 
00566   
00567   //
00568   // RETURN SIGCOR
00569   //
00570   if(StripMin.find("SIGCOR")!=string::npos) return sp->SigCor();
00571 
00572   const Strip& strip = *sp;
00573   float upos = -1.0, vpos = -1.0;
00574   if(strip.IsUview())
00575     {
00576       upos = strip.TPos();
00577       vpos = lpos;
00578     }
00579   else
00580     {
00581       upos = lpos;
00582       vpos = strip.TPos();
00583     }
00584 
00585   UgliGeomHandle ugh(vldc);
00586   if(!ugh.IsValid())
00587     {
00588       cerr << "FillMuonId::Get - invalid UgliGeomHandle: " << vldc << endl;
00589       return 0.0;
00590     }
00591 
00592   const PlexStripEndId seid(strip.GetEncoded());
00593   const UgliStripHandle ush = ugh.GetStripHandle(seid);
00594 
00595   if(!ush.IsValid())
00596     {
00597       cerr << "FillMuonId::Get - invalid UgliStripHandle: " << seid << endl;
00598       return 0.0;
00599     }
00600 
00601   const TVector3 guvz(upos, vpos, strip.ZPos());
00602   const TVector3 lxyz = ush.GlobalToLocal(guvz, false);
00603   Calibrator &calibrator = Calibrator::Instance();
00604   calibrator.ReInitialise(vldc);
00605  float sigmap = 0.0, sigmap_east = -1.0, sigmap_west = -1.0;
00606  if(vldc.GetDetector() == Detector::kNear)
00607    {
00608      if(fDebug) cout<<"FillShortVar::OtherStripEnergy  -near detector "<<lxyz.x()<<" "<<strip.SigCor()<<" "<<seid<<endl;
00609      sigmap = calibrator.GetAttenCorrected(strip.SigCor(), lxyz.x(), seid);
00610      if(fDebug) cout<<" here !"<<endl;
00611      sigmap = calibrator.GetAttenCorrectedTpos(strip.SigCor(), lpos, seid);
00612      if(fDebug) cout<<" after calibrator "<<endl;
00613    }
00614  else if(vldc.GetDetector() == Detector::kFar)
00615    {
00616      PlexStripEndId seid_far(seid);
00617      if(strip.SigCorEast() > 0.0)
00618        {
00619          seid_far.SetEnd(StripEnd::kEast);
00620          sigmap_east = calibrator.GetAttenCorrected(strip.SigCorEast(), lxyz.x(), seid_far);
00621          sigmap += sigmap_west;
00622        }
00623 
00624      if(strip.SigCorWest() > 0.0)
00625        {
00626          seid_far.SetEnd(StripEnd::kWest);
00627          sigmap_east = calibrator.GetAttenCorrected(strip.SigCorWest(), lxyz.x(), seid_far);
00628          sigmap += sigmap_east;
00629        }
00630    }
00631  else
00632    {
00633      cerr << "FillMuonId::Get - unknown detector" << endl;
00634      return 0.0;
00635    }
00636 
00637  //
00638  // Just want sigmap pulse height  
00639  //
00640  //
00641  // RETURN SIGMAP
00642  //
00643  if(StripMin.find("SIGMAP")!=string::npos){
00644    if(fDebug) cout<<" FillShortVar::OtherStripEnergy - return SIGMAP "<<sigmap<<endl;
00645    return sigmap;
00646  }
00647  if(StripMin.find("MIP")!=string::npos){
00648       float mip = 0.0;
00649      if(vldc.GetDetector() == Detector::kNear)
00650        {
00651      mip = Calibrator::Instance().GetMIP(sigmap, seid);
00652        }
00653      else if(vldc.GetDetector() == Detector::kFar)
00654        {
00655          PlexStripEndId seid_far(seid);
00656          
00657          if(sigmap_east > 0.0)
00658            {
00659              seid_far.SetEnd(StripEnd::kEast);
00660              mip += Calibrator::Instance().GetMIP(sigmap_east, seid_far);
00661            }
00662          if(sigmap_west > 0.0)
00663            {
00664              seid_far.SetEnd(StripEnd::kWest);
00665              mip = Calibrator::Instance().GetMIP(sigmap_west, seid_far);
00666            }
00667        } 
00668      //
00669      // RETURN MIP
00670      //
00671      if(fDebug) cout<<" FillShortVar::OtherStripEnergy - return MIP "<<mip<<endl;
00672      return mip;
00673    }
00674    
00675    cerr<<" FillShortVar::OtherStripEnergy - Invalid type "<<StripMin<<endl;   
00676    return 0;
00677 }

bool Anp::FillShortVar::Run ( Record record  )  [virtual]

Implements Anp::AlgSnarl.

Definition at line 50 of file FillShortVar.cxx.

References Anp::Record::Erase(), Anp::Record::EventBegIterator(), Anp::Record::EventEnd(), fDebug, fErase, fFillEvent, Fill(), fKeyBase, fNTrackAdd, fNTrackAll, Anp::GetTrack(), IsGoodTrack(), it, Anp::LongestTrack(), Munits::second, Study(), Anp::Record::TrackBegIterator(), and Anp::Record::TrackEndIterator().

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,100);
00066       if(FillShortVar::Study(*itrack, record,dmap2,"SIGMAP"))FillShortVar::Fill(dmap,dmap2,0);
00067       if(FillShortVar::Study(*itrack, record,dmap3,"MIP"))   FillShortVar::Fill(dmap,dmap3,200);
00068 
00069       if(itrack->KeyExists(fKeyBase+5) && itrack->KeyExists(fKeyBase+5))
00070       {
00071         if(itrack->DataAt(fKeyBase+5) < itrack->DataAt(fKeyBase+5))
00072           {
00073             dmap[fKeyBase+299]=itrack->DataAt(fKeyBase+5);
00074           }
00075         else dmap[fKeyBase+299]=itrack->DataAt(fKeyBase+5);
00076       }
00077       if(dmap.size()>0)
00078         {
00079           for(DataMap::const_iterator dit = dmap.begin(); dit!=dmap.end(); dit++) 
00080           {
00081             itrack->Add(dit->first+fKeyBase,dit->second);                 
00082           }
00083           if(!track_dmap.insert(map<short, const DataMap>::value_type(itrack -> TrackIndex(), dmap)).second)
00084           {
00085               cerr << "FillShortVar::Run - duplicate track index " << itrack -> TrackIndex() << endl;
00086           }
00087           
00088           ++fNTrackAdd;
00089         }
00090       itrack++;
00091     }
00092     else{
00093       if(fDebug) cout<<" FillShortVar:: Run - This track is bad"<<endl;
00094       if(fErase) itrack = record.Erase(itrack);
00095       else ++itrack;
00096     }
00097     ++fNTrackAll;        
00098   }
00099    //
00100    //  continue only if you WANT to erase  or you want to fill the event 
00101    //  return if you DONT want to erase AND you don't want to fill
00102   if(track_dmap.size()<1) return true;
00103   if(!fErase  && !fFillEvent )  return true;
00104   
00105    for ( EventIterator ievent = record.EventBegIterator(); ievent !=record.EventEnd();)
00106    {     
00107      const TrackVec tvec = Anp::GetTrack(*ievent, record);
00108      if(fErase &&ievent->GetNTracks()>0 &&(tvec.size()==0||(int)tvec.size()!=ievent->GetNTracks() ))
00109        {
00110          ievent=record.Erase(ievent);
00111          continue;
00112        }
00113 
00114        if(fFillEvent) 
00115        {
00116          TrackIter titer =Anp::LongestTrack(*ievent,record);
00117          map<short, const DataMap>::const_iterator dit = track_dmap.find(titer -> TrackIndex());
00118 
00119          if(dit == track_dmap.end())
00120            {
00121              //      cerr << "FillShortVar::Run - failed to find track index " << titer -> TrackIndex() << endl;
00122              ievent++;
00123              continue;
00124            }
00125          const DataMap &dmap = dit -> second;
00126 
00127          for(DataMap::const_iterator it = dmap.begin(); it != dmap.end(); ++it)ievent -> Add(it -> first+fKeyBase, it -> second);
00128 
00129        }
00130        ievent++;
00131    }   
00132    return true;
00133 }

bool Anp::FillShortVar::Study ( Track track,
const Record record,
DataMap dmap,
string  StripMin 
) [private]

Definition at line 192 of file FillShortVar.cxx.

References Anp::Track::ErrorQP(), fDebug, fEndNPlane, fMaxNPlane, fMinNPlane, Get(), Anp::Track::GetBasic(), Anp::Record::GetHeader(), GetScatter(), GetStripChargeCut(), GetTrackMap(), GetVldc(), GetWPos(), it, Anp::Basic::NPlaneScint(), OtherStripEnergy(), Anp::Track::QP(), Munits::second, Anp::Track::TrackIndex(), and TrackStripEnergy().

Referenced by Run().

00193 {  
00194   if(fDebug) cout<<" FillShortVar::Study - START! with StripChargeCut "<<StripMin<<endl;
00195   //
00196   // check total number of planes in track given by track container
00197   //  
00198   double last_plane=-1; double first_plane=-1; double sum_ph=0.0;   double sum_strip =0.0;
00199   double trk_ph = 0.0;  double now_ph =0.0;    double now_oph=0.0;  double last_ph=0.0;
00200   double l_ph = 0.0;    int l_ph_plane =0;     int count_plane = 0;
00201   int Ibase=20;
00202   int Sbase=30;
00203 
00204   double minStripPH=FillShortVar::GetStripChargeCut(StripMin);
00205   if(minStripPH<0) return false;
00206    
00207   if((track.GetBasic().NPlaneScint() < fMinNPlane)||
00208      (track.GetBasic().NPlaneScint() > fMaxNPlane && fMaxNPlane >0)||
00209      (track.GetBasic().NPlaneScint() < fEndNPlane))
00210     {
00211       return false;
00212     }
00213   
00214   dmap[0]=minStripPH;         
00215   
00216   //==================== Get Track Map===================
00217    PlaneMap track_map; 
00218    std::map<int,float> o_mean;
00219    if(!GetTrackMap(track,record,track_map,o_mean,StripMin))
00220    {
00221      return false;
00222    }
00223    //===check number of planes in track with PH cut======   
00224    const int nplane = static_cast<int>(track_map.size());
00225    if((nplane < fMinNPlane) ||
00226       (nplane > fMaxNPlane && fMaxNPlane>0)||
00227       (nplane < fEndNPlane))
00228    {
00229      return false;
00230    }
00231    //===Run through track map and find Analysis variables=
00232    for(PlaneMap::reverse_iterator pit = track_map.rbegin(); pit != track_map.rend(); ++pit)
00233    {
00234      ++count_plane;
00235       const unsigned short plane = pit -> first;
00236       if(last_plane ==-1) last_plane= plane;
00237       if(plane< last_plane) first_plane = plane;
00238       now_ph=0.0;
00239    
00240       vector<StripIter> &tvec = pit -> second;
00241       for(vector<StripIter>::iterator it = tvec.begin(); it!=tvec.end(); it++)
00242       {
00243         now_ph+= TrackStripEnergy((*it),track.TrackIndex(),StripMin);   
00244       }
00245 
00246       vector<StripIter>  ovec = Get(track, plane, record,o_mean,StripMin);
00247 
00248       for(vector<StripIter>::iterator oit = ovec.begin(); oit!=ovec.end(); oit++)
00249       {       
00250         double wpos =GetWPos((*oit)->GetPlane(),o_mean);
00251         double ovec_sc= OtherStripEnergy(*oit,GetVldc(record.GetHeader()),wpos,StripMin);
00252         if(ovec_sc> minStripPH) now_oph +=ovec_sc;              
00253       }
00254 
00255       // If you are at the end of the track
00256       if(count_plane>fEndNPlane) break;
00257       
00258       sum_ph+=(now_ph + now_oph);
00259       trk_ph+=now_ph;      
00260       sum_strip +=tvec.size();            
00261       last_ph=now_ph;      
00262       dmap[count_plane] =sum_ph;
00263       dmap[count_plane+10]= trk_ph;      
00264             
00265       if(now_ph+now_oph>l_ph)
00266       { 
00267         l_ph=now_ph + now_oph;
00268         l_ph_plane=count_plane;
00269       }           
00270    }
00271    
00272    dmap[Ibase+1]  = trk_ph/sum_ph;
00273    dmap[Ibase+2]  = sum_ph/sum_strip;
00274    dmap[Ibase+3]  = l_ph_plane;
00275    dmap[Ibase+4]  = l_ph;
00276 
00277 
00278    //==== Get track scatter quantities===============
00279    // Straggling
00280    // Straightness
00281 
00282    float pearu=0.0;    float pearv=0.0;
00283    float pearmodu=0.0; float pearmodv=0.0;
00284    
00285    
00286    if( FillShortVar::GetScatter(track_map, pearu,pearmodu, 1)&&
00287        FillShortVar::GetScatter(track_map, pearv,pearmodv, 2))
00288      {
00289        if(pearu>1.00) pearu=1.0;
00290   
00291      if(pearv>1.00) pearv=1.0;
00292        if(pearmodu>1.00) pearmodu=1.0;
00293        if(pearmodv>1.00) pearmodv=1.0;
00294        
00295        float scatu_1 = 0.01/(1.010-pearmodu);
00296        float scatv_1 = 0.01/(1.010-pearmodv);
00297        float scatu_2 = 0.01/(1.010-pearu);
00298        float scatv_2 = 0.01/(1.010-pearv);
00299        if(scatu_1>1.0 || scatv_1>1.0 ||scatu_2>1.0 || scatv_2>1.0){
00300          cerr<<"FillShortVar::Study - scattering variables greater than 1.0"<<endl;
00301        }
00302        dmap[Sbase+3]  = scatu_1;     
00303        dmap[Sbase+5]  = scatu_2;   
00304        dmap[Sbase+4]  = scatv_1;
00305        dmap[Sbase+6]  = scatv_2;
00306        dmap[Sbase+13]  = sqrt(pow(scatu_1-scatv_1,2))/(scatu_1+scatv_1);
00307        dmap[Sbase+15]  = sqrt(pow(scatu_2-scatv_2,2))/(scatu_2+scatv_2);
00308 
00309 
00310        dmap[Sbase+7]  = track.QP();
00311        if(pearmodu >0 || pearmodv>0)dmap[Sbase+8]  = 2*(pearmodu*pearmodv)/(pearmodu*pearmodu+pearmodv*pearmodv);
00312        else dmap[Sbase+8]  = 0.5;
00313        dmap[Sbase+9]  = track.QP()/track.ErrorQP();
00314 
00315      }
00316    return true;
00317 }

float Anp::FillShortVar::TrackStripEnergy ( Anp::StripIter  si,
short  index,
string  StripMin 
) const [private]

Definition at line 536 of file FillShortVar.cxx.

References fMinStripADC, fMinStripMIP, info, Anp::Strip::TrackInfo::mip_east, Anp::Strip::TrackInfo::mip_west, Munits::second, Anp::Strip::TrackInfo::sigmap_east, and Anp::Strip::TrackInfo::sigmap_west.

Referenced by GetTrackMap(), and Study().

00537 {
00538   if(StripMin.find("SIGCOR")!=string::npos && si->SigCor()>fMinStripADC) return si->SigCor();
00539 
00540   Strip::TrackInfoIter info_it = si->GetInfo(index);
00541 
00542   if(info_it == si-> InfoEndIter())
00543   {
00544     cout<<" FillShortVar::TrackStripEnergy -  Can't find info for track index  "<<index<<endl;
00545     return 0;
00546   }
00547 
00548   const Strip::TrackInfo &info = info_it -> second;
00549   double strip_charge = -1.0;
00550 
00551   if(StripMin.find("SIGMAP") !=string::npos)strip_charge =(info.sigmap_east+info.sigmap_west);
00552   else if(StripMin.find("MIP")!=string::npos)strip_charge =(info.mip_east   +info.mip_west   );
00553 
00554   if(strip_charge >fMinStripADC && StripMin.find("SIGMAP") !=string::npos) return strip_charge;
00555   if(strip_charge >fMinStripMIP && StripMin.find("MIP")    !=string::npos) return strip_charge;
00556   
00557   return 0;
00558 }


Member Data Documentation

bool Anp::FillShortVar::fDebug [private]

Definition at line 73 of file FillShortVar.h.

Referenced by Config(), GetTrackMap(), OtherStripEnergy(), Run(), and Study().

Definition at line 66 of file FillShortVar.h.

Referenced by Config(), and Study().

bool Anp::FillShortVar::fErase [private]

Definition at line 74 of file FillShortVar.h.

Referenced by Config(), and Run().

Definition at line 72 of file FillShortVar.h.

Referenced by Config(), and Run().

Definition at line 67 of file FillShortVar.h.

Referenced by Config(), and Run().

Definition at line 65 of file FillShortVar.h.

Referenced by Config(), IsGoodTrack(), and Study().

Definition at line 64 of file FillShortVar.h.

Referenced by Config(), and Study().

Definition at line 70 of file FillShortVar.h.

Referenced by Config(), FirstPassOtherStrip(), GetStripChargeCut(), and TrackStripEnergy().

Definition at line 71 of file FillShortVar.h.

Referenced by Config(), GetStripChargeCut(), and TrackStripEnergy().

Definition at line 84 of file FillShortVar.h.

Referenced by End(), and Run().

Definition at line 83 of file FillShortVar.h.

Referenced by End(), and Run().

Definition at line 76 of file FillShortVar.h.

Referenced by Config(), and IsGoodTrack().

double Anp::FillShortVar::frecolowE [private]

Definition at line 78 of file FillShortVar.h.

Referenced by Config(), and IsGoodTrack().

Definition at line 79 of file FillShortVar.h.

Referenced by Config(), and IsGoodTrack().

Definition at line 69 of file FillShortVar.h.

Referenced by FirstPassOtherStrip(), and Get().

Definition at line 68 of file FillShortVar.h.

Referenced by Config(), FirstPassOtherStrip(), and Get().

double Anp::FillShortVar::ftruelowE [private]

Definition at line 77 of file FillShortVar.h.

Referenced by Config(), and IsGoodTrack().


The documentation for this class was generated from the following files:

Generated on 24 Jul 2018 for loon by  doxygen 1.6.1