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

UberPlotsModule.cxx

Go to the documentation of this file.
00001 
00002 // $Id: UberPlotsModule.cxx,v 1.5 2007/03/01 17:37:57 rhatcher Exp $
00003 //
00004 // Fills histograms with data from UberRecords
00005 //
00006 // kordosky@hep.utexas.edu
00008 #include "CalDetDST/UberPlotsModule.h"
00009 
00010 #include "TString.h"
00011 #include "TClonesArray.h"
00012 #include "TFile.h"
00013 #include "TH1.h"
00014 #include "TH2.h"
00015 #include "TProfile.h"
00016 #include "TProfile2D.h"
00017 
00018 #include "MessageService/MsgService.h"
00019 #include "MinosObjectMap/MomNavigator.h"
00020 #include "JobControl/JobCModuleRegistry.h" // For JOBMODULE macro
00021 
00022 #include "CalDetDST/UberRecord.h"
00023 #include "CalDetDST/UberHit.h"
00024 
00025 TFile* UberPlotsModule::fOut=0;
00026 
00027 JOBMODULE(UberPlotsModule, "UberPlotsModule",
00028           "Make some plots from UberRecords");
00029 CVSID("$Id: UberPlotsModule.cxx,v 1.5 2007/03/01 17:37:57 rhatcher Exp $");
00030 //......................................................................
00031 
00032 UberPlotsModule::UberPlotsModule()
00033 {
00034 //======================================================================
00035 // does nothing
00036 //======================================================================
00037 
00038 }
00039 
00040 //......................................................................
00041 
00042 UberPlotsModule::~UberPlotsModule()
00043 {
00044 //======================================================================
00045 // does nothing
00046 //======================================================================
00047 
00048 /*
00049   // seg faulted -- why?
00050      if(fOut) {
00051           delete fOut;
00052           fOut=0;
00053      }
00054 */
00055 }
00056 
00057 //......................................................................
00058 
00059 void UberPlotsModule::BeginJob()
00060 {
00061 //======================================================================
00062 // opens a file to write histograms to
00063 // creates some histograms
00064 //======================================================================
00065 
00066 MSG("CalDetDST", Msg::kDebug)<<"UberPlotsModule::BeginJob()"<<endl;
00067 
00068 if(!fOut){
00069      fOut = new TFile("upm.root", "recreate");
00070 }
00071 
00072 // force histograms into the file
00073 Bool_t old_dir_stat = TH1::AddDirectoryStatus();
00074 TH1::AddDirectory(kTRUE);
00075 
00076 fOut->cd();
00077 TDirectory* d = new TDirectory(fDirName.c_str(), fDirName.c_str());
00078 d->cd();
00079 
00080 // define histograms
00081 h_mips=new TH1F("mips", "MIPs", 1000, 0, 2000);
00082 h_mips24=new TH1F("mips24", "MIPs (first 24 planes)", 1000, 0, 2000);
00083 
00084 h_ph = new TH1F("ph", "# Planes Hit", 60, -0.5, 59.5);
00085 
00086 for(int i=0; i<60; i++){
00087     TString n1="strip_occ_neg_p";n1+=i;
00088     TString t1="Strip Occupancy (-) side Plane "; t1+=i;
00089     TString n2="strip_occ_pos_p";n2+=i;
00090     TString t2="Strip Occupancy (+) side Plane "; t2+=i;
00091     fStripOcc1[i] = new TH1F(n1.Data(),t1.Data(),24,-0.5,23.5);
00092     fStripOcc2[i] = new TH1F(n2.Data(),t2.Data(),24,-0.5,23.5);
00093 }
00094 
00095 h_pse1 = new TH2F("pse1", "Plane vs. Strip: Even Planes (-) side", 
00096                   60, -0.5, 59.5, 24, -0.5, 23.5);
00097 h_pse2 = new TH2F("pse2", "Plane vs. Strip: Even Planes (+) side", 
00098                   60, -0.5, 59.5, 24, -0.5, 23.5);
00099 h_pso1 = new TH2F("pso1", "Plane vs. Strip: Odd Planes (-) side", 
00100                   60, -0.5, 59.5, 24, -0.5, 23.5);
00101 h_pso2 = new TH2F("pso2", "Plane vs. Strip: Odd Planes (+) side", 
00102                   60, -0.5, 59.5, 24, -0.5, 23.5);
00103 
00104 h_wpse1 = new TH2F("wpse1", 
00105                    "Plane vs. Strip: Weighted by MIPs Even Planes (-) side", 
00106                    60, -0.5, 59.5, 24, -0.5, 23.5);
00107 h_wpse2 = new TH2F("wpse2", 
00108                    "Plane vs. Strip: Weighted by MIPs Even Planes (+) side", 
00109                    60, -0.5, 59.5, 24, -0.5, 23.5);
00110 h_wpso1 = new TH2F("wpso1", 
00111                    "Plane vs. Strip: Weighted by MIPs Odd Planes (-) side", 
00112                    60, -0.5, 59.5, 24, -0.5, 23.5);
00113 h_wpso2 = new TH2F("wpso2", 
00114                    "Plane vs. Strip: Weighted by MIPs Odd Planes (+) side", 
00115                    60, -0.5, 59.5, 24, -0.5, 23.5);
00116 
00117 h_ptrig = new TH1F("ptrig", "Plane Trigger", 7, -0.5, 6.5);
00118 h_ptrig->GetXaxis()->SetTitle("n for n/n+1");
00119 
00120 h_edep = new TProfile("edep", "MIPs vs. Plane", 60, -0.5, 59.5);
00121 
00122 // Last thing:
00123 // switch back to old add dir status so as not to hose user
00124 TH1::AddDirectory(old_dir_stat);
00125 }
00126 
00127 
00128 //......................................................................
00129 
00130 void UberPlotsModule::Config(const Registry& r)
00131 {
00132 //======================================================================
00133 // Configure the module given the Registry r
00134 //======================================================================
00135   const char*    t;
00136 
00137   if (r.Get("DirName",t)) { fDirName = t; }
00138 
00139 }
00140 
00141 //......................................................................
00142 
00143 const Registry& UberPlotsModule::DefaultConfig() const
00144 {
00145 //======================================================================
00146 // Supply the default configuration for the module
00147 //======================================================================
00148   static Registry r; // Default configuration for module
00149 
00150   // Set name of config
00151   std::string name = this->JobCModule::GetName();
00152   name += ".config.default";
00153   r.SetName(name.c_str());
00154 
00155   // Set values in configuration
00156   r.UnLockValues();
00157 
00158   const char* s = "all";
00159   r.Set("DirName", s);
00160   
00161   r.LockValues();
00162 
00163   return r;
00164 }
00165 
00166  
00167 //......................................................................
00168 
00169 void UberPlotsModule::EndJob()
00170 {
00171 //======================================================================
00172 // write and close file
00173 //======================================================================
00174 
00175      if(fOut->IsOpen()){
00176           fOut->Write();
00177           fOut->Close();
00178      }
00179 }
00180 
00181 //......................................................................
00182 
00183 JobCResult UberPlotsModule::Ana(const MomNavigator* mom)
00184 {
00185 //======================================================================
00186 // does the plotting
00187 //======================================================================
00188 const UberRecord* ur = 
00189     dynamic_cast<const UberRecord*>(mom->GetFragment("UberRecord"));
00190 
00191 if(!ur) return JobCResult::kAOK; // don't care if there isn't a record!
00192 
00193 // require it to be a pion, nooverlap
00194 
00195 //if(!( (ur->cpid.pid&0x04)&&(ur->cpid.nov==1)) ) return JobCResult::kAOK;
00196 
00197 // loop over hits the first time to fill array of mips in each plane
00198 float mip_by_plane[60]={0.0};
00199 const TClonesArray* hitlist = ur->GetHitList();
00200 for(int i=0; i<hitlist->GetSize(); i++){
00201     const UberHit* hit= static_cast<const UberHit*>(hitlist->At(i));
00202     if(!hit) continue;
00203     
00204     const int plane=hit->GetPlane();
00205     if((plane<0)||(plane>59)) continue;
00206     const int strip=hit->GetStrip();
00207     if((strip<0)||(strip>23)) continue;
00208 
00209     mip_by_plane[plane]+=(hit->GetPosMIP()+hit->GetNegMIP());
00210 
00211 }
00212 
00213 map<double,int> pmap;
00214 for(int i=0; i<60; i++){pmap.insert(pair<double,int>(mip_by_plane[i],i));}
00215 
00216 
00217 // ok, now apply a plane trigger!
00218 
00219 const int trig = PlaneTrigger(mip_by_plane, 60);
00220 h_ptrig->Fill(trig);
00221 
00222 
00223 // cut on the trigger
00224 
00225 const int lowtrig=2; // n in n/n+1 ... should make configurable
00226 
00227 // not failing it, just don't want to histogram it
00228 if(trig<lowtrig) return JobCResult::kAOK; 
00229 
00230 h_mips->Fill(ur->totmip);
00231 h_ph->Fill(ur->nhitplanes);
00232 
00233 for(int i=0; i<60; i++) h_edep->Fill(i, mip_by_plane[i]);
00234 
00235 // compute # of mips in first 24 planes
00236 double mips24=0.0;
00237 for(int i=1; i<24; i++) mips24+=mip_by_plane[i];
00238 h_mips24->Fill(mips24);
00239 
00240 // loop over hits again
00241 for(int i=0; i<hitlist->GetSize(); i++){
00242     const UberHit* hit= static_cast<const UberHit*>(hitlist->At(i));
00243     if(!hit) continue;
00244     
00245     const int plane=hit->GetPlane();
00246     if((plane<0)||(plane>59)) continue;
00247     const int strip=hit->GetStrip();
00248     if((strip<0)||(strip>23)) continue;
00249     
00250     // fill strip occupancy histograms
00251     if(hit->GetNegNPE()>0.0) {
00252         fStripOcc1[plane]->Fill(strip);
00253         if(plane%2==0) {
00254             h_pse1->Fill(plane,strip);
00255             h_wpse1->Fill(plane,strip,hit->GetNegMIP()/ur->totmip);
00256             }
00257         else {
00258             h_pso1->Fill(plane,strip);
00259             h_wpso1->Fill(plane,strip,hit->GetNegMIP()/ur->totmip);
00260             }
00261         }
00262     if(hit->GetPosNPE()>0.0) {
00263         fStripOcc2[plane]->Fill(strip);
00264         if(plane%2==0) {
00265             h_pse2->Fill(plane,strip);
00266             h_wpse2->Fill(plane,strip,hit->GetPosMIP()/ur->totmip);
00267             }
00268         else {
00269             h_pso2->Fill(plane,strip);
00270             h_wpso2->Fill(plane,strip,hit->GetPosMIP()/ur->totmip);
00271             }
00272         }
00273     }
00274 
00275 
00276   return JobCResult::kPassed; // kNoDecision, kFailed, etc.
00277 }
00278 
00279 //......................................................................
00280 
00281 void UberPlotsModule::Help()
00282 {
00283 //======================================================================
00284 // I should print something here....
00285 //======================================================================
00286 }
00287 
00289 
00290 
00291 int UberPlotsModule::PlaneTrigger(float* qvec, int len)
00292     {
00293     // qvec= array of charge,pes,mips by plane
00294     // len= the length of qvec
00295     const float thresh = 0.0; // threshold to count a plane
00296     int trig=0;
00297     int lown=0; // n-1 for the lowest n to try (eg lown=1 implies 2/3)
00298     for(int i=0; i<len; i++){
00299         // form a window with j+1 elements
00300         // j=n in n/n+1
00301         for(int j=6; j>lown; j--){
00302             int count=0;
00303             // loop over the window, careful not to go overboard
00304             for(int k=i; (k<=i+j && k<len); k++){
00305                 if(qvec[k]>thresh) count++;
00306                 }
00307             // don't assign if we already have a more restrictive trigger
00308             if(count>=j && count>trig) { 
00309                 trig=j; // assign the trigger
00310                 // bump the window so we only look for more restrictive triggers 
00311                 lown=j;
00312                 }
00313             }
00314         }
00315     return trig;
00316     }

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