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

ShieldPlankListModule.cxx

Go to the documentation of this file.
00001 
00002 // $Id: ShieldPlankListModule.cxx,v 1.2 2007/03/01 17:02:52 rhatcher Exp $
00003 // Shield Strip module
00004 // 
00005 //
00006 // Caius Howcroft<howcroft@hep.phy.cam.ac.uk>
00008 #include "ShieldPlank/ShieldPlankListModule.h"
00009 #include "MessageService/MsgService.h"
00010 #include "MinosObjectMap/MomNavigator.h"
00011 #include "JobControl/JobCModuleRegistry.h" // For JOBMODULE macro
00012 #include "CandDigit/CandDigitListHandle.h"
00013 #include "CandDigit/CandDigitHandle.h"
00014 #include "CandData/CandHeader.h"
00015 #include "CandData/CandRecord.h"
00016 #include "Candidate/CandContext.h"
00017 #include "UgliGeometry/UgliGeomHandle.h"
00018 #include "Algorithm/AlgConfig.h"
00019 #include "Algorithm/AlgFactory.h"
00020 #include "Algorithm/AlgHandle.h"
00021 
00022 
00023 #include "ShieldPlank/CandShieldPlankList.h"
00024 #include "ShieldPlank/CandShieldPlankHandle.h"
00025 
00026 
00027 JOBMODULE(ShieldPlankListModule, "ShieldPlankListModule",
00028           "");
00029 CVSID("$Id: ShieldPlankListModule.cxx,v 1.2 2007/03/01 17:02:52 rhatcher Exp $");
00030 
00031 ClassImp(ShieldPlankListModule)
00032 
00033 
00034 //......................................................................
00035 
00036 ShieldPlankListModule::ShieldPlankListModule():
00037   fNameListOut("shieldstriplist"),
00038   fTitleListOut("FarDet Veto shield strips"),
00039   fListIn("canddigitlist"),
00040   fWriteNtp(1), fFile(0), fTree(0)
00041 {
00042   //======================================================================
00043   // Create the module and configure the default alg
00044   //======================================================================
00045   
00046 }
00047 
00048 //......................................................................
00049 
00050 ShieldPlankListModule::~ShieldPlankListModule()
00051 {
00052 //======================================================================
00053 // FILL_IN: [Document your code!!]
00054 //======================================================================
00055 }
00056 
00057 //......................................................................
00058 
00059 void ShieldPlankListModule::BeginJob()
00060 {
00061 //======================================================================
00062 // FILL_IN: [Document your code!!]
00063 //======================================================================
00064   TDirectory* cdir = gDirectory;
00065   if(fWriteNtp)
00066     {
00067       fFile = new TFile("shieldplank.root", "recreate");
00068       fFile->cd();     
00069       fTree = new TTree("splank", "ShieldPlanks");
00070       fTree->SetDirectory(fFile);
00071 
00072       fTree->Branch("fRun", &fRun, "fRun/I");
00073       fTree->Branch("fSnarl", &fSnarl, "fSnarl/I");
00074       fTree->Branch("fTime", &fTime, "fTime/D");
00075       fTree->Branch("fCharge", &fCharge, "fCharge/D");
00076       fTree->Branch("fX", &fX, "fX/D");
00077       fTree->Branch("fY", &fY, "fY/D");
00078       fTree->Branch("fZ", &fZ, "fZ/D");
00079       fTree->Branch("fSection", &fSection, "fSection/I");
00080       fTree->Branch("f2End", &f2End, "f2End/I");
00081       
00082     }
00083   gDirectory = cdir;
00084 }
00085 
00086 //......................................................................
00087 
00088 void ShieldPlankListModule::EndJob()
00089 {
00090 //======================================================================
00091 // FILL_IN: [Document your code!!]
00092 //======================================================================
00093   TDirectory* cdir = gDirectory;
00094   fFile->cd();
00095   fTree->Write();
00096   gDirectory = cdir;
00097 }
00098 
00099 //......................................................................
00100 
00101 JobCResult ShieldPlankListModule::Ana(const MomNavigator* mom)
00102 {
00103   cout.precision(4);
00104   cout.setf(ios_base::scientific,ios_base::floatfield);
00105   //======================================================================
00106   //Get pointers to Candidates 
00107   //
00108   const CandRecord *const candrec = dynamic_cast<const CandRecord *>
00109              (mom->GetFragment("CandRecord", "PrimaryCandidateRecord"));
00110   if (candrec == 0) {
00111     MSG("ShieldPlank", Msg::kWarning) << "No PrimaryCandidateRecord in MOM."<< endl;
00112     return JobCResult::kWarning; // Raise warning flag
00113   }
00114  
00115   const CandHeader* ch =   candrec->GetCandHeader();
00116   fRun   =  ch->GetRun();
00117   fSnarl =  ch->GetSnarl();
00118   
00119 
00120   const CandShieldPlankListHandle* const shieldstriplisthandle = dynamic_cast<const CandShieldPlankListHandle* const>(candrec->FindCandHandle("CandShieldPlankListHandle"));
00121  
00122   UgliGeomHandle ugh(*(candrec->GetVldContext()));
00123  
00124   CandShieldPlankHandleItr sstripIter(shieldstriplisthandle->GetDaughterIterator());
00125   cout << "======================================================================================"<<endl;
00126   cout << "CandPlankList: "<< shieldstriplisthandle->GetNDaughters()<<endl;
00127   while(const CandShieldPlankHandle* const sstrip = dynamic_cast<const CandShieldPlankHandle* const>(sstripIter()))
00128     {
00129       fSection = sstrip->GetSection();
00130       fX = sstrip->GetMeanX();
00131       fY = sstrip->GetMeanY();
00132       
00133       if(sstrip->GetCharge(StripEnd::kNorth)>0.0)
00134         {
00135 
00136           fZ = sstrip->GetMeanZ(StripEnd::kNorth);
00137           fCharge = sstrip->GetCharge(StripEnd::kNorth);
00138           fTime = sstrip->GetMeanTime(StripEnd::kNorth);
00139           f2End = 0;
00140           if(sstrip->GetCharge(StripEnd::kSouth)>0.0) f2End=1;
00141           fTree->Fill();
00142         }
00143 
00144       if(sstrip->GetCharge(StripEnd::kSouth)>0.0)
00145         {
00146           fZ = sstrip->GetMeanZ(StripEnd::kSouth);
00147           fCharge = sstrip->GetCharge(StripEnd::kSouth);
00148           fTime = sstrip->GetMeanTime(StripEnd::kSouth);
00149           f2End = 0;
00150           if(sstrip->GetCharge(StripEnd::kNorth)>0.0) f2End=1;
00151           fTree->Fill();
00152         }
00153 
00154       cout << "Strip: "<< "Section:"<<sstrip->GetSection()<< ", "<<sstrip->GetSubSection()<<endl
00155            << "   XYZ      :"<<sstrip->GetMeanX()<< ", "<< sstrip->GetMeanY()<<", "<< sstrip->GetMeanZ(StripEnd::kSouth)<<"->"<<sstrip->GetMeanZ(StripEnd::kNorth)<<endl
00156            << "   #Errors  :" << sstrip->GetNErrors()<<endl
00157            << "   ChargeN/S:" << sstrip->GetCharge(StripEnd::kNorth)<<" / "<<  sstrip->GetCharge(StripEnd::kSouth)<<endl
00158            << "   Time  N/S:" << sstrip->GetMeanTime(StripEnd::kNorth)<< " / "<<  sstrip->GetMeanTime(StripEnd::kSouth)<<endl
00159            << "   NDigits  :" << sstrip->GetNDaughters()<<endl
00160            << "   Z        :" << sstrip->GetMeanZ(StripEnd::kNorth)<< " / "<<sstrip->GetMeanZ(StripEnd::kSouth)<<endl;
00161       
00162       TIter digitIter(sstrip->GetDaughterIterator());
00163       while(const CandDigitHandle* digit = dynamic_cast<const CandDigitHandle*>(digitIter()))
00164         {
00165           const PlexSEIdAltL& paltl = digit->GetPlexSEIdAltL();
00166 
00167           
00168           cout << "DIGIT:"<<endl;
00169           cout << "------"<<endl;
00170           cout << "adc:"<<digit->GetCharge(CalDigitType::kNone)<<"  "<< endl;
00171           for(PlexSEIdAltL::const_iterator iter = paltl.begin();
00172               iter!=paltl.end();
00173               ++iter){
00174             const PlexStripEndId  pseid = paltl.GetBestSEId();            
00175             //cout << "     plane:" << pseid.GetPlane()<<" spt:"<< pseid.GetStrip()<< " end:" <<pseid.GetEnd()<<endl;   
00176             if(paltl.IsValid())
00177               {
00178                 const UgliStripHandle ush  = ugh.GetStripHandle(pseid);
00179                 if(ush.IsValid())
00180                   {
00181                     TVector3 gpos(ush.GlobalPos(0.0));
00182                     cout << "    xyz:"<< gpos.X()<<", "<<gpos.Y()<<", "<<gpos.Z()<<endl;
00183                     
00184                 }else{
00185                   cout <<" ###INVALID GEOM###"<<endl;
00186                 }
00187 
00188             }else{
00189               cout <<" ###INVALID PLEX###"<<endl;
00190             }
00191           }
00192         }
00193     }
00194 
00195   return JobCResult::kPassed; // kNoDecision, kFailed, etc.
00196 }
00197 
00198 //......................................................................
00199 
00200 JobCResult ShieldPlankListModule::Reco(MomNavigator* mom)
00201 {
00202 //======================================================================
00203 // FILL_IN: [Document your code!!]
00204 //======================================================================
00205   JobCResult result(JobCResult::kPassed);
00206  
00207   CandContext cx(this, mom);
00208     
00209   // Find PrimaryCandidateRecord fragment in MOM.
00210   CandRecord *candrec = dynamic_cast<CandRecord *>
00211              (mom->GetFragment("CandRecord", "PrimaryCandidateRecord"));
00212   if (candrec == 0) {
00213     MSG("ShieldPlank", Msg::kWarning) << "No PrimaryCandidateRecord in MOM."
00214                                                                 << endl;
00215     result.SetWarning().SetFailed();
00216     return result;
00217   }else {
00218     MSG("ShieldPlank", Msg::kDebug)<< "Set CandRecord pointer in CandContext." << endl;
00219     cx.SetCandRecord(candrec);
00220   }
00221   
00222   CandDigitListHandle *cdlh = dynamic_cast<CandDigitListHandle *>
00223     (candrec->FindCandHandle("CandDigitListHandle", fListIn.c_str()));
00224   if(!cdlh)
00225     {
00226       MSG("ShieldPlank", Msg::kWarning) << "No CandDigitList called " << fListIn<<" in CandRecord."<< endl;
00227       result.SetWarning().SetFailed();
00228       return result;
00229       
00230     }  
00231   cx.SetDataIn(cdlh);
00232 
00233   AlgFactory &af = AlgFactory::GetInstance();
00234   AlgHandle adlh = af.GetAlgHandle(fAlgShieldPlankList.c_str(),
00235                                    fAlgShieldPlankConfig.c_str());
00236   
00237 
00238   CandShieldPlankListHandle csslh = CandShieldPlankList::MakeCandidate(adlh, cx);
00239   csslh.SetName(fNameListOut.c_str());
00240   csslh.SetTitle(fTitleListOut.c_str());
00241 
00242   //Give Candidate to candrecord to hold
00243   candrec->SecureCandHandle(csslh);
00244 
00245   return JobCResult::kPassed; // kNoDecision, kFailed, etc.
00246 }
00247 
00248 //......................................................................
00249 
00250 const Registry& ShieldPlankListModule::DefaultConfig() const
00251 {
00252 //======================================================================
00253 // Supply the default configuration for the module
00254 //======================================================================
00255   static Registry r; // Default configuration for module
00256 // Find PrimaryCandidateRecord fragment in MOM.
00257   
00258   // Set values in configuration
00259   r.UnLockValues();
00260   r.Set("NameListOut",   "shieldstriplist");
00261   r.Set("TitleListOut",  "shieldstriplist");
00262   r.Set("AlgName",       "AlgShieldPlankList");
00263   r.Set("AlgConfig",     "default");
00264 
00265   r.LockValues();
00266 
00267   // Set name of config
00268   std::string name = this->JobCModule::GetName();
00269   name += ".config.default";
00270   r.SetName(name.c_str());
00271 
00272   return r;
00273 }
00274 
00275 //......................................................................
00276 
00277 void ShieldPlankListModule::Config(const Registry& r)
00278 {
00279 //======================================================================
00280 // Configure the module given the Registry r
00281 //======================================================================
00282 //  double tmpd;
00283   const char* tmps;
00284   int tmpi;
00285 
00286   if (r.Get("NameListOut",tmps)) { fNameListOut = tmps; }
00287   if (r.Get("TitleListOut",tmps)) { fTitleListOut = tmps; }
00288   if (r.Get("AlgName",   tmps))  { fAlgShieldPlankList = tmps;}
00289   if (r.Get("AlgConfig", tmps))  { fAlgShieldPlankConfig = tmps;}
00290   
00291   if (r.Get("NameListIn", tmps))  { fListIn = tmps;}
00292   if (r.Get("WriteNtp", tmpi)) {fWriteNtp = tmpi;}
00293   
00294 
00295 }
00296 

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