CMS 3D CMS Logo

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