CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/OnlineDB/CSCCondDB/src/CSCAFEBConnectAnalysis.cc

Go to the documentation of this file.
00001 #include "OnlineDB/CSCCondDB/interface/CSCAFEBConnectAnalysis.h"
00002 #include "OnlineDB/CSCCondDB/interface/CSCToAFEB.h"
00003 #include "OnlineDB/CSCCondDB/interface/CSCOnlineDB.h"
00004 #include "CondFormats/CSCObjects/interface/CSCobject.h"
00005 #include "TMath.h"
00006 
00007 CSCAFEBConnectAnalysis::CSCAFEBConnectAnalysis() {
00008 
00009 hist_file=0; // set to null
00010 
00011 nmbev=0;
00012 nmbev_no_wire=0;
00013 npulses=0;
00014 nmblayers=6;
00015 nmbpulses.resize(6,0);
00016 pulsed_layer=0;
00017 
00018 m_csc_list.clear();
00019 m_res_for_db.clear();
00020 
00021 mh_LayerNmbPulses.clear();
00022 mh_WireEff.clear();
00023 mh_WirePairCrosstalk.clear();
00024 mh_WireNonPairCrosstalk.clear();
00025 mh_Eff.clear();
00026 mh_PairCrosstalk.clear();
00027 mh_NonPairCrosstalk.clear();
00028 
00029 mh_FirstTime.clear();
00030 
00031 }
00032 
00033 void CSCAFEBConnectAnalysis::setup(const std::string& histoFileName) {
00035   hist_file=new TFile(histoFileName.c_str(),"RECREATE");
00036   hist_file->cd();
00037 }
00038  
00039 void CSCAFEBConnectAnalysis::bookForId(int flag, const int& idint,
00040                                              const std::string& idstring ) {
00041   hist_file->cd();
00042 
00043   std::ostringstream ss;
00044 
00045   if(flag==1) {
00046   ss <<idint<<"_Anode_First_Time";
00047   mh_FirstTime[idint]=new TH2F(ss.str().c_str(),"",675,0.0,675.0,50,0.0,10.0);
00048   mh_FirstTime[idint]->GetXaxis()->SetTitle("(Layer-1)*Nwires+Wire");
00049   mh_FirstTime[idint]->GetYaxis()->SetTitle("Anode First Time Bin");
00050   mh_FirstTime[idint]->SetOption("BOX");
00051   ss.str(""); // clear
00052   }
00053 
00054   if(flag==10) {
00055   ss <<"Layer_Nmb_Pulses";
00056   mh_LayerNmbPulses[idint]=new TH1F(ss.str().c_str(),"",7,0.0,7.0);
00057   mh_LayerNmbPulses[idint]->GetXaxis()->SetTitle("Layer");
00058   mh_LayerNmbPulses[idint]->GetYaxis()->SetTitle("Number of pulses");
00059   ss.str(""); // clear
00060   }
00061 
00062   if(flag==101) {
00063   ss <<idint<<"_Anode_Wire_Eff";
00064   mh_WireEff[idint]=new TH1F(ss.str().c_str(),"",675,0.0,675.0);
00065   mh_WireEff[idint]->GetXaxis()->SetTitle("(Layer-1)*Nwires+Wire");
00066   mh_WireEff[idint]->GetYaxis()->SetTitle("Efficiency");
00067   ss.str(""); // clear
00068   }
00069 
00070   if(flag==102) {
00071   ss <<idint<<"_Anode_Eff";
00072   mh_Eff[idint]=new TH1F(ss.str().c_str(),"",110,-0.05,1.05);
00073   mh_Eff[idint]->GetXaxis()->SetTitle("Efficiency");
00074   mh_Eff[idint]->GetYaxis()->SetTitle("Entries");
00075   ss.str(""); // clear
00076   }
00077 
00078   if(flag==201) {
00079   ss <<idint<<"_Anode_Wire_Pair_Layer_Crosstalk";
00080   mh_WirePairCrosstalk[idint]=new TH1F(ss.str().c_str(),"",675,0.0,675.0);
00081   mh_WirePairCrosstalk[idint]->GetXaxis()->SetTitle("(Layer-1)*Nwires+Wire");
00082   mh_WirePairCrosstalk[idint]->GetYaxis()->SetTitle("Probability");
00083   ss.str(""); // clear
00084   }
00085 
00086   if(flag==202) {
00087   ss <<idint<<"_Anode_Pair_Layer_Crosstalk";
00088   mh_PairCrosstalk[idint]=new TH1F(ss.str().c_str(),"",70,-0.05,0.3);
00089   mh_PairCrosstalk[idint]->GetXaxis()->SetTitle("Probability");
00090   mh_PairCrosstalk[idint]->GetYaxis()->SetTitle("Entries");
00091   ss.str(""); // clear
00092   }
00093 
00094   if(flag==301) {
00095   ss <<idint<<"_Anode_Wire_NonPair_Layer_Crosstalk";
00096   mh_WireNonPairCrosstalk[idint]=new TH1F(ss.str().c_str(),"",675,0.0,675.0);
00097   mh_WireNonPairCrosstalk[idint]->GetXaxis()->SetTitle("(Layer-1)*Nwires+Wire");
00098   mh_WireNonPairCrosstalk[idint]->GetYaxis()->SetTitle("Probability");
00099   ss.str(""); // clear
00100   }
00101 
00102   if(flag==302) {
00103   ss <<idint<<"_Anode_NonPair_Layer_Crosstalk";
00104   mh_NonPairCrosstalk[idint]=new TH1F(ss.str().c_str(),"",70,-0.05,0.3);
00105   mh_NonPairCrosstalk[idint]->GetXaxis()->SetTitle("Probability");  
00106   mh_NonPairCrosstalk[idint]->GetYaxis()->SetTitle("Entries");
00107   ss.str(""); // clear
00108   }
00109  
00110 }
00111 
00112 void CSCAFEBConnectAnalysis::hf1ForId(std::map<int, TH1*>& mp, int flag, 
00113 const int& id, float& x, float w) {
00114 
00115   std::map<int,TH1*>::iterator h;
00116   h=mp.find(id);
00117   if (h==mp.end()) {
00118      bookForId(flag,id,"");
00119      h=mp.find(id);
00120   }
00121   h->second->Fill(x,w);
00122 }
00123 
00124 void CSCAFEBConnectAnalysis::hf2ForId(std::map<int, TH2*>& mp, int flag,
00125 const int& id, float& x, float& y,  float w) {
00126                                                                                 
00127   std::map<int,TH2*>::iterator h;
00128   h=mp.find(id);
00129   if (h==mp.end()) {
00130      bookForId(flag,id,"");
00131      h=mp.find(id);
00132   }
00133   h->second->Fill(x,y,w);
00134 }
00135 
00136 
00137 /* Analyze the hits */
00138 void CSCAFEBConnectAnalysis::analyze(const CSCWireDigiCollection& wirecltn) {
00139 
00140 std::ostringstream ss;
00141 std::map<int,std::vector<int> >::iterator viIt;
00142 std::map<int, std::vector<std::vector<float> > >::iterator vvfIt;
00143 
00144 int current_layer;
00145 float x,y;
00146 m_wire_ev.clear();
00147 
00149 
00150 nmbev++;
00151 pulsed_layer++;
00152 if(pulsed_layer==7) pulsed_layer=1;
00153 nmbpulses[pulsed_layer-1]=nmbpulses[pulsed_layer-1]+1;
00154 
00155 //Anode wires
00156 
00157   CSCWireDigiCollection::DigiRangeIterator wiredetUnitIt;
00158   if(wirecltn.begin() == wirecltn.end())  nmbev_no_wire++; 
00159 
00160   if(wirecltn.begin() !=  wirecltn.end()) {
00161 
00162   for (wiredetUnitIt=wirecltn.begin();
00163        wiredetUnitIt!=wirecltn.end();
00164        ++wiredetUnitIt){
00165 
00166     const CSCDetId& id = (*wiredetUnitIt).first;
00167     const int idchamber=id.endcap()*10000 +id.station()*1000+
00168                         id.ring()*100 +id.chamber();
00169     const int idlayer  =id.endcap()*100000+id.station()*10000+
00170                         id.ring()*1000+id.chamber()*10+id.layer();
00171 
00172     const int maxwire=csctoafeb.getMaxWire(id.station(),id.ring());
00173     std::vector<int> wireplane(maxwire,0);
00174 
00175     const CSCWireDigiCollection::Range& range = (*wiredetUnitIt).second;
00176     for (CSCWireDigiCollection::const_iterator digiIt =
00177            range.first; digiIt!=range.second; ++digiIt){
00178 
00179       int iwire=(*digiIt).getWireGroup();
00180       if(iwire<=maxwire) {
00181         if(wireplane[iwire-1]==0) {
00182           wireplane[iwire-1]=(*digiIt).getBeamCrossingTag()+1;
00183 
00185           x=(id.layer()-1)*maxwire + iwire;
00186           y=wireplane[iwire-1];
00187           hf2ForId(mh_FirstTime, 1, idchamber,x, y, 1.0);
00188 
00190           wireplane[iwire-1]=1;
00191 
00192         } // end if wireplane[iwire-1]==0
00193       }   // end if iwire<=csctoafeb.getMaxWire(id.station(),id.ring()
00194     }     // end of for digis in layer
00195 
00196     if(m_wire_ev.count(idlayer)==0) m_wire_ev[idlayer]=wireplane; 
00197 
00198   }       // end of cycle on detUnit
00199 
00201 
00202   for(viIt=m_wire_ev.begin(); viIt!=m_wire_ev.end(); ++viIt) {
00203     const int idwirev=(*viIt).first;
00204     const std::vector<int> wiretemp=(*viIt).second;
00205     int nsize=4;
00206     std::vector<float> zer(nsize,0);
00207     vvfIt=m_res_for_db.find(idwirev);
00208     if(vvfIt==m_res_for_db.end()) {
00209       for(unsigned int j=0;j<wiretemp.size();j++)
00210          m_res_for_db[idwirev].push_back(zer);
00211       vvfIt=m_res_for_db.find(idwirev);
00212     }
00213     for(unsigned int i=0;i<(*viIt).second.size();i++) {
00214      current_layer=(*viIt).first/10;
00215      current_layer=(*viIt).first - current_layer*10;
00217      if(pulsed_layer==current_layer) {
00218        vvfIt->second[i][1]=vvfIt->second[i][1]+
00219                                    (*viIt).second[i];
00220      }
00222      if(pulsed_layer==1 || pulsed_layer==3 || pulsed_layer==5)
00223        if(current_layer == (pulsed_layer+1))
00224          vvfIt->second[i][2]=vvfIt->second[i][2]+
00225                                    (*viIt).second[i];
00226      if(pulsed_layer==2 || pulsed_layer==4 || pulsed_layer==6)
00227        if(current_layer == (pulsed_layer-1))
00228          vvfIt->second[i][2]=vvfIt->second[i][2]+
00229                                    (*viIt).second[i];
00231      if((pulsed_layer>2 && current_layer<3)  ||
00232         (pulsed_layer!=3 && pulsed_layer!=4  && 
00233          current_layer>2 && current_layer<5) ||
00234         (pulsed_layer<5 && current_layer>4)) 
00235        vvfIt->second[i][3]=vvfIt->second[i][3]+
00236                                    (*viIt).second[i];
00237    }
00238   } // end of adding hits to the maps
00239   } // end of   if(wirecltn.begin() !=  wirecltn.end())
00240 }   // end of void CSCAFEBConnectAnalysis
00241 
00242 
00243 void CSCAFEBConnectAnalysis::done() {
00244 
00245   float x,y;
00246 
00247   //This is for DB transfer
00248 //  CSCobject *cn = new CSCobject();
00249 //  condbon *dbon = new condbon();
00250   
00251   std::map<int, int>::iterator intIt;
00252   std::map<int, std::vector<std::vector<float> > >::iterator vvfIt;
00253   std::cout<<"Events analyzed  "<<nmbev<<std::endl;
00254   std::cout<<"Events no anodes "<<nmbev_no_wire<<std::endl<<std::endl;
00255 
00256   std::cout<<"Number of pulses per layer"<<std::endl;
00257   for(int i=0;i<nmblayers;i++) std::cout <<" "<<nmbpulses[i];
00258   std::cout<<"\n"<<std::endl; 
00259 
00260 //  std::vector<float> inputx;
00261 //  std::vector<float> inputy;
00262 
00265 
00266   for(int i=0;i<nmblayers;i++) {
00267      x=i+1;
00268      y=nmbpulses[i];
00269      hf1ForId(mh_LayerNmbPulses, 10, 1,x, y);
00270   }
00271   for(vvfIt=m_res_for_db.begin(); vvfIt!=m_res_for_db.end();
00272       ++vvfIt) {
00273       int idlayer=(*vvfIt).first;
00274       int idchmb=idlayer/10;
00275       int layer=idlayer-idchmb*10;
00276       for (unsigned int i=0;i<(*vvfIt).second.size();i++) {
00277         (*vvfIt).second[i][0]=nmbpulses[layer-1];
00278         (*vvfIt).second[i][3]=(*vvfIt).second[i][3]/4.0;
00279         (*vvfIt).second[i][1]=(*vvfIt).second[i][1]/(*vvfIt).second[i][0];
00280         (*vvfIt).second[i][2]=(*vvfIt).second[i][2]/(*vvfIt).second[i][0];
00281         (*vvfIt).second[i][3]=(*vvfIt).second[i][3]/(*vvfIt).second[i][0];
00282 
00283         x=(layer-1)*(*vvfIt).second.size() + (i+1);
00284 
00286         y=(*vvfIt).second[i][1];
00287         hf1ForId(mh_WireEff, 101, idchmb,x, y);
00288         hf1ForId(mh_Eff, 102, idchmb,y,1.0);
00289 
00291         y=(*vvfIt).second[i][2];
00292         hf1ForId(mh_WirePairCrosstalk, 201, idchmb,x, y);
00293         hf1ForId(mh_PairCrosstalk, 202, idchmb,y,1.0);
00294 
00296         y=(*vvfIt).second[i][3];
00297         hf1ForId(mh_WireNonPairCrosstalk, 301, idchmb,x, y);
00298         hf1ForId(mh_NonPairCrosstalk, 302, idchmb,y,1.0);
00299 
00300       }
00301   }
00302   std::cout<<"Size of map for DB "<<m_res_for_db.size()<<std::endl;
00303   
00304   std::cout<<"The following CSCs will go to DB"<<std::endl<<std::endl;
00305   for(vvfIt=m_res_for_db.begin(); vvfIt!=m_res_for_db.end();
00306       ++vvfIt) {
00307       int idchmb=(*vvfIt).first/10;
00308       if(m_csc_list.count(idchmb)==0) m_csc_list[idchmb]=0;
00309       if(m_csc_list.count(idchmb)>0)  
00310         m_csc_list[idchmb]=m_csc_list[idchmb]+(*vvfIt).second.size();
00311   }
00312   int count=0;
00313   for(intIt=m_csc_list.begin(); intIt!=m_csc_list.end();
00314       ++intIt) {
00315       count++;
00316       std::cout<<count<<" "<<" CSC "<<(*intIt).first<<"  "
00317                <<(*intIt).second<<std::endl;
00318   }
00319   std::cout<<std::endl;
00320 
00321 /*
00323 
00324   for(vvfIt=m_res_for_db.begin(); vvfIt!=m_res_for_db.end(); 
00325       ++vvfIt) {
00326       int idlayer=(*vvfIt).first;
00327       int size = (*vvfIt).second.size();
00328       cn->obj[idlayer].resize(size);
00329       for (unsigned int i=0;i<(*vvfIt).second.size();i++) { 
00330         std::cout<<idlayer<<" "<<i+1<<"    ";   
00331         for(int j=0;j<4;j++) std::cout<< (*vvfIt).second[i][j]<<" ";
00332         std::cout<<std::endl;
00333 
00334         cn->obj[idlayer][i].resize(4);
00335         cn->obj[idlayer][i][0] = (*vvfIt).second[i][0];
00336         cn->obj[idlayer][i][1] = (*vvfIt).second[i][1];
00337         cn->obj[idlayer][i][2] = (*vvfIt).second[i][2];
00338         cn->obj[idlayer][i][3] = (*vvfIt).second[i][3];
00339       }
00340   }
00341 
00343 
00344   dbon->cdbon_last_run("afeb_thresholds",&run);
00345   std::cout<<"Last AFEB thresholds run "<<run<<" for run file "<<myname<<" saved "<<myTime<<std::endl;
00346   if(debug) dbon->cdbon_write(cn,"afeb_thresholds",run+1,myTime);
00347 */
00348   
00349   if(hist_file!=0) { // if there was a histogram file...
00350     hist_file->Write(); // write out the histrograms
00351     delete hist_file; // close and delete the file
00352     hist_file=0; // set to zero to clean up
00353     std::cout << "Hist. file was closed\n";
00354   }
00355   std::cout<<" End of CSCAFEBConnectAnalysis"<<std::endl;  
00356 }