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

CellHitMerge.cxx

Go to the documentation of this file.
00001 
00002 // $Id: CellHitMerge.cxx,v 1.2 2009/08/28 18:35:14 vahle Exp $
00003 //
00004 // A module to merge CellHits if necessary
00005 // also removes "crazy" cells
00006 // reads in vector of CellHits from Cal() Folder
00007 // writes out new merged vector to a subfolder in Cal called MergeHits
00008 // originally adapted from RecoSubShower::FormStripList
00009 //
00010 // \author $Author: vahle $
00011 //
00013 #include <iostream>
00014 #include <vector>
00015 #include <cmath>
00016 #include "TH2D.h"
00017 #include "TH1D.h"
00018 #include "Geometry/Geometry.h"
00019 #include "JobControl/Exception.h"
00020 #include "Header/Header.h"
00021 #include "RecoBase/CellHit.h"
00022 #include "CellHitMerge/CellHitMerge.h"
00023 
00024 using namespace std;
00025 using namespace cellhitmerge;
00026 using namespace recobase;
00027 
00028 // This macro declares the existence of your module to ana
00029 MODULE_DECL(CellHitMerge); //Required!
00030 
00031 CellHitMerge::CellHitMerge(const char* version) :
00032   jobc::Module("cellhitmerge::CellHitMerge"), // Required!
00033   nprinted(0),
00034   fSkipMe(false),
00035   nevtmerged(0),
00036   maxdiffcells(0),
00037   npruned(0),
00038   maxpruned(0)
00039 {
00040   delTMerged = new TH1D("delTMerged","",200,0,2000);
00041   delPHMerged = new TH1D("delPHMerged","",300,-1500,1500);
00042   delPhvdelT = new TH2D("delPhvdelT","",200,0,2000,300,-1500,1500);
00043   celldiff = new TH1D("celldiff","",31,-0.5,30.5);
00044   delPhvPh = new TH2D("delPhvPh","",150,0,1500,300,-1500,1500);
00045   phvph = new TH2D("phvph","",150,0,1500,150,0,1500);
00046 
00047   this->SetCfgVersion(version); // Required!
00048 }
00049 
00050 //......................................................................
00051 
00052 void CellHitMerge::Update(const cfg::Config& c)
00053 {
00054 
00055 
00056   //maybe we wont want to do this step sometimes
00057   int domergestep;
00058   c("DoMergeStep").Get(domergestep);
00059   if(domergestep==0){
00060     fSkipMe=true;
00061   }
00062   else{
00063     fSkipMe=false;
00064   }
00065 
00066 }
00067 
00068 //......................................................................
00069 
00070 CellHitMerge::~CellHitMerge()
00071 {
00072   cout<<"Number of events that got pruned: "<<npruned<<" max pruning: "<<maxpruned<<" cells"<<endl;
00073   cout<<"Number of events that got merged or pruned: "<<nevtmerged<<" max difference: "<<maxdiffcells<<" cells"<<endl;
00074 }
00075 
00076 //......................................................................
00077 
00078 jobc::Result CellHitMerge::Reco(edm::EventHandle& evt)
00079 {
00080   if(fSkipMe) return jobc::kPassed;
00081   
00082   //get the list of CellHits
00083   std::vector<const recobase::CellHit*> hitlist(0);
00084   try{ evt.Cal().Get("Hits",hitlist); }
00085   catch(edm::Exception e){
00086     cerr<<"Couldn't find the CellHit list"<<endl;
00087     return jobc::kFailed;
00088   }
00089 
00090   //make a new hitlist to hold the pruned/merged hits
00091   std::vector<recobase::CellHit*> newhitlist;
00092 
00093   //now get a header
00094   std::vector<const hdr::Header*> head(0);
00095   try{ evt.DAQ().Get(".",head); }
00096   catch(edm::Exception e){
00097     cerr<<"Couldn't get a head"<<endl;
00098     return false;
00099   }
00100   geo::Geometry& geom = geo::Geometry::Instance(1,head[0]->DetectorID());
00101   int DETLASTPLANE = (int) geom.NPlanes();
00102   //now loop over CellHits in the list and look for crazies/duplicates
00103   std::vector<const recobase::CellHit*>::iterator chit=hitlist.begin();
00104   bool pruned=false;
00105   int ncellpruned = 0;
00106   while(chit!=hitlist.end()){
00107     const CellHit* stp = *chit;
00108     //    cout<<"Printing cell hit in CellHitMerge"<<endl;
00109     //    stp->Print();
00110     // if this cell has a plane number beyond the bounds of the detector
00111     //erase it from the list
00112     if(stp->Plane()<0 || stp->Plane()>DETLASTPLANE){
00113       hitlist.erase(chit); 
00114       cerr<<" CellHitMerge:: found plane crazy "<<stp->Plane()<<" strip "<<stp->Cell()<<endl;
00115       pruned=true;
00116       ncellpruned++;
00117       continue;
00118     }
00119     //if this cell has a cell number beyond the bounds of this plane
00120     //erase it from the list
00121     int PLANELASTCELL = (int) geom.Plane(stp->Plane()).Ncells();
00122     if(stp->Cell()<0 || stp->Cell()>PLANELASTCELL){
00123       hitlist.erase(chit);
00124       cerr<<" CellHitMerge:: found strip crazy "<< stp->Cell()<<" plane "<<stp->Plane()<< endl;       
00125       pruned=true;
00126       ncellpruned++;
00127       continue;
00128     }
00129 
00130     //make a new CellHit that we can modify if need be
00131     CellHit *newstp = new CellHit(*stp);
00132 
00133     //now check if this cell is duplicated in the list
00134     std::vector<const recobase::CellHit*>::iterator dhit=chit;
00135     dhit++;
00136     while(dhit!=hitlist.end()){
00137       const CellHit* stp2 = *dhit;
00138       if(newstp->Plane()==stp2->Plane() && newstp->Cell()==stp2->Cell()){
00139         if(nprinted<11){
00140           //      cerr<<"Merging Cells: "<<newstp->Plane()<<" "<<newstp->Cell()<<endl;
00141         }
00142         unsigned short tdc1, tdc2;
00143         newstp->TDC(tdc1);
00144         stp2->TDC(tdc2);
00145         float tdiff = fabs(1.*tdc1-1.*tdc2);
00146         delTMerged->Fill(tdiff);
00147 
00148         unsigned short adc1,adc2;
00149         newstp->ADC(adc1);
00150         stp2->ADC(adc2);
00151         float phdiff = 1.*adc1-1.*adc2;
00152         unsigned short maxph=adc1;
00153         if(adc2>adc1) maxph=adc2;
00154         delPHMerged->Fill(phdiff);
00155         delPhvdelT->Fill(tdiff,phdiff);
00156         delPhvPh->Fill(maxph,phdiff);
00157         phvph->Fill(adc1,adc2);
00158         newstp->Merge(stp2);
00159         hitlist.erase(dhit);
00160         continue;
00161       }      
00162       //      cout<<"about to put a CellHit in the newhitlist"<<endl;
00163       //      newstp->Print();
00164       dhit++;
00165     }
00166     newhitlist.push_back(newstp);
00167     chit++;
00168   }
00169   if(pruned){
00170     npruned++;
00171     if(ncellpruned>maxpruned){
00172       maxpruned=ncellpruned;
00173     }
00174   }
00175                       
00176   if(evt.Cal().GetFolder("./MergeHits")==0){
00177     evt.Cal().MakeFolder("./MergeHits");
00178   }
00179     
00180   //  cout<<"about to put vector of new hits in file "<<newhitlist.size()<<endl;
00181   evt.Cal().PutVector(newhitlist,"./MergeHits");
00182 
00183   return jobc::kPassed; // kFailed if you want to fail the event   
00184 }
00185 
00186 //......................................................................
00187 
00188 jobc::Result CellHitMerge::Ana(const edm::EventHandle& evt)
00189 {
00190 //======================================================================
00191 // Called for every event. "Ana" implies that you are looking at the
00192 // event, but not altering it.
00193 //======================================================================
00194 
00195 
00196   std::vector<const recobase::CellHit*> hitlist(0);
00197   try{ evt.Cal().Get("Hits",hitlist); }
00198   catch(edm::Exception e){
00199     cerr<<"Couldn't find the Original hit list"<<endl;
00200     return jobc::kFailed;
00201   }
00202 
00203   std::vector<const recobase::CellHit*> mergehitlist(0);
00204   try{ evt.Cal().Get("./MergeHits",mergehitlist); }
00205   catch(edm::Exception e){
00206     cerr<<"Couldn't find the merged hit list"<<endl;
00207     return jobc::kFailed;
00208   }
00209 
00210 
00211   if(hitlist.size()!=mergehitlist.size()){
00212     nevtmerged++;
00213     int diff = hitlist.size()-mergehitlist.size();
00214     if(diff<0){
00215        diff = mergehitlist.size()-hitlist.size();
00216     }
00217     if(diff>maxdiffcells){
00218       maxdiffcells=diff;
00219     }
00220     celldiff->Fill(diff);
00221     //    cout<<"Hit List Sizes differ.  Printing both.  Size of original: "
00222     //  <<hitlist.size()<<" Size of Merged "<<mergehitlist.size()<<" Diff: "<<diff<<endl;
00223   }
00224   else{
00225     celldiff->Fill(0);
00226     return jobc::kPassed;
00227   }
00228 
00229   nprinted++;
00230   if(nprinted<11){
00231     cout<<"Will print 10 events that got merged.  On number: "<<nprinted<<endl;
00232     cout<<"Printing Original Hits: "<<hitlist.size()<<endl;
00233     for(unsigned int i=0;i<hitlist.size();i++){
00234       cout<<"** Printing Original CellHit index "<<i<<" **"<<endl;
00235       hitlist[i]->Print("");
00236       cout<<"*************"<<endl;
00237     }
00238     
00239     cout<<"Printing Merged Hits: "<<mergehitlist.size()<<endl;
00240     for(unsigned int i=0;i<mergehitlist.size();i++){
00241       cout<<"** Printing Merged CellHit index "<<i<<" **"<<endl;
00242       mergehitlist[i]->Print("");
00243       cout<<"*************"<<endl;
00244     }
00245   }
00246   return jobc::kPassed; // kFailed if you want to fail the event
00247   
00248 }
00249 

Generated on Mon Nov 23 04:45:24 2009 for NOvA Offline by  doxygen 1.3.9.1