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

NtpSRBleachFiller.cxx

Go to the documentation of this file.
00001 
00002 //
00003 // NtpSRBleachFiller
00004 //
00005 // Package: CandNtupleSR/Module
00006 //
00007 // Purpose: Methods for filling an NtpSRBleach object.
00008 //
00010 #include <iostream>
00011 using namespace std;
00012 
00013 #include "CandNtupleSR/Module/NtpSRBleachFiller.h"
00014 #include "CandNtupleSR/Module/NtpSRNDAPPlaneHistory.h"
00015 #include "CandData/CandRecord.h"
00016 #include "RawData/RawRecord.h"
00017 #include "RawData/RawDigitDataBlock.h"
00018 #include "RawData/RawDigit.h"
00019 #include "RecoBase/CandStripHandle.h"
00020 #include "RecoBase/CandStripListHandle.h"
00021 #include "RecoBase/CandTrackHandle.h"
00022 #include "RecoBase/CandEventHandle.h"
00023 #include "Record/RecMinosHdr.h"
00024 #include "MessageService/MsgService.h"
00025 #include "Validity/VldContext.h"
00026 
00027 CVSID("$Id: NtpSRBleachFiller.cxx,v 1.2 2005/11/07 03:04:02 schubert Exp $");
00028 
00029 // Definition of methods (alphabetical order)
00030 // ***************************************************
00031 
00032 //......................................................................
00033 double NtpSRBleachFiller::GetEventDuration(const CandEventHandle* cndevt) {
00034   //
00035   // Purpose: Calculate event duration from first and last strip time in 
00036   //          event. 
00037   //
00038   // Arguments: CandEventHandle ptr.
00039   // 
00040   // Return: event duration in nsec.
00041   //
00042   // Author: Tobias Raufer (tobias.raufer@physics.ox.ac.uk) 
00043   //
00044   // Creation Date: 11/05
00045 
00046   Double_t result = -1;
00047   if (!cndevt){
00048     MSG("NtpSR",Msg::kWarning) 
00049       << "No CandEventHandle Found, will return the default value"<<endl;
00050     return result;
00051   }
00052 
00053   const VldContext* vldc = cndevt->GetVldContext();
00054   Detector::Detector_t fDetType = vldc->GetDetector();
00055   if (fDetType!=Detector::kNear) return result;
00056 
00057   // loop over all strips and find earliest and latest strip time
00058   Double_t evtStart = 99999;
00059   Double_t evtEnd = -1;
00060   CandStripHandleItr stpItr(cndevt->GetDaughterIterator());
00061   while (CandStripHandle* strip=dynamic_cast<CandStripHandle*>(stpItr())){
00062    
00063     if (strip->GetTime() < evtStart) {
00064       evtStart = strip->GetTime();
00065     }
00066     if (strip->GetTime() > evtEnd) {
00067       evtEnd = strip->GetTime();
00068     }
00069  }
00070   result = (evtEnd - evtStart)*1e9; // result is in nsec
00071   return result;
00072 }
00073 
00074 //......................................................................
00075 double NtpSRBleachFiller::GetFixedWindowPH(const CandEventHandle* cndevt, 
00076                                            const CandRecord* cndrec) {
00077   //
00078   // Purpose: Calculate predicted afterpulsing ph in a fixed window around
00079   //          the event vertex.
00080   //
00081   // Arguments: CandEventHandle ptr, CandRecord ptr.
00082   // 
00083   // Return: fixed window ph.
00084   //
00085   // Author: Tobias Raufer (tobias.raufer@physics.ox.ac.uk) 
00086   //
00087   // Creation Date: 11/05
00088 
00089   Double_t result = -1;
00090   if (!cndevt){
00091     MSG("NtpSR",Msg::kWarning) 
00092       << "No CandEventHandle Found, will return the default value"<<endl;
00093     return result;
00094   }
00095   if (!cndrec){
00096     MSG("NtpSR",Msg::kWarning) 
00097       << "No CandRecord Found, will return the default value"<<endl;
00098     return result;
00099   }
00100 
00101   VldContext vldc = cndrec->GetHeader()->GetVldContext();
00102   Detector::Detector_t fDetType = vldc.GetDetector();
00103   if (fDetType!=Detector::kNear) return result;
00104 
00105   // construct a NtpSRNDAPPlaneHistory object for each plane
00106   // this class contains the exponential model for the afterpulsing
00107   // based on the previous activity in the snarl
00108   map<Int_t,NtpSRNDAPPlaneHistory> planeHistMap; 
00109   
00110   for (Int_t plane=1; plane<282; plane++) {
00111     NtpSRNDAPPlaneHistory h(plane);
00112     planeHistMap.insert(std::pair<Int_t,NtpSRNDAPPlaneHistory>(plane,h));
00113   }
00114 
00115   // loop over all strips and fill NtpSRNDAPPlaneHistory objects
00116   const CandStripListHandle *striplisthandle 
00117     = dynamic_cast <const CandStripListHandle*> 
00118     (cndrec->FindCandHandle("CandStripListHandle"));
00119   if ( !striplisthandle ) {
00120     MSG("NtpSR",Msg::kWarning) 
00121       << "No strip list found in CandRecord. "
00122       << "Will return the default value " << endl;
00123     return result; // no strips => done
00124   }
00125 
00126   TIter stripItr(striplisthandle->GetDaughterIterator());
00127   while ( CandStripHandle* strip=dynamic_cast<CandStripHandle*>(stripItr())) {
00128     
00129     Int_t plane = strip->GetPlane();
00130 
00131     // add strip to NtpSRNDAPPlaneHistory object
00132     map<Int_t,NtpSRNDAPPlaneHistory>::iterator pos;    
00133     pos = planeHistMap.find(plane);
00134     if (pos!=planeHistMap.end())
00135       pos->second.AddStrip(strip->GetTime(),
00136                            strip->GetCharge(CalDigitType::kSigCorr));  
00137     else 
00138       MSG("NtpSR",Msg::kWarning) 
00139         << "No NtpSRNDAPPlaneHistory object for plane " << plane 
00140         << ". Not using this strip!" << endl;
00141   }
00142 
00143   // calculate pred. afterpulsing in 33 plane window around the vertex
00144   
00145   // find vertex plane; if track exists, use track vertex
00146   Int_t vtxPlane = -1; 
00147   const CandTrackHandle* trk = cndevt->GetPrimaryTrack();
00148   if (trk) 
00149     vtxPlane = trk->GetVtxPlane();
00150   else vtxPlane = cndevt->GetVtxPlane();
00151   
00152   Int_t minPlane = max(vtxPlane-2,1);
00153   Int_t maxPlane = min(vtxPlane+30,281);
00154 
00155   Double_t evtTime = 9999; // get event time from first strip in event
00156   CandStripHandleItr stpItr(cndevt->GetDaughterIterator());
00157   while (CandStripHandle* strip=dynamic_cast<CandStripHandle*>(stpItr())){
00158     if (strip->GetTime() < evtTime) {
00159       evtTime = strip->GetTime();
00160     }
00161   }
00162 
00163   Double_t APsum= 0;
00164   for (Int_t pl = minPlane; pl<maxPlane;pl++) {
00165     map<Int_t,NtpSRNDAPPlaneHistory>::iterator pos;    
00166     pos = planeHistMap.find(pl);
00167     if (pos!=planeHistMap.end())
00168       APsum +=
00169         pos->second.APPrediction(evtTime);
00170     else 
00171       MSG("NtpSR",Msg::kWarning) 
00172         << "No NtpSRNDAPPlaneHistory object for plane " << pl 
00173         << ". Not adding afterpulsing prediction for this plane!" 
00174         << endl;
00175   }
00176   result = APsum;
00177   return result;
00178 }
00179 
00180 //......................................................................
00181 float NtpSRBleachFiller::GetlateBucketPHFraction(const CandEventHandle* cndevt,
00182                                                  const RawRecord* rawrec) {
00183   //
00184   // Purpose: Calculate late bucket ph fraction for each event.
00185   //
00186   // Arguments: CandEventHandle ptr, RawRecord ptr.
00187   // 
00188   // Return: late bucket ph fraction. -1 if error.
00189   //
00190   // Authors: Tingjun Yang (tjyang@stanford.edu) 
00191   //          Jiajie Ling  (ling@barney.physics.sc.edu)
00192   //
00193   // Creation date: 11/05 
00194 
00195   float ratio = -1;
00196   if (!cndevt){
00197     MSG("NtpSR",Msg::kWarning) 
00198       << "No CandEventHandle Found, will return the default value"<<endl;
00199     return ratio;
00200   }
00201   if (!rawrec){
00202     MSG("NtpSR",Msg::kWarning) 
00203       << "No RawRecord Found, will return the default value"<<endl;
00204     return ratio;
00205   }
00206 
00207   VldContext vldc = rawrec->GetHeader()->GetVldContext();
00208   Detector::Detector_t fDetType = vldc.GetDetector();
00209   if (fDetType!=Detector::kNear) return ratio;
00210 
00211   const RawDigitDataBlock *rddb = dynamic_cast<const RawDigitDataBlock *>
00212                                   (rawrec->FindRawBlock("RawDigitDataBlock"));
00213 
00214   if (!rddb){
00215     MSG("NtpSR",Msg::kWarning) 
00216       << "No RawDigitDataBlock Found, will return the default value"<<endl;
00217     return ratio;
00218   }
00219 
00220   int firstbucket = 999999999; //the first time bucket in the current event
00221   int firstbucket_corr = 999999999; //corrected firstbucket after removing early digits
00222  
00223   CandStripHandleItr stripItr(cndevt->GetDaughterIterator());
00224   while (CandStripHandle* strip=dynamic_cast<CandStripHandle*>(stripItr())){
00225     CandDigitHandleItr digitItr(strip->GetDaughterIterator());
00226     while (CandDigitHandle *digit = dynamic_cast<CandDigitHandle*>(digitItr())){
00227       const RawDigit* rd=dynamic_cast<const RawDigit*>(rddb->At(digit->GetRawDigitIndex()));
00228       if(rd->GetTDC()<firstbucket) firstbucket = rd->GetTDC();
00229       if(rd->GetTDC()<firstbucket_corr && rd->GetADC()>0.01*cndevt->GetCharge(CalStripType::kSigLin)){//get rid of early digit(s) with low ph (less than 1% of total ADC)
00230         firstbucket_corr = rd->GetTDC();
00231       }
00232     }
00233   }
00234   if (firstbucket_corr == 999999999) firstbucket_corr = firstbucket;
00235 
00236   float totadc = 0;  //total ADC in the current event
00237   float lateadc = 0; //total ADC after first 3 time buckets
00238   CandStripHandleItr stripItr2(cndevt->GetDaughterIterator());
00239   while (CandStripHandle* strip=dynamic_cast<CandStripHandle*>(stripItr2())){
00240     CandDigitHandleItr digitItr(strip->GetDaughterIterator());
00241     while (CandDigitHandle *digit = dynamic_cast<CandDigitHandle*>(digitItr())){
00242       const RawDigit* rd=dynamic_cast<const RawDigit*>(rddb->At(digit->GetRawDigitIndex()));
00243       totadc += rd->GetADC();
00244       if (rd->GetTDC()>=firstbucket_corr+3){
00245         lateadc += rd->GetADC();
00246       }      
00247     }
00248   }
00249 
00250   if (totadc) ratio = lateadc/totadc;
00251 
00252   return ratio;
00253 }
00254 
00255 //......................................................................
00256 float NtpSRBleachFiller::GetstraightPHFraction(const CandEventHandle *evt,
00257                                                const CandRecord *crec){
00258   //
00259   // Purpose: Calculate the fraction of hits in an event that have previous
00260   //          activity in them.
00261   //
00262   // Arguments: CandEventHandle ptr, CandRecord ptr.
00263   // 
00264   // Return: straight ph fraction. -1 if error.
00265   //
00266   // Authors: Tom Osiecki (osiecki@mail.hep.utexas.edu)
00267   //
00268   // Creation date: 11/05 
00269   //
00270 
00271   if(!evt) {
00272     MSG("NtpSR",Msg::kWarning) << "No CandEventHandle Found in GetstraightPHFraction" << endl;
00273     return -1.0;
00274   }
00275 
00276   if(!crec) {
00277     MSG("NtpSR",Msg::kWarning) << "No CandRecord Found in GetstraightPHFraction" << endl;
00278     return -1.0;
00279   }
00280 
00281   const CandStripListHandle *striplisthandle = dynamic_cast <const CandStripListHandle*> 
00282     (crec->FindCandHandle("CandStripListHandle"));
00283 
00284   const CandStripListHandle *striplisthandle2 = dynamic_cast <const CandStripListHandle*> 
00285     (crec->FindCandHandle("CandStripListHandle"));
00286 
00287   if(!striplisthandle) return -1.0;
00288 
00289   TIter stripItr(striplisthandle->GetDaughterIterator());
00290   TIter stripItr2(striplisthandle2->GetDaughterIterator());
00291   
00292   int totalstrips = striplisthandle->GetNDaughters();      
00293   int *striparray = new int[totalstrips];
00294   std::map<Int_t, Int_t> uidmap;
00295 
00296   for(int zeroout = 0; zeroout < totalstrips; zeroout++) {
00297     striparray[zeroout] = -1;
00298   }
00299  
00300   Int_t index = 0;
00301   while(CandStripHandle* strip = dynamic_cast<CandStripHandle*> (stripItr())) {
00302     Int_t uid = strip -> GetUidInt();
00303     
00304     stripItr2.Reset();
00305     while(CandStripHandle* strip2 = dynamic_cast<CandStripHandle*> (stripItr2())) {
00306       Int_t uid2 = strip2 -> GetUidInt();
00307           
00308       if(uid != uid2 && 
00309          strip -> GetStrip() == strip2 -> GetStrip() && 
00310          strip -> GetPlane() == strip2 -> GetPlane()) {
00311       
00312         if((strip -> GetTime() - strip2 -> GetTime())*1.0e9 > 0.0) {
00313           striparray[index]++; 
00314           uidmap[uid] = index;
00315         }
00316         
00317       } // Don't compare the same strip to itself.
00318     }
00319     index++;
00320   }
00321   
00322   Int_t nstp = 0, nstpevt = 0;
00323   CandStripHandleItr evtstripItr(evt->GetDaughterIterator());
00324   while (CandStripHandle* strip = dynamic_cast<CandStripHandle*> (evtstripItr())) {
00325     nstpevt++;
00326     if(striparray[uidmap[strip -> GetUidInt()]] > -1.0) nstp++;
00327   }
00328 
00329   Float_t ratio = (float) nstp / nstpevt;
00330   MSG("NtpSR",Msg::kDebug) << "GetstraightPHFraction ratio = " << ratio << endl;
00331 
00332   delete [] striparray; striparray = 0;
00333 
00334   return ratio;
00335 }

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