CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCAFEBConnectAnalysis.cc
Go to the documentation of this file.
5 #include "TMath.h"
6 
8 
9 hist_file=0; // set to null
10 
11 nmbev=0;
13 npulses=0;
14 nmblayers=6;
15 nmbpulses.resize(6,0);
16 pulsed_layer=0;
17 
18 m_csc_list.clear();
19 m_res_for_db.clear();
20 
21 mh_LayerNmbPulses.clear();
22 mh_WireEff.clear();
23 mh_WirePairCrosstalk.clear();
25 mh_Eff.clear();
26 mh_PairCrosstalk.clear();
27 mh_NonPairCrosstalk.clear();
28 
29 mh_FirstTime.clear();
30 
31 }
32 
33 void CSCAFEBConnectAnalysis::setup(const std::string& histoFileName) {
35  hist_file=new TFile(histoFileName.c_str(),"RECREATE");
36  hist_file->cd();
37 }
38 
39 void CSCAFEBConnectAnalysis::bookForId(int flag, const int& idint,
40  const std::string& idstring ) {
41  hist_file->cd();
42 
43  std::ostringstream ss;
44 
45  if(flag==1) {
46  ss <<idint<<"_Anode_First_Time";
47  mh_FirstTime[idint]=new TH2F(ss.str().c_str(),"",675,0.0,675.0,50,0.0,10.0);
48  mh_FirstTime[idint]->GetXaxis()->SetTitle("(Layer-1)*Nwires+Wire");
49  mh_FirstTime[idint]->GetYaxis()->SetTitle("Anode First Time Bin");
50  mh_FirstTime[idint]->SetOption("BOX");
51  ss.str(""); // clear
52  }
53 
54  if(flag==10) {
55  ss <<"Layer_Nmb_Pulses";
56  mh_LayerNmbPulses[idint]=new TH1F(ss.str().c_str(),"",7,0.0,7.0);
57  mh_LayerNmbPulses[idint]->GetXaxis()->SetTitle("Layer");
58  mh_LayerNmbPulses[idint]->GetYaxis()->SetTitle("Number of pulses");
59  ss.str(""); // clear
60  }
61 
62  if(flag==101) {
63  ss <<idint<<"_Anode_Wire_Eff";
64  mh_WireEff[idint]=new TH1F(ss.str().c_str(),"",675,0.0,675.0);
65  mh_WireEff[idint]->GetXaxis()->SetTitle("(Layer-1)*Nwires+Wire");
66  mh_WireEff[idint]->GetYaxis()->SetTitle("Efficiency");
67  ss.str(""); // clear
68  }
69 
70  if(flag==102) {
71  ss <<idint<<"_Anode_Eff";
72  mh_Eff[idint]=new TH1F(ss.str().c_str(),"",110,-0.05,1.05);
73  mh_Eff[idint]->GetXaxis()->SetTitle("Efficiency");
74  mh_Eff[idint]->GetYaxis()->SetTitle("Entries");
75  ss.str(""); // clear
76  }
77 
78  if(flag==201) {
79  ss <<idint<<"_Anode_Wire_Pair_Layer_Crosstalk";
80  mh_WirePairCrosstalk[idint]=new TH1F(ss.str().c_str(),"",675,0.0,675.0);
81  mh_WirePairCrosstalk[idint]->GetXaxis()->SetTitle("(Layer-1)*Nwires+Wire");
82  mh_WirePairCrosstalk[idint]->GetYaxis()->SetTitle("Probability");
83  ss.str(""); // clear
84  }
85 
86  if(flag==202) {
87  ss <<idint<<"_Anode_Pair_Layer_Crosstalk";
88  mh_PairCrosstalk[idint]=new TH1F(ss.str().c_str(),"",70,-0.05,0.3);
89  mh_PairCrosstalk[idint]->GetXaxis()->SetTitle("Probability");
90  mh_PairCrosstalk[idint]->GetYaxis()->SetTitle("Entries");
91  ss.str(""); // clear
92  }
93 
94  if(flag==301) {
95  ss <<idint<<"_Anode_Wire_NonPair_Layer_Crosstalk";
96  mh_WireNonPairCrosstalk[idint]=new TH1F(ss.str().c_str(),"",675,0.0,675.0);
97  mh_WireNonPairCrosstalk[idint]->GetXaxis()->SetTitle("(Layer-1)*Nwires+Wire");
98  mh_WireNonPairCrosstalk[idint]->GetYaxis()->SetTitle("Probability");
99  ss.str(""); // clear
100  }
101 
102  if(flag==302) {
103  ss <<idint<<"_Anode_NonPair_Layer_Crosstalk";
104  mh_NonPairCrosstalk[idint]=new TH1F(ss.str().c_str(),"",70,-0.05,0.3);
105  mh_NonPairCrosstalk[idint]->GetXaxis()->SetTitle("Probability");
106  mh_NonPairCrosstalk[idint]->GetYaxis()->SetTitle("Entries");
107  ss.str(""); // clear
108  }
109 
110 }
111 
112 void CSCAFEBConnectAnalysis::hf1ForId(std::map<int, TH1*>& mp, int flag,
113 const int& id, float& x, float w) {
114 
115  std::map<int,TH1*>::iterator h;
116  h=mp.find(id);
117  if (h==mp.end()) {
118  bookForId(flag,id,"");
119  h=mp.find(id);
120  }
121  h->second->Fill(x,w);
122 }
123 
124 void CSCAFEBConnectAnalysis::hf2ForId(std::map<int, TH2*>& mp, int flag,
125 const int& id, float& x, float& y, float w) {
126 
127  std::map<int,TH2*>::iterator h;
128  h=mp.find(id);
129  if (h==mp.end()) {
130  bookForId(flag,id,"");
131  h=mp.find(id);
132  }
133  h->second->Fill(x,y,w);
134 }
135 
136 
137 /* Analyze the hits */
139 
140 std::ostringstream ss;
141 std::map<int,std::vector<int> >::iterator viIt;
142 std::map<int, std::vector<std::vector<float> > >::iterator vvfIt;
143 
144 int current_layer;
145 float x,y;
146 m_wire_ev.clear();
147 
149 
150 nmbev++;
151 pulsed_layer++;
152 if(pulsed_layer==7) pulsed_layer=1;
154 
155 //Anode wires
156 
158  if(wirecltn.begin() == wirecltn.end()) nmbev_no_wire++;
159 
160  if(wirecltn.begin() != wirecltn.end()) {
161 
162  for (wiredetUnitIt=wirecltn.begin();
163  wiredetUnitIt!=wirecltn.end();
164  ++wiredetUnitIt){
165 
166  const CSCDetId& id = (*wiredetUnitIt).first;
167  const int idchamber=id.endcap()*10000 +id.station()*1000+
168  id.ring()*100 +id.chamber();
169  const int idlayer =id.endcap()*100000+id.station()*10000+
170  id.ring()*1000+id.chamber()*10+id.layer();
171 
172  const int maxwire=csctoafeb.getMaxWire(id.station(),id.ring());
173  std::vector<int> wireplane(maxwire,0);
174 
175  const CSCWireDigiCollection::Range& range = (*wiredetUnitIt).second;
177  range.first; digiIt!=range.second; ++digiIt){
178 
179  int iwire=(*digiIt).getWireGroup();
180  if(iwire<=maxwire) {
181  if(wireplane[iwire-1]==0) {
182  wireplane[iwire-1]=(*digiIt).getBeamCrossingTag()+1;
183 
185  x=(id.layer()-1)*maxwire + iwire;
186  y=wireplane[iwire-1];
187  hf2ForId(mh_FirstTime, 1, idchamber,x, y, 1.0);
188 
190  wireplane[iwire-1]=1;
191 
192  } // end if wireplane[iwire-1]==0
193  } // end if iwire<=csctoafeb.getMaxWire(id.station(),id.ring()
194  } // end of for digis in layer
195 
196  if(m_wire_ev.count(idlayer)==0) m_wire_ev[idlayer]=wireplane;
197 
198  } // end of cycle on detUnit
199 
201 
202  for(viIt=m_wire_ev.begin(); viIt!=m_wire_ev.end(); ++viIt) {
203  const int idwirev=(*viIt).first;
204  const std::vector<int> wiretemp=(*viIt).second;
205  int nsize=4;
206  std::vector<float> zer(nsize,0);
207  vvfIt=m_res_for_db.find(idwirev);
208  if(vvfIt==m_res_for_db.end()) {
209  for(unsigned int j=0;j<wiretemp.size();j++)
210  m_res_for_db[idwirev].push_back(zer);
211  vvfIt=m_res_for_db.find(idwirev);
212  }
213  for(unsigned int i=0;i<(*viIt).second.size();i++) {
214  current_layer=(*viIt).first/10;
215  current_layer=(*viIt).first - current_layer*10;
217  if(pulsed_layer==current_layer) {
218  vvfIt->second[i][1]=vvfIt->second[i][1]+
219  (*viIt).second[i];
220  }
222  if(pulsed_layer==1 || pulsed_layer==3 || pulsed_layer==5)
223  if(current_layer == (pulsed_layer+1))
224  vvfIt->second[i][2]=vvfIt->second[i][2]+
225  (*viIt).second[i];
226  if(pulsed_layer==2 || pulsed_layer==4 || pulsed_layer==6)
227  if(current_layer == (pulsed_layer-1))
228  vvfIt->second[i][2]=vvfIt->second[i][2]+
229  (*viIt).second[i];
231  if((pulsed_layer>2 && current_layer<3) ||
232  (pulsed_layer!=3 && pulsed_layer!=4 &&
233  current_layer>2 && current_layer<5) ||
234  (pulsed_layer<5 && current_layer>4))
235  vvfIt->second[i][3]=vvfIt->second[i][3]+
236  (*viIt).second[i];
237  }
238  } // end of adding hits to the maps
239  } // end of if(wirecltn.begin() != wirecltn.end())
240 } // end of void CSCAFEBConnectAnalysis
241 
242 
244 
245  float x,y;
246 
247  //This is for DB transfer
248 // CSCobject *cn = new CSCobject();
249 // condbon *dbon = new condbon();
250 
251  std::map<int, int>::iterator intIt;
252  std::map<int, std::vector<std::vector<float> > >::iterator vvfIt;
253  std::cout<<"Events analyzed "<<nmbev<<std::endl;
254  std::cout<<"Events no anodes "<<nmbev_no_wire<<std::endl<<std::endl;
255 
256  std::cout<<"Number of pulses per layer"<<std::endl;
257  for(int i=0;i<nmblayers;i++) std::cout <<" "<<nmbpulses[i];
258  std::cout<<"\n"<<std::endl;
259 
260 // std::vector<float> inputx;
261 // std::vector<float> inputy;
262 
265 
266  for(int i=0;i<nmblayers;i++) {
267  x=i+1;
268  y=nmbpulses[i];
269  hf1ForId(mh_LayerNmbPulses, 10, 1,x, y);
270  }
271  for(vvfIt=m_res_for_db.begin(); vvfIt!=m_res_for_db.end();
272  ++vvfIt) {
273  int idlayer=(*vvfIt).first;
274  int idchmb=idlayer/10;
275  int layer=idlayer-idchmb*10;
276  for (unsigned int i=0;i<(*vvfIt).second.size();i++) {
277  (*vvfIt).second[i][0]=nmbpulses[layer-1];
278  (*vvfIt).second[i][3]=(*vvfIt).second[i][3]/4.0;
279  (*vvfIt).second[i][1]=(*vvfIt).second[i][1]/(*vvfIt).second[i][0];
280  (*vvfIt).second[i][2]=(*vvfIt).second[i][2]/(*vvfIt).second[i][0];
281  (*vvfIt).second[i][3]=(*vvfIt).second[i][3]/(*vvfIt).second[i][0];
282 
283  x=(layer-1)*(*vvfIt).second.size() + (i+1);
284 
286  y=(*vvfIt).second[i][1];
287  hf1ForId(mh_WireEff, 101, idchmb,x, y);
288  hf1ForId(mh_Eff, 102, idchmb,y,1.0);
289 
291  y=(*vvfIt).second[i][2];
292  hf1ForId(mh_WirePairCrosstalk, 201, idchmb,x, y);
293  hf1ForId(mh_PairCrosstalk, 202, idchmb,y,1.0);
294 
296  y=(*vvfIt).second[i][3];
297  hf1ForId(mh_WireNonPairCrosstalk, 301, idchmb,x, y);
298  hf1ForId(mh_NonPairCrosstalk, 302, idchmb,y,1.0);
299 
300  }
301  }
302  std::cout<<"Size of map for DB "<<m_res_for_db.size()<<std::endl;
303 
304  std::cout<<"The following CSCs will go to DB"<<std::endl<<std::endl;
305  for(vvfIt=m_res_for_db.begin(); vvfIt!=m_res_for_db.end();
306  ++vvfIt) {
307  int idchmb=(*vvfIt).first/10;
308  if(m_csc_list.count(idchmb)==0) m_csc_list[idchmb]=0;
309  if(m_csc_list.count(idchmb)>0)
310  m_csc_list[idchmb]=m_csc_list[idchmb]+(*vvfIt).second.size();
311  }
312  int count=0;
313  for(intIt=m_csc_list.begin(); intIt!=m_csc_list.end();
314  ++intIt) {
315  count++;
316  std::cout<<count<<" "<<" CSC "<<(*intIt).first<<" "
317  <<(*intIt).second<<std::endl;
318  }
319  std::cout<<std::endl;
320 
321 /*
323 
324  for(vvfIt=m_res_for_db.begin(); vvfIt!=m_res_for_db.end();
325  ++vvfIt) {
326  int idlayer=(*vvfIt).first;
327  int size = (*vvfIt).second.size();
328  cn->obj[idlayer].resize(size);
329  for (unsigned int i=0;i<(*vvfIt).second.size();i++) {
330  std::cout<<idlayer<<" "<<i+1<<" ";
331  for(int j=0;j<4;j++) std::cout<< (*vvfIt).second[i][j]<<" ";
332  std::cout<<std::endl;
333 
334  cn->obj[idlayer][i].resize(4);
335  cn->obj[idlayer][i][0] = (*vvfIt).second[i][0];
336  cn->obj[idlayer][i][1] = (*vvfIt).second[i][1];
337  cn->obj[idlayer][i][2] = (*vvfIt).second[i][2];
338  cn->obj[idlayer][i][3] = (*vvfIt).second[i][3];
339  }
340  }
341 
343 
344  dbon->cdbon_last_run("afeb_thresholds",&run);
345  std::cout<<"Last AFEB thresholds run "<<run<<" for run file "<<myname<<" saved "<<myTime<<std::endl;
346  if(debug) dbon->cdbon_write(cn,"afeb_thresholds",run+1,myTime);
347 */
348 
349  if(hist_file!=0) { // if there was a histogram file...
350  hist_file->Write(); // write out the histrograms
351  delete hist_file; // close and delete the file
352  hist_file=0; // set to zero to clean up
353  std::cout << "Hist. file was closed\n";
354  }
355  std::cout<<" End of CSCAFEBConnectAnalysis"<<std::endl;
356 }
int i
Definition: DBlmapReader.cc:9
long int flag
Definition: mlp_lapack.h:47
void hf1ForId(std::map< int, TH1 * > &mp, int flag, const int &id, float &x, float w)
std::map< int, TH1 * > mh_WireNonPairCrosstalk
tuple histoFileName
Definition: diJetCalib.py:108
std::vector< int > nmbpulses
int endcap() const
Definition: CSCDetId.h:95
std::map< int, int > m_csc_list
Maps.
std::map< int, TH1 * > mh_Eff
const CSCToAFEB csctoafeb
Layer, wire to AFEB, channel conversion.
int j
Definition: DBlmapReader.cc:9
int getMaxWire(int station, int ring) const
return max. number of wiregroups per layer
Definition: CSCToAFEB.cc:50
std::map< int, TH1 * > mh_LayerNmbPulses
Histogram maps.
std::map< int, std::vector< std::vector< float > > > m_res_for_db
std::map< int, TH1 * > mh_WirePairCrosstalk
std::map< int, std::vector< int > > m_wire_ev
void bookForId(int flag, const int &idint, const std::string &ids)
std::map< int, TH2 * > mh_FirstTime
std::map< int, TH1 * > mh_PairCrosstalk
std::map< int, TH1 * > mh_NonPairCrosstalk
std::vector< DigiType >::const_iterator const_iterator
void setup(const std::string &histoFileName)
void hf2ForId(std::map< int, TH2 * > &mp, int flag, const int &id, float &x, float &y, float w)
TFile * hist_file
ROOT hist file.
tuple cout
Definition: gather_cfg.py:41
std::pair< const_iterator, const_iterator > Range
Definition: DDAxes.h:10
std::map< int, TH1 * > mh_WireEff
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void analyze(const CSCWireDigiCollection &wirecltn)